From 3a9b2a3e83a4eea55f71cdce870083f49f17c717 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Tue, 7 Mar 2023 14:51:35 +0100 Subject: [PATCH 0001/1906] cmake: recommend CMake >=3.20.5 as minimum CMake version CMake versions <3.20.5 contains the following bug: https://gitlab.kitware.com/cmake/cmake/-/issues/22310 This bug was fixed in CMake 3.20.5: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6232 Generally Zephyr can build with CMake >=3.20.0, however the `cmake/package_helper.cmake` is impacted by the above issue. Therefore, specifically request CMake >=3.20.5 for package helper and update documentation to recommend CMake version 3.20.5 in order to minimize risk of users being impacted by this bug. Users invoking package helper with CMake 3.20.0-3.20.4 will see: > CMake Error at cmake/package_helper.cmake:45 (cmake_minimum_required): > CMake 3.20.5 or higher is required. You are running version 3.20.x Rest of Zephyr still builds with CMake versions >=3.20.0. Signed-off-by: Torsten Rasmussen --- cmake/package_helper.cmake | 2 +- doc/develop/getting_started/index.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/package_helper.cmake b/cmake/package_helper.cmake index 36741bbc9506..5f48185a57b5 100644 --- a/cmake/package_helper.cmake +++ b/cmake/package_helper.cmake @@ -42,7 +42,7 @@ # find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) # the 'foo.overlay' must be specified using '-DOVERLAY_CONFIG=foo.overlay' -cmake_minimum_required(VERSION 3.20.0) +cmake_minimum_required(VERSION 3.20.5) # add_custom_target and set_target_properties are not supported in script mode. # However, several Zephyr CMake modules create custom target for user convenience diff --git a/doc/develop/getting_started/index.rst b/doc/develop/getting_started/index.rst index 55baaf0beac2..e7c6f6810a64 100644 --- a/doc/develop/getting_started/index.rst +++ b/doc/develop/getting_started/index.rst @@ -62,7 +62,7 @@ The current minimum required version for the main dependencies are: - Min. Version * - `CMake `_ - - 3.20.0 + - 3.20.5 * - `Python `_ - 3.8 From 52f902f41188001647e48e8d1cd1f47d398f9d51 Mon Sep 17 00:00:00 2001 From: Filip Kokosinski Date: Tue, 7 Mar 2023 14:00:39 +0100 Subject: [PATCH 0002/1906] MAINTAINERS: add maintainers for "platform: SiLabs" area This commit adds a maintainer and a collaborator to the "platform: SiLabs" area. It also changes its status to "maintained". Signed-off-by: Filip Kokosinski --- MAINTAINERS.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index a6346a2c29cf..4dfb67e09f93 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -2040,7 +2040,11 @@ Raspberry Pi Pico Platforms: - "platform: Raspberry Pi Pico" SiLabs Platforms: - status: odd fixes + status: maintained + maintainers: + - fkokosinski + collaborators: + - tgorochowik files: - soc/arm/silabs_*/ - boards/arm/ef*/ From 1a0e7fa57af3edfa6c558dd71f742599b6483c14 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Fri, 3 Mar 2023 08:31:13 +0100 Subject: [PATCH 0003/1906] Bluetooth: audio: ascs: Remove reference to conn internals This removes using conn internal API in ASCS. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index bba7f5ef7779..3e301b3b69e3 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -31,7 +31,6 @@ LOG_MODULE_REGISTER(bt_ascs, CONFIG_BT_ASCS_LOG_LEVEL); #include "common/assert.h" #include "../host/hci_core.h" -#include "../host/conn_internal.h" #include "audio_internal.h" #include "bap_iso.h" @@ -111,10 +110,13 @@ static void ase_status_changed(struct bt_bap_ep *ep, uint8_t old_state, uint8_t { struct bt_ascs_ase *ase = CONTAINER_OF(ep, struct bt_ascs_ase, ep); struct bt_conn *conn = ase->ascs->conn; + struct bt_conn_info conn_info; LOG_DBG("ase %p, ep %p", ase, ep); - if (conn != NULL && conn->state == BT_CONN_CONNECTED) { + bt_conn_get_info(conn, &conn_info); + + if (conn != NULL && conn_info.state == BT_CONN_STATE_CONNECTED) { ascs_ep_get_status(ep, &ase_buf); bt_gatt_notify(conn, ase->attr, ase_buf.data, ase_buf.len); @@ -568,7 +570,7 @@ static int ascs_ep_get_status(struct bt_bap_ep *ep, struct net_buf_simple *buf) static int ascs_iso_accept(const struct bt_iso_accept_info *info, struct bt_iso_chan **iso_chan) { - LOG_DBG("acl %p", info->acl); + LOG_DBG("acl %p", (void *)info->acl); for (size_t i = 0U; i < ARRAY_SIZE(enabling); i++) { struct bt_bap_stream *c = enabling[i]; @@ -598,7 +600,7 @@ static int ascs_iso_listen(struct bt_bap_stream *stream) static bool server; int err; - LOG_DBG("stream %p conn %p", stream, stream->conn); + LOG_DBG("stream %p conn %p", stream, (void *)stream->conn); if (server) { goto done; @@ -1264,7 +1266,7 @@ static ssize_t ascs_ase_read(struct bt_conn *conn, struct bt_ascs_ase *ase; uint8_t ase_id; - LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset); + LOG_DBG("conn %p attr %p buf %p len %u offset %u", (void *)conn, attr, buf, len, offset); ase_id = POINTER_TO_UINT(BT_AUDIO_CHRC_USER_DATA(attr)); @@ -1539,7 +1541,7 @@ int bt_ascs_config_ase(struct bt_conn *conn, struct bt_bap_stream *stream, struc ep = stream->ep; if (stream->ep != NULL) { - LOG_DBG("Stream already configured for conn %p", stream->conn); + LOG_DBG("Stream already configured for conn %p", (void *)stream->conn); return -EALREADY; } @@ -2616,8 +2618,8 @@ static ssize_t ascs_cp_write(struct bt_conn *conn, req = net_buf_simple_pull_mem(&buf, sizeof(*req)); - LOG_DBG("conn %p attr %p buf %p len %u op %s (0x%02x)", conn, attr, data, len, - bt_ascs_op_str(req->op), req->op); + LOG_DBG("conn %p attr %p buf %p len %u op %s (0x%02x)", + (void *)conn, attr, data, len, bt_ascs_op_str(req->op), req->op); /* Reset/empty response buffer before using it again */ net_buf_simple_reset(&rsp_buf); From e26bf578c6746d3800f1d62c803bbee3cb12390d Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Tue, 7 Mar 2023 15:09:07 +0100 Subject: [PATCH 0004/1906] tests/lib/cpp/cxx: Fix for all POSIX arch platforms We need to exclude all POSIX arch boards, not just native_posix* as all use the host compiler toolchain. Signed-off-by: Alberto Escolar Piedras --- tests/lib/cpp/cxx/testcase.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/lib/cpp/cxx/testcase.yaml b/tests/lib/cpp/cxx/testcase.yaml index 9540d157bb11..77d1b06dbb2e 100644 --- a/tests/lib/cpp/cxx/testcase.yaml +++ b/tests/lib/cpp/cxx/testcase.yaml @@ -33,33 +33,33 @@ tests: # -Wno-pointer-sign or -Werror=implicit-int in C++ mode with # -std=c++98) cpp.main.cpp98: - platform_exclude: native_posix native_posix_64 + arch_exclude: posix build_only: true extra_configs: - CONFIG_STD_CPP98=y # Note: no "cpp.main.cpp11" as that's the default standard tested above cpp.main.cpp14: - platform_exclude: native_posix native_posix_64 + arch_exclude: posix build_only: true extra_configs: - CONFIG_STD_CPP14=y cpp.main.cpp17: - platform_exclude: native_posix native_posix_64 + arch_exclude: posix build_only: true extra_configs: - CONFIG_STD_CPP17=y cpp.main.cpp2A: - platform_exclude: native_posix native_posix_64 + arch_exclude: posix build_only: true extra_configs: - CONFIG_STD_CPP2A=y cpp.main.cpp20: - platform_exclude: native_posix native_posix_64 + arch_exclude: posix build_only: true extra_configs: - CONFIG_STD_CPP20=y cpp.main.cpp2B: - platform_exclude: native_posix native_posix_64 + arch_exclude: posix build_only: true extra_configs: - CONFIG_STD_CPP2B=y From 6deee01b4ed55fc4498af4a3c182208f3452bc56 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Tue, 7 Mar 2023 23:24:16 +0000 Subject: [PATCH 0005/1906] doc: mec172xmodular_assy6930: fix doc title Fix document title for mec172xmodular_assy6930. This is adding some incorrect links to the board list. Signed-off-by: Fabio Baltieri --- .../arm/mec172xmodular_assy6930/doc/mec172xmodular_assy6930.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/arm/mec172xmodular_assy6930/doc/mec172xmodular_assy6930.rst b/boards/arm/mec172xmodular_assy6930/doc/mec172xmodular_assy6930.rst index e8b9225c6d61..457cb85edaa0 100644 --- a/boards/arm/mec172xmodular_assy6930/doc/mec172xmodular_assy6930.rst +++ b/boards/arm/mec172xmodular_assy6930/doc/mec172xmodular_assy6930.rst @@ -1,7 +1,7 @@ .. _mec172xmodular_6930: Microchip MEC172x Modular Card ASSY6930 (Rev. B) -#########3333333333############################# +################################################ Overview ******** From 62ea2185a10ca9a5b7bfd36259e0c4dea65c28fd Mon Sep 17 00:00:00 2001 From: Aaron Massey Date: Tue, 7 Mar 2023 11:57:40 -0700 Subject: [PATCH 0006/1906] test: Filter HW test from prototyped SBS Gauge Issue #55521 shows hardware tests hanging when run against the Fuel Gauge's SBS gauge that's still being prototyped against emulated boards. Prevent accidental running of HW tests on the emulated SBS tests until HW tests have been contributed upstream by filtering for qemu and native posix boards. Signed-off-by: Aaron Massey --- tests/drivers/fuel_gauge/sbs_gauge/testcase.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/drivers/fuel_gauge/sbs_gauge/testcase.yaml b/tests/drivers/fuel_gauge/sbs_gauge/testcase.yaml index 48d419e1b4c2..4cddbb13d441 100644 --- a/tests/drivers/fuel_gauge/sbs_gauge/testcase.yaml +++ b/tests/drivers/fuel_gauge/sbs_gauge/testcase.yaml @@ -2,7 +2,9 @@ tests: # section.subsection drivers.sbs_gauge_new_api.emulated: tags: test_framework - filter: dt_compat_enabled("sbs,sbs-gauge-new-api") + filter: > + dt_compat_enabled("sbs,sbs-gauge-new-api") and + (CONFIG_QEMU_TARGET or CONFIG_BOARD_NATIVE_POSIX) extra_args: CONF_FILE="prj.conf;boards/emulated_board.conf" DTC_OVERLAY_FILE="boards/emulated_board.overlay" @@ -15,7 +17,9 @@ tests: xenvm_gicv3 drivers.sbs_gauge_new_api.emulated_64_bit_i2c_addr: tags: test_framework - filter: dt_compat_enabled("sbs,sbs-gauge-new-api") + filter: > + dt_compat_enabled("sbs,sbs-gauge-new-api") and + (CONFIG_QEMU_TARGET or CONFIG_BOARD_NATIVE_POSIX) platform_allow: qemu_cortex_a53 qemu_cortex_a53_smp From 821fddc2e16522cd779a9792258f12c72b39c3d3 Mon Sep 17 00:00:00 2001 From: Armin Brauns Date: Tue, 7 Mar 2023 10:59:44 +0100 Subject: [PATCH 0007/1906] drivers: bluetooth: hci_spi: fix condition causing infinite loop With a size of 0, the inner loop will never terminate, so don't try to enter it. Signed-off-by: Armin Brauns --- drivers/bluetooth/hci/spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/bluetooth/hci/spi.c b/drivers/bluetooth/hci/spi.c index 955cd3725c88..b40340668285 100644 --- a/drivers/bluetooth/hci/spi.c +++ b/drivers/bluetooth/hci/spi.c @@ -306,7 +306,7 @@ static void bt_spi_rx_thread(void) !ret)) && exit_irq_high_loop()); size = header_slave[STATUS_HEADER_TOREAD]; - if (!ret || size != 0) { + if (ret == 0 && size != 0) { do { ret = bt_spi_transceive(&txmsg, size, &rxmsg, size); From 41814f8c3bb076656197a78700d2b41ea9500c38 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Mon, 6 Mar 2023 14:34:34 +0100 Subject: [PATCH 0008/1906] tests: Bluetooth: Mesh: fix read access to uninitialized memory There are a couple of places where read access to uninitialized memory happens in new mesh-1.1 tests. Valgrind highlights them. PR fixes them. Signed-off-by: Aleksandr Khromykh --- tests/bluetooth/bsim/mesh/src/test_blob.c | 2 ++ tests/bluetooth/bsim/mesh/src/test_dfu.c | 2 ++ tests/bluetooth/bsim/mesh/src/test_op_agg.c | 6 ++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/bluetooth/bsim/mesh/src/test_blob.c b/tests/bluetooth/bsim/mesh/src/test_blob.c index 0664664d7e04..e32dee58a1f0 100644 --- a/tests/bluetooth/bsim/mesh/src/test_blob.c +++ b/tests/bluetooth/bsim/mesh/src/test_blob.c @@ -87,6 +87,8 @@ static int blob_chunk_rd(const struct bt_mesh_blob_io *io, const struct bt_mesh_blob_block *block, const struct bt_mesh_blob_chunk *chunk) { + memset(chunk->data, 0, chunk->size); + return 0; } diff --git a/tests/bluetooth/bsim/mesh/src/test_dfu.c b/tests/bluetooth/bsim/mesh/src/test_dfu.c index 5ac21f849665..6ec983dd5d6c 100644 --- a/tests/bluetooth/bsim/mesh/src/test_dfu.c +++ b/tests/bluetooth/bsim/mesh/src/test_dfu.c @@ -85,6 +85,8 @@ static int dummy_blob_chunk_rd(const struct bt_mesh_blob_io *io, const struct bt_mesh_blob_block *block, const struct bt_mesh_blob_chunk *chunk) { + memset(chunk->data, 0, chunk->size); + return 0; } diff --git a/tests/bluetooth/bsim/mesh/src/test_op_agg.c b/tests/bluetooth/bsim/mesh/src/test_op_agg.c index 6c58e5514d91..6d1c0c7e5f1c 100644 --- a/tests/bluetooth/bsim/mesh/src/test_op_agg.c +++ b/tests/bluetooth/bsim/mesh/src/test_op_agg.c @@ -73,7 +73,8 @@ static int get_handler(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, bt_mesh_model_msg_init(&msg, BT_MESH_DUMMY_VND_MOD_STATUS_OP); net_buf_simple_add_u8(&msg, seq); - net_buf_simple_add(&msg, BT_MESH_DUMMY_VND_MOD_MSG_MINLEN - 1); + memset(net_buf_simple_add(&msg, BT_MESH_DUMMY_VND_MOD_MSG_MINLEN - 1), 0, + BT_MESH_DUMMY_VND_MOD_MSG_MINLEN); /* Last message: One additional byte is added to fill the available access payload.*/ if (get_rcvd_count >= TEST_SEND_ITR) { @@ -107,7 +108,8 @@ static int dummy_vnd_mod_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx bt_mesh_model_msg_init(&msg, BT_MESH_DUMMY_VND_MOD_GET_OP); net_buf_simple_add_u8(&msg, seq); - net_buf_simple_add(&msg, BT_MESH_DUMMY_VND_MOD_MSG_MINLEN - 1); + memset(net_buf_simple_add(&msg, BT_MESH_DUMMY_VND_MOD_MSG_MINLEN - 1), 0, + BT_MESH_DUMMY_VND_MOD_MSG_MINLEN); /* Last message: One additional byte is added to fill the available access payload.*/ if (seq >= TEST_SEND_ITR - 1) { From 5bd0f5ea8bc7d8447e4c3ff8779346b041b7a097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mo=C5=84?= Date: Tue, 7 Mar 2023 09:43:05 +0100 Subject: [PATCH 0009/1906] usb: device_next: msc: handle MODE SENSE(10) command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit USB Mass Storage Specification for Bootability requires MODE SENSE(10) command. MODE SENSE(6) and MODE SENSE(10) generally access the same data but differ in the maximum allocated length and LLBAA support. However there is no point in extracting common handling because there no mode pages are supported now. Fail MODE SENSE requests if asking for anything other than supported page codes (to which the essentially hardcoded response is valid). Signed-off-by: Tomasz Moń --- subsys/usb/device_next/class/usbd_msc_scsi.c | 60 +++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/subsys/usb/device_next/class/usbd_msc_scsi.c b/subsys/usb/device_next/class/usbd_msc_scsi.c index 36e8db838454..de883c625b68 100644 --- a/subsys/usb/device_next/class/usbd_msc_scsi.c +++ b/subsys/usb/device_next/class/usbd_msc_scsi.c @@ -72,6 +72,7 @@ enum scsi_opcode { READ_CAPACITY_10 = 0x25, READ_10 = 0x28, WRITE_10 = 0x2A, + MODE_SENSE_10 = 0x5A, }; SCSI_CMD_STRUCT(TEST_UNIT_READY) { @@ -170,6 +171,8 @@ struct scsi_inquiry_response { */ } __packed; +#define MODE_SENSE_PAGE_CODE_ALL_PAGES 0x3F + SCSI_CMD_STRUCT(MODE_SENSE_6) { uint8_t opcode; uint8_t dbd; @@ -298,6 +301,30 @@ SCSI_CMD_STRUCT(WRITE_10) { uint8_t control; } __packed; +SCSI_CMD_STRUCT(MODE_SENSE_10) { + uint8_t opcode; + uint8_t llbaa_dbd; + uint8_t page; + uint8_t subpage; + uint8_t reserved4; + uint8_t reserved5; + uint8_t reserved6; + uint16_t allocation_length; + uint8_t control; +} __packed; + +/* SPC-5 7.5.6 Mode parameter header formats + * Table 444 — Mode parameter header(10) + */ +struct scsi_mode_sense_10_response { + uint16_t mode_data_length; + uint8_t medium_type; + uint8_t device_specific_parameter; + uint8_t longlba; + uint8_t reserved5; + uint16_t block_descriptor_length; +} __packed; + static int update_disk_info(struct scsi_ctx *const ctx) { int status = disk_access_status(ctx->disk); @@ -536,13 +563,17 @@ SCSI_CMD_HANDLER(MODE_SENSE_6) ctx->cmd_is_data_read = true; + if (cmd->page != MODE_SENSE_PAGE_CODE_ALL_PAGES || cmd->subpage != 0) { + return illegal_request(ctx, INVALID_FIELD_IN_CDB); + } + r.mode_data_length = 3; r.medium_type = 0x00; r.device_specific_parameter = 0x00; r.block_descriptor_length = 0x00; BUILD_ASSERT(sizeof(r) <= CONFIG_USBD_MSC_SCSI_BUFFER_SIZE); - length = MIN(sys_be16_to_cpu(cmd->allocation_length), sizeof(r)); + length = MIN(cmd->allocation_length, sizeof(r)); memcpy(data_in_buf, &r, length); return good(ctx, length); } @@ -749,6 +780,32 @@ SCSI_CMD_HANDLER(WRITE_10) return good(ctx, 0); } +/* SPC-5 6.15 MODE SENSE(10) command */ +SCSI_CMD_HANDLER(MODE_SENSE_10) +{ + struct scsi_mode_sense_10_response r; + int length; + + ctx->cmd_is_data_read = true; + + if (cmd->page != MODE_SENSE_PAGE_CODE_ALL_PAGES || cmd->subpage != 0) { + return illegal_request(ctx, INVALID_FIELD_IN_CDB); + } + + r.mode_data_length = sys_cpu_to_be16(6); + r.medium_type = 0x00; + r.device_specific_parameter = 0x00; + r.longlba = 0x00; + r.reserved5 = 0x00; + r.block_descriptor_length = sys_cpu_to_be16(0); + + BUILD_ASSERT(sizeof(r) <= CONFIG_USBD_MSC_SCSI_BUFFER_SIZE); + length = MIN(sys_be16_to_cpu(cmd->allocation_length), sizeof(r)); + memcpy(data_in_buf, &r, length); + + return good(ctx, length); +} + size_t scsi_cmd(struct scsi_ctx *ctx, const uint8_t *cb, int len, uint8_t data_in_buf[static CONFIG_USBD_MSC_SCSI_BUFFER_SIZE]) { @@ -779,6 +836,7 @@ size_t scsi_cmd(struct scsi_ctx *ctx, const uint8_t *cb, int len, SCSI_CMD(READ_CAPACITY_10); SCSI_CMD(READ_10); SCSI_CMD(WRITE_10); + SCSI_CMD(MODE_SENSE_10); LOG_ERR("Unknown SCSI opcode 0x%02x", cb[0]); return illegal_request(ctx, INVALID_FIELD_IN_CDB); From 551be5c7f6d5d6bcddd351a0ccc8a127fd8260cc Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Tue, 7 Mar 2023 16:53:36 +0100 Subject: [PATCH 0010/1906] drivers: adc: stm32 adc driver disable before calibration In the adc_stm32_init() function, when adc_stm32_calib() is called, the ADC is not yet enabled but still disabled. This patch makes sure to Disable the ADC before its calibration. Signed-off-by: Francois Ramu --- drivers/adc/adc_stm32.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/adc/adc_stm32.c b/drivers/adc/adc_stm32.c index 38aa1d576fb1..5273fdb6bed5 100644 --- a/drivers/adc/adc_stm32.c +++ b/drivers/adc/adc_stm32.c @@ -1255,6 +1255,7 @@ static int adc_stm32_init(const struct device *dev) * Calibration of F1 and F3 (ADC1_V2_5) series has to be started * after ADC Module is enabled. */ + adc_stm32_disable(adc); adc_stm32_calib(dev); #endif From cb1d36afca1f66bf2f719ac25a88e58a7b7d1609 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 22 Feb 2023 10:27:27 +0100 Subject: [PATCH 0011/1906] Bluetooth: audio: ascs: Remove unused includes This removes unused includes. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 3e301b3b69e3..15348d0a1166 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -12,9 +12,6 @@ #include #include -#include -#include - #include #include #include @@ -30,8 +27,6 @@ LOG_MODULE_REGISTER(bt_ascs, CONFIG_BT_ASCS_LOG_LEVEL); #include "common/bt_str.h" #include "common/assert.h" -#include "../host/hci_core.h" - #include "audio_internal.h" #include "bap_iso.h" #include "bap_endpoint.h" From cf7bfc406c317d11fcfb1003d3b0edc193b4ae9a Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Tue, 7 Mar 2023 15:21:47 +0100 Subject: [PATCH 0012/1906] Bluetooth: audio: Remove redundant forward declaration This removes redundant bt_bap_ep declaration, as the structure is defined right below. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/bap_endpoint.h | 1 - 1 file changed, 1 deletion(-) diff --git a/subsys/bluetooth/audio/bap_endpoint.h b/subsys/bluetooth/audio/bap_endpoint.h index e1d4983fae3f..db7f443a007b 100644 --- a/subsys/bluetooth/audio/bap_endpoint.h +++ b/subsys/bluetooth/audio/bap_endpoint.h @@ -31,7 +31,6 @@ struct bt_bap_unicast_group; struct bt_bap_broadcast_source; struct bt_bap_broadcast_sink; -struct bt_bap_ep; struct bt_bap_ep { uint8_t dir; From 136191e9369c7787f38303432b7966e1b6af50b6 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 7 Mar 2023 09:57:54 +0100 Subject: [PATCH 0013/1906] Bluetooth: Audio: Fix return value for VOCS invalid location If the location was invalid, we return 0 instead of an error. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/vocs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/audio/vocs.c b/subsys/bluetooth/audio/vocs.c index 48c0449c12e5..461d71b2ecc9 100644 --- a/subsys/bluetooth/audio/vocs.c +++ b/subsys/bluetooth/audio/vocs.c @@ -67,9 +67,11 @@ static ssize_t write_location(struct bt_conn *conn, const struct bt_gatt_attr *a } new_location = sys_get_le32(buf); - if ((new_location & BT_AUDIO_LOCATION_RFU) > 0) { + if (new_location == BT_AUDIO_LOCATION_PROHIBITED || + (new_location & BT_AUDIO_LOCATION_RFU) > 0) { LOG_DBG("Invalid location %u", new_location); - return 0; + + return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED); } if (new_location != inst->srv.location) { From 89ef99ce44f9af384eb4c1e8806360abdcce8591 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 7 Mar 2023 09:58:35 +0100 Subject: [PATCH 0014/1906] tests: Bluetooth: Fix vocs location error strings Some of the error strings were incorrect. Signed-off-by: Emil Gydesen --- tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c | 6 ++---- tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c b/tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c index dfd86c5cb1f2..53a4c8a25339 100644 --- a/tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c +++ b/tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c @@ -685,8 +685,7 @@ static void test_vocs_location_set(void) err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location); if (err == 0) { - FAIL("bt_vocs_location_set with NULL location 0x%08X did not fail", - invalid_location); + FAIL("bt_vocs_location_set with location 0x%08X did not fail", invalid_location); return; } @@ -694,8 +693,7 @@ static void test_vocs_location_set(void) err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location); if (err == 0) { - FAIL("bt_vocs_location_set with NULL location 0x%08X did not fail", - invalid_location); + FAIL("bt_vocs_location_set with location 0x%08X did not fail", invalid_location); return; } diff --git a/tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c b/tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c index 69507bc7116f..476491d33204 100644 --- a/tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c +++ b/tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c @@ -646,8 +646,7 @@ static void test_vocs_location_set(void) err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location); if (err == 0) { - FAIL("bt_vocs_location_set with NULL location 0x%08X did not fail", - invalid_location); + FAIL("bt_vocs_location_set with location 0x%08X did not fail", invalid_location); return; } @@ -655,8 +654,7 @@ static void test_vocs_location_set(void) err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location); if (err == 0) { - FAIL("bt_vocs_location_set with NULL location 0x%08X did not fail", - invalid_location); + FAIL("bt_vocs_location_set with location 0x%08X did not fail", invalid_location); return; } From b147f86392a3738633cf5219b9af032a96139018 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 7 Mar 2023 09:59:26 +0100 Subject: [PATCH 0015/1906] tests: Bluetooth: Fix VCP Vol rend standalone tests not being run Due to a missing backslash, the VCP vol rend tests were not being run. Signed-off-by: Emil Gydesen --- tests/bluetooth/bsim/audio/test_scripts/vcp.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/bluetooth/bsim/audio/test_scripts/vcp.sh b/tests/bluetooth/bsim/audio/test_scripts/vcp.sh index cad148cb6682..fb170d911db8 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/vcp.sh +++ b/tests/bluetooth/bsim/audio/test_scripts/vcp.sh @@ -27,8 +27,7 @@ cd ${BSIM_OUT_PATH}/bin printf "\n\n======== Running VCP Volume Renderer standalone (API) test =========\n\n" Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 - -testid=vcp_vol_rend_standalone -rs=23 + -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=vcp_vol_rend_standalone -rs=23 # Simulation time should be larger than the WAIT_TIME in common.h Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ From 589ca1f2d915f8e587dccd29748f3373e8b1817f Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Tue, 7 Mar 2023 08:40:35 +0100 Subject: [PATCH 0016/1906] manifest: hal_nordic: bump version of hal_nordic to `e9eca1e`. This commit bumps version of hal nordic to introduce newer radio driver. Signed-off-by: Przemyslaw Bida --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 87ace4d86aa0..7b6501a679bd 100644 --- a/west.yml +++ b/west.yml @@ -83,7 +83,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 6c9f23498ee6a225fee049c8c5b2e1ac760bd4a8 + revision: 609d4b41fe9773cd294eb8656d99eb9385389e52 path: modules/hal/nordic groups: - hal From dc5155e5a52a62bb5618474fbbd1aa358178de42 Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Mon, 20 Feb 2023 15:04:10 +0100 Subject: [PATCH 0017/1906] openthread: ieee802154_nrf5: Add implementation of new api. Adding an Openthread radio API `otPlatRadioSetMacFrameCounterIfLarger` implementation and the corresponding call to the IEEEE802154 driver. Signed-off-by: Przemyslaw Bida --- drivers/ieee802154/ieee802154_nrf5.c | 4 ++++ include/zephyr/net/ieee802154_radio.h | 6 ++++++ modules/openthread/platform/radio.c | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index c5c7906445d3..650ff10b6b93 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -952,6 +952,10 @@ static int nrf5_configure(const struct device *dev, case IEEE802154_CONFIG_FRAME_COUNTER: nrf_802154_security_global_frame_counter_set(config->frame_counter); break; + + case IEEE802154_CONFIG_FRAME_COUNTER_IF_LARGER: + nrf_802154_security_global_frame_counter_set_if_larger(config->frame_counter); + break; #endif /* CONFIG_IEEE802154_2015 */ case IEEE802154_CONFIG_ENH_ACK_HEADER_IE: { diff --git a/include/zephyr/net/ieee802154_radio.h b/include/zephyr/net/ieee802154_radio.h index 013b793e1bcb..3fa75f0a998c 100644 --- a/include/zephyr/net/ieee802154_radio.h +++ b/include/zephyr/net/ieee802154_radio.h @@ -169,6 +169,12 @@ enum ieee802154_config_type { /** Sets the current MAC frame counter value for radios supporting transmit security. */ IEEE802154_CONFIG_FRAME_COUNTER, + /** Sets the current MAC frame counter value if the provided value is greater than + * the current one. + */ + + IEEE802154_CONFIG_FRAME_COUNTER_IF_LARGER, + /** Configure a radio reception slot. This can be used for any scheduler reception, e.g.: * Zigbee GP device, CSL, TSCH, etc. * diff --git a/modules/openthread/platform/radio.c b/modules/openthread/platform/radio.c index 2859cefc0cd2..1c8b2896e8c5 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -1145,6 +1145,15 @@ void otPlatRadioSetMacFrameCounter(otInstance *aInstance, (void)radio_api->configure(radio_dev, IEEE802154_CONFIG_FRAME_COUNTER, &config); } + +void otPlatRadioSetMacFrameCounterIfLarger(otInstance *aInstance, uint32_t aMacFrameCounter) +{ + ARG_UNUSED(aInstance); + + struct ieee802154_config config = { .frame_counter = aMacFrameCounter }; + (void)radio_api->configure(radio_dev, IEEE802154_CONFIG_FRAME_COUNTER_IF_LARGER, + &config); +} #endif #if defined(CONFIG_OPENTHREAD_CSL_RECEIVER) From 72d80b74be33538b473ea526a29315f8221ee25a Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 2 Mar 2023 13:01:02 +0100 Subject: [PATCH 0018/1906] Bluetooth: Audio: Move stream_reset before released callback In the unicast client we should reset the stream before calling the released callback. This is so that we can reuse the stream object in the released callback. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/bap_unicast_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index d2ece654de80..eb179da46fda 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -451,6 +451,8 @@ static void unicast_client_ep_idle_state(struct bt_bap_ep *ep) return; } + bt_bap_stream_reset(stream); + /* Notify upper layer */ ops = stream->ops; if (ops != NULL && ops->released != NULL) { @@ -458,8 +460,6 @@ static void unicast_client_ep_idle_state(struct bt_bap_ep *ep) } else { LOG_WRN("No callback for released set"); } - - bt_bap_stream_reset(stream); } static void unicast_client_ep_qos_update(struct bt_bap_ep *ep, From ab410807bcc73fe9e88fb6c2dba393e2750aa4c1 Mon Sep 17 00:00:00 2001 From: Bartlomiej Fijal Date: Wed, 8 Mar 2023 07:56:31 +0100 Subject: [PATCH 0019/1906] dts: arm: st: h7: nucleo_stm32h723zg: add red_led Add red led to the dts file for the nucleo_stm32h723zg. Signed-off-by: Bartlomiej Fijal --- boards/arm/nucleo_h723zg/nucleo_h723zg.dts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/boards/arm/nucleo_h723zg/nucleo_h723zg.dts b/boards/arm/nucleo_h723zg/nucleo_h723zg.dts index 6a98ed55d1da..0addd56d72bc 100644 --- a/boards/arm/nucleo_h723zg/nucleo_h723zg.dts +++ b/boards/arm/nucleo_h723zg/nucleo_h723zg.dts @@ -35,6 +35,10 @@ gpios = <&gpioe 1 GPIO_ACTIVE_HIGH>; label = "User LD2"; }; + red_led: led_2 { + gpios = <&gpiob 14 GPIO_ACTIVE_HIGH>; + label = "User LD3"; + }; }; pwmleds { @@ -57,6 +61,7 @@ aliases { led0 = &green_led; led1 = &yellow_led; + led2 = &red_led; pwm-led0 = &red_pwm_led; sw0 = &user_button; }; From 4dfca4282dacf886625a17d113843a8fb1c8c269 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 8 Feb 2023 15:14:40 +0100 Subject: [PATCH 0020/1906] bluetooth: tester: Prefix tester BTP protocol defines Make all BTP related defines and structures prefixed with BTP. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp.c | 34 +- tests/bluetooth/tester/src/btp/btp_aics.h | 24 +- tests/bluetooth/tester/src/btp/btp_bap.h | 24 +- tests/bluetooth/tester/src/btp/btp_core.h | 18 +- tests/bluetooth/tester/src/btp/btp_gap.h | 256 +++---- tests/bluetooth/tester/src/btp/btp_gatt.h | 200 +++--- tests/bluetooth/tester/src/btp/btp_ias.h | 4 +- tests/bluetooth/tester/src/btp/btp_l2cap.h | 74 +- tests/bluetooth/tester/src/btp/btp_mesh.h | 332 ++++----- tests/bluetooth/tester/src/btp/btp_vcs.h | 14 +- tests/bluetooth/tester/src/btp/btp_vocs.h | 10 +- tests/bluetooth/tester/src/btp_bap.c | 26 +- tests/bluetooth/tester/src/btp_gap.c | 338 +++++----- tests/bluetooth/tester/src/btp_gatt.c | 344 +++++----- tests/bluetooth/tester/src/btp_ias.c | 12 +- tests/bluetooth/tester/src/btp_l2cap.c | 104 +-- tests/bluetooth/tester/src/btp_mesh.c | 750 ++++++++++----------- tests/bluetooth/tester/src/btp_vcp.c | 148 ++-- 18 files changed, 1355 insertions(+), 1357 deletions(-) diff --git a/tests/bluetooth/tester/src/btp.c b/tests/bluetooth/tester/src/btp.c index 5fc382ce0a5e..c7e1c80317d3 100644 --- a/tests/bluetooth/tester/src/btp.c +++ b/tests/bluetooth/tester/src/btp.c @@ -45,23 +45,23 @@ static K_FIFO_DEFINE(avail_queue); static void supported_commands(uint8_t *data, uint16_t len) { uint8_t buf[1]; - struct core_read_supported_commands_rp *rp = (void *) buf; + struct btp_core_read_supported_commands_rp *rp = (void *) buf; (void)memset(buf, 0, sizeof(buf)); - tester_set_bit(buf, CORE_READ_SUPPORTED_COMMANDS); - tester_set_bit(buf, CORE_READ_SUPPORTED_SERVICES); - tester_set_bit(buf, CORE_REGISTER_SERVICE); - tester_set_bit(buf, CORE_UNREGISTER_SERVICE); + tester_set_bit(buf, BTP_CORE_READ_SUPPORTED_COMMANDS); + tester_set_bit(buf, BTP_CORE_READ_SUPPORTED_SERVICES); + tester_set_bit(buf, BTP_CORE_REGISTER_SERVICE); + tester_set_bit(buf, BTP_CORE_UNREGISTER_SERVICE); - tester_send(BTP_SERVICE_ID_CORE, CORE_READ_SUPPORTED_COMMANDS, + tester_send(BTP_SERVICE_ID_CORE, BTP_CORE_READ_SUPPORTED_COMMANDS, BTP_INDEX_NONE, (uint8_t *) rp, sizeof(buf)); } static void supported_services(uint8_t *data, uint16_t len) { uint8_t buf[2]; - struct core_read_supported_services_rp *rp = (void *) buf; + struct btp_core_read_supported_services_rp *rp = (void *) buf; (void)memset(buf, 0, sizeof(buf)); @@ -87,13 +87,13 @@ static void supported_services(uint8_t *data, uint16_t len) tester_set_bit(buf, BTP_SERVICE_ID_VOCS); #endif /* CONFIG_BT_VOCS */ - tester_send(BTP_SERVICE_ID_CORE, CORE_READ_SUPPORTED_SERVICES, + tester_send(BTP_SERVICE_ID_CORE, BTP_CORE_READ_SUPPORTED_SERVICES, BTP_INDEX_NONE, (uint8_t *) rp, sizeof(buf)); } static void register_service(uint8_t *data, uint16_t len) { - struct core_register_service_cmd *cmd = (void *) data; + struct btp_core_register_service_cmd *cmd = (void *) data; uint8_t status; switch (cmd->id) { @@ -149,13 +149,13 @@ static void register_service(uint8_t *data, uint16_t len) } rsp: - tester_rsp(BTP_SERVICE_ID_CORE, CORE_REGISTER_SERVICE, BTP_INDEX_NONE, + tester_rsp(BTP_SERVICE_ID_CORE, BTP_CORE_REGISTER_SERVICE, BTP_INDEX_NONE, status); } static void unregister_service(uint8_t *data, uint16_t len) { - struct core_unregister_service_cmd *cmd = (void *) data; + struct btp_core_unregister_service_cmd *cmd = (void *) data; uint8_t status; switch (cmd->id) { @@ -201,7 +201,7 @@ static void unregister_service(uint8_t *data, uint16_t len) break; } - tester_rsp(BTP_SERVICE_ID_CORE, CORE_UNREGISTER_SERVICE, BTP_INDEX_NONE, + tester_rsp(BTP_SERVICE_ID_CORE, BTP_CORE_UNREGISTER_SERVICE, BTP_INDEX_NONE, status); } @@ -215,16 +215,16 @@ static void handle_core(uint8_t opcode, uint8_t index, uint8_t *data, } switch (opcode) { - case CORE_READ_SUPPORTED_COMMANDS: + case BTP_CORE_READ_SUPPORTED_COMMANDS: supported_commands(data, len); return; - case CORE_READ_SUPPORTED_SERVICES: + case BTP_CORE_READ_SUPPORTED_SERVICES: supported_services(data, len); return; - case CORE_REGISTER_SERVICE: + case BTP_CORE_REGISTER_SERVICE: register_service(data, len); return; - case CORE_UNREGISTER_SERVICE: + case BTP_CORE_UNREGISTER_SERVICE: unregister_service(data, len); return; default: @@ -410,7 +410,7 @@ void tester_init(void) uart_init(buf->data); - tester_send(BTP_SERVICE_ID_CORE, CORE_EV_IUT_READY, BTP_INDEX_NONE, + tester_send(BTP_SERVICE_ID_CORE, BTP_CORE_EV_IUT_READY, BTP_INDEX_NONE, NULL, 0); } diff --git a/tests/bluetooth/tester/src/btp/btp_aics.h b/tests/bluetooth/tester/src/btp/btp_aics.h index 202c152b5414..addd0b4f9fce 100644 --- a/tests/bluetooth/tester/src/btp/btp_aics.h +++ b/tests/bluetooth/tester/src/btp/btp_aics.h @@ -8,23 +8,23 @@ #include -#define AICS_READ_SUPPORTED_COMMANDS 0x01 +#define BTP_AICS_READ_SUPPORTED_COMMANDS 0x01 -#define AICS_SET_GAIN 0x02 -#define AICS_MUTE 0x03 -#define AICS_UNMUTE 0x04 -#define AICS_MAN_GAIN 0x05 -#define AICS_AUTO_GAIN 0x06 -#define AICS_MAN_GAIN_ONLY 0x07 -#define AICS_AUTO_GAIN_ONLY 0x08 -#define AICS_DESCRIPTION 0x09 -#define AICS_MUTE_DISABLE 0x0a +#define BTP_AICS_SET_GAIN 0x02 +#define BTP_AICS_MUTE 0x03 +#define BTP_AICS_UNMUTE 0x04 +#define BTP_AICS_MAN_GAIN 0x05 +#define BTP_AICS_AUTO_GAIN 0x06 +#define BTP_AICS_MAN_GAIN_ONLY 0x07 +#define BTP_AICS_AUTO_GAIN_ONLY 0x08 +#define BTP_AICS_DESCRIPTION 0x09 +#define BTP_AICS_MUTE_DISABLE 0x0a -struct aics_set_gain { +struct btp_aics_set_gain { int8_t gain; } __packed; -struct aics_audio_desc { +struct btp_aics_audio_desc { uint8_t desc_len; uint8_t desc[0]; } __packed; diff --git a/tests/bluetooth/tester/src/btp/btp_bap.h b/tests/bluetooth/tester/src/btp/btp_bap.h index 515975669abf..f0fab1553ea1 100644 --- a/tests/bluetooth/tester/src/btp/btp_bap.h +++ b/tests/bluetooth/tester/src/btp/btp_bap.h @@ -6,22 +6,20 @@ * SPDX-License-Identifier: Apache-2.0 */ - -#define PACS_CHARACTERISTIC_SINK_PAC 0x01 -#define PACS_CHARACTERISTIC_SOURCE_PAC 0x02 -#define PACS_CHARACTERISTIC_SINK_AUDIO_LOCATIONS 0x03 -#define PACS_CHARACTERISTIC_SOURCE_AUDIO_LOCATIONS 0x04 -#define PACS_CHARACTERISTIC_AVAILABLE_AUDIO_CONTEXTS 0x05 -#define PACS_CHARACTERISTIC_SUPPORTED_AUDIO_CONTEXTS 0x06 - - /* PACS commands */ -#define PACS_READ_SUPPORTED_COMMANDS 0x01 -struct pacs_read_supported_commands_rp { +#define BTP_PACS_READ_SUPPORTED_COMMANDS 0x01 +struct btp_pacs_read_supported_commands_rp { uint8_t data[0]; } __packed; -#define PACS_UPDATE_CHARACTERISTIC 0x02 -struct pacs_update_characteristic_cmd { +#define BTP_PACS_CHARACTERISTIC_SINK_PAC 0x01 +#define BTP_PACS_CHARACTERISTIC_SOURCE_PAC 0x02 +#define BTP_PACS_CHARACTERISTIC_SINK_AUDIO_LOCATIONS 0x03 +#define BTP_PACS_CHARACTERISTIC_SOURCE_AUDIO_LOCATIONS 0x04 +#define BTP_PACS_CHARACTERISTIC_AVAILABLE_AUDIO_CONTEXTS 0x05 +#define BTP_PACS_CHARACTERISTIC_SUPPORTED_AUDIO_CONTEXTS 0x06 + +#define BTP_PACS_UPDATE_CHARACTERISTIC 0x02 +struct btp_pacs_update_characteristic_cmd { uint8_t characteristic; } __packed; diff --git a/tests/bluetooth/tester/src/btp/btp_core.h b/tests/bluetooth/tester/src/btp/btp_core.h index 749c7fc98ec7..c31b7f8dee62 100644 --- a/tests/bluetooth/tester/src/btp/btp_core.h +++ b/tests/bluetooth/tester/src/btp/btp_core.h @@ -11,25 +11,25 @@ #include /* Core Service */ -#define CORE_READ_SUPPORTED_COMMANDS 0x01 -struct core_read_supported_commands_rp { +#define BTP_CORE_READ_SUPPORTED_COMMANDS 0x01 +struct btp_core_read_supported_commands_rp { uint8_t data[0]; } __packed; -#define CORE_READ_SUPPORTED_SERVICES 0x02 -struct core_read_supported_services_rp { +#define BTP_CORE_READ_SUPPORTED_SERVICES 0x02 +struct btp_core_read_supported_services_rp { uint8_t data[0]; } __packed; -#define CORE_REGISTER_SERVICE 0x03 -struct core_register_service_cmd { +#define BTP_CORE_REGISTER_SERVICE 0x03 +struct btp_core_register_service_cmd { uint8_t id; } __packed; -#define CORE_UNREGISTER_SERVICE 0x04 -struct core_unregister_service_cmd { +#define BTP_CORE_UNREGISTER_SERVICE 0x04 +struct btp_core_unregister_service_cmd { uint8_t id; } __packed; /* events */ -#define CORE_EV_IUT_READY 0x80 +#define BTP_CORE_EV_IUT_READY 0x80 diff --git a/tests/bluetooth/tester/src/btp/btp_gap.h b/tests/bluetooth/tester/src/btp/btp_gap.h index 6cf21e79625f..d56398f86eb8 100644 --- a/tests/bluetooth/tester/src/btp/btp_gap.h +++ b/tests/bluetooth/tester/src/btp/btp_gap.h @@ -12,36 +12,36 @@ /* GAP Service */ /* commands */ -#define GAP_READ_SUPPORTED_COMMANDS 0x01 -struct gap_read_supported_commands_rp { +#define BTP_GAP_READ_SUPPORTED_COMMANDS 0x01 +struct btp_gap_read_supported_commands_rp { uint8_t data[0]; } __packed; -#define GAP_READ_CONTROLLER_INDEX_LIST 0x02 -struct gap_read_controller_index_list_rp { +#define BTP_GAP_READ_CONTROLLER_INDEX_LIST 0x02 +struct btp_gap_read_controller_index_list_rp { uint8_t num; uint8_t index[]; } __packed; -#define GAP_SETTINGS_POWERED 0 -#define GAP_SETTINGS_CONNECTABLE 1 -#define GAP_SETTINGS_FAST_CONNECTABLE 2 -#define GAP_SETTINGS_DISCOVERABLE 3 -#define GAP_SETTINGS_BONDABLE 4 -#define GAP_SETTINGS_LINK_SEC_3 5 -#define GAP_SETTINGS_SSP 6 -#define GAP_SETTINGS_BREDR 7 -#define GAP_SETTINGS_HS 8 -#define GAP_SETTINGS_LE 9 -#define GAP_SETTINGS_ADVERTISING 10 -#define GAP_SETTINGS_SC 11 -#define GAP_SETTINGS_DEBUG_KEYS 12 -#define GAP_SETTINGS_PRIVACY 13 -#define GAP_SETTINGS_CONTROLLER_CONFIG 14 -#define GAP_SETTINGS_STATIC_ADDRESS 15 - -#define GAP_READ_CONTROLLER_INFO 0x03 -struct gap_read_controller_info_rp { +#define BTP_GAP_SETTINGS_POWERED 0 +#define BTP_GAP_SETTINGS_CONNECTABLE 1 +#define BTP_GAP_SETTINGS_FAST_CONNECTABLE 2 +#define BTP_GAP_SETTINGS_DISCOVERABLE 3 +#define BTP_GAP_SETTINGS_BONDABLE 4 +#define BTP_GAP_SETTINGS_LINK_SEC_3 5 +#define BTP_GAP_SETTINGS_SSP 6 +#define BTP_GAP_SETTINGS_BREDR 7 +#define BTP_GAP_SETTINGS_HS 8 +#define BTP_GAP_SETTINGS_LE 9 +#define BTP_GAP_SETTINGS_ADVERTISING 10 +#define BTP_GAP_SETTINGS_SC 11 +#define BTP_GAP_SETTINGS_DEBUG_KEYS 12 +#define BTP_GAP_SETTINGS_PRIVACY 13 +#define BTP_GAP_SETTINGS_CONTROLLER_CONFIG 14 +#define BTP_GAP_SETTINGS_STATIC_ADDRESS 15 + +#define BTP_GAP_READ_CONTROLLER_INFO 0x03 +struct btp_gap_read_controller_info_rp { uint8_t address[6]; uint32_t supported_settings; uint32_t current_settings; @@ -50,149 +50,149 @@ struct gap_read_controller_info_rp { uint8_t short_name[11]; } __packed; -#define GAP_RESET 0x04 -struct gap_reset_rp { +#define BTP_GAP_RESET 0x04 +struct btp_gap_reset_rp { uint32_t current_settings; } __packed; -#define GAP_SET_POWERED 0x05 -struct gap_set_powered_cmd { +#define BTP_GAP_SET_POWERED 0x05 +struct btp_gap_set_powered_cmd { uint8_t powered; } __packed; -struct gap_set_powered_rp { +struct btp_gap_set_powered_rp { uint32_t current_settings; } __packed; -#define GAP_SET_CONNECTABLE 0x06 -struct gap_set_connectable_cmd { +#define BTP_GAP_SET_CONNECTABLE 0x06 +struct btp_gap_set_connectable_cmd { uint8_t connectable; } __packed; -struct gap_set_connectable_rp { +struct btp_gap_set_connectable_rp { uint32_t current_settings; } __packed; -#define GAP_SET_FAST_CONNECTABLE 0x07 -struct gap_set_fast_connectable_cmd { +#define BTP_GAP_SET_FAST_CONNECTABLE 0x07 +struct btp_gap_set_fast_connectable_cmd { uint8_t fast_connectable; } __packed; -struct gap_set_fast_connectable_rp { +struct btp_gap_set_fast_connectable_rp { uint32_t current_settings; } __packed; -#define GAP_NON_DISCOVERABLE 0x00 -#define GAP_GENERAL_DISCOVERABLE 0x01 -#define GAP_LIMITED_DISCOVERABLE 0x02 +#define BTP_GAP_NON_DISCOVERABLE 0x00 +#define BTP_GAP_GENERAL_DISCOVERABLE 0x01 +#define BTP_GAP_LIMITED_DISCOVERABLE 0x02 -#define GAP_SET_DISCOVERABLE 0x08 -struct gap_set_discoverable_cmd { +#define BTP_GAP_SET_DISCOVERABLE 0x08 +struct btp_gap_set_discoverable_cmd { uint8_t discoverable; } __packed; -struct gap_set_discoverable_rp { +struct btp_gap_set_discoverable_rp { uint32_t current_settings; } __packed; -#define GAP_SET_BONDABLE 0x09 -struct gap_set_bondable_cmd { +#define BTP_GAP_SET_BONDABLE 0x09 +struct btp_gap_set_bondable_cmd { uint8_t bondable; } __packed; -struct gap_set_bondable_rp { +struct btp_gap_set_bondable_rp { uint32_t current_settings; } __packed; -#define GAP_START_ADVERTISING 0x0a -struct gap_start_advertising_cmd { +#define BTP_GAP_START_ADVERTISING 0x0a +struct btp_gap_start_advertising_cmd { uint8_t adv_data_len; uint8_t scan_rsp_len; uint8_t adv_sr_data[]; } __packed; -struct gap_start_advertising_rp { +struct btp_gap_start_advertising_rp { uint32_t current_settings; } __packed; -#define GAP_STOP_ADVERTISING 0x0b -struct gap_stop_advertising_rp { +#define BTP_GAP_STOP_ADVERTISING 0x0b +struct btp_gap_stop_advertising_rp { uint32_t current_settings; } __packed; -#define GAP_DISCOVERY_FLAG_LE 0x01 -#define GAP_DISCOVERY_FLAG_BREDR 0x02 -#define GAP_DISCOVERY_FLAG_LIMITED 0x04 -#define GAP_DISCOVERY_FLAG_LE_ACTIVE_SCAN 0x08 -#define GAP_DISCOVERY_FLAG_LE_OBSERVE 0x10 -#define GAP_DISCOVERY_FLAG_OWN_ID_ADDR 0x20 +#define BTP_GAP_DISCOVERY_FLAG_LE 0x01 +#define BTP_GAP_DISCOVERY_FLAG_BREDR 0x02 +#define BTP_GAP_DISCOVERY_FLAG_LIMITED 0x04 +#define BTP_GAP_DISCOVERY_FLAG_LE_ACTIVE_SCAN 0x08 +#define BTP_GAP_DISCOVERY_FLAG_LE_OBSERVE 0x10 +#define BTP_GAP_DISCOVERY_FLAG_OWN_ID_ADDR 0x20 -#define GAP_START_DISCOVERY 0x0c -struct gap_start_discovery_cmd { +#define BTP_GAP_START_DISCOVERY 0x0c +struct btp_gap_start_discovery_cmd { uint8_t flags; } __packed; -#define GAP_STOP_DISCOVERY 0x0d +#define BTP_GAP_STOP_DISCOVERY 0x0d -#define GAP_CONNECT 0x0e -struct gap_connect_cmd { +#define BTP_GAP_CONNECT 0x0e +struct btp_gap_connect_cmd { uint8_t address_type; uint8_t address[6]; } __packed; -#define GAP_DISCONNECT 0x0f -struct gap_disconnect_cmd { +#define BTP_GAP_DISCONNECT 0x0f +struct btp_gap_disconnect_cmd { uint8_t address_type; uint8_t address[6]; } __packed; -#define GAP_IO_CAP_DISPLAY_ONLY 0 -#define GAP_IO_CAP_DISPLAY_YESNO 1 -#define GAP_IO_CAP_KEYBOARD_ONLY 2 -#define GAP_IO_CAP_NO_INPUT_OUTPUT 3 -#define GAP_IO_CAP_KEYBOARD_DISPLAY 4 +#define BTP_GAP_IO_CAP_DISPLAY_ONLY 0 +#define BTP_GAP_IO_CAP_DISPLAY_YESNO 1 +#define BTP_GAP_IO_CAP_KEYBOARD_ONLY 2 +#define BTP_GAP_IO_CAP_NO_INPUT_OUTPUT 3 +#define BTP_GAP_IO_CAP_KEYBOARD_DISPLAY 4 -#define GAP_SET_IO_CAP 0x10 -struct gap_set_io_cap_cmd { +#define BTP_GAP_SET_IO_CAP 0x10 +struct btp_gap_set_io_cap_cmd { uint8_t io_cap; } __packed; -#define GAP_PAIR 0x11 -struct gap_pair_cmd { +#define BTP_GAP_PAIR 0x11 +struct btp_gap_pair_cmd { uint8_t address_type; uint8_t address[6]; } __packed; -#define GAP_UNPAIR 0x12 -struct gap_unpair_cmd { +#define BTP_GAP_UNPAIR 0x12 +struct btp_gap_unpair_cmd { uint8_t address_type; uint8_t address[6]; } __packed; -#define GAP_PASSKEY_ENTRY 0x13 -struct gap_passkey_entry_cmd { +#define BTP_GAP_PASSKEY_ENTRY 0x13 +struct btp_gap_passkey_entry_cmd { uint8_t address_type; uint8_t address[6]; uint32_t passkey; } __packed; -#define GAP_PASSKEY_CONFIRM 0x14 -struct gap_passkey_confirm_cmd { +#define BTP_GAP_PASSKEY_CONFIRM 0x14 +struct btp_gap_passkey_confirm_cmd { uint8_t address_type; uint8_t address[6]; uint8_t match; } __packed; -#define GAP_START_DIRECTED_ADV_HD BIT(0) -#define GAP_START_DIRECTED_ADV_OWN_ID BIT(1) -#define GAP_START_DIRECTED_ADV_PEER_RPA BIT(2) +#define BTP_GAP_START_DIRECTED_ADV_HD BIT(0) +#define BTP_GAP_START_DIRECTED_ADV_OWN_ID BIT(1) +#define BTP_GAP_START_DIRECTED_ADV_PEER_RPA BIT(2) -#define GAP_START_DIRECTED_ADV 0x15 -struct gap_start_directed_adv_cmd { +#define BTP_GAP_START_DIRECTED_ADV 0x15 +struct btp_gap_start_directed_adv_cmd { uint8_t address_type; uint8_t address[6]; uint16_t options; } __packed; -struct gap_start_directed_adv_rp { +struct btp_gap_start_directed_adv_rp { uint32_t current_settings; } __packed; -#define GAP_CONN_PARAM_UPDATE 0x16 -struct gap_conn_param_update_cmd { +#define BTP_GAP_CONN_PARAM_UPDATE 0x16 +struct btp_gap_conn_param_update_cmd { uint8_t address_type; uint8_t address[6]; uint16_t interval_min; @@ -201,53 +201,53 @@ struct gap_conn_param_update_cmd { uint16_t timeout; } __packed; -#define GAP_PAIRING_CONSENT 0x17 -struct gap_pairing_consent_cmd { +#define BTP_GAP_PAIRING_CONSENT 0x17 +struct btp_gap_pairing_consent_cmd { uint8_t address_type; uint8_t address[6]; uint8_t consent; } __packed; -#define GAP_OOB_LEGACY_SET_DATA 0x18 -struct gap_oob_legacy_set_data_cmd { +#define BTP_GAP_OOB_LEGACY_SET_DATA 0x18 +struct btp_gap_oob_legacy_set_data_cmd { uint8_t oob_data[16]; } __packed; -#define GAP_OOB_SC_GET_LOCAL_DATA 0x19 -struct gap_oob_sc_get_local_data_rp { +#define BTP_GAP_OOB_SC_GET_LOCAL_DATA 0x19 +struct btp_gap_oob_sc_get_local_data_rp { uint8_t rand[16]; uint8_t conf[16]; } __packed; -#define GAP_OOB_SC_SET_REMOTE_DATA 0x1a -struct gap_oob_sc_set_remote_data_cmd { +#define BTP_GAP_OOB_SC_SET_REMOTE_DATA 0x1a +struct btp_gap_oob_sc_set_remote_data_cmd { uint8_t rand[16]; uint8_t conf[16]; } __packed; -#define GAP_SET_MITM 0x1b -struct gap_set_mitm { +#define BTP_GAP_SET_MITM 0x1b +struct btp_gap_set_mitm { uint8_t mitm; } __packed; -#define GAP_SET_FILTER_LIST 0x1c -struct gap_set_filter_list { +#define BTP_GAP_SET_FILTER_LIST 0x1c +struct btp_gap_set_filter_list { uint8_t cnt; bt_addr_le_t addr[0]; } __packed; /* events */ -#define GAP_EV_NEW_SETTINGS 0x80 -struct gap_new_settings_ev { +#define BTP_GAP_EV_NEW_SETTINGS 0x80 +struct btp_gap_new_settings_ev { uint32_t current_settings; } __packed; -#define GAP_DEVICE_FOUND_FLAG_RSSI 0x01 -#define GAP_DEVICE_FOUND_FLAG_AD 0x02 -#define GAP_DEVICE_FOUND_FLAG_SD 0x04 +#define BTP_GAP_DEVICE_FOUND_FLAG_RSSI 0x01 +#define BTP_GAP_DEVICE_FOUND_FLAG_AD 0x02 +#define BTP_GAP_DEVICE_FOUND_FLAG_SD 0x04 -#define GAP_EV_DEVICE_FOUND 0x81 -struct gap_device_found_ev { +#define BTP_GAP_EV_DEVICE_FOUND 0x81 +struct btp_gap_device_found_ev { uint8_t address_type; uint8_t address[6]; int8_t rssi; @@ -256,8 +256,8 @@ struct gap_device_found_ev { uint8_t eir_data[]; } __packed; -#define GAP_EV_DEVICE_CONNECTED 0x82 -struct gap_device_connected_ev { +#define BTP_GAP_EV_DEVICE_CONNECTED 0x82 +struct btp_gap_device_connected_ev { uint8_t address_type; uint8_t address[6]; uint16_t interval; @@ -265,42 +265,42 @@ struct gap_device_connected_ev { uint16_t timeout; } __packed; -#define GAP_EV_DEVICE_DISCONNECTED 0x83 -struct gap_device_disconnected_ev { +#define BTP_GAP_EV_DEVICE_DISCONNECTED 0x83 +struct btp_gap_device_disconnected_ev { uint8_t address_type; uint8_t address[6]; } __packed; -#define GAP_EV_PASSKEY_DISPLAY 0x84 -struct gap_passkey_display_ev { +#define BTP_GAP_EV_PASSKEY_DISPLAY 0x84 +struct btp_gap_passkey_display_ev { uint8_t address_type; uint8_t address[6]; uint32_t passkey; } __packed; -#define GAP_EV_PASSKEY_ENTRY_REQ 0x85 -struct gap_passkey_entry_req_ev { +#define BTP_GAP_EV_PASSKEY_ENTRY_REQ 0x85 +struct btp_gap_passkey_entry_req_ev { uint8_t address_type; uint8_t address[6]; } __packed; -#define GAP_EV_PASSKEY_CONFIRM_REQ 0x86 -struct gap_passkey_confirm_req_ev { +#define BTP_GAP_EV_PASSKEY_CONFIRM_REQ 0x86 +struct btp_gap_passkey_confirm_req_ev { uint8_t address_type; uint8_t address[6]; uint32_t passkey; } __packed; -#define GAP_EV_IDENTITY_RESOLVED 0x87 -struct gap_identity_resolved_ev { +#define BTP_GAP_EV_IDENTITY_RESOLVED 0x87 +struct btp_gap_identity_resolved_ev { uint8_t address_type; uint8_t address[6]; uint8_t identity_address_type; uint8_t identity_address[6]; } __packed; -#define GAP_EV_CONN_PARAM_UPDATE 0x88 -struct gap_conn_param_update_ev { +#define BTP_GAP_EV_CONN_PARAM_UPDATE 0x88 +struct btp_gap_conn_param_update_ev { uint8_t address_type; uint8_t address[6]; uint16_t interval; @@ -308,31 +308,31 @@ struct gap_conn_param_update_ev { uint16_t timeout; } __packed; -#define GAP_SEC_LEVEL_UNAUTH_ENC 0x01 -#define GAP_SEC_LEVEL_AUTH_ENC 0x02 -#define GAP_SEC_LEVEL_AUTH_SC 0x03 +#define BTP_GAP_SEC_LEVEL_UNAUTH_ENC 0x01 +#define BTP_GAP_SEC_LEVEL_AUTH_ENC 0x02 +#define BTP_GAP_SEC_LEVEL_AUTH_SC 0x03 -#define GAP_EV_SEC_LEVEL_CHANGED 0x89 -struct gap_sec_level_changed_ev { +#define BTP_GAP_EV_SEC_LEVEL_CHANGED 0x89 +struct btp_gap_sec_level_changed_ev { uint8_t address_type; uint8_t address[6]; uint8_t sec_level; } __packed; -#define GAP_EV_PAIRING_CONSENT_REQ 0x8a -struct gap_pairing_consent_req_ev { +#define BTP_GAP_EV_PAIRING_CONSENT_REQ 0x8a +struct btp_gap_pairing_consent_req_ev { uint8_t address_type; uint8_t address[6]; } __packed; -#define GAP_EV_BOND_LOST 0x8b -struct gap_bond_lost_ev { +#define BTP_GAP_EV_BOND_LOST 0x8b +struct btp_gap_bond_lost_ev { uint8_t address_type; uint8_t address[6]; } __packed; -#define GAP_EV_PAIRING_FAILED 0x8c -struct gap_bond_pairing_failed_ev { +#define BTP_GAP_EV_PAIRING_FAILED 0x8c +struct btp_gap_bond_pairing_failed_ev { uint8_t address_type; uint8_t address[6]; uint8_t reason; diff --git a/tests/bluetooth/tester/src/btp/btp_gatt.h b/tests/bluetooth/tester/src/btp/btp_gatt.h index 20516602c9db..65fe4f0e6440 100644 --- a/tests/bluetooth/tester/src/btp/btp_gatt.h +++ b/tests/bluetooth/tester/src/btp/btp_gatt.h @@ -12,90 +12,90 @@ /* GATT Service */ /* commands */ -#define GATT_READ_SUPPORTED_COMMANDS 0x01 -struct gatt_read_supported_commands_rp { +#define BTP_GATT_READ_SUPPORTED_COMMANDS 0x01 +struct btp_gatt_read_supported_commands_rp { uint8_t data[0]; } __packed; -#define GATT_SERVICE_PRIMARY 0x00 -#define GATT_SERVICE_SECONDARY 0x01 +#define BTP_GATT_SERVICE_PRIMARY 0x00 +#define BTP_GATT_SERVICE_SECONDARY 0x01 -#define GATT_ADD_SERVICE 0x02 -struct gatt_add_service_cmd { +#define BTP_GATT_ADD_SERVICE 0x02 +struct btp_gatt_add_service_cmd { uint8_t type; uint8_t uuid_length; uint8_t uuid[]; } __packed; -struct gatt_add_service_rp { +struct btp_gatt_add_service_rp { uint16_t svc_id; } __packed; -#define GATT_ADD_CHARACTERISTIC 0x03 -struct gatt_add_characteristic_cmd { +#define BTP_GATT_ADD_CHARACTERISTIC 0x03 +struct btp_gatt_add_characteristic_cmd { uint16_t svc_id; uint8_t properties; uint8_t permissions; uint8_t uuid_length; uint8_t uuid[]; } __packed; -struct gatt_add_characteristic_rp { +struct btp_gatt_add_characteristic_rp { uint16_t char_id; } __packed; -#define GATT_ADD_DESCRIPTOR 0x04 -struct gatt_add_descriptor_cmd { +#define BTP_GATT_ADD_DESCRIPTOR 0x04 +struct btp_gatt_add_descriptor_cmd { uint16_t char_id; uint8_t permissions; uint8_t uuid_length; uint8_t uuid[]; } __packed; -struct gatt_add_descriptor_rp { +struct btp_gatt_add_descriptor_rp { uint16_t desc_id; } __packed; -#define GATT_ADD_INCLUDED_SERVICE 0x05 -struct gatt_add_included_service_cmd { +#define BTP_GATT_ADD_INCLUDED_SERVICE 0x05 +struct btp_gatt_add_included_service_cmd { uint16_t svc_id; } __packed; -struct gatt_add_included_service_rp { +struct btp_gatt_add_included_service_rp { uint16_t included_service_id; } __packed; -#define GATT_SET_VALUE 0x06 - struct gatt_set_value_cmd { +#define BTP_GATT_SET_VALUE 0x06 +struct btp_gatt_set_value_cmd { uint16_t attr_id; uint16_t len; uint8_t value[]; } __packed; -#define GATT_START_SERVER 0x07 -struct gatt_start_server_rp { +#define BTP_GATT_START_SERVER 0x07 +struct btp_gatt_start_server_rp { uint16_t db_attr_off; uint8_t db_attr_cnt; } __packed; -#define GATT_RESET_SERVER 0x08 +#define BTP_GATT_RESET_SERVER 0x08 -#define GATT_SET_ENC_KEY_SIZE 0x09 -struct gatt_set_enc_key_size_cmd { +#define BTP_GATT_SET_ENC_KEY_SIZE 0x09 +struct btp_gatt_set_enc_key_size_cmd { uint16_t attr_id; uint8_t key_size; } __packed; /* Gatt Client */ -struct gatt_service { +struct btp_gatt_service { uint16_t start_handle; uint16_t end_handle; uint8_t uuid_length; uint8_t uuid[]; } __packed; -struct gatt_included { +struct btp_gatt_included { uint16_t included_handle; - struct gatt_service service; + struct btp_gatt_service service; } __packed; -struct gatt_characteristic { +struct btp_gatt_characteristic { uint16_t characteristic_handle; uint16_t value_handle; uint8_t properties; @@ -103,66 +103,66 @@ struct gatt_characteristic { uint8_t uuid[]; } __packed; -struct gatt_descriptor { +struct btp_gatt_descriptor { uint16_t descriptor_handle; uint8_t uuid_length; uint8_t uuid[]; } __packed; -#define GATT_EXCHANGE_MTU 0x0a -struct gatt_exchange_mtu_cmd { +#define BTP_GATT_EXCHANGE_MTU 0x0a +struct btp_gatt_exchange_mtu_cmd { uint8_t address_type; uint8_t address[6]; } __packed; -#define GATT_DISC_ALL_PRIM 0x0b -struct gatt_disc_all_prim_cmd { +#define BTP_GATT_DISC_ALL_PRIM 0x0b +struct btp_gatt_disc_all_prim_cmd { uint8_t address_type; uint8_t address[6]; } __packed; -struct gatt_disc_all_prim_rp { +struct btp_gatt_disc_all_prim_rp { uint8_t services_count; - struct gatt_service services[]; + struct btp_gatt_service services[]; } __packed; -#define GATT_DISC_PRIM_UUID 0x0c -struct gatt_disc_prim_uuid_cmd { +#define BTP_GATT_DISC_PRIM_UUID 0x0c +struct btp_gatt_disc_prim_uuid_cmd { uint8_t address_type; uint8_t address[6]; uint8_t uuid_length; uint8_t uuid[]; } __packed; -struct gatt_disc_prim_rp { +struct btp_gatt_disc_prim_rp { uint8_t services_count; - struct gatt_service services[]; + struct btp_gatt_service services[]; } __packed; -#define GATT_FIND_INCLUDED 0x0d -struct gatt_find_included_cmd { +#define BTP_GATT_FIND_INCLUDED 0x0d +struct btp_gatt_find_included_cmd { uint8_t address_type; uint8_t address[6]; uint16_t start_handle; uint16_t end_handle; } __packed; -struct gatt_find_included_rp { +struct btp_gatt_find_included_rp { uint8_t services_count; - struct gatt_included included[]; + struct btp_gatt_included included[]; } __packed; -#define GATT_DISC_ALL_CHRC 0x0e -struct gatt_disc_all_chrc_cmd { +#define BTP_GATT_DISC_ALL_CHRC 0x0e +struct btp_gatt_disc_all_chrc_cmd { uint8_t address_type; uint8_t address[6]; uint16_t start_handle; uint16_t end_handle; } __packed; -struct gatt_disc_chrc_rp { +struct btp_gatt_disc_chrc_rp { uint8_t characteristics_count; - struct gatt_characteristic characteristics[]; + struct btp_gatt_characteristic characteristics[]; } __packed; -#define GATT_DISC_CHRC_UUID 0x0f -struct gatt_disc_chrc_uuid_cmd { +#define BTP_GATT_DISC_CHRC_UUID 0x0f +struct btp_gatt_disc_chrc_uuid_cmd { uint8_t address_type; uint8_t address[6]; uint16_t start_handle; @@ -171,38 +171,38 @@ struct gatt_disc_chrc_uuid_cmd { uint8_t uuid[]; } __packed; -#define GATT_DISC_ALL_DESC 0x10 -struct gatt_disc_all_desc_cmd { +#define BTP_GATT_DISC_ALL_DESC 0x10 +struct btp_gatt_disc_all_desc_cmd { uint8_t address_type; uint8_t address[6]; uint16_t start_handle; uint16_t end_handle; } __packed; -struct gatt_disc_all_desc_rp { +struct btp_gatt_disc_all_desc_rp { uint8_t descriptors_count; - struct gatt_descriptor descriptors[]; + struct btp_gatt_descriptor descriptors[]; } __packed; -#define GATT_READ 0x11 -struct gatt_read_cmd { +#define BTP_GATT_READ 0x11 +struct btp_gatt_read_cmd { uint8_t address_type; uint8_t address[6]; uint16_t handle; } __packed; -struct gatt_read_rp { +struct btp_gatt_read_rp { uint8_t att_response; uint16_t data_length; uint8_t data[]; } __packed; -struct gatt_char_value { +struct btp_gatt_char_value { uint16_t handle; uint8_t data_len; uint8_t data[0]; } __packed; -#define GATT_READ_UUID 0x12 -struct gatt_read_uuid_cmd { +#define BTP_GATT_READ_UUID 0x12 +struct btp_gatt_read_uuid_cmd { uint8_t address_type; uint8_t address[6]; uint16_t start_handle; @@ -210,40 +210,40 @@ struct gatt_read_uuid_cmd { uint8_t uuid_length; uint8_t uuid[]; } __packed; -struct gatt_read_uuid_rp { +struct btp_gatt_read_uuid_rp { uint8_t att_response; uint8_t values_count; - struct gatt_char_value values[0]; + struct btp_gatt_char_value values[0]; } __packed; -#define GATT_READ_LONG 0x13 -struct gatt_read_long_cmd { +#define BTP_GATT_READ_LONG 0x13 +struct btp_gatt_read_long_cmd { uint8_t address_type; uint8_t address[6]; uint16_t handle; uint16_t offset; } __packed; -struct gatt_read_long_rp { +struct btp_gatt_read_long_rp { uint8_t att_response; uint16_t data_length; uint8_t data[]; } __packed; -#define GATT_READ_MULTIPLE 0x14 -struct gatt_read_multiple_cmd { +#define BTP_GATT_READ_MULTIPLE 0x14 +struct btp_gatt_read_multiple_cmd { uint8_t address_type; uint8_t address[6]; uint8_t handles_count; uint16_t handles[]; } __packed; -struct gatt_read_multiple_rp { +struct btp_gatt_read_multiple_rp { uint8_t att_response; uint16_t data_length; uint8_t data[]; } __packed; -#define GATT_WRITE_WITHOUT_RSP 0x15 -struct gatt_write_without_rsp_cmd { +#define BTP_GATT_WRITE_WITHOUT_RSP 0x15 +struct btp_gatt_write_without_rsp_cmd { uint8_t address_type; uint8_t address[6]; uint16_t handle; @@ -251,8 +251,8 @@ struct gatt_write_without_rsp_cmd { uint8_t data[]; } __packed; -#define GATT_SIGNED_WRITE_WITHOUT_RSP 0x16 -struct gatt_signed_write_without_rsp_cmd { +#define BTP_GATT_SIGNED_WRITE_WITHOUT_RSP 0x16 +struct btp_gatt_signed_write_without_rsp_cmd { uint8_t address_type; uint8_t address[6]; uint16_t handle; @@ -260,20 +260,20 @@ struct gatt_signed_write_without_rsp_cmd { uint8_t data[]; } __packed; -#define GATT_WRITE 0x17 -struct gatt_write_cmd { +#define BTP_GATT_WRITE 0x17 +struct btp_gatt_write_cmd { uint8_t address_type; uint8_t address[6]; uint16_t handle; uint16_t data_length; uint8_t data[]; } __packed; -struct gatt_write_rp { +struct btp_gatt_write_rp { uint8_t att_response; } __packed; -#define GATT_WRITE_LONG 0x18 -struct gatt_write_long_cmd { +#define BTP_GATT_WRITE_LONG 0x18 +struct btp_gatt_write_long_cmd { uint8_t address_type; uint8_t address[6]; uint16_t handle; @@ -281,12 +281,12 @@ struct gatt_write_long_cmd { uint16_t data_length; uint8_t data[]; } __packed; -struct gatt_write_long_rp { +struct btp_gatt_write_long_rp { uint8_t att_response; } __packed; -#define GATT_RELIABLE_WRITE 0x19 -struct gatt_reliable_write_cmd { +#define BTP_GATT_RELIABLE_WRITE 0x19 +struct btp_gatt_reliable_write_cmd { uint8_t address_type; uint8_t address[6]; uint16_t handle; @@ -294,74 +294,74 @@ struct gatt_reliable_write_cmd { uint16_t data_length; uint8_t data[]; } __packed; -struct gatt_reliable_write_rp { +struct btp_gatt_reliable_write_rp { uint8_t att_response; } __packed; -#define GATT_CFG_NOTIFY 0x1a -#define GATT_CFG_INDICATE 0x1b -struct gatt_cfg_notify_cmd { +#define BTP_GATT_CFG_NOTIFY 0x1a +#define BTP_GATT_CFG_INDICATE 0x1b +struct btp_gatt_cfg_notify_cmd { uint8_t address_type; uint8_t address[6]; uint8_t enable; uint16_t ccc_handle; } __packed; -#define GATT_GET_ATTRIBUTES 0x1c -struct gatt_get_attributes_cmd { +#define BTP_GATT_GET_ATTRIBUTES 0x1c +struct btp_gatt_get_attributes_cmd { uint16_t start_handle; uint16_t end_handle; uint8_t type_length; uint8_t type[]; } __packed; -struct gatt_get_attributes_rp { +struct btp_gatt_get_attributes_rp { uint8_t attrs_count; uint8_t attrs[]; } __packed; -struct gatt_attr { +struct btp_gatt_attr { uint16_t handle; uint8_t permission; uint8_t type_length; uint8_t type[]; } __packed; -#define GATT_GET_ATTRIBUTE_VALUE 0x1d -struct gatt_get_attribute_value_cmd { +#define BTP_GATT_GET_ATTRIBUTE_VALUE 0x1d +struct btp_gatt_get_attribute_value_cmd { uint8_t address_type; uint8_t address[6]; uint16_t handle; } __packed; -struct gatt_get_attribute_value_rp { +struct btp_gatt_get_attribute_value_rp { uint8_t att_response; uint16_t value_length; uint8_t value[]; } __packed; -#define GATT_CHANGE_DB 0x1e -struct gatt_change_db_cmd { +#define BTP_GATT_CHANGE_DB 0x1e +struct btp_gatt_change_db_cmd { uint16_t start_handle; uint8_t visibility; } __packed; -#define GATT_EATT_CONNECT 0x1f -struct gatt_eatt_connect_cmd { +#define BTP_GATT_EATT_CONNECT 0x1f +struct btp_gatt_eatt_connect_cmd { uint8_t address_type; uint8_t address[6]; uint8_t num_channels; } __packed; -#define GATT_READ_MULTIPLE_VAR 0x20 +#define BTP_GATT_READ_MULTIPLE_VAR 0x20 -#define GATT_NOTIFY_MULTIPLE 0x21 -struct gatt_cfg_notify_mult_cmd { +#define BTP_GATT_NOTIFY_MULTIPLE 0x21 +struct btp_gatt_cfg_notify_mult_cmd { uint8_t address_type; uint8_t address[6]; uint16_t cnt; uint16_t attr_id[]; } __packed; /* GATT events */ -#define GATT_EV_NOTIFICATION 0x80 -struct gatt_notification_ev { +#define BTP_GATT_EV_NOTIFICATION 0x80 +struct btp_gatt_notification_ev { uint8_t address_type; uint8_t address[6]; uint8_t type; @@ -370,8 +370,8 @@ struct gatt_notification_ev { uint8_t data[]; } __packed; -#define GATT_EV_ATTR_VALUE_CHANGED 0x81 -struct gatt_attr_value_changed_ev { +#define BTP_GATT_EV_ATTR_VALUE_CHANGED 0x81 +struct btp_gatt_attr_value_changed_ev { uint16_t handle; uint16_t data_length; uint8_t data[]; diff --git a/tests/bluetooth/tester/src/btp/btp_ias.h b/tests/bluetooth/tester/src/btp/btp_ias.h index 8900c7b636e5..64f5a86749b0 100644 --- a/tests/bluetooth/tester/src/btp/btp_ias.h +++ b/tests/bluetooth/tester/src/btp/btp_ias.h @@ -10,7 +10,7 @@ #include /* events */ -#define IAS_EV_OUT_ALERT_ACTION 0x80 -struct ias_alert_action_ev { +#define BTP_IAS_EV_OUT_ALERT_ACTION 0x80 +struct btp_ias_alert_action_ev { uint8_t alert_lvl; } __packed; diff --git a/tests/bluetooth/tester/src/btp/btp_l2cap.h b/tests/bluetooth/tester/src/btp/btp_l2cap.h index b568b4101c1a..c6eedc5d7275 100644 --- a/tests/bluetooth/tester/src/btp/btp_l2cap.h +++ b/tests/bluetooth/tester/src/btp/btp_l2cap.h @@ -12,16 +12,16 @@ /* L2CAP Service */ /* commands */ -#define L2CAP_READ_SUPPORTED_COMMANDS 0x01 -struct l2cap_read_supported_commands_rp { +#define BTP_L2CAP_READ_SUPPORTED_COMMANDS 0x01 +struct btp_l2cap_read_supported_commands_rp { uint8_t data[0]; } __packed; -#define L2CAP_CONNECT_OPT_ECFC 0x01 -#define L2CAP_CONNECT_OPT_HOLD_CREDIT 0x02 +#define BTP_L2CAP_CONNECT_OPT_ECFC 0x01 +#define BTP_L2CAP_CONNECT_OPT_HOLD_CREDIT 0x02 -#define L2CAP_CONNECT 0x02 -struct l2cap_connect_cmd { +#define BTP_L2CAP_CONNECT 0x02 +struct btp_l2cap_connect_cmd { uint8_t address_type; uint8_t address[6]; uint16_t psm; @@ -29,47 +29,47 @@ struct l2cap_connect_cmd { uint8_t num; uint8_t options; } __packed; -struct l2cap_connect_rp { +struct btp_l2cap_connect_rp { uint8_t num; uint8_t chan_id[]; } __packed; -#define L2CAP_DISCONNECT 0x03 -struct l2cap_disconnect_cmd { +#define BTP_L2CAP_DISCONNECT 0x03 +struct btp_l2cap_disconnect_cmd { uint8_t chan_id; } __packed; -#define L2CAP_SEND_DATA 0x04 -struct l2cap_send_data_cmd { +#define BTP_L2CAP_SEND_DATA 0x04 +struct btp_l2cap_send_data_cmd { uint8_t chan_id; uint16_t data_len; uint8_t data[]; } __packed; -#define L2CAP_TRANSPORT_BREDR 0x00 -#define L2CAP_TRANSPORT_LE 0x01 +#define BTP_L2CAP_TRANSPORT_BREDR 0x00 +#define BTP_L2CAP_TRANSPORT_LE 0x01 -#define L2CAP_CONNECTION_RESPONSE_SUCCESS 0x00 -#define L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHEN 0x01 -#define L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHOR 0x02 -#define L2CAP_CONNECTION_RESPONSE_INSUFF_ENC_KEY 0x03 +#define BTP_L2CAP_CONNECTION_RESPONSE_SUCCESS 0x00 +#define BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHEN 0x01 +#define BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHOR 0x02 +#define BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_ENC_KEY 0x03 -#define L2CAP_LISTEN 0x05 -struct l2cap_listen_cmd { +#define BTP_L2CAP_LISTEN 0x05 +struct btp_l2cap_listen_cmd { uint16_t psm; uint8_t transport; uint16_t mtu; uint16_t response; } __packed; -#define L2CAP_ACCEPT_CONNECTION 0x06 -struct l2cap_accept_connection_cmd { +#define BTP_L2CAP_ACCEPT_CONNECTION 0x06 +struct btp_l2cap_accept_connection_cmd { uint8_t chan_id; uint16_t result; } __packed; -#define L2CAP_RECONFIGURE 0x07 -struct l2cap_reconfigure_cmd { +#define BTP_L2CAP_RECONFIGURE 0x07 +struct btp_l2cap_reconfigure_cmd { uint8_t address_type; uint8_t address[6]; uint16_t mtu; @@ -77,29 +77,29 @@ struct l2cap_reconfigure_cmd { uint8_t chan_id[]; } __packed; -#define L2CAP_CREDITS 0x08 -struct l2cap_credits_cmd { +#define BTP_L2CAP_CREDITS 0x08 +struct btp_l2cap_credits_cmd { uint8_t chan_id; } __packed; -#define L2CAP_DISCONNECT_EATT_CHANS 0x09 -struct l2cap_disconnect_eatt_chans_cmd { +#define BTP_L2CAP_DISCONNECT_EATT_CHANS 0x09 +struct btp_l2cap_disconnect_eatt_chans_cmd { uint8_t address_type; uint8_t address[6]; uint8_t count; } __packed; /* events */ -#define L2CAP_EV_CONNECTION_REQ 0x80 -struct l2cap_connection_req_ev { +#define BTP_L2CAP_EV_CONNECTION_REQ 0x80 +struct btp_l2cap_connection_req_ev { uint8_t chan_id; uint16_t psm; uint8_t address_type; uint8_t address[6]; } __packed; -#define L2CAP_EV_CONNECTED 0x81 -struct l2cap_connected_ev { +#define BTP_L2CAP_EV_CONNECTED 0x81 +struct btp_l2cap_connected_ev { uint8_t chan_id; uint16_t psm; uint16_t mtu_remote; @@ -110,8 +110,8 @@ struct l2cap_connected_ev { uint8_t address[6]; } __packed; -#define L2CAP_EV_DISCONNECTED 0x82 -struct l2cap_disconnected_ev { +#define BTP_L2CAP_EV_DISCONNECTED 0x82 +struct btp_l2cap_disconnected_ev { uint16_t result; uint8_t chan_id; uint16_t psm; @@ -119,15 +119,15 @@ struct l2cap_disconnected_ev { uint8_t address[6]; } __packed; -#define L2CAP_EV_DATA_RECEIVED 0x83 -struct l2cap_data_received_ev { +#define BTP_L2CAP_EV_DATA_RECEIVED 0x83 +struct btp_l2cap_data_received_ev { uint8_t chan_id; uint16_t data_length; uint8_t data[]; } __packed; -#define L2CAP_EV_RECONFIGURED 0x84 -struct l2cap_reconfigured_ev { +#define BTP_L2CAP_EV_RECONFIGURED 0x84 +struct btp_l2cap_reconfigured_ev { uint8_t chan_id; uint16_t mtu_remote; uint16_t mps_remote; diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index fde3c531864e..6c44f2f74429 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -12,30 +12,30 @@ /* MESH Service */ /* commands */ -#define MESH_READ_SUPPORTED_COMMANDS 0x01 -struct mesh_read_supported_commands_rp { +#define BTP_MESH_READ_SUPPORTED_COMMANDS 0x01 +struct btp_mesh_read_supported_commands_rp { uint8_t data[0]; } __packed; -#define MESH_OUT_BLINK BIT(0) -#define MESH_OUT_BEEP BIT(1) -#define MESH_OUT_VIBRATE BIT(2) -#define MESH_OUT_DISPLAY_NUMBER BIT(3) -#define MESH_OUT_DISPLAY_STRING BIT(4) +#define BTP_MESH_OUT_BLINK BIT(0) +#define BTP_MESH_OUT_BEEP BIT(1) +#define BTP_MESH_OUT_VIBRATE BIT(2) +#define BTP_MESH_OUT_DISPLAY_NUMBER BIT(3) +#define BTP_MESH_OUT_DISPLAY_STRING BIT(4) -#define MESH_IN_PUSH BIT(0) -#define MESH_IN_TWIST BIT(1) -#define MESH_IN_ENTER_NUMBER BIT(2) -#define MESH_IN_ENTER_STRING BIT(3) +#define BTP_MESH_IN_PUSH BIT(0) +#define BTP_MESH_IN_TWIST BIT(1) +#define BTP_MESH_IN_ENTER_NUMBER BIT(2) +#define BTP_MESH_IN_ENTER_STRING BIT(3) -#define MESH_CONFIG_PROVISIONING 0x02 +#define BTP_MESH_CONFIG_PROVISIONING 0x02 struct set_keys { uint8_t pub_key[64]; uint8_t priv_key[32]; } __packed; -struct mesh_config_provisioning_cmd { +struct btp_mesh_config_provisioning_cmd { uint8_t uuid[16]; uint8_t static_auth[16]; uint8_t out_size; @@ -46,8 +46,8 @@ struct mesh_config_provisioning_cmd { struct set_keys set_keys[0]; } __packed; -#define MESH_PROVISION_NODE 0x03 -struct mesh_provision_node_cmd { +#define BTP_MESH_PROVISION_NODE 0x03 +struct btp_mesh_provision_node_cmd { uint8_t net_key[16]; uint16_t net_key_idx; uint8_t flags; @@ -58,28 +58,28 @@ struct mesh_provision_node_cmd { uint8_t pub_key[0]; } __packed; -#define MESH_INIT 0x04 -#define MESH_RESET 0x05 -#define MESH_INPUT_NUMBER 0x06 -struct mesh_input_number_cmd { +#define BTP_MESH_INIT 0x04 +#define BTP_MESH_RESET 0x05 +#define BTP_MESH_INPUT_NUMBER 0x06 +struct btp_mesh_input_number_cmd { uint32_t number; } __packed; -#define MESH_INPUT_STRING 0x07 -struct mesh_input_string_cmd { +#define BTP_MESH_INPUT_STRING 0x07 +struct btp_mesh_input_string_cmd { uint8_t string_len; uint8_t string[]; } __packed; -#define MESH_IVU_TEST_MODE 0x08 -struct mesh_ivu_test_mode_cmd { +#define BTP_MESH_IVU_TEST_MODE 0x08 +struct btp_mesh_ivu_test_mode_cmd { uint8_t enable; } __packed; -#define MESH_IVU_TOGGLE_STATE 0x09 +#define BTP_MESH_IVU_TOGGLE_STATE 0x09 -#define MESH_NET_SEND 0x0a -struct mesh_net_send_cmd { +#define BTP_MESH_NET_SEND 0x0a +struct btp_mesh_net_send_cmd { uint8_t ttl; uint16_t src; uint16_t dst; @@ -87,8 +87,8 @@ struct mesh_net_send_cmd { uint8_t payload[]; } __packed; -#define MESH_HEALTH_GENERATE_FAULTS 0x0b -struct mesh_health_generate_faults_rp { +#define BTP_MESH_HEALTH_GENERATE_FAULTS 0x0b +struct btp_mesh_health_generate_faults_rp { uint8_t test_id; uint8_t cur_faults_count; uint8_t reg_faults_count; @@ -96,98 +96,98 @@ struct mesh_health_generate_faults_rp { uint8_t registered_faults[0]; } __packed; -#define MESH_HEALTH_CLEAR_FAULTS 0x0c +#define BTP_MESH_HEALTH_CLEAR_FAULTS 0x0c -#define MESH_LPN 0x0d -struct mesh_lpn_set_cmd { +#define BTP_MESH_LPN 0x0d +struct btp_mesh_lpn_set_cmd { uint8_t enable; } __packed; -#define MESH_LPN_POLL 0x0e +#define BTP_MESH_LPN_POLL 0x0e -#define MESH_MODEL_SEND 0x0f -struct mesh_model_send_cmd { +#define BTP_MESH_MODEL_SEND 0x0f +struct btp_mesh_model_send_cmd { uint16_t src; uint16_t dst; uint8_t payload_len; uint8_t payload[]; } __packed; -#define MESH_LPN_SUBSCRIBE 0x10 -struct mesh_lpn_subscribe_cmd { +#define BTP_MESH_LPN_SUBSCRIBE 0x10 +struct btp_mesh_lpn_subscribe_cmd { uint16_t address; } __packed; -#define MESH_LPN_UNSUBSCRIBE 0x11 -struct mesh_lpn_unsubscribe_cmd { +#define BTP_MESH_LPN_UNSUBSCRIBE 0x11 +struct btp_mesh_lpn_unsubscribe_cmd { uint16_t address; } __packed; -#define MESH_RPL_CLEAR 0x12 -#define MESH_PROXY_IDENTITY 0x13 -#define MESH_COMP_DATA_GET 0x14 -struct mesh_comp_data_get_cmd { +#define BTP_MESH_RPL_CLEAR 0x12 +#define BTP_MESH_PROXY_IDENTITY 0x13 +#define BTP_MESH_COMP_DATA_GET 0x14 +struct btp_mesh_comp_data_get_cmd { uint16_t net_idx; uint16_t address; uint8_t page; } __packed; -#define MESH_CFG_BEACON_GET 0x15 -struct mesh_cfg_val_get_cmd { +#define BTP_MESH_CFG_BEACON_GET 0x15 +struct btp_mesh_cfg_val_get_cmd { uint16_t net_idx; uint16_t address; } __packed; -#define MESH_CFG_BEACON_SET 0x16 -struct mesh_cfg_beacon_set_cmd { +#define BTP_MESH_CFG_BEACON_SET 0x16 +struct btp_mesh_cfg_beacon_set_cmd { uint16_t net_idx; uint16_t address; uint8_t val; } __packed; -#define MESH_CFG_DEFAULT_TTL_GET 0x18 -#define MESH_CFG_DEFAULT_TTL_SET 0x19 -struct mesh_cfg_default_ttl_set_cmd { +#define BTP_MESH_CFG_DEFAULT_TTL_GET 0x18 +#define BTP_MESH_CFG_DEFAULT_TTL_SET 0x19 +struct btp_mesh_cfg_default_ttl_set_cmd { uint16_t net_idx; uint16_t address; uint8_t val; } __packed; -#define MESH_CFG_GATT_PROXY_GET 0x1a -#define MESH_CFG_GATT_PROXY_SET 0x1b -struct mesh_cfg_gatt_proxy_set_cmd { +#define BTP_MESH_CFG_GATT_PROXY_GET 0x1a +#define BTP_MESH_CFG_GATT_PROXY_SET 0x1b +struct btp_mesh_cfg_gatt_proxy_set_cmd { uint16_t net_idx; uint16_t address; uint8_t val; } __packed; -#define MESH_CFG_FRIEND_GET 0x1c -#define MESH_CFG_FRIEND_SET 0x1d -struct mesh_cfg_friend_set_cmd { +#define BTP_MESH_CFG_FRIEND_GET 0x1c +#define BTP_MESH_CFG_FRIEND_SET 0x1d +struct btp_mesh_cfg_friend_set_cmd { uint16_t net_idx; uint16_t address; uint8_t val; } __packed; -#define MESH_CFG_RELAY_GET 0x1e -#define MESH_CFG_RELAY_SET 0x1f -struct mesh_cfg_relay_set_cmd { +#define BTP_MESH_CFG_RELAY_GET 0x1e +#define BTP_MESH_CFG_RELAY_SET 0x1f +struct btp_mesh_cfg_relay_set_cmd { uint16_t net_idx; uint16_t address; uint8_t new_relay; uint8_t new_transmit; } __packed; -#define MESH_CFG_MODEL_PUB_GET 0x20 -struct mesh_cfg_model_pub_get_cmd { +#define BTP_MESH_CFG_MODEL_PUB_GET 0x20 +struct btp_mesh_cfg_model_pub_get_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; uint16_t model_id; } __packed; -#define MESH_CFG_MODEL_PUB_SET 0x21 -struct mesh_cfg_model_pub_set_cmd { +#define BTP_MESH_CFG_MODEL_PUB_SET 0x21 +struct btp_mesh_cfg_model_pub_set_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; @@ -200,9 +200,9 @@ struct mesh_cfg_model_pub_set_cmd { uint8_t transmit; } __packed; -#define MESH_CFG_MODEL_SUB_ADD 0x22 -#define MESH_CFG_MODEL_SUB_DEL 0x23 -struct mesh_cfg_model_sub_cmd { +#define BTP_MESH_CFG_MODEL_SUB_ADD 0x22 +#define BTP_MESH_CFG_MODEL_SUB_DEL 0x23 +struct btp_mesh_cfg_model_sub_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; @@ -210,24 +210,24 @@ struct mesh_cfg_model_sub_cmd { uint16_t model_id; } __packed; -#define MESH_CFG_NETKEY_ADD 0x24 -struct mesh_cfg_netkey_add_cmd { +#define BTP_MESH_CFG_NETKEY_ADD 0x24 +struct btp_mesh_cfg_netkey_add_cmd { uint16_t net_idx; uint16_t address; uint8_t net_key[16]; uint16_t net_key_idx; } __packed; -#define MESH_CFG_NETKEY_GET 0x25 -#define MESH_CFG_NETKEY_DEL 0x26 -struct mesh_cfg_netkey_del_cmd { +#define BTP_MESH_CFG_NETKEY_GET 0x25 +#define BTP_MESH_CFG_NETKEY_DEL 0x26 +struct btp_mesh_cfg_netkey_del_cmd { uint16_t net_idx; uint16_t address; uint16_t net_key_idx; } __packed; -#define MESH_CFG_APPKEY_ADD 0x27 -struct mesh_cfg_appkey_add_cmd { +#define BTP_MESH_CFG_APPKEY_ADD 0x27 +struct btp_mesh_cfg_appkey_add_cmd { uint16_t net_idx; uint16_t address; uint16_t net_key_idx; @@ -235,24 +235,24 @@ struct mesh_cfg_appkey_add_cmd { uint16_t app_key_idx; } __packed; -#define MESH_CFG_APPKEY_DEL 0x28 -struct mesh_cfg_appkey_del_cmd { +#define BTP_MESH_CFG_APPKEY_DEL 0x28 +struct btp_mesh_cfg_appkey_del_cmd { uint16_t net_idx; uint16_t address; uint16_t net_key_idx; uint16_t app_key_idx; } __packed; -#define MESH_CFG_APPKEY_GET 0x29 -struct mesh_cfg_appkey_get_cmd { +#define BTP_MESH_CFG_APPKEY_GET 0x29 +struct btp_mesh_cfg_appkey_get_cmd { uint16_t net_idx; uint16_t address; uint16_t net_key_idx; } __packed; -#define MESH_CFG_MODEL_APP_BIND 0x2A -#define MESH_CFG_MODEL_APP_UNBIND 0x2B -struct mesh_cfg_model_app_bind_cmd { +#define BTP_MESH_CFG_MODEL_APP_BIND 0x2A +#define BTP_MESH_CFG_MODEL_APP_UNBIND 0x2B +struct btp_mesh_cfg_model_app_bind_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; @@ -260,9 +260,9 @@ struct mesh_cfg_model_app_bind_cmd { uint16_t mod_id; } __packed; -#define MESH_CFG_MODEL_APP_GET 0x2C -#define MESH_CFG_MODEL_APP_VND_GET 0x2D -struct mesh_cfg_model_app_get_cmd { +#define BTP_MESH_CFG_MODEL_APP_GET 0x2C +#define BTP_MESH_CFG_MODEL_APP_VND_GET 0x2D +struct btp_mesh_cfg_model_app_get_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; @@ -270,8 +270,8 @@ struct mesh_cfg_model_app_get_cmd { uint16_t cid; } __packed; -#define MESH_CFG_HEARTBEAT_PUB_SET 0x2E -struct mesh_cfg_heartbeat_pub_set_cmd { +#define BTP_MESH_CFG_HEARTBEAT_PUB_SET 0x2E +struct btp_mesh_cfg_heartbeat_pub_set_cmd { uint16_t net_idx; uint16_t address; uint16_t net_key_idx; @@ -282,9 +282,9 @@ struct mesh_cfg_heartbeat_pub_set_cmd { uint16_t features; } __packed; -#define MESH_CFG_HEARTBEAT_PUB_GET 0x2F -#define MESH_CFG_HEARTBEAT_SUB_SET 0x30 -struct mesh_cfg_heartbeat_sub_set_cmd { +#define BTP_MESH_CFG_HEARTBEAT_PUB_GET 0x2F +#define BTP_MESH_CFG_HEARTBEAT_SUB_SET 0x30 +struct btp_mesh_cfg_heartbeat_sub_set_cmd { uint16_t net_idx; uint16_t address; uint16_t source; @@ -292,34 +292,34 @@ struct mesh_cfg_heartbeat_sub_set_cmd { uint8_t period_log; } __packed; -#define MESH_CFG_HEARTBEAT_SUB_GET 0x31 -#define MESH_CFG_NET_TRANS_GET 0x32 -#define MESH_CFG_NET_TRANS_SET 0x33 -struct mesh_cfg_net_trans_set_cmd { +#define BTP_MESH_CFG_HEARTBEAT_SUB_GET 0x31 +#define BTP_MESH_CFG_NET_TRANS_GET 0x32 +#define BTP_MESH_CFG_NET_TRANS_SET 0x33 +struct btp_mesh_cfg_net_trans_set_cmd { uint16_t net_idx; uint16_t address; uint8_t transmit; } __packed; -#define MESH_CFG_MODEL_SUB_OVW 0x34 -#define MESH_CFG_MODEL_SUB_DEL_ALL 0x35 -struct mesh_cfg_model_sub_del_all_cmd { +#define BTP_MESH_CFG_MODEL_SUB_OVW 0x34 +#define BTP_MESH_CFG_MODEL_SUB_DEL_ALL 0x35 +struct btp_mesh_cfg_model_sub_del_all_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; uint16_t model_id; } __packed; -#define MESH_CFG_MODEL_SUB_GET 0x36 -struct mesh_cfg_model_sub_get_cmd { +#define BTP_MESH_CFG_MODEL_SUB_GET 0x36 +struct btp_mesh_cfg_model_sub_get_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; uint16_t model_id; } __packed; -#define MESH_CFG_MODEL_SUB_GET_VND 0x37 -struct mesh_cfg_model_sub_get_vnd_cmd { +#define BTP_MESH_CFG_MODEL_SUB_GET_VND 0x37 +struct btp_mesh_cfg_model_sub_get_vnd_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; @@ -327,10 +327,10 @@ struct mesh_cfg_model_sub_get_vnd_cmd { uint16_t cid; } __packed; -#define MESH_CFG_MODEL_SUB_VA_ADD 0x38 -#define MESH_CFG_MODEL_SUB_VA_DEL 0x39 -#define MESH_CFG_MODEL_SUB_VA_OVW 0x3A -struct mesh_cfg_model_sub_va_cmd { +#define BTP_MESH_CFG_MODEL_SUB_VA_ADD 0x38 +#define BTP_MESH_CFG_MODEL_SUB_VA_DEL 0x39 +#define BTP_MESH_CFG_MODEL_SUB_VA_OVW 0x3A +struct btp_mesh_cfg_model_sub_va_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; @@ -338,38 +338,38 @@ struct mesh_cfg_model_sub_va_cmd { uint8_t uuid[16]; } __packed; -#define MESH_CFG_NETKEY_UPDATE 0x3B -#define MESH_CFG_APPKEY_UPDATE 0x3C -#define MESH_CFG_NODE_IDT_SET 0x3D -struct mesh_cfg_node_idt_set_cmd { +#define BTP_MESH_CFG_NETKEY_UPDATE 0x3B +#define BTP_MESH_CFG_APPKEY_UPDATE 0x3C +#define BTP_MESH_CFG_NODE_IDT_SET 0x3D +struct btp_mesh_cfg_node_idt_set_cmd { uint16_t net_idx; uint16_t address; uint16_t net_key_idx; uint8_t new_identity; } __packed; -#define MESH_CFG_NODE_IDT_GET 0x3E -struct mesh_cfg_node_idt_get_cmd { +#define BTP_MESH_CFG_NODE_IDT_GET 0x3E +struct btp_mesh_cfg_node_idt_get_cmd { uint16_t net_idx; uint16_t address; uint16_t net_key_idx; } __packed; -#define MESH_CFG_NODE_RESET 0x3F -struct mesh_cfg_node_reset_cmd { +#define BTP_MESH_CFG_NODE_RESET 0x3F +struct btp_mesh_cfg_node_reset_cmd { uint16_t net_idx; uint16_t address; } __packed; -#define MESH_CFG_LPN_TIMEOUT_GET 0x40 -struct mesh_cfg_lpn_timeout_cmd { +#define BTP_MESH_CFG_LPN_TIMEOUT_GET 0x40 +struct btp_mesh_cfg_lpn_timeout_cmd { uint16_t net_idx; uint16_t address; uint16_t unicast_addr; } __packed; -#define MESH_CFG_MODEL_PUB_VA_SET 0x41 -struct mesh_cfg_model_pub_va_set_cmd { +#define BTP_MESH_CFG_MODEL_PUB_VA_SET 0x41 +struct btp_mesh_cfg_model_pub_va_set_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; @@ -382,8 +382,8 @@ struct mesh_cfg_model_pub_va_set_cmd { uint8_t uuid[16]; } __packed; -#define MESH_CFG_MODEL_APP_BIND_VND 0x42 -struct mesh_cfg_model_app_bind_vnd_cmd { +#define BTP_MESH_CFG_MODEL_APP_BIND_VND 0x42 +struct btp_mesh_cfg_model_app_bind_vnd_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; @@ -392,23 +392,23 @@ struct mesh_cfg_model_app_bind_vnd_cmd { uint16_t cid; } __packed; -#define MESH_HEALTH_FAULT_GET 0x43 -struct mesh_health_fault_get_cmd { +#define BTP_MESH_HEALTH_FAULT_GET 0x43 +struct btp_mesh_health_fault_get_cmd { uint16_t address; uint16_t app_idx; uint16_t cid; } __packed; -#define MESH_HEALTH_FAULT_CLEAR 0x44 -struct mesh_health_fault_clear_cmd { +#define BTP_MESH_HEALTH_FAULT_CLEAR 0x44 +struct btp_mesh_health_fault_clear_cmd { uint16_t address; uint16_t app_idx; uint16_t cid; uint8_t ack; } __packed; -#define MESH_HEALTH_FAULT_TEST 0x45 -struct mesh_health_fault_test_cmd { +#define BTP_MESH_HEALTH_FAULT_TEST 0x45 +struct btp_mesh_health_fault_test_cmd { uint16_t address; uint16_t app_idx; uint16_t cid; @@ -416,36 +416,36 @@ struct mesh_health_fault_test_cmd { uint8_t ack; } __packed; -#define MESH_HEALTH_PERIOD_GET 0x46 -struct mesh_health_period_get_cmd { +#define BTP_MESH_HEALTH_PERIOD_GET 0x46 +struct btp_mesh_health_period_get_cmd { uint16_t address; uint16_t app_idx; } __packed; -#define MESH_HEALTH_PERIOD_SET 0x47 -struct mesh_health_period_set_cmd { +#define BTP_MESH_HEALTH_PERIOD_SET 0x47 +struct btp_mesh_health_period_set_cmd { uint16_t address; uint16_t app_idx; uint8_t divisor; uint8_t ack; } __packed; -#define MESH_HEALTH_ATTENTION_GET 0x48 -struct mesh_health_attention_get_cmd { +#define BTP_MESH_HEALTH_ATTENTION_GET 0x48 +struct btp_mesh_health_attention_get_cmd { uint16_t address; uint16_t app_idx; } __packed; -#define MESH_HEALTH_ATTENTION_SET 0x49 -struct mesh_health_attention_set_cmd { +#define BTP_MESH_HEALTH_ATTENTION_SET 0x49 +struct btp_mesh_health_attention_set_cmd { uint16_t address; uint16_t app_idx; uint8_t attention; uint8_t ack; } __packed; -#define MESH_PROVISION_ADV 0x4A -struct mesh_provision_adv_cmd { +#define BTP_MESH_PROVISION_ADV 0x4A +struct btp_mesh_provision_adv_cmd { uint8_t uuid[16]; uint16_t net_idx; uint16_t address; @@ -453,15 +453,15 @@ struct mesh_provision_adv_cmd { uint8_t net_key[16]; } __packed; -#define MESH_CFG_KRP_GET 0x4B -struct mesh_cfg_krp_get_cmd { +#define BTP_MESH_CFG_KRP_GET 0x4B +struct btp_mesh_cfg_krp_get_cmd { uint16_t net_idx; uint16_t address; uint16_t key_net_idx; } __packed; -#define MESH_CFG_KRP_SET 0x4C -struct mesh_cfg_krp_set_cmd { +#define BTP_MESH_CFG_KRP_SET 0x4C +struct btp_mesh_cfg_krp_set_cmd { uint16_t net_idx; uint16_t address; uint16_t key_net_idx; @@ -469,40 +469,40 @@ struct mesh_cfg_krp_set_cmd { } __packed; /* events */ -#define MESH_EV_OUT_NUMBER_ACTION 0x80 -struct mesh_out_number_action_ev { +#define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 +struct btp_mesh_out_number_action_ev { uint16_t action; uint32_t number; } __packed; -#define MESH_EV_OUT_STRING_ACTION 0x81 -struct mesh_out_string_action_ev { +#define BTP_MESH_EV_OUT_STRING_ACTION 0x81 +struct btp_mesh_out_string_action_ev { uint8_t string_len; uint8_t string[]; } __packed; -#define MESH_EV_IN_ACTION 0x82 -struct mesh_in_action_ev { +#define BTP_MESH_EV_IN_ACTION 0x82 +struct btp_mesh_in_action_ev { uint16_t action; uint8_t size; } __packed; -#define MESH_EV_PROVISIONED 0x83 +#define BTP_MESH_EV_PROVISIONED 0x83 -#define MESH_PROV_BEARER_PB_ADV 0x00 -#define MESH_PROV_BEARER_PB_GATT 0x01 -#define MESH_EV_PROV_LINK_OPEN 0x84 -struct mesh_prov_link_open_ev { +#define BTP_MESH_PROV_BEARER_PB_ADV 0x00 +#define BTP_MESH_PROV_BEARER_PB_GATT 0x01 +#define BTP_MESH_EV_PROV_LINK_OPEN 0x84 +struct btp_mesh_prov_link_open_ev { uint8_t bearer; } __packed; -#define MESH_EV_PROV_LINK_CLOSED 0x85 -struct mesh_prov_link_closed_ev { +#define BTP_MESH_EV_PROV_LINK_CLOSED 0x85 +struct btp_mesh_prov_link_closed_ev { uint8_t bearer; } __packed; -#define MESH_EV_NET_RECV 0x86 -struct mesh_net_recv_ev { +#define BTP_MESH_EV_NET_RECV 0x86 +struct btp_mesh_net_recv_ev { uint8_t ttl; uint8_t ctl; uint16_t src; @@ -511,50 +511,50 @@ struct mesh_net_recv_ev { uint8_t payload[]; } __packed; -#define MESH_EV_INVALID_BEARER 0x87 -struct mesh_invalid_bearer_ev { +#define BTP_MESH_EV_INVALID_BEARER 0x87 +struct btp_mesh_invalid_bearer_ev { uint8_t opcode; } __packed; -#define MESH_EV_INCOMP_TIMER_EXP 0x88 +#define BTP_MESH_EV_INCOMP_TIMER_EXP 0x88 -#define MESH_EV_FRND_ESTABLISHED 0x89 -struct mesh_frnd_established_ev { +#define BTP_MESH_EV_FRND_ESTABLISHED 0x89 +struct btp_mesh_frnd_established_ev { uint16_t net_idx; uint16_t lpn_addr; uint8_t recv_delay; uint32_t polltimeout; } __packed; -#define MESH_EV_FRND_TERMINATED 0x8a -struct mesh_frnd_terminated_ev { +#define BTP_MESH_EV_FRND_TERMINATED 0x8a +struct btp_mesh_frnd_terminated_ev { uint16_t net_idx; uint16_t lpn_addr; } __packed; -#define MESH_EV_LPN_ESTABLISHED 0x8b -struct mesh_lpn_established_ev { +#define BTP_MESH_EV_LPN_ESTABLISHED 0x8b +struct btp_mesh_lpn_established_ev { uint16_t net_idx; uint16_t friend_addr; uint8_t queue_size; uint8_t recv_win; } __packed; -#define MESH_EV_LPN_TERMINATED 0x8c -struct mesh_lpn_terminated_ev { +#define BTP_MESH_EV_LPN_TERMINATED 0x8c +struct btp_mesh_lpn_terminated_ev { uint16_t net_idx; uint16_t friend_addr; } __packed; -#define MESH_EV_LPN_POLLED 0x8d -struct mesh_lpn_polled_ev { +#define BTP_MESH_EV_LPN_POLLED 0x8d +struct btp_mesh_lpn_polled_ev { uint16_t net_idx; uint16_t friend_addr; uint8_t retry; } __packed; -#define MESH_EV_PROV_NODE_ADDED 0x8e -struct mesh_prov_node_added_ev { +#define BTP_MESH_EV_PROV_NODE_ADDED 0x8e +struct btp_mesh_prov_node_added_ev { uint16_t net_idx; uint16_t addr; uint8_t uuid[16]; diff --git a/tests/bluetooth/tester/src/btp/btp_vcs.h b/tests/bluetooth/tester/src/btp/btp_vcs.h index 3101055463c5..2ff466a161ea 100644 --- a/tests/bluetooth/tester/src/btp/btp_vcs.h +++ b/tests/bluetooth/tester/src/btp/btp_vcs.h @@ -8,14 +8,14 @@ #include -#define VCS_READ_SUPPORTED_COMMANDS 0x01 +#define BTP_VCS_READ_SUPPORTED_COMMANDS 0x01 -#define VCS_SET_VOL 0x02 -#define VCS_VOL_UP 0x03 -#define VCS_VOL_DOWN 0x04 -#define VCS_MUTE 0x05 -#define VCS_UNMUTE 0x06 +#define BTP_VCS_SET_VOL 0x02 +#define BTP_VCS_VOL_UP 0x03 +#define BTP_VCS_VOL_DOWN 0x04 +#define BTP_VCS_MUTE 0x05 +#define BTP_VCS_UNMUTE 0x06 -struct vcs_set_vol_cmd { +struct btp_vcs_set_vol_cmd { uint8_t volume; } __packed; diff --git a/tests/bluetooth/tester/src/btp/btp_vocs.h b/tests/bluetooth/tester/src/btp/btp_vocs.h index c48459e53cf4..8397b90cc30b 100644 --- a/tests/bluetooth/tester/src/btp/btp_vocs.h +++ b/tests/bluetooth/tester/src/btp/btp_vocs.h @@ -8,16 +8,16 @@ #include -#define VOCS_READ_SUPPORTED_COMMANDS 0x01 +#define BTP_VOCS_READ_SUPPORTED_COMMANDS 0x01 -#define VOCS_UPDATE_LOC 0x02 -#define VOCS_UPDATE_DESC 0x03 +#define BTP_VOCS_UPDATE_LOC 0x02 +#define BTP_VOCS_UPDATE_DESC 0x03 -struct vocs_audio_desc { +struct btp_vocs_audio_desc { uint8_t desc_len; uint8_t desc[0]; } __packed; -struct vocs_audio_loc { +struct btp_vocs_audio_loc { uint32_t loc; } __packed; diff --git a/tests/bluetooth/tester/src/btp_bap.c b/tests/bluetooth/tester/src/btp_bap.c index 5cdb604bc931..b68f331273db 100644 --- a/tests/bluetooth/tester/src/btp_bap.c +++ b/tests/bluetooth/tester/src/btp_bap.c @@ -111,13 +111,13 @@ static int set_supported_contexts(void) static void pacs_supported_commands(uint8_t *data, uint16_t len) { uint8_t cmds[2]; - struct pacs_read_supported_commands_rp *rp = (void *)cmds; + struct btp_pacs_read_supported_commands_rp *rp = (void *)cmds; (void)memset(cmds, 0, sizeof(cmds)); - tester_set_bit(cmds, PACS_READ_SUPPORTED_COMMANDS); + tester_set_bit(cmds, BTP_PACS_READ_SUPPORTED_COMMANDS); - tester_send(BTP_SERVICE_ID_PACS, PACS_READ_SUPPORTED_COMMANDS, + tester_send(BTP_SERVICE_ID_PACS, BTP_PACS_READ_SUPPORTED_COMMANDS, CONTROLLER_INDEX, (uint8_t *)rp, sizeof(cmds)); } @@ -125,33 +125,33 @@ static void pacs_update_characteristic(uint8_t *data, uint16_t len) { int err = 0; uint8_t status = BTP_STATUS_SUCCESS; - const struct pacs_update_characteristic_cmd *cmd = (void *)data; + const struct btp_pacs_update_characteristic_cmd *cmd = (void *)data; switch (cmd->characteristic) { - case PACS_CHARACTERISTIC_SINK_PAC: + case BTP_PACS_CHARACTERISTIC_SINK_PAC: err = bt_pacs_cap_unregister(BT_AUDIO_DIR_SINK, &cap_sink); break; - case PACS_CHARACTERISTIC_SOURCE_PAC: + case BTP_PACS_CHARACTERISTIC_SOURCE_PAC: err = bt_pacs_cap_unregister(BT_AUDIO_DIR_SOURCE, &cap_source); break; - case PACS_CHARACTERISTIC_SINK_AUDIO_LOCATIONS: + case BTP_PACS_CHARACTERISTIC_SINK_AUDIO_LOCATIONS: err = bt_pacs_set_location(BT_AUDIO_DIR_SINK, BT_AUDIO_LOCATION_FRONT_CENTER | BT_AUDIO_LOCATION_BACK_CENTER); break; - case PACS_CHARACTERISTIC_SOURCE_AUDIO_LOCATIONS: + case BTP_PACS_CHARACTERISTIC_SOURCE_AUDIO_LOCATIONS: err = bt_pacs_set_location(BT_AUDIO_DIR_SOURCE, (BT_AUDIO_LOCATION_FRONT_LEFT | BT_AUDIO_LOCATION_FRONT_RIGHT | BT_AUDIO_LOCATION_FRONT_CENTER)); break; - case PACS_CHARACTERISTIC_AVAILABLE_AUDIO_CONTEXTS: + case BTP_PACS_CHARACTERISTIC_AVAILABLE_AUDIO_CONTEXTS: err = bt_pacs_set_available_contexts(BT_AUDIO_DIR_SOURCE, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); break; - case PACS_CHARACTERISTIC_SUPPORTED_AUDIO_CONTEXTS: + case BTP_PACS_CHARACTERISTIC_SUPPORTED_AUDIO_CONTEXTS: err = bt_pacs_set_supported_contexts(BT_AUDIO_DIR_SOURCE, SUPPORTED_SOURCE_CONTEXT | BT_AUDIO_CONTEXT_TYPE_INSTRUCTIONAL); @@ -164,7 +164,7 @@ static void pacs_update_characteristic(uint8_t *data, uint16_t len) status = BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_PACS, PACS_UPDATE_CHARACTERISTIC, + tester_rsp(BTP_SERVICE_ID_PACS, BTP_PACS_UPDATE_CHARACTERISTIC, CONTROLLER_INDEX, status); } @@ -172,10 +172,10 @@ void tester_handle_pacs(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len) { switch (opcode) { - case PACS_READ_SUPPORTED_COMMANDS: + case BTP_PACS_READ_SUPPORTED_COMMANDS: pacs_supported_commands(data, len); break; - case PACS_UPDATE_CHARACTERISTIC: + case BTP_PACS_UPDATE_CHARACTERISTIC: pacs_update_characteristic(data, len); break; default: diff --git a/tests/bluetooth/tester/src/btp_gap.c b/tests/bluetooth/tester/src/btp_gap.c index f7ded6d37c5d..8a8b9b5d74d8 100644 --- a/tests/bluetooth/tester/src/btp_gap.c +++ b/tests/bluetooth/tester/src/btp_gap.c @@ -31,7 +31,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #define CONTROLLER_NAME "btp_tester" #define BT_LE_AD_DISCOV_MASK (BT_LE_AD_LIMITED | BT_LE_AD_GENERAL) -#define ADV_BUF_LEN (sizeof(struct gap_device_found_ev) + 2 * 31) +#define ADV_BUF_LEN (sizeof(struct btp_gap_device_found_ev) + 2 * 31) static atomic_t current_settings; struct bt_conn_auth_cb cb; @@ -96,7 +96,7 @@ static uint8_t read_car_cb(struct bt_conn *conn, uint8_t err, static void le_connected(struct bt_conn *conn, uint8_t err) { - struct gap_device_connected_ev ev; + struct btp_gap_device_connected_ev ev; struct bt_conn_info info; if (err) { @@ -111,26 +111,26 @@ static void le_connected(struct bt_conn *conn, uint8_t err) ev.latency = sys_cpu_to_le16(info.le.latency); ev.timeout = sys_cpu_to_le16(info.le.timeout); - tester_send(BTP_SERVICE_ID_GAP, GAP_EV_DEVICE_CONNECTED, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_CONNECTED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } static void le_disconnected(struct bt_conn *conn, uint8_t reason) { - struct gap_device_disconnected_ev ev; + struct btp_gap_device_disconnected_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); memcpy(ev.address, addr->a.val, sizeof(ev.address)); ev.address_type = addr->type; - tester_send(BTP_SERVICE_ID_GAP, GAP_EV_DEVICE_DISCONNECTED, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_DISCONNECTED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } static void le_identity_resolved(struct bt_conn *conn, const bt_addr_le_t *rpa, const bt_addr_le_t *identity) { - struct gap_identity_resolved_ev ev; + struct btp_gap_identity_resolved_ev ev; ev.address_type = rpa->type; memcpy(ev.address, rpa->a.val, sizeof(ev.address)); @@ -139,14 +139,14 @@ static void le_identity_resolved(struct bt_conn *conn, const bt_addr_le_t *rpa, memcpy(ev.identity_address, identity->a.val, sizeof(ev.identity_address)); - tester_send(BTP_SERVICE_ID_GAP, GAP_EV_IDENTITY_RESOLVED, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_IDENTITY_RESOLVED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } static void le_param_updated(struct bt_conn *conn, uint16_t interval, uint16_t latency, uint16_t timeout) { - struct gap_conn_param_update_ev ev; + struct btp_gap_conn_param_update_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); memcpy(ev.address, addr->a.val, sizeof(ev.address)); @@ -155,7 +155,7 @@ static void le_param_updated(struct bt_conn *conn, uint16_t interval, ev.latency = sys_cpu_to_le16(latency); ev.timeout = sys_cpu_to_le16(timeout); - tester_send(BTP_SERVICE_ID_GAP, GAP_EV_CONN_PARAM_UPDATE, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_CONN_PARAM_UPDATE, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } @@ -176,8 +176,8 @@ static void le_security_changed(struct bt_conn *conn, bt_security_t level, enum bt_security_err err) { const bt_addr_le_t *addr = bt_conn_get_dst(conn); - struct gap_sec_level_changed_ev sec_ev; - struct gap_bond_lost_ev bond_ev; + struct btp_gap_sec_level_changed_ev sec_ev; + struct btp_gap_bond_lost_ev bond_ev; struct bt_conn_info info; switch (err) { @@ -187,7 +187,7 @@ static void le_security_changed(struct bt_conn *conn, bt_security_t level, /* enum matches BTP values */ sec_ev.sec_level = level; - tester_send(BTP_SERVICE_ID_GAP, GAP_EV_SEC_LEVEL_CHANGED, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_SEC_LEVEL_CHANGED, CONTROLLER_INDEX, (uint8_t *) &sec_ev, sizeof(sec_ev)); break; case BT_SECURITY_ERR_PIN_OR_KEY_MISSING: @@ -203,7 +203,7 @@ static void le_security_changed(struct bt_conn *conn, bt_security_t level, (void)memcpy(bond_ev.address, addr->a.val, sizeof(bond_ev.address)); bond_ev.address_type = addr->type; - tester_send(BTP_SERVICE_ID_GAP, GAP_EV_BOND_LOST, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_BOND_LOST, CONTROLLER_INDEX, (uint8_t *)&bond_ev, sizeof(bond_ev)); (void)bt_conn_set_security(conn, BT_SECURITY_L2 | BT_SECURITY_FORCE_PAIR); @@ -226,43 +226,43 @@ static struct bt_conn_cb conn_callbacks = { static void supported_commands(uint8_t *data, uint16_t len) { uint8_t cmds[4]; - struct gap_read_supported_commands_rp *rp = (void *) &cmds; + struct btp_gap_read_supported_commands_rp *rp = (void *) &cmds; (void)memset(cmds, 0, sizeof(cmds)); - tester_set_bit(cmds, GAP_READ_SUPPORTED_COMMANDS); - tester_set_bit(cmds, GAP_READ_CONTROLLER_INDEX_LIST); - tester_set_bit(cmds, GAP_READ_CONTROLLER_INFO); - tester_set_bit(cmds, GAP_SET_CONNECTABLE); - tester_set_bit(cmds, GAP_SET_DISCOVERABLE); - tester_set_bit(cmds, GAP_SET_BONDABLE); - tester_set_bit(cmds, GAP_START_ADVERTISING); - tester_set_bit(cmds, GAP_START_DIRECTED_ADV); - tester_set_bit(cmds, GAP_STOP_ADVERTISING); - tester_set_bit(cmds, GAP_START_DISCOVERY); - tester_set_bit(cmds, GAP_STOP_DISCOVERY); - tester_set_bit(cmds, GAP_CONNECT); - tester_set_bit(cmds, GAP_DISCONNECT); - tester_set_bit(cmds, GAP_SET_IO_CAP); - tester_set_bit(cmds, GAP_PAIR); - tester_set_bit(cmds, GAP_PASSKEY_ENTRY); - tester_set_bit(cmds, GAP_PASSKEY_CONFIRM); - tester_set_bit(cmds, GAP_CONN_PARAM_UPDATE); - tester_set_bit(cmds, GAP_SET_MITM); - tester_set_bit(cmds, GAP_OOB_LEGACY_SET_DATA); + tester_set_bit(cmds, BTP_GAP_READ_SUPPORTED_COMMANDS); + tester_set_bit(cmds, BTP_GAP_READ_CONTROLLER_INDEX_LIST); + tester_set_bit(cmds, BTP_GAP_READ_CONTROLLER_INFO); + tester_set_bit(cmds, BTP_GAP_SET_CONNECTABLE); + tester_set_bit(cmds, BTP_GAP_SET_DISCOVERABLE); + tester_set_bit(cmds, BTP_GAP_SET_BONDABLE); + tester_set_bit(cmds, BTP_GAP_START_ADVERTISING); + tester_set_bit(cmds, BTP_GAP_START_DIRECTED_ADV); + tester_set_bit(cmds, BTP_GAP_STOP_ADVERTISING); + tester_set_bit(cmds, BTP_GAP_START_DISCOVERY); + tester_set_bit(cmds, BTP_GAP_STOP_DISCOVERY); + tester_set_bit(cmds, BTP_GAP_CONNECT); + tester_set_bit(cmds, BTP_GAP_DISCONNECT); + tester_set_bit(cmds, BTP_GAP_SET_IO_CAP); + tester_set_bit(cmds, BTP_GAP_PAIR); + tester_set_bit(cmds, BTP_GAP_PASSKEY_ENTRY); + tester_set_bit(cmds, BTP_GAP_PASSKEY_CONFIRM); + tester_set_bit(cmds, BTP_GAP_CONN_PARAM_UPDATE); + tester_set_bit(cmds, BTP_GAP_SET_MITM); + tester_set_bit(cmds, BTP_GAP_OOB_LEGACY_SET_DATA); #if !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) - tester_set_bit(cmds, GAP_OOB_SC_GET_LOCAL_DATA); - tester_set_bit(cmds, GAP_OOB_SC_SET_REMOTE_DATA); + tester_set_bit(cmds, BTP_GAP_OOB_SC_GET_LOCAL_DATA); + tester_set_bit(cmds, BTP_GAP_OOB_SC_SET_REMOTE_DATA); #endif /* !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) */ - tester_set_bit(cmds, GAP_SET_FILTER_LIST); + tester_set_bit(cmds, BTP_GAP_SET_FILTER_LIST); - tester_send(BTP_SERVICE_ID_GAP, GAP_READ_SUPPORTED_COMMANDS, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_READ_SUPPORTED_COMMANDS, CONTROLLER_INDEX, (uint8_t *) rp, sizeof(cmds)); } static void controller_index_list(uint8_t *data, uint16_t len) { - struct gap_read_controller_index_list_rp *rp; + struct btp_gap_read_controller_index_list_rp *rp; uint8_t buf[sizeof(*rp) + 1]; rp = (void *) buf; @@ -270,13 +270,13 @@ static void controller_index_list(uint8_t *data, uint16_t len) rp->num = 1U; rp->index[0] = CONTROLLER_INDEX; - tester_send(BTP_SERVICE_ID_GAP, GAP_READ_CONTROLLER_INDEX_LIST, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_READ_CONTROLLER_INDEX_LIST, BTP_INDEX_NONE, (uint8_t *) rp, sizeof(buf)); } static void controller_info(uint8_t *data, uint16_t len) { - struct gap_read_controller_info_rp rp; + struct btp_gap_read_controller_info_rp rp; uint32_t supported_settings; (void)memset(&rp, 0, sizeof(rp)); @@ -299,22 +299,22 @@ static void controller_info(uint8_t *data, uint16_t len) */ #if !defined(CONFIG_BT_PRIVACY) if (oob_local.addr.type == BT_ADDR_LE_RANDOM) { - atomic_set_bit(¤t_settings, GAP_SETTINGS_STATIC_ADDRESS); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_STATIC_ADDRESS); } #endif /* CONFIG_BT_PRIVACY */ - supported_settings = BIT(GAP_SETTINGS_POWERED); - supported_settings |= BIT(GAP_SETTINGS_CONNECTABLE); - supported_settings |= BIT(GAP_SETTINGS_BONDABLE); - supported_settings |= BIT(GAP_SETTINGS_LE); - supported_settings |= BIT(GAP_SETTINGS_ADVERTISING); + supported_settings = BIT(BTP_GAP_SETTINGS_POWERED); + supported_settings |= BIT(BTP_GAP_SETTINGS_CONNECTABLE); + supported_settings |= BIT(BTP_GAP_SETTINGS_BONDABLE); + supported_settings |= BIT(BTP_GAP_SETTINGS_LE); + supported_settings |= BIT(BTP_GAP_SETTINGS_ADVERTISING); rp.supported_settings = sys_cpu_to_le32(supported_settings); rp.current_settings = sys_cpu_to_le32(current_settings); memcpy(rp.name, CONTROLLER_NAME, sizeof(CONTROLLER_NAME)); - tester_send(BTP_SERVICE_ID_GAP, GAP_READ_CONTROLLER_INFO, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_READ_CONTROLLER_INFO, CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); } @@ -413,11 +413,11 @@ static void oob_data_request(struct bt_conn *conn, static void get_oob_sc_local_data(void) { cb.oob_data_request = oob_data_request; - struct gap_oob_sc_get_local_data_rp rp = { 0 }; + struct btp_gap_oob_sc_get_local_data_rp rp = { 0 }; memcpy(&rp.conf[0], &oob_sc_local.le_sc_data.c[0], sizeof(rp.conf)); memcpy(&rp.rand[0], &oob_sc_local.le_sc_data.r[0], sizeof(rp.rand)); - tester_send(BTP_SERVICE_ID_GAP, GAP_OOB_SC_GET_LOCAL_DATA, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_OOB_SC_GET_LOCAL_DATA, CONTROLLER_INDEX, (uint8_t *)&rp, sizeof(rp)); } @@ -426,7 +426,7 @@ static void set_oob_sc_remote_data(const uint8_t *data, uint16_t len) cb.oob_data_request = oob_data_request; bt_set_oob_data_flag(true); - const struct gap_oob_sc_set_remote_data_cmd *cmd = (void *)data; + const struct btp_gap_oob_sc_set_remote_data_cmd *cmd = (void *)data; /* Note that the .addr field * will be set by the oob_data_request callback @@ -436,25 +436,25 @@ static void set_oob_sc_remote_data(const uint8_t *data, uint16_t len) memcpy(&oob_sc_remote.le_sc_data.c[0], &cmd->conf[0], sizeof(oob_sc_remote.le_sc_data.c)); - tester_rsp(BTP_SERVICE_ID_GAP, GAP_OOB_SC_SET_REMOTE_DATA, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_OOB_SC_SET_REMOTE_DATA, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } #endif /* !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) */ static void set_connectable(uint8_t *data, uint16_t len) { - const struct gap_set_connectable_cmd *cmd = (void *) data; - struct gap_set_connectable_rp rp; + const struct btp_gap_set_connectable_cmd *cmd = (void *) data; + struct btp_gap_set_connectable_rp rp; if (cmd->connectable) { - atomic_set_bit(¤t_settings, GAP_SETTINGS_CONNECTABLE); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_CONNECTABLE); } else { - atomic_clear_bit(¤t_settings, GAP_SETTINGS_CONNECTABLE); + atomic_clear_bit(¤t_settings, BTP_GAP_SETTINGS_CONNECTABLE); } rp.current_settings = sys_cpu_to_le32(current_settings); - tester_send(BTP_SERVICE_ID_GAP, GAP_SET_CONNECTABLE, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_SET_CONNECTABLE, CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); } @@ -466,62 +466,62 @@ static struct bt_data sd[10]; static void set_discoverable(uint8_t *data, uint16_t len) { - const struct gap_set_discoverable_cmd *cmd = (void *) data; - struct gap_set_discoverable_rp rp; + const struct btp_gap_set_discoverable_cmd *cmd = (void *) data; + struct btp_gap_set_discoverable_rp rp; switch (cmd->discoverable) { - case GAP_NON_DISCOVERABLE: + case BTP_GAP_NON_DISCOVERABLE: ad_flags &= ~(BT_LE_AD_GENERAL | BT_LE_AD_LIMITED); - atomic_clear_bit(¤t_settings, GAP_SETTINGS_DISCOVERABLE); + atomic_clear_bit(¤t_settings, BTP_GAP_SETTINGS_DISCOVERABLE); break; - case GAP_GENERAL_DISCOVERABLE: + case BTP_GAP_GENERAL_DISCOVERABLE: ad_flags &= ~BT_LE_AD_LIMITED; ad_flags |= BT_LE_AD_GENERAL; - atomic_set_bit(¤t_settings, GAP_SETTINGS_DISCOVERABLE); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_DISCOVERABLE); break; - case GAP_LIMITED_DISCOVERABLE: + case BTP_GAP_LIMITED_DISCOVERABLE: ad_flags &= ~BT_LE_AD_GENERAL; ad_flags |= BT_LE_AD_LIMITED; - atomic_set_bit(¤t_settings, GAP_SETTINGS_DISCOVERABLE); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_DISCOVERABLE); break; default: LOG_WRN("unknown mode: 0x%x", cmd->discoverable); - tester_rsp(BTP_SERVICE_ID_GAP, GAP_SET_DISCOVERABLE, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_SET_DISCOVERABLE, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } rp.current_settings = sys_cpu_to_le32(current_settings); - tester_send(BTP_SERVICE_ID_GAP, GAP_SET_DISCOVERABLE, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_SET_DISCOVERABLE, CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); } static void set_bondable(uint8_t *data, uint16_t len) { - const struct gap_set_bondable_cmd *cmd = (void *) data; - struct gap_set_bondable_rp rp; + const struct btp_gap_set_bondable_cmd *cmd = (void *) data; + struct btp_gap_set_bondable_rp rp; LOG_DBG("cmd->bondable: %d", cmd->bondable); if (cmd->bondable) { - atomic_set_bit(¤t_settings, GAP_SETTINGS_BONDABLE); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_BONDABLE); } else { - atomic_clear_bit(¤t_settings, GAP_SETTINGS_BONDABLE); + atomic_clear_bit(¤t_settings, BTP_GAP_SETTINGS_BONDABLE); } bt_set_bondable(cmd->bondable); rp.current_settings = sys_cpu_to_le32(current_settings); - tester_send(BTP_SERVICE_ID_GAP, GAP_SET_BONDABLE, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_SET_BONDABLE, CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); } static void start_advertising(const uint8_t *data, uint16_t len) { - const struct gap_start_advertising_cmd *cmd = (void *) data; - struct gap_start_advertising_rp rp; + const struct btp_gap_start_advertising_cmd *cmd = (void *) data; + struct btp_gap_start_advertising_rp rp; uint8_t adv_len, sd_len; bool adv_conn; int i; @@ -550,7 +550,7 @@ static void start_advertising(const uint8_t *data, uint16_t len) i += sd[sd_len].data_len; } - adv_conn = atomic_test_bit(¤t_settings, GAP_SETTINGS_CONNECTABLE); + adv_conn = atomic_test_bit(¤t_settings, BTP_GAP_SETTINGS_CONNECTABLE); /* BTP API don't allow to set empty scan response data. */ if (bt_le_adv_start(adv_conn ? BT_LE_ADV_CONN : BT_LE_ADV_NCONN, @@ -559,34 +559,34 @@ static void start_advertising(const uint8_t *data, uint16_t len) goto fail; } - atomic_set_bit(¤t_settings, GAP_SETTINGS_ADVERTISING); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_ADVERTISING); rp.current_settings = sys_cpu_to_le32(current_settings); - tester_send(BTP_SERVICE_ID_GAP, GAP_START_ADVERTISING, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_START_ADVERTISING, CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); return; fail: - tester_rsp(BTP_SERVICE_ID_GAP, GAP_START_ADVERTISING, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_START_ADVERTISING, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void start_directed_advertising(const uint8_t *data, uint16_t len) { - const struct gap_start_directed_adv_cmd *cmd = (void *)data; - struct gap_start_directed_adv_rp rp; + const struct btp_gap_start_directed_adv_cmd *cmd = (void *)data; + struct btp_gap_start_directed_adv_rp rp; struct bt_le_adv_param adv_param; uint16_t options = sys_le16_to_cpu(cmd->options); const bt_addr_le_t *peer = (bt_addr_le_t *)data; adv_param = *BT_LE_ADV_CONN_DIR(peer); - if (!(options & GAP_START_DIRECTED_ADV_HD)) { + if (!(options & BTP_GAP_START_DIRECTED_ADV_HD)) { adv_param.options |= BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY; adv_param.interval_max = BT_GAP_ADV_FAST_INT_MAX_2; adv_param.interval_min = BT_GAP_ADV_FAST_INT_MIN_2; } - if (options & GAP_START_DIRECTED_ADV_PEER_RPA) { + if (options & BTP_GAP_START_DIRECTED_ADV_PEER_RPA) { #if defined(CONFIG_BT_PRIVACY) /* check if peer supports Central Address Resolution */ for (int i = 0; i < CONFIG_BT_MAX_PAIRED; i++) { @@ -604,34 +604,34 @@ static void start_directed_advertising(const uint8_t *data, uint16_t len) goto fail; } - atomic_set_bit(¤t_settings, GAP_SETTINGS_ADVERTISING); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_ADVERTISING); rp.current_settings = sys_cpu_to_le32(current_settings); - tester_send(BTP_SERVICE_ID_GAP, GAP_START_DIRECTED_ADV, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_START_DIRECTED_ADV, CONTROLLER_INDEX, (uint8_t *)&rp, sizeof(rp)); return; fail: - tester_rsp(BTP_SERVICE_ID_GAP, GAP_START_DIRECTED_ADV, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_START_DIRECTED_ADV, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void stop_advertising(const uint8_t *data, uint16_t len) { - struct gap_stop_advertising_rp rp; + struct btp_gap_stop_advertising_rp rp; int err; err = bt_le_adv_stop(); if (err < 0) { - tester_rsp(BTP_SERVICE_ID_GAP, GAP_STOP_ADVERTISING, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_STOP_ADVERTISING, CONTROLLER_INDEX, BTP_STATUS_FAILED); LOG_ERR("Failed to stop advertising: %d", err); return; } - atomic_clear_bit(¤t_settings, GAP_SETTINGS_ADVERTISING); + atomic_clear_bit(¤t_settings, BTP_GAP_SETTINGS_ADVERTISING); rp.current_settings = sys_cpu_to_le32(current_settings); - tester_send(BTP_SERVICE_ID_GAP, GAP_STOP_ADVERTISING, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_STOP_ADVERTISING, CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); } @@ -668,7 +668,7 @@ static struct net_buf_simple *adv_buf = NET_BUF_SIMPLE(ADV_BUF_LEN); static void store_adv(const bt_addr_le_t *addr, int8_t rssi, struct net_buf_simple *ad) { - struct gap_device_found_ev *ev; + struct btp_gap_device_found_ev *ev; /* cleanup */ net_buf_simple_init(adv_buf, 0); @@ -678,7 +678,7 @@ static void store_adv(const bt_addr_le_t *addr, int8_t rssi, memcpy(ev->address, addr->a.val, sizeof(ev->address)); ev->address_type = addr->type; ev->rssi = rssi; - ev->flags = GAP_DEVICE_FOUND_FLAG_AD | GAP_DEVICE_FOUND_FLAG_RSSI; + ev->flags = BTP_GAP_DEVICE_FOUND_FLAG_AD | BTP_GAP_DEVICE_FOUND_FLAG_RSSI; ev->eir_data_len = ad->len; memcpy(net_buf_simple_add(adv_buf, ad->len), ad->data, ad->len); } @@ -687,7 +687,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t evtype, struct net_buf_simple *ad) { /* if General/Limited Discovery - parse Advertising data to get flags */ - if (!(discovery_flags & GAP_DISCOVERY_FLAG_LE_OBSERVE) && + if (!(discovery_flags & BTP_GAP_DISCOVERY_FLAG_LE_OBSERVE) && (evtype != BT_GAP_ADV_TYPE_SCAN_RSP)) { uint8_t flags = get_ad_flags(ad); @@ -698,7 +698,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t evtype, } /* if Limited Discovery - ignore general discoverable devices */ - if ((discovery_flags & GAP_DISCOVERY_FLAG_LIMITED) && + if ((discovery_flags & BTP_GAP_DISCOVERY_FLAG_LIMITED) && !(flags & BT_LE_AD_LIMITED)) { LOG_DBG("General discoverable, skipping"); return; @@ -707,7 +707,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t evtype, /* attach Scan Response data */ if (evtype == BT_GAP_ADV_TYPE_SCAN_RSP) { - struct gap_device_found_ev *ev; + struct btp_gap_device_found_ev *ev; bt_addr_le_t a; /* skip if there is no pending advertisement */ @@ -731,7 +731,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t evtype, } ev->eir_data_len += ad->len; - ev->flags |= GAP_DEVICE_FOUND_FLAG_SD; + ev->flags |= BTP_GAP_DEVICE_FOUND_FLAG_SD; memcpy(net_buf_simple_add(adv_buf, ad->len), ad->data, ad->len); @@ -743,7 +743,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t evtype, * current one */ if (adv_buf->len) { - tester_send(BTP_SERVICE_ID_GAP, GAP_EV_DEVICE_FOUND, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_FOUND, CONTROLLER_INDEX, adv_buf->data, adv_buf->len); net_buf_simple_reset(adv_buf); } @@ -751,31 +751,31 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t evtype, store_adv(addr, rssi, ad); /* if Active Scan and scannable event - wait for Scan Response */ - if ((discovery_flags & GAP_DISCOVERY_FLAG_LE_ACTIVE_SCAN) && + if ((discovery_flags & BTP_GAP_DISCOVERY_FLAG_LE_ACTIVE_SCAN) && (evtype == BT_GAP_ADV_TYPE_ADV_IND || evtype == BT_GAP_ADV_TYPE_ADV_SCAN_IND)) { LOG_DBG("Waiting for scan response"); return; } done: - tester_send(BTP_SERVICE_ID_GAP, GAP_EV_DEVICE_FOUND, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_FOUND, CONTROLLER_INDEX, adv_buf->data, adv_buf->len); net_buf_simple_reset(adv_buf); } static void start_discovery(const uint8_t *data, uint16_t len) { - const struct gap_start_discovery_cmd *cmd = (void *) data; + const struct btp_gap_start_discovery_cmd *cmd = (void *) data; uint8_t status; /* only LE scan is supported */ - if (cmd->flags & GAP_DISCOVERY_FLAG_BREDR) { + if (cmd->flags & BTP_GAP_DISCOVERY_FLAG_BREDR) { status = BTP_STATUS_FAILED; LOG_WRN("BR/EDR not supported"); goto reply; } - if (bt_le_scan_start(cmd->flags & GAP_DISCOVERY_FLAG_LE_ACTIVE_SCAN ? + if (bt_le_scan_start(cmd->flags & BTP_GAP_DISCOVERY_FLAG_LE_ACTIVE_SCAN ? BT_LE_SCAN_ACTIVE : BT_LE_SCAN_PASSIVE, device_found) < 0) { status = BTP_STATUS_FAILED; @@ -788,7 +788,7 @@ static void start_discovery(const uint8_t *data, uint16_t len) status = BTP_STATUS_SUCCESS; reply: - tester_rsp(BTP_SERVICE_ID_GAP, GAP_START_DISCOVERY, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_START_DISCOVERY, CONTROLLER_INDEX, status); } @@ -803,7 +803,7 @@ static void stop_discovery(const uint8_t *data, uint16_t len) status = BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_GAP, GAP_STOP_DISCOVERY, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_STOP_DISCOVERY, CONTROLLER_INDEX, status); } @@ -838,7 +838,7 @@ static void connect(const uint8_t *data, uint16_t len) status = BTP_STATUS_SUCCESS; rsp: - tester_rsp(BTP_SERVICE_ID_GAP, GAP_CONNECT, CONTROLLER_INDEX, status); + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_CONNECT, CONTROLLER_INDEX, status); } static void disconnect(const uint8_t *data, uint16_t len) @@ -863,45 +863,45 @@ static void disconnect(const uint8_t *data, uint16_t len) bt_conn_unref(conn); rsp: - tester_rsp(BTP_SERVICE_ID_GAP, GAP_DISCONNECT, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_DISCONNECT, CONTROLLER_INDEX, status); } static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) { - struct gap_passkey_display_ev ev; + struct btp_gap_passkey_display_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); memcpy(ev.address, addr->a.val, sizeof(ev.address)); ev.address_type = addr->type; ev.passkey = sys_cpu_to_le32(passkey); - tester_send(BTP_SERVICE_ID_GAP, GAP_EV_PASSKEY_DISPLAY, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_DISPLAY, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } static void auth_passkey_entry(struct bt_conn *conn) { - struct gap_passkey_entry_req_ev ev; + struct btp_gap_passkey_entry_req_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); memcpy(ev.address, addr->a.val, sizeof(ev.address)); ev.address_type = addr->type; - tester_send(BTP_SERVICE_ID_GAP, GAP_EV_PASSKEY_ENTRY_REQ, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_ENTRY_REQ, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey) { - struct gap_passkey_confirm_req_ev ev; + struct btp_gap_passkey_confirm_req_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); memcpy(ev.address, addr->a.val, sizeof(ev.address)); ev.address_type = addr->type; ev.passkey = sys_cpu_to_le32(passkey); - tester_send(BTP_SERVICE_ID_GAP, GAP_EV_PASSKEY_CONFIRM_REQ, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_CONFIRM_REQ, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } @@ -913,7 +913,7 @@ static void auth_cancel(struct bt_conn *conn) enum bt_security_err auth_pairing_accept(struct bt_conn *conn, const struct bt_conn_pairing_feat *const feat) { - struct gap_bond_lost_ev ev; + struct btp_gap_bond_lost_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); if (!bt_addr_le_is_bonded(BT_ID_DEFAULT, addr)) { @@ -928,7 +928,7 @@ enum bt_security_err auth_pairing_accept(struct bt_conn *conn, memcpy(ev.address, addr->a.val, sizeof(ev.address)); ev.address_type = addr->type; - tester_send(BTP_SERVICE_ID_GAP, GAP_EV_BOND_LOST, CONTROLLER_INDEX, (uint8_t *)&ev, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_BOND_LOST, CONTROLLER_INDEX, (uint8_t *)&ev, sizeof(ev)); return BT_SECURITY_ERR_SUCCESS; @@ -936,14 +936,14 @@ enum bt_security_err auth_pairing_accept(struct bt_conn *conn, void auth_pairing_failed(struct bt_conn *conn, enum bt_security_err reason) { - struct gap_bond_pairing_failed_ev ev; + struct btp_gap_bond_pairing_failed_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); memcpy(ev.address, addr->a.val, sizeof(ev.address)); ev.address_type = addr->type; ev.reason = reason; - tester_send(BTP_SERVICE_ID_GAP, GAP_EV_PAIRING_FAILED, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PAIRING_FAILED, CONTROLLER_INDEX, (uint8_t *)&ev, sizeof(ev)); } @@ -964,7 +964,7 @@ static struct bt_conn_auth_info_cb auth_info_cb = { static void set_io_cap(const uint8_t *data, uint16_t len) { - const struct gap_set_io_cap_cmd *cmd = (void *) data; + const struct btp_gap_set_io_cap_cmd *cmd = (void *) data; uint8_t status; /* Reset io cap requirements */ @@ -974,24 +974,24 @@ static void set_io_cap(const uint8_t *data, uint16_t len) LOG_DBG("io_cap: %d", cmd->io_cap); switch (cmd->io_cap) { - case GAP_IO_CAP_DISPLAY_ONLY: + case BTP_GAP_IO_CAP_DISPLAY_ONLY: cb.cancel = auth_cancel; cb.passkey_display = auth_passkey_display; break; - case GAP_IO_CAP_KEYBOARD_DISPLAY: + case BTP_GAP_IO_CAP_KEYBOARD_DISPLAY: cb.cancel = auth_cancel; cb.passkey_display = auth_passkey_display; cb.passkey_entry = auth_passkey_entry; cb.passkey_confirm = auth_passkey_confirm; break; - case GAP_IO_CAP_NO_INPUT_OUTPUT: + case BTP_GAP_IO_CAP_NO_INPUT_OUTPUT: cb.cancel = auth_cancel; break; - case GAP_IO_CAP_KEYBOARD_ONLY: + case BTP_GAP_IO_CAP_KEYBOARD_ONLY: cb.cancel = auth_cancel; cb.passkey_entry = auth_passkey_entry; break; - case GAP_IO_CAP_DISPLAY_YESNO: + case BTP_GAP_IO_CAP_DISPLAY_YESNO: cb.cancel = auth_cancel; cb.passkey_display = auth_passkey_display; cb.passkey_confirm = auth_passkey_confirm; @@ -1012,7 +1012,7 @@ static void set_io_cap(const uint8_t *data, uint16_t len) status = BTP_STATUS_SUCCESS; rsp: - tester_rsp(BTP_SERVICE_ID_GAP, GAP_SET_IO_CAP, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_SET_IO_CAP, CONTROLLER_INDEX, status); } @@ -1041,12 +1041,12 @@ static void pair(const uint8_t *data, uint16_t len) status = BTP_STATUS_SUCCESS; rsp: - tester_rsp(BTP_SERVICE_ID_GAP, GAP_PAIR, CONTROLLER_INDEX, status); + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_PAIR, CONTROLLER_INDEX, status); } static void unpair(const uint8_t *data, uint16_t len) { - struct gap_unpair_cmd *cmd = (void *) data; + struct btp_gap_unpair_cmd *cmd = (void *) data; struct bt_conn *conn; bt_addr_le_t addr; uint8_t status; @@ -1075,12 +1075,12 @@ static void unpair(const uint8_t *data, uint16_t len) status = err < 0 ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS; rsp: - tester_rsp(BTP_SERVICE_ID_GAP, GAP_UNPAIR, CONTROLLER_INDEX, status); + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_UNPAIR, CONTROLLER_INDEX, status); } static void passkey_entry(const uint8_t *data, uint16_t len) { - const struct gap_passkey_entry_cmd *cmd = (void *) data; + const struct btp_gap_passkey_entry_cmd *cmd = (void *) data; struct bt_conn *conn; uint8_t status; int err; @@ -1101,13 +1101,13 @@ static void passkey_entry(const uint8_t *data, uint16_t len) status = err < 0 ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS; rsp: - tester_rsp(BTP_SERVICE_ID_GAP, GAP_PASSKEY_ENTRY, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_PASSKEY_ENTRY, CONTROLLER_INDEX, status); } static void passkey_confirm(const uint8_t *data, uint16_t len) { - const struct gap_passkey_confirm_cmd *cmd = (void *) data; + const struct btp_gap_passkey_confirm_cmd *cmd = (void *) data; struct bt_conn *conn; uint8_t status; int err; @@ -1135,14 +1135,14 @@ static void passkey_confirm(const uint8_t *data, uint16_t len) status = err < 0 ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS; rsp: - tester_rsp(BTP_SERVICE_ID_GAP, GAP_PASSKEY_CONFIRM, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_PASSKEY_CONFIRM, CONTROLLER_INDEX, status); } static void conn_param_update(const uint8_t *data, uint16_t len) { - const struct gap_conn_param_update_cmd *cmd = (void *) data; + const struct btp_gap_conn_param_update_cmd *cmd = (void *) data; struct bt_le_conn_param param = { .interval_min = sys_le16_to_cpu(cmd->interval_min), .interval_max = sys_le16_to_cpu(cmd->interval_max), @@ -1168,7 +1168,7 @@ static void conn_param_update(const uint8_t *data, uint16_t len) status = err < 0 ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS; rsp: - tester_rsp(BTP_SERVICE_ID_GAP, GAP_CONN_PARAM_UPDATE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_CONN_PARAM_UPDATE, CONTROLLER_INDEX, status); } @@ -1176,26 +1176,26 @@ static void set_mitm(const uint8_t *data, uint16_t len) { LOG_WRN("Use CONFIG_BT_SMP_ENFORCE_MITM instead"); - tester_rsp(BTP_SERVICE_ID_GAP, GAP_SET_MITM, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_SET_MITM, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } static void set_oob_legacy_data(const uint8_t *data, uint16_t len) { - const struct gap_oob_legacy_set_data_cmd *cmd = (void *) data; + const struct btp_gap_oob_legacy_set_data_cmd *cmd = (void *) data; memcpy(oob_legacy_tk, cmd->oob_data, 16); bt_set_oob_data_flag(true); cb.oob_data_request = oob_data_request; - tester_rsp(BTP_SERVICE_ID_GAP, GAP_OOB_LEGACY_SET_DATA, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_OOB_LEGACY_SET_DATA, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } static void set_filter_list(const uint8_t *data, uint16_t len) { - const struct gap_set_filter_list *cmd = (const void *) data; + const struct btp_gap_set_filter_list *cmd = (const void *) data; uint8_t status; int err; @@ -1218,7 +1218,7 @@ static void set_filter_list(const uint8_t *data, uint16_t len) status = BTP_STATUS_SUCCESS; failed: - tester_rsp(BTP_SERVICE_ID_GAP, GAP_SET_FILTER_LIST, + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_SET_FILTER_LIST, CONTROLLER_INDEX, status); } @@ -1227,8 +1227,8 @@ void tester_handle_gap(uint8_t opcode, uint8_t index, uint8_t *data, { LOG_DBG("opcode: 0x%02x", opcode); switch (opcode) { - case GAP_READ_SUPPORTED_COMMANDS: - case GAP_READ_CONTROLLER_INDEX_LIST: + case BTP_GAP_READ_SUPPORTED_COMMANDS: + case BTP_GAP_READ_CONTROLLER_INDEX_LIST: if (index != BTP_INDEX_NONE){ tester_rsp(BTP_SERVICE_ID_GAP, opcode, index, BTP_STATUS_FAILED); @@ -1249,78 +1249,78 @@ void tester_handle_gap(uint8_t opcode, uint8_t index, uint8_t *data, } switch (opcode) { - case GAP_READ_SUPPORTED_COMMANDS: + case BTP_GAP_READ_SUPPORTED_COMMANDS: supported_commands(data, len); return; - case GAP_READ_CONTROLLER_INDEX_LIST: + case BTP_GAP_READ_CONTROLLER_INDEX_LIST: controller_index_list(data, len); return; - case GAP_READ_CONTROLLER_INFO: + case BTP_GAP_READ_CONTROLLER_INFO: controller_info(data, len); return; - case GAP_SET_CONNECTABLE: + case BTP_GAP_SET_CONNECTABLE: set_connectable(data, len); return; - case GAP_SET_DISCOVERABLE: + case BTP_GAP_SET_DISCOVERABLE: set_discoverable(data, len); return; - case GAP_SET_BONDABLE: + case BTP_GAP_SET_BONDABLE: set_bondable(data, len); return; - case GAP_START_ADVERTISING: + case BTP_GAP_START_ADVERTISING: start_advertising(data, len); return; - case GAP_START_DIRECTED_ADV: + case BTP_GAP_START_DIRECTED_ADV: start_directed_advertising(data, len); return; - case GAP_STOP_ADVERTISING: + case BTP_GAP_STOP_ADVERTISING: stop_advertising(data, len); return; - case GAP_START_DISCOVERY: + case BTP_GAP_START_DISCOVERY: start_discovery(data, len); return; - case GAP_STOP_DISCOVERY: + case BTP_GAP_STOP_DISCOVERY: stop_discovery(data, len); return; - case GAP_CONNECT: + case BTP_GAP_CONNECT: connect(data, len); return; - case GAP_DISCONNECT: + case BTP_GAP_DISCONNECT: disconnect(data, len); return; - case GAP_SET_IO_CAP: + case BTP_GAP_SET_IO_CAP: set_io_cap(data, len); return; - case GAP_PAIR: + case BTP_GAP_PAIR: pair(data, len); return; - case GAP_UNPAIR: + case BTP_GAP_UNPAIR: unpair(data, len); return; - case GAP_PASSKEY_ENTRY: + case BTP_GAP_PASSKEY_ENTRY: passkey_entry(data, len); return; - case GAP_PASSKEY_CONFIRM: + case BTP_GAP_PASSKEY_CONFIRM: passkey_confirm(data, len); return; - case GAP_CONN_PARAM_UPDATE: + case BTP_GAP_CONN_PARAM_UPDATE: conn_param_update(data, len); return; - case GAP_SET_MITM: + case BTP_GAP_SET_MITM: set_mitm(data, len); return; - case GAP_OOB_LEGACY_SET_DATA: + case BTP_GAP_OOB_LEGACY_SET_DATA: set_oob_legacy_data(data, len); return; #if !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) - case GAP_OOB_SC_GET_LOCAL_DATA: + case BTP_GAP_OOB_SC_GET_LOCAL_DATA: get_oob_sc_local_data(); return; - case GAP_OOB_SC_SET_REMOTE_DATA: + case BTP_GAP_OOB_SC_SET_REMOTE_DATA: set_oob_sc_remote_data(data, len); return; #endif /* !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) */ - case GAP_SET_FILTER_LIST: + case BTP_GAP_SET_FILTER_LIST: set_filter_list(data, len); return; default: @@ -1334,24 +1334,24 @@ void tester_handle_gap(uint8_t opcode, uint8_t index, uint8_t *data, static void tester_init_gap_cb(int err) { if (err) { - tester_rsp(BTP_SERVICE_ID_CORE, CORE_REGISTER_SERVICE, + tester_rsp(BTP_SERVICE_ID_CORE, BTP_CORE_REGISTER_SERVICE, BTP_INDEX_NONE, BTP_STATUS_FAILED); LOG_WRN("Error: %d", err); return; } atomic_clear(¤t_settings); - atomic_set_bit(¤t_settings, GAP_SETTINGS_POWERED); - atomic_set_bit(¤t_settings, GAP_SETTINGS_CONNECTABLE); - atomic_set_bit(¤t_settings, GAP_SETTINGS_BONDABLE); - atomic_set_bit(¤t_settings, GAP_SETTINGS_LE); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_POWERED); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_CONNECTABLE); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_BONDABLE); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_LE); #if defined(CONFIG_BT_PRIVACY) - atomic_set_bit(¤t_settings, GAP_SETTINGS_PRIVACY); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_PRIVACY); #endif /* CONFIG_BT_PRIVACY */ bt_conn_cb_register(&conn_callbacks); - tester_rsp(BTP_SERVICE_ID_CORE, CORE_REGISTER_SERVICE, BTP_INDEX_NONE, + tester_rsp(BTP_SERVICE_ID_CORE, BTP_CORE_REGISTER_SERVICE, BTP_INDEX_NONE, BTP_STATUS_SUCCESS); } diff --git a/tests/bluetooth/tester/src/btp_gatt.c b/tests/bluetooth/tester/src/btp_gatt.c index 93dd4eb1e684..6f0eb1148558 100644 --- a/tests/bluetooth/tester/src/btp_gatt.c +++ b/tests/bluetooth/tester/src/btp_gatt.c @@ -221,41 +221,41 @@ static uint8_t btp2bt_uuid(const uint8_t *uuid, uint8_t len, static void supported_commands(uint8_t *data, uint16_t len) { uint8_t cmds[5]; - struct gatt_read_supported_commands_rp *rp = (void *) cmds; + struct btp_gatt_read_supported_commands_rp *rp = (void *) cmds; (void)memset(cmds, 0, sizeof(cmds)); - tester_set_bit(cmds, GATT_READ_SUPPORTED_COMMANDS); - tester_set_bit(cmds, GATT_ADD_SERVICE); - tester_set_bit(cmds, GATT_ADD_CHARACTERISTIC); - tester_set_bit(cmds, GATT_ADD_DESCRIPTOR); - tester_set_bit(cmds, GATT_ADD_INCLUDED_SERVICE); - tester_set_bit(cmds, GATT_SET_VALUE); - tester_set_bit(cmds, GATT_START_SERVER); - tester_set_bit(cmds, GATT_SET_ENC_KEY_SIZE); - tester_set_bit(cmds, GATT_EXCHANGE_MTU); - tester_set_bit(cmds, GATT_DISC_PRIM_UUID); - tester_set_bit(cmds, GATT_FIND_INCLUDED); - tester_set_bit(cmds, GATT_DISC_ALL_CHRC); - tester_set_bit(cmds, GATT_DISC_CHRC_UUID); - tester_set_bit(cmds, GATT_DISC_ALL_DESC); - tester_set_bit(cmds, GATT_READ); - tester_set_bit(cmds, GATT_READ_LONG); - tester_set_bit(cmds, GATT_READ_MULTIPLE); - tester_set_bit(cmds, GATT_WRITE_WITHOUT_RSP); - tester_set_bit(cmds, GATT_SIGNED_WRITE_WITHOUT_RSP); - tester_set_bit(cmds, GATT_WRITE); - tester_set_bit(cmds, GATT_WRITE_LONG); - tester_set_bit(cmds, GATT_CFG_NOTIFY); - tester_set_bit(cmds, GATT_CFG_INDICATE); - tester_set_bit(cmds, GATT_GET_ATTRIBUTES); - tester_set_bit(cmds, GATT_GET_ATTRIBUTE_VALUE); - tester_set_bit(cmds, GATT_DISC_ALL_PRIM); - tester_set_bit(cmds, GATT_READ_MULTIPLE_VAR); - tester_set_bit(cmds, GATT_EATT_CONNECT); - tester_set_bit(cmds, GATT_NOTIFY_MULTIPLE); - - tester_send(BTP_SERVICE_ID_GATT, GATT_READ_SUPPORTED_COMMANDS, + tester_set_bit(cmds, BTP_GATT_READ_SUPPORTED_COMMANDS); + tester_set_bit(cmds, BTP_GATT_ADD_SERVICE); + tester_set_bit(cmds, BTP_GATT_ADD_CHARACTERISTIC); + tester_set_bit(cmds, BTP_GATT_ADD_DESCRIPTOR); + tester_set_bit(cmds, BTP_GATT_ADD_INCLUDED_SERVICE); + tester_set_bit(cmds, BTP_GATT_SET_VALUE); + tester_set_bit(cmds, BTP_GATT_START_SERVER); + tester_set_bit(cmds, BTP_GATT_SET_ENC_KEY_SIZE); + tester_set_bit(cmds, BTP_GATT_EXCHANGE_MTU); + tester_set_bit(cmds, BTP_GATT_DISC_PRIM_UUID); + tester_set_bit(cmds, BTP_GATT_FIND_INCLUDED); + tester_set_bit(cmds, BTP_GATT_DISC_ALL_CHRC); + tester_set_bit(cmds, BTP_GATT_DISC_CHRC_UUID); + tester_set_bit(cmds, BTP_GATT_DISC_ALL_DESC); + tester_set_bit(cmds, BTP_GATT_READ); + tester_set_bit(cmds, BTP_GATT_READ_LONG); + tester_set_bit(cmds, BTP_GATT_READ_MULTIPLE); + tester_set_bit(cmds, BTP_GATT_WRITE_WITHOUT_RSP); + tester_set_bit(cmds, BTP_GATT_SIGNED_WRITE_WITHOUT_RSP); + tester_set_bit(cmds, BTP_GATT_WRITE); + tester_set_bit(cmds, BTP_GATT_WRITE_LONG); + tester_set_bit(cmds, BTP_GATT_CFG_NOTIFY); + tester_set_bit(cmds, BTP_GATT_CFG_INDICATE); + tester_set_bit(cmds, BTP_GATT_GET_ATTRIBUTES); + tester_set_bit(cmds, BTP_GATT_GET_ATTRIBUTE_VALUE); + tester_set_bit(cmds, BTP_GATT_DISC_ALL_PRIM); + tester_set_bit(cmds, BTP_GATT_READ_MULTIPLE_VAR); + tester_set_bit(cmds, BTP_GATT_EATT_CONNECT); + tester_set_bit(cmds, BTP_GATT_NOTIFY_MULTIPLE); + + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_READ_SUPPORTED_COMMANDS, CONTROLLER_INDEX, (uint8_t *) rp, sizeof(cmds)); } @@ -278,8 +278,8 @@ static int register_service(void) static void add_service(uint8_t *data, uint16_t len) { - const struct gatt_add_service_cmd *cmd = (void *) data; - struct gatt_add_service_rp rp; + const struct btp_gatt_add_service_cmd *cmd = (void *) data; + struct btp_gatt_add_service_rp rp; struct bt_gatt_attr *attr_svc = NULL; union uuid uuid; size_t uuid_size; @@ -301,12 +301,12 @@ static void add_service(uint8_t *data, uint16_t len) svc_count++; switch (cmd->type) { - case GATT_SERVICE_PRIMARY: + case BTP_GATT_SERVICE_PRIMARY: attr_svc = gatt_db_add(&(struct bt_gatt_attr) BT_GATT_PRIMARY_SERVICE(&uuid.uuid), uuid_size); break; - case GATT_SERVICE_SECONDARY: + case BTP_GATT_SERVICE_SECONDARY: attr_svc = gatt_db_add(&(struct bt_gatt_attr) BT_GATT_SECONDARY_SERVICE(&uuid.uuid), uuid_size); @@ -320,12 +320,12 @@ static void add_service(uint8_t *data, uint16_t len) rp.svc_id = sys_cpu_to_le16(attr_svc->handle); - tester_send(BTP_SERVICE_ID_GATT, GATT_ADD_SERVICE, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_SERVICE, CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); return; fail: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_ADD_SERVICE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_SERVICE, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -362,14 +362,14 @@ static ssize_t read_value(struct bt_conn *conn, const struct bt_gatt_attr *attr, static void attr_value_changed_ev(uint16_t handle, const uint8_t *value, uint16_t len) { - uint8_t buf[len + sizeof(struct gatt_attr_value_changed_ev)]; - struct gatt_attr_value_changed_ev *ev = (void *) buf; + uint8_t buf[len + sizeof(struct btp_gatt_attr_value_changed_ev)]; + struct btp_gatt_attr_value_changed_ev *ev = (void *) buf; ev->handle = sys_cpu_to_le16(handle); ev->data_length = sys_cpu_to_le16(len); memcpy(ev->data, value, len); - tester_send(BTP_SERVICE_ID_GATT, GATT_EV_ATTR_VALUE_CHANGED, + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_EV_ATTR_VALUE_CHANGED, CONTROLLER_INDEX, buf, sizeof(buf)); } @@ -481,8 +481,8 @@ static int alloc_characteristic(struct add_characteristic *ch) static void add_characteristic(uint8_t *data, uint16_t len) { - const struct gatt_add_characteristic_cmd *cmd = (void *) data; - struct gatt_add_characteristic_rp rp; + const struct btp_gatt_add_characteristic_cmd *cmd = (void *) data; + struct btp_gatt_add_characteristic_rp rp; struct add_characteristic cmd_data; union uuid uuid; @@ -509,12 +509,12 @@ static void add_characteristic(uint8_t *data, uint16_t len) ccc_added = false; - tester_send(BTP_SERVICE_ID_GATT, GATT_ADD_CHARACTERISTIC, + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_CHARACTERISTIC, CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); return; fail: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_ADD_CHARACTERISTIC, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_CHARACTERISTIC, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -669,8 +669,8 @@ static struct bt_gatt_attr *get_base_chrc(struct bt_gatt_attr *attr) static void add_descriptor(uint8_t *data, uint16_t len) { - const struct gatt_add_descriptor_cmd *cmd = (void *) data; - struct gatt_add_descriptor_rp rp; + const struct btp_gatt_add_descriptor_cmd *cmd = (void *) data; + struct btp_gatt_add_descriptor_rp rp; struct add_descriptor cmd_data; struct bt_gatt_attr *chrc; union uuid uuid; @@ -705,12 +705,12 @@ static void add_descriptor(uint8_t *data, uint16_t len) } rp.desc_id = sys_cpu_to_le16(cmd_data.desc_id); - tester_send(BTP_SERVICE_ID_GATT, GATT_ADD_DESCRIPTOR, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_DESCRIPTOR, CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); return; fail: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_ADD_DESCRIPTOR, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_DESCRIPTOR, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -738,8 +738,8 @@ static int alloc_included(struct bt_gatt_attr *attr, static void add_included(uint8_t *data, uint16_t len) { - const struct gatt_add_included_service_cmd *cmd = (void *) data; - struct gatt_add_included_service_rp rp; + const struct btp_gatt_add_included_service_cmd *cmd = (void *) data; + struct btp_gatt_add_included_service_rp rp; struct bt_gatt_attr *svc; uint16_t included_service_id = 0U; @@ -760,12 +760,12 @@ static void add_included(uint8_t *data, uint16_t len) } rp.included_service_id = sys_cpu_to_le16(included_service_id); - tester_send(BTP_SERVICE_ID_GATT, GATT_ADD_INCLUDED_SERVICE, + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_INCLUDED_SERVICE, CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); return; fail: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_ADD_INCLUDED_SERVICE, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_INCLUDED_SERVICE, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -862,7 +862,7 @@ static uint8_t alloc_value(struct bt_gatt_attr *attr, struct set_value *data) static void set_value(uint8_t *data, uint16_t len) { - const struct gatt_set_value_cmd *cmd = (void *) data; + const struct btp_gatt_set_value_cmd *cmd = (void *) data; struct set_value cmd_data; uint8_t status; @@ -878,24 +878,24 @@ static void set_value(uint8_t *data, uint16_t len) server_db[0].handle], &cmd_data); } - tester_rsp(BTP_SERVICE_ID_GATT, GATT_SET_VALUE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_SET_VALUE, CONTROLLER_INDEX, status); } static void start_server(uint8_t *data, uint16_t len) { - struct gatt_start_server_rp rp; + struct btp_gatt_start_server_rp rp; /* Register last defined service */ if (svc_attr_count) { if (register_service()) { - tester_rsp(BTP_SERVICE_ID_GATT, GATT_START_SERVER, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_START_SERVER, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } } - tester_send(BTP_SERVICE_ID_GATT, GATT_START_SERVER, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_START_SERVER, CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); } @@ -925,7 +925,7 @@ static int set_attr_enc_key_size(const struct bt_gatt_attr *attr, static void set_enc_key_size(uint8_t *data, uint16_t len) { - const struct gatt_set_enc_key_size_cmd *cmd = (void *) data; + const struct btp_gatt_set_enc_key_size_cmd *cmd = (void *) data; uint8_t status; /* Fail if requested key size is invalid */ @@ -944,7 +944,7 @@ static void set_enc_key_size(uint8_t *data, uint16_t len) } fail: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_SET_ENC_KEY_SIZE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_SET_ENC_KEY_SIZE, CONTROLLER_INDEX, status); } @@ -952,13 +952,13 @@ static void exchange_func(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params) { if (err) { - tester_rsp(BTP_SERVICE_ID_GATT, GATT_EXCHANGE_MTU, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_EXCHANGE_MTU, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } - tester_rsp(BTP_SERVICE_ID_GATT, GATT_EXCHANGE_MTU, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_EXCHANGE_MTU, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } @@ -985,7 +985,7 @@ static void exchange_mtu(uint8_t *data, uint16_t len) return; fail: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_EXCHANGE_MTU, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_EXCHANGE_MTU, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -1004,8 +1004,8 @@ static uint8_t disc_prim_cb(struct bt_conn *conn, struct bt_gatt_discover_params *params) { struct bt_gatt_service_val *data; - struct gatt_disc_prim_rp *rp = (void *) gatt_buf.buf; - struct gatt_service *service; + struct btp_gatt_disc_prim_rp *rp = (void *) gatt_buf.buf; + struct btp_gatt_service *service; uint8_t uuid_length; if (!attr) { @@ -1054,7 +1054,7 @@ static void disc_all_prim(uint8_t *data, uint16_t len) goto fail_conn; } - if (!gatt_buf_reserve(sizeof(struct gatt_disc_prim_rp))) { + if (!gatt_buf_reserve(sizeof(struct btp_gatt_disc_prim_rp))) { goto fail; } @@ -1065,7 +1065,7 @@ static void disc_all_prim(uint8_t *data, uint16_t len) discover_params.func = disc_prim_cb; discover_params.chan_opt = BT_ATT_CHAN_OPT_NONE; - btp_opcode = GATT_DISC_ALL_PRIM; + btp_opcode = BTP_GATT_DISC_ALL_PRIM; if (bt_gatt_discover(conn, &discover_params) < 0) { discover_destroy(&discover_params); @@ -1080,13 +1080,13 @@ static void disc_all_prim(uint8_t *data, uint16_t len) bt_conn_unref(conn); fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_PRIM, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_PRIM, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void disc_prim_uuid(uint8_t *data, uint16_t len) { - const struct gatt_disc_prim_uuid_cmd *cmd = (void *) data; + const struct btp_gatt_disc_prim_uuid_cmd *cmd = (void *) data; struct bt_conn *conn; conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); @@ -1098,7 +1098,7 @@ static void disc_prim_uuid(uint8_t *data, uint16_t len) goto fail; } - if (!gatt_buf_reserve(sizeof(struct gatt_disc_prim_rp))) { + if (!gatt_buf_reserve(sizeof(struct btp_gatt_disc_prim_rp))) { goto fail; } @@ -1109,7 +1109,7 @@ static void disc_prim_uuid(uint8_t *data, uint16_t len) discover_params.func = disc_prim_cb; discover_params.chan_opt = BT_ATT_CHAN_OPT_NONE; - btp_opcode = GATT_DISC_PRIM_UUID; + btp_opcode = BTP_GATT_DISC_PRIM_UUID; if (bt_gatt_discover(conn, &discover_params) < 0) { discover_destroy(&discover_params); @@ -1124,7 +1124,7 @@ static void disc_prim_uuid(uint8_t *data, uint16_t len) bt_conn_unref(conn); fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_PRIM_UUID, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_PRIM_UUID, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -1133,12 +1133,12 @@ static uint8_t find_included_cb(struct bt_conn *conn, struct bt_gatt_discover_params *params) { struct bt_gatt_include *data; - struct gatt_find_included_rp *rp = (void *) gatt_buf.buf; - struct gatt_included *included; + struct btp_gatt_find_included_rp *rp = (void *) gatt_buf.buf; + struct btp_gatt_included *included; uint8_t uuid_length; if (!attr) { - tester_send(BTP_SERVICE_ID_GATT, GATT_FIND_INCLUDED, + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_FIND_INCLUDED, CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len); discover_destroy(params); return BT_GATT_ITER_STOP; @@ -1150,7 +1150,7 @@ static uint8_t find_included_cb(struct bt_conn *conn, included = gatt_buf_reserve(sizeof(*included) + uuid_length); if (!included) { - tester_rsp(BTP_SERVICE_ID_GATT, GATT_FIND_INCLUDED, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_FIND_INCLUDED, CONTROLLER_INDEX, BTP_STATUS_FAILED); discover_destroy(params); return BT_GATT_ITER_STOP; @@ -1177,7 +1177,7 @@ static uint8_t find_included_cb(struct bt_conn *conn, static void find_included(uint8_t *data, uint16_t len) { - const struct gatt_find_included_cmd *cmd = (void *) data; + const struct btp_gatt_find_included_cmd *cmd = (void *) data; struct bt_conn *conn; conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); @@ -1185,7 +1185,7 @@ static void find_included(uint8_t *data, uint16_t len) goto fail_conn; } - if (!gatt_buf_reserve(sizeof(struct gatt_find_included_rp))) { + if (!gatt_buf_reserve(sizeof(struct btp_gatt_find_included_rp))) { goto fail; } @@ -1208,7 +1208,7 @@ static void find_included(uint8_t *data, uint16_t len) bt_conn_unref(conn); fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_FIND_INCLUDED, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_FIND_INCLUDED, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -1217,8 +1217,8 @@ static uint8_t disc_chrc_cb(struct bt_conn *conn, struct bt_gatt_discover_params *params) { struct bt_gatt_chrc *data; - struct gatt_disc_chrc_rp *rp = (void *) gatt_buf.buf; - struct gatt_characteristic *chrc; + struct btp_gatt_disc_chrc_rp *rp = (void *) gatt_buf.buf; + struct btp_gatt_characteristic *chrc; uint8_t uuid_length; if (!attr) { @@ -1260,7 +1260,7 @@ static uint8_t disc_chrc_cb(struct bt_conn *conn, static void disc_all_chrc(uint8_t *data, uint16_t len) { - const struct gatt_disc_all_chrc_cmd *cmd = (void *) data; + const struct btp_gatt_disc_all_chrc_cmd *cmd = (void *) data; struct bt_conn *conn; conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); @@ -1268,7 +1268,7 @@ static void disc_all_chrc(uint8_t *data, uint16_t len) goto fail_conn; } - if (!gatt_buf_reserve(sizeof(struct gatt_disc_chrc_rp))) { + if (!gatt_buf_reserve(sizeof(struct btp_gatt_disc_chrc_rp))) { goto fail; } @@ -1279,7 +1279,7 @@ static void disc_all_chrc(uint8_t *data, uint16_t len) discover_params.chan_opt = BT_ATT_CHAN_OPT_NONE; /* TODO should be handled as user_data via CONTAINER_OF macro */ - btp_opcode = GATT_DISC_ALL_CHRC; + btp_opcode = BTP_GATT_DISC_ALL_CHRC; if (bt_gatt_discover(conn, &discover_params) < 0) { discover_destroy(&discover_params); @@ -1294,13 +1294,13 @@ static void disc_all_chrc(uint8_t *data, uint16_t len) bt_conn_unref(conn); fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_CHRC, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_CHRC, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void disc_chrc_uuid(uint8_t *data, uint16_t len) { - const struct gatt_disc_chrc_uuid_cmd *cmd = (void *) data; + const struct btp_gatt_disc_chrc_uuid_cmd *cmd = (void *) data; struct bt_conn *conn; conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); @@ -1312,7 +1312,7 @@ static void disc_chrc_uuid(uint8_t *data, uint16_t len) goto fail; } - if (!gatt_buf_reserve(sizeof(struct gatt_disc_chrc_rp))) { + if (!gatt_buf_reserve(sizeof(struct btp_gatt_disc_chrc_rp))) { goto fail; } @@ -1324,7 +1324,7 @@ static void disc_chrc_uuid(uint8_t *data, uint16_t len) discover_params.chan_opt = BT_ATT_CHAN_OPT_NONE; /* TODO should be handled as user_data via CONTAINER_OF macro */ - btp_opcode = GATT_DISC_CHRC_UUID; + btp_opcode = BTP_GATT_DISC_CHRC_UUID; if (bt_gatt_discover(conn, &discover_params) < 0) { discover_destroy(&discover_params); @@ -1339,7 +1339,7 @@ static void disc_chrc_uuid(uint8_t *data, uint16_t len) bt_conn_unref(conn); fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_CHRC_UUID, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_CHRC_UUID, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -1347,12 +1347,12 @@ static uint8_t disc_all_desc_cb(struct bt_conn *conn, const struct bt_gatt_attr *attr, struct bt_gatt_discover_params *params) { - struct gatt_disc_all_desc_rp *rp = (void *) gatt_buf.buf; - struct gatt_descriptor *descriptor; + struct btp_gatt_disc_all_desc_rp *rp = (void *) gatt_buf.buf; + struct btp_gatt_descriptor *descriptor; uint8_t uuid_length; if (!attr) { - tester_send(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_DESC, + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_DESC, CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len); discover_destroy(params); return BT_GATT_ITER_STOP; @@ -1362,7 +1362,7 @@ static uint8_t disc_all_desc_cb(struct bt_conn *conn, descriptor = gatt_buf_reserve(sizeof(*descriptor) + uuid_length); if (!descriptor) { - tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_DESC, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_DESC, CONTROLLER_INDEX, BTP_STATUS_FAILED); discover_destroy(params); return BT_GATT_ITER_STOP; @@ -1387,7 +1387,7 @@ static uint8_t disc_all_desc_cb(struct bt_conn *conn, static void disc_all_desc(uint8_t *data, uint16_t len) { - const struct gatt_disc_all_desc_cmd *cmd = (void *) data; + const struct btp_gatt_disc_all_desc_cmd *cmd = (void *) data; struct bt_conn *conn; conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); @@ -1395,7 +1395,7 @@ static void disc_all_desc(uint8_t *data, uint16_t len) goto fail_conn; } - if (!gatt_buf_reserve(sizeof(struct gatt_disc_all_desc_rp))) { + if (!gatt_buf_reserve(sizeof(struct btp_gatt_disc_all_desc_rp))) { goto fail; } @@ -1418,7 +1418,7 @@ static void disc_all_desc(uint8_t *data, uint16_t len) bt_conn_unref(conn); fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_DESC, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_DESC, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -1434,7 +1434,7 @@ static uint8_t read_cb(struct bt_conn *conn, uint8_t err, struct bt_gatt_read_params *params, const void *data, uint16_t length) { - struct gatt_read_rp *rp = (void *) gatt_buf.buf; + struct btp_gatt_read_rp *rp = (void *) gatt_buf.buf; /* Respond to the Lower Tester with ATT Error received */ if (err) { @@ -1465,8 +1465,8 @@ static uint8_t read_uuid_cb(struct bt_conn *conn, uint8_t err, struct bt_gatt_read_params *params, const void *data, uint16_t length) { - struct gatt_read_uuid_rp *rp = (void *)gatt_buf.buf; - struct gatt_char_value value; + struct btp_gatt_read_uuid_rp *rp = (void *)gatt_buf.buf; + struct btp_gatt_char_value value; /* Respond to the Lower Tester with ATT Error received */ if (err) { @@ -1485,7 +1485,7 @@ static uint8_t read_uuid_cb(struct bt_conn *conn, uint8_t err, value.handle = params->by_uuid.start_handle; value.data_len = length; - if (!gatt_buf_add(&value, sizeof(struct gatt_char_value))) { + if (!gatt_buf_add(&value, sizeof(struct btp_gatt_char_value))) { tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode, CONTROLLER_INDEX, BTP_STATUS_FAILED); read_destroy(params); @@ -1508,7 +1508,7 @@ static uint8_t read_uuid_cb(struct bt_conn *conn, uint8_t err, static void read_data(uint8_t *data, uint16_t len) { - const struct gatt_read_cmd *cmd = (void *) data; + const struct btp_gatt_read_cmd *cmd = (void *) data; struct bt_conn *conn; conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); @@ -1516,7 +1516,7 @@ static void read_data(uint8_t *data, uint16_t len) goto fail_conn; } - if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) { + if (!gatt_buf_reserve(sizeof(struct btp_gatt_read_rp))) { goto fail; } @@ -1527,7 +1527,7 @@ static void read_data(uint8_t *data, uint16_t len) read_params.chan_opt = BT_ATT_CHAN_OPT_NONE; /* TODO should be handled as user_data via CONTAINER_OF macro */ - btp_opcode = GATT_READ; + btp_opcode = BTP_GATT_READ; if (bt_gatt_read(conn, &read_params) < 0) { read_destroy(&read_params); @@ -1542,13 +1542,13 @@ static void read_data(uint8_t *data, uint16_t len) bt_conn_unref(conn); fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_READ, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void read_uuid(uint8_t *data, uint16_t len) { - const struct gatt_read_uuid_cmd *cmd = (void *) data; + const struct btp_gatt_read_uuid_cmd *cmd = (void *) data; struct bt_conn *conn; conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); @@ -1560,7 +1560,7 @@ static void read_uuid(uint8_t *data, uint16_t len) goto fail; } - if (!gatt_buf_reserve(sizeof(struct gatt_read_uuid_rp))) { + if (!gatt_buf_reserve(sizeof(struct btp_gatt_read_uuid_rp))) { goto fail; } @@ -1571,7 +1571,7 @@ static void read_uuid(uint8_t *data, uint16_t len) read_params.func = read_uuid_cb; read_params.chan_opt = BT_ATT_CHAN_OPT_NONE; - btp_opcode = GATT_READ_UUID; + btp_opcode = BTP_GATT_READ_UUID; if (bt_gatt_read(conn, &read_params) < 0) { read_destroy(&read_params); @@ -1586,13 +1586,13 @@ static void read_uuid(uint8_t *data, uint16_t len) bt_conn_unref(conn); fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ_UUID, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_READ_UUID, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void read_long(uint8_t *data, uint16_t len) { - const struct gatt_read_long_cmd *cmd = (void *) data; + const struct btp_gatt_read_long_cmd *cmd = (void *) data; struct bt_conn *conn; conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); @@ -1600,7 +1600,7 @@ static void read_long(uint8_t *data, uint16_t len) goto fail_conn; } - if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) { + if (!gatt_buf_reserve(sizeof(struct btp_gatt_read_rp))) { goto fail; } @@ -1611,7 +1611,7 @@ static void read_long(uint8_t *data, uint16_t len) read_params.chan_opt = BT_ATT_CHAN_OPT_NONE; /* TODO should be handled as user_data via CONTAINER_OF macro */ - btp_opcode = GATT_READ_LONG; + btp_opcode = BTP_GATT_READ_LONG; if (bt_gatt_read(conn, &read_params) < 0) { read_destroy(&read_params); @@ -1626,13 +1626,13 @@ static void read_long(uint8_t *data, uint16_t len) bt_conn_unref(conn); fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ_LONG, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_READ_LONG, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void read_multiple(uint8_t *data, uint16_t len, uint8_t opcode) { - const struct gatt_read_multiple_cmd *cmd = (void *) data; + const struct btp_gatt_read_multiple_cmd *cmd = (void *) data; uint16_t handles[cmd->handles_count]; struct bt_conn *conn; int i; @@ -1646,14 +1646,14 @@ static void read_multiple(uint8_t *data, uint16_t len, uint8_t opcode) goto fail_conn; } - if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) { + if (!gatt_buf_reserve(sizeof(struct btp_gatt_read_rp))) { goto fail; } read_params.func = read_cb; read_params.handle_count = i; read_params.multiple.handles = handles; /* not used in read func */ - read_params.multiple.variable = (opcode == GATT_READ_MULTIPLE_VAR); + read_params.multiple.variable = (opcode == BTP_GATT_READ_MULTIPLE_VAR); read_params.chan_opt = BT_ATT_CHAN_OPT_NONE; /* TODO should be handled as user_data via CONTAINER_OF macro */ @@ -1671,14 +1671,14 @@ static void read_multiple(uint8_t *data, uint16_t len, uint8_t opcode) bt_conn_unref(conn); fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ_MULTIPLE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_READ_MULTIPLE, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void write_without_rsp(uint8_t *data, uint16_t len, uint8_t op, bool sign) { - const struct gatt_write_without_rsp_cmd *cmd = (void *) data; + const struct btp_gatt_write_without_rsp_cmd *cmd = (void *) data; struct bt_conn *conn; uint8_t status = BTP_STATUS_SUCCESS; @@ -1703,7 +1703,7 @@ static void write_without_rsp(uint8_t *data, uint16_t len, uint8_t op, static void write_rsp(struct bt_conn *conn, uint8_t err, struct bt_gatt_write_params *params) { - tester_send(BTP_SERVICE_ID_GATT, GATT_WRITE, CONTROLLER_INDEX, &err, + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE, CONTROLLER_INDEX, &err, sizeof(err)); } @@ -1711,7 +1711,7 @@ static struct bt_gatt_write_params write_params; static void write_data(uint8_t *data, uint16_t len) { - const struct gatt_write_cmd *cmd = (void *) data; + const struct btp_gatt_write_cmd *cmd = (void *) data; struct bt_conn *conn; conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); @@ -1735,20 +1735,20 @@ static void write_data(uint8_t *data, uint16_t len) return; fail: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_WRITE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void write_long_rsp(struct bt_conn *conn, uint8_t err, struct bt_gatt_write_params *params) { - tester_send(BTP_SERVICE_ID_GATT, GATT_WRITE_LONG, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE_LONG, CONTROLLER_INDEX, &err, sizeof(err)); } static void write_long(uint8_t *data, uint16_t len) { - const struct gatt_write_long_cmd *cmd = (void *) data; + const struct btp_gatt_write_long_cmd *cmd = (void *) data; struct bt_conn *conn; conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); @@ -1772,7 +1772,7 @@ static void write_long(uint8_t *data, uint16_t len) return; fail: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_WRITE_LONG, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE_LONG, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -1792,13 +1792,13 @@ static struct bt_gatt_subscribe_params *find_subscription(uint16_t ccc_handle) /* TODO there should be better way of determining max supported MTU */ #define MAX_NOTIF_DATA (MIN(BT_L2CAP_RX_MTU, BT_L2CAP_TX_MTU) - 3) -static uint8_t ev_buf[sizeof(struct gatt_notification_ev) + MAX_NOTIF_DATA]; +static uint8_t ev_buf[sizeof(struct btp_gatt_notification_ev) + MAX_NOTIF_DATA]; static uint8_t notify_func(struct bt_conn *conn, struct bt_gatt_subscribe_params *params, const void *data, uint16_t length) { - struct gatt_notification_ev *ev = (void *) ev_buf; + struct btp_gatt_notification_ev *ev = (void *) ev_buf; const bt_addr_le_t *addr; if (!conn || !data) { @@ -1817,7 +1817,7 @@ static uint8_t notify_func(struct bt_conn *conn, memcpy(ev->address, addr->a.val, sizeof(ev->address)); ev->address_type = addr->type; - tester_send(BTP_SERVICE_ID_GATT, GATT_EV_NOTIFICATION, + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_EV_NOTIFICATION, CONTROLLER_INDEX, ev_buf, sizeof(*ev) + length); return BT_GATT_ITER_CONTINUE; @@ -1846,8 +1846,8 @@ static void discover_complete(struct bt_conn *conn, status = BTP_STATUS_SUCCESS; fail: - op = subscription->value == BT_GATT_CCC_NOTIFY ? GATT_CFG_NOTIFY : - GATT_CFG_INDICATE; + op = subscription->value == BT_GATT_CCC_NOTIFY ? BTP_GATT_CFG_NOTIFY : + BTP_GATT_CFG_INDICATE; if (status == BTP_STATUS_FAILED) { (void)memset(subscription, 0, sizeof(*subscription)); @@ -1937,7 +1937,7 @@ static int disable_subscription(struct bt_conn *conn, uint16_t ccc_handle) static void config_subscription(uint8_t *data, uint16_t len, uint16_t op) { - const struct gatt_cfg_notify_cmd *cmd = (void *) data; + const struct btp_gatt_cfg_notify_cmd *cmd = (void *) data; struct bt_conn *conn; uint16_t ccc_handle = sys_le16_to_cpu(cmd->ccc_handle); uint8_t status; @@ -1952,7 +1952,7 @@ static void config_subscription(uint8_t *data, uint16_t len, uint16_t op) if (cmd->enable) { uint16_t value; - if (op == GATT_CFG_NOTIFY) { + if (op == BTP_GATT_CFG_NOTIFY) { value = BT_GATT_CCC_NOTIFY; } else { value = BT_GATT_CCC_INDICATE; @@ -1988,7 +1988,7 @@ static void notify_cb(struct bt_conn *conn, void *user_data) static void notify_mult(uint8_t *data, uint16_t len, uint16_t op) { - const struct gatt_cfg_notify_mult_cmd *cmd = (void *) data; + const struct btp_gatt_cfg_notify_mult_cmd *cmd = (void *) data; const size_t max_cnt = CONFIG_BT_L2CAP_TX_BUF_COUNT; struct bt_gatt_notify_params params[max_cnt]; struct bt_conn *conn; @@ -2050,7 +2050,7 @@ static uint8_t get_attrs_rp(const struct bt_gatt_attr *attr, uint16_t handle, void *user_data) { struct get_attrs_foreach_data *foreach = user_data; - struct gatt_attr *gatt_attr; + struct btp_gatt_attr *gatt_attr; if (foreach->uuid && bt_uuid_cmp(foreach->uuid, attr->uuid)) { @@ -2079,8 +2079,8 @@ static uint8_t get_attrs_rp(const struct bt_gatt_attr *attr, uint16_t handle, static void get_attrs(uint8_t *data, uint16_t len) { - const struct gatt_get_attributes_cmd *cmd = (void *) data; - struct gatt_get_attributes_rp *rp; + const struct btp_gatt_get_attributes_cmd *cmd = (void *) data; + struct btp_gatt_get_attributes_rp *rp; struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE); struct get_attrs_foreach_data foreach; uint16_t start_handle, end_handle; @@ -2117,12 +2117,12 @@ static void get_attrs(uint8_t *data, uint16_t len) rp = net_buf_simple_push(buf, sizeof(*rp)); rp->attrs_count = foreach.count; - tester_send(BTP_SERVICE_ID_GATT, GATT_GET_ATTRIBUTES, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_GET_ATTRIBUTES, CONTROLLER_INDEX, buf->data, buf->len); return; fail: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_GET_ATTRIBUTES, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_GET_ATTRIBUTES, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -2141,7 +2141,7 @@ static uint8_t get_attr_val_rp(const struct bt_gatt_attr *attr, uint16_t handle, struct get_attr_data *u_data = user_data; struct net_buf_simple *buf = u_data->buf; struct bt_conn *conn = u_data->conn; - struct gatt_get_attribute_value_rp *rp; + struct btp_gatt_get_attribute_value_rp *rp; ssize_t read, to_read; rp = net_buf_simple_add(buf, sizeof(*rp)); @@ -2173,7 +2173,7 @@ static uint8_t get_attr_val_rp(const struct bt_gatt_attr *attr, uint16_t handle, static void get_attr_val(uint8_t *data, uint16_t len) { - const struct gatt_get_attribute_value_cmd *cmd = (void *) data; + const struct btp_gatt_get_attribute_value_cmd *cmd = (void *) data; struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE); uint16_t handle = sys_le16_to_cpu(cmd->handle); struct bt_conn *conn; @@ -2187,17 +2187,17 @@ static void get_attr_val(uint8_t *data, uint16_t len) bt_gatt_foreach_attr(handle, handle, get_attr_val_rp, &cb_data); if (buf->len) { - tester_send(BTP_SERVICE_ID_GATT, GATT_GET_ATTRIBUTE_VALUE, + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_GET_ATTRIBUTE_VALUE, CONTROLLER_INDEX, buf->data, buf->len); } else { - tester_rsp(BTP_SERVICE_ID_GATT, GATT_GET_ATTRIBUTE_VALUE, + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_GET_ATTRIBUTE_VALUE, CONTROLLER_INDEX, BTP_STATUS_FAILED); } } static void eatt_connect(uint8_t *data, uint16_t len) { - const struct gatt_eatt_connect_cmd *cmd = (void *)data; + const struct btp_gatt_eatt_connect_cmd *cmd = (void *)data; struct bt_conn *conn; uint8_t status = BTP_STATUS_SUCCESS; int err; @@ -2216,97 +2216,97 @@ static void eatt_connect(uint8_t *data, uint16_t len) bt_conn_unref(conn); response: - tester_rsp(BTP_SERVICE_ID_GATT, GATT_EATT_CONNECT, CONTROLLER_INDEX, status); + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_EATT_CONNECT, CONTROLLER_INDEX, status); } void tester_handle_gatt(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len) { switch (opcode) { - case GATT_READ_SUPPORTED_COMMANDS: + case BTP_GATT_READ_SUPPORTED_COMMANDS: supported_commands(data, len); return; - case GATT_ADD_SERVICE: + case BTP_GATT_ADD_SERVICE: add_service(data, len); return; - case GATT_ADD_CHARACTERISTIC: + case BTP_GATT_ADD_CHARACTERISTIC: add_characteristic(data, len); return; - case GATT_ADD_DESCRIPTOR: + case BTP_GATT_ADD_DESCRIPTOR: add_descriptor(data, len); return; - case GATT_ADD_INCLUDED_SERVICE: + case BTP_GATT_ADD_INCLUDED_SERVICE: add_included(data, len); return; - case GATT_SET_VALUE: + case BTP_GATT_SET_VALUE: set_value(data, len); return; - case GATT_START_SERVER: + case BTP_GATT_START_SERVER: start_server(data, len); return; - case GATT_SET_ENC_KEY_SIZE: + case BTP_GATT_SET_ENC_KEY_SIZE: set_enc_key_size(data, len); return; - case GATT_EXCHANGE_MTU: + case BTP_GATT_EXCHANGE_MTU: exchange_mtu(data, len); return; - case GATT_DISC_ALL_PRIM: + case BTP_GATT_DISC_ALL_PRIM: disc_all_prim(data, len); return; - case GATT_DISC_PRIM_UUID: + case BTP_GATT_DISC_PRIM_UUID: disc_prim_uuid(data, len); return; - case GATT_FIND_INCLUDED: + case BTP_GATT_FIND_INCLUDED: find_included(data, len); return; - case GATT_DISC_ALL_CHRC: + case BTP_GATT_DISC_ALL_CHRC: disc_all_chrc(data, len); return; - case GATT_DISC_CHRC_UUID: + case BTP_GATT_DISC_CHRC_UUID: disc_chrc_uuid(data, len); return; - case GATT_DISC_ALL_DESC: + case BTP_GATT_DISC_ALL_DESC: disc_all_desc(data, len); return; - case GATT_READ: + case BTP_GATT_READ: read_data(data, len); return; - case GATT_READ_UUID: + case BTP_GATT_READ_UUID: read_uuid(data, len); return; - case GATT_READ_LONG: + case BTP_GATT_READ_LONG: read_long(data, len); return; - case GATT_READ_MULTIPLE: - case GATT_READ_MULTIPLE_VAR: + case BTP_GATT_READ_MULTIPLE: + case BTP_GATT_READ_MULTIPLE_VAR: read_multiple(data, len, opcode); return; - case GATT_WRITE_WITHOUT_RSP: + case BTP_GATT_WRITE_WITHOUT_RSP: write_without_rsp(data, len, opcode, false); return; - case GATT_SIGNED_WRITE_WITHOUT_RSP: + case BTP_GATT_SIGNED_WRITE_WITHOUT_RSP: write_without_rsp(data, len, opcode, true); return; - case GATT_WRITE: + case BTP_GATT_WRITE: write_data(data, len); return; - case GATT_WRITE_LONG: + case BTP_GATT_WRITE_LONG: write_long(data, len); return; - case GATT_CFG_NOTIFY: - case GATT_CFG_INDICATE: + case BTP_GATT_CFG_NOTIFY: + case BTP_GATT_CFG_INDICATE: config_subscription(data, len, opcode); return; - case GATT_GET_ATTRIBUTES: + case BTP_GATT_GET_ATTRIBUTES: get_attrs(data, len); return; - case GATT_GET_ATTRIBUTE_VALUE: + case BTP_GATT_GET_ATTRIBUTE_VALUE: get_attr_val(data, len); return; - case GATT_EATT_CONNECT: + case BTP_GATT_EATT_CONNECT: eatt_connect(data, len); return; - case GATT_NOTIFY_MULTIPLE: + case BTP_GATT_NOTIFY_MULTIPLE: notify_mult(data, len, opcode); return; default: diff --git a/tests/bluetooth/tester/src/btp_ias.c b/tests/bluetooth/tester/src/btp_ias.c index bd3a2fc3f5de..1663d673b11e 100644 --- a/tests/bluetooth/tester/src/btp_ias.c +++ b/tests/bluetooth/tester/src/btp_ias.c @@ -20,31 +20,31 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); /* Immediate Alert Service */ static void alert_stop(void) { - struct ias_alert_action_ev ev; + struct btp_ias_alert_action_ev ev; ev.alert_lvl = BT_IAS_ALERT_LVL_NO_ALERT; - tester_send(BTP_SERVICE_ID_IAS, IAS_EV_OUT_ALERT_ACTION, + tester_send(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, CONTROLLER_INDEX, (uint8_t *)&ev, sizeof(ev)); } static void alert_start(void) { - struct ias_alert_action_ev ev; + struct btp_ias_alert_action_ev ev; ev.alert_lvl = BT_IAS_ALERT_LVL_MILD_ALERT; - tester_send(BTP_SERVICE_ID_IAS, IAS_EV_OUT_ALERT_ACTION, + tester_send(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, CONTROLLER_INDEX, (uint8_t *)&ev.alert_lvl, sizeof(ev)); } static void alert_high_start(void) { - struct ias_alert_action_ev ev; + struct btp_ias_alert_action_ev ev; ev.alert_lvl = BT_IAS_ALERT_LVL_HIGH_ALERT; - tester_send(BTP_SERVICE_ID_IAS, IAS_EV_OUT_ALERT_ACTION, + tester_send(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, CONTROLLER_INDEX, (uint8_t *)&ev, sizeof(ev)); } diff --git a/tests/bluetooth/tester/src/btp_l2cap.c b/tests/bluetooth/tester/src/btp_l2cap.c index f2f121bf7c1d..6894ba0646aa 100644 --- a/tests/bluetooth/tester/src/btp_l2cap.c +++ b/tests/bluetooth/tester/src/btp_l2cap.c @@ -47,18 +47,18 @@ static struct net_buf *alloc_buf_cb(struct bt_l2cap_chan *chan) return net_buf_alloc(&data_pool, K_FOREVER); } -static uint8_t recv_cb_buf[DATA_BUF_SIZE + sizeof(struct l2cap_data_received_ev)]; +static uint8_t recv_cb_buf[DATA_BUF_SIZE + sizeof(struct btp_l2cap_data_received_ev)]; static int recv_cb(struct bt_l2cap_chan *l2cap_chan, struct net_buf *buf) { - struct l2cap_data_received_ev *ev = (void *) recv_cb_buf; + struct btp_l2cap_data_received_ev *ev = (void *) recv_cb_buf; struct channel *chan = CONTAINER_OF(l2cap_chan, struct channel, le); ev->chan_id = chan->chan_id; ev->data_length = sys_cpu_to_le16(buf->len); memcpy(ev->data, buf->data, buf->len); - tester_send(BTP_SERVICE_ID_L2CAP, L2CAP_EV_DATA_RECEIVED, + tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_DATA_RECEIVED, CONTROLLER_INDEX, recv_cb_buf, sizeof(*ev) + buf->len); if (chan->hold_credit && !chan->pending_credit) { @@ -74,7 +74,7 @@ static int recv_cb(struct bt_l2cap_chan *l2cap_chan, struct net_buf *buf) static void connected_cb(struct bt_l2cap_chan *l2cap_chan) { - struct l2cap_connected_ev ev; + struct btp_l2cap_connected_ev ev; struct channel *chan = CONTAINER_OF(l2cap_chan, struct channel, le); struct bt_conn_info info; @@ -98,13 +98,13 @@ static void connected_cb(struct bt_l2cap_chan *l2cap_chan) } } - tester_send(BTP_SERVICE_ID_L2CAP, L2CAP_EV_CONNECTED, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_CONNECTED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } static void disconnected_cb(struct bt_l2cap_chan *l2cap_chan) { - struct l2cap_disconnected_ev ev; + struct btp_l2cap_disconnected_ev ev; struct channel *chan = CONTAINER_OF(l2cap_chan, struct channel, le); struct bt_conn_info info; @@ -114,7 +114,7 @@ static void disconnected_cb(struct bt_l2cap_chan *l2cap_chan) chan->pending_credit = NULL; } - (void)memset(&ev, 0, sizeof(struct l2cap_disconnected_ev)); + (void)memset(&ev, 0, sizeof(struct btp_l2cap_disconnected_ev)); /* TODO: ev.result */ ev.chan_id = chan->chan_id; @@ -135,14 +135,14 @@ static void disconnected_cb(struct bt_l2cap_chan *l2cap_chan) chan->in_use = false; - tester_send(BTP_SERVICE_ID_L2CAP, L2CAP_EV_DISCONNECTED, + tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_DISCONNECTED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } #if defined(CONFIG_BT_L2CAP_ECRED) static void reconfigured_cb(struct bt_l2cap_chan *l2cap_chan) { - struct l2cap_reconfigured_ev ev; + struct btp_l2cap_reconfigured_ev ev; struct channel *chan = CONTAINER_OF(l2cap_chan, struct channel, le); (void)memset(&ev, 0, sizeof(ev)); @@ -153,7 +153,7 @@ static void reconfigured_cb(struct bt_l2cap_chan *l2cap_chan) ev.mtu_local = sys_cpu_to_le16(chan->le.rx.mtu); ev.mps_local = sys_cpu_to_le16(chan->le.rx.mps); - tester_send(BTP_SERVICE_ID_L2CAP, L2CAP_EV_RECONFIGURED, + tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_RECONFIGURED, CONTROLLER_INDEX, (uint8_t *)&ev, sizeof(ev)); } #endif @@ -194,15 +194,15 @@ static struct channel *get_free_channel() static void connect(uint8_t *data, uint16_t len) { - const struct l2cap_connect_cmd *cmd = (void *) data; - struct l2cap_connect_rp *rp; + const struct btp_l2cap_connect_cmd *cmd = (void *) data; + struct btp_l2cap_connect_rp *rp; struct bt_conn *conn; struct channel *chan = NULL; struct bt_l2cap_chan *allocated_channels[5] = {}; uint16_t mtu = sys_le16_to_cpu(cmd->mtu); uint8_t buf[sizeof(*rp) + CHANNELS]; uint8_t i = 0; - bool ecfc = cmd->options & L2CAP_CONNECT_OPT_ECFC; + bool ecfc = cmd->options & BTP_L2CAP_CONNECT_OPT_ECFC; int err; if (cmd->num == 0 || cmd->num > CHANNELS || mtu > DATA_MTU_INITIAL) { @@ -226,7 +226,7 @@ static void connect(uint8_t *data, uint16_t len) rp->chan_id[i] = chan->chan_id; allocated_channels[i] = &chan->le.chan; - chan->hold_credit = cmd->options & L2CAP_CONNECT_OPT_HOLD_CREDIT; + chan->hold_credit = cmd->options & BTP_L2CAP_CONNECT_OPT_HOLD_CREDIT; } if (cmd->num == 1 && !ecfc) { @@ -251,7 +251,7 @@ static void connect(uint8_t *data, uint16_t len) rp->num = cmd->num; - tester_send(BTP_SERVICE_ID_L2CAP, L2CAP_CONNECT, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_CONNECT, CONTROLLER_INDEX, (uint8_t *)rp, sizeof(*rp) + rp->num); return; @@ -262,13 +262,13 @@ static void connect(uint8_t *data, uint16_t len) channels[BT_L2CAP_LE_CHAN(allocated_channels[i])->ident].in_use = false; } } - tester_rsp(BTP_SERVICE_ID_L2CAP, L2CAP_CONNECT, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_CONNECT, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void disconnect(uint8_t *data, uint16_t len) { - const struct l2cap_disconnect_cmd *cmd = (void *) data; + const struct btp_l2cap_disconnect_cmd *cmd = (void *) data; struct channel *chan = &channels[cmd->chan_id]; uint8_t status; int err; @@ -282,14 +282,14 @@ static void disconnect(uint8_t *data, uint16_t len) status = BTP_STATUS_SUCCESS; rsp: - tester_rsp(BTP_SERVICE_ID_L2CAP, L2CAP_DISCONNECT, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_DISCONNECT, CONTROLLER_INDEX, status); } #if defined(CONFIG_BT_L2CAP_ECRED) static void reconfigure(uint8_t *data, uint16_t len) { - const struct l2cap_reconfigure_cmd *cmd = (void *)data; + const struct btp_l2cap_reconfigure_cmd *cmd = (void *)data; uint16_t mtu = sys_le16_to_cpu(cmd->mtu); struct bt_conn *conn; uint8_t status; @@ -333,7 +333,7 @@ static void reconfigure(uint8_t *data, uint16_t len) status = BTP_STATUS_SUCCESS; rsp: - tester_rsp(BTP_SERVICE_ID_L2CAP, L2CAP_RECONFIGURE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_RECONFIGURE, CONTROLLER_INDEX, status); } #endif @@ -341,7 +341,7 @@ static void reconfigure(uint8_t *data, uint16_t len) #if defined(CONFIG_BT_EATT) void disconnect_eatt_chans(uint8_t *data, uint16_t len) { - const struct l2cap_disconnect_eatt_chans_cmd *cmd = (void *) data; + const struct btp_l2cap_disconnect_eatt_chans_cmd *cmd = (void *) data; struct bt_conn *conn; int err; int status; @@ -366,14 +366,14 @@ void disconnect_eatt_chans(uint8_t *data, uint16_t len) unref: bt_conn_unref(conn); failed: - tester_rsp(BTP_SERVICE_ID_L2CAP, L2CAP_DISCONNECT_EATT_CHANS, + tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_DISCONNECT_EATT_CHANS, CONTROLLER_INDEX, status); } #endif static void send_data(uint8_t *data, uint16_t len) { - const struct l2cap_send_data_cmd *cmd = (void *) data; + const struct btp_l2cap_send_data_cmd *cmd = (void *) data; struct channel *chan = &channels[cmd->chan_id]; struct net_buf *buf; int ret; @@ -400,12 +400,12 @@ static void send_data(uint8_t *data, uint16_t len) goto fail; } - tester_rsp(BTP_SERVICE_ID_L2CAP, L2CAP_SEND_DATA, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_SEND_DATA, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); return; fail: - tester_rsp(BTP_SERVICE_ID_L2CAP, L2CAP_SEND_DATA, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_SEND_DATA, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -464,7 +464,7 @@ static int accept(struct bt_conn *conn, struct bt_l2cap_chan **l2cap_chan) static void listen(uint8_t *data, uint16_t len) { - const struct l2cap_listen_cmd *cmd = (void *) data; + const struct btp_l2cap_listen_cmd *cmd = (void *) data; struct bt_l2cap_server *server; /* TODO: Handle cmd->transport flag */ @@ -485,12 +485,12 @@ static void listen(uint8_t *data, uint16_t len) server->accept = accept; server->psm = cmd->psm; - if (cmd->response == L2CAP_CONNECTION_RESPONSE_INSUFF_ENC_KEY) { + if (cmd->response == BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_ENC_KEY) { /* TSPX_psm_encryption_key_size_required */ req_keysize = 16; - } else if (cmd->response == L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHOR) { + } else if (cmd->response == BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHOR) { authorize_flag = true; - } else if (cmd->response == L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHEN) { + } else if (cmd->response == BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHEN) { server->sec_level = BT_SECURITY_L3; } @@ -499,18 +499,18 @@ static void listen(uint8_t *data, uint16_t len) goto fail; } - tester_rsp(BTP_SERVICE_ID_L2CAP, L2CAP_LISTEN, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_LISTEN, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); return; fail: - tester_rsp(BTP_SERVICE_ID_L2CAP, L2CAP_LISTEN, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_LISTEN, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void credits(uint8_t *data, uint16_t len) { - const struct l2cap_credits_cmd *cmd = (void *)data; + const struct btp_l2cap_credits_cmd *cmd = (void *)data; struct channel *chan = &channels[cmd->chan_id]; if (!chan->in_use) { @@ -526,35 +526,35 @@ static void credits(uint8_t *data, uint16_t len) chan->pending_credit = NULL; } - tester_rsp(BTP_SERVICE_ID_L2CAP, L2CAP_CREDITS, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_CREDITS, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); return; fail: - tester_rsp(BTP_SERVICE_ID_L2CAP, L2CAP_CREDITS, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_CREDITS, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void supported_commands(uint8_t *data, uint16_t len) { uint8_t cmds[2]; - struct l2cap_read_supported_commands_rp *rp = (void *) cmds; + struct btp_l2cap_read_supported_commands_rp *rp = (void *) cmds; (void)memset(cmds, 0, sizeof(cmds)); - tester_set_bit(cmds, L2CAP_READ_SUPPORTED_COMMANDS); - tester_set_bit(cmds, L2CAP_CONNECT); - tester_set_bit(cmds, L2CAP_DISCONNECT); - tester_set_bit(cmds, L2CAP_LISTEN); - tester_set_bit(cmds, L2CAP_SEND_DATA); + tester_set_bit(cmds, BTP_L2CAP_READ_SUPPORTED_COMMANDS); + tester_set_bit(cmds, BTP_L2CAP_CONNECT); + tester_set_bit(cmds, BTP_L2CAP_DISCONNECT); + tester_set_bit(cmds, BTP_L2CAP_LISTEN); + tester_set_bit(cmds, BTP_L2CAP_SEND_DATA); #if defined(CONFIG_BT_L2CAP_ECRED) - tester_set_bit(cmds, L2CAP_RECONFIGURE); + tester_set_bit(cmds, BTP_L2CAP_RECONFIGURE); #endif - tester_set_bit(cmds, L2CAP_CREDITS); + tester_set_bit(cmds, BTP_L2CAP_CREDITS); #if defined(CONFIG_BT_EATT) - tester_set_bit(cmds, L2CAP_DISCONNECT_EATT_CHANS); + tester_set_bit(cmds, BTP_L2CAP_DISCONNECT_EATT_CHANS); #endif - tester_send(BTP_SERVICE_ID_L2CAP, L2CAP_READ_SUPPORTED_COMMANDS, + tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_READ_SUPPORTED_COMMANDS, CONTROLLER_INDEX, (uint8_t *) rp, sizeof(cmds)); } @@ -562,31 +562,31 @@ void tester_handle_l2cap(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len) { switch (opcode) { - case L2CAP_READ_SUPPORTED_COMMANDS: + case BTP_L2CAP_READ_SUPPORTED_COMMANDS: supported_commands(data, len); return; - case L2CAP_CONNECT: + case BTP_L2CAP_CONNECT: connect(data, len); return; - case L2CAP_DISCONNECT: + case BTP_L2CAP_DISCONNECT: disconnect(data, len); return; - case L2CAP_SEND_DATA: + case BTP_L2CAP_SEND_DATA: send_data(data, len); return; - case L2CAP_LISTEN: + case BTP_L2CAP_LISTEN: listen(data, len); return; #if defined(CONFIG_BT_L2CAP_ECRED) - case L2CAP_RECONFIGURE: + case BTP_L2CAP_RECONFIGURE: reconfigure(data, len); return; #endif - case L2CAP_CREDITS: + case BTP_L2CAP_CREDITS: credits(data, len); return; #if defined(CONFIG_BT_EATT) - case L2CAP_DISCONNECT_EATT_CHANS: + case BTP_L2CAP_DISCONNECT_EATT_CHANS: disconnect_eatt_chans(data, len); return; #endif diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 5a4af80564a8..3421be88059b 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -78,83 +78,83 @@ static void supported_commands(uint8_t *data, uint16_t len) struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE); net_buf_simple_init(buf, 0); - net_buf_simple_add_u8(buf, MESH_READ_SUPPORTED_COMMANDS); - net_buf_simple_add_u8(buf, MESH_CONFIG_PROVISIONING); - net_buf_simple_add_u8(buf, MESH_PROVISION_NODE); - net_buf_simple_add_u8(buf, MESH_INIT); - net_buf_simple_add_u8(buf, MESH_RESET); - net_buf_simple_add_u8(buf, MESH_INPUT_NUMBER); - net_buf_simple_add_u8(buf, MESH_INPUT_STRING); - net_buf_simple_add_u8(buf, MESH_IVU_TEST_MODE); - net_buf_simple_add_u8(buf, MESH_IVU_TOGGLE_STATE); - net_buf_simple_add_u8(buf, MESH_NET_SEND); - net_buf_simple_add_u8(buf, MESH_HEALTH_GENERATE_FAULTS); - net_buf_simple_add_u8(buf, MESH_HEALTH_CLEAR_FAULTS); - net_buf_simple_add_u8(buf, MESH_LPN); - net_buf_simple_add_u8(buf, MESH_LPN_POLL); - net_buf_simple_add_u8(buf, MESH_MODEL_SEND); + net_buf_simple_add_u8(buf, BTP_MESH_READ_SUPPORTED_COMMANDS); + net_buf_simple_add_u8(buf, BTP_MESH_CONFIG_PROVISIONING); + net_buf_simple_add_u8(buf, BTP_MESH_PROVISION_NODE); + net_buf_simple_add_u8(buf, BTP_MESH_INIT); + net_buf_simple_add_u8(buf, BTP_MESH_RESET); + net_buf_simple_add_u8(buf, BTP_MESH_INPUT_NUMBER); + net_buf_simple_add_u8(buf, BTP_MESH_INPUT_STRING); + net_buf_simple_add_u8(buf, BTP_MESH_IVU_TEST_MODE); + net_buf_simple_add_u8(buf, BTP_MESH_IVU_TOGGLE_STATE); + net_buf_simple_add_u8(buf, BTP_MESH_NET_SEND); + net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_GENERATE_FAULTS); + net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_CLEAR_FAULTS); + net_buf_simple_add_u8(buf, BTP_MESH_LPN); + net_buf_simple_add_u8(buf, BTP_MESH_LPN_POLL); + net_buf_simple_add_u8(buf, BTP_MESH_MODEL_SEND); #if defined(CONFIG_BT_TESTING) - net_buf_simple_add_u8(buf, MESH_LPN_SUBSCRIBE); - net_buf_simple_add_u8(buf, MESH_LPN_UNSUBSCRIBE); - net_buf_simple_add_u8(buf, MESH_RPL_CLEAR); + net_buf_simple_add_u8(buf, BTP_MESH_LPN_SUBSCRIBE); + net_buf_simple_add_u8(buf, BTP_MESH_LPN_UNSUBSCRIBE); + net_buf_simple_add_u8(buf, BTP_MESH_RPL_CLEAR); #endif /* CONFIG_BT_TESTING */ - net_buf_simple_add_u8(buf, MESH_PROXY_IDENTITY); - net_buf_simple_add_u8(buf, MESH_COMP_DATA_GET); - net_buf_simple_add_u8(buf, MESH_CFG_BEACON_GET); - net_buf_simple_add_u8(buf, MESH_CFG_BEACON_SET); - net_buf_simple_add_u8(buf, MESH_CFG_DEFAULT_TTL_GET); - net_buf_simple_add_u8(buf, MESH_CFG_DEFAULT_TTL_SET); - net_buf_simple_add_u8(buf, MESH_CFG_GATT_PROXY_GET); - net_buf_simple_add_u8(buf, MESH_CFG_GATT_PROXY_SET); - net_buf_simple_add_u8(buf, MESH_CFG_FRIEND_GET); - net_buf_simple_add_u8(buf, MESH_CFG_FRIEND_SET); - net_buf_simple_add_u8(buf, MESH_CFG_RELAY_GET); - net_buf_simple_add_u8(buf, MESH_CFG_RELAY_SET); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_PUB_GET); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_PUB_SET); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_SUB_ADD); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_SUB_DEL); - net_buf_simple_add_u8(buf, MESH_CFG_NETKEY_ADD); - net_buf_simple_add_u8(buf, MESH_CFG_NETKEY_GET); - net_buf_simple_add_u8(buf, MESH_CFG_NETKEY_DEL); - net_buf_simple_add_u8(buf, MESH_CFG_APPKEY_ADD); - net_buf_simple_add_u8(buf, MESH_CFG_APPKEY_DEL); - net_buf_simple_add_u8(buf, MESH_CFG_APPKEY_GET); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_APP_BIND); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_APP_UNBIND); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_APP_GET); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_APP_VND_GET); - net_buf_simple_add_u8(buf, MESH_CFG_HEARTBEAT_PUB_SET); - net_buf_simple_add_u8(buf, MESH_CFG_HEARTBEAT_PUB_GET); - net_buf_simple_add_u8(buf, MESH_CFG_HEARTBEAT_SUB_SET); - net_buf_simple_add_u8(buf, MESH_CFG_HEARTBEAT_SUB_GET); - net_buf_simple_add_u8(buf, MESH_CFG_NET_TRANS_GET); - net_buf_simple_add_u8(buf, MESH_CFG_NET_TRANS_SET); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_SUB_OVW); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_SUB_DEL_ALL); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_SUB_GET); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_SUB_GET_VND); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_SUB_VA_ADD); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_SUB_VA_DEL); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_SUB_VA_OVW); - net_buf_simple_add_u8(buf, MESH_CFG_NETKEY_UPDATE); - net_buf_simple_add_u8(buf, MESH_CFG_APPKEY_UPDATE); - net_buf_simple_add_u8(buf, MESH_CFG_NODE_IDT_SET); - net_buf_simple_add_u8(buf, MESH_CFG_NODE_IDT_GET); - net_buf_simple_add_u8(buf, MESH_CFG_NODE_RESET); - net_buf_simple_add_u8(buf, MESH_CFG_LPN_TIMEOUT_GET); - net_buf_simple_add_u8(buf, MESH_CFG_MODEL_APP_BIND_VND); - net_buf_simple_add_u8(buf, MESH_HEALTH_FAULT_GET); - net_buf_simple_add_u8(buf, MESH_HEALTH_FAULT_CLEAR); - net_buf_simple_add_u8(buf, MESH_HEALTH_PERIOD_GET); - net_buf_simple_add_u8(buf, MESH_HEALTH_PERIOD_SET); - net_buf_simple_add_u8(buf, MESH_HEALTH_ATTENTION_GET); - net_buf_simple_add_u8(buf, MESH_HEALTH_ATTENTION_SET); - net_buf_simple_add_u8(buf, MESH_PROVISION_ADV); - net_buf_simple_add_u8(buf, MESH_CFG_KRP_GET); - net_buf_simple_add_u8(buf, MESH_CFG_KRP_SET); - - tester_send(BTP_SERVICE_ID_MESH, MESH_READ_SUPPORTED_COMMANDS, + net_buf_simple_add_u8(buf, BTP_MESH_PROXY_IDENTITY); + net_buf_simple_add_u8(buf, BTP_MESH_COMP_DATA_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_BEACON_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_BEACON_SET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_DEFAULT_TTL_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_DEFAULT_TTL_SET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_GATT_PROXY_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_GATT_PROXY_SET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_FRIEND_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_FRIEND_SET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_RELAY_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_RELAY_SET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_PUB_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_PUB_SET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_ADD); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_DEL); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_NETKEY_ADD); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_NETKEY_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_NETKEY_DEL); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_APPKEY_ADD); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_APPKEY_DEL); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_APPKEY_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_APP_BIND); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_APP_UNBIND); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_APP_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_APP_VND_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_HEARTBEAT_PUB_SET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_HEARTBEAT_PUB_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_HEARTBEAT_SUB_SET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_HEARTBEAT_SUB_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_NET_TRANS_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_NET_TRANS_SET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_OVW); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_DEL_ALL); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_GET_VND); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_VA_ADD); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_VA_DEL); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_VA_OVW); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_NETKEY_UPDATE); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_APPKEY_UPDATE); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_NODE_IDT_SET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_NODE_IDT_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_NODE_RESET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_LPN_TIMEOUT_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_APP_BIND_VND); + net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_FAULT_GET); + net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_FAULT_CLEAR); + net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_PERIOD_GET); + net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_PERIOD_SET); + net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_ATTENTION_GET); + net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_ATTENTION_SET); + net_buf_simple_add_u8(buf, BTP_MESH_PROVISION_ADV); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_KRP_GET); + net_buf_simple_add_u8(buf, BTP_MESH_CFG_KRP_SET); + + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_READ_SUPPORTED_COMMANDS, CONTROLLER_INDEX, buf->data, buf->len); } @@ -288,16 +288,16 @@ static struct bt_mesh_elem elements[] = { static void link_open(bt_mesh_prov_bearer_t bearer) { - struct mesh_prov_link_open_ev ev; + struct btp_mesh_prov_link_open_ev ev; LOG_DBG("bearer 0x%02x", bearer); switch (bearer) { case BT_MESH_PROV_ADV: - ev.bearer = MESH_PROV_BEARER_PB_ADV; + ev.bearer = BTP_MESH_PROV_BEARER_PB_ADV; break; case BT_MESH_PROV_GATT: - ev.bearer = MESH_PROV_BEARER_PB_GATT; + ev.bearer = BTP_MESH_PROV_BEARER_PB_GATT; break; default: LOG_ERR("Invalid bearer"); @@ -305,22 +305,22 @@ static void link_open(bt_mesh_prov_bearer_t bearer) return; } - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_PROV_LINK_OPEN, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROV_LINK_OPEN, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } static void link_close(bt_mesh_prov_bearer_t bearer) { - struct mesh_prov_link_closed_ev ev; + struct btp_mesh_prov_link_closed_ev ev; LOG_DBG("bearer 0x%02x", bearer); switch (bearer) { case BT_MESH_PROV_ADV: - ev.bearer = MESH_PROV_BEARER_PB_ADV; + ev.bearer = BTP_MESH_PROV_BEARER_PB_ADV; break; case BT_MESH_PROV_GATT: - ev.bearer = MESH_PROV_BEARER_PB_GATT; + ev.bearer = BTP_MESH_PROV_BEARER_PB_GATT; break; default: LOG_ERR("Invalid bearer"); @@ -328,20 +328,20 @@ static void link_close(bt_mesh_prov_bearer_t bearer) return; } - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_PROV_LINK_CLOSED, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROV_LINK_CLOSED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } static int output_number(bt_mesh_output_action_t action, uint32_t number) { - struct mesh_out_number_action_ev ev; + struct btp_mesh_out_number_action_ev ev; LOG_DBG("action 0x%04x number 0x%08x", action, number); ev.action = sys_cpu_to_le16(action); ev.number = sys_cpu_to_le32(number); - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_OUT_NUMBER_ACTION, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_OUT_NUMBER_ACTION, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); return 0; @@ -349,7 +349,7 @@ static int output_number(bt_mesh_output_action_t action, uint32_t number) static int output_string(const char *str) { - struct mesh_out_string_action_ev *ev; + struct btp_mesh_out_string_action_ev *ev; struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE); LOG_DBG("str %s", str); @@ -361,7 +361,7 @@ static int output_string(const char *str) net_buf_simple_add_mem(buf, str, ev->string_len); - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_OUT_STRING_ACTION, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_OUT_STRING_ACTION, CONTROLLER_INDEX, buf->data, buf->len); return 0; @@ -369,7 +369,7 @@ static int output_string(const char *str) static int input(bt_mesh_input_action_t action, uint8_t size) { - struct mesh_in_action_ev ev; + struct btp_mesh_in_action_ev ev; LOG_DBG("action 0x%04x number 0x%02x", action, size); @@ -378,7 +378,7 @@ static int input(bt_mesh_input_action_t action, uint8_t size) ev.action = sys_cpu_to_le16(action); ev.size = size; - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_IN_ACTION, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_IN_ACTION, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); return 0; @@ -392,14 +392,14 @@ static void prov_complete(uint16_t net_idx, uint16_t addr) net.local = addr; net.dst = addr; - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_PROVISIONED, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROVISIONED, CONTROLLER_INDEX, NULL, 0); } static void prov_node_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr, uint8_t num_elem) { - struct mesh_prov_node_added_ev ev; + struct btp_mesh_prov_node_added_ev ev; LOG_DBG("net_idx 0x%04x addr 0x%04x num_elem %d", net_idx, addr, num_elem); @@ -409,7 +409,7 @@ static void prov_node_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr, ev.num_elems = num_elem; memcpy(&ev.uuid, uuid, sizeof(ev.uuid)); - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_PROV_NODE_ADDED, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROV_NODE_ADDED, CONTROLLER_INDEX, (void *)&ev, sizeof(ev)); } @@ -442,7 +442,7 @@ static struct bt_mesh_prov prov = { static void config_prov(uint8_t *data, uint16_t len) { - const struct mesh_config_provisioning_cmd *cmd = (void *) data; + const struct btp_mesh_config_provisioning_cmd *cmd = (void *) data; int err = 0; LOG_DBG(""); @@ -474,13 +474,13 @@ static void config_prov(uint8_t *data, uint16_t len) LOG_ERR("err %d", err); } - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CONFIG_PROVISIONING, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CONFIG_PROVISIONING, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } static void provision_node(uint8_t *data, uint16_t len) { - const struct mesh_provision_node_cmd *cmd = (void *)data; + const struct btp_mesh_provision_node_cmd *cmd = (void *)data; int err; LOG_DBG(""); @@ -517,13 +517,13 @@ static void provision_node(uint8_t *data, uint16_t len) } fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_PROVISION_NODE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_PROVISION_NODE, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } static void provision_adv(uint8_t *data, uint16_t len) { - const struct mesh_provision_adv_cmd *cmd = (void *)data; + const struct btp_mesh_provision_adv_cmd *cmd = (void *)data; int err; LOG_DBG(""); @@ -536,7 +536,7 @@ static void provision_adv(uint8_t *data, uint16_t len) } fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_PROVISION_ADV, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_PROVISION_ADV, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } @@ -568,7 +568,7 @@ static void init(uint8_t *data, uint16_t len) } rsp: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_INIT, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_INIT, CONTROLLER_INDEX, status); } @@ -578,13 +578,13 @@ static void reset(uint8_t *data, uint16_t len) bt_mesh_reset(); - tester_rsp(BTP_SERVICE_ID_MESH, MESH_RESET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_RESET, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } static void input_number(uint8_t *data, uint16_t len) { - const struct mesh_input_number_cmd *cmd = (void *) data; + const struct btp_mesh_input_number_cmd *cmd = (void *) data; uint8_t status = BTP_STATUS_SUCCESS; uint32_t number; int err; @@ -598,13 +598,13 @@ static void input_number(uint8_t *data, uint16_t len) status = BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_MESH, MESH_INPUT_NUMBER, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_INPUT_NUMBER, CONTROLLER_INDEX, status); } static void input_string(uint8_t *data, uint16_t len) { - const struct mesh_input_string_cmd *cmd = (void *) data; + const struct btp_mesh_input_string_cmd *cmd = (void *) data; uint8_t status = BTP_STATUS_SUCCESS; uint8_t str_auth[16]; int err; @@ -629,19 +629,19 @@ static void input_string(uint8_t *data, uint16_t len) } rsp: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_INPUT_STRING, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_INPUT_STRING, CONTROLLER_INDEX, status); } static void ivu_test_mode(uint8_t *data, uint16_t len) { - const struct mesh_ivu_test_mode_cmd *cmd = (void *) data; + const struct btp_mesh_ivu_test_mode_cmd *cmd = (void *) data; LOG_DBG("enable 0x%02x", cmd->enable); bt_mesh_iv_update_test(cmd->enable ? true : false); - tester_rsp(BTP_SERVICE_ID_MESH, MESH_IVU_TEST_MODE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_IVU_TEST_MODE, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } @@ -656,13 +656,13 @@ static void ivu_toggle_state(uint8_t *data, uint16_t len) LOG_ERR("Failed to toggle the IV Update state"); } - tester_rsp(BTP_SERVICE_ID_MESH, MESH_IVU_TOGGLE_STATE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_IVU_TOGGLE_STATE, CONTROLLER_INDEX, result ? BTP_STATUS_SUCCESS : BTP_STATUS_FAILED); } static void lpn(uint8_t *data, uint16_t len) { - struct mesh_lpn_set_cmd *cmd = (void *) data; + struct btp_mesh_lpn_set_cmd *cmd = (void *) data; bool enable; int err; @@ -674,7 +674,7 @@ static void lpn(uint8_t *data, uint16_t len) LOG_ERR("Failed to toggle LPN (err %d)", err); } - tester_rsp(BTP_SERVICE_ID_MESH, MESH_LPN, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_LPN, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } @@ -689,13 +689,13 @@ static void lpn_poll(uint8_t *data, uint16_t len) LOG_ERR("Failed to send poll msg (err %d)", err); } - tester_rsp(BTP_SERVICE_ID_MESH, MESH_LPN_POLL, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_LPN_POLL, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } static void net_send(uint8_t *data, uint16_t len) { - struct mesh_net_send_cmd *cmd = (void *) data; + struct btp_mesh_net_send_cmd *cmd = (void *) data; NET_BUF_SIMPLE_DEFINE(msg, UINT8_MAX); struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, @@ -721,13 +721,13 @@ static void net_send(uint8_t *data, uint16_t len) LOG_ERR("Failed to send (err %d)", err); } - tester_rsp(BTP_SERVICE_ID_MESH, MESH_NET_SEND, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_NET_SEND, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } static void health_generate_faults(uint8_t *data, uint16_t len) { - struct mesh_health_generate_faults_rp *rp; + struct btp_mesh_health_generate_faults_rp *rp; NET_BUF_SIMPLE_DEFINE(buf, sizeof(*rp) + sizeof(cur_faults) + sizeof(reg_faults)); uint8_t some_faults[] = { 0x01, 0x02, 0x03, 0xff, 0x06 }; @@ -747,7 +747,7 @@ static void health_generate_faults(uint8_t *data, uint16_t len) bt_mesh_health_srv_fault_update(&elements[0]); - tester_send(BTP_SERVICE_ID_MESH, MESH_HEALTH_GENERATE_FAULTS, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_GENERATE_FAULTS, CONTROLLER_INDEX, buf.data, buf.len); } @@ -760,13 +760,13 @@ static void health_clear_faults(uint8_t *data, uint16_t len) bt_mesh_health_srv_fault_update(&elements[0]); - tester_rsp(BTP_SERVICE_ID_MESH, MESH_HEALTH_CLEAR_FAULTS, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_CLEAR_FAULTS, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } static void model_send(uint8_t *data, uint16_t len) { - struct mesh_model_send_cmd *cmd = (void *) data; + struct btp_mesh_model_send_cmd *cmd = (void *) data; NET_BUF_SIMPLE_DEFINE(msg, UINT8_MAX); struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, @@ -806,14 +806,14 @@ static void model_send(uint8_t *data, uint16_t len) } fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_MODEL_SEND, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_MODEL_SEND, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } #if defined(CONFIG_BT_TESTING) static void lpn_subscribe(uint8_t *data, uint16_t len) { - struct mesh_lpn_subscribe_cmd *cmd = (void *) data; + struct btp_mesh_lpn_subscribe_cmd *cmd = (void *) data; uint16_t address = sys_le16_to_cpu(cmd->address); int err; @@ -824,13 +824,13 @@ static void lpn_subscribe(uint8_t *data, uint16_t len) LOG_ERR("Failed to subscribe (err %d)", err); } - tester_rsp(BTP_SERVICE_ID_MESH, MESH_LPN_SUBSCRIBE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_LPN_SUBSCRIBE, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } static void lpn_unsubscribe(uint8_t *data, uint16_t len) { - struct mesh_lpn_unsubscribe_cmd *cmd = (void *) data; + struct btp_mesh_lpn_unsubscribe_cmd *cmd = (void *) data; uint16_t address = sys_le16_to_cpu(cmd->address); int err; @@ -841,7 +841,7 @@ static void lpn_unsubscribe(uint8_t *data, uint16_t len) LOG_ERR("Failed to unsubscribe (err %d)", err); } - tester_rsp(BTP_SERVICE_ID_MESH, MESH_LPN_UNSUBSCRIBE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_LPN_UNSUBSCRIBE, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } @@ -856,7 +856,7 @@ static void rpl_clear(uint8_t *data, uint16_t len) LOG_ERR("Failed to clear RPL (err %d)", err); } - tester_rsp(BTP_SERVICE_ID_MESH, MESH_RPL_CLEAR, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_RPL_CLEAR, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } #endif /* CONFIG_BT_TESTING */ @@ -872,13 +872,13 @@ static void proxy_identity_enable(uint8_t *data, uint16_t len) LOG_ERR("Failed to enable proxy identity (err %d)", err); } - tester_rsp(BTP_SERVICE_ID_MESH, MESH_PROXY_IDENTITY, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_PROXY_IDENTITY, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } static void composition_data_get(uint8_t *data, uint16_t len) { - struct mesh_comp_data_get_cmd *cmd = (void *)data; + struct btp_mesh_comp_data_get_cmd *cmd = (void *)data; uint8_t page; struct net_buf_simple *comp = NET_BUF_SIMPLE(128); int err; @@ -896,17 +896,17 @@ static void composition_data_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_COMP_DATA_GET, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_COMP_DATA_GET, CONTROLLER_INDEX, comp->data, comp->len); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_COMP_DATA_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_COMP_DATA_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_krp_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_krp_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_krp_get_cmd *cmd = (void *)data; struct net_buf_simple *buf = NET_BUF_SIMPLE(2); uint8_t status; uint8_t phase; @@ -926,16 +926,16 @@ static void config_krp_get(uint8_t *data, uint16_t len) net_buf_simple_add_u8(buf, status); net_buf_simple_add_u8(buf, phase); - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_KRP_GET, CONTROLLER_INDEX, buf->data, buf->len); + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_KRP_GET, CONTROLLER_INDEX, buf->data, buf->len); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_KRP_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_KRP_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_krp_set(uint8_t *data, uint16_t len) { - struct mesh_cfg_krp_set_cmd *cmd = (void *)data; + struct btp_mesh_cfg_krp_set_cmd *cmd = (void *)data; struct net_buf_simple *buf = NET_BUF_SIMPLE(2); uint8_t status; uint8_t phase; @@ -954,16 +954,16 @@ static void config_krp_set(uint8_t *data, uint16_t len) net_buf_simple_add_u8(buf, status); net_buf_simple_add_u8(buf, phase); - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_KRP_SET, CONTROLLER_INDEX, buf->data, buf->len); + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_KRP_SET, CONTROLLER_INDEX, buf->data, buf->len); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_KRP_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_KRP_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_beacon_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_val_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; uint8_t status; int err; @@ -975,17 +975,17 @@ static void config_beacon_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_BEACON_GET, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_BEACON_GET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_BEACON_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_BEACON_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_beacon_set(uint8_t *data, uint16_t len) { - struct mesh_cfg_beacon_set_cmd *cmd = (void *)data; + struct btp_mesh_cfg_beacon_set_cmd *cmd = (void *)data; uint8_t status; int err; @@ -998,17 +998,17 @@ static void config_beacon_set(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_BEACON_SET, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_BEACON_SET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_BEACON_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_BEACON_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_default_ttl_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_val_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1020,18 +1020,18 @@ static void config_default_ttl_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_DEFAULT_TTL_GET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_DEFAULT_TTL_GET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_DEFAULT_TTL_GET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_DEFAULT_TTL_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_default_ttl_set(uint8_t *data, uint16_t len) { - struct mesh_cfg_default_ttl_set_cmd *cmd = (void *)data; + struct btp_mesh_cfg_default_ttl_set_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1044,18 +1044,18 @@ static void config_default_ttl_set(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_DEFAULT_TTL_SET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_DEFAULT_TTL_SET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_DEFAULT_TTL_SET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_DEFAULT_TTL_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_gatt_proxy_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_val_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1067,18 +1067,18 @@ static void config_gatt_proxy_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_GATT_PROXY_GET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_GATT_PROXY_GET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_GATT_PROXY_GET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_GATT_PROXY_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_gatt_proxy_set(uint8_t *data, uint16_t len) { - struct mesh_cfg_gatt_proxy_set_cmd *cmd = (void *)data; + struct btp_mesh_cfg_gatt_proxy_set_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1091,18 +1091,18 @@ static void config_gatt_proxy_set(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_GATT_PROXY_SET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_GATT_PROXY_SET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_GATT_PROXY_SET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_GATT_PROXY_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_friend_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_val_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1114,17 +1114,17 @@ static void config_friend_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_FRIEND_GET, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_FRIEND_GET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_FRIEND_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_FRIEND_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_friend_set(uint8_t *data, uint16_t len) { - struct mesh_cfg_friend_set_cmd *cmd = (void *)data; + struct btp_mesh_cfg_friend_set_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1137,17 +1137,17 @@ static void config_friend_set(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_FRIEND_SET, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_FRIEND_SET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_FRIEND_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_FRIEND_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_relay_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_val_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; uint8_t status; uint8_t transmit; int err; @@ -1161,17 +1161,17 @@ static void config_relay_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_RELAY_GET, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_RELAY_GET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_RELAY_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_RELAY_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_relay_set(uint8_t *data, uint16_t len) { - struct mesh_cfg_relay_set_cmd *cmd = (void *)data; + struct btp_mesh_cfg_relay_set_cmd *cmd = (void *)data; uint8_t status; uint8_t transmit; int err; @@ -1185,17 +1185,17 @@ static void config_relay_set(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_RELAY_SET, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_RELAY_SET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_RELAY_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_RELAY_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_mod_pub_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_pub_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_pub_get_cmd *cmd = (void *)data; struct bt_mesh_cfg_cli_mod_pub pub; uint8_t status; int err; @@ -1210,18 +1210,18 @@ static void config_mod_pub_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_PUB_GET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_PUB_GET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_PUB_GET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_PUB_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_mod_pub_set(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_pub_set_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_pub_set_cmd *cmd = (void *)data; uint8_t status; struct bt_mesh_cfg_cli_mod_pub pub; int err; @@ -1245,18 +1245,18 @@ static void config_mod_pub_set(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_PUB_SET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_PUB_SET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_PUB_SET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_PUB_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_mod_pub_va_set(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_pub_va_set_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_pub_va_set_cmd *cmd = (void *)data; uint8_t status; struct bt_mesh_cfg_cli_mod_pub pub; int err; @@ -1279,18 +1279,18 @@ static void config_mod_pub_va_set(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_PUB_VA_SET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_PUB_VA_SET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_PUB_VA_SET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_PUB_VA_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_mod_sub_add(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_sub_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_sub_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1305,18 +1305,18 @@ static void config_mod_sub_add(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_ADD, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_ADD, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_ADD, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_ADD, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_mod_sub_ovw(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_sub_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_sub_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1331,18 +1331,18 @@ static void config_mod_sub_ovw(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_OVW, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_OVW, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_OVW, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_OVW, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_mod_sub_del(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_sub_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_sub_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1357,18 +1357,18 @@ static void config_mod_sub_del(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_DEL, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_DEL, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_DEL, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_DEL, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_mod_sub_del_all(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_sub_del_all_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_sub_del_all_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1383,18 +1383,18 @@ static void config_mod_sub_del_all(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_DEL_ALL, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_DEL_ALL, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_DEL_ALL, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_DEL_ALL, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_mod_sub_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_sub_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_sub_get_cmd *cmd = (void *)data; uint8_t status; int16_t subs; size_t sub_cn; @@ -1411,18 +1411,18 @@ static void config_mod_sub_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_GET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_GET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_GET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_mod_sub_get_vnd(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_sub_get_vnd_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_sub_get_vnd_cmd *cmd = (void *)data; uint8_t status; uint16_t subs; size_t sub_cn; @@ -1439,18 +1439,18 @@ static void config_mod_sub_get_vnd(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_GET_VND, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_GET_VND, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_GET_VND, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_GET_VND, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_mod_sub_va_add(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_sub_va_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_sub_va_cmd *cmd = (void *)data; uint8_t status; uint16_t virt_addr_rcv; int err; @@ -1467,18 +1467,18 @@ static void config_mod_sub_va_add(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_VA_ADD, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_VA_ADD, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_VA_ADD, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_VA_ADD, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_mod_sub_va_del(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_sub_va_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_sub_va_cmd *cmd = (void *)data; uint8_t status; uint16_t virt_addr_rcv; int err; @@ -1495,18 +1495,18 @@ static void config_mod_sub_va_del(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_VA_DEL, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_VA_DEL, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_VA_DEL, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_VA_DEL, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_mod_sub_va_ovw(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_sub_va_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_sub_va_cmd *cmd = (void *)data; uint8_t status; uint16_t virt_addr_rcv; int err; @@ -1523,18 +1523,18 @@ static void config_mod_sub_va_ovw(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_VA_OVW, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_VA_OVW, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_SUB_VA_OVW, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_VA_OVW, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_netkey_add(uint8_t *data, uint16_t len) { - struct mesh_cfg_netkey_add_cmd *cmd = (void *)data; + struct btp_mesh_cfg_netkey_add_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1548,17 +1548,17 @@ static void config_netkey_add(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_NETKEY_ADD, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_ADD, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_NETKEY_ADD, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_ADD, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_netkey_update(uint8_t *data, uint16_t len) { - struct mesh_cfg_netkey_add_cmd *cmd = (void *)data; + struct btp_mesh_cfg_netkey_add_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1573,18 +1573,18 @@ static void config_netkey_update(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_NETKEY_UPDATE, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_UPDATE, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_NETKEY_UPDATE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_UPDATE, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_netkey_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_val_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; uint16_t keys; size_t key_cnt; int err; @@ -1599,17 +1599,17 @@ static void config_netkey_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_NETKEY_GET, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_GET, CONTROLLER_INDEX, (uint8_t *)&keys, key_cnt); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_NETKEY_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_netkey_del(uint8_t *data, uint16_t len) { - struct mesh_cfg_netkey_del_cmd *cmd = (void *)data; + struct btp_mesh_cfg_netkey_del_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1623,17 +1623,17 @@ static void config_netkey_del(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_NETKEY_DEL, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_DEL, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_NETKEY_DEL, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_DEL, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_appkey_add(uint8_t *data, uint16_t len) { - struct mesh_cfg_appkey_add_cmd *cmd = (void *)data; + struct btp_mesh_cfg_appkey_add_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1648,17 +1648,17 @@ static void config_appkey_add(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_APPKEY_ADD, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_ADD, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_APPKEY_ADD, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_ADD, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_appkey_update(uint8_t *data, uint16_t len) { - struct mesh_cfg_appkey_add_cmd *cmd = (void *)data; + struct btp_mesh_cfg_appkey_add_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1673,18 +1673,18 @@ static void config_appkey_update(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_APPKEY_UPDATE, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_UPDATE, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_APPKEY_UPDATE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_UPDATE, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_appkey_del(uint8_t *data, uint16_t len) { - struct mesh_cfg_appkey_del_cmd *cmd = (void *)data; + struct btp_mesh_cfg_appkey_del_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1699,17 +1699,17 @@ static void config_appkey_del(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_APPKEY_DEL, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_DEL, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_APPKEY_DEL, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_DEL, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_appkey_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_appkey_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_appkey_get_cmd *cmd = (void *)data; uint8_t status; uint16_t keys; size_t key_cnt; @@ -1726,17 +1726,17 @@ static void config_appkey_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_APPKEY_GET, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_GET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_APPKEY_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_model_app_bind(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_app_bind_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_app_bind_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1751,18 +1751,18 @@ static void config_model_app_bind(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_APP_BIND, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_BIND, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_APP_BIND, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_BIND, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_model_app_bind_vnd(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_app_bind_vnd_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_app_bind_vnd_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1777,18 +1777,18 @@ static void config_model_app_bind_vnd(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_APP_BIND_VND, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_BIND_VND, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_APP_BIND_VND, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_BIND_VND, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_model_app_unbind(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_app_bind_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_app_bind_cmd *cmd = (void *)data; uint8_t status; int err; @@ -1803,18 +1803,18 @@ static void config_model_app_unbind(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_APP_UNBIND, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_UNBIND, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_APP_UNBIND, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_UNBIND, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_model_app_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_app_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_app_get_cmd *cmd = (void *)data; uint8_t status; uint16_t apps; size_t app_cnt; @@ -1831,18 +1831,18 @@ static void config_model_app_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_APP_GET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_GET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_APP_GET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_model_app_vnd_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_model_app_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_model_app_get_cmd *cmd = (void *)data; uint8_t status; uint16_t apps; size_t app_cnt; @@ -1859,18 +1859,18 @@ static void config_model_app_vnd_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_APP_VND_GET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_VND_GET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_MODEL_APP_VND_GET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_VND_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_hb_pub_set(uint8_t *data, uint16_t len) { - struct mesh_cfg_heartbeat_pub_set_cmd *cmd = (void *)data; + struct btp_mesh_cfg_heartbeat_pub_set_cmd *cmd = (void *)data; uint8_t status; struct bt_mesh_cfg_cli_hb_pub pub; int err; @@ -1891,18 +1891,18 @@ static void config_hb_pub_set(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_HEARTBEAT_PUB_SET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_PUB_SET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_HEARTBEAT_PUB_SET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_PUB_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_hb_pub_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_val_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; uint8_t status; struct bt_mesh_cfg_cli_hb_pub pub; int err; @@ -1916,18 +1916,18 @@ static void config_hb_pub_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_HEARTBEAT_PUB_GET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_PUB_GET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_HEARTBEAT_PUB_GET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_PUB_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_hb_sub_set(uint8_t *data, uint16_t len) { - struct mesh_cfg_heartbeat_sub_set_cmd *cmd = (void *)data; + struct btp_mesh_cfg_heartbeat_sub_set_cmd *cmd = (void *)data; uint8_t status; struct bt_mesh_cfg_cli_hb_sub sub; int err; @@ -1945,18 +1945,18 @@ static void config_hb_sub_set(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_HEARTBEAT_SUB_SET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_SUB_SET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_HEARTBEAT_SUB_SET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_SUB_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_hb_sub_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_val_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; uint8_t status; struct bt_mesh_cfg_cli_hb_sub sub; int err; @@ -1970,18 +1970,18 @@ static void config_hb_sub_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_HEARTBEAT_SUB_GET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_SUB_GET, CONTROLLER_INDEX, &status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_HEARTBEAT_SUB_GET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_SUB_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_net_trans_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_val_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; uint8_t transmit; int err; @@ -1995,18 +1995,18 @@ static void config_net_trans_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_NET_TRANS_GET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NET_TRANS_GET, CONTROLLER_INDEX, &transmit, sizeof(transmit)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_NET_TRANS_GET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NET_TRANS_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_net_trans_set(uint8_t *data, uint16_t len) { - struct mesh_cfg_net_trans_set_cmd *cmd = (void *)data; + struct btp_mesh_cfg_net_trans_set_cmd *cmd = (void *)data; uint8_t transmit; int err; @@ -2020,18 +2020,18 @@ static void config_net_trans_set(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_NET_TRANS_SET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NET_TRANS_SET, CONTROLLER_INDEX, &transmit, sizeof(transmit)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_NET_TRANS_SET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NET_TRANS_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_node_identity_set(uint8_t *data, uint16_t len) { - struct mesh_cfg_node_idt_set_cmd *cmd = (void *)data; + struct btp_mesh_cfg_node_idt_set_cmd *cmd = (void *)data; struct net_buf_simple *buf = NET_BUF_SIMPLE(2); uint8_t identity; uint8_t status; @@ -2052,17 +2052,17 @@ static void config_node_identity_set(uint8_t *data, uint16_t len) net_buf_simple_add_u8(buf, status); net_buf_simple_add_u8(buf, identity); - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_NODE_IDT_SET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NODE_IDT_SET, CONTROLLER_INDEX, buf->data, buf->len); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_NODE_IDT_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NODE_IDT_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_node_identity_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_node_idt_get_cmd *cmd = (void *)data; + struct btp_mesh_cfg_node_idt_get_cmd *cmd = (void *)data; struct net_buf_simple *buf = NET_BUF_SIMPLE(2); uint8_t identity; uint8_t status; @@ -2083,17 +2083,17 @@ static void config_node_identity_get(uint8_t *data, uint16_t len) net_buf_simple_add_u8(buf, status); net_buf_simple_add_u8(buf, identity); - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_NODE_IDT_GET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NODE_IDT_GET, CONTROLLER_INDEX, buf->data, buf->len); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_NODE_IDT_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NODE_IDT_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_node_reset(uint8_t *data, uint16_t len) { - struct mesh_cfg_node_reset_cmd *cmd = (void *)data; + struct btp_mesh_cfg_node_reset_cmd *cmd = (void *)data; bool status; int err; @@ -2106,17 +2106,17 @@ static void config_node_reset(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_NODE_RESET, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NODE_RESET, CONTROLLER_INDEX, (uint8_t *)&status, sizeof(status)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_NODE_RESET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NODE_RESET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void config_lpn_timeout_get(uint8_t *data, uint16_t len) { - struct mesh_cfg_lpn_timeout_cmd *cmd = (void *)data; + struct btp_mesh_cfg_lpn_timeout_cmd *cmd = (void *)data; int32_t polltimeout; int err; @@ -2130,19 +2130,19 @@ static void config_lpn_timeout_get(uint8_t *data, uint16_t len) goto fail; } - tester_send(BTP_SERVICE_ID_MESH, MESH_CFG_LPN_TIMEOUT_GET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_LPN_TIMEOUT_GET, CONTROLLER_INDEX, (uint8_t *)&polltimeout, sizeof(polltimeout)); return; fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_CFG_LPN_TIMEOUT_GET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_LPN_TIMEOUT_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); } static void health_fault_get(uint8_t *data, uint16_t len) { - struct mesh_health_fault_get_cmd *cmd = (void *)data; + struct btp_mesh_health_fault_get_cmd *cmd = (void *)data; struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, .addr = cmd->address, @@ -2164,13 +2164,13 @@ static void health_fault_get(uint8_t *data, uint16_t len) } fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_HEALTH_FAULT_GET, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_FAULT_GET, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } static void health_fault_clear(uint8_t *data, uint16_t len) { - struct mesh_health_fault_clear_cmd *cmd = (void *)data; + struct btp_mesh_health_fault_clear_cmd *cmd = (void *)data; struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, .addr = cmd->address, @@ -2196,20 +2196,20 @@ static void health_fault_clear(uint8_t *data, uint16_t len) } if (cmd->ack) { - tester_send(BTP_SERVICE_ID_MESH, MESH_HEALTH_FAULT_CLEAR, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_FAULT_CLEAR, CONTROLLER_INDEX, &test_id, sizeof(test_id)); return; } fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_HEALTH_FAULT_CLEAR, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_FAULT_CLEAR, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } static void health_fault_test(uint8_t *data, uint16_t len) { - struct mesh_health_fault_test_cmd *cmd = (void *)data; + struct btp_mesh_health_fault_test_cmd *cmd = (void *)data; struct net_buf_simple *buf = NET_BUF_SIMPLE(19); struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, @@ -2245,20 +2245,20 @@ static void health_fault_test(uint8_t *data, uint16_t len) net_buf_simple_add_le16(buf, cid); net_buf_simple_add_mem(buf, faults, fault_count); - tester_send(BTP_SERVICE_ID_MESH, MESH_HEALTH_FAULT_TEST, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_FAULT_TEST, CONTROLLER_INDEX, buf->data, buf->len); return; } fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_HEALTH_FAULT_TEST, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_FAULT_TEST, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } static void health_period_get(uint8_t *data, uint16_t len) { - struct mesh_health_period_get_cmd *cmd = (void *)data; + struct btp_mesh_health_period_get_cmd *cmd = (void *)data; struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, .addr = cmd->address, @@ -2277,14 +2277,14 @@ static void health_period_get(uint8_t *data, uint16_t len) } fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_HEALTH_PERIOD_GET, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_PERIOD_GET, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } static void health_period_set(uint8_t *data, uint16_t len) { - struct mesh_health_period_set_cmd *cmd = (void *)data; + struct btp_mesh_health_period_set_cmd *cmd = (void *)data; struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, .addr = cmd->address, @@ -2308,21 +2308,21 @@ static void health_period_set(uint8_t *data, uint16_t len) } if (cmd->ack) { - tester_send(BTP_SERVICE_ID_MESH, MESH_HEALTH_PERIOD_SET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_PERIOD_SET, CONTROLLER_INDEX, &updated_divisor, sizeof(updated_divisor)); return; } fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_HEALTH_PERIOD_SET, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_PERIOD_SET, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } static void health_attention_get(uint8_t *data, uint16_t len) { - struct mesh_health_attention_get_cmd *cmd = (void *)data; + struct btp_mesh_health_attention_get_cmd *cmd = (void *)data; struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, .addr = cmd->address, @@ -2341,14 +2341,14 @@ static void health_attention_get(uint8_t *data, uint16_t len) } fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_HEALTH_ATTENTION_GET, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_ATTENTION_GET, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } static void health_attention_set(uint8_t *data, uint16_t len) { - struct mesh_health_attention_set_cmd *cmd = (void *)data; + struct btp_mesh_health_attention_set_cmd *cmd = (void *)data; struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, .addr = cmd->address, @@ -2372,14 +2372,14 @@ static void health_attention_set(uint8_t *data, uint16_t len) } if (cmd->ack) { - tester_send(BTP_SERVICE_ID_MESH, MESH_HEALTH_ATTENTION_SET, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_ATTENTION_SET, CONTROLLER_INDEX, &updated_attention, sizeof(updated_attention)); return; } fail: - tester_rsp(BTP_SERVICE_ID_MESH, MESH_HEALTH_ATTENTION_SET, + tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_ATTENTION_SET, CONTROLLER_INDEX, err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); } @@ -2387,231 +2387,231 @@ static void health_attention_set(uint8_t *data, uint16_t len) void tester_handle_mesh(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len) { switch (opcode) { - case MESH_READ_SUPPORTED_COMMANDS: + case BTP_MESH_READ_SUPPORTED_COMMANDS: supported_commands(data, len); break; - case MESH_CONFIG_PROVISIONING: + case BTP_MESH_CONFIG_PROVISIONING: config_prov(data, len); break; - case MESH_PROVISION_NODE: + case BTP_MESH_PROVISION_NODE: provision_node(data, len); break; - case MESH_INIT: + case BTP_MESH_INIT: init(data, len); break; - case MESH_RESET: + case BTP_MESH_RESET: reset(data, len); break; - case MESH_INPUT_NUMBER: + case BTP_MESH_INPUT_NUMBER: input_number(data, len); break; - case MESH_INPUT_STRING: + case BTP_MESH_INPUT_STRING: input_string(data, len); break; - case MESH_IVU_TEST_MODE: + case BTP_MESH_IVU_TEST_MODE: ivu_test_mode(data, len); break; - case MESH_IVU_TOGGLE_STATE: + case BTP_MESH_IVU_TOGGLE_STATE: ivu_toggle_state(data, len); break; - case MESH_LPN: + case BTP_MESH_LPN: lpn(data, len); break; - case MESH_LPN_POLL: + case BTP_MESH_LPN_POLL: lpn_poll(data, len); break; - case MESH_NET_SEND: + case BTP_MESH_NET_SEND: net_send(data, len); break; - case MESH_HEALTH_GENERATE_FAULTS: + case BTP_MESH_HEALTH_GENERATE_FAULTS: health_generate_faults(data, len); break; - case MESH_HEALTH_CLEAR_FAULTS: + case BTP_MESH_HEALTH_CLEAR_FAULTS: health_clear_faults(data, len); break; - case MESH_MODEL_SEND: + case BTP_MESH_MODEL_SEND: model_send(data, len); break; - case MESH_COMP_DATA_GET: + case BTP_MESH_COMP_DATA_GET: composition_data_get(data, len); break; - case MESH_CFG_BEACON_GET: + case BTP_MESH_CFG_BEACON_GET: config_beacon_get(data, len); break; - case MESH_CFG_BEACON_SET: + case BTP_MESH_CFG_BEACON_SET: config_beacon_set(data, len); break; - case MESH_CFG_DEFAULT_TTL_GET: + case BTP_MESH_CFG_DEFAULT_TTL_GET: config_default_ttl_get(data, len); break; - case MESH_CFG_DEFAULT_TTL_SET: + case BTP_MESH_CFG_DEFAULT_TTL_SET: config_default_ttl_set(data, len); break; - case MESH_CFG_GATT_PROXY_GET: + case BTP_MESH_CFG_GATT_PROXY_GET: config_gatt_proxy_get(data, len); break; - case MESH_CFG_GATT_PROXY_SET: + case BTP_MESH_CFG_GATT_PROXY_SET: config_gatt_proxy_set(data, len); break; - case MESH_CFG_FRIEND_GET: + case BTP_MESH_CFG_FRIEND_GET: config_friend_get(data, len); break; - case MESH_CFG_FRIEND_SET: + case BTP_MESH_CFG_FRIEND_SET: config_friend_set(data, len); break; - case MESH_CFG_RELAY_GET: + case BTP_MESH_CFG_RELAY_GET: config_relay_get(data, len); break; - case MESH_CFG_RELAY_SET: + case BTP_MESH_CFG_RELAY_SET: config_relay_set(data, len); break; - case MESH_CFG_MODEL_PUB_GET: + case BTP_MESH_CFG_MODEL_PUB_GET: config_mod_pub_get(data, len); break; - case MESH_CFG_MODEL_PUB_SET: + case BTP_MESH_CFG_MODEL_PUB_SET: config_mod_pub_set(data, len); break; - case MESH_CFG_MODEL_SUB_ADD: + case BTP_MESH_CFG_MODEL_SUB_ADD: config_mod_sub_add(data, len); break; - case MESH_CFG_MODEL_SUB_DEL: + case BTP_MESH_CFG_MODEL_SUB_DEL: config_mod_sub_del(data, len); break; - case MESH_CFG_MODEL_SUB_OVW: + case BTP_MESH_CFG_MODEL_SUB_OVW: config_mod_sub_ovw(data, len); break; - case MESH_CFG_MODEL_SUB_DEL_ALL: + case BTP_MESH_CFG_MODEL_SUB_DEL_ALL: config_mod_sub_del_all(data, len); break; - case MESH_CFG_MODEL_SUB_GET: + case BTP_MESH_CFG_MODEL_SUB_GET: config_mod_sub_get(data, len); break; - case MESH_CFG_MODEL_SUB_GET_VND: + case BTP_MESH_CFG_MODEL_SUB_GET_VND: config_mod_sub_get_vnd(data, len); break; - case MESH_CFG_MODEL_SUB_VA_ADD: + case BTP_MESH_CFG_MODEL_SUB_VA_ADD: config_mod_sub_va_add(data, len); break; - case MESH_CFG_MODEL_SUB_VA_DEL: + case BTP_MESH_CFG_MODEL_SUB_VA_DEL: config_mod_sub_va_del(data, len); break; - case MESH_CFG_MODEL_SUB_VA_OVW: + case BTP_MESH_CFG_MODEL_SUB_VA_OVW: config_mod_sub_va_ovw(data, len); break; - case MESH_CFG_NETKEY_ADD: + case BTP_MESH_CFG_NETKEY_ADD: config_netkey_add(data, len); break; - case MESH_CFG_NETKEY_GET: + case BTP_MESH_CFG_NETKEY_GET: config_netkey_get(data, len); break; - case MESH_CFG_NETKEY_DEL: + case BTP_MESH_CFG_NETKEY_DEL: config_netkey_del(data, len); break; - case MESH_CFG_NETKEY_UPDATE: + case BTP_MESH_CFG_NETKEY_UPDATE: config_netkey_update(data, len); break; - case MESH_CFG_APPKEY_ADD: + case BTP_MESH_CFG_APPKEY_ADD: config_appkey_add(data, len); break; - case MESH_CFG_APPKEY_DEL: + case BTP_MESH_CFG_APPKEY_DEL: config_appkey_del(data, len); break; - case MESH_CFG_APPKEY_GET: + case BTP_MESH_CFG_APPKEY_GET: config_appkey_get(data, len); break; - case MESH_CFG_APPKEY_UPDATE: + case BTP_MESH_CFG_APPKEY_UPDATE: config_appkey_update(data, len); break; - case MESH_CFG_MODEL_APP_BIND: + case BTP_MESH_CFG_MODEL_APP_BIND: config_model_app_bind(data, len); break; - case MESH_CFG_MODEL_APP_UNBIND: + case BTP_MESH_CFG_MODEL_APP_UNBIND: config_model_app_unbind(data, len); break; - case MESH_CFG_MODEL_APP_GET: + case BTP_MESH_CFG_MODEL_APP_GET: config_model_app_get(data, len); break; - case MESH_CFG_MODEL_APP_VND_GET: + case BTP_MESH_CFG_MODEL_APP_VND_GET: config_model_app_vnd_get(data, len); break; - case MESH_CFG_HEARTBEAT_PUB_SET: + case BTP_MESH_CFG_HEARTBEAT_PUB_SET: config_hb_pub_set(data, len); break; - case MESH_CFG_HEARTBEAT_PUB_GET: + case BTP_MESH_CFG_HEARTBEAT_PUB_GET: config_hb_pub_get(data, len); break; - case MESH_CFG_HEARTBEAT_SUB_SET: + case BTP_MESH_CFG_HEARTBEAT_SUB_SET: config_hb_sub_set(data, len); break; - case MESH_CFG_HEARTBEAT_SUB_GET: + case BTP_MESH_CFG_HEARTBEAT_SUB_GET: config_hb_sub_get(data, len); break; - case MESH_CFG_NET_TRANS_GET: + case BTP_MESH_CFG_NET_TRANS_GET: config_net_trans_get(data, len); break; - case MESH_CFG_NET_TRANS_SET: + case BTP_MESH_CFG_NET_TRANS_SET: config_net_trans_set(data, len); break; - case MESH_CFG_NODE_IDT_SET: + case BTP_MESH_CFG_NODE_IDT_SET: config_node_identity_set(data, len); break; - case MESH_CFG_NODE_IDT_GET: + case BTP_MESH_CFG_NODE_IDT_GET: config_node_identity_get(data, len); break; - case MESH_CFG_NODE_RESET: + case BTP_MESH_CFG_NODE_RESET: config_node_reset(data, len); break; - case MESH_CFG_LPN_TIMEOUT_GET: + case BTP_MESH_CFG_LPN_TIMEOUT_GET: config_lpn_timeout_get(data, len); break; - case MESH_CFG_MODEL_PUB_VA_SET: + case BTP_MESH_CFG_MODEL_PUB_VA_SET: config_mod_pub_va_set(data, len); break; - case MESH_CFG_MODEL_APP_BIND_VND: + case BTP_MESH_CFG_MODEL_APP_BIND_VND: config_model_app_bind_vnd(data, len); break; - case MESH_HEALTH_FAULT_GET: + case BTP_MESH_HEALTH_FAULT_GET: health_fault_get(data, len); break; - case MESH_HEALTH_FAULT_CLEAR: + case BTP_MESH_HEALTH_FAULT_CLEAR: health_fault_clear(data, len); break; - case MESH_HEALTH_FAULT_TEST: + case BTP_MESH_HEALTH_FAULT_TEST: health_fault_test(data, len); break; - case MESH_HEALTH_PERIOD_GET: + case BTP_MESH_HEALTH_PERIOD_GET: health_period_get(data, len); break; - case MESH_HEALTH_PERIOD_SET: + case BTP_MESH_HEALTH_PERIOD_SET: health_period_set(data, len); break; - case MESH_HEALTH_ATTENTION_GET: + case BTP_MESH_HEALTH_ATTENTION_GET: health_attention_get(data, len); break; - case MESH_HEALTH_ATTENTION_SET: + case BTP_MESH_HEALTH_ATTENTION_SET: health_attention_set(data, len); break; - case MESH_PROVISION_ADV: + case BTP_MESH_PROVISION_ADV: provision_adv(data, len); break; - case MESH_CFG_KRP_GET: + case BTP_MESH_CFG_KRP_GET: config_krp_get(data, len); break; - case MESH_CFG_KRP_SET: + case BTP_MESH_CFG_KRP_SET: config_krp_set(data, len); break; #if defined(CONFIG_BT_TESTING) - case MESH_LPN_SUBSCRIBE: + case BTP_MESH_LPN_SUBSCRIBE: lpn_subscribe(data, len); break; - case MESH_LPN_UNSUBSCRIBE: + case BTP_MESH_LPN_UNSUBSCRIBE: lpn_unsubscribe(data, len); break; - case MESH_RPL_CLEAR: + case BTP_MESH_RPL_CLEAR: rpl_clear(data, len); break; #endif /* CONFIG_BT_TESTING */ - case MESH_PROXY_IDENTITY: + case BTP_MESH_PROXY_IDENTITY: proxy_identity_enable(data, len); break; default: @@ -2625,7 +2625,7 @@ void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const voi size_t payload_len) { NET_BUF_SIMPLE_DEFINE(buf, UINT8_MAX); - struct mesh_net_recv_ev *ev; + struct btp_mesh_net_recv_ev *ev; LOG_DBG("ttl 0x%02x ctl 0x%02x src 0x%04x dst 0x%04x payload_len %zu", ttl, ctl, src, dst, payload_len); @@ -2643,7 +2643,7 @@ void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const voi ev->payload_len = payload_len; net_buf_simple_add_mem(&buf, payload, payload_len); - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_NET_RECV, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_NET_RECV, CONTROLLER_INDEX, buf.data, buf.len); } @@ -2691,19 +2691,19 @@ static void model_unbound_cb(uint16_t addr, struct bt_mesh_model *model, static void invalid_bearer_cb(uint8_t opcode) { - struct mesh_invalid_bearer_ev ev = { + struct btp_mesh_invalid_bearer_ev ev = { .opcode = opcode, }; LOG_DBG("opcode 0x%02x", opcode); - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_INVALID_BEARER, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_INVALID_BEARER, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } static void incomp_timer_exp_cb(void) { - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_INCOMP_TIMER_EXP, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_INCOMP_TIMER_EXP, CONTROLLER_INDEX, NULL, 0); } @@ -2718,7 +2718,7 @@ static struct bt_test_cb bt_test_cb = { static void friend_established(uint16_t net_idx, uint16_t lpn_addr, uint8_t recv_delay, uint32_t polltimeout) { - struct mesh_frnd_established_ev ev = { net_idx, lpn_addr, recv_delay, + struct btp_mesh_frnd_established_ev ev = { net_idx, lpn_addr, recv_delay, polltimeout }; LOG_DBG("Friendship (as Friend) established with " @@ -2726,18 +2726,18 @@ static void friend_established(uint16_t net_idx, uint16_t lpn_addr, lpn_addr, recv_delay, polltimeout); - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_FRND_ESTABLISHED, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_FRND_ESTABLISHED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } static void friend_terminated(uint16_t net_idx, uint16_t lpn_addr) { - struct mesh_frnd_terminated_ev ev = { net_idx, lpn_addr }; + struct btp_mesh_frnd_terminated_ev ev = { net_idx, lpn_addr }; LOG_DBG("Friendship (as Friend) lost with LPN " "0x%04x", lpn_addr); - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_FRND_TERMINATED, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_FRND_TERMINATED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } @@ -2749,35 +2749,35 @@ BT_MESH_FRIEND_CB_DEFINE(friend_cb) = { static void lpn_established(uint16_t net_idx, uint16_t friend_addr, uint8_t queue_size, uint8_t recv_win) { - struct mesh_lpn_established_ev ev = { net_idx, friend_addr, queue_size, + struct btp_mesh_lpn_established_ev ev = { net_idx, friend_addr, queue_size, recv_win }; LOG_DBG("Friendship (as LPN) established with " "Friend 0x%04x Queue Size %d Receive Window %d", friend_addr, queue_size, recv_win); - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_LPN_ESTABLISHED, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_LPN_ESTABLISHED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } static void lpn_terminated(uint16_t net_idx, uint16_t friend_addr) { - struct mesh_lpn_polled_ev ev = { net_idx, friend_addr }; + struct btp_mesh_lpn_polled_ev ev = { net_idx, friend_addr }; LOG_DBG("Friendship (as LPN) lost with Friend " "0x%04x", friend_addr); - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_LPN_TERMINATED, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_LPN_TERMINATED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } static void lpn_polled(uint16_t net_idx, uint16_t friend_addr, bool retry) { - struct mesh_lpn_polled_ev ev = { net_idx, friend_addr, (uint8_t)retry }; + struct btp_mesh_lpn_polled_ev ev = { net_idx, friend_addr, (uint8_t)retry }; LOG_DBG("LPN polled 0x%04x %s", friend_addr, retry ? "(retry)" : ""); - tester_send(BTP_SERVICE_ID_MESH, MESH_EV_LPN_POLLED, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_LPN_POLLED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); } diff --git a/tests/bluetooth/tester/src/btp_vcp.c b/tests/bluetooth/tester/src/btp_vcp.c index 04921850e87f..308a8f8675a1 100644 --- a/tests/bluetooth/tester/src/btp_vcp.c +++ b/tests/bluetooth/tester/src/btp_vcp.c @@ -39,20 +39,20 @@ static void vcs_supported_commands(uint8_t *data, uint16_t len) struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE); net_buf_simple_init(buf, 0); - net_buf_simple_add_u8(buf, VCS_READ_SUPPORTED_COMMANDS); - net_buf_simple_add_u8(buf, VCS_SET_VOL); - net_buf_simple_add_u8(buf, VCS_VOL_UP); - net_buf_simple_add_u8(buf, VCS_VOL_DOWN); - net_buf_simple_add_u8(buf, VCS_MUTE); - net_buf_simple_add_u8(buf, VCS_UNMUTE); - - tester_send(BTP_SERVICE_ID_VCS, VCS_READ_SUPPORTED_COMMANDS, + net_buf_simple_add_u8(buf, BTP_VCS_READ_SUPPORTED_COMMANDS); + net_buf_simple_add_u8(buf, BTP_VCS_SET_VOL); + net_buf_simple_add_u8(buf, BTP_VCS_VOL_UP); + net_buf_simple_add_u8(buf, BTP_VCS_VOL_DOWN); + net_buf_simple_add_u8(buf, BTP_VCS_MUTE); + net_buf_simple_add_u8(buf, BTP_VCS_UNMUTE); + + tester_send(BTP_SERVICE_ID_VCS, BTP_VCS_READ_SUPPORTED_COMMANDS, CONTROLLER_INDEX, buf->data, buf->len); } static void set_volume(uint8_t *data) { - const struct vcs_set_vol_cmd *cmd = (void *)data; + const struct btp_vcs_set_vol_cmd *cmd = (void *)data; uint8_t volume; volume = cmd->volume; @@ -60,12 +60,12 @@ static void set_volume(uint8_t *data) LOG_DBG("Set volume 0x%02x", volume); if (bt_vcp_vol_rend_set_vol(volume) != 0) { - tester_rsp(BTP_SERVICE_ID_VCS, VCS_SET_VOL, + tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_SET_VOL, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } - tester_rsp(BTP_SERVICE_ID_VCS, VCS_SET_VOL, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_SET_VOL, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } @@ -74,12 +74,12 @@ static void vol_up(void) LOG_DBG("Volume Up"); if (bt_vcp_vol_rend_vol_up() != 0) { - tester_rsp(BTP_SERVICE_ID_VCS, VCS_VOL_UP, + tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_VOL_UP, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } - tester_rsp(BTP_SERVICE_ID_VCS, VCS_VOL_UP, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_VOL_UP, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } @@ -88,12 +88,12 @@ static void vol_down(void) LOG_DBG("Volume Down"); if (bt_vcp_vol_rend_vol_down() != 0) { - tester_rsp(BTP_SERVICE_ID_VCS, VCS_VOL_DOWN, + tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_VOL_DOWN, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } - tester_rsp(BTP_SERVICE_ID_VCS, VCS_VOL_DOWN, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_VOL_DOWN, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } @@ -102,12 +102,12 @@ static void mute(void) LOG_DBG("Mute"); if (bt_vcp_vol_rend_mute() != 0) { - tester_rsp(BTP_SERVICE_ID_VCS, VCS_MUTE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_MUTE, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } - tester_rsp(BTP_SERVICE_ID_VCS, VCS_MUTE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_MUTE, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } @@ -116,12 +116,12 @@ static void unmute(void) LOG_DBG("Unmute"); if (bt_vcp_vol_rend_unmute() != 0) { - tester_rsp(BTP_SERVICE_ID_VCS, VCS_UNMUTE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_UNMUTE, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } - tester_rsp(BTP_SERVICE_ID_VCS, VCS_UNMUTE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_UNMUTE, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } @@ -144,22 +144,22 @@ void tester_handle_vcs(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len) { switch (opcode) { - case VCS_READ_SUPPORTED_COMMANDS: + case BTP_VCS_READ_SUPPORTED_COMMANDS: vcs_supported_commands(data, len); break; - case VCS_SET_VOL: + case BTP_VCS_SET_VOL: set_volume(data); break; - case VCS_VOL_UP: + case BTP_VCS_VOL_UP: vol_up(); break; - case VCS_VOL_DOWN: + case BTP_VCS_VOL_DOWN: vol_down(); break; - case VCS_MUTE: + case BTP_VCS_MUTE: mute(); break; - case VCS_UNMUTE: + case BTP_VCS_UNMUTE: unmute(); break; default: @@ -175,15 +175,15 @@ static void aics_supported_commands(uint8_t *data, uint16_t len) struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE); net_buf_simple_init(buf, 0); - net_buf_simple_add_u8(buf, AICS_READ_SUPPORTED_COMMANDS); - net_buf_simple_add_u8(buf, AICS_SET_GAIN); - net_buf_simple_add_u8(buf, AICS_MUTE); - net_buf_simple_add_u8(buf, AICS_UNMUTE); - net_buf_simple_add_u8(buf, AICS_MAN_GAIN); - net_buf_simple_add_u8(buf, AICS_AUTO_GAIN); - net_buf_simple_add_u8(buf, AICS_DESCRIPTION); - - tester_send(BTP_SERVICE_ID_AICS, AICS_READ_SUPPORTED_COMMANDS, + net_buf_simple_add_u8(buf, BTP_AICS_READ_SUPPORTED_COMMANDS); + net_buf_simple_add_u8(buf, BTP_AICS_SET_GAIN); + net_buf_simple_add_u8(buf, BTP_AICS_MUTE); + net_buf_simple_add_u8(buf, BTP_AICS_UNMUTE); + net_buf_simple_add_u8(buf, BTP_AICS_MAN_GAIN); + net_buf_simple_add_u8(buf, BTP_AICS_AUTO_GAIN); + net_buf_simple_add_u8(buf, BTP_AICS_DESCRIPTION); + + tester_send(BTP_SERVICE_ID_AICS, BTP_AICS_READ_SUPPORTED_COMMANDS, CONTROLLER_INDEX, buf->data, buf->len); } @@ -226,7 +226,7 @@ static struct bt_aics_cb aics_cb = { void aics_set_gain(uint8_t *data) { - const struct aics_set_gain *cmd = (void *)data; + const struct btp_aics_set_gain *cmd = (void *)data; const int8_t gain = cmd->gain; @@ -234,13 +234,13 @@ void aics_set_gain(uint8_t *data) for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_gain_set(included.aics[0], gain) != 0) { - tester_rsp(BTP_SERVICE_ID_AICS, AICS_SET_GAIN, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_SET_GAIN, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } } - tester_rsp(BTP_SERVICE_ID_AICS, AICS_SET_GAIN, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_SET_GAIN, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } @@ -250,13 +250,13 @@ void aics_mute(void) for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_mute(included.aics[i]) != 0) { - tester_rsp(BTP_SERVICE_ID_AICS, AICS_MUTE, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_MUTE, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } } - tester_rsp(BTP_SERVICE_ID_AICS, AICS_MUTE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_MUTE, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } @@ -266,13 +266,13 @@ void aics_unmute(void) for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_unmute(included.aics[i]) != 0) { - tester_rsp(BTP_SERVICE_ID_AICS, AICS_UNMUTE, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_UNMUTE, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } } - tester_rsp(BTP_SERVICE_ID_AICS, AICS_UNMUTE, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_UNMUTE, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } @@ -282,13 +282,13 @@ void aics_man_gain(void) for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_manual_gain_set(included.aics[i]) != 0) { - tester_rsp(BTP_SERVICE_ID_AICS, AICS_MAN_GAIN, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_MAN_GAIN, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } } - tester_rsp(BTP_SERVICE_ID_AICS, AICS_MAN_GAIN, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_MAN_GAIN, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } @@ -298,13 +298,13 @@ void aics_auto_gain(void) for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_automatic_gain_set(included.aics[i]) != 0) { - tester_rsp(BTP_SERVICE_ID_AICS, AICS_AUTO_GAIN, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_AUTO_GAIN, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } } - tester_rsp(BTP_SERVICE_ID_AICS, AICS_AUTO_GAIN, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_AUTO_GAIN, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } @@ -313,7 +313,7 @@ void aics_auto_gain_only(void) { LOG_DBG("AICS auto gain only"); - tester_rsp(BTP_SERVICE_ID_AICS, AICS_AUTO_GAIN_ONLY, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_AUTO_GAIN_ONLY, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -322,7 +322,7 @@ void aics_auto_man_only(void) { LOG_DBG("AICS manual gain only"); - tester_rsp(BTP_SERVICE_ID_AICS, AICS_MAN_GAIN_ONLY, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_MAN_GAIN_ONLY, CONTROLLER_INDEX, BTP_STATUS_FAILED); } @@ -331,13 +331,13 @@ void aics_mute_disable(void) { LOG_DBG("AICS mute disable"); - tester_rsp(BTP_SERVICE_ID_AICS, AICS_MUTE_DISABLE, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_MUTE_DISABLE, CONTROLLER_INDEX, BTP_STATUS_FAILED); } void aics_desc(uint8_t *data) { - const struct aics_audio_desc *cmd = (void *) data; + const struct btp_aics_audio_desc *cmd = (void *) data; char description[BT_AICS_MAX_INPUT_DESCRIPTION_SIZE]; LOG_DBG("AICS description"); @@ -353,47 +353,47 @@ void aics_desc(uint8_t *data) for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_description_set(included.aics[i], description) != 0) { - tester_rsp(BTP_SERVICE_ID_AICS, AICS_DESCRIPTION, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_DESCRIPTION, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } } rsp: - tester_rsp(BTP_SERVICE_ID_AICS, AICS_DESCRIPTION, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_DESCRIPTION, CONTROLLER_INDEX, BTP_STATUS_FAILED); } void tester_handle_aics(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len) { switch (opcode) { - case AICS_READ_SUPPORTED_COMMANDS: + case BTP_AICS_READ_SUPPORTED_COMMANDS: aics_supported_commands(data, len); break; - case AICS_SET_GAIN: + case BTP_AICS_SET_GAIN: aics_set_gain(data); break; - case AICS_MUTE: + case BTP_AICS_MUTE: aics_mute(); break; - case AICS_UNMUTE: + case BTP_AICS_UNMUTE: aics_unmute(); break; - case AICS_MAN_GAIN: + case BTP_AICS_MAN_GAIN: aics_man_gain(); break; - case AICS_AUTO_GAIN: + case BTP_AICS_AUTO_GAIN: aics_auto_gain(); break; - case AICS_MAN_GAIN_ONLY: + case BTP_AICS_MAN_GAIN_ONLY: aics_auto_gain_only(); break; - case AICS_AUTO_GAIN_ONLY: + case BTP_AICS_AUTO_GAIN_ONLY: aics_auto_gain_only(); break; - case AICS_DESCRIPTION: + case BTP_AICS_DESCRIPTION: aics_desc(data); break; - case AICS_MUTE_DISABLE: + case BTP_AICS_MUTE_DISABLE: aics_mute_disable(); break; default: @@ -409,11 +409,11 @@ static void vocs_supported_commands(void) struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE); net_buf_simple_init(buf, 0); - net_buf_simple_add_u8(buf, VOCS_READ_SUPPORTED_COMMANDS); - net_buf_simple_add_u8(buf, VOCS_UPDATE_LOC); - net_buf_simple_add_u8(buf, VOCS_UPDATE_DESC); + net_buf_simple_add_u8(buf, BTP_VOCS_READ_SUPPORTED_COMMANDS); + net_buf_simple_add_u8(buf, BTP_VOCS_UPDATE_LOC); + net_buf_simple_add_u8(buf, BTP_VOCS_UPDATE_DESC); - tester_send(BTP_SERVICE_ID_VOCS, VOCS_READ_SUPPORTED_COMMANDS, + tester_send(BTP_SERVICE_ID_VOCS, BTP_VOCS_READ_SUPPORTED_COMMANDS, CONTROLLER_INDEX, buf->data, buf->len); } @@ -441,7 +441,7 @@ static struct bt_vocs_cb vocs_cb = { void vocs_audio_desc(uint8_t *data) { - struct vocs_audio_desc *cmd = (void *) data; + struct btp_vocs_audio_desc *cmd = (void *) data; char description[BT_AICS_MAX_OUTPUT_DESCRIPTION_SIZE]; LOG_DBG("VOCS description"); @@ -457,31 +457,31 @@ void vocs_audio_desc(uint8_t *data) for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT; i++) { if (bt_vocs_description_set(included.vocs[i], description) != 0) { - tester_rsp(BTP_SERVICE_ID_VOCS, VOCS_UPDATE_DESC, + tester_rsp(BTP_SERVICE_ID_VOCS, BTP_VOCS_UPDATE_DESC, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } } rsp: - tester_rsp(BTP_SERVICE_ID_VOCS, VOCS_UPDATE_DESC, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_VOCS, BTP_VOCS_UPDATE_DESC, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } void vocs_audio_loc(uint8_t *data) { - const struct vocs_audio_loc *cmd = (void *) data; + const struct btp_vocs_audio_loc *cmd = (void *) data; LOG_DBG("VOCS location"); for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT; i++) { if (bt_vocs_location_set(included.vocs[i], cmd->loc) != 0) { - tester_rsp(BTP_SERVICE_ID_VOCS, VOCS_UPDATE_LOC, + tester_rsp(BTP_SERVICE_ID_VOCS, BTP_VOCS_UPDATE_LOC, CONTROLLER_INDEX, BTP_STATUS_FAILED); return; } } - tester_rsp(BTP_SERVICE_ID_VOCS, VOCS_UPDATE_LOC, CONTROLLER_INDEX, + tester_rsp(BTP_SERVICE_ID_VOCS, BTP_VOCS_UPDATE_LOC, CONTROLLER_INDEX, BTP_STATUS_SUCCESS); } @@ -489,13 +489,13 @@ void tester_handle_vocs(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len) { switch (opcode) { - case VOCS_READ_SUPPORTED_COMMANDS: + case BTP_VOCS_READ_SUPPORTED_COMMANDS: vocs_supported_commands(); break; - case VOCS_UPDATE_DESC: + case BTP_VOCS_UPDATE_DESC: vocs_audio_desc(data); break; - case VOCS_UPDATE_LOC: + case BTP_VOCS_UPDATE_LOC: vocs_audio_loc(data); break; default: From d53e48d84b69e2cbda83bbff062758da69ad244d Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 8 Feb 2023 15:34:45 +0100 Subject: [PATCH 0021/1906] bluetooth: tester: Move core service to separate file There is no need to keep it in same file as BTP protocol handler. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/CMakeLists.txt | 1 + tests/bluetooth/tester/src/btp.c | 197 +------------------ tests/bluetooth/tester/src/btp/bttester.h | 3 + tests/bluetooth/tester/src/btp_core.c | 223 ++++++++++++++++++++++ 4 files changed, 229 insertions(+), 195 deletions(-) create mode 100644 tests/bluetooth/tester/src/btp_core.c diff --git a/tests/bluetooth/tester/CMakeLists.txt b/tests/bluetooth/tester/CMakeLists.txt index f25675a9c2fa..c3daa18c2e38 100644 --- a/tests/bluetooth/tester/CMakeLists.txt +++ b/tests/bluetooth/tester/CMakeLists.txt @@ -14,6 +14,7 @@ zephyr_library_include_directories(${ZEPHYR_BASE}/subsys/bluetooth/host) target_sources(app PRIVATE src/main.c src/btp.c + src/btp_core.c src/btp_gap.c src/btp_gatt.c ) diff --git a/tests/bluetooth/tester/src/btp.c b/tests/bluetooth/tester/src/btp.c index c7e1c80317d3..9f7b73f696e3 100644 --- a/tests/bluetooth/tester/src/btp.c +++ b/tests/bluetooth/tester/src/btp.c @@ -42,199 +42,6 @@ static struct btp_buf cmd_buf[CMD_QUEUED]; static K_FIFO_DEFINE(cmds_queue); static K_FIFO_DEFINE(avail_queue); -static void supported_commands(uint8_t *data, uint16_t len) -{ - uint8_t buf[1]; - struct btp_core_read_supported_commands_rp *rp = (void *) buf; - - (void)memset(buf, 0, sizeof(buf)); - - tester_set_bit(buf, BTP_CORE_READ_SUPPORTED_COMMANDS); - tester_set_bit(buf, BTP_CORE_READ_SUPPORTED_SERVICES); - tester_set_bit(buf, BTP_CORE_REGISTER_SERVICE); - tester_set_bit(buf, BTP_CORE_UNREGISTER_SERVICE); - - tester_send(BTP_SERVICE_ID_CORE, BTP_CORE_READ_SUPPORTED_COMMANDS, - BTP_INDEX_NONE, (uint8_t *) rp, sizeof(buf)); -} - -static void supported_services(uint8_t *data, uint16_t len) -{ - uint8_t buf[2]; - struct btp_core_read_supported_services_rp *rp = (void *) buf; - - (void)memset(buf, 0, sizeof(buf)); - - tester_set_bit(buf, BTP_SERVICE_ID_CORE); - tester_set_bit(buf, BTP_SERVICE_ID_GAP); - tester_set_bit(buf, BTP_SERVICE_ID_GATT); -#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL) - tester_set_bit(buf, BTP_SERVICE_ID_L2CAP); -#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */ -#if defined(CONFIG_BT_MESH) - tester_set_bit(buf, BTP_SERVICE_ID_MESH); -#endif /* CONFIG_BT_MESH */ -#if defined(CONFIG_BT_VCP_VOL_REND) - tester_set_bit(buf, BTP_SERVICE_ID_VCS); -#endif /* CONFIG_BT_VCP_VOL_REND */ -#if defined(CONFIG_BT_IAS) || defined(CONFIG_BT_IAS_CLIENT) - tester_set_bit(buf, BTP_SERVICE_ID_IAS); -#endif /* CONFIG_BT_IAS */ -#if defined(CONFIG_BT_AICS) || defined(CONFIG_BT_AICS_CLIENT) - tester_set_bit(buf, BTP_SERVICE_ID_AICS); -#endif /*CONFIG_BT_AICS */ -#if defined(CONFIG_BT_VOCS) || defined(CONFIG_BT_VOCS_CLIENT) - tester_set_bit(buf, BTP_SERVICE_ID_VOCS); -#endif /* CONFIG_BT_VOCS */ - - tester_send(BTP_SERVICE_ID_CORE, BTP_CORE_READ_SUPPORTED_SERVICES, - BTP_INDEX_NONE, (uint8_t *) rp, sizeof(buf)); -} - -static void register_service(uint8_t *data, uint16_t len) -{ - struct btp_core_register_service_cmd *cmd = (void *) data; - uint8_t status; - - switch (cmd->id) { - case BTP_SERVICE_ID_GAP: - status = tester_init_gap(); - /* Rsp with success status will be handled by bt enable cb */ - if (status == BTP_STATUS_FAILED) { - goto rsp; - } - return; - case BTP_SERVICE_ID_GATT: - status = tester_init_gatt(); - break; -#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL) - case BTP_SERVICE_ID_L2CAP: - status = tester_init_l2cap(); -#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */ - break; -#if defined(CONFIG_BT_MESH) - case BTP_SERVICE_ID_MESH: - status = tester_init_mesh(); - break; -#endif /* CONFIG_BT_MESH */ -#if defined(CONFIG_BT_VCP_VOL_REND) - case BTP_SERVICE_ID_VCS: - status = tester_init_vcp(); - break; -#endif /* CONFIG_BT_VCP_VOL_REND */ -#if defined(CONFIG_BT_VOCS) || defined(CONFIG_BT_VOCS_CLIENT) - case BTP_SERVICE_ID_VOCS: - status = tester_init_vcp(); - break; -#endif /* CONFIG_BT_VOCS */ -#if defined(CONFIG_BT_AICS) || defined(CONFIG_BT_AICS_CLIENT) - case BTP_SERVICE_ID_AICS: - status = tester_init_vcp(); - break; -#endif /* CONFIG_BT_AICS */ -#if defined(CONFIG_BT_IAS) || defined(CONFIG_BT_IAS_CLIENT) - case BTP_SERVICE_ID_IAS: - status = BTP_STATUS_SUCCESS; - break; -#endif /* CONFIG_BT_IAS */ -#if defined(CONFIG_BT_PACS) - case BTP_SERVICE_ID_PACS: - status = tester_init_bap(); - break; -#endif /* CONFIG_BT_PACS */ - default: - LOG_WRN("unknown id: 0x%02x", cmd->id); - status = BTP_STATUS_FAILED; - break; - } - -rsp: - tester_rsp(BTP_SERVICE_ID_CORE, BTP_CORE_REGISTER_SERVICE, BTP_INDEX_NONE, - status); -} - -static void unregister_service(uint8_t *data, uint16_t len) -{ - struct btp_core_unregister_service_cmd *cmd = (void *) data; - uint8_t status; - - switch (cmd->id) { - case BTP_SERVICE_ID_GAP: - status = tester_unregister_gap(); - break; - case BTP_SERVICE_ID_GATT: - status = tester_unregister_gatt(); - break; -#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL) - case BTP_SERVICE_ID_L2CAP: - status = tester_unregister_l2cap(); - break; -#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */ -#if defined(CONFIG_BT_MESH) - case BTP_SERVICE_ID_MESH: - status = tester_unregister_mesh(); - break; -#endif /* CONFIG_BT_MESH */ -#if defined(CONFIG_BT_VCP_VOL_REND) - case BTP_SERVICE_ID_VCS: - status = tester_unregister_vcp(); - break; -#endif /* CONFIG_BT_VCP_VOL_REND */ -#if defined(CONFIG_BT_AICS) || defined(CONFIG_BT_AICS_CLIENT) - case BTP_SERVICE_ID_AICS: - status = tester_unregister_vcp(); - break; -#endif /* CONFIG_BT_AICS */ -#if defined(CONFIG_BT_VOCS) || defined(CONFIG_BT_VOCS_CLIENT) - case BTP_SERVICE_ID_VOCS: - status = tester_unregister_vcp(); - break; -#endif /* CONFIG_BT_VOCS */ -#if defined(CONFIG_BT_PACS) - case BTP_SERVICE_ID_PACS: - status = tester_unregister_bap(); - break; -#endif /* CONFIG_BT_PACS */ - default: - LOG_WRN("unknown id: 0x%x", cmd->id); - status = BTP_STATUS_FAILED; - break; - } - - tester_rsp(BTP_SERVICE_ID_CORE, BTP_CORE_UNREGISTER_SERVICE, BTP_INDEX_NONE, - status); -} - -static void handle_core(uint8_t opcode, uint8_t index, uint8_t *data, - uint16_t len) -{ - if (index != BTP_INDEX_NONE) { - LOG_WRN("index != BTP_INDEX_NONE: 0x%x", index); - tester_rsp(BTP_SERVICE_ID_CORE, opcode, index, BTP_STATUS_FAILED); - return; - } - - switch (opcode) { - case BTP_CORE_READ_SUPPORTED_COMMANDS: - supported_commands(data, len); - return; - case BTP_CORE_READ_SUPPORTED_SERVICES: - supported_services(data, len); - return; - case BTP_CORE_REGISTER_SERVICE: - register_service(data, len); - return; - case BTP_CORE_UNREGISTER_SERVICE: - unregister_service(data, len); - return; - default: - LOG_WRN("unknown opcode: 0x%x", opcode); - tester_rsp(BTP_SERVICE_ID_CORE, opcode, BTP_INDEX_NONE, - BTP_STATUS_UNKNOWN_CMD); - return; - } -} - static void cmd_handler(void *p1, void *p2, void *p3) { while (1) { @@ -251,8 +58,8 @@ static void cmd_handler(void *p1, void *p2, void *p3) switch (cmd->hdr.service) { case BTP_SERVICE_ID_CORE: - handle_core(cmd->hdr.opcode, cmd->hdr.index, - cmd->hdr.data, len); + tester_handle_core(cmd->hdr.opcode, cmd->hdr.index, + cmd->hdr.data, len); break; case BTP_SERVICE_ID_GAP: tester_handle_gap(cmd->hdr.opcode, cmd->hdr.index, diff --git a/tests/bluetooth/tester/src/btp/bttester.h b/tests/bluetooth/tester/src/btp/bttester.h index b1b74ab8ba37..c2e067b137d2 100644 --- a/tests/bluetooth/tester/src/btp/bttester.h +++ b/tests/bluetooth/tester/src/btp/bttester.h @@ -55,6 +55,9 @@ uint8_t tester_unregister_gap(void); void tester_handle_gap(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len); +void tester_handle_core(uint8_t opcode, uint8_t index, uint8_t *data, + uint16_t len); + uint8_t tester_init_bap(void); uint8_t tester_unregister_bap(void); void tester_handle_pacs(uint8_t opcode, uint8_t index, uint8_t *data, diff --git a/tests/bluetooth/tester/src/btp_core.c b/tests/bluetooth/tester/src/btp_core.c new file mode 100644 index 000000000000..a4cc2dcba6d8 --- /dev/null +++ b/tests/bluetooth/tester/src/btp_core.c @@ -0,0 +1,223 @@ +/* btp_core.c - Bluetooth Core service */ + +/* + * Copyright (c) 2015-2016 Intel Corporation + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#define LOG_MODULE_NAME bttester_core +LOG_MODULE_REGISTER(LOG_MODULE_NAME); + +#include "btp/btp.h" + + +static void supported_commands(uint8_t *data, uint16_t len) +{ + uint8_t buf[1]; + struct btp_core_read_supported_commands_rp *rp = (void *) buf; + + (void)memset(buf, 0, sizeof(buf)); + + tester_set_bit(buf, BTP_CORE_READ_SUPPORTED_COMMANDS); + tester_set_bit(buf, BTP_CORE_READ_SUPPORTED_SERVICES); + tester_set_bit(buf, BTP_CORE_REGISTER_SERVICE); + tester_set_bit(buf, BTP_CORE_UNREGISTER_SERVICE); + + tester_send(BTP_SERVICE_ID_CORE, BTP_CORE_READ_SUPPORTED_COMMANDS, + BTP_INDEX_NONE, (uint8_t *) rp, sizeof(buf)); +} + +static void supported_services(uint8_t *data, uint16_t len) +{ + uint8_t buf[2]; + struct btp_core_read_supported_services_rp *rp = (void *) buf; + + (void)memset(buf, 0, sizeof(buf)); + + tester_set_bit(buf, BTP_SERVICE_ID_CORE); + tester_set_bit(buf, BTP_SERVICE_ID_GAP); + tester_set_bit(buf, BTP_SERVICE_ID_GATT); +#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL) + tester_set_bit(buf, BTP_SERVICE_ID_L2CAP); +#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */ +#if defined(CONFIG_BT_MESH) + tester_set_bit(buf, BTP_SERVICE_ID_MESH); +#endif /* CONFIG_BT_MESH */ +#if defined(CONFIG_BT_VCP_VOL_REND) + tester_set_bit(buf, BTP_SERVICE_ID_VCS); +#endif /* CONFIG_BT_VCP_VOL_REND */ +#if defined(CONFIG_BT_IAS) || defined(CONFIG_BT_IAS_CLIENT) + tester_set_bit(buf, BTP_SERVICE_ID_IAS); +#endif /* CONFIG_BT_IAS */ +#if defined(CONFIG_BT_AICS) || defined(CONFIG_BT_AICS_CLIENT) + tester_set_bit(buf, BTP_SERVICE_ID_AICS); +#endif /*CONFIG_BT_AICS */ +#if defined(CONFIG_BT_VOCS) || defined(CONFIG_BT_VOCS_CLIENT) + tester_set_bit(buf, BTP_SERVICE_ID_VOCS); +#endif /* CONFIG_BT_VOCS */ + + tester_send(BTP_SERVICE_ID_CORE, BTP_CORE_READ_SUPPORTED_SERVICES, + BTP_INDEX_NONE, (uint8_t *) rp, sizeof(buf)); +} + +static void register_service(uint8_t *data, uint16_t len) +{ + struct btp_core_register_service_cmd *cmd = (void *) data; + uint8_t status; + + switch (cmd->id) { + case BTP_SERVICE_ID_GAP: + status = tester_init_gap(); + /* Rsp with success status will be handled by bt enable cb */ + if (status == BTP_STATUS_FAILED) { + goto rsp; + } + return; + case BTP_SERVICE_ID_GATT: + status = tester_init_gatt(); + break; +#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL) + case BTP_SERVICE_ID_L2CAP: + status = tester_init_l2cap(); +#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */ + break; +#if defined(CONFIG_BT_MESH) + case BTP_SERVICE_ID_MESH: + status = tester_init_mesh(); + break; +#endif /* CONFIG_BT_MESH */ +#if defined(CONFIG_BT_VCP_VOL_REND) + case BTP_SERVICE_ID_VCS: + status = tester_init_vcp(); + break; +#endif /* CONFIG_BT_VCP_VOL_REND */ +#if defined(CONFIG_BT_VOCS) || defined(CONFIG_BT_VOCS_CLIENT) + case BTP_SERVICE_ID_VOCS: + status = tester_init_vcp(); + break; +#endif /* CONFIG_BT_VOCS */ +#if defined(CONFIG_BT_AICS) || defined(CONFIG_BT_AICS_CLIENT) + case BTP_SERVICE_ID_AICS: + status = tester_init_vcp(); + break; +#endif /* CONFIG_BT_AICS */ +#if defined(CONFIG_BT_IAS) || defined(CONFIG_BT_IAS_CLIENT) + case BTP_SERVICE_ID_IAS: + status = BTP_STATUS_SUCCESS; + break; +#endif /* CONFIG_BT_IAS */ +#if defined(CONFIG_BT_PACS) + case BTP_SERVICE_ID_PACS: + status = tester_init_bap(); + break; +#endif /* CONFIG_BT_PACS */ + default: + LOG_WRN("unknown id: 0x%02x", cmd->id); + status = BTP_STATUS_FAILED; + break; + } + +rsp: + tester_rsp(BTP_SERVICE_ID_CORE, BTP_CORE_REGISTER_SERVICE, BTP_INDEX_NONE, + status); +} + +static void unregister_service(uint8_t *data, uint16_t len) +{ + struct btp_core_unregister_service_cmd *cmd = (void *) data; + uint8_t status; + + switch (cmd->id) { + case BTP_SERVICE_ID_GAP: + status = tester_unregister_gap(); + break; + case BTP_SERVICE_ID_GATT: + status = tester_unregister_gatt(); + break; +#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL) + case BTP_SERVICE_ID_L2CAP: + status = tester_unregister_l2cap(); + break; +#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */ +#if defined(CONFIG_BT_MESH) + case BTP_SERVICE_ID_MESH: + status = tester_unregister_mesh(); + break; +#endif /* CONFIG_BT_MESH */ +#if defined(CONFIG_BT_VCP_VOL_REND) + case BTP_SERVICE_ID_VCS: + status = tester_unregister_vcp(); + break; +#endif /* CONFIG_BT_VCP_VOL_REND */ +#if defined(CONFIG_BT_AICS) || defined(CONFIG_BT_AICS_CLIENT) + case BTP_SERVICE_ID_AICS: + status = tester_unregister_vcp(); + break; +#endif /* CONFIG_BT_AICS */ +#if defined(CONFIG_BT_VOCS) || defined(CONFIG_BT_VOCS_CLIENT) + case BTP_SERVICE_ID_VOCS: + status = tester_unregister_vcp(); + break; +#endif /* CONFIG_BT_VOCS */ +#if defined(CONFIG_BT_PACS) + case BTP_SERVICE_ID_PACS: + status = tester_unregister_bap(); + break; +#endif /* CONFIG_BT_PACS */ + default: + LOG_WRN("unknown id: 0x%x", cmd->id); + status = BTP_STATUS_FAILED; + break; + } + + tester_rsp(BTP_SERVICE_ID_CORE, BTP_CORE_UNREGISTER_SERVICE, BTP_INDEX_NONE, + status); +} + +void tester_handle_core(uint8_t opcode, uint8_t index, uint8_t *data, + uint16_t len) +{ + if (index != BTP_INDEX_NONE) { + LOG_WRN("index != BTP_INDEX_NONE: 0x%x", index); + tester_rsp(BTP_SERVICE_ID_CORE, opcode, index, BTP_STATUS_FAILED); + return; + } + + switch (opcode) { + case BTP_CORE_READ_SUPPORTED_COMMANDS: + supported_commands(data, len); + return; + case BTP_CORE_READ_SUPPORTED_SERVICES: + supported_services(data, len); + return; + case BTP_CORE_REGISTER_SERVICE: + register_service(data, len); + return; + case BTP_CORE_UNREGISTER_SERVICE: + unregister_service(data, len); + return; + default: + LOG_WRN("unknown opcode: 0x%x", opcode); + tester_rsp(BTP_SERVICE_ID_CORE, opcode, BTP_INDEX_NONE, + BTP_STATUS_UNKNOWN_CMD); + return; + } +} From 4683fabb1e7f25c2b3bffccbb189377234d25bd0 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 8 Feb 2023 15:42:56 +0100 Subject: [PATCH 0022/1906] bluetooth: tester: Initialize GAP service synchronously There is no need to initialize in asynchronous way as BTP is blocked anyway until init is done. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp_core.c | 7 +---- tests/bluetooth/tester/src/btp_gap.c | 39 +++++++++------------------ 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/tests/bluetooth/tester/src/btp_core.c b/tests/bluetooth/tester/src/btp_core.c index a4cc2dcba6d8..a4a5b43e8373 100644 --- a/tests/bluetooth/tester/src/btp_core.c +++ b/tests/bluetooth/tester/src/btp_core.c @@ -28,7 +28,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "btp/btp.h" - static void supported_commands(uint8_t *data, uint16_t len) { uint8_t buf[1]; @@ -86,11 +85,7 @@ static void register_service(uint8_t *data, uint16_t len) switch (cmd->id) { case BTP_SERVICE_ID_GAP: status = tester_init_gap(); - /* Rsp with success status will be handled by bt enable cb */ - if (status == BTP_STATUS_FAILED) { - goto rsp; - } - return; + break; case BTP_SERVICE_ID_GATT: status = tester_init_gatt(); break; diff --git a/tests/bluetooth/tester/src/btp_gap.c b/tests/bluetooth/tester/src/btp_gap.c index 8a8b9b5d74d8..ef1994de1592 100644 --- a/tests/bluetooth/tester/src/btp_gap.c +++ b/tests/bluetooth/tester/src/btp_gap.c @@ -1331,30 +1331,6 @@ void tester_handle_gap(uint8_t opcode, uint8_t index, uint8_t *data, } } -static void tester_init_gap_cb(int err) -{ - if (err) { - tester_rsp(BTP_SERVICE_ID_CORE, BTP_CORE_REGISTER_SERVICE, - BTP_INDEX_NONE, BTP_STATUS_FAILED); - LOG_WRN("Error: %d", err); - return; - } - - atomic_clear(¤t_settings); - atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_POWERED); - atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_CONNECTABLE); - atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_BONDABLE); - atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_LE); -#if defined(CONFIG_BT_PRIVACY) - atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_PRIVACY); -#endif /* CONFIG_BT_PRIVACY */ - - bt_conn_cb_register(&conn_callbacks); - - tester_rsp(BTP_SERVICE_ID_CORE, BTP_CORE_REGISTER_SERVICE, BTP_INDEX_NONE, - BTP_STATUS_SUCCESS); -} - uint8_t tester_init_gap(void) { int err; @@ -1365,14 +1341,25 @@ uint8_t tester_init_gap(void) if (bt_conn_auth_cb_register(&cb)) { return BTP_STATUS_FAILED; } - bt_conn_auth_info_cb_register(&auth_info_cb); - err = bt_enable(tester_init_gap_cb); + err = bt_enable(NULL); if (err < 0) { LOG_ERR("Unable to enable Bluetooth: %d", err); return BTP_STATUS_FAILED; } + atomic_clear(¤t_settings); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_POWERED); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_CONNECTABLE); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_BONDABLE); + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_LE); +#if defined(CONFIG_BT_PRIVACY) + atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_PRIVACY); +#endif /* CONFIG_BT_PRIVACY */ + + bt_conn_cb_register(&conn_callbacks); + bt_conn_auth_info_cb_register(&auth_info_cb); + return BTP_STATUS_SUCCESS; } From 79f1df9f5b0b40266bc541adf10e07836fe4d22d Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 8 Feb 2023 16:04:03 +0100 Subject: [PATCH 0023/1906] bluetooth: tester: Refactor BTP handling This changes the way of BTP commmand handlers are called. Instead of calling functions to handle service we now provide API for registering callbacks per command. This allows to keep common checks (size etc) in single place for (most) commands. Also provide common buffer for reponses forcing callbacks to handle replay in common way. In this commit only Core and GAP services are converted. This leaves rest of services unfuntional (but code stil compiles correctly). Other services are converted in following commits. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp.c | 115 ++-- tests/bluetooth/tester/src/btp/btp.h | 6 + tests/bluetooth/tester/src/btp/btp_gap.h | 7 + tests/bluetooth/tester/src/btp/bttester.h | 17 +- tests/bluetooth/tester/src/btp_core.c | 176 +++-- tests/bluetooth/tester/src/btp_gap.c | 795 ++++++++++++---------- 6 files changed, 651 insertions(+), 465 deletions(-) diff --git a/tests/bluetooth/tester/src/btp.c b/tests/bluetooth/tester/src/btp.c index 9f7b73f696e3..360452107e38 100644 --- a/tests/bluetooth/tester/src/btp.c +++ b/tests/bluetooth/tester/src/btp.c @@ -35,6 +35,7 @@ struct btp_buf { uint8_t data[BTP_MTU]; struct btp_hdr hdr; }; + uint8_t rsp[BTP_MTU]; }; static struct btp_buf cmd_buf[CMD_QUEUED]; @@ -42,76 +43,83 @@ static struct btp_buf cmd_buf[CMD_QUEUED]; static K_FIFO_DEFINE(cmds_queue); static K_FIFO_DEFINE(avail_queue); +static struct { + const struct btp_handler *handlers; + size_t num; +} service_handler[BTP_SERVICE_ID_MAX + 1]; + + +void tester_register_command_handlers(uint8_t service, + const struct btp_handler *handlers, + size_t num) +{ + __ASSERT_NO_MSG(service <= BTP_SERVICE_ID_MAX); + __ASSERT_NO_MSG(service_handler[service].handlers == NULL); + + service_handler[service].handlers = handlers; + service_handler[service].num = num; +} + +static const struct btp_handler *find_btp_handler(uint8_t service, uint8_t opcode) +{ + if ((service > BTP_SERVICE_ID_MAX) || + (service_handler[service].handlers == NULL)) { + return NULL; + } + + for (uint8_t i = 0; i < service_handler[service].num; i++) { + if (service_handler[service].handlers[i].opcode == opcode) { + return &service_handler[service].handlers[i]; + } + } + + return NULL; +} + static void cmd_handler(void *p1, void *p2, void *p3) { while (1) { + const struct btp_handler *btp; struct btp_buf *cmd; + uint8_t status; + uint16_t rsp_len = 0; uint16_t len; cmd = k_fifo_get(&cmds_queue, K_FOREVER); len = sys_le16_to_cpu(cmd->hdr.len); - /* TODO - * verify if service is registered before calling handler - */ + btp = find_btp_handler(cmd->hdr.service, cmd->hdr.opcode); + if (btp) { + if ((btp->expect_len >= 0) && (btp->expect_len != len)) { + status = BTP_STATUS_FAILED; + } else { + status = btp->func(cmd->hdr.index, cmd->hdr.data, + len, cmd->rsp, &rsp_len); + } + + __ASSERT_NO_MSG((rsp_len + sizeof(struct btp_hdr)) <= BTP_MTU); + } else { + status = BTP_STATUS_UNKNOWN_CMD; + } - switch (cmd->hdr.service) { - case BTP_SERVICE_ID_CORE: - tester_handle_core(cmd->hdr.opcode, cmd->hdr.index, - cmd->hdr.data, len); - break; - case BTP_SERVICE_ID_GAP: - tester_handle_gap(cmd->hdr.opcode, cmd->hdr.index, - cmd->hdr.data, len); - break; - case BTP_SERVICE_ID_GATT: - tester_handle_gatt(cmd->hdr.opcode, cmd->hdr.index, - cmd->hdr.data, len); - break; -#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL) - case BTP_SERVICE_ID_L2CAP: - tester_handle_l2cap(cmd->hdr.opcode, cmd->hdr.index, - cmd->hdr.data, len); -#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */ - break; -#if defined(CONFIG_BT_MESH) - case BTP_SERVICE_ID_MESH: - tester_handle_mesh(cmd->hdr.opcode, cmd->hdr.index, - cmd->hdr.data, len); - break; -#endif /* CONFIG_BT_MESH */ -#if defined(CONFIG_BT_VCP_VOL_REND) - case BTP_SERVICE_ID_VCS: - tester_handle_vcs(cmd->hdr.opcode, cmd->hdr.index, - cmd->hdr.data, len); - break; -#endif /* CONFIG_BT_VCP_VOL_REND */ -#if defined(CONFIG_BT_AICS) - case BTP_SERVICE_ID_AICS: - tester_handle_aics(cmd->hdr.opcode, cmd->hdr.index, - cmd->hdr.data, len); - break; -#endif /* CONFIG_BT_AICS */ -#if defined(CONFIG_BT_VOCS) - case BTP_SERVICE_ID_VOCS: - tester_handle_vocs(cmd->hdr.opcode, cmd->hdr.index, - cmd->hdr.data, len); - break; -#endif /* CONFIG_BT_VOCS */ + if (status != BTP_STATUS_DELAY_REPLY) { + if ((status == BTP_STATUS_SUCCESS) && rsp_len > 0) { + tester_send(cmd->hdr.service, cmd->hdr.opcode, + cmd->hdr.index, cmd->rsp, rsp_len); + } else { #if defined(CONFIG_BT_PACS) case BTP_SERVICE_ID_PACS: tester_handle_pacs(cmd->hdr.opcode, cmd->hdr.index, cmd->hdr.data, len); break; #endif /* CONFIG_BT_PACS */ - default: - LOG_WRN("unknown service: 0x%x", cmd->hdr.service); - tester_rsp(cmd->hdr.service, cmd->hdr.opcode, - cmd->hdr.index, BTP_STATUS_FAILED); - break; + tester_rsp(cmd->hdr.service, cmd->hdr.opcode, + cmd->hdr.index, status); + } } + (void)memset(cmd, 0, sizeof(*cmd)); k_fifo_put(&avail_queue, cmd); } } @@ -217,6 +225,9 @@ void tester_init(void) uart_init(buf->data); + /* core service is always available */ + tester_init_core(); + tester_send(BTP_SERVICE_ID_CORE, BTP_CORE_EV_IUT_READY, BTP_INDEX_NONE, NULL, 0); } @@ -229,7 +240,7 @@ void tester_send(uint8_t service, uint8_t opcode, uint8_t index, uint8_t *data, msg.service = service; msg.opcode = opcode; msg.index = index; - msg.len = len; + msg.len = sys_cpu_to_le16(len); uart_send((uint8_t *)&msg, sizeof(msg)); if (data && len) { diff --git a/tests/bluetooth/tester/src/btp/btp.h b/tests/bluetooth/tester/src/btp/btp.h index db29345f9d9d..4fe47e85a4b7 100644 --- a/tests/bluetooth/tester/src/btp/btp.h +++ b/tests/bluetooth/tester/src/btp/btp.h @@ -40,12 +40,18 @@ #define BTP_SERVICE_ID_AICS 10 #define BTP_SERVICE_ID_VOCS 11 #define BTP_SERVICE_ID_PACS 12 +#define BTP_SERVICE_ID_MAX BTP_SERVICE_ID_PACS #define BTP_STATUS_SUCCESS 0x00 #define BTP_STATUS_FAILED 0x01 #define BTP_STATUS_UNKNOWN_CMD 0x02 #define BTP_STATUS_NOT_READY 0x03 +/* TODO indicate delay response, should be removed when all commands are + * converted to cmd+status+ev pattern + */ +#define BTP_STATUS_DELAY_REPLY 0xFF + struct btp_hdr { uint8_t service; uint8_t opcode; diff --git a/tests/bluetooth/tester/src/btp/btp_gap.h b/tests/bluetooth/tester/src/btp/btp_gap.h index d56398f86eb8..a138cdb4b5ff 100644 --- a/tests/bluetooth/tester/src/btp/btp_gap.h +++ b/tests/bluetooth/tester/src/btp/btp_gap.h @@ -104,6 +104,12 @@ struct btp_gap_start_advertising_cmd { uint8_t adv_data_len; uint8_t scan_rsp_len; uint8_t adv_sr_data[]; +/* + * This command is very unfortunate because it has two fields after variable + * data. Those needs to be handled explicitly by handler. + * uint32_t duration; + * uint8_t own_addr_type; + */ } __packed; struct btp_gap_start_advertising_rp { uint32_t current_settings; @@ -132,6 +138,7 @@ struct btp_gap_start_discovery_cmd { struct btp_gap_connect_cmd { uint8_t address_type; uint8_t address[6]; + uint8_t own_addr_type; } __packed; #define BTP_GAP_DISCONNECT 0x0f diff --git a/tests/bluetooth/tester/src/btp/bttester.h b/tests/bluetooth/tester/src/btp/bttester.h index c2e067b137d2..402668d7f0ff 100644 --- a/tests/bluetooth/tester/src/btp/bttester.h +++ b/tests/bluetooth/tester/src/btp/bttester.h @@ -10,6 +10,7 @@ #include #include #include +#include static inline void tester_set_bit(uint8_t *addr, unsigned int bit) { @@ -30,6 +31,17 @@ void tester_rsp(uint8_t service, uint8_t opcode, uint8_t index, uint8_t status); void tester_send(uint8_t service, uint8_t opcode, uint8_t index, uint8_t *data, size_t len); +struct btp_handler { + uint8_t opcode; + ssize_t expect_len; + uint8_t (*func)(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len); +}; + +void tester_register_command_handlers(uint8_t service, + const struct btp_handler *handlers, + size_t num); + uint8_t tester_init_gatt(void); uint8_t tester_unregister_gatt(void); void tester_handle_gatt(uint8_t opcode, uint8_t index, uint8_t *data, @@ -52,11 +64,8 @@ void tester_handle_vocs(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t l uint8_t tester_init_gap(void); uint8_t tester_unregister_gap(void); -void tester_handle_gap(uint8_t opcode, uint8_t index, uint8_t *data, - uint16_t len); -void tester_handle_core(uint8_t opcode, uint8_t index, uint8_t *data, - uint16_t len); +void tester_init_core(void); uint8_t tester_init_bap(void); uint8_t tester_unregister_bap(void); diff --git a/tests/bluetooth/tester/src/btp_core.c b/tests/bluetooth/tester/src/btp_core.c index a4a5b43e8373..f5700de96197 100644 --- a/tests/bluetooth/tester/src/btp_core.c +++ b/tests/bluetooth/tester/src/btp_core.c @@ -28,61 +28,87 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "btp/btp.h" -static void supported_commands(uint8_t *data, uint16_t len) +static ATOMIC_DEFINE(registered_services, BTP_SERVICE_ID_MAX); + +static uint8_t supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - uint8_t buf[1]; - struct btp_core_read_supported_commands_rp *rp = (void *) buf; + struct btp_core_read_supported_commands_rp *rp = rsp; + + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } - (void)memset(buf, 0, sizeof(buf)); + tester_set_bit(rp->data, BTP_CORE_READ_SUPPORTED_COMMANDS); + tester_set_bit(rp->data, BTP_CORE_READ_SUPPORTED_SERVICES); + tester_set_bit(rp->data, BTP_CORE_REGISTER_SERVICE); + tester_set_bit(rp->data, BTP_CORE_UNREGISTER_SERVICE); - tester_set_bit(buf, BTP_CORE_READ_SUPPORTED_COMMANDS); - tester_set_bit(buf, BTP_CORE_READ_SUPPORTED_SERVICES); - tester_set_bit(buf, BTP_CORE_REGISTER_SERVICE); - tester_set_bit(buf, BTP_CORE_UNREGISTER_SERVICE); + *rsp_len = sizeof(*rp) + 1; - tester_send(BTP_SERVICE_ID_CORE, BTP_CORE_READ_SUPPORTED_COMMANDS, - BTP_INDEX_NONE, (uint8_t *) rp, sizeof(buf)); + return BTP_STATUS_SUCCESS; } -static void supported_services(uint8_t *data, uint16_t len) +static uint8_t supported_services(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - uint8_t buf[2]; - struct btp_core_read_supported_services_rp *rp = (void *) buf; + struct btp_core_read_supported_services_rp *rp = rsp; - (void)memset(buf, 0, sizeof(buf)); + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } - tester_set_bit(buf, BTP_SERVICE_ID_CORE); - tester_set_bit(buf, BTP_SERVICE_ID_GAP); - tester_set_bit(buf, BTP_SERVICE_ID_GATT); + /* octet 0 */ + tester_set_bit(rp->data, BTP_SERVICE_ID_CORE); + tester_set_bit(rp->data, BTP_SERVICE_ID_GAP); + tester_set_bit(rp->data, BTP_SERVICE_ID_GATT); #if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL) - tester_set_bit(buf, BTP_SERVICE_ID_L2CAP); + tester_set_bit(rp->data, BTP_SERVICE_ID_L2CAP); #endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */ #if defined(CONFIG_BT_MESH) - tester_set_bit(buf, BTP_SERVICE_ID_MESH); + tester_set_bit(rp->data, BTP_SERVICE_ID_MESH); #endif /* CONFIG_BT_MESH */ + + /* octet 1 */ #if defined(CONFIG_BT_VCP_VOL_REND) - tester_set_bit(buf, BTP_SERVICE_ID_VCS); + tester_set_bit(rp->data, BTP_SERVICE_ID_VCS); #endif /* CONFIG_BT_VCP_VOL_REND */ #if defined(CONFIG_BT_IAS) || defined(CONFIG_BT_IAS_CLIENT) - tester_set_bit(buf, BTP_SERVICE_ID_IAS); + tester_set_bit(rp->data, BTP_SERVICE_ID_IAS); #endif /* CONFIG_BT_IAS */ #if defined(CONFIG_BT_AICS) || defined(CONFIG_BT_AICS_CLIENT) - tester_set_bit(buf, BTP_SERVICE_ID_AICS); + tester_set_bit(rp->data, BTP_SERVICE_ID_AICS); #endif /*CONFIG_BT_AICS */ #if defined(CONFIG_BT_VOCS) || defined(CONFIG_BT_VOCS_CLIENT) - tester_set_bit(buf, BTP_SERVICE_ID_VOCS); + tester_set_bit(rp->data, BTP_SERVICE_ID_VOCS); #endif /* CONFIG_BT_VOCS */ - tester_send(BTP_SERVICE_ID_CORE, BTP_CORE_READ_SUPPORTED_SERVICES, - BTP_INDEX_NONE, (uint8_t *) rp, sizeof(buf)); + *rsp_len = sizeof(*rp) + 2; + + return BTP_STATUS_SUCCESS; } -static void register_service(uint8_t *data, uint16_t len) +static uint8_t register_service(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_core_register_service_cmd *cmd = (void *) data; + const struct btp_core_register_service_cmd *cp = cmd; uint8_t status; - switch (cmd->id) { + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } + + /* invalid service */ + if ((cp->id == BTP_SERVICE_ID_CORE) || (cp->id > BTP_SERVICE_ID_MAX)) { + return BTP_STATUS_FAILED; + } + + /* already registered */ + if (atomic_test_bit(registered_services, cp->id)) { + return BTP_STATUS_FAILED; + } + + switch (cp->id) { case BTP_SERVICE_ID_GAP: status = tester_init_gap(); break; @@ -125,22 +151,39 @@ static void register_service(uint8_t *data, uint16_t len) break; #endif /* CONFIG_BT_PACS */ default: - LOG_WRN("unknown id: 0x%02x", cmd->id); + LOG_WRN("unknown id: 0x%02x", cp->id); status = BTP_STATUS_FAILED; break; } -rsp: - tester_rsp(BTP_SERVICE_ID_CORE, BTP_CORE_REGISTER_SERVICE, BTP_INDEX_NONE, - status); + if (status == BTP_STATUS_SUCCESS) { + atomic_set_bit(registered_services, cp->id); + } + + return status; } -static void unregister_service(uint8_t *data, uint16_t len) +static uint8_t unregister_service(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_core_unregister_service_cmd *cmd = (void *) data; + const struct btp_core_unregister_service_cmd *cp = cmd; uint8_t status; - switch (cmd->id) { + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } + + /* invalid service ID */ + if ((cp->id == BTP_SERVICE_ID_CORE) || (cp->id > BTP_SERVICE_ID_MAX)) { + return BTP_STATUS_FAILED; + } + + /* not registered */ + if (!atomic_test_bit(registered_services, cp->id)) { + return BTP_STATUS_FAILED; + } + + switch (cp->id) { case BTP_SERVICE_ID_GAP: status = tester_unregister_gap(); break; @@ -178,41 +221,44 @@ static void unregister_service(uint8_t *data, uint16_t len) break; #endif /* CONFIG_BT_PACS */ default: - LOG_WRN("unknown id: 0x%x", cmd->id); + LOG_WRN("unknown id: 0x%x", cp->id); status = BTP_STATUS_FAILED; break; } - tester_rsp(BTP_SERVICE_ID_CORE, BTP_CORE_UNREGISTER_SERVICE, BTP_INDEX_NONE, - status); + if (status == BTP_STATUS_SUCCESS) { + atomic_clear_bit(registered_services, cp->id); + } + + return BTP_STATUS_FAILED; } -void tester_handle_core(uint8_t opcode, uint8_t index, uint8_t *data, - uint16_t len) -{ - if (index != BTP_INDEX_NONE) { - LOG_WRN("index != BTP_INDEX_NONE: 0x%x", index); - tester_rsp(BTP_SERVICE_ID_CORE, opcode, index, BTP_STATUS_FAILED); - return; - } +static const struct btp_handler handlers[] = { + { + .opcode = BTP_CORE_READ_SUPPORTED_COMMANDS, + .expect_len = 0, + .func = supported_commands, + }, + { + .opcode = BTP_CORE_READ_SUPPORTED_SERVICES, + .expect_len = 0, + .func = supported_services, + }, + { + .opcode = BTP_CORE_REGISTER_SERVICE, + .expect_len = sizeof(struct btp_core_register_service_cmd), + .func = register_service, + }, + { + .opcode = BTP_CORE_UNREGISTER_SERVICE, + .expect_len = sizeof(struct btp_core_unregister_service_cmd), + .func = unregister_service, + }, +}; - switch (opcode) { - case BTP_CORE_READ_SUPPORTED_COMMANDS: - supported_commands(data, len); - return; - case BTP_CORE_READ_SUPPORTED_SERVICES: - supported_services(data, len); - return; - case BTP_CORE_REGISTER_SERVICE: - register_service(data, len); - return; - case BTP_CORE_UNREGISTER_SERVICE: - unregister_service(data, len); - return; - default: - LOG_WRN("unknown opcode: 0x%x", opcode); - tester_rsp(BTP_SERVICE_ID_CORE, opcode, BTP_INDEX_NONE, - BTP_STATUS_UNKNOWN_CMD); - return; - } +void tester_init_core(void) +{ + tester_register_command_handlers(BTP_SERVICE_ID_CORE, handlers, + ARRAY_SIZE(handlers)); + atomic_set_bit(registered_services, BTP_SERVICE_ID_CORE); } diff --git a/tests/bluetooth/tester/src/btp_gap.c b/tests/bluetooth/tester/src/btp_gap.c index ef1994de1592..cfe2258c9b18 100644 --- a/tests/bluetooth/tester/src/btp_gap.c +++ b/tests/bluetooth/tester/src/btp_gap.c @@ -309,13 +309,14 @@ static void controller_info(uint8_t *data, uint16_t len) supported_settings |= BIT(BTP_GAP_SETTINGS_LE); supported_settings |= BIT(BTP_GAP_SETTINGS_ADVERTISING); - rp.supported_settings = sys_cpu_to_le32(supported_settings); - rp.current_settings = sys_cpu_to_le32(current_settings); + rp->supported_settings = sys_cpu_to_le32(supported_settings); + rp->current_settings = sys_cpu_to_le32(current_settings); - memcpy(rp.name, CONTROLLER_NAME, sizeof(CONTROLLER_NAME)); + memcpy(rp->name, CONTROLLER_NAME, sizeof(CONTROLLER_NAME)); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_READ_CONTROLLER_INFO, - CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); + *rsp_len = sizeof(*rp); + + return BTP_STATUS_SUCCESS; } #if !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) @@ -410,52 +411,69 @@ static void oob_data_request(struct bt_conn *conn, } #if !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) -static void get_oob_sc_local_data(void) +static uint8_t get_oob_sc_local_data(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { + struct btp_gap_oob_sc_get_local_data_rp *rp = rsp; + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + cb.oob_data_request = oob_data_request; - struct btp_gap_oob_sc_get_local_data_rp rp = { 0 }; - memcpy(&rp.conf[0], &oob_sc_local.le_sc_data.c[0], sizeof(rp.conf)); - memcpy(&rp.rand[0], &oob_sc_local.le_sc_data.r[0], sizeof(rp.rand)); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_OOB_SC_GET_LOCAL_DATA, - CONTROLLER_INDEX, (uint8_t *)&rp, sizeof(rp)); + memcpy(rp->conf, &oob_sc_local.le_sc_data.c[0], sizeof(rp->conf)); + memcpy(rp->rand, &oob_sc_local.le_sc_data.r[0], sizeof(rp->rand)); + + *rsp_len = sizeof(*rp); + return BTP_STATUS_SUCCESS; } -static void set_oob_sc_remote_data(const uint8_t *data, uint16_t len) +static uint8_t set_oob_sc_remote_data(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { + const struct btp_gap_oob_sc_set_remote_data_cmd *cp = cmd; + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + cb.oob_data_request = oob_data_request; bt_set_oob_data_flag(true); - const struct btp_gap_oob_sc_set_remote_data_cmd *cmd = (void *)data; - /* Note that the .addr field * will be set by the oob_data_request callback */ - memcpy(&oob_sc_remote.le_sc_data.r[0], &cmd->rand[0], + memcpy(&oob_sc_remote.le_sc_data.r[0], cp->rand, sizeof(oob_sc_remote.le_sc_data.r)); - memcpy(&oob_sc_remote.le_sc_data.c[0], &cmd->conf[0], + memcpy(&oob_sc_remote.le_sc_data.c[0], cp->conf, sizeof(oob_sc_remote.le_sc_data.c)); - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_OOB_SC_SET_REMOTE_DATA, - CONTROLLER_INDEX, BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } #endif /* !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) */ -static void set_connectable(uint8_t *data, uint16_t len) +static uint8_t set_connectable(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gap_set_connectable_cmd *cmd = (void *) data; - struct btp_gap_set_connectable_rp rp; + const struct btp_gap_set_connectable_cmd *cp = cmd; + struct btp_gap_set_connectable_rp *rp = rsp; + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } - if (cmd->connectable) { + if (cp->connectable) { atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_CONNECTABLE); } else { atomic_clear_bit(¤t_settings, BTP_GAP_SETTINGS_CONNECTABLE); } - rp.current_settings = sys_cpu_to_le32(current_settings); + rp->current_settings = sys_cpu_to_le32(current_settings); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_SET_CONNECTABLE, CONTROLLER_INDEX, - (uint8_t *) &rp, sizeof(rp)); + *rsp_len = sizeof(*rp); + + return BTP_STATUS_SUCCESS; } static uint8_t ad_flags = BT_LE_AD_NO_BREDR; @@ -464,12 +482,17 @@ static struct bt_data ad[10] = { }; static struct bt_data sd[10]; -static void set_discoverable(uint8_t *data, uint16_t len) +static uint8_t set_discoverable(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gap_set_discoverable_cmd *cmd = (void *) data; - struct btp_gap_set_discoverable_rp rp; + const struct btp_gap_set_discoverable_cmd *cp = cmd; + struct btp_gap_set_discoverable_rp *rp = rsp; - switch (cmd->discoverable) { + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + switch (cp->discoverable) { case BTP_GAP_NON_DISCOVERABLE: ad_flags &= ~(BT_LE_AD_GENERAL | BT_LE_AD_LIMITED); atomic_clear_bit(¤t_settings, BTP_GAP_SETTINGS_DISCOVERABLE); @@ -485,100 +508,150 @@ static void set_discoverable(uint8_t *data, uint16_t len) atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_DISCOVERABLE); break; default: - LOG_WRN("unknown mode: 0x%x", cmd->discoverable); - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_SET_DISCOVERABLE, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - return; + return BTP_STATUS_FAILED; } - rp.current_settings = sys_cpu_to_le32(current_settings); + rp->current_settings = sys_cpu_to_le32(current_settings); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_SET_DISCOVERABLE, CONTROLLER_INDEX, - (uint8_t *) &rp, sizeof(rp)); + *rsp_len = sizeof(*rp); + return BTP_STATUS_SUCCESS; } -static void set_bondable(uint8_t *data, uint16_t len) +static uint8_t set_bondable(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gap_set_bondable_cmd *cmd = (void *) data; - struct btp_gap_set_bondable_rp rp; + const struct btp_gap_set_bondable_cmd *cp = cmd; + struct btp_gap_set_bondable_rp *rp = rsp; - LOG_DBG("cmd->bondable: %d", cmd->bondable); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + LOG_DBG("bondable: %d", cp->bondable); - if (cmd->bondable) { + if (cp->bondable) { atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_BONDABLE); } else { atomic_clear_bit(¤t_settings, BTP_GAP_SETTINGS_BONDABLE); } - bt_set_bondable(cmd->bondable); - - rp.current_settings = sys_cpu_to_le32(current_settings); + bt_set_bondable(cp->bondable); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_SET_BONDABLE, CONTROLLER_INDEX, - (uint8_t *) &rp, sizeof(rp)); + rp->current_settings = sys_cpu_to_le32(current_settings); + *rsp_len = sizeof(*rp); + return BTP_STATUS_SUCCESS; } -static void start_advertising(const uint8_t *data, uint16_t len) +static uint8_t start_advertising(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gap_start_advertising_cmd *cmd = (void *) data; - struct btp_gap_start_advertising_rp rp; - uint8_t adv_len, sd_len; - bool adv_conn; + const struct btp_gap_start_advertising_cmd *cp = cmd; + struct btp_gap_start_advertising_rp *rp = rsp; + struct bt_le_adv_param param = BT_LE_ADV_PARAM_INIT(0, + BT_GAP_ADV_FAST_INT_MIN_2, + BT_GAP_ADV_FAST_INT_MAX_2, + NULL); + uint8_t own_addr_type; + uint32_t duration; + uint8_t adv_len; + uint8_t sd_len; int i; - for (i = 0, adv_len = 1U; i < cmd->adv_data_len; adv_len++) { + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + /* This command is very unfortunate since after variable data there is + * additional 5 bytes (4 bytes for duration, 1 byte for own address + * type. + */ + if ((cmd_len < sizeof(*cp)) || + (cmd_len != sizeof(*cp) + cp->adv_data_len + cp->scan_rsp_len + + sizeof(duration) + sizeof(own_addr_type))) { + return BTP_STATUS_FAILED; + } + + /* currently ignored */ + duration = sys_get_le32(cp->adv_sr_data + cp->adv_data_len + cp->scan_rsp_len); + (void)duration; + own_addr_type = cp->adv_sr_data[cp->adv_data_len + cp->scan_rsp_len + sizeof(duration)]; + + for (i = 0, adv_len = 1U; i < cp->adv_data_len; adv_len++) { if (adv_len >= ARRAY_SIZE(ad)) { LOG_ERR("ad[] Out of memory"); - goto fail; + return BTP_STATUS_FAILED; } - ad[adv_len].type = cmd->adv_sr_data[i++]; - ad[adv_len].data_len = cmd->adv_sr_data[i++]; - ad[adv_len].data = &cmd->adv_sr_data[i]; + ad[adv_len].type = cp->adv_sr_data[i++]; + ad[adv_len].data_len = cp->adv_sr_data[i++]; + ad[adv_len].data = &cp->adv_sr_data[i]; i += ad[adv_len].data_len; } - for (sd_len = 0U; i < cmd->adv_data_len+cmd->scan_rsp_len; sd_len++) { + for (sd_len = 0U; i < cp->adv_data_len + cp->scan_rsp_len; sd_len++) { if (sd_len >= ARRAY_SIZE(sd)) { LOG_ERR("sd[] Out of memory"); - goto fail; + return BTP_STATUS_FAILED; } - sd[sd_len].type = cmd->adv_sr_data[i++]; - sd[sd_len].data_len = cmd->adv_sr_data[i++]; - sd[sd_len].data = &cmd->adv_sr_data[i]; + sd[sd_len].type = cp->adv_sr_data[i++]; + sd[sd_len].data_len = cp->adv_sr_data[i++]; + sd[sd_len].data = &cp->adv_sr_data[i]; i += sd[sd_len].data_len; } - adv_conn = atomic_test_bit(¤t_settings, BTP_GAP_SETTINGS_CONNECTABLE); + if (atomic_test_bit(¤t_settings, BTP_GAP_SETTINGS_CONNECTABLE)) { + param.options |= BT_LE_ADV_OPT_CONNECTABLE; + } + + switch (own_addr_type) { + case 0x00: + param.options |= BT_LE_ADV_OPT_USE_IDENTITY; + break; +#if defined(CONFIG_BT_PRIVACY) + case 0x01: + /* RPA usage is is controlled via privacy settings */ + if (!atomic_test_bit(¤t_settings, BTP_GAP_SETTINGS_PRIVACY)) { + return BTP_STATUS_FAILED; + } + break; + case 0x02: + /* NRPA is used only for non-connectable advertising */ + if (atomic_test_bit(¤t_settings, BTP_GAP_SETTINGS_CONNECTABLE)) { + return BTP_STATUS_FAILED; + } + break; +#endif + default: + return BTP_STATUS_FAILED; + } /* BTP API don't allow to set empty scan response data. */ - if (bt_le_adv_start(adv_conn ? BT_LE_ADV_CONN : BT_LE_ADV_NCONN, - ad, adv_len, sd_len ? sd : NULL, sd_len) < 0) { + if (bt_le_adv_start(¶m, ad, adv_len, sd_len ? sd : NULL, sd_len) < 0) { LOG_ERR("Failed to start advertising"); - goto fail; + return BTP_STATUS_FAILED; } atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_ADVERTISING); - rp.current_settings = sys_cpu_to_le32(current_settings); - - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_START_ADVERTISING, CONTROLLER_INDEX, - (uint8_t *) &rp, sizeof(rp)); - return; -fail: - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_START_ADVERTISING, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + rp->current_settings = sys_cpu_to_le32(current_settings); + + *rsp_len = sizeof(*rp); + return BTP_STATUS_SUCCESS; } -static void start_directed_advertising(const uint8_t *data, uint16_t len) +static uint8_t start_directed_advertising(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gap_start_directed_adv_cmd *cmd = (void *)data; - struct btp_gap_start_directed_adv_rp rp; + const struct btp_gap_start_directed_adv_cmd *cp = cmd; + struct btp_gap_start_directed_adv_rp *rp = rsp; struct bt_le_adv_param adv_param; - uint16_t options = sys_le16_to_cpu(cmd->options); - const bt_addr_le_t *peer = (bt_addr_le_t *)data; + uint16_t options = sys_le16_to_cpu(cp->options); + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } - adv_param = *BT_LE_ADV_CONN_DIR(peer); + adv_param = *BT_LE_ADV_CONN_DIR(&cp->address); if (!(options & BTP_GAP_START_DIRECTED_ADV_HD)) { adv_param.options |= BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY; @@ -601,38 +674,39 @@ static void start_directed_advertising(const uint8_t *data, uint16_t len) if (bt_le_adv_start(&adv_param, NULL, 0, NULL, 0) < 0) { LOG_ERR("Failed to start advertising"); - goto fail; + return BTP_STATUS_FAILED; } atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_ADVERTISING); - rp.current_settings = sys_cpu_to_le32(current_settings); - - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_START_DIRECTED_ADV, - CONTROLLER_INDEX, (uint8_t *)&rp, sizeof(rp)); - return; -fail: - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_START_DIRECTED_ADV, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + rp->current_settings = sys_cpu_to_le32(current_settings); + + *rsp_len = sizeof(*rp); + return BTP_STATUS_SUCCESS; } -static void stop_advertising(const uint8_t *data, uint16_t len) +static uint8_t stop_advertising(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_gap_stop_advertising_rp rp; + struct btp_gap_stop_advertising_rp *rp = rsp; int err; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + err = bt_le_adv_stop(); if (err < 0) { tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_STOP_ADVERTISING, CONTROLLER_INDEX, BTP_STATUS_FAILED); LOG_ERR("Failed to stop advertising: %d", err); - return; + return BTP_STATUS_FAILED; } atomic_clear_bit(¤t_settings, BTP_GAP_SETTINGS_ADVERTISING); - rp.current_settings = sys_cpu_to_le32(current_settings); + rp->current_settings = sys_cpu_to_le32(current_settings); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_STOP_ADVERTISING, CONTROLLER_INDEX, - (uint8_t *) &rp, sizeof(rp)); + *rsp_len = sizeof(*rp); + return BTP_STATUS_SUCCESS; } static uint8_t get_ad_flags(struct net_buf_simple *ad) @@ -763,65 +837,70 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t evtype, net_buf_simple_reset(adv_buf); } -static void start_discovery(const uint8_t *data, uint16_t len) +static uint8_t start_discovery(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gap_start_discovery_cmd *cmd = (void *) data; - uint8_t status; + const struct btp_gap_start_discovery_cmd *cp = cmd; + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } /* only LE scan is supported */ - if (cmd->flags & BTP_GAP_DISCOVERY_FLAG_BREDR) { - status = BTP_STATUS_FAILED; + if (cp->flags & BTP_GAP_DISCOVERY_FLAG_BREDR) { LOG_WRN("BR/EDR not supported"); - goto reply; + return BTP_STATUS_FAILED; } - if (bt_le_scan_start(cmd->flags & BTP_GAP_DISCOVERY_FLAG_LE_ACTIVE_SCAN ? + if (bt_le_scan_start(cp->flags & BTP_GAP_DISCOVERY_FLAG_LE_ACTIVE_SCAN ? BT_LE_SCAN_ACTIVE : BT_LE_SCAN_PASSIVE, device_found) < 0) { - status = BTP_STATUS_FAILED; LOG_ERR("Failed to start scanning"); - goto reply; + return BTP_STATUS_FAILED; } net_buf_simple_init(adv_buf, 0); - discovery_flags = cmd->flags; + discovery_flags = cp->flags; - status = BTP_STATUS_SUCCESS; -reply: - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_START_DISCOVERY, CONTROLLER_INDEX, - status); + return BTP_STATUS_SUCCESS; } -static void stop_discovery(const uint8_t *data, uint16_t len) +static uint8_t stop_discovery(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - uint8_t status = BTP_STATUS_SUCCESS; int err; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + err = bt_le_scan_stop(); if (err < 0) { LOG_ERR("Failed to stop scanning: %d", err); - status = BTP_STATUS_FAILED; + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_STOP_DISCOVERY, CONTROLLER_INDEX, - status); + return BTP_STATUS_SUCCESS; } -static void connect(const uint8_t *data, uint16_t len) +static uint8_t connect(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const bt_addr_le_t *addr = (const bt_addr_le_t *)data; - uint8_t status; + const struct btp_gap_connect_cmd *cp = cmd; int err; - if (!bt_addr_le_eq(addr, BT_ADDR_LE_ANY)) { + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if (!bt_addr_le_eq(&cp->address, BT_ADDR_LE_ANY)) { struct bt_conn *conn; - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, + err = bt_conn_le_create(&cp->address, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, &conn); if (err) { LOG_ERR("Failed to create connection (%d)", err); - status = BTP_STATUS_FAILED; - goto rsp; + return BTP_STATUS_FAILED; } bt_conn_unref(conn); @@ -830,27 +909,28 @@ static void connect(const uint8_t *data, uint16_t len) BT_LE_CONN_PARAM_DEFAULT); if (err) { LOG_ERR("Failed to create auto connection (%d)", err); - status = BTP_STATUS_FAILED; - goto rsp; + return BTP_STATUS_FAILED; } } - status = BTP_STATUS_SUCCESS; - -rsp: - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_CONNECT, CONTROLLER_INDEX, status); + return BTP_STATUS_SUCCESS; } -static void disconnect(const uint8_t *data, uint16_t len) +static uint8_t disconnect(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { + const struct btp_gap_disconnect_cmd *cp = cmd; struct bt_conn *conn; uint8_t status; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - status = BTP_STATUS_FAILED; LOG_ERR("Unknown connection"); - goto rsp; + return BTP_STATUS_FAILED; } if (bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN)) { @@ -862,9 +942,7 @@ static void disconnect(const uint8_t *data, uint16_t len) bt_conn_unref(conn); -rsp: - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_DISCONNECT, CONTROLLER_INDEX, - status); + return status; } static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) @@ -962,18 +1040,22 @@ static struct bt_conn_auth_info_cb auth_info_cb = { .pairing_complete = auth_pairing_complete, }; -static void set_io_cap(const uint8_t *data, uint16_t len) +static uint8_t set_io_cap(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gap_set_io_cap_cmd *cmd = (void *) data; - uint8_t status; + const struct btp_gap_set_io_cap_cmd *cp = cmd; + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } /* Reset io cap requirements */ (void)memset(&cb, 0, sizeof(cb)); bt_conn_auth_cb_register(NULL); - LOG_DBG("io_cap: %d", cmd->io_cap); + LOG_DBG("io_cap: %d", cp->io_cap); - switch (cmd->io_cap) { + switch (cp->io_cap) { case BTP_GAP_IO_CAP_DISPLAY_ONLY: cb.cancel = auth_cancel; cb.passkey_display = auth_passkey_display; @@ -997,67 +1079,61 @@ static void set_io_cap(const uint8_t *data, uint16_t len) cb.passkey_confirm = auth_passkey_confirm; break; default: - LOG_WRN("Unhandled io_cap: 0x%x", cmd->io_cap); - status = BTP_STATUS_FAILED; - goto rsp; + LOG_WRN("Unhandled io_cap: 0x%x", cp->io_cap); + return BTP_STATUS_FAILED; } cb.pairing_accept = auth_pairing_accept; if (bt_conn_auth_cb_register(&cb)) { - status = BTP_STATUS_FAILED; - goto rsp; + return BTP_STATUS_FAILED; } - status = BTP_STATUS_SUCCESS; - -rsp: - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_SET_IO_CAP, CONTROLLER_INDEX, - status); + return BTP_STATUS_SUCCESS; } -static void pair(const uint8_t *data, uint16_t len) +static uint8_t pair(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { + const struct btp_gap_pair_cmd *cp = cmd; struct bt_conn *conn; - uint8_t status; int err; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { LOG_ERR("Unknown connection"); - status = BTP_STATUS_FAILED; - goto rsp; + return BTP_STATUS_FAILED; } err = bt_conn_set_security(conn, BT_SECURITY_L2); if (err < 0) { LOG_ERR("Failed to set security: %d", err); - status = BTP_STATUS_FAILED; bt_conn_unref(conn); - goto rsp; + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - status = BTP_STATUS_SUCCESS; - -rsp: - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_PAIR, CONTROLLER_INDEX, status); + return BTP_STATUS_SUCCESS; } -static void unpair(const uint8_t *data, uint16_t len) +static uint8_t unpair(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_gap_unpair_cmd *cmd = (void *) data; + const struct btp_gap_unpair_cmd *cp = cmd; struct bt_conn *conn; - bt_addr_le_t addr; - uint8_t status; int err; - addr.type = cmd->address_type; - memcpy(addr.a.val, cmd->address, sizeof(addr.a.val)); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &addr); + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - LOG_ERR("Unknown connection"); + LOG_INF("Unknown connection"); goto keys; } @@ -1067,59 +1143,63 @@ static void unpair(const uint8_t *data, uint16_t len) if (err < 0) { LOG_ERR("Failed to disconnect: %d", err); - status = BTP_STATUS_FAILED; - goto rsp; + return BTP_STATUS_FAILED; } keys: - err = bt_unpair(BT_ID_DEFAULT, &addr); + err = bt_unpair(BT_ID_DEFAULT, &cp->address); + if (err < 0) { + return BTP_STATUS_FAILED; + } - status = err < 0 ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS; -rsp: - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_UNPAIR, CONTROLLER_INDEX, status); + return BTP_STATUS_SUCCESS; } -static void passkey_entry(const uint8_t *data, uint16_t len) +static uint8_t passkey_entry(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gap_passkey_entry_cmd *cmd = (void *) data; + const struct btp_gap_passkey_entry_cmd *cp = cmd; struct bt_conn *conn; - uint8_t status; int err; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { LOG_ERR("Unknown connection"); - status = BTP_STATUS_FAILED; - goto rsp; + return BTP_STATUS_FAILED; } - err = bt_conn_auth_passkey_entry(conn, sys_le32_to_cpu(cmd->passkey)); + err = bt_conn_auth_passkey_entry(conn, sys_le32_to_cpu(cp->passkey)); + bt_conn_unref(conn); + if (err < 0) { LOG_ERR("Failed to enter passkey: %d", err); + return BTP_STATUS_FAILED; } - bt_conn_unref(conn); - status = err < 0 ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS; - -rsp: - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_PASSKEY_ENTRY, CONTROLLER_INDEX, - status); + return BTP_STATUS_SUCCESS; } -static void passkey_confirm(const uint8_t *data, uint16_t len) +static uint8_t passkey_confirm(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gap_passkey_confirm_cmd *cmd = (void *) data; + const struct btp_gap_passkey_confirm_cmd *cp = cmd; struct bt_conn *conn; - uint8_t status; int err; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { LOG_ERR("Unknown connection"); - status = BTP_STATUS_FAILED; - goto rsp; + return BTP_STATUS_FAILED; } - if (cmd->match) { + if (cp->match) { err = bt_conn_auth_passkey_confirm(conn); if (err < 0) { LOG_ERR("Failed to confirm passkey: %d", err); @@ -1132,204 +1212,228 @@ static void passkey_confirm(const uint8_t *data, uint16_t len) } bt_conn_unref(conn); - status = err < 0 ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS; -rsp: - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_PASSKEY_CONFIRM, CONTROLLER_INDEX, - status); -} + if (err < 0) { + return BTP_STATUS_FAILED; + } + return BTP_STATUS_SUCCESS; +} -static void conn_param_update(const uint8_t *data, uint16_t len) +static uint8_t conn_param_update(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gap_conn_param_update_cmd *cmd = (void *) data; + const struct btp_gap_conn_param_update_cmd *cp = cmd; struct bt_le_conn_param param = { - .interval_min = sys_le16_to_cpu(cmd->interval_min), - .interval_max = sys_le16_to_cpu(cmd->interval_max), - .latency = sys_le16_to_cpu(cmd->latency), - .timeout = sys_le16_to_cpu(cmd->timeout), + .interval_min = sys_le16_to_cpu(cp->interval_min), + .interval_max = sys_le16_to_cpu(cp->interval_max), + .latency = sys_le16_to_cpu(cp->latency), + .timeout = sys_le16_to_cpu(cp->timeout), }; struct bt_conn *conn; - uint8_t status = BTP_STATUS_FAILED; int err; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { LOG_ERR("Unknown connection"); - goto rsp; + return BTP_STATUS_FAILED; } err = bt_conn_le_param_update(conn, ¶m); + bt_conn_unref(conn); + if (err < 0) { LOG_ERR("Failed to update params: %d", err); + return BTP_STATUS_FAILED; } - - bt_conn_unref(conn); - status = err < 0 ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS; - -rsp: - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_CONN_PARAM_UPDATE, CONTROLLER_INDEX, - status); + return BTP_STATUS_SUCCESS; } -static void set_mitm(const uint8_t *data, uint16_t len) +static uint8_t set_mitm(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { + /* TODO verify if can be done in runtime */ LOG_WRN("Use CONFIG_BT_SMP_ENFORCE_MITM instead"); - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_SET_MITM, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; } -static void set_oob_legacy_data(const uint8_t *data, uint16_t len) +static uint8_t set_oob_legacy_data(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gap_oob_legacy_set_data_cmd *cmd = (void *) data; + const struct btp_gap_oob_legacy_set_data_cmd *cp = cmd; + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } - memcpy(oob_legacy_tk, cmd->oob_data, 16); + memcpy(oob_legacy_tk, cp->oob_data, 16); bt_set_oob_data_flag(true); cb.oob_data_request = oob_data_request; - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_OOB_LEGACY_SET_DATA, - CONTROLLER_INDEX, BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void set_filter_list(const uint8_t *data, uint16_t len) +static uint8_t set_filter_list(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gap_set_filter_list *cmd = (const void *) data; - uint8_t status; + const struct btp_gap_set_filter_list *cp = cmd; int err; - if (len < sizeof(*cmd) || - len != (sizeof(*cmd) + (cmd->cnt * sizeof(cmd->addr[0])))) { - status = BTP_STATUS_FAILED; - goto failed; + if ((cmd_len < sizeof(*cp)) || + (cmd_len != sizeof(*cp) + (cp->cnt * sizeof(cp->addr[0])))) { + return BTP_STATUS_FAILED; + } + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; } (void)bt_le_filter_accept_list_clear(); - for (int i = 0; i < cmd->cnt; i++) { - err = bt_le_filter_accept_list_add(&cmd->addr[i]); + for (int i = 0; i < cp->cnt; i++) { + err = bt_le_filter_accept_list_add(&cp->addr[i]); if (err < 0) { - status = BTP_STATUS_FAILED; - goto failed; + return BTP_STATUS_FAILED; } } - status = BTP_STATUS_SUCCESS; - -failed: - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_SET_FILTER_LIST, - CONTROLLER_INDEX, status); + return BTP_STATUS_SUCCESS; } -void tester_handle_gap(uint8_t opcode, uint8_t index, uint8_t *data, - uint16_t len) -{ - LOG_DBG("opcode: 0x%02x", opcode); - switch (opcode) { - case BTP_GAP_READ_SUPPORTED_COMMANDS: - case BTP_GAP_READ_CONTROLLER_INDEX_LIST: - if (index != BTP_INDEX_NONE){ - tester_rsp(BTP_SERVICE_ID_GAP, opcode, index, - BTP_STATUS_FAILED); - LOG_WRN("index != BTP_INDEX_NONE: opcode: 0x%x " - "index: 0x%x", opcode, index); - return; - } - break; - default: - if (index != CONTROLLER_INDEX){ - tester_rsp(BTP_SERVICE_ID_GAP, opcode, index, - BTP_STATUS_FAILED); - LOG_WRN("index != CONTROLLER_INDEX: opcode: 0x%x " - "index: 0x%x", opcode, index); - return; - } - break; - } - - switch (opcode) { - case BTP_GAP_READ_SUPPORTED_COMMANDS: - supported_commands(data, len); - return; - case BTP_GAP_READ_CONTROLLER_INDEX_LIST: - controller_index_list(data, len); - return; - case BTP_GAP_READ_CONTROLLER_INFO: - controller_info(data, len); - return; - case BTP_GAP_SET_CONNECTABLE: - set_connectable(data, len); - return; - case BTP_GAP_SET_DISCOVERABLE: - set_discoverable(data, len); - return; - case BTP_GAP_SET_BONDABLE: - set_bondable(data, len); - return; - case BTP_GAP_START_ADVERTISING: - start_advertising(data, len); - return; - case BTP_GAP_START_DIRECTED_ADV: - start_directed_advertising(data, len); - return; - case BTP_GAP_STOP_ADVERTISING: - stop_advertising(data, len); - return; - case BTP_GAP_START_DISCOVERY: - start_discovery(data, len); - return; - case BTP_GAP_STOP_DISCOVERY: - stop_discovery(data, len); - return; - case BTP_GAP_CONNECT: - connect(data, len); - return; - case BTP_GAP_DISCONNECT: - disconnect(data, len); - return; - case BTP_GAP_SET_IO_CAP: - set_io_cap(data, len); - return; - case BTP_GAP_PAIR: - pair(data, len); - return; - case BTP_GAP_UNPAIR: - unpair(data, len); - return; - case BTP_GAP_PASSKEY_ENTRY: - passkey_entry(data, len); - return; - case BTP_GAP_PASSKEY_CONFIRM: - passkey_confirm(data, len); - return; - case BTP_GAP_CONN_PARAM_UPDATE: - conn_param_update(data, len); - return; - case BTP_GAP_SET_MITM: - set_mitm(data, len); - return; - case BTP_GAP_OOB_LEGACY_SET_DATA: - set_oob_legacy_data(data, len); - return; +static const struct btp_handler handlers[] = { + { + .opcode = BTP_GAP_READ_SUPPORTED_COMMANDS, + .expect_len = 0, + .func = supported_commands, + }, + { + .opcode = BTP_GAP_READ_CONTROLLER_INDEX_LIST, + .expect_len = 0, + .func = controller_index_list, + }, + { + .opcode = BTP_GAP_READ_CONTROLLER_INFO, + .expect_len = 0, + .func = controller_info, + }, + { + .opcode = BTP_GAP_SET_CONNECTABLE, + .expect_len = sizeof(struct btp_gap_set_connectable_cmd), + .func = set_connectable, + }, + { + .opcode = BTP_GAP_SET_DISCOVERABLE, + .expect_len = sizeof(struct btp_gap_set_discoverable_cmd), + .func = set_discoverable, + }, + { + .opcode = BTP_GAP_SET_BONDABLE, + .expect_len = sizeof(struct btp_gap_set_bondable_cmd), + .func = set_bondable, + }, + { + .opcode = BTP_GAP_START_ADVERTISING, + .expect_len = -1, + .func = start_advertising, + }, + { + .opcode = BTP_GAP_START_DIRECTED_ADV, + .expect_len = sizeof(struct btp_gap_start_directed_adv_cmd), + .func = start_directed_advertising, + }, + { + .opcode = BTP_GAP_STOP_ADVERTISING, + .expect_len = 0, + .func = stop_advertising, + }, + { + .opcode = BTP_GAP_START_DISCOVERY, + .expect_len = sizeof(struct btp_gap_start_discovery_cmd), + .func = start_discovery, + }, + { + .opcode = BTP_GAP_STOP_DISCOVERY, + .expect_len = 0, + .func = stop_discovery, + }, + { + .opcode = BTP_GAP_CONNECT, + .expect_len = sizeof(struct btp_gap_connect_cmd), + .func = connect, + }, + { + .opcode = BTP_GAP_DISCONNECT, + .expect_len = sizeof(struct btp_gap_disconnect_cmd), + .func = disconnect, + }, + { + .opcode = BTP_GAP_SET_IO_CAP, + .expect_len = sizeof(struct btp_gap_set_io_cap_cmd), + .func = set_io_cap, + }, + { + .opcode = BTP_GAP_PAIR, + .expect_len = sizeof(struct btp_gap_pair_cmd), + .func = pair, + }, + { + .opcode = BTP_GAP_UNPAIR, + .expect_len = sizeof(struct btp_gap_unpair_cmd), + .func = unpair, + }, + { + .opcode = BTP_GAP_PASSKEY_ENTRY, + .expect_len = sizeof(struct btp_gap_passkey_entry_cmd), + .func = passkey_entry, + }, + { + .opcode = BTP_GAP_PASSKEY_CONFIRM, + .expect_len = sizeof(struct btp_gap_passkey_confirm_cmd), + .func = passkey_confirm, + }, + { + .opcode = BTP_GAP_CONN_PARAM_UPDATE, + .expect_len = sizeof(struct btp_gap_conn_param_update_cmd), + .func = conn_param_update, + }, + { + .opcode = BTP_GAP_SET_MITM, + .expect_len = sizeof(struct btp_gap_set_mitm), + .func = set_mitm, + }, + { + .opcode = BTP_GAP_OOB_LEGACY_SET_DATA, + .expect_len = sizeof(struct btp_gap_oob_legacy_set_data_cmd), + .func = set_oob_legacy_data, + }, #if !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) - case BTP_GAP_OOB_SC_GET_LOCAL_DATA: - get_oob_sc_local_data(); - return; - case BTP_GAP_OOB_SC_SET_REMOTE_DATA: - set_oob_sc_remote_data(data, len); - return; + { + .opcode = BTP_GAP_OOB_SC_GET_LOCAL_DATA, + .expect_len = 0, + .func = get_oob_sc_local_data, + }, + { + .opcode = BTP_GAP_OOB_SC_SET_REMOTE_DATA, + .expect_len = sizeof(struct btp_gap_oob_sc_set_remote_data_cmd), + .func = set_oob_sc_remote_data, + }, #endif /* !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) */ - case BTP_GAP_SET_FILTER_LIST: - set_filter_list(data, len); - return; - default: - LOG_WRN("Unknown opcode: 0x%x", opcode); - tester_rsp(BTP_SERVICE_ID_GAP, opcode, index, - BTP_STATUS_UNKNOWN_CMD); - return; - } -} + { + .opcode = BTP_GAP_SET_FILTER_LIST, + .expect_len = -1, + .func = set_filter_list, + }, +}; uint8_t tester_init_gap(void) { @@ -1360,6 +1464,9 @@ uint8_t tester_init_gap(void) bt_conn_cb_register(&conn_callbacks); bt_conn_auth_info_cb_register(&auth_info_cb); + tester_register_command_handlers(BTP_SERVICE_ID_GAP, handlers, + ARRAY_SIZE(handlers)); + return BTP_STATUS_SUCCESS; } From 2d53525ad2b895994d8e2e369cf3749cf6e4cfd1 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 21 Feb 2023 15:29:43 +0100 Subject: [PATCH 0024/1906] bluetooth: tester: Convert BTP to use bt_addr_le_t bt_addr_le_t matches BTP convention for addresses and it makes it so much better to handle those directly from command structures. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp/btp_gap.h | 68 ++++------ tests/bluetooth/tester/src/btp/btp_gatt.h | 63 +++------ tests/bluetooth/tester/src/btp/btp_l2cap.h | 18 +-- tests/bluetooth/tester/src/btp_gap.c | 149 +++++++++++---------- tests/bluetooth/tester/src/btp_gatt.c | 5 +- tests/bluetooth/tester/src/btp_l2cap.c | 20 ++- 6 files changed, 134 insertions(+), 189 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_gap.h b/tests/bluetooth/tester/src/btp/btp_gap.h index a138cdb4b5ff..986e82e90d34 100644 --- a/tests/bluetooth/tester/src/btp/btp_gap.h +++ b/tests/bluetooth/tester/src/btp/btp_gap.h @@ -42,7 +42,7 @@ struct btp_gap_read_controller_index_list_rp { #define BTP_GAP_READ_CONTROLLER_INFO 0x03 struct btp_gap_read_controller_info_rp { - uint8_t address[6]; + bt_addr_t address; uint32_t supported_settings; uint32_t current_settings; uint8_t cod[3]; @@ -136,15 +136,13 @@ struct btp_gap_start_discovery_cmd { #define BTP_GAP_CONNECT 0x0e struct btp_gap_connect_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint8_t own_addr_type; } __packed; #define BTP_GAP_DISCONNECT 0x0f struct btp_gap_disconnect_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; } __packed; #define BTP_GAP_IO_CAP_DISPLAY_ONLY 0 @@ -160,27 +158,23 @@ struct btp_gap_set_io_cap_cmd { #define BTP_GAP_PAIR 0x11 struct btp_gap_pair_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; } __packed; #define BTP_GAP_UNPAIR 0x12 struct btp_gap_unpair_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; } __packed; #define BTP_GAP_PASSKEY_ENTRY 0x13 struct btp_gap_passkey_entry_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint32_t passkey; } __packed; #define BTP_GAP_PASSKEY_CONFIRM 0x14 struct btp_gap_passkey_confirm_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint8_t match; } __packed; @@ -190,8 +184,7 @@ struct btp_gap_passkey_confirm_cmd { #define BTP_GAP_START_DIRECTED_ADV 0x15 struct btp_gap_start_directed_adv_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t options; } __packed; struct btp_gap_start_directed_adv_rp { @@ -200,8 +193,7 @@ struct btp_gap_start_directed_adv_rp { #define BTP_GAP_CONN_PARAM_UPDATE 0x16 struct btp_gap_conn_param_update_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t interval_min; uint16_t interval_max; uint16_t latency; @@ -210,8 +202,7 @@ struct btp_gap_conn_param_update_cmd { #define BTP_GAP_PAIRING_CONSENT 0x17 struct btp_gap_pairing_consent_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint8_t consent; } __packed; @@ -255,8 +246,7 @@ struct btp_gap_new_settings_ev { #define BTP_GAP_EV_DEVICE_FOUND 0x81 struct btp_gap_device_found_ev { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; int8_t rssi; uint8_t flags; uint16_t eir_data_len; @@ -265,8 +255,7 @@ struct btp_gap_device_found_ev { #define BTP_GAP_EV_DEVICE_CONNECTED 0x82 struct btp_gap_device_connected_ev { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t interval; uint16_t latency; uint16_t timeout; @@ -274,42 +263,35 @@ struct btp_gap_device_connected_ev { #define BTP_GAP_EV_DEVICE_DISCONNECTED 0x83 struct btp_gap_device_disconnected_ev { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; } __packed; #define BTP_GAP_EV_PASSKEY_DISPLAY 0x84 struct btp_gap_passkey_display_ev { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint32_t passkey; } __packed; #define BTP_GAP_EV_PASSKEY_ENTRY_REQ 0x85 struct btp_gap_passkey_entry_req_ev { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; } __packed; #define BTP_GAP_EV_PASSKEY_CONFIRM_REQ 0x86 struct btp_gap_passkey_confirm_req_ev { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint32_t passkey; } __packed; #define BTP_GAP_EV_IDENTITY_RESOLVED 0x87 struct btp_gap_identity_resolved_ev { - uint8_t address_type; - uint8_t address[6]; - uint8_t identity_address_type; - uint8_t identity_address[6]; + bt_addr_le_t address; + bt_addr_le_t identity_address; } __packed; #define BTP_GAP_EV_CONN_PARAM_UPDATE 0x88 struct btp_gap_conn_param_update_ev { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t interval; uint16_t latency; uint16_t timeout; @@ -321,26 +303,22 @@ struct btp_gap_conn_param_update_ev { #define BTP_GAP_EV_SEC_LEVEL_CHANGED 0x89 struct btp_gap_sec_level_changed_ev { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint8_t sec_level; } __packed; #define BTP_GAP_EV_PAIRING_CONSENT_REQ 0x8a struct btp_gap_pairing_consent_req_ev { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; } __packed; #define BTP_GAP_EV_BOND_LOST 0x8b struct btp_gap_bond_lost_ev { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; } __packed; #define BTP_GAP_EV_PAIRING_FAILED 0x8c struct btp_gap_bond_pairing_failed_ev { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint8_t reason; } __packed; diff --git a/tests/bluetooth/tester/src/btp/btp_gatt.h b/tests/bluetooth/tester/src/btp/btp_gatt.h index 65fe4f0e6440..32ea174112ec 100644 --- a/tests/bluetooth/tester/src/btp/btp_gatt.h +++ b/tests/bluetooth/tester/src/btp/btp_gatt.h @@ -111,14 +111,12 @@ struct btp_gatt_descriptor { #define BTP_GATT_EXCHANGE_MTU 0x0a struct btp_gatt_exchange_mtu_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; } __packed; #define BTP_GATT_DISC_ALL_PRIM 0x0b struct btp_gatt_disc_all_prim_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; } __packed; struct btp_gatt_disc_all_prim_rp { uint8_t services_count; @@ -127,8 +125,7 @@ struct btp_gatt_disc_all_prim_rp { #define BTP_GATT_DISC_PRIM_UUID 0x0c struct btp_gatt_disc_prim_uuid_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint8_t uuid_length; uint8_t uuid[]; } __packed; @@ -139,8 +136,7 @@ struct btp_gatt_disc_prim_rp { #define BTP_GATT_FIND_INCLUDED 0x0d struct btp_gatt_find_included_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t start_handle; uint16_t end_handle; } __packed; @@ -151,8 +147,7 @@ struct btp_gatt_find_included_rp { #define BTP_GATT_DISC_ALL_CHRC 0x0e struct btp_gatt_disc_all_chrc_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t start_handle; uint16_t end_handle; } __packed; @@ -163,8 +158,7 @@ struct btp_gatt_disc_chrc_rp { #define BTP_GATT_DISC_CHRC_UUID 0x0f struct btp_gatt_disc_chrc_uuid_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t start_handle; uint16_t end_handle; uint8_t uuid_length; @@ -173,8 +167,7 @@ struct btp_gatt_disc_chrc_uuid_cmd { #define BTP_GATT_DISC_ALL_DESC 0x10 struct btp_gatt_disc_all_desc_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t start_handle; uint16_t end_handle; } __packed; @@ -185,8 +178,7 @@ struct btp_gatt_disc_all_desc_rp { #define BTP_GATT_READ 0x11 struct btp_gatt_read_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t handle; } __packed; struct btp_gatt_read_rp { @@ -203,8 +195,7 @@ struct btp_gatt_char_value { #define BTP_GATT_READ_UUID 0x12 struct btp_gatt_read_uuid_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t start_handle; uint16_t end_handle; uint8_t uuid_length; @@ -218,8 +209,7 @@ struct btp_gatt_read_uuid_rp { #define BTP_GATT_READ_LONG 0x13 struct btp_gatt_read_long_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t handle; uint16_t offset; } __packed; @@ -231,8 +221,7 @@ struct btp_gatt_read_long_rp { #define BTP_GATT_READ_MULTIPLE 0x14 struct btp_gatt_read_multiple_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint8_t handles_count; uint16_t handles[]; } __packed; @@ -244,8 +233,7 @@ struct btp_gatt_read_multiple_rp { #define BTP_GATT_WRITE_WITHOUT_RSP 0x15 struct btp_gatt_write_without_rsp_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t handle; uint16_t data_length; uint8_t data[]; @@ -253,8 +241,7 @@ struct btp_gatt_write_without_rsp_cmd { #define BTP_GATT_SIGNED_WRITE_WITHOUT_RSP 0x16 struct btp_gatt_signed_write_without_rsp_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t handle; uint16_t data_length; uint8_t data[]; @@ -262,8 +249,7 @@ struct btp_gatt_signed_write_without_rsp_cmd { #define BTP_GATT_WRITE 0x17 struct btp_gatt_write_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t handle; uint16_t data_length; uint8_t data[]; @@ -274,8 +260,7 @@ struct btp_gatt_write_rp { #define BTP_GATT_WRITE_LONG 0x18 struct btp_gatt_write_long_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t handle; uint16_t offset; uint16_t data_length; @@ -287,8 +272,7 @@ struct btp_gatt_write_long_rp { #define BTP_GATT_RELIABLE_WRITE 0x19 struct btp_gatt_reliable_write_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t handle; uint16_t offset; uint16_t data_length; @@ -301,8 +285,7 @@ struct btp_gatt_reliable_write_rp { #define BTP_GATT_CFG_NOTIFY 0x1a #define BTP_GATT_CFG_INDICATE 0x1b struct btp_gatt_cfg_notify_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint8_t enable; uint16_t ccc_handle; } __packed; @@ -327,8 +310,7 @@ struct btp_gatt_attr { #define BTP_GATT_GET_ATTRIBUTE_VALUE 0x1d struct btp_gatt_get_attribute_value_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t handle; } __packed; struct btp_gatt_get_attribute_value_rp { @@ -345,8 +327,7 @@ struct btp_gatt_change_db_cmd { #define BTP_GATT_EATT_CONNECT 0x1f struct btp_gatt_eatt_connect_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint8_t num_channels; } __packed; @@ -354,16 +335,14 @@ struct btp_gatt_eatt_connect_cmd { #define BTP_GATT_NOTIFY_MULTIPLE 0x21 struct btp_gatt_cfg_notify_mult_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t cnt; uint16_t attr_id[]; } __packed; /* GATT events */ #define BTP_GATT_EV_NOTIFICATION 0x80 struct btp_gatt_notification_ev { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint8_t type; uint16_t handle; uint16_t data_length; diff --git a/tests/bluetooth/tester/src/btp/btp_l2cap.h b/tests/bluetooth/tester/src/btp/btp_l2cap.h index c6eedc5d7275..f01a8abe19d7 100644 --- a/tests/bluetooth/tester/src/btp/btp_l2cap.h +++ b/tests/bluetooth/tester/src/btp/btp_l2cap.h @@ -22,8 +22,7 @@ struct btp_l2cap_read_supported_commands_rp { #define BTP_L2CAP_CONNECT 0x02 struct btp_l2cap_connect_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t psm; uint16_t mtu; uint8_t num; @@ -70,8 +69,7 @@ struct btp_l2cap_accept_connection_cmd { #define BTP_L2CAP_RECONFIGURE 0x07 struct btp_l2cap_reconfigure_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint16_t mtu; uint8_t num; uint8_t chan_id[]; @@ -84,8 +82,7 @@ struct btp_l2cap_credits_cmd { #define BTP_L2CAP_DISCONNECT_EATT_CHANS 0x09 struct btp_l2cap_disconnect_eatt_chans_cmd { - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; uint8_t count; } __packed; @@ -94,8 +91,7 @@ struct btp_l2cap_disconnect_eatt_chans_cmd { struct btp_l2cap_connection_req_ev { uint8_t chan_id; uint16_t psm; - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; } __packed; #define BTP_L2CAP_EV_CONNECTED 0x81 @@ -106,8 +102,7 @@ struct btp_l2cap_connected_ev { uint16_t mps_remote; uint16_t mtu_local; uint16_t mps_local; - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; } __packed; #define BTP_L2CAP_EV_DISCONNECTED 0x82 @@ -115,8 +110,7 @@ struct btp_l2cap_disconnected_ev { uint16_t result; uint8_t chan_id; uint16_t psm; - uint8_t address_type; - uint8_t address[6]; + bt_addr_le_t address; } __packed; #define BTP_L2CAP_EV_DATA_RECEIVED 0x83 diff --git a/tests/bluetooth/tester/src/btp_gap.c b/tests/bluetooth/tester/src/btp_gap.c index cfe2258c9b18..3e1696b7b386 100644 --- a/tests/bluetooth/tester/src/btp_gap.c +++ b/tests/bluetooth/tester/src/btp_gap.c @@ -105,8 +105,7 @@ static void le_connected(struct bt_conn *conn, uint8_t err) bt_conn_get_info(conn, &info); - memcpy(ev.address, info.le.dst->a.val, sizeof(ev.address)); - ev.address_type = info.le.dst->type; + bt_addr_le_copy(&ev.address, info.le.dst); ev.interval = sys_cpu_to_le16(info.le.interval); ev.latency = sys_cpu_to_le16(info.le.latency); ev.timeout = sys_cpu_to_le16(info.le.timeout); @@ -120,8 +119,7 @@ static void le_disconnected(struct bt_conn *conn, uint8_t reason) struct btp_gap_device_disconnected_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); - memcpy(ev.address, addr->a.val, sizeof(ev.address)); - ev.address_type = addr->type; + bt_addr_le_copy(&ev.address, addr); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_DISCONNECTED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); @@ -132,12 +130,8 @@ static void le_identity_resolved(struct bt_conn *conn, const bt_addr_le_t *rpa, { struct btp_gap_identity_resolved_ev ev; - ev.address_type = rpa->type; - memcpy(ev.address, rpa->a.val, sizeof(ev.address)); - - ev.identity_address_type = identity->type; - memcpy(ev.identity_address, identity->a.val, - sizeof(ev.identity_address)); + bt_addr_le_copy(&ev.address, rpa); + bt_addr_le_copy(&ev.identity_address, identity); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_IDENTITY_RESOLVED, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); @@ -149,8 +143,7 @@ static void le_param_updated(struct bt_conn *conn, uint16_t interval, struct btp_gap_conn_param_update_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); - memcpy(ev.address, addr->a.val, sizeof(ev.address)); - ev.address_type = addr->type; + bt_addr_le_copy(&ev.address, addr); ev.interval = sys_cpu_to_le16(interval); ev.latency = sys_cpu_to_le16(latency); ev.timeout = sys_cpu_to_le16(timeout); @@ -182,8 +175,7 @@ static void le_security_changed(struct bt_conn *conn, bt_security_t level, switch (err) { case BT_SECURITY_ERR_SUCCESS: - memcpy(sec_ev.address, addr->a.val, sizeof(sec_ev.address)); - sec_ev.address_type = addr->type; + bt_addr_le_copy(&sec_ev.address, addr); /* enum matches BTP values */ sec_ev.sec_level = level; @@ -200,8 +192,7 @@ static void le_security_changed(struct bt_conn *conn, bt_security_t level, info.role == BT_CONN_ROLE_CENTRAL) { LOG_DBG("Bond lost"); - (void)memcpy(bond_ev.address, addr->a.val, sizeof(bond_ev.address)); - bond_ev.address_type = addr->type; + bt_addr_le_copy(&bond_ev.address, addr); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_BOND_LOST, CONTROLLER_INDEX, (uint8_t *)&bond_ev, sizeof(bond_ev)); @@ -223,68 +214,84 @@ static struct bt_conn_cb conn_callbacks = { .security_changed = le_security_changed, }; -static void supported_commands(uint8_t *data, uint16_t len) +static uint8_t supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - uint8_t cmds[4]; - struct btp_gap_read_supported_commands_rp *rp = (void *) &cmds; - - (void)memset(cmds, 0, sizeof(cmds)); - - tester_set_bit(cmds, BTP_GAP_READ_SUPPORTED_COMMANDS); - tester_set_bit(cmds, BTP_GAP_READ_CONTROLLER_INDEX_LIST); - tester_set_bit(cmds, BTP_GAP_READ_CONTROLLER_INFO); - tester_set_bit(cmds, BTP_GAP_SET_CONNECTABLE); - tester_set_bit(cmds, BTP_GAP_SET_DISCOVERABLE); - tester_set_bit(cmds, BTP_GAP_SET_BONDABLE); - tester_set_bit(cmds, BTP_GAP_START_ADVERTISING); - tester_set_bit(cmds, BTP_GAP_START_DIRECTED_ADV); - tester_set_bit(cmds, BTP_GAP_STOP_ADVERTISING); - tester_set_bit(cmds, BTP_GAP_START_DISCOVERY); - tester_set_bit(cmds, BTP_GAP_STOP_DISCOVERY); - tester_set_bit(cmds, BTP_GAP_CONNECT); - tester_set_bit(cmds, BTP_GAP_DISCONNECT); - tester_set_bit(cmds, BTP_GAP_SET_IO_CAP); - tester_set_bit(cmds, BTP_GAP_PAIR); - tester_set_bit(cmds, BTP_GAP_PASSKEY_ENTRY); - tester_set_bit(cmds, BTP_GAP_PASSKEY_CONFIRM); - tester_set_bit(cmds, BTP_GAP_CONN_PARAM_UPDATE); - tester_set_bit(cmds, BTP_GAP_SET_MITM); - tester_set_bit(cmds, BTP_GAP_OOB_LEGACY_SET_DATA); + struct btp_gap_read_supported_commands_rp *rp = rsp; + + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } + + /* octet 0 */ + tester_set_bit(rp->data, BTP_GAP_READ_SUPPORTED_COMMANDS); + tester_set_bit(rp->data, BTP_GAP_READ_CONTROLLER_INDEX_LIST); + tester_set_bit(rp->data, BTP_GAP_READ_CONTROLLER_INFO); + tester_set_bit(rp->data, BTP_GAP_SET_CONNECTABLE); + + /* octet 1 */ + tester_set_bit(rp->data, BTP_GAP_SET_DISCOVERABLE); + tester_set_bit(rp->data, BTP_GAP_SET_BONDABLE); + tester_set_bit(rp->data, BTP_GAP_START_ADVERTISING); + tester_set_bit(rp->data, BTP_GAP_STOP_ADVERTISING); + tester_set_bit(rp->data, BTP_GAP_START_DISCOVERY); + tester_set_bit(rp->data, BTP_GAP_STOP_DISCOVERY); + tester_set_bit(rp->data, BTP_GAP_CONNECT); + tester_set_bit(rp->data, BTP_GAP_DISCONNECT); + + /* octet 2 */ + tester_set_bit(rp->data, BTP_GAP_SET_IO_CAP); + tester_set_bit(rp->data, BTP_GAP_PAIR); + tester_set_bit(rp->data, BTP_GAP_PASSKEY_ENTRY); + tester_set_bit(rp->data, BTP_GAP_PASSKEY_CONFIRM); + tester_set_bit(rp->data, BTP_GAP_START_DIRECTED_ADV); + tester_set_bit(rp->data, BTP_GAP_CONN_PARAM_UPDATE); + + /* octet 3 */ + tester_set_bit(rp->data, BTP_GAP_OOB_LEGACY_SET_DATA); #if !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) - tester_set_bit(cmds, BTP_GAP_OOB_SC_GET_LOCAL_DATA); - tester_set_bit(cmds, BTP_GAP_OOB_SC_SET_REMOTE_DATA); + tester_set_bit(rp->data, BTP_GAP_OOB_SC_GET_LOCAL_DATA); + tester_set_bit(rp->data, BTP_GAP_OOB_SC_SET_REMOTE_DATA); #endif /* !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) */ - tester_set_bit(cmds, BTP_GAP_SET_FILTER_LIST); + tester_set_bit(rp->data, BTP_GAP_SET_MITM); + tester_set_bit(rp->data, BTP_GAP_SET_FILTER_LIST); + + *rsp_len = sizeof(*rp) + 4; - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_READ_SUPPORTED_COMMANDS, - CONTROLLER_INDEX, (uint8_t *) rp, sizeof(cmds)); + return BTP_STATUS_SUCCESS; } -static void controller_index_list(uint8_t *data, uint16_t len) +static uint8_t controller_index_list(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_gap_read_controller_index_list_rp *rp; - uint8_t buf[sizeof(*rp) + 1]; + struct btp_gap_read_controller_index_list_rp *rp = rsp; - rp = (void *) buf; + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } rp->num = 1U; rp->index[0] = CONTROLLER_INDEX; - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_READ_CONTROLLER_INDEX_LIST, - BTP_INDEX_NONE, (uint8_t *) rp, sizeof(buf)); + *rsp_len = sizeof(*rp) + 1; + + return BTP_STATUS_SUCCESS; } -static void controller_info(uint8_t *data, uint16_t len) +static uint8_t controller_info(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_gap_read_controller_info_rp rp; + struct btp_gap_read_controller_info_rp *rp = rsp; uint32_t supported_settings; - - (void)memset(&rp, 0, sizeof(rp)); - struct bt_le_oob oob_local = { 0 }; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + bt_le_oob_get_local(BT_ID_DEFAULT, &oob_local); - memcpy(rp.address, &oob_local.addr.a, sizeof(bt_addr_t)); + + bt_addr_copy(&rp->address, &oob_local.addr.a); /* * Re-use the oob data read here in get_oob_sc_local_data() @@ -663,7 +670,7 @@ static uint8_t start_directed_advertising(uint8_t index, const void *cmd, uint16 #if defined(CONFIG_BT_PRIVACY) /* check if peer supports Central Address Resolution */ for (int i = 0; i < CONFIG_BT_MAX_PAIRED; i++) { - if (bt_addr_le_eq(peer, &cars[i].addr)) { + if (bt_addr_le_eq(&cp->address, &cars[i].addr)) { if (cars[i].supported) { adv_param.options |= BT_LE_ADV_OPT_DIR_ADDR_RPA; } @@ -749,8 +756,7 @@ static void store_adv(const bt_addr_le_t *addr, int8_t rssi, ev = net_buf_simple_add(adv_buf, sizeof(*ev)); - memcpy(ev->address, addr->a.val, sizeof(ev->address)); - ev->address_type = addr->type; + bt_addr_le_copy(&ev->address, addr); ev->rssi = rssi; ev->flags = BTP_GAP_DEVICE_FOUND_FLAG_AD | BTP_GAP_DEVICE_FOUND_FLAG_RSSI; ev->eir_data_len = ad->len; @@ -791,8 +797,8 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t evtype, } ev = (void *) adv_buf->data; - a.type = ev->address_type; - memcpy(a.a.val, ev->address, sizeof(a.a.val)); + + bt_addr_le_copy(&a, &ev->address); /* * in general, the Scan Response comes right after the @@ -950,8 +956,7 @@ static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) struct btp_gap_passkey_display_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); - memcpy(ev.address, addr->a.val, sizeof(ev.address)); - ev.address_type = addr->type; + bt_addr_le_copy(&ev.address, addr); ev.passkey = sys_cpu_to_le32(passkey); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_DISPLAY, @@ -963,8 +968,7 @@ static void auth_passkey_entry(struct bt_conn *conn) struct btp_gap_passkey_entry_req_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); - memcpy(ev.address, addr->a.val, sizeof(ev.address)); - ev.address_type = addr->type; + bt_addr_le_copy(&ev.address, addr); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_ENTRY_REQ, CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); @@ -975,8 +979,7 @@ static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey) struct btp_gap_passkey_confirm_req_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); - memcpy(ev.address, addr->a.val, sizeof(ev.address)); - ev.address_type = addr->type; + bt_addr_le_copy(&ev.address, addr); ev.passkey = sys_cpu_to_le32(passkey); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_CONFIRM_REQ, @@ -1003,8 +1006,7 @@ enum bt_security_err auth_pairing_accept(struct bt_conn *conn, */ LOG_DBG("Bond lost"); - memcpy(ev.address, addr->a.val, sizeof(ev.address)); - ev.address_type = addr->type; + bt_addr_le_copy(&ev.address, addr); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_BOND_LOST, CONTROLLER_INDEX, (uint8_t *)&ev, sizeof(ev)); @@ -1017,8 +1019,7 @@ void auth_pairing_failed(struct bt_conn *conn, enum bt_security_err reason) struct btp_gap_bond_pairing_failed_ev ev; const bt_addr_le_t *addr = bt_conn_get_dst(conn); - memcpy(ev.address, addr->a.val, sizeof(ev.address)); - ev.address_type = addr->type; + bt_addr_le_copy(&ev.address, addr); ev.reason = reason; tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PAIRING_FAILED, CONTROLLER_INDEX, diff --git a/tests/bluetooth/tester/src/btp_gatt.c b/tests/bluetooth/tester/src/btp_gatt.c index 6f0eb1148558..18af803a9d28 100644 --- a/tests/bluetooth/tester/src/btp_gatt.c +++ b/tests/bluetooth/tester/src/btp_gatt.c @@ -1799,14 +1799,12 @@ static uint8_t notify_func(struct bt_conn *conn, const void *data, uint16_t length) { struct btp_gatt_notification_ev *ev = (void *) ev_buf; - const bt_addr_le_t *addr; if (!conn || !data) { LOG_DBG("Unsubscribed"); (void)memset(params, 0, sizeof(*params)); return BT_GATT_ITER_STOP; } - addr = bt_conn_get_dst(conn); ev->type = (uint8_t)params->value; ev->handle = sys_cpu_to_le16(params->value_handle); @@ -1814,8 +1812,7 @@ static uint8_t notify_func(struct bt_conn *conn, ev->data_length = sys_cpu_to_le16(length); memcpy(ev->data, data, length); - memcpy(ev->address, addr->a.val, sizeof(ev->address)); - ev->address_type = addr->type; + bt_addr_le_copy(&ev->address, bt_conn_get_dst(conn)); tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_EV_NOTIFICATION, CONTROLLER_INDEX, ev_buf, sizeof(*ev) + length); diff --git a/tests/bluetooth/tester/src/btp_l2cap.c b/tests/bluetooth/tester/src/btp_l2cap.c index 6894ba0646aa..295a6b4ec0bb 100644 --- a/tests/bluetooth/tester/src/btp_l2cap.c +++ b/tests/bluetooth/tester/src/btp_l2cap.c @@ -87,14 +87,12 @@ static void connected_cb(struct bt_l2cap_chan *l2cap_chan) ev.mps_remote = sys_cpu_to_le16(chan->le.tx.mps); ev.mtu_local = sys_cpu_to_le16(chan->le.rx.mtu); ev.mps_local = sys_cpu_to_le16(chan->le.rx.mps); - ev.address_type = info.le.dst->type; - memcpy(ev.address, info.le.dst->a.val, - sizeof(ev.address)); + bt_addr_le_copy(&ev.address, info.le.dst); break; case BT_CONN_TYPE_BR: - memcpy(ev.address, info.br.dst->val, - sizeof(ev.address)); - break; + default: + /* TODO figure out how (if) want to handle BR/EDR */ + return; } } @@ -122,14 +120,12 @@ static void disconnected_cb(struct bt_l2cap_chan *l2cap_chan) if (!bt_conn_get_info(l2cap_chan->conn, &info)) { switch (info.type) { case BT_CONN_TYPE_LE: - ev.address_type = info.le.dst->type; - memcpy(ev.address, info.le.dst->a.val, - sizeof(ev.address)); + bt_addr_le_copy(&ev.address, info.le.dst); break; case BT_CONN_TYPE_BR: - memcpy(ev.address, info.br.dst->val, - sizeof(ev.address)); - break; + default: + /* TODO figure out how (if) want to handle BR/EDR */ + return; } } From bc9df109c6daa54eb43be252f68f99d32bc69fe4 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 21 Feb 2023 18:34:07 +0100 Subject: [PATCH 0025/1906] bluetooth: tester: Convert GATT service to new BTP API This makes GATT service to use new BTP command handlers API. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp/btp_gatt.h | 10 + tests/bluetooth/tester/src/btp/bttester.h | 2 - tests/bluetooth/tester/src/btp_gatt.c | 1361 +++++++++++++-------- 3 files changed, 847 insertions(+), 526 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_gatt.h b/tests/bluetooth/tester/src/btp/btp_gatt.h index 32ea174112ec..269244309927 100644 --- a/tests/bluetooth/tester/src/btp/btp_gatt.h +++ b/tests/bluetooth/tester/src/btp/btp_gatt.h @@ -332,6 +332,16 @@ struct btp_gatt_eatt_connect_cmd { } __packed; #define BTP_GATT_READ_MULTIPLE_VAR 0x20 +struct btp_gatt_read_multiple_var_cmd { + bt_addr_le_t address; + uint8_t handles_count; + uint16_t handles[]; +} __packed; +struct btp_gatt_read_multiple_var_rp { + uint8_t att_response; + uint16_t data_length; + uint8_t data[]; +} __packed; #define BTP_GATT_NOTIFY_MULTIPLE 0x21 struct btp_gatt_cfg_notify_mult_cmd { diff --git a/tests/bluetooth/tester/src/btp/bttester.h b/tests/bluetooth/tester/src/btp/bttester.h index 402668d7f0ff..1f290cd9f340 100644 --- a/tests/bluetooth/tester/src/btp/bttester.h +++ b/tests/bluetooth/tester/src/btp/bttester.h @@ -44,8 +44,6 @@ void tester_register_command_handlers(uint8_t service, uint8_t tester_init_gatt(void); uint8_t tester_unregister_gatt(void); -void tester_handle_gatt(uint8_t opcode, uint8_t index, uint8_t *data, - uint16_t len); uint8_t tester_init_l2cap(void); uint8_t tester_unregister_l2cap(void); diff --git a/tests/bluetooth/tester/src/btp_gatt.c b/tests/bluetooth/tester/src/btp_gatt.c index 18af803a9d28..f6e6ed99a854 100644 --- a/tests/bluetooth/tester/src/btp_gatt.c +++ b/tests/bluetooth/tester/src/btp_gatt.c @@ -218,45 +218,58 @@ static uint8_t btp2bt_uuid(const uint8_t *uuid, uint8_t len, return BTP_STATUS_SUCCESS; } -static void supported_commands(uint8_t *data, uint16_t len) -{ - uint8_t cmds[5]; - struct btp_gatt_read_supported_commands_rp *rp = (void *) cmds; - - (void)memset(cmds, 0, sizeof(cmds)); - - tester_set_bit(cmds, BTP_GATT_READ_SUPPORTED_COMMANDS); - tester_set_bit(cmds, BTP_GATT_ADD_SERVICE); - tester_set_bit(cmds, BTP_GATT_ADD_CHARACTERISTIC); - tester_set_bit(cmds, BTP_GATT_ADD_DESCRIPTOR); - tester_set_bit(cmds, BTP_GATT_ADD_INCLUDED_SERVICE); - tester_set_bit(cmds, BTP_GATT_SET_VALUE); - tester_set_bit(cmds, BTP_GATT_START_SERVER); - tester_set_bit(cmds, BTP_GATT_SET_ENC_KEY_SIZE); - tester_set_bit(cmds, BTP_GATT_EXCHANGE_MTU); - tester_set_bit(cmds, BTP_GATT_DISC_PRIM_UUID); - tester_set_bit(cmds, BTP_GATT_FIND_INCLUDED); - tester_set_bit(cmds, BTP_GATT_DISC_ALL_CHRC); - tester_set_bit(cmds, BTP_GATT_DISC_CHRC_UUID); - tester_set_bit(cmds, BTP_GATT_DISC_ALL_DESC); - tester_set_bit(cmds, BTP_GATT_READ); - tester_set_bit(cmds, BTP_GATT_READ_LONG); - tester_set_bit(cmds, BTP_GATT_READ_MULTIPLE); - tester_set_bit(cmds, BTP_GATT_WRITE_WITHOUT_RSP); - tester_set_bit(cmds, BTP_GATT_SIGNED_WRITE_WITHOUT_RSP); - tester_set_bit(cmds, BTP_GATT_WRITE); - tester_set_bit(cmds, BTP_GATT_WRITE_LONG); - tester_set_bit(cmds, BTP_GATT_CFG_NOTIFY); - tester_set_bit(cmds, BTP_GATT_CFG_INDICATE); - tester_set_bit(cmds, BTP_GATT_GET_ATTRIBUTES); - tester_set_bit(cmds, BTP_GATT_GET_ATTRIBUTE_VALUE); - tester_set_bit(cmds, BTP_GATT_DISC_ALL_PRIM); - tester_set_bit(cmds, BTP_GATT_READ_MULTIPLE_VAR); - tester_set_bit(cmds, BTP_GATT_EATT_CONNECT); - tester_set_bit(cmds, BTP_GATT_NOTIFY_MULTIPLE); - - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_READ_SUPPORTED_COMMANDS, - CONTROLLER_INDEX, (uint8_t *) rp, sizeof(cmds)); +static uint8_t supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + struct btp_gatt_read_supported_commands_rp *rp = rsp; + + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } + + /* octet 0 */ + tester_set_bit(rp->data, BTP_GATT_READ_SUPPORTED_COMMANDS); + tester_set_bit(rp->data, BTP_GATT_ADD_SERVICE); + tester_set_bit(rp->data, BTP_GATT_ADD_CHARACTERISTIC); + tester_set_bit(rp->data, BTP_GATT_ADD_DESCRIPTOR); + tester_set_bit(rp->data, BTP_GATT_ADD_INCLUDED_SERVICE); + tester_set_bit(rp->data, BTP_GATT_SET_VALUE); + tester_set_bit(rp->data, BTP_GATT_START_SERVER); + + /* octet 1 */ + tester_set_bit(rp->data, BTP_GATT_SET_ENC_KEY_SIZE); + tester_set_bit(rp->data, BTP_GATT_EXCHANGE_MTU); + tester_set_bit(rp->data, BTP_GATT_DISC_ALL_PRIM); + tester_set_bit(rp->data, BTP_GATT_DISC_PRIM_UUID); + tester_set_bit(rp->data, BTP_GATT_FIND_INCLUDED); + tester_set_bit(rp->data, BTP_GATT_DISC_ALL_CHRC); + tester_set_bit(rp->data, BTP_GATT_DISC_CHRC_UUID); + + /* octet 2 */ + tester_set_bit(rp->data, BTP_GATT_DISC_ALL_DESC); + tester_set_bit(rp->data, BTP_GATT_READ); + tester_set_bit(rp->data, BTP_GATT_READ_LONG); + tester_set_bit(rp->data, BTP_GATT_READ_MULTIPLE); + tester_set_bit(rp->data, BTP_GATT_WRITE_WITHOUT_RSP); + tester_set_bit(rp->data, BTP_GATT_SIGNED_WRITE_WITHOUT_RSP); + tester_set_bit(rp->data, BTP_GATT_WRITE); + + /* octet 3 */ + tester_set_bit(rp->data, BTP_GATT_WRITE_LONG); + tester_set_bit(rp->data, BTP_GATT_CFG_NOTIFY); + tester_set_bit(rp->data, BTP_GATT_CFG_INDICATE); + tester_set_bit(rp->data, BTP_GATT_GET_ATTRIBUTES); + tester_set_bit(rp->data, BTP_GATT_GET_ATTRIBUTE_VALUE); + tester_set_bit(rp->data, BTP_GATT_EATT_CONNECT); + + /* octet 4 */ + tester_set_bit(rp->data, BTP_GATT_READ_MULTIPLE_VAR); + tester_set_bit(rp->data, BTP_GATT_NOTIFY_MULTIPLE); + + + *rsp_len = sizeof(*rp) + 5; + + return BTP_STATUS_SUCCESS; } static int register_service(void) @@ -276,16 +289,26 @@ static int register_service(void) return err; } -static void add_service(uint8_t *data, uint16_t len) +static uint8_t add_service(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_add_service_cmd *cmd = (void *) data; - struct btp_gatt_add_service_rp rp; + const struct btp_gatt_add_service_cmd *cp = cmd; + struct btp_gatt_add_service_rp *rp = rsp; struct bt_gatt_attr *attr_svc = NULL; union uuid uuid; size_t uuid_size; - if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid.uuid)) { - goto fail; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if ((cmd_len < sizeof(*cp)) || + (cmd_len != sizeof(*cp) + cp->uuid_length)) { + return BTP_STATUS_FAILED; + } + + if (btp2bt_uuid(cp->uuid, cp->uuid_length, &uuid.uuid)) { + return BTP_STATUS_FAILED; } uuid_size = uuid.uuid.type == BT_UUID_TYPE_16 ? sizeof(uuid.u16) : @@ -294,13 +317,13 @@ static void add_service(uint8_t *data, uint16_t len) /* Register last defined service */ if (svc_attr_count) { if (register_service()) { - goto fail; + return BTP_STATUS_FAILED; } } svc_count++; - switch (cmd->type) { + switch (cp->type) { case BTP_GATT_SERVICE_PRIMARY: attr_svc = gatt_db_add(&(struct bt_gatt_attr) BT_GATT_PRIMARY_SERVICE(&uuid.uuid), @@ -315,18 +338,13 @@ static void add_service(uint8_t *data, uint16_t len) if (!attr_svc) { svc_count--; - goto fail; + return BTP_STATUS_FAILED; } - rp.svc_id = sys_cpu_to_le16(attr_svc->handle); + rp->svc_id = sys_cpu_to_le16(attr_svc->handle); + *rsp_len = sizeof(*rp); - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_SERVICE, CONTROLLER_INDEX, - (uint8_t *) &rp, sizeof(rp)); - - return; -fail: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_SERVICE, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } struct gatt_value { @@ -479,43 +497,48 @@ static int alloc_characteristic(struct add_characteristic *ch) return 0; } -static void add_characteristic(uint8_t *data, uint16_t len) +static uint8_t add_characteristic(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_add_characteristic_cmd *cmd = (void *) data; - struct btp_gatt_add_characteristic_rp rp; + const struct btp_gatt_add_characteristic_cmd *cp = cmd; + struct btp_gatt_add_characteristic_rp *rp = rsp; struct add_characteristic cmd_data; union uuid uuid; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if ((cmd_len < sizeof(*cp)) || + (cmd_len != sizeof(*cp) + cp->uuid_length)) { + return BTP_STATUS_FAILED; + } + /* Pre-set char_id */ cmd_data.char_id = 0U; - cmd_data.permissions = cmd->permissions; - cmd_data.properties = cmd->properties; + cmd_data.permissions = cp->permissions; + cmd_data.properties = cp->properties; cmd_data.uuid = &uuid.uuid; - if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid.uuid)) { - goto fail; + if (btp2bt_uuid(cp->uuid, cp->uuid_length, &uuid.uuid)) { + return BTP_STATUS_FAILED; } /* characteristic must be added only sequential */ - if (cmd->svc_id) { - goto fail; + if (cp->svc_id) { + return BTP_STATUS_FAILED; } if (alloc_characteristic(&cmd_data)) { - goto fail; + return BTP_STATUS_FAILED; } - rp.char_id = sys_cpu_to_le16(cmd_data.char_id); - ccc_added = false; - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_CHARACTERISTIC, - CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); - return; + rp->char_id = sys_cpu_to_le16(cmd_data.char_id); + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_CHARACTERISTIC, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } static void ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) @@ -667,51 +690,57 @@ static struct bt_gatt_attr *get_base_chrc(struct bt_gatt_attr *attr) return NULL; } -static void add_descriptor(uint8_t *data, uint16_t len) +static uint8_t add_descriptor(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_add_descriptor_cmd *cmd = (void *) data; - struct btp_gatt_add_descriptor_rp rp; + const struct btp_gatt_add_descriptor_cmd *cp = cmd; + struct btp_gatt_add_descriptor_rp *rp = rsp; struct add_descriptor cmd_data; struct bt_gatt_attr *chrc; union uuid uuid; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if ((cmd_len < sizeof(*cp)) || + (cmd_len != sizeof(*cp) + cp->uuid_length)) { + return BTP_STATUS_FAILED; + } + /* Must be declared first svc or at least 3 attrs (svc+char+char val) */ if (!svc_count || attr_count < 3) { - goto fail; + return BTP_STATUS_FAILED; } /* Pre-set desc_id */ cmd_data.desc_id = 0U; - cmd_data.permissions = cmd->permissions; + cmd_data.permissions = cp->permissions; cmd_data.uuid = &uuid.uuid; - if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid.uuid)) { - goto fail; + if (btp2bt_uuid(cp->uuid, cp->uuid_length, &uuid.uuid)) { + return BTP_STATUS_FAILED; } /* descriptor can be added only sequential */ - if (cmd->char_id) { - goto fail; + if (cp->char_id) { + return BTP_STATUS_FAILED; } /* Lookup preceding Characteristic Declaration here */ chrc = get_base_chrc(LAST_DB_ATTR); if (!chrc) { - goto fail; + return BTP_STATUS_FAILED; } if (alloc_descriptor(chrc, &cmd_data)) { - goto fail; + return BTP_STATUS_FAILED; } - rp.desc_id = sys_cpu_to_le16(cmd_data.desc_id); - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_DESCRIPTOR, CONTROLLER_INDEX, - (uint8_t *) &rp, sizeof(rp)); - return; + rp->desc_id = sys_cpu_to_le16(cmd_data.desc_id); + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_DESCRIPTOR, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } static int alloc_included(struct bt_gatt_attr *attr, @@ -736,37 +765,45 @@ static int alloc_included(struct bt_gatt_attr *attr, return 0; } -static void add_included(uint8_t *data, uint16_t len) +static uint8_t add_included(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_add_included_service_cmd *cmd = (void *) data; - struct btp_gatt_add_included_service_rp rp; + const struct btp_gatt_add_included_service_cmd *cp = cmd; + struct btp_gatt_add_included_service_rp *rp = rsp; struct bt_gatt_attr *svc; + uint16_t svc_id; uint16_t included_service_id = 0U; - if (!svc_count || !cmd->svc_id) { - goto fail; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; } - svc = &server_db[cmd->svc_id - 1]; + if (!svc_count) { + return BTP_STATUS_FAILED; + } + + svc_id = sys_le16_to_cpu(cp->svc_id); + + if (svc_id == 0 || svc_id > SERVER_MAX_ATTRIBUTES) { + return BTP_STATUS_FAILED; + } + + svc = &server_db[svc_id - 1]; /* Fail if attribute stored under requested handle is not a service */ if (bt_uuid_cmp(svc->uuid, BT_UUID_GATT_PRIMARY) && bt_uuid_cmp(svc->uuid, BT_UUID_GATT_SECONDARY)) { - goto fail; + return BTP_STATUS_FAILED; } - if (alloc_included(svc, &included_service_id, cmd->svc_id)) { - goto fail; + if (alloc_included(svc, &included_service_id, svc_id)) { + return BTP_STATUS_FAILED; } - rp.included_service_id = sys_cpu_to_le16(included_service_id); - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_INCLUDED_SERVICE, - CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); - return; + rp->included_service_id = sys_cpu_to_le16(included_service_id); + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_ADD_INCLUDED_SERVICE, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } static uint8_t set_cep_value(struct bt_gatt_attr *attr, const void *value, @@ -860,43 +897,64 @@ static uint8_t alloc_value(struct bt_gatt_attr *attr, struct set_value *data) return BTP_STATUS_SUCCESS; } -static void set_value(uint8_t *data, uint16_t len) +static uint8_t set_value(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_set_value_cmd *cmd = (void *) data; + const struct btp_gatt_set_value_cmd *cp = cmd; struct set_value cmd_data; + uint16_t attr_id; uint8_t status; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if ((cmd_len < sizeof(*cp)) || + (cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->len))) { + return BTP_STATUS_FAILED; + } + + attr_id = sys_le16_to_cpu(cp->attr_id); + if (attr_id > SERVER_MAX_ATTRIBUTES) { + return BTP_STATUS_FAILED; + } + /* Pre-set btp_status */ - cmd_data.value = cmd->value; - cmd_data.len = sys_le16_to_cpu(cmd->len); + cmd_data.value = cp->value; + cmd_data.len = sys_le16_to_cpu(cp->len); - if (!cmd->attr_id) { + if (attr_id == 0) { status = alloc_value(LAST_DB_ATTR, &cmd_data); } else { /* set value of local attr, corrected by pre set attr handles */ - status = alloc_value(&server_db[cmd->attr_id - - server_db[0].handle], &cmd_data); + status = alloc_value(&server_db[attr_id - server_db[0].handle], + &cmd_data); } - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_SET_VALUE, CONTROLLER_INDEX, - status); + return BTP_STATUS_SUCCESS; } -static void start_server(uint8_t *data, uint16_t len) +static uint8_t start_server(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_gatt_start_server_rp rp; + struct btp_gatt_start_server_rp *rp = rsp; + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } /* Register last defined service */ if (svc_attr_count) { if (register_service()) { - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_START_SERVER, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - return; + return BTP_STATUS_FAILED; } } - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_START_SERVER, CONTROLLER_INDEX, - (uint8_t *) &rp, sizeof(rp)); + rp->db_attr_off = sys_cpu_to_le16(0); /* TODO*/ + rp->db_attr_cnt = svc_attr_count; + *rsp_len = sizeof(*rp); + + return BTP_STATUS_SUCCESS; } static int set_attr_enc_key_size(const struct bt_gatt_attr *attr, @@ -923,70 +981,79 @@ static int set_attr_enc_key_size(const struct bt_gatt_attr *attr, return 0; } -static void set_enc_key_size(uint8_t *data, uint16_t len) +static uint8_t set_enc_key_size(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_set_enc_key_size_cmd *cmd = (void *) data; - uint8_t status; + const struct btp_gatt_set_enc_key_size_cmd *cp = cmd; + uint16_t attr_id; + int ret; + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } /* Fail if requested key size is invalid */ - if (cmd->key_size < 0x07 || cmd->key_size > 0x0f) { - status = BTP_STATUS_FAILED; - goto fail; + if (cp->key_size < 0x07 || cp->key_size > 0x0f) { + return BTP_STATUS_FAILED; } - if (!cmd->attr_id) { - status = set_attr_enc_key_size(LAST_DB_ATTR, cmd->key_size); + attr_id = sys_le16_to_cpu(cp->attr_id); + + if (!attr_id) { + ret = set_attr_enc_key_size(LAST_DB_ATTR, cp->key_size); } else { /* set value of local attr, corrected by pre set attr handles */ - status = set_attr_enc_key_size(&server_db[cmd->attr_id - - server_db[0].handle], - cmd->key_size); + ret = set_attr_enc_key_size(&server_db[attr_id - + server_db[0].handle], cp->key_size); } -fail: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_SET_ENC_KEY_SIZE, CONTROLLER_INDEX, - status); + if (ret) { + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; } static void exchange_func(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params) { - if (err) { - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_EXCHANGE_MTU, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - - return; + if (err != 0U) { + LOG_ERR("MTU exchange failed"); + } else { + LOG_DBG("MTU exchange succeed"); } - - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_EXCHANGE_MTU, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); } static struct bt_gatt_exchange_params exchange_params; -static void exchange_mtu(uint8_t *data, uint16_t len) +static uint8_t exchange_mtu(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { + const struct btp_gatt_exchange_mtu_cmd *cp = cmd; struct bt_conn *conn; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - goto fail; + return BTP_STATUS_FAILED; } exchange_params.func = exchange_func; if (bt_gatt_exchange_mtu(conn, &exchange_params) < 0) { bt_conn_unref(conn); - - goto fail; + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - return; -fail: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_EXCHANGE_MTU, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + /* this BTP command is about initiating MTU exchange, no need to wait + * for procedure to complete. + */ + return BTP_STATUS_SUCCESS; } static struct bt_gatt_discover_params discover_params; @@ -1045,17 +1112,24 @@ static uint8_t disc_prim_cb(struct bt_conn *conn, return BT_GATT_ITER_CONTINUE; } -static void disc_all_prim(uint8_t *data, uint16_t len) +static uint8_t disc_all_prim(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { + const struct btp_gatt_disc_all_prim_cmd *cp = cmd; struct bt_conn *conn; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - goto fail_conn; + return BTP_STATUS_FAILED; } if (!gatt_buf_reserve(sizeof(struct btp_gatt_disc_prim_rp))) { - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } discover_params.uuid = NULL; @@ -1069,37 +1143,43 @@ static void disc_all_prim(uint8_t *data, uint16_t len) if (bt_gatt_discover(conn, &discover_params) < 0) { discover_destroy(&discover_params); - - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - return; -fail: - bt_conn_unref(conn); - -fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_PRIM, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_DELAY_REPLY; } -static void disc_prim_uuid(uint8_t *data, uint16_t len) +static uint8_t disc_prim_uuid(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_disc_prim_uuid_cmd *cmd = (void *) data; + const struct btp_gatt_disc_prim_uuid_cmd *cp = cmd; struct bt_conn *conn; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if ((cmd_len < sizeof(*cp)) || + (cmd_len != sizeof(*cp) + cp->uuid_length)) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - goto fail_conn; + return BTP_STATUS_FAILED; } - if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid.uuid)) { - goto fail; + if (btp2bt_uuid(cp->uuid, cp->uuid_length, &uuid.uuid)) { + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } if (!gatt_buf_reserve(sizeof(struct btp_gatt_disc_prim_rp))) { - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } discover_params.uuid = &uuid.uuid; @@ -1113,19 +1193,13 @@ static void disc_prim_uuid(uint8_t *data, uint16_t len) if (bt_gatt_discover(conn, &discover_params) < 0) { discover_destroy(&discover_params); - - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - return; -fail: - bt_conn_unref(conn); - -fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_PRIM_UUID, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_DELAY_REPLY; } static uint8_t find_included_cb(struct bt_conn *conn, @@ -1175,41 +1249,41 @@ static uint8_t find_included_cb(struct bt_conn *conn, return BT_GATT_ITER_CONTINUE; } -static void find_included(uint8_t *data, uint16_t len) +static uint8_t find_included(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_find_included_cmd *cmd = (void *) data; + const struct btp_gatt_find_included_cmd *cp = cmd; struct bt_conn *conn; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - goto fail_conn; + return BTP_STATUS_FAILED; } if (!gatt_buf_reserve(sizeof(struct btp_gatt_find_included_rp))) { - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } - discover_params.start_handle = sys_le16_to_cpu(cmd->start_handle); - discover_params.end_handle = sys_le16_to_cpu(cmd->end_handle); + discover_params.start_handle = sys_le16_to_cpu(cp->start_handle); + discover_params.end_handle = sys_le16_to_cpu(cp->end_handle); discover_params.type = BT_GATT_DISCOVER_INCLUDE; discover_params.func = find_included_cb; discover_params.chan_opt = BT_ATT_CHAN_OPT_NONE; if (bt_gatt_discover(conn, &discover_params) < 0) { discover_destroy(&discover_params); - - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - return; -fail: - bt_conn_unref(conn); - -fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_FIND_INCLUDED, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_DELAY_REPLY; } static uint8_t disc_chrc_cb(struct bt_conn *conn, @@ -1258,22 +1332,28 @@ static uint8_t disc_chrc_cb(struct bt_conn *conn, return BT_GATT_ITER_CONTINUE; } -static void disc_all_chrc(uint8_t *data, uint16_t len) +static uint8_t disc_all_chrc(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_disc_all_chrc_cmd *cmd = (void *) data; + const struct btp_gatt_disc_all_chrc_cmd *cp = cmd; struct bt_conn *conn; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - goto fail_conn; + return BTP_STATUS_FAILED; } if (!gatt_buf_reserve(sizeof(struct btp_gatt_disc_chrc_rp))) { - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } - discover_params.start_handle = sys_le16_to_cpu(cmd->start_handle); - discover_params.end_handle = sys_le16_to_cpu(cmd->end_handle); + discover_params.start_handle = sys_le16_to_cpu(cp->start_handle); + discover_params.end_handle = sys_le16_to_cpu(cp->end_handle); discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; discover_params.func = disc_chrc_cb; discover_params.chan_opt = BT_ATT_CHAN_OPT_NONE; @@ -1283,42 +1363,48 @@ static void disc_all_chrc(uint8_t *data, uint16_t len) if (bt_gatt_discover(conn, &discover_params) < 0) { discover_destroy(&discover_params); - - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - return; -fail: - bt_conn_unref(conn); - -fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_CHRC, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_DELAY_REPLY; } -static void disc_chrc_uuid(uint8_t *data, uint16_t len) +static uint8_t disc_chrc_uuid(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_disc_chrc_uuid_cmd *cmd = (void *) data; + const struct btp_gatt_disc_chrc_uuid_cmd *cp = cmd; struct bt_conn *conn; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if ((cmd_len < sizeof(*cp)) || + (cmd_len != sizeof(*cp) + cp->uuid_length)) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - goto fail_conn; + return BTP_STATUS_FAILED; } - if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid.uuid)) { - goto fail; + if (btp2bt_uuid(cp->uuid, cp->uuid_length, &uuid.uuid)) { + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } if (!gatt_buf_reserve(sizeof(struct btp_gatt_disc_chrc_rp))) { - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } discover_params.uuid = &uuid.uuid; - discover_params.start_handle = sys_le16_to_cpu(cmd->start_handle); - discover_params.end_handle = sys_le16_to_cpu(cmd->end_handle); + discover_params.start_handle = sys_le16_to_cpu(cp->start_handle); + discover_params.end_handle = sys_le16_to_cpu(cp->end_handle); discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; discover_params.func = disc_chrc_cb; discover_params.chan_opt = BT_ATT_CHAN_OPT_NONE; @@ -1328,19 +1414,13 @@ static void disc_chrc_uuid(uint8_t *data, uint16_t len) if (bt_gatt_discover(conn, &discover_params) < 0) { discover_destroy(&discover_params); - - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - return; -fail: - bt_conn_unref(conn); - -fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_CHRC_UUID, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_DELAY_REPLY; } static uint8_t disc_all_desc_cb(struct bt_conn *conn, @@ -1385,41 +1465,41 @@ static uint8_t disc_all_desc_cb(struct bt_conn *conn, return BT_GATT_ITER_CONTINUE; } -static void disc_all_desc(uint8_t *data, uint16_t len) +static uint8_t disc_all_desc(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_disc_all_desc_cmd *cmd = (void *) data; + const struct btp_gatt_disc_all_desc_cmd *cp = cmd; struct bt_conn *conn; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - goto fail_conn; + return BTP_STATUS_FAILED; } if (!gatt_buf_reserve(sizeof(struct btp_gatt_disc_all_desc_rp))) { - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } - discover_params.start_handle = sys_le16_to_cpu(cmd->start_handle); - discover_params.end_handle = sys_le16_to_cpu(cmd->end_handle); + discover_params.start_handle = sys_le16_to_cpu(cp->start_handle); + discover_params.end_handle = sys_le16_to_cpu(cp->end_handle); discover_params.type = BT_GATT_DISCOVER_DESCRIPTOR; discover_params.func = disc_all_desc_cb; discover_params.chan_opt = BT_ATT_CHAN_OPT_NONE; if (bt_gatt_discover(conn, &discover_params) < 0) { discover_destroy(&discover_params); - - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - return; -fail: - bt_conn_unref(conn); - -fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_DESC, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_DELAY_REPLY; } static struct bt_gatt_read_params read_params; @@ -1506,22 +1586,28 @@ static uint8_t read_uuid_cb(struct bt_conn *conn, uint8_t err, return BT_GATT_ITER_CONTINUE; } -static void read_data(uint8_t *data, uint16_t len) +static uint8_t read_data(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_read_cmd *cmd = (void *) data; + const struct btp_gatt_read_cmd *cp = cmd; struct bt_conn *conn; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - goto fail_conn; + return BTP_STATUS_FAILED; } if (!gatt_buf_reserve(sizeof(struct btp_gatt_read_rp))) { - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } read_params.handle_count = 1; - read_params.single.handle = sys_le16_to_cpu(cmd->handle); + read_params.single.handle = sys_le16_to_cpu(cp->handle); read_params.single.offset = 0x0000; read_params.func = read_cb; read_params.chan_opt = BT_ATT_CHAN_OPT_NONE; @@ -1531,43 +1617,49 @@ static void read_data(uint8_t *data, uint16_t len) if (bt_gatt_read(conn, &read_params) < 0) { read_destroy(&read_params); - - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - return; -fail: - bt_conn_unref(conn); - -fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_READ, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_DELAY_REPLY; } -static void read_uuid(uint8_t *data, uint16_t len) +static uint8_t read_uuid(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_read_uuid_cmd *cmd = (void *) data; + const struct btp_gatt_read_uuid_cmd *cp = cmd; struct bt_conn *conn; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if ((cmd_len < sizeof(*cp)) || + (cmd_len != sizeof(*cp) + cp->uuid_length)) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - goto fail_conn; + return BTP_STATUS_FAILED; } - if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid.uuid)) { - goto fail; + if (btp2bt_uuid(cp->uuid, cp->uuid_length, &uuid.uuid)) { + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } if (!gatt_buf_reserve(sizeof(struct btp_gatt_read_uuid_rp))) { - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } read_params.by_uuid.uuid = &uuid.uuid; read_params.handle_count = 0; - read_params.by_uuid.start_handle = sys_le16_to_cpu(cmd->start_handle); - read_params.by_uuid.end_handle = sys_le16_to_cpu(cmd->end_handle); + read_params.by_uuid.start_handle = sys_le16_to_cpu(cp->start_handle); + read_params.by_uuid.end_handle = sys_le16_to_cpu(cp->end_handle); read_params.func = read_uuid_cb; read_params.chan_opt = BT_ATT_CHAN_OPT_NONE; @@ -1575,38 +1667,38 @@ static void read_uuid(uint8_t *data, uint16_t len) if (bt_gatt_read(conn, &read_params) < 0) { read_destroy(&read_params); - - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - return; -fail: - bt_conn_unref(conn); - -fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_READ_UUID, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_DELAY_REPLY; } -static void read_long(uint8_t *data, uint16_t len) +static uint8_t read_long(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_read_long_cmd *cmd = (void *) data; + const struct btp_gatt_read_long_cmd *cp = cmd; struct bt_conn *conn; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - goto fail_conn; + return BTP_STATUS_FAILED; } if (!gatt_buf_reserve(sizeof(struct btp_gatt_read_rp))) { - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } read_params.handle_count = 1; - read_params.single.handle = sys_le16_to_cpu(cmd->handle); - read_params.single.offset = sys_le16_to_cpu(cmd->offset); + read_params.single.handle = sys_le16_to_cpu(cp->handle); + read_params.single.offset = sys_le16_to_cpu(cp->offset); read_params.func = read_cb; read_params.chan_opt = BT_ATT_CHAN_OPT_NONE; @@ -1615,89 +1707,187 @@ static void read_long(uint8_t *data, uint16_t len) if (bt_gatt_read(conn, &read_params) < 0) { read_destroy(&read_params); - - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - return; -fail: + return BTP_STATUS_DELAY_REPLY; +} + +static uint8_t read_multiple(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_gatt_read_multiple_cmd *cp = cmd; + uint16_t handles[5]; + struct bt_conn *conn; + int i; + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if ((cmd_len < sizeof(*cp)) || + (cmd_len != sizeof(*cp) + (cp->handles_count * sizeof(cp->handles[0])))) { + return BTP_STATUS_FAILED; + } + + if (cp->handles_count > ARRAY_SIZE(handles)) { + return BTP_STATUS_FAILED; + } + + for (i = 0; i < ARRAY_SIZE(handles); i++) { + handles[i] = sys_le16_to_cpu(cp->handles[i]); + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); + if (!conn) { + return BTP_STATUS_FAILED; + } + + if (!gatt_buf_reserve(sizeof(struct btp_gatt_read_rp))) { + bt_conn_unref(conn); + return BTP_STATUS_FAILED; + } + + read_params.func = read_cb; + read_params.handle_count = i; + read_params.multiple.handles = handles; /* not used in read func */ + read_params.multiple.variable = false; + read_params.chan_opt = BT_ATT_CHAN_OPT_NONE; + + /* TODO should be handled as user_data via CONTAINER_OF macro */ + btp_opcode = BTP_GATT_READ_MULTIPLE; + + if (bt_gatt_read(conn, &read_params) < 0) { + gatt_buf_clear(); + bt_conn_unref(conn); + return BTP_STATUS_FAILED; + } + bt_conn_unref(conn); -fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_READ_LONG, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_DELAY_REPLY; } -static void read_multiple(uint8_t *data, uint16_t len, uint8_t opcode) +static uint8_t read_multiple_var(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_read_multiple_cmd *cmd = (void *) data; - uint16_t handles[cmd->handles_count]; + const struct btp_gatt_read_multiple_var_cmd *cp = cmd; + uint16_t handles[5]; struct bt_conn *conn; int i; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if ((cmd_len < sizeof(*cp)) || + (cmd_len != sizeof(*cp) + (cp->handles_count * sizeof(cp->handles[0])))) { + return BTP_STATUS_FAILED; + } + + if (cp->handles_count > ARRAY_SIZE(handles)) { + return BTP_STATUS_FAILED; + } + for (i = 0; i < ARRAY_SIZE(handles); i++) { - handles[i] = sys_le16_to_cpu(cmd->handles[i]); + handles[i] = sys_le16_to_cpu(cp->handles[i]); } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - goto fail_conn; + return BTP_STATUS_FAILED; } if (!gatt_buf_reserve(sizeof(struct btp_gatt_read_rp))) { - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } read_params.func = read_cb; read_params.handle_count = i; read_params.multiple.handles = handles; /* not used in read func */ - read_params.multiple.variable = (opcode == BTP_GATT_READ_MULTIPLE_VAR); + read_params.multiple.variable = true; read_params.chan_opt = BT_ATT_CHAN_OPT_NONE; /* TODO should be handled as user_data via CONTAINER_OF macro */ - btp_opcode = opcode; + btp_opcode = BTP_GATT_READ_MULTIPLE_VAR; if (bt_gatt_read(conn, &read_params) < 0) { gatt_buf_clear(); - goto fail; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - return; -fail: - bt_conn_unref(conn); + return BTP_STATUS_DELAY_REPLY; +} + +static uint8_t write_without_rsp(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_gatt_write_without_rsp_cmd *cp = cmd; + struct bt_conn *conn; + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if (cmd_len < sizeof(*cp) || + cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_length)) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); + if (!conn) { + return BTP_STATUS_FAILED; + } + + if (bt_gatt_write_without_response(conn, sys_le16_to_cpu(cp->handle), + cp->data, + sys_le16_to_cpu(cp->data_length), + false) < 0) { + bt_conn_unref(conn); + return BTP_STATUS_FAILED; + } -fail_conn: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_READ_MULTIPLE, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + bt_conn_unref(conn); + return BTP_STATUS_SUCCESS; } -static void write_without_rsp(uint8_t *data, uint16_t len, uint8_t op, - bool sign) +static uint8_t write_signed_without_rsp(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_write_without_rsp_cmd *cmd = (void *) data; + const struct btp_gatt_signed_write_without_rsp_cmd *cp = cmd; struct bt_conn *conn; - uint8_t status = BTP_STATUS_SUCCESS; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if (cmd_len < sizeof(*cp) || + cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_length)) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - status = BTP_STATUS_FAILED; - goto rsp; + return BTP_STATUS_FAILED; } - if (bt_gatt_write_without_response(conn, sys_le16_to_cpu(cmd->handle), - cmd->data, - sys_le16_to_cpu(cmd->data_length), - sign) < 0) { - status = BTP_STATUS_FAILED; + if (bt_gatt_write_without_response(conn, sys_le16_to_cpu(cp->handle), + cp->data, + sys_le16_to_cpu(cp->data_length), + true) < 0) { + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } bt_conn_unref(conn); -rsp: - tester_rsp(BTP_SERVICE_ID_GATT, op, CONTROLLER_INDEX, status); + return BTP_STATUS_SUCCESS; } static void write_rsp(struct bt_conn *conn, uint8_t err, @@ -1709,34 +1899,40 @@ static void write_rsp(struct bt_conn *conn, uint8_t err, static struct bt_gatt_write_params write_params; -static void write_data(uint8_t *data, uint16_t len) +static uint8_t write_data(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_write_cmd *cmd = (void *) data; + const struct btp_gatt_write_cmd *cp = cmd; struct bt_conn *conn; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if (cmd_len < sizeof(*cp) || + cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_length)) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - goto fail; + return BTP_STATUS_FAILED; } - write_params.handle = sys_le16_to_cpu(cmd->handle); + write_params.handle = sys_le16_to_cpu(cp->handle); write_params.func = write_rsp; write_params.offset = 0U; - write_params.data = cmd->data; - write_params.length = sys_le16_to_cpu(cmd->data_length); + write_params.data = cp->data; + write_params.length = sys_le16_to_cpu(cp->data_length); write_params.chan_opt = BT_ATT_CHAN_OPT_NONE; if (bt_gatt_write(conn, &write_params) < 0) { bt_conn_unref(conn); - goto fail; + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - - return; -fail: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_DELAY_REPLY; } static void write_long_rsp(struct bt_conn *conn, uint8_t err, @@ -1746,34 +1942,40 @@ static void write_long_rsp(struct bt_conn *conn, uint8_t err, &err, sizeof(err)); } -static void write_long(uint8_t *data, uint16_t len) +static uint8_t write_long(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_write_long_cmd *cmd = (void *) data; + const struct btp_gatt_write_long_cmd *cp = cmd; struct bt_conn *conn; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if (cmd_len < sizeof(*cp) || + cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_length)) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - goto fail; + return BTP_STATUS_FAILED; } - write_params.handle = sys_le16_to_cpu(cmd->handle); + write_params.handle = sys_le16_to_cpu(cp->handle); write_params.func = write_long_rsp; - write_params.offset = cmd->offset; - write_params.data = cmd->data; - write_params.length = sys_le16_to_cpu(cmd->data_length); + write_params.offset = sys_le16_to_cpu(cp->offset); + write_params.data = cp->data; + write_params.length = sys_le16_to_cpu(cp->data_length); write_params.chan_opt = BT_ATT_CHAN_OPT_NONE; if (bt_gatt_write(conn, &write_params) < 0) { bt_conn_unref(conn); - goto fail; + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - - return; -fail: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE_LONG, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_DELAY_REPLY; } static struct bt_gatt_subscribe_params subscriptions[MAX_SUBSCRIPTIONS]; @@ -1932,33 +2134,67 @@ static int disable_subscription(struct bt_conn *conn, uint16_t ccc_handle) return 0; } -static void config_subscription(uint8_t *data, uint16_t len, uint16_t op) +static uint8_t config_subscription_notif(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_cfg_notify_cmd *cmd = (void *) data; + const struct btp_gatt_cfg_notify_cmd *cp = cmd; struct bt_conn *conn; - uint16_t ccc_handle = sys_le16_to_cpu(cmd->ccc_handle); + uint16_t ccc_handle = sys_le16_to_cpu(cp->ccc_handle); uint8_t status; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - tester_rsp(BTP_SERVICE_ID_GATT, op, CONTROLLER_INDEX, - BTP_STATUS_FAILED); - return; + return BTP_STATUS_FAILED; } - if (cmd->enable) { - uint16_t value; + if (cp->enable) { + /* on success response will be sent from callback */ + if (enable_subscription(conn, ccc_handle, BT_GATT_CCC_NOTIFY) == 0) { + bt_conn_unref(conn); + return BTP_STATUS_DELAY_REPLY; + } - if (op == BTP_GATT_CFG_NOTIFY) { - value = BT_GATT_CCC_NOTIFY; + status = BTP_STATUS_FAILED; + } else { + if (disable_subscription(conn, ccc_handle) < 0) { + status = BTP_STATUS_FAILED; } else { - value = BT_GATT_CCC_INDICATE; + status = BTP_STATUS_SUCCESS; } + } + + LOG_DBG("Config notification subscription status %u", status); + + bt_conn_unref(conn); + return status; +} + +static uint8_t config_subscription_ind(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_gatt_cfg_notify_cmd *cp = cmd; + struct bt_conn *conn; + uint16_t ccc_handle = sys_le16_to_cpu(cp->ccc_handle); + uint8_t status; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); + if (!conn) { + return BTP_STATUS_FAILED; + } + + if (cp->enable) { /* on success response will be sent from callback */ - if (enable_subscription(conn, ccc_handle, value) == 0) { + if (enable_subscription(conn, ccc_handle, BT_GATT_CCC_INDICATE) == 0) { bt_conn_unref(conn); - return; + return BTP_STATUS_DELAY_REPLY; } status = BTP_STATUS_FAILED; @@ -1970,48 +2206,54 @@ static void config_subscription(uint8_t *data, uint16_t len, uint16_t op) } } - LOG_DBG("Config subscription (op %u) status %u", op, status); + LOG_DBG("Config indication subscription status %u", status); bt_conn_unref(conn); - tester_rsp(BTP_SERVICE_ID_GATT, op, CONTROLLER_INDEX, status); + return status; } - #if defined(CONFIG_BT_GATT_NOTIFY_MULTIPLE) static void notify_cb(struct bt_conn *conn, void *user_data) { LOG_DBG("Nofication sent"); } -static void notify_mult(uint8_t *data, uint16_t len, uint16_t op) +static uint8_t notify_mult(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_cfg_notify_mult_cmd *cmd = (void *) data; + const struct btp_gatt_cfg_notify_mult_cmd *cp = cmd; const size_t max_cnt = CONFIG_BT_L2CAP_TX_BUF_COUNT; struct bt_gatt_notify_params params[max_cnt]; struct bt_conn *conn; const size_t min_cnt = 1U; int err = 0; - uint8_t status = BTP_STATUS_SUCCESS; uint16_t attr_data_len = 0; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); - if (!conn) { - status = BTP_STATUS_FAILED; - goto rsp; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if ((cmd_len < sizeof(*cp)) || + (cmd_len != sizeof(*cp) + (cp->cnt * sizeof(cp->attr_id[0])))) { + return BTP_STATUS_FAILED; } - if (!IN_RANGE(cmd->cnt, min_cnt, max_cnt)) { + if (!IN_RANGE(cp->cnt, min_cnt, max_cnt)) { LOG_ERR("Invalid count value %d (range %zu to %zu)", - cmd->cnt, min_cnt, max_cnt); + cp->cnt, min_cnt, max_cnt); - status = BTP_STATUS_FAILED; - goto rsp; + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); + if (!conn) { + return BTP_STATUS_FAILED; } (void)memset(params, 0, sizeof(params)); - for (uint16_t i = 0U; i < cmd->cnt; i++) { - struct bt_gatt_attr attr = server_db[cmd->attr_id[i] - + for (uint16_t i = 0U; i < cp->cnt; i++) { + struct bt_gatt_attr attr = server_db[cp->attr_id[i] - server_db[0].handle]; attr_data_len = strtoul(attr.user_data, NULL, 16); @@ -2023,17 +2265,16 @@ static void notify_mult(uint8_t *data, uint16_t len, uint16_t op) params[i].user_data = NULL; } - err = bt_gatt_notify_multiple(conn, cmd->cnt, params); + err = bt_gatt_notify_multiple(conn, cp->cnt, params); if (err != 0) { LOG_ERR("bt_gatt_notify_multiple failed: %d", err); - status = BTP_STATUS_FAILED; - goto rsp; - } else { - LOG_DBG("Send %u notifications", cmd->cnt); + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } -rsp: - tester_rsp(BTP_SERVICE_ID_GATT, op, CONTROLLER_INDEX, status); + LOG_DBG("Send %u notifications", cp->cnt); + bt_conn_unref(conn); + return BTP_STATUS_SUCCESS; } #endif /* CONFIG_BT_GATT_NOTIFY_MULTIPLE */ @@ -2074,23 +2315,33 @@ static uint8_t get_attrs_rp(const struct bt_gatt_attr *attr, uint16_t handle, return BT_GATT_ITER_CONTINUE; } -static void get_attrs(uint8_t *data, uint16_t len) +static uint8_t get_attrs(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_get_attributes_cmd *cmd = (void *) data; - struct btp_gatt_get_attributes_rp *rp; - struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE); + const struct btp_gatt_get_attributes_cmd *cp = cmd; + struct btp_gatt_get_attributes_rp *rp = rsp; + struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE - sizeof(*rp)); struct get_attrs_foreach_data foreach; uint16_t start_handle, end_handle; union uuid uuid; - start_handle = sys_le16_to_cpu(cmd->start_handle); - end_handle = sys_le16_to_cpu(cmd->end_handle); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if ((cmd_len < sizeof(*cp)) || + (cmd_len != sizeof(*cp) + cp->type_length)) { + return BTP_STATUS_FAILED; + } - if (cmd->type_length) { + start_handle = sys_le16_to_cpu(cp->start_handle); + end_handle = sys_le16_to_cpu(cp->end_handle); + + if (cp->type_length) { char uuid_str[BT_UUID_STR_LEN]; - if (btp2bt_uuid(cmd->type, cmd->type_length, &uuid.uuid)) { - goto fail; + if (btp2bt_uuid(cp->type, cp->type_length, &uuid.uuid)) { + return BTP_STATUS_FAILED; } bt_uuid_to_str(&uuid.uuid, uuid_str, sizeof(uuid_str)); @@ -2104,23 +2355,19 @@ static void get_attrs(uint8_t *data, uint16_t len) foreach.uuid = NULL; } - net_buf_simple_init(buf, sizeof(*rp)); + net_buf_simple_init(buf, 0); foreach.buf = buf; foreach.count = 0U; bt_gatt_foreach_attr(start_handle, end_handle, get_attrs_rp, &foreach); - rp = net_buf_simple_push(buf, sizeof(*rp)); + (void)memcpy(rp->attrs, buf->data, buf->len); rp->attrs_count = foreach.count; - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_GET_ATTRIBUTES, CONTROLLER_INDEX, - buf->data, buf->len); + *rsp_len = sizeof(*rp) + buf->len; - return; -fail: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_GET_ATTRIBUTES, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } static uint8_t err_to_att(int err) @@ -2168,14 +2415,19 @@ static uint8_t get_attr_val_rp(const struct bt_gatt_attr *attr, uint16_t handle, return BT_GATT_ITER_STOP; } -static void get_attr_val(uint8_t *data, uint16_t len) +static uint8_t get_attr_val(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_get_attribute_value_cmd *cmd = (void *) data; + const struct btp_gatt_get_attribute_value_cmd *cp = cmd; struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE); - uint16_t handle = sys_le16_to_cpu(cmd->handle); + uint16_t handle = sys_le16_to_cpu(cp->handle); struct bt_conn *conn; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)cmd); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); net_buf_simple_init(buf, 0); @@ -2184,135 +2436,193 @@ static void get_attr_val(uint8_t *data, uint16_t len) bt_gatt_foreach_attr(handle, handle, get_attr_val_rp, &cb_data); if (buf->len) { - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_GET_ATTRIBUTE_VALUE, - CONTROLLER_INDEX, buf->data, buf->len); - } else { - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_GET_ATTRIBUTE_VALUE, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + (void)memcpy(rsp, buf->data, buf->len); + *rsp_len = buf->len; + return BTP_STATUS_SUCCESS; } + + return BTP_STATUS_FAILED; } -static void eatt_connect(uint8_t *data, uint16_t len) +static uint8_t eatt_connect(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_gatt_eatt_connect_cmd *cmd = (void *)data; + const struct btp_gatt_eatt_connect_cmd *cp = cmd; struct bt_conn *conn; - uint8_t status = BTP_STATUS_SUCCESS; int err; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)cmd); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { - status = BTP_STATUS_FAILED; - goto response; + return BTP_STATUS_FAILED; } - err = bt_eatt_connect(conn, cmd->num_channels); + err = bt_eatt_connect(conn, cp->num_channels); if (err) { - status = BTP_STATUS_FAILED; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } bt_conn_unref(conn); - -response: - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_EATT_CONNECT, CONTROLLER_INDEX, status); -} - -void tester_handle_gatt(uint8_t opcode, uint8_t index, uint8_t *data, - uint16_t len) -{ - switch (opcode) { - case BTP_GATT_READ_SUPPORTED_COMMANDS: - supported_commands(data, len); - return; - case BTP_GATT_ADD_SERVICE: - add_service(data, len); - return; - case BTP_GATT_ADD_CHARACTERISTIC: - add_characteristic(data, len); - return; - case BTP_GATT_ADD_DESCRIPTOR: - add_descriptor(data, len); - return; - case BTP_GATT_ADD_INCLUDED_SERVICE: - add_included(data, len); - return; - case BTP_GATT_SET_VALUE: - set_value(data, len); - return; - case BTP_GATT_START_SERVER: - start_server(data, len); - return; - case BTP_GATT_SET_ENC_KEY_SIZE: - set_enc_key_size(data, len); - return; - case BTP_GATT_EXCHANGE_MTU: - exchange_mtu(data, len); - return; - case BTP_GATT_DISC_ALL_PRIM: - disc_all_prim(data, len); - return; - case BTP_GATT_DISC_PRIM_UUID: - disc_prim_uuid(data, len); - return; - case BTP_GATT_FIND_INCLUDED: - find_included(data, len); - return; - case BTP_GATT_DISC_ALL_CHRC: - disc_all_chrc(data, len); - return; - case BTP_GATT_DISC_CHRC_UUID: - disc_chrc_uuid(data, len); - return; - case BTP_GATT_DISC_ALL_DESC: - disc_all_desc(data, len); - return; - case BTP_GATT_READ: - read_data(data, len); - return; - case BTP_GATT_READ_UUID: - read_uuid(data, len); - return; - case BTP_GATT_READ_LONG: - read_long(data, len); - return; - case BTP_GATT_READ_MULTIPLE: - case BTP_GATT_READ_MULTIPLE_VAR: - read_multiple(data, len, opcode); - return; - case BTP_GATT_WRITE_WITHOUT_RSP: - write_without_rsp(data, len, opcode, false); - return; - case BTP_GATT_SIGNED_WRITE_WITHOUT_RSP: - write_without_rsp(data, len, opcode, true); - return; - case BTP_GATT_WRITE: - write_data(data, len); - return; - case BTP_GATT_WRITE_LONG: - write_long(data, len); - return; - case BTP_GATT_CFG_NOTIFY: - case BTP_GATT_CFG_INDICATE: - config_subscription(data, len, opcode); - return; - case BTP_GATT_GET_ATTRIBUTES: - get_attrs(data, len); - return; - case BTP_GATT_GET_ATTRIBUTE_VALUE: - get_attr_val(data, len); - return; - case BTP_GATT_EATT_CONNECT: - eatt_connect(data, len); - return; - case BTP_GATT_NOTIFY_MULTIPLE: - notify_mult(data, len, opcode); - return; - default: - tester_rsp(BTP_SERVICE_ID_GATT, opcode, index, - BTP_STATUS_UNKNOWN_CMD); - return; - } + return BTP_STATUS_SUCCESS; } +static const struct btp_handler handlers[] = { + { + .opcode = BTP_GATT_READ_SUPPORTED_COMMANDS, + .expect_len = 0, + .func = supported_commands, + }, + { + .opcode = BTP_GATT_ADD_SERVICE, + .expect_len = -1, + .func = add_service, + }, + { + .opcode = BTP_GATT_ADD_CHARACTERISTIC, + .expect_len = -1, + .func = add_characteristic, + }, + { + .opcode = BTP_GATT_ADD_DESCRIPTOR, + .expect_len = -1, + .func = add_descriptor, + }, + { + .opcode = BTP_GATT_ADD_INCLUDED_SERVICE, + .expect_len = sizeof(struct btp_gatt_add_included_service_cmd), + .func = add_included, + }, + { + .opcode = BTP_GATT_SET_VALUE, + .expect_len = -1, + .func = set_value, + }, + { + .opcode = BTP_GATT_START_SERVER, + .expect_len = 0, + .func = start_server, + }, + { + .opcode = BTP_GATT_SET_ENC_KEY_SIZE, + .expect_len = sizeof(struct btp_gatt_set_enc_key_size_cmd), + .func = set_enc_key_size, + }, + { + .opcode = BTP_GATT_EXCHANGE_MTU, + .expect_len = sizeof(struct btp_gatt_exchange_mtu_cmd), + .func = exchange_mtu, + }, + { + .opcode = BTP_GATT_DISC_ALL_PRIM, + .expect_len = sizeof(struct btp_gatt_disc_all_prim_cmd), + .func = disc_all_prim, + }, + { + .opcode = BTP_GATT_DISC_PRIM_UUID, + .expect_len = -1, + .func = disc_prim_uuid, + }, + { + .opcode = BTP_GATT_FIND_INCLUDED, + .expect_len = sizeof(struct btp_gatt_find_included_cmd), + .func = find_included, + }, + { + .opcode = BTP_GATT_DISC_ALL_CHRC, + .expect_len = sizeof(struct btp_gatt_disc_all_chrc_cmd), + .func = disc_all_chrc, + }, + { + .opcode = BTP_GATT_DISC_CHRC_UUID, + .expect_len = -1, + .func = disc_chrc_uuid, + }, + { + .opcode = BTP_GATT_DISC_ALL_DESC, + .expect_len = sizeof(struct btp_gatt_disc_all_desc_cmd), + .func = disc_all_desc, + }, + { + .opcode = BTP_GATT_READ, + .expect_len = sizeof(struct btp_gatt_read_cmd), + .func = read_data, + }, + { + .opcode = BTP_GATT_READ_UUID, + .expect_len = -1, + .func = read_uuid, + }, + { + .opcode = BTP_GATT_READ_LONG, + .expect_len = sizeof(struct btp_gatt_read_long_cmd), + .func = read_long, + }, + { + .opcode = BTP_GATT_READ_MULTIPLE, + .expect_len = -1, + .func = read_multiple, + }, + { + .opcode = BTP_GATT_WRITE_WITHOUT_RSP, + .expect_len = -1, + .func = write_without_rsp, + }, + { + .opcode = BTP_GATT_SIGNED_WRITE_WITHOUT_RSP, + .expect_len = -1, + .func = write_signed_without_rsp, + }, + { + .opcode = BTP_GATT_WRITE, + .expect_len = -1, + .func = write_data, + }, + { + .opcode = BTP_GATT_WRITE_LONG, + .expect_len = -1, + .func = write_long, + }, + { + .opcode = BTP_GATT_CFG_NOTIFY, + .expect_len = sizeof(struct btp_gatt_cfg_notify_cmd), + .func = config_subscription_notif, + }, + { + .opcode = BTP_GATT_CFG_INDICATE, + .expect_len = sizeof(struct btp_gatt_cfg_notify_cmd), + .func = config_subscription_ind, + }, + { + .opcode = BTP_GATT_GET_ATTRIBUTES, + .expect_len = -1, + .func = get_attrs, + }, + { + .opcode = BTP_GATT_GET_ATTRIBUTE_VALUE, + .expect_len = sizeof(struct btp_gatt_get_attribute_value_cmd), + .func = get_attr_val, + }, + { + .opcode = BTP_GATT_EATT_CONNECT, + .expect_len = sizeof(struct btp_gatt_eatt_connect_cmd), + .func = eatt_connect, + }, + { + .opcode = BTP_GATT_READ_MULTIPLE_VAR, + .expect_len = -1, + .func = read_multiple_var, + }, + { + .opcode = BTP_GATT_NOTIFY_MULTIPLE, + .expect_len = -1, + .func = notify_mult, + }, +}; + uint8_t tester_init_gatt(void) { server_buf = net_buf_alloc(&server_pool, K_NO_WAIT); @@ -2322,6 +2632,9 @@ uint8_t tester_init_gatt(void) net_buf_reserve(server_buf, SERVER_BUF_SIZE); + tester_register_command_handlers(BTP_SERVICE_ID_GATT, handlers, + ARRAY_SIZE(handlers)); + return BTP_STATUS_SUCCESS; } From 43bf912e60b1cc55dde18f415a15a99116901b24 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 22 Feb 2023 13:32:05 +0100 Subject: [PATCH 0026/1906] bluetooth: tester: Convert L2CAP service to new BTP API This makes L2CAP service to use new BTP command handlers API. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp/btp_l2cap.h | 36 +- tests/bluetooth/tester/src/btp/bttester.h | 2 - tests/bluetooth/tester/src/btp_l2cap.c | 384 +++++++++++---------- 3 files changed, 225 insertions(+), 197 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_l2cap.h b/tests/bluetooth/tester/src/btp/btp_l2cap.h index f01a8abe19d7..269c4ee826a4 100644 --- a/tests/bluetooth/tester/src/btp/btp_l2cap.h +++ b/tests/bluetooth/tester/src/btp/btp_l2cap.h @@ -12,15 +12,15 @@ /* L2CAP Service */ /* commands */ -#define BTP_L2CAP_READ_SUPPORTED_COMMANDS 0x01 +#define BTP_L2CAP_READ_SUPPORTED_COMMANDS 0x01 struct btp_l2cap_read_supported_commands_rp { uint8_t data[0]; } __packed; -#define BTP_L2CAP_CONNECT_OPT_ECFC 0x01 -#define BTP_L2CAP_CONNECT_OPT_HOLD_CREDIT 0x02 +#define BTP_L2CAP_CONNECT_OPT_ECFC 0x01 +#define BTP_L2CAP_CONNECT_OPT_HOLD_CREDIT 0x02 -#define BTP_L2CAP_CONNECT 0x02 +#define BTP_L2CAP_CONNECT 0x02 struct btp_l2cap_connect_cmd { bt_addr_le_t address; uint16_t psm; @@ -33,27 +33,27 @@ struct btp_l2cap_connect_rp { uint8_t chan_id[]; } __packed; -#define BTP_L2CAP_DISCONNECT 0x03 +#define BTP_L2CAP_DISCONNECT 0x03 struct btp_l2cap_disconnect_cmd { uint8_t chan_id; } __packed; -#define BTP_L2CAP_SEND_DATA 0x04 +#define BTP_L2CAP_SEND_DATA 0x04 struct btp_l2cap_send_data_cmd { uint8_t chan_id; uint16_t data_len; uint8_t data[]; } __packed; -#define BTP_L2CAP_TRANSPORT_BREDR 0x00 -#define BTP_L2CAP_TRANSPORT_LE 0x01 +#define BTP_L2CAP_TRANSPORT_BREDR 0x00 +#define BTP_L2CAP_TRANSPORT_LE 0x01 #define BTP_L2CAP_CONNECTION_RESPONSE_SUCCESS 0x00 #define BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHEN 0x01 #define BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHOR 0x02 #define BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_ENC_KEY 0x03 -#define BTP_L2CAP_LISTEN 0x05 +#define BTP_L2CAP_LISTEN 0x05 struct btp_l2cap_listen_cmd { uint16_t psm; uint8_t transport; @@ -61,13 +61,13 @@ struct btp_l2cap_listen_cmd { uint16_t response; } __packed; -#define BTP_L2CAP_ACCEPT_CONNECTION 0x06 +#define BTP_L2CAP_ACCEPT_CONNECTION 0x06 struct btp_l2cap_accept_connection_cmd { uint8_t chan_id; uint16_t result; } __packed; -#define BTP_L2CAP_RECONFIGURE 0x07 +#define BTP_L2CAP_RECONFIGURE 0x07 struct btp_l2cap_reconfigure_cmd { bt_addr_le_t address; uint16_t mtu; @@ -75,26 +75,26 @@ struct btp_l2cap_reconfigure_cmd { uint8_t chan_id[]; } __packed; -#define BTP_L2CAP_CREDITS 0x08 +#define BTP_L2CAP_CREDITS 0x08 struct btp_l2cap_credits_cmd { uint8_t chan_id; } __packed; -#define BTP_L2CAP_DISCONNECT_EATT_CHANS 0x09 +#define BTP_L2CAP_DISCONNECT_EATT_CHANS 0x09 struct btp_l2cap_disconnect_eatt_chans_cmd { bt_addr_le_t address; uint8_t count; } __packed; /* events */ -#define BTP_L2CAP_EV_CONNECTION_REQ 0x80 +#define BTP_L2CAP_EV_CONNECTION_REQ 0x80 struct btp_l2cap_connection_req_ev { uint8_t chan_id; uint16_t psm; bt_addr_le_t address; } __packed; -#define BTP_L2CAP_EV_CONNECTED 0x81 +#define BTP_L2CAP_EV_CONNECTED 0x81 struct btp_l2cap_connected_ev { uint8_t chan_id; uint16_t psm; @@ -105,7 +105,7 @@ struct btp_l2cap_connected_ev { bt_addr_le_t address; } __packed; -#define BTP_L2CAP_EV_DISCONNECTED 0x82 +#define BTP_L2CAP_EV_DISCONNECTED 0x82 struct btp_l2cap_disconnected_ev { uint16_t result; uint8_t chan_id; @@ -113,14 +113,14 @@ struct btp_l2cap_disconnected_ev { bt_addr_le_t address; } __packed; -#define BTP_L2CAP_EV_DATA_RECEIVED 0x83 +#define BTP_L2CAP_EV_DATA_RECEIVED 0x83 struct btp_l2cap_data_received_ev { uint8_t chan_id; uint16_t data_length; uint8_t data[]; } __packed; -#define BTP_L2CAP_EV_RECONFIGURED 0x84 +#define BTP_L2CAP_EV_RECONFIGURED 0x84 struct btp_l2cap_reconfigured_ev { uint8_t chan_id; uint16_t mtu_remote; diff --git a/tests/bluetooth/tester/src/btp/bttester.h b/tests/bluetooth/tester/src/btp/bttester.h index 1f290cd9f340..3314c1d70dba 100644 --- a/tests/bluetooth/tester/src/btp/bttester.h +++ b/tests/bluetooth/tester/src/btp/bttester.h @@ -47,8 +47,6 @@ uint8_t tester_unregister_gatt(void); uint8_t tester_init_l2cap(void); uint8_t tester_unregister_l2cap(void); -void tester_handle_l2cap(uint8_t opcode, uint8_t index, uint8_t *data, - uint16_t len); uint8_t tester_init_mesh(void); uint8_t tester_unregister_mesh(void); diff --git a/tests/bluetooth/tester/src/btp_l2cap.c b/tests/bluetooth/tester/src/btp_l2cap.c index 295a6b4ec0bb..9f61f22cd512 100644 --- a/tests/bluetooth/tester/src/btp_l2cap.c +++ b/tests/bluetooth/tester/src/btp_l2cap.c @@ -187,32 +187,34 @@ static struct channel *get_free_channel() return NULL; } - -static void connect(uint8_t *data, uint16_t len) +static uint8_t connect(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_l2cap_connect_cmd *cmd = (void *) data; - struct btp_l2cap_connect_rp *rp; + const struct btp_l2cap_connect_cmd *cp = cmd; + struct btp_l2cap_connect_rp *rp = rsp; struct bt_conn *conn; struct channel *chan = NULL; struct bt_l2cap_chan *allocated_channels[5] = {}; - uint16_t mtu = sys_le16_to_cpu(cmd->mtu); - uint8_t buf[sizeof(*rp) + CHANNELS]; + uint16_t mtu = sys_le16_to_cpu(cp->mtu); + uint16_t psm = sys_le16_to_cpu(cp->psm); uint8_t i = 0; - bool ecfc = cmd->options & BTP_L2CAP_CONNECT_OPT_ECFC; + bool ecfc = cp->options & BTP_L2CAP_CONNECT_OPT_ECFC; int err; - if (cmd->num == 0 || cmd->num > CHANNELS || mtu > DATA_MTU_INITIAL) { - goto fail; + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); - if (!conn) { - goto fail; + if (cp->num == 0 || cp->num > CHANNELS || mtu > DATA_MTU_INITIAL) { + return BTP_STATUS_FAILED; } - rp = (void *)buf; + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); + if (!conn) { + return BTP_STATUS_FAILED; + } - for (i = 0U; i < cmd->num; i++) { + for (i = 0U; i < cp->num; i++) { chan = get_free_channel(); if (!chan) { goto fail; @@ -222,18 +224,18 @@ static void connect(uint8_t *data, uint16_t len) rp->chan_id[i] = chan->chan_id; allocated_channels[i] = &chan->le.chan; - chan->hold_credit = cmd->options & BTP_L2CAP_CONNECT_OPT_HOLD_CREDIT; + chan->hold_credit = cp->options & BTP_L2CAP_CONNECT_OPT_HOLD_CREDIT; } - if (cmd->num == 1 && !ecfc) { - err = bt_l2cap_chan_connect(conn, &chan->le.chan, cmd->psm); + if (cp->num == 1 && !ecfc) { + err = bt_l2cap_chan_connect(conn, &chan->le.chan, psm); if (err < 0) { goto fail; } } else if (ecfc) { #if defined(CONFIG_BT_L2CAP_ECRED) err = bt_l2cap_ecred_chan_connect(conn, allocated_channels, - cmd->psm); + psm); if (err < 0) { goto fail; } @@ -245,12 +247,10 @@ static void connect(uint8_t *data, uint16_t len) goto fail; } - rp->num = cmd->num; - - tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_CONNECT, CONTROLLER_INDEX, - (uint8_t *)rp, sizeof(*rp) + rp->num); + rp->num = cp->num; + *rsp_len = sizeof(*rp) + (rp->num * sizeof(rp->chan_id[0])); - return; + return BTP_STATUS_SUCCESS; fail: for (i = 0U; i < ARRAY_SIZE(allocated_channels); i++) { @@ -258,151 +258,167 @@ static void connect(uint8_t *data, uint16_t len) channels[BT_L2CAP_LE_CHAN(allocated_channels[i])->ident].in_use = false; } } - tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_CONNECT, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_FAILED; } -static void disconnect(uint8_t *data, uint16_t len) +static uint8_t disconnect(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_l2cap_disconnect_cmd *cmd = (void *) data; - struct channel *chan = &channels[cmd->chan_id]; - uint8_t status; + const struct btp_l2cap_disconnect_cmd *cp = cmd; + struct channel *chan; int err; + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } + + if (cp->chan_id >= CHANNELS) { + return BTP_STATUS_FAILED; + } + + chan = &channels[cp->chan_id]; + err = bt_l2cap_chan_disconnect(&chan->le.chan); if (err) { - status = BTP_STATUS_FAILED; - goto rsp; + return BTP_STATUS_FAILED; } - status = BTP_STATUS_SUCCESS; - -rsp: - tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_DISCONNECT, CONTROLLER_INDEX, - status); + return BTP_STATUS_SUCCESS; } #if defined(CONFIG_BT_L2CAP_ECRED) -static void reconfigure(uint8_t *data, uint16_t len) +static uint8_t reconfigure(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_l2cap_reconfigure_cmd *cmd = (void *)data; - uint16_t mtu = sys_le16_to_cpu(cmd->mtu); + const struct btp_l2cap_reconfigure_cmd *cp = cmd; + uint16_t mtu; struct bt_conn *conn; - uint8_t status; int err; - struct bt_l2cap_chan *reconf_channels[CHANNELS + 1] = {}; - /* address is first in data */ - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)cmd); - if (!conn) { - LOG_ERR("Unknown connection"); - status = BTP_STATUS_FAILED; - goto rsp; + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } + + if (cmd_len < sizeof(*cp) || + cmd_len != sizeof(*cp) + cp->num) { + return BTP_STATUS_FAILED; } - if (cmd->num > CHANNELS) { - status = BTP_STATUS_FAILED; - goto rsp; + if (cp->num > CHANNELS) { + return BTP_STATUS_FAILED; } + mtu = sys_le16_to_cpu(cp->mtu); if (mtu > DATA_MTU) { - status = BTP_STATUS_FAILED; - goto rsp; + return BTP_STATUS_FAILED; } - for (int i = 0; i < cmd->num; i++) { - if (cmd->chan_id[i] > CHANNELS) { - status = BTP_STATUS_FAILED; - goto rsp; + for (int i = 0; i < cp->num; i++) { + if (cp->chan_id[i] > CHANNELS) { + return BTP_STATUS_FAILED; } - reconf_channels[i] = &channels[cmd->chan_id[i]].le.chan; + reconf_channels[i] = &channels[cp->chan_id[i]].le.chan; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); + if (!conn) { + LOG_ERR("Unknown connection"); + return BTP_STATUS_FAILED; } err = bt_l2cap_ecred_chan_reconfigure(reconf_channels, mtu); if (err) { - status = BTP_STATUS_FAILED; - goto rsp; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } - status = BTP_STATUS_SUCCESS; - -rsp: - tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_RECONFIGURE, CONTROLLER_INDEX, - status); + bt_conn_unref(conn); + return BTP_STATUS_SUCCESS; } #endif #if defined(CONFIG_BT_EATT) -void disconnect_eatt_chans(uint8_t *data, uint16_t len) +static uint8_t disconnect_eatt_chans(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_l2cap_disconnect_eatt_chans_cmd *cmd = (void *) data; + const struct btp_l2cap_disconnect_eatt_chans_cmd *cp = cmd; struct bt_conn *conn; int err; - int status; - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data); + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } + + conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { LOG_ERR("Unknown connection"); - status = BTP_STATUS_FAILED; - goto failed; + return BTP_STATUS_FAILED; } - for (int i = 0; i < cmd->count; i++) { + for (int i = 0; i < cp->count; i++) { err = bt_eatt_disconnect_one(conn); if (err) { - status = BTP_STATUS_FAILED; - goto unref; + bt_conn_unref(conn); + return BTP_STATUS_FAILED; } } - status = BTP_STATUS_SUCCESS; - -unref: bt_conn_unref(conn); -failed: - tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_DISCONNECT_EATT_CHANS, - CONTROLLER_INDEX, status); + return BTP_STATUS_SUCCESS; } #endif -static void send_data(uint8_t *data, uint16_t len) + +static uint8_t send_data(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_l2cap_send_data_cmd *cmd = (void *) data; - struct channel *chan = &channels[cmd->chan_id]; + const struct btp_l2cap_send_data_cmd *cp = cmd; + struct channel *chan; struct net_buf *buf; + uint16_t data_len; int ret; - uint16_t data_len = sys_le16_to_cpu(cmd->data_len); + + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } + + if (cmd_len < sizeof(*cp) || + cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_len)) { + return BTP_STATUS_FAILED; + } + + if (cp->chan_id >= CHANNELS) { + return BTP_STATUS_FAILED; + } + + chan = &channels[cp->chan_id]; + data_len = sys_le16_to_cpu(cp->data_len); + /* FIXME: For now, fail if data length exceeds buffer length */ if (data_len > DATA_MTU) { - goto fail; + return BTP_STATUS_FAILED; } /* FIXME: For now, fail if data length exceeds remote's L2CAP SDU */ if (data_len > chan->le.tx.mtu) { - goto fail; + return BTP_STATUS_FAILED; } buf = net_buf_alloc(&data_pool, K_FOREVER); net_buf_reserve(buf, BT_L2CAP_SDU_CHAN_SEND_RESERVE); - net_buf_add_mem(buf, cmd->data, data_len); + net_buf_add_mem(buf, cp->data, data_len); ret = bt_l2cap_chan_send(&chan->le.chan, buf); if (ret < 0) { LOG_ERR("Unable to send data: %d", -ret); net_buf_unref(buf); - goto fail; + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_SEND_DATA, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); - return; - -fail: - tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_SEND_DATA, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } static struct bt_l2cap_server *get_free_server(void) @@ -458,143 +474,157 @@ static int accept(struct bt_conn *conn, struct bt_l2cap_chan **l2cap_chan) return 0; } -static void listen(uint8_t *data, uint16_t len) +static uint8_t listen(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_l2cap_listen_cmd *cmd = (void *) data; + const struct btp_l2cap_listen_cmd *cp = cmd; struct bt_l2cap_server *server; + uint16_t psm = sys_le16_to_cpu(cp->psm); /* TODO: Handle cmd->transport flag */ - if (!is_free_psm(cmd->psm)) { - goto fail; + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; } - if (cmd->psm == 0) { - goto fail; + if (psm == 0 || !is_free_psm(psm)) { + return BTP_STATUS_FAILED; } server = get_free_server(); if (!server) { - goto fail; + return BTP_STATUS_FAILED; } server->accept = accept; - server->psm = cmd->psm; + server->psm = psm; - if (cmd->response == BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_ENC_KEY) { + if (cp->response == BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_ENC_KEY) { /* TSPX_psm_encryption_key_size_required */ req_keysize = 16; - } else if (cmd->response == BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHOR) { + } else if (cp->response == BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHOR) { authorize_flag = true; - } else if (cmd->response == BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHEN) { + } else if (cp->response == BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHEN) { server->sec_level = BT_SECURITY_L3; } if (bt_l2cap_server_register(server) < 0) { server->psm = 0U; - goto fail; + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_LISTEN, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); - return; - -fail: - tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_LISTEN, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void credits(uint8_t *data, uint16_t len) +static uint8_t credits(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_l2cap_credits_cmd *cmd = (void *)data; - struct channel *chan = &channels[cmd->chan_id]; + const struct btp_l2cap_credits_cmd *cp = cmd; + struct channel *chan; + + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } + + if (cp->chan_id >= CHANNELS) { + return BTP_STATUS_FAILED; + } + + chan = &channels[cp->chan_id]; if (!chan->in_use) { - goto fail; + return BTP_STATUS_FAILED; } if (chan->pending_credit) { if (bt_l2cap_chan_recv_complete(&chan->le.chan, chan->pending_credit) < 0) { - goto fail; + return BTP_STATUS_FAILED; } chan->pending_credit = NULL; } - tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_CREDITS, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); - return; - -fail: - tester_rsp(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_CREDITS, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void supported_commands(uint8_t *data, uint16_t len) +static uint8_t supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - uint8_t cmds[2]; - struct btp_l2cap_read_supported_commands_rp *rp = (void *) cmds; + struct btp_l2cap_read_supported_commands_rp *rp = rsp; - (void)memset(cmds, 0, sizeof(cmds)); + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } - tester_set_bit(cmds, BTP_L2CAP_READ_SUPPORTED_COMMANDS); - tester_set_bit(cmds, BTP_L2CAP_CONNECT); - tester_set_bit(cmds, BTP_L2CAP_DISCONNECT); - tester_set_bit(cmds, BTP_L2CAP_LISTEN); - tester_set_bit(cmds, BTP_L2CAP_SEND_DATA); + /* octet 0 */ + tester_set_bit(rp->data, BTP_L2CAP_READ_SUPPORTED_COMMANDS); + tester_set_bit(rp->data, BTP_L2CAP_CONNECT); + tester_set_bit(rp->data, BTP_L2CAP_DISCONNECT); + tester_set_bit(rp->data, BTP_L2CAP_SEND_DATA); + tester_set_bit(rp->data, BTP_L2CAP_LISTEN); #if defined(CONFIG_BT_L2CAP_ECRED) - tester_set_bit(cmds, BTP_L2CAP_RECONFIGURE); + tester_set_bit(rp->data, BTP_L2CAP_RECONFIGURE); #endif - tester_set_bit(cmds, BTP_L2CAP_CREDITS); + /* octet 1 */ + tester_set_bit(rp->data, BTP_L2CAP_CREDITS); #if defined(CONFIG_BT_EATT) - tester_set_bit(cmds, BTP_L2CAP_DISCONNECT_EATT_CHANS); + tester_set_bit(rp->data, BTP_L2CAP_DISCONNECT_EATT_CHANS); #endif - tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_READ_SUPPORTED_COMMANDS, - CONTROLLER_INDEX, (uint8_t *) rp, sizeof(cmds)); -} -void tester_handle_l2cap(uint8_t opcode, uint8_t index, uint8_t *data, - uint16_t len) -{ - switch (opcode) { - case BTP_L2CAP_READ_SUPPORTED_COMMANDS: - supported_commands(data, len); - return; - case BTP_L2CAP_CONNECT: - connect(data, len); - return; - case BTP_L2CAP_DISCONNECT: - disconnect(data, len); - return; - case BTP_L2CAP_SEND_DATA: - send_data(data, len); - return; - case BTP_L2CAP_LISTEN: - listen(data, len); - return; -#if defined(CONFIG_BT_L2CAP_ECRED) - case BTP_L2CAP_RECONFIGURE: - reconfigure(data, len); - return; -#endif - case BTP_L2CAP_CREDITS: - credits(data, len); - return; -#if defined(CONFIG_BT_EATT) - case BTP_L2CAP_DISCONNECT_EATT_CHANS: - disconnect_eatt_chans(data, len); - return; -#endif - default: - tester_rsp(BTP_SERVICE_ID_L2CAP, opcode, index, - BTP_STATUS_UNKNOWN_CMD); - return; - } + *rsp_len = sizeof(*rp) + 2; + + return BTP_STATUS_SUCCESS; } +static const struct btp_handler handlers[] = { + { + .opcode = BTP_L2CAP_READ_SUPPORTED_COMMANDS, + .expect_len = 0, + .func = supported_commands, + }, + { + .opcode = BTP_L2CAP_CONNECT, + .expect_len = sizeof(struct btp_l2cap_connect_cmd), + .func = connect, + }, + { + .opcode = BTP_L2CAP_DISCONNECT, + .expect_len = sizeof(struct btp_l2cap_disconnect_cmd), + .func = disconnect, + }, + { + .opcode = BTP_L2CAP_SEND_DATA, + .expect_len = -1, + .func = send_data, + }, + { + .opcode = BTP_L2CAP_LISTEN, + .expect_len = sizeof(struct btp_l2cap_listen_cmd), + .func = listen, + }, + { + .opcode = BTP_L2CAP_RECONFIGURE, + .expect_len = -1, + .func = reconfigure, + }, + { + .opcode = BTP_L2CAP_CREDITS, + .expect_len = sizeof(struct btp_l2cap_credits_cmd), + .func = credits, + }, + { + .opcode = BTP_L2CAP_DISCONNECT_EATT_CHANS, + .expect_len = sizeof(struct btp_l2cap_disconnect_eatt_chans_cmd), + .func = disconnect_eatt_chans, + }, +}; + uint8_t tester_init_l2cap(void) { + tester_register_command_handlers(BTP_SERVICE_ID_L2CAP, handlers, + ARRAY_SIZE(handlers)); + return BTP_STATUS_SUCCESS; } From c1efda1cb1b9e9a1152c9bcf3e4484e64aa84529 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 22 Feb 2023 16:03:13 +0100 Subject: [PATCH 0027/1906] bluetooth: tester: Cleanup BTP definitions Cleanup and unify names and conventions in BTP headers. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp/btp_aics.h | 31 +++++++++++++---------- tests/bluetooth/tester/src/btp/btp_vcs.h | 17 ++++++++----- tests/bluetooth/tester/src/btp/btp_vocs.h | 18 +++++++------ tests/bluetooth/tester/src/btp_vcp.c | 8 +++--- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_aics.h b/tests/bluetooth/tester/src/btp/btp_aics.h index addd0b4f9fce..41a523905919 100644 --- a/tests/bluetooth/tester/src/btp/btp_aics.h +++ b/tests/bluetooth/tester/src/btp/btp_aics.h @@ -8,23 +8,28 @@ #include -#define BTP_AICS_READ_SUPPORTED_COMMANDS 0x01 - -#define BTP_AICS_SET_GAIN 0x02 -#define BTP_AICS_MUTE 0x03 -#define BTP_AICS_UNMUTE 0x04 -#define BTP_AICS_MAN_GAIN 0x05 -#define BTP_AICS_AUTO_GAIN 0x06 -#define BTP_AICS_MAN_GAIN_ONLY 0x07 -#define BTP_AICS_AUTO_GAIN_ONLY 0x08 -#define BTP_AICS_DESCRIPTION 0x09 -#define BTP_AICS_MUTE_DISABLE 0x0a +/*AICS service */ +#define BTP_AICS_READ_SUPPORTED_COMMANDS 0x01 +struct btp_aics_read_supported_commands_rp { + uint8_t data[0]; +} __packed; -struct btp_aics_set_gain { +#define BTP_AICS_SET_GAIN 0x02 +struct btp_aics_set_gain_cmd { int8_t gain; } __packed; -struct btp_aics_audio_desc { +#define BTP_AICS_MUTE 0x03 +#define BTP_AICS_UNMUTE 0x04 +#define BTP_AICS_MAN_GAIN 0x05 +#define BTP_AICS_AUTO_GAIN 0x06 +#define BTP_AICS_MAN_GAIN_ONLY 0x07 +#define BTP_AICS_AUTO_GAIN_ONLY 0x08 + +#define BTP_AICS_DESCRIPTION 0x09 +struct btp_aics_audio_desc_cmd { uint8_t desc_len; uint8_t desc[0]; } __packed; + +#define BTP_AICS_MUTE_DISABLE 0x0a diff --git a/tests/bluetooth/tester/src/btp/btp_vcs.h b/tests/bluetooth/tester/src/btp/btp_vcs.h index 2ff466a161ea..522073f6a92a 100644 --- a/tests/bluetooth/tester/src/btp/btp_vcs.h +++ b/tests/bluetooth/tester/src/btp/btp_vcs.h @@ -8,14 +8,17 @@ #include -#define BTP_VCS_READ_SUPPORTED_COMMANDS 0x01 - -#define BTP_VCS_SET_VOL 0x02 -#define BTP_VCS_VOL_UP 0x03 -#define BTP_VCS_VOL_DOWN 0x04 -#define BTP_VCS_MUTE 0x05 -#define BTP_VCS_UNMUTE 0x06 +#define BTP_VCS_READ_SUPPORTED_COMMANDS 0x01 +struct btp_vcs_read_supported_commands_rp { + uint8_t data[0]; +} __packed; +#define BTP_VCS_SET_VOL 0x02 struct btp_vcs_set_vol_cmd { uint8_t volume; } __packed; + +#define BTP_VCS_VOL_UP 0x03 +#define BTP_VCS_VOL_DOWN 0x04 +#define BTP_VCS_MUTE 0x05 +#define BTP_VCS_UNMUTE 0x06 diff --git a/tests/bluetooth/tester/src/btp/btp_vocs.h b/tests/bluetooth/tester/src/btp/btp_vocs.h index 8397b90cc30b..cb9621c94542 100644 --- a/tests/bluetooth/tester/src/btp/btp_vocs.h +++ b/tests/bluetooth/tester/src/btp/btp_vocs.h @@ -8,16 +8,18 @@ #include -#define BTP_VOCS_READ_SUPPORTED_COMMANDS 0x01 +#define BTP_VOCS_READ_SUPPORTED_COMMANDS 0x01 +struct btp_vocs_read_supported_commands_rp { + uint8_t data[0]; +} __packed; -#define BTP_VOCS_UPDATE_LOC 0x02 -#define BTP_VOCS_UPDATE_DESC 0x03 +#define BTP_VOCS_UPDATE_LOC 0x02 +struct btp_vocs_audio_loc_cmd { + uint32_t loc; +} __packed; -struct btp_vocs_audio_desc { +#define BTP_VOCS_UPDATE_DESC 0x03 +struct btp_vocs_audio_desc_cmd { uint8_t desc_len; uint8_t desc[0]; } __packed; - -struct btp_vocs_audio_loc { - uint32_t loc; -} __packed; diff --git a/tests/bluetooth/tester/src/btp_vcp.c b/tests/bluetooth/tester/src/btp_vcp.c index 308a8f8675a1..95a6b2c24bdd 100644 --- a/tests/bluetooth/tester/src/btp_vcp.c +++ b/tests/bluetooth/tester/src/btp_vcp.c @@ -226,7 +226,7 @@ static struct bt_aics_cb aics_cb = { void aics_set_gain(uint8_t *data) { - const struct btp_aics_set_gain *cmd = (void *)data; + const struct btp_aics_set_gain_cmd *cmd = (void *)data; const int8_t gain = cmd->gain; @@ -337,7 +337,7 @@ void aics_mute_disable(void) void aics_desc(uint8_t *data) { - const struct btp_aics_audio_desc *cmd = (void *) data; + const struct btp_aics_audio_desc_cmd *cmd = (void *) data; char description[BT_AICS_MAX_INPUT_DESCRIPTION_SIZE]; LOG_DBG("AICS description"); @@ -441,7 +441,7 @@ static struct bt_vocs_cb vocs_cb = { void vocs_audio_desc(uint8_t *data) { - struct btp_vocs_audio_desc *cmd = (void *) data; + struct btp_vocs_audio_desc_cmd *cmd = (void *) data; char description[BT_AICS_MAX_OUTPUT_DESCRIPTION_SIZE]; LOG_DBG("VOCS description"); @@ -469,7 +469,7 @@ void vocs_audio_desc(uint8_t *data) void vocs_audio_loc(uint8_t *data) { - const struct btp_vocs_audio_loc *cmd = (void *) data; + const struct btp_vocs_audio_loc_cmd *cmd = (void *) data; LOG_DBG("VOCS location"); From 59b75401a9d4350c5c6400650bd692dff0a499d8 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 22 Feb 2023 16:33:27 +0100 Subject: [PATCH 0028/1906] bluetooth: tester: Fix IAS service registration Make sure we don't send events if service was not registered. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp/btp_ias.h | 2 +- tests/bluetooth/tester/src/btp/bttester.h | 3 +++ tests/bluetooth/tester/src/btp_core.c | 5 ++++ tests/bluetooth/tester/src/btp_ias.c | 29 +++++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/src/btp/btp_ias.h b/tests/bluetooth/tester/src/btp/btp_ias.h index 64f5a86749b0..295aea2871aa 100644 --- a/tests/bluetooth/tester/src/btp/btp_ias.h +++ b/tests/bluetooth/tester/src/btp/btp_ias.h @@ -10,7 +10,7 @@ #include /* events */ -#define BTP_IAS_EV_OUT_ALERT_ACTION 0x80 +#define BTP_IAS_EV_OUT_ALERT_ACTION 0x80 struct btp_ias_alert_action_ev { uint8_t alert_lvl; } __packed; diff --git a/tests/bluetooth/tester/src/btp/bttester.h b/tests/bluetooth/tester/src/btp/bttester.h index 3314c1d70dba..d249eff4dd32 100644 --- a/tests/bluetooth/tester/src/btp/bttester.h +++ b/tests/bluetooth/tester/src/btp/bttester.h @@ -58,6 +58,9 @@ void tester_handle_vcs(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t le void tester_handle_aics(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len); void tester_handle_vocs(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len); +uint8_t tester_init_ias(void); +uint8_t tester_unregister_ias(void); + uint8_t tester_init_gap(void); uint8_t tester_unregister_gap(void); diff --git a/tests/bluetooth/tester/src/btp_core.c b/tests/bluetooth/tester/src/btp_core.c index f5700de96197..084007958347 100644 --- a/tests/bluetooth/tester/src/btp_core.c +++ b/tests/bluetooth/tester/src/btp_core.c @@ -215,6 +215,11 @@ static uint8_t unregister_service(uint8_t index, const void *cmd, uint16_t cmd_l status = tester_unregister_vcp(); break; #endif /* CONFIG_BT_VOCS */ +#if defined(CONFIG_BT_IAS) + case BTP_SERVICE_ID_IAS: + status = tester_unregister_ias(); + break; +#endif /* CONFIG_BT_IAS */ #if defined(CONFIG_BT_PACS) case BTP_SERVICE_ID_PACS: status = tester_unregister_bap(); diff --git a/tests/bluetooth/tester/src/btp_ias.c b/tests/bluetooth/tester/src/btp_ias.c index 1663d673b11e..e2df5bcaa2c0 100644 --- a/tests/bluetooth/tester/src/btp_ias.c +++ b/tests/bluetooth/tester/src/btp_ias.c @@ -17,11 +17,18 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #define CONTROLLER_INDEX 0 +static bool initialized; + + /* Immediate Alert Service */ static void alert_stop(void) { struct btp_ias_alert_action_ev ev; + if (!initialized) { + return; + } + ev.alert_lvl = BT_IAS_ALERT_LVL_NO_ALERT; tester_send(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, @@ -32,6 +39,10 @@ static void alert_start(void) { struct btp_ias_alert_action_ev ev; + if (!initialized) { + return; + } + ev.alert_lvl = BT_IAS_ALERT_LVL_MILD_ALERT; tester_send(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, @@ -42,6 +53,10 @@ static void alert_high_start(void) { struct btp_ias_alert_action_ev ev; + if (!initialized) { + return; + } + ev.alert_lvl = BT_IAS_ALERT_LVL_HIGH_ALERT; tester_send(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, @@ -53,3 +68,17 @@ BT_IAS_CB_DEFINE(ias_callbacks) = { .mild_alert = alert_start, .high_alert = alert_high_start, }; + +uint8_t tester_init_ias(void) +{ + initialized = true; + + return BTP_STATUS_SUCCESS; +} + +uint8_t tester_unregister_ias(void) +{ + initialized = false; + + return BTP_STATUS_SUCCESS; +} From df5fbbcc105c7f04febf2fa778e4c95951588569 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 24 Feb 2023 16:29:12 +0100 Subject: [PATCH 0029/1906] bluetooth: tester: Refactor VCP BTP Split register functions, convert to new BTP API and fix some bugs in BTP handlers. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp/bttester.h | 12 +- tests/bluetooth/tester/src/btp_core.c | 28 +- tests/bluetooth/tester/src/btp_vcp.c | 562 ++++++++++++---------- 3 files changed, 322 insertions(+), 280 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/bttester.h b/tests/bluetooth/tester/src/btp/bttester.h index d249eff4dd32..97a81ddacf17 100644 --- a/tests/bluetooth/tester/src/btp/bttester.h +++ b/tests/bluetooth/tester/src/btp/bttester.h @@ -54,9 +54,15 @@ void tester_handle_mesh(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t l uint8_t tester_init_vcp(void); uint8_t tester_unregister_vcp(void); -void tester_handle_vcs(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len); -void tester_handle_aics(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len); -void tester_handle_vocs(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len); + +uint8_t tester_init_vcs(void); +uint8_t tester_unregister_vcs(void); + +uint8_t tester_init_aics(void); +uint8_t tester_unregister_aics(void); + +uint8_t tester_init_vocs(void); +uint8_t tester_unregister_vocs(void); uint8_t tester_init_ias(void); uint8_t tester_unregister_ias(void); diff --git a/tests/bluetooth/tester/src/btp_core.c b/tests/bluetooth/tester/src/btp_core.c index 084007958347..9ff9c563f61e 100644 --- a/tests/bluetooth/tester/src/btp_core.c +++ b/tests/bluetooth/tester/src/btp_core.c @@ -127,22 +127,18 @@ static uint8_t register_service(uint8_t index, const void *cmd, uint16_t cmd_len #endif /* CONFIG_BT_MESH */ #if defined(CONFIG_BT_VCP_VOL_REND) case BTP_SERVICE_ID_VCS: - status = tester_init_vcp(); + status = tester_init_vcs(); break; -#endif /* CONFIG_BT_VCP_VOL_REND */ -#if defined(CONFIG_BT_VOCS) || defined(CONFIG_BT_VOCS_CLIENT) case BTP_SERVICE_ID_VOCS: - status = tester_init_vcp(); + status = tester_init_vocs(); break; -#endif /* CONFIG_BT_VOCS */ -#if defined(CONFIG_BT_AICS) || defined(CONFIG_BT_AICS_CLIENT) case BTP_SERVICE_ID_AICS: - status = tester_init_vcp(); + status = tester_init_aics(); break; -#endif /* CONFIG_BT_AICS */ -#if defined(CONFIG_BT_IAS) || defined(CONFIG_BT_IAS_CLIENT) +#endif /* CONFIG_BT_VCP_VOL_REND */ +#if defined(CONFIG_BT_IAS) case BTP_SERVICE_ID_IAS: - status = BTP_STATUS_SUCCESS; + status = tester_init_ias(); break; #endif /* CONFIG_BT_IAS */ #if defined(CONFIG_BT_PACS) @@ -202,19 +198,15 @@ static uint8_t unregister_service(uint8_t index, const void *cmd, uint16_t cmd_l #endif /* CONFIG_BT_MESH */ #if defined(CONFIG_BT_VCP_VOL_REND) case BTP_SERVICE_ID_VCS: - status = tester_unregister_vcp(); + status = tester_unregister_vcs(); break; -#endif /* CONFIG_BT_VCP_VOL_REND */ -#if defined(CONFIG_BT_AICS) || defined(CONFIG_BT_AICS_CLIENT) case BTP_SERVICE_ID_AICS: - status = tester_unregister_vcp(); + status = tester_unregister_aics(); break; -#endif /* CONFIG_BT_AICS */ -#if defined(CONFIG_BT_VOCS) || defined(CONFIG_BT_VOCS_CLIENT) case BTP_SERVICE_ID_VOCS: - status = tester_unregister_vcp(); + status = tester_unregister_vocs(); break; -#endif /* CONFIG_BT_VOCS */ +#endif /* CONFIG_BT_VCP_VOL_REND */ #if defined(CONFIG_BT_IAS) case BTP_SERVICE_ID_IAS: status = tester_unregister_ias(); diff --git a/tests/bluetooth/tester/src/btp_vcp.c b/tests/bluetooth/tester/src/btp_vcp.c index 95a6b2c24bdd..f694d09c4c39 100644 --- a/tests/bluetooth/tester/src/btp_vcp.c +++ b/tests/bluetooth/tester/src/btp_vcp.c @@ -27,102 +27,112 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #define BT_AICS_MAX_INPUT_DESCRIPTION_SIZE 16 #define BT_AICS_MAX_OUTPUT_DESCRIPTION_SIZE 16 -struct bt_vcp_vol_rend_register_param vcp_register_param; -struct bt_vcp_included included; - -static void set_register_params(uint8_t gain_mode); -uint8_t tester_init_vcp(void); +static struct bt_vcp_vol_rend_register_param vcp_register_param; +static struct bt_vcp_included included; /* Volume Control Service */ -static void vcs_supported_commands(uint8_t *data, uint16_t len) +static uint8_t vcs_supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE); + struct btp_vcs_read_supported_commands_rp *rp = rsp; + + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } - net_buf_simple_init(buf, 0); - net_buf_simple_add_u8(buf, BTP_VCS_READ_SUPPORTED_COMMANDS); - net_buf_simple_add_u8(buf, BTP_VCS_SET_VOL); - net_buf_simple_add_u8(buf, BTP_VCS_VOL_UP); - net_buf_simple_add_u8(buf, BTP_VCS_VOL_DOWN); - net_buf_simple_add_u8(buf, BTP_VCS_MUTE); - net_buf_simple_add_u8(buf, BTP_VCS_UNMUTE); + /* octet 0 */ + tester_set_bit(rp->data, BTP_VCS_READ_SUPPORTED_COMMANDS); + tester_set_bit(rp->data, BTP_VCS_SET_VOL); + tester_set_bit(rp->data, BTP_VCS_VOL_UP); + tester_set_bit(rp->data, BTP_VCS_VOL_DOWN); + tester_set_bit(rp->data, BTP_VCS_MUTE); + tester_set_bit(rp->data, BTP_VCS_UNMUTE); - tester_send(BTP_SERVICE_ID_VCS, BTP_VCS_READ_SUPPORTED_COMMANDS, - CONTROLLER_INDEX, buf->data, buf->len); + *rsp_len = sizeof(*rp) + 1; + + return BTP_STATUS_SUCCESS; } -static void set_volume(uint8_t *data) +static uint8_t set_volume(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_vcs_set_vol_cmd *cmd = (void *)data; - uint8_t volume; + const struct btp_vcs_set_vol_cmd *cp = cmd; - volume = cmd->volume; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } - LOG_DBG("Set volume 0x%02x", volume); + LOG_DBG("Set volume 0x%02x", cp->volume); - if (bt_vcp_vol_rend_set_vol(volume) != 0) { - tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_SET_VOL, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - return; + if (bt_vcp_vol_rend_set_vol(cp->volume) != 0) { + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_SET_VOL, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void vol_up(void) +static uint8_t vol_up(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { LOG_DBG("Volume Up"); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + if (bt_vcp_vol_rend_vol_up() != 0) { - tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_VOL_UP, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - return; + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_VOL_UP, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void vol_down(void) +static uint8_t vol_down(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { LOG_DBG("Volume Down"); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + if (bt_vcp_vol_rend_vol_down() != 0) { - tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_VOL_DOWN, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - return; + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_VOL_DOWN, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void mute(void) +static uint8_t mute(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { LOG_DBG("Mute"); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + if (bt_vcp_vol_rend_mute() != 0) { - tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_MUTE, CONTROLLER_INDEX, - BTP_STATUS_FAILED); - return; + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_MUTE, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void unmute(void) +static uint8_t unmute(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { LOG_DBG("Unmute"); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + if (bt_vcp_vol_rend_unmute() != 0) { - tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_UNMUTE, CONTROLLER_INDEX, - BTP_STATUS_FAILED); - return; + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_VCS, BTP_VCS_UNMUTE, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } static void vcs_state_cb(int err, uint8_t volume, uint8_t mute) @@ -140,51 +150,63 @@ static struct bt_vcp_vol_rend_cb vcs_cb = { .flags = vcs_flags_cb, }; -void tester_handle_vcs(uint8_t opcode, uint8_t index, uint8_t *data, - uint16_t len) -{ - switch (opcode) { - case BTP_VCS_READ_SUPPORTED_COMMANDS: - vcs_supported_commands(data, len); - break; - case BTP_VCS_SET_VOL: - set_volume(data); - break; - case BTP_VCS_VOL_UP: - vol_up(); - break; - case BTP_VCS_VOL_DOWN: - vol_down(); - break; - case BTP_VCS_MUTE: - mute(); - break; - case BTP_VCS_UNMUTE: - unmute(); - break; - default: - tester_rsp(BTP_SERVICE_ID_VCS, opcode, index, - BTP_STATUS_UNKNOWN_CMD); - break; - } -} +static const struct btp_handler vcs_handlers[] = { + { + .opcode = BTP_VCS_READ_SUPPORTED_COMMANDS, + .expect_len = 0, + .func = vcs_supported_commands, + }, + { + .opcode = BTP_VCS_SET_VOL, + .expect_len = sizeof(struct btp_vcs_set_vol_cmd), + .func = set_volume, + }, + { + .opcode = BTP_VCS_VOL_UP, + .expect_len = 0, + .func = vol_up, + }, + { + .opcode = BTP_VCS_VOL_DOWN, + .expect_len = 0, + .func = vol_down, + }, + { + .opcode = BTP_VCS_MUTE, + .expect_len = 0, + .func = mute, + }, + { + .opcode = BTP_VCS_UNMUTE, + .expect_len = 0, + .func = unmute, + }, +}; /* Audio Input Control Service */ -static void aics_supported_commands(uint8_t *data, uint16_t len) +static uint8_t aics_supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE); + struct btp_aics_read_supported_commands_rp *rp = rsp; + + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } + + /* octet 0 */ + tester_set_bit(rp->data, BTP_AICS_READ_SUPPORTED_COMMANDS); + tester_set_bit(rp->data, BTP_AICS_SET_GAIN); + tester_set_bit(rp->data, BTP_AICS_MUTE); + tester_set_bit(rp->data, BTP_AICS_UNMUTE); + tester_set_bit(rp->data, BTP_AICS_MAN_GAIN); + tester_set_bit(rp->data, BTP_AICS_AUTO_GAIN); + + /* octet 1 */ + tester_set_bit(rp->data, BTP_AICS_DESCRIPTION); - net_buf_simple_init(buf, 0); - net_buf_simple_add_u8(buf, BTP_AICS_READ_SUPPORTED_COMMANDS); - net_buf_simple_add_u8(buf, BTP_AICS_SET_GAIN); - net_buf_simple_add_u8(buf, BTP_AICS_MUTE); - net_buf_simple_add_u8(buf, BTP_AICS_UNMUTE); - net_buf_simple_add_u8(buf, BTP_AICS_MAN_GAIN); - net_buf_simple_add_u8(buf, BTP_AICS_AUTO_GAIN); - net_buf_simple_add_u8(buf, BTP_AICS_DESCRIPTION); + *rsp_len = sizeof(*rp) + 2; - tester_send(BTP_SERVICE_ID_AICS, BTP_AICS_READ_SUPPORTED_COMMANDS, - CONTROLLER_INDEX, buf->data, buf->len); + return BTP_STATUS_SUCCESS; } static void aics_state_cb(struct bt_aics *inst, int err, int8_t gain, @@ -224,197 +246,188 @@ static struct bt_aics_cb aics_cb = { .description = aics_description_cb }; -void aics_set_gain(uint8_t *data) +static uint8_t aics_set_gain(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_aics_set_gain_cmd *cmd = (void *)data; + const struct btp_aics_set_gain_cmd *cp = cmd; - const int8_t gain = cmd->gain; + LOG_DBG("AICS set gain %d", cp->gain); - LOG_DBG("AICS set gain %d", gain); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { - if (bt_aics_gain_set(included.aics[0], gain) != 0) { - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_SET_GAIN, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - return; + if (bt_aics_gain_set(included.aics[0], cp->gain) != 0) { + return BTP_STATUS_FAILED; } } - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_SET_GAIN, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -void aics_mute(void) +static uint8_t aics_mute(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { LOG_DBG("AICS mute"); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_mute(included.aics[i]) != 0) { - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_MUTE, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - return; + return BTP_STATUS_FAILED; } } - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_MUTE, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -void aics_unmute(void) +static uint8_t aics_unmute(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { LOG_DBG("AICS unmute"); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_unmute(included.aics[i]) != 0) { - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_UNMUTE, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - return; + return BTP_STATUS_FAILED; } } - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_UNMUTE, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -void aics_man_gain(void) +static uint8_t aics_man_gain(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { LOG_DBG("AICS manual gain set"); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_manual_gain_set(included.aics[i]) != 0) { - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_MAN_GAIN, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - return; + return BTP_STATUS_FAILED; } } - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_MAN_GAIN, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -void aics_auto_gain(void) +static uint8_t aics_auto_gain(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { LOG_DBG("AICS auto gain set"); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_automatic_gain_set(included.aics[i]) != 0) { - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_AUTO_GAIN, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - return; + return BTP_STATUS_FAILED; } } - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_AUTO_GAIN, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); -} - -/* TODO: Need new API function for this */ -void aics_auto_gain_only(void) -{ - LOG_DBG("AICS auto gain only"); - - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_AUTO_GAIN_ONLY, CONTROLLER_INDEX, - BTP_STATUS_FAILED); -} - -/* TODO: Need new API function for this */ -void aics_auto_man_only(void) -{ - LOG_DBG("AICS manual gain only"); - - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_MAN_GAIN_ONLY, CONTROLLER_INDEX, - BTP_STATUS_FAILED); -} - -/* TODO: Need new API function for this */ -void aics_mute_disable(void) -{ - LOG_DBG("AICS mute disable"); - - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_MUTE_DISABLE, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -void aics_desc(uint8_t *data) +static uint8_t aics_desc(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_aics_audio_desc_cmd *cmd = (void *) data; + const struct btp_aics_audio_desc_cmd *cp = cmd; char description[BT_AICS_MAX_INPUT_DESCRIPTION_SIZE]; LOG_DBG("AICS description"); - if (cmd->desc_len > BT_AICS_MAX_INPUT_DESCRIPTION_SIZE) { - LOG_ERR("Too long input (%u chars required)", - BT_AICS_MAX_INPUT_DESCRIPTION_SIZE); - goto rsp; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if (cmd_len < sizeof(*cp) || + cmd_len != sizeof(*cp) + cp->desc_len) { + return BTP_STATUS_FAILED; + } + + if (cp->desc_len >= sizeof(description)) { + return BTP_STATUS_FAILED; } - memcpy(description, cmd->desc, cmd->desc_len); - description[cmd->desc_len] = '\0'; + memcpy(description, cp->desc, cp->desc_len); + description[cp->desc_len] = '\0'; for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_description_set(included.aics[i], description) != 0) { - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_DESCRIPTION, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - return; + return BTP_STATUS_FAILED; } } -rsp: - tester_rsp(BTP_SERVICE_ID_AICS, BTP_AICS_DESCRIPTION, CONTROLLER_INDEX, - BTP_STATUS_FAILED); -} - -void tester_handle_aics(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len) -{ - switch (opcode) { - case BTP_AICS_READ_SUPPORTED_COMMANDS: - aics_supported_commands(data, len); - break; - case BTP_AICS_SET_GAIN: - aics_set_gain(data); - break; - case BTP_AICS_MUTE: - aics_mute(); - break; - case BTP_AICS_UNMUTE: - aics_unmute(); - break; - case BTP_AICS_MAN_GAIN: - aics_man_gain(); - break; - case BTP_AICS_AUTO_GAIN: - aics_auto_gain(); - break; - case BTP_AICS_MAN_GAIN_ONLY: - aics_auto_gain_only(); - break; - case BTP_AICS_AUTO_GAIN_ONLY: - aics_auto_gain_only(); - break; - case BTP_AICS_DESCRIPTION: - aics_desc(data); - break; - case BTP_AICS_MUTE_DISABLE: - aics_mute_disable(); - break; - default: - tester_rsp(BTP_SERVICE_ID_AICS, opcode, index, - BTP_STATUS_UNKNOWN_CMD); - break; - } + + return BTP_STATUS_SUCCESS; } +static const struct btp_handler aics_handlers[] = { + { + .opcode = BTP_AICS_READ_SUPPORTED_COMMANDS, + .expect_len = 0, + .func = aics_supported_commands, + }, + { + .opcode = BTP_AICS_SET_GAIN, + .expect_len = sizeof(struct btp_aics_set_gain_cmd), + .func = aics_set_gain, + }, + { + .opcode = BTP_AICS_MUTE, + .expect_len = 0, + .func = aics_mute, + }, + { + .opcode = BTP_AICS_UNMUTE, + .expect_len = 0, + .func = aics_unmute, + }, + { + .opcode = BTP_AICS_MAN_GAIN, + .expect_len = 0, + .func = aics_man_gain, + }, + { + .opcode = BTP_AICS_AUTO_GAIN, + .expect_len = 0, + .func = aics_auto_gain, + }, + { + .opcode = BTP_AICS_DESCRIPTION, + .expect_len = -1, + .func = aics_desc, + }, +}; + /* Volume Offset Control Service */ -static void vocs_supported_commands(void) +static uint8_t vocs_supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE); + struct btp_vocs_read_supported_commands_rp *rp = rsp; - net_buf_simple_init(buf, 0); - net_buf_simple_add_u8(buf, BTP_VOCS_READ_SUPPORTED_COMMANDS); - net_buf_simple_add_u8(buf, BTP_VOCS_UPDATE_LOC); - net_buf_simple_add_u8(buf, BTP_VOCS_UPDATE_DESC); + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } + + /* octet 0 */ + tester_set_bit(rp->data, BTP_VOCS_READ_SUPPORTED_COMMANDS); + tester_set_bit(rp->data, BTP_VOCS_UPDATE_LOC); + tester_set_bit(rp->data, BTP_VOCS_UPDATE_DESC); + + *rsp_len = sizeof(*rp) + 1; - tester_send(BTP_SERVICE_ID_VOCS, BTP_VOCS_READ_SUPPORTED_COMMANDS, - CONTROLLER_INDEX, buf->data, buf->len); + return BTP_STATUS_SUCCESS; } static void vocs_state_cb(struct bt_vocs *inst, int err, int16_t offset) @@ -439,71 +452,73 @@ static struct bt_vocs_cb vocs_cb = { .description = vocs_description_cb }; -void vocs_audio_desc(uint8_t *data) +static uint8_t vocs_audio_desc(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_vocs_audio_desc_cmd *cmd = (void *) data; + const struct btp_vocs_audio_desc_cmd *cp = cmd; char description[BT_AICS_MAX_OUTPUT_DESCRIPTION_SIZE]; - LOG_DBG("VOCS description"); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + if (cmd_len < sizeof(*cp) || + cmd_len != sizeof(*cp) + cp->desc_len) { + return BTP_STATUS_FAILED; + } - /* FIXME: Spec does not specify maximum desc length */ - if (cmd->desc_len >= BT_AICS_MAX_OUTPUT_DESCRIPTION_SIZE) { - LOG_ERR("Too long input (%u chars required)", 16); - goto rsp; + if (cp->desc_len >= sizeof(description)) { + return BTP_STATUS_FAILED; } - memcpy(description, cmd->desc, cmd->desc_len); - description[cmd->desc_len] = '\0'; + memcpy(description, cp->desc, cp->desc_len); + description[cp->desc_len] = '\0'; for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT; i++) { if (bt_vocs_description_set(included.vocs[i], description) != 0) { - tester_rsp(BTP_SERVICE_ID_VOCS, BTP_VOCS_UPDATE_DESC, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - return; + return BTP_STATUS_FAILED; } } -rsp: - tester_rsp(BTP_SERVICE_ID_VOCS, BTP_VOCS_UPDATE_DESC, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + + return BTP_STATUS_SUCCESS; } -void vocs_audio_loc(uint8_t *data) +static uint8_t vocs_audio_loc(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_vocs_audio_loc_cmd *cmd = (void *) data; + const struct btp_vocs_audio_loc_cmd *cp = cmd; + uint32_t loc = sys_le32_to_cpu(cp->loc); - LOG_DBG("VOCS location"); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT; i++) { - if (bt_vocs_location_set(included.vocs[i], cmd->loc) != 0) { - tester_rsp(BTP_SERVICE_ID_VOCS, BTP_VOCS_UPDATE_LOC, - CONTROLLER_INDEX, BTP_STATUS_FAILED); - return; + if (bt_vocs_location_set(included.vocs[i], loc) != 0) { + return BTP_STATUS_FAILED; } } - tester_rsp(BTP_SERVICE_ID_VOCS, BTP_VOCS_UPDATE_LOC, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -void tester_handle_vocs(uint8_t opcode, uint8_t index, uint8_t *data, - uint16_t len) -{ - switch (opcode) { - case BTP_VOCS_READ_SUPPORTED_COMMANDS: - vocs_supported_commands(); - break; - case BTP_VOCS_UPDATE_DESC: - vocs_audio_desc(data); - break; - case BTP_VOCS_UPDATE_LOC: - vocs_audio_loc(data); - break; - default: - tester_rsp(BTP_SERVICE_ID_VOCS, opcode, index, - BTP_STATUS_UNKNOWN_CMD); - break; - } -} +static const struct btp_handler vocs_handlers[] = { + { + .opcode = BTP_VOCS_READ_SUPPORTED_COMMANDS, + .expect_len = 0, + .func = vocs_supported_commands, + }, + { + .opcode = BTP_VOCS_UPDATE_DESC, + .expect_len = -1, + .func = vocs_audio_desc, + }, + { + .opcode = BTP_VOCS_UPDATE_LOC, + .expect_len = sizeof(struct btp_vocs_audio_loc_cmd), + .func = vocs_audio_loc, + }, +}; /* General profile handling */ static void set_register_params(uint8_t gain_mode) @@ -544,7 +559,7 @@ static void set_register_params(uint8_t gain_mode) vcp_register_param.cb = &vcs_cb; } -uint8_t tester_init_vcp(void) +uint8_t tester_init_vcs(void) { int err; @@ -560,10 +575,39 @@ uint8_t tester_init_vcp(void) return BTP_STATUS_FAILED; } + tester_register_command_handlers(BTP_SERVICE_ID_VCS, vcs_handlers, + ARRAY_SIZE(vcs_handlers)); + + return BTP_STATUS_SUCCESS; +} + +uint8_t tester_unregister_vcs(void) +{ return BTP_STATUS_SUCCESS; } -uint8_t tester_unregister_vcp(void) +uint8_t tester_init_aics(void) +{ + tester_register_command_handlers(BTP_SERVICE_ID_AICS, aics_handlers, + ARRAY_SIZE(aics_handlers)); + + return tester_init_vcs(); +} + +uint8_t tester_unregister_aics(void) +{ + return BTP_STATUS_SUCCESS; +} + +uint8_t tester_init_vocs(void) +{ + tester_register_command_handlers(BTP_SERVICE_ID_VOCS, vocs_handlers, + ARRAY_SIZE(vocs_handlers)); + + return tester_init_vcs(); +} + +uint8_t tester_unregister_vocs(void) { return BTP_STATUS_SUCCESS; } From 77acd8857fb3991e50142695e705f98451214361 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 28 Feb 2023 17:46:17 +0100 Subject: [PATCH 0030/1906] bluetooth: tester: Convert MESH service to new BTP API This makes MESH service to use new BTP command handlers API. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp/btp_mesh.h | 303 ++- tests/bluetooth/tester/src/btp/bttester.h | 1 - tests/bluetooth/tester/src/btp_mesh.c | 2716 ++++++++++++--------- 3 files changed, 1871 insertions(+), 1149 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 6c44f2f74429..8cc679ea8052 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -30,11 +30,6 @@ struct btp_mesh_read_supported_commands_rp { #define BTP_MESH_CONFIG_PROVISIONING 0x02 -struct set_keys { - uint8_t pub_key[64]; - uint8_t priv_key[32]; -} __packed; - struct btp_mesh_config_provisioning_cmd { uint8_t uuid[16]; uint8_t static_auth[16]; @@ -43,7 +38,17 @@ struct btp_mesh_config_provisioning_cmd { uint8_t in_size; uint16_t in_actions; uint8_t auth_method; - struct set_keys set_keys[0]; +} __packed; +struct btp_mesh_config_provisioning_cmd_v2 { + uint8_t uuid[16]; + uint8_t static_auth[16]; + uint8_t out_size; + uint16_t out_actions; + uint8_t in_size; + uint16_t in_actions; + uint8_t auth_method; + uint8_t set_pub_key[64]; + uint8_t set_priv_key[32]; } __packed; #define BTP_MESH_PROVISION_NODE 0x03 @@ -55,7 +60,16 @@ struct btp_mesh_provision_node_cmd { uint32_t seq_num; uint16_t addr; uint8_t dev_key[16]; - uint8_t pub_key[0]; +} __packed; +struct btp_mesh_provision_node_cmd_v2 { + uint8_t net_key[16]; + uint16_t net_key_idx; + uint8_t flags; + uint32_t iv_index; + uint32_t seq_num; + uint16_t addr; + uint8_t dev_key[16]; + uint8_t pub_key[64]; } __packed; #define BTP_MESH_INIT 0x04 @@ -131,12 +145,18 @@ struct btp_mesh_comp_data_get_cmd { uint16_t address; uint8_t page; } __packed; +struct btp_mesh_comp_data_get_rp { + uint8_t data[0]; +} __packed; #define BTP_MESH_CFG_BEACON_GET 0x15 -struct btp_mesh_cfg_val_get_cmd { +struct btp_mesh_cfg_beacon_get_cmd { uint16_t net_idx; uint16_t address; } __packed; +struct btp_mesh_cfg_beacon_get_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_BEACON_SET 0x16 struct btp_mesh_cfg_beacon_set_cmd { @@ -144,32 +164,76 @@ struct btp_mesh_cfg_beacon_set_cmd { uint16_t address; uint8_t val; } __packed; +struct btp_mesh_cfg_beacon_set_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_DEFAULT_TTL_GET 0x18 +struct btp_mesh_cfg_default_ttl_get_cmd { + uint16_t net_idx; + uint16_t address; +} __packed; +struct btp_mesh_cfg_default_ttl_get_rp { + uint8_t status; +} __packed; + #define BTP_MESH_CFG_DEFAULT_TTL_SET 0x19 struct btp_mesh_cfg_default_ttl_set_cmd { uint16_t net_idx; uint16_t address; uint8_t val; } __packed; +struct btp_mesh_cfg_default_ttl_set_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_GATT_PROXY_GET 0x1a +struct btp_mesh_cfg_gatt_proxy_get_cmd { + uint16_t net_idx; + uint16_t address; +} __packed; +struct btp_mesh_cfg_gatt_proxy_get_rp { + uint8_t status; +} __packed; + #define BTP_MESH_CFG_GATT_PROXY_SET 0x1b struct btp_mesh_cfg_gatt_proxy_set_cmd { uint16_t net_idx; uint16_t address; uint8_t val; } __packed; +struct btp_mesh_cfg_gatt_proxy_set_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_FRIEND_GET 0x1c +struct btp_mesh_cfg_friend_get_cmd { + uint16_t net_idx; + uint16_t address; +} __packed; +struct btp_mesh_cfg_friend_get_rp { + uint8_t status; +} __packed; + #define BTP_MESH_CFG_FRIEND_SET 0x1d struct btp_mesh_cfg_friend_set_cmd { uint16_t net_idx; uint16_t address; uint8_t val; } __packed; +struct btp_mesh_cfg_friend_set_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_RELAY_GET 0x1e +struct btp_mesh_cfg_relay_get_cmd { + uint16_t net_idx; + uint16_t address; +} __packed; +struct btp_mesh_cfg_relay_get_rp { + uint8_t status; +} __packed; + #define BTP_MESH_CFG_RELAY_SET 0x1f struct btp_mesh_cfg_relay_set_cmd { uint16_t net_idx; @@ -177,6 +241,9 @@ struct btp_mesh_cfg_relay_set_cmd { uint8_t new_relay; uint8_t new_transmit; } __packed; +struct btp_mesh_cfg_relay_set_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_MODEL_PUB_GET 0x20 struct btp_mesh_cfg_model_pub_get_cmd { @@ -185,6 +252,9 @@ struct btp_mesh_cfg_model_pub_get_cmd { uint16_t elem_address; uint16_t model_id; } __packed; +struct btp_mesh_cfg_model_pub_get_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_MODEL_PUB_SET 0x21 struct btp_mesh_cfg_model_pub_set_cmd { @@ -199,16 +269,33 @@ struct btp_mesh_cfg_model_pub_set_cmd { uint8_t period; uint8_t transmit; } __packed; +struct btp_mesh_cfg_model_pub_set_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_MODEL_SUB_ADD 0x22 +struct btp_mesh_cfg_model_sub_add_cmd { + uint16_t net_idx; + uint16_t address; + uint16_t elem_address; + uint16_t sub_addr; + uint16_t model_id; +} __packed; +struct btp_mesh_cfg_model_sub_add_rp { + uint8_t status; +} __packed; + #define BTP_MESH_CFG_MODEL_SUB_DEL 0x23 -struct btp_mesh_cfg_model_sub_cmd { +struct btp_mesh_cfg_model_sub_del_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; uint16_t sub_addr; uint16_t model_id; } __packed; +struct btp_mesh_cfg_model_sub_del_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_NETKEY_ADD 0x24 struct btp_mesh_cfg_netkey_add_cmd { @@ -217,14 +304,29 @@ struct btp_mesh_cfg_netkey_add_cmd { uint8_t net_key[16]; uint16_t net_key_idx; } __packed; +struct btp_mesh_cfg_netkey_add_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_NETKEY_GET 0x25 +struct btp_mesh_cfg_netkey_get_cmd { + uint16_t net_idx; + uint16_t address; + uint16_t net_key_idx; +} __packed; +struct btp_mesh_cfg_netkey_get_rp { + uint8_t status; +} __packed; + #define BTP_MESH_CFG_NETKEY_DEL 0x26 struct btp_mesh_cfg_netkey_del_cmd { uint16_t net_idx; uint16_t address; uint16_t net_key_idx; } __packed; +struct btp_mesh_cfg_netkey_del_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_APPKEY_ADD 0x27 struct btp_mesh_cfg_appkey_add_cmd { @@ -234,6 +336,9 @@ struct btp_mesh_cfg_appkey_add_cmd { uint8_t app_key[16]; uint16_t app_key_idx; } __packed; +struct btp_mesh_cfg_appkey_add_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_APPKEY_DEL 0x28 struct btp_mesh_cfg_appkey_del_cmd { @@ -242,6 +347,9 @@ struct btp_mesh_cfg_appkey_del_cmd { uint16_t net_key_idx; uint16_t app_key_idx; } __packed; +struct btp_mesh_cfg_appkey_del_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_APPKEY_GET 0x29 struct btp_mesh_cfg_appkey_get_cmd { @@ -249,9 +357,11 @@ struct btp_mesh_cfg_appkey_get_cmd { uint16_t address; uint16_t net_key_idx; } __packed; +struct btp_mesh_cfg_appkey_get_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_MODEL_APP_BIND 0x2A -#define BTP_MESH_CFG_MODEL_APP_UNBIND 0x2B struct btp_mesh_cfg_model_app_bind_cmd { uint16_t net_idx; uint16_t address; @@ -259,9 +369,23 @@ struct btp_mesh_cfg_model_app_bind_cmd { uint16_t app_key_idx; uint16_t mod_id; } __packed; +struct btp_mesh_cfg_model_app_bind_rp { + uint8_t status; +} __packed; + +#define BTP_MESH_CFG_MODEL_APP_UNBIND 0x2B +struct btp_mesh_cfg_model_app_unbind_cmd { + uint16_t net_idx; + uint16_t address; + uint16_t elem_address; + uint16_t app_key_idx; + uint16_t mod_id; +} __packed; +struct btp_mesh_cfg_model_app_unbind_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_MODEL_APP_GET 0x2C -#define BTP_MESH_CFG_MODEL_APP_VND_GET 0x2D struct btp_mesh_cfg_model_app_get_cmd { uint16_t net_idx; uint16_t address; @@ -269,6 +393,21 @@ struct btp_mesh_cfg_model_app_get_cmd { uint16_t mod_id; uint16_t cid; } __packed; +struct btp_mesh_cfg_model_app_get_rp { + uint8_t status; +} __packed; + +#define BTP_MESH_CFG_MODEL_APP_VND_GET 0x2D +struct btp_mesh_cfg_model_app_vnd_get_cmd { + uint16_t net_idx; + uint16_t address; + uint16_t elem_address; + uint16_t mod_id; + uint16_t cid; +} __packed; +struct btp_mesh_cfg_model_app_vnd_get_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_HEARTBEAT_PUB_SET 0x2E struct btp_mesh_cfg_heartbeat_pub_set_cmd { @@ -281,8 +420,19 @@ struct btp_mesh_cfg_heartbeat_pub_set_cmd { uint8_t ttl; uint16_t features; } __packed; +struct btp_mesh_cfg_heartbeat_pub_set_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_HEARTBEAT_PUB_GET 0x2F +struct btp_mesh_cfg_heartbeat_pub_get_cmd { + uint16_t net_idx; + uint16_t address; +} __packed; +struct btp_mesh_cfg_heartbeat_pub_get_rp { + uint8_t status; +} __packed; + #define BTP_MESH_CFG_HEARTBEAT_SUB_SET 0x30 struct btp_mesh_cfg_heartbeat_sub_set_cmd { uint16_t net_idx; @@ -291,17 +441,49 @@ struct btp_mesh_cfg_heartbeat_sub_set_cmd { uint16_t destination; uint8_t period_log; } __packed; +struct btp_mesh_cfg_heartbeat_sub_set_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_HEARTBEAT_SUB_GET 0x31 +struct btp_mesh_cfg_heartbeat_sub_get_cmd { + uint16_t net_idx; + uint16_t address; +} __packed; +struct btp_mesh_cfg_heartbeat_sub_get_rp { + uint8_t status; +} __packed; + #define BTP_MESH_CFG_NET_TRANS_GET 0x32 +struct btp_mesh_cfg_net_trans_get_cmd { + uint16_t net_idx; + uint16_t address; +} __packed; +struct btp_mesh_cfg_net_trans_get_rp { + uint8_t transmit; +} __packed; + #define BTP_MESH_CFG_NET_TRANS_SET 0x33 struct btp_mesh_cfg_net_trans_set_cmd { uint16_t net_idx; uint16_t address; uint8_t transmit; } __packed; +struct btp_mesh_cfg_net_trans_set_rp { + uint8_t transmit; +} __packed; #define BTP_MESH_CFG_MODEL_SUB_OVW 0x34 +struct btp_mesh_cfg_model_sub_ovw_cmd { + uint16_t net_idx; + uint16_t address; + uint16_t elem_address; + uint16_t model_id; +} __packed; +struct btp_mesh_cfg_model_sub_ovw_rp { + uint8_t status; +} __packed; + #define BTP_MESH_CFG_MODEL_SUB_DEL_ALL 0x35 struct btp_mesh_cfg_model_sub_del_all_cmd { uint16_t net_idx; @@ -309,6 +491,9 @@ struct btp_mesh_cfg_model_sub_del_all_cmd { uint16_t elem_address; uint16_t model_id; } __packed; +struct btp_mesh_cfg_model_sub_del_all_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_MODEL_SUB_GET 0x36 struct btp_mesh_cfg_model_sub_get_cmd { @@ -317,6 +502,9 @@ struct btp_mesh_cfg_model_sub_get_cmd { uint16_t elem_address; uint16_t model_id; } __packed; +struct btp_mesh_cfg_model_sub_get_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_MODEL_SUB_GET_VND 0x37 struct btp_mesh_cfg_model_sub_get_vnd_cmd { @@ -326,20 +514,69 @@ struct btp_mesh_cfg_model_sub_get_vnd_cmd { uint16_t model_id; uint16_t cid; } __packed; +struct btp_mesh_cfg_model_sub_get_vnd_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_MODEL_SUB_VA_ADD 0x38 +struct btp_mesh_cfg_model_sub_va_add_cmd { + uint16_t net_idx; + uint16_t address; + uint16_t elem_address; + uint16_t model_id; + uint8_t uuid[16]; +} __packed; +struct btp_mesh_cfg_model_sub_va_add_rp { + uint8_t status; +} __packed; + #define BTP_MESH_CFG_MODEL_SUB_VA_DEL 0x39 +struct btp_mesh_cfg_model_sub_va_del_cmd { + uint16_t net_idx; + uint16_t address; + uint16_t elem_address; + uint16_t model_id; + uint8_t uuid[16]; +} __packed; +struct btp_mesh_cfg_model_sub_va_del_rp { + uint8_t status; +} __packed; + #define BTP_MESH_CFG_MODEL_SUB_VA_OVW 0x3A -struct btp_mesh_cfg_model_sub_va_cmd { +struct btp_mesh_cfg_model_sub_va_ovw_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; uint16_t model_id; uint8_t uuid[16]; } __packed; +struct btp_mesh_cfg_model_sub_va_ovw_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_NETKEY_UPDATE 0x3B +struct btp_mesh_cfg_netkey_update_cmd { + uint16_t net_idx; + uint16_t address; + uint8_t net_key[16]; + uint16_t net_key_idx; +} __packed; +struct btp_mesh_cfg_netkey_update_rp { + uint8_t status; +} __packed; + #define BTP_MESH_CFG_APPKEY_UPDATE 0x3C +struct btp_mesh_cfg_appkey_update_cmd { + uint16_t net_idx; + uint16_t address; + uint16_t net_key_idx; + uint8_t app_key[16]; + uint16_t app_key_idx; +} __packed; +struct btp_mesh_cfg_appkey_update_rp { + uint8_t status; +} __packed; + #define BTP_MESH_CFG_NODE_IDT_SET 0x3D struct btp_mesh_cfg_node_idt_set_cmd { uint16_t net_idx; @@ -347,6 +584,10 @@ struct btp_mesh_cfg_node_idt_set_cmd { uint16_t net_key_idx; uint8_t new_identity; } __packed; +struct btp_mesh_cfg_node_idt_set_rp { + uint8_t status; + uint8_t identity; +} __packed; #define BTP_MESH_CFG_NODE_IDT_GET 0x3E struct btp_mesh_cfg_node_idt_get_cmd { @@ -354,12 +595,19 @@ struct btp_mesh_cfg_node_idt_get_cmd { uint16_t address; uint16_t net_key_idx; } __packed; +struct btp_mesh_cfg_node_idt_get_rp { + uint8_t status; + uint8_t identity; +} __packed; #define BTP_MESH_CFG_NODE_RESET 0x3F struct btp_mesh_cfg_node_reset_cmd { uint16_t net_idx; uint16_t address; } __packed; +struct btp_mesh_cfg_node_reset_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_LPN_TIMEOUT_GET 0x40 struct btp_mesh_cfg_lpn_timeout_cmd { @@ -367,6 +615,9 @@ struct btp_mesh_cfg_lpn_timeout_cmd { uint16_t address; uint16_t unicast_addr; } __packed; +struct btp_mesh_cfg_lpn_timeout_rp { + int32_t timeout; +} __packed; #define BTP_MESH_CFG_MODEL_PUB_VA_SET 0x41 struct btp_mesh_cfg_model_pub_va_set_cmd { @@ -381,6 +632,9 @@ struct btp_mesh_cfg_model_pub_va_set_cmd { uint8_t transmit; uint8_t uuid[16]; } __packed; +struct btp_mesh_cfg_model_pub_va_set_rp { + uint8_t status; +} __packed; #define BTP_MESH_CFG_MODEL_APP_BIND_VND 0x42 struct btp_mesh_cfg_model_app_bind_vnd_cmd { @@ -391,6 +645,9 @@ struct btp_mesh_cfg_model_app_bind_vnd_cmd { uint16_t mod_id; uint16_t cid; } __packed; +struct btp_mesh_cfg_model_app_bind_vnd_rp { + uint8_t status; +} __packed; #define BTP_MESH_HEALTH_FAULT_GET 0x43 struct btp_mesh_health_fault_get_cmd { @@ -406,6 +663,9 @@ struct btp_mesh_health_fault_clear_cmd { uint16_t cid; uint8_t ack; } __packed; +struct btp_mesh_health_fault_clear_rp { + uint8_t test_id; +} __packed; #define BTP_MESH_HEALTH_FAULT_TEST 0x45 struct btp_mesh_health_fault_test_cmd { @@ -415,6 +675,11 @@ struct btp_mesh_health_fault_test_cmd { uint8_t test_id; uint8_t ack; } __packed; +struct btp_mesh_health_fault_test_rp { + uint8_t test_id; + uint16_t cid; + uint8_t faults[]; +} __packed; #define BTP_MESH_HEALTH_PERIOD_GET 0x46 struct btp_mesh_health_period_get_cmd { @@ -429,6 +694,9 @@ struct btp_mesh_health_period_set_cmd { uint8_t divisor; uint8_t ack; } __packed; +struct btp_mesh_health_period_set_rp { + uint8_t divisor; +} __packed; #define BTP_MESH_HEALTH_ATTENTION_GET 0x48 struct btp_mesh_health_attention_get_cmd { @@ -443,6 +711,9 @@ struct btp_mesh_health_attention_set_cmd { uint8_t attention; uint8_t ack; } __packed; +struct btp_mesh_health_attention_set_rp { + uint8_t attention; +} __packed; #define BTP_MESH_PROVISION_ADV 0x4A struct btp_mesh_provision_adv_cmd { @@ -459,6 +730,10 @@ struct btp_mesh_cfg_krp_get_cmd { uint16_t address; uint16_t key_net_idx; } __packed; +struct btp_mesh_cfg_krp_get_rp { + uint8_t status; + uint8_t phase; +} __packed; #define BTP_MESH_CFG_KRP_SET 0x4C struct btp_mesh_cfg_krp_set_cmd { @@ -467,6 +742,10 @@ struct btp_mesh_cfg_krp_set_cmd { uint16_t key_net_idx; uint8_t transition; } __packed; +struct btp_mesh_cfg_krp_set_rp { + uint8_t status; + uint8_t phase; +} __packed; /* events */ #define BTP_MESH_EV_OUT_NUMBER_ACTION 0x80 diff --git a/tests/bluetooth/tester/src/btp/bttester.h b/tests/bluetooth/tester/src/btp/bttester.h index 97a81ddacf17..7dec11d0892d 100644 --- a/tests/bluetooth/tester/src/btp/bttester.h +++ b/tests/bluetooth/tester/src/btp/bttester.h @@ -50,7 +50,6 @@ uint8_t tester_unregister_l2cap(void); uint8_t tester_init_mesh(void); uint8_t tester_unregister_mesh(void); -void tester_handle_mesh(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len); uint8_t tester_init_vcp(void); uint8_t tester_unregister_vcp(void); diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 3421be88059b..5484a595ecad 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -73,89 +73,114 @@ static struct { .dst = BT_MESH_ADDR_UNASSIGNED, }; -static void supported_commands(uint8_t *data, uint16_t len) + +static uint8_t supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct net_buf_simple *buf = NET_BUF_SIMPLE(BTP_DATA_MAX_SIZE); + struct btp_mesh_read_supported_commands_rp *rp = rsp; - net_buf_simple_init(buf, 0); - net_buf_simple_add_u8(buf, BTP_MESH_READ_SUPPORTED_COMMANDS); - net_buf_simple_add_u8(buf, BTP_MESH_CONFIG_PROVISIONING); - net_buf_simple_add_u8(buf, BTP_MESH_PROVISION_NODE); - net_buf_simple_add_u8(buf, BTP_MESH_INIT); - net_buf_simple_add_u8(buf, BTP_MESH_RESET); - net_buf_simple_add_u8(buf, BTP_MESH_INPUT_NUMBER); - net_buf_simple_add_u8(buf, BTP_MESH_INPUT_STRING); - net_buf_simple_add_u8(buf, BTP_MESH_IVU_TEST_MODE); - net_buf_simple_add_u8(buf, BTP_MESH_IVU_TOGGLE_STATE); - net_buf_simple_add_u8(buf, BTP_MESH_NET_SEND); - net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_GENERATE_FAULTS); - net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_CLEAR_FAULTS); - net_buf_simple_add_u8(buf, BTP_MESH_LPN); - net_buf_simple_add_u8(buf, BTP_MESH_LPN_POLL); - net_buf_simple_add_u8(buf, BTP_MESH_MODEL_SEND); + if (index != BTP_INDEX_NONE) { + return BTP_STATUS_FAILED; + } + + /* octet 0 */ + tester_set_bit(rp->data, BTP_MESH_READ_SUPPORTED_COMMANDS); + tester_set_bit(rp->data, BTP_MESH_CONFIG_PROVISIONING); + tester_set_bit(rp->data, BTP_MESH_PROVISION_NODE); + tester_set_bit(rp->data, BTP_MESH_INIT); + tester_set_bit(rp->data, BTP_MESH_RESET); + tester_set_bit(rp->data, BTP_MESH_INPUT_NUMBER); + tester_set_bit(rp->data, BTP_MESH_INPUT_STRING); + + /* octet 1 */ + tester_set_bit(rp->data, BTP_MESH_IVU_TEST_MODE); + tester_set_bit(rp->data, BTP_MESH_IVU_TOGGLE_STATE); + tester_set_bit(rp->data, BTP_MESH_NET_SEND); + tester_set_bit(rp->data, BTP_MESH_HEALTH_GENERATE_FAULTS); + tester_set_bit(rp->data, BTP_MESH_HEALTH_CLEAR_FAULTS); + tester_set_bit(rp->data, BTP_MESH_LPN); + tester_set_bit(rp->data, BTP_MESH_LPN_POLL); + tester_set_bit(rp->data, BTP_MESH_MODEL_SEND); + + /* octet 2 */ #if defined(CONFIG_BT_TESTING) - net_buf_simple_add_u8(buf, BTP_MESH_LPN_SUBSCRIBE); - net_buf_simple_add_u8(buf, BTP_MESH_LPN_UNSUBSCRIBE); - net_buf_simple_add_u8(buf, BTP_MESH_RPL_CLEAR); + tester_set_bit(rp->data, BTP_MESH_LPN_SUBSCRIBE); + tester_set_bit(rp->data, BTP_MESH_LPN_UNSUBSCRIBE); + tester_set_bit(rp->data, BTP_MESH_RPL_CLEAR); #endif /* CONFIG_BT_TESTING */ - net_buf_simple_add_u8(buf, BTP_MESH_PROXY_IDENTITY); - net_buf_simple_add_u8(buf, BTP_MESH_COMP_DATA_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_BEACON_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_BEACON_SET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_DEFAULT_TTL_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_DEFAULT_TTL_SET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_GATT_PROXY_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_GATT_PROXY_SET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_FRIEND_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_FRIEND_SET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_RELAY_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_RELAY_SET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_PUB_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_PUB_SET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_ADD); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_DEL); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_NETKEY_ADD); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_NETKEY_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_NETKEY_DEL); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_APPKEY_ADD); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_APPKEY_DEL); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_APPKEY_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_APP_BIND); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_APP_UNBIND); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_APP_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_APP_VND_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_HEARTBEAT_PUB_SET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_HEARTBEAT_PUB_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_HEARTBEAT_SUB_SET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_HEARTBEAT_SUB_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_NET_TRANS_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_NET_TRANS_SET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_OVW); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_DEL_ALL); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_GET_VND); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_VA_ADD); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_VA_DEL); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_SUB_VA_OVW); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_NETKEY_UPDATE); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_APPKEY_UPDATE); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_NODE_IDT_SET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_NODE_IDT_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_NODE_RESET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_LPN_TIMEOUT_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_MODEL_APP_BIND_VND); - net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_FAULT_GET); - net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_FAULT_CLEAR); - net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_PERIOD_GET); - net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_PERIOD_SET); - net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_ATTENTION_GET); - net_buf_simple_add_u8(buf, BTP_MESH_HEALTH_ATTENTION_SET); - net_buf_simple_add_u8(buf, BTP_MESH_PROVISION_ADV); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_KRP_GET); - net_buf_simple_add_u8(buf, BTP_MESH_CFG_KRP_SET); - - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_READ_SUPPORTED_COMMANDS, - CONTROLLER_INDEX, buf->data, buf->len); + tester_set_bit(rp->data, BTP_MESH_PROXY_IDENTITY); + tester_set_bit(rp->data, BTP_MESH_COMP_DATA_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_BEACON_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_BEACON_SET); + + /* octet 3 */ + tester_set_bit(rp->data, BTP_MESH_CFG_DEFAULT_TTL_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_DEFAULT_TTL_SET); + tester_set_bit(rp->data, BTP_MESH_CFG_GATT_PROXY_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_GATT_PROXY_SET); + tester_set_bit(rp->data, BTP_MESH_CFG_FRIEND_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_FRIEND_SET); + tester_set_bit(rp->data, BTP_MESH_CFG_RELAY_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_RELAY_SET); + + /* octet 4 */ + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_PUB_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_PUB_SET); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_SUB_ADD); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_SUB_DEL); + tester_set_bit(rp->data, BTP_MESH_CFG_NETKEY_ADD); + tester_set_bit(rp->data, BTP_MESH_CFG_NETKEY_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_NETKEY_DEL); + tester_set_bit(rp->data, BTP_MESH_CFG_APPKEY_ADD); + + /* octet 5 */ + tester_set_bit(rp->data, BTP_MESH_CFG_APPKEY_DEL); + tester_set_bit(rp->data, BTP_MESH_CFG_APPKEY_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_APP_BIND); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_APP_UNBIND); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_APP_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_APP_VND_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_HEARTBEAT_PUB_SET); + tester_set_bit(rp->data, BTP_MESH_CFG_HEARTBEAT_PUB_GET); + + /* octet 6 */ + tester_set_bit(rp->data, BTP_MESH_CFG_HEARTBEAT_SUB_SET); + tester_set_bit(rp->data, BTP_MESH_CFG_HEARTBEAT_SUB_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_NET_TRANS_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_NET_TRANS_SET); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_SUB_OVW); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_SUB_DEL_ALL); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_SUB_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_SUB_GET_VND); + + /* octet 7 */ + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_SUB_VA_ADD); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_SUB_VA_DEL); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_SUB_VA_OVW); + tester_set_bit(rp->data, BTP_MESH_CFG_NETKEY_UPDATE); + tester_set_bit(rp->data, BTP_MESH_CFG_APPKEY_UPDATE); + tester_set_bit(rp->data, BTP_MESH_CFG_NODE_IDT_SET); + tester_set_bit(rp->data, BTP_MESH_CFG_NODE_IDT_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_NODE_RESET); + + /* octet 8 */ + tester_set_bit(rp->data, BTP_MESH_CFG_LPN_TIMEOUT_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_MODEL_APP_BIND_VND); + tester_set_bit(rp->data, BTP_MESH_HEALTH_FAULT_GET); + tester_set_bit(rp->data, BTP_MESH_HEALTH_FAULT_CLEAR); + tester_set_bit(rp->data, BTP_MESH_HEALTH_PERIOD_GET); + tester_set_bit(rp->data, BTP_MESH_HEALTH_PERIOD_SET); + + /* octet 9 */ + tester_set_bit(rp->data, BTP_MESH_HEALTH_ATTENTION_GET); + tester_set_bit(rp->data, BTP_MESH_HEALTH_ATTENTION_SET); + tester_set_bit(rp->data, BTP_MESH_PROVISION_ADV); + tester_set_bit(rp->data, BTP_MESH_CFG_KRP_GET); + tester_set_bit(rp->data, BTP_MESH_CFG_KRP_SET); + + *rsp_len = sizeof(*rp) + 10; + + return BTP_STATUS_SUCCESS; } static void get_faults(uint8_t *faults, uint8_t faults_size, uint8_t *dst, uint8_t *count) @@ -440,248 +465,299 @@ static struct bt_mesh_prov prov = { .reset = prov_reset, }; -static void config_prov(uint8_t *data, uint16_t len) +static uint8_t config_prov(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_mesh_config_provisioning_cmd *cmd = (void *) data; + const struct btp_mesh_config_provisioning_cmd *cp = cmd; + const struct btp_mesh_config_provisioning_cmd_v2 *cp2 = cmd; int err = 0; + /* TODO consider fix BTP commands to avoid this */ + if (cmd_len != sizeof(*cp) && cmd_len != (sizeof(*cp2))) { + return BTP_STATUS_FAILED; + } + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + LOG_DBG(""); - memcpy(dev_uuid, cmd->uuid, sizeof(dev_uuid)); - memcpy(static_auth, cmd->static_auth, sizeof(static_auth)); + memcpy(dev_uuid, cp->uuid, sizeof(dev_uuid)); + memcpy(static_auth, cp->static_auth, sizeof(static_auth)); - prov.output_size = cmd->out_size; - prov.output_actions = sys_le16_to_cpu(cmd->out_actions); - prov.input_size = cmd->in_size; - prov.input_actions = sys_le16_to_cpu(cmd->in_actions); + prov.output_size = cp->out_size; + prov.output_actions = sys_le16_to_cpu(cp->out_actions); + prov.input_size = cp->in_size; + prov.input_actions = sys_le16_to_cpu(cp->in_actions); - if (cmd->auth_method == AUTH_METHOD_OUTPUT) { + if (cmd_len == sizeof(*cp2)) { + memcpy(pub_key, cp2->set_pub_key, sizeof(cp2->set_pub_key)); + memcpy(priv_key, cp2->set_priv_key, sizeof(cp2->set_priv_key)); + prov.public_key_be = pub_key; + prov.private_key_be = priv_key; + } + + if (cp->auth_method == AUTH_METHOD_OUTPUT) { err = bt_mesh_auth_method_set_output(prov.output_actions, prov.output_size); - } else if (cmd->auth_method == AUTH_METHOD_INPUT) { + } else if (cp->auth_method == AUTH_METHOD_INPUT) { err = bt_mesh_auth_method_set_input(prov.input_actions, prov.input_size); - } else if (cmd->auth_method == AUTH_METHOD_STATIC) { + } else if (cp->auth_method == AUTH_METHOD_STATIC) { err = bt_mesh_auth_method_set_static(static_auth, sizeof(static_auth)); } - if (len > sizeof(*cmd)) { - memcpy(pub_key, cmd->set_keys->pub_key, sizeof(cmd->set_keys->pub_key)); - memcpy(priv_key, cmd->set_keys->priv_key, sizeof(cmd->set_keys->priv_key)); - prov.public_key_be = pub_key; - prov.private_key_be = priv_key; - } - if (err) { LOG_ERR("err %d", err); + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CONFIG_PROVISIONING, CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void provision_node(uint8_t *data, uint16_t len) +static uint8_t provision_node(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_mesh_provision_node_cmd *cmd = (void *)data; + const struct btp_mesh_provision_node_cmd *cp = cmd; + const struct btp_mesh_provision_node_cmd_v2 *cp2 = cmd; int err; + /* TODO consider fix BTP commands to avoid this */ + if (cmd_len != sizeof(*cp) && cmd_len != (sizeof(*cp2))) { + return BTP_STATUS_FAILED; + } + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + LOG_DBG(""); - memcpy(dev_key, cmd->dev_key, sizeof(dev_key)); - memcpy(net_key, cmd->net_key, sizeof(net_key)); + memcpy(dev_key, cp->dev_key, sizeof(dev_key)); + memcpy(net_key, cp->net_key, sizeof(net_key)); - addr = sys_le16_to_cpu(cmd->addr); - flags = cmd->flags; - iv_index = sys_le32_to_cpu(cmd->iv_index); - net_key_idx = sys_le16_to_cpu(cmd->net_key_idx); + addr = sys_le16_to_cpu(cp->addr); + flags = cp->flags; + iv_index = sys_le32_to_cpu(cp->iv_index); + net_key_idx = sys_le16_to_cpu(cp->net_key_idx); - if (len > sizeof(*cmd)) { - memcpy(pub_key, cmd->pub_key, sizeof(pub_key)); + if (cmd_len == sizeof(*cp2)) { + memcpy(pub_key, cp2->pub_key, sizeof(pub_key)); err = bt_mesh_prov_remote_pub_key_set(pub_key); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } } #if defined(CONFIG_BT_MESH_PROVISIONER) err = bt_mesh_cdb_create(net_key); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } #endif err = bt_mesh_provision(net_key, net_key_idx, flags, iv_index, addr, dev_key); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_PROVISION_NODE, CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void provision_adv(uint8_t *data, uint16_t len) +static uint8_t provision_adv(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_mesh_provision_adv_cmd *cmd = (void *)data; + const struct btp_mesh_provision_adv_cmd *cp = cmd; int err; LOG_DBG(""); - err = bt_mesh_provision_adv(cmd->uuid, cmd->net_idx, cmd->address, - cmd->attention_duration); + err = bt_mesh_provision_adv(cp->uuid, sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + cp->attention_duration); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_PROVISION_ADV, CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void init(uint8_t *data, uint16_t len) +static uint8_t init(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - uint8_t status = BTP_STATUS_SUCCESS; int err; LOG_DBG(""); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + err = bt_mesh_init(&prov, &comp); if (err) { - status = BTP_STATUS_FAILED; - - goto rsp; + return BTP_STATUS_FAILED; } if (addr) { err = bt_mesh_provision(net_key, net_key_idx, flags, iv_index, addr, dev_key); if (err) { - status = BTP_STATUS_FAILED; + return BTP_STATUS_FAILED; } } else { err = bt_mesh_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT); if (err) { - status = BTP_STATUS_FAILED; + return BTP_STATUS_FAILED; } } -rsp: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_INIT, CONTROLLER_INDEX, - status); + return BTP_STATUS_SUCCESS; } -static void reset(uint8_t *data, uint16_t len) +static uint8_t reset(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { LOG_DBG(""); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + bt_mesh_reset(); - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_RESET, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void input_number(uint8_t *data, uint16_t len) +static uint8_t input_number(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_mesh_input_number_cmd *cmd = (void *) data; - uint8_t status = BTP_STATUS_SUCCESS; + const struct btp_mesh_input_number_cmd *cp = cmd; uint32_t number; int err; - number = sys_le32_to_cpu(cmd->number); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + number = sys_le32_to_cpu(cp->number); LOG_DBG("number 0x%04x", number); err = bt_mesh_input_number(number); if (err) { - status = BTP_STATUS_FAILED; + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_INPUT_NUMBER, CONTROLLER_INDEX, - status); + return BTP_STATUS_SUCCESS; } -static void input_string(uint8_t *data, uint16_t len) +static uint8_t input_string(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_mesh_input_string_cmd *cmd = (void *) data; + const struct btp_mesh_input_string_cmd *cp = cmd; uint8_t status = BTP_STATUS_SUCCESS; - uint8_t str_auth[16]; int err; LOG_DBG(""); - if (cmd->string_len > sizeof(str_auth)) { - LOG_ERR("Too long input (%u chars required)", input_size); - status = BTP_STATUS_FAILED; - goto rsp; - } else if (cmd->string_len < input_size) { - LOG_ERR("Too short input (%u chars required)", input_size); - status = BTP_STATUS_FAILED; - goto rsp; + if (cmd_len < sizeof(*cp) && + cmd_len != (sizeof(*cp) + cp->string_len)) { + return BTP_STATUS_FAILED; + } + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; } - strncpy(str_auth, cmd->string, cmd->string_len); + /* for historical reasons this commands must send NULL terminated + * string + */ + if (cp->string[cp->string_len] != '\0') { + return BTP_STATUS_FAILED; + } - err = bt_mesh_input_string(str_auth); + if (strlen(cp->string) < input_size) { + LOG_ERR("Too short input (%u chars required)", input_size); + return BTP_STATUS_FAILED; + } + + err = bt_mesh_input_string(cp->string); if (err) { status = BTP_STATUS_FAILED; } -rsp: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_INPUT_STRING, CONTROLLER_INDEX, - status); + return BTP_STATUS_SUCCESS; } -static void ivu_test_mode(uint8_t *data, uint16_t len) +static uint8_t ivu_test_mode(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - const struct btp_mesh_ivu_test_mode_cmd *cmd = (void *) data; + const struct btp_mesh_ivu_test_mode_cmd *cp = cmd; + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } - LOG_DBG("enable 0x%02x", cmd->enable); + LOG_DBG("enable 0x%02x", cp->enable); - bt_mesh_iv_update_test(cmd->enable ? true : false); + bt_mesh_iv_update_test(cp->enable ? true : false); - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_IVU_TEST_MODE, CONTROLLER_INDEX, - BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void ivu_toggle_state(uint8_t *data, uint16_t len) +static uint8_t ivu_toggle_state(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { bool result; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + LOG_DBG(""); result = bt_mesh_iv_update(); if (!result) { LOG_ERR("Failed to toggle the IV Update state"); + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_IVU_TOGGLE_STATE, CONTROLLER_INDEX, - result ? BTP_STATUS_SUCCESS : BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void lpn(uint8_t *data, uint16_t len) +static uint8_t lpn(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_lpn_set_cmd *cmd = (void *) data; - bool enable; + const struct btp_mesh_lpn_set_cmd *cp = cmd; int err; - LOG_DBG("enable 0x%02x", cmd->enable); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + LOG_DBG("enable 0x%02x", cp->enable); - enable = cmd->enable ? true : false; - err = bt_mesh_lpn_set(enable); + err = bt_mesh_lpn_set(cp->enable ? true : false); if (err) { LOG_ERR("Failed to toggle LPN (err %d)", err); + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_LPN, CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void lpn_poll(uint8_t *data, uint16_t len) +static uint8_t lpn_poll(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { int err; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + LOG_DBG(""); err = bt_mesh_lpn_poll(); @@ -689,24 +765,34 @@ static void lpn_poll(uint8_t *data, uint16_t len) LOG_ERR("Failed to send poll msg (err %d)", err); } - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_LPN_POLL, CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void net_send(uint8_t *data, uint16_t len) +static uint8_t net_send(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_net_send_cmd *cmd = (void *) data; + const struct btp_mesh_net_send_cmd *cp = cmd; NET_BUF_SIMPLE_DEFINE(msg, UINT8_MAX); + int err; + + if (cmd_len < sizeof(*cp) && + cmd_len != (sizeof(*cp) + cp->payload_len)) { + return BTP_STATUS_FAILED; + } + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, .app_idx = vnd_app_key_idx, - .addr = sys_le16_to_cpu(cmd->dst), - .send_ttl = cmd->ttl, + .addr = sys_le16_to_cpu(cp->dst), + .send_ttl = cp->ttl, }; - int err; LOG_DBG("ttl 0x%02x dst 0x%04x payload_len %d", ctx.send_ttl, - ctx.addr, cmd->payload_len); + ctx.addr, cp->payload_len); if (!bt_mesh_app_key_exists(vnd_app_key_idx)) { (void)bt_mesh_app_key_add(vnd_app_key_idx, net.net_idx, @@ -714,72 +800,92 @@ static void net_send(uint8_t *data, uint16_t len) vnd_models[0].keys[0] = vnd_app_key_idx; } - net_buf_simple_add_mem(&msg, cmd->payload, cmd->payload_len); + net_buf_simple_add_mem(&msg, cp->payload, cp->payload_len); err = bt_mesh_model_send(&vnd_models[0], &ctx, &msg, NULL, NULL); if (err) { LOG_ERR("Failed to send (err %d)", err); + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_NET_SEND, CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void health_generate_faults(uint8_t *data, uint16_t len) +static uint8_t health_generate_faults(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_health_generate_faults_rp *rp; - NET_BUF_SIMPLE_DEFINE(buf, sizeof(*rp) + sizeof(cur_faults) + - sizeof(reg_faults)); + struct btp_mesh_health_generate_faults_rp *rp = rsp; uint8_t some_faults[] = { 0x01, 0x02, 0x03, 0xff, 0x06 }; - uint8_t cur_faults_count, reg_faults_count; + uint8_t cur_faults_count; + uint8_t reg_faults_count; - rp = net_buf_simple_add(&buf, sizeof(*rp)); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } cur_faults_count = MIN(sizeof(cur_faults), sizeof(some_faults)); memcpy(cur_faults, some_faults, cur_faults_count); - net_buf_simple_add_mem(&buf, cur_faults, cur_faults_count); + memcpy(rp->current_faults, cur_faults, cur_faults_count); rp->cur_faults_count = cur_faults_count; reg_faults_count = MIN(sizeof(reg_faults), sizeof(some_faults)); memcpy(reg_faults, some_faults, reg_faults_count); - net_buf_simple_add_mem(&buf, reg_faults, reg_faults_count); + memcpy(rp->registered_faults + cur_faults_count, reg_faults, reg_faults_count); rp->reg_faults_count = reg_faults_count; bt_mesh_health_srv_fault_update(&elements[0]); - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_GENERATE_FAULTS, - CONTROLLER_INDEX, buf.data, buf.len); + *rsp_len = sizeof(*rp) + cur_faults_count + reg_faults_count; + + return BTP_STATUS_SUCCESS; } -static void health_clear_faults(uint8_t *data, uint16_t len) +static uint8_t health_clear_faults(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { LOG_DBG(""); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + (void)memset(cur_faults, 0, sizeof(cur_faults)); (void)memset(reg_faults, 0, sizeof(reg_faults)); bt_mesh_health_srv_fault_update(&elements[0]); - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_CLEAR_FAULTS, - CONTROLLER_INDEX, BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void model_send(uint8_t *data, uint16_t len) +static uint8_t model_send(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_model_send_cmd *cmd = (void *) data; + const struct btp_mesh_model_send_cmd *cp = cmd; NET_BUF_SIMPLE_DEFINE(msg, UINT8_MAX); + struct bt_mesh_model *model = NULL; + uint16_t src; + int err; + + if (cmd_len < sizeof(*cp) && + cmd_len != (sizeof(*cp) + cp->payload_len)) { + return BTP_STATUS_FAILED; + } + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, .app_idx = BT_MESH_KEY_DEV, - .addr = sys_le16_to_cpu(cmd->dst), + .addr = sys_le16_to_cpu(cp->dst), .send_ttl = BT_MESH_TTL_DEFAULT, }; - struct bt_mesh_model *model = NULL; - int err, i; - uint16_t src = sys_le16_to_cpu(cmd->src); + + src = sys_le16_to_cpu(cp->src); /* Lookup source address */ - for (i = 0; i < ARRAY_SIZE(model_bound); i++) { + for (int i = 0; i < ARRAY_SIZE(model_bound); i++) { if (bt_mesh_model_elem(model_bound[i].model)->addr == src) { model = model_bound[i].model; ctx.app_idx = model_bound[i].appkey_idx; @@ -790,31 +896,29 @@ static void model_send(uint8_t *data, uint16_t len) if (!model) { LOG_ERR("Model not found"); - err = -EINVAL; - - goto fail; + return BTP_STATUS_FAILED; } LOG_DBG("src 0x%04x dst 0x%04x model %p payload_len %d", src, - ctx.addr, model, cmd->payload_len); + ctx.addr, model, cp->payload_len); - net_buf_simple_add_mem(&msg, cmd->payload, cmd->payload_len); + net_buf_simple_add_mem(&msg, cp->payload, cp->payload_len); err = bt_mesh_model_send(model, &ctx, &msg, NULL, NULL); if (err) { LOG_ERR("Failed to send (err %d)", err); + return BTP_STATUS_FAILED; } -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_MODEL_SEND, CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } #if defined(CONFIG_BT_TESTING) -static void lpn_subscribe(uint8_t *data, uint16_t len) +static uint8_t lpn_subscribe(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_lpn_subscribe_cmd *cmd = (void *) data; - uint16_t address = sys_le16_to_cpu(cmd->address); + const struct btp_mesh_lpn_subscribe_cmd *cp = cmd; + uint16_t address = sys_le16_to_cpu(cp->address); int err; LOG_DBG("address 0x%04x", address); @@ -822,16 +926,17 @@ static void lpn_subscribe(uint8_t *data, uint16_t len) err = bt_test_mesh_lpn_group_add(address); if (err) { LOG_ERR("Failed to subscribe (err %d)", err); + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_LPN_SUBSCRIBE, CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void lpn_unsubscribe(uint8_t *data, uint16_t len) +static uint8_t lpn_unsubscribe(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_lpn_unsubscribe_cmd *cmd = (void *) data; - uint16_t address = sys_le16_to_cpu(cmd->address); + const struct btp_mesh_lpn_unsubscribe_cmd *cp = cmd; + uint16_t address = sys_le16_to_cpu(cp->address); int err; LOG_DBG("address 0x%04x", address); @@ -839,13 +944,14 @@ static void lpn_unsubscribe(uint8_t *data, uint16_t len) err = bt_test_mesh_lpn_group_remove(&address, 1); if (err) { LOG_ERR("Failed to unsubscribe (err %d)", err); + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_LPN_UNSUBSCRIBE, CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void rpl_clear(uint8_t *data, uint16_t len) +static uint8_t rpl_clear(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { int err; @@ -854,14 +960,15 @@ static void rpl_clear(uint8_t *data, uint16_t len) err = bt_test_mesh_rpl_clear(); if (err) { LOG_ERR("Failed to clear RPL (err %d)", err); + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_RPL_CLEAR, CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } #endif /* CONFIG_BT_TESTING */ -static void proxy_identity_enable(uint8_t *data, uint16_t len) +static uint8_t proxy_identity_enable(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { int err; @@ -870,531 +977,622 @@ static void proxy_identity_enable(uint8_t *data, uint16_t len) err = bt_mesh_proxy_identity_enable(); if (err) { LOG_ERR("Failed to enable proxy identity (err %d)", err); + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_PROXY_IDENTITY, CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void composition_data_get(uint8_t *data, uint16_t len) +static uint8_t composition_data_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_comp_data_get_cmd *cmd = (void *)data; + const struct btp_mesh_comp_data_get_cmd *cp = cmd; + struct btp_mesh_comp_data_get_rp *rp = rsp; uint8_t page; struct net_buf_simple *comp = NET_BUF_SIMPLE(128); int err; LOG_DBG(""); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + bt_mesh_cfg_cli_timeout_set(10 * MSEC_PER_SEC); net_buf_simple_init(comp, 0); - err = bt_mesh_cfg_cli_comp_data_get(cmd->net_idx, cmd->address, cmd->page, - &page, comp); + err = bt_mesh_cfg_cli_comp_data_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + cp->page, &page, comp); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_COMP_DATA_GET, CONTROLLER_INDEX, - comp->data, comp->len); - return; + memcpy(rp->data, comp->data, comp->len); + *rsp_len = comp->len; -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_COMP_DATA_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_krp_get(uint8_t *data, uint16_t len) +static uint8_t config_krp_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_krp_get_cmd *cmd = (void *)data; - struct net_buf_simple *buf = NET_BUF_SIMPLE(2); + const struct btp_mesh_cfg_krp_get_cmd *cp = cmd; + struct btp_mesh_cfg_krp_get_rp *rp = rsp; uint8_t status; uint8_t phase; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_krp_get(cmd->net_idx, cmd->address, cmd->key_net_idx, &status, - &phase); + err = bt_mesh_cfg_cli_krp_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->key_net_idx), + &status, &phase); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - net_buf_simple_init(buf, 0); - net_buf_simple_add_u8(buf, status); - net_buf_simple_add_u8(buf, phase); + rp->status = status; + rp->phase = phase; - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_KRP_GET, CONTROLLER_INDEX, buf->data, buf->len); - return; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_KRP_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_krp_set(uint8_t *data, uint16_t len) +static uint8_t config_krp_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_krp_set_cmd *cmd = (void *)data; - struct net_buf_simple *buf = NET_BUF_SIMPLE(2); + const struct btp_mesh_cfg_krp_set_cmd *cp = cmd; + struct btp_mesh_cfg_krp_set_rp *rp = rsp; uint8_t status; uint8_t phase; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_krp_set(cmd->net_idx, cmd->address, cmd->key_net_idx, cmd->transition, - &status, &phase); + err = bt_mesh_cfg_cli_krp_set(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->key_net_idx), + cp->transition, &status, &phase); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - net_buf_simple_init(buf, 0); - net_buf_simple_add_u8(buf, status); - net_buf_simple_add_u8(buf, phase); + rp->status = status; + rp->phase = phase; - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_KRP_SET, CONTROLLER_INDEX, buf->data, buf->len); - return; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_KRP_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_beacon_get(uint8_t *data, uint16_t len) +static uint8_t config_beacon_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_beacon_get_cmd *cp = cmd; + struct btp_mesh_cfg_beacon_get_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_beacon_get(cmd->net_idx, cmd->address, &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_beacon_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_BEACON_GET, CONTROLLER_INDEX, - &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_BEACON_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_beacon_set(uint8_t *data, uint16_t len) +static uint8_t config_beacon_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_beacon_set_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_beacon_set_cmd *cp = cmd; + struct btp_mesh_cfg_beacon_set_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_beacon_set(cmd->net_idx, cmd->address, cmd->val, - &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_beacon_set(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), cp->val, + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_BEACON_SET, CONTROLLER_INDEX, - &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_BEACON_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_default_ttl_get(uint8_t *data, uint16_t len) +static uint8_t config_default_ttl_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_default_ttl_get_cmd *cp = cmd; + struct btp_mesh_cfg_default_ttl_get_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_ttl_get(cmd->net_idx, cmd->address, &status); + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_ttl_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_DEFAULT_TTL_GET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_DEFAULT_TTL_GET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_default_ttl_set(uint8_t *data, uint16_t len) +static uint8_t config_default_ttl_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_default_ttl_set_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_default_ttl_set_cmd *cp = cmd; + struct btp_mesh_cfg_default_ttl_set_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_ttl_set(cmd->net_idx, cmd->address, cmd->val, - &status); + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_ttl_set(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), cp->val, + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_DEFAULT_TTL_SET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_DEFAULT_TTL_SET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_gatt_proxy_get(uint8_t *data, uint16_t len) +static uint8_t config_gatt_proxy_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_gatt_proxy_get_cmd *cp = cmd; + struct btp_mesh_cfg_gatt_proxy_get_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_gatt_proxy_get(cmd->net_idx, cmd->address, &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_gatt_proxy_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_GATT_PROXY_GET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_GATT_PROXY_GET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_gatt_proxy_set(uint8_t *data, uint16_t len) +static uint8_t config_gatt_proxy_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_gatt_proxy_set_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_gatt_proxy_set_cmd *cp = cmd; + struct btp_mesh_cfg_gatt_proxy_set_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_gatt_proxy_set(cmd->net_idx, cmd->address, cmd->val, - &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_gatt_proxy_set(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + cp->val, &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_GATT_PROXY_SET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_GATT_PROXY_SET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_friend_get(uint8_t *data, uint16_t len) +static uint8_t config_friend_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_friend_get_cmd *cp = cmd; + struct btp_mesh_cfg_friend_get_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_friend_get(cmd->net_idx, cmd->address, &status); + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_friend_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_FRIEND_GET, CONTROLLER_INDEX, - &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_FRIEND_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_friend_set(uint8_t *data, uint16_t len) +static uint8_t config_friend_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_friend_set_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_friend_set_cmd *cp = cmd; + struct btp_mesh_cfg_friend_set_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_friend_set(cmd->net_idx, cmd->address, cmd->val, - &status); + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_friend_set(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + cp->val, &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_FRIEND_SET, CONTROLLER_INDEX, - &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_FRIEND_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_relay_get(uint8_t *data, uint16_t len) +static uint8_t config_relay_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_relay_get_cmd *cp = cmd; + struct btp_mesh_cfg_relay_get_rp *rp = rsp; uint8_t status; uint8_t transmit; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_relay_get(cmd->net_idx, cmd->address, &status, - &transmit); + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_relay_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), &status, + &transmit); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_RELAY_GET, CONTROLLER_INDEX, - &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_RELAY_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_relay_set(uint8_t *data, uint16_t len) +static uint8_t config_relay_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_relay_set_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_relay_set_cmd *cp = cmd; + struct btp_mesh_cfg_relay_set_rp *rp = rsp; uint8_t status; uint8_t transmit; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_relay_set(cmd->net_idx, cmd->address, cmd->new_relay, - cmd->new_transmit, &status, &transmit); + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_relay_set(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + cp->new_relay, cp->new_transmit, + &status, &transmit); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_RELAY_SET, CONTROLLER_INDEX, - &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_RELAY_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_mod_pub_get(uint8_t *data, uint16_t len) +static uint8_t config_mod_pub_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_pub_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_pub_get_cmd *cp = cmd; + struct btp_mesh_cfg_model_pub_get_rp *rp = rsp; struct bt_mesh_cfg_cli_mod_pub pub; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_pub_get(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->model_id, &pub, - &status); + + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_mod_pub_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->model_id), + &pub, &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_PUB_GET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_PUB_GET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_mod_pub_set(uint8_t *data, uint16_t len) +static uint8_t config_mod_pub_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_pub_set_cmd *cmd = (void *)data; - uint8_t status; + const struct btp_mesh_cfg_model_pub_set_cmd *cp = cmd; + struct btp_mesh_cfg_model_pub_set_rp *rp = rsp; struct bt_mesh_cfg_cli_mod_pub pub; + uint8_t status; int err; LOG_DBG(""); - pub.addr = cmd->pub_addr; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + pub.addr = sys_le16_to_cpu(cp->pub_addr); pub.uuid = NULL; - pub.app_idx = cmd->app_idx; - pub.cred_flag = cmd->cred_flag; - pub.ttl = cmd->ttl; - pub.period = cmd->period; - pub.transmit = cmd->transmit; - - err = bt_mesh_cfg_cli_mod_pub_set(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->model_id, &pub, - &status); + pub.app_idx = sys_le16_to_cpu(cp->app_idx); + pub.cred_flag = cp->cred_flag; + pub.ttl = cp->ttl; + pub.period = cp->period; + pub.transmit = cp->transmit; + + err = bt_mesh_cfg_cli_mod_pub_set(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->model_id), + &pub, &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_PUB_SET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_PUB_SET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_mod_pub_va_set(uint8_t *data, uint16_t len) +static uint8_t config_mod_pub_va_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_pub_va_set_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_pub_va_set_cmd *cp = cmd; + struct btp_mesh_cfg_model_pub_va_set_rp *rp = rsp; uint8_t status; struct bt_mesh_cfg_cli_mod_pub pub; int err; LOG_DBG(""); - pub.uuid = cmd->uuid; - pub.app_idx = cmd->app_idx; - pub.cred_flag = cmd->cred_flag; - pub.ttl = cmd->ttl; - pub.period = cmd->period; - pub.transmit = cmd->transmit; + pub.uuid = cp->uuid; + pub.app_idx = sys_le16_to_cpu(cp->app_idx); + pub.cred_flag = cp->cred_flag; + pub.ttl = cp->ttl; + pub.period = cp->period; + pub.transmit = cp->transmit; - err = bt_mesh_cfg_cli_mod_pub_set(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->model_id, - &pub, &status); + err = bt_mesh_cfg_cli_mod_pub_set(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->model_id), + &pub, &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_PUB_VA_SET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_PUB_VA_SET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_mod_sub_add(uint8_t *data, uint16_t len) +static uint8_t config_mod_sub_add(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_sub_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_sub_add_cmd *cp = cmd; + struct btp_mesh_cfg_model_sub_add_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_sub_add(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->sub_addr, - cmd->model_id, &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_mod_sub_add(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->sub_addr), + sys_le16_to_cpu(cp->model_id), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_ADD, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_ADD, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_mod_sub_ovw(uint8_t *data, uint16_t len) +static uint8_t config_mod_sub_ovw(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_sub_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_sub_add_cmd *cp = cmd; + struct btp_mesh_cfg_model_sub_add_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_sub_overwrite(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->sub_addr, - cmd->model_id, &status); - + err = bt_mesh_cfg_cli_mod_sub_overwrite(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->sub_addr), + sys_le16_to_cpu(cp->model_id), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_OVW, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_OVW, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_mod_sub_del(uint8_t *data, uint16_t len) +static uint8_t config_mod_sub_del(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_sub_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_sub_del_cmd *cp = cmd; + struct btp_mesh_cfg_model_sub_del_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_sub_del(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->sub_addr, - cmd->model_id, &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + err = bt_mesh_cfg_cli_mod_sub_del(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->sub_addr), + sys_le16_to_cpu(cp->model_id), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_DEL, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_DEL, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_mod_sub_del_all(uint8_t *data, uint16_t len) +static uint8_t config_mod_sub_del_all(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_sub_del_all_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_sub_del_all_cmd *cp = cmd; + struct btp_mesh_cfg_model_sub_del_all_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_sub_del_all(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->model_id, - &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_mod_sub_del_all(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->model_id), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_DEL_ALL, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_DEL_ALL, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_mod_sub_get(uint8_t *data, uint16_t len) +static uint8_t config_mod_sub_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_sub_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_sub_get_cmd *cp = cmd; + struct btp_mesh_cfg_model_sub_get_rp *rp = rsp; uint8_t status; int16_t subs; size_t sub_cn; @@ -1402,27 +1600,31 @@ static void config_mod_sub_get(uint8_t *data, uint16_t len) LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_sub_get(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->model_id, &status, - &subs, &sub_cn); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + err = bt_mesh_cfg_cli_mod_sub_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->model_id), + &status, &subs, &sub_cn); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_GET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_GET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_mod_sub_get_vnd(uint8_t *data, uint16_t len) +static uint8_t config_mod_sub_get_vnd(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_sub_get_vnd_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_sub_get_vnd_cmd *cp = cmd; + struct btp_mesh_cfg_model_sub_get_vnd_rp *rp = rsp; uint8_t status; uint16_t subs; size_t sub_cn; @@ -1430,391 +1632,478 @@ static void config_mod_sub_get_vnd(uint8_t *data, uint16_t len) LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_sub_get_vnd(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->model_id, - cmd->cid, &status, &subs, &sub_cn); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_mod_sub_get_vnd(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->model_id), + sys_le16_to_cpu(cp->cid), + &status, &subs, &sub_cn); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_GET_VND, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_GET_VND, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_mod_sub_va_add(uint8_t *data, uint16_t len) +static uint8_t config_mod_sub_va_add(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_sub_va_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_sub_va_add_cmd *cp = cmd; + struct btp_mesh_cfg_model_sub_va_add_rp *rp = rsp; uint8_t status; uint16_t virt_addr_rcv; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_sub_va_add(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->uuid, - cmd->model_id, &virt_addr_rcv, - &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_mod_sub_va_add(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->uuid), + sys_le16_to_cpu(cp->model_id), + &virt_addr_rcv, &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_VA_ADD, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_VA_ADD, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_mod_sub_va_del(uint8_t *data, uint16_t len) +static uint8_t config_mod_sub_va_del(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_sub_va_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_sub_va_del_cmd *cp = cmd; + struct btp_mesh_cfg_model_sub_va_del_rp *rp = rsp; uint8_t status; uint16_t virt_addr_rcv; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_sub_va_del(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->uuid, - cmd->model_id, &virt_addr_rcv, - &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_mod_sub_va_del(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->uuid), + sys_le16_to_cpu(cp->model_id), + &virt_addr_rcv, &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_VA_DEL, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_VA_DEL, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_mod_sub_va_ovw(uint8_t *data, uint16_t len) +static uint8_t config_mod_sub_va_ovw(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_sub_va_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_sub_va_ovw_cmd *cp = cmd; + struct btp_mesh_cfg_model_sub_va_ovw_rp *rp = rsp; uint8_t status; uint16_t virt_addr_rcv; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_sub_va_overwrite(cmd->net_idx, cmd->address, - cmd->elem_address, - cmd->uuid, cmd->model_id, - &virt_addr_rcv, &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_mod_sub_va_overwrite(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->uuid), + sys_le16_to_cpu(cp->model_id), + &virt_addr_rcv, &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_VA_OVW, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_SUB_VA_OVW, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_netkey_add(uint8_t *data, uint16_t len) +static uint8_t config_netkey_add(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_netkey_add_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_netkey_add_cmd *cp = cmd; + struct btp_mesh_cfg_netkey_add_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_net_key_add(cmd->net_idx, cmd->address, - cmd->net_key_idx, cmd->net_key, &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_net_key_add(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->net_key_idx), + cp->net_key, &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_ADD, CONTROLLER_INDEX, - &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_ADD, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_netkey_update(uint8_t *data, uint16_t len) +static uint8_t config_netkey_update(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_netkey_add_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_netkey_update_cmd *cp = cmd; + struct btp_mesh_cfg_netkey_update_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_net_key_update(cmd->net_idx, cmd->address, - cmd->net_key_idx, cmd->net_key, - &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_net_key_update(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->net_key_idx), + cp->net_key, + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_UPDATE, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_UPDATE, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_netkey_get(uint8_t *data, uint16_t len) +static uint8_t config_netkey_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_netkey_get_cmd *cp = cmd; + struct btp_mesh_cfg_netkey_get_rp *rp = rsp; + size_t key_cnt = 1; uint16_t keys; - size_t key_cnt; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_net_key_get(cmd->net_idx, cmd->address, &keys, - &key_cnt); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + err = bt_mesh_cfg_cli_net_key_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + &keys, &key_cnt); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_GET, CONTROLLER_INDEX, - (uint8_t *)&keys, key_cnt); - return; + /* for historical reasons this command has status in response */ + rp->status = 0; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_netkey_del(uint8_t *data, uint16_t len) +static uint8_t config_netkey_del(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_netkey_del_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_netkey_del_cmd *cp = cmd; + struct btp_mesh_cfg_netkey_del_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_net_key_del(cmd->net_idx, cmd->address, - cmd->net_key_idx, &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_net_key_del(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->net_key_idx), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_DEL, CONTROLLER_INDEX, - &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NETKEY_DEL, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_appkey_add(uint8_t *data, uint16_t len) +static uint8_t config_appkey_add(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_appkey_add_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_appkey_add_cmd *cp = cmd; + struct btp_mesh_cfg_appkey_add_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_app_key_add(cmd->net_idx, cmd->address, - cmd->net_key_idx, cmd->app_key_idx, - cmd->app_key, &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_app_key_add(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->net_key_idx), + sys_le16_to_cpu(cp->app_key_idx), + sys_le16_to_cpu(cp->app_key), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_ADD, CONTROLLER_INDEX, - &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_ADD, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_appkey_update(uint8_t *data, uint16_t len) +static uint8_t config_appkey_update(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_appkey_add_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_appkey_update_cmd *cp = cmd; + struct btp_mesh_cfg_appkey_update_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_app_key_update(cmd->net_idx, cmd->address, - cmd->net_key_idx, cmd->app_key_idx, - cmd->app_key, &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_app_key_update(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->net_key_idx), + sys_le16_to_cpu(cp->app_key_idx), + sys_le16_to_cpu(cp->app_key), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_UPDATE, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_UPDATE, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_appkey_del(uint8_t *data, uint16_t len) +static uint8_t config_appkey_del(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_appkey_del_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_appkey_del_cmd *cp = cmd; + struct btp_mesh_cfg_appkey_del_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_app_key_del(cmd->net_idx, cmd->address, - cmd->net_key_idx, cmd->app_key_idx, - &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_app_key_del(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->net_key_idx), + sys_le16_to_cpu(cp->app_key_idx), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_DEL, CONTROLLER_INDEX, - &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_DEL, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_appkey_get(uint8_t *data, uint16_t len) +static uint8_t config_appkey_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_appkey_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_appkey_get_cmd *cp = cmd; + struct btp_mesh_cfg_appkey_get_rp *rp = rsp; uint8_t status; uint16_t keys; - size_t key_cnt; + size_t key_cnt = 1; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_app_key_get(cmd->net_idx, cmd->address, - cmd->net_key_idx, &status, &keys, - &key_cnt); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_app_key_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->net_key_idx), + &status, &keys, &key_cnt); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_GET, CONTROLLER_INDEX, - &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_APPKEY_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_model_app_bind(uint8_t *data, uint16_t len) + +static uint8_t config_model_app_bind(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_app_bind_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_app_bind_cmd *cp = cmd; + struct btp_mesh_cfg_model_app_bind_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_app_bind(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->app_key_idx, - cmd->mod_id, &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_mod_app_bind(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->app_key_idx), + sys_le16_to_cpu(cp->mod_id), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_BIND, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_BIND, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_model_app_bind_vnd(uint8_t *data, uint16_t len) +static uint8_t config_model_app_bind_vnd(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_app_bind_vnd_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_app_bind_vnd_cmd *cp = cmd; + struct btp_mesh_cfg_model_app_bind_vnd_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_app_bind_vnd(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->app_key_idx, - cmd->mod_id, cmd->cid, &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_mod_app_bind_vnd(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->app_key_idx), + sys_le16_to_cpu(cp->mod_id), + sys_le16_to_cpu(cp->cid), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_BIND_VND, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_BIND_VND, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_model_app_unbind(uint8_t *data, uint16_t len) +static uint8_t config_model_app_unbind(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_app_bind_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_app_unbind_cmd *cp = cmd; + struct btp_mesh_cfg_model_app_unbind_rp *rp = rsp; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_app_unbind(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->app_key_idx, - cmd->mod_id, &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + err = bt_mesh_cfg_cli_mod_app_unbind(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->app_key_idx), + sys_le16_to_cpu(cp->mod_id), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_UNBIND, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_UNBIND, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_model_app_get(uint8_t *data, uint16_t len) + +static uint8_t config_model_app_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_app_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_app_get_cmd *cp = cmd; + struct btp_mesh_cfg_model_app_get_rp *rp = rsp; uint8_t status; uint16_t apps; size_t app_cnt; @@ -1822,27 +2111,32 @@ static void config_model_app_get(uint8_t *data, uint16_t len) LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_app_get(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->mod_id, &status, - &apps, &app_cnt); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_mod_app_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->mod_id), + &status, &apps, &app_cnt); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_GET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_GET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_model_app_vnd_get(uint8_t *data, uint16_t len) +static uint8_t config_model_app_vnd_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_model_app_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_model_app_vnd_get_cmd *cp = cmd; + struct btp_mesh_cfg_model_app_vnd_get_rp *rp = rsp; uint8_t status; uint16_t apps; size_t app_cnt; @@ -1850,303 +2144,316 @@ static void config_model_app_vnd_get(uint8_t *data, uint16_t len) LOG_DBG(""); - err = bt_mesh_cfg_cli_mod_app_get_vnd(cmd->net_idx, cmd->address, - cmd->elem_address, cmd->mod_id, - cmd->cid, &status, &apps, &app_cnt); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + err = bt_mesh_cfg_cli_mod_app_get_vnd(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->elem_address), + sys_le16_to_cpu(cp->mod_id), + sys_le16_to_cpu(cp->cid), + &status, &apps, &app_cnt); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_VND_GET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_MODEL_APP_VND_GET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_hb_pub_set(uint8_t *data, uint16_t len) +static uint8_t config_hb_pub_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_heartbeat_pub_set_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_heartbeat_pub_set_cmd *cp = cmd; + struct btp_mesh_cfg_heartbeat_pub_set_rp *rp = rsp; uint8_t status; struct bt_mesh_cfg_cli_hb_pub pub; int err; LOG_DBG(""); - pub.net_idx = cmd->net_key_idx; - pub.dst = cmd->destination; - pub.count = cmd->count_log; - pub.period = cmd->period_log; - pub.ttl = cmd->ttl; - pub.feat = cmd->features; + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + pub.net_idx = sys_le16_to_cpu(cp->net_key_idx); + pub.dst = sys_le16_to_cpu(cp->destination); + pub.count = cp->count_log; + pub.period = cp->period_log; + pub.ttl = cp->ttl; + pub.feat = sys_le16_to_cpu(cp->features); - err = bt_mesh_cfg_cli_hb_pub_set(cmd->net_idx, cmd->address, &pub, &status); + err = bt_mesh_cfg_cli_hb_pub_set(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + &pub, &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_PUB_SET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_PUB_SET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_hb_pub_get(uint8_t *data, uint16_t len) +static uint8_t config_hb_pub_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_heartbeat_pub_get_cmd *cp = cmd; + struct btp_mesh_cfg_heartbeat_pub_get_rp *rp = rsp; uint8_t status; struct bt_mesh_cfg_cli_hb_pub pub; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_hb_pub_get(cmd->net_idx, cmd->address, &pub, &status); + if (index != CONTROLLER_INDEX) { + return BTP_STATUS_FAILED; + } + + err = bt_mesh_cfg_cli_hb_pub_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + &pub, &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_PUB_GET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_PUB_GET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_hb_sub_set(uint8_t *data, uint16_t len) +static uint8_t config_hb_sub_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_heartbeat_sub_set_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_heartbeat_sub_set_cmd *cp = cmd; + struct btp_mesh_cfg_heartbeat_sub_set_rp *rp = rsp; uint8_t status; struct bt_mesh_cfg_cli_hb_sub sub; int err; LOG_DBG(""); - sub.src = cmd->source; - sub.dst = cmd->destination; - sub.period = cmd->period_log; + sub.src = sys_le16_to_cpu(cp->source); + sub.dst = sys_le16_to_cpu(cp->destination); + sub.period = cp->period_log; - err = bt_mesh_cfg_cli_hb_sub_set(cmd->net_idx, cmd->address, &sub, &status); + err = bt_mesh_cfg_cli_hb_sub_set(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + &sub, &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_SUB_SET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_SUB_SET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_hb_sub_get(uint8_t *data, uint16_t len) +static uint8_t config_hb_sub_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_heartbeat_sub_get_cmd *cp = cmd; + struct btp_mesh_cfg_heartbeat_sub_get_rp *rp = rsp; uint8_t status; struct bt_mesh_cfg_cli_hb_sub sub; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_hb_sub_get(cmd->net_idx, cmd->address, &sub, &status); + err = bt_mesh_cfg_cli_hb_sub_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + &sub, &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_SUB_GET, - CONTROLLER_INDEX, &status, sizeof(status)); - return; + rp->status = status; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_HEARTBEAT_SUB_GET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_net_trans_get(uint8_t *data, uint16_t len) +static uint8_t config_net_trans_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_val_get_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_net_trans_get_cmd *cp = cmd; + struct btp_mesh_cfg_net_trans_get_rp *rp = rsp; uint8_t transmit; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_net_transmit_get(cmd->net_idx, cmd->address, - &transmit); + err = bt_mesh_cfg_cli_net_transmit_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + &transmit); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NET_TRANS_GET, - CONTROLLER_INDEX, &transmit, sizeof(transmit)); - return; + rp->transmit = transmit; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NET_TRANS_GET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_net_trans_set(uint8_t *data, uint16_t len) +static uint8_t config_net_trans_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_net_trans_set_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_net_trans_set_cmd *cp = cmd; + struct btp_mesh_cfg_net_trans_set_rp *rp = rsp; uint8_t transmit; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_net_transmit_set(cmd->net_idx, cmd->address, - cmd->transmit, &transmit); + err = bt_mesh_cfg_cli_net_transmit_set(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + cp->transmit, &transmit); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NET_TRANS_SET, - CONTROLLER_INDEX, &transmit, sizeof(transmit)); - return; + rp->transmit = transmit; + *rsp_len = sizeof(*rp); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NET_TRANS_SET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + return BTP_STATUS_SUCCESS; } -static void config_node_identity_set(uint8_t *data, uint16_t len) +static uint8_t config_node_identity_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_node_idt_set_cmd *cmd = (void *)data; - struct net_buf_simple *buf = NET_BUF_SIMPLE(2); + const struct btp_mesh_cfg_node_idt_set_cmd *cp = cmd; + struct btp_mesh_cfg_node_idt_set_rp *rp = rsp; uint8_t identity; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_node_identity_set(cmd->net_idx, cmd->address, - cmd->net_key_idx, cmd->new_identity, - &status, &identity); + err = bt_mesh_cfg_cli_node_identity_set(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->net_key_idx), + cp->new_identity, + &status, &identity); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - net_buf_simple_init(buf, 0); - net_buf_simple_add_u8(buf, status); - net_buf_simple_add_u8(buf, identity); - - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NODE_IDT_SET, - CONTROLLER_INDEX, buf->data, buf->len); - return; + rp->status = status; + rp->identity = identity; -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NODE_IDT_SET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + *rsp_len = sizeof(*rp); + return BTP_STATUS_SUCCESS; } -static void config_node_identity_get(uint8_t *data, uint16_t len) +static uint8_t config_node_identity_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_node_idt_get_cmd *cmd = (void *)data; - struct net_buf_simple *buf = NET_BUF_SIMPLE(2); + const struct btp_mesh_cfg_node_idt_get_cmd *cp = cmd; + struct btp_mesh_cfg_node_idt_get_rp *rp = rsp; uint8_t identity; uint8_t status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_node_identity_get(cmd->net_idx, cmd->address, - cmd->net_key_idx, &status, - &identity); + err = bt_mesh_cfg_cli_node_identity_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->net_key_idx), + &status, &identity); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - net_buf_simple_init(buf, 0); - net_buf_simple_add_u8(buf, status); - net_buf_simple_add_u8(buf, identity); - - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NODE_IDT_GET, - CONTROLLER_INDEX, buf->data, buf->len); - return; + rp->status = status; + rp->identity = identity; -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NODE_IDT_GET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + *rsp_len = sizeof(*rp); + return BTP_STATUS_SUCCESS; } -static void config_node_reset(uint8_t *data, uint16_t len) +static uint8_t config_node_reset(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_node_reset_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_node_reset_cmd *cp = cmd; + struct btp_mesh_cfg_node_reset_rp *rp = rsp; bool status; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_node_reset(cmd->net_idx, cmd->address, &status); + err = bt_mesh_cfg_cli_node_reset(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + &status); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NODE_RESET, CONTROLLER_INDEX, - (uint8_t *)&status, sizeof(status)); - return; + rp->status = status; -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_NODE_RESET, CONTROLLER_INDEX, BTP_STATUS_FAILED); + *rsp_len = sizeof(*rp); + return BTP_STATUS_SUCCESS; } -static void config_lpn_timeout_get(uint8_t *data, uint16_t len) +static uint8_t config_lpn_timeout_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_cfg_lpn_timeout_cmd *cmd = (void *)data; + const struct btp_mesh_cfg_lpn_timeout_cmd *cp = cmd; + struct btp_mesh_cfg_lpn_timeout_rp *rp = rsp; int32_t polltimeout; int err; LOG_DBG(""); - err = bt_mesh_cfg_cli_lpn_timeout_get(cmd->net_idx, cmd->address, - cmd->unicast_addr, &polltimeout); + err = bt_mesh_cfg_cli_lpn_timeout_get(sys_le16_to_cpu(cp->net_idx), + sys_le16_to_cpu(cp->address), + sys_le16_to_cpu(cp->unicast_addr), + &polltimeout); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_LPN_TIMEOUT_GET, - CONTROLLER_INDEX, (uint8_t *)&polltimeout, - sizeof(polltimeout)); - return; + rp->timeout = sys_cpu_to_le32(polltimeout); -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_CFG_LPN_TIMEOUT_GET, CONTROLLER_INDEX, - BTP_STATUS_FAILED); + *rsp_len = sizeof(*rp); + return BTP_STATUS_SUCCESS; } -static void health_fault_get(uint8_t *data, uint16_t len) +static uint8_t health_fault_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_health_fault_get_cmd *cmd = (void *)data; + const struct btp_mesh_health_fault_get_cmd *cp = cmd; struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, - .addr = cmd->address, - .app_idx = cmd->app_idx, + .addr = sys_le16_to_cpu(cp->address), + .app_idx = sys_le16_to_cpu(cp->app_idx), }; uint8_t test_id; size_t fault_count = 16; @@ -2155,26 +2462,26 @@ static void health_fault_get(uint8_t *data, uint16_t len) LOG_DBG(""); - err = bt_mesh_health_cli_fault_get(&health_cli, &ctx, cmd->cid, &test_id, faults, - &fault_count); + err = bt_mesh_health_cli_fault_get(&health_cli, &ctx, + sys_le16_to_cpu(cp->cid), &test_id, + faults, &fault_count); if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_FAULT_GET, CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void health_fault_clear(uint8_t *data, uint16_t len) +static uint8_t health_fault_clear(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_health_fault_clear_cmd *cmd = (void *)data; + const struct btp_mesh_health_fault_clear_cmd *cp = cmd; struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, - .addr = cmd->address, - .app_idx = cmd->app_idx, + .addr = sys_le16_to_cpu(cp->address), + .app_idx = sys_le16_to_cpu(cp->app_idx), }; uint8_t test_id; size_t fault_count = 16; @@ -2183,38 +2490,39 @@ static void health_fault_clear(uint8_t *data, uint16_t len) LOG_DBG(""); - if (cmd->ack) { - err = bt_mesh_health_cli_fault_clear(&health_cli, &ctx, cmd->cid, &test_id, faults, + if (cp->ack) { + err = bt_mesh_health_cli_fault_clear(&health_cli, &ctx, + sys_le16_to_cpu(cp->cid), + &test_id, faults, &fault_count); } else { - err = bt_mesh_health_cli_fault_clear_unack(&health_cli, &ctx, cmd->cid); + err = bt_mesh_health_cli_fault_clear_unack(&health_cli, &ctx, + sys_le16_to_cpu(cp->cid)); } if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - if (cmd->ack) { - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_FAULT_CLEAR, - CONTROLLER_INDEX, &test_id, sizeof(test_id)); - return; + if (cp->ack) { + struct btp_mesh_health_fault_clear_rp *rp = rsp; + + rp->test_id = test_id; + *rsp_len = sizeof(*rp); } -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_FAULT_CLEAR, - CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void health_fault_test(uint8_t *data, uint16_t len) +static uint8_t health_fault_test(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_health_fault_test_cmd *cmd = (void *)data; - struct net_buf_simple *buf = NET_BUF_SIMPLE(19); + const struct btp_mesh_health_fault_test_cmd *cp = cmd; struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, - .addr = cmd->address, - .app_idx = cmd->app_idx, + .addr = sys_le16_to_cpu(cp->address), + .app_idx = sys_le16_to_cpu(cp->app_idx), }; size_t fault_count = 16; uint8_t faults[fault_count]; @@ -2224,10 +2532,10 @@ static void health_fault_test(uint8_t *data, uint16_t len) LOG_DBG(""); - test_id = cmd->test_id; - cid = cmd->cid; + test_id = cp->test_id; + cid = sys_le16_to_cpu(cp->cid); - if (cmd->ack) { + if (cp->ack) { err = bt_mesh_health_cli_fault_test(&health_cli, &ctx, cid, test_id, faults, &fault_count); } else { @@ -2236,33 +2544,30 @@ static void health_fault_test(uint8_t *data, uint16_t len) if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - if (cmd->ack) { - net_buf_simple_init(buf, 0); - net_buf_simple_add_u8(buf, test_id); - net_buf_simple_add_le16(buf, cid); - net_buf_simple_add_mem(buf, faults, fault_count); + if (cp->ack) { + struct btp_mesh_health_fault_test_rp *rp = rsp; - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_FAULT_TEST, - CONTROLLER_INDEX, buf->data, buf->len); - return; + rp->test_id = test_id; + rp->cid = sys_cpu_to_le16(cid); + (void)memcpy(rp->faults, faults, fault_count); + + *rsp_len = sizeof(*rp) + fault_count; } -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_FAULT_TEST, - CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void health_period_get(uint8_t *data, uint16_t len) +static uint8_t health_period_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_health_period_get_cmd *cmd = (void *)data; + const struct btp_mesh_health_period_get_cmd *cp = cmd; struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, - .addr = cmd->address, - .app_idx = cmd->app_idx, + .addr = sys_le16_to_cpu(cp->address), + .app_idx = sys_le16_to_cpu(cp->app_idx), }; uint8_t divisor; int err; @@ -2273,60 +2578,57 @@ static void health_period_get(uint8_t *data, uint16_t len) if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_PERIOD_GET, - CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void health_period_set(uint8_t *data, uint16_t len) +static uint8_t health_period_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_health_period_set_cmd *cmd = (void *)data; + const struct btp_mesh_health_period_set_cmd *cp = cmd; struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, - .addr = cmd->address, - .app_idx = cmd->app_idx, + .addr = sys_le16_to_cpu(cp->address), + .app_idx = sys_le16_to_cpu(cp->app_idx), }; uint8_t updated_divisor; int err; LOG_DBG(""); - if (cmd->ack) { - err = bt_mesh_health_cli_period_set(&health_cli, &ctx, cmd->divisor, + if (cp->ack) { + err = bt_mesh_health_cli_period_set(&health_cli, &ctx, cp->divisor, &updated_divisor); } else { - err = bt_mesh_health_cli_period_set_unack(&health_cli, &ctx, cmd->divisor); + err = bt_mesh_health_cli_period_set_unack(&health_cli, &ctx, cp->divisor); } if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - if (cmd->ack) { - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_PERIOD_SET, - CONTROLLER_INDEX, &updated_divisor, - sizeof(updated_divisor)); - return; + if (cp->ack) { + struct btp_mesh_health_period_set_rp *rp = rsp; + + rp->divisor = updated_divisor; + + *rsp_len = sizeof(*rp); } -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_PERIOD_SET, - CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void health_attention_get(uint8_t *data, uint16_t len) +static uint8_t health_attention_get(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_health_attention_get_cmd *cmd = (void *)data; + const struct btp_mesh_health_attention_get_cmd *cp = cmd; struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, - .addr = cmd->address, - .app_idx = cmd->app_idx, + .addr = sys_le16_to_cpu(cp->address), + .app_idx = sys_le16_to_cpu(cp->app_idx), }; uint8_t attention; int err; @@ -2337,289 +2639,428 @@ static void health_attention_get(uint8_t *data, uint16_t len) if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_ATTENTION_GET, - CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -static void health_attention_set(uint8_t *data, uint16_t len) +static uint8_t health_attention_set(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - struct btp_mesh_health_attention_set_cmd *cmd = (void *)data; + const struct btp_mesh_health_attention_set_cmd *cp = cmd; struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, - .addr = cmd->address, - .app_idx = cmd->app_idx, + .addr = sys_le16_to_cpu(cp->address), + .app_idx = sys_le16_to_cpu(cp->app_idx), }; uint8_t updated_attention; int err; LOG_DBG(""); - if (cmd->ack) { - err = bt_mesh_health_cli_attention_set(&health_cli, &ctx, cmd->attention, + if (cp->ack) { + err = bt_mesh_health_cli_attention_set(&health_cli, &ctx, cp->attention, &updated_attention); } else { - err = bt_mesh_health_cli_attention_set_unack(&health_cli, &ctx, cmd->attention); + err = bt_mesh_health_cli_attention_set_unack(&health_cli, &ctx, cp->attention); } if (err) { LOG_ERR("err %d", err); - goto fail; + return BTP_STATUS_FAILED; } - if (cmd->ack) { - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_ATTENTION_SET, - CONTROLLER_INDEX, &updated_attention, - sizeof(updated_attention)); - return; + if (cp->ack) { + struct btp_mesh_health_attention_set_rp *rp = rsp; + + rp->attention = updated_attention; + + *rsp_len = sizeof(*rp); } -fail: - tester_rsp(BTP_SERVICE_ID_MESH, BTP_MESH_HEALTH_ATTENTION_SET, - CONTROLLER_INDEX, - err ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS); + return BTP_STATUS_SUCCESS; } -void tester_handle_mesh(uint8_t opcode, uint8_t index, uint8_t *data, uint16_t len) -{ - switch (opcode) { - case BTP_MESH_READ_SUPPORTED_COMMANDS: - supported_commands(data, len); - break; - case BTP_MESH_CONFIG_PROVISIONING: - config_prov(data, len); - break; - case BTP_MESH_PROVISION_NODE: - provision_node(data, len); - break; - case BTP_MESH_INIT: - init(data, len); - break; - case BTP_MESH_RESET: - reset(data, len); - break; - case BTP_MESH_INPUT_NUMBER: - input_number(data, len); - break; - case BTP_MESH_INPUT_STRING: - input_string(data, len); - break; - case BTP_MESH_IVU_TEST_MODE: - ivu_test_mode(data, len); - break; - case BTP_MESH_IVU_TOGGLE_STATE: - ivu_toggle_state(data, len); - break; - case BTP_MESH_LPN: - lpn(data, len); - break; - case BTP_MESH_LPN_POLL: - lpn_poll(data, len); - break; - case BTP_MESH_NET_SEND: - net_send(data, len); - break; - case BTP_MESH_HEALTH_GENERATE_FAULTS: - health_generate_faults(data, len); - break; - case BTP_MESH_HEALTH_CLEAR_FAULTS: - health_clear_faults(data, len); - break; - case BTP_MESH_MODEL_SEND: - model_send(data, len); - break; - case BTP_MESH_COMP_DATA_GET: - composition_data_get(data, len); - break; - case BTP_MESH_CFG_BEACON_GET: - config_beacon_get(data, len); - break; - case BTP_MESH_CFG_BEACON_SET: - config_beacon_set(data, len); - break; - case BTP_MESH_CFG_DEFAULT_TTL_GET: - config_default_ttl_get(data, len); - break; - case BTP_MESH_CFG_DEFAULT_TTL_SET: - config_default_ttl_set(data, len); - break; - case BTP_MESH_CFG_GATT_PROXY_GET: - config_gatt_proxy_get(data, len); - break; - case BTP_MESH_CFG_GATT_PROXY_SET: - config_gatt_proxy_set(data, len); - break; - case BTP_MESH_CFG_FRIEND_GET: - config_friend_get(data, len); - break; - case BTP_MESH_CFG_FRIEND_SET: - config_friend_set(data, len); - break; - case BTP_MESH_CFG_RELAY_GET: - config_relay_get(data, len); - break; - case BTP_MESH_CFG_RELAY_SET: - config_relay_set(data, len); - break; - case BTP_MESH_CFG_MODEL_PUB_GET: - config_mod_pub_get(data, len); - break; - case BTP_MESH_CFG_MODEL_PUB_SET: - config_mod_pub_set(data, len); - break; - case BTP_MESH_CFG_MODEL_SUB_ADD: - config_mod_sub_add(data, len); - break; - case BTP_MESH_CFG_MODEL_SUB_DEL: - config_mod_sub_del(data, len); - break; - case BTP_MESH_CFG_MODEL_SUB_OVW: - config_mod_sub_ovw(data, len); - break; - case BTP_MESH_CFG_MODEL_SUB_DEL_ALL: - config_mod_sub_del_all(data, len); - break; - case BTP_MESH_CFG_MODEL_SUB_GET: - config_mod_sub_get(data, len); - break; - case BTP_MESH_CFG_MODEL_SUB_GET_VND: - config_mod_sub_get_vnd(data, len); - break; - case BTP_MESH_CFG_MODEL_SUB_VA_ADD: - config_mod_sub_va_add(data, len); - break; - case BTP_MESH_CFG_MODEL_SUB_VA_DEL: - config_mod_sub_va_del(data, len); - break; - case BTP_MESH_CFG_MODEL_SUB_VA_OVW: - config_mod_sub_va_ovw(data, len); - break; - case BTP_MESH_CFG_NETKEY_ADD: - config_netkey_add(data, len); - break; - case BTP_MESH_CFG_NETKEY_GET: - config_netkey_get(data, len); - break; - case BTP_MESH_CFG_NETKEY_DEL: - config_netkey_del(data, len); - break; - case BTP_MESH_CFG_NETKEY_UPDATE: - config_netkey_update(data, len); - break; - case BTP_MESH_CFG_APPKEY_ADD: - config_appkey_add(data, len); - break; - case BTP_MESH_CFG_APPKEY_DEL: - config_appkey_del(data, len); - break; - case BTP_MESH_CFG_APPKEY_GET: - config_appkey_get(data, len); - break; - case BTP_MESH_CFG_APPKEY_UPDATE: - config_appkey_update(data, len); - break; - case BTP_MESH_CFG_MODEL_APP_BIND: - config_model_app_bind(data, len); - break; - case BTP_MESH_CFG_MODEL_APP_UNBIND: - config_model_app_unbind(data, len); - break; - case BTP_MESH_CFG_MODEL_APP_GET: - config_model_app_get(data, len); - break; - case BTP_MESH_CFG_MODEL_APP_VND_GET: - config_model_app_vnd_get(data, len); - break; - case BTP_MESH_CFG_HEARTBEAT_PUB_SET: - config_hb_pub_set(data, len); - break; - case BTP_MESH_CFG_HEARTBEAT_PUB_GET: - config_hb_pub_get(data, len); - break; - case BTP_MESH_CFG_HEARTBEAT_SUB_SET: - config_hb_sub_set(data, len); - break; - case BTP_MESH_CFG_HEARTBEAT_SUB_GET: - config_hb_sub_get(data, len); - break; - case BTP_MESH_CFG_NET_TRANS_GET: - config_net_trans_get(data, len); - break; - case BTP_MESH_CFG_NET_TRANS_SET: - config_net_trans_set(data, len); - break; - case BTP_MESH_CFG_NODE_IDT_SET: - config_node_identity_set(data, len); - break; - case BTP_MESH_CFG_NODE_IDT_GET: - config_node_identity_get(data, len); - break; - case BTP_MESH_CFG_NODE_RESET: - config_node_reset(data, len); - break; - case BTP_MESH_CFG_LPN_TIMEOUT_GET: - config_lpn_timeout_get(data, len); - break; - case BTP_MESH_CFG_MODEL_PUB_VA_SET: - config_mod_pub_va_set(data, len); - break; - case BTP_MESH_CFG_MODEL_APP_BIND_VND: - config_model_app_bind_vnd(data, len); - break; - case BTP_MESH_HEALTH_FAULT_GET: - health_fault_get(data, len); - break; - case BTP_MESH_HEALTH_FAULT_CLEAR: - health_fault_clear(data, len); - break; - case BTP_MESH_HEALTH_FAULT_TEST: - health_fault_test(data, len); - break; - case BTP_MESH_HEALTH_PERIOD_GET: - health_period_get(data, len); - break; - case BTP_MESH_HEALTH_PERIOD_SET: - health_period_set(data, len); - break; - case BTP_MESH_HEALTH_ATTENTION_GET: - health_attention_get(data, len); - break; - case BTP_MESH_HEALTH_ATTENTION_SET: - health_attention_set(data, len); - break; - case BTP_MESH_PROVISION_ADV: - provision_adv(data, len); - break; - case BTP_MESH_CFG_KRP_GET: - config_krp_get(data, len); - break; - case BTP_MESH_CFG_KRP_SET: - config_krp_set(data, len); - break; +static const struct btp_handler handlers[] = { + { + .opcode = BTP_MESH_READ_SUPPORTED_COMMANDS, + .expect_len = 0, + .func = supported_commands, + }, + { + .opcode = BTP_MESH_CONFIG_PROVISIONING, + .expect_len = -1, + .func = config_prov, + }, + { + .opcode = BTP_MESH_PROVISION_NODE, + .expect_len = -1, + .func = provision_node, + }, + { + .opcode = BTP_MESH_INIT, + .expect_len = 0, + .func = init, + }, + { + .opcode = BTP_MESH_RESET, + .expect_len = 0, + .func = reset, + }, + { + .opcode = BTP_MESH_INPUT_NUMBER, + .expect_len = sizeof(struct btp_mesh_input_number_cmd), + .func = input_number, + }, + { + .opcode = BTP_MESH_INPUT_STRING, + .expect_len = -1, + .func = input_string, + }, + { + .opcode = BTP_MESH_IVU_TEST_MODE, + .expect_len = sizeof(struct btp_mesh_ivu_test_mode_cmd), + .func = ivu_test_mode, + }, + { + .opcode = BTP_MESH_IVU_TOGGLE_STATE, + .expect_len = 0, + .func = ivu_toggle_state, + }, + { + .opcode = BTP_MESH_LPN, + .expect_len = sizeof(struct btp_mesh_lpn_set_cmd), + .func = lpn, + }, + { + .opcode = BTP_MESH_LPN_POLL, + .expect_len = 0, + .func = lpn_poll, + }, + { + .opcode = BTP_MESH_NET_SEND, + .expect_len = -1, + .func = net_send, + }, + { + .opcode = BTP_MESH_HEALTH_GENERATE_FAULTS, + .expect_len = 0, + .func = health_generate_faults, + }, + { + .opcode = BTP_MESH_HEALTH_CLEAR_FAULTS, + .expect_len = 0, + .func = health_clear_faults, + }, + { + .opcode = BTP_MESH_MODEL_SEND, + .expect_len = -1, + .func = model_send, + }, + { + .opcode = BTP_MESH_COMP_DATA_GET, + .expect_len = sizeof(struct btp_mesh_comp_data_get_cmd), + .func = composition_data_get, + }, + { + .opcode = BTP_MESH_CFG_BEACON_GET, + .expect_len = sizeof(struct btp_mesh_cfg_beacon_get_cmd), + .func = config_beacon_get, + }, + { + .opcode = BTP_MESH_CFG_BEACON_SET, + .expect_len = sizeof(struct btp_mesh_cfg_beacon_set_cmd), + .func = config_beacon_set, + }, + { + .opcode = BTP_MESH_CFG_DEFAULT_TTL_GET, + .expect_len = sizeof(struct btp_mesh_cfg_default_ttl_get_cmd), + .func = config_default_ttl_get, + }, + { + .opcode = BTP_MESH_CFG_DEFAULT_TTL_SET, + .expect_len = sizeof(struct btp_mesh_cfg_default_ttl_set_cmd), + .func = config_default_ttl_set, + }, + { + .opcode = BTP_MESH_CFG_GATT_PROXY_GET, + .expect_len = sizeof(struct btp_mesh_cfg_gatt_proxy_get_cmd), + .func = config_gatt_proxy_get, + }, + { + .opcode = BTP_MESH_CFG_GATT_PROXY_SET, + .expect_len = sizeof(struct btp_mesh_cfg_gatt_proxy_set_cmd), + .func = config_gatt_proxy_set, + }, + { + .opcode = BTP_MESH_CFG_FRIEND_GET, + .expect_len = sizeof(struct btp_mesh_cfg_friend_get_cmd), + .func = config_friend_get, + }, + { + .opcode = BTP_MESH_CFG_FRIEND_SET, + .expect_len = sizeof(struct btp_mesh_cfg_friend_set_cmd), + .func = config_friend_set, + }, + { + .opcode = BTP_MESH_CFG_RELAY_GET, + .expect_len = sizeof(struct btp_mesh_cfg_relay_get_cmd), + .func = config_relay_get, + }, + { + .opcode = BTP_MESH_CFG_RELAY_SET, + .expect_len = sizeof(struct btp_mesh_cfg_relay_set_cmd), + .func = config_relay_set, + }, + { + .opcode = BTP_MESH_CFG_MODEL_PUB_GET, + .expect_len = sizeof(struct btp_mesh_cfg_model_pub_get_cmd), + .func = config_mod_pub_get, + }, + { + .opcode = BTP_MESH_CFG_MODEL_PUB_SET, + .expect_len = sizeof(struct btp_mesh_cfg_model_pub_set_cmd), + .func = config_mod_pub_set, + }, + { + .opcode = BTP_MESH_CFG_MODEL_SUB_ADD, + .expect_len = sizeof(struct btp_mesh_cfg_model_sub_add_cmd), + .func = config_mod_sub_add, + }, + { + .opcode = BTP_MESH_CFG_MODEL_SUB_DEL, + .expect_len = sizeof(struct btp_mesh_cfg_model_sub_del_cmd), + .func = config_mod_sub_del, + }, + { + .opcode = BTP_MESH_CFG_MODEL_SUB_OVW, + .expect_len = sizeof(struct btp_mesh_cfg_model_sub_ovw_cmd), + .func = config_mod_sub_ovw, + }, + { + .opcode = BTP_MESH_CFG_MODEL_SUB_DEL_ALL, + .expect_len = sizeof(struct btp_mesh_cfg_model_sub_del_all_cmd), + .func = config_mod_sub_del_all, + }, + { + .opcode = BTP_MESH_CFG_MODEL_SUB_GET, + .expect_len = sizeof(struct btp_mesh_cfg_model_sub_get_cmd), + .func = config_mod_sub_get, + }, + { + .opcode = BTP_MESH_CFG_MODEL_SUB_GET_VND, + .expect_len = sizeof(struct btp_mesh_cfg_model_sub_get_vnd_cmd), + .func = config_mod_sub_get_vnd, + }, + { + .opcode = BTP_MESH_CFG_MODEL_SUB_VA_ADD, + .expect_len = sizeof(struct btp_mesh_cfg_model_sub_va_add_cmd), + .func = config_mod_sub_va_add, + }, + { + .opcode = BTP_MESH_CFG_MODEL_SUB_VA_DEL, + .expect_len = sizeof(struct btp_mesh_cfg_model_sub_va_del_cmd), + .func = config_mod_sub_va_del, + }, + { + .opcode = BTP_MESH_CFG_MODEL_SUB_VA_OVW, + .expect_len = sizeof(struct btp_mesh_cfg_model_sub_va_ovw_cmd), + .func = config_mod_sub_va_ovw, + }, + { + .opcode = BTP_MESH_CFG_NETKEY_ADD, + .expect_len = sizeof(struct btp_mesh_cfg_netkey_add_cmd), + .func = config_netkey_add, + }, + { + .opcode = BTP_MESH_CFG_NETKEY_GET, + .expect_len = sizeof(struct btp_mesh_cfg_netkey_get_cmd), + .func = config_netkey_get, + }, + { + .opcode = BTP_MESH_CFG_NETKEY_DEL, + .expect_len = sizeof(struct btp_mesh_cfg_netkey_del_cmd), + .func = config_netkey_del, + }, + { + .opcode = BTP_MESH_CFG_NETKEY_UPDATE, + .expect_len = sizeof(struct btp_mesh_cfg_netkey_update_cmd), + .func = config_netkey_update, + }, + { + .opcode = BTP_MESH_CFG_APPKEY_ADD, + .expect_len = sizeof(struct btp_mesh_cfg_appkey_add_cmd), + .func = config_appkey_add, + }, + { + .opcode = BTP_MESH_CFG_APPKEY_GET, + .expect_len = sizeof(struct btp_mesh_cfg_appkey_get_cmd), + .func = config_appkey_get, + }, + { + .opcode = BTP_MESH_CFG_APPKEY_DEL, + .expect_len = sizeof(struct btp_mesh_cfg_appkey_del_cmd), + .func = config_appkey_del, + }, + { + .opcode = BTP_MESH_CFG_APPKEY_UPDATE, + .expect_len = sizeof(struct btp_mesh_cfg_appkey_update_cmd), + .func = config_appkey_update, + }, + { + .opcode = BTP_MESH_CFG_MODEL_APP_BIND, + .expect_len = sizeof(struct btp_mesh_cfg_model_app_bind_cmd), + .func = config_model_app_bind, + }, + { + .opcode = BTP_MESH_CFG_MODEL_APP_UNBIND, + .expect_len = sizeof(struct btp_mesh_cfg_model_app_unbind_cmd), + .func = config_model_app_unbind, + }, + { + .opcode = BTP_MESH_CFG_MODEL_APP_GET, + .expect_len = sizeof(struct btp_mesh_cfg_model_app_get_cmd), + .func = config_model_app_get, + }, + { + .opcode = BTP_MESH_CFG_MODEL_APP_VND_GET, + .expect_len = sizeof(struct btp_mesh_cfg_model_app_vnd_get_cmd), + .func = config_model_app_vnd_get, + }, + { + .opcode = BTP_MESH_CFG_HEARTBEAT_PUB_SET, + .expect_len = sizeof(struct btp_mesh_cfg_heartbeat_pub_set_cmd), + .func = config_hb_pub_set, + }, + { + .opcode = BTP_MESH_CFG_HEARTBEAT_PUB_GET, + .expect_len = sizeof(struct btp_mesh_cfg_heartbeat_pub_get_cmd), + .func = config_hb_pub_get, + }, + { + .opcode = BTP_MESH_CFG_HEARTBEAT_SUB_SET, + .expect_len = sizeof(struct btp_mesh_cfg_heartbeat_sub_set_cmd), + .func = config_hb_sub_set, + }, + { + .opcode = BTP_MESH_CFG_HEARTBEAT_SUB_GET, + .expect_len = sizeof(struct btp_mesh_cfg_heartbeat_sub_get_cmd), + .func = config_hb_sub_get, + }, + { + .opcode = BTP_MESH_CFG_NET_TRANS_GET, + .expect_len = sizeof(struct btp_mesh_cfg_net_trans_get_cmd), + .func = config_net_trans_get, + }, + { + .opcode = BTP_MESH_CFG_NET_TRANS_SET, + .expect_len = sizeof(struct btp_mesh_cfg_net_trans_set_cmd), + .func = config_net_trans_set, + }, + { + .opcode = BTP_MESH_CFG_NODE_IDT_SET, + .expect_len = sizeof(struct btp_mesh_cfg_node_idt_set_cmd), + .func = config_node_identity_set, + }, + { + .opcode = BTP_MESH_CFG_NODE_IDT_GET, + .expect_len = sizeof(struct btp_mesh_cfg_node_idt_get_cmd), + .func = config_node_identity_get, + }, + { + .opcode = BTP_MESH_CFG_NODE_RESET, + .expect_len = sizeof(struct btp_mesh_cfg_node_reset_cmd), + .func = config_node_reset, + }, + { + .opcode = BTP_MESH_CFG_LPN_TIMEOUT_GET, + .expect_len = sizeof(struct btp_mesh_cfg_lpn_timeout_cmd), + .func = config_lpn_timeout_get, + }, + { + .opcode = BTP_MESH_CFG_MODEL_PUB_VA_SET, + .expect_len = sizeof(struct btp_mesh_cfg_model_pub_va_set_cmd), + .func = config_mod_pub_va_set, + }, + { + .opcode = BTP_MESH_CFG_MODEL_APP_BIND_VND, + .expect_len = sizeof(struct btp_mesh_cfg_model_app_bind_vnd_cmd), + .func = config_model_app_bind_vnd, + }, + { + .opcode = BTP_MESH_HEALTH_FAULT_GET, + .expect_len = sizeof(struct btp_mesh_health_fault_get_cmd), + .func = health_fault_get, + }, + { + .opcode = BTP_MESH_HEALTH_FAULT_CLEAR, + .expect_len = sizeof(struct btp_mesh_health_fault_clear_cmd), + .func = health_fault_clear, + }, + { + .opcode = BTP_MESH_HEALTH_FAULT_TEST, + .expect_len = sizeof(struct btp_mesh_health_fault_test_cmd), + .func = health_fault_test, + }, + { + .opcode = BTP_MESH_HEALTH_PERIOD_GET, + .expect_len = sizeof(struct btp_mesh_health_period_get_cmd), + .func = health_period_get, + }, + { + .opcode = BTP_MESH_HEALTH_PERIOD_SET, + .expect_len = sizeof(struct btp_mesh_health_period_set_cmd), + .func = health_period_set, + }, + { + .opcode = BTP_MESH_HEALTH_ATTENTION_GET, + .expect_len = sizeof(struct btp_mesh_health_attention_get_cmd), + .func = health_attention_get, + }, + { + .opcode = BTP_MESH_HEALTH_ATTENTION_SET, + .expect_len = sizeof(struct btp_mesh_health_attention_set_cmd), + .func = health_attention_set, + }, + { + .opcode = BTP_MESH_PROVISION_ADV, + .expect_len = sizeof(struct btp_mesh_provision_adv_cmd), + .func = provision_adv, + }, + { + .opcode = BTP_MESH_CFG_KRP_GET, + .expect_len = sizeof(struct btp_mesh_cfg_krp_get_cmd), + .func = config_krp_get, + }, + { + .opcode = BTP_MESH_CFG_KRP_SET, + .expect_len = sizeof(struct btp_mesh_cfg_krp_set_cmd), + .func = config_krp_set, + }, #if defined(CONFIG_BT_TESTING) - case BTP_MESH_LPN_SUBSCRIBE: - lpn_subscribe(data, len); - break; - case BTP_MESH_LPN_UNSUBSCRIBE: - lpn_unsubscribe(data, len); - break; - case BTP_MESH_RPL_CLEAR: - rpl_clear(data, len); - break; + { + .opcode = BTP_MESH_LPN_SUBSCRIBE, + .expect_len = sizeof(struct btp_mesh_lpn_subscribe_cmd), + .func = lpn_subscribe, + }, + { + .opcode = BTP_MESH_LPN_UNSUBSCRIBE, + .expect_len = sizeof(struct btp_mesh_lpn_unsubscribe_cmd), + .func = lpn_unsubscribe, + }, + { + .opcode = BTP_MESH_RPL_CLEAR, + .expect_len = 0, + .func = rpl_clear, + }, #endif /* CONFIG_BT_TESTING */ - case BTP_MESH_PROXY_IDENTITY: - proxy_identity_enable(data, len); - break; - default: - tester_rsp(BTP_SERVICE_ID_MESH, opcode, index, - BTP_STATUS_UNKNOWN_CMD); - break; - } -} + { + .opcode = BTP_MESH_PROXY_IDENTITY, + .expect_len = 0, + .func = proxy_identity_enable, + }, +}; void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const void *payload, size_t payload_len) @@ -2793,6 +3234,9 @@ uint8_t tester_init_mesh(void) bt_test_cb_register(&bt_test_cb); } + tester_register_command_handlers(BTP_SERVICE_ID_MESH, handlers, + ARRAY_SIZE(handlers)); + return BTP_STATUS_SUCCESS; } From 7363d37300fa221a062ed061c83afa8a03b91931 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 1 Mar 2023 22:13:04 +0100 Subject: [PATCH 0031/1906] bluetooth: tester: Convert PACS service to new BTP API This makes PACS service to use new BTP command handlers API. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp/bttester.h | 2 - tests/bluetooth/tester/src/btp_bap.c | 65 +++++++++++------------ 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/bttester.h b/tests/bluetooth/tester/src/btp/bttester.h index 7dec11d0892d..84d7337b29b7 100644 --- a/tests/bluetooth/tester/src/btp/bttester.h +++ b/tests/bluetooth/tester/src/btp/bttester.h @@ -73,5 +73,3 @@ void tester_init_core(void); uint8_t tester_init_bap(void); uint8_t tester_unregister_bap(void); -void tester_handle_pacs(uint8_t opcode, uint8_t index, uint8_t *data, - uint16_t len); diff --git a/tests/bluetooth/tester/src/btp_bap.c b/tests/bluetooth/tester/src/btp_bap.c index b68f331273db..83d8ea50bf53 100644 --- a/tests/bluetooth/tester/src/btp_bap.c +++ b/tests/bluetooth/tester/src/btp_bap.c @@ -108,26 +108,26 @@ static int set_supported_contexts(void) return 0; } -static void pacs_supported_commands(uint8_t *data, uint16_t len) +static uint8_t pacs_supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - uint8_t cmds[2]; - struct btp_pacs_read_supported_commands_rp *rp = (void *)cmds; + struct btp_pacs_read_supported_commands_rp *rp = rsp; - (void)memset(cmds, 0, sizeof(cmds)); + /* octet 0 */ + tester_set_bit(rp->data, BTP_PACS_READ_SUPPORTED_COMMANDS); - tester_set_bit(cmds, BTP_PACS_READ_SUPPORTED_COMMANDS); + *rsp_len = sizeof(*rp) + 1; - tester_send(BTP_SERVICE_ID_PACS, BTP_PACS_READ_SUPPORTED_COMMANDS, - CONTROLLER_INDEX, (uint8_t *)rp, sizeof(cmds)); + return BTP_STATUS_SUCCESS; } -static void pacs_update_characteristic(uint8_t *data, uint16_t len) +static uint8_t pacs_update_characteristic(uint8_t index, const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { - int err = 0; - uint8_t status = BTP_STATUS_SUCCESS; - const struct btp_pacs_update_characteristic_cmd *cmd = (void *)data; + const struct btp_pacs_update_characteristic_cmd *cp = cmd; + int err; - switch (cmd->characteristic) { + switch (cp->characteristic) { case BTP_PACS_CHARACTERISTIC_SINK_PAC: err = bt_pacs_cap_unregister(BT_AUDIO_DIR_SINK, &cap_sink); @@ -157,37 +157,31 @@ static void pacs_update_characteristic(uint8_t *data, uint16_t len) BT_AUDIO_CONTEXT_TYPE_INSTRUCTIONAL); break; default: - status = BTP_STATUS_UNKNOWN_CMD; + return BTP_STATUS_FAILED; } if (err != 0) { - status = BTP_STATUS_FAILED; + return BTP_STATUS_FAILED; } - tester_rsp(BTP_SERVICE_ID_PACS, BTP_PACS_UPDATE_CHARACTERISTIC, - CONTROLLER_INDEX, status); + return BTP_STATUS_SUCCESS; } -void tester_handle_pacs(uint8_t opcode, uint8_t index, uint8_t *data, - uint16_t len) -{ - switch (opcode) { - case BTP_PACS_READ_SUPPORTED_COMMANDS: - pacs_supported_commands(data, len); - break; - case BTP_PACS_UPDATE_CHARACTERISTIC: - pacs_update_characteristic(data, len); - break; - default: - tester_rsp(BTP_SERVICE_ID_PACS, opcode, index, - BTP_STATUS_UNKNOWN_CMD); - break; - } -} +static const struct btp_handler pacs_handlers[] = { + { + .opcode = BTP_PACS_READ_SUPPORTED_COMMANDS, + .expect_len = 0, + .func = pacs_supported_commands, + }, + { + .opcode = BTP_PACS_UPDATE_CHARACTERISTIC, + .expect_len = sizeof(struct btp_pacs_update_characteristic_cmd), + .func = pacs_update_characteristic, + }, +}; uint8_t tester_init_bap(void) { - uint8_t status = BTP_STATUS_SUCCESS; int err; bt_pacs_cap_register(BT_AUDIO_DIR_SINK, &cap_sink); @@ -208,7 +202,10 @@ uint8_t tester_init_bap(void) return BTP_STATUS_FAILED; } - return status; + tester_register_command_handlers(BTP_SERVICE_ID_PACS, pacs_handlers, + ARRAY_SIZE(pacs_handlers)); + + return BTP_STATUS_SUCCESS; } uint8_t tester_unregister_bap(void) From 1e2ca26a27f6b2544df2f15604bc708d238a6259 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 1 Mar 2023 16:09:48 +0100 Subject: [PATCH 0032/1906] bluetooth: tester: Unify BTP index handling We always have 0 index (and occasional NONE index) so there is no point in validating those in each handler. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp.c | 51 +-- tests/bluetooth/tester/src/btp/btp.h | 1 + tests/bluetooth/tester/src/btp/bttester.h | 8 +- tests/bluetooth/tester/src/btp_bap.c | 7 +- tests/bluetooth/tester/src/btp_core.c | 28 +- tests/bluetooth/tester/src/btp_gap.c | 182 +++------- tests/bluetooth/tester/src/btp_gatt.c | 229 +++---------- tests/bluetooth/tester/src/btp_ias.c | 8 +- tests/bluetooth/tester/src/btp_l2cap.c | 58 +--- tests/bluetooth/tester/src/btp_mesh.c | 396 +++++----------------- tests/bluetooth/tester/src/btp_vcp.c | 103 ++---- 11 files changed, 270 insertions(+), 801 deletions(-) diff --git a/tests/bluetooth/tester/src/btp.c b/tests/bluetooth/tester/src/btp.c index 360452107e38..d3e505fcde59 100644 --- a/tests/bluetooth/tester/src/btp.c +++ b/tests/bluetooth/tester/src/btp.c @@ -48,6 +48,10 @@ static struct { size_t num; } service_handler[BTP_SERVICE_ID_MAX + 1]; +static void tester_send_with_index(uint8_t service, uint8_t opcode, uint8_t index, + uint8_t *data, size_t len); +static void tester_rsp_with_index(uint8_t service, uint8_t opcode, uint8_t index, + uint8_t status); void tester_register_command_handlers(uint8_t service, const struct btp_handler *handlers, @@ -91,11 +95,13 @@ static void cmd_handler(void *p1, void *p2, void *p3) btp = find_btp_handler(cmd->hdr.service, cmd->hdr.opcode); if (btp) { - if ((btp->expect_len >= 0) && (btp->expect_len != len)) { + if (btp->index != cmd->hdr.index) { + status = BTP_STATUS_FAILED; + } else if ((btp->expect_len >= 0) && (btp->expect_len != len)) { status = BTP_STATUS_FAILED; } else { - status = btp->func(cmd->hdr.index, cmd->hdr.data, - len, cmd->rsp, &rsp_len); + status = btp->func(cmd->hdr.data, len, + cmd->rsp, &rsp_len); } __ASSERT_NO_MSG((rsp_len + sizeof(struct btp_hdr)) <= BTP_MTU); @@ -105,17 +111,11 @@ static void cmd_handler(void *p1, void *p2, void *p3) if (status != BTP_STATUS_DELAY_REPLY) { if ((status == BTP_STATUS_SUCCESS) && rsp_len > 0) { - tester_send(cmd->hdr.service, cmd->hdr.opcode, - cmd->hdr.index, cmd->rsp, rsp_len); + tester_send_with_index(cmd->hdr.service, cmd->hdr.opcode, + cmd->hdr.index, cmd->rsp, rsp_len); } else { -#if defined(CONFIG_BT_PACS) - case BTP_SERVICE_ID_PACS: - tester_handle_pacs(cmd->hdr.opcode, cmd->hdr.index, - cmd->hdr.data, len); - break; -#endif /* CONFIG_BT_PACS */ - tester_rsp(cmd->hdr.service, cmd->hdr.opcode, - cmd->hdr.index, status); + tester_rsp_with_index(cmd->hdr.service, cmd->hdr.opcode, + cmd->hdr.index, status); } } @@ -228,12 +228,12 @@ void tester_init(void) /* core service is always available */ tester_init_core(); - tester_send(BTP_SERVICE_ID_CORE, BTP_CORE_EV_IUT_READY, BTP_INDEX_NONE, - NULL, 0); + tester_send_with_index(BTP_SERVICE_ID_CORE, BTP_CORE_EV_IUT_READY, + BTP_INDEX_NONE, NULL, 0); } -void tester_send(uint8_t service, uint8_t opcode, uint8_t index, uint8_t *data, - size_t len) +static void tester_send_with_index(uint8_t service, uint8_t opcode, uint8_t index, + uint8_t *data, size_t len) { struct btp_hdr msg; @@ -248,15 +248,26 @@ void tester_send(uint8_t service, uint8_t opcode, uint8_t index, uint8_t *data, } } -void tester_rsp(uint8_t service, uint8_t opcode, uint8_t index, uint8_t status) +static void tester_rsp_with_index(uint8_t service, uint8_t opcode, uint8_t index, + uint8_t status) { struct btp_status s; if (status == BTP_STATUS_SUCCESS) { - tester_send(service, opcode, index, NULL, 0); + tester_send_with_index(service, opcode, index, NULL, 0); return; } s.code = status; - tester_send(service, BTP_STATUS, index, (uint8_t *) &s, sizeof(s)); + tester_send_with_index(service, BTP_STATUS, index, (uint8_t *) &s, sizeof(s)); +} + +void tester_send(uint8_t service, uint8_t opcode, uint8_t *data, size_t len) +{ + tester_send_with_index(service, opcode, BTP_INDEX, data, len); +} + +void tester_rsp(uint8_t service, uint8_t opcode, uint8_t status) +{ + tester_rsp_with_index(service, opcode, BTP_INDEX, status); } diff --git a/tests/bluetooth/tester/src/btp/btp.h b/tests/bluetooth/tester/src/btp/btp.h index 4fe47e85a4b7..270e419a2028 100644 --- a/tests/bluetooth/tester/src/btp/btp.h +++ b/tests/bluetooth/tester/src/btp/btp.h @@ -26,6 +26,7 @@ #define BTP_DATA_MAX_SIZE (BTP_MTU - sizeof(struct btp_hdr)) #define BTP_INDEX_NONE 0xff +#define BTP_INDEX 0x00 #define BTP_SERVICE_ID_CORE 0 #define BTP_SERVICE_ID_GAP 1 diff --git a/tests/bluetooth/tester/src/btp/bttester.h b/tests/bluetooth/tester/src/btp/bttester.h index 84d7337b29b7..edbd21cedce1 100644 --- a/tests/bluetooth/tester/src/btp/bttester.h +++ b/tests/bluetooth/tester/src/btp/bttester.h @@ -27,14 +27,14 @@ static inline uint8_t tester_test_bit(const uint8_t *addr, unsigned int bit) } void tester_init(void); -void tester_rsp(uint8_t service, uint8_t opcode, uint8_t index, uint8_t status); -void tester_send(uint8_t service, uint8_t opcode, uint8_t index, uint8_t *data, - size_t len); +void tester_rsp(uint8_t service, uint8_t opcode, uint8_t status); +void tester_send(uint8_t service, uint8_t opcode, uint8_t *data, size_t len); struct btp_handler { uint8_t opcode; + uint8_t index; ssize_t expect_len; - uint8_t (*func)(uint8_t index, const void *cmd, uint16_t cmd_len, + uint8_t (*func)(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len); }; diff --git a/tests/bluetooth/tester/src/btp_bap.c b/tests/bluetooth/tester/src/btp_bap.c index 83d8ea50bf53..b9dee9dad5e9 100644 --- a/tests/bluetooth/tester/src/btp_bap.c +++ b/tests/bluetooth/tester/src/btp_bap.c @@ -19,8 +19,6 @@ #include "bap_endpoint.h" #include "btp/btp.h" -#define CONTROLLER_INDEX 0 - #define SUPPORTED_SINK_CONTEXT (BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | \ BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | \ BT_AUDIO_CONTEXT_TYPE_MEDIA | \ @@ -108,7 +106,7 @@ static int set_supported_contexts(void) return 0; } -static uint8_t pacs_supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t pacs_supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_pacs_read_supported_commands_rp *rp = rsp; @@ -121,7 +119,7 @@ static uint8_t pacs_supported_commands(uint8_t index, const void *cmd, uint16_t return BTP_STATUS_SUCCESS; } -static uint8_t pacs_update_characteristic(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t pacs_update_characteristic(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_pacs_update_characteristic_cmd *cp = cmd; @@ -170,6 +168,7 @@ static uint8_t pacs_update_characteristic(uint8_t index, const void *cmd, uint16 static const struct btp_handler pacs_handlers[] = { { .opcode = BTP_PACS_READ_SUPPORTED_COMMANDS, + .index = BTP_INDEX_NONE, .expect_len = 0, .func = pacs_supported_commands, }, diff --git a/tests/bluetooth/tester/src/btp_core.c b/tests/bluetooth/tester/src/btp_core.c index 9ff9c563f61e..4e1eca7f26bd 100644 --- a/tests/bluetooth/tester/src/btp_core.c +++ b/tests/bluetooth/tester/src/btp_core.c @@ -30,15 +30,11 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); static ATOMIC_DEFINE(registered_services, BTP_SERVICE_ID_MAX); -static uint8_t supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_core_read_supported_commands_rp *rp = rsp; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - tester_set_bit(rp->data, BTP_CORE_READ_SUPPORTED_COMMANDS); tester_set_bit(rp->data, BTP_CORE_READ_SUPPORTED_SERVICES); tester_set_bit(rp->data, BTP_CORE_REGISTER_SERVICE); @@ -49,15 +45,11 @@ static uint8_t supported_commands(uint8_t index, const void *cmd, uint16_t cmd_l return BTP_STATUS_SUCCESS; } -static uint8_t supported_services(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t supported_services(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_core_read_supported_services_rp *rp = rsp; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - /* octet 0 */ tester_set_bit(rp->data, BTP_SERVICE_ID_CORE); tester_set_bit(rp->data, BTP_SERVICE_ID_GAP); @@ -88,16 +80,12 @@ static uint8_t supported_services(uint8_t index, const void *cmd, uint16_t cmd_l return BTP_STATUS_SUCCESS; } -static uint8_t register_service(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t register_service(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_core_register_service_cmd *cp = cmd; uint8_t status; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - /* invalid service */ if ((cp->id == BTP_SERVICE_ID_CORE) || (cp->id > BTP_SERVICE_ID_MAX)) { return BTP_STATUS_FAILED; @@ -159,16 +147,12 @@ static uint8_t register_service(uint8_t index, const void *cmd, uint16_t cmd_len return status; } -static uint8_t unregister_service(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t unregister_service(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_core_unregister_service_cmd *cp = cmd; uint8_t status; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - /* invalid service ID */ if ((cp->id == BTP_SERVICE_ID_CORE) || (cp->id > BTP_SERVICE_ID_MAX)) { return BTP_STATUS_FAILED; @@ -233,21 +217,25 @@ static uint8_t unregister_service(uint8_t index, const void *cmd, uint16_t cmd_l static const struct btp_handler handlers[] = { { .opcode = BTP_CORE_READ_SUPPORTED_COMMANDS, + .index = BTP_INDEX_NONE, .expect_len = 0, .func = supported_commands, }, { .opcode = BTP_CORE_READ_SUPPORTED_SERVICES, + .index = BTP_INDEX_NONE, .expect_len = 0, .func = supported_services, }, { .opcode = BTP_CORE_REGISTER_SERVICE, + .index = BTP_INDEX_NONE, .expect_len = sizeof(struct btp_core_register_service_cmd), .func = register_service, }, { .opcode = BTP_CORE_UNREGISTER_SERVICE, + .index = BTP_INDEX_NONE, .expect_len = sizeof(struct btp_core_unregister_service_cmd), .func = unregister_service, }, diff --git a/tests/bluetooth/tester/src/btp_gap.c b/tests/bluetooth/tester/src/btp_gap.c index 3e1696b7b386..4cd7631c30cd 100644 --- a/tests/bluetooth/tester/src/btp_gap.c +++ b/tests/bluetooth/tester/src/btp_gap.c @@ -27,7 +27,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "btp/btp.h" -#define CONTROLLER_INDEX 0 #define CONTROLLER_NAME "btp_tester" #define BT_LE_AD_DISCOV_MASK (BT_LE_AD_LIMITED | BT_LE_AD_GENERAL) @@ -111,7 +110,7 @@ static void le_connected(struct bt_conn *conn, uint8_t err) ev.timeout = sys_cpu_to_le16(info.le.timeout); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_CONNECTED, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } static void le_disconnected(struct bt_conn *conn, uint8_t reason) @@ -122,7 +121,7 @@ static void le_disconnected(struct bt_conn *conn, uint8_t reason) bt_addr_le_copy(&ev.address, addr); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_DISCONNECTED, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } static void le_identity_resolved(struct bt_conn *conn, const bt_addr_le_t *rpa, @@ -134,7 +133,7 @@ static void le_identity_resolved(struct bt_conn *conn, const bt_addr_le_t *rpa, bt_addr_le_copy(&ev.identity_address, identity); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_IDENTITY_RESOLVED, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } static void le_param_updated(struct bt_conn *conn, uint16_t interval, @@ -149,7 +148,7 @@ static void le_param_updated(struct bt_conn *conn, uint16_t interval, ev.timeout = sys_cpu_to_le16(timeout); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_CONN_PARAM_UPDATE, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param) @@ -180,7 +179,7 @@ static void le_security_changed(struct bt_conn *conn, bt_security_t level, sec_ev.sec_level = level; tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_SEC_LEVEL_CHANGED, - CONTROLLER_INDEX, (uint8_t *) &sec_ev, sizeof(sec_ev)); + (uint8_t *) &sec_ev, sizeof(sec_ev)); break; case BT_SECURITY_ERR_PIN_OR_KEY_MISSING: /* for central role this means that peer have no LTK when we @@ -195,7 +194,7 @@ static void le_security_changed(struct bt_conn *conn, bt_security_t level, bt_addr_le_copy(&bond_ev.address, addr); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_BOND_LOST, - CONTROLLER_INDEX, (uint8_t *)&bond_ev, sizeof(bond_ev)); + (uint8_t *)&bond_ev, sizeof(bond_ev)); (void)bt_conn_set_security(conn, BT_SECURITY_L2 | BT_SECURITY_FORCE_PAIR); } @@ -214,15 +213,11 @@ static struct bt_conn_cb conn_callbacks = { .security_changed = le_security_changed, }; -static uint8_t supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_gap_read_supported_commands_rp *rp = rsp; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - /* octet 0 */ tester_set_bit(rp->data, BTP_GAP_READ_SUPPORTED_COMMANDS); tester_set_bit(rp->data, BTP_GAP_READ_CONTROLLER_INDEX_LIST); @@ -261,34 +256,26 @@ static uint8_t supported_commands(uint8_t index, const void *cmd, uint16_t cmd_l return BTP_STATUS_SUCCESS; } -static uint8_t controller_index_list(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t controller_index_list(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_gap_read_controller_index_list_rp *rp = rsp; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - rp->num = 1U; - rp->index[0] = CONTROLLER_INDEX; + rp->index[0] = BTP_INDEX; *rsp_len = sizeof(*rp) + 1; return BTP_STATUS_SUCCESS; } -static uint8_t controller_info(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t controller_info(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_gap_read_controller_info_rp *rp = rsp; uint32_t supported_settings; struct bt_le_oob oob_local = { 0 }; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - bt_le_oob_get_local(BT_ID_DEFAULT, &oob_local); bt_addr_copy(&rp->address, &oob_local.addr.a); @@ -418,15 +405,11 @@ static void oob_data_request(struct bt_conn *conn, } #if !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) -static uint8_t get_oob_sc_local_data(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t get_oob_sc_local_data(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_gap_oob_sc_get_local_data_rp *rp = rsp; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - cb.oob_data_request = oob_data_request; memcpy(rp->conf, &oob_sc_local.le_sc_data.c[0], sizeof(rp->conf)); @@ -436,15 +419,11 @@ static uint8_t get_oob_sc_local_data(uint8_t index, const void *cmd, uint16_t cm return BTP_STATUS_SUCCESS; } -static uint8_t set_oob_sc_remote_data(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t set_oob_sc_remote_data(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_oob_sc_set_remote_data_cmd *cp = cmd; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - cb.oob_data_request = oob_data_request; bt_set_oob_data_flag(true); @@ -460,16 +439,12 @@ static uint8_t set_oob_sc_remote_data(uint8_t index, const void *cmd, uint16_t c } #endif /* !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) */ -static uint8_t set_connectable(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t set_connectable(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_set_connectable_cmd *cp = cmd; struct btp_gap_set_connectable_rp *rp = rsp; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if (cp->connectable) { atomic_set_bit(¤t_settings, BTP_GAP_SETTINGS_CONNECTABLE); } else { @@ -489,16 +464,12 @@ static struct bt_data ad[10] = { }; static struct bt_data sd[10]; -static uint8_t set_discoverable(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t set_discoverable(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_set_discoverable_cmd *cp = cmd; struct btp_gap_set_discoverable_rp *rp = rsp; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - switch (cp->discoverable) { case BTP_GAP_NON_DISCOVERABLE: ad_flags &= ~(BT_LE_AD_GENERAL | BT_LE_AD_LIMITED); @@ -524,16 +495,12 @@ static uint8_t set_discoverable(uint8_t index, const void *cmd, uint16_t cmd_len return BTP_STATUS_SUCCESS; } -static uint8_t set_bondable(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t set_bondable(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_set_bondable_cmd *cp = cmd; struct btp_gap_set_bondable_rp *rp = rsp; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - LOG_DBG("bondable: %d", cp->bondable); if (cp->bondable) { @@ -549,7 +516,7 @@ static uint8_t set_bondable(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t start_advertising(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t start_advertising(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_start_advertising_cmd *cp = cmd; @@ -564,10 +531,6 @@ static uint8_t start_advertising(uint8_t index, const void *cmd, uint16_t cmd_le uint8_t sd_len; int i; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - /* This command is very unfortunate since after variable data there is * additional 5 bytes (4 bytes for duration, 1 byte for own address * type. @@ -646,7 +609,7 @@ static uint8_t start_advertising(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t start_directed_advertising(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t start_directed_advertising(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_start_directed_adv_cmd *cp = cmd; @@ -654,10 +617,6 @@ static uint8_t start_directed_advertising(uint8_t index, const void *cmd, uint16 struct bt_le_adv_param adv_param; uint16_t options = sys_le16_to_cpu(cp->options); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - adv_param = *BT_LE_ADV_CONN_DIR(&cp->address); if (!(options & BTP_GAP_START_DIRECTED_ADV_HD)) { @@ -691,20 +650,15 @@ static uint8_t start_directed_advertising(uint8_t index, const void *cmd, uint16 return BTP_STATUS_SUCCESS; } -static uint8_t stop_advertising(uint8_t index, const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) +static uint8_t stop_advertising(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { struct btp_gap_stop_advertising_rp *rp = rsp; int err; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_le_adv_stop(); if (err < 0) { - tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_STOP_ADVERTISING, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_GAP, BTP_GAP_STOP_ADVERTISING, BTP_STATUS_FAILED); LOG_ERR("Failed to stop advertising: %d", err); return BTP_STATUS_FAILED; } @@ -824,7 +778,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t evtype, */ if (adv_buf->len) { tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_FOUND, - CONTROLLER_INDEX, adv_buf->data, adv_buf->len); + adv_buf->data, adv_buf->len); net_buf_simple_reset(adv_buf); } @@ -839,19 +793,15 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t evtype, } done: tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_FOUND, - CONTROLLER_INDEX, adv_buf->data, adv_buf->len); + adv_buf->data, adv_buf->len); net_buf_simple_reset(adv_buf); } -static uint8_t start_discovery(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t start_discovery(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_start_discovery_cmd *cp = cmd; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - /* only LE scan is supported */ if (cp->flags & BTP_GAP_DISCOVERY_FLAG_BREDR) { LOG_WRN("BR/EDR not supported"); @@ -871,15 +821,11 @@ static uint8_t start_discovery(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t stop_discovery(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t stop_discovery(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { int err; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_le_scan_stop(); if (err < 0) { LOG_ERR("Failed to stop scanning: %d", err); @@ -889,16 +835,12 @@ static uint8_t stop_discovery(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t connect(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t connect(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_connect_cmd *cp = cmd; int err; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if (!bt_addr_le_eq(&cp->address, BT_ADDR_LE_ANY)) { struct bt_conn *conn; @@ -922,17 +864,13 @@ static uint8_t connect(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t disconnect(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t disconnect(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_disconnect_cmd *cp = cmd; struct bt_conn *conn; uint8_t status; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { LOG_ERR("Unknown connection"); @@ -960,7 +898,7 @@ static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) ev.passkey = sys_cpu_to_le32(passkey); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_DISPLAY, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } static void auth_passkey_entry(struct bt_conn *conn) @@ -971,7 +909,7 @@ static void auth_passkey_entry(struct bt_conn *conn) bt_addr_le_copy(&ev.address, addr); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_ENTRY_REQ, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey) @@ -983,7 +921,7 @@ static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey) ev.passkey = sys_cpu_to_le32(passkey); tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_CONFIRM_REQ, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } static void auth_cancel(struct bt_conn *conn) @@ -1008,7 +946,7 @@ enum bt_security_err auth_pairing_accept(struct bt_conn *conn, bt_addr_le_copy(&ev.address, addr); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_BOND_LOST, CONTROLLER_INDEX, (uint8_t *)&ev, + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_BOND_LOST, (uint8_t *)&ev, sizeof(ev)); return BT_SECURITY_ERR_SUCCESS; @@ -1022,8 +960,8 @@ void auth_pairing_failed(struct bt_conn *conn, enum bt_security_err reason) bt_addr_le_copy(&ev.address, addr); ev.reason = reason; - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PAIRING_FAILED, CONTROLLER_INDEX, - (uint8_t *)&ev, sizeof(ev)); + tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PAIRING_FAILED, + (uint8_t *)&ev, sizeof(ev)); } static void auth_pairing_complete(struct bt_conn *conn, bool bonded) @@ -1041,15 +979,11 @@ static struct bt_conn_auth_info_cb auth_info_cb = { .pairing_complete = auth_pairing_complete, }; -static uint8_t set_io_cap(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t set_io_cap(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_set_io_cap_cmd *cp = cmd; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - /* Reset io cap requirements */ (void)memset(&cb, 0, sizeof(cb)); bt_conn_auth_cb_register(NULL); @@ -1093,17 +1027,13 @@ static uint8_t set_io_cap(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t pair(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t pair(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_pair_cmd *cp = cmd; struct bt_conn *conn; int err; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { LOG_ERR("Unknown connection"); @@ -1121,17 +1051,13 @@ static uint8_t pair(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t unpair(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t unpair(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_unpair_cmd *cp = cmd; struct bt_conn *conn; int err; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { LOG_INF("Unknown connection"); @@ -1155,17 +1081,13 @@ static uint8_t unpair(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t passkey_entry(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t passkey_entry(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_passkey_entry_cmd *cp = cmd; struct bt_conn *conn; int err; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { LOG_ERR("Unknown connection"); @@ -1183,17 +1105,13 @@ static uint8_t passkey_entry(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t passkey_confirm(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t passkey_confirm(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_passkey_confirm_cmd *cp = cmd; struct bt_conn *conn; int err; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { LOG_ERR("Unknown connection"); @@ -1221,7 +1139,7 @@ static uint8_t passkey_confirm(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t conn_param_update(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t conn_param_update(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_conn_param_update_cmd *cp = cmd; @@ -1234,10 +1152,6 @@ static uint8_t conn_param_update(uint8_t index, const void *cmd, uint16_t cmd_le struct bt_conn *conn; int err; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { LOG_ERR("Unknown connection"); @@ -1254,28 +1168,20 @@ static uint8_t conn_param_update(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t set_mitm(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t set_mitm(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { /* TODO verify if can be done in runtime */ LOG_WRN("Use CONFIG_BT_SMP_ENFORCE_MITM instead"); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - return BTP_STATUS_SUCCESS; } -static uint8_t set_oob_legacy_data(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t set_oob_legacy_data(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_oob_legacy_set_data_cmd *cp = cmd; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - memcpy(oob_legacy_tk, cp->oob_data, 16); bt_set_oob_data_flag(true); @@ -1284,7 +1190,7 @@ static uint8_t set_oob_legacy_data(uint8_t index, const void *cmd, uint16_t cmd_ return BTP_STATUS_SUCCESS; } -static uint8_t set_filter_list(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t set_filter_list(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gap_set_filter_list *cp = cmd; @@ -1295,10 +1201,6 @@ static uint8_t set_filter_list(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - (void)bt_le_filter_accept_list_clear(); for (int i = 0; i < cp->cnt; i++) { @@ -1314,11 +1216,13 @@ static uint8_t set_filter_list(uint8_t index, const void *cmd, uint16_t cmd_len, static const struct btp_handler handlers[] = { { .opcode = BTP_GAP_READ_SUPPORTED_COMMANDS, + .index = BTP_INDEX_NONE, .expect_len = 0, .func = supported_commands, }, { .opcode = BTP_GAP_READ_CONTROLLER_INDEX_LIST, + .index = BTP_INDEX_NONE, .expect_len = 0, .func = controller_index_list, }, diff --git a/tests/bluetooth/tester/src/btp_gatt.c b/tests/bluetooth/tester/src/btp_gatt.c index f6e6ed99a854..910cd25337ab 100644 --- a/tests/bluetooth/tester/src/btp_gatt.c +++ b/tests/bluetooth/tester/src/btp_gatt.c @@ -29,7 +29,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "btp/btp.h" -#define CONTROLLER_INDEX 0 #define MAX_BUFFER_SIZE 2048 #define MAX_UUID_LEN 16 @@ -218,15 +217,11 @@ static uint8_t btp2bt_uuid(const uint8_t *uuid, uint8_t len, return BTP_STATUS_SUCCESS; } -static uint8_t supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_gatt_read_supported_commands_rp *rp = rsp; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - /* octet 0 */ tester_set_bit(rp->data, BTP_GATT_READ_SUPPORTED_COMMANDS); tester_set_bit(rp->data, BTP_GATT_ADD_SERVICE); @@ -289,7 +284,7 @@ static int register_service(void) return err; } -static uint8_t add_service(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t add_service(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_add_service_cmd *cp = cmd; @@ -298,10 +293,6 @@ static uint8_t add_service(uint8_t index, const void *cmd, uint16_t cmd_len, union uuid uuid; size_t uuid_size; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if ((cmd_len < sizeof(*cp)) || (cmd_len != sizeof(*cp) + cp->uuid_length)) { return BTP_STATUS_FAILED; @@ -388,7 +379,7 @@ static void attr_value_changed_ev(uint16_t handle, const uint8_t *value, uint16_ memcpy(ev->data, value, len); tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_EV_ATTR_VALUE_CHANGED, - CONTROLLER_INDEX, buf, sizeof(buf)); + buf, sizeof(buf)); } static ssize_t write_value(struct bt_conn *conn, @@ -497,7 +488,7 @@ static int alloc_characteristic(struct add_characteristic *ch) return 0; } -static uint8_t add_characteristic(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t add_characteristic(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_add_characteristic_cmd *cp = cmd; @@ -505,10 +496,6 @@ static uint8_t add_characteristic(uint8_t index, const void *cmd, uint16_t cmd_l struct add_characteristic cmd_data; union uuid uuid; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if ((cmd_len < sizeof(*cp)) || (cmd_len != sizeof(*cp) + cp->uuid_length)) { return BTP_STATUS_FAILED; @@ -690,7 +677,7 @@ static struct bt_gatt_attr *get_base_chrc(struct bt_gatt_attr *attr) return NULL; } -static uint8_t add_descriptor(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t add_descriptor(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_add_descriptor_cmd *cp = cmd; @@ -699,10 +686,6 @@ static uint8_t add_descriptor(uint8_t index, const void *cmd, uint16_t cmd_len, struct bt_gatt_attr *chrc; union uuid uuid; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if ((cmd_len < sizeof(*cp)) || (cmd_len != sizeof(*cp) + cp->uuid_length)) { return BTP_STATUS_FAILED; @@ -765,7 +748,7 @@ static int alloc_included(struct bt_gatt_attr *attr, return 0; } -static uint8_t add_included(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t add_included(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_add_included_service_cmd *cp = cmd; @@ -774,10 +757,6 @@ static uint8_t add_included(uint8_t index, const void *cmd, uint16_t cmd_len, uint16_t svc_id; uint16_t included_service_id = 0U; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if (!svc_count) { return BTP_STATUS_FAILED; } @@ -897,7 +876,7 @@ static uint8_t alloc_value(struct bt_gatt_attr *attr, struct set_value *data) return BTP_STATUS_SUCCESS; } -static uint8_t set_value(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t set_value(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_set_value_cmd *cp = cmd; @@ -905,10 +884,6 @@ static uint8_t set_value(uint8_t index, const void *cmd, uint16_t cmd_len, uint16_t attr_id; uint8_t status; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if ((cmd_len < sizeof(*cp)) || (cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->len))) { return BTP_STATUS_FAILED; @@ -934,15 +909,11 @@ static uint8_t set_value(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t start_server(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t start_server(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_gatt_start_server_rp *rp = rsp; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - /* Register last defined service */ if (svc_attr_count) { if (register_service()) { @@ -981,17 +952,13 @@ static int set_attr_enc_key_size(const struct bt_gatt_attr *attr, return 0; } -static uint8_t set_enc_key_size(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t set_enc_key_size(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_set_enc_key_size_cmd *cp = cmd; uint16_t attr_id; int ret; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - /* Fail if requested key size is invalid */ if (cp->key_size < 0x07 || cp->key_size > 0x0f) { return BTP_STATUS_FAILED; @@ -1026,16 +993,12 @@ static void exchange_func(struct bt_conn *conn, uint8_t err, static struct bt_gatt_exchange_params exchange_params; -static uint8_t exchange_mtu(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t exchange_mtu(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_exchange_mtu_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { return BTP_STATUS_FAILED; @@ -1077,7 +1040,7 @@ static uint8_t disc_prim_cb(struct bt_conn *conn, if (!attr) { tester_send(BTP_SERVICE_ID_GATT, btp_opcode, - CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len); + gatt_buf.buf, gatt_buf.len); discover_destroy(params); return BT_GATT_ITER_STOP; } @@ -1088,8 +1051,7 @@ static uint8_t disc_prim_cb(struct bt_conn *conn, service = gatt_buf_reserve(sizeof(*service) + uuid_length); if (!service) { - tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode, BTP_STATUS_FAILED); discover_destroy(params); return BT_GATT_ITER_STOP; } @@ -1112,16 +1074,12 @@ static uint8_t disc_prim_cb(struct bt_conn *conn, return BT_GATT_ITER_CONTINUE; } -static uint8_t disc_all_prim(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t disc_all_prim(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_disc_all_prim_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { return BTP_STATUS_FAILED; @@ -1152,16 +1110,12 @@ static uint8_t disc_all_prim(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_DELAY_REPLY; } -static uint8_t disc_prim_uuid(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t disc_prim_uuid(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_disc_prim_uuid_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if ((cmd_len < sizeof(*cp)) || (cmd_len != sizeof(*cp) + cp->uuid_length)) { return BTP_STATUS_FAILED; @@ -1213,7 +1167,7 @@ static uint8_t find_included_cb(struct bt_conn *conn, if (!attr) { tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_FIND_INCLUDED, - CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len); + gatt_buf.buf, gatt_buf.len); discover_destroy(params); return BT_GATT_ITER_STOP; } @@ -1224,8 +1178,7 @@ static uint8_t find_included_cb(struct bt_conn *conn, included = gatt_buf_reserve(sizeof(*included) + uuid_length); if (!included) { - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_FIND_INCLUDED, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_FIND_INCLUDED, BTP_STATUS_FAILED); discover_destroy(params); return BT_GATT_ITER_STOP; } @@ -1249,16 +1202,12 @@ static uint8_t find_included_cb(struct bt_conn *conn, return BT_GATT_ITER_CONTINUE; } -static uint8_t find_included(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t find_included(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_find_included_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { return BTP_STATUS_FAILED; @@ -1297,7 +1246,7 @@ static uint8_t disc_chrc_cb(struct bt_conn *conn, if (!attr) { tester_send(BTP_SERVICE_ID_GATT, btp_opcode, - CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len); + gatt_buf.buf, gatt_buf.len); discover_destroy(params); return BT_GATT_ITER_STOP; } @@ -1308,8 +1257,7 @@ static uint8_t disc_chrc_cb(struct bt_conn *conn, chrc = gatt_buf_reserve(sizeof(*chrc) + uuid_length); if (!chrc) { - tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode, BTP_STATUS_FAILED); discover_destroy(params); return BT_GATT_ITER_STOP; } @@ -1332,16 +1280,12 @@ static uint8_t disc_chrc_cb(struct bt_conn *conn, return BT_GATT_ITER_CONTINUE; } -static uint8_t disc_all_chrc(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t disc_all_chrc(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_disc_all_chrc_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { return BTP_STATUS_FAILED; @@ -1372,16 +1316,12 @@ static uint8_t disc_all_chrc(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_DELAY_REPLY; } -static uint8_t disc_chrc_uuid(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t disc_chrc_uuid(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_disc_chrc_uuid_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if ((cmd_len < sizeof(*cp)) || (cmd_len != sizeof(*cp) + cp->uuid_length)) { return BTP_STATUS_FAILED; @@ -1433,7 +1373,7 @@ static uint8_t disc_all_desc_cb(struct bt_conn *conn, if (!attr) { tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_DESC, - CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len); + gatt_buf.buf, gatt_buf.len); discover_destroy(params); return BT_GATT_ITER_STOP; } @@ -1442,8 +1382,7 @@ static uint8_t disc_all_desc_cb(struct bt_conn *conn, descriptor = gatt_buf_reserve(sizeof(*descriptor) + uuid_length); if (!descriptor) { - tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_DESC, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_DESC, BTP_STATUS_FAILED); discover_destroy(params); return BT_GATT_ITER_STOP; } @@ -1465,16 +1404,12 @@ static uint8_t disc_all_desc_cb(struct bt_conn *conn, return BT_GATT_ITER_CONTINUE; } -static uint8_t disc_all_desc(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t disc_all_desc(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_disc_all_desc_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { return BTP_STATUS_FAILED; @@ -1523,15 +1458,14 @@ static uint8_t read_cb(struct bt_conn *conn, uint8_t err, /* read complete */ if (!data) { - tester_send(BTP_SERVICE_ID_GATT, btp_opcode, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_GATT, btp_opcode, gatt_buf.buf, gatt_buf.len); read_destroy(params); return BT_GATT_ITER_STOP; } if (!gatt_buf_add(data, length)) { - tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode, BTP_STATUS_FAILED); read_destroy(params); return BT_GATT_ITER_STOP; } @@ -1555,7 +1489,7 @@ static uint8_t read_uuid_cb(struct bt_conn *conn, uint8_t err, /* read complete */ if (!data) { - tester_send(BTP_SERVICE_ID_GATT, btp_opcode, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_GATT, btp_opcode, gatt_buf.buf, gatt_buf.len); read_destroy(params); @@ -1566,16 +1500,14 @@ static uint8_t read_uuid_cb(struct bt_conn *conn, uint8_t err, value.data_len = length; if (!gatt_buf_add(&value, sizeof(struct btp_gatt_char_value))) { - tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode, BTP_STATUS_FAILED); read_destroy(params); return BT_GATT_ITER_STOP; } if (!gatt_buf_add(data, length)) { - tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode, - CONTROLLER_INDEX, BTP_STATUS_FAILED); + tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode, BTP_STATUS_FAILED); read_destroy(params); return BT_GATT_ITER_STOP; @@ -1586,16 +1518,12 @@ static uint8_t read_uuid_cb(struct bt_conn *conn, uint8_t err, return BT_GATT_ITER_CONTINUE; } -static uint8_t read_data(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t read_data(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_read_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { return BTP_STATUS_FAILED; @@ -1626,16 +1554,12 @@ static uint8_t read_data(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_DELAY_REPLY; } -static uint8_t read_uuid(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t read_uuid(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_read_uuid_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if ((cmd_len < sizeof(*cp)) || (cmd_len != sizeof(*cp) + cp->uuid_length)) { return BTP_STATUS_FAILED; @@ -1676,16 +1600,12 @@ static uint8_t read_uuid(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_DELAY_REPLY; } -static uint8_t read_long(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t read_long(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_read_long_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { return BTP_STATUS_FAILED; @@ -1716,7 +1636,7 @@ static uint8_t read_long(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_DELAY_REPLY; } -static uint8_t read_multiple(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t read_multiple(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_read_multiple_cmd *cp = cmd; @@ -1724,10 +1644,6 @@ static uint8_t read_multiple(uint8_t index, const void *cmd, uint16_t cmd_len, struct bt_conn *conn; int i; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if ((cmd_len < sizeof(*cp)) || (cmd_len != sizeof(*cp) + (cp->handles_count * sizeof(cp->handles[0])))) { return BTP_STATUS_FAILED; @@ -1771,7 +1687,7 @@ static uint8_t read_multiple(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_DELAY_REPLY; } -static uint8_t read_multiple_var(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t read_multiple_var(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_read_multiple_var_cmd *cp = cmd; @@ -1779,10 +1695,6 @@ static uint8_t read_multiple_var(uint8_t index, const void *cmd, uint16_t cmd_le struct bt_conn *conn; int i; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if ((cmd_len < sizeof(*cp)) || (cmd_len != sizeof(*cp) + (cp->handles_count * sizeof(cp->handles[0])))) { return BTP_STATUS_FAILED; @@ -1826,16 +1738,12 @@ static uint8_t read_multiple_var(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_DELAY_REPLY; } -static uint8_t write_without_rsp(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t write_without_rsp(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_write_without_rsp_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if (cmd_len < sizeof(*cp) || cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_length)) { return BTP_STATUS_FAILED; @@ -1858,16 +1766,12 @@ static uint8_t write_without_rsp(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t write_signed_without_rsp(uint8_t index, const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) +static uint8_t write_signed_without_rsp(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { const struct btp_gatt_signed_write_without_rsp_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if (cmd_len < sizeof(*cp) || cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_length)) { return BTP_STATUS_FAILED; @@ -1893,22 +1797,17 @@ static uint8_t write_signed_without_rsp(uint8_t index, const void *cmd, uint16_t static void write_rsp(struct bt_conn *conn, uint8_t err, struct bt_gatt_write_params *params) { - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE, CONTROLLER_INDEX, &err, - sizeof(err)); + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE, &err, sizeof(err)); } static struct bt_gatt_write_params write_params; -static uint8_t write_data(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t write_data(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_write_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if (cmd_len < sizeof(*cp) || cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_length)) { return BTP_STATUS_FAILED; @@ -1938,20 +1837,15 @@ static uint8_t write_data(uint8_t index, const void *cmd, uint16_t cmd_len, static void write_long_rsp(struct bt_conn *conn, uint8_t err, struct bt_gatt_write_params *params) { - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE_LONG, CONTROLLER_INDEX, - &err, sizeof(err)); + tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE_LONG, &err, sizeof(err)); } -static uint8_t write_long(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t write_long(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_write_long_cmd *cp = cmd; struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if (cmd_len < sizeof(*cp) || cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_length)) { return BTP_STATUS_FAILED; @@ -2017,7 +1911,7 @@ static uint8_t notify_func(struct bt_conn *conn, bt_addr_le_copy(&ev->address, bt_conn_get_dst(conn)); tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_EV_NOTIFICATION, - CONTROLLER_INDEX, ev_buf, sizeof(*ev) + length); + ev_buf, sizeof(*ev) + length); return BT_GATT_ITER_CONTINUE; } @@ -2052,7 +1946,7 @@ static void discover_complete(struct bt_conn *conn, (void)memset(subscription, 0, sizeof(*subscription)); } - tester_rsp(BTP_SERVICE_ID_GATT, op, CONTROLLER_INDEX, status); + tester_rsp(BTP_SERVICE_ID_GATT, op, status); (void)memset(params, 0, sizeof(*params)); } @@ -2134,7 +2028,7 @@ static int disable_subscription(struct bt_conn *conn, uint16_t ccc_handle) return 0; } -static uint8_t config_subscription_notif(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_subscription_notif(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_cfg_notify_cmd *cp = cmd; @@ -2142,10 +2036,6 @@ static uint8_t config_subscription_notif(uint8_t index, const void *cmd, uint16_ uint16_t ccc_handle = sys_le16_to_cpu(cp->ccc_handle); uint8_t status; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { return BTP_STATUS_FAILED; @@ -2173,7 +2063,7 @@ static uint8_t config_subscription_notif(uint8_t index, const void *cmd, uint16_ return status; } -static uint8_t config_subscription_ind(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_subscription_ind(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_cfg_notify_cmd *cp = cmd; @@ -2181,10 +2071,6 @@ static uint8_t config_subscription_ind(uint8_t index, const void *cmd, uint16_t uint16_t ccc_handle = sys_le16_to_cpu(cp->ccc_handle); uint8_t status; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { return BTP_STATUS_FAILED; @@ -2218,7 +2104,7 @@ static void notify_cb(struct bt_conn *conn, void *user_data) LOG_DBG("Nofication sent"); } -static uint8_t notify_mult(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t notify_mult(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_cfg_notify_mult_cmd *cp = cmd; @@ -2229,10 +2115,6 @@ static uint8_t notify_mult(uint8_t index, const void *cmd, uint16_t cmd_len, int err = 0; uint16_t attr_data_len = 0; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if ((cmd_len < sizeof(*cp)) || (cmd_len != sizeof(*cp) + (cp->cnt * sizeof(cp->attr_id[0])))) { return BTP_STATUS_FAILED; @@ -2315,7 +2197,7 @@ static uint8_t get_attrs_rp(const struct bt_gatt_attr *attr, uint16_t handle, return BT_GATT_ITER_CONTINUE; } -static uint8_t get_attrs(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t get_attrs(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_get_attributes_cmd *cp = cmd; @@ -2325,10 +2207,6 @@ static uint8_t get_attrs(uint8_t index, const void *cmd, uint16_t cmd_len, uint16_t start_handle, end_handle; union uuid uuid; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if ((cmd_len < sizeof(*cp)) || (cmd_len != sizeof(*cp) + cp->type_length)) { return BTP_STATUS_FAILED; @@ -2415,7 +2293,7 @@ static uint8_t get_attr_val_rp(const struct bt_gatt_attr *attr, uint16_t handle, return BT_GATT_ITER_STOP; } -static uint8_t get_attr_val(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t get_attr_val(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_get_attribute_value_cmd *cp = cmd; @@ -2423,10 +2301,6 @@ static uint8_t get_attr_val(uint8_t index, const void *cmd, uint16_t cmd_len, uint16_t handle = sys_le16_to_cpu(cp->handle); struct bt_conn *conn; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); net_buf_simple_init(buf, 0); @@ -2444,17 +2318,13 @@ static uint8_t get_attr_val(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } -static uint8_t eatt_connect(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t eatt_connect(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_gatt_eatt_connect_cmd *cp = cmd; struct bt_conn *conn; int err; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { return BTP_STATUS_FAILED; @@ -2473,6 +2343,7 @@ static uint8_t eatt_connect(uint8_t index, const void *cmd, uint16_t cmd_len, static const struct btp_handler handlers[] = { { .opcode = BTP_GATT_READ_SUPPORTED_COMMANDS, + .index = BTP_INDEX_NONE, .expect_len = 0, .func = supported_commands, }, diff --git a/tests/bluetooth/tester/src/btp_ias.c b/tests/bluetooth/tester/src/btp_ias.c index e2df5bcaa2c0..5b4a47889865 100644 --- a/tests/bluetooth/tester/src/btp_ias.c +++ b/tests/bluetooth/tester/src/btp_ias.c @@ -15,8 +15,6 @@ #define LOG_MODULE_NAME bttester_ias LOG_MODULE_REGISTER(LOG_MODULE_NAME); -#define CONTROLLER_INDEX 0 - static bool initialized; @@ -32,7 +30,7 @@ static void alert_stop(void) ev.alert_lvl = BT_IAS_ALERT_LVL_NO_ALERT; tester_send(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, - CONTROLLER_INDEX, (uint8_t *)&ev, sizeof(ev)); + (uint8_t *)&ev, sizeof(ev)); } static void alert_start(void) @@ -46,7 +44,7 @@ static void alert_start(void) ev.alert_lvl = BT_IAS_ALERT_LVL_MILD_ALERT; tester_send(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, - CONTROLLER_INDEX, (uint8_t *)&ev.alert_lvl, sizeof(ev)); + (uint8_t *)&ev.alert_lvl, sizeof(ev)); } static void alert_high_start(void) @@ -60,7 +58,7 @@ static void alert_high_start(void) ev.alert_lvl = BT_IAS_ALERT_LVL_HIGH_ALERT; tester_send(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, - CONTROLLER_INDEX, (uint8_t *)&ev, sizeof(ev)); + (uint8_t *)&ev, sizeof(ev)); } BT_IAS_CB_DEFINE(ias_callbacks) = { diff --git a/tests/bluetooth/tester/src/btp_l2cap.c b/tests/bluetooth/tester/src/btp_l2cap.c index 9f61f22cd512..4004efde236a 100644 --- a/tests/bluetooth/tester/src/btp_l2cap.c +++ b/tests/bluetooth/tester/src/btp_l2cap.c @@ -19,7 +19,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "btp/btp.h" -#define CONTROLLER_INDEX 0 #define DATA_MTU_INITIAL 128 #define DATA_MTU 256 #define DATA_BUF_SIZE BT_L2CAP_SDU_BUF_SIZE(DATA_MTU) @@ -59,7 +58,7 @@ static int recv_cb(struct bt_l2cap_chan *l2cap_chan, struct net_buf *buf) memcpy(ev->data, buf->data, buf->len); tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_DATA_RECEIVED, - CONTROLLER_INDEX, recv_cb_buf, sizeof(*ev) + buf->len); + recv_cb_buf, sizeof(*ev) + buf->len); if (chan->hold_credit && !chan->pending_credit) { /* no need for extra ref, as when returning EINPROGRESS user @@ -96,7 +95,7 @@ static void connected_cb(struct bt_l2cap_chan *l2cap_chan) } } - tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_CONNECTED, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_CONNECTED, (uint8_t *) &ev, sizeof(ev)); } @@ -132,7 +131,7 @@ static void disconnected_cb(struct bt_l2cap_chan *l2cap_chan) chan->in_use = false; tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_DISCONNECTED, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } #if defined(CONFIG_BT_L2CAP_ECRED) @@ -150,7 +149,7 @@ static void reconfigured_cb(struct bt_l2cap_chan *l2cap_chan) ev.mps_local = sys_cpu_to_le16(chan->le.rx.mps); tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_RECONFIGURED, - CONTROLLER_INDEX, (uint8_t *)&ev, sizeof(ev)); + (uint8_t *)&ev, sizeof(ev)); } #endif @@ -187,7 +186,7 @@ static struct channel *get_free_channel() return NULL; } -static uint8_t connect(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t connect(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_l2cap_connect_cmd *cp = cmd; @@ -201,10 +200,6 @@ static uint8_t connect(uint8_t index, const void *cmd, uint16_t cmd_len, bool ecfc = cp->options & BTP_L2CAP_CONNECT_OPT_ECFC; int err; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - if (cp->num == 0 || cp->num > CHANNELS || mtu > DATA_MTU_INITIAL) { return BTP_STATUS_FAILED; } @@ -261,17 +256,13 @@ static uint8_t connect(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } -static uint8_t disconnect(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t disconnect(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_l2cap_disconnect_cmd *cp = cmd; struct channel *chan; int err; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - if (cp->chan_id >= CHANNELS) { return BTP_STATUS_FAILED; } @@ -287,7 +278,7 @@ static uint8_t disconnect(uint8_t index, const void *cmd, uint16_t cmd_len, } #if defined(CONFIG_BT_L2CAP_ECRED) -static uint8_t reconfigure(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t reconfigure(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_l2cap_reconfigure_cmd *cp = cmd; @@ -296,10 +287,6 @@ static uint8_t reconfigure(uint8_t index, const void *cmd, uint16_t cmd_len, int err; struct bt_l2cap_chan *reconf_channels[CHANNELS + 1] = {}; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - if (cmd_len < sizeof(*cp) || cmd_len != sizeof(*cp) + cp->num) { return BTP_STATUS_FAILED; @@ -340,17 +327,13 @@ static uint8_t reconfigure(uint8_t index, const void *cmd, uint16_t cmd_len, #endif #if defined(CONFIG_BT_EATT) -static uint8_t disconnect_eatt_chans(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t disconnect_eatt_chans(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_l2cap_disconnect_eatt_chans_cmd *cp = cmd; struct bt_conn *conn; int err; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, &cp->address); if (!conn) { LOG_ERR("Unknown connection"); @@ -371,7 +354,7 @@ static uint8_t disconnect_eatt_chans(uint8_t index, const void *cmd, uint16_t cm #endif -static uint8_t send_data(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t send_data(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_l2cap_send_data_cmd *cp = cmd; @@ -380,10 +363,6 @@ static uint8_t send_data(uint8_t index, const void *cmd, uint16_t cmd_len, uint16_t data_len; int ret; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - if (cmd_len < sizeof(*cp) || cmd_len != sizeof(*cp) + sys_le16_to_cpu(cp->data_len)) { return BTP_STATUS_FAILED; @@ -474,7 +453,7 @@ static int accept(struct bt_conn *conn, struct bt_l2cap_chan **l2cap_chan) return 0; } -static uint8_t listen(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t listen(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_l2cap_listen_cmd *cp = cmd; @@ -483,10 +462,6 @@ static uint8_t listen(uint8_t index, const void *cmd, uint16_t cmd_len, /* TODO: Handle cmd->transport flag */ - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - if (psm == 0 || !is_free_psm(psm)) { return BTP_STATUS_FAILED; } @@ -516,16 +491,12 @@ static uint8_t listen(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t credits(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t credits(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_l2cap_credits_cmd *cp = cmd; struct channel *chan; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - if (cp->chan_id >= CHANNELS) { return BTP_STATUS_FAILED; } @@ -548,15 +519,11 @@ static uint8_t credits(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_l2cap_read_supported_commands_rp *rp = rsp; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - /* octet 0 */ tester_set_bit(rp->data, BTP_L2CAP_READ_SUPPORTED_COMMANDS); tester_set_bit(rp->data, BTP_L2CAP_CONNECT); @@ -580,6 +547,7 @@ static uint8_t supported_commands(uint8_t index, const void *cmd, uint16_t cmd_l static const struct btp_handler handlers[] = { { .opcode = BTP_L2CAP_READ_SUPPORTED_COMMANDS, + .index = BTP_INDEX_NONE, .expect_len = 0, .func = supported_commands, }, diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 5484a595ecad..085685cf5382 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -20,7 +20,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "btp/btp.h" -#define CONTROLLER_INDEX 0 #define CID_LOCAL 0x05F1 /* Health server data */ @@ -74,15 +73,11 @@ static struct { }; -static uint8_t supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_mesh_read_supported_commands_rp *rp = rsp; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - /* octet 0 */ tester_set_bit(rp->data, BTP_MESH_READ_SUPPORTED_COMMANDS); tester_set_bit(rp->data, BTP_MESH_CONFIG_PROVISIONING); @@ -331,7 +326,7 @@ static void link_open(bt_mesh_prov_bearer_t bearer) } tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROV_LINK_OPEN, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } static void link_close(bt_mesh_prov_bearer_t bearer) @@ -354,7 +349,7 @@ static void link_close(bt_mesh_prov_bearer_t bearer) } tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROV_LINK_CLOSED, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } static int output_number(bt_mesh_output_action_t action, uint32_t number) @@ -367,7 +362,7 @@ static int output_number(bt_mesh_output_action_t action, uint32_t number) ev.number = sys_cpu_to_le32(number); tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_OUT_NUMBER_ACTION, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); return 0; } @@ -387,7 +382,7 @@ static int output_string(const char *str) net_buf_simple_add_mem(buf, str, ev->string_len); tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_OUT_STRING_ACTION, - CONTROLLER_INDEX, buf->data, buf->len); + buf->data, buf->len); return 0; } @@ -403,7 +398,7 @@ static int input(bt_mesh_input_action_t action, uint8_t size) ev.action = sys_cpu_to_le16(action); ev.size = size; - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_IN_ACTION, CONTROLLER_INDEX, + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_IN_ACTION, (uint8_t *) &ev, sizeof(ev)); return 0; @@ -417,8 +412,7 @@ static void prov_complete(uint16_t net_idx, uint16_t addr) net.local = addr; net.dst = addr; - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROVISIONED, CONTROLLER_INDEX, - NULL, 0); + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROVISIONED, NULL, 0); } static void prov_node_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr, @@ -435,7 +429,7 @@ static void prov_node_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr, memcpy(&ev.uuid, uuid, sizeof(ev.uuid)); tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROV_NODE_ADDED, - CONTROLLER_INDEX, (void *)&ev, sizeof(ev)); + (void *)&ev, sizeof(ev)); } static void prov_reset(void) @@ -465,7 +459,7 @@ static struct bt_mesh_prov prov = { .reset = prov_reset, }; -static uint8_t config_prov(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_prov(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_config_provisioning_cmd *cp = cmd; @@ -477,10 +471,6 @@ static uint8_t config_prov(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - LOG_DBG(""); memcpy(dev_uuid, cp->uuid, sizeof(dev_uuid)); @@ -514,7 +504,7 @@ static uint8_t config_prov(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t provision_node(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t provision_node(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_provision_node_cmd *cp = cmd; @@ -526,10 +516,6 @@ static uint8_t provision_node(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - LOG_DBG(""); memcpy(dev_key, cp->dev_key, sizeof(dev_key)); @@ -566,7 +552,7 @@ static uint8_t provision_node(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t provision_adv(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t provision_adv(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_provision_adv_cmd *cp = cmd; @@ -585,17 +571,13 @@ static uint8_t provision_adv(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t init(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t init(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { int err; LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_init(&prov, &comp); if (err) { return BTP_STATUS_FAILED; @@ -617,31 +599,23 @@ static uint8_t init(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t reset(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t reset(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - bt_mesh_reset(); return BTP_STATUS_SUCCESS; } -static uint8_t input_number(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t input_number(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_input_number_cmd *cp = cmd; uint32_t number; int err; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - number = sys_le32_to_cpu(cp->number); LOG_DBG("number 0x%04x", number); @@ -654,7 +628,7 @@ static uint8_t input_number(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t input_string(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t input_string(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_input_string_cmd *cp = cmd; @@ -668,10 +642,6 @@ static uint8_t input_string(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - /* for historical reasons this commands must send NULL terminated * string */ @@ -692,15 +662,11 @@ static uint8_t input_string(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t ivu_test_mode(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t ivu_test_mode(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_ivu_test_mode_cmd *cp = cmd; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - LOG_DBG("enable 0x%02x", cp->enable); bt_mesh_iv_update_test(cp->enable ? true : false); @@ -708,15 +674,11 @@ static uint8_t ivu_test_mode(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t ivu_toggle_state(uint8_t index, const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) +static uint8_t ivu_toggle_state(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { bool result; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - LOG_DBG(""); result = bt_mesh_iv_update(); @@ -728,16 +690,12 @@ static uint8_t ivu_toggle_state(uint8_t index, const void *cmd, uint16_t cmd_len return BTP_STATUS_SUCCESS; } -static uint8_t lpn(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t lpn(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_lpn_set_cmd *cp = cmd; int err; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - LOG_DBG("enable 0x%02x", cp->enable); err = bt_mesh_lpn_set(cp->enable ? true : false); @@ -749,15 +707,11 @@ static uint8_t lpn(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t lpn_poll(uint8_t index, const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) +static uint8_t lpn_poll(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { int err; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - LOG_DBG(""); err = bt_mesh_lpn_poll(); @@ -768,8 +722,8 @@ static uint8_t lpn_poll(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t net_send(uint8_t index, const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) +static uint8_t net_send(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { const struct btp_mesh_net_send_cmd *cp = cmd; NET_BUF_SIMPLE_DEFINE(msg, UINT8_MAX); @@ -780,10 +734,6 @@ static uint8_t net_send(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, .app_idx = vnd_app_key_idx, @@ -811,7 +761,7 @@ static uint8_t net_send(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t health_generate_faults(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t health_generate_faults(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_mesh_health_generate_faults_rp *rp = rsp; @@ -819,10 +769,6 @@ static uint8_t health_generate_faults(uint8_t index, const void *cmd, uint16_t c uint8_t cur_faults_count; uint8_t reg_faults_count; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - cur_faults_count = MIN(sizeof(cur_faults), sizeof(some_faults)); memcpy(cur_faults, some_faults, cur_faults_count); memcpy(rp->current_faults, cur_faults, cur_faults_count); @@ -840,15 +786,11 @@ static uint8_t health_generate_faults(uint8_t index, const void *cmd, uint16_t c return BTP_STATUS_SUCCESS; } -static uint8_t health_clear_faults(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t health_clear_faults(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - (void)memset(cur_faults, 0, sizeof(cur_faults)); (void)memset(reg_faults, 0, sizeof(reg_faults)); @@ -857,7 +799,7 @@ static uint8_t health_clear_faults(uint8_t index, const void *cmd, uint16_t cmd_ return BTP_STATUS_SUCCESS; } -static uint8_t model_send(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t model_send(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_model_send_cmd *cp = cmd; @@ -871,10 +813,6 @@ static uint8_t model_send(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - struct bt_mesh_msg_ctx ctx = { .net_idx = net.net_idx, .app_idx = BT_MESH_KEY_DEV, @@ -914,7 +852,7 @@ static uint8_t model_send(uint8_t index, const void *cmd, uint16_t cmd_len, } #if defined(CONFIG_BT_TESTING) -static uint8_t lpn_subscribe(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t lpn_subscribe(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_lpn_subscribe_cmd *cp = cmd; @@ -932,7 +870,7 @@ static uint8_t lpn_subscribe(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t lpn_unsubscribe(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t lpn_unsubscribe(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_lpn_unsubscribe_cmd *cp = cmd; @@ -950,7 +888,7 @@ static uint8_t lpn_unsubscribe(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t rpl_clear(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t rpl_clear(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { int err; @@ -967,7 +905,7 @@ static uint8_t rpl_clear(uint8_t index, const void *cmd, uint16_t cmd_len, } #endif /* CONFIG_BT_TESTING */ -static uint8_t proxy_identity_enable(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t proxy_identity_enable(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { int err; @@ -983,7 +921,7 @@ static uint8_t proxy_identity_enable(uint8_t index, const void *cmd, uint16_t cm return BTP_STATUS_SUCCESS; } -static uint8_t composition_data_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t composition_data_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_comp_data_get_cmd *cp = cmd; @@ -994,10 +932,6 @@ static uint8_t composition_data_get(uint8_t index, const void *cmd, uint16_t cmd LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - bt_mesh_cfg_cli_timeout_set(10 * MSEC_PER_SEC); net_buf_simple_init(comp, 0); @@ -1016,7 +950,7 @@ static uint8_t composition_data_get(uint8_t index, const void *cmd, uint16_t cmd return BTP_STATUS_SUCCESS; } -static uint8_t config_krp_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_krp_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_krp_get_cmd *cp = cmd; @@ -1045,7 +979,7 @@ static uint8_t config_krp_get(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t config_krp_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_krp_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_krp_set_cmd *cp = cmd; @@ -1073,7 +1007,7 @@ static uint8_t config_krp_set(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t config_beacon_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_beacon_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_beacon_get_cmd *cp = cmd; @@ -1083,10 +1017,6 @@ static uint8_t config_beacon_get(uint8_t index, const void *cmd, uint16_t cmd_le LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_beacon_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), &status); if (err) { @@ -1100,7 +1030,7 @@ static uint8_t config_beacon_get(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_beacon_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_beacon_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_beacon_set_cmd *cp = cmd; @@ -1110,10 +1040,6 @@ static uint8_t config_beacon_set(uint8_t index, const void *cmd, uint16_t cmd_le LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_beacon_set(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), cp->val, &status); @@ -1128,7 +1054,7 @@ static uint8_t config_beacon_set(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_default_ttl_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_default_ttl_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_default_ttl_get_cmd *cp = cmd; @@ -1138,10 +1064,6 @@ static uint8_t config_default_ttl_get(uint8_t index, const void *cmd, uint16_t c LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_ttl_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), &status); @@ -1156,7 +1078,7 @@ static uint8_t config_default_ttl_get(uint8_t index, const void *cmd, uint16_t c return BTP_STATUS_SUCCESS; } -static uint8_t config_default_ttl_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_default_ttl_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_default_ttl_set_cmd *cp = cmd; @@ -1166,10 +1088,6 @@ static uint8_t config_default_ttl_set(uint8_t index, const void *cmd, uint16_t c LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_ttl_set(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), cp->val, &status); @@ -1185,7 +1103,7 @@ static uint8_t config_default_ttl_set(uint8_t index, const void *cmd, uint16_t c return BTP_STATUS_SUCCESS; } -static uint8_t config_gatt_proxy_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_gatt_proxy_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_gatt_proxy_get_cmd *cp = cmd; @@ -1195,10 +1113,6 @@ static uint8_t config_gatt_proxy_get(uint8_t index, const void *cmd, uint16_t cm LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_gatt_proxy_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), &status); @@ -1213,7 +1127,7 @@ static uint8_t config_gatt_proxy_get(uint8_t index, const void *cmd, uint16_t cm return BTP_STATUS_SUCCESS; } -static uint8_t config_gatt_proxy_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_gatt_proxy_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_gatt_proxy_set_cmd *cp = cmd; @@ -1223,10 +1137,6 @@ static uint8_t config_gatt_proxy_set(uint8_t index, const void *cmd, uint16_t cm LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_gatt_proxy_set(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), cp->val, &status); @@ -1241,7 +1151,7 @@ static uint8_t config_gatt_proxy_set(uint8_t index, const void *cmd, uint16_t cm return BTP_STATUS_SUCCESS; } -static uint8_t config_friend_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_friend_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_friend_get_cmd *cp = cmd; @@ -1251,10 +1161,6 @@ static uint8_t config_friend_get(uint8_t index, const void *cmd, uint16_t cmd_le LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_friend_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), &status); @@ -1270,7 +1176,7 @@ static uint8_t config_friend_get(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_friend_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_friend_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_friend_set_cmd *cp = cmd; @@ -1280,10 +1186,6 @@ static uint8_t config_friend_set(uint8_t index, const void *cmd, uint16_t cmd_le LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_friend_set(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), cp->val, &status); @@ -1299,7 +1201,7 @@ static uint8_t config_friend_set(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_relay_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_relay_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_relay_get_cmd *cp = cmd; @@ -1310,10 +1212,6 @@ static uint8_t config_relay_get(uint8_t index, const void *cmd, uint16_t cmd_len LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_relay_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), &status, &transmit); @@ -1329,7 +1227,7 @@ static uint8_t config_relay_get(uint8_t index, const void *cmd, uint16_t cmd_len return BTP_STATUS_SUCCESS; } -static uint8_t config_relay_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_relay_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_relay_set_cmd *cp = cmd; @@ -1340,10 +1238,6 @@ static uint8_t config_relay_set(uint8_t index, const void *cmd, uint16_t cmd_len LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_relay_set(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), cp->new_relay, cp->new_transmit, @@ -1360,7 +1254,7 @@ static uint8_t config_relay_set(uint8_t index, const void *cmd, uint16_t cmd_len return BTP_STATUS_SUCCESS; } -static uint8_t config_mod_pub_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_mod_pub_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_pub_get_cmd *cp = cmd; @@ -1371,10 +1265,6 @@ static uint8_t config_mod_pub_get(uint8_t index, const void *cmd, uint16_t cmd_l LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_mod_pub_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -1392,7 +1282,7 @@ static uint8_t config_mod_pub_get(uint8_t index, const void *cmd, uint16_t cmd_l return BTP_STATUS_SUCCESS; } -static uint8_t config_mod_pub_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_mod_pub_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_pub_set_cmd *cp = cmd; @@ -1403,10 +1293,6 @@ static uint8_t config_mod_pub_set(uint8_t index, const void *cmd, uint16_t cmd_l LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - pub.addr = sys_le16_to_cpu(cp->pub_addr); pub.uuid = NULL; pub.app_idx = sys_le16_to_cpu(cp->app_idx); @@ -1432,7 +1318,7 @@ static uint8_t config_mod_pub_set(uint8_t index, const void *cmd, uint16_t cmd_l return BTP_STATUS_SUCCESS; } -static uint8_t config_mod_pub_va_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_mod_pub_va_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_pub_va_set_cmd *cp = cmd; @@ -1467,7 +1353,7 @@ static uint8_t config_mod_pub_va_set(uint8_t index, const void *cmd, uint16_t cm return BTP_STATUS_SUCCESS; } -static uint8_t config_mod_sub_add(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_mod_sub_add(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_sub_add_cmd *cp = cmd; @@ -1477,10 +1363,6 @@ static uint8_t config_mod_sub_add(uint8_t index, const void *cmd, uint16_t cmd_l LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_mod_sub_add(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -1499,7 +1381,7 @@ static uint8_t config_mod_sub_add(uint8_t index, const void *cmd, uint16_t cmd_l return BTP_STATUS_SUCCESS; } -static uint8_t config_mod_sub_ovw(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_mod_sub_ovw(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_sub_add_cmd *cp = cmd; @@ -1526,7 +1408,7 @@ static uint8_t config_mod_sub_ovw(uint8_t index, const void *cmd, uint16_t cmd_l return BTP_STATUS_SUCCESS; } -static uint8_t config_mod_sub_del(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_mod_sub_del(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_sub_del_cmd *cp = cmd; @@ -1536,10 +1418,6 @@ static uint8_t config_mod_sub_del(uint8_t index, const void *cmd, uint16_t cmd_l LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_mod_sub_del(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -1557,7 +1435,7 @@ static uint8_t config_mod_sub_del(uint8_t index, const void *cmd, uint16_t cmd_l return BTP_STATUS_SUCCESS; } -static uint8_t config_mod_sub_del_all(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_mod_sub_del_all(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_sub_del_all_cmd *cp = cmd; @@ -1567,10 +1445,6 @@ static uint8_t config_mod_sub_del_all(uint8_t index, const void *cmd, uint16_t c LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_mod_sub_del_all(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -1588,7 +1462,7 @@ static uint8_t config_mod_sub_del_all(uint8_t index, const void *cmd, uint16_t c return BTP_STATUS_SUCCESS; } -static uint8_t config_mod_sub_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_mod_sub_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_sub_get_cmd *cp = cmd; @@ -1600,10 +1474,6 @@ static uint8_t config_mod_sub_get(uint8_t index, const void *cmd, uint16_t cmd_l LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_mod_sub_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -1620,7 +1490,7 @@ static uint8_t config_mod_sub_get(uint8_t index, const void *cmd, uint16_t cmd_l return BTP_STATUS_SUCCESS; } -static uint8_t config_mod_sub_get_vnd(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_mod_sub_get_vnd(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_sub_get_vnd_cmd *cp = cmd; @@ -1632,11 +1502,6 @@ static uint8_t config_mod_sub_get_vnd(uint8_t index, const void *cmd, uint16_t c LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - - err = bt_mesh_cfg_cli_mod_sub_get_vnd(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -1654,7 +1519,7 @@ static uint8_t config_mod_sub_get_vnd(uint8_t index, const void *cmd, uint16_t c return BTP_STATUS_SUCCESS; } -static uint8_t config_mod_sub_va_add(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_mod_sub_va_add(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_sub_va_add_cmd *cp = cmd; @@ -1665,10 +1530,6 @@ static uint8_t config_mod_sub_va_add(uint8_t index, const void *cmd, uint16_t cm LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_mod_sub_va_add(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -1687,7 +1548,7 @@ static uint8_t config_mod_sub_va_add(uint8_t index, const void *cmd, uint16_t cm return BTP_STATUS_SUCCESS; } -static uint8_t config_mod_sub_va_del(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_mod_sub_va_del(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_sub_va_del_cmd *cp = cmd; @@ -1698,10 +1559,6 @@ static uint8_t config_mod_sub_va_del(uint8_t index, const void *cmd, uint16_t cm LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_mod_sub_va_del(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -1720,7 +1577,7 @@ static uint8_t config_mod_sub_va_del(uint8_t index, const void *cmd, uint16_t cm return BTP_STATUS_SUCCESS; } -static uint8_t config_mod_sub_va_ovw(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_mod_sub_va_ovw(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_sub_va_ovw_cmd *cp = cmd; @@ -1731,10 +1588,6 @@ static uint8_t config_mod_sub_va_ovw(uint8_t index, const void *cmd, uint16_t cm LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_mod_sub_va_overwrite(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -1753,7 +1606,7 @@ static uint8_t config_mod_sub_va_ovw(uint8_t index, const void *cmd, uint16_t cm return BTP_STATUS_SUCCESS; } -static uint8_t config_netkey_add(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_netkey_add(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_netkey_add_cmd *cp = cmd; @@ -1763,10 +1616,6 @@ static uint8_t config_netkey_add(uint8_t index, const void *cmd, uint16_t cmd_le LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_net_key_add(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->net_key_idx), @@ -1783,7 +1632,7 @@ static uint8_t config_netkey_add(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_netkey_update(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_netkey_update(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_netkey_update_cmd *cp = cmd; @@ -1793,10 +1642,6 @@ static uint8_t config_netkey_update(uint8_t index, const void *cmd, uint16_t cmd LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_net_key_update(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->net_key_idx), @@ -1814,7 +1659,7 @@ static uint8_t config_netkey_update(uint8_t index, const void *cmd, uint16_t cmd return BTP_STATUS_SUCCESS; } -static uint8_t config_netkey_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_netkey_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_netkey_get_cmd *cp = cmd; @@ -1825,10 +1670,6 @@ static uint8_t config_netkey_get(uint8_t index, const void *cmd, uint16_t cmd_le LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_net_key_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), &keys, &key_cnt); @@ -1844,7 +1685,7 @@ static uint8_t config_netkey_get(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_netkey_del(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_netkey_del(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_netkey_del_cmd *cp = cmd; @@ -1854,10 +1695,6 @@ static uint8_t config_netkey_del(uint8_t index, const void *cmd, uint16_t cmd_le LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_net_key_del(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->net_key_idx), @@ -1874,7 +1711,7 @@ static uint8_t config_netkey_del(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_appkey_add(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_appkey_add(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_appkey_add_cmd *cp = cmd; @@ -1884,10 +1721,6 @@ static uint8_t config_appkey_add(uint8_t index, const void *cmd, uint16_t cmd_le LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_app_key_add(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->net_key_idx), @@ -1906,7 +1739,7 @@ static uint8_t config_appkey_add(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_appkey_update(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_appkey_update(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_appkey_update_cmd *cp = cmd; @@ -1916,10 +1749,6 @@ static uint8_t config_appkey_update(uint8_t index, const void *cmd, uint16_t cmd LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_app_key_update(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->net_key_idx), @@ -1938,7 +1767,7 @@ static uint8_t config_appkey_update(uint8_t index, const void *cmd, uint16_t cmd return BTP_STATUS_SUCCESS; } -static uint8_t config_appkey_del(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_appkey_del(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_appkey_del_cmd *cp = cmd; @@ -1948,10 +1777,6 @@ static uint8_t config_appkey_del(uint8_t index, const void *cmd, uint16_t cmd_le LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_app_key_del(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->net_key_idx), @@ -1969,7 +1794,7 @@ static uint8_t config_appkey_del(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_appkey_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_appkey_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_appkey_get_cmd *cp = cmd; @@ -1981,10 +1806,6 @@ static uint8_t config_appkey_get(uint8_t index, const void *cmd, uint16_t cmd_le LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_app_key_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->net_key_idx), @@ -2002,7 +1823,7 @@ static uint8_t config_appkey_get(uint8_t index, const void *cmd, uint16_t cmd_le } -static uint8_t config_model_app_bind(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_model_app_bind(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_app_bind_cmd *cp = cmd; @@ -2012,10 +1833,6 @@ static uint8_t config_model_app_bind(uint8_t index, const void *cmd, uint16_t cm LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_mod_app_bind(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -2034,7 +1851,7 @@ static uint8_t config_model_app_bind(uint8_t index, const void *cmd, uint16_t cm return BTP_STATUS_SUCCESS; } -static uint8_t config_model_app_bind_vnd(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_model_app_bind_vnd(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_app_bind_vnd_cmd *cp = cmd; @@ -2044,10 +1861,6 @@ static uint8_t config_model_app_bind_vnd(uint8_t index, const void *cmd, uint16_ LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_mod_app_bind_vnd(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -2067,7 +1880,7 @@ static uint8_t config_model_app_bind_vnd(uint8_t index, const void *cmd, uint16_ return BTP_STATUS_SUCCESS; } -static uint8_t config_model_app_unbind(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_model_app_unbind(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_app_unbind_cmd *cp = cmd; @@ -2077,10 +1890,6 @@ static uint8_t config_model_app_unbind(uint8_t index, const void *cmd, uint16_t LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_mod_app_unbind(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -2099,7 +1908,7 @@ static uint8_t config_model_app_unbind(uint8_t index, const void *cmd, uint16_t } -static uint8_t config_model_app_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_model_app_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_app_get_cmd *cp = cmd; @@ -2111,10 +1920,6 @@ static uint8_t config_model_app_get(uint8_t index, const void *cmd, uint16_t cmd LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_mod_app_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -2132,7 +1937,7 @@ static uint8_t config_model_app_get(uint8_t index, const void *cmd, uint16_t cmd return BTP_STATUS_SUCCESS; } -static uint8_t config_model_app_vnd_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_model_app_vnd_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_model_app_vnd_get_cmd *cp = cmd; @@ -2144,10 +1949,6 @@ static uint8_t config_model_app_vnd_get(uint8_t index, const void *cmd, uint16_t LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_mod_app_get_vnd(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), sys_le16_to_cpu(cp->elem_address), @@ -2165,7 +1966,7 @@ static uint8_t config_model_app_vnd_get(uint8_t index, const void *cmd, uint16_t return BTP_STATUS_SUCCESS; } -static uint8_t config_hb_pub_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_hb_pub_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_heartbeat_pub_set_cmd *cp = cmd; @@ -2176,10 +1977,6 @@ static uint8_t config_hb_pub_set(uint8_t index, const void *cmd, uint16_t cmd_le LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - pub.net_idx = sys_le16_to_cpu(cp->net_key_idx); pub.dst = sys_le16_to_cpu(cp->destination); pub.count = cp->count_log; @@ -2202,7 +1999,7 @@ static uint8_t config_hb_pub_set(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_hb_pub_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_hb_pub_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_heartbeat_pub_get_cmd *cp = cmd; @@ -2213,10 +2010,6 @@ static uint8_t config_hb_pub_get(uint8_t index, const void *cmd, uint16_t cmd_le LOG_DBG(""); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - err = bt_mesh_cfg_cli_hb_pub_get(sys_le16_to_cpu(cp->net_idx), sys_le16_to_cpu(cp->address), &pub, &status); @@ -2232,7 +2025,7 @@ static uint8_t config_hb_pub_get(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_hb_sub_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_hb_sub_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_heartbeat_sub_set_cmd *cp = cmd; @@ -2262,7 +2055,7 @@ static uint8_t config_hb_sub_set(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_hb_sub_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_hb_sub_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_heartbeat_sub_get_cmd *cp = cmd; @@ -2288,7 +2081,7 @@ static uint8_t config_hb_sub_get(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_net_trans_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_net_trans_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_net_trans_get_cmd *cp = cmd; @@ -2313,7 +2106,7 @@ static uint8_t config_net_trans_get(uint8_t index, const void *cmd, uint16_t cmd return BTP_STATUS_SUCCESS; } -static uint8_t config_net_trans_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_net_trans_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_net_trans_set_cmd *cp = cmd; @@ -2338,7 +2131,7 @@ static uint8_t config_net_trans_set(uint8_t index, const void *cmd, uint16_t cmd return BTP_STATUS_SUCCESS; } -static uint8_t config_node_identity_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_node_identity_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_node_idt_set_cmd *cp = cmd; @@ -2367,7 +2160,7 @@ static uint8_t config_node_identity_set(uint8_t index, const void *cmd, uint16_t return BTP_STATUS_SUCCESS; } -static uint8_t config_node_identity_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_node_identity_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_node_idt_get_cmd *cp = cmd; @@ -2395,7 +2188,7 @@ static uint8_t config_node_identity_get(uint8_t index, const void *cmd, uint16_t return BTP_STATUS_SUCCESS; } -static uint8_t config_node_reset(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_node_reset(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_node_reset_cmd *cp = cmd; @@ -2420,7 +2213,7 @@ static uint8_t config_node_reset(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t config_lpn_timeout_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t config_lpn_timeout_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_cfg_lpn_timeout_cmd *cp = cmd; @@ -2446,7 +2239,7 @@ static uint8_t config_lpn_timeout_get(uint8_t index, const void *cmd, uint16_t c return BTP_STATUS_SUCCESS; } -static uint8_t health_fault_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t health_fault_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_health_fault_get_cmd *cp = cmd; @@ -2474,7 +2267,7 @@ static uint8_t health_fault_get(uint8_t index, const void *cmd, uint16_t cmd_len return BTP_STATUS_SUCCESS; } -static uint8_t health_fault_clear(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t health_fault_clear(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_health_fault_clear_cmd *cp = cmd; @@ -2515,7 +2308,7 @@ static uint8_t health_fault_clear(uint8_t index, const void *cmd, uint16_t cmd_l return BTP_STATUS_SUCCESS; } -static uint8_t health_fault_test(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t health_fault_test(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_health_fault_test_cmd *cp = cmd; @@ -2560,7 +2353,7 @@ static uint8_t health_fault_test(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t health_period_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t health_period_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_health_period_get_cmd *cp = cmd; @@ -2584,7 +2377,7 @@ static uint8_t health_period_get(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t health_period_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t health_period_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_health_period_set_cmd *cp = cmd; @@ -2621,7 +2414,7 @@ static uint8_t health_period_set(uint8_t index, const void *cmd, uint16_t cmd_le return BTP_STATUS_SUCCESS; } -static uint8_t health_attention_get(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t health_attention_get(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_health_attention_get_cmd *cp = cmd; @@ -2645,7 +2438,7 @@ static uint8_t health_attention_get(uint8_t index, const void *cmd, uint16_t cmd return BTP_STATUS_SUCCESS; } -static uint8_t health_attention_set(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t health_attention_set(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_mesh_health_attention_set_cmd *cp = cmd; @@ -2685,6 +2478,7 @@ static uint8_t health_attention_set(uint8_t index, const void *cmd, uint16_t cmd static const struct btp_handler handlers[] = { { .opcode = BTP_MESH_READ_SUPPORTED_COMMANDS, + .index = BTP_INDEX_NONE, .expect_len = 0, .func = supported_commands, }, @@ -3084,8 +2878,7 @@ void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const voi ev->payload_len = payload_len; net_buf_simple_add_mem(&buf, payload, payload_len); - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_NET_RECV, CONTROLLER_INDEX, - buf.data, buf.len); + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_NET_RECV, buf.data, buf.len); } static void model_bound_cb(uint16_t addr, struct bt_mesh_model *model, @@ -3139,13 +2932,12 @@ static void invalid_bearer_cb(uint8_t opcode) LOG_DBG("opcode 0x%02x", opcode); tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_INVALID_BEARER, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } static void incomp_timer_exp_cb(void) { - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_INCOMP_TIMER_EXP, - CONTROLLER_INDEX, NULL, 0); + tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_INCOMP_TIMER_EXP, NULL, 0); } static struct bt_test_cb bt_test_cb = { @@ -3168,7 +2960,7 @@ static void friend_established(uint16_t net_idx, uint16_t lpn_addr, tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_FRND_ESTABLISHED, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } static void friend_terminated(uint16_t net_idx, uint16_t lpn_addr) @@ -3179,7 +2971,7 @@ static void friend_terminated(uint16_t net_idx, uint16_t lpn_addr) "0x%04x", lpn_addr); tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_FRND_TERMINATED, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } BT_MESH_FRIEND_CB_DEFINE(friend_cb) = { @@ -3198,7 +2990,7 @@ static void lpn_established(uint16_t net_idx, uint16_t friend_addr, friend_addr, queue_size, recv_win); tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_LPN_ESTABLISHED, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } static void lpn_terminated(uint16_t net_idx, uint16_t friend_addr) @@ -3209,7 +3001,7 @@ static void lpn_terminated(uint16_t net_idx, uint16_t friend_addr) "0x%04x", friend_addr); tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_LPN_TERMINATED, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } static void lpn_polled(uint16_t net_idx, uint16_t friend_addr, bool retry) @@ -3219,7 +3011,7 @@ static void lpn_polled(uint16_t net_idx, uint16_t friend_addr, bool retry) LOG_DBG("LPN polled 0x%04x %s", friend_addr, retry ? "(retry)" : ""); tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_LPN_POLLED, - CONTROLLER_INDEX, (uint8_t *) &ev, sizeof(ev)); + (uint8_t *) &ev, sizeof(ev)); } BT_MESH_LPN_CB_DEFINE(lpn_cb) = { diff --git a/tests/bluetooth/tester/src/btp_vcp.c b/tests/bluetooth/tester/src/btp_vcp.c index f694d09c4c39..1b7552318aab 100644 --- a/tests/bluetooth/tester/src/btp_vcp.c +++ b/tests/bluetooth/tester/src/btp_vcp.c @@ -23,7 +23,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "btp/btp.h" -#define CONTROLLER_INDEX 0 #define BT_AICS_MAX_INPUT_DESCRIPTION_SIZE 16 #define BT_AICS_MAX_OUTPUT_DESCRIPTION_SIZE 16 @@ -31,15 +30,11 @@ static struct bt_vcp_vol_rend_register_param vcp_register_param; static struct bt_vcp_included included; /* Volume Control Service */ -static uint8_t vcs_supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t vcs_supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_vcs_read_supported_commands_rp *rp = rsp; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - /* octet 0 */ tester_set_bit(rp->data, BTP_VCS_READ_SUPPORTED_COMMANDS); tester_set_bit(rp->data, BTP_VCS_SET_VOL); @@ -53,15 +48,11 @@ static uint8_t vcs_supported_commands(uint8_t index, const void *cmd, uint16_t c return BTP_STATUS_SUCCESS; } -static uint8_t set_volume(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t set_volume(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_vcs_set_vol_cmd *cp = cmd; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - LOG_DBG("Set volume 0x%02x", cp->volume); if (bt_vcp_vol_rend_set_vol(cp->volume) != 0) { @@ -71,15 +62,11 @@ static uint8_t set_volume(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t vol_up(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t vol_up(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { LOG_DBG("Volume Up"); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if (bt_vcp_vol_rend_vol_up() != 0) { return BTP_STATUS_FAILED; } @@ -87,15 +74,11 @@ static uint8_t vol_up(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t vol_down(uint8_t index, const void *cmd, uint16_t cmd_len, - void *rsp, uint16_t *rsp_len) +static uint8_t vol_down(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) { LOG_DBG("Volume Down"); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if (bt_vcp_vol_rend_vol_down() != 0) { return BTP_STATUS_FAILED; } @@ -103,15 +86,11 @@ static uint8_t vol_down(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t mute(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t mute(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { LOG_DBG("Mute"); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if (bt_vcp_vol_rend_mute() != 0) { return BTP_STATUS_FAILED; } @@ -119,15 +98,11 @@ static uint8_t mute(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t unmute(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t unmute(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { LOG_DBG("Unmute"); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if (bt_vcp_vol_rend_unmute() != 0) { return BTP_STATUS_FAILED; } @@ -153,6 +128,7 @@ static struct bt_vcp_vol_rend_cb vcs_cb = { static const struct btp_handler vcs_handlers[] = { { .opcode = BTP_VCS_READ_SUPPORTED_COMMANDS, + .index = BTP_INDEX_NONE, .expect_len = 0, .func = vcs_supported_commands, }, @@ -184,15 +160,11 @@ static const struct btp_handler vcs_handlers[] = { }; /* Audio Input Control Service */ -static uint8_t aics_supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t aics_supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_aics_read_supported_commands_rp *rp = rsp; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - /* octet 0 */ tester_set_bit(rp->data, BTP_AICS_READ_SUPPORTED_COMMANDS); tester_set_bit(rp->data, BTP_AICS_SET_GAIN); @@ -246,17 +218,13 @@ static struct bt_aics_cb aics_cb = { .description = aics_description_cb }; -static uint8_t aics_set_gain(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t aics_set_gain(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_aics_set_gain_cmd *cp = cmd; LOG_DBG("AICS set gain %d", cp->gain); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_gain_set(included.aics[0], cp->gain) != 0) { return BTP_STATUS_FAILED; @@ -266,15 +234,11 @@ static uint8_t aics_set_gain(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t aics_mute(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t aics_mute(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { LOG_DBG("AICS mute"); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_mute(included.aics[i]) != 0) { return BTP_STATUS_FAILED; @@ -284,16 +248,11 @@ static uint8_t aics_mute(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t aics_unmute(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t aics_unmute(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { LOG_DBG("AICS unmute"); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - - for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_unmute(included.aics[i]) != 0) { return BTP_STATUS_FAILED; @@ -303,15 +262,11 @@ static uint8_t aics_unmute(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t aics_man_gain(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t aics_man_gain(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { LOG_DBG("AICS manual gain set"); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_manual_gain_set(included.aics[i]) != 0) { return BTP_STATUS_FAILED; @@ -321,15 +276,11 @@ static uint8_t aics_man_gain(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t aics_auto_gain(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t aics_auto_gain(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { LOG_DBG("AICS auto gain set"); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT; i++) { if (bt_aics_automatic_gain_set(included.aics[i]) != 0) { return BTP_STATUS_FAILED; @@ -339,7 +290,7 @@ static uint8_t aics_auto_gain(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t aics_desc(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t aics_desc(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_aics_audio_desc_cmd *cp = cmd; @@ -347,10 +298,6 @@ static uint8_t aics_desc(uint8_t index, const void *cmd, uint16_t cmd_len, LOG_DBG("AICS description"); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if (cmd_len < sizeof(*cp) || cmd_len != sizeof(*cp) + cp->desc_len) { return BTP_STATUS_FAILED; @@ -375,6 +322,7 @@ static uint8_t aics_desc(uint8_t index, const void *cmd, uint16_t cmd_len, static const struct btp_handler aics_handlers[] = { { .opcode = BTP_AICS_READ_SUPPORTED_COMMANDS, + .index = BTP_INDEX_NONE, .expect_len = 0, .func = aics_supported_commands, }, @@ -411,15 +359,11 @@ static const struct btp_handler aics_handlers[] = { }; /* Volume Offset Control Service */ -static uint8_t vocs_supported_commands(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t vocs_supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { struct btp_vocs_read_supported_commands_rp *rp = rsp; - if (index != BTP_INDEX_NONE) { - return BTP_STATUS_FAILED; - } - /* octet 0 */ tester_set_bit(rp->data, BTP_VOCS_READ_SUPPORTED_COMMANDS); tester_set_bit(rp->data, BTP_VOCS_UPDATE_LOC); @@ -452,16 +396,12 @@ static struct bt_vocs_cb vocs_cb = { .description = vocs_description_cb }; -static uint8_t vocs_audio_desc(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t vocs_audio_desc(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_vocs_audio_desc_cmd *cp = cmd; char description[BT_AICS_MAX_OUTPUT_DESCRIPTION_SIZE]; - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - if (cmd_len < sizeof(*cp) || cmd_len != sizeof(*cp) + cp->desc_len) { return BTP_STATUS_FAILED; @@ -483,16 +423,12 @@ static uint8_t vocs_audio_desc(uint8_t index, const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } -static uint8_t vocs_audio_loc(uint8_t index, const void *cmd, uint16_t cmd_len, +static uint8_t vocs_audio_loc(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { const struct btp_vocs_audio_loc_cmd *cp = cmd; uint32_t loc = sys_le32_to_cpu(cp->loc); - if (index != CONTROLLER_INDEX) { - return BTP_STATUS_FAILED; - } - for (int i = 0; i < CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT; i++) { if (bt_vocs_location_set(included.vocs[i], loc) != 0) { return BTP_STATUS_FAILED; @@ -505,6 +441,7 @@ static uint8_t vocs_audio_loc(uint8_t index, const void *cmd, uint16_t cmd_len, static const struct btp_handler vocs_handlers[] = { { .opcode = BTP_VOCS_READ_SUPPORTED_COMMANDS, + .index = BTP_INDEX_NONE, .expect_len = 0, .func = vocs_supported_commands, }, From 06a418346a2250a731fd1e470f07540d41d6c028 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 3 Mar 2023 11:46:43 +0100 Subject: [PATCH 0033/1906] bluetooth: tester: Keep BTP command in buffer for delayed response This allows to avoid copying data for async callbacks. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp.c | 48 ++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/tests/bluetooth/tester/src/btp.c b/tests/bluetooth/tester/src/btp.c index d3e505fcde59..4f442dffe869 100644 --- a/tests/bluetooth/tester/src/btp.c +++ b/tests/bluetooth/tester/src/btp.c @@ -43,6 +43,8 @@ static struct btp_buf cmd_buf[CMD_QUEUED]; static K_FIFO_DEFINE(cmds_queue); static K_FIFO_DEFINE(avail_queue); +static struct btp_buf *delayed_cmd; + static struct { const struct btp_handler *handlers; size_t num; @@ -108,15 +110,22 @@ static void cmd_handler(void *p1, void *p2, void *p3) } else { status = BTP_STATUS_UNKNOWN_CMD; } + /* Allow to delay only 1 command. This is for convenience only + * of using cmd data without need of copying those in async + * functions. Should be not needed eventually. + */ + if (status == BTP_STATUS_DELAY_REPLY) { + __ASSERT_NO_MSG(delayed_cmd == NULL); + delayed_cmd = cmd; + continue; + } - if (status != BTP_STATUS_DELAY_REPLY) { - if ((status == BTP_STATUS_SUCCESS) && rsp_len > 0) { - tester_send_with_index(cmd->hdr.service, cmd->hdr.opcode, - cmd->hdr.index, cmd->rsp, rsp_len); - } else { - tester_rsp_with_index(cmd->hdr.service, cmd->hdr.opcode, - cmd->hdr.index, status); - } + if ((status == BTP_STATUS_SUCCESS) && rsp_len > 0) { + tester_send_with_index(cmd->hdr.service, cmd->hdr.opcode, + cmd->hdr.index, cmd->rsp, rsp_len); + } else { + tester_rsp_with_index(cmd->hdr.service, cmd->hdr.opcode, + cmd->hdr.index, status); } (void)memset(cmd, 0, sizeof(*cmd)); @@ -265,9 +274,32 @@ static void tester_rsp_with_index(uint8_t service, uint8_t opcode, uint8_t index void tester_send(uint8_t service, uint8_t opcode, uint8_t *data, size_t len) { tester_send_with_index(service, opcode, BTP_INDEX, data, len); + + /* async response to command */ + if (opcode < 0x80) { + struct btp_buf *cmd; + + __ASSERT_NO_MSG(delayed_cmd != NULL); + + cmd = delayed_cmd; + delayed_cmd = NULL; + + (void)memset(cmd, 0, sizeof(*cmd)); + k_fifo_put(&avail_queue, cmd); + } } void tester_rsp(uint8_t service, uint8_t opcode, uint8_t status) { + struct btp_buf *cmd; + tester_rsp_with_index(service, opcode, BTP_INDEX, status); + + __ASSERT_NO_MSG(delayed_cmd != NULL); + + cmd = delayed_cmd; + delayed_cmd = NULL; + + (void)memset(cmd, 0, sizeof(*cmd)); + k_fifo_put(&avail_queue, cmd); } From c978a2ae051eef91216341ef328efbd8e8e4ecb5 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 3 Mar 2023 15:59:03 +0100 Subject: [PATCH 0034/1906] bluetooth: tester: Add explicit functions for event and response This make is easier to verify if proper use of BTP is maintained. tester_rsp and tester_rsp_full will be removed eventually when BTP is fully async. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp.c | 37 +++++++++++--------- tests/bluetooth/tester/src/btp/bttester.h | 4 ++- tests/bluetooth/tester/src/btp_gap.c | 39 +++++++++------------ tests/bluetooth/tester/src/btp_gatt.c | 34 +++++++++---------- tests/bluetooth/tester/src/btp_ias.c | 8 ++--- tests/bluetooth/tester/src/btp_l2cap.c | 13 +++---- tests/bluetooth/tester/src/btp_mesh.c | 41 +++++++++-------------- 7 files changed, 79 insertions(+), 97 deletions(-) diff --git a/tests/bluetooth/tester/src/btp.c b/tests/bluetooth/tester/src/btp.c index 4f442dffe869..eab5ed283d83 100644 --- a/tests/bluetooth/tester/src/btp.c +++ b/tests/bluetooth/tester/src/btp.c @@ -51,7 +51,7 @@ static struct { } service_handler[BTP_SERVICE_ID_MAX + 1]; static void tester_send_with_index(uint8_t service, uint8_t opcode, uint8_t index, - uint8_t *data, size_t len); + const uint8_t *data, size_t len); static void tester_rsp_with_index(uint8_t service, uint8_t opcode, uint8_t index, uint8_t status); @@ -174,7 +174,7 @@ static void uart_init(uint8_t *data) uart_pipe_register(data, BTP_MTU, recv_cb); } -static void uart_send(uint8_t *data, size_t len) +static void uart_send(const uint8_t *data, size_t len) { uart_pipe_send(data, len); } @@ -206,7 +206,7 @@ static void uart_init(uint8_t *data) k_timer_start(&timer, K_MSEC(10), K_MSEC(10)); } -static void uart_send(uint8_t *data, size_t len) +static void uart_send(const uint8_t *data, size_t len) { int i; @@ -242,7 +242,7 @@ void tester_init(void) } static void tester_send_with_index(uint8_t service, uint8_t opcode, uint8_t index, - uint8_t *data, size_t len) + const uint8_t *data, size_t len) { struct btp_hdr msg; @@ -271,32 +271,37 @@ static void tester_rsp_with_index(uint8_t service, uint8_t opcode, uint8_t index tester_send_with_index(service, BTP_STATUS, index, (uint8_t *) &s, sizeof(s)); } -void tester_send(uint8_t service, uint8_t opcode, uint8_t *data, size_t len) +void tester_event(uint8_t service, uint8_t opcode, const void *data, size_t len) { + __ASSERT_NO_MSG(opcode >= 0x80); tester_send_with_index(service, opcode, BTP_INDEX, data, len); +} - /* async response to command */ - if (opcode < 0x80) { - struct btp_buf *cmd; +void tester_rsp_full(uint8_t service, uint8_t opcode, const void *rsp, size_t len) +{ + struct btp_buf *cmd; - __ASSERT_NO_MSG(delayed_cmd != NULL); + __ASSERT_NO_MSG(opcode < 0x80); + __ASSERT_NO_MSG(delayed_cmd != NULL); - cmd = delayed_cmd; - delayed_cmd = NULL; + tester_send_with_index(service, opcode, BTP_INDEX, rsp, len); - (void)memset(cmd, 0, sizeof(*cmd)); - k_fifo_put(&avail_queue, cmd); - } + cmd = delayed_cmd; + delayed_cmd = NULL; + + (void)memset(cmd, 0, sizeof(*cmd)); + k_fifo_put(&avail_queue, cmd); } void tester_rsp(uint8_t service, uint8_t opcode, uint8_t status) { struct btp_buf *cmd; - tester_rsp_with_index(service, opcode, BTP_INDEX, status); - + __ASSERT_NO_MSG(opcode < 0x80); __ASSERT_NO_MSG(delayed_cmd != NULL); + tester_rsp_with_index(service, opcode, BTP_INDEX, status); + cmd = delayed_cmd; delayed_cmd = NULL; diff --git a/tests/bluetooth/tester/src/btp/bttester.h b/tests/bluetooth/tester/src/btp/bttester.h index edbd21cedce1..1419a682eb8c 100644 --- a/tests/bluetooth/tester/src/btp/bttester.h +++ b/tests/bluetooth/tester/src/btp/bttester.h @@ -27,8 +27,10 @@ static inline uint8_t tester_test_bit(const uint8_t *addr, unsigned int bit) } void tester_init(void); + void tester_rsp(uint8_t service, uint8_t opcode, uint8_t status); -void tester_send(uint8_t service, uint8_t opcode, uint8_t *data, size_t len); +void tester_rsp_full(uint8_t service, uint8_t opcode, const void *rsp, size_t len); +void tester_event(uint8_t service, uint8_t opcode, const void *data, size_t len); struct btp_handler { uint8_t opcode; diff --git a/tests/bluetooth/tester/src/btp_gap.c b/tests/bluetooth/tester/src/btp_gap.c index 4cd7631c30cd..ab873d3119ef 100644 --- a/tests/bluetooth/tester/src/btp_gap.c +++ b/tests/bluetooth/tester/src/btp_gap.c @@ -109,8 +109,7 @@ static void le_connected(struct bt_conn *conn, uint8_t err) ev.latency = sys_cpu_to_le16(info.le.latency); ev.timeout = sys_cpu_to_le16(info.le.timeout); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_CONNECTED, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_CONNECTED, &ev, sizeof(ev)); } static void le_disconnected(struct bt_conn *conn, uint8_t reason) @@ -120,8 +119,7 @@ static void le_disconnected(struct bt_conn *conn, uint8_t reason) bt_addr_le_copy(&ev.address, addr); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_DISCONNECTED, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_DISCONNECTED, &ev, sizeof(ev)); } static void le_identity_resolved(struct bt_conn *conn, const bt_addr_le_t *rpa, @@ -132,8 +130,7 @@ static void le_identity_resolved(struct bt_conn *conn, const bt_addr_le_t *rpa, bt_addr_le_copy(&ev.address, rpa); bt_addr_le_copy(&ev.identity_address, identity); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_IDENTITY_RESOLVED, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_IDENTITY_RESOLVED, &ev, sizeof(ev)); } static void le_param_updated(struct bt_conn *conn, uint16_t interval, @@ -147,8 +144,7 @@ static void le_param_updated(struct bt_conn *conn, uint16_t interval, ev.latency = sys_cpu_to_le16(latency); ev.timeout = sys_cpu_to_le16(timeout); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_CONN_PARAM_UPDATE, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_CONN_PARAM_UPDATE, &ev, sizeof(ev)); } static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param) @@ -178,8 +174,8 @@ static void le_security_changed(struct bt_conn *conn, bt_security_t level, /* enum matches BTP values */ sec_ev.sec_level = level; - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_SEC_LEVEL_CHANGED, - (uint8_t *) &sec_ev, sizeof(sec_ev)); + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_SEC_LEVEL_CHANGED, + &sec_ev, sizeof(sec_ev)); break; case BT_SECURITY_ERR_PIN_OR_KEY_MISSING: /* for central role this means that peer have no LTK when we @@ -193,8 +189,8 @@ static void le_security_changed(struct bt_conn *conn, bt_security_t level, bt_addr_le_copy(&bond_ev.address, addr); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_BOND_LOST, - (uint8_t *)&bond_ev, sizeof(bond_ev)); + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_BOND_LOST, + &bond_ev, sizeof(bond_ev)); (void)bt_conn_set_security(conn, BT_SECURITY_L2 | BT_SECURITY_FORCE_PAIR); } @@ -777,7 +773,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t evtype, * current one */ if (adv_buf->len) { - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_FOUND, + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_FOUND, adv_buf->data, adv_buf->len); net_buf_simple_reset(adv_buf); } @@ -792,7 +788,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t evtype, return; } done: - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_FOUND, + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_FOUND, adv_buf->data, adv_buf->len); net_buf_simple_reset(adv_buf); } @@ -897,8 +893,7 @@ static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) bt_addr_le_copy(&ev.address, addr); ev.passkey = sys_cpu_to_le32(passkey); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_DISPLAY, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_DISPLAY, &ev, sizeof(ev)); } static void auth_passkey_entry(struct bt_conn *conn) @@ -908,8 +903,7 @@ static void auth_passkey_entry(struct bt_conn *conn) bt_addr_le_copy(&ev.address, addr); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_ENTRY_REQ, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_ENTRY_REQ, &ev, sizeof(ev)); } static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey) @@ -920,8 +914,7 @@ static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey) bt_addr_le_copy(&ev.address, addr); ev.passkey = sys_cpu_to_le32(passkey); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_CONFIRM_REQ, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PASSKEY_CONFIRM_REQ, &ev, sizeof(ev)); } static void auth_cancel(struct bt_conn *conn) @@ -946,8 +939,7 @@ enum bt_security_err auth_pairing_accept(struct bt_conn *conn, bt_addr_le_copy(&ev.address, addr); - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_BOND_LOST, (uint8_t *)&ev, - sizeof(ev)); + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_BOND_LOST, &ev, sizeof(ev)); return BT_SECURITY_ERR_SUCCESS; } @@ -960,8 +952,7 @@ void auth_pairing_failed(struct bt_conn *conn, enum bt_security_err reason) bt_addr_le_copy(&ev.address, addr); ev.reason = reason; - tester_send(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PAIRING_FAILED, - (uint8_t *)&ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_PAIRING_FAILED, &ev, sizeof(ev)); } static void auth_pairing_complete(struct bt_conn *conn, bool bonded) diff --git a/tests/bluetooth/tester/src/btp_gatt.c b/tests/bluetooth/tester/src/btp_gatt.c index 910cd25337ab..fc16426a8343 100644 --- a/tests/bluetooth/tester/src/btp_gatt.c +++ b/tests/bluetooth/tester/src/btp_gatt.c @@ -378,7 +378,7 @@ static void attr_value_changed_ev(uint16_t handle, const uint8_t *value, uint16_ ev->data_length = sys_cpu_to_le16(len); memcpy(ev->data, value, len); - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_EV_ATTR_VALUE_CHANGED, + tester_event(BTP_SERVICE_ID_GATT, BTP_GATT_EV_ATTR_VALUE_CHANGED, buf, sizeof(buf)); } @@ -1039,8 +1039,8 @@ static uint8_t disc_prim_cb(struct bt_conn *conn, uint8_t uuid_length; if (!attr) { - tester_send(BTP_SERVICE_ID_GATT, btp_opcode, - gatt_buf.buf, gatt_buf.len); + tester_rsp_full(BTP_SERVICE_ID_GATT, btp_opcode, + gatt_buf.buf, gatt_buf.len); discover_destroy(params); return BT_GATT_ITER_STOP; } @@ -1166,8 +1166,8 @@ static uint8_t find_included_cb(struct bt_conn *conn, uint8_t uuid_length; if (!attr) { - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_FIND_INCLUDED, - gatt_buf.buf, gatt_buf.len); + tester_rsp_full(BTP_SERVICE_ID_GATT, BTP_GATT_FIND_INCLUDED, + gatt_buf.buf, gatt_buf.len); discover_destroy(params); return BT_GATT_ITER_STOP; } @@ -1245,8 +1245,8 @@ static uint8_t disc_chrc_cb(struct bt_conn *conn, uint8_t uuid_length; if (!attr) { - tester_send(BTP_SERVICE_ID_GATT, btp_opcode, - gatt_buf.buf, gatt_buf.len); + tester_rsp_full(BTP_SERVICE_ID_GATT, btp_opcode, + gatt_buf.buf, gatt_buf.len); discover_destroy(params); return BT_GATT_ITER_STOP; } @@ -1372,8 +1372,8 @@ static uint8_t disc_all_desc_cb(struct bt_conn *conn, uint8_t uuid_length; if (!attr) { - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_DESC, - gatt_buf.buf, gatt_buf.len); + tester_rsp_full(BTP_SERVICE_ID_GATT, BTP_GATT_DISC_ALL_DESC, + gatt_buf.buf, gatt_buf.len); discover_destroy(params); return BT_GATT_ITER_STOP; } @@ -1458,8 +1458,8 @@ static uint8_t read_cb(struct bt_conn *conn, uint8_t err, /* read complete */ if (!data) { - tester_send(BTP_SERVICE_ID_GATT, btp_opcode, - gatt_buf.buf, gatt_buf.len); + tester_rsp_full(BTP_SERVICE_ID_GATT, btp_opcode, + gatt_buf.buf, gatt_buf.len); read_destroy(params); return BT_GATT_ITER_STOP; } @@ -1489,8 +1489,8 @@ static uint8_t read_uuid_cb(struct bt_conn *conn, uint8_t err, /* read complete */ if (!data) { - tester_send(BTP_SERVICE_ID_GATT, btp_opcode, - gatt_buf.buf, gatt_buf.len); + tester_rsp_full(BTP_SERVICE_ID_GATT, btp_opcode, + gatt_buf.buf, gatt_buf.len); read_destroy(params); return BT_GATT_ITER_STOP; @@ -1797,7 +1797,7 @@ static uint8_t write_signed_without_rsp(const void *cmd, uint16_t cmd_len, static void write_rsp(struct bt_conn *conn, uint8_t err, struct bt_gatt_write_params *params) { - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE, &err, sizeof(err)); + tester_rsp_full(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE, &err, sizeof(err)); } static struct bt_gatt_write_params write_params; @@ -1837,7 +1837,7 @@ static uint8_t write_data(const void *cmd, uint16_t cmd_len, static void write_long_rsp(struct bt_conn *conn, uint8_t err, struct bt_gatt_write_params *params) { - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE_LONG, &err, sizeof(err)); + tester_rsp_full(BTP_SERVICE_ID_GATT, BTP_GATT_WRITE_LONG, &err, sizeof(err)); } static uint8_t write_long(const void *cmd, uint16_t cmd_len, @@ -1910,8 +1910,8 @@ static uint8_t notify_func(struct bt_conn *conn, memcpy(ev->data, data, length); bt_addr_le_copy(&ev->address, bt_conn_get_dst(conn)); - tester_send(BTP_SERVICE_ID_GATT, BTP_GATT_EV_NOTIFICATION, - ev_buf, sizeof(*ev) + length); + tester_event(BTP_SERVICE_ID_GATT, BTP_GATT_EV_NOTIFICATION, + ev, sizeof(*ev) + length); return BT_GATT_ITER_CONTINUE; } diff --git a/tests/bluetooth/tester/src/btp_ias.c b/tests/bluetooth/tester/src/btp_ias.c index 5b4a47889865..bf07fe04b214 100644 --- a/tests/bluetooth/tester/src/btp_ias.c +++ b/tests/bluetooth/tester/src/btp_ias.c @@ -29,7 +29,7 @@ static void alert_stop(void) ev.alert_lvl = BT_IAS_ALERT_LVL_NO_ALERT; - tester_send(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, + tester_event(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, (uint8_t *)&ev, sizeof(ev)); } @@ -43,8 +43,7 @@ static void alert_start(void) ev.alert_lvl = BT_IAS_ALERT_LVL_MILD_ALERT; - tester_send(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, - (uint8_t *)&ev.alert_lvl, sizeof(ev)); + tester_event(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, &ev, sizeof(ev)); } static void alert_high_start(void) @@ -57,8 +56,7 @@ static void alert_high_start(void) ev.alert_lvl = BT_IAS_ALERT_LVL_HIGH_ALERT; - tester_send(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, - (uint8_t *)&ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, &ev, sizeof(ev)); } BT_IAS_CB_DEFINE(ias_callbacks) = { diff --git a/tests/bluetooth/tester/src/btp_l2cap.c b/tests/bluetooth/tester/src/btp_l2cap.c index 4004efde236a..d9ccf6d9fe29 100644 --- a/tests/bluetooth/tester/src/btp_l2cap.c +++ b/tests/bluetooth/tester/src/btp_l2cap.c @@ -57,8 +57,8 @@ static int recv_cb(struct bt_l2cap_chan *l2cap_chan, struct net_buf *buf) ev->data_length = sys_cpu_to_le16(buf->len); memcpy(ev->data, buf->data, buf->len); - tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_DATA_RECEIVED, - recv_cb_buf, sizeof(*ev) + buf->len); + tester_event(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_DATA_RECEIVED, + recv_cb_buf, sizeof(*ev) + buf->len); if (chan->hold_credit && !chan->pending_credit) { /* no need for extra ref, as when returning EINPROGRESS user @@ -95,8 +95,7 @@ static void connected_cb(struct bt_l2cap_chan *l2cap_chan) } } - tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_CONNECTED, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_CONNECTED, &ev, sizeof(ev)); } static void disconnected_cb(struct bt_l2cap_chan *l2cap_chan) @@ -130,8 +129,7 @@ static void disconnected_cb(struct bt_l2cap_chan *l2cap_chan) chan->in_use = false; - tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_DISCONNECTED, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_DISCONNECTED, &ev, sizeof(ev)); } #if defined(CONFIG_BT_L2CAP_ECRED) @@ -148,8 +146,7 @@ static void reconfigured_cb(struct bt_l2cap_chan *l2cap_chan) ev.mtu_local = sys_cpu_to_le16(chan->le.rx.mtu); ev.mps_local = sys_cpu_to_le16(chan->le.rx.mps); - tester_send(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_RECONFIGURED, - (uint8_t *)&ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_L2CAP, BTP_L2CAP_EV_RECONFIGURED, &ev, sizeof(ev)); } #endif diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 085685cf5382..948a694ed128 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -325,8 +325,7 @@ static void link_open(bt_mesh_prov_bearer_t bearer) return; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROV_LINK_OPEN, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROV_LINK_OPEN, &ev, sizeof(ev)); } static void link_close(bt_mesh_prov_bearer_t bearer) @@ -348,8 +347,7 @@ static void link_close(bt_mesh_prov_bearer_t bearer) return; } - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROV_LINK_CLOSED, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROV_LINK_CLOSED, &ev, sizeof(ev)); } static int output_number(bt_mesh_output_action_t action, uint32_t number) @@ -361,8 +359,7 @@ static int output_number(bt_mesh_output_action_t action, uint32_t number) ev.action = sys_cpu_to_le16(action); ev.number = sys_cpu_to_le32(number); - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_OUT_NUMBER_ACTION, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_OUT_NUMBER_ACTION, &ev, sizeof(ev)); return 0; } @@ -381,7 +378,7 @@ static int output_string(const char *str) net_buf_simple_add_mem(buf, str, ev->string_len); - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_OUT_STRING_ACTION, + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_OUT_STRING_ACTION, buf->data, buf->len); return 0; @@ -398,8 +395,7 @@ static int input(bt_mesh_input_action_t action, uint8_t size) ev.action = sys_cpu_to_le16(action); ev.size = size; - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_IN_ACTION, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_IN_ACTION, &ev, sizeof(ev)); return 0; } @@ -412,7 +408,7 @@ static void prov_complete(uint16_t net_idx, uint16_t addr) net.local = addr; net.dst = addr; - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROVISIONED, NULL, 0); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROVISIONED, NULL, 0); } static void prov_node_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr, @@ -428,8 +424,7 @@ static void prov_node_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr, ev.num_elems = num_elem; memcpy(&ev.uuid, uuid, sizeof(ev.uuid)); - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROV_NODE_ADDED, - (void *)&ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_PROV_NODE_ADDED, &ev, sizeof(ev)); } static void prov_reset(void) @@ -2878,7 +2873,7 @@ void net_recv_ev(uint8_t ttl, uint8_t ctl, uint16_t src, uint16_t dst, const voi ev->payload_len = payload_len; net_buf_simple_add_mem(&buf, payload, payload_len); - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_NET_RECV, buf.data, buf.len); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_NET_RECV, buf.data, buf.len); } static void model_bound_cb(uint16_t addr, struct bt_mesh_model *model, @@ -2931,13 +2926,12 @@ static void invalid_bearer_cb(uint8_t opcode) LOG_DBG("opcode 0x%02x", opcode); - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_INVALID_BEARER, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_INVALID_BEARER, &ev, sizeof(ev)); } static void incomp_timer_exp_cb(void) { - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_INCOMP_TIMER_EXP, NULL, 0); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_INCOMP_TIMER_EXP, NULL, 0); } static struct bt_test_cb bt_test_cb = { @@ -2959,8 +2953,7 @@ static void friend_established(uint16_t net_idx, uint16_t lpn_addr, lpn_addr, recv_delay, polltimeout); - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_FRND_ESTABLISHED, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_FRND_ESTABLISHED, &ev, sizeof(ev)); } static void friend_terminated(uint16_t net_idx, uint16_t lpn_addr) @@ -2970,8 +2963,7 @@ static void friend_terminated(uint16_t net_idx, uint16_t lpn_addr) LOG_DBG("Friendship (as Friend) lost with LPN " "0x%04x", lpn_addr); - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_FRND_TERMINATED, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_FRND_TERMINATED, &ev, sizeof(ev)); } BT_MESH_FRIEND_CB_DEFINE(friend_cb) = { @@ -2989,8 +2981,7 @@ static void lpn_established(uint16_t net_idx, uint16_t friend_addr, "Friend 0x%04x Queue Size %d Receive Window %d", friend_addr, queue_size, recv_win); - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_LPN_ESTABLISHED, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_LPN_ESTABLISHED, &ev, sizeof(ev)); } static void lpn_terminated(uint16_t net_idx, uint16_t friend_addr) @@ -3000,8 +2991,7 @@ static void lpn_terminated(uint16_t net_idx, uint16_t friend_addr) LOG_DBG("Friendship (as LPN) lost with Friend " "0x%04x", friend_addr); - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_LPN_TERMINATED, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_LPN_TERMINATED, &ev, sizeof(ev)); } static void lpn_polled(uint16_t net_idx, uint16_t friend_addr, bool retry) @@ -3010,8 +3000,7 @@ static void lpn_polled(uint16_t net_idx, uint16_t friend_addr, bool retry) LOG_DBG("LPN polled 0x%04x %s", friend_addr, retry ? "(retry)" : ""); - tester_send(BTP_SERVICE_ID_MESH, BTP_MESH_EV_LPN_POLLED, - (uint8_t *) &ev, sizeof(ev)); + tester_event(BTP_SERVICE_ID_MESH, BTP_MESH_EV_LPN_POLLED, &ev, sizeof(ev)); } BT_MESH_LPN_CB_DEFINE(lpn_cb) = { From 51adfd71721605039528b1f4e0ead74e5e55325f Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 6 Mar 2023 09:05:13 +0100 Subject: [PATCH 0035/1906] bluetooth: tester: Use define for variable length BTP commands This makes code a bit easier to follow. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp/bttester.h | 5 ++++ tests/bluetooth/tester/src/btp_gap.c | 4 +-- tests/bluetooth/tester/src/btp_gatt.c | 30 +++++++++++------------ tests/bluetooth/tester/src/btp_l2cap.c | 4 +-- tests/bluetooth/tester/src/btp_mesh.c | 10 ++++---- tests/bluetooth/tester/src/btp_vcp.c | 4 +-- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/bttester.h b/tests/bluetooth/tester/src/btp/bttester.h index 1419a682eb8c..cf59dda10aab 100644 --- a/tests/bluetooth/tester/src/btp/bttester.h +++ b/tests/bluetooth/tester/src/btp/bttester.h @@ -32,6 +32,11 @@ void tester_rsp(uint8_t service, uint8_t opcode, uint8_t status); void tester_rsp_full(uint8_t service, uint8_t opcode, const void *rsp, size_t len); void tester_event(uint8_t service, uint8_t opcode, const void *data, size_t len); +/* Used to indicate that command length is variable and that validation will + * be done in handler. + */ +#define BTP_HANDLER_LENGTH_VARIABLE (-1) + struct btp_handler { uint8_t opcode; uint8_t index; diff --git a/tests/bluetooth/tester/src/btp_gap.c b/tests/bluetooth/tester/src/btp_gap.c index ab873d3119ef..e37e381440c8 100644 --- a/tests/bluetooth/tester/src/btp_gap.c +++ b/tests/bluetooth/tester/src/btp_gap.c @@ -1239,7 +1239,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_GAP_START_ADVERTISING, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = start_advertising, }, { @@ -1326,7 +1326,7 @@ static const struct btp_handler handlers[] = { #endif /* !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) */ { .opcode = BTP_GAP_SET_FILTER_LIST, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = set_filter_list, }, }; diff --git a/tests/bluetooth/tester/src/btp_gatt.c b/tests/bluetooth/tester/src/btp_gatt.c index fc16426a8343..0bdf8361b0f2 100644 --- a/tests/bluetooth/tester/src/btp_gatt.c +++ b/tests/bluetooth/tester/src/btp_gatt.c @@ -2349,17 +2349,17 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_GATT_ADD_SERVICE, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = add_service, }, { .opcode = BTP_GATT_ADD_CHARACTERISTIC, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = add_characteristic, }, { .opcode = BTP_GATT_ADD_DESCRIPTOR, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = add_descriptor, }, { @@ -2369,7 +2369,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_GATT_SET_VALUE, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = set_value, }, { @@ -2394,7 +2394,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_GATT_DISC_PRIM_UUID, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = disc_prim_uuid, }, { @@ -2409,7 +2409,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_GATT_DISC_CHRC_UUID, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = disc_chrc_uuid, }, { @@ -2424,7 +2424,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_GATT_READ_UUID, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = read_uuid, }, { @@ -2434,27 +2434,27 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_GATT_READ_MULTIPLE, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = read_multiple, }, { .opcode = BTP_GATT_WRITE_WITHOUT_RSP, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = write_without_rsp, }, { .opcode = BTP_GATT_SIGNED_WRITE_WITHOUT_RSP, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = write_signed_without_rsp, }, { .opcode = BTP_GATT_WRITE, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = write_data, }, { .opcode = BTP_GATT_WRITE_LONG, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = write_long, }, { @@ -2469,7 +2469,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_GATT_GET_ATTRIBUTES, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = get_attrs, }, { @@ -2484,12 +2484,12 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_GATT_READ_MULTIPLE_VAR, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = read_multiple_var, }, { .opcode = BTP_GATT_NOTIFY_MULTIPLE, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = notify_mult, }, }; diff --git a/tests/bluetooth/tester/src/btp_l2cap.c b/tests/bluetooth/tester/src/btp_l2cap.c index d9ccf6d9fe29..f57e006b27c5 100644 --- a/tests/bluetooth/tester/src/btp_l2cap.c +++ b/tests/bluetooth/tester/src/btp_l2cap.c @@ -560,7 +560,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_L2CAP_SEND_DATA, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = send_data, }, { @@ -570,7 +570,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_L2CAP_RECONFIGURE, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = reconfigure, }, { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 948a694ed128..d4cd1dbe18cb 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -2479,12 +2479,12 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_MESH_CONFIG_PROVISIONING, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = config_prov, }, { .opcode = BTP_MESH_PROVISION_NODE, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = provision_node, }, { @@ -2504,7 +2504,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_MESH_INPUT_STRING, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = input_string, }, { @@ -2529,7 +2529,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_MESH_NET_SEND, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = net_send, }, { @@ -2544,7 +2544,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_MESH_MODEL_SEND, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = model_send, }, { diff --git a/tests/bluetooth/tester/src/btp_vcp.c b/tests/bluetooth/tester/src/btp_vcp.c index 1b7552318aab..59c3e098f1aa 100644 --- a/tests/bluetooth/tester/src/btp_vcp.c +++ b/tests/bluetooth/tester/src/btp_vcp.c @@ -353,7 +353,7 @@ static const struct btp_handler aics_handlers[] = { }, { .opcode = BTP_AICS_DESCRIPTION, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = aics_desc, }, }; @@ -447,7 +447,7 @@ static const struct btp_handler vocs_handlers[] = { }, { .opcode = BTP_VOCS_UPDATE_DESC, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = vocs_audio_desc, }, { From f19e6d481164420ed758f5c07d879aa75da93eed Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 6 Mar 2023 15:06:14 +0100 Subject: [PATCH 0036/1906] bluetooth: tester: Use one-time advertising in GAP tests This avoids potencial races where PTS is changing type of advertising during tests. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp_gap.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/src/btp_gap.c b/tests/bluetooth/tester/src/btp_gap.c index e37e381440c8..dbd409cd339f 100644 --- a/tests/bluetooth/tester/src/btp_gap.c +++ b/tests/bluetooth/tester/src/btp_gap.c @@ -110,6 +110,14 @@ static void le_connected(struct bt_conn *conn, uint8_t err) ev.timeout = sys_cpu_to_le16(info.le.timeout); tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_DEVICE_CONNECTED, &ev, sizeof(ev)); + + if (info.role == BT_CONN_ROLE_PERIPHERAL) { + struct btp_gap_new_settings_ev ev; + + atomic_clear_bit(¤t_settings, BTP_GAP_SETTINGS_ADVERTISING); + ev.current_settings = sys_cpu_to_le32(current_settings); + tester_event(BTP_SERVICE_ID_GAP, BTP_GAP_EV_NEW_SETTINGS, &ev, sizeof(ev)); + } } static void le_disconnected(struct bt_conn *conn, uint8_t reason) @@ -517,7 +525,7 @@ static uint8_t start_advertising(const void *cmd, uint16_t cmd_len, { const struct btp_gap_start_advertising_cmd *cp = cmd; struct btp_gap_start_advertising_rp *rp = rsp; - struct bt_le_adv_param param = BT_LE_ADV_PARAM_INIT(0, + struct bt_le_adv_param param = BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_ONE_TIME, BT_GAP_ADV_FAST_INT_MIN_2, BT_GAP_ADV_FAST_INT_MAX_2, NULL); From 8a229732dfe35060afa2c9c1dd25e83267ad44af Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Tue, 7 Mar 2023 16:42:07 +0200 Subject: [PATCH 0037/1906] samples: sensor_shell: Fix return code for sensor_shell Fix return code from boolean (probably typo) to int. Signed-off-by: Andrei Emeltchenko --- samples/sensor/sensor_shell/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/sensor/sensor_shell/src/main.c b/samples/sensor/sensor_shell/src/main.c index 4d80f2f296ae..1fe6f415db03 100644 --- a/samples/sensor/sensor_shell/src/main.c +++ b/samples/sensor/sensor_shell/src/main.c @@ -47,7 +47,7 @@ static void data_ready_trigger_handler(const struct device *sensor, continue; } - rc = sensor_channel_get(sensor, i, &value) != 0; + rc = sensor_channel_get(sensor, i, &value); if (rc == -ENOTSUP && stats[i].state == SAMPLE_STATS_STATE_UNINITIALIZED) { /* Stop reading this channel if the driver told us it's not supported. */ stats[i].state = SAMPLE_STATS_STATE_DISABLED; From 79d4107beb41cce38892a890539bc78918caf8f0 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Wed, 1 Mar 2023 09:07:08 -0500 Subject: [PATCH 0038/1906] net: http: define http service and resource iterable sections Provide a means of declaring zero or more HTTP services, each with zero or more static HTTP resources. Static HTTP resources are those which have fixed paths[1] which are known prior to system initialization. Some examples of static http resources would be * a forwarder from '/' to '/index.html' * a REST endpoint with fixed path '/api/foo' and detail pointing at some implementation-specific function * a Javascript file in string form with fixed path '/js/util.js' * a 'construction' image with path '/res/work.png' * a gzip-compressed 'Hello' HTML file at '/hello.html' Without describing in any detail how static HTTP resources are organized or served by any given HTTP server, we can describe what static resources exist on a system in a common way that does not require any optional facilities (e.g. filesystem) and relies only on addressable memory. Additionally, for the purposes of simply allowing others to implement custom HTTP servers in a consistent way, or benchmarking implementations, or having a consistent testsuite to use across multiple implementations, it is helpful to have a common method to declare HTTP services and static resources for Zephyr. [1] https://en.wikipedia.org/wiki/URL Signed-off-by: Chris Friedt --- .../linker/common-rom/common-rom-net.ld | 4 + include/zephyr/net/http/service.h | 166 ++++++++++++++++++ subsys/net/lib/http/Kconfig | 7 + 3 files changed, 177 insertions(+) create mode 100644 include/zephyr/net/http/service.h diff --git a/include/zephyr/linker/common-rom/common-rom-net.ld b/include/zephyr/linker/common-rom/common-rom-net.ld index 7876196d2d9d..a01c94cc21ba 100644 --- a/include/zephyr/linker/common-rom/common-rom-net.ld +++ b/include/zephyr/linker/common-rom/common-rom-net.ld @@ -11,3 +11,7 @@ #if defined(CONFIG_DNS_SD) ITERABLE_SECTION_ROM(dns_sd_rec, 4) #endif + +#if defined(CONFIG_HTTP_SERVER) + ITERABLE_SECTION_ROM(http_service_desc, 4) +#endif diff --git a/include/zephyr/net/http/service.h b/include/zephyr/net/http/service.h new file mode 100644 index 000000000000..49b3085b5bba --- /dev/null +++ b/include/zephyr/net/http/service.h @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2022 Meta + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_NET_HTTP_SERVICE_H_ +#define ZEPHYR_INCLUDE_NET_HTTP_SERVICE_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct http_resource_desc { + const char *resource; + void *detail; +}; + +/** + * @brief Define a static HTTP resource + * + * A static HTTP resource is one that is known prior to system initialization. In contrast, + * dynamic resources may be discovered upon system initialization. Dynamic resources may also be + * inserted, or removed by events originating internally or externally to the system at runtime. + * + * @note The @p _resource is the URL without the associated protocol, host, or URL parameters. E.g. + * the resource for `http://www.foo.com/bar/baz.html#param1=value1` would be `/bar/baz.html`. It + * is often referred to as the "path" of the URL. Every `(service, resource)` pair should be + * unique. The @p _resource must be non-NULL. + * + * @param _name Name of the resource. + * @param _service Name of the associated service. + * @param _resource Pathname-like string identifying the resource. + * @param _detail Implementation-specific detail associated with the resource. + */ +#define HTTP_RESOURCE_DEFINE(_name, _service, _resource, _detail) \ + const STRUCT_SECTION_ITERABLE_ALTERNATE(http_resource_desc_##_service, http_resource_desc, \ + _name) = { \ + .resource = _resource, \ + .detail = (_detail), \ + } + +struct http_service_desc { + const char *host; + uint16_t *port; + void *detail; + size_t concurrent; + size_t backlog; + struct http_resource_desc *res_begin; + struct http_resource_desc *res_end; +}; + +#define __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, _res_begin, \ + _res_end) \ + static const STRUCT_SECTION_ITERABLE(http_service_desc, _name) = { \ + .host = _host, \ + .port = (uint16_t *)(_port), \ + .detail = (void *)(_detail), \ + .concurrent = (_concurrent), \ + .backlog = (_backlog), \ + .res_begin = (_res_begin), \ + .res_end = (_res_end), \ + } + +/** + * @brief Define an HTTP service without static resources. + * + * @note The @p _host parameter must be non-`NULL`. It is used to specify an IP address either in + * IPv4 or IPv6 format a fully-qualified hostname or a virtual host. + * + * @note The @p _port parameter must be non-`NULL`. It points to a location that specifies the port + * number to use for the service. If the specified port number is zero, then an ephemeral port + * number will be used and the actual port number assigned will be written back to memory. For + * ephemeral port numbers, the memory pointed to by @p _port must be writeable. + * + * @param _name Name of the service. + * @param _host IP address or hostname associated with the service. + * @param[inout] _port Pointer to port associated with the service. + * @param _concurrent Maximum number of concurrent clients. + * @param _backlog Maximum number queued connections. + * @param _detail Implementation-specific detail associated with the service. + */ +#define HTTP_SERVICE_DEFINE_EMPTY(_name, _host, _port, _concurrent, _backlog, _detail) \ + __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, NULL, NULL) + +/** + * @brief Define an HTTP service with static resources. + * + * @note The @p _host parameter must be non-`NULL`. It is used to specify an IP address either in + * IPv4 or IPv6 format a fully-qualified hostname or a virtual host. + * + * @note The @p _port parameter must be non-`NULL`. It points to a location that specifies the port + * number to use for the service. If the specified port number is zero, then an ephemeral port + * number will be used and the actual port number assigned will be written back to memory. For + * ephemeral port numbers, the memory pointed to by @p _port must be writeable. + * + * @param _name Name of the service. + * @param _host IP address or hostname associated with the service. + * @param[inout] _port Pointer to port associated with the service. + * @param _concurrent Maximum number of concurrent clients. + * @param _backlog Maximum number queued connections. + * @param _detail Implementation-specific detail associated with the service. + */ +#define HTTP_SERVICE_DEFINE(_name, _host, _port, _concurrent, _backlog, _detail) \ + extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_start)[]; \ + extern struct http_resource_desc _CONCAT(_http_resource_desc_##_name, _list_end)[]; \ + __z_http_service_define(_name, _host, _port, _concurrent, _backlog, _detail, \ + &_CONCAT(_http_resource_desc_##_name, _list_start)[0], \ + &_CONCAT(_http_resource_desc_##_name, _list_end)[0]) + +/** + * @brief Count the number of HTTP services. + * + * @param[out] _dst Pointer to location where result is written. + */ +#define HTTP_SERVICE_COUNT(_dst) STRUCT_SECTION_COUNT(http_service_desc, _dst) + +/** + * @brief Count HTTP service static resources. + * + * @param _service Pointer to a service. + */ +#define HTTP_SERVICE_RESOURCE_COUNT(_service) ((_service)->res_end - (_service)->res_begin) + +/** + * @brief Iterate over all HTTP services. + * + * @param _it Name of iterator (of type @ref http_service_desc) + */ +#define HTTP_SERVICE_FOREACH(_it) STRUCT_SECTION_FOREACH(http_service_desc, _it) + +/** + * @brief Iterate over static HTTP reesources associated with a given @p _service. + * + * @note This macro requires that @p _service is defined with @ref HTTP_SERVICE_DEFINE. + * + * @param _service Name of HTTP service + * @param _it Name of iterator (of type @ref http_resource_desc) + */ +#define HTTP_RESOURCE_FOREACH(_service, _it) \ + STRUCT_SECTION_FOREACH_ALTERNATE(http_resource_desc_##_service, http_resource_desc, _it) + +/** + * @brief Iterate over all static resources associated with @p _service . + * + * @note This macro is suitable for a @p _service defined with either @ref HTTP_SERVICE_DEFINE + * or @ref HTTP_SERVICE_DEFINE_EMPTY. + * + * @param _service Pointer to HTTP service + * @param _it Name of iterator (of type @ref http_resource_desc) + */ +#define HTTP_SERVICE_FOREACH_RESOURCE(_service, _it) \ + for (struct http_resource_desc *_it = (_service)->res_begin; ({ \ + __ASSERT(_it <= (_service)->res_end, "unexpected list end location"); \ + _it < (_service)->res_end; \ + }); \ + _it++) + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_NET_HTTP_SERVICE_H_ */ diff --git a/subsys/net/lib/http/Kconfig b/subsys/net/lib/http/Kconfig index e21f0340d8bd..789e45827c33 100644 --- a/subsys/net/lib/http/Kconfig +++ b/subsys/net/lib/http/Kconfig @@ -30,6 +30,13 @@ config HTTP_CLIENT help HTTP client API +config HTTP_SERVER + bool "HTTP Server [EXPERIMENTAL]" + select WARN_EXPERIMENTAL + help + HTTP server support. + Note: this is a work-in-progress + module = NET_HTTP module-dep = NET_LOG module-str = Log level for HTTP client library From 7b364c7f9a53caaa3448b2196d08e90398fde17f Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Wed, 1 Mar 2023 13:23:13 -0500 Subject: [PATCH 0039/1906] tests: net: http_service: verify service and resource macros Add tests to verify the newly-added HTTP service and resource macros. Signed-off-by: Chris Friedt --- .../net/lib/http_server/common/CMakeLists.txt | 10 + tests/net/lib/http_server/common/prj.conf | 10 + .../lib/http_server/common/sections-rom.ld | 2 + tests/net/lib/http_server/common/src/main.c | 249 ++++++++++++++++++ .../net/lib/http_server/common/testcase.yaml | 8 + 5 files changed, 279 insertions(+) create mode 100644 tests/net/lib/http_server/common/CMakeLists.txt create mode 100644 tests/net/lib/http_server/common/prj.conf create mode 100644 tests/net/lib/http_server/common/sections-rom.ld create mode 100644 tests/net/lib/http_server/common/src/main.c create mode 100644 tests/net/lib/http_server/common/testcase.yaml diff --git a/tests/net/lib/http_server/common/CMakeLists.txt b/tests/net/lib/http_server/common/CMakeLists.txt new file mode 100644 index 000000000000..92b8593eab4c --- /dev/null +++ b/tests/net/lib/http_server/common/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(http_service_defines) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) + +zephyr_linker_sources(SECTIONS sections-rom.ld) diff --git a/tests/net/lib/http_server/common/prj.conf b/tests/net/lib/http_server/common/prj.conf new file mode 100644 index 000000000000..4422a170d581 --- /dev/null +++ b/tests/net/lib/http_server/common/prj.conf @@ -0,0 +1,10 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y + +CONFIG_NETWORKING=y +CONFIG_NET_TEST=y +CONFIG_ENTROPY_GENERATOR=y +CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_ZTEST_STACK_SIZE=1024 + +CONFIG_HTTP_SERVER=y diff --git a/tests/net/lib/http_server/common/sections-rom.ld b/tests/net/lib/http_server/common/sections-rom.ld new file mode 100644 index 000000000000..893e9bd8c96e --- /dev/null +++ b/tests/net/lib/http_server/common/sections-rom.ld @@ -0,0 +1,2 @@ +ITERABLE_SECTION_ROM(http_resource_desc_service_A, 4) +ITERABLE_SECTION_ROM(http_resource_desc_service_B, 4) diff --git a/tests/net/lib/http_server/common/src/main.c b/tests/net/lib/http_server/common/src/main.c new file mode 100644 index 000000000000..c0aee694c84e --- /dev/null +++ b/tests/net/lib/http_server/common/src/main.c @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2023 Meta + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include + +#define DETAIL(n) (void *)((0xde7a11 * 10) + (n)) +#define RES(n) (void *)((0x2e5 * 10) + (n)) + +/* + * Two separate HTTP server instances (A and B), each with different static + * resources, listening on different ports. Static resources could be, for + * example, gzip compressed html, javascript, css, or image files which + * have fixed paths known at build time. + * + * REST endpoints could be considered as static resources, as long as + * the paths (and implementation-specific details) are known at compile time. + */ +static const uint16_t service_A_port = 4242; +HTTP_SERVICE_DEFINE(service_A, "a.service.com", &service_A_port, 4, 2, DETAIL(0)); +HTTP_RESOURCE_DEFINE(resource_0, service_A, "/", RES(0)); +HTTP_RESOURCE_DEFINE(resource_1, service_A, "/index.html", RES(1)); + +/* ephemeral port of 0 */ +static uint16_t service_B_port; +HTTP_SERVICE_DEFINE(service_B, "b.service.com", &service_B_port, 7, 3, DETAIL(1)); +HTTP_RESOURCE_DEFINE(resource_2, service_B, "/foo.htm", RES(2)); +HTTP_RESOURCE_DEFINE(resource_3, service_B, "/bar/baz.php", RES(3)); + +/* + * An "empty" HTTP service is one without static resources. For example, a + * service which loads resources from a filesystem that are determined at + * runtime. + */ +static const uint16_t service_C_port = 5959; +HTTP_SERVICE_DEFINE_EMPTY(service_C, "192.168.1.1", &service_C_port, 5, 9, DETAIL(2)); + +ZTEST(http_service, test_HTTP_SERVICE_DEFINE) +{ + zassert_ok(strcmp(service_A.host, "a.service.com")); + zassert_equal(service_A.port, &service_A_port); + zassert_equal(*service_A.port, 4242); + zassert_equal(service_A.detail, DETAIL(0)); + zassert_equal(service_A.concurrent, 4); + zassert_equal(service_A.backlog, 2); + + zassert_ok(strcmp(service_B.host, "b.service.com")); + zassert_equal(service_B.port, &service_B_port); + zassert_equal(*service_B.port, 0); + zassert_equal(service_B.detail, DETAIL(1)); + zassert_equal(service_B.concurrent, 7); + zassert_equal(service_B.backlog, 3); + + zassert_ok(strcmp(service_C.host, "192.168.1.1")); + zassert_equal(service_C.port, &service_C_port); + zassert_equal(*service_C.port, 5959); + zassert_equal(service_C.detail, DETAIL(2)); + zassert_equal(service_C.concurrent, 5); + zassert_equal(service_C.backlog, 9); + zassert_equal(service_C.res_begin, NULL); + zassert_equal(service_C.res_end, NULL); +} + +ZTEST(http_service, test_HTTP_SERVICE_COUNT) +{ + size_t n_svc; + + n_svc = 4273; + HTTP_SERVICE_COUNT(&n_svc); + zassert_equal(n_svc, 3); +} + +ZTEST(http_service, test_HTTP_SERVICE_RESOURCE_COUNT) +{ + zassert_equal(HTTP_SERVICE_RESOURCE_COUNT(&service_A), 2); + zassert_equal(HTTP_SERVICE_RESOURCE_COUNT(&service_B), 2); + zassert_equal(HTTP_SERVICE_RESOURCE_COUNT(&service_C), 0); +} + +ZTEST(http_service, test_HTTP_SERVICE_FOREACH) +{ + size_t n_svc = 0; + size_t have_service_A = 0; + size_t have_service_B = 0; + size_t have_service_C = 0; + + HTTP_SERVICE_FOREACH(svc) { + if (svc == &service_A) { + have_service_A = 1; + } else if (svc == &service_B) { + have_service_B = 1; + } else if (svc == &service_C) { + have_service_C = 1; + } else { + zassert_unreachable("svc (%p) not equal to &service_A (%p), &service_B " + "(%p), or &service_C (%p)", + svc, &service_A, &service_B, &service_C); + } + + n_svc++; + } + + zassert_equal(n_svc, 3); + zassert_equal(have_service_A + have_service_B + have_service_C, n_svc); +} + +ZTEST(http_service, test_HTTP_RESOURCE_FOREACH) +{ + size_t first_res, second_res, n_res; + + n_res = 0; + first_res = 0; + second_res = 0; + HTTP_RESOURCE_FOREACH(service_A, res) { + if (res == &resource_0) { + first_res = 1; + } else if (res == &resource_1) { + second_res = 1; + } else { + zassert_unreachable( + "res (%p) not equal to &resource_0 (%p) or &resource_1 (%p)", res, + &resource_0, &resource_1); + } + + n_res++; + } + + zassert_equal(n_res, 2); + zassert_equal(first_res + second_res, n_res); + + n_res = 0; + first_res = 0; + second_res = 0; + HTTP_RESOURCE_FOREACH(service_B, res) { + if (res == &resource_2) { + first_res = 1; + } else if (res == &resource_3) { + second_res = 1; + } else { + zassert_unreachable( + "res (%p) not equal to &resource_2 (%p) or &resource_3 (%p)", res, + &resource_2, &resource_3); + } + + n_res++; + } + + zassert_equal(n_res, 2); + zassert_equal(first_res + second_res, n_res); + + n_res = 0; + HTTP_SERVICE_FOREACH_RESOURCE(&service_C, res) { + zassert_unreachable("service_C does not have any resources"); + n_res++; + } + + zassert_equal(n_res, 0); +} + +ZTEST(http_service, test_HTTP_SERVICE_FOREACH_RESOURCE) +{ + size_t first_res, second_res, n_res; + + n_res = 0; + first_res = 0; + second_res = 0; + HTTP_SERVICE_FOREACH_RESOURCE(&service_A, res) { + if (res == &resource_0) { + first_res = 1; + } else if (res == &resource_1) { + second_res = 1; + } else { + zassert_unreachable( + "res (%p) not equal to &resource_0 (%p) or &resource_1 (%p)", res, + &resource_0, &resource_1); + } + + n_res++; + } + + zassert_equal(n_res, 2); + zassert_equal(first_res + second_res, n_res); + + n_res = 0; + first_res = 0; + second_res = 0; + HTTP_SERVICE_FOREACH_RESOURCE(&service_B, res) { + if (res == &resource_2) { + first_res = 1; + } else if (res == &resource_3) { + second_res = 1; + } else { + zassert_unreachable( + "res (%p) not equal to &resource_2 (%p) or &resource_3 (%p)", res, + &resource_2, &resource_3); + } + + n_res++; + } + + zassert_equal(n_res, 2); + zassert_equal(first_res + second_res, n_res); + + n_res = 0; + HTTP_SERVICE_FOREACH_RESOURCE(&service_C, res) { + zassert_unreachable("service_C does not have any resources"); + n_res++; + } + + zassert_equal(n_res, 0); +} + +ZTEST(http_service, test_HTTP_RESOURCE_DEFINE) +{ + HTTP_SERVICE_FOREACH_RESOURCE(&service_A, res) { + if (res == &resource_0) { + zassert_ok(strcmp(res->resource, "/")); + zassert_equal(res->detail, RES(0)); + } else if (res == &resource_1) { + zassert_ok(strcmp(res->resource, "/index.html")); + zassert_equal(res->detail, RES(1)); + } else { + zassert_unreachable( + "res (%p) not equal to &resource_0 (%p) or &resource_1 (%p)", res, + &resource_0, &resource_1); + } + } + + HTTP_SERVICE_FOREACH_RESOURCE(&service_B, res) { + if (res == &resource_2) { + zassert_ok(strcmp(res->resource, "/foo.htm")); + zassert_equal(res->detail, RES(2)); + } else if (res == &resource_3) { + zassert_ok(strcmp(res->resource, "/bar/baz.php")); + zassert_equal(res->detail, RES(3)); + } else { + zassert_unreachable( + "res (%p) not equal to &resource_0 (%p) or &resource_1 (%p)", res, + &resource_0, &resource_1); + } + } +} + +ZTEST_SUITE(http_service, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/net/lib/http_server/common/testcase.yaml b/tests/net/lib/http_server/common/testcase.yaml new file mode 100644 index 000000000000..8e0a75376737 --- /dev/null +++ b/tests/net/lib/http_server/common/testcase.yaml @@ -0,0 +1,8 @@ +common: + min_ram: 16 + tags: net http server + integration_platforms: + - native_posix + +tests: + net.http.server.common: {} From 67c1a6bc20b77e3331b63814b9950e9e3c2402a8 Mon Sep 17 00:00:00 2001 From: Kevin Townsend Date: Mon, 6 Mar 2023 02:33:05 +0100 Subject: [PATCH 0040/1906] modules: tf-m: Fix thread preemption toggling Fixes an issue where thread preemption was not being disabled correctly, failing to taking into account MetaIRQ, which can be used to preempt any cooperative thread. The updated code sets the current thread to `K_HIGHEST_THREAD_PRIO` before calling the secure function, and restores the thread priority level once secure execution has terminated, allowing the thread to be preempted once again. Signed-off-by: Kevin Townsend --- modules/trusted-firmware-m/interface/interface.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/trusted-firmware-m/interface/interface.c b/modules/trusted-firmware-m/interface/interface.c index 9852fafe612a..200e9a9d41a7 100644 --- a/modules/trusted-firmware-m/interface/interface.c +++ b/modules/trusted-firmware-m/interface/interface.c @@ -31,6 +31,7 @@ int32_t tfm_ns_interface_dispatch(veneer_fn fn, { int32_t result; bool is_pre_kernel = k_is_pre_kernel(); + int tfm_ns_saved_prio; if (!is_pre_kernel) { /* TF-M request protected by NS lock */ @@ -41,10 +42,15 @@ int32_t tfm_ns_interface_dispatch(veneer_fn fn, #if !defined(CONFIG_ARM_NONSECURE_PREEMPTIBLE_SECURE_CALLS) /* Prevent the thread from being preempted, while executing a * Secure function. This is required to prevent system crashes - * that could occur, if a thead context switch is triggered in - * the middle of a Secure call. + * that could occur, if a thread context switch is triggered in + * the middle of a Secure call. Note that the code below takes + * into account MetaIRQ, which can preempt cooperative threads + * of any priority. */ - k_sched_lock(); + tfm_ns_saved_prio = k_thread_priority_get(k_current_get()); + k_thread_priority_set(k_current_get(), K_HIGHEST_THREAD_PRIO); +#else + ARG_UNUSED(tfm_ns_saved_prio); #endif } @@ -58,8 +64,8 @@ int32_t tfm_ns_interface_dispatch(veneer_fn fn, if (!is_pre_kernel) { #if !defined(CONFIG_ARM_NONSECURE_PREEMPTIBLE_SECURE_CALLS) - /* Unlock the scheduler, to allow the thread to be preempted. */ - k_sched_unlock(); + /* Restore thread priority, to allow the thread to be preempted. */ + k_thread_priority_set(k_current_get(), tfm_ns_saved_prio); #endif k_mutex_unlock(&tfm_mutex); From ce4a8097511d7bad521819854abee3db4b0c2d27 Mon Sep 17 00:00:00 2001 From: Ajay Parida Date: Mon, 6 Mar 2023 17:14:20 +0530 Subject: [PATCH 0041/1906] net: wifi_mgmt: Updated TWT setup response status Display message updated for TWT setup response. Signed-off-by: Ajay Parida --- subsys/net/l2/wifi/wifi_shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 5c1388eed3e3..e5f6785e26f9 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -160,7 +160,7 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) /* If accepted, then no need to print TWT params */ if (resp->setup_cmd != WIFI_TWT_SETUP_CMD_ACCEPT) { print(context.sh, SHELL_NORMAL, - "TWT parameters: trigger: %s wake_interval_ms: %d, interval_ms: %d\n", + "TWT parameters: trigger: %s wake_interval: %d ms, interval: %d ms\n", resp->setup.trigger ? "trigger" : "no_trigger", resp->setup.twt_wake_interval_ms, resp->setup.twt_interval_ms); From b3b2f28270c3d140bce069eb336c2d8f8eb86107 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Wed, 8 Mar 2023 09:52:28 +0000 Subject: [PATCH 0042/1906] CODEOWNERS: Add self to sysbuild Add myself to sysbuild entry and adds additional folders. Signed-off-by: Jamie McCrae --- CODEOWNERS | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index d7fcfa31967c..a8e818d98273 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -211,6 +211,7 @@ /doc/_scripts/ @carlescufi /doc/connectivity/bluetooth/ @alwa-nordic @jhedberg @Vudentz /doc/build/dts/ @galak @mbolivar-nordic +/doc/build/sysbuild/ @tejlmand @nordicjm /doc/hardware/peripherals/canbus/ @alexanderwachter @henrikbrixandersen /doc/security/ @ceolin @d3zd3z /drivers/debug/ @nashif @@ -685,6 +686,7 @@ /kernel/device.c @andyross @nashif /kernel/idle.c @andyross @nashif /samples/ @nashif +/samples/application_development/sysbuild/ @tejlmand @nordicjm /samples/basic/minimal/ @carlescufi /samples/basic/servo_motor/boards/*microbit* @jhe /samples/bluetooth/ @jhedberg @Vudentz @alwa-nordic @sjanc @@ -761,7 +763,7 @@ scripts/build/gen_image_info.py @tejlmand /scripts/build/uf2conv.py @petejohanson /scripts/build/user_wordsize.py @cfriedt /scripts/valgrind.supp @aescolar @daor-oti -/share/sysbuild/ @tejlmand +/share/sysbuild/ @tejlmand @nordicjm /share/zephyr-package/ @tejlmand /share/zephyrunittest-package/ @tejlmand /subsys/bluetooth/ @alwa-nordic @jhedberg @Vudentz From ef7a9af7e3672b0c7c343d6c08559a410b42341c Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Wed, 8 Mar 2023 09:53:11 +0000 Subject: [PATCH 0043/1906] MAINTAINERS: Add sysbuild entry Adds a sysbuild maintainers entry. Signed-off-by: Jamie McCrae --- MAINTAINERS.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index 4dfb67e09f93..c03854962629 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -2362,6 +2362,19 @@ Storage: labels: - "area: Storage" +Sysbuild: + status: maintained + maintainers: + - tejlmand + collaborators: + - nordicjm + files: + - share/sysbuild/ + - samples/application_development/sysbuild/ + - doc/build/sysbuild/ + labels: + - "area: Sysbuild" + Task Watchdog: status: maintained maintainers: From 0a1a5f8ab8c58496b2201cc323c4a4b7c8cd9886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Wed, 8 Mar 2023 10:36:27 -0800 Subject: [PATCH 0044/1906] cmake: modules: west: allow custom MIN_WEST_VERSION MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Different users of the Zephyr CMake package may have different minimum required versions of west. One important in-tree example is the documentation, which must either be built with the latest version of west, or with no west installed at all. Make the MIN_WEST_VERSION variable configurable to support use cases like this. Signed-off-by: Martí Bolívar --- cmake/modules/west.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/west.cmake b/cmake/modules/west.cmake index c3e40e76791a..89d836e71819 100644 --- a/cmake/modules/west.cmake +++ b/cmake/modules/west.cmake @@ -62,7 +62,7 @@ else() # We can import west from PYTHON_EXECUTABLE and have its version. # Make sure its version matches the minimum required one. - set(MIN_WEST_VERSION 0.7.1) + set_ifndef(MIN_WEST_VERSION 0.7.1) if(${west_version} VERSION_LESS ${MIN_WEST_VERSION}) message(FATAL_ERROR "The detected west version, ${west_version}, is unsupported.\n\ The minimum supported version is ${MIN_WEST_VERSION}.\n\ From 523de0d9be8020b305d86c7b3cabf07c5342841d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Wed, 8 Mar 2023 10:37:34 -0800 Subject: [PATCH 0045/1906] doc: set MIN_WEST_VERSION to 1.0.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If west is installed, we have to build the Zephyr documentation with a recent version of west. This is because the west API documentation is part of the Zephyr documentation, and the west API documentation contains Sphinx autodoc directives which pull API documentation out of the west source code itself. This is similar to how we pull Doxygen comments out of the Zephyr API headers using breathe. (If west is not installed, we don't build the west API docs, so you can uninstall west if you don't want this.) The current API docs require west v1.0.0 or later to build, since that version of west introduced new APIs and documentation for them not available in prior versions. Signed-off-by: Martí Bolívar --- doc/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 6b55729ffbd4..7c03af46d8c0 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.20.0) project(Zephyr-Kernel-Doc LANGUAGES) +set(MIN_WEST_VERSION 1.0.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} .. COMPONENTS doc) file(TO_CMAKE_PATH "${ZEPHYR_BASE}" ZEPHYR_BASE) From 430990ee3fd72fe37560d249e6686a7c630b24ca Mon Sep 17 00:00:00 2001 From: Sam Hurst Date: Wed, 8 Mar 2023 07:16:52 -0800 Subject: [PATCH 0046/1906] usb-c: tcpc: Disable Dead Battery after system starts The Dead Battery resistors interfere with port partner detection. So, Dead Battery is disabled after the system starts and sets the Rd or Rp resistors on the CC lines. Tested on b_g474e_dpow1 with JP5 set to USBC. Tested on stm32g081b_eval with JP17 set to D5V. Signed-off-by: Sam Hurst --- drivers/usb_c/tcpc/ucpd_stm32.c | 53 ++++++++++++++++++++++------ drivers/usb_c/tcpc/ucpd_stm32_priv.h | 3 ++ 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/drivers/usb_c/tcpc/ucpd_stm32.c b/drivers/usb_c/tcpc/ucpd_stm32.c index 45c514e7bf81..812ddfaa7a13 100644 --- a/drivers/usb_c/tcpc/ucpd_stm32.c +++ b/drivers/usb_c/tcpc/ucpd_stm32.c @@ -360,6 +360,37 @@ static int ucpd_get_rp_value(const struct device *dev, enum tc_rp_value *rp) return 0; } +/** + * @brief Enable or disable Dead Battery resistors + */ +static void dead_battery(const struct device *dev, bool en) +{ + struct tcpc_data *data = dev->data; + +#ifdef CONFIG_SOC_SERIES_STM32G0X + const struct tcpc_config *const config = dev->config; + uint32_t cr; + + cr = LL_UCPD_ReadReg(config->ucpd_port, CR); + + if (en) { + cr |= UCPD_CR_DBATTEN; + } else { + cr &= ~UCPD_CR_DBATTEN; + } + + LL_UCPD_WriteReg(config->ucpd_port, CR, cr); + update_stm32g0x_cc_line(config->ucpd_port); +#else + if (en) { + CLEAR_BIT(PWR->CR3, PWR_CR3_UCPD_DBDIS); + } else { + SET_BIT(PWR->CR3, PWR_CR3_UCPD_DBDIS); + } +#endif + data->dead_battery_active = en; +} + /** * @brief Set the CC pull up or pull down resistors * @@ -373,6 +404,11 @@ static int ucpd_set_cc(const struct device *dev, struct tcpc_data *data = dev->data; uint32_t cr; + /* Disable dead battery if it's active */ + if (data->dead_battery_active) { + dead_battery(dev, false); + } + cr = LL_UCPD_ReadReg(config->ucpd_port, CR); /* @@ -1384,16 +1420,13 @@ static int ucpd_init(const struct device *dev) /* Enable Dead Battery Support */ if (config->ucpd_dead_battery) { -#ifdef CONFIG_SOC_SERIES_STM32G0X - uint32_t cr; - - cr = LL_UCPD_ReadReg(config->ucpd_port, CR); - cr |= UCPD_CR_DBATTEN; - LL_UCPD_WriteReg(config->ucpd_port, CR, cr); - update_stm32g0x_cc_line(config->ucpd_port); -#else - CLEAR_BIT(PWR->CR3, PWR_CR3_UCPD_DBDIS); -#endif + dead_battery(dev, true); + } else { + /* + * Some devices have dead battery enabled by default + * after power up, so disable it + */ + dead_battery(dev, false); } /* Initialize the isr */ diff --git a/drivers/usb_c/tcpc/ucpd_stm32_priv.h b/drivers/usb_c/tcpc/ucpd_stm32_priv.h index 727524c15195..67eda58a0002 100644 --- a/drivers/usb_c/tcpc/ucpd_stm32_priv.h +++ b/drivers/usb_c/tcpc/ucpd_stm32_priv.h @@ -322,6 +322,9 @@ struct tcpc_data { /* Track CC line that VCONN was active on */ enum tc_cc_polarity ucpd_vconn_cc; + /* Dead Battery active */ + bool dead_battery_active; + /* Timer for amount of time to wait for receiving a GoodCRC */ struct k_timer goodcrc_rx_timer; }; From c3b6ad07c1650adba56daa2566c031cfbcce2248 Mon Sep 17 00:00:00 2001 From: Jeppe Odgaard Date: Wed, 8 Mar 2023 09:18:59 +0100 Subject: [PATCH 0047/1906] drivers: uart: mcux_lpuart: add parity support Read and use device tree parity value. If the property is not set parity none is used. Signed-off-by: Jeppe Odgaard --- drivers/serial/uart_mcux_lpuart.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/serial/uart_mcux_lpuart.c b/drivers/serial/uart_mcux_lpuart.c index 177b73b33dd1..e9dcd337bb73 100644 --- a/drivers/serial/uart_mcux_lpuart.c +++ b/drivers/serial/uart_mcux_lpuart.c @@ -43,6 +43,7 @@ struct mcux_lpuart_config { clock_control_subsys_t clock_subsys; uint32_t baud_rate; uint8_t flow_ctrl; + uint8_t parity; bool rs485_de_active_low; bool loopback_en; #ifdef CONFIG_UART_MCUX_LPUART_ISR_SUPPORT @@ -1048,7 +1049,7 @@ static int mcux_lpuart_init(const struct device *dev) #endif uart_api_config->baudrate = config->baud_rate; - uart_api_config->parity = UART_CFG_PARITY_NONE; + uart_api_config->parity = config->parity; uart_api_config->stop_bits = UART_CFG_STOP_BITS_1; uart_api_config->data_bits = UART_CFG_DATA_BITS_8; uart_api_config->flow_ctrl = config->flow_ctrl; @@ -1207,6 +1208,7 @@ static const struct mcux_lpuart_config mcux_lpuart_##n##_config = { \ .clock_subsys = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name), \ .baud_rate = DT_INST_PROP(n, current_speed), \ .flow_ctrl = FLOW_CONTROL(n), \ + .parity = DT_INST_ENUM_IDX_OR(n, parity, UART_CFG_PARITY_NONE), \ .rs485_de_active_low = DT_INST_PROP(n, nxp_rs485_de_active_low), \ .loopback_en = DT_INST_PROP(n, nxp_loopback), \ PINCTRL_INIT(n) \ From 3cd58c29bf466a7d2a1ca5f8b4428b01ad1dcbda Mon Sep 17 00:00:00 2001 From: Sebastian Arnd Date: Tue, 7 Mar 2023 21:43:05 +0100 Subject: [PATCH 0048/1906] net/lib: mqtt_sn: Fix MQTT-SN IPv6 Support and assertation in Example 1. `zsock_socket()` gets the right packet familiy. 2. `inet_pton()` returns 1 on success. This should address #55193. Signed-off-by: Sebastian Arnd --- samples/net/mqtt_sn_publisher/src/udp.c | 2 +- subsys/net/lib/mqtt_sn/mqtt_sn_transport_udp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/net/mqtt_sn_publisher/src/udp.c b/samples/net/mqtt_sn_publisher/src/udp.c index b460c72c0c1a..fb96e71ae79f 100644 --- a/samples/net/mqtt_sn_publisher/src/udp.c +++ b/samples/net/mqtt_sn_publisher/src/udp.c @@ -116,7 +116,7 @@ static void process_thread(void) gateway.sin_family = AF_INET; gateway.sin_port = htons(CONFIG_NET_SAMPLE_MQTT_SN_GATEWAY_PORT); err = zsock_inet_pton(AF_INET, CONFIG_NET_SAMPLE_MQTT_SN_GATEWAY_IP, &gateway.sin_addr); - __ASSERT(err == 0, "zsock_inet_pton() failed %d", err); + __ASSERT(err == 1, "zsock_inet_pton() failed %d", err); LOG_INF("Waiting for connection..."); LOG_HEXDUMP_DBG(&gateway, sizeof(gateway), "gateway"); diff --git a/subsys/net/lib/mqtt_sn/mqtt_sn_transport_udp.c b/subsys/net/lib/mqtt_sn/mqtt_sn_transport_udp.c index 7f5fb2742ac0..ff63437c9878 100644 --- a/subsys/net/lib/mqtt_sn/mqtt_sn_transport_udp.c +++ b/subsys/net/lib/mqtt_sn/mqtt_sn_transport_udp.c @@ -48,7 +48,7 @@ static int tp_udp_init(struct mqtt_sn_transport *transport) struct mqtt_sn_transport_udp *udp = UDP_TRANSPORT(transport); int err; - udp->sock = zsock_socket(PF_INET, SOCK_DGRAM, 0); + udp->sock = zsock_socket(udp->gwaddr.sa_family, SOCK_DGRAM, 0); if (udp->sock < 0) { return errno; } From d20ab8c6093ade09855aa62126c357ef876b10b3 Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Mon, 6 Mar 2023 14:28:29 -0800 Subject: [PATCH 0049/1906] subsys/pm: Use correct timeout API The z_set_timeout_expiry() function is a wrapper provided in the timeout subsystem that has some corrections for timelicing. But the suspend code doesn't care; by definition there are no active threads that might be timeslicing at the point where the OS is suspending. Use the lower-level timer driver API instead. (z_set_timeout_expiry() is also about to disappear) Signed-off-by: Andy Ross --- subsys/pm/pm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/pm/pm.c b/subsys/pm/pm.c index e5afc76ce32f..e34467f5d280 100644 --- a/subsys/pm/pm.c +++ b/subsys/pm/pm.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -235,7 +236,7 @@ bool pm_system_suspend(int32_t ticks) * We need to set the timer to interrupt a little bit early to * accommodate the time required by the CPU to fully wake up. */ - z_set_timeout_expiry(ticks - + sys_clock_set_timeout(ticks - k_us_to_ticks_ceil32( z_cpus_pm_state[id].exit_latency_us), true); From f3afd5a4c979d1f13da93cca23b4fc8438f89856 Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Mon, 6 Mar 2023 14:31:35 -0800 Subject: [PATCH 0050/1906] kernel/sched: Use kernel timeouts for timeslice expirations Rework the fragile and ad-hoc computation of timeslice expirations into per-CPU struct _timeout objects with regular callbacks. The expiration callbacks themselves simply set a per-cpu flag (they might run on any CPU), which gets checked at the end of the timer ISR on every CPU. This simplifies logic and removes a bunch of code. It also fixes at least three bugs: 1. As @npitre discovered: On SMP, the number of ticks announced on any given CPU is going to be a subset of all expired ticks. This broke the accounting of timeslice ticks, and effectively meant that timeslicing only worked on SMP on systems where one CPU could hog all the announcements, and only on that CPU. 2. The bootstrap path to arm the timer driver after setting the first timeout in an empty list couldn't take into account sys_clock_elapsed() ticks, as it didn't know whether it was being called underneath an existing announce loop. Now this code is no longer responsible for knowing anything about time slicing at all. 3. Also on SMP, there was a case where two CPUs timeslicing simultaneously could stomp on each others' timeouts in z_set_timeout_expiry(), as neither had a way of knowing what the other's state was. CPUs could miss their own expiration and have to wait for the slice expiration on the other CPU. Now, timeouts are global objects with simple expiration times, and there's no need for that function at all. Signed-off-by: Andy Ross --- include/zephyr/kernel_structs.h | 5 --- include/zephyr/timeout_q.h | 2 -- kernel/include/ksched.h | 2 +- kernel/sched.c | 39 +++++++++++------------- kernel/timeout.c | 54 +++------------------------------ 5 files changed, 23 insertions(+), 79 deletions(-) diff --git a/include/zephyr/kernel_structs.h b/include/zephyr/kernel_structs.h index 5a48745ffa68..bb1ee9d61e8c 100644 --- a/include/zephyr/kernel_structs.h +++ b/include/zephyr/kernel_structs.h @@ -119,11 +119,6 @@ struct _cpu { struct k_thread *metairq_preempted; #endif -#ifdef CONFIG_TIMESLICING - /* number of ticks remaining in current time slice */ - int slice_ticks; -#endif - uint8_t id; #if defined(CONFIG_FPU_SHARING) diff --git a/include/zephyr/timeout_q.h b/include/zephyr/timeout_q.h index 3a3cb365c44e..fc930db62d2e 100644 --- a/include/zephyr/timeout_q.h +++ b/include/zephyr/timeout_q.h @@ -56,8 +56,6 @@ static inline int z_abort_thread_timeout(struct k_thread *thread) int32_t z_get_next_timeout_expiry(void); -void z_set_timeout_expiry(int32_t ticks, bool is_idle); - k_ticks_t z_timeout_remaining(const struct _timeout *timeout); #else diff --git a/kernel/include/ksched.h b/kernel/include/ksched.h index fd873c9ef542..56fa7aac8174 100644 --- a/kernel/include/ksched.h +++ b/kernel/include/ksched.h @@ -55,7 +55,7 @@ void z_thread_priority_set(struct k_thread *thread, int prio); bool z_set_prio(struct k_thread *thread, int prio); void *z_get_next_switch_handle(void *interrupted); void idle(void *unused1, void *unused2, void *unused3); -void z_time_slice(int ticks); +void z_time_slice(void); void z_reset_time_slice(struct k_thread *curr); void z_sched_abort(struct k_thread *thread); void z_sched_ipi(void); diff --git a/kernel/sched.c b/kernel/sched.c index b9c326c494de..20d3e2dc860c 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -405,6 +405,8 @@ static void move_thread_to_end_of_prio_q(struct k_thread *thread) static int slice_ticks; static int slice_max_prio; +struct _timeout slice_timeouts[CONFIG_MP_MAX_NUM_CPUS]; +bool slice_expired[CONFIG_MP_MAX_NUM_CPUS]; static inline int slice_time(struct k_thread *curr) { @@ -427,22 +429,28 @@ static inline int slice_time(struct k_thread *curr) static struct k_thread *pending_current; #endif +static void slice_timeout(struct _timeout *t) +{ + int cpu = ARRAY_INDEX(slice_timeouts, t); + + slice_expired[cpu] = true; +} + void z_reset_time_slice(struct k_thread *curr) { - /* Add the elapsed time since the last announced tick to the - * slice count, as we'll see those "expired" ticks arrive in a - * FUTURE z_time_slice() call. - */ + int cpu = _current_cpu->id; + + z_abort_timeout(&slice_timeouts[cpu]); if (slice_time(curr) != 0) { - _current_cpu->slice_ticks = slice_time(curr) + sys_clock_elapsed(); - z_set_timeout_expiry(slice_time(curr), false); + slice_expired[cpu] = false; + z_add_timeout(&slice_timeouts[cpu], slice_timeout, + K_TICKS(slice_time(curr) - 1)); } } void k_sched_time_slice_set(int32_t slice, int prio) { LOCKED(&sched_spinlock) { - _current_cpu->slice_ticks = 0; slice_ticks = k_ms_to_ticks_ceil32(slice); if (IS_ENABLED(CONFIG_TICKLESS_KERNEL) && slice > 0) { /* It's not possible to reliably set a 1-tick @@ -501,15 +509,8 @@ static k_spinlock_key_t slice_expired_locked(k_spinlock_key_t sched_lock_key) } /* Called out of each timer interrupt */ -void z_time_slice(int ticks) -{ - /* Hold sched_spinlock, so that activity on another CPU - * (like a call to k_thread_abort() at just the wrong time) - * won't affect the correctness of the decisions made here. - * Also prevents any nested interrupts from changing - * thread state to avoid similar issues, since this would - * normally run with IRQs enabled. - */ +void z_time_slice(void) +{ k_spinlock_key_t key = k_spin_lock(&sched_spinlock); #ifdef CONFIG_SWAP_NONATOMIC @@ -522,7 +523,7 @@ void z_time_slice(int ticks) #endif if (slice_time(_current) && sliceable(_current)) { - if (ticks >= _current_cpu->slice_ticks) { + if (slice_expired[_current_cpu->id]) { /* Note: this will (if so enabled) internally * drop and reacquire the scheduler lock * around the callback! Don't put anything @@ -530,11 +531,7 @@ void z_time_slice(int ticks) * synchronization. */ key = slice_expired_locked(key); - } else { - _current_cpu->slice_ticks -= ticks; } - } else { - _current_cpu->slice_ticks = 0; } k_spin_unlock(&sched_spinlock, key); } diff --git a/kernel/timeout.c b/kernel/timeout.c index 85244a3df667..f5daf8222596 100644 --- a/kernel/timeout.c +++ b/kernel/timeout.c @@ -77,11 +77,6 @@ static int32_t next_timeout(void) ret = MAX(0, to->dticks - ticks_elapsed); } -#ifdef CONFIG_TIMESLICING - if (_current_cpu->slice_ticks && _current_cpu->slice_ticks < ret) { - ret = _current_cpu->slice_ticks; - } -#endif return ret; } @@ -125,24 +120,7 @@ void z_add_timeout(struct _timeout *to, _timeout_func_t fn, } if (to == first()) { -#if CONFIG_TIMESLICING - /* - * This is not ideal, since it does not - * account the time elapsed since the - * last announcement, and slice_ticks is based - * on that. It means that the time remaining for - * the next announcement can be less than - * slice_ticks. - */ - int32_t next_time = next_timeout(); - - if (next_time == 0 || - _current_cpu->slice_ticks != next_time) { - sys_clock_set_timeout(next_time, false); - } -#else sys_clock_set_timeout(next_timeout(), false); -#endif /* CONFIG_TIMESLICING */ } } } @@ -212,36 +190,8 @@ int32_t z_get_next_timeout_expiry(void) return ret; } -void z_set_timeout_expiry(int32_t ticks, bool is_idle) -{ - LOCKED(&timeout_lock) { - int next_to = next_timeout(); - bool sooner = (next_to == K_TICKS_FOREVER) - || (ticks <= next_to); - bool imminent = next_to <= 1; - - /* Only set new timeouts when they are sooner than - * what we have. Also don't try to set a timeout when - * one is about to expire: drivers have internal logic - * that will bump the timeout to the "next" tick if - * it's not considered to be settable as directed. - * SMP can't use this optimization though: we don't - * know when context switches happen until interrupt - * exit and so can't get the timeslicing clamp folded - * in. - */ - if (!imminent && (sooner || IS_ENABLED(CONFIG_SMP))) { - sys_clock_set_timeout(MIN(ticks, next_to), is_idle); - } - } -} - void sys_clock_announce(int32_t ticks) { -#ifdef CONFIG_TIMESLICING - z_time_slice(ticks); -#endif - k_spinlock_key_t key = k_spin_lock(&timeout_lock); /* We release the lock around the callbacks below, so on SMP @@ -285,6 +235,10 @@ void sys_clock_announce(int32_t ticks) sys_clock_set_timeout(next_timeout(), false); k_spin_unlock(&timeout_lock, key); + +#ifdef CONFIG_TIMESLICING + z_time_slice(); +#endif } int64_t sys_clock_tick_get(void) From c5c3ad95deed4f6dcec963ef3d3bbd687149abba Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Tue, 7 Mar 2023 08:29:31 -0800 Subject: [PATCH 0051/1906] kernel/sched: Close hole with cross-core timeslice expirations Moving timeslice events to timeouts isn't quite enough on SMP, as it's still possible for systems that don't broadcast their timer interrupts to end up handling an expiration for a foreign CPU. There, we need an IPI, and a symmetric call to z_time_slice() (which is itempotent and fast) in the IPI ISR. Signed-off-by: Andy Ross --- kernel/sched.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/kernel/sched.c b/kernel/sched.c index 20d3e2dc860c..4367b0b4dc18 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -401,6 +401,15 @@ static void move_thread_to_end_of_prio_q(struct k_thread *thread) update_cache(thread == _current); } +static void flag_ipi(void) +{ +#if defined(CONFIG_SMP) && defined(CONFIG_SCHED_IPI_SUPPORTED) + if (arch_num_cpus() > 1) { + _kernel.pending_ipi = true; + } +#endif +} + #ifdef CONFIG_TIMESLICING static int slice_ticks; @@ -434,6 +443,14 @@ static void slice_timeout(struct _timeout *t) int cpu = ARRAY_INDEX(slice_timeouts, t); slice_expired[cpu] = true; + + /* We need an IPI if we just handled a timeslice expiration + * for a different CPU. Ideally this would be able to target + * the specific core, but that's not part of the API yet. + */ + if (IS_ENABLED(CONFIG_SMP) && cpu != _current_cpu->id) { + flag_ipi(); + } } void z_reset_time_slice(struct k_thread *curr) @@ -604,15 +621,6 @@ static bool thread_active_elsewhere(struct k_thread *thread) return false; } -static void flag_ipi(void) -{ -#if defined(CONFIG_SMP) && defined(CONFIG_SCHED_IPI_SUPPORTED) - if (arch_num_cpus() > 1) { - _kernel.pending_ipi = true; - } -#endif -} - static void ready_thread(struct k_thread *thread) { #ifdef CONFIG_KERNEL_COHERENCE @@ -1553,6 +1561,12 @@ void z_sched_ipi(void) #ifdef CONFIG_TRACE_SCHED_IPI z_trace_sched_ipi(); #endif + +#ifdef CONFIG_TIMESLICING + if (slice_time(_current) && sliceable(_current)) { + z_time_slice(); + } +#endif } #endif From a2116cde81d0d5f1d7b5f6bd358903e27e823e17 Mon Sep 17 00:00:00 2001 From: Carsten Thuesen Date: Mon, 6 Mar 2023 17:14:21 +0100 Subject: [PATCH 0052/1906] boards: nucleo_f031k6: update CONFIG_ISR_STACK_SIZE The current setting of `CONFIG_ISR_STACK_SIZE=256` in the `nucleo_f031k6_defconfig` for the `nucleo_f031k6` creates a stack overflow in the `ISR0` thread. The stack is simply too small. This can be verified by increasing `CONFIG_ISR_STACK_SIZE=512` and then build some of the sample applications (fx. `samples/basic/blinky` and `samples/helloworld`). As part of the study the `THREAD_ANALYZER` was enabled, to get some insigt to what a proper new stack size for `ISR0` should be. The used config is shown below. ``` CONFIG_THREAD_ANALYZER=y CONFIG_THREAD_ANALYZER_USE_PRINTK=y CONFIG_THREAD_ANALYZER_AUTO=y CONFIG_THREAD_ANALYZER_AUTO_INTERVAL=5 CONFIG_THREAD_ANALYZER_AUTO_STACK_SIZE=540 CONFIG_THREAD_NAME=y CONFIG_THREAD_RUNTIME_STATS=y ``` During the tests the following results were recorded for the `samples/basic/blinky` and `samples/helloworld`. As seen the `ISR0` stack usage is 80% for the two use cases, which leaves a little headroom for other samples and applications. **samples/basic/blinky**: ``` Thread analyze: thread_analyzer : STACK: unused 96 usage 504 / 600 (84 %); CPU: 0 % : Total CPU cycles used: 12472939 idle : STACK: unused 104 usage 48 / 152 (31 %); CPU: 99 % : Total CPU cycles used: 1679934713 main : STACK: unused 284 usage 228 / 512 (44 %); CPU: 0 % : Total CPU cycles used: 274737 ISR0 : STACK: unused 100 usage 412 / 512 (80 %) ``` **samples/helloworld**: ``` Thread analyze: thread_analyzer : STACK: unused 40 usage 504 / 544 (92 %); CPU: 0 % : Total CPU cycles used: 2634078 idle : STACK: unused 104 usage 48 / 152 (31 %); CPU: 99 % : Total CPU cycles used: 480004798 ISR0 : STACK: unused 100 usage 412 / 512 (80 %) ``` As part of the test it was also checked if the stack usage of `ISR0` could be lowered by setting `CONFIG_UART_INTERRUPT_DRIVEN=n` in the `nucleo_f031k6_defconfig`. This didn't seem to have any effect on the `ISR0` stack utilization. Signed-off-by: Carsten Thuesen --- boards/arm/nucleo_f031k6/nucleo_f031k6_defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/arm/nucleo_f031k6/nucleo_f031k6_defconfig b/boards/arm/nucleo_f031k6/nucleo_f031k6_defconfig index c2c8d055a904..87cb9a811488 100644 --- a/boards/arm/nucleo_f031k6/nucleo_f031k6_defconfig +++ b/boards/arm/nucleo_f031k6/nucleo_f031k6_defconfig @@ -7,7 +7,7 @@ CONFIG_SOC_STM32F031X6=y # Kernel Options due to Low Memory (4k) CONFIG_MAIN_STACK_SIZE=512 CONFIG_IDLE_STACK_SIZE=150 -CONFIG_ISR_STACK_SIZE=256 +CONFIG_ISR_STACK_SIZE=512 CONFIG_LOG_BUFFER_SIZE=256 # Prevent Interrupt Vector Table in RAM CONFIG_SRAM_VECTOR_TABLE=n From 7d9da1c68711acc7dcb6915f3c3f1aeb70aced3d Mon Sep 17 00:00:00 2001 From: Aditya Bhutada Date: Fri, 3 Mar 2023 10:20:41 -0800 Subject: [PATCH 0053/1906] drivers: espi: espi_mchp_xec: removed redundant state variables Removed struct variables for storing states: sx, plt_rst, espi_rst. While Sx & espi_rst state variables were totally redundant, plt_rst variable had a use-case to prevent sending multiple callbacks to app. Experimentally proven that use-case was not valid, as plt_rst isr itself gets called only upon rising/falling edge. Removing the condition to check plt_rst's current and previous state, also solves the problem where global reset do not update plt_rst state. Signed-off-by: Aditya Bhutada --- drivers/espi/espi_mchp_xec.c | 22 ++++------------------ drivers/espi/espi_mchp_xec_v2.c | 18 ++++-------------- drivers/espi/espi_mchp_xec_v2.h | 3 --- 3 files changed, 8 insertions(+), 35 deletions(-) diff --git a/drivers/espi/espi_mchp_xec.c b/drivers/espi/espi_mchp_xec.c index e0e505f6587a..2474c666ced0 100644 --- a/drivers/espi/espi_mchp_xec.c +++ b/drivers/espi/espi_mchp_xec.c @@ -80,9 +80,6 @@ struct espi_xec_data { struct k_sem tx_lock; struct k_sem rx_lock; struct k_sem flash_lock; - uint8_t plt_rst_asserted; - uint8_t espi_rst_asserted; - uint8_t sx_state; }; struct xec_signal { @@ -853,12 +850,11 @@ static void espi_rst_isr(const struct device *dev) if (rst_sts & MCHP_ESPI_RST_ISTS) { if (rst_sts & MCHP_ESPI_RST_ISTS_PIN_RO_HI) { - data->espi_rst_asserted = 1; + evt.evt_data = 1; } else { - data->espi_rst_asserted = 0; + evt.evt_data = 0; } - evt.evt_data = data->espi_rst_asserted; espi_send_callbacks(&data->callbacks, dev, evt); #ifdef CONFIG_ESPI_OOB_CHANNEL espi_init_oob(dev); @@ -1108,12 +1104,8 @@ static void vw_pltrst_isr(const struct device *dev) setup_espi_io_config(dev, MCHP_ESPI_IOBAR_INIT_DFLT); } - /* PLT_RST will be received several times */ - if (status != data->plt_rst_asserted) { - data->plt_rst_asserted = status; - evt.evt_data = status; - espi_send_callbacks(&data->callbacks, dev, evt); - } + evt.evt_data = status; + espi_send_callbacks(&data->callbacks, dev, evt); } /* Send callbacks if enabled and track eSPI host system state */ @@ -1125,10 +1117,6 @@ static void notify_system_state(const struct device *dev, uint8_t status = 0; espi_xec_receive_vwire(dev, signal, &status); - if (!status) { - data->sx_state = signal; - } - evt.evt_details = signal; evt.evt_data = status; espi_send_callbacks(&data->callbacks, dev, evt); @@ -1488,8 +1476,6 @@ static int espi_xec_init(const struct device *dev) return ret; } - data->plt_rst_asserted = 0; - /* Configure eSPI_PLTRST# to cause nSIO_RESET reset */ PCR_REGS->PWR_RST_CTRL = MCHP_PCR_PR_CTRL_USE_ESPI_PLTRST; ESPI_CAP_REGS->PLTRST_SRC = MCHP_ESPI_PLTRST_SRC_IS_VW; diff --git a/drivers/espi/espi_mchp_xec_v2.c b/drivers/espi/espi_mchp_xec_v2.c index d4e9914cb6f7..3c54086e0ff8 100644 --- a/drivers/espi/espi_mchp_xec_v2.c +++ b/drivers/espi/espi_mchp_xec_v2.c @@ -764,12 +764,11 @@ static void espi_rst_isr(const struct device *dev) if (rst_sts & MCHP_ESPI_RST_ISTS) { if (rst_sts & MCHP_ESPI_RST_ISTS_PIN_RO_HI) { - data->espi_rst_asserted = 1; + evt.evt_data = 1; } else { - data->espi_rst_asserted = 0; + evt.evt_data = 0; } - evt.evt_data = data->espi_rst_asserted; espi_send_callbacks(&data->callbacks, dev, evt); #ifdef CONFIG_ESPI_OOB_CHANNEL espi_init_oob(dev); @@ -1023,10 +1022,6 @@ static void notify_system_state(const struct device *dev, uint8_t status = 0; espi_xec_receive_vwire(dev, signal, &status); - if (!status) { - data->sx_state = signal; - } - evt.evt_details = signal; evt.evt_data = status; espi_send_callbacks(&data->callbacks, dev, evt); @@ -1161,12 +1156,8 @@ static void vw_pltrst_handler(int girq_id, int src, void *user) setup_espi_io_config(dev, MCHP_ESPI_IOBAR_INIT_DFLT); } - /* PLT_RST will be received several times */ - if (status != data->plt_rst_asserted) { - data->plt_rst_asserted = status; - evt.evt_data = status; - espi_send_callbacks(&data->callbacks, dev, evt); - } + evt.evt_data = status; + espi_send_callbacks(&data->callbacks, dev, evt); } const struct espi_vw_isr m2s_vwires_isr[] = { @@ -1330,7 +1321,6 @@ static int espi_xec_init(const struct device *dev) return ret; } - data->plt_rst_asserted = 0; #ifdef ESPI_XEC_V2_DEBUG data->espi_rst_count = 0; #endif diff --git a/drivers/espi/espi_mchp_xec_v2.h b/drivers/espi/espi_mchp_xec_v2.h index 263aacd02f53..dd456525ed08 100644 --- a/drivers/espi/espi_mchp_xec_v2.h +++ b/drivers/espi/espi_mchp_xec_v2.h @@ -53,9 +53,6 @@ struct espi_xec_data { struct k_sem tx_lock; struct k_sem rx_lock; struct k_sem flash_lock; - uint8_t plt_rst_asserted; - uint8_t espi_rst_asserted; - uint8_t sx_state; #ifdef ESPI_XEC_V2_DEBUG uint32_t espi_rst_count; #endif From cf20ff0765abc5a2dbd9c0eb1137cff39b09031f Mon Sep 17 00:00:00 2001 From: Attie Grande Date: Thu, 2 Mar 2023 20:04:47 +0000 Subject: [PATCH 0054/1906] drivers: i2c: sam0: add support for I2C_MSG_RESTART This support was accidentally removed in the re-shuffle in de18f97 Signed-off-by: Attie Grande --- drivers/i2c/i2c_sam0.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c_sam0.c b/drivers/i2c/i2c_sam0.c index c61b0dcb8f41..e1a5b4329169 100644 --- a/drivers/i2c/i2c_sam0.c +++ b/drivers/i2c/i2c_sam0.c @@ -155,7 +155,24 @@ static void i2c_sam0_isr(const struct device *dev) if (status & SERCOM_I2CM_INTFLAG_MB) { if (!data->msg.size) { i2c->INTENCLR.reg = SERCOM_I2CM_INTENCLR_MASK; - i2c->CTRLB.bit.CMD = 3; + + /* + * Decide whether to issue a repeated start, or a stop condition... + * - A repeated start can either be accomplished by writing a 0x1 + * to the CMD field, or by writing to ADDR - which is what this + * driver does in i2c_sam0_transfer(). + * - A stop is accomplished by writing a 0x3 to CMD (below). + * + * This decision is not the same as continue_next, as the value of + * data->msg.size is already zero (not one), and i2c_sam0_transfer() + * is responsible for advancing to the next message, not the ISR. + */ + if ((data->num_msgs <= 1) + || (data->msgs[0].flags & I2C_MSG_STOP) + || !(data->msgs[1].flags & I2C_MSG_RESTART)) { + i2c->CTRLB.bit.CMD = 3; + } + k_sem_give(&data->sem); return; } From a2dccf12830014b3d393ea8dc75a901354f61e5c Mon Sep 17 00:00:00 2001 From: Aastha Grover Date: Wed, 1 Mar 2023 14:27:33 -0500 Subject: [PATCH 0055/1906] kernel: events: fix walking the waitq race condition Fixes race condition for k_event_post_internal() in an SMP environment while walking the waitq. Uses z_sched_waitq_walk() to safely walk the waitq by using a sched_spinlock. It should be noted that since walking the wait queue is an operation of indeterminant length, there exists the possibility that the sched_spinlock (which is a highly used and contended-for lock) may be locked for an indeterminant amount of time. However, it is expected that few threads will be waiting on any given kernel event object, which should ameliorate this risk. Fixes #54317 Signed-off-by: Aastha Grover --- kernel/events.c | 51 +++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/kernel/events.c b/kernel/events.c index 5a23390286e9..38fe25cb4bea 100644 --- a/kernel/events.c +++ b/kernel/events.c @@ -39,6 +39,11 @@ #define K_EVENT_WAIT_RESET 0x02 /* Reset events prior to waiting */ +struct event_walk_data { + struct k_thread *head; + uint32_t events; +}; + void z_impl_k_event_init(struct k_event *event) { event->events = 0; @@ -84,14 +89,35 @@ static bool are_wait_conditions_met(uint32_t desired, uint32_t current, return match != 0; } +static int event_walk_op(struct k_thread *thread, void *data) +{ + unsigned int wait_condition; + struct event_walk_data *event_data = data; + + wait_condition = thread->event_options & K_EVENT_WAIT_MASK; + + if (are_wait_conditions_met(thread->events, event_data->events, + wait_condition)) { + /* + * The wait conditions have been satisfied. Add this + * thread to the list of threads to unpend. + */ + + thread->next_event_link = event_data->head; + event_data->head = thread; + } + + return 0; +} + static void k_event_post_internal(struct k_event *event, uint32_t events, uint32_t events_mask) { k_spinlock_key_t key; struct k_thread *thread; - unsigned int wait_condition; - struct k_thread *head = NULL; + struct event_walk_data data; + data.head = NULL; key = k_spin_lock(&event->lock); SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_event, post, event, events, @@ -100,7 +126,7 @@ static void k_event_post_internal(struct k_event *event, uint32_t events, events = (event->events & ~events_mask) | (events & events_mask); event->events = events; - + data.events = events; /* * Posting an event has the potential to wake multiple pended threads. * It is desirable to unpend all affected threads simultaneously. To @@ -112,23 +138,10 @@ static void k_event_post_internal(struct k_event *event, uint32_t events, * 3. Ready each of the threads in the linked list */ - _WAIT_Q_FOR_EACH(&event->wait_q, thread) { - wait_condition = thread->event_options & K_EVENT_WAIT_MASK; - - if (are_wait_conditions_met(thread->events, events, - wait_condition)) { - /* - * The wait conditions have been satisfied. Add this - * thread to the list of threads to unpend. - */ - - thread->next_event_link = head; - head = thread; - } - } + z_sched_waitq_walk(&event->wait_q, event_walk_op, &data); - if (head != NULL) { - thread = head; + if (data.head != NULL) { + thread = data.head; do { z_unpend_thread(thread); arch_thread_return_value_set(thread, 0); From 55377768988def2b5debb126c4471a1872ced830 Mon Sep 17 00:00:00 2001 From: Aastha Grover Date: Wed, 8 Mar 2023 16:54:12 -0500 Subject: [PATCH 0056/1906] kernel: Add z_sched_wake_thread API This API wakes up a given thread and is also called from z_thread_timeout() Signed-off-by: Aastha Grover --- kernel/include/ksched.h | 12 ++++++++++++ kernel/sched.c | 23 ++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/kernel/include/ksched.h b/kernel/include/ksched.h index 56fa7aac8174..0ec1897a2f3e 100644 --- a/kernel/include/ksched.h +++ b/kernel/include/ksched.h @@ -315,6 +315,18 @@ static ALWAYS_INLINE bool z_is_thread_timeout_expired(struct k_thread *thread) */ bool z_sched_wake(_wait_q_t *wait_q, int swap_retval, void *swap_data); +/** + * Wakes the specified thread. + * + * Given a specific thread, wake it up. This routine assumes that the given + * thread is not on the timeout queue. + * + * @param thread Given thread to wake up. + * @param is_timeout True if called from the timer ISR; false otherwise. + * + */ +void z_sched_wake_thread(struct k_thread *thread, bool is_timeout); + /** * Wake up all threads pending on the provided wait queue * diff --git a/kernel/sched.c b/kernel/sched.c index 4367b0b4dc18..e1a79525bca6 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -799,26 +799,35 @@ ALWAYS_INLINE void z_unpend_thread_no_timeout(struct k_thread *thread) } } -#ifdef CONFIG_SYS_CLOCK_EXISTS -/* Timeout handler for *_thread_timeout() APIs */ -void z_thread_timeout(struct _timeout *timeout) +void z_sched_wake_thread(struct k_thread *thread, bool is_timeout) { - struct k_thread *thread = CONTAINER_OF(timeout, - struct k_thread, base.timeout); - LOCKED(&sched_spinlock) { bool killed = ((thread->base.thread_state & _THREAD_DEAD) || (thread->base.thread_state & _THREAD_ABORTING)); if (!killed) { + /* The thread is not being killed */ if (thread->base.pended_on != NULL) { unpend_thread_no_timeout(thread); } z_mark_thread_as_started(thread); - z_mark_thread_as_not_suspended(thread); + if (is_timeout) { + z_mark_thread_as_not_suspended(thread); + } ready_thread(thread); } } + +} + +#ifdef CONFIG_SYS_CLOCK_EXISTS +/* Timeout handler for *_thread_timeout() APIs */ +void z_thread_timeout(struct _timeout *timeout) +{ + struct k_thread *thread = CONTAINER_OF(timeout, + struct k_thread, base.timeout); + + z_sched_wake_thread(thread, true); } #endif From 877fc3d508208633bfdb9bf0a2ca0779684c0167 Mon Sep 17 00:00:00 2001 From: Aastha Grover Date: Wed, 8 Mar 2023 16:56:31 -0500 Subject: [PATCH 0057/1906] kernel: events: fix waitq timeout race condition Updates events to prevent a timeout from corrupting the list of threads that needs to be waken up. Signed-off-by: Aastha Grover --- include/zephyr/kernel/thread.h | 3 +++ kernel/events.c | 25 +++++++++++++++++-------- kernel/sched.c | 10 ++++++++++ kernel/thread.c | 3 +++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/include/zephyr/kernel/thread.h b/include/zephyr/kernel/thread.h index f84c02d32d4c..6f24413e13d0 100644 --- a/include/zephyr/kernel/thread.h +++ b/include/zephyr/kernel/thread.h @@ -264,6 +264,9 @@ struct k_thread { uint32_t events; uint32_t event_options; + + /** true if timeout should not wake the thread */ + bool no_wake_on_timeout; #endif #if defined(CONFIG_THREAD_MONITOR) diff --git a/kernel/events.c b/kernel/events.c index 38fe25cb4bea..5e71aa57ca65 100644 --- a/kernel/events.c +++ b/kernel/events.c @@ -98,13 +98,22 @@ static int event_walk_op(struct k_thread *thread, void *data) if (are_wait_conditions_met(thread->events, event_data->events, wait_condition)) { + + /* + * Events create a list of threads to wake up. We do + * not want z_thread_timeout to wake these threads; they + * will be woken up by k_event_post_internal once they + * have been processed. + */ + thread->no_wake_on_timeout = true; + /* * The wait conditions have been satisfied. Add this * thread to the list of threads to unpend. */ - thread->next_event_link = event_data->head; event_data->head = thread; + z_abort_timeout(&thread->base.timeout); } return 0; @@ -129,11 +138,10 @@ static void k_event_post_internal(struct k_event *event, uint32_t events, data.events = events; /* * Posting an event has the potential to wake multiple pended threads. - * It is desirable to unpend all affected threads simultaneously. To - * do so, this must be done in three steps as it is unsafe to unpend - * threads from within the _WAIT_Q_FOR_EACH() loop. + * It is desirable to unpend all affected threads simultaneously. This + * is done in three steps: * - * 1. Create a linked list of threads to unpend. + * 1. Walk the waitq and create a linked list of threads to unpend. * 2. Unpend each of the threads in the linked list * 3. Ready each of the threads in the linked list */ @@ -142,12 +150,13 @@ static void k_event_post_internal(struct k_event *event, uint32_t events, if (data.head != NULL) { thread = data.head; + struct k_thread *next; do { - z_unpend_thread(thread); arch_thread_return_value_set(thread, 0); thread->events = events; - z_ready_thread(thread); - thread = thread->next_event_link; + next = thread->next_event_link; + z_sched_wake_thread(thread, false); + thread = next; } while (thread != NULL); } diff --git a/kernel/sched.c b/kernel/sched.c index e1a79525bca6..1abfea2e6794 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -805,6 +805,16 @@ void z_sched_wake_thread(struct k_thread *thread, bool is_timeout) bool killed = ((thread->base.thread_state & _THREAD_DEAD) || (thread->base.thread_state & _THREAD_ABORTING)); +#ifdef CONFIG_EVENTS + bool do_nothing = thread->no_wake_on_timeout && is_timeout; + + thread->no_wake_on_timeout = false; + + if (do_nothing) { + continue; + } +#endif + if (!killed) { /* The thread is not being killed */ if (thread->base.pended_on != NULL) { diff --git a/kernel/thread.c b/kernel/thread.c index 2c94554fbfcd..277b8eb46420 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -578,6 +578,9 @@ char *z_setup_new_thread(struct k_thread *new_thread, /* Initialize custom data field (value is opaque to kernel) */ new_thread->custom_data = NULL; #endif +#ifdef CONFIG_EVENTS + new_thread->no_wake_on_timeout = false; +#endif #ifdef CONFIG_THREAD_MONITOR new_thread->entry.pEntry = entry; new_thread->entry.parameter1 = p1; From 8cc716792ac5aaadd9c4601607abda4504e7044c Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 20 Feb 2023 09:36:50 +0000 Subject: [PATCH 0058/1906] cmake: zephyr_module: Rename internal variables to lower case Rename internals variables to lower case to distinguish those variables from variables intended to be globally available. Signed-off-by: Torsten Rasmussen Signed-off-by: Jamie McCrae --- cmake/modules/zephyr_module.cmake | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cmake/modules/zephyr_module.cmake b/cmake/modules/zephyr_module.cmake index 6d36972264e4..83d3712c76e4 100644 --- a/cmake/modules/zephyr_module.cmake +++ b/cmake/modules/zephyr_module.cmake @@ -42,11 +42,11 @@ if(ZEPHYR_EXTRA_MODULES) endif() file(MAKE_DIRECTORY ${KCONFIG_BINARY_DIR}) -set(KCONFIG_MODULES_FILE ${KCONFIG_BINARY_DIR}/Kconfig.modules) -set(ZEPHYR_SETTINGS_FILE ${CMAKE_BINARY_DIR}/zephyr_settings.txt) +set(kconfig_modules_file ${KCONFIG_BINARY_DIR}/Kconfig.modules) +set(zephyr_settings_file ${CMAKE_BINARY_DIR}/zephyr_settings.txt) if(WEST) - set(WEST_ARG "--zephyr-base" ${ZEPHYR_BASE}) + set(west_arg "--zephyr-base" ${ZEPHYR_BASE}) endif() if(WEST OR ZEPHYR_MODULES) @@ -55,12 +55,12 @@ if(WEST OR ZEPHYR_MODULES) execute_process( COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/zephyr_module.py - ${WEST_ARG} + ${west_arg} ${ZEPHYR_MODULES_ARG} ${ZEPHYR_EXTRA_MODULES_ARG} - --kconfig-out ${KCONFIG_MODULES_FILE} + --kconfig-out ${kconfig_modules_file} --cmake-out ${CMAKE_BINARY_DIR}/zephyr_modules.txt - --settings-out ${ZEPHYR_SETTINGS_FILE} + --settings-out ${zephyr_settings_file} WORKING_DIRECTORY ${ZEPHYR_BASE} ERROR_VARIABLE zephyr_module_error_text @@ -72,9 +72,9 @@ if(WEST OR ZEPHYR_MODULES) message(FATAL_ERROR "${zephyr_module_error_text}") endif() - if(EXISTS ${ZEPHYR_SETTINGS_FILE}) - file(STRINGS ${ZEPHYR_SETTINGS_FILE} ZEPHYR_SETTINGS_TXT ENCODING UTF-8 REGEX "^[^#]") - foreach(setting ${ZEPHYR_SETTINGS_TXT}) + if(EXISTS ${zephyr_settings_file}) + file(STRINGS ${zephyr_settings_file} zephyr_settings_txt ENCODING UTF-8 REGEX "^[^#]") + foreach(setting ${zephyr_settings_txt}) # Match : for each line of file, each corresponding to # a setting. The use of quotes is required due to CMake not supporting # lazy regexes (it supports greedy only). @@ -88,11 +88,11 @@ if(WEST OR ZEPHYR_MODULES) list(APPEND MODULE_EXT_ROOT ${ZEPHYR_BASE}) if(EXISTS ${CMAKE_BINARY_DIR}/zephyr_modules.txt) - file(STRINGS ${CMAKE_BINARY_DIR}/zephyr_modules.txt ZEPHYR_MODULES_TXT + file(STRINGS ${CMAKE_BINARY_DIR}/zephyr_modules.txt zephyr_modules_txt ENCODING UTF-8) set(ZEPHYR_MODULE_NAMES) - foreach(module ${ZEPHYR_MODULES_TXT}) + foreach(module ${zephyr_modules_txt}) # Match "":"" for each line of file, each corresponding to # one module. The use of quotes is required due to CMake not supporting # lazy regexes (it supports greedy only). @@ -112,8 +112,8 @@ if(WEST OR ZEPHYR_MODULES) include(${root}/modules/modules.cmake) endforeach() - if(DEFINED ZEPHYR_MODULES_TXT) - foreach(module ${ZEPHYR_MODULES_TXT}) + if(DEFINED zephyr_modules_txt) + foreach(module ${zephyr_modules_txt}) # Match "":"" for each line of file, each corresponding to # one Zephyr module. The use of quotes is required due to CMake not # supporting lazy regexes (it supports greedy only). @@ -135,7 +135,7 @@ ${MODULE_NAME_UPPER} is a restricted name for Zephyr modules as it is used for \ endif() else() - file(WRITE ${KCONFIG_MODULES_FILE} + file(WRITE ${kconfig_modules_file} "# No west and no Zephyr modules\n" ) From 631fa636100b9605dfbc9bfb1968fdfae656ddd4 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 20 Feb 2023 09:55:14 +0000 Subject: [PATCH 0059/1906] sysbuild: split running of CMake from ExternalZephyrProject_add() Split running CMake from ExternalZephyrProject_add(). This will allow systems to define all Zephyr projects and then at later stages run the CMake configure stage. This makes it both cleaner when CMake is invoked as well as prepare for future work where images could be depending on CMake outcome from other projects. Signed-off-by: Torsten Rasmussen Signed-off-by: Jamie McCrae --- share/sysbuild/CMakeLists.txt | 3 + .../cmake/modules/sysbuild_extensions.cmake | 193 ++++++++++++------ 2 files changed, 128 insertions(+), 68 deletions(-) diff --git a/share/sysbuild/CMakeLists.txt b/share/sysbuild/CMakeLists.txt index f939e73cafe7..f0ee3763186c 100644 --- a/share/sysbuild/CMakeLists.txt +++ b/share/sysbuild/CMakeLists.txt @@ -91,4 +91,7 @@ while(NOT "${images_length}" EQUAL "${processed_length}") set(processed_length ${processed_length_new}) endwhile() +foreach(image ${IMAGES}) + ExternalZephyrProject_Cmake(APPLICATION ${image}) +endforeach() include(cmake/domains.cmake) diff --git a/share/sysbuild/cmake/modules/sysbuild_extensions.cmake b/share/sysbuild/cmake/modules/sysbuild_extensions.cmake index 9ae0daa749f2..843ff2060e7c 100644 --- a/share/sysbuild/cmake/modules/sysbuild_extensions.cmake +++ b/share/sysbuild/cmake/modules/sysbuild_extensions.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Nordic Semiconductor +# Copyright (c) 2021-2023 Nordic Semiconductor # # SPDX-License-Identifier: Apache-2.0 @@ -178,44 +178,6 @@ function(ExternalZephyrProject_Add) set(sysbuild_cache_file ${CMAKE_BINARY_DIR}/${ZBUILD_APPLICATION}_sysbuild_cache.txt) - get_cmake_property(sysbuild_cache CACHE_VARIABLES) - foreach(var_name ${sysbuild_cache}) - if(NOT "${var_name}" MATCHES "^CMAKE_.*") - # We don't want to pass internal CMake variables. - # Required CMake variable to be passed, like CMAKE_BUILD_TYPE must be - # passed using `-D` on command invocation. - get_property(var_type CACHE ${var_name} PROPERTY TYPE) - set(cache_entry "${var_name}:${var_type}=$CACHE{${var_name}}") - string(REPLACE ";" "\;" cache_entry "${cache_entry}") - list(APPEND sysbuild_cache_strings "${cache_entry}\n") - endif() - endforeach() - list(APPEND sysbuild_cache_strings "SYSBUILD_NAME:STRING=${ZBUILD_APPLICATION}\n") - - if(ZBUILD_MAIN_APP) - list(APPEND sysbuild_cache_strings "SYSBUILD_MAIN_APP:BOOL=True\n") - endif() - - if(DEFINED ZBUILD_BOARD) - # Only set image specific board if provided. - # The sysbuild BOARD is exported through sysbuild cache, and will be used - # unless _BOARD is defined. - if(DEFINED ZBUILD_BOARD_REVISION) - # Use provided board revision - list(APPEND sysbuild_cache_strings "${ZBUILD_APPLICATION}_BOARD:STRING=${ZBUILD_BOARD}@${ZBUILD_BOARD_REVISION}\n") - else() - list(APPEND sysbuild_cache_strings "${ZBUILD_APPLICATION}_BOARD:STRING=${ZBUILD_BOARD}\n") - endif() - elseif(DEFINED ZBUILD_BOARD_REVISION) - message(FATAL_ERROR - "ExternalZephyrProject_Add(... BOARD_REVISION ${ZBUILD_BOARD_REVISION})" - " requires BOARD." - ) - endif() - - file(WRITE ${sysbuild_cache_file}.tmp ${sysbuild_cache_strings}) - zephyr_file_copy(${sysbuild_cache_file}.tmp ${sysbuild_cache_file} ONLY_IF_DIFFERENT) - set(shared_cmake_vars_argument) foreach(shared_var ${shared_cmake_variables_list}) if(DEFINED CACHE{${ZBUILD_APPLICATION}_${shared_var}}) @@ -231,34 +193,6 @@ function(ExternalZephyrProject_Add) endif() endforeach() - set(image_banner "* Running CMake for ${ZBUILD_APPLICATION} *") - string(LENGTH "${image_banner}" image_banner_width) - string(REPEAT "*" ${image_banner_width} image_banner_header) - message(STATUS "\n ${image_banner_header}\n" - " ${image_banner}\n" - " ${image_banner_header}\n" - ) - - execute_process( - COMMAND ${CMAKE_COMMAND} - -G${CMAKE_GENERATOR} - -DSYSBUILD:BOOL=True - -DSYSBUILD_CACHE:FILEPATH=${sysbuild_cache_file} - ${shared_cmake_vars_argument} - -B${CMAKE_BINARY_DIR}/${ZBUILD_APPLICATION} - -S${ZBUILD_SOURCE_DIR} - RESULT_VARIABLE return_val - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - ) - - if(return_val) - message(FATAL_ERROR - "CMake configure failed for Zephyr project: ${ZBUILD_APPLICATION}\n" - "Location: ${ZBUILD_SOURCE_DIR}" - ) - endif() - load_cache(IMAGE ${ZBUILD_APPLICATION} BINARY_DIR ${CMAKE_BINARY_DIR}/${ZBUILD_APPLICATION}) - foreach(kconfig_target menuconfig hardenconfig @@ -282,10 +216,133 @@ function(ExternalZephyrProject_Add) SOURCE_DIR ${ZBUILD_SOURCE_DIR} BINARY_DIR ${CMAKE_BINARY_DIR}/${ZBUILD_APPLICATION} CONFIGURE_COMMAND "" + CMAKE_ARGS -DSYSBUILD:BOOL=True + -DSYSBUILD_CACHE:FILEPATH=${sysbuild_cache_file} + ${shared_cmake_vars_argument} BUILD_COMMAND ${CMAKE_COMMAND} --build . INSTALL_COMMAND "" BUILD_ALWAYS True USES_TERMINAL_BUILD True ) - import_kconfig(CONFIG_ ${CMAKE_BINARY_DIR}/${ZBUILD_APPLICATION}/zephyr/.config TARGET ${ZBUILD_APPLICATION}) + set_target_properties(${ZBUILD_APPLICATION} PROPERTIES CACHE_FILE ${sysbuild_cache_file}) + if(ZBUILD_MAIN_APP) + set_target_properties(${ZBUILD_APPLICATION} PROPERTIES MAIN_APP True) + endif() + + if(DEFINED ZBUILD_BOARD) + # Only set image specific board if provided. + # The sysbuild BOARD is exported through sysbuild cache, and will be used + # unless _BOARD is defined. + if(DEFINED ZBUILD_BOARD_REVISION) + # Use provided board revision + set_target_properties(${ZBUILD_APPLICATION} PROPERTIES BOARD ${ZBUILD_BOARD}@${ZBUILD_BOARD_REVISION}) + else() + set_target_properties(${ZBUILD_APPLICATION} PROPERTIES BOARD ${ZBUILD_BOARD}) + endif() + elseif(DEFINED ZBUILD_BOARD_REVISION) + message(FATAL_ERROR + "ExternalZephyrProject_Add(... BOARD_REVISION ${ZBUILD_BOARD_REVISION})" + " requires BOARD." + ) + elseif(DEFINED BOARD_REVISION) + # Include build revision for target image + set_target_properties(${ZBUILD_APPLICATION} PROPERTIES BOARD ${BOARD}@${BOARD_REVISION}) + endif() +endfunction() + +# Usage: +# ExternalZephyrProject_Cmake(APPLICATION ) +# +# This function invokes the CMake configure step on an external Zephyr project +# which has been added at an earlier stage using `ExternalZephyrProject_Add()` +# +# If the application is not due to ExternalZephyrProject_Add() being called, +# then an error is raised. +# +# APPLICATION: : Name of the application. +# +function(ExternalZephyrProject_Cmake) + cmake_parse_arguments(ZCMAKE "" "APPLICATION" "" ${ARGN}) + + if(ZBUILD_UNPARSED_ARGUMENTS) + message(FATAL_ERROR + "ExternalZephyrProject_Cmake(${ARGV0} ...) given unknown arguments:" + " ${ZBUILD_UNPARSED_ARGUMENTS}" + ) + endif() + + if(NOT DEFINED ZCMAKE_APPLICATION) + message(FATAL_ERROR "Missing required argument: APPLICATION") + endif() + + if(NOT TARGET ${ZCMAKE_APPLICATION}) + message(FATAL_ERROR + "${ZCMAKE_APPLICATION} does not exists. Remember to call " + "ExternalZephyrProject_Add(APPLICATION ${ZCMAKE_APPLICATION} ...) first." + ) + endif() + + set(image_banner "* Running CMake for ${ZCMAKE_APPLICATION} *") + string(LENGTH "${image_banner}" image_banner_width) + string(REPEAT "*" ${image_banner_width} image_banner_header) + message(STATUS "\n ${image_banner_header}\n" + " ${image_banner}\n" + " ${image_banner_header}\n" + ) + + ExternalProject_Get_Property(${ZCMAKE_APPLICATION} SOURCE_DIR BINARY_DIR CMAKE_ARGS) + get_target_property(${ZCMAKE_APPLICATION}_CACHE_FILE ${ZCMAKE_APPLICATION} CACHE_FILE) + get_target_property(${ZCMAKE_APPLICATION}_BOARD ${ZCMAKE_APPLICATION} BOARD) + get_target_property(${ZCMAKE_APPLICATION}_MAIN_APP ${ZCMAKE_APPLICATION} MAIN_APP) + + get_cmake_property(sysbuild_cache CACHE_VARIABLES) + foreach(var_name ${sysbuild_cache}) + if(NOT "${var_name}" MATCHES "^CMAKE_.*") + # We don't want to pass internal CMake variables. + # Required CMake variable to be passed, like CMAKE_BUILD_TYPE must be + # passed using `-D` on command invocation. + get_property(var_type CACHE ${var_name} PROPERTY TYPE) + set(cache_entry "${var_name}:${var_type}=${${var_name}}") + string(REPLACE ";" "\;" cache_entry "${cache_entry}") + list(APPEND sysbuild_cache_strings "${cache_entry}\n") + endif() + endforeach() + list(APPEND sysbuild_cache_strings "SYSBUILD_NAME:STRING=${ZCMAKE_APPLICATION}\n") + + if(${ZCMAKE_APPLICATION}_MAIN_APP) + list(APPEND sysbuild_cache_strings "SYSBUILD_MAIN_APP:BOOL=True\n") + endif() + + if(${ZCMAKE_APPLICATION}_BOARD) + # Only set image specific board if provided. + # The sysbuild BOARD is exported through sysbuild cache, and will be used + # unless _BOARD is defined. + list(APPEND sysbuild_cache_strings + "${ZCMAKE_APPLICATION}_BOARD:STRING=${${ZCMAKE_APPLICATION}_BOARD}\n" + ) + endif() + + file(WRITE ${${ZCMAKE_APPLICATION}_CACHE_FILE}.tmp ${sysbuild_cache_strings}) + zephyr_file_copy(${${ZCMAKE_APPLICATION}_CACHE_FILE}.tmp + ${${ZCMAKE_APPLICATION}_CACHE_FILE} ONLY_IF_DIFFERENT + ) + + execute_process( + COMMAND ${CMAKE_COMMAND} + -G${CMAKE_GENERATOR} + ${CMAKE_ARGS} + -B${BINARY_DIR} + -S${SOURCE_DIR} + RESULT_VARIABLE return_val + WORKING_DIRECTORY ${BINARY_DIR} + ) + + if(return_val) + message(FATAL_ERROR + "CMake configure failed for Zephyr project: ${ZCMAKE_APPLICATION}\n" + "Location: ${SOURCE_DIR}" + ) + endif() + load_cache(IMAGE ${ZCMAKE_APPLICATION} BINARY_DIR ${BINARY_DIR}) + import_kconfig(CONFIG_ ${BINARY_DIR}/zephyr/.config TARGET ${ZCMAKE_APPLICATION}) endfunction() From df9027a64a7fdbde0fcf6f0d3109733115b68723 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 20 Feb 2023 10:00:38 +0000 Subject: [PATCH 0060/1906] sysbuild: support Zephyr modules This commit extends the Zephyr module yaml scheme with additional entries for sysbuild in the build section. This allows for Zephyr modules to extend the sysbuild infrastructure by providing additional CMake and Kconfig files to be included in sysbuild. The new settings are: build: sysbuild-cmake: sysbuild-kconfig: / sysbuild-ext: | sysbuild-kconfig-ext: | those settings follow the same pattern as the equivalent Zephyr build settings but are processed by sysbuild. Signed-off-by: Jamie McCrae Signed-off-by: Torsten Rasmussen --- cmake/modules/zephyr_module.cmake | 101 ++++++++++++------ modules/Kconfig.sysbuild | 28 +++++ scripts/zephyr_module.py | 95 +++++++++++++++- share/sysbuild/CMakeLists.txt | 18 ++++ share/sysbuild/Kconfig | 6 ++ .../cmake/modules/sysbuild_kconfig.cmake | 1 - 6 files changed, 215 insertions(+), 34 deletions(-) create mode 100644 modules/Kconfig.sysbuild diff --git a/cmake/modules/zephyr_module.cmake b/cmake/modules/zephyr_module.cmake index 83d3712c76e4..3dcae3ea61b5 100644 --- a/cmake/modules/zephyr_module.cmake +++ b/cmake/modules/zephyr_module.cmake @@ -43,6 +43,9 @@ endif() file(MAKE_DIRECTORY ${KCONFIG_BINARY_DIR}) set(kconfig_modules_file ${KCONFIG_BINARY_DIR}/Kconfig.modules) +set(kconfig_sysbuild_file ${KCONFIG_BINARY_DIR}/Kconfig.sysbuild.modules) +set(cmake_modules_file ${CMAKE_BINARY_DIR}/zephyr_modules.txt) +set(cmake_sysbuild_file ${CMAKE_BINARY_DIR}/sysbuild_modules.txt) set(zephyr_settings_file ${CMAKE_BINARY_DIR}/zephyr_settings.txt) if(WEST) @@ -59,7 +62,9 @@ if(WEST OR ZEPHYR_MODULES) ${ZEPHYR_MODULES_ARG} ${ZEPHYR_EXTRA_MODULES_ARG} --kconfig-out ${kconfig_modules_file} - --cmake-out ${CMAKE_BINARY_DIR}/zephyr_modules.txt + --cmake-out ${cmake_modules_file} + --sysbuild-kconfig-out ${kconfig_sysbuild_file} + --sysbuild-cmake-out ${cmake_sysbuild_file} --settings-out ${zephyr_settings_file} WORKING_DIRECTORY ${ZEPHYR_BASE} ERROR_VARIABLE @@ -87,20 +92,32 @@ if(WEST OR ZEPHYR_MODULES) # Append ZEPHYR_BASE as a default ext root at lowest priority list(APPEND MODULE_EXT_ROOT ${ZEPHYR_BASE}) - if(EXISTS ${CMAKE_BINARY_DIR}/zephyr_modules.txt) - file(STRINGS ${CMAKE_BINARY_DIR}/zephyr_modules.txt zephyr_modules_txt - ENCODING UTF-8) + if(EXISTS ${cmake_modules_file}) + file(STRINGS ${cmake_modules_file} zephyr_modules_txt ENCODING UTF-8) + endif() - set(ZEPHYR_MODULE_NAMES) - foreach(module ${zephyr_modules_txt}) - # Match "":"" for each line of file, each corresponding to - # one module. The use of quotes is required due to CMake not supporting - # lazy regexes (it supports greedy only). - string(REGEX REPLACE "\"(.*)\":\".*\":\".*\"" "\\1" module_name ${module}) - list(APPEND ZEPHYR_MODULE_NAMES ${module_name}) - endforeach() + set(ZEPHYR_MODULE_NAMES) + foreach(module ${zephyr_modules_txt}) + # Match "":"" for each line of file, each corresponding to + # one module. The use of quotes is required due to CMake not supporting + # lazy regexes (it supports greedy only). + string(REGEX REPLACE "\"(.*)\":\".*\":\".*\"" "\\1" module_name ${module}) + list(APPEND ZEPHYR_MODULE_NAMES ${module_name}) + endforeach() + + if(EXISTS ${cmake_sysbuild_file}) + file(STRINGS ${cmake_sysbuild_file} sysbuild_modules_txt ENCODING UTF-8) endif() + set(SYSBUILD_MODULE_NAMES) + foreach(module ${sysbuild_modules_txt}) + # Match "":"" for each line of file, each corresponding to + # one module. The use of quotes is required due to CMake not supporting + # lazy regexes (it supports greedy only). + string(REGEX REPLACE "\"(.*)\":\".*\":\".*\"" "\\1" module_name ${module}) + list(APPEND SYSBUILD_MODULE_NAMES ${module_name}) + endforeach() + # MODULE_EXT_ROOT is process order which means Zephyr module roots processed # later wins. therefore we reverse the list before processing. list(REVERSE MODULE_EXT_ROOT) @@ -112,31 +129,53 @@ if(WEST OR ZEPHYR_MODULES) include(${root}/modules/modules.cmake) endforeach() - if(DEFINED zephyr_modules_txt) - foreach(module ${zephyr_modules_txt}) - # Match "":"" for each line of file, each corresponding to - # one Zephyr module. The use of quotes is required due to CMake not - # supporting lazy regexes (it supports greedy only). - string(CONFIGURE ${module} module) - string(REGEX REPLACE "\"(.*)\":\".*\":\".*\"" "\\1" module_name ${module}) - string(REGEX REPLACE "\".*\":\"(.*)\":\".*\"" "\\1" module_path ${module}) - string(REGEX REPLACE "\".*\":\".*\":\"(.*)\"" "\\1" cmake_path ${module}) - - zephyr_string(SANITIZE TOUPPER MODULE_NAME_UPPER ${module_name}) - if(NOT ${MODULE_NAME_UPPER} STREQUAL CURRENT) - set(ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR ${module_path}) - set(ZEPHYR_${MODULE_NAME_UPPER}_CMAKE_DIR ${cmake_path}) - else() - message(FATAL_ERROR "Found Zephyr module named: ${module_name}\n\ + foreach(module ${zephyr_modules_txt}) + # Match "":"" for each line of file, each corresponding to + # one Zephyr module. The use of quotes is required due to CMake not + # supporting lazy regexes (it supports greedy only). + string(CONFIGURE ${module} module) + string(REGEX REPLACE "\"(.*)\":\".*\":\".*\"" "\\1" module_name ${module}) + string(REGEX REPLACE "\".*\":\"(.*)\":\".*\"" "\\1" module_path ${module}) + string(REGEX REPLACE "\".*\":\".*\":\"(.*)\"" "\\1" cmake_path ${module}) + + zephyr_string(SANITIZE TOUPPER MODULE_NAME_UPPER ${module_name}) + if(NOT ${MODULE_NAME_UPPER} STREQUAL CURRENT) + set(ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR ${module_path}) + set(ZEPHYR_${MODULE_NAME_UPPER}_CMAKE_DIR ${cmake_path}) + else() + message(FATAL_ERROR "Found Zephyr module named: ${module_name}\n\ ${MODULE_NAME_UPPER} is a restricted name for Zephyr modules as it is used for \ \${ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR} CMake variable.") - endif() - endforeach() - endif() + endif() + endforeach() + + foreach(module ${sysbuild_modules_txt}) + # Match "":"" for each line of file, each corresponding to + # one Zephyr module. The use of quotes is required due to CMake not + # supporting lazy regexes (it supports greedy only). + string(CONFIGURE ${module} module) + string(REGEX REPLACE "\"(.*)\":\".*\":\".*\"" "\\1" module_name ${module}) + string(REGEX REPLACE "\".*\":\"(.*)\":\".*\"" "\\1" module_path ${module}) + string(REGEX REPLACE "\".*\":\".*\":\"(.*)\"" "\\1" cmake_path ${module}) + + zephyr_string(SANITIZE TOUPPER MODULE_NAME_UPPER ${module_name}) + if(NOT ${MODULE_NAME_UPPER} STREQUAL CURRENT) + set(SYSBUILD_${MODULE_NAME_UPPER}_MODULE_DIR ${module_path}) + set(SYSBUILD_${MODULE_NAME_UPPER}_CMAKE_DIR ${cmake_path}) + else() + message(FATAL_ERROR "Found Zephyr module named: ${module_name}\n\ +${MODULE_NAME_UPPER} is a restricted name for Zephyr modules as it is used for \ +\${SYSBUILD_${MODULE_NAME_UPPER}_MODULE_DIR} CMake variable.") + endif() + endforeach() else() file(WRITE ${kconfig_modules_file} "# No west and no Zephyr modules\n" ) + file(WRITE ${kconfig_sysbuild_file} + "# No west and no Zephyr modules\n" + ) + endif() diff --git a/modules/Kconfig.sysbuild b/modules/Kconfig.sysbuild new file mode 100644 index 000000000000..517e0e335f75 --- /dev/null +++ b/modules/Kconfig.sysbuild @@ -0,0 +1,28 @@ +# Copyright (c) 2019 Intel Corporation +# Copyright (c) 2022 Nordic Semiconductor +# +# SPDX-License-Identifier: Apache-2.0 + +comment "Available modules." + +source "$(KCONFIG_BINARY_DIR)/Kconfig.sysbuild.modules" + +comment "Unavailable modules, please install those via the project manifest." + +# List of comments to display when Zephyr modules are not available, please +# use the following syntax: +# --------------------------------------------------- +# comment " module not available." +# depends on !SYSBUILD__MODULE +# +# Remember to add the following code inside the `/Kconfig file: +# --------------------------------------------------- +# config SYSBUILD__MODULE +# bool + +# This ensures that symbols are available in Kconfig for dependency checking +# and referencing, while keeping the settings themselves unavailable when the +# modules are not present in the workspace +if 0 +osource "modules/*/Kconfig.sysbuild" +endif diff --git a/scripts/zephyr_module.py b/scripts/zephyr_module.py index 65fb7c5c74d1..e0cf18d56456 100755 --- a/scripts/zephyr_module.py +++ b/scripts/zephyr_module.py @@ -57,6 +57,20 @@ required: false type: bool default: false + sysbuild-cmake: + required: false + type: str + sysbuild-kconfig: + required: false + type: str + sysbuild-cmake-ext: + required: false + type: bool + default: false + sysbuild-kconfig-ext: + required: false + type: bool + default: false depends: required: false type: seq @@ -216,6 +230,40 @@ def process_cmake(module, meta): module_path.as_posix())) +def process_sysbuildcmake(module, meta): + section = meta.get('build', dict()) + module_path = PurePath(module) + module_yml = module_path.joinpath('zephyr/module.yml') + + cmake_extern = section.get('sysbuild-cmake-ext', False) + if cmake_extern: + return('\"{}\":\"{}\":\"{}\"\n' + .format(meta['name'], + module_path.as_posix(), + "${SYSBUILD_" + meta['name-sanitized'].upper() + "_CMAKE_DIR}")) + + cmake_setting = section.get('sysbuild-cmake', None) + if not validate_setting(cmake_setting, module, 'CMakeLists.txt'): + sys.exit('ERROR: "cmake" key in {} has folder value "{}" which ' + 'does not contain a CMakeLists.txt file.' + .format(module_yml.as_posix(), cmake_setting)) + + if cmake_setting is None: + return "" + + cmake_path = os.path.join(module, cmake_setting or 'zephyr') + cmake_file = os.path.join(cmake_path, 'CMakeLists.txt') + if os.path.isfile(cmake_file): + return('\"{}\":\"{}\":\"{}\"\n' + .format(meta['name'], + module_path.as_posix(), + Path(cmake_path).resolve().as_posix())) + else: + return('\"{}\":\"{}\":\"\"\n' + .format(meta['name'], + module_path.as_posix())) + + def process_settings(module, meta): section = meta.get('build', dict()) build_settings = section.get('settings', None) @@ -260,13 +308,14 @@ def process_blobs(module, meta): return blobs -def kconfig_snippet(meta, path, kconfig_file=None, blobs=False): +def kconfig_snippet(meta, path, kconfig_file=None, blobs=False, sysbuild=False): name = meta['name'] name_sanitized = meta['name-sanitized'] snippet = [f'menu "{name} ({path.as_posix()})"', f'osource "{kconfig_file.resolve().as_posix()}"' if kconfig_file - else f'osource "$(ZEPHYR_{name_sanitized.upper()}_KCONFIG)"', + else f'osource "$(SYSBUILD_{name_sanitized.upper()}_KCONFIG)"' if sysbuild is True + else f'osource "$(ZEPHYR_{name_sanitized.upper()}_KCONFIG)"', f'config ZEPHYR_{name_sanitized.upper()}_MODULE', ' bool', ' default y', @@ -301,6 +350,30 @@ def process_kconfig(module, meta): return "" +def process_sysbuildkconfig(module, meta): + section = meta.get('build', dict()) + module_path = PurePath(module) + module_yml = module_path.joinpath('zephyr/module.yml') + kconfig_extern = section.get('sysbuild-kconfig-ext', False) + if kconfig_extern: + return kconfig_snippet(meta, module_path, sysbuild=True) + + kconfig_setting = section.get('sysbuild-kconfig', None) + if not validate_setting(kconfig_setting, module): + sys.exit('ERROR: "kconfig" key in {} has value "{}" which does ' + 'not point to a valid Kconfig file.' + .format(module_yml, kconfig_setting)) + + if kconfig_setting is None: + return "" + + kconfig_file = os.path.join(module, kconfig_setting) + if os.path.isfile(kconfig_file): + return kconfig_snippet(meta, module_path, Path(kconfig_file)) + else: + return "" + + def process_twister(module, meta): out = "" @@ -553,6 +626,12 @@ def main(): parser.add_argument('--cmake-out', help="""File to write with resulting : values to use for including in CMake""") + parser.add_argument('--sysbuild-kconfig-out', + help="""File to write with resulting KConfig import + statements.""") + parser.add_argument('--sysbuild-cmake-out', + help="""File to write with resulting : + values to use for including in CMake""") parser.add_argument('--meta-out', help="""Write a build meta YaML file containing a list of Zephyr modules and west projects. @@ -576,6 +655,8 @@ def main(): kconfig = "" cmake = "" + sysbuild_kconfig = "" + sysbuild_cmake = "" settings = "" twister = "" @@ -586,6 +667,8 @@ def main(): for module in modules: kconfig += process_kconfig(module.project, module.meta) cmake += process_cmake(module.project, module.meta) + sysbuild_kconfig += process_sysbuildkconfig(module.project, module.meta) + sysbuild_cmake += process_sysbuildcmake(module.project, module.meta) settings += process_settings(module.project, module.meta) twister += process_twister(module.project, module.meta) @@ -597,6 +680,14 @@ def main(): with open(args.cmake_out, 'w', encoding="utf-8") as fp: fp.write(cmake) + if args.sysbuild_kconfig_out: + with open(args.sysbuild_kconfig_out, 'w', encoding="utf-8") as fp: + fp.write(sysbuild_kconfig) + + if args.sysbuild_cmake_out: + with open(args.sysbuild_cmake_out, 'w', encoding="utf-8") as fp: + fp.write(sysbuild_cmake) + if args.settings_out: with open(args.settings_out, 'w', encoding="utf-8") as fp: fp.write('''\ diff --git a/share/sysbuild/CMakeLists.txt b/share/sysbuild/CMakeLists.txt index f0ee3763186c..aeb0476d57d7 100644 --- a/share/sysbuild/CMakeLists.txt +++ b/share/sysbuild/CMakeLists.txt @@ -30,6 +30,24 @@ set(IMAGES) get_filename_component(APP_DIR ${APP_DIR} ABSOLUTE) get_filename_component(app_name ${APP_DIR} NAME) +# Include zephyr modules generated sysbuild CMake file. +foreach(module_name ${SYSBUILD_MODULE_NAMES}) + # Note the second, binary_dir parameter requires the added + # subdirectory to have its own, local cmake target(s). If not then + # this binary_dir is created but stays empty. Object files land in + # the main binary dir instead. + # https://cmake.org/pipermail/cmake/2019-June/069547.html + zephyr_string(SANITIZE TOUPPER MODULE_NAME_UPPER ${module_name}) + if(NOT ${SYSBUILD_${MODULE_NAME_UPPER}_CMAKE_DIR} STREQUAL "") + set(SYSBUILD_CURRENT_MODULE_DIR ${SYSBUILD_${MODULE_NAME_UPPER}_MODULE_DIR}) + set(SYSBUILD_CURRENT_CMAKE_DIR ${SYSBUILD_${MODULE_NAME_UPPER}_CMAKE_DIR}) + add_subdirectory(${SYSBUILD_CURRENT_CMAKE_DIR} ${CMAKE_BINARY_DIR}/modules/${module_name}) + endif() +endforeach() +# Done processing modules, clear SYSBUILD_CURRENT_MODULE_DIR and SYSBUILD_CURRENT_CMAKE_DIR. +set(SYSBUILD_CURRENT_MODULE_DIR) +set(SYSBUILD_CURRENT_CMAKE_DIR) + # Propagate bootloader and signing settings from this system to the MCUboot and # application image build systems. if(SB_CONFIG_BOOTLOADER_MCUBOOT) diff --git a/share/sysbuild/Kconfig b/share/sysbuild/Kconfig index 0ef8f8b80235..74c46ba2f71a 100644 --- a/share/sysbuild/Kconfig +++ b/share/sysbuild/Kconfig @@ -6,6 +6,12 @@ comment "Sysbuild image configuration" osource "$(BOARD_DIR)/Kconfig.sysbuild" +menu "Modules" + +source "modules/Kconfig.sysbuild" + +endmenu + config EXPERIMENTAL bool help diff --git a/share/sysbuild/cmake/modules/sysbuild_kconfig.cmake b/share/sysbuild/cmake/modules/sysbuild_kconfig.cmake index 33e33fa59c2e..5dbf82728a5e 100644 --- a/share/sysbuild/cmake/modules/sysbuild_kconfig.cmake +++ b/share/sysbuild/cmake/modules/sysbuild_kconfig.cmake @@ -46,7 +46,6 @@ endif() # Empty files to make kconfig.py happy. file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/empty.conf) set(APPLICATION_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -set(KCONFIG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(AUTOCONF_H ${CMAKE_CURRENT_BINARY_DIR}/autoconf.h) set(CONF_FILE ${SB_CONF_FILE}) set(BOARD_DEFCONFIG "${CMAKE_CURRENT_BINARY_DIR}/empty.conf") From 388b3c237a408b56c886a3e77509fd2c82a157ef Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Tue, 28 Feb 2023 09:01:59 +0000 Subject: [PATCH 0061/1906] doc: sysbuild: Add details on external modules Adds details on how to use the new sysbuild external module feature. Signed-off-by: Jamie McCrae --- doc/build/sysbuild/index.rst | 15 ++++++ doc/develop/modules.rst | 94 ++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/doc/build/sysbuild/index.rst b/doc/build/sysbuild/index.rst index 4548d05bbccb..30df8f0baca4 100644 --- a/doc/build/sysbuild/index.rst +++ b/doc/build/sysbuild/index.rst @@ -562,3 +562,18 @@ debug the application. .. _MCUboot with Zephyr: https://mcuboot.com/documentation/readme-zephyr/ .. _ExternalProject: https://cmake.org/cmake/help/latest/module/ExternalProject.html + +Extending sysbuild +****************** + +Sysbuild can be extended by other modules to give it additional functionality +or include other configuration or images, an example could be to add support +for another bootloader or external signing method. + +Modules can be extended by adding custom CMake or Kconfig files as normal +:ref:`modules ` do, this will cause the files to be included in +each image that is part of a project. Alternatively, there are +:ref:`sysbuild-specific module extension ` files +which can be used to include CMake and Kconfig files for the overall sysbuild +image itself, this is where e.g. a custom image for a particular board or SoC +can be added. diff --git a/doc/develop/modules.rst b/doc/develop/modules.rst index e799174338c6..2557d681e420 100644 --- a/doc/develop/modules.rst +++ b/doc/develop/modules.rst @@ -495,6 +495,54 @@ module: cmake: . kconfig: Kconfig +.. _sysbuild_module_integration: + +Sysbuild integration +==================== + +:ref:`Sysbuild` is the Zephyr build system that allows for building +multiple images as part of a single application, the sysbuild build process +can be extended externally with modules as needed, for example to add custom +build steps or add additional targets to a build. Inclusion of +sysbuild-specific build files, :file:`CMakeLists.txt` and :file:`Kconfig`, can +be described as: + +.. code-block:: yaml + + build: + sysbuild-cmake: + sysbuild-kconfig: /Kconfig + +The ``sysbuild-cmake: `` part specifies that +:file:`` contains the :file:`CMakeLists.txt` to use. The +``sysbuild-kconfig: /Kconfig`` part specifies the Kconfig file to +use. + +Here is an example :file:`module.yml` file referring to +:file:`CMakeLists.txt` and :file:`Kconfig` files in the `sysbuild` directory of +the module: + +.. code-block:: yaml + + build: + sysbuild-cmake: sysbuild + sysbuild-kconfig: sysbuild/Kconfig + +The module description file :file:`zephyr/module.yml` can also be used to +specify that the build files, :file:`CMakeLists.txt` and :file:`Kconfig`, are +located in a :ref:`modules_module_ext_root`. + +Build files located in a ``MODULE_EXT_ROOT`` can be described as: + +.. code-block:: yaml + + build: + sysbuild-cmake-ext: True + sysbuild-kconfig-ext: True + +This allows control of the build inclusion to be described externally to the +Zephyr module. + Build system integration ======================== @@ -502,6 +550,9 @@ When a module has a :file:`module.yml` file, it will automatically be included i the Zephyr build system. The path to the module is then accessible through Kconfig and CMake variables. +Normal modules +-------------- + In both Kconfig and CMake, the variable ``ZEPHYR__MODULE_DIR`` contains the absolute path to the module. @@ -562,6 +613,49 @@ Zephyr CMakeLists.txt scope: An example of a Zephyr list where this is useful is when adding additional directories to the ``SYSCALL_INCLUDE_DIRS`` list. +Sysbuild modules +---------------- + +In both Kconfig and CMake, the variable ``SYSBUILD_CURRENT_MODULE_DIR`` +contains the absolute path to the sysbuild module. In CMake, +``SYSBUILD_CURRENT_CMAKE_DIR`` contains the absolute path to the directory +containing the :file:`CMakeLists.txt` file that is included into CMake build +system. This variable's value is empty if the module.yml file does not specify +a CMakeLists.txt. + +To read these variables for a sysbuild module: + +- In CMake: use ``${SYSBUILD_CURRENT_MODULE_DIR}`` for the module's top level + directory, and ``${SYSBUILD_CURRENT_CMAKE_DIR}`` for the directory containing + its :file:`CMakeLists.txt` +- In Kconfig: use ``$(SYSBUILD_CURRENT_MODULE_DIR)`` for the module's top level + directory + +In Kconfig, the variable may be used to find additional files to include. +For example, to include the file :file:`some/Kconfig`: + +.. code-block:: kconfig + + source "$(SYSBUILD_CURRENT_MODULE_DIR)/some/Kconfig" + +The module can source additional CMake files using these variables. For +example: + +.. code-block:: cmake + + include(${SYSBUILD_CURRENT_MODULE_DIR}/cmake/code.cmake) + +It is possible to append values to a Zephyr CMake list variable from the +module's first CMakeLists.txt file. +To do so, append the value to the list and then set the list in the +PARENT_SCOPE of the CMakeLists.txt file. For example, to append ``bar`` to the +``FOO_LIST`` variable in the Zephyr CMakeLists.txt scope: + +.. code-block:: cmake + + list(APPEND FOO_LIST bar) + set(FOO_LIST ${FOO_LIST} PARENT_SCOPE) + Zephyr module dependencies ========================== From 2117853d9609eb438da4e54e38325a250afc0c45 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 2 Mar 2023 14:06:15 +0100 Subject: [PATCH 0062/1906] ci: twister: Enable tests on bsim boards Since the move to github workflows e366d7948a536951d63392dd3bc63c36212e8081 we lost the ability to run in CI in twister the bsim boards. This means people cannot use the nrf52_bsim in normal twister workflows even if it would work perfectly fine otherwise (say as a stand alone test of the controller that does not require an actual BT pair). It also meant changes to the bsim board itself where not tested with twister like for other boards, but relied solely on the BT tests. Enable this kind of tests again. Signed-off-by: Alberto Escolar Piedras --- .github/workflows/twister.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/twister.yaml b/.github/workflows/twister.yaml index d52bb6e2bd57..5a801803e74c 100644 --- a/.github/workflows/twister.yaml +++ b/.github/workflows/twister.yaml @@ -35,6 +35,8 @@ jobs: PUSH_MATRIX_SIZE: 15 DAILY_MATRIX_SIZE: 80 ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.15.2 + BSIM_OUT_PATH: /opt/bsim/ + BSIM_COMPONENTS_PATH: /opt/bsim/components TESTS_PER_BUILDER: 700 COMMIT_RANGE: ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} BASE_REF: ${{ github.base_ref }} @@ -128,6 +130,8 @@ jobs: subset: ${{fromJSON(needs.twister-build-prep.outputs.subset)}} env: ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.15.2 + BSIM_OUT_PATH: /opt/bsim/ + BSIM_COMPONENTS_PATH: /opt/bsim/components TWISTER_COMMON: ' --force-color --inline-logs -v -N -M --retry-failed 3 ' DAILY_OPTIONS: ' -M --build-only --all --show-footprint' PR_OPTIONS: ' --clobber-output --integration' From e253dc94a1b9510fc99883a36ce6f58b6bc44937 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Wed, 8 Mar 2023 08:22:08 +0000 Subject: [PATCH 0063/1906] docs: release: 3.4: Fix extra word Removes an extra word which was repeated Signed-off-by: Jamie McCrae --- doc/releases/release-notes-3.4.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/releases/release-notes-3.4.rst b/doc/releases/release-notes-3.4.rst index 171166380a51..f9bfd45440de 100644 --- a/doc/releases/release-notes-3.4.rst +++ b/doc/releases/release-notes-3.4.rst @@ -203,8 +203,8 @@ Boards & SoC Support Build system and infrastructure ******************************* -* Fixed an issue whereby whereby older versions of the Zephyr SDK toolchain - were used instead of the latest compatible version. +* Fixed an issue whereby older versions of the Zephyr SDK toolchain were used + instead of the latest compatible version. Drivers and Sensors ******************* From 5739d8dc1b868606b8a482253eaff9072b9cfd06 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Wed, 8 Mar 2023 08:23:20 +0000 Subject: [PATCH 0064/1906] sysbuild: Fix mcuboot checksum only verification not working Fixes an issue when configuring a project through sysbuild to use mcuboot and setting the verification to checksum only whereby the image would be unbootable. Signed-off-by: Jamie McCrae --- share/sysbuild/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/share/sysbuild/CMakeLists.txt b/share/sysbuild/CMakeLists.txt index aeb0476d57d7..12729d8cd1f6 100644 --- a/share/sysbuild/CMakeLists.txt +++ b/share/sysbuild/CMakeLists.txt @@ -59,6 +59,12 @@ if(SB_CONFIG_BOOTLOADER_MCUBOOT) "Signature key file for signing" FORCE ) + if(SB_CONFIG_BOOT_SIGNATURE_TYPE_NONE) + set(${app_name}_CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE y CACHE STRING + "MCUBOOT is configured for checksum mode" FORCE + ) + endif() + # Set corresponding values in mcuboot set(mcuboot_CONFIG_BOOT_SIGNATURE_TYPE_${SB_CONFIG_SIGNATURE_TYPE} y CACHE STRING "MCUBOOT signature type" FORCE From 6f4a077bc67f3b17a41adabd406cd5ccd235ce35 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Wed, 8 Mar 2023 08:24:34 +0000 Subject: [PATCH 0065/1906] docs: release: 3.4: Add note on sysbuild mcuboot checksum fix Adds a note that images are now bootable when built using sysbuild with mcuboot in checksum only mode. Signed-off-by: Jamie McCrae --- doc/releases/release-notes-3.4.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/releases/release-notes-3.4.rst b/doc/releases/release-notes-3.4.rst index f9bfd45440de..ad1ec38c7081 100644 --- a/doc/releases/release-notes-3.4.rst +++ b/doc/releases/release-notes-3.4.rst @@ -206,6 +206,9 @@ Build system and infrastructure * Fixed an issue whereby older versions of the Zephyr SDK toolchain were used instead of the latest compatible version. +* Fixed an issue whereby building an application with sysbuild and specifying + mcuboot's verification to be checksum only did not build a bootable image. + Drivers and Sensors ******************* From 01bba46736351ae65ec1833134937a1ed6d2ff82 Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Wed, 8 Mar 2023 10:23:34 +0100 Subject: [PATCH 0066/1906] samples: kernel: metairq_dispatch differ the assert msg Differ the __ASSERT_NO_MSG of the k_msgq_get() just after checking the nb of cycles. It allows precise counting of cpu cycles where the assert does not interfere. Signed-off-by: Francois Ramu --- samples/kernel/metairq_dispatch/src/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/kernel/metairq_dispatch/src/main.c b/samples/kernel/metairq_dispatch/src/main.c index a767cb8d76cb..b388a77b4642 100644 --- a/samples/kernel/metairq_dispatch/src/main.c +++ b/samples/kernel/metairq_dispatch/src/main.c @@ -188,8 +188,6 @@ static void thread_fn(void *p1, void *p2, void *p3) int ret = k_msgq_get(&threads[id].msgq, &m, K_FOREVER); uint32_t start = k_cycle_get_32(); - __ASSERT_NO_MSG(ret == 0); - /* Spin on the CPU for the requested number of cycles * doing the "work" required to "process" the event. * Note the inner loop: hammering on k_cycle_get_32() @@ -202,6 +200,7 @@ static void thread_fn(void *p1, void *p2, void *p3) for (volatile int i = 0; i < 100; i++) { } } + __ASSERT_NO_MSG(ret == 0); uint32_t dur = k_cycle_get_32() - start; From 50d21999fe14db1f90de27fc98274fe75c4f2dd3 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 8 Mar 2023 14:49:13 +0100 Subject: [PATCH 0067/1906] Bluetooth: ascs: Fix bt_ascs_ase missing cleanup Once the bt_ascs_ase is taken from the mem_slab, it has to be memset to override the junk data. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 15348d0a1166..76ddbec70f3f 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -1194,6 +1194,8 @@ void ascs_ep_init(struct bt_bap_ep *ep, uint8_t id) static void ase_init(struct bt_ascs_ase *ase, uint8_t id) { + memset(ase, 0, sizeof(*ase)); + ascs_ep_init(&ase->ep, id); /* Lookup ASE characteristic */ @@ -1218,10 +1220,9 @@ static struct bt_ascs_ase *ase_new(struct bt_ascs *ascs, uint8_t id) return NULL; } - sys_slist_append(&ascs->ases, &ase->node); - ase_init(ase, id); ase->ascs = ascs; + sys_slist_append(&ascs->ases, &ase->node); return ase; } From b91aa2e28c1004141e452dee8cc1d1a8712e7d35 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Tue, 7 Mar 2023 10:49:27 +0100 Subject: [PATCH 0068/1906] manifest: EDTT: Update to latest version Just a minor fix in the edtt which mostly avoids flooding the logs with exceptions in some error cases. Signed-off-by: Alberto Escolar Piedras --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 7b6501a679bd..9338f4ac39d9 100644 --- a/west.yml +++ b/west.yml @@ -37,7 +37,7 @@ manifest: groups: - hal - name: edtt - revision: fc998bcaed44796c3800a3e62cf026bd9403d299 + revision: 64e5105ad82390164fb73fc654be3f73a608209a path: tools/edtt groups: - tools From 6ca2dac6a31e6d914ace5baed76293878ca3e793 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 7 Mar 2023 13:12:18 +0100 Subject: [PATCH 0069/1906] bluetooth: controller: Fix build with BT_HCI_VS_EXT disabled [216/319] Building C object zephyr/subsys/bluetooth/controller/ CMakeFiles/subsys__bluetooth__controller.dir/hci/hci.c.obj zephyrproject/zephyr/subsys/bluetooth/controller/hci/hci.c: In function 'hci_vendor_cmd_handle_common': zephyrproject/zephyr/subsys/bluetooth/controller/hci/hci.c:5459:17: warning: implicit declaration of function 'vs_set_min_used_chans'; did you mean 'll_set_min_used_chans'? [-Wimplicit-function-declaration] 5459 | vs_set_min_used_chans(cmd, evt); | ^~~~~~~~~~~~~~~~~~~~~ | ll_set_min_used_chans .... zephyr-sdk-0.15.0/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/../ ../../../arm-zephyr-eabi/bin/ld.exe: zephyr/subsys/bluetooth/controller/ libsubsys__bluetooth__controller.a(hci.c.obj): in function `hci_vendor_cmd_handle_common': zephyrproject/zephyr/subsys/bluetooth/controller/hci/hci.c:5459: undefined reference to `vs_set_min_used_chans' collect2.exe: error: ld returned 1 exit status ninja: build stopped: subcommand failed. Signed-off-by: Szymon Janc --- subsys/bluetooth/controller/hci/hci.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 8b316dca62d4..3dc09242a5c9 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -5445,14 +5445,6 @@ int hci_vendor_cmd_handle_common(uint16_t ocf, struct net_buf *cmd, vs_read_tx_power_level(cmd, evt); break; #endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ -#endif /* CONFIG_BT_HCI_VS_EXT */ - -#if defined(CONFIG_BT_HCI_MESH_EXT) - case BT_OCF(BT_HCI_OP_VS_MESH): - mesh_cmd_handle(cmd, evt); - break; -#endif /* CONFIG_BT_HCI_MESH_EXT */ - #if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) #if defined(CONFIG_BT_CTLR_MIN_USED_CHAN) && defined(CONFIG_BT_PERIPHERAL) case BT_OCF(BT_HCI_OP_VS_SET_MIN_NUM_USED_CHANS): @@ -5460,6 +5452,13 @@ int hci_vendor_cmd_handle_common(uint16_t ocf, struct net_buf *cmd, break; #endif /* CONFIG_BT_CTLR_MIN_USED_CHAN && CONFIG_BT_PERIPHERAL */ #endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ +#endif /* CONFIG_BT_HCI_VS_EXT */ + +#if defined(CONFIG_BT_HCI_MESH_EXT) + case BT_OCF(BT_HCI_OP_VS_MESH): + mesh_cmd_handle(cmd, evt); + break; +#endif /* CONFIG_BT_HCI_MESH_EXT */ default: return -EINVAL; From da97ab6ee883dd0657a28645daa1739ea870b0a4 Mon Sep 17 00:00:00 2001 From: Jonathan Rico Date: Mon, 6 Mar 2023 07:46:30 +0100 Subject: [PATCH 0070/1906] Bluetooth: host: gatt: respect `BT_GATT_ENFORCE_SUBSCRIPTION` A subscription check was still being done in the gatt_notify_multiple_verify_params() fn, regardless of the value of CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION. This could lead to getting this warning if BT_GATT_NOTIFY_MULTIPLE is enabled, and the notifications not being sent to unsubscribed peers. Signed-off-by: Jonathan Rico --- subsys/bluetooth/host/gatt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index adae4ffd73a0..770a59d5e52b 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -2944,7 +2944,8 @@ static int gatt_notify_multiple_verify_params(struct bt_conn *conn, } /* Check if the characteristic is subscribed. */ - if (!bt_gatt_is_subscribed(conn, params[i].attr, + if (IS_ENABLED(CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION) && + !bt_gatt_is_subscribed(conn, params[i].attr, BT_GATT_CCC_NOTIFY)) { LOG_WRN("Device is not subscribed to characteristic"); return -EINVAL; From 8cf65fa282161444212ffde184d54aaaeb44e3e2 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 8 Mar 2023 19:39:28 +0100 Subject: [PATCH 0071/1906] tests: bluetooth gatt settings: Fix random test failures These tests are creating and deleting temporary files. But they deleted them with a wildcard that matched each other's temporary files causing failures when the tests run in parallel. Avoid it by only deleting the files for each test. As a freeby: Add the option to pass arbitrary commands to Phy from the calling script, as with most other tests Signed-off-by: Alberto Escolar Piedras --- .../host/gatt/settings/test_scripts/run_gatt_settings.sh | 7 ++++--- .../host/gatt/settings/test_scripts/run_gatt_settings_2.sh | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings.sh b/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings.sh index f64070ba009c..dfa2fa9fe0e3 100755 --- a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings.sh +++ b/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings.sh @@ -26,10 +26,11 @@ function Execute() { cd ${BSIM_OUT_PATH}/bin # Remove the files used by the custom SETTINGS backend -echo "remove settings files ${simulation_id}_*.log" -rm ${simulation_id}_*.log || true +TO_DELETE="${simulation_id}_server.log ${simulation_id}_client.log" +echo "remove settings files ${TO_DELETE}" +rm ${TO_DELETE} || true -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s="${simulation_id}" -D=8 -sim_length=30e6 +Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s="${simulation_id}" -D=8 -sim_length=30e6 $@ # Only one `server` device is really running at a time. This is a necessary hack # because bsim doesn't support plugging devices in and out of a running diff --git a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings_2.sh b/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings_2.sh index d2f99f372af8..fb6d4e6f45a6 100755 --- a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings_2.sh +++ b/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings_2.sh @@ -26,10 +26,11 @@ function Execute() { cd ${BSIM_OUT_PATH}/bin # Remove the files used by the custom SETTINGS backend -echo "remove settings files ${simulation_id}_*.log" -rm ${simulation_id}_*.log || true +TO_DELETE="${simulation_id}_server_2.log ${simulation_id}_client_2.log" +echo "remove settings files ${TO_DELETE}" +rm ${TO_DELETE} || true -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s="${simulation_id}" -D=8 -sim_length=30e6 +Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s="${simulation_id}" -D=8 -sim_length=30e6 $@ # Only one `server` device is really running at a time. This is a necessary hack # because bsim doesn't support plugging devices in and out of a running From 4a59107fc7d8e417ce74aba68b7c5c973534a5c3 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 9 Mar 2023 13:53:34 +0100 Subject: [PATCH 0072/1906] Bluetooth: Mesh: Fix compilation issue in access.c This fixes compilation errors of BabbleSim tests generated by gcc-12 when MOD_REL_LIST_SIZE is zero. Signed-off-by: Pavel Vasilyev --- subsys/bluetooth/mesh/Kconfig | 1 + subsys/bluetooth/mesh/access.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 754484c11cce..701dd055edff 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1280,6 +1280,7 @@ config BT_MESH_COMP_PAGE_1 config BT_MESH_MODEL_EXTENSION_LIST_SIZE int "Model extensions list size" depends on BT_MESH_COMP_PAGE_1 + range 1 255 default 10 help This option specifies how many models relations can be saved. diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 5218ccce16ef..30f1b9547671 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -79,7 +79,7 @@ static struct mod_relation mod_rel_list[MOD_REL_LIST_SIZE]; #define MOD_REL_LIST_FOR_EACH(idx) \ for ((idx) = 0; \ - (idx) < MOD_REL_LIST_SIZE && \ + (idx) < ARRAY_SIZE(mod_rel_list) && \ !(mod_rel_list[(idx)].elem_base == 0 && \ mod_rel_list[(idx)].idx_base == 0 && \ mod_rel_list[(idx)].elem_ext == 0 && \ @@ -1437,7 +1437,7 @@ static int mod_rel_register(struct bt_mesh_model *base, }; int i; - for (i = 0; i < MOD_REL_LIST_SIZE; i++) { + for (i = 0; i < ARRAY_SIZE(mod_rel_list); i++) { if (mod_rel_list[i].elem_base == 0 && mod_rel_list[i].idx_base == 0 && mod_rel_list[i].elem_ext == 0 && From c89b614e8e3cf169bf5d369e131585cd3d60bdd1 Mon Sep 17 00:00:00 2001 From: Sylvio Alves Date: Thu, 2 Mar 2023 08:05:10 -0300 Subject: [PATCH 0073/1906] soc: esp32s2: remove BT entry from deconfig ESP32-S2 does not have BT, hence remove its reference. Decrease default heap stack when Wi-Fi is enabled. Signed-off-by: Sylvio Alves --- boards/xtensa/esp32s2_saola/Kconfig.defconfig | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/boards/xtensa/esp32s2_saola/Kconfig.defconfig b/boards/xtensa/esp32s2_saola/Kconfig.defconfig index a6dd10503173..077b2bde4ac7 100644 --- a/boards/xtensa/esp32s2_saola/Kconfig.defconfig +++ b/boards/xtensa/esp32s2_saola/Kconfig.defconfig @@ -11,10 +11,5 @@ config ENTROPY_GENERATOR default y config HEAP_MEM_POOL_SIZE - default 98304 if WIFI - default 16384 if BT + default 32768 if WIFI default 4096 - -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice From 14ac1347e2875652ace071d5a32ed80bd2ae7889 Mon Sep 17 00:00:00 2001 From: Sylvio Alves Date: Thu, 2 Mar 2023 08:06:03 -0300 Subject: [PATCH 0074/1906] samples: wifi: esp32s2_saola: decrease heap size Current stack size is making build fail due to ram overflow. So, decresase total heap available to make room for the application. Signed-off-by: Sylvio Alves --- samples/net/wifi/boards/esp32s2_saola.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/net/wifi/boards/esp32s2_saola.conf b/samples/net/wifi/boards/esp32s2_saola.conf index 69077ff1a7b5..713c75ad3cad 100644 --- a/samples/net/wifi/boards/esp32s2_saola.conf +++ b/samples/net/wifi/boards/esp32s2_saola.conf @@ -1,5 +1,5 @@ CONFIG_WIFI=y -CONFIG_HEAP_MEM_POOL_SIZE=37760 +CONFIG_HEAP_MEM_POOL_SIZE=32768 # when enabling NET_SHELL, the following # helps to optimize memory footprint From bdbfcb12ca7cbb7067208f668779e96cd1e99104 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 25 Jan 2023 17:17:42 +0100 Subject: [PATCH 0075/1906] Bluetooth: Audio: Unicast stream start fix The unicast client would attempt to send the receiver start ready opcode to the server for source ASEs before the CIS was connected, which is a spec violation. The code has been refactored to set a boolean, and then send the receiver start ready opcode on CIS connection instead. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/bap_endpoint.h | 2 +- subsys/bluetooth/audio/bap_unicast_client.c | 89 +++++++++++++++++---- 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/subsys/bluetooth/audio/bap_endpoint.h b/subsys/bluetooth/audio/bap_endpoint.h index db7f443a007b..a2d102f9a611 100644 --- a/subsys/bluetooth/audio/bap_endpoint.h +++ b/subsys/bluetooth/audio/bap_endpoint.h @@ -43,7 +43,7 @@ struct bt_bap_ep { struct bt_codec_qos_pref qos_pref; struct bt_bap_iso *iso; - /* Used by the unicast server */ + /* Used by the unicast server and client */ bool receiver_ready; /* TODO: Create a union to reduce memory usage */ diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index eb179da46fda..773df93fd9d9 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -91,6 +91,44 @@ static int unicast_client_ep_set_metadata(struct bt_bap_ep *ep, void *data, uint static int unicast_client_ep_set_codec(struct bt_bap_ep *ep, uint8_t id, uint16_t cid, uint16_t vid, void *data, uint8_t len, struct bt_codec *codec); +static int unicast_client_ep_start(struct bt_bap_ep *ep, + struct net_buf_simple *buf); + +static int unicast_client_send_start(struct bt_bap_ep *ep) +{ + if (ep->receiver_ready != true || ep->dir != BT_AUDIO_DIR_SOURCE) { + LOG_DBG("Invalid ep %p %u %s", + ep, ep->receiver_ready, bt_audio_dir_str(ep->dir)); + + return -EINVAL; + } + + struct bt_ascs_start_op *req; + struct net_buf_simple *buf; + int err; + + buf = bt_bap_unicast_client_ep_create_pdu(BT_ASCS_START_OP); + + req = net_buf_simple_add(buf, sizeof(*req)); + req->num_ases = 1U; + + err = unicast_client_ep_start(ep, buf); + if (err != 0) { + LOG_DBG("unicast_client_ep_start failed: %d", + err); + + return err; + } + + err = bt_bap_unicast_client_ep_send(ep->stream->conn, ep, buf); + if (err != 0) { + LOG_DBG("bt_bap_unicast_client_ep_send failed: %d", err); + + return err; + } + + return 0; +} static void unicast_client_ep_idle_state(struct bt_bap_ep *ep); @@ -224,7 +262,21 @@ static void unicast_client_ep_iso_connected(struct bt_bap_ep *ep) return; } - LOG_DBG("stream %p ep %p dir %s", stream, ep, bt_audio_dir_str(ep->dir)); + LOG_DBG("stream %p ep %p dir %s", + stream, ep, bt_audio_dir_str(ep->dir)); + + LOG_ERR("ep->receiver_ready %u", ep->receiver_ready); + + if (ep->receiver_ready && ep->dir == BT_AUDIO_DIR_SOURCE) { + const int err = unicast_client_send_start(ep); + + if (err != 0) { + LOG_DBG("Failed to send start: %d", err); + + /* TBD: Should we release the stream then? */ + ep->receiver_ready = false; + } + } } static void unicast_client_iso_connected(struct bt_iso_chan *chan) @@ -2474,24 +2526,33 @@ int bt_bap_unicast_client_start(struct bt_bap_stream *stream) * Central Establishment procedure. */ err = unicast_client_stream_connect(stream); - if (err && err != -EALREADY) { - LOG_DBG("unicast_client_stream_connect failed: %d", err); - return err; + if (err == 0) { + if (ep->dir == BT_AUDIO_DIR_SOURCE) { + /* Set bool and wait for ISO to be connected to send the + * receiver start ready + */ + stream->ep->receiver_ready = true; + } } else if (err == -EALREADY) { LOG_DBG("ISO %p already connected", bt_bap_stream_iso_chan_get(stream)); - } - /* When initiated by the client, valid only if Direction field - * parameter value = 0x02 (Server is Audio Source) - */ - if (ep->dir == BT_AUDIO_DIR_SOURCE) { - err = unicast_client_ep_start(ep, buf); - if (err) { - return err; + if (ep->dir == BT_AUDIO_DIR_SOURCE) { + stream->ep->receiver_ready = true; + + err = unicast_client_send_start(ep); + if (err != 0) { + LOG_DBG("Failed to send start: %d", err); + + /* TBD: Should we release the stream then? */ + stream->ep->receiver_ready = false; + + return err; + } } - req->num_ases++; + } else { + LOG_DBG("unicast_client_stream_connect failed: %d", err); - return bt_bap_unicast_client_ep_send(stream->conn, ep, buf); + return err; } return 0; From c574bfcfd27a8a2b4fa5e8cd57a50c6d19533569 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Thu, 9 Mar 2023 10:52:57 +0200 Subject: [PATCH 0076/1906] bluetooth: audio: Fix NULL dereference before NULL check Fixes NULL dereference before NULL check for conn. Signed-off-by: Andrei Emeltchenko --- subsys/bluetooth/audio/ascs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 76ddbec70f3f..a21b2289e868 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -105,16 +105,19 @@ static void ase_status_changed(struct bt_bap_ep *ep, uint8_t old_state, uint8_t { struct bt_ascs_ase *ase = CONTAINER_OF(ep, struct bt_ascs_ase, ep); struct bt_conn *conn = ase->ascs->conn; - struct bt_conn_info conn_info; LOG_DBG("ase %p, ep %p", ase, ep); - bt_conn_get_info(conn, &conn_info); + if (conn != NULL) { + struct bt_conn_info conn_info; - if (conn != NULL && conn_info.state == BT_CONN_STATE_CONNECTED) { - ascs_ep_get_status(ep, &ase_buf); + bt_conn_get_info(conn, &conn_info); - bt_gatt_notify(conn, ase->attr, ase_buf.data, ase_buf.len); + if (conn_info.state == BT_CONN_STATE_CONNECTED) { + ascs_ep_get_status(ep, &ase_buf); + + bt_gatt_notify(conn, ase->attr, ase_buf.data, ase_buf.len); + } } } From 6810e669e12a1140b8b4b2c8d557190ff52d4d67 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Wed, 1 Mar 2023 16:35:12 +0100 Subject: [PATCH 0077/1906] Bluetooth: Mesh: Reschedule dedicated relay adv sets immediately Reschedule dedicated relay adv sets immediatey after finishing advertising of the previous relay message. This allows a node to relay messages as fast as possible when Relay Retransmit Count state is zero using less relay adv sets. When Relay Retransmit Count state is non-zero, the delay doesn't do anything as the time between pushing a relay message to the host and triggering adv_sent callback will be greater than this delay. In this case the relay adv set will send a next message immediately. Signed-off-by: Pavel Vasilyev --- subsys/bluetooth/mesh/adv_ext.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 851e663ecd14..38bb4313f6fd 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -337,7 +337,8 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv) atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); - if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && adv->tag & BT_MESH_FRIEND_ADV) { + if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && adv->tag & BT_MESH_FRIEND_ADV) || + (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tag == BT_MESH_RELAY_ADV)) { k_work_reschedule(&adv->work, K_NO_WAIT); } else { /* The controller will send the next advertisement immediately. From 307b10e516f34e08ef6557de9711b9bcd4f2248e Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 9 Mar 2023 10:38:07 +0000 Subject: [PATCH 0078/1906] doc: modules: Change normal modules to zephyr modules Minor doc change that was missed from a PR. Signed-off-by: Jamie McCrae --- doc/develop/modules.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/develop/modules.rst b/doc/develop/modules.rst index 2557d681e420..4ed3320909e9 100644 --- a/doc/develop/modules.rst +++ b/doc/develop/modules.rst @@ -550,7 +550,7 @@ When a module has a :file:`module.yml` file, it will automatically be included i the Zephyr build system. The path to the module is then accessible through Kconfig and CMake variables. -Normal modules +Zephyr modules -------------- In both Kconfig and CMake, the variable ``ZEPHYR__MODULE_DIR`` From 2d97b86b5c9fb83ced9cd2c697ce022bede7e9cc Mon Sep 17 00:00:00 2001 From: Marek Pieta Date: Thu, 9 Mar 2023 12:19:52 +0100 Subject: [PATCH 0079/1906] boards: thingy53_nrf5340: Add missing DTS nodelabels for sensors Change adds missing DTS nodelabels for bh1749 and bme688 sensors. This is done to simplify referring to the sensors in application. Signed-off-by: Marek Pieta --- boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dts b/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dts index ebe3bd523a73..4c5b1d91b13b 100644 --- a/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dts +++ b/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dts @@ -166,13 +166,13 @@ reg = <0x10>; }; - bh1749@38 { + bh1749: bh1749@38 { compatible = "rohm,bh1749"; reg = <0x38>; int-gpios = <&gpio1 5 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; }; - bme688@76 { + bme688: bme688@76 { compatible = "bosch,bme680"; reg = <0x76>; }; From 4701581776a29732805c7856370bf1bc4a2b5ce0 Mon Sep 17 00:00:00 2001 From: Sylvio Alves Date: Thu, 9 Mar 2023 09:16:42 -0300 Subject: [PATCH 0080/1906] drivers: timer: esp32c3: fix dtick counter increment System uptime is not getting incremented when TICKLESS_KERNEL is enabled. This fixes it by changing the clock_annouce and updating last_count increment accordingly. Signed-off-by: Sylvio Alves --- drivers/timer/esp32c3_sys_timer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/timer/esp32c3_sys_timer.c b/drivers/timer/esp32c3_sys_timer.c index 367470cadc70..f239de5faad2 100644 --- a/drivers/timer/esp32c3_sys_timer.c +++ b/drivers/timer/esp32c3_sys_timer.c @@ -65,9 +65,9 @@ static void sys_timer_isr(const void *arg) k_spinlock_key_t key = k_spin_lock(&lock); uint64_t now = get_systimer_alarm(); - uint32_t dticks = (uint32_t)((now - last_count) / CYC_PER_TICK); + uint64_t dticks = (uint64_t)((now - last_count) / CYC_PER_TICK); - last_count = now; + last_count += dticks * CYC_PER_TICK; if (!TICKLESS) { uint64_t next = last_count + CYC_PER_TICK; @@ -79,7 +79,7 @@ static void sys_timer_isr(const void *arg) } k_spin_unlock(&lock, key); - sys_clock_announce(IS_ENABLED(CONFIG_TICKLESS_KERNEL) ? dticks : 1); + sys_clock_announce(dticks); } void sys_clock_set_timeout(int32_t ticks, bool idle) From ef58fef8c88bb7a5ce2bf8e9c2da5da0ae89b9e6 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 9 Mar 2023 13:23:56 +0100 Subject: [PATCH 0081/1906] tests/bluetooth/bsim: Fail CI on build failure After 1de363d9d52, compile.sh stopped failing on build failures as failing jobs in the background would neither stop the script nor have their status propagated. Fix it. Signed-off-by: Alberto Escolar Piedras --- tests/bluetooth/bsim/audio/compile.sh | 4 +- tests/bluetooth/bsim/compile.sh | 12 +++-- tests/bluetooth/bsim/compile.source | 8 ++- tests/bluetooth/bsim/host/compile.sh | 70 +++++++++++++-------------- tests/bluetooth/bsim/ll/compile.sh | 26 +++++----- tests/bluetooth/bsim/mesh/compile.sh | 18 +++---- tests/bluetooth/bsim/sh_common.source | 16 ++++++ 7 files changed, 89 insertions(+), 65 deletions(-) create mode 100644 tests/bluetooth/bsim/sh_common.source diff --git a/tests/bluetooth/bsim/audio/compile.sh b/tests/bluetooth/bsim/audio/compile.sh index e92a3bc8064c..2f0f15f2103c 100755 --- a/tests/bluetooth/bsim/audio/compile.sh +++ b/tests/bluetooth/bsim/audio/compile.sh @@ -20,6 +20,6 @@ mkdir -p ${WORK_DIR} source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source -app=tests/bluetooth/bsim/audio compile & +app=tests/bluetooth/bsim/audio compile -wait +wait_for_background_jobs diff --git a/tests/bluetooth/bsim/compile.sh b/tests/bluetooth/bsim/compile.sh index b3458304e1d4..858138a5659c 100755 --- a/tests/bluetooth/bsim/compile.sh +++ b/tests/bluetooth/bsim/compile.sh @@ -18,9 +18,11 @@ BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} -${ZEPHYR_BASE}/tests/bluetooth/bsim/audio/compile.sh & -${ZEPHYR_BASE}/tests/bluetooth/bsim/host/compile.sh & -${ZEPHYR_BASE}/tests/bluetooth/bsim/ll/compile.sh & -${ZEPHYR_BASE}/tests/bluetooth/bsim/mesh/compile.sh & +source ${ZEPHYR_BASE}/tests/bluetooth/bsim/sh_common.source -wait +run_in_background ${ZEPHYR_BASE}/tests/bluetooth/bsim/audio/compile.sh +run_in_background ${ZEPHYR_BASE}/tests/bluetooth/bsim/host/compile.sh +run_in_background ${ZEPHYR_BASE}/tests/bluetooth/bsim/ll/compile.sh +run_in_background ${ZEPHYR_BASE}/tests/bluetooth/bsim/mesh/compile.sh + +wait_for_background_jobs diff --git a/tests/bluetooth/bsim/compile.source b/tests/bluetooth/bsim/compile.source index e3242c62c7bb..0107f713517c 100644 --- a/tests/bluetooth/bsim/compile.source +++ b/tests/bluetooth/bsim/compile.source @@ -1,13 +1,15 @@ # Copyright 2018 Oticon A/S # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bluetooth/bsim/sh_common.source + function print_error_info(){ echo -e "\033[0;31mFailure building ${app} ${conf_file} for ${BOARD}\033[0m\n\ You can rebuild it with\n\ ${cmake_cmd[@]} && ninja ${ninja_args}" } -function compile(){ +function _compile(){ : "${app:?app must be defined}" local app_root="${app_root:-${ZEPHYR_BASE}}" @@ -63,3 +65,7 @@ function compile(){ nm ${exe_name} | grep -v " [U|w] " | sort | cut -d" " -f1,3 > ${map_file_name} sed -i "1i $(wc -l ${map_file_name} | cut -d" " -f1)" ${map_file_name} } + +function compile(){ + run_in_background _compile +} diff --git a/tests/bluetooth/bsim/host/compile.sh b/tests/bluetooth/bsim/host/compile.sh index 993d9fb578af..5b56fb8495b1 100755 --- a/tests/bluetooth/bsim/host/compile.sh +++ b/tests/bluetooth/bsim/host/compile.sh @@ -20,38 +20,38 @@ mkdir -p ${WORK_DIR} source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source -app=tests/bluetooth/bsim/host/adv/resume compile & -app=tests/bluetooth/bsim/host/adv/resume conf_file=prj_2.conf compile & -app=tests/bluetooth/bsim/host/adv/chain compile & -app=tests/bluetooth/bsim/host/adv/periodic compile & -app=tests/bluetooth/bsim/host/adv/periodic conf_file=prj_long_data.conf compile & - -app=tests/bluetooth/bsim/host/att/eatt conf_file=prj_collision.conf compile & -app=tests/bluetooth/bsim/host/att/eatt conf_file=prj_multiple_conn.conf compile & -app=tests/bluetooth/bsim/host/att/eatt conf_file=prj_autoconnect.conf compile & -app=tests/bluetooth/bsim/host/att/eatt_notif conf_file=prj.conf compile & -app=tests/bluetooth/bsim/host/att/mtu_update compile & - -app=tests/bluetooth/bsim/host/gatt/caching compile & -app=tests/bluetooth/bsim/host/gatt/general compile & -app=tests/bluetooth/bsim/host/gatt/notify compile & -app=tests/bluetooth/bsim/host/gatt/notify_multiple compile & -app=tests/bluetooth/bsim/host/gatt/settings compile & -app=tests/bluetooth/bsim/host/gatt/settings conf_file=prj_2.conf compile & -app=tests/bluetooth/bsim/host/gatt/write compile & - -app=tests/bluetooth/bsim/host/l2cap/general compile & -app=tests/bluetooth/bsim/host/l2cap/userdata compile & -app=tests/bluetooth/bsim/host/l2cap/stress compile & - -app=tests/bluetooth/bsim/host/misc/disable compile & -app=tests/bluetooth/bsim/host/misc/multiple_id compile & - -app=tests/bluetooth/bsim/host/privacy/central compile & -app=tests/bluetooth/bsim/host/privacy/peripheral compile & -app=tests/bluetooth/bsim/host/privacy/device compile & - -app=tests/bluetooth/bsim/host/security/bond_overwrite_allowed compile & -app=tests/bluetooth/bsim/host/security/bond_overwrite_denied compile & - -wait +app=tests/bluetooth/bsim/host/adv/resume compile +app=tests/bluetooth/bsim/host/adv/resume conf_file=prj_2.conf compile +app=tests/bluetooth/bsim/host/adv/chain compile +app=tests/bluetooth/bsim/host/adv/periodic compile +app=tests/bluetooth/bsim/host/adv/periodic conf_file=prj_long_data.conf compile + +app=tests/bluetooth/bsim/host/att/eatt conf_file=prj_collision.conf compile +app=tests/bluetooth/bsim/host/att/eatt conf_file=prj_multiple_conn.conf compile +app=tests/bluetooth/bsim/host/att/eatt conf_file=prj_autoconnect.conf compile +app=tests/bluetooth/bsim/host/att/eatt_notif conf_file=prj.conf compile +app=tests/bluetooth/bsim/host/att/mtu_update compile + +app=tests/bluetooth/bsim/host/gatt/caching compile +app=tests/bluetooth/bsim/host/gatt/general compile +app=tests/bluetooth/bsim/host/gatt/notify compile +app=tests/bluetooth/bsim/host/gatt/notify_multiple compile +app=tests/bluetooth/bsim/host/gatt/settings compile +app=tests/bluetooth/bsim/host/gatt/settings conf_file=prj_2.conf compile +app=tests/bluetooth/bsim/host/gatt/write compile + +app=tests/bluetooth/bsim/host/l2cap/general compile +app=tests/bluetooth/bsim/host/l2cap/userdata compile +app=tests/bluetooth/bsim/host/l2cap/stress compile + +app=tests/bluetooth/bsim/host/misc/disable compile +app=tests/bluetooth/bsim/host/misc/multiple_id compile + +app=tests/bluetooth/bsim/host/privacy/central compile +app=tests/bluetooth/bsim/host/privacy/peripheral compile +app=tests/bluetooth/bsim/host/privacy/device compile + +app=tests/bluetooth/bsim/host/security/bond_overwrite_allowed compile +app=tests/bluetooth/bsim/host/security/bond_overwrite_denied compile + +wait_for_background_jobs diff --git a/tests/bluetooth/bsim/ll/compile.sh b/tests/bluetooth/bsim/ll/compile.sh index d3b258a8a7e3..ede4c74895e6 100755 --- a/tests/bluetooth/bsim/ll/compile.sh +++ b/tests/bluetooth/bsim/ll/compile.sh @@ -20,26 +20,26 @@ mkdir -p ${WORK_DIR} source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source -app=tests/bluetooth/bsim/ll/advx compile & +app=tests/bluetooth/bsim/ll/advx compile -app=tests/bluetooth/bsim/ll/conn conf_file=prj_split.conf compile & -app=tests/bluetooth/bsim/ll/conn conf_file=prj_split_privacy.conf compile & -app=tests/bluetooth/bsim/ll/conn conf_file=prj_split_low_lat.conf compile & +app=tests/bluetooth/bsim/ll/conn conf_file=prj_split.conf compile +app=tests/bluetooth/bsim/ll/conn conf_file=prj_split_privacy.conf compile +app=tests/bluetooth/bsim/ll/conn conf_file=prj_split_low_lat.conf compile -app=tests/bluetooth/bsim/ll/iso compile & -app=tests/bluetooth/bsim/ll/iso conf_file=prj_vs_dp.conf compile & +app=tests/bluetooth/bsim/ll/iso compile +app=tests/bluetooth/bsim/ll/iso conf_file=prj_vs_dp.conf compile app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ - conf_file=prj_dut_llcp.conf compile & + conf_file=prj_dut_llcp.conf compile app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ - conf_file=prj_tst_llcp.conf compile & + conf_file=prj_tst_llcp.conf compile app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ - conf_file=prj_dut.conf compile & + conf_file=prj_dut.conf compile app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ - conf_file=prj_tst.conf compile & + conf_file=prj_tst.conf compile app=tests/bluetooth/bsim/ll/edtt/gatt_test_app \ - conf_file=prj.conf compile & + conf_file=prj.conf compile app=tests/bluetooth/bsim/ll/edtt/gatt_test_app \ - conf_file=prj_llcp.conf compile & + conf_file=prj_llcp.conf compile -wait +wait_for_background_jobs diff --git a/tests/bluetooth/bsim/mesh/compile.sh b/tests/bluetooth/bsim/mesh/compile.sh index c64eea898194..d1c2df42c025 100755 --- a/tests/bluetooth/bsim/mesh/compile.sh +++ b/tests/bluetooth/bsim/mesh/compile.sh @@ -20,16 +20,16 @@ mkdir -p ${WORK_DIR} source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source -app=tests/bluetooth/bsim/mesh compile & -app=tests/bluetooth/bsim/mesh conf_overlay=overlay_low_lat.conf compile & -app=tests/bluetooth/bsim/mesh conf_overlay=overlay_pst.conf compile & -app=tests/bluetooth/bsim/mesh conf_overlay=overlay_gatt.conf compile & -app=tests/bluetooth/bsim/mesh conf_file=prj_mesh1d1.conf compile & +app=tests/bluetooth/bsim/mesh compile +app=tests/bluetooth/bsim/mesh conf_overlay=overlay_low_lat.conf compile +app=tests/bluetooth/bsim/mesh conf_overlay=overlay_pst.conf compile +app=tests/bluetooth/bsim/mesh conf_overlay=overlay_gatt.conf compile +app=tests/bluetooth/bsim/mesh conf_file=prj_mesh1d1.conf compile app=tests/bluetooth/bsim/mesh \ - conf_file=prj_mesh1d1.conf conf_overlay=overlay_pst.conf compile & + conf_file=prj_mesh1d1.conf conf_overlay=overlay_pst.conf compile app=tests/bluetooth/bsim/mesh \ - conf_file=prj_mesh1d1.conf conf_overlay=overlay_gatt.conf compile & + conf_file=prj_mesh1d1.conf conf_overlay=overlay_gatt.conf compile app=tests/bluetooth/bsim/mesh \ - conf_file=prj_mesh1d1.conf conf_overlay=overlay_low_lat.conf compile & + conf_file=prj_mesh1d1.conf conf_overlay=overlay_low_lat.conf compile -wait +wait_for_background_jobs diff --git a/tests/bluetooth/bsim/sh_common.source b/tests/bluetooth/bsim/sh_common.source new file mode 100644 index 000000000000..25c59d3f3c5b --- /dev/null +++ b/tests/bluetooth/bsim/sh_common.source @@ -0,0 +1,16 @@ +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +_process_ids=""; + +function run_in_background(){ + $@ & _process_ids="$_process_ids $!" +} + +function wait_for_background_jobs(){ + exit_code=0 + for process_id in $_process_ids; do + wait $process_id || let "exit_code=$?" + done + exit $exit_code #the last exit code != 0 +} From f2d43cf0ac54f337c0ab0453a4ebc57232fe051f Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 8 Mar 2023 15:01:23 +0100 Subject: [PATCH 0082/1906] Bluetooth: ascs: Fix missing list initialization This fixes missing initialization of active ASE list. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index a21b2289e868..fb6546dfb396 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -1161,12 +1161,20 @@ static void ase_stream_add(struct bt_ascs *ascs, struct bt_ascs_ase *ase, stream->ep = &ase->ep; } +static void ascs_init(struct bt_ascs *ascs, struct bt_conn *conn) +{ + memset(ascs, 0, sizeof(*ascs)); + + ascs->conn = bt_conn_ref(conn); + sys_slist_init(&ascs->ases); +} + static struct bt_ascs *ascs_get(struct bt_conn *conn) { struct bt_ascs *session = &sessions[bt_conn_index(conn)]; if (session->conn == NULL) { - session->conn = bt_conn_ref(conn); + ascs_init(session, conn); } return session; From 63e9e37fc356ab708527e0b02ded70032e1c6012 Mon Sep 17 00:00:00 2001 From: Joel Guittet Date: Sat, 18 Feb 2023 10:40:01 +0100 Subject: [PATCH 0083/1906] boards: Add support for Wio Terminal Add support for the Wio Terminal board, including support of its sensors, MicroSD and LCD. Tested with samples already available. Signed-off-by: Joel Guittet --- boards/arm/wio_terminal/Kconfig.board | 8 + boards/arm/wio_terminal/Kconfig.defconfig | 8 + boards/arm/wio_terminal/board.cmake | 5 + .../arm/wio_terminal/doc/img/wio_terminal.png | Bin 0 -> 50281 bytes boards/arm/wio_terminal/doc/index.rst | 212 +++++++++++++ boards/arm/wio_terminal/pre_dt_board.cmake | 9 + boards/arm/wio_terminal/support/openocd.cfg | 22 ++ .../wio_terminal/wio_terminal-pinctrl.dtsi | 76 +++++ boards/arm/wio_terminal/wio_terminal.dts | 280 ++++++++++++++++++ boards/arm/wio_terminal/wio_terminal.yaml | 21 ++ .../arm/wio_terminal/wio_terminal_defconfig | 31 ++ .../drivers/uart/uart_async_api/testcase.yaml | 2 +- 12 files changed, 673 insertions(+), 1 deletion(-) create mode 100644 boards/arm/wio_terminal/Kconfig.board create mode 100644 boards/arm/wio_terminal/Kconfig.defconfig create mode 100644 boards/arm/wio_terminal/board.cmake create mode 100644 boards/arm/wio_terminal/doc/img/wio_terminal.png create mode 100644 boards/arm/wio_terminal/doc/index.rst create mode 100644 boards/arm/wio_terminal/pre_dt_board.cmake create mode 100644 boards/arm/wio_terminal/support/openocd.cfg create mode 100644 boards/arm/wio_terminal/wio_terminal-pinctrl.dtsi create mode 100644 boards/arm/wio_terminal/wio_terminal.dts create mode 100644 boards/arm/wio_terminal/wio_terminal.yaml create mode 100644 boards/arm/wio_terminal/wio_terminal_defconfig diff --git a/boards/arm/wio_terminal/Kconfig.board b/boards/arm/wio_terminal/Kconfig.board new file mode 100644 index 000000000000..cec329c248f4 --- /dev/null +++ b/boards/arm/wio_terminal/Kconfig.board @@ -0,0 +1,8 @@ +# Copyright (c) 2023 Joel Guittet +# Wio Terminal board configuration + +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_WIO_TERMINAL + bool "Wio Terminal" + depends on SOC_PART_NUMBER_SAMD51P19A diff --git a/boards/arm/wio_terminal/Kconfig.defconfig b/boards/arm/wio_terminal/Kconfig.defconfig new file mode 100644 index 000000000000..a8974dbd5664 --- /dev/null +++ b/boards/arm/wio_terminal/Kconfig.defconfig @@ -0,0 +1,8 @@ +# Copyright (c) 2023 Joel Guittet +# Wio Terminal board configuration + +# SPDX-License-Identifier: Apache-2.0 + +config BOARD + default "wio_terminal" + depends on BOARD_WIO_TERMINAL diff --git a/boards/arm/wio_terminal/board.cmake b/boards/arm/wio_terminal/board.cmake new file mode 100644 index 000000000000..42f5b451d285 --- /dev/null +++ b/boards/arm/wio_terminal/board.cmake @@ -0,0 +1,5 @@ +# Copyright (c) 2023 Joel Guittet +# SPDX-License-Identifier: Apache-2.0 + +include(${ZEPHYR_BASE}/boards/common/bossac.board.cmake) +include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake) diff --git a/boards/arm/wio_terminal/doc/img/wio_terminal.png b/boards/arm/wio_terminal/doc/img/wio_terminal.png new file mode 100644 index 0000000000000000000000000000000000000000..ada43bf984b96a90b18670467f890e03ac02e94e GIT binary patch literal 50281 zcmeEtWlWvX(r!yPMT<+JxE80lLvg3LySux)ySuxU;_mM5?zSoJ@Vz}>a&vS4-oGb- zutQ+7)~sh{p0Uth(js4Av0*=a`0zzcR8a222Z*!}A3i!me+GU7$#cpB{D83$Rki={ z0S@)w_s0)u8DBqq==&xn_*20}>pT-m2WLL>J=-mrS{2-`Bd^*0)#CS;k25AP$S zw_twgul#YNg&M+fnMFfi@T5Fh<0K3eQr?FO~dl&iIy7rx)$8*PABrz_S9=94Z^ z`e(oi_dJZ8*O}UiVRR@2AOHLHUk&_M1OL^)|DOhYzaxo;_V6^p{YQ-NM}n!Tr3`gN zRn->P(cpegr?VkzQ`2EsP|GX>BO`}|goL`$WZFEN>CE00p+J}!l+OJc2~5lf7@VXJ zfd{(Cw*PTUA-E9ZG?uCOo;TA&#o2CVJ%0?XH5%OSt7hfoKf7Uk z9MEA5U(AO=e#a%-F~%*2t8~~68}UI0iyVz;^heeQHT(gmbh3Yp6uX3-lt-7-WQwMJOB?A z+}vhtJ7kW2hl*xg2t`ZamA<*ark25L* zxbp;bU0s7Qc%|Na&h!3ty8=_&F;B#;HFTQ5Du>)eKmaFNhGhEdf;A?7tV~ zh6px0g|x@%`%(VOyuRrE5dVsKUv%B{tK&z zWp4sSJO$hC8G&6B3H?_9v{3#W_hJwvF;gHjGqYT*zQ3st;!y6*V&!d1K&DZt&XPR7F@EB2BjfL=zsqcmPFSGe2x(WQI?m% zWqBSfqvCn|^*y~iUuWf|;daC+qSN$1IVYu|xzE{p)_#Axcz>Ii^xh8Vyt=ki^=6!o zVmK6lc;)lquf->@L;YtEu-nU4sl4}4V}pQ#@Jv0g?RxATc-Qkj0}7>Ao=Y!zJeUhd$$x?-TAh{ z9E^aQ7S1M2@kcApfLc%`$KZ6P2n`K&6;C()n46d3+Alkq zFE1|*g6Sl{)ktg{05wHNVJ4G(L=n}4n4b?0)ABeDJigz2@2YQg0&_vpUcq!BSF*%j z@^`@WxL+*U>TAEg-CK7$U*?gn*8XAm&bGUMWSc=UH3>+1#`?}G0w~-Cz?J;N7~|xa z%TYH})kdQ=z8?LopbmmqTk73uMA??~rq|PPap#T9`;Cl@B)9GgUZ1s`%^j7VRRl;c z8vy+oK5%&vo$jI#aS4r40VqQG%A!)kc!0X;{ zx{kg3MrzHcr`7#K^k$Ooisq220jl$7DzOw6NXQx$a?vYYmcV$di_ym z<7P`iZN7esxL7Pnwn20^7v7xj++0F?s;X*v$6I~%=3^n9_rCuQp^)QX?awL+z_a25 z*WBG@vrPbW|4A~Zw2;|)Hz;!V;$i(g^S!aN-5#bQc~;iIlf)^Vy{i?$3h!Cr3KbfJ zc86QJE^NN?wr*-(c8{Qk%gxRdH9;_%SrQ>%mqL=Qjs4_6G62 zrqgMW(2|eGr-@sBwV$t7U3Wssd7Mux8+kki+8CW{w%qF`c)-D+JOLkmMvjbTOhDjQ z!l{{=tkx@kba}6JPv55&hs2WBtwO-Wn!k2<#{N`?jB$3aJ4K`#uaMx7k zmX@0SPD!0l0IUZS*_W5cL)l~|LP2q{z)LaUIZmX4;$l9;dB8SUY;fU;@nF)Z-whZ~ z5nX{)=<~_wA)A{9`~6H?hoTRDiLMnvPk8xbZ#XXECU-uATMxJM$Z744_fYE>FJUDw z`1=2(b}ftxAkDTGNu@VfP^=vrXSZ+lR*Xd~l;Bc>LjWXc0|DrcN*aKxD1j0*6B849 zm0G*mNv89fEo7W0MsFA!41_&s0JHuyOFK@+`wIEAsLzJ%sJtvcU;p0qF!O$`veEOs z1_qT3JZ==63*w&3P$EJNS%GAYCA6~wuvH_#7w3`XbyA87;QpBIVy#)A z?~@$~7Buv|#eN9qC|{6h7vKZPCgA~uH4*!OvMbhGoufU@rbV`hybsFH&n+2sr%~aI zyz0pGTONiwYaYb+0to+BT_8AId{g7NXye;8~$Ffgv^{Y9M>f+Iikk7PZ` z`+N{3@PcMyVK%PPsL?yY1zwB-#bd&EC_QXCylX6Ufm%;fX9WjkEt6Kh(ouq_-R@tM zHyIdHU5%xm!>Y9Reg1#q=np=f#VYPz@7qyrud_+IP6tPT0*cunOWWWzoq(9%V@fORvjO_O6a>w!k6os@u8Umc%v?q zCGRaA3XMHRJkOihQy?5p1PICM(KA9hRd1`~kC9}*Wf=Rl&K7PxPc+*fz5$W?S%&8^ zp)xh~xT148n;fZ82x1V3UDsc8Y|#Nt`jSq~ti&p*s%kxTeL~E*+Cz=j-kh6bT9vvQ z{ww1pFQ@Eqx&$^Gr+vD$O@+op@f#Ido(@Whyo#HfjIW5WyOGdafCn#mUiS;(SfZK9UhbM_s!g`AvM zFdSXe76qDzx5M1g52#v(S@k?eJX>A>@dzJbrLtgv5B}0QHKm0*kIxq}E!S0?blSCU z^C(Sah2hbCI>O^Zcrs!lLzEhtCHy?s0^Y9Xl;~}lRvfp!|(})MMgRpq!$IqAHzjK z2mzsF^EpacZvSE3WZT|wzj&Qlpi!R?lacs#Q5T8^xrB=Tfvj6ZW8WhXIwc^t17wWD zXdVpd{9b1|tF+;^YUw}-kMMs}XMz>b77?AxaUrJ6OQZMeqIF|KeMVNE+yMWWV5L;SSTe>~ zKJN*c7bEieG1y<27&R=@5tYS96fPz3>CoVOZ&hxM~ z#=^ov%|9kehDjyChaG!kZyP3H(_ODnsWX`_TJ`?x|DHjwy8{)1Va5Mqr2mezrzA?i z{x5Ynv^}g4)8T_YTW|F~8l~&>=$Vz_y?v}yZ=?-?v?q#l&%^LH1r@2#WBIca1gi{M zioX~EAkMrdhm=1neK<4bZQV)Ve7bv&!eO^#-Y^**p3s}V_hm0^ng@{sq<9M|WtQ02 z1Zk<+T;@3Y&1I7UFwH*4%F4=G9ifD;V(=wA`2SnBYjA~tcBW~0?*K0u(Q!Pp?N zL!yLy2C~|L2&r@yX@G%0PrjXMYro@IwUM`AjFr@fN+$8_O|xZvs)-i7$fg~mAM`KI zay#K@nteCF%V4LPHpoHnW3+X5LFfzZu_QwWLRkUFS_U-?4!3Vo!(GC^@bLC1y}3|T_ZA!K>nDP4g+WGYXu&yf zl@g&uEkpTYuMhX6db2M$?+beNa3NBb*sNA-2iBga>fTLzGZOe0$71JWlC-%J9;O>3@`@A{nx!r$QeQ|cg#=Jsn=PTfgRa-nH`-NI; z?bwh!+v6&zuyNz5(>TNS;Q67$fq*m9@493HjW(kM5Qus^WT!=9lK?uw#>>p*YbW-fnh2pG1B5?LTbW&5|G?g3L~_uaaoo^+&j!H(wtk(^;s8 z#>Ub>z7(`qC9smS!{m4=wh@EET?qmxRK|H71ZIRZg@fY40bSeST2CZ_{6J<1^XP3?BUI#XmmRzwrq6el#)QklD}qrWWJGH8 z`C^<6cclFrs2Vm-hlhvwZ98F9JWb%I(|2v%?U;5p2&9ZMbc~6lB@S$yFEH>p0788A zM`_~uBvDGL*c0Ag>?gBoD<4Lbt6l`$ga_~xyemO_M$pnmWg_PmyHTHkV;|_m9(supjDYUW>8L!n z9}i^&;Sc7Y?=N^iVT{@S)=3hy|5_wvz;r+C+0WxENEb{Z!gs*tc5_5Ix2a*j@px$c zv-0^+UQW(AXZxp=l{5yV@mY2e&h`(KoGC708;wZNPGDDy9pjS!h| zTWuO&5E^rf~IGrkI|dxy%8*)GUE=&kHn0&=*xxHiR; zrcd37-VYE@CA@Go&5-*sTjG;t;%oV%sibg#N(|U%GK~3AOiV2&m)gx2|8Bm&ZKzgv z+?^yweu*qDDl81^q7FF-p!kQw$GgNMzgbuM)1NM(a+sP9({Jk5?dSb7+r9WbZM;3J z^P(6hq8<4YSmggGw;+35hKL+8U;5CQ{$t`_Kw*+x27J^tjej;g{}`GDQnYz^c>@z3rdtDggNBTr+;UPu(9N zC>+5U2?+_EH?G-@u4Z@a#cdW86`X_ou}R=^XOXl?ka+)PxQ8mX1!9spxi#$GuPu)9 z7frj)*{U5Lk3=Tz6ivfXptw2{-Q2DS3{&u-C=7`}PfW;hEU`$vhW+?FRmb0cIvOb{ zDbA1!J-7|)0EzZ%QB_-Zl&{plx&4K*o=JU)34Y0{YTleN%E)*Eg@Edf2Fugb5)pP^ zOQPrxIGAGC5TSUTrU(TgCt~qriW^?f=iX`F3w|Phz2aYV-fmr+m#;X1qs9YA)xY{} z^J`f81MSs|B7OzeHaYL>@S^kinrqQ&zp+VObBZ)i(Px5FUEybF8*dSDK2R~5fQ*52 zi^sc~y88UQvUV+|-!*AsTm#VDI{k6TO;Jh_?AGFLM!;dZ&ovVtG%6Gbcqs*XdvX#R z15k`mR-@r)(&hb{{bKR^)6=Qw)p2SNNp{H{VR9_P@Zk_pO9`Wa7&chvy6i)puWVdj za2de5PP55e@*%#YJa|V)xYL53@ppA)AJRPx2Ym(-or5j>Pf z>R-@&^QEw|>kuV~g(eB-)I4zAa6K%y_BvHR2|z7kCeE^F9!tG1?&=9W$uJCre7p^H z&|pt~01BO0+JoWwQb-W!iHde)^Nh zW=p3(W)R=~rfv|=bMNWu>Z2Rr?B8$b9!Kh!Jz}*V3&00R*V3`x9DJ@;`Veg z(t9s9cv7vwV);-_T}`?t&jhvfPaaGp*4}i%xMx3{?}Lf4DRuIJ()r7JzMQ6e(Tk9+mVJJqPwDhoSLS%D#&9C6DIh%w zo0XoKm#mN7As05RW`CTWOA-{IN6{QI`Vr0Q%d@PGc~<>}fTw-z%rId)KhRLl1>Q{FAsSm7!#jniD`Lc4udNa$F zDhN$Uo{osMODihaATe!1yCYh<4B(A$ zvPE&8a!|kGoEABL10Ty_Ez2u_e@~WX5N0csViD)OZ;{FTj3sIsLN<)-6k^rGeL-RH$GoXc7e48Qf)cbqa858r2*Gg3jCb z_m|I9$H%7TvM8p`Mn*=bIrwM@1Ym%~54;lYfdFCxumi7$?IN*guB)Lu*5r0uQ%%iv zCXEUaeJ)w4LzW*YSJp(0o8KyS$6m?sKaz}nf5du77CZBeWN24Fk8YJR{L&1a_bW>l zceQBZ*;iuCqmh(De&b}iWm*h&=KaELMJQn;m>b+lVN>0xz+Hijun`&YY}B5k!a5k8 zodfPT#3O+&I)z0WKt(x1I1_$3P_ua5KRX+9hJ%B3;&W+$=Yj(h%Kl5iPGa}lKL0Co znqNNMnis!;f%3Zql@c{Cobq$1$wyYA6>YKs9fT#qgCH?JI8Oa-98nw!N`d_^?`@Pg zx40&)L_=M8^V3?@9Gq$jYQj|`Lu0bXrm9g>XH*+%=1Mi{Ej#G^wdJ*t*vy)Rg+x(| zzY5c+-m=X~Trk{^=2oA(5xokMGMuw8QmYK*Wfb+e<>eJzVgJn4)RV))!M(-B$G3m; zOYoe7x-t-*vJ`pVNXhxiUTHw!!xGz%ltjMiIjO0w(X6+>+;kK**zammcQ`?PWrBM6 z7MI$^mnbk}M^7sCCG&=tvfSjyn;)@YIt3v!Aw=s6LTOf=$N7o0MDiZKsAywZY-@^^ zMmj@1)jGSl-oAw?PYK5g2ccZJf;65UM=U%^_>sr$1foL!f;E9wt&pbIqw(Aq*0mhv z@gcsM*k=Zq0K3ZW$)7LnM2y6{y3iAijEsyUagQEbYtdPJ3i?A)UM?E`K$zk46xjU@ z5WS0p@~W0AvjnO%s>|f2zX+iX>1h!5eS|X2^sGBv8k*Yc*qVh z+xE9Lr01qWZ*T_sG;ccoC!tB=v;*#$?*6L%wJ^U<4-wqGH>Jj|aGjiK?nppi`7IzsR~4cy{CXkO98gd*;BI zjWC_&BD2t-n1&Jk?CR)v`+HH#{dNz?1Fue`zOhdHEX}d~jvR+yN<7F%ulxCt@7F$y z*wzvZj(1Ot{i@VxR*`V#3sV4Ii-W7iPVDpBlG~hP{5Odr>92OAg(|%J&IwF2q|qd@ zL&K1;NpARw*T%Q6-v+x+DE4FN@t`GIOZ^`;d1~?OI4|GKEZ*M3g5g~WiHTpQYU20O zhWULk{=*Ruk&%76#!5>{aGuJw-v)Qcv)!&FA|t<$6VQ9X)Aq1OLE7tNk1vs3g&?3} z68Zil)&Z%K!{*|zjt+mBr0S4Vr|K0fI{oJS7V1!mtlaD}s_E>S^1LQ?^W!o@&FbVd zshnQ(Bc+8A0 zoRTe!T`kD@XDWnpQ<;L(P|w5p%-xOEjNRRj;pp0Io+iDX;;n%{&58)WOksM+%sVDx z{rG6t4bYE&wecGfVK*6>a`DN`V2OyiUWYzi`a})$u^h`8l#E*XtIEy#`LZL!|dm=%Q!AoVdy;kqjZIiq&@r0 zF#m*y--5)wxFM*>VuS>Nos)j~s0cQW`0ITVq=LH$IdINd2IK@HmPmB@1M1Z}ZW_1M ziJaoCL;RDIZw=d<&e7TQjWPcxo%TfW=}I6v?FCZr(Ag}P7hAEb)X?y9lE*#aSwB-+ za8VR4;y0kDeTIbe(@>9LfAh^P6jHY3#-a6TM(hYCRJ>TJNTx*k7k5y&q{uyc)m=_6 zcLCG7u6mL@_5AvJDfS7cf_p2pvZ*oFN+-0`HG^SR#6z6~;r6|%O}_T>%1XN7 zjM{oUR#aZ8Wr)FAdT;=bel#J=zRdm;vw3W_!Dt0?JyK%*6-VnP!9G1*om@X2$i%$z zNCrMrFrn_U*SN(V*pmcP(n$DMvTQFC&vFI!l^NX$$wpCQGWY3g+}F$gOw*Q#c)BQIZD(;&C! zI>QED)yd!){2K~mv?$24EXO5GAK!6(%dY+O1WDrHqoSNbv6|Y|%^h-dRiL9653KnR z()w2^&W>5Gh}D{$2TwF{e5pRli~a-T{gTh=|MGYIk6>>;n7TU0J^ZCc>#@$47vp5! z*Bg0EVmx~kC$?1QCQ z6%HX%3e9t1FdF)ig+gH9u7a~Thu(KiG=^4B_~ZjhBkDB5%jFHVO0{&v(zX{{q{K?m zzr!$OAfUm!Q`=rfpr1W5j8c=HH^Vr^{hbEAChd{qQ6vso$RVvjP=C5^{a^vd{_kT* zQc@Ci$j+TU&j*bky8j~RS*{c~l$nVo*`5s$Z1}RX~@$Dsj z#0fv#84{+7IzMp+-?lvmUw?$Z_dPRK2UspTB+ zwRUFT=odSy$1pZ@{DO?6>}vk4!5i8(6`iu(xEfp24Vu3Z^>vODIXm7an8dC$YZli1Q_{-XT1I+y_UW7ekZ*7S=IAO;0{S@DJ+|6vJlXW^eH;HxcR77@ z!nX@2IJ=}Vlu738z%K*Ih8+e)lpaE^M?|B~|H@D049o*kFFaxxrgH}AD(67{NX&Hc z4xt5`>QivR7g|3-wMsXT{-8byo}BF_f0xINTtQxlVvsBptj7>{T& zE`7)xbjGx~W;zr$I|#jgv{-hVg%RSf;VML&BLpnz$l0n#WXB;If)->N$G4HpW}{K? z%yueOltZIRs;Q-A1msfthP{Ow)A=+RnVG*GdK9prMPnTe1|_zgFVlOaXbr<#Adpft zX>5`g%c|}u6LTpQ#iad5#{8Osz z3Rlw137=*NMRngLrIa;o>{*Fji%}s^6Y2Y{O3!nB@#=cv9lE}36uCi2xwJy^-cr&O zilG}clt(bt#YsAfV>tG@EthgQcpSy#IV2{l=KzVUgHx*tGb!1u3TwL*$(f`BF$=3_ zlUO1yTTF5s=L1#l*{rEIN_s4~1B!tnFC{w^N6k zeXlL_EXau*@4}3!BBk?Ull@~r&#w>o`Hb}{_X_F=QnxupY%pw*cZ{$xhYW>M$f221dats zRQKbUtL&$6&5OZGrOcUMkq8;k`}D<&#nA~WSfq+Z4Am++B+3f9Y+~7$GP_OtFhNhcHJ3%J4fgpIjtA5uj%p6FqGEjNLM_b9 zC|#e1$tRmGI(XN9dp=L@TKWV`?cvD@^^%ntYk_6=6aV_;`?R|B6n-g$ma`mVT97(tNk$Yh zYQZyCp>1u=JRh;!Q4(>B#VCx^`WuVy-^ z`96Pz&$KWQj}2%wmiI*{@Dg zGZ)+Hx_1xbcw$+3rM$QMJ#M}6J#Ev5A#a}TdbnMfS+GuJ-Vj%jJRyZr-jrlmFV1Rw zKv#kvK4iIaWtt~2h4WHUQE|qkaTGKdbsmrR7QGKCanfhn3^+HuZXk&kAG}nMYqs)s@1w5>P}czc(!-u)3ORMPoBlYSLt| z3XW&W7Qn*B?!~88&M;)m2uWk*E4)NCB=cZMsvC?9ISXjes^2Nk`*obPw8dscCAi4Q zY7()?%dgaA4!Ce4;8@=PLpj3H%=dc&ABbvy7uGu-ee!;qZ3LS0RT4mDwitIZ^7~56 zeh-!2Y*XfEft%1RzyjMqpLaF5;__{%A!aQWRp_BAm!4uJ>3bOLxPCDU(6C)g-bQaW zi)Fg(I6zCXHOe9~(%}C2Qgviy$`QKX@{8hoz6flIb9r+u!(2wH=FwWdg1tm>S>?Gx zV(`keREc`MBdBg`Z1}{Nic1JRhh0V&S!27Toq~B?N=_!NseiraH0o9^><_2v-bR!C zwX>%{drxoYN`oiW05nzUgchdmx3Eu%r8_Bg#2u*2i4Q~{y@6^b7vtx^4?Fa5wm(NJ zs;je~^6}rcFuh+-PwnYrUVdUp@}4PJ`PiXiS)3a2N(QEjB0&riAL)JcZ6vD-?TrYm z!5#lay8*a_v&hDa|4mz=7J(mZ<)uDlXfVb$Ez6ZBG6|RbxcGej8CWOxBm4r_L+WhtPE<(ipw@yg3>9eIrpFKA3c=vUdyNG89*Kkf8(2)ZTzygpEu=InmX<1u0(bGEpOQr&3E1I3 z$2Pv{j(+>;8oCtfvA2TsX|y~+>7m_oLK`&^Z?@`EBgQUA$q2k=rwx`!=~2EjUMjYK zwlb-majDF-*13t8R(H-HY}%%Yfuc3{f>>v9L(~Kps5LtrZb8b&c4vdzT^<;Z&K~S* z-S2nT>A&h3yD8vZhuLC-`O50rrit%Idj$zM?`+*7mg#Xt(XKaMALLM8cdT;pl;mFiHvxP9^6!OIQ})ObV)3;LqijhF)68}tdzc+h<~JKIW1vw6 zUX#l=7Cp~_Jmm}4AK=s`QNz)GyA_yOy)v3LK6>Wm8i!&;kfs%5EOZJ~txKIwm`gg7 z>7SNkch*v&@T4wM%a-?m*6jA4**Ui4yZD)NauR;2N~w0?DRiswL50%VV_2Eyjue*k zjSAbrNN`=#9N0R-aWsj>4Di)u&CS!Lfu(^Z%UK&{DUi%Al6B3q9H#_6pEN&~=8NT~ zifRvdWx)j+@qXGrc!9y;a4_*0o|>t(5gUz#D{d1HLQn+eFdOGDyzV<;=-47TGl%(K zf@1jCd|fb7;;0!dR~&BVtF_8$+iw^wec>Cz9Ewc^bC5&HoEQ=Ub}^Kl19ON^`W$g5 zC^Yy+IIMCBoqv*pXI+QYqvofFk&-uMrv)rGJ8+f8BFh@8lv)SI>s6f5VZl=*?+<8n zPMb6OXpJo!{wMqqWPxOzOUVBy#$E{QM-9+5!r5jvx77=XwPC1P)a!J0Qwf-SJIQhf zJAK;AXUO=u8rrn5=SS-oKg{p%^tEaCCy~zJOTQ&NnV=52*_Y7pmjiVx+3SN$tU9t2 zrx+gF$c>8@ZTQ0BGnVYsa}cUmPeL)Oz;TGUZT&Y{lfHZnZCqap+vIefwSt98&2q+( zeRkgY^(2gTEB+YP?(bhYVc|+@5y^=+>Y5zfexF)8=C#QV5@gD)S>gbBT!g=W0zGHB^COsb-2;x+r}88>7=Lb`4dvBv?HDaR)T@Ap znQY*xJZD7;5q)(l*zG($);vW8^;P4o;fN_o@|k;ggeAk_Yte%Bgnv`$Ig4%L_GOk4 zjq=}P3FGgp8q`^UO~5L0E0C%Qn^~Inm7%#gCntW8ss8(=c?6e`DpbTxlE|u_RB?)^{f&(0DMvcv?3ZMN|umc_4i#Ld#7=`R`f6N;Oyk4DU| zeer(k4UE5E101cDT}>#S8O0uur;Rn%C+eq72av>vZ2K}*Wq3X*io|e?$k5SQT>*`u zT)YFf`2{dpz^SBNZAWd-C*^-ev<9IDN1ae#D?Sfu5YtHe{HsO9cUds(8v#O zNhKX4z)0TNIY(1t@c9m(Z+e@stf1hl?;hEa2;syrha)ZR9xxP~A4Mu2Bxxysq{-nj zm566b6$-n6i|nEBoT3W;D(Bgf4AR6*Um z6`Lmy4SeOW$UK`*CX<<$<@Tg{+XF{e0+d?mehD^BERv#|Uvq9;hB(ePZN>f6!Kb6E z!hZ%?u)3Z_vv>qt;U)y{FdmG{FKW7Hs+ELSh7-*Obdl3MDSwiS;yxuUX(8w|;ch!6T+3X&e5LWi2V03lA$N-o z_C2hSZzof3o-|n_kGAbE|7~sdn;`dP->!?<1pGpngn|#5ll)Hm8T^c3Cf#9T6KJO% zqiC1tLIDnwRRjx%YM*eDzc-a`DF9$d~@C~Svv?~ zNJ3H3&`_=^S@r1kcQGnv$WMsNBcjIs1QmMYiHt(4X2((vPcW9+?^Igu2A^wK!Dnku z`&EryB3#NG-EPlSPKmcYWX_cDSB^8n26?xiB5L;Rkq-=_R(gBK+5Ludm1kBD*R#cHFr zI_tC{gf3rh_(2=vLAkQlTlmv_wO8rCg^v)dEZJ1i1Sh?Ubi4SNGY6p8tpwAT-*pq# zOCeu$M3QYksae5$g~5wB-{!Dz6W&{w3^O3qLTgvcOT5wswrkyLp~0}+CLbLVI0CP? z&R?NloJQE$b0=mHicK6-O{{W~T{|x|t@os$c!phpUDljwnpR?t2MR_Q7_pRWQ`0S?ywXhi?D1M$t@CNl+Po3V9xgB8XXEWaENR~08(uUezY=}>-UP0vKN za167!%1n4VRJ$1JYpEc8>`8kjjC){$q=to6eQQ`i-Q7L-378cl?XlxQB?Glv8MxzV zU7CiA^THJa*vH5=a;+|$J3Wu>G&eV&cfV*acRJrFZMmce-$XbxU|6|2!qz}Zps4!a zhv_~JY54CmUN_UmQz)yub|tfso{wj%A-FR^~LeVmYXKFuYhL6qT8fOzd_|1 zHM8M+eSd-KB$v-B9)3+z)#h)lO3hZ``bNU5A@pSF(%Tql_*&_-Zqx1~Xi-LCP6Vd7 zLPffB45!9Hl#Jq5DQ*#CZMlke8ZsFr1WKcS>kVVMqA$J$MTJnG2F~FcS+#~W681fj zWA(OiSSl3u3E78i3yX8M+>@SqFgr_Vg`J*&r3C$3U`6LUmnu1zpuSk#w|HpjmKoHy zn87{}5S6ig3&Jb&1*c~U8*^D7>vZy>@1J)aDWDwFsg};-1hoi_v>PqDvFk9@bm_Ey zV6Rvsa1KYVJ}V!Uk>#{{_6`@z?j!W9fh%KmoOUId&MJ<(s5Y=I@s)*nzC|sZ)g>-xLph?7S5BFE znFl_R|LP3U%yKxE{gh&L?c{jjLg_0O3*G3gRk)74*G4OMx{S@E&a-&n*Kw|f?1*|g ztBA;8e#QX=(L4kw%<2zu?i~EIWW~jImh7{-?lgA*7DTU?wc2+42sejzBR>U z)$8QC-Oex0PkOz{-#+L^lLk7~F?B7@vwhasx z#y2u`pozFD#fY%-FsyEFfl#y-IecInpC@i!@~oa#k|fs?2KL^rIiM~i_p^3^)ea*r zoI=o7Vp;>!6yZk8;TsIu+^EfetQ88hO?bm$dYx!-pD8L;ZfPJ7VOJkO}8Bm*I_d zrAwnD&t70V>!WDZLAqvHH!-K!@Xm}f2UF>T4U6f8chb7y|H?z@X``+Xw@R8z@C z6`(_e7#WE*TU9c`Q{~}RwXfD%(sY$1?>%eV?uDl!n#PknE6Z{Sw7=l0`B{cJb}esk zsW51{?$e#fc)#Sg0J}np-#CyUpKpZ?8~kfgThUNB;l51#2w7|=)^UyK=k zrSi80nG8BYv)C^SvJqBeodaDw(VgiPI*jL_Ct=5N-Q-U6EAx(XVqTqE zKcuBGIF_}%-dza9unZL59;hJHl(vc~Kh;c0j5+QsOVRpCR#ay{jv3Fhc0AHB12e@r zeAlQh8|ETYieO~h12=k?C-0svFj#D z6UBJ0pE@>}P9LM`G*%~16poitS$Hija%8R(M-s1liptzXNzX6OhgzAlcY7{hPd_i_ z!?ycHXiS^8zK!3`ML;bkDkZRr<2lRfX`y`fP(n-l6qUkh19M|gP|WJ&;BXv3@NB3( z)F!iZ_oYiiq1{iO_fKn2EwYl-aXOFQ1AQhA8XvEg@i%cARl6*=^ZLbk-uLV1`C2hK zXZZuGk=fr4^Qq4wwrFn^vIs~9s7!bYCX&Wvfd zEp(Hp?H#{cz*g#PZq^W97*M<7e-@Kd#yp`AO7!|nF?Rh<6@J>${)NNHsMLBKH9x81 z^ezUsUUW3khR5;;t=T+zC#LySoA0XmEEa#ogVC zyA#~q9fEW7z47k-1q?FINY2@N&AHBQa`W-CM+R!c^*aW(+=O9%1jyJ|4KCX|yJr5I zn*OEvk58@VK5X?taWAb{S{4F^)p%|S&TyPPqA<)3V?(#ryU&>{;1F4$(9tu@%@P{r zcVjp|s$&su?7)71fh2DER0HxzDJm7pLr)@8M!Psd7Ql+skq(oeke(mExe%31;>I(D zRLgHgHHy3D)vh^>hD$WG(z6!+V7$YLXpNq5K#>xfggumy(%2e5CnOdZ({Gs^9_>E5 zC0DKP`D%iDbj%`_hnha#uHRQSG$?Wd06m$)`rl9ZlVzT>wFNs}wiS+sODi-R{obCA z#sJBO4N*fEFb424ss>B>l8H^>(_X4&R&hn=tF28}H-heu$M!ZB2d`9V7Hj6XGI@vP z-j5}nvs_Qn)Pc7d8Q+tmi3IlAb2t0U zv!T7!&!Ezmr@LJIJ!j-G z4tpI}9_F!uOnC9mm@nrk86n1|??BkzZJN5vdfTJ_h`j9W%S$A|dE*u6iRkZBgJTE} zlPrFv-ql^L@?dN_``$1xIG8%M%Ue8Ktgju@zXqG;xj-`bT-+oMZ}xy&DX@Q?^mE%! zVty8FpOU+X+G#WWvZ_??2KsNy!hkR)1$_y#ZL46%KgV{5idO-HBLlnr{eiZlE?=O&qXv&uL`$8@Gr zmQm4l@*JoUKFM=-${yspJx!2eiTFSa7TSKNUk!yd=vT2z2Ypm`X#i3kykME@?h z@0WYF2cu~HE5w4j9^F&|xTFQJ-3lDtIka7nKDuIYimo z7NdxJ<#Bua&R+l6lc@2Xr*dF$UoQVvU4F4dxlyfTxlTKFB6r#iR3oarZgcD#sfC3n zVnlIOfm@*!M$o*Raq{$ukB@6v2?zRl{eoG;$j#(O>H4}xjh($6!PjQS*RwHSp`7OG zK$>si7Tx4a3+aR`Kr%-@5TDakMU%^R@H5Lztp4Gh#I#p!6>Hp`LO)BW9n0%&Q6atm zb*@z8FAygx!GW^dfyd|8Z|$M*fwrBG8uj+eb9tB<{R*@I#wHNY!B&Kxn`jC`G=zQ+ivgq_W4g<2HO>9_Cue* z6)-}vsBz5~HK|S0C-Xv=rX8a%wv7X*8PnPn9|a6+gkJSpRnzB(!P$`9b-JGe?ducn zCqO0l39w8E92Y}xnL8sa%71lWCb>%*hY@RXWI+SG@SNJ(0Q9QMy=Af+_ z_^cy}}5H*aGP4_x%Uj!yi^}tQ7l> zWk3D1Tb6t%OvvW*$~BBc`o4LKo;jGpkRQf|@}SjFYOtei1fL&cXM3!CdOtKag4!~1 z>XG{5B_!G(0OYK%M6xfpe}7`Z*zojkfVJhoKb6yxvOWuzis6833nwL_V}W46U%(qi zlSEcDTL8ayg_ncad9t5YUE6xtlF&O*n_Q4)=65$3PvA(}S}5JrEDPjLEQ&k+2nbVK zzOecnG9H;$Ij(sgtJXiiK;yex=>LhU%RQ5pr@uH}eIB44{SZYOZ3rCOUI5l<;<3*z zF6Ilrf|ZKSSG{Xl8pxSmHi!bVzaBHn_p^pC+4j}FHB=H9h8GcqwZTq-VZAE0k38V> z@uqrNu;FC^EB6`qDC6F9g-F+Nmf~-B7S)!EmM8xN>7^#)02ZBu%*<0mmpp>zZm7x; zoPefWwM|%}8gHI?Ua=>xmBWBL4;?_uVPbSX!Jgx(UZ4uhJ$s^m}@pUVp4V!RS6mNVXYff78EKTDuFVR%J`b2QpZz`hy=s{yf zDXG6C|4hzB)ovLssuvh`Um_k0yCkeMetsD=_DS?dY^3T&6CKrCu3>HBZyp#!C-v<1Efmmy+|Ie*o969ajk(OWZc=(__1`Mo>3@Fvb_5=6VENe*4YGqhmq()O zA6;z{mI+9mMn0kPVvzH$siz-SBI1uiKOa5#N8P-x`>!5(c2Oqy*)~@%?d*Z)Zox_c!SV4>vb_ z!B6&GDRQU$fHRi}4HqdQfSRii0(;tBuCsV$bO$g0Ch8U0K+ktTgF&##xgUvu+vv;Z z&V%i9^v}X=ZW|Mx|Az`hc6n@eN0Nt@jCADu>?>eK+^t=k`_QZwQO zjbi;H+F5Ym$1qf~-|zA88iEGUk2X2px6+m}d0*EVzn3$49OiZ#6R&ehj;Ob?c$}JR z2Af898EP4o&Q%zc@;JOId(l7l=4OAZ9k9T*8TDG*q4Y}cVz=r_L-E(k6<(=RfvD%g zAwFiy)~@h<>LCo$v$3)U zGl)0m{z@UbF<_DKxl+sS9&^ok^m}_CIaN(Qr47*2*|UlZl4n04WDiJ3s}vF(iHmmJ~N(5-;{3&dM?O z_JX|_-R3Kw1p1|Neky1T@`xj}<#x=ieIDof;)Jg1_9s^G^lwFT5R`10oeJ%c9`O`u{JcY{%b`Hp;ANGuD;hfoV+k-*7!wm1k4}zUyXjVWWvHmfeC;W$ zE0D&aYl~T@k?d>eI5XD5^QcEj$yb)Y(M(* z{T<%wRP33o?Ce5=BZvm~qb@b8fq)wJPuGi5)zeJrwPQv1xR4b#1Xd%?WH)WL%Wsnz ziJ9#bbOOg<1WVSR#FQ@km)VdNxQ~JV?Ouqm6ySs$kEJ`WH%3;x?Ff_({*v1a?19|9 zvZu!$_h^lUF>aC3@$3KqHyufqElIn_ddpe|w^P_(!sdPFJ}13`TvHF4q2`Vt6VMd8 z*bw7)yMEZu5;z;Z`B`HJ){eWZ!JUrvOWYylTCw}?vZF_sLh~Y?y`Ht>1wqWYG7XIK zei+ee3FpM+~G4N5aH%N00^d2&kXZ_m2Ek%aBM-MYBMk>);=I4#LkB1YFTW~2V(DkXhYTx*f zh7$}IPTA`zg;W-%T7V36ENuCP5@_DxmYaSTr`Ye&GE5?(nJu8#=$H2eI~F;i6v3Kc z&bDhM7#IJrC3y|W^GPruxqw-Ku8>KH=C;1tRC3+t!92NALR5vV%=*VT3y@pqzXbPj z?B@&*=s#{XV<3M6LKiZ>3wwg!>72bAAG#M&XL{Ydg2j5<36Oj(y~O@~;%Qpkmz>>= ztzHGm78E=Jf>Meq3q<{q0&-S;4H!Jtsa$I@-rxB~+?MkR{pjEf(hHPrPNc$PoFX%} zJ5d;y5Mi_^6VxUJl3rydC}V#lX@1ztKRDqWVs0RpZMgOod1*MLlRUNk^{^_O{LIwZ zP<12hokqoyKa#|1R3W^CC3_QlUh;8sYTE^&MhMaVppK*eG{oS^j^o;e|Alu>aX|Vg zbY8PpQ&W>vT=Jgwr9zt_^ZLslUA^VHRy`9=5@KRwH2h-=c6f7wUOJ{Ej|W|O;_CER zFw3_p6WGe6d(*NQjRa84f~>iiZ8j7hBGHZCg6Y8El)R-0aEbHjR*2f)&U%4?dm~rZ zS6L#^43~8Y1^I^9h{zGK?x^3QoW>aT@``0hN@IE|`wC@gEqlQR>tnWKY@BSrXB$ii zt8I*)U-Vsk0q`OmYd#AAxhKiP6ETX=PEBqAcj+cou(eilulDUfA=n0?U7X zrZE7jFggav;cwDpP_K>lCew_xMen53+HLVo4Fo27-_>drIrv`d*}%*0^R9QT)k1}< zB(}DNMC>RI>(xE`N*67R_EV^r%8WX{+poc~@9C}vh)yHRO~7}HSKp?tgJ`)}rId*Q zZOGbSDhGReja?)t6?v_Up5HF<)ao`hS{R-hO1GSd^ANTY2nt!7%4c9Kg;Z^dVc}#| z@^7FdpR2JjC7IOEf;cI-B*cdwsIz4xKKY#XihUy=Cf^0~j{Oc&>*lyfjh9)Y@R?vx zMn5z_hV1XdtWu?x**kU=NyC18$0f zBWb9+`Zv>`#(W(^hA8w{@D_CNBYoMgbuAA`dYDwavf10d>=V9cc2p;i+baM~Wv}%H z)Mb4@Noi?4f?CT1e9I;pdKzsHv-e%gcZy>f%1?$4U#NWaB#!?6Q9RdeXG*eluvL44 zo^}OTeSo(}SKPp2EWl4e?!?NnD65IWiZB7=mgeC{-?vwN(Te>2$Nk94qL|bvejEC3 zi+7AYM%8XhCsqrU9}WWGVw|Pd6m!l0G>}GgaKxXI6?;kEa6P@U=wg`3Z969{c=04i z*?Z9!C>CxD%kw$;+;2Ht+}_@rx}PmwuOqv4j`m8yq#YvANvjqLE`4LJR($8Ll2i7!_2&5>>Gh(0%S@hdvgYfoeG4vTj^2 zM0h1o!L0ZfLzgEERd+xxY;M|wO^|+&Jp4g;X-i4Cu?KY0eZ03c!&pi>;QiLoj@cw& z>_0k{)R!sXe#k3dEg$B!60sO6x0qz`%TSgHoT#Q3PQe3X3DxPvw_&Q%y1~(*F*h8n zd`{(-+6;j?#o6mYR?%88g@iV%T)z=gPAjo7+(g&!hm$ss>${B>Ie#Lm`A{=rM3~Zz z?36IocCqUUAvFDwnWe>YP-1RE6-!2XX=`#qV!yr1!$BJ+&d~CET5fGYzUl?zKvFHo z#h?*z$)C<-A309+!%s^2(SbAZ0}C0ka9c9Qe)xs)}garDN&Y0 zGQVJf`p8$q`rJRw%#>7+i@Hjjh9BJPUQfnVtW(F-hVLwy7*i)b%VhF5cIB z_WTyAf!Xc$wSFFi?3#YfYlQC^vcsjmp(?c*X{SU3MI@?#dk2BpDucoV-x;b=4Vor* zzRlvJ)2pN+Z+BTO#pu_4n48+S9OXTY-e(fDB)|@*UJhl&CdBSKnrNHlhMh-OwJ$pISt&8992KmCGK>HJb!<=YwYYY zQhez(^Y}O-ewt2x4yOjC3OV3=DyxOu&aeL&H>~=Won$DN?^EF^VQDmyc020Mr`lXi zg$1_I-%3h?Pv`#H#KKLR&l&YFdM;pYmlkpz^Rv%7&!agy=B$GHJ>8$zyEzi+wV`Pl zK5V(>kIWRD9C`OGRFu2VjeU6$5`hJ?HLw}Q_AWb|dYahI-}bzwSsE5KL%zk-mZ$>U z@zLQiH5##yL!^~=EEWsnXX8;(^M#73j|109Ob?hoL&x#EkKG>q|H%^T6MAlax7&;Ey6T#JF5$SrQv2KS`O%5BP6C*zG_w)mbb#bW*pW2`R*8j zH%p4J+@a#2naJ?j2sIi+g|gJBR)uwW@vn%e!XY*Xx8{op6VwH=bg22}2QPep?*rkD ze(S=pXtkU%SSQo9Ivt$AgnJG*Q~jf%^m_a)rJ+G7_2`DG(a6v?_oeZr%F@qh>?u|} z4eCOrONGzZh*BXp_jJTvs*LKwhz-;g6$4Qjjozd0`$E%`8yO^wAS@ZIb@z-J3lnbC zZ)Ktnl+|3a8Yoz4>5X>ooJ(rAw+a<5CWl=6kt}6VpBI%TYhbRA7v}19-O#^`sb#hm z-;2NcCxqL|T~4YNj?)S|*Z_-<4($AFM-Qf;nToNJ)vP?vjG*z&H@_E;vkS&3Qb94jt;Fx0qb zb7^?WT>hqAd44(GZt@pw-L*VhJ0TdJ9+aRblchze4UphU+1iOE4>P$8CHAN3mfX8I zUVql~xr)zrmb+>K{(x={`=(qyt&UDiT%F@(#m4=7?lvBEAMuXPw9hXR@^UMke|yx@ zW+NfZw3J2B5uJ?~Lid?E4iT*i2Cb9*g^ z>qX1{)MV(B>~3(mtr&Q8sBkef#vc3gC$eik|GjdwHk8rr4>_puTV%!a=k zA-T*WrCaT5x^CL$aGWkJKUaMYW940zj zwZja<8t+$(@_T~$@m1$r=mD92PmM-Jshk$2Z_g9!f0w1irnLdPKSL*@2No0@s&9W{ zr`~yZu=nmNthW+%TLj{3?32%ms0*p^fb5oH{d${)4G5!OkxS! zZyhDpXC3T|x4}M7QjVa*?emmDzKCgoP=vr;ImTKuV{ANT`cu$9$$B68JZIrKWC`-R{H?Ba|7LjDiq*;_ew;B#A0qEwR!WWS+lN zEf(nbEi!>Wm)FP!oopJTK$mH&u%hDqnQxu1>o)f;u@*JZ+4Vj4u{lp%@HFNO{hS;# zhjD#Eijpa$H-Jb~ZTW87lfo$ln&rM07ag4RsXVgtI+jY2_CNcIYn`cgg(I`2rn=@> zae3*Jq=n|*1KBB=srg`kw+HV?to`kcF7?j2LORcPyN*hS29v1-;hxpd8TAV;`z1cP z`uvRI>6-p;-WHVcwWwr53=r%1Qb@fKi$**huC-_J62lg*l-uuXul0*IfJS8>4)@9I zg>iljce?@=uS6YitxadO#kF{;!$%KxF2}5i!sitD+zKW=+h~EQNVTY6*g78}$GH4m zH`potr6+U@W0#k@k2mXA*{`yJdT=i++`cB0O}*{@IpvN3hov@^atWU1x`^3rm-6JR z5Mb2CM}x~&;d|!o+o&cZQA;miXoQyC^7Yi2i;(+%{^=jbob&ZgC42o&{2_s6o9?E| z5}eC*g@e0XAv(;|2UQFl_C)Ub+XEKOoMWS~QbDBD9qf5}pwk0-=<%vH$L<1{us0^@Yzs^uF1t^JdboLmY>YA@DJ)6EO5wmCmhsb}WYkl40^tnlgXTAKfDtTGF7JBp)# zspw0Z%XL6pK&|XfUIm{sP8_G17-#vY4@?Pv*Yxac-XG%ZTdXCM46=nPRGYzLw(hP; z+^YAgdO}x=S|8Tm5)=*+$K*fNp0z+G)SadI1!of46xG@1=DUm~ax$M}x$ zQbGjCeOdOUyCGU9#z=7owKfnW$5@AuRw6jHZnfX`?%m~;YxZ7^)~^i%c*W-CDKmX3va^^?zB&n zT6FdR?|WS?)8}_I#}|(A($;o%8HR3EqWXu~U1%=O3~)O$m>vSx7WZsTz4N{{+ib@~VQFI#rTdNJ6vwiq|e9*JKaXGI_FYv%M+ja=ks z!`vj_eOzvH%CdBRiy3aqgC>@@?#nxc@ecoVX#Q~su4&Rw1p!4x;q_+I5Z#s={8OH~ z^1nllik}JuR!IVg9NL01wNGINRMFKj%c~uFPZT%GaOn4<%Ii{AMoa2yPu_E}g&xWd z5&MIOcHpXRJ@ADeGBp?GzH;8&Ar{1yNE9wa(0O_5Nm!5V-!>v(&PKyBgB90qXkn14 zWTy4Uu{`w*vk|!X_wHmZhqGTQny~mNmUMPyp^R36F#0&$r8>q3&@CFCw2hhl^{TUJ%2mv6znNQ({cgwIT|;M%z~qeOxPZ&I;0MjNvdVI0 zRa@KE@BaRR^DmRWJRIEDyQ1Dr$;>>F=3?-@bN0($Hr#SZrPCfqhFOam6n&8T-zcI` z2wtY+m>@Hd3f**?s1mffJ{Aq6QgJ!GOq9Aawbj$zqv1}H+>Q(P!het8Y3e5b!Mj~r z^JMcYoRl?a1|RRsRCsu16geeNfCmw!p|SsC&-uB=+f(OTE-JTItue*`#hOU81%2Mn z#vj8EG#}}&$1|c;B^v)p2#*Z?L65f?Co&F9d05S$i)D(u{_W! zsjU^RmGwOn{C`2^r?=RQAuA8;pSA5^QrYzQ(vbpb(lqv(I^&hMTcfuilk-mKDJK~L z(iJZvJqE!Cni`z%Kf>hPx_$@2GK!U2mN^HHo4v{FIiY6Ff~w&K?HQeHpHlJq@;glj zq-^?z@k$!*VvezpBN^hXZlVO@xH;n_AP%ju;+F-HBoO}>Bv*w|dOCT?nL^XD1OX&W7xftF@d7fQY&qEqo^Ji3qZ9N=#qUveTGX3vhaO;@Xd1X3w(t~}CP6*z9iE)+P*;*?SJFp5U zY8E#630_xSOR65_o82A!5kv;(8shi5XVR++Hve$uPTyu{GQ1*|>tI(A)ZcJ7IB=&h z((!(8e?P~;v)FLN3umRuxc$HRvE$U~+>=~EGO|Lv&+_MM9-^Jgv>hspud3gThvKeh zVJf+Tf~J?j=!D4A;5(GB0v+sen4HJ=;1+3o>5n?Gnz1BU=&D9^L(^x_9pWlAp8n6iK~ew*jskNh|*S*0>? zqCFqWd9-}0^vOz!HN~dJq&hkkm=zwqnTN%~^)g!P9dk#-%sz@2z7^12xT#l)o)u>ChzUWT!;e~QJ4-aXiMf;$J1TLt>C1m zX2;(<0;AS{tAw_k^DuGVvA7UcY7eGZq^-ij1NNtYE_c28eTgnNtSL!eIr`%6-=e3W zDLjS?8QNj|p$2D{YvZm!y1Z5r4`F666@r_@>1pF=3TxZz3*#PiveV|#U70U){~h&5 ztgZWQzS71^kWp@jTfsv-~xg#=cq3prEy)1f{&x|)Z1UQ|PDHh*7AHxXjBeAfdb zjkl{k&9(RAw<|p%+OKOHZ%zs=h9sgx+M_-U{w8pVu#;SI?0oC-IeNov^q4nrM{JBg zC=A=A0^FFMrUF-XV)aX_$CU%)Lw8_>4&w9OOcF&wg7XW7`qZe~n}MLbTRYmjo^*RG z?)@69-@3du7@{Rn%t_+ew^jXeqFMB6J9`^es20jAEtHxKr_gT}4YvKb7RGgR^?Fjl zON0E)!go*u*rW*~lX-Z(1}HFIZ8uw)KsbyYs&LLIAJNJ<;uL!v?)tz{A^LGN7KNZD zc`A3Hqzx`~bkuI=q3(3R{TVHE$`U`*>x`k-ShM%BdEhekUp4lh<7e$5r}po3zruZV zLAN;`8W3*3=)8>U4c*W5yWo>#`&;C-XUE232iSnd4}b%}-j}3ealneBw-PI+2I9!p zd=a9yH8u2sHLg&kR&S6S0RgWq|!RHM~=;knnuDN`0ar31oLRB{5 zo$imZh0K=p0|xlU&iL7lww(fc5TGydbxLZP%+?0GJuq22BC5B91UA#@l|u>~MIbQD z19rd&HRJByKfI{A^JU_R()-ETkclTBuo-hhU*h~Jx$oK0ABj~H6$aWe!*&#~utLT0 z5>`xsoR$&LRv~bK)HU__w5GMW3L6S++}3#3`P3G)ifSr18qic@9%Lip2AEJB!(-sVqr)Hk=fZ> z`*AWdzUcH$zuJ$VEXK)@pPeiHJ!dOSBZXZ*;0_VRWYAX)S6G&{bjD&7 z^I@z1B{*AX?RxC|8C58c_soVW%WlNeXurH#HCPaS(`l+kDE^?Q^Hku-WUAwq(m!|SwO?`*l+-Z&R*h~ z<|Jk<#@wd4qMl#mS|~d(p%%Sf6wWPBot@?Bm2_}}Lg`SZlcF~+#9={Hof7fw5ZCD# zftqtwfeZV%02h`suJkL1Aza_>b--HCi|VY127y)T$6m${V3LG!4VXuSNPh=Vid8i7 zmDTj4V46qj_0TK%eWq!{f#9?$Cax`JuWGAHPyem--C_|j@lj8=C?)uZ>8fA`WJVq*P!do+Pou8=9-Ho8R?d^S1+#5TYB+f$_8TRpG{>?O zB`L>v4l7)FxqU81LZShD=`hIAf2AQJy#m;c&Xk!d!N*g`)!J#Dq^yOX z`Sf>qgX3ux?|Lzz_+qj8`#j+t2CEcsQr#0?9pIw%7Em|~%+E1{%y~_Au}y-V<#th{ z;x+EBtfy2DnS{7sRatCh3XznTmZ}}kSE#kBM0Qosei4*-mRVM)W{D!?qhv~Dii6B6 z5ek^hS2EDEAcf|vwc92W!?Y{1A?WdhTb`r?V}w_zFq_$I8|V0fh|O$Kzc&9oFFtlC zK5VFK6}#vASMnX0(_~c;4Rlh`i}1FMJe|!VK!9p_u($6Dw|J!z{J3}?Ru?Op)`DPQ zHGYZ>ctIg#$0&*T=gdUKoOQG=YnKB;D|Y?%EC z@oRsqIa&amcfgl0|CnLV-W)VZtYI`+t&c`Qt&R84O-qLa-;&HK*7+saz}E=DoFEGcJERW)jE_RK z|7r*E(rTE`KWN`Wm89&C&*RrBmp!K;tzFt`J^D$9M<=38PzrA6-a(!~e!FvY_*X%n zrJE3ZX5BiHTL2l%{Qr@f9`;F63tbGc*{@iIF)%Pr6jwSt^8lIlx6bulIGu6nx>+_E z{LbnHZ|}nqRFB4GMCv>6GMUYrbWYU}=+8HUsequm0aR(9HrXMnEBPv!s`;RRdu$P zwJMX$gp0A?bSUL}w}?6mgHzJ*(={FR|Ie+O}>ys1a-PbVi#JU9NmuZM9N zC1qtygdI5pfxS&tF0*P!BlwoaE-{sv3GZi|X3vIfpBKl~^cE(MY-}NW7=YZ)dzOrA zWM9~BsYRLy%bF?uDl?niwtzvxegwN$L6)BD2@i!C`E)5dKu0m$OYVYLB|S6I1v5YF z_4k!E^q)kB`Dh9|31B2kF;P$twqt*GQan8=hWgtEp?J|968= z)vxFK&ae%e@o6wmm#(<>pM2liVdbaUn2dUc$*Hhunp-O}t->1RJRtypgr!y;^oK)_ ztmx}6#&+@5CqIG`Fiu{8^q>#0wFBls=GO@T9uNTmK2_9q8am_d1C(@gM1hWrpa~$*LBx-Vo- z9b$X!hU=WA>hW%xKRP_o&t+<6QfFxVh5vIMz{{Y( zp`k@mp(l{FAp>$Nw-G`3K-#ZEA4d?McUKMGYv|3Fzuulgz2!5&78+6lgCbma$hP)G!o5T+jb|4K?NaQyOmramEjUG{ie>6d?Wd>qH3@-<1( z*+tR&71c-`R?cUTiQvP_*tov$`+HDn!(;!sOeql9oj^$+<`2NWEXxChW?htDkTRo>2*?5_h5BfLtn9b=`C&xJbN#5Gs&CA-+)X^bJZ((6jwG$8V~;0&rtb8H zaJKIj6Sqsh8S|Ch_XCi~5@5SSKP`4;KR7v?aO_`(3P~2tr;9BsyKHv?B5} zjHbcvpNg3EMAS<)eg05y_G_EG^y42ro%ZrCCu!~r-YVrC9{0wO;F4oQmbh(ygN19D z)x6i52Fzg%I0`zP4|?JSt~aTi?iDO{(Psi1>zi&DAJWF^h{MD4v8o9Aw!?9J>T8^#E2c610?w@vZV7Ug2u;UST(Iwh4fR7J#ouh<5c zi4OJxZHQT@YNzCgLzpRZm=nqXjW8Jnj=Hv<6_i=71T!XADmSiN2^kDNI-2ktD#rL` zRq?q~$9o@6=i9XD*{up!_ylo^V~2LIH~@s_No{c|t+MqxD5t2{B>u_#od`>mz9|+h z$^jL!J>3czWfEEf!2O?%q@}sac6ZKUD#9qfS5nj*;t!zFmgUr5$V%8$0JiJIVXGob4MeevIL!r47(5v0^(tus*o2d#jzT~k7rcKKB z+P(mnDFlLU#xDyaQv6Ex_>s40E!&A^adMyX${e=X$J~c|e+)nM6VrF5CwmKf-Pv&y z!@2AXsubm;6xTi{|WJt*+ zH)*2SYr@Q7lph$j0*gPuvaHm23O1)yGI}ZOGPa0hryDfoH_#PJqZjo%x=!(awIdLp+5K>*qiLy5t>q#0 zmmw}GOLC#T{{G+}`h`S(dDW;G5rv%GLhXW_RHo)Y#c|I4ESEEqukm#vy8BpAF*vX& z%r&JFMZNDd3h&4%S6Nn)W~iz8>ao%*Oa}twBV?M{HrD;gz*G#1Rwqt zo70rUXZOcgr3_p*J2bV*3ltoG78v@?pOGR!s<`cZr#rIyyxQtsSs|@#h{Z8IR7`>I zc>OPrbEMvDwcMq6f>`QjT5>xEr_?er(NGw}v7E@2xdYQo-_h6u>j(+Ejc>9KA!?p` z=XARFQk^v{DJ;Fa)dl3`w>lig<@lHtPa zqJIlBpN4&7b;`j7t&B=2n|SflIx}(npwS%dJ(JNBG+nJj$YSOiQ_#O(HpyXSEb=j( z?+h3C3@}JAnF?B?=}@2li{E~@#Et=(E%JMq&o182_7dhT5EtHiVFyUToHGcp5(D7x ze;Mqi78l;t*heBI1~SIwi(!_jN5bWpo2Ng4Ysc z#Z12&9*m1IwLXw@FiMp}siQ;0f0AEbub{_;=BKx?yiTL_V=iZBmR6fBTmR?XZ%fP3 zlxl)?g*)o=XjYWQ*t-8_4|kI;TfVUKH*#+^5G4VDaIecu3{ zGECTKb7Tp=!6~R2W6za3d~lW3qF}~e@w~l`93R&NWw|*l&AZ6Yh(uVy?xrR(9w(1SA9}h0|j(Thvv+}M& zI&bF&o-~Pg?_G_||HV~Bs*Hmbw+$%$8#3E~$;Q9o{2Ob=0b~JUay);$b$rkg3-!SV zWEY!6;u>26-PY3En}?oW80(+p+X|@(WlUn3kdBKRlCs!t;mHW-y1#Llo|61w7PJpf z;?w^go}xH;Ark7lrIsXa$G}uBQKBvSj{5r`Uitx6Wry=F#D-G8vyoCR4FvFV0g?06 z%>EZ=s%Uv+NDM(jlBx)rSBSi+uZadbp)QYj1{G?33G!h9TTy;ANUmDU`gn|dB#F#W z{QW@~r9vy=vnzbA?NEY-{blKdK)cDkjCom>ZWB1PHg5Iifyy#Y z>`j82rZU0z)h4ZDnc5tEs@7rRBWPpV9H)60rV6q5wIwACnWWTb9q#K->G-MGa&wcD ze^!sM8?DzbR=X!3g%-0<3mW?h=0Qh7*oMY-Olr>O6NA!Xt7BM8i51s@`h5%|(yZ17 z?$?(Cb(4yB$ym&=>OX>6SaX^IvizILv2Kx0lHh{@)BJRe3X_9rELtXQn}Uk-gxYU+ z1FD5b&vmA4AxX-j28Z>EIS1_!m$L5ai)IXbWed!RnBsnh5;+jUadn8maQy=ZwJ;S; zS+wPL=S!Z6vHh6%1o`PoYxvo5VZGG3_BPSmbP59N-wQ`T<%8pn71=E#5EH$N< z-?-rJkESR;ccwvMDSofv?-?_UGio!hzX?aR2w3!+SQjT8#o_@O+V%V&I4Tz38&L6k%Xs^~IISujgvty2#z znQan+d&3IZZa=+9KZx}>yb6z?6-%&Pww9FHqgvj&G)eUHfrjnufkr?Sa#m#Uus3&b#yFLPNh>?soc0$jqx=10(x5 zUDi*^Ew*q_#HF%Xd^(blj%Ej4|8Ltil&_m-<8%o<0nRdi#Tk`L>^v0R#;;)zJ&)!1 z$%iT{4s_0;j+qSL4KnpQ8I`A9b0IwC7ZAYxbjb%OVGe0DM&Kg>)KV0nf!;iCWByp+Mv5w8vZpVF})T~SHub?OB;kVKXWfiMVgK)X>rB%5DIEq zbG}qLnITM#(5%V#;MF=554oCNSmV6Xs?$Jb*L@>Ae{Y9cY)I%2+6U&wA{fUifHH#Z zW5}2b@b0#|A2T1BrHU3Ri|zC$OdBp)%mFP_;i-hh(*ggTs;*y}YS+L}E! zFVG~2a}4F1i1BO%g@*+fWvr0CWX5{Po)j2}aC)~gi4vs;^5!5nAB@{q&d?OD)zb zd$dWT_*Rk$KN0-fShp1POPu5JN+X-##;(YmUBoA@zP$qpI;laD6lA&`%Z*H?{Anch zG+zuQrElo*DM@j$s^e16s0o|-rRe-`4k8|4(owhDVMbOuJByZLI?o)I2H#A6m@LwG zOI1!pE^xV9E$r2n5fB$xXH{3$e~Wf|R9u)fd$xtuBXxus=H28!5Jk4%GUF98_Ib>y zOj6_`kx}cWF@$k`K-j{>3rtY>=4VKZpqZyJvBQO7{;^MtB8P8v*xBAPe!}o~3 zP}uvww$|_WVQNxfR#=Jcdl-Ytw-MSLAWrq}*rF?|-D?6?s`-Z4yXO6DV8bzKUP1d| z)nUzW>IX1%&%$1>r>J z6}OO8oN)wbATl*Bf38y5{#f$(9-fZF4TqM~fTOte3vT}B2ZaMEVebWGz|cS}r|;JE zM$pq@ki302Q-@gHiFB zE?!!0c4?D+K7U>QZ)Omlmg0320QPvu{9xGi)z8Z`EOLW$xf<#)UwtExeakQTvgn?& zffN2q{fL#d^KUC=s&0BsT40cT2!h(Rre#@n!o; zWc3^9DsRY7zs786e6uGQLbr4qdQIW4{U5}8EET#9vsDSP70%AhD=oFUza_K%W8FY> zhkG4^S(^nA|EImPe2X%A_dOsAh)5&dU6KMrH$w_YmvnbYOLup7=MV!7B}jL7NH>VI z)OpmS- zL}mTF-5-NKFNd?qASQ`uUzF)5q5Ku|{Rb|^Y>Dy@Agp->7chz$BM}7!<>kQ371j0Q zV^~B4CuIJ*v77w3DLjUo`ty9l~P`2k}Tq@(U zY^19|HC7NPF!HQuel52)5ROe}wa}isJITj74uc{mA;sQqQf_ou(~-VGfbGO}bmoen zIj4Kk{t~pO(qbRO_e8a)yIf}t$63t{vvq&0U;lHvu0iH|mrv^NO;!{S?-{l&AU8Ar zq-zpy9w?_xxMl2UvvY@tYlHtzx@A~y%L1ay*@@0y7mG_38vE@Xf-}padf!fPP#~p0 zH2_slM?^|jB?icosFJ(M$qkz-FSNSF`su_)vCEv2@s|Iu*Ohh`r-p)h;%! zFBP+J`B9)0m@m*PEr3Hbvr`m;iQ`hRULu}8yJmoc#a`LYhd!;1y-$TDG6`$u^UD*U zmgtUpB@@-ZEnC_89IF+SD`YRm8D{dDNA6p7?#+G0#A`Yq!77yR4Ig=eM9ho$84k&8 zS87K;nk#drbnK|x`6Tz&IYZ}r{VD8<@9pf=TM6?95p=cS@>>~q1((fiB` zdykiFmQ^eO=K=vlLj~}xbVC84LPiE5-Pv--d1VWqFAC2%xMivM9!18ByKC{&gWzSG zqUU%1t1(miyc^SWvAwGGs4!XZvR2D)UE3ipR)u?w)o5C+Ay#jaC2c$>w3UJ$etmhl zXel&t1{J#qk4)Q$L7Y@)Q&W%6jW?#4L??+dhz*(}zJD8XE17Cq#6lU0tPJs%Q zgKh;+61{~jGj9+g z7=q~~6?O$QcEMPp9k`BVm5u-i-irE)Cx zT1aLee$sO{^#AtupyV(=vlFMJYddD6TzK8xfGxZ{_xH_;Sx|HknGEEbsTL;NW?_3{ zCKM8@H=(@lwG}=vYu4gD@N>=wu-^2CimJN0SdCYNjx@o88=l83nx~B1OhXyt6NyNH zuMN4u9S_i3d&CrGs`)NlrgaVeO68DnltyUIkAW@c1UY!VJ<@T}C(*NUWdyCr=i%$LQ?P>x8DOeaXkh&ctl`_bM$ z?|RwUGIT*w_H#e;LJ+{$?hK)S)M_{3>9tbr%4S~001l%gFyAO(7qkk85`-+0RHUIc zm!+wu=VJ=cUrk9)PmR__9T2s5YBPPrKaC7^xiOa_lMYSeveWS_-Q0Y76mhw6IlKji z(p-7SFcqb!htM`^+AMYU|AOq|?apoI&st+LJFftY) z9HGto%0(=FxiI&oCv`S@qeJ-;v?_2qG3MxTuo*gQVBn>ukikJv9A0u5@bEJvS&+t7*t^>Z zi`u4nf)6Rvtd=jYFj-AVQtwj6bY@9iU|3W1G%)JS_4QPP4vnSetmcGhR+>oa9Yk)c zH7EJ}>`eBI^MIJ2Cnpuslyi38&FfMP{-G(%`t7)mX`ycpW;e}%GZ+KV^7b5mY*$cY zgo{{P%N_dH2cq)xzcTm{?ZIvrL)ANH+tp6l?=_QZs^FuDiS?(|Mx0rC8Z4uG@P|q; zTj%1Ha^*IUbPRE@(4KKXkNORj(G1j1s@}{qc)^gRZqe;<607C+<))|G6_|00)U}G- z*YBp)d=`+Xz((Gh&+GfRY#xoAR8#XE_Q;tlI(46^h7wVoiJH66be`RnOP+K)U#(M_ z<8wn`+d;&K&~c2}6Bp|c45lC8d~Ypz6?8brLulndMerB~< z+1IfTzvr;UH_cbJ;cm=qI?_L8+qQNZO8!%^ztw6N3H1C$;)<7AcnMD-)3J=L<78xs zWOc0@ntXFZ(j#UB{=RHPCzFvdEoFJoeQLVr zo@Lqv&6^7sDhqCXDm;bFCfw_e$W}9XxuZK-eF3e_H|bwtHg&udyG6_wabvgCPf_s%|iY<8AEbF0)8I(usm#eeWE{LV7*y=$}1}G*@XWP8c z;*#PNZ~;2U&`Tpwdq-C`PfXtleZczdj1>kCm_~L74Bnt#S~w!^j4 z5la`e&0kIhDSh6GFI*+R?PmK@mFbXq1WU*%SQ}aYCcftTaNG2ocrev5-r&2@@dCyB z%UM-LRN7Je3twKtr_trXnH;xZgzBH z`Wc#%qJz%apGioF=Z;N%RjH!Rat+!YR!z$-mQ=bsr`^VT(U`9D&N?a?vyS)tb4{La zcFio%Z`uQUaQ{wO`jr=#KWp^Y`EB?|zXNMaReQ`t`sipISAvpjtiB(O>1FsK zAzMdPwQ&2kH@T+I%$n%gwJMt+{m^PFC>-QA(=KlYTgdin`MFT4qkfDF6et5!d#h9j z1*k`R$6hXTUvvfk4*oP0J8^grOqft0&NGSIxLeC)d!xCn+kH&ec;e{M{IR3^y#3O> zq68+TkOg2abGUE`_WCeX3V)I2R&BG4jo7SQ6@Q>Oe;QSC$as=Vm;eT!=AfrKKefH2 z-d5K&o35@fYz58_Eti-npUXRQDw^9EWha}`jC4wWSlftE0b`*vifQTo`Z*Qa@gus) zCAkor$go2~LRL%(3=a1#yU1yVzFrtv9Nid~NHuMIjlIvJKZkM5^!2shP1U`5hZ8_J zKJRPA75Yxa$KLV|xNh6PcJKwUG= z=x&kS@8+fhPl2VQ*TKBCWcL=0Xra=So=NRH{+C0^k2Dd~co&E!8L1+1*KX3GsUYBg zQ$H;8HqUFuCXbQOO|Xyd?KjFlB7T=IuD#JA zrYM8hR0|ai-gp?sz5H{^J99`)xT~r}sb=Ml{b4q%sd0%CKRET4U8~&)H+fO)ekF?H zfYy~olXg$(edf@$Nz=?Srj~ZcmIj=qlm5xcTOCq9gB!$SVGd zOQHc=<6^bdnVZM!8Ty+GPu)wXzDm=hkL86nVzuzu>SKIa^XBsD6?83#thOw<%e4fm z3NLi`2MsmOgz{K(i23-~dd@d#G-0`nHj%PFYemeErHZ`+XP2NQLM>Y~1u#FSTv5m5=CQ4_!{+kT7{z>uYT<6)lGhH#+48&c&~WN4h)#?B?0rL7 zB(iopAY4|O>#1_O)FBrPtjCqd3>$KnY zeNlIIX|RoUh90n;gAq3A-I<=8$5(<)OW z4n=W@RKLe=+E1ve7mh2*yVJt_lQfW+*LLfSpp9II?532K<(P(e3JSai%b?G(xONUn z)mS5Sd}OD5X+AggE>^l66Q7Aj2QNABc1R&G_su(!AD!#0gCl+?008Rg7Z4!`;+q?o zzfT2tn*XhdP0bdD2oUC(Ys+{c5Xk*V-K1Vf7u{wFQB@lOcyuBKjc7=K7OKiJTh@2R(It*=>mm6L0HJimjJqOf-09K$pk)D&7z}J2oZKY=d`pJ4vo0b3LQyVsV-m>9Saz+l?L3K`id`aZ#alJ;_=g%vj(esz8 z2s5>teh|~Xp2c*wL{;Ey&YRP5#{fOD^qv@`;K)_0lIu4=_cloUA|LPCtvl&*xOr^Q z&lL81einTMIV}M7f>$EHertroFEa3e0hFa;UU{o2KH~mT*wQ11kk-57JvK))FZ(ln zyMCBuZ^)?>H{}ma9)%M#q@Wn&v6Oi;lM44jz%R&#qa4X}rS@8GS%@x!+}i4vt?$Ii z49p=jgl{vEs2AvsuMMt4Ir)1K3yw2*K(uMw1=qHNM+bC_wwQY)Z5osJPp7z%`jOR7 zt$5BUi}k6=6GeN6o=M;Y2_nop&-R+TlMxUB&Y-r;adyykLF}MbQ1SC53t7-LMn=Bd zj{xn!mPIa2Zsh}F^bhG6ndueCLqY@?8P{PS`uM_f)z{RWaX1DeBO}*>SS*P#NWBOz z9x9I=V4oa$8pQ_eGT2b7!jQ;zEUv$pn3?;1zi8*O-m6Oez^YmI0i8GBO{85U4i1I- z9gsu};!DbsX~+I9BQH8O2A<>QHjqH;uNA>ilzh~ME;!X?bi4_y^EBTm z5KxCN*jNUa#Vsmm^74O{l@1CuQ8zb}9g&r$AH3;Zvu&P=GU?z780n4ijFlV&RTPum zB>Ib;E56Iqr0K}El{bnhtT##it-t1*GTbR)V!&!vD>=(bw{rqY;q;|qB;+|LjY$u60fl$Fra*nm`;5CJ?u6PW>gmz;cp1vMS z<{ap6rvxwR$69yH3z-xVPTwV9(l>kqr@I(iLRYyw)lsqpPrs&#J3(ia={qG#0eM?q zf@@HbWAKW))b=0lhvwGMAhmCfq?;{nr-Yj93;BcJGBdBRuqveDyjXHW`SpHEn%)VW zy7n=wp&3@{h@CCxNA^dSr7r3Y(WaiJ!Kys8mKc$0F1e7$0HM_$+ZeaFJ6+v(65z=BQ&1@WcZ0hN^5MgC0{ML0t5sjL55V<(8Ho$FkTj`x^EpHbPH)%o51Xeq1_Z z$-p5{Z0I7$hp3YKOOSu}U23XB7SzzwYbgIang3Cg*&DOwsvHB}QcA*et>#ZN^~7K- z!=7Dl${Lk+P$TPH)WGWUQnJWF#P>O;tReAs3(F7LX zsF8K(`-~?q7DqE5EhN*N&$^wG1Bel6$t~T#_9@{cF|;XXtou+KvOKDCpyc(hbIOf( znoRzNi%>b(I@-LPed|%3^lB5g4Y_u>&QODmesR#P8R7NLc35!worPN+Egba&jrMKp zIYEq~uGN7&&wjua%0>XYjb@iRs{8;U16WOwxfbV&=UVgH93zdAqt8=YV*_r)?E{Qx z7qJp^(Gb&jVDdLNO}>re$1XWNjmKGI1D)TO``9HpzXuZ}BX0|ky{##|mH3bV_m>L5 zNO_oKwcwygB*XRQ)7PBV@jml-me@=2j95Ed3K5+RP(ag#J>6`_fn9{AAst>nuo>cEJ=g z(;?s#8{_< zu1rr@IErhd=7GwVIhc!bGHQa~uECcOD(HDd&+@Goc4$J+Z!~ez-TQbS4yrv~fogl| z-Ny&j<$87A-X$+LnCE(4R`a;XjeSM8hd6jvMX!5iK*>LKd9B@wmhi%LkGeQU%K82N zy2{9yDX!UhyS@_EWIJOTjA55wk72H(td$>|OH2p(y1!3_hwYfrAHlM;mo9@aJQVL) z!Eh8fcl>ope&Ngsj6f*p*?6XvbJlOMJiu$z&d|>Y`SDH7D3|Q3;zU-%*G)N#fuWT6 z_8;*gSU|!_ek*XIeBcB8Y$mZsUHg_w)L*Nxu=G2gh0OG`R9Du3&%P(T5}2P#;M!aI zXzXT8iuv_|wKruYr`$F9X}ndmH6!5SuXm)Obm`kS&$bliIQK4^31pDqq)_ zKZ{48u8Ey@OW6ASh?;DS&C&R}+*9^Z)RVek+AD<^^rdpX>Pf^_`dCsr>R4OB&bvHp z>-V%mDE~-10 z3hZhbNsD3eh({a|8(>`bZ$>3Km#Qkq7j?Ikn5pC%k^6(UCcEl3`}iYRSM*!o4(u%nc3W33=?=-P#B%GkP5f*`271 zItr9@wEAStleL?x<0J>YQxv%sTS=|a?QCVbeEzonpbA&H^rh~$lz@1%rfhIqt5;^X z2~7`i?-loTB#!LNBDo^4#J2YrjgB{|fL<2E)yAc+p?w7?hHXeqQq6WN1!Ooo6cis) z0F;94Xz@&--gEM$m{4sEU(nWX6;4j1fjW_e@zMT^adACWJz`-N$?ChWXwdkQ>fGsV zZ^T}+{1ujAwmNaR06QmSd6VXa?Z>5n34?66p2pA#q2nqaT0&7Q@Z;gNuHmlvYoMei zuJl{#r10~tmHQDGR59)}PX^5@?RfdDqClT1s8S!v7Fefoyilw0aC7Rb&0NSGyeH1g<^+lYZY-ktounFJ9n% zn{$i=XKeTh&nCQ_#b5IBE6|f$RpmC!U|6NXuc{<2;fo&8Y@9P)yBdC&^lR$#5QB40 z+E7|(VhX?vXYNAUjnEIQe1cD6{EO_EWbVXqd40yeA~{6%P4FMM@-I zN<&7bPUrh>CrplU=`<|q_$~A?Hu-QODw(DfM=!I;uMlINQ}q;BsHaW?9=B?#{0s`6 z5gP8u;#7N&5r|~2#9%#5*30`(`bjB1ShijX(-f=gz*X=e+@{Mmll@zDIwfoI;1kqV zXU^AU+EPM69s-MynR$U3vF(hz_2&hbSf@8~{=Cl0!;>5YN{_Meoc7Yjpsnd@qKJYU zem5Iw>v28pgUsh&SdoWGXh-TaG~zCQVw2dh41qXil|v&xK_lU@@XL}vhhADo9-Bei zKqSR_am-$(eFqZctvjeH?dR7iVnNS$n)@NaQpn=vR^Ocqam8*#)Xnw`LUGVMyf3!; zj!Ttt^*y)-az_#X=Mf!n9(VZWvn&I!%Bm}gG?bOECBq^+ucquqGHi+qVq|zcW(Aeq2xAvsX}2A z{q(%tP(*5iGDwp6Mf{QwJC@t1d_?Zt?zAFZ_|-Uly^j)bxWjp+9Jv94~Z#ObXb!d7wb2G5P|ZKQ=SPx;-; z6SgS1-A3uhtml>$DzG0gQ~x?7We`TY$F`8~|TRApfOA-b#RlFOMM8KUiB)lTMR#4Sc$SAGlP&~ zHN%BO8Sq2pvM*|^6F^!UDvcd&bd%NsqK5B;8w*V(ceVARR!3X71ZTFc->W<*y_oR*7X4G*Tc5$?Sn$X_wB9%GCAwK>*K{K{Y6J3k z(F)#?@eT3EGiUZ2nJsHBrym1G>K4dwYr`6XkscIxXw0M)qCyTWW#l-I6Q_?2A5nL50tb9K)_J zcA7M&tq1hV*oq9f$GchaueDnIh~mp*{bS_N{Dz>tl74k3aI&~fM>dXn$fTEX(Qf32 zQj|n0#WUze#@XA4C(^wo#OMqy`ufU&lL2CyG;(UvI{dQu`6kNU7p-*vGKTur+Q+B!IG^*dNaD~;S_Kr(k{&YSBpW|g2 zPf^uvu-!bUm_?*`x1^UBBst3Oy7^5ytw(K*hSk%2<*$JZx0d=3OCFfp6n`~Swy79N z^gGVl$kkD*6CWEO|HX??I0Rhq-$e%--$s?`QM3CN$1ZO&imApFNoy4MWI)1Wrdm$`xk#fjPHI(-5jEb zVVIeA%PwhyoB=~7oS70>#@EGe0eVi`KA806a zG(!bx{X`a|^JTvpwb220KoU18CpIaL+pYs$Yzw|5-5-LJ-}%rnt(=S`k%&=Hl$(@q zG`}v<8jl+BwwoBx{MK}e!@mf1MXg^RnVqEQdy9)W+nMo7TT}M2So5Q5JV^}vn}>yw zPs;PMkrJ2_H?IPgx-5BGttWi-9Q4EpK@$hTZ#cZ!1?8Qm_=%Ub{S6it7F=sSga0}!^8d~Xt&MIt;#MGBRm@LxQs%Cf1||n? z#7X(EL^0L%K{rD$b1H=Xm7Zy+T|^qDbxGItR&0pCQc02Eetc_>eO|us} z#M1i(s0nBuOy?n`-|u?1FT0TI8kzSl4-SSMyA+JCSkA|A4$dk;mVI1i5}LV4*#5(C z=Eg)ZXg}V0ZfFC{|GgG>yhd^fr#FPzKD-Yb{f_seKjN@ASGJV8G`0iEOhr4>o10OG ztffzi74S2Hy)c@!;pO(6lBzuq zqh^#|E(;_h4`^d!Yx$(X2+8u&So4d`}2_y9U?o^d52Rv%LnHJ#l^*K7-}XX?l(E>$N*s zOnq9nNuKx0k>IHXs|t}({)k_dyb zr;lf1=`x;q(h1FQTZEt}+b1Nlq+FjTgx79UlZ+IH8JmwQ;(zx*X6u>#%{?#IAlQ&q z^>It3IYXkV3RylqTXlZ09FqQCqy15z+EqrGCa;qJdsbn{+~S_W-k9Ka`MvqrMl4cd z3gQdM!4o*h%CtaNlIgEi5|np%@R|cwkn>b>Rw%K6rX!lf@cu8e97>p!L?R~pdW($l z8ke08LD$SnKRAS)#yN^Uf*R4ZqjU8dsy1zgGxYjg0m{D8{BmtKfah(vGH1!E!l{B} zW@Q-u=)eL}RiS1W)S8LUnpUPy(qc^!b8L8srkjSO+{v>zuUWxq+icx>&-T0{f7RI_ zjuq$G$gkJ3$SsQ|ekvxNCW6VF7FOtjSh?cKK|+%w@05Z(YBNieYztr!dkvtUnz;Oe zkfMciou-G-feAt)_0P~K;;N6dw{i$5iog^@H#%FXG=e??1}(qg+M}zaWZy${wB7>c z$T!U4#iV6GgrUm6U(!yu5$GUz_>&VJDUg*Xu!X7h8r9g1z&NIp9+Dop|y z?%K5X?$#^e!Z8&tPX5Fm<<%8-PH`#47-_VMv!o3yEmY%uB&m*<*4;5r$OBdK$o=hH zR~Y9KqcjNty4IzTgpA%wfh3CI3GtQBvlB_4sgxW|X%Yy^gv@D*-EKDMc#04ksJmMu zRgD|^7VirPkPJXd1*-lYJA?7ufD+VW79tRp#DoHM|BK0O7&S&IBDu^F`&BByT53*C z)zGDxS3vHw#NcFb^Pu7svT+F4etTIt|Sajeiane#nME__S zu#qVBm|)85a4hI{jOd&H6aMgI7ql^@se9@;_}A=38&3Q~WF%4FRMT-ghMhxsp_a}< z*$ekW{5BPyykmT1ngo+fHiUJBL-0sa7sTqE#4YBFgXMEWDRj9uZTK@sx7}hY0^oht z{qoH6b?39e3gZFF9T#rBy!u!N(g@-a5kdj3mpr?>$;Xqg9<0;T4=?#aAk<<#!!n!% zwePEI&Bz~z&OU986Y*Q1Pfb*qcbTL1>nD#2I$t|acr}|ww#t+N{VI6n`jthwlV}mL z3v+hEWWnJ&3uCO~j-^p?mv2L;f4TE6yVg2|d0&x8Z^g`dg$92y`lP@zgP_SQNgqQX zsA79>(QHS;keybv(S|H%Nykv2YLzzZMC&LcQ345oLK~C1)t<-i9Jfi+{q`P{vFQ{A zkl~Mtb}l6m{=G*)UmC&d!PVC&y&Uk!Ng(8sQl?5Pp^9=L7Zz<^{Wq1n-&TzFag%(s zKH6?tv^6S3N(qmc4l*9Nv_pc^ZG#*AZk@Be_@uE~|8$14G*xFT3!X7_+C|Fz>~+lN zkC=wugtU&?Iv(~Lfv^*uz-ypNVHO(k=F!<2XP$CKRJ*gDM}*|ydWl1VK|<-#y~!;j znz6`U$rva2zjQ>WGzx7Bm>Hl8B(R8`&M?R&TstzTT4UV6Y2Em8Z)}BNWS@LM3V}NA zUx^R7zfAqnVLmtAAc z6zIJ`8a1`ns$z+PLn6?Eh8d`z+Qf1tl4?y%4$qGZn86OA62fdD|7WeQIDr7m_s#HFyodm{ zi2u1$*w90z_514DnwnNT)@7vv+|6%8x+$p(gaiyrl0a6KWe{0*rN=T-edYR$ZZ^wG zd~;sPo}lojIwLs9fOu|JQAnK7GOpY_&7fzp1zKCqsn;cfJ<3qV^&0Pq=EbXNBiOFXRjb$1?U65CxY4pq&^Gn?J|qX>2#-G&`ofJLLo19sLQowZa7VL+Um zhfcaG6a7bhYXvYXagC9lD#{j(E<+@NDSbAg`6e2722W2kwS^nwp+m;b?c6hgxe&Fy z&1l9gGxN4RcZg#P@7C3?ZJQl|tp%-_t?dg6uI=H04nH1ek$VRuTRTzPc(%>qCtTzA z{x@S#1PlJdAUNI>Wrodk1a20eK^n{v2GoyY9D0!>Jw24kuiQP~tnOj8r6(sZtu4Rx zUz&cNpUfA})oi!87%o>W$xBMYaV@B8yAo^LtHYpcmA( zNxxmBve&JOb8s)shEt%szzK+>8do0yMx&;OOunoNuPZ;+araZQ&koDOogk)H{lDz9sfGw z{o8#JVE5tQQ}}S{BaB8G3szt=@!F#ZJvcZRqI$N)bUeQ*SN%o1WvC9&gnwVAA zjK@Gz_HG0*x+ZenmZOAo8XPw5T4pj64raH%0KIkpmry3~J{$2(Alz!Biu>hM)sgrL z(EZRAjOkW#${ddZ=GnQXXx&-aJ6nwQ@dkzWkT5 zU-Ho);yohn9K*9ysba}eEo2%LFs*RLPN|BAHfM@XiY0tprB9|VkJ+G=&ZlVLO#M0> zw}A*nEPcrX(B)vSfD@ch#%>_O+u^v9^sCIv`#mK0v32JZVmzRZ*3Z5#1gux)mnJaS zPs+pxv}=In;aCk0Suf#(CY9c&XxIb}KEADTQKcxV2c)*5e>Un3Nd3OXU9dovTlssS zH=wh?iT?^EwG&{^kHMkSypRiFt4=*kBB&%}ff}8Fe)A!a6n?1fgy0QrytH|-S8qvr zL-PX6mu#yMS(C{;oWM7tM4vU;P`^M~r)!Qf35hfcFDIDHbGcs*J;WafTFD@OT^ki$8^b;(B&-oj7%9H%aq zEy*8$5HcVr`SMg#pKgqKt@}{~Kv=Py069VjgOLr8=sXaegLcc0>>fl zAT)VygGg`Fqa zuo3SRNFCP>tjwnGWPzN|!Vi$2pTp4M`DH&O|FO}Sr^#>{r`Clf;bwz!dT00aXxr6K zF5Ve4^XBH!i1U;Rix!XO5DAhteIzJp^^T#mD*kbeYF_cybe^4ZaXs`YU4OMH=dYHf zsn2Y8l6nFOeP`z@5}#**?b#Vp-s7qUH>!~=1Wu1GP!=BwHS@n3yI?JI)5~^j+VJ_!Q{enPauG zt9;4!D*JIy+|r1tT~IBjo0d?(57#z$zNTcc0gn619_C=sT^x)y2n}K;D0qegg|j}IyxQC z65%gudJUbhy-Bq6bgfiCI4=fslNL{rUwI%*xa-7m8+sEVTI+B%@Y*(e1G*+ znsw;_<`s)9RVm%-u4^XWk41=87)FGPN{dL#F-Y`_aYN;c=GE1fWF%>>&{MD8f%$k! ze4sPPsTNqm|Bo@Lso)o2t#1TjFQza4fh**rML5$a2?8eCn#+{qjZRk)vbFrHOpLab zg|-)0{a*+T@!gmk!&NF3n#YP}XSsq`Nc8aQJwwbPL=c<3?fsMknj7>UByX9-Rdh<9+D-GfRR zaFy;%*>bQQ%cc)YQ7@N6Z<5aCv$!r|&BuhTsX%|fNRWJTm-!bJu>ZT4-@Hc%6+sx1 zAm`y}et+rHR8!--(*5U;+zcm24Um1#!asPs6X`m0oO8y6Iq1+}O#c*AoJ;csRR%K= zB!aCoz2-kjLr+hW9hCQFw*4gK#0~M=8)LTWt&=}FM4?M){<^%8NA zxDj~GRSn8;6I4)DooS~F_&lHZyk(|W8bfQngjEi%ySw5zLFY4{2y8^Kd?JLP6TMTeBJQcSzlR4 zr@5=WzzA1&e8J7lHG6q(Neg)-&t6X2{>?XPGdDaK#3I507eZjSnbf(rm#$NlWi;oq z-T;WjvHR&DTw?UMGEfOVnYIj)@oz_Qx)~|TUxA_6>6bKsb(Hys8b|tTYf3wqj;z>%k;f&67#fl8OkQKj@w)QhpZE`KWxZn%FOt(e_FZ35K9|9z`Pfw_C~Q zXod;(?H{7V6E+9fzjNa-3b^611SA^Nz;BA@4}-xr4>E-ss;jqE!bY7j==k7`>SYj% zH2G$xRn@dBW=sdeWLcOgh$U?ZFBp0_1b*rUnWi3zteW!cZqq}k0~%iu?98nR>a~5w za=t!LE`0I+yV`nODxcny57MB!(3g?$AyA7a7lsu zfn41gB*qpBq-1bKf=VJPi3yIi9WoN6#3Xy^b$@>&o0n_p88hFa9Y7^>Z7wb@AqkLK zi#6rJ`|zQQ?=+~KOg{6|=~q!vf8+HXU=;tKn^yMEP2=XM`4{UgB7)jL4Maqlp*_=l zq>!x3mE~n6@wfLlQI$An=LnkY&g7ps$;oFf5|6a`DCl2J=Er5Mt&P>`&%56uR(u^> zedP};Eh@ST1XK*pzwg#p6crV@)$I>H0cRx+kii3;Qs(u)(hbP literal 0 HcmV?d00001 diff --git a/boards/arm/wio_terminal/doc/index.rst b/boards/arm/wio_terminal/doc/index.rst new file mode 100644 index 000000000000..613061d8d50a --- /dev/null +++ b/boards/arm/wio_terminal/doc/index.rst @@ -0,0 +1,212 @@ +.. _wio_terminal: + +Wio Terminal +############ + +Overview +******** + +The Wio Terminal is a small (72 mm x 57 mm x 12 mm) and powerful ARM board with +wireless connectivity (2.4G/5G dual-band Wi-Fi and BLE 5.0), LCD display, +USB C port, FPC connector, microSD card slot, Raspberry Pi compatible 40-pins +header and 2 Grove connectors. + +.. image:: img/wio_terminal.png + :width: 500px + :align: center + :alt: Seeed Studio Wio Terminal + +Hardware +******** + +- ATSAMD51P19 ARM Cortex-M4F processor at 120 MHz +- 512 KiB flash memory and 192 KiB of RAM +- 4 MiB external flash +- MicroSD card slot +- RTL8720DN 2.4G/5G Dual Bands Wireless and BLE5.0 Combo Module +- 2.4inch LCD display +- LIS3DH accelerometer +- Microphone 1.0V-10V -42dB +- Speaker ≥78dB @10cm 4000Hz +- Light Sensor 400-1050nm +- Infrared Emitter 940nm +- GPIO 40 pin (Raspberry Pi compatible) +- 2x Grove connectors +- 1x user LED +- 3x user buttons +- 5-way user button +- Power/Reset/Boot mode switch +- Native USB port + +Supported Features +================== + +The wio_terminal board configuration supports the following hardware features: + +.. list-table:: + :header-rows: 1 + + * - Interface + - Controller + - Driver / Component + * - NVIC + - on-chip + - Nested vector interrupt controller + * - Flash + - on-chip + - Can be used with LittleFS to store files + * - SYSTICK + - on-chip + - Systick + * - WDT + - on-chip + - Watchdog + * - GPIO + - on-chip + - I/O ports + * - USART + - on-chip + - Serial port + * - I2C + - on-chip + - Inter-Integrated Circuit + * - SPI + - on-chip + - Serial Peripheral Interface port + * - TRNG + - on-chip + - True Random Number Generator + * - HWINFO + - on-chip + - Unique 128 bit serial number + * - RTC + - on-chip + - Real-Time Counter + * - USB + - on-chip + - USB device + * - PWM + - on-chip + - PWM + +Other hardware features are not currently supported by Zephyr. + +The default configuration can be found in the Kconfig file +:zephyr_file:`boards/arm/wio_terminal/wio_terminal_defconfig`. + +Zephyr can use the default Cortex-M SYSTICK timer or the SAM0 specific RTC. +To use the RTC, set :kconfig:option:`CONFIG_CORTEX_M_SYSTICK=n` and set +:kconfig:option:`CONFIG_SYS_CLOCK_TICKS_PER_SEC` to no more than 32 kHZ divided +by 7, i.e. no more than 4500. + +Connections and IOs +=================== + +The `Wio Terminal Getting started guide`_ has detailed information about the +board including `pinouts`_ and its `schematics`_. + +System Clock +============ + +The SAMD51 MCU is configured to use the 32.768 kHz internal oscillator with the +on-chip PLL generating the 120 MHz system clock. + +Serial Port +=========== + +Zephyr console output is available using the USB connector, which is used to +make the console available on PC as USB CDC class. + +USB Device Port +=============== + +The SAMD51 MCU has a USB device port that can be used to communicate with a +host PC. See the :ref:`usb-samples` sample applications for more, such as the +:ref:`usb_cdc-acm` sample which sets up a virtual serial port that echos +characters back to the host PC. + +Programming and Debugging +************************* + +The Wio Terminal ships with an UF2 bootloader that is BOSSA compatible. The +bootloader can be entered by quickly tapping the reset button twice. + +The UF2 file is generated when building the application, and it is possible to +use it to flash the target. Enter the bootloader by quickly sliding the power +button twice, and copy the UF2 file to the USB mass storage device. The device +reboots on the new firmware after the UF2 file has finished transferring. + +Flashing +======== + +#. Build the Zephyr kernel and the :code:`button` sample application: + + .. zephyr-app-commands:: + :zephyr-app: samples/basic/button + :board: wio_terminal + :goals: build + :compact: + +#. Swipe the reset/power button down twice quickly to enter bootloader mode + +#. Flash the image: + + .. zephyr-app-commands:: + :zephyr-app: samples/basic/button + :board: wio_terminal + :goals: flash + :compact: + + You should see the blue (user) LED flashing whenever you press the third + (counting from the top left) user button at the top of the Wio Terminal. + +Debugging +========= + +In addition to the built-in bootloader, the Wio Terminal can be flashed and +debugged using an SWD probe such as the Segger J-Link. + +#. Solder cables to the code:`SWCLK`, :code:`SWDIO`, :code:`RESET`, + :code:`GND`, and :code:`3V3` pins. See `Test with SWD`_ for more + information. + +#. Connect the board to the probe by connecting the :code:`SWCLK`, + :code:`SWDIO`, :code:`RESET`, :code:`GND`, and :code:`3V3` pins on the + Wio Terminal to the :code:`SWCLK`, :code:`SWDIO`, :code:`RESET`, + :code:`GND`, and :code:`VTref` pins on the `J-Link`_. + +#. Flash the image: + + .. zephyr-app-commands:: + :zephyr-app: samples/basic/button + :board: wio_terminal + :goals: flash -r openocd + :compact: + +#. Start debugging: + + .. zephyr-app-commands:: + :zephyr-app: samples/basic/button + :board: wio_terminal + :goals: debug + :compact: + +References +********** + +.. target-notes:: + +.. _Wio Terminal Getting started guide: + https://wiki.seeedstudio.com/Wio-Terminal-Getting-Started/ + +.. _pinouts: + https://wiki.seeedstudio.com/Wio-Terminal-Getting-Started/#pinout-diagram + +.. _schematics: + https://wiki.seeedstudio.com/Wio-Terminal-Getting-Started/#resources + +.. _Test with SWD: + https://wiki.seeedstudio.com/Wio-Terminal-Getting-Started/#test-with-swd + +.. _J-Link: + https://www.segger.com/products/debug-probes/j-link/technology/interface-description/ diff --git a/boards/arm/wio_terminal/pre_dt_board.cmake b/boards/arm/wio_terminal/pre_dt_board.cmake new file mode 100644 index 000000000000..2a14587c24b1 --- /dev/null +++ b/boards/arm/wio_terminal/pre_dt_board.cmake @@ -0,0 +1,9 @@ +# Copyright (c) 2023 Joel Guittet +# SPDX-License-Identifier: Apache-2.0 + +# SPI is implemented via sercom so node name isn't spi@... +list(APPEND EXTRA_DTC_FLAGS "-Wno-spi_bus_bridge") + +# Suppress "unique_unit_address_if_enabled" to handle the following overlaps: +# - /soc/pinmux@41008000 & /soc/gpio@41008000 +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") diff --git a/boards/arm/wio_terminal/support/openocd.cfg b/boards/arm/wio_terminal/support/openocd.cfg new file mode 100644 index 000000000000..ce9baa8012f1 --- /dev/null +++ b/boards/arm/wio_terminal/support/openocd.cfg @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: Apache-2.0 + +source [find interface/jlink.cfg] + +transport select swd + +set CHIPNAME atsamd51p19 + +source [find target/atsame5x.cfg] + +adapter_khz 500 +reset_config srst_only + +$_TARGETNAME configure -event gdb-attach { + echo "Debugger attaching: halting execution" + reset halt +} + +$_TARGETNAME configure -event gdb-detach { + echo "Debugger detaching: resuming execution" + resume +} diff --git a/boards/arm/wio_terminal/wio_terminal-pinctrl.dtsi b/boards/arm/wio_terminal/wio_terminal-pinctrl.dtsi new file mode 100644 index 000000000000..c2fafd25ad97 --- /dev/null +++ b/boards/arm/wio_terminal/wio_terminal-pinctrl.dtsi @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2023 Joel Guittet + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +&pinctrl { + + sercom0_spi_default: sercom0_spi_default { + group1 { + pinmux = , + , + ; + }; + }; + + sercom1_uart_default: sercom1_uart_default { + group1 { + pinmux = , + ; + }; + }; + + sercom2_uart_default: sercom2_uart_default { + group1 { + pinmux = , + ; + }; + }; + + sercom3_i2c_default: sercom3_i2c_default { + group1 { + pinmux = , + ; + }; + }; + + sercom4_i2c_default: sercom4_i2c_default { + group1 { + pinmux = , + ; + }; + }; + + sercom5_spi_default: sercom5_spi_default { + group1 { + pinmux = , + , + ; + }; + }; + + sercom6_spi_default: sercom6_spi_default { + group1 { + pinmux = , + , + ; + }; + }; + + sercom7_spi_default: sercom7_spi_default { + group1 { + pinmux = , + , + ; + }; + }; + + usb_dc_default: usb_dc_default { + group1 { + pinmux = , + ; + }; + }; +}; diff --git a/boards/arm/wio_terminal/wio_terminal.dts b/boards/arm/wio_terminal/wio_terminal.dts new file mode 100644 index 000000000000..85d48dc6989f --- /dev/null +++ b/boards/arm/wio_terminal/wio_terminal.dts @@ -0,0 +1,280 @@ +/* + * Copyright (c) 2023 Joel Guittet + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; +#include +#include "wio_terminal-pinctrl.dtsi" +#include + +/ { + model = "Wio Terminal"; + compatible = "seeed,wio-terminal"; + + chosen { + zephyr,sram = &sram0; + zephyr,flash = &flash0; + zephyr,console = &wio_terminal_console; + zephyr,shell-uart = &wio_terminal_console; + zephyr,code-partition = &code_partition; + zephyr,display = &ili9341; + }; + + /* These aliases are provided for compatibility with samples */ + aliases { + led0 = &led0; + sw0 = &user_button_0; + sw1 = &user_button_1; + sw2 = &user_button_2; + i2c0 = &sercom4; + i2c1 = &sercom3; + spi0 = &sercom5; + uart0 = &sercom2; + accel0 = &lis3dh; + sdhc0 = &sdhc0; + }; + + /* LEDs */ + leds { + compatible = "gpio-leds"; + led0: led_0 { + label = "LED"; + gpios = <&porta 15 GPIO_ACTIVE_HIGH>; + }; + }; + + /* Buttons */ + gpio_keys { + compatible = "gpio-keys"; + user_button_0: button_0 { + label = "User Button 0"; + gpios = <&portc 26 GPIO_ACTIVE_LOW>; + }; + user_button_1: button_1 { + label = "User Button 1"; + gpios = <&portc 27 GPIO_ACTIVE_LOW>; + }; + user_button_2: button_2 { + label = "User Button 2"; + gpios = <&portc 28 GPIO_ACTIVE_LOW>; + }; + joy_sel: joystick_selection { + label = "joystick selection"; + gpios = <&portd 10 GPIO_ACTIVE_LOW>; + }; + joy_down: joystick_down { + label = "joystick down"; + gpios = <&portd 8 GPIO_ACTIVE_LOW>; + }; + joy_up: joystick_up { + label = "joystick up"; + gpios = <&portd 20 GPIO_ACTIVE_LOW>; + }; + joy_left: joystick_left { + label = "joystick left"; + gpios = <&portd 12 GPIO_ACTIVE_LOW>; + }; + joy_right: joystick_right { + label = "joystick right"; + gpios = <&portd 9 GPIO_ACTIVE_LOW>; + }; + }; + + /* Regulators */ + lcd_backlight_en { + compatible = "regulator-fixed"; + regulator-name = "lcd_backlight_enable"; + enable-gpios = <&portc 5 GPIO_ACTIVE_HIGH>; + regulator-boot-on; + }; + rpi_power_3v3_en { + compatible = "regulator-fixed"; + regulator-name = "rpi_power_3v3_enable"; + enable-gpios = <&portc 15 GPIO_ACTIVE_LOW>; + regulator-boot-on; + }; + rpi_power_5v_en { + compatible = "regulator-fixed"; + regulator-name = "rpi_power_5v_enable"; + enable-gpios = <&portc 14 GPIO_ACTIVE_HIGH>; + regulator-boot-on; + }; + usb_power_5v_en { + compatible = "regulator-fixed"; + regulator-name = "usb_power_5v_en"; + enable-gpios = <&porta 27 GPIO_ACTIVE_LOW>; + }; +}; + +&cpu0 { + clock-frequency = <120000000>; +}; + +&dmac { + status = "okay"; +}; + +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "uf2"; + reg = <0x00000000 DT_SIZE_K(16)>; + read-only; + }; + + code_partition: partition@4000 { + label = "code"; + reg = <0x4000 DT_SIZE_K(512-16)>; + read-only; + }; + }; +}; + +/* RTL8720D (Wifi/BLE) */ +&sercom0 { + status = "okay"; + compatible = "atmel,sam0-spi"; + #address-cells = <1>; + #size-cells = <0>; + dipo = <2>; + dopo = <0>; + pinctrl-0 = <&sercom0_spi_default>; + pinctrl-names = "default"; + cs-gpios = <&portc 25 GPIO_ACTIVE_LOW>; +}; + +/* RTL8720D (Wifi/BLE) */ +&sercom1 { + status = "okay"; + compatible = "atmel,sam0-uart"; + current-speed = <115200>; + rxpo = <1>; + txpo = <0>; + pinctrl-0 = <&sercom1_uart_default>; + pinctrl-names = "default"; +}; + +/* UART, Raspberry Pi connector */ +&sercom2 { + status = "okay"; + compatible = "atmel,sam0-uart"; + current-speed = <115200>; + rxpo = <1>; + txpo = <0>; + pinctrl-0 = <&sercom2_uart_default>; + pinctrl-names = "default"; +}; + +/* I2C1, Raspberry Pi and Groove connectors */ +&sercom3 { + status = "okay"; + compatible = "atmel,sam0-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + pinctrl-0 = <&sercom3_i2c_default>; + pinctrl-names = "default"; +}; + +/* I2C0, LIS3DH, ATECC608, Raspberry Pi connector */ +&sercom4 { + status = "okay"; + compatible = "atmel,sam0-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + pinctrl-0 = <&sercom4_i2c_default>; + pinctrl-names = "default"; + + /* LIS3DH */ + lis3dh: lis3dh@18 { + compatible = "st,lis3dh", "st,lis2dh"; + status = "okay"; + reg = <0x18>; + irq-gpios = <&portc 21 GPIO_ACTIVE_HIGH>; + }; + + /* ATECC608A */ + atecc608a@6a { + compatible = "atmel,atecc608"; + reg = <0x6a>; + }; +}; + +/* SPI, Raspberry Pi connector */ +&sercom5 { + status = "okay"; + compatible = "atmel,sam0-spi"; + #address-cells = <1>; + #size-cells = <0>; + dipo = <2>; + dopo = <0>; + pinctrl-0 = <&sercom5_spi_default>; + pinctrl-names = "default"; + cs-gpios = <&portb 1 GPIO_ACTIVE_LOW>; +}; + +/* microSD Card */ +&sercom6 { + status = "okay"; + compatible = "atmel,sam0-spi"; + #address-cells = <1>; + #size-cells = <0>; + dipo = <2>; + dopo = <0>; + pinctrl-0 = <&sercom6_spi_default>; + pinctrl-names = "default"; + cs-gpios = <&portc 19 GPIO_ACTIVE_LOW>; + + /* microSD Card */ + sdhc0: sdhc@0 { + compatible = "zephyr,sdhc-spi-slot"; + reg = <0>; + spi-max-frequency = <24000000>; + mmc { + compatible = "zephyr,sdmmc-disk"; + }; + }; +}; + +/* LCD */ +&sercom7 { + status = "okay"; + compatible = "atmel,sam0-spi"; + #address-cells = <1>; + #size-cells = <0>; + dipo = <2>; + dopo = <3>; + pinctrl-0 = <&sercom7_spi_default>; + pinctrl-names = "default"; + cs-gpios = <&portb 21 GPIO_ACTIVE_LOW>; + + /* LCD */ + ili9341: ili9341@0 { + compatible = "ilitek,ili9341"; + spi-max-frequency = <24000000>; + reg = <0>; + cmd-data-gpios = <&portc 6 GPIO_ACTIVE_LOW>; + reset-gpios = <&portc 7 GPIO_ACTIVE_LOW>; + pixel-format = ; + rotation = <270>; + width = <320>; + height = <240>; + }; +}; + +/* USB */ +zephyr_udc0: &usb0 { + status = "okay"; + pinctrl-0 = <&usb_dc_default>; + pinctrl-names = "default"; + + wio_terminal_console: wio_terminal_console { + compatible = "zephyr,cdc-acm-uart"; + }; +}; diff --git a/boards/arm/wio_terminal/wio_terminal.yaml b/boards/arm/wio_terminal/wio_terminal.yaml new file mode 100644 index 000000000000..3612a32d33b4 --- /dev/null +++ b/boards/arm/wio_terminal/wio_terminal.yaml @@ -0,0 +1,21 @@ +identifier: wio_terminal +name: Wio Terminal +type: mcu +arch: arm +ram: 192 +flash: 512 +toolchain: + - zephyr + - gnuarmemb + - xtools +supported: + - adc + - counter + - dma + - gpio + - i2c + - pwm + - spi + - usb_cdc + - usb_device + - watchdog diff --git a/boards/arm/wio_terminal/wio_terminal_defconfig b/boards/arm/wio_terminal/wio_terminal_defconfig new file mode 100644 index 000000000000..353a699c150c --- /dev/null +++ b/boards/arm/wio_terminal/wio_terminal_defconfig @@ -0,0 +1,31 @@ +# Copyright (c) 2023 Joel Guittet +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_SAMD51=y +CONFIG_SOC_PART_NUMBER_SAMD51P19A=y +CONFIG_SOC_ATMEL_SAMD5X_XOSC32K=y +CONFIG_SOC_ATMEL_SAMD5X_XOSC32K_AS_MAIN=y +CONFIG_BOARD_WIO_TERMINAL=y +CONFIG_ARM_MPU=y +CONFIG_CORTEX_M_SYSTICK=y +CONFIG_HW_STACK_PROTECTION=y +CONFIG_REGULATOR=y +CONFIG_GPIO=y + +# BOSSA bootloader +CONFIG_BOOTLOADER_BOSSA=y +CONFIG_BOOTLOADER_BOSSA_ADAFRUIT_UF2=y +CONFIG_BUILD_OUTPUT_UF2=y + +# Console over USB CDC-ACM +CONFIG_SERIAL=y +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y +CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y +CONFIG_USB_DEVICE_VID=0x2886 +CONFIG_USB_DEVICE_PID=0x802D +CONFIG_USB_DEVICE_MANUFACTURER="Seeed Studio" +CONFIG_USB_DEVICE_PRODUCT="Wio Terminal" +CONFIG_USB_CDC_ACM_LOG_LEVEL_OFF=y diff --git a/tests/drivers/uart/uart_async_api/testcase.yaml b/tests/drivers/uart/uart_async_api/testcase.yaml index a79eb74a3592..fdd03b3f7df9 100644 --- a/tests/drivers/uart/uart_async_api/testcase.yaml +++ b/tests/drivers/uart/uart_async_api/testcase.yaml @@ -3,7 +3,7 @@ common: adafruit_itsybitsy_m4_express atsame54_xpro atsamd21_xpro adafruit_trinket_m0 arduino_nano_33_iot arduino_zero atsamd21_xpro adafruit_feather_m0_basic_proto adafruit_feather_m0_lora arduino_mkrzero atsaml21_xpro atsamr34_xpro stamp_c3 - xiao_esp32c3 + wio_terminal xiao_esp32c3 tags: drivers uart tests: drivers.uart.async_api: From 031b294c915f86f60fec4ac8bdfc4022e4284257 Mon Sep 17 00:00:00 2001 From: Joel Guittet Date: Wed, 8 Mar 2023 10:01:04 +0100 Subject: [PATCH 0084/1906] doc: release_notes v3.3: Add new board wio terminal Add new board Wio Terminal from Seeed Studio Signed-off-by: Joel Guittet --- doc/releases/release-notes-3.4.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/releases/release-notes-3.4.rst b/doc/releases/release-notes-3.4.rst index ad1ec38c7081..f98e0bc9947b 100644 --- a/doc/releases/release-notes-3.4.rst +++ b/doc/releases/release-notes-3.4.rst @@ -164,6 +164,8 @@ Boards & SoC Support * Added support for these ARM boards: + * Seeed Studio Wio Terminal + * Added support for these ARM64 boards: * Added support for these RISC-V boards: From 24ad09623234c80a24d849fbe6195f3d653e29e4 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Thu, 16 Feb 2023 13:44:59 +0100 Subject: [PATCH 0085/1906] logging: Renamed internal defines to get rid of 2 suffix Some internal macros were still using 2 suffix which comes from time when there was v1 and v2. Cleaning up by removing the suffix. Signed-off-by: Krzysztof Chruscinski --- include/zephyr/logging/log_core.h | 6 +- include/zephyr/logging/log_link.h | 2 +- include/zephyr/logging/log_msg.h | 136 +++++++++--------- include/zephyr/shell/shell_log_backend.h | 2 +- .../backends/log_multidomain_backend.c | 2 +- subsys/logging/log_core.c | 6 +- subsys/logging/log_msg.c | 12 +- .../log_core_additional/src/log_test.c | 8 +- .../subsys/logging/log_link_order/src/main.c | 8 +- tests/subsys/logging/log_msg/src/main.c | 64 ++++----- 10 files changed, 129 insertions(+), 117 deletions(-) diff --git a/include/zephyr/logging/log_core.h b/include/zephyr/logging/log_core.h index 789c536ab357..bb0f9c68cb9f 100644 --- a/include/zephyr/logging/log_core.h +++ b/include/zephyr/logging/log_core.h @@ -238,7 +238,7 @@ static inline char z_log_minimal_level_to_char(int level) int _mode; \ void *_src = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \ (void *)_dsource : (void *)_source; \ - Z_LOG_MSG2_CREATE(UTIL_NOT(IS_ENABLED(CONFIG_USERSPACE)), _mode, \ + Z_LOG_MSG_CREATE(UTIL_NOT(IS_ENABLED(CONFIG_USERSPACE)), _mode, \ Z_LOG_LOCAL_DOMAIN_ID, _src, _level, NULL,\ 0, __VA_ARGS__); \ (void)_mode; \ @@ -314,7 +314,7 @@ static inline char z_log_minimal_level_to_char(int level) int mode; \ void *_src = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \ (void *)_dsource : (void *)_source; \ - Z_LOG_MSG2_CREATE(UTIL_NOT(IS_ENABLED(CONFIG_USERSPACE)), mode, \ + Z_LOG_MSG_CREATE(UTIL_NOT(IS_ENABLED(CONFIG_USERSPACE)), mode, \ Z_LOG_LOCAL_DOMAIN_ID, _src, _level, \ _data, _len, \ COND_CODE_0(NUM_VA_ARGS_LESS_1(_, ##__VA_ARGS__), \ @@ -411,7 +411,7 @@ extern struct log_source_const_data __log_const_end[]; if (0) {\ z_log_printf_arg_checker(__VA_ARGS__); \ } \ - Z_LOG_MSG2_CREATE(!IS_ENABLED(CONFIG_USERSPACE), _mode, \ + Z_LOG_MSG_CREATE(!IS_ENABLED(CONFIG_USERSPACE), _mode, \ Z_LOG_LOCAL_DOMAIN_ID, (uintptr_t)_is_raw, \ LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, __VA_ARGS__);\ } while (0) diff --git a/include/zephyr/logging/log_link.h b/include/zephyr/logging/log_link.h index d87b323bcf0f..f1cbaee258d2 100644 --- a/include/zephyr/logging/log_link.h +++ b/include/zephyr/logging/log_link.h @@ -83,7 +83,7 @@ struct log_link { * @param _ctx Context (void *) associated with the link. */ #define LOG_LINK_DEF(_name, _api, _buf_wlen, _ctx) \ - static uint32_t __aligned(Z_LOG_MSG2_ALIGNMENT) _name##_buf32[_buf_wlen]; \ + static uint32_t __aligned(Z_LOG_MSG_ALIGNMENT) _name##_buf32[_buf_wlen]; \ static const struct mpsc_pbuf_buffer_config _name##_mpsc_pbuf_config = { \ .buf = (uint32_t *)_name##_buf32, \ .size = _buf_wlen, \ diff --git a/include/zephyr/logging/log_msg.h b/include/zephyr/logging/log_msg.h index 0a3730e18d52..0113d8b50c2f 100644 --- a/include/zephyr/logging/log_msg.h +++ b/include/zephyr/logging/log_msg.h @@ -26,8 +26,8 @@ extern "C" { #endif -#define LOG_MSG2_DEBUG 0 -#define LOG_MSG2_DBG(...) IF_ENABLED(LOG_MSG2_DEBUG, (printk(__VA_ARGS__))) +#define LOG_MSG_DEBUG 0 +#define LOG_MSG_DBG(...) IF_ENABLED(LOG_MSG_DEBUG, (printk(__VA_ARGS__))) #ifdef CONFIG_LOG_TIMESTAMP_64BIT typedef uint64_t log_timestamp_t; @@ -42,17 +42,21 @@ typedef uint32_t log_timestamp_t; * @{ */ -#define Z_LOG_MSG2_LOG 0 +#define Z_LOG_MSG_LOG 0 -#define LOG_MSG2_GENERIC_HDR \ +#define Z_LOG_MSG_PACKAGE_BITS 10 + +#define Z_LOG_MSG_MAX_PACKAGE BIT_MASK(Z_LOG_MSG_PACKAGE_BITS) + +#define LOG_MSG_GENERIC_HDR \ MPSC_PBUF_HDR;\ uint32_t type:1 struct log_msg_desc { - LOG_MSG2_GENERIC_HDR; + LOG_MSG_GENERIC_HDR; uint32_t domain:3; uint32_t level:3; - uint32_t package_len:10; + uint32_t package_len:Z_LOG_MSG_PACKAGE_BITS; uint32_t data_len:12; uint32_t reserved:1; }; @@ -78,11 +82,11 @@ struct log_msg_hdr { }; /* Messages are aligned to alignment required by cbprintf package. */ -#define Z_LOG_MSG2_ALIGNMENT CBPRINTF_PACKAGE_ALIGNMENT +#define Z_LOG_MSG_ALIGNMENT CBPRINTF_PACKAGE_ALIGNMENT -#define Z_LOG_MSG2_PADDING \ - ((sizeof(struct log_msg_hdr) % Z_LOG_MSG2_ALIGNMENT) > 0 ? \ - (Z_LOG_MSG2_ALIGNMENT - (sizeof(struct log_msg_hdr) % Z_LOG_MSG2_ALIGNMENT)) : \ +#define Z_LOG_MSG_PADDING \ + ((sizeof(struct log_msg_hdr) % Z_LOG_MSG_ALIGNMENT) > 0 ? \ + (Z_LOG_MSG_ALIGNMENT - (sizeof(struct log_msg_hdr) % Z_LOG_MSG_ALIGNMENT)) : \ 0) struct log_msg { @@ -90,14 +94,14 @@ struct log_msg { /* Adding padding to ensure that cbprintf package that follows is * properly aligned. */ - uint8_t padding[Z_LOG_MSG2_PADDING]; + uint8_t padding[Z_LOG_MSG_PADDING]; uint8_t data[]; }; /** * @cond INTERNAL_HIDDEN */ -BUILD_ASSERT(sizeof(struct log_msg) % Z_LOG_MSG2_ALIGNMENT == 0, +BUILD_ASSERT(sizeof(struct log_msg) % Z_LOG_MSG_ALIGNMENT == 0, "Log msg size must aligned"); /** * @endcond @@ -105,7 +109,7 @@ BUILD_ASSERT(sizeof(struct log_msg) % Z_LOG_MSG2_ALIGNMENT == 0, struct log_msg_generic_hdr { - LOG_MSG2_GENERIC_HDR; + LOG_MSG_GENERIC_HDR; }; union log_msg_generic { @@ -122,25 +126,25 @@ enum z_log_msg_mode { /* Runtime mode is least efficient but supports all cases thus it is * treated as a fallback method when others cannot be used. */ - Z_LOG_MSG2_MODE_RUNTIME, + Z_LOG_MSG_MODE_RUNTIME, /* Mode creates statically a string package on stack and calls a * function for creating a message. It takes code size than - * Z_LOG_MSG2_MODE_ZERO_COPY but is a bit slower. + * Z_LOG_MSG_MODE_ZERO_COPY but is a bit slower. */ - Z_LOG_MSG2_MODE_FROM_STACK, + Z_LOG_MSG_MODE_FROM_STACK, /* Mode calculates size of the message and allocates it and writes * directly to the message space. It is the fastest method but requires * more code size. */ - Z_LOG_MSG2_MODE_ZERO_COPY, + Z_LOG_MSG_MODE_ZERO_COPY, }; #define Z_LOG_MSG_DESC_INITIALIZER(_domain_id, _level, _plen, _dlen) \ { \ .valid = 0, \ .busy = 0, \ - .type = Z_LOG_MSG2_LOG, \ + .type = Z_LOG_MSG_LOG, \ .domain = _domain_id, \ .level = _level, \ .package_len = _plen, \ @@ -148,28 +152,28 @@ enum z_log_msg_mode { .reserved = 0, \ } -#define Z_LOG_MSG2_CBPRINTF_FLAGS(_cstr_cnt) \ +#define Z_LOG_MSG_CBPRINTF_FLAGS(_cstr_cnt) \ (CBPRINTF_PACKAGE_FIRST_RO_STR_CNT(_cstr_cnt) | \ (IS_ENABLED(CONFIG_LOG_MSG_APPEND_RO_STRING_LOC) ? \ CBPRINTF_PACKAGE_ADD_STRING_IDXS : 0)) #ifdef CONFIG_LOG_USE_VLA -#define Z_LOG_MSG2_ON_STACK_ALLOC(ptr, len) \ +#define Z_LOG_MSG_ON_STACK_ALLOC(ptr, len) \ long long _ll_buf[ceiling_fraction(len, sizeof(long long))]; \ long double _ld_buf[ceiling_fraction(len, sizeof(long double))]; \ - ptr = (sizeof(long double) == Z_LOG_MSG2_ALIGNMENT) ? \ + ptr = (sizeof(long double) == Z_LOG_MSG_ALIGNMENT) ? \ (struct log_msg *)_ld_buf : (struct log_msg *)_ll_buf; \ if (IS_ENABLED(CONFIG_LOG_TEST_CLEAR_MESSAGE_SPACE)) { \ /* During test fill with 0's to simplify message comparison */ \ memset(ptr, 0, len); \ } -#else /* Z_LOG_MSG2_USE_VLA */ +#else /* Z_LOG_MSG_USE_VLA */ /* When VLA cannot be used we need to trick compiler a bit and create multiple * fixed size arrays and take the smallest one that will fit the message. * Compiler will remove unused arrays and stack usage will be kept similar * to vla case, rounded to the size of the used buffer. */ -#define Z_LOG_MSG2_ON_STACK_ALLOC(ptr, len) \ +#define Z_LOG_MSG_ON_STACK_ALLOC(ptr, len) \ long long _ll_buf32[32 / sizeof(long long)]; \ long long _ll_buf48[48 / sizeof(long long)]; \ long long _ll_buf64[64 / sizeof(long long)]; \ @@ -180,7 +184,7 @@ enum z_log_msg_mode { long double _ld_buf64[64 / sizeof(long double)]; \ long double _ld_buf128[128 / sizeof(long double)]; \ long double _ld_buf256[256 / sizeof(long double)]; \ - if (sizeof(long double) == Z_LOG_MSG2_ALIGNMENT) { \ + if (sizeof(long double) == Z_LOG_MSG_ALIGNMENT) { \ ptr = (len > 128) ? (struct log_msg *)_ld_buf256 : \ ((len > 64) ? (struct log_msg *)_ld_buf128 : \ ((len > 48) ? (struct log_msg *)_ld_buf64 : \ @@ -197,17 +201,17 @@ enum z_log_msg_mode { /* During test fill with 0's to simplify message comparison */ \ memset(ptr, 0, len); \ } -#endif /* Z_LOG_MSG2_USE_VLA */ +#endif /* Z_LOG_MSG_USE_VLA */ -#define Z_LOG_MSG2_ALIGN_OFFSET \ +#define Z_LOG_MSG_ALIGN_OFFSET \ offsetof(struct log_msg, data) -#define Z_LOG_MSG2_LEN(pkg_len, data_len) \ +#define Z_LOG_MSG_LEN(pkg_len, data_len) \ (offsetof(struct log_msg, data) + pkg_len + (data_len)) -#define Z_LOG_MSG2_ALIGNED_WLEN(pkg_len, data_len) \ - ceiling_fraction(ROUND_UP(Z_LOG_MSG2_LEN(pkg_len, data_len), \ - Z_LOG_MSG2_ALIGNMENT), \ +#define Z_LOG_MSG_ALIGNED_WLEN(pkg_len, data_len) \ + ceiling_fraction(ROUND_UP(Z_LOG_MSG_LEN(pkg_len, data_len), \ + Z_LOG_MSG_ALIGNMENT), \ sizeof(uint32_t)) /* @@ -221,49 +225,49 @@ enum z_log_msg_mode { #define Z_LOG_ARM64_VLA_PROTECT() compiler_barrier() -#define Z_LOG_MSG2_STACK_CREATE(_cstr_cnt, _domain_id, _source, _level, _data, _dlen, ...) \ +#define Z_LOG_MSG_STACK_CREATE(_cstr_cnt, _domain_id, _source, _level, _data, _dlen, ...) \ do { \ int _plen; \ - uint32_t flags = Z_LOG_MSG2_CBPRINTF_FLAGS(_cstr_cnt) | \ + uint32_t flags = Z_LOG_MSG_CBPRINTF_FLAGS(_cstr_cnt) | \ CBPRINTF_PACKAGE_ADD_RW_STR_POS; \ if (GET_ARG_N(1, __VA_ARGS__) == NULL) { \ _plen = 0; \ } else { \ - CBPRINTF_STATIC_PACKAGE(NULL, 0, _plen, Z_LOG_MSG2_ALIGN_OFFSET, flags, \ + CBPRINTF_STATIC_PACKAGE(NULL, 0, _plen, Z_LOG_MSG_ALIGN_OFFSET, flags, \ __VA_ARGS__); \ } \ struct log_msg *_msg; \ - Z_LOG_MSG2_ON_STACK_ALLOC(_msg, Z_LOG_MSG2_LEN(_plen, 0)); \ + Z_LOG_MSG_ON_STACK_ALLOC(_msg, Z_LOG_MSG_LEN(_plen, 0)); \ Z_LOG_ARM64_VLA_PROTECT(); \ if (_plen != 0) { \ CBPRINTF_STATIC_PACKAGE(_msg->data, _plen, \ - _plen, Z_LOG_MSG2_ALIGN_OFFSET, flags, \ + _plen, Z_LOG_MSG_ALIGN_OFFSET, flags, \ __VA_ARGS__);\ } \ struct log_msg_desc _desc = \ Z_LOG_MSG_DESC_INITIALIZER(_domain_id, _level, \ (uint32_t)_plen, _dlen); \ - LOG_MSG2_DBG("creating message on stack: package len: %d, data len: %d\n", \ + LOG_MSG_DBG("creating message on stack: package len: %d, data len: %d\n", \ _plen, (int)(_dlen)); \ z_log_msg_static_create((void *)_source, _desc, _msg->data, _data); \ } while (false) #ifdef CONFIG_LOG_SPEED -#define Z_LOG_MSG2_SIMPLE_CREATE(_cstr_cnt, _domain_id, _source, _level, ...) do { \ +#define Z_LOG_MSG_SIMPLE_CREATE(_cstr_cnt, _domain_id, _source, _level, ...) do { \ int _plen; \ - CBPRINTF_STATIC_PACKAGE(NULL, 0, _plen, Z_LOG_MSG2_ALIGN_OFFSET, \ - Z_LOG_MSG2_CBPRINTF_FLAGS(_cstr_cnt), \ + CBPRINTF_STATIC_PACKAGE(NULL, 0, _plen, Z_LOG_MSG_ALIGN_OFFSET, \ + Z_LOG_MSG_CBPRINTF_FLAGS(_cstr_cnt), \ __VA_ARGS__); \ - size_t _msg_wlen = Z_LOG_MSG2_ALIGNED_WLEN(_plen, 0); \ + size_t _msg_wlen = Z_LOG_MSG_ALIGNED_WLEN(_plen, 0); \ struct log_msg *_msg = z_log_msg_alloc(_msg_wlen); \ struct log_msg_desc _desc = \ Z_LOG_MSG_DESC_INITIALIZER(_domain_id, _level, (uint32_t)_plen, 0); \ - LOG_MSG2_DBG("creating message zero copy: package len: %d, msg: %p\n", \ + LOG_MSG_DBG("creating message zero copy: package len: %d, msg: %p\n", \ _plen, _msg); \ if (_msg) { \ CBPRINTF_STATIC_PACKAGE(_msg->data, _plen, _plen, \ - Z_LOG_MSG2_ALIGN_OFFSET, \ - Z_LOG_MSG2_CBPRINTF_FLAGS(_cstr_cnt), \ + Z_LOG_MSG_ALIGN_OFFSET, \ + Z_LOG_MSG_CBPRINTF_FLAGS(_cstr_cnt), \ __VA_ARGS__); \ } \ z_log_msg_finalize(_msg, (void *)_source, _desc, NULL); \ @@ -272,7 +276,7 @@ do { \ /* Alternative empty macro created to speed up compilation when LOG_SPEED is * disabled (default). */ -#define Z_LOG_MSG2_SIMPLE_CREATE(...) +#define Z_LOG_MSG_SIMPLE_CREATE(...) #endif /* Macro handles case when local variable with log message string is created. It @@ -336,7 +340,7 @@ do { \ /* Macro handles case when there is no string provided, in that case variable * is not created. */ -#define Z_LOG_MSG2_STR_VAR_IN_SECTION(_name, ...) \ +#define Z_LOG_MSG_STR_VAR_IN_SECTION(_name, ...) \ COND_CODE_0(NUM_VA_ARGS_LESS_1(_, ##__VA_ARGS__), \ (/* No args provided, no variable */), \ (static const char _name[] \ @@ -350,9 +354,9 @@ do { \ * @param _name Variable name. * @param ... Optional log message with arguments (may be empty). */ -#define Z_LOG_MSG2_STR_VAR(_name, ...) \ +#define Z_LOG_MSG_STR_VAR(_name, ...) \ IF_ENABLED(CONFIG_LOG_FMT_SECTION, \ - (Z_LOG_MSG2_STR_VAR_IN_SECTION(_name, ##__VA_ARGS__))) + (Z_LOG_MSG_STR_VAR_IN_SECTION(_name, ##__VA_ARGS__))) /** @brief Create log message and write it into the logger buffer. * @@ -396,36 +400,36 @@ do { \ #if defined(CONFIG_LOG_ALWAYS_RUNTIME) || \ (!defined(CONFIG_LOG) && \ (!TOOLCHAIN_HAS_PRAGMA_DIAG || !TOOLCHAIN_HAS_C_AUTO_TYPE)) -#define Z_LOG_MSG2_CREATE2(_try_0cpy, _mode, _cstr_cnt, _domain_id, _source,\ +#define Z_LOG_MSG_CREATE2(_try_0cpy, _mode, _cstr_cnt, _domain_id, _source,\ _level, _data, _dlen, ...) \ do {\ - Z_LOG_MSG2_STR_VAR(_fmt, ##__VA_ARGS__) \ + Z_LOG_MSG_STR_VAR(_fmt, ##__VA_ARGS__) \ z_log_msg_runtime_create(_domain_id, (void *)_source, \ _level, (uint8_t *)_data, _dlen,\ - Z_LOG_MSG2_CBPRINTF_FLAGS(_cstr_cnt) | \ + Z_LOG_MSG_CBPRINTF_FLAGS(_cstr_cnt) | \ (IS_ENABLED(CONFIG_LOG_USE_TAGGED_ARGUMENTS) ? \ CBPRINTF_PACKAGE_ARGS_ARE_TAGGED : 0), \ Z_LOG_FMT_RUNTIME_ARGS(_fmt, ##__VA_ARGS__));\ - _mode = Z_LOG_MSG2_MODE_RUNTIME; \ + _mode = Z_LOG_MSG_MODE_RUNTIME; \ } while (false) #else /* CONFIG_LOG_ALWAYS_RUNTIME */ -#define Z_LOG_MSG2_CREATE3(_try_0cpy, _mode, _cstr_cnt, _domain_id, _source,\ +#define Z_LOG_MSG_CREATE3(_try_0cpy, _mode, _cstr_cnt, _domain_id, _source,\ _level, _data, _dlen, ...) \ do { \ - Z_LOG_MSG2_STR_VAR(_fmt, ##__VA_ARGS__); \ + Z_LOG_MSG_STR_VAR(_fmt, ##__VA_ARGS__); \ bool has_rw_str = CBPRINTF_MUST_RUNTIME_PACKAGE( \ - Z_LOG_MSG2_CBPRINTF_FLAGS(_cstr_cnt), \ + Z_LOG_MSG_CBPRINTF_FLAGS(_cstr_cnt), \ __VA_ARGS__); \ if (IS_ENABLED(CONFIG_LOG_SPEED) && _try_0cpy && ((_dlen) == 0) && !has_rw_str) {\ - LOG_MSG2_DBG("create zero-copy message\n");\ - Z_LOG_MSG2_SIMPLE_CREATE(_cstr_cnt, _domain_id, _source, \ + LOG_MSG_DBG("create zero-copy message\n");\ + Z_LOG_MSG_SIMPLE_CREATE(_cstr_cnt, _domain_id, _source, \ _level, Z_LOG_FMT_ARGS(_fmt, ##__VA_ARGS__)); \ - _mode = Z_LOG_MSG2_MODE_ZERO_COPY; \ + _mode = Z_LOG_MSG_MODE_ZERO_COPY; \ } else { \ - LOG_MSG2_DBG("create on stack message\n");\ - Z_LOG_MSG2_STACK_CREATE(_cstr_cnt, _domain_id, _source, _level, _data, \ + LOG_MSG_DBG("create on stack message\n");\ + Z_LOG_MSG_STACK_CREATE(_cstr_cnt, _domain_id, _source, _level, _data, \ _dlen, Z_LOG_FMT_ARGS(_fmt, ##__VA_ARGS__)); \ - _mode = Z_LOG_MSG2_MODE_FROM_STACK; \ + _mode = Z_LOG_MSG_MODE_FROM_STACK; \ } \ (void)_mode; \ } while (false) @@ -449,14 +453,14 @@ do { \ * This is done to prevent multiple evaluations of input arguments (in case argument * evaluation has side effects, e.g. it is a non-pure function call). */ -#define Z_LOG_MSG2_CREATE2(_try_0cpy, _mode, _cstr_cnt, _domain_id, _source, \ +#define Z_LOG_MSG_CREATE2(_try_0cpy, _mode, _cstr_cnt, _domain_id, _source, \ _level, _data, _dlen, ...) \ do { \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \ FOR_EACH_IDX(Z_LOG_LOCAL_ARG_CREATE, (;), __VA_ARGS__); \ _Pragma("GCC diagnostic pop") \ - Z_LOG_MSG2_CREATE3(_try_0cpy, _mode, _cstr_cnt, _domain_id, _source,\ + Z_LOG_MSG_CREATE3(_try_0cpy, _mode, _cstr_cnt, _domain_id, _source,\ _level, _data, _dlen, \ FOR_EACH_IDX(Z_LOG_LOCAL_ARG_NAME, (,), __VA_ARGS__)); \ } while (false) @@ -465,9 +469,9 @@ do { \ */ -#define Z_LOG_MSG2_CREATE(_try_0cpy, _mode, _domain_id, _source,\ +#define Z_LOG_MSG_CREATE(_try_0cpy, _mode, _domain_id, _source,\ _level, _data, _dlen, ...) \ - Z_LOG_MSG2_CREATE2(_try_0cpy, _mode, UTIL_CAT(Z_LOG_FUNC_PREFIX_, _level), \ + Z_LOG_MSG_CREATE2(_try_0cpy, _mode, UTIL_CAT(Z_LOG_FUNC_PREFIX_, _level), \ _domain_id, _source, _level, _data, _dlen, \ Z_LOG_STR(_level, __VA_ARGS__)) @@ -573,7 +577,7 @@ static inline void z_log_msg_runtime_create(uint8_t domain_id, static inline bool z_log_item_is_msg(const union log_msg_generic *msg) { - return msg->generic.type == Z_LOG_MSG2_LOG; + return msg->generic.type == Z_LOG_MSG_LOG; } /** @brief Get total length (in 32 bit words) of a log message. @@ -584,7 +588,7 @@ static inline bool z_log_item_is_msg(const union log_msg_generic *msg) */ static inline uint32_t log_msg_get_total_wlen(const struct log_msg_desc desc) { - return Z_LOG_MSG2_ALIGNED_WLEN(desc.package_len, desc.data_len); + return Z_LOG_MSG_ALIGNED_WLEN(desc.package_len, desc.data_len); } /** @brief Get length of the log item. diff --git a/include/zephyr/shell/shell_log_backend.h b/include/zephyr/shell/shell_log_backend.h index d229d0f0e654..620709ffd6a3 100644 --- a/include/zephyr/shell/shell_log_backend.h +++ b/include/zephyr/shell/shell_log_backend.h @@ -72,7 +72,7 @@ int z_shell_log_backend_output_func(uint8_t *data, size_t length, void *ctx); LOG_OUTPUT_DEFINE(_name##_log_output, z_shell_log_backend_output_func,\ _buf, _size); \ static struct shell_log_backend_control_block _name##_control_block; \ - static uint32_t __aligned(Z_LOG_MSG2_ALIGNMENT) \ + static uint32_t __aligned(Z_LOG_MSG_ALIGNMENT) \ _name##_buf[_queue_size / sizeof(uint32_t)]; \ const struct mpsc_pbuf_buffer_config _name##_mpsc_buffer_config = { \ .buf = _name##_buf, \ diff --git a/subsys/logging/backends/log_multidomain_backend.c b/subsys/logging/backends/log_multidomain_backend.c index 652dd0b06fee..603c433b5d6b 100644 --- a/subsys/logging/backends/log_multidomain_backend.c +++ b/subsys/logging/backends/log_multidomain_backend.c @@ -33,7 +33,7 @@ static void process(const struct log_backend *const backend, } /* Need to ensure that package is aligned to a pointer size. */ - uint32_t msg_len = Z_LOG_MSG2_LEN(fsc_plen, dlen); + uint32_t msg_len = Z_LOG_MSG_LEN(fsc_plen, dlen); uint8_t buf[msg_len + sizeof(void *)] __aligned(sizeof(void *)); size_t msg_offset = offsetof(struct log_multidomain_msg, data); struct log_multidomain_msg *out_msg = diff --git a/subsys/logging/log_core.c b/subsys/logging/log_core.c index 8b5bb2a43301..6c2430e3a35f 100644 --- a/subsys/logging/log_core.c +++ b/subsys/logging/log_core.c @@ -112,7 +112,7 @@ static STRUCT_SECTION_ITERABLE(log_msg_ptr, log_msg_ptr); static STRUCT_SECTION_ITERABLE_ALTERNATE(log_mpsc_pbuf, mpsc_pbuf_buffer, log_buffer); static struct mpsc_pbuf_buffer *curr_log_buffer; -static uint32_t __aligned(Z_LOG_MSG2_ALIGNMENT) +static uint32_t __aligned(Z_LOG_MSG_ALIGNMENT) buf32[CONFIG_LOG_BUFFER_SIZE / sizeof(int)]; static void z_log_notify_drop(const struct mpsc_pbuf_buffer *buffer, @@ -201,7 +201,7 @@ void z_log_vprintk(const char *fmt, va_list ap) z_log_msg_runtime_vcreate(Z_LOG_LOCAL_DOMAIN_ID, NULL, LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, - Z_LOG_MSG2_CBPRINTF_FLAGS(0), + Z_LOG_MSG_CBPRINTF_FLAGS(0), fmt, ap); } @@ -752,7 +752,7 @@ bool z_log_msg_pending(void) void z_log_msg_enqueue(const struct log_link *link, const void *data, size_t len) { struct log_msg *log_msg = (struct log_msg *)data; - size_t wlen = ceiling_fraction(ROUND_UP(len, Z_LOG_MSG2_ALIGNMENT), sizeof(int)); + size_t wlen = ceiling_fraction(ROUND_UP(len, Z_LOG_MSG_ALIGNMENT), sizeof(int)); struct mpsc_pbuf_buffer *mpsc_pbuffer = link->mpsc_pbuf ? link->mpsc_pbuf : &log_buffer; struct log_msg *local_msg = msg_alloc(mpsc_pbuffer, wlen); diff --git a/subsys/logging/log_msg.c b/subsys/logging/log_msg.c index 456cb0f94a48..27b6f871276a 100644 --- a/subsys/logging/log_msg.c +++ b/subsys/logging/log_msg.c @@ -9,6 +9,8 @@ #include #include #include +#include +LOG_MODULE_DECLARE(log); /* Returns true if any backend is in use. */ #define BACKENDS_IN_USE() \ @@ -61,6 +63,12 @@ void z_impl_z_log_msg_static_create(const void *source, NULL, 0, flags, strl, ARRAY_SIZE(strl)); + if (len > Z_LOG_MSG_MAX_PACKAGE) + { + LOG_WRN("Log message dropped because it exceeds current limitation (%u)", + (uint32_t)Z_LOG_MSG_MAX_PACKAGE); + return; + } /* Update package length with calculated value (which may be extended * when strings are copied into the package. */ @@ -99,7 +107,7 @@ void z_impl_z_log_msg_runtime_vcreate(uint8_t domain_id, const void *source, va_list ap2; va_copy(ap2, ap); - plen = cbvprintf_package(NULL, Z_LOG_MSG2_ALIGN_OFFSET, + plen = cbvprintf_package(NULL, Z_LOG_MSG_ALIGN_OFFSET, package_flags, fmt, ap2); __ASSERT_NO_MSG(plen >= 0); va_end(ap2); @@ -107,7 +115,7 @@ void z_impl_z_log_msg_runtime_vcreate(uint8_t domain_id, const void *source, plen = 0; } - size_t msg_wlen = Z_LOG_MSG2_ALIGNED_WLEN(plen, dlen); + size_t msg_wlen = Z_LOG_MSG_ALIGNED_WLEN(plen, dlen); struct log_msg *msg; uint8_t *pkg; struct log_msg_desc desc = diff --git a/tests/subsys/logging/log_core_additional/src/log_test.c b/tests/subsys/logging/log_core_additional/src/log_test.c index e1039eba49f1..34cb712c771e 100644 --- a/tests/subsys/logging/log_core_additional/src/log_test.c +++ b/tests/subsys/logging/log_core_additional/src/log_test.c @@ -484,11 +484,11 @@ ZTEST(test_log_core_additional, test_log_msg_create) level, &msg_data, 0, sizeof(msg_data), NULL); /* try z_log_msg_static_create() */ - Z_LOG_MSG2_STACK_CREATE(0, domain, __log_current_const_data, + Z_LOG_MSG_STACK_CREATE(0, domain, __log_current_const_data, level, &msg_data, sizeof(msg_data), NULL); - Z_LOG_MSG2_CREATE(!IS_ENABLED(CONFIG_USERSPACE), mode, + Z_LOG_MSG_CREATE(!IS_ENABLED(CONFIG_USERSPACE), mode, Z_LOG_LOCAL_DOMAIN_ID, NULL, LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, TEST_MESSAGE); @@ -510,11 +510,11 @@ ZTEST_USER(test_log_core_additional, test_log_msg_create_user) level, &msg_data, 0, sizeof(msg_data), TEST_MESSAGE); /* try z_log_msg_static_create() */ - Z_LOG_MSG2_STACK_CREATE(0, domain, NULL, + Z_LOG_MSG_STACK_CREATE(0, domain, NULL, level, &msg_data, sizeof(msg_data), TEST_MESSAGE); - Z_LOG_MSG2_CREATE(!IS_ENABLED(CONFIG_USERSPACE), mode, + Z_LOG_MSG_CREATE(!IS_ENABLED(CONFIG_USERSPACE), mode, Z_LOG_LOCAL_DOMAIN_ID, NULL, LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, TEST_MESSAGE); diff --git a/tests/subsys/logging/log_link_order/src/main.c b/tests/subsys/logging/log_link_order/src/main.c index 4797688e41f9..1fc537c8cef8 100644 --- a/tests/subsys/logging/log_link_order/src/main.c +++ b/tests/subsys/logging/log_link_order/src/main.c @@ -95,14 +95,14 @@ ZTEST(log_link_order, test_log_only_local) struct log_msg *log1; log1 = z_log_msg_alloc(sizeof(struct log_msg) / sizeof(int)); - log1->hdr.desc.type = Z_LOG_MSG2_LOG; + log1->hdr.desc.type = Z_LOG_MSG_LOG; log1->hdr.desc.package_len = 0; log1->hdr.desc.data_len = 0; /* Commit local message. */ z_log_msg_commit(log1); - log2.hdr.desc.type = Z_LOG_MSG2_LOG; + log2.hdr.desc.type = Z_LOG_MSG_LOG; log2.hdr.desc.package_len = 0; log2.hdr.desc.data_len = 0; @@ -136,7 +136,7 @@ ZTEST(log_link_order, test_log_local_unordered) /* Simulate receiving of remote message. It is enqueued later but with * earlier timestamp. */ - log2.hdr.desc.type = Z_LOG_MSG2_LOG; + log2.hdr.desc.type = Z_LOG_MSG_LOG; log2.hdr.timestamp = t; log2.hdr.desc.package_len = 0; log2.hdr.desc.data_len = 0; @@ -172,7 +172,7 @@ ZTEST(log_link_order, test_log_one_remote_ordering) */ log2.hdr.timestamp = t; - log2.hdr.desc.type = Z_LOG_MSG2_LOG; + log2.hdr.desc.type = Z_LOG_MSG_LOG; log2.hdr.desc.package_len = 0; log2.hdr.desc.data_len = 0; diff --git a/tests/subsys/logging/log_msg/src/main.c b/tests/subsys/logging/log_msg/src/main.c index b87ae791b467..5696f7917939 100644 --- a/tests/subsys/logging/log_msg/src/main.c +++ b/tests/subsys/logging/log_msg/src/main.c @@ -20,9 +20,9 @@ #include #if CONFIG_NO_OPTIMIZATIONS -#define EXP_MODE(name) Z_LOG_MSG2_MODE_RUNTIME +#define EXP_MODE(name) Z_LOG_MSG_MODE_RUNTIME #else -#define EXP_MODE(name) Z_LOG_MSG2_MODE_##name +#define EXP_MODE(name) Z_LOG_MSG_MODE_##name #endif #define TEST_TIMESTAMP_INIT_VALUE \ @@ -152,9 +152,9 @@ void validate_base_message_set(const struct log_source_const_data *source, log_timestamp_t t, const void *data, size_t data_len, char *str) { - uint8_t __aligned(Z_LOG_MSG2_ALIGNMENT) buf0[256]; - uint8_t __aligned(Z_LOG_MSG2_ALIGNMENT) buf1[256]; - uint8_t __aligned(Z_LOG_MSG2_ALIGNMENT) buf2[256]; + uint8_t __aligned(Z_LOG_MSG_ALIGNMENT) buf0[256]; + uint8_t __aligned(Z_LOG_MSG_ALIGNMENT) buf1[256]; + uint8_t __aligned(Z_LOG_MSG_ALIGNMENT) buf2[256]; size_t len0, len1, len2; union log_msg_generic *msg0, *msg1, *msg2; @@ -209,11 +209,11 @@ ZTEST(log_msg, test_log_msg_0_args_msg) test_init(); printk("Test string:%s\n", TEST_MSG); - Z_LOG_MSG2_CREATE3(1, mode, 0, domain, source, level, + Z_LOG_MSG_CREATE3(1, mode, 0, domain, source, level, NULL, 0, TEST_MSG); zassert_equal(mode, EXP_MODE(ZERO_COPY)); - Z_LOG_MSG2_CREATE3(0, mode, 0, domain, source, level, + Z_LOG_MSG_CREATE3(0, mode, 0, domain, source, level, NULL, 0, TEST_MSG); zassert_equal(mode, EXP_MODE(FROM_STACK)); @@ -242,11 +242,11 @@ ZTEST(log_msg, test_log_msg_various_args) test_init(); printk("Test string:%s\n", TEST_MSG); - Z_LOG_MSG2_CREATE3(1, mode, 0, domain, source, level, NULL, 0, + Z_LOG_MSG_CREATE3(1, mode, 0, domain, source, level, NULL, 0, TEST_MSG, s8, u, lld, (void *)str, lld, (void *)iarray); zassert_equal(mode, EXP_MODE(ZERO_COPY)); - Z_LOG_MSG2_CREATE3(0, mode, 0, domain, source, level, NULL, 0, + Z_LOG_MSG_CREATE3(0, mode, 0, domain, source, level, NULL, 0, TEST_MSG, s8, u, lld, (void *)str, lld, (void *)iarray); zassert_equal(mode, EXP_MODE(FROM_STACK)); @@ -269,11 +269,11 @@ ZTEST(log_msg, test_log_msg_only_data) test_init(); - Z_LOG_MSG2_CREATE3(1, mode, 0, domain, source, level, array, + Z_LOG_MSG_CREATE3(1, mode, 0, domain, source, level, array, sizeof(array)); zassert_equal(mode, EXP_MODE(FROM_STACK)); - Z_LOG_MSG2_CREATE3(0, mode, 0, domain, source, level, array, + Z_LOG_MSG_CREATE3(0, mode, 0, domain, source, level, array, sizeof(array)); zassert_equal(mode, EXP_MODE(FROM_STACK)); @@ -298,11 +298,11 @@ ZTEST(log_msg, test_log_msg_string_and_data) test_init(); - Z_LOG_MSG2_CREATE3(1, mode, 0, domain, source, level, array, + Z_LOG_MSG_CREATE3(1, mode, 0, domain, source, level, array, sizeof(array), TEST_MSG); zassert_equal(mode, EXP_MODE(FROM_STACK)); - Z_LOG_MSG2_CREATE3(0, mode, 0, domain, source, level, array, + Z_LOG_MSG_CREATE3(0, mode, 0, domain, source, level, array, sizeof(array), TEST_MSG); zassert_equal(mode, EXP_MODE(FROM_STACK)); @@ -335,11 +335,11 @@ ZTEST(log_msg, test_log_msg_fp) test_init(); - Z_LOG_MSG2_CREATE3(1, mode, 0, domain, source, level, NULL, 0, + Z_LOG_MSG_CREATE3(1, mode, 0, domain, source, level, NULL, 0, TEST_MSG, i, lli, (double)f, &i, d, source); zassert_equal(mode, EXP_MODE(ZERO_COPY)); - Z_LOG_MSG2_CREATE3(0, mode, 0, domain, source, level, NULL, 0, + Z_LOG_MSG_CREATE3(0, mode, 0, domain, source, level, NULL, 0, TEST_MSG, i, lli, (double)f, &i, d, source); zassert_equal(mode, EXP_MODE(FROM_STACK)); @@ -374,12 +374,12 @@ ZTEST(log_msg, test_mode_size_plain_string) uint32_t exp_len; int mode; - Z_LOG_MSG2_CREATE3(1, mode, 0, domain, source, level, NULL, 0, + Z_LOG_MSG_CREATE3(1, mode, 0, domain, source, level, NULL, 0, "test str"); zassert_equal(mode, EXP_MODE(ZERO_COPY), "Unexpected creation mode"); - Z_LOG_MSG2_CREATE3(0, mode, 0, domain, source, level, NULL, 0, + Z_LOG_MSG_CREATE3(0, mode, 0, domain, source, level, NULL, 0, "test str"); zassert_equal(mode, EXP_MODE(FROM_STACK), "Unexpected creation mode"); @@ -393,7 +393,7 @@ ZTEST(log_msg, test_mode_size_plain_string) exp_len = offsetof(struct log_msg, data) + /* package */sizeof(struct cbprintf_package_hdr_ext); - exp_len = ROUND_UP(exp_len, Z_LOG_MSG2_ALIGNMENT) / sizeof(int); + exp_len = ROUND_UP(exp_len, Z_LOG_MSG_ALIGNMENT) / sizeof(int); get_msg_validate_length(exp_len); get_msg_validate_length(exp_len); } @@ -410,7 +410,7 @@ ZTEST(log_msg, test_mode_size_data_only) */ uint8_t data[] = {1, 2, 3}; - Z_LOG_MSG2_CREATE3(1, mode, 0, domain, source, level, + Z_LOG_MSG_CREATE3(1, mode, 0, domain, source, level, data, sizeof(data)); zassert_equal(mode, EXP_MODE(FROM_STACK), "Unexpected creation mode"); @@ -422,7 +422,7 @@ ZTEST(log_msg, test_mode_size_data_only) * Message size is rounded up to the required alignment. */ exp_len = offsetof(struct log_msg, data) + sizeof(data); - exp_len = ROUND_UP(exp_len, Z_LOG_MSG2_ALIGNMENT) / sizeof(int); + exp_len = ROUND_UP(exp_len, Z_LOG_MSG_ALIGNMENT) / sizeof(int); get_msg_validate_length(exp_len); } @@ -438,7 +438,7 @@ ZTEST(log_msg, test_mode_size_plain_str_data) */ uint8_t data[] = {1, 2, 3}; - Z_LOG_MSG2_CREATE3(1, mode, 0, domain, source, level, + Z_LOG_MSG_CREATE3(1, mode, 0, domain, source, level, data, sizeof(data), "test"); zassert_equal(mode, EXP_MODE(FROM_STACK), "Unexpected creation mode"); @@ -451,7 +451,7 @@ ZTEST(log_msg, test_mode_size_plain_str_data) */ exp_len = offsetof(struct log_msg, data) + sizeof(data) + /* package */sizeof(struct cbprintf_package_hdr_ext); - exp_len = ROUND_UP(exp_len, Z_LOG_MSG2_ALIGNMENT) / sizeof(int); + exp_len = ROUND_UP(exp_len, Z_LOG_MSG_ALIGNMENT) / sizeof(int); get_msg_validate_length(exp_len); } @@ -464,13 +464,13 @@ ZTEST(log_msg, test_mode_size_str_with_strings) int mode; static const char *prefix = "prefix"; - Z_LOG_MSG2_CREATE3(1, mode, + Z_LOG_MSG_CREATE3(1, mode, 1 /* accept one string pointer*/, domain, source, level, NULL, 0, "test %s", prefix); zassert_equal(mode, EXP_MODE(ZERO_COPY), "Unexpected creation mode"); - Z_LOG_MSG2_CREATE3(0, mode, + Z_LOG_MSG_CREATE3(0, mode, 1 /* accept one string pointer*/, domain, source, level, NULL, 0, "test %s", prefix); @@ -486,7 +486,7 @@ ZTEST(log_msg, test_mode_size_str_with_strings) exp_len = offsetof(struct log_msg, data) + /* package */sizeof(struct cbprintf_package_hdr_ext) + sizeof(const char *); - exp_len = ROUND_UP(exp_len, Z_LOG_MSG2_ALIGNMENT) / sizeof(int); + exp_len = ROUND_UP(exp_len, Z_LOG_MSG_ALIGNMENT) / sizeof(int); get_msg_validate_length(exp_len); get_msg_validate_length(exp_len); @@ -505,13 +505,13 @@ ZTEST(log_msg, test_mode_size_str_with_2strings) static const char *prefix = "prefix"; char sufix[] = "sufix"; - Z_LOG_MSG2_CREATE3(1, mode, + Z_LOG_MSG_CREATE3(1, mode, 1 /* accept one string pointer*/, domain, source, level, NULL, 0, TEST_STR, prefix, sufix); zassert_equal(mode, EXP_MODE(FROM_STACK), "Unexpected creation mode"); - Z_LOG_MSG2_CREATE3(0, mode, + Z_LOG_MSG_CREATE3(0, mode, 1 /* accept one string pointer*/, domain, source, level, NULL, 0, TEST_STR, prefix, sufix); @@ -529,7 +529,7 @@ ZTEST(log_msg, test_mode_size_str_with_2strings) /* package */sizeof(struct cbprintf_package_hdr_ext) + 2 * sizeof(const char *) + 2 + strlen(sufix); - exp_len = ROUND_UP(exp_len, Z_LOG_MSG2_ALIGNMENT) / sizeof(int); + exp_len = ROUND_UP(exp_len, Z_LOG_MSG_ALIGNMENT) / sizeof(int); get_msg_validate_length(exp_len); get_msg_validate_length(exp_len); @@ -548,7 +548,7 @@ ZTEST(log_msg, test_saturate) uint32_t exp_len = ROUND_UP(offsetof(struct log_msg, data) + 2 * sizeof(void *), - Z_LOG_MSG2_ALIGNMENT); + Z_LOG_MSG_ALIGNMENT); uint32_t exp_capacity = CONFIG_LOG_BUFFER_SIZE / exp_len; int mode; union log_msg_generic *msg; @@ -558,14 +558,14 @@ ZTEST(log_msg, test_saturate) log_set_timestamp_func(timestamp_get_inc, 0); for (int i = 0; i < exp_capacity; i++) { - Z_LOG_MSG2_CREATE3(1, mode, 0, 0, (void *)1, 2, NULL, 0, "test"); + Z_LOG_MSG_CREATE3(1, mode, 0, 0, (void *)1, 2, NULL, 0, "test"); } zassert_equal(z_log_dropped_read_and_clear(), 0, "No dropped messages."); /* Message should not fit in and be dropped. */ - Z_LOG_MSG2_CREATE3(1, mode, 0, 0, (void *)1, 2, NULL, 0, "test"); - Z_LOG_MSG2_CREATE3(0, mode, 0, 0, (void *)1, 2, NULL, 0, "test"); + Z_LOG_MSG_CREATE3(1, mode, 0, 0, (void *)1, 2, NULL, 0, "test"); + Z_LOG_MSG_CREATE3(0, mode, 0, 0, (void *)1, 2, NULL, 0, "test"); z_log_msg_runtime_create(0, (void *)1, 2, NULL, 0, 0, "test"); zassert_equal(z_log_dropped_read_and_clear(), 3, "No dropped messages."); From a5979dcfa1349954113be457fc2b0a72a1068c8a Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Thu, 16 Feb 2023 13:54:40 +0100 Subject: [PATCH 0086/1906] logging: Log warning and drop too big message When packacge exceeds the limitation warning log is printed and message is dropped. Signed-off-by: Krzysztof Chruscinski --- subsys/logging/log_msg.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/subsys/logging/log_msg.c b/subsys/logging/log_msg.c index 27b6f871276a..8bc1e2e9ef1b 100644 --- a/subsys/logging/log_msg.c +++ b/subsys/logging/log_msg.c @@ -63,10 +63,12 @@ void z_impl_z_log_msg_static_create(const void *source, NULL, 0, flags, strl, ARRAY_SIZE(strl)); - if (len > Z_LOG_MSG_MAX_PACKAGE) - { - LOG_WRN("Log message dropped because it exceeds current limitation (%u)", - (uint32_t)Z_LOG_MSG_MAX_PACKAGE); + if (len > Z_LOG_MSG_MAX_PACKAGE) { + struct cbprintf_package_hdr_ext *pkg = + (struct cbprintf_package_hdr_ext *)package; + + LOG_WRN("Message (\"%s\") dropped because it exceeds size limitation (%u)", + pkg->fmt, (uint32_t)Z_LOG_MSG_MAX_PACKAGE); return; } /* Update package length with calculated value (which may be extended From 68955ebdb6d8a9c6598810446fecc316209089e1 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Thu, 16 Feb 2023 13:58:58 +0100 Subject: [PATCH 0087/1906] logging: Increase package size limit to 2047 Package length was previously stored on 10 bits which limited package size to 1023 bytes. Descriptor which contained package length field had one unused bit which can be used to increase package length field to 11 bits doubling the maximum package length. Signed-off-by: Krzysztof Chruscinski --- include/zephyr/logging/log_msg.h | 4 +--- subsys/logging/log_msg.c | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/zephyr/logging/log_msg.h b/include/zephyr/logging/log_msg.h index 0113d8b50c2f..452332778bba 100644 --- a/include/zephyr/logging/log_msg.h +++ b/include/zephyr/logging/log_msg.h @@ -44,7 +44,7 @@ typedef uint32_t log_timestamp_t; #define Z_LOG_MSG_LOG 0 -#define Z_LOG_MSG_PACKAGE_BITS 10 +#define Z_LOG_MSG_PACKAGE_BITS 11 #define Z_LOG_MSG_MAX_PACKAGE BIT_MASK(Z_LOG_MSG_PACKAGE_BITS) @@ -58,7 +58,6 @@ struct log_msg_desc { uint32_t level:3; uint32_t package_len:Z_LOG_MSG_PACKAGE_BITS; uint32_t data_len:12; - uint32_t reserved:1; }; union log_msg_source { @@ -149,7 +148,6 @@ enum z_log_msg_mode { .level = _level, \ .package_len = _plen, \ .data_len = _dlen, \ - .reserved = 0, \ } #define Z_LOG_MSG_CBPRINTF_FLAGS(_cstr_cnt) \ diff --git a/subsys/logging/log_msg.c b/subsys/logging/log_msg.c index 8bc1e2e9ef1b..3ca3a5d63991 100644 --- a/subsys/logging/log_msg.c +++ b/subsys/logging/log_msg.c @@ -12,6 +12,9 @@ #include LOG_MODULE_DECLARE(log); +BUILD_ASSERT(sizeof(struct log_msg_desc) == sizeof(uint32_t), + "Descriptor must fit in 32 bits"); + /* Returns true if any backend is in use. */ #define BACKENDS_IN_USE() \ !(IS_ENABLED(CONFIG_LOG_FRONTEND) && \ From a40434748c91c839052b4ff4d283d00edcc9375d Mon Sep 17 00:00:00 2001 From: Erik Brockhoff Date: Thu, 9 Mar 2023 12:35:52 +0100 Subject: [PATCH 0088/1906] Revert "Bluetooth: controller: fixing CIS establish flow for refactored LLCP" This reverts commit 1d8acfe5faee22b4cec4de49e9ef2049468c89a5. Signed-off-by: Erik Brockhoff --- subsys/bluetooth/controller/ll_sw/ull_conn_iso.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c index a4cf9dc42e69..0ac351c47657 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c @@ -296,12 +296,15 @@ void ull_conn_iso_lll_cis_established(struct lll_conn_iso_stream *cis_lll) { struct ll_conn_iso_stream *cis = ll_conn_iso_stream_get(cis_lll->handle); - struct node_rx_pdu *node_rx; if (cis->established) { return; } +#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) + struct node_rx_conn_iso_estab *est; + struct node_rx_pdu *node_rx; + node_rx = ull_pdu_rx_alloc(); if (!node_rx) { /* No node available - try again later */ @@ -310,8 +313,6 @@ void ull_conn_iso_lll_cis_established(struct lll_conn_iso_stream *cis_lll) node_rx->hdr.type = NODE_RX_TYPE_CIS_ESTABLISHED; -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - struct node_rx_conn_iso_estab *est; /* TODO: Send CIS_ESTABLISHED with status != 0 in error scenarios */ node_rx->hdr.handle = 0xFFFF; node_rx->hdr.rx_ftr.param = cis; @@ -321,12 +322,7 @@ void ull_conn_iso_lll_cis_established(struct lll_conn_iso_stream *cis_lll) est->cis_handle = cis_lll->handle; ll_rx_put_sched(node_rx->hdr.link, node_rx); -#else - /* Send node to ULL RX demuxer for triggering LLCP state machine */ - node_rx->hdr.handle = cis->lll.acl_handle; - - ull_rx_put_sched(node_rx->hdr.link, node_rx); -#endif /* defined(CONFIG_BT_LL_SW_LLCP_LEGACY) */ +#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ cis->established = 1; } From 1028cab11eca4049aa95e6bd89721e554dae3bb0 Mon Sep 17 00:00:00 2001 From: Erik Brockhoff Date: Thu, 9 Mar 2023 12:36:02 +0100 Subject: [PATCH 0089/1906] Revert "Bluetooth: controller: use RX node piggy-back for NTF when possible" This reverts commit 6dbc446342994c53e875016a0e03d35bdf9d31ac. Signed-off-by: Erik Brockhoff --- subsys/bluetooth/controller/ll_sw/lll.h | 2 - subsys/bluetooth/controller/ll_sw/ull.c | 3 +- subsys/bluetooth/controller/ll_sw/ull_conn.c | 8 +- subsys/bluetooth/controller/ll_sw/ull_llcp.c | 38 +- subsys/bluetooth/controller/ll_sw/ull_llcp.h | 7 +- .../bluetooth/controller/ll_sw/ull_llcp_cc.c | 167 +++++---- .../controller/ll_sw/ull_llcp_common.c | 259 +++++++------- .../controller/ll_sw/ull_llcp_conn_upd.c | 238 ++++--------- .../bluetooth/controller/ll_sw/ull_llcp_enc.c | 116 ++++-- .../controller/ll_sw/ull_llcp_internal.h | 25 +- .../controller/ll_sw/ull_llcp_local.c | 13 +- .../bluetooth/controller/ll_sw/ull_llcp_phy.c | 332 +++++++++--------- .../controller/ll_sw/ull_llcp_remote.c | 21 +- .../controller/common/include/helper_util.h | 1 - .../controller/common/src/helper_util.c | 38 +- .../controller/ctrl_cis_create/src/main.c | 27 +- .../controller/ctrl_collision/src/main.c | 18 +- .../controller/ctrl_conn_update/src/main.c | 70 ++-- .../controller/ctrl_cte_req/src/main.c | 14 +- .../ctrl_data_length_update/src/main.c | 34 +- .../controller/ctrl_encrypt/src/main.c | 89 ++++- .../ctrl_feature_exchange/src/main.c | 43 ++- .../ctrl_feature_exchange/src/main_hci.c | 2 +- .../bluetooth/controller/ctrl_hci/src/main.c | 4 +- .../controller/ctrl_phy_update/src/main.c | 105 +----- .../bluetooth/controller/mock_ctrl/src/ull.c | 6 +- 26 files changed, 822 insertions(+), 858 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll.h b/subsys/bluetooth/controller/ll_sw/lll.h index 775bb9cd34f3..4f988ae3fb86 100644 --- a/subsys/bluetooth/controller/ll_sw/lll.h +++ b/subsys/bluetooth/controller/ll_sw/lll.h @@ -316,8 +316,6 @@ enum node_rx_type { NODE_RX_TYPE_DTM_IQ_SAMPLE_REPORT, NODE_RX_TYPE_IQ_SAMPLE_REPORT_ULL_RELEASE, NODE_RX_TYPE_IQ_SAMPLE_REPORT_LLL_RELEASE, - /* Signals retention (ie non-release) of rx node */ - NODE_RX_TYPE_RETAIN, #if defined(CONFIG_BT_CTLR_USER_EXT) /* No entries shall be added after the NODE_RX_TYPE_USER_START/END */ diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index c01bb6f5878b..533682e69e67 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -2829,8 +2829,7 @@ static inline int rx_demux_rx(memq_link_t *link, struct node_rx_hdr *rx) (void)memq_dequeue(memq_ull_rx.tail, &memq_ull_rx.head, NULL); - /* Only schedule node if not marked as retain by LLCP */ - if (rx && rx->type != NODE_RX_TYPE_RETAIN) { + if (rx) { ll_rx_put_sched(link, rx); } } diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index ba35c53fe330..38d12a0ee5dc 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -1144,7 +1144,6 @@ int ull_conn_rx(memq_link_t *link, struct node_rx_pdu **rx) #endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ #if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - /* Handle possibly pending NTF/complete */ ull_cp_tx_ntf(conn); #endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ @@ -1159,13 +1158,13 @@ int ull_conn_rx(memq_link_t *link, struct node_rx_pdu **rx) nack = ctrl_rx(link, rx, pdu_rx, conn); return nack; #else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ + ARG_UNUSED(link); ARG_UNUSED(pdu_rx); + ull_cp_rx(conn, *rx); + /* Mark buffer for release */ (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - ull_cp_rx(conn, link, *rx); - return 0; #endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ } @@ -1556,7 +1555,6 @@ void ull_conn_done(struct node_rx_event_done *done) #endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ #if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - /* Handle possibly pending NTF/complete */ ull_cp_tx_ntf(conn); #endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp.c b/subsys/bluetooth/controller/ll_sw/ull_llcp.c index e4a09a9c875c..36c351565e25 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp.c +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp.c @@ -279,17 +279,6 @@ void llcp_tx_resume_data(struct ll_conn *conn, enum llcp_tx_q_pause_data_mask re } } -void llcp_rx_node_retain(struct proc_ctx *ctx) -{ - LL_ASSERT(ctx->node_ref.rx); - - /* Mark RX node to NOT release */ - ctx->node_ref.rx->hdr.type = NODE_RX_TYPE_RETAIN; - - /* store link element reference to use once this node is moved up */ - ctx->node_ref.rx->hdr.link = ctx->node_ref.link; -} - /* * LLCP Procedure Creation */ @@ -307,8 +296,7 @@ static struct proc_ctx *create_procedure(enum llcp_proc proc, struct llcp_mem_po ctx->collision = 0U; ctx->done = 0U; ctx->rx_greedy = 0U; - ctx->node_ref.rx = NULL; - ctx->node_ref.tx_ack = NULL; + ctx->tx_ack = NULL; /* Clear procedure data */ memset((void *)&ctx->data, 0, sizeof(ctx->data)); @@ -587,6 +575,12 @@ void ull_cp_release_tx(struct ll_conn *conn, struct node_tx *tx) tx_release(tx); } +void ull_cp_release_ntf(struct node_rx_pdu *ntf) +{ + ntf->hdr.next = NULL; + ll_rx_mem_release((void **)&ntf); +} + static int prt_elapse(uint16_t *expire, uint16_t elapsed_event) { if (*expire != 0U) { @@ -1668,13 +1662,13 @@ void ull_cp_tx_ack(struct ll_conn *conn, struct node_tx *tx) struct proc_ctx *ctx; ctx = llcp_lr_peek(conn); - if (ctx && ctx->node_ref.tx_ack == tx) { + if (ctx && ctx->tx_ack == tx) { /* TX ack re. local request */ llcp_lr_tx_ack(conn, ctx, tx); } ctx = llcp_rr_peek(conn); - if (ctx && ctx->node_ref.tx_ack == tx) { + if (ctx && ctx->tx_ack == tx) { /* TX ack re. remote response */ llcp_rr_tx_ack(conn, ctx, tx); } @@ -1697,7 +1691,7 @@ void ull_cp_tx_ntf(struct ll_conn *conn) } } -void ull_cp_rx(struct ll_conn *conn, memq_link_t *link, struct node_rx_pdu *rx) +void ull_cp_rx(struct ll_conn *conn, struct node_rx_pdu *rx) { struct proc_ctx *ctx_l; struct proc_ctx *ctx_r; @@ -1768,7 +1762,7 @@ void ull_cp_rx(struct ll_conn *conn, memq_link_t *link, struct node_rx_pdu *rx) */ /* Process PDU in remote procedure */ - llcp_rr_rx(conn, ctx_r, link, rx); + llcp_rr_rx(conn, ctx_r, rx); } else if (unexpected_r) { /* Local active procedure * Expected local procedure PDU @@ -1777,7 +1771,7 @@ void ull_cp_rx(struct ll_conn *conn, memq_link_t *link, struct node_rx_pdu *rx) */ /* Process PDU in local procedure */ - llcp_lr_rx(conn, ctx_l, link, rx); + llcp_lr_rx(conn, ctx_l, rx); } else { /* Local active procedure * Expected local procedure PDU @@ -1805,7 +1799,7 @@ void ull_cp_rx(struct ll_conn *conn, memq_link_t *link, struct node_rx_pdu *rx) /* Process PDU as a new remote request */ LL_ASSERT(pdu_valid); - llcp_rr_new(conn, link, rx, true); + llcp_rr_new(conn, rx, true); } else { /* Local active procedure * Expected local procedure PDU @@ -1813,7 +1807,7 @@ void ull_cp_rx(struct ll_conn *conn, memq_link_t *link, struct node_rx_pdu *rx) */ /* Process PDU in local procedure */ - llcp_lr_rx(conn, ctx_l, link, rx); + llcp_lr_rx(conn, ctx_l, rx); } } } else if (ctx_r) { @@ -1822,14 +1816,14 @@ void ull_cp_rx(struct ll_conn *conn, memq_link_t *link, struct node_rx_pdu *rx) */ /* Process PDU in remote procedure */ - llcp_rr_rx(conn, ctx_r, link, rx); + llcp_rr_rx(conn, ctx_r, rx); } else { /* No local active procedure * No remote active procedure */ /* Process PDU as a new remote request */ - llcp_rr_new(conn, link, rx, pdu_valid); + llcp_rr_new(conn, rx, pdu_valid); } } diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp.h b/subsys/bluetooth/controller/ll_sw/ull_llcp.h index f897b100541d..a264e0297f3c 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp.h +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp.h @@ -35,6 +35,11 @@ void ull_cp_update_tx_buffer_queue(struct ll_conn *conn); */ void ull_cp_release_tx(struct ll_conn *conn, struct node_tx *tx); +/** + * + */ +void ull_cp_release_ntf(struct node_rx_pdu *ntf); + /** * @brief Procedure Response Timeout Check * @param elapsed_event The number of elapsed events. @@ -63,7 +68,7 @@ void ull_cp_tx_ntf(struct ll_conn *conn); /** * @brief Handle received LL Control PDU. */ -void ull_cp_rx(struct ll_conn *conn, memq_link_t *link, struct node_rx_pdu *rx); +void ull_cp_rx(struct ll_conn *conn, struct node_rx_pdu *rx); #if defined(CONFIG_BT_CTLR_LE_PING) /** diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c b/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c index dec930de2b16..6421f144ea52 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_cc.c @@ -52,18 +52,31 @@ #include #include "hal/debug.h" +static bool cc_check_cis_established_or_timeout_lll(struct proc_ctx *ctx) +{ + const struct ll_conn_iso_stream *cis = + ll_conn_iso_stream_get(ctx->data.cis_create.cis_handle); + + if (cis->established) { + return true; + } + + if (!cis->event_expire) { + ctx->data.cis_create.error = BT_HCI_ERR_CONN_FAIL_TO_ESTAB; + return true; + } + + return false; +} + static void cc_ntf_established(struct ll_conn *conn, struct proc_ctx *ctx) { - struct node_rx_conn_iso_estab *pdu; struct node_rx_pdu *ntf; - uint8_t piggy_back; + struct node_rx_conn_iso_estab *pdu; /* Allocate ntf node */ - ntf = ctx->node_ref.rx; + ntf = llcp_ntf_alloc(); LL_ASSERT(ntf); - ctx->node_ref.rx = NULL; - - piggy_back = (ntf->hdr.type != NODE_RX_TYPE_RETAIN); ntf->hdr.type = NODE_RX_TYPE_CIS_ESTABLISHED; ntf->hdr.handle = conn->lll.handle; @@ -74,10 +87,8 @@ static void cc_ntf_established(struct ll_conn *conn, struct proc_ctx *ctx) pdu->cis_handle = ctx->data.cis_create.cis_handle; pdu->status = ctx->data.cis_create.error; - if (!piggy_back) { - /* Enqueue notification towards LL */ - ll_rx_put_sched(ntf->hdr.link, ntf); - } + /* Enqueue notification towards LL */ + ll_rx_put_sched(ntf->hdr.link, ntf); } #if defined(CONFIG_BT_PERIPHERAL) @@ -86,13 +97,14 @@ enum { /* Establish Procedure */ RP_CC_STATE_IDLE, RP_CC_STATE_WAIT_RX_CIS_REQ, + RP_CC_STATE_WAIT_NTF_CIS_CREATE, RP_CC_STATE_WAIT_REPLY, RP_CC_STATE_WAIT_TX_CIS_RSP, RP_CC_STATE_WAIT_TX_REJECT_IND, RP_CC_STATE_WAIT_RX_CIS_IND, RP_CC_STATE_WAIT_INSTANT, RP_CC_STATE_WAIT_CIS_ESTABLISHED, - RP_CC_STATE_WAIT_NTF_AVAIL, + RP_CC_STATE_WAIT_NTF, }; /* LLCP Remote Procedure FSM events */ @@ -190,9 +202,8 @@ static void llcp_rp_cc_tx_reject(struct ll_conn *conn, struct proc_ctx *ctx, uin struct pdu_data *pdu; /* Allocate tx node */ - tx = ctx->node_ref.tx_ack; + tx = llcp_tx_alloc(conn, ctx); LL_ASSERT(tx); - ctx->node_ref.tx_ack = NULL; pdu = (struct pdu_data *)tx->pdu; @@ -209,8 +220,8 @@ static void rp_cc_ntf_create(struct ll_conn *conn, struct proc_ctx *ctx) struct node_rx_pdu *ntf; struct node_rx_conn_iso_req *pdu; - ntf = ctx->node_ref.rx; - ctx->node_ref.rx = NULL; + /* Allocate ntf node */ + ntf = llcp_ntf_alloc(); LL_ASSERT(ntf); ntf->hdr.type = NODE_RX_TYPE_CIS_REQUEST; @@ -222,13 +233,20 @@ static void rp_cc_ntf_create(struct ll_conn *conn, struct proc_ctx *ctx) pdu->cis_handle = ctx->data.cis_create.cis_handle; ctx->data.cis_create.host_request_to = 0U; + + /* Enqueue notification towards LL */ + ll_rx_put_sched(ntf->hdr.link, ntf); } static void rp_cc_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { - cc_ntf_established(conn, ctx); - llcp_rr_complete(conn); - ctx->state = RP_CC_STATE_IDLE; + if (!llcp_ntf_alloc_is_available()) { + ctx->state = RP_CC_STATE_WAIT_NTF; + } else { + cc_ntf_established(conn, ctx); + llcp_rr_complete(conn); + ctx->state = RP_CC_STATE_IDLE; + } } static void rp_cc_send_cis_rsp(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, @@ -245,28 +263,23 @@ static void rp_cc_send_cis_rsp(struct ll_conn *conn, struct proc_ctx *ctx, uint8 } } +static void rp_cc_send_create_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, + void *param) +{ + if (!llcp_ntf_alloc_is_available()) { + ctx->state = RP_CC_STATE_WAIT_NTF_CIS_CREATE; + } else { + rp_cc_ntf_create(conn, ctx); + ctx->state = RP_CC_STATE_WAIT_REPLY; + } +} + static void rp_cc_send_reject_ind(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { if (llcp_rr_ispaused(conn) || !llcp_tx_alloc_peek(conn, ctx)) { ctx->state = RP_CC_STATE_WAIT_TX_REJECT_IND; } else { - /* Allocate TX node to use, store in case we need to wait for NTF node */ - ctx->node_ref.tx_ack = llcp_tx_alloc(conn, ctx); - if (ctx->data.cis_create.error == BT_HCI_ERR_CONN_ACCEPT_TIMEOUT) { - /* We complete with error, so we must generate NTF, thus we must make sure - * we have a node to use for NTF before TX'ing - */ - if (!llcp_ntf_alloc_is_available()) { - ctx->state = RP_CC_STATE_WAIT_NTF_AVAIL; - return; - } - ctx->node_ref.rx = llcp_ntf_alloc(); - - /* Mark node as RETAIN to trigger put/sched */ - ctx->node_ref.rx->hdr.type = NODE_RX_TYPE_RETAIN; - } - llcp_rp_cc_tx_reject(conn, ctx, PDU_DATA_LLCTRL_TYPE_CIS_REQ); if (ctx->data.cis_create.error == BT_HCI_ERR_CONN_ACCEPT_TIMEOUT) { @@ -344,8 +357,7 @@ static void rp_cc_state_wait_rx_cis_req(struct ll_conn *conn, struct proc_ctx *c if (ctx->data.cis_create.error == BT_HCI_ERR_SUCCESS) { /* Now controller accepts, so go ask the host to accept or decline */ - rp_cc_ntf_create(conn, ctx); - ctx->state = RP_CC_STATE_WAIT_REPLY; + rp_cc_send_create_ntf(conn, ctx, evt, param); } else { /* Now controller rejects, right out */ rp_cc_send_reject_ind(conn, ctx, evt, param); @@ -398,9 +410,6 @@ static void rp_cc_state_wait_rx_cis_ind(struct ll_conn *conn, struct proc_ctx *c /* CIS has been setup, go wait for 'instant' before starting */ ctx->state = RP_CC_STATE_WAIT_INSTANT; - /* Mark node as RETAIN to keep until we need for NTF */ - llcp_rx_node_retain(ctx); - /* Check if this connection event is where we need to start the CIS */ rp_cc_check_instant(conn, ctx, evt, param); break; @@ -418,20 +427,12 @@ static void rp_cc_state_wait_rx_cis_ind(struct ll_conn *conn, struct proc_ctx *c } } -static void rp_cc_state_wait_ntf_avail(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, - void *param) +static void rp_cc_state_wait_ntf_cis_create(struct ll_conn *conn, struct proc_ctx *ctx, + uint8_t evt, void *param) { switch (evt) { case RP_CC_EVT_RUN: - if (llcp_ntf_alloc_is_available()) { - ctx->node_ref.rx = llcp_ntf_alloc(); - /* Mark node as RETAIN to trigger put/sched */ - ctx->node_ref.rx->hdr.type = NODE_RX_TYPE_RETAIN; - - /* Now we're good to TX reject and complete procedure*/ - llcp_rp_cc_tx_reject(conn, ctx, PDU_DATA_LLCTRL_TYPE_CIS_REQ); - rp_cc_complete(conn, ctx, evt, param); - } + rp_cc_send_create_ntf(conn, ctx, evt, param); break; default: /* Ignore other evts */ @@ -439,6 +440,18 @@ static void rp_cc_state_wait_ntf_avail(struct ll_conn *conn, struct proc_ctx *ct } } +static void rp_cc_state_wait_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, + void *param) +{ + switch (evt) { + case RP_CC_EVT_RUN: + rp_cc_complete(conn, ctx, evt, param); + break; + default: + /* Ignore other evts */ + break; + } +} static void rp_cc_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) @@ -511,7 +524,18 @@ static void rp_cc_state_wait_cis_established(struct ll_conn *conn, struct proc_c uint8_t evt, void *param) { switch (evt) { + case RP_CC_EVT_RUN: + /* Check for CIS state */ + if (cc_check_cis_established_or_timeout_lll(ctx)) { + /* CIS was established or establishement timed out, + * In either case complete procedure and generate + * notification + */ + rp_cc_complete(conn, ctx, evt, param); + } + break; case RP_CC_EVT_CIS_ESTABLISHED: + /* CIS was established, so let's go ahead and complete procedure */ rp_cc_complete(conn, ctx, evt, param); break; default: @@ -531,6 +555,9 @@ static void rp_cc_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_ case RP_CC_STATE_WAIT_RX_CIS_REQ: rp_cc_state_wait_rx_cis_req(conn, ctx, evt, param); break; + case RP_CC_STATE_WAIT_NTF_CIS_CREATE: + rp_cc_state_wait_ntf_cis_create(conn, ctx, evt, param); + break; case RP_CC_STATE_WAIT_TX_REJECT_IND: rp_cc_state_wait_tx_reject_ind(conn, ctx, evt, param); break; @@ -549,8 +576,8 @@ static void rp_cc_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_ case RP_CC_STATE_WAIT_CIS_ESTABLISHED: rp_cc_state_wait_cis_established(conn, ctx, evt, param); break; - case RP_CC_STATE_WAIT_NTF_AVAIL: - rp_cc_state_wait_ntf_avail(conn, ctx, evt, param); + case RP_CC_STATE_WAIT_NTF: + rp_cc_state_wait_ntf(conn, ctx, evt, param); break; default: /* Unknown state */ @@ -641,6 +668,7 @@ enum { LP_CC_STATE_WAIT_TX_CIS_IND, LP_CC_STATE_WAIT_INSTANT, LP_CC_STATE_WAIT_ESTABLISHED, + LP_CC_STATE_WAIT_NTF, }; /* LLCP Local Procedure CIS Creation FSM events */ @@ -795,9 +823,13 @@ static void lp_cc_send_cis_ind(struct ll_conn *conn, struct proc_ctx *ctx, uint8 static void lp_cc_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { - cc_ntf_established(conn, ctx); - llcp_lr_complete(conn); - ctx->state = LP_CC_STATE_IDLE; + if (!llcp_ntf_alloc_is_available()) { + ctx->state = LP_CC_STATE_WAIT_NTF; + } else { + cc_ntf_established(conn, ctx); + llcp_lr_complete(conn); + ctx->state = LP_CC_STATE_IDLE; + } } static void lp_cc_st_wait_rx_cis_rsp(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, @@ -809,10 +841,6 @@ static void lp_cc_st_wait_rx_cis_rsp(struct ll_conn *conn, struct proc_ctx *ctx, case LP_CC_EVT_CIS_RSP: /* TODO: Reject response if outside offset range? */ llcp_pdu_decode_cis_rsp(ctx, param); - - /* Mark RX node to NOT release */ - llcp_rx_node_retain(ctx); - lp_cc_send_cis_ind(conn, ctx, evt, param); break; case LP_CC_EVT_UNKNOWN: @@ -887,6 +915,12 @@ static void lp_cc_st_wait_established(struct ll_conn *conn, struct proc_ctx *ctx void *param) { switch (evt) { + case LP_CC_EVT_RUN: + if (cc_check_cis_established_or_timeout_lll(ctx)) { + /* CIS was established, so let's got ahead and complete procedure */ + lp_cc_complete(conn, ctx, evt, param); + } + break; case LP_CC_EVT_ESTABLISHED: /* CIS was established, so let's go ahead and complete procedure */ lp_cc_complete(conn, ctx, evt, param); @@ -897,6 +931,18 @@ static void lp_cc_st_wait_established(struct ll_conn *conn, struct proc_ctx *ctx } } +static void lp_cc_st_wait_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) +{ + switch (evt) { + case LP_CC_EVT_RUN: + lp_cc_complete(conn, ctx, evt, param); + break; + default: + /* Ignore other evts */ + break; + } +} + static void lp_cc_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { switch (ctx->state) { @@ -918,6 +964,9 @@ static void lp_cc_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_ case LP_CC_STATE_WAIT_ESTABLISHED: lp_cc_st_wait_established(conn, ctx, evt, param); break; + case LP_CC_STATE_WAIT_NTF: + lp_cc_st_wait_ntf(conn, ctx, evt, param); + break; default: /* Unknown state */ LL_ASSERT(0); diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_common.c b/subsys/bluetooth/controller/ll_sw/ull_llcp_common.c index a2d95fecd2f0..4bb887e80536 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_common.c +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_common.c @@ -57,7 +57,7 @@ enum { LP_COMMON_STATE_WAIT_TX, LP_COMMON_STATE_WAIT_TX_ACK, LP_COMMON_STATE_WAIT_RX, - LP_COMMON_STATE_WAIT_NTF_AVAIL, + LP_COMMON_STATE_WAIT_NTF, }; /* LLCP Local Procedure Common FSM events */ @@ -88,6 +88,7 @@ enum { RP_COMMON_STATE_POSTPONE_TERMINATE, RP_COMMON_STATE_WAIT_TX, RP_COMMON_STATE_WAIT_TX_ACK, + RP_COMMON_STATE_WAIT_NTF, }; /* LLCP Remote Procedure Common FSM events */ enum { @@ -150,11 +151,6 @@ static void lp_comm_tx(struct ll_conn *conn, struct proc_ctx *ctx) pdu = (struct pdu_data *)tx->pdu; - /* Clear tx_ack/rx node reference due to dual/union functionality - * rx node might be !=NULL and thus tx_ack !=NULL - */ - ctx->node_ref.tx_ack = NULL; - /* Encode LL Control PDU */ switch (ctx->proc) { #if defined(CONFIG_BT_CTLR_LE_PING) @@ -170,7 +166,7 @@ static void lp_comm_tx(struct ll_conn *conn, struct proc_ctx *ctx) #if defined(CONFIG_BT_CTLR_MIN_USED_CHAN) && defined(CONFIG_BT_PERIPHERAL) case PROC_MIN_USED_CHANS: llcp_pdu_encode_min_used_chans_ind(ctx, pdu); - ctx->node_ref.tx_ack = tx; + ctx->tx_ack = tx; ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; break; #endif /* CONFIG_BT_CTLR_MIN_USED_CHAN && CONFIG_BT_PERIPHERAL */ @@ -180,13 +176,13 @@ static void lp_comm_tx(struct ll_conn *conn, struct proc_ctx *ctx) break; case PROC_TERMINATE: llcp_pdu_encode_terminate_ind(ctx, pdu); - ctx->node_ref.tx_ack = tx; + ctx->tx_ack = tx; ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; break; #if defined(CONFIG_BT_CTLR_CENTRAL_ISO) || defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) case PROC_CIS_TERMINATE: llcp_pdu_encode_cis_terminate_ind(ctx, pdu); - ctx->node_ref.tx_ack = tx; + ctx->tx_ack = tx; ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; break; #endif /* CONFIG_BT_CTLR_CENTRAL_ISO || CONFIG_BT_CTLR_PERIPHERAL_ISO */ @@ -303,9 +299,13 @@ static void lp_comm_ntf_cte_req(struct ll_conn *conn, struct proc_ctx *ctx, stru static void lp_comm_ntf_cte_req_tx(struct ll_conn *conn, struct proc_ctx *ctx) { - lp_comm_ntf(conn, ctx); - ull_cp_cte_req_set_disable(conn); - ctx->state = LP_COMMON_STATE_IDLE; + if (llcp_ntf_alloc_is_available()) { + lp_comm_ntf(conn, ctx); + ull_cp_cte_req_set_disable(conn); + ctx->state = LP_COMMON_STATE_IDLE; + } else { + ctx->state = LP_COMMON_STATE_WAIT_NTF; + } } static void lp_comm_complete_cte_req(struct ll_conn *conn, struct proc_ctx *ctx) @@ -376,18 +376,12 @@ static void lp_comm_ntf_sca(struct node_rx_pdu *ntf, struct proc_ctx *ctx, struc static void lp_comm_ntf(struct ll_conn *conn, struct proc_ctx *ctx) { - uint8_t piggy_back = 1U; struct node_rx_pdu *ntf; struct pdu_data *pdu; - ntf = ctx->node_ref.rx; - ctx->node_ref.rx = NULL; - if (!ntf) { - /* Allocate ntf node */ - ntf = llcp_ntf_alloc(); - LL_ASSERT(ntf); - piggy_back = 0U; - } + /* Allocate ntf node */ + ntf = llcp_ntf_alloc(); + LL_ASSERT(ntf); ntf->hdr.type = NODE_RX_TYPE_DC_PDU; ntf->hdr.handle = conn->lll.handle; @@ -420,14 +414,8 @@ static void lp_comm_ntf(struct ll_conn *conn, struct proc_ctx *ctx) break; } - if (!piggy_back) { - /* Enqueue notification towards LL, unless we re-use RX node, - * in which case it is handled on the ull_cp_rx return path - */ - ll_rx_put_sched(ntf->hdr.link, ntf); - } - - + /* Enqueue notification towards LL */ + ll_rx_put_sched(ntf->hdr.link, ntf); } static void lp_comm_terminate_invalid_pdu(struct ll_conn *conn, struct proc_ctx *ctx) @@ -439,6 +427,23 @@ static void lp_comm_terminate_invalid_pdu(struct ll_conn *conn, struct proc_ctx ctx->state = LP_COMMON_STATE_IDLE; } +static void lp_comm_ntf_complete_proxy(struct ll_conn *conn, struct proc_ctx *ctx, + const bool valid_pdu) +{ + if (valid_pdu) { + if (!llcp_ntf_alloc_is_available()) { + ctx->state = LP_COMMON_STATE_WAIT_NTF; + } else { + lp_comm_ntf(conn, ctx); + llcp_lr_complete(conn); + ctx->state = LP_COMMON_STATE_IDLE; + } + } else { + /* Illegal response opcode */ + lp_comm_terminate_invalid_pdu(conn, ctx); + } +} + static void lp_comm_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { switch (ctx->proc) { @@ -455,15 +460,9 @@ static void lp_comm_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t break; #endif /* CONFIG_BT_CTLR_LE_PING */ case PROC_FEATURE_EXCHANGE: - if ((ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_UNKNOWN_RSP || - ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_FEATURE_RSP)) { - lp_comm_ntf(conn, ctx); - llcp_lr_complete(conn); - ctx->state = LP_COMMON_STATE_IDLE; - } else { - /* Illegal response opcode */ - lp_comm_terminate_invalid_pdu(conn, ctx); - } + lp_comm_ntf_complete_proxy(conn, ctx, + (ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_UNKNOWN_RSP || + ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_FEATURE_RSP)); break; #if defined(CONFIG_BT_CTLR_MIN_USED_CHAN) && defined(CONFIG_BT_PERIPHERAL) case PROC_MIN_USED_CHANS: @@ -472,25 +471,8 @@ static void lp_comm_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t break; #endif /* CONFIG_BT_CTLR_MIN_USED_CHAN && CONFIG_BT_PERIPHERAL */ case PROC_VERSION_EXCHANGE: - if (ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_VERSION_IND) { - if (ctx->node_ref.rx || llcp_ntf_alloc_is_available()) { - /* Either this is a piggy-back or there is a NTF node avail */ - lp_comm_ntf(conn, ctx); - llcp_lr_complete(conn); - ctx->state = LP_COMMON_STATE_IDLE; - } else { - /* Handle procedure TO, in case we end up waiting 'forever' for - * NTF buffer. This is a simple way to implement mechanism to - * trigger disconnect in case NTF buffer 'never' becomes avail - * see elaborate note in lp_comm_st_wait_ntf_avail() - */ - llcp_lr_prt_restart(conn); - ctx->state = LP_COMMON_STATE_WAIT_NTF_AVAIL; - } - } else { - /* Illegal response opcode */ - lp_comm_terminate_invalid_pdu(conn, ctx); - } + lp_comm_ntf_complete_proxy(conn, ctx, + (ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_VERSION_IND)); break; case PROC_TERMINATE: /* No notification */ @@ -513,11 +495,16 @@ static void lp_comm_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t /* Apply changes in data lengths/times */ uint8_t dle_changed = ull_dle_update_eff(conn); - if (dle_changed) { - lp_comm_ntf(conn, ctx); + if (dle_changed && !llcp_ntf_alloc_is_available()) { + /* We need to generate NTF but no buffers avail so wait for one */ + ctx->state = LP_COMMON_STATE_WAIT_NTF; + } else { + if (dle_changed) { + lp_comm_ntf(conn, ctx); + } + llcp_lr_complete(conn); + ctx->state = LP_COMMON_STATE_IDLE; } - llcp_lr_complete(conn); - ctx->state = LP_COMMON_STATE_IDLE; } else if (ctx->response_opcode == PDU_DATA_LLCTRL_TYPE_UNKNOWN_RSP) { /* Peer does not accept DLU, so disable on current connection */ feature_unmask_features(conn, LL_FEAT_BIT_DLE); @@ -563,9 +550,13 @@ static void lp_comm_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t #endif /* defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) */ } #endif /* CONFIG_BT_PERIPHERAL */ - lp_comm_ntf(conn, ctx); - llcp_lr_complete(conn); - ctx->state = LP_COMMON_STATE_IDLE; + if (!llcp_ntf_alloc_is_available()) { + ctx->state = LP_COMMON_STATE_WAIT_NTF; + } else { + lp_comm_ntf(conn, ctx); + llcp_lr_complete(conn); + ctx->state = LP_COMMON_STATE_IDLE; + } break; default: /* Illegal response opcode */ @@ -594,8 +585,7 @@ static bool lp_comm_tx_proxy(struct ll_conn *conn, struct proc_ctx *ctx, const b lp_comm_tx(conn, ctx); /* Select correct state, depending on TX ack handling 'request' */ - ctx->state = ctx->node_ref.tx_ack ? - LP_COMMON_STATE_WAIT_TX_ACK : LP_COMMON_STATE_WAIT_RX; + ctx->state = ctx->tx_ack ? LP_COMMON_STATE_WAIT_TX_ACK : LP_COMMON_STATE_WAIT_RX; return true; } return false; @@ -627,8 +617,6 @@ static void lp_comm_send_req(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t } } else { ctx->response_opcode = PDU_DATA_LLCTRL_TYPE_VERSION_IND; - /* Clear node_ref to signal no NTF piggy-backing */ - ctx->node_ref.rx = NULL; lp_comm_complete(conn, ctx, evt, param); } break; @@ -679,7 +667,7 @@ static void lp_comm_send_req(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t 1) { #endif /* CONFIG_BT_CTLR_PHY */ lp_comm_tx_proxy(conn, ctx, - llcp_rr_get_paused_cmd(conn) == PROC_CTE_REQ); + (llcp_rr_get_paused_cmd(conn) == PROC_CTE_REQ)); } else { /* The PHY was changed to CODED when the request was waiting in a local * request queue. @@ -721,7 +709,11 @@ static void lp_comm_st_idle(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t ctx->data.cis_term.error_code); } #endif /* CONFIG_BT_CTLR_CENTRAL_ISO || CONFIG_BT_CTLR_PERIPHERAL_ISO */ - lp_comm_send_req(conn, ctx, evt, param); + if (llcp_lr_ispaused(conn)) { + ctx->state = LP_COMMON_STATE_WAIT_TX; + } else { + lp_comm_send_req(conn, ctx, evt, param); + } break; default: /* Ignore other evts */ @@ -750,14 +742,17 @@ static void lp_comm_st_wait_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, u switch (ctx->proc) { #if defined(CONFIG_BT_CTLR_MIN_USED_CHAN) && defined(CONFIG_BT_PERIPHERAL) case PROC_MIN_USED_CHANS: + ctx->tx_ack = NULL; lp_comm_complete(conn, ctx, evt, param); break; #endif /* CONFIG_BT_CTLR_MIN_USED_CHAN && CONFIG_BT_PERIPHERAL */ case PROC_TERMINATE: + ctx->tx_ack = NULL; lp_comm_complete(conn, ctx, evt, param); break; #if defined(CONFIG_BT_CTLR_CENTRAL_ISO) || defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) case PROC_CIS_TERMINATE: + ctx->tx_ack = NULL; lp_comm_complete(conn, ctx, evt, param); break; #endif /* CONFIG_BT_CTLR_CENTRAL_ISO || CONFIG_BT_CTLR_PERIPHERAL_ISO */ @@ -848,34 +843,36 @@ static void lp_comm_st_wait_rx(struct ll_conn *conn, struct proc_ctx *ctx, uint8 } } -static void lp_comm_st_wait_ntf_avail(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, +static void lp_comm_st_wait_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { switch (evt) { case LP_COMMON_EVT_RUN: switch (ctx->proc) { + case PROC_FEATURE_EXCHANGE: case PROC_VERSION_EXCHANGE: - /* Note re. procedure timeout handling: - * Procedure TO is specifically NOT reset while in wait state, since - * the mechanism is being 'hi-jacked' to implement a TO on the NTF wait - * This to catch the very unlikely case: - * local VERSION IND started after a VERSION IND had already been TX'ed - * in which case the local procedure should complete with NTF without - * prior TX (ie no procedure TO handling initiated). IF this NTF never - * finds buffer avail it would wait forever, but not with proc TO active - */ +#if defined(CONFIG_BT_CTLR_DATA_LENGTH) + case PROC_DATA_LENGTH_UPDATE: +#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ +#if defined(CONFIG_BT_CTLR_SCA_UPDATE) + case PROC_SCA_UPDATE: +#endif /* CONFIG_BT_CTLR_SCA_UPDATE) */ if (llcp_ntf_alloc_is_available()) { lp_comm_ntf(conn, ctx); llcp_lr_complete(conn); ctx->state = LP_COMMON_STATE_IDLE; } break; +#if defined(CONFIG_BT_CTLR_DF_CONN_CTE_REQ) + case PROC_CTE_REQ: + if (llcp_ntf_alloc_is_available()) { + lp_comm_ntf(conn, ctx); + ctx->state = LP_COMMON_STATE_IDLE; + lp_comm_complete_cte_req_finalize(conn); + } + break; +#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */ default: - /* If we get here it is not good since only VERSION EXCHANGE procedure - * out of the ones handled in ull_llcp_common should end up waiting for - * non-piggy-back'ed NTF - */ - LL_ASSERT(0); break; } break; @@ -900,8 +897,8 @@ static void lp_comm_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint case LP_COMMON_STATE_WAIT_RX: lp_comm_st_wait_rx(conn, ctx, evt, param); break; - case LP_COMMON_STATE_WAIT_NTF_AVAIL: - lp_comm_st_wait_ntf_avail(conn, ctx, evt, param); + case LP_COMMON_STATE_WAIT_NTF: + lp_comm_st_wait_ntf(conn, ctx, evt, param); break; default: /* Unknown state */ @@ -1008,9 +1005,6 @@ static void rp_comm_rx_decode(struct ll_conn *conn, struct proc_ctx *ctx, struct */ llcp_tx_pause_data(conn, LLCP_TX_QUEUE_PAUSE_DATA_DATA_LENGTH); ctx->data.dle.ntf_dle = ull_dle_update_eff_rx(conn); - - /* Mark RX pdu to be removed from RX queue, but NOT be released */ - llcp_rx_node_retain(ctx); break; #endif /* CONFIG_BT_CTLR_DATA_LENGTH */ #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RSP) @@ -1040,9 +1034,6 @@ static void rp_comm_tx(struct ll_conn *conn, struct proc_ctx *ctx) pdu = (struct pdu_data *)tx->pdu; - /* Clear tx_ack/rx node reference */ - ctx->node_ref.tx_ack = NULL; - /* Encode LL Control PDU */ switch (ctx->proc) { #if defined(CONFIG_BT_CTLR_LE_PING) @@ -1062,7 +1053,7 @@ static void rp_comm_tx(struct ll_conn *conn, struct proc_ctx *ctx) #if defined(CONFIG_BT_CTLR_DATA_LENGTH) case PROC_DATA_LENGTH_UPDATE: llcp_pdu_encode_length_rsp(conn, pdu); - ctx->node_ref.tx_ack = tx; + ctx->tx_ack = tx; ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; break; #endif /* CONFIG_BT_CTLR_DATA_LENGTH */ @@ -1095,7 +1086,7 @@ static void rp_comm_tx(struct ll_conn *conn, struct proc_ctx *ctx) ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; } - ctx->node_ref.tx_ack = tx; + ctx->tx_ack = tx; break; } @@ -1103,7 +1094,7 @@ static void rp_comm_tx(struct ll_conn *conn, struct proc_ctx *ctx) #if defined(CONFIG_BT_CTLR_SCA_UPDATE) case PROC_SCA_UPDATE: llcp_pdu_encode_clock_accuracy_rsp(ctx, pdu); - ctx->node_ref.tx_ack = tx; + ctx->tx_ack = tx; ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; break; #endif /* CONFIG_BT_CTLR_SCA_UPDATE */ @@ -1133,31 +1124,40 @@ static void rp_comm_st_idle(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t } } #if defined(CONFIG_BT_CTLR_DATA_LENGTH) -static void rp_comm_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t generate_ntf) +static void rp_comm_ntf_length_change(struct ll_conn *conn, struct proc_ctx *ctx, + struct pdu_data *pdu) +{ + llcp_ntf_encode_length_change(conn, pdu); +} + +static void rp_comm_ntf(struct ll_conn *conn, struct proc_ctx *ctx) { struct node_rx_pdu *ntf; struct pdu_data *pdu; ARG_UNUSED(pdu); /* Allocate ntf node */ - ntf = ctx->node_ref.rx; + ntf = llcp_ntf_alloc(); LL_ASSERT(ntf); - /* This should be an 'old' RX node, so put/sched when done */ - LL_ASSERT(ntf->hdr.type == NODE_RX_TYPE_RETAIN); - - /* And release memory if no NTF to be generated */ - ntf->hdr.type = NODE_RX_TYPE_RELEASE; - - if (generate_ntf) { - ntf->hdr.type = NODE_RX_TYPE_DC_PDU; - ntf->hdr.handle = conn->lll.handle; - pdu = (struct pdu_data *)ntf->pdu; - LL_ASSERT(ctx->proc == PROC_DATA_LENGTH_UPDATE); - llcp_ntf_encode_length_change(conn, pdu); + ntf->hdr.type = NODE_RX_TYPE_DC_PDU; + ntf->hdr.handle = conn->lll.handle; + pdu = (struct pdu_data *)ntf->pdu; + switch (ctx->proc) { +/* Note: the 'double' ifdef in case this switch case expands + * in the future and the function is re-instated + */ +#if defined(CONFIG_BT_CTLR_DATA_LENGTH) + case PROC_DATA_LENGTH_UPDATE: + rp_comm_ntf_length_change(conn, ctx, pdu); + break; +#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ + default: + LL_ASSERT(0); + break; } - /* Enqueue notification towards LL - releases mem if no ntf */ + /* Enqueue notification towards LL */ ll_rx_put_sched(ntf->hdr.link, ntf); } #endif /* CONFIG_BT_CTLR_DATA_LENGTH */ @@ -1266,8 +1266,7 @@ static void rp_comm_send_rsp(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t #endif /* CONFIG_BT_CTLR_DATA_LENGTH */ #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RSP) case PROC_CTE_REQ: - if (llcp_rr_ispaused(conn) || - !llcp_tx_alloc_peek(conn, ctx) || + if (llcp_rr_ispaused(conn) || !llcp_tx_alloc_peek(conn, ctx) || (llcp_rr_get_paused_cmd(conn) == PROC_CTE_REQ)) { ctx->state = RP_COMMON_STATE_WAIT_TX; } else { @@ -1345,20 +1344,25 @@ static void rp_comm_st_wait_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, u /* Apply changes in data lengths/times */ uint8_t dle_changed = ull_dle_update_eff_tx(conn); - ctx->node_ref.tx_ack = NULL; dle_changed |= ctx->data.dle.ntf_dle; llcp_tx_resume_data(conn, LLCP_TX_QUEUE_PAUSE_DATA_DATA_LENGTH); - rp_comm_ntf(conn, ctx, dle_changed); - llcp_rr_complete(conn); - ctx->state = RP_COMMON_STATE_IDLE; + if (dle_changed && !llcp_ntf_alloc_is_available()) { + ctx->state = RP_COMMON_STATE_WAIT_NTF; + } else { + if (dle_changed) { + rp_comm_ntf(conn, ctx); + } + llcp_rr_complete(conn); + ctx->state = RP_COMMON_STATE_IDLE; + } break; } #endif /* CONFIG_BT_CTLR_DATA_LENGTH */ #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RSP) case PROC_CTE_REQ: { /* add PHY update pause = false here */ - ctx->node_ref.tx_ack = NULL; + ctx->tx_ack = NULL; llcp_rr_set_paused_cmd(conn, PROC_NONE); llcp_rr_complete(conn); ctx->state = RP_COMMON_STATE_IDLE; @@ -1366,7 +1370,7 @@ static void rp_comm_st_wait_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, u #endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RSP */ #if defined(CONFIG_BT_CTLR_SCA_UPDATE) case PROC_SCA_UPDATE: { - ctx->node_ref.tx_ack = NULL; + ctx->tx_ack = NULL; #if defined(CONFIG_BT_PERIPHERAL) if (conn->lll.role == BT_HCI_ROLE_PERIPHERAL) { conn->periph.sca = ctx->data.sca_update.sca; @@ -1391,6 +1395,18 @@ static void rp_comm_st_wait_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, u } } +#if defined(CONFIG_BT_CTLR_DATA_LENGTH) +static void rp_comm_st_wait_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, + void *param) +{ + if (llcp_ntf_alloc_is_available()) { + rp_comm_ntf(conn, ctx); + llcp_rr_complete(conn); + ctx->state = RP_COMMON_STATE_IDLE; + } +} +#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ + static void rp_comm_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { @@ -1410,6 +1426,11 @@ static void rp_comm_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint case RP_COMMON_STATE_WAIT_TX_ACK: rp_comm_st_wait_tx_ack(conn, ctx, evt, param); break; +#if defined(CONFIG_BT_CTLR_DATA_LENGTH) + case RP_COMMON_STATE_WAIT_NTF: + rp_comm_st_wait_ntf(conn, ctx, evt, param); + break; +#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ default: /* Unknown state */ LL_ASSERT(0); diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_conn_upd.c b/subsys/bluetooth/controller/ll_sw/ull_llcp_conn_upd.c index 1f5de4b34940..a3d037e05372 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_conn_upd.c +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_conn_upd.c @@ -85,7 +85,7 @@ enum { LP_CU_STATE_WAIT_RX_CONN_UPDATE_IND, LP_CU_STATE_WAIT_TX_REJECT_EXT_IND, LP_CU_STATE_WAIT_INSTANT, - LP_CU_STATE_WAIT_NTF_AVAIL, + LP_CU_STATE_WAIT_NTF, }; /* LLCP Local Procedure Connection Update FSM events */ @@ -120,7 +120,7 @@ enum { RP_CU_STATE_WAIT_TX_CONN_UPDATE_IND, RP_CU_STATE_WAIT_RX_CONN_UPDATE_IND, RP_CU_STATE_WAIT_INSTANT, - RP_CU_STATE_WAIT_NTF_AVAIL, + RP_CU_STATE_WAIT_NTF, RP_CU_STATE_WAIT_TX_UNKNOWN_RSP }; @@ -238,15 +238,11 @@ static void cu_ntf(struct ll_conn *conn, struct proc_ctx *ctx) { struct node_rx_pdu *ntf; struct node_rx_cu *pdu; - uint8_t piggy_back; /* Allocate ntf node */ - ntf = ctx->node_ref.rx; - ctx->node_ref.rx = NULL; + ntf = llcp_ntf_alloc(); LL_ASSERT(ntf); - piggy_back = (ntf->hdr.type != NODE_RX_TYPE_RETAIN); - ntf->hdr.type = NODE_RX_TYPE_CONN_UPDATE; ntf->hdr.handle = conn->lll.handle; pdu = (struct node_rx_cu *)ntf->pdu; @@ -262,12 +258,8 @@ static void cu_ntf(struct ll_conn *conn, struct proc_ctx *ctx) pdu->timeout = conn->supervision_timeout; } - if (!piggy_back) { - /* Enqueue notification towards LL, unless piggy-backing, - * in which case this is done on the rx return path - */ - ll_rx_put_sched(ntf->hdr.link, ntf); - } + /* Enqueue notification towards LL */ + ll_rx_put_sched(ntf->hdr.link, ntf); } #if defined(CONFIG_BT_CENTRAL) || defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) @@ -276,16 +268,9 @@ static void lp_cu_tx(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t opcode) struct node_tx *tx; struct pdu_data *pdu; - /* Get pre-allocated tx node */ - tx = ctx->node_ref.tx_ack; - /* Clear to not trigger tx-ack*/ - ctx->node_ref.tx_ack = NULL; - - if (!tx) { - /* Allocate tx node if non pre-alloc'ed */ - tx = llcp_tx_alloc(conn, ctx); - LL_ASSERT(tx); - } + /* Allocate tx node */ + tx = llcp_tx_alloc(conn, ctx); + LL_ASSERT(tx); pdu = (struct pdu_data *)tx->pdu; @@ -338,11 +323,15 @@ static void lp_cu_complete(struct ll_conn *conn, struct proc_ctx *ctx) ctx->state = LP_CU_STATE_IDLE; } -static void lp_cu_ntf_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, +static void lp_cu_wait_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { - cu_ntf(conn, ctx); - lp_cu_complete(conn, ctx); + if (!llcp_ntf_alloc_is_available()) { + ctx->state = LP_CU_STATE_WAIT_NTF; + } else { + cu_ntf(conn, ctx); + lp_cu_complete(conn, ctx); + } } #if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) @@ -400,54 +389,16 @@ static void lp_cu_send_conn_param_req(struct ll_conn *conn, struct proc_ctx *ctx #endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ #if defined(CONFIG_BT_CENTRAL) -static void lp_cu_send_conn_update_ind_finalize(struct ll_conn *conn, struct proc_ctx *ctx, - uint8_t evt, void *param) -{ - if (ctx->node_ref.rx == NULL) { - /* If we get here without RX node we know one is avail to be allocated, - * so pre-alloc NTF node - */ - ctx->node_ref.rx = llcp_ntf_alloc(); - } - - /* Signal put/sched on NTF - ie non-RX node piggy */ - ctx->node_ref.rx->hdr.type = NODE_RX_TYPE_RETAIN; - - cu_prepare_update_ind(conn, ctx); - lp_cu_tx(conn, ctx, PDU_DATA_LLCTRL_TYPE_CONN_UPDATE_IND); - ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; - ctx->state = LP_CU_STATE_WAIT_INSTANT; -} - static void lp_cu_send_conn_update_ind(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { if (llcp_lr_ispaused(conn) || !llcp_tx_alloc_peek(conn, ctx)) { ctx->state = LP_CU_STATE_WAIT_TX_CONN_UPDATE_IND; } else { - /* ensure alloc of TX node, before possibly waiting for NTF node */ - ctx->node_ref.tx_ack = llcp_tx_alloc(conn, ctx); - if (ctx->node_ref.rx == NULL && !llcp_ntf_alloc_is_available()) { - /* No RX node piggy, and no NTF avail, so go wait for one, before TX'ing */ - ctx->state = LP_CU_STATE_WAIT_NTF_AVAIL; - } else { - lp_cu_send_conn_update_ind_finalize(conn, ctx, evt, param); - } - } -} - -static void lp_cu_st_wait_ntf_avail(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, - void *param) -{ - switch (evt) { - case LP_CU_EVT_RUN: - if (llcp_ntf_alloc_is_available()) { - lp_cu_send_conn_update_ind_finalize(conn, ctx, evt, param); - } - break; - default: - /* Ignore other evts */ - break; + cu_prepare_update_ind(conn, ctx); + lp_cu_tx(conn, ctx, PDU_DATA_LLCTRL_TYPE_CONN_UPDATE_IND); + ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; + ctx->state = LP_CU_STATE_WAIT_INSTANT; } } #endif /* CONFIG_BT_CENTRAL */ @@ -464,8 +415,6 @@ static void lp_cu_st_idle(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t ev #endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ #if defined(CONFIG_BT_CENTRAL) case PROC_CONN_UPDATE: - /* Ensure the non-piggy-back'ing is signaled */ - ctx->node_ref.rx = NULL; lp_cu_send_conn_update_ind(conn, ctx, evt, param); break; #endif /* CONFIG_BT_CENTRAL */ @@ -528,16 +477,12 @@ static void lp_cu_st_wait_rx_conn_param_rsp(struct ll_conn *conn, struct proc_ct lp_cu_send_reject_ext_ind(conn, ctx, evt, param); break; } - /* Keep RX node to use for NTF */ - llcp_rx_node_retain(ctx); lp_cu_send_conn_update_ind(conn, ctx, evt, param); break; case LP_CU_EVT_UNKNOWN: llcp_rr_set_incompat(conn, INCOMPAT_RESERVED); /* Unsupported in peer, so disable locally for this connection */ feature_unmask_features(conn, LL_FEAT_BIT_CONN_PARAM_REQ); - /* Keep RX node to use for NTF */ - llcp_rx_node_retain(ctx); lp_cu_send_conn_update_ind(conn, ctx, evt, param); break; case LP_CU_EVT_REJECT: @@ -546,13 +491,11 @@ static void lp_cu_st_wait_rx_conn_param_rsp(struct ll_conn *conn, struct proc_ct llcp_rr_set_incompat(conn, INCOMPAT_RESERVED); /* Unsupported in peer, so disable locally for this connection */ feature_unmask_features(conn, LL_FEAT_BIT_CONN_PARAM_REQ); - /* Keep RX node to use for NTF */ - llcp_rx_node_retain(ctx); lp_cu_send_conn_update_ind(conn, ctx, evt, param); } else { llcp_rr_set_incompat(conn, INCOMPAT_NO_COLLISION); ctx->data.cu.error = pdu->llctrl.reject_ext_ind.error_code; - lp_cu_ntf_complete(conn, ctx, evt, param); + lp_cu_wait_complete(conn, ctx, evt, param); } break; default: @@ -585,19 +528,17 @@ static void lp_cu_st_wait_rx_conn_update_ind(struct ll_conn *conn, struct proc_c switch (evt) { case LP_CU_EVT_CONN_UPDATE_IND: llcp_pdu_decode_conn_update_ind(ctx, param); - /* Keep RX node to use for NTF */ - llcp_rx_node_retain(ctx); ctx->state = LP_CU_STATE_WAIT_INSTANT; break; case LP_CU_EVT_UNKNOWN: /* Unsupported in peer, so disable locally for this connection */ feature_unmask_features(conn, LL_FEAT_BIT_CONN_PARAM_REQ); ctx->data.cu.error = BT_HCI_ERR_UNSUPP_REMOTE_FEATURE; - lp_cu_ntf_complete(conn, ctx, evt, param); + lp_cu_wait_complete(conn, ctx, evt, param); break; case LP_CU_EVT_REJECT: ctx->data.cu.error = pdu->llctrl.reject_ext_ind.error_code; - lp_cu_ntf_complete(conn, ctx, evt, param); + lp_cu_wait_complete(conn, ctx, evt, param); break; default: /* Ignore other evts */ @@ -630,13 +571,8 @@ static void lp_cu_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint notify = cu_should_notify_host(ctx); if (notify) { ctx->data.cu.error = BT_HCI_ERR_SUCCESS; - lp_cu_ntf_complete(conn, ctx, evt, param); + lp_cu_wait_complete(conn, ctx, evt, param); } else { - /* Release RX node kept for NTF */ - ctx->node_ref.rx->hdr.type = NODE_RX_TYPE_RELEASE; - ll_rx_put_sched(ctx->node_ref.rx->hdr.link, ctx->node_ref.rx); - ctx->node_ref.rx = NULL; - lp_cu_complete(conn, ctx); } } @@ -655,6 +591,18 @@ static void lp_cu_st_wait_instant(struct ll_conn *conn, struct proc_ctx *ctx, ui } } +static void lp_cu_st_wait_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) +{ + switch (evt) { + case LP_CU_EVT_RUN: + lp_cu_wait_complete(conn, ctx, evt, param); + break; + default: + /* Ignore other evts */ + break; + } +} + static void lp_cu_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { switch (ctx->state) { @@ -675,9 +623,6 @@ static void lp_cu_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_ case LP_CU_STATE_WAIT_TX_CONN_UPDATE_IND: lp_cu_st_wait_tx_conn_update_ind(conn, ctx, evt, param); break; - case LP_CU_STATE_WAIT_NTF_AVAIL: - lp_cu_st_wait_ntf_avail(conn, ctx, evt, param); - break; #endif /* CONFIG_BT_CENTRAL */ #if defined(CONFIG_BT_PERIPHERAL) case LP_CU_STATE_WAIT_RX_CONN_UPDATE_IND: @@ -692,6 +637,9 @@ static void lp_cu_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_ case LP_CU_STATE_WAIT_INSTANT: lp_cu_st_wait_instant(conn, ctx, evt, param); break; + case LP_CU_STATE_WAIT_NTF: + lp_cu_st_wait_ntf(conn, ctx, evt, param); + break; default: /* Unknown state */ LL_ASSERT(0); @@ -746,15 +694,9 @@ static void rp_cu_tx(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t opcode) struct node_tx *tx; struct pdu_data *pdu; - /* Get pre-allocated tx node */ - tx = ctx->node_ref.tx_ack; - ctx->node_ref.tx_ack = NULL; - - if (!tx) { - /* Allocate tx node if non pre-alloc'ed */ - tx = llcp_tx_alloc(conn, ctx); - LL_ASSERT(tx); - } + /* Allocate tx node */ + tx = llcp_tx_alloc(conn, ctx); + LL_ASSERT(tx); pdu = (struct pdu_data *)tx->pdu; @@ -801,28 +743,19 @@ static void rp_cu_conn_param_req_ntf(struct ll_conn *conn, struct proc_ctx *ctx) { struct node_rx_pdu *ntf; struct pdu_data *pdu; - uint8_t piggy_back; - /* Allocate ntf node */ - ntf = ctx->node_ref.rx; - ctx->node_ref.rx = NULL; + ntf = llcp_ntf_alloc(); LL_ASSERT(ntf); - piggy_back = (ntf->hdr.type != NODE_RX_TYPE_RETAIN); - ntf->hdr.type = NODE_RX_TYPE_DC_PDU; ntf->hdr.handle = conn->lll.handle; pdu = (struct pdu_data *)ntf->pdu; llcp_pdu_encode_conn_param_req(ctx, pdu); - if (!piggy_back) { - /* Enqueue notification towards LL, unless piggy-backing, - * in which case this is done on the rx return path - */ - ll_rx_put_sched(ntf->hdr.link, ntf); - } + /* Enqueue notification towards LL */ + ll_rx_put_sched(ntf->hdr.link, ntf); } #endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ @@ -837,21 +770,15 @@ static void rp_cu_complete(struct ll_conn *conn, struct proc_ctx *ctx) ctx->state = RP_CU_STATE_IDLE; } -static void rp_cu_send_conn_update_ind_finalize(struct ll_conn *conn, struct proc_ctx *ctx, - uint8_t evt, void *param) +static void rp_cu_wait_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, + void *param) { - /* Central role path, should not get here with !=NULL rx-node reference */ - LL_ASSERT(ctx->node_ref.rx == NULL); - /* We pre-alloc NTF node */ - ctx->node_ref.rx = llcp_ntf_alloc(); - - /* Signal put/sched on NTF - ie non-RX node piggy */ - ctx->node_ref.rx->hdr.type = NODE_RX_TYPE_RETAIN; - - cu_prepare_update_ind(conn, ctx); - rp_cu_tx(conn, ctx, PDU_DATA_LLCTRL_TYPE_CONN_UPDATE_IND); - ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; - ctx->state = RP_CU_STATE_WAIT_INSTANT; + if (!llcp_ntf_alloc_is_available()) { + ctx->state = RP_CU_STATE_WAIT_NTF; + } else { + cu_ntf(conn, ctx); + rp_cu_complete(conn, ctx); + } } static void rp_cu_send_conn_update_ind(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, @@ -860,30 +787,10 @@ static void rp_cu_send_conn_update_ind(struct ll_conn *conn, struct proc_ctx *ct if (llcp_rr_ispaused(conn) || !llcp_tx_alloc_peek(conn, ctx)) { ctx->state = RP_CU_STATE_WAIT_TX_CONN_UPDATE_IND; } else { - /* ensure alloc of TX node, before possibly waiting for NTF node */ - ctx->node_ref.tx_ack = llcp_tx_alloc(conn, ctx); - if (!llcp_ntf_alloc_is_available()) { - /* No RX node piggy, and no NTF avail, so go wait for one, before TX'ing */ - ctx->state = RP_CU_STATE_WAIT_NTF_AVAIL; - } else { - rp_cu_send_conn_update_ind_finalize(conn, ctx, evt, param); - } - } -} - -static void rp_cu_st_wait_ntf_avail(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, - void *param) -{ - switch (evt) { - case RP_CU_EVT_RUN: - if (llcp_ntf_alloc_is_available()) { - /* If NTF node is now avail, so pick it up and continue */ - rp_cu_send_conn_update_ind_finalize(conn, ctx, evt, param); - } - break; - default: - /* Ignore other evts */ - break; + cu_prepare_update_ind(conn, ctx); + rp_cu_tx(conn, ctx, PDU_DATA_LLCTRL_TYPE_CONN_UPDATE_IND); + ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; + ctx->state = RP_CU_STATE_WAIT_INSTANT; } } @@ -979,8 +886,6 @@ static void rp_cu_st_wait_conn_param_req_available(struct ll_conn *conn, struct ctx->data.cu.error = BT_HCI_ERR_UNSUPP_LL_PARAM_VAL; rp_cu_send_reject_ext_ind(conn, ctx, evt, param); } - /* In case we have to defer NTF */ - llcp_rx_node_retain(ctx); } else { cpr_active_set(conn); const bool params_changed = @@ -989,8 +894,7 @@ static void rp_cu_st_wait_conn_param_req_available(struct ll_conn *conn, struct /* notify Host if conn parameters changed, else respond */ if (params_changed) { - rp_cu_conn_param_req_ntf(conn, ctx); - ctx->state = RP_CU_STATE_WAIT_CONN_PARAM_REQ_REPLY; + rp_cu_send_conn_param_req_ntf(conn, ctx, evt, param); } else { #if defined(CONFIG_BT_CTLR_USER_CPR_ANCHOR_POINT_MOVE) /* Handle APM as a vendor specific user extension */ @@ -1073,8 +977,6 @@ static void rp_cu_state_wait_conn_param_req_reply_continue(struct ll_conn *conn, switch (evt) { case RP_CU_EVT_RUN: if (conn->lll.role == BT_HCI_ROLE_CENTRAL) { - /* Ensure that node_ref does not indicate RX node for piggyback */ - ctx->node_ref.rx = NULL; rp_cu_send_conn_update_ind(conn, ctx, evt, param); } else if (conn->lll.role == BT_HCI_ROLE_PERIPHERAL) { if (!ctx->data.cu.error) { @@ -1174,14 +1076,10 @@ static void rp_cu_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint notify = cu_should_notify_host(ctx); if (notify) { ctx->data.cu.error = BT_HCI_ERR_SUCCESS; - cu_ntf(conn, ctx); + rp_cu_wait_complete(conn, ctx, evt, param); } else { - /* Release RX node kept for NTF */ - ctx->node_ref.rx->hdr.type = NODE_RX_TYPE_RELEASE; - ll_rx_put_sched(ctx->node_ref.rx->hdr.link, ctx->node_ref.rx); - ctx->node_ref.rx = NULL; + rp_cu_complete(conn, ctx); } - rp_cu_complete(conn, ctx); } } @@ -1201,8 +1099,6 @@ static void rp_cu_st_wait_rx_conn_update_ind(struct ll_conn *conn, struct proc_c if (is_instant_not_passed(ctx->data.cu.instant, ull_conn_event_counter(conn))) { - llcp_rx_node_retain(ctx); - ctx->state = RP_CU_STATE_WAIT_INSTANT; /* In case we only just received it in time */ rp_cu_check_instant(conn, ctx, evt, param); @@ -1235,6 +1131,18 @@ static void rp_cu_st_wait_instant(struct ll_conn *conn, struct proc_ctx *ctx, ui } } +static void rp_cu_st_wait_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) +{ + switch (evt) { + case RP_CU_EVT_RUN: + rp_cu_wait_complete(conn, ctx, evt, param); + break; + default: + /* Ignore other evts */ + break; + } +} + static void rp_cu_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { switch (ctx->state) { @@ -1278,8 +1186,8 @@ static void rp_cu_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_ case RP_CU_STATE_WAIT_INSTANT: rp_cu_st_wait_instant(conn, ctx, evt, param); break; - case RP_CU_STATE_WAIT_NTF_AVAIL: - rp_cu_st_wait_ntf_avail(conn, ctx, evt, param); + case RP_CU_STATE_WAIT_NTF: + rp_cu_st_wait_ntf(conn, ctx, evt, param); break; default: /* Unknown state */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_enc.c b/subsys/bluetooth/controller/ll_sw/ull_llcp_enc.c index 2612cc22d09b..690e63d07a3f 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_enc.c +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_enc.c @@ -59,6 +59,7 @@ enum { LP_ENC_STATE_WAIT_RX_START_ENC_REQ, LP_ENC_STATE_WAIT_TX_START_ENC_RSP, LP_ENC_STATE_WAIT_RX_START_ENC_RSP, + LP_ENC_STATE_WAIT_NTF, /* Pause Procedure */ LP_ENC_STATE_ENCRYPTED, LP_ENC_STATE_WAIT_TX_PAUSE_ENC_REQ, @@ -98,10 +99,12 @@ enum { RP_ENC_STATE_UNENCRYPTED, RP_ENC_STATE_WAIT_RX_ENC_REQ, RP_ENC_STATE_WAIT_TX_ENC_RSP, + RP_ENC_STATE_WAIT_NTF_LTK_REQ, RP_ENC_STATE_WAIT_LTK_REPLY, RP_ENC_STATE_WAIT_TX_START_ENC_REQ, RP_ENC_STATE_WAIT_TX_REJECT_IND, RP_ENC_STATE_WAIT_RX_START_ENC_RSP, + RP_ENC_STATE_WAIT_NTF, RP_ENC_STATE_WAIT_TX_START_ENC_RSP, /* Pause Procedure */ RP_ENC_STATE_ENCRYPTED, @@ -222,8 +225,8 @@ static void lp_enc_ntf(struct ll_conn *conn, struct proc_ctx *ctx) struct node_rx_pdu *ntf; struct pdu_data *pdu; - /* Piggy-back on RX node */ - ntf = ctx->node_ref.rx; + /* Allocate ntf node */ + ntf = llcp_ntf_alloc(); LL_ASSERT(ntf); ntf->hdr.type = NODE_RX_TYPE_DC_PDU; @@ -245,13 +248,20 @@ static void lp_enc_ntf(struct ll_conn *conn, struct proc_ctx *ctx) } else { llcp_pdu_encode_reject_ind(pdu, ctx->data.enc.error); } + + /* Enqueue notification towards LL */ + ll_rx_put_sched(ntf->hdr.link, ntf); } static void lp_enc_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { - lp_enc_ntf(conn, ctx); - llcp_lr_complete(conn); - ctx->state = LP_ENC_STATE_UNENCRYPTED; + if (!llcp_ntf_alloc_is_available()) { + ctx->state = LP_ENC_STATE_WAIT_NTF; + } else { + lp_enc_ntf(conn, ctx); + llcp_lr_complete(conn); + ctx->state = LP_ENC_STATE_UNENCRYPTED; + } } static void lp_enc_store_m(struct ll_conn *conn, struct proc_ctx *ctx, struct pdu_data *pdu) @@ -509,6 +519,18 @@ static void lp_enc_st_wait_rx_start_enc_rsp(struct ll_conn *conn, struct proc_ct } } +static void lp_enc_st_wait_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) +{ + switch (evt) { + case LP_ENC_EVT_RUN: + lp_enc_complete(conn, ctx, evt, param); + break; + default: + /* Ignore other evts */ + break; + } +} + static void lp_enc_state_encrypted(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { @@ -590,6 +612,9 @@ static void lp_enc_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8 case LP_ENC_STATE_WAIT_RX_START_ENC_RSP: lp_enc_st_wait_rx_start_enc_rsp(conn, ctx, evt, param); break; + case LP_ENC_STATE_WAIT_NTF: + lp_enc_st_wait_ntf(conn, ctx, evt, param); + break; /* Pause Procedure */ case LP_ENC_STATE_ENCRYPTED: lp_enc_state_encrypted(conn, ctx, evt, param); @@ -730,26 +755,19 @@ static void rp_enc_ntf_ltk(struct ll_conn *conn, struct proc_ctx *ctx) { struct node_rx_pdu *ntf; struct pdu_data *pdu; - uint8_t piggy_back; - /* Piggy-back on RX node */ - ntf = ctx->node_ref.rx; - ctx->node_ref.rx = NULL; + /* Allocate ntf node */ + ntf = llcp_ntf_alloc(); LL_ASSERT(ntf); - piggy_back = (ntf->hdr.type != NODE_RX_TYPE_RETAIN); - ntf->hdr.type = NODE_RX_TYPE_DC_PDU; ntf->hdr.handle = conn->lll.handle; pdu = (struct pdu_data *)ntf->pdu; llcp_ntf_encode_enc_req(ctx, pdu); - if (!piggy_back) { - /* Enqueue notification towards LL unless it's piggybacked */ - ll_rx_put_sched(ntf->hdr.link, ntf); - } - + /* Enqueue notification towards LL */ + ll_rx_put_sched(ntf->hdr.link, ntf); } static void rp_enc_ntf(struct ll_conn *conn, struct proc_ctx *ctx) @@ -757,9 +775,8 @@ static void rp_enc_ntf(struct ll_conn *conn, struct proc_ctx *ctx) struct node_rx_pdu *ntf; struct pdu_data *pdu; - /* Piggy-back on RX node */ - ntf = ctx->node_ref.rx; - ctx->node_ref.rx = NULL; + /* Allocate ntf node */ + ntf = llcp_ntf_alloc(); LL_ASSERT(ntf); ntf->hdr.type = NODE_RX_TYPE_DC_PDU; @@ -777,6 +794,9 @@ static void rp_enc_ntf(struct ll_conn *conn, struct proc_ctx *ctx) /* Should never happen */ LL_ASSERT(0); } + + /* Enqueue notification towards LL */ + ll_rx_put_sched(ntf->hdr.link, ntf); } static void rp_enc_send_start_enc_rsp(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, @@ -784,8 +804,23 @@ static void rp_enc_send_start_enc_rsp(struct ll_conn *conn, struct proc_ctx *ctx static void rp_enc_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { - rp_enc_ntf(conn, ctx); - rp_enc_send_start_enc_rsp(conn, ctx, evt, param); + if (!llcp_ntf_alloc_is_available()) { + ctx->state = RP_ENC_STATE_WAIT_NTF; + } else { + rp_enc_ntf(conn, ctx); + rp_enc_send_start_enc_rsp(conn, ctx, evt, param); + } +} + +static void rp_enc_send_ltk_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, + void *param) +{ + if (!llcp_ntf_alloc_is_available()) { + ctx->state = RP_ENC_STATE_WAIT_NTF_LTK_REQ; + } else { + rp_enc_ntf_ltk(conn, ctx); + ctx->state = RP_ENC_STATE_WAIT_LTK_REPLY; + } } static void rp_enc_store_s(struct ll_conn *conn, struct proc_ctx *ctx, struct pdu_data *pdu) @@ -805,15 +840,11 @@ static void rp_enc_send_enc_rsp(struct ll_conn *conn, struct proc_ctx *ctx, uint struct node_tx *tx; if (!llcp_tx_alloc_peek(conn, ctx)) { - /* Mark RX node to not release, needed for LTK NTF */ - llcp_rx_node_retain(ctx); ctx->state = RP_ENC_STATE_WAIT_TX_ENC_RSP; } else { tx = llcp_rp_enc_tx(conn, ctx, PDU_DATA_LLCTRL_TYPE_ENC_RSP); rp_enc_store_s(conn, ctx, (struct pdu_data *)tx->pdu); - - rp_enc_ntf_ltk(conn, ctx); - ctx->state = RP_ENC_STATE_WAIT_LTK_REPLY; + rp_enc_send_ltk_ntf(conn, ctx, evt, param); } } @@ -938,7 +969,6 @@ static void rp_enc_state_wait_rx_enc_req(struct ll_conn *conn, struct proc_ctx * llcp_lr_pause(conn); rp_enc_store_m(conn, ctx, param); - rp_enc_send_enc_rsp(conn, ctx, evt, param); break; default: @@ -960,6 +990,19 @@ static void rp_enc_state_wait_tx_enc_rsp(struct ll_conn *conn, struct proc_ctx * } } +static void rp_enc_state_wait_ntf_ltk_req(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, + void *param) +{ + switch (evt) { + case RP_ENC_EVT_RUN: + rp_enc_send_ltk_ntf(conn, ctx, evt, param); + break; + default: + /* Ignore other evts */ + break; + } +} + static void rp_enc_state_wait_ltk_reply(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { @@ -1015,6 +1058,19 @@ static void rp_enc_state_wait_rx_start_enc_rsp(struct ll_conn *conn, struct proc } } +static void rp_enc_state_wait_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, + void *param) +{ + switch (evt) { + case RP_ENC_EVT_RUN: + rp_enc_complete(conn, ctx, evt, param); + break; + default: + /* Ignore other evts */ + break; + } +} + static void rp_enc_state_wait_tx_start_enc_rsp(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { @@ -1106,6 +1162,9 @@ static void rp_enc_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8 case RP_ENC_STATE_WAIT_TX_ENC_RSP: rp_enc_state_wait_tx_enc_rsp(conn, ctx, evt, param); break; + case RP_ENC_STATE_WAIT_NTF_LTK_REQ: + rp_enc_state_wait_ntf_ltk_req(conn, ctx, evt, param); + break; case RP_ENC_STATE_WAIT_LTK_REPLY: rp_enc_state_wait_ltk_reply(conn, ctx, evt, param); break; @@ -1118,6 +1177,9 @@ static void rp_enc_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8 case RP_ENC_STATE_WAIT_RX_START_ENC_RSP: rp_enc_state_wait_rx_start_enc_rsp(conn, ctx, evt, param); break; + case RP_ENC_STATE_WAIT_NTF: + rp_enc_state_wait_ntf(conn, ctx, evt, param); + break; case RP_ENC_STATE_WAIT_TX_START_ENC_RSP: rp_enc_state_wait_tx_start_enc_rsp(conn, ctx, evt, param); break; diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_internal.h b/subsys/bluetooth/controller/ll_sw/ull_llcp_internal.h index a708dd282dfd..f7f7d581b233 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_internal.h +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_internal.h @@ -156,14 +156,9 @@ struct proc_ctx { enum llcp_wait_reason wait_reason; #endif /* LLCP_TX_CTRL_BUF_QUEUE_ENABLE */ - struct { - /* Rx node link element */ - memq_link_t *link; - /* TX node awaiting ack */ - struct node_tx *tx_ack; - /* most recent RX node */ - struct node_rx_pdu *rx; - } node_ref; + /* TX node awaiting ack */ + struct node_tx *tx_ack; + /* * This flag is set to 1 when we are finished with the control * procedure and it is safe to release the context ctx @@ -195,7 +190,6 @@ struct proc_ctx { uint8_t ntf_pu:1; #if defined(CONFIG_BT_CTLR_DATA_LENGTH) uint8_t ntf_dle:1; - struct node_rx_pdu *ntf_dle_node; #endif /* CONFIG_BT_CTLR_DATA_LENGTH */ uint8_t error; uint16_t instant; @@ -402,10 +396,6 @@ bool llcp_tx_alloc_peek(struct ll_conn *conn, struct proc_ctx *ctx); void llcp_tx_alloc_unpeek(struct proc_ctx *ctx); struct node_tx *llcp_tx_alloc(struct ll_conn *conn, struct proc_ctx *ctx); void llcp_proc_ctx_release(struct proc_ctx *ctx); -void llcp_ntf_set_pending(struct ll_conn *conn); -void llcp_ntf_clear_pending(struct ll_conn *conn); -bool llcp_ntf_pending(struct ll_conn *conn); -void llcp_rx_node_retain(struct proc_ctx *ctx); /* * ULL -> LLL Interface @@ -526,8 +516,7 @@ void llcp_lr_pause(struct ll_conn *conn); void llcp_lr_resume(struct ll_conn *conn); void llcp_lr_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, struct node_tx *tx); void llcp_lr_tx_ntf(struct ll_conn *conn, struct proc_ctx *ctx); -void llcp_lr_rx(struct ll_conn *conn, struct proc_ctx *ctx, memq_link_t *link, - struct node_rx_pdu *rx); +void llcp_lr_rx(struct ll_conn *conn, struct proc_ctx *ctx, struct node_rx_pdu *rx); void llcp_lr_enqueue(struct ll_conn *conn, struct proc_ctx *ctx); void llcp_lr_init(struct ll_conn *conn); void llcp_lr_run(struct ll_conn *conn); @@ -550,16 +539,14 @@ void llcp_rr_pause(struct ll_conn *conn); void llcp_rr_resume(struct ll_conn *conn); void llcp_rr_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, struct node_tx *tx); void llcp_rr_tx_ntf(struct ll_conn *conn, struct proc_ctx *ctx); -void llcp_rr_rx(struct ll_conn *conn, struct proc_ctx *ctx, memq_link_t *link, - struct node_rx_pdu *rx); +void llcp_rr_rx(struct ll_conn *conn, struct proc_ctx *ctx, struct node_rx_pdu *rx); void llcp_rr_init(struct ll_conn *conn); void llcp_rr_prepare(struct ll_conn *conn, struct node_rx_pdu *rx); void llcp_rr_run(struct ll_conn *conn); void llcp_rr_complete(struct ll_conn *conn); void llcp_rr_connect(struct ll_conn *conn); void llcp_rr_disconnect(struct ll_conn *conn); -void llcp_rr_new(struct ll_conn *conn, memq_link_t *link, struct node_rx_pdu *rx, - bool valid_pdu); +void llcp_rr_new(struct ll_conn *conn, struct node_rx_pdu *rx, bool valid_pdu); void llcp_rr_check_done(struct ll_conn *conn, struct proc_ctx *ctx); #if defined(CONFIG_BT_CTLR_LE_PING) diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_local.c b/subsys/bluetooth/controller/ll_sw/ull_llcp_local.c index 99c0ecf10c78..8136576cf39d 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_local.c +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_local.c @@ -171,7 +171,7 @@ struct proc_ctx *llcp_lr_peek(struct ll_conn *conn) bool llcp_lr_ispaused(struct ll_conn *conn) { - return (conn->llcp.local.pause == 1U); + return conn->llcp.local.pause == 1U; } void llcp_lr_pause(struct ll_conn *conn) @@ -199,13 +199,8 @@ void llcp_lr_prt_stop(struct ll_conn *conn) conn->llcp.local.prt_expire = 0U; } -void llcp_lr_rx(struct ll_conn *conn, struct proc_ctx *ctx, memq_link_t *link, - struct node_rx_pdu *rx) +void llcp_lr_rx(struct ll_conn *conn, struct proc_ctx *ctx, struct node_rx_pdu *rx) { - /* Store RX node and link */ - ctx->node_ref.rx = rx; - ctx->node_ref.link = link; - switch (ctx->proc) { #if defined(CONFIG_BT_CTLR_LE_PING) case PROC_LE_PING: @@ -310,10 +305,6 @@ void llcp_lr_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, struct node_tx * break; /* Ignore tx_ack */ } - - /* Clear TX node reference */ - ctx->node_ref.tx_ack = NULL; - llcp_lr_check_done(conn, ctx); } diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_phy.c b/subsys/bluetooth/controller/ll_sw/ull_llcp_phy.c index ef59aef9e5e5..ddd42ed36de4 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_phy.c +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_phy.c @@ -57,9 +57,9 @@ enum { LP_PU_STATE_WAIT_TX_PHY_UPDATE_IND, LP_PU_STATE_WAIT_TX_ACK_PHY_UPDATE_IND, LP_PU_STATE_WAIT_RX_PHY_UPDATE_IND, - LP_PU_STATE_WAIT_NTF_AVAIL, LP_PU_STATE_WAIT_INSTANT, LP_PU_STATE_WAIT_INSTANT_ON_AIR, + LP_PU_STATE_WAIT_NTF, }; /* LLCP Local Procedure PHY Update FSM events */ @@ -95,9 +95,9 @@ enum { RP_PU_STATE_WAIT_TX_PHY_UPDATE_IND, RP_PU_STATE_WAIT_TX_ACK_PHY_UPDATE_IND, RP_PU_STATE_WAIT_RX_PHY_UPDATE_IND, - RP_PU_STATE_WAIT_NTF_AVAIL, RP_PU_STATE_WAIT_INSTANT, RP_PU_STATE_WAIT_INSTANT_ON_AIR, + RP_PU_STATE_WAIT_NTF, }; /* LLCP Remote Procedure PHY Update FSM events */ @@ -372,56 +372,38 @@ static void pu_prepare_instant(struct ll_conn *conn, struct proc_ctx *ctx) * LLCP Local Procedure PHY Update FSM */ -static void lp_pu_tx(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) +static void lp_pu_tx(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t opcode) { struct node_tx *tx; struct pdu_data *pdu; - /* Allocate tx node, but only do it if not already done */ - if (ctx->node_ref.tx_ack == NULL) { - ctx->node_ref.tx_ack = llcp_tx_alloc(conn, ctx); - LL_ASSERT(ctx->node_ref.tx_ack); - } - -#if defined(CONFIG_BT_CENTRAL) - if (!((ctx->tx_opcode == PDU_DATA_LLCTRL_TYPE_PHY_REQ) && - (conn->lll.role == BT_HCI_ROLE_CENTRAL))) { - if (!llcp_ntf_alloc_is_available()) { - /* No NTF nodes avail, so we need to hold off TX */ - ctx->state = LP_PU_STATE_WAIT_NTF_AVAIL; - return; - } -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - ctx->data.pu.ntf_dle_node = llcp_ntf_alloc(); - LL_ASSERT(ctx->data.pu.ntf_dle_node); -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - } -#endif + /* Allocate tx node */ + tx = llcp_tx_alloc(conn, ctx); + LL_ASSERT(tx); - tx = ctx->node_ref.tx_ack; pdu = (struct pdu_data *)tx->pdu; /* Encode LL Control PDU */ - switch (ctx->tx_opcode) { + switch (opcode) { case PDU_DATA_LLCTRL_TYPE_PHY_REQ: pu_set_preferred_phys(conn, ctx); llcp_pdu_encode_phy_req(ctx, pdu); - llcp_tx_pause_data(conn, LLCP_TX_QUEUE_PAUSE_DATA_PHY_UPDATE); - ctx->state = LP_PU_STATE_WAIT_TX_ACK_PHY_REQ; break; #if defined(CONFIG_BT_CENTRAL) case PDU_DATA_LLCTRL_TYPE_PHY_UPD_IND: pu_prep_update_ind(conn, ctx); pu_prepare_instant(conn, ctx); llcp_pdu_encode_phy_update_ind(ctx, pdu); - ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; - ctx->state = LP_PU_STATE_WAIT_TX_ACK_PHY_UPDATE_IND; break; #endif /* CONFIG_BT_CENTRAL */ default: LL_ASSERT(0); } + /* Always 'request' the ACK signal */ + ctx->tx_ack = tx; + ctx->tx_opcode = pdu->llctrl.opcode; + /* Enqueue LL Control PDU towards LLL */ llcp_tx_enqueue(conn, tx); @@ -434,33 +416,21 @@ static void pu_ntf(struct ll_conn *conn, struct proc_ctx *ctx) struct node_rx_pdu *ntf; struct node_rx_pu *pdu; - /* Piggy-back on stored RX node */ - ntf = ctx->node_ref.rx; + /* Allocate ntf node */ + ntf = llcp_ntf_alloc(); LL_ASSERT(ntf); - if (ctx->data.pu.ntf_pu) { - LL_ASSERT(ntf->hdr.type == NODE_RX_TYPE_RETAIN); - ntf->hdr.type = NODE_RX_TYPE_PHY_UPDATE; - ntf->hdr.handle = conn->lll.handle; - pdu = (struct node_rx_pu *)ntf->pdu; - - pdu->status = ctx->data.pu.error; - pdu->rx = conn->lll.phy_rx; - pdu->tx = conn->lll.phy_tx; - } else { - ntf->hdr.type = NODE_RX_TYPE_RELEASE; - } + ntf->hdr.type = NODE_RX_TYPE_PHY_UPDATE; + ntf->hdr.handle = conn->lll.handle; + pdu = (struct node_rx_pu *)ntf->pdu; + + pdu->status = ctx->data.pu.error; + pdu->rx = conn->lll.phy_rx; + pdu->tx = conn->lll.phy_tx; /* Enqueue notification towards LL */ -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - /* only 'put' as the 'sched' is handled when handling DLE ntf */ - ll_rx_put(ntf->hdr.link, ntf); -#else ll_rx_put_sched(ntf->hdr.link, ntf); -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - ctx->data.pu.ntf_pu = 0; - ctx->node_ref.rx = NULL; } #if defined(CONFIG_BT_CTLR_DATA_LENGTH) @@ -469,69 +439,82 @@ static void pu_dle_ntf(struct ll_conn *conn, struct proc_ctx *ctx) struct node_rx_pdu *ntf; struct pdu_data *pdu; - /* Retrieve DLE ntf node */ - ntf = ctx->data.pu.ntf_dle_node; - - if (!ctx->data.pu.ntf_dle) { - if (!ntf) { - /* If no DLE ntf was pre-allocated there is nothing more to do */ - /* This will happen in case of a completion on UNKNOWN_RSP to PHY_REQ - * in Central case. - */ - return; - } - /* Signal to release pre-allocated node in case there is no DLE ntf */ - ntf->hdr.type = NODE_RX_TYPE_RELEASE; - } else { - LL_ASSERT(ntf); + /* Allocate ntf node */ + ntf = llcp_ntf_alloc(); + LL_ASSERT(ntf); - ntf->hdr.type = NODE_RX_TYPE_DC_PDU; - ntf->hdr.handle = conn->lll.handle; - pdu = (struct pdu_data *)ntf->pdu; + ntf->hdr.type = NODE_RX_TYPE_DC_PDU; + ntf->hdr.handle = conn->lll.handle; + pdu = (struct pdu_data *)ntf->pdu; - llcp_ntf_encode_length_change(conn, pdu); - } + llcp_ntf_encode_length_change(conn, pdu); /* Enqueue notification towards LL */ ll_rx_put_sched(ntf->hdr.link, ntf); - - ctx->data.pu.ntf_dle = 0; - ctx->data.pu.ntf_dle_node = NULL; } #endif -static void lp_pu_complete_finalize(struct ll_conn *conn, struct proc_ctx *ctx) +static void lp_pu_tx_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt) { - llcp_lr_complete(conn); - llcp_rr_set_paused_cmd(conn, PROC_NONE); - ctx->state = LP_PU_STATE_IDLE; -} +#if defined(CONFIG_BT_CTLR_DATA_LENGTH) +#define NTF_DLE (ctx->data.pu.ntf_dle) +#else +#define NTF_DLE 0 +#endif + uint8_t ntf_count = ctx->data.pu.ntf_pu + NTF_DLE; -static void lp_pu_tx_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) -{ - pu_ntf(conn, ctx); + /* if we need to send both PHY and DLE notification, but we + * do not have 2 buffers available we serialize the sending + * of notifications + */ +#if defined(CONFIG_BT_CTLR_DATA_LENGTH) + if ((ntf_count > 1) && !llcp_ntf_alloc_num_available(ntf_count)) { + ntf_count = 1; + } +#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ + if (ntf_count && !llcp_ntf_alloc_num_available(ntf_count)) { + ctx->state = LP_PU_STATE_WAIT_NTF; + } else { + if (ctx->data.pu.ntf_pu) { + pu_ntf(conn, ctx); +#if defined(CONFIG_BT_CTLR_DATA_LENGTH) + if (ntf_count == 1 && NTF_DLE == 1) { + ctx->state = LP_PU_STATE_WAIT_NTF; + return; + } +#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ + } #if defined(CONFIG_BT_CTLR_DATA_LENGTH) - pu_dle_ntf(conn, ctx); + if (ctx->data.pu.ntf_dle) { + pu_dle_ntf(conn, ctx); + } #endif - lp_pu_complete_finalize(conn, ctx); + llcp_lr_complete(conn); + ctx->state = LP_PU_STATE_IDLE; + llcp_rr_set_paused_cmd(conn, PROC_NONE); + } } -static void lp_pu_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) +static void lp_pu_complete_after_inst_on_air(struct ll_conn *conn, struct proc_ctx *ctx, + uint8_t evt, void *param) { + /* When complete reset timing restrictions - idempotent + * (so no problem if we need to wait for NTF buffer) + */ pu_reset_timing_restrict(conn); - /* Postpone procedure completion (and possible NTF generation) to actual 'air instant' - * Since LLCP STM is driven from LLL prepare this actually happens BEFORE instant - * and thus NTFs are generated and propagated up prior to actual instant on air. - * Instead postpone completion/NTF to the beginning of RX handling - */ + /* Wait for instant on air to send notification */ ctx->state = LP_PU_STATE_WAIT_INSTANT_ON_AIR; +} - if (ctx->node_ref.rx) { - /* Mark RX node to NOT release */ - llcp_rx_node_retain(ctx); - } +static void lp_pu_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) +{ + /* when complete reset timing restrictions - idempotent + * (so no problem if we need to wait for NTF buffer) + */ + pu_reset_timing_restrict(conn); + lp_pu_tx_ntf(conn, ctx, evt); } static void lp_pu_send_phy_req(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) @@ -543,8 +526,9 @@ static void lp_pu_send_phy_req(struct ll_conn *conn, struct proc_ctx *ctx, uint8 } else { llcp_rr_set_incompat(conn, INCOMPAT_RESOLVABLE); llcp_rr_set_paused_cmd(conn, PROC_CTE_REQ); - ctx->tx_opcode = PDU_DATA_LLCTRL_TYPE_PHY_REQ; - lp_pu_tx(conn, ctx, evt, param); + lp_pu_tx(conn, ctx, PDU_DATA_LLCTRL_TYPE_PHY_REQ); + llcp_tx_pause_data(conn, LLCP_TX_QUEUE_PAUSE_DATA_PHY_UPDATE); + ctx->state = LP_PU_STATE_WAIT_TX_ACK_PHY_REQ; } } @@ -555,8 +539,9 @@ static void lp_pu_send_phy_update_ind(struct ll_conn *conn, struct proc_ctx *ctx if (llcp_lr_ispaused(conn) || !llcp_tx_alloc_peek(conn, ctx)) { ctx->state = LP_PU_STATE_WAIT_TX_PHY_UPDATE_IND; } else { - ctx->tx_opcode = PDU_DATA_LLCTRL_TYPE_PHY_UPD_IND; - lp_pu_tx(conn, ctx, evt, param); + lp_pu_tx(conn, ctx, PDU_DATA_LLCTRL_TYPE_PHY_UPD_IND); + ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; + ctx->state = LP_PU_STATE_WAIT_TX_ACK_PHY_UPDATE_IND; } } #endif /* CONFIG_BT_CENTRAL */ @@ -602,10 +587,6 @@ static void lp_pu_st_wait_rx_phy_rsp(struct ll_conn *conn, struct proc_ctx *ctx, llcp_tx_pause_data(conn, LLCP_TX_QUEUE_PAUSE_DATA_PHY_UPDATE); /* Combine with the 'Preferred' phys */ pu_combine_phys(conn, ctx, tx_pref, rx_pref); - - /* Mark RX node to NOT release */ - llcp_rx_node_retain(ctx); - lp_pu_send_phy_update_ind(conn, ctx, evt, param); break; case LP_PU_EVT_UNKNOWN: @@ -614,10 +595,6 @@ static void lp_pu_st_wait_rx_phy_rsp(struct ll_conn *conn, struct proc_ctx *ctx, * Peer does not accept PHY UPDATE, so disable non 1M phys on current connection */ feature_unmask_features(conn, LL_FEAT_BIT_PHY_2M | LL_FEAT_BIT_PHY_CODED); - - /* Mark RX node to NOT release */ - llcp_rx_node_retain(ctx); - ctx->data.pu.error = BT_HCI_ERR_UNSUPP_REMOTE_FEATURE; ctx->data.pu.ntf_pu = 1; lp_pu_complete(conn, ctx, evt, param); @@ -722,9 +699,6 @@ static void lp_pu_st_wait_rx_phy_update_ind(struct ll_conn *conn, struct proc_ct llcp_pdu_decode_phy_update_ind(ctx, (struct pdu_data *)param); const uint8_t end_procedure = pu_check_update_ind(conn, ctx); - /* Mark RX node to NOT release */ - llcp_rx_node_retain(ctx); - if (!end_procedure) { if (ctx->data.pu.p_to_c_phy) { /* If periph to central phy changes apply tx timing restriction */ @@ -751,10 +725,6 @@ static void lp_pu_st_wait_rx_phy_update_ind(struct ll_conn *conn, struct proc_ct case LP_PU_EVT_REJECT: llcp_rr_set_incompat(conn, INCOMPAT_NO_COLLISION); llcp_pdu_decode_reject_ext_ind(ctx, (struct pdu_data *) param); - - /* Mark RX node to NOT release */ - llcp_rx_node_retain(ctx); - ctx->data.pu.error = ctx->reject_ext_ind.error_code; ctx->data.pu.ntf_pu = 1; lp_pu_complete(conn, ctx, evt, param); @@ -766,10 +736,6 @@ static void lp_pu_st_wait_rx_phy_update_ind(struct ll_conn *conn, struct proc_ct * Peer does not accept PHY UPDATE, so disable non 1M phys on current connection */ feature_unmask_features(conn, LL_FEAT_BIT_PHY_2M | LL_FEAT_BIT_PHY_CODED); - - /* Mark RX node to NOT release */ - llcp_rx_node_retain(ctx); - ctx->data.pu.error = BT_HCI_ERR_UNSUPP_REMOTE_FEATURE; ctx->data.pu.ntf_pu = 1; lp_pu_complete(conn, ctx, evt, param); @@ -795,7 +761,7 @@ static void lp_pu_check_instant(struct ll_conn *conn, struct proc_ctx *ctx, uint llcp_rr_set_incompat(conn, INCOMPAT_NO_COLLISION); ctx->data.pu.error = BT_HCI_ERR_SUCCESS; ctx->data.pu.ntf_pu = (phy_changed || ctx->data.pu.host_initiated); - lp_pu_complete(conn, ctx, evt, param); + lp_pu_complete_after_inst_on_air(conn, ctx, evt, param); } } @@ -812,12 +778,11 @@ static void lp_pu_st_wait_instant(struct ll_conn *conn, struct proc_ctx *ctx, ui } } -static void lp_pu_st_wait_instant_on_air(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, - void *param) +static void lp_pu_st_wait_instant_on_air(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt) { switch (evt) { case LP_PU_EVT_NTF: - lp_pu_tx_ntf(conn, ctx, evt, param); + lp_pu_tx_ntf(conn, ctx, evt); break; default: /* Ignore other evts */ @@ -825,12 +790,11 @@ static void lp_pu_st_wait_instant_on_air(struct ll_conn *conn, struct proc_ctx * } } -static void lp_pu_st_wait_ntf_avail(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, - void *param) +static void lp_pu_st_wait_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { switch (evt) { case LP_PU_EVT_RUN: - lp_pu_tx(conn, ctx, evt, param); + lp_pu_tx_ntf(conn, ctx, evt); break; default: /* Ignore other evts */ @@ -870,10 +834,10 @@ static void lp_pu_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_ lp_pu_st_wait_instant(conn, ctx, evt, param); break; case LP_PU_STATE_WAIT_INSTANT_ON_AIR: - lp_pu_st_wait_instant_on_air(conn, ctx, evt, param); + lp_pu_st_wait_instant_on_air(conn, ctx, evt); break; - case LP_PU_STATE_WAIT_NTF_AVAIL: - lp_pu_st_wait_ntf_avail(conn, ctx, evt, param); + case LP_PU_STATE_WAIT_NTF: + lp_pu_st_wait_ntf(conn, ctx, evt, param); break; default: /* Unknown state */ @@ -940,38 +904,22 @@ bool llcp_lp_pu_awaiting_instant(struct proc_ctx *ctx) /* * LLCP Remote Procedure PHY Update FSM */ -static void rp_pu_tx(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) +static void rp_pu_tx(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t opcode) { struct node_tx *tx; struct pdu_data *pdu; - /* (pre)allocate tx node, but only do it if not already done */ - if (ctx->node_ref.tx_ack == NULL) { - ctx->node_ref.tx_ack = llcp_tx_alloc(conn, ctx); - LL_ASSERT(ctx->node_ref.tx_ack); - } - - if (!llcp_ntf_alloc_is_available()) { - /* No NTF nodes avail, so we need to hold off TX */ - ctx->state = RP_PU_STATE_WAIT_NTF_AVAIL; - return; - } - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - ctx->data.pu.ntf_dle_node = llcp_ntf_alloc(); - LL_ASSERT(ctx->data.pu.ntf_dle_node); -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ + /* Allocate tx node */ + tx = llcp_tx_alloc(conn, ctx); + LL_ASSERT(tx); - tx = ctx->node_ref.tx_ack; pdu = (struct pdu_data *)tx->pdu; /* Encode LL Control PDU */ - switch (ctx->tx_opcode) { + switch (opcode) { #if defined(CONFIG_BT_PERIPHERAL) case PDU_DATA_LLCTRL_TYPE_PHY_RSP: llcp_pdu_encode_phy_rsp(conn, pdu); - ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_PHY_UPD_IND; - ctx->state = RP_PU_STATE_WAIT_TX_ACK_PHY_RSP; break; #endif /* CONFIG_BT_PERIPHERAL */ #if defined(CONFIG_BT_CENTRAL) @@ -979,14 +927,15 @@ static void rp_pu_tx(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, vo pu_prep_update_ind(conn, ctx); pu_prepare_instant(conn, ctx); llcp_pdu_encode_phy_update_ind(ctx, pdu); - ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; - ctx->state = RP_PU_STATE_WAIT_TX_ACK_PHY_UPDATE_IND; break; #endif /* CONFIG_BT_CENTRAL */ default: LL_ASSERT(0); } + ctx->tx_ack = tx; + ctx->tx_opcode = pdu->llctrl.opcode; + /* Enqueue LL Control PDU towards LLL */ llcp_tx_enqueue(conn, tx); @@ -996,29 +945,65 @@ static void rp_pu_tx(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, vo static void rp_pu_complete_finalize(struct ll_conn *conn, struct proc_ctx *ctx) { - llcp_rr_complete(conn); llcp_rr_set_paused_cmd(conn, PROC_NONE); + llcp_rr_complete(conn); ctx->state = RP_PU_STATE_IDLE; } static void rp_pu_complete(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { - pu_reset_timing_restrict(conn); - /* Postpone procedure completion (and possible NTF generation) to actual 'air instant' - * Since LLCP STM is driven from LLL prepare this actually happens BEFORE instant - * and thus NTFs are generated and propagated up prior to actual instant on air. - * Instead postpone completion/NTF to the beginning of RX handling + /* when complete reset timing restrictions - idempotent + * (so no problem if we need to wait for NTF buffer) */ - ctx->state = RP_PU_STATE_WAIT_INSTANT_ON_AIR; + pu_reset_timing_restrict(conn); + + /* For remote initiated PHY update Host is notified only if a PHY changes */ + if (ctx->data.pu.ntf_pu) { + /* Notification may be send after instant is on air */ + ctx->state = RP_PU_STATE_WAIT_INSTANT_ON_AIR; + } else { + rp_pu_complete_finalize(conn, ctx); + } } -static void rp_pu_tx_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) +void rp_pu_tx_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { - pu_ntf(conn, ctx); + +#if defined(CONFIG_BT_CTLR_DATA_LENGTH) +#define NTF_DLE (ctx->data.pu.ntf_dle) +#else +#define NTF_DLE 0 +#endif + uint8_t ntf_count = ctx->data.pu.ntf_pu + NTF_DLE; + + /* if we need to send both PHY and DLE notification, but we + * do not have 2 buffers available we serialize the sending + * of notifications + */ +#if defined(CONFIG_BT_CTLR_DATA_LENGTH) + if ((ntf_count > 1) && !llcp_ntf_alloc_num_available(ntf_count)) { + ntf_count = 1; + } +#endif /* CONFIG_BT_CTLR_DATA_LENGTH) */ + if ((ntf_count > 0) && !llcp_ntf_alloc_num_available(ntf_count)) { + ctx->state = RP_PU_STATE_WAIT_NTF; + } else { + if (ctx->data.pu.ntf_pu) { + pu_ntf(conn, ctx); #if defined(CONFIG_BT_CTLR_DATA_LENGTH) - pu_dle_ntf(conn, ctx); + if (ntf_count == 1 && NTF_DLE == 1) { + ctx->state = RP_PU_STATE_WAIT_NTF; + return; + } +#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ + } +#if defined(CONFIG_BT_CTLR_DATA_LENGTH) + if (ctx->data.pu.ntf_dle) { + pu_dle_ntf(conn, ctx); + } #endif - rp_pu_complete_finalize(conn, ctx); + rp_pu_complete_finalize(conn, ctx); + } } #if defined(CONFIG_BT_CENTRAL) @@ -1026,14 +1011,15 @@ static void rp_pu_send_phy_update_ind(struct ll_conn *conn, struct proc_ctx *ctx void *param) { if (llcp_rr_ispaused(conn) || !llcp_tx_alloc_peek(conn, ctx) || - (llcp_rr_get_paused_cmd(conn) == PROC_PHY_UPDATE) || + (llcp_rr_get_paused_cmd(conn) == PROC_PHY_UPDATE) || !ull_is_lll_tx_queue_empty(conn)) { ctx->state = RP_PU_STATE_WAIT_TX_PHY_UPDATE_IND; } else { llcp_rr_set_paused_cmd(conn, PROC_CTE_REQ); - ctx->tx_opcode = PDU_DATA_LLCTRL_TYPE_PHY_UPD_IND; - rp_pu_tx(conn, ctx, evt, param); + rp_pu_tx(conn, ctx, PDU_DATA_LLCTRL_TYPE_PHY_UPD_IND); + ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_UNUSED; + ctx->state = RP_PU_STATE_WAIT_TX_ACK_PHY_UPDATE_IND; } } #endif /* CONFIG_BT_CENTRAL */ @@ -1046,8 +1032,9 @@ static void rp_pu_send_phy_rsp(struct ll_conn *conn, struct proc_ctx *ctx, uint8 ctx->state = RP_PU_STATE_WAIT_TX_PHY_RSP; } else { llcp_rr_set_paused_cmd(conn, PROC_CTE_REQ); - ctx->tx_opcode = PDU_DATA_LLCTRL_TYPE_PHY_RSP; - rp_pu_tx(conn, ctx, evt, param); + rp_pu_tx(conn, ctx, PDU_DATA_LLCTRL_TYPE_PHY_RSP); + ctx->rx_opcode = PDU_DATA_LLCTRL_TYPE_PHY_UPD_IND; + ctx->state = RP_PU_STATE_WAIT_TX_ACK_PHY_RSP; } } #endif /* CONFIG_BT_CENTRAL */ @@ -1077,8 +1064,6 @@ static void rp_pu_st_wait_rx_phy_req(struct ll_conn *conn, struct proc_ctx *ctx, switch (conn->lll.role) { #if defined(CONFIG_BT_CENTRAL) case BT_HCI_ROLE_CENTRAL: - /* Mark RX node to NOT release */ - llcp_rx_node_retain(ctx); rp_pu_send_phy_update_ind(conn, ctx, evt, param); break; #endif /* CONFIG_BT_CENTRAL */ @@ -1180,14 +1165,12 @@ static void rp_pu_st_wait_rx_phy_update_ind(struct ll_conn *conn, struct proc_ct llcp_pdu_decode_phy_update_ind(ctx, (struct pdu_data *)param); const uint8_t end_procedure = pu_check_update_ind(conn, ctx); - /* Mark RX node to NOT release */ - llcp_rx_node_retain(ctx); - if (!end_procedure) { /* Since at least one phy will change, * stop the procedure response timeout */ llcp_rr_prt_stop(conn); + ctx->state = RP_PU_STATE_WAIT_INSTANT; } else { if (ctx->data.pu.error == BT_HCI_ERR_INSTANT_PASSED) { @@ -1247,12 +1230,11 @@ static void rp_pu_st_wait_instant_on_air(struct ll_conn *conn, struct proc_ctx * } } -static void rp_pu_st_wait_ntf_avail(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, - void *param) +static void rp_pu_st_wait_ntf(struct ll_conn *conn, struct proc_ctx *ctx, uint8_t evt, void *param) { switch (evt) { case RP_PU_EVT_RUN: - rp_pu_tx(conn, ctx, evt, param); + rp_pu_tx_ntf(conn, ctx, evt, param); break; default: /* Ignore other evts */ @@ -1294,8 +1276,8 @@ static void rp_pu_execute_fsm(struct ll_conn *conn, struct proc_ctx *ctx, uint8_ case RP_PU_STATE_WAIT_INSTANT_ON_AIR: rp_pu_st_wait_instant_on_air(conn, ctx, evt, param); break; - case RP_PU_STATE_WAIT_NTF_AVAIL: - rp_pu_st_wait_ntf_avail(conn, ctx, evt, param); + case RP_PU_STATE_WAIT_NTF: + rp_pu_st_wait_ntf(conn, ctx, evt, param); break; default: /* Unknown state */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_llcp_remote.c b/subsys/bluetooth/controller/ll_sw/ull_llcp_remote.c index b36981d7c4b1..f3e05e8423d7 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_llcp_remote.c +++ b/subsys/bluetooth/controller/ll_sw/ull_llcp_remote.c @@ -190,7 +190,7 @@ struct proc_ctx *llcp_rr_peek(struct ll_conn *conn) bool llcp_rr_ispaused(struct ll_conn *conn) { - return (conn->llcp.remote.pause == 1U); + return conn->llcp.remote.pause == 1U; } void llcp_rr_pause(struct ll_conn *conn) @@ -213,13 +213,8 @@ void llcp_rr_prt_stop(struct ll_conn *conn) conn->llcp.remote.prt_expire = 0U; } -void llcp_rr_rx(struct ll_conn *conn, struct proc_ctx *ctx, memq_link_t *link, - struct node_rx_pdu *rx) +void llcp_rr_rx(struct ll_conn *conn, struct proc_ctx *ctx, struct node_rx_pdu *rx) { - /* Store RX node and link */ - ctx->node_ref.rx = rx; - ctx->node_ref.link = link; - switch (ctx->proc) { case PROC_UNKNOWN: /* Do nothing */ @@ -324,15 +319,17 @@ void llcp_rr_tx_ack(struct ll_conn *conn, struct proc_ctx *ctx, struct node_tx * break; } - /* Clear TX node reference */ - ctx->node_ref.tx_ack = NULL; - llcp_rr_check_done(conn, ctx); } void llcp_rr_tx_ntf(struct ll_conn *conn, struct proc_ctx *ctx) { switch (ctx->proc) { +#if defined(CONFIG_BT_CTLR_DATA_LENGTH) + case PROC_DATA_LENGTH_UPDATE: + /* llcp_rp_comm_tx_ntf(conn, ctx); */ + break; +#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ #ifdef CONFIG_BT_CTLR_PHY case PROC_PHY_UPDATE: llcp_rp_pu_tx_ntf(conn, ctx); @@ -862,7 +859,7 @@ static const struct proc_role new_proc_lut[] = { #endif /* CONFIG_BT_CTLR_SCA_UPDATE */ }; -void llcp_rr_new(struct ll_conn *conn, memq_link_t *link, struct node_rx_pdu *rx, bool valid_pdu) +void llcp_rr_new(struct ll_conn *conn, struct node_rx_pdu *rx, bool valid_pdu) { struct proc_ctx *ctx; struct pdu_data *pdu; @@ -901,7 +898,7 @@ void llcp_rr_new(struct ll_conn *conn, memq_link_t *link, struct node_rx_pdu *rx /* Handle PDU */ ctx = llcp_rr_peek(conn); if (ctx) { - llcp_rr_rx(conn, ctx, link, rx); + llcp_rr_rx(conn, ctx, rx); } } diff --git a/tests/bluetooth/controller/common/include/helper_util.h b/tests/bluetooth/controller/common/include/helper_util.h index 1b1d8f200616..a2492c0fdcb5 100644 --- a/tests/bluetooth/controller/common/include/helper_util.h +++ b/tests/bluetooth/controller/common/include/helper_util.h @@ -42,5 +42,4 @@ void ut_rx_node_real(const char *file, uint32_t line, enum helper_node_opcode op struct node_rx_pdu **ntf_ref, void *param); void ut_rx_q_is_empty_real(const char *file, uint32_t line); -void release_ntf(struct node_rx_pdu *ntf); void encode_pdu(enum helper_pdu_opcode opcode, struct pdu_data *pdu, void *param); diff --git a/tests/bluetooth/controller/common/src/helper_util.c b/tests/bluetooth/controller/common/src/helper_util.c index ae9012a507ae..ea72fabf60eb 100644 --- a/tests/bluetooth/controller/common/src/helper_util.c +++ b/tests/bluetooth/controller/common/src/helper_util.c @@ -40,7 +40,6 @@ #include "ull_conn_iso_internal.h" #include "ull_conn_types.h" -#include "ull_internal.h" #include "ull_conn_internal.h" #include "ull_llcp_internal.h" #include "ull_llcp.h" @@ -355,25 +354,14 @@ void event_done(struct ll_conn *conn) zassert_equal(*evt_active, 1, "Called outside an active event"); *evt_active = 0; - /* Notify all control procedures that wait with Host notifications for instant to be on + /* Notify all conotrol procedures that wait with Host notifications for instant to be on * air. This is done here because UT does not maintain actual connection events. */ ull_cp_tx_ntf(conn); while ((rx = (struct node_rx_pdu *)sys_slist_get(<_tx_q))) { - - /* Mark buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - ull_cp_rx(conn, NULL, rx); - - if (rx->hdr.type == NODE_RX_TYPE_RELEASE) { - /* Only release if node was not hi-jacked by LLCP */ - ll_rx_release(rx); - } else if (rx->hdr.type != NODE_RX_TYPE_RETAIN) { - /* Otherwise put/sched to emulate ull_cp_rx return path */ - ll_rx_put_sched(rx->hdr.link, rx); - } + ull_cp_rx(conn, rx); + free(rx); } } @@ -395,8 +383,6 @@ uint16_t event_counter(struct ll_conn *conn) return event_counter; } -static struct node_rx_pdu *rx_malloc_store; - void lt_tx_real(const char *file, uint32_t line, enum helper_pdu_opcode opcode, struct ll_conn *conn, void *param) { @@ -406,9 +392,6 @@ void lt_tx_real(const char *file, uint32_t line, enum helper_pdu_opcode opcode, rx = malloc(PDU_RX_NODE_SIZE); zassert_not_null(rx, "Out of memory.\nCalled at %s:%d\n", file, line); - /* Remember RX node to allow for correct release */ - rx_malloc_store = rx; - /* Encode node_rx_pdu if required by particular procedure */ if (helper_node_encode[opcode]) { helper_node_encode[opcode](rx, param); @@ -428,25 +411,10 @@ void lt_tx_real_no_encode(const char *file, uint32_t line, struct pdu_data *pdu, rx = malloc(PDU_RX_NODE_SIZE); zassert_not_null(rx, "Out of memory.\nCalled at %s:%d\n", file, line); - - /* Remember RX node to allow for correct release */ - rx_malloc_store = rx; - memcpy((struct pdu_data *)rx->pdu, pdu, sizeof(struct pdu_data)); sys_slist_append(<_tx_q, (sys_snode_t *)rx); } -void release_ntf(struct node_rx_pdu *ntf) -{ - if (ntf == rx_malloc_store) { - free(ntf); - return; - } - - ntf->hdr.next = NULL; - ll_rx_mem_release((void **)&ntf); -} - void lt_rx_real(const char *file, uint32_t line, enum helper_pdu_opcode opcode, struct ll_conn *conn, struct node_tx **tx_ref, void *param) { diff --git a/tests/bluetooth/controller/ctrl_cis_create/src/main.c b/tests/bluetooth/controller/ctrl_cis_create/src/main.c index 93388f4d3c4e..e9f5d78facc4 100644 --- a/tests/bluetooth/controller/ctrl_cis_create/src/main.c +++ b/tests/bluetooth/controller/ctrl_cis_create/src/main.c @@ -153,7 +153,7 @@ ZTEST(cis_create, test_cc_create_periph_rem_host_accept) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Accept request */ ull_cp_cc_accept(&conn); @@ -195,15 +195,7 @@ ZTEST(cis_create, test_cc_create_periph_rem_host_accept) ut_rx_q_is_empty(); } - /* Prepare */ - event_prepare(&conn); - - /* Done */ - event_done(&conn); - /* Emulate CIS becoming established */ - ull_cp_cc_established(&conn, 0); - /* Prepare */ event_prepare(&conn); @@ -281,9 +273,6 @@ ZTEST(cis_create, test_cc_create_periph_rem_host_reject) ut_rx_node(NODE_CIS_REQUEST, &ntf, &cis_req); ut_rx_q_is_empty(); - /* Release Ntf */ - release_ntf(ntf); - /* Decline request */ ull_cp_cc_reject(&conn, ERROR_CODE); @@ -338,10 +327,6 @@ ZTEST(cis_create, test_cc_create_periph_rem_host_accept_to) .error_code = BT_HCI_ERR_CONN_ACCEPT_TIMEOUT, .reject_opcode = PDU_DATA_LLCTRL_TYPE_CIS_REQ }; - struct node_rx_conn_iso_estab cis_estab = { - .cis_handle = 0x00, - .status = BT_HCI_ERR_CONN_ACCEPT_TIMEOUT - }; /* Role */ test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL); @@ -362,9 +347,6 @@ ZTEST(cis_create, test_cc_create_periph_rem_host_accept_to) ut_rx_node(NODE_CIS_REQUEST, &ntf, &cis_req); ut_rx_q_is_empty(); - /* Release Ntf */ - release_ntf(ntf); - /* Emulate that time passes real fast re. timeout */ conn.connect_accept_to = 0; @@ -384,13 +366,6 @@ ZTEST(cis_create, test_cc_create_periph_rem_host_accept_to) /* Done */ event_done(&conn); - /* There should be excactly one host notification */ - ut_rx_node(NODE_CIS_ESTABLISHED, &ntf, &cis_estab); - ut_rx_q_is_empty(); - - /* Release Ntf */ - release_ntf(ntf); - zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } diff --git a/tests/bluetooth/controller/ctrl_collision/src/main.c b/tests/bluetooth/controller/ctrl_collision/src/main.c index 3c0224eba39d..82cdf64429ba 100644 --- a/tests/bluetooth/controller/ctrl_collision/src/main.c +++ b/tests/bluetooth/controller/ctrl_collision/src/main.c @@ -309,7 +309,7 @@ ZTEST(collision, test_phy_update_central_loc_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -430,7 +430,7 @@ ZTEST(collision, test_phy_update_central_rem_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Prepare */ event_prepare(&conn); @@ -481,7 +481,7 @@ ZTEST(collision, test_phy_update_central_rem_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -551,19 +551,13 @@ ZTEST(collision, test_phy_update_periph_loc_collision) /* Done */ event_done(&conn); - /* Prepare */ - event_prepare(&conn); - - /* Done */ - event_done(&conn); - /* There should be one host notification */ pu.status = BT_HCI_ERR_LL_PROC_COLLISION; ut_rx_node(NODE_PHY_UPDATE, &ntf, &pu); ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Prepare */ event_prepare(&conn); @@ -611,7 +605,7 @@ ZTEST(collision, test_phy_update_periph_loc_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -750,7 +744,7 @@ ZTEST(collision, test_phy_conn_update_central_loc_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } diff --git a/tests/bluetooth/controller/ctrl_conn_update/src/main.c b/tests/bluetooth/controller/ctrl_conn_update/src/main.c index 397652582e6a..7da7a69c1f7a 100644 --- a/tests/bluetooth/controller/ctrl_conn_update/src/main.c +++ b/tests/bluetooth/controller/ctrl_conn_update/src/main.c @@ -323,7 +323,7 @@ ZTEST(central_loc, test_conn_update_central_loc_accept) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -581,7 +581,7 @@ ZTEST(central_loc, test_conn_update_central_loc_accept_reject_2nd_cpr) ull_cp_release_tx(&conn_3rd, tx); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* One less CTXs as the conn_3rd CPR is still 'running' */ zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt()-1, @@ -794,7 +794,7 @@ ZTEST(central_loc, test_conn_update_central_loc_reject) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -919,7 +919,7 @@ ZTEST(central_loc, test_conn_update_central_loc_remote_legacy) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -1044,7 +1044,7 @@ ZTEST(central_loc, test_conn_update_central_loc_unsupp_wo_feat_exch) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -1140,7 +1140,7 @@ ZTEST(central_loc, test_conn_update_central_loc_unsupp_w_feat_exch) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -1307,7 +1307,7 @@ ZTEST(central_loc, test_conn_update_central_loc_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -1372,7 +1372,7 @@ ZTEST(central_rem, test_conn_update_central_rem_accept) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /*******************/ @@ -1427,7 +1427,7 @@ ZTEST(central_rem, test_conn_update_central_rem_accept) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -1544,7 +1544,7 @@ ZTEST(central_rem, test_conn_update_central_rem_reject) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /*******************/ @@ -1683,7 +1683,7 @@ ZTEST(central_rem, test_conn_update_central_rem_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /*******************/ @@ -1744,7 +1744,7 @@ ZTEST(central_rem, test_conn_update_central_rem_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Prepare */ event_prepare(&conn); @@ -1802,7 +1802,7 @@ ZTEST(central_rem, test_conn_update_central_rem_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -1906,7 +1906,7 @@ ZTEST(periph_loc, test_conn_update_periph_loc_accept) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -1986,7 +1986,7 @@ ZTEST(periph_loc, test_conn_update_periph_loc_reject) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -2066,7 +2066,7 @@ ZTEST(periph_loc, test_conn_update_periph_loc_unsupp_feat_wo_feat_exch) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -2234,7 +2234,7 @@ ZTEST(periph_loc, test_conn_update_periph_loc_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /*******************/ @@ -2262,7 +2262,7 @@ ZTEST(periph_loc, test_conn_update_periph_loc_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Prepare */ event_prepare(&conn); @@ -2306,7 +2306,7 @@ ZTEST(periph_loc, test_conn_update_periph_loc_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -2376,7 +2376,7 @@ ZTEST(periph_rem, test_conn_update_periph_rem_accept) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /*******************/ @@ -2437,7 +2437,7 @@ ZTEST(periph_rem, test_conn_update_periph_rem_accept) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -3213,7 +3213,7 @@ ZTEST(periph_loc, test_conn_update_periph_loc_collision_reject_2nd_cpr) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /*******************/ @@ -3241,7 +3241,7 @@ ZTEST(periph_loc, test_conn_update_periph_loc_collision_reject_2nd_cpr) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); { /* Initiate a parallel local Connection Parameter Request Procedure */ @@ -3326,7 +3326,7 @@ ZTEST(periph_loc, test_conn_update_periph_loc_collision_reject_2nd_cpr) } /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* One less CTXs as the conn_2nd CPR is still 'running' */ zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt()-1, @@ -3487,7 +3487,7 @@ ZTEST(periph_rem, test_conn_update_periph_rem_accept_reject_2nd_cpr) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /*******************/ @@ -3587,7 +3587,7 @@ ZTEST(periph_rem, test_conn_update_periph_rem_accept_reject_2nd_cpr) } /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* One less CTXs as the conn_2nd CPR is still 'running' */ zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt()-1, @@ -3720,7 +3720,7 @@ ZTEST(periph_rem, test_conn_update_periph_rem_invalid_ind) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /*******************/ @@ -3781,7 +3781,7 @@ ZTEST(periph_rem, test_conn_update_periph_rem_invalid_ind) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /*******************/ @@ -3843,7 +3843,7 @@ ZTEST(periph_rem, test_conn_update_periph_rem_invalid_ind) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /*******************/ @@ -3942,7 +3942,7 @@ ZTEST(periph_rem, test_conn_update_periph_rem_reject) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /*******************/ @@ -4081,7 +4081,7 @@ ZTEST(periph_rem, test_conn_update_periph_rem_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /*******************/ @@ -4146,7 +4146,7 @@ ZTEST(periph_rem, test_conn_update_periph_rem_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Prepare */ event_prepare(&conn); @@ -4190,7 +4190,7 @@ ZTEST(periph_rem, test_conn_update_periph_rem_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); } @@ -4296,7 +4296,7 @@ ZTEST(central_loc_no_param_req, test_conn_update_central_loc_accept_no_param_req ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); } } while (parameters_changed-- > 0U); @@ -4539,7 +4539,7 @@ ZTEST(periph_rem_no_param_req, test_conn_update_periph_rem_accept_no_param_req) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); } } while (parameters_changed-- > 0U); diff --git a/tests/bluetooth/controller/ctrl_cte_req/src/main.c b/tests/bluetooth/controller/ctrl_cte_req/src/main.c index d841c5a1bafb..949f1d783212 100644 --- a/tests/bluetooth/controller/ctrl_cte_req/src/main.c +++ b/tests/bluetooth/controller/ctrl_cte_req/src/main.c @@ -133,7 +133,7 @@ ZTEST(cte_req_after_fex, test_cte_req_central_local) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Release tx node */ ull_cp_release_tx(&conn, tx); @@ -208,7 +208,7 @@ ZTEST(cte_req_after_fex, test_cte_req_peripheral_local) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Release tx node */ ull_cp_release_tx(&conn, tx); @@ -427,7 +427,7 @@ ZTEST(cte_req_after_fex, test_cte_req_rejected_inv_ll_param_central_local) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Release tx node */ ull_cp_release_tx(&conn, tx); @@ -506,7 +506,7 @@ ZTEST(cte_req_after_fex, test_cte_req_rejected_inv_ll_param_peripheral_local) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Release tx node */ ull_cp_release_tx(&conn, tx); @@ -726,7 +726,7 @@ static void test_cte_req_ll_unknown_rsp_local(uint8_t role) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Release tx node */ ull_cp_release_tx(&conn, tx); @@ -861,7 +861,7 @@ static void run_local_cte_req(struct pdu_data_llctrl_cte_req *cte_req) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Release tx node */ ull_cp_release_tx(&conn, tx); @@ -918,7 +918,7 @@ static void check_phy_update(bool is_local, struct pdu_data_llctrl_phy_req *phy_ } /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* The RX queue should be empty now */ ut_rx_q_is_empty(); diff --git a/tests/bluetooth/controller/ctrl_data_length_update/src/main.c b/tests/bluetooth/controller/ctrl_data_length_update/src/main.c index b7b0a8ee67ae..76e9047f408a 100644 --- a/tests/bluetooth/controller/ctrl_data_length_update/src/main.c +++ b/tests/bluetooth/controller/ctrl_data_length_update/src/main.c @@ -97,6 +97,13 @@ ZTEST(dle_central, test_data_length_update_central_loc) ull_conn_default_tx_time_set(2120); ull_dle_init(&conn, PHY_1M); + /* Steal all ntf buffers, so as to check that the wait_ntf mechanism works */ + while (ll_pdu_rx_alloc_peek(1)) { + ntf = ll_pdu_rx_alloc(); + /* Make sure we use a correct type or the release won't work */ + ntf->hdr.type = NODE_RX_TYPE_DC_PDU; + } + /* Initiate a Data Length Update Procedure */ err = ull_cp_data_length_update(&conn, 211, 1800); zassert_equal(err, BT_HCI_ERR_SUCCESS); @@ -114,14 +121,19 @@ ZTEST(dle_central, test_data_length_update_central_loc) event_done(&conn); + ut_rx_q_is_empty(); + + /* Release Ntf, so next cycle will generate NTF and complete procedure */ + ull_cp_release_ntf(ntf); + + event_prepare(&conn); + event_done(&conn); + /* There should be one host notification */ ut_rx_pdu(LL_LENGTH_RSP, &ntf, &length_ntf); ut_rx_q_is_empty(); - zassert_equal(conn.lll.event_counter, 1, "Wrong event-count %d\n", + zassert_equal(conn.lll.event_counter, 2, "Wrong event-count %d\n", conn.lll.event_counter); - - zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), - "Free CTX buffers %d", llcp_ctx_buffers_free()); } /* @@ -601,6 +613,13 @@ ZTEST(dle_periph, test_data_length_update_periph_rem) ull_conn_default_tx_time_set(1800); ull_dle_init(&conn, PHY_1M); + /* Steal all ntf buffers, so as to check that the wait_ntf mechanism works */ + while (ll_pdu_rx_alloc_peek(1)) { + ntf = ll_pdu_rx_alloc(); + /* Make sure we use a correct type or the release won't work */ + ntf->hdr.type = NODE_RX_TYPE_DC_PDU; + } + event_prepare(&conn); /* Tx Queue should have one LL Control PDU */ @@ -617,6 +636,13 @@ ZTEST(dle_periph, test_data_length_update_periph_rem) /* TX Ack */ event_tx_ack(&conn, tx); + event_done(&conn); + ut_rx_q_is_empty(); + + /* Release Ntf, so next cycle will generate NTF and complete procedure */ + ull_cp_release_ntf(ntf); + + event_prepare(&conn); event_done(&conn); ut_rx_pdu(LL_LENGTH_RSP, &ntf, &length_ntf); diff --git a/tests/bluetooth/controller/ctrl_encrypt/src/main.c b/tests/bluetooth/controller/ctrl_encrypt/src/main.c index 86e11ee00df4..1793f7dd7deb 100644 --- a/tests/bluetooth/controller/ctrl_encrypt/src/main.c +++ b/tests/bluetooth/controller/ctrl_encrypt/src/main.c @@ -290,7 +290,7 @@ ZTEST(encryption_start, test_encryption_start_central_loc) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -392,6 +392,13 @@ ZTEST(encryption_start, test_encryption_start_central_loc_limited_memory) /* Dummy remove, as above loop might queue up ctx */ llcp_tx_alloc_unpeek(ctx); + /* Steal all ntf buffers */ + while (ll_pdu_rx_alloc_peek(1)) { + ntf = ll_pdu_rx_alloc(); + /* Make sure we use a correct type or the release won't work */ + ntf->hdr.type = NODE_RX_TYPE_DC_PDU; + } + /* Initiate an Encryption Start Procedure */ err = ull_cp_encryption_start(&conn, rand, ediv, ltk); zassert_equal(err, BT_HCI_ERR_SUCCESS); @@ -478,12 +485,32 @@ ZTEST(encryption_start, test_encryption_start_central_loc_limited_memory) CHECK_RX_PE_STATE(conn, RESUMED, ENCRYPTED); /* Rx enc. */ CHECK_TX_PE_STATE(conn, RESUMED, ENCRYPTED); /* Tx enc. */ + /* There should be no host notifications */ + ut_rx_q_is_empty(); + + /* Release Ntf */ + ull_cp_release_ntf(ntf); + + /* Prepare */ + event_prepare(&conn); + + /* Check state */ + CHECK_RX_PE_STATE(conn, RESUMED, ENCRYPTED); /* Rx enc. */ + CHECK_TX_PE_STATE(conn, RESUMED, ENCRYPTED); /* Tx enc. */ + + /* Done */ + event_done(&conn); + + /* Check state */ + CHECK_RX_PE_STATE(conn, RESUMED, ENCRYPTED); /* Rx enc. */ + CHECK_TX_PE_STATE(conn, RESUMED, ENCRYPTED); /* Tx enc. */ + /* There should be one host notification */ ut_rx_pdu(LL_START_ENC_RSP, &ntf, NULL); ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Tx Encryption should be enabled */ zassert_equal(conn.lll.enc_tx, 1U); @@ -594,7 +621,7 @@ ZTEST(encryption_start, test_encryption_start_central_loc_reject_ext) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -691,7 +718,7 @@ ZTEST(encryption_start, test_encryption_start_central_loc_reject) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -802,7 +829,7 @@ ZTEST(encryption_start, test_encryption_start_central_loc_no_ltk) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -908,7 +935,7 @@ ZTEST(encryption_start, test_encryption_start_central_loc_no_ltk_2) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -1170,7 +1197,7 @@ ZTEST(encryption_start, test_encryption_start_periph_rem) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* LTK request reply */ ull_cp_ltk_req_reply(&conn, ltk); @@ -1352,6 +1379,13 @@ ZTEST(encryption_start, test_encryption_start_periph_rem_limited_memory) /* Dummy remove, as above loop might queue up ctx */ llcp_tx_alloc_unpeek(ctx); + /* Steal all ntf buffers */ + while (ll_pdu_rx_alloc_peek(1)) { + ntf = ll_pdu_rx_alloc(); + /* Make sure we use a correct type or the release won't work */ + ntf->hdr.type = NODE_RX_TYPE_DC_PDU; + } + /* Check state */ CHECK_RX_PE_STATE(conn, RESUMED, UNENCRYPTED); /* Rx unenc. */ CHECK_TX_PE_STATE(conn, RESUMED, UNENCRYPTED); /* Tx unenc. */ @@ -1390,12 +1424,29 @@ ZTEST(encryption_start, test_encryption_start_periph_rem_limited_memory) CHECK_RX_PE_STATE(conn, PAUSED, UNENCRYPTED); /* Rx paused & unenc. */ CHECK_TX_PE_STATE(conn, PAUSED, UNENCRYPTED); /* Tx paused & unenc. */ - /* There should be one host notification */ - ut_rx_pdu(LL_ENC_REQ, &ntf, &enc_req); + /* Done */ + event_done(&conn); + + /* Check state */ + CHECK_RX_PE_STATE(conn, PAUSED, UNENCRYPTED); /* Rx paused & unenc. */ + CHECK_TX_PE_STATE(conn, PAUSED, UNENCRYPTED); /* Tx paused & unenc. */ + + /* There should not be a host notification */ ut_rx_q_is_empty(); /* Release ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); + + /* Prepare */ + event_prepare(&conn); + + /* Check state */ + CHECK_RX_PE_STATE(conn, PAUSED, UNENCRYPTED); /* Rx paused & unenc. */ + CHECK_TX_PE_STATE(conn, PAUSED, UNENCRYPTED); /* Tx paused & unenc. */ + + /* There should be one host notification */ + ut_rx_pdu(LL_ENC_REQ, &ntf, &enc_req); + ut_rx_q_is_empty(); /* Done */ event_done(&conn); @@ -1472,13 +1523,19 @@ ZTEST(encryption_start, test_encryption_start_periph_rem_limited_memory) CHECK_RX_PE_STATE(conn, PAUSED, ENCRYPTED); /* Rx paused & enc. */ CHECK_TX_PE_STATE(conn, PAUSED, UNENCRYPTED); /* Tx paused & unenc. */ - /* There should be one host notification */ - ut_rx_pdu(LL_START_ENC_RSP, &ntf, NULL); + /* There should not be a host notification */ ut_rx_q_is_empty(); + /* Release ntf */ + ull_cp_release_ntf(ntf); + /* Prepare */ event_prepare(&conn); + /* There should be one host notification */ + ut_rx_pdu(LL_START_ENC_RSP, &ntf, NULL); + ut_rx_q_is_empty(); + /* Tx Queue should not have a LL Control PDU */ lt_rx_q_is_empty(&conn); @@ -1630,7 +1687,7 @@ ZTEST(encryption_start, test_encryption_start_periph_rem_no_ltk) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* LTK request reply */ ull_cp_ltk_req_neq_reply(&conn); @@ -1770,7 +1827,7 @@ ZTEST(encryption_start, test_encryption_start_periph_rem_mic) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Prepare */ event_prepare(&conn); @@ -1955,7 +2012,7 @@ ZTEST(encryption_pause, test_encryption_pause_central_loc) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Tx Encryption should be enabled */ zassert_equal(conn.lll.enc_tx, 1U); @@ -2072,7 +2129,7 @@ ZTEST(encryption_pause, test_encryption_pause_periph_rem) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* LTK request reply */ ull_cp_ltk_req_reply(&conn, ltk); diff --git a/tests/bluetooth/controller/ctrl_feature_exchange/src/main.c b/tests/bluetooth/controller/ctrl_feature_exchange/src/main.c index 83488ffbf96d..d00b7ece07a5 100644 --- a/tests/bluetooth/controller/ctrl_feature_exchange/src/main.c +++ b/tests/bluetooth/controller/ctrl_feature_exchange/src/main.c @@ -129,7 +129,7 @@ ZTEST(fex_central, test_feat_exchange_central_loc) ut_rx_q_is_empty(); ull_cp_release_tx(&conn, tx); - release_ntf(ntf); + ull_cp_release_ntf(ntf); } /* Test that host enabled feature makes it into feature exchange */ @@ -159,7 +159,7 @@ ZTEST(fex_central, test_feat_exchange_central_loc) ut_rx_q_is_empty(); ull_cp_release_tx(&conn, tx); - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Remove host feature bit again */ ll_set_host_feature(BT_LE_FEAT_BIT_ISO_CHANNELS, 0); @@ -432,7 +432,7 @@ ZTEST(fex_central, test_feat_exchange_central_rem_2) lt_rx_q_is_empty(&conn); ull_cp_release_tx(&conn, tx); - release_ntf(ntf); + ull_cp_release_ntf(ntf); } zassert_equal(conn.lll.event_counter, CENTRAL_NR_OF_EVENTS * (feat_to_test), @@ -460,6 +460,13 @@ ZTEST(fex_periph, test_peripheral_feat_exchange_periph_loc) /* Connect */ ull_cp_state_set(&conn, ULL_CP_CONNECTED); + /* Steal all ntf buffers, so as to check that the wait_ntf mechanism works */ + while (ll_pdu_rx_alloc_peek(1)) { + ntf = ll_pdu_rx_alloc(); + /* Make sure we use a correct type or the release won't work */ + ntf->hdr.type = NODE_RX_TYPE_DC_PDU; + } + /* Initiate a Feature Exchange Procedure */ err = ull_cp_feature_exchange(&conn); zassert_equal(err, BT_HCI_ERR_SUCCESS); @@ -474,11 +481,19 @@ ZTEST(fex_periph, test_peripheral_feat_exchange_periph_loc) event_done(&conn); + ut_rx_q_is_empty(); + + /* Release Ntf, so next cycle will generate NTF and complete procedure */ + ull_cp_release_ntf(ntf); + + event_prepare(&conn); + event_done(&conn); + /* There should be one host notification */ + ut_rx_pdu(LL_FEATURE_RSP, &ntf, &remote_feature_rsp); ut_rx_q_is_empty(); - - zassert_equal(conn.lll.event_counter, 1, "Wrong event-count %d\n", + zassert_equal(conn.lll.event_counter, 2, "Wrong event-count %d\n", conn.lll.event_counter); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -504,7 +519,15 @@ ZTEST(fex_periph, test_feat_exchange_periph_loc_unknown_rsp) ull_cp_state_set(&conn, ULL_CP_CONNECTED); + /* Steal all ntf buffers, so as to check that the wait_ntf mechanism works */ + while (ll_pdu_rx_alloc_peek(1)) { + ntf = ll_pdu_rx_alloc(); + /* Make sure we use a correct type or the release won't work */ + ntf->hdr.type = NODE_RX_TYPE_DC_PDU; + } + /* Initiate a Feature Exchange Procedure */ + event_prepare(&conn); err = ull_cp_feature_exchange(&conn); zassert_equal(err, BT_HCI_ERR_SUCCESS); @@ -522,9 +545,17 @@ ZTEST(fex_periph, test_feat_exchange_periph_loc_unknown_rsp) event_done(&conn); + ut_rx_q_is_empty(); + + /* Release Ntf, so next cycle will generate NTF and complete procedure */ + ull_cp_release_ntf(ntf); + + event_prepare(&conn); + event_done(&conn); + ut_rx_pdu(LL_UNKNOWN_RSP, &ntf, &unknown_rsp); ut_rx_q_is_empty(); - zassert_equal(conn.lll.event_counter, 2, "Wrong event-count %d\n", + zassert_equal(conn.lll.event_counter, 3, "Wrong event-count %d\n", conn.lll.event_counter); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); diff --git a/tests/bluetooth/controller/ctrl_feature_exchange/src/main_hci.c b/tests/bluetooth/controller/ctrl_feature_exchange/src/main_hci.c index 85a67ca9f6d1..336f65b03c5d 100644 --- a/tests/bluetooth/controller/ctrl_feature_exchange/src/main_hci.c +++ b/tests/bluetooth/controller/ctrl_feature_exchange/src/main_hci.c @@ -136,7 +136,7 @@ ZTEST(hci_fex, test_hci_feat_exchange_central_loc) "Wrong event count %d\n", conn_from_pool->lll.event_counter); ull_cp_release_tx(conn_from_pool, tx); - release_ntf(ntf); + ull_cp_release_ntf(ntf); ll_conn_release(conn_from_pool); } diff --git a/tests/bluetooth/controller/ctrl_hci/src/main.c b/tests/bluetooth/controller/ctrl_hci/src/main.c index 00aadbade9e7..42235a724767 100644 --- a/tests/bluetooth/controller/ctrl_hci/src/main.c +++ b/tests/bluetooth/controller/ctrl_hci/src/main.c @@ -120,7 +120,7 @@ ZTEST(hci_fex, test_hci_feature_exchange) zassert_equal(conn_from_pool->lll.event_counter, 1, "Wrong event count %d\n", conn_from_pool->lll.event_counter); ull_cp_release_tx(conn_from_pool, tx); - release_ntf(ntf); + ull_cp_release_ntf(ntf); ll_conn_release(conn_from_pool); } @@ -186,7 +186,7 @@ ZTEST(hci_version, test_hci_version_ind) zassert_equal(conn_from_pool->lll.event_counter, 1, "Wrong event count %d\n", conn_from_pool->lll.event_counter); ull_cp_release_tx(conn_from_pool, tx); - release_ntf(ntf); + ull_cp_release_ntf(ntf); ll_conn_release(conn_from_pool); } diff --git a/tests/bluetooth/controller/ctrl_phy_update/src/main.c b/tests/bluetooth/controller/ctrl_phy_update/src/main.c index 13e3409acb82..d67a44b6b482 100644 --- a/tests/bluetooth/controller/ctrl_phy_update/src/main.c +++ b/tests/bluetooth/controller/ctrl_phy_update/src/main.c @@ -37,7 +37,6 @@ #include "ull_iso_types.h" #include "ull_conn_iso_types.h" -#include "ull_internal.h" #include "ull_conn_types.h" #include "ull_llcp.h" #include "ull_conn_internal.h" @@ -121,7 +120,7 @@ ZTEST(phy_central, test_phy_update_central_loc) struct pdu_data_llctrl_phy_req req = { .rx_phys = PHY_2M, .tx_phys = PHY_2M }; struct pdu_data_llctrl_phy_req rsp = { .rx_phys = PHY_1M | PHY_2M, .tx_phys = PHY_1M | PHY_2M }; - struct pdu_data_llctrl_phy_upd_ind ind = { .instant = 8, + struct pdu_data_llctrl_phy_upd_ind ind = { .instant = 7, .c_to_p_phy = PHY_2M, .p_to_c_phy = PHY_2M }; struct pdu_data_llctrl_length_rsp length_ntf = { @@ -145,13 +144,6 @@ ZTEST(phy_central, test_phy_update_central_loc) err = ull_cp_phy_update(&conn, PHY_2M, PREFER_S8_CODING, PHY_2M, HOST_INITIATED); zassert_equal(err, BT_HCI_ERR_SUCCESS); - /* Steal all ntf buffers, to trigger TX stall on non avail of NTF buffer for DLE */ - while (ll_pdu_rx_alloc_peek(1)) { - ntf = ll_pdu_rx_alloc(); - /* Make sure we use a correct type or the release won't work */ - ntf->hdr.type = NODE_RX_TYPE_DC_PDU; - } - /* Prepare */ event_prepare(&conn); @@ -177,18 +169,6 @@ ZTEST(phy_central, test_phy_update_central_loc) /* Prepare */ event_prepare(&conn); - /* No TX yet as unable to pre-allocate NTF buffer for DLE */ - lt_rx_q_is_empty(&conn); - - /* Done */ - event_done(&conn); - - /* Release RX node to now allow pre-alloc for DLE NTF */ - release_ntf(ntf); - - /* Prepare */ - event_prepare(&conn); - /* Tx Queue should have one LL Control PDU */ lt_rx(LL_PHY_UPDATE_IND, &conn, &tx, &ind); lt_rx_q_is_empty(&conn); @@ -237,15 +217,11 @@ ZTEST(phy_central, test_phy_update_central_loc) /* There should be two host notifications, one pu and one dle */ ut_rx_node(NODE_PHY_UPDATE, &ntf, &pu); - /* Release Ntf */ - release_ntf(ntf); - ut_rx_pdu(LL_LENGTH_RSP, &ntf, &length_ntf); - /* Release Ntf */ - release_ntf(ntf); - ut_rx_q_is_empty(); + /* Release Ntf */ + ull_cp_release_ntf(ntf); CHECK_CURRENT_PHY_STATE(conn, PHY_2M, PREFER_S8_CODING, PHY_2M); CHECK_PREF_PHY_STATE(conn, PHY_2M, PHY_2M); @@ -342,18 +318,12 @@ ZTEST(phy_central, test_phy_update_central_loc_unsupp_feat) /* Release Tx */ ull_cp_release_tx(&conn, tx); - /* Prepare */ - event_prepare(&conn); - - /* Done */ - event_done(&conn); - /* There should be one host notification */ ut_rx_node(NODE_PHY_UPDATE, &ntf, &pu); ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -365,7 +335,7 @@ ZTEST(phy_central, test_phy_update_central_rem) struct node_rx_pdu *ntf; struct pdu_data *pdu; struct pdu_data_llctrl_phy_req req = { .rx_phys = PHY_1M, .tx_phys = PHY_2M }; - struct pdu_data_llctrl_phy_upd_ind ind = { .instant = 8, + struct pdu_data_llctrl_phy_upd_ind ind = { .instant = 7, .c_to_p_phy = 0, .p_to_c_phy = PHY_2M }; uint16_t instant; @@ -378,13 +348,6 @@ ZTEST(phy_central, test_phy_update_central_rem) /* Connect */ ull_cp_state_set(&conn, ULL_CP_CONNECTED); - /* Steal all ntf buffers, to trigger TX stall on non avail of NTF buffer for DLE */ - while (ll_pdu_rx_alloc_peek(1)) { - ntf = ll_pdu_rx_alloc(); - /* Make sure we use a correct type or the release won't work */ - ntf->hdr.type = NODE_RX_TYPE_DC_PDU; - } - /* Prepare */ event_prepare(&conn); @@ -397,18 +360,6 @@ ZTEST(phy_central, test_phy_update_central_rem) /* Done */ event_done(&conn); - /* Prepare */ - event_prepare(&conn); - - /* No TX yet as unable to pre-allocate NTF buffer for DLE */ - lt_rx_q_is_empty(&conn); - - /* Done */ - event_done(&conn); - - /* Release RX node to now allow pre-alloc for DLE NTF */ - release_ntf(ntf); - /* Check that data tx was paused */ zassert_equal(conn.tx_q.pause_data, 1U, "Data tx is not paused"); @@ -464,7 +415,7 @@ ZTEST(phy_central, test_phy_update_central_rem) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); CHECK_CURRENT_PHY_STATE(conn, PHY_1M, PREFER_S8_CODING, PHY_2M); CHECK_PREF_PHY_STATE(conn, PHY_1M | PHY_2M | PHY_CODED, PHY_1M | PHY_2M | PHY_CODED); @@ -553,7 +504,7 @@ ZTEST(phy_periph, test_phy_update_periph_loc) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); CHECK_CURRENT_PHY_STATE(conn, PHY_2M, PREFER_S8_CODING, PHY_2M); CHECK_PREF_PHY_STATE(conn, PHY_2M, PHY_2M); @@ -651,7 +602,7 @@ ZTEST(phy_periph, test_phy_update_periph_rem) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); CHECK_CURRENT_PHY_STATE(conn, PHY_2M, PREFER_S8_CODING, PHY_1M); CHECK_PREF_PHY_STATE(conn, PHY_1M | PHY_2M | PHY_CODED, PHY_1M | PHY_2M | PHY_CODED); @@ -700,18 +651,12 @@ ZTEST(phy_periph, test_phy_update_periph_loc_unsupp_feat) /* Release Tx */ ull_cp_release_tx(&conn, tx); - /* Prepare */ - event_prepare(&conn); - - /* Done */ - event_done(&conn); - /* There should be one host notification */ ut_rx_node(NODE_PHY_UPDATE, &ntf, &pu); ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -936,7 +881,7 @@ ZTEST(phy_central, test_phy_update_central_loc_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -1062,7 +1007,7 @@ ZTEST(phy_central, test_phy_update_central_rem_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Prepare */ event_prepare(&conn); @@ -1113,7 +1058,7 @@ ZTEST(phy_central, test_phy_update_central_rem_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -1183,19 +1128,13 @@ ZTEST(phy_periph, test_phy_update_periph_loc_collision) /* Done */ event_done(&conn); - /* Prepare */ - event_prepare(&conn); - - /* Done */ - event_done(&conn); - /* There should be one host notification */ pu.status = BT_HCI_ERR_LL_PROC_COLLISION; ut_rx_node(NODE_PHY_UPDATE, &ntf, &pu); ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); /* Prepare */ event_prepare(&conn); @@ -1243,7 +1182,7 @@ ZTEST(phy_periph, test_phy_update_periph_loc_collision) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(), "Free CTX buffers %d", llcp_ctx_buffers_free()); @@ -1326,7 +1265,7 @@ ZTEST(phy_central, test_phy_update_central_loc_no_act_change) ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); CHECK_CURRENT_PHY_STATE(conn, PHY_1M, PREFER_S8_CODING, PHY_1M); CHECK_PREF_PHY_STATE(conn, PHY_1M, PHY_1M); @@ -1449,18 +1388,12 @@ ZTEST(phy_periph, test_phy_update_periph_loc_no_actual_change) /* Done */ event_done(&conn); - /* Prepare */ - event_prepare(&conn); - - /* Done */ - event_done(&conn); - /* There should be one notification due to Host initiated PHY UPD */ ut_rx_node(NODE_PHY_UPDATE, &ntf, &pu); ut_rx_q_is_empty(); /* Release Ntf */ - release_ntf(ntf); + ull_cp_release_ntf(ntf); CHECK_CURRENT_PHY_STATE(conn, PHY_1M, PREFER_S8_CODING, PHY_1M); CHECK_PREF_PHY_STATE(conn, PHY_1M, PHY_1M); @@ -1526,12 +1459,6 @@ ZTEST(phy_periph, test_phy_update_periph_rem_no_actual_change) /* There should be no host notification */ ut_rx_q_is_empty(); - /* Prepare */ - event_prepare(&conn); - - /* Done */ - event_done(&conn); - CHECK_CURRENT_PHY_STATE(conn, PHY_1M, PREFER_S8_CODING, PHY_1M); CHECK_PREF_PHY_STATE(conn, PHY_1M | PHY_2M | PHY_CODED, PHY_1M | PHY_2M | PHY_CODED); diff --git a/tests/bluetooth/controller/mock_ctrl/src/ull.c b/tests/bluetooth/controller/mock_ctrl/src/ull.c index a7e9785c9c68..600c880870b6 100644 --- a/tests/bluetooth/controller/mock_ctrl/src/ull.c +++ b/tests/bluetooth/controller/mock_ctrl/src/ull.c @@ -137,7 +137,6 @@ void ll_rx_mem_release(void **node_rx) case NODE_RX_TYPE_ENC_REFRESH: case NODE_RX_TYPE_PHY_UPDATE: case NODE_RX_TYPE_CIS_REQUEST: - case NODE_RX_TYPE_CIS_ESTABLISHED: ll_rx_link_inc_quota(1); mem_release(rx_free, &mem_pdu_rx.free); @@ -180,10 +179,7 @@ void ll_rx_release(void *node_rx) void ll_rx_put(memq_link_t *link, void *rx) { - if (((struct node_rx_hdr *)rx)->type != NODE_RX_TYPE_RELEASE) { - /* Only put/sched if node was not marked for release */ - sys_slist_append(&ut_rx_q, (sys_snode_t *)rx); - } + sys_slist_append(&ut_rx_q, (sys_snode_t *)rx); } void ll_rx_sched(void) From ca3d0c8ee9a88740adcad6950d58a5b23b882be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vidar=20Lilleb=C3=B8?= Date: Thu, 2 Mar 2023 15:14:42 +0100 Subject: [PATCH 0090/1906] mbedtls: Remove dependency on MBEDTLS_BUILTIN for MBEDTLS_DEBUG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows using MBEDTLS_DEBUG functionality when not using MBEDTLS_BUILTIN. Signed-off-by: Vidar Lillebø --- modules/mbedtls/Kconfig | 1 - subsys/net/lib/sockets/sockets_tls.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/mbedtls/Kconfig b/modules/mbedtls/Kconfig index ced8519ba2db..81edf4ab5742 100644 --- a/modules/mbedtls/Kconfig +++ b/modules/mbedtls/Kconfig @@ -82,7 +82,6 @@ source "subsys/logging/Kconfig.template.log_config" config MBEDTLS_DEBUG bool "mbed TLS debug activation" - depends on MBEDTLS_BUILTIN help Enable debugging activation for mbed TLS configuration. If you use mbedTLS/Zephyr integration (e.g. native TLS sockets), this will diff --git a/subsys/net/lib/sockets/sockets_tls.c b/subsys/net/lib/sockets/sockets_tls.c index 8f67d8ea3107..436f3448a09b 100644 --- a/subsys/net/lib/sockets/sockets_tls.c +++ b/subsys/net/lib/sockets/sockets_tls.c @@ -56,7 +56,7 @@ LOG_MODULE_REGISTER(net_sock_tls, CONFIG_NET_SOCKETS_LOG_LEVEL); #include "sockets_internal.h" #include "tls_internal.h" -#if defined(CONFIG_MBEDTLS_BUILTIN) +#if defined(CONFIG_MBEDTLS_DEBUG) #include #endif From 02eac5cbc2252675d08ccf54f3eee2b132269953 Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Thu, 9 Mar 2023 15:06:26 +0100 Subject: [PATCH 0091/1906] Bluetooth: controller: fix compile error when VS cmds disabled When vendor specific commands are disabled by setting BT_HCI_VS=n the host still calls bt_read_static_addr, but that function is not compiled in, resulting in a build error. Fixed by moving the code in controller/hci/hci.c outside of the conditional compile Signed-off-by: Andries Kruithof --- subsys/bluetooth/controller/hci/hci.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 3dc09242a5c9..7b11fd01969a 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -4726,6 +4726,16 @@ static int controller_cmd_handle(uint16_t ocf, struct net_buf *cmd, return 0; } +/* If Zephyr VS HCI commands are not enabled provide this functionality directly + */ +#if !defined(CONFIG_BT_HCI_VS_EXT) +uint8_t bt_read_static_addr(struct bt_hci_vs_static_addr addrs[], uint8_t size) +{ + return hci_vendor_read_static_addr(addrs, size); +} +#endif /* !defined(CONFIG_BT_HCI_VS_EXT) */ + + #if defined(CONFIG_BT_HCI_VS) static void vs_read_version_info(struct net_buf *buf, struct net_buf **evt) { @@ -4793,15 +4803,6 @@ uint8_t __weak hci_vendor_read_static_addr(struct bt_hci_vs_static_addr addrs[], return 0; } -/* If Zephyr VS HCI commands are not enabled provide this functionality directly - */ -#if !defined(CONFIG_BT_HCI_VS_EXT) -uint8_t bt_read_static_addr(struct bt_hci_vs_static_addr addrs[], uint8_t size) -{ - return hci_vendor_read_static_addr(addrs, size); -} -#endif /* !defined(CONFIG_BT_HCI_VS_EXT) */ - #if defined(CONFIG_BT_HCI_VS_EXT) static void vs_write_bd_addr(struct net_buf *buf, struct net_buf **evt) { From 8f45c0db79e51f8ef4f0ba5eaa4c5fc33a96bda2 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 10 Mar 2023 06:14:34 +0000 Subject: [PATCH 0092/1906] twister: fix wrong reason when timeout occurs We are wrongly claiming no console output, yet console output is there and the failure is just a regular timeout, i.e. the test did not complete within allocated time. Signed-off-by: Anas Nashif --- scripts/pylib/twister/twisterlib/handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pylib/twister/twisterlib/handlers.py b/scripts/pylib/twister/twisterlib/handlers.py index f4b2c5aaa61d..5ab69aa940c9 100755 --- a/scripts/pylib/twister/twisterlib/handlers.py +++ b/scripts/pylib/twister/twisterlib/handlers.py @@ -645,7 +645,7 @@ def handle(self): self.instance.reason = "Failed" elif not flash_error: self.instance.status = "error" - self.instance.reason = "No Console Output(Timeout)" + self.instance.reason = "Timeout" if self.instance.status == "error": self.instance.add_missing_case_status("blocked", self.instance.reason) From 81847a57ff67aac04944a70acf70d86cc79ee2e3 Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Fri, 10 Mar 2023 10:08:04 +0800 Subject: [PATCH 0093/1906] Bluetooth: Host: Refine assert message Add opcode information for cmd timeout assert, since BT_DBG usually not show in real product, however we can't see any information just from assert message. Signed-off-by: Lingao Meng --- subsys/bluetooth/host/hci_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index c2caade6b965..45509edb17ae 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -327,7 +327,7 @@ int bt_hci_cmd_send_sync(uint16_t opcode, struct net_buf *buf, net_buf_put(&bt_dev.cmd_tx_queue, net_buf_ref(buf)); err = k_sem_take(&sync_sem, HCI_CMD_TIMEOUT); - BT_ASSERT_MSG(err == 0, "k_sem_take failed with err %d", err); + BT_ASSERT_MSG(err == 0, "command opcode 0x%04x timeout with err %d", opcode, err); status = cmd(buf)->status; if (status) { From 7b85e7072261a1dba01abe2d2577fd25f064ce7c Mon Sep 17 00:00:00 2001 From: Herman Berget Date: Thu, 9 Mar 2023 16:45:19 +0100 Subject: [PATCH 0094/1906] Bluetooth: Host: Add missing include in bluetooth/gap.h bluetooth/gap.h uses some utility macros. Include the relevant header to avoid users having to include it before including the GAP header. Signed-off-by: Herman Berget --- include/zephyr/bluetooth/gap.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/zephyr/bluetooth/gap.h b/include/zephyr/bluetooth/gap.h index ea85f6aa4636..dddcf4ef5132 100644 --- a/include/zephyr/bluetooth/gap.h +++ b/include/zephyr/bluetooth/gap.h @@ -15,6 +15,8 @@ extern "C" { #endif +#include + /** * @brief Bluetooth Generic Access Profile defines and Assigned Numbers. * @defgroup bt_gap_defines Defines and Assigned Numbers From f9d155b7d5419bdb825fe63abf862adcc7d97e8d Mon Sep 17 00:00:00 2001 From: Siyuan Cheng Date: Mon, 11 Jul 2022 14:58:29 +0800 Subject: [PATCH 0095/1906] dts: boards :emsdp: add SPI support There is a spi-flash fl256s on emsdp board, which can be contolled by DesignWare SPI driver. Now add DW SPI and SPI-FLASH support for emsdp board. Signed-off-by: Siyuan Cheng --- boards/arc/emsdp/Kconfig.defconfig | 17 ++++++++ boards/arc/emsdp/arc_mpu_regions.c | 2 +- boards/arc/emsdp/doc/index.rst | 50 +++++++++++++++++++++++ boards/arc/emsdp/emsdp.dts | 8 ++++ boards/arc/emsdp/emsdp.yaml | 2 + boards/arc/emsdp/emsdp_defconfig | 1 + boards/arc/emsdp/emsdp_em4.dts | 8 ++++ boards/arc/emsdp/emsdp_em5d.dts | 8 ++++ boards/arc/emsdp/emsdp_em5d_defconfig | 1 + boards/arc/emsdp/emsdp_em6.dts | 8 ++++ boards/arc/emsdp/emsdp_em6.yaml | 2 + boards/arc/emsdp/emsdp_em6_defconfig | 1 + boards/arc/emsdp/emsdp_em7d.dts | 8 ++++ boards/arc/emsdp/emsdp_em7d_esp.dts | 9 ++++ boards/arc/emsdp/emsdp_em7d_esp.yaml | 2 + boards/arc/emsdp/emsdp_em7d_esp_defconfig | 1 + boards/arc/emsdp/emsdp_em9d.dts | 8 ++++ boards/arc/emsdp/emsdp_em9d.yaml | 2 + boards/arc/emsdp/emsdp_em9d_defconfig | 1 + dts/arc/synopsys/emsdp.dtsi | 34 +++++++++++++++ soc/arc/snps_emsdp/Kconfig.soc | 1 + 21 files changed, 173 insertions(+), 1 deletion(-) diff --git a/boards/arc/emsdp/Kconfig.defconfig b/boards/arc/emsdp/Kconfig.defconfig index 95a3a4493469..c0ee191aa959 100644 --- a/boards/arc/emsdp/Kconfig.defconfig +++ b/boards/arc/emsdp/Kconfig.defconfig @@ -16,4 +16,21 @@ config GPIO_INIT_PRIORITY endif # GPIO +if SPI + +config SPI_DW + default y + +if SPI_DW + +config SPI_DW_FIFO_DEPTH + default 32 + +config SPI_DW_ARC_AUX_REGS + default n + +endif # SPI_DW + +endif # SPI + endif # BOARD_EMSDP diff --git a/boards/arc/emsdp/arc_mpu_regions.c b/boards/arc/emsdp/arc_mpu_regions.c index 9ff278fb7a33..6fb2e57d4c66 100644 --- a/boards/arc/emsdp/arc_mpu_regions.c +++ b/boards/arc/emsdp/arc_mpu_regions.c @@ -43,7 +43,7 @@ static struct arc_mpu_region mpu_regions[] = { /* Region Peripheral */ MPU_REGION_ENTRY("PERIPHERAL", 0xF0000000, - 64 * 1024, + 32 * 1024 * 1024, REGION_KERNEL_RAM_ATTR), }; diff --git a/boards/arc/emsdp/doc/index.rst b/boards/arc/emsdp/doc/index.rst index 4bc32e6d6a79..4747cbd1944e 100644 --- a/boards/arc/emsdp/doc/index.rst +++ b/boards/arc/emsdp/doc/index.rst @@ -44,9 +44,59 @@ The following table shows the hardware features supported for different core con | Secure | N | N | N | N | Y | N | N | +-----------+-----+-----+------+------+----------+------+-------+ +The table below shows which drivers are currently available in Zephyr. + ++-----------+------------+-------+-----------------------+ +| Interface | Controller | EMSDP | Driver/Component | ++===========+============+=======+=======================+ +| SDIO | on-chip | N | SD-card controller | ++-----------+------------+-------+-----------------------+ +| UART | Arduino + | Y | serial port-polling; | +| | 3 Pmods | | serial port-interrupt | ++-----------+------------+-------+-----------------------+ +| SPI | Arduino + | Y | spi | +| | Pmod + adc | | | ++-----------+------------+-------+-----------------------+ +| ADC | 1 Pmod | N | adc (via spi) | ++-----------+------------+-------+-----------------------+ +| I2C | Arduino + | N | i2c | +| | Pmod | | | ++-----------+------------+-------+-----------------------+ +| GPIO | Arduino + | Y | gpio | +| | Pmod + Pin | | | ++-----------+------------+-------+-----------------------+ +| PWM | Arduino + | N | pwm | +| | Pmod | | | ++-----------+------------+-------+-----------------------+ +| I2S | on-chip | N | Audio interface | ++-----------+------------+-------+-----------------------+ + +Support two 32 MByte Quad-SPI Flash memory, one only contains FPGA image, the other +one is user SPI-FLASH, which is connected via SPI bus and its sample can be found in +``samples/drivers/spi_flash``. + +To configure the FPGA, The ARC EM SDP offers a single USB 2.0 host port, which is +both used to access the FPGAs configuration memory and as a DEBUG/ UART port. + +When connected using the USB cable to a PC, the ARC EM SDP presents itself as a mass +storage device. This allows an FPGA configuration bitstream to be dragged and dropped into +the configuration memory. The FPGA bitstream is automatically loaded into the FPGA device +upon power-on reset, or when the configuration button is pressed. + For hardware feature details, refer to : `ARC EM Software Development Platform `__ +Peripheral driver test and sample +================================= + +``tests/drivers/spi/spi_loopback``: verify DesignWare SPI driver. No need to connect +MISO with MOSI, DW SPI register is configured to internally connect them. This test +use two different speed to verify data transfer with asynchronous functionality. +Note: DW SPI only available on SPI0 and SPI1. + +``samples/drivers/spi_flash``: Verfiy DW SPI and SPI-FLASH on SPI1. First erase the +whole flash then write 4 byte data to the flash. Read from the flash and compare the +result with buffer to check functionality. Programming and Debugging ************************* diff --git a/boards/arc/emsdp/emsdp.dts b/boards/arc/emsdp/emsdp.dts index f09c918e2bbe..4cb95a398576 100644 --- a/boards/arc/emsdp/emsdp.dts +++ b/boards/arc/emsdp/emsdp.dts @@ -16,6 +16,7 @@ aliases { uart-0 = &uart0; + spi-flash0 = &s25fl256s; }; chosen { @@ -41,5 +42,12 @@ interrupts = <85 1>; }; + spi@f0008000 { + interrupts = <83 1>; + }; + + spi@f1000000 { + interrupts = <84 1>; + }; }; }; diff --git a/boards/arc/emsdp/emsdp.yaml b/boards/arc/emsdp/emsdp.yaml index ce6f08679bd2..44de46e8a7a0 100644 --- a/boards/arc/emsdp/emsdp.yaml +++ b/boards/arc/emsdp/emsdp.yaml @@ -7,6 +7,8 @@ toolchain: - cross-compile - xtools ram: 128 +supported: + - spi testing: ignore_tags: - net diff --git a/boards/arc/emsdp/emsdp_defconfig b/boards/arc/emsdp/emsdp_defconfig index 448533332736..031a0ebe6ad9 100644 --- a/boards/arc/emsdp/emsdp_defconfig +++ b/boards/arc/emsdp/emsdp_defconfig @@ -15,3 +15,4 @@ CONFIG_SERIAL=y CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_ARC_MPU_ENABLE=y CONFIG_GPIO=y +CONFIG_SPI=y diff --git a/boards/arc/emsdp/emsdp_em4.dts b/boards/arc/emsdp/emsdp_em4.dts index 83b87b4e62a1..0d0306065c09 100644 --- a/boards/arc/emsdp/emsdp_em4.dts +++ b/boards/arc/emsdp/emsdp_em4.dts @@ -15,6 +15,7 @@ aliases { uart-0 = &uart0; + spi-flash0 = &s25fl256s; }; chosen { @@ -40,5 +41,12 @@ interrupts = <86 1>; }; + spi@f0008000 { + interrupts = <83 1>; + }; + + spi@f1000000 { + interrupts = <84 1>; + }; }; }; diff --git a/boards/arc/emsdp/emsdp_em5d.dts b/boards/arc/emsdp/emsdp_em5d.dts index d7268eba8e91..66a544e95ef7 100644 --- a/boards/arc/emsdp/emsdp_em5d.dts +++ b/boards/arc/emsdp/emsdp_em5d.dts @@ -15,6 +15,7 @@ aliases { uart-0 = &uart0; + spi-flash0 = &s25fl256s; }; chosen { @@ -40,5 +41,12 @@ interrupts = <85 1>; }; + spi@f0008000 { + interrupts = <83 1>; + }; + + spi@f1000000 { + interrupts = <84 1>; + }; }; }; diff --git a/boards/arc/emsdp/emsdp_em5d_defconfig b/boards/arc/emsdp/emsdp_em5d_defconfig index 1739ed4befe1..2d117c7f42de 100644 --- a/boards/arc/emsdp/emsdp_em5d_defconfig +++ b/boards/arc/emsdp/emsdp_em5d_defconfig @@ -15,3 +15,4 @@ CONFIG_SERIAL=y CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_ARC_MPU_ENABLE=y CONFIG_GPIO=y +CONFIG_SPI=y diff --git a/boards/arc/emsdp/emsdp_em6.dts b/boards/arc/emsdp/emsdp_em6.dts index 83b87b4e62a1..0d0306065c09 100644 --- a/boards/arc/emsdp/emsdp_em6.dts +++ b/boards/arc/emsdp/emsdp_em6.dts @@ -15,6 +15,7 @@ aliases { uart-0 = &uart0; + spi-flash0 = &s25fl256s; }; chosen { @@ -40,5 +41,12 @@ interrupts = <86 1>; }; + spi@f0008000 { + interrupts = <83 1>; + }; + + spi@f1000000 { + interrupts = <84 1>; + }; }; }; diff --git a/boards/arc/emsdp/emsdp_em6.yaml b/boards/arc/emsdp/emsdp_em6.yaml index 2f97cc77a6e7..804cdb911862 100644 --- a/boards/arc/emsdp/emsdp_em6.yaml +++ b/boards/arc/emsdp/emsdp_em6.yaml @@ -7,6 +7,8 @@ toolchain: - cross-compile - xtools ram: 128 +supported: + - spi testing: ignore_tags: - net diff --git a/boards/arc/emsdp/emsdp_em6_defconfig b/boards/arc/emsdp/emsdp_em6_defconfig index 1dae91b7382d..7bcaa11ecb0d 100644 --- a/boards/arc/emsdp/emsdp_em6_defconfig +++ b/boards/arc/emsdp/emsdp_em6_defconfig @@ -15,3 +15,4 @@ CONFIG_SERIAL=y CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_ARC_MPU_ENABLE=y CONFIG_GPIO=y +CONFIG_SPI=y diff --git a/boards/arc/emsdp/emsdp_em7d.dts b/boards/arc/emsdp/emsdp_em7d.dts index d7268eba8e91..66a544e95ef7 100644 --- a/boards/arc/emsdp/emsdp_em7d.dts +++ b/boards/arc/emsdp/emsdp_em7d.dts @@ -15,6 +15,7 @@ aliases { uart-0 = &uart0; + spi-flash0 = &s25fl256s; }; chosen { @@ -40,5 +41,12 @@ interrupts = <85 1>; }; + spi@f0008000 { + interrupts = <83 1>; + }; + + spi@f1000000 { + interrupts = <84 1>; + }; }; }; diff --git a/boards/arc/emsdp/emsdp_em7d_esp.dts b/boards/arc/emsdp/emsdp_em7d_esp.dts index cbd9743550c4..89fc30499b7f 100644 --- a/boards/arc/emsdp/emsdp_em7d_esp.dts +++ b/boards/arc/emsdp/emsdp_em7d_esp.dts @@ -15,6 +15,7 @@ aliases { uart-0 = &uart0; + spi-flash0 = &s25fl256s; }; chosen { @@ -40,5 +41,13 @@ interrupts = <86 1>; }; + /* IRQ line in em7d_esp is different to others */ + spi@f0008000 { + interrupts = <84 1>; + }; + + spi@f1000000 { + interrupts = <85 1>; + }; }; }; diff --git a/boards/arc/emsdp/emsdp_em7d_esp.yaml b/boards/arc/emsdp/emsdp_em7d_esp.yaml index 52cffdc5061b..cdf45ea786fa 100644 --- a/boards/arc/emsdp/emsdp_em7d_esp.yaml +++ b/boards/arc/emsdp/emsdp_em7d_esp.yaml @@ -7,6 +7,8 @@ toolchain: - cross-compile - xtools ram: 128 +supported: + - spi testing: ignore_tags: - net diff --git a/boards/arc/emsdp/emsdp_em7d_esp_defconfig b/boards/arc/emsdp/emsdp_em7d_esp_defconfig index 5ebd6a5da124..b67dca68179a 100644 --- a/boards/arc/emsdp/emsdp_em7d_esp_defconfig +++ b/boards/arc/emsdp/emsdp_em7d_esp_defconfig @@ -17,3 +17,4 @@ CONFIG_ARC_MPU_ENABLE=y CONFIG_GPIO=y CONFIG_ARC_HAS_SECURE=y CONFIG_TRUSTED_EXECUTION_SECURE=y +CONFIG_SPI=y diff --git a/boards/arc/emsdp/emsdp_em9d.dts b/boards/arc/emsdp/emsdp_em9d.dts index 5e90bda4bcfd..c28956b9f600 100644 --- a/boards/arc/emsdp/emsdp_em9d.dts +++ b/boards/arc/emsdp/emsdp_em9d.dts @@ -16,6 +16,7 @@ aliases { uart-0 = &uart0; + spi-flash0 = &s25fl256s; }; chosen { @@ -51,5 +52,12 @@ interrupts = <85 1>; }; + spi@f0008000 { + interrupts = <83 1>; + }; + + spi@f1000000 { + interrupts = <84 1>; + }; }; }; diff --git a/boards/arc/emsdp/emsdp_em9d.yaml b/boards/arc/emsdp/emsdp_em9d.yaml index 2c571dee846d..d495ec11eb31 100644 --- a/boards/arc/emsdp/emsdp_em9d.yaml +++ b/boards/arc/emsdp/emsdp_em9d.yaml @@ -7,6 +7,8 @@ toolchain: - cross-compile - xtools ram: 128 +supported: + - spi testing: ignore_tags: - net diff --git a/boards/arc/emsdp/emsdp_em9d_defconfig b/boards/arc/emsdp/emsdp_em9d_defconfig index afbdae66c3d3..5a7342f67b26 100644 --- a/boards/arc/emsdp/emsdp_em9d_defconfig +++ b/boards/arc/emsdp/emsdp_em9d_defconfig @@ -15,3 +15,4 @@ CONFIG_SERIAL=y CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_ARC_MPU_ENABLE=y CONFIG_GPIO=y +CONFIG_SPI=y diff --git a/dts/arc/synopsys/emsdp.dtsi b/dts/arc/synopsys/emsdp.dtsi index 45a7fdd23f2d..baf8d6cd0235 100644 --- a/dts/arc/synopsys/emsdp.dtsi +++ b/dts/arc/synopsys/emsdp.dtsi @@ -51,6 +51,11 @@ reg = <0x10000000 0x1000000>; }; + spiclk: spi-clock { + compatible = "fixed-clock"; + clock-frequency = <1000000>; + #clock-cells = <0>; + }; soc { #address-cells = <1>; @@ -84,5 +89,34 @@ #gpio-cells = <2>; }; + /* wifi rs9113 */ + spi0: spi@f0008000 { + compatible = "snps,designware-spi"; + reg = <0xf0008000 0x1000>; + clocks = <&spiclk>; + interrupt-parent = <&intc>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + + /* SPI-flash for user data */ + spi1: spi@f1000000 { + compatible = "snps,designware-spi"; + reg = <0xf1000000 0x1000>; + clocks = <&spiclk>; + interrupt-parent = <&intc>; + #address-cells = <1>; + #size-cells = <0>; + s25fl256s: s25fl256s@0 { + compatible = "spansion,s25fl256s", "jedec,spi-nor"; + reg = <0>; + size = <0x10000000>; + spi-max-frequency = <100000>; + status = "okay"; + jedec-id = [01 02 19]; + }; + }; + }; }; diff --git a/soc/arc/snps_emsdp/Kconfig.soc b/soc/arc/snps_emsdp/Kconfig.soc index ed0a2f88e20c..a1358b8ad9d0 100644 --- a/soc/arc/snps_emsdp/Kconfig.soc +++ b/soc/arc/snps_emsdp/Kconfig.soc @@ -4,3 +4,4 @@ config SOC_ARC_EMSDP bool "Synopsys ARC EM Software Development Platform" select ARC + select HAS_SPI_DW if SPI From 60430e5481d016bd0a1c651f93d3d22c2a5ab35d Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 10 Mar 2023 10:54:08 +0000 Subject: [PATCH 0096/1906] tests: lwm2m: fix test identifier Fix identifier and remove extra lib string. Signed-off-by: Anas Nashif --- tests/net/lib/lwm2m/lwm2m_engine/testcase.yaml | 2 +- tests/net/lib/lwm2m/lwm2m_rd_client/testcase.yaml | 4 ++-- tests/net/lib/lwm2m/lwm2m_registry/testcase.yaml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/net/lib/lwm2m/lwm2m_engine/testcase.yaml b/tests/net/lib/lwm2m/lwm2m_engine/testcase.yaml index 2dafedeae790..b661a02b5c28 100644 --- a/tests/net/lib/lwm2m/lwm2m_engine/testcase.yaml +++ b/tests/net/lib/lwm2m/lwm2m_engine/testcase.yaml @@ -1,6 +1,6 @@ common: depends_on: netif tests: - subsys.net.lib.lwm2m.lwm2m_engine: + net.lwm2m.lwm2m_engine: platform_allow: native_posix tags: lwm2m net diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/testcase.yaml b/tests/net/lib/lwm2m/lwm2m_rd_client/testcase.yaml index 385bea40011f..3cd913518d31 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/testcase.yaml +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/testcase.yaml @@ -7,7 +7,7 @@ common: - qemu_x86 tests: - subsys.net.lib.lwm2m_rd_client: + net.lwm2m.lwm2m_rd_client: extra_args: EXTRA_CFLAGS="" - subsys.net.lib.lwm2m_rd_client_dtls: + net.lwm2m.lwm2m_rd_client_dtls: extra_args: EXTRA_CFLAGS=-DCONFIG_LWM2M_DTLS_SUPPORT diff --git a/tests/net/lib/lwm2m/lwm2m_registry/testcase.yaml b/tests/net/lib/lwm2m/lwm2m_registry/testcase.yaml index 5b83daa66586..3d9f22048419 100644 --- a/tests/net/lib/lwm2m/lwm2m_registry/testcase.yaml +++ b/tests/net/lib/lwm2m/lwm2m_registry/testcase.yaml @@ -1,6 +1,6 @@ common: depends_on: netif tests: - subsys.net.lib.lwm2m.lwm2m_registry: + net.lwm2m.lwm2m_registry: tags: lwm2m net filter: TOOLCHAIN_HAS_NEWLIB == 1 From 9bb3ff7c467a9527ae3414a41b39d90f5776d19f Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 10 Mar 2023 11:02:19 +0000 Subject: [PATCH 0097/1906] tests: emul: remove subsys from test identifer Component name should not be subsys. Signed-off-by: Anas Nashif --- tests/subsys/emul/testcase.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/subsys/emul/testcase.yaml b/tests/subsys/emul/testcase.yaml index 0238aeb25024..94c2b906f8b6 100644 --- a/tests/subsys/emul/testcase.yaml +++ b/tests/subsys/emul/testcase.yaml @@ -1,4 +1,4 @@ tests: - subsys.emul: - tags: devicetree + emul.emul: + tags: emul platform_allow: native_posix From 70745ae79d8abf3ec5b39b01ebc896ff564a639c Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 10 Mar 2023 11:02:29 +0000 Subject: [PATCH 0098/1906] tests: input: remove subsys from test identifer Component name should not be subsys. Signed-off-by: Anas Nashif --- tests/subsys/input/api/testcase.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/subsys/input/api/testcase.yaml b/tests/subsys/input/api/testcase.yaml index a553469d656f..f92bf450946c 100644 --- a/tests/subsys/input/api/testcase.yaml +++ b/tests/subsys/input/api/testcase.yaml @@ -1,14 +1,14 @@ # SPDX-License-Identifier: Apache-2.0 tests: - subsys.input.api.thread: + input.api.thread: tags: input integration_platforms: - native_posix extra_configs: - CONFIG_INPUT_MODE_THREAD=y - CONFIG_INPUT_THREAD_STACK_SIZE=1024 - subsys.input.api.synchronous: + input.api.synchronous: tags: input integration_platforms: - native_posix From 24cb002588cab8a75d687fc915bf7719cd0b11fd Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 10 Mar 2023 11:02:39 +0000 Subject: [PATCH 0099/1906] tests: rtio: remove subsys from test identifer Component name should not be subsys. Signed-off-by: Anas Nashif --- tests/subsys/rtio/rtio_api/testcase.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/subsys/rtio/rtio_api/testcase.yaml b/tests/subsys/rtio/rtio_api/testcase.yaml index a07f0fb023e2..166dafe1cbb7 100644 --- a/tests/subsys/rtio/rtio_api/testcase.yaml +++ b/tests/subsys/rtio/rtio_api/testcase.yaml @@ -4,20 +4,20 @@ common: - arch - simulation tests: - subsys.rtio.api: + rtio.api: filter: not CONFIG_ARCH_HAS_USERSPACE tags: rtio - subsys.rtio.api.submit_sem: + rtio.api.submit_sem: filter: not CONFIG_ARCH_HAS_USERSPACE tags: rtio extra_configs: - CONFIG_RTIO_SUBMIT_SEM=y - subsys.rtio.api.userspace: + rtio.api.userspace: filter: CONFIG_ARCH_HAS_USERSPACE extra_configs: - CONFIG_USERSPACE=y tags: rtio userspace - subsys.rtio.api.userspace.submit_sem: + rtio.api.userspace.submit_sem: filter: CONFIG_ARCH_HAS_USERSPACE extra_configs: - CONFIG_USERSPACE=y From 1545f9ba7f33195ca7561ac733658078fe56c3da Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 10 Mar 2023 11:02:48 +0000 Subject: [PATCH 0100/1906] tests: sd: remove subsys from test identifer Component name should not be subsys. Signed-off-by: Anas Nashif --- tests/subsys/sd/mmc/testcase.yaml | 2 +- tests/subsys/sd/sdmmc/testcase.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/subsys/sd/mmc/testcase.yaml b/tests/subsys/sd/mmc/testcase.yaml index 27863b4d5abf..c07cb9c98563 100644 --- a/tests/subsys/sd/mmc/testcase.yaml +++ b/tests/subsys/sd/mmc/testcase.yaml @@ -2,7 +2,7 @@ common: depends_on: sdhc tags: drivers sdhc tests: - subsys.sd.mmc: + sd.mmc: harness: ztest filter: dt_compat_enabled("zephyr,mmc-disk") tags: sdhc diff --git a/tests/subsys/sd/sdmmc/testcase.yaml b/tests/subsys/sd/sdmmc/testcase.yaml index fe6d4dd61956..dcab67aa8bde 100644 --- a/tests/subsys/sd/sdmmc/testcase.yaml +++ b/tests/subsys/sd/sdmmc/testcase.yaml @@ -2,7 +2,7 @@ common: depends_on: sdhc tags: drivers sdhc tests: - subsys.sd.sdmmc: + sd.sdmmc: harness: ztest harness_config: fixture: fixture_sdhc From ed2c25effccc55e459e2b96f389d9b1a177daf7d Mon Sep 17 00:00:00 2001 From: Rainer Paat Date: Sun, 3 Jul 2022 13:54:07 +0300 Subject: [PATCH 0101/1906] drivers: counter: MCP7940N: initialization fix This PR fixes MCP7940N initialization failure on Sunday if external battery is used to keep the RTC running over the MCU or Zephyr OS restarts. Signed-off-by: Rainer Paat --- drivers/counter/rtc_mcp7940n.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/counter/rtc_mcp7940n.c b/drivers/counter/rtc_mcp7940n.c index f44f0a7219d5..9ffa2de9152a 100644 --- a/drivers/counter/rtc_mcp7940n.c +++ b/drivers/counter/rtc_mcp7940n.c @@ -306,9 +306,7 @@ static int set_day_of_week(const struct device *dev, time_t *unix_time) struct tm time_buffer = { 0 }; int rc = 0; - gmtime_r(unix_time, &time_buffer); - - if (time_buffer.tm_wday != 0) { + if (gmtime_r(unix_time, &time_buffer) != NULL) { data->registers.rtc_weekday.weekday = time_buffer.tm_wday; rc = write_register(dev, REG_RTC_WDAY, *((uint8_t *)(&data->registers.rtc_weekday))); From f75c5b8c3b0776e28d94c3cf8d8effa3e8f6eeb7 Mon Sep 17 00:00:00 2001 From: Manojkumar Subramaniam Date: Wed, 8 Mar 2023 18:21:16 +0000 Subject: [PATCH 0102/1906] drivers: gpio: sifive: Update to use the available common IRQ API and remove obsolete code. Fixes issue: #20338 Signed-off-by: Manojkumar Subramaniam --- drivers/gpio/gpio_sifive.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/drivers/gpio/gpio_sifive.c b/drivers/gpio/gpio_sifive.c index c4a133d92966..a3b5292fe142 100644 --- a/drivers/gpio/gpio_sifive.c +++ b/drivers/gpio/gpio_sifive.c @@ -67,27 +67,11 @@ struct gpio_sifive_data { #define DEV_GPIO_DATA(dev) \ ((struct gpio_sifive_data *)(dev)->data) -/* _irq_level and _level2_irq are copied from - * soc/riscv/riscv-privileged/common/soc_common_irq.c - * Ideally this kind of thing should be made available in include/irq.h or - * somewhere similar since the multi-level IRQ format is generic to - Zephyr, and then both this copy and the one in riscv-privileged - * be removed for the shared implementation - */ -static inline unsigned int _irq_level(unsigned int irq) -{ - return ((irq >> 8) && 0xff) == 0U ? 1 : 2; -} - -static inline unsigned int _level2_irq(unsigned int irq) -{ - return (irq >> 8) - 1; -} /* Given gpio_irq_base and the pin number, return the IRQ number for the pin */ static inline unsigned int gpio_sifive_pin_irq(unsigned int base_irq, int pin) { - unsigned int level = _irq_level(base_irq); + unsigned int level = irq_get_level(base_irq); unsigned int pin_irq = 0; if (level == 1) { @@ -104,10 +88,10 @@ static inline unsigned int gpio_sifive_pin_irq(unsigned int base_irq, int pin) */ static inline int gpio_sifive_plic_to_pin(unsigned int base_irq, int plic_irq) { - unsigned int level = _irq_level(base_irq); + unsigned int level = irq_get_level(base_irq); if (level == 2) { - base_irq = _level2_irq(base_irq); + base_irq = irq_from_level_2(base_irq); } return (plic_irq - base_irq); From 2535a46995278e151fd048bf674ab6ad19426a78 Mon Sep 17 00:00:00 2001 From: Vaishnav Achath Date: Wed, 1 Feb 2023 21:03:08 +0530 Subject: [PATCH 0103/1906] drivers: ieee802154: cc13xx_cc26xx_subg: Skip CRC for invalid packets During extended testing, rx_done() callback was seen to be invoked with zero-length packets.When RAW_MODE is enabled, CRC is being appended to these packets thus making downstream consumers think the packet is valid. Root cause of the callback being invoked with zero-length packet is unknown, but appending CRC to these packets is incorrect, thus fix it. Also fix a minor error which causes build failure when CONFIG_NET_L2_IEEE802154_SUB_GHZ is not defined. Signed-off-by: Vaishnav Achath --- drivers/ieee802154/ieee802154_cc13xx_cc26xx_subg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ieee802154/ieee802154_cc13xx_cc26xx_subg.c b/drivers/ieee802154/ieee802154_cc13xx_cc26xx_subg.c index 1e550cfe02c6..3c6d4aa25dd7 100644 --- a/drivers/ieee802154/ieee802154_cc13xx_cc26xx_subg.c +++ b/drivers/ieee802154/ieee802154_cc13xx_cc26xx_subg.c @@ -593,7 +593,7 @@ static void ieee802154_cc13xx_cc26xx_subg_rx_done( status = drv_data->rx_data[i][len--]; rssi = drv_data->rx_data[i][len--]; - if (IS_ENABLED(CONFIG_IEEE802154_RAW_MODE)) { + if (IS_ENABLED(CONFIG_IEEE802154_RAW_MODE) && len > 0) { /* append CRC-16/CCITT */ uint16_t crc = 0; @@ -906,7 +906,7 @@ NET_DEVICE_DT_INST_DEFINE(0, ieee802154_cc13xx_cc26xx_subg_init, NULL, IEEE802154_L2, NET_L2_GET_CTX_TYPE(IEEE802154_L2), IEEE802154_MTU); #else -DEVICE_DT_INST_DEFINE(0 ieee802154_cc13xx_cc26xx_subg_init, NULL, +DEVICE_DT_INST_DEFINE(0, ieee802154_cc13xx_cc26xx_subg_init, NULL, &ieee802154_cc13xx_cc26xx_subg_data, NULL, POST_KERNEL, CONFIG_IEEE802154_CC13XX_CC26XX_SUB_GHZ_INIT_PRIO, &ieee802154_cc13xx_cc26xx_subg_radio_api); From c6da2ebe7736660179cd7f0df0bf781474f29736 Mon Sep 17 00:00:00 2001 From: Vaishnav Achath Date: Wed, 1 Feb 2023 21:21:49 +0530 Subject: [PATCH 0104/1906] drivers: ieee802154: cc13xx_cc26xx: Allow both radios to coexist Currently the 2.4G radio driver for CC1352 has few implementations which prevents both the radios to be used in a single build, thus preventing applications to have different builds to switch the RF bands even though the hardware supports dual bands simultaneously. The following updates are made: * Remove RF patches from stack. * Implement if_stop() to stop the interface and yield the interface. * Use RF_runCmd() instead of RF_runImmediateCmd() so that two RF handles can work simultaneously. All the updates are similar to the more recent cc13xx subg driver which implements all these recommended practices already. Signed-off-by: Vaishnav Achath --- drivers/ieee802154/ieee802154_cc13xx_cc26xx.c | 72 ++++++++++++++++--- 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/drivers/ieee802154/ieee802154_cc13xx_cc26xx.c b/drivers/ieee802154/ieee802154_cc13xx_cc26xx.c index a7b1b915c4dc..7f0b9d9c7ed7 100644 --- a/drivers/ieee802154/ieee802154_cc13xx_cc26xx.c +++ b/drivers/ieee802154/ieee802154_cc13xx_cc26xx.c @@ -149,12 +149,32 @@ static int ieee802154_cc13xx_cc26xx_cca(const struct device *dev) } } +static inline int ieee802154_cc13xx_cc26xx_channel_to_frequency( + uint16_t channel, uint16_t *frequency, uint16_t *fractFreq) +{ + __ASSERT_NO_MSG(frequency != NULL); + __ASSERT_NO_MSG(fractFreq != NULL); + + if (channel >= IEEE802154_2_4_GHZ_CHANNEL_MIN + && channel <= IEEE802154_2_4_GHZ_CHANNEL_MAX) { + *frequency = 2405 + 5 * (channel - IEEE802154_2_4_GHZ_CHANNEL_MIN); + *fractFreq = 0; + } else { + *frequency = 0; + *fractFreq = 0; + return -EINVAL; + } + + return 0; +} + static int ieee802154_cc13xx_cc26xx_set_channel(const struct device *dev, uint16_t channel) { int r; - RF_Stat status; RF_CmdHandle cmd_handle; + RF_EventMask reason; + uint16_t freq, fract; struct ieee802154_cc13xx_cc26xx_data *drv_data = dev->data; /* TODO Support sub-GHz for CC13xx */ @@ -162,6 +182,12 @@ static int ieee802154_cc13xx_cc26xx_set_channel(const struct device *dev, return -EINVAL; } + r = ieee802154_cc13xx_cc26xx_channel_to_frequency( + channel, &freq, &fract); + if (r < 0) { + return -EINVAL; + } + /* Abort FG and BG processes */ if (ieee802154_cc13xx_cc26xx_stop(dev) < 0) { r = -EIO; @@ -171,11 +197,14 @@ static int ieee802154_cc13xx_cc26xx_set_channel(const struct device *dev, /* Block TX while changing channel */ k_mutex_lock(&drv_data->tx_mutex, K_FOREVER); - /* Set all RX entries to empty */ - status = RF_runImmediateCmd(drv_data->rf_handle, - (uint32_t *)&drv_data->cmd_clear_rx); - if (status != RF_StatCmdDoneSuccess && status != RF_StatSuccess) { - LOG_ERR("Failed to clear RX queue (%d)", status); + /* Set the frequency */ + drv_data->cmd_fs.status = IDLE; + drv_data->cmd_fs.frequency = freq; + drv_data->cmd_fs.fractFreq = fract; + reason = RF_runCmd(drv_data->rf_handle, (RF_Op *)&drv_data->cmd_fs, + RF_PriorityNormal, NULL, 0); + if (reason != RF_EventLastCmdDone) { + LOG_ERR("Failed to set frequency: 0x%" PRIx64, reason); r = -EIO; goto out; } @@ -463,6 +492,25 @@ static int ieee802154_cc13xx_cc26xx_stop(const struct device *dev) return 0; } +/** + * Stops the sub-GHz interface and yields the radio (tells RF module to power + * down). + */ +static int ieee802154_cc13xx_cc26xx_stop_if(const struct device *dev) +{ + struct ieee802154_cc13xx_cc26xx_data *drv_data = dev->data; + int ret; + + ret = ieee802154_cc13xx_cc26xx_stop(dev); + if (ret < 0) { + return ret; + } + + /* power down radio */ + RF_yield(drv_data->rf_handle); + return 0; +} + static int ieee802154_cc13xx_cc26xx_configure(const struct device *dev, enum ieee802154_config_type type, @@ -531,18 +579,20 @@ static struct ieee802154_radio_api ieee802154_cc13xx_cc26xx_radio_api = { .set_txpower = ieee802154_cc13xx_cc26xx_set_txpower, .tx = ieee802154_cc13xx_cc26xx_tx, .start = ieee802154_cc13xx_cc26xx_start, - .stop = ieee802154_cc13xx_cc26xx_stop, + .stop = ieee802154_cc13xx_cc26xx_stop_if, .configure = ieee802154_cc13xx_cc26xx_configure, }; +/** RF patches to use (note: RF core keeps a pointer to this, so no stack). */ +static RF_Mode rf_mode = { + .rfMode = RF_MODE_MULTIPLE, + .cpePatchFxn = &rf_patch_cpe_multi_protocol, +}; + static int ieee802154_cc13xx_cc26xx_init(const struct device *dev) { RF_Params rf_params; RF_EventMask reason; - RF_Mode rf_mode = { - .rfMode = RF_MODE_MULTIPLE, - .cpePatchFxn = &rf_patch_cpe_multi_protocol, - }; struct ieee802154_cc13xx_cc26xx_data *drv_data = dev->data; /* Initialize driver data */ From 0368642d54eaeda0853fb33b4ca27828b12e4aa9 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 10 Mar 2023 12:59:56 +0100 Subject: [PATCH 0105/1906] boards: arm: lpcxpress55s36: list CAN as a supported feature List CAN as a supported feature for the NXP LPCXpresso 55S36 Development Board. Signed-off-by: Henrik Brix Andersen --- boards/arm/lpcxpresso55s36/lpcxpresso55s36.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/boards/arm/lpcxpresso55s36/lpcxpresso55s36.yaml b/boards/arm/lpcxpresso55s36/lpcxpresso55s36.yaml index f66d0fdb4695..823e4d3aeab0 100644 --- a/boards/arm/lpcxpresso55s36/lpcxpresso55s36.yaml +++ b/boards/arm/lpcxpresso55s36/lpcxpresso55s36.yaml @@ -15,5 +15,6 @@ toolchain: - gnuarmemb - xtools supported: + - can - gpio - pwm From d6a83d32b4ff717e5cbe46cb75a822d3a3de3599 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 10 Mar 2023 13:02:31 +0100 Subject: [PATCH 0106/1906] boards: arm: lpcxpresso55s36: fix devicetree status spelling Change the can0 devicetree node status from "ok" to "okay" to match recommendations. Signed-off-by: Henrik Brix Andersen --- boards/arm/lpcxpresso55s36/lpcxpresso55s36.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/arm/lpcxpresso55s36/lpcxpresso55s36.dts b/boards/arm/lpcxpresso55s36/lpcxpresso55s36.dts index 1e1b90583652..4a9a1dada16a 100644 --- a/boards/arm/lpcxpresso55s36/lpcxpresso55s36.dts +++ b/boards/arm/lpcxpresso55s36/lpcxpresso55s36.dts @@ -127,7 +127,7 @@ bus-speed-data = <1000000>; pinctrl-0 = <&pinmux_mcan_can0>; pinctrl-names = "default"; - status = "ok"; + status = "okay"; }; &flash0 { From 0d7097292b2b011dd9eef481febaa7fb3986ea66 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 10 Mar 2023 13:31:35 +0100 Subject: [PATCH 0107/1906] boards: arm: lpcxpresso55s36: add CAN transceiver The NXP LPCXpresso55S36 Development Board is equipped with a NXP TJA1044GT CAN transceiver with a maximum bitrate of 5Mbit/s. Signed-off-by: Henrik Brix Andersen --- boards/arm/lpcxpresso55s36/lpcxpresso55s36.dts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/boards/arm/lpcxpresso55s36/lpcxpresso55s36.dts b/boards/arm/lpcxpresso55s36/lpcxpresso55s36.dts index 4a9a1dada16a..cf67e65ebf4f 100644 --- a/boards/arm/lpcxpresso55s36/lpcxpresso55s36.dts +++ b/boards/arm/lpcxpresso55s36/lpcxpresso55s36.dts @@ -128,6 +128,10 @@ pinctrl-0 = <&pinmux_mcan_can0>; pinctrl-names = "default"; status = "okay"; + + can-transceiver { + max-bitrate = <5000000>; + }; }; &flash0 { From 13f9fd2016f4e2f86b0de36cd3782a3bb72e65cd Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 10 Mar 2023 18:09:01 +0100 Subject: [PATCH 0108/1906] boards: arm: lpcxpresso55s36: document the CAN IOs used List the IOs used for the CAN RXD/TXD lines in the board documentation. Signed-off-by: Henrik Brix Andersen --- boards/arm/lpcxpresso55s36/doc/index.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/boards/arm/lpcxpresso55s36/doc/index.rst b/boards/arm/lpcxpresso55s36/doc/index.rst index 01bade69d253..8e9e358fb07c 100644 --- a/boards/arm/lpcxpresso55s36/doc/index.rst +++ b/boards/arm/lpcxpresso55s36/doc/index.rst @@ -133,7 +133,10 @@ the functionality of a pin. +---------+-----------------+----------------------------+ | PIO0_31 | FLEXPPWM1_PWM2_B| pwm | +---------+-----------------+----------------------------+ - +| PIO1_2 | CAN0_TXD | CAN TX | ++---------+-----------------+----------------------------+ +| PIO1_3 | CAN0_RXD | CAN RX | ++---------+-----------------+----------------------------+ System Clock ============ From 109e03eb4e46d5208ae3157d1d66ca933d97425a Mon Sep 17 00:00:00 2001 From: Declan Snyder Date: Thu, 9 Mar 2023 09:51:17 -0600 Subject: [PATCH 0109/1906] drivers: memc: fix flexspi init priorities Fix flexspi memc drivers init priorities Signed-off-by: Declan Snyder --- drivers/memc/memc_mcux_flexspi_aps6408l.c | 2 +- drivers/memc/memc_mcux_flexspi_s27ks0641.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/memc/memc_mcux_flexspi_aps6408l.c b/drivers/memc/memc_mcux_flexspi_aps6408l.c index ea9ca8c8360a..0c295221a105 100644 --- a/drivers/memc/memc_mcux_flexspi_aps6408l.c +++ b/drivers/memc/memc_mcux_flexspi_aps6408l.c @@ -323,7 +323,7 @@ static int memc_flexspi_aps6408l_init(const struct device *dev) &memc_flexspi_aps6408l_data_##n, \ &memc_flexspi_aps6408l_config_##n, \ POST_KERNEL, \ - CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ + CONFIG_MEMC_INIT_PRIORITY, \ NULL); DT_INST_FOREACH_STATUS_OKAY(MEMC_FLEXSPI_APS6408L) diff --git a/drivers/memc/memc_mcux_flexspi_s27ks0641.c b/drivers/memc/memc_mcux_flexspi_s27ks0641.c index e78de6a1b230..ee7431c92013 100644 --- a/drivers/memc/memc_mcux_flexspi_s27ks0641.c +++ b/drivers/memc/memc_mcux_flexspi_s27ks0641.c @@ -197,7 +197,7 @@ static int memc_flexspi_s27ks0641_init(const struct device *dev) &memc_flexspi_s27ks0641_data_##n, \ &memc_flexspi_s27ks0641_config_##n, \ POST_KERNEL, \ - CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ + CONFIG_MEMC_INIT_PRIORITY, \ NULL); DT_INST_FOREACH_STATUS_OKAY(MEMC_FLEXSPI_S27KS0641) From aced3bb2ac1e2e69a35f74edb723a08f57f33aab Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Fri, 10 Mar 2023 09:08:36 +0100 Subject: [PATCH 0110/1906] drivers: i2c: gpio: cast io context to void* i2c_bitbang_init takes a context as void *, so discarding const qualifier of the driver's config. Explicitely cast to void * to fix the problem. Signed-off-by: Gerard Marull-Paretas --- drivers/i2c/i2c_gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/i2c_gpio.c b/drivers/i2c/i2c_gpio.c index b1316693262c..c7d8f4676612 100644 --- a/drivers/i2c/i2c_gpio.c +++ b/drivers/i2c/i2c_gpio.c @@ -141,7 +141,7 @@ static int i2c_gpio_init(const struct device *dev) return err; } - i2c_bitbang_init(&context->bitbang, &io_fns, config); + i2c_bitbang_init(&context->bitbang, &io_fns, (void *)config); bitrate_cfg = i2c_map_dt_bitrate(config->bitrate); err = i2c_bitbang_configure(&context->bitbang, From 0f2b17b5e1df9c87696481a7f5613353311cf67a Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Tue, 7 Mar 2023 10:53:51 +0100 Subject: [PATCH 0111/1906] drivers: can: shell: add support for CAN-FD frame format filters Add shell support for adding filters for CAN-FD format frames. Signed-off-by: Henrik Brix Andersen --- drivers/can/can_shell.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/can/can_shell.c b/drivers/can/can_shell.c index 6d59f560306b..f690b3d8f498 100644 --- a/drivers/can/can_shell.c +++ b/drivers/can/can_shell.c @@ -652,6 +652,9 @@ static int cmd_can_filter_add(const struct shell *sh, size_t argc, char **argv) filter.flags |= CAN_FILTER_IDE; max_id = CAN_MAX_EXT_ID; argidx++; + } else if (strcmp(argv[argidx], "-f") == 0) { + filter.flags |= CAN_FILTER_FDF; + argidx++; } else if (strcmp(argv[argidx], "-r") == 0) { filter.flags |= CAN_FILTER_RTR; argidx++; @@ -715,13 +718,14 @@ static int cmd_can_filter_add(const struct shell *sh, size_t argc, char **argv) } shell_print(sh, "adding filter with %s (%d-bit) CAN ID 0x%0*x, " - "CAN ID mask 0x%0*x, data frames %d, RTR frames %d", + "CAN ID mask 0x%0*x, data frames %d, RTR frames %d, CAN-FD frames %d", (filter.flags & CAN_FILTER_IDE) != 0 ? "extended" : "standard", (filter.flags & CAN_FILTER_IDE) != 0 ? 29 : 11, (filter.flags & CAN_FILTER_IDE) != 0 ? 8 : 3, filter.id, (filter.flags & CAN_FILTER_IDE) != 0 ? 8 : 3, filter.mask, (filter.flags & CAN_FILTER_DATA) != 0 ? 1 : 0, - (filter.flags & CAN_FILTER_RTR) != 0 ? 1 : 0); + (filter.flags & CAN_FILTER_RTR) != 0 ? 1 : 0, + (filter.flags & CAN_FILTER_FDF) != 0 ? 1 : 0); err = can_add_rx_filter_msgq(dev, &can_shell_rx_msgq, &filter); if (err < 0) { @@ -839,11 +843,12 @@ SHELL_DYNAMIC_CMD_CREATE(dsub_can_device_name_mode, cmd_can_device_name_mode); SHELL_STATIC_SUBCMD_SET_CREATE(sub_can_filter_cmds, SHELL_CMD_ARG(add, &dsub_can_device_name, "Add rx filter\n" - "Usage: can filter add [-e] [-r] [-R] [CAN ID mask]\n" + "Usage: can filter add [-e] [-f] [-r] [-R] [CAN ID mask]\n" "-e use extended (29-bit) CAN ID/CAN ID mask\n" + "-f match CAN-FD format frames\n" "-r also match Remote Transmission Request (RTR) frames\n" "-R only match Remote Transmission Request (RTR) frames", - cmd_can_filter_add, 3, 4), + cmd_can_filter_add, 3, 5), SHELL_CMD_ARG(remove, &dsub_can_device_name, "Remove rx filter\n" "Usage: can filter remove ", From 9d5c21d5800370a67f9441f6c20a48a533f45529 Mon Sep 17 00:00:00 2001 From: Iuliana Prodan Date: Wed, 8 Mar 2023 15:39:27 +0200 Subject: [PATCH 0112/1906] dts: xtensa: nxp: remove unused include Remove unused include file from dtsi. Signed-off-by: Iuliana Prodan --- dts/xtensa/nxp/nxp_imx8.dtsi | 1 - dts/xtensa/nxp/nxp_imx8m.dtsi | 1 - 2 files changed, 2 deletions(-) diff --git a/dts/xtensa/nxp/nxp_imx8.dtsi b/dts/xtensa/nxp/nxp_imx8.dtsi index 10d314c36e50..06b38e1bbee1 100644 --- a/dts/xtensa/nxp/nxp_imx8.dtsi +++ b/dts/xtensa/nxp/nxp_imx8.dtsi @@ -5,7 +5,6 @@ */ #include -#include #include / { diff --git a/dts/xtensa/nxp/nxp_imx8m.dtsi b/dts/xtensa/nxp/nxp_imx8m.dtsi index 10d314c36e50..06b38e1bbee1 100644 --- a/dts/xtensa/nxp/nxp_imx8m.dtsi +++ b/dts/xtensa/nxp/nxp_imx8m.dtsi @@ -5,7 +5,6 @@ */ #include -#include #include / { From a9349fe74d6caf22138e213ed832ffaa1b68e522 Mon Sep 17 00:00:00 2001 From: Julien Vermillard Date: Fri, 10 Mar 2023 14:56:52 +0100 Subject: [PATCH 0113/1906] net: lwm2m: Typo in LWM2M_IPSO_TIMER description Changed description to "IPSO Timer Support" in place of "Light Control Support" Signed-off-by: Julien Vermillard --- subsys/net/lib/lwm2m/Kconfig.ipso | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/net/lib/lwm2m/Kconfig.ipso b/subsys/net/lib/lwm2m/Kconfig.ipso index 9a2b5ea49980..de85a64871af 100644 --- a/subsys/net/lib/lwm2m/Kconfig.ipso +++ b/subsys/net/lib/lwm2m/Kconfig.ipso @@ -215,7 +215,7 @@ config LWM2M_IPSO_BUZZER_VERSION_1_1 endchoice config LWM2M_IPSO_TIMER - bool "IPSO Light Control Support" + bool "IPSO Timer Support" help This Object is used to time events / actions From 196defd953a7b551f997706d503f5ec834533064 Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Fri, 10 Mar 2023 07:52:15 -0800 Subject: [PATCH 0114/1906] doc: Clean up documentation for cycle counter API Discussion in #55658 showed that our API docs for the hardware cycle counter layer were a little lacking. Technically it's owned by the architecture layer, but the arch docs were unhelpful. And the arch layers uniformly farm it out to an API in the timer drivers that was never documented at all. Clean things up. Signed-off-by: Andy Ross --- include/zephyr/drivers/timer/system_timer.h | 31 +++++++++++++++++++++ include/zephyr/sys/arch_interface.h | 22 +++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/include/zephyr/drivers/timer/system_timer.h b/include/zephyr/drivers/timer/system_timer.h index 02be3f8e62b4..12d7a3f150f0 100644 --- a/include/zephyr/drivers/timer/system_timer.h +++ b/include/zephyr/drivers/timer/system_timer.h @@ -118,6 +118,37 @@ extern uint32_t sys_clock_elapsed(void); */ extern void sys_clock_disable(void); +/** + * @brief Hardware cycle counter + * + * Timer drivers are generally responsible for the system cycle + * counter as well as the tick announcements. This function is + * generally called out of the architecture layer (@see + * arch_k_cycle_get_32()) to implement the cycle counter, though the + * user-facing API is owned by the architecture, not the driver. The + * rate must match CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC. + * + * @return The current cycle time. This should count up monotonically + * through the full 32 bit space, wrapping at 0xffffffff. Hardware + * with fewer bits of precision in the timer is expected to synthesize + * a 32 bit count. + */ +uint32_t sys_clock_cycle_get_32(void); + +/** + * @brief 64 bit hardware cycle counter + * + * As for sys_clock_cycle_get_32(), but with a 64 bit return value. + * Not all hardware has 64 bit counters. This function need be + * implemented only if CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER is set. + * + * @return The current cycle time. This should count up monotonically + * through the full 64 bit space, wrapping at 2^64-1. Hardware with + * fewer bits of precision in the timer is generally not expected to + * implement this API. + */ +uint64_t sys_clock_cycle_get_64(void); + /** * @} */ diff --git a/include/zephyr/sys/arch_interface.h b/include/zephyr/sys/arch_interface.h index 3b9c0ef4a42c..c9eee0d0b4b8 100644 --- a/include/zephyr/sys/arch_interface.h +++ b/include/zephyr/sys/arch_interface.h @@ -52,16 +52,32 @@ typedef void (*k_thread_entry_t)(void *p1, void *p2, void *p3); */ /** - * Obtain the current cycle count, in units that are hardware-specific + * Obtain the current cycle count, in units specified by + * CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC. While this is historically + * specified as part of the architecture API, in practice virtually + * all platforms forward it to the sys_clock_cycle_get_32() API + * provided by the timer driver. * * @see k_cycle_get_32() + * + * @return The current cycle time. This should count up monotonically + * through the full 32 bit space, wrapping at 0xffffffff. Hardware + * with fewer bits of precision in the timer is expected to synthesize + * a 32 bit count. */ static inline uint32_t arch_k_cycle_get_32(void); /** - * Obtain the current cycle count, in units that are hardware-specific + * As for arch_k_cycle_get_32(), but with a 64 bit return value. Not + * all timer hardware has a 64 bit timer, this needs to be implemented + * only if CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER is set. + * + * @see arch_k_cycle_get_32() * - * @see k_cycle_get_64() + * @return The current cycle time. This should count up monotonically + * through the full 64 bit space, wrapping at 2^64-1. Hardware with + * fewer bits of precision in the timer is generally not expected to + * implement this API. */ static inline uint64_t arch_k_cycle_get_64(void); From 332f326ab18b41d52f7b0f6ba0e49341d48fd52e Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 10 Mar 2023 13:43:11 +0100 Subject: [PATCH 0115/1906] tests: drivers: can: timing: remove superfluous timing test Remove test for attempting to set an arbitration bitrate of 8000001 bit/s. This test belongs in the data phase timing test, where it already present as well. Signed-off-by: Henrik Brix Andersen --- tests/drivers/can/timing/src/main.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/drivers/can/timing/src/main.c b/tests/drivers/can/timing/src/main.c index 61dae746322b..09b548a7faf5 100644 --- a/tests/drivers/can/timing/src/main.c +++ b/tests/drivers/can/timing/src/main.c @@ -53,13 +53,8 @@ static const struct can_timing_test can_timing_tests[] = { { 125000, 800, false }, /** Valid bitrate, invalid sample point. */ { 125000, 1000, true }, -#ifdef CONFIG_CAN_FD_MODE - /** Invalid CAN-FD bitrate, valid sample point. */ - { 8000000 + 1, 750, true }, -#else /* CONFIG_CAN_FD_MODE */ - /** Invalid classical bitrate, valid sample point. */ + /** Invalid classic/arbitration bitrate, valid sample point. */ { 1000000 + 1, 750, true }, -#endif /* CONFIG_CAN_FD_MODE */ }; /** From 4156e10860b6032a1d330d2a267e8a1c746cd1f7 Mon Sep 17 00:00:00 2001 From: Emilio Benavente Date: Tue, 28 Feb 2023 13:09:43 -0600 Subject: [PATCH 0116/1906] tests: drivers: pwm: pwm_api: Missing sleep statement If a board runs this test at a high frequency, they will see a noticable skip of a test due to a missing k_sleep function that allows the pwm time to display the requested pwm signal. Signed-off-by: Emilio Benavente --- tests/drivers/pwm/pwm_api/src/test_pwm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/drivers/pwm/pwm_api/src/test_pwm.c b/tests/drivers/pwm/pwm_api/src/test_pwm.c index 8039caa6ea3e..430061245599 100644 --- a/tests/drivers/pwm/pwm_api/src/test_pwm.c +++ b/tests/drivers/pwm/pwm_api/src/test_pwm.c @@ -159,4 +159,5 @@ ZTEST_USER(pwm_basic, test_pwm_cycle) /* Period : Pulse (64000 : 0), unit (cycle). Voltage : 0V */ zassert_true(test_task(DEFAULT_PWM_PORT, DEFAULT_PERIOD_CYCLE, 0, UNIT_CYCLES) == TC_PASS, NULL); + k_sleep(K_MSEC(1000)); } From 5081f6aa28edc818a47dda3868b169132496ca99 Mon Sep 17 00:00:00 2001 From: Emilio Benavente Date: Tue, 28 Feb 2023 13:11:51 -0600 Subject: [PATCH 0117/1906] drivers: pwm: pwm_mcux_sctimer: duty cycle fix This is a fix for a driver bug that assumes a user will want a new pwm channel for a new pwm signal if they decide to change the period length of the pwm. In some cases, this creates a noticable change of duty cycle accuracy. Signed-off-by: Emilio Benavente --- drivers/pwm/pwm_mcux_sctimer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm_mcux_sctimer.c b/drivers/pwm/pwm_mcux_sctimer.c index 73a61b21a419..1d78e76b00c9 100644 --- a/drivers/pwm/pwm_mcux_sctimer.c +++ b/drivers/pwm/pwm_mcux_sctimer.c @@ -76,7 +76,8 @@ static int mcux_sctimer_pwm_set_cycles(const struct device *dev, return 0; } - if (period_cycles != data->period_cycles[channel]) { + if (period_cycles != data->period_cycles[channel] && + duty_cycle != data->channel[channel].dutyCyclePercent) { uint32_t clock_freq; uint32_t pwm_freq; @@ -107,6 +108,7 @@ static int mcux_sctimer_pwm_set_cycles(const struct device *dev, SCTIMER_StartTimer(config->base, kSCTIMER_Counter_U); } else { + data->period_cycles[channel] = period_cycles; SCTIMER_UpdatePwmDutycycle(config->base, channel, duty_cycle, data->event_number[channel]); } From 5027f55a1215aee80a5f31b17de22f5d61c1827b Mon Sep 17 00:00:00 2001 From: Mariusz Poslinski Date: Wed, 8 Mar 2023 09:04:15 +0100 Subject: [PATCH 0118/1906] manifest: openthread upmerge up to commit 1f1a826 Regular OpenThread upmerge. Added new configs: CONFIG_OPENTHREAD_TCP -> OT_TCP CONFIG_OPENTHREAD_DNS_QUERY_UPSTREAM -> OT_DNS_QUERY_UPSTREAM CONFIG_OPENTHREAD_MESH_DIAG -> OT_MESH_DIAG Signed-off-by: Mariusz Poslinski --- modules/openthread/CMakeLists.txt | 18 ++++++++++++++++++ modules/openthread/Kconfig.features | 11 +++++++++++ modules/openthread/Kconfig.thread | 2 +- west.yml | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/modules/openthread/CMakeLists.txt b/modules/openthread/CMakeLists.txt index 981d65a8c5b7..f69d26416f17 100644 --- a/modules/openthread/CMakeLists.txt +++ b/modules/openthread/CMakeLists.txt @@ -184,6 +184,12 @@ else() set(OT_DNS_DSO OFF CACHE BOOL "Enable DNS Stateful Operations (DSO) support" FORCE) endif() +if(CONFIG_OPENTHREAD_DNS_QUERY_UPSTREAM) + set(OT_DNS_QUERY_UPSTREAM ON CACHE BOOL "Enable forwarding DNS queries to upstream" FORCE) +else() + set(OT_DNS_QUERY_UPSTREAM OFF CACHE BOOL "Enable forwarding DNS queries to upstream" FORCE) +endif() + if(CONFIG_OPENTHREAD_DNSSD_SERVER) set(OT_DNSSD_SERVER ON CACHE BOOL "Enable DNS-SD server support" FORCE) else() @@ -286,6 +292,12 @@ else() set(OT_MAC_FILTER OFF CACHE BOOL "Enable MAC filter support" FORCE) endif() +if(CONFIG_OPENTHREAD_MESH_DIAG) + set(OT_MESH_DIAG ON CACHE BOOL "Enable Mesh Diagnostics" FORCE) +else() + set(OT_MESH_DIAG OFF CACHE BOOL "Enable Mesh Diagnostics" FORCE) +endif() + if(CONFIG_OPENTHREAD_MESSAGE_USE_HEAP) set(OT_MESSAGE_USE_HEAP ON CACHE BOOL "Enable heap allocator for message buffers" FORCE) else() @@ -412,6 +424,12 @@ else() set(OT_SRP_SERVER OFF CACHE BOOL "Enable SRP Server support" FORCE) endif() +if(CONFIG_OPENTHREAD_TCP_ENABLE) + set(OT_TCP ON CACHE BOOL "Enable TCP support" FORCE) +else() + set(OT_TCP OFF CACHE BOOL "Enable TCP support" FORCE) +endif() + if(CONFIG_OPENTHREAD_TIME_SYNC) set(OT_TIME_SYNC ON CACHE BOOL "Enable the time synchronization service feature" FORCE) else() diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index 643d731fb4ee..a34ee320d318 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -109,6 +109,11 @@ config OPENTHREAD_DNS_CLIENT config OPENTHREAD_DNS_DSO bool "DNS Stateful Operations (DSO) support" +config OPENTHREAD_DNS_QUERY_UPSTREAM + bool "Forwarding DNS queries to upstream" + help + Enable forwarding DNS queries to platform DNS upstream API + config OPENTHREAD_DNSSD_SERVER bool "DNS-SD server support" @@ -166,6 +171,12 @@ config OPENTHREAD_LOG_LEVEL_DYNAMIC config OPENTHREAD_MAC_FILTER bool "MAC filter support" +config OPENTHREAD_MESH_DIAG + bool "Mesh Diagnostics" + depends on OPENTHREAD_FTD + help + Enable Mesh Diagnostics + config OPENTHREAD_MESSAGE_USE_HEAP bool "Heap allocator for message buffers" diff --git a/modules/openthread/Kconfig.thread b/modules/openthread/Kconfig.thread index b9904369aa8d..30775304599a 100644 --- a/modules/openthread/Kconfig.thread +++ b/modules/openthread/Kconfig.thread @@ -153,7 +153,7 @@ config OPENTHREAD_IP6_MAX_EXT_MCAST_ADDRS default 2 config OPENTHREAD_TCP_ENABLE - bool "TCP" + bool "TCP support" config OPENTHREAD_CLI_TCP_ENABLE bool "TCP in the CLI tool" diff --git a/west.yml b/west.yml index 9338f4ac39d9..5949caca9e0a 100644 --- a/west.yml +++ b/west.yml @@ -203,7 +203,7 @@ manifest: revision: aedcc262f93bbb1b0c2f58026911575729b7465c path: modules/lib/open-amp - name: openthread - revision: 242c7cc7c3a80c985476689b64cdb6d8fbcf5b6d + revision: 1f1a826d1891fc99d14822abc0a1de257e9c6e9b path: modules/lib/openthread - name: picolibc path: modules/lib/picolibc From ee2c367892a161d0a758a739a2e91d5c34c75873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20Rist=20Sk=C3=B8ien?= Date: Thu, 9 Mar 2023 13:57:55 +0100 Subject: [PATCH 0119/1906] boards: nrf5340_audio_dk: Arduino and mcuboot added MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added definitions for Arduino headers and MCUboot button and LED. Signed-off-by: Kristoffer Rist Skøien --- ...rf5340_audio_dk_nrf5340_cpuapp_common.dtsi | 29 +++++++++++++++++++ .../nrf5340_audio_dk_nrf5340_shared.dtsi | 3 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi index 76bc0dde67bf..d45db3438561 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi @@ -25,6 +25,35 @@ }; }; + arduino_header: connector { + compatible = "arduino-header-r3"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <0 0 &gpio0 4 0>, /* A0 */ + <1 0 &gpio0 5 0>, /* A1 */ + <2 0 &gpio0 6 0>, /* A2 */ + <3 0 &gpio0 7 0>, /* A3 */ + <4 0 &gpio0 25 0>, /* A4 */ + <5 0 &gpio0 26 0>, /* A5 */ + <6 0 &gpio1 9 0>, /* D0 */ + <7 0 &gpio1 8 0>, /* D1 */ + <8 0 &gpio0 31 0>, /* D2 */ + <9 0 &gpio1 0 0>, /* D3 */ + <10 0 &gpio1 1 0>, /* D4 */ + <11 0 &gpio1 14 0>, /* D5 */ + <12 0 &gpio1 7 0>, /* D6 */ + <13 0 &gpio1 11 0>, /* D7 */ + <14 0 &gpio1 10 0>, /* D8 */ + <15 0 &gpio1 13 0>, /* D9 */ + <16 0 &gpio1 12 0>, /* D10 */ + <17 0 &gpio0 9 0>, /* D11 */ + <18 0 &gpio0 10 0>, /* D12 */ + <19 0 &gpio0 8 0>, /* D13 */ + <20 0 &gpio1 2 0>, /* D14 */ + <21 0 &gpio1 3 0>; /* D15 */ + }; + pmic { compatible = "nordic,npm1100"; nordic,iset-gpios = <&gpio0 23 GPIO_ACTIVE_HIGH>; diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_shared.dtsi b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_shared.dtsi index 7a363d58700c..15cbd575f123 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_shared.dtsi +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_shared.dtsi @@ -37,7 +37,6 @@ gpios = <&gpio1 1 GPIO_ACTIVE_HIGH>; label = "4 LED_MONO_GREEN"; }; - }; buttons { @@ -79,6 +78,8 @@ sw2 = &button3; sw3 = &button4; sw4 = &button5; + mcuboot-led0 = &led1_blue; + mcuboot-button0 = &button3; watchdog0 = &wdt0; }; }; From 719ebb6a27b10579816d8d4885eb0f3b827efc0d Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 10 Mar 2023 13:53:12 +0100 Subject: [PATCH 0120/1906] tests: drivers: can: timing: use recommended sample point Use the recommended sample point of 75.0% for the data phase bitrate test @ 1Mbit/s. This matches the default sample point calculated in can_common.c:sample_point_for_bitrate(). Signed-off-by: Henrik Brix Andersen --- tests/drivers/can/timing/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/drivers/can/timing/src/main.c b/tests/drivers/can/timing/src/main.c index 09b548a7faf5..2c90863ad641 100644 --- a/tests/drivers/can/timing/src/main.c +++ b/tests/drivers/can/timing/src/main.c @@ -64,7 +64,7 @@ static const struct can_timing_test can_timing_tests[] = { static const struct can_timing_test can_timing_data_tests[] = { /** Standard bitrates. */ { 500000, 875, false }, - { 1000000, 875, false }, + { 1000000, 750, false }, /** Additional, valid sample points. */ { 500000, 900, false }, { 500000, 800, false }, From 9ca4968b21c19443213b85ca14bca9db42feeeb9 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 10 Mar 2023 19:23:52 +0100 Subject: [PATCH 0121/1906] drivers: can: clarify the documentation on overlapping filters Attempt to clarify the documentation on the behaviour of overlapping CAN RX filters. Signed-off-by: Henrik Brix Andersen --- include/zephyr/drivers/can.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/zephyr/drivers/can.h b/include/zephyr/drivers/can.h index d9206c1828c9..3d34e1245c8a 100644 --- a/include/zephyr/drivers/can.h +++ b/include/zephyr/drivers/can.h @@ -1136,8 +1136,8 @@ __syscall int can_send(const struct device *dev, const struct can_frame *frame, * frame matching the filter is received by the CAN controller, the callback * function is called in interrupt context. * - * If a frame matches more than one attached filter, the priority of the match - * is hardware dependent. + * If a received frame matches more than one filter (i.e., the filter IDs/masks or + * flags overlap), the priority of the match is hardware dependent. * * The same callback function can be used for multiple filters. * @@ -1183,8 +1183,8 @@ static inline int can_add_rx_filter(const struct device *dev, can_rx_callback_t * Wrapper function for @a can_add_rx_filter() which puts received CAN frames * matching the filter in a message queue instead of calling a callback. * - * If a frame matches more than one attached filter, the priority of the match - * is hardware dependent. + * If a received frame matches more than one filter (i.e., the filter IDs/masks or + * flags overlap), the priority of the match is hardware dependent. * * The same message queue can be used for multiple filters. * From b24dca032ea4811b3295c77726741d15ed3d7349 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 10 Mar 2023 19:34:12 +0100 Subject: [PATCH 0122/1906] drivers: can: add CAN-FD Error State Indicator (ESI) flag Add definition for the CAN-FD Error State Indicator (ESI) flag. The presence of this flag indicates that the transmitting CAN-FD node is in error-passive state. Signed-off-by: Henrik Brix Andersen --- include/zephyr/drivers/can.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/zephyr/drivers/can.h b/include/zephyr/drivers/can.h index 3d34e1245c8a..3475f5541248 100644 --- a/include/zephyr/drivers/can.h +++ b/include/zephyr/drivers/can.h @@ -145,6 +145,11 @@ enum can_state { /** Frame uses CAN-FD Baud Rate Switch (BRS). Only valid in combination with ``CAN_FRAME_FDF``. */ #define CAN_FRAME_BRS BIT(3) +/** CAN-FD Error State Indicator (ESI). Indicates that the transmitting node is in error-passive + * state. Only valid in combination with ``CAN_FRAME_FDF``. + */ +#define CAN_FRAME_ESI BIT(4) + /** @} */ /** From e08546fe983d64aed995e479b38ab792104ffd93 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 10 Mar 2023 19:37:29 +0100 Subject: [PATCH 0123/1906] drivers: can: shell: add support for the CAN-FD ESI flag Print the CAN-FD Error State Indicator (ESI) flag as "P" for "Passive" in received frames. Signed-off-by: Henrik Brix Andersen --- drivers/can/can_shell.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/can/can_shell.c b/drivers/can/can_shell.c index f690b3d8f498..9c5c05e3f8d3 100644 --- a/drivers/can/can_shell.c +++ b/drivers/can/can_shell.c @@ -72,7 +72,9 @@ static void can_shell_print_frame(const struct shell *sh, const struct can_frame #ifdef CONFIG_CAN_FD_MODE /* Flags */ - shell_fprintf(sh, SHELL_NORMAL, "%c ", (frame->flags & CAN_FRAME_BRS) == 0 ? '-' : 'B'); + shell_fprintf(sh, SHELL_NORMAL, "%c%c ", + (frame->flags & CAN_FRAME_BRS) == 0 ? '-' : 'B', + (frame->flags & CAN_FRAME_ESI) == 0 ? '-' : 'P'); #endif /* CONFIG_CAN_FD_MODE */ /* CAN ID */ From 641b89801a61e61de2eaa59a86fe2b7ba53f7fb2 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 10 Mar 2023 19:39:21 +0100 Subject: [PATCH 0124/1906] drivers: can: mcan: add support for CAN-FD ESI flag Add support for the CAN-FD Error State Indicator (ESI) flag in received frames. Signed-off-by: Henrik Brix Andersen --- drivers/can/can_mcan.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/can/can_mcan.c b/drivers/can/can_mcan.c index 0b1b5cd8c01f..b54263ee0ece 100644 --- a/drivers/can/can_mcan.c +++ b/drivers/can/can_mcan.c @@ -643,6 +643,10 @@ static void can_mcan_get_message(const struct device *dev, frame.flags |= CAN_FRAME_BRS; } + if (hdr.esi != 0) { + frame.flags |= CAN_FRAME_ESI; + } + #if defined(CONFIG_CAN_RX_TIMESTAMP) frame.timestamp = hdr.rxts; #endif From 751de22ca47efad58393e226d1b82b7a971b5a39 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Fri, 10 Mar 2023 14:07:59 -0800 Subject: [PATCH 0125/1906] syscalls: skip generating mrsh.c if not userspace There is no need to generate all the *_mrsh.c files for marshalling syscall arguments when userspace is not enabled. Signed-off-by: Daniel Leung --- CMakeLists.txt | 1 + scripts/build/gen_syscalls.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a31b6172fdf8..b2c5b7ab05b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -735,6 +735,7 @@ add_custom_command(OUTPUT include/generated/syscall_dispatch.c ${syscall_list_h} --base-output include/generated/syscalls # Write to this dir --syscall-dispatch include/generated/syscall_dispatch.c # Write this file --syscall-list ${syscall_list_h} + $<$:--gen-mrsh-files> ${SYSCALL_LONG_REGISTERS_ARG} ${SYSCALL_SPLIT_TIMEOUT_ARG} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} diff --git a/scripts/build/gen_syscalls.py b/scripts/build/gen_syscalls.py index 57413150e4f0..301b963e8701 100755 --- a/scripts/build/gen_syscalls.py +++ b/scripts/build/gen_syscalls.py @@ -401,6 +401,8 @@ def parse_args(): help="A long type that must be split/marshalled on 32-bit systems") parser.add_argument("-x", "--long-registers", action="store_true", help="Indicates we are on system with 64-bit registers") + parser.add_argument("--gen-mrsh-files", action="store_true", + help="Generate marshalling files (*_mrsh.c)") args = parser.parse_args() @@ -477,14 +479,15 @@ def main(): fp.write(header) # Likewise emit _mrsh.c files for syscall inclusion - for fn in mrsh_defs: - mrsh_fn = os.path.join(args.base_output, fn + "_mrsh.c") - - with open(mrsh_fn, "w") as fp: - fp.write("/* auto-generated by gen_syscalls.py, don't edit */\n\n") - fp.write(mrsh_includes[fn] + "\n") - fp.write("\n") - fp.write(mrsh_defs[fn] + "\n") + if args.gen_mrsh_files: + for fn in mrsh_defs: + mrsh_fn = os.path.join(args.base_output, fn + "_mrsh.c") + + with open(mrsh_fn, "w") as fp: + fp.write("/* auto-generated by gen_syscalls.py, don't edit */\n\n") + fp.write(mrsh_includes[fn] + "\n") + fp.write("\n") + fp.write(mrsh_defs[fn] + "\n") if __name__ == "__main__": main() From 3d76ee8f251be426b8132d94e6d2756c78b9bdcd Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Wed, 8 Mar 2023 15:09:56 +0100 Subject: [PATCH 0126/1906] cmake: provide CMake helper macros for argument validation This commit provides a number of helper macros for verifying arguments passing to function: - zephyr_check_flags_required - zephyr_check_arguments_required - zephyr_check_arguments_required_all - zephyr_check_flags_exclusive - zephyr_check_arguments_exclusive which facilitates checking whether a required argument or flag has been given or if mutual exclusive arguments are given. Signed-off-by: Torsten Rasmussen --- cmake/modules/extensions.cmake | 104 +++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/cmake/modules/extensions.cmake b/cmake/modules/extensions.cmake index e8ec63e3472a..aa66e8f24342 100644 --- a/cmake/modules/extensions.cmake +++ b/cmake/modules/extensions.cmake @@ -32,6 +32,7 @@ include(CheckCXXCompilerFlag) # 4.2. *_if_dt_node # 5. Zephyr linker functions # 5.1. zephyr_linker* +# 6 Function helper macros ######################################################## # 1. Zephyr-aware extensions @@ -4194,3 +4195,106 @@ macro(zephyr_linker_arg_val_list list arguments) endif() endforeach() endmacro() + +######################################################## +# 6. Function helper macros +######################################################## +# +# Set of CMake macros to facilitate argument processing when defining functions. +# + +# +# Helper macro for verifying that at least one of the required arguments has +# been provided by the caller. +# +# A FATAL_ERROR will be raised if not one of the required arguments has been +# passed by the caller. +# +# Usage: +# zephyr_check_arguments_required( [ ...]) +# +macro(zephyr_check_arguments_required function prefix) + set(check_defined DEFINED) + zephyr_check_flags_required(${function} ${prefix} ${ARGN}) + set(check_defined) +endmacro() + +# +# Helper macro for verifying that at least one of the required flags has +# been provided by the caller. +# +# A FATAL_ERROR will be raised if not one of the required arguments has been +# passed by the caller. +# +# Usage: +# zephyr_check_flags_required( [ ...]) +# +macro(zephyr_check_flags_required function prefix) + set(required_found FALSE) + foreach(required ${ARGN}) + if(${check_defined} ${prefix}_${required}) + set(required_found TRUE) + endif() + endforeach() + + if(NOT required_found) + message(FATAL_ERROR "${function}(...) missing a required argument: ${ARGN}") + endif() +endmacro() + +# +# Helper macro for verifying that all the required arguments have been +# provided by the caller. +# +# A FATAL_ERROR will be raised if one of the required arguments is missing. +# +# Usage: +# zephyr_check_arguments_required_all( [ ...]) +# +macro(zephyr_check_arguments_required_all function prefix) + foreach(required ${ARGN}) + if(NOT DEFINED ${prefix}_${required}) + message(FATAL_ERROR "${function}(...) missing a required argument: ${required}") + endif() + endforeach() +endmacro() + +# +# Helper macro for verifying that none of the mutual exclusive arguments are +# provided together. +# +# A FATAL_ERROR will be raised if any of the arguments are given together. +# +# Usage: +# zephyr_check_arguments_exclusive( [ ...]) +# +macro(zephyr_check_arguments_exclusive function prefix) + set(check_defined DEFINED) + zephyr_check_flags_exclusive(${function} ${prefix} ${ARGN}) + set(check_defined) +endmacro() + +# +# Helper macro for verifying that none of the mutual exclusive flags are +# provided together. +# +# A FATAL_ERROR will be raised if any of the flags are given together. +# +# Usage: +# zephyr_check_flags_exclusive( [ ...]) +# +macro(zephyr_check_flags_exclusive function prefix) + set(args_defined) + foreach(arg ${ARGN}) + if(${check_defined} ${prefix}_${arg}) + list(APPEND args_defined ${arg}) + endif() + endforeach() + list(LENGTH args_defined exclusive_length) + if(exclusive_length GREATER 1) + list(POP_FRONT args_defined argument) + message(FATAL_ERROR "${function}(${argument} ...) cannot be used with " + "argument: ${args_defined}" + ) + endif() +endmacro() From 9940940cea1996fb06deb01523fc6d35b7470138 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Wed, 8 Mar 2023 15:16:01 +0100 Subject: [PATCH 0127/1906] cmake: sysbuild PRE_CMAKE, POST_CMAKE, PRE_DOMAINS, POST_DOMAINS hooks Provide a uniform way for sysbuild modules to create hooks that are called at specific time during sysbuild CMake configure time. A module can create functions following the scheme: - _pre_cmake - _post_cmake - _pre_domains - _post_domains those functions, if defined, will be called by sysbuild CMake at the location indicated by the function name. A new global variable `SYSBUILD_CURRENT_MODULE_NAME` is created, which a module can use to know it's own name when defining those functions during sysbuild module CMake inclusion. Signed-off-by: Torsten Rasmussen --- share/sysbuild/CMakeLists.txt | 11 ++++-- .../cmake/modules/sysbuild_extensions.cmake | 36 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/share/sysbuild/CMakeLists.txt b/share/sysbuild/CMakeLists.txt index 12729d8cd1f6..5a8428be54f5 100644 --- a/share/sysbuild/CMakeLists.txt +++ b/share/sysbuild/CMakeLists.txt @@ -31,17 +31,17 @@ get_filename_component(APP_DIR ${APP_DIR} ABSOLUTE) get_filename_component(app_name ${APP_DIR} NAME) # Include zephyr modules generated sysbuild CMake file. -foreach(module_name ${SYSBUILD_MODULE_NAMES}) +foreach(SYSBUILD_CURRENT_MODULE_NAME ${SYSBUILD_MODULE_NAMES}) # Note the second, binary_dir parameter requires the added # subdirectory to have its own, local cmake target(s). If not then # this binary_dir is created but stays empty. Object files land in # the main binary dir instead. # https://cmake.org/pipermail/cmake/2019-June/069547.html - zephyr_string(SANITIZE TOUPPER MODULE_NAME_UPPER ${module_name}) + zephyr_string(SANITIZE TOUPPER MODULE_NAME_UPPER ${SYSBUILD_CURRENT_MODULE_NAME}) if(NOT ${SYSBUILD_${MODULE_NAME_UPPER}_CMAKE_DIR} STREQUAL "") set(SYSBUILD_CURRENT_MODULE_DIR ${SYSBUILD_${MODULE_NAME_UPPER}_MODULE_DIR}) set(SYSBUILD_CURRENT_CMAKE_DIR ${SYSBUILD_${MODULE_NAME_UPPER}_CMAKE_DIR}) - add_subdirectory(${SYSBUILD_CURRENT_CMAKE_DIR} ${CMAKE_BINARY_DIR}/modules/${module_name}) + add_subdirectory(${SYSBUILD_CURRENT_CMAKE_DIR} ${CMAKE_BINARY_DIR}/modules/${SYSBUILD_CURRENT_MODULE_NAME}) endif() endforeach() # Done processing modules, clear SYSBUILD_CURRENT_MODULE_DIR and SYSBUILD_CURRENT_CMAKE_DIR. @@ -115,7 +115,12 @@ while(NOT "${images_length}" EQUAL "${processed_length}") set(processed_length ${processed_length_new}) endwhile() +sysbuild_module_call(PRE_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES}) foreach(image ${IMAGES}) ExternalZephyrProject_Cmake(APPLICATION ${image}) endforeach() +sysbuild_module_call(POST_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES}) + +sysbuild_module_call(PRE_DOMAINS MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES}) include(cmake/domains.cmake) +sysbuild_module_call(POST_DOMAINS MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES}) diff --git a/share/sysbuild/cmake/modules/sysbuild_extensions.cmake b/share/sysbuild/cmake/modules/sysbuild_extensions.cmake index 843ff2060e7c..d7eb004a17df 100644 --- a/share/sysbuild/cmake/modules/sysbuild_extensions.cmake +++ b/share/sysbuild/cmake/modules/sysbuild_extensions.cmake @@ -346,3 +346,39 @@ function(ExternalZephyrProject_Cmake) load_cache(IMAGE ${ZCMAKE_APPLICATION} BINARY_DIR ${BINARY_DIR}) import_kconfig(CONFIG_ ${BINARY_DIR}/zephyr/.config TARGET ${ZCMAKE_APPLICATION}) endfunction() + +# Usage: +# sysbuild_module_call( MODULES [IMAGES ] [EXTRA_ARGS ]) +# +# This function invokes the sysbuild hook provided as for . +# +# If `IMAGES` is passed, then the provided list of of images will be passed to +# the hook. +# +# `EXTRA_ARGS` can be used to pass extra arguments to the hook. +# +# Valid values: +# PRE_CMAKE : Invoke pre-CMake call for modules before CMake configure is invoked for images +# POST_CMAKE : Invoke post-CMake call for modules after CMake configure has been invoked for images +# PRE_DOMAINS : Invoke pre-domains call for modules before creating domains yaml. +# POST_DOMAINS: Invoke post-domains call for modules after creation of domains yaml. +# +function(sysbuild_module_call) + set(options "PRE_CMAKE;POST_CMAKE;PRE_DOMAINS;POST_DOMAINS") + set(multi_args "MODULES;IMAGES;EXTRA_ARGS") + cmake_parse_arguments(SMC "${options}" "${test_args}" "${multi_args}" ${ARGN}) + + zephyr_check_flags_required("sysbuild_module_call" SMC ${options}) + zephyr_check_flags_exclusive("sysbuild_module_call" SMC ${options}) + + foreach(call ${options}) + if(SMC_${call}) + foreach(module ${SMC_MODULES}) + if(COMMAND ${module}_${call}) + cmake_language(CALL ${module}_${call} IMAGES ${SMC_IMAGES} ${SMC_EXTRA_ARGS}) + endif() + endforeach() + endif() + endforeach() + +endfunction() From 139fa8292a9cb91312cb4f9fc3d43d97683db3e6 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Thu, 9 Mar 2023 11:01:32 +0100 Subject: [PATCH 0128/1906] doc: document the sysbuild PRE/POST_CMAKE, PRE/POST_DOMAINS hooks Document how sysbuild modules can provide functions that will be invoked during sysbuild CMake configure time. The following functions has been documented: - _pre_cmake - _post_cmake - _pre_domains - _post_domains Signed-off-by: Torsten Rasmussen --- doc/develop/modules.rst | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/doc/develop/modules.rst b/doc/develop/modules.rst index 4ed3320909e9..1f5b9737b31c 100644 --- a/doc/develop/modules.rst +++ b/doc/develop/modules.rst @@ -656,6 +656,45 @@ PARENT_SCOPE of the CMakeLists.txt file. For example, to append ``bar`` to the list(APPEND FOO_LIST bar) set(FOO_LIST ${FOO_LIST} PARENT_SCOPE) +Sysbuild modules hooks +---------------------- + +Sysbuild provides an infrastructure which allows a sysbuild module to define +a function which will be invoked by sysbuild at a pre-defined point in the +CMake flow. + +Functions invoked by sysbuild: + +- ``_pre_cmake(IMAGES )``: This function is called for each + sysbuild module before CMake configure is invoked for all images. +- ``_post_cmake(IMAGES )``: This function is called for each + sysbuild module after CMake configure has completed for all images. +- ``_pre_domains(IMAGES )``: This function is called for each + sysbuild module before domains yaml is created by sysbuild. +- ``_post_domains(IMAGES )``: This function is called for each + sysbuild module after domains yaml has been created by sysbuild. + +arguments passed from sysbuild to the function defined by a module: + +- ```` is the list of Zephyr images that will be created by the build system. + +If a module ``foo`` want to provide a post CMake configure function, then the +module's sysbuild :file:`CMakeLists.txt` file must define function ``foo_post_cmake()``. + +To facilitate naming of functions, the module name is provided by sysbuild CMake +through the ``SYSBUILD_CURRENT_MODULE_NAME`` CMake variable when loading the +module's sysbuild :file:`CMakeLists.txt` file. + +Example of how the ``foo`` sysbuild module can define ``foo_post_cmake()``: + +.. code-block:: cmake + + function(${SYSBUILD_CURRENT_MODULE_NAME}_post_cmake) + cmake_parse_arguments(POST_CMAKE "" "" "IMAGES" ${ARGN}) + + message("Invoking ${CMAKE_CURRENT_FUNCTION}. Images: ${POST_CMAKE_IMAGES}") + endfunction() + Zephyr module dependencies ========================== From 190701178d457e06f6cd033df6b51ccc654c8f0b Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Fri, 10 Mar 2023 11:52:20 +0100 Subject: [PATCH 0129/1906] tests: Bluetooth: Shell: Add LC3 support for native_posix The native_posix board can also be used for audio, and thus should have LC3 support similar to the nrf5340. Signed-off-by: Emil Gydesen --- tests/bluetooth/shell/boards/native_posix.conf | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/bluetooth/shell/boards/native_posix.conf b/tests/bluetooth/shell/boards/native_posix.conf index e52a0a2849b1..f35bf051edcc 100644 --- a/tests/bluetooth/shell/boards/native_posix.conf +++ b/tests/bluetooth/shell/boards/native_posix.conf @@ -7,3 +7,12 @@ CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE=4096 # 5ms ISO interval bidirectional data the system shall never stall for more # than 1.5 ms in average. CONFIG_SYS_CLOCK_TICKS_PER_SEC=500 + +# For LC3 the following configs are needed +CONFIG_FPU=y +CONFIG_LIBLC3=y +# The LC3 codec uses a large amount of stack. This app runs the codec in the work-queue, hence +# inctease stack size for that thread. +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 +# LC3 lib requires floating point support in the c-lib NEWLIB is one way of getting that. +CONFIG_NEWLIB_LIBC=y From 546b8476fda058b93cfd41178a96292cace62cd5 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 10 Mar 2023 08:55:15 +0100 Subject: [PATCH 0130/1906] tests/bt/bsim/mesh: Fix tests dependent on RSSI The friendship tests are dependent on the attenuation level as they take (much) longer with higher channel attenuation. As BabbleSim's "magic" modem model (default one used in these tests) has been updated to provide a somehow accurate RSSI measurement, one of these tests fails tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_mesh_low_lat.sh fails with the default channel attenuation of 60dBs. Reduce the channel attenuation to 35dBs to approach the previous RSSI values this tests were seeing on the DUTs with the default modem. Signed-off-by: Alberto Escolar Piedras --- tests/bluetooth/bsim/mesh/_mesh_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bluetooth/bsim/mesh/_mesh_test.sh b/tests/bluetooth/bsim/mesh/_mesh_test.sh index b73df051c984..811c8fe9b567 100755 --- a/tests/bluetooth/bsim/mesh/_mesh_test.sh +++ b/tests/bluetooth/bsim/mesh/_mesh_test.sh @@ -84,7 +84,7 @@ function RunTest(){ echo "Starting phy with $count devices" - Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=$s_id -D=$count + Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=$s_id -D=$count -argschannel -at=35 for process_id in ${process_ids[@]}; do wait $process_id || let "exit_code=$?" From 77b02252c0aa2967fbd9717e3574449a8fde863c Mon Sep 17 00:00:00 2001 From: Dmitrii Golovanov Date: Thu, 16 Feb 2023 21:51:14 +0100 Subject: [PATCH 0131/1906] twister: Fix DeviceHandler serial leftover cleanup Fix how DeviceHandler class does 'serial leftover' cleanup with loss of test output observed on fast console connections, e.g. over telnet: either 1 sec. of output might be missed, or up to 1000 bytes/chars, whatever happens first. Signed-off-by: Dmitrii Golovanov --- scripts/pylib/twister/twisterlib/handlers.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/handlers.py b/scripts/pylib/twister/twisterlib/handlers.py index 5ab69aa940c9..e69be4480758 100755 --- a/scripts/pylib/twister/twisterlib/handlers.py +++ b/scripts/pylib/twister/twisterlib/handlers.py @@ -353,7 +353,8 @@ def monitor_serial(self, ser, halt_event, harness): # from the test. harness.capture_coverage = True - ser.flush() + # Clear serial leftover. + ser.reset_input_buffer() while ser.isOpen(): if halt_event.is_set(): @@ -548,21 +549,6 @@ def handle(self): self.make_device_available(serial_device) return - ser.flush() - - # turns out the ser.flush() is not enough to clear serial leftover from last case - # explicitly readline() can do it reliably - old_timeout = ser.timeout - # wait for 1s if no serial output - ser.timeout = 1 - # or read 1000 lines at most - # if the leftovers are more than 1000 lines, user should realize that once - # saw the caught ones and fix it. - leftover_lines = ser.readlines(1000) - for line in leftover_lines: - logger.debug(f"leftover log of previous test: {line}") - ser.timeout = old_timeout - harness_name = self.instance.testsuite.harness.capitalize() harness_import = HarnessImporter(harness_name) harness = harness_import.instance From 364d7527c11566f47434ee305ab16892179884bd Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 6 Mar 2023 15:35:04 -0500 Subject: [PATCH 0132/1906] arch/arm64/mmu: minor addition to debugging code Display table allocations and whether or not mappings can be overwritten. Signed-off-by: Nicolas Pitre --- arch/arm64/core/mmu.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/arm64/core/mmu.c b/arch/arm64/core/mmu.c index 14962be3fd9b..e4bee392dbe2 100644 --- a/arch/arm64/core/mmu.c +++ b/arch/arm64/core/mmu.c @@ -34,13 +34,16 @@ static struct k_spinlock xlat_lock; /* Returns a reference to a free table */ static uint64_t *new_table(void) { + uint64_t *table; unsigned int i; /* Look for a free table. */ for (i = 0U; i < CONFIG_MAX_XLAT_TABLES; i++) { if (xlat_use_count[i] == 0U) { + table = &xlat_tables[i * Ln_XLAT_NUM_ENTRIES]; xlat_use_count[i] = 1U; - return &xlat_tables[i * Ln_XLAT_NUM_ENTRIES]; + MMU_DEBUG("allocating table [%d]%p\n", i, table); + return table; } } @@ -616,8 +619,9 @@ static int __add_map(struct arm_mmu_ptables *ptables, const char *name, uint64_t desc = get_region_desc(attrs); bool may_overwrite = !(attrs & MT_NO_OVERWRITE); - MMU_DEBUG("mmap [%s]: virt %lx phys %lx size %lx attr %llx\n", - name, virt, phys, size, desc); + MMU_DEBUG("mmap [%s]: virt %lx phys %lx size %lx attr %llx %s overwrite\n", + name, virt, phys, size, desc, + may_overwrite ? "may" : "no"); __ASSERT(((virt | phys | size) & (CONFIG_MMU_PAGE_SIZE - 1)) == 0, "address/size are not page aligned\n"); desc |= phys; From bcef6333161915fd649a76523453a04371ae0849 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 6 Mar 2023 15:39:19 -0500 Subject: [PATCH 0133/1906] arch/arm64/mmu: arch_mem_map() should not overwrite existing mappings If so this is most certainly a bug. arch_mem_unmap() should be used before mapping the same area again. Signed-off-by: Nicolas Pitre --- arch/arm64/core/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/core/mmu.c b/arch/arm64/core/mmu.c index e4bee392dbe2..c431fee8af55 100644 --- a/arch/arm64/core/mmu.c +++ b/arch/arm64/core/mmu.c @@ -892,7 +892,7 @@ static void sync_domains(uintptr_t virt, size_t size) static int __arch_mem_map(void *virt, uintptr_t phys, size_t size, uint32_t flags) { struct arm_mmu_ptables *ptables; - uint32_t entry_flags = MT_DEFAULT_SECURE_STATE | MT_P_RX_U_NA; + uint32_t entry_flags = MT_DEFAULT_SECURE_STATE | MT_P_RX_U_NA | MT_NO_OVERWRITE; /* Always map in the kernel page tables */ ptables = &kernel_ptables; From f76bfa57120b44172740ac1a7c14691595a8be79 Mon Sep 17 00:00:00 2001 From: Julien D'Ascenzio Date: Fri, 20 Jan 2023 12:46:16 +0100 Subject: [PATCH 0134/1906] nvs: use NVS cache in write and gc functions NVS cache was used only in read function. This commit add the usage of NVS cache in write and gc functions. Signed-off-by: Julien D'Ascenzio --- subsys/fs/nvs/nvs.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/subsys/fs/nvs/nvs.c b/subsys/fs/nvs/nvs.c index 01f3f5aefbee..63703147bc46 100644 --- a/subsys/fs/nvs/nvs.c +++ b/subsys/fs/nvs/nvs.c @@ -629,7 +629,15 @@ static int nvs_gc(struct nvs_fs *fs) continue; } +#ifdef CONFIG_NVS_LOOKUP_CACHE + wlk_addr = fs->lookup_cache[nvs_lookup_cache_pos(gc_ate.id)]; + + if (wlk_addr == NVS_LOOKUP_CACHE_NO_ADDR) { + wlk_addr = fs->ate_wra; + } +#else wlk_addr = fs->ate_wra; +#endif do { wlk_prev_addr = wlk_addr; rc = nvs_prev_ate(fs, &wlk_addr, &wlk_ate); @@ -854,6 +862,16 @@ static int nvs_startup(struct nvs_fs *fs) fs->ate_wra &= ADDR_SECT_MASK; fs->ate_wra += (fs->sector_size - 2 * ate_size); fs->data_wra = (fs->ate_wra & ADDR_SECT_MASK); +#ifdef CONFIG_NVS_LOOKUP_CACHE + /** + * At this point, the lookup cache wasn't built but the gc function need to use it. + * So, temporarily, we set the lookup cache to the end of the fs. + * The cache will be rebuilt afterwards + **/ + for (int i = 0; i < CONFIG_NVS_LOOKUP_CACHE_SIZE; i++) { + fs->lookup_cache[i] = fs->ate_wra; + } +#endif rc = nvs_gc(fs); goto end; } @@ -1016,7 +1034,15 @@ ssize_t nvs_write(struct nvs_fs *fs, uint16_t id, const void *data, size_t len) } /* find latest entry with same id */ +#ifdef CONFIG_NVS_LOOKUP_CACHE + wlk_addr = fs->lookup_cache[nvs_lookup_cache_pos(id)]; + + if (wlk_addr == NVS_LOOKUP_CACHE_NO_ADDR) { + goto no_cached_entry; + } +#else wlk_addr = fs->ate_wra; +#endif rd_addr = wlk_addr; while (1) { @@ -1034,6 +1060,10 @@ ssize_t nvs_write(struct nvs_fs *fs, uint16_t id, const void *data, size_t len) } } +#ifdef CONFIG_NVS_LOOKUP_CACHE +no_cached_entry: +#endif + if (prev_found) { /* previous entry found */ rd_addr &= ADDR_SECT_MASK; From 65512e9445db5a203001f7f24d5eb8ecf34b33ab Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Fri, 10 Mar 2023 09:48:21 +0100 Subject: [PATCH 0135/1906] boards: arm: nrf5340_audio_dk_nrf5340: add bindings for audio codec The board embeds an audio codec IC, Cirrus CS42L73. While there is no in-tree driver for it, we need a binding to describe how it is wired in the board, e.g. for IRQ/RESET lines. Following Linux binding for the same IC, create one in dts/bindings/sound. Note that Linux binding is less complete/outdated. Ref. https://statics.cirrus.com/pubs/proDatasheet/CS47L63_DS1249F2.pdf Signed-off-by: Gerard Marull-Paretas --- ...rf5340_audio_dk_nrf5340_cpuapp_common.dtsi | 6 ++ dts/bindings/sound/cirrus,cs47l63.yaml | 82 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 dts/bindings/sound/cirrus,cs47l63.yaml diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi index d45db3438561..b56846ffd60f 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi @@ -184,8 +184,14 @@ spi-max-frequency = <8000000>; }; + cs47l63: cs47l63@1 { + compatible = "cirrus,cs47l63"; reg = <1>; + spi-max-frequency = <8000000>; + irq-gpios = <&gpio0 19 GPIO_ACTIVE_LOW>; + reset-gpios = <&gpio0 18 GPIO_ACTIVE_LOW>; + gpio9-gpios = <&gpio0 20 GPIO_ACTIVE_LOW>; }; }; diff --git a/dts/bindings/sound/cirrus,cs47l63.yaml b/dts/bindings/sound/cirrus,cs47l63.yaml new file mode 100644 index 000000000000..24940a9d7b67 --- /dev/null +++ b/dts/bindings/sound/cirrus,cs47l63.yaml @@ -0,0 +1,82 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: Cirrus Logic CS47L63 Low-Power Audio DSP + +compatible: "cirrus,cs47l63" + +include: spi-device.yaml + +properties: + reg: + required: true + + irq-gpios: + type: phandle-array + description: + Interrupt request (IRQ) output. + + reset-gpios: + type: phandle-array + description: + Digital reset input. + + gpio1-gpios: + type: phandle-array + description: + GPIO1 input with bus-keeper + + gpio2-gpios: + type: phandle-array + description: + GPIO2 input with bus-keeper + + gpio3-gpios: + type: phandle-array + description: + GPIO3 input with bus-keeper + + gpio4-gpios: + type: phandle-array + description: + GPIO4 input with bus-keeper + + gpio5-gpios: + type: phandle-array + description: + GPIO5 input with bus-keeper + + gpio6-gpios: + type: phandle-array + description: + GPIO6 input with bus-keeper + + gpio7-gpios: + type: phandle-array + description: + GPIO7 input with bus-keeper + + gpio8-gpios: + type: phandle-array + description: + GPIO8 input with bus-keeper + + gpio9-gpios: + type: phandle-array + description: + GPIO9 input with bus-keeper + + gpio10-gpios: + type: phandle-array + description: + GPIO10 input with bus-keeper + + gpio11-gpios: + type: phandle-array + description: + GPIO11 input with bus-keeper + + gpio12-gpios: + type: phandle-array + description: + GPIO12 input with bus-keeper From c1a1108ae2fc3c1bc9716a527acd1aa26ba4f3ad Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Fri, 10 Mar 2023 10:11:24 +0100 Subject: [PATCH 0136/1906] boards: arm: nrf5340_audio_dk_nrf5340: add board id description nRF5340 Audio DK embeds a voltage divider to identify the "board ID". Use the existing 'voltage-divider' binding to describe it. Also configure the ADC channel 0 to read the voltage divider value. Configuration from https://github.com/nrfconnect/sdk-nrf/blob/main/applications/ nrf5340_audio/src/utils/board_version.c has been taken. Signed-off-by: Gerard Marull-Paretas --- ...rf5340_audio_dk_nrf5340_cpuapp_common.dtsi | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi index b56846ffd60f..6a941ab8b860 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi @@ -59,6 +59,14 @@ nordic,iset-gpios = <&gpio0 23 GPIO_ACTIVE_HIGH>; }; + board_id: board_id { + compatible = "voltage-divider"; + io-channels = <&adc 0>; + output-ohms = <20000>; + full-ohms = <47000>; + power-gpios = <&gpio0 24 GPIO_ACTIVE_HIGH>; + }; + pwmleds { compatible = "pwm-leds"; rgb1_red_pwm_led: pwm_led_0 { @@ -84,6 +92,18 @@ &adc { status = "okay"; + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1_4"; + zephyr,reference = "ADC_REF_VDD_1_4"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; + zephyr,resolution = <12>; + zephyr,oversampling = <8>; + }; }; &gpiote { From 20d34bdb6e49af486c0572a98541ea516bef57cd Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Fri, 10 Mar 2023 10:29:18 +0100 Subject: [PATCH 0137/1906] boards: arm: nrf5340_audio_dk_nrf5340: add codec iface gpio hogs The nRF5340 Audio DK provides a multiplexer circuit that allows to interface the audio codec by an external master. Use GPIO hogs to initialize the multiplexers correctly. Signed-off-by: Gerard Marull-Paretas --- .../nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi index 6a941ab8b860..66c829570335 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi @@ -112,6 +112,13 @@ &gpio0 { status = "okay"; + + codec-interface { + gpio-hog; + gpios = <21 GPIO_ACTIVE_HIGH>; + /* low output to select on-board codec control */ + output-low; + }; }; &gpio1 { From 43c08d5c3f68d2b23ae66c67a6403bb9c4b1b510 Mon Sep 17 00:00:00 2001 From: Michal Ciesielski Date: Fri, 10 Mar 2023 12:55:11 +0100 Subject: [PATCH 0138/1906] lwm2m: Fix multi res inst, create flags and post write callback for SWMGMT The multi resource and create flags were reversed, meaning that resources were defined as multi resource but weren't being created by default. That doesn't reflect the LWM2M Software Management, which specifies which objects can be multi resource and which are mandatory. The post write callbacks were assigned to the validate callbacks. Signed-off-by: Michal Ciesielski --- subsys/net/lib/lwm2m/lwm2m_obj_swmgmt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_swmgmt.c b/subsys/net/lib/lwm2m/lwm2m_obj_swmgmt.c index ddbba643a713..9c817c69cf2e 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_swmgmt.c +++ b/subsys/net/lib/lwm2m/lwm2m_obj_swmgmt.c @@ -731,19 +731,19 @@ static struct lwm2m_engine_obj_inst *swmgmt_create(uint16_t obj_inst_id) res_inst_idx, &instance->package_name, PACKAGE_NAME_LEN, 0); INIT_OBJ_RES_LEN(SWMGMT_PACKAGE_VERSION_ID, res[index], res_idx, res_inst[index], - res_inst_idx, 1, true, false, &instance->package_version, + res_inst_idx, 1, false, true, &instance->package_version, PACKAGE_VERSION_LEN, 0, state_read_pkg_version, NULL, NULL, NULL, NULL); INIT_OBJ_RES_OPT(SWMGMT_PACKAGE_ID, res[index], res_idx, res_inst[index], res_inst_idx, 1, - true, false, NULL, NULL, package_write_cb, NULL, NULL); + false, false, NULL, NULL, NULL, package_write_cb, NULL); #ifdef CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT INIT_OBJ_RES(SWMGMT_PACKAGE_URI_ID, res[index], res_idx, res_inst[index], res_inst_idx, 1, - true, true, instance->package_uri, PACKAGE_URI_LEN, NULL, NULL, NULL, + false, true, instance->package_uri, PACKAGE_URI_LEN, NULL, NULL, NULL, package_uri_write_cb, NULL); #else INIT_OBJ_RES_OPT(SWMGMT_PACKAGE_URI_ID, res[index], res_idx, res_inst[index], res_inst_idx, - 1, true, false, NULL, NULL, package_uri_write_cb, NULL, NULL); + 1, false, true, NULL, NULL, NULL, package_uri_write_cb, NULL); #endif INIT_OBJ_RES_EXECUTE(SWMGMT_INSTALL_ID, res[index], res_idx, install_cb); From 303eb762930e2717b1357812761487f7d85c1430 Mon Sep 17 00:00:00 2001 From: Siyuan Cheng Date: Mon, 27 Feb 2023 15:04:12 +0800 Subject: [PATCH 0139/1906] sample: driver: spi_flash: Add emsdp support Add emsdp support in spi_flash driver sample output log: JEDEC QSPI-NOR SPI flash testing ========================== Test 1: Flash erase Flash erase succeeded! Test 2: Flash write Attempting to write 4 bytes Data read matches data written. Good! Signed-off-by: Siyuan Cheng --- samples/drivers/spi_flash/boards/emsdp.conf | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 samples/drivers/spi_flash/boards/emsdp.conf diff --git a/samples/drivers/spi_flash/boards/emsdp.conf b/samples/drivers/spi_flash/boards/emsdp.conf new file mode 100644 index 000000000000..4e3bfcd17d5b --- /dev/null +++ b/samples/drivers/spi_flash/boards/emsdp.conf @@ -0,0 +1,7 @@ +# +# Copyright (c) 2023 Synopsys. +# +# SPDX-License-Identifier: Apache-2.0 +# + +CONFIG_SPI_NOR=y From eba73727eec2422817f5168eae88ad0b5325aa39 Mon Sep 17 00:00:00 2001 From: Nicola Ochsenbein Date: Fri, 16 Dec 2022 16:05:02 +0100 Subject: [PATCH 0140/1906] modules: fs: Add reentrant zephyr support This commit enables zephyr to configure the FatFs FF_FS_REENTRANT option and support fs actions from multiple threads. CONFIG_FS_FATFS_REENTRANT enables the option and provides zephyr mutex wrappers. Signed-off-by: Nicola Ochsenbein --- modules/fatfs/CMakeLists.txt | 5 ++- modules/fatfs/zephyr_fatfs_config.h | 9 ++++ modules/fatfs/zfs_ffsystem.c | 69 +++++++++++++++++++++++++++++ subsys/fs/Kconfig.fatfs | 9 ++++ 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 modules/fatfs/zfs_ffsystem.c diff --git a/modules/fatfs/CMakeLists.txt b/modules/fatfs/CMakeLists.txt index 97371b1fb44f..63c4701bb987 100644 --- a/modules/fatfs/CMakeLists.txt +++ b/modules/fatfs/CMakeLists.txt @@ -18,9 +18,12 @@ if(CONFIG_FAT_FILESYSTEM_ELM) zephyr_library_sources_ifdef(CONFIG_FS_FATFS_LFN ${ZEPHYR_FATFS_MODULE_DIR}/option/ffunicode.c - ${ZEPHYR_FATFS_MODULE_DIR}/option/ffsystem.c ) + if(DEFINED CONFIG_FS_FATFS_LFN OR DEFINED CONFIG_FS_FATFS_REENTRANT) + zephyr_library_sources(zfs_ffsystem.c) + endif() + zephyr_library_link_libraries(ELMFAT) target_link_libraries(ELMFAT INTERFACE zephyr_interface) endif() diff --git a/modules/fatfs/zephyr_fatfs_config.h b/modules/fatfs/zephyr_fatfs_config.h index be6dd04a1b4c..7ced4f74cdf4 100644 --- a/modules/fatfs/zephyr_fatfs_config.h +++ b/modules/fatfs/zephyr_fatfs_config.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2022 Nordic Semiconductor ASA + * Copyright (c) 2023 Husqvarna AB * * SPDX-License-Identifier: Apache-2.0 */ @@ -62,6 +63,14 @@ #define FF_FS_EXFAT CONFIG_FS_FATFS_EXFAT #endif /* defined(CONFIG_FS_FATFS_EXFAT) */ +#if defined(CONFIG_FS_FATFS_REENTRANT) +#undef FF_FS_REENTRANT +#undef FF_FS_TIMEOUT +#include +#define FF_FS_REENTRANT CONFIG_FS_FATFS_REENTRANT +#define FF_FS_TIMEOUT K_FOREVER +#endif /* defined(CONFIG_FS_FATFS_REENTRANT) */ + /* * These options are override from default values, but have no Kconfig * options. diff --git a/modules/fatfs/zfs_ffsystem.c b/modules/fatfs/zfs_ffsystem.c new file mode 100644 index 000000000000..6f4d134f798b --- /dev/null +++ b/modules/fatfs/zfs_ffsystem.c @@ -0,0 +1,69 @@ +/* + * OS Dependent Functions for FatFs + * + * Copyright (c) 2023 Husqvarna AB + * + * SPDX-License-Identifier: Apache-2.0 + */ +/* The file is based on template file by (C)ChaN, 2022, as + * available from FAT FS module source: + * https://github.com/zephyrproject-rtos/fatfs/blob/master/option/ffsystem.c + */ + +#include + +#if FF_USE_LFN == 3 /* Dynamic memory allocation */ +/* Allocate a memory block */ +void *ff_memalloc(UINT msize) +{ + return k_malloc(msize); +} + +/* Free a memory block */ +void ff_memfree(void *mblock) +{ + k_free(mblock); +} +#endif /* FF_USE_LFN == 3 */ + +#if FF_FS_REENTRANT /* Mutual exclusion */ +/* Table of Zephyr mutex. One for each volume and an extra one for the ff system. + * See also the template file used as reference. Link is available in the header of this file. + */ +static struct k_mutex fs_reentrant_mutex[FF_VOLUMES + 1]; + +/* Create a Mutex + * Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) + * Returns 1: Succeeded or 0: Could not create the mutex + */ +int ff_mutex_create(int vol) +{ + return (int)(k_mutex_init(&fs_reentrant_mutex[vol]) == 0); +} + +/* Delete a Mutex + * Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) + */ +void ff_mutex_delete(int vol) +{ + /* (nothing to do) */ + (void)vol; +} + +/* Request Grant to Access the Volume + * Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) + * Returns 1: Succeeded or 0: Timeout + */ +int ff_mutex_take(int vol) +{ + return (int)(k_mutex_lock(&fs_reentrant_mutex[vol], FF_FS_TIMEOUT) == 0); +} + +/* Release Grant to Access the Volume + * Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) + */ +void ff_mutex_give(int vol) +{ + k_mutex_unlock(&fs_reentrant_mutex[vol]); +} +#endif /* FF_FS_REENTRANT */ diff --git a/subsys/fs/Kconfig.fatfs b/subsys/fs/Kconfig.fatfs index 2a138dbb9567..e44ca1c781d9 100644 --- a/subsys/fs/Kconfig.fatfs +++ b/subsys/fs/Kconfig.fatfs @@ -1,5 +1,6 @@ # Copyright (c) 2016 Intel Corporation # Copyright (c) 2020 Nordic Semiconductor ASA +# Copyright (c) 2023 Husqvarna AB # SPDX-License-Identifier: Apache-2.0 config FAT_FILESYSTEM_ELM @@ -220,6 +221,14 @@ config FS_FATFS_WINDOW_ALIGNMENT that, in worst scenario, value provided here may cause FATFS structure to have size of twice the value. +config FS_FATFS_REENTRANT + bool "FatFs reentrant" + depends on !FS_FATFS_LFN_MODE_BSS + help + Enable the FatFs re-entrancy (thread safe) option for file/directory + access for each volume. Will create a zephyr mutex object for each + FatFs volume and a FatFs system mutex. + endmenu endif # FAT_FILESYSTEM_ELM From 31a384719d2e9208e797f02f0bb5989d8e1b2d81 Mon Sep 17 00:00:00 2001 From: Nicola Ochsenbein Date: Fri, 16 Dec 2022 16:05:40 +0100 Subject: [PATCH 0141/1906] test: fs: fat_fs_api: Add tests for reentrant zephyr support This commit adds tests for the FatFs FF_FS_REENTRANT option. Signed-off-by: Nicola Ochsenbein --- tests/subsys/fs/fat_fs_api/CMakeLists.txt | 2 + tests/subsys/fs/fat_fs_api/src/common.c | 3 + tests/subsys/fs/fat_fs_api/src/main.c | 4 + tests/subsys/fs/fat_fs_api/src/test_fat.h | 9 +- .../fat_fs_api/src/test_fat_file_reentrant.c | 179 ++++++++++++++++++ .../subsys/fs/fat_fs_api/src/test_fat_mkfs.c | 3 - .../subsys/fs/fat_fs_api/src/test_fat_mount.c | 4 - .../fat_fs_api/src/test_fat_rd_only_mount.c | 4 - tests/subsys/fs/fat_fs_api/testcase.yaml | 5 + 9 files changed, 201 insertions(+), 12 deletions(-) create mode 100644 tests/subsys/fs/fat_fs_api/src/test_fat_file_reentrant.c diff --git a/tests/subsys/fs/fat_fs_api/CMakeLists.txt b/tests/subsys/fs/fat_fs_api/CMakeLists.txt index 54fa26123131..96a02b2be72e 100644 --- a/tests/subsys/fs/fat_fs_api/CMakeLists.txt +++ b/tests/subsys/fs/fat_fs_api/CMakeLists.txt @@ -18,3 +18,5 @@ target_sources(app PRIVATE target_sources_ifdef(CONFIG_FLASH app PRIVATE ../common/test_fs_mkfs.c src/test_fat_mkfs.c) +target_sources_ifdef(CONFIG_FS_FATFS_REENTRANT app PRIVATE + src/test_fat_file_reentrant.c) diff --git a/tests/subsys/fs/fat_fs_api/src/common.c b/tests/subsys/fs/fat_fs_api/src/common.c index 4e250fcb4a9e..fd4aa46b3082 100644 --- a/tests/subsys/fs/fat_fs_api/src/common.c +++ b/tests/subsys/fs/fat_fs_api/src/common.c @@ -1,11 +1,14 @@ /* * Copyright (c) 2016 Intel Corporation. + * Copyright (c) 2023 Husqvarna AB * * SPDX-License-Identifier: Apache-2.0 */ #include "test_fat.h" +/* FatFs work area */ +FATFS fat_fs; struct fs_file_t filep; const char test_str[] = "hello world!"; diff --git a/tests/subsys/fs/fat_fs_api/src/main.c b/tests/subsys/fs/fat_fs_api/src/main.c index 870cda4def20..30f73aa0d8a0 100644 --- a/tests/subsys/fs/fat_fs_api/src/main.c +++ b/tests/subsys/fs/fat_fs_api/src/main.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2016 Intel Corporation. + * Copyright (c) 2023 Husqvarna AB * * SPDX-License-Identifier: Apache-2.0 */ @@ -18,6 +19,9 @@ static void *fat_fs_basic_setup(void) test_fat_fs(); test_fat_rename(); test_fs_open_flags(); +#ifdef CONFIG_FS_FATFS_REENTRANT + test_fat_file_reentrant(); +#endif /* CONFIG_FS_FATFS_REENTRANT */ test_fat_unmount(); return NULL; diff --git a/tests/subsys/fs/fat_fs_api/src/test_fat.h b/tests/subsys/fs/fat_fs_api/src/test_fat.h index 607f3eb0bc41..9c168b4bccf8 100644 --- a/tests/subsys/fs/fat_fs_api/src/test_fat.h +++ b/tests/subsys/fs/fat_fs_api/src/test_fat.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2016 Intel Corporation. * Copyright (c) 2020 Nordic Semiconductor ASA + * Copyright (c) 2023 Husqvarna AB * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,6 +9,7 @@ #include #include #include +#include #ifdef CONFIG_DISK_DRIVER_RAM #define DISK_NAME CONFIG_DISK_RAM_VOLUME_NAME @@ -27,12 +29,14 @@ "/testlongfilenamethatsmuchlongerthan8.3chars.text" #else #define TEST_FILE FATFS_MNTP"/testfile.txt" -#endif /* IS_ENABLED(CONFIG_FS_FATFS_LFN) */ +#endif /* CONFIG_FS_FATFS_LFN */ #define TEST_DIR FATFS_MNTP"/testdir" #define TEST_DIR_FILE FATFS_MNTP"/testdir/testfile.txt" extern struct fs_file_t filep; extern const char test_str[]; +/* FatFs work area */ +extern FATFS fat_fs; int check_file_dir_exists(const char *path); @@ -42,3 +46,6 @@ void test_fat_file(void); void test_fat_dir(void); void test_fat_fs(void); void test_fat_rename(void); +#ifdef CONFIG_FS_FATFS_REENTRANT +void test_fat_file_reentrant(void); +#endif /* CONFIG_FS_FATFS_REENTRANT */ diff --git a/tests/subsys/fs/fat_fs_api/src/test_fat_file_reentrant.c b/tests/subsys/fs/fat_fs_api/src/test_fat_file_reentrant.c new file mode 100644 index 000000000000..2ef24aaea02d --- /dev/null +++ b/tests/subsys/fs/fat_fs_api/src/test_fat_file_reentrant.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2023 Husqvarna AB + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "test_fat.h" + +#ifdef CONFIG_FS_FATFS_REENTRANT + +#define REENTRANT_TEST_STACK_SIZE 500 +#define SEMAPHORE_OP_SUCCESS 0 +#define TEST_FILE2 FATFS_MNTP"/tfile2.txt" + +void tlock_mutex(void *p1, void *p2, void *p3); +void tfile2_access(void *p1, void *p2, void *p3); + +K_THREAD_STACK_DEFINE(tlock_mutex_stack_area, REENTRANT_TEST_STACK_SIZE); +K_THREAD_STACK_DEFINE(tfile2_access_stack_area, REENTRANT_TEST_STACK_SIZE); +struct k_thread tlock_mutex_data; +struct k_thread tfile2_access_data; +struct k_sem mutex_unlocked_sem; +struct k_sem run_non_thread_sem; + +static int test_reentrant_access(void) +{ + int res; + + TC_PRINT("\nReentrant tests:\n"); + zassert_ok(k_sem_init(&mutex_unlocked_sem, 0, 1), NULL); + zassert_ok(k_sem_init(&run_non_thread_sem, 0, 1), NULL); + + /* Start mutex locking thread */ + k_tid_t tid = k_thread_create(&tlock_mutex_data, tlock_mutex_stack_area, + K_THREAD_STACK_SIZEOF(tlock_mutex_stack_area), + tlock_mutex, + NULL, NULL, NULL, + K_PRIO_PREEMPT(0), 0, K_NO_WAIT); + + /* Make sure thread was able to lock mutex */ + k_sem_take(&run_non_thread_sem, K_FOREVER); + + /* File open should wait here, as the fs is locked. Therefore, automatic switch back to + * thread + */ + TC_PRINT("Open file\n"); + res = fs_open(&filep, TEST_FILE, FS_O_CREATE | FS_O_RDWR); + zassert_ok(res, "Err: File could not be opened [%d]\n", res); + TC_PRINT("File opened\n"); + + /* Check if mutex thread really unlocked the mutexes */ + zassert_equal(SEMAPHORE_OP_SUCCESS, k_sem_take(&mutex_unlocked_sem, K_NO_WAIT), + "File open with locked mutex"); + + /* Cleanup */ + res = fs_close(&filep); + zassert_ok(res, "Error closing file [%d]\n", res); + res = fs_unlink(TEST_FILE); + zassert_ok(res, "Error deleting file [%d]\n", res); + + k_thread_join(tid, K_FOREVER); + + return res; +} + +static int test_reentrant_parallel_file_access(void) +{ + int res; + + TC_PRINT("\nParallel reentrant-safe file access test:\n"); + + TC_PRINT("Open file 1\n"); + res = fs_open(&filep, TEST_FILE, FS_O_CREATE | FS_O_RDWR); + zassert_ok(res, "Err: File 1 could not be opened [%d]\n", res); + TC_PRINT("File 1 opened 1\n"); + + /* Start 2nd file acces thread */ + k_tid_t tid = k_thread_create(&tfile2_access_data, tfile2_access_stack_area, + K_THREAD_STACK_SIZEOF(tfile2_access_stack_area), + tfile2_access, + NULL, NULL, NULL, + K_PRIO_PREEMPT(0), 0, K_NO_WAIT); + + /* Wait for thread to finish accessing file 2 */ + k_thread_join(tid, K_FOREVER); + + /* Check existence of file 2 */ + struct fs_file_t filep2; + + fs_file_t_init(&filep2); + + TC_PRINT("Check file 2 existence\n"); + res = fs_open(&filep2, TEST_FILE2, FA_OPEN_EXISTING | FA_READ); + zassert_ok(res, "Err: File 2 does not exist [%d]\n", res); + + /* Cleanup */ + res = fs_close(&filep2); + zassert_ok(res, "Error closing file 2 [%d]\n", res); + res = fs_unlink(TEST_FILE2); + zassert_ok(res, "Error deleting file 2 [%d]\n", res); + res = fs_close(&filep); + zassert_ok(res, "Error closing file 1 [%d]\n", res); + res = fs_unlink(TEST_FILE); + zassert_ok(res, "Error deleting file 1 [%d]\n", res); + + return res; +} + +void release_dirty_mutex(void) +{ + ff_mutex_give(fat_fs.ldrv); +} + +int request_dirty_mutex(void) +{ + return ff_mutex_take(fat_fs.ldrv); +} + +void tlock_mutex(void *p1, void *p2, void *p3) +{ + TC_PRINT("Mutex thread: Started, locking fs\n"); + request_dirty_mutex(); + TC_PRINT("Mutex thread: Lock acquired, yield to switch back to try to open file\n"); + k_sem_give(&run_non_thread_sem); + k_yield(); + + TC_PRINT("Mutex thread: Got back to thread, release mutex now and give semaphore to check " + "if file opened\n"); + k_sem_give(&mutex_unlocked_sem); + release_dirty_mutex(); + + TC_PRINT("Mutex thread: Lock released, thread terminating\n"); +} + +void tfile2_access(void *p1, void *p2, void *p3) +{ + int res; + ssize_t brw; + struct fs_file_t filep2; + + TC_PRINT("File 2 access thread started\n"); + + /* Init fp for 2nd File for parallel access test */ + fs_file_t_init(&filep2); + + /* open 2nd file */ + TC_PRINT("Open file 2\n"); + res = fs_open(&filep2, TEST_FILE2, FS_O_CREATE | FS_O_RDWR); + zassert_ok(res, "Err: File 2 could not be opened [%d]\n", res); + TC_PRINT("File 2 opened 2\n"); + + /* Verify fs_write() not locked */ + brw = fs_write(&filep2, (char *)test_str, strlen(test_str)); + if (brw < 0) { + TC_PRINT("Failed writing to file [%zd]\n", brw); + fs_close(&filep2); + return; + } + + if (brw < strlen(test_str)) { + TC_PRINT("Unable to complete write. Volume full.\n"); + TC_PRINT("Number of bytes written: [%zd]\n", brw); + fs_close(&filep2); + return; + } + + /* Close file and switch back to test context*/ + res = fs_close(&filep2); + zassert_ok(res, "Error closing file [%d]\n", res); + + TC_PRINT("File 2 access thread successfully wrote to file 2\n"); +} + +void test_fat_file_reentrant(void) +{ + zassert_true(test_reentrant_access() == TC_PASS, NULL); + zassert_true(test_reentrant_parallel_file_access() == TC_PASS, NULL); +} +#endif /* CONFIG_FS_FATFS_REENTRANT */ diff --git a/tests/subsys/fs/fat_fs_api/src/test_fat_mkfs.c b/tests/subsys/fs/fat_fs_api/src/test_fat_mkfs.c index 2c567cc2d829..a377fd1a5234 100644 --- a/tests/subsys/fs/fat_fs_api/src/test_fat_mkfs.c +++ b/tests/subsys/fs/fat_fs_api/src/test_fat_mkfs.c @@ -13,9 +13,6 @@ #include #endif -/* FatFs work area */ -static FATFS fat_fs; - /* mounting info */ static struct fs_mount_t fatfs_mnt = { .type = FS_FATFS, diff --git a/tests/subsys/fs/fat_fs_api/src/test_fat_mount.c b/tests/subsys/fs/fat_fs_api/src/test_fat_mount.c index 020104b01ac5..d0c7de813c3b 100644 --- a/tests/subsys/fs/fat_fs_api/src/test_fat_mount.c +++ b/tests/subsys/fs/fat_fs_api/src/test_fat_mount.c @@ -7,10 +7,6 @@ #include "test_fat.h" -#include - -/* FatFs work area */ -static FATFS fat_fs; /* mounting info */ static struct fs_mount_t fatfs_mnt = { diff --git a/tests/subsys/fs/fat_fs_api/src/test_fat_rd_only_mount.c b/tests/subsys/fs/fat_fs_api/src/test_fat_rd_only_mount.c index 7331cc9442f2..0a49b6430f99 100644 --- a/tests/subsys/fs/fat_fs_api/src/test_fat_rd_only_mount.c +++ b/tests/subsys/fs/fat_fs_api/src/test_fat_rd_only_mount.c @@ -6,10 +6,6 @@ #include "test_fat.h" -#include - -/* FatFs work area */ -static FATFS fat_fs; /* mounting info */ static struct fs_mount_t fatfs_mnt = { diff --git a/tests/subsys/fs/fat_fs_api/testcase.yaml b/tests/subsys/fs/fat_fs_api/testcase.yaml index 522b51ceed5a..ac546a4ed75e 100644 --- a/tests/subsys/fs/fat_fs_api/testcase.yaml +++ b/tests/subsys/fs/fat_fs_api/testcase.yaml @@ -14,3 +14,8 @@ tests: filesystem.fat.ram.api: platform_allow: native_posix extra_args: CONF_FILE="prj_native_posix_ram.conf" + filesystem.fat.api.reentrant: + platform_allow: native_posix + extra_configs: + - CONFIG_FS_FATFS_REENTRANT=y + - CONFIG_MULTITHREADING=y From 96dd61842bf8278e699df47e15f465bb16101ae0 Mon Sep 17 00:00:00 2001 From: Nicola Ochsenbein Date: Mon, 27 Feb 2023 10:39:08 +0100 Subject: [PATCH 0142/1906] MAINTAINERS: Add ox11 to FatFs ox11 is maintaining on FatFs. Signed-off-by: Nicola Ochsenbein --- MAINTAINERS.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index c03854962629..a16797280d95 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -1371,6 +1371,16 @@ Filesystems: labels: - "area: File System" +"Filesystems: FatFs reentrant support": + status: maintained + maintainers: + - ox11 + files: + - modules/fatfs/zfs_ffsystem.c + - tests/subsys/fs/fat_fs_api/src/test_fat_file_reentrant.c + labels: + - "area: File System" + Formatted Output: status: maintained maintainers: From 516b6730c6ec0b191ab50f5d6866a65cfbe5d1ca Mon Sep 17 00:00:00 2001 From: Nicola Ochsenbein Date: Mon, 27 Feb 2023 12:00:16 +0100 Subject: [PATCH 0143/1906] doc: release-notes: Update release notes 3.4 Update release notes 3.4 with the new FatFs reentrant Kconfig option. Signed-off-by: Nicola Ochsenbein --- doc/releases/release-notes-3.4.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/releases/release-notes-3.4.rst b/doc/releases/release-notes-3.4.rst index f98e0bc9947b..a420828dc2f9 100644 --- a/doc/releases/release-notes-3.4.rst +++ b/doc/releases/release-notes-3.4.rst @@ -324,6 +324,10 @@ Devicetree Libraries / Subsystems ********************** +* File systems + + * Added :kconfig:option:`CONFIG_FS_FATFS_REENTRANT` to enable the FAT FS reentrant option. + HALs **** From 1adec07f011dbfa454c617997d51ccd833566ce5 Mon Sep 17 00:00:00 2001 From: Lucas Tamborrino Date: Mon, 27 Feb 2023 16:31:21 -0300 Subject: [PATCH 0144/1906] drivers: spi: esp32xx: refactor SPI DMA preprocessor identifiers Change the preprocessor identifier from CONFIG_SOC_ESP32C3 to SOC_GDMA_SUPPORTED so it can include ESP32S3 in GDMA routines. Remove hardcoded values from hal calls to use dma_host instead. Signed-off-by: Lucas Tamborrino --- drivers/spi/spi_esp32_spim.c | 14 ++++++++------ drivers/spi/spi_esp32_spim.h | 4 ++-- dts/riscv/espressif/esp32c3.dtsi | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi_esp32_spim.c b/drivers/spi/spi_esp32_spim.c index 21c29b0847d3..2bcab3347ee5 100644 --- a/drivers/spi/spi_esp32_spim.c +++ b/drivers/spi/spi_esp32_spim.c @@ -19,9 +19,11 @@ LOG_MODULE_REGISTER(esp32_spi, CONFIG_SPI_LOG_LEVEL); #ifndef CONFIG_SOC_ESP32C3 #include #else +#include +#endif +#ifdef SOC_GDMA_SUPPORTED #include #include -#include #endif #include #include "spi_context.h" @@ -163,17 +165,17 @@ static int spi_esp32_init_dma(const struct device *dev) return -EIO; } -#ifdef CONFIG_SOC_ESP32C3 - gdma_hal_init(&data->hal_gdma, 0); +#ifdef SOC_GDMA_SUPPORTED + gdma_hal_init(&data->hal_gdma, cfg->dma_host); gdma_ll_enable_clock(data->hal_gdma.dev, true); gdma_ll_tx_reset_channel(data->hal_gdma.dev, cfg->dma_host); gdma_ll_rx_reset_channel(data->hal_gdma.dev, cfg->dma_host); - gdma_ll_tx_connect_to_periph(data->hal_gdma.dev, cfg->dma_host, 0); - gdma_ll_rx_connect_to_periph(data->hal_gdma.dev, cfg->dma_host, 0); + gdma_ll_tx_connect_to_periph(data->hal_gdma.dev, cfg->dma_host, cfg->dma_host); + gdma_ll_rx_connect_to_periph(data->hal_gdma.dev, cfg->dma_host, cfg->dma_host); channel_offset = 0; #else channel_offset = 1; -#endif /* CONFIG_SOC_ESP32C3 */ +#endif /* SOC_GDMA_SUPPORTED */ #ifdef CONFIG_SOC_ESP32 /*Connect SPI and DMA*/ DPORT_SET_PERI_REG_BITS(DPORT_SPI_DMA_CHAN_SEL_REG, 3, cfg->dma_host + 1, diff --git a/drivers/spi/spi_esp32_spim.h b/drivers/spi/spi_esp32_spim.h index f6242c9e71c2..ecaf6397bb90 100644 --- a/drivers/spi/spi_esp32_spim.h +++ b/drivers/spi/spi_esp32_spim.h @@ -9,7 +9,7 @@ #include #include -#ifdef CONFIG_SOC_ESP32C3 +#ifdef SOC_GDMA_SUPPORTED #include #endif @@ -42,7 +42,7 @@ struct spi_esp32_data { struct spi_context ctx; spi_hal_context_t hal; spi_hal_config_t hal_config; -#ifdef CONFIG_SOC_ESP32C3 +#ifdef SOC_GDMA_SUPPORTED gdma_hal_context_t hal_gdma; #endif spi_hal_timing_conf_t timing_config; diff --git a/dts/riscv/espressif/esp32c3.dtsi b/dts/riscv/espressif/esp32c3.dtsi index ac0ef9e028c2..8e3afbde687c 100644 --- a/dts/riscv/espressif/esp32c3.dtsi +++ b/dts/riscv/espressif/esp32c3.dtsi @@ -206,7 +206,7 @@ interrupt-parent = <&intc>; clocks = <&rtc ESP32_SPI2_MODULE>; dma-clk = ; - dma-host = <1>; + dma-host = <0>; status = "disabled"; }; From fa358f9757dc03a75e3f1fc708e7b83201895821 Mon Sep 17 00:00:00 2001 From: Lucas Tamborrino Date: Mon, 27 Feb 2023 16:31:21 -0300 Subject: [PATCH 0145/1906] dts: esp32s3: Add SPI support Add SPI support for esp32s3 Signed-off-by: Lucas Tamborrino --- .../esp32s3_devkitm-pinctrl.dtsi | 24 +++++++++++++++++++ .../esp32s3_devkitm/esp32s3_devkitm.dts | 16 +++++++++++++ .../esp32s3_devkitm/esp32s3_devkitm.yaml | 1 + dts/xtensa/espressif/esp32s3.dtsi | 21 ++++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm-pinctrl.dtsi b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm-pinctrl.dtsi index e07a3a0e7e53..eab6da9eb5f2 100644 --- a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm-pinctrl.dtsi +++ b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm-pinctrl.dtsi @@ -38,4 +38,28 @@ output-high; }; }; + + spim2_default: spim2_default { + group1 { + pinmux = , + , + ; + }; + group2 { + pinmux = ; + output-low; + }; + }; + + spim3_default: spim3_default { + group1 { + pinmux = , + , + ; + }; + group2 { + pinmux = ; + output-low; + }; + }; }; diff --git a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts index 6bd3583ea57b..10f2b5aa46a8 100644 --- a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts +++ b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts @@ -72,6 +72,22 @@ pinctrl-names = "default"; }; +&spi2 { + #address-cells = <1>; + #size-cells = <0>; + status = "okay"; + pinctrl-0 = <&spim2_default>; + pinctrl-names = "default"; +}; + +&spi3 { + #address-cells = <1>; + #size-cells = <0>; + status = "okay"; + pinctrl-0 = <&spim3_default>; + pinctrl-names = "default"; +}; + &flash0 { status = "okay"; partitions { diff --git a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml index f93155836def..96c8ff0db125 100644 --- a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml +++ b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml @@ -8,6 +8,7 @@ supported: - gpio - uart - i2c + - spi testing: ignore_tags: - net diff --git a/dts/xtensa/espressif/esp32s3.dtsi b/dts/xtensa/espressif/esp32s3.dtsi index 03873a522824..f784ad28f5c8 100644 --- a/dts/xtensa/espressif/esp32s3.dtsi +++ b/dts/xtensa/espressif/esp32s3.dtsi @@ -173,5 +173,26 @@ status = "disabled"; }; + spi2: spi@60024000 { + compatible = "espressif,esp32-spi"; + reg = <0x60024000 DT_SIZE_K(4)>; + interrupts = ; + interrupt-parent = <&intc>; + clocks = <&rtc ESP32_SPI2_MODULE>; + dma-clk = ; + dma-host = <0>; + status = "disabled"; + }; + + spi3: spi@60025000 { + compatible = "espressif,esp32-spi"; + reg = <0x60025000 DT_SIZE_K(4)>; + interrupts = ; + interrupt-parent = <&intc>; + clocks = <&rtc ESP32_SPI3_MODULE>; + dma-clk = ; + dma-host = <1>; + status = "disabled"; + }; }; }; From 9015f23b75b83ade5aacce5ba0d2ce30a3b02a89 Mon Sep 17 00:00:00 2001 From: Lucas Tamborrino Date: Mon, 27 Feb 2023 16:31:22 -0300 Subject: [PATCH 0146/1906] tests: spi_loopback: Add esp32s3 Add esp32s3 to spi_loopback test Signed-off-by: Lucas Tamborrino --- .../spi_loopback/boards/esp32s3_devkitm.conf | 1 + .../boards/esp32s3_devkitm.overlay | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/drivers/spi/spi_loopback/boards/esp32s3_devkitm.conf create mode 100644 tests/drivers/spi/spi_loopback/boards/esp32s3_devkitm.overlay diff --git a/tests/drivers/spi/spi_loopback/boards/esp32s3_devkitm.conf b/tests/drivers/spi/spi_loopback/boards/esp32s3_devkitm.conf new file mode 100644 index 000000000000..fb0909611c89 --- /dev/null +++ b/tests/drivers/spi/spi_loopback/boards/esp32s3_devkitm.conf @@ -0,0 +1 @@ +CONFIG_SPI_ESP32_INTERRUPT=y diff --git a/tests/drivers/spi/spi_loopback/boards/esp32s3_devkitm.overlay b/tests/drivers/spi/spi_loopback/boards/esp32s3_devkitm.overlay new file mode 100644 index 000000000000..389546fdcd25 --- /dev/null +++ b/tests/drivers/spi/spi_loopback/boards/esp32s3_devkitm.overlay @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Kumar Gala + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&spi3 { + slow@0 { + compatible = "test-spi-loopback-slow"; + reg = <0>; + spi-max-frequency = <100000>; + }; + fast@0 { + compatible = "test-spi-loopback-fast"; + reg = <0>; + spi-max-frequency = <16000000>; + }; +}; + +&spi3 { + dma-enabled; +}; From 7f4dadee3a20a53b23a75f9cef39dcb9cb8e17df Mon Sep 17 00:00:00 2001 From: Lucas Tamborrino Date: Mon, 27 Feb 2023 16:31:22 -0300 Subject: [PATCH 0147/1906] drivers: spi: esp32xx: add support for dedicated CS Currently the driver only support software controlled CS defined by cs-gpios property. This commit enables the possibility of using dedicated CS by setting the pins on pinctrl and omitting the cs-gpios property. Signed-off-by: Lucas Tamborrino --- drivers/spi/spi_esp32_spim.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi_esp32_spim.c b/drivers/spi/spi_esp32_spim.c index 2bcab3347ee5..56f1d648d060 100644 --- a/drivers/spi/spi_esp32_spim.c +++ b/drivers/spi/spi_esp32_spim.c @@ -107,6 +107,10 @@ static int IRAM_ATTR spi_esp32_transfer(const struct device *dev) hal_trans->tx_bitlen = bit_len; hal_trans->rx_bitlen = bit_len; + /* keep cs line active ultil last transmission */ + hal_trans->cs_keep_active = + (!ctx->num_cs_gpios && (ctx->rx_count > 1 || ctx->tx_count > 1)); + /* configure SPI */ spi_hal_setup_trans(hal, hal_dev, hal_trans); spi_hal_prepare_data(hal, hal_dev, hal_trans); @@ -324,8 +328,7 @@ static int IRAM_ATTR spi_esp32_configure(const struct device *dev, data->trans_config.line_mode.addr_lines = 1; data->trans_config.line_mode.cmd_lines = 1; - /* keep cs line after transmission not supported */ - data->trans_config.cs_keep_active = 0; + hal_dev->cs_setup = 1; /* SPI mode */ hal_dev->mode = 0; @@ -339,6 +342,16 @@ static int IRAM_ATTR spi_esp32_configure(const struct device *dev, spi_hal_setup_device(hal, hal_dev); + /* + * Workaround for ESP32S3 and ESP32C3 SoC. This dummy transaction is needed to sync CLK and + * software controlled CS when SPI is in mode 3 + */ +#if defined(CONFIG_SOC_ESP32S3) || defined(CONFIG_SOC_ESP32C3) + if (ctx->num_cs_gpios && (hal_dev->mode & (SPI_MODE_CPOL | SPI_MODE_CPHA))) { + spi_esp32_transfer(dev); + } +#endif + return 0; } From 935e8708cd9acf1b3e973dfec85f5b555eb5fbc6 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Fri, 10 Mar 2023 12:58:21 +0100 Subject: [PATCH 0148/1906] samples: Bluetooth: Add nrf5340_audio_dk board config to audio samples Add the nrf5340_audio_dk board config to the unicast audio samples that use LC3. Signed-off-by: Emil Gydesen --- .../boards/nrf5340_audio_dk_nrf5340_cpuapp.conf | 8 ++++++++ .../boards/nrf5340_audio_dk_nrf5340_cpuapp.conf | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 samples/bluetooth/unicast_audio_client/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf create mode 100644 samples/bluetooth/unicast_audio_server/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf diff --git a/samples/bluetooth/unicast_audio_client/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf b/samples/bluetooth/unicast_audio_client/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf new file mode 100644 index 000000000000..f7c6bbfd3db0 --- /dev/null +++ b/samples/bluetooth/unicast_audio_client/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf @@ -0,0 +1,8 @@ +# For LC3 the following configs are needed +CONFIG_FPU=y +CONFIG_LIBLC3=y +# The LC3 codec uses a large amount of stack. This app runs the codec in the work-queue, hence +# inctease stack size for that thread. +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 +# LC3 lib requires floating point support in the c-lib NEWLIB is one way of getting that. +CONFIG_NEWLIB_LIBC=y diff --git a/samples/bluetooth/unicast_audio_server/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf b/samples/bluetooth/unicast_audio_server/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf new file mode 100644 index 000000000000..f7c6bbfd3db0 --- /dev/null +++ b/samples/bluetooth/unicast_audio_server/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf @@ -0,0 +1,8 @@ +# For LC3 the following configs are needed +CONFIG_FPU=y +CONFIG_LIBLC3=y +# The LC3 codec uses a large amount of stack. This app runs the codec in the work-queue, hence +# inctease stack size for that thread. +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 +# LC3 lib requires floating point support in the c-lib NEWLIB is one way of getting that. +CONFIG_NEWLIB_LIBC=y From a87d39561050eddddb3b31be84c28654ac660370 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Fri, 10 Mar 2023 12:59:06 +0100 Subject: [PATCH 0149/1906] tests: Bluetooth: Add nrf5340_audio_dk board config for shell Add a nrf5340_audio_dk board config the for BT shell which enables support for LC3. Signed-off-by: Emil Gydesen --- .../shell/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/bluetooth/shell/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf diff --git a/tests/bluetooth/shell/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf b/tests/bluetooth/shell/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf new file mode 100644 index 000000000000..f7c6bbfd3db0 --- /dev/null +++ b/tests/bluetooth/shell/boards/nrf5340_audio_dk_nrf5340_cpuapp.conf @@ -0,0 +1,8 @@ +# For LC3 the following configs are needed +CONFIG_FPU=y +CONFIG_LIBLC3=y +# The LC3 codec uses a large amount of stack. This app runs the codec in the work-queue, hence +# inctease stack size for that thread. +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 +# LC3 lib requires floating point support in the c-lib NEWLIB is one way of getting that. +CONFIG_NEWLIB_LIBC=y From 4fbabc14c5662ecdb6edb257387188ed118577ea Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Fri, 10 Mar 2023 15:02:06 +0100 Subject: [PATCH 0150/1906] Bluetooth: Audio: Shell: Fix bug with txing_stream and bap send The bap send command would set txing_stream but the pointer would never be reset. The txing_stream is mainly to handling the start_sine, so only {start|stop}_sine commands now sets this. Signed-off-by: Emil Gydesen --- subsys/bluetooth/shell/bap.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/subsys/bluetooth/shell/bap.c b/subsys/bluetooth/shell/bap.c index e416c0eb3609..4715f4ded115 100644 --- a/subsys/bluetooth/shell/bap.c +++ b/subsys/bluetooth/shell/bap.c @@ -2219,9 +2219,7 @@ static int cmd_send(const struct shell *sh, size_t argc, char *argv[]) return -ENOEXEC; } - if (txing_stream == NULL) { - txing_stream = default_stream; - } else { + if (txing_stream != NULL) { shell_error(sh, "A stream %p is already TXing", txing_stream); return -ENOEXEC; @@ -2230,8 +2228,6 @@ static int cmd_send(const struct shell *sh, size_t argc, char *argv[]) if (txing_stream->qos == NULL) { shell_error(sh, "NULL stream QoS"); - txing_stream = NULL; - return -ENOEXEC; } @@ -2241,8 +2237,6 @@ static int cmd_send(const struct shell *sh, size_t argc, char *argv[]) shell_print(sh, "Unable to send: len %d > %u MTU", len, txing_stream->qos->sdu); - txing_stream = NULL; - return -ENOEXEC; } } else { @@ -2263,8 +2257,6 @@ static int cmd_send(const struct shell *sh, size_t argc, char *argv[]) shell_print(sh, "Unable to send: %d", -ret); net_buf_unref(buf); - txing_stream = NULL; - return -ENOEXEC; } From 0ebc7c2b6901ca82ff34f09c7fb99dcd2e44980e Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Fri, 10 Mar 2023 17:49:16 +0100 Subject: [PATCH 0151/1906] Bluetooth: Audio: Rename BT_AUDIO_LC3_PRESET to BT_BAP... This was missing from the recent BT_AUDIO -> BT_BAP rename. Signed-off-by: Emil Gydesen --- .../zephyr/bluetooth/audio/bap_lc3_preset.h | 246 +++++++++--------- 1 file changed, 123 insertions(+), 123 deletions(-) diff --git a/include/zephyr/bluetooth/audio/bap_lc3_preset.h b/include/zephyr/bluetooth/audio/bap_lc3_preset.h index 8d92b8a42e04..3781be1a6db1 100644 --- a/include/zephyr/bluetooth/audio/bap_lc3_preset.h +++ b/include/zephyr/bluetooth/audio/bap_lc3_preset.h @@ -19,7 +19,7 @@ struct bt_bap_lc3_preset { }; /** Helper to declare an LC3 preset structure */ -#define BT_AUDIO_LC3_PRESET(_codec, _qos) \ +#define BT_BAP_LC3_PRESET(_codec, _qos) \ { \ .codec = _codec, .qos = _qos, \ } @@ -33,8 +33,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_8_1_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(26u, 2u, 8u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(26u, 2u, 8u, 40000u)) /** * @brief Helper to declare LC3 Unicast 8_2_1 codec configuration @@ -43,8 +43,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_8_2_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(30u, 2u, 10u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(30u, 2u, 10u, 40000u)) /** * @brief Helper to declare LC3 Unicast 16_1_1 codec configuration @@ -53,8 +53,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_16_1_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(30u, 2u, 8u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(30u, 2u, 8u, 40000u)) /** * @brief Helper to declare LC3 Unicast 16_2_1 codec configuration @@ -65,8 +65,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_16_2_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(40u, 2u, 10u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(40u, 2u, 10u, 40000u)) /** * @brief Helper to declare LC3 Unicast 24_1_1 codec configuration @@ -75,8 +75,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_24_1_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(45u, 2u, 8u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(45u, 2u, 8u, 40000u)) /** * @brief Helper to declare LC3 Unicast 24_2_1 codec configuration @@ -87,8 +87,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_24_2_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(60u, 2u, 10u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(60u, 2u, 10u, 40000u)) /** * @brief Helper to declare LC3 Unicast 32_1_1 codec configuration @@ -97,8 +97,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_32_1_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(60u, 2u, 8u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(60u, 2u, 8u, 40000u)) /** * @brief Helper to declare LC3 Unicast 32_2_1 codec configuration @@ -107,8 +107,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_32_2_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(80u, 2u, 10u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(80u, 2u, 10u, 40000u)) /** * @brief Helper to declare LC3 Unicast 441_1_1 codec configuration @@ -117,7 +117,7 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_441_1_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET( \ + BT_BAP_LC3_PRESET( \ BT_CODEC_LC3_CONFIG_441_1(_loc, _stream_context), \ BT_CODEC_QOS(8163u, BT_CODEC_QOS_FRAMED, BT_CODEC_QOS_2M, 97u, 5u, 24u, 40000u)) @@ -128,7 +128,7 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_441_2_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET( \ + BT_BAP_LC3_PRESET( \ BT_CODEC_LC3_CONFIG_441_2(_loc, _stream_context), \ BT_CODEC_QOS(10884u, BT_CODEC_QOS_FRAMED, BT_CODEC_QOS_2M, 130u, 5u, 31u, 40000u)) @@ -139,8 +139,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_48_1_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(75u, 5u, 15u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(75u, 5u, 15u, 40000u)) /** * @brief Helper to declare LC3 Unicast 48_2_1 codec configuration @@ -149,8 +149,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_48_2_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(100u, 5u, 20u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(100u, 5u, 20u, 40000u)) /** * @brief Helper to declare LC3 Unicast 48_3_1 codec configuration @@ -159,8 +159,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_48_3_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_3(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(90u, 5u, 15u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_3(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(90u, 5u, 15u, 40000u)) /** * @brief Helper to declare LC3 Unicast 48_4_1 codec configuration @@ -169,8 +169,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_48_4_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_4(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(120u, 5u, 20u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_4(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(120u, 5u, 20u, 40000u)) /** * @brief Helper to declare LC3 Unicast 8_5_1 codec configuration @@ -179,8 +179,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_48_5_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_5(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(117u, 5u, 15u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_5(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(117u, 5u, 15u, 40000u)) /** * @brief Helper to declare LC3 Unicast 48_6_1 codec configuration @@ -189,8 +189,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_48_6_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_6(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(155u, 5u, 20u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_6(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(155u, 5u, 20u, 40000u)) /** * @brief Helper to declare LC3 Unicast 8_1_2 codec configuration @@ -200,8 +200,8 @@ struct bt_bap_lc3_preset { */ /* Following presets are for unicast high reliability audio data */ #define BT_BAP_LC3_UNICAST_PRESET_8_1_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(26u, 13u, 75u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(26u, 13u, 75u, 40000u)) /** * @brief Helper to declare LC3 Unicast 8_2_2 codec configuration @@ -210,8 +210,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_8_2_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(30u, 13u, 95u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(30u, 13u, 95u, 40000u)) /** * @brief Helper to declare LC3 Unicast 16_1_2 codec configuration @@ -220,8 +220,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_16_1_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(30u, 13u, 75u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(30u, 13u, 75u, 40000u)) /** * @brief Helper to declare LC3 Unicast 16_2_2 codec configuration @@ -230,8 +230,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_16_2_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(40u, 13u, 95u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(40u, 13u, 95u, 40000u)) /** * @brief Helper to declare LC3 Unicast 24_1_2 codec configuration @@ -240,8 +240,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_24_1_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(45u, 13u, 75u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(45u, 13u, 75u, 40000u)) /** * @brief Helper to declare LC3 Unicast 24_2_2 codec configuration @@ -250,8 +250,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_24_2_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(60u, 13u, 95u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(60u, 13u, 95u, 40000u)) /** * @brief Helper to declare LC3 Unicast 32_1_2 codec configuration @@ -260,8 +260,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_32_1_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(60u, 13u, 75u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(60u, 13u, 75u, 40000u)) /** * @brief Helper to declare LC3 Unicast 32_2_2 codec configuration @@ -270,8 +270,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_32_2_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(80u, 13u, 95u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(80u, 13u, 95u, 40000u)) /** * @brief Helper to declare LC3 Unicast 441_1_2 codec configuration @@ -280,7 +280,7 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_441_1_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET( \ + BT_BAP_LC3_PRESET( \ BT_CODEC_LC3_CONFIG_441_1(_loc, _stream_context), \ BT_CODEC_QOS(8163u, BT_CODEC_QOS_FRAMED, BT_CODEC_QOS_2M, 97u, 13u, 80u, 40000u)) @@ -291,9 +291,9 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_441_2_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_441_2(_loc, _stream_context), \ - BT_CODEC_QOS(10884u, BT_CODEC_QOS_FRAMED, BT_CODEC_QOS_2M, 130u, 13u, \ - 85u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_441_2(_loc, _stream_context), \ + BT_CODEC_QOS(10884u, BT_CODEC_QOS_FRAMED, BT_CODEC_QOS_2M, 130u, 13u, \ + 85u, 40000u)) /** * @brief Helper to declare LC3 Unicast 48_1_2 codec configuration @@ -302,8 +302,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_48_1_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(75u, 13u, 75u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(75u, 13u, 75u, 40000u)) /** * @brief Helper to declare LC3 Unicast 48_2_2 codec configuration @@ -312,8 +312,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_48_2_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(100u, 13u, 95u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(100u, 13u, 95u, 40000u)) /** * @brief Helper to declare LC3 Unicast 48_3_2 codec configuration @@ -322,8 +322,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_48_3_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_3(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(90u, 13u, 75u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_3(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(90u, 13u, 75u, 40000u)) /** * @brief Helper to declare LC3 Unicast 48_4_2 codec configuration @@ -332,8 +332,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_48_4_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_4(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(120u, 13u, 100u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_4(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(120u, 13u, 100u, 40000u)) /** * @brief Helper to declare LC3 Unicast 48_5_2 codec configuration @@ -342,8 +342,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_48_5_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_5(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(117u, 13u, 75u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_5(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(117u, 13u, 75u, 40000u)) /** * @brief Helper to declare LC3 Unicast 48_6_2 codec configuration @@ -352,8 +352,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_UNICAST_PRESET_48_6_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_6(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(155u, 13u, 100u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_6(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(155u, 13u, 100u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 8_1_1 codec configuration @@ -363,8 +363,8 @@ struct bt_bap_lc3_preset { */ /* LC3 Broadcast presets defined by table 6.4 in the BAP v1.0 specification */ #define BT_BAP_LC3_BROADCAST_PRESET_8_1_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(26u, 2u, 8u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(26u, 2u, 8u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 8_2_1 codec configuration @@ -373,8 +373,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_8_2_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(30u, 2u, 10u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(30u, 2u, 10u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 16_1_1 codec configuration @@ -383,8 +383,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_16_1_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(30u, 2u, 8u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(30u, 2u, 8u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 16_2_1 codec configuration @@ -395,8 +395,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_16_2_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(40u, 2u, 10u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(40u, 2u, 10u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 24_1_1 codec configuration @@ -405,8 +405,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_24_1_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(45u, 2u, 8u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(45u, 2u, 8u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 24_2_1 codec configuration @@ -417,8 +417,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_24_2_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(60u, 2u, 10u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(60u, 2u, 10u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 32_1_1 codec configuration @@ -427,8 +427,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_32_1_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(60u, 2u, 8u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(60u, 2u, 8u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 32_2_1 codec configuration @@ -437,8 +437,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_32_2_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(80u, 2u, 10u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(80u, 2u, 10u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 441_1_1 codec configuration @@ -447,7 +447,7 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_441_1_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET( \ + BT_BAP_LC3_PRESET( \ BT_CODEC_LC3_CONFIG_441_1(_loc, _stream_context), \ BT_CODEC_QOS(8163u, BT_CODEC_QOS_FRAMED, BT_CODEC_QOS_2M, 97u, 4u, 24u, 40000u)) @@ -458,7 +458,7 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_441_2_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET( \ + BT_BAP_LC3_PRESET( \ BT_CODEC_LC3_CONFIG_441_2(_loc, _stream_context), \ BT_CODEC_QOS(10884u, BT_CODEC_QOS_FRAMED, BT_CODEC_QOS_2M, 130u, 4u, 31u, 40000u)) @@ -469,8 +469,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_48_1_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(75u, 4u, 15u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(75u, 4u, 15u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 48_2_1 codec configuration @@ -479,8 +479,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_48_2_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(100u, 4u, 20u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(100u, 4u, 20u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 48_3_1 codec configuration @@ -489,8 +489,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_48_3_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_3(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(90u, 4u, 15u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_3(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(90u, 4u, 15u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 48_4_1 codec configuration @@ -499,8 +499,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_48_4_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_4(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(120u, 4u, 20u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_4(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(120u, 4u, 20u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 48_5_1 codec configuration @@ -509,8 +509,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_48_5_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_5(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(117u, 4u, 15u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_5(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(117u, 4u, 15u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 48_6_1 codec configuration @@ -519,8 +519,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_48_6_1(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_6(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(155u, 4u, 20u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_6(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(155u, 4u, 20u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 8_1_2 codec configuration @@ -530,8 +530,8 @@ struct bt_bap_lc3_preset { */ /* Following presets are for broadcast high reliability audio data */ #define BT_BAP_LC3_BROADCAST_PRESET_8_1_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(26u, 4u, 45u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(26u, 4u, 45u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 8_2_2 codec configuration @@ -540,8 +540,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_8_2_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(30u, 4u, 60u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_8_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(30u, 4u, 60u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 16_1_2 codec configuration @@ -550,8 +550,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_16_1_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(30u, 4u, 45u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(30u, 4u, 45u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 16_2_2 codec configuration @@ -562,8 +562,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_16_2_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(40u, 4u, 60u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_16_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(40u, 4u, 60u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 24_1_2 codec configuration @@ -572,8 +572,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_24_1_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(45u, 4u, 45u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(45u, 4u, 45u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 24_2_2 codec configuration @@ -584,8 +584,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_24_2_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(60u, 4u, 60u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_24_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(60u, 4u, 60u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 32_1_2 codec configuration @@ -594,8 +594,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_32_1_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(60u, 4u, 45u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(60u, 4u, 45u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 32_2_2 codec configuration @@ -604,8 +604,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_32_2_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(80u, 4u, 60u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_32_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(80u, 4u, 60u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 441_1_2 codec configuration @@ -614,7 +614,7 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_441_1_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET( \ + BT_BAP_LC3_PRESET( \ BT_CODEC_LC3_CONFIG_441_1(_loc, _stream_context), \ BT_CODEC_QOS(8163u, BT_CODEC_QOS_FRAMED, BT_CODEC_QOS_2M, 97u, 4u, 54u, 40000u)) @@ -625,7 +625,7 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_441_2_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET( \ + BT_BAP_LC3_PRESET( \ BT_CODEC_LC3_CONFIG_441_2(_loc, _stream_context), \ BT_CODEC_QOS(10884u, BT_CODEC_QOS_FRAMED, BT_CODEC_QOS_2M, 130u, 4u, 60u, 40000u)) @@ -636,8 +636,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_48_1_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_1(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(75u, 4u, 50u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_1(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(75u, 4u, 50u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 48_2_2 codec configuration @@ -646,8 +646,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_48_2_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_2(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(100u, 4u, 65u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_2(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(100u, 4u, 65u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 48_3_2 codec configuration @@ -656,8 +656,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_48_3_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_3(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(90u, 4u, 50u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_3(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(90u, 4u, 50u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 48_4_2 codec configuration @@ -666,8 +666,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_48_4_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_4(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(120u, 4u, 65u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_4(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(120u, 4u, 65u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 48_5_2 codec configuration @@ -676,8 +676,8 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_48_5_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_5(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_7_5_UNFRAMED(117u, 4u, 50u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_5(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_7_5_UNFRAMED(117u, 4u, 50u, 40000u)) /** * @brief Helper to declare LC3 Broadcast 48_6_2 codec configuration @@ -686,7 +686,7 @@ struct bt_bap_lc3_preset { * @param _stream_context Stream context (BT_AUDIO_CONTEXT_*) */ #define BT_BAP_LC3_BROADCAST_PRESET_48_6_2(_loc, _stream_context) \ - BT_AUDIO_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_6(_loc, _stream_context), \ - BT_CODEC_LC3_QOS_10_UNFRAMED(155u, 4u, 65u, 40000u)) + BT_BAP_LC3_PRESET(BT_CODEC_LC3_CONFIG_48_6(_loc, _stream_context), \ + BT_CODEC_LC3_QOS_10_UNFRAMED(155u, 4u, 65u, 40000u)) #endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_BAP_LC3_PRESET_ */ From 1eff8e76bd728b7cab14f044911d9a729eb41db4 Mon Sep 17 00:00:00 2001 From: Andriy Gelman Date: Sun, 12 Mar 2023 16:31:05 -0400 Subject: [PATCH 0152/1906] drivers: spi: spi_esp32_spim: Fix potential tx_temp leak If rx_temp allocation fails then tx_temp needs to freed. Signed-off-by: Andriy Gelman --- drivers/spi/spi_esp32_spim.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/spi/spi_esp32_spim.c b/drivers/spi/spi_esp32_spim.c index 56f1d648d060..878c021c0e84 100644 --- a/drivers/spi/spi_esp32_spim.c +++ b/drivers/spi/spi_esp32_spim.c @@ -95,6 +95,7 @@ static int IRAM_ATTR spi_esp32_transfer(const struct device *dev) rx_temp = k_calloc(((ctx->rx_len << 3) + 31) / 8, sizeof(uint8_t)); if (!rx_temp) { LOG_ERR("Error allocating temp buffer Rx"); + k_free(tx_temp); return -ENOMEM; } } From 6c3998d4947349a6fe00fb5370099812e940d1e5 Mon Sep 17 00:00:00 2001 From: Andriy Gelman Date: Sun, 12 Mar 2023 16:32:52 -0400 Subject: [PATCH 0153/1906] drivers: spi: spi_esp32_spim: Remove check for NULL before freeing As per k_free() documentation it accepts a NULL argument. Signed-off-by: Andriy Gelman --- drivers/spi/spi_esp32_spim.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/spi/spi_esp32_spim.c b/drivers/spi/spi_esp32_spim.c index 878c021c0e84..50e9ab58eb0b 100644 --- a/drivers/spi/spi_esp32_spim.c +++ b/drivers/spi/spi_esp32_spim.c @@ -133,13 +133,8 @@ static int IRAM_ATTR spi_esp32_transfer(const struct device *dev) spi_context_update_rx(&data->ctx, data->dfs, chunk_len); - if (tx_temp) { - k_free(tx_temp); - } - - if (rx_temp) { - k_free(rx_temp); - } + k_free(tx_temp); + k_free(rx_temp); return 0; } From 07cd477201eb421038c39577f4b69b1be3214a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katarzyna=20Gi=C4=85d=C5=82a?= Date: Mon, 13 Mar 2023 10:38:55 +0100 Subject: [PATCH 0154/1906] tests: drivers: regulator: fixed: Unify set of pins for nrf9160dk_nrf9160 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unify set of the pins on `nrf9160dk_nrf9160`, which is used by `gpio_loopback` fixture. Signed-off-by: Katarzyna Giądła --- .../regulator/fixed/boards/nrf9160dk_nrf9160.overlay | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/drivers/regulator/fixed/boards/nrf9160dk_nrf9160.overlay b/tests/drivers/regulator/fixed/boards/nrf9160dk_nrf9160.overlay index 289c23caeb9c..cfde997642d0 100644 --- a/tests/drivers/regulator/fixed/boards/nrf9160dk_nrf9160.overlay +++ b/tests/drivers/regulator/fixed/boards/nrf9160dk_nrf9160.overlay @@ -7,12 +7,12 @@ / { regulator { - /* Arduino D0 */ - enable-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>; + /* Arduino D10 */ + enable-gpios = <&gpio0 10 GPIO_ACTIVE_HIGH>; }; resources { - /* Arduino D1 */ - check-gpios = <&gpio0 1 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; + /* Arduino D11 */ + check-gpios = <&gpio0 11 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; }; }; From 6648da731bb9882309457a3ab6ce710499ce93b8 Mon Sep 17 00:00:00 2001 From: Aleksander Wasaznik Date: Tue, 10 Jan 2023 21:56:09 +0100 Subject: [PATCH 0155/1906] Bluetooth: Host: SMP Keypress Notification Add experimental support for SMP Keypress Notification. Signed-off-by: Aleksander Wasaznik --- include/zephyr/bluetooth/conn.h | 57 +++++++++++++++++++++ subsys/bluetooth/host/Kconfig | 7 +++ subsys/bluetooth/host/conn.c | 14 ++++++ subsys/bluetooth/host/smp.c | 88 +++++++++++++++++++++++++++++++++ subsys/bluetooth/host/smp.h | 2 + subsys/bluetooth/shell/bt.c | 51 +++++++++++++++++++ tests/bluetooth/shell/prj.conf | 1 + 7 files changed, 220 insertions(+) diff --git a/include/zephyr/bluetooth/conn.h b/include/zephyr/bluetooth/conn.h index 2fb1676aa494..ab243d907cba 100644 --- a/include/zephyr/bluetooth/conn.h +++ b/include/zephyr/bluetooth/conn.h @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -466,6 +467,19 @@ struct bt_conn_le_tx_power { int8_t max_level; }; +/** @brief Passkey Keypress Notification type + * + * The numeric values are the same as in the Core specification for Pairing + * Keypress Notification PDU. + */ +enum bt_conn_auth_keypress { + BT_CONN_AUTH_KEYPRESS_ENTRY_STARTED = 0x00, + BT_CONN_AUTH_KEYPRESS_DIGIT_ENTERED = 0x01, + BT_CONN_AUTH_KEYPRESS_DIGIT_ERASED = 0x02, + BT_CONN_AUTH_KEYPRESS_CLEARED = 0x03, + BT_CONN_AUTH_KEYPRESS_ENTRY_COMPLETED = 0x04, +}; + /** @brief Get connection info * * @param conn Connection object. @@ -1223,6 +1237,32 @@ struct bt_conn_auth_cb { */ void (*passkey_display)(struct bt_conn *conn, unsigned int passkey); +#if defined(CONFIG_BT_PASSKEY_KEYPRESS) + /** @brief Receive Passkey Keypress Notification during pairing + * + * This allows the remote device to use the local device to give users + * feedback on the progress of entering the passkey over there. This is + * useful when the remote device itself has no display suitable for + * showing the progress. + * + * The handler of this callback is expected to keep track of the number + * of digits entered and show a password-field-like feedback to the + * user. + * + * This callback is only relevant while the local side does Passkey + * Display. + * + * The event type is verified to be in range of the enum. No other + * sanitization has been done. The remote could send a large number of + * events of any type in any order. + * + * @param conn The related connection. + * @param type Type of event. Verified in range of the enum. + */ + void (*passkey_display_keypress)(struct bt_conn *conn, + enum bt_conn_auth_keypress type); +#endif + /** @brief Request the user to enter a passkey. * * When called the user is expected to enter a passkey. The passkey @@ -1437,6 +1477,23 @@ int bt_conn_auth_info_cb_unregister(struct bt_conn_auth_info_cb *cb); */ int bt_conn_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey); +/** @brief Send Passkey Keypress Notification during pairing + * + * This function may be called only after passkey_entry callback from + * bt_conn_auth_cb structure was called. + * + * Requires @kconfig{CONFIG_BT_PASSKEY_KEYPRESS}. + * + * @param conn Destination for the notification. + * @param type What keypress event type to send. @see bt_conn_auth_keypress. + * + * @retval 0 Success + * @retval -EINVAL Improper use of the API. + * @retval -ENOMEM Failed to allocate. + * @retval -ENOBUFS Failed to allocate. + */ +int bt_conn_auth_keypress_notify(struct bt_conn *conn, enum bt_conn_auth_keypress type); + /** @brief Cancel ongoing authenticated pairing. * * This function allows to cancel ongoing authenticated pairing. diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index f0f8c8e639c0..e448ecf36b3d 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -357,6 +357,13 @@ config BT_SMP (SMP), making it possible to pair devices over LE. if BT_SMP +config BT_PASSKEY_KEYPRESS + bool "Passkey Keypress Notification support [EXPERIMENTAL]" + select EXPERIMENTAL + help + Enable support for receiving and sending Keypress Notifications during + Passkey Entry during pairing. + config BT_PRIVACY bool "Privacy Feature" help diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 567d03908d85..258962f23e85 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -3069,6 +3070,19 @@ int bt_conn_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey) return -EINVAL; } +#if defined(CONFIG_BT_PASSKEY_KEYPRESS) +int bt_conn_auth_keypress_notify(struct bt_conn *conn, + enum bt_conn_auth_keypress type) +{ + if (IS_ENABLED(CONFIG_BT_SMP) && conn->type == BT_CONN_TYPE_LE) { + return bt_smp_auth_keypress_notify(conn, type); + } + + LOG_ERR("Not implemented for conn type %d", conn->type); + return -EINVAL; +} +#endif + int bt_conn_auth_passkey_confirm(struct bt_conn *conn) { if (IS_ENABLED(CONFIG_BT_SMP) && conn->type == BT_CONN_TYPE_LE) { diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index e3e2ebaceabb..626c4bb925d6 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -2571,6 +2572,12 @@ static uint8_t get_auth(struct bt_smp *smp, uint8_t auth) auth &= ~BT_SMP_AUTH_BONDING; } + if (IS_ENABLED(CONFIG_BT_PASSKEY_KEYPRESS)) { + auth |= BT_SMP_AUTH_KEYPRESS; + } else { + auth &= ~BT_SMP_AUTH_KEYPRESS; + } + return auth; } @@ -4306,6 +4313,39 @@ static uint8_t smp_dhkey_check(struct bt_smp *smp, struct net_buf *buf) return 0; } +#if defined(CONFIG_BT_PASSKEY_KEYPRESS) +static uint8_t smp_keypress_notif(struct bt_smp *smp, struct net_buf *buf) +{ + const struct bt_conn_auth_cb *smp_auth_cb = latch_auth_cb(smp); + struct bt_conn *conn = smp->chan.chan.conn; + struct bt_smp_keypress_notif *notif = (void *)buf->data; + enum bt_conn_auth_keypress type = notif->type; + + LOG_DBG("Keypress from conn %u, type %u", bt_conn_index(conn), type); + + /* For now, keypress notifications are always accepted. In the future we + * should be smarter about this. We might also want to enforce something + * about the 'start' and 'end' messages. + */ + atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); + + if (!IN_RANGE(type, + BT_CONN_AUTH_KEYPRESS_ENTRY_STARTED, + BT_CONN_AUTH_KEYPRESS_ENTRY_COMPLETED)) { + LOG_WRN("Received unknown keypress event type %u. Discarding.", type); + return BT_SMP_ERR_INVALID_PARAMS; + } + + /* Reset SMP timeout, like the spec says. */ + k_work_reschedule(&smp->work, SMP_TIMEOUT); + + if (smp_auth_cb->passkey_display_keypress) { + smp_auth_cb->passkey_display_keypress(conn, type); + } + + return 0; +} +#else static uint8_t smp_keypress_notif(struct bt_smp *smp, struct net_buf *buf) { ARG_UNUSED(smp); @@ -4317,6 +4357,7 @@ static uint8_t smp_keypress_notif(struct bt_smp *smp, struct net_buf *buf) atomic_set_bit(smp->allowed_cmds, BT_SMP_KEYPRESS_NOTIFICATION); return 0; } +#endif static const struct { uint8_t (*func)(struct bt_smp *smp, struct net_buf *buf); @@ -5228,6 +5269,53 @@ int bt_smp_auth_cb_overlay(struct bt_conn *conn, const struct bt_conn_auth_cb *c } } +#if defined(CONFIG_BT_PASSKEY_KEYPRESS) +static int smp_send_keypress_notif(struct bt_smp *smp, uint8_t type) +{ + struct bt_smp_keypress_notif *req; + struct net_buf *buf; + + buf = smp_create_pdu(smp, BT_SMP_KEYPRESS_NOTIFICATION, sizeof(*req)); + if (!buf) { + return -ENOMEM; + } + + req = net_buf_add(buf, sizeof(*req)); + req->type = type; + + smp_send(smp, buf, NULL, NULL); + + return 0; +} +#endif + +#if defined(CONFIG_BT_PASSKEY_KEYPRESS) +int bt_smp_auth_keypress_notify(struct bt_conn *conn, enum bt_conn_auth_keypress type) +{ + struct bt_smp *smp; + + smp = smp_chan_get(conn); + if (!smp) { + return -EINVAL; + } + + CHECKIF(!IN_RANGE(type, + BT_CONN_AUTH_KEYPRESS_ENTRY_STARTED, + BT_CONN_AUTH_KEYPRESS_ENTRY_COMPLETED)) { + LOG_ERR("Refusing to send unknown event type %u", type); + return -EINVAL; + } + + if (smp->method != PASSKEY_INPUT || + !atomic_test_bit(smp->flags, SMP_FLAG_USER)) { + LOG_ERR("Refusing to send keypress: Not waiting for passkey input."); + return -EINVAL; + } + + return smp_send_keypress_notif(smp, type); +} +#endif + int bt_smp_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey) { struct bt_smp *smp; diff --git a/subsys/bluetooth/host/smp.h b/subsys/bluetooth/host/smp.h index 83d2b570f6c1..21207a0cb8da 100644 --- a/subsys/bluetooth/host/smp.h +++ b/subsys/bluetooth/host/smp.h @@ -142,6 +142,8 @@ int bt_smp_br_send_pairing_req(struct bt_conn *conn); int bt_smp_init(void); int bt_smp_auth_cb_overlay(struct bt_conn *conn, const struct bt_conn_auth_cb *cb); +int bt_smp_auth_keypress_notify(struct bt_conn *conn, + enum bt_conn_auth_keypress type); int bt_smp_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey); int bt_smp_auth_passkey_confirm(struct bt_conn *conn); int bt_smp_auth_pairing_confirm(struct bt_conn *conn); diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index b6b29473ac6f..a7f135b09bea 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -3054,6 +3055,19 @@ static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) shell_print(ctx_shell, "Passkey for %s: %s", addr, passkey_str); } +#if defined(CONFIG_BT_PASSKEY_KEYPRESS) +static void auth_passkey_display_keypress(struct bt_conn *conn, + enum bt_conn_auth_keypress type) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + shell_print(ctx_shell, "Passkey keypress notification from %s: type %d", + addr, type); +} +#endif + static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey) { char addr[BT_ADDR_LE_STR_LEN]; @@ -3250,6 +3264,9 @@ void bond_deleted(uint8_t id, const bt_addr_le_t *peer) static struct bt_conn_auth_cb auth_cb_display = { .passkey_display = auth_passkey_display, +#if defined(CONFIG_BT_PASSKEY_KEYPRESS) + .passkey_display_keypress = auth_passkey_display_keypress, +#endif .passkey_entry = NULL, .passkey_confirm = NULL, #if defined(CONFIG_BT_BREDR) @@ -3582,6 +3599,36 @@ static int cmd_auth_passkey(const struct shell *sh, return 0; } +#if defined(CONFIG_BT_PASSKEY_KEYPRESS) +static int cmd_auth_passkey_notify(const struct shell *sh, + size_t argc, char *argv[]) +{ + unsigned long type; + int err; + + if (!default_conn) { + shell_print(sh, "Not connected"); + return -ENOEXEC; + } + + err = 0; + type = shell_strtoul(argv[1], 0, &err); + if (err || !IN_RANGE(type, BT_CONN_AUTH_KEYPRESS_ENTRY_STARTED, + BT_CONN_AUTH_KEYPRESS_ENTRY_COMPLETED)) { + shell_error(sh, " must be a value in range of enum bt_conn_auth_keypress"); + return -EINVAL; + } + + err = bt_conn_auth_keypress_notify(default_conn, type); + if (err) { + shell_error(sh, "bt_conn_auth_keypress_notify errno %d", err); + return err; + } + + return 0; +} +#endif /* CONFIG_BT_PASSKEY_KEYPRESS */ + #if !defined(CONFIG_BT_SMP_SC_PAIR_ONLY) static int cmd_auth_oob_tk(const struct shell *sh, size_t argc, char *argv[]) { @@ -3794,6 +3841,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds, cmd_auth, 2, 0), SHELL_CMD_ARG(auth-cancel, NULL, HELP_NONE, cmd_auth_cancel, 1, 0), SHELL_CMD_ARG(auth-passkey, NULL, "", cmd_auth_passkey, 2, 0), +#if defined(CONFIG_BT_PASSKEY_KEYPRESS) + SHELL_CMD_ARG(auth-passkey-notify, NULL, "", + cmd_auth_passkey_notify, 2, 0), +#endif /* CONFIG_BT_PASSKEY_KEYPRESS */ SHELL_CMD_ARG(auth-passkey-confirm, NULL, HELP_NONE, cmd_auth_passkey_confirm, 1, 0), SHELL_CMD_ARG(auth-pairing-confirm, NULL, HELP_NONE, diff --git a/tests/bluetooth/shell/prj.conf b/tests/bluetooth/shell/prj.conf index b592c3336e6f..665bf936a1ae 100644 --- a/tests/bluetooth/shell/prj.conf +++ b/tests/bluetooth/shell/prj.conf @@ -9,6 +9,7 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_PRIVACY=y CONFIG_BT_SMP=y +CONFIG_BT_PASSKEY_KEYPRESS=y CONFIG_BT_SIGNING=y CONFIG_BT_FIXED_PASSKEY=y CONFIG_BT_ATT_PREPARE_COUNT=2 From e80eca0239a554b4fb3e4fe9d762f4d2744bdab1 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 22 Feb 2023 14:56:39 +0100 Subject: [PATCH 0156/1906] Bluetooth: Audio: Shell: Add automatic receiver ready for server When a stream for a sink ASE goes into the enabled state we automatically execute the receiver start ready operation as the unicast server. This makes the shell easier to use as the server. Signed-off-by: Emil Gydesen --- subsys/bluetooth/shell/bap.c | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/subsys/bluetooth/shell/bap.c b/subsys/bluetooth/shell/bap.c index 4715f4ded115..af49a73db55f 100644 --- a/subsys/bluetooth/shell/bap.c +++ b/subsys/bluetooth/shell/bap.c @@ -1630,6 +1630,43 @@ static void audio_recv(struct bt_bap_stream *stream, } #endif /* CONFIG_BT_BAP_UNICAST || CONFIG_BT_BAP_BROADCAST_SINK */ +static void stream_enabled_cb(struct bt_bap_stream *stream) +{ + shell_print(ctx_shell, "Stream %p enabled", stream); + + if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_SERVER)) { + struct bt_bap_ep_info ep_info; + struct bt_conn_info conn_info; + int err; + + err = bt_conn_get_info(stream->conn, &conn_info); + if (err != 0) { + shell_error(ctx_shell, "Failed to get conn info: %d", err); + return; + } + + if (conn_info.role == BT_CONN_ROLE_CENTRAL) { + return; /* We also want to autonomously start the stream as the server */ + } + + err = bt_bap_ep_get_info(stream->ep, &ep_info); + if (err != 0) { + shell_error(ctx_shell, "Failed to get ep info: %d", err); + return; + } + + if (ep_info.dir == BT_AUDIO_DIR_SINK) { + /* Automatically do the receiver start ready operation */ + err = bt_bap_stream_start(stream); + + if (err != 0) { + shell_error(ctx_shell, "Failed to start stream: %d", err); + return; + } + } + } +} + static void stream_started_cb(struct bt_bap_stream *stream) { printk("Stream %p started\n", stream); @@ -1690,6 +1727,7 @@ static struct bt_bap_stream_ops stream_ops = { #endif /* CONFIG_BT_BAP_UNICAST || CONFIG_BT_BAP_BROADCAST_SINK */ #if defined(CONFIG_BT_BAP_UNICAST) .released = stream_released_cb, + .enabled = stream_enabled_cb, #endif /* CONFIG_BT_BAP_UNICAST */ .started = stream_started_cb, .stopped = stream_stopped_cb, From 15c77acfb4326b7c39f3d2d48f13fbd9fe30404e Mon Sep 17 00:00:00 2001 From: Jonathan Rico Date: Mon, 13 Mar 2023 12:18:52 +0100 Subject: [PATCH 0157/1906] tests: Bluetooth: fix att_mtu warnings on gcc-12 The warnings are correct, we were copying 17 bytes from a 4-byte source. Signed-off-by: Jonathan Rico --- .../bluetooth/mtu_update/central/src/central_mtu_update.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/bluetooth/mtu_update/central/src/central_mtu_update.c b/samples/bluetooth/mtu_update/central/src/central_mtu_update.c index f969b5177529..046446882dcb 100644 --- a/samples/bluetooth/mtu_update/central/src/central_mtu_update.c +++ b/samples/bluetooth/mtu_update/central/src/central_mtu_update.c @@ -34,6 +34,8 @@ static void start_scan(void); static struct bt_conn *default_conn; static struct bt_uuid_128 uuid = BT_UUID_INIT_128(0); +static const struct bt_uuid *ccc_uuid = BT_UUID_GATT_CCC; + static struct bt_gatt_discover_params discover_params; static struct bt_gatt_subscribe_params subscribe_params; @@ -82,8 +84,7 @@ static uint8_t discover_func(struct bt_conn *conn, const struct bt_gatt_attr *at printk("Discover failed (err %d)\n", err); } } else if (!bt_uuid_cmp(discover_params.uuid, BT_UUID_MTU_TEST_NOTIFY)) { - memcpy(&uuid, BT_UUID_GATT_CCC, sizeof(uuid)); - discover_params.uuid = &uuid.uuid; + discover_params.uuid = ccc_uuid; discover_params.start_handle = attr->handle + 2; discover_params.type = BT_GATT_DISCOVER_DESCRIPTOR; subscribe_params.value_handle = bt_gatt_attr_value_handle(attr); From 867c25480117e31ea2c510b414391ba9f43b9875 Mon Sep 17 00:00:00 2001 From: Ionut Catalin Pavel Date: Sun, 12 Feb 2023 18:06:47 +0200 Subject: [PATCH 0158/1906] drivers: regulator: common: skip voltage change at init if already valid The current implementation always sets the voltage before enabling, even if the current voltage is in the allowed range. This has some side effects, i.e. for PMIC regulators that are pre-programmed for a specific value but allow voltage changes during runtime. The side effect being that the regulator will always be reset to the lower value of the voltage range at init. Another usecase would be when a bootloader sets a specific voltage then loads an application that uses the same driver. The proposed fix is to evaluate the current voltage and try to bring the actual voltage in range if the current voltage is not valid according to the min/max constraints. Tested on custom SAMD20 board with a custom RK816 PMIC driver. Signed-off-by: Ionut Catalin Pavel --- drivers/regulator/regulator_common.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/regulator/regulator_common.c b/drivers/regulator/regulator_common.c index d00e2f647feb..cc705238a090 100644 --- a/drivers/regulator/regulator_common.c +++ b/drivers/regulator/regulator_common.c @@ -18,6 +18,7 @@ int regulator_common_init(const struct device *dev, bool is_enabled) const struct regulator_driver_api *api = dev->api; const struct regulator_common_config *config = dev->config; struct regulator_common_data *data = dev->data; + int32_t current_uv; int ret; if (config->initial_mode != REGULATOR_INITIAL_MODE_UNKNOWN) { @@ -27,13 +28,26 @@ int regulator_common_init(const struct device *dev, bool is_enabled) } } - /* regulator voltage needs to be within allowed range before enabling */ + /* If we have valid range values, we try to match them before enabling */ if ((config->min_uv > INT32_MIN) || (config->max_uv < INT32_MAX)) { - ret = regulator_set_voltage(dev, config->min_uv, - config->max_uv); - if ((ret < 0) && (ret != -ENOSYS)) { + + ret = regulator_get_voltage(dev, ¤t_uv); + if (ret < 0) { return ret; } + + /* Snap to closest interval value if out of range */ + if (current_uv < config->min_uv) { + ret = regulator_set_voltage(dev, config->min_uv, config->min_uv); + if (ret < 0) { + return ret; + } + } else if (current_uv > config->max_uv) { + ret = regulator_set_voltage(dev, config->max_uv, config->max_uv); + if (ret < 0) { + return ret; + } + } } if (is_enabled) { From 4684006f1b6f9e461bc627985a3a3094179097e1 Mon Sep 17 00:00:00 2001 From: Vibhor Meshram Date: Tue, 21 Feb 2023 21:05:11 +0530 Subject: [PATCH 0159/1906] Bluetooth: Audio: Remove "Input" from MICP naming Removed "Input" from Microphone Input Control Profile. Release notes kept unchanged. Signed-off-by: Vibhor Meshram --- .../bluetooth/bluetooth-audio-arch.rst | 10 +++--- include/zephyr/bluetooth/audio/micp.h | 34 +++++++++---------- include/zephyr/bluetooth/uuid.h | 4 +-- samples/bluetooth/hap_ha/src/micp_mic_dev.c | 2 +- subsys/bluetooth/audio/Kconfig.micp | 32 ++++++++--------- subsys/bluetooth/audio/micp_mic_ctlr.c | 2 +- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/doc/connectivity/bluetooth/bluetooth-audio-arch.rst b/doc/connectivity/bluetooth/bluetooth-audio-arch.rst index 245d1cc66e75..121169658dfb 100644 --- a/doc/connectivity/bluetooth/bluetooth-audio-arch.rst +++ b/doc/connectivity/bluetooth/bluetooth-audio-arch.rst @@ -88,7 +88,7 @@ Rendering and Capture Control ----------------------------- Rendering and capture control is implemented by the Volume Control Profile -(VCP) and Microphone Input Control Profile (MICP). +(VCP) and Microphone Control Profile (MICP). The VCP implementation supports the following roles @@ -97,14 +97,14 @@ The VCP implementation supports the following roles The MICP implementation supports the following roles -* Microphone Input Control Profile (MICP) Microphone Device (server) -* Microphone Input Control Profile (MICP) Microphone Controller (client) +* Microphone Control Profile (MICP) Microphone Device (server) +* Microphone Control Profile (MICP) Microphone Controller (client) The API reference for volume control can be found in :ref:`Bluetooth Volume Control `. -The API reference for microphone input control can be found in -:ref:`Bluetooth Microphone Input Control `. +The API reference for Microphone Control can be found in +:ref:`Bluetooth Microphone Control `. Content Control diff --git a/include/zephyr/bluetooth/audio/micp.h b/include/zephyr/bluetooth/audio/micp.h index 24a18145bebd..3e358e2319af 100644 --- a/include/zephyr/bluetooth/audio/micp.h +++ b/include/zephyr/bluetooth/audio/micp.h @@ -8,9 +8,9 @@ #define ZEPHYR_INCLUDE_BLUETOOTH_MICP_H_ /** - * @brief Microphone Input Control Profile (MICP) + * @brief Microphone Control Profile (MICP) * - * @defgroup bt_gatt_micp Microphone Input Control Profile (MICP) + * @defgroup bt_gatt_micp Microphone Control Profile (MICP) * * @ingroup bluetooth * @{ @@ -36,7 +36,7 @@ extern "C" { #define BT_MICP_ERR_MUTE_DISABLED 0x80 #define BT_MICP_ERR_VAL_OUT_OF_RANGE 0x81 -/** Microphone Input Control Profile mute states */ +/** Microphone Control Profile mute states */ #define BT_MICP_MUTE_UNMUTED 0x00 #define BT_MICP_MUTE_MUTED 0x01 #define BT_MICP_MUTE_DISABLED 0x02 @@ -44,21 +44,21 @@ extern "C" { /** @brief Opaque Microphone Controller instance. */ struct bt_micp_mic_ctlr; -/** @brief Register parameters structure for Microphone Input Control Service */ +/** @brief Register parameters structure for Microphone Control Service */ struct bt_micp_mic_dev_register_param { #if defined(CONFIG_BT_MICP_MIC_DEV_AICS) /** Register parameter structure for Audio Input Control Services */ struct bt_aics_register_param aics_param[BT_MICP_MIC_DEV_AICS_CNT]; #endif /* CONFIG_BT_MICP_MIC_DEV_AICS */ - /** Microphone Input Control Profile callback structure. */ + /** Microphone Control Profile callback structure. */ struct bt_micp_mic_dev_cb *cb; }; /** - * @brief Microphone Input Control Profile included services + * @brief Microphone Control Profile included services * - * Used for to represent the Microphone Input Control Profile included service + * Used for to represent the Microphone Control Profile included service * instances, for either a Microphone Controller or a Microphone Device. * The instance pointers either represent local service instances, * or remote service instances. @@ -71,9 +71,9 @@ struct bt_micp_included { }; /** - * @brief Initialize the Microphone Input Control Profile Microphone Device + * @brief Initialize the Microphone Control Profile Microphone Device * - * This will enable the Microphone Input Control Service instance and make it + * This will enable the Microphone Control Service instance and make it * discoverable by Microphone Controllers. * * @param param Pointer to an initialization structure. @@ -104,7 +104,7 @@ struct bt_micp_mic_dev_cb { * or if the value is changed by either the Microphone Device or a * Microphone Controller. * - * @param mute The mute setting of the Microphone Input Control Service. + * @param mute The mute setting of the Microphone Control Service. */ void (*mute)(uint8_t mute); }; @@ -141,7 +141,7 @@ int bt_micp_mic_dev_mute_get(void); struct bt_micp_mic_ctlr_cb { /** - * @brief Callback function for Microphone Input Control Profile mute. + * @brief Callback function for Microphone Control Profile mute. * * Called when the value is read, * or if the value is changed by either the Microphone Device or a @@ -150,7 +150,7 @@ struct bt_micp_mic_ctlr_cb { * @param mic_ctlr Microphone Controller instance pointer. * @param err Error value. 0 on success, GATT error or errno on fail. * For notifications, this will always be 0. - * @param mute The mute setting of the Microphone Input Control Service. + * @param mute The mute setting of the Microphone Control Service. */ void (*mute)(struct bt_micp_mic_ctlr *mic_ctlr, int err, uint8_t mute); @@ -166,7 +166,7 @@ struct bt_micp_mic_ctlr_cb { uint8_t aics_count); /** - * @brief Callback function for Microphone Input Control Profile mute/unmute. + * @brief Callback function for Microphone Control Profile mute/unmute. * * @param mic_ctlr Microphone Controller instance pointer. * @param err Error value. 0 on success, GATT error or errno on fail. @@ -174,7 +174,7 @@ struct bt_micp_mic_ctlr_cb { void (*mute_written)(struct bt_micp_mic_ctlr *mic_ctlr, int err); /** - * @brief Callback function for Microphone Input Control Profile mute/unmute. + * @brief Callback function for Microphone Control Profile mute/unmute. * * @param mic_ctlr Microphone Controller instance pointer. * @param err Error value. 0 on success, GATT error or errno on fail. @@ -188,10 +188,10 @@ struct bt_micp_mic_ctlr_cb { }; /** - * @brief Get Microphone Input Control Profile included services + * @brief Get Microphone Control Profile included services * * Returns a pointer to a struct that contains information about the - * Microphone Input Control Profile included services instances, such as + * Microphone Control Profile included services instances, such as * pointers to the Audio Input Control Service instances. * * Requires that @kconfig{CONFIG_BT_MICP_MIC_CTLR_AICS} is enabled. @@ -218,7 +218,7 @@ int bt_micp_mic_ctlr_conn_get(const struct bt_micp_mic_ctlr *mic_ctlr, struct bt_conn **conn); /** - * @brief Discover Microphone Input Control Service + * @brief Discover Microphone Control Service * * This will start a GATT discovery and setup handles and subscriptions. * This shall be called once before any other actions can be executed for the diff --git a/include/zephyr/bluetooth/uuid.h b/include/zephyr/bluetooth/uuid.h index 72bd14226484..0a48614fb26a 100644 --- a/include/zephyr/bluetooth/uuid.h +++ b/include/zephyr/bluetooth/uuid.h @@ -4691,11 +4691,11 @@ struct bt_uuid_128 { #define BT_UUID_TBS_FRIENDLY_NAME \ BT_UUID_DECLARE_16(BT_UUID_TBS_FRIENDLY_NAME_VAL) /** - * @brief Microphone Input Control Service Mute value + * @brief Microphone Control Service Mute value */ #define BT_UUID_MICS_MUTE_VAL 0x2bc3 /** - * @brief Microphone Input Control Service Mute + * @brief Microphone Control Service Mute */ #define BT_UUID_MICS_MUTE \ BT_UUID_DECLARE_16(BT_UUID_MICS_MUTE_VAL) diff --git a/samples/bluetooth/hap_ha/src/micp_mic_dev.c b/samples/bluetooth/hap_ha/src/micp_mic_dev.c index f1c8ffb5ac4e..bd36c587002b 100644 --- a/samples/bluetooth/hap_ha/src/micp_mic_dev.c +++ b/samples/bluetooth/hap_ha/src/micp_mic_dev.c @@ -1,5 +1,5 @@ /** @file - * @brief Bluetooth Microphone Input Control Profile (MICP) Microphone Device role. + * @brief Bluetooth Microphone Control Profile (MICP) Microphone Device role. * * Copyright (c) 2020 Bose Corporation * Copyright (c) 2020-2022 Nordic Semiconductor ASA diff --git a/subsys/bluetooth/audio/Kconfig.micp b/subsys/bluetooth/audio/Kconfig.micp index bebfbd10fc64..ec5b7ff9e23e 100644 --- a/subsys/bluetooth/audio/Kconfig.micp +++ b/subsys/bluetooth/audio/Kconfig.micp @@ -1,4 +1,4 @@ -# Bluetooth Audio - Microphone Input Control Service options +# Bluetooth Audio - Microphone Control Service options # # Copyright (c) 2020 Bose Corporation # Copyright (c) 2020-2022 Nordic Semiconductor ASA @@ -6,58 +6,58 @@ # SPDX-License-Identifier: Apache-2.0 # -########### Microphone Input Control Profile Microphone Device ########### +########### Microphone Control Profile Microphone Device ########### config BT_MICP_MIC_DEV - bool "Microphone Input Control Profile Microphone Device Support [EXPERIMENTAL]" + bool "Microphone Control Profile Microphone Device Support [EXPERIMENTAL]" select EXPERIMENTAL help - This option enables support for Microphone Input Control Profile + This option enables support for Microphone Control Profile Microphone Device. if BT_MICP_MIC_DEV config BT_MICP_MIC_DEV_AICS_INSTANCE_COUNT int "Audio Input Control Service instance count for \ - Microphone Input Control Service Microphone Device" + Microphone Control Service Microphone Device" default 0 range 0 BT_AICS_MAX_INSTANCE_COUNT help This option sets the number of instances of Audio Input Control - Services for Microphone Input Control Profile Microphone Device. + Services for Microphone Control Profile Microphone Device. config BT_MICP_MIC_DEV_AICS bool # Hidden default y if BT_MICP_MIC_DEV_AICS_INSTANCE_COUNT > 0 help This hidden option makes it possible to easily check if AICS is - enabled for Microphone Input Control Profile Microphone Device. + enabled for Microphone Control Profile Microphone Device. ############# DEBUG ############# config BT_DEBUG_MICP_MIC_DEV - bool "Microphone Input Control Profile Microphone Device debug" + bool "Microphone Control Profile Microphone Device debug" select DEPRECATED help - Use this option to enable Microphone Input Control Profile + Use this option to enable Microphone Control Profile Microphone Device debug logs for the Bluetooth Audio functionality. module = BT_MICP_MIC_DEV legacy-debug-sym = BT_DEBUG_MICP_MIC_DEV -module-str = "Microphone Input Control Profile Microphone Device" +module-str = "Microphone Control Profile Microphone Device" source "subsys/bluetooth/common/Kconfig.template.log_config_bt" endif # BT_MICP_MIC_DEV -########### Microphone Input Control Profile Microphone Controller ########### +########### Microphone Control Profile Microphone Controller ########### config BT_MICP_MIC_CTLR - bool "Microphone Input Control Profile Microphone Controller Support [EXPERIMENTAL]" + bool "Microphone Control Profile Microphone Controller Support [EXPERIMENTAL]" select BT_GATT_CLIENT select BT_GATT_AUTO_DISCOVER_CCC select EXPERIMENTAL help - This option enables support for the Microphone Input Control Profile + This option enables support for the Microphone Control Profile Microphone Controller role if BT_MICP_MIC_CTLR @@ -80,15 +80,15 @@ config BT_MICP_MIC_CTLR_AICS ############# DEBUG ############# config BT_DEBUG_MICP_MIC_CTLR - bool "Microphone Input Control Profile Microphone Controller debug" + bool "Microphone Control Profile Microphone Controller debug" select DEPRECATED help - Use this option to enable Microphone Input Control Profile Microphone + Use this option to enable Microphone Control Profile Microphone Controller debug logs for the Bluetooth Audio functionality. module = BT_MICP_MIC_CTLR legacy-debug-sym = BT_DEBUG_MICP_MIC_CTLR -module-str = "Microphone Input Control Profile Microphone Controller" +module-str = "Microphone Control Profile Microphone Controller" source "subsys/bluetooth/common/Kconfig.template.log_config_bt" endif # BT_MICP_MIC_CTLR diff --git a/subsys/bluetooth/audio/micp_mic_ctlr.c b/subsys/bluetooth/audio/micp_mic_ctlr.c index 227ebe22ebac..3599287fdd5e 100644 --- a/subsys/bluetooth/audio/micp_mic_ctlr.c +++ b/subsys/bluetooth/audio/micp_mic_ctlr.c @@ -1,4 +1,4 @@ -/* Bluetooth MICP - Microphone Input Control Profile - Microphone Controller */ +/* Bluetooth MICP - Microphone Control Profile - Microphone Controller */ /* * Copyright (c) 2020 Bose Corporation From 8c895669934bd1e77ae289fad0351ec0bf3f0eb8 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Tue, 29 Nov 2022 10:26:08 +0100 Subject: [PATCH 0160/1906] subsys/disk: No need of runtime intialization for disk access part Mutex and double-linked list can be statically initialized. This removes a little bit of boot time overhead. Signed-off-by: Tomasz Bursztyka --- subsys/disk/disk_access.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/subsys/disk/disk_access.c b/subsys/disk/disk_access.c index f640e42b799a..e69bc4946076 100644 --- a/subsys/disk/disk_access.c +++ b/subsys/disk/disk_access.c @@ -18,10 +18,10 @@ LOG_MODULE_REGISTER(disk); /* list of mounted file systems */ -static sys_dlist_t disk_access_list; +static sys_dlist_t disk_access_list = SYS_DLIST_STATIC_INIT(&disk_access_list); /* lock to protect storage layer registration */ -static struct k_mutex mutex; +static K_MUTEX_DEFINE(mutex); struct disk_info *disk_access_get_di(const char *name) { @@ -168,14 +168,3 @@ int disk_access_unregister(struct disk_info *disk) k_mutex_unlock(&mutex); return rc; } - -static int disk_init(const struct device *dev) -{ - ARG_UNUSED(dev); - - k_mutex_init(&mutex); - sys_dlist_init(&disk_access_list); - return 0; -} - -SYS_INIT(disk_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); From 93f7a6730d12dd5f8eae8cadb41adeb66c1136d9 Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sat, 21 Jan 2023 20:04:48 +0900 Subject: [PATCH 0161/1906] west: hal_rpi_pico: Update Pico-SDK to v1.5.0 Update Pico-SDK to v1.5.0 release. Signed-off-by: TOKITA Hiroshi --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 5949caca9e0a..160ef7e31c52 100644 --- a/west.yml +++ b/west.yml @@ -115,7 +115,7 @@ manifest: - hal - name: hal_rpi_pico path: modules/hal/rpi_pico - revision: a094c060e0c2d43c7f9d8f5c06cc0665117e0c18 + revision: b7801e4db6a62ea2d37bbef7880c3d056530c9bf groups: - hal - name: hal_silabs From 9854c915ffdfc3bbe74eb759bff8070ad9aafd24 Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Mon, 20 Feb 2023 11:22:36 +0100 Subject: [PATCH 0162/1906] intel_adsp: cpu init refactor Reusing existing code during CPU init at power gating exit. Additional changes: - replacing magic value for memctl and atomctl with more readable definitions, - using dedicated macros in place of asm inlines. Signed-off-by: Tomasz Leman --- soc/xtensa/intel_adsp/ace/power.c | 14 +--------- .../intel_adsp/common/include/cpu_init.h | 26 ++++++++++++++----- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/soc/xtensa/intel_adsp/ace/power.c b/soc/xtensa/intel_adsp/ace/power.c index f31b75774c17..b01cbfa0865a 100644 --- a/soc/xtensa/intel_adsp/ace/power.c +++ b/soc/xtensa/intel_adsp/ace/power.c @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -20,8 +19,6 @@ #define LPSCTL_BATTR_MASK GENMASK(16, 12) #define SRAM_ALIAS_BASE 0xA0000000 #define SRAM_ALIAS_MASK 0xF0000000 -#define MEMCTL_DEFAULT_VALUE (MEMCTL_INV_EN | MEMCTL_ICWU_MASK | MEMCTL_DCWA_MASK | \ - MEMCTL_DCWU_MASK | MEMCTL_L0IBUF_EN) __imr void power_init(void) { @@ -110,15 +107,6 @@ struct lpsram_header { uint8_t rom_bypass_vectors_reserved[0xC00 - 0x14]; }; -static ALWAYS_INLINE void _core_basic_init(void) -{ - XTENSA_WSR("MEMCTL", MEMCTL_DEFAULT_VALUE); - XTENSA_WSR("PREFCTL", ADSP_L1_CACHE_PREFCTL_VALUE); - ARCH_XTENSA_SET_RPO_TLB(); - XTENSA_WSR("ATOMCTL", 0x15); - __asm__ volatile("rsync"); -} - static ALWAYS_INLINE void _save_core_context(uint32_t core_id) { core_desc[core_id].vecbase = XTENSA_RSR("VECBASE"); @@ -162,7 +150,7 @@ void power_gate_entry(uint32_t core_id) void power_gate_exit(void) { - _core_basic_init(); + cpu_early_init(); _restore_core_context(); } diff --git a/soc/xtensa/intel_adsp/common/include/cpu_init.h b/soc/xtensa/intel_adsp/common/include/cpu_init.h index 30878f016746..8560972c6ada 100644 --- a/soc/xtensa/intel_adsp/common/include/cpu_init.h +++ b/soc/xtensa/intel_adsp/common/include/cpu_init.h @@ -4,10 +4,20 @@ #ifndef __INTEL_ADSP_CPU_INIT_H #define __INTEL_ADSP_CPU_INIT_H +#include #include #include +#include #include +#define MEMCTL_VALUE (MEMCTL_INV_EN | MEMCTL_ICWU_MASK | MEMCTL_DCWA_MASK | \ + MEMCTL_DCWU_MASK | MEMCTL_L0IBUF_EN) + +#define ATOMCTL_BY_RCW BIT(0) /* RCW Transaction for Bypass Memory */ +#define ATOMCTL_WT_RCW BIT(2) /* RCW Transaction for Writethrough Cacheable Memory */ +#define ATOMCTL_WB_RCW BIT(4) /* RCW Transaction for Writeback Cacheable Memory */ +#define ATOMCTL_VALUE (ATOMCTL_BY_RCW | ATOMCTL_WT_RCW | ATOMCTL_WB_RCW) + /* Low-level CPU initialization. Call this immediately after entering * C code to initialize the cache, protection and synchronization * features. @@ -43,8 +53,9 @@ static ALWAYS_INLINE void cpu_early_init(void) * fetch buffer. */ #if XCHAL_USE_MEMCTL - reg = 0xffffff01; - __asm__ volatile("wsr %0, MEMCTL; rsync" :: "r"(reg)); + reg = MEMCTL_VALUE; + XTENSA_WSR("MEMCTL", reg); + __asm__ volatile("rsync"); #endif /* Likewise enable prefetching. Sadly these values are not @@ -54,7 +65,8 @@ static ALWAYS_INLINE void cpu_early_init(void) * we're supposed to ask Cadence I guess. */ reg = ADSP_L1_CACHE_PREFCTL_VALUE; - __asm__ volatile("wsr %0, PREFCTL; rsync" :: "r"(reg)); + XTENSA_WSR("PREFCTL", reg); + __asm__ volatile("rsync"); /* Finally we need to enable the cache in the Region * Protection Option "TLB" entries. The hardware defaults @@ -67,12 +79,12 @@ static ALWAYS_INLINE void cpu_early_init(void) * local CPU! We need external transactions on the shared * bus. */ - reg = 0x15; - __asm__ volatile("wsr %0, ATOMCTL" :: "r"(reg)); + reg = ATOMCTL_VALUE; + XTENSA_WSR("ATOMCTL", reg); /* Initialize interrupts to "disabled" */ reg = 0; - __asm__ volatile("wsr %0, INTENABLE" :: "r"(reg)); + XTENSA_WSR("INTENABLE", reg); /* Finally VECBASE. Note that on core 0 startup, we're still * running in IMR and the vectors at this address won't be @@ -81,7 +93,7 @@ static ALWAYS_INLINE void cpu_early_init(void) * consistently until Zephyr switches into the main thread. */ reg = VECBASE_RESET_PADDR_SRAM; - __asm__ volatile("wsr %0, VECBASE" :: "r"(reg)); + XTENSA_WSR("VECBASE", reg); } #endif /* __INTEL_ADSP_CPU_INIT_H */ From 593dea7f3666a75311e1fb56e3c02974ce9c4764 Mon Sep 17 00:00:00 2001 From: Ahmed Moheb Date: Thu, 29 Dec 2022 11:04:47 +0200 Subject: [PATCH 0163/1906] tests: bluetooth: host: Add mocks for crypto.c Add required mocks to be able to compile/test /bluetooth/host/crypto.c Signed-off-by: Ahmed Moheb --- tests/bluetooth/host/crypto/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/bluetooth/host/crypto/CMakeLists.txt b/tests/bluetooth/host/crypto/CMakeLists.txt index a96c57f60584..1a8ae2f5a500 100644 --- a/tests/bluetooth/host/crypto/CMakeLists.txt +++ b/tests/bluetooth/host/crypto/CMakeLists.txt @@ -13,6 +13,9 @@ add_library(mocks STATIC mocks/crypto_help_utils.c ${ZEPHYR_BASE}/subsys/bluetooth/host/crypto.c + ${ZEPHYR_BASE}/subsys/logging/log_minimal.c + ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c + ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c ) target_include_directories(mocks PUBLIC From ebf96f4148e57a7c17eb4b04dcffccfdceab973f Mon Sep 17 00:00:00 2001 From: Ahmed Moheb Date: Thu, 29 Dec 2022 11:08:36 +0200 Subject: [PATCH 0164/1906] tests: bluetooth: host: Add UT for prng_init() Unit test project for prng_init(). This is part of subsys/bluetooth/host/crypto.c unit testing. Signed-off-by: Ahmed Moheb --- .../host/crypto/prng_init/CMakeLists.txt | 6 ++++-- tests/bluetooth/host/crypto/prng_init/prj.conf | 4 ---- tests/bluetooth/host/crypto/prng_init/src/main.c | 12 +++++++----- .../prng_init/src/test_suite_invalid_inputs.c | 16 +++++++++------- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/tests/bluetooth/host/crypto/prng_init/CMakeLists.txt b/tests/bluetooth/host/crypto/prng_init/CMakeLists.txt index 3ecc28beabb2..8fd8d7ec9653 100644 --- a/tests/bluetooth/host/crypto/prng_init/CMakeLists.txt +++ b/tests/bluetooth/host/crypto/prng_init/CMakeLists.txt @@ -2,10 +2,12 @@ cmake_minimum_required(VERSION 3.20.0) -FILE(GLOB SOURCES src/*.c) +set(SOURCES + src/main.c + src/test_suite_invalid_inputs.c +) project(prng_init) -add_compile_definitions(test_unit_name="${PROJECT_NAME}") find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) diff --git a/tests/bluetooth/host/crypto/prng_init/prj.conf b/tests/bluetooth/host/crypto/prng_init/prj.conf index c0dad049caf0..542d140aa567 100644 --- a/tests/bluetooth/host/crypto/prng_init/prj.conf +++ b/tests/bluetooth/host/crypto/prng_init/prj.conf @@ -7,7 +7,3 @@ CONFIG_ASSERT=y CONFIG_ASSERT_LEVEL=2 CONFIG_ASSERT_VERBOSE=y CONFIG_ASSERT_ON_ERRORS=y - -CONFIG_LOG=n -CONFIG_BT_DEBUG_LOG=n -CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/bluetooth/host/crypto/prng_init/src/main.c b/tests/bluetooth/host/crypto/prng_init/src/main.c index 146c94cbe61d..2270aea1f135 100644 --- a/tests/bluetooth/host/crypto/prng_init/src/main.c +++ b/tests/bluetooth/host/crypto/prng_init/src/main.c @@ -4,14 +4,16 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include -#include +#include "mocks/crypto_help_utils.h" #include "mocks/hci_core.h" #include "mocks/hci_core_expects.h" #include "mocks/hmac_prng.h" #include "mocks/hmac_prng_expects.h" -#include "mocks/crypto_help_utils.h" + +#include +#include + +#include DEFINE_FFF_GLOBALS; @@ -52,5 +54,5 @@ ZTEST(prng_init, test_prng_init_succeeds) expect_single_call_tc_hmac_prng_init(hmac_prng, 8); expect_single_call_tc_hmac_prng_reseed(hmac_prng, 32, sizeof(int64_t)); - zassert_ok(err, "'%s()' returned unexpected error code %d", test_unit_name, err); + zassert_ok(err, "Unexpected error code '%d' was returned", err); } diff --git a/tests/bluetooth/host/crypto/prng_init/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/crypto/prng_init/src/test_suite_invalid_inputs.c index 4c8ebf661912..fa25017c23e0 100644 --- a/tests/bluetooth/host/crypto/prng_init/src/test_suite_invalid_inputs.c +++ b/tests/bluetooth/host/crypto/prng_init/src/test_suite_invalid_inputs.c @@ -4,14 +4,16 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include +#include "host_mocks/assert.h" +#include "mocks/crypto_help_utils.h" #include "mocks/hci_core.h" #include "mocks/hci_core_expects.h" #include "mocks/hmac_prng.h" #include "mocks/hmac_prng_expects.h" -#include "mocks/crypto_help_utils.h" -#include "host_mocks/assert.h" + +#include + +#include ZTEST_SUITE(prng_init_invalid_cases, NULL, NULL, NULL, NULL, NULL); @@ -35,7 +37,7 @@ ZTEST(prng_init_invalid_cases, test_bt_hci_le_rand_fails) expect_call_count_bt_hci_le_rand(1, expected_args_history); - zassert_true(err < 0, "'%s()' returned unexpected error code %d", test_unit_name, err); + zassert_true(err < 0, "Unexpected error code '%d' was returned", err); } /* @@ -62,7 +64,7 @@ ZTEST(prng_init_invalid_cases, test_tc_hmac_prng_init_fails) expect_call_count_bt_hci_le_rand(1, expected_args_history); expect_single_call_tc_hmac_prng_init(hmac_prng, 8); - zassert_true(err == -EIO, "'%s()' returned unexpected error code %d", test_unit_name, err); + zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err); } /* @@ -92,5 +94,5 @@ ZTEST(prng_init_invalid_cases, test_prng_reseed_fails) expect_single_call_tc_hmac_prng_init(hmac_prng, 8); expect_single_call_tc_hmac_prng_reseed(hmac_prng, 32, sizeof(int64_t)); - zassert_true(err == -EIO, "'%s()' returned unexpected error code %d", test_unit_name, err); + zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err); } From 574d78483ca185593120febd089382ec5e08eefd Mon Sep 17 00:00:00 2001 From: Ahmed Moheb Date: Thu, 20 Oct 2022 09:47:19 +0200 Subject: [PATCH 0165/1906] tests: bluetooth: host: Add UT for bt_rand() Unit test project for bt_rand(). This is part of subsys/bluetooth/host/crypto.c unit testing. Signed-off-by: Ahmed Moheb --- .../host/crypto/bt_rand/CMakeLists.txt | 17 ++ tests/bluetooth/host/crypto/bt_rand/prj.conf | 9 + .../bluetooth/host/crypto/bt_rand/src/main.c | 130 ++++++++++++ .../bt_rand/src/test_suite_invalid_inputs.c | 187 ++++++++++++++++++ .../host/crypto/bt_rand/testcase.yaml | 9 + 5 files changed, 352 insertions(+) create mode 100644 tests/bluetooth/host/crypto/bt_rand/CMakeLists.txt create mode 100644 tests/bluetooth/host/crypto/bt_rand/prj.conf create mode 100644 tests/bluetooth/host/crypto/bt_rand/src/main.c create mode 100644 tests/bluetooth/host/crypto/bt_rand/src/test_suite_invalid_inputs.c create mode 100644 tests/bluetooth/host/crypto/bt_rand/testcase.yaml diff --git a/tests/bluetooth/host/crypto/bt_rand/CMakeLists.txt b/tests/bluetooth/host/crypto/bt_rand/CMakeLists.txt new file mode 100644 index 000000000000..51abecdc50c5 --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_rand/CMakeLists.txt @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +set(SOURCES + src/main.c + src/test_suite_invalid_inputs.c +) + +project(bt_rand) + +find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) + +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/crypto mocks) + +target_link_libraries(testbinary PRIVATE mocks host_mocks) diff --git a/tests/bluetooth/host/crypto/bt_rand/prj.conf b/tests/bluetooth/host/crypto/bt_rand/prj.conf new file mode 100644 index 000000000000..542d140aa567 --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_rand/prj.conf @@ -0,0 +1,9 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_BT=y +CONFIG_BT_CENTRAL=y +CONFIG_BT_MAX_PAIRED=7 +CONFIG_ASSERT=y +CONFIG_ASSERT_LEVEL=2 +CONFIG_ASSERT_VERBOSE=y +CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/crypto/bt_rand/src/main.c b/tests/bluetooth/host/crypto/bt_rand/src/main.c new file mode 100644 index 000000000000..b288d2172c8f --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_rand/src/main.c @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mocks/crypto_help_utils.h" +#include "mocks/hci_core.h" +#include "mocks/hci_core_expects.h" +#include "mocks/hmac_prng.h" +#include "mocks/hmac_prng_expects.h" + +#include +#include +#include + +#include + +DEFINE_FFF_GLOBALS; + +static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) +{ + HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); + HMAC_PRNG_FFF_FAKES_LIST(RESET_FAKE); +} + +ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); + +ZTEST_SUITE(bt_rand, NULL, NULL, NULL, NULL, NULL); + +/* + * Test bt_rand() succeeds while 'CONFIG_BT_HOST_CRYPTO_PRNG' isn't enabled. + * + * Constraints: + * - 'CONFIG_BT_HOST_CRYPTO_PRNG' isn't enabled + * - bt_hci_le_rand() succeeds and returns 0 (success) + * + * Expected behaviour: + * - bt_rand() returns 0 (success) + */ +ZTEST(bt_rand, test_bt_rand_succeeds_host_crypto_prng_disabled) +{ + int err; + uint8_t buf[16]; + size_t buf_len = 16; + uint8_t expected_args_history[] = {16}; + + Z_TEST_SKIP_IFDEF(CONFIG_BT_HOST_CRYPTO_PRNG); + + bt_hci_le_rand_fake.return_val = 0; + + err = bt_rand(buf, buf_len); + + expect_call_count_bt_hci_le_rand(1, expected_args_history); + + zassert_ok(err, "Unexpected error code '%d' was returned", err); +} + +/* + * Test bt_rand() succeeds when tc_hmac_prng_generate() succeeds on the first call while + * 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled. + * + * Constraints: + * - 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled + * - tc_hmac_prng_generate() succeeds and returns 'TC_CRYPTO_SUCCESS' on the first call. + * + * Expected behaviour: + * - bt_rand() returns 0 (success) + */ +ZTEST(bt_rand, test_tc_hmac_prng_generate_succeeds_on_first_call) +{ + int err; + uint8_t buf[16]; + size_t buf_len = 16; + struct tc_hmac_prng_struct *hmac_prng = bt_crypto_get_hmac_prng_instance(); + + Z_TEST_SKIP_IFNDEF(CONFIG_BT_HOST_CRYPTO_PRNG); + + tc_hmac_prng_generate_fake.return_val = TC_CRYPTO_SUCCESS; + + err = bt_rand(buf, buf_len); + + expect_call_count_tc_hmac_prng_generate(1, buf, buf_len, hmac_prng); + + zassert_ok(err, "Unexpected error code '%d' was returned", err); +} + +static int tc_hmac_prng_generate_custom_fake(uint8_t *out, unsigned int outlen, TCHmacPrng_t prng) +{ + if (tc_hmac_prng_generate_fake.call_count == 1) { + return TC_HMAC_PRNG_RESEED_REQ; + } + + return TC_CRYPTO_SUCCESS; +} + +/* + * Test bt_rand() succeeds when tc_hmac_prng_generate() succeeds on the second call after a seeding + * request by tc_hmac_prng_generate() while 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled. + * + * Constraints: + * - 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled + * - tc_hmac_prng_generate() fails and returns 'TC_HMAC_PRNG_RESEED_REQ' on the first call. + * - tc_hmac_prng_generate() succeeds and returns 'TC_CRYPTO_SUCCESS' on the second call. + * + * Expected behaviour: + * - bt_rand() returns 0 (success) + */ +ZTEST(bt_rand, test_tc_hmac_prng_generate_succeeds_on_second_call) +{ + int err; + uint8_t buf[16]; + size_t buf_len = 16; + struct tc_hmac_prng_struct *hmac_prng = bt_crypto_get_hmac_prng_instance(); + + Z_TEST_SKIP_IFNDEF(CONFIG_BT_HOST_CRYPTO_PRNG); + + tc_hmac_prng_generate_fake.custom_fake = tc_hmac_prng_generate_custom_fake; + + /* This is to make prng_reseed() succeeds and return 0 */ + bt_hci_le_rand_fake.return_val = 0; + tc_hmac_prng_reseed_fake.return_val = TC_CRYPTO_SUCCESS; + + err = bt_rand(buf, buf_len); + + expect_call_count_tc_hmac_prng_generate(2, buf, buf_len, hmac_prng); + expect_single_call_tc_hmac_prng_reseed(hmac_prng, 32, sizeof(int64_t)); + + zassert_ok(err, "Unexpected error code '%d' was returned", err); +} diff --git a/tests/bluetooth/host/crypto/bt_rand/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/crypto/bt_rand/src/test_suite_invalid_inputs.c new file mode 100644 index 000000000000..b3c9e60e8f59 --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_rand/src/test_suite_invalid_inputs.c @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "host_mocks/assert.h" +#include "mocks/crypto_help_utils.h" +#include "mocks/hci_core.h" +#include "mocks/hci_core_expects.h" +#include "mocks/hmac_prng.h" +#include "mocks/hmac_prng_expects.h" + +#include +#include + +#include + +ZTEST_SUITE(bt_rand_invalid_cases, NULL, NULL, NULL, NULL, NULL); + +/* + * Test passing NULL reference destination buffer argument + * + * Constraints: + * - NULL reference is used as an argument for the destination buffer + * + * Expected behaviour: + * - An assertion is raised and execution stops + */ +ZTEST(bt_rand_invalid_cases, test_null_dst_buf_reference) +{ + expect_assert(); + bt_rand(NULL, 1); +} + +/* + * Test passing a valid destination buffer reference with size 0 + * + * Constraints: + * - A valid reference is used as an argument for the destination buffer + * - Destination buffer size is passed as 0 + * + * Expected behaviour: + * - An assertion is raised and execution stops + */ +ZTEST(bt_rand_invalid_cases, test_zero_dst_buf_size_reference) +{ + uint8_t buf[16]; + + expect_assert(); + bt_rand(buf, 0); +} + +/* + * Test bt_rand() fails when bt_hci_le_rand() fails while 'CONFIG_BT_HOST_CRYPTO_PRNG' + * isn't enabled. + * + * Constraints: + * - 'CONFIG_BT_HOST_CRYPTO_PRNG' isn't enabled + * - bt_hci_le_rand() fails and returns a negative error code. + * + * Expected behaviour: + * - bt_rand() returns a negative error code (failure) + */ +ZTEST(bt_rand_invalid_cases, test_bt_hci_le_rand_fails) +{ + int err; + uint8_t buf[16]; + size_t buf_len = 16; + uint8_t expected_args_history[] = {16}; + + Z_TEST_SKIP_IFDEF(CONFIG_BT_HOST_CRYPTO_PRNG); + + bt_hci_le_rand_fake.return_val = -1; + + err = bt_rand(buf, buf_len); + + expect_call_count_bt_hci_le_rand(1, expected_args_history); + + zassert_true(err < 0, "Unexpected error code '%d' was returned", err); +} + +/* + * Test bt_rand() fails when tc_hmac_prng_generate() fails on the first call while + * 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled. + * + * Constraints: + * - 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled + * - tc_hmac_prng_generate() fails and returns 'TC_CRYPTO_FAIL' on the first call. + * + * Expected behaviour: + * - bt_rand() returns a negative error code '-EIO' (failure) + */ +ZTEST(bt_rand_invalid_cases, test_tc_hmac_prng_generate_fails_on_first_call) +{ + int err; + uint8_t buf[16]; + size_t buf_len = 16; + struct tc_hmac_prng_struct *hmac_prng = bt_crypto_get_hmac_prng_instance(); + + Z_TEST_SKIP_IFNDEF(CONFIG_BT_HOST_CRYPTO_PRNG); + + tc_hmac_prng_generate_fake.return_val = TC_CRYPTO_FAIL; + + err = bt_rand(buf, buf_len); + + expect_call_count_tc_hmac_prng_generate(1, buf, buf_len, hmac_prng); + + zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err); +} + +/* + * Test bt_rand() fails when prng_reseed() fails on seeding request by tc_hmac_prng_generate() + * while 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled. + * + * Constraints: + * - 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled + * - tc_hmac_prng_generate() fails and returns 'TC_HMAC_PRNG_RESEED_REQ' on the first call. + * - prng_reseed() fails and returns a negative error code + * + * Expected behaviour: + * - bt_rand() returns a negative error code (failure) + */ +ZTEST(bt_rand_invalid_cases, test_prng_reseed_fails_on_seeding_request) +{ + int err; + uint8_t buf[16]; + size_t buf_len = 16; + struct tc_hmac_prng_struct *hmac_prng = bt_crypto_get_hmac_prng_instance(); + + Z_TEST_SKIP_IFNDEF(CONFIG_BT_HOST_CRYPTO_PRNG); + + tc_hmac_prng_generate_fake.return_val = TC_HMAC_PRNG_RESEED_REQ; + + /* This is to make prng_reseed() fails */ + bt_hci_le_rand_fake.return_val = -1; + + err = bt_rand(buf, buf_len); + + expect_call_count_tc_hmac_prng_generate(1, buf, buf_len, hmac_prng); + + zassert_true(err < 0, "Unexpected error code '%d' was returned", err); +} + +static int tc_hmac_prng_generate_custom_fake(uint8_t *out, unsigned int outlen, TCHmacPrng_t prng) +{ + if (tc_hmac_prng_generate_fake.call_count == 1) { + return TC_HMAC_PRNG_RESEED_REQ; + } + + return TC_CRYPTO_FAIL; +} + +/* + * Test bt_rand() fails when tc_hmac_prng_generate() fails on the second call after a seeding + * request by tc_hmac_prng_generate() while 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled. + * + * Constraints: + * - 'CONFIG_BT_HOST_CRYPTO_PRNG' is enabled + * - tc_hmac_prng_generate() fails and returns 'TC_HMAC_PRNG_RESEED_REQ' on the first call. + * - tc_hmac_prng_generate() fails and returns 'TC_CRYPTO_FAIL' on the second call. + * + * Expected behaviour: + * - bt_rand() returns a negative error code '-EIO' (failure) + */ +ZTEST(bt_rand_invalid_cases, test_tc_hmac_prng_generate_fails_on_second_call) +{ + int err; + uint8_t buf[16]; + size_t buf_len = 16; + struct tc_hmac_prng_struct *hmac_prng = bt_crypto_get_hmac_prng_instance(); + + Z_TEST_SKIP_IFNDEF(CONFIG_BT_HOST_CRYPTO_PRNG); + + tc_hmac_prng_generate_fake.custom_fake = tc_hmac_prng_generate_custom_fake; + + /* This is to make prng_reseed() succeeds and return 0 */ + bt_hci_le_rand_fake.return_val = 0; + tc_hmac_prng_reseed_fake.return_val = TC_CRYPTO_SUCCESS; + + err = bt_rand(buf, buf_len); + + expect_call_count_tc_hmac_prng_generate(2, buf, buf_len, hmac_prng); + expect_single_call_tc_hmac_prng_reseed(hmac_prng, 32, sizeof(int64_t)); + + zassert_true(err == -EIO, "Unexpected error code '%d' was returned", err); +} diff --git a/tests/bluetooth/host/crypto/bt_rand/testcase.yaml b/tests/bluetooth/host/crypto/bt_rand/testcase.yaml new file mode 100644 index 000000000000..47ece1ea71ef --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_rand/testcase.yaml @@ -0,0 +1,9 @@ +common: + tags: test_framework bluetooth host +tests: + bluetooth.host.bt_rand.default: + type: unit + bluetooth.host.bt_rand.host_crypto_prng_disabled: + type: unit + extra_configs: + - CONFIG_BT_HOST_CRYPTO_PRNG=n From 3638889505fb12a99bac8cb175053dfc06151575 Mon Sep 17 00:00:00 2001 From: Ahmed Moheb Date: Thu, 20 Oct 2022 13:09:30 +0200 Subject: [PATCH 0166/1906] tests: bluetooth: host: Add UT for bt_encrypt_le() Unit test project for bt_encrypt_le(). This is part of subsys/bluetooth/host/crypto.c unit testing. Signed-off-by: Ahmed Moheb --- .../host/crypto/bt_encrypt_le/CMakeLists.txt | 17 +++ .../host/crypto/bt_encrypt_le/prj.conf | 9 ++ .../host/crypto/bt_encrypt_le/src/main.c | 52 ++++++++ .../src/test_suite_invalid_inputs.c | 120 ++++++++++++++++++ .../host/crypto/bt_encrypt_le/testcase.yaml | 5 + 5 files changed, 203 insertions(+) create mode 100644 tests/bluetooth/host/crypto/bt_encrypt_le/CMakeLists.txt create mode 100644 tests/bluetooth/host/crypto/bt_encrypt_le/prj.conf create mode 100644 tests/bluetooth/host/crypto/bt_encrypt_le/src/main.c create mode 100644 tests/bluetooth/host/crypto/bt_encrypt_le/src/test_suite_invalid_inputs.c create mode 100644 tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/CMakeLists.txt b/tests/bluetooth/host/crypto/bt_encrypt_le/CMakeLists.txt new file mode 100644 index 000000000000..515194c85cb5 --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_encrypt_le/CMakeLists.txt @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +set(SOURCES + src/main.c + src/test_suite_invalid_inputs.c +) + +project(bt_encrypt_le) + +find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) + +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/crypto mocks) + +target_link_libraries(testbinary PRIVATE mocks host_mocks) diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/prj.conf b/tests/bluetooth/host/crypto/bt_encrypt_le/prj.conf new file mode 100644 index 000000000000..542d140aa567 --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_encrypt_le/prj.conf @@ -0,0 +1,9 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_BT=y +CONFIG_BT_CENTRAL=y +CONFIG_BT_MAX_PAIRED=7 +CONFIG_ASSERT=y +CONFIG_ASSERT_LEVEL=2 +CONFIG_ASSERT_VERBOSE=y +CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/src/main.c b/tests/bluetooth/host/crypto/bt_encrypt_le/src/main.c new file mode 100644 index 000000000000..4442885456e8 --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_encrypt_le/src/main.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mocks/aes.h" +#include "mocks/aes_expects.h" + +#include +#include +#include + +#include + +DEFINE_FFF_GLOBALS; + +static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) +{ + AES_FFF_FAKES_LIST(RESET_FAKE); +} + +ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); + +ZTEST_SUITE(bt_encrypt_le, NULL, NULL, NULL, NULL, NULL); + +/* + * Test bt_encrypt_le() succeeds + * + * Constraints: + * - tc_aes128_set_encrypt_key() succeeds and returns 'TC_CRYPTO_SUCCESS'. + * - tc_aes_encrypt() succeeds and returns 'TC_CRYPTO_SUCCESS'. + * + * Expected behaviour: + * - bt_encrypt_le() returns 0 (success) + */ +ZTEST(bt_encrypt_le, test_bt_encrypt_le_succeeds) +{ + int err; + const uint8_t key[16] = {0}; + const uint8_t plaintext[16] = {0}; + uint8_t enc_data[16] = {0}; + + tc_aes128_set_encrypt_key_fake.return_val = TC_CRYPTO_SUCCESS; + tc_aes_encrypt_fake.return_val = TC_CRYPTO_SUCCESS; + + err = bt_encrypt_le(key, plaintext, enc_data); + + expect_single_call_tc_aes_encrypt(enc_data); + + zassert_ok(err, "Unexpected error code '%d' was returned", err); +} diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/crypto/bt_encrypt_le/src/test_suite_invalid_inputs.c new file mode 100644 index 000000000000..2e32d47f3467 --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_encrypt_le/src/test_suite_invalid_inputs.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "host_mocks/assert.h" +#include "mocks/aes.h" + +#include +#include + +#include + +ZTEST_SUITE(bt_encrypt_le_invalid_cases, NULL, NULL, NULL, NULL, NULL); + +/* + * Test passing NULL reference for the key argument + * + * Constraints: + * - NULL reference is used for the key argument + * - Valid references are used for the other arguments + * + * Expected behaviour: + * - An assertion is raised and execution stops + */ +ZTEST(bt_encrypt_le_invalid_cases, test_null_key_reference) +{ + const uint8_t plaintext[16] = {0}; + uint8_t enc_data[16] = {0}; + + expect_assert(); + bt_encrypt_le(NULL, plaintext, enc_data); +} + +/* + * Test passing NULL reference for the plain text argument + * + * Constraints: + * - NULL reference is used for the plain text argument + * - Valid references are used for the other arguments + * + * Expected behaviour: + * - An assertion is raised and execution stops + */ +ZTEST(bt_encrypt_le_invalid_cases, test_null_plaintext_reference) +{ + const uint8_t key[16] = {0}; + uint8_t enc_data[16] = {0}; + + expect_assert(); + bt_encrypt_le(key, NULL, enc_data); +} + +/* + * Test passing NULL reference for the encrypted data destination buffer argument + * + * Constraints: + * - NULL reference is used for the encrypted data destination buffer argument + * - Valid references are used for the other arguments + * + * Expected behaviour: + * - An assertion is raised and execution stops + */ +ZTEST(bt_encrypt_le_invalid_cases, test_null_enc_data_reference) +{ + const uint8_t key[16] = {0}; + const uint8_t plaintext[16] = {0}; + + expect_assert(); + bt_encrypt_le(key, plaintext, NULL); +} + +/* + * Test bt_encrypt_le() fails when tc_aes128_set_encrypt_key() fails + * + * Constraints: + * - tc_aes128_set_encrypt_key() fails and returns 'TC_CRYPTO_FAIL'. + * + * Expected behaviour: + * - bt_encrypt_le() returns a negative error code '-EINVAL' (failure) + */ +ZTEST(bt_encrypt_le_invalid_cases, test_tc_aes128_set_encrypt_key_fails) +{ + int err; + const uint8_t key[16] = {0}; + const uint8_t plaintext[16] = {0}; + uint8_t enc_data[16] = {0}; + + tc_aes128_set_encrypt_key_fake.return_val = TC_CRYPTO_FAIL; + + err = bt_encrypt_le(key, plaintext, enc_data); + + zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); +} + +/* + * Test bt_encrypt_le() fails when tc_aes_encrypt() fails + * + * Constraints: + * - tc_aes128_set_encrypt_key() succeeds and returns 'TC_CRYPTO_SUCCESS'. + * - tc_aes_encrypt() fails and returns 'TC_CRYPTO_FAIL'. + * + * Expected behaviour: + * - bt_encrypt_le() returns a negative error code '-EINVAL' (failure) + */ +ZTEST(bt_encrypt_le_invalid_cases, test_tc_aes_encrypt_fails) +{ + int err; + const uint8_t key[16] = {0}; + const uint8_t plaintext[16] = {0}; + uint8_t enc_data[16] = {0}; + + tc_aes128_set_encrypt_key_fake.return_val = TC_CRYPTO_SUCCESS; + tc_aes_encrypt_fake.return_val = TC_CRYPTO_FAIL; + + err = bt_encrypt_le(key, plaintext, enc_data); + + zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); +} diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml b/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml new file mode 100644 index 000000000000..e311b01269f0 --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml @@ -0,0 +1,5 @@ +common: + tags: test_framework bluetooth host +tests: + bluetooth.host.bt_encrypt_le.default: + type: unit From 15ed0457b5254ee7cd3d9dc411c45a6dd56b05f8 Mon Sep 17 00:00:00 2001 From: Ahmed Moheb Date: Thu, 20 Oct 2022 16:37:02 +0200 Subject: [PATCH 0167/1906] tests: bluetooth: host: Add UT for bt_encrypt_be() Unit test project for bt_encrypt_be(). This is part of subsys/bluetooth/host/crypto.c unit testing. Signed-off-by: Ahmed Moheb --- .../host/crypto/bt_encrypt_be/CMakeLists.txt | 17 +++ .../host/crypto/bt_encrypt_be/prj.conf | 9 ++ .../host/crypto/bt_encrypt_be/src/main.c | 52 ++++++++ .../src/test_suite_invalid_inputs.c | 120 ++++++++++++++++++ .../host/crypto/bt_encrypt_be/testcase.yaml | 5 + 5 files changed, 203 insertions(+) create mode 100644 tests/bluetooth/host/crypto/bt_encrypt_be/CMakeLists.txt create mode 100644 tests/bluetooth/host/crypto/bt_encrypt_be/prj.conf create mode 100644 tests/bluetooth/host/crypto/bt_encrypt_be/src/main.c create mode 100644 tests/bluetooth/host/crypto/bt_encrypt_be/src/test_suite_invalid_inputs.c create mode 100644 tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/CMakeLists.txt b/tests/bluetooth/host/crypto/bt_encrypt_be/CMakeLists.txt new file mode 100644 index 000000000000..01d383c7c4b3 --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_encrypt_be/CMakeLists.txt @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +set(SOURCES + src/main.c + src/test_suite_invalid_inputs.c +) + +project(bt_encrypt_be) + +find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) + +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/crypto mocks) + +target_link_libraries(testbinary PRIVATE mocks host_mocks) diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/prj.conf b/tests/bluetooth/host/crypto/bt_encrypt_be/prj.conf new file mode 100644 index 000000000000..542d140aa567 --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_encrypt_be/prj.conf @@ -0,0 +1,9 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_BT=y +CONFIG_BT_CENTRAL=y +CONFIG_BT_MAX_PAIRED=7 +CONFIG_ASSERT=y +CONFIG_ASSERT_LEVEL=2 +CONFIG_ASSERT_VERBOSE=y +CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/src/main.c b/tests/bluetooth/host/crypto/bt_encrypt_be/src/main.c new file mode 100644 index 000000000000..32e9ada29116 --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_encrypt_be/src/main.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mocks/aes.h" +#include "mocks/aes_expects.h" + +#include +#include +#include + +#include + +DEFINE_FFF_GLOBALS; + +static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) +{ + AES_FFF_FAKES_LIST(RESET_FAKE); +} + +ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); + +ZTEST_SUITE(bt_encrypt_be, NULL, NULL, NULL, NULL, NULL); + +/* + * Test bt_encrypt_be() succeeds + * + * Constraints: + * - tc_aes128_set_encrypt_key() succeeds and returns 'TC_CRYPTO_SUCCESS'. + * - tc_aes_encrypt() succeeds and returns 'TC_CRYPTO_SUCCESS'. + * + * Expected behaviour: + * - bt_encrypt_be() returns 0 (success) + */ +ZTEST(bt_encrypt_be, test_bt_encrypt_be_succeeds) +{ + int err; + const uint8_t key[16] = {0}; + const uint8_t plaintext[16] = {0}; + uint8_t enc_data[16] = {0}; + + tc_aes128_set_encrypt_key_fake.return_val = TC_CRYPTO_SUCCESS; + tc_aes_encrypt_fake.return_val = TC_CRYPTO_SUCCESS; + + err = bt_encrypt_be(key, plaintext, enc_data); + + expect_single_call_tc_aes_encrypt(enc_data); + + zassert_ok(err, "Unexpected error code '%d' was returned", err); +} diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/crypto/bt_encrypt_be/src/test_suite_invalid_inputs.c new file mode 100644 index 000000000000..2e32d47f3467 --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_encrypt_be/src/test_suite_invalid_inputs.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "host_mocks/assert.h" +#include "mocks/aes.h" + +#include +#include + +#include + +ZTEST_SUITE(bt_encrypt_le_invalid_cases, NULL, NULL, NULL, NULL, NULL); + +/* + * Test passing NULL reference for the key argument + * + * Constraints: + * - NULL reference is used for the key argument + * - Valid references are used for the other arguments + * + * Expected behaviour: + * - An assertion is raised and execution stops + */ +ZTEST(bt_encrypt_le_invalid_cases, test_null_key_reference) +{ + const uint8_t plaintext[16] = {0}; + uint8_t enc_data[16] = {0}; + + expect_assert(); + bt_encrypt_le(NULL, plaintext, enc_data); +} + +/* + * Test passing NULL reference for the plain text argument + * + * Constraints: + * - NULL reference is used for the plain text argument + * - Valid references are used for the other arguments + * + * Expected behaviour: + * - An assertion is raised and execution stops + */ +ZTEST(bt_encrypt_le_invalid_cases, test_null_plaintext_reference) +{ + const uint8_t key[16] = {0}; + uint8_t enc_data[16] = {0}; + + expect_assert(); + bt_encrypt_le(key, NULL, enc_data); +} + +/* + * Test passing NULL reference for the encrypted data destination buffer argument + * + * Constraints: + * - NULL reference is used for the encrypted data destination buffer argument + * - Valid references are used for the other arguments + * + * Expected behaviour: + * - An assertion is raised and execution stops + */ +ZTEST(bt_encrypt_le_invalid_cases, test_null_enc_data_reference) +{ + const uint8_t key[16] = {0}; + const uint8_t plaintext[16] = {0}; + + expect_assert(); + bt_encrypt_le(key, plaintext, NULL); +} + +/* + * Test bt_encrypt_le() fails when tc_aes128_set_encrypt_key() fails + * + * Constraints: + * - tc_aes128_set_encrypt_key() fails and returns 'TC_CRYPTO_FAIL'. + * + * Expected behaviour: + * - bt_encrypt_le() returns a negative error code '-EINVAL' (failure) + */ +ZTEST(bt_encrypt_le_invalid_cases, test_tc_aes128_set_encrypt_key_fails) +{ + int err; + const uint8_t key[16] = {0}; + const uint8_t plaintext[16] = {0}; + uint8_t enc_data[16] = {0}; + + tc_aes128_set_encrypt_key_fake.return_val = TC_CRYPTO_FAIL; + + err = bt_encrypt_le(key, plaintext, enc_data); + + zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); +} + +/* + * Test bt_encrypt_le() fails when tc_aes_encrypt() fails + * + * Constraints: + * - tc_aes128_set_encrypt_key() succeeds and returns 'TC_CRYPTO_SUCCESS'. + * - tc_aes_encrypt() fails and returns 'TC_CRYPTO_FAIL'. + * + * Expected behaviour: + * - bt_encrypt_le() returns a negative error code '-EINVAL' (failure) + */ +ZTEST(bt_encrypt_le_invalid_cases, test_tc_aes_encrypt_fails) +{ + int err; + const uint8_t key[16] = {0}; + const uint8_t plaintext[16] = {0}; + uint8_t enc_data[16] = {0}; + + tc_aes128_set_encrypt_key_fake.return_val = TC_CRYPTO_SUCCESS; + tc_aes_encrypt_fake.return_val = TC_CRYPTO_FAIL; + + err = bt_encrypt_le(key, plaintext, enc_data); + + zassert_true(err == -EINVAL, "Unexpected error code '%d' was returned", err); +} diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml b/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml new file mode 100644 index 000000000000..fe49e6034c94 --- /dev/null +++ b/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml @@ -0,0 +1,5 @@ +common: + tags: test_framework bluetooth host +tests: + bluetooth.host.bt_encrypt_be.default: + type: unit From 6c40abb99f4536cf8fd15b765a738ee29201dbf0 Mon Sep 17 00:00:00 2001 From: Jaxson Han Date: Sun, 24 Jul 2022 21:58:09 +0800 Subject: [PATCH 0168/1906] arch: arm64: Introduce safe exception stack Introduce two configs to prepare to enable the safe exception stack for the kernel space. This is the preparation for enabling hardware stack guard. Also define the safe exception stack for kernel exception stack check. Signed-off-by: Jaxson Han --- arch/arm64/core/Kconfig | 16 ++++++++++++++++ arch/arm64/core/fatal.c | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/arch/arm64/core/Kconfig b/arch/arm64/core/Kconfig index 968454634f78..8853f4dbf008 100644 --- a/arch/arm64/core/Kconfig +++ b/arch/arm64/core/Kconfig @@ -110,6 +110,22 @@ config WAIT_AT_RESET_VECTOR Spin at reset vector waiting for debugger to attach and resume execution +config ARM64_SAFE_EXCEPTION_STACK + bool "To enable the safe exception stack" + help + The safe exception stack is used for checking whether the kernel stack + overflows during the exception happens from EL1. This stack is not + used for user stack overflow checking, because kernel stack support + the checking work. + +config ARM64_SAFE_EXCEPTION_STACK_SIZE + int "The stack size of the safe exception stack" + default 4096 + depends on ARM64_SAFE_EXCEPTION_STACK + help + The stack size of the safe exception stack. The safe exception stack + requires to be enough to do the stack overflow check. + if CPU_CORTEX_A config ARMV8_A_NS diff --git a/arch/arm64/core/fatal.c b/arch/arm64/core/fatal.c index 7c1c16544be3..64cd4d62940b 100644 --- a/arch/arm64/core/fatal.c +++ b/arch/arm64/core/fatal.c @@ -20,6 +20,12 @@ LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK +K_KERNEL_PINNED_STACK_ARRAY_DEFINE(z_arm64_safe_exception_stacks, + CONFIG_MP_MAX_NUM_CPUS, + CONFIG_ARM64_SAFE_EXCEPTION_STACK_SIZE); +#endif + #ifdef CONFIG_USERSPACE Z_EXC_DECLARE(z_arm64_user_string_nlen); From d8d74b13209a9f5c9480f88256a81ee0d7b00e3c Mon Sep 17 00:00:00 2001 From: Jaxson Han Date: Tue, 25 Oct 2022 14:55:47 +0800 Subject: [PATCH 0169/1906] arch: arm64: Add el label for vector entry macro Add a new label el for z_arm64_enter_exc to indicate which el the exception comes from. Signed-off-by: Jaxson Han --- arch/arm64/core/vector_table.S | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/arch/arm64/core/vector_table.S b/arch/arm64/core/vector_table.S index ffb5a452cdb6..2b547995af20 100644 --- a/arch/arm64/core/vector_table.S +++ b/arch/arm64/core/vector_table.S @@ -24,7 +24,7 @@ _ASM_FILE_PROLOGUE * ISR and/or context switch. */ -.macro z_arm64_enter_exc xreg0, xreg1 +.macro z_arm64_enter_exc xreg0, xreg1, el /* * Two things can happen to the remaining registers: * @@ -111,12 +111,12 @@ SECTION_SUBSEC_FUNC(exc_vector_table,_vector_table_section,_vector_table) /* Current EL with SP0 / Synchronous */ .align 7 - z_arm64_enter_exc x0, x1 + z_arm64_enter_exc x0, x1, el1 b z_arm64_sync_exc /* Current EL with SP0 / IRQ */ .align 7 - z_arm64_enter_exc x0, x1 + z_arm64_enter_exc x0, x1, el1 #ifdef CONFIG_GEN_SW_ISR_TABLE b _isr_wrapper #else @@ -129,17 +129,17 @@ SECTION_SUBSEC_FUNC(exc_vector_table,_vector_table_section,_vector_table) /* Current EL with SP0 / SError */ .align 7 - z_arm64_enter_exc x0, x1 + z_arm64_enter_exc x0, x1, el1 b z_arm64_serror /* Current EL with SPx / Synchronous */ .align 7 - z_arm64_enter_exc x0, x1 + z_arm64_enter_exc x0, x1, el1 b z_arm64_sync_exc /* Current EL with SPx / IRQ */ .align 7 - z_arm64_enter_exc x0, x1 + z_arm64_enter_exc x0, x1, el1 #ifdef CONFIG_GEN_SW_ISR_TABLE b _isr_wrapper #else @@ -152,17 +152,17 @@ SECTION_SUBSEC_FUNC(exc_vector_table,_vector_table_section,_vector_table) /* Current EL with SPx / SError */ .align 7 - z_arm64_enter_exc x0, x1 + z_arm64_enter_exc x0, x1, el1 b z_arm64_serror /* Lower EL using AArch64 / Synchronous */ .align 7 - z_arm64_enter_exc x0, x1 + z_arm64_enter_exc x0, x1, el0 b z_arm64_sync_exc /* Lower EL using AArch64 / IRQ */ .align 7 - z_arm64_enter_exc x0, x1 + z_arm64_enter_exc x0, x1, el0 #ifdef CONFIG_GEN_SW_ISR_TABLE b _isr_wrapper #else @@ -175,7 +175,7 @@ SECTION_SUBSEC_FUNC(exc_vector_table,_vector_table_section,_vector_table) /* Lower EL using AArch64 / SError */ .align 7 - z_arm64_enter_exc x0, x1 + z_arm64_enter_exc x0, x1, el0 b z_arm64_serror /* Lower EL using AArch32 / Synchronous */ From 7040c554386280cf87ee22bdc533816d07571b3e Mon Sep 17 00:00:00 2001 From: Jaxson Han Date: Tue, 1 Nov 2022 15:32:50 +0800 Subject: [PATCH 0170/1906] arch: arm64: Add stack check relevant variables to _cpu_arch_t Add three per-cpu variables for the convenience of quickly accessing. The safe_exception_stack stores the top of safe exception stack pointer. The current_stack_limit stores the current thread's priv stack limit. The corrputed_sp stores the priv sp or irq sp for the stack overflow case, or 0 for the normal case. Signed-off-by: Jaxson Han --- arch/arm64/core/offsets/offsets.c | 6 ++++++ arch/arm64/include/offsets_short_arch.h | 9 +++++++++ include/zephyr/arch/arm64/structs.h | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/arch/arm64/core/offsets/offsets.c b/arch/arm64/core/offsets/offsets.c index aa49d6848660..52f67f0a0a8c 100644 --- a/arch/arm64/core/offsets/offsets.c +++ b/arch/arm64/core/offsets/offsets.c @@ -56,6 +56,12 @@ GEN_NAMED_OFFSET_SYM(_esf_t, x0, x0_x1); GEN_ABSOLUTE_SYM(___esf_t_SIZEOF, sizeof(_esf_t)); +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK +GEN_OFFSET_SYM(_cpu_arch_t, safe_exception_stack); +GEN_OFFSET_SYM(_cpu_arch_t, current_stack_limit); +GEN_OFFSET_SYM(_cpu_arch_t, corrupted_sp); +#endif + #ifdef CONFIG_HAS_ARM_SMCCC #include diff --git a/arch/arm64/include/offsets_short_arch.h b/arch/arm64/include/offsets_short_arch.h index aeae8430a8e6..fe9b1a5d2e66 100644 --- a/arch/arm64/include/offsets_short_arch.h +++ b/arch/arm64/include/offsets_short_arch.h @@ -27,4 +27,13 @@ #define _thread_offset_to_callee_saved_sp_elx_lr \ (___thread_t_callee_saved_OFFSET + ___callee_saved_t_sp_elx_lr_OFFSET) +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK +#define _cpu_offset_to_safe_exception_stack \ + (___cpu_t_arch_OFFSET + ___cpu_arch_t_safe_exception_stack_OFFSET) +#define _cpu_offset_to_current_stack_limit \ + (___cpu_t_arch_OFFSET + ___cpu_arch_t_current_stack_limit_OFFSET) +#define _cpu_offset_to_corrupted_sp \ + (___cpu_t_arch_OFFSET + ___cpu_arch_t_corrupted_sp_OFFSET) +#endif + #endif /* ZEPHYR_ARCH_ARM64_INCLUDE_OFFSETS_SHORT_ARCH_H_ */ diff --git a/include/zephyr/arch/arm64/structs.h b/include/zephyr/arch/arm64/structs.h index 25052ccabe49..88068c837ce9 100644 --- a/include/zephyr/arch/arm64/structs.h +++ b/include/zephyr/arch/arm64/structs.h @@ -12,6 +12,12 @@ struct _cpu_arch { #ifdef CONFIG_FPU_SHARING struct k_thread *fpu_owner; #endif +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK + uint64_t safe_exception_stack; + uint64_t current_stack_limit; + /* Saved the corrupted stack pointer when stack overflow, else 0 */ + uint64_t corrupted_sp; +#endif }; #endif /* ZEPHYR_INCLUDE_ARM64_STRUCTS_H_ */ From 61b8b34b271f72ef37e6a6b7696e7c8e7d59dde7 Mon Sep 17 00:00:00 2001 From: Jaxson Han Date: Tue, 1 Nov 2022 15:47:25 +0800 Subject: [PATCH 0171/1906] arch: arm64: Add the sp variable in _esf_t As the preparation for enabling safe exception stack, add a variable in _esf_t to save the user stack held by sp_el0 at the point of the exception happening from EL0. The newly added variable in _esf_t is named sp from which the user stack will be restored when exceptions eret to EL0. Signed-off-by: Jaxson Han --- arch/arm64/core/offsets/offsets.c | 1 + include/zephyr/arch/arm64/exc.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/arch/arm64/core/offsets/offsets.c b/arch/arm64/core/offsets/offsets.c index 52f67f0a0a8c..daa086abbbf1 100644 --- a/arch/arm64/core/offsets/offsets.c +++ b/arch/arm64/core/offsets/offsets.c @@ -60,6 +60,7 @@ GEN_ABSOLUTE_SYM(___esf_t_SIZEOF, sizeof(_esf_t)); GEN_OFFSET_SYM(_cpu_arch_t, safe_exception_stack); GEN_OFFSET_SYM(_cpu_arch_t, current_stack_limit); GEN_OFFSET_SYM(_cpu_arch_t, corrupted_sp); +GEN_NAMED_OFFSET_SYM(_esf_t, sp, sp_el0); #endif #ifdef CONFIG_HAS_ARM_SMCCC diff --git a/include/zephyr/arch/arm64/exc.h b/include/zephyr/arch/arm64/exc.h index 3a23fa8bfdf4..ccbb903360cb 100644 --- a/include/zephyr/arch/arm64/exc.h +++ b/include/zephyr/arch/arm64/exc.h @@ -47,6 +47,9 @@ struct __esf { uint64_t lr; uint64_t spsr; uint64_t elr; +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK + uint64_t sp; +#endif } __aligned(16); typedef struct __esf z_arch_esf_t; From 3a5fa0498f0ca9ad951da04a0e4ded6c9266ec2a Mon Sep 17 00:00:00 2001 From: Jaxson Han Date: Fri, 20 Jan 2023 22:56:22 +0800 Subject: [PATCH 0172/1906] arch: arm64: Add stack_limit to thread_arch_t Add stack_limit to thread_arch_t to store the thread's stack limit. Signed-off-by: Jaxson Han --- arch/arm64/core/offsets/offsets.c | 1 + arch/arm64/include/offsets_short_arch.h | 2 ++ include/zephyr/arch/arm64/thread.h | 3 +++ 3 files changed, 6 insertions(+) diff --git a/arch/arm64/core/offsets/offsets.c b/arch/arm64/core/offsets/offsets.c index daa086abbbf1..7ff6eee31d95 100644 --- a/arch/arm64/core/offsets/offsets.c +++ b/arch/arm64/core/offsets/offsets.c @@ -60,6 +60,7 @@ GEN_ABSOLUTE_SYM(___esf_t_SIZEOF, sizeof(_esf_t)); GEN_OFFSET_SYM(_cpu_arch_t, safe_exception_stack); GEN_OFFSET_SYM(_cpu_arch_t, current_stack_limit); GEN_OFFSET_SYM(_cpu_arch_t, corrupted_sp); +GEN_OFFSET_SYM(_thread_arch_t, stack_limit); GEN_NAMED_OFFSET_SYM(_esf_t, sp, sp_el0); #endif diff --git a/arch/arm64/include/offsets_short_arch.h b/arch/arm64/include/offsets_short_arch.h index fe9b1a5d2e66..abd93bba7bac 100644 --- a/arch/arm64/include/offsets_short_arch.h +++ b/arch/arm64/include/offsets_short_arch.h @@ -34,6 +34,8 @@ (___cpu_t_arch_OFFSET + ___cpu_arch_t_current_stack_limit_OFFSET) #define _cpu_offset_to_corrupted_sp \ (___cpu_t_arch_OFFSET + ___cpu_arch_t_corrupted_sp_OFFSET) +#define _thread_offset_to_stack_limit \ + (___thread_t_arch_OFFSET + ___thread_arch_t_stack_limit_OFFSET) #endif #endif /* ZEPHYR_ARCH_ARM64_INCLUDE_OFFSETS_SHORT_ARCH_H_ */ diff --git a/include/zephyr/arch/arm64/thread.h b/include/zephyr/arch/arm64/thread.h index 377f4c376876..c03b65c2af2d 100644 --- a/include/zephyr/arch/arm64/thread.h +++ b/include/zephyr/arch/arm64/thread.h @@ -53,6 +53,9 @@ struct _thread_arch { #if defined(CONFIG_USERSPACE) && defined(CONFIG_ARM_MMU) struct arm_mmu_ptables *ptables; #endif +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK + uint64_t stack_limit; +#endif #ifdef CONFIG_FPU_SHARING struct z_arm64_fp_context saved_fp_context; #endif From 463b1c9396d2385b8e6028db09e0d73139a1f52c Mon Sep 17 00:00:00 2001 From: Jaxson Han Date: Tue, 1 Nov 2022 16:03:42 +0800 Subject: [PATCH 0173/1906] arch: arm64: Add safe exception stack init function Add safe exception stack init function which does several things: 1) setting current cpu safe exception stack pointer to its corresponding stack top. 2) init sp_el0 with the above safe exception stack. That makes sure the sp_el0 points to per-cpu safe_stack in the kernel space. 3) init the current_stack_limit and corrupted_sp with 0 Signed-off-by: Jaxson Han --- arch/arm64/core/fatal.c | 15 +++++++++++++++ arch/arm64/core/prep_c.c | 4 ++++ arch/arm64/core/smp.c | 3 +++ arch/arm64/include/kernel_arch_func.h | 4 ++++ include/zephyr/arch/arm64/lib_helpers.h | 1 + 5 files changed, 27 insertions(+) diff --git a/arch/arm64/core/fatal.c b/arch/arm64/core/fatal.c index 64cd4d62940b..96211f14c67f 100644 --- a/arch/arm64/core/fatal.c +++ b/arch/arm64/core/fatal.c @@ -24,6 +24,21 @@ LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); K_KERNEL_PINNED_STACK_ARRAY_DEFINE(z_arm64_safe_exception_stacks, CONFIG_MP_MAX_NUM_CPUS, CONFIG_ARM64_SAFE_EXCEPTION_STACK_SIZE); + +void z_arm64_safe_exception_stack_init(void) +{ + int cpu_id; + char *safe_exc_sp; + + cpu_id = arch_curr_cpu()->id; + safe_exc_sp = Z_KERNEL_STACK_BUFFER(z_arm64_safe_exception_stacks[cpu_id]) + + CONFIG_ARM64_SAFE_EXCEPTION_STACK_SIZE; + arch_curr_cpu()->arch.safe_exception_stack = (uint64_t)safe_exc_sp; + write_sp_el0((uint64_t)safe_exc_sp); + + arch_curr_cpu()->arch.current_stack_limit = 0UL; + arch_curr_cpu()->arch.corrupted_sp = 0UL; +} #endif #ifdef CONFIG_USERSPACE diff --git a/arch/arm64/core/prep_c.c b/arch/arm64/core/prep_c.c index 395e0058dcc7..2f40aff0ef58 100644 --- a/arch/arm64/core/prep_c.c +++ b/arch/arm64/core/prep_c.c @@ -58,6 +58,10 @@ void z_arm64_prep_c(void) z_bss_zero(); z_data_copy(); +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK + /* After bss clean, _kernel.cpus is in bss section */ + z_arm64_safe_exception_stack_init(); +#endif z_arm64_mm_init(true); z_arm64_interrupt_init(); z_cstart(); diff --git a/arch/arm64/core/smp.c b/arch/arm64/core/smp.c index a8686114feeb..b09f26fdfdb6 100644 --- a/arch/arm64/core/smp.c +++ b/arch/arm64/core/smp.c @@ -119,6 +119,9 @@ void z_arm64_secondary_start(void) /* Initialize tpidrro_el0 with our struct _cpu instance address */ write_tpidrro_el0((uintptr_t)&_kernel.cpus[cpu_num]); +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK + z_arm64_safe_exception_stack_init(); +#endif z_arm64_mm_init(false); diff --git a/arch/arm64/include/kernel_arch_func.h b/arch/arm64/include/kernel_arch_func.h index d90860415384..014c166db005 100644 --- a/arch/arm64/include/kernel_arch_func.h +++ b/arch/arm64/include/kernel_arch_func.h @@ -52,6 +52,10 @@ void z_arm64_flush_local_fpu(void); void z_arm64_flush_fpu_ipi(unsigned int cpu); #endif +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK +void z_arm64_safe_exception_stack_init(void); +#endif + #endif /* _ASMLANGUAGE */ #ifdef __cplusplus diff --git a/include/zephyr/arch/arm64/lib_helpers.h b/include/zephyr/arch/arm64/lib_helpers.h index 7f7e2c319fef..f133f4b46852 100644 --- a/include/zephyr/arch/arm64/lib_helpers.h +++ b/include/zephyr/arch/arm64/lib_helpers.h @@ -74,6 +74,7 @@ MAKE_REG_HELPER(par_el1) MAKE_REG_HELPER(scr_el3); MAKE_REG_HELPER(tpidrro_el0); MAKE_REG_HELPER(vmpidr_el2); +MAKE_REG_HELPER(sp_el0); MAKE_REG_HELPER_EL123(actlr) MAKE_REG_HELPER_EL123(cpacr) From 00adc0b4938d4ee564553c660fceb76464163800 Mon Sep 17 00:00:00 2001 From: Jaxson Han Date: Tue, 1 Nov 2022 16:11:45 +0800 Subject: [PATCH 0174/1906] arch: arm64: Enable safe exception stack This commit mainly enable the safe exception stack including the stack switch. Init the safe exception stack by calling z_arm64_safe_exception_stack during the boot stage on every core. Also, tweaks several files to properly switch the mode with different cases. 1) The same as before, when executing in userspace, SP_EL0 holds the user stack and SP_EL1 holds the privileged stack, using EL1h mode. 2) When entering exception from EL0 then SP_EL0 will be saved in the _esf_t structure. SP_EL1 will be the current SP, then retrieves the safe exception stack to SP_EL0, making sure the always pointing to safe exception stack as long as the system running in kernel space. 3) When exiting exception from EL1 to EL0 then SP_EL0 will be restored from the stack value previously saved in the _esf_t structure. Still at EL1h mode. 4) Either entering or exiting exception from EL1 to EL1, SP_EL0 will keep holding the safe exception stack unchanged as memtioned above. 5) Do a quick stack check every time entering the exception from EL1 to EL1. If check fail, set SP_EL1 to safe exception stack, and then handle the fatal error. Overall, the exception from user mode will be handled with kernel stack at the assumption that it is impossible the stackoverflow happens at the entry of exception from EL0 to EL1. However the exception from kernel mode will be firstly checked with the safe exception stack to see if the kernel stack overflows, because the exception might be triggered by stack invalid accessing. Signed-off-by: Jaxson Han --- arch/arm64/core/switch.S | 10 ++++ arch/arm64/core/vector_table.S | 91 ++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/arch/arm64/core/switch.S b/arch/arm64/core/switch.S index aaf7f506ab8a..95c1a44aa47d 100644 --- a/arch/arm64/core/switch.S +++ b/arch/arm64/core/switch.S @@ -32,15 +32,21 @@ _ASM_FILE_PROLOGUE GTEXT(z_arm64_context_switch) SECTION_FUNC(TEXT, z_arm64_context_switch) +#ifndef CONFIG_ARM64_SAFE_EXCEPTION_STACK /* Save the current SP_EL0 */ mrs x4, sp_el0 +#endif stp x19, x20, [x1, #_thread_offset_to_callee_saved_x19_x20] stp x21, x22, [x1, #_thread_offset_to_callee_saved_x21_x22] stp x23, x24, [x1, #_thread_offset_to_callee_saved_x23_x24] stp x25, x26, [x1, #_thread_offset_to_callee_saved_x25_x26] stp x27, x28, [x1, #_thread_offset_to_callee_saved_x27_x28] +#ifndef CONFIG_ARM64_SAFE_EXCEPTION_STACK stp x29, x4, [x1, #_thread_offset_to_callee_saved_x29_sp_el0] +#else + str x29, [x1, #_thread_offset_to_callee_saved_x29_sp_el0] +#endif /* Save the current SP_ELx and return address */ mov x4, sp @@ -89,10 +95,14 @@ SECTION_FUNC(TEXT, z_arm64_context_switch) ldp x23, x24, [x0, #_thread_offset_to_callee_saved_x23_x24] ldp x25, x26, [x0, #_thread_offset_to_callee_saved_x25_x26] ldp x27, x28, [x0, #_thread_offset_to_callee_saved_x27_x28] +#ifndef CONFIG_ARM64_SAFE_EXCEPTION_STACK ldp x29, x4, [x0, #_thread_offset_to_callee_saved_x29_sp_el0] /* Restore SP_EL0 */ msr sp_el0, x4 +#else + ldr x29, [x0, #_thread_offset_to_callee_saved_x29_sp_el0] +#endif /* Restore SP_EL1 and return address */ ldp x4, lr, [x0, #_thread_offset_to_callee_saved_sp_elx_lr] diff --git a/arch/arm64/core/vector_table.S b/arch/arm64/core/vector_table.S index 2b547995af20..b32e07fd6726 100644 --- a/arch/arm64/core/vector_table.S +++ b/arch/arm64/core/vector_table.S @@ -13,6 +13,9 @@ #include #include #include +#include +#include "macro_priv.inc" + _ASM_FILE_PROLOGUE @@ -36,6 +39,21 @@ _ASM_FILE_PROLOGUE sub sp, sp, ___esf_t_SIZEOF +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK + .if \el == el1 + /* + * EL1t mode cannot access sp_el1, so set x0 to sp_el1 without corrupt + * other registers + */ + add sp, sp, x0 // sp' = sp + x0 + sub x0, sp, x0 // x0' = sp' - x0 = sp + msr SPSel, #0 + stp x16, x17, [sp, -(___esf_t_SIZEOF - ___esf_t_x16_x17_OFFSET)] + stp x18, lr, [sp, -(___esf_t_SIZEOF - ___esf_t_x18_lr_OFFSET)] + bl z_arm64_quick_stack_check + .endif +#endif + stp x0, x1, [sp, ___esf_t_x0_x1_OFFSET] stp x2, x3, [sp, ___esf_t_x2_x3_OFFSET] stp x4, x5, [sp, ___esf_t_x4_x5_OFFSET] @@ -44,13 +62,32 @@ _ASM_FILE_PROLOGUE stp x10, x11, [sp, ___esf_t_x10_x11_OFFSET] stp x12, x13, [sp, ___esf_t_x12_x13_OFFSET] stp x14, x15, [sp, ___esf_t_x14_x15_OFFSET] +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK + /* The expection from el1 does not need to save x16, x17, x18 and lr */ + .if \el == el0 +#endif stp x16, x17, [sp, ___esf_t_x16_x17_OFFSET] stp x18, lr, [sp, ___esf_t_x18_lr_OFFSET] +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK + .endif +#endif mrs \xreg0, spsr_el1 mrs \xreg1, elr_el1 stp \xreg0, \xreg1, [sp, ___esf_t_spsr_elr_OFFSET] +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK + .if \el == el0 + mrs x0, sp_el0 + str x0, [sp, ___esf_t_sp_el0_OFFSET] + + /* Retrieving safe exception stack */ + get_cpu x0 + ldr x1, [x0, #_cpu_offset_to_safe_exception_stack] + msr sp_el0, x1 + .endif +#endif + /* Clear usermode flag and increment exception depth */ mrs \xreg0, tpidrro_el0 mov \xreg1, #TPIDRROEL0_EXC_UNIT @@ -204,6 +241,53 @@ SECTION_FUNC(TEXT, z_arm64_serror) /* Return here only in case of recoverable error */ b z_arm64_exit_exc +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK +GTEXT(z_arm64_quick_stack_check) +SECTION_FUNC(TEXT, z_arm64_quick_stack_check) + /* + * x0 is SP_EL1 + * Retrieve the current stack limit + */ + get_cpu x16 + ldr x17, [x16, #_cpu_offset_to_current_stack_limit] + /* + * If priv sp <= the stack limit, then keep the safe exception stack + * go to the stack overflow process. + */ + cmp x0, x17 + /* Restore the sp_el1 */ + msr SPSel, #1 // switch sp to sp_el1 + sub x0, sp, x0 // x0'' = sp' - x0' = x0 + sub sp, sp, x0 // sp'' = sp' - x0 = sp + ble 1f + /* + * If the stack does not overflow, keep using sp_el1, copy the original + * x16, x17, x18, lr from sp_el0 (safe_exception_stack) to sp_el1. So + * the four registers can be restroed directly from sp_el1 without a + * stack mode switch. + */ + mrs x18, sp_el0 + ldp x16, x17, [x18, -(___esf_t_SIZEOF - ___esf_t_x16_x17_OFFSET)] + stp x16, x17, [sp, ___esf_t_x16_x17_OFFSET] + ldp x16, x17, [x18, -(___esf_t_SIZEOF - ___esf_t_x18_lr_OFFSET)] + stp x16, x17, [sp, ___esf_t_x18_lr_OFFSET] + ret +1: /* + * If stack overflow, save the current sp and then switch sp to safe + * exception stack + * x16 is still the current _cpu + */ + mrs x18, sp_el0 + mov x17, sp + str x17, [x16, #_cpu_offset_to_corrupted_sp] + /* + * switch sp to safe exception stack, which means we handle the fatal + * error with safe exception stack. + */ + sub sp, x18, ___esf_t_SIZEOF + ret +#endif + /* * Restore volatile registers, LR, SPSR_EL1 and ELR_EL1 * @@ -233,6 +317,13 @@ SECTION_FUNC(TEXT, z_arm64_exit_exc) sub x0, x0, x1 msr tpidrro_el0, x0 +#ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK + bne 1f + ldr x0, [sp, ___esf_t_sp_el0_OFFSET] + msr sp_el0, x0 +1: +#endif + ldp x0, x1, [sp, ___esf_t_x0_x1_OFFSET] ldp x2, x3, [sp, ___esf_t_x2_x3_OFFSET] ldp x4, x5, [sp, ___esf_t_x4_x5_OFFSET] From e416c5f1bdcbd3669474cdc9f798f13cf69cdb6d Mon Sep 17 00:00:00 2001 From: Jaxson Han Date: Sat, 21 Jan 2023 00:00:23 +0800 Subject: [PATCH 0175/1906] arch: arm64: Update current stack limit on every context switch Update current stack limit on every context switch, including switching to irq stack and switching back to thread stack. Signed-off-by: Jaxson Han --- arch/arm64/core/isr_wrapper.S | 10 ++++++++++ arch/arm64/core/switch.S | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/arch/arm64/core/isr_wrapper.S b/arch/arm64/core/isr_wrapper.S index c12bf176f3e4..809762f27f96 100644 --- a/arch/arm64/core/isr_wrapper.S +++ b/arch/arm64/core/isr_wrapper.S @@ -44,6 +44,10 @@ SECTION_FUNC(TEXT, _isr_wrapper) mov x2, sp mov sp, x1 str x2, [sp, #-16]! +#if defined(CONFIG_ARM64_SAFE_EXCEPTION_STACK) + sub x1, x1, #CONFIG_ISR_STACK_SIZE + str x1, [x0, #_cpu_offset_to_current_stack_limit] +#endif 1: #ifdef CONFIG_SCHED_THREAD_USAGE bl z_sched_usage_stop @@ -123,6 +127,12 @@ z_arm64_irq_done: /* retrieve pointer to the current thread */ ldr x1, [x0, #___cpu_t_current_OFFSET] +#if defined(CONFIG_ARM64_SAFE_EXCEPTION_STACK) + /* arch_curr_cpu()->arch.current_stack_limit = thread->arch.stack_limit */ + ldr x2, [x1, #_thread_offset_to_stack_limit] + str x2, [x0, #_cpu_offset_to_current_stack_limit] +#endif + /* * Get next thread to schedule with z_get_next_switch_handle(). * We pass it a NULL as we didn't save the whole thread context yet. diff --git a/arch/arm64/core/switch.S b/arch/arm64/core/switch.S index 95c1a44aa47d..cb721cec9e9c 100644 --- a/arch/arm64/core/switch.S +++ b/arch/arm64/core/switch.S @@ -108,6 +108,13 @@ SECTION_FUNC(TEXT, z_arm64_context_switch) ldp x4, lr, [x0, #_thread_offset_to_callee_saved_sp_elx_lr] mov sp, x4 +#if defined(CONFIG_ARM64_SAFE_EXCEPTION_STACK) + /* arch_curr_cpu()->arch.current_stack_limit = thread->arch.stack_limit */ + get_cpu x4 + ldr x2, [x0, #_thread_offset_to_stack_limit] + str x2, [x4, #_cpu_offset_to_current_stack_limit] +#endif + #ifdef CONFIG_USERSPACE str lr, [sp, #-16]! bl z_arm64_swap_mem_domains @@ -184,6 +191,11 @@ offload: mov x4, sp mov sp, x3 str x4, [sp, #-16]! +#if defined(CONFIG_ARM64_SAFE_EXCEPTION_STACK) + /* update the stack limit with IRQ stack limit */ + sub x3, x3, #CONFIG_ISR_STACK_SIZE + str x3, [x2, #_cpu_offset_to_current_stack_limit] +#endif 1: /* Execute provided routine (argument is in x0 already). */ blr x1 From 43bd60a13ad84c91857f52d44d51957d1ba466c0 Mon Sep 17 00:00:00 2001 From: Ajay Parida Date: Mon, 20 Feb 2023 17:05:49 +0530 Subject: [PATCH 0176/1906] net: wifi_mgmt: Send TWT sleep status event to app Send TWT sleep status(sleep/awake) event to the apps registered for event. Signed-off-by: Ajay Parida --- include/zephyr/net/wifi_mgmt.h | 9 +++++++++ subsys/net/l2/wifi/wifi_mgmt.c | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 649d946f2f65..365788996a79 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -111,6 +111,7 @@ enum net_event_wifi_cmd { NET_EVENT_WIFI_CMD_DISCONNECT_RESULT, NET_EVENT_WIFI_CMD_IFACE_STATUS, NET_EVENT_WIFI_CMD_TWT, + NET_EVENT_WIFI_CMD_TWT_SLEEP_STATE, }; #define NET_EVENT_WIFI_SCAN_RESULT \ @@ -131,6 +132,8 @@ enum net_event_wifi_cmd { #define NET_EVENT_WIFI_TWT \ (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_TWT) +#define NET_EVENT_WIFI_TWT_SLEEP_STATE \ + (_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_TWT_SLEEP_STATE) /* Each result is provided to the net_mgmt_event_callback * via its info attribute (see net_mgmt.h) */ @@ -263,6 +266,11 @@ struct wifi_reg_domain { uint8_t country_code[WIFI_COUNTRY_CODE_LEN]; }; +enum wifi_twt_sleep_state { + WIFI_TWT_STATE_SLEEP = 0, + WIFI_TWT_STATE_AWAKE = 1, +}; + #include typedef void (*scan_result_cb_t)(struct net_if *iface, int status, @@ -316,6 +324,7 @@ void wifi_mgmt_raise_iface_status_event(struct net_if *iface, struct wifi_iface_status *iface_status); void wifi_mgmt_raise_twt_event(struct net_if *iface, struct wifi_twt_params *twt_params); +void wifi_mgmt_raise_twt_state(struct net_if *iface, int twt_sleep_state); #ifdef __cplusplus } #endif diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index 29b37bf4701e..7f92410f9175 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -335,3 +335,11 @@ static int wifi_set_power_save_timeout(uint32_t mgmt_request, struct net_if *ifa } NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PS_TIMEOUT, wifi_set_power_save_timeout); + +void wifi_mgmt_raise_twt_sleep_state(struct net_if *iface, + int twt_sleep_state) +{ + net_mgmt_event_notify_with_info(NET_EVENT_WIFI_TWT_SLEEP_STATE, + iface, INT_TO_POINTER(twt_sleep_state), + sizeof(twt_sleep_state)); +} From 4c4fcbe8dfbb3465df5f71e62910376319020841 Mon Sep 17 00:00:00 2001 From: Ole Saether Date: Thu, 9 Mar 2023 12:30:03 +0100 Subject: [PATCH 0177/1906] samples: bluetooth: BTHome sensor template A template for a sensor that uses the BTHome advertising format. Signed-off-by: Ole Saether --- .../bthome_sensor_template/CMakeLists.txt | 14 ++++ .../bthome_sensor_template/README.rst | 23 ++++++ .../bluetooth/bthome_sensor_template/prj.conf | 8 ++ .../bthome_sensor_template/src/main.c | 81 +++++++++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 samples/bluetooth/bthome_sensor_template/CMakeLists.txt create mode 100644 samples/bluetooth/bthome_sensor_template/README.rst create mode 100644 samples/bluetooth/bthome_sensor_template/prj.conf create mode 100644 samples/bluetooth/bthome_sensor_template/src/main.c diff --git a/samples/bluetooth/bthome_sensor_template/CMakeLists.txt b/samples/bluetooth/bthome_sensor_template/CMakeLists.txt new file mode 100644 index 000000000000..547a4a73d1a6 --- /dev/null +++ b/samples/bluetooth/bthome_sensor_template/CMakeLists.txt @@ -0,0 +1,14 @@ +# +# Copyright (c) 2023 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(bthome_sensor_template) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) + +target_include_directories(app PRIVATE include) diff --git a/samples/bluetooth/bthome_sensor_template/README.rst b/samples/bluetooth/bthome_sensor_template/README.rst new file mode 100644 index 000000000000..8b91fb432770 --- /dev/null +++ b/samples/bluetooth/bthome_sensor_template/README.rst @@ -0,0 +1,23 @@ +.. _bluetooth-bthome-sensor-template-sample: + +Bluetooth: BTHome sensor template +################################# + +Template for a `BTHome `_ sensor. + +Requirements +************ + +* A board with BLE support +* A BTHome compatible listener, for example `Home Assistant `_ with the BTHome integration running. + +Building and Running +******************** + +This sample can be found under :zephyr_file:`samples/bluetooth/bthome_sensor_template` in the Zephyr tree. + +See :ref:`bluetooth samples section ` for details. + +When the sample is running, navigate to Devices & Services under settings in Home +Assistant. There you will be asked to configure the BTHome sensor if everything +went well. diff --git a/samples/bluetooth/bthome_sensor_template/prj.conf b/samples/bluetooth/bthome_sensor_template/prj.conf new file mode 100644 index 000000000000..ed0ec7310b48 --- /dev/null +++ b/samples/bluetooth/bthome_sensor_template/prj.conf @@ -0,0 +1,8 @@ +# +# Copyright (c) 2023 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# +CONFIG_BT=y +CONFIG_BT_PERIPHERAL=y +CONFIG_BT_DEVICE_NAME="BTHome template" diff --git a/samples/bluetooth/bthome_sensor_template/src/main.c b/samples/bluetooth/bthome_sensor_template/src/main.c new file mode 100644 index 000000000000..77ccf1e78eb3 --- /dev/null +++ b/samples/bluetooth/bthome_sensor_template/src/main.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#define SERVICE_DATA_LEN 9 +#define SERVICE_UUID 0xfcd2 /* BTHome service UUID */ +#define IDX_TEMPL 4 /* Index of lo byte of temp in service data*/ +#define IDX_TEMPH 5 /* Index of hi byte of temp in service data*/ + +#define ADV_PARAM BT_LE_ADV_PARAM(BT_LE_ADV_OPT_USE_IDENTITY, \ + BT_GAP_ADV_SLOW_INT_MIN, \ + BT_GAP_ADV_SLOW_INT_MAX, NULL) + + +static uint8_t service_data[SERVICE_DATA_LEN] = { + BT_UUID_16_ENCODE(SERVICE_UUID), + 0x40, + 0x02, /* Temperature */ + 0xc4, /* Low byte */ + 0x00, /* High byte */ + 0x00, /* Humidity */ + 0xbf, /* 50.55% low byte*/ + 0x13, /* 50.55% high byte*/ +}; + +static struct bt_data ad[] = { + BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR), + BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), + BT_DATA(BT_DATA_SVC_DATA16, service_data, ARRAY_SIZE(service_data)) +}; + +static void bt_ready(int err) +{ + if (err) { + printk("Bluetooth init failed (err %d)\n", err); + return; + } + + printk("Bluetooth initialized\n"); + + /* Start advertising */ + err = bt_le_adv_start(ADV_PARAM, ad, ARRAY_SIZE(ad), NULL, 0); + if (err) { + printk("Advertising failed to start (err %d)\n", err); + return; + } +} + +void main(void) +{ + int err; + int temp = 0; + + printk("Starting BTHome sensor template\n"); + + /* Initialize the Bluetooth Subsystem */ + err = bt_enable(bt_ready); + if (err) { + printk("Bluetooth init failed (err %d)\n", err); + return; + } + + for (;;) { + /* Simulate temperature from 0C to 25C */ + service_data[IDX_TEMPH] = (temp * 100) >> 8; + service_data[IDX_TEMPL] = (temp * 100) & 0xff; + if (temp++ == 25) { + temp = 0; + } + err = bt_le_adv_update_data(ad, ARRAY_SIZE(ad), NULL, 0); + if (err) { + printk("Failed to update advertising data (err %d)\n", err); + } + k_sleep(K_MSEC(BT_GAP_ADV_SLOW_INT_MIN)); + } +} From 08720b0d2aa6671b42cfc389ccfd6e72719fd50b Mon Sep 17 00:00:00 2001 From: Marc Desvaux Date: Thu, 9 Mar 2023 14:14:43 +0100 Subject: [PATCH 0178/1906] dts: arm: st: nodes moved from .dts to .dtsi stm32l5x/u5x/g4x/l4x/g0x/wlx/wbx power-states node moved from .dts to .dtsi Signed-off-by: Marc Desvaux --- boards/arm/b_g474e_dpow1/b_g474e_dpow1.dts | 15 ------------- .../b_u585i_iot02a/b_u585i_iot02a-common.dtsi | 20 ------------------ .../arm/disco_l475_iot1/disco_l475_iot1.dts | 21 ------------------- boards/arm/nucleo_g070rb/nucleo_g070rb.dts | 14 ------------- boards/arm/nucleo_g071rb/nucleo_g071rb.dts | 14 ------------- boards/arm/nucleo_g0b1re/nucleo_g0b1re.dts | 15 ------------- boards/arm/nucleo_g474re/nucleo_g474re.dts | 15 ------------- boards/arm/nucleo_l476rg/nucleo_l476rg.dts | 21 ------------------- boards/arm/nucleo_wb55rg/nucleo_wb55rg.dts | 21 ------------------- boards/arm/nucleo_wl55jc/nucleo_wl55jc.dts | 21 ------------------- .../olimex_lora_stm32wl_devkit.dts | 21 ------------------- .../stm32l562e_dk/stm32l562e_dk_common.dtsi | 21 ------------------- dts/arm/st/g0/stm32g0.dtsi | 15 +++++++++++++ dts/arm/st/g4/stm32g4.dtsi | 15 +++++++++++++ dts/arm/st/l4/stm32l4.dtsi | 21 +++++++++++++++++++ dts/arm/st/l5/stm32l5.dtsi | 21 +++++++++++++++++++ dts/arm/st/u5/stm32u5.dtsi | 21 +++++++++++++++++++ dts/arm/st/wb/stm32wb.dtsi | 21 +++++++++++++++++++ dts/arm/st/wl/stm32wl.dtsi | 21 +++++++++++++++++++ 19 files changed, 135 insertions(+), 219 deletions(-) diff --git a/boards/arm/b_g474e_dpow1/b_g474e_dpow1.dts b/boards/arm/b_g474e_dpow1/b_g474e_dpow1.dts index a12eb527bc22..81bd492989b9 100644 --- a/boards/arm/b_g474e_dpow1/b_g474e_dpow1.dts +++ b/boards/arm/b_g474e_dpow1/b_g474e_dpow1.dts @@ -63,21 +63,6 @@ }; }; - power-states { - stop0: state0 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <1>; - min-residency-us = <20>; - }; - stop1: state1 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <2>; - min-residency-us = <100>; - }; - }; - cpus { cpu@0 { cpu-power-states = <&stop0 &stop1>; diff --git a/boards/arm/b_u585i_iot02a/b_u585i_iot02a-common.dtsi b/boards/arm/b_u585i_iot02a/b_u585i_iot02a-common.dtsi index 7cb9c1b717c7..564a26abf5e5 100644 --- a/boards/arm/b_u585i_iot02a/b_u585i_iot02a-common.dtsi +++ b/boards/arm/b_u585i_iot02a/b_u585i_iot02a-common.dtsi @@ -29,26 +29,6 @@ }; }; - power-states { - stop0: state0 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <1>; - min-residency-us = <100>; - }; - stop1: state1 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <2>; - min-residency-us = <500>; - }; - stop2: state2 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <3>; - min-residency-us = <900>; - }; - }; aliases { watchdog0 = &iwdg; diff --git a/boards/arm/disco_l475_iot1/disco_l475_iot1.dts b/boards/arm/disco_l475_iot1/disco_l475_iot1.dts index 753cfe6ee985..7f707ed20679 100644 --- a/boards/arm/disco_l475_iot1/disco_l475_iot1.dts +++ b/boards/arm/disco_l475_iot1/disco_l475_iot1.dts @@ -42,27 +42,6 @@ }; }; - power-states { - stop0: state0 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <1>; - min-residency-us = <500>; - }; - stop1: state1 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <2>; - min-residency-us = <700>; - }; - stop2: state2 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <3>; - min-residency-us = <1000>; - }; - }; - pwmleds: pwmleds { compatible = "pwm-leds"; status = "disabled"; diff --git a/boards/arm/nucleo_g070rb/nucleo_g070rb.dts b/boards/arm/nucleo_g070rb/nucleo_g070rb.dts index 84376938e7a4..770a18f4768f 100644 --- a/boards/arm/nucleo_g070rb/nucleo_g070rb.dts +++ b/boards/arm/nucleo_g070rb/nucleo_g070rb.dts @@ -20,20 +20,6 @@ zephyr,flash = &flash0; }; - power-states { - stop0: state0 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <1>; - min-residency-us = <20>; - }; - stop1: state1 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <2>; - min-residency-us = <100>; - }; - }; leds { compatible = "gpio-leds"; diff --git a/boards/arm/nucleo_g071rb/nucleo_g071rb.dts b/boards/arm/nucleo_g071rb/nucleo_g071rb.dts index 35da009f22d3..d81103efd9e8 100644 --- a/boards/arm/nucleo_g071rb/nucleo_g071rb.dts +++ b/boards/arm/nucleo_g071rb/nucleo_g071rb.dts @@ -21,20 +21,6 @@ zephyr,flash = &flash0; }; - power-states { - stop0: state0 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <1>; - min-residency-us = <20>; - }; - stop1: state1 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <2>; - min-residency-us = <100>; - }; - }; leds { compatible = "gpio-leds"; diff --git a/boards/arm/nucleo_g0b1re/nucleo_g0b1re.dts b/boards/arm/nucleo_g0b1re/nucleo_g0b1re.dts index 1880653b4ff8..bae0ad7bee7b 100644 --- a/boards/arm/nucleo_g0b1re/nucleo_g0b1re.dts +++ b/boards/arm/nucleo_g0b1re/nucleo_g0b1re.dts @@ -23,21 +23,6 @@ zephyr,canbus = &can1; }; - power-states { - stop0: state0 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <1>; - min-residency-us = <20>; - }; - stop1: state1 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <2>; - min-residency-us = <100>; - }; - }; - leds { compatible = "gpio-leds"; green_led_1: led_4 { diff --git a/boards/arm/nucleo_g474re/nucleo_g474re.dts b/boards/arm/nucleo_g474re/nucleo_g474re.dts index 819bc1cf46a1..adca78fe5de8 100644 --- a/boards/arm/nucleo_g474re/nucleo_g474re.dts +++ b/boards/arm/nucleo_g474re/nucleo_g474re.dts @@ -45,21 +45,6 @@ }; }; - power-states { - stop0: state0 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <1>; - min-residency-us = <20>; - }; - stop1: state1 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <2>; - min-residency-us = <100>; - }; - }; - cpus { cpu@0 { cpu-power-states = <&stop0 &stop1>; diff --git a/boards/arm/nucleo_l476rg/nucleo_l476rg.dts b/boards/arm/nucleo_l476rg/nucleo_l476rg.dts index b77274b7b590..eaa5f54b9cde 100644 --- a/boards/arm/nucleo_l476rg/nucleo_l476rg.dts +++ b/boards/arm/nucleo_l476rg/nucleo_l476rg.dts @@ -20,27 +20,6 @@ zephyr,flash = &flash0; }; - power-states { - stop0: state0 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <1>; - min-residency-us = <500>; - }; - stop1: state1 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <2>; - min-residency-us = <700>; - }; - stop2: state2 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <3>; - min-residency-us = <1000>; - }; - }; - leds { compatible = "gpio-leds"; green_led_2: led_2 { diff --git a/boards/arm/nucleo_wb55rg/nucleo_wb55rg.dts b/boards/arm/nucleo_wb55rg/nucleo_wb55rg.dts index e6972cd6ee35..900e8a2d8032 100644 --- a/boards/arm/nucleo_wb55rg/nucleo_wb55rg.dts +++ b/boards/arm/nucleo_wb55rg/nucleo_wb55rg.dts @@ -23,27 +23,6 @@ zephyr,code-partition = &slot0_partition; }; - power-states { - stop0: state0 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <1>; - min-residency-us = <100>; - }; - stop1: state1 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <2>; - min-residency-us = <500>; - }; - stop2: state2 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <3>; - min-residency-us = <900>; - }; - }; - leds { compatible = "gpio-leds"; blue_led_1: led_0 { diff --git a/boards/arm/nucleo_wl55jc/nucleo_wl55jc.dts b/boards/arm/nucleo_wl55jc/nucleo_wl55jc.dts index 06d6a4d0c274..38fd036dd1d1 100644 --- a/boards/arm/nucleo_wl55jc/nucleo_wl55jc.dts +++ b/boards/arm/nucleo_wl55jc/nucleo_wl55jc.dts @@ -61,27 +61,6 @@ lora0 = &lora; watchdog0 = &iwdg; }; - - power-states { - stop0: state0 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <1>; - min-residency-us = <100>; - }; - stop1: state1 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <2>; - min-residency-us = <500>; - }; - stop2: state2 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <3>; - min-residency-us = <900>; - }; - }; }; &cpu0 { diff --git a/boards/arm/olimex_lora_stm32wl_devkit/olimex_lora_stm32wl_devkit.dts b/boards/arm/olimex_lora_stm32wl_devkit/olimex_lora_stm32wl_devkit.dts index 34b7edf937d2..aac34f420e7d 100644 --- a/boards/arm/olimex_lora_stm32wl_devkit/olimex_lora_stm32wl_devkit.dts +++ b/boards/arm/olimex_lora_stm32wl_devkit/olimex_lora_stm32wl_devkit.dts @@ -41,27 +41,6 @@ lora0 = &lora; watchdog0 = &iwdg; }; - - power-states { - stop0: state0 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <1>; - min-residency-us = <100>; - }; - stop1: state1 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <2>; - min-residency-us = <500>; - }; - stop2: state2 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <3>; - min-residency-us = <900>; - }; - }; }; &cpu0 { diff --git a/boards/arm/stm32l562e_dk/stm32l562e_dk_common.dtsi b/boards/arm/stm32l562e_dk/stm32l562e_dk_common.dtsi index 607814c421e3..745cea0d7761 100644 --- a/boards/arm/stm32l562e_dk/stm32l562e_dk_common.dtsi +++ b/boards/arm/stm32l562e_dk/stm32l562e_dk_common.dtsi @@ -29,27 +29,6 @@ }; }; - power-states { - stop0: state0 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <1>; - min-residency-us = <100>; - }; - stop1: state1 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <2>; - min-residency-us = <500>; - }; - stop2: state2 { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <3>; - min-residency-us = <900>; - }; - }; - aliases { spi-flash0 = &mx25lm51245; }; diff --git a/dts/arm/st/g0/stm32g0.dtsi b/dts/arm/st/g0/stm32g0.dtsi index 2d41059c3b2d..8e930eb15cef 100644 --- a/dts/arm/st/g0/stm32g0.dtsi +++ b/dts/arm/st/g0/stm32g0.dtsi @@ -76,6 +76,21 @@ }; }; + power-states { + stop0: state0 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <1>; + min-residency-us = <20>; + }; + stop1: state1 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <2>; + min-residency-us = <100>; + }; + }; + soc { flash: flash-controller@40022000 { compatible = "st,stm32-flash-controller", "st,stm32g0-flash-controller"; diff --git a/dts/arm/st/g4/stm32g4.dtsi b/dts/arm/st/g4/stm32g4.dtsi index 7ad7b7d1d4ae..463e3a8f158a 100644 --- a/dts/arm/st/g4/stm32g4.dtsi +++ b/dts/arm/st/g4/stm32g4.dtsi @@ -80,6 +80,21 @@ }; }; + power-states { + stop0: state0 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <1>; + min-residency-us = <20>; + }; + stop1: state1 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <2>; + min-residency-us = <100>; + }; + }; + soc { /* * Both adc instances cannot be used in parallel right now. diff --git a/dts/arm/st/l4/stm32l4.dtsi b/dts/arm/st/l4/stm32l4.dtsi index c6c84e53ebb0..bffa12ddb8a0 100644 --- a/dts/arm/st/l4/stm32l4.dtsi +++ b/dts/arm/st/l4/stm32l4.dtsi @@ -81,6 +81,27 @@ }; }; + power-states { + stop0: state0 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <1>; + min-residency-us = <500>; + }; + stop1: state1 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <2>; + min-residency-us = <700>; + }; + stop2: state2 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <3>; + min-residency-us = <1000>; + }; + }; + soc { flash: flash-controller@40022000 { compatible = "st,stm32-flash-controller", "st,stm32l4-flash-controller"; diff --git a/dts/arm/st/l5/stm32l5.dtsi b/dts/arm/st/l5/stm32l5.dtsi index 00135c7353f8..3f7deca28a30 100644 --- a/dts/arm/st/l5/stm32l5.dtsi +++ b/dts/arm/st/l5/stm32l5.dtsi @@ -97,6 +97,27 @@ }; }; + power-states { + stop0: state0 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <1>; + min-residency-us = <100>; + }; + stop1: state1 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <2>; + min-residency-us = <500>; + }; + stop2: state2 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <3>; + min-residency-us = <900>; + }; + }; + soc { flash: flash-controller@40022000 { compatible = "st,stm32-flash-controller", "st,stm32l5-flash-controller"; diff --git a/dts/arm/st/u5/stm32u5.dtsi b/dts/arm/st/u5/stm32u5.dtsi index 19ae19824ccd..790e3864bff4 100644 --- a/dts/arm/st/u5/stm32u5.dtsi +++ b/dts/arm/st/u5/stm32u5.dtsi @@ -114,6 +114,27 @@ }; }; + power-states { + stop0: state0 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <1>; + min-residency-us = <100>; + }; + stop1: state1 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <2>; + min-residency-us = <500>; + }; + stop2: state2 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <3>; + min-residency-us = <900>; + }; + }; + soc { flash: flash-controller@40022000 { compatible = "st,stm32-flash-controller", "st,stm32l5-flash-controller"; diff --git a/dts/arm/st/wb/stm32wb.dtsi b/dts/arm/st/wb/stm32wb.dtsi index 8198c64bb361..2f7083905425 100644 --- a/dts/arm/st/wb/stm32wb.dtsi +++ b/dts/arm/st/wb/stm32wb.dtsi @@ -114,6 +114,27 @@ }; }; + power-states { + stop0: state0 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <1>; + min-residency-us = <100>; + }; + stop1: state1 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <2>; + min-residency-us = <500>; + }; + stop2: state2 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <3>; + min-residency-us = <900>; + }; + }; + soc { flash: flash-controller@58004000 { compatible = "st,stm32-flash-controller", "st,stm32wb-flash-controller"; diff --git a/dts/arm/st/wl/stm32wl.dtsi b/dts/arm/st/wl/stm32wl.dtsi index 7b65fde63afa..b669c00d08f1 100644 --- a/dts/arm/st/wl/stm32wl.dtsi +++ b/dts/arm/st/wl/stm32wl.dtsi @@ -82,6 +82,27 @@ }; }; + power-states { + stop0: state0 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <1>; + min-residency-us = <100>; + }; + stop1: state1 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <2>; + min-residency-us = <500>; + }; + stop2: state2 { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + substate-id = <3>; + min-residency-us = <900>; + }; + }; + soc { flash: flash-controller@58004000 { compatible = "st,stm32-flash-controller", "st,stm32l4-flash-controller"; From 545ecbb947aafc98d264cbe6f8c4157f423c50fa Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Thu, 26 Jan 2023 11:34:10 +0200 Subject: [PATCH 0179/1906] tests: bluetooth: Correct unsigned compare (unsigned - unsigned) is always >= 0, so I believe the right compare string is (unsigned > unsigned), otherwise we would check for (is equal). Signed-off-by: Andrei Emeltchenko --- .../ctrl_isoal/src/sub_sets/isoal_test_rx.c | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c index ec6dce98ee69..fc4bb6af67a4 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_rx.c @@ -5604,7 +5604,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[1] = seqn[0] + 1; @@ -5846,7 +5846,7 @@ ZTEST(test_rx_framed, test_rx_framed_zero_length_sdu) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[1] = seqn[0] + 1; @@ -5858,7 +5858,7 @@ ZTEST(test_rx_framed, test_rx_framed_zero_length_sdu) (testdata_size - testdata_indx), sdu_timeoffset, &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[2] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[2] = seqn[1] + 1; @@ -6153,7 +6153,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_padding) payload_number++; - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; @@ -6331,7 +6331,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err1) payload_number++; - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; @@ -6511,7 +6511,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_pdu_err2) payload_number++; - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; @@ -6873,7 +6873,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1) payload_number++; - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); /* ISO-AL has no concept of time and is unable to detect than an SDU @@ -6889,7 +6889,7 @@ ZTEST(test_rx_framed, test_rx_framed_dbl_pdu_dbl_sdu_seq_err1) payload_number++; - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; @@ -7127,7 +7127,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err1) payload_number++; - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; @@ -7371,7 +7371,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err2) payload_number++; - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; @@ -7623,7 +7623,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_err3) payload_number++; - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; @@ -7846,7 +7846,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_seq_err1) payload_number++; - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; @@ -8069,7 +8069,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_single_sdu_pdu_seq_err1) payload_number++; - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn++; @@ -8257,7 +8257,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[1] = seqn[0] + 1; @@ -8361,7 +8361,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err1) payload_number++; pdu_timestamp = 9249 + (iso_interval_int * CONN_INT_UNIT_US); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[0] = seqn[1] + 1; @@ -8544,7 +8544,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[1] = seqn[0]; @@ -8631,7 +8631,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err2) payload_number++; pdu_timestamp = 9249 + (iso_interval_int * CONN_INT_UNIT_US); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[0] = seqn[1] + 1; @@ -8810,7 +8810,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[1] = seqn[0] + 1; @@ -8929,7 +8929,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_err3) payload_number++; pdu_timestamp = 9249 + (iso_interval_int * CONN_INT_UNIT_US); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[0] = seqn[1] + 1; @@ -9102,7 +9102,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) testdata_size += 10; /* No change in SDU 1 size */ - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); /* ISO-AL has no concept of time and is unable to detect than an SDU @@ -9170,7 +9170,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seq_err1) payload_number++; pdu_timestamp = 9249 + (iso_interval_int * CONN_INT_UNIT_US); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[0] = seqn[1] + 1; @@ -9344,7 +9344,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) testdata_size += 10; /* No change in SDU 1 size */ - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); /* ISO-AL has no concept of time and is unable to detect than an SDU @@ -9412,7 +9412,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_pdu_seq_err1) payload_number++; pdu_timestamp = 9249 + (iso_interval_int * CONN_INT_UNIT_US); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[0] = seqn[1] + 1; @@ -9931,7 +9931,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err1) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[1] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[1] = seqn[0] + 1; @@ -10160,7 +10160,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) (testdata_size - testdata_indx), &rx_pdu_meta_buf.pdu_meta); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[1] = sdu_timestamp[0] + sdu_interval; seqn[1] = seqn[0] + 1; @@ -10276,7 +10276,7 @@ ZTEST(test_rx_framed, test_rx_framed_trppl_pdu_dbl_sdu_seg_err2) payload_number++; pdu_timestamp = 9249 + (iso_interval_int * CONN_INT_UNIT_US); - sdu_timeoffset = sdu_timeoffset - sdu_interval > 0 ? sdu_timeoffset - sdu_interval : + sdu_timeoffset = sdu_timeoffset > sdu_interval ? sdu_timeoffset - sdu_interval : sdu_timeoffset + (iso_interval_int * CONN_INT_UNIT_US) - sdu_interval; sdu_timestamp[0] = (uint32_t)((int64_t)pdu_timestamp + latency - sdu_timeoffset); seqn[0] = seqn[1] + 1; From 0a1655828933ef837a2f384a948211938aa70256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katarzyna=20Gi=C4=85d=C5=82a?= Date: Mon, 13 Mar 2023 11:40:37 +0100 Subject: [PATCH 0180/1906] tests: drivers: uart: uart_pm: Unify set of pins on nrf52840dk_nrf52840 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unify set of the pins on `nrf52840dk_nrf52840`, which is used by `gpio_loopback` fixture. Signed-off-by: Katarzyna Giądła --- .../uart/uart_pm/boards/nrf52840dk_nrf52840.overlay | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/drivers/uart/uart_pm/boards/nrf52840dk_nrf52840.overlay b/tests/drivers/uart/uart_pm/boards/nrf52840dk_nrf52840.overlay index ddcd6ce0776d..86f2ea169cd5 100644 --- a/tests/drivers/uart/uart_pm/boards/nrf52840dk_nrf52840.overlay +++ b/tests/drivers/uart/uart_pm/boards/nrf52840dk_nrf52840.overlay @@ -20,8 +20,8 @@ group1 { psels = , , - , - ; + , + ; }; }; @@ -29,8 +29,8 @@ group1 { psels = , , - , - ; + , + ; low-power-enable; }; }; From c530eca285d482b1e25668e5ed8781753a66469b Mon Sep 17 00:00:00 2001 From: Lucas Tamborrino Date: Mon, 27 Feb 2023 16:44:21 -0300 Subject: [PATCH 0181/1906] dts: esp32s3: Add timers support Add timer support for esp32s3 Signed-off-by: Lucas Tamborrino --- boards/xtensa/esp32s3_devkitm/doc/index.rst | 4 ++ .../esp32s3_devkitm/esp32s3_devkitm.dts | 16 ++++++++ .../esp32s3_devkitm/esp32s3_devkitm.yaml | 1 + dts/xtensa/espressif/esp32s3.dtsi | 40 +++++++++++++++++++ 4 files changed, 61 insertions(+) diff --git a/boards/xtensa/esp32s3_devkitm/doc/index.rst b/boards/xtensa/esp32s3_devkitm/doc/index.rst index 5d41114d16ca..0bcb0fb802fa 100644 --- a/boards/xtensa/esp32s3_devkitm/doc/index.rst +++ b/boards/xtensa/esp32s3_devkitm/doc/index.rst @@ -90,6 +90,10 @@ Current Zephyr's ESP32-S3-DevKitM board supports the following features: +------------+------------+-------------------------------------+ | USB-JTAG | on-chip | hardware interface | +------------+------------+-------------------------------------+ +| SPI Master | on-chip | spi | ++------------+------------+-------------------------------------+ +| Timers | on-chip | counter | ++------------+------------+-------------------------------------+ Prerequisites ------------- diff --git a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts index 10f2b5aa46a8..8c3c4fcc5f74 100644 --- a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts +++ b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts @@ -88,6 +88,22 @@ pinctrl-names = "default"; }; +&timer0 { + status = "disabled"; +}; + +&timer1 { + status = "disabled"; +}; + +&timer2 { + status = "disabled"; +}; + +&timer3 { + status = "disabled"; +}; + &flash0 { status = "okay"; partitions { diff --git a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml index 96c8ff0db125..e290263c3b89 100644 --- a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml +++ b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml @@ -9,6 +9,7 @@ supported: - uart - i2c - spi + - counter testing: ignore_tags: - net diff --git a/dts/xtensa/espressif/esp32s3.dtsi b/dts/xtensa/espressif/esp32s3.dtsi index f784ad28f5c8..6500f2ffce39 100644 --- a/dts/xtensa/espressif/esp32s3.dtsi +++ b/dts/xtensa/espressif/esp32s3.dtsi @@ -194,5 +194,45 @@ dma-host = <1>; status = "disabled"; }; + + timer0: counter@6001f000 { + compatible = "espressif,esp32-timer"; + reg = <0x6001f000 DT_SIZE_K(4)>; + group = <0>; + index = <0>; + interrupts = ; + interrupt-parent = <&intc>; + status = "disabled"; + }; + + timer1: counter@6001f024 { + compatible = "espressif,esp32-timer"; + reg = <0x6001f024 DT_SIZE_K(4)>; + group = <0>; + index = <1>; + interrupts = ; + interrupt-parent = <&intc>; + status = "disabled"; + }; + + timer2: counter@60020000 { + compatible = "espressif,esp32-timer"; + reg = <0x60020000 DT_SIZE_K(4)>; + group = <1>; + index = <0>; + interrupts = ; + interrupt-parent = <&intc>; + status = "disabled"; + }; + + timer3: counter@60020024 { + compatible = "espressif,esp32-timer"; + reg = <0x60020024 DT_SIZE_K(4)>; + group = <1>; + index = <1>; + interrupts = ; + interrupt-parent = <&intc>; + }; + }; }; From 81aaaa9f72ba01ef5ebdf706f4356dd34f9dcd43 Mon Sep 17 00:00:00 2001 From: Lucas Tamborrino Date: Mon, 27 Feb 2023 16:44:22 -0300 Subject: [PATCH 0182/1906] samples: drivers: counter: add esp32s3 overlay Add esp32s3 overlay to counter sample Signed-off-by: Lucas Tamborrino --- samples/drivers/counter/alarm/boards/esp32s3_devkitm.overlay | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 samples/drivers/counter/alarm/boards/esp32s3_devkitm.overlay diff --git a/samples/drivers/counter/alarm/boards/esp32s3_devkitm.overlay b/samples/drivers/counter/alarm/boards/esp32s3_devkitm.overlay new file mode 100644 index 000000000000..241947b06437 --- /dev/null +++ b/samples/drivers/counter/alarm/boards/esp32s3_devkitm.overlay @@ -0,0 +1,3 @@ +&timer0 { + status = "okay"; +}; From cf3b2643376e0f92a9b5cc38513a586567abe69c Mon Sep 17 00:00:00 2001 From: Lucas Tamborrino Date: Mon, 27 Feb 2023 16:44:22 -0300 Subject: [PATCH 0183/1906] tests: driver: counter: Add esp32s3 to basic api test Add esp32s3 to counter basic api testing Signed-off-by: Lucas Tamborrino --- tests/drivers/counter/counter_basic_api/boards/esp32.conf | 1 - .../counter/counter_basic_api/boards/esp32c3_devkitm.overlay | 3 +++ .../counter/counter_basic_api/boards/esp32s2_saola.overlay | 3 +++ .../counter/counter_basic_api/boards/esp32s3_devkitm.overlay | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) delete mode 100644 tests/drivers/counter/counter_basic_api/boards/esp32.conf create mode 100644 tests/drivers/counter/counter_basic_api/boards/esp32c3_devkitm.overlay create mode 100644 tests/drivers/counter/counter_basic_api/boards/esp32s2_saola.overlay create mode 100644 tests/drivers/counter/counter_basic_api/boards/esp32s3_devkitm.overlay diff --git a/tests/drivers/counter/counter_basic_api/boards/esp32.conf b/tests/drivers/counter/counter_basic_api/boards/esp32.conf deleted file mode 100644 index bb1f1de1e69e..000000000000 --- a/tests/drivers/counter/counter_basic_api/boards/esp32.conf +++ /dev/null @@ -1 +0,0 @@ -CONFIG_COUNTER_TMR_ESP32=y diff --git a/tests/drivers/counter/counter_basic_api/boards/esp32c3_devkitm.overlay b/tests/drivers/counter/counter_basic_api/boards/esp32c3_devkitm.overlay new file mode 100644 index 000000000000..241947b06437 --- /dev/null +++ b/tests/drivers/counter/counter_basic_api/boards/esp32c3_devkitm.overlay @@ -0,0 +1,3 @@ +&timer0 { + status = "okay"; +}; diff --git a/tests/drivers/counter/counter_basic_api/boards/esp32s2_saola.overlay b/tests/drivers/counter/counter_basic_api/boards/esp32s2_saola.overlay new file mode 100644 index 000000000000..241947b06437 --- /dev/null +++ b/tests/drivers/counter/counter_basic_api/boards/esp32s2_saola.overlay @@ -0,0 +1,3 @@ +&timer0 { + status = "okay"; +}; diff --git a/tests/drivers/counter/counter_basic_api/boards/esp32s3_devkitm.overlay b/tests/drivers/counter/counter_basic_api/boards/esp32s3_devkitm.overlay new file mode 100644 index 000000000000..2b3ef4f24cae --- /dev/null +++ b/tests/drivers/counter/counter_basic_api/boards/esp32s3_devkitm.overlay @@ -0,0 +1,3 @@ +&timer3 { + status = "okay"; +}; From 2a76e05d0cfeda5375a99354c6d8094eb2e15f13 Mon Sep 17 00:00:00 2001 From: Alperen Sener Date: Mon, 13 Mar 2023 15:57:29 +0100 Subject: [PATCH 0184/1906] Bluetooth: Tester: fixing mesh btp cmds fix mesh btp command structs for btp commands cfg_model_sub_ovw and cfg_model_app_get Signed-off-by: Alperen Sener --- tests/bluetooth/tester/src/btp/btp_mesh.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 8cc679ea8052..5aa191d7d7b8 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -391,7 +391,6 @@ struct btp_mesh_cfg_model_app_get_cmd { uint16_t address; uint16_t elem_address; uint16_t mod_id; - uint16_t cid; } __packed; struct btp_mesh_cfg_model_app_get_rp { uint8_t status; @@ -478,6 +477,7 @@ struct btp_mesh_cfg_model_sub_ovw_cmd { uint16_t net_idx; uint16_t address; uint16_t elem_address; + uint16_t sub_addr; uint16_t model_id; } __packed; struct btp_mesh_cfg_model_sub_ovw_rp { From 8a85f0e87f40e78f8533d18c1706af0be80fb313 Mon Sep 17 00:00:00 2001 From: Patryk Duda Date: Thu, 10 Nov 2022 14:38:47 +0100 Subject: [PATCH 0185/1906] drivers: flash: Introduce API function for flash extended operations Besides of standard flash operations like write or erase, flash controllers also support additional features like write protection or readout protection. These features are not available in every flash controller, what's more controllers can implement it in a different way. It doesn't make sense to add a separate flash API function for every flash controller feature, because it could be unique (supported on small number of flash controllers) or the API won't be able to represent the same feature on every flash controller. Extended operation interface provides flexible way for supporting flash controller features. Code space is divided equally into Zephyr codes (MSb == 0) and vendor codes (MSb == 1). This way we can easily add extended operations to the drivers without cluttering the API or problems with API incompatibility. Extended operation can be promoted from vendor codes to Zephyr codes if the feature is available in most flash controllers and can be represented in the same way. Signed-off-by: Patryk Duda --- drivers/flash/Kconfig | 14 ++++++++ drivers/flash/flash_handlers.c | 19 ++++++++++ include/zephyr/drivers/flash.h | 66 ++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/drivers/flash/Kconfig b/drivers/flash/Kconfig index 39d57ebc188e..bf6fa61c4344 100644 --- a/drivers/flash/Kconfig +++ b/drivers/flash/Kconfig @@ -11,6 +11,12 @@ config FLASH_HAS_DRIVER_ENABLED help This option is enabled when any flash driver is enabled. +config FLASH_HAS_EX_OP + bool + help + This option is selected by drivers that support flash extended + operations. + config FLASH_HAS_PAGE_LAYOUT bool help @@ -78,6 +84,14 @@ config FLASH_PAGE_LAYOUT help Enables API for retrieving the layout of flash memory pages. +config FLASH_EX_OP_ENABLED + bool "API for extended flash operations" + depends on FLASH_HAS_EX_OP + default n + help + Enables flash extended operations API. It can be used to perform + non-standard operations e.g. manipulating flash protection. + config FLASH_INIT_PRIORITY int "Flash init priority" default KERNEL_INIT_PRIORITY_DEVICE diff --git a/drivers/flash/flash_handlers.c b/drivers/flash/flash_handlers.c index 6ffb6c7fe429..b83a739a5d4b 100644 --- a/drivers/flash/flash_handlers.c +++ b/drivers/flash/flash_handlers.c @@ -98,3 +98,22 @@ static inline int z_vrfy_flash_read_jedec_id(const struct device *dev, #include #endif /* CONFIG_FLASH_JESD216_API */ + +#ifdef CONFIG_FLASH_EX_OP_ENABLED + +static inline int z_vrfy_flash_ex_op(const struct device *dev, uint16_t code, + const uintptr_t in, void *out) +{ + Z_OOPS(Z_SYSCALL_DRIVER_FLASH(dev, ex_op)); + + /* + * If the code is a vendor code, then ex_op function have to perform + * verification. Zephyr codes should be verified here, but currently + * there are no Zephyr extended codes yet. + */ + + return z_impl_flash_ex_op(dev, code, in, out); +} +#include + +#endif /* CONFIG_FLASH_EX_OP_ENABLED */ diff --git a/include/zephyr/drivers/flash.h b/include/zephyr/drivers/flash.h index d1d56bdd456d..df2402c1a860 100644 --- a/include/zephyr/drivers/flash.h +++ b/include/zephyr/drivers/flash.h @@ -125,6 +125,8 @@ typedef void (*flash_api_pages_layout)(const struct device *dev, typedef int (*flash_api_sfdp_read)(const struct device *dev, off_t offset, void *data, size_t len); typedef int (*flash_api_read_jedec_id)(const struct device *dev, uint8_t *id); +typedef int (*flash_api_ex_op)(const struct device *dev, uint16_t code, + const uintptr_t in, void *out); __subsystem struct flash_driver_api { flash_api_read read; @@ -138,6 +140,9 @@ __subsystem struct flash_driver_api { flash_api_sfdp_read sfdp_read; flash_api_read_jedec_id read_jedec_id; #endif /* CONFIG_FLASH_JESD216_API */ +#if defined(CONFIG_FLASH_EX_OP_ENABLED) + flash_api_ex_op ex_op; +#endif /* CONFIG_FLASH_EX_OP_ENABLED */ }; /** @@ -422,6 +427,67 @@ static inline const struct flash_parameters *z_impl_flash_get_parameters(const s return api->get_parameters(dev); } +/** + * @brief Execute flash extended operation on given device + * + * Besides of standard flash operations like write or erase, flash controllers + * also support additional features like write protection or readout + * protection. These features are not available in every flash controller, + * what's more controllers can implement it in a different way. + * + * It doesn't make sense to add a separate flash API function for every flash + * controller feature, because it could be unique (supported on small number of + * flash controllers) or the API won't be able to represent the same feature on + * every flash controller. + * + * @param dev Flash device + * @param code Operation which will be executed on the device. + * @param in Pointer to input data used by operation. If operation doesn't + * need any input data it could be NULL. + * @param out Pointer to operation output data. If operation doesn't produce + * any output it could be NULL. + * + * @retval 0 on success. + * @retval -ENOTSUP if given device doesn't support extended operation. + * @retval -ENOSYS if support for extended operations is not enabled in Kconfig + * @retval negative value on extended operation errors. + */ +__syscall int flash_ex_op(const struct device *dev, uint16_t code, + const uintptr_t in, void *out); + +/* + * Extended operation interface provides flexible way for supporting flash + * controller features. Code space is divided equally into Zephyr codes + * (MSb == 0) and vendor codes (MSb == 1). This way we can easily add extended + * operations to the drivers without cluttering the API or problems with API + * incompatibility. Extended operation can be promoted from vendor codes to + * Zephyr codes if the feature is available in most flash controllers and + * can be represented in the same way. + * + * It's not forbidden to have operation in Zephyr codes and vendor codes for + * the same functionality. In this case, vendor operation could provide more + * specific access when abstraction in Zephyr counterpart is insufficient. + */ +#define FLASH_EX_OP_VENDOR_BASE 0x8000 +#define FLASH_EX_OP_IS_VENDOR(c) ((c) & FLASH_EX_OP_VENDOR_BASE) + +static inline int z_impl_flash_ex_op(const struct device *dev, uint16_t code, + const uintptr_t in, void *out) +{ +#if defined(CONFIG_FLASH_EX_OP_ENABLED) + const struct flash_driver_api *api = + (const struct flash_driver_api *)dev->api; + + if (api->ex_op == NULL) { + return -ENOTSUP; + } + + return api->ex_op(dev, code, in, out); +#else + return -ENOSYS; +#endif /* CONFIG_FLASH_EX_OP_ENABLED */ +} + #ifdef __cplusplus } #endif From 73d0118c06adc7a12f2dec8830c91bb540cc418d Mon Sep 17 00:00:00 2001 From: Patryk Duda Date: Mon, 13 Mar 2023 14:35:07 +0100 Subject: [PATCH 0186/1906] doc: release-notes: Update release notes 3.4 Add information about Flash API changes. Signed-off-by: Patryk Duda --- doc/releases/release-notes-3.4.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/releases/release-notes-3.4.rst b/doc/releases/release-notes-3.4.rst index a420828dc2f9..4692a23f1c6a 100644 --- a/doc/releases/release-notes-3.4.rst +++ b/doc/releases/release-notes-3.4.rst @@ -116,6 +116,12 @@ Stable API changes in this release New APIs in this release ======================== +* Introduced :c:func:`flash_ex_op` function. This allows to perform extra + operations on flash devices, defined by Zephyr Flash API or by vendor specific + header files. Support for extra operations is enabled by + :kconfig:option:`CONFIG_FLASH_EX_OP_ENABLED` which depends on + :kconfig:option:`CONFIG_FLASH_HAS_EX_OP` selected by driver. + Kernel ****** @@ -250,6 +256,14 @@ Drivers and Sensors * Flash + * Introduced new flash API call :c:func:`flash_ex_op` which calls + :c:func:`ec_op` callback provided by a flash driver. This allows to perform + extra operations on flash devices, defined by Zephyr Flash API or by vendor + specific header files. :kconfig:option:`CONFIG_FLASH_HAS_EX_OP` should be + selected by the driver to indicate that extra operations are supported. + To enable extra operations user should select + :kconfig:option:`CONFIG_FLASH_EX_OP_ENABLED`. + * FPGA * Fuel Gauge From 8aec9dd552bf0c09e07e07a34227af60a9cbfdda Mon Sep 17 00:00:00 2001 From: Armin Brauns Date: Tue, 24 Jan 2023 09:53:56 +0100 Subject: [PATCH 0187/1906] drivers/fpga: ice40: fix minimum config delay MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From FPGA-TN-02001-3.3 "iCE40 Programming and Configuration": > After driving CRESET_B High or allowing it to float High, the AP must > wait a minimum of 1200 µs, allowing the iCE40 FPGA to clear its internal > configuration memory. Signed-off-by: Armin Brauns --- drivers/fpga/fpga_ice40.c | 2 +- dts/bindings/fpga/lattice,ice40-fpga.yaml | 2 +- tests/drivers/build_all/fpga/spi.dtsi | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/fpga/fpga_ice40.c b/drivers/fpga/fpga_ice40.c index 26d98ef20cac..9d0808a2b530 100644 --- a/drivers/fpga/fpga_ice40.c +++ b/drivers/fpga/fpga_ice40.c @@ -71,7 +71,7 @@ #define FPGA_ICE40_SPI_HZ_MAX 25000000 #define FPGA_ICE40_CRESET_DELAY_NS_MIN 200 -#define FPGA_ICE40_CONFIG_DELAY_US_MIN 300 +#define FPGA_ICE40_CONFIG_DELAY_US_MIN 1200 #define FPGA_ICE40_LEADING_CLOCKS_MIN 8 #define FPGA_ICE40_TRAILING_CLOCKS_MIN 49 diff --git a/dts/bindings/fpga/lattice,ice40-fpga.yaml b/dts/bindings/fpga/lattice,ice40-fpga.yaml index f306b6c3dc12..8e5467be236b 100644 --- a/dts/bindings/fpga/lattice,ice40-fpga.yaml +++ b/dts/bindings/fpga/lattice,ice40-fpga.yaml @@ -84,7 +84,7 @@ properties: description: | Delay (in microseconds) after releasing CRESET_B to clear internal configuration memory. Example usage / default: - config-delay-us = <300>; + config-delay-us = <1200>; leading-clocks: type: int description: | diff --git a/tests/drivers/build_all/fpga/spi.dtsi b/tests/drivers/build_all/fpga/spi.dtsi index d0ca6b3810a8..c5b439d97e9b 100644 --- a/tests/drivers/build_all/fpga/spi.dtsi +++ b/tests/drivers/build_all/fpga/spi.dtsi @@ -16,7 +16,7 @@ test_spi_fpga_ice40_gpio: ice40@0 { load-mode = <0>; cdone-gpios = <&test_gpio 0 0>; creset-gpios = <&test_gpio 0 0>; - config-delay-us = <390>; + config-delay-us = <3900>; }; test_spi_fpga_ice40_spi: ice40@1 { @@ -33,5 +33,5 @@ test_spi_fpga_ice40_spi: ice40@1 { pico-gpios = <&test_gpio 0 0>; gpios-set-reg = <0>; gpios-clear-reg = <0>; - config-delay-us = <390>; + config-delay-us = <3900>; }; From 2f6dff59c50f44a426ac0ae78fe1f28ceed7fd96 Mon Sep 17 00:00:00 2001 From: Armin Brauns Date: Tue, 24 Jan 2023 09:55:22 +0100 Subject: [PATCH 0188/1906] drivers/fpga: ice40: use k_usleep instead of busy loop in SPI mode The 200ns reset time are a minimum value, there is no need to enforce precise timing (and thus manual per-device calibration) here. Signed-off-by: Armin Brauns --- drivers/fpga/fpga_ice40.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/fpga/fpga_ice40.c b/drivers/fpga/fpga_ice40.c index 9d0808a2b530..a86ef41fd92e 100644 --- a/drivers/fpga/fpga_ice40.c +++ b/drivers/fpga/fpga_ice40.c @@ -365,7 +365,7 @@ static int fpga_ice40_load_spi(const struct device *dev, uint32_t *image_ptr, ui /* Wait a minimum of 200ns */ LOG_DBG("Delay %u ns (%u us)", config->creset_delay_ns, delay_us); - fpga_ice40_delay(2 * config->mhz_delay_count * delay_us); + k_usleep(delay_us); __ASSERT(gpio_pin_get_dt(&config->cdone) == 0, "CDONE was not high"); From d0762e54394401110c9d96333904fafe5b5c553c Mon Sep 17 00:00:00 2001 From: Armin Brauns Date: Tue, 24 Jan 2023 09:57:23 +0100 Subject: [PATCH 0189/1906] drivers/fpga: ice40: use microsecond resolution for reset time The 200ns reset time specified in the datasheet are a minimum time; and the nanoseconds were being rounded to whole microseconds anyway. Also make it the same type as `config_delay_us` (`uint16_t`). Signed-off-by: Armin Brauns --- drivers/fpga/fpga_ice40.c | 30 +++++++++-------------- dts/bindings/fpga/lattice,ice40-fpga.yaml | 6 ++--- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/drivers/fpga/fpga_ice40.c b/drivers/fpga/fpga_ice40.c index a86ef41fd92e..6b1e648e6356 100644 --- a/drivers/fpga/fpga_ice40.c +++ b/drivers/fpga/fpga_ice40.c @@ -70,7 +70,7 @@ #define FPGA_ICE40_SPI_HZ_MIN 1000000 #define FPGA_ICE40_SPI_HZ_MAX 25000000 -#define FPGA_ICE40_CRESET_DELAY_NS_MIN 200 +#define FPGA_ICE40_CRESET_DELAY_US_MIN 1 /* 200ns absolute minimum */ #define FPGA_ICE40_CONFIG_DELAY_US_MIN 1200 #define FPGA_ICE40_LEADING_CLOCKS_MIN 8 #define FPGA_ICE40_TRAILING_CLOCKS_MIN 49 @@ -95,7 +95,7 @@ struct fpga_ice40_config { volatile gpio_port_pins_t *set; volatile gpio_port_pins_t *clear; uint16_t mhz_delay_count; - uint8_t creset_delay_ns; + uint16_t creset_delay_us; uint16_t config_delay_us; uint8_t leading_clocks; uint8_t trailing_clocks; @@ -210,7 +210,6 @@ static int fpga_ice40_load_gpio(const struct device *dev, uint32_t *image_ptr, u { int ret; uint32_t crc; - uint32_t delay_us; gpio_port_pins_t cs; gpio_port_pins_t clk; k_spinlock_key_t key; @@ -231,9 +230,6 @@ static int fpga_ice40_load_gpio(const struct device *dev, uint32_t *image_ptr, u LOG_WRN("already loaded with image CRC32c: 0x%08x", data->crc); } - /* precompute delay values */ - delay_us = ceiling_fraction(config->creset_delay_ns, NSEC_PER_USEC); - key = k_spin_lock(&data->lock); /* clear crc */ @@ -254,8 +250,8 @@ static int fpga_ice40_load_gpio(const struct device *dev, uint32_t *image_ptr, u *config->clear |= (creset | cs); /* Wait a minimum of 200ns */ - LOG_DBG("Delay %u ns (%u us)", config->creset_delay_ns, delay_us); - fpga_ice40_delay(2 * config->mhz_delay_count * delay_us); + LOG_DBG("Delay %u us", config->creset_delay_us); + fpga_ice40_delay(2 * config->mhz_delay_count * config->creset_delay_us); __ASSERT(gpio_pin_get_dt(&config->cdone) == 0, "CDONE was not high"); @@ -316,7 +312,6 @@ static int fpga_ice40_load_spi(const struct device *dev, uint32_t *image_ptr, ui { int ret; uint32_t crc; - uint32_t delay_us; k_spinlock_key_t key; struct spi_buf tx_buf; const struct spi_buf_set tx_bufs = { @@ -333,9 +328,6 @@ static int fpga_ice40_load_spi(const struct device *dev, uint32_t *image_ptr, ui LOG_WRN("already loaded with image CRC32c: 0x%08x", data->crc); } - /* precompute delay values */ - delay_us = ceiling_fraction(config->creset_delay_ns, NSEC_PER_USEC); - key = k_spin_lock(&data->lock); /* clear crc */ @@ -364,8 +356,8 @@ static int fpga_ice40_load_spi(const struct device *dev, uint32_t *image_ptr, ui } /* Wait a minimum of 200ns */ - LOG_DBG("Delay %u ns (%u us)", config->creset_delay_ns, delay_us); - k_usleep(delay_us); + LOG_DBG("Delay %u us", config->creset_delay_us); + k_usleep(config->creset_delay_us); __ASSERT(gpio_pin_get_dt(&config->cdone) == 0, "CDONE was not high"); @@ -541,8 +533,8 @@ static int fpga_ice40_init(const struct device *dev) #define FPGA_ICE40_CONFIG_DELAY_US(inst) \ DT_INST_PROP_OR(inst, config_delay_us, FPGA_ICE40_CONFIG_DELAY_US_MIN) -#define FPGA_ICE40_CRESET_DELAY_NS(inst) \ - DT_INST_PROP_OR(inst, creset_delay_ns, FPGA_ICE40_CRESET_DELAY_NS_MIN) +#define FPGA_ICE40_CRESET_DELAY_US(inst) \ + DT_INST_PROP_OR(inst, creset_delay_us, FPGA_ICE40_CRESET_DELAY_US_MIN) #define FPGA_ICE40_LEADING_CLOCKS(inst) \ DT_INST_PROP_OR(inst, leading_clocks, FPGA_ICE40_LEADING_CLOCKS_MIN) @@ -576,8 +568,8 @@ static int fpga_ice40_init(const struct device *dev) BUILD_ASSERT(FPGA_ICE40_BUS_FREQ(inst) <= FPGA_ICE40_SPI_HZ_MAX); \ BUILD_ASSERT(FPGA_ICE40_CONFIG_DELAY_US(inst) >= FPGA_ICE40_CONFIG_DELAY_US_MIN); \ BUILD_ASSERT(FPGA_ICE40_CONFIG_DELAY_US(inst) <= UINT16_MAX); \ - BUILD_ASSERT(FPGA_ICE40_CRESET_DELAY_NS(inst) >= FPGA_ICE40_CRESET_DELAY_NS_MIN); \ - BUILD_ASSERT(FPGA_ICE40_CRESET_DELAY_NS(inst) <= UINT8_MAX); \ + BUILD_ASSERT(FPGA_ICE40_CRESET_DELAY_US(inst) >= FPGA_ICE40_CRESET_DELAY_US_MIN); \ + BUILD_ASSERT(FPGA_ICE40_CRESET_DELAY_US(inst) <= UINT16_MAX); \ BUILD_ASSERT(FPGA_ICE40_LEADING_CLOCKS(inst) >= FPGA_ICE40_LEADING_CLOCKS_MIN); \ BUILD_ASSERT(FPGA_ICE40_LEADING_CLOCKS(inst) <= UINT8_MAX); \ BUILD_ASSERT(FPGA_ICE40_TRAILING_CLOCKS(inst) >= FPGA_ICE40_TRAILING_CLOCKS_MIN); \ @@ -597,7 +589,7 @@ static int fpga_ice40_init(const struct device *dev) .clear = FPGA_ICE40_GPIO_PINS(inst, gpios_clear_reg), \ .mhz_delay_count = FPGA_ICE40_MHZ_DELAY_COUNT(inst), \ .config_delay_us = FPGA_ICE40_CONFIG_DELAY_US(inst), \ - .creset_delay_ns = FPGA_ICE40_CRESET_DELAY_NS(inst), \ + .creset_delay_us = FPGA_ICE40_CRESET_DELAY_US(inst), \ .leading_clocks = FPGA_ICE40_LEADING_CLOCKS(inst), \ .trailing_clocks = FPGA_ICE40_TRAILING_CLOCKS(inst), \ .load = FPGA_ICE40_LOAD_FUNC(inst), \ diff --git a/dts/bindings/fpga/lattice,ice40-fpga.yaml b/dts/bindings/fpga/lattice,ice40-fpga.yaml index 8e5467be236b..530f99e679cc 100644 --- a/dts/bindings/fpga/lattice,ice40-fpga.yaml +++ b/dts/bindings/fpga/lattice,ice40-fpga.yaml @@ -73,12 +73,12 @@ properties: } Example usage / default: mhz-delay-count = <0>; - creset-delay-ns: + creset-delay-us: type: int description: | - Delay (in nanoseconds) between asserting CRESET_B and releasing CRESET_B. + Delay (in microseconds) between asserting CRESET_B and releasing CRESET_B. Example usage / default: - creset-delay-ns = <200>; + creset-delay-us = <1>; config-delay-us: type: int description: | From a6e5135381199e84e453300f49077f38f5e65a6f Mon Sep 17 00:00:00 2001 From: Armin Brauns Date: Fri, 10 Mar 2023 08:50:43 +0100 Subject: [PATCH 0190/1906] drivers: fpga: ice40: fix busy delay loop This was being optimized out entirely by certain compiler configurations. Signed-off-by: Armin Brauns --- drivers/fpga/fpga_ice40.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/fpga/fpga_ice40.c b/drivers/fpga/fpga_ice40.c index 6b1e648e6356..b6a59c5057e5 100644 --- a/drivers/fpga/fpga_ice40.c +++ b/drivers/fpga/fpga_ice40.c @@ -132,6 +132,7 @@ static void fpga_ice40_crc_to_str(uint32_t crc, char *s) static inline void fpga_ice40_delay(size_t n) { for (; n > 0; --n) { + __asm__ __volatile__(""); } } From bb6fa5707f77d72307008405f19dd83247405392 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Tue, 14 Mar 2023 09:17:13 +0100 Subject: [PATCH 0191/1906] nrf52_bsim: Fix unfreed memory There was a chunk of unfreed memory left over at exit(). Clear it as it should be. The issue is only a cause for a warning in valgrind, as Linux frees all process booked memory on exit, but nonetheless it is better fixing it. Signed-off-by: Alberto Escolar Piedras --- boards/posix/nrf52_bsim/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/boards/posix/nrf52_bsim/main.c b/boards/posix/nrf52_bsim/main.c index cc5d28eaeaca..38e92f668de6 100644 --- a/boards/posix/nrf52_bsim/main.c +++ b/boards/posix/nrf52_bsim/main.c @@ -37,6 +37,7 @@ uint8_t inner_main_clean_up(int exit_code) bs_dump_files_close_all(); bs_clean_back_channels(); + bs_clear_Tsymbols(); uint8_t bst_result = bst_delete(); From 33220ef086cc13e9f0e2334fbe4a853876792414 Mon Sep 17 00:00:00 2001 From: Grzegorz Chwierut Date: Wed, 8 Mar 2023 15:54:02 +0100 Subject: [PATCH 0192/1906] twister: extend --force-platform to skip platform_allow options In many of test specifications yaml files (testcase.yaml, sample.yaml) section `platform_allow` is added. This change allows to test some scenarios on platforms, that are not added yet to platform allow list (or are not going to be added for some reasons). Signed-off-by: Grzegorz Chwierut --- scripts/pylib/twister/twisterlib/testplan.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/pylib/twister/twisterlib/testplan.py b/scripts/pylib/twister/twisterlib/testplan.py index 3794baecc1ef..4a65eba38285 100755 --- a/scripts/pylib/twister/twisterlib/testplan.py +++ b/scripts/pylib/twister/twisterlib/testplan.py @@ -754,7 +754,9 @@ def apply_filters(self, **kwargs): if platform_filter and plat.name not in platform_filter: instance.add_filter("Command line platform filter", Filters.CMD_LINE) - if ts.platform_allow and plat.name not in ts.platform_allow: + if ts.platform_allow \ + and plat.name not in ts.platform_allow \ + and not (platform_filter and force_platform): instance.add_filter("Not in testsuite platform allow list", Filters.TESTSUITE) if ts.platform_type and plat.type not in ts.platform_type: From c626070ae6dd5dec687770858a41d4ae7be166a4 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Mon, 13 Mar 2023 11:05:33 +0200 Subject: [PATCH 0193/1906] drivers: mt9m114: Fix value type Fixes value type conversion from uint16_t to uint32_t. Signed-off-by: Andrei Emeltchenko --- drivers/video/mt9m114.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/mt9m114.c b/drivers/video/mt9m114.c index 57613c1b16f3..45915431307c 100644 --- a/drivers/video/mt9m114.c +++ b/drivers/video/mt9m114.c @@ -144,7 +144,7 @@ static int mt9m114_write_reg(const struct device *dev, uint16_t reg_addr, *(uint16_t *)value = sys_cpu_to_be16(*(uint16_t *)value); break; case 4: - *(uint16_t *)value = sys_cpu_to_be32(*(uint16_t *)value); + *(uint32_t *)value = sys_cpu_to_be32(*(uint32_t *)value); break; case 1: break; From 4d1757b15ab44ff8804486e80aa9074f08e7346a Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Fri, 10 Mar 2023 15:43:35 +0100 Subject: [PATCH 0194/1906] Bluetooth: Mesh: add more fixed group addresses Mesh-1.1 spec extends number group addresses. There were added: all forwarding address, all ip nodes, all ip border routers. Even Zephyr's mesh doesn't support them it should be able to subscribe heartbeat on these groups. Also mesh should provide ability to subscribe\publish models on these groups. Signed-off-by: Aleksandr Khromykh --- include/zephyr/bluetooth/mesh/access.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/zephyr/bluetooth/mesh/access.h b/include/zephyr/bluetooth/mesh/access.h index 8f28fbcf555f..8ac7c6c18177 100644 --- a/include/zephyr/bluetooth/mesh/access.h +++ b/include/zephyr/bluetooth/mesh/access.h @@ -33,11 +33,14 @@ extern "C" { #endif -#define BT_MESH_ADDR_UNASSIGNED 0x0000 -#define BT_MESH_ADDR_ALL_NODES 0xffff -#define BT_MESH_ADDR_PROXIES 0xfffc -#define BT_MESH_ADDR_FRIENDS 0xfffd -#define BT_MESH_ADDR_RELAYS 0xfffe +#define BT_MESH_ADDR_UNASSIGNED 0x0000 +#define BT_MESH_ADDR_ALL_NODES 0xffff +#define BT_MESH_ADDR_RELAYS 0xfffe +#define BT_MESH_ADDR_FRIENDS 0xfffd +#define BT_MESH_ADDR_PROXIES 0xfffc +#define BT_MESH_ADDR_DFW_NODES 0xfffb +#define BT_MESH_ADDR_IP_NODES 0xfffa +#define BT_MESH_ADDR_IP_BR_ROUTERS 0xfff9 #define BT_MESH_KEY_UNUSED 0xffff #define BT_MESH_KEY_ANY 0xffff @@ -50,7 +53,7 @@ extern "C" { #define BT_MESH_ADDR_IS_GROUP(addr) ((addr) >= 0xc000 && (addr) < 0xff00) #define BT_MESH_ADDR_IS_FIXED_GROUP(addr) ((addr) >= 0xff00 && (addr) < 0xffff) #define BT_MESH_ADDR_IS_VIRTUAL(addr) ((addr) >= 0x8000 && (addr) < 0xc000) -#define BT_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xff00 && (addr) <= 0xfffb) +#define BT_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xff00 && (addr) <= 0xfff8) #define BT_MESH_IS_DEV_KEY(key) (key == BT_MESH_KEY_DEV_LOCAL || \ key == BT_MESH_KEY_DEV_REMOTE) From 6862fdea1a6999db1980803d2580a11f1e8cb7b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Fri, 10 Mar 2023 13:32:42 +0100 Subject: [PATCH 0195/1906] net: dns: Check existing DNS servers before reconfigure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In dns_resolve_reconfigure() check if the DNS servers already exist before cancel all ongoing queries. This will solve an issue with getaddrinfo() returning DNS_EAI_CANCELED when receiving a retransmitted DHCP offer and when receiving a IPv6 Router Advertisement. Signed-off-by: Stig Bjørlykke --- subsys/net/lib/dns/resolve.c | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/subsys/net/lib/dns/resolve.c b/subsys/net/lib/dns/resolve.c index db419adc0f40..d5d571cc73ce 100644 --- a/subsys/net/lib/dns/resolve.c +++ b/subsys/net/lib/dns/resolve.c @@ -1386,6 +1386,59 @@ int dns_resolve_close(struct dns_resolve_context *ctx) return ret; } +static bool dns_server_exists(struct dns_resolve_context *ctx, + const struct sockaddr *addr) +{ + for (int i = 0; i < SERVER_COUNT; i++) { + if (IS_ENABLED(CONFIG_NET_IPV4) && (addr->sa_family == AF_INET) && + (ctx->servers[i].dns_server.sa_family == AF_INET)) { + if (net_ipv4_addr_cmp(&net_sin(addr)->sin_addr, + &net_sin(&ctx->servers[i].dns_server)->sin_addr)) { + return true; + } + } + + if (IS_ENABLED(CONFIG_NET_IPV6) && (addr->sa_family == AF_INET6) && + (ctx->servers[i].dns_server.sa_family == AF_INET6)) { + if (net_ipv6_addr_cmp(&net_sin6(addr)->sin6_addr, + &net_sin6(&ctx->servers[i].dns_server)->sin6_addr)) { + return true; + } + } + } + + return false; +} + +static bool dns_servers_exists(struct dns_resolve_context *ctx, + const char *servers[], + const struct sockaddr *servers_sa[]) +{ + if (servers) { + for (int i = 0; i < SERVER_COUNT && servers[i]; i++) { + struct sockaddr addr; + + if (!net_ipaddr_parse(servers[i], strlen(servers[i]), &addr)) { + continue; + } + + if (!dns_server_exists(ctx, &addr)) { + return false; + } + } + } + + if (servers_sa) { + for (int i = 0; i < SERVER_COUNT && servers_sa[i]; i++) { + if (!dns_server_exists(ctx, servers_sa[i])) { + return false; + } + } + } + + return true; +} + int dns_resolve_reconfigure(struct dns_resolve_context *ctx, const char *servers[], const struct sockaddr *servers_sa[]) @@ -1398,6 +1451,12 @@ int dns_resolve_reconfigure(struct dns_resolve_context *ctx, k_mutex_lock(&ctx->lock, K_FOREVER); + if (dns_servers_exists(ctx, servers, servers_sa)) { + /* DNS servers did not change. */ + err = 0; + goto unlock; + } + if (ctx->state == DNS_RESOLVE_CONTEXT_DEACTIVATING) { err = -EBUSY; goto unlock; From 6ad247268de11afebc7eaff290482e3b5b38639f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Sun, 26 Feb 2023 12:19:30 +0100 Subject: [PATCH 0196/1906] west.yml: Use latest STM32 HAL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use latest STM32 HAL to have the new STM32C0xx Series. Signed-off-by: Benjamin Björnsson --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 160ef7e31c52..04fac496bdab 100644 --- a/west.yml +++ b/west.yml @@ -129,7 +129,7 @@ manifest: groups: - hal - name: hal_stm32 - revision: c36136b253a46ed8dd63525eeee659393047ce83 + revision: 7c511b744fadde3fd197779a93043d27e30b0025 path: modules/hal/stm32 groups: - hal From cc482128755bb90f2111e569b763dbaeed0076e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Wed, 15 Feb 2023 22:43:30 +0100 Subject: [PATCH 0197/1906] soc: arm: st_stm32: stm32c0: Add STM32C0 Series support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add initial support of STM32C0 Series. Signed-off-by: Benjamin Björnsson --- soc/arm/st_stm32/stm32c0/CMakeLists.txt | 6 +++ .../st_stm32/stm32c0/Kconfig.defconfig.series | 13 +++++ .../stm32c0/Kconfig.defconfig.stm32c031xx | 14 +++++ soc/arm/st_stm32/stm32c0/Kconfig.series | 16 ++++++ soc/arm/st_stm32/stm32c0/Kconfig.soc | 13 +++++ soc/arm/st_stm32/stm32c0/linker.ld | 9 ++++ soc/arm/st_stm32/stm32c0/soc.c | 51 +++++++++++++++++++ soc/arm/st_stm32/stm32c0/soc.h | 26 ++++++++++ 8 files changed, 148 insertions(+) create mode 100644 soc/arm/st_stm32/stm32c0/CMakeLists.txt create mode 100644 soc/arm/st_stm32/stm32c0/Kconfig.defconfig.series create mode 100644 soc/arm/st_stm32/stm32c0/Kconfig.defconfig.stm32c031xx create mode 100644 soc/arm/st_stm32/stm32c0/Kconfig.series create mode 100644 soc/arm/st_stm32/stm32c0/Kconfig.soc create mode 100644 soc/arm/st_stm32/stm32c0/linker.ld create mode 100644 soc/arm/st_stm32/stm32c0/soc.c create mode 100644 soc/arm/st_stm32/stm32c0/soc.h diff --git a/soc/arm/st_stm32/stm32c0/CMakeLists.txt b/soc/arm/st_stm32/stm32c0/CMakeLists.txt new file mode 100644 index 000000000000..ac3ba70ace6e --- /dev/null +++ b/soc/arm/st_stm32/stm32c0/CMakeLists.txt @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_include_directories(${ZEPHYR_BASE}/drivers) +zephyr_sources( + soc.c + ) diff --git a/soc/arm/st_stm32/stm32c0/Kconfig.defconfig.series b/soc/arm/st_stm32/stm32c0/Kconfig.defconfig.series new file mode 100644 index 000000000000..d4ee373c0914 --- /dev/null +++ b/soc/arm/st_stm32/stm32c0/Kconfig.defconfig.series @@ -0,0 +1,13 @@ +# STMicroelectronics STM32C0 MCU line + +# Copyright (c) 2023 Benjamin Björnsson +# SPDX-License-Identifier: Apache-2.0 + +if SOC_SERIES_STM32C0X + +source "soc/arm/st_stm32/stm32c0/Kconfig.defconfig.stm32c0*" + +config SOC_SERIES + default "stm32c0" + +endif # SOC_SERIES_STM32C0X diff --git a/soc/arm/st_stm32/stm32c0/Kconfig.defconfig.stm32c031xx b/soc/arm/st_stm32/stm32c0/Kconfig.defconfig.stm32c031xx new file mode 100644 index 000000000000..5a84b4ff31a1 --- /dev/null +++ b/soc/arm/st_stm32/stm32c0/Kconfig.defconfig.stm32c031xx @@ -0,0 +1,14 @@ +# STMicroelectronics STM32C031xx MCU + +# Copyright (c) 2023 Benjamin Björnsson +# SPDX-License-Identifier: Apache-2.0 + +if SOC_STM32C031XX + +config SOC + default "stm32c031xx" + +config NUM_IRQS + default 29 + +endif # SOC_STM32C031XX diff --git a/soc/arm/st_stm32/stm32c0/Kconfig.series b/soc/arm/st_stm32/stm32c0/Kconfig.series new file mode 100644 index 000000000000..cc69099a6c6e --- /dev/null +++ b/soc/arm/st_stm32/stm32c0/Kconfig.series @@ -0,0 +1,16 @@ +# STMicroelectronics STM32C0 MCU series + +# Copyright (c) 2023 Benjamin Björnsson +# SPDX-License-Identifier: Apache-2.0 + +config SOC_SERIES_STM32C0X + bool "STM32C0x Series MCU" + select ARM + select CPU_CORTEX_M0PLUS + select CPU_CORTEX_M_HAS_VTOR + select CPU_HAS_ARM_MPU + select SOC_FAMILY_STM32 + select HAS_STM32CUBE + select CPU_CORTEX_M_HAS_SYSTICK + help + Enable support for STM32C0 MCU series diff --git a/soc/arm/st_stm32/stm32c0/Kconfig.soc b/soc/arm/st_stm32/stm32c0/Kconfig.soc new file mode 100644 index 000000000000..e54678aefffd --- /dev/null +++ b/soc/arm/st_stm32/stm32c0/Kconfig.soc @@ -0,0 +1,13 @@ +# STMicroelectronics STM32C0 MCU line + +# Copyright (c) 2023 Benjamin Björnsson +# SPDX-License-Identifier: Apache-2.0 + +choice + prompt "STM32C0x MCU Selection" + depends on SOC_SERIES_STM32C0X + +config SOC_STM32C031XX + bool "STM32C031XX" + +endchoice diff --git a/soc/arm/st_stm32/stm32c0/linker.ld b/soc/arm/st_stm32/stm32c0/linker.ld new file mode 100644 index 000000000000..fda50c307af0 --- /dev/null +++ b/soc/arm/st_stm32/stm32c0/linker.ld @@ -0,0 +1,9 @@ +/* linker.ld - Linker command/script file */ + +/* + * Copyright (c) 2023 Benjamin Björnsson + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include diff --git a/soc/arm/st_stm32/stm32c0/soc.c b/soc/arm/st_stm32/stm32c0/soc.c new file mode 100644 index 000000000000..4ef3783abe82 --- /dev/null +++ b/soc/arm/st_stm32/stm32c0/soc.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Benjamin Björnsson + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief System/hardware module for STM32C0 processor + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * @brief Perform basic hardware initialization at boot. + * + * This needs to be run from the very beginning. + * So the init priority has to be 0 (zero). + * + * @return 0 + */ +static int stm32c0_init(const struct device *arg) +{ + uint32_t key; + + ARG_UNUSED(arg); + + key = irq_lock(); + + /* Install default handler that simply resets the CPU + * if configured in the kernel, NOP otherwise + */ + NMI_INIT(); + + irq_unlock(key); + + /* Update CMSIS SystemCoreClock variable (HCLK) */ + /* At reset, system core clock is set to 48 MHz from HSI */ + SystemCoreClock = 48000000; + + return 0; +} + +SYS_INIT(stm32c0_init, PRE_KERNEL_1, 0); diff --git a/soc/arm/st_stm32/stm32c0/soc.h b/soc/arm/st_stm32/stm32c0/soc.h new file mode 100644 index 000000000000..fa562a6eb332 --- /dev/null +++ b/soc/arm/st_stm32/stm32c0/soc.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 Benjamin Björnsson + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file SoC configuration macros for the STM32C0 family processors. + * + * Based on reference manual: + * STM32C0X advanced ARM ® -based 32-bit MCUs + * + * Chapter 2.2: Memory organization + */ + + +#ifndef _STM32C0_SOC_H_ +#define _STM32C0_SOC_H_ + +#ifndef _ASMLANGUAGE + +#include + +#endif /* !_ASMLANGUAGE */ + +#endif /* _STM32C0_SOC_H_ */ From 17f96eba34e960c3df239dc947ec2f932ac7b0db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Sun, 26 Feb 2023 11:07:18 +0100 Subject: [PATCH 0198/1906] dt-bindings: reset: Add STM32C0 reset header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add header to be included in STM32C0 series dtsi files. Signed-off-by: Benjamin Björnsson --- .../zephyr/dt-bindings/reset/stm32c0_reset.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 include/zephyr/dt-bindings/reset/stm32c0_reset.h diff --git a/include/zephyr/dt-bindings/reset/stm32c0_reset.h b/include/zephyr/dt-bindings/reset/stm32c0_reset.h new file mode 100644 index 000000000000..6965c0631b51 --- /dev/null +++ b/include/zephyr/dt-bindings/reset/stm32c0_reset.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022 Google Inc + * Copyright (c) Benjamin Björnsson + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_RESET_STM32C0_RESET_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_RESET_STM32C0_RESET_H_ + +#include "stm32-common.h" + +/* RCC bus reset register offset */ +#define STM32_RESET_BUS_IOP 0x24 +#define STM32_RESET_BUS_AHB1 0x28 +#define STM32_RESET_BUS_APB1L 0x2C +#define STM32_RESET_BUS_APB1H 0x30 + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_RESET_STM32C0_RESET_H_ */ From 9818fae522918a722ba7beb94eda57a7100285e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Sun, 26 Feb 2023 11:09:32 +0100 Subject: [PATCH 0199/1906] dts: bindings: clock: Add STM32C0 HSI clock binding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add binding for HSI clock source in STM32C0 series. Signed-off-by: Benjamin Björnsson --- dts/bindings/clock/st,stm32c0-hsi-clock.yaml | 39 ++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 dts/bindings/clock/st,stm32c0-hsi-clock.yaml diff --git a/dts/bindings/clock/st,stm32c0-hsi-clock.yaml b/dts/bindings/clock/st,stm32c0-hsi-clock.yaml new file mode 100644 index 000000000000..a19fd6f605d0 --- /dev/null +++ b/dts/bindings/clock/st,stm32c0-hsi-clock.yaml @@ -0,0 +1,39 @@ +# Copyright (c) 2023 Benjamin Björnsson . +# SPDX-License-Identifier: Apache-2.0 + +description: | + STM32 HSI Clock node description for STM32C0 devices + On STM32C0, HSI is a 48MHz fixed clock. + + It also produces a HSISYS secondary clk which can be used as system clock + source. In that case, a HSI divisor (ranges from 1 to 128) can be applied: + SYSCLK = HSI48 / HSI DIV + enum: + - 1 ==> HSISYS = 48MHZ + - 2 ==> HSISYS = 24MHZ + - 4 ==> HSISYS = 12MHZ + - 8 ==> HSISYS = 6MHZ + - 16 ==> HSISYS = 3MHZ + - 32 ==> HSISYS = 1.5MHz + - 64 ==> HSISYS = 0.75MHZ + - 128 ==> HSISYS = 0.375MHz + +compatible: "st,stm32c0-hsi-clock" + +include: [fixed-clock.yaml] + +properties: + hsi-div: + type: int + required: true + description: | + HSI clock divider. Configures the output HSI clock frequency (HSISYS). + enum: + - 1 + - 2 + - 4 + - 8 + - 16 + - 32 + - 64 + - 128 From 3d937e2ccd12c7de1f65e852006adc42c4782ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Sun, 26 Feb 2023 10:57:32 +0100 Subject: [PATCH 0200/1906] dts: arm: st: add STM32C0 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add STM32C031X6 device tree. Signed-off-by: Benjamin Björnsson --- dts/arm/st/c0/stm32c0.dtsi | 167 +++++++++++++++++++++++++++++++++ dts/arm/st/c0/stm32c031.dtsi | 21 +++++ dts/arm/st/c0/stm32c031X6.dtsi | 22 +++++ 3 files changed, 210 insertions(+) create mode 100644 dts/arm/st/c0/stm32c0.dtsi create mode 100644 dts/arm/st/c0/stm32c031.dtsi create mode 100644 dts/arm/st/c0/stm32c031X6.dtsi diff --git a/dts/arm/st/c0/stm32c0.dtsi b/dts/arm/st/c0/stm32c0.dtsi new file mode 100644 index 000000000000..610408c4e567 --- /dev/null +++ b/dts/arm/st/c0/stm32c0.dtsi @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2023 Benjamin Björnsson + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +/ { + chosen { + zephyr,flash-controller = &flash; + }; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-m0+"; + reg = <0>; + }; + }; + + sram0: memory@20000000 { + compatible = "mmio-sram"; + }; + + clocks { + clk_hse: clk-hse { + #clock-cells = <0>; + compatible = "st,stm32-hse-clock"; + status = "disabled"; + }; + + clk_hsi: clk-hsi { + #clock-cells = <0>; + compatible = "st,stm32c0-hsi-clock"; + hsi-div = <1>; + clock-frequency = ; + status = "disabled"; + }; + + clk_lse: clk-lse { + #clock-cells = <0>; + compatible = "st,stm32-lse-clock"; + clock-frequency = <32768>; + driving-capability = <0>; + status = "disabled"; + }; + + clk_lsi: clk-lsi { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = ; + status = "disabled"; + }; + }; + + soc { + flash: flash-controller@40022000 { + compatible = "st,stm32-flash-controller"; + reg = <0x40022000 0x400>; + interrupts = <3 0>; + clocks = <&rcc STM32_CLOCK_BUS_AHB1 0x00000100>; + + #address-cells = <1>; + #size-cells = <1>; + + flash0: flash@8000000 { + compatible = "st,stm32-nv-flash", "soc-nv-flash"; + + write-block-size = <8>; + erase-block-size = <2048>; + /* maximum erase time(ms) for a 2K sector */ + max-erase-time = <40>; + }; + }; + + rcc: rcc@40021000 { + compatible = "st,stm32f0-rcc"; + #clock-cells = <2>; + reg = <0x40021000 0x400>; + + rctl: reset-controller { + compatible = "st,stm32-rcc-rctl"; + #reset-cells = <1>; + }; + }; + + exti: interrupt-controller@40021800 { + compatible = "st,stm32-exti"; + interrupt-controller; + #interrupt-cells = <1>; + reg = <0x40021800 0x400>; + num-lines = <16>; + interrupts = <5 0>, <6 0>, <7 0>; + interrupt-names = "line0-1", "line2-3", "line4-15"; + line-ranges = <0 2>, <2 2>, <4 12>; + }; + + pinctrl: pin-controller@50000000 { + compatible = "st,stm32-pinctrl"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x50000000 0x2000>; + + gpioa: gpio@50000000 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x50000000 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_IOP 0x00000001>; + }; + + gpiob: gpio@50000400 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x50000400 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_IOP 0x00000002>; + }; + + gpioc: gpio@50000800 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x50000800 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_IOP 0x00000004>; + }; + + gpiof: gpio@50001400 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x50001400 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_IOP 0x00000020>; + }; + }; + + usart1: serial@40013800 { + compatible = "st,stm32-usart", "st,stm32-uart"; + reg = <0x40013800 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1_2 0x00004000>; + resets = <&rctl STM32_RESET(APB1H, 14U)>; + interrupts = <27 0>; + status = "disabled"; + }; + + usart2: serial@40004400 { + compatible = "st,stm32-usart", "st,stm32-uart"; + reg = <0x40004400 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1 0x00020000>; + resets = <&rctl STM32_RESET(APB1L, 17U)>; + interrupts = <28 0>; + status = "disabled"; + }; + }; +}; + +&nvic { + arm,num-irq-priority-bits = <2>; +}; diff --git a/dts/arm/st/c0/stm32c031.dtsi b/dts/arm/st/c0/stm32c031.dtsi new file mode 100644 index 000000000000..23f26117329c --- /dev/null +++ b/dts/arm/st/c0/stm32c031.dtsi @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Benjamin Björnsson + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/ { + soc { + pinctrl: pin-controller@50000000 { + gpiod: gpio@50000c00 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x50000c00 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_IOP 0x00000008>; + }; + }; + }; +}; diff --git a/dts/arm/st/c0/stm32c031X6.dtsi b/dts/arm/st/c0/stm32c031X6.dtsi new file mode 100644 index 000000000000..817118aef2a8 --- /dev/null +++ b/dts/arm/st/c0/stm32c031X6.dtsi @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Benjamin Björnsson . + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/ { + sram0: memory@20000000 { + reg = <0x20000000 DT_SIZE_K(12)>; + }; + + soc { + flash-controller@40022000 { + flash0: flash@8000000 { + reg = <0x08000000 DT_SIZE_K(32)>; + }; + }; + }; +}; From cc03cb37904f2ae9ccf1183ca430d1ebb58c1725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Tue, 21 Feb 2023 18:10:08 +0100 Subject: [PATCH 0201/1906] drivers: gpio: gpio_stm32: Add STM32C0 Support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add STM32C0 support to gpio driver. Signed-off-by: Benjamin Björnsson --- drivers/gpio/gpio_stm32.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpio_stm32.c b/drivers/gpio/gpio_stm32.c index 465f68c5372b..8edb92d54a73 100644 --- a/drivers/gpio/gpio_stm32.c +++ b/drivers/gpio/gpio_stm32.c @@ -299,7 +299,8 @@ static inline uint32_t gpio_stm32_pin_to_exti_line(int pin) return ((pin % 4 * 4) << 16) | (pin / 4); #elif defined(CONFIG_SOC_SERIES_STM32MP1X) return (((pin * 8) % 32) << 16) | (pin / 4); -#elif defined(CONFIG_SOC_SERIES_STM32G0X) || \ +#elif defined(CONFIG_SOC_SERIES_STM32C0X) || \ + defined(CONFIG_SOC_SERIES_STM32G0X) || \ defined(CONFIG_SOC_SERIES_STM32L5X) || \ defined(CONFIG_SOC_SERIES_STM32U5X) return ((pin & 0x3) << (16 + 3)) | (pin >> 2); @@ -329,7 +330,8 @@ static void gpio_stm32_set_exti_source(int port, int pin) LL_GPIO_AF_SetEXTISource(port, line); #elif CONFIG_SOC_SERIES_STM32MP1X LL_EXTI_SetEXTISource(port, line); -#elif defined(CONFIG_SOC_SERIES_STM32G0X) || \ +#elif defined(CONFIG_SOC_SERIES_STM32C0X) || \ + defined(CONFIG_SOC_SERIES_STM32G0X) || \ defined(CONFIG_SOC_SERIES_STM32L5X) || \ defined(CONFIG_SOC_SERIES_STM32U5X) LL_EXTI_SetEXTISource(port, line); @@ -348,7 +350,8 @@ static int gpio_stm32_get_exti_source(int pin) port = LL_GPIO_AF_GetEXTISource(line); #elif CONFIG_SOC_SERIES_STM32MP1X port = LL_EXTI_GetEXTISource(line); -#elif defined(CONFIG_SOC_SERIES_STM32G0X) || \ +#elif defined(CONFIG_SOC_SERIES_STM32C0X) || \ + defined(CONFIG_SOC_SERIES_STM32G0X) || \ defined(CONFIG_SOC_SERIES_STM32L5X) || \ defined(CONFIG_SOC_SERIES_STM32U5X) port = LL_EXTI_GetEXTISource(line); From 074a6c0f206bd142f0520b4c06cb7adb936ed6e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Tue, 21 Feb 2023 18:11:25 +0100 Subject: [PATCH 0202/1906] drivers: interrupt-controller: intc_exti_stm32: Add STM32C0 Support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add STM32C0 support to interrupt-controller driver. Signed-off-by: Benjamin Björnsson --- drivers/interrupt_controller/intc_exti_stm32.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/interrupt_controller/intc_exti_stm32.c b/drivers/interrupt_controller/intc_exti_stm32.c index 84336e261e8e..bb3f5d88c665 100644 --- a/drivers/interrupt_controller/intc_exti_stm32.c +++ b/drivers/interrupt_controller/intc_exti_stm32.c @@ -95,6 +95,7 @@ static inline int stm32_exti_is_pending(int line) { if (line < 32) { #if defined(CONFIG_SOC_SERIES_STM32MP1X) || \ + defined(CONFIG_SOC_SERIES_STM32C0X) || \ defined(CONFIG_SOC_SERIES_STM32G0X) || \ defined(CONFIG_SOC_SERIES_STM32L5X) || \ defined(CONFIG_SOC_SERIES_STM32U5X) @@ -120,6 +121,7 @@ static inline void stm32_exti_clear_pending(int line) { if (line < 32) { #if defined(CONFIG_SOC_SERIES_STM32MP1X) || \ + defined(CONFIG_SOC_SERIES_STM32C0X) || \ defined(CONFIG_SOC_SERIES_STM32G0X) || \ defined(CONFIG_SOC_SERIES_STM32L5X) || \ defined(CONFIG_SOC_SERIES_STM32U5X) From f38a75f753c20cd93e84270137ef47503a6c9a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Sun, 26 Feb 2023 11:01:03 +0100 Subject: [PATCH 0203/1906] drivers: clock_control: add STM32C0 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add STM32C0 support to clock_control driver. Signed-off-by: Benjamin Björnsson --- drivers/clock_control/CMakeLists.txt | 1 + drivers/clock_control/clock_stm32_ll_common.c | 4 + drivers/clock_control/clock_stm32c0.c | 25 ++++++ .../clock_control/stm32_clock_control.h | 4 +- .../zephyr/dt-bindings/clock/stm32c0_clock.h | 76 +++++++++++++++++++ 5 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 drivers/clock_control/clock_stm32c0.c create mode 100644 include/zephyr/dt-bindings/clock/stm32c0_clock.h diff --git a/drivers/clock_control/CMakeLists.txt b/drivers/clock_control/CMakeLists.txt index c6e7d23700b9..034db40ad60e 100644 --- a/drivers/clock_control/CMakeLists.txt +++ b/drivers/clock_control/CMakeLists.txt @@ -33,6 +33,7 @@ elseif(CONFIG_SOC_SERIES_STM32U5X) zephyr_library_sources(clock_stm32_ll_u5.c) else() zephyr_library_sources(clock_stm32_ll_common.c) + zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_STM32C0X clock_stm32c0.c) zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_STM32F0X clock_stm32f0_f3.c) zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_STM32F1X clock_stm32f1.c) zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_STM32F2X clock_stm32f2_f4_f7.c) diff --git a/drivers/clock_control/clock_stm32_ll_common.c b/drivers/clock_control/clock_stm32_ll_common.c index 5c2419cb114a..03ff2924562e 100644 --- a/drivers/clock_control/clock_stm32_ll_common.c +++ b/drivers/clock_control/clock_stm32_ll_common.c @@ -622,11 +622,13 @@ static void set_up_fixed_clock_sources(void) z_stm32_hsem_lock(CFG_HW_RCC_SEMID, HSEM_LOCK_DEFAULT_RETRY); +#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) /* Set the DBP bit in the Power control register 1 (PWR_CR1) */ LL_PWR_EnableBkUpAccess(); while (!LL_PWR_IsEnabledBkUpAccess()) { /* Wait for Backup domain access */ } +#endif /* PWR_CR_DBP || PWR_CR1_DBP */ #if STM32_LSE_DRIVING /* Configure driving capability */ @@ -651,7 +653,9 @@ static void set_up_fixed_clock_sources(void) } #endif /* RCC_BDCR_LSESYSEN */ +#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) LL_PWR_DisableBkUpAccess(); +#endif /* PWR_CR_DBP || PWR_CR1_DBP */ z_stm32_hsem_unlock(CFG_HW_RCC_SEMID); } diff --git a/drivers/clock_control/clock_stm32c0.c b/drivers/clock_control/clock_stm32c0.c new file mode 100644 index 000000000000..7be327296cc4 --- /dev/null +++ b/drivers/clock_control/clock_stm32c0.c @@ -0,0 +1,25 @@ +/* + * + * Copyright (c) 2023 Benjamin Björnsson . + * + * SPDX-License-Identifier: Apache-2.0 + */ + + +#include +#include +#include +#include +#include +#include +#include +#include "clock_stm32_ll_common.h" + +/** + * @brief Activate default clocks + */ +void config_enable_default_clocks(void) +{ + /* Enable the power interface clock */ + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); +} diff --git a/include/zephyr/drivers/clock_control/stm32_clock_control.h b/include/zephyr/drivers/clock_control/stm32_clock_control.h index 9b446a56effe..064c3953be6a 100644 --- a/include/zephyr/drivers/clock_control/stm32_clock_control.h +++ b/include/zephyr/drivers/clock_control/stm32_clock_control.h @@ -11,7 +11,9 @@ #include -#if defined(CONFIG_SOC_SERIES_STM32F0X) +#if defined(CONFIG_SOC_SERIES_STM32C0X) +#include +#elif defined(CONFIG_SOC_SERIES_STM32F0X) #include #elif defined(CONFIG_SOC_SERIES_STM32F1X) #include diff --git a/include/zephyr/dt-bindings/clock/stm32c0_clock.h b/include/zephyr/dt-bindings/clock/stm32c0_clock.h new file mode 100644 index 000000000000..b48aa7d2ef1a --- /dev/null +++ b/include/zephyr/dt-bindings/clock/stm32c0_clock.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2023 Benjamin Björnsson + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_STM32C0_CLOCK_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_STM32C0_CLOCK_H_ + +/** Bus clocks */ +#define STM32_CLOCK_BUS_IOP 0x034 +#define STM32_CLOCK_BUS_AHB1 0x038 +#define STM32_CLOCK_BUS_APB1 0x03c +#define STM32_CLOCK_BUS_APB1_2 0x040 + +#define STM32_PERIPH_BUS_MIN STM32_CLOCK_BUS_IOP +#define STM32_PERIPH_BUS_MAX STM32_CLOCK_BUS_APB1_2 + +/** Domain clocks */ +/* RM0490, §5.4.21/22 Clock configuration register (RCC_CCIPRx) */ + +/** Fixed clocks */ +#define STM32_SRC_HSI48 0x001 +#define STM32_SRC_HSE 0x002 +#define STM32_SRC_LSE 0x003 +#define STM32_SRC_LSI 0x004 +/** System clock */ +#define STM32_SRC_SYSCLK 0x005 +/** Peripheral bus clock */ +#define STM32_SRC_PCLK 0x006 + +#define STM32_CLOCK_REG_MASK 0xFFU +#define STM32_CLOCK_REG_SHIFT 0U +#define STM32_CLOCK_SHIFT_MASK 0x1FU +#define STM32_CLOCK_SHIFT_SHIFT 8U +#define STM32_CLOCK_MASK_MASK 0x7U +#define STM32_CLOCK_MASK_SHIFT 13U +#define STM32_CLOCK_VAL_MASK 0x7U +#define STM32_CLOCK_VAL_SHIFT 16U + +/** + * @brief STM32 clock configuration bit field. + * + * - reg (1/2/3) [ 0 : 7 ] + * - shift (0..31) [ 8 : 12 ] + * - mask (0x1, 0x3, 0x7) [ 13 : 15 ] + * - val (0..7) [ 16 : 18 ] + * + * @param reg RCC_CCIPRx register offset + * @param shift Position within RCC_CCIPRx. + * @param mask Mask for the RCC_CCIPRx field. + * @param val Clock value (0, 1, ... 7). + */ +#define STM32_CLOCK(val, mask, shift, reg) \ + ((((reg) & STM32_CLOCK_REG_MASK) << STM32_CLOCK_REG_SHIFT) | \ + (((shift) & STM32_CLOCK_SHIFT_MASK) << STM32_CLOCK_SHIFT_SHIFT) | \ + (((mask) & STM32_CLOCK_MASK_MASK) << STM32_CLOCK_MASK_SHIFT) | \ + (((val) & STM32_CLOCK_VAL_MASK) << STM32_CLOCK_VAL_SHIFT)) + +/** @brief RCC_CCIPR register offset */ +#define CCIPR_REG 0x54 + +/** @brief RCC_CSR1 register offset */ +#define CSR1_REG 0x5C + +/** @brief Device domain clocks selection helpers */ +/** CCIPR devices */ +#define USART1_SEL(val) STM32_CLOCK(val, 3, 0, CCIPR_REG) +#define I2C1_SEL(val) STM32_CLOCK(val, 3, 12, CCIPR_REG) +#define I2C2_I2S1_SEL(val) STM32_CLOCK(val, 3, 14, CCIPR_REG) +#define ADC_SEL(val) STM32_CLOCK(val, 3, 30, CCIPR_REG) +/** CSR1 devices */ +#define RTC_SEL(val) STM32_CLOCK(val, 3, 8, CSR1_REG) +/** Dummy: Add a specificier when no selection is possible */ +#define NO_SEL 0xFF + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_STM32C0_CLOCK_H_ */ From 86e51f69afa4fcf2859e71c38d65e265b309d7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Sun, 26 Feb 2023 16:57:59 +0100 Subject: [PATCH 0204/1906] boards: arm: nucleo_c031c6: Add initial support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add initial support of the Nucleo C031C6 board. Signed-off-by: Benjamin Björnsson --- boards/arm/nucleo_c031c6/Kconfig.board | 8 ++ boards/arm/nucleo_c031c6/Kconfig.defconfig | 11 ++ .../nucleo_c031c6/arduino_r3_connector.dtsi | 38 +++++ boards/arm/nucleo_c031c6/board.cmake | 5 + .../nucleo_c031c6/doc/img/nucleo_c031c6.jpg | Bin 0 -> 57960 bytes boards/arm/nucleo_c031c6/doc/index.rst | 135 ++++++++++++++++++ boards/arm/nucleo_c031c6/nucleo_c031c6.dts | 69 +++++++++ boards/arm/nucleo_c031c6/nucleo_c031c6.yaml | 12 ++ .../arm/nucleo_c031c6/nucleo_c031c6_defconfig | 24 ++++ 9 files changed, 302 insertions(+) create mode 100644 boards/arm/nucleo_c031c6/Kconfig.board create mode 100644 boards/arm/nucleo_c031c6/Kconfig.defconfig create mode 100644 boards/arm/nucleo_c031c6/arduino_r3_connector.dtsi create mode 100644 boards/arm/nucleo_c031c6/board.cmake create mode 100644 boards/arm/nucleo_c031c6/doc/img/nucleo_c031c6.jpg create mode 100644 boards/arm/nucleo_c031c6/doc/index.rst create mode 100644 boards/arm/nucleo_c031c6/nucleo_c031c6.dts create mode 100644 boards/arm/nucleo_c031c6/nucleo_c031c6.yaml create mode 100644 boards/arm/nucleo_c031c6/nucleo_c031c6_defconfig diff --git a/boards/arm/nucleo_c031c6/Kconfig.board b/boards/arm/nucleo_c031c6/Kconfig.board new file mode 100644 index 000000000000..7cc977547553 --- /dev/null +++ b/boards/arm/nucleo_c031c6/Kconfig.board @@ -0,0 +1,8 @@ +# STM32 Nucleo-64 development board with STM32C031C6 MCU configuration + +# Copyright (c) 2023 Benjamin Björnsson +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_NUCLEO_C031C6 + bool "NUCLEO-64 C031C6 Development Board" + depends on SOC_STM32C031XX diff --git a/boards/arm/nucleo_c031c6/Kconfig.defconfig b/boards/arm/nucleo_c031c6/Kconfig.defconfig new file mode 100644 index 000000000000..acaa8c977eb4 --- /dev/null +++ b/boards/arm/nucleo_c031c6/Kconfig.defconfig @@ -0,0 +1,11 @@ +# STM32 Nucleo-64 development board with STM32C031C6 MCU + +# Copyright (c) 2023 Benjamin Björnsson +# SPDX-License-Identifier: Apache-2.0 + +if BOARD_NUCLEO_C031C6 + +config BOARD + default "nucleo_c031c6" + +endif # BOARD_NUCLEO_C031C6 diff --git a/boards/arm/nucleo_c031c6/arduino_r3_connector.dtsi b/boards/arm/nucleo_c031c6/arduino_r3_connector.dtsi new file mode 100644 index 000000000000..aa818d839de2 --- /dev/null +++ b/boards/arm/nucleo_c031c6/arduino_r3_connector.dtsi @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Benjamin Björnsson + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + arduino_header: connector { + compatible = "arduino-header-r3"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <0 0 &gpioa 0 0>, /* A0 */ + <1 0 &gpioa 1 0>, /* A1 */ + <2 0 &gpioa 4 0>, /* A2 */ + <3 0 &gpiob 1 0>, /* A3 */ + <4 0 &gpioa 11 0>, /* A4 */ + <5 0 &gpioa 12 0>, /* A5 */ + <6 0 &gpiob 7 0>, /* D0 */ + <7 0 &gpiob 6 0>, /* D1 */ + <8 0 &gpioa 10 0>, /* D2 */ + <9 0 &gpiob 3 0>, /* D3 */ + <10 0 &gpiob 10 0>, /* D4 */ + <11 0 &gpiob 4 0>, /* D5 */ + <12 0 &gpiob 5 0>, /* D6 */ + <13 0 &gpioa 15 0>, /* D7 */ + <14 0 &gpioa 9 0>, /* D8 */ + <15 0 &gpioc 7 0>, /* D9 */ + <16 0 &gpiob 0 0>, /* D10 */ + <17 0 &gpioa 7 0>, /* D11 */ + <18 0 &gpioa 6 0>, /* D12 */ + <19 0 &gpioa 5 0>, /* D13 */ + <20 0 &gpiob 9 0>, /* D14 */ + <21 0 &gpiob 8 0>; /* D15 */ + }; +}; + +arduino_serial: &usart1 {}; diff --git a/boards/arm/nucleo_c031c6/board.cmake b/boards/arm/nucleo_c031c6/board.cmake new file mode 100644 index 000000000000..d1a6cbfe6f2f --- /dev/null +++ b/boards/arm/nucleo_c031c6/board.cmake @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: Apache-2.0 + +board_runner_args(stm32cubeprogrammer "--port=swd" "--reset-mode=hw") + +include(${ZEPHYR_BASE}/boards/common/stm32cubeprogrammer.board.cmake) diff --git a/boards/arm/nucleo_c031c6/doc/img/nucleo_c031c6.jpg b/boards/arm/nucleo_c031c6/doc/img/nucleo_c031c6.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0f2bc49efa75dc0df92863ce7908f9c7e1250531 GIT binary patch literal 57960 zcma%CLy#s6jBVStZQHhO+n%;<+qUiQ>7KT2+vd0bWp8`fR1Uc$hg2%{@{*`XOGp?U z0s(1?izsO*aS^HgXDe}oAJlJFLTT|6S^WY-6tU z*ngs6P2iow2B^+oed`*R=mO)!6vAILB0jvp&jE;M4Lg2nvlTz}jeQ}%0dxV5zbU7( zXPVy)>V*3N2VYmR9K^*7Rof^EPQU>*SaweW`fneYlY1z`3`zt8<}elYF`-UEmUlK@-* z(4Uq!$*;L_$xT4lPu&C9dca&jCxHJN_VR2FFdyIrpagh+2MpZx1{4Aae|2B(4jAVL zS^}znKYmpKhVKIaK%n3lpdcXi_wH-pmlFU02zCiB{SJL-`lWoYeIvdUq!t(%jsuDS z#lJJZ9lv|;i~ztd0DGVY(DJMMV|mli={O%S4w(BddJdrB%kaMl01?4dfCeDo=k9v| zp!gC10KEU42E4yXe;ES?b|_y)0E%ayKqeS0D=mQPoALjLl9;0vFoSK^DVv*vq#2)q zFgSF41dU@#Kl_)$3byK5IH{xd-NH6mxTi&ijYyN4<&9b!;DD4u-kJ_2UY`DgJyqeR z(JJd-7jvBD*~?&DF5MCeisQ+axwO#8Hxhon#+u9M?wOM5TGsfXge&C>;sMJqd2*L9 zz5RXv;UxkW473@oU33iCHfR#TFC3%j*<<)voTFNtD)@rC^Py~`lJ@$l1au9LE24tg zPS>v{-pP1!x4|h@3;+zcM(NCp3#FOuK^E{>@5L5l=DG3H;R31cX$74qYB7Lu_qfk< z{z$mf8pPmfkKg;fu2kxl5?F-hS|Gm4sg8{y5o$StpuOr1L0#Q)sV#I1B~GNqh~pZn z^qY7ZZW_Uc4j3Nnsmp)!W<0fuX8uSgydJ|rP%~z$+-HeQy9wx|^F0z+(=Ga#(?D%7MA|jl zq+mrmBY`JpZgwP}>#7Stj4G|$#m6JLN81t1U#_b(T+Tb(JooZVv9cI{^KoA5+PGUm z2A}2J;5rIriYn?Z>Xf(=9WM@x$pX_x{zX1LY*o`_31isNei_HjF1qy>u_83)GX-xZ z6{VhlT-5*LoVV}ea7joYu7#3XO^~Stn?i-D6uK4VWZm8-AFxspG(|oue5)6ZYd8V% z$+%c$DfMi_$!}}(519a9>cIDcHkLHwrFeD{T4PKNp2o4^j3{qX5`l<*h1%6B_XNSU?z&0$U$hKS$f^{K75SJ=`o!H4BR)6Wcij?Rr z%0Ib+^tr^k?QDDm;QDa4e=i4_742bRl9H8#q@N*Z!Wj0TtqP%E%ACCUI`WvYq$SRK zZqUd!HmOU9hDqAvsbG|rV(E7a&RM{Z+$FIO{yDI#naIxS`tqsD!*MaMnAM;gg^mH! zZ1#Y}YIFvCe9J0T#$k_qXW=fS{T5J0n9nNr!lSMbxi=ShCrpKF!7*K%QzPxoEP&|K z`1+4798UYINp+{Y0HUwUb~`Q>K>RyqdBpN>GWC)%268YcIIPwxHfcaS{I9h<ft=bdX2`*+MkUc%9OUj(KgA{ib-s)vZSd8r(kHDsEkT{FeT1!d7WM0S&>fkHcB zB^dy{tM81mQyP~LpVtQ_2=ap^xUuT5qRfFuSEJy;uL~j4#82nwmIRs;%lIDQR*|Or zDh~BbAY3ldvo(&< zEqhCGk)(Eu4M{1b9yzARgg1XaRp3I$Nov)D06;EVz6EYW12;dQtnxD{tPr3cqUdm@ zhnm)o-4=@d)1q=&9WQr!mL}R za7Nv8g+L6uSdlRq>K`vdJP>zLyD9UZ;WoQoy`f(pe8ubHHG-ikkNlL3(jc1ELk~wa zxtFF@%_-`Zxii;fJLI#tCK@GOTE7S(^8AWM{5#nTVzX7*a8Yd<`vTjfQr?Iu15hW+ zOxZ(QF&gsvxCcUdd>rz7l6P+z4W_`T&-!g|e+}gnxxzhTe*+k=>^T~inKYjjB3omb zH)G$rf6wc8>lDUTzQH6R+jW@_<=DJ$A{|x*TG1S)gZM-bY!MnZL2v*oJ>ix86;9LN@1x)}@IiVP2VW-2 z3a>Gz?)5lYF(8+)UM|LK;tY9+f8Vq5W&k zK~005n!FB{*G!v}h27)rYYmxL4qJj5`7FO|N zz6|QU6f9QM2p*$8(YqMM+; z<+{rCY=2@9R`*8LyVz+=4>QVjEfXD9@frk|R%1%m1M>qJxDZuhr?(iCU)PXgUpp=)V%LoRzU8k(0;?E5n+!KqS_Ch`Pr6Hwg zPfwVoTvFNSOv5sJqjFAnlT5h7N6a8&j8!}#;n#HFr!TPAAoKVe_l>x*h*1lrT7fyV zNO9`l1dDN^e#{;}M4gf<>a&lC7jhjEkIg4_QP!W|a6O`jpw1iXs$TRr`T6EgcBLyG z1;t|>899VI=Of3rNX$Mj&n=bpPvn@c7PNn1-TIahgoT{D@!lqkAm+jR5@WQkrt#h=>?WvodR@V1(=uwK}&fZGdv>Q^im7OcWhGWdg1C+uHLU~+N&{T1znCHuZto&PkxC4 zV%EYO=SSX~08=>nVfyNjmckupO!>?Ke3a#35hqN1R0oB^G3uHwOltk)D_y#5;+?ai^ zDwqk_iVh945vwglYr7kB-L)Q0oB zE%H|KJK@B?Z?--we?Uy^RXIf8ZV}bD5)}R7QWzcnRKLNNcl29lVu=JVQ+%LZmhS;J|OKVekenWU=_ zaY-5dBth@YQsa|!tLNn_Jd(#kQ?__iApBdaszXqhE92_wGy}@5+vN9-0;2h=O^gZ% z(FE)8xwIc#^`KiPgDVM)6(!g>r;EUSd*H*=WV8=p-rCmN zFZ}aEXEc4P!S+|}GtXyIOCD2O;Uybfu(=MLFkR-$x7qlOJekRsOE{Cn(DF4GN=W47 zd>i#nMg@YoLh=!uus|8WIyb;ux&YE1@S+)|oMt(t%*+i_hMLe0dwq8F01DWHGbFDm zIRB>+A~UYAo2cNz&axl*0V8(-o*d$Mw>_Huk6ai|Kk71`Zd2ab*P(~MX+{hvQ+a-{ z@Dfcd-vD8&Y4ohU|0g>#P~go8ao-8(i1XD=DqxomZsFwYvC;ogZ^32VY-MMBYy1fy zPp>QZnZ;9zR|hTT;nUX0Tl2Fx(3U1B6M!JYS39M{@Gt77ySzK5_7e8E9`qXyNnhu2 zlsj_#D-oYy);pOg1H??3iIH4%ZXgAQSyV!q_}pHzesj#^$I#1%$c&>GB`Gk(6Cc{~ zD^Rwk?Mk`P!gtIdpV#d4nDvB!}wVuO2)pL{lQWfsmj{CiU06mUwG`9TM=pUlFeEzq3dkDxt z=!lnlB{?xtj@?+=*Ia^uZLlEP7yHZ_@mPbBpt(Rwuft*%Or7XkV;Cu<&cY@J(Cc-3 zlU5~^%?|r!uxuaws{v62R2*keELE4l9{6c*ob67A1j=E8jIJF=1wvOHW=3Mlj7t9j z?z|!m{}GoiFF!^Pc~KJNLtDj$Z@RvF!By8tDu|cYek%G_6YWnRdQHJ4TH70=cs4}7 z&S&^ES|Z9F+6@bo`ICkp<-+YLUgZk7>~Rb!fc^R;h)a00EcfOLqRbf6y=h-O>KIWk z_sGpqiAIDXnmdNqG^6AxHuo$n<>mcbb31GKs7n1e7A%5#-ck>9gC#C>y#AZ)o|5$E z_{WLwA1Zk>m@2e*S)+{LQ-}PLyGJU*8DPa@4=#-|+^s{>+AGg7t%}D_b~2xV*qd4U z0u}Bk4(}(^=~`zAVw!gGN2?>xMO9hSUur_sxmCq_=;u#N!C95I5V&8NJq$T&*!u>Gz8YB zusIkyMWZ5wN2%kl%!+O_a+LW;zSo{v8TsFyqb{{=PHK zEr+saVl12xOV%f?TlGgZ9b4TD}1YSxQ|$JcW=V~D?gW+= z!$3QM*vNhtf8}uk z%v^|9tt%Bm#(KVG@VJ8fv{UNh>+WY}uTr4a!>@?mR+@4!A!{;KiiDPQUQO=Kz@a{V zC3b9NLjke+q+UKYc%YlDp?0+LA29PcI#Av6(?wWlN|g*&_zxj(d;j0MxexRU$TK^-5l=q%f&~#&N+$xyq>dZywwNxg{OtCyuT~nAnPyl;lls?s z2D#ABsf15uEiX`rcf+l=2DnYk#WmeI#P2E_%Vh1IB~=)81d9rr_s#yhO$JZYF=hN! zsD9tSD#l^d(v8Bib>17uO@&oc=(l_Mg?BB@X5Z*Y?Y<@6;B07b8#a2AKla5plU5(l zI+JoWGa2mr?Nc0}DddnwbgGN@b*`Jvz3sL0u{K}nYgK(QI6{Itz#CR*BVB^G8)>5 z*FbQui0iaL?%&q#`R`h9{IG}&ox&1D$hBC`qiKX@hmHHZ`sUO;tf7MpV0e%lrYkPK zs39F!sjy&LQS`tW(J?2ecnsagAub222TG2Fy9g9^6S@AAT|hL*H19YLm8=z}Ol5d^II0l33P87?t-={sN$(SRA&q?v;PMo8jx^&+!H04PVtJlEku`rr<;9 zaoMAD=o!D`>(KSt;!iUSL3O)u%+flzX!&#E4|W3Q+?%ZTmbTSAh{%{_B>r&w{G3Wj zV^hjZf^sh@O{+c=OfJ}fE`(lvLZxw6kF*jlI=Q^lqGW%h!;&pNLoY|K8rqma0k zo-#O0wr{I2U(hk)^rRGZy$?U^LQOlJRXSK(+v*WlIamcjBwU)PYr9fL*B{52kl>r= z5vrKgfn#`0fn}W#!uJD{0~+~G;0z=O(|w>U)9Fje6xXKKk|9dG!DcK_G-tYLD-<>n zDbBY%pQ|vVYbgF(#T7^X=7fY`MNP4$mVP;?=nh{V{G|{TVoM*nQ(b5Et1j#E4hY;( z9!$%GF>{o~XR!e2JEOs?5tc5hWd z#XNSiAw2f~W%Iphqj6#K7if3$fd~ZWq1ui*1V9l`COq`5%J2sSaGod!6LStHkIj}N z?uVznRKpQN!Dr-A?jG)_am^HDWzPel8JV9XPeF{AGxuZ#rZUZ;Uh8YZ4MVXEb{pSO zhgWN*Jb%-4`Nb0alo3{@H5e!LB?dNEHFZzp+XZm^(?Ldn6=yraU?L$2B(K-Y_@rnF zgw5ZX5&i2RxPN~HB2Ki1uXd`ZwxD7FH>~z)lyT2_5SG?7RUk1txy{a_2RSyit|CpT zej>g!RjvSI?|Fp5mjm#@@(GaZL|J}U->8B_ms3-!Su@nPt$JA!2fnzj$`RbPIf#@B z(F|vfT)@f`f}rU6OWyX-`Xm;qgE{rh6bak6bcwi`sYrn)h>(pfZ}C2taFC;J{W9y& zH7f_}IilLeZS1qEc}9~3kPhpuP07#a&&d-fTG^j_YRH9@2lzPJ+cn=jE&ww^mAqLHD;enwsVBO>ghVYxeA2We$)36#6cl*V90OhRWsl$UB1J%uKMd(B#RR7+I%`#lz75?QDKyqEz=!PiW zSs!B{)5tcF8b~=53F$d%(K%K}R1b)JUJuait0H|ah`W@4pG!DZ`Xfnec{)uXb6=dFBtDZ+xcZ7<~ilkBk9oR zjp_uFo}*<2jm~Si*EE-U zF-j8I+NU=`agc3_tHCX`w6Hek=rht~_2nmFmXP;No8izUi1Eh155lntM4zz+ z3Cdi>@p-%dPq_t7jO_+Hui^M8TKcE~m%)Ot0zRp!sHD6=ue=WX ze*{WY_D-tu>nQL}nV;6c(zV*na&1qcF5OT&9=fMuApy>Eeh2*Aw9w#&F=@A3{ARU+ z@>C#MUNsIXszBqxn5T0vmOx+vaUYSZ%}GTN1M{?yVFGft*GRo9*Z8U$?Jn9zj$J2i zYYRBO61<@8ntJhHeudZK>c?WYuPt{6p^l$EAa!|lG~wCuU6~5Ra8!)&#+|LHX~V=t zeM+@SQ8V+k|P~IU)c+zPI}1qj>F6zOp@*QAL$7D^) zS1%{~#!N{{?}E}sO0|&>dS^`-e1|`OZ9uR@F~;)4w+9E%_6i0tLRT~<=p*ZP`IUk> zQ8W)U&AmKflgjRnSt!yh<$NX`HHqGBjiM*G?~-N|j2W2G?3oO>IXlC=-BeV%sT zG1`9tC=H1At)*cp#3H9$DQyhF_g;EG`8+UxTBq>5ig}&*D>iO%i7F>F z6okef8TW>0Oq)(5$-~cN$pR99-VPZ~!TMLc-A{X&9HoGnOG01*fiQp@(vb6bZWhoG zjznwUH7o<^ff~(Gifse?R3)F5a9Gg*a~m+z?mZ(vio`eWIS9cu=*{hSw@6M z<6)n&t$Fjf4vf*=GU>B?v#wAkDXG*U`+)fB6#P4u3*=ZXnsBkXao8?-@(L8Gp>07K z1UDo7pfTdTL%P9-$GzQNrSU?`85#i2rX1bkN$%F+*H_mEUC4m%X8~ZlZ=9&ORR){D z{q%}5Si!VebZV#GfPdT&8B1yM#zFrimZ}TBs%>}SX1VEJkA~~lfc2+vIobT-{(D6F z2SvNyOeT4u8@Lx#K?X70l>kaZOZ(Xm(Di(CedgM|F}x{Xl`C;9b#9gi>dD{T6=bAi zy1;#LGFJjVMkVhrYPta>9^~L#A;BE?sOvd_5VC8hMQ;Z$&rS;Wyrfr_*LZ`}zz~(t zke|`NazlIeslTWP*f}D-!cauP%vdZ2x}Da@vHNeRL-{Y)3OxJ+r^|08oyp*in?v7@ z3Xui*HF=8S{HP#zmygkv8BcP)T~QE&3Q`arYzOVppHdX!ZH>3}8Y6ECS0ur!c=c6rsBjiQoba6Ohz<&#EGk%Dk5ae78KTIf1osAz)jY=8C9yCzY09 zvUZBm;BtI6^k#hw%1Jc(K3IWJbe=h2CaUS^6(gnWKw<`g(`&jHQ)(@}Bzm<`^>$xfhUmeE zlI|Sj?T)t!ZK{gqwddxcaFBe*EF<1{ru$uy0`BAl96!oI>2gyndUN5r0S+Nf2FV z!poL?>7+#ROb;X|+@|Uxfmf6vvs7jcs|D1bUgaBFQx}^TRrH75ZeTq~fr47eE^~rd z>REoUL=(~)P4G{&9}|iSuY7GSlZFFTSho}Sny_UAAu~LdkQ}zyxQfUn-BIhjjaV4m zEsYHvHb8tNO>89|9K{|ei5JiGwCue>VX_}-(pW>j6!qc#(*|S7mLecjWDNCyBuDsF zx$X?(u^zQdkQrY$XAn#q(7eBjVNiFIZa`%%H;T}DJ|Rr1At~HX5h%X?euE_-GjuI| zp21K?Q(mw0@=I-AAW8JtXd2Ulj6dZ*D#%`iD4reIr4!pycciomgs;vi6mQU^lI+_G z?m&|BIVeJq;^G+E9=684dLXzdGY%8YuGzW@ktAu~v#G)Ha4Xxh1Iu&w8>5uKI~-z3 z4|q#WCO{7&KccuxGrDa*!m&nqYt$$$n7jqL__q`);0Wz@$zt1w9Z_LOA9dq@#Ad@F-UCL%Mkivj zCJ$ZKQLc(q>k7IE119+;rnH+h*rpx}rY zA7gar0ZuUu6B=knGc%ZG5|-oHZDJBukmn)$_Y`YYDd(d{7BKaYHyNUYPQ*JFw53hiLS zgIF;y|&j;vp&Ps4k5)>wOO~1fMWNoT7SIQ^^oUC}Jdw!MouHX>Sl&90kk2dCQ z8N7W2+k}>3ph8=W`ytw_G9Mhh;e4B_|FL8PmVK^*YwC3mY{@G=36mIQLxmAF{nOXP z!0rqm*E@H^BJ8jsh4!h5SJ)<66~r61;`oCYci|}0r)M*`g8$IM|6BFZfAY%RVewft zx)X99oKbz>QqeGYoUG?etZy80zs;V`yviE56hyhVK+uH~o^~MNj>b@gX`1Qg)tfCh z3{-8qi=YD;B$1N~9g>p9IxQCycMe~>W<#r42~pW3M*MBW-!dCP;}uWyl{cQ1U+Yn* ztg#$gxF(!|&qr(zTLVMJe}=sL*^Ov?2FW+YgL=AUx>}TP*mm1$X`V7fbP(_6vpM1@ z@DM6J-MOXUlZYHlO>)TB$d_C(+npGYw2VQi!*ZASp`N7(#>8RIWmk?(VUfE6GS0OT z5*#oZ+b#)E^3{p(2FG0@*4^1WJkp+*$sD(RfK0Ur3bcZc_C7rjC~n9Mie!^~-#w;V zlS|i(2^6@b%K3g{*I#Cjnm*|KcdJdX4Jhi%Z+W)icV_uxmSUiMI*y?!9+cvjAS@uJ z`QTJ6Ys&+Ux-`P>87_xpkk4(}+MU%18Yf#p$xGp}mry`c9>h+eG*iwJ5`E+CKJ{Oh zF9!N4!)a>>SIUks7Ee$^!!_AH+qebA>9OhjVnVliI?L$nT#8l&as5R>u+hhpaIR9> zqB_t4V2MOM_2jGM$40lBN2z+o}gLa5&rF47qx$2nB^_+h9Am&CrN)qMLDe(j@W-P=J%PF%*^nLtMg2jKHT%z zNXS4EMtK5}HxYVGJzP3#3kWtFi&Pbhg<)ZrkHxz!bDc_;ojPvC|GjPiB-{x<7tK2) z6~qv)CI5s63k33TiaH&DKE+LSC^TSfnXJACLN~~tx)Y+iMDQepc_%U;L9yV{<2quN zH8SL1nP}L>(Vu79`Mi5heCy;eZKrir&MC9Y4ZHdWfkYp5d%1Ws&*{1S&9Hy>I*sc) zj;w@s#S^XtYRDkUZae}V`J3j&<3joF@QpMa2Z?&=`~5vx@qp4Z#(XR!FkwS z0vZ*^|8{h&r-)_F9p=ERM%shzMIC6BvgM*r`c48=*MuFegz;hn+FRLu?jG<{1rmxD z>i1bA9odjY3zUc3Gs^Q|0b?BID`e+pxgfkRJUJRgUw_6Gwt|n;J7m*K;D}0JHgLbq zf~^@YJwyINfNF;0do-=QKR?UgeO>O)xo{sfi%n)&#CW6bu-1YNk)yVq;e;R}P(vGz#xjF5cmLdqU6{8vp?o;NSh?=eQJ$<$u^iLsTkPDfgXu_lq`(bC?)-cknyOlKq^cX@$S@ zK#T4mqu^#*ZWg(i@QHK+=@Z{``rjc(6qWbNr`2f*#e<^q&8am`O_;SVH@T*(PzN1X z0ctcm-tAy@oacv`9z_8F)*EQC?2v_SO(!G8{EepP!lJZYDa#i+GrlaKJSp-M3$!C$k*pvAQmlJ#TzHH>X$QR^L)_pbQ z7lcfTlt^rW(AnH8V}mFPTxY~iK|m;pj>|$7WKdcdi8gCHudkiMySP!vDL!UdyNQdf zo|liU=!47QZ`zG__lXcT@}vg}3KWgt-r@F}4#YKNlrcL8*ZJ2;Xr=@*A@zJmuZ9qr z^K;ZCH7g>mn*I~{01uHGkCqEzo5duO|BSfAhNM&BblL{ssg!t8%4P2?JlnX{xINZ<02OZ z!a!hc`*M_!p@6YXPG}W@%sT{;5uC(&S>C4cQplAGA3bE?eu_Ob9iR2!o^O*T^{Q!|uJW$gDE}m#;8~=!PI2 z^>saQc8f>JqGfr;WwZsPGpiPAx#tU_18OPZ+^Px_KWj^SHu(9?fPtl%T{KtFX;K*bL82<&n~88A%b7(*`5DDvcWO@P*NY9MG*-PiaI z_)Ow>H_(h|XB}F;f%7PQ&qF2VsXzDDSc7iwvE72#LH0vYnm6`sj4<7851^zBs4~F` z3qBJd-A&D>VbLZt2=fG0QeTLLv21s2CjCt0=jhlE9}noi`+KdB*AZP2ybCvyYS~Xa zBc4b0m+6^D`{a+KZ@x1LOw9_o9Nv1_%3P(Z>Z!Qzu^4qph(m=4l>62)YctoJ8oa% z{jXXq(<5OXgSw2O25%*{)ZMK7?-ReCfu{g^VLOI~yNIg?ec{J~<~{rmI~!t^zJCR@ zU}@mv=@#d@GG09q1dA8(Aidu++`{8S^s1+hQVZ>rllY=<7XjLlGs({c+blZW?3p36 z*5scgS7_NlKFVV^b;MEEOst;+T6E%Bb62`XD2u2n0kxOP&m`Q}0`>Z$9yx>mxO=<{ zcPi9#Xlg)~-jMa$!xblg=H)`Xe&BRSqgj?3Lv*b52M}8Queb=1UUozbU?J2=SRqtW zrU-j*_n?OcTY>ji1xOX~HV3|bKJ2sIwm!hiSg34)3+_fqw(AUCB}HOx`gV`rq?A*E z?qJ_=Nr9sF_s{wJu{zKAsTviQB;%jPke@O9tmL~GPZ-WD627zw?4mue_119QgkI`= zQA;gb+=S*_k_-8MPf71Jo$uf9fcmGYb6F6?X(qh3v_3eGl)Bw;RQDe)PV zioOsFz;bNv^T$6i$g>3uf=vz1Je;a@0mecay3Ygf6M9`FX)%9-n^obI`Vnp}2-ra9DygCxVM12i31oap z&@nChSACBmppa;o*{6RhaXX?M=L1{#&^c(qs{uw2mmPEX>XE2bt&;|CXTkM-W3yiU z{N{Nh)&}HuA?%fUX@e% zsO&pDO16KnPJYwY>1*43(ok3W0pr;KY_QQDbIOc?S!NIFLA+~KC?>R8T}Y#unl8zz zRqMpPA+f~moihG^oiBg=cROmSnIWGys(Y;uOtywIEHGa^eeYD?A$!4RBs5yf>R>={ zFqq?P{*r-o(G4VL$j`3``m-AcNTb78qwNLFI)60!Xl}p?SPz>aS#MH09aai0f0s z8S^n(1QsO2z1z&kRSZQFAeAI}F$h>zE7I7vq>BvW`eUxin&)f8!=(ifKbrbzYNklw zH7G?O;i1xv;Aj}B7^D^pHIF2^tS^UsR;=b+f1I3Z=826UM7PZ zCthAi*fFXreo#jr75{O50dZ4v&73cO&5OMi^wK~%?<4OwS!z83RLd(bZ||NkbYg;p zxTjUspWtQ=GII3)k}3;iIs~}4ISC`RJRB0abQF<-6``!IU{l{FKc|4gOSmy5T8@V} zk$^oyqt@JQsdwgP=}6!NdW|d>URjU}4@63JKAYtvBAsjAcg__cDdp-Lo0deuG75Nj zpBRqN`u%yIXrrB%ksL}nqcc`X_DxWn8^-qkrQez?kS-L-v*cQNJx_1tfwB?+p`1dB z(JawwNoatfGQE93FBR{hlvqTH(z?^MAW+rUR7#7h^6POK0E-V)$I}Z5-uhN0k2n4* z_$;E#1mf8*jAbBMr7?vc7c{NWE0-<|EDo+&*)$$K;8oBE&U|(tn8xH00egjcox1dh zsPi-H7UYpqxkO3-trO355vmA+*h5eW39#mG+9Xwf~~ zz%k-Wz3Z+ogaS7dWG*N5=}qXMir5|)2%c8j*Wu9}wQZ%U_R5aOXcbxY-4udNtPo@p_ zKWSbD7<8>i)*cII5F@y=ubOp`ziMh4zP&5u&d4W1hpn>qnbNkl_Aa9kx+&N2C`Hh} zEH>k#wCD;!$n|8N8Hp9r;ozKcO0RXEX8)pnA(%20&pDO}9QGzR@rc8ITj5B3`E-*h zh)$M2%6EI5^jsRG0)BvX{gpN{e(Px;(bs&`?^IM9EuFd8IS``AfMn{`mVv%}qt{Mj z-BzoLk}aS&4Wm2J2dWs5fyta{soCqx7eKxCT&4+)RPIrB>OevHrnQR#>)eqVsTr)c zi$=Oq4L2Rnisc&n4Mp|^eC-?k6AgiMsL%$v^!LK<37OESMZqd(s1kb)r`nkOc6n2^NxGv30>^Yt+sPeVL7tad(5$yqo_1~oeq+%l67V4uVz$uo93;lF zK7lQeaA$sn^goS3OTH3DJ1}c&dWS~O0lnPd%Pi%&ZXbvfIY5DB8(@WDc8hFmWWx$w;@|59;-ysKi zfJkK;Yh||ef+f)~a+$;>Cj{Oh$h}KcYANpH@jaY!6!o5FUIu-v11L*nQieRAr0>lv zt@Z)S6J6H0)RA5BEl4<*fnbiphq5>}EH1NdwO$8#6 zCU4-9z`Z7~H9kTHvncs1bTf?FS8PN#AIq&b5VDTOis@l(f?v|q1Dmx|QBEBiFEh{^zRSgLz526IKU@@?3sv=pOPZ-E*Y!7Si z;hlfjF+4&@IB%k2YaD+RYnW&InGd$|L!{$vZzyBdp%<;>s`9N8%r1o1a=?|I{K)r` zHIfH`rw}xi)+w$&+0q6X=Rces(6%o_g_LM^6UnbJHgl+rask|7{27}_aozZe-&lWd z+yp7i%hb*DjT9vwr!EoA*oVo_nSnfq8^lc<5HlQsc3Ho2-&%6-c=(RUY2@@%*<&68 zW4ch^2ScAFe<1BmUap zAvYzi0IcXh6z9U`o>9}#fQ3t*K}yG%)3&kSS*uvuDoVSrqCwr+EA;n6^n&yn!#84t zDxcVyI-pu`tC4HEpYAxpVvDx~=-2#{D%Src^b-078z3>PJ8Qp^j_YI&Fb!L)C``Bw z(I50Xq2IGw^(i#ZBT?PbOwSQA8a~M3Qsm)#6wPMB;n{=}%wfM%0dApi6_VI~-I+CJ zpqrZZ0`%d3v0iXU%7E3^5!a>Fn|A5EQ7yxuRmF21tqcfQ=n7W2%)6 zD+e}p+GYUEN7y+8X@eR(=bMV@nzasu_yk1GqX{=E0Ev<-0jF)d+Og?0(Py4gi%ekG zrMLikBpx4p$=Z#U^}&X>lzFvrp8RY+w<0-=>+!sPWm5NS^pKQdlRdiB{3Fn*w79=f zMQ(RUr84j|sNDZ{qL~Bu1Avsgd3SSs>EW~tCY&>$(mI!*s~XjJGh9yR3oxxM$jp3^ z98vCb1`6XbE~k0x8@$`{>>v?!e{!{Q+y~}-1lH)58U=C2J-Ty)O*7-T@!24R!6XXN zPtqoYSII=nlvbQygnh1T8d$a?rA3$X2V}{B#~51T>(dF50$f2V8fgg|ng>zMTV0!i z7t+mNv2FRal`C?sAmv0t|0IWpas~$ei~U4dv0OD3cx@xK6LT%RVsusa##BaL1&u3W zzrWHb-+Nr*ZqMs|vXr6lLjoUU?!v-ZCKec1g$Z?;?ssFjg?}T$XTGnVSM}VeC=FDm zYWHlNuaLVO^k2r^K@?(K>jDmOwzqMvHzpEME6ATA_^C1L$SKsQ=xt~)*><#k8=WAD z^WYffi1P?Vm;EDDIYm@oR+}X``VQUFRksx3+P5vzA*JeygEs*lBH^i0+1z`V*93HE z39*=@QF^A!yAqlkXv39R`84jSY){xY&M8+ND59Gdm`ZR*+iCyTwpk9hRt zM;PBgmroN~B#_(SCaA-v)23^$(n^#*%rR^kf=z%QC)06jV4QF1Ppp9+6Weog0L`xg zf`K9=^vk3LWXf0mONI&~CU>*I2*}=Urf2lXRSDH9Pp{rc#lT;&RGWI9?;fJz?CC`* zP_^=}7zIJ7Hr%SIgAC^=o?j}GX;YdT%7TAJ?6rA2MJr_1km1kleA|x=qoO5ww4x=& z>~&buhL}(1lGhh!FRVotu$*4r)9?2;(Y`^jpw(-q_#biYj|C8IMtYj2`HxXRsYiCT zykEFh;dl(mAeXk8{Yzs}=-%YCL?86xuL)F4fJ76E=K25rf3)RSvZ}0aL6y=rq;W2S zfwg2KHOS?p=pVt2&?RlIf%7K1>f;SpVlvezG>xe06I*bEK1%+ayP6o;Y-iQ<_n z@K)IdI(}wD4C14u@;WJ$-hbl!mY116#C`hoAx)$OHG*{1<%YjE-)KOP%xgeR)CH2B z0&a$NmZ)hx0ClECj+ZWZ33WU7yxDnU=zAQN@Q5F7moU{Yev(HKN?Z$|9ta?i#%&7&o5VbRc*_~8~Ek8M$(r^|u5`>;=ToB9i!Cri4*AlyW3hssh z=8YQ|30DNiD%z!MM(~lli%CJ~u?CnkN|X0R#E$CmWNl&jC79$qn`by>I7yQJ$rXsz z@_mclrX#Tqar;r$=ZS}bPe^f^i4hR9dPp)F7H0kfsMbw=&incOjbvr_CyBlYl)e-W zTA2!*T8Hxj(B!?ygrNgipBFOYP(cibj{=kOJCH;!3Z?`qQ$D_yC~-@wL?e{VEYY;w zhoexZ^T_YIv()IR0j-?e#Gy%juq6_8Dm%1&hDf*?jp} z_mhw37?M{itS(FITr^N)p~+{i7~;OVOUt<2HUb^f15hhY$c{|c-inz&fSOOQrSHYS zLqVqLplnP5v0_1Wct|;D(Dfv9bHGvIv3(67GEwZE3$BQD|^X` zbbvd2Z5s-C0>K)->b{T;Cj@DrL8)TV99tBBAy(hb7!tOmgx1~iF37<;^^Y1Ocj{~4 z5D9#ac;oU5Oc25Y`pcgMsWFE#y>9MpO}E#j>?zeMyxYd_9?+_$UxBrmJ)IFy|sAiU;rPUl@Q`fZz{C-ek zV(W~sk1CCoS4xMj(6Cg_C|ba?c|Lp~NZ|u*sIDC>X(d9@ns%<7evUN34~Hz(TnE32 zcTukL20&CVieHt51t95W`?Xx_Wc~%Hz_#2fh}A_s0;C*e-|?c-X8cQg?N+Gky!N`iYgFo!NhsX_s?+9vzPRw2in+?-<#nkBFUlgeg$~f|-B)sNPCVrFt zrswvy_#N{ZTpR?a=>>i4)t6n>P!(BE$`{Qfxh8uD#Zq2kt+^r}WfqtI4*)Gd(!beJ zKAyrP`0<-$AN<(QXmmC#aGfiksUY4E1Wem>1RPbQH3_N_mfbm22$wyC)0|Y2%(8koE0FFY?)IO{vGaf9W-Krj)oO-7hwu)N{?r>oYm9k@Z}i8MBc}BMkV_E*KQD z4I)#L$^Q@VV7h%BNV>)w_mz%MC~M~mFhI*BJu^U~fyxF)Ae_r$vMd?O!(|>~vCn|- zGDd<08|>UGEFqT4AIjV@+eOKb>f;utv7T6o+n}q%w&&=o6k2-y8ephV2K5E_Ym1mvxNSlVG3Y_n7+P}bH(#fEd z1*DUIGmNv=vVvlyf2h9`RIyxR->KU|kEiTn7 zwW8ZZo6RIHjm`u=V+UjB=oJzQZk5T`sXj`e#6L32ib2Al~BR1JOZ(yu<>s5q(ctb!`}2g5uq zJHf^Bs_M(`&}TSt>m_i(#m6Od8sK>OibNGX@A}v)zRsT&Es+jo2N7v07QTU?%uVm6 zgNCG-79?wBCU69scdxtGOJQMFmL`42$ZUC_%&IjB9#-_d;q918_Y#%isGyeTh@QpJU->h zIsEb&9ZB2rVTcmRxLez-;5}tzxj)?pUnjZauxu@uy$IE*W(<3Y84OV``S^%CCFIm7NEhR$ zbdjXEej-;ak#LTq(hlyt#1`MApyn4qzSi>kq z`^1gh3aRyx6o`8|liWXi7Rn;Y`VsscKAYJas38Msmi^I~sLe?3sV+b1#1YgZXmI&a zjVhgi4}&cvfH^Yzm0r+>?iz#Y%j7fb9^{ffNyY=+H}uXFeIIw>kun|1iUc7Tcf3U; z-{^f4<4T|9t@Y15sgo;Ck~Dr*YX7}_sNW;flbStZC!&`zzyT9_AZG1s_C2Yl~; zzFcbGUd(qyk@Fwm4G=xM*)!2Xnk2Nr1m9dbUe7~?qc-e-v8L7F6CcRozxc(|lMQd9 zL0IGkn)w77zaoA?YkCY{Clz80Lro1r-f{Rz;VJZ`#ngCX0mKmlC?)0K4pMReTv87R z-q16o&AUGav|G>sREJo_)OP}vUFPw#PzFeIjCc&k>m5a_Ox>QlZH*kVKWyz=ZG<}C zwe(@~BoDYqY6!PnKC)^lbA&K~J`1e@p?&Z#EGL2P0d7+N48lJKG6%Ttq0nzyvP7eO zC;)$Z@t(5u$XoZ6Sj;0XWWI;8CLa^1Y;NbHW%0#~m$$b;I0oOV#}= zSTZGsL%+K%t>eTP>f$}$Ac~t*9U^y~yUs!`|trAf>`UoQz z<^24L;RT~X@4qDM3EP9bMNq2LkL1<#-{ph&eqEK1_Qkfn@}76uAD{nB+1Ygs(cY7P(ijl^#}5U*?=gF#wJD3#oL|{%cDP3@ zd#}T|J_Qn*lWUhs zq17%+`H3y#V=9WJ`j@E$&K9J&e$#yXkP8887;hOoCiw-&%sk0^=NzL*{T9|OAl-zy2h}jvj|L!K z@c2<%BcgFvz*-^2v0*@SEO=pr#6p|3PEy#g;zX0SEviNFIn9-h#>aDq=S63Urb0Jv zC6eJ&NRFv7bMMF=&k;2XzGloLMlpL-!u2-~poq~s3?@W-s>>!?R|)Lg()HnS1%xp! zuWWQBH3>n}D&T~J6WDDq9cpX!p@Y{Rm(QOoVESeVN#do&WQ$g!7vA&hwkyWaMe`^( z3bkCdsnEc_q;=(KuTwtFTy>hu_5B zT@n~Yq-;aSMwlpCy}o2kSn@4sGX#7wu*+M3!St9s5e@5m4E^5NjNZN4E%|ZEAs%Ak z|I~Ecys=Ywl$)R3h@gmmIJFiev?yXcz()tSyNyEqG`JgYDr^0md2hv?ifakx2BD*u zl9aoAJiMtCCe$6&Px1^=&lk`8wHH^Dwk%k5#lVHh6XOXfD3%&N3KAQU z-zN(uuDC!j##r2uFELcxQP3|>F+2)JdFZ(jPLsT&ZkEQyU`S7&ydf#il(eZ`CST`B zF-?wP6mK;9mT0k@WA0m9GKyiIcbYMg1jmcC@4!lFJ)>Wj#UVnX;>tcMV{p#B4TM@yxrAYUs}b39Ka(X5unUMf zWT?~31Tp)A4M5Lx|K!pT>Z3DQuwe8Qi68%@qC63vM}$*HRYxHU2yFcN?R7;=Wn1=Vjy7PGIo z>2;&Qc4CRsVs)GQt(%tP0o@oZq_aUM#>lN}`v5ge9i=v-Y?yV~y<^<^vJTK!3**YO zv^aLIv;Nf81oi&i4!&a-M(Wee2-AO*HeeHYz6N~MAaNrTP@s^@Ceg*gtG2@&xZfPn zb#VIAXYx&thYNyD+3X8@#njv=^Z__)mfvK-_cij=b{ghV!1+s-;6OGbzG6)3zFdS7 zu=~yH8YnmRSxydI@h5?at3Ku`C3fcGCB%V&7OH9m4pX4H0rh8?AazOG;N#VK8Gv+q zYW&<=7&A|j1Azv}=FpC4+fhr~x~P#^hC3FFIL2ge-y3a>XL-w+$=f9k+d5g$W%{9; z=qr}+Z{;ssoPouRPpM0N3}w&oTa^x?>OK(j2g6W5y%V{1tEvIscZ`0 zc~YO6FKEOW7u#YA*Djyk!EGLyaf_!>_Os{qq}rhVCvApC^|5!5(xcJ1@4cUJJ%aup z!a)l2Re}R*{K_N++5A1OYI3v(DiOL)Tk!J&YbG5u<&b?|@j*n1Nj@YNolHePKyp>EU0IZ61H zs=UgSEj=^-4fS3;t7p-%_E;27r+)PM|J>G#xr!mIv^rx(fY9ikW2)C~Q72iYq0F9P zAo&HG%U@4An}_7#DVc`08V%ia)b02E9g0<*LfNb!EN2<5sbA~wJZF5%XWBfnp^waybg?yo^>Y{icjKbQ%K-!*xX^3q&5DJ2Gg zdkI>`0)}h+#}TUWbIi~Z^e_%oE@JVoSO7alq*W&etb5~r;LF$|n!HtyZXFCMKI2=Z zNwG2#(!8nMAXdOU;8VSG@XaDL0s*M{h4j&Iix80fPL$GfU}c;&|o^?yMojnC3;FF@c>(NdVPv_rn-1A1SH_BRz*hG{fLLB;}f!1fWyhm;vLm7>SGB?#kVvoCc%#tZtndsgy66c7l$k483 za=I`&^`7TF8@LX_<+R>{`nK^%vB!7(5Hd8$wmelt&LsAK-CH~WfX+13fMO<>^=bQ2 z;Up7m(ilYE!n@&yLC1-;cXH6zg_TVAWT^x5hoe!Q_tqm|4W2E7x$5qp~dM)Bamp#6NR@G58e;F}d5>@J1?~hibc_F$(3BkAT?g zs-B1~W;4!!2RL@p4uDuDC(_$7N{E5H7wbcv$FNUbSZ}uD;Y{oXRIm-`x?rb^#+cTN zO4dIr#`kBs>^3B$nhF{witcc`n5nlwuVo39@zD?HW0UC7hpK4sW!v);m(G=0 z(L~RDF<9cVZw@0>U_r_bvPoE3do9X@W{v_Isi`ZjIMrEWbifgZgrjp9(@Nl*^Yn!$ zr+bv41gT|XkMCIguJW#mAOI>M_!qrXD>~h!bP2+GxbFzMs3{@F{{P;d?k(Gx8BuJN zyeA~0DLU@CcPX8}iqh6`E6jMa}5>7%^k+1a(x z99coWb%IN<4fnW9#{%|UNCBj#Q{~9Vq%*qUF9&tIIDT#nI2I4$Pc@gj7*I?yUJF(q ze@|!P?H$gZN+!y&;+9NV;J^DW#ArLoO-uAQx++1kCo=^0TLjp~Y2%Mu7@!3v6-_ud zp_p&hX}+{gn9(_jQF#}{0@V)8O-t4y-X11q-AH|2pOgH}AKUEQrsYuG`&KgTY+fXN zHKY=C6-CJUYmdM{6-C3IeSqQmLB(1ce8d z1Ob(ln^?lz)+;e)`)+=YrsSwVx|`10xvpu5HwL7MYYY=$SscB&hso1J_~QE!u!a-dGWLBu_7Yd5v*Q`b1+oXcX>Ca;#brY=_sNI=ZpT>Nb6KhCf-eT(6L!1R>( zzzijhj8+?8C>IBc2I&fYl2VmBK}iAMvWK9;fqYxQ_WPlJzaj79V3Hz7XZPCe7D2z!I|!j;#?jNc zPE;x1nJ=H;QVujt<$J|9)%<0eYtA8b%QuU)T& zcld>zb?gh&4xytt!5CTt@i~=SVyY;{S5&VO+krz{m$Nvw8Z+-+U6mlD5pk{*ynw2HRCU`59hFT~WdX|fDLi!`#lc)xQEZMoXWNzUz6QoB6% z!z|?U_vwVjwb{DB_7APvz`BDO{EQE*-w-!;uO;)9chMKrbphDEVBC^`zrUm|dbB<} z_G!$=)zNqsdMRZ~vzGHM@3EFDj~~{v4e!2-W?)S8r9g`V(}?EK4>A0wYW4JYpg0A4 zG=SW8Rlut~02=<)2t*{IDgx1G$byEEnP-<)zJq#cI6so)JB@Lq1VvXG%c?c-3J3l` zlGxpVGud^(+sl{5dAt;)(Ead{(jaiBkGbZ$SA#pK`d1{l??J|I0v$bMMbimb)dSs9 z6J|Pwd+L!jE%$E(D~E-@Lgr*9p$IvIFCOg{VXh^tWIe|J(?!d1=+Wk0%s<~_Px>+XO;`_Qw8O}m85Z`+DRD(fEjn7FcCm^ z>P-{E908B+aA1AW!o%{#|1AmGHlw$>uo=P};9&5G`?DlIV{j|ld1k8oWBlX?Ok&Ks5S)Kb-m!U5S{5W6kZT5L$|f>wiD0s5ZTVYZT6QL_g{+oQ}FsK6qW zZ-~=q4SdPvk4Zj}6A0W`!FT?Ws+4&WOS4~R1 zh%(9MU`P)b1S|!scCa=M#L^8NI0O7gRd3|FF{9%=_khp6ku_XXmUf;ZEF~kaF21{@ zTP|5;p-#{=QzGXz%#%-C4U!waXAtu47%&5i@i}&OIPQ0y1KvCFH{SJA1z-MRy|6}k z`5j11tjEuULYe7l@o6Wa=jhXTU;>%t!&6E=a@^JCZNvXl-OYzcB5w2^^kdgVk&ZU- zh({1=;R7JiBkHMuCdSn*Ayq0&Sr>a#%#L2Ez8w%)-RVulPocP5i%%&?ppN8iOg;WL zP;(S1WTiRo7iyCgHocBQhy?STiNIgs#cqP$A20gVTf3CKiPXRK{h!iblufYwEn|UI z^yjIN8|bdW>DFiuY-K)La>EZGduGkuW5-$~C+xy_P;Q!hxpA|HkFJzq7G4J0esM;f zgQ#LpX6M|E;_dodx{EBgoIPX&Gh;bLGZJa1fE3E$R;scq=kA7{;S}`=&F=DU06I<( z^KfZW?eCqS4UQB=ZW-+Vw2#o1DO!nQJJmKBIVc&~Dr*h!ooa%$g|sk`{C^OKlA_@x z|4T~qwQB$FW4i6U#~q<`@<7%pEr5t`Ei4g&tBercxIhSgL3$HoaH32u)U1%CK*`V$ z5w!u`oqeBY!uCoc!zG(|dUmPC06t%X3*Q?qX6x>GfX&EkyR1ru=%+&aK9cxQo)tHj z!vxB(Q_kcTC=q<+lCcc<%0|9CXAK}!%^w*oSK8_~ns(2+qxPP(94|56?eoIL_>T89 zSlNAx`htH+>5XQa{iIGT#Ix`H^C!O)8b;IbrvuaI;Stv zxL#8S#ql_~QB0FR9d01QCJMIhz@%*Pf{X%bc=y_UsE@@+82kVVA^Tw-i&X?f>)pND z#V~TrBpL(5LmTeVL0=U!Ln2l+4W+Jh+~~l|CCMN#^IVFdp%@$1QRydfUzP>_MX-6^8oS+5^Kagm$rjK!FCmD^Wprq66Y)-j z=+>{j+69+_`wj02Gs|?{gQ&hwccZuVSz*@gmf=iRv}#ZU1cS4tWJ=_B;}{#N`0AW@(tv{~6rur$1gp`FEuewmbySgeb(Tr3&PM=x@4{^qKJI z_jmPdcM>|E{zgSDZ^r3E(4o(^wZ>?OAq8<_a*WLAQJI@{GvL_go}#)RXRr#Z`x+#~N+E(o_-papF_S_y z51{o9`U+@xYt_Qup9xP&vC)MzPF%+alS&k9eBn{IOl{CK!+oTRe8oVmEJ#r1C9I$w zAH~K23Sg1j%+|`8{5({};{}zY5*w}WtFd^*q*~LWVTB1yKuNCg!TK?Ub}Y zXF3>5Geie`7ldX0uRk*iUHSxVEwBu#rX6bQERVK((XN_A3d-O=Rixb0a6xa1AXS%eWp*-9!6@=r?}RAqwNbT>YIr++Fuv6>qNpsr|V<*x-ZH#oa$T2%LJmn2%v8 z9Xq&7J^VAy_L$e|$q%h$D)9GKj|j|8!dD1btgYaB>s+52Vc((%vev@IE%^6r)am$Q z&U7X`_)HL3V~#B7FQ|Ppt@EGcw6698s?wGfbU&qiSC%-S1X^>ePYLQv^BO$v$K$~r zl2q5MobyR|i2{`A@i<>&hZDNEPU@LZ`hyrl4AIvjwg*7q`P&6vRz_e-rd$DdK#}sF ze5(n9LL(h6qJ4X!!0HV-{S5pwpomcd1_mPL!E_OY?^@7MACJ1z<7Yihe^5YeAQW)L zOd;d!S2+s!fkH|i?wwVyq!t6W_c$E^@aQN#)mz6QhL_%|OV<+B@<-_R{#t`bw}HpG z5uKThx-0g%1^X=Vrq9`@<%~5jRMJFJQ)&7Z?@1)lp@K!H4rV7`Y)n+7UY%`?;oue3KAd%f&Uz2);0-N3!2H|GI&B4d4 zp0WJM4ux7pmEBdbUfkL(j}(w5X=y>o53Au0mRSfsdiNRZhtwwoNN|eEPfystq;ZIO zc3Zq3rpQHEU6}aZg-5%`;JvFJw+OWQpY={xN*R ztmkKrOH<@odrwi}r0F7AFsfNXXG~2srnZX-+>JQ~s5-S7O=HD&U{_+qE=CV62S=t4 zox2C~PQ|Is;TrVI2D`s)2F|JF#8^kJ=lGgCoxI1YaZ0_ju3v(J?LP4ZczRh`q!oW2D5VUfETxIt&y95Fs-j!p$#} ztN6Rm)`;vDsA9vLAO9eYKgl`$l?YZ;AD-?d^n)jKVqwS^mh1FR{OAR$=1J{Y#**RX zo-c-_t|sEq1m{hsA%?Df4UxrNn35`p)`+;(+dtMm95AN+iO3FdhLU>}9$D6v@op2; zD03J6VKTH{ht`QB7lvHy;!cqML+V^j&YgTVM0$MDf*Py0*RU1!do(Tz1Xy4#R4?yD zdn*K(UIt@N)8hsxWy3M!tH&Ys;kL0Bms-M+J~vbfTlhU5e@|zc35CnlJ=dn@vXON? zD$6IK-ztxf-xBx4z(zc&a$aDD(@AbhZp+8v=vn8G%Z--5w;!WA zzLo`2^gSA4Z*_KFR`u*NJ0!D&zq__Xd|S07+CRo8YWLF3^o!%lYQHS}lFiHeV?q}< zFWWBZ*W}S^9!%Ni+jGp%=YwNoN)LHBfI$%e@(j0Xyn{P9DoKSSNwH>}3P&&0Sr>{= z0kk1=Ua+*DW>*6tnZ`Y2j_Qyi?1b>SoCMge-Zj&=`-ypqy=F5pD^oIUR>1dnd1GkV zIofk|fg+N<*mFPNQN^o@TC;U`^$oh|lNJ@7Fxs&5FE|l_M%N9<|0#~&5gMaZkrbG- znP;A|tDYXV)PMD#_wHr54~^u<#Pe)faB_@XkJ3H%%P#a4m_=V}Hqsm?a;Zfam61Oo zpwToHZH7~E6Z1BtO<*bVvGYQa^1eUGSO9y>T8H02oC6T}yiJ}?e*<+0`-cW$p#eZ9 z8bD@SI&^k{>g{1&_!_zjrHHrjwtg#6r^aeQOhHele+>v`Y5%kGu`s^UGR7=Jd}@|? zD@P#Ke_&y-VKghieuzp!@I-y>*79!54A}oeL{ao}(5%E266$qqFj&5j#k`ZGL<)Xm zyeyG(FJwr;tH(ID^=qd~|5iWL+4b3$II+QEjX^ltC}@pDlff&Pd;0;uNELo2TY2P~ z3}=AlQhG*cl24uO4UFL;hx&%+73@jcU@sIMZGc4OMy623FHG=85{!&;VlCnnoQrq0)m*4#>`4Yoa zNQ2n$YtusXk`*BPosXv>6# zVG`t>4eb2jRFsb$0-v;hj#k8gX$cS+M&|DLkvwf1>vkM}fsFhe;5 zh9!91?XOz>Q2cAXGZyWdRYV-ZtD8QkY~;BEPq9d2DM!ARCRb{T?gbC4=yPsTT1Jvsix!WWtf7Q*CE2 zpt)WLX_%Bv!Fwv@-TYgZC5&tNcKB#?!JtQA`8Yf5rujU6gDPw@xDNLkMY!SEyy2$- zv=8OPou<&u;QE)hhAn_R!6YwghfUJaq4gROl7~Hq4Nw=$k0%iP6R*hlB9H`xckn^b z&n|u1sT4FMOF3$AK>MGzUk3CrQ%`tc=B^yl7*Zft9I-o;LYo4lShYLBq+~k%Ek=_`rPF ziewDEM^By7DDhE6ACCBh%&0cIaDC7g1cR8}{b?hX?Qyq6rZeuGSh`uH>5?k^vT$jp z&}j?Bw{YZ;XtyIS@no=ZO>)r16w#9cngP$y*fHiS);M@sZy{ewkV;d?a*`7N3gSX2 zQxtr&&+kYakkRqz-7b&F3THACox`iJ*dW`?<{g zim3U4=D}|^&EC-KrS4ZaMdsSFVu0_g>@R_V!SDO8gc|#V`i3c@So0aa!(p3@5Zptr ziJTB6wIqy$)o487jY|^dq~lKzlG|(H+KlJ7r-bv+Bwk87WlCTDSSj`E&QD3KycK-k zGR?xwqv)fPjdVEsDmor!ruTPbG!2j5bfwj9&t)}I$$IJ2%Rp~6o9K58V(bP-9w>q} zb}F=1lc>1sk~SkSRdI^9JPg7=*+E3XmQ_#|nHL{|GhcF|`tSjsW#5r-;n_Pqn4$-! zPD=%I6`LnHM_NI-5LkmI`y3n|m!1(>O-EO^g}dgWjE3}$NbXBLH45Vv6+t+`B- zHynnzNpV)r)qAO2l>!}411)LMufI>Ezs%0>r`lv^ZUN$P(|g-@)&J8^TxLh|VeIPD zF7n)`NAG_XY=G|uwU(~Q33(N_vYSYG*e9p{{6MR^-i1-B2QNYpO5u&f!J!b<~VOfQ_c;$NgRC^@9`KyeYy)Yv2hL~wpQ+<&YmfDkgWfGS=rhOEgb=ZEh zj1h_h08$T6&h-*B4Zqq*xi50`w>95CWsF3VrzIf5AkB|?i=Ros!`$2g1 zHAVfe>IkS~N=mV?IU{Z=dShj+@bG91>s9#Qcnm5NeKYsM%KhLu!n+w@ZHqBrJ}bpR z@u8YfPAlNIyIsK91D>8EN-ya%Tton2sJ$0Ne{3q!46w*7PX^-Y2~po>B->&uY}=&Z zcFJ`a)9IdCLg6hYBdYs>?9i;Kz!DM-*0FD+JV(#@d7gisTuFvuPL-o zM8iLr3eC|97!=Lb3MwxpK2f8G^BNSw@3X=ZVk1=K!G_ANs<~ zfl~m?!peNfUq!FW9U~V%`CG%1Wp&JA%)1J?k#k!HsDd>d{vKak7EG+2+;FJkJd%H) z#F?1#D<~(4{B^FVboP?xrIeD7a@*mcWuUm#@-<>~^U^)492u$_tOc>J@U=iqm_MNh z;EiOyZAV9y#o*W|g*s;($u>?Rvigfy-@w>xqSnp>e_8MbrM_vT)5NM=9X3Z03Pz-k zM?;o3Ra6|jm7AWKOzU5`Y}2Bz1_m@YQx}9|~o~I+OzT zf!v|J1j1!#m*-HAz67Vyq4n}np1ne-MpZ(a#_=G<8->pQrsPaSAm!zF0it9(km&HD zHkC@wk>ONH-DKh=r`|t?etlmMYAta|P#VjQp|A}!6}JIwZ(xUIm?LimkA+sB#z~ex z(Gj6>Z{jIx$=!KJR>#YMU5xqkJHy2()eK3|x%^Zi=BPiS>TAf$t*TK2I!!UjM`VgH z^rh>E#rTPhXnSwvLV2=wgl{>z4eq(cJI&nre+n(iT>Kz8`>Nq}&++G8deY#2uvhr1 z7*B_(eV?GaJ{nuWbGsb>hq>3F)8K_LAhMtBMPh~lp_9*9a$eHlp)gIC5I&5xqLeU^ z>~}czT8P+mQ~dMjy@r^8KKQs7m(vjaAF&Rhzk#ef{wOfM4OOiF_$j2__X%%^?~pn8 z#k(@3|4mSwOReR=8377U`vn!a{ulXqz_P2-m+%K6MYM?S0^F!Fc%AdNS{5@Plp>6DvxstrP3U8^Ht+$my<_PMq5RFK;+Gv-qfss&hP#}M4zFeLJA7D zA&Qfhqc!L2oiBX}nJkWIAvLO271_L0TE**frz+ickc(%Wumhtd;KgL9*QjRHt2m!? z=^=sqIzN<3N(E&E!bV4;Df4N$ff!;gx++;o&g1N;{*Ue=>`ES5qia}*3EZd%80BxCs`SXLI+jyn< zRS~VfVH@)tXxb8nGg80kXRA-tIeZar1G}gCE#yipWNo%2k^{02US8YS#RL`&z$i_* zs-@lG^ae6?juVcqIW{OyfVF3NLy#M z2#b~X#sU!hIJSkk#J%weIuYst3A3!y2MRpC8XA|ELg3435DYixAFO;HW-kR~TmI%yP8Q#}k+xx09?AhoJ{`lz_ zJZNVIoFpkhzB|x`{dV51WF! z+o}U5M#Q&f(sH1pn30tq`D}+ob-H7R3wFmV_+{*$9~HKks&($4#!rVg%x=b2h&(kr>Z$1aRQP#ldP?>I`D0w!~EZ@ZL3zl zgdbu&vKI~crMhtzpKPsbwrm`B0||{u(&^djeGPYqJYXQ@U4z$G1&LKF<4RrZZDzuA zx3S5w3kepepN{cxtTYcsjOI!zAS?$4EOsHZAxV~?9sLk16+oG^E(6e7p}c*jQ}OM)dh0FXV2EyQ;Q1x| zDDo{rIZ{3qF)i5Zh42N1I-PFKNu1IYpE{=5=1pCJ6}>a@#tg1)1)6b@SwJCADx4n9 z>zSp5OZawe!i#aZ^~aZj#foLi5WdyP>_ZsHpBn@LP(^0J-mE&Nr5IV5l5dV~4cQln z;vEYLQK3VkgjFElnYg*gy#6+hboadjzbGdr43ygaZ%&cqET2iy7hKHDiJ=7Cy(qfu z?}td1qnhcLLDZ~~t-CI7hqo`HX3(Sse*!t)048zF#@Td&&@!{C5^f;i^zYliF zF_MfI*=CGP7w?|ra2RP*-I`F))^WPkG`ZOb>CuTm#I!Lpe9T`EjfxW$_HL(nOjPK@ zb&df^P437sfZGg5^3M*g-a2<6FIA?5?|7cRD?5THlivjgoLhgiA6dWZniuRJ6V^#E z%dEG?M=2wa8~HK$qhO|>E#HVGE*uHhO{Oy`8gdNA`8fASF^M1ldj|NLZTnGY^k>ck zPH3C-rC|^e#4iuQeQH~q)+PLnPTVZvm~Qp3u@0tOwM4EW0}3#myO-ZdmRC$3Rsg6> zuQFjM3T_afviJ5vSp!gj>K~MZnyA1Fo7lw6Mf_|r{BsUzOwy&oH&x1N=j$YeL1ZsC zD5Ylt;Y&Q?2@8#Zi>5DW+hK~kY5-fN2PJI5{BV#a@jvbKC{~^Ub&FF1)ZLqIBW$Fm zYWVd}4eBTCpABVK6|sC6U-1rGM3?+u>f(o>tsK1rgofE_HE?vnaIcUeS@us`DgYux zS?%-GwAmkLPcn|ODp%yBdBIUCwDoZ0EazS&m10JEfSqNG?p9yd5BU=S2ol=_n54T? z9;x*@P~*d9lIhWuFXf<=eyyO1am&hV4&FI06CIgPw_@Y2ZT@F;WXR3znOdELK+`W~ z#v3fQFp8=g6;hj*oyJuGKD9nn=x)O!08xXzLRgsICvPEc)P;i z4-9m45?S|^!vcXw*shxFZPgcstfBa-0RpgaRZT3#wCDA!~Mx(h@( z46fxD34i=iHL#}9s5xWlp*Cl#c9%Vz9E1U2t=B};#AcFm_^JQgQgk+0cgw>2bf%`q z0wW@?&bjPT0+57Q+Gc*We{4k#@Yv-M%9Y~X4`6US=pJ?1_;DQS3L(w^z|2&ug4r9g zc*W^%ppUzqV+#5e>Rb=+$9SMD6brg3VT%XdXD-m|ma8jh{Je10g#i&)bvrsNb2+^8 zH!Sq)`-l}&s7pDTN+%fo6og)Z_ME^s^pcWeggOed4N%d+c>f?}Hg`opP`-xtlgEhY z-0m2YBu3_TcET^s+0e&iGSf>I7`MsGFR+U@Aej$bA{Tv3o&#MgPzQq5N}7odvsa@= zTm3ALJhc!&)|lJo{j-hah0#G&C}(%g@3gwYzs4%9_;q&k&#~B_AGa1MI%Va%?wKYI+F>C5 z8jTMYIq48}HeC|8Ju)a-!7oUcTwCZ!zpb3JA6Q$N!#~LGyC@pDA}n3Vo^+1EKx!RW zcD7;eq;ZJFa}e0Y$Zqf8DWGB77JbQpM$1ut zUQlWuv=NA-)*18mP{0PRdYn;Z(>qGfMI_hpZ-L|cs%@Jr;1mCME&YL z|3pI+rFSW}+NxcoX?-qz&M-UgDYtckNL3%Ecr`7fZVK&5B@yEPauF` zfsO2-4$JNO8+W|GI`K#5)OZe?UcsdA0nQ$_pHyfiC(yz587Y`@v}T+Q+%IX+xa8$v zRbhHA{YV*PQ??VvD}{X5OnTU!eD@u344+n$5UxcLTcgFwuw_B91q&V$Psd$iRbS^Wu7Un7c2KI;xkuX$$HY{&HM@Rh1V~CRg^M+AAEHz%XPno&OMc0s z<@ofgTXD8^(#EE8%u+^EOIGfz79uOyK9BJ6tafniNeHaLp!G1d0RAZTQ&b^3(~)!# zHbR_E%+{V#^0O_1CcnpuS#brn%~j z)A~7*7PGgR#Q1C;co|!LqzuO?Vr#<7*JsK zw6+F(zpx07qHgCO=(L~dRhAAiZ2?!D!T*`zzFKL{@LNBr7KP{t4W~y#iB7N0I_`sz z-v@=iVNhfHV6vAsinCnILwU(?ZwO|BtY;1s%=)G-e7?tvFp zvQzyyyViOfd z-i}b&Cr>P_4EKgQw}>_Kk4&37&KG7~qxl62&oq(No{ipnUv+8$E|Rx##iP#jR(&cu zsnh$X(!Yl5s7A270`xJZsBY3cfgDoY!Cr-{vK53P)LPOLSuh!h&JZX(WIn-(UM!QV6NVHnD5k zw1bLmh(`;IDD#(zM`#<*AnOUh6BU($La8W!%Htpwma=b(VI2(P zW~TK>_nH6FLSZ3mts4JV6jQ<+KE0~l(!#U6-{$DUl-CJT6DL~VjA^1R>K_Y5Gx51p9~Dc_gaDn6W3J1IU4axcgTqXMJ0^t znwa@YV(td7dfK22*A9JJP=@5dw06}3dboC34F$S={tKjY`;8@W(f*4wP<;SR@{>Hl zWy8JzCZ+#{2F{MV=>C@K6y+|J2X-(q)HAmTYxCkPsz2XzoX=}iyA3uR+xB=LG&6q{ ziM6)XBhKbQGh83Z?G9VjCE^%S#dqBM;PV7T{?id|95E&-s+7<<)vlJZe2=_ z&X{kfKp&{+qpxD2k@!OkVOwsPA3-V8A~&zeNskuSHnInelo{ScS>W`G!XrjL^fG`J z_?6f&8ObMG^&EI=m=#QhrPay5%z>9r<%K=<0L6@!S*YWNg5`}%t@HpwBWO-m`J!(M z7!gtrU|c_ZL>@k!g+1!;1%P%)l%zMuy^XxoL)AR7J5C{I_-G7D+&Vr*5)5W3?h-|h z)XVeqRV5l>k{w42%v+xm)JVEOpGpN!l7u#Jg7UV7t4U2p(u(}cwQZO-K?~3nA;e^$ z>c*CRGD9!MA|HlY&}C}q|MnD7F-Ktg-uJK|@W}XU@BO~c`>DcOHAl!3db!06N2+o9 zeQc`Fh+T*GX2_l;2Y5YCm4Y|?d5EgFiHy{O&e0?cO1J<*Hs7oii?Lb0HY6jyl;NM$ zdU#I$fLu!{DJcTK21lvHDim3zP!Q(A65OZ;xOa7Fp`i^|wIU8+ByS7JVA}TQ^l_?B zgIWc^Ukij%4UQ*A1w@=qsR+4hNm|`qzuPA8QFV(nQ?aO;=5qT2p3;_RoKazbg=Y}N zWNuB3Ux8QblU4i`{y|-7-py2n=O_$_fU`IzY1Ep7d7!9Oe_);U=l%2Ya2!02?@c|_nMa%7h62e{+YJ-SQ zUf|MQbYr7KVkCHd;bzD67==l8BNBv!BY=1N^;U4A0($7?hUNZ^nAlNCV8oiI_I2Nk zaHD_d0WWr^#98R9?{5yed`C181eq@1C-T>Dhi0rqo0C4l#;-rRgIS-*je zt`oB%o}D#EH)l;US~q)>sGTS)Qq6p3vrQ)Ks3%LCkm zr#cZ9ruGEte_N`pgeu^FB%>ghjx8CVFcYS}E2HM=2WnaxP~J*F#ha;v=ek=FY*~TA zcxDJIBpS*d1fcpUT?@V1W&~W7e#FR4i#q3ETz!q!LBD)93SCfkIw zTzBbwLJ$A!&e|${chua%`W?8+UwGPD;dXq{7#6IE25j8A)+w7F z#LB^}^K6Yo)jY&qZ3OJ%+45Gyc15ymH_L6>H@rf(;>M#sQ?M4bP1biYoQ8cN`bQdR z^z7CpkJuzet6%l1f%nJM3(JBkaJN)yTbCk+j`P4mB?lufm(Yz}+mJ-oNmn^Zj{-UO z?+s(OE`(Djg^(kC-Riq#@cOFYURIi*o%S}x>aZWD%$EF1GSQFRAqcb_J!#OEa4c@CmUFau&hBvE2G#T z%6W{na2}|V@bRDOB6+Po*)54w3z2+R-0ZZ_O?06)lR-Lgc_fmtO8gRG-(96zg+ou3 z=yoH{6?iA}I!xhfV+8@v!J49wcJ%P(X~B=vscq6ARzPKT4e_9()?@409(^U!nVpzf z{E&Cjc{V-R*sll~j>jf8cL149wb5|ro)P;>Igm}N9!{Eq<|^ZX2HEQrqr?{c z&T{240zp%W1ohidjT346HNU(WCpo`e>86ga5kZNf2}l!@hNk*t(r|a8!xYV2j1MGs zVM9`$y8d%J4IDsK)%F1pRtX{Lpr8HBqe=vutlT}HP^M}9A-fS?${IkEhpy2`{QhvP zWuUnDK4ko|*4tOiya;bTv(YiA5^^V7q_%C3|oWzzuo9<=9=S zxW5Z^Sv1Oqd=&9cGmx;xC`tEmOy4X!Fk)GL!}#n^!U?)NQkuI+Qm`y(vBOx(%{Kw# zvpy2)6k>OuzdtJ_TMMQuKN@T&cj{R#Gx=uY?C)X&C)?P61CWdU&Z8P$W`acvk#Q3M zJ0#KJP?nRBV;wht31a8W=NO{TTf1(m;iW1rgvb3;bR5sWtnK#-iv^^5z5j{>Hb#!U z*%0~cG*5ntT+j3kgB{JQ*gOmN?-!e2eXDQRrQ?Yaz$!ZeFym2jzL$xhd6ZogcsD=M zx$^Qov&EgEJEg^&7sW?5wCB1t_5hvzZckC4wEKYUn))6<&VJ%d<_<4bA6bChgmi%C zWr7Tlj`EQamE#1cr`vXGv*RMya(9Jfo)Rcy)>{n%^RONOYPkXU)do|C#-z7Gwus*S zOBg(!uU-|?#G4gwBRaiITTuC+9_w!V;f>c4YJNrJ$t0@Om8D=8ZudJKh|hTXt$rqE zCfXlm0#ems6Q}|9PJa}OO9&KbLD-lV`#*OVZYyv-Qwf4We;CDrND$6)uKjJH*eU^V z0-ZN3EZqmz%2%H^F9&`u+S9EzEC{*!vh7A5i{Y;%&vRZ%=r_-Re^%i zK50m4CXPBmxpQ!zKPxqy?)f?SvK%=@6gdac3ujBNy@>WD3~5%LyTETFxN$|4EC z{>s(em~>3f&=~775h!M+oNfhDzQJgELcHmznf}^qs3b7TExUc=(3pz`$j6YM>sfIH z5Kr`bqxcnibOCySw*Iu&XFO6jG?j)bff+eeG?!i6)Q3yknQaM^y<^k}K32sg1u}CI z)Yf5DlQxlA1N*@_ta`78$BF2G?4IxkkcTvdHbhZ>II;lGTRfw>9OPOp^tU>#vo-|K z6yWGo?KfQ}g2(4bHX?a7rKiNc4^AfB+`toJ%kl)yMRvE>*$uS2PF4Q{KgNG6|4v-Y zuZ;Rj*89Meh9-f7g99?h5T`vGCdQB|6IlyfCOEY$iDy+in2ITYRI*BBC*X00meh$_ zyUox#7+_u(qbo!tlkUl<&<_;2PFtPMT7DX$#9O5?O$u@ysS~ZYeSXX$y0=&k)&cj# z(Qjupy6h+|DJ>Yue5y^lf?6O(hqHTa^vKWC4B&%}zEBNOoFoZiu=@HA#bf`yTm{7y2K#aWb6eK@*qLHGeULAE3QlpDTkszKi!^eXYyhtQUh89;K=2 zh5WINu^TpUQYv&_9Fzabucu4tV8N<8{c5Wi6Y*_LwtIr{Kg-ehcL|SR6?G+zB!Y@@ zVY!}bpIvC>^8N9oK0}uZ1MFRZtb2u$zEU~hEX@4)rZ5)fR&j%)$i`Owh}cZ%mpF!L z&;p&i8nssaA)joNoqTP@zQEdxk0}sRAR{*D@#2NLguZHjj>O;36k>Ij7pmiS^geSi zN^f~3J^=~aBkmi{QO)4s#{@zTrgi-=V z{CXxXD*HA@(BH4s0l%g!m*?%W?yYX`wO5%&G0x>siHnqafOJB2F(c>*?zptFv8w4s z-tz$zJDDbX=hf2OWRb3tdVSBN*z8X_uSUvnF`a)K)$YU?v1sS1oLp1ofAGWY*|lfh zfJdZ_1joLUJ{c+gz1?h{VPVC2=tqDK9Kehe9SyI@1*T6_LZbA1o*_&*{ADWqYQ{DS zvy^^P^kK4xp@28F@2&#h-){vVDzpB!1`61iB9p{QHhp|6hc5;0e?-sAxLHy>D2z~- z4@s)>Ex#};vW@o$<3t@3MUW{5l|vC?Ln&@iUt5i*?<2c9ITj0VRfc;~tF zVjd0hgLp6lswD>eY!aI)&N!Jhhut*FGUB%xf_d(_!Ri6?Gv4CE)2BoyC@hi3QirO3 zu#2Tg-1_2!(YRH(o|cV!MeeW|JljY#t&aDDvwDKNt?d}+=s;J*ZwAN3%;jm4ieMlk zMcy#KJqP~sl&FZ@CYcLnlPT$IkuwpHonrL-u{6Xpm0S?(Yr(7 zI{zRx+d;!9_WzD(>W08baX!jgV3o}j9#s@C_nO*wair+H)!rK9RI#!MtGYg0U>}~$ zAPyFWyw5bp(2l@|^(tdY%{kIWxw`p6i($UC5)C)#+$ZtR{kP~pKuHW4@+VEK|94jT zJt?!tdJ;!eFzeZ!%jB0svtnlAwWB-;#r4x2CH`eWlG+FpcaYJ{DcI7&zG~mkzFi^B z0En8gME<*=jn93nz`%s>;y+v&z~H@aMt?<})J-9y4R)W;Kl%()QR>h>k-JfFmvSQ{ zQ+|wXwlOpBP;;HQU6>fylO}&zOQAK`d=(C$x?PGj0J4JS=Qnk=wQm#k%FOQZf0LmXg!DRoY#t~zvv`>kc*1{&F)QeJ*2uGOLPO^!mQN!%s#Q->p%@xU(Z7f)dTw|z-mx%^lEJJ@6oTgK<(i&9n9{YVvR7uh0I);mR zlaqRvg6hgebtNKLYTAC=h{P>SLJxdZdv8o>FRZ1Rc{RIV_Irt<55sV*>~^xLJ4*T4 zWllZy8Em;UH8u_dDh+rAm2;SzYOKNh4i!$gF4!uT`jlnZxgzVgJ>Ui~F^J|OTX~$5 z%I(vgq^$JuSXIQ&O7ZsE=GP~hnYVW~AwL&C$47I|<72@NPpIUA7q>)D$Ld}?N?E$o zXTWaMNO|s>rL>Fg=!AtK(&s;+og!YExTtlRE>LCoJ!lO)*wuTw>J|S5fgK0aP?eG- z{YrH8q@z0CPwywOcI(w3h_ zQ1MB>+@lo|1$-T$KE0LP9^s|kZ<&r{IK$nHzupyu&8xjEBeKzrkh*}7iw9b+pkJs9 z7i-bl^FIcn`j5}7oN~G)a}gSdgEU>Ej-_tn!M-jO1idg}Oy|tqc__5goeOAZ-tHP!-;Hh?|U*`+YFf zm3d~Hml8ZoIF(bv-O6bP6@{W;LH+)t7WyecYol8vgde;AW4kzleH0WM66A0(XBt4IdSz?i7 zfkSvOomOQ1-S~?g%RR{Yu^lH|q4S@6*bbTQXNW59|t8_39MP%F~X^`lVO1uu>3glF{E9JTL#MZkvHu6 zGkeaTJE0v2*ltu5gUAXDx$AyWD<#Qpw)eQUH&)`i)s z`H`jgip6<^y4OI#qRqxEh_-#YsDW6e1>*?{zD&rgx0fB411iH{jO~gq(jA4PY#hiD zxYITNPmKb1j1Z&tL1S4gn#w4QO;&iYb7bjEgjY4i90z7jxU~*Sy0&W@wVvL|^u-a2 zdg0Bmz{ViFA>$-Rm*Pv<6%2WNQlyKy(A)Nc{&mlieqG zsfMNhzeM&${G{65Zw&yY$bVs9BlifeY-jD|N);oWoRq#z>l{#EAWFYsy}H?-k78f-Td>+^XlK#nv0ZZuQ6; z5Dgv0Qk_a>7I7t~4CB+MdEW0t55}HnQVR?6T|ncP+n0gnmT0}dR^Yz8)3P77Mz~HxLUcn{3$mp5oB*Tf3;!!ka z7LNpgHh+<^b1$w)4E1-7xXK1hpjyGFO`;77En8Mhn=OVp9J?+82{+ABLw3f)>f#~O z$*$nI%Q0sL63R5=wz->4+r{&(d2_arkX^e0{EbLZqUYqNpxDVHxjM*&_Pa)c-GtU# zHqMXniG9n(e$!X~m4KA7|3}<6pPhF|UWtBUS~(_`=JKu~DoXCFUe~+WuA!4(6!Hf} z^lMC`sz58RN|;`%h5o)03}`s4Q`paL;SY%&ul1k2dt1>8I7|`Vvl_QLuQfP91K%yy ze^*V~noRE*;Zod2tlxFXv|A}(NC;U)otF%#_Csq$&12313!u_$8PnGJ%X<^9b8dhP zGueoS1t2EOZX&_~QWUlq8eZ^YZ}XD}gq9KzOou_X^!^oT`@l4}<$p5slna8E9?QB|Y2pZ)OFp3?#StT~yH>KGNilR9_{^}^WCbQ<=H))88#1;X zsOF*@FwQh=GJOExeU=TWL<*Ccf*ksti_dy;5Zy*~aJa ze>Qy~6r-Cj0g(rYJ1SYP>ZJhSTd1;5r5(AS>hbaB4pSPQMF27yC4eY{2>s9tB89ZR zA<(B38}NiCRdjXWG60ab0crJ01Si@aZ=MYIgouXtE%KR1j!g}wYc0(4bA^G;H7ceh z^&z<=piO&0zz4RYJ0`!FPPoqL6F{X_yBf>MDm>_+T{WPU+%#N2aQ%zV#XWYU`b9kR z0<_?L7qtnSDo$TnR6$Zj^ktP0&9&D$MV;n#dvtk|@laxzB3O9zq zY%86l>`MSi6!Pg5kQciRD!Z}Y8f22d9p8c?WzFl$Gic?okTi06f0EP-Va zu@e#4p%a!#=7UTca*F5~64_hSe#Djl2T^gFA;f5q^a52IhG0-3M=q12iPbw>ADZM3 zk7qhI{&vJyo0=118ec_g1DtKa^9qJ&3|h!5JAWdup262o`-imX_aJnKZH-m6v#I8- zG&*!<-h|w4>0Z(Fu$H2ddqHoMyM%cW`rPV@X*2LOqu%tYADc#m=_6jcCfBMBY!$6u z0Vu_hbPFh$ga1Kr`CADUT(hMdZBYMtX-0I-Z&sIT`>Q1~wVMBOhTkkG-EsGlc2Rp+O5qylK@MWp0p49E!@KlJr@!vRM8jTO1^GMaT|XBc-RA4Gt$ODawR;exye#~n zYqkzR=9Cb;F}m$sjU!V)x2O%nF+BcD7erC@KfkmSS2fZSG6561^Ok< zAp15g*beg^tbAq~uQbORZpLIcLbU#3=%0F#Q0;suO5!ID>)|rCTGr5&>O`urk?=@6 zN->j3OpwmAe~;+DBn;_be6G4ZH||qB$D2cSG{ei-k!^Lu$LR8(RlJhM>_8*{ab(1d z{Yy03R$UYdqI5-280PE2TZZ-79XXFhU@kY$SKilE2`d_fk32w62)U}nFaS2&@@d_^ z8H%Z+?Fe*akW?@lVhr(KFQZXd!AH&P@0(QB%ZOUG>GX7L#t2=#r#c%u*<~Gk&@16kWfDd^>Ix1qX_E&yarKnCIT6H8&SjR&hXuI(dg zHNx?}V&y}`U|yKz=sL3t&IP_3S!L_TYS7djP7Tf5zJ=^Ft4)@iD&E!lRikkQx;7k>;j=i`q%%ctv( zU0ZGgIejj8(f8E!ki``31+dyEj8148L@JpLT;KVIz;%9C>w3xGVyBwM62V~@q*6;y zdTDm#T`_K2i>`LWL)6-WHH@vKfZ+hhsDLA(x!))U27~2&2ZqkfQw!EKG0k3keM_G| z!8=NOm5+a1`!V~ogruqLvoJf9^o_0Z8S3o$Bil1(l@Davou?F}k%T&x$^AE`Kan(P zJPbe(x5QD5(<@Xil<1+JW7bWp0ivX4z{=>i7`JN*js^ufMZs6PzyssMd`l>7McY zqh`tYp26*x9DcS;{rfC{SKOuKMHPWX7as|O;h=G24009!Y+AA7Ak^Ar1$aRvb%lD^Bd=PItlw0gQxPaUIYHGZrPD^_+ zDzO`;<2z(MHQ0(B6mnrdF7d=1@@t)rxCS04 zF>|buS6`=|Q>+$$7_wqHZ~S~7pNH;GL?k;*IiFYQHT!B7KA+AJ}XZLDadXlauX3P!9E0^+6czxuqM- z+Xe!lz=P~cPoxr>kSZDE>@l+>=)r-;U@1=FojAuu&%m z#?AkSuqLUGUCX;cgxI;LTe)loKHVODqh@>ly!P%ngE-0oucHtu;iY|z?2#|0Oa`~b zi`NlP+lyt6F+scw>n{vY2&Cre;Y?Ot7%pRIu@F|wh*S^M>IP^9dxL*qO(0SV2fq%$vz zS=9&qL55DS)jK116ghnNg}na>}sL97QcxNw&ZZSX>VGa#JIGCZZ*#s1DpWhG2EEj6`4r4K}rjxk~TLR zB+sQDBE5t^&Zk7lkvNy_Ax^cloP@up>M<|wsJoVL1dYA8-Nr2%$#tT0*rR&BQPKQs zd3Z-_d zZ-ykzw$TRSB0lnIxqD(-zUB94C2QQ8n(%03(N3kB^&%h-CV3epv?V;Pupm(35|qPb zR?S50cwQs|4%5!>bU3djmhrGsF}+K>`K=1d;6}b%w_|Ake^TJlxq{JrduLKbe55;C zWP{+WqbsWzFn0c;fk-El+Iyvcmaw`u7x#z`W5Qy!7r-Y)wqu@F30{4RJDls$-m@Zq zoV$LvA}8o`Ioxfqf}U1+8YCvFS;p*=haI&H$h5+&yz_}%2Est`fx^*t ztM-|O)T$GGS%|Yj@onJ+b)2-Xmi+52(dw=wb30v_`-&fUNYRRvjUoW zlKWjrMbe@l{RbSXX`H>TH%HIR%8m?0kDS(c)!a!xS7X0`rI?s#l}6}QpJ3i zXb_)9WoBWq24nApf~FcsztDMf*0y(31(?|Svi_R>wP#Ck;7XV8^ViEA3T&vp#3|9; z{>23dsl4~~y_E`j#1q1Q#$W}V)1(C=Skg-<`dS%+s}v!0AQl*7Uyq1l6Fhi-z(HHI zMUdzfS;Zm{dB7#T2;>EuxSFAUE!H>fAcQ<9_%FQ6Mf~WXnd+jl+p0Ikf}cPuFi{!@ z-PJni5yytm3}J0%LEMDL?$)`v{htOmtdvBTGpkhWjSSsb)bxsFPZk{VcO<~ihU>O% z0d-hDj~hMQ5j4Rlx62wwYXpvI)Z4ZFSevO#mK>tpg6QzSA=v--u0J@oT|3Cu2Yk+g zITkk||91KIY6Fg2r(+)@;smIs3Zp$n#dHSuOo z%DD$!jJLjU!jKwZ+VPxKFbPJl4Fssq(?cXowgGllL{c*eK`Hk=ThfN7rGCd%R-R1q zV(pjE2GXV$nu$WJ5+y?>ro?pWrv%pQ+g{@5v!|f*4X290Vb_h&%3($`WkIV#0=>%T zWo9Y_8e;Xi3K8a0LdyGa@y-^_L4{NH)+zch7xV}E^Jdr{`TWv!(lxn=Xz~!|vWv}t zUh#)Xr&xhoZ;h@{i1HN;NUg&j{Ws-Qp(wnWu9Gs~OI1WHB9LzXhK^Px>$YvXe#u0(jXS^+kB27}9MfpB zz{C*fvAaEFbSkb zqDR46lT9<1I+P;)tsRE(cbQ1*myPwB^J~TRo`G?+^ptlr{x{Eqd<2SM^ zc@)O3t&dxb0@Nan)!bG3dX5AEJlPNxbrsz zL}C>6zr&_2Tb>%xZGg;FpqH*Jwa0&X0I_XblM<|AdF;eVm5t@CWea$NQx?{!f|}kq%oE5k~>G-8N`SS=PqB zaMi`Y&B6!WI>aVsb30}~%d=&gF2oiebw-)^t^7I4Br!6$1h%Nzv26q9$k!lreN@)KjTnGgKWa-&woeI zh+~mlkL+DzDZpU=Yoz%SO`wv~hT3Q6>GzOdfj;34 zCFo1>5*Li0$Q$ka+>ww7kj8YYFmF=VuGl!k35c$UPsZ_Nh3lu(f7 z_F3}hV)?F?4$*VHQ^26^iT<>MR@_ z{S~J}hQySlCr#z32u)?IOcrPu)Q}`O8qP9xPCW418t&_f(2yFPW z)RbWUB915zk-ErQr-;AEiBTO44k^1V@D60`5uF6Meh3D=ZZY6;w)H>W6k@ge6ryZp zR5Yy_Um0PlblLm=wYUPH&n*c}Eprlrd$?S+Y^@9CJiev=t=d59ZBMvGdO3b0zKfN; zJ}7(+?63)xH&R#F<&dH=miJ%r?Ka=)|F-2f@BL|)sRmqY z8?>=xOuJK~m2IF@)4c^d7P0RJDR0WvT^c{%vaI=-R0t)HBhH=e`i>yr-G`QDkYc(i zuUPn_^lZ=>%pXxYouf-|Y4U%h4LCB6m5zT#+fB=U(tOpNZ|g#TwyPL`F zXr<;sPu`C$gxP)-@1vJYvtVn?y@n=jcn}5Uy)rWCEA_nG?Ak4vhi1ax&JQP?ocaA7LfvZi;jvw_j87$`3l9|qv zW?nq<^=rHU%g7L65p6zg-{R~GlIQY=e=AwN06t&u_l`0SnkFubDLq3Yiw9tNDyRYTdwc9VaX#h@^Y2y#Nr+rH-HRG!8Jfgk%=-owWi#lP*#n!*N(e9%A% zbh8Xtn!e|53^R8vkKEp9BY93H$;oiw>m}8kcJq*AQ6IsKBvaju*}}itO;iy-e~DUW zoWjKE(o^UECL$H0)fxl-O;osO=6zYfN!|{dcvIhvm9}gLnppc3%d2=AoSh4aT1A}g z_@~5+-Lln{Ve)Sow_L7m<7SF#69H}tKA4e48c6;Ku|>nPbF!!_q=#(dJk)eu9p3mj z@`)uI88zbR#NqXg-NFaFFrZsiR@P?-XOgH%-+{A3Aqx{@zWz9G+lSgkcCC8_EK(HY z)5wMlS-p&XglBMj!cD+HJZSiV4Qd?ip{F3wfk5XAloTLh&!;)t03D?Ab_5BAZj04s z*Zh7rRJ0RO%s0OCA7_ZK(wS>^$F$ZqfOA%fb4@@6re4(}@wUsbD=WrYLe#nSKo8Q1TJo z^ijRMsEjS*VEOfe*d6tbEM;Y_$!-XQUPhgzq)1B^5S|bOTmkYY~xdFM9`5 z!opQS*!9e=ya3p$+$x6E7nh0B^nW#00PNP#(oeV=dbBlqf3GyJ?lj|(Aaoa6^+FXq z+mGREMPT8H%T?gb62Y#wSUXeW8r`78)DED0NHtjQCDp7d>A&djutp3Vi1I^3= zILjaa;VPag3L5Vn)O@zcQ57L|lG-$ffaonsKkrDBD<2i^KGO+FDKa?}bfQLt?!+^6 z1}#sr;Hw~CY&QDfEf#4=gv43r|3LnIe1vGyvf)Y@nIBG2Q{&A!omfSB(E7|q1gd!R zL!+0MOlUi7R)%dpY7C3QhY#hn4sV=Ka*M=>Bkyf7p0?UL@F4mM#rd*;VvVB)3r2BW`&AuJ-bZR zd81ncC!Bava4ZrZSe~#7^gnA0D{pnO$PrTcLOjmj?Hm$N001(fn#qUeFSh-42?L?n z;}~yBs8O?=h#hDt6JvhzJ+!Y)A;P9urBvE(e9yqBdrXA8?QO+F?wgCmi-Z>EFu0Kn z>v*y@nn@jipu(fms1Xw7GP!H`)44A=?1n_wWS2gA_bt%E-kI|V=388nca#hbI~@9P zmbhpF>`2UMOD8RUy|FCFU`0tOfl4IfL(H-tZM;9v?R>C^&UI;n4)@AZ zNwhp!)Luf9cG)lmJuA3l;IY>Y62?8(Hcv1O7G4iKnjqO_+z^e~&sG{4?+LBfHnCYH z6y;kI;ba>c&hpYx>ggG z=nBw@wkdGJK#83r(7DSIPLFTNwZJn_bA0YX|usAO{EY{io(?7KB)gnuZP@ zAnJN?U{;|ydFu1_?>RISTSk`r({3)GHB))XGz_&OU84Tw$4@9q@t(R-aS70~_es`? zg*ny&5^k-{^4=grDl6nfteI4S#gPg{Qjmm@%gHt6jzA9IbZ$-+pja=2)Gyyh5z<|d zMlPRmvMnW!s6^5vaP`yTG}^%=Hj-@c=@GkHkyGV`)S(lR^4bcL&dMUfx|tqS{vc1x zkeiAYB`bE34Ax@p9{cGJq{(DT{a1}{`-4-mk>w*JAOx7G=zSy?9dgJ%Ie54;wspKz z8m^G}_*fu?bV7az)o^Y0M|wYVXWB_1`fQ<;#4hj|-wNgyiR$cjt-RT9e({9@JH4X7 z)QauS6UJ=7`(*wvt?{}%Tun(u7Rw(W=20I)v;nna-m|rCzV*rIE<(x705gVJa6_?p zn4-)nm9rw;JG_`JpI}dC7g3FTqmA^;nWu+dI?4+ttR2NM>W$|c;QiMNC&At_aDten!J6PUOsciw?00WRJsimV#pHp}ow_?B zRg{4v((d=&e^(^04X?PgYww7L^&uBnf%sn3{GflxIKc@fns_y=Sgh;8N9`7`d40V$ zMuZ9a6}rl7Q)oH1UeirZH#~Fdr%3Y)G{#`&9N&M4BQ3Gl#VfQCK?=sWk3a)FP-UYZ zp5*Yn!e*`psRNO1wr)!BU>+3gMH(-uXB}{08tys^Tua!sTz^Pzw$)UIp}t9Qo?%t8 zJfy)qWCrLdj2DUd8%7WkWtYqG$0>JwaBN+!Hrm(Jp43yV#ap|EWr(s9``H1(D}e{- zHqH8^S%5sVft~u!uTzINO4iLv5L5vKusB#+KydpuBE$m?^3uTIaQi z**4FJx9l6_i0D~(!Y-r1-n?bSF93&2jZ^2ak2j9jDL8~5Dji($!2w9rJcm0+mRF`L z5Y7a8VJyrv{z(OwMW}u%bGOR{ql`4~3BcvpMIBTMeIeS$mfmg;MUT=F8ufin1=+4eUgE9J$)(D(Ln4tBtf#X;u%#-G zoTT-KvyAJ~6DI3?7pt8|*Gz zp1hhcuQj6YotS_haN|?8&uO3NZH?l7M!#uJC4L*HG2HEgbg2kx>t3AWtD4TBgg2x( zHx%%Oc&>1V6>py;EvU(&3TKyFuOqXXd(CCrZUz(yYY}~}zR4MmgW1dlL-V{!F%@4h zp!ue-R3;Y|7en432uKW3rw3sYti#?v)WLeAsWmOrbzMgqE4Y|$}Tg7{eM zGW4QEyAT)TV+j)@M0EhSO#G$Z1yR{`g7aZEv2kf!fZu+s+V#1cUtYWL7_pm~8LMj= zYBz;s1llgf>9^(^xOX`-BfrVVV)AOf)G}DlEn<%_-f~)^Zk-`c9QoBWD-91;!w##Im=mYj>SqwuLQyJQcE3O}E~$pqVyv$o1KFu&Wej;!j;2 zpE}%(lH+kai-f;`97#xtyA!Mm{#Rbu`N#(qrkiHxTZ+H zw#gf4@D7TV_?1>_FzuI!k-Q6sl!vCxaVrh7J8a??jZ4ARAq zXS8TIZJ!PRbA^K$D>=kIbS1G&m`6=IeDivi*HIx70Lxt&S+#`>RM5UfbJecx-pRp~ z3K)!+F_KH~>*l5`96X$#)xL^vqf^?$W#b>~7mGihM!bVBH}cJ0c`*Xq#)T}M%eHDE zayyI~IT(YmR=OEEP+bl{DIg%q1orpr;Gk?50NYam!kQBGq0V9DV66jwu4GVL);9W~ zAzV0661hz+RSWdo{c>c9J5Acw zwX0ZiO=%Jb7Je!A3^*l&wmm|>+3u+_rDGEcU*3NR{EmQ!h+)jZ z4imtECy=WKf?^ZQ*Fo!;HP=5~iVf?GUZj|?FlEh%NfY1?sNh$(E~=N&#Va4?5C za}^$g_d7N#cIq2b%Q_!VEUI$c&1IuJMN7;@h!1)1;Eq@IW+0QIHk=F-fM`sG76xa| zNRqc!fYxk*Enjcd&>lW&SS&g2+Be6JlVQ^vmKu$5@D{+;t97f0V%|m5waS+rf#0D_ z@;Ke;H(~#Kw;}`;Ax6iNH7x((ZY=N=M9dw<#tM7P>1{B_bs$lNQ9X}E%#aMSul4(EbV0968FuCk zDsTe?2|V4{_HsKA?*9WoU+qUt6VM9dy`lwVw*O$qHPk+sZdPa)RN-J`h^tR^N4#Dn zFtKEC8VnQWWLJu*Vn$&=bCP&3XSV6{za&}n-vYsfiUN@N?V#FER>$+laT%+aKY3hhYV_x zs*VRPfv(bM{cIpE}1>hQc{?7k2)ZDMVTE9u;~YqO%o20Ua-6MmCC*9rzQ~ zLbDw6m_TFLtM`d3BUvb5r^)Bs@n{|60Yo{22Ebq_EuK^^{^H*$Zq~LxIb|pM!ur9` zm1#DZN`3nmOE~9%nFszberArNCPQRhj8MTnM`F^XBtpfMF@zz@m|va9)GI2;jQ38l z8Z&N9|5upwk$G_I;G!O-fM#T?eW$!8sIt~e0QZ61ktvc_;micr!M_@~5aDC`PdZN- zCZvNard;U|c`m0^-+fXpe7y;TQRkJX;r^L$#fjsb%_MS<_KLBSfE|vxMg#>9`~w$= zPttilz-okHjAq{e!95Yfl0bh>c%o~M_p((ZxYhESD>D%~o! ztpVWDxzl?@(lLPtjNz{}t{%bO#=x#kWk#X;-hU@g2G_ZCryn&9tVWSLEy{`80YNORaCgOjp?1f49}yOwP!=@x zimSfw=%#R6Jpq{^X5Jxg6U`{9nzaZ9Q7wq`F&L<@fOXBdmf*uAh|8|~e$T(zDh0du z5|MCZQnCKf;JWfKfHm~0X{Z*MoW%$C4kin!ctIBQ9rhC7*hL33;EWB@Q?4NIROhJUr|w zrGM8g#jju6XfcytuoMWOm#>4rMbGvN}Cr9VkGiiOhv%H?eh4y%(jQ&b}IA8 zxVS!TGmksx{he!@x;LAB_-;Ju_E2lKY8N}^XbDprW01nc{VEyg@WWNe(KDQz=)Ow` z@0RtRu792yF}B&|iz7v%9lu41AoF#sX*k-mPwnG7i_Nf4-40ewT$2skZron`L~;cw zRApX>twG8_`h|~Nfk@g;q%E7EIO2>Do8aJh7|)|X&rMiiJq$W|(-TWHE2oG{ky&ah zJhP1A1|Aq;o{>24X6KzN$o{4P3L8|~R06{CTUUlHu+T{m%CX?Bx%Yp@-KpnzPdXh= z^s?IhOX2NVipJgcAdv@YJ-o^2WzDG&I$rgK6xn6j|6EMc3;6||QQn@` zw_O4Z6;&{@U#^_wUHWMe;!LL=599T$dCl-EEk~7p+{`c&g~_%& zGe?00Da2D6h~%)OdIDYx;Q*u%3hoO}f`J@!fx6=v;GoDCRr03=O>9I%_yzMa=$<`0 z&CBsr;6Xd4HSCD0?s7OmknVj6x!$3G_JMd@CX`0UW!f^Jh!9&a9G-6Q{WvhwKgZ6~ zfXn-HevUWbjwfvl!k3`fQ3BOUxbAc`8Io@q^OSVbnKyU+zl%m7;*w0uH@qfyL~-<# z)hqp?g%tt?T^UrCQ!k-}t#bN?*h2mAjupJtQC)brQKtXW7RSe0a4c7Y^;9M`4w~n* z#ELZK;;tL)MJF!%aBgHYz1d#PpIvGYzzie>uhH{$PXypOC)}2FnX}=nYjQ?0`aU7KT77j%j#yZ#x%1AUu6o_758|wy@+YUq5z0c zmhR_Gs_Mr0c_J(J?)X2JR-(79?{{1B(=|hpVp6}9KNuC9!uW8owoAO|zup9JG+#%1H-E#&+Ilzpa(zd)1O+`uZOXX5=@!Lh2a#cr? zKnwn_NK-p3_PgT@i2Y8oY2-r9L;>GvpJ%8iIxNwSB<*t9p|Sm%BtaA5=h=1RkR1wQ zoIJ?)G*~2VSHo$4ghiUFMU>ch3XVh;NLTN-fKFWwCzyA7waAY5g9Y!^< z{0K1DQ0P}d+p&Aj7B%m^mDwLTPQ`@`Bn{?>)J%EKfj67@1pt9DHly$3H~an3he$eC zRT&Y;`c1n^O4ccV-=9j*3N$)8v%t5niz+)-?O9+Nl3*gI2$MJqAE zSH`vO7fix2AKGaOHmQWTM59>5y3!_igEPe%P;);Uf`Rd|D}+D&u(cc7&c1?Xp;&Op z{mVAs@Uz(6Bssj6$3cmT8oe3h75EfNsKW|7?Z=IR8|VJuakGWp?n~?<|9`fZ@XHTk z{lG(lmZ`kOc#4K~?(}of6i731jGAK%J}M6`>@)wG{=0dj#yx(vl2gC^GhZnMf|R!U z-iCDG+7l$!AQ&mrgn}D;V&ap#uAcuycG^6mF|wkA9^}&96tv~GokhS`6}itou?O|` z46Y{8*r5L7&sEjnsX(J-8-&G1I1Sq`IwRrBD%iJ%-oaS?iEjt=_OyP^;&p3XJ2Crg zw5qtGdIV7&vqZtyn;4U!;~y(r`E;1@^hs9QJ8k6QQSdQ!ua$CdV{{)3vx>d zqewL1Gw<8VZy^?isG3k?h7{0+g(wL@WLmlprzHPPhH=vgn$tH5!jxeV4oD5Fw}RW= zaTS|mzgIC|!q|8EvQ|m@oh8eQX+BYvwve=4!mnJspX*hU^cn+bAWtqs@{_}PchK*0 zKtLSt(1Q$r>UONoEY1e7VyTx(=E{`s5+9{F*0l%;JjU?j!L(8wWu?BLG%02H%`I707);sZGepf;N~NrT(pjWiEWhly1N7oEWuIiLEX(8m3?QhnQ=#MQ(aB&Ot5X^U$18}{6^E+QG!5F13w`pK zL?%NnmbFp^uDrfXGRr6u;Z@78@Nqfm=}%WjHI0efiHmOQ z1ER!iAOQz41+@s1<}V1EFIv3^C0vFaId?15y89kOLViDOM#(;yR#~8buH@0lsIEQr zpvW=rRzo*O*qXL~nvHPHK+|8qj4ly#=#&4&H*IG2MAzUawD zc_1-yS7Qh}RfUnflR_F4^OLu7E$}u@M=fT4{w&EWa`T%<&CEptd}u3z$7=J#cyuWw z(ex82q!K@}jy@AAuOM_X(S{rM#(spZF_vlB0 zsDO<)h?Y=Ev&DaNue*}ce!+7RLa)L6fA~COdq;3xn3JLrk|M;ainp+K`gL!6VI87{ z$&U63F2HQxN;Lm1S^7yQTpDs-80(OhK<7TaiBJz_@Jj0|Nn|WNme{!C4zb{_j>dKW z@A>_*2#Y|ZFbm2KkZoI~>uUAxs%vzgf1?|Xtv(tYZuDlBvg|5f3GesHR0M%l3_z`5 zUZ46r7Zj}F4@YOsCN?dvj@hUB?wxd23h@pCahAcg!%D>N2N7c?YRJBx0vJF@dvf20 zsI%{>e*Z$+g~**)1tgL-%$(WFIEl8Tr57u{mosNLD0}hXZSeH=%EJ`|}G{xosXS_S!w{>8(V-6%D6uIzrPrn&TvWNU@-2JCnO zo)cmWa0V2tEFYt3b?Vm8e26e9pwOSrI*MA^?VGgye|I*n>6jsqU3NI@dX_ZoSbVDy;6>H}0 zSHEqHw=UgY*H&X3O@kU`(_MQw*L$YvbaW~s@6&U8FMLcdY6;9n5**Zo2Rl9VHgsL*Qh_=3Ujq^l?MD^nrP-Bc zQBfd0WIiCB(Y@I(_E@kFzlLFrHeyrFiK;2`g%#6U5tokc)#Nv{V{Z9ovfAP1XLM!) z5kziIPO)S1FGtzW)>piLQl*3Z4dSD(*Y~{@KGWSCd>z_Jwr74FM*rL{5nz6oa~{lY zbhy*IKQ6L+=Ro)6|2j3^5A=LlBi5wMQy8`b#MaX68tXQWfkc@YV~S+8Vx5n$`uvpbYU_ z!~NPNomqvBq@$br;+=)^AhTqnf9{9B)9EwfQtmAde?*!F{K2Y~pH4Wuh7tB^Va4c# z1~Ih0m9~!W&)^m;I`E4w-q;?Ort9gJj6plIOw9-08cG?yn|>V%+I^pI4V@F~5B<3u z2(cSUJ#9e6zKvXjK7qvfZ@y})baZ{m3+8i<>83NItXw)+r*F#XPPXBu$25H=3^=w4 zS@)Iw2N1aWnP=A1(5(m?&~EN#V5p0pb2|I!zS%ogawnqRa%Ol5-ma8Ri83UurI;eN z=>qYkq)iz8!f9@gPYb#J@8h?oIqVoobMf$5Bxc4o$;`y~iqNDDHepRLGIm?C-%9bs zBejP6%oNNIGmF#q{CUuKY@$W*BRKyWIL#ouG_s(;X@o<~RKS!Pb!9175tV)wB^p=B zr1p?veqNoy&&FEgN}@oz1ou}m1TbCUjEh|CZ_of;acd%dQy`!JnY8^Y;dbF})a94h8CCC~v;hTf6 zC`^2h=@OnnB8L0+v-ichn$@#B+GKajauv(DuB~qKm=FPmP4P9mcxOqs+Ul|eT|+n# z5_>Ml0FIn|UAxdKwbd*5aMx4l+~nwl#Z4E!%qvv=+bV!y|MJJOrqYmX5g5U+qkd?j z%>vIA(RbsY{qcc+p@|3d7e(-5ncuxs2y)ZXdI$GztrORyl`$yls=;YTj>h=#ojxa? z0FmBLX*1ZXvwZ}pN;+KBQg{#RvrZGm!A|ucvO`>Awhb%1{uyA_aP~uo(Cy}l>0Xcw zIAT`_(M0u87RY}9yC(f5Xb~`qp-@ixv5(lp=1~U25Z3`UwQ_CC+G3O5?sp@aL91#I z*vktRCB`K=%Xr&yp@4Sy$3?XqmayWC?5YFg7q zpXOv3u3IYa?CW*hCL>a*l&HS9eHmzY-pB1BCPm1k94Xc{()4nce8={ z)5~BTZIgAa7^*}}UR?Z=oN_Zp{itjao7Yn{B8`RUZ59?(1n_&V4hyPv)L z@hK$oPz|9fUG9%9H`kDUMzFWl)rMBkBfQ3Bh|9UY*@YXs=6-Jo4N==UEf~OZ|QD;p=RvwB&pT(|>l2WV$bkx@NuGKwr^zQm6@{^zxO-YkRZTsQ922{$W@#uP*eM^2LVUKss*(biZWG^_kB@UFO+*3XE|{uk@#&6tf!=XrBE?$}#-Eou}8G$!(^wPkhZDBaq`t2=cZ-<27TAl0}m@eyDjL5x>nF zWkR)GfjgrjV(wemBEEcvxJFa$ez=M>ublP4 zz>C_P(vXgH;B?R{YEOI6m(uw|33lr8cPCU2ulk|Uf2k2EhlxRa7=lyT;^G-~exZ*d z3+Z6P=p;!=-DeS6AlhF|NlgX2=z?5~pvJ#)u?$$?4S5WvQviDi;+?{jyZ?dfMyIk>09kkKPvk>r=@$7Bo{q1mz4OBdp zU^9HpI(`k$$92YV^5)EDU`{R?32~(|7a!~*!&=T|Z#-$- z@oA`Yi4fmPgP?C{O5D%iqL5ZgH(`ARdR^*2BJqC^&87p87nI5OLlO0E26f5J8C-wz z;%#4ap#lBDga3PihN!~4NhG!J%E&5PYamQn%4saKw!#O6 zJ>Y9|;F0=X?=$b!#Nb6GKD?*XX@`@xC$1)$u3Pe$`yrH@mOR@%Q*;$@)&k883j|e@ zVG(a_M9%}0*IKiV;x^q74??^`J{r5*WZ3U_cb*7g(Nj4f9@7{nrTwZc+hX*tP%y;sP^F}47p-AgDld{0g%=(@y~a5(HT5r z9}^Q$9Ksmh+Bm4M15Ln(#n^!lJ+j3rMCYDOc|TXa8{1LveWm~65<%~0vbfOjIoIJg zQDIc-ZOwQqMe_{RVM+w6Yr76Mw6GK8poB!apvW+FLQelDs%m;}p1NhP90h4mn11s^ z-g9V8DsADyb{Tfy3?TDZ^TXrP)t6thpUtaCt9`si~s!EG*7?7@4d3Y7n|Y#~lCmM`MRkAfVK zo5SQ6B?6vX&n=UQc^<_E?TqZ*$b<-XLspBe=JW*ssXM)p-f<>Za+f~Y{Z+_7a5Q?y zmOOx5=65IirNaS)UE)**Q@uG3@GcaLfU{Y5W>|MK%XOiy^|UXQs*?kl%XcOS1t|mw zvt`<|0-s8k-)>p6Dr+%-#uspfvb}Ectw<*^aV(U{4g3Ht5l(=PH&~L3F^i6Y_lxRR zDe^=IpKR{v-C=9VSC<+lzlAoSjsZj^NV9;d90esTL@Y>(&0F{eecEoIs2D1zEB`Dh zp4sI*zJ;-bM#F9qr(VJ|MnMKimhI2wSYfj6YPF6Q1-xOh@K_JiQ6z4C z)(HER?Q|Aq_a*xc59g{|)#80&6-YJq_+TuL^T=6OY0{Ei+nh!|1gRjmHHM_vQdQ*_ zS1Ia@L%H0W(NI4XAnY#f%`n++=|uPR3{8$4PKqejuY4LNI<{I)$wgr!j|;4{#||b( z;mof&sYYYSLf!yz=<%oCu_w}yzuE&t`dQu>EzCw5C+utS*URi1#^s+}4onY9Cqq4= zsb89CP4fEEjzWj>H6uj_OtoCxqo$2B=0%wLrd4 z9E<`!2m7s$@{(7A2SdTH@Tb%=O;4`C7l_OZ4Z#DvJ9x3BJUr>j6+U7 zZU9F~TxBsv?~m6O>vE$C{b2ZoxjLPx?##V8Lj(wj^eOsvuPVyaNse{NoR08MXstL) zPOa@BTAR-$abeyy&~)g>%m_sxVuagdTwx<=NaC-X=Qzvwm$>ZLqoV?;AGNbZ!mBjm zg;6Ku)$Pf6#_;_6d(4*7#ZQ9OAcrX;-4bJ(=`?N`FQw@%ca_D%7VFS~efE_xl%DnMvXp6Y^{a6*A z_x7wlcAu1<$d?S4!&4MyoG z0-3E2&Tmv3UfA-iKFx+xRAaxLfu1rVT`0K=sJn1>4)v+iPJx7~7S`CZ|D-?vFnh=( z;6!*8rM&P&Mypd=ze&=Y!L z-#F!oYdMIbLdWuk3{9o+rYQZyGOO&fOt*;H`5!OEHwrGl{7pITy#&Yy?~lf%R>#f# zpTx#X^H7+aGHG2-20;uy?QStI0Gkr9pesiyW0n7;w%@!SeiR|{JM&usdak~wVd1)p zTA%>OnGv5g&k)UL>0bHG-i{yYC331<3i`KkCZEQG=@(XvyS}O@lpZLfxc@EURsW2g z)z)#{ILL140bS3s>t(|wx?X7iLyD@bXkZkm@mqERu*`#jB17OqZhVdiOL5Amnem?n zaf^dNEgyU4ZUOB7S4Y=7cS^ORDbt;Ah=l3aAZoGDIO?cKTsw+)Ge<0Z{1%r9Eh*2^vMWVke_~TKyP}@LXP_oYkpXypQk9qH@x^AF2u(JL+n}gK^R=Jg<)B z{OLc+_o9KkL;d)S5X~B3n@0T6_pz*F5p~SyZ}q^pk-5?jC)B)A3m3ru$xJ%C4wQFx zCI&*igY;(HlhQSz_%VzM<5d$50Z3IBr_o&9Sf-G4?P@cRNFrgDy0x;?Jl@a|Eb$Nv z+54Jsh1y0zUq68rrReV@UAJj$kp)q!HzG~)YBxi-KyvxO7&vq~e) z@h9{aqb`5&Un{MUOHyhpxOhyd$Ch4!3KtL1CY!LtU(FYt?i;TzcIJcPRp_ETHvezK zStJCxp3(ZzRZX0(Z&G+Zy1Gc5(YdJYk~FljI?a3;Wd#!x-r5_PRZgYE4kROu|Ke02ssqv zrtuO;l(lc}cJ3{fC50T|EGt^D(>|pq{ZR2>mix_q)2zsVmd4IX#VRJoB_QVzvAu^j z0FBR*u$>_LIrvePM5wS@paoci>*6_Rj8QPgMblsfm%uXW_$7Y(16`P^yR0WsedxBOTM>zoIewqgfwkg*lxe3AF0rkXx(xsY{|;Ln0j|8&Kn=x? zWoUog{EAiGxn-=wbe_Quwlpl)^%&FAIY{fSbmlnvbtAdh_n- z4X*`rnd&Lkz*CS+B#V4-Uv}%FQxZALDQFqy#Fo{#7nMDRs)luRcrrl zlc$u0rc{)3ssw5qWhO8$qxZl;dnR+ZEIc`{ZR{V}AB#k~B&v=K8}_F|wUyN}@H7S| z?~*pX!i94ygFvj8K(UuEnFnc+NPo5^QzYQ9fIuu4bQ(l*vh)pEWicscN5)y-6aq!K z30P0%J%J3edP9HX-eS71?o|o7k-ByM)eYm$oS0PvGyTnjPT@8Gup|SmD8hiIAfpgx z(PIGzb3`!y=FVY}8&wOaeX&LAdVSsC_^vG?9^NfwMa%FLYe=%3g0ZXB z)}J_piz#lr^uUF;1eYD(fv6AJ$1lq>@kokC+W_OP>0>>E`(G_MOdwjYrJ*s3+rSu| z!&Es}#|)DL!fynMxC><;eXJTO&E=4M$ktPGITJGAJq3OA74o>i8u8-{9=#ru6$*}l zfsEhwKSoIkxf83`1OmzbUXGYH^~o_IsP31kIuUH2)Rsl{9Rd7wR5c64()*Idvkg42<|pqv1@4acFTXcQ7}= mIA->8L=XrW52erm00000000000000000000000000002sv1uXz literal 0 HcmV?d00001 diff --git a/boards/arm/nucleo_c031c6/doc/index.rst b/boards/arm/nucleo_c031c6/doc/index.rst new file mode 100644 index 000000000000..9c1a4c02f2aa --- /dev/null +++ b/boards/arm/nucleo_c031c6/doc/index.rst @@ -0,0 +1,135 @@ +.. _nucleo_c031c6_board: + +ST Nucleo C031C6 +################ + +Overview +******** +The STM32 Nucleo-64 development board with STM32C031C6 MCU, supports Arduino and ST morpho connectivity. + +The STM32 Nucleo board provides an affordable, and flexible way for users to try out new concepts, +and build prototypes with the STM32 microcontroller, choosing from the various +combinations of performance, power consumption and features. + +The STM32 Nucleo board integrates the ST-LINK/V2-1 debugger and programmer. + +The STM32 Nucleo board comes with the STM32 comprehensive software HAL library together +with various packaged software examples. + +.. image:: img/nucleo_c031c6.jpg + :align: center + :alt: Nucleo C031C6 + +More information about the board can be found at the `Nucleo C031C6 website`_. + +Hardware +******** +Nucleo C031C6 provides the following hardware components: + +- STM32 microcontroller in 48-pin package featuring 32 Kbytes of Flash memory + and 12 Kbytes of SRAM. +- Extension resource: + + - Arduino* Uno V3 connectivity + +- On-board ST-LINK/V2-1 debugger/programmer with SWD connector: + +- Flexible board power supply: + + - USB VBUS or external source (3.3V, 5V, 7 - 12V) + - Current consumption measurement (IDD) + +- Four LEDs: + + - USB communication (LD1), USB power fault LED (LD2), power LED (LD3), + user LED (LD4) + +- Two push-button: USER and RESET + +- USB re-enumeration capability. Three different interfaces supported on USB: + + - Virtual COM port + - Mass storage + - Debug port + +More information about STM32C031C6 can be found here: +`STM32C0x1 reference manual`_ + +Supported Features +================== + +The Zephyr nucleo_c031c6 board configuration supports the following hardware features: + ++-----------+------------+-------------------------------------+ +| Interface | Controller | Driver/Component | ++===========+============+=====================================+ +| NVIC | on-chip | nested vector interrupt controller | ++-----------+------------+-------------------------------------+ +| UART | on-chip | serial port-polling; | +| | | serial port-interrupt | ++-----------+------------+-------------------------------------+ +| PINMUX | on-chip | pinmux | ++-----------+------------+-------------------------------------+ +| GPIO | on-chip | gpio | ++-----------+------------+-------------------------------------+ +| CLOCK | on-chip | reset and clock control | ++-----------+------------+-------------------------------------+ + +Other hardware features are not yet supported in this Zephyr port. + +The default configuration can be found in the defconfig file: +``boards/arm/nucleo_c031c6/nucleo_c031c6_defconfig`` + +Connections and IOs +=================== + +Each of the GPIO pins can be configured by software as output (push-pull or open-drain), as +input (with or without pull-up or pull-down), or as peripheral alternate function. Most of the +GPIO pins are shared with digital or analog alternate functions. All GPIOs are high current +capable except for analog inputs. + +Default Zephyr Peripheral Mapping: +---------------------------------- + +- UART_2 TX/RX : PA2/PA3 (ST-Link Virtual Port Com) +- LD4 : PA5 + +For mode details please refer to `STM32 Nucleo-64 board User Manual`_. + +Programming and Debugging +************************* + +Applications for the ``nucleo_c031c6`` board configuration can be built and +flashed in the usual way (see :ref:`build_an_application` and +:ref:`application_run` for more details). + +Flashing +======== + +Nucleo C031C6 board includes an ST-LINK/V2-1 embedded debug tool interface. + +Flashing an application to Nucleo C031C6 +---------------------------------------- + +Here is an example for the :ref:`blinky-sample` application. + +.. zephyr-app-commands:: + :zephyr-app: samples/basic/blinky + :board: nucleo_c031c6 + :goals: build flash + +You will see the LED blinking every second. + +References +********** + +.. target-notes:: + +.. _Nucleo C031C6 website: + http://www.st.com/en/evaluation-tools/nucleo-c031c6.html + +.. _STM32C0x1 reference manual: + https://www.st.com/resource/en/reference_manual/rm0490-stm32c0x1-advanced-armbased-64bit-mcus-stmicroelectronics.pdf + +.. _STM32 Nucleo-64 board User Manual: + https://www.st.com/resource/en/user_manual/um2953-stm32c0-nucleo64-board-mb1717-stmicroelectronics.pdf diff --git a/boards/arm/nucleo_c031c6/nucleo_c031c6.dts b/boards/arm/nucleo_c031c6/nucleo_c031c6.dts new file mode 100644 index 000000000000..a7ae659be906 --- /dev/null +++ b/boards/arm/nucleo_c031c6/nucleo_c031c6.dts @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023 Benjamin Björnsson + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; +#include +#include +#include "arduino_r3_connector.dtsi" + +/ { + model = "STMicroelectronics STM32C031C6-NUCLEO board"; + compatible = "st,stm32c031c6-nucleo"; + + chosen { + zephyr,console = &usart2; + zephyr,shell-uart = &usart2; + zephyr,sram = &sram0; + zephyr,flash = &flash0; + }; + + leds { + compatible = "gpio-leds"; + green_led_4: led_4 { + gpios = <&gpioa 5 GPIO_ACTIVE_HIGH>; + label = "User LD4"; + }; + }; + + gpio_keys { + compatible = "gpio-keys"; + user_button: button { + label = "user button"; + gpios = <&gpioc 13 GPIO_ACTIVE_LOW>; + status = "okay"; + }; + }; + + aliases { + led0 = &green_led_4; + sw0 = &user_button; + }; +}; + +&clk_hse { + clock-frequency = ; + status = "okay"; +}; + +&rcc { + clocks = <&clk_hse>; + clock-frequency = ; + ahb-prescaler = <1>; + apb1-prescaler = <1>; +}; + +&usart1 { + pinctrl-0 = <&usart1_tx_pb6 &usart1_rx_pb7>; + pinctrl-names = "default"; + current-speed = <115200>; +}; + +&usart2 { + pinctrl-0 = <&usart2_tx_pa2 &usart2_rx_pa3>; + pinctrl-names = "default"; + current-speed = <115200>; + status = "okay"; +}; diff --git a/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml b/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml new file mode 100644 index 000000000000..95cbece59819 --- /dev/null +++ b/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml @@ -0,0 +1,12 @@ +identifier: nucleo_c031c6 +name: ST Nucleo C031C6 +type: mcu +arch: arm +toolchain: + - zephyr + - gnuarmemb + - xtools +supported: + - gpio +ram: 12 +flash: 32 diff --git a/boards/arm/nucleo_c031c6/nucleo_c031c6_defconfig b/boards/arm/nucleo_c031c6/nucleo_c031c6_defconfig new file mode 100644 index 000000000000..c955a55e0e45 --- /dev/null +++ b/boards/arm/nucleo_c031c6/nucleo_c031c6_defconfig @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Zephyr Kernel Configuration +CONFIG_SOC_SERIES_STM32C0X=y + +# Platform Configuration +CONFIG_SOC_STM32C031XX=y + +# Serial Drivers +CONFIG_SERIAL=y +CONFIG_UART_INTERRUPT_DRIVEN=y + +# enable console +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y + +# GPIO Controller +CONFIG_GPIO=y + +# Enable Clocks +CONFIG_CLOCK_CONTROL=y + +# enable pin controller +CONFIG_PINCTRL=y From 29ac5d43817a8f384d76485d5be8c36969b92442 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Tue, 14 Mar 2023 16:51:36 +0000 Subject: [PATCH 0205/1906] tests: iterable_sections: stop excluding posix The iterable_sections test is excluding posix. Whatever the issue was at the time this was set, the test seems to run fine on native_posix just fine now. Dropping the exclude to make this test run on native_posix. Signed-off-by: Fabio Baltieri --- tests/misc/iterable_sections/testcase.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/misc/iterable_sections/testcase.yaml b/tests/misc/iterable_sections/testcase.yaml index bb0d84972b51..7e8581946eba 100644 --- a/tests/misc/iterable_sections/testcase.yaml +++ b/tests/misc/iterable_sections/testcase.yaml @@ -1,4 +1,4 @@ tests: misc.iterable_sections: tags: iterable_sections - arch_exclude: posix xtensa + arch_exclude: xtensa From 2815f964404a32200e5dbc517e3a1c5822b7b9ae Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Tue, 31 Jan 2023 15:58:22 +0000 Subject: [PATCH 0206/1906] drivers: move gpio_keys from gpio to input Port the gpio_keys_zephyr driver from the gpio subsystem with a dedicated API to the input subsystem reporting input events. Move the test as well, simplify the cases a bit since the API is simpler now. Signed-off-by: Fabio Baltieri --- doc/hardware/peripherals/gpio.rst | 1 - drivers/CMakeLists.txt | 1 + drivers/Kconfig | 1 + drivers/gpio/CMakeLists.txt | 1 - drivers/gpio/Kconfig | 2 - drivers/input/CMakeLists.txt | 6 + drivers/input/Kconfig | 12 ++ .../Kconfig.gpio_keys} | 2 +- .../input_gpio_keys.c} | 114 +++-------------- .../{gpio => input}/zephyr,gpio-keys.yaml | 0 include/zephyr/drivers/gpio_keys.h | 104 --------------- .../gpio_api_1pin/boards/native_posix.overlay | 28 +--- .../gpio/gpio_api_1pin/src/test_gpio_keys.c | 121 ------------------ tests/drivers/input/gpio_keys/CMakeLists.txt | 9 ++ .../gpio_keys/boards/native_posix.overlay | 25 ++++ .../gpio_keys/boards/native_posix_64.overlay | 6 + tests/drivers/input/gpio_keys/prj.conf | 7 + tests/drivers/input/gpio_keys/src/main.c | 84 ++++++++++++ tests/drivers/input/gpio_keys/testcase.yaml | 8 ++ 19 files changed, 182 insertions(+), 350 deletions(-) create mode 100644 drivers/input/CMakeLists.txt create mode 100644 drivers/input/Kconfig rename drivers/{gpio/Kconfig.zephyr => input/Kconfig.gpio_keys} (89%) rename drivers/{gpio/gpio_keys_zephyr.c => input/input_gpio_keys.c} (64%) rename dts/bindings/{gpio => input}/zephyr,gpio-keys.yaml (100%) delete mode 100644 include/zephyr/drivers/gpio_keys.h delete mode 100644 tests/drivers/gpio/gpio_api_1pin/src/test_gpio_keys.c create mode 100644 tests/drivers/input/gpio_keys/CMakeLists.txt create mode 100644 tests/drivers/input/gpio_keys/boards/native_posix.overlay create mode 100644 tests/drivers/input/gpio_keys/boards/native_posix_64.overlay create mode 100644 tests/drivers/input/gpio_keys/prj.conf create mode 100644 tests/drivers/input/gpio_keys/src/main.c create mode 100644 tests/drivers/input/gpio_keys/testcase.yaml diff --git a/doc/hardware/peripherals/gpio.rst b/doc/hardware/peripherals/gpio.rst index 33b1c4e1e360..9a07809b87da 100644 --- a/doc/hardware/peripherals/gpio.rst +++ b/doc/hardware/peripherals/gpio.rst @@ -18,4 +18,3 @@ API Reference ************* .. doxygengroup:: gpio_interface -.. doxygengroup:: gpio_keys_interface diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index af5bccc8da6c..63af95cedd89 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -38,6 +38,7 @@ add_subdirectory_ifdef(CONFIG_I2C i2c) add_subdirectory_ifdef(CONFIG_I2S i2s) add_subdirectory_ifdef(CONFIG_I3C i3c) add_subdirectory_ifdef(CONFIG_IEEE802154 ieee802154) +add_subdirectory_ifdef(CONFIG_INPUT input) add_subdirectory_ifdef(CONFIG_IPM ipm) add_subdirectory_ifdef(CONFIG_KSCAN kscan) add_subdirectory_ifdef(CONFIG_LED led) diff --git a/drivers/Kconfig b/drivers/Kconfig index ef3059e16cc7..d4259816ade4 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -36,6 +36,7 @@ source "drivers/i2c/Kconfig" source "drivers/i2s/Kconfig" source "drivers/i3c/Kconfig" source "drivers/ieee802154/Kconfig" +source "drivers/input/Kconfig" source "drivers/interrupt_controller/Kconfig" source "drivers/interrupt_controller/Kconfig.shared_irq" source "drivers/ipm/Kconfig" diff --git a/drivers/gpio/CMakeLists.txt b/drivers/gpio/CMakeLists.txt index ec6761667c96..cf52114b73e6 100644 --- a/drivers/gpio/CMakeLists.txt +++ b/drivers/gpio/CMakeLists.txt @@ -73,5 +73,4 @@ zephyr_library_sources_ifdef(CONFIG_GPIO_NPM6001 gpio_npm6001.c) zephyr_library_sources_ifdef(CONFIG_GPIO_RT1718S gpio_rt1718s.c) zephyr_library_sources_ifdef(CONFIG_GPIO_RT1718S gpio_rt1718s_port.c) zephyr_library_sources_ifdef(CONFIG_GPIO_NUMICRO gpio_numicro.c) -zephyr_library_sources_ifdef(CONFIG_GPIO_KEYS_ZEPHYR gpio_keys_zephyr.c) zephyr_library_sources_ifdef(CONFIG_GPIO_HOGS gpio_hogs.c) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 68256a7e9c9b..3e6d21ef6c89 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -181,6 +181,4 @@ source "drivers/gpio/Kconfig.numicro" source "drivers/gpio/Kconfig.bd8lb600fs" -source "drivers/gpio/Kconfig.zephyr" - endif # GPIO diff --git a/drivers/input/CMakeLists.txt b/drivers/input/CMakeLists.txt new file mode 100644 index 000000000000..ed2667341630 --- /dev/null +++ b/drivers/input/CMakeLists.txt @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() +zephyr_library_property(ALLOW_EMPTY TRUE) + +zephyr_library_sources_ifdef(CONFIG_INPUT_GPIO_KEYS input_gpio_keys.c) diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig new file mode 100644 index 000000000000..f62fd27fac22 --- /dev/null +++ b/drivers/input/Kconfig @@ -0,0 +1,12 @@ +# Copyright 2023 Google LLC +# SPDX-License-Identifier: Apache-2.0 + +if INPUT + +menu "Input Drivers" + +source "drivers/input/Kconfig.gpio_keys" + +endmenu # Input Drivers + +endif # INPUT diff --git a/drivers/gpio/Kconfig.zephyr b/drivers/input/Kconfig.gpio_keys similarity index 89% rename from drivers/gpio/Kconfig.zephyr rename to drivers/input/Kconfig.gpio_keys index 0e584a6d66f1..9da697edb535 100644 --- a/drivers/gpio/Kconfig.zephyr +++ b/drivers/input/Kconfig.gpio_keys @@ -1,7 +1,7 @@ # Copyright (c) 2022 Google LLC # SPDX-License-Identifier: Apache-2.0 -config GPIO_KEYS_ZEPHYR +config INPUT_GPIO_KEYS bool "Zephyr GPIO Keys" default y depends on DT_HAS_ZEPHYR_GPIO_KEYS_ENABLED diff --git a/drivers/gpio/gpio_keys_zephyr.c b/drivers/input/input_gpio_keys.c similarity index 64% rename from drivers/gpio/gpio_keys_zephyr.c rename to drivers/input/input_gpio_keys.c index 6a9ce6274f2c..13ef2b9187a1 100644 --- a/drivers/gpio/gpio_keys_zephyr.c +++ b/drivers/input/input_gpio_keys.c @@ -6,14 +6,20 @@ #include #include -#include +#include #include #include -LOG_MODULE_REGISTER(zephyr_gpio_keys, CONFIG_GPIO_LOG_LEVEL); +LOG_MODULE_REGISTER(zephyr_gpio_keys, CONFIG_INPUT_LOG_LEVEL); #define DT_DRV_COMPAT zephyr_gpio_keys +struct gpio_keys_callback { + struct gpio_callback gpio_cb; + uint32_t zephyr_code; + int8_t pin_state; +}; + struct gpio_keys_pin_config { /** GPIO specification from devicetree */ struct gpio_dt_spec spec; @@ -35,7 +41,6 @@ struct gpio_keys_pin_data { }; struct gpio_keys_data { - gpio_keys_callback_handler_t callback; struct gpio_keys_pin_data *pin_data; }; @@ -56,12 +61,12 @@ static void gpio_keys_change_deferred(struct k_work *work) LOG_DBG("gpio_change_deferred %s pin_state=%d, new_pressed=%d, key_index=%d", dev->name, pin_data->cb_data.pin_state, new_pressed, key_index); - /* If gpio changed, invoke callback */ + /* If gpio changed, report the event */ if (new_pressed != pin_data->cb_data.pin_state) { pin_data->cb_data.pin_state = new_pressed; - LOG_DBG("Calling callback %s %d, code=%d", dev->name, new_pressed, + LOG_DBG("Report event %s %d, code=%d", dev->name, new_pressed, pin_cfg->zephyr_code); - data->callback(dev, &pin_data->cb_data, BIT(pin_cfg->spec.pin)); + input_report_key(dev, pin_cfg->zephyr_code, new_pressed, true, K_FOREVER); } } @@ -108,85 +113,6 @@ static int gpio_keys_interrupt_configure(const struct gpio_dt_spec *gpio_spec, return retval; } -static int gpio_keys_zephyr_enable_interrupt(const struct device *dev, - gpio_keys_callback_handler_t gpio_keys_cb) -{ - int retval = -ENODEV; - const struct gpio_keys_config *cfg = dev->config; - struct gpio_keys_data *data = dev->data; - - data->callback = gpio_keys_cb; - for (int i = 0; i < cfg->num_keys; i++) { - retval = gpio_keys_interrupt_configure(&cfg->pin_cfg[i].spec, - &data->pin_data[i].cb_data, - cfg->pin_cfg[i].zephyr_code); - } - - return retval; -} - -static int gpio_keys_zephyr_disable_interrupt(const struct device *dev) -{ - int retval = -ENODEV; - const struct gpio_keys_config *cfg = dev->config; - struct gpio_keys_data *data = dev->data; - const struct gpio_dt_spec *gpio_spec; - - for (int i = 0; i < cfg->num_keys; i++) { - gpio_spec = &cfg->pin_cfg[i].spec; - retval = z_impl_gpio_pin_interrupt_configure(gpio_spec->port, gpio_spec->pin, - GPIO_INT_MODE_DISABLED); - if (data->pin_data[i].cb_data.gpio_cb.handler) { - retval = gpio_remove_callback(gpio_spec->port, - &data->pin_data[i].cb_data.gpio_cb); - memset(&data->pin_data[i].cb_data, 0, sizeof(struct gpio_keys_callback)); - } - LOG_DBG("disable interrupt [0x%p, %d], rv=%d", gpio_spec->port, gpio_spec->pin, - retval); - } - - return retval; -} - -static int gpio_keys_get_gpio_port_logical(const struct device *gpio_dev, gpio_port_value_t *value) -{ - const struct gpio_driver_data *const data = gpio_dev->data; - - int ret = z_impl_gpio_port_get_raw(gpio_dev, value); - - if (ret == 0) { - *value ^= data->invert; - } - - return ret; -} - -static int gpio_keys_zephyr_get_pin(const struct device *dev, uint32_t idx) -{ - const struct gpio_keys_config *cfg = dev->config; - const struct gpio_dt_spec *gpio_spec = &cfg->pin_cfg[idx].spec; - const struct device *gpio_dev = gpio_spec->port; - const struct gpio_driver_config __maybe_unused *gpio_cfg = gpio_dev->config; - int ret; - gpio_port_value_t value; - - __ASSERT((gpio_cfg->port_pin_mask & (gpio_port_pins_t)BIT(gpio_spec->pin)) != 0U, - "Unsupported pin"); - - ret = gpio_keys_get_gpio_port_logical(gpio_dev, &value); - - if (ret == 0) { - ret = (value & (gpio_port_pins_t)BIT(gpio_spec->pin)) != 0 ? 1 : 0; - } - - if (ret < 0) { - LOG_ERR("Cannot read %s, ret=%d", dev->name, ret); - ret = 0; - } - - return ret; -} - static int gpio_keys_init(const struct device *dev) { struct gpio_keys_data *data = dev->data; @@ -209,17 +135,19 @@ static int gpio_keys_init(const struct device *dev) data->pin_data[i].dev = dev; k_work_init_delayable(&data->pin_data[i].work, gpio_keys_change_deferred); + + ret = gpio_keys_interrupt_configure(&cfg->pin_cfg[i].spec, + &data->pin_data[i].cb_data, + cfg->pin_cfg[i].zephyr_code); + if (ret != 0) { + LOG_ERR("Pin %d interrupt configuration failed: %d", i, ret); + return ret; + } } return 0; } -static const struct gpio_keys_api gpio_keys_zephyr_api = { - .enable_interrupt = gpio_keys_zephyr_enable_interrupt, - .disable_interrupt = gpio_keys_zephyr_disable_interrupt, - .get_pin = gpio_keys_zephyr_get_pin, -}; - #define GPIO_KEYS_CFG_DEF(node_id) \ { \ .spec = GPIO_DT_SPEC_GET(node_id, gpios), \ @@ -240,7 +168,7 @@ static const struct gpio_keys_api gpio_keys_zephyr_api = { .pin_data = gpio_keys_pin_data_##i, \ }; \ DEVICE_DT_INST_DEFINE(i, &gpio_keys_init, NULL, &gpio_keys_data_##i, \ - &gpio_keys_config_##i, POST_KERNEL, CONFIG_GPIO_INIT_PRIORITY, \ - &gpio_keys_zephyr_api); + &gpio_keys_config_##i, POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \ + NULL); DT_INST_FOREACH_STATUS_OKAY(GPIO_KEYS_INIT) diff --git a/dts/bindings/gpio/zephyr,gpio-keys.yaml b/dts/bindings/input/zephyr,gpio-keys.yaml similarity index 100% rename from dts/bindings/gpio/zephyr,gpio-keys.yaml rename to dts/bindings/input/zephyr,gpio-keys.yaml diff --git a/include/zephyr/drivers/gpio_keys.h b/include/zephyr/drivers/gpio_keys.h deleted file mode 100644 index 18a4faf7e032..000000000000 --- a/include/zephyr/drivers/gpio_keys.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2022 Google LLC - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef ZEPHYR_INCLUDE_DRIVERS_GPIO_KEYS_H_ -#define ZEPHYR_INCLUDE_DRIVERS_GPIO_KEYS_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct gpio_keys_callback { - struct gpio_callback gpio_cb; - uint32_t zephyr_code; - int8_t pin_state; -}; - -typedef void (*gpio_keys_callback_handler_t)(const struct device *port, - struct gpio_keys_callback *cb, gpio_port_pins_t pins); -/** - * @brief GPIO Keys Driver APIs - * @defgroup gpio_keys_interface GPIO KeysDriver APIs - * @ingroup io_interfaces - * @{ - */ - -__subsystem struct gpio_keys_api { - int (*enable_interrupt)(const struct device *dev, gpio_keys_callback_handler_t cb); - int (*disable_interrupt)(const struct device *dev); - int (*get_pin)(const struct device *dev, uint32_t idx); -}; - -/** - * @brief Enable interrupt - * - * @param dev Pointer to device structure for the driver instance. - * @param cb Function callback to be invoked after GPIO key has been debounced - * - * @return 0 If successful - */ -__syscall int gpio_keys_enable_interrupt(const struct device *dev, gpio_keys_callback_handler_t cb); - -static inline int z_impl_gpio_keys_enable_interrupt(const struct device *dev, - gpio_keys_callback_handler_t cb) -{ - struct gpio_keys_api *api; - - api = (struct gpio_keys_api *)dev->api; - return api->enable_interrupt(dev, cb); -} - -/** - * @brief Disable interrupt - * - * @param dev Pointer to device structure for the driver instance. - * - * @return 0 If successful - */ -__syscall int gpio_keys_disable_interrupt(const struct device *dev); - -static inline int z_impl_gpio_keys_disable_interrupt(const struct device *dev) -{ - struct gpio_keys_api *api; - - api = (struct gpio_keys_api *)dev->api; - return api->disable_interrupt(dev); -} - -/** - * @brief Get the logical level of GPIO Key - * - * @param dev Pointer to device structure for the driver instance. - * @param idx GPIO Key index in device tree - * - * @retval 0 If successful. - * @retval -EIO I/O error when accessing an external GPIO chip. - * @retval -EWOULDBLOCK if operation would block. - */ -__syscall int gpio_keys_get_pin(const struct device *dev, uint32_t idx); - -static inline int z_impl_gpio_keys_get_pin(const struct device *dev, uint32_t idx) -{ - struct gpio_keys_api *api; - - api = (struct gpio_keys_api *)dev->api; - return api->get_pin(dev, idx); -} - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#include - -#endif /* ZEPHYR_INCLUDE_DRIVERS_GPIO_KEYS_H_ */ diff --git a/tests/drivers/gpio/gpio_api_1pin/boards/native_posix.overlay b/tests/drivers/gpio/gpio_api_1pin/boards/native_posix.overlay index cb99d2694661..ed09218f14e3 100644 --- a/tests/drivers/gpio/gpio_api_1pin/boards/native_posix.overlay +++ b/tests/drivers/gpio/gpio_api_1pin/boards/native_posix.overlay @@ -5,31 +5,5 @@ */ &gpio0 { - ngpios = <3>; -}; - -/ { - gpio-keys0 { - compatible = "zephyr,gpio-keys"; - debounce-interval-ms = <30>; - - voldown_button: button_0 { - gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; - zephyr,code = <10>; - }; - volup_button: button_1 { - gpios = <&gpio0 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; - zephyr,code = <11>; - }; - }; - - gpio-keys1 { - compatible = "zephyr,gpio-keys"; - debounce-interval-ms = <100>; - - power_button: button_2 { - gpios = <&gpio0 2 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; - zephyr,code = <20>; - }; - }; + ngpios = <2>; }; diff --git a/tests/drivers/gpio/gpio_api_1pin/src/test_gpio_keys.c b/tests/drivers/gpio/gpio_api_1pin/src/test_gpio_keys.c deleted file mode 100644 index 45b33867662f..000000000000 --- a/tests/drivers/gpio/gpio_api_1pin/src/test_gpio_keys.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2022 Google LLC - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "zephyr/sys/util.h" -#include -#include -#include -#include -#include - -#include - -LOG_MODULE_REGISTER(gpio_keys_test, LOG_LEVEL_DBG); - -#if DT_NODE_EXISTS(DT_NODELABEL(voldown_button)) - -const struct device *test_gpio_keys_dev = DEVICE_DT_GET(DT_PARENT(DT_NODELABEL(voldown_button))); -#define BUTTON_0_IDX DT_NODE_CHILD_IDX(DT_NODELABEL(voldown_button)) -#define BUTTON_1_IDX DT_NODE_CHILD_IDX(DT_NODELABEL(volup_button)) - -struct gpio_keys_pin_config { - /** GPIO specification from devicetree */ - struct gpio_dt_spec spec; - /** Zephyr code from devicetree */ - uint32_t zephyr_code; -}; -struct gpio_keys_config { - /** Debounce interval in milliseconds from devicetree */ - uint32_t debounce_interval_ms; - const int num_keys; - const struct gpio_keys_pin_config *pin_cfg; -}; - -/** - * @brief Test Suite: Verifies gpio_keys_config functionality. - */ -ZTEST_SUITE(gpio_keys, NULL, NULL, NULL, NULL, NULL); - -/** - * @brief TestPurpose: Verify gpio_keys_config pressed raw. - * - */ -ZTEST(gpio_keys, test_gpio_keys_pressed) -{ - const struct gpio_keys_config *config = test_gpio_keys_dev->config; - const struct gpio_keys_pin_config *pin_cfg = &config->pin_cfg[BUTTON_0_IDX]; - const struct gpio_dt_spec *spec = &pin_cfg->spec; - - zassert_ok(gpio_pin_configure(spec->port, spec->pin, GPIO_INPUT)); - - zassert_ok(gpio_emul_input_set(spec->port, spec->pin, 1)); - zassert_equal(1, gpio_keys_get_pin(test_gpio_keys_dev, BUTTON_0_IDX)); - - zassert_ok(gpio_emul_input_set(spec->port, spec->pin, 0)); - zassert_equal(0, gpio_keys_get_pin(test_gpio_keys_dev, BUTTON_0_IDX)); -} - -/** - * @brief TestPurpose: Verify button interrupt. - * - */ -uint32_t gpio_keys_interrupt_called; -void test_gpio_keys_cb_handler(const struct device *dev, struct gpio_keys_callback *cbdata, - uint32_t pins) -{ - LOG_DBG("GPIO_KEY %s pressed, pins=%d, zephyr_code=%u, pin_state=%d", dev->name, pins, - cbdata->zephyr_code, cbdata->pin_state); - gpio_keys_interrupt_called = cbdata->zephyr_code; -} - -ZTEST(gpio_keys, test_gpio_keys_interrupt) -{ - int button_idx[] = {BUTTON_0_IDX, BUTTON_1_IDX}; - int num_gpio_keys = ARRAY_SIZE(button_idx); - const struct gpio_keys_config *config = test_gpio_keys_dev->config; - const struct gpio_keys_pin_config *pin_cfg; - const struct gpio_dt_spec *spec; - - for (int i = 0; i < num_gpio_keys; i++) { - pin_cfg = &config->pin_cfg[button_idx[i]]; - spec = &pin_cfg->spec; - - LOG_DBG("GPIO_KEY config=[0x%p, %d]", config->debounce_interval_ms, - pin_cfg->zephyr_code); - LOG_DBG("GPIO_KEY spec=[0x%p, %d]", spec->port, spec->pin); - - zassert_ok(gpio_pin_configure(spec->port, spec->pin, GPIO_INPUT)); - zassert_ok(gpio_keys_disable_interrupt(test_gpio_keys_dev), NULL); - k_sleep(K_MSEC(500)); - - /* Check interrupts are disabled */ - gpio_keys_interrupt_called = 0; - zassert_ok(gpio_emul_input_set(spec->port, spec->pin, 0)); - k_sleep(K_MSEC(1000)); - zassert_ok(gpio_emul_input_set(spec->port, spec->pin, 1)); - k_sleep(K_MSEC(1000)); - zassert_equal(gpio_keys_interrupt_called, 0); - - zassert_ok( - gpio_keys_enable_interrupt(test_gpio_keys_dev, test_gpio_keys_cb_handler), - NULL); - zassert_ok(gpio_emul_input_set(spec->port, spec->pin, 0)); - k_sleep(K_MSEC(1000)); - - gpio_keys_interrupt_called = 0; - zassert_ok(gpio_emul_input_set(spec->port, spec->pin, 1)); - - /* Check interrupt doesn't prematurely fires */ - k_sleep(K_MSEC(config->debounce_interval_ms / 2)); - zassert_equal(gpio_keys_interrupt_called, 0); - - /* Check interrupt fires after debounce interval */ - k_sleep(K_MSEC(config->debounce_interval_ms)); - zassert_equal(gpio_keys_interrupt_called, pin_cfg->zephyr_code); - } -} - -#endif /* DT_NODE_EXISTS(DT_NODELABEL(voldown_button)) */ diff --git a/tests/drivers/input/gpio_keys/CMakeLists.txt b/tests/drivers/input/gpio_keys/CMakeLists.txt new file mode 100644 index 000000000000..96e819c83ba4 --- /dev/null +++ b/tests/drivers/input/gpio_keys/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(gpio_keys) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/drivers/input/gpio_keys/boards/native_posix.overlay b/tests/drivers/input/gpio_keys/boards/native_posix.overlay new file mode 100644 index 000000000000..c878e8c50160 --- /dev/null +++ b/tests/drivers/input/gpio_keys/boards/native_posix.overlay @@ -0,0 +1,25 @@ +/* + * Copyright 2023 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&gpio0 { + ngpios = <2>; +}; + +/ { + buttons: gpio-keys0 { + compatible = "zephyr,gpio-keys"; + debounce-interval-ms = <30>; + + voldown_button: button_0 { + gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + zephyr,code = <10>; + }; + volup_button: button_1 { + gpios = <&gpio0 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + zephyr,code = <11>; + }; + }; +}; diff --git a/tests/drivers/input/gpio_keys/boards/native_posix_64.overlay b/tests/drivers/input/gpio_keys/boards/native_posix_64.overlay new file mode 100644 index 000000000000..166e6f02e82d --- /dev/null +++ b/tests/drivers/input/gpio_keys/boards/native_posix_64.overlay @@ -0,0 +1,6 @@ +/* + * Copyright 2023 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "native_posix.overlay" diff --git a/tests/drivers/input/gpio_keys/prj.conf b/tests/drivers/input/gpio_keys/prj.conf new file mode 100644 index 000000000000..0da3a38cadff --- /dev/null +++ b/tests/drivers/input/gpio_keys/prj.conf @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_GPIO=y +CONFIG_INPUT=y +CONFIG_INPUT_MODE_SYNCHRONOUS=y diff --git a/tests/drivers/input/gpio_keys/src/main.c b/tests/drivers/input/gpio_keys/src/main.c new file mode 100644 index 000000000000..09d78c3dc6be --- /dev/null +++ b/tests/drivers/input/gpio_keys/src/main.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "zephyr/sys/util.h" +#include +#include +#include +#include +#include + +static const struct device *const test_gpio_keys_dev = DEVICE_DT_GET(DT_NODELABEL(buttons)); +#define BUTTON_0_IDX DT_NODE_CHILD_IDX(DT_NODELABEL(voldown_button)) + +struct gpio_keys_pin_config { + /** GPIO specification from devicetree */ + struct gpio_dt_spec spec; + /** Zephyr code from devicetree */ + uint32_t zephyr_code; +}; +struct gpio_keys_config { + /** Debounce interval in milliseconds from devicetree */ + uint32_t debounce_interval_ms; + const int num_keys; + const struct gpio_keys_pin_config *pin_cfg; +}; + +/** + * @brief Test Suite: Verifies gpio_keys_config functionality. + */ +ZTEST_SUITE(gpio_keys, NULL, NULL, NULL, NULL, NULL); + +static int event_count; +static uint16_t last_code; +static bool last_val; +static void test_gpio_keys_cb_handler(struct input_event *evt) +{ + TC_PRINT("GPIO_KEY %s pressed, zephyr_code=%u, value=%d\n", + evt->dev->name, evt->code, evt->value); + event_count++; + last_code = evt->code; + last_val = evt->value; +} +INPUT_LISTENER_CB_DEFINE(test_gpio_keys_dev, test_gpio_keys_cb_handler); + +/** + * @brief TestPurpose: Verify gpio_keys_config pressed raw. + * + */ +ZTEST(gpio_keys, test_gpio_keys_pressed) +{ + const struct gpio_keys_config *config = test_gpio_keys_dev->config; + const struct gpio_keys_pin_config *pin_cfg = &config->pin_cfg[BUTTON_0_IDX]; + const struct gpio_dt_spec *spec = &pin_cfg->spec; + + last_code = 0; + last_val = false; + + zassert_ok(gpio_emul_input_set(spec->port, spec->pin, 0)); + + /* Check interrupt doesn't prematurely fires */ + k_sleep(K_MSEC(config->debounce_interval_ms / 2)); + zassert_equal(event_count, 0); + + /* Check interrupt fires after debounce interval */ + k_sleep(K_MSEC(config->debounce_interval_ms)); + zassert_equal(event_count, 1); + zassert_equal(last_code, pin_cfg->zephyr_code); + zassert_equal(last_val, true); + + zassert_ok(gpio_emul_input_set(spec->port, spec->pin, 1)); + + /* Check interrupt doesn't prematurely fires */ + k_sleep(K_MSEC(config->debounce_interval_ms / 2)); + zassert_equal(event_count, 1); + + /* Check interrupt fires after debounce interval */ + k_sleep(K_MSEC(config->debounce_interval_ms)); + zassert_equal(event_count, 2); + zassert_equal(last_code, pin_cfg->zephyr_code); + zassert_equal(last_val, false); +} diff --git a/tests/drivers/input/gpio_keys/testcase.yaml b/tests/drivers/input/gpio_keys/testcase.yaml new file mode 100644 index 000000000000..476e2436163c --- /dev/null +++ b/tests/drivers/input/gpio_keys/testcase.yaml @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +tests: + drivers.input.gpio_keys: + tags: drivers input + platform_allow: native_posix native_posix_64 + integration_platforms: + - native_posix From f057010eea5a909da8043228423330719c6fbd1b Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Tue, 7 Mar 2023 10:03:02 +0000 Subject: [PATCH 0207/1906] samples: input_dump: add a board overlay for testing zephyr,gpio-keys Add an initial board overlay in the input_dump directory for testing zephyr,gpio-keys. This takes the exsiting "gpio-keys" node, changes the compatible to the one used by the gpio keys input driver and set some codes. Signed-off-by: Fabio Baltieri --- .../boards/nrf52dk_nrf52832.overlay | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 samples/subsys/input/input_dump/boards/nrf52dk_nrf52832.overlay diff --git a/samples/subsys/input/input_dump/boards/nrf52dk_nrf52832.overlay b/samples/subsys/input/input_dump/boards/nrf52dk_nrf52832.overlay new file mode 100644 index 000000000000..d0a3852b7517 --- /dev/null +++ b/samples/subsys/input/input_dump/boards/nrf52dk_nrf52832.overlay @@ -0,0 +1,25 @@ +/* + * Copyright 2023 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/ { + buttons { + compatible = "zephyr,gpio-keys"; + button_0 { + zephyr,code = ; + }; + button_1 { + zephyr,code = ; + }; + button_2 { + zephyr,code = ; + }; + button_3 { + zephyr,code = ; + }; + }; +}; From b9dabf04f0e0af673af3e91dcb509962e4cddf0b Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Tue, 7 Mar 2023 11:51:32 +0000 Subject: [PATCH 0208/1906] dts: bindings: zephyr,gpio-keys require code and add docs The zephyr,gpio-keys is now emitting input events, so it makes sense to require a key code to be set. Change the zephyr,code property to be required and add an example in the binding description. Signed-off-by: Fabio Baltieri --- dts/bindings/input/gpio-keys.yaml | 2 +- dts/bindings/input/zephyr,gpio-keys.yaml | 26 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/dts/bindings/input/gpio-keys.yaml b/dts/bindings/input/gpio-keys.yaml index bbf08d95212e..0a05cd631f3e 100644 --- a/dts/bindings/input/gpio-keys.yaml +++ b/dts/bindings/input/gpio-keys.yaml @@ -27,4 +27,4 @@ child-binding: zephyr,code: type: int default: 0 - description: Key / Axis code to emit. + description: Key code to emit. diff --git a/dts/bindings/input/zephyr,gpio-keys.yaml b/dts/bindings/input/zephyr,gpio-keys.yaml index 6a85e240415d..c4787718e264 100644 --- a/dts/bindings/input/zephyr,gpio-keys.yaml +++ b/dts/bindings/input/zephyr,gpio-keys.yaml @@ -1,8 +1,32 @@ # Copyright (c) 2022 Google LLC # SPDX-License-Identifier: Apache-2.0 -description: Zephyr GPIO KEYS parent node +description: | + Zephyr Input GPIO KEYS parent node + + This defines a group of buttons that can generate input events. Each button + is defined in a child node of the zephyr,gpio-keys node and define a specific + key code. + + For example: + + #include + + / { + buttons { + compatible = "zephyr,gpio-keys"; + button_0 { + gpios = <&gpio0 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + zephyr,code = ; + }; + }; + }; compatible: "zephyr,gpio-keys" include: [gpio-keys.yaml] + +child-binding: + properties: + zephyr,code: + required: true From e155b2dc5fb2bb1bb19fa06086ae788c399c4aaa Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Tue, 14 Mar 2023 22:04:46 +0000 Subject: [PATCH 0209/1906] MAINTAINERS: add drivers/input/ to the input file list Add the driver/input subdirectory to the list of paths maintained under input. Signed-off-by: Fabio Baltieri --- MAINTAINERS.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index a16797280d95..a46a27cc2a7c 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -1427,6 +1427,7 @@ Input: - gmarull files: - doc/services/input/ + - drivers/input/ - include/zephyr/dt-bindings/input/ - include/zephyr/input/ - samples/subsys/input/ From b23c330c63f77883ec255ea7b5ea77ee1421fabc Mon Sep 17 00:00:00 2001 From: Jonathan Rico Date: Tue, 7 Mar 2023 10:09:38 +0100 Subject: [PATCH 0210/1906] Bluetooth: host: shrink bt_l2cap_le_chan size Most of this struct is bookkeeping for the dynamic channels. This isn't needed for e.g., a simple peripheral using GATT. With a peripheral_hr build for nrf52840dk_nrf52840, we save 280 bytes of RAM. Signed-off-by: Jonathan Rico --- include/zephyr/bluetooth/l2cap.h | 2 +- subsys/bluetooth/host/l2cap.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/zephyr/bluetooth/l2cap.h b/include/zephyr/bluetooth/l2cap.h index 08272ec8adcc..b5655bd19f81 100644 --- a/include/zephyr/bluetooth/l2cap.h +++ b/include/zephyr/bluetooth/l2cap.h @@ -172,6 +172,7 @@ struct bt_l2cap_le_chan { /** Channel Transmission Endpoint */ struct bt_l2cap_le_endpoint tx; +#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL) /** Channel Transmission queue */ struct k_fifo tx_queue; /** Channel Pending Transmission buffer */ @@ -185,7 +186,6 @@ struct bt_l2cap_le_chan { struct k_work rx_work; struct k_fifo rx_queue; -#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL) bt_l2cap_chan_state_t state; /** Remote PSM to be connected */ uint16_t psm; diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index 1433831b2845..225ca4c20dd5 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -1865,7 +1865,6 @@ static void l2cap_chan_tx_resume(struct bt_l2cap_le_chan *ch) k_work_submit(&ch->tx_work); } -#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL) static void resume_all_channels(struct bt_conn *conn, void *data) { struct bt_l2cap_chan *chan; @@ -1874,7 +1873,6 @@ static void resume_all_channels(struct bt_conn *conn, void *data) l2cap_chan_tx_resume(BT_L2CAP_LE_CHAN(chan)); } } -#endif static void l2cap_chan_sdu_sent(struct bt_conn *conn, void *user_data, int err) { From fd2191b2b1dcb0e64be635b0fc0a1c2050e39137 Mon Sep 17 00:00:00 2001 From: Lucas Tamborrino Date: Thu, 16 Feb 2023 14:34:08 -0300 Subject: [PATCH 0211/1906] dts: esp32s3: Add wdt support Add watchdog support for esp32s3 Signed-off-by: Lucas Tamborrino --- boards/xtensa/esp32s3_devkitm/doc/index.rst | 2 ++ .../xtensa/esp32s3_devkitm/esp32s3_devkitm.dts | 5 +++++ .../xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml | 1 + dts/xtensa/espressif/esp32s3.dtsi | 17 +++++++++++++++++ 4 files changed, 25 insertions(+) diff --git a/boards/xtensa/esp32s3_devkitm/doc/index.rst b/boards/xtensa/esp32s3_devkitm/doc/index.rst index 0bcb0fb802fa..f65feafac015 100644 --- a/boards/xtensa/esp32s3_devkitm/doc/index.rst +++ b/boards/xtensa/esp32s3_devkitm/doc/index.rst @@ -94,6 +94,8 @@ Current Zephyr's ESP32-S3-DevKitM board supports the following features: +------------+------------+-------------------------------------+ | Timers | on-chip | counter | +------------+------------+-------------------------------------+ +| Watchdog | on-chip | watchdog | ++------------+------------+-------------------------------------+ Prerequisites ------------- diff --git a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts index 8c3c4fcc5f74..cc62ac7be527 100644 --- a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts +++ b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts @@ -14,6 +14,7 @@ aliases { i2c-0 = &i2c0; + watchdog0 = &wdt0; }; chosen { @@ -104,6 +105,10 @@ status = "disabled"; }; +&wdt0 { + status = "okay"; +}; + &flash0 { status = "okay"; partitions { diff --git a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml index e290263c3b89..b7e19268e9d0 100644 --- a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml +++ b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml @@ -10,6 +10,7 @@ supported: - i2c - spi - counter + - watchdog testing: ignore_tags: - net diff --git a/dts/xtensa/espressif/esp32s3.dtsi b/dts/xtensa/espressif/esp32s3.dtsi index 6500f2ffce39..faa8e029c48a 100644 --- a/dts/xtensa/espressif/esp32s3.dtsi +++ b/dts/xtensa/espressif/esp32s3.dtsi @@ -234,5 +234,22 @@ interrupt-parent = <&intc>; }; + wdt0: watchdog@6001f048 { + compatible = "espressif,esp32-watchdog"; + reg = <0x6001f048 0x20>; + interrupts = ; + interrupt-parent = <&intc>; + clocks = <&rtc ESP32_TIMG0_MODULE>; + status = "disabled"; + }; + + wdt1: watchdog@60020048 { + compatible = "espressif,esp32-watchdog"; + reg = <0x60020048 0x20>; + interrupts = ; + interrupt-parent = <&intc>; + clocks = <&rtc ESP32_TIMG1_MODULE>; + status = "disabled"; + }; }; }; From 517a977e847160b4d726b2a2f2342d069519c317 Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Mon, 13 Mar 2023 23:26:22 -0600 Subject: [PATCH 0212/1906] spi: initialize spi_sam spin locks Uninitialized sam spinlocks were causing an error if the stack happens to have 'thread_cpu' memory set to something other than 0. Signed-off-by: Yuval Peress --- drivers/spi/spi_sam.c | 49 ++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/drivers/spi/spi_sam.c b/drivers/spi/spi_sam.c index 38ba82d1be0e..c3821cd61706 100644 --- a/drivers/spi/spi_sam.c +++ b/drivers/spi/spi_sam.c @@ -43,12 +43,27 @@ struct spi_sam_config { /* Device run time data */ struct spi_sam_data { struct spi_context ctx; + struct k_spinlock lock; #ifdef CONFIG_SPI_SAM_DMA struct k_sem dma_sem; #endif /* CONFIG_SPI_SAM_DMA */ }; +static inline k_spinlock_key_t spi_spin_lock(const struct device *dev) +{ + struct spi_sam_data *data = dev->data; + + return k_spin_lock(&data->lock); +} + +static inline void spi_spin_unlock(const struct device *dev, k_spinlock_key_t key) +{ + struct spi_sam_data *data = dev->data; + + k_spin_unlock(&data->lock, key); +} + static int spi_slave_to_mr_pcs(int slave) { int pcs[SAM_SPI_CHIP_SELECT_COUNT] = {0x0, 0x1, 0x3, 0x7}; @@ -178,10 +193,9 @@ static void spi_sam_finish(Spi *regs) } /* Fast path that transmits a buf */ -static void spi_sam_fast_tx(Spi *regs, const struct spi_buf *tx_buf) +static void spi_sam_fast_tx(const struct device *dev, Spi *regs, const struct spi_buf *tx_buf) { - struct k_spinlock lock; - k_spinlock_key_t key = k_spin_lock(&lock); + k_spinlock_key_t key = spi_spin_lock(dev); const uint8_t *p = tx_buf->buf; const uint8_t *pend = (uint8_t *)tx_buf->buf + tx_buf->len; @@ -198,14 +212,13 @@ static void spi_sam_fast_tx(Spi *regs, const struct spi_buf *tx_buf) spi_sam_finish(regs); - k_spin_unlock(&lock, key); + spi_spin_unlock(dev, key); } /* Fast path that reads into a buf */ -static void spi_sam_fast_rx(Spi *regs, const struct spi_buf *rx_buf) +static void spi_sam_fast_rx(const struct device *dev, Spi *regs, const struct spi_buf *rx_buf) { - struct k_spinlock lock; - k_spinlock_key_t key = k_spin_lock(&lock); + k_spinlock_key_t key = spi_spin_lock(dev); uint8_t *rx = rx_buf->buf; int len = rx_buf->len; @@ -243,7 +256,7 @@ static void spi_sam_fast_rx(Spi *regs, const struct spi_buf *rx_buf) spi_sam_finish(regs); - k_spin_unlock(&lock, key); + spi_spin_unlock(dev, key); } #ifdef CONFIG_SPI_SAM_DMA @@ -389,12 +402,10 @@ static int spi_sam_dma_txrx(const struct device *dev, /* Fast path that writes and reads bufs of the same length */ -static void spi_sam_fast_txrx(Spi *regs, - const struct spi_buf *tx_buf, +static void spi_sam_fast_txrx(const struct device *dev, Spi *regs, const struct spi_buf *tx_buf, const struct spi_buf *rx_buf) { - struct k_spinlock lock; - k_spinlock_key_t key = k_spin_lock(&lock); + k_spinlock_key_t key = spi_spin_lock(dev); const uint8_t *tx = tx_buf->buf; const uint8_t *txend = (uint8_t *)tx_buf->buf + tx_buf->len; @@ -445,7 +456,7 @@ static void spi_sam_fast_txrx(Spi *regs, spi_sam_finish(regs); - k_spin_unlock(&lock, key); + spi_spin_unlock(dev, key); } static inline void spi_sam_rx(const struct device *dev, @@ -456,12 +467,12 @@ static inline void spi_sam_rx(const struct device *dev, const struct spi_sam_config *cfg = dev->config; if (rx->len < SAM_SPI_DMA_THRESHOLD || cfg->dma_dev == NULL) { - spi_sam_fast_rx(regs, rx); + spi_sam_fast_rx(dev, regs, rx); } else { spi_sam_dma_txrx(dev, regs, NULL, rx); } #else - spi_sam_fast_rx(regs, rx); + spi_sam_fast_rx(dev, regs, rx); #endif } @@ -473,12 +484,12 @@ static inline void spi_sam_tx(const struct device *dev, const struct spi_sam_config *cfg = dev->config; if (tx->len < SAM_SPI_DMA_THRESHOLD || cfg->dma_dev == NULL) { - spi_sam_fast_tx(regs, tx); + spi_sam_fast_tx(dev, regs, tx); } else { spi_sam_dma_txrx(dev, regs, tx, NULL); } #else - spi_sam_fast_tx(regs, tx); + spi_sam_fast_tx(dev, regs, tx); #endif } @@ -492,12 +503,12 @@ static inline void spi_sam_txrx(const struct device *dev, const struct spi_sam_config *cfg = dev->config; if (tx->len < SAM_SPI_DMA_THRESHOLD || cfg->dma_dev == NULL) { - spi_sam_fast_txrx(regs, tx, rx); + spi_sam_fast_txrx(dev, regs, tx, rx); } else { spi_sam_dma_txrx(dev, regs, tx, rx); } #else - spi_sam_fast_txrx(regs, tx, rx); + spi_sam_fast_txrx(dev, regs, tx, rx); #endif } From 74426372010dcf60e9d6d110751360515e48c16d Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Mon, 13 Mar 2023 21:46:59 +0100 Subject: [PATCH 0213/1906] drivers: can: shell: add support for setting SJW Add support for setting the Synchronization Jump Width (SJW) for both the classic/arbitration phase and the CAN-FD data phase. Signed-off-by: Henrik Brix Andersen --- drivers/can/can_shell.c | 58 +++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/drivers/can/can_shell.c b/drivers/can/can_shell.c index 9c5c05e3f8d3..5e0ad6d87227 100644 --- a/drivers/can/can_shell.c +++ b/drivers/can/can_shell.c @@ -366,7 +366,15 @@ static int cmd_can_bitrate_set(const struct shell *sh, size_t argc, char **argv) return -EINVAL; } - timing.sjw = CAN_SJW_NO_CHANGE; + if (argc >= 5) { + timing.sjw = (uint16_t)strtoul(argv[4], &endptr, 10); + if (*endptr != '\0') { + shell_error(sh, "failed to parse SJW"); + return -EINVAL; + } + } else { + timing.sjw = CAN_SJW_NO_CHANGE; + } err = can_calc_timing(dev, &timing, bitrate, sample_pnt); if (err < 0) { @@ -376,9 +384,16 @@ static int cmd_can_bitrate_set(const struct shell *sh, size_t argc, char **argv) return err; } - shell_print(sh, "setting bitrate to %d bps, sample point %d.%d%% " - "(+/- %d.%d%%)", - bitrate, sample_pnt / 10, sample_pnt % 10, err / 10, err % 10); + if (timing.sjw == CAN_SJW_NO_CHANGE) { + shell_print(sh, "setting bitrate to %d bps, sample point %d.%d%% " + "(+/- %d.%d%%)", + bitrate, sample_pnt / 10, sample_pnt % 10, err / 10, err % 10); + } else { + shell_print(sh, "setting bitrate to %d bps, sample point %d.%d%% " + "(+/- %d.%d%%), sjw %d", + bitrate, sample_pnt / 10, sample_pnt % 10, err / 10, err % 10, + timing.sjw); + } err = can_set_timing(dev, &timing); if (err != 0) { @@ -425,7 +440,15 @@ static int cmd_can_dbitrate_set(const struct shell *sh, size_t argc, char **argv return -EINVAL; } - timing.sjw = CAN_SJW_NO_CHANGE; + if (argc >= 5) { + timing.sjw = (uint16_t)strtoul(argv[4], &endptr, 10); + if (*endptr != '\0') { + shell_error(sh, "failed to parse SJW"); + return -EINVAL; + } + } else { + timing.sjw = CAN_SJW_NO_CHANGE; + } err = can_calc_timing_data(dev, &timing, bitrate, sample_pnt); if (err < 0) { @@ -435,9 +458,16 @@ static int cmd_can_dbitrate_set(const struct shell *sh, size_t argc, char **argv return err; } - shell_print(sh, "setting data bitrate to %d bps, sample point %d.%d%% " - "(+/- %d.%d%%)", - bitrate, sample_pnt / 10, sample_pnt % 10, err / 10, err % 10); + if (timing.sjw == CAN_SJW_NO_CHANGE) { + shell_print(sh, "setting data bitrate to %d bps, sample point %d.%d%% " + "(+/- %d.%d%%)", + bitrate, sample_pnt / 10, sample_pnt % 10, err / 10, err % 10); + } else { + shell_print(sh, "setting data bitrate to %d bps, sample point %d.%d%% " + "(+/- %d.%d%%), sjw %d", + bitrate, sample_pnt / 10, sample_pnt % 10, err / 10, err % 10, + timing.sjw); + } err = can_set_timing_data(dev, &timing); if (err != 0) { @@ -872,14 +902,14 @@ SHELL_STATIC_SUBCMD_SET_CREATE(sub_can_cmds, "Usage: can show ", cmd_can_show, 2, 0), SHELL_CMD_ARG(bitrate, &dsub_can_device_name, - "Set CAN controller bitrate and optional sample point\n" - "Usage: can bitrate [sample point]", - cmd_can_bitrate_set, 3, 1), + "Set CAN controller bitrate (sample point and SJW optional)\n" + "Usage: can bitrate [sample point] [sjw]", + cmd_can_bitrate_set, 3, 2), SHELL_COND_CMD_ARG(CONFIG_CAN_FD_MODE, dbitrate, &dsub_can_device_name, - "Set CAN controller data phase bitrate and optional sample point\n" - "Usage: can dbitrate [sample point]", - cmd_can_dbitrate_set, 3, 1), + "Set CAN controller data phase bitrate (sample point and SJW optional)\n" + "Usage: can dbitrate [sample point] [sjw]", + cmd_can_dbitrate_set, 3, 2), SHELL_CMD_ARG(mode, &dsub_can_device_name_mode, "Set CAN controller mode\n" "Usage: can mode [mode] [mode] [...]", From 4bb9ad929febc3d015a241a7b9438326656aeb26 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Wed, 25 Jan 2023 12:49:02 +0200 Subject: [PATCH 0214/1906] drivers: fxos8700: Remove unneeded assignment Remove unneeded assignment fixing issue with using uninitialized variable. Signed-off-by: Andrei Emeltchenko --- drivers/sensor/fxos8700/fxos8700.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/sensor/fxos8700/fxos8700.c b/drivers/sensor/fxos8700/fxos8700.c index 2021e02614a0..aff38c233806 100644 --- a/drivers/sensor/fxos8700/fxos8700.c +++ b/drivers/sensor/fxos8700/fxos8700.c @@ -487,7 +487,7 @@ static int fxos8700_channel_get(const struct device *dev, int fxos8700_get_power(const struct device *dev, enum fxos8700_power *power) { const struct fxos8700_config *config = dev->config; - uint8_t val = *power; + uint8_t val; if (config->ops->byte_read(dev, FXOS8700_REG_CTRLREG1, &val)) { LOG_ERR("Could not get power setting"); From 3588706d1ae969bf2103d5ded3867fb265c1d2c6 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Sun, 12 Mar 2023 16:31:26 +0100 Subject: [PATCH 0215/1906] Bluetooth: Audio: Shell: Rename streams to unicast_streams The streams array only contained unicast streams, and the name should reflect that. Signed-off-by: Emil Gydesen --- subsys/bluetooth/shell/bap.c | 54 +++++++++++++++++------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/subsys/bluetooth/shell/bap.c b/subsys/bluetooth/shell/bap.c index af49a73db55f..e71c27bc752c 100644 --- a/subsys/bluetooth/shell/bap.c +++ b/subsys/bluetooth/shell/bap.c @@ -40,7 +40,8 @@ CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT), \ (0)) -static struct bt_bap_stream streams[UNICAST_SERVER_STREAM_COUNT + UNICAST_CLIENT_STREAM_COUNT]; +static struct bt_bap_stream + unicast_streams[UNICAST_SERVER_STREAM_COUNT + UNICAST_CLIENT_STREAM_COUNT]; static const struct bt_codec_qos_pref qos_pref = BT_CODEC_QOS_PREF(true, BT_GAP_LE_PHY_2M, 0u, 60u, 20000u, 40000u, 20000u, 40000u); @@ -555,15 +556,13 @@ static struct named_lc3_preset *set_preset(enum bt_audio_dir dir, return set_preset; } -static void set_stream(struct bt_bap_stream *stream) +static void set_unicast_stream(struct bt_bap_stream *stream) { - int i; - default_stream = stream; - for (i = 0; i < ARRAY_SIZE(streams); i++) { - if (stream == &streams[i]) { - shell_print(ctx_shell, "Default stream: %u", i + 1); + for (size_t i = 0; i < ARRAY_SIZE(unicast_streams); i++) { + if (stream == &unicast_streams[i]) { + shell_print(ctx_shell, "Default stream: %zu", i + 1); } } } @@ -589,23 +588,23 @@ static int cmd_select_unicast(const struct shell *sh, size_t argc, char *argv[]) return -ENOEXEC; } - if (index > ARRAY_SIZE(streams)) { + if (index > ARRAY_SIZE(unicast_streams)) { shell_error(sh, "Invalid index: %lu", index); return -ENOEXEC; } - stream = &streams[index]; + stream = &unicast_streams[index]; - set_stream(stream); + set_unicast_stream(stream); return 0; } static struct bt_bap_stream *stream_alloc(void) { - for (size_t i = 0; i < ARRAY_SIZE(streams); i++) { - struct bt_bap_stream *stream = &streams[i]; + for (size_t i = 0; i < ARRAY_SIZE(unicast_streams); i++) { + struct bt_bap_stream *stream = &unicast_streams[i]; if (!stream->conn) { return stream; @@ -625,14 +624,14 @@ static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_ *stream = stream_alloc(); if (*stream == NULL) { - shell_print(ctx_shell, "No streams available"); + shell_print(ctx_shell, "No unicast_streams available"); return -ENOMEM; } shell_print(ctx_shell, "ASE Codec Config stream %p", *stream); - set_stream(*stream); + set_unicast_stream(*stream); *pref = qos_pref; @@ -647,7 +646,7 @@ static int lc3_reconfig(struct bt_bap_stream *stream, enum bt_audio_dir dir, print_codec(codec); if (default_stream == NULL) { - set_stream(stream); + set_unicast_stream(stream); } *pref = qos_pref; @@ -1070,7 +1069,7 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) return -ENOEXEC; } - if (index > ARRAY_SIZE(streams)) { + if (index > ARRAY_SIZE(unicast_streams)) { shell_error(sh, "Invalid index: %lu", index); return -ENOEXEC; @@ -1123,7 +1122,7 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) int err; if (default_stream == NULL) { - stream = &streams[0]; + stream = &unicast_streams[0]; } else { stream = default_stream; } @@ -1145,8 +1144,8 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) static int create_unicast_group(const struct shell *sh) { - struct bt_bap_unicast_group_stream_pair_param pair_param[ARRAY_SIZE(streams)]; - struct bt_bap_unicast_group_stream_param stream_params[ARRAY_SIZE(streams)]; + struct bt_bap_unicast_group_stream_pair_param pair_param[ARRAY_SIZE(unicast_streams)]; + struct bt_bap_unicast_group_stream_param stream_params[ARRAY_SIZE(unicast_streams)]; struct bt_bap_unicast_group_param group_param; size_t source_cnt = 0; size_t sink_cnt = 0; @@ -1157,8 +1156,8 @@ static int create_unicast_group(const struct shell *sh) memset(stream_params, 0, sizeof(stream_params)); memset(&group_param, 0, sizeof(group_param)); - for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { - struct bt_bap_stream *stream = &streams[i]; + for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) { + struct bt_bap_stream *stream = &unicast_streams[i]; if (stream->ep != NULL) { struct bt_bap_unicast_group_stream_param *stream_param; @@ -1398,8 +1397,8 @@ static int cmd_list(const struct shell *sh, size_t argc, char *argv[]) shell_print(sh, "Configured Channels:"); - for (i = 0; i < ARRAY_SIZE(streams); i++) { - struct bt_bap_stream *stream = &streams[i]; + for (i = 0; i < ARRAY_SIZE(unicast_streams); i++) { + struct bt_bap_stream *stream = &unicast_streams[i]; if (stream->conn) { shell_print(sh, " %s#%u: stream %p ep %p group %p", @@ -1737,7 +1736,6 @@ static struct bt_bap_stream_ops stream_ops = { static int cmd_select_broadcast_source(const struct shell *sh, size_t argc, char *argv[]) { - struct bt_bap_stream *stream; unsigned long index; int err = 0; @@ -1754,9 +1752,7 @@ static int cmd_select_broadcast_source(const struct shell *sh, size_t argc, return -ENOEXEC; } - stream = &broadcast_source_streams[index]; - - set_stream(stream); + default_stream = &broadcast_source_streams[index]; return 0; } @@ -2216,8 +2212,8 @@ static int cmd_init(const struct shell *sh, size_t argc, char *argv[]) } #if defined(CONFIG_BT_BAP_UNICAST) - for (i = 0; i < ARRAY_SIZE(streams); i++) { - bt_bap_stream_cb_register(&streams[i], &stream_ops); + for (i = 0; i < ARRAY_SIZE(unicast_streams); i++) { + bt_bap_stream_cb_register(&unicast_streams[i], &stream_ops); } #endif /* CONFIG_BT_BAP_UNICAST */ From 2638a042143dba299162cf30ed70c9f857042c00 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Sun, 12 Mar 2023 17:08:04 +0100 Subject: [PATCH 0216/1906] Bluetooth: Audio: Shell: Make BAP shell presets constant Make the BAP shell presets constant. This reflects more what they represent, and make it not only possible, but also easier, to modify the individual streams QoS and Codec configurations, without affecting other streams. Signed-off-by: Emil Gydesen --- subsys/bluetooth/shell/bap.c | 101 +++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 41 deletions(-) diff --git a/subsys/bluetooth/shell/bap.c b/subsys/bluetooth/shell/bap.c index e71c27bc752c..0f7c98b91986 100644 --- a/subsys/bluetooth/shell/bap.c +++ b/subsys/bluetooth/shell/bap.c @@ -40,8 +40,11 @@ CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT), \ (0)) -static struct bt_bap_stream - unicast_streams[UNICAST_SERVER_STREAM_COUNT + UNICAST_CLIENT_STREAM_COUNT]; +static struct unicast_stream { + struct bt_bap_stream stream; + struct bt_codec codec; + struct bt_codec_qos qos; +} unicast_streams[UNICAST_SERVER_STREAM_COUNT + UNICAST_CLIENT_STREAM_COUNT]; static const struct bt_codec_qos_pref qos_pref = BT_CODEC_QOS_PREF(true, BT_GAP_LE_PHY_2M, 0u, 60u, 20000u, 40000u, 20000u, 40000u); @@ -60,6 +63,8 @@ static struct bt_bap_ep *srcs[CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT]; #if defined(CONFIG_BT_BAP_BROADCAST_SOURCE) static struct bt_bap_stream broadcast_source_streams[CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT]; static struct bt_bap_broadcast_source *default_source; +static struct bt_codec broadcast_source_codec; +static struct bt_codec_qos broadcast_source_qos; #endif /* CONFIG_BT_BAP_BROADCAST_SOURCE */ #if defined(CONFIG_BT_BAP_BROADCAST_SINK) static struct bt_bap_stream broadcast_sink_streams[BROADCAST_SNK_STREAM_CNT]; @@ -75,7 +80,7 @@ struct named_lc3_preset { struct bt_bap_lc3_preset preset; }; -static struct named_lc3_preset lc3_unicast_presets[] = { +static const struct named_lc3_preset lc3_unicast_presets[] = { {"8_1_1", BT_BAP_LC3_UNICAST_PRESET_8_1_1(LOCATION, CONTEXT)}, {"8_2_1", BT_BAP_LC3_UNICAST_PRESET_8_2_1(LOCATION, CONTEXT)}, {"16_1_1", BT_BAP_LC3_UNICAST_PRESET_16_1_1(LOCATION, CONTEXT)}, @@ -111,7 +116,7 @@ static struct named_lc3_preset lc3_unicast_presets[] = { {"48_6_2", BT_BAP_LC3_UNICAST_PRESET_48_6_2(LOCATION, CONTEXT)}, }; -static struct named_lc3_preset lc3_broadcast_presets[] = { +static const struct named_lc3_preset lc3_broadcast_presets[] = { {"8_1_1", BT_BAP_LC3_BROADCAST_PRESET_8_1_1(LOCATION, CONTEXT)}, {"8_2_1", BT_BAP_LC3_BROADCAST_PRESET_8_2_1(LOCATION, CONTEXT)}, {"16_1_1", BT_BAP_LC3_BROADCAST_PRESET_16_1_1(LOCATION, CONTEXT)}, @@ -148,9 +153,9 @@ static struct named_lc3_preset lc3_broadcast_presets[] = { }; /* Default to 16_2_1 */ -static struct named_lc3_preset *default_sink_preset = &lc3_unicast_presets[3]; -static struct named_lc3_preset *default_source_preset = &lc3_unicast_presets[3]; -static struct named_lc3_preset *default_broadcast_source_preset = &lc3_broadcast_presets[3]; +static const struct named_lc3_preset *default_sink_preset = &lc3_unicast_presets[3]; +static const struct named_lc3_preset *default_source_preset = &lc3_unicast_presets[3]; +static const struct named_lc3_preset *default_broadcast_source_preset = &lc3_broadcast_presets[3]; static bool initialized; static uint16_t get_next_seq_num(uint32_t interval_us) @@ -400,13 +405,11 @@ static void print_codec(const struct bt_codec *codec) } } -static struct named_lc3_preset *set_preset(enum bt_audio_dir dir, - bool is_unicast, - size_t argc, - char **argv) +static const struct named_lc3_preset *set_preset(enum bt_audio_dir dir, bool is_unicast, + size_t argc, char **argv) { static struct named_lc3_preset named_preset; - struct named_lc3_preset *set_preset = NULL; + const struct named_lc3_preset *set_preset = NULL; int err = 0; if (is_unicast) { @@ -561,7 +564,7 @@ static void set_unicast_stream(struct bt_bap_stream *stream) default_stream = stream; for (size_t i = 0; i < ARRAY_SIZE(unicast_streams); i++) { - if (stream == &unicast_streams[i]) { + if (stream == &unicast_streams[i].stream) { shell_print(ctx_shell, "Default stream: %zu", i + 1); } } @@ -594,7 +597,7 @@ static int cmd_select_unicast(const struct shell *sh, size_t argc, char *argv[]) return -ENOEXEC; } - stream = &unicast_streams[index]; + stream = &unicast_streams[index].stream; set_unicast_stream(stream); @@ -604,7 +607,7 @@ static int cmd_select_unicast(const struct shell *sh, size_t argc, char *argv[]) static struct bt_bap_stream *stream_alloc(void) { for (size_t i = 0; i < ARRAY_SIZE(unicast_streams); i++) { - struct bt_bap_stream *stream = &unicast_streams[i]; + struct bt_bap_stream *stream = &unicast_streams[i].stream; if (!stream->conn) { return stream; @@ -1051,8 +1054,9 @@ static int cmd_discover(const struct shell *sh, size_t argc, char *argv[]) static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) { + const struct named_lc3_preset *named_preset; + struct unicast_stream *uni_stream; struct bt_bap_ep *ep = NULL; - struct named_lc3_preset *named_preset; enum bt_audio_dir dir; unsigned long index; int err = 0; @@ -1062,6 +1066,10 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) return -ENOEXEC; } + if (default_stream == NULL) { + default_stream = &unicast_streams[0].stream; + } + index = shell_strtoul(argv[2], 0, &err); if (err != 0) { shell_error(sh, "Could not parse index: %d", err); @@ -1111,30 +1119,35 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) } } - if (default_stream && default_stream->ep == ep) { - if (bt_bap_stream_reconfig(default_stream, - &named_preset->preset.codec) < 0) { - shell_error(sh, "Unable reconfig stream"); + uni_stream = CONTAINER_OF(default_stream, struct unicast_stream, stream); + memcpy(&uni_stream->qos, &named_preset->preset.qos, sizeof(uni_stream->qos)); + memcpy(&uni_stream->codec, &named_preset->preset.codec, sizeof(uni_stream->codec)); + /* Need to update the `bt_data.data` pointer to the new value after copying the codec */ + for (size_t i = 0U; i < ARRAY_SIZE(uni_stream->codec.data); i++) { + struct bt_codec_data *data = &uni_stream->codec.data[i]; + + data->data.data = data->value; + } + + for (size_t i = 0U; i < ARRAY_SIZE(uni_stream->codec.meta); i++) { + struct bt_codec_data *data = &uni_stream->codec.meta[i]; + + data->data.data = data->value; + } + + if (default_stream->ep == ep) { + err = bt_bap_stream_reconfig(default_stream, &uni_stream->codec); + if (err != 0) { + shell_error(sh, "Unable reconfig stream: %d", err); return -ENOEXEC; } } else { - struct bt_bap_stream *stream; - int err; - - if (default_stream == NULL) { - stream = &unicast_streams[0]; - } else { - stream = default_stream; - } - err = bt_bap_stream_config(default_conn, stream, ep, - &named_preset->preset.codec); + err = bt_bap_stream_config(default_conn, default_stream, ep, &uni_stream->codec); if (err != 0) { shell_error(sh, "Unable to config stream: %d", err); return err; } - - default_stream = stream; } shell_print(sh, "ASE config: preset %s", named_preset->name); @@ -1157,7 +1170,9 @@ static int create_unicast_group(const struct shell *sh) memset(&group_param, 0, sizeof(group_param)); for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) { - struct bt_bap_stream *stream = &unicast_streams[i]; + struct bt_bap_stream *stream = &unicast_streams[i].stream; + struct unicast_stream *uni_stream = + CONTAINER_OF(stream, struct unicast_stream, stream); if (stream->ep != NULL) { struct bt_bap_unicast_group_stream_param *stream_param; @@ -1166,10 +1181,10 @@ static int create_unicast_group(const struct shell *sh) stream_param->stream = stream; if (stream_dir(stream) == BT_AUDIO_DIR_SINK) { - stream_param->qos = &default_sink_preset->preset.qos; + stream_param->qos = &uni_stream->qos; pair_param[sink_cnt++].tx_param = stream_param; } else { - stream_param->qos = &default_source_preset->preset.qos; + stream_param->qos = &uni_stream->qos; pair_param[source_cnt++].rx_param = stream_param; } @@ -1285,7 +1300,7 @@ static int cmd_stop(const struct shell *sh, size_t argc, char *argv[]) static int cmd_preset(const struct shell *sh, size_t argc, char *argv[]) { - struct named_lc3_preset *named_preset; + const struct named_lc3_preset *named_preset; enum bt_audio_dir dir; if (!strcmp(argv[1], "sink")) { @@ -1398,7 +1413,7 @@ static int cmd_list(const struct shell *sh, size_t argc, char *argv[]) shell_print(sh, "Configured Channels:"); for (i = 0; i < ARRAY_SIZE(unicast_streams); i++) { - struct bt_bap_stream *stream = &unicast_streams[i]; + struct bt_bap_stream *stream = &unicast_streams[i].stream; if (stream->conn) { shell_print(sh, " %s#%u: stream %p ep %p group %p", @@ -1764,7 +1779,7 @@ static int cmd_create_broadcast(const struct shell *sh, size_t argc, stream_params[ARRAY_SIZE(broadcast_source_streams)]; struct bt_bap_broadcast_source_subgroup_param subgroup_param; struct bt_bap_broadcast_source_create_param create_param = {0}; - struct named_lc3_preset *named_preset; + const struct named_lc3_preset *named_preset; int err; if (default_source != NULL) { @@ -1823,16 +1838,20 @@ static int cmd_create_broadcast(const struct shell *sh, size_t argc, } } + memcpy(&broadcast_source_codec, &named_preset->preset.codec, + sizeof(broadcast_source_codec)); + memcpy(&broadcast_source_qos, &named_preset->preset.qos, sizeof(broadcast_source_qos)); + (void)memset(stream_params, 0, sizeof(stream_params)); for (size_t i = 0; i < ARRAY_SIZE(stream_params); i++) { stream_params[i].stream = &broadcast_source_streams[i]; } subgroup_param.params_count = ARRAY_SIZE(stream_params); subgroup_param.params = stream_params; - subgroup_param.codec = &named_preset->preset.codec; + subgroup_param.codec = &broadcast_source_codec; create_param.params_count = 1U; create_param.params = &subgroup_param; - create_param.qos = &named_preset->preset.qos; + create_param.qos = &broadcast_source_qos; err = bt_bap_broadcast_source_create(&create_param, &default_source); if (err != 0) { @@ -2213,7 +2232,7 @@ static int cmd_init(const struct shell *sh, size_t argc, char *argv[]) #if defined(CONFIG_BT_BAP_UNICAST) for (i = 0; i < ARRAY_SIZE(unicast_streams); i++) { - bt_bap_stream_cb_register(&unicast_streams[i], &stream_ops); + bt_bap_stream_cb_register(&unicast_streams[i].stream, &stream_ops); } #endif /* CONFIG_BT_BAP_UNICAST */ From b9a4deb429308b271773b973c42070b9d1b414e3 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Mon, 13 Mar 2023 10:59:51 +0100 Subject: [PATCH 0217/1906] Bluetooth: Audio: Shell: Replace hacky metadata handling The hacky handle_metadata_update that copied the metadata to a variable, since stream->codec->meta could not be modified, has been replaced with a proper solution now that stream->codec->meta can be modified. It still only supports settings the streaming context, but it is much easier to expand now. Signed-off-by: Emil Gydesen --- subsys/bluetooth/shell/bap.c | 73 ++++++++++-------------------------- 1 file changed, 20 insertions(+), 53 deletions(-) diff --git a/subsys/bluetooth/shell/bap.c b/subsys/bluetooth/shell/bap.c index 0f7c98b91986..b73c5c678621 100644 --- a/subsys/bluetooth/shell/bap.c +++ b/subsys/bluetooth/shell/bap.c @@ -830,40 +830,17 @@ static uint16_t strmeta(const char *name) return 0u; } -static int handle_metadata_update(struct bt_codec *codec, - const char *meta_str, - struct bt_codec_data *meta_out[], - size_t *meta_count_out) +static int set_metadata(struct bt_codec *codec, const char *meta_str) { - static struct bt_codec_data meta[CONFIG_BT_CODEC_MAX_METADATA_COUNT]; - size_t meta_count; + uint16_t context; - /* We create a copy of the preset meta, as the presets cannot be modified */ - meta_count = codec->meta_count; - (void)memset(meta, 0, sizeof(meta)); - - for (size_t i = 0U; i < meta_count; i++) { - (void)memcpy(meta[i].value, codec->meta[i].data.data, - codec->meta[i].data.data_len); - meta[i].data.data_len = codec->meta[i].data.data_len; - meta[i].data.type = codec->meta[i].data.type; - meta[i].data.data = meta[i].value; - } - - if (meta_str != NULL) { - uint16_t context; - - context = strmeta(meta_str); - if (context == 0) { - return -ENOEXEC; - } - - /* TODO: Check the type and only overwrite the streaming context */ - sys_put_le16(context, meta[0].value); + context = strmeta(meta_str); + if (context == 0) { + return -ENOEXEC; } - *meta_count_out = meta_count; - *meta_out = meta; + /* TODO: Check the type and only overwrite the streaming context */ + sys_put_le16(context, codec->meta[0].value); return 0; } @@ -1247,9 +1224,7 @@ static int cmd_qos(const struct shell *sh, size_t argc, char *argv[]) static int cmd_enable(const struct shell *sh, size_t argc, char *argv[]) { - struct bt_codec_data *meta; struct bt_codec *codec; - size_t meta_count; int err; if (default_stream == NULL) { @@ -1260,17 +1235,14 @@ static int cmd_enable(const struct shell *sh, size_t argc, char *argv[]) codec = default_stream->codec; if (argc > 1) { - err = handle_metadata_update(codec, argv[1], &meta, &meta_count); - } else { - err = handle_metadata_update(codec, NULL, &meta, &meta_count); - } - - if (err != 0) { - shell_error(sh, "Unable to handle metadata update: %d", err); - return err; + err = set_metadata(codec, argv[1]); + if (err != 0) { + shell_error(sh, "Unable to handle metadata update: %d", err); + return err; + } } - err = bt_bap_stream_enable(default_stream, meta, meta_count); + err = bt_bap_stream_enable(default_stream, codec->meta, codec->meta_count); if (err) { shell_error(sh, "Unable to enable Channel"); return -ENOEXEC; @@ -1338,9 +1310,7 @@ static int cmd_preset(const struct shell *sh, size_t argc, char *argv[]) static int cmd_metadata(const struct shell *sh, size_t argc, char *argv[]) { - struct bt_codec_data *meta; struct bt_codec *codec; - size_t meta_count; int err; if (default_stream == NULL) { @@ -1351,17 +1321,14 @@ static int cmd_metadata(const struct shell *sh, size_t argc, char *argv[]) codec = default_stream->codec; if (argc > 1) { - err = handle_metadata_update(codec, argv[1], &meta, &meta_count); - } else { - err = handle_metadata_update(codec, NULL, &meta, &meta_count); - } - - if (err != 0) { - shell_error(sh, "Unable to handle metadata update: %d", err); - return err; + err = set_metadata(codec, argv[1]); + if (err != 0) { + shell_error(sh, "Unable to handle metadata update: %d", err); + return err; + } } - err = bt_bap_stream_metadata(default_stream, meta, meta_count); + err = bt_bap_stream_metadata(default_stream, codec->meta, codec->meta_count); if (err) { shell_error(sh, "Unable to set Channel metadata"); return -ENOEXEC; @@ -2415,7 +2382,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( "[preset] [interval] [framing] [latency] [pd] [sdu] [phy]" " [rtn]", cmd_qos, 1, 8), - SHELL_CMD_ARG(enable, NULL, NULL, cmd_enable, 1, 1), + SHELL_CMD_ARG(enable, NULL, "[context]", cmd_enable, 1, 1), SHELL_CMD_ARG(stop, NULL, NULL, cmd_stop, 1, 0), #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ #if defined(CONFIG_BT_BAP_UNICAST_SERVER) From a02a1c19a14a332a29cde5c8a33448a3335e7587 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Mon, 13 Mar 2023 11:41:42 +0100 Subject: [PATCH 0218/1906] Bluetooth: Audio: Shell: Refactor set_preset The function is now called get_named_preset and only returns a named preset. The QoS parameter handling has been moved to a new function, cmd_stream_qos, which can be used to set specific QoS for a stream. The get_named_preset does also no longer set the default preset, and cmd_preset must be used for that now. This means that a function like cmd_config no longer has any side effects, thus making it easier to set up multiple streams with different presets. Signed-off-by: Emil Gydesen --- subsys/bluetooth/shell/bap.c | 316 +++++++++++++++++------------------ 1 file changed, 152 insertions(+), 164 deletions(-) diff --git a/subsys/bluetooth/shell/bap.c b/subsys/bluetooth/shell/bap.c index b73c5c678621..ac4f58c0a6a8 100644 --- a/subsys/bluetooth/shell/bap.c +++ b/subsys/bluetooth/shell/bap.c @@ -405,158 +405,23 @@ static void print_codec(const struct bt_codec *codec) } } -static const struct named_lc3_preset *set_preset(enum bt_audio_dir dir, bool is_unicast, - size_t argc, char **argv) +static const struct named_lc3_preset *get_named_preset(bool is_unicast, const char *preset_arg) { - static struct named_lc3_preset named_preset; - const struct named_lc3_preset *set_preset = NULL; - int err = 0; - if (is_unicast) { for (size_t i = 0U; i < ARRAY_SIZE(lc3_unicast_presets); i++) { - if (!strcmp(argv[0], lc3_unicast_presets[i].name)) { - if (dir == BT_AUDIO_DIR_SINK) { - default_sink_preset = &lc3_unicast_presets[i]; - set_preset = default_sink_preset; - } else { - default_source_preset = &lc3_unicast_presets[i]; - set_preset = default_source_preset; - } - - break; + if (!strcmp(preset_arg, lc3_unicast_presets[i].name)) { + return &lc3_unicast_presets[i]; } } } else { for (size_t i = 0U; i < ARRAY_SIZE(lc3_broadcast_presets); i++) { - if (!strcmp(argv[0], lc3_broadcast_presets[i].name)) { - default_broadcast_source_preset = &lc3_broadcast_presets[i]; - set_preset = default_broadcast_source_preset; - break; + if (!strcmp(preset_arg, lc3_broadcast_presets[i].name)) { + return &lc3_broadcast_presets[i]; } } } - if (argc == 1) { - return set_preset; - } - - named_preset = *set_preset; - set_preset = &named_preset; - - if (argc > 1) { - unsigned long interval; - - interval = shell_strtoul(argv[1], 0, &err); - if (err != 0) { - return NULL; - } - - if (!IN_RANGE(interval, - BT_ISO_SDU_INTERVAL_MIN, - BT_ISO_SDU_INTERVAL_MAX)) { - return NULL; - } - - named_preset.preset.qos.interval = interval; - } - - if (argc > 2) { - unsigned long framing; - - framing = shell_strtoul(argv[2], 0, &err); - if (err != 0) { - return NULL; - } - - if (!IN_RANGE(framing, - BT_ISO_FRAMING_UNFRAMED, - BT_ISO_FRAMING_FRAMED)) { - return NULL; - } - - named_preset.preset.qos.framing = framing; - } - - if (argc > 3) { - unsigned long latency; - - latency = shell_strtoul(argv[3], 0, &err); - if (err != 0) { - return NULL; - } - - if (!IN_RANGE(latency, - BT_ISO_LATENCY_MIN, - BT_ISO_LATENCY_MAX)) { - return NULL; - } - - named_preset.preset.qos.latency = latency; - } - - if (argc > 4) { - unsigned long pd; - - pd = shell_strtoul(argv[4], 0, &err); - if (err != 0) { - return NULL; - } - - if (pd > BT_AUDIO_PD_MAX) { - return NULL; - } - - named_preset.preset.qos.pd = pd; - } - - if (argc > 5) { - unsigned long sdu; - - sdu = shell_strtoul(argv[5], 0, &err); - if (err != 0) { - return NULL; - } - - if (sdu > BT_ISO_MAX_SDU) { - return NULL; - } - - named_preset.preset.qos.sdu = sdu; - } - - if (argc > 6) { - unsigned long phy; - - phy = shell_strtoul(argv[6], 0, &err); - if (err != 0) { - return NULL; - } - - if (phy != BT_GAP_LE_PHY_1M && - phy != BT_GAP_LE_PHY_2M && - phy != BT_GAP_LE_PHY_CODED) { - return NULL; - } - - named_preset.preset.qos.phy = phy; - } - - if (argc > 7) { - unsigned long rtn; - - rtn = shell_strtoul(argv[7], 0, &err); - if (err != 0) { - return NULL; - } - - if (rtn > BT_ISO_CONNECTED_RTN_MAX) { - return NULL; - } - - named_preset.preset.qos.rtn = rtn; - } - - return set_preset; + return NULL; } static void set_unicast_stream(struct bt_bap_stream *stream) @@ -1034,7 +899,6 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) const struct named_lc3_preset *named_preset; struct unicast_stream *uni_stream; struct bt_bap_ep *ep = NULL; - enum bt_audio_dir dir; unsigned long index; int err = 0; @@ -1064,7 +928,6 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 } else if (!strcmp(argv[1], "sink")) { - dir = BT_AUDIO_DIR_SINK; ep = snks[index]; named_preset = default_source_preset; @@ -1072,7 +935,6 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 } else if (!strcmp(argv[1], "source")) { - dir = BT_AUDIO_DIR_SOURCE; ep = srcs[index]; named_preset = default_sink_preset; @@ -1088,10 +950,9 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) } if (argc > 3) { - named_preset = set_preset(dir, true, 1, argv + 3); + named_preset = get_named_preset(true, argv[3]); if (named_preset == NULL) { - shell_error(sh, "Unable to parse named_preset %s", - argv[4]); + shell_error(sh, "Unable to parse named_preset %s", argv[3]); return -ENOEXEC; } } @@ -1132,6 +993,129 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) return 0; } +static int cmd_stream_qos(const struct shell *sh, size_t argc, char *argv[]) +{ + struct bt_codec_qos *qos; + unsigned long interval; + int err; + + if (default_stream == NULL) { + shell_print(sh, "No stream selected"); + return -ENOEXEC; + } + + qos = default_stream->qos; + + if (qos == NULL) { + shell_print(sh, "Stream not configured"); + return -ENOEXEC; + } + + interval = shell_strtoul(argv[1], 0, &err); + if (err != 0) { + return -ENOEXEC; + } + + if (!IN_RANGE(interval, BT_ISO_SDU_INTERVAL_MIN, BT_ISO_SDU_INTERVAL_MAX)) { + return -ENOEXEC; + } + + qos->interval = interval; + + if (argc > 2) { + unsigned long framing; + + framing = shell_strtoul(argv[2], 0, &err); + if (err != 0) { + return -ENOEXEC; + } + + if (!IN_RANGE(framing, BT_ISO_FRAMING_UNFRAMED, BT_ISO_FRAMING_FRAMED)) { + return -ENOEXEC; + } + + qos->framing = framing; + } + + if (argc > 3) { + unsigned long latency; + + latency = shell_strtoul(argv[3], 0, &err); + if (err != 0) { + return -ENOEXEC; + } + + if (!IN_RANGE(latency, BT_ISO_LATENCY_MIN, BT_ISO_LATENCY_MAX)) { + return -ENOEXEC; + } + + qos->latency = latency; + } + + if (argc > 4) { + unsigned long pd; + + pd = shell_strtoul(argv[4], 0, &err); + if (err != 0) { + return -ENOEXEC; + } + + if (pd > BT_AUDIO_PD_MAX) { + return -ENOEXEC; + } + + qos->pd = pd; + } + + if (argc > 5) { + unsigned long sdu; + + sdu = shell_strtoul(argv[5], 0, &err); + if (err != 0) { + return -ENOEXEC; + } + + if (sdu > BT_ISO_MAX_SDU) { + return -ENOEXEC; + } + + qos->sdu = sdu; + } + + if (argc > 6) { + unsigned long phy; + + phy = shell_strtoul(argv[6], 0, &err); + if (err != 0) { + return -ENOEXEC; + } + + if (phy != BT_GAP_LE_PHY_1M && phy != BT_GAP_LE_PHY_2M && + phy != BT_GAP_LE_PHY_CODED) { + return -ENOEXEC; + } + + qos->phy = phy; + } + + if (argc > 7) { + unsigned long rtn; + + rtn = shell_strtoul(argv[7], 0, &err); + if (err != 0) { + return -ENOEXEC; + } + + if (rtn > BT_ISO_CONNECTED_RTN_MAX) { + return -ENOEXEC; + } + + qos->rtn = rtn; + } + + return 0; +} + static int create_unicast_group(const struct shell *sh) { struct bt_bap_unicast_group_stream_pair_param pair_param[ARRAY_SIZE(unicast_streams)]; @@ -1273,28 +1257,35 @@ static int cmd_stop(const struct shell *sh, size_t argc, char *argv[]) static int cmd_preset(const struct shell *sh, size_t argc, char *argv[]) { const struct named_lc3_preset *named_preset; - enum bt_audio_dir dir; + bool unicast = true; if (!strcmp(argv[1], "sink")) { - dir = BT_AUDIO_DIR_SINK; - named_preset = default_sink_preset; } else if (!strcmp(argv[1], "source")) { - dir = BT_AUDIO_DIR_SOURCE; - named_preset = default_source_preset; + } else if (!strcmp(argv[1], "broadcast")) { + unicast = false; + + named_preset = default_broadcast_source_preset; } else { shell_error(sh, "Unsupported dir: %s", argv[1]); return -ENOEXEC; } if (argc > 2) { - named_preset = set_preset(dir, true, argc - 2, argv + 2); + named_preset = get_named_preset(unicast, argv[2]); if (named_preset == NULL) { - shell_error(sh, "Unable to parse named_preset %s", - argv[1]); + shell_error(sh, "Unable to parse named_preset %s", argv[2]); return -ENOEXEC; } + + if (!strcmp(argv[1], "sink")) { + default_sink_preset = named_preset; + } else if (!strcmp(argv[1], "source")) { + default_source_preset = named_preset; + } else if (!strcmp(argv[1], "broadcast")) { + default_broadcast_source_preset = named_preset; + } } shell_print(sh, "%s", named_preset->name); @@ -1789,8 +1780,7 @@ static int cmd_create_broadcast(const struct shell *sh, size_t argc, i++; arg = argv[i]; - named_preset = set_preset(BT_AUDIO_DIR_SOURCE, - false, 1, &arg); + named_preset = get_named_preset(false, arg); if (named_preset == NULL) { shell_error(sh, "Unable to parse named_preset %s", arg); @@ -2376,12 +2366,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE( #if defined(CONFIG_BT_BAP_UNICAST) #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) SHELL_CMD_ARG(discover, NULL, "[dir: sink, source]", cmd_discover, 1, 1), - SHELL_CMD_ARG(config, NULL, " [codec] [preset]", - cmd_config, 3, 2), - SHELL_CMD_ARG(qos, NULL, - "[preset] [interval] [framing] [latency] [pd] [sdu] [phy]" - " [rtn]", - cmd_qos, 1, 8), + SHELL_CMD_ARG(config, NULL, " [preset]", cmd_config, 3, 1), + SHELL_CMD_ARG(stream_qos, NULL, "interval [framing] [latency] [pd] [sdu] [phy] [rtn]", + cmd_stream_qos, 2, 6), + SHELL_CMD_ARG(qos, NULL, "Send QoS configure for Unicast Group", cmd_qos, 1, 0), SHELL_CMD_ARG(enable, NULL, "[context]", cmd_enable, 1, 1), SHELL_CMD_ARG(stop, NULL, NULL, cmd_stop, 1, 0), #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ @@ -2389,7 +2377,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_CMD_ARG(print_ase_info, NULL, "Print ASE info for default connection", cmd_print_ase_info, 0, 0), #endif /* CONFIG_BT_BAP_UNICAST_SERVER */ - SHELL_CMD_ARG(preset, NULL, "dir [preset]", cmd_preset, 2, 1), SHELL_CMD_ARG(metadata, NULL, "[context]", cmd_metadata, 1, 1), SHELL_CMD_ARG(start, NULL, NULL, cmd_start, 1, 0), SHELL_CMD_ARG(disable, NULL, NULL, cmd_disable, 1, 0), @@ -2397,6 +2384,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_CMD_ARG(list, NULL, NULL, cmd_list, 1, 0), SHELL_CMD_ARG(select_unicast, NULL, "", cmd_select_unicast, 2, 0), #endif /* CONFIG_BT_BAP_UNICAST */ + SHELL_CMD_ARG(preset, NULL, " [preset]", cmd_preset, 2, 1), SHELL_CMD_ARG(send, NULL, "Send to Audio Stream [data]", cmd_send, 1, 1), #if defined(CONFIG_LIBLC3) SHELL_CMD_ARG(start_sine, NULL, "Start sending a LC3 encoded sine wave", cmd_start_sine, 1, From 53912795ba16f2fa738116a7adae127f7dfe6560 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Mon, 13 Mar 2023 13:25:46 +0100 Subject: [PATCH 0219/1906] Bluetooth: Audio: Shell: Update BAP shell documentation Update the BAP shell documentation to be more up to date. There are still several BAP commands that do not have examples of further documentation, but that is still a TODO. Signed-off-by: Emil Gydesen --- doc/connectivity/bluetooth/api/shell/bap.rst | 126 +++++++++---------- 1 file changed, 56 insertions(+), 70 deletions(-) diff --git a/doc/connectivity/bluetooth/api/shell/bap.rst b/doc/connectivity/bluetooth/api/shell/bap.rst index cfb6b5956bf8..7ceeba7cc272 100644 --- a/doc/connectivity/bluetooth/api/shell/bap.rst +++ b/doc/connectivity/bluetooth/api/shell/bap.rst @@ -18,30 +18,36 @@ Commands Subcommands: init select_broadcast : - create_broadcast :[codec] [preset] + create_broadcast :[preset ] [enc ] start_broadcast : stop_broadcast : delete_broadcast : broadcast_scan : accept_broadcast :0x - sync_broadcast :0x + sync_broadcast :0x [[[0x] 0x] ...] stop_broadcast_sink :Stops broadcast sink term_broadcast_sink : - discover :[type: sink, source] - preset :[preset] - config : [codec] [preset] - qos :[preset] [interval] [framing] [latency] [pd] [sdu] [phy] - [rtn] - enable + discover :[dir: sink, source] + config : [preset] + stream_qos :interval [framing] [latency] [pd] [sdu] [phy] [rtn] + qos :Send QoS configure for Unicast Group + enable :[context] + stop + print_ase_info :Print ASE info for default connection metadata :[context] start disable - stop release list - connect : [codec] [preset] select_unicast : + preset : [preset] send :Send to Audio Stream [data] + start_sine :Start sending a LC3 encoded sine wave + stop_sine :Stop sending a LC3 encoded sine wave + set_location : + set_context : + .. csv-table:: State Machine Transitions :header: "Command", "Depends", "Allowed States", "Next States" @@ -237,19 +243,33 @@ any stream previously configured. .. code-block:: console - uart:~$ bap preset [preset] - uart:~$ bap preset + uart:~$ bap preset [preset] + uart:~$ bap preset sink 16_2_1 - codec 0x06 cid 0x0000 vid 0x0000 count 3 + codec 0x06 cid 0x0000 vid 0x0000 count 4 data #0: type 0x01 len 1 - 00000000: 02 |. | data #1: type 0x02 len 1 - 00000000: 01 |. | - data #2: type 0x04 len 2 - 00000000: 28 00 |(. | + data #2: type 0x03 len 4 + 00000000: 01 00 00 |... | + data #3: type 0x04 len 2 + 00000000: 28 |( | meta #0: type 0x02 len 2 - 00000000: 02 00 |.. | - QoS: dir 0x02 interval 10000 framing 0x00 phy 0x02 sdu 40 rtn 2 latency 10 pd 40000 + 00000000: 06 |. | + QoS: interval 10000 framing 0x00 phy 0x02 sdu 40 rtn 2 latency 10 pd 40000 + + uart:~$ bap preset sink 32_2_1 + 32_2_1 + codec 0x06 cid 0x0000 vid 0x0000 count 4 + data #0: type 0x01 len 1 + data #1: type 0x02 len 1 + data #2: type 0x03 len 4 + 00000000: 01 00 00 |... | + data #3: type 0x04 len 2 + 00000000: 50 |P | + meta #0: type 0x02 len 2 + 00000000: 06 |. | + QoS: interval 10000 framing 0x00 phy 0x02 sdu 80 rtn 2 latency 10 pd 40000 + Configure Codec *************** @@ -266,7 +286,7 @@ or in case it is omitted the default preset is used. .. code-block:: console - uart:~$ bap config [codec] [preset] + uart:~$ bap config [preset] uart:~$ bap config sink 0 ASE Codec Config: conn 0x8173800 ep 0x81754e0 cap 0x816a360 codec 0x06 cid 0x0000 vid 0x0000 count 3 @@ -282,6 +302,16 @@ or in case it is omitted the default preset is used. Default ase: 1 ASE config: preset 16_2_1 +Configure Stream QoS +******************** + +The :code:`stream_qos` Sets a new stream QoS. + +.. code-block:: console + + uart:~$ bap stream_qos [framing] [latency] [pd] [sdu] [phy] [rtn] + uart:~$ bap stream_qos 10 + Configure QoS ************* @@ -297,9 +327,7 @@ parameters. .. code-block:: console - uart:~$ bap qos [preset] [interval] [framing] [latency] [pd] [sdu] [phy] [rtn] uart:~$ bap qos - ASE config: preset 16_2_1 Enable ****** @@ -315,10 +343,11 @@ if the remote peer accepts then the ISO connection procedure is also initiated. .. code-block:: console - uart:~$ bap enable + uart:~$ bap enable [context] + uart:~$ bap enable Media -Start [sink only] -***************** +Start +***** The :code:`start` command is only necessary when acting as a sink as it indicates to the source the stack is ready to start receiving data. @@ -350,8 +379,8 @@ initiated. uart:~$ bap disable -Stop [sink only] -**************** +Stop +**** The :code:`stop` command is only necessary when acting as a sink as it indicates to the source the stack is ready to stop receiving data. @@ -421,49 +450,6 @@ To select a broadcast stream: uart:~$ bap select 0x01 broadcast Default stream: 1 (broadcast) -Connect -******* - -The :code:`connect` command combines config, qos and enable commands in one so -it can be used to quickly configure and enable a stream. - -.. csv-table:: State Machine Transitions - :header: "Depends", "Allowed States", "Next States" - :widths: auto - - "discover","idle/codec-configured/qos-configured","streaming" - -.. code-block:: console - - uart:~$ bap connect [codec] [preset] - uart:~$ bap connect sink 0 - ASE Codec Config: conn 0x17ca40 ep 0x17f860 cap 0x19f6a0 - codec 0x06 cid 0x0000 vid 0x0000 count 3 - data #0: type 0x01 len 1 - 00000000: 02 |. | - data #1: type 0x02 len 1 - 00000000: 01 |. | - data #2: type 0x04 len 2 - 00000000: 28 00 |(. | - meta #0: type 0x02 len 2 - 00000000: 02 00 |.. | - ASE Codec Config stream 0x1851c0 - Default ase: 1 - ASE config: preset 16_2_1 - ASE Codec Reconfig: stream 0x1851c0 cap 0x19f6a0 - codec 0x06 cid 0x0000 vid 0x0000 count 3 - data #0: type 0x01 len 1 - 00000000: 02 |. | - data #1: type 0x02 len 1 - 00000000: 01 |. | - data #2: type 0x04 len 2 - 00000000: 28 00 |(. | - meta #0: type 0x02 len 2 - 00000000: 02 00 |.. | - QoS: stream 0x1851c0 - QoS: dir 0x02 interval 10000 framing 0x00 phy 0x02 sdu 40 rtn 2 latency 10 pd 40000 - Start: stream 0x1851c0 - Send **** From 5704b83ea7880b0a9d38443c86ab5bef4878bb5b Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Mon, 13 Mar 2023 14:24:44 +0100 Subject: [PATCH 0220/1906] Bluetooth: Audio: Shell: Add location to cmd_config Add support for setting the location value (BT_CODEC_CONFIG_LC3_CHAN_ALLOC) in the codec configuration. Signed-off-by: Emil Gydesen --- doc/connectivity/bluetooth/api/shell/bap.rst | 4 +- subsys/bluetooth/shell/bap.c | 70 ++++++++++++++++++-- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/doc/connectivity/bluetooth/api/shell/bap.rst b/doc/connectivity/bluetooth/api/shell/bap.rst index 7ceeba7cc272..11a91e020fa3 100644 --- a/doc/connectivity/bluetooth/api/shell/bap.rst +++ b/doc/connectivity/bluetooth/api/shell/bap.rst @@ -28,7 +28,7 @@ Commands stop_broadcast_sink :Stops broadcast sink term_broadcast_sink : discover :[dir: sink, source] - config : [preset] + config : [loc ] [preset ] stream_qos :interval [framing] [latency] [pd] [sdu] [phy] [rtn] qos :Send QoS configure for Unicast Group enable :[context] @@ -286,7 +286,7 @@ or in case it is omitted the default preset is used. .. code-block:: console - uart:~$ bap config [preset] + uart:~$ bap config [loc ] [preset ] uart:~$ bap config sink 0 ASE Codec Config: conn 0x8173800 ep 0x81754e0 cap 0x816a360 codec 0x06 cid 0x0000 vid 0x0000 count 3 diff --git a/subsys/bluetooth/shell/bap.c b/subsys/bluetooth/shell/bap.c index ac4f58c0a6a8..41a007b03911 100644 --- a/subsys/bluetooth/shell/bap.c +++ b/subsys/bluetooth/shell/bap.c @@ -896,6 +896,7 @@ static int cmd_discover(const struct shell *sh, size_t argc, char *argv[]) static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) { + enum bt_audio_location location = BT_AUDIO_LOCATION_PROHIBITED; const struct named_lc3_preset *named_preset; struct unicast_stream *uni_stream; struct bt_bap_ep *ep = NULL; @@ -949,11 +950,49 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) return -ENOEXEC; } - if (argc > 3) { - named_preset = get_named_preset(true, argv[3]); - if (named_preset == NULL) { - shell_error(sh, "Unable to parse named_preset %s", argv[3]); - return -ENOEXEC; + for (size_t i = 3U; i < argc; i++) { + const char *arg = argv[i]; + + /* argc needs to be larger than `i` to parse the argument value */ + if (argc <= i) { + shell_help(sh); + + return SHELL_CMD_HELP_PRINTED; + } + + if (strcmp(arg, "loc") == 0) { + unsigned long loc_bits; + + arg = argv[++i]; + loc_bits = shell_strtoul(arg, 0, &err); + if (err != 0) { + shell_error(sh, "Could not parse loc_bits: %d", err); + + return -ENOEXEC; + } + + if (loc_bits == BT_AUDIO_LOCATION_PROHIBITED || + loc_bits > BT_AUDIO_LOCATION_ANY) { + shell_error(sh, "Invalid loc_bits: %lu", loc_bits); + + return -ENOEXEC; + } + + location = (enum bt_audio_location)loc_bits; + } else if (strcmp(arg, "preset") == 0) { + if (argc > i) { + arg = argv[++i]; + + named_preset = get_named_preset(true, arg); + if (named_preset == NULL) { + shell_error(sh, "Unable to parse named_preset %s", arg); + return -ENOEXEC; + } + } else { + shell_help(sh); + + return SHELL_CMD_HELP_PRINTED; + } } } @@ -973,6 +1012,23 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) data->data.data = data->value; } + /* If location has been modifed, we update the location in the codec configuration */ + if (location != BT_AUDIO_LOCATION_PROHIBITED) { + for (size_t i = 0U; i < uni_stream->codec.data_count; i++) { + struct bt_codec_data *data = &uni_stream->codec.data[i]; + + /* Overwrite the location value */ + if (data->data.type == BT_CODEC_CONFIG_LC3_CHAN_ALLOC) { + const uint32_t loc_32 = location; + + sys_put_le32(loc_32, data->value); + + shell_print(sh, "Setting location to 0x%08X", location); + break; + } + } + } + if (default_stream->ep == ep) { err = bt_bap_stream_reconfig(default_stream, &uni_stream->codec); if (err != 0) { @@ -2366,7 +2422,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE( #if defined(CONFIG_BT_BAP_UNICAST) #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) SHELL_CMD_ARG(discover, NULL, "[dir: sink, source]", cmd_discover, 1, 1), - SHELL_CMD_ARG(config, NULL, " [preset]", cmd_config, 3, 1), + SHELL_CMD_ARG(config, NULL, + " [loc ] [preset ]", + cmd_config, 3, 4), SHELL_CMD_ARG(stream_qos, NULL, "interval [framing] [latency] [pd] [sdu] [phy] [rtn]", cmd_stream_qos, 2, 6), SHELL_CMD_ARG(qos, NULL, "Send QoS configure for Unicast Group", cmd_qos, 1, 0), From 48214e86b08116d9029eca598ba521d67d2772f2 Mon Sep 17 00:00:00 2001 From: Declan Snyder Date: Thu, 23 Feb 2023 10:50:50 -0600 Subject: [PATCH 0221/1906] soc: rt: Add flash chosen node functionality Add functionality for changing the code location based on the flash chosen node for RT devices. Remove obsolete Kconfigs that used to be used to set the code location for RT devices. Signed-off-by: Declan Snyder --- soc/arm/nxp_imx/rt/Kconfig.defconfig.series | 71 +++------------------ 1 file changed, 10 insertions(+), 61 deletions(-) diff --git a/soc/arm/nxp_imx/rt/Kconfig.defconfig.series b/soc/arm/nxp_imx/rt/Kconfig.defconfig.series index 9ead840ac1ab..cc9cc9b54803 100644 --- a/soc/arm/nxp_imx/rt/Kconfig.defconfig.series +++ b/soc/arm/nxp_imx/rt/Kconfig.defconfig.series @@ -75,73 +75,22 @@ config PM_MCUX_PMU endif # SOC_SERIES_IMX_RT10XX && PM -if CODE_SEMC +DT_CHOSEN_Z_FLASH := zephyr,flash +DT_COMPAT_FLEXSPI := nxp,imx-flexspi -config FLASH_SIZE - default $(dt_node_reg_size_int,/memory@80000000,0,K) - -config FLASH_BASE_ADDRESS - default $(dt_node_reg_addr_hex,/memory@80000000) - -endif # CODE_SEMC +DT_CHOSEN_FLASH_NODE := $(dt_chosen_path,$(DT_CHOSEN_Z_FLASH)) +DT_CHOSEN_FLASH_PARENT := $(dt_node_parent,$(DT_CHOSEN_FLASH_NODE)) -if CODE_ITCM - -config FLASH_SIZE - default $(dt_node_reg_size_int,/soc/flexram@40028000/itcm@0,0,K) if SOC_SERIES_IMX_RT11XX - default $(dt_node_reg_size_int,/soc/flexram@400b0000/itcm@0,0,K) if SOC_SERIES_IMX_RT10XX +DT_FLASH_PARENT_IS_FLEXSPI := $(dt_node_has_compat,$(DT_CHOSEN_FLASH_PARENT),$(DT_COMPAT_FLEXSPI)) +DT_FLASH_HAS_SIZE_PROP := $(dt_node_has_prop,$(DT_CHOSEN_FLASH_NODE),size) config FLASH_BASE_ADDRESS - default $(dt_node_reg_addr_hex,/soc/flexram@40028000/itcm@0) if SOC_SERIES_IMX_RT11XX - default $(dt_node_reg_addr_hex,/soc/flexram@400b0000/itcm@0) if SOC_SERIES_IMX_RT10XX - -endif # CODE_ITCM - -if CODE_SRAM0 + default $(dt_node_reg_addr_hex,$(DT_CHOSEN_FLASH_PARENT),1) \ + if $(DT_FLASH_PARENT_IS_FLEXSPI) config FLASH_SIZE - default $(dt_node_reg_size_int,/soc/memory@1ffe0000,0,K) - -config FLASH_BASE_ADDRESS - default $(dt_node_reg_addr_hex,/soc/memory@1ffe0000) - -endif # CODE_SRAM0 - -if CODE_OCRAM - -config FLASH_SIZE - default $(dt_node_reg_size_int,/soc/ocram@20200000,0,K) - -config FLASH_BASE_ADDRESS - default $(dt_node_reg_addr_hex,/soc/ocram@20200000) - -endif # CODE_OCRAM - -if CODE_FLEXSPI - -config FLASH_SIZE - default $(dt_node_reg_size_int,/soc/spi@400cc000,1,K) if SOC_SERIES_IMX_RT11XX - default $(dt_node_reg_size_int,/soc/spi@400a0000,1,K) if SOC_MIMXRT1011 - default $(dt_node_reg_size_int,/soc/spi@402a8000,1,K) if SOC_SERIES_IMX_RT10XX - -config FLASH_BASE_ADDRESS - default $(dt_node_reg_addr_hex,/soc/spi@400cc000,1) if SOC_SERIES_IMX_RT11XX - default $(dt_node_reg_addr_hex,/soc/spi@400a0000,1) if SOC_MIMXRT1011 - default $(dt_node_reg_addr_hex,/soc/spi@402a8000,1) if SOC_SERIES_IMX_RT10XX - -endif # CODE_FLEXSPI - -if CODE_FLEXSPI2 - -config FLASH_SIZE - default $(dt_node_reg_size_int,/soc/spi@400d0000,1,K) if SOC_SERIES_IMX_RT11XX - default $(dt_node_reg_size_int,/soc/spi@402a4000,1,K) if SOC_SERIES_IMX_RT10XX - -config FLASH_BASE_ADDRESS - default $(dt_node_reg_addr_hex,/soc/spi@400d0000,1) if SOC_SERIES_IMX_RT11XX - default $(dt_node_reg_addr_hex,/soc/spi@402a4000,1) if SOC_SERIES_IMX_RT10XX - -endif # CODE_FLEXSPI2 + default $(dt_node_int_prop_int,$(DT_CHOSEN_FLASH_NODE),size,Kb) \ + if $(DT_FLASH_HAS_SIZE_PROP) choice USB_MCUX_CONTROLLER_TYPE default USB_DC_NXP_EHCI From 1bc6045fd9e581ed2c0bd1285700fd1263c0bd3a Mon Sep 17 00:00:00 2001 From: Artur Rojek Date: Thu, 8 Dec 2022 14:17:23 +0100 Subject: [PATCH 0222/1906] drivers: clock_control: imx: Simplify pointer casting. Use `uintptr_t` to cast a pointer to integer type for `clock_name`. While at it, also remove an unused variable. Signed-off-by: Artur Rojek --- drivers/clock_control/clock_control_mcux_ccm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/clock_control/clock_control_mcux_ccm.c b/drivers/clock_control/clock_control_mcux_ccm.c index 78d0b12706be..ef7922177140 100644 --- a/drivers/clock_control/clock_control_mcux_ccm.c +++ b/drivers/clock_control/clock_control_mcux_ccm.c @@ -60,12 +60,7 @@ static int mcux_ccm_get_subsys_rate(const struct device *dev, clock_control_subsys_t sub_system, uint32_t *rate) { -#ifdef CONFIG_ARM64 - uint32_t clock_name = (uint32_t)(uint64_t) sub_system; -#else - uint32_t clock_name = (uint32_t) sub_system; -#endif - uint32_t mux __unused; + uint32_t clock_name = (uintptr_t)sub_system; switch (clock_name) { From 14912d241cf85c037ad5595afa2fd7c9cbb06a65 Mon Sep 17 00:00:00 2001 From: Artur Rojek Date: Thu, 8 Dec 2022 14:55:46 +0100 Subject: [PATCH 0223/1906] nxp: imx: Implement iuart clock gating Add clock control support for UART controllers found in i.MX SoC family. This change moves clock gating out of respective `soc.c` files and into clock controller's `clock_control_on`/`_off` methods, allowing for dynamic clock state control, and setup via Device Tree bindings. This is especially important on SoCs, where Zephyr is sharing the bus with cores running other OSes, such as might be the case for i.MX 8MM. Unfortunately, Zephyr doesn't possess an ability to represent clock hierarchy (e.g. via DT's `assigned-clocks` property), so clock source and frequency still need to be hardcoded in aforementioned `soc.c` files. Signed-off-by: Artur Rojek --- .../clock_control/clock_control_mcux_ccm.c | 41 ++++++++++++++++++- drivers/serial/uart_mcux_iuart.c | 2 + 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/clock_control/clock_control_mcux_ccm.c b/drivers/clock_control/clock_control_mcux_ccm.c index ef7922177140..9ed1fe406616 100644 --- a/drivers/clock_control/clock_control_mcux_ccm.c +++ b/drivers/clock_control/clock_control_mcux_ccm.c @@ -30,6 +30,13 @@ static const clock_root_control_t uart_clk_root[] = { kCLOCK_RootUart3, kCLOCK_RootUart4, }; + +static const clock_ip_name_t uart_clocks[] = { + kCLOCK_Uart1, + kCLOCK_Uart2, + kCLOCK_Uart3, + kCLOCK_Uart4, +}; #endif #if defined(CONFIG_UART_MCUX_LPUART) && defined(CONFIG_SOC_MIMX93_A55) static const clock_root_t lpuart_clk_root[] = { @@ -47,13 +54,43 @@ static const clock_root_t lpuart_clk_root[] = { static int mcux_ccm_on(const struct device *dev, clock_control_subsys_t sub_system) { - return 0; + uint32_t clock_name = (uintptr_t)sub_system; + uint32_t instance = clock_name & IMX_CCM_INSTANCE_MASK; + + switch (clock_name) { +#ifdef CONFIG_UART_MCUX_IUART + case IMX_CCM_UART1_CLK: + case IMX_CCM_UART2_CLK: + case IMX_CCM_UART3_CLK: + case IMX_CCM_UART4_CLK: + CLOCK_EnableClock(uart_clocks[instance]); + return 0; +#endif + default: + (void)instance; + return 0; + } } static int mcux_ccm_off(const struct device *dev, clock_control_subsys_t sub_system) { - return 0; + uint32_t clock_name = (uintptr_t)sub_system; + uint32_t instance = clock_name & IMX_CCM_INSTANCE_MASK; + + switch (clock_name) { +#ifdef CONFIG_UART_MCUX_IUART + case IMX_CCM_UART1_CLK: + case IMX_CCM_UART2_CLK: + case IMX_CCM_UART3_CLK: + case IMX_CCM_UART4_CLK: + CLOCK_DisableClock(uart_clocks[instance]); + return 0; +#endif + default: + (void)instance; + return 0; + } } static int mcux_ccm_get_subsys_rate(const struct device *dev, diff --git a/drivers/serial/uart_mcux_iuart.c b/drivers/serial/uart_mcux_iuart.c index c72100b5d1ed..09ae22c906ee 100644 --- a/drivers/serial/uart_mcux_iuart.c +++ b/drivers/serial/uart_mcux_iuart.c @@ -241,10 +241,12 @@ static int mcux_iuart_init(const struct device *dev) uart_config.enableRx = true; uart_config.baudRate_Bps = config->baud_rate; + clock_control_on(config->clock_dev, config->clock_subsys); UART_Init(config->base, &uart_config, clock_freq); err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); if (err) { + clock_control_off(config->clock_dev, config->clock_subsys); return err; } From 49fa1519dfa7a9d095898f648daf77647867d6c4 Mon Sep 17 00:00:00 2001 From: Artur Rojek Date: Thu, 8 Dec 2022 14:56:59 +0100 Subject: [PATCH 0224/1906] nxp: imx: Derive i.MX8 UARTs from DT bindings Use Device Tree bindings to configure clock source/frequency for enabled UARTs only. Get rid of UART clock ungating from `soc.c`, as that functionality has been moved to the clock controller. Signed-off-by: Artur Rojek --- soc/arm/nxp_imx/mimx8ml8_m7/soc.c | 26 +++++++++++++++++++++----- soc/arm/nxp_imx/mimx8mm6_m4/soc.c | 24 ++++++++++++++++++++++-- soc/arm/nxp_imx/mimx8mq6_m4/soc.c | 5 ++--- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/soc/arm/nxp_imx/mimx8ml8_m7/soc.c b/soc/arm/nxp_imx/mimx8ml8_m7/soc.c index 47aefc1fd4d0..5b9f818d97be 100644 --- a/soc/arm/nxp_imx/mimx8ml8_m7/soc.c +++ b/soc/arm/nxp_imx/mimx8ml8_m7/soc.c @@ -106,11 +106,31 @@ static void SOC_ClockInit(void) /* switch AHB to SYSTEM PLL1 DIV6 */ CLOCK_SetRootMux(kCLOCK_RootAhb, kCLOCK_AhbRootmuxSysPll1Div6); -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) && CONFIG_UART_MCUX_IUART +#if defined(CONFIG_UART_MCUX_IUART) +#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) + /* Set UART source to SysPLL1 Div10 80MHZ */ + CLOCK_SetRootMux(kCLOCK_RootUart1, kCLOCK_UartRootmuxSysPll1Div10); + /* Set root clock to 80MHZ/ 1= 80MHZ */ + CLOCK_SetRootDivider(kCLOCK_RootUart1, 1U, 1U); +#endif +#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) + /* Set UART source to SysPLL1 Div10 80MHZ */ + CLOCK_SetRootMux(kCLOCK_RootUart2, kCLOCK_UartRootmuxSysPll1Div10); + /* Set root clock to 80MHZ/ 1= 80MHZ */ + CLOCK_SetRootDivider(kCLOCK_RootUart2, 1U, 1U); +#endif +#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) + /* Set UART source to SysPLL1 Div10 80MHZ */ + CLOCK_SetRootMux(kCLOCK_RootUart3, kCLOCK_UartRootmuxSysPll1Div10); + /* Set root clock to 80MHZ/ 1= 80MHZ */ + CLOCK_SetRootDivider(kCLOCK_RootUart3, 1U, 1U); +#endif +#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart4, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart4, 1U, 1U); +#endif #endif CLOCK_EnableClock(kCLOCK_Rdc); /* Enable RDC clock */ @@ -126,10 +146,6 @@ static void SOC_ClockInit(void) CLOCK_EnableClock(kCLOCK_Debug); CLOCK_EnableClock(kCLOCK_Dram); CLOCK_EnableClock(kCLOCK_Sec_Debug); - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) && CONFIG_UART_MCUX_IUART - CLOCK_EnableClock(kCLOCK_Uart4); -#endif } static int nxp_mimx8ml8_init(const struct device *arg) diff --git a/soc/arm/nxp_imx/mimx8mm6_m4/soc.c b/soc/arm/nxp_imx/mimx8mm6_m4/soc.c index b386b3a6e036..c2ff6d1bc09d 100644 --- a/soc/arm/nxp_imx/mimx8mm6_m4/soc.c +++ b/soc/arm/nxp_imx/mimx8mm6_m4/soc.c @@ -103,10 +103,32 @@ static void SOC_ClockInit(void) /* switch AUDIO AHB to SYSTEM PLL1 */ CLOCK_SetRootMux(kCLOCK_RootAudioAhb, kCLOCK_AudioAhbRootmuxSysPll1); +#if defined(CONFIG_UART_MCUX_IUART) +#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) + /* Set UART source to SysPLL1 Div10 80MHZ */ + CLOCK_SetRootMux(kCLOCK_RootUart1, kCLOCK_UartRootmuxSysPll1Div10); + /* Set root clock to 80MHZ/ 1= 80MHZ */ + CLOCK_SetRootDivider(kCLOCK_RootUart1, 1U, 1U); +#endif +#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) + /* Set UART source to SysPLL1 Div10 80MHZ */ + CLOCK_SetRootMux(kCLOCK_RootUart2, kCLOCK_UartRootmuxSysPll1Div10); + /* Set root clock to 80MHZ/ 1= 80MHZ */ + CLOCK_SetRootDivider(kCLOCK_RootUart2, 1U, 1U); +#endif +#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) + /* Set UART source to SysPLL1 Div10 80MHZ */ + CLOCK_SetRootMux(kCLOCK_RootUart3, kCLOCK_UartRootmuxSysPll1Div10); + /* Set root clock to 80MHZ/ 1= 80MHZ */ + CLOCK_SetRootDivider(kCLOCK_RootUart3, 1U, 1U); +#endif +#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart4, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart4, 1U, 1U); +#endif +#endif /* Enable RDC clock */ CLOCK_EnableClock(kCLOCK_Rdc); @@ -124,8 +146,6 @@ static void SOC_ClockInit(void) CLOCK_EnableClock(kCLOCK_Debug); CLOCK_EnableClock(kCLOCK_Dram); CLOCK_EnableClock(kCLOCK_Sec_Debug); - - CLOCK_EnableClock(kCLOCK_Uart4); } static int nxp_mimx8mm6_init(const struct device *arg) diff --git a/soc/arm/nxp_imx/mimx8mq6_m4/soc.c b/soc/arm/nxp_imx/mimx8mq6_m4/soc.c index 393c08ad4428..2f58ac9e4ef8 100644 --- a/soc/arm/nxp_imx/mimx8mq6_m4/soc.c +++ b/soc/arm/nxp_imx/mimx8mq6_m4/soc.c @@ -66,32 +66,31 @@ static void SOC_ClockInit(void) /* Switch cortex-m4 to SYSTEM PLL1 DIV3 */ CLOCK_SetRootMux(kCLOCK_RootM4, kCLOCK_M4RootmuxSysPll1Div3); +#if defined(CONFIG_UART_MCUX_IUART) #if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart1, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart1, 1U, 1U); #endif - #if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart2, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart2, 1U, 1U); #endif - #if DT_NODE_HAS_STATUS(DT_NODELABEL(uart3), okay) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart3, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart3, 1U, 1U); #endif - #if DT_NODE_HAS_STATUS(DT_NODELABEL(uart4), okay) /* Set UART source to SysPLL1 Div10 80MHZ */ CLOCK_SetRootMux(kCLOCK_RootUart4, kCLOCK_UartRootmuxSysPll1Div10); /* Set root clock to 80MHZ/ 1= 80MHZ */ CLOCK_SetRootDivider(kCLOCK_RootUart4, 1U, 1U); +#endif #endif /* Enable RDC clock */ From 4a1d0782cb58995900601e521efb7889c74d2528 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Tue, 7 Mar 2023 13:42:37 +0100 Subject: [PATCH 0225/1906] net: buf: Fix using incorrect logging macro As there is dedicated NET_BUF_SIMPLE_* logging macros set, NET_BUF_SIMPLE_DBG shall be used in this place instead. Signed-off-by: Mariusz Skamra --- subsys/net/buf.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/subsys/net/buf.c b/subsys/net/buf.c index dc6f5dc8e0d2..4dac9d9b6d5f 100644 --- a/subsys/net/buf.c +++ b/subsys/net/buf.c @@ -435,15 +435,6 @@ void net_buf_simple_init_with_data(struct net_buf_simple *buf, buf->len = size; } -void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve) -{ - __ASSERT_NO_MSG(buf); - __ASSERT_NO_MSG(buf->len == 0U); - NET_BUF_DBG("buf %p reserve %zu", buf, reserve); - - buf->data = buf->__buf + reserve; -} - static struct k_spinlock net_buf_slist_lock; void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf) @@ -756,6 +747,15 @@ size_t net_buf_append_bytes(struct net_buf *buf, size_t len, #define NET_BUF_SIMPLE_INFO(fmt, ...) #endif /* CONFIG_NET_BUF_SIMPLE_LOG */ +void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve) +{ + __ASSERT_NO_MSG(buf); + __ASSERT_NO_MSG(buf->len == 0U); + NET_BUF_SIMPLE_DBG("buf %p reserve %zu", buf, reserve); + + buf->data = buf->__buf + reserve; +} + void net_buf_simple_clone(const struct net_buf_simple *original, struct net_buf_simple *clone) { From 3f09fd9e82312d8b32d640dd6d1c45fd96bdc12c Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Tue, 7 Mar 2023 13:42:37 +0100 Subject: [PATCH 0226/1906] tests: net: buf: Fix invalid check in test This fixes using invalid byte array for verification of 64 bit value. Signed-off-by: Mariusz Skamra --- tests/net/buf/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/net/buf/src/main.c b/tests/net/buf/src/main.c index 8aa2ca6d77f1..2456587094c1 100644 --- a/tests/net/buf/src/main.c +++ b/tests/net/buf/src/main.c @@ -573,7 +573,7 @@ ZTEST(net_buf_tests, test_net_buf_byte_order) zassert_mem_equal(le64, net_buf_pull_mem(buf, sizeof(le64)), sizeof(le64), "Invalid 64 bits byte order"); zassert_mem_equal(be64, net_buf_pull_mem(buf, sizeof(be64)), - sizeof(be48), "Invalid 64 bits byte order"); + sizeof(be64), "Invalid 64 bits byte order"); /* push/remove byte order */ net_buf_reset(buf); From 5862c8263b8dcd0a029e21ac9472cded14d8bad4 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Tue, 7 Mar 2023 13:42:37 +0100 Subject: [PATCH 0227/1906] net: buf: Factor out net_buf_simple to separate source file This moves net_buf_simple related code to separate source file. Having those in separate file makes unit testing easier as simple network buffers do not use kernel objects, thus can be used in unit tests without a need for adding any mocks. Signed-off-by: Mariusz Skamra --- subsys/net/CMakeLists.txt | 6 +- subsys/net/buf.c | 530 ------------------------------------ subsys/net/buf_simple.c | 548 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 553 insertions(+), 531 deletions(-) create mode 100644 subsys/net/buf_simple.c diff --git a/subsys/net/CMakeLists.txt b/subsys/net/CMakeLists.txt index bbc680f74e7f..35fab9994e4f 100644 --- a/subsys/net/CMakeLists.txt +++ b/subsys/net/CMakeLists.txt @@ -1,7 +1,11 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_library() -zephyr_library_sources_ifdef(CONFIG_NET_BUF buf.c) +zephyr_library_sources_ifdef( + CONFIG_NET_BUF + buf.c + buf_simple.c + ) zephyr_library_sources_ifdef(CONFIG_NET_HOSTNAME_ENABLE hostname.c) if(CONFIG_NETWORKING) diff --git a/subsys/net/buf.c b/subsys/net/buf.c index 4dac9d9b6d5f..c257c982ac5e 100644 --- a/subsys/net/buf.c +++ b/subsys/net/buf.c @@ -426,15 +426,6 @@ struct net_buf *net_buf_get(struct k_fifo *fifo, k_timeout_t timeout) return buf; } -void net_buf_simple_init_with_data(struct net_buf_simple *buf, - void *data, size_t size) -{ - buf->__buf = data; - buf->data = data; - buf->size = size; - buf->len = size; -} - static struct k_spinlock net_buf_slist_lock; void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf) @@ -734,524 +725,3 @@ size_t net_buf_append_bytes(struct net_buf *buf, size_t len, /* Unreachable */ return 0; } - -#if defined(CONFIG_NET_BUF_SIMPLE_LOG) -#define NET_BUF_SIMPLE_DBG(fmt, ...) NET_BUF_DBG(fmt, ##__VA_ARGS__) -#define NET_BUF_SIMPLE_ERR(fmt, ...) NET_BUF_ERR(fmt, ##__VA_ARGS__) -#define NET_BUF_SIMPLE_WARN(fmt, ...) NET_BUF_WARN(fmt, ##__VA_ARGS__) -#define NET_BUF_SIMPLE_INFO(fmt, ...) NET_BUF_INFO(fmt, ##__VA_ARGS__) -#else -#define NET_BUF_SIMPLE_DBG(fmt, ...) -#define NET_BUF_SIMPLE_ERR(fmt, ...) -#define NET_BUF_SIMPLE_WARN(fmt, ...) -#define NET_BUF_SIMPLE_INFO(fmt, ...) -#endif /* CONFIG_NET_BUF_SIMPLE_LOG */ - -void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve) -{ - __ASSERT_NO_MSG(buf); - __ASSERT_NO_MSG(buf->len == 0U); - NET_BUF_SIMPLE_DBG("buf %p reserve %zu", buf, reserve); - - buf->data = buf->__buf + reserve; -} - -void net_buf_simple_clone(const struct net_buf_simple *original, - struct net_buf_simple *clone) -{ - memcpy(clone, original, sizeof(struct net_buf_simple)); -} - -void *net_buf_simple_add(struct net_buf_simple *buf, size_t len) -{ - uint8_t *tail = net_buf_simple_tail(buf); - - NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); - - __ASSERT_NO_MSG(net_buf_simple_tailroom(buf) >= len); - - buf->len += len; - return tail; -} - -void *net_buf_simple_add_mem(struct net_buf_simple *buf, const void *mem, - size_t len) -{ - NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); - - return memcpy(net_buf_simple_add(buf, len), mem, len); -} - -uint8_t *net_buf_simple_add_u8(struct net_buf_simple *buf, uint8_t val) -{ - uint8_t *u8; - - NET_BUF_SIMPLE_DBG("buf %p val 0x%02x", buf, val); - - u8 = net_buf_simple_add(buf, 1); - *u8 = val; - - return u8; -} - -void net_buf_simple_add_le16(struct net_buf_simple *buf, uint16_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - - sys_put_le16(val, net_buf_simple_add(buf, sizeof(val))); -} - -void net_buf_simple_add_be16(struct net_buf_simple *buf, uint16_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - - sys_put_be16(val, net_buf_simple_add(buf, sizeof(val))); -} - -void net_buf_simple_add_le24(struct net_buf_simple *buf, uint32_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - - sys_put_le24(val, net_buf_simple_add(buf, 3)); -} - -void net_buf_simple_add_be24(struct net_buf_simple *buf, uint32_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - - sys_put_be24(val, net_buf_simple_add(buf, 3)); -} - -void net_buf_simple_add_le32(struct net_buf_simple *buf, uint32_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - - sys_put_le32(val, net_buf_simple_add(buf, sizeof(val))); -} - -void net_buf_simple_add_be32(struct net_buf_simple *buf, uint32_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - - sys_put_be32(val, net_buf_simple_add(buf, sizeof(val))); -} - -void net_buf_simple_add_le48(struct net_buf_simple *buf, uint64_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); - - sys_put_le48(val, net_buf_simple_add(buf, 6)); -} - -void net_buf_simple_add_be48(struct net_buf_simple *buf, uint64_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); - - sys_put_be48(val, net_buf_simple_add(buf, 6)); -} - -void net_buf_simple_add_le64(struct net_buf_simple *buf, uint64_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); - - sys_put_le64(val, net_buf_simple_add(buf, sizeof(val))); -} - -void net_buf_simple_add_be64(struct net_buf_simple *buf, uint64_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); - - sys_put_be64(val, net_buf_simple_add(buf, sizeof(val))); -} - -void *net_buf_simple_remove_mem(struct net_buf_simple *buf, size_t len) -{ - NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); - - __ASSERT_NO_MSG(buf->len >= len); - - buf->len -= len; - return buf->data + buf->len; -} - -uint8_t net_buf_simple_remove_u8(struct net_buf_simple *buf) -{ - uint8_t val; - void *ptr; - - ptr = net_buf_simple_remove_mem(buf, sizeof(val)); - val = *(uint8_t *)ptr; - - return val; -} - -uint16_t net_buf_simple_remove_le16(struct net_buf_simple *buf) -{ - uint16_t val; - void *ptr; - - ptr = net_buf_simple_remove_mem(buf, sizeof(val)); - val = UNALIGNED_GET((uint16_t *)ptr); - - return sys_le16_to_cpu(val); -} - -uint16_t net_buf_simple_remove_be16(struct net_buf_simple *buf) -{ - uint16_t val; - void *ptr; - - ptr = net_buf_simple_remove_mem(buf, sizeof(val)); - val = UNALIGNED_GET((uint16_t *)ptr); - - return sys_be16_to_cpu(val); -} - -uint32_t net_buf_simple_remove_le24(struct net_buf_simple *buf) -{ - struct uint24 { - uint32_t u24 : 24; - } __packed val; - void *ptr; - - ptr = net_buf_simple_remove_mem(buf, sizeof(val)); - val = UNALIGNED_GET((struct uint24 *)ptr); - - return sys_le24_to_cpu(val.u24); -} - -uint32_t net_buf_simple_remove_be24(struct net_buf_simple *buf) -{ - struct uint24 { - uint32_t u24 : 24; - } __packed val; - void *ptr; - - ptr = net_buf_simple_remove_mem(buf, sizeof(val)); - val = UNALIGNED_GET((struct uint24 *)ptr); - - return sys_be24_to_cpu(val.u24); -} - -uint32_t net_buf_simple_remove_le32(struct net_buf_simple *buf) -{ - uint32_t val; - void *ptr; - - ptr = net_buf_simple_remove_mem(buf, sizeof(val)); - val = UNALIGNED_GET((uint32_t *)ptr); - - return sys_le32_to_cpu(val); -} - -uint32_t net_buf_simple_remove_be32(struct net_buf_simple *buf) -{ - uint32_t val; - void *ptr; - - ptr = net_buf_simple_remove_mem(buf, sizeof(val)); - val = UNALIGNED_GET((uint32_t *)ptr); - - return sys_be32_to_cpu(val); -} - -uint64_t net_buf_simple_remove_le48(struct net_buf_simple *buf) -{ - struct uint48 { - uint64_t u48 : 48; - } __packed val; - void *ptr; - - ptr = net_buf_simple_remove_mem(buf, sizeof(val)); - val = UNALIGNED_GET((struct uint48 *)ptr); - - return sys_le48_to_cpu(val.u48); -} - -uint64_t net_buf_simple_remove_be48(struct net_buf_simple *buf) -{ - struct uint48 { - uint64_t u48 : 48; - } __packed val; - void *ptr; - - ptr = net_buf_simple_remove_mem(buf, sizeof(val)); - val = UNALIGNED_GET((struct uint48 *)ptr); - - return sys_be48_to_cpu(val.u48); -} - -uint64_t net_buf_simple_remove_le64(struct net_buf_simple *buf) -{ - uint64_t val; - void *ptr; - - ptr = net_buf_simple_remove_mem(buf, sizeof(val)); - val = UNALIGNED_GET((uint64_t *)ptr); - - return sys_le64_to_cpu(val); -} - -uint64_t net_buf_simple_remove_be64(struct net_buf_simple *buf) -{ - uint64_t val; - void *ptr; - - ptr = net_buf_simple_remove_mem(buf, sizeof(val)); - val = UNALIGNED_GET((uint64_t *)ptr); - - return sys_be64_to_cpu(val); -} - -void *net_buf_simple_push(struct net_buf_simple *buf, size_t len) -{ - NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); - - __ASSERT_NO_MSG(net_buf_simple_headroom(buf) >= len); - - buf->data -= len; - buf->len += len; - return buf->data; -} - -void *net_buf_simple_push_mem(struct net_buf_simple *buf, const void *mem, - size_t len) -{ - NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); - - return memcpy(net_buf_simple_push(buf, len), mem, len); -} - -void net_buf_simple_push_le16(struct net_buf_simple *buf, uint16_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - - sys_put_le16(val, net_buf_simple_push(buf, sizeof(val))); -} - -void net_buf_simple_push_be16(struct net_buf_simple *buf, uint16_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - - sys_put_be16(val, net_buf_simple_push(buf, sizeof(val))); -} - -void net_buf_simple_push_u8(struct net_buf_simple *buf, uint8_t val) -{ - uint8_t *data = net_buf_simple_push(buf, 1); - - *data = val; -} - -void net_buf_simple_push_le24(struct net_buf_simple *buf, uint32_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - - sys_put_le24(val, net_buf_simple_push(buf, 3)); -} - -void net_buf_simple_push_be24(struct net_buf_simple *buf, uint32_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - - sys_put_be24(val, net_buf_simple_push(buf, 3)); -} - -void net_buf_simple_push_le32(struct net_buf_simple *buf, uint32_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - - sys_put_le32(val, net_buf_simple_push(buf, sizeof(val))); -} - -void net_buf_simple_push_be32(struct net_buf_simple *buf, uint32_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - - sys_put_be32(val, net_buf_simple_push(buf, sizeof(val))); -} - -void net_buf_simple_push_le48(struct net_buf_simple *buf, uint64_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); - - sys_put_le48(val, net_buf_simple_push(buf, 6)); -} - -void net_buf_simple_push_be48(struct net_buf_simple *buf, uint64_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); - - sys_put_be48(val, net_buf_simple_push(buf, 6)); -} - -void net_buf_simple_push_le64(struct net_buf_simple *buf, uint64_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); - - sys_put_le64(val, net_buf_simple_push(buf, sizeof(val))); -} - -void net_buf_simple_push_be64(struct net_buf_simple *buf, uint64_t val) -{ - NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); - - sys_put_be64(val, net_buf_simple_push(buf, sizeof(val))); -} - -void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len) -{ - NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); - - __ASSERT_NO_MSG(buf->len >= len); - - buf->len -= len; - return buf->data += len; -} - -void *net_buf_simple_pull_mem(struct net_buf_simple *buf, size_t len) -{ - void *data = buf->data; - - NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); - - __ASSERT_NO_MSG(buf->len >= len); - - buf->len -= len; - buf->data += len; - - return data; -} - -uint8_t net_buf_simple_pull_u8(struct net_buf_simple *buf) -{ - uint8_t val; - - val = buf->data[0]; - net_buf_simple_pull(buf, 1); - - return val; -} - -uint16_t net_buf_simple_pull_le16(struct net_buf_simple *buf) -{ - uint16_t val; - - val = UNALIGNED_GET((uint16_t *)buf->data); - net_buf_simple_pull(buf, sizeof(val)); - - return sys_le16_to_cpu(val); -} - -uint16_t net_buf_simple_pull_be16(struct net_buf_simple *buf) -{ - uint16_t val; - - val = UNALIGNED_GET((uint16_t *)buf->data); - net_buf_simple_pull(buf, sizeof(val)); - - return sys_be16_to_cpu(val); -} - -uint32_t net_buf_simple_pull_le24(struct net_buf_simple *buf) -{ - struct uint24 { - uint32_t u24:24; - } __packed val; - - val = UNALIGNED_GET((struct uint24 *)buf->data); - net_buf_simple_pull(buf, sizeof(val)); - - return sys_le24_to_cpu(val.u24); -} - -uint32_t net_buf_simple_pull_be24(struct net_buf_simple *buf) -{ - struct uint24 { - uint32_t u24:24; - } __packed val; - - val = UNALIGNED_GET((struct uint24 *)buf->data); - net_buf_simple_pull(buf, sizeof(val)); - - return sys_be24_to_cpu(val.u24); -} - -uint32_t net_buf_simple_pull_le32(struct net_buf_simple *buf) -{ - uint32_t val; - - val = UNALIGNED_GET((uint32_t *)buf->data); - net_buf_simple_pull(buf, sizeof(val)); - - return sys_le32_to_cpu(val); -} - -uint32_t net_buf_simple_pull_be32(struct net_buf_simple *buf) -{ - uint32_t val; - - val = UNALIGNED_GET((uint32_t *)buf->data); - net_buf_simple_pull(buf, sizeof(val)); - - return sys_be32_to_cpu(val); -} - -uint64_t net_buf_simple_pull_le48(struct net_buf_simple *buf) -{ - struct uint48 { - uint64_t u48:48; - } __packed val; - - val = UNALIGNED_GET((struct uint48 *)buf->data); - net_buf_simple_pull(buf, sizeof(val)); - - return sys_le48_to_cpu(val.u48); -} - -uint64_t net_buf_simple_pull_be48(struct net_buf_simple *buf) -{ - struct uint48 { - uint64_t u48:48; - } __packed val; - - val = UNALIGNED_GET((struct uint48 *)buf->data); - net_buf_simple_pull(buf, sizeof(val)); - - return sys_be48_to_cpu(val.u48); -} - -uint64_t net_buf_simple_pull_le64(struct net_buf_simple *buf) -{ - uint64_t val; - - val = UNALIGNED_GET((uint64_t *)buf->data); - net_buf_simple_pull(buf, sizeof(val)); - - return sys_le64_to_cpu(val); -} - -uint64_t net_buf_simple_pull_be64(struct net_buf_simple *buf) -{ - uint64_t val; - - val = UNALIGNED_GET((uint64_t *)buf->data); - net_buf_simple_pull(buf, sizeof(val)); - - return sys_be64_to_cpu(val); -} - -size_t net_buf_simple_headroom(struct net_buf_simple *buf) -{ - return buf->data - buf->__buf; -} - -size_t net_buf_simple_tailroom(struct net_buf_simple *buf) -{ - return buf->size - net_buf_simple_headroom(buf) - buf->len; -} - -uint16_t net_buf_simple_max_len(struct net_buf_simple *buf) -{ - return buf->size - net_buf_simple_headroom(buf); -} diff --git a/subsys/net/buf_simple.c b/subsys/net/buf_simple.c new file mode 100644 index 000000000000..8937a6361564 --- /dev/null +++ b/subsys/net/buf_simple.c @@ -0,0 +1,548 @@ +/* buf_simple.c - Simple network buffer management */ + +/* + * Copyright (c) 2015-2019 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +LOG_MODULE_REGISTER(net_buf_simple, CONFIG_NET_BUF_LOG_LEVEL); + +#include +#include +#include +#include + +#include + +#if defined(CONFIG_NET_BUF_SIMPLE_LOG) +#define NET_BUF_SIMPLE_DBG(fmt, ...) LOG_DBG("(%p) " fmt, k_current_get(), \ + ##__VA_ARGS__) +#define NET_BUF_SIMPLE_ERR(fmt, ...) LOG_ERR(fmt, ##__VA_ARGS__) +#define NET_BUF_SIMPLE_WARN(fmt, ...) LOG_WRN(fmt, ##__VA_ARGS__) +#define NET_BUF_SIMPLE_INFO(fmt, ...) LOG_INF(fmt, ##__VA_ARGS__) +#else +#define NET_BUF_SIMPLE_DBG(fmt, ...) +#define NET_BUF_SIMPLE_ERR(fmt, ...) +#define NET_BUF_SIMPLE_WARN(fmt, ...) +#define NET_BUF_SIMPLE_INFO(fmt, ...) +#endif /* CONFIG_NET_BUF_SIMPLE_LOG */ + +void net_buf_simple_init_with_data(struct net_buf_simple *buf, + void *data, size_t size) +{ + buf->__buf = data; + buf->data = data; + buf->size = size; + buf->len = size; +} + +void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve) +{ + __ASSERT_NO_MSG(buf); + __ASSERT_NO_MSG(buf->len == 0U); + NET_BUF_SIMPLE_DBG("buf %p reserve %zu", buf, reserve); + + buf->data = buf->__buf + reserve; +} + +void net_buf_simple_clone(const struct net_buf_simple *original, + struct net_buf_simple *clone) +{ + memcpy(clone, original, sizeof(struct net_buf_simple)); +} + +void *net_buf_simple_add(struct net_buf_simple *buf, size_t len) +{ + uint8_t *tail = net_buf_simple_tail(buf); + + NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); + + __ASSERT_NO_MSG(net_buf_simple_tailroom(buf) >= len); + + buf->len += len; + return tail; +} + +void *net_buf_simple_add_mem(struct net_buf_simple *buf, const void *mem, + size_t len) +{ + NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); + + return memcpy(net_buf_simple_add(buf, len), mem, len); +} + +uint8_t *net_buf_simple_add_u8(struct net_buf_simple *buf, uint8_t val) +{ + uint8_t *u8; + + NET_BUF_SIMPLE_DBG("buf %p val 0x%02x", buf, val); + + u8 = net_buf_simple_add(buf, 1); + *u8 = val; + + return u8; +} + +void net_buf_simple_add_le16(struct net_buf_simple *buf, uint16_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); + + sys_put_le16(val, net_buf_simple_add(buf, sizeof(val))); +} + +void net_buf_simple_add_be16(struct net_buf_simple *buf, uint16_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); + + sys_put_be16(val, net_buf_simple_add(buf, sizeof(val))); +} + +void net_buf_simple_add_le24(struct net_buf_simple *buf, uint32_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); + + sys_put_le24(val, net_buf_simple_add(buf, 3)); +} + +void net_buf_simple_add_be24(struct net_buf_simple *buf, uint32_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); + + sys_put_be24(val, net_buf_simple_add(buf, 3)); +} + +void net_buf_simple_add_le32(struct net_buf_simple *buf, uint32_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); + + sys_put_le32(val, net_buf_simple_add(buf, sizeof(val))); +} + +void net_buf_simple_add_be32(struct net_buf_simple *buf, uint32_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); + + sys_put_be32(val, net_buf_simple_add(buf, sizeof(val))); +} + +void net_buf_simple_add_le48(struct net_buf_simple *buf, uint64_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); + + sys_put_le48(val, net_buf_simple_add(buf, 6)); +} + +void net_buf_simple_add_be48(struct net_buf_simple *buf, uint64_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); + + sys_put_be48(val, net_buf_simple_add(buf, 6)); +} + +void net_buf_simple_add_le64(struct net_buf_simple *buf, uint64_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); + + sys_put_le64(val, net_buf_simple_add(buf, sizeof(val))); +} + +void net_buf_simple_add_be64(struct net_buf_simple *buf, uint64_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); + + sys_put_be64(val, net_buf_simple_add(buf, sizeof(val))); +} + +void *net_buf_simple_remove_mem(struct net_buf_simple *buf, size_t len) +{ + NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); + + __ASSERT_NO_MSG(buf->len >= len); + + buf->len -= len; + return buf->data + buf->len; +} + +uint8_t net_buf_simple_remove_u8(struct net_buf_simple *buf) +{ + uint8_t val; + void *ptr; + + ptr = net_buf_simple_remove_mem(buf, sizeof(val)); + val = *(uint8_t *)ptr; + + return val; +} + +uint16_t net_buf_simple_remove_le16(struct net_buf_simple *buf) +{ + uint16_t val; + void *ptr; + + ptr = net_buf_simple_remove_mem(buf, sizeof(val)); + val = UNALIGNED_GET((uint16_t *)ptr); + + return sys_le16_to_cpu(val); +} + +uint16_t net_buf_simple_remove_be16(struct net_buf_simple *buf) +{ + uint16_t val; + void *ptr; + + ptr = net_buf_simple_remove_mem(buf, sizeof(val)); + val = UNALIGNED_GET((uint16_t *)ptr); + + return sys_be16_to_cpu(val); +} + +uint32_t net_buf_simple_remove_le24(struct net_buf_simple *buf) +{ + struct uint24 { + uint32_t u24 : 24; + } __packed val; + void *ptr; + + ptr = net_buf_simple_remove_mem(buf, sizeof(val)); + val = UNALIGNED_GET((struct uint24 *)ptr); + + return sys_le24_to_cpu(val.u24); +} + +uint32_t net_buf_simple_remove_be24(struct net_buf_simple *buf) +{ + struct uint24 { + uint32_t u24 : 24; + } __packed val; + void *ptr; + + ptr = net_buf_simple_remove_mem(buf, sizeof(val)); + val = UNALIGNED_GET((struct uint24 *)ptr); + + return sys_be24_to_cpu(val.u24); +} + +uint32_t net_buf_simple_remove_le32(struct net_buf_simple *buf) +{ + uint32_t val; + void *ptr; + + ptr = net_buf_simple_remove_mem(buf, sizeof(val)); + val = UNALIGNED_GET((uint32_t *)ptr); + + return sys_le32_to_cpu(val); +} + +uint32_t net_buf_simple_remove_be32(struct net_buf_simple *buf) +{ + uint32_t val; + void *ptr; + + ptr = net_buf_simple_remove_mem(buf, sizeof(val)); + val = UNALIGNED_GET((uint32_t *)ptr); + + return sys_be32_to_cpu(val); +} + +uint64_t net_buf_simple_remove_le48(struct net_buf_simple *buf) +{ + struct uint48 { + uint64_t u48 : 48; + } __packed val; + void *ptr; + + ptr = net_buf_simple_remove_mem(buf, sizeof(val)); + val = UNALIGNED_GET((struct uint48 *)ptr); + + return sys_le48_to_cpu(val.u48); +} + +uint64_t net_buf_simple_remove_be48(struct net_buf_simple *buf) +{ + struct uint48 { + uint64_t u48 : 48; + } __packed val; + void *ptr; + + ptr = net_buf_simple_remove_mem(buf, sizeof(val)); + val = UNALIGNED_GET((struct uint48 *)ptr); + + return sys_be48_to_cpu(val.u48); +} + +uint64_t net_buf_simple_remove_le64(struct net_buf_simple *buf) +{ + uint64_t val; + void *ptr; + + ptr = net_buf_simple_remove_mem(buf, sizeof(val)); + val = UNALIGNED_GET((uint64_t *)ptr); + + return sys_le64_to_cpu(val); +} + +uint64_t net_buf_simple_remove_be64(struct net_buf_simple *buf) +{ + uint64_t val; + void *ptr; + + ptr = net_buf_simple_remove_mem(buf, sizeof(val)); + val = UNALIGNED_GET((uint64_t *)ptr); + + return sys_be64_to_cpu(val); +} + +void *net_buf_simple_push(struct net_buf_simple *buf, size_t len) +{ + NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); + + __ASSERT_NO_MSG(net_buf_simple_headroom(buf) >= len); + + buf->data -= len; + buf->len += len; + return buf->data; +} + +void *net_buf_simple_push_mem(struct net_buf_simple *buf, const void *mem, + size_t len) +{ + NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); + + return memcpy(net_buf_simple_push(buf, len), mem, len); +} + +void net_buf_simple_push_le16(struct net_buf_simple *buf, uint16_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); + + sys_put_le16(val, net_buf_simple_push(buf, sizeof(val))); +} + +void net_buf_simple_push_be16(struct net_buf_simple *buf, uint16_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); + + sys_put_be16(val, net_buf_simple_push(buf, sizeof(val))); +} + +void net_buf_simple_push_u8(struct net_buf_simple *buf, uint8_t val) +{ + uint8_t *data = net_buf_simple_push(buf, 1); + + *data = val; +} + +void net_buf_simple_push_le24(struct net_buf_simple *buf, uint32_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); + + sys_put_le24(val, net_buf_simple_push(buf, 3)); +} + +void net_buf_simple_push_be24(struct net_buf_simple *buf, uint32_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); + + sys_put_be24(val, net_buf_simple_push(buf, 3)); +} + +void net_buf_simple_push_le32(struct net_buf_simple *buf, uint32_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); + + sys_put_le32(val, net_buf_simple_push(buf, sizeof(val))); +} + +void net_buf_simple_push_be32(struct net_buf_simple *buf, uint32_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); + + sys_put_be32(val, net_buf_simple_push(buf, sizeof(val))); +} + +void net_buf_simple_push_le48(struct net_buf_simple *buf, uint64_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); + + sys_put_le48(val, net_buf_simple_push(buf, 6)); +} + +void net_buf_simple_push_be48(struct net_buf_simple *buf, uint64_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); + + sys_put_be48(val, net_buf_simple_push(buf, 6)); +} + +void net_buf_simple_push_le64(struct net_buf_simple *buf, uint64_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); + + sys_put_le64(val, net_buf_simple_push(buf, sizeof(val))); +} + +void net_buf_simple_push_be64(struct net_buf_simple *buf, uint64_t val) +{ + NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val); + + sys_put_be64(val, net_buf_simple_push(buf, sizeof(val))); +} + +void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len) +{ + NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); + + __ASSERT_NO_MSG(buf->len >= len); + + buf->len -= len; + return buf->data += len; +} + +void *net_buf_simple_pull_mem(struct net_buf_simple *buf, size_t len) +{ + void *data = buf->data; + + NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); + + __ASSERT_NO_MSG(buf->len >= len); + + buf->len -= len; + buf->data += len; + + return data; +} + +uint8_t net_buf_simple_pull_u8(struct net_buf_simple *buf) +{ + uint8_t val; + + val = buf->data[0]; + net_buf_simple_pull(buf, 1); + + return val; +} + +uint16_t net_buf_simple_pull_le16(struct net_buf_simple *buf) +{ + uint16_t val; + + val = UNALIGNED_GET((uint16_t *)buf->data); + net_buf_simple_pull(buf, sizeof(val)); + + return sys_le16_to_cpu(val); +} + +uint16_t net_buf_simple_pull_be16(struct net_buf_simple *buf) +{ + uint16_t val; + + val = UNALIGNED_GET((uint16_t *)buf->data); + net_buf_simple_pull(buf, sizeof(val)); + + return sys_be16_to_cpu(val); +} + +uint32_t net_buf_simple_pull_le24(struct net_buf_simple *buf) +{ + struct uint24 { + uint32_t u24:24; + } __packed val; + + val = UNALIGNED_GET((struct uint24 *)buf->data); + net_buf_simple_pull(buf, sizeof(val)); + + return sys_le24_to_cpu(val.u24); +} + +uint32_t net_buf_simple_pull_be24(struct net_buf_simple *buf) +{ + struct uint24 { + uint32_t u24:24; + } __packed val; + + val = UNALIGNED_GET((struct uint24 *)buf->data); + net_buf_simple_pull(buf, sizeof(val)); + + return sys_be24_to_cpu(val.u24); +} + +uint32_t net_buf_simple_pull_le32(struct net_buf_simple *buf) +{ + uint32_t val; + + val = UNALIGNED_GET((uint32_t *)buf->data); + net_buf_simple_pull(buf, sizeof(val)); + + return sys_le32_to_cpu(val); +} + +uint32_t net_buf_simple_pull_be32(struct net_buf_simple *buf) +{ + uint32_t val; + + val = UNALIGNED_GET((uint32_t *)buf->data); + net_buf_simple_pull(buf, sizeof(val)); + + return sys_be32_to_cpu(val); +} + +uint64_t net_buf_simple_pull_le48(struct net_buf_simple *buf) +{ + struct uint48 { + uint64_t u48:48; + } __packed val; + + val = UNALIGNED_GET((struct uint48 *)buf->data); + net_buf_simple_pull(buf, sizeof(val)); + + return sys_le48_to_cpu(val.u48); +} + +uint64_t net_buf_simple_pull_be48(struct net_buf_simple *buf) +{ + struct uint48 { + uint64_t u48:48; + } __packed val; + + val = UNALIGNED_GET((struct uint48 *)buf->data); + net_buf_simple_pull(buf, sizeof(val)); + + return sys_be48_to_cpu(val.u48); +} + +uint64_t net_buf_simple_pull_le64(struct net_buf_simple *buf) +{ + uint64_t val; + + val = UNALIGNED_GET((uint64_t *)buf->data); + net_buf_simple_pull(buf, sizeof(val)); + + return sys_le64_to_cpu(val); +} + +uint64_t net_buf_simple_pull_be64(struct net_buf_simple *buf) +{ + uint64_t val; + + val = UNALIGNED_GET((uint64_t *)buf->data); + net_buf_simple_pull(buf, sizeof(val)); + + return sys_be64_to_cpu(val); +} + +size_t net_buf_simple_headroom(struct net_buf_simple *buf) +{ + return buf->data - buf->__buf; +} + +size_t net_buf_simple_tailroom(struct net_buf_simple *buf) +{ + return buf->size - net_buf_simple_headroom(buf) - buf->len; +} + +uint16_t net_buf_simple_max_len(struct net_buf_simple *buf) +{ + return buf->size - net_buf_simple_headroom(buf); +} From 063c039480881d73bcb9fcbd28000bf45194174b Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Tue, 7 Mar 2023 13:42:37 +0100 Subject: [PATCH 0228/1906] test: net: buf_simple: Add unit tests for simple buffers This adds set of unit tests for simple network buffers. The suite is based of the test cases that are already defined for network buffers. Those test_net_buf_byte_order test case have been split to smaller tests testing one functionality at a time. Signed-off-by: Mariusz Skamra --- tests/net/buf_simple/CMakeLists.txt | 18 ++ tests/net/buf_simple/prj.conf | 10 + tests/net/buf_simple/src/main.c | 406 ++++++++++++++++++++++++++++ tests/net/buf_simple/testcase.yaml | 5 + tests/net/mocks/CMakeLists.txt | 13 + tests/net/mocks/assert.c | 39 +++ tests/net/mocks/assert.h | 16 ++ 7 files changed, 507 insertions(+) create mode 100644 tests/net/buf_simple/CMakeLists.txt create mode 100644 tests/net/buf_simple/prj.conf create mode 100644 tests/net/buf_simple/src/main.c create mode 100644 tests/net/buf_simple/testcase.yaml create mode 100644 tests/net/mocks/CMakeLists.txt create mode 100644 tests/net/mocks/assert.c create mode 100644 tests/net/mocks/assert.h diff --git a/tests/net/buf_simple/CMakeLists.txt b/tests/net/buf_simple/CMakeLists.txt new file mode 100644 index 000000000000..3feb1b01bfdf --- /dev/null +++ b/tests/net/buf_simple/CMakeLists.txt @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +project(buf_simple) + +find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) + +add_subdirectory(${ZEPHYR_BASE}/tests/net/mocks net_mocks) + +target_link_libraries(testbinary PRIVATE net_mocks) + +target_sources(testbinary + PRIVATE + src/main.c + + ${ZEPHYR_BASE}/subsys/net/buf_simple.c +) diff --git a/tests/net/buf_simple/prj.conf b/tests/net/buf_simple/prj.conf new file mode 100644 index 000000000000..2d34630767b0 --- /dev/null +++ b/tests/net/buf_simple/prj.conf @@ -0,0 +1,10 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_ASSERT=y +CONFIG_ASSERT_LEVEL=2 +CONFIG_ASSERT_VERBOSE=y +CONFIG_ASSERT_ON_ERRORS=y +CONFIG_NET_BUF=y +#CONFIG_NET_BUF_LOG=y +#CONFIG_NET_BUF_LOG_LEVEL_DBG=y +#CONFIG_NET_BUF_SIMPLE_LOG=y diff --git a/tests/net/buf_simple/src/main.c b/tests/net/buf_simple/src/main.c new file mode 100644 index 000000000000..def63b38aaea --- /dev/null +++ b/tests/net/buf_simple/src/main.c @@ -0,0 +1,406 @@ +/* + * Copyright (c) 2015 Intel Corporation + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +DEFINE_FFF_GLOBALS; + +NET_BUF_SIMPLE_DEFINE_STATIC(buf, 16); +static const uint8_t le16[2] = { 0x02, 0x01 }; +static const uint8_t be16[2] = { 0x01, 0x02 }; +static const uint8_t le24[3] = { 0x03, 0x02, 0x01 }; +static const uint8_t be24[3] = { 0x01, 0x02, 0x03 }; +static const uint8_t le32[4] = { 0x04, 0x03, 0x02, 0x01 }; +static const uint8_t be32[4] = { 0x01, 0x02, 0x03, 0x04 }; +static const uint8_t le48[6] = { 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +static const uint8_t be48[6] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; +static const uint8_t le64[8] = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +static const uint8_t be64[8] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +static const uint16_t u16 = 0x0102; +static const uint32_t u24 = 0x010203; +static const uint32_t u32 = 0x01020304; +static const uint64_t u48 = 0x010203040506; +static const uint64_t u64 = 0x0102030405060708; + +static void net_buf_simple_test_suite_before(void *f) +{ + net_buf_simple_reset(&buf); +} + +ZTEST_SUITE(net_buf_simple_test_suite, NULL, NULL, + net_buf_simple_test_suite_before, NULL, NULL); + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_clone) +{ + struct net_buf_simple clone; + + net_buf_simple_clone(&buf, &clone); + + zassert_equal(buf.data, clone.data, "Incorrect clone data pointer"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_pull_le16) +{ + net_buf_simple_add_mem(&buf, &le16, sizeof(le16)); + + zassert_equal(u16, net_buf_simple_pull_le16(&buf), + "Invalid 16 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_pull_be16) +{ + net_buf_simple_add_mem(&buf, &be16, sizeof(be16)); + + zassert_equal(u16, net_buf_simple_pull_be16(&buf), + "Invalid 16 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_add_le16) +{ + net_buf_simple_add_le16(&buf, u16); + + zassert_mem_equal(le16, net_buf_simple_pull_mem(&buf, sizeof(le16)), + sizeof(le16), "Invalid 16 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_add_be16) +{ + net_buf_simple_add_be16(&buf, u16); + + zassert_mem_equal(be16, net_buf_simple_pull_mem(&buf, sizeof(be16)), + sizeof(be16), "Invalid 16 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_pull_le24) +{ + net_buf_simple_add_mem(&buf, &le24, sizeof(le24)); + + zassert_equal(u24, net_buf_simple_pull_le24(&buf), + "Invalid 24 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_pull_be24) +{ + net_buf_simple_add_mem(&buf, &be24, sizeof(be24)); + + zassert_equal(u24, net_buf_simple_pull_be24(&buf), + "Invalid 24 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_add_le24) +{ + net_buf_simple_add_le24(&buf, u24); + + zassert_mem_equal(le24, net_buf_simple_pull_mem(&buf, sizeof(le24)), + sizeof(le24), "Invalid 24 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_add_be24) +{ + net_buf_simple_add_be24(&buf, u24); + + zassert_mem_equal(be24, net_buf_simple_pull_mem(&buf, sizeof(be24)), + sizeof(be24), "Invalid 24 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_pull_le32) +{ + net_buf_simple_add_mem(&buf, &le32, sizeof(le32)); + + zassert_equal(u32, net_buf_simple_pull_le32(&buf), + "Invalid 32 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_pull_be32) +{ + net_buf_simple_add_mem(&buf, &be32, sizeof(be32)); + + zassert_equal(u32, net_buf_simple_pull_be32(&buf), + "Invalid 32 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_add_le32) +{ + net_buf_simple_add_le32(&buf, u32); + + zassert_mem_equal(le32, net_buf_simple_pull_mem(&buf, sizeof(le32)), + sizeof(le32), "Invalid 32 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_add_be32) +{ + net_buf_simple_add_be32(&buf, u32); + + zassert_mem_equal(be32, net_buf_simple_pull_mem(&buf, sizeof(be32)), + sizeof(be32), "Invalid 32 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_pull_le48) +{ + net_buf_simple_add_mem(&buf, &le48, sizeof(le48)); + + zassert_equal(u48, net_buf_simple_pull_le48(&buf), + "Invalid 48 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_pull_be48) +{ + net_buf_simple_add_mem(&buf, &be48, sizeof(be48)); + + zassert_equal(u48, net_buf_simple_pull_be48(&buf), + "Invalid 48 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_add_le48) +{ + net_buf_simple_add_le48(&buf, u48); + + zassert_mem_equal(le48, net_buf_simple_pull_mem(&buf, sizeof(le48)), + sizeof(le48), "Invalid 48 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_add_be48) +{ + net_buf_simple_add_be48(&buf, u48); + + zassert_mem_equal(be48, net_buf_simple_pull_mem(&buf, sizeof(be48)), + sizeof(be48), "Invalid 48 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_pull_le64) +{ + net_buf_simple_add_mem(&buf, &le64, sizeof(le64)); + + zassert_equal(u64, net_buf_simple_pull_le64(&buf), + "Invalid 64 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_pull_be64) +{ + net_buf_simple_add_mem(&buf, &be64, sizeof(be64)); + + zassert_equal(u64, net_buf_simple_pull_be64(&buf), + "Invalid 64 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_add_le64) +{ + net_buf_simple_add_le64(&buf, u64); + + zassert_mem_equal(le64, net_buf_simple_pull_mem(&buf, sizeof(le64)), + sizeof(le64), "Invalid 64 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_add_be64) +{ + net_buf_simple_add_be64(&buf, u64); + + zassert_mem_equal(be64, net_buf_simple_pull_mem(&buf, sizeof(be64)), + sizeof(be64), "Invalid 64 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_remove_le16) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_mem(&buf, &le16, sizeof(le16)); + + zassert_equal(u16, net_buf_simple_remove_le16(&buf), + "Invalid 16 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_remove_be16) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_mem(&buf, &be16, sizeof(be16)); + + zassert_equal(u16, net_buf_simple_remove_be16(&buf), + "Invalid 16 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_push_le16) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_le16(&buf, u16); + + zassert_mem_equal(le16, net_buf_simple_remove_mem(&buf, sizeof(le16)), + sizeof(le16), "Invalid 16 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_push_be16) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_be16(&buf, u16); + + zassert_mem_equal(be16, net_buf_simple_remove_mem(&buf, sizeof(be16)), + sizeof(be16), "Invalid 16 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_remove_le24) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_mem(&buf, &le24, sizeof(le24)); + + zassert_equal(u24, net_buf_simple_remove_le24(&buf), + "Invalid 24 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_remove_be24) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_mem(&buf, &be24, sizeof(be24)); + + zassert_equal(u24, net_buf_simple_remove_be24(&buf), + "Invalid 24 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_push_le24) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_le24(&buf, u24); + + zassert_mem_equal(le24, net_buf_simple_remove_mem(&buf, sizeof(le24)), + sizeof(le24), "Invalid 24 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_push_be24) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_be24(&buf, u24); + + zassert_mem_equal(be24, net_buf_simple_remove_mem(&buf, sizeof(be24)), + sizeof(be24), "Invalid 24 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_remove_le32) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_mem(&buf, &le32, sizeof(le32)); + + zassert_equal(u32, net_buf_simple_remove_le32(&buf), + "Invalid 32 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_remove_be32) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_mem(&buf, &be32, sizeof(be32)); + + zassert_equal(u32, net_buf_simple_remove_be32(&buf), + "Invalid 32 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_push_le32) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_le32(&buf, u32); + + zassert_mem_equal(le32, net_buf_simple_remove_mem(&buf, sizeof(le32)), + sizeof(le32), "Invalid 32 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_push_be32) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_be32(&buf, u32); + + zassert_mem_equal(be32, net_buf_simple_remove_mem(&buf, sizeof(be32)), + sizeof(be32), "Invalid 32 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_remove_le48) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_mem(&buf, &le48, sizeof(le48)); + + zassert_equal(u48, net_buf_simple_remove_le48(&buf), + "Invalid 48 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_remove_be48) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_mem(&buf, &be48, sizeof(be48)); + + zassert_equal(u48, net_buf_simple_remove_be48(&buf), + "Invalid 48 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_push_le48) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_le48(&buf, u48); + + zassert_mem_equal(le48, net_buf_simple_remove_mem(&buf, sizeof(le48)), + sizeof(le48), "Invalid 48 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_push_be48) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_be48(&buf, u48); + + zassert_mem_equal(be48, net_buf_simple_remove_mem(&buf, sizeof(be48)), + sizeof(be48), "Invalid 48 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_remove_le64) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_mem(&buf, &le64, sizeof(le64)); + + zassert_equal(u64, net_buf_simple_remove_le64(&buf), + "Invalid 64 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_remove_be64) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_mem(&buf, &be64, sizeof(be64)); + + zassert_equal(u64, net_buf_simple_remove_be64(&buf), + "Invalid 64 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_push_le64) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_le64(&buf, u64); + + zassert_mem_equal(le64, net_buf_simple_remove_mem(&buf, sizeof(le64)), + sizeof(le64), "Invalid 64 bits byte order"); +} + +ZTEST(net_buf_simple_test_suite, test_net_buf_simple_push_be64) +{ + net_buf_simple_reserve(&buf, 16); + + net_buf_simple_push_be64(&buf, u64); + + zassert_mem_equal(be64, net_buf_simple_remove_mem(&buf, sizeof(be64)), + sizeof(be64), "Invalid 64 bits byte order"); +} diff --git a/tests/net/buf_simple/testcase.yaml b/tests/net/buf_simple/testcase.yaml new file mode 100644 index 000000000000..8710f842d7e7 --- /dev/null +++ b/tests/net/buf_simple/testcase.yaml @@ -0,0 +1,5 @@ +common: + tags: net buf +tests: + net.buf_simple: + type: unit diff --git a/tests/net/mocks/CMakeLists.txt b/tests/net/mocks/CMakeLists.txt new file mode 100644 index 000000000000..a6b3e5936c7f --- /dev/null +++ b/tests/net/mocks/CMakeLists.txt @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: Apache-2.0 + +add_library(net_mocks STATIC + assert.c +) + +target_include_directories(net_mocks PUBLIC + ${ZEPHYR_BASE}/subsys/net + ${ZEPHYR_BASE}/tests/net +) + +target_link_libraries(net_mocks PRIVATE test_interface) +target_compile_options(test_interface INTERFACE -include ztest.h) diff --git a/tests/net/mocks/assert.c b/tests/net/mocks/assert.c new file mode 100644 index 000000000000..643347968052 --- /dev/null +++ b/tests/net/mocks/assert.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "assert.h" + +DEFINE_FAKE_VALUE_FUNC(bool, mock_check_if_assert_expected); + +void assert_print(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vprintk(fmt, ap); + va_end(ap); +} + +void assert_post_action(const char *file, unsigned int line) +{ + /* ztest_test_pass()/ztest_test_fail() are used to stop the execution + * If this is an unexpected assert (i.e. not following expect_assert()) + * calling mock_check_if_assert_expected() will return 'false' as + * a default return value + */ + if (mock_check_if_assert_expected() == true) { + printk("Assertion expected as part of a test case.\n"); + /* Mark the test as passed and stop execution: + * Needed in the passing scenario to prevent undefined behavior after hitting the + * assert. In real builds (non-UT), the system will be halted by the assert. + */ + ztest_test_pass(); + } else { + /* Mark the test as failed and stop execution */ + ztest_test_fail(); + } +} diff --git a/tests/net/mocks/assert.h b/tests/net/mocks/assert.h new file mode 100644 index 000000000000..4282dc803af8 --- /dev/null +++ b/tests/net/mocks/assert.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* List of fakes used by this unit tester */ +#define ASSERT_FFF_FAKES_LIST(FAKE) \ + FAKE(mock_check_if_assert_expected) \ + +DECLARE_FAKE_VALUE_FUNC(bool, mock_check_if_assert_expected); + +#define expect_assert() (mock_check_if_assert_expected_fake.return_val = 1) From 53091c505680df4695b6b2681186156df6df3e8d Mon Sep 17 00:00:00 2001 From: Ludvig Samuelsen Jordet Date: Tue, 14 Mar 2023 16:33:26 +0100 Subject: [PATCH 0229/1906] Bluetooth: Mesh: Fix confusing DFU slot doc The word "valid" is already in use to mean slots that return true for `bt_mesh_dfu_slot_is_valid`, whereas `bt_mesh_dfu_slot_foreach` iterates over all added slots. Signed-off-by: Ludvig Samuelsen Jordet --- subsys/bluetooth/mesh/dfu_slot.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/mesh/dfu_slot.h b/subsys/bluetooth/mesh/dfu_slot.h index 7e4135b2d6d1..1bc58f64de96 100644 --- a/subsys/bluetooth/mesh/dfu_slot.h +++ b/subsys/bluetooth/mesh/dfu_slot.h @@ -102,13 +102,13 @@ int bt_mesh_dfu_slot_get(const uint8_t *fwid, size_t fwid_len, */ int bt_mesh_dfu_slot_idx_get(const struct bt_mesh_dfu_slot *slot); -/** @brief Iterate through all valid DFU image slots. +/** @brief Iterate through all DFU image slots. * - * Calls the callback for every valid DFU image slot or until the callback returns + * Calls the callback for every DFU image slot or until the callback returns * something other than @ref BT_MESH_DFU_ITER_CONTINUE. * * @param cb Callback to call for each slot, or NULL to just count the - * number of valid slots. + * number of slots. * @param user_data User data to pass to the callback. * * @return The number of slots iterated over. From 608a9bc89ed80e489a4e1ce946048d40a5485010 Mon Sep 17 00:00:00 2001 From: Filip Kokosinski Date: Mon, 13 Mar 2023 13:50:53 +0100 Subject: [PATCH 0230/1906] dts/arm/st/l4: don't delete the `sram0` node This commit removes the deletion of the `sram0` node, which resulted in the compat string `mmio-sram` missing from the final devicetree when building stm32l4r5-based platforms in Zephyr. This bug was introduced in 306dea6ff3716f9a0b4b5928d044e8f69a285c37. Signed-off-by: Filip Kokosinski --- dts/arm/st/l4/stm32l4r5.dtsi | 1 - 1 file changed, 1 deletion(-) diff --git a/dts/arm/st/l4/stm32l4r5.dtsi b/dts/arm/st/l4/stm32l4r5.dtsi index 417ca9c58cfd..2aa01db17b1b 100644 --- a/dts/arm/st/l4/stm32l4r5.dtsi +++ b/dts/arm/st/l4/stm32l4r5.dtsi @@ -8,7 +8,6 @@ #include /delete-node/ &sdmmc2; -/delete-node/ &sram0; / { sram0: memory@20000000 { From b5465825f15c5fa0e201b2175f8e2f042e593406 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 8 Mar 2023 15:46:21 +0100 Subject: [PATCH 0231/1906] Bluetooth: ascs: Remove duplicated logic The ase_stream_add does the same job as bt_bap_stream_attach that is called right below. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index fb6546dfb396..4cc3d5dff4f9 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -1150,17 +1150,6 @@ static struct bt_bap_iso *bap_iso_get_or_new(struct bt_ascs *ascs, uint8_t cig_i return iso; } -static void ase_stream_add(struct bt_ascs *ascs, struct bt_ascs_ase *ase, - struct bt_bap_stream *stream) -{ - LOG_DBG("ase %p stream %p", ase, stream); - ase->ep.stream = stream; - if (stream->conn == NULL) { - stream->conn = bt_conn_ref(ascs->conn); - } - stream->ep = &ase->ep; -} - static void ascs_init(struct bt_ascs *ascs, struct bt_conn *conn) { memset(ascs, 0, sizeof(*ascs)); @@ -1515,15 +1504,10 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, return err; } - - ase_stream_add(ascs, ase, stream); } ascs_cp_rsp_success(ASE_ID(ase), BT_ASCS_CONFIG_OP); - /* TODO: bt_bap_stream_attach duplicates some of the - * ase_stream_add. Should be cleaned up. - */ bt_bap_stream_attach(ascs->conn, stream, &ase->ep, &ase->ep.codec); ascs_ep_set_state(&ase->ep, BT_BAP_EP_STATE_CODEC_CONFIGURED); From 0b7a335864bfb084a3758aea066e950917675ed1 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 8 Mar 2023 15:55:15 +0100 Subject: [PATCH 0232/1906] Bluetooth: ascs: Fix uninitialized stream object This fixes "Conditional jump or move depends on uninitialised value(s)" error seen in valgrind. The stream object that is allocated by application has to be initialized as it may contain invalid data. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 2 ++ subsys/bluetooth/audio/bap_stream.c | 16 ++++++++++++++++ subsys/bluetooth/audio/bap_stream.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 4cc3d5dff4f9..cb638aacb7bf 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -1504,6 +1504,8 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, return err; } + + bt_bap_stream_init(stream); } ascs_cp_rsp_success(ASE_ID(ase), BT_ASCS_CONFIG_OP); diff --git a/subsys/bluetooth/audio/bap_stream.c b/subsys/bluetooth/audio/bap_stream.c index 9138803b6af8..1a0ae50585b8 100644 --- a/subsys/bluetooth/audio/bap_stream.c +++ b/subsys/bluetooth/audio/bap_stream.c @@ -78,6 +78,22 @@ void bt_audio_codec_qos_to_iso_qos(struct bt_iso_chan_io_qos *io, * CONFIG_BT_BAP_BROADCAST_SINK \ */ +void bt_bap_stream_init(struct bt_bap_stream *stream) +{ + struct bt_bap_stream_ops *ops; + void *user_data; + + /* Save the stream->ops and stream->user_data owned by API user */ + ops = stream->ops; + user_data = stream->user_data; + + memset(stream, 0, sizeof(*stream)); + + /* Restore */ + stream->ops = ops; + stream->user_data = user_data; +} + void bt_bap_stream_attach(struct bt_conn *conn, struct bt_bap_stream *stream, struct bt_bap_ep *ep, struct bt_codec *codec) { diff --git a/subsys/bluetooth/audio/bap_stream.h b/subsys/bluetooth/audio/bap_stream.h index 2f5bb8224f02..0c51b47509c1 100644 --- a/subsys/bluetooth/audio/bap_stream.h +++ b/subsys/bluetooth/audio/bap_stream.h @@ -7,6 +7,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +void bt_bap_stream_init(struct bt_bap_stream *stream); + /* Disconnect ISO channel */ int bt_bap_stream_disconnect(struct bt_bap_stream *stream); From 71f12d71616c062c9ae238ee90df333ed49f940b Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Mon, 13 Mar 2023 23:38:48 -0400 Subject: [PATCH 0233/1906] tests: net: socketpair: explicit fcntl path on native_posix Previously, `socketpair()` tests had pulled in the native `fcntl()` implementation instead of using the Zephyr version when being run under `native_posix_64`. Signed-off-by: Christopher Friedt --- tests/net/socket/socketpair/src/_main.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/net/socket/socketpair/src/_main.h b/tests/net/socket/socketpair/src/_main.h index 7573d72e51f1..ee41ab94f79a 100644 --- a/tests/net/socket/socketpair/src/_main.h +++ b/tests/net/socket/socketpair/src/_main.h @@ -12,16 +12,10 @@ #include #include +#include #include #include -#ifdef CONFIG_ARCH_POSIX -#include -#else -#include -#include -#endif - LOG_MODULE_DECLARE(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL); extern struct k_work_q test_socketpair_work_q; From 1c985a8029d7502665bf3b65720a833824df02bf Mon Sep 17 00:00:00 2001 From: Christopher Friedt Date: Mon, 13 Mar 2023 23:42:01 -0400 Subject: [PATCH 0234/1906] Revert "tests: net: socketpair: skip nonblocking tests on posix arch" This reverts commit 2eb53f4bd79fd348271cb99280f5298acadf50fe. Signed-off-by: Christopher Friedt --- tests/net/socket/socketpair/src/fcntl.c | 5 ----- tests/net/socket/socketpair/src/nonblock.c | 10 ---------- 2 files changed, 15 deletions(-) diff --git a/tests/net/socket/socketpair/src/fcntl.c b/tests/net/socket/socketpair/src/fcntl.c index 9b8da2b34705..b2e4527b51b2 100644 --- a/tests/net/socket/socketpair/src/fcntl.c +++ b/tests/net/socket/socketpair/src/fcntl.c @@ -12,11 +12,6 @@ ZTEST_USER(net_socketpair, fcntl) int sv[2] = {-1, -1}; int flags; - if (IS_ENABLED(CONFIG_ARCH_POSIX)) { - printk("non-blocking socketpair I/O is unsupported with CONFIG_ARCH_POSIX\n"); - ztest_test_skip(); - } - res = socketpair(AF_UNIX, SOCK_STREAM, 0, sv); zassert_equal(res, 0, "socketpair(AF_UNIX, SOCK_STREAM, 0, sv) failed"); diff --git a/tests/net/socket/socketpair/src/nonblock.c b/tests/net/socket/socketpair/src/nonblock.c index c6b2aad57870..5259a5ca68bb 100644 --- a/tests/net/socket/socketpair/src/nonblock.c +++ b/tests/net/socket/socketpair/src/nonblock.c @@ -11,11 +11,6 @@ ZTEST_USER(net_socketpair, write_nonblock) int res; int sv[2] = {-1, -1}; - if (IS_ENABLED(CONFIG_ARCH_POSIX)) { - printk("non-blocking socketpair I/O is unsupported with CONFIG_ARCH_POSIX\n"); - ztest_test_skip(); - } - res = socketpair(AF_UNIX, SOCK_STREAM, 0, sv); zassert_equal(res, 0, "socketpair() failed: %d", errno); @@ -51,11 +46,6 @@ ZTEST_USER(net_socketpair, read_nonblock) int sv[2] = {-1, -1}; char c; - if (IS_ENABLED(CONFIG_ARCH_POSIX)) { - printk("non-blocking socketpair I/O is unsupported with CONFIG_ARCH_POSIX\n"); - ztest_test_skip(); - } - res = socketpair(AF_UNIX, SOCK_STREAM, 0, sv); zassert_equal(res, 0, "socketpair() failed: %d", errno); From 341c01fcd010c305b25a7b8d18c7e0d4282ff82d Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Wed, 15 Mar 2023 12:18:41 +0100 Subject: [PATCH 0235/1906] scripts: runners: nrf_common: Fix QSPI erase switch The QSPI erase switch is not part of the "firmware" dict, but rather placed in the overall operation dict. Fixes #55625. Signed-off-by: Carles Cufi --- scripts/west_commands/runners/nrf_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/west_commands/runners/nrf_common.py b/scripts/west_commands/runners/nrf_common.py index a4862161a3ad..22f4bc368b87 100644 --- a/scripts/west_commands/runners/nrf_common.py +++ b/scripts/west_commands/runners/nrf_common.py @@ -342,7 +342,7 @@ def op_program(self, hex_file, erase, qspi_erase, defer=False, core=None): args = {'firmware': {'file': hex_file, 'format': 'NRFDL_FW_INTEL_HEX'}, 'chip_erase_mode': erase, 'verify': 'VERIFY_READ'} if qspi_erase: - args['firmware']['qspi_erase_mode'] = qspi_erase + args['qspi_erase_mode'] = qspi_erase self.exec_op('program', defer, core, **args) def exec_op(self, op, defer=False, core=None, **kwargs): From 11574c0a6b69075e473323a78fd6cac8f1f705e2 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Mon, 23 Jan 2023 10:21:18 +0100 Subject: [PATCH 0236/1906] drivers: spi: sam: Fix DMA build A MACRO argument naming mismatch causes a bug when trying to use DMA. Fix the MACRO argument and conditional DMA configuration. Signed-off-by: Pieter De Gendt --- drivers/spi/spi_sam.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi_sam.c b/drivers/spi/spi_sam.c index c3821cd61706..4e5bc7140dce 100644 --- a/drivers/spi/spi_sam.c +++ b/drivers/spi/spi_sam.c @@ -720,7 +720,11 @@ static const struct spi_driver_api spi_sam_driver_api = { .dma_rx_channel = DT_INST_DMAS_CELL_BY_NAME(n, rx, channel), \ .dma_rx_perid = DT_INST_DMAS_CELL_BY_NAME(n, rx, perid), -#define SPI_SAM_USE_DMA(inst) DT_INST_DMAS_HAS_NAME(n, tx) && IS_ENABLED(CONFIG_SPI_SAM_DMA) +#ifdef CONFIG_SPI_SAM_DMA +#define SPI_SAM_USE_DMA(n) DT_INST_DMAS_HAS_NAME(n, tx) +#else +#define SPI_SAM_USE_DMA(n) 0 +#endif #define SPI_SAM_DEFINE_CONFIG(n) \ static const struct spi_sam_config spi_sam_config_##n = { \ From c22f40a3585582ad23533d10c658747cb6eef57d Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 2 Mar 2023 16:19:44 +0530 Subject: [PATCH 0237/1906] Bluetooth: Controller: Fix max PDU len radio config for BIS Ctrl PDUs Fix missing radio configuration that limits the maximum PDU len on reception to consider that Control PDU can be larger than the max PDU size in the BIS parameters. Use dedicated PDU buffer for transmission and reception of BIG Control PDUs so that it is independent of maximum ISO PDU length which can be less than BIG Control PDU length. Signed-off-by: Vinayak Kariappa Chettimada --- .../ll_sw/nordic/hal/nrf5/radio/radio.c | 12 +++ .../ll_sw/nordic/hal/nrf5/radio/radio.h | 1 + .../controller/ll_sw/nordic/lll/lll_adv_iso.c | 19 ++++- .../ll_sw/nordic/lll/lll_sync_iso.c | 75 +++++++++++++------ 4 files changed, 82 insertions(+), 25 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index 3b6a64936c6f..1af23246bd64 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -667,6 +667,18 @@ void *radio_pkt_decrypt_get(void) #error "Undefined HAL_RADIO_PDU_LEN_MAX." #endif +#if defined(CONFIG_BT_CTLR_ADV_ISO) || defined(CONFIG_BT_CTLR_SYNC_ISO) +/* Dedicated Rx PDU Buffer for Control PDU independent of node_rx with BIS Data + * PDU buffer + */ +static uint8_t pkt_big_ctrl[sizeof(struct pdu_big_ctrl)]; + +void *radio_pkt_big_ctrl_get(void) +{ + return pkt_big_ctrl; +} +#endif /* CONFIG_BT_CTLR_ADV_ISO || CONFIG_BT_CTLR_SYNC_ISO */ + #if !defined(CONFIG_BT_CTLR_TIFS_HW) static uint8_t sw_tifs_toggle; /** diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h index a5f41d90cf92..93ad9272d1ab 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.h @@ -94,6 +94,7 @@ uint32_t radio_crc_is_valid(void); void *radio_pkt_empty_get(void); void *radio_pkt_scratch_get(void); void *radio_pkt_decrypt_get(void); +void *radio_pkt_big_ctrl_get(void); void radio_switch_complete_and_rx(uint8_t phy_rx); void radio_switch_complete_and_tx(uint8_t phy_rx, uint8_t flags_rx, uint8_t phy_tx, diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c index 679fbfbd20e4..545cbfd2a89b 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c @@ -505,7 +505,7 @@ static void isr_tx_common(void *param, */ struct pdu_big_ctrl_term_ind *term; - pdu = radio_pkt_scratch_get(); + pdu = radio_pkt_big_ctrl_get(); pdu->ll_id = PDU_BIS_LLID_CTRL; pdu->cssn = lll->cssn; pdu->cstf = 0U; @@ -529,7 +529,7 @@ static void isr_tx_common(void *param, */ struct pdu_big_ctrl_chan_map_ind *chm; - pdu = radio_pkt_scratch_get(); + pdu = radio_pkt_big_ctrl_get(); pdu->ll_id = PDU_BIS_LLID_CTRL; pdu->cssn = lll->cssn; pdu->cstf = 0U; @@ -696,6 +696,21 @@ static void isr_tx_common(void *param, /* Control subevent, then complete subevent and close radio use */ if (!bis) { + uint8_t pkt_flags; + + pkt_flags = RADIO_PKT_CONF_FLAGS(RADIO_PKT_CONF_PDU_TYPE_BIS, + lll->phy, + RADIO_PKT_CONF_CTE_DISABLED); + if (lll->enc) { + radio_pkt_configure(RADIO_PKT_CONF_LENGTH_8BIT, + (sizeof(struct pdu_big_ctrl) + PDU_MIC_SIZE), + pkt_flags); + } else { + radio_pkt_configure(RADIO_PKT_CONF_LENGTH_8BIT, + sizeof(struct pdu_big_ctrl), + pkt_flags); + } + radio_switch_complete_and_disable(); radio_isr_set(isr_done_term, lll); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c index 38709fff3c89..48eed1ee209b 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c @@ -563,22 +563,12 @@ static void isr_rx(void *param) lll->ctrl) { lll->cssn_curr = lll->cssn_next; - /* By design, there shall alway be one free node rx - * available for setting up radio for new PDU reception. - * Control procedure handling does not consume any - * node rx, hence checking for one free node rx is - * sufficient. - */ - node_rx = ull_iso_pdu_rx_alloc_peek(1U); - LL_ASSERT(node_rx); - - pdu = (void *)node_rx->pdu; - if (pdu->ll_id != PDU_BIS_LLID_CTRL) { - goto isr_rx_done; + /* Check the dedicated Control PDU buffer */ + pdu = radio_pkt_big_ctrl_get(); + if (pdu->ll_id == PDU_BIS_LLID_CTRL) { + isr_rx_ctrl_recv(lll, pdu); } - isr_rx_ctrl_recv(lll, pdu); - goto isr_rx_done; } else { /* Check if there are 2 free rx buffers, one will be @@ -794,6 +784,8 @@ static void isr_rx(void *param) /* Control subevent */ if (!lll->ctrl && (lll->cssn_next != lll->cssn_curr)) { + uint8_t pkt_flags; + /* Receive the control PDU and close the BIG event * there after. */ @@ -802,6 +794,22 @@ static void isr_rx(void *param) /* control subevent to use bis = 0 and se_n = 1 */ bis = 0U; + /* Configure Radio to receive Control PDU that can have greater + * PDU length than max_pdu length. + */ + pkt_flags = RADIO_PKT_CONF_FLAGS(RADIO_PKT_CONF_PDU_TYPE_BIS, + lll->phy, + RADIO_PKT_CONF_CTE_DISABLED); + if (lll->enc) { + radio_pkt_configure(RADIO_PKT_CONF_LENGTH_8BIT, + (sizeof(struct pdu_big_ctrl) + PDU_MIC_SIZE), + pkt_flags); + } else { + radio_pkt_configure(RADIO_PKT_CONF_LENGTH_8BIT, + sizeof(struct pdu_big_ctrl), + pkt_flags); + } + goto isr_rx_next_subevent; } @@ -997,20 +1005,26 @@ static void isr_rx(void *param) lll_chan_set(data_chan_use); - /* By design, there shall alway be one free node rx available for - * setting up radio for new PDU reception. - */ - node_rx = ull_iso_pdu_rx_alloc_peek(1U); - LL_ASSERT(node_rx); - /* Encryption */ if (lll->enc) { uint64_t payload_count; + struct pdu_bis *pdu; payload_count = lll->payload_count - lll->bn; if (bis) { payload_count += (lll->bn_curr - 1U) + (lll->ptc_curr * lll->pto); + + /* By design, there shall alway be one free node rx + * available for setting up radio for new PDU reception. + */ + node_rx = ull_iso_pdu_rx_alloc_peek(1U); + LL_ASSERT(node_rx); + + pdu = (void *)node_rx->pdu; + } else { + /* Use the dedicated Control PDU buffer */ + pdu = radio_pkt_big_ctrl_get(); } lll->ccm_rx.counter = payload_count; @@ -1018,10 +1032,25 @@ static void isr_rx(void *param) (void)memcpy(lll->ccm_rx.iv, lll->giv, 4U); mem_xor_32(lll->ccm_rx.iv, lll->ccm_rx.iv, access_addr); - radio_pkt_rx_set(radio_ccm_rx_pkt_set(&lll->ccm_rx, lll->phy, - node_rx->pdu)); + radio_pkt_rx_set(radio_ccm_rx_pkt_set(&lll->ccm_rx, lll->phy, pdu)); + } else { - radio_pkt_rx_set(node_rx->pdu); + struct pdu_bis *pdu; + + if (bis) { + /* By design, there shall alway be one free node rx + * available for setting up radio for new PDU reception. + */ + node_rx = ull_iso_pdu_rx_alloc_peek(1U); + LL_ASSERT(node_rx); + + pdu = (void *)node_rx->pdu; + } else { + /* Use the dedicated Control PDU buffer */ + pdu = radio_pkt_big_ctrl_get(); + } + + radio_pkt_rx_set(pdu); } radio_switch_complete_and_disable(); From 11ad5bf92c25991feae1b3b58fb922d9eadedf61 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 10 Mar 2023 17:23:34 +0530 Subject: [PATCH 0238/1906] Bluetooth: Controller: Inherit BT_ISO_TX_BUF_COUNT value Inherit BT_ISO_TX_BUF_COUNT value when BT_ISO is enabled to set BT_CTLR_ISO_TX_BUFFERS count. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 7b197bd9a458..63c7b83bc3f8 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -221,6 +221,7 @@ config BT_CTLR_ISO_TX_BUFFERS int "Number of Isochronous Tx buffers" depends on BT_CTLR_ADV_ISO || BT_CTLR_CONN_ISO range 1 19 + default BT_ISO_TX_BUF_COUNT if BT_ISO default 3 help Set the number of Isochronous Tx PDUs to be queued for transmission From 2abc58b886eaa729887231e5b6c4fb92d674ab01 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 2 Mar 2023 16:27:56 +0530 Subject: [PATCH 0239/1906] samples: Bluetooth: Remove duplicate board conf for iso_broadcast Remove duplicated board specific conf file for iso_broadcast and iso_receive samples. Instead, have an overlay conf file. Signed-off-by: Vinayak Kariappa Chettimada --- samples/bluetooth/iso_broadcast/README.rst | 3 ++- .../iso_broadcast/boards/nrf21540dk_nrf52840.conf | 4 ---- .../iso_broadcast/boards/nrf52840dk_nrf52840.conf | 4 ---- .../bluetooth/iso_broadcast/boards/nrf52_bsim.conf | 4 ---- .../iso_broadcast/boards/nrf52dk_nrf52832.conf | 4 ---- .../iso_broadcast/overlay-bt_ll_sw_split.conf | 13 +++++++++++++ samples/bluetooth/iso_broadcast/prj.conf | 6 ++---- samples/bluetooth/iso_broadcast/sample.yaml | 7 +++++++ samples/bluetooth/iso_receive/README.rst | 3 ++- .../iso_receive/boards/nrf52840dk_nrf52840.conf | 4 ---- .../bluetooth/iso_receive/boards/nrf52_bsim.conf | 4 ---- .../iso_receive/boards/nrf52dk_nrf52832.conf | 4 ---- ...dk_nrf52840.conf => overlay-bt_ll_sw_split.conf} | 0 samples/bluetooth/iso_receive/sample.yaml | 7 +++++++ 14 files changed, 33 insertions(+), 34 deletions(-) delete mode 100644 samples/bluetooth/iso_broadcast/boards/nrf21540dk_nrf52840.conf delete mode 100644 samples/bluetooth/iso_broadcast/boards/nrf52840dk_nrf52840.conf delete mode 100644 samples/bluetooth/iso_broadcast/boards/nrf52_bsim.conf delete mode 100644 samples/bluetooth/iso_broadcast/boards/nrf52dk_nrf52832.conf create mode 100644 samples/bluetooth/iso_broadcast/overlay-bt_ll_sw_split.conf delete mode 100644 samples/bluetooth/iso_receive/boards/nrf52840dk_nrf52840.conf delete mode 100644 samples/bluetooth/iso_receive/boards/nrf52_bsim.conf delete mode 100644 samples/bluetooth/iso_receive/boards/nrf52dk_nrf52832.conf rename samples/bluetooth/iso_receive/{boards/nrf21540dk_nrf52840.conf => overlay-bt_ll_sw_split.conf} (100%) diff --git a/samples/bluetooth/iso_broadcast/README.rst b/samples/bluetooth/iso_broadcast/README.rst index 6be75c93c02a..0caec4201579 100644 --- a/samples/bluetooth/iso_broadcast/README.rst +++ b/samples/bluetooth/iso_broadcast/README.rst @@ -21,7 +21,8 @@ Building and Running ******************** This sample can be found under :zephyr_file:`samples/bluetooth/iso_broadcast` in -the Zephyr tree. +the Zephyr tree. Use `-DOVERLAY_CONFIG=overlay-bt_ll_sw_split.conf` to enable +required ISO feature support in Zephyr Bluetooth Controller on supported boards. Use the sample found under :zephyr_file:`samples/bluetooth/iso_receive` in the Zephyr tree that will scan, establish a periodic advertising synchronization, diff --git a/samples/bluetooth/iso_broadcast/boards/nrf21540dk_nrf52840.conf b/samples/bluetooth/iso_broadcast/boards/nrf21540dk_nrf52840.conf deleted file mode 100644 index 19a1f2c75e92..000000000000 --- a/samples/bluetooth/iso_broadcast/boards/nrf21540dk_nrf52840.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_BT_CTLR_ADV_ISO=y -CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX=251 -CONFIG_BT_CTLR_ADV_ISO_STREAM_MAX=2 -CONFIG_BT_CTLR_ISOAL_SOURCES=2 diff --git a/samples/bluetooth/iso_broadcast/boards/nrf52840dk_nrf52840.conf b/samples/bluetooth/iso_broadcast/boards/nrf52840dk_nrf52840.conf deleted file mode 100644 index 19a1f2c75e92..000000000000 --- a/samples/bluetooth/iso_broadcast/boards/nrf52840dk_nrf52840.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_BT_CTLR_ADV_ISO=y -CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX=251 -CONFIG_BT_CTLR_ADV_ISO_STREAM_MAX=2 -CONFIG_BT_CTLR_ISOAL_SOURCES=2 diff --git a/samples/bluetooth/iso_broadcast/boards/nrf52_bsim.conf b/samples/bluetooth/iso_broadcast/boards/nrf52_bsim.conf deleted file mode 100644 index 19a1f2c75e92..000000000000 --- a/samples/bluetooth/iso_broadcast/boards/nrf52_bsim.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_BT_CTLR_ADV_ISO=y -CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX=251 -CONFIG_BT_CTLR_ADV_ISO_STREAM_MAX=2 -CONFIG_BT_CTLR_ISOAL_SOURCES=2 diff --git a/samples/bluetooth/iso_broadcast/boards/nrf52dk_nrf52832.conf b/samples/bluetooth/iso_broadcast/boards/nrf52dk_nrf52832.conf deleted file mode 100644 index 19a1f2c75e92..000000000000 --- a/samples/bluetooth/iso_broadcast/boards/nrf52dk_nrf52832.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_BT_CTLR_ADV_ISO=y -CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX=251 -CONFIG_BT_CTLR_ADV_ISO_STREAM_MAX=2 -CONFIG_BT_CTLR_ISOAL_SOURCES=2 diff --git a/samples/bluetooth/iso_broadcast/overlay-bt_ll_sw_split.conf b/samples/bluetooth/iso_broadcast/overlay-bt_ll_sw_split.conf new file mode 100644 index 000000000000..a5f8b3cc1c5b --- /dev/null +++ b/samples/bluetooth/iso_broadcast/overlay-bt_ll_sw_split.conf @@ -0,0 +1,13 @@ +CONFIG_BT_CTLR_ADV_ISO=y +CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX=4 +CONFIG_BT_CTLR_ADV_ISO_STREAM_MAX=2 + +CONFIG_BT_CTLR_ISOAL_SOURCES=2 + +# FIXME: Host needs CONFIG_BT_ISO_TX_MTU + 4 bytes for sequence number, and +# optionally additional + 4 bytes for timestamp when not using +# BT_ISO_TIMESTAMP_NONE in bt_iso_chan_send(), otherwise Host tries to fragment +# ISO data. +# When Host is fixed, CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE can inherit the +# CONFIG_BT_ISO_TX_MTU value. +CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE=12 diff --git a/samples/bluetooth/iso_broadcast/prj.conf b/samples/bluetooth/iso_broadcast/prj.conf index 253bb72c0470..8b403e885204 100644 --- a/samples/bluetooth/iso_broadcast/prj.conf +++ b/samples/bluetooth/iso_broadcast/prj.conf @@ -4,9 +4,7 @@ CONFIG_BT_DEBUG_LOG=y CONFIG_BT_DEVICE_NAME="Test ISO Broadcaster" CONFIG_BT_ISO_MAX_CHAN=2 -CONFIG_BT_ISO_TX_BUF_COUNT=2 +CONFIG_BT_ISO_TX_BUF_COUNT=4 # Just needs to send a uint32_t value -CONFIG_BT_ISO_TX_MTU=23 - -CONFIG_BT_CTLR_ISO_TX_BUFFERS=2 +CONFIG_BT_ISO_TX_MTU=4 diff --git a/samples/bluetooth/iso_broadcast/sample.yaml b/samples/bluetooth/iso_broadcast/sample.yaml index 7c5d552e4246..fdd0b344363f 100644 --- a/samples/bluetooth/iso_broadcast/sample.yaml +++ b/samples/bluetooth/iso_broadcast/sample.yaml @@ -7,3 +7,10 @@ tests: integration_platforms: - qemu_cortex_m3 tags: bluetooth + sample.bluetooth.iso_broadcast.bt_ll_sw_split: + harness: bluetooth + platform_allow: qemu_cortex_m3 qemu_x86 nrf52_bsim nrf52dk_nrf52832 + integration_platforms: + - nrf52dk_nrf52832 + extra_args: OVERLAY_CONFIG=overlay-bt_ll_sw_split.conf + tags: bluetooth diff --git a/samples/bluetooth/iso_receive/README.rst b/samples/bluetooth/iso_receive/README.rst index d57b7282480c..6e5d871bb618 100644 --- a/samples/bluetooth/iso_receive/README.rst +++ b/samples/bluetooth/iso_receive/README.rst @@ -21,7 +21,8 @@ Building and Running ******************** This sample can be found under :zephyr_file:`samples/bluetooth/iso_receive` in -the Zephyr tree. +the Zephyr tree. Use `-DOVERLAY_CONFIG=overlay-bt_ll_sw_split.conf` to enable +required ISO feature support in Zephyr Bluetooth Controller on supported boards. Use the sample found under :zephyr_file:`samples/bluetooth/iso_broadcast` on another board that will start periodic advertising, create BIG to which this diff --git a/samples/bluetooth/iso_receive/boards/nrf52840dk_nrf52840.conf b/samples/bluetooth/iso_receive/boards/nrf52840dk_nrf52840.conf deleted file mode 100644 index c976fa83c812..000000000000 --- a/samples/bluetooth/iso_receive/boards/nrf52840dk_nrf52840.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_BT_CTLR_SYNC_ISO=y -CONFIG_BT_CTLR_SYNC_ISO_PDU_LEN_MAX=251 -CONFIG_BT_CTLR_SYNC_ISO_STREAM_MAX=2 -CONFIG_BT_CTLR_ISOAL_SINKS=2 diff --git a/samples/bluetooth/iso_receive/boards/nrf52_bsim.conf b/samples/bluetooth/iso_receive/boards/nrf52_bsim.conf deleted file mode 100644 index c976fa83c812..000000000000 --- a/samples/bluetooth/iso_receive/boards/nrf52_bsim.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_BT_CTLR_SYNC_ISO=y -CONFIG_BT_CTLR_SYNC_ISO_PDU_LEN_MAX=251 -CONFIG_BT_CTLR_SYNC_ISO_STREAM_MAX=2 -CONFIG_BT_CTLR_ISOAL_SINKS=2 diff --git a/samples/bluetooth/iso_receive/boards/nrf52dk_nrf52832.conf b/samples/bluetooth/iso_receive/boards/nrf52dk_nrf52832.conf deleted file mode 100644 index c976fa83c812..000000000000 --- a/samples/bluetooth/iso_receive/boards/nrf52dk_nrf52832.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_BT_CTLR_SYNC_ISO=y -CONFIG_BT_CTLR_SYNC_ISO_PDU_LEN_MAX=251 -CONFIG_BT_CTLR_SYNC_ISO_STREAM_MAX=2 -CONFIG_BT_CTLR_ISOAL_SINKS=2 diff --git a/samples/bluetooth/iso_receive/boards/nrf21540dk_nrf52840.conf b/samples/bluetooth/iso_receive/overlay-bt_ll_sw_split.conf similarity index 100% rename from samples/bluetooth/iso_receive/boards/nrf21540dk_nrf52840.conf rename to samples/bluetooth/iso_receive/overlay-bt_ll_sw_split.conf diff --git a/samples/bluetooth/iso_receive/sample.yaml b/samples/bluetooth/iso_receive/sample.yaml index 3536a15f3901..33684885599f 100644 --- a/samples/bluetooth/iso_receive/sample.yaml +++ b/samples/bluetooth/iso_receive/sample.yaml @@ -7,3 +7,10 @@ tests: integration_platforms: - qemu_cortex_m3 tags: bluetooth + sample.bluetooth.iso_receive.bt_ll_sw_split: + harness: bluetooth + platform_allow: qemu_cortex_m3 qemu_x86 nrf52_bsim nrf52dk_nrf52832 + integration_platforms: + - nrf52dk_nrf52832 + extra_args: OVERLAY_CONFIG=overlay-bt_ll_sw_split.conf + tags: bluetooth From 3a36b0736d613d5e2e872099bfa01aee38ab4f5d Mon Sep 17 00:00:00 2001 From: Jiafei Pan Date: Wed, 15 Mar 2023 17:39:52 +0800 Subject: [PATCH 0240/1906] board: arm64: mimx8mp/n/m: fix cpu command in document Fixed the wrong cpu command. Signed-off-by: Jiafei Pan --- boards/arm64/mimx8mm_evk/doc/index.rst | 2 +- boards/arm64/mimx8mn_evk/doc/index.rst | 2 +- boards/arm64/mimx8mp_evk/doc/index.rst | 2 +- boards/arm64/mimx93_evk/doc/index.rst | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/boards/arm64/mimx8mm_evk/doc/index.rst b/boards/arm64/mimx8mm_evk/doc/index.rst index be9095c1180a..aa82dbdda83e 100644 --- a/boards/arm64/mimx8mm_evk/doc/index.rst +++ b/boards/arm64/mimx8mm_evk/doc/index.rst @@ -88,7 +88,7 @@ Or kick SMP zephyr.bin: .. code-block:: console - mw 303d0518 f 1; fatload mmc 1:1 0x93c00000 zephyr.bin; dcache flush; icache flush; dcache off; icache off; cpu release 2 0x93c00000 + mw 303d0518 f 1; fatload mmc 1:1 0x93c00000 zephyr.bin; dcache flush; icache flush; dcache off; icache off; cpu 2 release 0x93c00000 Use this configuration to run basic Zephyr applications and kernel tests, diff --git a/boards/arm64/mimx8mn_evk/doc/index.rst b/boards/arm64/mimx8mn_evk/doc/index.rst index e96aa6216977..4e7497b672e7 100644 --- a/boards/arm64/mimx8mn_evk/doc/index.rst +++ b/boards/arm64/mimx8mn_evk/doc/index.rst @@ -88,7 +88,7 @@ Or kick SMP zephyr.bin: .. code-block:: console - mw 303d0518 f 1; fatload mmc 1:1 0x93c00000 zephyr.bin; dcache flush; icache flush; dcache off; icache off; cpu release 2 0x93c00000 + mw 303d0518 f 1; fatload mmc 1:1 0x93c00000 zephyr.bin; dcache flush; icache flush; dcache off; icache off; cpu 2 release 0x93c00000 Use this configuration to run basic Zephyr applications and kernel tests, diff --git a/boards/arm64/mimx8mp_evk/doc/index.rst b/boards/arm64/mimx8mp_evk/doc/index.rst index 3d8a1a775e02..ab63461f2e88 100644 --- a/boards/arm64/mimx8mp_evk/doc/index.rst +++ b/boards/arm64/mimx8mp_evk/doc/index.rst @@ -88,7 +88,7 @@ Or kick SMP zephyr.bin: .. code-block:: console - mw 303d0518 f 1; fatload mmc 1:1 0xc0000000 zephyr.bin; dcache flush; icache flush; dcache off; icache off; cpu release 2 0xc0000000 + mw 303d0518 f 1; fatload mmc 1:1 0xc0000000 zephyr.bin; dcache flush; icache flush; dcache off; icache off; cpu 2 release 0xc0000000 Use this configuration to run basic Zephyr applications and kernel tests, for example, with the :ref:`synchronization_sample`: diff --git a/boards/arm64/mimx93_evk/doc/index.rst b/boards/arm64/mimx93_evk/doc/index.rst index fafc45a8b107..1e3bb0180c97 100644 --- a/boards/arm64/mimx93_evk/doc/index.rst +++ b/boards/arm64/mimx93_evk/doc/index.rst @@ -86,7 +86,7 @@ Use U-Boot to load and kick zephyr.bin to Cortex-A55 Core1: .. code-block:: console - fatload mmc 1:1 0xc0000000 zephyr.bin; dcache flush; icache flush; dcache off; icache off; cpu release 1 0xc0000000 + fatload mmc 1:1 0xc0000000 zephyr.bin; dcache flush; icache flush; dcache off; icache off; cpu 1 release 0xc0000000 Or use the following command to kick zephyr.bin to Cortex-A55 Core0: From 34dad88d455b882e2e7e0478bfc45b8f69548291 Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Wed, 15 Mar 2023 12:37:10 +0100 Subject: [PATCH 0241/1906] west.yml: Update hal_renesas revision Adds new HAL to be used by existing and upcoming drivers. Signed-off-by: Andrzej Kaczmarek --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 04fac496bdab..190b368a4f2f 100644 --- a/west.yml +++ b/west.yml @@ -110,7 +110,7 @@ manifest: - hal - name: hal_renesas path: modules/hal/renesas - revision: 468d3f2146d18c7f86a4640fc641cc1d20a4a100 + revision: f2d791d28cd8fdbc5861652b863822632c91f690 groups: - hal - name: hal_rpi_pico From c37272b32114157fa78f23785376782e4e94fc23 Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Mon, 20 Feb 2023 16:30:22 +0100 Subject: [PATCH 0242/1906] drivers: dma: stm32 disabling stream waits for disable Add the loop to wait until the stream is really disable after disabling and also cleared the TCIF flag. This is a specifity of the dma of type V1. Signed-off-by: Francois Ramu --- drivers/dma/dma_stm32_v1.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/dma/dma_stm32_v1.c b/drivers/dma/dma_stm32_v1.c index 1ebc4f0a06cf..c22b171d9c5a 100644 --- a/drivers/dma/dma_stm32_v1.c +++ b/drivers/dma/dma_stm32_v1.c @@ -332,11 +332,12 @@ int stm32_dma_disable_stream(DMA_TypeDef *dma, uint32_t id) { LL_DMA_DisableStream(dma, dma_stm32_id_to_stream(id)); - if (!LL_DMA_IsEnabledStream(dma, dma_stm32_id_to_stream(id))) { - return 0; + while (stm32_dma_is_enabled_stream(dma, id)) { } - return -EAGAIN; + dma_stm32_clear_tc(dma, id); + + return 0; } void stm32_dma_disable_fifo_irq(DMA_TypeDef *dma, uint32_t id) From 40b4cccf83fee088e64c4f9b4ddb7b3a87c402b7 Mon Sep 17 00:00:00 2001 From: Magdalena Kasenberg Date: Thu, 9 Mar 2023 15:40:56 +0100 Subject: [PATCH 0243/1906] bluetooth: tester: Add nrf5340_hci_rpmsg.conf file To apply when the hci_rpmsg controller with overlay nrf5340_cpunet_iso-bt_ll_sw_split.conf is used on the netcore. Signed-off-by: Magdalena Kasenberg --- tests/bluetooth/tester/nrf5340_hci_rpmsg.conf | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/bluetooth/tester/nrf5340_hci_rpmsg.conf diff --git a/tests/bluetooth/tester/nrf5340_hci_rpmsg.conf b/tests/bluetooth/tester/nrf5340_hci_rpmsg.conf new file mode 100644 index 000000000000..16d6d2ab402c --- /dev/null +++ b/tests/bluetooth/tester/nrf5340_hci_rpmsg.conf @@ -0,0 +1,13 @@ +# Those have to be the same as in the controller (hci_rpmsg) +CONFIG_BT_MAX_CONN=2 +CONFIG_BT_BUF_EVT_RX_COUNT=16 +CONFIG_BT_BUF_EVT_RX_SIZE=255 +CONFIG_BT_BUF_CMD_TX_SIZE=255 +CONFIG_BT_BUF_ACL_TX_SIZE=251 + +# L2CAP SDU/PDU TX MTU +CONFIG_BT_L2CAP_TX_MTU=247 + +# The minimum value for this is +# L2AP MPS + L2CAP header (4) +CONFIG_BT_BUF_ACL_RX_SIZE=255 From 26cf0b68506b441ccc29b2b4eb579606ecbe7e65 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 10 Mar 2023 12:25:02 +0100 Subject: [PATCH 0244/1906] bluetooth: tester: Add support for missing BTP L2CAP listen param BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_ENCRYPTION is used to indicate encryption is required (but not authentication). Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp/btp_l2cap.h | 1 + tests/bluetooth/tester/src/btp_l2cap.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_l2cap.h b/tests/bluetooth/tester/src/btp/btp_l2cap.h index 269c4ee826a4..d08a89fba850 100644 --- a/tests/bluetooth/tester/src/btp/btp_l2cap.h +++ b/tests/bluetooth/tester/src/btp/btp_l2cap.h @@ -52,6 +52,7 @@ struct btp_l2cap_send_data_cmd { #define BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHEN 0x01 #define BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHOR 0x02 #define BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_ENC_KEY 0x03 +#define BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_ENCRYPTION 0x04 #define BTP_L2CAP_LISTEN 0x05 struct btp_l2cap_listen_cmd { diff --git a/tests/bluetooth/tester/src/btp_l2cap.c b/tests/bluetooth/tester/src/btp_l2cap.c index f57e006b27c5..e9ee8728c03a 100644 --- a/tests/bluetooth/tester/src/btp_l2cap.c +++ b/tests/bluetooth/tester/src/btp_l2cap.c @@ -471,13 +471,22 @@ static uint8_t listen(const void *cmd, uint16_t cmd_len, server->accept = accept; server->psm = psm; - if (cp->response == BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_ENC_KEY) { + switch (cp->response) { + case BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_ENC_KEY: /* TSPX_psm_encryption_key_size_required */ req_keysize = 16; - } else if (cp->response == BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHOR) { + break; + case BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHOR: authorize_flag = true; - } else if (cp->response == BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHEN) { + break; + case BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_AUTHEN: server->sec_level = BT_SECURITY_L3; + break; + case BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_ENCRYPTION: + server->sec_level = BT_SECURITY_L2; + break; + default: + return BTP_STATUS_FAILED; } if (bt_l2cap_server_register(server) < 0) { From b07f474d71400253b12b8b5173a38e9e6dda2789 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Mon, 13 Mar 2023 17:02:23 +0100 Subject: [PATCH 0245/1906] bluetooth: tester: Fix copy paste issue in config_mod_sub_ovw stuct btp_mesh_cfg_model_sub_add_cmd was used instead of struct btp_mesh_cfg_model_sub_ovw_cmd for parsing command. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp_mesh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index d4cd1dbe18cb..5571cfd21566 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1379,7 +1379,7 @@ static uint8_t config_mod_sub_add(const void *cmd, uint16_t cmd_len, static uint8_t config_mod_sub_ovw(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { - const struct btp_mesh_cfg_model_sub_add_cmd *cp = cmd; + const struct btp_mesh_cfg_model_sub_ovw_cmd *cp = cmd; struct btp_mesh_cfg_model_sub_add_rp *rp = rsp; uint8_t status; int err; From d7ca01537f6dce2729111001b1b111b42fe23077 Mon Sep 17 00:00:00 2001 From: Jonathan Rico Date: Thu, 9 Mar 2023 13:34:58 +0100 Subject: [PATCH 0246/1906] samples: Bluetooth: add more documentation for hci_uart Try to explain how to use the hci_uart sample with another board running the zephyr host. Signed-off-by: Jonathan Rico --- samples/bluetooth/hci_uart/README.rst | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/samples/bluetooth/hci_uart/README.rst b/samples/bluetooth/hci_uart/README.rst index 335a812c56a1..1bd915de2117 100644 --- a/samples/bluetooth/hci_uart/README.rst +++ b/samples/bluetooth/hci_uart/README.rst @@ -148,3 +148,45 @@ Using a USB CDC ACM UART ======================== The sample can be configured to use a USB UART instead. See :zephyr_file:`samples/bluetooth/hci_uart/nrf52840dongle_nrf52840.conf` and :zephyr_file:`samples/bluetooth/hci_uart/nrf52840dongle_nrf52840.overlay`. + +Using the controller with the Zephyr host +========================================= + +This describes how to hook up a board running this sample to a board running +an application that uses the Zephyr host. + +On the controller side, the `zephyr,bt-c2h-uart` DTS property (in the `chosen` +block) is used to select which uart device to use. For example if we want to +keep the console logs, we can keep console on uart0 and the HCI on uart1 like +so: + +.. code-block:: dts + + / { + chosen { + zephyr,console = &uart0; + zephyr,shell-uart = &uart0; + zephyr,bt-c2h-uart = &uart1; + }; + }; + +On the host application, some config options need to be used to select the H4 +driver instead of the built-in controller: + +.. code-block:: kconfig + + CONFIG_BT_HCI=y + CONFIG_BT_CTLR=n + CONFIG_BT_H4=y + +Similarly, the `zephyr,bt-uart` DTS property selects which uart to use: + +.. code-block:: dts + + / { + chosen { + zephyr,console = &uart0; + zephyr,shell-uart = &uart0; + zephyr,bt-uart = &uart1; + }; + }; From aae379f245ed0a722970f1381d9eff7854f0992c Mon Sep 17 00:00:00 2001 From: Jun Qing Zou Date: Wed, 15 Mar 2023 17:44:13 +0900 Subject: [PATCH 0247/1906] net: mqtt: Debug logging of pointers Cast pointer to `void *` for `%p` parameter. Otherwise lots of warnings in the log like below: ` cbprintf_package: (unsigned) char * used for %p argument. It's recommended to cast it to void * because it may cause misbehavior in certain configurations. String:"%s: (%p): >> length:0x%08x cur:%p, end:%p" argument:3` Signed-off-by: Jun Qing Zou --- subsys/net/lib/mqtt/mqtt_decoder.c | 8 ++++---- subsys/net/lib/mqtt/mqtt_encoder.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/subsys/net/lib/mqtt/mqtt_decoder.c b/subsys/net/lib/mqtt/mqtt_decoder.c index 9fdbfae76274..ee86d44e1849 100644 --- a/subsys/net/lib/mqtt/mqtt_decoder.c +++ b/subsys/net/lib/mqtt/mqtt_decoder.c @@ -29,7 +29,7 @@ LOG_MODULE_REGISTER(net_mqtt_dec, CONFIG_MQTT_LOG_LEVEL); */ static int unpack_uint8(struct buf_ctx *buf, uint8_t *val) { - NET_DBG(">> cur:%p, end:%p", buf->cur, buf->end); + NET_DBG(">> cur:%p, end:%p", (void *)buf->cur, (void *)buf->end); if ((buf->end - buf->cur) < sizeof(uint8_t)) { return -EINVAL; @@ -55,7 +55,7 @@ static int unpack_uint8(struct buf_ctx *buf, uint8_t *val) */ static int unpack_uint16(struct buf_ctx *buf, uint16_t *val) { - NET_DBG(">> cur:%p, end:%p", buf->cur, buf->end); + NET_DBG(">> cur:%p, end:%p", (void *)buf->cur, (void *)buf->end); if ((buf->end - buf->cur) < sizeof(uint16_t)) { return -EINVAL; @@ -85,7 +85,7 @@ static int unpack_utf8_str(struct buf_ctx *buf, struct mqtt_utf8 *str) uint16_t utf8_strlen; int err_code; - NET_DBG(">> cur:%p, end:%p", buf->cur, buf->end); + NET_DBG(">> cur:%p, end:%p", (void *)buf->cur, (void *)buf->end); err_code = unpack_uint16(buf, &utf8_strlen); if (err_code != 0) { @@ -126,7 +126,7 @@ static int unpack_utf8_str(struct buf_ctx *buf, struct mqtt_utf8 *str) static int unpack_data(uint32_t length, struct buf_ctx *buf, struct mqtt_binstr *str) { - NET_DBG(">> cur:%p, end:%p", buf->cur, buf->end); + NET_DBG(">> cur:%p, end:%p", (void *)buf->cur, (void *)buf->end); if ((buf->end - buf->cur) < length) { return -EINVAL; diff --git a/subsys/net/lib/mqtt/mqtt_encoder.c b/subsys/net/lib/mqtt/mqtt_encoder.c index b9c397d2448a..e2abc0ab9e5f 100644 --- a/subsys/net/lib/mqtt/mqtt_encoder.c +++ b/subsys/net/lib/mqtt/mqtt_encoder.c @@ -49,7 +49,7 @@ static int pack_uint8(uint8_t val, struct buf_ctx *buf) return -ENOMEM; } - NET_DBG(">> val:%02x cur:%p, end:%p", val, buf->cur, buf->end); + NET_DBG(">> val:%02x cur:%p, end:%p", val, (void *)buf->cur, (void *)buf->end); /* Pack value. */ *(buf->cur++) = val; @@ -73,7 +73,7 @@ static int pack_uint16(uint16_t val, struct buf_ctx *buf) return -ENOMEM; } - NET_DBG(">> val:%04x cur:%p, end:%p", val, buf->cur, buf->end); + NET_DBG(">> val:%04x cur:%p, end:%p", val, (void *)buf->cur, (void *)buf->end); /* Pack value. */ *(buf->cur++) = (val >> 8) & 0xFF; @@ -99,7 +99,7 @@ static int pack_utf8_str(const struct mqtt_utf8 *str, struct buf_ctx *buf) } NET_DBG(">> str_size:%08x cur:%p, end:%p", - (uint32_t)GET_UT8STR_BUFFER_SIZE(str), buf->cur, buf->end); + (uint32_t)GET_UT8STR_BUFFER_SIZE(str), (void *)buf->cur, (void *)buf->end); /* Pack length followed by string. */ (void)pack_uint16(str->size, buf); @@ -140,7 +140,7 @@ static uint8_t packet_length_encode(uint32_t length, struct buf_ctx *buf) uint8_t encoded_bytes = 0U; NET_DBG(">> length:0x%08x cur:%p, end:%p", length, - (buf == NULL) ? 0 : buf->cur, (buf == NULL) ? 0 : buf->end); + (buf == NULL) ? 0 : (void *)buf->cur, (buf == NULL) ? 0 : (void *)buf->end); do { encoded_bytes++; From b721f0b3a15b185f1fd7ce820935af240c94c229 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Wed, 15 Mar 2023 10:38:57 +0100 Subject: [PATCH 0248/1906] tests: bluetooth: fix testcase.yaml line indentations Fix the line indentations used in the Bluetooth testcase.yaml files. Signed-off-by: Henrik Brix Andersen --- .../host/crypto/bt_encrypt_be/testcase.yaml | 4 +-- .../host/crypto/bt_encrypt_le/testcase.yaml | 4 +-- .../host/crypto/bt_rand/testcase.yaml | 8 +++--- .../host/id/bt_br_oob_get_local/testcase.yaml | 4 +-- .../bluetooth/host/id/bt_id_add/testcase.yaml | 16 ++++++------ .../bt_id_adv_random_addr_check/testcase.yaml | 20 +++++++------- .../host/id/bt_id_create/testcase.yaml | 8 +++--- .../bluetooth/host/id/bt_id_del/testcase.yaml | 20 +++++++------- .../host/id/bt_id_delete/testcase.yaml | 16 ++++++------ .../bluetooth/host/id/bt_id_get/testcase.yaml | 4 +-- .../host/id/bt_id_init/testcase.yaml | 12 ++++----- .../host/id/bt_id_reset/testcase.yaml | 4 +-- .../testcase.yaml | 16 ++++++------ .../id/bt_id_set_adv_own_addr/testcase.yaml | 12 ++++----- .../bt_id_set_adv_private_addr/testcase.yaml | 12 ++++----- .../bt_id_set_adv_random_addr/testcase.yaml | 8 +++--- .../testcase.yaml | 8 +++--- .../id/bt_id_set_private_addr/testcase.yaml | 8 +++--- .../id/bt_id_set_scan_own_addr/testcase.yaml | 16 ++++++------ .../bt_le_ext_adv_oob_get_local/testcase.yaml | 8 +++--- .../host/id/bt_le_oob_get_local/testcase.yaml | 12 ++++----- .../id/bt_le_oob_get_sc_data/testcase.yaml | 6 ++--- .../id/bt_le_oob_set_legacy_tk/testcase.yaml | 6 ++--- .../id/bt_le_oob_set_sc_data/testcase.yaml | 6 ++--- .../host/id/bt_lookup_id_addr/testcase.yaml | 8 +++--- .../id/bt_setup_public_id_addr/testcase.yaml | 16 ++++++------ .../id/bt_setup_random_id_addr/testcase.yaml | 26 +++++++++---------- .../host/keys/bt_keys_store/testcase.yaml | 6 ++--- .../keys/bt_keys_update_usage/testcase.yaml | 10 +++---- 29 files changed, 152 insertions(+), 152 deletions(-) diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml b/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml index fe49e6034c94..6d78c36809f7 100644 --- a/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml +++ b/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_encrypt_be.default: - type: unit + type: unit diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml b/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml index e311b01269f0..e4df36c4c321 100644 --- a/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml +++ b/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_encrypt_le.default: - type: unit + type: unit diff --git a/tests/bluetooth/host/crypto/bt_rand/testcase.yaml b/tests/bluetooth/host/crypto/bt_rand/testcase.yaml index 47ece1ea71ef..3e504610e6e5 100644 --- a/tests/bluetooth/host/crypto/bt_rand/testcase.yaml +++ b/tests/bluetooth/host/crypto/bt_rand/testcase.yaml @@ -1,9 +1,9 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_rand.default: - type: unit + type: unit bluetooth.host.bt_rand.host_crypto_prng_disabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_HOST_CRYPTO_PRNG=n diff --git a/tests/bluetooth/host/id/bt_br_oob_get_local/testcase.yaml b/tests/bluetooth/host/id/bt_br_oob_get_local/testcase.yaml index 150db8f6e9ec..83a3e7a904af 100644 --- a/tests/bluetooth/host/id/bt_br_oob_get_local/testcase.yaml +++ b/tests/bluetooth/host/id/bt_br_oob_get_local/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_br_oob_get_local.default: - type: unit + type: unit diff --git a/tests/bluetooth/host/id/bt_id_add/testcase.yaml b/tests/bluetooth/host/id/bt_id_add/testcase.yaml index 3b9a245f15a4..416ef93c4d18 100644 --- a/tests/bluetooth/host/id/bt_id_add/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_add/testcase.yaml @@ -1,20 +1,20 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_add.default: - type: unit + type: unit bluetooth.host.bt_id_add.broadcaster_ext_adv_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_EXT_ADV=y - CONFIG_BT_BROADCASTER=y bluetooth.host.bt_id_add.broadcaster_no_ext_adv: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_BROADCASTER=y bluetooth.host.bt_id_add.observer_ext_adv: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_EXT_ADV=y - CONFIG_BT_OBSERVER=y - CONFIG_BT_BROADCASTER=y diff --git a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/testcase.yaml b/tests/bluetooth/host/id/bt_id_adv_random_addr_check/testcase.yaml index 4635566138c4..7eb9efa443cf 100644 --- a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_adv_random_addr_check/testcase.yaml @@ -1,27 +1,27 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_adv_random_addr_check.default: - type: unit + type: unit bluetooth.host.bt_id_adv_random_addr_check.observer_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_CENTRAL=y - CONFIG_BT_OBSERVER=y bluetooth.host.bt_id_adv_random_addr_check.observer_privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y - CONFIG_BT_CENTRAL=y - CONFIG_BT_OBSERVER=y bluetooth.host.bt_id_adv_random_addr_check.observer_scan_with_identity_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SCAN_WITH_IDENTITY=y - CONFIG_BT_CENTRAL=y - CONFIG_BT_OBSERVER=y bluetooth.host.bt_id_adv_random_addr_check.bt_ext_adv_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_EXT_ADV=y diff --git a/tests/bluetooth/host/id/bt_id_create/testcase.yaml b/tests/bluetooth/host/id/bt_id_create/testcase.yaml index 8170d496eabe..bf963cc2894b 100644 --- a/tests/bluetooth/host/id/bt_id_create/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_create/testcase.yaml @@ -1,10 +1,10 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_create.default: - type: unit + type: unit bluetooth.host.bt_id_create.bt_privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/host/id/bt_id_del/testcase.yaml b/tests/bluetooth/host/id/bt_id_del/testcase.yaml index 128d613d1b3b..ddb6dd67a570 100644 --- a/tests/bluetooth/host/id/bt_id_del/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_del/testcase.yaml @@ -1,26 +1,26 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_del.default: - type: unit + type: unit bluetooth.host.bt_id_del.broadcaster_ext_adv_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_EXT_ADV=y - CONFIG_BT_BROADCASTER=y bluetooth.host.bt_id_del.broadcaster_no_ext_adv: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_BROADCASTER=y bluetooth.host.bt_id_del.broadcaster_no_ext_adv_privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_CENTRAL=y - CONFIG_BT_PRIVACY=y - CONFIG_BT_BROADCASTER=y bluetooth.host.bt_id_del.observer_ext_adv: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_EXT_ADV=y - CONFIG_BT_OBSERVER=y - CONFIG_BT_BROADCASTER=y diff --git a/tests/bluetooth/host/id/bt_id_delete/testcase.yaml b/tests/bluetooth/host/id/bt_id_delete/testcase.yaml index b4ba4abbfe00..07525d5b95fa 100644 --- a/tests/bluetooth/host/id/bt_id_delete/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_delete/testcase.yaml @@ -1,21 +1,21 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_delete.default: - type: unit + type: unit bluetooth.host.bt_id_delete.default_bt_settings_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_SETTINGS=y - CONFIG_BT_SETTINGS=y bluetooth.host.bt_id_delete.privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y bluetooth.host.bt_id_delete.privacy_bt_settings_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_SETTINGS=y - CONFIG_BT_SETTINGS=y - CONFIG_BT_SMP=y diff --git a/tests/bluetooth/host/id/bt_id_get/testcase.yaml b/tests/bluetooth/host/id/bt_id_get/testcase.yaml index 0a0cc76c0e19..3aa6d2fb36e1 100644 --- a/tests/bluetooth/host/id/bt_id_get/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_get/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_get.default: - type: unit + type: unit diff --git a/tests/bluetooth/host/id/bt_id_init/testcase.yaml b/tests/bluetooth/host/id/bt_id_init/testcase.yaml index 382af95f9bad..629def2ca1ed 100644 --- a/tests/bluetooth/host/id/bt_id_init/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_init/testcase.yaml @@ -1,15 +1,15 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_init.default: - type: unit + type: unit bluetooth.host.bt_id_init.default_bt_settings_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_SETTINGS=y - CONFIG_BT_SETTINGS=y bluetooth.host.bt_id_create.bt_privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/host/id/bt_id_reset/testcase.yaml b/tests/bluetooth/host/id/bt_id_reset/testcase.yaml index 115cb1d33269..f265b392521c 100644 --- a/tests/bluetooth/host/id/bt_id_reset/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_reset/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_reset.default: - type: unit + type: unit diff --git a/tests/bluetooth/host/id/bt_id_scan_random_addr_check/testcase.yaml b/tests/bluetooth/host/id/bt_id_scan_random_addr_check/testcase.yaml index 0ed0abc7ff5d..c34c60bff9a6 100644 --- a/tests/bluetooth/host/id/bt_id_scan_random_addr_check/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_scan_random_addr_check/testcase.yaml @@ -1,19 +1,19 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_scan_random_addr_check.default: - type: unit + type: unit bluetooth.host.bt_id_scan_random_addr_check.broadcaster_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_BROADCASTER=y bluetooth.host.bt_id_scan_random_addr_check.broadcaster_privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y - CONFIG_BT_BROADCASTER=y bluetooth.host.bt_id_scan_random_addr_check.bt_ext_adv_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_EXT_ADV=y diff --git a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_adv_own_addr/testcase.yaml index 5610dd9f4cca..6c1449b0522e 100644 --- a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_set_adv_own_addr/testcase.yaml @@ -1,14 +1,14 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_set_adv_own_addr.default: - type: unit + type: unit bluetooth.host.bt_id_set_adv_own_addr.default_ext_adv_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_EXT_ADV=y bluetooth.host.bt_id_set_adv_own_addr.privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_adv_private_addr/testcase.yaml index aaf74d52f53b..e619429ab921 100644 --- a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_set_adv_private_addr/testcase.yaml @@ -1,16 +1,16 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_set_adv_private_addr.default: - type: unit + type: unit bluetooth.host.bt_id_set_adv_private_addr.bt_privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y bluetooth.host.bt_id_set_adv_private_addr.bt_privacy_ext_adv_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y - CONFIG_BT_EXT_ADV=y diff --git a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_adv_random_addr/testcase.yaml index c366fc09e469..133e5e389b13 100644 --- a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_set_adv_random_addr/testcase.yaml @@ -1,9 +1,9 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_set_adv_random_addr.default: - type: unit + type: unit bluetooth.host.bt_id_set_adv_random_addr.bt_ext_adv_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_EXT_ADV=y diff --git a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/testcase.yaml index db70d1dc07a2..e198cdd892a9 100644 --- a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/testcase.yaml @@ -1,10 +1,10 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_set_create_conn_own_addr.default: - type: unit + type: unit bluetooth.host.bt_id_set_create_conn_own_addr.privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/host/id/bt_id_set_private_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_private_addr/testcase.yaml index 0306d5091aff..0db68688544f 100644 --- a/tests/bluetooth/host/id/bt_id_set_private_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_set_private_addr/testcase.yaml @@ -1,10 +1,10 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_set_private_addr.default: - type: unit + type: unit bluetooth.host.bt_id_set_private_addr.bt_privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_scan_own_addr/testcase.yaml index 89e44c99fb81..861ecb6ddb54 100644 --- a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_set_scan_own_addr/testcase.yaml @@ -1,20 +1,20 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_set_scan_own_addr.default: - type: unit + type: unit bluetooth.host.bt_id_set_scan_own_addr.privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y bluetooth.host.bt_id_set_scan_own_addr.default_scan_with_identity: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SCAN_WITH_IDENTITY=y bluetooth.host.bt_id_set_scan_own_addr.privacy_scan_with_identity_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SCAN_WITH_IDENTITY=y - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/testcase.yaml b/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/testcase.yaml index a705a034ed86..286a7a7d3726 100644 --- a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/testcase.yaml +++ b/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/testcase.yaml @@ -1,10 +1,10 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_le_ext_adv_oob_get_local.default: - type: unit + type: unit bluetooth.host.bt_le_oob_get_local.bt_privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/host/id/bt_le_oob_get_local/testcase.yaml b/tests/bluetooth/host/id/bt_le_oob_get_local/testcase.yaml index f9ad3efe078f..b3d75b2dafcf 100644 --- a/tests/bluetooth/host/id/bt_le_oob_get_local/testcase.yaml +++ b/tests/bluetooth/host/id/bt_le_oob_get_local/testcase.yaml @@ -1,16 +1,16 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_le_oob_get_local.default: - type: unit + type: unit bluetooth.host.bt_le_oob_get_local.bt_privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y bluetooth.host.bt_le_oob_get_local.bt_broadcaster_privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y - CONFIG_BT_BROADCASTER=y diff --git a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/testcase.yaml b/tests/bluetooth/host/id/bt_le_oob_get_sc_data/testcase.yaml index bedd08e8f809..919cb8d6570b 100644 --- a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/testcase.yaml +++ b/tests/bluetooth/host/id/bt_le_oob_get_sc_data/testcase.yaml @@ -1,7 +1,7 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_le_oob_get_sc_data.default: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y diff --git a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/testcase.yaml b/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/testcase.yaml index 5a733af11639..9129b02f28b6 100644 --- a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/testcase.yaml +++ b/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/testcase.yaml @@ -1,7 +1,7 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_le_oob_set_legacy_tk.default: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y diff --git a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/testcase.yaml b/tests/bluetooth/host/id/bt_le_oob_set_sc_data/testcase.yaml index 0c375a1f0aeb..f55121dd0d32 100644 --- a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/testcase.yaml +++ b/tests/bluetooth/host/id/bt_le_oob_set_sc_data/testcase.yaml @@ -1,7 +1,7 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_le_oob_set_sc_data.default: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y diff --git a/tests/bluetooth/host/id/bt_lookup_id_addr/testcase.yaml b/tests/bluetooth/host/id/bt_lookup_id_addr/testcase.yaml index d9f9407c18bb..de16dd3b000a 100644 --- a/tests/bluetooth/host/id/bt_lookup_id_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_lookup_id_addr/testcase.yaml @@ -1,9 +1,9 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_lookup_id_addr.default: - type: unit + type: unit bluetooth.host.bt_lookup_id_addr.bt_smp_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y diff --git a/tests/bluetooth/host/id/bt_setup_public_id_addr/testcase.yaml b/tests/bluetooth/host/id/bt_setup_public_id_addr/testcase.yaml index dbf58a3e2026..565120762a28 100644 --- a/tests/bluetooth/host/id/bt_setup_public_id_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_setup_public_id_addr/testcase.yaml @@ -1,21 +1,21 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_setup_public_id_addr.default: - type: unit + type: unit bluetooth.host.bt_setup_public_id_addr.default_bt_settings_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_SETTINGS=y - CONFIG_BT_SETTINGS=y bluetooth.host.bt_setup_public_id_addr.bt_privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y bluetooth.host.bt_setup_public_id_addr.bt_privacy_settings_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y - CONFIG_SETTINGS=y diff --git a/tests/bluetooth/host/id/bt_setup_random_id_addr/testcase.yaml b/tests/bluetooth/host/id/bt_setup_random_id_addr/testcase.yaml index 04b8c368a854..ab4da7ae51c3 100644 --- a/tests/bluetooth/host/id/bt_setup_random_id_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_setup_random_id_addr/testcase.yaml @@ -1,34 +1,34 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_id_create.default: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_ID_MAX=1 bluetooth.host.bt_id_create.multiple_identities: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_ID_MAX=4 bluetooth.host.bt_id_create.hci_vs_ext_detect: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_ID_MAX=1 - CONFIG_BT_HCI_VS_EXT_DETECT=y bluetooth.host.bt_id_create.multiple_identities_hci_vs_ext_detect: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_ID_MAX=4 - CONFIG_BT_HCI_VS_EXT_DETECT=y bluetooth.host.bt_id_create.multiple_identities_hci_vs_ext_detect_privacy_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_ID_MAX=4 - CONFIG_BT_HCI_VS_EXT_DETECT=y - CONFIG_BT_SMP=y - CONFIG_BT_PRIVACY=y bluetooth.host.bt_id_create.multiple_identities_hci_vs_ext_detect_privacy_settings_enabled: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_ID_MAX=4 - CONFIG_BT_HCI_VS_EXT_DETECT=y - CONFIG_BT_SMP=y diff --git a/tests/bluetooth/host/keys/bt_keys_store/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_store/testcase.yaml index 3c12ec51e296..de9f05cbd4a6 100644 --- a/tests/bluetooth/host/keys/bt_keys_store/testcase.yaml +++ b/tests/bluetooth/host/keys/bt_keys_store/testcase.yaml @@ -1,8 +1,8 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_keys_store.default: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_SETTINGS=y - CONFIG_BT_SETTINGS=y diff --git a/tests/bluetooth/host/keys/bt_keys_update_usage/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_update_usage/testcase.yaml index a2e1b866a3a9..17705c9279c6 100644 --- a/tests/bluetooth/host/keys/bt_keys_update_usage/testcase.yaml +++ b/tests/bluetooth/host/keys/bt_keys_update_usage/testcase.yaml @@ -1,14 +1,14 @@ common: - tags: test_framework bluetooth host + tags: test_framework bluetooth host tests: bluetooth.host.bt_keys_update_usage.default: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_BT_SMP=y - CONFIG_BT_KEYS_OVERWRITE_OLDEST=y bluetooth.host.bt_keys_update_usage.save_aging_counter: - type: unit - extra_configs: + type: unit + extra_configs: - CONFIG_SETTINGS=y - CONFIG_BT_SETTINGS=y - CONFIG_BT_SMP=y From c6c5d5842d1db917a0dcd0de49b980e99c2340d9 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Wed, 15 Mar 2023 10:43:15 +0100 Subject: [PATCH 0249/1906] tests: remove test_framework tag from tests non-framework tests Remove the "test_framework" tag from tests that are not testing the ztest framework itself. Signed-off-by: Henrik Brix Andersen --- tests/bluetooth/controller/ctrl_api/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_chmu/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_cis_create/testcase.yaml | 2 +- .../bluetooth/controller/ctrl_cis_terminate/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_collision/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_conn_update/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_cte_req/testcase.yaml | 2 +- .../controller/ctrl_data_length_update/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_encrypt/testcase.yaml | 2 +- .../controller/ctrl_feature_exchange/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_hci/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_invalid/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_le_ping/testcase.yaml | 2 +- .../controller/ctrl_min_used_chans/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_phy_update/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_sca_update/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_terminate/testcase.yaml | 2 +- .../controller/ctrl_tx_buffer_alloc/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_unsupported/testcase.yaml | 2 +- tests/bluetooth/controller/ctrl_version/testcase.yaml | 2 +- .../host/buf/bt_buf_get_cmd_complete/testcase.yaml | 2 +- tests/bluetooth/host/buf/bt_buf_get_evt/testcase.yaml | 2 +- tests/bluetooth/host/buf/bt_buf_get_rx/testcase.yaml | 2 +- tests/bluetooth/host/buf/bt_buf_get_type/testcase.yaml | 2 +- tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml | 2 +- tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml | 2 +- tests/bluetooth/host/crypto/bt_rand/testcase.yaml | 2 +- tests/bluetooth/host/crypto/prng_init/testcase.yaml | 2 +- tests/bluetooth/host/id/bt_br_oob_get_local/testcase.yaml | 2 +- tests/bluetooth/host/id/bt_id_add/testcase.yaml | 2 +- .../host/id/bt_id_adv_random_addr_check/testcase.yaml | 2 +- tests/bluetooth/host/id/bt_id_create/testcase.yaml | 2 +- tests/bluetooth/host/id/bt_id_del/testcase.yaml | 2 +- tests/bluetooth/host/id/bt_id_delete/testcase.yaml | 2 +- tests/bluetooth/host/id/bt_id_get/testcase.yaml | 2 +- tests/bluetooth/host/id/bt_id_init/testcase.yaml | 2 +- .../host/id/bt_id_read_public_addr/testcase.yaml | 2 +- tests/bluetooth/host/id/bt_id_reset/testcase.yaml | 2 +- .../host/id/bt_id_scan_random_addr_check/testcase.yaml | 2 +- .../host/id/bt_id_set_adv_own_addr/testcase.yaml | 2 +- .../host/id/bt_id_set_adv_private_addr/testcase.yaml | 2 +- .../host/id/bt_id_set_adv_random_addr/testcase.yaml | 2 +- .../host/id/bt_id_set_create_conn_own_addr/testcase.yaml | 2 +- .../host/id/bt_id_set_private_addr/testcase.yaml | 2 +- .../host/id/bt_id_set_scan_own_addr/testcase.yaml | 2 +- .../host/id/bt_le_ext_adv_oob_get_local/testcase.yaml | 2 +- tests/bluetooth/host/id/bt_le_oob_get_local/testcase.yaml | 2 +- .../bluetooth/host/id/bt_le_oob_get_sc_data/testcase.yaml | 2 +- .../host/id/bt_le_oob_set_legacy_tk/testcase.yaml | 2 +- .../bluetooth/host/id/bt_le_oob_set_sc_data/testcase.yaml | 2 +- tests/bluetooth/host/id/bt_lookup_id_addr/testcase.yaml | 2 +- .../host/id/bt_setup_public_id_addr/testcase.yaml | 2 +- .../host/id/bt_setup_random_id_addr/testcase.yaml | 2 +- tests/bluetooth/host/keys/bt_keys_add_type/testcase.yaml | 2 +- tests/bluetooth/host/keys/bt_keys_clear/testcase.yaml | 2 +- tests/bluetooth/host/keys/bt_keys_find/testcase.yaml | 2 +- tests/bluetooth/host/keys/bt_keys_find_addr/testcase.yaml | 2 +- tests/bluetooth/host/keys/bt_keys_find_irk/testcase.yaml | 2 +- .../host/keys/bt_keys_foreach_bond/testcase.yaml | 2 +- .../host/keys/bt_keys_foreach_type/testcase.yaml | 2 +- tests/bluetooth/host/keys/bt_keys_get_addr/testcase.yaml | 2 +- tests/bluetooth/host/keys/bt_keys_get_type/testcase.yaml | 2 +- tests/bluetooth/host/keys/bt_keys_store/testcase.yaml | 2 +- .../host/keys/bt_keys_update_usage/testcase.yaml | 2 +- tests/drivers/fuel_gauge/sbs_gauge/testcase.yaml | 4 ++-- tests/drivers/sensor/sbs_gauge/testcase.yaml | 8 ++++---- 66 files changed, 70 insertions(+), 70 deletions(-) diff --git a/tests/bluetooth/controller/ctrl_api/testcase.yaml b/tests/bluetooth/controller/ctrl_api/testcase.yaml index 6efe042568c7..6be24ed9ffb7 100644 --- a/tests/bluetooth/controller/ctrl_api/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_api/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_api bt_ull_llcp + tags: bluetooth bt_api bt_ull_llcp tests: bluetooth.controller.ctrl_api.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_chmu/testcase.yaml b/tests/bluetooth/controller/ctrl_chmu/testcase.yaml index 3d14bf176de5..ead7cba0f456 100644 --- a/tests/bluetooth/controller/ctrl_chmu/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_chmu/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_chmu bt_ull_llcp + tags: bluetooth bt_chmu bt_ull_llcp tests: bluetooth.controller.ctrl_chmu.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_cis_create/testcase.yaml b/tests/bluetooth/controller/ctrl_cis_create/testcase.yaml index 990c232af060..0c3520381056 100644 --- a/tests/bluetooth/controller/ctrl_cis_create/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_cis_create/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_cis_create bt_ull_llcp + tags: bluetooth bt_cis_create bt_ull_llcp tests: bluetooth.controller.ctrl_cis_create.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_cis_terminate/testcase.yaml b/tests/bluetooth/controller/ctrl_cis_terminate/testcase.yaml index 2027fc6d0be6..e48f8f2da747 100644 --- a/tests/bluetooth/controller/ctrl_cis_terminate/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_cis_terminate/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_cis_terminate bt_ull_llcp + tags: bluetooth bt_cis_terminate bt_ull_llcp tests: bluetooth.controller.ctrl_cis_terminate.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_collision/testcase.yaml b/tests/bluetooth/controller/ctrl_collision/testcase.yaml index a452a30909f5..6bc59c25a910 100644 --- a/tests/bluetooth/controller/ctrl_collision/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_collision/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_collision bt_ull_llcp + tags: bluetooth bt_collision bt_ull_llcp tests: bluetooth.controller.ctrl_collision.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_conn_update/testcase.yaml b/tests/bluetooth/controller/ctrl_conn_update/testcase.yaml index 924e31484612..bb7825798c4b 100644 --- a/tests/bluetooth/controller/ctrl_conn_update/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_conn_update/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_conn_update bt_conn_param_req bt_ull_llcp + tags: bluetooth bt_conn_update bt_conn_param_req bt_ull_llcp tests: bluetooth.controller.ctrl_conn_update.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_cte_req/testcase.yaml b/tests/bluetooth/controller/ctrl_cte_req/testcase.yaml index b67729e43a81..aa286ae26f5d 100644 --- a/tests/bluetooth/controller/ctrl_cte_req/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_cte_req/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_le_cte_req bt_ull_llcp + tags: bluetooth bt_le_cte_req bt_ull_llcp tests: bluetooth.controller.ctrl_cte_req.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_data_length_update/testcase.yaml b/tests/bluetooth/controller/ctrl_data_length_update/testcase.yaml index 511e893c4dc4..c2330e3971fb 100644 --- a/tests/bluetooth/controller/ctrl_data_length_update/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_data_length_update/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_data_length_update bt_ull_llcp + tags: bluetooth bt_data_length_update bt_ull_llcp tests: bluetooth.controller.ctrl_data_length_update.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_encrypt/testcase.yaml b/tests/bluetooth/controller/ctrl_encrypt/testcase.yaml index 71a197c2cfa9..6b002c986493 100644 --- a/tests/bluetooth/controller/ctrl_encrypt/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_encrypt/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_encrypt bt_ull_llcp + tags: bluetooth bt_encrypt bt_ull_llcp tests: bluetooth.controller.ctrl_encrypt.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_feature_exchange/testcase.yaml b/tests/bluetooth/controller/ctrl_feature_exchange/testcase.yaml index 416b3e851ea9..625feca529c9 100644 --- a/tests/bluetooth/controller/ctrl_feature_exchange/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_feature_exchange/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_feature_exchange bt_ull_llcp + tags: bluetooth bt_feature_exchange bt_ull_llcp tests: bluetooth.controller.ctrl_feature_exchange.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_hci/testcase.yaml b/tests/bluetooth/controller/ctrl_hci/testcase.yaml index f2a94d8f2301..3a523736c157 100644 --- a/tests/bluetooth/controller/ctrl_hci/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_hci/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_ctrl_hci bt_ull_llcp + tags: bluetooth bt_ctrl_hci bt_ull_llcp tests: bluetooth.controller.ctrl_hci.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_invalid/testcase.yaml b/tests/bluetooth/controller/ctrl_invalid/testcase.yaml index 41d2eb397b50..717498dd0a45 100644 --- a/tests/bluetooth/controller/ctrl_invalid/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_invalid/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_invalid bt_ull_llcp + tags: bluetooth bt_invalid bt_ull_llcp tests: bluetooth.controller.ctrl_invalid.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_le_ping/testcase.yaml b/tests/bluetooth/controller/ctrl_le_ping/testcase.yaml index 9c4551f5d737..2a117d2911f0 100644 --- a/tests/bluetooth/controller/ctrl_le_ping/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_le_ping/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_le_ping bt_ull_llcp + tags: bluetooth bt_le_ping bt_ull_llcp tests: bluetooth.controller.ctrl_le_ping.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_min_used_chans/testcase.yaml b/tests/bluetooth/controller/ctrl_min_used_chans/testcase.yaml index 9396b13b3c50..9360c10415a0 100644 --- a/tests/bluetooth/controller/ctrl_min_used_chans/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_min_used_chans/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_min_used_chans bt_ull_llcp + tags: bluetooth bt_min_used_chans bt_ull_llcp tests: bluetooth.controller.ctrl_min_used_chans.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_phy_update/testcase.yaml b/tests/bluetooth/controller/ctrl_phy_update/testcase.yaml index 26f1d13f063c..f1ae45f3f238 100644 --- a/tests/bluetooth/controller/ctrl_phy_update/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_phy_update/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_phy_update bt_ull_llcp + tags: bluetooth bt_phy_update bt_ull_llcp tests: bluetooth.controller.ctrl_phy_update.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_sca_update/testcase.yaml b/tests/bluetooth/controller/ctrl_sca_update/testcase.yaml index 3076e6164477..aa137c378048 100644 --- a/tests/bluetooth/controller/ctrl_sca_update/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_sca_update/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_sca_update bt_ull_llcp + tags: bluetooth bt_sca_update bt_ull_llcp tests: bluetooth.controller.ctrl_sca_update.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_terminate/testcase.yaml b/tests/bluetooth/controller/ctrl_terminate/testcase.yaml index 55c28f6a2bcf..f4f6105283af 100644 --- a/tests/bluetooth/controller/ctrl_terminate/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_terminate/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_terminate bt_ull_llcp + tags: bluetooth bt_terminate bt_ull_llcp tests: bluetooth.controller.ctrl_terminate.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_tx_buffer_alloc/testcase.yaml b/tests/bluetooth/controller/ctrl_tx_buffer_alloc/testcase.yaml index ff525ecf5261..1b6440607966 100644 --- a/tests/bluetooth/controller/ctrl_tx_buffer_alloc/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_tx_buffer_alloc/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_tx_buffer_alloc bt_ull_llcp + tags: bluetooth bt_tx_buffer_alloc bt_ull_llcp tests: bluetooth.controller.ctrl_tx_buffer_alloc.test_0_per_conn: type: unit diff --git a/tests/bluetooth/controller/ctrl_unsupported/testcase.yaml b/tests/bluetooth/controller/ctrl_unsupported/testcase.yaml index 089be64b3f3d..6e358a2f6481 100644 --- a/tests/bluetooth/controller/ctrl_unsupported/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_unsupported/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_unsupported bt_ull_llcp + tags: bluetooth bt_unsupported bt_ull_llcp tests: bluetooth.controller.ctrl_unsupported.default.test: type: unit diff --git a/tests/bluetooth/controller/ctrl_version/testcase.yaml b/tests/bluetooth/controller/ctrl_version/testcase.yaml index 3571650afb95..8b8fe6c3bf03 100644 --- a/tests/bluetooth/controller/ctrl_version/testcase.yaml +++ b/tests/bluetooth/controller/ctrl_version/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth bt_version_exchange bt_ull_llcp + tags: bluetooth bt_version_exchange bt_ull_llcp tests: bluetooth.controller.ctrl_version.test: type: unit diff --git a/tests/bluetooth/host/buf/bt_buf_get_cmd_complete/testcase.yaml b/tests/bluetooth/host/buf/bt_buf_get_cmd_complete/testcase.yaml index f8450fd2059e..d8cc9098fa18 100644 --- a/tests/bluetooth/host/buf/bt_buf_get_cmd_complete/testcase.yaml +++ b/tests/bluetooth/host/buf/bt_buf_get_cmd_complete/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_buf_get_cmd_complete.default: type: unit diff --git a/tests/bluetooth/host/buf/bt_buf_get_evt/testcase.yaml b/tests/bluetooth/host/buf/bt_buf_get_evt/testcase.yaml index 77746e39e4e7..e73499d94514 100644 --- a/tests/bluetooth/host/buf/bt_buf_get_evt/testcase.yaml +++ b/tests/bluetooth/host/buf/bt_buf_get_evt/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_buf_get_evt.default: type: unit diff --git a/tests/bluetooth/host/buf/bt_buf_get_rx/testcase.yaml b/tests/bluetooth/host/buf/bt_buf_get_rx/testcase.yaml index a88852224cb9..81da95831cfe 100644 --- a/tests/bluetooth/host/buf/bt_buf_get_rx/testcase.yaml +++ b/tests/bluetooth/host/buf/bt_buf_get_rx/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_buf_get_rx.default: type: unit diff --git a/tests/bluetooth/host/buf/bt_buf_get_type/testcase.yaml b/tests/bluetooth/host/buf/bt_buf_get_type/testcase.yaml index 2b8b669fec1d..f710f561511b 100644 --- a/tests/bluetooth/host/buf/bt_buf_get_type/testcase.yaml +++ b/tests/bluetooth/host/buf/bt_buf_get_type/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_buf_get_type.default: type: unit diff --git a/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml b/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml index 6d78c36809f7..258c8f2831d4 100644 --- a/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml +++ b/tests/bluetooth/host/crypto/bt_encrypt_be/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_encrypt_be.default: type: unit diff --git a/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml b/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml index e4df36c4c321..4d0902195864 100644 --- a/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml +++ b/tests/bluetooth/host/crypto/bt_encrypt_le/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_encrypt_le.default: type: unit diff --git a/tests/bluetooth/host/crypto/bt_rand/testcase.yaml b/tests/bluetooth/host/crypto/bt_rand/testcase.yaml index 3e504610e6e5..392039bda48d 100644 --- a/tests/bluetooth/host/crypto/bt_rand/testcase.yaml +++ b/tests/bluetooth/host/crypto/bt_rand/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_rand.default: type: unit diff --git a/tests/bluetooth/host/crypto/prng_init/testcase.yaml b/tests/bluetooth/host/crypto/prng_init/testcase.yaml index c52585f04b2f..4ad108412f9d 100644 --- a/tests/bluetooth/host/crypto/prng_init/testcase.yaml +++ b/tests/bluetooth/host/crypto/prng_init/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.prng_init.default: type: unit diff --git a/tests/bluetooth/host/id/bt_br_oob_get_local/testcase.yaml b/tests/bluetooth/host/id/bt_br_oob_get_local/testcase.yaml index 83a3e7a904af..65a694dd476a 100644 --- a/tests/bluetooth/host/id/bt_br_oob_get_local/testcase.yaml +++ b/tests/bluetooth/host/id/bt_br_oob_get_local/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_br_oob_get_local.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_add/testcase.yaml b/tests/bluetooth/host/id/bt_id_add/testcase.yaml index 416ef93c4d18..321df6e71667 100644 --- a/tests/bluetooth/host/id/bt_id_add/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_add/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_add.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/testcase.yaml b/tests/bluetooth/host/id/bt_id_adv_random_addr_check/testcase.yaml index 7eb9efa443cf..e2f5f84f888a 100644 --- a/tests/bluetooth/host/id/bt_id_adv_random_addr_check/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_adv_random_addr_check/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_adv_random_addr_check.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_create/testcase.yaml b/tests/bluetooth/host/id/bt_id_create/testcase.yaml index bf963cc2894b..61a81e1ff874 100644 --- a/tests/bluetooth/host/id/bt_id_create/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_create/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_create.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_del/testcase.yaml b/tests/bluetooth/host/id/bt_id_del/testcase.yaml index ddb6dd67a570..b702663150dd 100644 --- a/tests/bluetooth/host/id/bt_id_del/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_del/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_del.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_delete/testcase.yaml b/tests/bluetooth/host/id/bt_id_delete/testcase.yaml index 07525d5b95fa..9a9af7aab93e 100644 --- a/tests/bluetooth/host/id/bt_id_delete/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_delete/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_delete.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_get/testcase.yaml b/tests/bluetooth/host/id/bt_id_get/testcase.yaml index 3aa6d2fb36e1..334fe29f3074 100644 --- a/tests/bluetooth/host/id/bt_id_get/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_get/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_get.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_init/testcase.yaml b/tests/bluetooth/host/id/bt_id_init/testcase.yaml index 629def2ca1ed..cc10262b9f6e 100644 --- a/tests/bluetooth/host/id/bt_id_init/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_init/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_init.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_read_public_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_read_public_addr/testcase.yaml index f0101beb251b..688e5c024235 100644 --- a/tests/bluetooth/host/id/bt_id_read_public_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_read_public_addr/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_read_public_addr.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_reset/testcase.yaml b/tests/bluetooth/host/id/bt_id_reset/testcase.yaml index f265b392521c..9c3642675a4e 100644 --- a/tests/bluetooth/host/id/bt_id_reset/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_reset/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_reset.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_scan_random_addr_check/testcase.yaml b/tests/bluetooth/host/id/bt_id_scan_random_addr_check/testcase.yaml index c34c60bff9a6..22dbee297846 100644 --- a/tests/bluetooth/host/id/bt_id_scan_random_addr_check/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_scan_random_addr_check/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_scan_random_addr_check.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_adv_own_addr/testcase.yaml index 6c1449b0522e..ad0df9dff09b 100644 --- a/tests/bluetooth/host/id/bt_id_set_adv_own_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_set_adv_own_addr/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_set_adv_own_addr.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_adv_private_addr/testcase.yaml index e619429ab921..bf08287a31c9 100644 --- a/tests/bluetooth/host/id/bt_id_set_adv_private_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_set_adv_private_addr/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_set_adv_private_addr.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_adv_random_addr/testcase.yaml index 133e5e389b13..8f4272c8a3f4 100644 --- a/tests/bluetooth/host/id/bt_id_set_adv_random_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_set_adv_random_addr/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_set_adv_random_addr.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/testcase.yaml index e198cdd892a9..331130b1c5d0 100644 --- a/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_set_create_conn_own_addr/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_set_create_conn_own_addr.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_set_private_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_private_addr/testcase.yaml index 0db68688544f..c4cec4aafec8 100644 --- a/tests/bluetooth/host/id/bt_id_set_private_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_set_private_addr/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_set_private_addr.default: type: unit diff --git a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/testcase.yaml b/tests/bluetooth/host/id/bt_id_set_scan_own_addr/testcase.yaml index 861ecb6ddb54..fcf3f4bb494a 100644 --- a/tests/bluetooth/host/id/bt_id_set_scan_own_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_id_set_scan_own_addr/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_set_scan_own_addr.default: type: unit diff --git a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/testcase.yaml b/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/testcase.yaml index 286a7a7d3726..5d629808b4b5 100644 --- a/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/testcase.yaml +++ b/tests/bluetooth/host/id/bt_le_ext_adv_oob_get_local/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_le_ext_adv_oob_get_local.default: type: unit diff --git a/tests/bluetooth/host/id/bt_le_oob_get_local/testcase.yaml b/tests/bluetooth/host/id/bt_le_oob_get_local/testcase.yaml index b3d75b2dafcf..73942daef45e 100644 --- a/tests/bluetooth/host/id/bt_le_oob_get_local/testcase.yaml +++ b/tests/bluetooth/host/id/bt_le_oob_get_local/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_le_oob_get_local.default: type: unit diff --git a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/testcase.yaml b/tests/bluetooth/host/id/bt_le_oob_get_sc_data/testcase.yaml index 919cb8d6570b..b5542d714e8c 100644 --- a/tests/bluetooth/host/id/bt_le_oob_get_sc_data/testcase.yaml +++ b/tests/bluetooth/host/id/bt_le_oob_get_sc_data/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_le_oob_get_sc_data.default: type: unit diff --git a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/testcase.yaml b/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/testcase.yaml index 9129b02f28b6..97d6c85d11a6 100644 --- a/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/testcase.yaml +++ b/tests/bluetooth/host/id/bt_le_oob_set_legacy_tk/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_le_oob_set_legacy_tk.default: type: unit diff --git a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/testcase.yaml b/tests/bluetooth/host/id/bt_le_oob_set_sc_data/testcase.yaml index f55121dd0d32..8144fb9f3cc5 100644 --- a/tests/bluetooth/host/id/bt_le_oob_set_sc_data/testcase.yaml +++ b/tests/bluetooth/host/id/bt_le_oob_set_sc_data/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_le_oob_set_sc_data.default: type: unit diff --git a/tests/bluetooth/host/id/bt_lookup_id_addr/testcase.yaml b/tests/bluetooth/host/id/bt_lookup_id_addr/testcase.yaml index de16dd3b000a..3e253c229370 100644 --- a/tests/bluetooth/host/id/bt_lookup_id_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_lookup_id_addr/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_lookup_id_addr.default: type: unit diff --git a/tests/bluetooth/host/id/bt_setup_public_id_addr/testcase.yaml b/tests/bluetooth/host/id/bt_setup_public_id_addr/testcase.yaml index 565120762a28..4494e36304bb 100644 --- a/tests/bluetooth/host/id/bt_setup_public_id_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_setup_public_id_addr/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_setup_public_id_addr.default: type: unit diff --git a/tests/bluetooth/host/id/bt_setup_random_id_addr/testcase.yaml b/tests/bluetooth/host/id/bt_setup_random_id_addr/testcase.yaml index ab4da7ae51c3..f04ef2b7ffdd 100644 --- a/tests/bluetooth/host/id/bt_setup_random_id_addr/testcase.yaml +++ b/tests/bluetooth/host/id/bt_setup_random_id_addr/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_id_create.default: type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_add_type/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_add_type/testcase.yaml index b1c04072cc3e..0e7b2d3e15cd 100644 --- a/tests/bluetooth/host/keys/bt_keys_add_type/testcase.yaml +++ b/tests/bluetooth/host/keys/bt_keys_add_type/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_keys_add_type.default: type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_clear/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_clear/testcase.yaml index 69c5c2c5e2b6..b1e826a6704b 100644 --- a/tests/bluetooth/host/keys/bt_keys_clear/testcase.yaml +++ b/tests/bluetooth/host/keys/bt_keys_clear/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_keys_clear.default: type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_find/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_find/testcase.yaml index ecb7794ca1c2..323aa3a6a0f8 100644 --- a/tests/bluetooth/host/keys/bt_keys_find/testcase.yaml +++ b/tests/bluetooth/host/keys/bt_keys_find/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_keys_find.default: type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_find_addr/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_find_addr/testcase.yaml index 8b102a901687..8151745957f1 100644 --- a/tests/bluetooth/host/keys/bt_keys_find_addr/testcase.yaml +++ b/tests/bluetooth/host/keys/bt_keys_find_addr/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_keys_find_addr.default: type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_find_irk/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_find_irk/testcase.yaml index 2504bc695442..211bd9a92003 100644 --- a/tests/bluetooth/host/keys/bt_keys_find_irk/testcase.yaml +++ b/tests/bluetooth/host/keys/bt_keys_find_irk/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_keys_find_irk.default: type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_bond/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_foreach_bond/testcase.yaml index 5be79598ebbd..056281d0e2cd 100644 --- a/tests/bluetooth/host/keys/bt_keys_foreach_bond/testcase.yaml +++ b/tests/bluetooth/host/keys/bt_keys_foreach_bond/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_keys_foreach_bond.default: type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_foreach_type/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_foreach_type/testcase.yaml index 3af7518fb734..27eb686c9378 100644 --- a/tests/bluetooth/host/keys/bt_keys_foreach_type/testcase.yaml +++ b/tests/bluetooth/host/keys/bt_keys_foreach_type/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_keys_foreach_type.default: type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_get_addr/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_get_addr/testcase.yaml index db3e9f3b2a9e..3cc6e00de69f 100644 --- a/tests/bluetooth/host/keys/bt_keys_get_addr/testcase.yaml +++ b/tests/bluetooth/host/keys/bt_keys_get_addr/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_keys_get_addr.default: type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_get_type/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_get_type/testcase.yaml index 5b1e0b9f74ce..639689547001 100644 --- a/tests/bluetooth/host/keys/bt_keys_get_type/testcase.yaml +++ b/tests/bluetooth/host/keys/bt_keys_get_type/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_keys_get_type.default: type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_store/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_store/testcase.yaml index de9f05cbd4a6..a6f02f865c38 100644 --- a/tests/bluetooth/host/keys/bt_keys_store/testcase.yaml +++ b/tests/bluetooth/host/keys/bt_keys_store/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_keys_store.default: type: unit diff --git a/tests/bluetooth/host/keys/bt_keys_update_usage/testcase.yaml b/tests/bluetooth/host/keys/bt_keys_update_usage/testcase.yaml index 17705c9279c6..6cf25916ad20 100644 --- a/tests/bluetooth/host/keys/bt_keys_update_usage/testcase.yaml +++ b/tests/bluetooth/host/keys/bt_keys_update_usage/testcase.yaml @@ -1,5 +1,5 @@ common: - tags: test_framework bluetooth host + tags: bluetooth host tests: bluetooth.host.bt_keys_update_usage.default: type: unit diff --git a/tests/drivers/fuel_gauge/sbs_gauge/testcase.yaml b/tests/drivers/fuel_gauge/sbs_gauge/testcase.yaml index 4cddbb13d441..e4fcfeed450e 100644 --- a/tests/drivers/fuel_gauge/sbs_gauge/testcase.yaml +++ b/tests/drivers/fuel_gauge/sbs_gauge/testcase.yaml @@ -1,7 +1,7 @@ tests: # section.subsection drivers.sbs_gauge_new_api.emulated: - tags: test_framework + tags: drivers fuel_gauge filter: > dt_compat_enabled("sbs,sbs-gauge-new-api") and (CONFIG_QEMU_TARGET or CONFIG_BOARD_NATIVE_POSIX) @@ -16,7 +16,7 @@ tests: xenvm xenvm_gicv3 drivers.sbs_gauge_new_api.emulated_64_bit_i2c_addr: - tags: test_framework + tags: drivers fuel_gauge filter: > dt_compat_enabled("sbs,sbs-gauge-new-api") and (CONFIG_QEMU_TARGET or CONFIG_BOARD_NATIVE_POSIX) diff --git a/tests/drivers/sensor/sbs_gauge/testcase.yaml b/tests/drivers/sensor/sbs_gauge/testcase.yaml index 61dfc364c968..c4a213b4a429 100644 --- a/tests/drivers/sensor/sbs_gauge/testcase.yaml +++ b/tests/drivers/sensor/sbs_gauge/testcase.yaml @@ -1,13 +1,13 @@ tests: # section.subsection - drivers.sbs_gauge: + drivers.sensors.sbs_gauge: build_only: true - tags: test_framework + tags: drivers sensors filter: dt_compat_enabled("sbs,sbs-gauge") integration_platforms: - nucleo_f070rb - drivers.sbs_gauge.emulated: - tags: test_framework + drivers.sensors.sbs_gauge.emulated: + tags: drivers sensors filter: dt_compat_enabled("sbs,sbs-gauge") platform_allow: native_posix qemu_cortex_a9 qemu_arc_hs integration_platforms: From 7e63be14c308a2d79a30b138100d751022ac7115 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Tue, 14 Mar 2023 17:30:29 +0200 Subject: [PATCH 0250/1906] bluetooth: shell: Fix NULL dereference Fix NULL dereference when dereferencing txing_stream, which was used instead of default_stream. Signed-off-by: Andrei Emeltchenko --- subsys/bluetooth/shell/bap.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/subsys/bluetooth/shell/bap.c b/subsys/bluetooth/shell/bap.c index 41a007b03911..c0300d11e309 100644 --- a/subsys/bluetooth/shell/bap.c +++ b/subsys/bluetooth/shell/bap.c @@ -2291,7 +2291,7 @@ static int cmd_send(const struct shell *sh, size_t argc, char *argv[]) return -ENOEXEC; } - if (txing_stream->qos == NULL) { + if (default_stream->qos == NULL) { shell_error(sh, "NULL stream QoS"); return -ENOEXEC; @@ -2299,14 +2299,14 @@ static int cmd_send(const struct shell *sh, size_t argc, char *argv[]) if (argc > 1) { len = hex2bin(argv[1], strlen(argv[1]), data, sizeof(data)); - if (len > txing_stream->qos->sdu) { + if (len > default_stream->qos->sdu) { shell_print(sh, "Unable to send: len %d > %u MTU", - len, txing_stream->qos->sdu); + len, default_stream->qos->sdu); return -ENOEXEC; } } else { - len = MIN(txing_stream->qos->sdu, sizeof(data)); + len = MIN(default_stream->qos->sdu, sizeof(data)); memset(data, 0xff, len); } @@ -2315,10 +2315,10 @@ static int cmd_send(const struct shell *sh, size_t argc, char *argv[]) net_buf_add_mem(buf, data, len); - seq_num = get_next_seq_num(txing_stream->qos->interval); + seq_num = get_next_seq_num(default_stream->qos->interval); - ret = bt_bap_stream_send(txing_stream, buf, seq_num, - BT_ISO_TIMESTAMP_NONE); + ret = bt_bap_stream_send(default_stream, buf, seq_num, + BT_ISO_TIMESTAMP_NONE); if (ret < 0) { shell_print(sh, "Unable to send: %d", -ret); net_buf_unref(buf); From ce3557a9581193e157e74882724f7680ea2f3fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Mon, 13 Mar 2023 15:01:06 +0100 Subject: [PATCH 0251/1906] Bluetooth: Mesh: Add SAR srv persistence storage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds persistent storage for SAR server RX and TX set cmd parameters. Also ensures that SAR RX and TX parameters are set back to default values upon reset of the mesh device. Signed-off-by: Anders Storrø --- subsys/bluetooth/mesh/sar_cfg_srv.c | 61 +++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/subsys/bluetooth/mesh/sar_cfg_srv.c b/subsys/bluetooth/mesh/sar_cfg_srv.c index c2f8c5e30886..e05489ee0cfd 100644 --- a/subsys/bluetooth/mesh/sar_cfg_srv.c +++ b/subsys/bluetooth/mesh/sar_cfg_srv.c @@ -21,11 +21,28 @@ #include "foundation.h" #include "mesh.h" #include "sar_cfg_internal.h" +#include "settings.h" #define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL #include LOG_MODULE_REGISTER(bt_mesh_sar_cfg_srv); +static int sar_rx_store(struct bt_mesh_model *model, bool delete) +{ + const void *data = delete ? NULL : &bt_mesh.sar_rx; + size_t len = delete ? 0 : sizeof(struct bt_mesh_sar_rx); + + return bt_mesh_model_data_store(model, false, "sar_rx", data, len); +} + +static int sar_tx_store(struct bt_mesh_model *model, bool delete) +{ + const void *data = delete ? NULL : &bt_mesh.sar_tx; + size_t len = delete ? 0 : sizeof(struct bt_mesh_sar_tx); + + return bt_mesh_model_data_store(model, false, "sar_tx", data, len); +} + static void transmitter_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx) { @@ -84,6 +101,10 @@ static int transmitter_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx * bt_mesh_sar_tx_decode(buf, tx); transmitter_status(model, ctx); + if (IS_ENABLED(CONFIG_BT_SETTINGS)) { + sar_tx_store(model, false); + } + return 0; } @@ -107,6 +128,10 @@ static int receiver_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx bt_mesh_sar_rx_decode(buf, rx); receiver_status(model, ctx); + if (IS_ENABLED(CONFIG_BT_SETTINGS)) { + sar_rx_store(model, false); + } + return 0; } @@ -135,6 +160,42 @@ static int sar_cfg_srv_init(struct bt_mesh_model *model) return 0; } +static void sar_cfg_srv_reset(struct bt_mesh_model *model) +{ + struct bt_mesh_sar_tx sar_tx = BT_MESH_SAR_TX_INIT; + struct bt_mesh_sar_rx sar_rx = BT_MESH_SAR_RX_INIT; + + bt_mesh.sar_tx = sar_tx; + bt_mesh.sar_rx = sar_rx; + + if (IS_ENABLED(CONFIG_BT_SETTINGS)) { + sar_rx_store(model, true); + sar_tx_store(model, true); + } +} + +#ifdef CONFIG_BT_SETTINGS +static int sar_cfg_srv_settings_set(struct bt_mesh_model *model, const char *name, size_t len_rd, + settings_read_cb read_cb, void *cb_data) +{ + if (!strncmp(name, "sar_rx", 5)) { + return bt_mesh_settings_set(read_cb, cb_data, &bt_mesh.sar_rx, + sizeof(bt_mesh.sar_rx)); + } + + if (!strncmp(name, "sar_tx", 5)) { + return bt_mesh_settings_set(read_cb, cb_data, &bt_mesh.sar_tx, + sizeof(bt_mesh.sar_tx)); + } + + return 0; +} +#endif + const struct bt_mesh_model_cb bt_mesh_sar_cfg_srv_cb = { .init = sar_cfg_srv_init, + .reset = sar_cfg_srv_reset, +#ifdef CONFIG_BT_SETTINGS + .settings_set = sar_cfg_srv_settings_set +#endif }; From a818d06cf24dd7605f2bf47b56fc7f078da168b6 Mon Sep 17 00:00:00 2001 From: Michael Kaplan Date: Tue, 4 Oct 2022 20:38:24 +0200 Subject: [PATCH 0252/1906] drivers: sensors: apds9960 fix trigger callback context In the current implementation, the apds9960 trigger callback function is called with the pointer of a driver-internal allocated trigger structure. This structure is not initialized anywhere, so essentially the trigger callback gets called with junk data. Besides the missing initialization, it would be better instead to hold a const pointer to a user allocated sensor_trigger object. This way user code can establish a context with related user data (for example a pointer to a C++ object) by storing its sensor_trigger object within a structure alongside the user data, and then using CONTAINER_OF() macro to get the pointer of the container struct (and thus the user data). Signed-off-by: Michael Kaplan --- drivers/sensor/apds9960/apds9960.h | 2 +- drivers/sensor/apds9960/apds9960_trigger.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/sensor/apds9960/apds9960.h b/drivers/sensor/apds9960/apds9960.h index e6d2c5cc9319..75e19d6e4b69 100644 --- a/drivers/sensor/apds9960/apds9960.h +++ b/drivers/sensor/apds9960/apds9960.h @@ -230,7 +230,7 @@ struct apds9960_data { #ifdef CONFIG_APDS9960_TRIGGER sensor_trigger_handler_t p_th_handler; - struct sensor_trigger p_th_trigger; + const struct sensor_trigger *p_th_trigger; #else struct k_sem data_sem; #endif diff --git a/drivers/sensor/apds9960/apds9960_trigger.c b/drivers/sensor/apds9960/apds9960_trigger.c index 62be59e8c733..245fdab68fba 100644 --- a/drivers/sensor/apds9960/apds9960_trigger.c +++ b/drivers/sensor/apds9960/apds9960_trigger.c @@ -25,7 +25,7 @@ void apds9960_work_cb(struct k_work *work) const struct device *dev = data->dev; if (data->p_th_handler != NULL) { - data->p_th_handler(dev, &data->p_th_trigger); + data->p_th_handler(dev, data->p_th_trigger); } apds9960_setup_int(dev->config, true); @@ -75,6 +75,7 @@ int apds9960_trigger_set(const struct device *dev, case SENSOR_TRIG_THRESHOLD: if (trig->chan == SENSOR_CHAN_PROX) { data->p_th_handler = handler; + data->p_th_trigger = trig; if (i2c_reg_update_byte_dt(&config->i2c, APDS9960_ENABLE_REG, APDS9960_ENABLE_PIEN, From e72cdcd4f9d74c08dd9eb187b94a0e41f0355d84 Mon Sep 17 00:00:00 2001 From: Emilio Benavente Date: Thu, 2 Mar 2023 10:53:43 -0600 Subject: [PATCH 0253/1906] boards: arm: mimxrt595_evk: Added Pinctrl Adding Pinctrl for SC Timer Support. Signed-off-by: Emilio Benavente --- boards/arm/mimxrt595_evk/mimxrt595_evk_cm33-pinctrl.dtsi | 9 +++++++++ boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.dts | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33-pinctrl.dtsi b/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33-pinctrl.dtsi index ef046a88c761..4bbab86e6de3 100644 --- a/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33-pinctrl.dtsi +++ b/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33-pinctrl.dtsi @@ -188,4 +188,13 @@ drive-strength = "normal"; }; }; + + pinmux_sctimer_default: pinmux_sctimer_default { + group0 { + pinmux = , + ; + slew-rate = "normal"; + drive-strength = "normal"; + }; + }; }; diff --git a/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.dts b/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.dts index 67887b303672..f21a14b12afd 100644 --- a/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.dts +++ b/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.dts @@ -26,6 +26,7 @@ accel0 = &fxos8700; sdhc0 = &usdhc0; kscan0 = &touch_controller; + pwm-0 = &sc_timer; }; chosen { @@ -467,3 +468,9 @@ zephyr_udc0: &usbhs { ahb-write-wait-interval = <0>; }; }; + +&sc_timer { + pinctrl-0 = <&pinmux_sctimer_default>; + pinctrl-names = "default"; + status = "okay"; +}; From c8c859c2cd10a09615d320a3c2d46d1bb4a415a1 Mon Sep 17 00:00:00 2001 From: Emilio Benavente Date: Fri, 3 Mar 2023 13:14:18 -0600 Subject: [PATCH 0254/1906] boards: arm: mimxrt595_evk: Documents SCT pins Added to the Docs for the mimxrt595_evk for the added sc_timer pins. Signed-off-by: Emilio Benavente --- boards/arm/mimxrt595_evk/doc/index.rst | 4 ++++ boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.yaml | 1 + 2 files changed, 5 insertions(+) diff --git a/boards/arm/mimxrt595_evk/doc/index.rst b/boards/arm/mimxrt595_evk/doc/index.rst index 728e31db37a4..13a194e37eed 100644 --- a/boards/arm/mimxrt595_evk/doc/index.rst +++ b/boards/arm/mimxrt595_evk/doc/index.rst @@ -153,6 +153,10 @@ functionality of a pin. +---------+-----------------+----------------------------+ | PIO1_6 | SPI | SPI SSEL | +---------+-----------------+----------------------------+ +| PIO0_5 | SCT0 | SCT0 GPI0 | ++---------+-----------------+----------------------------+ +| PIO0_6 | SCT0 | SCT0 GPI1 | ++---------+-----------------+----------------------------+ System Clock ============ diff --git a/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.yaml b/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.yaml index b25924329cbd..dbf6499c6ff0 100644 --- a/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.yaml +++ b/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.yaml @@ -26,3 +26,4 @@ supported: - usb_device - watchdog - sdhc + - pwm From e454203290220c1094348dc6aea44c25fa3dd0e1 Mon Sep 17 00:00:00 2001 From: Anisetti Avinash Krishna Date: Mon, 13 Mar 2023 14:16:35 +0530 Subject: [PATCH 0255/1906] soc: x86: raptor_lake: Add GPIO support for rpl_crb Enabled GPIO support for rpl_crb board by adding platform GPIO specific definitions. Signed-off-by: Anisetti Avinash Krishna --- soc/x86/raptor_lake/soc.h | 4 +++ soc/x86/raptor_lake/soc_gpio.h | 53 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 soc/x86/raptor_lake/soc_gpio.h diff --git a/soc/x86/raptor_lake/soc.h b/soc/x86/raptor_lake/soc.h index 356f936b8dfa..6de3f7fa9c0e 100644 --- a/soc/x86/raptor_lake/soc.h +++ b/soc/x86/raptor_lake/soc.h @@ -21,6 +21,10 @@ #include #endif +#ifdef CONFIG_GPIO_INTEL +#include "soc_gpio.h" +#endif + #if DT_ON_BUS(DT_CHOSEN(zephyr_console), pcie) #include #define X86_SOC_EARLY_SERIAL_PCIDEV DT_REG_ADDR(DT_CHOSEN(zephyr_console)) diff --git a/soc/x86/raptor_lake/soc_gpio.h b/soc/x86/raptor_lake/soc_gpio.h new file mode 100644 index 000000000000..544df564a081 --- /dev/null +++ b/soc/x86/raptor_lake/soc_gpio.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023, Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief GPIO macros for the Raptor Lake SoC + * + * This header file is used to specify the GPIO macros for + * the Raptor Lake SoC. + */ + +#ifndef __SOC_GPIO_H_ +#define __SOC_GPIO_H_ + +#define GPIO_INTEL_NR_SUBDEVS 13 + +#define REG_PAD_OWNER_BASE 0x00A0 +#define REG_GPI_INT_STS_BASE 0x0200 +#define PAD_CFG0_PMODE_MASK (0x07 << 10) + +#define REG_GPI_INT_EN_BASE 0x0220 +#define REG_PAD_HOST_SW_OWNER 0x150 +#define PAD_BASE_ADDR_MASK 0xfff + +#define GPIO_REG_BASE(reg_base) \ + (reg_base & ~PAD_BASE_ADDR_MASK) + +#define GPIO_PAD_BASE(reg_base) \ + (reg_base & PAD_BASE_ADDR_MASK) + +#define GPIO_PAD_OWNERSHIP(raw_pin, pin_offset) \ + (pin_offset % 8) ? \ + REG_PAD_OWNER_BASE + \ + ((((pin_offset / 8) + 1) + (raw_pin / 8)) * 0x4) : \ + REG_PAD_OWNER_BASE + \ + (((pin_offset / 8) + (raw_pin / 8)) * 0x4); \ + +#define GPIO_OWNERSHIP_BIT(raw_pin) ((raw_pin % 8) * 4) + +#define GPIO_RAW_PIN(pin, pin_offset) pin + +#define GPIO_INTERRUPT_BASE(cfg) \ + (cfg->group_index * 0x4) + +#define GPIO_BASE(cfg) \ + (cfg->group_index * 0x4) + +#define PIN_OFFSET 0x10 + +#endif /* __SOC_GPIO_H_ */ From 98e280a24921f47a7fefb95cd33c46dc433cc5d2 Mon Sep 17 00:00:00 2001 From: Anisetti Avinash Krishna Date: Mon, 13 Mar 2023 14:33:17 +0530 Subject: [PATCH 0256/1906] dts: x86: intel: raptor_lake: Add GPIO instances Added GPIO instances in raptor_lake dtsi file. Signed-off-by: Anisetti Avinash Krishna --- dts/x86/intel/raptor_lake.dtsi | 182 +++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) diff --git a/dts/x86/intel/raptor_lake.dtsi b/dts/x86/intel/raptor_lake.dtsi index 9dea7c541610..3f79de241c66 100644 --- a/dts/x86/intel/raptor_lake.dtsi +++ b/dts/x86/intel/raptor_lake.dtsi @@ -64,6 +64,188 @@ status = "okay"; }; + gpio_0_i: gpio@e06e0700 { + compatible = "intel,gpio"; + reg = <0xe06e0700 0x1000>; + interrupts = <14 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + group-index = <0x0>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <23>; + pin-offset = <0>; + + status = "okay"; + }; + + gpio_0_r: gpio@e06e0890 { + compatible = "intel,gpio"; + reg = <0xe06e0890 0x1000>; + interrupts = <14 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + group-index = <0x1>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <22>; + pin-offset = <26>; + + status = "okay"; + }; + + gpio_0_j: gpio@e06e0a00 { + compatible = "intel,gpio"; + reg = <0xe06e0a00 0x1000>; + interrupts = <14 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + group-index = <0x2>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <12>; + pin-offset = <49>; + + status = "okay"; + }; + + gpio_1_b: gpio@e06d0700 { + compatible = "intel,gpio"; + reg = <0xe06d0700 0x1000>; + interrupts = <14 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + group-index = <0x0>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <24>; + pin-offset = <0>; + + status = "okay"; + }; + + gpio_1_g: gpio@e06d0880 { + compatible = "intel,gpio"; + reg = <0xe06d0880 0x1000>; + interrupts = <14 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + group-index = <0x1>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <8>; + pin-offset = <24>; + + status = "okay"; + }; + + gpio_1_h: gpio@e06d0900 { + compatible = "intel,gpio"; + reg = <0xe06d0900 0x1000>; + interrupts = <14 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + group-index = <0x2>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <24>; + pin-offset = <32>; + + status = "okay"; + }; + + gpio_3_a: gpio@e06b0790 { + compatible = "intel,gpio"; + reg = <0xe06b0790 0x1000>; + interrupts = <14 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + group-index = <0x1>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <15>; + pin-offset = <9>; + + status = "okay"; + }; + + gpio_3_c: gpio@e06b0890 { + compatible = "intel,gpio"; + reg = <0xe06b0890 0x1000>; + interrupts = <14 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + group-index = <0x2>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <24>; + pin-offset = <25>; + + status = "okay"; + }; + + gpio_4_s: gpio@e06a0700 { + compatible = "intel,gpio"; + reg = <0xe06a0700 0x1000>; + interrupts = <14 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + group-index = <0x0>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <8>; + pin-offset = <0>; + + status = "okay"; + }; + + gpio_4_e: gpio@e06a0780 { + compatible = "intel,gpio"; + reg = <0xe06a0780 0x1000>; + interrupts = <14 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + group-index = <0x1>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <22>; + pin-offset = <8>; + + status = "okay"; + }; + + gpio_4_k: gpio@e06a08f0 { + compatible = "intel,gpio"; + reg = <0xe06a08f0 0x1000>; + interrupts = <14 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + group-index = <0x2>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <12>; + pin-offset = <25>; + + status = "okay"; + }; + + gpio_4_f: gpio@e06a09e0 { + compatible = "intel,gpio"; + reg = <0xe06a09e0 0x1000>; + interrupts = <14 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + group-index = <0x3>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <24>; + pin-offset = <41>; + + status = "okay"; + }; + + gpio_5_d: gpio@e0690700 { + compatible = "intel,gpio"; + reg = <0xe0690700 0x1000>; + interrupts = <14 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + group-index = <0x0>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <24>; + pin-offset = <0>; + + status = "okay"; + }; + hpet: hpet@fed00000 { compatible = "intel,hpet"; reg = <0xfed00000 0x400>; From 9a63f9d3d8fe9d1c2e2e6e38b4d74dfb07f54abc Mon Sep 17 00:00:00 2001 From: Aleksander Wasaznik Date: Tue, 14 Mar 2023 16:18:55 +0100 Subject: [PATCH 0257/1906] Bluetooth: Host: Doc `bt_conn_foreach` includes disconnected A user reported confusion about whether disconnected `bt_conn` are meant to be found by `bt_conn_foreach`. The confusion likely stems from the inprecise wording "existing connections". This commit doucments `bt_conn_foreach` as it is: A low-level API for iterating trough all `bt_conn` objects, connected or not. This commit also includes a warning about possibly unintutive behavior in preemptible threads. Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/53996 Signed-off-by: Aleksander Wasaznik --- include/zephyr/bluetooth/conn.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/zephyr/bluetooth/conn.h b/include/zephyr/bluetooth/conn.h index ab243d907cba..8cefb6cd797b 100644 --- a/include/zephyr/bluetooth/conn.h +++ b/include/zephyr/bluetooth/conn.h @@ -216,7 +216,17 @@ struct bt_conn *bt_conn_ref(struct bt_conn *conn); */ void bt_conn_unref(struct bt_conn *conn); -/** @brief Iterate through all existing connections. +/** @brief Iterate through all bt_conn objects. + * + * Iterates trough all bt_conn objects that are alive in the Host allocator. + * + * To find established connections, combine this with @ref bt_conn_get_info. + * Check that @ref bt_conn_info.state is @ref BT_CONN_STATE_CONNECTED. + * + * Thread safety: This API is thread safe, but it does not guarantee a + * sequentially-consistent view for objects allocated during the current + * invocation of this API. E.g. If preempted while allocations A then B then C + * happen then results may include A and C but miss B. * * @param type Connection Type * @param func Function to call for each connection. From d79e6974579e46c91bc0119ebb27fc25495dddc9 Mon Sep 17 00:00:00 2001 From: "Fyall Ian (CYSC CSS ICW SW MTO INT)" Date: Tue, 7 Mar 2023 11:25:03 -0800 Subject: [PATCH 0258/1906] MAINTAINERS: Add Infineon Platforms section Add the Infineon Platforms section. Signed-off-by: Fyall Ian (CYSC CSS ICW SW MTO INT) --- MAINTAINERS.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index a46a27cc2a7c..e2b34a14fcce 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -2350,6 +2350,32 @@ Xilinx Platforms: labels: - "platform: Xilinx" +Infineon Platforms: + status: maintained + maintainers: + - ifyall + collaborators: + - npal-cy + - talih0 + files: + - boards/arm/cy8ckit_*/ + - boards/arm/cy8cproto_*/ + - boards/arm/xmc*_relax*/ + - drivers/*/*ifx_cat1*/ + - drivers/*/*ifx_cat1*.c + - drivers/*/*ifx_cat1* + - drivers/*/*xmc*/ + - drivers/*/*xmc*.c + - drivers/*/*/*xmc* + - dts/arm/infineon/ + - dts/bindings/*/*infineon* + - soc/arm/infineon_*/ + labels: + - "platform: Infineon" + description: >- + Infineon SOCs, dts files and related drivers. Infineon Proto, Pioneer, Eval and Relax + boards. + RTIO: status: maintained maintainers: From 5e44b7ac31acdcb690fdf99765a6d3ba45fa6296 Mon Sep 17 00:00:00 2001 From: Joel Guittet Date: Fri, 10 Mar 2023 10:27:41 +0100 Subject: [PATCH 0259/1906] bindings: add raspberrypi gpio header Add bindind support for Raspberry Pi header. Signed-off-by: Joel Guittet --- .../gpio/raspberrypi-40pins-header.yaml | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 dts/bindings/gpio/raspberrypi-40pins-header.yaml diff --git a/dts/bindings/gpio/raspberrypi-40pins-header.yaml b/dts/bindings/gpio/raspberrypi-40pins-header.yaml new file mode 100644 index 000000000000..d824c7551fd8 --- /dev/null +++ b/dts/bindings/gpio/raspberrypi-40pins-header.yaml @@ -0,0 +1,35 @@ +# Copyright (c) 2023 Joel Guittet +# SPDX-License-Identifier: Apache-2.0 + +description: | + GPIO pins exposed on Raspberry Pi 40-pin header. + + The Raspberry Pi layout provides a 2x20 pins header. + + This binding provides a nexus mapping for 28 pins as depicted below. + + - 3V3 5V - + 0 GPIO2/I2C1_SDA 5V - + 1 GPIO3/I2C1_SCL GND - + 2 GPIO4 GPIO14/UART0_TXD 3 + - GND GPIO15/UART0_RXD 4 + 5 GPIO17 GPIO18 6 + 7 GPIO27 GND - + 8 GPIO22 GPIO23 9 + - 3V3 GPIO24 10 + 11 GPIO10/SPI0_MOSI GND - + 12 GPIO9/SPI0_MISO GPIO25 13 + 14 GPIO11/SPI0_SCLK GPIO8/SPI0_CE0 15 + - GND GPIO7/SPI0_CE1 16 + 17 ID_SD/I2C0_SDA ID_SC/I2C0_SCL 18 + 19 GPIO5 GND - + 20 GPIO6 GPIO12 21 + 22 GPIO13 GND - + 23 GPIO19 GPIO16 24 + 25 GPIO26 GPIO20 26 + - GND GPIO21 27 + + +compatible: "raspberrypi-40pins-header" + +include: [gpio-nexus.yaml, base.yaml] From 0eb7391a63ba04e77276ee3e38264b6a3e25b259 Mon Sep 17 00:00:00 2001 From: Joel Guittet Date: Fri, 10 Mar 2023 10:28:47 +0100 Subject: [PATCH 0260/1906] wio terminal: add raspberrypi gpio header Add Raspberry Pi header to the Wio Terminal board. Signed-off-by: Joel Guittet --- .../raspberrypi_40pins_connector.dtsi | 46 +++++++++++++++++++ boards/arm/wio_terminal/wio_terminal.dts | 1 + 2 files changed, 47 insertions(+) create mode 100644 boards/arm/wio_terminal/raspberrypi_40pins_connector.dtsi diff --git a/boards/arm/wio_terminal/raspberrypi_40pins_connector.dtsi b/boards/arm/wio_terminal/raspberrypi_40pins_connector.dtsi new file mode 100644 index 000000000000..75ed89e635e6 --- /dev/null +++ b/boards/arm/wio_terminal/raspberrypi_40pins_connector.dtsi @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Joel Guittet + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + raspberrypi_header: raspberrypi_header { + compatible = "raspberrypi-40pins-header"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <0 0 &porta 17 0>, /* I2C1_SDA */ + <1 0 &porta 16 0>, /* I2C1_SCL */ + <2 0 &portb 14 0>, /* GPCLK0 */ + <3 0 &portb 26 0>, /* TXD */ + <4 0 &portb 27 0>, /* RXD */ + <5 0 &porta 2 0>, /* DAC0 */ + <6 0 &portb 16 0>, /* I2S_BLCK */ + <7 0 &portb 8 0>, /* A0/D0 */ + <8 0 &portb 9 0>, /* A1/D1 */ + <9 0 &porta 7 0>, /* A2/D2 */ + <10 0 &portb 4 0>, /* A3/D3 */ + <11 0 &portb 2 0>, /* SPI_MOSI */ + <12 0 &portb 0 0>, /* SPI_MISO */ + <13 0 &portb 5 0>, /* A4/D4 */ + <14 0 &portb 3 0>, /* SPI_SCK */ + <15 0 &portb 1 0>, /* SPI_CS */ + <16 0 &porta 5 0>, /* DAC1 */ + <17 0 &porta 13 0>, /* I2C0_SDA */ + <18 0 &porta 12 0>, /* I2C0_SCL */ + <19 0 &portb 12 0>, /* GPCLK1 */ + <20 0 &portb 13 0>, /* GPCLK2 */ + <21 0 &portb 6 0>, /* A5/D5 */ + <22 0 &porta 4 0>, /* A6/D6 */ + <23 0 &porta 20 0>, /* I2S_LRCLK */ + <24 0 &portb 7 0>, /* A7/D7 */ + <25 0 &porta 6 0>, /* A8/D8 */ + <26 0 &porta 21 0>, /* I2S_SDIN */ + <27 0 &porta 22 0>; /* I2S_SDOUT */ + }; +}; + +raspberrypi_serial: &sercom2 {}; +raspberrypi_i2c0: &sercom4 {}; +raspberrypi_i2c1: &sercom3 {}; +raspberrypi_spi: &sercom5 {}; diff --git a/boards/arm/wio_terminal/wio_terminal.dts b/boards/arm/wio_terminal/wio_terminal.dts index 85d48dc6989f..377c296b6202 100644 --- a/boards/arm/wio_terminal/wio_terminal.dts +++ b/boards/arm/wio_terminal/wio_terminal.dts @@ -6,6 +6,7 @@ /dts-v1/; #include #include "wio_terminal-pinctrl.dtsi" +#include "raspberrypi_40pins_connector.dtsi" #include / { From 0e93ffc8e372c6e14e78ba59eaefe6bcd32d0907 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Thu, 9 Mar 2023 23:44:07 +0000 Subject: [PATCH 0261/1906] samples: hash_map: Add newlib filter to samples.yaml Not all toolchains support newlib so tests that require newlib need to have a filter to we don't try and build those tests on those testcases. Add the following to samples.yaml to handle the issue: filter: TOOLCHAIN_HAS_NEWLIB == 1 Signed-off-by: Kumar Gala --- samples/basic/hash_map/sample.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/samples/basic/hash_map/sample.yaml b/samples/basic/hash_map/sample.yaml index 12c3ede3c1e4..0ba16fe1fc21 100644 --- a/samples/basic/hash_map/sample.yaml +++ b/samples/basic/hash_map/sample.yaml @@ -31,16 +31,19 @@ tests: - CONFIG_SYS_HASH_FUNC32_CHOICE_DJB2=y # Newlib libraries.hash_map.newlib.separate_chaining.djb2: + filter: TOOLCHAIN_HAS_NEWLIB == 1 extra_configs: - CONFIG_NEWLIB_LIBC=y - CONFIG_SYS_HASH_MAP_CHOICE_SC=y - CONFIG_SYS_HASH_FUNC32_CHOICE_DJB2=y libraries.hash_map.newlib.open_addressing.djb2: + filter: TOOLCHAIN_HAS_NEWLIB == 1 extra_configs: - CONFIG_NEWLIB_LIBC=y - CONFIG_SYS_HASH_MAP_CHOICE_OA_LP=y - CONFIG_SYS_HASH_FUNC32_CHOICE_DJB2=y libraries.hash_map.newlib.cxx_unordered_map.djb2: + filter: TOOLCHAIN_HAS_NEWLIB == 1 extra_configs: - CONFIG_NEWLIB_LIBC=y - CONFIG_SYS_HASH_MAP_CHOICE_CXX=y From 0342deb5d930b59b3d15fa84256ecd3ed4643c76 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Wed, 15 Mar 2023 16:40:43 +0000 Subject: [PATCH 0262/1906] Bluetooth: Mesh: Fix compiler warning When building with an LLVM toolchain get the following warning: bluetooth/mesh/pb_adv.c:774:4: error: expression which evaluates to zero treated as a null pointer constant of type 'void *' [-Werror,-Wnon-literal-null-conversion] PROV_BEARER_LINK_STATUS_SUCCESS); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fix by adding a cast to (void *). Signed-off-by: Kumar Gala --- subsys/bluetooth/mesh/pb_adv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/pb_adv.c b/subsys/bluetooth/mesh/pb_adv.c index 562e8bf88193..899e7c3a2fd2 100644 --- a/subsys/bluetooth/mesh/pb_adv.c +++ b/subsys/bluetooth/mesh/pb_adv.c @@ -771,7 +771,7 @@ static void link_open(struct prov_rx *rx, struct net_buf_simple *buf) /* Ignore errors, message will be attempted again if we keep receiving link open: */ (void)bearer_ctl_send_unacked( ctl_buf_create(LINK_ACK, NULL, 0, RETRANSMITS_ACK), - PROV_BEARER_LINK_STATUS_SUCCESS); + (void *)PROV_BEARER_LINK_STATUS_SUCCESS); return; } @@ -786,7 +786,7 @@ static void link_open(struct prov_rx *rx, struct net_buf_simple *buf) err = bearer_ctl_send_unacked( ctl_buf_create(LINK_ACK, NULL, 0, RETRANSMITS_ACK), - PROV_BEARER_LINK_STATUS_SUCCESS); + (void *)PROV_BEARER_LINK_STATUS_SUCCESS); if (err) { reset_adv_link(); return; From f18ae82f960ab74dd8d9d5a38172a76be82a8638 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Wed, 15 Mar 2023 17:55:09 +0000 Subject: [PATCH 0263/1906] oneapi: disable use of libirc when building C++ When building with C++ the icx compiler will try to utilize optimized versions of memset/memcpy that are provided as part of libirc. However libirc also has dependencies on things likes getenv/setenv, etc that are expect in a linux host environment. So disable use of libirc via compiler flag -no-intel-lib=libirc. Signed-off-by: Kumar Gala --- cmake/compiler/icx/target.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/compiler/icx/target.cmake b/cmake/compiler/icx/target.cmake index 028d9a21e8fb..b72af1600aca 100644 --- a/cmake/compiler/icx/target.cmake +++ b/cmake/compiler/icx/target.cmake @@ -40,9 +40,9 @@ foreach(isystem_include_dir ${NOSTDINC}) endforeach() if(CONFIG_64BIT) - string(APPEND TOOLCHAIN_C_FLAGS "-m64") + list(APPEND TOOLCHAIN_C_FLAGS "-m64") else() - string(APPEND TOOLCHAIN_C_FLAGS "-m32") + list(APPEND TOOLCHAIN_C_FLAGS "-m32") endif() @@ -67,3 +67,7 @@ string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") macro(toolchain_cc_nostdinc) zephyr_compile_options( -nostdinc) endmacro() + +if(CONFIG_CPP) + list(APPEND TOOLCHAIN_C_FLAGS "-no-intel-lib=libirc") +endif() From f2d1757df735503a5504b28c367fd2f419b5d6ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20S=C3=A6ther?= Date: Wed, 15 Mar 2023 13:39:43 +0100 Subject: [PATCH 0264/1906] samples: bluetooth: BTHome sensor template bugfix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code for humidity was wrong. Signed-off-by: Ole Sæther --- samples/bluetooth/bthome_sensor_template/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/bluetooth/bthome_sensor_template/src/main.c b/samples/bluetooth/bthome_sensor_template/src/main.c index 77ccf1e78eb3..fcfa5103a6fb 100644 --- a/samples/bluetooth/bthome_sensor_template/src/main.c +++ b/samples/bluetooth/bthome_sensor_template/src/main.c @@ -23,7 +23,7 @@ static uint8_t service_data[SERVICE_DATA_LEN] = { 0x02, /* Temperature */ 0xc4, /* Low byte */ 0x00, /* High byte */ - 0x00, /* Humidity */ + 0x03, /* Humidity */ 0xbf, /* 50.55% low byte*/ 0x13, /* 50.55% high byte*/ }; From 94ae33c20a7374cc09f338b3e6928de88779b435 Mon Sep 17 00:00:00 2001 From: Tim Lin Date: Wed, 15 Mar 2023 16:41:46 +0800 Subject: [PATCH 0265/1906] ITE: soc/riscv/ite: policy: Add minimum residency time to enter sleep Adding this condition will limit the minimum residency time to enter sleep mode. This will fix tests in test\kernel\sleep\usleep.c causing longer than expected test times due to going into sleep mode with no time limit. Signed-off-by: Tim Lin --- soc/riscv/riscv-ite/common/policy.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/soc/riscv/riscv-ite/common/policy.c b/soc/riscv/riscv-ite/common/policy.c index ded3c071b944..597442d8000b 100644 --- a/soc/riscv/riscv-ite/common/policy.c +++ b/soc/riscv/riscv-ite/common/policy.c @@ -17,6 +17,7 @@ __weak const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t tic for (int16_t i = (int16_t)num_cpu_states - 1; i >= 0; i--) { const struct pm_state_info *state = &cpu_states[i]; + uint32_t min_residency; /* check if there is a lock on state + substate */ if (pm_policy_state_lock_is_active( @@ -24,7 +25,14 @@ __weak const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t tic continue; } - return state; + min_residency = k_us_to_ticks_ceil32(state->min_residency_us); + /* + * The tick interval for the system to enter sleep mode needs + * to be longer than or equal to the minimum residency. + */ + if (ticks >= min_residency) { + return state; + } } return NULL; From 5879d2d6c174509c3d569b05eddab68c31d3634d Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 9 Mar 2023 22:45:18 -0500 Subject: [PATCH 0266/1906] sched: minor time slicing cleanup Make sliceable() the actual condition for a sliceable thread. Avoid creating a slice timeout for non sliceable threads. Always reset slice_expired even if the next thread is not sliceable. Fold slice_expired_locked() into z_time_slice() to avoid the hidden unlock/lock. Change `curr` to `thread` as this is not necessarily the current thread (yet) being set. Make variables static. Signed-off-by: Nicolas Pitre --- kernel/sched.c | 103 +++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 59 deletions(-) diff --git a/kernel/sched.c b/kernel/sched.c index 1abfea2e6794..c3ee06cc0f2b 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -414,30 +414,45 @@ static void flag_ipi(void) static int slice_ticks; static int slice_max_prio; -struct _timeout slice_timeouts[CONFIG_MP_MAX_NUM_CPUS]; -bool slice_expired[CONFIG_MP_MAX_NUM_CPUS]; +static struct _timeout slice_timeouts[CONFIG_MP_MAX_NUM_CPUS]; +static bool slice_expired[CONFIG_MP_MAX_NUM_CPUS]; -static inline int slice_time(struct k_thread *curr) +#ifdef CONFIG_SWAP_NONATOMIC +/* If z_swap() isn't atomic, then it's possible for a timer interrupt + * to try to timeslice away _current after it has already pended + * itself but before the corresponding context switch. Treat that as + * a noop condition in z_time_slice(). + */ +static struct k_thread *pending_current; +#endif + +static inline int slice_time(struct k_thread *thread) { int ret = slice_ticks; #ifdef CONFIG_TIMESLICE_PER_THREAD - if (curr->base.slice_ticks != 0) { - ret = curr->base.slice_ticks; + if (thread->base.slice_ticks != 0) { + ret = thread->base.slice_ticks; } #endif return ret; } -#ifdef CONFIG_SWAP_NONATOMIC -/* If z_swap() isn't atomic, then it's possible for a timer interrupt - * to try to timeslice away _current after it has already pended - * itself but before the corresponding context switch. Treat that as - * a noop condition in z_time_slice(). - */ -static struct k_thread *pending_current; +static inline bool sliceable(struct k_thread *thread) +{ + bool ret = is_preempt(thread) + && slice_time(thread) != 0 + && !z_is_prio_higher(thread->base.prio, slice_max_prio) + && !z_is_thread_prevented_from_running(thread) + && !z_is_idle_thread_object(thread); + +#ifdef CONFIG_TIMESLICE_PER_THREAD + ret |= thread->base.slice_ticks != 0; #endif + return ret; +} + static void slice_timeout(struct _timeout *t) { int cpu = ARRAY_INDEX(slice_timeouts, t); @@ -458,8 +473,8 @@ void z_reset_time_slice(struct k_thread *curr) int cpu = _current_cpu->id; z_abort_timeout(&slice_timeouts[cpu]); - if (slice_time(curr) != 0) { - slice_expired[cpu] = false; + slice_expired[cpu] = false; + if (sliceable(curr)) { z_add_timeout(&slice_timeouts[cpu], slice_timeout, K_TICKS(slice_time(curr) - 1)); } @@ -492,63 +507,33 @@ void k_thread_time_slice_set(struct k_thread *th, int32_t slice_ticks, } #endif -static inline bool sliceable(struct k_thread *thread) -{ - bool ret = is_preempt(thread) - && !z_is_thread_prevented_from_running(thread) - && !z_is_prio_higher(thread->base.prio, slice_max_prio) - && !z_is_idle_thread_object(thread); - -#ifdef CONFIG_TIMESLICE_PER_THREAD - ret |= thread->base.slice_ticks != 0; -#endif - - return ret; -} - -static k_spinlock_key_t slice_expired_locked(k_spinlock_key_t sched_lock_key) -{ - struct k_thread *curr = _current; - -#ifdef CONFIG_TIMESLICE_PER_THREAD - if (curr->base.slice_expired) { - k_spin_unlock(&sched_spinlock, sched_lock_key); - curr->base.slice_expired(curr, curr->base.slice_data); - sched_lock_key = k_spin_lock(&sched_spinlock); - } -#endif - if (!z_is_thread_prevented_from_running(curr)) { - move_thread_to_end_of_prio_q(curr); - } - z_reset_time_slice(curr); - - return sched_lock_key; -} - /* Called out of each timer interrupt */ void z_time_slice(void) { k_spinlock_key_t key = k_spin_lock(&sched_spinlock); + struct k_thread *curr = _current; #ifdef CONFIG_SWAP_NONATOMIC - if (pending_current == _current) { - z_reset_time_slice(_current); + if (pending_current == curr) { + z_reset_time_slice(curr); k_spin_unlock(&sched_spinlock, key); return; } pending_current = NULL; #endif - if (slice_time(_current) && sliceable(_current)) { - if (slice_expired[_current_cpu->id]) { - /* Note: this will (if so enabled) internally - * drop and reacquire the scheduler lock - * around the callback! Don't put anything - * after this line that requires - * synchronization. - */ - key = slice_expired_locked(key); + if (slice_expired[_current_cpu->id] && sliceable(curr)) { +#ifdef CONFIG_TIMESLICE_PER_THREAD + if (curr->base.slice_expired) { + k_spin_unlock(&sched_spinlock, key); + curr->base.slice_expired(curr, curr->base.slice_data); + key = k_spin_lock(&sched_spinlock); + } +#endif + if (!z_is_thread_prevented_from_running(curr)) { + move_thread_to_end_of_prio_q(curr); } + z_reset_time_slice(curr); } k_spin_unlock(&sched_spinlock, key); } @@ -1582,7 +1567,7 @@ void z_sched_ipi(void) #endif #ifdef CONFIG_TIMESLICING - if (slice_time(_current) && sliceable(_current)) { + if (sliceable(_current)) { z_time_slice(); } #endif From b1fe487bb1d8354271d09e5202796fddf822eb46 Mon Sep 17 00:00:00 2001 From: Nirosharn Amarasinghe Date: Mon, 20 Feb 2023 14:20:05 +0100 Subject: [PATCH 0267/1906] Bluetooth: controller: Release of padding PDUs for framed production Implemented: -- Released framed padding PDUs when data received in SDUs for a given event do not fully utilise BN. Signed-off-by: Nirosharn Amarasinghe --- subsys/bluetooth/controller/ll_sw/isoal.c | 77 +++++++++++++++++++---- 1 file changed, 65 insertions(+), 12 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/isoal.c b/subsys/bluetooth/controller/ll_sw/isoal.c index 88b5767167d3..1a44e20a2647 100644 --- a/subsys/bluetooth/controller/ll_sw/isoal.c +++ b/subsys/bluetooth/controller/ll_sw/isoal.c @@ -250,14 +250,14 @@ isoal_status_t isoal_sink_create( */ if (role == BT_CONN_ROLE_PERIPHERAL) { isoal_global.sink_state[*hdl].session.latency_unframed = - stream_sync_delay + ((flush_timeout - 1) * iso_interval_us); + stream_sync_delay + ((flush_timeout - 1UL) * iso_interval_us); isoal_global.sink_state[*hdl].session.latency_framed = stream_sync_delay + sdu_interval + (flush_timeout * iso_interval_us); } else if (role == BT_CONN_ROLE_CENTRAL) { isoal_global.sink_state[*hdl].session.latency_unframed = stream_sync_delay - group_sync_delay - - (((iso_interval_us / sdu_interval) - 1) * iso_interval_us); + (((iso_interval_us / sdu_interval) - 1UL) * iso_interval_us); isoal_global.sink_state[*hdl].session.latency_framed = stream_sync_delay - group_sync_delay; @@ -921,7 +921,7 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, seq_err = (meta->payload_number != (sp->prev_pdu_id + 1)); } - end_of_pdu = ((uint8_t *) pdu_meta->pdu->payload) + pdu_meta->pdu->len - 1; + end_of_pdu = ((uint8_t *) pdu_meta->pdu->payload) + pdu_meta->pdu->len - 1UL; seg_hdr = (pdu_err || seq_err || pdu_padding) ? NULL : (struct pdu_iso_sdu_sh *) pdu_meta->pdu->payload; @@ -1064,7 +1064,7 @@ static isoal_status_t isoal_rx_framed_consume(struct isoal_sink *sink, if (((uint8_t *) seg_hdr) > end_of_pdu) { seg_hdr = NULL; } else if (isoal_check_seg_header(seg_hdr, - (uint8_t)(end_of_pdu + 1 - ((uint8_t *) seg_hdr))) == + (uint8_t)(end_of_pdu + 1UL - ((uint8_t *) seg_hdr))) == ISOAL_SDU_STATUS_LOST_DATA) { seg_err = true; seg_hdr = NULL; @@ -1457,10 +1457,17 @@ static isoal_status_t isoal_tx_pdu_emit(const struct isoal_source *source_ctx, return status; } -/* Allocates a new PDU only if the previous PDU was emitted */ +/** + * Allocates a new PDU only if the previous PDU was emitted + * @param[in] source ISO-AL source reference + * @param[in] tx_sdu SDU fragment to be transmitted (can be NULL) + * @return Error status of operation + */ static isoal_status_t isoal_tx_allocate_pdu(struct isoal_source *source, const struct isoal_sdu_tx *tx_sdu) { + ARG_UNUSED(tx_sdu); + struct isoal_source_session *session; struct isoal_pdu_production *pp; struct isoal_pdu_produced *pdu; @@ -2050,16 +2057,15 @@ static isoal_status_t isoal_tx_framed_produce(struct isoal_source *source, err |= err_emit; - /* TODO: Send padding PDU(s) if required - * - * BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL: + /* BT Core V5.3 : Vol 6 Low Energy Controller : Part G IS0-AL: * 2 ISOAL Features : * Padding is required when the data does not add up to the * configured number of PDUs that are specified in the BN * parameter per CIS or BIS event. * * When padding PDUs as opposed to null PDUs are required for - * framed production is not clear. + * framed production is not clear. Padding PDUs will be released + * on the next event prepare trigger. */ padding_pdu = false; zero_length_sdu = false; @@ -2080,16 +2086,22 @@ static isoal_status_t isoal_tx_framed_event_prepare_handle(isoal_source_handle_t { struct isoal_source_session *session; struct isoal_pdu_production *pp; + uint64_t first_event_payload; struct isoal_source *source; uint64_t last_event_payload; + isoal_status_t err_alloc; + bool release_padding; isoal_status_t err; err = ISOAL_STATUS_OK; + err_alloc = ISOAL_STATUS_OK; + release_padding = false; source = &isoal_global.source_state[source_hdl]; session = &source->session; pp = &source->pdu_production; - last_event_payload = (session->burst_number * (event_count + 1)) - 1; + first_event_payload = (session->burst_number * event_count); + last_event_payload = (session->burst_number * (event_count + 1ULL)) - 1ULL; if (pp->pdu_available > 0 && pp->payload_number <= last_event_payload) { @@ -2097,8 +2109,49 @@ static isoal_status_t isoal_tx_framed_event_prepare_handle(isoal_source_handle_t err = isoal_tx_try_emit_pdu(source, true, PDU_BIS_LLID_FRAMED); } - if (pp->payload_number < last_event_payload + 1) { - pp->payload_number = last_event_payload + 1; + if (pp->mode != ISOAL_PRODUCTION_MODE_DISABLED) { + /* BT Core V5.3 : Vol 6 Low Energy Controller : + * Part G IS0-AL: + * + * 2 ISOAL Features : + * Padding is required when the data does not add up to the + * configured number of PDUs that are specified in the BN + * parameter per CIS or BIS event. + * + * There is some lack of clarity in the specifications as to why + * padding PDUs should be used as opposed to null PDUs. However + * if a payload is not available, the LL must default to waiting + * for the flush timeout before it can proceed to the next + * payload. + * + * This means a loss of retransmission capacity for future + * payloads that could exist. Sending padding PDUs will prevent + * this loss while not resulting in additional SDUs on the + * receiver. However it does incur the allocation and handling + * overhead on the transmitter. + * + * As an interpretation of the specification, padding PDUs will + * only be released if an SDU has been received in the current + * event. + */ + if (pp->payload_number > first_event_payload) { + release_padding = true; + } + } + + if (release_padding) { + while (!err && !err_alloc && (pp->payload_number < last_event_payload + 1ULL)) { + err_alloc = isoal_tx_allocate_pdu(source, NULL); + + err = isoal_tx_try_emit_pdu(source, true, PDU_BIS_LLID_FRAMED); + } + } + + /* Not possible to recover if allocation or emit fails here*/ + LL_ASSERT(!(err || err_alloc)); + + if (pp->payload_number < last_event_payload + 1ULL) { + pp->payload_number = last_event_payload + 1ULL; } return err; From 52db7907001127b430b64dcc54a3fc99685f2d30 Mon Sep 17 00:00:00 2001 From: Nirosharn Amarasinghe Date: Tue, 28 Feb 2023 12:34:26 +0100 Subject: [PATCH 0268/1906] tests: bluetooth: controller: release of padding PDUs for framed prod. Implemented tests to check release of framed padding PDUs as the end of the event. Signed-off-by: Nirosharn Amarasinghe --- .../ctrl_isoal/src/isoal_test_common.h | 4 + .../ctrl_isoal/src/sub_sets/isoal_test_tx.c | 727 +++++++++++++++++- 2 files changed, 728 insertions(+), 3 deletions(-) diff --git a/tests/bluetooth/ctrl_isoal/src/isoal_test_common.h b/tests/bluetooth/ctrl_isoal/src/isoal_test_common.h index b15da3c4c0d0..aa38109112a2 100644 --- a/tests/bluetooth/ctrl_isoal/src/isoal_test_common.h +++ b/tests/bluetooth/ctrl_isoal/src/isoal_test_common.h @@ -51,6 +51,10 @@ #define COLLATED_RX_SDU_INFO(_non_buf, _buf) (_non_buf) #endif /* ISOAL_CONFIG_BUFFER_RX_SDUS_ENABLE */ +/* Maximum PDU payload for given number of PDUs */ +#define MAX_FRAMED_PDU_PAYLOAD(_pdus) \ + (TEST_TX_PDU_PAYLOAD_MAX * _pdus) - \ + ((PDU_ISO_SEG_HDR_SIZE * _pdus) + PDU_ISO_SEG_TIMEOFFSET_SIZE) struct rx_pdu_meta_buffer { struct isoal_pdu_rx pdu_meta; diff --git a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c index 10971a12cd6e..e042812cd4a1 100644 --- a/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c +++ b/tests/bluetooth/ctrl_isoal/src/sub_sets/isoal_test_tx.c @@ -10,6 +10,11 @@ */ +/* Each segment header in a test would usually be written to when it is first + * inserted and again when the segment is finalized. + */ +#define EXPECTED_SEG_HDR_WRITES (2) + /*------------------ PDU Allocation Callback ---------------------------------*/ /* Fake function */ FAKE_VALUE_FUNC(isoal_status_t, source_pdu_alloc_test, struct isoal_pdu_buffer*); @@ -4396,8 +4401,543 @@ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu) */ ZTEST(test_tx_framed, test_tx_framed_2_sdu_3_frag_4_pdu_padding) { - PRINT("Framed padding not implemented.\n"); - ztest_test_skip(); + const uint8_t number_of_pdus = 2; + const uint8_t number_of_sdu_frags = 3; + const uint8_t testdata_size_max = MAX_FRAMED_PDU_PAYLOAD(number_of_pdus); + const uint8_t number_of_seg_hdr_buf = EXPECTED_SEG_HDR_WRITES * number_of_pdus; + + struct tx_pdu_meta_buffer tx_pdu_meta_buf[number_of_pdus]; + struct pdu_iso_sdu_sh seg_hdr[number_of_seg_hdr_buf]; + struct isoal_pdu_buffer pdu_buffer[number_of_pdus]; + struct tx_sdu_frag_buffer tx_sdu_frag_buf; + uint8_t testdata[testdata_size_max]; + isoal_source_handle_t source_hdl; + isoal_sdu_len_t sdu_total_size; + isoal_pdu_len_t pdu_write_size; + uint32_t stream_sync_delay; + uint64_t sdu_packet_number; + uint32_t group_sync_delay; + uint8_t iso_interval_int; + uint64_t payload_number; + uint32_t sdu_timestamp; + uint16_t testdata_indx; + uint16_t testdata_size; + uint16_t pdu_write_loc; + uint16_t sdu_read_loc; + uint64_t event_number; + uint32_t sdu_interval; + uint8_t sdu_fragments; + uint16_t pdu_hdr_loc; + uint32_t ref_point; + isoal_status_t err; + uint8_t max_octets; + uint8_t role; + uint8_t BN; + uint8_t FT; + + /* Settings */ + role = BT_CONN_ROLE_PERIPHERAL; + iso_interval_int = 2; + sdu_interval = CONN_INT_UNIT_US + 50; + max_octets = TEST_TX_PDU_PAYLOAD_MAX + 5; + BN = 6; + FT = 1; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + + /* SDU 1 Frag 1 ------------------------------------------------------*/ + isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); + isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]); + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + init_test_data_buffer(testdata, testdata_size_max); + (void)memset(&seg_hdr, 0, sizeof(seg_hdr)); + pdu_buffer[0].handle = (void *)&tx_pdu_meta_buf[0].node_tx; + pdu_buffer[0].pdu = (struct pdu_iso *)tx_pdu_meta_buf[0].node_tx.pdu; + pdu_buffer[0].size = TEST_TX_PDU_PAYLOAD_MAX; + pdu_buffer[1].handle = (void *)&tx_pdu_meta_buf[1].node_tx; + pdu_buffer[1].pdu = (struct pdu_iso *)tx_pdu_meta_buf[1].node_tx.pdu; + pdu_buffer[1].size = TEST_TX_PDU_PAYLOAD_MAX; + sdu_packet_number = 2000; + event_number = 2000; + sdu_timestamp = 9249; + ref_point = 9249 + (iso_interval_int * CONN_INT_UNIT_US) - 50; + sdu_total_size = testdata_size_max; + testdata_indx = 0; + testdata_size = testdata_size_max / number_of_sdu_frags; + sdu_fragments = 0; + + source_hdl = basic_tx_test_setup(0xADAD, /* Handle */ + role, /* Role */ + true, /* Framed */ + BN, /* BN */ + FT, /* FT */ + max_octets, /* max_octets */ + sdu_interval, /* SDU Interval */ + iso_interval_int, /* ISO Interval */ + stream_sync_delay, /* Stream Sync Delay */ + group_sync_delay); /* Group Sync Delay */ + + isoal_test_create_sdu_fagment(BT_ISO_START, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_total_size, + sdu_packet_number, + sdu_timestamp, + ref_point, + event_number, + &tx_sdu_frag_buf.sdu_tx); + + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]); + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]); + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]); + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]); + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]); + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]); + PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK); + PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK); + PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK); + PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK); + + err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test segmentation (Black Box) */ + /* Valid PDUs */ + /* PDU 1 */ + payload_number = event_number * BN; + seg_hdr[0].sc = 0; + seg_hdr[0].cmplt = 0; + seg_hdr[0].timeoffset = ref_point - sdu_timestamp; + seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE; + pdu_hdr_loc = 0; + pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE; + sdu_read_loc = 0; + pdu_write_size = (testdata_size_max / number_of_sdu_frags) + pdu_write_loc; + sdu_fragments++; + + ZASSERT_PDU_WRITE_TEST(history[0], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[0], + (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)); + + ZASSERT_PDU_WRITE_TEST(history[1], + pdu_buffer[0], + pdu_write_loc, + &testdata[sdu_read_loc], + (pdu_write_size - pdu_write_loc)); + + seg_hdr[1] = seg_hdr[0]; + seg_hdr[1].len += (pdu_write_size - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[2], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[1], + PDU_ISO_SEG_HDR_SIZE); + + /* PDU should not be emitted */ + ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* SDU 1 Frag 2 ------------------------------------------------------*/ + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + sdu_timestamp += 10; + testdata_indx += testdata_size; + testdata_size += testdata_size_max / number_of_sdu_frags; + + isoal_test_create_sdu_fagment(BT_ISO_CONT, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_total_size, + sdu_packet_number, + sdu_timestamp, + ref_point, + event_number, + &tx_sdu_frag_buf.sdu_tx); + + err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test segmentation (Black Box) */ + /* Valid PDUs */ + /* PDU 1 */ + pdu_write_loc = pdu_write_size; + pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX; + sdu_read_loc = testdata_indx; + + ZASSERT_PDU_WRITE_TEST(history[3], + pdu_buffer[0], + pdu_write_loc, + &testdata[sdu_read_loc], + (pdu_write_size - pdu_write_loc)); + + /* PDU should not be allocated */ + + seg_hdr[1].len += (pdu_write_size - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[4], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[1], + PDU_ISO_SEG_HDR_SIZE); + + ZASSERT_PDU_EMIT_TEST(history[0], + &tx_pdu_meta_buf[0].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_size, + isoal_global.source_state[source_hdl].session.handle); + + /* PDU 2 */ + payload_number++; + seg_hdr[2].sc = 1; + seg_hdr[2].cmplt = 0; + seg_hdr[2].timeoffset = 0; + seg_hdr[2].len = 0; + sdu_read_loc = (pdu_write_size - pdu_write_loc) + testdata_indx; + pdu_write_size = testdata_size - testdata_indx - (pdu_write_size - pdu_write_loc) + + PDU_ISO_SEG_HDR_SIZE; + pdu_hdr_loc = 0; + pdu_write_loc = PDU_ISO_SEG_HDR_SIZE; + sdu_fragments = 1; + + ZASSERT_PDU_WRITE_TEST(history[5], + pdu_buffer[1], + pdu_hdr_loc, + &seg_hdr[2], + PDU_ISO_SEG_HDR_SIZE); + + ZASSERT_PDU_WRITE_TEST(history[6], + pdu_buffer[1], + pdu_write_loc, + &testdata[sdu_read_loc], + (pdu_write_size - pdu_write_loc)); + + seg_hdr[3] = seg_hdr[2]; + seg_hdr[3].len += (pdu_write_size - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[7], + pdu_buffer[1], + pdu_hdr_loc, + &seg_hdr[3], + PDU_ISO_SEG_HDR_SIZE); + + /* PDU should not be emitted */ + ZASSERT_PDU_EMIT_TEST_CALL_COUNT(1); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* SDU 1 Frag 3 ------------------------------------------------------*/ + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + sdu_timestamp += 10; + testdata_indx = testdata_size; + testdata_size = testdata_size_max; + + isoal_test_create_sdu_fagment(BT_ISO_END, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_total_size, + sdu_packet_number, + sdu_timestamp, + ref_point, + event_number, + &tx_sdu_frag_buf.sdu_tx); + + err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test segmentation (Black Box) */ + /* Valid PDUs */ + /* PDU 2 */ + pdu_write_loc = pdu_write_size; + pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX; + sdu_read_loc = testdata_indx; + sdu_fragments++; + + /* PDU should not be allocated */ + + ZASSERT_PDU_WRITE_TEST(history[8], + pdu_buffer[1], + pdu_write_loc, + &testdata[sdu_read_loc], + (pdu_write_size - pdu_write_loc)); + + seg_hdr[3].cmplt = 1; + seg_hdr[3].len += (pdu_write_size - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[9], + pdu_buffer[1], + pdu_hdr_loc, + &seg_hdr[3], + PDU_ISO_SEG_HDR_SIZE); + + ZASSERT_PDU_EMIT_TEST(history[1], + &tx_pdu_meta_buf[1].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_size, + isoal_global.source_state[source_hdl].session.handle); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* SDU 2 Frag 1 ------------------------------------------------------*/ + isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); + isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]); + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + sdu_packet_number++; + event_number = 2000; + sdu_timestamp = 9249 + sdu_interval; + ref_point = 9249 + (iso_interval_int * CONN_INT_UNIT_US) - 50; + sdu_total_size = testdata_size_max; + testdata_indx = 0; + testdata_size = testdata_size_max / number_of_sdu_frags; + sdu_fragments = 0; + + isoal_test_create_sdu_fagment(BT_ISO_START, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_total_size, + sdu_packet_number, + sdu_timestamp, + ref_point, + event_number, + &tx_sdu_frag_buf.sdu_tx); + + err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test segmentation (Black Box) */ + /* Valid PDUs */ + /* PDU 3 */ + payload_number++; + seg_hdr[0].sc = 0; + seg_hdr[0].cmplt = 0; + seg_hdr[0].timeoffset = ref_point - sdu_timestamp; + seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE; + pdu_hdr_loc = 0; + pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE; + sdu_read_loc = 0; + pdu_write_size = (testdata_size_max / number_of_sdu_frags) + pdu_write_loc; + sdu_fragments++; + + ZASSERT_PDU_WRITE_TEST(history[10], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[0], + (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)); + + ZASSERT_PDU_WRITE_TEST(history[11], + pdu_buffer[0], + pdu_write_loc, + &testdata[sdu_read_loc], + (pdu_write_size - pdu_write_loc)); + + seg_hdr[1] = seg_hdr[0]; + seg_hdr[1].len += (pdu_write_size - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[12], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[1], + PDU_ISO_SEG_HDR_SIZE); + + /* PDU should not be emitted */ + ZASSERT_PDU_EMIT_TEST_CALL_COUNT(2); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* SDU 2 Frag 2 ------------------------------------------------------*/ + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + sdu_timestamp += 10; + testdata_indx += testdata_size; + testdata_size += testdata_size_max / number_of_sdu_frags; + + isoal_test_create_sdu_fagment(BT_ISO_CONT, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_total_size, + sdu_packet_number, + sdu_timestamp, + ref_point, + event_number, + &tx_sdu_frag_buf.sdu_tx); + + err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test segmentation (Black Box) */ + /* Valid PDUs */ + /* PDU 3 */ + pdu_write_loc = pdu_write_size; + pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX; + sdu_read_loc = testdata_indx; + + /* PDU should not be allocated */ + + ZASSERT_PDU_WRITE_TEST(history[13], + pdu_buffer[0], + pdu_write_loc, + &testdata[sdu_read_loc], + (pdu_write_size - pdu_write_loc)); + + seg_hdr[1].len += (pdu_write_size - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[14], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[1], + PDU_ISO_SEG_HDR_SIZE); + + ZASSERT_PDU_EMIT_TEST(history[2], + &tx_pdu_meta_buf[0].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_size, + isoal_global.source_state[source_hdl].session.handle); + + /* PDU 4 */ + payload_number++; + seg_hdr[2].sc = 1; + seg_hdr[2].cmplt = 0; + seg_hdr[2].timeoffset = 0; + seg_hdr[2].len = 0; + sdu_read_loc = (pdu_write_size - pdu_write_loc) + testdata_indx; + pdu_write_size = testdata_size - testdata_indx - (pdu_write_size - pdu_write_loc) + + PDU_ISO_SEG_HDR_SIZE; + pdu_hdr_loc = 0; + pdu_write_loc = PDU_ISO_SEG_HDR_SIZE; + sdu_fragments = 1; + + ZASSERT_PDU_WRITE_TEST(history[15], + pdu_buffer[1], + pdu_hdr_loc, + &seg_hdr[2], + PDU_ISO_SEG_HDR_SIZE); + + ZASSERT_PDU_WRITE_TEST(history[16], + pdu_buffer[1], + pdu_write_loc, + &testdata[sdu_read_loc], + (pdu_write_size - pdu_write_loc)); + + seg_hdr[3] = seg_hdr[2]; + seg_hdr[3].len += (pdu_write_size - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[17], + pdu_buffer[1], + pdu_hdr_loc, + &seg_hdr[3], + PDU_ISO_SEG_HDR_SIZE); + /* PDU should not be emitted */ + ZASSERT_PDU_EMIT_TEST_CALL_COUNT(3); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* SDU 2 Frag 3 ------------------------------------------------------*/ + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + sdu_timestamp += 10; + testdata_indx = testdata_size; + testdata_size = testdata_size_max; + + isoal_test_create_sdu_fagment(BT_ISO_END, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_total_size, + sdu_packet_number, + sdu_timestamp, + ref_point, + event_number, + &tx_sdu_frag_buf.sdu_tx); + + err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test segmentation (Black Box) */ + /* Valid PDUs */ + /* PDU 4 */ + pdu_write_loc = pdu_write_size; + pdu_write_size = TEST_TX_PDU_PAYLOAD_MAX; + sdu_read_loc = testdata_indx; + sdu_fragments++; + + /* PDU should not be allocated */ + ZASSERT_PDU_ALLOC_TEST_CALL_COUNT(4); + + ZASSERT_PDU_WRITE_TEST(history[18], + pdu_buffer[1], + pdu_write_loc, + &testdata[sdu_read_loc], + (pdu_write_size - pdu_write_loc)); + + seg_hdr[3].cmplt = 1; + seg_hdr[3].len += (pdu_write_size - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[19], + pdu_buffer[1], + pdu_hdr_loc, + &seg_hdr[3], + PDU_ISO_SEG_HDR_SIZE); + + ZASSERT_PDU_EMIT_TEST(history[3], + &tx_pdu_meta_buf[1].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_size, + isoal_global.source_state[source_hdl].session.handle); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* Send Event Timeout ----------------------------------------------- */ + isoal_tx_event_prepare(source_hdl, event_number); + + /* PDU 5 (Padding) */ + payload_number++; + pdu_write_size = 0; + sdu_fragments = 0; + + /* PDU should not be written to */ + ZASSERT_PDU_WRITE_TEST_CALL_COUNT(20); + + ZASSERT_PDU_EMIT_TEST(history[4], + &tx_pdu_meta_buf[0].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_size, + isoal_global.source_state[source_hdl].session.handle); + + /* PDU 6 (Padding) */ + payload_number++; + sdu_fragments = 0; + + /* PDU should not be written to */ + ZASSERT_PDU_WRITE_TEST_CALL_COUNT(20); + + ZASSERT_PDU_EMIT_TEST(history[5], + &tx_pdu_meta_buf[1].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_size, + isoal_global.source_state[source_hdl].session.handle); } /** @@ -5009,7 +5549,7 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_maxPDU) iso_interval_int = 1; sdu_interval = CONN_INT_UNIT_US + 50; max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; - BN = 3; + BN = 1; FT = 1; stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; @@ -5103,6 +5643,187 @@ ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_maxPDU) isoal_global.source_state[source_hdl].session.handle); } + +/** + * Test Suite : TX framed SDU segmentation + * + * Tests segmentation of a single SDU contained in a single fragment + * into a single PDU followed by padding + */ +ZTEST(test_tx_framed, test_tx_framed_1_zero_sdu_1_frag_1_pdu_padding) +{ + struct tx_pdu_meta_buffer tx_pdu_meta_buf[3]; + struct tx_sdu_frag_buffer tx_sdu_frag_buf; + struct isoal_pdu_buffer pdu_buffer[3]; + isoal_source_handle_t source_hdl; + struct pdu_iso_sdu_sh seg_hdr[2]; + isoal_sdu_len_t sdu_total_size; + isoal_pdu_len_t pdu_write_size; + uint32_t stream_sync_delay; + uint64_t sdu_packet_number; + uint32_t group_sync_delay; + uint8_t iso_interval_int; + uint64_t payload_number; + uint32_t sdu_timestamp; + uint16_t testdata_indx; + uint16_t testdata_size; + uint16_t pdu_write_loc; + uint16_t sdu_read_loc; + uint64_t event_number; + uint32_t sdu_interval; + uint8_t sdu_fragments; + uint16_t pdu_hdr_loc; + uint8_t testdata[1]; + uint32_t ref_point; + isoal_status_t err; + uint8_t max_octets; + uint8_t role; + uint8_t BN; + uint8_t FT; + + /* Settings */ + role = BT_CONN_ROLE_PERIPHERAL; + iso_interval_int = 1; + sdu_interval = CONN_INT_UNIT_US + 50; + max_octets = TEST_TX_PDU_PAYLOAD_MAX - 5; + BN = 3; + FT = 1; + stream_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 200; + group_sync_delay = (iso_interval_int * CONN_INT_UNIT_US) - 50; + + /* SDU Frag 1 --------------------------------------------------------*/ + isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[0]); + isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[1]); + isoal_test_init_tx_pdu_buffer(&tx_pdu_meta_buf[2]); + isoal_test_init_tx_sdu_buffer(&tx_sdu_frag_buf); + init_test_data_buffer(testdata, 1); + (void)memset(seg_hdr, 0, sizeof(seg_hdr)); + pdu_buffer[0].handle = (void *)&tx_pdu_meta_buf[0].node_tx; + pdu_buffer[0].pdu = (struct pdu_iso *)tx_pdu_meta_buf[0].node_tx.pdu; + pdu_buffer[0].size = TEST_TX_PDU_PAYLOAD_MAX; + pdu_buffer[1].handle = (void *)&tx_pdu_meta_buf[1].node_tx; + pdu_buffer[1].pdu = (struct pdu_iso *)tx_pdu_meta_buf[1].node_tx.pdu; + pdu_buffer[1].size = TEST_TX_PDU_PAYLOAD_MAX; + pdu_buffer[2].handle = (void *)&tx_pdu_meta_buf[2].node_tx; + pdu_buffer[2].pdu = (struct pdu_iso *)tx_pdu_meta_buf[2].node_tx.pdu; + pdu_buffer[2].size = TEST_TX_PDU_PAYLOAD_MAX; + sdu_packet_number = 2000; + event_number = 2000; + sdu_timestamp = 9249; + ref_point = sdu_timestamp + (iso_interval_int * CONN_INT_UNIT_US) - 50; + sdu_total_size = + TEST_TX_PDU_PAYLOAD_MAX - 5 - (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE); + testdata_indx = 0; + testdata_size = 0; + payload_number = event_number * BN; + + source_hdl = basic_tx_test_setup(0xADAD, /* Handle */ + role, /* Role */ + true, /* Framed */ + BN, /* BN */ + FT, /* FT */ + max_octets, /* max_octets */ + sdu_interval, /* SDU Interval */ + iso_interval_int, /* ISO Interval */ + stream_sync_delay, /* Stream Sync Delay */ + group_sync_delay); /* Group Sync Delay */ + + isoal_test_create_sdu_fagment(BT_ISO_SINGLE, + &testdata[testdata_indx], + (testdata_size - testdata_indx), + sdu_total_size, + sdu_packet_number, + sdu_timestamp, + ref_point, + event_number, + &tx_sdu_frag_buf.sdu_tx); + + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[0]); + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[1]); + SET_NEXT_PDU_ALLOC_BUFFER(&pdu_buffer[2]); + PDU_ALLOC_TEST_RETURNS(ISOAL_STATUS_OK); + PDU_WRITE_TEST_RETURNS(ISOAL_STATUS_OK); + PDU_EMIT_TEST_RETURNS(ISOAL_STATUS_OK); + PDU_RELEASE_TEST_RETURNS(ISOAL_STATUS_OK); + + err = isoal_tx_sdu_fragment(source_hdl, &tx_sdu_frag_buf.sdu_tx); + + zassert_equal(err, ISOAL_STATUS_OK, "err = 0x%02x", err); + + /* Test segmentation (Black Box) */ + /* Valid PDUs */ + /* PDU 1 */ + seg_hdr[0].sc = 0; + seg_hdr[0].cmplt = 0; + seg_hdr[0].timeoffset = ref_point - sdu_timestamp; + seg_hdr[0].len = PDU_ISO_SEG_TIMEOFFSET_SIZE; + pdu_hdr_loc = 0; + pdu_write_loc = PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE; + sdu_read_loc = 0; + pdu_write_size = pdu_write_loc; + sdu_fragments = 1; + + ZASSERT_PDU_WRITE_TEST(history[0], + pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[0], + (PDU_ISO_SEG_HDR_SIZE + PDU_ISO_SEG_TIMEOFFSET_SIZE)); + + seg_hdr[1] = seg_hdr[0]; + seg_hdr[1].cmplt = 1; + seg_hdr[1].len += (pdu_write_size - pdu_write_loc); + + ZASSERT_PDU_WRITE_TEST(history[1], pdu_buffer[0], + pdu_hdr_loc, + &seg_hdr[1], + PDU_ISO_SEG_HDR_SIZE); + + /* PDU should not be emitted */ + ZASSERT_PDU_EMIT_TEST_CALL_COUNT(0); + + /* PDU release not expected (No Error) */ + ZASSERT_PDU_RELEASE_TEST_CALL_COUNT(0); + + /* Send Event Timeout ----------------------------------------------- */ + isoal_tx_event_prepare(source_hdl, event_number); + + ZASSERT_PDU_EMIT_TEST(history[0], &tx_pdu_meta_buf[0].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_size, + isoal_global.source_state[source_hdl].session.handle); + + /* PDU 2 (Padding) */ + payload_number++; + pdu_write_size = 0; + sdu_fragments = 0; + + /* PDU should not be written to */ + ZASSERT_PDU_WRITE_TEST_CALL_COUNT(2); + + ZASSERT_PDU_EMIT_TEST(history[1], &tx_pdu_meta_buf[1].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_size, + isoal_global.source_state[source_hdl].session.handle); + + /* PDU 3 (Padding) */ + payload_number++; + sdu_fragments = 0; + + /* PDU should not be written to */ + ZASSERT_PDU_WRITE_TEST_CALL_COUNT(2); + + ZASSERT_PDU_EMIT_TEST(history[2], &tx_pdu_meta_buf[2].node_tx, + payload_number, + sdu_fragments, + PDU_BIS_LLID_FRAMED, + pdu_write_size, + isoal_global.source_state[source_hdl].session.handle); +} + /** * Test Suite : TX framed SDU segmentation * From a2057cde3c49fd7a183eb0d43ef2e49f81e21b65 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 3 Jan 2023 15:15:29 +0100 Subject: [PATCH 0269/1906] Bluetooth: Audio: Fixed naming of invalid length ASCS response The "Invalid Length" response code was called truncated, which does not match the spec definition. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/ascs.c | 4 ++-- subsys/bluetooth/audio/ascs_internal.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index cb638aacb7bf..8c08bfdee013 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -889,7 +889,7 @@ static void ascs_cp_rsp_add(uint8_t id, uint8_t op, uint8_t code, * set to 0xFF. */ case BT_ASCS_RSP_NOT_SUPPORTED: - case BT_ASCS_RSP_TRUNCATED: + case BT_ASCS_RSP_INVALID_LENGTH: rsp->num_ase = 0xff; break; default: @@ -2649,7 +2649,7 @@ static ssize_t ascs_cp_write(struct bt_conn *conn, } if (ret == BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN)) { - ascs_cp_rsp_add(0, req->op, BT_ASCS_RSP_TRUNCATED, + ascs_cp_rsp_add(0, req->op, BT_ASCS_RSP_INVALID_LENGTH, BT_ASCS_REASON_NONE); } diff --git a/subsys/bluetooth/audio/ascs_internal.h b/subsys/bluetooth/audio/ascs_internal.h index 698bf25f3ed0..57e44d414ea7 100644 --- a/subsys/bluetooth/audio/ascs_internal.h +++ b/subsys/bluetooth/audio/ascs_internal.h @@ -10,7 +10,7 @@ /* Response Status Code */ #define BT_ASCS_RSP_SUCCESS 0x00 #define BT_ASCS_RSP_NOT_SUPPORTED 0x01 -#define BT_ASCS_RSP_TRUNCATED 0x02 +#define BT_ASCS_RSP_INVALID_LENGTH 0x02 #define BT_ASCS_RSP_INVALID_ASE 0x03 #define BT_ASCS_RSP_INVALID_ASE_STATE 0x04 #define BT_ASCS_RSP_INVALID_DIR 0x05 @@ -299,8 +299,8 @@ static inline const char *bt_ascs_rsp_str(uint8_t code) return "Success"; case BT_ASCS_RSP_NOT_SUPPORTED: return "Unsupported Opcode"; - case BT_ASCS_RSP_TRUNCATED: - return "Truncated Operation"; + case BT_ASCS_RSP_INVALID_LENGTH: + return "Invalid Length"; case BT_ASCS_RSP_INVALID_ASE: return "Invalid ASE_ID"; case BT_ASCS_RSP_INVALID_ASE_STATE: From 68fa04788a4962264271cd9234745ef180374065 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 3 Jan 2023 16:03:30 +0100 Subject: [PATCH 0270/1906] Bluetooth: Audio: Add unicast client cp notify callbacks Add callbacks for control point notifications sent by the unicast server. These will allow the upper layers to know if and why a specific operation failed. Signed-off-by: Emil Gydesen --- include/zephyr/bluetooth/audio/bap.h | 173 ++++++++++++++++++ subsys/bluetooth/audio/ascs.c | 183 +++++++++----------- subsys/bluetooth/audio/ascs_internal.h | 81 +++------ subsys/bluetooth/audio/bap_unicast_client.c | 101 ++++++++++- 4 files changed, 378 insertions(+), 160 deletions(-) diff --git a/include/zephyr/bluetooth/audio/bap.h b/include/zephyr/bluetooth/audio/bap.h index 076bfd8a26b2..f94a2db744de 100644 --- a/include/zephyr/bluetooth/audio/bap.h +++ b/include/zephyr/bluetooth/audio/bap.h @@ -83,6 +83,77 @@ enum bt_bap_ep_state { BT_BAP_EP_STATE_RELEASING = 0x06, }; +/** + * @brief Response Status Code + * + * These are sent by the server to the client when a stream operation is + * requested. + */ +enum bt_bap_ascs_rsp_code { + /** Server completed operation successfully */ + BT_BAP_ASCS_RSP_CODE_SUCCESS = 0x00, + /** Server did not support operation by client */ + BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED = 0x01, + /** Server rejected due to invalid operation length */ + BT_BAP_ASCS_RSP_CODE_INVALID_LENGTH = 0x02, + /** Invalid ASE ID */ + BT_BAP_ASCS_RSP_CODE_INVALID_ASE = 0x03, + /** Invalid ASE state */ + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE = 0x04, + /** Invalid operation for direction */ + BT_BAP_ASCS_RSP_CODE_INVALID_DIR = 0x05, + /** Capabilities not supported by server */ + BT_BAP_ASCS_RSP_CODE_CAP_UNSUPPORTED = 0x06, + /** Configuration parameters not supported by server */ + BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED = 0x07, + /** Configuration parameters rejected by server */ + BT_BAP_ASCS_RSP_CODE_CONF_REJECTED = 0x08, + /** Invalid Configuration parameters */ + BT_BAP_ASCS_RSP_CODE_CONF_INVALID = 0x09, + /** Unsupported metadata */ + BT_BAP_ASCS_RSP_CODE_METADATA_UNSUPPORTED = 0x0a, + /** Metadata rejected by server */ + BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED = 0x0b, + /** Invalid metadata */ + BT_BAP_ASCS_RSP_CODE_METADATA_INVALID = 0x0c, + /** Server has insufficient resources */ + BT_BAP_ASCS_RSP_CODE_NO_MEM = 0x0d, + /** Unspecified error */ + BT_BAP_ASCS_RSP_CODE_UNSPECIFIED = 0x0e, +}; + +/** + * @brief Response Reasons + * + * These are used if the @ref bt_bap_ascs_rsp_code value is + * @ref BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED, @ref BT_BAP_ASCS_RSP_CODE_CONF_REJECTED or + * @ref BT_BAP_ASCS_RSP_CODE_CONF_INVALID. + */ +enum bt_bap_ascs_reason { + /** No reason */ + BT_BAP_ASCS_REASON_NONE = 0x00, + /** Codec ID */ + BT_BAP_ASCS_REASON_CODEC = 0x01, + /** Codec configuration */ + BT_BAP_ASCS_REASON_CODEC_DATA = 0x02, + /** SDU interval */ + BT_BAP_ASCS_REASON_INTERVAL = 0x03, + /** Framing */ + BT_BAP_ASCS_REASON_FRAMING = 0x04, + /** PHY */ + BT_BAP_ASCS_REASON_PHY = 0x05, + /** Maximum SDU size*/ + BT_BAP_ASCS_REASON_SDU = 0x06, + /** RTN */ + BT_BAP_ASCS_REASON_RTN = 0x07, + /** Max transport latency */ + BT_BAP_ASCS_REASON_LATENCY = 0x08, + /** Presendation delay */ + BT_BAP_ASCS_REASON_PD = 0x09, + /** Invalid CIS mapping */ + BT_BAP_ASCS_REASON_CIS = 0x0a, +}; + /** @brief Abstract Audio Broadcast Source structure. */ struct bt_bap_broadcast_source; @@ -801,6 +872,108 @@ struct bt_bap_unicast_client_cb { */ void (*available_contexts)(struct bt_conn *conn, enum bt_audio_context snk_ctx, enum bt_audio_context src_ctx); + + /** + * @brief Callback function for bt_bap_stream_config() and bt_bap_stream_reconfig(). + * + * Called when the codec configure operation is completed on the server. + * + * @param stream Stream the operation was performed on. + * @param rsp_code Response code. + * @param reason Reason code. + */ + void (*config)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason); + + /** + * @brief Callback function for bt_bap_stream_qos(). + * + * Called when the QoS configure operation is completed on the server. + * This will be called for each stream in the group that was being QoS + * configured. + * + * @param stream Stream the operation was performed on. + * @param rsp_code Response code. + * @param reason Reason code. + */ + void (*qos)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason); + + /** + * @brief Callback function for bt_bap_stream_enable(). + * + * Called when the enable operation is completed on the server. + * + * @param stream Stream the operation was performed on. + * @param rsp_code Response code. + * @param reason Reason code. + */ + void (*enable)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason); + + /** + * @brief Callback function for bt_bap_stream_start(). + * + * Called when the start operation is completed on the server. This will + * only be called if the stream supplied to bt_bap_stream_start() is + * for a @ref BT_AUDIO_DIR_SOURCE endpoint. + * + * @param stream Stream the operation was performed on. + * @param rsp_code Response code. + * @param reason Reason code. + */ + void (*start)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason); + + /** + * @brief Callback function for bt_bap_stream_stop(). + * + * Called when the stop operation is completed on the server. This will + * only be called if the stream supplied to bt_bap_stream_stop() is + * for a @ref BT_AUDIO_DIR_SOURCE endpoint. + * + * @param stream Stream the operation was performed on. + * @param rsp_code Response code. + * @param reason Reason code. + */ + void (*stop)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason); + + /** + * @brief Callback function for bt_bap_stream_disable(). + * + * Called when the disable operation is completed on the server. + * + * @param stream Stream the operation was performed on. + * @param rsp_code Response code. + * @param reason Reason code. + */ + void (*disable)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason); + + /** + * @brief Callback function for bt_bap_stream_metadata(). + * + * Called when the metadata operation is completed on the server. + * + * @param stream Stream the operation was performed on. + * @param rsp_code Response code. + * @param reason Reason code. + */ + void (*metadata)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason); + + /** + * @brief Callback function for bt_bap_stream_release(). + * + * Called when the release operation is completed on the server. + * + * @param stream Stream the operation was performed on. + * @param rsp_code Response code. + * @param reason Reason code. + */ + void (*release)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason); }; /** diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 8c08bfdee013..c42a7e4337b6 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -888,8 +888,8 @@ static void ascs_cp_rsp_add(uint8_t id, uint8_t op, uint8_t code, /* If the Response_Code value is 0x01 or 0x02, Number_of_ASEs shall be * set to 0xFF. */ - case BT_ASCS_RSP_NOT_SUPPORTED: - case BT_ASCS_RSP_INVALID_LENGTH: + case BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED: + case BT_BAP_ASCS_RSP_CODE_INVALID_LENGTH: rsp->num_ase = 0xff; break; default: @@ -911,67 +911,60 @@ static void ascs_cp_rsp_add_errno(uint8_t id, uint8_t op, int err, switch (err) { case -ENOBUFS: case -ENOMEM: - return ascs_cp_rsp_add(id, op, BT_ASCS_RSP_NO_MEM, - BT_ASCS_REASON_NONE); + return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_NO_MEM, + BT_BAP_ASCS_REASON_NONE); case -EINVAL: switch (op) { case BT_ASCS_CONFIG_OP: /* Fallthrough */ case BT_ASCS_QOS_OP: - return ascs_cp_rsp_add(id, op, - BT_ASCS_RSP_CONF_INVALID, - reason); + return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_CONF_INVALID, reason); case BT_ASCS_ENABLE_OP: /* Fallthrough */ case BT_ASCS_METADATA_OP: - return ascs_cp_rsp_add(id, op, - BT_ASCS_RSP_METADATA_INVALID, + return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_METADATA_INVALID, reason); default: - return ascs_cp_rsp_add(id, op, BT_ASCS_RSP_UNSPECIFIED, - BT_ASCS_REASON_NONE); + return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, + BT_BAP_ASCS_REASON_NONE); } case -ENOTSUP: switch (op) { case BT_ASCS_CONFIG_OP: /* Fallthrough */ case BT_ASCS_QOS_OP: - return ascs_cp_rsp_add(id, op, - BT_ASCS_RSP_CONF_UNSUPPORTED, + return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED, reason); case BT_ASCS_ENABLE_OP: /* Fallthrough */ case BT_ASCS_METADATA_OP: - return ascs_cp_rsp_add(id, op, - BT_ASCS_RSP_METADATA_UNSUPPORTED, + return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_METADATA_UNSUPPORTED, reason); default: - return ascs_cp_rsp_add(id, op, - BT_ASCS_RSP_NOT_SUPPORTED, - BT_ASCS_REASON_NONE); + return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + BT_BAP_ASCS_REASON_NONE); } case -EBADMSG: - return ascs_cp_rsp_add(id, op, BT_ASCS_RSP_INVALID_ASE_STATE, - BT_ASCS_REASON_NONE); + return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, + BT_BAP_ASCS_REASON_NONE); case -EACCES: switch (op) { case BT_ASCS_METADATA_OP: - return ascs_cp_rsp_add(id, op, - BT_ASCS_RSP_METADATA_REJECTED, + return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED, reason); default: - return ascs_cp_rsp_add(id, op, BT_ASCS_RSP_UNSPECIFIED, - BT_ASCS_REASON_NONE); + return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, + BT_BAP_ASCS_REASON_NONE); } default: - return ascs_cp_rsp_add(id, op, BT_ASCS_RSP_UNSPECIFIED, - BT_ASCS_REASON_NONE); + return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, + BT_BAP_ASCS_REASON_NONE); } } static void ascs_cp_rsp_success(uint8_t id, uint8_t op) { - ascs_cp_rsp_add(id, op, BT_ASCS_RSP_SUCCESS, BT_ASCS_REASON_NONE); + ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_SUCCESS, BT_BAP_ASCS_REASON_NONE); } static void ase_release(struct bt_ascs_ase *ase) @@ -993,7 +986,7 @@ static void ase_release(struct bt_ascs_ase *ase) if (err) { ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_RELEASE_OP, err, - BT_ASCS_REASON_NONE); + BT_BAP_ASCS_REASON_NONE); return; } @@ -1020,8 +1013,8 @@ static void ase_disable(struct bt_ascs_ase *ase) break; default: LOG_WRN("Invalid operation in state: %s", bt_bap_ep_state_str(ep->status.state)); - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_DISABLE_OP, - -EBADMSG, BT_ASCS_REASON_NONE); + ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_DISABLE_OP, -EBADMSG, + BT_BAP_ASCS_REASON_NONE); return; } @@ -1035,8 +1028,8 @@ static void ase_disable(struct bt_ascs_ase *ase) if (err) { LOG_ERR("Disable failed: %d", err); - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_DISABLE_OP, - err, BT_ASCS_REASON_NONE); + ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_DISABLE_OP, err, + BT_BAP_ASCS_REASON_NONE); return; } @@ -1412,17 +1405,16 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, if (cfg->latency < BT_ASCS_CONFIG_LATENCY_LOW || cfg->latency > BT_ASCS_CONFIG_LATENCY_HIGH) { LOG_WRN("Invalid latency: 0x%02x", cfg->latency); - ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, - BT_ASCS_RSP_CONF_INVALID, - BT_ASCS_REASON_LATENCY); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_CONF_INVALID, + BT_BAP_ASCS_REASON_LATENCY); return 0; } if (cfg->phy < BT_ASCS_CONFIG_PHY_LE_1M || cfg->phy > BT_ASCS_CONFIG_PHY_LE_CODED) { LOG_WRN("Invalid PHY: 0x%02x", cfg->phy); - ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, - BT_ASCS_RSP_CONF_INVALID, BT_ASCS_REASON_PHY); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_CONF_INVALID, + BT_BAP_ASCS_REASON_PHY); return 0; } @@ -1438,7 +1430,7 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, LOG_WRN("Invalid operation in state: %s", bt_bap_ep_state_str(ase->ep.status.state)); ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, - BT_ASCS_RSP_INVALID_ASE_STATE, 0x00); + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, 0x00); return 0; } @@ -1452,9 +1444,8 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, sys_le16_to_cpu(cfg->codec.vid), buf, cfg->cc_len, &ase->ep.codec)) { (void)memcpy(&ase->ep.codec, &codec, sizeof(codec)); - ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, - BT_ASCS_RSP_CONF_INVALID, - BT_ASCS_REASON_CODEC_DATA); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_CONF_INVALID, + BT_BAP_ASCS_REASON_CODEC_DATA); return 0; } @@ -1470,7 +1461,7 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, } if (err != 0) { - uint8_t reason = BT_ASCS_REASON_CODEC_DATA; + uint8_t reason = BT_BAP_ASCS_REASON_CODEC_DATA; LOG_ERR("Reconfig failed: %d", err); @@ -1499,8 +1490,8 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, (void)memcpy(&ase->ep.codec, &codec, sizeof(codec)); ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, - BT_ASCS_RSP_CONF_REJECTED, - BT_ASCS_REASON_CODEC_DATA); + BT_BAP_ASCS_RSP_CODE_CONF_REJECTED, + BT_BAP_ASCS_REASON_CODEC_DATA); return err; } @@ -1620,15 +1611,15 @@ static ssize_t ascs_config(struct bt_ascs *ascs, struct net_buf_simple *buf) if (!cfg->ase || cfg->ase > ASE_COUNT) { LOG_WRN("Invalid ASE ID: %u", cfg->ase); ascs_cp_rsp_add(cfg->ase, BT_ASCS_CONFIG_OP, - BT_ASCS_RSP_INVALID_ASE, 0x00); + BT_BAP_ASCS_RSP_CODE_INVALID_ASE, 0x00); continue; } else { ase = ase_get(ascs, cfg->ase); } if (!ase) { - ascs_cp_rsp_add(cfg->ase, BT_ASCS_CONFIG_OP, - BT_ASCS_RSP_NO_MEM, 0x00); + ascs_cp_rsp_add(cfg->ase, BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_NO_MEM, + 0x00); LOG_WRN("No free ASE found for config ASE ID 0x%02x", cfg->ase); continue; } @@ -1769,26 +1760,26 @@ static void ase_qos(struct bt_ascs_ase *ase, const struct bt_ascs_qos *qos) err = ase_stream_qos(stream, cqos, ase->ascs, cig_id, cis_id); if (err) { - uint8_t reason = BT_ASCS_REASON_NONE; + uint8_t reason = BT_BAP_ASCS_REASON_NONE; LOG_ERR("QoS failed: err %d", err); if (err == -ENOTSUP) { if (cqos->interval == 0) { - reason = BT_ASCS_REASON_INTERVAL; + reason = BT_BAP_ASCS_REASON_INTERVAL; } else if (cqos->framing == 0xff) { - reason = BT_ASCS_REASON_FRAMING; + reason = BT_BAP_ASCS_REASON_FRAMING; } else if (cqos->phy == 0) { - reason = BT_ASCS_REASON_PHY; + reason = BT_BAP_ASCS_REASON_PHY; } else if (cqos->sdu == 0xffff) { - reason = BT_ASCS_REASON_SDU; + reason = BT_BAP_ASCS_REASON_SDU; } else if (cqos->latency == 0) { - reason = BT_ASCS_REASON_LATENCY; + reason = BT_BAP_ASCS_REASON_LATENCY; } else if (cqos->pd == 0) { - reason = BT_ASCS_REASON_PD; + reason = BT_BAP_ASCS_REASON_PD; } } else if (err == -EALREADY) { - reason = BT_ASCS_REASON_CIS; + reason = BT_BAP_ASCS_REASON_CIS; /* FIXME: Ugly workaround to send Response_Code * 0x09 = Invalid Configuration Parameter Value */ @@ -1835,8 +1826,8 @@ static ssize_t ascs_qos(struct bt_ascs *ascs, struct net_buf_simple *buf) LOG_DBG("ase 0x%02x", qos->ase); if (!is_valid_ase_id(qos->ase)) { - ascs_cp_rsp_add(qos->ase, BT_ASCS_QOS_OP, - BT_ASCS_RSP_INVALID_ASE, 0x00); + ascs_cp_rsp_add(qos->ase, BT_ASCS_QOS_OP, BT_BAP_ASCS_RSP_CODE_INVALID_ASE, + 0x00); LOG_WRN("Unknown ase 0x%02x", qos->ase); continue; } @@ -1845,7 +1836,7 @@ static ssize_t ascs_qos(struct bt_ascs *ascs, struct net_buf_simple *buf) if (!ase) { LOG_DBG("Invalid operation for idle ASE"); ascs_cp_rsp_add(qos->ase, BT_ASCS_QOS_OP, - BT_ASCS_RSP_INVALID_ASE_STATE, 0x00); + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, 0x00); continue; } @@ -2061,8 +2052,8 @@ static int ase_metadata(struct bt_ascs_ase *ase, uint8_t op, if (err < 0) { ascs_cp_rsp_add_errno(ASE_ID(ase), op, err, 0x00); } else { - ascs_cp_rsp_add(ASE_ID(ase), op, - BT_ASCS_RSP_METADATA_INVALID, err); + ascs_cp_rsp_add(ASE_ID(ase), op, BT_BAP_ASCS_RSP_CODE_METADATA_INVALID, + err); } return 0; } @@ -2109,8 +2100,7 @@ static int ase_enable(struct bt_ascs_ase *ase, struct bt_ascs_metadata *meta, if (ep->status.state != BT_BAP_EP_STATE_QOS_CONFIGURED) { err = -EBADMSG; LOG_WRN("Invalid operation in state: %s", bt_bap_ep_state_str(ep->status.state)); - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_ENABLE_OP, err, - BT_ASCS_REASON_NONE); + ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_ENABLE_OP, err, BT_BAP_ASCS_REASON_NONE); return err; } @@ -2121,7 +2111,7 @@ static int ase_enable(struct bt_ascs_ase *ase, struct bt_ascs_metadata *meta, err, 0x00); } else { ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_ENABLE_OP, - BT_ASCS_RSP_METADATA_INVALID, err); + BT_BAP_ASCS_RSP_CODE_METADATA_INVALID, err); } return 0; } @@ -2136,8 +2126,7 @@ static int ase_enable(struct bt_ascs_ase *ase, struct bt_ascs_metadata *meta, if (err) { LOG_ERR("Enable rejected: %d", err); - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_ENABLE_OP, err, - BT_ASCS_REASON_NONE); + ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_ENABLE_OP, err, BT_BAP_ASCS_REASON_NONE); return -EFAULT; } @@ -2185,7 +2174,7 @@ static ssize_t ascs_enable(struct bt_ascs *ascs, struct net_buf_simple *buf) if (!is_valid_ase_id(meta->ase)) { ascs_cp_rsp_add(meta->ase, BT_ASCS_ENABLE_OP, - BT_ASCS_RSP_INVALID_ASE, 0x00); + BT_BAP_ASCS_RSP_CODE_INVALID_ASE, 0x00); LOG_WRN("Unknown ase 0x%02x", meta->ase); continue; } @@ -2194,7 +2183,7 @@ static ssize_t ascs_enable(struct bt_ascs *ascs, struct net_buf_simple *buf) if (!ase) { LOG_DBG("Invalid operation for idle ASE"); ascs_cp_rsp_add(meta->ase, BT_ASCS_ENABLE_OP, - BT_ASCS_RSP_INVALID_ASE_STATE, 0x00); + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, 0x00); continue; } @@ -2217,7 +2206,7 @@ static void ase_start(struct bt_ascs_ase *ase) if (ep->status.state != BT_BAP_EP_STATE_ENABLING) { LOG_WRN("Invalid operation in state: %s", bt_bap_ep_state_str(ep->status.state)); ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_START_OP, -EBADMSG, - BT_ASCS_REASON_NONE); + BT_BAP_ASCS_REASON_NONE); return; } @@ -2229,8 +2218,8 @@ static void ase_start(struct bt_ascs_ase *ase) */ if (ep->dir == BT_AUDIO_DIR_SINK) { LOG_WRN("Start failed: invalid operation for Sink"); - ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, - BT_ASCS_RSP_INVALID_DIR, BT_ASCS_REASON_NONE); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, BT_BAP_ASCS_RSP_CODE_INVALID_DIR, + BT_BAP_ASCS_REASON_NONE); return; } else if (ep->iso->chan.state != BT_ISO_STATE_CONNECTED) { /* An ASE may not go into the streaming state unless the CIS @@ -2239,8 +2228,7 @@ static void ase_start(struct bt_ascs_ase *ase) LOG_WRN("Start failed: CIS not connected: %u", ep->iso->chan.state); ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, - BT_ASCS_RSP_INVALID_ASE_STATE, - BT_ASCS_REASON_NONE); + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, BT_BAP_ASCS_REASON_NONE); return; } @@ -2252,8 +2240,7 @@ static void ase_start(struct bt_ascs_ase *ase) if (err) { LOG_ERR("Start failed: %d", err); - ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, err, - BT_ASCS_REASON_NONE); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, err, BT_BAP_ASCS_REASON_NONE); return; } @@ -2295,8 +2282,8 @@ static ssize_t ascs_start(struct bt_ascs *ascs, struct net_buf_simple *buf) LOG_DBG("ase 0x%02x", id); if (!is_valid_ase_id(id)) { - ascs_cp_rsp_add(id, BT_ASCS_START_OP, - BT_ASCS_RSP_INVALID_ASE, 0x00); + ascs_cp_rsp_add(id, BT_ASCS_START_OP, BT_BAP_ASCS_RSP_CODE_INVALID_ASE, + 0x00); LOG_WRN("Unknown ase 0x%02x", id); continue; } @@ -2305,7 +2292,7 @@ static ssize_t ascs_start(struct bt_ascs *ascs, struct net_buf_simple *buf) if (!ase) { LOG_DBG("Invalid operation for idle ASE"); ascs_cp_rsp_add(id, BT_ASCS_START_OP, - BT_ASCS_RSP_INVALID_ASE_STATE, 0x00); + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, 0x00); continue; } @@ -2345,8 +2332,8 @@ static ssize_t ascs_disable(struct bt_ascs *ascs, struct net_buf_simple *buf) LOG_DBG("ase 0x%02x", id); if (!is_valid_ase_id(id)) { - ascs_cp_rsp_add(id, BT_ASCS_DISABLE_OP, - BT_ASCS_RSP_INVALID_ASE, 0x00); + ascs_cp_rsp_add(id, BT_ASCS_DISABLE_OP, BT_BAP_ASCS_RSP_CODE_INVALID_ASE, + 0x00); LOG_WRN("Unknown ase 0x%02x", id); continue; } @@ -2355,7 +2342,7 @@ static ssize_t ascs_disable(struct bt_ascs *ascs, struct net_buf_simple *buf) if (!ase) { LOG_DBG("Invalid operation for idle ASE"); ascs_cp_rsp_add(id, BT_ASCS_DISABLE_OP, - BT_ASCS_RSP_INVALID_ASE_STATE, 0x00); + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, 0x00); continue; } @@ -2383,15 +2370,15 @@ static void ase_stop(struct bt_ascs_ase *ase) */ if (ase->ep.dir == BT_AUDIO_DIR_SINK) { LOG_WRN("Stop failed: invalid operation for Sink"); - ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_STOP_OP, - BT_ASCS_RSP_INVALID_DIR, BT_ASCS_REASON_NONE); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_STOP_OP, BT_BAP_ASCS_RSP_CODE_INVALID_DIR, + BT_BAP_ASCS_REASON_NONE); return; } if (ep->status.state != BT_BAP_EP_STATE_DISABLING) { LOG_WRN("Invalid operation in state: %s", bt_bap_ep_state_str(ep->status.state)); ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_STOP_OP, -EBADMSG, - BT_ASCS_REASON_NONE); + BT_BAP_ASCS_REASON_NONE); return; } @@ -2404,8 +2391,7 @@ static void ase_stop(struct bt_ascs_ase *ase) if (err) { LOG_ERR("Stop failed: %d", err); - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_STOP_OP, err, - BT_ASCS_REASON_NONE); + ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_STOP_OP, err, BT_BAP_ASCS_REASON_NONE); return; } @@ -2455,8 +2441,8 @@ static ssize_t ascs_stop(struct bt_ascs *ascs, struct net_buf_simple *buf) LOG_DBG("ase 0x%02x", id); if (!is_valid_ase_id(id)) { - ascs_cp_rsp_add(id, BT_ASCS_STOP_OP, - BT_ASCS_RSP_INVALID_ASE, 0x00); + ascs_cp_rsp_add(id, BT_ASCS_STOP_OP, BT_BAP_ASCS_RSP_CODE_INVALID_ASE, + 0x00); LOG_WRN("Unknown ase 0x%02x", id); continue; } @@ -2464,8 +2450,8 @@ static ssize_t ascs_stop(struct bt_ascs *ascs, struct net_buf_simple *buf) ase = ase_find(ascs, id); if (!ase) { LOG_DBG("Invalid operation for idle ASE"); - ascs_cp_rsp_add(id, BT_ASCS_STOP_OP, - BT_ASCS_RSP_INVALID_ASE_STATE, 0x00); + ascs_cp_rsp_add(id, BT_ASCS_STOP_OP, BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, + 0x00); continue; } @@ -2512,7 +2498,7 @@ static ssize_t ascs_metadata(struct bt_ascs *ascs, struct net_buf_simple *buf) if (!is_valid_ase_id(meta->ase)) { ascs_cp_rsp_add(meta->ase, BT_ASCS_METADATA_OP, - BT_ASCS_RSP_INVALID_ASE, 0x00); + BT_BAP_ASCS_RSP_CODE_INVALID_ASE, 0x00); LOG_WRN("Unknown ase 0x%02x", meta->ase); continue; } @@ -2521,7 +2507,7 @@ static ssize_t ascs_metadata(struct bt_ascs *ascs, struct net_buf_simple *buf) if (!ase) { LOG_DBG("Invalid operation for idle ASE"); ascs_cp_rsp_add(meta->ase, BT_ASCS_METADATA_OP, - BT_ASCS_RSP_INVALID_ASE_STATE, 0x00); + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, 0x00); continue; } @@ -2561,8 +2547,8 @@ static ssize_t ascs_release(struct bt_ascs *ascs, struct net_buf_simple *buf) LOG_DBG("ase 0x%02x", id); if (!is_valid_ase_id(id)) { - ascs_cp_rsp_add(id, BT_ASCS_RELEASE_OP, - BT_ASCS_RSP_INVALID_ASE, 0x00); + ascs_cp_rsp_add(id, BT_ASCS_RELEASE_OP, BT_BAP_ASCS_RSP_CODE_INVALID_ASE, + 0x00); LOG_WRN("Unknown ase 0x%02x", id); continue; } @@ -2571,7 +2557,7 @@ static ssize_t ascs_release(struct bt_ascs *ascs, struct net_buf_simple *buf) if (!ase) { LOG_DBG("Invalid operation for idle ASE"); ascs_cp_rsp_add(id, BT_ASCS_RELEASE_OP, - BT_ASCS_RSP_INVALID_ASE_STATE, 0x00); + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, 0x00); continue; } @@ -2580,7 +2566,8 @@ static ssize_t ascs_release(struct bt_ascs *ascs, struct net_buf_simple *buf) LOG_WRN("Invalid operation in state: %s", bt_bap_ep_state_str(ase->ep.status.state)); ascs_cp_rsp_add(id, BT_ASCS_RELEASE_OP, - BT_ASCS_RSP_INVALID_ASE_STATE, BT_ASCS_REASON_NONE); + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, + BT_BAP_ASCS_REASON_NONE); continue; } @@ -2643,14 +2630,14 @@ static ssize_t ascs_cp_write(struct bt_conn *conn, ret = ascs_release(ascs, &buf); break; default: - ascs_cp_rsp_add(0x00, req->op, BT_ASCS_RSP_NOT_SUPPORTED, 0); + ascs_cp_rsp_add(0x00, req->op, BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, 0); LOG_DBG("Unknown opcode"); goto respond; } if (ret == BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN)) { - ascs_cp_rsp_add(0, req->op, BT_ASCS_RSP_INVALID_LENGTH, - BT_ASCS_REASON_NONE); + ascs_cp_rsp_add(0, req->op, BT_BAP_ASCS_RSP_CODE_INVALID_LENGTH, + BT_BAP_ASCS_REASON_NONE); } respond: diff --git a/subsys/bluetooth/audio/ascs_internal.h b/subsys/bluetooth/audio/ascs_internal.h index 57e44d414ea7..4cf0f012db71 100644 --- a/subsys/bluetooth/audio/ascs_internal.h +++ b/subsys/bluetooth/audio/ascs_internal.h @@ -7,35 +7,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -/* Response Status Code */ -#define BT_ASCS_RSP_SUCCESS 0x00 -#define BT_ASCS_RSP_NOT_SUPPORTED 0x01 -#define BT_ASCS_RSP_INVALID_LENGTH 0x02 -#define BT_ASCS_RSP_INVALID_ASE 0x03 -#define BT_ASCS_RSP_INVALID_ASE_STATE 0x04 -#define BT_ASCS_RSP_INVALID_DIR 0x05 -#define BT_ASCS_RSP_CAP_UNSUPPORTED 0x06 -#define BT_ASCS_RSP_CONF_UNSUPPORTED 0x07 -#define BT_ASCS_RSP_CONF_REJECTED 0x08 -#define BT_ASCS_RSP_CONF_INVALID 0x09 -#define BT_ASCS_RSP_METADATA_UNSUPPORTED 0x0a -#define BT_ASCS_RSP_METADATA_REJECTED 0x0b -#define BT_ASCS_RSP_METADATA_INVALID 0x0c -#define BT_ASCS_RSP_NO_MEM 0x0d -#define BT_ASCS_RSP_UNSPECIFIED 0x0e - -/* Response Reasons */ -#define BT_ASCS_REASON_NONE 0x00 -#define BT_ASCS_REASON_CODEC 0x01 -#define BT_ASCS_REASON_CODEC_DATA 0x02 -#define BT_ASCS_REASON_INTERVAL 0x03 -#define BT_ASCS_REASON_FRAMING 0x04 -#define BT_ASCS_REASON_PHY 0x05 -#define BT_ASCS_REASON_SDU 0x06 -#define BT_ASCS_REASON_RTN 0x07 -#define BT_ASCS_REASON_LATENCY 0x08 -#define BT_ASCS_REASON_PD 0x09 -#define BT_ASCS_REASON_CIS 0x0a /* Transport QoS Packing */ #define BT_ASCS_QOS_PACKING_SEQ 0x00 @@ -295,35 +266,35 @@ static inline const char *bt_ascs_op_str(uint8_t op) static inline const char *bt_ascs_rsp_str(uint8_t code) { switch (code) { - case BT_ASCS_RSP_SUCCESS: + case BT_BAP_ASCS_RSP_CODE_SUCCESS: return "Success"; - case BT_ASCS_RSP_NOT_SUPPORTED: + case BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED: return "Unsupported Opcode"; - case BT_ASCS_RSP_INVALID_LENGTH: + case BT_BAP_ASCS_RSP_CODE_INVALID_LENGTH: return "Invalid Length"; - case BT_ASCS_RSP_INVALID_ASE: + case BT_BAP_ASCS_RSP_CODE_INVALID_ASE: return "Invalid ASE_ID"; - case BT_ASCS_RSP_INVALID_ASE_STATE: + case BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE: return "Invalid ASE State"; - case BT_ASCS_RSP_INVALID_DIR: + case BT_BAP_ASCS_RSP_CODE_INVALID_DIR: return "Invalid ASE Direction"; - case BT_ASCS_RSP_CAP_UNSUPPORTED: + case BT_BAP_ASCS_RSP_CODE_CAP_UNSUPPORTED: return "Unsupported Capabilities"; - case BT_ASCS_RSP_CONF_UNSUPPORTED: + case BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED: return "Unsupported Configuration Value"; - case BT_ASCS_RSP_CONF_REJECTED: + case BT_BAP_ASCS_RSP_CODE_CONF_REJECTED: return "Rejected Configuration Value"; - case BT_ASCS_RSP_CONF_INVALID: + case BT_BAP_ASCS_RSP_CODE_CONF_INVALID: return "Invalid Configuration Value"; - case BT_ASCS_RSP_METADATA_UNSUPPORTED: + case BT_BAP_ASCS_RSP_CODE_METADATA_UNSUPPORTED: return "Unsupported Metadata"; - case BT_ASCS_RSP_METADATA_REJECTED: + case BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED: return "Rejected Metadata"; - case BT_ASCS_RSP_METADATA_INVALID: + case BT_BAP_ASCS_RSP_CODE_METADATA_INVALID: return "Invalid Metadata"; - case BT_ASCS_RSP_NO_MEM: + case BT_BAP_ASCS_RSP_CODE_NO_MEM: return "Insufficient Resources"; - case BT_ASCS_RSP_UNSPECIFIED: + case BT_BAP_ASCS_RSP_CODE_UNSPECIFIED: return "Unspecified Error"; } @@ -333,27 +304,27 @@ static inline const char *bt_ascs_rsp_str(uint8_t code) static inline const char *bt_ascs_reason_str(uint8_t reason) { switch (reason) { - case BT_ASCS_REASON_NONE: + case BT_BAP_ASCS_REASON_NONE: return "None"; - case BT_ASCS_REASON_CODEC: + case BT_BAP_ASCS_REASON_CODEC: return "Codec ID"; - case BT_ASCS_REASON_CODEC_DATA: + case BT_BAP_ASCS_REASON_CODEC_DATA: return "Codec Specific Configuration"; - case BT_ASCS_REASON_INTERVAL: + case BT_BAP_ASCS_REASON_INTERVAL: return "SDU Interval"; - case BT_ASCS_REASON_FRAMING: + case BT_BAP_ASCS_REASON_FRAMING: return "Framing"; - case BT_ASCS_REASON_PHY: + case BT_BAP_ASCS_REASON_PHY: return "PHY"; - case BT_ASCS_REASON_SDU: + case BT_BAP_ASCS_REASON_SDU: return "Maximum SDU Size"; - case BT_ASCS_REASON_RTN: + case BT_BAP_ASCS_REASON_RTN: return "Retransmission Number"; - case BT_ASCS_REASON_LATENCY: + case BT_BAP_ASCS_REASON_LATENCY: return "Maximum Transport Delay"; - case BT_ASCS_REASON_PD: + case BT_BAP_ASCS_REASON_PD: return "Presentation Delay"; - case BT_ASCS_REASON_CIS: + case BT_BAP_ASCS_REASON_CIS: return "Invalid ASE CIS Mapping"; } diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index 773df93fd9d9..e7bed1e16216 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -170,6 +170,38 @@ static bool unicast_client_can_disconnect_stream(const struct bt_bap_stream *str return false; } +static struct bt_bap_stream *audio_stream_by_ep_id(const struct bt_conn *conn, + uint8_t id) +{ +#if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 || CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 + const uint8_t conn_index = bt_conn_index(conn); +#endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 || \ + * CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 \ + */ + +#if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 + for (size_t i = 0U; i < ARRAY_SIZE(snks[conn_index]); i++) { + const struct bt_bap_unicast_client_ep *client_ep = &snks[conn_index][i]; + + if (client_ep->ep.status.id == id) { + return client_ep->ep.stream; + } + } +#endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 */ + +#if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 + for (size_t i = 0U; i < ARRAY_SIZE(srcs[conn_index]); i++) { + const struct bt_bap_unicast_client_ep *client_ep = &srcs[conn_index][i]; + + if (client_ep->ep.status.id == id) { + return client_ep->ep.stream; + } + } +#endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 */ + + return NULL; +} + static void unicast_client_ep_iso_recv(struct bt_iso_chan *chan, const struct bt_iso_recv_info *info, struct net_buf *buf) { @@ -1192,8 +1224,6 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn, uint16_t length) { struct bt_ascs_cp_rsp *rsp; - int i; - struct net_buf_simple buf; LOG_DBG("conn %p len %u", conn, length); @@ -1213,8 +1243,9 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn, rsp = net_buf_simple_pull_mem(&buf, sizeof(*rsp)); - for (i = 0; i < rsp->num_ase; i++) { + for (uint8_t i = 0U; i < rsp->num_ase; i++) { struct bt_ascs_cp_ase_rsp *ase_rsp; + struct bt_bap_stream *stream; if (buf.len < sizeof(*ase_rsp)) { LOG_ERR("Control Point Notification too small"); @@ -1224,10 +1255,66 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn, ase_rsp = net_buf_simple_pull_mem(&buf, sizeof(*ase_rsp)); LOG_DBG("op %s (0x%02x) id 0x%02x code %s (0x%02x) " - "reason %s (0x%02x)", - bt_ascs_op_str(rsp->op), rsp->op, ase_rsp->id, - bt_ascs_rsp_str(ase_rsp->code), ase_rsp->code, - bt_ascs_reason_str(ase_rsp->reason), ase_rsp->reason); + "reason %s (0x%02x)", bt_ascs_op_str(rsp->op), rsp->op, + ase_rsp->id, bt_ascs_rsp_str(ase_rsp->code), + ase_rsp->code, bt_ascs_reason_str(ase_rsp->reason), + ase_rsp->reason); + + if (unicast_client_cbs == NULL) { + continue; + } + + stream = audio_stream_by_ep_id(conn, ase_rsp->id); + if (stream == NULL) { + LOG_DBG("Could not find stream by id %u", ase_rsp->id); + continue; + } + + switch (rsp->op) { + case BT_ASCS_CONFIG_OP: + if (unicast_client_cbs->config != NULL) { + unicast_client_cbs->config(stream, ase_rsp->code, ase_rsp->reason); + } + break; + case BT_ASCS_QOS_OP: + if (unicast_client_cbs->qos != NULL) { + unicast_client_cbs->qos(stream, ase_rsp->code, ase_rsp->reason); + } + break; + case BT_ASCS_ENABLE_OP: + if (unicast_client_cbs->enable != NULL) { + unicast_client_cbs->enable(stream, ase_rsp->code, ase_rsp->reason); + } + break; + case BT_ASCS_START_OP: + if (unicast_client_cbs->start != NULL) { + unicast_client_cbs->start(stream, ase_rsp->code, ase_rsp->reason); + } + break; + case BT_ASCS_DISABLE_OP: + if (unicast_client_cbs->disable != NULL) { + unicast_client_cbs->disable(stream, ase_rsp->code, ase_rsp->reason); + } + break; + case BT_ASCS_STOP_OP: + if (unicast_client_cbs->stop != NULL) { + unicast_client_cbs->stop(stream, ase_rsp->code, ase_rsp->reason); + } + break; + case BT_ASCS_METADATA_OP: + if (unicast_client_cbs->metadata != NULL) { + unicast_client_cbs->metadata(stream, ase_rsp->code, + ase_rsp->reason); + } + break; + case BT_ASCS_RELEASE_OP: + if (unicast_client_cbs->release != NULL) { + unicast_client_cbs->release(stream, ase_rsp->code, ase_rsp->reason); + } + break; + default: + break; + } } return BT_GATT_ITER_CONTINUE; From 88644a775c7bb10c7cb1deb7b4a121e2b06d19ba Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 4 Jan 2023 11:29:13 +0100 Subject: [PATCH 0271/1906] Bluetooth: Audio: Shell: Add unicast client operation callbacks Add the unicast client operation callbacks to the shell, simply printing the values sent by the server. Signed-off-by: Emil Gydesen --- subsys/bluetooth/shell/bap.c | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/subsys/bluetooth/shell/bap.c b/subsys/bluetooth/shell/bap.c index c0300d11e309..2e45b31e09bf 100644 --- a/subsys/bluetooth/shell/bap.c +++ b/subsys/bluetooth/shell/bap.c @@ -840,9 +840,73 @@ static void available_contexts_cb(struct bt_conn *conn, shell_print(ctx_shell, "snk ctx %u src ctx %u\n", snk_ctx, src_ctx); } +static void config_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + shell_print(ctx_shell, "stream %p config operation rsp_code %u reason %u", + stream, rsp_code, reason); +} + +static void qos_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + shell_print(ctx_shell, "stream %p qos operation rsp_code %u reason %u", + stream, rsp_code, reason); +} + +static void enable_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + shell_print(ctx_shell, "stream %p enable operation rsp_code %u reason %u", + stream, rsp_code, reason); +} + +static void start_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + shell_print(ctx_shell, "stream %p start operation rsp_code %u reason %u", + stream, rsp_code, reason); +} + +static void stop_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + shell_print(ctx_shell, "stream %p stop operation rsp_code %u reason %u", + stream, rsp_code, reason); +} + +static void disable_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + shell_print(ctx_shell, "stream %p disable operation rsp_code %u reason %u", + stream, rsp_code, reason); +} + +static void metadata_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + shell_print(ctx_shell, "stream %p metadata operation rsp_code %u reason %u", + stream, rsp_code, reason); +} + +static void release_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + shell_print(ctx_shell, "stream %p release operation rsp_code %u reason %u", + stream, rsp_code, reason); +} + const struct bt_bap_unicast_client_cb unicast_client_cbs = { .location = unicast_client_location_cb, .available_contexts = available_contexts_cb, + .config = config_cb, + .qos = qos_cb, + .enable = enable_cb, + .start = start_cb, + .stop = stop_cb, + .disable = disable_cb, + .metadata = metadata_cb, + .release = release_cb, }; static int cmd_discover(const struct shell *sh, size_t argc, char *argv[]) From db7bb2c9b17e9bc98e5f4d7b6a7241f1d73e1363 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 4 Jan 2023 12:05:44 +0100 Subject: [PATCH 0272/1906] tests: Bluetooth: Audio: Add unicast client CP notification bsim testing Adds waiting for the control point operation callbacks in the unicast client BSIM test, ensuring that the callbacks work, but also testing that the server is correctly sending them. Signed-off-by: Emil Gydesen --- .../bsim/audio/src/bap_unicast_client_test.c | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/tests/bluetooth/bsim/audio/src/bap_unicast_client_test.c b/tests/bluetooth/bsim/audio/src/bap_unicast_client_test.c index c6524d1d7ada..bd921f702e0e 100644 --- a/tests/bluetooth/bsim/audio/src/bap_unicast_client_test.c +++ b/tests/bluetooth/bsim/audio/src/bap_unicast_client_test.c @@ -31,6 +31,7 @@ static atomic_t flag_stream_qos_configured; CREATE_FLAG(flag_stream_enabled); CREATE_FLAG(flag_stream_started); CREATE_FLAG(flag_stream_released); +CREATE_FLAG(flag_operation_success); static void stream_configured(struct bt_bap_stream *stream, const struct bt_codec_qos_pref *pref) @@ -112,9 +113,98 @@ static void available_contexts_cb(struct bt_conn *conn, printk("snk ctx %u src ctx %u\n", snk_ctx, src_ctx); } + +static void config_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + printk("stream %p config operation rsp_code %u reason %u\n", stream, rsp_code, reason); + + if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + SET_FLAG(flag_operation_success); + } +} + +static void qos_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + printk("stream %p qos operation rsp_code %u reason %u\n", stream, rsp_code, reason); + + if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + SET_FLAG(flag_operation_success); + } +} + +static void enable_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + printk("stream %p enable operation rsp_code %u reason %u\n", stream, rsp_code, reason); + + if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + SET_FLAG(flag_operation_success); + } +} + +static void start_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + printk("stream %p start operation rsp_code %u reason %u\n", stream, rsp_code, reason); + + if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + SET_FLAG(flag_operation_success); + } +} + +static void stop_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + printk("stream %p stop operation rsp_code %u reason %u\n", stream, rsp_code, reason); + + if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + SET_FLAG(flag_operation_success); + } +} + +static void disable_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + printk("stream %p disable operation rsp_code %u reason %u\n", stream, rsp_code, reason); + + if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + SET_FLAG(flag_operation_success); + } +} + +static void metadata_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + printk("stream %p metadata operation rsp_code %u reason %u\n", stream, rsp_code, reason); + + if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + SET_FLAG(flag_operation_success); + } +} + +static void release_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, + enum bt_bap_ascs_reason reason) +{ + printk("stream %p release operation rsp_code %u reason %u\n", stream, rsp_code, reason); + + if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + SET_FLAG(flag_operation_success); + } +} + const struct bt_bap_unicast_client_cb unicast_client_cbs = { .location = unicast_client_location_cb, .available_contexts = available_contexts_cb, + .config = config_cb, + .qos = qos_cb, + .enable = enable_cb, + .start = start_cb, + .stop = stop_cb, + .disable = disable_cb, + .metadata = metadata_cb, + .release = release_cb, }; static void add_remote_sink(struct bt_bap_ep *ep, uint8_t index) @@ -267,6 +357,7 @@ static int codec_configure_stream(struct bt_bap_stream *stream, struct bt_bap_ep int err; UNSET_FLAG(flag_stream_codec_configured); + UNSET_FLAG(flag_operation_success); err = bt_bap_stream_config(default_conn, stream, ep, &preset_16_2_1.codec); @@ -276,6 +367,7 @@ static int codec_configure_stream(struct bt_bap_stream *stream, struct bt_bap_ep } WAIT_FOR_FLAG(flag_stream_codec_configured); + WAIT_FOR_FLAG(flag_operation_success); return 0; } @@ -393,6 +485,7 @@ static size_t release_streams(size_t stream_cnt) break; } + UNSET_FLAG(flag_operation_success); UNSET_FLAG(flag_stream_released); err = bt_bap_stream_release(&g_streams[i]); @@ -401,6 +494,7 @@ static size_t release_streams(size_t stream_cnt) return 0; } + WAIT_FOR_FLAG(flag_operation_success); WAIT_FOR_FLAG(flag_stream_released); } From f7cf252a8cb6cdff0f06e26db1c08fab6f1c2840 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 14 Feb 2023 13:44:24 +0100 Subject: [PATCH 0273/1906] Bluetooth: Audio: Add special handling of release cp notification When releasing a stream as the unicast client, we may get either the ASE state notification with state idle or the control point notification first. If we get the ASE state notification first, we pretend we get the CP notification first, and call the release callback. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/bap_unicast_client.c | 39 +++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index e7bed1e16216..655ae1158920 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -47,6 +47,9 @@ struct bt_bap_unicast_client_ep { struct bt_gatt_subscribe_params subscribe; struct bt_gatt_discover_params discover; struct bt_bap_ep ep; + + /* Bool to help handle different order of CP and ASE notification when releasing */ + bool release_requested; }; static const struct bt_uuid *snk_uuid = BT_UUID_PACS_SNK; @@ -514,6 +517,8 @@ static struct bt_bap_ep *unicast_client_ep_get(struct bt_conn *conn, enum bt_aud static void unicast_client_ep_idle_state(struct bt_bap_ep *ep) { + struct bt_bap_unicast_client_ep *client_ep = + CONTAINER_OF(ep, struct bt_bap_unicast_client_ep, ep); struct bt_bap_stream *stream = ep->stream; const struct bt_bap_stream_ops *ops; @@ -538,6 +543,19 @@ static void unicast_client_ep_idle_state(struct bt_bap_ep *ep) bt_bap_stream_reset(stream); /* Notify upper layer */ + if (client_ep->release_requested) { + /* In case that we get the idle state notification before the CP notification we + * trigger the CP callback now, as after this we won't be able to find the stream + * by the ASE ID + */ + client_ep->release_requested = false; + + if (unicast_client_cbs->release != NULL) { + unicast_client_cbs->release(stream, BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); + } + } + ops = stream->ops; if (ops != NULL && ops->released != NULL) { ops->released(stream); @@ -1244,6 +1262,7 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn, rsp = net_buf_simple_pull_mem(&buf, sizeof(*rsp)); for (uint8_t i = 0U; i < rsp->num_ase; i++) { + struct bt_bap_unicast_client_ep *client_ep; struct bt_ascs_cp_ase_rsp *ase_rsp; struct bt_bap_stream *stream; @@ -1270,6 +1289,8 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn, continue; } + client_ep = CONTAINER_OF(stream->ep, struct bt_bap_unicast_client_ep, ep); + switch (rsp->op) { case BT_ASCS_CONFIG_OP: if (unicast_client_cbs->config != NULL) { @@ -1308,7 +1329,12 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn, } break; case BT_ASCS_RELEASE_OP: - if (unicast_client_cbs->release != NULL) { + if (client_ep->release_requested) { + /* Set to false to only handle the callback here */ + client_ep->release_requested = false; + } + + if (unicast_client_cbs->config != NULL) { unicast_client_cbs->release(stream, ase_rsp->code, ase_rsp->reason); } break; @@ -2699,6 +2725,7 @@ int bt_bap_unicast_client_stop(struct bt_bap_stream *stream) int bt_bap_unicast_client_release(struct bt_bap_stream *stream) { + struct bt_bap_unicast_client_ep *client_ep; struct bt_bap_ep *ep = stream->ep; struct net_buf_simple *buf; struct bt_ascs_disable_op *req; @@ -2731,7 +2758,15 @@ int bt_bap_unicast_client_release(struct bt_bap_stream *stream) return 0; } - return bt_bap_unicast_client_ep_send(stream->conn, ep, buf); + err = bt_bap_unicast_client_ep_send(stream->conn, ep, buf); + if (err != 0) { + return err; + } + + client_ep = CONTAINER_OF(ep, struct bt_bap_unicast_client_ep, ep); + client_ep->release_requested = true; + + return 0; } static uint8_t unicast_client_cp_discover_func(struct bt_conn *conn, From b525db221c3430c66b882393965de4ee4388fb02 Mon Sep 17 00:00:00 2001 From: Wolfgang Puffitsch Date: Fri, 10 Mar 2023 12:51:28 +0100 Subject: [PATCH 0274/1906] Bluetooth: controller: Avoid the use of weak functions for ISO data path Avoid the use of weak functions and call the respective functions only if vendor-specific data path is supported. The weak dummy functions will not implement the desired behavior anyway. This change makes it explicit that these functions need to be implemented by the vendor. Signed-off-by: Wolfgang Puffitsch --- subsys/bluetooth/controller/hci/hci.c | 12 +++-- subsys/bluetooth/controller/include/ll.h | 1 + .../ll_sw/nordic/ull/ull_iso_vendor.c | 19 +++++++ subsys/bluetooth/controller/ll_sw/nrf.cmake | 2 +- subsys/bluetooth/controller/ll_sw/ull.c | 16 ------ subsys/bluetooth/controller/ll_sw/ull_iso.c | 54 +++---------------- .../controller/ll_sw/ull_iso_internal.h | 16 ++++++ 7 files changed, 51 insertions(+), 69 deletions(-) diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 7b11fd01969a..16d8893f2d07 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -640,10 +640,14 @@ static void configure_data_path(struct net_buf *buf, vs_config = &cmd->vs_config[0]; - status = ll_configure_data_path(cmd->data_path_dir, - cmd->data_path_id, - cmd->vs_config_len, - vs_config); + if (IS_ENABLED(CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH)) { + status = ll_configure_data_path(cmd->data_path_dir, + cmd->data_path_id, + cmd->vs_config_len, + vs_config); + } else { + status = BT_HCI_ERR_INVALID_PARAM; + } rp = hci_cmd_complete(evt, sizeof(*rp)); rp->status = status; diff --git a/subsys/bluetooth/controller/include/ll.h b/subsys/bluetooth/controller/include/ll.h index bb9396c837b7..1e446ced2c29 100644 --- a/subsys/bluetooth/controller/include/ll.h +++ b/subsys/bluetooth/controller/include/ll.h @@ -164,6 +164,7 @@ uint8_t ll_cis_parameters_test_set(uint8_t cis_id, uint8_t nse, uint16_t c_pdu, uint16_t p_pdu, uint8_t c_phy, uint8_t p_phy, uint8_t c_bn, uint8_t p_bn); +/* Must be implemented by vendor if vendor-specific data path is supported */ uint8_t ll_configure_data_path(uint8_t data_path_dir, uint8_t data_path_id, uint8_t vs_config_len, diff --git a/subsys/bluetooth/controller/ll_sw/nordic/ull/ull_iso_vendor.c b/subsys/bluetooth/controller/ll_sw/nordic/ull/ull_iso_vendor.c index d7073f93906c..ffe57d1b2c1d 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/ull/ull_iso_vendor.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/ull/ull_iso_vendor.c @@ -8,6 +8,8 @@ #include #include +#include "isoal.h" +#include "ull_iso_types.h" /* FIXME: Implement vendor specific data path configuration */ static bool dummy; @@ -20,6 +22,23 @@ bool ll_data_path_configured(uint8_t data_path_dir, uint8_t data_path_id) return dummy; } +bool ll_data_path_source_create(uint16_t handle, + struct ll_iso_datapath *datapath, + isoal_source_pdu_alloc_cb *pdu_alloc, + isoal_source_pdu_write_cb *pdu_write, + isoal_source_pdu_emit_cb *pdu_emit, + isoal_source_pdu_release_cb *pdu_release) +{ + ARG_UNUSED(handle); + ARG_UNUSED(datapath); + ARG_UNUSED(pdu_alloc); + ARG_UNUSED(pdu_write); + ARG_UNUSED(pdu_emit); + ARG_UNUSED(pdu_release); + + return false; +} + uint8_t ll_configure_data_path(uint8_t data_path_dir, uint8_t data_path_id, uint8_t vs_config_len, uint8_t *vs_config) { diff --git a/subsys/bluetooth/controller/ll_sw/nrf.cmake b/subsys/bluetooth/controller/ll_sw/nrf.cmake index eec9559a939b..a0a6324e1009 100644 --- a/subsys/bluetooth/controller/ll_sw/nrf.cmake +++ b/subsys/bluetooth/controller/ll_sw/nrf.cmake @@ -80,7 +80,7 @@ if(CONFIG_BT_LL_SW_SPLIT) CONFIG_BT_CTLR_PERIPHERAL_ISO ll_sw/nordic/lll/lll_peripheral_iso.c ) - if(CONFIG_BT_CTLR_ISO) + if(CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH) zephyr_library_sources( ll_sw/nordic/ull/ull_iso_vendor.c ) diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index 533682e69e67..9d6c962c94d9 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -3084,19 +3084,3 @@ void *ull_rxfifo_release(uint8_t s, uint8_t n, uint8_t f, uint8_t *l, uint8_t *m return rx; } - -#if defined(CONFIG_BT_CTLR_HCI_CODEC_AND_DELAY_INFO) -/* Contains vendor specific argument, function to be implemented by vendors */ -__weak uint8_t ll_configure_data_path(uint8_t data_path_dir, - uint8_t data_path_id, - uint8_t vs_config_len, - uint8_t *vs_config) -{ - ARG_UNUSED(data_path_dir); - ARG_UNUSED(data_path_id); - ARG_UNUSED(vs_config_len); - ARG_UNUSED(vs_config); - - return BT_HCI_ERR_CMD_DISALLOWED; -} -#endif /* CONFIG_BT_CTLR_HCI_CODEC_AND_DELAY_INFO */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_iso.c b/subsys/bluetooth/controller/ll_sw/ull_iso.c index d12b618b2548..c1b30256b175 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_iso.c @@ -156,16 +156,6 @@ static struct { #endif /* CONFIG_BT_CTLR_ADV_ISO || CONFIG_BT_CTLR_CONN_ISO */ -/* Must be implemented by vendor */ -__weak bool ll_data_path_configured(uint8_t data_path_dir, - uint8_t data_path_id) -{ - ARG_UNUSED(data_path_dir); - ARG_UNUSED(data_path_id); - - return false; -} - uint8_t ll_read_iso_tx_sync(uint16_t handle, uint16_t *seq, uint32_t *timestamp, uint32_t *offset) { @@ -196,41 +186,6 @@ uint8_t ll_read_iso_tx_sync(uint16_t handle, uint16_t *seq, return BT_HCI_ERR_UNKNOWN_CONN_ID; } -/* Must be implemented by vendor */ -__weak bool ll_data_path_sink_create(uint16_t handle, - struct ll_iso_datapath *datapath, - isoal_sink_sdu_alloc_cb *sdu_alloc, - isoal_sink_sdu_emit_cb *sdu_emit, - isoal_sink_sdu_write_cb *sdu_write) -{ - ARG_UNUSED(handle); - ARG_UNUSED(datapath); - - *sdu_alloc = NULL; - *sdu_emit = NULL; - *sdu_write = NULL; - - return false; -} - -/* Could be implemented by vendor */ -__weak bool ll_data_path_source_create(uint16_t handle, - struct ll_iso_datapath *datapath, - isoal_source_pdu_alloc_cb *pdu_alloc, - isoal_source_pdu_write_cb *pdu_write, - isoal_source_pdu_emit_cb *pdu_emit, - isoal_source_pdu_release_cb *pdu_release) -{ - ARG_UNUSED(handle); - ARG_UNUSED(datapath); - ARG_UNUSED(pdu_alloc); - ARG_UNUSED(pdu_write); - ARG_UNUSED(pdu_emit); - ARG_UNUSED(pdu_release); - - return false; -} - static inline bool path_is_vendor_specific(uint8_t path_id) { return (path_id >= BT_HCI_DATAPATH_ID_VS && @@ -396,7 +351,8 @@ uint8_t ll_setup_iso_path(uint16_t handle, uint8_t path_dir, uint8_t path_id, } if (path_is_vendor_specific(path_id) && - !ll_data_path_configured(path_dir, path_id)) { + (!IS_ENABLED(CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH) || + !ll_data_path_configured(path_dir, path_id))) { /* Data path must be configured prior to setup */ return BT_HCI_ERR_CMD_DISALLOWED; } @@ -451,7 +407,8 @@ uint8_t ll_setup_iso_path(uint16_t handle, uint8_t path_dir, uint8_t path_id, isoal_sink_sdu_write_cb sdu_write; /* Request vendor sink callbacks for path */ - if (ll_data_path_sink_create(handle, dp, &sdu_alloc, + if (IS_ENABLED(CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH) && + ll_data_path_sink_create(handle, dp, &sdu_alloc, &sdu_emit, &sdu_write)) { err = isoal_sink_create(handle, role, framed, burst_number, @@ -503,7 +460,8 @@ uint8_t ll_setup_iso_path(uint16_t handle, uint8_t path_dir, uint8_t path_id, isoal_source_pdu_release_cb pdu_release; if (path_is_vendor_specific(path_id)) { - if (!ll_data_path_source_create(handle, dp, + if (!IS_ENABLED(CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH) || + !ll_data_path_source_create(handle, dp, &pdu_alloc, &pdu_write, &pdu_emit, &pdu_release)) { diff --git a/subsys/bluetooth/controller/ll_sw/ull_iso_internal.h b/subsys/bluetooth/controller/ll_sw/ull_iso_internal.h index fc601bc72615..cb7b1bb7cdae 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_iso_internal.h +++ b/subsys/bluetooth/controller/ll_sw/ull_iso_internal.h @@ -29,3 +29,19 @@ void ll_iso_rx_put(memq_link_t *link, void *rx); void *ll_iso_rx_get(void); void ll_iso_rx_dequeue(void); void ll_iso_transmit_test_send_sdu(uint16_t handle, uint32_t ticks_at_expire); + +/* Must be implemented by vendor if vendor-specific data path is supported */ +bool ll_data_path_configured(uint8_t data_path_dir, uint8_t data_path_id); +/* Must be implemented by vendor if vendor-specific data path is supported */ +bool ll_data_path_sink_create(uint16_t handle, + struct ll_iso_datapath *datapath, + isoal_sink_sdu_alloc_cb *sdu_alloc, + isoal_sink_sdu_emit_cb *sdu_emit, + isoal_sink_sdu_write_cb *sdu_write); +/* Must be implemented by vendor if vendor-specific data path is supported */ +bool ll_data_path_source_create(uint16_t handle, + struct ll_iso_datapath *datapath, + isoal_source_pdu_alloc_cb *pdu_alloc, + isoal_source_pdu_write_cb *pdu_write, + isoal_source_pdu_emit_cb *pdu_emit, + isoal_source_pdu_release_cb *pdu_release); From 61559bfe3ab8db9cc25236474f241de663280fff Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 2 Mar 2023 14:54:18 +0100 Subject: [PATCH 0275/1906] Bluetooth: Audio: Explicit stream type of unicast client group stream Make it more explicit that the streams that the value covers are CIS and not BAP streams. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/Kconfig.bap | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/audio/Kconfig.bap b/subsys/bluetooth/audio/Kconfig.bap index c08b3cc41d7d..be0b1a0872e2 100644 --- a/subsys/bluetooth/audio/Kconfig.bap +++ b/subsys/bluetooth/audio/Kconfig.bap @@ -81,14 +81,15 @@ config BT_BAP_UNICAST_CLIENT_GROUP_COUNT the unicast client. config BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT - int "Basic Audio Unicast Group Stream count" + int "Basic Audio Profile Unicast Group Connected Isochronous Stream (CIS) count" depends on BT_BAP_UNICAST_CLIENT_GROUP_COUNT > 0 default 1 range 1 BT_ISO_MAX_CHAN if BT_ISO_MAX_CHAN < 31 range 1 31 help - This option sets the maximum number of streams per unicast group - to support. + This option sets the maximum number of CIS per unicast group to support. + Since BAP streams are unidirectional, two BAP streams may use a single CIS, the number of + BAP audio streams per group may be up to twice of this value. config BT_BAP_UNICAST_CLIENT_PAC_COUNT int "Basic Audio Profile PAC count" From 871db2d277d69ba2e289413000334eaff062b854 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 15 Mar 2023 15:21:33 +0100 Subject: [PATCH 0276/1906] Bluetooth: Move bt_data_parse to dedicated source file This moves bt_data_parse function outside of hci_core.c. Having it in separate file makes unit testing easier as the function do not use kernel objects, thus can be used in unit tests without a need for adding any mocks. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/host/CMakeLists.txt | 1 + subsys/bluetooth/host/data.c | 45 ++++++++++++++++++++++++++++ subsys/bluetooth/host/hci_core.c | 32 -------------------- 3 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 subsys/bluetooth/host/data.c diff --git a/subsys/bluetooth/host/CMakeLists.txt b/subsys/bluetooth/host/CMakeLists.txt index e67f7181798b..a9810c8af32a 100644 --- a/subsys/bluetooth/host/CMakeLists.txt +++ b/subsys/bluetooth/host/CMakeLists.txt @@ -34,6 +34,7 @@ if(CONFIG_BT_HCI_HOST) uuid.c addr.c buf.c + data.c hci_core.c hci_common.c id.c diff --git a/subsys/bluetooth/host/data.c b/subsys/bluetooth/host/data.c new file mode 100644 index 000000000000..151dba181291 --- /dev/null +++ b/subsys/bluetooth/host/data.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017-2021 Nordic Semiconductor ASA + * Copyright (c) 2015-2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#define LOG_LEVEL CONFIG_BT_HCI_CORE_LOG_LEVEL +#include +LOG_MODULE_REGISTER(bt_data); + +void bt_data_parse(struct net_buf_simple *ad, + bool (*func)(struct bt_data *data, void *user_data), + void *user_data) +{ + while (ad->len > 1) { + struct bt_data data; + uint8_t len; + + len = net_buf_simple_pull_u8(ad); + if (len == 0U) { + /* Early termination */ + return; + } + + if (len > ad->len) { + LOG_WRN("malformed advertising data %u / %u", + len, ad->len); + return; + } + + data.type = net_buf_simple_pull_u8(ad); + data.data_len = len - 1; + data.data = ad->data; + + if (!func(&data, user_data)) { + return; + } + + net_buf_simple_pull(ad, len - 1); + } +} diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 45509edb17ae..465e454e8067 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -4059,38 +4059,6 @@ int bt_le_set_rpa_timeout(uint16_t new_rpa_timeout) } #endif -void bt_data_parse(struct net_buf_simple *ad, - bool (*func)(struct bt_data *data, void *user_data), - void *user_data) -{ - while (ad->len > 1) { - struct bt_data data; - uint8_t len; - - len = net_buf_simple_pull_u8(ad); - if (len == 0U) { - /* Early termination */ - return; - } - - if (len > ad->len) { - LOG_WRN("malformed advertising data %u / %u", - len, ad->len); - return; - } - - data.type = net_buf_simple_pull_u8(ad); - data.data_len = len - 1; - data.data = ad->data; - - if (!func(&data, user_data)) { - return; - } - - net_buf_simple_pull(ad, len - 1); - } -} - int bt_configure_data_path(uint8_t dir, uint8_t id, uint8_t vs_config_len, const uint8_t *vs_config) { From 253d0806d304e74943859c7919648bb7e2486b94 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 15 Mar 2023 15:22:12 +0100 Subject: [PATCH 0277/1906] test: Bluetooth: host: Add unit tests for bt_data_parse This adds unit tests for bt_data_parse. The sample data concept used in test is based on AD Structures of Advertising, Periodic Advertising, and Scan Response presented in Core specification. Signed-off-by: Mariusz Skamra --- .../host/data/bt_data_parse/CMakeLists.txt | 22 ++ .../host/data/bt_data_parse/prj.conf | 7 + .../host/data/bt_data_parse/src/main.c | 194 ++++++++++++++++++ .../host/data/bt_data_parse/testcase.yaml | 5 + 4 files changed, 228 insertions(+) create mode 100644 tests/bluetooth/host/data/bt_data_parse/CMakeLists.txt create mode 100644 tests/bluetooth/host/data/bt_data_parse/prj.conf create mode 100644 tests/bluetooth/host/data/bt_data_parse/src/main.c create mode 100644 tests/bluetooth/host/data/bt_data_parse/testcase.yaml diff --git a/tests/bluetooth/host/data/bt_data_parse/CMakeLists.txt b/tests/bluetooth/host/data/bt_data_parse/CMakeLists.txt new file mode 100644 index 000000000000..32592896a7c9 --- /dev/null +++ b/tests/bluetooth/host/data/bt_data_parse/CMakeLists.txt @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +project(bt_data_parse) + +find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) + +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) + +target_link_libraries(testbinary PRIVATE host_mocks) + +target_sources(testbinary + PRIVATE + src/main.c + + ${ZEPHYR_BASE}/subsys/bluetooth/host/data.c + ${ZEPHYR_BASE}/subsys/net/buf_simple.c + ${ZEPHYR_BASE}/subsys/logging/log_minimal.c + ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c + ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c +) diff --git a/tests/bluetooth/host/data/bt_data_parse/prj.conf b/tests/bluetooth/host/data/bt_data_parse/prj.conf new file mode 100644 index 000000000000..c68da48c1fb9 --- /dev/null +++ b/tests/bluetooth/host/data/bt_data_parse/prj.conf @@ -0,0 +1,7 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_ASSERT=y +CONFIG_ASSERT_LEVEL=2 +CONFIG_ASSERT_VERBOSE=y +CONFIG_ASSERT_ON_ERRORS=y +CONFIG_NET_BUF=y diff --git a/tests/bluetooth/host/data/bt_data_parse/src/main.c b/tests/bluetooth/host/data/bt_data_parse/src/main.c new file mode 100644 index 000000000000..c25af6d40458 --- /dev/null +++ b/tests/bluetooth/host/data/bt_data_parse/src/main.c @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +DEFINE_FFF_GLOBALS; + +FAKE_VALUE_FUNC(bool, bt_data_parse_func, struct bt_data *, void *); + +static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) +{ + RESET_FAKE(bt_data_parse_func); +} + +ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); + +ZTEST_SUITE(bt_data_parse, NULL, NULL, NULL, NULL, NULL); + +/* + * Test empty data buffer + * + * Constraints: + * - data.len set to 0 + * + * Expected behaviour: + * - Callback function is not called + */ +ZTEST(bt_data_parse, test_parsing_empty_buf) +{ + struct net_buf_simple *buf = NET_BUF_SIMPLE(0); + + bt_data_parse(buf, bt_data_parse_func, NULL); + + zassert_equal(bt_data_parse_func_fake.call_count, 0); +} + +/* + * Test AD Structure invalid length + * + * Constraints: + * - AD Structure N length > number of bytes after + * + * Expected behaviour: + * - Callback function is called N - 1 times + */ +ZTEST(bt_data_parse, test_parsing_invalid_length) +{ + struct net_buf_simple buf; + uint8_t data[] = { + /* Significant part */ + 0x02, 0x01, 0x00, /* AD Structure 1 */ + 0x03, 0x02, 0x01, 0x00, /* AD Structure 2 */ + /* Invalid length 0xff */ + 0xff, 0x03, 0x02, 0x01, /* AD Structure N */ + 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, /* AD Structure N + 1 */ + }; + + bt_data_parse_func_fake.return_val = true; + + net_buf_simple_init_with_data(&buf, data, ARRAY_SIZE(data)); + + bt_data_parse(&buf, bt_data_parse_func, NULL); + + zassert_equal(2, bt_data_parse_func_fake.call_count, + "called %d", bt_data_parse_func_fake.call_count); +} + +/* + * Test early termination of the significant part + * + * Constraints: + * - The significant part contains a sequence of N AD structures + * - The non-significant part extends the data with all-zero octets + * + * Expected behaviour: + * - Callback function is called N times + */ +ZTEST(bt_data_parse, test_parsing_early_termination) +{ + struct net_buf_simple buf; + uint8_t data[] = { + /* Significant part */ + 0x02, 0x01, 0x00, /* AD Structure 1 */ + 0x03, 0x02, 0x01, 0x00, /* AD Structure 2 */ + 0x04, 0x03, 0x02, 0x01, 0x00, /* AD Structure 3 */ + /* Non-significant part */ + 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + bt_data_parse_func_fake.return_val = true; + + net_buf_simple_init_with_data(&buf, data, ARRAY_SIZE(data)); + + bt_data_parse(&buf, bt_data_parse_func, NULL); + + zassert_equal(3, bt_data_parse_func_fake.call_count, + "called %d", bt_data_parse_func_fake.call_count); +} + +/* + * Test parsing stopped + * + * Constraints: + * - Data contains valid AD Structures + * - Callback function returns false to stop parsing + * + * Expected behaviour: + * - Once parsing is stopped, the callback is not called anymore + */ +ZTEST(bt_data_parse, test_parsing_stopped) +{ + struct net_buf_simple buf; + uint8_t data[] = { + /* Significant part */ + 0x02, 0x01, 0x00, /* AD Structure 1 */ + 0x03, 0x02, 0x01, 0x00, /* AD Structure 2 */ + }; + + bt_data_parse_func_fake.return_val = false; + + net_buf_simple_init_with_data(&buf, data, ARRAY_SIZE(data)); + + bt_data_parse(&buf, bt_data_parse_func, NULL); + + zassert_equal(1, bt_data_parse_func_fake.call_count, + "called %d", bt_data_parse_func_fake.call_count); +} + +struct custom_fake_user_data { + const uint8_t *data; + size_t len; +}; + +static bool bt_data_parse_func_custom_fake(struct bt_data *data, + void *user_data) +{ + struct custom_fake_user_data *ud = user_data; + + /* length check */ + zassert_true(ud->len-- > 0); + zassert_equal(data->data_len, *ud->data - 1); + ud->data++; + + /* type check */ + zassert_true(ud->len-- > 0); + zassert_equal(data->type, *ud->data); + ud->data++; + + /* value check */ + zassert_true(ud->len >= data->data_len); + zassert_mem_equal(data->data, ud->data, data->data_len); + ud->data += data->data_len; + ud->len -= data->data_len; + + return true; +} + +/* + * Test parsing AD Data + * + * Constraints: + * - Data contains valid AD Structures + * - Callback function returns false to stop parsing + * + * Expected behaviour: + * - Data passed to the callback match the expected data + */ +ZTEST(bt_data_parse, test_parsing_success) +{ + struct net_buf_simple buf; + uint8_t data[] = { + /* Significant part */ + 0x02, 0x01, 0x00, /* AD Structure 1 */ + 0x03, 0x02, 0x01, 0x00, /* AD Structure 2 */ + }; + struct custom_fake_user_data user_data = { + .data = data, + .len = ARRAY_SIZE(data), + }; + + bt_data_parse_func_fake.custom_fake = bt_data_parse_func_custom_fake; + + net_buf_simple_init_with_data(&buf, data, ARRAY_SIZE(data)); + + bt_data_parse(&buf, bt_data_parse_func, &user_data); + + zassert_equal(2, bt_data_parse_func_fake.call_count, + "called %d", bt_data_parse_func_fake.call_count); +} diff --git a/tests/bluetooth/host/data/bt_data_parse/testcase.yaml b/tests/bluetooth/host/data/bt_data_parse/testcase.yaml new file mode 100644 index 000000000000..3d3c5908b0c9 --- /dev/null +++ b/tests/bluetooth/host/data/bt_data_parse/testcase.yaml @@ -0,0 +1,5 @@ +common: + tags: bluetooth host +tests: + bluetooth.host.bt_data_parse: + type: unit From 9a759025d9123c7871308173a5fa31657a43a179 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Wed, 15 Mar 2023 21:41:42 +0000 Subject: [PATCH 0278/1906] samples: net: sockets: tcp: Add newlib filter to samples.yaml Not all toolchains support newlib so tests that require newlib need to have a filter to we don't try and build those tests on those testcases. Add the following to samples.yaml to handle the issue: filter: TOOLCHAIN_HAS_NEWLIB == 1 Signed-off-by: Kumar Gala --- samples/net/sockets/tcp/sample.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/net/sockets/tcp/sample.yaml b/samples/net/sockets/tcp/sample.yaml index c58d8c91d207..5342f135a3ee 100644 --- a/samples/net/sockets/tcp/sample.yaml +++ b/samples/net/sockets/tcp/sample.yaml @@ -3,6 +3,7 @@ sample: name: tcp tests: sample.net.socket.tcp: + filter: TOOLCHAIN_HAS_NEWLIB == 1 harness: net platform_allow: qemu_x86 tags: socket tcp From ac5e4fea906ccd74d1a05eafd6fef35f6d46f11f Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 16 Mar 2023 10:28:29 +0100 Subject: [PATCH 0279/1906] Bluetooth: Audio: Unicast Client Log more of QoS pref Add logging of some missing fields of the QoS preference we receiver from the unicast server. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/bap_unicast_client.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index 655ae1158920..1fe9d3d0d472 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -641,9 +641,10 @@ static void unicast_client_ep_config_state(struct bt_bap_ep *ep, struct net_buf_ pref->pref_pd_max = sys_get_le24(cfg->prefer_pd_max); LOG_DBG("dir %s unframed_supported 0x%02x phy 0x%02x rtn %u " - "latency %u pd_min %u pd_max %u codec 0x%02x ", + "latency %u pd_min %u pd_max %u pref_pd_min %u pref_pd_max %u codec 0x%02x ", bt_audio_dir_str(ep->dir), pref->unframed_supported, pref->phy, pref->rtn, - pref->latency, pref->pd_min, pref->pd_max, stream->codec->id); + pref->latency, pref->pd_min, pref->pd_max, pref->pref_pd_min, pref->pref_pd_max, + stream->codec->id); unicast_client_ep_set_codec(ep, cfg->codec.id, sys_le16_to_cpu(cfg->codec.cid), sys_le16_to_cpu(cfg->codec.vid), cc, cfg->cc_len, NULL); From e051c2a43702eaa9f71389659c75c4ca3cc76c5d Mon Sep 17 00:00:00 2001 From: Bindu S Date: Wed, 15 Mar 2023 10:05:11 +0530 Subject: [PATCH 0280/1906] dts: x86: intel: raptor_lake: Add i2c instances Added i2c instances in raptor_lake dtsi file. Signed-off-by: Bindu S --- dts/x86/intel/raptor_lake.dtsi | 104 +++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/dts/x86/intel/raptor_lake.dtsi b/dts/x86/intel/raptor_lake.dtsi index 3f79de241c66..8570fdd7445b 100644 --- a/dts/x86/intel/raptor_lake.dtsi +++ b/dts/x86/intel/raptor_lake.dtsi @@ -39,6 +39,110 @@ #size-cells = <1>; compatible = "intel,pcie"; ranges; + + i2c0: i2c0 { + compatible = "snps,designware-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + vendor-id = <0x8086>; + device-id = <0x7acc>; + interrupts = ; + interrupt-parent = <&intc>; + + status = "okay"; + }; + + i2c1: i2c1 { + compatible = "snps,designware-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + vendor-id = <0x8086>; + device-id = <0x7acd>; + interrupts = ; + interrupt-parent = <&intc>; + + status = "okay"; + }; + + i2c2: i2c2 { + compatible = "snps,designware-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + vendor-id = <0x8086>; + device-id = <0x7ace>; + interrupts = ; + interrupt-parent = <&intc>; + + status = "okay"; + }; + + i2c3: i2c3 { + compatible = "snps,designware-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + vendor-id = <0x8086>; + device-id = <0x7acf>; + interrupts = ; + interrupt-parent = <&intc>; + + status = "disabled"; + }; + + i2c4: i2c4 { + compatible = "snps,designware-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + vendor-id = <0x8086>; + device-id = <0x7afc>; + interrupts = ; + interrupt-parent = <&intc>; + + status = "disabled"; + }; + + i2c5: i2c5 { + compatible = "snps,designware-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + vendor-id = <0x8086>; + device-id = <0x7afd>; + interrupts = ; + interrupt-parent = <&intc>; + + status = "disabled"; + }; + + i2c6: i2c6 { + compatible = "snps,designware-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + vendor-id = <0x8086>; + device-id = <0x7ada>; + interrupts = ; + interrupt-parent = <&intc>; + + status = "disabled"; + }; + + i2c7: i2c7 { + compatible = "snps,designware-i2c"; + clock-frequency = ; + #address-cells = <1>; + #size-cells = <0>; + vendor-id = <0x8086>; + device-id = <0x7adb>; + interrupts = ; + interrupt-parent = <&intc>; + + status = "disabled"; + }; }; soc { From d485ef0231ada7caaa685caad253b75793c2c9f1 Mon Sep 17 00:00:00 2001 From: Luca Fancellu Date: Tue, 7 Mar 2023 10:05:59 +0000 Subject: [PATCH 0281/1906] net: zperf: Reduce the scope of input address variables Reduce the scope of in4_addr_my and in6_addr_my pointer variables that are currently global, but they are used only inside tcp_receiver_thread. Take the occasion to fix a typo in one error message. Signed-off-by: Luca Fancellu --- subsys/net/lib/zperf/zperf_tcp_receiver.c | 49 ++++++++++------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_tcp_receiver.c b/subsys/net/lib/zperf/zperf_tcp_receiver.c index 5e58f03ff894..d1b54f1512f4 100644 --- a/subsys/net/lib/zperf/zperf_tcp_receiver.c +++ b/subsys/net/lib/zperf/zperf_tcp_receiver.c @@ -23,9 +23,6 @@ LOG_MODULE_DECLARE(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL); #define NET_LOG_ENABLED 1 #include "net_private.h" -static struct sockaddr_in6 *in6_addr_my; -static struct sockaddr_in *in4_addr_my; - #if defined(CONFIG_NET_TC_THREAD_COOPERATIVE) #define TCP_RECEIVER_THREAD_PRIORITY K_PRIO_COOP(8) #else @@ -114,9 +111,7 @@ static void tcp_server_session(void) } if (IS_ENABLED(CONFIG_NET_IPV4)) { - const struct in_addr *in4_addr = NULL; - - in4_addr_my = zperf_get_sin(); + struct sockaddr_in *in4_addr = zperf_get_sin(); fds[SOCK_ID_IPV4_LISTEN].fd = zsock_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); @@ -128,7 +123,7 @@ static void tcp_server_session(void) if (MY_IP4ADDR && strlen(MY_IP4ADDR)) { /* Use Setting IP */ ret = zperf_get_ipv4_addr(MY_IP4ADDR, - &in4_addr_my->sin_addr); + &in4_addr->sin_addr); if (ret < 0) { NET_WARN("Unable to set IPv4"); goto use_existing_ipv4; @@ -136,26 +131,27 @@ static void tcp_server_session(void) } else { use_existing_ipv4: /* Use existing IP */ - in4_addr = zperf_get_default_if_in4_addr(); - if (!in4_addr) { - NET_ERR("Unable to get IPv4 by default"); + const struct in_addr *addr = + zperf_get_default_if_in4_addr(); + if (!addr) { + NET_ERR("Unable to get IPv4 by default\n"); goto error; } - memcpy(&in4_addr_my->sin_addr, in4_addr, + memcpy(&in4_addr->sin_addr, addr, sizeof(struct in_addr)); } - in4_addr_my->sin_port = htons(tcp_server_port); + in4_addr->sin_port = htons(tcp_server_port); NET_INFO("Binding to %s", - net_sprint_ipv4_addr(&in4_addr_my->sin_addr)); + net_sprint_ipv4_addr(&in4_addr->sin_addr)); ret = zsock_bind(fds[SOCK_ID_IPV4_LISTEN].fd, - (struct sockaddr *)in4_addr_my, + (struct sockaddr *)in4_addr, sizeof(struct sockaddr_in)); if (ret < 0) { NET_ERR("Cannot bind IPv4 TCP port %d (%d)", - ntohs(in4_addr_my->sin_port), errno); + ntohs(in4_addr->sin_port), errno); goto error; } @@ -169,9 +165,7 @@ static void tcp_server_session(void) } if (IS_ENABLED(CONFIG_NET_IPV6)) { - const struct in6_addr *in6_addr = NULL; - - in6_addr_my = zperf_get_sin6(); + struct sockaddr_in6 *in6_addr = zperf_get_sin6(); fds[SOCK_ID_IPV6_LISTEN].fd = zsock_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); @@ -184,7 +178,7 @@ static void tcp_server_session(void) /* Use Setting IP */ ret = zperf_get_ipv6_addr(MY_IP6ADDR, MY_PREFIX_LEN_STR, - &in6_addr_my->sin6_addr); + &in6_addr->sin6_addr); if (ret < 0) { NET_WARN("Unable to set IPv6"); goto use_existing_ipv6; @@ -192,26 +186,27 @@ static void tcp_server_session(void) } else { use_existing_ipv6: /* Use existing IP */ - in6_addr = zperf_get_default_if_in6_addr(); - if (!in6_addr) { - NET_ERR("Unable to get IPv4 by default"); + const struct in6_addr *addr = + zperf_get_default_if_in6_addr(); + if (!addr) { + NET_ERR("Unable to get IPv6 by default\n"); goto error; } - memcpy(&in6_addr_my->sin6_addr, in6_addr, + memcpy(&in6_addr->sin6_addr, addr, sizeof(struct in6_addr)); } - in6_addr_my->sin6_port = htons(tcp_server_port); + in6_addr->sin6_port = htons(tcp_server_port); NET_INFO("Binding to %s", - net_sprint_ipv6_addr(&in6_addr_my->sin6_addr)); + net_sprint_ipv6_addr(&in6_addr->sin6_addr)); ret = zsock_bind(fds[SOCK_ID_IPV6_LISTEN].fd, - (struct sockaddr *)in6_addr_my, + (struct sockaddr *)in6_addr, sizeof(struct sockaddr_in6)); if (ret < 0) { NET_ERR("Cannot bind IPv6 TCP port %d (%d)", - ntohs(in6_addr_my->sin6_port), errno); + ntohs(in6_addr->sin6_port), errno); goto error; } From 6748d588abd161f80cf307986a05df072fd23788 Mon Sep 17 00:00:00 2001 From: Luca Fancellu Date: Tue, 7 Mar 2023 13:49:28 +0000 Subject: [PATCH 0282/1906] net: zperf: allow TCP receiver to handle multiple connections Currently the zperf_tcp_receiver can handle only one TCP connection each time, modify the code to poll and handle multiple connections. Take the occasion to unify the bind and listen part of the code between ipv4 and ipv6 part using a structure introduced to handle the multiple connections. Now in case the zsock_recv fails, we can't stop every connection and fail through the error label, so just print the error message and report the failure through the callback. Signed-off-by: Luca Fancellu --- subsys/net/lib/zperf/zperf_tcp_receiver.c | 164 ++++++++++++---------- 1 file changed, 93 insertions(+), 71 deletions(-) diff --git a/subsys/net/lib/zperf/zperf_tcp_receiver.c b/subsys/net/lib/zperf/zperf_tcp_receiver.c index d1b54f1512f4..fd35b4487501 100644 --- a/subsys/net/lib/zperf/zperf_tcp_receiver.c +++ b/subsys/net/lib/zperf/zperf_tcp_receiver.c @@ -32,10 +32,8 @@ LOG_MODULE_DECLARE(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL); #define TCP_RECEIVER_STACK_SIZE 2048 #define SOCK_ID_IPV4_LISTEN 0 -#define SOCK_ID_IPV4_DATA 1 -#define SOCK_ID_IPV6_LISTEN 2 -#define SOCK_ID_IPV6_DATA 3 -#define SOCK_ID_MAX 4 +#define SOCK_ID_IPV6_LISTEN 1 +#define SOCK_ID_MAX (CONFIG_NET_ZPERF_MAX_SESSIONS + 2) #define TCP_RECEIVER_BUF_SIZE 1500 #define POLL_TIMEOUT_MS 100 @@ -100,10 +98,50 @@ static void tcp_received(const struct sockaddr *addr, size_t datalen) } } +static int tcp_bind_listen_connection(struct zsock_pollfd *pollfd, + struct sockaddr *address) +{ + uint16_t port; + int ret; + + if (address->sa_family == AF_INET) { + port = ntohs(net_sin(address)->sin_port); + } else { + port = ntohs(net_sin6(address)->sin6_port); + } + + ret = zsock_bind(pollfd->fd, address, sizeof(*address)); + if (ret < 0) { + NET_ERR("Cannot bind IPv%d TCP port %d (%d)", + (address->sa_family == AF_INET ? 4 : 6), port, errno); + goto out; + } + + ret = zsock_listen(pollfd->fd, 1); + if (ret < 0) { + NET_ERR("Cannot listen IPv%d TCP (%d)", + (address->sa_family == AF_INET ? 4 : 6), errno); + goto out; + } + + pollfd->events = ZSOCK_POLLIN; + +out: + return ret; +} + +static void tcp_session_error_report(void) +{ + if (tcp_session_cb != NULL) { + tcp_session_cb(ZPERF_SESSION_ERROR, NULL, tcp_user_data); + } +} + static void tcp_server_session(void) { static uint8_t buf[TCP_RECEIVER_BUF_SIZE]; - struct zsock_pollfd fds[SOCK_ID_MAX] = { 0 }; + static struct zsock_pollfd fds[SOCK_ID_MAX]; + static struct sockaddr sock_addr[SOCK_ID_MAX]; int ret; for (int i = 0; i < ARRAY_SIZE(fds); i++) { @@ -134,7 +172,7 @@ static void tcp_server_session(void) const struct in_addr *addr = zperf_get_default_if_in4_addr(); if (!addr) { - NET_ERR("Unable to get IPv4 by default\n"); + NET_ERR("Unable to get IPv4 by default"); goto error; } memcpy(&in4_addr->sin_addr, addr, @@ -146,22 +184,15 @@ static void tcp_server_session(void) NET_INFO("Binding to %s", net_sprint_ipv4_addr(&in4_addr->sin_addr)); - ret = zsock_bind(fds[SOCK_ID_IPV4_LISTEN].fd, - (struct sockaddr *)in4_addr, - sizeof(struct sockaddr_in)); - if (ret < 0) { - NET_ERR("Cannot bind IPv4 TCP port %d (%d)", - ntohs(in4_addr->sin_port), errno); - goto error; - } + memcpy(net_sin(&sock_addr[SOCK_ID_IPV4_LISTEN]), in4_addr, + sizeof(struct sockaddr_in)); - ret = zsock_listen(fds[SOCK_ID_IPV4_LISTEN].fd, 1); + ret = tcp_bind_listen_connection( + &fds[SOCK_ID_IPV4_LISTEN], + &sock_addr[SOCK_ID_IPV4_LISTEN]); if (ret < 0) { - NET_ERR("Cannot listen IPv4 TCP (%d)", errno); goto error; } - - fds[SOCK_ID_IPV4_LISTEN].events = ZSOCK_POLLIN; } if (IS_ENABLED(CONFIG_NET_IPV6)) { @@ -189,7 +220,7 @@ static void tcp_server_session(void) const struct in6_addr *addr = zperf_get_default_if_in6_addr(); if (!addr) { - NET_ERR("Unable to get IPv6 by default\n"); + NET_ERR("Unable to get IPv6 by default"); goto error; } memcpy(&in6_addr->sin6_addr, addr, @@ -201,29 +232,20 @@ static void tcp_server_session(void) NET_INFO("Binding to %s", net_sprint_ipv6_addr(&in6_addr->sin6_addr)); - ret = zsock_bind(fds[SOCK_ID_IPV6_LISTEN].fd, - (struct sockaddr *)in6_addr, - sizeof(struct sockaddr_in6)); - if (ret < 0) { - NET_ERR("Cannot bind IPv6 TCP port %d (%d)", - ntohs(in6_addr->sin6_port), errno); - goto error; - } + memcpy(net_sin6(&sock_addr[SOCK_ID_IPV6_LISTEN]), in6_addr, + sizeof(struct sockaddr_in6)); - ret = zsock_listen(fds[SOCK_ID_IPV6_LISTEN].fd, 1); + ret = tcp_bind_listen_connection( + &fds[SOCK_ID_IPV6_LISTEN], + &sock_addr[SOCK_ID_IPV6_LISTEN]); if (ret < 0) { - NET_ERR("Cannot listen IPv6 TCP (%d)", errno); goto error; } - - fds[SOCK_ID_IPV6_LISTEN].events = ZSOCK_POLLIN; } NET_INFO("Listening on port %d", tcp_server_port); while (true) { - struct sockaddr addr_ipv4, addr_ipv6; - ret = zsock_poll(fds, ARRAY_SIZE(fds), POLL_TIMEOUT_MS); if (ret < 0) { NET_ERR("TCP receiver poll error (%d)", errno); @@ -239,13 +261,11 @@ static void tcp_server_session(void) } for (int i = 0; i < ARRAY_SIZE(fds); i++) { - struct sockaddr *addr = &addr_ipv6; - socklen_t addrlen = sizeof(struct sockaddr); - if ((fds[i].revents & ZSOCK_POLLERR) || (fds[i].revents & ZSOCK_POLLNVAL)) { NET_ERR("TCP receiver IPv%d socket error", - (i <= SOCK_ID_IPV4_DATA) ? 4 : 6); + (sock_addr[i].sa_family == AF_INET + ? 4 : 6)); goto error; } @@ -253,70 +273,72 @@ static void tcp_server_session(void) continue; } - switch (i) { - case SOCK_ID_IPV4_LISTEN: - addr = &addr_ipv4; - __fallthrough; - case SOCK_ID_IPV6_LISTEN:{ - int sock = zsock_accept(fds[i].fd, addr, &addrlen); + if ((i >= SOCK_ID_IPV4_LISTEN) && (i <= SOCK_ID_IPV6_LISTEN)) { + int j = SOCK_ID_IPV6_LISTEN + 1; + struct sockaddr addr_incoming_conn; + socklen_t addrlen = sizeof(struct sockaddr); + int sock = zsock_accept(fds[i].fd, + &addr_incoming_conn, + &addrlen); if (sock < 0) { NET_ERR("TCP receiver IPv%d accept error", - (i <= SOCK_ID_IPV4_DATA) ? 4 : 6); + (sock_addr[i].sa_family == AF_INET + ? 4 : 6)); goto error; } - if (i == SOCK_ID_IPV4_LISTEN && - fds[SOCK_ID_IPV4_DATA].fd < 0) { - fds[SOCK_ID_IPV4_DATA].fd = sock; - fds[SOCK_ID_IPV4_DATA].events = ZSOCK_POLLIN; - } else if (i == SOCK_ID_IPV6_LISTEN && - fds[SOCK_ID_IPV6_DATA].fd < 0) { - fds[SOCK_ID_IPV6_DATA].fd = sock; - fds[SOCK_ID_IPV6_DATA].events = ZSOCK_POLLIN; - } else { + for (; j < SOCK_ID_MAX; j++) { + if (fds[j].fd < 0) { + break; + } + } + + if (j == SOCK_ID_MAX) { /* Too many connections. */ + NET_ERR("Dropping TCP connection, reached maximum limit."); zsock_close(sock); - break; + } else { + fds[j].fd = sock; + fds[j].events = ZSOCK_POLLIN; + memcpy(&sock_addr[j], + &addr_incoming_conn, + addrlen); } - - break; - } - - case SOCK_ID_IPV4_DATA: - addr = &addr_ipv4; - __fallthrough; - case SOCK_ID_IPV6_DATA: + } else if ((i > SOCK_ID_IPV6_LISTEN) && (i < SOCK_ID_MAX)) { ret = zsock_recv(fds[i].fd, buf, sizeof(buf), 0); if (ret < 0) { NET_ERR("recv failed on IPv%d socket (%d)", - (i <= SOCK_ID_IPV4_DATA) ? 4 : 6, + (sock_addr[i].sa_family == AF_INET + ? 4 : 6), errno); - goto error; + tcp_session_error_report(); + /* This will close the zperf session */ + ret = 0; } - tcp_received(addr, ret); + tcp_received(&sock_addr[i], ret); if (ret == 0) { zsock_close(fds[i].fd); fds[i].fd = -1; + memset(&sock_addr[i], 0, + sizeof(struct sockaddr)); } - - break; + } else { + goto error; } } } error: - if (tcp_session_cb != NULL) { - tcp_session_cb(ZPERF_SESSION_ERROR, NULL, - tcp_user_data); - } + tcp_session_error_report(); cleanup: for (int i = 0; i < ARRAY_SIZE(fds); i++) { if (fds[i].fd >= 0) { zsock_close(fds[i].fd); + memset(&sock_addr[i], 0, sizeof(struct sockaddr)); } } } From 169270e911d3d3c699453ab0fa8618363f953913 Mon Sep 17 00:00:00 2001 From: Jonathan Rico Date: Tue, 7 Mar 2023 10:34:33 +0100 Subject: [PATCH 0283/1906] Bluetooth: host: downgrade select log messages In the case of a constrained system that uses dynamic channels (ie, not much initial credits), the user's log would be flooded with those three messages. This is not really an error per se as the stack will handle it properly and reschedule the sending of the buffers as soon as more credits arrive. Thus downgrading the severity of - the l2cap messages, as they are only compiled when dynamic channels are enabled - the conn message. Reporting the error belongs in the upper layers. Signed-off-by: Jonathan Rico --- subsys/bluetooth/host/att.c | 3 +++ subsys/bluetooth/host/conn.c | 2 +- subsys/bluetooth/host/l2cap.c | 4 ++-- subsys/bluetooth/host/smp.c | 16 ++++++++++++++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index 5efa9201dd93..375479e843dc 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -281,6 +281,9 @@ static int chan_send(struct bt_att_chan *chan, struct net_buf *buf) err = bt_l2cap_send_cb(chan->att->conn, BT_L2CAP_CID_ATT, buf, att_cb(buf), data); if (err) { + if (err == -ENOBUFS) { + LOG_ERR("Ran out of TX buffers or contexts."); + } /* In case of an error has occurred restore the buffer state */ net_buf_simple_restore(&buf->b, &state); } diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 258962f23e85..d92b8d947d88 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -429,7 +429,7 @@ int bt_conn_send_cb(struct bt_conn *conn, struct net_buf *buf, if (cb) { tx = conn_tx_alloc(); if (!tx) { - LOG_ERR("Unable to allocate TX context"); + LOG_DBG("Unable to allocate TX context"); return -ENOBUFS; } diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index 225ca4c20dd5..3276c69db52c 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -1973,7 +1973,7 @@ static int l2cap_chan_le_send(struct bt_l2cap_le_chan *ch, int len, err; if (!test_and_dec(&ch->tx.credits)) { - LOG_WRN("No credits to transmit packet"); + LOG_DBG("No credits to transmit packet"); return -EAGAIN; } @@ -2003,7 +2003,7 @@ static int l2cap_chan_le_send(struct bt_l2cap_le_chan *ch, } if (err) { - LOG_WRN("Unable to send seg %d", err); + LOG_DBG("Unable to send seg %d", err); atomic_inc(&ch->tx.credits); /* The host takes ownership of the reference in seg when diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 626c4bb925d6..43417ef06b49 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -798,7 +798,13 @@ static void smp_br_timeout(struct k_work *work) static void smp_br_send(struct bt_smp_br *smp, struct net_buf *buf, bt_conn_tx_cb_t cb) { - if (bt_l2cap_send_cb(smp->chan.chan.conn, BT_L2CAP_CID_BR_SMP, buf, cb, NULL)) { + int err = bt_l2cap_send_cb(smp->chan.chan.conn, BT_L2CAP_CID_BR_SMP, buf, cb, NULL); + + if (err) { + if (err == -ENOBUFS) { + LOG_ERR("Ran out of TX buffers or contexts."); + } + net_buf_unref(buf); return; } @@ -1716,7 +1722,13 @@ static void smp_timeout(struct k_work *work) static void smp_send(struct bt_smp *smp, struct net_buf *buf, bt_conn_tx_cb_t cb, void *user_data) { - if (bt_l2cap_send_cb(smp->chan.chan.conn, BT_L2CAP_CID_SMP, buf, cb, NULL)) { + int err = bt_l2cap_send_cb(smp->chan.chan.conn, BT_L2CAP_CID_SMP, buf, cb, NULL); + + if (err) { + if (err == -ENOBUFS) { + LOG_ERR("Ran out of TX buffers or contexts."); + } + net_buf_unref(buf); return; } From 914c4c6913b2e9872e36a9cfd50421e247866ab1 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Wed, 15 Mar 2023 21:50:23 +0900 Subject: [PATCH 0284/1906] ci: Switch to CI image v0.25.0 This commit updates the CI workflows to use the CI image v0.25.0, in order to pull in the Zephyr SDK 0.16.0 release. Signed-off-by: Stephanos Ioannidis --- .github/workflows/bluetooth-tests.yaml | 2 +- .github/workflows/clang.yaml | 2 +- .github/workflows/codecov.yaml | 2 +- .github/workflows/errno.yml | 2 +- .github/workflows/footprint-tracking.yml | 2 +- .github/workflows/footprint.yml | 2 +- .github/workflows/twister.yaml | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/bluetooth-tests.yaml b/.github/workflows/bluetooth-tests.yaml index 3aff62698ba8..e117e9d6d0c4 100644 --- a/.github/workflows/bluetooth-tests.yaml +++ b/.github/workflows/bluetooth-tests.yaml @@ -21,7 +21,7 @@ jobs: if: github.repository_owner == 'zephyrproject-rtos' runs-on: zephyr-runner-linux-x64-4xlarge container: - image: ghcr.io/zephyrproject-rtos/ci:v0.24.11 + image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 options: '--entrypoint /bin/bash' volumes: - /repo-cache/zephyrproject:/github/cache/zephyrproject diff --git a/.github/workflows/clang.yaml b/.github/workflows/clang.yaml index 259ebc0cedba..a68907cb636e 100644 --- a/.github/workflows/clang.yaml +++ b/.github/workflows/clang.yaml @@ -11,7 +11,7 @@ jobs: if: github.repository_owner == 'zephyrproject-rtos' runs-on: zephyr-runner-linux-x64-4xlarge container: - image: ghcr.io/zephyrproject-rtos/ci:v0.24.11 + image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 options: '--entrypoint /bin/bash' volumes: - /repo-cache/zephyrproject:/github/cache/zephyrproject diff --git a/.github/workflows/codecov.yaml b/.github/workflows/codecov.yaml index 07c0fd902263..7a88dd506a06 100644 --- a/.github/workflows/codecov.yaml +++ b/.github/workflows/codecov.yaml @@ -13,7 +13,7 @@ jobs: if: github.repository == 'zephyrproject-rtos/zephyr' runs-on: zephyr-runner-linux-x64-4xlarge container: - image: ghcr.io/zephyrproject-rtos/ci:v0.24.11 + image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 options: '--entrypoint /bin/bash' volumes: - /repo-cache/zephyrproject:/github/cache/zephyrproject diff --git a/.github/workflows/errno.yml b/.github/workflows/errno.yml index 1e07f43066df..f55f508b5866 100644 --- a/.github/workflows/errno.yml +++ b/.github/workflows/errno.yml @@ -10,7 +10,7 @@ jobs: check-errno: runs-on: ubuntu-20.04 container: - image: ghcr.io/zephyrproject-rtos/ci:v0.24.11 + image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 env: ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.15.2 diff --git a/.github/workflows/footprint-tracking.yml b/.github/workflows/footprint-tracking.yml index 0d8ab4ce7525..d10056da6fef 100644 --- a/.github/workflows/footprint-tracking.yml +++ b/.github/workflows/footprint-tracking.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-20.04 if: github.repository == 'zephyrproject-rtos/zephyr' container: - image: ghcr.io/zephyrproject-rtos/ci:v0.24.11 + image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 options: '--entrypoint /bin/bash' strategy: fail-fast: false diff --git a/.github/workflows/footprint.yml b/.github/workflows/footprint.yml index be6883f365c8..de6f5c3016ec 100644 --- a/.github/workflows/footprint.yml +++ b/.github/workflows/footprint.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-20.04 if: github.repository == 'zephyrproject-rtos/zephyr' container: - image: ghcr.io/zephyrproject-rtos/ci:v0.24.11 + image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 options: '--entrypoint /bin/bash' strategy: fail-fast: false diff --git a/.github/workflows/twister.yaml b/.github/workflows/twister.yaml index 5a801803e74c..1bb6a44a7595 100644 --- a/.github/workflows/twister.yaml +++ b/.github/workflows/twister.yaml @@ -22,7 +22,7 @@ jobs: if: github.repository_owner == 'zephyrproject-rtos' runs-on: zephyr-runner-linux-x64-4xlarge container: - image: ghcr.io/zephyrproject-rtos/ci:v0.24.11 + image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 options: '--entrypoint /bin/bash' volumes: - /repo-cache/zephyrproject:/github/cache/zephyrproject @@ -120,7 +120,7 @@ jobs: needs: twister-build-prep if: needs.twister-build-prep.outputs.size != 0 container: - image: ghcr.io/zephyrproject-rtos/ci:v0.24.11 + image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 options: '--entrypoint /bin/bash' volumes: - /repo-cache/zephyrproject:/github/cache/zephyrproject From 5797fbc10197e9795f97e3d74adc8e799ca20900 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Wed, 15 Mar 2023 21:51:42 +0900 Subject: [PATCH 0285/1906] ci: Use Zephyr SDK 0.16.0 This commit updates the CI workflows to use the Zephyr SDK 0.16.0 for building and testing Zephyr in the CI. Signed-off-by: Stephanos Ioannidis --- .github/workflows/bluetooth-tests.yaml | 2 +- .github/workflows/clang.yaml | 2 +- .github/workflows/codecov.yaml | 2 +- .github/workflows/errno.yml | 2 +- .github/workflows/footprint-tracking.yml | 2 +- .github/workflows/footprint.yml | 2 +- .github/workflows/twister.yaml | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/bluetooth-tests.yaml b/.github/workflows/bluetooth-tests.yaml index e117e9d6d0c4..5c4153cc1266 100644 --- a/.github/workflows/bluetooth-tests.yaml +++ b/.github/workflows/bluetooth-tests.yaml @@ -27,7 +27,7 @@ jobs: - /repo-cache/zephyrproject:/github/cache/zephyrproject env: ZEPHYR_TOOLCHAIN_VARIANT: zephyr - ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.15.2 + ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.16.0 BSIM_OUT_PATH: /opt/bsim/ BSIM_COMPONENTS_PATH: /opt/bsim/components EDTT_PATH: ../tools/edtt diff --git a/.github/workflows/clang.yaml b/.github/workflows/clang.yaml index a68907cb636e..214bf6fe2178 100644 --- a/.github/workflows/clang.yaml +++ b/.github/workflows/clang.yaml @@ -20,7 +20,7 @@ jobs: matrix: platform: ["native_posix"] env: - ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.15.2 + ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.16.0 LLVM_TOOLCHAIN_PATH: /usr/lib/llvm-15 COMMIT_RANGE: ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} BASE_REF: ${{ github.base_ref }} diff --git a/.github/workflows/codecov.yaml b/.github/workflows/codecov.yaml index 7a88dd506a06..7a1ceb30a56b 100644 --- a/.github/workflows/codecov.yaml +++ b/.github/workflows/codecov.yaml @@ -22,7 +22,7 @@ jobs: matrix: platform: ["native_posix", "qemu_x86", "unit_testing"] env: - ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.15.2 + ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.16.0 steps: - name: Apply container owner mismatch workaround run: | diff --git a/.github/workflows/errno.yml b/.github/workflows/errno.yml index f55f508b5866..5ff27b801528 100644 --- a/.github/workflows/errno.yml +++ b/.github/workflows/errno.yml @@ -12,7 +12,7 @@ jobs: container: image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 env: - ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.15.2 + ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.16.0 steps: - name: Apply container owner mismatch workaround diff --git a/.github/workflows/footprint-tracking.yml b/.github/workflows/footprint-tracking.yml index d10056da6fef..0d4c18bc7553 100644 --- a/.github/workflows/footprint-tracking.yml +++ b/.github/workflows/footprint-tracking.yml @@ -27,7 +27,7 @@ jobs: strategy: fail-fast: false env: - ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.15.2 + ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.16.0 ZEPHYR_TOOLCHAIN_VARIANT: zephyr steps: - name: Apply container owner mismatch workaround diff --git a/.github/workflows/footprint.yml b/.github/workflows/footprint.yml index de6f5c3016ec..660776fbc525 100644 --- a/.github/workflows/footprint.yml +++ b/.github/workflows/footprint.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: false env: - ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.15.2 + ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.16.0 ZEPHYR_TOOLCHAIN_VARIANT: zephyr steps: - name: Apply container owner mismatch workaround diff --git a/.github/workflows/twister.yaml b/.github/workflows/twister.yaml index 1bb6a44a7595..eb0a620b2eec 100644 --- a/.github/workflows/twister.yaml +++ b/.github/workflows/twister.yaml @@ -34,7 +34,7 @@ jobs: MATRIX_SIZE: 10 PUSH_MATRIX_SIZE: 15 DAILY_MATRIX_SIZE: 80 - ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.15.2 + ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.16.0 BSIM_OUT_PATH: /opt/bsim/ BSIM_COMPONENTS_PATH: /opt/bsim/components TESTS_PER_BUILDER: 700 @@ -129,7 +129,7 @@ jobs: matrix: subset: ${{fromJSON(needs.twister-build-prep.outputs.subset)}} env: - ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.15.2 + ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.16.0 BSIM_OUT_PATH: /opt/bsim/ BSIM_COMPONENTS_PATH: /opt/bsim/components TWISTER_COMMON: ' --force-color --inline-logs -v -N -M --retry-failed 3 ' From b4538ffcdbfe6b0384601861c9469b93740f881a Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Wed, 15 Mar 2023 22:17:48 +0900 Subject: [PATCH 0286/1906] doc: Update installation instructions for Zephyr SDK 0.16.0 This commit updates the Zephyr SDK installation instructions for the Zephyr SDK 0.16.0 release. Note that the distribution bundle archive format has been changed from `tar.gz` to `tar.xz` for Linux and macOS, and from `zip` to `7z` for Windows. Signed-off-by: Stephanos Ioannidis --- doc/develop/getting_started/index.rst | 38 +++++++++---------- .../getting_started/installation_linux.rst | 14 +++---- doc/develop/toolchains/zephyr_sdk.rst | 36 +++++++++--------- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/doc/develop/getting_started/index.rst b/doc/develop/getting_started/index.rst index e7c6f6810a64..189ebfa24898 100644 --- a/doc/develop/getting_started/index.rst +++ b/doc/develop/getting_started/index.rst @@ -166,7 +166,7 @@ The current minimum required version for the main dependencies are: .. code-block:: console choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' - choco install ninja gperf python git dtc-msys2 wget unzip + choco install ninja gperf python git dtc-msys2 wget 7zip #. Close the window and open a new ``cmd.exe`` window **as a regular user** to continue. @@ -502,8 +502,8 @@ that are used to emulate, flash and debug Zephyr applications. .. code-block:: bash cd ~ - wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_linux-x86_64.tar.gz - wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/sha256.sum | shasum --check --ignore-missing + wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/zephyr-sdk-0.16.0_linux-x86_64.tar.xz + wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/sha256.sum | shasum --check --ignore-missing If your host architecture is 64-bit ARM (for example, Raspberry Pi), replace ``x86_64`` with ``aarch64`` in order to download the 64-bit ARM Linux SDK. @@ -512,7 +512,7 @@ that are used to emulate, flash and debug Zephyr applications. .. code-block:: bash - tar xvf zephyr-sdk-0.15.2_linux-x86_64.tar.gz + tar xvf zephyr-sdk-0.16.0_linux-x86_64.tar.xz .. note:: It is recommended to extract the Zephyr SDK bundle at one of the following locations: @@ -524,15 +524,15 @@ that are used to emulate, flash and debug Zephyr applications. * ``/opt`` * ``/usr/local`` - The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.15.2`` directory and, when + The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.16.0`` directory and, when extracted under ``$HOME``, the resulting installation path will be - ``$HOME/zephyr-sdk-0.15.2``. + ``$HOME/zephyr-sdk-0.16.0``. #. Run the Zephyr SDK bundle setup script: .. code-block:: bash - cd zephyr-sdk-0.15.2 + cd zephyr-sdk-0.16.0 ./setup.sh .. note:: @@ -546,7 +546,7 @@ that are used to emulate, flash and debug Zephyr applications. .. code-block:: bash - sudo cp ~/zephyr-sdk-0.15.2/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d + sudo cp ~/zephyr-sdk-0.16.0/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d sudo udevadm control --reload .. group-tab:: macOS @@ -559,8 +559,8 @@ that are used to emulate, flash and debug Zephyr applications. .. code-block:: bash cd ~ - wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_macos-x86_64.tar.gz - wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/sha256.sum | shasum --check --ignore-missing + wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/zephyr-sdk-0.16.0_macos-x86_64.tar.xz + wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/sha256.sum | shasum --check --ignore-missing If your host architecture is 64-bit ARM (Apple Silicon, also known as M1), replace ``x86_64`` with ``aarch64`` in order to download the 64-bit ARM macOS SDK. @@ -569,7 +569,7 @@ that are used to emulate, flash and debug Zephyr applications. .. code-block:: bash - tar xvf zephyr-sdk-0.15.2_macos-x86_64.tar.gz + tar xvf zephyr-sdk-0.16.0_macos-x86_64.tar.xz .. note:: It is recommended to extract the Zephyr SDK bundle at one of the following locations: @@ -581,15 +581,15 @@ that are used to emulate, flash and debug Zephyr applications. * ``/opt`` * ``/usr/local`` - The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.15.2`` directory and, when + The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.16.0`` directory and, when extracted under ``$HOME``, the resulting installation path will be - ``$HOME/zephyr-sdk-0.15.2``. + ``$HOME/zephyr-sdk-0.16.0``. #. Run the Zephyr SDK bundle setup script: .. code-block:: bash - cd zephyr-sdk-0.15.2 + cd zephyr-sdk-0.16.0 ./setup.sh .. note:: @@ -610,13 +610,13 @@ that are used to emulate, flash and debug Zephyr applications. .. code-block:: console cd %HOMEPATH% - wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_windows-x86_64.zip + wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/zephyr-sdk-0.16.0_windows-x86_64.7z #. Extract the Zephyr SDK bundle archive: .. code-block:: console - unzip zephyr-sdk-0.15.2_windows-x86_64.zip + 7z x zephyr-sdk-0.16.0_windows-x86_64.7z .. note:: It is recommended to extract the Zephyr SDK bundle at one of the following locations: @@ -624,15 +624,15 @@ that are used to emulate, flash and debug Zephyr applications. * ``%HOMEPATH%`` * ``%PROGRAMFILES%`` - The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.15.2`` directory and, when + The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.16.0`` directory and, when extracted under ``%HOMEPATH%``, the resulting installation path will be - ``%HOMEPATH%\zephyr-sdk-0.15.2``. + ``%HOMEPATH%\zephyr-sdk-0.16.0``. #. Run the Zephyr SDK bundle setup script: .. code-block:: console - cd zephyr-sdk-0.15.2 + cd zephyr-sdk-0.16.0 setup.cmd .. note:: diff --git a/doc/develop/getting_started/installation_linux.rst b/doc/develop/getting_started/installation_linux.rst index 706b6eff65da..0e044eab450c 100644 --- a/doc/develop/getting_started/installation_linux.rst +++ b/doc/develop/getting_started/installation_linux.rst @@ -232,10 +232,10 @@ Follow these steps to install the Zephyr SDK: .. code-block:: bash - wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_linux-x86_64.tar.gz - wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/sha256.sum | shasum --check --ignore-missing + wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/zephyr-sdk-0.16.0_linux-x86_64.tar.xz + wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/sha256.sum | shasum --check --ignore-missing - You can change ``0.15.2`` to another version if needed; the `Zephyr SDK + You can change ``0.16.0`` to another version if needed; the `Zephyr SDK Releases`_ page contains all available SDK releases. If your host architecture is 64-bit ARM (for example, Raspberry Pi), replace @@ -246,13 +246,13 @@ Follow these steps to install the Zephyr SDK: .. code-block:: bash cd - tar xvf zephyr-sdk-0.15.2_linux-x86_64.tar.gz + tar xvf zephyr-sdk-0.16.0_linux-x86_64.tar.xz #. Run the Zephyr SDK bundle setup script: .. code-block:: bash - cd zephyr-sdk-0.15.2 + cd zephyr-sdk-0.16.0 ./setup.sh If this fails, make sure Zephyr's dependencies were installed as described @@ -271,9 +271,9 @@ If you relocate the SDK directory, you need to re-run the setup script. * ``/opt`` * ``/usr/local`` - The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.15.2`` directory and, when + The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.16.0`` directory and, when extracted under ``$HOME``, the resulting installation path will be - ``$HOME/zephyr-sdk-0.15.2``. + ``$HOME/zephyr-sdk-0.16.0``. If you install the Zephyr SDK outside any of these locations, you must register the Zephyr SDK in the CMake package registry by running the setup diff --git a/doc/develop/toolchains/zephyr_sdk.rst b/doc/develop/toolchains/zephyr_sdk.rst index 52af0cf5a112..c12c72e08cd2 100644 --- a/doc/develop/toolchains/zephyr_sdk.rst +++ b/doc/develop/toolchains/zephyr_sdk.rst @@ -65,10 +65,10 @@ Install Zephyr SDK on Linux .. code-block:: bash - wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_linux-x86_64.tar.gz - wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/sha256.sum | shasum --check --ignore-missing + wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/zephyr-sdk-0.16.0_linux-x86_64.tar.xz + wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/sha256.sum | shasum --check --ignore-missing - You can change ``0.15.2`` to another version if needed; the `Zephyr SDK + You can change ``0.16.0`` to another version if needed; the `Zephyr SDK Releases`_ page contains all available SDK releases. If your host architecture is 64-bit ARM (for example, Raspberry Pi), replace @@ -79,13 +79,13 @@ Install Zephyr SDK on Linux .. code-block:: bash cd - tar xvf zephyr-sdk-0.15.2_linux-x86_64.tar.gz + tar xvf zephyr-sdk-0.16.0_linux-x86_64.tar.xz #. Run the Zephyr SDK bundle setup script: .. code-block:: bash - cd zephyr-sdk-0.15.2 + cd zephyr-sdk-0.16.0 ./setup.sh If this fails, make sure Zephyr's dependencies were installed as described @@ -105,9 +105,9 @@ If you relocate the SDK directory, you need to re-run the setup script. * ``/opt`` * ``/usr/local`` - The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.15.2`` directory and, when + The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.16.0`` directory and, when extracted under ``$HOME``, the resulting installation path will be - ``$HOME/zephyr-sdk-0.15.2``. + ``$HOME/zephyr-sdk-0.16.0``. .. _toolchain_zephyr_sdk_install_macos: @@ -119,8 +119,8 @@ Install Zephyr SDK on macOS .. code-block:: bash cd ~ - wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_macos-x86_64.tar.gz - wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/sha256.sum | shasum --check --ignore-missing + wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/zephyr-sdk-0.16.0_macos-x86_64.tar.xz + wget -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/sha256.sum | shasum --check --ignore-missing If your host architecture is 64-bit ARM (Apple Silicon, also known as M1), replace ``x86_64`` with ``aarch64`` in order to download the 64-bit ARM macOS SDK. @@ -129,7 +129,7 @@ Install Zephyr SDK on macOS .. code-block:: bash - tar xvf zephyr-sdk-0.15.2_macos-x86_64.tar.gz + tar xvf zephyr-sdk-0.16.0_macos-x86_64.tar.xz .. note:: It is recommended to extract the Zephyr SDK bundle at one of the following @@ -142,15 +142,15 @@ Install Zephyr SDK on macOS * ``/opt`` * ``/usr/local`` - The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.15.2`` directory and, when + The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.16.0`` directory and, when extracted under ``$HOME``, the resulting installation path will be - ``$HOME/zephyr-sdk-0.15.2``. + ``$HOME/zephyr-sdk-0.16.0``. #. Run the Zephyr SDK bundle setup script: .. code-block:: bash - cd zephyr-sdk-0.15.2 + cd zephyr-sdk-0.16.0 ./setup.sh .. note:: @@ -171,13 +171,13 @@ Install Zephyr SDK on Windows .. code-block:: console cd %HOMEPATH% - wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_windows-x86_64.zip + wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/zephyr-sdk-0.16.0_windows-x86_64.7z #. Extract the Zephyr SDK bundle archive: .. code-block:: console - unzip zephyr-sdk-0.15.2_windows-x86_64.zip + 7z x zephyr-sdk-0.16.0_windows-x86_64.7z .. note:: It is recommended to extract the Zephyr SDK bundle at one of the following @@ -186,15 +186,15 @@ Install Zephyr SDK on Windows * ``%HOMEPATH%`` * ``%PROGRAMFILES%`` - The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.15.2`` directory and, when + The Zephyr SDK bundle archive contains the ``zephyr-sdk-0.16.0`` directory and, when extracted under ``%HOMEPATH%``, the resulting installation path will be - ``%HOMEPATH%\zephyr-sdk-0.15.2``. + ``%HOMEPATH%\zephyr-sdk-0.16.0``. #. Run the Zephyr SDK bundle setup script: .. code-block:: console - cd zephyr-sdk-0.15.2 + cd zephyr-sdk-0.16.0 setup.cmd .. note:: From ca44b34994c2402b8c1b0e896d72c57cf06b315f Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 15 Mar 2023 16:44:08 +0530 Subject: [PATCH 0287/1906] Bluetooth: Controller: Fix ISO Sync Receiver reception abort Fix ISO Sync Receiver PDU reception to enqueue towards ULL any PDUs that where received before the BIG event in unreserved timespace is aborted due to overlap with other radio events. Signed-off-by: Vinayak Kariappa Chettimada --- .../ll_sw/nordic/lll/lll_sync_iso.c | 297 ++++++++++-------- 1 file changed, 164 insertions(+), 133 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c index 48eed1ee209b..824dedf99822 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c @@ -47,6 +47,8 @@ static int prepare_cb_common(struct lll_prepare_param *p); static void abort_cb(struct lll_prepare_param *prepare_param, void *param); static void isr_rx_estab(void *param); static void isr_rx(void *param); +static void isr_rx_done(void *param); +static void isr_done(void *param); static void next_chan_calc(struct lll_sync_iso *lll, uint16_t event_counter, uint16_t data_chan_id); static void isr_rx_iso_data_valid(const struct lll_sync_iso *const lll, @@ -398,7 +400,7 @@ static void abort_cb(struct lll_prepare_param *prepare_param, void *param) /* NOTE: This is not a prepare being cancelled */ if (!prepare_param) { - radio_isr_set(lll_isr_done, param); + radio_isr_set(isr_done, param); radio_disable(); return; } @@ -480,7 +482,6 @@ static void isr_rx(void *param) { struct lll_sync_iso_stream *stream; struct node_rx_pdu *node_rx; - struct event_done_extra *e; struct lll_sync_iso *lll; uint8_t access_addr[4]; uint16_t data_chan_id; @@ -497,7 +498,6 @@ static void isr_rx(void *param) uint32_t hcto; uint8_t bis; uint8_t nse; - uint8_t bn; if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) { lll_prof_latency_capture(); @@ -813,136 +813,7 @@ static void isr_rx(void *param) goto isr_rx_next_subevent; } - /* Enqueue PDUs to ULL */ - node_rx = NULL; - lll->stream_curr = 0U; - payload_index = lll->payload_tail; - for (bis_idx = 0U; bis_idx < lll->num_bis; bis_idx++) { - struct lll_sync_iso_stream *stream; - uint8_t payload_tail; - uint8_t stream_curr; - uint16_t stream_handle; - - stream_handle = lll->stream_handle[lll->stream_curr]; - stream = ull_sync_iso_lll_stream_get(stream_handle); - /* Skip BIS indices not synchronized. bis_index is 0x01 to 0x1F, - * where as bis_idx is 0 indexed. - */ - if ((bis_idx + 1U) != stream->bis_index) { - continue; - } - - payload_tail = lll->payload_tail; - bn = lll->bn; - while (bn--) { - if (lll->payload[bis_idx][payload_tail]) { - node_rx = - lll->payload[bis_idx][payload_tail]; - lll->payload[bis_idx][payload_tail] = NULL; - - iso_rx_put(node_rx->hdr.link, node_rx); - } else { - /* Check if there are 2 free rx buffers, one - * will be consumed to generate PDU with invalid - * status, and the other is to ensure a PDU can - * be setup for the radio DMA to receive in the - * next sub_interval/iso_interval. - */ - node_rx = ull_iso_pdu_rx_alloc_peek(2U); - if (node_rx) { - struct pdu_bis *pdu; - uint16_t handle; - - ull_iso_pdu_rx_alloc(); - - pdu = (void *)node_rx->pdu; - pdu->ll_id = PDU_BIS_LLID_COMPLETE_END; - pdu->len = 0U; - - handle = LL_BIS_SYNC_HANDLE_FROM_IDX(stream_handle); - isr_rx_iso_data_invalid(lll, bn, handle, - node_rx); - - iso_rx_put(node_rx->hdr.link, node_rx); - } - } - - payload_index = payload_tail + 1U; - if (payload_index >= lll->payload_count_max) { - payload_index = 0U; - } - payload_tail = payload_index; - } - - stream_curr = lll->stream_curr + 1U; - if (stream_curr < lll->stream_count) { - lll->stream_curr = stream_curr; - } - } - lll->payload_tail = payload_index; - -#if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) - if (node_rx) { - iso_rx_sched(); - } -#endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ - - e = ull_event_done_extra_get(); - LL_ASSERT(e); - - /* Check if BIG terminate procedure received */ - if (lll->term_reason) { - e->type = EVENT_DONE_EXTRA_TYPE_SYNC_ISO_TERMINATE; - - lll_isr_cleanup(param); - - return; - - /* Check if BIG Channel Map Update */ - } else if (lll->chm_chan_count) { - const uint16_t event_counter = lll->payload_count / lll->bn; - - /* Bluetooth Core Specification v5.3 Vol 6, Part B, - * Section 5.5.2 BIG Control Procedures - * - * When a Synchronized Receiver receives such a PDU where - * (instant - bigEventCounter) mod 65536 is greater than or - * equal to 32767 (because the instant is in the past), the - * the Link Layer may stop synchronization with the BIG. - */ - - /* Note: We are not validating whether the control PDU was - * received after the instant but apply the new channel map. - * If the channel map was new at or after the instant and the - * the channel at the event counter did not match then the - * control PDU would not have been received. - */ - if (((event_counter - lll->ctrl_instant) & 0xFFFF) <= 0x7FFF) { - (void)memcpy(lll->data_chan_map, lll->chm_chan_map, - sizeof(lll->data_chan_map)); - lll->data_chan_count = lll->chm_chan_count; - lll->chm_chan_count = 0U; - } - } - - /* Calculate and place the drift information in done event */ - e->type = EVENT_DONE_EXTRA_TYPE_SYNC_ISO; - e->trx_cnt = trx_cnt; - e->crc_valid = crc_ok_anchor; - - if (trx_cnt) { - e->drift.preamble_to_addr_us = addr_us_get(lll->phy); - e->drift.start_to_address_actual_us = - radio_tmr_aa_restore() - radio_tmr_ready_restore(); - e->drift.window_widening_event_us = - lll->window_widening_event_us; - - /* Reset window widening, as anchor point sync-ed */ - lll->window_widening_event_us = 0U; - lll->window_size_event_us = 0U; - } - - lll_isr_cleanup(param); + isr_rx_done(param); if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) { lll_prof_send(); @@ -1149,6 +1020,166 @@ static void isr_rx(void *param) } } +static void isr_rx_done(void *param) +{ + struct node_rx_pdu *node_rx; + struct event_done_extra *e; + struct lll_sync_iso *lll; + uint8_t payload_index; + uint8_t bis_idx; + uint8_t bn; + + /* Enqueue PDUs to ULL */ + node_rx = NULL; + lll = param; + lll->stream_curr = 0U; + payload_index = lll->payload_tail; + for (bis_idx = 0U; bis_idx < lll->num_bis; bis_idx++) { + struct lll_sync_iso_stream *stream; + uint8_t payload_tail; + uint8_t stream_curr; + uint16_t stream_handle; + + stream_handle = lll->stream_handle[lll->stream_curr]; + stream = ull_sync_iso_lll_stream_get(stream_handle); + /* Skip BIS indices not synchronized. bis_index is 0x01 to 0x1F, + * where as bis_idx is 0 indexed. + */ + if ((bis_idx + 1U) != stream->bis_index) { + continue; + } + + payload_tail = lll->payload_tail; + bn = lll->bn; + while (bn--) { + if (lll->payload[bis_idx][payload_tail]) { + node_rx = + lll->payload[bis_idx][payload_tail]; + lll->payload[bis_idx][payload_tail] = NULL; + + iso_rx_put(node_rx->hdr.link, node_rx); + } else { + /* Check if there are 2 free rx buffers, one + * will be consumed to generate PDU with invalid + * status, and the other is to ensure a PDU can + * be setup for the radio DMA to receive in the + * next sub_interval/iso_interval. + */ + node_rx = ull_iso_pdu_rx_alloc_peek(2U); + if (node_rx) { + struct pdu_bis *pdu; + uint16_t handle; + + ull_iso_pdu_rx_alloc(); + + pdu = (void *)node_rx->pdu; + pdu->ll_id = PDU_BIS_LLID_COMPLETE_END; + pdu->len = 0U; + + handle = LL_BIS_SYNC_HANDLE_FROM_IDX(stream_handle); + isr_rx_iso_data_invalid(lll, bn, handle, + node_rx); + + iso_rx_put(node_rx->hdr.link, node_rx); + } + } + + payload_index = payload_tail + 1U; + if (payload_index >= lll->payload_count_max) { + payload_index = 0U; + } + payload_tail = payload_index; + } + + stream_curr = lll->stream_curr + 1U; + if (stream_curr < lll->stream_count) { + lll->stream_curr = stream_curr; + } + } + lll->payload_tail = payload_index; + +#if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) + if (node_rx) { + iso_rx_sched(); + } +#endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ + + e = ull_event_done_extra_get(); + LL_ASSERT(e); + + /* Check if BIG terminate procedure received */ + if (lll->term_reason) { + e->type = EVENT_DONE_EXTRA_TYPE_SYNC_ISO_TERMINATE; + + goto isr_done_cleanup; + + /* Check if BIG Channel Map Update */ + } else if (lll->chm_chan_count) { + const uint16_t event_counter = lll->payload_count / lll->bn; + + /* Bluetooth Core Specification v5.3 Vol 6, Part B, + * Section 5.5.2 BIG Control Procedures + * + * When a Synchronized Receiver receives such a PDU where + * (instant - bigEventCounter) mod 65536 is greater than or + * equal to 32767 (because the instant is in the past), the + * the Link Layer may stop synchronization with the BIG. + */ + + /* Note: We are not validating whether the control PDU was + * received after the instant but apply the new channel map. + * If the channel map was new at or after the instant and the + * the channel at the event counter did not match then the + * control PDU would not have been received. + */ + if (((event_counter - lll->ctrl_instant) & 0xFFFF) <= 0x7FFF) { + (void)memcpy(lll->data_chan_map, lll->chm_chan_map, + sizeof(lll->data_chan_map)); + lll->data_chan_count = lll->chm_chan_count; + lll->chm_chan_count = 0U; + } + } + + /* Calculate and place the drift information in done event */ + e->type = EVENT_DONE_EXTRA_TYPE_SYNC_ISO; + e->trx_cnt = trx_cnt; + e->crc_valid = crc_ok_anchor; + + if (trx_cnt) { + e->drift.preamble_to_addr_us = addr_us_get(lll->phy); + e->drift.start_to_address_actual_us = + radio_tmr_aa_restore() - radio_tmr_ready_restore(); + e->drift.window_widening_event_us = + lll->window_widening_event_us; + + /* Reset window widening, as anchor point sync-ed */ + lll->window_widening_event_us = 0U; + lll->window_size_event_us = 0U; + } + +isr_done_cleanup: + lll_isr_cleanup(param); +} + +static void isr_done(void *param) +{ + if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) { + lll_prof_latency_capture(); + } + + lll_isr_status_reset(); + + if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) { + lll_prof_cputime_capture(); + } + + isr_rx_done(param); + + if (IS_ENABLED(CONFIG_BT_CTLR_PROFILE_ISR)) { + lll_prof_send(); + } +} + static void next_chan_calc(struct lll_sync_iso *lll, uint16_t event_counter, uint16_t data_chan_id) { From 947ef4c96bc768462b5af99f22cb69eccc8c53fb Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 15 Mar 2023 15:31:24 +0530 Subject: [PATCH 0288/1906] Bluetooth: Controller: Remove redundant EVENT_IFS_US in BIS timing Remove redundant EVENT_IFS_US used in Control PDU timing calculation. The BIG radio event ends with Control Subevent and hence there is no need to add EVENT_IFS_US at the end of the BIG event. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/ll_sw/ull_adv_iso.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index dffef2b3fb26..78afbff27436 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -271,7 +271,7 @@ uint8_t ll_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis, phy, lll_adv_iso->phy_flags) + EVENT_MSS_US; ctrl_spacing = PDU_BIS_US(sizeof(struct pdu_big_ctrl), encryption, phy, - lll_adv_iso->phy_flags) + EVENT_IFS_US; + lll_adv_iso->phy_flags); latency_packing = lll_adv_iso->sub_interval * lll_adv_iso->nse * lll_adv_iso->num_bis; event_spacing = latency_packing + ctrl_spacing + @@ -916,8 +916,7 @@ static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, lll_iso->phy_flags) + EVENT_MSS_US; ctrl_spacing = PDU_BIS_US(sizeof(struct pdu_big_ctrl), lll_iso->enc, - lll_iso->phy, lll_iso->phy_flags) + - EVENT_IFS_US; + lll_iso->phy, lll_iso->phy_flags); slot_us = (pdu_spacing * lll_iso->nse * lll_iso->num_bis) + ctrl_spacing; slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; From 14138d4a3426592bf899001a1ad9e4385d245f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Bene=C5=A1?= Date: Wed, 15 Mar 2023 13:43:51 +0100 Subject: [PATCH 0289/1906] Bluetooth: Controller: Add coexistence implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To enable Bluetooth controller coexistence feature, there is implementation of ticker task, which aborts any ongoing radio events during assertion of the grant pin. This solves the co-existence issue in the role of the subordinate transceiver. Signed-off-by: Tomáš Beneš --- .../net/wireless/gpio-radio-coex.yaml | 31 +++ .../beacon/boards/nrf52840dk_nrf52840.overlay | 16 ++ samples/bluetooth/beacon/prj-coex.conf | 7 + samples/bluetooth/beacon/sample.yaml | 6 + subsys/bluetooth/controller/CMakeLists.txt | 1 + .../bluetooth/controller/Kconfig.ll_sw_split | 2 + .../bluetooth/controller/coex/CMakeLists.txt | 5 + subsys/bluetooth/controller/coex/Kconfig | 19 ++ .../bluetooth/controller/coex/coex_ticker.c | 212 ++++++++++++++++++ subsys/bluetooth/controller/coex/readme.rst | 22 ++ subsys/bluetooth/controller/include/ll.h | 2 + .../controller/ll_sw/nordic/hal/nrf5/debug.h | 36 +++ subsys/bluetooth/controller/ll_sw/ull.c | 21 +- 13 files changed, 378 insertions(+), 2 deletions(-) create mode 100644 dts/bindings/net/wireless/gpio-radio-coex.yaml create mode 100644 samples/bluetooth/beacon/boards/nrf52840dk_nrf52840.overlay create mode 100644 samples/bluetooth/beacon/prj-coex.conf create mode 100644 subsys/bluetooth/controller/coex/CMakeLists.txt create mode 100644 subsys/bluetooth/controller/coex/Kconfig create mode 100644 subsys/bluetooth/controller/coex/coex_ticker.c create mode 100644 subsys/bluetooth/controller/coex/readme.rst diff --git a/dts/bindings/net/wireless/gpio-radio-coex.yaml b/dts/bindings/net/wireless/gpio-radio-coex.yaml new file mode 100644 index 000000000000..e21cc53d4339 --- /dev/null +++ b/dts/bindings/net/wireless/gpio-radio-coex.yaml @@ -0,0 +1,31 @@ +# Copyright (c) 2022-2023 Dronetag s.r.o. +# SPDX-License-Identifier: Apache-2.0 + +description: | + Generic representation of Coexistance pin interface for radios. This + interface is usually available on Wifi/Bluetooth/LTE modules to + interact with each other when sharing same antenna. This prevents + any collisions between transmissions from different modules. The grant + signal should signal that the external transceiver/module is not + transmitting. Therefore you are free to perform any TX operations as + required. When grant pin becomes inactive then you have time to + finish all of the ongoing TX operations before the external + transceiver begins their transmission. This is specified by the + grant-delay-us property. + +compatible: "gpio-radio-coex" + +include: base.yaml + +properties: + grant-gpios: + type: phandle-array + required: true + description: | + GPIO input from the external transceiver + + grant-delay-us: + type: int + required: true + description: | + Delay after assertion for the external transceiver operation diff --git a/samples/bluetooth/beacon/boards/nrf52840dk_nrf52840.overlay b/samples/bluetooth/beacon/boards/nrf52840dk_nrf52840.overlay new file mode 100644 index 000000000000..d7a5571e6c55 --- /dev/null +++ b/samples/bluetooth/beacon/boards/nrf52840dk_nrf52840.overlay @@ -0,0 +1,16 @@ +/* + * Copyright 2022 Dronetag + * + * SPDX-License-Identifier: Apache-2.0 + */ +/{ + coex_gpio: coex { + compatible = "gpio-radio-coex"; + grant-gpios = <&gpio1 0 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW)>; + grant-delay-us = <150>; + }; +}; + +&radio { + coex = <&coex_gpio>; +}; diff --git a/samples/bluetooth/beacon/prj-coex.conf b/samples/bluetooth/beacon/prj-coex.conf new file mode 100644 index 000000000000..6dafb5b261be --- /dev/null +++ b/samples/bluetooth/beacon/prj-coex.conf @@ -0,0 +1,7 @@ +CONFIG_BT=y +CONFIG_BT_DEBUG_LOG=y +CONFIG_BT_DEVICE_NAME="Test beacon" + +CONFIG_BT_LL_SW_SPLIT=y +CONFIG_BT_CTLR_COEX_DRIVERS=y +CONFIG_BT_CTLR_COEX_TICKER=y diff --git a/samples/bluetooth/beacon/sample.yaml b/samples/bluetooth/beacon/sample.yaml index fca28387d2c8..fce3d96b19ac 100644 --- a/samples/bluetooth/beacon/sample.yaml +++ b/samples/bluetooth/beacon/sample.yaml @@ -7,3 +7,9 @@ tests: tags: bluetooth integration_platforms: - qemu_cortex_m3 + + sample.bluetooth.beacon-coex: + extra_args: CONF_FILE="prj-coex.conf" + harness: bluetooth + platform_allow: nrf52840dk_nrf52840 + tags: bluetooth diff --git a/subsys/bluetooth/controller/CMakeLists.txt b/subsys/bluetooth/controller/CMakeLists.txt index d2e083a00866..9e3a382f2ed9 100644 --- a/subsys/bluetooth/controller/CMakeLists.txt +++ b/subsys/bluetooth/controller/CMakeLists.txt @@ -155,6 +155,7 @@ if(CONFIG_BT_LL_SW_SPLIT) CONFIG_BT_HCI_MESH_EXT ll_sw/ll_mesh.c ) + add_subdirectory_ifdef(CONFIG_BT_CTLR_COEX_DRIVERS coex) endif() if(CONFIG_SOC_COMPATIBLE_NRF) diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index d5a2c99a045f..acd2fd848c79 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -969,6 +969,8 @@ config BT_CTLR_USER_CPR_ANCHOR_POINT_MOVE endmenu +source "subsys/bluetooth/controller/coex/Kconfig" + comment "BLE Controller debug configuration" config BT_CTLR_PROFILE_ISR diff --git a/subsys/bluetooth/controller/coex/CMakeLists.txt b/subsys/bluetooth/controller/coex/CMakeLists.txt new file mode 100644 index 000000000000..eaa89c2b4f81 --- /dev/null +++ b/subsys/bluetooth/controller/coex/CMakeLists.txt @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_COEX_TICKER coex_ticker.c +) diff --git a/subsys/bluetooth/controller/coex/Kconfig b/subsys/bluetooth/controller/coex/Kconfig new file mode 100644 index 000000000000..31754fbf52cc --- /dev/null +++ b/subsys/bluetooth/controller/coex/Kconfig @@ -0,0 +1,19 @@ +# Bluetooth co-existence configuration options + +# Copyright (c) 2022 Dronetag +# SPDX-License-Identifier: Apache-2.0 + +menuconfig BT_CTLR_COEX_DRIVERS + bool "Bluetooth Co-existence Drivers" + default n + depends on BT_CTLR + +if BT_CTLR_COEX_DRIVERS + +config BT_CTLR_COEX_TICKER + bool "Coexistence Ticker" + help + When enabled Coexistence device implementation is included in + the controller. Which abort any radio states, when coex pin is asserted. + +endif # BT_CTLR_COEX_DRIVERS diff --git a/subsys/bluetooth/controller/coex/coex_ticker.c b/subsys/bluetooth/controller/coex/coex_ticker.c new file mode 100644 index 000000000000..fa5c22f38316 --- /dev/null +++ b/subsys/bluetooth/controller/coex/coex_ticker.c @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2022 Dronetag + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "controller/hal/ticker.h" +#include "controller/ticker/ticker.h" +#include "controller/include/ll.h" +#include "controller/ll_sw/nordic/hal/nrf5/debug.h" + +LOG_MODULE_REGISTER(coex_ticker); + +#define COEX_RADIO_WORK_DELAY_US 50 +#define COEX_RADIO_WORK_RESCHEDULE_DELAY_US 200 + +struct coex_ticker_config { + struct gpio_dt_spec grant_spec; + size_t grant_delay_us; +}; + +struct coex_ticker_data { + const struct device *dev; + struct gpio_callback grant_irq_cb; +}; + +static int time_slot_delay(uint32_t ticks_at_expire, uint32_t ticks_delay, + ticker_timeout_func callback, void *context) +{ + uint8_t instance_index; + uint8_t ticker_id; + int err; + + ll_coex_ticker_id_get(&instance_index, &ticker_id); + + /* start a secondary one-shot ticker after ticks_delay, + * this will let any radio role to gracefully abort and release the + * Radio h/w. + */ + err = ticker_start(instance_index, /* Radio instance ticker */ + 1, /* user id for link layer ULL_HIGH */ + /* (MAYFLY_CALL_ID_WORKER) */ + ticker_id, /* ticker_id */ + ticks_at_expire, /* current tick */ + ticks_delay, /* one-shot delayed timeout */ + 0, /* periodic timeout */ + 0, /* periodic remainder */ + 0, /* lazy, voluntary skips */ + 0, + callback, /* handler for executing radio abort or */ + /* coex work */ + context, /* the context for the coex operation */ + NULL, /* no op callback */ + NULL); + + return err; +} + + +static void time_slot_callback_work(uint32_t ticks_at_expire, + uint32_t ticks_drift, + uint32_t remainder, + uint16_t lazy, uint8_t force, + void *context) +{ + int ret; + uint8_t instance_index; + uint8_t ticker_id; + const struct device *dev = context; + const struct coex_ticker_config *config = dev->config; + + __ASSERT(ll_radio_state_is_idle(), + "Radio is on during coex operation.\n"); + + /* Read grant pin */ + if (gpio_pin_get_dt(&config->grant_spec) == 0) { + DEBUG_COEX_GRANT(1); + + if (!ll_radio_state_is_idle()) { + ll_radio_state_abort(); + } + /* Schedule another check for grant pin and abort any events scheduled */ + time_slot_delay(ticker_ticks_now_get(), + HAL_TICKER_US_TO_TICKS(COEX_RADIO_WORK_RESCHEDULE_DELAY_US), + time_slot_callback_work, + context); + } else { + LOG_DBG("COEX Inhibit Off"); + DEBUG_COEX_IRQ(0); + DEBUG_COEX_GRANT(0); + + /* Enable coex pin interrupt */ + gpio_pin_interrupt_configure_dt(&config->grant_spec, GPIO_INT_EDGE_TO_INACTIVE); + + /* Stop the time slot ticker */ + ll_coex_ticker_id_get(&instance_index, &ticker_id); + + ret = ticker_stop(instance_index, 0, ticker_id, NULL, NULL); + if (ret != TICKER_STATUS_SUCCESS && + ret != TICKER_STATUS_BUSY) { + __ASSERT(0, "Failed to stop ticker.\n"); + } + } +} + +static void time_slot_callback_abort(uint32_t ticks_at_expire, + uint32_t ticks_drift, + uint32_t remainder, + uint16_t lazy, uint8_t force, + void *context) +{ + ll_radio_state_abort(); + time_slot_delay(ticks_at_expire, + HAL_TICKER_US_TO_TICKS(COEX_RADIO_WORK_DELAY_US), + time_slot_callback_work, + context); +} + +static int coex_ticker_grant_start(const struct device *dev) +{ + const struct coex_ticker_config *cfg = dev->config; + uint32_t err; + + err = time_slot_delay( + ticker_ticks_now_get(), + HAL_TICKER_US_TO_TICKS(cfg->grant_delay_us - COEX_RADIO_WORK_DELAY_US), + time_slot_callback_abort, + (void *)dev + ); + + if (err != TICKER_STATUS_SUCCESS && err != TICKER_STATUS_BUSY) { + return -EBUSY; + } + + return 0; +} + + +static void coex_ticker_grant_irq_handler(const struct device *dev, + struct gpio_callback *cb, uint32_t pins) +{ + ARG_UNUSED(dev); + ARG_UNUSED(pins); + struct coex_ticker_data *data = CONTAINER_OF(cb, struct coex_ticker_data, grant_irq_cb); + const struct coex_ticker_config *config = data->dev->config; + + LOG_DBG("COEX Inhibit IRQ Detected"); + DEBUG_COEX_IRQ(1); + DEBUG_COEX_GRANT(0); + + gpio_pin_interrupt_configure_dt(&config->grant_spec, GPIO_INT_DISABLE); + coex_ticker_grant_start(data->dev); +} + + +static int coex_ticker_init(const struct device *dev) +{ + const struct coex_ticker_config *config = dev->config; + struct coex_ticker_data *data = dev->data; + int res; + + data->dev = dev; + + DEBUG_COEX_INIT(); + res = gpio_pin_configure_dt(&config->grant_spec, GPIO_INPUT); + if (res) { + return res; + } + + gpio_init_callback(&data->grant_irq_cb, + coex_ticker_grant_irq_handler, + BIT(config->grant_spec.pin)); + + res = gpio_add_callback(config->grant_spec.port, &data->grant_irq_cb); + if (res) { + return res; + } + + res = gpio_pin_interrupt_configure_dt(&config->grant_spec, GPIO_INT_EDGE_TO_INACTIVE); + if (res) { + return res; + } + + return 0; +} + +#define RADIO_NODE DT_NODELABEL(radio) +#define COEX_NODE DT_PROP(RADIO_NODE, coex) + +#if DT_NODE_EXISTS(COEX_NODE) +static struct coex_ticker_config config = { + .grant_spec = GPIO_DT_SPEC_GET(COEX_NODE, grant_gpios), + .grant_delay_us = DT_PROP(COEX_NODE, grant_delay_us) +}; +static struct coex_ticker_data data; + +DEVICE_DEFINE(coex_ticker, "COEX_TICKER", &coex_ticker_init, NULL, + &data, &config, + APPLICATION, 90, + NULL); +#endif diff --git a/subsys/bluetooth/controller/coex/readme.rst b/subsys/bluetooth/controller/coex/readme.rst new file mode 100644 index 000000000000..066b3e61af9f --- /dev/null +++ b/subsys/bluetooth/controller/coex/readme.rst @@ -0,0 +1,22 @@ +****************************** +Bluetooth co-existence drivers +****************************** + +Co-existence Ticker +################### + +Implementation :file:`coex_ticker.c` is designed to utilize co-existence with another transmitter. Chips such as nordic nRF9160 provide a 1-wire co-existence interface, which allows the Bluetooth controller to suspend its activity until the other transceiver suspends its operation. + +Nordic connect SDK provides detailed description of the 1-wire and 3-wire co-existence interface for the `SoftDevice Bluetooth controller `_ + +Similarly, as in the nordic implementation of the 1-wire interface, the coexistence ticker utilizes a single pin called BLE_GRANT, which active level (high or low) is programmable by the device tree definition. + +.. code-block:: DTS + + coex_gpio: coex { + compatible = "gpio-radio-coex"; + grant-gpios = <&gpio0 0 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>; + grant-delay-us = <150>; + }; + +Whenever the grant pin transitions into non-active (such as 1 for the nRF9160). state the implementation starts a ticker job, which in predefined intervals cancels any radio events. This way all advertisements and other radioactivities are suspended until the grant pin transitions into an active state. diff --git a/subsys/bluetooth/controller/include/ll.h b/subsys/bluetooth/controller/include/ll.h index 1e446ced2c29..9facc5452bc1 100644 --- a/subsys/bluetooth/controller/include/ll.h +++ b/subsys/bluetooth/controller/include/ll.h @@ -331,5 +331,7 @@ uint8_t ll_conn_iso_accept_timeout_set(uint16_t timeout); /* External co-operation */ void ll_timeslice_ticker_id_get(uint8_t * const instance_index, uint8_t * const ticker_id); +void ll_coex_ticker_id_get(uint8_t * const instance_index, + uint8_t * const ticker_id); void ll_radio_state_abort(void); uint32_t ll_radio_state_is_idle(void); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/debug.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/debug.h index 4fa2e9d804a1..34cef5f9f69f 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/debug.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/debug.h @@ -343,3 +343,39 @@ #define DEBUG_RADIO_START_M(flag) #define DEBUG_RADIO_CLOSE_M(flag) #endif /* CONFIG_BT_CTLR_DEBUG_PINS */ + +#if defined(CONFIG_BT_CTLR_DEBUG_PINS) || \ + defined(CONFIG_BT_CTLR_DEBUG_PINS_CPUAPP) +#define DEBUG_COEX_PORT NRF_P1 +#define DEBUG_COEX_PIN_GRANT BIT(12) +#define DEBUG_COEX_PIN_IRQ BIT(13) +#define DEBUG_COEX_PIN_MASK (DEBUG_COEX_PIN_IRQ | DEBUG_COEX_PIN_GRANT) +#define DEBUG_COEX_INIT() \ + do { \ + DEBUG_COEX_PORT->DIRSET = DEBUG_COEX_PIN_MASK; \ + DEBUG_COEX_PORT->OUTCLR = DEBUG_COEX_PIN_MASK; \ + } while (0) + +#define DEBUG_COEX_GRANT(flag) \ + do { \ + if (flag) { \ + DEBUG_COEX_PORT->OUTSET = DEBUG_COEX_PIN_GRANT; \ + } else { \ + DEBUG_COEX_PORT->OUTCLR = DEBUG_COEX_PIN_GRANT; \ + } \ + } while (0) + + +#define DEBUG_COEX_IRQ(flag) \ + do { \ + if (flag) { \ + DEBUG_COEX_PORT->OUTSET = DEBUG_COEX_PIN_IRQ; \ + } else { \ + DEBUG_COEX_PORT->OUTCLR = DEBUG_COEX_PIN_IRQ; \ + } \ + } while (0) +#else +#define DEBUG_COEX_INIT() +#define DEBUG_COEX_GRANT(flag) +#define DEBUG_COEX_IRQ(flag) +#endif /* CONFIG_BT_CTLR_DEBUG_PINS */ diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index 9d6c962c94d9..ef7f2533c56e 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -168,6 +168,15 @@ #define USER_TICKER_NODES 0 #endif + +#if defined(CONFIG_BT_CTLR_COEX_TICKER) +#define COEX_TICKER_NODES 1 + /* No. of tickers reserved for coex drivers */ +#else +#define COEX_TICKER_NODES 0 +#endif + + #if defined(CONFIG_SOC_FLASH_NRF_RADIO_SYNC_TICKER) #define FLASH_TICKER_NODES 2 /* No. of tickers reserved for flash * driver @@ -201,7 +210,8 @@ BT_CONN_TICKER_NODES + \ BT_CIG_TICKER_NODES + \ USER_TICKER_NODES + \ - FLASH_TICKER_NODES) + FLASH_TICKER_NODES + \ + COEX_TICKER_NODES) /* When both central and peripheral are supported, one each Rx node will be * needed by connectable advertising and the initiator to generate connection @@ -1772,7 +1782,14 @@ void ll_timeslice_ticker_id_get(uint8_t * const instance_index, uint8_t * const ticker_id) { *instance_index = TICKER_INSTANCE_ID_CTLR; - *ticker_id = (TICKER_NODES - FLASH_TICKER_NODES); + *ticker_id = (TICKER_NODES - FLASH_TICKER_NODES - COEX_TICKER_NODES); +} + +void ll_coex_ticker_id_get(uint8_t * const instance_index, + uint8_t * const ticker_id) +{ + *instance_index = TICKER_INSTANCE_ID_CTLR; + *ticker_id = (TICKER_NODES - COEX_TICKER_NODES); } void ll_radio_state_abort(void) From ec6433e889907bac944f9facb8554c07c30e8c00 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Wed, 15 Mar 2023 15:41:08 +0100 Subject: [PATCH 0290/1906] tests: Bluetooth: Mesh: Set resync offset to 100ms for all mesh tests Since this becomes de facto a default value for most of our tests, set it by default. Signed-off-by: Pavel Vasilyev --- tests/bluetooth/bsim/mesh/src/mesh_test.c | 10 +++++----- tests/bluetooth/bsim/mesh/src/test_blob.c | 13 ------------- tests/bluetooth/bsim/mesh/src/test_dfu.c | 3 --- tests/bluetooth/bsim/mesh/src/test_provision.c | 10 ---------- 4 files changed, 5 insertions(+), 31 deletions(-) diff --git a/tests/bluetooth/bsim/mesh/src/mesh_test.c b/tests/bluetooth/bsim/mesh/src/mesh_test.c index e8421ea4123c..eeb10d6134f5 100644 --- a/tests/bluetooth/bsim/mesh/src/mesh_test.c +++ b/tests/bluetooth/bsim/mesh/src/mesh_test.c @@ -262,11 +262,6 @@ void bt_mesh_test_setup(void) { static struct bt_mesh_prov prov; - /* Ensure those test devices will not drift more than - * 100ms for each other in emulated time - */ - tm_set_phy_max_resync_offset(100000); - net_buf_simple_init(pub.msg, 0); net_buf_simple_init(vnd_pub.msg, 0); @@ -289,6 +284,11 @@ void bt_mesh_test_cfg_set(const struct bt_mesh_test_cfg *my_cfg, int wait_time) bst_ticker_set_next_tick_absolute(wait_time * USEC_PER_SEC); bst_result = In_progress; cfg = my_cfg; + + /* Ensure those test devices will not drift more than + * 100ms for each other in emulated time + */ + tm_set_phy_max_resync_offset(100000); } static struct bt_mesh_test_msg *blocking_recv(k_timeout_t timeout) diff --git a/tests/bluetooth/bsim/mesh/src/test_blob.c b/tests/bluetooth/bsim/mesh/src/test_blob.c index e32dee58a1f0..e81e3043c489 100644 --- a/tests/bluetooth/bsim/mesh/src/test_blob.c +++ b/tests/bluetooth/bsim/mesh/src/test_blob.c @@ -879,8 +879,6 @@ static void test_cli_trans_complete(void) { int err; - tm_set_phy_max_resync_offset(100000); - bt_mesh_test_cfg_set(NULL, 400); bt_mesh_device_setup(&prov, &cli_comp); blob_cli_prov_and_conf(BLOB_CLI_ADDR); @@ -923,8 +921,6 @@ static void test_cli_trans_complete(void) static void test_srv_trans_complete(void) { - tm_set_phy_max_resync_offset(100000); - bt_mesh_test_cfg_set(NULL, 400); bt_mesh_device_setup(&prov, &srv_comp); blob_srv_prov_and_conf(bt_mesh_test_own_addr_get(BLOB_CLI_ADDR)); @@ -961,7 +957,6 @@ static void test_cli_trans_resume(void) }; bt_mesh_test_sync_init(&sync); - tm_set_phy_max_resync_offset(100000); bt_mesh_test_cfg_set(NULL, 800); bt_mesh_device_setup(&prov, &cli_comp); @@ -1033,7 +1028,6 @@ static void test_srv_trans_resume(void) }; bt_mesh_test_sync_init(&sync); - tm_set_phy_max_resync_offset(100000); bt_mesh_test_cfg_set(NULL, 800); bt_mesh_device_setup(&prov, &srv_comp); @@ -1090,8 +1084,6 @@ static void test_cli_trans_persistency_pull(void) { int err; - tm_set_phy_max_resync_offset(100000); - bt_mesh_test_cfg_set(NULL, 240); bt_mesh_device_setup(&prov, &cli_comp); blob_cli_prov_and_conf(BLOB_CLI_ADDR); @@ -1129,8 +1121,6 @@ static void test_cli_trans_persistency_pull(void) static void test_srv_trans_persistency_pull(void) { - tm_set_phy_max_resync_offset(100000); - bt_mesh_test_cfg_set(NULL, 240); bt_mesh_device_setup(&prov, &srv_comp); blob_srv_prov_and_conf(bt_mesh_test_own_addr_get(BLOB_CLI_ADDR)); @@ -1197,7 +1187,6 @@ static int fail_on_block_start(const struct bt_mesh_blob_io *io, static void cli_common_fail_on_init(void) { - tm_set_phy_max_resync_offset(100000); bt_mesh_test_cfg_set(NULL, 800); bt_mesh_device_setup(&prov, &cli_comp); blob_cli_prov_and_conf(BLOB_CLI_ADDR); @@ -1259,8 +1248,6 @@ static void test_cli_fail_on_persistency(void) static void common_fail_on_srv_init(const struct bt_mesh_comp *comp) { - tm_set_phy_max_resync_offset(100000); - bt_mesh_test_cfg_set(NULL, 800); bt_mesh_device_setup(&prov, comp); blob_srv_prov_and_conf(bt_mesh_test_own_addr_get(BLOB_CLI_ADDR)); diff --git a/tests/bluetooth/bsim/mesh/src/test_dfu.c b/tests/bluetooth/bsim/mesh/src/test_dfu.c index 6ec983dd5d6c..fd22b32f467e 100644 --- a/tests/bluetooth/bsim/mesh/src/test_dfu.c +++ b/tests/bluetooth/bsim/mesh/src/test_dfu.c @@ -658,7 +658,6 @@ static void cli_common_fail_on_init(void) { const struct bt_mesh_dfu_slot *slot; - tm_set_phy_max_resync_offset(100000); settings_test_backend_clear(); bt_mesh_test_cfg_set(NULL, 300); bt_mesh_device_setup(&prov, &cli_comp); @@ -973,8 +972,6 @@ static void test_target_fail_on_nothing(void) static void test_pre_init(void) { - tm_set_phy_max_resync_offset(100000); - k_sem_init(&dfu_dist_ended, 0, 1); k_sem_init(&dfu_ended, 0, 1); k_sem_init(&caps_get_sem, 0, 1); diff --git a/tests/bluetooth/bsim/mesh/src/test_provision.c b/tests/bluetooth/bsim/mesh/src/test_provision.c index 956f39ae98d8..336d18739593 100644 --- a/tests/bluetooth/bsim/mesh/src/test_provision.c +++ b/tests/bluetooth/bsim/mesh/src/test_provision.c @@ -142,11 +142,6 @@ static bool is_oob_auth; static void test_device_init(void) { - /* Ensure those test devices will not drift more than - * 100ms for each other in emulated time - */ - tm_set_phy_max_resync_offset(100000); - /* Ensure that the UUID is unique: */ dev_uuid[6] = '0' + get_device_nbr(); @@ -156,11 +151,6 @@ static void test_device_init(void) static void test_provisioner_init(void) { - /* Ensure those test devices will not drift more than - * 100ms for each other in emulated time - */ - tm_set_phy_max_resync_offset(100000); - atomic_set_bit(test_flags, IS_PROVISIONER); bt_mesh_test_cfg_set(NULL, WAIT_TIME); k_work_init_delayable(&oob_timer, delayed_input); From 58f35ead65074891bfeb4592199c534df6f3b7b3 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Wed, 15 Mar 2023 16:26:39 +0100 Subject: [PATCH 0291/1906] tests: Bluetooth: Mesh: Remove device synchronization API This API was creating more problems than solving. We should not use back channel in bsim tests unless there is no other way to communicate between devices. To synchronize devices we should use k_sleep. This addresses https://github.com/zephyrproject-rtos/zephyr/issues/55821 Signed-off-by: Pavel Vasilyev --- tests/bluetooth/bsim/mesh/src/mesh_test.c | 75 ------------------- tests/bluetooth/bsim/mesh/src/mesh_test.h | 5 -- tests/bluetooth/bsim/mesh/src/test_blob.c | 21 +----- .../bluetooth/bsim/mesh/src/test_transport.c | 17 +---- 4 files changed, 4 insertions(+), 114 deletions(-) diff --git a/tests/bluetooth/bsim/mesh/src/mesh_test.c b/tests/bluetooth/bsim/mesh/src/mesh_test.c index eeb10d6134f5..61eec7538c65 100644 --- a/tests/bluetooth/bsim/mesh/src/mesh_test.c +++ b/tests/bluetooth/bsim/mesh/src/mesh_test.c @@ -503,81 +503,6 @@ void bt_mesh_test_ra_cb_setup(void (*cb)(uint8_t *, size_t)) ra_cb = cb; } -void bt_mesh_test_sync_init(struct bt_mesh_test_sync_ctx *ctx) -{ - ctx->chan_id = bs_open_back_channel(get_device_nbr(), - ctx->dev_nmbr, - ctx->chan_nmbr, ctx->cnt); -} - -static bool wait_for_sync(uint32_t channel_id, int *wait, uint8_t msg_len) -{ - int size; - - while (true) { - size = bs_bc_is_msg_received(channel_id); - - if (size < 0) { - FAIL("Sync channel error: %d", size); - } else if (size > 0) { - ASSERT_EQUAL(size, msg_len); - return true; - } else if (*wait <= 0) { - return false; - } - - k_sleep(K_MSEC(100)); - *wait -= 100; - } -} - -bool bt_mesh_test_sync_multi(struct bt_mesh_test_sync_ctx *ctx, uint32_t channel, uint16_t wait_sec) -{ - const uint32_t barrier_msg = 0xC0FFEE; - uint32_t recv_msg; - int wait = wait_sec * MSEC_PER_SEC; - - for (int i = 0; i < ctx->cnt; i++) { - if (ctx->chan_nmbr[i] != channel) { - continue; - } - - if (!wait_for_sync(ctx->chan_id[i], &wait, sizeof(barrier_msg))) { - return false; - } - - bs_bc_receive_msg(ctx->chan_id[i], (uint8_t *)&recv_msg, sizeof(recv_msg)); - ASSERT_EQUAL(barrier_msg, recv_msg); - } - - for (int i = 0; i < ctx->cnt; i++) { - if (ctx->chan_nmbr[i] != channel) { - continue; - } - - bs_bc_send_msg(ctx->chan_id[i], (uint8_t *)&barrier_msg, sizeof(barrier_msg)); - } - - return true; -} - -bool bt_mesh_test_sync(uint32_t channel_id, uint16_t wait_sec) -{ - const uint32_t barrier_msg = 0xC0FFEE; - uint32_t recv_msg; - int wait = wait_sec * MSEC_PER_SEC; - - bs_bc_send_msg(channel_id, (uint8_t *)&barrier_msg, sizeof(barrier_msg)); - - if (!wait_for_sync(channel_id, &wait, sizeof(barrier_msg))) { - return false; - } - - bs_bc_receive_msg(channel_id, (uint8_t *)&recv_msg, sizeof(recv_msg)); - ASSERT_EQUAL(barrier_msg, recv_msg); - return true; -} - uint16_t bt_mesh_test_own_addr_get(uint16_t start_addr) { return start_addr + get_device_nbr(); diff --git a/tests/bluetooth/bsim/mesh/src/mesh_test.h b/tests/bluetooth/bsim/mesh/src/mesh_test.h index 59d12e2dffca..a4db379a175f 100644 --- a/tests/bluetooth/bsim/mesh/src/mesh_test.h +++ b/tests/bluetooth/bsim/mesh/src/mesh_test.h @@ -156,11 +156,6 @@ int bt_mesh_test_send_ra(uint16_t addr, uint8_t *data, size_t len, void *cb_data); void bt_mesh_test_ra_cb_setup(void (*cb)(uint8_t *, size_t)); -void bt_mesh_test_sync_init(struct bt_mesh_test_sync_ctx *ctx); -bool bt_mesh_test_sync_multi(struct bt_mesh_test_sync_ctx *ctx, uint32_t channel, - uint16_t wait_sec); -bool bt_mesh_test_sync(uint32_t channel_id, uint16_t wait_sec); - uint16_t bt_mesh_test_own_addr_get(uint16_t start_addr); #if defined(CONFIG_BT_MESH_SAR_CFG) diff --git a/tests/bluetooth/bsim/mesh/src/test_blob.c b/tests/bluetooth/bsim/mesh/src/test_blob.c index e81e3043c489..9e299e717716 100644 --- a/tests/bluetooth/bsim/mesh/src/test_blob.c +++ b/tests/bluetooth/bsim/mesh/src/test_blob.c @@ -950,13 +950,6 @@ static void test_srv_trans_complete(void) static void test_cli_trans_resume(void) { int err; - struct bt_mesh_test_sync_ctx sync = { - .chan_nmbr = (uint32_t[]){ SYNC_CHAN }, - .dev_nmbr = (uint32_t[]){ SRV1_DEV }, - .cnt = 1 - }; - - bt_mesh_test_sync_init(&sync); bt_mesh_test_cfg_set(NULL, 800); bt_mesh_device_setup(&prov, &cli_comp); @@ -1002,8 +995,6 @@ static void test_cli_trans_resume(void) ASSERT_TRUE(blob_cli.state == BT_MESH_BLOB_CLI_STATE_SUSPENDED); - /* Sync with the server device to enable scanning again. */ - ASSERT_TRUE(bt_mesh_test_sync(sync.chan_id[0], 3)); /* Initiate resumption of BLOB transfer */ err = bt_mesh_blob_cli_resume(&blob_cli); if (err) { @@ -1021,14 +1012,6 @@ static void test_cli_trans_resume(void) static void test_srv_trans_resume(void) { - struct bt_mesh_test_sync_ctx sync = { - .chan_nmbr = (uint32_t[]){ SYNC_CHAN }, - .dev_nmbr = (uint32_t[]){ 0 }, - .cnt = 1 - }; - - bt_mesh_test_sync_init(&sync); - bt_mesh_test_cfg_set(NULL, 800); bt_mesh_device_setup(&prov, &srv_comp); blob_srv_prov_and_conf(bt_mesh_test_own_addr_get(BLOB_CLI_ADDR)); @@ -1059,8 +1042,8 @@ static void test_srv_trans_resume(void) ASSERT_TRUE(blob_srv.phase == BT_MESH_BLOB_XFER_PHASE_SUSPENDED); - /* Wait for BLOB client to suspend */ - ASSERT_TRUE(bt_mesh_test_sync(sync.chan_id[0], 400)); + /* Wait for BLOB client to suspend. Measured experimentally. */ + k_sleep(K_SECONDS(140)); bt_mesh_scan_enable(); diff --git a/tests/bluetooth/bsim/mesh/src/test_transport.c b/tests/bluetooth/bsim/mesh/src/test_transport.c index d2f5955f3134..548c408b70b3 100644 --- a/tests/bluetooth/bsim/mesh/src/test_transport.c +++ b/tests/bluetooth/bsim/mesh/src/test_transport.c @@ -152,19 +152,14 @@ static void test_tx_va(void) { uint16_t virtual_addr; int err; - struct bt_mesh_test_sync_ctx sync = { - .chan_nmbr = (uint32_t[]){ SYNC_CHAN }, - .dev_nmbr = (uint32_t[]){ SRV1_DEV }, - .cnt = 1 - }; - bt_mesh_test_sync_init(&sync); bt_mesh_test_setup(); err = bt_mesh_va_add(test_va_uuid, &virtual_addr); ASSERT_OK_MSG(err, "Virtual addr add failed (err %d)", err); - ASSERT_TRUE(bt_mesh_test_sync(sync.chan_id[0], 4)); + /* Wait for the receiver to subscribe on address. */ + k_sleep(K_SECONDS(1)); for (int i = 0; i < ARRAY_SIZE(test_vector); i++) { err = bt_mesh_test_send(virtual_addr, test_vector[i].len, @@ -438,21 +433,13 @@ static void test_rx_va(void) uint16_t virtual_addr; uint8_t status; int err; - struct bt_mesh_test_sync_ctx sync = { - .chan_nmbr = (uint32_t[]){ SYNC_CHAN }, - .dev_nmbr = (uint32_t[]){ CLI_DEV }, - .cnt = 1 - }; - bt_mesh_test_sync_init(&sync); bt_mesh_test_setup(); err = bt_mesh_cfg_cli_mod_sub_va_add(0, cfg->addr, cfg->addr, test_va_uuid, TEST_MOD_ID, &virtual_addr, &status); ASSERT_OK_MSG(err || status, "Sub add failed (err %d, status %u)", err, status); - ASSERT_TRUE(bt_mesh_test_sync(sync.chan_id[0], 4)); - for (int i = 0; i < ARRAY_SIZE(test_vector); i++) { err = bt_mesh_test_recv(test_vector[i].len, virtual_addr, K_SECONDS(20)); From a92478f4bd511c9a42d9c74842939441dd332418 Mon Sep 17 00:00:00 2001 From: Felipe Date: Sun, 12 Mar 2023 20:41:21 -0300 Subject: [PATCH 0292/1906] drivers: ipm_esp32: add set enabled default implementation, it is required to be present when using openamp on zephyr. Signed-off-by: Felipe Neves --- drivers/ipm/ipm_esp32.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/ipm/ipm_esp32.c b/drivers/ipm/ipm_esp32.c index e6b314555584..9f7e60635193 100644 --- a/drivers/ipm/ipm_esp32.c +++ b/drivers/ipm/ipm_esp32.c @@ -170,6 +170,20 @@ static uint32_t esp_32_ipm_max_id_val_get(const struct device *dev) return 0xFFFF; } +static int esp_32_ipm_set_enabled(const struct device *dev, int enable) +{ + /* The esp32 IPM is always enabled + * but rpmsg backend needs IPM set enabled to be + * implemented so just return success here + */ + + ARG_UNUSED(dev); + ARG_UNUSED(enable); + + return 0; +} + + static int esp32_ipm_init(const struct device *dev) { struct esp32_ipm_data *data = (struct esp32_ipm_data *)dev->data; @@ -221,7 +235,8 @@ static const struct ipm_driver_api esp32_ipm_driver_api = { .send = esp32_ipm_send, .register_callback = esp32_ipm_register_callback, .max_data_size_get = esp32_ipm_max_data_size_get, - .max_id_val_get = esp_32_ipm_max_id_val_get + .max_id_val_get = esp_32_ipm_max_id_val_get, + .set_enabled = esp_32_ipm_set_enabled }; #define ESP32_IPM_SHM_SIZE_BY_IDX(idx) \ From bd705e68b048b5c956beecee26517f2ca6f22e76 Mon Sep 17 00:00:00 2001 From: Felipe Date: Sun, 12 Mar 2023 20:42:30 -0300 Subject: [PATCH 0293/1906] soc: xtensa: esp32: increase shared memory region for esp32 and esp32_net because the default 2048 bytes are not sufficient for rpmsg usage. Signed-off-by: Felipe Neves --- dts/xtensa/espressif/esp32.dtsi | 6 +++--- soc/xtensa/esp32/linker.ld | 6 +++--- soc/xtensa/esp32_net/linker.ld | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dts/xtensa/espressif/esp32.dtsi b/dts/xtensa/espressif/esp32.dtsi index f84bcb4ea3b3..9a92e7674b60 100644 --- a/dts/xtensa/espressif/esp32.dtsi +++ b/dts/xtensa/espressif/esp32.dtsi @@ -75,7 +75,7 @@ shm0: memory@3ffe5630 { compatible = "mmio-sram"; - reg = <0x3FFE5630 0x400>; + reg = <0x3FFE5630 0x3C00>; }; intc: interrupt-controller@3ff00104 { @@ -118,9 +118,9 @@ }; }; - ipm0: ipm@3ffe5a30 { + ipm0: ipm@3ffed238 { compatible = "espressif,esp32-ipm"; - reg = <0x3FFE5A30 0x8>; + reg = <0x3FFED238 0x8>; status = "disabled"; shared-memory = <&ipmmem0>; shared-memory-size = <0x400>; diff --git a/soc/xtensa/esp32/linker.ld b/soc/xtensa/esp32/linker.ld index 3dbd08195978..9d3a1b84c37c 100644 --- a/soc/xtensa/esp32/linker.ld +++ b/soc/xtensa/esp32/linker.ld @@ -75,9 +75,9 @@ MEMORY dram0_0_seg(RW): org = 0x3FFB0000 + CONFIG_ESP32_BT_RESERVE_DRAM, len = 0x2c200 - CONFIG_ESP32_BT_RESERVE_DRAM #ifdef CONFIG_ESP32_NETWORK_CORE - dram0_shm0_seg(RW): org = 0x3FFE5230, len = 2K /* shared RAM reserved for IPM */ - dram0_sem0_seg(RW): org = 0x3FFE5A30, len = 8 /* shared data reserved for IPM data header */ - dram0_1_seg(RW): org = 0x3FFE5A38, len = 0K /* for AMP builds dram0_1 is reserved for network core */ + dram0_shm0_seg(RW): org = 0x3FFE5230, len = 16K /* shared RAM reserved for IPM */ + dram0_sem0_seg(RW): org = 0x3FFED238, len = 8 /* shared data reserved for IPM data header */ + dram0_1_seg(RW): org = 0x3FFE9238, len = 0K /* for AMP builds dram0_1 is reserved for network core */ #else dram0_1_seg(RW): org = 0x3FFE5230, len = 0x1BCB0 - 0xEE0 /* skip data for APP CPU initialization usage */ #endif diff --git a/soc/xtensa/esp32_net/linker.ld b/soc/xtensa/esp32_net/linker.ld index 0b21e141bead..6c1b69872b19 100644 --- a/soc/xtensa/esp32_net/linker.ld +++ b/soc/xtensa/esp32_net/linker.ld @@ -29,9 +29,9 @@ MEMORY { iram0_0_seg(RX): org = 0x40080000 + 0x08000, len = 0x18000 - dram0_shm0_seg(RW): org = 0x3FFE5230, len = 2K /* shared RAM reserved for IPM */ - dram0_sem0_seg(RW): org = 0x3FFE5A30, len = 8 /*shared data reserved for IPM data header */ - dram0_1_seg(RW): org = 0x3FFE5A38 + CONFIG_ESP32_BT_RESERVE_DRAM, len = 0x1BCB0 - 0xEE0 - CONFIG_ESP32_BT_RESERVE_DRAM + dram0_shm0_seg(RW): org = 0x3FFE5230, len = 16K /* shared RAM reserved for IPM */ + dram0_sem0_seg(RW): org = 0x3FFED238, len = 8 /*shared data reserved for IPM data header */ + dram0_1_seg(RW): org = 0x3FFE9238 + CONFIG_ESP32_BT_RESERVE_DRAM, len = 0x17CB0 - 0xEE0 - CONFIG_ESP32_BT_RESERVE_DRAM #ifdef CONFIG_GEN_ISR_TABLES IDT_LIST(RW): org = 0x3ebfe010, len = 0x2000 #endif From 0e6a886ce49b1a878e2c095b58b749b576e11e47 Mon Sep 17 00:00:00 2001 From: Felipe Date: Sun, 12 Mar 2023 20:45:45 -0300 Subject: [PATCH 0294/1906] samples: subsys: ipc: add esp32 as supported board to the rpmsg service sample. Signed-off-by: Felipe Neves --- .../subsys/ipc/rpmsg_service/CMakeLists.txt | 9 +++++++++ .../ipc/rpmsg_service/boards/esp32.conf | 1 + .../ipc/rpmsg_service/boards/esp32.overlay | 19 +++++++++++++++++++ .../ipc/rpmsg_service/remote/CMakeLists.txt | 3 ++- .../remote/boards/esp32_net.conf | 1 + .../remote/boards/esp32_net.overlay | 19 +++++++++++++++++++ 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 samples/subsys/ipc/rpmsg_service/boards/esp32.conf create mode 100644 samples/subsys/ipc/rpmsg_service/boards/esp32.overlay create mode 100644 samples/subsys/ipc/rpmsg_service/remote/boards/esp32_net.conf create mode 100644 samples/subsys/ipc/rpmsg_service/remote/boards/esp32_net.overlay diff --git a/samples/subsys/ipc/rpmsg_service/CMakeLists.txt b/samples/subsys/ipc/rpmsg_service/CMakeLists.txt index 69cec368a704..18108f25fa03 100644 --- a/samples/subsys/ipc/rpmsg_service/CMakeLists.txt +++ b/samples/subsys/ipc/rpmsg_service/CMakeLists.txt @@ -18,6 +18,8 @@ elseif("${BOARD}" STREQUAL "mps2_an521") set(BOARD_REMOTE "mps2_an521_remote") elseif("${BOARD}" STREQUAL "v2m_musca_b1") set(BOARD_REMOTE "v2m_musca_b1_ns") +elseif("${BOARD}" STREQUAL "esp32") + set(BOARD_REMOTE "esp32_net") else() message(FATAL_ERROR "${BOARD} was not supported for this sample") endif() @@ -31,6 +33,11 @@ enable_language(C ASM) target_sources(app PRIVATE src/main.c) +if("${BOARD}" STREQUAL "esp32") + set_source_files_properties(${REMOTE_ZEPHYR_DIR}/esp32_net_firmware.c PROPERTIES GENERATED TRUE) + target_sources(app PRIVATE src/main.c ${REMOTE_ZEPHYR_DIR}/esp32_net_firmware.c) +endif() + include(ExternalProject) ExternalProject_Add( @@ -45,6 +52,8 @@ ExternalProject_Add( if(("${BOARD}" STREQUAL "lpcxpresso54114_m4")) add_dependencies(core_m0_inc_target rpmsg_service_remote) +elseif("${BOARD}" STREQUAL "esp32") + add_dependencies(app rpmsg_service_remote) endif() target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/samples/subsys/ipc/rpmsg_service/boards/esp32.conf b/samples/subsys/ipc/rpmsg_service/boards/esp32.conf new file mode 100644 index 000000000000..5cb30cb75c05 --- /dev/null +++ b/samples/subsys/ipc/rpmsg_service/boards/esp32.conf @@ -0,0 +1 @@ +CONFIG_ESP32_NETWORK_CORE=y diff --git a/samples/subsys/ipc/rpmsg_service/boards/esp32.overlay b/samples/subsys/ipc/rpmsg_service/boards/esp32.overlay new file mode 100644 index 000000000000..ad437c16e493 --- /dev/null +++ b/samples/subsys/ipc/rpmsg_service/boards/esp32.overlay @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 Felipe Neves + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* + * shared memory reserved for the inter-processor communication + */ + zephyr,ipc_shm = &shm0; + zephyr,ipc = &ipm0; + }; +}; + +&ipm0 { + status = "okay"; +}; diff --git a/samples/subsys/ipc/rpmsg_service/remote/CMakeLists.txt b/samples/subsys/ipc/rpmsg_service/remote/CMakeLists.txt index a37269c592e2..fa4fe6ebad5b 100644 --- a/samples/subsys/ipc/rpmsg_service/remote/CMakeLists.txt +++ b/samples/subsys/ipc/rpmsg_service/remote/CMakeLists.txt @@ -9,7 +9,8 @@ if("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpunet" OR "${BOARD}" STREQUAL "bl5340_dvk_cpunet" OR "${BOARD}" STREQUAL "lpcxpresso54114_m0" OR "${BOARD}" STREQUAL "mps2_an521_remote" - OR "${BOARD}" STREQUAL "v2m_musca_b1_ns") + OR "${BOARD}" STREQUAL "v2m_musca_b1_ns" + OR "${BOARD}" STREQUAL "esp32_net") message(STATUS "${BOARD} compile as slave in this sample") else() message(FATAL_ERROR "${BOARD} was not supported for this sample") diff --git a/samples/subsys/ipc/rpmsg_service/remote/boards/esp32_net.conf b/samples/subsys/ipc/rpmsg_service/remote/boards/esp32_net.conf new file mode 100644 index 000000000000..eee0f29606c7 --- /dev/null +++ b/samples/subsys/ipc/rpmsg_service/remote/boards/esp32_net.conf @@ -0,0 +1 @@ +CONFIG_KERNEL_BIN_NAME="esp32_net_firmware" diff --git a/samples/subsys/ipc/rpmsg_service/remote/boards/esp32_net.overlay b/samples/subsys/ipc/rpmsg_service/remote/boards/esp32_net.overlay new file mode 100644 index 000000000000..6da59669fc52 --- /dev/null +++ b/samples/subsys/ipc/rpmsg_service/remote/boards/esp32_net.overlay @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 Felipe Neves + * + * SPDX-License-Identifier: Apache-2.0 + */ + + / { + chosen { + /* + * shared memory reserved for the inter-processor communication + */ + zephyr,ipc_shm = &shm0; + zephyr,ipc = &ipm0; + }; +}; + +&ipm0 { + status = "okay"; +}; From 3a0fa866e4690416970f6bbf5ea4e384bff55a66 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 14 Mar 2023 13:04:39 +0100 Subject: [PATCH 0295/1906] Bluetooth: Mesh: Fix timeout handling on link opening in RPR Client This commit fixes an issue, where the RPR Client gets stuck forever until reboot if it doesn't receive Link Status or Link Report message when openinig the remote provisioning link. The RPR_CLI_LINK_OPEN flag was used to control the remote provision link and protect against receiving an unexpected message, but it didn't cover a case when neither of messages were received from the RPR Server. cli->link.state only changes by Link Status or Link Report message and is set to BT_MESH_RPR_LINK_IDLE when opening the link. Therefore, when the RPR Client's timer timed out, the client didn't reset its internal states. This commit adds an additional state to cover this intermediate state when the client initiated the link opening but didn't receive any response. Signed-off-by: Pavel Vasilyev --- subsys/bluetooth/mesh/rpr_cli.c | 96 +++++++++++++-------------------- 1 file changed, 38 insertions(+), 58 deletions(-) diff --git a/subsys/bluetooth/mesh/rpr_cli.c b/subsys/bluetooth/mesh/rpr_cli.c index 91f9ef9278ee..97bf2137d449 100644 --- a/subsys/bluetooth/mesh/rpr_cli.c +++ b/subsys/bluetooth/mesh/rpr_cli.c @@ -28,12 +28,13 @@ BUILD_ASSERT(BT_MESH_MODEL_OP_LEN(RPR_OP_PDU_SEND) == 2, "Assumes PDU send is a } enum { - RPR_CLI_LINK_OPEN, - RPR_CLI_NUM_FLAGS, + BEARER_LINK_IDLE, + BEARER_LINK_OPENING, + BEARER_LINK_OPENED, }; static struct { - ATOMIC_DEFINE(flags, RPR_CLI_NUM_FLAGS); + int link; const struct prov_bearer_cb *cb; struct bt_mesh_rpr_cli *cli; struct { @@ -54,22 +55,23 @@ static void link_report(struct bt_mesh_rpr_cli *cli, struct pb_remote_ctx ctx = { cli, srv }; if (link->state == BT_MESH_RPR_LINK_ACTIVE && - !atomic_test_and_set_bit(bearer.flags, RPR_CLI_LINK_OPEN)) { + bearer.link == BEARER_LINK_OPENING) { + bearer.link = BEARER_LINK_OPENED; LOG_DBG("Opened"); bearer.cb->link_opened(&pb_remote_cli, &ctx); return; } - if (link->state != BT_MESH_RPR_LINK_IDLE || - !atomic_test_and_clear_bit(bearer.flags, RPR_CLI_LINK_OPEN)) { - return; - } + if (link->state == BT_MESH_RPR_LINK_IDLE && + bearer.link != BEARER_LINK_IDLE) { + bearer.link = BEARER_LINK_IDLE; - LOG_DBG("Closed (%u)", link->status); - bearer.cb->link_closed(&pb_remote_cli, &ctx, - ((link->status == BT_MESH_RPR_SUCCESS) ? - PROV_BEARER_LINK_STATUS_SUCCESS : - PROV_BEARER_LINK_STATUS_FAIL)); + LOG_DBG("Closed (%u)", link->status); + bearer.cb->link_closed(&pb_remote_cli, &ctx, + ((link->status == BT_MESH_RPR_SUCCESS) ? + PROV_BEARER_LINK_STATUS_SUCCESS : + PROV_BEARER_LINK_STATUS_FAIL)); + } } static void tx_complete(struct bt_mesh_rpr_cli *cli, int err, void *cb_data) @@ -142,13 +144,13 @@ static int handle_link_report(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx tx_complete(cli, -ECANCELED, cb_data); } - k_work_reschedule(&cli->link.timeout, K_SECONDS(cli->link.time)); - if (cli->link.srv.addr != srv.addr) { LOG_DBG("Link report from unknown server 0x%04x", srv.addr); return 0; } + k_work_reschedule(&cli->link.timeout, K_SECONDS(cli->link.time)); + cli->link.state = link.state; LOG_DBG("0x%04x: status: %u state: %u", srv.addr, link.status, @@ -205,8 +207,6 @@ static int handle_pdu_outbound_report(struct bt_mesh_model *mod, struct bt_mesh_ void *cb_data; uint8_t num; - k_work_reschedule(&cli->link.timeout, K_SECONDS(cli->link.time)); - if (srv.addr != cli->link.srv.addr) { LOG_WRN("Outbound report from unknown server 0x%04x", srv.addr); return 0; @@ -216,6 +216,7 @@ static int handle_pdu_outbound_report(struct bt_mesh_model *mod, struct bt_mesh_ LOG_DBG("0x%04x: %u", srv.addr, num); + k_work_reschedule(&cli->link.timeout, K_SECONDS(cli->link.time)); if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, RPR_OP_PDU_OUTBOUND_REPORT, srv.addr, &cb_data) || @@ -358,7 +359,7 @@ static void link_timeout(struct k_work *work) struct bt_mesh_rpr_cli *cli = CONTAINER_OF(k_work_delayable_from_work(work), struct bt_mesh_rpr_cli, link.timeout); - if (cli->link.state != BT_MESH_RPR_LINK_IDLE) { + if (bearer.link != BEARER_LINK_IDLE) { LOG_DBG(""); link_closed(cli, BT_MESH_RPR_ERR_LINK_CLOSED_BY_CLIENT); } @@ -578,35 +579,17 @@ static int link_open_prov(struct bt_mesh_rpr_cli *cli, uint8_t timeout) { struct bt_mesh_msg_ctx ctx = LINK_CTX(srv, false); - int err; - - if (cli->link.srv.addr != BT_MESH_ADDR_UNASSIGNED) { - return -EBUSY; - } BT_MESH_MODEL_BUF_DEFINE(buf, RPR_OP_LINK_OPEN, 17); bt_mesh_model_msg_init(&buf, RPR_OP_LINK_OPEN); net_buf_simple_add_mem(&buf, uuid, 16); - if (timeout) { - cli->link.time = timeout; - } - if (cli->link.time != LINK_TIMEOUT_SECONDS_DEFAULT) { net_buf_simple_add_u8(&buf, cli->link.time); } - link_init(cli, srv); - - LOG_DBG(""); - - err = bt_mesh_model_send(cli->mod, &ctx, &buf, NULL, NULL); - if (err) { - link_reset(cli); - } - - return err; + return bt_mesh_model_send(cli->mod, &ctx, &buf, NULL, NULL); } static int link_open_node(struct bt_mesh_rpr_cli *cli, @@ -614,29 +597,13 @@ static int link_open_node(struct bt_mesh_rpr_cli *cli, enum bt_mesh_rpr_node_refresh type) { struct bt_mesh_msg_ctx ctx = LINK_CTX(srv, false); - int err; - - if (cli->link.srv.addr != BT_MESH_ADDR_UNASSIGNED) { - return -EBUSY; - } BT_MESH_MODEL_BUF_DEFINE(buf, RPR_OP_LINK_OPEN, 1); bt_mesh_model_msg_init(&buf, RPR_OP_LINK_OPEN); net_buf_simple_add_u8(&buf, type); - cli->link.time = LINK_TIMEOUT_SECONDS_DEFAULT; - - link_init(cli, srv); - - LOG_DBG(""); - - err = bt_mesh_model_send(cli->mod, &ctx, &buf, NULL, NULL); - if (err) { - link_reset(cli); - } - - return err; + return bt_mesh_model_send(cli->mod, &ctx, &buf, NULL, NULL); } static int link_close(struct bt_mesh_rpr_cli *cli, @@ -732,24 +699,37 @@ static int pb_link_open(const uint8_t uuid[16], uint8_t timeout, const struct prov_bearer_cb *cb, void *cb_data) { struct pb_remote_ctx *ctx = cb_data; + struct bt_mesh_rpr_cli *cli = ctx->cli; + const struct bt_mesh_rpr_node *srv = ctx->srv; int err; + if (cli->link.srv.addr != BT_MESH_ADDR_UNASSIGNED) { + return -EBUSY; + } + bearer.cli = ctx->cli; bearer.cb = cb; + cli->link.time = timeout ? timeout : LINK_TIMEOUT_SECONDS_DEFAULT; + + LOG_DBG("timeout: %d", cli->link.time); + + link_init(cli, srv); + if (uuid) { - err = link_open_prov(ctx->cli, ctx->srv, uuid, timeout); + err = link_open_prov(cli, srv, uuid, timeout); } else { - err = link_open_node(ctx->cli, ctx->srv, ctx->refresh); + err = link_open_node(cli, srv, ctx->refresh); } if (err) { + link_reset(cli); return err; } - atomic_clear(bearer.flags); + bearer.link = BEARER_LINK_OPENING; - return err; + return 0; } static void pb_link_close(enum prov_bearer_link_status status) From e9a20cc3b62dae279b500d884d96a127e5c3909b Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 14 Mar 2023 16:06:05 +0100 Subject: [PATCH 0296/1906] Bluetooth: Mesh: Restart timer after sending PDU to RPR Server This commit fixes an issue where the RPR Client gets stuck after sending PDU to RPR Server (even with segmented flag), but doesn't hear anything back from the server. Signed-off-by: Pavel Vasilyev --- subsys/bluetooth/mesh/rpr_cli.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/rpr_cli.c b/subsys/bluetooth/mesh/rpr_cli.c index 97bf2137d449..92de520dca6d 100644 --- a/subsys/bluetooth/mesh/rpr_cli.c +++ b/subsys/bluetooth/mesh/rpr_cli.c @@ -405,7 +405,10 @@ static void pdu_send_end(int err, void *cb_data) link_closed(cli, BT_MESH_RPR_ERR_LINK_CLOSED_AS_CANNOT_SEND_PDU); + return; } + + k_work_reschedule(&cli->link.timeout, K_SECONDS(cli->link.time)); } static const struct bt_mesh_send_cb pdu_send_cb = { @@ -465,8 +468,8 @@ static void link_closed(struct bt_mesh_rpr_cli *cli, .state = BT_MESH_RPR_LINK_IDLE, }; - LOG_DBG("0x%04x: status: %u state: %u", srv.addr, link.status, - link.state); + LOG_DBG("0x%04x: status: %u state: %u rx: %u tx: %u", srv.addr, link.status, + cli->link.state, cli->link.rx_pdu, cli->link.tx_pdu); link_reset(cli); @@ -626,6 +629,7 @@ static int link_close(struct bt_mesh_rpr_cli *cli, link_reset(cli); } + k_work_reschedule(&cli->link.timeout, K_SECONDS(cli->link.time)); return err; } From 3e14c13d8ddcf2b389767221baf5260f802c6cb8 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 14 Mar 2023 16:08:05 +0100 Subject: [PATCH 0297/1906] Bluetooth: Mesh: Use default provisioning protocol timeout in RPR Client The timeout used upon opening the link with the server relates to the PB-Remote Link Open procedure, but not to the whole provisioning procedure. For the provisioning procedure, the timeout should be at least 60 seconds as explained in section 5.4.4. Signed-off-by: Pavel Vasilyev --- subsys/bluetooth/mesh/prov_bearer.h | 6 +++++- subsys/bluetooth/mesh/rpr_cli.c | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/prov_bearer.h b/subsys/bluetooth/mesh/prov_bearer.h index a990566d94fc..a14f1888147b 100644 --- a/subsys/bluetooth/mesh/prov_bearer.h +++ b/subsys/bluetooth/mesh/prov_bearer.h @@ -4,7 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define PROTOCOL_TIMEOUT K_SECONDS(60) +/** Provisioning protocol timeout in seconds. */ +#define PROTOCOL_TIMEOUT_SEC 60 + +/** Provisioning protocol timeout. */ +#define PROTOCOL_TIMEOUT K_SECONDS(PROTOCOL_TIMEOUT_SEC) /** @def PROV_BEARER_BUF_HEADROOM * diff --git a/subsys/bluetooth/mesh/rpr_cli.c b/subsys/bluetooth/mesh/rpr_cli.c index 92de520dca6d..40b4cf51362c 100644 --- a/subsys/bluetooth/mesh/rpr_cli.c +++ b/subsys/bluetooth/mesh/rpr_cli.c @@ -59,6 +59,11 @@ static void link_report(struct bt_mesh_rpr_cli *cli, bearer.link = BEARER_LINK_OPENED; LOG_DBG("Opened"); bearer.cb->link_opened(&pb_remote_cli, &ctx); + + /* PB-Remote Open Link procedure timeout is configurable, but the provisioning + * protocol timeout is not. Use default provisioning protocol timeout. + */ + cli->link.time = PROTOCOL_TIMEOUT_SEC; return; } From 78849e18ff8d4fdc0090e3807afbceb7a6ba1060 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 16 Mar 2023 16:12:24 +0100 Subject: [PATCH 0298/1906] dts: bindings: arm,sbsa-uart: fix dangling entry interrupts property was previously added with "required: false", but when required was removed (redundant), the interrupts property was left dangling. Signed-off-by: Gerard Marull-Paretas --- dts/bindings/serial/arm,sbsa-uart.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/dts/bindings/serial/arm,sbsa-uart.yaml b/dts/bindings/serial/arm,sbsa-uart.yaml index 287e21d38574..6d35bd9c35ae 100644 --- a/dts/bindings/serial/arm,sbsa-uart.yaml +++ b/dts/bindings/serial/arm,sbsa-uart.yaml @@ -7,5 +7,3 @@ include: uart-controller.yaml properties: reg: required: true - - interrupts: From 6199b9175af0675cbe9edd028a7db15211414564 Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Thu, 16 Mar 2023 13:55:51 +0100 Subject: [PATCH 0299/1906] soc: arm: stm32h7 soc defines the _STM32H7_SOC_H_ flag Fix the error of the _STM32H7_SOC_H_ flag name for the stm32h7 serie Signed-off-by: Francois Ramu --- soc/arm/st_stm32/stm32h7/soc.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/soc/arm/st_stm32/stm32h7/soc.h b/soc/arm/st_stm32/stm32h7/soc.h index 48de3ef843df..ff37e9a1e6d4 100644 --- a/soc/arm/st_stm32/stm32h7/soc.h +++ b/soc/arm/st_stm32/stm32h7/soc.h @@ -4,8 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef _STM32F7_SOC_H_ -#define _STM32F7_SOC_H_ +#ifndef _STM32H7_SOC_H_ +#define _STM32H7_SOC_H_ #ifndef _ASMLANGUAGE @@ -13,4 +13,4 @@ #endif /* !_ASMLANGUAGE */ -#endif /* _STM32F7_SOC_H7_ */ +#endif /* _STM32H7_SOC_H7_ */ From 2b66410675076192db501f8dc79824470886b94e Mon Sep 17 00:00:00 2001 From: Manimaran A Date: Wed, 15 Mar 2023 18:42:48 +0530 Subject: [PATCH 0300/1906] soc: configuration: microchip SOC Kconfig bug fix Removed the EEPROM and ESPI configuration from file Kconfig.defconfig.mec172xnsz. Since it overrides the setting present in the Device Tree file. Signed-off-by: Manimaran A --- .../microchip_mec/mec172x/Kconfig.defconfig.mec172xnsz | 8 -------- 1 file changed, 8 deletions(-) diff --git a/soc/arm/microchip_mec/mec172x/Kconfig.defconfig.mec172xnsz b/soc/arm/microchip_mec/mec172x/Kconfig.defconfig.mec172xnsz index 45a4cc85c5e3..b218798465d3 100644 --- a/soc/arm/microchip_mec/mec172x/Kconfig.defconfig.mec172xnsz +++ b/soc/arm/microchip_mec/mec172x/Kconfig.defconfig.mec172xnsz @@ -11,12 +11,4 @@ config SOC config GPIO default y -config ESPI_XEC_V2 - default y - depends on ESPI - -config EEPROM_XEC - default y - depends on EEPROM - endif # SOC_MEC172X_NSZ From 5623f54a35a5f613505553b2da7e9acc03b28cc1 Mon Sep 17 00:00:00 2001 From: Gregory Shue Date: Mon, 27 Feb 2023 16:47:44 -0800 Subject: [PATCH 0301/1906] fff: Add fff_extensions.h, RETURN_HANDLED_CONTEXT() Add supplementary header . Add macro to fff_extensions.h for simplifying definition of custom fake functions needing call-unique information for producing desired output data. When an array of custom fake context structures is defined and the return field within the first structure instance is registered with the standard SET_RETURN_SEQ() macro of FFF, the RETURN_HANDLED_CONTEXT() macro provides the inverse logic to recover the context structure for this called instance. The body of the custom fake handler is provided to the RETURN_HANDLED_CONTEXT() macro for appropriate execution and access to the custom fake parameters. A test suite is also provided to verify macro implementation and illustrate usage. It is at: zephyr/tests/subsys/testsuite/fff_fake_contexts/ This code was verified by: 1. (Pass) west build -p always \ -b unit_testing tests/subsys/testsuite/fff_fake_contexts/ && \ ./build/testbinary 2. (Pass) west build -p always \ -b native_posix tests/subsys/testsuite/fff_fake_contexts/ && \ ./build/zephyr/zephyr.exe 3. (Pass) ./scripts/twister -p unit_testing \ -T tests/subsys/testsuite/fff_fake_contexts/ 4. (Pass) ./scripts/twister -p native_posix \ -T tests/subsys/testsuite/fff_fake_contexts/ 5. (Pass) cd doc && build html-fast Fix #55246 Signed-off-by: Gregory Shue --- doc/develop/test/ztest.rst | 17 +- doc/zephyr.doxyfile.in | 1 + .../testsuite/include/zephyr/fff_extensions.h | 98 +++++ .../fff_fake_contexts/CMakeLists.txt | 23 ++ .../include/zephyr/called_API.h | 57 +++ .../include/zephyr/code_under_test.h | 35 ++ .../testsuite/fff_fake_contexts/prj.conf | 5 + .../fff_fake_contexts/src/code_under_test.c | 32 ++ .../fff_fake_contexts/src/fakes/called_API.c | 12 + .../fff_fake_contexts/src/fakes/called_API.h | 29 ++ .../testsuite/fff_fake_contexts/src/main.c | 338 ++++++++++++++++++ .../testsuite/fff_fake_contexts/testcase.yaml | 13 + 12 files changed, 658 insertions(+), 2 deletions(-) create mode 100644 subsys/testsuite/include/zephyr/fff_extensions.h create mode 100644 tests/subsys/testsuite/fff_fake_contexts/CMakeLists.txt create mode 100644 tests/subsys/testsuite/fff_fake_contexts/include/zephyr/called_API.h create mode 100644 tests/subsys/testsuite/fff_fake_contexts/include/zephyr/code_under_test.h create mode 100644 tests/subsys/testsuite/fff_fake_contexts/prj.conf create mode 100644 tests/subsys/testsuite/fff_fake_contexts/src/code_under_test.c create mode 100644 tests/subsys/testsuite/fff_fake_contexts/src/fakes/called_API.c create mode 100644 tests/subsys/testsuite/fff_fake_contexts/src/fakes/called_API.h create mode 100644 tests/subsys/testsuite/fff_fake_contexts/src/main.c create mode 100644 tests/subsys/testsuite/fff_fake_contexts/testcase.yaml diff --git a/doc/develop/test/ztest.rst b/doc/develop/test/ztest.rst index a69bb4b3ec2b..23ff98d4f2c1 100644 --- a/doc/develop/test/ztest.rst +++ b/doc/develop/test/ztest.rst @@ -520,13 +520,14 @@ Example output for a failed macro from .. doxygengroup:: ztest_assume -.. _mocking-fff: - Ztress ====== .. doxygengroup:: ztest_ztress + +.. _mocking-fff: + Mocking via FFF =============== @@ -544,6 +545,9 @@ devicetree bindings for more information: - :dtcompatible:`zephyr,fake-can` - :dtcompatible:`zephyr,fake-eeprom` +Zephyr also has defined extensions to FFF for simplified declarations of fake functions. +See :ref:`FFF Extensions `. + Customizing Test Output *********************** The way output is presented when running tests can be customized. @@ -594,4 +598,13 @@ For example $ zephyr.exe -test="fixture_tests::test_fixture_pointer,framework_tests::test_assert_mem_equal" $ zephyr.exe -test="framework_tests::*" + +.. _fff-extensions: + +FFF Extensions +************** + +.. doxygengroup:: fff_extensions + + .. _FFF: https://github.com/meekrosoft/fff diff --git a/doc/zephyr.doxyfile.in b/doc/zephyr.doxyfile.in index 498c2f95a70b..fd0284865f2e 100644 --- a/doc/zephyr.doxyfile.in +++ b/doc/zephyr.doxyfile.in @@ -925,6 +925,7 @@ INPUT = @ZEPHYR_BASE@/doc/_doxygen/mainpage.md \ @ZEPHYR_BASE@/kernel/include/kernel_arch_interface.h \ @ZEPHYR_BASE@/include/ \ @ZEPHYR_BASE@/lib/libc/minimal/include/ \ + @ZEPHYR_BASE@/subsys/testsuite/include/ \ @ZEPHYR_BASE@/subsys/testsuite/ztest/include/ \ @ZEPHYR_BASE@/tests/kernel/ diff --git a/subsys/testsuite/include/zephyr/fff_extensions.h b/subsys/testsuite/include/zephyr/fff_extensions.h new file mode 100644 index 000000000000..946cde8c3431 --- /dev/null +++ b/subsys/testsuite/include/zephyr/fff_extensions.h @@ -0,0 +1,98 @@ +/* + * Copyright(c) 2023 Legrand North America, LLC. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * + * @brief Zephyr testing framework FFF extension macros + */ + +#ifndef ZEPHYR_SUBSYS_TESTSUITE_INCLUDE_ZEPHYR_FFF_EXTENSIONS_H_ +#define ZEPHYR_SUBSYS_TESTSUITE_INCLUDE_ZEPHYR_FFF_EXTENSIONS_H_ + +#include +#include /* for CONTAINER_OF */ + +/** + * @defgroup fff_extensions FFF extensions + * @ingroup all_tests + * + * This module provides extensions to FFF for simplifying the + * configuration and usage of fakes. + * + * @{ + */ + + +/** + * @brief Wrap custom fake body to extract defined context struct + * + * Add extension macro for simplified creation of + * fake functions needing call-specific context data. + * + * This macro enables a fake to be implemented as follows and + * requires no familiarity with the inner workings of FFF. + * + * @code + * struct FUNCNAME##_custom_fake_context + * { + * struct instance * const instance; + * int result; + * }; + * + * int FUNCNAME##_custom_fake( + * const struct instance **instance_out) + * { + * RETURN_HANDLED_CONTEXT( + * FUNCNAME, + * struct FUNCNAME##_custom_fake_context, + * result, + * context, + * { + * if (context != NULL) + * { + * if (context->result == 0) + * { + * if (instance_out != NULL) + * { + * *instance_out = context->instance; + * } + * } + * return context->result; + * } + * return FUNCNAME##_fake.return_val; + * } + * ); + * } + * @endcode + * + * @param FUNCNAME Name of function being faked + * @param CONTEXTTYPE type of custom defined fake context struct + * @param RESULTFIELD name of field holding the return type & value + * @param CONTEXTPTRNAME expected name of pointer to custom defined fake context struct + * @param HANDLERBODY in-line custom fake handling logic + */ + +#define RETURN_HANDLED_CONTEXT(FUNCNAME, \ + CONTEXTTYPE, RESULTFIELD, CONTEXTPTRNAME, HANDLERBODY) \ + if (FUNCNAME##_fake.return_val_seq_len) { \ + CONTEXTTYPE * const contexts = \ + CONTAINER_OF(FUNCNAME##_fake.return_val_seq, \ + CONTEXTTYPE, RESULTFIELD); \ + size_t const seq_idx = (FUNCNAME##_fake.return_val_seq_idx < \ + FUNCNAME##_fake.return_val_seq_len) ? \ + FUNCNAME##_fake.return_val_seq_idx++ :\ + FUNCNAME##_fake.return_val_seq_idx - 1;\ + CONTEXTTYPE * const CONTEXTPTRNAME = &contexts[seq_idx]; \ + HANDLERBODY; \ + } \ + return FUNCNAME##_fake.return_val + +/** + * @} + */ + +#endif /* ZEPHYR_SUBSYS_TESTSUITE_INCLUDE_ZEPHYR_FFF_EXTENSIONS_H_ */ diff --git a/tests/subsys/testsuite/fff_fake_contexts/CMakeLists.txt b/tests/subsys/testsuite/fff_fake_contexts/CMakeLists.txt new file mode 100644 index 000000000000..3f71a78ed033 --- /dev/null +++ b/tests/subsys/testsuite/fff_fake_contexts/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright (c) 2023 Legrand North America, LLC. +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +if(BOARD STREQUAL unit_testing) + find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE}) + set(target testbinary) +else() + find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + set(target app) +endif() + +project(base) +target_sources(${target} PRIVATE + src/code_under_test.c + src/main.c + src/fakes/called_API.c +) + +target_include_directories(${target} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${CMAKE_CURRENT_SOURCE_DIR}/include +) diff --git a/tests/subsys/testsuite/fff_fake_contexts/include/zephyr/called_API.h b/tests/subsys/testsuite/fff_fake_contexts/include/zephyr/called_API.h new file mode 100644 index 000000000000..b083c9a193d9 --- /dev/null +++ b/tests/subsys/testsuite/fff_fake_contexts/include/zephyr/called_API.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023 Legrand North America, LLC. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_TESTS_SUBSYS_TESTSUITE_FFF_FAKE_CONTEXTS_INCLUDE_ZEPHYR_CALLED_API_H_ +#define ZEPHYR_TESTS_SUBSYS_TESTSUITE_FFF_FAKE_CONTEXTS_INCLUDE_ZEPHYR_CALLED_API_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* A container struct for hidden instance data */ +struct called_API_info; + +/** + * @brief Provide an instance handle to a session of the called_API. + * + * This API is defined for the code_under_test() example to call. + * It represents a routine which provides call-unique data to the caller + * as well as providing a return value. This requires the _custom_fake + * implementation to serve the data from a custom_fake context struture, + * where each call needs to return a unique, configured value. + * + * @param instance_out Session instance handle for caller to use. + * + * @return zero(0) upon success, with *instance_out updated. + * @return -EINVAL if invalid parameter(s) + * @return -E2BIG if more calls were made than expected. + */ +int called_API_open(const struct called_API_info **instance_out); + +/** + * @brief Return an instance handle to a session of the called_API. + * + * This API is defined for the code_under_test() example to call. + * It represents a routine which requires specific data from the caller + * as well as providing a return value. This is defined to + * have the code_under_test call multiple functions to illustrate + * a way to verify a specific calling sequence was made + * + * @param instance Session instance handle provided by called_API_open + * + * @return zero(0) upon success, with instance invalidated. + * @return -EINVAL if invalid parameter(s) + * @return -E2BIG if more calls were made than expected. + */ +int called_API_close(const struct called_API_info *instance); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_TESTS_SUBSYS_TESTSUITE_FFF_FAKE_CONTEXTS_INCLUDE_ZEPHYR_CALLED_API_H_ */ diff --git a/tests/subsys/testsuite/fff_fake_contexts/include/zephyr/code_under_test.h b/tests/subsys/testsuite/fff_fake_contexts/include/zephyr/code_under_test.h new file mode 100644 index 000000000000..cab38d0f520f --- /dev/null +++ b/tests/subsys/testsuite/fff_fake_contexts/include/zephyr/code_under_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Legrand North America, LLC. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_TESTS_SUBSYS_TESTSUITE_FFF_FAKE_CONTEXTS_INCLUDE_ZEPHYR_CODE_UNDER_TEST_H_ +#define ZEPHYR_TESTS_SUBSYS_TESTSUITE_FFF_FAKE_CONTEXTS_INCLUDE_ZEPHYR_CODE_UNDER_TEST_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Opens and closes called_API session twice + * + * This routine loops twice on opening/closing a called_API session. + * Failures cause early termination of the loop, and the error number + * from the called routine is returned by this routine. This routine + * is designed for exercising custom_fake routines that need to use + * call-specific data. + * + * @return zero(0) upon success + * @return -EINVAL if invalid parameter(s) + * @return -E2BIG if more calls were made than expected. + */ +int code_under_test(void); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_TESTS_SUBSYS_TESTSUITE_FFF_FAKE_CONTEXTS_INCLUDE_ZEPHYR_CODE_UNDER_TEST_H_ */ diff --git a/tests/subsys/testsuite/fff_fake_contexts/prj.conf b/tests/subsys/testsuite/fff_fake_contexts/prj.conf new file mode 100644 index 000000000000..b79d06d0c644 --- /dev/null +++ b/tests/subsys/testsuite/fff_fake_contexts/prj.conf @@ -0,0 +1,5 @@ +# Copyright (c) 2023 Legrand North America, LLC. +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/testsuite/fff_fake_contexts/src/code_under_test.c b/tests/subsys/testsuite/fff_fake_contexts/src/code_under_test.c new file mode 100644 index 000000000000..7aa8514185bd --- /dev/null +++ b/tests/subsys/testsuite/fff_fake_contexts/src/code_under_test.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Legrand North America, LLC. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include /* NULL */ +#include +#include + + +int code_under_test(void) +{ + int result = 0; + + for (int i = 0; i < 2; ++i) { + const struct called_API_info *called_API = NULL; + + result = called_API_open(&called_API); + if (result != 0) { + break; + } + + result = called_API_close(called_API); + if (result != 0) { + break; + } + + } + + return result; +} diff --git a/tests/subsys/testsuite/fff_fake_contexts/src/fakes/called_API.c b/tests/subsys/testsuite/fff_fake_contexts/src/fakes/called_API.c new file mode 100644 index 000000000000..13c8b190a52b --- /dev/null +++ b/tests/subsys/testsuite/fff_fake_contexts/src/fakes/called_API.c @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2023 Legrand North America, LLC. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "fakes/called_API.h" + +DEFINE_FAKE_VALUE_FUNC(int, called_API_open, const struct called_API_info **); +DEFINE_FAKE_VALUE_FUNC(int, called_API_close, const struct called_API_info *); diff --git a/tests/subsys/testsuite/fff_fake_contexts/src/fakes/called_API.h b/tests/subsys/testsuite/fff_fake_contexts/src/fakes/called_API.h new file mode 100644 index 000000000000..12b696597845 --- /dev/null +++ b/tests/subsys/testsuite/fff_fake_contexts/src/fakes/called_API.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 Legrand North America, LLC. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_TESTS_SUBSYS_TESTSUITE_FFF_FAKE_CONTEXTS_FAKES_CALLED_API_H_ +#define ZEPHYR_TESTS_SUBSYS_TESTSUITE_FFF_FAKE_CONTEXTS_FAKES_CALLED_API_H_ + +#include +#include + +#define ZEPHYR_CALLED_API_FFF_FAKES_LIST(FAKE) \ + FAKE(called_API_open) \ + FAKE(called_API_close) \ + + +#ifdef __cplusplus +extern "C" { +#endif + +DECLARE_FAKE_VALUE_FUNC(int, called_API_open, const struct called_API_info **); +DECLARE_FAKE_VALUE_FUNC(int, called_API_close, const struct called_API_info *); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_TESTS_SUBSYS_TESTSUITE_FFF_FAKE_CONTEXTS_FAKES_CALLED_API_H_ */ diff --git a/tests/subsys/testsuite/fff_fake_contexts/src/main.c b/tests/subsys/testsuite/fff_fake_contexts/src/main.c new file mode 100644 index 000000000000..98a89b002905 --- /dev/null +++ b/tests/subsys/testsuite/fff_fake_contexts/src/main.c @@ -0,0 +1,338 @@ +/* + * Copyright (c) 2023 Legrand North America, LLC. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + + +#include +#include +#include + +#include "fakes/called_API.h" + + +#define RESET_HISTORY_AND_FAKES() \ + ZEPHYR_CALLED_API_FFF_FAKES_LIST(RESET_FAKE) \ + FFF_RESET_HISTORY() + +DEFINE_FFF_GLOBALS; + + +/* + * Custom Fakes: + */ + +struct called_API_open_custom_fake_context { + /* Written to code under test by custom fake */ + const struct called_API_info * const instance_out; + + int result; +}; + +int called_API_open_custom_fake( + const struct called_API_info **instance_out) +{ + RETURN_HANDLED_CONTEXT( + called_API_open, + struct called_API_open_custom_fake_context, + result, /* return field name in _fake_context struct */ + context, /* Name of context ptr variable used below */ + { + if (context != NULL) { + if (context->result == 0) { + if (instance_out != NULL) { + *instance_out = context->instance_out; + } + } + + return context->result; + } + + return called_API_open_fake.return_val; + } + ); +} + +/* + * Tests + */ + +ZTEST(fff_fake_contexts_tests, test_code_under_test) +{ + struct test_case { + const char *description_oneliner; + + void **expected_call_history; + + /* Last FFF sequence entry is reused for excess calls. + * Have an extra entry that returns a distinct failure (-E2BIG) + * + * Expect one less call than _len, or 0 if sequence ptr is NULL + * + * Configure to return -E2BIG if excess calls. + */ + int called_API_open_custom_fake_contexts_len; + struct called_API_open_custom_fake_context * + called_API_open_custom_fake_contexts; + + int called_API_close_fake_return_val_seq_len; + int *called_API_close_fake_return_val_seq; + + int result_expected; + } + const test_cases[] = { + { + .description_oneliner = "First called_API_open() returns -EINVAL", + .expected_call_history = (void * []) + { + called_API_open, + NULL, /* mark end of array */ + }, + + .called_API_open_custom_fake_contexts_len = 2, + .called_API_open_custom_fake_contexts = + (struct called_API_open_custom_fake_context []) + { + { + .result = -EINVAL, + }, + { + .result = -E2BIG, /* for excessive calls */ + }, + }, + + .called_API_close_fake_return_val_seq = NULL, + + .result_expected = -EINVAL, + }, + { + .description_oneliner = "First called_API_close() returns -EINVAL", + .expected_call_history = (void * []) + { + called_API_open, + called_API_close, + NULL, /* mark end of array */ + }, + + .called_API_open_custom_fake_contexts_len = 2, + .called_API_open_custom_fake_contexts = + (struct called_API_open_custom_fake_context []) + { + { + .result = 0, + }, + { + .result = -E2BIG, /* for excessive calls */ + }, + }, + + .called_API_close_fake_return_val_seq_len = 2, + .called_API_close_fake_return_val_seq = (int []) + { + -EINVAL, + -E2BIG, /* for excessive calls */ + }, + + .result_expected = -EINVAL, + }, + { + .description_oneliner = "Second called_API_open() returns -EINVAL", + .expected_call_history = (void * []) + { + called_API_open, + called_API_close, + called_API_open, + NULL, /* mark end of array */ + }, + + .called_API_open_custom_fake_contexts_len = 3, + .called_API_open_custom_fake_contexts = + (struct called_API_open_custom_fake_context []) + { + { + .result = 0, + }, + { + .result = -EINVAL, + }, + { + .result = -E2BIG, /* for excessive calls */ + }, + }, + + .called_API_close_fake_return_val_seq_len = 2, + .called_API_close_fake_return_val_seq = (int []) + { + 0, + -E2BIG, /* for excessive calls */ + }, + + .result_expected = -EINVAL, + }, + { + .description_oneliner = "Second called_API_close() returns -EINVAL", + .expected_call_history = (void * []) + { + called_API_open, + called_API_close, + called_API_open, + called_API_close, + NULL, /* mark end of array */ + }, + + .called_API_open_custom_fake_contexts_len = 3, + .called_API_open_custom_fake_contexts = + (struct called_API_open_custom_fake_context []) + { + { + .result = 0, + }, + { + .result = 0, + }, + { + .result = -E2BIG, /* for excessive calls */ + }, + }, + + .called_API_close_fake_return_val_seq_len = 3, + .called_API_close_fake_return_val_seq = (int []) + { + 0, + -EINVAL, + -E2BIG, /* for excessive calls */ + }, + + .result_expected = -EINVAL, + }, + { + .description_oneliner = "All calls return no error", + .expected_call_history = (void * []) + { + called_API_open, + called_API_close, + called_API_open, + called_API_close, + NULL, /* mark end of array */ + }, + + .called_API_open_custom_fake_contexts_len = 3, + .called_API_open_custom_fake_contexts = + (struct called_API_open_custom_fake_context []) + { + { + .result = 0, + }, + { + .result = 0, + }, + { + .result = -E2BIG, /* for excessive calls */ + }, + }, + + .called_API_close_fake_return_val_seq_len = 3, + .called_API_close_fake_return_val_seq = (int []) + { + 0, + 0, + -E2BIG, /* for excessive calls */ + }, + + .result_expected = 0, + }, + + }; + + for (int i = 0; i < ARRAY_SIZE(test_cases); ++i) { + const struct test_case * const tc = &test_cases[i]; + + + printk("Checking test_cases[%i]: %s\n", i, + (tc->description_oneliner != NULL) ? tc->description_oneliner : ""); + + /* + * Set up pre-conditions + */ + RESET_HISTORY_AND_FAKES(); + + /* NOTE: Point to the return type field in the first returns struct. + * This custom_fake: + * - uses *_fake.return_val_seq and CONTAINER_OF() + * to determine the beginning of the array of structures. + * - uses *_fake.return_val_seq_id to index into + * the array of structures. + * This overloading is to allow the return_val_seq to + * also contain call-specific output parameters to be + * applied by the custom_fake. + */ + called_API_open_fake.return_val = -E2BIG; /* for excessive calls */ + SET_RETURN_SEQ(called_API_open, + &tc->called_API_open_custom_fake_contexts[0].result, + tc->called_API_open_custom_fake_contexts_len); + called_API_open_fake.custom_fake = called_API_open_custom_fake; + + /* NOTE: This uses the standard _fake without contexts */ + called_API_close_fake.return_val = -E2BIG; /* for excessive calls */ + SET_RETURN_SEQ(called_API_close, + tc->called_API_close_fake_return_val_seq, + tc->called_API_close_fake_return_val_seq_len); + + + /* + * Call code_under_test + */ + int result = code_under_test(); + + + /* + * Verify expected behavior of code_under_test: + * - call history, args per call + * - results + * - outputs + */ + if (tc->expected_call_history != NULL) { + for (int j = 0; j < fff.call_history_idx; ++j) { + zassert_equal(fff.call_history[j], + tc->expected_call_history[j], NULL); + } + zassert_is_null(tc->expected_call_history[ + fff.call_history_idx], NULL); + } else { + zassert_equal(fff.call_history_idx, 0, NULL); + } + + + const int called_API_open_fake_call_count_expected = + (tc->called_API_open_custom_fake_contexts == NULL) ? 0 : + tc->called_API_open_custom_fake_contexts_len - 1; + + zassert_equal(called_API_open_fake.call_count, + called_API_open_fake_call_count_expected, NULL); + for (int j = 0; j < called_API_open_fake_call_count_expected; ++j) { + zassert_not_null(called_API_open_fake.arg0_history[j], NULL); + } + + + const int called_API_close_fake_call_count_expected = + (tc->called_API_close_fake_return_val_seq == NULL) ? 0 : + tc->called_API_close_fake_return_val_seq_len - 1; + + zassert_equal(called_API_close_fake.call_count, + called_API_close_fake_call_count_expected, NULL); + for (int j = 0; j < called_API_close_fake_call_count_expected; ++j) { + /* Verify code_under_test returns value provided by open. */ + zassert_equal(called_API_close_fake.arg0_history[j], + tc->called_API_open_custom_fake_contexts[j] + .instance_out, NULL); + } + + + zassert_equal(result, tc->result_expected, NULL); + } +} + +ZTEST_SUITE(fff_fake_contexts_tests, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/subsys/testsuite/fff_fake_contexts/testcase.yaml b/tests/subsys/testsuite/fff_fake_contexts/testcase.yaml new file mode 100644 index 000000000000..ad6bc36f37c6 --- /dev/null +++ b/tests/subsys/testsuite/fff_fake_contexts/testcase.yaml @@ -0,0 +1,13 @@ +# Copyright (c) 2023 Legrand North America, LLC. +# SPDX-License-Identifier: Apache-2.0 + +tests: + testing.testsuite.fff_fake_contexts.unit: + tags: test_framework + type: unit + testing.testsuite.fff_fake_contexts: + integration_platforms: + - qemu_cortex_m3 + - native_posix_64 + tags: test_framework + platform_allow: qemu_cortex_m3 native_posix_64 From 6c47b9a5d740b2ba234a12d339a7c380b3bd0ac4 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Thu, 16 Mar 2023 16:36:21 +0100 Subject: [PATCH 0302/1906] MAINTAINERS: add pdgendt as collaborator for Atmel Add myself as a collaborator for the Atmel SAM platform and HAL. Signed-off-by: Pieter De Gendt --- MAINTAINERS.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index e2b34a14fcce..3cc26775010c 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -2161,6 +2161,7 @@ Microchip SAM Platforms: - nandojve collaborators: - attie-argentum + - pdgendt - mnkp - stephanosio files: @@ -2619,6 +2620,8 @@ West: status: maintained maintainers: - nandojve + collaborators: + - pdgendt files: - modules/Kconfig.atmel labels: From b0ea0c8ec6135aa5cb8d0e70ca72af2abe1f38fa Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Thu, 16 Mar 2023 06:01:20 +0000 Subject: [PATCH 0303/1906] debug: coredump: Fix build issue with armclang Building tests/drivers/coredump/coredump_api with armclang gets: include/zephyr/debug/coredump.h:98:2: error: unknown type name 'uint8_t' uint8_t *buffer; ^ Fix simply be including to get uint8_t typedef. Signed-off-by: Kumar Gala --- include/zephyr/debug/coredump.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/zephyr/debug/coredump.h b/include/zephyr/debug/coredump.h index ce36d072215f..2df10aa6c5e2 100644 --- a/include/zephyr/debug/coredump.h +++ b/include/zephyr/debug/coredump.h @@ -8,6 +8,7 @@ #define ZEPHYR_INCLUDE_DEBUG_COREDUMP_H_ #include +#include #include /* Query ID */ From f3cbd34d3f5f27c886b7b384f2ea2bf6fb6401b2 Mon Sep 17 00:00:00 2001 From: Nick Ward Date: Thu, 2 Feb 2023 13:41:16 +1100 Subject: [PATCH 0304/1906] drivers: sensor: bq274xx: add CONFIG_BQ274XX_PM This symbol allows users of the driver to disable the power management feature of just this sensor if they are not using the int_gpios pin of the BQ274XX. Signed-off-by: Nick Ward --- drivers/sensor/bq274xx/Kconfig | 10 ++++++++++ drivers/sensor/bq274xx/bq274xx.c | 17 +++++++++++------ drivers/sensor/bq274xx/bq274xx.h | 2 +- drivers/sensor/bq274xx/bq274xx_trigger.c | 4 ++-- dts/bindings/sensor/ti,bq274xx.yaml | 3 ++- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/drivers/sensor/bq274xx/Kconfig b/drivers/sensor/bq274xx/Kconfig index de4d29028259..f718be36bcc1 100644 --- a/drivers/sensor/bq274xx/Kconfig +++ b/drivers/sensor/bq274xx/Kconfig @@ -12,6 +12,16 @@ menuconfig BQ274XX if BQ274XX +config BQ274XX_PM + bool "BQ274XX Power Management" + depends on PM_DEVICE + default y + help + This option enables the device power management feature of the + BQ274XX. + Note: if the int_gpios pin is not used then this feature must be + disabled. + choice BQ274XX_TRIGGER_MODE prompt "Trigger mode" default BQ274XX_TRIGGER_NONE diff --git a/drivers/sensor/bq274xx/bq274xx.c b/drivers/sensor/bq274xx/bq274xx.c index f2af58b98c08..6266bc2d88d1 100644 --- a/drivers/sensor/bq274xx/bq274xx.c +++ b/drivers/sensor/bq274xx/bq274xx.c @@ -384,7 +384,7 @@ static int bq274xx_gauge_init(const struct device *dev) return -ENODEV; } -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_BQ274XX_TRIGGER) +#if defined(CONFIG_BQ274XX_PM) || defined(CONFIG_BQ274XX_TRIGGER) if (!device_is_ready(config->int_gpios.port)) { LOG_ERR("GPIO device pointer is not ready to be used"); return -ENODEV; @@ -659,7 +659,7 @@ static int bq274xx_gauge_configure(const struct device *dev) return 0; } -#ifdef CONFIG_PM_DEVICE +#ifdef CONFIG_BQ274XX_PM static int bq274xx_enter_shutdown_mode(const struct device *dev) { int status; @@ -756,7 +756,7 @@ static int bq274xx_pm_action(const struct device *dev, return ret; } -#endif /* CONFIG_PM_DEVICE */ +#endif /* CONFIG_BQ274XX_PM */ static const struct sensor_driver_api bq274xx_battery_driver_api = { .sample_fetch = bq274xx_sample_fetch, @@ -766,11 +766,16 @@ static const struct sensor_driver_api bq274xx_battery_driver_api = { #endif }; -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_BQ274XX_TRIGGER) +#if defined(CONFIG_BQ274XX_PM) || defined(CONFIG_BQ274XX_TRIGGER) #define BQ274XX_INT_CFG(index) \ .int_gpios = GPIO_DT_SPEC_INST_GET(index, int_gpios), +#define PM_BQ274XX_DT_INST_DEFINE(index, bq274xx_pm_action) \ + PM_DEVICE_DT_INST_DEFINE(index, bq274xx_pm_action) +#define PM_BQ274XX_DT_INST_GET(index) PM_DEVICE_DT_INST_GET(index) #else #define BQ274XX_INT_CFG(index) +#define PM_BQ274XX_DT_INST_DEFINE(index, bq274xx_pm_action) +#define PM_BQ274XX_DT_INST_GET(index) NULL #endif #define BQ274XX_INIT(index) \ @@ -786,10 +791,10 @@ static const struct sensor_driver_api bq274xx_battery_driver_api = { .lazy_loading = DT_INST_PROP(index, zephyr_lazy_load), \ }; \ \ - PM_DEVICE_DT_INST_DEFINE(index, bq274xx_pm_action); \ + PM_BQ274XX_DT_INST_DEFINE(index, bq274xx_pm_action); \ \ SENSOR_DEVICE_DT_INST_DEFINE(index, &bq274xx_gauge_init, \ - PM_DEVICE_DT_INST_GET(index), \ + PM_BQ274XX_DT_INST_GET(index), \ &bq274xx_driver_##index, \ &bq274xx_config_##index, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, \ diff --git a/drivers/sensor/bq274xx/bq274xx.h b/drivers/sensor/bq274xx/bq274xx.h index 6dbb346ce1c5..2306fb9bb61b 100644 --- a/drivers/sensor/bq274xx/bq274xx.h +++ b/drivers/sensor/bq274xx/bq274xx.h @@ -114,7 +114,7 @@ struct bq274xx_config { uint16_t design_capacity; uint16_t taper_current; uint16_t terminate_voltage; -#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_BQ274XX_TRIGGER) +#if defined(CONFIG_BQ274XX_PM) || defined(CONFIG_BQ274XX_TRIGGER) struct gpio_dt_spec int_gpios; #endif bool lazy_loading; diff --git a/drivers/sensor/bq274xx/bq274xx_trigger.c b/drivers/sensor/bq274xx/bq274xx_trigger.c index bc08492a8ea5..207f82d708a3 100644 --- a/drivers/sensor/bq274xx/bq274xx_trigger.c +++ b/drivers/sensor/bq274xx/bq274xx_trigger.c @@ -10,7 +10,7 @@ #include #include -#ifdef CONFIG_PM_DEVICE +#ifdef CONFIG_BQ274XX_PM #include #endif @@ -111,7 +111,7 @@ int bq274xx_trigger_set(const struct device *dev, struct bq274xx_data *data = dev->data; int status; -#ifdef CONFIG_PM_DEVICE +#ifdef CONFIG_BQ274XX_PM enum pm_device_state state; (void)pm_device_state_get(dev, &state); diff --git a/dts/bindings/sensor/ti,bq274xx.yaml b/dts/bindings/sensor/ti,bq274xx.yaml index b641e401a9ff..16032b625cf3 100644 --- a/dts/bindings/sensor/ti,bq274xx.yaml +++ b/dts/bindings/sensor/ti,bq274xx.yaml @@ -36,7 +36,8 @@ properties: description: | The INT signal defaults to active low open drain, so requires a pull-up on the board. By default it acts as an output and signals - specific events happening (e.g. change in State of Charge). While in + specific events happening (e.g. change in State of Charge). + Note this pin is required for this sensor's power management APIs: in shutdown mode it acts as an input and toggling it will make the sensor exit the mode. From c49a6a0b0cd9ef1b5c6bd8164bb2ea37657e72c5 Mon Sep 17 00:00:00 2001 From: Nick Ward Date: Mon, 6 Mar 2023 12:40:55 +1100 Subject: [PATCH 0305/1906] samples: sensor: bq274xx: add test for CONFIG_BQ274XX_PM=n Adds a test for BQ274XX driver option CONFIG_BQ274XX_PM=n. Signed-off-by: Nick Ward --- samples/sensor/bq274xx/sample.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/samples/sensor/bq274xx/sample.yaml b/samples/sensor/bq274xx/sample.yaml index c4d92a21b677..1912a288b195 100644 --- a/samples/sensor/bq274xx/sample.yaml +++ b/samples/sensor/bq274xx/sample.yaml @@ -9,3 +9,12 @@ tests: - nrf9160_innblue22 tags: sensors depends_on: i2c + sample.sensor.bq274xx_without_int_gpios: + harness: sensor + platform_allow: nrf9160_innblue22 + integration_platforms: + - nrf9160_innblue22 + tags: sensors + depends_on: i2c + extra_configs: + - CONFIG_BQ274XX_PM=n From 8ba27967e4f36a5136dd6f106856d02a58e36c64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Ciupis?= Date: Fri, 17 Mar 2023 07:23:16 +0100 Subject: [PATCH 0306/1906] manifest: update hal_nordic revision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates revision of hal_nordic repository to bring the latest changes in IEEE 802.15.4 driver. Signed-off-by: Jędrzej Ciupis --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 190b368a4f2f..f2c77d6f5344 100644 --- a/west.yml +++ b/west.yml @@ -83,7 +83,7 @@ manifest: groups: - hal - name: hal_nordic - revision: 609d4b41fe9773cd294eb8656d99eb9385389e52 + revision: 6c6b666ab3bc02b6fa0696ab7bd15658a694a03a path: modules/hal/nordic groups: - hal From 045c686734918710905b74e14f81582b2a1f5eab Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Thu, 16 Mar 2023 15:49:54 -0700 Subject: [PATCH 0307/1906] dma: dw: Add a debug utility function Add a helper function to dump the GPDMA SHIM and channel registers for debug along with a config option to enable it. Co-developed-by: Tom Burdick Singed-off-by: Tom Burdick Signed-off-by: Ranjani Sridharan --- drivers/dma/Kconfig.intel_adsp_gpdma | 5 +++++ drivers/dma/dma_dw_common.h | 4 ++++ drivers/dma/dma_intel_adsp_gpdma.c | 32 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/drivers/dma/Kconfig.intel_adsp_gpdma b/drivers/dma/Kconfig.intel_adsp_gpdma index 8488793ae12a..a590a3ac277c 100644 --- a/drivers/dma/Kconfig.intel_adsp_gpdma +++ b/drivers/dma/Kconfig.intel_adsp_gpdma @@ -26,6 +26,11 @@ config DMA_INTEL_ADSP_GPDMA_HAS_LLP Intel ADSP GPDMA may optionally have a linear link position feature. +config DMA_INTEL_ADSP_GPDMA_DEBUG + bool "Debug dump for IP registers" + help + Dump Intel ADSP GPDMA registers for debug + source "drivers/dma/Kconfig.dw_common" endif # DMA_INTEL_ADSP_GPDMA diff --git a/drivers/dma/dma_dw_common.h b/drivers/dma/dma_dw_common.h index 44274f9ef711..c4b33fac584e 100644 --- a/drivers/dma/dma_dw_common.h +++ b/drivers/dma/dma_dw_common.h @@ -152,6 +152,10 @@ extern "C" { /* min number of elems for config with irq disabled */ #define DW_DMA_CFG_NO_IRQ_MIN_ELEMS 3 +#define DW_DMA_CHANNEL_REGISTER_OFFSET_END 0x50 +#define DW_DMA_IP_REGISTER_OFFSET_END 0x418 +#define DW_DMA_IP_REGISTER_OFFSET_START 0x2C0 + /* linked list item address */ #define DW_DMA_LLI_ADDRESS(lli, dir) \ (((dir) == MEMORY_TO_PERIPHERAL) ? ((lli)->sar) : ((lli)->dar)) diff --git a/drivers/dma/dma_intel_adsp_gpdma.c b/drivers/dma/dma_intel_adsp_gpdma.c index 8310e561d08a..5d673e36cee1 100644 --- a/drivers/dma/dma_intel_adsp_gpdma.c +++ b/drivers/dma/dma_intel_adsp_gpdma.c @@ -51,6 +51,38 @@ struct intel_adsp_gpdma_cfg { uint32_t shim; }; +#ifdef DMA_INTEL_ADSP_GPDMA_DEBUG +static void intel_adsp_gpdma_dump_registers(const struct device *dev, uint32_t channel) +{ + const struct intel_adsp_gpdma_cfg *const dev_cfg = dev->config; + const struct dw_dma_dev_cfg *const dw_cfg = &dev_cfg->dw_cfg; + uint32_t cap, ctl, ipptr, llpc, llpl, llpu; + int i; + + /* Shims */ + cap = dw_read(dev_cfg->shim, 0x0); + ctl = dw_read(dev_cfg->shim, 0x4); + ipptr = dw_read(dev_cfg->shim, 0x8); + llpc = dw_read(dev_cfg->shim, GPDMA_CHLLPC_OFFSET(channel)); + llpl = dw_read(dev_cfg->shim, GPDMA_CHLLPL(channel)); + llpu = dw_read(dev_cfg->shim, GPDMA_CHLLPU(channel)); + + LOG_INF("channel: %d cap %x, ctl %x, ipptr %x, llpc %x, llpl %x, llpu %x", + channel, cap, ctl, ipptr, llpc, llpl, llpu); + + /* Channel Register Dump */ + for (i = 0; i <= DW_DMA_CHANNEL_REGISTER_OFFSET_END; i += 0x8) + LOG_INF(" channel register offset: %#x value: %#x\n", chan_reg_offs[i], + dw_read(dw_cfg->base, DW_CHAN_OFFSET(channel) + chan_reg_offs[i])); + + /* IP Register Dump */ + for (i = DW_DMA_CHANNEL_REGISTER_OFFSET_START; i <= DW_DMA_CHANNEL_REGISTER_OFFSET_END; + i += 0x8) + LOG_INF(" ip register offset: %#x value: %#x\n", ip_reg_offs[i], + dw_read(dw_cfg->base, ip_reg_offs[i])); +} +#endif + static void intel_adsp_gpdma_llp_config(const struct device *dev, uint32_t channel, uint32_t dma_slot) { From 08d9efb202cc4f436c7321fd49130c21a525e90d Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Thu, 16 Mar 2023 15:05:25 -0700 Subject: [PATCH 0308/1906] dma: dw: Do not program SAR/DAR and CTL_HI/LO when using HW LLI When using the HW LLI, there is no need to program these resgisters. Signed-off-by: Ranjani Sridharan --- drivers/dma/dma_dw_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/dma/dma_dw_common.c b/drivers/dma/dma_dw_common.c index 9dc24f63e4e9..3eb431ff8281 100644 --- a/drivers/dma/dma_dw_common.c +++ b/drivers/dma/dma_dw_common.c @@ -475,8 +475,7 @@ int dw_dma_start(const struct device *dev, uint32_t channel) dw_write(dev_cfg->base, DW_LLP(channel), llp); LOG_DBG("ctrl_lo %x, masked ctrl_lo %x, LLP %x", lli->ctrl_lo, masked_ctrl_lo, dw_read(dev_cfg->base, DW_LLP(channel))); -#endif /* CONFIG_DMA_DW_HW_LLI */ - +#else /* channel needs to start from scratch, so write SAR and DAR */ dw_write(dev_cfg->base, DW_SAR(channel), lli->sar); dw_write(dev_cfg->base, DW_DAR(channel), lli->dar); @@ -484,6 +483,7 @@ int dw_dma_start(const struct device *dev, uint32_t channel) /* program CTL_LO and CTL_HI */ dw_write(dev_cfg->base, DW_CTRL_LOW(channel), lli->ctrl_lo); dw_write(dev_cfg->base, DW_CTRL_HIGH(channel), lli->ctrl_hi); +#endif /* CONFIG_DMA_DW_HW_LLI */ /* program CFG_LO and CFG_HI */ dw_write(dev_cfg->base, DW_CFG_LOW(channel), chan_data->cfg_lo); From 6226f9e6e44f7f2f5ef87fa2cc7406446a6938cc Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Thu, 16 Mar 2023 15:07:09 -0700 Subject: [PATCH 0309/1906] dma: dw: fix the return value check The WAIT_FOR() function returns the value of checked expression. So fix the return value check to log and return the timeout error when checking if the FIFO is empty during stop. Signed-off-by: Ranjani Sridharan --- drivers/dma/dma_dw_common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/dma/dma_dw_common.c b/drivers/dma/dma_dw_common.c index 3eb431ff8281..2fe3a60679ad 100644 --- a/drivers/dma/dma_dw_common.c +++ b/drivers/dma/dma_dw_common.c @@ -552,10 +552,11 @@ int dw_dma_stop(const struct device *dev, uint32_t channel) chan_data->cfg_lo | DW_CFGL_SUSPEND | DW_CFGL_DRAIN); /* now we wait for FIFO to be empty */ - bool timeout = WAIT_FOR(dw_read(dev_cfg->base, DW_CFG_LOW(channel)) & DW_CFGL_FIFO_EMPTY, + bool fifo_empty = WAIT_FOR(dw_read(dev_cfg->base, DW_CFG_LOW(channel)) & DW_CFGL_FIFO_EMPTY, DW_DMA_TIMEOUT, k_busy_wait(DW_DMA_TIMEOUT/10)); - if (timeout) { + if (!fifo_empty) { LOG_ERR("%s: dma %d channel drain time out", __func__, channel); + return -ETIMEDOUT; } #endif From b32b321f502a875f8256be55e83a22a947c7b8c2 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Thu, 16 Mar 2023 15:09:59 -0700 Subject: [PATCH 0310/1906] dma: dw: Poll to check for channel disable with timeout After disabling the channel, it is recommended to poll with timeout to ensure that the channel has actually been disabled. Without this, reconfiguring the DMA again while the channel is active could lead to unexpected behavior and/or DMA underruns. Signed-off-by: Ranjani Sridharan --- drivers/dma/dma_dw_common.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/dma/dma_dw_common.c b/drivers/dma/dma_dw_common.c index 2fe3a60679ad..16fd3c875b8f 100644 --- a/drivers/dma/dma_dw_common.c +++ b/drivers/dma/dma_dw_common.c @@ -562,6 +562,14 @@ int dw_dma_stop(const struct device *dev, uint32_t channel) dw_write(dev_cfg->base, DW_DMA_CHAN_EN, DW_CHAN_MASK(channel)); + /* now we wait for channel to be disabled */ + bool is_disabled = WAIT_FOR(!(dw_read(dev_cfg->base, DW_DMA_CHAN_EN) & DW_CHAN(channel)), + DW_DMA_TIMEOUT, k_busy_wait(DW_DMA_TIMEOUT/10)); + if (!is_disabled) { + LOG_ERR("%s: dma %d channel disable timeout", __func__, channel); + return -ETIMEDOUT; + } + #if CONFIG_DMA_DW_HW_LLI for (i = 0; i < chan_data->lli_count; i++) { lli->ctrl_hi &= ~DW_CTLH_DONE(1); From a2e0a860a61eab91130216de986d541c5ce9eb0f Mon Sep 17 00:00:00 2001 From: Aaron Massey Date: Thu, 16 Mar 2023 10:31:27 -0600 Subject: [PATCH 0311/1906] fuel_gauge: Add init priority Add an device driver initialization priority for fuel gauge drivers. Signed-off-by: Aaron Massey --- drivers/fuel_gauge/Kconfig | 6 ++++++ drivers/fuel_gauge/sbs_gauge/sbs_gauge.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/fuel_gauge/Kconfig b/drivers/fuel_gauge/Kconfig index e85af9f79f2b..9555f8a39e1e 100644 --- a/drivers/fuel_gauge/Kconfig +++ b/drivers/fuel_gauge/Kconfig @@ -13,6 +13,12 @@ module = FUEL_GAUGE module-str = fuel_gauge source "subsys/logging/Kconfig.template.log_config" +config FUEL_GAUGE_INIT_PRIORITY + int "Battery Fuel Gauge init priority" + default 90 + help + Battery fuel gauge initialization priority. + source "drivers/fuel_gauge/sbs_gauge/Kconfig" endif # FUEL_GAUGE diff --git a/drivers/fuel_gauge/sbs_gauge/sbs_gauge.c b/drivers/fuel_gauge/sbs_gauge/sbs_gauge.c index fa5798a3953e..1429400d1241 100644 --- a/drivers/fuel_gauge/sbs_gauge/sbs_gauge.c +++ b/drivers/fuel_gauge/sbs_gauge/sbs_gauge.c @@ -214,6 +214,6 @@ static const struct fuel_gauge_driver_api sbs_gauge_driver_api = { }; \ \ DEVICE_DT_INST_DEFINE(index, &sbs_gauge_init, NULL, NULL, &sbs_gauge_config_##index, \ - POST_KERNEL, 90, &sbs_gauge_driver_api); + POST_KERNEL, CONFIG_FUEL_GAUGE_INIT_PRIORITY, &sbs_gauge_driver_api); DT_INST_FOREACH_STATUS_OKAY(SBS_GAUGE_INIT) From 831bd2f841faa49008c4acd471bb019f44de1c9d Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Wed, 15 Mar 2023 23:58:29 +0000 Subject: [PATCH 0312/1906] armclang: fix compiler warnings with isprint() We get compile warnings of the form: drivers/console/uart_console.c:508:8: error: converting the result of '<<' to a boolean; did you mean '((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'? [-Werror,-Wint-in-bool-context] if (!isprint(byte)) { ^ Since isprint returns an int, change check to an explicit test against the return value. Signed-off-by: Kumar Gala --- drivers/console/uart_console.c | 2 +- samples/subsys/shell/shell_module/src/main.c | 4 ++-- subsys/logging/log_output.c | 2 +- subsys/shell/shell.c | 4 ++-- subsys/tracing/tracing_backend_uart.c | 2 +- tests/lib/c_lib/src/main.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/console/uart_console.c b/drivers/console/uart_console.c index b0a85cf480d9..d527768c1d98 100644 --- a/drivers/console/uart_console.c +++ b/drivers/console/uart_console.c @@ -505,7 +505,7 @@ static void uart_console_isr(const struct device *unused, void *user_data) } /* Handle special control characters */ - if (!isprint(byte)) { + if (isprint(byte) == 0) { switch (byte) { case BS: case DEL: diff --git a/samples/subsys/shell/shell_module/src/main.c b/samples/subsys/shell/shell_module/src/main.c index 31a93a1b8449..298643a77af9 100644 --- a/samples/subsys/shell/shell_module/src/main.c +++ b/samples/subsys/shell/shell_module/src/main.c @@ -140,7 +140,7 @@ static int cmd_demo_getopt_ts(const struct shell *sh, size_t argc, shell_print(sh, "Option -%c requires an argument.", state->optopt); - } else if (isprint(state->optopt)) { + } else if (isprint(state->optopt) != 0) { shell_print(sh, "Unknown option `-%c'.", state->optopt); @@ -190,7 +190,7 @@ static int cmd_demo_getopt(const struct shell *sh, size_t argc, shell_print(sh, "Option -%c requires an argument.", optopt); - } else if (isprint(optopt)) { + } else if (isprint(optopt) != 0) { shell_print(sh, "Unknown option `-%c'.", optopt); } else { diff --git a/subsys/logging/log_output.c b/subsys/logging/log_output.c index 2e32cc53f6e7..b92d553920be 100644 --- a/subsys/logging/log_output.c +++ b/subsys/logging/log_output.c @@ -397,7 +397,7 @@ static void hexdump_line_print(const struct log_output *output, unsigned char c = (unsigned char)data[i]; print_formatted(output, "%c", - isprint((int)c) ? c : '.'); + isprint((int)c) != 0 ? c : '.'); } else { print_formatted(output, " "); } diff --git a/subsys/shell/shell.c b/subsys/shell/shell.c index d36cfb45db5a..c66f617ac30a 100644 --- a/subsys/shell/shell.c +++ b/subsys/shell/shell.c @@ -1049,7 +1049,7 @@ static void state_collect(const struct shell *shell) break; default: - if (isprint((int) data)) { + if (isprint((int) data) != 0) { z_flag_history_exit_set(shell, true); z_shell_op_char_insert(shell, data); } else if (z_flag_echo_get(shell)) { @@ -1557,7 +1557,7 @@ void shell_hexdump_line(const struct shell *shell, unsigned int offset, char c = data[i]; shell_fprintf(shell, SHELL_NORMAL, "%c", - isprint((int)c) ? c : '.'); + isprint((int)c) != 0 ? c : '.'); } else { shell_fprintf(shell, SHELL_NORMAL, " "); } diff --git a/subsys/tracing/tracing_backend_uart.c b/subsys/tracing/tracing_backend_uart.c index cfc046927cd2..647f26abf08f 100644 --- a/subsys/tracing/tracing_backend_uart.c +++ b/subsys/tracing/tracing_backend_uart.c @@ -48,7 +48,7 @@ static void uart_isr(const struct device *dev, void *user_data) length = tracing_cmd_buffer_alloc(&cmd); } - if (!isprint(byte)) { + if (isprint(byte) == 0) { if (byte == '\r') { cmd[cur] = '\0'; tracing_cmd_handle(cmd, cur); diff --git a/tests/lib/c_lib/src/main.c b/tests/lib/c_lib/src/main.c index abe3f38d285d..0e747ef7b4d1 100644 --- a/tests/lib/c_lib/src/main.c +++ b/tests/lib/c_lib/src/main.c @@ -479,7 +479,7 @@ ZTEST(test_c_lib, test_checktype) ptr = buf; for (int i = 0; i < 128; i++) { - if (isprint(i)) { + if (isprint(i) != 0) { *ptr++ = i; } } From ed1cc603a79a9b27d5282c62b9e8fbdaf5315c3c Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 16 Mar 2023 15:01:13 +0100 Subject: [PATCH 0313/1906] Bluetooth: BAP: Fix bad ASSERT in ASCS disconn stream handler The conditions of the assert were incorrect compared to the text, and caused an assert to happen when it shouldn't. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/ascs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index c42a7e4337b6..21ced50f73c6 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -130,11 +130,9 @@ static void ascs_disconnect_stream_work_handler(struct k_work *work) struct bt_bap_stream *stream = ep->stream; struct bt_bap_stream *pair_stream; - __ASSERT(stream != NULL && - ep->iso != NULL && - ep->iso->chan.state != BT_ISO_STATE_CONNECTED, + __ASSERT(ep != NULL && ep->iso && stream != NULL, "Invalid endpoint %p, iso %p or stream %p", - ep, ep->iso, stream); + ep, ep == NULL ? NULL : ep->iso, stream); if (ep->dir == BT_AUDIO_DIR_SINK) { pair_stream = ep->iso->tx.stream; From cf737b510e3724274fbaad0a12d49fa9daa17832 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 16 Mar 2023 14:53:50 +0100 Subject: [PATCH 0314/1906] Bluetooth: BAP: Remove bad LOG_ERR from unicast client Remove a bad LOG_ERR that should never have been merged. Added the valuet that was logged to the debug log statement. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/bap_unicast_client.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index 1fe9d3d0d472..1b83f3802e3d 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -297,10 +297,8 @@ static void unicast_client_ep_iso_connected(struct bt_bap_ep *ep) return; } - LOG_DBG("stream %p ep %p dir %s", - stream, ep, bt_audio_dir_str(ep->dir)); - - LOG_ERR("ep->receiver_ready %u", ep->receiver_ready); + LOG_DBG("stream %p ep %p dir %s receiver_ready %u", + stream, ep, bt_audio_dir_str(ep->dir), ep->receiver_ready); if (ep->receiver_ready && ep->dir == BT_AUDIO_DIR_SOURCE) { const int err = unicast_client_send_start(ep); From 92507497147d0ff79732b5f6f029face510ecdd2 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 16 Mar 2023 14:05:06 +0100 Subject: [PATCH 0315/1906] nrf52_bsim: Add options to synchronize to the Phy before booting Some testcases may benefit from having options to synchronize to the Phy either before running the test pre-initialization and/or before booting the CPU. Provide these options. Background: Before synchronizing to the Phy devices execute ahead asynchronously. This is not a problem in most cases, as normally the only interaction between devices happens thru the radio, and as soon as any radio interaction occurs, the devices are step-locked by the Phy. But some devices do share information in other ways between, like for example using the backchannels. This may benefit from using these options. Signed-off-by: Alberto Escolar Piedras --- boards/posix/nrf52_bsim/argparse.c | 33 ++++++++++++++++++++++++++++++ boards/posix/nrf52_bsim/argparse.h | 2 ++ boards/posix/nrf52_bsim/main.c | 12 ++++++++--- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/boards/posix/nrf52_bsim/argparse.c b/boards/posix/nrf52_bsim/argparse.c index 4e3196dd0c84..0058109803c9 100644 --- a/boards/posix/nrf52_bsim/argparse.c +++ b/boards/posix/nrf52_bsim/argparse.c @@ -63,6 +63,16 @@ static void cmd_no_delay_init_found(char *argv, int offset) arg.delay_init = false; } +static void cmd_no_sync_preinit_found(char *argv, int offset) +{ + arg.sync_preinit = false; +} + +static void cmd_no_sync_preboot_found(char *argv, int offset) +{ + arg.sync_preboot = false; +} + static void save_test_arg(struct NRF_bsim_args_t *args, char *argv) { if (args->test_case_argc >= MAXPARAMS_TESTCASES) { @@ -116,6 +126,29 @@ void nrfbsim_register_args(void) (void *)&nosim, cmd_nosim_found, "(debug feature) Do not connect to the phy"}, { false, false, true, + "sync_preinit", "", 'b', + (void *)&arg.sync_preinit, NULL, + "Postpone pre-initialization and boot " + "until the phy has reached time 0 (or start_offset) (by default not set)" + }, + { false, false, true, + "no_sync_preinit", "", 'b', + NULL, cmd_no_sync_preinit_found, + "Clear sync_preinit. Note that by default sync_preinit is not set" + }, + { false, false, true, + "sync_preboot", "", 'b', + (void *)&arg.sync_preboot, NULL, + "Postpone CPU boot " + "until the phy has reached time 0 (or start_offset) (by default not set)" + "If sync_preinit is set, this option has no effect." + }, + { false, false, true, + "no_sync_preboot", "", 'b', + NULL, cmd_no_sync_preboot_found, + "Clear sync_preboot. Note that by default sync_preboot is not set" + }, + { false, false, true, "delay_init", "", 'b', (void *)&arg.delay_init, NULL, "If start_offset is used, postpone initialization and startup " diff --git a/boards/posix/nrf52_bsim/argparse.h b/boards/posix/nrf52_bsim/argparse.h index d13e440499ba..e46bb035eb99 100644 --- a/boards/posix/nrf52_bsim/argparse.h +++ b/boards/posix/nrf52_bsim/argparse.h @@ -22,6 +22,8 @@ struct NRF_bsim_args_t { char *test_case_argv[MAXPARAMS_TESTCASES]; int test_case_argc; bool delay_init; + bool sync_preinit; + bool sync_preboot; nrf_hw_sub_args_t nrf_hw; }; diff --git a/boards/posix/nrf52_bsim/main.c b/boards/posix/nrf52_bsim/main.c index 38e92f668de6..13f86b416bc9 100644 --- a/boards/posix/nrf52_bsim/main.c +++ b/boards/posix/nrf52_bsim/main.c @@ -96,11 +96,13 @@ int main(int argc, char *argv[]) /* We pass to a possible testcase its command line arguments */ bst_pass_args(args->test_case_argc, args->test_case_argv); - if ((args->nrf_hw.start_offset > 0) && (args->delay_init)) { + if (((args->nrf_hw.start_offset > 0) && (args->delay_init)) + || args->sync_preinit) { /* Delay the next steps until the simulation time has - * reached start_offset + * reached either time 0 or start_offset. */ - hwll_wait_for_phy_simu_time(args->nrf_hw.start_offset); + hwll_wait_for_phy_simu_time(BS_MAX(args->nrf_hw.start_offset, 0)); + args->sync_preboot = false; /* Already sync'ed */ } nrf_hw_initialize(&args->nrf_hw); @@ -109,6 +111,10 @@ int main(int argc, char *argv[]) bst_pre_init(); + if (args->sync_preboot) { + hwll_wait_for_phy_simu_time(BS_MAX(args->nrf_hw.start_offset, 0)); + } + posix_boot_cpu(); run_native_tasks(_NATIVE_FIRST_SLEEP_LEVEL); From 2ca438fc554991cc48cbe331fd2fb3a93e580b35 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 16 Mar 2023 14:09:17 +0100 Subject: [PATCH 0316/1906] tests/bluetooth/mesh: Synchronize devices before boot To ensure no indeterminism, synchronize devices before they boot, and therefore before the test main function is executed. Note that at this point, there is no actual indeterminism to correct. Signed-off-by: Alberto Escolar Piedras --- tests/bluetooth/bsim/mesh/_mesh_test.sh | 2 +- .../bluetooth/bsim/mesh/src/test_provision.c | 44 ++++++++++--------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/tests/bluetooth/bsim/mesh/_mesh_test.sh b/tests/bluetooth/bsim/mesh/_mesh_test.sh index 811c8fe9b567..bd303163428e 100755 --- a/tests/bluetooth/bsim/mesh/_mesh_test.sh +++ b/tests/bluetooth/bsim/mesh/_mesh_test.sh @@ -75,7 +75,7 @@ function RunTest(){ Execute \ ${exe_name} \ - -v=${verbosity_level} -s=$s_id -d=$idx -RealEncryption=1 \ + -v=${verbosity_level} -s=$s_id -d=$idx -sync_preboot -RealEncryption=1 \ -testid=$testid ${test_options} let idx=idx+1 done diff --git a/tests/bluetooth/bsim/mesh/src/test_provision.c b/tests/bluetooth/bsim/mesh/src/test_provision.c index 336d18739593..2431fde9993d 100644 --- a/tests/bluetooth/bsim/mesh/src/test_provision.c +++ b/tests/bluetooth/bsim/mesh/src/test_provision.c @@ -327,16 +327,8 @@ static void oob_auth_set(int test_step) static void oob_device(bool use_oob_pk) { - int err = 0; - k_sem_init(&prov_sem, 0, 1); - oob_channel_id = bs_open_back_channel(get_device_nbr(), - (uint[]){(get_device_nbr() + 1) % 2}, (uint[]){0}, 1); - if (!oob_channel_id) { - FAIL("Can't open OOB interface (err %d)\n", err); - } - bt_mesh_device_setup(&prov, &comp); if (use_oob_pk) { @@ -366,16 +358,8 @@ static void oob_device(bool use_oob_pk) static void oob_provisioner(bool read_oob_pk, bool use_oob_pk) { - int err = 0; - k_sem_init(&prov_sem, 0, 1); - oob_channel_id = bs_open_back_channel(get_device_nbr(), - (uint[]){(get_device_nbr() + 1) % 2}, (uint[]){0}, 1); - if (!oob_channel_id) { - FAIL("Can't open OOB interface (err %d)\n", err); - } - bt_mesh_device_setup(&prov, &comp); if (read_oob_pk) { @@ -549,6 +533,15 @@ static void test_provisioner_pb_adv_oob_auth(void) PASS(); } +static void test_back_channel_pre_init(void) +{ + oob_channel_id = bs_open_back_channel(get_device_nbr(), + (uint[]){(get_device_nbr() + 1) % 2}, (uint[]){0}, 1); + if (!oob_channel_id) { + FAIL("Can't open OOB interface\n"); + } +} + static void test_device_pb_adv_oob_public_key(void) { oob_device(true); @@ -1196,13 +1189,22 @@ static void test_device_pb_remote_server_ncrp_second_time(void) .test_main_f = test_##role##_##name, \ .test_delete_f = test_terminate \ } +#define TEST_CASE_WBACKCHANNEL(role, name, description) \ + { \ + .test_id = "prov_" #role "_" #name, .test_descr = description, \ + .test_post_init_f = test_##role##_init, \ + .test_pre_init_f = test_back_channel_pre_init, \ + .test_tick_f = bt_mesh_test_timeout, \ + .test_main_f = test_##role##_##name, \ + .test_delete_f = test_terminate \ + } static const struct bst_test_instance test_connect[] = { TEST_CASE(device, pb_adv_no_oob, "Device: pb-adv provisioning use no-oob method"), - TEST_CASE(device, pb_adv_oob_auth, + TEST_CASE_WBACKCHANNEL(device, pb_adv_oob_auth, "Device: pb-adv provisioning use oob authentication"), - TEST_CASE(device, pb_adv_oob_public_key, + TEST_CASE_WBACKCHANNEL(device, pb_adv_oob_public_key, "Device: pb-adv provisioning use oob public key"), TEST_CASE(device, pb_adv_reprovision, "Device: pb-adv provisioning, reprovision"), @@ -1221,11 +1223,11 @@ static const struct bst_test_instance test_connect[] = { "Provisioner: effect on ivu_duration when IV Update flag is set to zero"), TEST_CASE(provisioner, iv_update_flag_one, "Provisioner: effect on ivu_duration when IV Update flag is set to one"), - TEST_CASE(provisioner, pb_adv_oob_auth, + TEST_CASE_WBACKCHANNEL(provisioner, pb_adv_oob_auth, "Provisioner: pb-adv provisioning use oob authentication"), - TEST_CASE(provisioner, pb_adv_oob_public_key, + TEST_CASE_WBACKCHANNEL(provisioner, pb_adv_oob_public_key, "Provisioner: pb-adv provisioning use oob public key"), - TEST_CASE(provisioner, pb_adv_oob_auth_no_oob_public_key, + TEST_CASE_WBACKCHANNEL(provisioner, pb_adv_oob_auth_no_oob_public_key, "Provisioner: pb-adv provisioning use oob authentication, ignore oob public key"), TEST_CASE(provisioner, pb_adv_reprovision, "Provisioner: pb-adv provisioning, resetting and reprovisioning multiple times."), From 38095f881883952e772c7f7d147efa770232d628 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 16 Mar 2023 14:08:05 +0100 Subject: [PATCH 0317/1906] Bluetooth: BAP: Shell: Delete uni group when all streams released Previously we assumed only a single stream, and deleted the unicast group on the first stream released. Now we wait for all the streams to be released before deleting the group. This still assumes that all streams are initiated by us as the client, and will not work if using the BAP unicast client and server role concurrently. Signed-off-by: Emil Gydesen --- subsys/bluetooth/shell/bap.c | 38 +++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/subsys/bluetooth/shell/bap.c b/subsys/bluetooth/shell/bap.c index 2e45b31e09bf..6da04ec48be3 100644 --- a/subsys/bluetooth/shell/bap.c +++ b/subsys/bluetooth/shell/bap.c @@ -1784,19 +1784,35 @@ static void stream_released_cb(struct bt_bap_stream *stream) shell_print(ctx_shell, "Stream %p released\n", stream); #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) - /* The current shell application only supports a single stream in - * the unicast group, so when that gets disconnected, we delete the - * unicast group so that it can be recreated when settings the QoS - */ if (default_unicast_group != NULL) { - int err = bt_bap_unicast_group_delete(default_unicast_group); + bool group_can_be_deleted = true; - if (err != 0) { - shell_error(ctx_shell, - "Failed to delete unicast group: %d", - err); - } else { - default_unicast_group = NULL; + for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) { + if (unicast_streams[i].stream.ep != NULL) { + struct bt_bap_ep_info ep_info; + + bt_bap_ep_get_info(unicast_streams[i].stream.ep, &ep_info); + + if (ep_info.state != BT_BAP_EP_STATE_CODEC_CONFIGURED && + ep_info.state != BT_BAP_EP_STATE_IDLE) { + group_can_be_deleted = false; + break; + } + } + } + + if (group_can_be_deleted) { + int err; + + shell_print(ctx_shell, "All streams released, deleting group\n"); + + err = bt_bap_unicast_group_delete(default_unicast_group); + + if (err != 0) { + shell_error(ctx_shell, "Failed to delete unicast group: %d", err); + } else { + default_unicast_group = NULL; + } } } #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ From bb43c05dc88f4378f753ec2580c118dc043e8c50 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 16 Mar 2023 14:03:11 +0100 Subject: [PATCH 0318/1906] Bluetooth: ISO: Set missing CIS disconnecting state The BT_ISO_STATE_DISCONNECTING was never set when the CIS was actually in the disconnecting state. Signed-off-by: Emil Gydesen --- subsys/bluetooth/host/iso.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/host/iso.c b/subsys/bluetooth/host/iso.c index 9687daf452b1..8a72ae9e8706 100644 --- a/subsys/bluetooth/host/iso.c +++ b/subsys/bluetooth/host/iso.c @@ -886,6 +886,8 @@ int bt_iso_chan_get_tx_sync(const struct bt_iso_chan *chan, struct bt_iso_tx_inf #if defined(CONFIG_BT_ISO_UNICAST) int bt_iso_chan_disconnect(struct bt_iso_chan *chan) { + int err; + CHECKIF(!chan) { LOG_DBG("Invalid parameter: chan %p", chan); return -EINVAL; @@ -920,7 +922,12 @@ int bt_iso_chan_disconnect(struct bt_iso_chan *chan) return -EALREADY; } - return bt_conn_disconnect(chan->iso, BT_HCI_ERR_REMOTE_USER_TERM_CONN); + err = bt_conn_disconnect(chan->iso, BT_HCI_ERR_REMOTE_USER_TERM_CONN); + if (err == 0) { + bt_iso_chan_set_state(chan, BT_ISO_STATE_DISCONNECTING); + } + + return err; } void bt_iso_cleanup_acl(struct bt_conn *iso) From 64143fc8815376c6b6974a7208bea9b1ce029b27 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 16 Mar 2023 14:04:16 +0100 Subject: [PATCH 0319/1906] Bluetooth: BAP: unicast released callback only after CIS disconnect Ensure that the stream released callback is only called after the CIS has disconnected. Since the ACL disconnect event may come before the CIS disconnect event, we use the unicast_client_ep_idle_state in the unicast_client_reset function to use the existing state verification, and only after both the ACL and CIS has disconnected, we finalize the reset of the stream and call the released callback, assuming that the CIS can be disconnected. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/bap_unicast_client.c | 59 ++++++++++++++------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index 1b83f3802e3d..aed239539282 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -97,6 +97,8 @@ static int unicast_client_ep_set_codec(struct bt_bap_ep *ep, uint8_t id, uint16_ static int unicast_client_ep_start(struct bt_bap_ep *ep, struct net_buf_simple *buf); +static void unicast_client_reset(struct bt_bap_ep *ep); + static int unicast_client_send_start(struct bt_bap_ep *ep) { if (ep->receiver_ready != true || ep->dir != BT_AUDIO_DIR_SOURCE) { @@ -133,7 +135,7 @@ static int unicast_client_send_start(struct bt_bap_ep *ep) return 0; } -static void unicast_client_ep_idle_state(struct bt_bap_ep *ep); +static int unicast_client_ep_idle_state(struct bt_bap_ep *ep); /** Checks if the stream can terminate the CIS * @@ -347,7 +349,21 @@ static void unicast_client_ep_iso_disconnected(struct bt_bap_ep *ep, uint8_t rea * the ISO has finalized the disconnection */ if (ep->status.state == BT_BAP_EP_STATE_IDLE) { - unicast_client_ep_idle_state(ep); + + (void)unicast_client_ep_idle_state(ep); + + if (stream->conn != NULL) { + struct bt_conn_info conn_info; + int err; + + err = bt_conn_get_info(stream->conn, &conn_info); + if (err != 0 || conn_info.state == BT_CONN_STATE_DISCONNECTED) { + /* Retrigger the reset of the EP if the ACL is disconnected before + * the ISO is disconnected + */ + unicast_client_reset(ep); + } + } } else { if (stream->ops != NULL && stream->ops->stopped != NULL) { stream->ops->stopped(stream, reason); @@ -513,7 +529,7 @@ static struct bt_bap_ep *unicast_client_ep_get(struct bt_conn *conn, enum bt_aud return unicast_client_ep_new(conn, dir, handle); } -static void unicast_client_ep_idle_state(struct bt_bap_ep *ep) +static int unicast_client_ep_idle_state(struct bt_bap_ep *ep) { struct bt_bap_unicast_client_ep *client_ep = CONTAINER_OF(ep, struct bt_bap_unicast_client_ep, ep); @@ -521,21 +537,24 @@ static void unicast_client_ep_idle_state(struct bt_bap_ep *ep) const struct bt_bap_stream_ops *ops; if (stream == NULL) { - return; + return -EINVAL; } /* If CIS is connected, disconnect and wait for CIS disconnection */ if (unicast_client_can_disconnect_stream(stream)) { - const int err = bt_bap_stream_disconnect(stream); + int err; + + LOG_DBG("Disconnecting stream"); + err = bt_bap_stream_disconnect(stream); if (err != 0) { LOG_ERR("Failed to disconnect stream: %d", err); - } else { - return; } + + return err; } else if (ep->iso != NULL && ep->iso->chan.state == BT_ISO_STATE_DISCONNECTING) { /* Wait */ - return; + return -EBUSY; } bt_bap_stream_reset(stream); @@ -560,6 +579,8 @@ static void unicast_client_ep_idle_state(struct bt_bap_ep *ep) } else { LOG_WRN("No callback for released set"); } + + return 0; } static void unicast_client_ep_qos_update(struct bt_bap_ep *ep, @@ -910,7 +931,7 @@ static void unicast_client_ep_set_status(struct bt_bap_ep *ep, struct net_buf_si switch (status->state) { case BT_BAP_EP_STATE_IDLE: - unicast_client_ep_idle_state(ep); + (void)unicast_client_ep_idle_state(ep); break; case BT_BAP_EP_STATE_CODEC_CONFIGURED: switch (old_state) { @@ -1751,24 +1772,22 @@ static void unicast_client_reset(struct bt_bap_ep *ep) { struct bt_bap_unicast_client_ep *client_ep = CONTAINER_OF(ep, struct bt_bap_unicast_client_ep, ep); - struct bt_bap_stream *stream = ep->stream; + int err; LOG_DBG("ep %p", ep); - if (stream != NULL && ep->status.state != BT_BAP_EP_STATE_IDLE) { - const struct bt_bap_stream_ops *ops; + /* Pretend we received an idle state notification from the server to trigger all cleanup */ + ep->status.state = BT_BAP_EP_STATE_IDLE; + err = unicast_client_ep_idle_state(ep); + if (err != 0) { + LOG_DBG("unicast_client_ep_idle_state returned %d", err); - /* Notify upper layer */ - ops = stream->ops; - if (ops != NULL && ops->released != NULL) { - ops->released(stream); - } else { - LOG_WRN("No callback for released set"); + if (err == -EBUSY) { + /* Wait for ISO disconnected event */ + return; } } - bt_bap_stream_reset(stream); - (void)memset(ep, 0, sizeof(*ep)); client_ep->cp_handle = 0U; From ba7656d05f490b28ea1f95e4cb0714d200b948d5 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 8 Mar 2023 14:48:13 +0100 Subject: [PATCH 0320/1906] tests: Bluetooth: Audio: Streamline connection handling in tests Modify the tests to only have a single set of connection callbacks, where all the tests can use the same default_conn and flag_connected. Signed-off-by: Emil Gydesen --- .../audio/src/bap_broadcast_assistant_test.c | 42 ++++--------------- .../bsim/audio/src/bap_scan_delegator_test.c | 26 +----------- .../bsim/audio/src/bap_unicast_client_test.c | 24 ----------- .../bsim/audio/src/bap_unicast_server_test.c | 21 ---------- .../bsim/audio/src/cap_acceptor_test.c | 22 ---------- .../bsim/audio/src/cap_initiator_test.c | 24 ----------- tests/bluetooth/bsim/audio/src/common.c | 29 +++++++++++++ tests/bluetooth/bsim/audio/src/common.h | 1 + .../audio/src/csip_set_coordinator_test.c | 33 ++------------- .../bsim/audio/src/csip_set_member_test.c | 15 ------- .../bsim/audio/src/has_client_test.c | 26 +----------- .../bsim/audio/src/ias_client_test.c | 33 +++------------ tests/bluetooth/bsim/audio/src/ias_test.c | 26 +----------- tests/bluetooth/bsim/audio/src/mcc_test.c | 28 +------------ tests/bluetooth/bsim/audio/src/mcs_test.c | 26 +----------- .../bsim/audio/src/media_controller_test.c | 37 ++-------------- .../bsim/audio/src/micp_mic_ctlr_test.c | 25 +---------- .../bsim/audio/src/micp_mic_dev_test.c | 24 +---------- .../bsim/audio/src/tbs_client_test.c | 26 +----------- tests/bluetooth/bsim/audio/src/tbs_test.c | 26 +----------- .../bsim/audio/src/vcp_vol_ctlr_test.c | 24 +---------- .../bsim/audio/src/vcp_vol_rend_test.c | 23 +--------- 22 files changed, 61 insertions(+), 500 deletions(-) diff --git a/tests/bluetooth/bsim/audio/src/bap_broadcast_assistant_test.c b/tests/bluetooth/bsim/audio/src/bap_broadcast_assistant_test.c index 4552ee82d5e0..8a1c2d46436a 100644 --- a/tests/bluetooth/bsim/audio/src/bap_broadcast_assistant_test.c +++ b/tests/bluetooth/bsim/audio/src/bap_broadcast_assistant_test.c @@ -12,11 +12,9 @@ #include "../../../../../subsys/bluetooth/host/hci_core.h" #include "common.h" -static struct bt_conn_cb conn_callbacks; extern enum bst_result_t bst_result; /* BASS variables */ -static volatile bool g_is_connected; static volatile bool g_mtu_exchanged; static volatile bool g_discovery_complete; static volatile bool g_write_complete; @@ -28,7 +26,6 @@ static volatile uint8_t g_src_id; static volatile uint32_t g_broadcast_id; static volatile bool g_cb; -static struct bt_conn *g_conn; /* Broadcaster variables */ static bt_addr_le_t g_broadcaster_addr; @@ -227,27 +224,6 @@ static struct bt_bap_broadcast_assistant_cb broadcast_assistant_cbs = { .rem_src = bap_broadcast_assistant_rem_src_cb, }; -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - g_conn = conn; - g_is_connected = true; -} - -static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, -}; - static void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx) { g_mtu_exchanged = true; @@ -301,7 +277,7 @@ static void test_bass_discover(void) int err; printk("Discovering BASS\n"); - err = bt_bap_broadcast_assistant_discover(g_conn); + err = bt_bap_broadcast_assistant_discover(default_conn); if (err != 0) { FAIL("Failed to discover BASS %d\n", err); return; @@ -317,7 +293,7 @@ static void test_bass_scan_start(void) printk("Starting scan\n"); g_write_complete = false; - err = bt_bap_broadcast_assistant_scan_start(g_conn, true); + err = bt_bap_broadcast_assistant_scan_start(default_conn, true); if (err != 0) { FAIL("Could not write scan start to BASS (err %d)\n", err); return; @@ -333,7 +309,7 @@ static void test_bass_scan_stop(void) printk("Stopping scan\n"); g_write_complete = false; - err = bt_bap_broadcast_assistant_scan_stop(g_conn); + err = bt_bap_broadcast_assistant_scan_stop(default_conn); if (err != 0) { FAIL("Could not write scan stop to BASS (err %d)\n", err); return; @@ -379,7 +355,7 @@ static void test_bass_add_source(void) add_src_param.subgroups = &subgroup; subgroup.bis_sync = 0; subgroup.metadata_len = 0; - err = bt_bap_broadcast_assistant_add_src(g_conn, &add_src_param); + err = bt_bap_broadcast_assistant_add_src(default_conn, &add_src_param); if (err != 0) { FAIL("Could not add source (err %d)\n", err); return; @@ -404,7 +380,7 @@ static void test_bass_mod_source(void) mod_src_param.pa_interval = g_broadcaster_info.interval; subgroup.bis_sync = 0; subgroup.metadata_len = 0; - err = bt_bap_broadcast_assistant_mod_src(g_conn, &mod_src_param); + err = bt_bap_broadcast_assistant_mod_src(default_conn, &mod_src_param); if (err != 0) { FAIL("Could not modify source (err %d)\n", err); return; @@ -427,8 +403,7 @@ static void test_bass_broadcast_code(void) printk("Adding broadcast code\n"); g_write_complete = false; - err = bt_bap_broadcast_assistant_set_broadcast_code(g_conn, g_src_id, - broadcast_code); + err = bt_bap_broadcast_assistant_set_broadcast_code(default_conn, g_src_id, broadcast_code); if (err != 0) { FAIL("Could not add broadcast code (err %d)\n", err); return; @@ -444,7 +419,7 @@ static void test_bass_remove_source(void) printk("Removing source\n"); g_cb = g_write_complete = false; - err = bt_bap_broadcast_assistant_rem_src(g_conn, g_src_id); + err = bt_bap_broadcast_assistant_rem_src(default_conn, g_src_id); if (err != 0) { FAIL("Could not remove source (err %d)\n", err); return; @@ -464,7 +439,6 @@ static void test_main(void) return; } - bt_conn_cb_register(&conn_callbacks); bt_gatt_cb_register(&gatt_callbacks); bt_bap_broadcast_assistant_register_cb(&broadcast_assistant_cbs); bt_le_per_adv_sync_cb_register(&sync_callbacks); @@ -478,7 +452,7 @@ static void test_main(void) printk("Scanning successfully started\n"); - WAIT_FOR_COND(g_is_connected); + WAIT_FOR_FLAG(flag_connected); test_exchange_mtu(); test_bass_discover(); diff --git a/tests/bluetooth/bsim/audio/src/bap_scan_delegator_test.c b/tests/bluetooth/bsim/audio/src/bap_scan_delegator_test.c index aecdf0a0f0eb..250243cc493d 100644 --- a/tests/bluetooth/bsim/audio/src/bap_scan_delegator_test.c +++ b/tests/bluetooth/bsim/audio/src/bap_scan_delegator_test.c @@ -12,8 +12,6 @@ extern enum bst_result_t bst_result; static volatile bool g_cb; static volatile bool g_pa_synced; -static struct bt_conn *g_conn; -static bool g_connected; static void pa_synced(struct bt_bap_scan_delegator_recv_state *recv_state, const struct bt_le_per_adv_sync_synced_info *info) @@ -42,27 +40,6 @@ static struct bt_bap_scan_delegator_cb scan_delegator_cb = { .pa_recv = pa_recv }; -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - g_conn = conn; - g_connected = true; -} - -static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, -}; - static void test_main(void) { int err; @@ -76,7 +53,6 @@ static void test_main(void) printk("Bluetooth initialized\n"); bt_bap_scan_delegator_register_cb(&scan_delegator_cb); - bt_conn_cb_register(&conn_callbacks); err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, AD_SIZE, NULL, 0); if (err) { @@ -86,7 +62,7 @@ static void test_main(void) printk("Advertising successfully started\n"); - WAIT_FOR_COND(g_connected); + WAIT_FOR_FLAG(flag_connected); WAIT_FOR_COND(g_pa_synced); diff --git a/tests/bluetooth/bsim/audio/src/bap_unicast_client_test.c b/tests/bluetooth/bsim/audio/src/bap_unicast_client_test.c index bd921f702e0e..8a2c330cf9af 100644 --- a/tests/bluetooth/bsim/audio/src/bap_unicast_client_test.c +++ b/tests/bluetooth/bsim/audio/src/bap_unicast_client_test.c @@ -23,7 +23,6 @@ static struct bt_bap_ep *g_sinks[CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT]; static struct bt_bap_lc3_preset preset_16_2_1 = BT_BAP_LC3_UNICAST_PRESET_16_2_1( BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); -CREATE_FLAG(flag_connected); CREATE_FLAG(flag_mtu_exchanged); CREATE_FLAG(flag_sink_discovered); CREATE_FLAG(flag_stream_codec_configured); @@ -260,29 +259,6 @@ static void discover_sink_cb(struct bt_conn *conn, struct bt_codec *codec, struc } } -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - (void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - bt_conn_unref(default_conn); - default_conn = NULL; - - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - SET_FLAG(flag_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - static void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx) { printk("MTU exchanged\n"); diff --git a/tests/bluetooth/bsim/audio/src/bap_unicast_server_test.c b/tests/bluetooth/bsim/audio/src/bap_unicast_server_test.c index 650442c8b717..ad2cb6a49bd0 100644 --- a/tests/bluetooth/bsim/audio/src/bap_unicast_server_test.c +++ b/tests/bluetooth/bsim/audio/src/bap_unicast_server_test.c @@ -32,7 +32,6 @@ static const struct bt_data unicast_server_ad[] = { BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_ASCS_VAL)), }; -CREATE_FLAG(flag_connected); CREATE_FLAG(flag_stream_configured); static void print_ase_info(struct bt_bap_ep *ep, void *user_data) @@ -245,26 +244,6 @@ static struct bt_bap_stream_ops stream_ops = { .recv = stream_recv }; -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - SET_FLAG(flag_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - static void init(void) { static struct bt_pacs_cap cap = { diff --git a/tests/bluetooth/bsim/audio/src/cap_acceptor_test.c b/tests/bluetooth/bsim/audio/src/cap_acceptor_test.c index 71e48fac6e25..90c18abd620c 100644 --- a/tests/bluetooth/bsim/audio/src/cap_acceptor_test.c +++ b/tests/bluetooth/bsim/audio/src/cap_acceptor_test.c @@ -193,28 +193,6 @@ static const struct bt_data cap_acceptor_ad[] = { static struct bt_csip_set_member_svc_inst *csip_set_member; -CREATE_FLAG(flag_connected); - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - SET_FLAG(flag_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - static void init(void) { struct bt_csip_set_member_register_param csip_set_member_param = { diff --git a/tests/bluetooth/bsim/audio/src/cap_initiator_test.c b/tests/bluetooth/bsim/audio/src/cap_initiator_test.c index 5d6c0384f6b9..46d465e27001 100644 --- a/tests/bluetooth/bsim/audio/src/cap_initiator_test.c +++ b/tests/bluetooth/bsim/audio/src/cap_initiator_test.c @@ -36,7 +36,6 @@ static struct bt_bap_lc3_preset broadcast_preset_16_2_1 = BT_BAP_LC3_BROADCAST_P static K_SEM_DEFINE(sem_broadcast_started, 0U, ARRAY_SIZE(broadcast_streams)); static K_SEM_DEFINE(sem_broadcast_stopped, 0U, ARRAY_SIZE(broadcast_streams)); -CREATE_FLAG(flag_connected); CREATE_FLAG(flag_discovered); CREATE_FLAG(flag_mtu_exchanged); CREATE_FLAG(flag_broadcast_stopping); @@ -129,29 +128,6 @@ static struct bt_cap_initiator_cb cap_cb = { .unicast_discovery_complete = cap_discovery_complete_cb }; -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - (void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - bt_conn_unref(default_conn); - default_conn = NULL; - - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - SET_FLAG(flag_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - static void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx) { printk("MTU exchanged\n"); diff --git a/tests/bluetooth/bsim/audio/src/common.c b/tests/bluetooth/bsim/audio/src/common.c index 9111010b3d05..d9ae4a4d34b6 100644 --- a/tests/bluetooth/bsim/audio/src/common.c +++ b/tests/bluetooth/bsim/audio/src/common.c @@ -9,6 +9,7 @@ extern enum bst_result_t bst_result; struct bt_conn *default_conn; +atomic_t flag_connected; const struct bt_data ad[AD_SIZE] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)) @@ -51,6 +52,28 @@ void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, } } +static void connected(struct bt_conn *conn, uint8_t err) +{ + char addr[BT_ADDR_LE_STR_LEN]; + + (void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + + if (default_conn == NULL) { + default_conn = bt_conn_ref(conn); + } + + if (err != 0) { + bt_conn_unref(default_conn); + default_conn = NULL; + + FAIL("Failed to connect to %s (%u)\n", addr, err); + return; + } + + printk("Connected to %s\n", addr); + SET_FLAG(flag_connected); +} + void disconnected(struct bt_conn *conn, uint8_t reason) { char addr[BT_ADDR_LE_STR_LEN]; @@ -65,8 +88,14 @@ void disconnected(struct bt_conn *conn, uint8_t reason) bt_conn_unref(default_conn); default_conn = NULL; + UNSET_FLAG(flag_connected); } +BT_CONN_CB_DEFINE(conn_callbacks) = { + .connected = connected, + .disconnected = disconnected, +}; + void test_tick(bs_time_t HW_device_time) { if (bst_result != Passed) { diff --git a/tests/bluetooth/bsim/audio/src/common.h b/tests/bluetooth/bsim/audio/src/common.h index b8bf8ccba405..4c16113ea13d 100644 --- a/tests/bluetooth/bsim/audio/src/common.h +++ b/tests/bluetooth/bsim/audio/src/common.h @@ -57,6 +57,7 @@ #define AD_SIZE 1 extern const struct bt_data ad[AD_SIZE]; extern struct bt_conn *default_conn; +extern atomic_t flag_connected; void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, struct net_buf_simple *ad); diff --git a/tests/bluetooth/bsim/audio/src/csip_set_coordinator_test.c b/tests/bluetooth/bsim/audio/src/csip_set_coordinator_test.c index 467a53a71236..8a799162ff1f 100644 --- a/tests/bluetooth/bsim/audio/src/csip_set_coordinator_test.c +++ b/tests/bluetooth/bsim/audio/src/csip_set_coordinator_test.c @@ -10,7 +10,6 @@ #include "common.h" extern enum bst_result_t bst_result; -static volatile bool is_connected; static volatile bool discovered; static volatile bool members_discovered; static volatile bool set_locked; @@ -92,31 +91,6 @@ static void csip_set_coordinator_ordered_access_cb( } } -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (is_connected) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - bt_conn_unref(default_conn); - default_conn = NULL; - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - is_connected = true; -} - -static struct bt_conn_cb conn_callbacks = { - .connected = connected, -}; - static struct bt_csip_set_coordinator_cb cbs = { .lock_set = csip_set_coordinator_lock_set_cb, .release_set = csip_set_coordinator_lock_release_cb, @@ -245,7 +219,6 @@ static void test_main(void) printk("Audio Client: Bluetooth initialized\n"); - bt_conn_cb_register(&conn_callbacks); bt_csip_set_coordinator_register_cb(&cbs); k_work_init_delayable(&discover_members_timer, discover_members_timer_handler); @@ -277,7 +250,7 @@ static void test_main(void) } printk("Connecting to %s\n", addr); - WAIT_FOR_COND(is_connected); + WAIT_FOR_FLAG(flag_connected); connected_member_count++; err = bt_csip_set_coordinator_discover(conns[0]); @@ -314,7 +287,7 @@ static void test_main(void) for (uint8_t i = 1; i < members_found; i++) { bt_addr_le_to_str(&addr_found[i], addr, sizeof(addr)); - is_connected = false; + UNSET_FLAG(flag_connected); printk("Connecting to member[%d] (%s)", i, addr); err = bt_conn_le_create(&addr_found[i], BT_CONN_LE_CREATE_CONN, @@ -326,7 +299,7 @@ static void test_main(void) } printk("Connected to %s\n", addr); - WAIT_FOR_COND(is_connected); + WAIT_FOR_FLAG(flag_connected); connected_member_count++; discovered = false; diff --git a/tests/bluetooth/bsim/audio/src/csip_set_member_test.c b/tests/bluetooth/bsim/audio/src/csip_set_member_test.c index 5321744ac7f5..1c0d6373cc83 100644 --- a/tests/bluetooth/bsim/audio/src/csip_set_member_test.c +++ b/tests/bluetooth/bsim/audio/src/csip_set_member_test.c @@ -10,7 +10,6 @@ #include "common.h" static struct bt_csip_set_member_svc_inst *svc_inst; -static struct bt_conn_cb conn_callbacks; extern enum bst_result_t bst_result; static volatile bool g_locked; static uint8_t sirk_read_req_rsp = BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT; @@ -23,19 +22,6 @@ struct bt_csip_set_member_register_param param = { 0x22, 0xfd, 0xa1, 0x21, 0x09, 0x7d, 0x7d, 0x45 }, }; -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - printk("Connected\n"); -} - static void csip_disconnected(struct bt_conn *conn, uint8_t reason) { printk("Disconnected (reason %u)\n", reason); @@ -102,7 +88,6 @@ static void bt_ready(int err) } static struct bt_conn_cb conn_callbacks = { - .connected = connected, .disconnected = csip_disconnected, }; diff --git a/tests/bluetooth/bsim/audio/src/has_client_test.c b/tests/bluetooth/bsim/audio/src/has_client_test.c index 32a7c0575c04..9d63463e0ce2 100644 --- a/tests/bluetooth/bsim/audio/src/has_client_test.c +++ b/tests/bluetooth/bsim/audio/src/has_client_test.c @@ -17,13 +17,11 @@ extern const uint8_t test_preset_index_1; extern const uint8_t test_preset_index_5; extern const enum bt_has_properties test_preset_properties; -CREATE_FLAG(g_is_connected); CREATE_FLAG(g_service_discovered); CREATE_FLAG(g_preset_switched); CREATE_FLAG(g_preset_1_found); CREATE_FLAG(g_preset_5_found); -static struct bt_conn *g_conn; static struct bt_has *g_has; static uint8_t g_active_index; @@ -90,26 +88,6 @@ static const struct bt_has_client_cb has_cb = { .preset_read_rsp = preset_read_rsp_cb, }; -static void connected(struct bt_conn *conn, uint8_t err) -{ - if (err > 0) { - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - FAIL("Failed to connect to %s (err %u)\n", addr, err); - return; - } - - g_conn = conn; - SET_FLAG(g_is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - static bool test_preset_switch(uint8_t index) { int err; @@ -187,9 +165,9 @@ static void test_main(void) printk("Scanning successfully started\n"); - WAIT_FOR_COND(g_is_connected); + WAIT_FOR_FLAG(flag_connected); - err = bt_has_client_discover(g_conn); + err = bt_has_client_discover(default_conn); if (err < 0) { FAIL("Failed to discover HAS (err %d)\n", err); return; diff --git a/tests/bluetooth/bsim/audio/src/ias_client_test.c b/tests/bluetooth/bsim/audio/src/ias_client_test.c index f7c1c19826c8..2c5dbd40bd0a 100644 --- a/tests/bluetooth/bsim/audio/src/ias_client_test.c +++ b/tests/bluetooth/bsim/audio/src/ias_client_test.c @@ -12,11 +12,8 @@ extern enum bst_result_t bst_result; -CREATE_FLAG(g_is_connected); CREATE_FLAG(g_service_discovered); -static struct bt_conn *g_conn; - static void discover_cb(struct bt_conn *conn, int err) { if (err) { @@ -32,21 +29,6 @@ static const struct bt_ias_client_cb ias_client_cb = { .discover = discover_cb, }; -static void connected(struct bt_conn *conn, uint8_t err) -{ - if (err > 0) { - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - FAIL("Failed to connect to %s (err %u)\n", addr, err); - return; - } - - g_conn = conn; - SET_FLAG(g_is_connected); -} - static void test_alert_high(struct bt_conn *conn) { int err; @@ -83,11 +65,6 @@ static void test_alert_stop(struct bt_conn *conn) } } -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - static void test_main(void) { int err; @@ -114,9 +91,9 @@ static void test_main(void) printk("Scanning successfully started\n"); - WAIT_FOR_FLAG(g_is_connected); + WAIT_FOR_FLAG(flag_connected); - err = bt_ias_discover(g_conn); + err = bt_ias_discover(default_conn); if (err < 0) { FAIL("Failed to discover IAS (err %d)\n", err); return; @@ -125,13 +102,13 @@ static void test_main(void) WAIT_FOR_FLAG(g_service_discovered); /* Set alert levels with a delay to let the server handle any changes it want */ - test_alert_high(g_conn); + test_alert_high(default_conn); k_sleep(K_SECONDS(1)); - test_alert_mild(g_conn); + test_alert_mild(default_conn); k_sleep(K_SECONDS(1)); - test_alert_stop(g_conn); + test_alert_stop(default_conn); k_sleep(K_SECONDS(1)); PASS("IAS client PASS\n"); diff --git a/tests/bluetooth/bsim/audio/src/ias_test.c b/tests/bluetooth/bsim/audio/src/ias_test.c index 40e9d8b6e892..ef3f46a57e57 100644 --- a/tests/bluetooth/bsim/audio/src/ias_test.c +++ b/tests/bluetooth/bsim/audio/src/ias_test.c @@ -23,7 +23,6 @@ extern enum bst_result_t bst_result; -CREATE_FLAG(g_is_connected); CREATE_FLAG(g_high_alert_received); CREATE_FLAG(g_mild_alert_received); CREATE_FLAG(g_stop_alert_received); @@ -49,27 +48,6 @@ BT_IAS_CB_DEFINE(ias_callbacks) = { .no_alert = no_alert_cb, }; -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - default_conn = bt_conn_ref(conn); - g_is_connected = true; -} - -static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, -}; - static void test_main(void) { int err; @@ -80,8 +58,6 @@ static void test_main(void) return; } - bt_conn_cb_register(&conn_callbacks); - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, AD_SIZE, NULL, 0); if (err) { FAIL("Advertising failed to start (err %d)\n", err); @@ -90,7 +66,7 @@ static void test_main(void) printk("Advertising successfully started\n"); - WAIT_FOR_FLAG(g_is_connected); + WAIT_FOR_FLAG(flag_connected); WAIT_FOR_FLAG(g_high_alert_received); printk("High alert received\n"); diff --git a/tests/bluetooth/bsim/audio/src/mcc_test.c b/tests/bluetooth/bsim/audio/src/mcc_test.c index 41493f1d7cce..c242faf04d7c 100644 --- a/tests/bluetooth/bsim/audio/src/mcc_test.c +++ b/tests/bluetooth/bsim/audio/src/mcc_test.c @@ -32,7 +32,6 @@ static uint8_t g_command_result; static uint8_t g_search_result; CREATE_FLAG(ble_is_initialized); -CREATE_FLAG(ble_link_is_ready); CREATE_FLAG(discovery_done); CREATE_FLAG(player_name_read); CREATE_FLAG(icon_object_id_read); @@ -546,23 +545,6 @@ static void bt_ready(int err) SET_FLAG(ble_is_initialized); } -/* Callback on connection */ -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err) { - bt_conn_unref(default_conn); - default_conn = NULL; - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - SET_FLAG(ble_link_is_ready); -} - /* Helper function - select object and read the object metadata * * Will FAIL the test on errors calling select and read metadata. @@ -1328,11 +1310,6 @@ void test_main(void) int err; uint64_t tmp_object_id; - static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, - }; - printk("Media Control Client test application. Board: %s\n", CONFIG_BOARD); UNSET_FLAG(ble_is_initialized); @@ -1345,10 +1322,7 @@ void test_main(void) WAIT_FOR_FLAG(ble_is_initialized); printk("Bluetooth initialized\n"); - bt_conn_cb_register(&conn_callbacks); - /* Connect ******************************************/ - UNSET_FLAG(ble_link_is_ready); err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err) { FAIL("Failed to start scanning (err %d\n)", err); @@ -1356,7 +1330,7 @@ void test_main(void) printk("Scanning started successfully\n"); } - WAIT_FOR_FLAG(ble_link_is_ready); + WAIT_FOR_FLAG(flag_connected); char addr[BT_ADDR_LE_STR_LEN]; diff --git a/tests/bluetooth/bsim/audio/src/mcs_test.c b/tests/bluetooth/bsim/audio/src/mcs_test.c index 413ce60921de..5340d6d9eaff 100644 --- a/tests/bluetooth/bsim/audio/src/mcs_test.c +++ b/tests/bluetooth/bsim/audio/src/mcs_test.c @@ -12,8 +12,6 @@ extern enum bst_result_t bst_result; -CREATE_FLAG(ble_link_is_ready); - /* Callback after Bluetoot initialization attempt */ static void bt_ready(int err) { @@ -33,34 +31,12 @@ static void bt_ready(int err) printk("Advertising successfully started\n"); } -/* Callback when connected */ -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - } else { - default_conn = bt_conn_ref(conn); - printk("Connected: %s\n", addr); - SET_FLAG(ble_link_is_ready); - } -} - static void test_main(void) { int err; - static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, - }; printk("Media Control Server test application. Board: %s\n", CONFIG_BOARD); - bt_conn_cb_register(&conn_callbacks); - /* Initialize media player */ err = media_proxy_pl_init(); if (err) { @@ -75,7 +51,7 @@ static void test_main(void) return; } - WAIT_FOR_FLAG(ble_link_is_ready); + WAIT_FOR_FLAG(flag_connected); PASS("MCS passed\n"); } diff --git a/tests/bluetooth/bsim/audio/src/media_controller_test.c b/tests/bluetooth/bsim/audio/src/media_controller_test.c index 98f918ea9789..9c1df656fd1d 100644 --- a/tests/bluetooth/bsim/audio/src/media_controller_test.c +++ b/tests/bluetooth/bsim/audio/src/media_controller_test.c @@ -31,7 +31,6 @@ static uint32_t g_commands_supported; static uint8_t g_search_control_point_result_code; CREATE_FLAG(ble_is_initialized); -CREATE_FLAG(ble_link_is_ready); CREATE_FLAG(local_player_instance); CREATE_FLAG(remote_player_instance); CREATE_FLAG(player_name_read); @@ -560,21 +559,6 @@ static void bt_ready(int err) SET_FLAG(ble_is_initialized); } -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected: %s\n", addr); - SET_FLAG(ble_link_is_ready); -} - /* Helper function to read the media state and verify that it is as expected * Will FAIL on error reading the media state * Will FAIL if the state is not as expected @@ -1608,7 +1592,6 @@ void scan_and_connect(void) char addr[BT_ADDR_LE_STR_LEN]; int err; - UNSET_FLAG(ble_link_is_ready); err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); if (err) { FAIL("Failed to start scanning (err %d\n)", err); @@ -1617,8 +1600,7 @@ void scan_and_connect(void) printk("Scanning started successfully\n"); - WAIT_FOR_FLAG(ble_link_is_ready); - + WAIT_FOR_FLAG(flag_connected); bt_addr_le_to_str(bt_conn_get_dst(default_conn), addr, sizeof(addr)); printk("Connected: %s\n", addr); @@ -1658,24 +1640,17 @@ void test_media_controller_local_player(void) void test_media_controller_remote_player(void) { int err; - static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, - }; - printk("Media Control remote player test application. Board: %s\n", CONFIG_BOARD); - bt_conn_cb_register(&conn_callbacks); - initialize_bluetooth(); initialize_media(); - UNSET_FLAG(ble_link_is_ready); err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, AD_SIZE, NULL, 0); if (err) { FAIL("Advertising failed to start (err %d)\n", err); } - WAIT_FOR_FLAG(ble_link_is_ready); + + WAIT_FOR_FLAG(flag_connected); discover_remote_player(); /* Sets global variable */ printk("Remote player instance: %p\n", remote_player); @@ -1689,15 +1664,9 @@ void test_media_controller_remote_player(void) /* BabbleSim entry point for server for remote player test */ void test_media_controller_server(void) { - static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, - }; printk("Media Control server test application. Board: %s\n", CONFIG_BOARD); - bt_conn_cb_register(&conn_callbacks); - initialize_bluetooth(); initialize_media(); diff --git a/tests/bluetooth/bsim/audio/src/micp_mic_ctlr_test.c b/tests/bluetooth/bsim/audio/src/micp_mic_ctlr_test.c index b8c0b534a2cb..1074c8c2cef9 100644 --- a/tests/bluetooth/bsim/audio/src/micp_mic_ctlr_test.c +++ b/tests/bluetooth/bsim/audio/src/micp_mic_ctlr_test.c @@ -18,7 +18,6 @@ extern enum bst_result_t bst_result; static struct bt_micp_mic_ctlr *mic_ctlr; static struct bt_micp_included micp_included; static volatile bool g_bt_init; -static volatile bool g_is_connected; static volatile bool g_discovery_complete; static volatile bool g_write_complete; @@ -185,23 +184,6 @@ static struct bt_micp_mic_ctlr_cb micp_mic_ctlr_cbs = { } }; -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - bt_conn_unref(default_conn); - default_conn = NULL; - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - g_is_connected = true; -} - static void bt_ready(int err) { if (err != 0) { @@ -212,11 +194,6 @@ static void bt_ready(int err) g_bt_init = true; } -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - static int test_aics(void) { int err; @@ -390,7 +367,7 @@ static void test_main(void) return; } printk("Scanning successfully started\n"); - WAIT_FOR_COND(g_is_connected); + WAIT_FOR_FLAG(flag_connected); err = bt_micp_mic_ctlr_discover(default_conn, &mic_ctlr); if (err != 0) { diff --git a/tests/bluetooth/bsim/audio/src/micp_mic_dev_test.c b/tests/bluetooth/bsim/audio/src/micp_mic_dev_test.c index 771fb767f023..25d78bdaeb2a 100644 --- a/tests/bluetooth/bsim/audio/src/micp_mic_dev_test.c +++ b/tests/bluetooth/bsim/audio/src/micp_mic_dev_test.c @@ -29,7 +29,6 @@ static volatile uint8_t g_aics_gain_min; static volatile bool g_aics_active = true; static char g_aics_desc[AICS_DESC_SIZE]; static volatile bool g_cb; -static bool g_is_connected; static void micp_mute_cb(uint8_t mute) { @@ -116,27 +115,6 @@ static struct bt_aics_cb aics_cb = { }; #endif /* CONFIG_BT_MICP_MIC_DEV_AICS */ -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - default_conn = bt_conn_ref(conn); - g_is_connected = true; -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - static int test_aics_server_only(void) { int err; @@ -450,7 +428,7 @@ static void test_main(void) printk("Advertising successfully started\n"); - WAIT_FOR_COND(g_is_connected); + WAIT_FOR_FLAG(flag_connected); PASS("MICP mic_dev passed\n"); } diff --git a/tests/bluetooth/bsim/audio/src/tbs_client_test.c b/tests/bluetooth/bsim/audio/src/tbs_client_test.c index 38c6df6e3167..0d06ae9822cb 100644 --- a/tests/bluetooth/bsim/audio/src/tbs_client_test.c +++ b/tests/bluetooth/bsim/audio/src/tbs_client_test.c @@ -11,10 +11,8 @@ #include "common.h" -static struct bt_conn_cb conn_callbacks; extern enum bst_result_t bst_result; static volatile bool bt_init; -static volatile bool is_connected; static volatile bool discovery_complete; static volatile bool is_gtbs_found; static volatile bool read_complete; @@ -116,22 +114,6 @@ static const struct bt_tbs_client_cb tbs_client_cbs = { .termination_reason = NULL }; -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - bt_conn_unref(default_conn); - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - is_connected = true; -} - static void bt_ready(int err) { if (err != 0) { @@ -142,11 +124,6 @@ static void bt_ready(int err) bt_init = true; } -static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, -}; - static void test_ccid(void) { if (is_gtbs_found) { @@ -193,7 +170,6 @@ static void test_main(void) return; } - bt_conn_cb_register(&conn_callbacks); bt_tbs_client_register_cb(&tbs_client_cbs); WAIT_FOR_COND(bt_init); @@ -208,7 +184,7 @@ static void test_main(void) printk("Advertising successfully started\n"); - WAIT_FOR_COND(is_connected); + WAIT_FOR_COND(flag_connected); tbs_client_err = bt_tbs_client_discover(default_conn, true); if (tbs_client_err) { diff --git a/tests/bluetooth/bsim/audio/src/tbs_test.c b/tests/bluetooth/bsim/audio/src/tbs_test.c index 0a2042facb9e..ebae08f7531a 100644 --- a/tests/bluetooth/bsim/audio/src/tbs_test.c +++ b/tests/bluetooth/bsim/audio/src/tbs_test.c @@ -10,7 +10,6 @@ #include "common.h" extern enum bst_result_t bst_result; -static volatile bool is_connected; static volatile bool call_placed; static volatile bool call_held; static volatile bool call_id; @@ -47,28 +46,6 @@ static struct bt_tbs_cb tbs_cbs = { .authorize = tbs_authorize_cb, }; -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - - default_conn = bt_conn_ref(conn); - is_connected = true; -} - -static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, -}; - static void test_main(void) { int err; @@ -81,7 +58,6 @@ static void test_main(void) printk("Audio Client: Bluetooth initialized\n"); - bt_conn_cb_register(&conn_callbacks); bt_tbs_register_cb(&tbs_cbs); err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); @@ -92,7 +68,7 @@ static void test_main(void) printk("Scanning successfully started\n"); - WAIT_FOR_COND(is_connected); + WAIT_FOR_FLAG(flag_connected); WAIT_FOR_COND(call_placed); diff --git a/tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c b/tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c index 53a4c8a25339..52ba2f072ab3 100644 --- a/tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c +++ b/tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c @@ -20,7 +20,6 @@ extern enum bst_result_t bst_result; static struct bt_vcp_vol_ctlr *vol_ctlr; static struct bt_vcp_included vcp_included; -static volatile bool g_is_connected; static volatile bool g_discovery_complete; static volatile bool g_write_complete; @@ -226,27 +225,6 @@ static void vcs_write_cb(struct bt_vcp_vol_ctlr *vol_ctlr, int err) g_write_complete = true; } -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - bt_conn_unref(default_conn); - default_conn = NULL; - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - printk("Connected to %s\n", addr); - g_is_connected = true; -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - static void test_aics_deactivate(void) { int err; @@ -1185,7 +1163,7 @@ static void test_main(void) printk("Scanning successfully started\n"); - WAIT_FOR_COND(g_is_connected); + WAIT_FOR_FLAG(flag_connected); test_discover(); test_included_get(); diff --git a/tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c b/tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c index 476491d33204..e27909316762 100644 --- a/tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c +++ b/tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c @@ -42,7 +42,6 @@ static volatile uint8_t g_aics_gain_min; static volatile bool g_aics_active = 1; static char g_aics_desc[AICS_DESC_SIZE]; static volatile bool g_cb; -static bool g_is_connected; static void vcs_state_cb(int err, uint8_t volume, uint8_t mute) { @@ -185,26 +184,6 @@ static struct bt_aics_cb aics_cb = { .description = aics_description_cb }; -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - printk("Connected to %s\n", addr); - default_conn = bt_conn_ref(conn); - g_is_connected = true; -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - static void test_aics_deactivate(void) { const bool expected_aics_active = false; @@ -1069,7 +1048,7 @@ static void test_main(void) printk("Advertising successfully started\n"); - WAIT_FOR_COND(g_is_connected); + WAIT_FOR_FLAG(flag_connected); PASS("VCP volume renderer passed\n"); } From 3e7205876cb5145d6630a7d1bcaf09945009f9f3 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Thu, 16 Mar 2023 13:31:34 +0100 Subject: [PATCH 0321/1906] bluetooth: tester: Fix BTP L2CAP listen command Fixes regression introduced in 26cf0b68506b441ccc29b2b4eb579606ecbe7e65 "bluetooth: tester: Add support for missing BTP L2CAP listen param". Success status was missing resulting in BTP to fail for tests that require success on connection. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp_l2cap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/bluetooth/tester/src/btp_l2cap.c b/tests/bluetooth/tester/src/btp_l2cap.c index e9ee8728c03a..61953b2c95e5 100644 --- a/tests/bluetooth/tester/src/btp_l2cap.c +++ b/tests/bluetooth/tester/src/btp_l2cap.c @@ -472,6 +472,8 @@ static uint8_t listen(const void *cmd, uint16_t cmd_len, server->psm = psm; switch (cp->response) { + case BTP_L2CAP_CONNECTION_RESPONSE_SUCCESS: + break; case BTP_L2CAP_CONNECTION_RESPONSE_INSUFF_ENC_KEY: /* TSPX_psm_encryption_key_size_required */ req_keysize = 16; From c976211a34a5253c21b70eb03e8aa380ea19a162 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Thu, 16 Mar 2023 11:35:52 +0200 Subject: [PATCH 0322/1906] MAINTAINERS: Correct intel bindings for platform Intel ADSP At the moment all Intel drivers get label Intel ADSP. Correct to match only "intel,adsp*". Signed-off-by: Andrei Emeltchenko --- MAINTAINERS.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index 3cc26775010c..975b54e5ce46 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -2106,7 +2106,7 @@ Intel Platforms (Xtensa): - dts/xtensa/intel/ - tests/boards/intel_adsp/ - samples/boards/intel_adsp/ - - dts/bindings/*/intel,* + - dts/bindings/*/intel,adsp* labels: - "platform: Intel ADSP" From 86757f5ae5cc9d8f079dbaeaf2e17f7780c8c826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20M=C3=B8ller?= Date: Fri, 30 Sep 2022 16:52:48 +0200 Subject: [PATCH 0323/1906] Bluetooth: controller: Fix channel selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For ISO-subevents channel selection must use remap table always -regardless of channel is a mapped or unmapped channel. Signed-off-by: Henrik Møller --- subsys/bluetooth/controller/ll_sw/lll_chan.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll_chan.c b/subsys/bluetooth/controller/ll_sw/lll_chan.c index 465591d1f0b1..4451910bbe1d 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_chan.c +++ b/subsys/bluetooth/controller/ll_sw/lll_chan.c @@ -144,15 +144,9 @@ uint8_t lll_chan_iso_subevent(uint16_t chan_id, uint8_t *chan_map, x = 0; } - chan_idx = ((((uint32_t)prn_subevent_se * x) >> 16) + - d + *remap_idx) % chan_count; - - if ((chan_map[chan_idx >> 3] & (1 << (chan_idx % 8))) == 0U) { - *remap_idx = chan_idx; - chan_idx = chan_sel_remap(chan_map, *remap_idx); - } else { - *remap_idx = chan_idx; - } + *remap_idx = ((((uint32_t)prn_subevent_se * x) >> 16) + + d + *remap_idx) % chan_count; + chan_idx = chan_sel_remap(chan_map, *remap_idx); return chan_idx; } From c3e6edd4021789b6d3f3669d57e24624e93f93eb Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 16 Mar 2023 10:25:21 +0530 Subject: [PATCH 0324/1906] Bluetooth: Controller: Remove redundant use of local variable Remove redundant use of local variable chan_idx in the lll_chan_iso_subevent() function. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/ll_sw/lll_chan.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll_chan.c b/subsys/bluetooth/controller/ll_sw/lll_chan.c index 4451910bbe1d..5a2c47ce2075 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_chan.c +++ b/subsys/bluetooth/controller/ll_sw/lll_chan.c @@ -127,7 +127,6 @@ uint8_t lll_chan_iso_subevent(uint16_t chan_id, uint8_t *chan_map, uint16_t *remap_idx) { uint16_t prn_subevent_se; - uint8_t chan_idx; uint8_t d; uint8_t x; @@ -145,10 +144,9 @@ uint8_t lll_chan_iso_subevent(uint16_t chan_id, uint8_t *chan_map, } *remap_idx = ((((uint32_t)prn_subevent_se * x) >> 16) + - d + *remap_idx) % chan_count; - chan_idx = chan_sel_remap(chan_map, *remap_idx); + d + *remap_idx) % chan_count; - return chan_idx; + return chan_sel_remap(chan_map, *remap_idx); } #endif /* CONFIG_BT_CTLR_ISO */ #endif /* CONFIG_BT_CTLR_CHAN_SEL_2 */ From 9b3a3ee79bd568499d49fe75a580eeda8aea1530 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 16 Mar 2023 10:01:19 +0530 Subject: [PATCH 0325/1906] Bluetooth: Controller: Add additional LE Channel Selection tests Add additional custom LE Channel Selection #2 tests to cover event and subevent mapping. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/ll_sw/lll_chan.c | 86 +++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll_chan.c b/subsys/bluetooth/controller/ll_sw/lll_chan.c index 5a2c47ce2075..c5b7a3f719e0 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_chan.c +++ b/subsys/bluetooth/controller/ll_sw/lll_chan.c @@ -340,6 +340,8 @@ void lll_chan_sel_2_ut(void) uint8_t const chan_map_1_37_used = 37U; uint8_t chan_map_2[] = {0x00, 0x06, 0xE0, 0x00, 0x1E}; uint8_t const chan_map_2_9_used = 9U; + uint8_t chan_map_3[] = {0x06, 0x00, 0x00, 0x00, 0x00}; + uint8_t const chan_map_3_2_used = 2U; uint16_t const chan_id = 0x305F; uint8_t m; @@ -357,7 +359,7 @@ void lll_chan_sel_2_ut(void) m = lll_chan_sel_2(3, chan_id, chan_map_1, chan_map_1_37_used); LL_ASSERT(m == 21U); - /* Section 3.1 Sample Data 2 (9 used channels) */ + /* Section 3.2 Sample Data 2 (9 used channels) */ m = lll_chan_sel_2(6, chan_id, chan_map_2, chan_map_2_9_used); LL_ASSERT(m == 23U); @@ -367,6 +369,18 @@ void lll_chan_sel_2_ut(void) m = lll_chan_sel_2(8, chan_id, chan_map_2, chan_map_2_9_used); LL_ASSERT(m == 34U); + /* FIXME: Use Sample Data from Spec, if one is added. + * Below is a random sample to cover implementation in this file. + */ + /* Section x.x Sample Data 3 (2 used channels) */ + m = lll_chan_sel_2(11U, chan_id, chan_map_3, chan_map_3_2_used); + LL_ASSERT(m == 1U); + + m = lll_chan_sel_2(12U, chan_id, chan_map_3, chan_map_3_2_used); + LL_ASSERT(m == 2U); + + m = lll_chan_sel_2(13U, chan_id, chan_map_3, chan_map_3_2_used); + LL_ASSERT(m == 1U); #if defined(CONFIG_BT_CTLR_ISO) uint16_t prn_subevent_lu; @@ -473,7 +487,7 @@ void lll_chan_sel_2_ut(void) LL_ASSERT(remap_idx == 8U); LL_ASSERT(m == 8U); - /* Section 3.1 Sample Data 2 (9 used channels) */ + /* Section 3.2 Sample Data 2 (9 used channels) */ /* BIS subevent 1, event counter 6 */ m = lll_chan_iso_event(6, chan_id, chan_map_2, chan_map_2_9_used, &prn_s, &remap_idx); LL_ASSERT((prn_s ^ chan_id) == 10975); @@ -536,6 +550,74 @@ void lll_chan_sel_2_ut(void) m = lll_chan_iso_subevent(chan_id, chan_map_2, chan_map_2_9_used, &prn_s, &remap_idx); LL_ASSERT(remap_idx == 1U); LL_ASSERT(m == 10U); + + /* FIXME: Use Sample Data from Spec, if one is added. + * Below is a random sample to cover implementation in this file. + */ + /* Section x.x Sample Data 3 (2 used channels) */ + /* BIS subevent 1, event counter 11 */ + m = lll_chan_iso_event(11U, chan_id, chan_map_3, chan_map_3_2_used, &prn_s, &remap_idx); + LL_ASSERT((prn_s ^ chan_id) == 8628U); + LL_ASSERT(remap_idx == 0U); + LL_ASSERT(m == 1U); + + /* BIS subvent 2 */ + m = lll_chan_iso_subevent(chan_id, chan_map_3, chan_map_3_2_used, &prn_s, &remap_idx); + LL_ASSERT(remap_idx == 1U); + LL_ASSERT(m == 2U); + + /* BIS subvent 3 */ + m = lll_chan_iso_subevent(chan_id, chan_map_3, chan_map_3_2_used, &prn_s, &remap_idx); + LL_ASSERT(remap_idx == 0U); + LL_ASSERT(m == 1U); + + /* BIS subvent 4 */ + m = lll_chan_iso_subevent(chan_id, chan_map_3, chan_map_3_2_used, &prn_s, &remap_idx); + LL_ASSERT(remap_idx == 1U); + LL_ASSERT(m == 2U); + + /* BIS subevent 1, event counter 12 */ + m = lll_chan_iso_event(12U, chan_id, chan_map_3, chan_map_3_2_used, &prn_s, &remap_idx); + LL_ASSERT((prn_s ^ chan_id) == 34748U); + LL_ASSERT(remap_idx == 1U); + LL_ASSERT(m == 2U); + + /* BIS subvent 2 */ + m = lll_chan_iso_subevent(chan_id, chan_map_3, chan_map_3_2_used, &prn_s, &remap_idx); + LL_ASSERT(remap_idx == 0U); + LL_ASSERT(m == 1U); + + /* BIS subvent 3 */ + m = lll_chan_iso_subevent(chan_id, chan_map_3, chan_map_3_2_used, &prn_s, &remap_idx); + LL_ASSERT(remap_idx == 1U); + LL_ASSERT(m == 2U); + + /* BIS subvent 4 */ + m = lll_chan_iso_subevent(chan_id, chan_map_3, chan_map_3_2_used, &prn_s, &remap_idx); + LL_ASSERT(remap_idx == 0U); + LL_ASSERT(m == 1U); + + /* BIS subevent 1, event counter 13 */ + m = lll_chan_iso_event(13U, chan_id, chan_map_3, chan_map_3_2_used, &prn_s, &remap_idx); + LL_ASSERT((prn_s ^ chan_id) == 22072U); + LL_ASSERT(remap_idx == 0U); + LL_ASSERT(m == 1U); + + /* BIS subvent 2 */ + m = lll_chan_iso_subevent(chan_id, chan_map_3, chan_map_3_2_used, &prn_s, &remap_idx); + LL_ASSERT(remap_idx == 1U); + LL_ASSERT(m == 2U); + + /* BIS subvent 3 */ + m = lll_chan_iso_subevent(chan_id, chan_map_3, chan_map_3_2_used, &prn_s, &remap_idx); + LL_ASSERT(remap_idx == 0U); + LL_ASSERT(m == 1U); + + /* BIS subvent 4 */ + m = lll_chan_iso_subevent(chan_id, chan_map_3, chan_map_3_2_used, &prn_s, &remap_idx); + LL_ASSERT(remap_idx == 1U); + LL_ASSERT(m == 2U); + #endif /* CONFIG_BT_CTLR_ISO */ } #endif /* CONFIG_BT_CTLR_TEST */ From 1f52e70fe26918a0d938555474d05eaaf8b46f67 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 16 Mar 2023 10:06:28 +0530 Subject: [PATCH 0326/1906] Bluetooth: Controller: Add 'U' suffix when using unsigned variables Add a 'U' suffix to values, when computing and comparing against unsigned variables. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/ll_sw/lll_chan.c | 50 ++++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll_chan.c b/subsys/bluetooth/controller/ll_sw/lll_chan.c index c5b7a3f719e0..3d66bbb54294 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_chan.c +++ b/subsys/bluetooth/controller/ll_sw/lll_chan.c @@ -347,26 +347,26 @@ void lll_chan_sel_2_ut(void) /* Tests when ISO not supported */ /* Section 3.1 Sample Data 1 (37 used channels) */ - m = lll_chan_sel_2(0, chan_id, chan_map_1, chan_map_1_37_used); + m = lll_chan_sel_2(0U, chan_id, chan_map_1, chan_map_1_37_used); LL_ASSERT(m == 25U); - m = lll_chan_sel_2(1, chan_id, chan_map_1, chan_map_1_37_used); + m = lll_chan_sel_2(1U, chan_id, chan_map_1, chan_map_1_37_used); LL_ASSERT(m == 20U); - m = lll_chan_sel_2(2, chan_id, chan_map_1, chan_map_1_37_used); + m = lll_chan_sel_2(2U, chan_id, chan_map_1, chan_map_1_37_used); LL_ASSERT(m == 6U); - m = lll_chan_sel_2(3, chan_id, chan_map_1, chan_map_1_37_used); + m = lll_chan_sel_2(3U, chan_id, chan_map_1, chan_map_1_37_used); LL_ASSERT(m == 21U); /* Section 3.2 Sample Data 2 (9 used channels) */ - m = lll_chan_sel_2(6, chan_id, chan_map_2, chan_map_2_9_used); + m = lll_chan_sel_2(6U, chan_id, chan_map_2, chan_map_2_9_used); LL_ASSERT(m == 23U); - m = lll_chan_sel_2(7, chan_id, chan_map_2, chan_map_2_9_used); + m = lll_chan_sel_2(7U, chan_id, chan_map_2, chan_map_2_9_used); LL_ASSERT(m == 9U); - m = lll_chan_sel_2(8, chan_id, chan_map_2, chan_map_2_9_used); + m = lll_chan_sel_2(8U, chan_id, chan_map_2, chan_map_2_9_used); LL_ASSERT(m == 34U); /* FIXME: Use Sample Data from Spec, if one is added. @@ -389,23 +389,23 @@ void lll_chan_sel_2_ut(void) uint16_t prn_s; /* BIS subevent 2, event counter 0, test prnSubEvent_se */ - prn_s = 56857 ^ chan_id; + prn_s = 56857U ^ chan_id; prn_subevent_lu = prn_s; prn_subevent_se = chan_prn_subevent_se(chan_id, &prn_subevent_lu); - LL_ASSERT(prn_subevent_se == 11710); + LL_ASSERT(prn_subevent_se == 11710U); /* BIS subevent 3, event counter 0 */ prn_subevent_se = chan_prn_subevent_se(chan_id, &prn_subevent_lu); - LL_ASSERT(prn_subevent_se == 16649); + LL_ASSERT(prn_subevent_se == 16649U); /* BIS subevent 4, event counter 0 */ prn_subevent_se = chan_prn_subevent_se(chan_id, &prn_subevent_lu); - LL_ASSERT(prn_subevent_se == 38198); + LL_ASSERT(prn_subevent_se == 38198U); /* Section 3.1 Sample Data 1 (37 used channels) */ /* BIS subevent 1, event counter 0 */ - m = lll_chan_iso_event(0, chan_id, chan_map_1, chan_map_1_37_used, &prn_s, &remap_idx); - LL_ASSERT((prn_s ^ chan_id) == 56857); + m = lll_chan_iso_event(0U, chan_id, chan_map_1, chan_map_1_37_used, &prn_s, &remap_idx); + LL_ASSERT((prn_s ^ chan_id) == 56857U); LL_ASSERT(m == 25U); LL_ASSERT(remap_idx == 25U); @@ -425,8 +425,8 @@ void lll_chan_sel_2_ut(void) LL_ASSERT(m == 36U); /* BIS subevent 1, event counter 1 */ - m = lll_chan_iso_event(1, chan_id, chan_map_1, chan_map_1_37_used, &prn_s, &remap_idx); - LL_ASSERT((prn_s ^ chan_id) == 1685); + m = lll_chan_iso_event(1U, chan_id, chan_map_1, chan_map_1_37_used, &prn_s, &remap_idx); + LL_ASSERT((prn_s ^ chan_id) == 1685U); LL_ASSERT(m == 20U); LL_ASSERT(remap_idx == 20U); @@ -446,8 +446,8 @@ void lll_chan_sel_2_ut(void) LL_ASSERT(m == 34U); /* BIS subevent 1, event counter 2 */ - m = lll_chan_iso_event(2, chan_id, chan_map_1, chan_map_1_37_used, &prn_s, &remap_idx); - LL_ASSERT((prn_s ^ chan_id) == 38301); + m = lll_chan_iso_event(2U, chan_id, chan_map_1, chan_map_1_37_used, &prn_s, &remap_idx); + LL_ASSERT((prn_s ^ chan_id) == 38301U); LL_ASSERT(m == 6U); LL_ASSERT(remap_idx == 6U); @@ -467,8 +467,8 @@ void lll_chan_sel_2_ut(void) LL_ASSERT(m == 21U); /* BIS subevent 1, event counter 3 */ - m = lll_chan_iso_event(3, chan_id, chan_map_1, chan_map_1_37_used, &prn_s, &remap_idx); - LL_ASSERT((prn_s ^ chan_id) == 27475); + m = lll_chan_iso_event(3U, chan_id, chan_map_1, chan_map_1_37_used, &prn_s, &remap_idx); + LL_ASSERT((prn_s ^ chan_id) == 27475U); LL_ASSERT(m == 21U); LL_ASSERT(remap_idx == 21U); @@ -489,8 +489,8 @@ void lll_chan_sel_2_ut(void) /* Section 3.2 Sample Data 2 (9 used channels) */ /* BIS subevent 1, event counter 6 */ - m = lll_chan_iso_event(6, chan_id, chan_map_2, chan_map_2_9_used, &prn_s, &remap_idx); - LL_ASSERT((prn_s ^ chan_id) == 10975); + m = lll_chan_iso_event(6U, chan_id, chan_map_2, chan_map_2_9_used, &prn_s, &remap_idx); + LL_ASSERT((prn_s ^ chan_id) == 10975U); LL_ASSERT(remap_idx == 4U); LL_ASSERT(m == 23U); @@ -510,8 +510,8 @@ void lll_chan_sel_2_ut(void) LL_ASSERT(m == 36U); /* BIS subevent 1, event counter 7 */ - m = lll_chan_iso_event(7, chan_id, chan_map_2, chan_map_2_9_used, &prn_s, &remap_idx); - LL_ASSERT((prn_s ^ chan_id) == 5490); + m = lll_chan_iso_event(7U, chan_id, chan_map_2, chan_map_2_9_used, &prn_s, &remap_idx); + LL_ASSERT((prn_s ^ chan_id) == 5490U); LL_ASSERT(remap_idx == 0U); LL_ASSERT(m == 9U); @@ -531,8 +531,8 @@ void lll_chan_sel_2_ut(void) LL_ASSERT(m == 33U); /* BIS subevent 1, event counter 8 */ - m = lll_chan_iso_event(8, chan_id, chan_map_2, chan_map_2_9_used, &prn_s, &remap_idx); - LL_ASSERT((prn_s ^ chan_id) == 46970); + m = lll_chan_iso_event(8U, chan_id, chan_map_2, chan_map_2_9_used, &prn_s, &remap_idx); + LL_ASSERT((prn_s ^ chan_id) == 46970U); LL_ASSERT(remap_idx == 6U); LL_ASSERT(m == 34U); From 36c8b433c8ae539a357ab739e250b3dd165969a8 Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Fri, 3 Mar 2023 09:46:08 -0700 Subject: [PATCH 0327/1906] scripts: Print file causing error for syscalls I was using a source file provided by TDK for a sensor driver and the file was (originally) not encoded as UTF-8. When the read() function was called, the build would fail but I had no idea why. This change wrapps the 'read()' call and prints the error with the file name as context. Signed-off-by: Yuval Peress --- scripts/build/parse_syscalls.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/build/parse_syscalls.py b/scripts/build/parse_syscalls.py index b9aef7178784..4385f5a8a9a9 100644 --- a/scripts/build/parse_syscalls.py +++ b/scripts/build/parse_syscalls.py @@ -77,7 +77,11 @@ def analyze_headers(multiple_directories): continue with open(path, "r", encoding="utf-8") as fp: - contents = fp.read() + try: + contents = fp.read() + except Exception: + sys.stderr.write("Error decoding %s\n" % path) + raise try: syscall_result = [(mo.groups(), fn) From 91ea8fa911b920846be0cef97b07062be6dcf929 Mon Sep 17 00:00:00 2001 From: Scott Chao Date: Fri, 10 Mar 2023 08:09:31 +0800 Subject: [PATCH 0328/1906] samples: blinky_pwm: Add stm32f072b_disco support This will enable the use of stm23f072b_disco on this sample. - Set pwm3 as tim3_ch1_pc6 since red led is using PC6/ TIM3_CH1. Signed-off-by: Scott Chao --- .../arm/stm32f072b_disco/stm32f072b_disco.dts | 21 +++++++++++++++++++ .../boards/stm32f072b_disco.overlay | 13 ++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 samples/basic/blinky_pwm/boards/stm32f072b_disco.overlay diff --git a/boards/arm/stm32f072b_disco/stm32f072b_disco.dts b/boards/arm/stm32f072b_disco/stm32f072b_disco.dts index dc13e7e99baf..1e6e10f79cd4 100644 --- a/boards/arm/stm32f072b_disco/stm32f072b_disco.dts +++ b/boards/arm/stm32f072b_disco/stm32f072b_disco.dts @@ -48,11 +48,21 @@ }; }; + pwmleds: pwmleds { + compatible = "pwm-leds"; + status = "disabled"; + + red_pwm_led: red_pwm_led { + pwms = <&pwm3 1 PWM_MSEC(20) PWM_POLARITY_NORMAL>; + }; + }; + aliases { led0 = &red_up_led_3; led1 = &yellow_left_4; led2 = &green_right_led_5; led3 = &blue_low_led_6; + pwm-led0 = &red_pwm_led; sw0 = &user_button; watchdog0 = &iwdg; }; @@ -113,3 +123,14 @@ &iwdg { status = "okay"; }; + +&timers3 { + st,prescaler = <10000>; + status = "okay"; + + pwm3: pwm { + status = "okay"; + pinctrl-0 = <&tim3_ch1_pc6>; + pinctrl-names = "default"; + }; +}; diff --git a/samples/basic/blinky_pwm/boards/stm32f072b_disco.overlay b/samples/basic/blinky_pwm/boards/stm32f072b_disco.overlay new file mode 100644 index 000000000000..2dc80b14dca8 --- /dev/null +++ b/samples/basic/blinky_pwm/boards/stm32f072b_disco.overlay @@ -0,0 +1,13 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2023 Scott Chao + */ + +&pwmleds { + status = "okay"; +}; + +&pwm3 { + status = "okay"; +}; From 56572687c701fdfca8165c4b94fced35bda7fe6c Mon Sep 17 00:00:00 2001 From: Evgeniy Paltsev Date: Fri, 10 Mar 2023 16:07:16 +0000 Subject: [PATCH 0329/1906] drivers: serial: add virtual uart over ARC hostlink channel Add support for virtual UART device that uses ARC Hostlink channels for data transfers. Due to the Hostlink principle, this driver supports only polling API. Signed-off-by: Eugeniy Paltsev Signed-off-by: Evgeniy Paltsev --- drivers/serial/CMakeLists.txt | 1 + drivers/serial/Kconfig | 2 + drivers/serial/Kconfig.hostlink | 13 + drivers/serial/uart_hostlink.c | 410 ++++++++++++++++++++ dts/bindings/serial/snps,hostlink-uart.yaml | 8 + 5 files changed, 434 insertions(+) create mode 100644 drivers/serial/Kconfig.hostlink create mode 100644 drivers/serial/uart_hostlink.c create mode 100644 dts/bindings/serial/snps,hostlink-uart.yaml diff --git a/drivers/serial/CMakeLists.txt b/drivers/serial/CMakeLists.txt index 96f1ab20b461..863e16ea2b13 100644 --- a/drivers/serial/CMakeLists.txt +++ b/drivers/serial/CMakeLists.txt @@ -56,6 +56,7 @@ zephyr_library_sources_ifdef(CONFIG_UART_SMARTBOND uart_smartbond.c) zephyr_library_sources_ifdef(CONFIG_UART_NXP_S32_LINFLEXD uart_nxp_s32_linflexd.c) zephyr_library_sources_ifdef(CONFIG_UART_CDNS uart_cdns.c) zephyr_library_sources_ifdef(CONFIG_UART_OPENTITAN uart_opentitan.c) +zephyr_library_sources_ifdef(CONFIG_UART_HOSTLINK uart_hostlink.c) zephyr_library_sources_ifdef(CONFIG_USERSPACE uart_handlers.c) diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index 81e76a6c22b4..8dd7147a22d7 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig @@ -214,4 +214,6 @@ source "drivers/serial/Kconfig.opentitan" source "drivers/serial/Kconfig.altera" +source "drivers/serial/Kconfig.hostlink" + endif # SERIAL diff --git a/drivers/serial/Kconfig.hostlink b/drivers/serial/Kconfig.hostlink new file mode 100644 index 000000000000..b2028edf7047 --- /dev/null +++ b/drivers/serial/Kconfig.hostlink @@ -0,0 +1,13 @@ +# Copyright (c) 2023 Synopsys Inc. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Virtual UART HOSTLINK driver option + +config UART_HOSTLINK + bool "ARC HOSTLINK UART driver" + default y + depends on ARC + depends on DT_HAS_SNPS_HOSTLINK_UART_ENABLED + select SERIAL_HAS_DRIVER + help + This option enables access to HOSTLINK channel as UART device. diff --git a/drivers/serial/uart_hostlink.c b/drivers/serial/uart_hostlink.c new file mode 100644 index 000000000000..34f6bddeffa2 --- /dev/null +++ b/drivers/serial/uart_hostlink.c @@ -0,0 +1,410 @@ +/* + * Copyright (c) 2023 Synopsys Inc. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#define DT_DRV_COMPAT snps_hostlink_uart + +/* Only supported by HW and nSIM targets */ +BUILD_ASSERT(!IS_ENABLED(CONFIG_QEMU_TARGET)); +/* Only supported by ARC targets */ +BUILD_ASSERT(IS_ENABLED(CONFIG_ARC)); + +#define HL_SYSCALL_OPEN 0 +#define HL_SYSCALL_CLOSE 1 +#define HL_SYSCALL_READ 2 +#define HL_SYSCALL_WRITE 3 +#define HL_SYSCALL_LSEEK 4 +#define HL_SYSCALL_UNLINK 5 +#define HL_SYSCALL_ISATTY 6 +#define HL_SYSCALL_TMPNAM 7 +#define HL_SYSCALL_GETENV 8 +#define HL_SYSCALL_CLOCK 9 +#define HL_SYSCALL_TIME 10 +#define HL_SYSCALL_RENAME 11 +#define HL_SYSCALL_ARGC 12 +#define HL_SYSCALL_ARGV 13 +#define HL_SYSCALL_RETCODE 14 +#define HL_SYSCALL_ACCESS 15 +#define HL_SYSCALL_GETPID 16 +#define HL_SYSCALL_GETCWD 17 +#define HL_SYSCALL_USER 18 + +#ifndef __noinline +#define __noinline __attribute__((noinline)) +#endif /* __noinline */ + +#define HL_VERSION 1 + +/* "No message here" mark. */ +#define HL_NOADDRESS 0xFFFFFFFF + +/* TODO: if we want to carve some additional space we can use the actual maximum processor cache + * line size here (i.e 128) + */ +#define HL_MAX_DCACHE_LINE 256 + +/* Hostlink gateway structure. */ +struct hl_hdr { + uint32_t version; /* Current version is 1. */ + uint32_t target2host_addr; /* Packet address from target to host. */ + uint32_t host2target_addr; /* Packet address from host to target. */ + uint32_t buf_addr; /* Address for host to write answer. */ + uint32_t payload_size; /* Buffer size without packet header. */ + uint32_t options; /* For future use. */ + uint32_t break_to_mon_addr; /* For future use. */ +} __packed; + +/* Hostlink packet header. */ +struct hl_pkt_hdr { + uint32_t packet_id; /* Packet id. Always set to 1 here. */ + uint32_t total_size; /* Size of packet including header. */ + uint32_t priority; /* For future use. */ + uint32_t type; /* For future use. */ + uint32_t checksum; /* For future use. */ +} __packed; + +struct hl_packed_int { + volatile uint16_t type; + volatile uint16_t size; + volatile int32_t value; +} __packed; + +struct hl_packed_short_buff { + volatile uint16_t type; + volatile uint16_t size; + volatile uint8_t payload_short[4]; +} __packed; + +BUILD_ASSERT(sizeof(struct hl_packed_int) == sizeof(struct hl_packed_short_buff)); + +struct hl_pkt_write_char_put { + struct hl_packed_int syscall_nr; + struct hl_packed_int fd; + struct hl_packed_short_buff buff; + struct hl_packed_int nbyte; +} __packed; + +struct hl_pkt_write_char_get { + struct hl_packed_int byte_written; + struct hl_packed_int host_errno; +} __packed; + +#define MAX_PKT_SZ MAX(sizeof(struct hl_pkt_write_char_put), sizeof(struct hl_pkt_write_char_get)) +#define HL_HEADERS_SZ (sizeof(struct hl_hdr) + sizeof(struct hl_pkt_hdr)) +BUILD_ASSERT(HL_HEADERS_SZ + MAX_PKT_SZ < HL_MAX_DCACHE_LINE); + +union payload_u { + struct hl_pkt_write_char_put pkt_write_char_put; + struct hl_pkt_write_char_get pkt_write_char_get; + char reserved[HL_MAX_DCACHE_LINE - HL_HEADERS_SZ]; +} __packed; + +BUILD_ASSERT(sizeof(union payload_u) % 4 == 0); + +/* Main hostlink structure. */ +struct hl { + /* General hostlink information. */ + volatile struct hl_hdr hdr; + /* Start of the hostlink buffer. */ + volatile struct hl_pkt_hdr pkt_hdr; + /* Payload buffer */ + volatile union payload_u payload; +} __aligned(HL_MAX_DCACHE_LINE) __packed; + +/* In general we must exactly fit into one or multiple cache lines as we shouldn't share hostlink + * buffer (which is uncached) with any cached data + */ +BUILD_ASSERT(sizeof(struct hl) % HL_MAX_DCACHE_LINE == 0); +/* However, with current supported functionality we fit into one MAX cache line. If we add + * some features which require bigger payload buffer this might become not true. + */ +BUILD_ASSERT(sizeof(struct hl) == HL_MAX_DCACHE_LINE); + +/* Main structure. Do not rename as nSIM simulator / MDB debugger looks for the '__HOSTLINK__' + * symbol. We need to keep it initialized so it won't be put into BSS (so we won't write with + * regular cached access in it). + */ +volatile struct hl __HOSTLINK__ = { + .hdr = { + .version = HL_VERSION, + .target2host_addr = HL_NOADDRESS + } +}; + +BUILD_ASSERT(sizeof(__HOSTLINK__) % HL_MAX_DCACHE_LINE == 0); + +#if defined(__CCAC__) +#define HL_HAS_C_ACCESSORS 0 +#elif defined(CONFIG_ISA_ARCV3) +#define HL_HAS_C_ACCESSORS 0 +#else +#define HL_HAS_C_ACCESSORS 1 +#endif + +#if HL_HAS_C_ACCESSORS + +#ifndef __uncached +#define __uncached __attribute__((uncached)) +#endif /* __uncached */ + +static inline void hl_write32(volatile void *addr, uint32_t val) +{ + *(volatile __uncached uint32_t *)addr = val; +} + +static inline void hl_write16(volatile void *addr, uint16_t val) +{ + *(volatile __uncached uint16_t *)addr = val; +} + +static inline void hl_write8(volatile void *addr, uint8_t val) +{ + *(volatile __uncached uint8_t *)addr = val; +} + +static inline uint32_t hl_read32(volatile void *addr) +{ + return *(volatile __uncached uint32_t *)addr; +} + +static inline uint16_t hl_read16(volatile void *addr) +{ + return *(volatile __uncached uint16_t *)addr; +} +#else +static inline void hl_write32(volatile void *addr, uint32_t val) +{ + __asm__ __volatile__("st.di %0, [%1]" :: "r" (val), "r" (addr) : "memory"); +} + +static inline void hl_write16(volatile void *addr, uint16_t val) +{ + __asm__ __volatile__("stb.di %0, [%1]" :: "r" (val), "r" (addr) : "memory"); +} + +static inline void hl_write8(volatile void *addr, uint8_t val) +{ + __asm__ __volatile__("sth.di %0, [%1]" :: "r" (val), "r" (addr) : "memory"); +} + +static inline uint32_t hl_read32(volatile void *addr) +{ + uint32_t w; + + __asm__ __volatile__("ld.di %0, [%1]" : "=r" (w) : "r" (addr) : "memory"); + + return w; +} + +static inline uint16_t hl_read16(volatile void *addr) +{ + uint16_t w; + + __asm__ __volatile__("ld.di %0, [%1]" : "=r" (w) : "r" (addr) : "memory"); + + return w; +} +#endif /* HL_HAS_C_ACCESSORS */ + +/* Get hostlink payload size (iochunk + reserved space). */ +static uint32_t hl_payload_size(void) +{ + return sizeof(__HOSTLINK__.payload); +} + +#define ALIGN(x, y) (((x) + ((y) - 1)) & ~((y) - 1)) + +/* Fill hostlink packet header. */ +static void hl_pkt_init(volatile struct hl_pkt_hdr *pkt, int size) +{ + hl_write32(&pkt->packet_id, 1); + hl_write32(&pkt->total_size, ALIGN(size, 4) + sizeof(struct hl_pkt_hdr)); + hl_write32(&pkt->priority, 0); + hl_write32(&pkt->type, 0); + hl_write32(&pkt->checksum, 0); +} + +/* Send hostlink packet to the host. */ +static void hl_static_send(size_t payload_used) +{ + /* We are OK to cast pointer to uint32_t even on 64bit platforms as we support to build + * Zephyr on ARCv3 64bit only to lower 4GiB. Still we need to cast via uintptr_t to avoid + * compiler warnings. + */ + uint32_t buf_addr = (uint32_t)(uintptr_t)(&__HOSTLINK__.pkt_hdr); + + hl_pkt_init(&__HOSTLINK__.pkt_hdr, payload_used); + + hl_write32(&__HOSTLINK__.hdr.buf_addr, buf_addr); + hl_write32(&__HOSTLINK__.hdr.payload_size, hl_payload_size()); + hl_write32(&__HOSTLINK__.hdr.host2target_addr, HL_NOADDRESS); + hl_write32(&__HOSTLINK__.hdr.version, HL_VERSION); + hl_write32(&__HOSTLINK__.hdr.options, 0); + hl_write32(&__HOSTLINK__.hdr.break_to_mon_addr, 0); + + compiler_barrier(); + + /* This tells the debugger we have a command. + * It is responsibility of debugger to set this back to HL_NOADDRESS + * after receiving the packet. + * Please note that we don't wait here because some implementations + * use hl_blockedPeek() function as a signal that we send a messege. + */ + hl_write32(&__HOSTLINK__.hdr.target2host_addr, buf_addr); + + compiler_barrier(); +} + +/* + * Wait for host response and return pointer to hostlink payload. + * Symbol hl_blockedPeek() is used by the simulator as message signal. + */ +static void __noinline _hl_blockedPeek(void) +{ + while (hl_read32(&__HOSTLINK__.hdr.host2target_addr) == HL_NOADDRESS) { + /* TODO: Timeout. */ + } +} + +static void hl_static_recv(void) +{ + compiler_barrier(); + _hl_blockedPeek(); + compiler_barrier(); +} + +/* Mark hostlink buffer as "No message here". */ +static void hl_delete(void) +{ + hl_write32(&__HOSTLINK__.hdr.target2host_addr, HL_NOADDRESS); +} + +/* Parameter types. */ +#define PAT_CHAR 1 +#define PAT_SHORT 2 +#define PAT_INT 3 +#define PAT_STRING 4 +/* For future use. */ +#define PAT_INT64 5 + +static void hl_static_pack_int(volatile struct hl_packed_int *pack, int32_t value) +{ + hl_write16(&pack->type, PAT_INT); + hl_write16(&pack->size, 4); + hl_write32(&pack->value, value); +} + +static void hl_static_pack_char(volatile struct hl_packed_short_buff *pack, unsigned char c) +{ + hl_write16(&pack->type, PAT_STRING); + hl_write16(&pack->size, 1); + hl_write8(&pack->payload_short, c); +} + +static int hl_static_unpack_int(volatile struct hl_packed_int *pack, int32_t *value) +{ + uint16_t type = hl_read16(&pack->type); + uint16_t size = hl_read16(&pack->size); + + if (type != PAT_INT) { + return -1; + } + + if (size != 4) { + return -1; + } + + *value = hl_read32(&pack->value); + + return 0; +} + +static inline int32_t hl_write_char(int fd, const char c) +{ + /* + * Format: + * in, int -> syscall (HL_SYSCALL_WRITE) + * in, int -> file descriptor + * in, ptr -> buffer + * in, int -> bytes number + * out, int -> bytes written + * out, int, host errno + */ + + hl_static_pack_int(&__HOSTLINK__.payload.pkt_write_char_put.syscall_nr, HL_SYSCALL_WRITE); + + hl_static_pack_int(&__HOSTLINK__.payload.pkt_write_char_put.fd, fd); + + hl_static_pack_char(&__HOSTLINK__.payload.pkt_write_char_put.buff, c); + + hl_static_pack_int(&__HOSTLINK__.payload.pkt_write_char_put.nbyte, 1); + + hl_static_send(sizeof(struct hl_pkt_write_char_put)); + hl_static_recv(); + + int32_t bwr = 0; + int ret = hl_static_unpack_int(&__HOSTLINK__.payload.pkt_write_char_get.byte_written, &bwr); + + /* we can get host errno here with: + * hl_static_unpack_int(&__HOSTLINK__.pkt_write_char_get.host_errno, &host_errno); + * but we don't need it for UART emulation. + */ + + if (bwr <= 0) { + ret = -1; + } + + hl_delete(); + + return ret; +} + +static int uart_hostlink_init(const struct device *dev) +{ + ARG_UNUSED(dev); + + return 0; +} + +/** + * @brief Poll the device for input. + * + * @param dev UART device struct + * @param c Pointer to character + * + * @return 0 if a character arrived, -1 if the input buffer if empty. + */ +static int uart_hostlink_poll_in(const struct device *dev, unsigned char *c) +{ + ARG_UNUSED(dev); + + /* We plan to use hostlink for logging, so no much sense in poll_in implementation */ + return -1; +} + +/** + * @brief Output a character in polled mode. + * + * @param dev UART device struct + * @param c Character to send + */ +static void uart_hostlink_poll_out(const struct device *dev, unsigned char c) +{ + ARG_UNUSED(dev); + + hl_write_char(1, c); +} + +static const struct uart_driver_api uart_hostlink_driver_api = { + .poll_in = uart_hostlink_poll_in, + .poll_out = uart_hostlink_poll_out, +}; + +DEVICE_DT_DEFINE(DT_NODELABEL(hostlink), uart_hostlink_init, NULL, NULL, NULL, PRE_KERNEL_1, + CONFIG_SERIAL_INIT_PRIORITY, &uart_hostlink_driver_api); diff --git a/dts/bindings/serial/snps,hostlink-uart.yaml b/dts/bindings/serial/snps,hostlink-uart.yaml new file mode 100644 index 000000000000..79c175fd715b --- /dev/null +++ b/dts/bindings/serial/snps,hostlink-uart.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2023, Synopsys Inc. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +description: ARC HOSTLINK UART + +compatible: "snps,hostlink-uart" + +include: uart-controller.yaml From d4a5f183d0fedd9ce79fb6b7c9721939dbd40a54 Mon Sep 17 00:00:00 2001 From: Evgeniy Paltsev Date: Tue, 14 Mar 2023 15:22:43 +0000 Subject: [PATCH 0330/1906] ARC: boards: add nsim-based board with hostlink uart support Add nsim_hs3x_hostlink nsim-based board to test virtual UART emulated with hostlink channel. Signed-off-by: Eugeniy Paltsev Signed-off-by: Evgeniy Paltsev --- boards/arc/nsim/nsim-smp.dtsi | 1 + boards/arc/nsim/nsim-uart-hostlink.dtsi | 19 ++++++++ boards/arc/nsim/nsim-uart-ns16550.dtsi | 24 ++++++++++ boards/arc/nsim/nsim.dtsi | 15 ------ boards/arc/nsim/nsim_em.dtsi | 1 + boards/arc/nsim/nsim_hs.dts | 1 + boards/arc/nsim/nsim_hs3x_hostlink.dts | 27 +++++++++++ boards/arc/nsim/nsim_hs3x_hostlink.yaml | 14 ++++++ boards/arc/nsim/nsim_hs3x_hostlink_defconfig | 15 ++++++ boards/arc/nsim/nsim_hs5x.dts | 1 + boards/arc/nsim/nsim_hs6x.dts | 1 + boards/arc/nsim/nsim_hs_flash_xip.dts | 1 + boards/arc/nsim/nsim_hs_mpuv6.dts | 1 + boards/arc/nsim/nsim_hs_sram.dts | 1 + .../arc/nsim/support/mdb_hs3x_hostlink.args | 44 +++++++++++++++++ .../arc/nsim/support/nsim_hs3x_hostlink.props | 47 +++++++++++++++++++ 16 files changed, 198 insertions(+), 15 deletions(-) create mode 100644 boards/arc/nsim/nsim-uart-hostlink.dtsi create mode 100644 boards/arc/nsim/nsim-uart-ns16550.dtsi create mode 100644 boards/arc/nsim/nsim_hs3x_hostlink.dts create mode 100644 boards/arc/nsim/nsim_hs3x_hostlink.yaml create mode 100644 boards/arc/nsim/nsim_hs3x_hostlink_defconfig create mode 100644 boards/arc/nsim/support/mdb_hs3x_hostlink.args create mode 100644 boards/arc/nsim/support/nsim_hs3x_hostlink.props diff --git a/boards/arc/nsim/nsim-smp.dtsi b/boards/arc/nsim/nsim-smp.dtsi index 5a2eb307bad6..facdf989401f 100644 --- a/boards/arc/nsim/nsim-smp.dtsi +++ b/boards/arc/nsim/nsim-smp.dtsi @@ -4,6 +4,7 @@ */ #include "nsim.dtsi" +#include "nsim-uart-ns16550.dtsi" / { ici: intercore-interrupt-unit { diff --git a/boards/arc/nsim/nsim-uart-hostlink.dtsi b/boards/arc/nsim/nsim-uart-hostlink.dtsi new file mode 100644 index 000000000000..5ac165f840da --- /dev/null +++ b/boards/arc/nsim/nsim-uart-hostlink.dtsi @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023, Synopsys Inc. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "skeleton.dtsi" + +/ { + hostlink: hostlink { + compatible = "snps,hostlink-uart"; + status = "okay"; + }; + + chosen { + zephyr,console = &hostlink; + zephyr,shell-uart = &hostlink; + }; +}; diff --git a/boards/arc/nsim/nsim-uart-ns16550.dtsi b/boards/arc/nsim/nsim-uart-ns16550.dtsi new file mode 100644 index 000000000000..a14e360d237b --- /dev/null +++ b/boards/arc/nsim/nsim-uart-ns16550.dtsi @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023, Synopsys Inc. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "skeleton.dtsi" + +/ { + uart0: uart@f0000000 { + compatible = "ns16550"; + clock-frequency = <50000000>; + reg = <0xf0000000 0x400>; + current-speed = <115200>; + interrupt-parent = <&intc>; + interrupts = <24 1>; + reg-shift = <2>; + }; + + chosen { + zephyr,console = &uart0; + zephyr,shell-uart = &uart0; + }; +}; diff --git a/boards/arc/nsim/nsim.dtsi b/boards/arc/nsim/nsim.dtsi index fc27f7fbbf99..6469bffb180c 100644 --- a/boards/arc/nsim/nsim.dtsi +++ b/boards/arc/nsim/nsim.dtsi @@ -32,19 +32,4 @@ interrupts = <17 1>; interrupt-parent = <&intc>; }; - - uart0: uart@f0000000 { - compatible = "ns16550"; - clock-frequency = <50000000>; - reg = <0xf0000000 0x400>; - current-speed = <115200>; - interrupt-parent = <&intc>; - interrupts = <24 1>; - reg-shift = <2>; - }; - - chosen { - zephyr,console = &uart0; - zephyr,shell-uart = &uart0; - }; }; diff --git a/boards/arc/nsim/nsim_em.dtsi b/boards/arc/nsim/nsim_em.dtsi index 2910e6a27a3c..45f90abf925f 100644 --- a/boards/arc/nsim/nsim_em.dtsi +++ b/boards/arc/nsim/nsim_em.dtsi @@ -8,6 +8,7 @@ #include "nsim.dtsi" #include "nsim-ccm-mem.dtsi" +#include "nsim-uart-ns16550.dtsi" / { cpus { diff --git a/boards/arc/nsim/nsim_hs.dts b/boards/arc/nsim/nsim_hs.dts index 4fdcf80d906f..e066c8d92d0a 100644 --- a/boards/arc/nsim/nsim_hs.dts +++ b/boards/arc/nsim/nsim_hs.dts @@ -8,6 +8,7 @@ #include "nsim.dtsi" #include "nsim-ccm-mem.dtsi" +#include "nsim-uart-ns16550.dtsi" / { model = "snps,nsim_hs"; diff --git a/boards/arc/nsim/nsim_hs3x_hostlink.dts b/boards/arc/nsim/nsim_hs3x_hostlink.dts new file mode 100644 index 000000000000..057adc016e5c --- /dev/null +++ b/boards/arc/nsim/nsim_hs3x_hostlink.dts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023, Synopsys Inc. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; + +#include "nsim.dtsi" +#include "nsim-ccm-mem.dtsi" +#include "nsim-uart-hostlink.dtsi" + +/ { + model = "snps,nsim_hs"; + compatible = "snps,nsim_hs"; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu@0 { + device_type = "cpu"; + compatible = "snps,archs"; + reg = <0>; + }; + }; +}; diff --git a/boards/arc/nsim/nsim_hs3x_hostlink.yaml b/boards/arc/nsim/nsim_hs3x_hostlink.yaml new file mode 100644 index 000000000000..4c7d60f42f5d --- /dev/null +++ b/boards/arc/nsim/nsim_hs3x_hostlink.yaml @@ -0,0 +1,14 @@ +identifier: nsim_hs3x_hostlink +name: HS3x nSIM simulator +type: sim +simulation: nsim +simulation_exec: nsimdrv +arch: arc +toolchain: + - zephyr + - cross-compile + - arcmwdt +testing: + ignore_tags: + - net + - bluetooth diff --git a/boards/arc/nsim/nsim_hs3x_hostlink_defconfig b/boards/arc/nsim/nsim_hs3x_hostlink_defconfig new file mode 100644 index 000000000000..92ca6763a598 --- /dev/null +++ b/boards/arc/nsim/nsim_hs3x_hostlink_defconfig @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_NSIM=y +CONFIG_SOC_NSIM_HS=y +CONFIG_BOARD_NSIM=y +CONFIG_SYS_CLOCK_TICKS_PER_SEC=100 +CONFIG_XIP=n +CONFIG_BUILD_OUTPUT_BIN=n +CONFIG_ARCV2_INTERRUPT_UNIT=y +CONFIG_ARCV2_TIMER=y +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y +CONFIG_SERIAL=y +CONFIG_ARC_EXCEPTION_DEBUG=y +CONFIG_ARC_MPU_ENABLE=y diff --git a/boards/arc/nsim/nsim_hs5x.dts b/boards/arc/nsim/nsim_hs5x.dts index ec4baf12ba39..4ea66398a3d5 100644 --- a/boards/arc/nsim/nsim_hs5x.dts +++ b/boards/arc/nsim/nsim_hs5x.dts @@ -8,6 +8,7 @@ #include "nsim.dtsi" #include "nsim-flat-mem.dtsi" +#include "nsim-uart-ns16550.dtsi" / { model = "snps,nsim_hs"; diff --git a/boards/arc/nsim/nsim_hs6x.dts b/boards/arc/nsim/nsim_hs6x.dts index eb574e019490..136fc8c7a19d 100644 --- a/boards/arc/nsim/nsim_hs6x.dts +++ b/boards/arc/nsim/nsim_hs6x.dts @@ -8,6 +8,7 @@ #include "nsim.dtsi" #include "nsim-flat-mem.dtsi" +#include "nsim-uart-ns16550.dtsi" / { model = "snps,nsim_hs"; diff --git a/boards/arc/nsim/nsim_hs_flash_xip.dts b/boards/arc/nsim/nsim_hs_flash_xip.dts index 4a82ec64ffb5..b53aebd03ea2 100644 --- a/boards/arc/nsim/nsim_hs_flash_xip.dts +++ b/boards/arc/nsim/nsim_hs_flash_xip.dts @@ -8,6 +8,7 @@ #include "nsim.dtsi" #include "nsim-flash-sram-mem.dtsi" +#include "nsim-uart-ns16550.dtsi" / { model = "snps,nsim_hs"; diff --git a/boards/arc/nsim/nsim_hs_mpuv6.dts b/boards/arc/nsim/nsim_hs_mpuv6.dts index b58f92f046a4..86a1994d0f76 100644 --- a/boards/arc/nsim/nsim_hs_mpuv6.dts +++ b/boards/arc/nsim/nsim_hs_mpuv6.dts @@ -8,6 +8,7 @@ #include "nsim.dtsi" #include "nsim-ccm-mem.dtsi" +#include "nsim-uart-ns16550.dtsi" / { model = "snps,nsim_hs"; diff --git a/boards/arc/nsim/nsim_hs_sram.dts b/boards/arc/nsim/nsim_hs_sram.dts index a8a8115667fe..0f836a78e686 100644 --- a/boards/arc/nsim/nsim_hs_sram.dts +++ b/boards/arc/nsim/nsim_hs_sram.dts @@ -8,6 +8,7 @@ #include "nsim.dtsi" #include "nsim-flat-mem.dtsi" +#include "nsim-uart-ns16550.dtsi" / { model = "snps,nsim_hs"; diff --git a/boards/arc/nsim/support/mdb_hs3x_hostlink.args b/boards/arc/nsim/support/mdb_hs3x_hostlink.args new file mode 100644 index 000000000000..322ab33998aa --- /dev/null +++ b/boards/arc/nsim/support/mdb_hs3x_hostlink.args @@ -0,0 +1,44 @@ + -arcv2hs + -core2 + -arcnum=3 + -rgf_num_banks=2 + -rgf_banked_regs=32 + -rgf_num_wr_ports=2 + -Xatomic + -Xll64 + -Xunaligned + -Xcode_density + -Xdiv_rem=radix4 + -Xswap + -Xbitscan + -Xmpy_option=qmpyh + -Xshift_assist + -Xbarrel_shifter + -Xfpud_div + -Xfpu_mac + -Xtimer0 + -Xtimer0_level=1 + -Xtimer1 + -Xtimer1_level=0 + -Xrtc + -action_points=8 + -Xstack_check + -interrupts=72 + -interrupt_priorities=2 + -ext_interrupts=70 + -firq + -interrupt_base=0x0 + -dcache=65536,64,2,a + -dcache_feature=2 + -dcache_uncached_region + -dcache_mem_cycles=2 + -icache=65536,64,4,a + -icache_feature=2 + -dccm_size=0x40000 + -dccm_base=0x80000000 + -dccm_mem_cycles=2 + -iccm0_size=0x40000 + -iccm0_base=0x70000000 + -mpuv3 + -mpu_regions=16 + -noprofile diff --git a/boards/arc/nsim/support/nsim_hs3x_hostlink.props b/boards/arc/nsim/support/nsim_hs3x_hostlink.props new file mode 100644 index 000000000000..f3cc662c9909 --- /dev/null +++ b/boards/arc/nsim/support/nsim_hs3x_hostlink.props @@ -0,0 +1,47 @@ + nsim_isa_family=av2hs + nsim_isa_core=2 + arcver=0x52 + nsim_isa_rgf_num_banks=2 + nsim_isa_rgf_banked_regs=32 + nsim_isa_rgf_num_regs=32 + nsim_isa_rgf_num_wr_ports=2 + nsim_isa_big_endian=0 + nsim_isa_lpc_size=32 + nsim_isa_pc_size=32 + nsim_isa_addr_size=32 + nsim_isa_atomic_option=1 + nsim_isa_ll64_option=1 + nsim_isa_unaligned_option=1 + nsim_isa_code_density_option=2 + nsim_isa_div_rem_option=2 + nsim_isa_swap_option=1 + nsim_isa_bitscan_option=1 + nsim_isa_mpy_option=9 + nsim_isa_shift_option=3 + nsim_isa_fpud_div_option=1 + nsim_isa_fpu_mac_option=1 + nsim_isa_enable_timer_0=1 + nsim_isa_timer_0_int_level=1 + nsim_isa_enable_timer_1=1 + nsim_isa_timer_1_int_level=0 + nsim_isa_rtc_option=1 + nsim_isa_num_actionpoints=8 + nsim_isa_stack_checking=1 + nsim_isa_number_of_interrupts=72 + nsim_isa_number_of_levels=2 + nsim_isa_number_of_external_interrupts=70 + nsim_isa_fast_irq=1 + nsim_isa_intvbase_preset=0x0 + dcache=65536,64,2,a + nsim_isa_dc_feature_level=2 + nsim_isa_dc_uncached_region=1 + nsim_isa_dc_mem_cycles=2 + icache=65536,64,4,a + nsim_isa_ic_feature_level=2 + dccm_size=0x40000 + dccm_base=0x80000000 + nsim_isa_dccm_mem_cycles=2 + iccm0_size=0x40000 + iccm0_base=0x70000000 + mpu_regions=16 + mpu_version=3 From 6599c3796d8218defde779307d4643440eaf2f1a Mon Sep 17 00:00:00 2001 From: Evgeniy Paltsev Date: Thu, 16 Mar 2023 19:16:35 +0000 Subject: [PATCH 0331/1906] west: runners: mdb-hw: add hostlink-awareness Add hostlink-awareness to mdb-hw runner. The mdb-nsim and arc-nsim runners (as well as cmake scripting for nSIM boards) doesn't require any changes. Signed-off-by: Eugeniy Paltsev Signed-off-by: Evgeniy Paltsev --- scripts/west_commands/runners/mdb.py | 33 +++++--- scripts/west_commands/tests/test_mdb.py | 108 +++++++++++++++++++----- 2 files changed, 111 insertions(+), 30 deletions(-) diff --git a/scripts/west_commands/runners/mdb.py b/scripts/west_commands/runners/mdb.py index c2e60441a8d4..a25f6fb179b7 100644 --- a/scripts/west_commands/runners/mdb.py +++ b/scripts/west_commands/runners/mdb.py @@ -17,16 +17,29 @@ # from it. However as we do lookup for runners with # ZephyrBinaryRunner.__subclasses__() such sub-sub-classes won't be found. # So, we move all common functionality to helper functions instead. -def simulation_run(mdb_runner): +def is_simulation_run(mdb_runner): return mdb_runner.nsim_args != '' +def is_hostlink_used(mdb_runner): + return mdb_runner.build_conf.getboolean('CONFIG_UART_HOSTLINK') + +def is_flash_cmd_need_exit_immediately(mdb_runner): + if is_simulation_run(mdb_runner): + # for nsim, we can't run and quit immediately + return False + elif is_hostlink_used(mdb_runner): + # if hostlink is used we can't run and quit immediately, as we still need MDB process + # attached to process hostlink IO + return False + else: + return True + def mdb_do_run(mdb_runner, command): commander = "mdb" mdb_runner.require(commander) - mdb_basic_options = ['-nooptions', '-nogoifmain', - '-toggle=include_local_symbols=1'] + mdb_basic_options = ['-nooptions', '-nogoifmain', '-toggle=include_local_symbols=1'] # remove previous .sc.project folder which has temporary settings # for MDB. This is useful for troubleshooting situations with @@ -36,7 +49,7 @@ def mdb_do_run(mdb_runner, command): shutil.rmtree(mdb_cfg_dir) # nsim - if simulation_run(mdb_runner): + if is_simulation_run(mdb_runner): mdb_target = ['-nsim', '@' + mdb_runner.nsim_args] # hardware target else: @@ -48,19 +61,17 @@ def mdb_do_run(mdb_runner, command): raise ValueError('unsupported jtag adapter {}'.format(mdb_runner.jtag)) if command == 'flash': - if simulation_run(mdb_runner): - # for nsim , can't run and quit immediately - mdb_run = ['-run', '-cl'] - else: + if is_flash_cmd_need_exit_immediately(mdb_runner): mdb_run = ['-run', '-cmd=-nowaitq run', '-cmd=quit', '-cl'] + else: + mdb_run = ['-run', '-cl'] elif command == 'debug': # use mdb gui to debug mdb_run = ['-OKN'] if mdb_runner.cores == 1: # single core's mdb command is different with multicores - mdb_cmd = ([commander] + mdb_basic_options + mdb_target + - mdb_run + [mdb_runner.elf_name]) + mdb_cmd = [commander] + mdb_basic_options + mdb_target + mdb_run + [mdb_runner.elf_name] elif 1 < mdb_runner.cores <= 4: mdb_multifiles = '-multifiles=' for i in range(mdb_runner.cores): @@ -74,7 +85,7 @@ def mdb_do_run(mdb_runner, command): # to enable multi-core aware mode for use with the MetaWare debugger, # need to set the NSIM_MULTICORE environment variable to a non-zero value - if simulation_run(mdb_runner): + if is_simulation_run(mdb_runner): os.environ["NSIM_MULTICORE"] = '1' mdb_cmd = [commander] + [mdb_multifiles] + mdb_run diff --git a/scripts/west_commands/tests/test_mdb.py b/scripts/west_commands/tests/test_mdb.py index b6b9c7a9f5f0..eb7252c99640 100644 --- a/scripts/west_commands/tests/test_mdb.py +++ b/scripts/west_commands/tests/test_mdb.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 import argparse -from os import path +from os import path, fspath from unittest.mock import patch from unittest.mock import call @@ -18,6 +18,15 @@ TEST_TARGET = 'test-target' TEST_BOARD_NSIM_ARGS = '@' + path.join(RC_BOARD_DIR, 'support', TEST_NSIM_ARGS) +DOTCONFIG_HOSTLINK = f''' +CONFIG_ARC=y +CONFIG_UART_HOSTLINK=y +''' + +DOTCONFIG_NO_HOSTLINK = f''' +CONFIG_ARC=y +''' + # mdb-nsim TEST_NSIM_FLASH_CASES = [ { @@ -50,7 +59,7 @@ '-run', '-cl'] # mdb-hw -TEST_HW_FLASH_CASES = [ +TEST_HW_FLASH_CASES_NO_HOSTLINK = [ { 'i': ['--jtag=digilent', '--cores=1'], 'o': [TEST_DRIVER_CMD, '-nooptions', '-nogoifmain', @@ -65,6 +74,19 @@ '-run', '-cmd=-nowaitq run', '-cmd=quit', '-cl', RC_KERNEL_ELF] }] +TEST_HW_FLASH_CASES_HOSTLINK = [ + { + 'i': ['--jtag=digilent', '--cores=1'], + 'o': [TEST_DRIVER_CMD, '-nooptions', '-nogoifmain', + '-toggle=include_local_symbols=1', + '-digilent', '-run', '-cl', RC_KERNEL_ELF] + }, { + 'i': ['--jtag=digilent', '--cores=1', '--dig-device=test'], + 'o': [TEST_DRIVER_CMD, '-nooptions', '-nogoifmain', + '-toggle=include_local_symbols=1', + '-digilent', '-prop=dig_device=test', '-run', '-cl', RC_KERNEL_ELF] + }] + TEST_HW_FLASH_CASES_ERR = [ { 'i': ['--jtag=test_debug', '--cores=1'], @@ -106,8 +128,23 @@ '-prop=download=2', '-nooptions', '-nogoifmain', '-toggle=include_local_symbols=1', '-digilent', RC_KERNEL_ELF] -TEST_HW_CORES_LAUNCH = [TEST_DRIVER_CMD, '-multifiles=core1,core0', '-run', +TEST_HW_CORES_LAUNCH_NO_HOSTLINK = [TEST_DRIVER_CMD, '-multifiles=core1,core0', '-run', '-cmd=-nowaitq run', '-cmd=quit', '-cl'] +TEST_HW_CORES_LAUNCH_HOSTLINK = [TEST_DRIVER_CMD, '-multifiles=core1,core0', '-run', '-cl'] + + +def adjust_runner_config(runner_config, tmpdir, dotconfig): + # Adjust a RunnerConfig object, 'runner_config', by + # replacing its build directory with 'tmpdir' after writing + # the contents of 'dotconfig' to tmpdir/zephyr/.config. + + zephyr = tmpdir / 'zephyr' + zephyr.mkdir() + with open(zephyr / '.config', 'w') as f: + f.write(dotconfig) + + print("" + fspath(tmpdir)) + return runner_config._replace(build_dir=fspath(tmpdir)) # # Fixtures @@ -139,7 +176,13 @@ def mdb_nsim(runner_config, tmpdir): return mdb(runner_config, tmpdir, MdbNsimBinaryRunner) @pytest.fixture -def mdb_hw(runner_config, tmpdir): +def mdb_hw_no_hl(runner_config, tmpdir): + runner_config = adjust_runner_config(runner_config, tmpdir, DOTCONFIG_NO_HOSTLINK) + return mdb(runner_config, tmpdir, MdbHwBinaryRunner) + +@pytest.fixture +def mdb_hw_hl(runner_config, tmpdir): + runner_config = adjust_runner_config(runner_config, tmpdir, DOTCONFIG_HOSTLINK) return mdb(runner_config, tmpdir, MdbHwBinaryRunner) # @@ -183,37 +226,53 @@ def test_multicores_nsim(require, pii, cc, test_case, mdb_nsim): # mdb-hw test cases -@pytest.mark.parametrize('test_case', TEST_HW_FLASH_CASES) +@pytest.mark.parametrize('test_case', TEST_HW_FLASH_CASES_NO_HOSTLINK) @patch('runners.mdb.MdbHwBinaryRunner.call') @patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch) -def test_flash_hw(require, cc, test_case, mdb_hw): - mdb_hw(test_case['i']).run('flash') +def test_flash_hw_no_hl(require, cc, test_case, mdb_hw_no_hl, tmpdir): + mdb_hw_no_hl(test_case['i']).run('flash') assert require.called - cc.assert_called_once_with(test_case['o'], cwd=RC_BUILD_DIR) + cc.assert_called_once_with(test_case['o'], cwd=tmpdir) + +@pytest.mark.parametrize('test_case', TEST_HW_FLASH_CASES_HOSTLINK) +@patch('runners.mdb.MdbHwBinaryRunner.call') +@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch) +def test_flash_hw_hl(require, cc, test_case, mdb_hw_hl, tmpdir): + mdb_hw_hl(test_case['i']).run('flash') + assert require.called + cc.assert_called_once_with(test_case['o'], cwd=tmpdir) @pytest.mark.parametrize('test_case', TEST_HW_FLASH_CASES_ERR) @patch('runners.mdb.MdbHwBinaryRunner.call') @patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch) -def test_flash_hw_err(require, cc, test_case, mdb_hw): +def test_flash_hw_err(require, cc, test_case, mdb_hw_no_hl): with pytest.raises(ValueError) as rinfo: - mdb_hw(test_case['i']).run('flash') + mdb_hw_no_hl(test_case['i']).run('flash') assert str(rinfo.value) == test_case['e'] @pytest.mark.parametrize('test_case', TEST_HW_DEBUG_CASES) @patch('runners.mdb.MdbHwBinaryRunner.call') @patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch) -def test_debug_hw(require, pii, test_case, mdb_hw): - mdb_hw(test_case['i']).run('debug') +def test_debug_hw(require, pii, test_case, mdb_hw_no_hl, tmpdir): + mdb_hw_no_hl(test_case['i']).run('debug') assert require.called - pii.assert_called_once_with(test_case['o'], cwd=RC_BUILD_DIR) + pii.assert_called_once_with(test_case['o'], cwd=tmpdir) + +@pytest.mark.parametrize('test_case', TEST_HW_DEBUG_CASES) +@patch('runners.mdb.MdbHwBinaryRunner.call') +@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch) +def test_debug_hw_hl(require, pii, test_case, mdb_hw_hl, tmpdir): + mdb_hw_hl(test_case['i']).run('debug') + assert require.called + pii.assert_called_once_with(test_case['o'], cwd=tmpdir) @pytest.mark.parametrize('test_case', TEST_HW_DEBUG_CASES_ERR) @patch('runners.mdb.MdbHwBinaryRunner.call') @patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch) -def test_debug_hw_err(require, pii, test_case, mdb_hw): +def test_debug_hw_err(require, pii, test_case, mdb_hw_no_hl): with pytest.raises(ValueError) as rinfo: - mdb_hw(test_case['i']).run('debug') + mdb_hw_no_hl(test_case['i']).run('debug') assert str(rinfo.value) == test_case['e'] @@ -221,9 +280,20 @@ def test_debug_hw_err(require, pii, test_case, mdb_hw): @patch('runners.mdb.MdbHwBinaryRunner.check_call') @patch('runners.mdb.MdbHwBinaryRunner.call') @patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch) -def test_multicores_hw(require, pii, cc, test_case, mdb_hw): - mdb_hw(test_case).run('flash') +def test_multicores_hw_no_hl(require, pii, cc, test_case, mdb_hw_no_hl, tmpdir): + mdb_hw_no_hl(test_case).run('flash') + assert require.called + cc_calls = [call(TEST_HW_CORE1, cwd=tmpdir), call(TEST_HW_CORE2, cwd=tmpdir)] + cc.assert_has_calls(cc_calls) + pii.assert_called_once_with(TEST_HW_CORES_LAUNCH_NO_HOSTLINK, cwd=tmpdir) + +@pytest.mark.parametrize('test_case', TEST_HW_MULTICORE_CASES) +@patch('runners.mdb.MdbHwBinaryRunner.check_call') +@patch('runners.mdb.MdbHwBinaryRunner.call') +@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch) +def test_multicores_hw_hl(require, pii, cc, test_case, mdb_hw_hl, tmpdir): + mdb_hw_hl(test_case).run('flash') assert require.called - cc_calls = [call(TEST_HW_CORE1, cwd=RC_BUILD_DIR), call(TEST_HW_CORE2, cwd=RC_BUILD_DIR)] + cc_calls = [call(TEST_HW_CORE1, cwd=tmpdir), call(TEST_HW_CORE2, cwd=tmpdir)] cc.assert_has_calls(cc_calls) - pii.assert_called_once_with(TEST_HW_CORES_LAUNCH, cwd=RC_BUILD_DIR) + pii.assert_called_once_with(TEST_HW_CORES_LAUNCH_HOSTLINK, cwd=tmpdir) From b652c8d3dd3dbe1816770f37cae9e10e116ece78 Mon Sep 17 00:00:00 2001 From: Ingar Kulbrandstad Date: Tue, 14 Mar 2023 17:23:19 +0100 Subject: [PATCH 0332/1906] Doc: Bluetooth: Mesh: Added shell remote provisioning documentation Add description all shell commands related to remote provisioning. Signed-off-by: Ingar Kulbrandstad --- doc/connectivity/bluetooth/api/mesh/shell.rst | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/doc/connectivity/bluetooth/api/mesh/shell.rst b/doc/connectivity/bluetooth/api/mesh/shell.rst index cd7454592fd9..f4a5fb7fe760 100644 --- a/doc/connectivity/bluetooth/api/mesh/shell.rst +++ b/doc/connectivity/bluetooth/api/mesh/shell.rst @@ -1475,6 +1475,92 @@ The Opcodes Aggregator client is an optional Bluetooth mesh model that can be en Abort the Opcodes Aggregator Sequence message. This command clears the Opcodes Aggregator Client context. +Remote Provisioning Client +-------------------------- + +The Remote Provisioning Client is an optional Bluetooth mesh model enabled through the :kconfig:option:`CONFIG_BT_MESH_RPR_CLI` configuration option. The Remote Provisioning Client model provides support for remote provisioning of devices into a mesh network by using the Remote Provisioning Server model. + +This shell module can be used to trigger interaction between Remote Provisioning Clients and Remote Provisioning Servers on devices in a mesh network. + +``mesh models rpr scan []`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Start scanning for unprovisioned devices. + + * ``timeout in seconds``: Scan timeout in seconds. Must be at least 1 second. + * ``UUID``: Device UUID to scan for. If omitted, all devices will be reported. + +``mesh models rpr scan-ext [ ... ]`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Start the extended scanning for unprovisioned devices. + + * ``timeout in seconds``: Scan timeout in seconds. Valid values from :c:macro:`BT_MESH_RPR_EXT_SCAN_TIME_MIN` to :c:macro:`BT_MESH_RPR_EXT_SCAN_TIME_MAX`. + * ``UUID``: Device UUID to start extended scanning for. + * ``AD-type``: List of AD types to include in the scan report. Must contain 1 to :kconfig:option:`CONFIG_BT_MESH_RPR_AD_TYPES_MAX` entries. + +``mesh models rpr scan-srv [ ... ]`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Start the extended scanning for the Remote Provisioning Server. + + * ``AD-type``: List of AD types to include in the scan report. Must contain 1 to :kconfig:option:`CONFIG_BT_MESH_RPR_AD_TYPES_MAX` entries. + +``mesh models rpr scan-caps`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Get the scanning capabilities of the Remote Provisioning Server. + +``mesh models rpr scan-get`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Get the current scanning state of the Remote Provisioning Server. + +``mesh models rpr scan-stop`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Stop any ongoing scanning on the Remote Provisioning Server. + +``mesh models rpr link-get`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Get the current link status of the Remote Provisioning Server. + +``mesh models rpr link-close`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Close any open links on the Remote Provisioning Server. + +``mesh models rpr provision-remote `` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Provision a mesh node using the PB-Remote provisioning bearer. + + * ``UUID``: UUID of the unprovisioned node. + * ``NetKeyIndex``: Network Key Index to give to the unprovisioned node. + * ``addr``: Address to assign to remote device. If ``addr`` is 0, the lowest available address will be chosen. + +``mesh models rpr reprovision-remote []`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Reprovision a mesh node using the PB-Remote provisioning bearer. + + * ``addr``: Address to assign to remote device. If ``addr`` is 0, the lowest available address will be chosen. + * ``comp changed``: The Target node has indicated that its Composition Data has changed. Defaults to false. + +``mesh models rpr instance-set `` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Use the Remote Provisioning Client model instance on the specified element when using the other Remote Provisioning Client model commands. + + * ``elem_idx``: The element on which to find the Remote Provisioning Client model instance to use. + +``mesh models rpr instance-get-all`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Get a list of all Remote Provisioning Client model instances on the node. + + Configuration database ====================== From f9d0e3837625bee9c3a58e60b5e6239dae8b26bb Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 16 Mar 2023 11:01:45 +0000 Subject: [PATCH 0333/1906] cmake: Throw error if no prj.conf file is in the app config dir This now throws an error if there is no prj.conf file located in a user-specified APPLICATION_CONFIG_DIR, which otherwise would have used an empty configuration and not included board-specific files. Signed-off-by: Jamie McCrae --- cmake/modules/configuration_files.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/modules/configuration_files.cmake b/cmake/modules/configuration_files.cmake index 39a7760dd536..5ed9777816b0 100644 --- a/cmake/modules/configuration_files.cmake +++ b/cmake/modules/configuration_files.cmake @@ -67,10 +67,12 @@ elseif(CACHED_CONF_FILE) set(CONF_FILE ${CACHED_CONF_FILE}) elseif(EXISTS ${APPLICATION_CONFIG_DIR}/prj_${BOARD}.conf) set(CONF_FILE ${APPLICATION_CONFIG_DIR}/prj_${BOARD}.conf) - elseif(EXISTS ${APPLICATION_CONFIG_DIR}/prj.conf) set(CONF_FILE ${APPLICATION_CONFIG_DIR}/prj.conf) set(CONF_FILE_INCLUDE_FRAGMENTS true) +else() + message(FATAL_ERROR "No prj.conf file was found in the ${APPLICATION_CONFIG_DIR} folder, " + "please read the Zephyr documentation on application development.") endif() if(CONF_FILE_INCLUDE_FRAGMENTS) From e534da007d61a932bc1ef1f337aeb4c6c079f89b Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 16 Mar 2023 11:35:50 +0000 Subject: [PATCH 0334/1906] samples/tests: Add empty prj.conf files Adds empty prj.conf files as this file is required to configure a build. Signed-off-by: Jamie McCrae --- boards/arm/mps2_an521/empty_cpu0/prj.conf | 1 + samples/application_development/sysbuild/with_mcuboot/prj.conf | 1 + samples/boards/arc_secure_services/prj.conf | 1 + tests/misc/test_build/prj.conf | 1 + 4 files changed, 4 insertions(+) create mode 100644 boards/arm/mps2_an521/empty_cpu0/prj.conf create mode 100644 samples/application_development/sysbuild/with_mcuboot/prj.conf create mode 100644 samples/boards/arc_secure_services/prj.conf create mode 100644 tests/misc/test_build/prj.conf diff --git a/boards/arm/mps2_an521/empty_cpu0/prj.conf b/boards/arm/mps2_an521/empty_cpu0/prj.conf new file mode 100644 index 000000000000..932b79829cf3 --- /dev/null +++ b/boards/arm/mps2_an521/empty_cpu0/prj.conf @@ -0,0 +1 @@ +# Empty file diff --git a/samples/application_development/sysbuild/with_mcuboot/prj.conf b/samples/application_development/sysbuild/with_mcuboot/prj.conf new file mode 100644 index 000000000000..932b79829cf3 --- /dev/null +++ b/samples/application_development/sysbuild/with_mcuboot/prj.conf @@ -0,0 +1 @@ +# Empty file diff --git a/samples/boards/arc_secure_services/prj.conf b/samples/boards/arc_secure_services/prj.conf new file mode 100644 index 000000000000..932b79829cf3 --- /dev/null +++ b/samples/boards/arc_secure_services/prj.conf @@ -0,0 +1 @@ +# Empty file diff --git a/tests/misc/test_build/prj.conf b/tests/misc/test_build/prj.conf new file mode 100644 index 000000000000..932b79829cf3 --- /dev/null +++ b/tests/misc/test_build/prj.conf @@ -0,0 +1 @@ +# Empty file From 4b5bbb29028a6406a8c3cd86f31ab5c2e274d76e Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 16 Mar 2023 11:43:10 +0000 Subject: [PATCH 0335/1906] docs: build system: Update note that prj.conf file is needed Adds a note that this file is mandatory. Signed-off-by: Jamie McCrae --- doc/build/kconfig/setting.rst | 4 ++-- doc/develop/application/index.rst | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/build/kconfig/setting.rst b/doc/build/kconfig/setting.rst index e3180edf755d..1e8b20cba8ae 100644 --- a/doc/build/kconfig/setting.rst +++ b/doc/build/kconfig/setting.rst @@ -165,8 +165,8 @@ The application configuration can come from the sources below. By default, configuration directory, the result of merging it with :file:`prj.conf` and :file:`boards/.conf` is used. -6. Otherwise, :file:`prj.conf` is used if it exists in the application - configuration directory +6. Otherwise, :file:`prj.conf` is used from the application configuration + directory. If it does not exist then a fatal error will be emitted. All configuration files will be taken from the application's configuration directory except for files with an absolute path that are given with the diff --git a/doc/develop/application/index.rst b/doc/develop/application/index.rst index d4f258d00602..f7cc5c72a93a 100644 --- a/doc/develop/application/index.rst +++ b/doc/develop/application/index.rst @@ -357,7 +357,8 @@ Zephyr's :ref:`samples-and-demos` as a starting point is likely to be easier. #. Create at least one Kconfig fragment for your application (usually named :file:`prj.conf`) and set Kconfig option values needed by your application - there. See :ref:`application-kconfig`. + there. See :ref:`application-kconfig`. If no Kconfig options need to be set, + create an empty file. #. Configure any devicetree overlays needed by your application, usually in a file named :file:`app.overlay`. See :ref:`set-devicetree-overlays`. From 6d4e31d3f14afffa0d8bfc77cc69a6b279427da7 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 16 Mar 2023 11:44:01 +0000 Subject: [PATCH 0336/1906] docs: release: 3.4: Add note on prj.conf requirement Adds a note that the prj.conf (or equivalent) file is mandatory for applications. Signed-off-by: Jamie McCrae --- doc/releases/release-notes-3.4.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/releases/release-notes-3.4.rst b/doc/releases/release-notes-3.4.rst index 4692a23f1c6a..8e22e0d138e0 100644 --- a/doc/releases/release-notes-3.4.rst +++ b/doc/releases/release-notes-3.4.rst @@ -217,6 +217,10 @@ Build system and infrastructure * Fixed an issue whereby building an application with sysbuild and specifying mcuboot's verification to be checksum only did not build a bootable image. +* Fixed an issue whereby if no prj.conf file was present then board + configuration files would not be included by emitting a fatal error. As a + result, prj.conf files are now mandatory in projects. + Drivers and Sensors ******************* From 4a176977770a4d92e4238c536c73fae59b5d542c Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Thu, 16 Mar 2023 16:04:19 +0000 Subject: [PATCH 0337/1906] mailmap: add two fixes for bad commits Make sure we count the same people once and show them as one contributor. Signed-off-by: Anas Nashif --- .mailmap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.mailmap b/.mailmap index 7078a163b224..dddc3965f09b 100644 --- a/.mailmap +++ b/.mailmap @@ -33,3 +33,5 @@ Sean Nyekjaer Marc Herbert <46978960+marc-hb@users.noreply.github.com> Martin Jäger <17674105+martinjaeger@users.noreply.github.com> Armand Ciejak +Chunlin Han +chao an From d0b0bb43d3104ce8f21edacffac78da41427efb8 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Fri, 17 Mar 2023 10:51:11 +0100 Subject: [PATCH 0338/1906] Bluetooth: BAP: Remove BT_BAP_UNICAST_CLIENT_PAC_COUNT The BT_BAP_UNICAST_CLIENT_PAC_COUNT is there due to a merge conflict gone wrong. Removed again. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/Kconfig.bap | 8 -------- 1 file changed, 8 deletions(-) diff --git a/subsys/bluetooth/audio/Kconfig.bap b/subsys/bluetooth/audio/Kconfig.bap index be0b1a0872e2..c07e044e8cf7 100644 --- a/subsys/bluetooth/audio/Kconfig.bap +++ b/subsys/bluetooth/audio/Kconfig.bap @@ -91,14 +91,6 @@ config BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT Since BAP streams are unidirectional, two BAP streams may use a single CIS, the number of BAP audio streams per group may be up to twice of this value. -config BT_BAP_UNICAST_CLIENT_PAC_COUNT - int "Basic Audio Profile PAC count" - default 2 - range 0 146 - help - This option enables caching a number of Published Audio Capabilities - (PAC) for Basic Audio Profile on a per connection basis. - config BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT int "Basic Audio Profile ASE Sink count" default 2 From e5091db1ad44c26fa9300cfd462351f07b9d0863 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Fri, 17 Mar 2023 10:53:05 +0200 Subject: [PATCH 0339/1906] bluetooth: audio: Fix using wrong function check Correct function check before calling it. Signed-off-by: Andrei Emeltchenko --- subsys/bluetooth/audio/bap_unicast_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index aed239539282..fcec2eb4bf9c 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -1354,7 +1354,7 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn, client_ep->release_requested = false; } - if (unicast_client_cbs->config != NULL) { + if (unicast_client_cbs->release != NULL) { unicast_client_cbs->release(stream, ase_rsp->code, ase_rsp->reason); } break; From cf5ea49d232340ec01a711e87d7d783b3c09e56d Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Thu, 16 Mar 2023 16:29:08 +0100 Subject: [PATCH 0340/1906] Bluetooth: Mesh: Fix registering GATT Proxy service after reboot After commit https://github.com/zephyrproject-rtos/zephyr/commit/3486f133e9dcfc48e0291b9a31fdbdc9af2f5f09 GATT Proxy service registration is broken because it is registered from settings_load() in mesh_commit(). Because mesh_commit() is called before sc_commit() is called in gatt.c, bt_gatt_service_register() can't be called yet. Use k_work to postpone the service registration. Signed-off-by: Pavel Vasilyev --- subsys/bluetooth/mesh/main.c | 1 - subsys/bluetooth/mesh/proxy_srv.c | 29 +++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/subsys/bluetooth/mesh/main.c b/subsys/bluetooth/mesh/main.c index 35aa313c0b0c..9381a00857e6 100644 --- a/subsys/bluetooth/mesh/main.c +++ b/subsys/bluetooth/mesh/main.c @@ -525,7 +525,6 @@ int bt_mesh_start(void) if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { (void)bt_mesh_proxy_gatt_enable(); - bt_mesh_adv_gatt_update(); } } diff --git a/subsys/bluetooth/mesh/proxy_srv.c b/subsys/bluetooth/mesh/proxy_srv.c index 74712973e061..45276224fb48 100644 --- a/subsys/bluetooth/mesh/proxy_srv.c +++ b/subsys/bluetooth/mesh/proxy_srv.c @@ -875,10 +875,24 @@ static struct bt_gatt_attr proxy_attrs[] = { static struct bt_gatt_service proxy_svc = BT_GATT_SERVICE(proxy_attrs); -int bt_mesh_proxy_gatt_enable(void) +static void svc_reg_work_handler(struct k_work *work) { - int i; + (void)bt_gatt_service_register(&proxy_svc); + service_registered = true; + + for (int i = 0; i < ARRAY_SIZE(clients); i++) { + if (clients[i].cli) { + clients[i].filter_type = ACCEPT; + } + } + + bt_mesh_adv_gatt_update(); +} + +static struct k_work svc_reg_work = Z_WORK_INITIALIZER(svc_reg_work_handler); +int bt_mesh_proxy_gatt_enable(void) +{ LOG_DBG(""); if (!bt_mesh_is_provisioned()) { @@ -889,16 +903,7 @@ int bt_mesh_proxy_gatt_enable(void) return -EBUSY; } - (void)bt_gatt_service_register(&proxy_svc); - service_registered = true; - - for (i = 0; i < ARRAY_SIZE(clients); i++) { - if (clients[i].cli) { - clients[i].filter_type = ACCEPT; - } - } - - return 0; + return k_work_submit(&svc_reg_work); } void bt_mesh_proxy_gatt_disconnect(void) From 70e4e7399832f67fead955b0e748fb38187dc775 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 16 Mar 2023 10:29:33 +0100 Subject: [PATCH 0341/1906] Bluetooth: BAP: Shell: Fix problems with codec and qos config The copying from the presets to the stream codec and qos structs were not done in a way that worked. Fixed by doing a more proper and deeper copy. This also fixes a small issue with using the wrong default preset. Signed-off-by: Emil Gydesen --- subsys/bluetooth/shell/bap.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/shell/bap.c b/subsys/bluetooth/shell/bap.c index 6da04ec48be3..72d4fb77b73b 100644 --- a/subsys/bluetooth/shell/bap.c +++ b/subsys/bluetooth/shell/bap.c @@ -995,14 +995,14 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) } else if (!strcmp(argv[1], "sink")) { ep = snks[index]; - named_preset = default_source_preset; + named_preset = default_sink_preset; #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 */ #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 } else if (!strcmp(argv[1], "source")) { ep = srcs[index]; - named_preset = default_sink_preset; + named_preset = default_source_preset; #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 */ } else { shell_error(sh, "Unsupported dir: %s", argv[1]); @@ -1057,6 +1057,10 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) return SHELL_CMD_HELP_PRINTED; } + } else { + shell_help(sh); + + return SHELL_CMD_HELP_PRINTED; } } @@ -1064,16 +1068,25 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) memcpy(&uni_stream->qos, &named_preset->preset.qos, sizeof(uni_stream->qos)); memcpy(&uni_stream->codec, &named_preset->preset.codec, sizeof(uni_stream->codec)); /* Need to update the `bt_data.data` pointer to the new value after copying the codec */ + /* Need to copy from the data pointer, as the preset->value is empty, as they are defined as + * compound literals + */ for (size_t i = 0U; i < ARRAY_SIZE(uni_stream->codec.data); i++) { + const struct bt_codec_data *preset_data = &named_preset->preset.codec.data[i]; struct bt_codec_data *data = &uni_stream->codec.data[i]; data->data.data = data->value; + data->data.data_len = preset_data->data.data_len; + memcpy(data->value, preset_data->data.data, preset_data->data.data_len); } for (size_t i = 0U; i < ARRAY_SIZE(uni_stream->codec.meta); i++) { - struct bt_codec_data *data = &uni_stream->codec.meta[i]; + const struct bt_codec_data *preset_meta = &named_preset->preset.codec.meta[i]; + struct bt_codec_data *meta = &uni_stream->codec.meta[i]; - data->data.data = data->value; + meta->data.data = meta->value; + meta->data.data_len = preset_meta->data.data_len; + memcpy(meta->value, preset_meta->data.data, preset_meta->data.data_len); } /* If location has been modifed, we update the location in the codec configuration */ From d638811be1654dee0c4354e21470508c32fa6ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Fri, 24 Feb 2023 13:14:11 +0100 Subject: [PATCH 0342/1906] tests: Bluetooth: Mesh: Test API and persistent storage of DFU slots MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tests behaviour of API (addition and deletion of slots, setting valid state, iteration through slot list). Tests if slots are correctly saved, recovered and deleted from persistent storage. Signed-off-by: Krzysztof Kopyściński --- tests/bluetooth/bsim/mesh/prj_mesh1d1.conf | 1 + tests/bluetooth/bsim/mesh/src/test_dfu.c | 184 ++++++++++++++++++ .../bsim/mesh/tests_scripts/dfu/dfu_slot.sh | 22 +++ 3 files changed, 207 insertions(+) create mode 100755 tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_slot.sh diff --git a/tests/bluetooth/bsim/mesh/prj_mesh1d1.conf b/tests/bluetooth/bsim/mesh/prj_mesh1d1.conf index 0ab9bfea131d..116215ddaa2c 100644 --- a/tests/bluetooth/bsim/mesh/prj_mesh1d1.conf +++ b/tests/bluetooth/bsim/mesh/prj_mesh1d1.conf @@ -60,6 +60,7 @@ CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y CONFIG_BT_MESH_DFU_SRV=y CONFIG_BT_MESH_DFU_CLI=y CONFIG_BT_MESH_DFD_SRV=y +CONFIG_BT_MESH_DFU_SLOT_CNT=3 # Needed for RPR tests due to huge amount of retransmitted messages CONFIG_BT_MESH_MSG_CACHE_SIZE=64 diff --git a/tests/bluetooth/bsim/mesh/src/test_dfu.c b/tests/bluetooth/bsim/mesh/src/test_dfu.c index fd22b32f467e..46283496f115 100644 --- a/tests/bluetooth/bsim/mesh/src/test_dfu.c +++ b/tests/bluetooth/bsim/mesh/src/test_dfu.c @@ -511,6 +511,184 @@ static void test_dist_dfu_self_update(void) PASS(); } +static void test_dist_dfu_slot_create(void) +{ + const struct bt_mesh_dfu_slot *slot[3]; + size_t size = 100; + uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0 }; + size_t fwid_len = 4; + uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN] = { 0 }; + size_t metadata_len = 4; + const char *uri = "test"; + int err, i; + + ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3, + "CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 3"); + + settings_test_backend_clear(); + + bt_mesh_test_cfg_set(NULL, WAIT_TIME); + bt_mesh_device_setup(&prov, &dist_comp); + dist_prov_and_conf(DIST_ADDR); + + for (i = 0; i < CONFIG_BT_MESH_DFU_SLOT_CNT; i++) { + fwid[0] = i; + metadata[0] = i; + slot[i] = bt_mesh_dfu_slot_add(size, fwid, fwid_len, metadata, metadata_len, uri, + strlen(uri)); + + ASSERT_FALSE(slot[i] == NULL, "Failed to add slot"); + } + + /* First slot is set as valid */ + err = bt_mesh_dfu_slot_valid_set(slot[0], true); + if (err) { + FAIL("Setting slot to valid state failed (err %d)", err); + return; + } + ASSERT_TRUE(bt_mesh_dfu_slot_is_valid(slot[0])); + + /* Second slot is set as invalid */ + err = bt_mesh_dfu_slot_valid_set(slot[1], false); + if (err) { + FAIL("Setting slot to invalid state failed (err %d)", err); + return; + } + ASSERT_TRUE(!bt_mesh_dfu_slot_is_valid(slot[1])); + + /* Last slot is deleted */ + err = bt_mesh_dfu_slot_del(slot[CONFIG_BT_MESH_DFU_SLOT_CNT - 1]); + if (err) { + FAIL("Slot delete failed (err %d)", err); + return; + } + + PASS(); +} + +enum bt_mesh_dfu_iter check_slot(const struct bt_mesh_dfu_slot *slot, void *data) +{ + size_t size = 100; + uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0 }; + size_t fwid_len = 4; + uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN] = { 0 }; + size_t metadata_len = 4; + const char *uri = "test"; + int idx = bt_mesh_dfu_slot_idx_get(slot); + + ASSERT_TRUE(idx >= 0, "Failed to retrieve slot index"); + + ASSERT_EQUAL(size, slot->size); + ASSERT_TRUE(strcmp(uri, slot->uri) == 0); + + fwid[0] = idx; + + ASSERT_EQUAL(fwid_len, slot->fwid_len); + ASSERT_TRUE(memcmp(fwid, slot->fwid, fwid_len) == 0); + + metadata[0] = idx; + ASSERT_EQUAL(metadata_len, slot->metadata_len); + ASSERT_TRUE(memcmp(metadata, slot->metadata, metadata_len) == 0); + + return BT_MESH_DFU_ITER_CONTINUE; +} + +static void test_dist_dfu_slot_create_recover(void) +{ + size_t slot_count; + const struct bt_mesh_dfu_slot *slot; + size_t size = 100; + uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0 }; + size_t fwid_len = 4; + uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN] = { 0 }; + size_t metadata_len = 4; + const char *uri = "test"; + int i, idx; + + ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3, + "CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 3"); + + bt_mesh_test_cfg_set(NULL, WAIT_TIME); + bt_mesh_device_setup(&prov, &dist_comp); + + slot_count = bt_mesh_dfu_slot_foreach(check_slot, NULL); + ASSERT_EQUAL(CONFIG_BT_MESH_DFU_SLOT_CNT - 1, slot_count); + + slot = bt_mesh_dfu_slot_at(0); + ASSERT_EQUAL(true, bt_mesh_dfu_slot_is_valid(slot)); + + slot = bt_mesh_dfu_slot_at(1); + ASSERT_TRUE(slot != NULL); + ASSERT_EQUAL(false, bt_mesh_dfu_slot_is_valid(slot)); + + for (i = 0; i < (CONFIG_BT_MESH_DFU_SLOT_CNT - 1); i++) { + fwid[0] = i; + idx = bt_mesh_dfu_slot_get(fwid, fwid_len, &slot); + ASSERT_TRUE(idx >= 0); + ASSERT_EQUAL(idx, bt_mesh_dfu_slot_idx_get(slot)); + + ASSERT_EQUAL(size, slot->size); + ASSERT_TRUE(strcmp(uri, slot->uri) == 0); + + metadata[0] = idx; + ASSERT_EQUAL(metadata_len, slot->metadata_len); + ASSERT_TRUE(memcmp(metadata, slot->metadata, metadata_len) == 0); + } + + PASS(); +} + +static void check_delete_all(void) +{ + int i, idx, err; + const struct bt_mesh_dfu_slot *slot; + size_t slot_count; + + ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3, + "CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 3"); + + slot_count = bt_mesh_dfu_slot_foreach(NULL, NULL); + ASSERT_EQUAL(0, slot_count); + + for (i = 0; i < CONFIG_BT_MESH_DFU_SLOT_CNT - 1; i++) { + slot = bt_mesh_dfu_slot_at(i); + ASSERT_TRUE(slot == NULL); + + idx = bt_mesh_dfu_slot_idx_get(slot); + ASSERT_TRUE(idx < 0); + + err = bt_mesh_dfu_slot_valid_set(slot, true); + ASSERT_EQUAL(err, -ENOENT); + + ASSERT_TRUE(!bt_mesh_dfu_slot_is_valid(slot)); + } +} + +static void test_dist_dfu_slot_delete_all(void) +{ + ASSERT_TRUE(CONFIG_BT_MESH_DFU_SLOT_CNT >= 3, + "CONFIG_BT_MESH_DFU_SLOT_CNT must be at least 3"); + + bt_mesh_test_cfg_set(NULL, WAIT_TIME); + bt_mesh_device_setup(&prov, &dist_comp); + + bt_mesh_dfu_slot_del_all(); + + check_delete_all(); + + PASS(); +} + +static void test_dist_dfu_slot_check_delete_all(void) +{ + bt_mesh_test_cfg_set(NULL, WAIT_TIME); + bt_mesh_device_setup(&prov, &dist_comp); + + check_delete_all(); + + PASS(); +} + static void target_test_effect(enum bt_mesh_dfu_effect effect) { dfu_target_effect = effect; @@ -997,6 +1175,12 @@ static void test_pre_init(void) static const struct bst_test_instance test_dfu[] = { TEST_CASE(dist, dfu, "Distributor performs DFU"), TEST_CASE(dist, dfu_self_update, "Distributor performs DFU with self update"), + TEST_CASE(dist, dfu_slot_create, "Distributor creates image slots"), + TEST_CASE(dist, dfu_slot_create_recover, + "Distributor recovers created image slots from persitent storage"), + TEST_CASE(dist, dfu_slot_delete_all, "Distributor deletes all image slots"), + TEST_CASE(dist, dfu_slot_check_delete_all, + "Distributor checks if all slots are removed from persistent storage"), TEST_CASE(cli, fail_on_persistency, "DFU Client doesn't give up DFU Transfer"), TEST_CASE(target, dfu_no_change, "Target node, Comp Data stays unchanged"), diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_slot.sh b/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_slot.sh new file mode 100755 index 000000000000..506a49838ef7 --- /dev/null +++ b/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_slot.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +# Test DFU Slot API. This tests are meant to be executed in sequence to work properly. +# - First test creates slots and saves them in storage. +# - Second test is rebooted device that restores saved slots from storage and checks their state. +# - Third test is rebooted device that deletes all previously added slots +# and verifies they do not exist. +# - Fourth test is rebooted device that verifies if removing all slots also removed them +# from storage. +conf=prj_mesh1d1_conf +overlay=overlay_pst_conf +RunTest dfu_slot dfu_dist_dfu_slot_create + +RunTest dfu_slot dfu_dist_dfu_slot_create_recover + +RunTest dfu_slot dfu_dist_dfu_slot_delete_all + +RunTest dfu_slot dfu_dist_dfu_slot_check_delete_all From 407216b505b8f55522c9d0676ef25a11b20d0020 Mon Sep 17 00:00:00 2001 From: Marc Desvaux Date: Mon, 27 Feb 2023 09:53:07 +0100 Subject: [PATCH 0343/1906] soc: arm: st_stm32: stm32l4: power.c standby shutdownn mode STM32L4x power management stop mode modification Signed-off-by: Marc Desvaux --- soc/arm/st_stm32/stm32l4/power.c | 93 ++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/soc/arm/st_stm32/stm32l4/power.c b/soc/arm/st_stm32/stm32l4/power.c index dee84a1770cc..a8129ee6ac77 100644 --- a/soc/arm/st_stm32/stm32l4/power.c +++ b/soc/arm/st_stm32/stm32l4/power.c @@ -27,82 +27,93 @@ LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL); #define RCC_STOP_WAKEUPCLOCK_SELECTED LL_RCC_STOP_WAKEUPCLOCK_HSI #endif -/* Invoke Low Power/System Off specific Tasks */ -__weak void pm_state_set(enum pm_state state, uint8_t substate_id) +void set_mode_stop(uint8_t substate_id) { - if (state != PM_STATE_SUSPEND_TO_IDLE) { - LOG_DBG("Unsupported power state %u", state); - return; - } + /* ensure the proper wake-up system clock */ + LL_RCC_SetClkAfterWakeFromStop(RCC_STOP_WAKEUPCLOCK_SELECTED); switch (substate_id) { case 1: /* this corresponds to the STOP0 mode: */ - /* ensure the proper wake-up system clock */ - LL_RCC_SetClkAfterWakeFromStop(RCC_STOP_WAKEUPCLOCK_SELECTED); /* enter STOP0 mode */ LL_PWR_SetPowerMode(LL_PWR_MODE_STOP0); - LL_LPM_EnableDeepSleep(); - /* enter SLEEP mode : WFE or WFI */ - k_cpu_idle(); break; case 2: /* this corresponds to the STOP1 mode: */ - /* ensure the proper wake-up system clock */ - LL_RCC_SetClkAfterWakeFromStop(RCC_STOP_WAKEUPCLOCK_SELECTED); /* enter STOP1 mode */ LL_PWR_SetPowerMode(LL_PWR_MODE_STOP1); - LL_LPM_EnableDeepSleep(); - /* enter SLEEP mode : WFE or WFI */ - k_cpu_idle(); break; case 3: /* this corresponds to the STOP2 mode: */ - /* ensure the proper wake-up system clock */ - LL_RCC_SetClkAfterWakeFromStop(RCC_STOP_WAKEUPCLOCK_SELECTED); #ifdef PWR_CR1_RRSTP LL_PWR_DisableSRAM3Retention(); #endif /* PWR_CR1_RRSTP */ /* enter STOP2 mode */ LL_PWR_SetPowerMode(LL_PWR_MODE_STOP2); + break; + default: + LOG_DBG("Unsupported power state substate-id %u", substate_id); + break; + } +} + +/* Invoke Low Power/System Off specific Tasks */ +__weak void pm_state_set(enum pm_state state, uint8_t substate_id) +{ + switch (state) { + case PM_STATE_SUSPEND_TO_IDLE: + set_mode_stop(substate_id); + /* Set SLEEPDEEP bit of Cortex System Control Register */ LL_LPM_EnableDeepSleep(); - /* enter SLEEP mode : WFE or WFI */ + /* Select mode entry : WFE or WFI and enter the CPU selected mode */ k_cpu_idle(); break; + case PM_STATE_STANDBY: + __fallthrough; + case PM_STATE_SOFT_OFF: + __fallthrough; default: - LOG_DBG("Unsupported power state substate-id %u", - substate_id); - break; + LOG_DBG("Unsupported power state %u", state); + return; } + } /* Handle SOC specific activity after Low Power Mode Exit */ __weak void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id) { - if (state != PM_STATE_SUSPEND_TO_IDLE) { - LOG_DBG("Unsupported power substate-id %u", state); - } else { - switch (substate_id) { - case 1: /* STOP0 */ - __fallthrough; - case 2: /* STOP1 */ - __fallthrough; - case 3: /* STOP2 */ + switch (state) { + case PM_STATE_SUSPEND_TO_IDLE: + if (substate_id <= 3) { LL_LPM_DisableSleepOnExit(); LL_LPM_EnableSleep(); - break; - default: + } else { LOG_DBG("Unsupported power substate-id %u", - substate_id); - break; + substate_id); } /* need to restore the clock */ stm32_clock_control_init(NULL); + + /* + * System is now in active mode. + * Reenable interrupts which were disabled + * when OS started idling code. + */ + irq_unlock(0); + break; + case PM_STATE_STANDBY: + __fallthrough; + case PM_STATE_SOFT_OFF: + /* We should not get there */ + __fallthrough; + case PM_STATE_ACTIVE: + __fallthrough; + case PM_STATE_SUSPEND_TO_RAM: + __fallthrough; + case PM_STATE_SUSPEND_TO_DISK: + __fallthrough; + default: + LOG_DBG("Unsupported power state %u", state); + break; } - /* - * System is now in active mode. - * Reenable interrupts which were disabled - * when OS started idling code. - */ - irq_unlock(0); } /* Initialize STM32 Power */ From ba44549ae800c8ef2526f10fbb0c25717956ef60 Mon Sep 17 00:00:00 2001 From: Marc Desvaux Date: Fri, 3 Mar 2023 09:27:16 +0100 Subject: [PATCH 0344/1906] soc: arm: st_stm32: stm32l4: power.c ultra_low_power mode STM32L4x power management (ultra_low_power) of Standby mode and shutdown mode ultra_low_power Signed-off-by: Marc Desvaux --- soc/arm/st_stm32/stm32l4/power.c | 33 ++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/soc/arm/st_stm32/stm32l4/power.c b/soc/arm/st_stm32/stm32l4/power.c index a8129ee6ac77..10d423a38334 100644 --- a/soc/arm/st_stm32/stm32l4/power.c +++ b/soc/arm/st_stm32/stm32l4/power.c @@ -27,6 +27,19 @@ LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL); #define RCC_STOP_WAKEUPCLOCK_SELECTED LL_RCC_STOP_WAKEUPCLOCK_HSI #endif +void enter_ultra_low_power_mode(void) +{ + /* Configure CPU core */ + /* Enable CPU deep sleep mode */ + LL_LPM_EnableDeepSleep(); + LL_DBGMCU_DisableDBGStandbyMode(); + /* Enter ultra_low-power mode */ + + for (;;) { + k_cpu_idle(); + } +} + void set_mode_stop(uint8_t substate_id) { /* ensure the proper wake-up system clock */ @@ -54,6 +67,20 @@ void set_mode_stop(uint8_t substate_id) } } +void set_mode_standby(void) +{ + /* Select standby mode */ + LL_PWR_SetPowerMode(LL_PWR_MODE_STANDBY); + enter_ultra_low_power_mode(); +} + +void set_mode_shutdown(void) +{ + /* Select shutdown mode */ + LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN); + enter_ultra_low_power_mode(); +} + /* Invoke Low Power/System Off specific Tasks */ __weak void pm_state_set(enum pm_state state, uint8_t substate_id) { @@ -66,9 +93,11 @@ __weak void pm_state_set(enum pm_state state, uint8_t substate_id) k_cpu_idle(); break; case PM_STATE_STANDBY: - __fallthrough; + set_mode_standby(); + break; case PM_STATE_SOFT_OFF: - __fallthrough; + set_mode_shutdown(); + break; default: LOG_DBG("Unsupported power state %u", state); return; From b3f739476c35922888a3dc1a8b7f86cbef2cae67 Mon Sep 17 00:00:00 2001 From: Marc Desvaux Date: Fri, 3 Mar 2023 09:42:48 +0100 Subject: [PATCH 0345/1906] samples: boards: stm32: Power_mgmt: sample for standby shutdownn mode STM32L4x power management (ultra_low_power) of Standby mode and shutdown mode Signed-off-by: Marc Desvaux --- .../standby_shutdown/CMakeLists.txt | 7 + .../power_mgmt/standby_shutdown/README.rst | 47 ++++++ .../power_mgmt/standby_shutdown/prj.conf | 4 + .../power_mgmt/standby_shutdown/sample.yaml | 19 +++ .../power_mgmt/standby_shutdown/src/main.c | 155 ++++++++++++++++++ 5 files changed, 232 insertions(+) create mode 100644 samples/boards/stm32/power_mgmt/standby_shutdown/CMakeLists.txt create mode 100644 samples/boards/stm32/power_mgmt/standby_shutdown/README.rst create mode 100644 samples/boards/stm32/power_mgmt/standby_shutdown/prj.conf create mode 100644 samples/boards/stm32/power_mgmt/standby_shutdown/sample.yaml create mode 100644 samples/boards/stm32/power_mgmt/standby_shutdown/src/main.c diff --git a/samples/boards/stm32/power_mgmt/standby_shutdown/CMakeLists.txt b/samples/boards/stm32/power_mgmt/standby_shutdown/CMakeLists.txt new file mode 100644 index 000000000000..b583c9a246f4 --- /dev/null +++ b/samples/boards/stm32/power_mgmt/standby_shutdown/CMakeLists.txt @@ -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(stm32_pm_standby_shutdown) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/boards/stm32/power_mgmt/standby_shutdown/README.rst b/samples/boards/stm32/power_mgmt/standby_shutdown/README.rst new file mode 100644 index 000000000000..3efd2b08a93c --- /dev/null +++ b/samples/boards/stm32/power_mgmt/standby_shutdown/README.rst @@ -0,0 +1,47 @@ +.. _stm32-pm-standby_shutdown-sample: + +STM32 PM Standby shutdown +######################### + +Overview +******** + +This sample is a minimum application to demonstrate basic power management of Standby mode and +shutdown mode +behavior in a basic blinking LED set up you can enter in shutdown mode or in standbymode mode. +Press and hold the user button: +when LED2 is OFF to enter to Shutdown Mode +when LED2 is ON to enter to Standby Mode +release the user button to exit from shutdown mode or from shutdown mode. + +.. _stm32-pm-standby_shutdown-sample-requirements: + +Requirements +************ + +The board should support enabling PM. For a STM32 based target, it means that +it should support a clock source alternative to Cortex Systick that can be used +in core sleep states, as LPTIM (:dtcompatible:`st,stm32-lptim`). +For another board than nucleo_L476RG please adjust wakeup pin into config_wakeup_features(). + +Building and Running +******************** + +Build and flash standby_shutdown as follows, changing ``nucleo_L476RG`` for your board: + +.. zephyr-app-commands:: + :zephyr-app: samples/samples/boards/stm32/power_mgmt/standby_shutdown + :board: nucleo_L476RG + :goals: build flash + :compact: + +After flashing, the LED starts to blink. +Press and hold the user button: +when LED2 is OFF to enter to Shutdown Mode +when LED2 is ON to enter to Standby Mode +release the user button to exit from shutdown mode or from shutdown mode. + +PM configurations +***************** + +By default, :kconfig:option:`CONFIG_PM` is enabled. diff --git a/samples/boards/stm32/power_mgmt/standby_shutdown/prj.conf b/samples/boards/stm32/power_mgmt/standby_shutdown/prj.conf new file mode 100644 index 000000000000..738c014c57a9 --- /dev/null +++ b/samples/boards/stm32/power_mgmt/standby_shutdown/prj.conf @@ -0,0 +1,4 @@ +CONFIG_PM=y +CONFIG_PM_DEVICE=n +CONFIG_PM_DEVICE_RUNTIME=n +CONFIG_HWINFO=y diff --git a/samples/boards/stm32/power_mgmt/standby_shutdown/sample.yaml b/samples/boards/stm32/power_mgmt/standby_shutdown/sample.yaml new file mode 100644 index 000000000000..b4d610de660e --- /dev/null +++ b/samples/boards/stm32/power_mgmt/standby_shutdown/sample.yaml @@ -0,0 +1,19 @@ +sample: + name: STM32 GPIO Power Management +tests: + sample.boards.stm32.power_mgmt.standby_shutdown: + platform_allow: nucleo_l476rg disco_l475_iot1 + tags: LED power + harness: console + harness_config: + type: multi_line + regex: + - "Reset cause: Reset pin" + - "Device ready: .*" + - "Press and hold the user button:" + - "when LED2 is OFF to enter to Shutdown Mode" + - "when LED2 is ON to enter to Standby Mode" + filter: dt_compat_enabled("zephyr,power-state") and + dt_enabled_alias_with_parent_compat("led0", "gpio-leds") and + dt_compat_enabled("st,stm32-lptim") + extra_args: "CONFIG_DEBUG=y" diff --git a/samples/boards/stm32/power_mgmt/standby_shutdown/src/main.c b/samples/boards/stm32/power_mgmt/standby_shutdown/src/main.c new file mode 100644 index 000000000000..118ecaafc7f6 --- /dev/null +++ b/samples/boards/stm32/power_mgmt/standby_shutdown/src/main.c @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#if !defined(CONFIG_SOC_SERIES_STM32L4X) +#error Not implemented for other series +#endif /* CONFIG_SOC_SERIES_STM32L4X */ + +#define STACKSIZE 1024 +#define PRIORITY 7 +#define SLEEP_TIME_MS 3000 + +#define SW0_NODE DT_ALIAS(sw0) +#if !DT_NODE_HAS_STATUS(SW0_NODE, okay) +#error "Unsupported board: sw0 devicetree alias is not defined" +#endif + +/* Semaphore used to control button pressed value */ +static struct k_sem button_sem; + +static int led_is_on; + +static const struct gpio_dt_spec button = + GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, {0}); + +static const struct gpio_dt_spec led = + GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios); + +static struct gpio_callback button_cb_data; + +void config_wakeup_features(void) +{ + /* Configure wake-up features */ + /* WKUP2(PC13) only , - active low, pull-up */ + /* Set pull-ups for standby modes */ + LL_PWR_EnableGPIOPullUp(LL_PWR_GPIO_C, LL_PWR_GPIO_BIT_13); + LL_PWR_IsWakeUpPinPolarityLow(LL_PWR_WAKEUP_PIN2); + /* Enable pin pull up configurations and wakeup pins */ + LL_PWR_EnablePUPDCfg(); + LL_PWR_EnableWakeUpPin(LL_PWR_WAKEUP_PIN2); + /* Clear wakeup flags */ + LL_PWR_ClearFlag_WU(); +} + +void button_pressed(const struct device *dev, struct gpio_callback *cb, + uint32_t pins) +{ + k_sem_give(&button_sem); +} + +void thread_shutdown_standby_mode(void) +{ + k_sem_init(&button_sem, 0, 1); + k_sem_take(&button_sem, K_FOREVER); + gpio_pin_configure(led.port, led.pin, GPIO_DISCONNECTED); + printk("User button pressed\n"); + config_wakeup_features(); + if (led_is_on == false) { + printk("Shutdown Mode requested\n"); + printk("Release the user button to exit from Shutdown Mode\n\n"); +#ifdef CONFIG_LOG + k_msleep(2000); +#endif /* CONFIG_LOG */ + pm_state_force(0u, &(struct pm_state_info) {PM_STATE_SOFT_OFF, 0, 0}); + /* stay in Shutdown mode until wakeup line activated */ + } else { + printk("Standby Mode requested\n"); + printk("Release the user button to exit from Standby Mode\n\n"); +#ifdef CONFIG_LOG + k_msleep(2000); +#endif /* CONFIG_LOG */ + pm_state_force(0u, &(struct pm_state_info) {PM_STATE_STANDBY, 0, 0}); + /* stay in Standby mode until wakeup line activated */ + } +} + +K_THREAD_DEFINE(thread_shutdown_standby_mode_id, STACKSIZE, thread_shutdown_standby_mode, + NULL, NULL, NULL, PRIORITY, 0, 0); + +void main(void) +{ + int ret; + uint32_t cause; + + hwinfo_get_reset_cause(&cause); + hwinfo_clear_reset_cause(); + + if ((LL_PWR_IsActiveFlag_SB() == true) && (cause == 0)) { + LL_PWR_ClearFlag_SB(); + LL_PWR_ClearFlag_WU(); + printk("\nReset cause: Standby mode\n\n"); + } + + if (cause == (RESET_PIN | RESET_BROWNOUT)) { + LL_PWR_ClearFlag_WU(); + printk("\nReset cause: Shutdown mode or power up\n\n"); + } + + if (cause == RESET_PIN) { + LL_PWR_ClearFlag_WU(); + printk("\nReset cause: Reset pin\n\n"); + } + + + __ASSERT_NO_MSG(device_is_ready(led.port)); + if (!gpio_is_ready_dt(&button)) { + printk("Error: button device %s is not ready\n", + button.port->name); + return; + } + + ret = gpio_pin_configure_dt(&button, GPIO_INPUT); + if (ret != 0) { + printk("Error %d: failed to configure %s pin %d\n", + ret, button.port->name, button.pin); + return; + } + + ret = gpio_pin_interrupt_configure_dt(&button, + GPIO_INT_EDGE_TO_ACTIVE); + if (ret != 0) { + printk("Error %d: failed to configure interrupt on %s pin %d\n", + ret, button.port->name, button.pin); + return; + } + + gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin)); + gpio_add_callback(button.port, &button_cb_data); + + printk("Device ready: %s\n\n\n", CONFIG_BOARD); + + printk("Press and hold the user button:\n"); + printk(" when LED2 is OFF to enter to Shutdown Mode\n"); + printk(" when LED2 is ON to enter to Standby Mode\n\n"); + + led_is_on = true; + while (true) { + gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); + gpio_pin_set(led.port, led.pin, (int)led_is_on); + k_msleep(SLEEP_TIME_MS); + led_is_on = !led_is_on; + } + +} From 2ada005d7c74f89dfbabaacb4bc4f5059761b618 Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Mon, 19 Sep 2022 11:58:43 +0200 Subject: [PATCH 0346/1906] Bluetooth: controller: removing legacy LLCP code This commit removes the legacy LLCP code including the Kconfig option It also updates the babblesim tests, and removes the tests for the legacy controller Signed-off-by: Andries Kruithof --- .../boards/nrf52833dk_nrf52820.conf | 3 - .../boards/nrf52833dk_nrf52833.conf | 3 - .../boards/nrf52833dk_nrf52820.conf | 3 - .../boards/nrf52833dk_nrf52833.conf | 3 - .../hci_uart/overlay-all-bt_ll_sw_split.conf | 1 - subsys/bluetooth/controller/CMakeLists.txt | 47 +- .../bluetooth/controller/Kconfig.ll_sw_split | 35 +- subsys/bluetooth/controller/hci/hci.c | 19 +- subsys/bluetooth/controller/ll_sw/ll_tx_pwr.c | 4 +- subsys/bluetooth/controller/ll_sw/lll_conn.h | 12 - .../controller/ll_sw/nordic/lll/lll_conn.c | 8 - .../ll_sw/nordic/lll/lll_scan_aux.c | 9 - .../controller/ll_sw/openisa/lll/lll_conn.c | 8 - subsys/bluetooth/controller/ll_sw/ull.c | 15 +- subsys/bluetooth/controller/ll_sw/ull_adv.c | 108 +- .../bluetooth/controller/ll_sw/ull_central.c | 222 +- .../controller/ll_sw/ull_chan_internal.h | 2 - subsys/bluetooth/controller/ll_sw/ull_conn.c | 6331 +---------------- .../controller/ll_sw/ull_conn_internal.h | 4 - .../bluetooth/controller/ll_sw/ull_conn_iso.c | 6 +- .../controller/ll_sw/ull_conn_types.h | 325 - .../bluetooth/controller/ll_sw/ull_filter.c | 2 - subsys/bluetooth/controller/ll_sw/ull_iso.c | 10 +- .../controller/ll_sw/ull_peripheral.c | 64 +- .../controller/ll_sw/ull_peripheral_iso.c | 21 +- subsys/bluetooth/controller/ll_sw/ull_scan.c | 5 +- subsys/bluetooth/controller/ll_sw/ull_sched.c | 4 +- .../bsim/ll/edtt/gatt_test_app/prj.conf | 30 - .../bsim/ll/edtt/gatt_test_app/prj_llcp.conf | 2 - .../bsim/ll/edtt/hci_test_app/prj_dut.conf | 44 - .../ll/edtt/hci_test_app/prj_dut_llcp.conf | 1 - .../bsim/ll/edtt/hci_test_app/prj_tst.conf | 44 - .../ll/edtt/hci_test_app/prj_tst_llcp.conf | 1 - .../bsim/ll/edtt/tests_scripts/gap.sh | 14 - .../bsim/ll/edtt/tests_scripts/gap.test_list | 57 - .../bsim/ll/edtt/tests_scripts/gatt.sh | 48 - .../bsim/ll/edtt/tests_scripts/gatt.test_list | 72 - .../bsim/ll/edtt/tests_scripts/hci.sh | 14 - .../bsim/ll/edtt/tests_scripts/hci.test_list | 33 - .../bsim/ll/edtt/tests_scripts/ll.1.sh | 15 - .../bsim/ll/edtt/tests_scripts/ll.2.sh | 15 - .../ll/edtt/tests_scripts/ll.set1.test_list | 71 - .../ll/edtt/tests_scripts/ll.set2.test_list | 75 - .../controller/mock_ctrl/src/ull_conn_iso.c | 2 - .../bluetooth/df/connection_cte_req/prj.conf | 3 - .../df/connection_cte_tx_params/prj.conf | 3 - tests/bluetooth/init/prj_llcp.conf | 1 - 47 files changed, 261 insertions(+), 7558 deletions(-) delete mode 100644 tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj.conf delete mode 100644 tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut.conf delete mode 100644 tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst.conf delete mode 100755 tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.sh delete mode 100644 tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.test_list delete mode 100755 tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.sh delete mode 100644 tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.test_list delete mode 100755 tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.sh delete mode 100644 tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.test_list delete mode 100755 tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.1.sh delete mode 100755 tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.2.sh delete mode 100644 tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set1.test_list delete mode 100644 tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set2.test_list diff --git a/samples/bluetooth/direction_finding_central/boards/nrf52833dk_nrf52820.conf b/samples/bluetooth/direction_finding_central/boards/nrf52833dk_nrf52820.conf index 848ac5852d5d..dafd888a1f97 100644 --- a/samples/bluetooth/direction_finding_central/boards/nrf52833dk_nrf52820.conf +++ b/samples/bluetooth/direction_finding_central/boards/nrf52833dk_nrf52820.conf @@ -7,9 +7,6 @@ CONFIG_BT_CTLR=y CONFIG_BT_LL_SW_SPLIT=y -# Enable new implementation of LLCPs -CONFIG_BT_LL_SW_LLCP=y - # Enable Direction Finding Feature including AoA and AoD CONFIG_BT_CTLR_DF=y diff --git a/samples/bluetooth/direction_finding_central/boards/nrf52833dk_nrf52833.conf b/samples/bluetooth/direction_finding_central/boards/nrf52833dk_nrf52833.conf index 848ac5852d5d..dafd888a1f97 100644 --- a/samples/bluetooth/direction_finding_central/boards/nrf52833dk_nrf52833.conf +++ b/samples/bluetooth/direction_finding_central/boards/nrf52833dk_nrf52833.conf @@ -7,9 +7,6 @@ CONFIG_BT_CTLR=y CONFIG_BT_LL_SW_SPLIT=y -# Enable new implementation of LLCPs -CONFIG_BT_LL_SW_LLCP=y - # Enable Direction Finding Feature including AoA and AoD CONFIG_BT_CTLR_DF=y diff --git a/samples/bluetooth/direction_finding_peripheral/boards/nrf52833dk_nrf52820.conf b/samples/bluetooth/direction_finding_peripheral/boards/nrf52833dk_nrf52820.conf index 0a751804938f..4e006fa81ebc 100644 --- a/samples/bluetooth/direction_finding_peripheral/boards/nrf52833dk_nrf52820.conf +++ b/samples/bluetooth/direction_finding_peripheral/boards/nrf52833dk_nrf52820.conf @@ -7,9 +7,6 @@ CONFIG_BT_CTLR=y CONFIG_BT_LL_SW_SPLIT=y -# Enable new implementation of LLCPs -CONFIG_BT_LL_SW_LLCP=y - # Enable Direction Finding Feature including AoA and AoD CONFIG_BT_CTLR_DF=y diff --git a/samples/bluetooth/direction_finding_peripheral/boards/nrf52833dk_nrf52833.conf b/samples/bluetooth/direction_finding_peripheral/boards/nrf52833dk_nrf52833.conf index 0a751804938f..4e006fa81ebc 100644 --- a/samples/bluetooth/direction_finding_peripheral/boards/nrf52833dk_nrf52833.conf +++ b/samples/bluetooth/direction_finding_peripheral/boards/nrf52833dk_nrf52833.conf @@ -7,9 +7,6 @@ CONFIG_BT_CTLR=y CONFIG_BT_LL_SW_SPLIT=y -# Enable new implementation of LLCPs -CONFIG_BT_LL_SW_LLCP=y - # Enable Direction Finding Feature including AoA and AoD CONFIG_BT_CTLR_DF=y diff --git a/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf b/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf index 31baeba582b8..c1815fa52f7b 100644 --- a/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_uart/overlay-all-bt_ll_sw_split.conf @@ -56,7 +56,6 @@ CONFIG_BT_CTLR_DF=y CONFIG_BT_CTLR_DF_PER_ADV_CTE_NUM_MAX=3 CONFIG_BT_CTLR_DF_PER_SCAN_CTE_NUM_MAX=3 -CONFIG_BT_LL_SW_LLCP=y CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=6 CONFIG_BT_CTLR_DF_CTE_TX=y diff --git a/subsys/bluetooth/controller/CMakeLists.txt b/subsys/bluetooth/controller/CMakeLists.txt index 9e3a382f2ed9..1909bd46fb93 100644 --- a/subsys/bluetooth/controller/CMakeLists.txt +++ b/subsys/bluetooth/controller/CMakeLists.txt @@ -68,33 +68,30 @@ if(CONFIG_BT_LL_SW_SPLIT) zephyr_library_sources( ll_sw/ull_conn.c ) - if(CONFIG_BT_LL_SW_LLCP_LEGACY) - else() - zephyr_library_sources_ifdef( - CONFIG_BT_CTLR_PHY - ll_sw/ull_llcp_phy.c - ) - zephyr_library_sources_ifdef( - CONFIG_BT_CTLR_LE_ENC - ll_sw/ull_llcp_enc.c - ) - if (CONFIG_BT_CTLR_PERIPHERAL_ISO OR - CONFIG_BT_CTLR_CENTRAL_ISO) - zephyr_library_sources( - ll_sw/ull_llcp_cc.c - ) - endif() + zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_PHY + ll_sw/ull_llcp_phy.c + ) + zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_LE_ENC + ll_sw/ull_llcp_enc.c + ) + if (CONFIG_BT_CTLR_PERIPHERAL_ISO OR + CONFIG_BT_CTLR_CENTRAL_ISO) zephyr_library_sources( - ll_sw/ull_tx_queue.c - ll_sw/ull_llcp.c - ll_sw/ull_llcp_common.c - ll_sw/ull_llcp_local.c - ll_sw/ull_llcp_pdu.c - ll_sw/ull_llcp_conn_upd.c - ll_sw/ull_llcp_chmu.c - ll_sw/ull_llcp_remote.c - ) + ll_sw/ull_llcp_cc.c + ) endif() + zephyr_library_sources( + ll_sw/ull_tx_queue.c + ll_sw/ull_llcp.c + ll_sw/ull_llcp_common.c + ll_sw/ull_llcp_local.c + ll_sw/ull_llcp_pdu.c + ll_sw/ull_llcp_conn_upd.c + ll_sw/ull_llcp_chmu.c + ll_sw/ull_llcp_remote.c + ) if(CONFIG_BT_PERIPHERAL) zephyr_library_sources( ll_sw/ull_peripheral.c diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index acd2fd848c79..8b2db4e890c9 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -37,7 +37,7 @@ config BT_LLL_VENDOR_NORDIC select BT_CTLR_CTEINLINE_SUPPORT if HAS_HW_NRF_RADIO_DFE select BT_CTLR_CHAN_SEL_2_SUPPORT select BT_CTLR_MIN_USED_CHAN_SUPPORT - select BT_CTLR_SCA_UPDATE_SUPPORT if !BT_LL_SW_LLCP_LEGACY + select BT_CTLR_SCA_UPDATE_SUPPORT select BT_CTLR_DTM_HCI_SUPPORT select BT_CTLR_CONN_RSSI_SUPPORT @@ -85,27 +85,6 @@ config BT_CTLR_TIFS_HW_SUPPORT config BT_CTLR_ULL_LLL_PRIO_SUPPORT bool -choice BT_LL_SW_LLCP_IMPL - prompt "Bluetooth Low Energy Software Link Layer Control Procedure Implementation" - default BT_LL_SW_LLCP - help - Select the Bluetooth Low Energy Software Link Layer Control Procedure implementation. - -config BT_LL_SW_LLCP_LEGACY - bool "Legacy implementation (DEPRECATED)" - depends on !BT_CTLR_DF_CONN_CTE_RX && !BT_CTLR_DF_CONN_CTE_TX - select DEPRECATED - help - Use the Bluetooth Low Energy Software Link Layer Legacy Control Procedure implementation. - -config BT_LL_SW_LLCP - bool "State-machine based implementation, replacing the legacy one" - help - Use the new Bluetooth Low Energy Software Link Layer Control Procedure implementation. - -endchoice - - config BT_CTLR_RX_PRIO_STACK_SIZE # Controller's Co-Operative high priority Rx thread stack size. int "High priority Rx thread stack size" @@ -622,7 +601,6 @@ config BT_CTLR_LLCP_CONN more than this number of connections simultaneously may cause instabilities. -if !BT_LL_SW_LLCP_LEGACY config BT_CTLR_LLCP_TX_PER_CONN_TX_CTRL_BUF_NUM_MAX int default 4 @@ -674,23 +652,12 @@ config BT_CTLR_LLCP_REMOTE_PROC_CTX_BUF_NUM for handling remote initiated control procedures. This pool is shared across all connections, with allocation through a queue. -endif #!BT_LL_SW_LLCP_LEGACY - - config BT_CTLR_LLID_DATA_START_EMPTY bool "Handle zero length L2CAP start frame" default y if BT_HCI_RAW help Handle zero length L2CAP start frame. -config BT_CTLR_RX_ENQUEUE_HOLD - bool "Procedure Complete after on-air instant" - depends on BT_LL_SW_LLCP_LEGACY - default y if BT_HCI_RAW - help - Hold enqueue of Procedure Complete events with instant until after the - on-air instant is reached. - config BT_CTLR_TX_RETRY_DISABLE bool "Disable Tx Retry" help diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 16d8893f2d07..d8281bcae087 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -53,9 +53,7 @@ #include "ll_sw/isoal.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) #include "ll_sw/ull_tx_queue.h" -#endif #include "ll_sw/ull_adv_types.h" #include "ll_sw/ull_scan_types.h" @@ -4866,7 +4864,7 @@ static void vs_read_key_hierarchy_roots(struct net_buf *buf, rp->status = 0x00; hci_vendor_read_key_hierarchy_roots(rp->ir, rp->er); } -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) + #if defined(CONFIG_BT_CTLR_MIN_USED_CHAN) && defined(CONFIG_BT_PERIPHERAL) static void vs_set_min_used_chans(struct net_buf *buf, struct net_buf **evt) { @@ -4879,7 +4877,7 @@ static void vs_set_min_used_chans(struct net_buf *buf, struct net_buf **evt) *evt = cmd_complete_status(status); } #endif /* CONFIG_BT_CTLR_MIN_USED_CHAN && CONFIG_BT_PERIPHERAL */ -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ + #if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) static void vs_write_tx_power_level(struct net_buf *buf, struct net_buf **evt) { @@ -5450,13 +5448,6 @@ int hci_vendor_cmd_handle_common(uint16_t ocf, struct net_buf *cmd, vs_read_tx_power_level(cmd, evt); break; #endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */ -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#if defined(CONFIG_BT_CTLR_MIN_USED_CHAN) && defined(CONFIG_BT_PERIPHERAL) - case BT_OCF(BT_HCI_OP_VS_SET_MIN_NUM_USED_CHANS): - vs_set_min_used_chans(cmd, evt); - break; -#endif /* CONFIG_BT_CTLR_MIN_USED_CHAN && CONFIG_BT_PERIPHERAL */ -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ #endif /* CONFIG_BT_HCI_VS_EXT */ #if defined(CONFIG_BT_HCI_MESH_EXT) @@ -5465,6 +5456,12 @@ int hci_vendor_cmd_handle_common(uint16_t ocf, struct net_buf *cmd, break; #endif /* CONFIG_BT_HCI_MESH_EXT */ +#if defined(CONFIG_BT_CTLR_MIN_USED_CHAN) && defined(CONFIG_BT_PERIPHERAL) + case BT_OCF(BT_HCI_OP_VS_SET_MIN_NUM_USED_CHANS): + vs_set_min_used_chans(cmd, evt); + break; +#endif /* CONFIG_BT_CTLR_MIN_USED_CHAN && CONFIG_BT_PERIPHERAL */ + default: return -EINVAL; } diff --git a/subsys/bluetooth/controller/ll_sw/ll_tx_pwr.c b/subsys/bluetooth/controller/ll_sw/ll_tx_pwr.c index 165a80d5fe52..c46b6b399694 100644 --- a/subsys/bluetooth/controller/ll_sw/ll_tx_pwr.c +++ b/subsys/bluetooth/controller/ll_sw/ll_tx_pwr.c @@ -31,9 +31,7 @@ #include "lll/lll_df_types.h" #include "lll_conn.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#include "ull_tx_queue.h" -#endif +#include "ll_sw/ull_tx_queue.h" #include "ull_adv_types.h" #include "ull_scan_types.h" diff --git a/subsys/bluetooth/controller/ll_sw/lll_conn.h b/subsys/bluetooth/controller/ll_sw/lll_conn.h index d8fe6b0c283e..13666d869d6a 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_conn.h +++ b/subsys/bluetooth/controller/ll_sw/lll_conn.h @@ -87,17 +87,6 @@ struct lll_conn { }; #if defined(CONFIG_BT_CTLR_DATA_LENGTH) - -#ifdef CONFIG_BT_LL_SW_LLCP_LEGACY - uint16_t max_tx_octets; - uint16_t max_rx_octets; - -#if defined(CONFIG_BT_CTLR_PHY) - uint16_t max_tx_time; - uint16_t max_rx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ struct { struct data_pdu_length local; struct data_pdu_length remote; @@ -109,7 +98,6 @@ struct lll_conn { uint8_t update; } dle; #endif /* CONFIG_BT_CTLR_DATA_LENGTH */ -#endif/* CONFIG_BT_LL_SW_LLCP_LEGACY */ #if defined(CONFIG_BT_CTLR_PHY) uint8_t phy_tx:3; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c index 93f1a999172e..a774346e9beb 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c @@ -651,11 +651,7 @@ void lll_conn_rx_pkt_set(struct lll_conn *lll) LL_ASSERT(node_rx); #if defined(CONFIG_BT_CTLR_DATA_LENGTH) -#ifdef CONFIG_BT_LL_SW_LLCP_LEGACY - max_rx_octets = lll->max_rx_octets; -#else max_rx_octets = lll->dle.eff.max_rx_octets; -#endif #else /* !CONFIG_BT_CTLR_DATA_LENGTH */ max_rx_octets = PDU_DC_PAYLOAD_SIZE_MIN; #endif /* !CONFIG_BT_CTLR_DATA_LENGTH */ @@ -708,11 +704,7 @@ void lll_conn_tx_pkt_set(struct lll_conn *lll, struct pdu_data *pdu_data_tx) uint16_t max_tx_octets; #if defined(CONFIG_BT_CTLR_DATA_LENGTH) -#ifdef CONFIG_BT_LL_SW_LLCP_LEGACY - max_tx_octets = lll->max_tx_octets; -#else max_tx_octets = lll->dle.eff.max_tx_octets; -#endif #else /* !CONFIG_BT_CTLR_DATA_LENGTH */ max_tx_octets = PDU_DC_PAYLOAD_SIZE_MIN; #endif /* !CONFIG_BT_CTLR_DATA_LENGTH */ diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c index a71a1087305e..81f17c315c8e 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c @@ -1521,21 +1521,12 @@ static void isr_rx_connect_rsp(void *param) struct lll_conn *conn_lll = lll->conn; #if defined(CONFIG_BT_CTLR_DATA_LENGTH) -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - conn_lll->max_tx_time = MAX(conn_lll->max_tx_time, - PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - lll_aux->phy)); - conn_lll->max_rx_time = MAX(conn_lll->max_rx_time, - PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - lll_aux->phy)); -#else conn_lll->dle.eff.max_tx_time = MAX(conn_lll->dle.eff.max_tx_time, PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, lll_aux->phy)); conn_lll->dle.eff.max_rx_time = MAX(conn_lll->dle.eff.max_rx_time, PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, lll_aux->phy)); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ #endif /* CONFIG_BT_CTLR_DATA_LENGTH*/ conn_lll->phy_tx = lll_aux->phy; diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_conn.c b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_conn.c index 88bf62284ff4..ccf18702dce7 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_conn.c +++ b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_conn.c @@ -425,11 +425,7 @@ void lll_conn_rx_pkt_set(struct lll_conn *lll) LL_ASSERT(node_rx); #if defined(CONFIG_BT_CTLR_DATA_LENGTH) -#ifdef CONFIG_BT_LL_SW_LLCP_LEGACY - max_rx_octets = lll->max_rx_octets; -#else max_rx_octets = lll->dle.eff.max_rx_octets; -#endif #else /* !CONFIG_BT_CTLR_DATA_LENGTH */ max_rx_octets = PDU_DC_PAYLOAD_SIZE_MIN; #endif /* !CONFIG_BT_CTLR_DATA_LENGTH */ @@ -463,11 +459,7 @@ void lll_conn_tx_pkt_set(struct lll_conn *lll, struct pdu_data *pdu_data_tx) uint8_t phy, flags; #if defined(CONFIG_BT_CTLR_DATA_LENGTH) -#ifdef CONFIG_BT_LL_SW_LLCP_LEGACY - max_tx_octets = lll->max_tx_octets; -#else max_tx_octets = lll->dle.eff.max_tx_octets; -#endif #else /* !CONFIG_BT_CTLR_DATA_LENGTH */ max_tx_octets = PDU_DC_PAYLOAD_SIZE_MIN; #endif /* !CONFIG_BT_CTLR_DATA_LENGTH */ diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index ef7f2533c56e..224e96c7dade 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -49,9 +49,7 @@ #include "ull_adv_types.h" #include "ull_scan_types.h" #include "ull_sync_types.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#include "ull_tx_queue.h" -#endif +#include "ll_sw/ull_tx_queue.h" #include "ull_conn_types.h" #include "ull_filter.h" #include "ull_df_types.h" @@ -372,20 +370,11 @@ static RXFIFO_DEFINE(done, sizeof(struct node_rx_event_done), * simultaneous parallel PHY update or Connection Update procedures amongst * active connections. * Minimum node rx of 2 that can be reserved happens when: - * - for legacy LLCPs: - * Local central initiated PHY Update reserves 2 node rx, - * one for PHY update complete and another for Data Length Update complete - * notification. Otherwise, a peripheral only needs 1 additional node rx to - * generate Data Length Update complete when PHY Update completes; node rx for - * PHY update complete is reserved as the received PHY Update Ind PDU. - * - for new LLCPs: * Central and peripheral always use two new nodes for handling completion * notification one for PHY update complete and another for Data Length Update * complete. */ -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) && defined(CONFIG_BT_CTLR_PHY) && \ - (defined(CONFIG_BT_LL_SW_LLCP_LEGACY) && defined(CONFIG_BT_CENTRAL) || \ - !defined(CONFIG_BT_LL_SW_LLCP_LEGACY)) +#if defined(CONFIG_BT_CTLR_DATA_LENGTH) && defined(CONFIG_BT_CTLR_PHY) #define LL_PDU_RX_CNT (2 * (CONFIG_BT_CTLR_LLCP_CONN)) #elif defined(CONFIG_BT_CONN) #define LL_PDU_RX_CNT (CONFIG_BT_CTLR_LLCP_CONN) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv.c b/subsys/bluetooth/controller/ll_sw/ull_adv.c index ac401404f976..0e2900890453 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv.c @@ -42,9 +42,7 @@ #include "lll_filter.h" #include "lll_conn_iso.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) #include "ll_sw/ull_tx_queue.h" -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ #include "ull_adv_types.h" #include "ull_scan_types.h" @@ -60,13 +58,12 @@ #include "ll_feat.h" #include "ll_settings.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#include "isoal.h" -#include "ull_iso_types.h" -#include "ull_conn_iso_types.h" +#include "ll_sw/isoal.h" +#include "ll_sw/ull_iso_types.h" +#include "ll_sw/ull_conn_iso_types.h" + +#include "ll_sw/ull_llcp.h" -#include "ull_llcp.h" -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ #include "hal/debug.h" @@ -1014,33 +1011,6 @@ uint8_t ll_adv_enable(uint8_t enable) conn_lll->nesn = 0; conn_lll->empty = 0; -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - conn_lll->max_tx_octets = PDU_DC_PAYLOAD_SIZE_MIN; - conn_lll->max_rx_octets = PDU_DC_PAYLOAD_SIZE_MIN; - -#if defined(CONFIG_BT_CTLR_PHY) - /* Use the default 1M packet max time */ - conn_lll->max_tx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - PHY_1M); - conn_lll->max_rx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - PHY_1M); -#if defined(CONFIG_BT_CTLR_ADV_EXT) - if (pdu_adv->type == PDU_ADV_TYPE_EXT_IND) { - conn_lll->max_tx_time = - MAX(conn_lll->max_tx_time, - PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - lll->phy_s)); - conn_lll->max_rx_time = - MAX(conn_lll->max_rx_time, - PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - lll->phy_s)); - } -#endif /* CONFIG_BT_CTLR_ADV_EXT */ -#endif /* CONFIG_BT_CTLR_PHY */ -#endif -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - #if defined(CONFIG_BT_CTLR_PHY) conn_lll->phy_flags = 0; if (0) { @@ -1097,9 +1067,6 @@ uint8_t ll_adv_enable(uint8_t enable) #endif /* CONFIG_BT_CTLR_DF_CONN_CTE_TX */ conn->connect_expire = 6; conn->supervision_expire = 0; -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - conn->procedure_expire = 0; -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ #if defined(CONFIG_BT_CTLR_LE_PING) conn->apto_expire = 0U; @@ -1115,70 +1082,6 @@ uint8_t ll_adv_enable(uint8_t enable) sizeof(conn->peer_id_addr)); #endif /* CONFIG_BT_CTLR_CHECK_SAME_PEER_CONN */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - conn->common.fex_valid = 0; - conn->common.txn_lock = 0; - conn->periph.latency_cancel = 0; - - conn->llcp_req = conn->llcp_ack = conn->llcp_type = 0; - conn->llcp_rx = NULL; - conn->llcp_cu.req = conn->llcp_cu.ack = 0; - conn->llcp_cu.pause_tx = 0U; - conn->llcp_feature.req = conn->llcp_feature.ack = 0; - conn->llcp_feature.features_conn = ll_feat_get(); - conn->llcp_feature.features_peer = 0; - conn->llcp_version.req = conn->llcp_version.ack = 0; - conn->llcp_version.tx = conn->llcp_version.rx = 0; - conn->llcp_terminate.req = conn->llcp_terminate.ack = 0; - conn->llcp_terminate.reason_final = 0; - /* NOTE: use allocated link for generating dedicated - * terminate ind rx node - */ - conn->llcp_terminate.node_rx.hdr.link = link; - -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) - conn->llcp_rx_hold = NULL; - conn_lll->rx_hold_req = 0U; - conn_lll->rx_hold_ack = 0U; -#endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - -#if defined(CONFIG_BT_CTLR_LE_ENC) - conn_lll->enc_rx = conn_lll->enc_tx = 0U; - conn->llcp_enc.req = conn->llcp_enc.ack = 0U; - conn->llcp_enc.pause_tx = conn->llcp_enc.pause_rx = 0U; - conn->llcp_enc.refresh = 0U; - conn->periph.llcp_type = 0U; -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - conn->llcp_conn_param.req = 0U; - conn->llcp_conn_param.ack = 0U; - conn->llcp_conn_param.disabled = 0U; - conn->llcp_conn_param.cache.timeout = 0U; - conn->periph.ticks_to_offset = 0U; -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - conn->llcp_length.req = conn->llcp_length.ack = 0U; - conn->llcp_length.disabled = 0U; - conn->llcp_length.cache.tx_octets = 0U; - conn->default_tx_octets = ull_conn_default_tx_octets_get(); -#if defined(CONFIG_BT_CTLR_PHY) - conn->default_tx_time = ull_conn_default_tx_time_get(); -#endif /* CONFIG_BT_CTLR_PHY */ -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - -#if defined(CONFIG_BT_CTLR_PHY) - conn->llcp_phy.req = conn->llcp_phy.ack = 0; - conn->llcp_phy.disabled = 0U; - conn->llcp_phy.pause_tx = 0U; - conn->phy_pref_tx = ull_conn_default_phy_tx_get(); - conn->phy_pref_rx = ull_conn_default_phy_rx_get(); -#endif /* CONFIG_BT_CTLR_PHY */ - - conn->tx_head = conn->tx_ctrl = conn->tx_ctrl_last = - conn->tx_data = conn->tx_data_last = 0; -#else /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ /* Re-initialize the control procedure data structures */ ull_llcp_init(conn); @@ -1212,7 +1115,6 @@ uint8_t ll_adv_enable(uint8_t enable) /* Re-initialize the Tx Q */ ull_tx_q_init(&conn->tx_q); -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ /* NOTE: using same link as supplied for terminate ind */ adv->link_cc_free = link; diff --git a/subsys/bluetooth/controller/ll_sw/ull_central.c b/subsys/bluetooth/controller/ll_sw/ull_central.c index e4add37fe0d1..5ea7b5926bb5 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central.c @@ -40,9 +40,7 @@ #include "lll_filter.h" #include "lll_conn_iso.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#include "ull_tx_queue.h" -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ +#include "ll_sw/ull_tx_queue.h" #include "ull_adv_types.h" #include "ull_scan_types.h" @@ -59,13 +57,11 @@ #include "ll_feat.h" #include "ll_settings.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#include "isoal.h" -#include "ull_iso_types.h" -#include "ull_conn_iso_types.h" +#include "ll_sw/isoal.h" +#include "ll_sw/ull_iso_types.h" +#include "ll_sw/ull_conn_iso_types.h" -#include "ull_llcp.h" -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ +#include "ll_sw/ull_llcp.h" #include "hal/debug.h" @@ -225,24 +221,9 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, conn_lll->phy_rx = PHY_1M; #endif /* CONFIG_BT_CTLR_PHY */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - conn_lll->max_tx_octets = PDU_DC_PAYLOAD_SIZE_MIN; - conn_lll->max_rx_octets = PDU_DC_PAYLOAD_SIZE_MIN; - -#if defined(CONFIG_BT_CTLR_PHY) - /* Use the default 1M packet Tx time, extended connection initiation - * in LLL will update this with the correct PHY. - */ - conn_lll->max_tx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M); - conn_lll->max_rx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M); -#endif /* CONFIG_BT_CTLR_PHY */ -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ #if defined(CONFIG_BT_CTLR_DATA_LENGTH) ull_dle_init(conn, PHY_1M); #endif /* CONFIG_BT_CTLR_DATA_LENGTH */ -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ #if defined(CONFIG_BT_CTLR_CONN_RSSI) conn_lll->rssi_latest = BT_HCI_LE_RSSI_NOT_AVAILABLE; @@ -288,12 +269,6 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, conn_interval_us = (uint32_t)interval * CONN_INT_UNIT_US; conn->supervision_timeout = timeout; -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - conn->procedure_expire = 0U; - conn->procedure_reload = RADIO_CONN_EVENTS(40000000, - conn_interval_us); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - #if defined(CONFIG_BT_CTLR_LE_PING) conn->apto_expire = 0U; /* APTO in no. of connection events */ @@ -308,69 +283,13 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, conn->apto_reload; #endif /* CONFIG_BT_CTLR_LE_PING */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - conn->common.fex_valid = 0U; - conn->common.txn_lock = 0U; - conn->central.terminate_ack = 0U; - - conn->llcp_req = conn->llcp_ack = conn->llcp_type = 0U; - conn->llcp_rx = NULL; - conn->llcp_cu.req = conn->llcp_cu.ack = 0; - conn->llcp_cu.pause_tx = 0U; - conn->llcp_feature.req = conn->llcp_feature.ack = 0; - conn->llcp_feature.features_conn = ll_feat_get(); - conn->llcp_feature.features_peer = 0; - conn->llcp_version.req = conn->llcp_version.ack = 0; - conn->llcp_version.tx = conn->llcp_version.rx = 0U; - conn->llcp_terminate.req = conn->llcp_terminate.ack = 0U; - conn->llcp_terminate.reason_final = 0U; - /* NOTE: use allocated link for generating dedicated - * terminate ind rx node - */ - conn->llcp_terminate.node_rx.hdr.link = link; - +/* TODO: verify if we need to enable CTLR_RX_ENQUEUE_HOLD */ #if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) conn->llcp_rx_hold = NULL; conn_lll->rx_hold_req = 0U; conn_lll->rx_hold_ack = 0U; #endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ -#if defined(CONFIG_BT_CTLR_LE_ENC) - conn_lll->enc_rx = conn_lll->enc_tx = 0U; - conn->llcp_enc.req = conn->llcp_enc.ack = 0U; - conn->llcp_enc.pause_tx = conn->llcp_enc.pause_rx = 0U; - conn->llcp_enc.refresh = 0U; -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - conn->llcp_conn_param.req = 0U; - conn->llcp_conn_param.ack = 0U; - conn->llcp_conn_param.cache.timeout = 0U; - conn->llcp_conn_param.disabled = 0U; -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - conn->llcp_length.req = conn->llcp_length.ack = 0U; - conn->llcp_length.disabled = 0U; - conn->llcp_length.cache.tx_octets = 0U; - conn->default_tx_octets = ull_conn_default_tx_octets_get(); - -#if defined(CONFIG_BT_CTLR_PHY) - conn->default_tx_time = ull_conn_default_tx_time_get(); -#endif /* CONFIG_BT_CTLR_PHY */ -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - -#if defined(CONFIG_BT_CTLR_PHY) - conn->llcp_phy.req = conn->llcp_phy.ack = 0U; - conn->llcp_phy.disabled = 0U; - conn->llcp_phy.pause_tx = 0U; - conn->phy_pref_tx = ull_conn_default_phy_tx_get(); - conn->phy_pref_rx = ull_conn_default_phy_rx_get(); -#endif /* CONFIG_BT_CTLR_PHY */ - - conn->tx_head = conn->tx_ctrl = conn->tx_ctrl_last = - conn->tx_data = conn->tx_data_last = 0; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ /* Re-initialize the control procedure data structures */ ull_llcp_init(conn); @@ -396,7 +315,6 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, /* Re-initialize the Tx Q */ ull_tx_q_init(&conn->tx_q); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ /* TODO: active_to_start feature port */ conn->ull.ticks_active_to_start = 0U; @@ -426,24 +344,20 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, ready_delay_us = lll_radio_tx_ready_delay_get(0, 0); #endif -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) + /* TODO(thoh-ot): Not entirely sure this is correct */ #if defined(CONFIG_BT_CTLR_DATA_LENGTH) -#if defined(CONFIG_BT_CTLR_PHY) + /* TODO: do we need to do the following? */ #if defined(CONFIG_BT_CTLR_ADV_EXT) - conn_lll->max_tx_time = MAX(conn_lll->max_tx_time, - PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - lll->phy)); - conn_lll->max_rx_time = MAX(conn_lll->max_rx_time, - PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - lll->phy)); + conn_lll->dle.eff.max_tx_time = MAX(conn_lll->dle.eff.max_tx_time, + PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, + lll->phy)); + conn_lll->dle.eff.max_rx_time = MAX(conn_lll->dle.eff.max_rx_time, + PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, + lll->phy)); #endif /* CONFIG_BT_CTLR_ADV_EXT */ - max_tx_time = conn_lll->max_tx_time; - max_rx_time = conn_lll->max_rx_time; -#else /* !CONFIG_BT_CTLR_PHY */ - max_tx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M); - max_rx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M); -#endif /* !CONFIG_BT_CTLR_PHY */ -#else /* !CONFIG_BT_CTLR_DATA_LENGTH */ + max_tx_time = conn_lll->dle.eff.max_tx_time; + max_rx_time = conn_lll->dle.eff.max_rx_time; +#else /* CONFIG_BT_CTLR_DATA_LENGTH */ max_tx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M); max_rx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M); #if defined(CONFIG_BT_CTLR_ADV_EXT) @@ -452,22 +366,7 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, max_rx_time = MAX(max_rx_time, PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, lll->phy)); #endif /* CONFIG_BT_CTLR_ADV_EXT */ -#endif /* !CONFIG_BT_CTLR_DATA_LENGTH */ -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) -#if defined(CONFIG_BT_CTLR_ADV_EXT) - conn->lll.dle.eff.max_tx_time = MAX(conn->lll.dle.eff.max_tx_time, - PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, lll->phy)); - conn->lll.dle.eff.max_rx_time = MAX(conn->lll.dle.eff.max_rx_time, - PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, lll->phy)); -#endif /* CONFIG_BT_CTLR_ADV_EXT */ - max_tx_time = conn_lll->dle.eff.max_tx_time; - max_rx_time = conn_lll->dle.eff.max_rx_time; -#else /* !CONFIG_BT_CTLR_DATA_LENGTH */ - max_tx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M); - max_rx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M); -#endif /* !CONFIG_BT_CTLR_DATA_LENGTH */ -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ +#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US + @@ -658,77 +557,12 @@ uint8_t ll_enc_req_send(uint16_t handle, uint8_t const *const rand_num, uint8_t const *const ediv, uint8_t const *const ltk) { struct ll_conn *conn; - struct node_tx *tx; conn = ll_connected_get(handle); if (!conn) { return BT_HCI_ERR_UNKNOWN_CONN_ID; } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if ((conn->llcp_enc.req != conn->llcp_enc.ack) || - ((conn->llcp_req != conn->llcp_ack) && - (conn->llcp_type == LLCP_ENCRYPTION))) { - return BT_HCI_ERR_CMD_DISALLOWED; - } - - tx = ll_tx_mem_acquire(); - if (tx) { - struct pdu_data *pdu_data_tx; - - pdu_data_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_data_tx); - - memcpy(&conn->llcp_enc.ltk[0], ltk, sizeof(conn->llcp_enc.ltk)); - - if (!conn->lll.enc_rx && !conn->lll.enc_tx) { - struct pdu_data_llctrl_enc_req *enc_req; - - pdu_data_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_data_tx->len = - offsetof(struct pdu_data_llctrl, enc_rsp) + - sizeof(struct pdu_data_llctrl_enc_req); - pdu_data_tx->llctrl.opcode = - PDU_DATA_LLCTRL_TYPE_ENC_REQ; - enc_req = (void *) - &pdu_data_tx->llctrl.enc_req; - memcpy(enc_req->rand, rand_num, sizeof(enc_req->rand)); - enc_req->ediv[0] = ediv[0]; - enc_req->ediv[1] = ediv[1]; - lll_csrand_get(enc_req->skdm, sizeof(enc_req->skdm)); - lll_csrand_get(enc_req->ivm, sizeof(enc_req->ivm)); - } else if (conn->lll.enc_rx && conn->lll.enc_tx) { - memcpy(&conn->llcp_enc.rand[0], rand_num, - sizeof(conn->llcp_enc.rand)); - - conn->llcp_enc.ediv[0] = ediv[0]; - conn->llcp_enc.ediv[1] = ediv[1]; - - pdu_data_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_data_tx->len = offsetof(struct pdu_data_llctrl, - enc_req); - pdu_data_tx->llctrl.opcode = - PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_REQ; - } else { - ll_tx_mem_release(tx); - - return BT_HCI_ERR_CMD_DISALLOWED; - } - - if (ll_tx_mem_enqueue(handle, tx)) { - ll_tx_mem_release(tx); - - return BT_HCI_ERR_CMD_DISALLOWED; - } - - conn->llcp_enc.req++; - - return 0; - } -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - ARG_UNUSED(tx); - if (!conn->lll.enc_tx && !conn->lll.enc_rx) { /* Encryption is fully disabled */ return ull_cp_encryption_start(conn, rand_num, ediv, ltk); @@ -736,7 +570,6 @@ uint8_t ll_enc_req_send(uint16_t handle, uint8_t const *const rand_num, /* Encryption is fully enabled */ return ull_cp_encryption_pause(conn, rand_num, ediv, ltk); } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ return BT_HCI_ERR_CMD_DISALLOWED; } @@ -911,10 +744,8 @@ void ull_central_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, lll->handle = ll_conn_handle_get(conn); rx->handle = lll->handle; -#if (!defined(CONFIG_BT_LL_SW_LLCP_LEGACY)) /* Set LLCP as connection-wise connected */ ull_cp_state_set(conn, ULL_CP_CONNECTED); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ #if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL) lll->tx_pwr_lvl = RADIO_TXP_DEFAULT; @@ -1147,33 +978,18 @@ uint8_t ull_central_chm_update(void) while (handle--) { struct ll_conn *conn; uint8_t ret; + uint8_t chm[5]; conn = ll_connected_get(handle); if (!conn || conn->lll.role) { continue; } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - ret = ull_conn_llcp_req(conn); - if (ret) { - return ret; - } - - /* Fill Channel Map here, fill instant when enqueued to LLL */ - ull_chan_map_get(conn->llcp.chan_map.chm); - conn->llcp.chan_map.initiate = 1U; - - conn->llcp_type = LLCP_CHAN_MAP; - conn->llcp_req++; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - uint8_t chm[5]; - ull_chan_map_get(chm); ret = ull_cp_chan_map_update(conn, chm); if (ret) { return ret; } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ } return 0; diff --git a/subsys/bluetooth/controller/ll_sw/ull_chan_internal.h b/subsys/bluetooth/controller/ll_sw/ull_chan_internal.h index cfc6dd0ead47..bcef535b4fe9 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_chan_internal.h +++ b/subsys/bluetooth/controller/ll_sw/ull_chan_internal.h @@ -6,6 +6,4 @@ int ull_chan_reset(void); uint8_t ull_chan_map_get(uint8_t *const chan_map); -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) void ull_chan_map_set(uint8_t const *const chan_map); -#endif diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index 38d12a0ee5dc..49a5464b2f61 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -36,9 +36,7 @@ #include "lll_conn_iso.h" #include "lll/lll_vendor.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#include "ull_tx_queue.h" -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ +#include "ll_sw/ull_tx_queue.h" #include "isoal.h" #include "ull_iso_types.h" @@ -50,9 +48,7 @@ #endif /* CONFIG_BT_CTLR_USER_EXT */ #include "ull_internal.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) #include "ull_llcp_internal.h" -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ #include "ull_sched_internal.h" #include "ull_chan_internal.h" #include "ull_conn_internal.h" @@ -68,10 +64,8 @@ #include "ll_feat.h" #include "ll_settings.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#include "ull_llcp.h" -#include "ull_llcp_features.h" -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ +#include "ll_sw/ull_llcp.h" +#include "ll_sw/ull_llcp_features.h" #include "hal/debug.h" @@ -116,64 +110,6 @@ static int empty_data_start_release(struct ll_conn *conn, struct node_tx *tx); struct ll_conn *conn_upd_curr; #endif /* defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -static inline void ctrl_tx_enqueue(struct ll_conn *conn, struct node_tx *tx); -static inline void event_fex_prep(struct ll_conn *conn); -static inline void event_vex_prep(struct ll_conn *conn); -static inline int event_conn_upd_prep(struct ll_conn *conn, uint16_t lazy, - uint32_t ticks_at_expire); -static inline void event_ch_map_prep(struct ll_conn *conn, - uint16_t event_counter); - -#if defined(CONFIG_BT_CTLR_LE_ENC) -static inline void ctrl_tx_check_and_resume(struct ll_conn *conn); -static bool is_enc_req_pause_tx(struct ll_conn *conn); -static inline void event_enc_prep(struct ll_conn *conn); -#if defined(CONFIG_BT_PERIPHERAL) -static int enc_rsp_send(struct ll_conn *conn); -#endif /* CONFIG_BT_PERIPHERAL */ -static int start_enc_rsp_send(struct ll_conn *conn, - struct pdu_data *pdu_ctrl_tx); -static inline bool ctrl_is_unexpected(struct ll_conn *conn, uint8_t opcode); -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) -static inline void event_conn_param_prep(struct ll_conn *conn, - uint16_t event_counter, - uint32_t ticks_at_expire); -static void cpr_cache_initiate_or_complete(struct ll_conn *conn); -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - -#if defined(CONFIG_BT_CTLR_LE_PING) -static inline void event_ping_prep(struct ll_conn *conn); -#endif /* CONFIG_BT_CTLR_LE_PING */ - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) -static inline void event_len_prep(struct ll_conn *conn); -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - -#if defined(CONFIG_BT_CTLR_PHY) -static inline void event_phy_req_prep(struct ll_conn *conn); -static inline void event_phy_upd_ind_prep(struct ll_conn *conn, - uint16_t event_counter); -#endif /* CONFIG_BT_CTLR_PHY */ - -#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) -static inline void event_send_cis_rsp(struct ll_conn *conn, - uint16_t event_counter); -static inline void event_peripheral_iso_prep(struct ll_conn *conn, - uint16_t event_counter, - uint32_t ticks_at_expire); -#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO */ - -static inline void ctrl_tx_pre_ack(struct ll_conn *conn, - struct pdu_data *pdu_tx); -static inline void ctrl_tx_ack(struct ll_conn *conn, struct node_tx **tx, - struct pdu_data *pdu_tx); -static inline int ctrl_rx(memq_link_t *link, struct node_rx_pdu **rx, - struct pdu_data *pdu_rx, struct ll_conn *conn); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - #if defined(CONFIG_BT_CTLR_FORCE_MD_AUTO) static uint8_t force_md_cnt_calc(struct lll_conn *lll_conn, uint32_t tx_rate); #endif /* CONFIG_BT_CTLR_FORCE_MD_AUTO */ @@ -192,12 +128,9 @@ static uint8_t force_md_cnt_calc(struct lll_conn *lll_conn, uint32_t tx_rate); * they are transmitted out to peer before encryption is setup. * Allocate additional Tx buffers to accommodate simultaneous encryption setup * across active connections. + * TODO: verify that we don't need this for the refactored LLCP */ -#if defined(CONFIG_BT_CTLR_LE_ENC) && defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#define CONN_ENC_REQ_BUFFERS CONFIG_BT_CTLR_LLCP_CONN -#else #define CONN_ENC_REQ_BUFFERS 0 -#endif #define CONN_DATA_BUFFERS (CONFIG_BT_BUF_ACL_TX_COUNT + CONN_ENC_REQ_BUFFERS) /** @@ -205,11 +138,7 @@ static uint8_t force_md_cnt_calc(struct lll_conn *lll_conn, uint32_t tx_rate); * simultaneously, for example 2 for encryption, 1 for termination, * and 1 one that is in flight and has not been returned to the pool */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#define CONN_TX_CTRL_BUFFERS (4 * CONFIG_BT_CTLR_LLCP_CONN) -#else /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ #define CONN_TX_CTRL_BUFFERS LLCP_TX_CTRL_BUF_COUNT -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ #define CONN_TX_CTRL_BUF_SIZE MROUND(offsetof(struct node_tx, pdu) + \ offsetof(struct pdu_data, llctrl) + \ PDU_DC_CTRL_TX_SIZE_MAX) @@ -235,13 +164,6 @@ static struct { uint8_t pool[CONN_TX_BUF_SIZE * CONN_DATA_BUFFERS]; } mem_conn_tx; -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -static struct { - void *free; - uint8_t pool[CONN_TX_CTRL_BUF_SIZE * CONN_TX_CTRL_BUFFERS]; -} mem_conn_tx_ctrl; -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - static struct { void *free; uint8_t pool[sizeof(memq_link_t) * @@ -402,97 +324,6 @@ uint8_t ll_conn_update(uint16_t handle, uint8_t cmd, uint8_t status, uint16_t in return BT_HCI_ERR_UNKNOWN_CONN_ID; } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - /* Anchor point move not supported in Legacy LLCP */ - ARG_UNUSED(offset); - if (!cmd) { -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - if (!conn->llcp_conn_param.disabled && - (!conn->common.fex_valid || - (conn->llcp_feature.features_conn & - BIT64(BT_LE_FEAT_BIT_CONN_PARAM_REQ)))) { - cmd++; - } else if (conn->lll.role) { - return BT_HCI_ERR_UNSUPP_REMOTE_FEATURE; - } -#else /* !CONFIG_BT_CTLR_CONN_PARAM_REQ */ - if (conn->lll.role) { - return BT_HCI_ERR_CMD_DISALLOWED; - } -#endif /* !CONFIG_BT_CTLR_CONN_PARAM_REQ */ - } - - if (!cmd) { - if (conn->llcp_cu.req != conn->llcp_cu.ack) { - return BT_HCI_ERR_CMD_DISALLOWED; - } - - conn->llcp_cu.win_size = 1U; - conn->llcp_cu.win_offset_us = 0U; - conn->llcp_cu.interval = interval_max; - conn->llcp_cu.latency = latency; - conn->llcp_cu.timeout = timeout; - conn->llcp_cu.state = LLCP_CUI_STATE_USE; - conn->llcp_cu.cmd = 1U; - - conn->llcp_cu.req++; - } else { -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - cmd--; - - if (cmd) { - if ((conn->llcp_conn_param.req == - conn->llcp_conn_param.ack) || - (conn->llcp_conn_param.state != - LLCP_CPR_STATE_APP_WAIT)) { - return BT_HCI_ERR_CMD_DISALLOWED; - } - - conn->llcp_conn_param.status = status; - conn->llcp_conn_param.state = cmd; - conn->llcp_conn_param.cmd = 1U; - } else { - if (conn->llcp_conn_param.req != - conn->llcp_conn_param.ack) { - if (!conn->llcp_conn_param.remote || - conn->llcp_conn_param.cache.timeout) { - return BT_HCI_ERR_CMD_DISALLOWED; - } - - conn->llcp_conn_param.cache.interval_min = - interval_min; - conn->llcp_conn_param.cache.interval_max = - interval_max; - conn->llcp_conn_param.cache.latency = - latency; - conn->llcp_conn_param.cache.timeout = - timeout; - - return BT_HCI_ERR_SUCCESS; - } - - conn->llcp_conn_param.status = 0U; - conn->llcp_conn_param.interval_min = interval_min; - conn->llcp_conn_param.interval_max = interval_max; - conn->llcp_conn_param.latency = latency; - conn->llcp_conn_param.timeout = timeout; - conn->llcp_conn_param.state = cmd; - conn->llcp_conn_param.cmd = 1U; - conn->llcp_conn_param.remote = 0U; - conn->llcp_conn_param.req++; - - if (IS_ENABLED(CONFIG_BT_PERIPHERAL) && - conn->lll.role) { - ull_periph_latency_cancel(conn, handle); - } - } - -#else /* !CONFIG_BT_CTLR_CONN_PARAM_REQ */ - /* CPR feature not supported */ - return BT_HCI_ERR_CMD_DISALLOWED; -#endif /* !CONFIG_BT_CTLR_CONN_PARAM_REQ */ - } -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ if (cmd == 0U) { uint8_t err; @@ -521,7 +352,6 @@ uint8_t ll_conn_update(uint16_t handle, uint8_t cmd, uint8_t status, uint16_t in } else { return BT_HCI_ERR_UNKNOWN_CMD; } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ return 0; } @@ -535,16 +365,6 @@ uint8_t ll_chm_get(uint16_t handle, uint8_t *chm) return BT_HCI_ERR_UNKNOWN_CONN_ID; } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - /* Iterate until we are sure the ISR did not modify the value while - * we were reading it from memory. - */ - do { - conn->chm_updated = 0U; - memcpy(chm, conn->lll.data_chan_map, - sizeof(conn->lll.data_chan_map)); - } while (conn->chm_updated); -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ /* * Core Spec 5.2 Vol4: 7.8.20: * The HCI_LE_Read_Channel_Map command returns the current Channel_Map @@ -562,7 +382,6 @@ uint8_t ll_chm_get(uint16_t handle, uint8_t *chm) } else { memcpy(chm, conn->lll.data_chan_map, sizeof(conn->lll.data_chan_map)); } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ return 0; } @@ -612,27 +431,16 @@ uint8_t ll_terminate_ind_send(uint16_t handle, uint8_t reason) return BT_HCI_ERR_CMD_DISALLOWED; } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if (conn->llcp_terminate.req != conn->llcp_terminate.ack) { - return BT_HCI_ERR_CMD_DISALLOWED; - } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - if (!is_valid_disconnect_reason(reason)) { return BT_HCI_ERR_INVALID_PARAM; } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - conn->llcp_terminate.reason_own = reason; - conn->llcp_terminate.req++; /* (req - ack) == 1, TERM_REQ */ -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ uint8_t err; err = ull_cp_terminate(conn, reason); if (err) { return err; } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ if (IS_ENABLED(CONFIG_BT_PERIPHERAL) && conn->lll.role) { ull_periph_latency_cancel(conn, handle); @@ -641,7 +449,6 @@ uint8_t ll_terminate_ind_send(uint16_t handle, uint8_t reason) } #if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) || defined(CONFIG_BT_CTLR_CENTRAL_ISO) if (IS_CIS_HANDLE(handle)) { -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) cis = ll_iso_stream_connected_get(handle); /* Disallow if CIS is not connected */ if (!cis) { @@ -655,11 +462,6 @@ uint8_t ll_terminate_ind_send(uint16_t handle, uint8_t reason) } return ull_cp_cis_terminate(conn, cis, reason); -#else - ARG_UNUSED(cis); - /* LEGACY LLCP does not support CIS Terminate procedure */ - return BT_HCI_ERR_UNKNOWN_CMD; -#endif /* !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) */ } #endif /* defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) || defined(CONFIG_BT_CTLR_CENTRAL_ISO) */ @@ -676,20 +478,12 @@ uint8_t ll_feature_req_send(uint16_t handle) return BT_HCI_ERR_UNKNOWN_CONN_ID; } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if (conn->llcp_feature.req != conn->llcp_feature.ack) { - return BT_HCI_ERR_CMD_DISALLOWED; - } - - conn->llcp_feature.req++; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ uint8_t err; err = ull_cp_feature_exchange(conn); if (err) { return err; } -#endif if (IS_ENABLED(CONFIG_BT_PERIPHERAL) && IS_ENABLED(CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG) && @@ -710,20 +504,12 @@ uint8_t ll_version_ind_send(uint16_t handle) return BT_HCI_ERR_UNKNOWN_CONN_ID; } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if (conn->llcp_version.req != conn->llcp_version.ack) { - return BT_HCI_ERR_CMD_DISALLOWED; - } - - conn->llcp_version.req++; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ uint8_t err; err = ull_cp_version_exchange(conn); if (err) { return err; } -#endif if (IS_ENABLED(CONFIG_BT_PERIPHERAL) && conn->lll.role) { ull_periph_latency_cancel(conn, handle); @@ -765,57 +551,6 @@ uint32_t ll_length_req_send(uint16_t handle, uint16_t tx_octets, return BT_HCI_ERR_UNKNOWN_CONN_ID; } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if (conn->llcp_length.disabled || - (conn->common.fex_valid && - !(conn->llcp_feature.features_conn & BIT64(BT_LE_FEAT_BIT_DLE)))) { - return BT_HCI_ERR_UNSUPP_REMOTE_FEATURE; - } - -#if defined(CONFIG_BT_CTLR_PHY) -#if defined(CONFIG_BT_CTLR_PHY_CODED) - const uint16_t tx_time_max = - PDU_DC_MAX_US(LL_LENGTH_OCTETS_TX_MAX, PHY_CODED); -#else /* !CONFIG_BT_CTLR_PHY_CODED */ - const uint16_t tx_time_max = - PDU_DC_MAX_US(LL_LENGTH_OCTETS_TX_MAX, PHY_1M); -#endif /* !CONFIG_BT_CTLR_PHY_CODED */ - - if (tx_time > tx_time_max) { - tx_time = tx_time_max; - } -#endif /* CONFIG_BT_CTLR_PHY */ - - if (conn->llcp_length.req != conn->llcp_length.ack) { - switch (conn->llcp_length.state) { - case LLCP_LENGTH_STATE_RSP_ACK_WAIT: - case LLCP_LENGTH_STATE_RESIZE_RSP: - case LLCP_LENGTH_STATE_RESIZE_RSP_ACK_WAIT: - /* cached until peer procedure completes */ - if (!conn->llcp_length.cache.tx_octets) { - conn->llcp_length.cache.tx_octets = tx_octets; -#if defined(CONFIG_BT_CTLR_PHY) - conn->llcp_length.cache.tx_time = tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - return 0; - } - __fallthrough; - default: - return BT_HCI_ERR_CMD_DISALLOWED; - } - } - - /* TODO: parameter check tx_octets and tx_time */ - - conn->llcp_length.state = LLCP_LENGTH_STATE_REQ; - conn->llcp_length.tx_octets = tx_octets; - -#if defined(CONFIG_BT_CTLR_PHY) - conn->llcp_length.tx_time = tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - - conn->llcp_length.req++; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ if (!feature_dle(conn)) { return BT_HCI_ERR_UNSUPP_REMOTE_FEATURE; } @@ -826,7 +561,6 @@ uint32_t ll_length_req_send(uint16_t handle, uint16_t tx_octets, if (err) { return err; } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ if (IS_ENABLED(CONFIG_BT_PERIPHERAL) && conn->lll.role) { ull_periph_latency_cancel(conn, handle); @@ -906,26 +640,6 @@ uint8_t ll_phy_req_send(uint16_t handle, uint8_t tx, uint8_t flags, uint8_t rx) return BT_HCI_ERR_UNKNOWN_CONN_ID; } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if (conn->llcp_phy.disabled || - (conn->common.fex_valid && - !(conn->llcp_feature.features_conn & BIT64(BT_LE_FEAT_BIT_PHY_2M)) && - !(conn->llcp_feature.features_conn & - BIT64(BT_LE_FEAT_BIT_PHY_CODED)))) { - return BT_HCI_ERR_UNSUPP_REMOTE_FEATURE; - } - - if (conn->llcp_phy.req != conn->llcp_phy.ack) { - return BT_HCI_ERR_CMD_DISALLOWED; - } - - conn->llcp_phy.state = LLCP_PHY_STATE_REQ; - conn->llcp_phy.cmd = 1U; - conn->llcp_phy.tx = tx; - conn->llcp_phy.flags = flags; - conn->llcp_phy.rx = rx; - conn->llcp_phy.req++; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ if (!feature_phy_2m(conn) && !feature_phy_coded(conn)) { return BT_HCI_ERR_UNSUPP_REMOTE_FEATURE; } @@ -936,7 +650,6 @@ uint8_t ll_phy_req_send(uint16_t handle, uint8_t tx, uint8_t flags, uint8_t rx) if (err) { return err; } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ if (IS_ENABLED(CONFIG_BT_PERIPHERAL) && conn->lll.role) { ull_periph_latency_cancel(conn, handle); @@ -1138,26 +851,19 @@ int ull_conn_rx(memq_link_t *link, struct node_rx_pdu **rx) } #if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) + /* TODO: is this required for refactored LLCP? */ if (conn->llcp_rx_hold && rx_hold_is_done(conn)) { rx_hold_flush(conn); } #endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) ull_cp_tx_ntf(conn); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ pdu_rx = (void *)(*rx)->pdu; switch (pdu_rx->ll_id) { case PDU_DATA_LLID_CTRL: { -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - int nack; - - nack = ctrl_rx(link, rx, pdu_rx, conn); - return nack; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ ARG_UNUSED(link); ARG_UNUSED(pdu_rx); @@ -1166,17 +872,12 @@ int ull_conn_rx(memq_link_t *link, struct node_rx_pdu **rx) /* Mark buffer for release */ (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; return 0; -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ } case PDU_DATA_LLID_DATA_CONTINUE: case PDU_DATA_LLID_DATA_START: #if defined(CONFIG_BT_CTLR_LE_ENC) -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if (conn->llcp_enc.pause_rx) { -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ if (conn->pause_rx_data) { -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ conn->llcp_terminate.reason_final = BT_HCI_ERR_TERM_DUE_TO_MIC_FAIL; @@ -1189,11 +890,7 @@ int ull_conn_rx(memq_link_t *link, struct node_rx_pdu **rx) case PDU_DATA_LLID_RESV: default: #if defined(CONFIG_BT_CTLR_LE_ENC) -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if (conn->llcp_enc.pause_rx) { -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ if (conn->pause_rx_data) { -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ conn->llcp_terminate.reason_final = BT_HCI_ERR_TERM_DUE_TO_MIC_FAIL; } @@ -1213,291 +910,6 @@ int ull_conn_rx(memq_link_t *link, struct node_rx_pdu **rx) int ull_conn_llcp(struct ll_conn *conn, uint32_t ticks_at_expire, uint16_t lazy) { -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - /* Check if no other procedure with instant is requested and not in - * Encryption setup. - */ - if ((conn->llcp_ack == conn->llcp_req) && -#if defined(CONFIG_BT_CTLR_LE_ENC) -#if defined(CONFIG_BT_PERIPHERAL) - (!conn->lll.role || (conn->periph.llcp_type == LLCP_NONE)) && -#endif /* CONFIG_BT_PERIPHERAL */ - !conn->llcp_enc.pause_rx) { -#else /* !CONFIG_BT_CTLR_LE_ENC */ - 1) { -#endif /* !CONFIG_BT_CTLR_LE_ENC */ - - /* TODO: Optimize the checks below, maybe have common flag */ - - /* check if connection update procedure is requested */ - if (conn->llcp_cu.ack != conn->llcp_cu.req) { - /* Delay until all pending Tx in LLL is acknowledged, - * new Tx PDUs will not be enqueued until we proceed to - * initiate connection update and get acknowledged. - * This is required to ensure PDU with instant can be - * transmitted before instant expires. - */ - if (memq_peek(conn->lll.memq_tx.head, - conn->lll.memq_tx.tail, NULL)) { - return 0; - } - - /* switch to LLCP_CONN_UPD state machine */ - conn->llcp_type = LLCP_CONN_UPD; - conn->llcp_ack -= 2U; - -#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) - } else if (conn->llcp_cis.req != conn->llcp_cis.ack) { - if (conn->llcp_cis.state == LLCP_CIS_STATE_RSP_WAIT) { - const struct lll_conn *lll = &conn->lll; - uint16_t event_counter; - - /* Calculate current event counter */ - event_counter = lll->event_counter + - lll->latency_prepare + lazy; - - /* Handle CIS response */ - event_send_cis_rsp(conn, event_counter); - } - -#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO */ - /* check if feature exchange procedure is requested */ - } else if (conn->llcp_feature.ack != conn->llcp_feature.req) { - /* handle feature exchange state machine */ - event_fex_prep(conn); - - /* check if version info procedure is requested */ - } else if (conn->llcp_version.ack != conn->llcp_version.req) { - /* handle version info state machine */ - event_vex_prep(conn); - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - /* check if CPR procedure is requested */ - } else if (conn->llcp_conn_param.ack != - conn->llcp_conn_param.req) { - struct lll_conn *lll = &conn->lll; - uint16_t event_counter; - - /* Calculate current event counter */ - event_counter = lll->event_counter + - lll->latency_prepare + lazy; - - /* handle CPR state machine */ - event_conn_param_prep(conn, event_counter, - ticks_at_expire); -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - /* check if DLE procedure is requested */ - } else if (conn->llcp_length.ack != conn->llcp_length.req) { - /* handle DLU state machine */ - event_len_prep(conn); -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - -#if defined(CONFIG_BT_CTLR_PHY) - /* check if PHY Req procedure is requested */ - } else if (conn->llcp_phy.ack != conn->llcp_phy.req) { - /* handle PHY Upd state machine */ - event_phy_req_prep(conn); -#endif /* CONFIG_BT_CTLR_PHY */ - } - } - - /* Check if procedures with instant or encryption setup is requested or - * active. - */ - if (((conn->llcp_req - conn->llcp_ack) & 0x03) == 0x02) { - /* Process parallel procedures that are active */ - if (0) { -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - /* Check if DLE in progress */ - } else if (conn->llcp_length.ack != conn->llcp_length.req) { - if ((conn->llcp_length.state == - LLCP_LENGTH_STATE_RESIZE) || - (conn->llcp_length.state == - LLCP_LENGTH_STATE_RESIZE_RSP)) { - /* handle DLU state machine */ - event_len_prep(conn); - } -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - } - - /* Process procedures with instants or encryption setup */ - /* FIXME: Make LE Ping cacheable */ - switch (conn->llcp_type) { - case LLCP_CONN_UPD: - { - if (event_conn_upd_prep(conn, lazy, - ticks_at_expire) == 0) { - return -ECANCELED; - } - } - break; - - case LLCP_CHAN_MAP: - { - struct lll_conn *lll = &conn->lll; - uint16_t event_counter; - - /* Calculate current event counter */ - event_counter = lll->event_counter + - lll->latency_prepare + lazy; - - event_ch_map_prep(conn, event_counter); - } - break; - -#if defined(CONFIG_BT_CTLR_LE_ENC) - case LLCP_ENCRYPTION: - event_enc_prep(conn); - break; -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -#if defined(CONFIG_BT_CTLR_LE_PING) - case LLCP_PING: - event_ping_prep(conn); - break; -#endif /* CONFIG_BT_CTLR_LE_PING */ - -#if defined(CONFIG_BT_CTLR_PHY) - case LLCP_PHY_UPD: - { - struct lll_conn *lll = &conn->lll; - uint16_t event_counter; - - /* Calculate current event counter */ - event_counter = lll->event_counter + - lll->latency_prepare + lazy; - - event_phy_upd_ind_prep(conn, event_counter); - } - break; -#endif /* CONFIG_BT_CTLR_PHY */ - - default: - LL_ASSERT(0); - break; - } - } - -#if defined(CONFIG_BT_PERIPHERAL) && defined(CONFIG_BT_CTLR_LE_ENC) - /* Run any pending local peripheral role initiated procedure stored when - * peer central initiated a encryption procedure - */ - if (conn->lll.role && (conn->periph.llcp_type != LLCP_NONE)) { - switch (conn->periph.llcp_type) { - case LLCP_CONN_UPD: - { - if (event_conn_upd_prep(conn, lazy, - ticks_at_expire) == 0) { - return -ECANCELED; - } - } - break; - - case LLCP_CHAN_MAP: - { - struct lll_conn *lll = &conn->lll; - uint16_t event_counter; - - /* Calculate current event counter */ - event_counter = lll->event_counter + - lll->latency_prepare + lazy; - - event_ch_map_prep(conn, event_counter); - } - break; - -#if defined(CONFIG_BT_CTLR_PHY) - case LLCP_PHY_UPD: - { - struct lll_conn *lll = &conn->lll; - uint16_t event_counter; - - /* Calculate current event counter */ - event_counter = lll->event_counter + - lll->latency_prepare + lazy; - - event_phy_upd_ind_prep(conn, event_counter); - } - break; -#endif /* CONFIG_BT_CTLR_PHY */ - - default: - LL_ASSERT(0); - break; - } - } -#endif /* CONFIG_BT_PERIPHERAL && CONFIG_BT_CTLR_LE_ENC */ - - /* Terminate Procedure Request */ - if (((conn->llcp_terminate.req - conn->llcp_terminate.ack) & 0xFF) == - TERM_REQ) { - struct node_tx *tx; - - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (tx) { - struct pdu_data *pdu_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_tx); - - /* Terminate Procedure initiated, - * make (req - ack) == 2 - */ - conn->llcp_terminate.ack--; - - /* place the terminate ind packet in tx queue */ - pdu_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_tx->len = offsetof(struct pdu_data_llctrl, - terminate_ind) + - sizeof(struct pdu_data_llctrl_terminate_ind); - pdu_tx->llctrl.opcode = - PDU_DATA_LLCTRL_TYPE_TERMINATE_IND; - pdu_tx->llctrl.terminate_ind.error_code = - conn->llcp_terminate.reason_own; - - ctrl_tx_enqueue(conn, tx); - } - - if (!conn->procedure_expire) { - /* Terminate Procedure timeout is started, will - * replace any other timeout running - */ - const uint32_t conn_interval_us = conn->lll.interval * CONN_INT_UNIT_US; - - conn->procedure_expire = RADIO_CONN_EVENTS( - (conn->supervision_timeout * 10U * 1000U), - conn_interval_us); - - /* NOTE: if supervision timeout equals connection - * interval, dont timeout in current event. - */ - if (conn->procedure_expire <= 1U) { - conn->procedure_expire++; - } - } - } - -#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) - /* In any state, allow processing of CIS peripheral waiting for - * instant. - */ - if (conn->llcp_cis.state == LLCP_CIS_STATE_INST_WAIT) { - const struct lll_conn *lll = &conn->lll; - uint16_t event_counter; - - /* Calculate current event counter */ - event_counter = lll->event_counter + - lll->latency_prepare + lazy; - - event_peripheral_iso_prep(conn, event_counter, - ticks_at_expire); - - } -#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO */ - - return 0; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ LL_ASSERT(conn->lll.handle != LLL_HANDLE_INVALID); conn->llcp.prep.ticks_at_expire = ticks_at_expire; @@ -1515,7 +927,6 @@ int ull_conn_llcp(struct ll_conn *conn, uint32_t ticks_at_expire, uint16_t lazy) /* Continue prepare */ return 0; -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ } void ull_conn_done(struct node_rx_event_done *done) @@ -1554,20 +965,14 @@ void ull_conn_done(struct node_rx_event_done *done) } #endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) ull_cp_tx_ntf(conn); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ #if defined(CONFIG_BT_CTLR_LE_ENC) /* Check authenticated payload expiry or MIC failure */ switch (done->extra.mic_state) { case LLL_CONN_MIC_NONE: #if defined(CONFIG_BT_CTLR_LE_PING) -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if (lll->enc_rx || conn->llcp_enc.pause_rx) { -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ if (lll->enc_rx && lll->enc_tx) { -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ uint16_t appto_reload_new; /* check for change in apto */ @@ -1612,26 +1017,7 @@ void ull_conn_done(struct node_rx_event_done *done) * reason_final is set exactly under the above conditions */ reason_final = conn->llcp_terminate.reason_final; - if (reason_final && ( -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#if defined(CONFIG_BT_PERIPHERAL) - lll->role || -#else /* CONFIG_BT_PERIPHERAL */ - false || -#endif /* CONFIG_BT_PERIPHERAL */ -#if defined(CONFIG_BT_CENTRAL) - (((conn->llcp_terminate.req - - conn->llcp_terminate.ack) & 0xFF) == - TERM_ACKED) || - conn->central.terminate_ack || - (reason_final == BT_HCI_ERR_TERM_DUE_TO_MIC_FAIL) -#else /* CONFIG_BT_CENTRAL */ - true -#endif /* CONFIG_BT_CENTRAL */ -#else /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ - true -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ - )) { + if (reason_final) { conn_cleanup(conn, reason_final); return; @@ -1667,19 +1053,6 @@ void ull_conn_done(struct node_rx_event_done *done) ull_drift_ticks_get(done, &ticks_drift_plus, &ticks_drift_minus); -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if (!conn->tx_head) { - ull_conn_tx_demux(UINT8_MAX); - } - - if (conn->tx_head || memq_peek(lll->memq_tx.head, - lll->memq_tx.tail, - NULL)) { - lll->latency_event = 0U; - } else if (lll->periph.latency_enabled) { - lll->latency_event = lll->latency; - } -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ if (!ull_tx_q_peek(&conn->tx_q)) { ull_conn_tx_demux(UINT8_MAX); } @@ -1691,7 +1064,6 @@ void ull_conn_done(struct node_rx_event_done *done) } else if (lll->periph.latency_enabled) { lll->latency_event = lll->latency; } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ #endif /* CONFIG_BT_PERIPHERAL */ #if defined(CONFIG_BT_CENTRAL) @@ -1776,17 +1148,6 @@ void ull_conn_done(struct node_rx_event_done *done) } /* check procedure timeout */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if (conn->procedure_expire != 0U) { - if (conn->procedure_expire > elapsed_event) { - conn->procedure_expire -= elapsed_event; - } else { - conn_cleanup(conn, BT_HCI_ERR_LL_RESP_TIMEOUT); - - return; - } - } -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ uint8_t error_code; if (-ETIMEDOUT == ull_cp_prt_elapse(conn, elapsed_event, &error_code)) { @@ -1794,7 +1155,6 @@ void ull_conn_done(struct node_rx_event_done *done) return; } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ #if defined(CONFIG_BT_CTLR_LE_PING) /* check apto */ @@ -1826,16 +1186,8 @@ void ull_conn_done(struct node_rx_event_done *done) } else { conn->appto_expire = 0U; -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if ((conn->procedure_expire == 0U) && - (conn->llcp_req == conn->llcp_ack)) { - conn->llcp_type = LLCP_PING; - conn->llcp_ack -= 2U; - } -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ /* Initiate LE_PING procedure */ ull_cp_le_ping(conn); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ } } #endif /* CONFIG_BT_CTLR_LE_PING */ @@ -1893,16 +1245,6 @@ void ull_conn_done(struct node_rx_event_done *done) } #endif /* CONFIG_BT_CTLR_CONN_RSSI_EVENT */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - /* break latency based on ctrl procedure pending */ - if (((((conn->llcp_req - conn->llcp_ack) & 0x03) == 0x02) && - ((conn->llcp_type == LLCP_CONN_UPD) || - (conn->llcp_type == LLCP_CHAN_MAP))) || - (conn->llcp_cu.req != conn->llcp_cu.ack)) { - lll->latency_event = 0U; - } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - /* check if latency needs update */ lazy = 0U; if ((force) || (latency_event != lll->latency_event)) { @@ -2016,24 +1358,7 @@ void ull_conn_tx_demux(uint8_t count) } #endif /* CONFIG_BT_CTLR_LLID_DATA_START_EMPTY */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - tx->next = NULL; - if (!conn->tx_data) { - conn->tx_data = tx; - if (!conn->tx_head) { - conn->tx_head = tx; - conn->tx_data_last = NULL; - } - } - - if (conn->tx_data_last) { - conn->tx_data_last->next = tx; - } - - conn->tx_data_last = tx; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ ull_tx_q_enqueue_data(&conn->tx_q, tx); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ } else { struct node_tx *tx = lll_tx->node; struct pdu_data *p = (void *)tx->pdu; @@ -2052,38 +1377,6 @@ void ull_conn_tx_demux(uint8_t count) void ull_conn_tx_lll_enqueue(struct ll_conn *conn, uint8_t count) { -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - bool pause_tx = false; - - while (conn->tx_head && - (( - (conn->llcp_cu.req == conn->llcp_cu.ack) && -#if defined(CONFIG_BT_CTLR_PHY) - !conn->llcp_phy.pause_tx && -#endif /* CONFIG_BT_CTLR_PHY */ -#if defined(CONFIG_BT_CTLR_LE_ENC) - !conn->llcp_enc.pause_tx && - !(pause_tx = is_enc_req_pause_tx(conn)) && -#endif /* CONFIG_BT_CTLR_LE_ENC */ - 1) || - (!pause_tx && (conn->tx_head == conn->tx_ctrl))) && count--) { - struct pdu_data *pdu_tx; - struct node_tx *tx; - memq_link_t *link; - - tx = tx_ull_dequeue(conn, conn->tx_head); - - pdu_tx = (void *)tx->pdu; - if (pdu_tx->ll_id == PDU_DATA_LLID_CTRL) { - ctrl_tx_pre_ack(conn, pdu_tx); - } - - link = mem_acquire(&mem_link_tx.free); - LL_ASSERT(link); - - memq_enqueue(link, tx, &conn->lll.memq_tx.tail); - } -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ while (count--) { struct node_tx *tx; memq_link_t *link; @@ -2100,7 +1393,6 @@ void ull_conn_tx_lll_enqueue(struct ll_conn *conn, uint8_t count) /* Enqueue towards LLL */ memq_enqueue(link, tx, &conn->lll.memq_tx.tail); } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ } void ull_conn_link_tx_release(void *link) @@ -2184,24 +1476,16 @@ void ull_conn_tx_ack(uint16_t handle, memq_link_t *link, struct node_tx *tx) } #endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - ctrl_tx_ack(conn, &tx, pdu_tx); -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ ull_cp_tx_ack(conn, tx); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ } /* release ctrl mem if points to itself */ if (link->next == (void *)tx) { LL_ASSERT(link->next); -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - mem_release(tx, &mem_conn_tx_ctrl.free); -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ struct ll_conn *conn = ll_connected_get(handle); ull_cp_release_tx(conn, tx); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ return; } else if (!tx) { /* Tx Node re-used to enqueue new ctrl PDU */ @@ -2225,28 +1509,9 @@ void ull_conn_tx_ack(uint16_t handle, memq_link_t *link, struct node_tx *tx) ll_tx_ack_put(handle, tx); } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -uint8_t ull_conn_llcp_req(void *conn) +uint16_t ull_conn_lll_max_tx_octets_get(struct lll_conn *lll) { - struct ll_conn * const conn_hdr = conn; - - if (conn_hdr->llcp_req != conn_hdr->llcp_ack) { - return BT_HCI_ERR_CMD_DISALLOWED; - } - - conn_hdr->llcp_req++; - if (((conn_hdr->llcp_req - conn_hdr->llcp_ack) & 0x03) != 1) { - conn_hdr->llcp_req--; - return BT_HCI_ERR_CMD_DISALLOWED; - } - - return 0; -} -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - -uint16_t ull_conn_lll_max_tx_octets_get(struct lll_conn *lll) -{ - uint16_t max_tx_octets; + uint16_t max_tx_octets; #if defined(CONFIG_BT_CTLR_DATA_LENGTH) #if defined(CONFIG_BT_CTLR_PHY) @@ -2257,11 +1522,7 @@ uint16_t ull_conn_lll_max_tx_octets_get(struct lll_conn *lll) * Deduct 10 bytes for preamble (1), access address (4), * header (2), and CRC (3). */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - max_tx_octets = (lll->max_tx_time >> 3) - 10; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ max_tx_octets = (lll->dle.eff.max_tx_time >> 3) - 10; -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ break; case PHY_2M: @@ -2269,11 +1530,7 @@ uint16_t ull_conn_lll_max_tx_octets_get(struct lll_conn *lll) * Deduct 11 bytes for preamble (2), access address (4), * header (2), and CRC (3). */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - max_tx_octets = (lll->max_tx_time >> 2) - 11; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ max_tx_octets = (lll->dle.eff.max_tx_time >> 2) - 11; -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ break; #if defined(CONFIG_BT_CTLR_PHY_CODED) @@ -2286,13 +1543,8 @@ uint16_t ull_conn_lll_max_tx_octets_get(struct lll_conn *lll) * TERM2 (24), total 592 us. * Subtract 2 bytes for header. */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - max_tx_octets = ((lll->max_tx_time - 592) >> - 6) - 2; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ max_tx_octets = ((lll->dle.eff.max_tx_time - 592) >> 6) - 2; -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ } else { /* S2 Coded PHY, 2us = 1 bit, hence divide by * 16. @@ -2301,13 +1553,8 @@ uint16_t ull_conn_lll_max_tx_octets_get(struct lll_conn *lll) * TERM2 (6), total 430 us. * Subtract 2 bytes for header. */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - max_tx_octets = ((lll->max_tx_time - 430) >> - 4) - 2; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ max_tx_octets = ((lll->dle.eff.max_tx_time - 430) >> 4) - 2; -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ } break; #endif /* CONFIG_BT_CTLR_PHY_CODED */ @@ -2320,22 +1567,12 @@ uint16_t ull_conn_lll_max_tx_octets_get(struct lll_conn *lll) } #endif /* CONFIG_BT_CTLR_LE_ENC */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if (max_tx_octets > lll->max_tx_octets) { - max_tx_octets = lll->max_tx_octets; - } -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ if (max_tx_octets > lll->dle.eff.max_tx_octets) { max_tx_octets = lll->dle.eff.max_tx_octets; } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ #else /* !CONFIG_BT_CTLR_PHY */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - max_tx_octets = lll->max_tx_octets; -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ max_tx_octets = lll->dle.eff.max_tx_octets; -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ #endif /* !CONFIG_BT_CTLR_PHY */ #else /* !CONFIG_BT_CTLR_DATA_LENGTH */ max_tx_octets = PDU_DC_PAYLOAD_SIZE_MIN; @@ -2366,22 +1603,14 @@ static int init_reset(void) mem_init(mem_conn_tx.pool, CONN_TX_BUF_SIZE, CONN_DATA_BUFFERS, &mem_conn_tx.free); -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - /* Initialize tx ctrl pool. */ - mem_init(mem_conn_tx_ctrl.pool, CONN_TX_CTRL_BUF_SIZE, - CONN_TX_CTRL_BUFFERS, &mem_conn_tx_ctrl.free); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - /* Initialize tx link pool. */ mem_init(mem_link_tx.pool, sizeof(memq_link_t), (CONN_DATA_BUFFERS + CONN_TX_CTRL_BUFFERS), &mem_link_tx.free); -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) /* Initialize control procedure system. */ ull_cp_init(); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ #if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) /* Reset CPR mutex */ @@ -2489,39 +1718,6 @@ static void tx_demux(void *param) ull_conn_tx_lll_enqueue(param, 1); } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -static struct node_tx *tx_ull_dequeue(struct ll_conn *conn, struct node_tx *tx) -{ -#if defined(CONFIG_BT_CTLR_LE_ENC) - if (!conn->tx_ctrl && (conn->tx_head != conn->tx_data)) { - ctrl_tx_check_and_resume(conn); - } -#endif /* CONFIG_BT_CTLR_LE_ENC */ - - if (conn->tx_head == conn->tx_ctrl) { - conn->tx_head = conn->tx_head->next; - if (conn->tx_ctrl == conn->tx_ctrl_last) { - conn->tx_ctrl = NULL; - conn->tx_ctrl_last = NULL; - } else { - conn->tx_ctrl = conn->tx_head; - } - - /* point to self to indicate a control PDU mem alloc */ - tx->next = tx; - } else { - if (conn->tx_head == conn->tx_data) { - conn->tx_data = conn->tx_data->next; - } - conn->tx_head = conn->tx_head->next; - - /* point to NULL to indicate a Data PDU mem alloc */ - tx->next = NULL; - } - - return tx; -} -#else static struct node_tx *tx_ull_dequeue(struct ll_conn *conn, struct node_tx *unused) { struct node_tx *tx = NULL; @@ -2541,7 +1737,6 @@ static struct node_tx *tx_ull_dequeue(struct ll_conn *conn, struct node_tx *unus } return tx; } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ static void ticker_update_conn_op_cb(uint32_t status, void *param) { @@ -2648,5376 +1843,233 @@ static void conn_cleanup_iso_cis_released_cb(struct ll_conn *conn) reason); } else { /* No more CISes associated with conn - finalize */ - conn_cleanup_finalize(conn); - } -} -#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO || CONFIG_BT_CTLR_CENTRAL_ISO */ - -static void conn_cleanup_finalize(struct ll_conn *conn) -{ - struct lll_conn *lll = &conn->lll; - struct node_rx_pdu *rx; - uint32_t ticker_status; - -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - /* release any llcp reserved rx node */ - rx = conn->llcp_rx; - while (rx) { - struct node_rx_hdr *hdr; - - /* traverse to next rx node */ - hdr = &rx->hdr; - rx = hdr->link->mem; - - /* Mark for buffer for release */ - hdr->type = NODE_RX_TYPE_RELEASE; - - /* enqueue rx node towards Thread */ - ll_rx_put(hdr->link, hdr); - } -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - ARG_UNUSED(rx); - ull_cp_state_set(conn, ULL_CP_DISCONNECTED); - - /* Update tx buffer queue handling */ -#if defined(LLCP_TX_CTRL_BUF_QUEUE_ENABLE) - ull_cp_update_tx_buffer_queue(conn); -#endif /* LLCP_TX_CTRL_BUF_QUEUE_ENABLE */ -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - - /* flush demux-ed Tx buffer still in ULL context */ - tx_ull_flush(conn); - - /* Stop Central or Peripheral role ticker */ - ticker_status = ticker_stop(TICKER_INSTANCE_ID_CTLR, - TICKER_USER_ID_ULL_HIGH, - TICKER_ID_CONN_BASE + lll->handle, - ticker_stop_op_cb, conn); - LL_ASSERT((ticker_status == TICKER_STATUS_SUCCESS) || - (ticker_status == TICKER_STATUS_BUSY)); - - /* Invalidate the connection context */ - lll->handle = LLL_HANDLE_INVALID; - - /* Demux and flush Tx PDUs that remain enqueued in thread context */ - ull_conn_tx_demux(UINT8_MAX); -} - -static void conn_cleanup(struct ll_conn *conn, uint8_t reason) -{ - struct node_rx_pdu *rx; - -#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) || defined(CONFIG_BT_CTLR_CENTRAL_ISO) - struct ll_conn_iso_stream *cis; -#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO || CONFIG_BT_CTLR_CENTRAL_ISO */ - -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - /* Reset CPR mutex */ - cpr_active_check_and_reset(conn); -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - - /* Only termination structure is populated here in ULL context - * but the actual enqueue happens in the LLL context in - * tx_lll_flush. The reason being to avoid passing the reason - * value and handle through the mayfly scheduling of the - * tx_lll_flush. - */ - rx = (void *)&conn->llcp_terminate.node_rx; - rx->hdr.handle = conn->lll.handle; - rx->hdr.type = NODE_RX_TYPE_TERMINATE; - *((uint8_t *)rx->pdu) = reason; - -#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) || defined(CONFIG_BT_CTLR_CENTRAL_ISO) - cis = ll_conn_iso_stream_get_by_acl(conn, NULL); - if (cis) { - /* Stop CIS and defer cleanup to after teardown. */ - ull_conn_iso_cis_stop(cis, conn_cleanup_iso_cis_released_cb, - reason); - return; - } -#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO || CONFIG_BT_CTLR_CENTRAL_ISO */ - - conn_cleanup_finalize(conn); -} - -static void tx_ull_flush(struct ll_conn *conn) -{ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - while (conn->tx_head) { - struct node_tx *tx; - memq_link_t *link; - - tx = tx_ull_dequeue(conn, conn->tx_head); - - link = mem_acquire(&mem_link_tx.free); - LL_ASSERT(link); - - memq_enqueue(link, tx, &conn->lll.memq_tx.tail); - } -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - struct node_tx *tx; - - ull_tx_q_resume_data(&conn->tx_q); - - tx = tx_ull_dequeue(conn, NULL); - while (tx) { - memq_link_t *link; - - link = mem_acquire(&mem_link_tx.free); - LL_ASSERT(link); - - /* Enqueue towards LLL */ - memq_enqueue(link, tx, &conn->lll.memq_tx.tail); - - tx = tx_ull_dequeue(conn, NULL); - } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ -} - -static void ticker_stop_op_cb(uint32_t status, void *param) -{ - static memq_link_t link; - static struct mayfly mfy = {0, 0, &link, NULL, conn_disable}; - uint32_t ret; - - LL_ASSERT(status == TICKER_STATUS_SUCCESS); - - /* Check if any pending LLL events that need to be aborted */ - mfy.param = param; - ret = mayfly_enqueue(TICKER_USER_ID_ULL_LOW, - TICKER_USER_ID_ULL_HIGH, 0, &mfy); - LL_ASSERT(!ret); -} - -static void conn_disable(void *param) -{ - struct ll_conn *conn; - struct ull_hdr *hdr; - - /* Check ref count to determine if any pending LLL events in pipeline */ - conn = param; - hdr = &conn->ull; - if (ull_ref_get(hdr)) { - static memq_link_t link; - static struct mayfly mfy = {0, 0, &link, NULL, lll_disable}; - uint32_t ret; - - mfy.param = &conn->lll; - - /* Setup disabled callback to be called when ref count - * returns to zero. - */ - LL_ASSERT(!hdr->disabled_cb); - hdr->disabled_param = mfy.param; - hdr->disabled_cb = disabled_cb; - - /* Trigger LLL disable */ - ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, - TICKER_USER_ID_LLL, 0, &mfy); - LL_ASSERT(!ret); - } else { - /* No pending LLL events */ - disabled_cb(&conn->lll); - } -} - -static void disabled_cb(void *param) -{ - static memq_link_t link; - static struct mayfly mfy = {0, 0, &link, NULL, tx_lll_flush}; - uint32_t ret; - - mfy.param = param; - ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, - TICKER_USER_ID_LLL, 0, &mfy); - LL_ASSERT(!ret); -} - -static void tx_lll_flush(void *param) -{ - struct node_rx_pdu *rx; - struct lll_conn *lll; - struct ll_conn *conn; - struct node_tx *tx; - memq_link_t *link; - uint16_t handle; - - /* Get reference to ULL context */ - lll = param; - conn = HDR_LLL2ULL(lll); - handle = ll_conn_handle_get(conn); - - lll_conn_flush(handle, lll); - - link = memq_dequeue(lll->memq_tx.tail, &lll->memq_tx.head, - (void **)&tx); - while (link) { - struct lll_tx *lll_tx; - uint8_t idx; - - idx = MFIFO_ENQUEUE_GET(conn_ack, (void **)&lll_tx); - LL_ASSERT(lll_tx); - - lll_tx->handle = LLL_HANDLE_INVALID; - lll_tx->node = tx; - - /* TX node UPSTREAM, i.e. Tx node ack path */ - link->next = tx->next; /* Indicates ctrl pool or data pool */ - tx->next = link; - - MFIFO_ENQUEUE(conn_ack, idx); - - link = memq_dequeue(lll->memq_tx.tail, &lll->memq_tx.head, - (void **)&tx); - } - - /* Get the terminate structure reserved in the connection context. - * The terminate reason and connection handle should already be - * populated before this mayfly function was scheduled. - */ - rx = (void *)&conn->llcp_terminate.node_rx; - LL_ASSERT(rx->hdr.link); - link = rx->hdr.link; - rx->hdr.link = NULL; - - /* Enqueue the terminate towards ULL context */ - ull_rx_put_sched(link, rx); -} - -#if defined(CONFIG_BT_CTLR_LLID_DATA_START_EMPTY) -static int empty_data_start_release(struct ll_conn *conn, struct node_tx *tx) -{ - struct pdu_data *p = (void *)tx->pdu; - - if ((p->ll_id == PDU_DATA_LLID_DATA_START) && !p->len) { - conn->start_empty = 1U; - - ll_tx_ack_put(conn->lll.handle, tx); - - return -EINVAL; - } else if (p->len && conn->start_empty) { - conn->start_empty = 0U; - - if (p->ll_id == PDU_DATA_LLID_DATA_CONTINUE) { - p->ll_id = PDU_DATA_LLID_DATA_START; - } - } - - return 0; -} -#endif /* CONFIG_BT_CTLR_LLID_DATA_START_EMPTY */ - -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -/* Check transaction violation and get free ctrl tx PDU */ -static struct node_tx *ctrl_tx_rsp_mem_acquire(struct ll_conn *conn, - struct node_rx_pdu *rx, - int *err) -{ - struct node_tx *tx; - - /* Ignore duplicate requests without previous being acknowledged. */ - if (conn->common.txn_lock) { - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - /* Drop request */ - *err = 0; - - return NULL; - } - - /* Acquire ctrl tx mem */ - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - *err = -ENOBUFS; - - return NULL; - } - - /* Lock further responses to duplicate requests before previous - * response is acknowledged. - */ - conn->common.txn_lock = 1U; - - /* NOTE: err value not required when returning valid ctrl tx PDU */ - - return tx; -} - -#if defined(CONFIG_BT_CTLR_LE_ENC) -static inline void ctrl_tx_check_and_resume(struct ll_conn *conn) -{ - struct pdu_data *pdu_data_tx; - - pdu_data_tx = (void *)conn->tx_head->pdu; - if ((pdu_data_tx->ll_id != PDU_DATA_LLID_CTRL) || - ((pdu_data_tx->llctrl.opcode != - PDU_DATA_LLCTRL_TYPE_ENC_REQ) && - (pdu_data_tx->llctrl.opcode != - PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_REQ))) { - conn->tx_ctrl = conn->tx_ctrl_last = conn->tx_head; - } -} -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -static inline void ctrl_tx_last_enqueue(struct ll_conn *conn, - struct node_tx *tx) -{ - tx->next = conn->tx_ctrl_last->next; - conn->tx_ctrl_last->next = tx; - conn->tx_ctrl_last = tx; -} - -static inline void ctrl_tx_pause_enqueue(struct ll_conn *conn, - struct node_tx *tx, bool pause) -{ - /* check if a packet was tx-ed and not acked by peer */ - if ( - /* data/ctrl packet is in the head */ - conn->tx_head && - !conn->llcp_cu.pause_tx && -#if defined(CONFIG_BT_CTLR_LE_ENC) - !conn->llcp_enc.pause_tx && -#endif /* CONFIG_BT_CTLR_LE_ENC */ -#if defined(CONFIG_BT_CTLR_PHY) - !conn->llcp_phy.pause_tx && -#endif /* CONFIG_BT_CTLR_PHY */ - 1) { - /* data or ctrl may have been transmitted once, but not acked - * by peer, hence place this new ctrl after head - */ - - /* if data transmitted once, keep it at head of the tx list, - * as we will insert a ctrl after it, hence advance the - * data pointer - */ - if (conn->tx_head == conn->tx_data) { - conn->tx_data = conn->tx_data->next; -#if defined(CONFIG_BT_CTLR_LE_ENC) - } else if (!conn->tx_ctrl) { - ctrl_tx_check_and_resume(conn); -#endif /* CONFIG_BT_CTLR_LE_ENC */ - } - - /* if no ctrl packet already queued, new ctrl added will be - * the ctrl pointer and is inserted after head. - */ - if (!conn->tx_ctrl) { - tx->next = conn->tx_head->next; - conn->tx_head->next = tx; - - /* If in Encryption Procedure, other control PDUs, - * Feature Rsp and Version Ind, are placed before data - * marker and after control last marker. Hence, if no - * control marker i.e. this is the first control PDU and - * to be paused, do not set the control marker. A valid - * control PDU in Encryption Procedure that is not - * implicitly paused, will set the control and control - * last marker. - */ - if (!pause) { - conn->tx_ctrl = tx; - conn->tx_ctrl_last = tx; - } - } else { - /* ENC_REQ PDU is always allocated from data pool, hence - * the head can not have the control marker, and pause - * be true. - */ - LL_ASSERT(!pause); - - ctrl_tx_last_enqueue(conn, tx); - } - } else { - /* No packet needing ACK. */ - - /* If first ctrl packet then add it as head else add it to the - * tail of the ctrl packets. - */ - if (!conn->tx_ctrl) { - tx->next = conn->tx_head; - conn->tx_head = tx; - if (!pause) { - conn->tx_ctrl = tx; - conn->tx_ctrl_last = tx; - } - } else { - LL_ASSERT(!pause); - - ctrl_tx_last_enqueue(conn, tx); - } - } - - /* Update last pointer if ctrl added at end of tx list */ - if (!tx->next) { - conn->tx_data_last = tx; - } -} - -static inline void ctrl_tx_enqueue(struct ll_conn *conn, struct node_tx *tx) -{ - ctrl_tx_pause_enqueue(conn, tx, false); -} - -static void ctrl_tx_sec_enqueue(struct ll_conn *conn, struct node_tx *tx) -{ - bool pause = false; - -#if defined(CONFIG_BT_CTLR_LE_ENC) - if (conn->llcp_enc.pause_tx) { - if (!conn->tx_ctrl) { - /* As data PDU tx is paused and no control PDU in queue, - * its safe to add new control PDU at head. - * Note, here the PDUs are stacked, not queued. Last In - * First Out. - */ - tx->next = conn->tx_head; - conn->tx_head = tx; - } else { - /* As data PDU tx is paused and there are control PDUs - * in the queue, add it after control PDUs last marker - * and before the data start marker. - * Note, here the PDUs are stacked, not queued. Last In - * First Out. - */ - tx->next = conn->tx_ctrl_last->next; - conn->tx_ctrl_last->next = tx; - } - - /* Update last pointer if ctrl added at end of tx list */ - if (!tx->next) { - conn->tx_data_last = tx; - } - } else { - /* check if Encryption Request is at head, enqueue this control - * PDU after control last marker and before data marker. - * This way it is paused until Encryption Setup completes. - */ - if (conn->tx_head) { - struct pdu_data *pdu_data_tx; - - pdu_data_tx = (void *)conn->tx_head->pdu; - if ((conn->llcp_req != conn->llcp_ack) && - (conn->llcp_type == LLCP_ENCRYPTION) && - (pdu_data_tx->ll_id == PDU_DATA_LLID_CTRL) && - ((pdu_data_tx->llctrl.opcode == - PDU_DATA_LLCTRL_TYPE_ENC_REQ) || - (pdu_data_tx->llctrl.opcode == - PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_REQ))) { - pause = true; - } - } - -#else /* !CONFIG_BT_CTLR_LE_ENC */ - { -#endif /* !CONFIG_BT_CTLR_LE_ENC */ - - ctrl_tx_pause_enqueue(conn, tx, pause); - } -} - -#if defined(CONFIG_BT_CTLR_LE_ENC) -static bool is_enc_req_pause_tx(struct ll_conn *conn) -{ - struct pdu_data *pdu_data_tx; - - pdu_data_tx = (void *)conn->tx_head->pdu; - if ((pdu_data_tx->ll_id == PDU_DATA_LLID_CTRL) && - ((pdu_data_tx->llctrl.opcode == - PDU_DATA_LLCTRL_TYPE_ENC_REQ) || - (pdu_data_tx->llctrl.opcode == - PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_REQ))) { - if (((conn->llcp_req != conn->llcp_ack) && - (conn->llcp_type != LLCP_ENCRYPTION)) || - ((conn->llcp_req == conn->llcp_ack) && - ((conn->llcp_feature.ack != conn->llcp_feature.req) || - (conn->llcp_version.ack != conn->llcp_version.req) || -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - (conn->llcp_conn_param.ack != - conn->llcp_conn_param.req) || -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - (conn->llcp_length.ack != conn->llcp_length.req) || -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ -#if defined(CONFIG_BT_CTLR_PHY) - (conn->llcp_phy.ack != conn->llcp_phy.req) || -#endif /* CONFIG_BT_CTLR_PHY */ - 0))) { - struct node_tx *tx; - - /* if we have control packets enqueued after this PDU - * bring it ahead, and move the enc_req to last of - * ctrl queue. - */ - tx = conn->tx_head; - if ((tx->next != NULL) && - (tx->next == conn->tx_ctrl)) { - conn->tx_head = tx->next; - tx->next = conn->tx_ctrl_last->next; - conn->tx_ctrl_last->next = tx; - conn->tx_data = tx; - if (!conn->tx_data_last) { - conn->tx_data_last = tx; - } - - /* Head now contains a control packet permitted - * to be transmitted to peer. - */ - return false; - } - - /* Head contains ENC_REQ packet deferred due to another - * control procedure in progress. - */ - return true; - } - - if (conn->llcp_req == conn->llcp_ack) { - conn->llcp.encryption.state = LLCP_ENC_STATE_INIT; - - conn->llcp_type = LLCP_ENCRYPTION; - conn->llcp_ack -= 2U; - } else { - LL_ASSERT(conn->llcp_type == LLCP_ENCRYPTION); - } - } - - /* Head contains a permitted data or control packet. */ - return false; -} -#endif /* CONFIG_BT_CTLR_LE_ENC */ - - -static inline void event_conn_upd_init(struct ll_conn *conn, - uint16_t event_counter, - uint32_t ticks_at_expire, - struct pdu_data *pdu_ctrl_tx, - struct mayfly *mfy_sched_offset, - void (*fp_mfy_select_or_use)(void *)) -{ - /* place the conn update req packet as next in tx queue */ - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = offsetof(struct pdu_data_llctrl, conn_update_ind) + - sizeof(struct pdu_data_llctrl_conn_update_ind); - pdu_ctrl_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_CONN_UPDATE_IND; - pdu_ctrl_tx->llctrl.conn_update_ind.win_size = conn->llcp_cu.win_size; - pdu_ctrl_tx->llctrl.conn_update_ind.win_offset = - sys_cpu_to_le16(conn->llcp_cu.win_offset_us / - CONN_INT_UNIT_US); - pdu_ctrl_tx->llctrl.conn_update_ind.interval = - sys_cpu_to_le16(conn->llcp_cu.interval); - pdu_ctrl_tx->llctrl.conn_update_ind.latency = - sys_cpu_to_le16(conn->llcp_cu.latency); - pdu_ctrl_tx->llctrl.conn_update_ind.timeout = - sys_cpu_to_le16(conn->llcp_cu.timeout); - -#if defined(CONFIG_BT_CTLR_SCHED_ADVANCED) - /* move to offset calculation requested state */ - conn->llcp_cu.state = LLCP_CUI_STATE_OFFS_REQ; - - { - uint32_t retval; - void *win_offs; - - /* calculate window offset that places the connection in the - * next available slot after existing centrals. - */ - conn->llcp.conn_upd.ticks_anchor = ticks_at_expire; - -#if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) - if (conn->ull.ticks_prepare_to_start & XON_BITMASK) { - uint32_t ticks_prepare_to_start = - MAX(conn->ull.ticks_active_to_start, - conn->ull.ticks_preempt_to_start); - - conn->llcp.conn_upd.ticks_anchor -= - (conn->ull.ticks_prepare_to_start & - ~XON_BITMASK) - ticks_prepare_to_start; - } -#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */ - - win_offs = &pdu_ctrl_tx->llctrl.conn_update_ind.win_offset; - /* No need to check alignment here since the pointer that gets - * stored is never derreferenced directly, only passed - * to memcpy(). - */ - conn->llcp.conn_upd.pdu_win_offset = win_offs; - - mfy_sched_offset->fp = fp_mfy_select_or_use; - mfy_sched_offset->param = (void *)conn; - - retval = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, - TICKER_USER_ID_ULL_LOW, 1, - mfy_sched_offset); - LL_ASSERT(!retval); - } -#else /* !CONFIG_BT_CTLR_SCHED_ADVANCED */ - ARG_UNUSED(ticks_at_expire); - ARG_UNUSED(mfy_sched_offset); - ARG_UNUSED(fp_mfy_select_or_use); - - /* move to in progress */ - conn->llcp_cu.state = LLCP_CUI_STATE_INPROG; -#endif /* !CONFIG_BT_CTLR_SCHED_ADVANCED */ -} - -static inline int event_conn_upd_prep(struct ll_conn *conn, uint16_t lazy, - uint32_t ticks_at_expire) -{ - struct lll_conn *lll = &conn->lll; - uint16_t instant_latency; - uint16_t event_counter; - - /* Calculate current event counter */ - event_counter = lll->event_counter + lll->latency_prepare + lazy; - - instant_latency = (event_counter - conn->llcp.conn_upd.instant) & - 0xffff; - if (conn->llcp_cu.state != LLCP_CUI_STATE_INPROG) { - struct pdu_data *pdu_ctrl_tx; - struct node_rx_pdu *rx; - struct node_tx *tx; -#if defined(CONFIG_BT_CTLR_SCHED_ADVANCED) - static memq_link_t s_link; - static struct mayfly s_mfy_sched_offset = {0, 0, - &s_link, 0, 0 }; - void (*fp_mfy_select_or_use)(void *) = NULL; - - switch (conn->llcp_cu.state) { - case LLCP_CUI_STATE_USE: - fp_mfy_select_or_use = ull_sched_mfy_win_offset_use; - break; - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - case LLCP_CUI_STATE_SELECT: - fp_mfy_select_or_use = ull_sched_mfy_win_offset_select; - break; - - case LLCP_CUI_STATE_REJECT: - /* procedure request acked */ - conn->llcp_ack = conn->llcp_req; - conn->llcp_cu.ack = conn->llcp_cu.req; - - /* Check and initiate new CPR from cache, if any */ - cpr_cache_initiate_or_complete(conn); - - /* Reset CPR mutex */ - cpr_active_reset(); - - /* enqueue control PDU */ - pdu_ctrl_tx = - CONTAINER_OF(conn->llcp.conn_upd.pdu_win_offset, - struct pdu_data, - llctrl.conn_update_ind.win_offset); - tx = CONTAINER_OF(pdu_ctrl_tx, struct node_tx, pdu); - ctrl_tx_enqueue(conn, tx); - - /* Acquire the reserved Rx node */ - rx = conn->llcp_rx; - LL_ASSERT(rx && rx->hdr.link); - conn->llcp_rx = rx->hdr.link->mem; - - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - /* enqueue rx node towards Thread */ - ll_rx_put(rx->hdr.link, rx); - ll_rx_sched(); - - return -ECANCELED; -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - - case LLCP_CUI_STATE_OFFS_REQ: - return -EBUSY; - - case LLCP_CUI_STATE_OFFS_RDY: - /* set instant */ - conn->llcp.conn_upd.instant = event_counter + - conn->lll.latency + 6; - pdu_ctrl_tx = - CONTAINER_OF(conn->llcp.conn_upd.pdu_win_offset, - struct pdu_data, - llctrl.conn_update_ind.win_offset); - pdu_ctrl_tx->llctrl.conn_update_ind.instant = - sys_cpu_to_le16(conn->llcp.conn_upd.instant); - - /* move to in progress */ - conn->llcp_cu.state = LLCP_CUI_STATE_INPROG; - - /* Data PDU tx paused, as we ensure PDUs in LLL have all - * been ack-ed. - */ - conn->llcp_cu.pause_tx = 1U; - - /* enqueue control PDU */ - tx = CONTAINER_OF(pdu_ctrl_tx, struct node_tx, pdu); - ctrl_tx_enqueue(conn, tx); - return -EINPROGRESS; - - default: - LL_ASSERT(0); - break; - } -#endif /* !CONFIG_BT_CTLR_SCHED_ADVANCED */ - - rx = ll_pdu_rx_alloc_peek(1); - if (!rx) { - return -ENOBUFS; - } - - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - return -ENOBUFS; - } - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - /* Set CPR mutex */ - cpr_active_check_and_set(conn); -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - - (void)ll_pdu_rx_alloc(); - rx->hdr.link->mem = conn->llcp_rx; - conn->llcp_rx = rx; - - pdu_ctrl_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_ctrl_tx); - -#if defined(CONFIG_BT_CTLR_SCHED_ADVANCED) - event_conn_upd_init(conn, event_counter, ticks_at_expire, - pdu_ctrl_tx, &s_mfy_sched_offset, - fp_mfy_select_or_use); -#else /* !CONFIG_BT_CTLR_SCHED_ADVANCED */ - event_conn_upd_init(conn, event_counter, ticks_at_expire, - pdu_ctrl_tx, NULL, NULL); - /* set instant */ - conn->llcp.conn_upd.instant = event_counter + - conn->lll.latency + 6; - pdu_ctrl_tx->llctrl.conn_update_ind.instant = - sys_cpu_to_le16(conn->llcp.conn_upd.instant); - - /* Data PDU tx paused, as we ensure PDUs in LLL have all been - * ack-ed. - */ - conn->llcp_cu.pause_tx = 1U; - - /* enqueue control PDU */ - ctrl_tx_enqueue(conn, tx); -#endif /* !CONFIG_BT_CTLR_SCHED_ADVANCED */ - } else if (instant_latency <= 0x7FFF) { - uint32_t ticks_win_offset = 0U; - uint32_t ticks_slot_overhead; - uint16_t conn_interval_old; - uint16_t conn_interval_new; - uint32_t conn_interval_us; - struct node_rx_pdu *rx; - uint8_t ticker_id_conn; - uint32_t ticker_status; - uint32_t periodic_us; - uint16_t latency; - -#if defined(CONFIG_BT_PERIPHERAL) && defined(CONFIG_BT_CTLR_LE_ENC) - if (conn->lll.role && (conn->periph.llcp_type != LLCP_NONE)) { - /* Local peripheral initiated connection update - * completed while a remote central had initiated - * encryption procedure - */ - conn->periph.llcp_type = LLCP_NONE; - } else -#endif /* CONFIG_BT_PERIPHERAL && CONFIG_BT_CTLR_LE_ENC */ - { - /* procedure request acked */ - conn->llcp_ack = conn->llcp_req; - } - - /* procedure request acked */ - conn->llcp_cu.ack = conn->llcp_cu.req; - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - if ((conn->llcp_conn_param.req != conn->llcp_conn_param.ack) && - (conn->llcp_conn_param.state == LLCP_CPR_STATE_UPD)) { - /* Check and initiate new CPR from cache, if any */ - cpr_cache_initiate_or_complete(conn); - - /* Stop procedure timeout */ - conn->procedure_expire = 0U; - } - - /* Reset CPR mutex */ - cpr_active_check_and_reset(conn); -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - - lll = &conn->lll; - - /* Acquire Rx node */ - rx = conn->llcp_rx; - LL_ASSERT(rx && rx->hdr.link); - conn->llcp_rx = rx->hdr.link->mem; - - /* Prepare the rx packet structure */ - if ((conn->llcp_cu.interval != lll->interval) || - (conn->llcp_cu.latency != lll->latency) || - (conn->llcp_cu.timeout != conn->supervision_timeout)) { - struct node_rx_cu *cu; - - rx->hdr.handle = lll->handle; - rx->hdr.type = NODE_RX_TYPE_CONN_UPDATE; - - /* prepare connection update complete structure */ - cu = (void *)rx->pdu; - cu->status = 0x00; - cu->interval = conn->llcp_cu.interval; - cu->latency = conn->llcp_cu.latency; - cu->timeout = conn->llcp_cu.timeout; - -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) - /* hold node rx until the instant's anchor point sync */ - rx_hold_put(conn, rx->hdr.link, rx); -#else /* !CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - /* enqueue rx node towards Thread */ - ll_rx_put_sched(rx->hdr.link, rx); -#endif /* !CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - - } else { - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - /* enqueue rx node towards Thread */ - ll_rx_put_sched(rx->hdr.link, rx); - } - -#if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) - /* restore to normal prepare */ - if (conn->ull.ticks_prepare_to_start & XON_BITMASK) { - uint32_t ticks_prepare_to_start = - MAX(conn->ull.ticks_active_to_start, - conn->ull.ticks_preempt_to_start); - - conn->ull.ticks_prepare_to_start &= ~XON_BITMASK; - ticks_at_expire -= (conn->ull.ticks_prepare_to_start - - ticks_prepare_to_start); - } -#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */ - - /* compensate for instant_latency due to laziness */ - conn_interval_old = instant_latency * lll->interval; - latency = conn_interval_old / conn->llcp_cu.interval; - conn_interval_new = latency * conn->llcp_cu.interval; - if (conn_interval_new > conn_interval_old) { - ticks_at_expire += HAL_TICKER_US_TO_TICKS( - (conn_interval_new - conn_interval_old) * - CONN_INT_UNIT_US); - } else { - ticks_at_expire -= HAL_TICKER_US_TO_TICKS( - (conn_interval_old - conn_interval_new) * - CONN_INT_UNIT_US); - } - lll->latency_prepare += lazy; - lll->latency_prepare -= (instant_latency - latency); - - /* calculate the offset */ - if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { - ticks_slot_overhead = - MAX(conn->ull.ticks_active_to_start, - conn->ull.ticks_prepare_to_start); - - } else { - ticks_slot_overhead = 0U; - } - - /* calculate the window widening and interval */ - conn_interval_us = conn->llcp_cu.interval * - CONN_INT_UNIT_US; - periodic_us = conn_interval_us; - - if (0) { -#if defined(CONFIG_BT_PERIPHERAL) - } else if (lll->role) { - lll->periph.window_widening_prepare_us -= - lll->periph.window_widening_periodic_us * - instant_latency; - - lll->periph.window_widening_periodic_us = - ceiling_fraction(((lll_clock_ppm_local_get() + - lll_clock_ppm_get(conn->periph.sca)) * - conn_interval_us), USEC_PER_SEC); - lll->periph.window_widening_max_us = - (conn_interval_us >> 1) - EVENT_IFS_US; - lll->periph.window_size_prepare_us = - conn->llcp_cu.win_size * CONN_INT_UNIT_US; - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - conn->periph.ticks_to_offset = 0U; -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - - lll->periph.window_widening_prepare_us += - lll->periph.window_widening_periodic_us * - latency; - if (lll->periph.window_widening_prepare_us > - lll->periph.window_widening_max_us) { - lll->periph.window_widening_prepare_us = - lll->periph.window_widening_max_us; - } - - ticks_at_expire -= HAL_TICKER_US_TO_TICKS( - lll->periph.window_widening_periodic_us * - latency); - ticks_win_offset = HAL_TICKER_US_TO_TICKS( - (conn->llcp_cu.win_offset_us / - CONN_INT_UNIT_US) * CONN_INT_UNIT_US); - periodic_us -= lll->periph.window_widening_periodic_us; -#endif /* CONFIG_BT_PERIPHERAL */ - -#if defined(CONFIG_BT_CENTRAL) - } else if (!lll->role) { - ticks_win_offset = HAL_TICKER_US_TO_TICKS( - conn->llcp_cu.win_offset_us); - - /* Workaround: Due to the missing remainder param in - * ticker_start function for first interval; add a - * tick so as to use the ceiled value. - */ - ticks_win_offset += 1U; -#endif /* CONFIG_BT_CENTRAL */ - - } else { - LL_ASSERT(0); - } - - lll->interval = conn->llcp_cu.interval; - lll->latency = conn->llcp_cu.latency; - - conn->supervision_timeout = conn->llcp_cu.timeout; - conn->procedure_reload = - RADIO_CONN_EVENTS((40 * 1000 * 1000), conn_interval_us); - -#if defined(CONFIG_BT_CTLR_LE_PING) - /* APTO in no. of connection events */ - conn->apto_reload = RADIO_CONN_EVENTS((30 * 1000 * 1000), - conn_interval_us); - /* Dispatch LE Ping PDU 6 connection events (that peer would - * listen to) before 30s timeout - * TODO: "peer listens to" is greater than 30s due to latency - */ - conn->appto_reload = (conn->apto_reload > (lll->latency + 6)) ? - (conn->apto_reload - (lll->latency + 6)) : - conn->apto_reload; -#endif /* CONFIG_BT_CTLR_LE_PING */ - - if (conn->llcp_cu.cmd) { - conn->supervision_expire = 0U; - } - -#if (CONFIG_BT_CTLR_ULL_HIGH_PRIO == CONFIG_BT_CTLR_ULL_LOW_PRIO) - /* disable ticker job, in order to chain stop and start - * to avoid RTC being stopped if no tickers active. - */ - uint32_t mayfly_was_enabled = - mayfly_is_enabled(TICKER_USER_ID_ULL_HIGH, - TICKER_USER_ID_ULL_LOW); - mayfly_enable(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_ULL_LOW, - 0); -#endif - - /* start peripheral/central with new timings */ - ticker_id_conn = TICKER_ID_CONN_BASE + ll_conn_handle_get(conn); - ticker_status = ticker_stop(TICKER_INSTANCE_ID_CTLR, - TICKER_USER_ID_ULL_HIGH, - ticker_id_conn, - ticker_stop_conn_op_cb, - (void *)conn); - LL_ASSERT((ticker_status == TICKER_STATUS_SUCCESS) || - (ticker_status == TICKER_STATUS_BUSY)); - ticker_status = - ticker_start(TICKER_INSTANCE_ID_CTLR, - TICKER_USER_ID_ULL_HIGH, - ticker_id_conn, - ticks_at_expire, ticks_win_offset, - HAL_TICKER_US_TO_TICKS(periodic_us), - HAL_TICKER_REMAINDER(periodic_us), -#if defined(CONFIG_BT_TICKER_LOW_LAT) - TICKER_NULL_LAZY, -#else - TICKER_LAZY_MUST_EXPIRE_KEEP, -#endif /* CONFIG_BT_TICKER_LOW_LAT */ - (ticks_slot_overhead + - conn->ull.ticks_slot), -#if defined(CONFIG_BT_PERIPHERAL) && defined(CONFIG_BT_CENTRAL) - lll->role ? ull_periph_ticker_cb : - ull_central_ticker_cb, -#elif defined(CONFIG_BT_PERIPHERAL) - ull_periph_ticker_cb, -#else - ull_central_ticker_cb, -#endif - conn, ticker_start_conn_op_cb, - (void *)conn); - LL_ASSERT((ticker_status == TICKER_STATUS_SUCCESS) || - (ticker_status == TICKER_STATUS_BUSY)); - -#if (CONFIG_BT_CTLR_ULL_HIGH_PRIO == CONFIG_BT_CTLR_ULL_LOW_PRIO) - /* enable ticker job, if disabled in this function */ - if (mayfly_was_enabled) { - mayfly_enable(TICKER_USER_ID_ULL_HIGH, - TICKER_USER_ID_ULL_LOW, 1); - } -#endif - - return 0; - } - - return -EINPROGRESS; -} - -static inline void event_ch_map_prep(struct ll_conn *conn, - uint16_t event_counter) -{ - if (conn->llcp.chan_map.initiate) { - struct node_tx *tx; - - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (tx) { - struct pdu_data *pdu_ctrl_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_ctrl_tx); - - /* reset initiate flag */ - conn->llcp.chan_map.initiate = 0U; - - /* set instant */ - conn->llcp.chan_map.instant = event_counter + - conn->lll.latency + 6; - - /* place the channel map req packet as next in - * tx queue - */ - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = offsetof(struct pdu_data_llctrl, - chan_map_ind) + - sizeof(struct pdu_data_llctrl_chan_map_ind); - pdu_ctrl_tx->llctrl.opcode = - PDU_DATA_LLCTRL_TYPE_CHAN_MAP_IND; - memcpy(&pdu_ctrl_tx->llctrl.chan_map_ind.chm[0], - &conn->llcp.chan_map.chm[0], - sizeof(pdu_ctrl_tx->llctrl.chan_map_ind.chm)); - pdu_ctrl_tx->llctrl.chan_map_ind.instant = - sys_cpu_to_le16(conn->llcp.chan_map.instant); - - ctrl_tx_enqueue(conn, tx); - } - } else if (((event_counter - conn->llcp.chan_map.instant) & 0xFFFF) - <= 0x7FFF) { - struct lll_conn *lll = &conn->lll; - -#if defined(CONFIG_BT_PERIPHERAL) && defined(CONFIG_BT_CTLR_LE_ENC) - if (conn->lll.role && (conn->periph.llcp_type != LLCP_NONE)) { - /* Local peripheral initiated channel map update - * completed while a remote central had initiated - * encryption procedure - */ - conn->periph.llcp_type = LLCP_NONE; - } else -#endif /* CONFIG_BT_PERIPHERAL && CONFIG_BT_CTLR_LE_ENC */ - { - /* procedure request acked */ - conn->llcp_ack = conn->llcp_req; - } - - /* copy to active channel map */ - memcpy(&lll->data_chan_map[0], - &conn->llcp.chan_map.chm[0], - sizeof(lll->data_chan_map)); - lll->data_chan_count = - util_ones_count_get(&lll->data_chan_map[0], - sizeof(lll->data_chan_map)); - conn->chm_updated = 1U; - } - -} - -#if defined(CONFIG_BT_CTLR_LE_ENC) -static inline void event_enc_reject_prep(struct ll_conn *conn, - struct pdu_data *pdu) -{ - pdu->ll_id = PDU_DATA_LLID_CTRL; - - if (conn->common.fex_valid && - (conn->llcp_feature.features_conn & - BIT64(BT_LE_FEAT_BIT_EXT_REJ_IND))) { - struct pdu_data_llctrl_reject_ext_ind *p; - - pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_REJECT_EXT_IND; - - p = (void *)&pdu->llctrl.reject_ext_ind; - p->reject_opcode = PDU_DATA_LLCTRL_TYPE_ENC_REQ; - p->error_code = conn->llcp.encryption.error_code; - - pdu->len = sizeof(struct pdu_data_llctrl_reject_ext_ind); - } else { - struct pdu_data_llctrl_reject_ind *p; - - pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_REJECT_IND; - - p = (void *)&pdu->llctrl.reject_ind; - p->error_code = conn->llcp.encryption.error_code; - - pdu->len = sizeof(struct pdu_data_llctrl_reject_ind); - } - - pdu->len += offsetof(struct pdu_data_llctrl, reject_ind); - - conn->llcp.encryption.error_code = 0U; -} - -static inline void event_enc_prep(struct ll_conn *conn) -{ - struct lll_conn *lll = &conn->lll; - struct pdu_data *pdu_ctrl_tx; - struct node_tx *tx; - - if (conn->llcp.encryption.state) { -#if defined(CONFIG_BT_PERIPHERAL) && !defined(CONFIG_BT_CTLR_FAST_ENC) - if (lll->role && - (conn->llcp.encryption.state == LLCP_ENC_STATE_INIT)) { - struct node_rx_pdu *rx; - struct pdu_data *pdu; - uint8_t err; - - /* TODO BT Spec. text: may finalize the sending - * of additional data channel PDUs queued in the - * controller. - */ - err = enc_rsp_send(conn); - if (err) { - return; - } - - /* get a rx node for ULL->LL */ - rx = ll_pdu_rx_alloc(); - if (!rx) { - return; - } - - /* prepare enc req structure */ - rx->hdr.handle = conn->lll.handle; - rx->hdr.type = NODE_RX_TYPE_DC_PDU; - pdu = (void *)rx->pdu; - pdu->ll_id = PDU_DATA_LLID_CTRL; - pdu->len = offsetof(struct pdu_data_llctrl, enc_req) + - sizeof(struct pdu_data_llctrl_enc_req); - pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_ENC_REQ; - memcpy(&pdu->llctrl.enc_req.rand[0], - &conn->llcp_enc.rand[0], - sizeof(pdu->llctrl.enc_req.rand)); - pdu->llctrl.enc_req.ediv[0] = conn->llcp_enc.ediv[0]; - pdu->llctrl.enc_req.ediv[1] = conn->llcp_enc.ediv[1]; - - /* enqueue enc req structure into rx queue */ - ll_rx_put_sched(rx->hdr.link, rx); - - /* Wait for LTK reply */ - conn->llcp.encryption.state = LLCP_ENC_STATE_LTK_WAIT; - } -#endif /* CONFIG_BT_PERIPHERAL && !CONFIG_BT_CTLR_FAST_ENC */ - - return; - } - - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - return; - } - - pdu_ctrl_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_ctrl_tx); - - /* central sends encrypted enc start rsp in control priority */ - if (!lll->role) { - /* calc the Session Key */ - ecb_encrypt(&conn->llcp_enc.ltk[0], - &conn->llcp.encryption.skd[0], NULL, - &lll->ccm_rx.key[0]); - - /* copy the Session Key */ - memcpy(&lll->ccm_tx.key[0], &lll->ccm_rx.key[0], - sizeof(lll->ccm_tx.key)); - - /* copy the IV */ - memcpy(&lll->ccm_tx.iv[0], &lll->ccm_rx.iv[0], - sizeof(lll->ccm_tx.iv)); - - /* initialise counter */ - lll->ccm_rx.counter = 0U; - lll->ccm_tx.counter = 0U; - - /* set direction: peripheral to central = 0, - * central to peripheral = 1 - */ - lll->ccm_rx.direction = 0U; - lll->ccm_tx.direction = 1U; - - /* enable receive encryption */ - lll->enc_rx = 1U; - - /* send enc start resp */ - start_enc_rsp_send(conn, pdu_ctrl_tx); - - ctrl_tx_enqueue(conn, tx); - } - - /* peripheral send reject ind or start enc req at control priority */ - -#if defined(CONFIG_BT_CTLR_FAST_ENC) - else { -#else /* !CONFIG_BT_CTLR_FAST_ENC */ - else if (!lll->enc_rx) { -#endif /* !CONFIG_BT_CTLR_FAST_ENC */ - - /* place the reject ind packet as next in tx queue */ - if (conn->llcp.encryption.error_code) { - event_enc_reject_prep(conn, pdu_ctrl_tx); - - ctrl_tx_enqueue(conn, tx); - - /* procedure request acked */ - conn->llcp_ack = conn->llcp_req; - - return; - } - /* place the start enc req packet as next in tx queue */ - else { - /* calc the Session Key */ - ecb_encrypt(&conn->llcp_enc.ltk[0], - &conn->llcp.encryption.skd[0], NULL, - &lll->ccm_rx.key[0]); - - /* copy the Session Key */ - memcpy(&lll->ccm_tx.key[0], - &lll->ccm_rx.key[0], - sizeof(lll->ccm_tx.key)); - - /* copy the IV */ - memcpy(&lll->ccm_tx.iv[0], &lll->ccm_rx.iv[0], - sizeof(lll->ccm_tx.iv)); - - /* initialise counter */ - lll->ccm_rx.counter = 0U; - lll->ccm_tx.counter = 0U; - - /* set direction: peripheral to central = 0, - * central to peripheral = 1 - */ - lll->ccm_rx.direction = 1U; - lll->ccm_tx.direction = 0U; - - /* enable receive encryption (transmit turned - * on when start enc resp from central is - * received) - */ - lll->enc_rx = 1U; - - /* prepare the start enc req */ - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = offsetof(struct pdu_data_llctrl, - start_enc_req) + - sizeof(struct pdu_data_llctrl_start_enc_req); - pdu_ctrl_tx->llctrl.opcode = - PDU_DATA_LLCTRL_TYPE_START_ENC_REQ; - - ctrl_tx_enqueue(conn, tx); - } - -#if !defined(CONFIG_BT_CTLR_FAST_ENC) - /* Peripheral sends start enc rsp after reception of start enc rsp */ - } else { - start_enc_rsp_send(conn, pdu_ctrl_tx); - - ctrl_tx_enqueue(conn, tx); -#endif /* !CONFIG_BT_CTLR_FAST_ENC */ - } - - /* Wait for encryption setup to complete */ - conn->llcp.encryption.state = LLCP_ENC_STATE_ENC_WAIT; -} -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -static inline void event_fex_prep(struct ll_conn *conn) -{ - struct node_tx *tx; - - /* If waiting for response, do nothing */ - if (!((conn->llcp_feature.ack - conn->llcp_feature.req) & 0x01)) { - return; - } - - if (conn->common.fex_valid) { - struct node_rx_pdu *rx; - struct pdu_data *pdu; - - /* get a rx node for ULL->LL */ - rx = ll_pdu_rx_alloc(); - if (!rx) { - return; - } - - /* procedure request acked */ - conn->llcp_feature.ack = conn->llcp_feature.req; - - /* prepare feature rsp structure */ - rx->hdr.handle = conn->lll.handle; - rx->hdr.type = NODE_RX_TYPE_DC_PDU; - pdu = (void *)rx->pdu; - pdu->ll_id = PDU_DATA_LLID_CTRL; - pdu->len = offsetof(struct pdu_data_llctrl, feature_rsp) + - sizeof(struct pdu_data_llctrl_feature_rsp); - pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_FEATURE_RSP; - (void)memset(&pdu->llctrl.feature_rsp.features[0], 0x00, - sizeof(pdu->llctrl.feature_rsp.features)); - sys_put_le64(conn->llcp_feature.features_peer, - pdu->llctrl.feature_req.features); - - /* enqueue feature rsp structure into rx queue */ - ll_rx_put_sched(rx->hdr.link, rx); - - return; - } - - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (tx) { - struct pdu_data *pdu = (void *)tx->pdu; - - ull_pdu_data_init(pdu); - - /* procedure request acked, move to waiting state */ - conn->llcp_feature.ack--; - - /* place the feature exchange req packet as next in tx queue */ - pdu->ll_id = PDU_DATA_LLID_CTRL; - pdu->len = offsetof(struct pdu_data_llctrl, feature_req) + - sizeof(struct pdu_data_llctrl_feature_req); - pdu->llctrl.opcode = !conn->lll.role ? - PDU_DATA_LLCTRL_TYPE_FEATURE_REQ : - PDU_DATA_LLCTRL_TYPE_PER_INIT_FEAT_XCHG; - (void)memset(&pdu->llctrl.feature_req.features[0], - 0x00, - sizeof(pdu->llctrl.feature_req.features)); - sys_put_le64(conn->llcp_feature.features_conn, - pdu->llctrl.feature_req.features); - - ctrl_tx_enqueue(conn, tx); - - /* Start Procedure Timeout (TODO: this shall not replace - * terminate procedure) - */ - conn->procedure_expire = conn->procedure_reload; - } - -} - -static inline void event_vex_prep(struct ll_conn *conn) -{ - /* If waiting for response, do nothing */ - if (!((conn->llcp_version.ack - conn->llcp_version.req) & 0x01)) { - return; - } - - if (conn->llcp_version.tx == 0U) { - struct node_tx *tx; - - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (tx) { - struct pdu_data *pdu = (void *)tx->pdu; - uint16_t cid; - uint16_t svn; - - ull_pdu_data_init(pdu); - - /* procedure request acked, move to waiting state */ - conn->llcp_version.ack--; - - /* set version ind tx-ed flag */ - conn->llcp_version.tx = 1U; - - /* place the version ind packet as next in tx queue */ - pdu->ll_id = PDU_DATA_LLID_CTRL; - pdu->len = - offsetof(struct pdu_data_llctrl, version_ind) + - sizeof(struct pdu_data_llctrl_version_ind); - pdu->llctrl.opcode = - PDU_DATA_LLCTRL_TYPE_VERSION_IND; - pdu->llctrl.version_ind.version_number = - LL_VERSION_NUMBER; - cid = sys_cpu_to_le16(ll_settings_company_id()); - svn = sys_cpu_to_le16(ll_settings_subversion_number()); - pdu->llctrl.version_ind.company_id = cid; - pdu->llctrl.version_ind.sub_version_number = svn; - - ctrl_tx_enqueue(conn, tx); - - /* Start Procedure Timeout (TODO: this shall not - * replace terminate procedure) - */ - conn->procedure_expire = conn->procedure_reload; - } - } else if (conn->llcp_version.rx) { - struct node_rx_pdu *rx; - struct pdu_data *pdu; - - /* get a rx node for ULL->LL */ - rx = ll_pdu_rx_alloc(); - if (!rx) { - return; - } - - /* procedure request acked */ - conn->llcp_version.ack = conn->llcp_version.req; - - rx->hdr.handle = conn->lll.handle; - rx->hdr.type = NODE_RX_TYPE_DC_PDU; - - /* prepare version ind structure */ - pdu = (void *)rx->pdu; - pdu->ll_id = PDU_DATA_LLID_CTRL; - pdu->len = offsetof(struct pdu_data_llctrl, version_ind) + - sizeof(struct pdu_data_llctrl_version_ind); - pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_VERSION_IND; - pdu->llctrl.version_ind.version_number = - conn->llcp_version.version_number; - pdu->llctrl.version_ind.company_id = - sys_cpu_to_le16(conn->llcp_version.company_id); - pdu->llctrl.version_ind.sub_version_number = - sys_cpu_to_le16(conn->llcp_version.sub_version_number); - - /* enqueue version ind structure into rx queue */ - ll_rx_put_sched(rx->hdr.link, rx); - } else { - /* tx-ed but no rx, and new request placed */ - LL_ASSERT(0); - } -} - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) -static inline void event_conn_param_req(struct ll_conn *conn, - uint16_t event_counter, - uint32_t ticks_at_expire) -{ - struct pdu_data_llctrl_conn_param_req *p; - struct pdu_data *pdu_ctrl_tx; - struct node_tx *tx; - - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - return; - } - - /* place the conn param req packet as next in tx queue */ - pdu_ctrl_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_ctrl_tx); - - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = offsetof(struct pdu_data_llctrl, conn_param_req) + - sizeof(struct pdu_data_llctrl_conn_param_req); - pdu_ctrl_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ; - p = (void *)&pdu_ctrl_tx->llctrl.conn_param_req; - p->interval_min = sys_cpu_to_le16(conn->llcp_conn_param.interval_min); - p->interval_max = sys_cpu_to_le16(conn->llcp_conn_param.interval_max); - p->latency = sys_cpu_to_le16(conn->llcp_conn_param.latency); - p->timeout = sys_cpu_to_le16(conn->llcp_conn_param.timeout); - p->preferred_periodicity = 0U; - p->offset0 = sys_cpu_to_le16(0x0000); - p->offset1 = sys_cpu_to_le16(0xffff); - p->offset2 = sys_cpu_to_le16(0xffff); - p->offset3 = sys_cpu_to_le16(0xffff); - p->offset4 = sys_cpu_to_le16(0xffff); - p->offset5 = sys_cpu_to_le16(0xffff); - - /* Set CPR mutex */ - cpr_active_set(conn); - - /* Start Procedure Timeout (TODO: this shall not replace - * terminate procedure). - */ - conn->procedure_expire = conn->procedure_reload; - -#if defined(CONFIG_BT_CTLR_SCHED_ADVANCED) - /* move to wait for offset calculations */ - conn->llcp_conn_param.state = LLCP_CPR_STATE_OFFS_REQ; - - { - static memq_link_t s_link; - static struct mayfly s_mfy_sched_offset = {0, 0, &s_link, NULL, - ull_sched_mfy_free_win_offset_calc}; - uint32_t retval; - void *win_offs; - - conn->llcp_conn_param.ticks_ref = ticks_at_expire; - -#if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) - if (conn->ull.ticks_prepare_to_start & XON_BITMASK) { - uint32_t ticks_prepare_to_start = - MAX(conn->ull.ticks_active_to_start, - conn->ull.ticks_preempt_to_start); - - conn->llcp_conn_param.ticks_ref -= - (conn->ull.ticks_prepare_to_start & - ~XON_BITMASK) - ticks_prepare_to_start; - } -#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */ - - win_offs = &p->offset0; - /* No need to check alignment here since the pointer that gets - * stored is never derreferenced directly, only passed - * to memcpy(). - */ - conn->llcp_conn_param.pdu_win_offset0 = win_offs; - - s_mfy_sched_offset.param = (void *)conn; - - retval = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, - TICKER_USER_ID_ULL_LOW, 1, - &s_mfy_sched_offset); - LL_ASSERT(!retval); - } -#else /* !CONFIG_BT_CTLR_SCHED_ADVANCED */ - ARG_UNUSED(ticks_at_expire); - - /* set reference counter value */ - p->reference_conn_event_count = sys_cpu_to_le16(event_counter); - /* move to wait for conn_update_rsp/rej */ - conn->llcp_conn_param.state = LLCP_CPR_STATE_RSP_WAIT; - /* enqueue control PDU */ - ctrl_tx_enqueue(conn, tx); -#endif /* !CONFIG_BT_CTLR_SCHED_ADVANCED */ -} - -static inline void event_conn_param_rsp(struct ll_conn *conn) -{ - struct pdu_data_llctrl_conn_param_rsp *rsp; - struct node_tx *tx; - struct pdu_data *pdu; - - /* handle rejects */ - if (conn->llcp_conn_param.status) { - struct pdu_data_llctrl_reject_ext_ind *rej; - - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - return; - } - - /* central/peripheral response with reject ext ind */ - pdu = (void *)tx->pdu; - - ull_pdu_data_init(pdu); - - pdu->ll_id = PDU_DATA_LLID_CTRL; - pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_REJECT_EXT_IND; - pdu->len = offsetof(struct pdu_data_llctrl, reject_ext_ind) + - sizeof(struct pdu_data_llctrl_reject_ext_ind); - - rej = (void *)&pdu->llctrl.reject_ext_ind; - rej->reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ; - rej->error_code = conn->llcp_conn_param.status; - - ctrl_tx_enqueue(conn, tx); - - /* Check and initiate new CPR from cache, if any */ - cpr_cache_initiate_or_complete(conn); - - /* Reset CPR mutex */ - cpr_active_reset(); - - return; - } - - /* central respond with connection update */ - if (!conn->lll.role) { - uint16_t interval_max; - uint8_t preferred_periodicity; - - if (conn->llcp_cu.req != conn->llcp_cu.ack) { - return; - } - - /* Move to waiting for connection update completion */ - conn->llcp_conn_param.state = LLCP_CPR_STATE_UPD; - - /* Initiate connection update procedure */ - conn->llcp_cu.win_size = 1U; - conn->llcp_cu.win_offset_us = 0U; - - interval_max = conn->llcp_conn_param.interval_max; - preferred_periodicity = conn->llcp_conn_param.preferred_periodicity; - if (preferred_periodicity) { - /* Find interval with preferred periodicity by rounding down from max */ - conn->llcp_cu.interval = (interval_max / preferred_periodicity) * - preferred_periodicity; - /* Use maximum in case of underflowing minimum interval */ - if (conn->llcp_cu.interval < conn->llcp_conn_param.interval_min) { - conn->llcp_cu.interval = interval_max; - } - } else { - /* Choose maximum interval as default */ - conn->llcp_cu.interval = interval_max; - } - conn->llcp_cu.latency = conn->llcp_conn_param.latency; - conn->llcp_cu.timeout = conn->llcp_conn_param.timeout; - conn->llcp_cu.state = LLCP_CUI_STATE_SELECT; - conn->llcp_cu.cmd = conn->llcp_conn_param.cmd; - conn->llcp_cu.ack--; - - return; - } - - /* peripheral response with connection parameter response */ - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - return; - } - - /* place the conn param rsp packet as next in tx queue */ - pdu = (void *)tx->pdu; - - ull_pdu_data_init(pdu); - - pdu->ll_id = PDU_DATA_LLID_CTRL; - pdu->len = offsetof(struct pdu_data_llctrl, conn_param_rsp) + - sizeof(struct pdu_data_llctrl_conn_param_rsp); - pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_RSP; - rsp = (void *)&pdu->llctrl.conn_param_rsp; - rsp->interval_min = - sys_cpu_to_le16(conn->llcp_conn_param.interval_min); - rsp->interval_max = - sys_cpu_to_le16(conn->llcp_conn_param.interval_max); - rsp->latency = - sys_cpu_to_le16(conn->llcp_conn_param.latency); - rsp->timeout = - sys_cpu_to_le16(conn->llcp_conn_param.timeout); - rsp->preferred_periodicity = - conn->llcp_conn_param.preferred_periodicity; - rsp->reference_conn_event_count = - sys_cpu_to_le16(conn->llcp_conn_param.reference_conn_event_count); - rsp->offset0 = sys_cpu_to_le16(conn->llcp_conn_param.offset0); - rsp->offset1 = sys_cpu_to_le16(conn->llcp_conn_param.offset1); - rsp->offset2 = sys_cpu_to_le16(conn->llcp_conn_param.offset2); - rsp->offset3 = sys_cpu_to_le16(conn->llcp_conn_param.offset3); - rsp->offset4 = sys_cpu_to_le16(conn->llcp_conn_param.offset4); - rsp->offset5 = sys_cpu_to_le16(conn->llcp_conn_param.offset5); - - ctrl_tx_enqueue(conn, tx); - - /* Wait for connection update to be initiated by - * peer central device - */ - conn->llcp_conn_param.state = LLCP_CPR_STATE_UPD_WAIT; -} - -static inline void event_conn_param_app_req(struct ll_conn *conn) -{ - struct pdu_data_llctrl_conn_param_req *p; - struct node_rx_pdu *rx; - struct pdu_data *pdu; - -#if defined(CONFIG_BT_CTLR_LE_ENC) - /* defer until encryption setup is complete */ - if (conn->llcp_enc.pause_tx) { - return; - } -#endif /* CONFIG_BT_CTLR_LE_ENC */ - - /* wait for free rx buffer */ - rx = ll_pdu_rx_alloc(); - if (!rx) { - return; - } - - /* move to wait for conn_update/rsp/rej */ - conn->llcp_conn_param.state = LLCP_CPR_STATE_APP_WAIT; - - /* Emulate as Rx-ed CPR data channel PDU */ - rx->hdr.handle = conn->lll.handle; - rx->hdr.type = NODE_RX_TYPE_DC_PDU; - - /* place the conn param req packet as next in rx queue */ - pdu = (void *)rx->pdu; - pdu->ll_id = PDU_DATA_LLID_CTRL; - pdu->len = offsetof(struct pdu_data_llctrl, conn_param_req) + - sizeof(struct pdu_data_llctrl_conn_param_req); - pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ; - p = (void *) &pdu->llctrl.conn_param_req; - p->interval_min = sys_cpu_to_le16(conn->llcp_conn_param.interval_min); - p->interval_max = sys_cpu_to_le16(conn->llcp_conn_param.interval_max); - p->latency = sys_cpu_to_le16(conn->llcp_conn_param.latency); - p->timeout = sys_cpu_to_le16(conn->llcp_conn_param.timeout); - - /* enqueue connection parameter request into rx queue */ - ll_rx_put_sched(rx->hdr.link, rx); -} - -static inline void event_conn_param_prep(struct ll_conn *conn, - uint16_t event_counter, - uint32_t ticks_at_expire) -{ - /* Defer new CPR if another in progress across active connections */ - if (cpr_active_is_set(conn)) { - return; - } - - switch (conn->llcp_conn_param.state) { - case LLCP_CPR_STATE_REQ: - event_conn_param_req(conn, event_counter, ticks_at_expire); - break; - - case LLCP_CPR_STATE_RSP: - event_conn_param_rsp(conn); - break; - - case LLCP_CPR_STATE_APP_REQ: - event_conn_param_app_req(conn); - break; - - case LLCP_CPR_STATE_APP_WAIT: - case LLCP_CPR_STATE_RSP_WAIT: - case LLCP_CPR_STATE_UPD_WAIT: - case LLCP_CPR_STATE_UPD: - /* Do nothing */ - break; - -#if defined(CONFIG_BT_CTLR_SCHED_ADVANCED) - case LLCP_CPR_STATE_OFFS_REQ: - /* Do nothing */ - break; - - case LLCP_CPR_STATE_OFFS_RDY: - { - struct pdu_data *pdu_ctrl_tx; - struct node_tx *tx; - - /* set reference counter value */ - pdu_ctrl_tx = - CONTAINER_OF(conn->llcp_conn_param.pdu_win_offset0, - struct pdu_data, - llctrl.conn_param_req.offset0); - pdu_ctrl_tx->llctrl.conn_param_req.reference_conn_event_count = - sys_cpu_to_le16(event_counter); - /* move to wait for conn_update_rsp/rej */ - conn->llcp_conn_param.state = LLCP_CPR_STATE_RSP_WAIT; - /* enqueue control PDU */ - tx = CONTAINER_OF(pdu_ctrl_tx, struct node_tx, pdu); - ctrl_tx_enqueue(conn, tx); - } - break; -#endif /* CONFIG_BT_CTLR_SCHED_ADVANCED */ - - default: - LL_ASSERT(0); - break; - } -} -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - -#if defined(CONFIG_BT_CTLR_LE_PING) -static inline void event_ping_prep(struct ll_conn *conn) -{ - struct node_tx *tx; - - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (tx) { - struct pdu_data *pdu_ctrl_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_ctrl_tx); - - /* procedure request acked */ - conn->llcp_ack = conn->llcp_req; - - /* place the ping req packet as next in tx queue */ - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = offsetof(struct pdu_data_llctrl, ping_req) + - sizeof(struct pdu_data_llctrl_ping_req); - pdu_ctrl_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_PING_REQ; - - ctrl_tx_enqueue(conn, tx); - - /* Start Procedure Timeout (TODO: this shall not replace - * terminate procedure) - */ - conn->procedure_expire = conn->procedure_reload; - } - -} -#endif /* CONFIG_BT_CTLR_LE_PING */ - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) -static inline void dle_max_time_get(const struct ll_conn *conn, - uint16_t *max_rx_time, - uint16_t *max_tx_time) -{ - uint64_t feature_coded_phy = 0U; - uint64_t feature_phy_2m = 0U; - uint16_t rx_time = 0U; - uint16_t tx_time = 0U; - -#if defined(CONFIG_BT_CTLR_PHY) -#if defined(CONFIG_BT_CTLR_PHY_CODED) - feature_coded_phy = (conn->llcp_feature.features_conn & - BIT64(BT_LE_FEAT_BIT_PHY_CODED)); -#else - feature_coded_phy = 0U; -#endif - -#if defined(CONFIG_BT_CTLR_PHY_2M) - feature_phy_2m = (conn->llcp_feature.features_conn & - BIT64(BT_LE_FEAT_BIT_PHY_2M)); -#else - feature_phy_2m = 0U; -#endif -#else - feature_coded_phy = 0U; - feature_phy_2m = 0U; -#endif - - if (!conn->common.fex_valid || - (!feature_coded_phy && !feature_phy_2m)) { - rx_time = PDU_DC_MAX_US(LL_LENGTH_OCTETS_RX_MAX, PHY_1M); -#if defined(CONFIG_BT_CTLR_PHY) - tx_time = CLAMP(conn->default_tx_time, - PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M), - PDU_DC_MAX_US(LL_LENGTH_OCTETS_RX_MAX, PHY_1M)); -#else /* !CONFIG_BT_CTLR_PHY */ - tx_time = PDU_DC_MAX_US(conn->default_tx_octets, PHY_1M); -#endif /* !CONFIG_BT_CTLR_PHY */ - -#if defined(CONFIG_BT_CTLR_PHY) -#if defined(CONFIG_BT_CTLR_PHY_CODED) - } else if (feature_coded_phy) { - rx_time = MAX(PDU_DC_MAX_US(LL_LENGTH_OCTETS_RX_MAX, - PHY_CODED), - PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - PHY_CODED)); - tx_time = MIN(PDU_DC_MAX_US(LL_LENGTH_OCTETS_RX_MAX, - PHY_CODED), - conn->default_tx_time); - tx_time = MAX(PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - PHY_1M), tx_time); -#endif /* CONFIG_BT_CTLR_PHY_CODED */ - -#if defined(CONFIG_BT_CTLR_PHY_2M) - } else if (feature_phy_2m) { - rx_time = MAX(PDU_DC_MAX_US(LL_LENGTH_OCTETS_RX_MAX, PHY_2M), - PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_2M)); - tx_time = MAX(PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M), - MIN(PDU_DC_MAX_US(LL_LENGTH_OCTETS_RX_MAX, - PHY_2M), - conn->default_tx_time)); -#endif /* CONFIG_BT_CTLR_PHY_2M */ -#endif /* CONFIG_BT_CTLR_PHY */ - } - - /* - * see Vol. 6 Part B chapter 4.5.10 - * minimum value for time is 328 us - */ - rx_time = MAX(PDU_DC_PAYLOAD_TIME_MIN, rx_time); - tx_time = MAX(PDU_DC_PAYLOAD_TIME_MIN, tx_time); - - *max_rx_time = rx_time; - *max_tx_time = tx_time; -} - -static inline void event_len_prep(struct ll_conn *conn) -{ - switch (conn->llcp_length.state) { - case LLCP_LENGTH_STATE_REQ: - { - struct pdu_data_llctrl_length_req *lr; - struct pdu_data *pdu_ctrl_tx; - struct node_tx *tx; - /* - * initialize to 0 to eliminate compiler warnings - */ - uint16_t rx_time = 0U; - uint16_t tx_time = 0U; - - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - return; - } - - /* wait for resp before completing the procedure */ - conn->llcp_length.state = LLCP_LENGTH_STATE_REQ_ACK_WAIT; - - /* set the default tx octets/time to requested value */ - conn->default_tx_octets = conn->llcp_length.tx_octets; - -#if defined(CONFIG_BT_CTLR_PHY) - conn->default_tx_time = conn->llcp_length.tx_time; -#endif - - /* place the length req packet as next in tx queue */ - pdu_ctrl_tx = (void *) tx->pdu; - - ull_pdu_data_init(pdu_ctrl_tx); - - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = - offsetof(struct pdu_data_llctrl, length_req) + - sizeof(struct pdu_data_llctrl_length_req); - pdu_ctrl_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_LENGTH_REQ; - - lr = &pdu_ctrl_tx->llctrl.length_req; - lr->max_rx_octets = sys_cpu_to_le16(LL_LENGTH_OCTETS_RX_MAX); - lr->max_tx_octets = sys_cpu_to_le16(conn->default_tx_octets); - - dle_max_time_get(conn, &rx_time, &tx_time); - lr->max_rx_time = sys_cpu_to_le16(rx_time); - lr->max_tx_time = sys_cpu_to_le16(tx_time); - - ctrl_tx_enqueue(conn, tx); - - /* Start Procedure Timeout (TODO: this shall not replace - * terminate procedure). - */ - conn->procedure_expire = conn->procedure_reload; - } - break; - - case LLCP_LENGTH_STATE_RESIZE: - case LLCP_LENGTH_STATE_RESIZE_RSP: - { - struct pdu_data_llctrl_length_rsp *lr; - struct pdu_data *pdu_ctrl_rx; - struct node_rx_pdu *rx; - struct lll_conn *lll; - uint16_t tx_octets; - - lll = &conn->lll; - - /* Use the new rx octets/time in the connection */ - lll->max_rx_octets = conn->llcp_length.rx_octets; - - /* backup tx_octets */ - tx_octets = conn->llcp_length.tx_octets; - -#if defined(CONFIG_BT_CTLR_PHY) - /* Use the new rx time in the connection */ - lll->max_rx_time = conn->llcp_length.rx_time; - - /* backup tx time */ - uint16_t tx_time = conn->llcp_length.tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - - /* switch states, to wait for ack, to request cached values or - * complete the procedure - */ - if (conn->llcp_length.state == LLCP_LENGTH_STATE_RESIZE) { - /* check cache */ - if (!conn->llcp_length.cache.tx_octets) { - /* Procedure complete */ - conn->llcp_length.ack = conn->llcp_length.req; - conn->procedure_expire = 0U; - } else { - /* Initiate cached procedure */ - conn->llcp_length.tx_octets = - conn->llcp_length.cache.tx_octets; - conn->llcp_length.cache.tx_octets = 0U; -#if defined(CONFIG_BT_CTLR_PHY) - conn->llcp_length.tx_time = - conn->llcp_length.cache.tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - conn->llcp_length.state = LLCP_LENGTH_STATE_REQ; - } - } else { - conn->llcp_length.state = - LLCP_LENGTH_STATE_RESIZE_RSP_ACK_WAIT; - } - - /* Prepare the rx packet structure */ - rx = conn->llcp_rx; - LL_ASSERT(rx && rx->hdr.link); - conn->llcp_rx = rx->hdr.link->mem; - - rx->hdr.handle = conn->lll.handle; - rx->hdr.type = NODE_RX_TYPE_DC_PDU; - - /* prepare length rsp structure */ - pdu_ctrl_rx = (void *)rx->pdu; - pdu_ctrl_rx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_rx->len = - offsetof(struct pdu_data_llctrl, length_rsp) + - sizeof(struct pdu_data_llctrl_length_rsp); - pdu_ctrl_rx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_LENGTH_RSP; - - lr = &pdu_ctrl_rx->llctrl.length_rsp; - lr->max_rx_octets = sys_cpu_to_le16(lll->max_rx_octets); - lr->max_tx_octets = sys_cpu_to_le16(tx_octets); -#if !defined(CONFIG_BT_CTLR_PHY) - lr->max_rx_time = - sys_cpu_to_le16(PDU_DC_MAX_US(lll->max_rx_octets, - PHY_1M)); - lr->max_tx_time = sys_cpu_to_le16(PDU_DC_MAX_US(tx_octets, - PHY_1M)); -#else /* CONFIG_BT_CTLR_PHY */ - lr->max_rx_time = sys_cpu_to_le16(lll->max_rx_time); - lr->max_tx_time = sys_cpu_to_le16(tx_time); -#endif /* CONFIG_BT_CTLR_PHY */ - - /* enqueue rx node towards Thread */ - ll_rx_put_sched(rx->hdr.link, rx); - } - break; - - case LLCP_LENGTH_STATE_REQ_ACK_WAIT: - case LLCP_LENGTH_STATE_RSP_WAIT: - case LLCP_LENGTH_STATE_RSP_ACK_WAIT: - case LLCP_LENGTH_STATE_RESIZE_RSP_ACK_WAIT: - /* no nothing */ - break; - - default: - LL_ASSERT(0); - break; - } -} - -#if defined(CONFIG_BT_CTLR_PHY) -static uint16_t calc_eff_time(uint8_t max_octets, uint8_t phy, uint16_t default_time) -{ - uint16_t eff_time; - - eff_time = MAX(PDU_DC_PAYLOAD_TIME_MIN, PDU_DC_MAX_US(max_octets, phy)); - eff_time = MIN(eff_time, default_time); -#if defined(CONFIG_BT_CTLR_PHY_CODED) - eff_time = MAX(eff_time, PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, phy)); -#endif - - return eff_time; -} -#endif /* CONFIG_BT_CTLR_PHY */ -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - -#if defined(CONFIG_BT_CTLR_PHY) -static inline void event_phy_req_prep(struct ll_conn *conn) -{ - switch (conn->llcp_phy.state) { - case LLCP_PHY_STATE_REQ: - { - struct pdu_data_llctrl_phy_req *pr; - struct pdu_data *pdu_ctrl_tx; - struct node_tx *tx; - - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - break; - } - - conn->llcp_phy.state = LLCP_PHY_STATE_ACK_WAIT; - - /* update preferred phy */ - conn->phy_pref_tx = conn->llcp_phy.tx; - conn->phy_pref_rx = conn->llcp_phy.rx; - conn->lll.phy_flags = conn->llcp_phy.flags; - - /* place the phy req packet as next in tx queue */ - pdu_ctrl_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_ctrl_tx); - - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = - offsetof(struct pdu_data_llctrl, phy_req) + - sizeof(struct pdu_data_llctrl_phy_req); - pdu_ctrl_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_PHY_REQ; - - pr = &pdu_ctrl_tx->llctrl.phy_req; - pr->tx_phys = conn->llcp_phy.tx; - pr->rx_phys = conn->llcp_phy.rx; - - ctrl_tx_enqueue(conn, tx); - - /* Start Procedure Timeout (TODO: this shall not replace - * terminate procedure). - */ - conn->procedure_expire = conn->procedure_reload; - } - break; - - case LLCP_PHY_STATE_UPD: - { - /* Defer if another procedure in progress */ - if (conn->llcp_ack != conn->llcp_req) { - return; - } - - /* Procedure complete */ - conn->llcp_phy.ack = conn->llcp_phy.req; - - /* select only one tx phy, prefer 2M */ - if (conn->llcp_phy.tx & PHY_2M) { - conn->llcp_phy.tx = PHY_2M; - } else if (conn->llcp_phy.tx & PHY_1M) { - conn->llcp_phy.tx = PHY_1M; - } else if (conn->llcp_phy.tx & PHY_CODED) { - conn->llcp_phy.tx = PHY_CODED; - } else { - conn->llcp_phy.tx = 0U; - } - - /* select only one rx phy, prefer 2M */ - if (conn->llcp_phy.rx & PHY_2M) { - conn->llcp_phy.rx = PHY_2M; - } else if (conn->llcp_phy.rx & PHY_1M) { - conn->llcp_phy.rx = PHY_1M; - } else if (conn->llcp_phy.rx & PHY_CODED) { - conn->llcp_phy.rx = PHY_CODED; - } else { - conn->llcp_phy.rx = 0U; - } - - /* Initiate PHY Update Ind */ - if (conn->llcp_phy.tx != conn->lll.phy_tx) { - conn->llcp.phy_upd_ind.tx = conn->llcp_phy.tx; - } else { - conn->llcp.phy_upd_ind.tx = 0U; - } - if (conn->llcp_phy.rx != conn->lll.phy_rx) { - conn->llcp.phy_upd_ind.rx = conn->llcp_phy.rx; - } else { - conn->llcp.phy_upd_ind.rx = 0U; - } - /* conn->llcp.phy_upd_ind.instant = 0U; for now, will be filled - * in initiate state. - */ - conn->llcp.phy_upd_ind.initiate = 1U; - conn->llcp.phy_upd_ind.cmd = conn->llcp_phy.cmd; - - conn->llcp_type = LLCP_PHY_UPD; - conn->llcp_ack -= 2U; - } - break; - - case LLCP_PHY_STATE_ACK_WAIT: - case LLCP_PHY_STATE_RSP_WAIT: - /* no nothing */ - break; - - default: - LL_ASSERT(0); - break; - } -} - -static inline void event_phy_upd_ind_prep(struct ll_conn *conn, - uint16_t event_counter) -{ - struct node_rx_pu *upd; - - if (conn->llcp.phy_upd_ind.initiate) { - struct pdu_data_llctrl_phy_upd_ind *ind; - struct pdu_data *pdu_ctrl_tx; - struct node_rx_pdu *rx; - struct node_tx *tx; - - /* Delay until all pending Tx in LLL is acknowledged, - * conn->llcp_phy.pause_tx is true, new Tx PDUs will not be - * enqueued until we proceed to initiate PHY update. - * This is required to ensure PDU with instant can be - * transmitted before instant expires. - */ - if (memq_peek(conn->lll.memq_tx.head, conn->lll.memq_tx.tail, - NULL)) { - return; - } - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - rx = ll_pdu_rx_alloc_peek(2); -#else /* !CONFIG_BT_CTLR_DATA_LENGTH */ - rx = ll_pdu_rx_alloc_peek(1); -#endif /* !CONFIG_BT_CTLR_DATA_LENGTH */ - if (!rx) { - return; - } - - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - return; - } - - /* reset initiate flag */ - conn->llcp.phy_upd_ind.initiate = 0U; - - /* Check if both tx and rx PHY unchanged */ - if (!((conn->llcp.phy_upd_ind.tx | - conn->llcp.phy_upd_ind.rx) & 0x07)) { - /* Procedure complete */ - conn->llcp_ack = conn->llcp_req; - - /* 0 instant */ - conn->llcp.phy_upd_ind.instant = 0U; - - /* generate phy update event */ - if (conn->llcp.phy_upd_ind.cmd) { - struct lll_conn *lll = &conn->lll; - - (void)ll_pdu_rx_alloc(); - - rx->hdr.handle = lll->handle; - rx->hdr.type = NODE_RX_TYPE_PHY_UPDATE; - - upd = (void *)rx->pdu; - upd->status = 0U; - upd->tx = lll->phy_tx; - upd->rx = lll->phy_rx; - - /* Enqueue Rx node */ - ll_rx_put_sched(rx->hdr.link, rx); - } - } else { - struct lll_conn *lll = &conn->lll; - - /* set instant */ - conn->llcp.phy_upd_ind.instant = event_counter + - lll->latency + - 6; - /* reserve rx node for event generation at instant */ - (void)ll_pdu_rx_alloc(); - rx->hdr.link->mem = conn->llcp_rx; - conn->llcp_rx = rx; - - /* reserve rx node for DLE event generation */ - if (IS_ENABLED(CONFIG_BT_CTLR_DATA_LENGTH)) { - rx = ll_pdu_rx_alloc(); - rx->hdr.link->mem = conn->llcp_rx; - conn->llcp_rx = rx; - } - } - - /* place the phy update ind packet as next in - * tx queue - */ - pdu_ctrl_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_ctrl_tx); - - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = - offsetof(struct pdu_data_llctrl, phy_upd_ind) + - sizeof(struct pdu_data_llctrl_phy_upd_ind); - pdu_ctrl_tx->llctrl.opcode = - PDU_DATA_LLCTRL_TYPE_PHY_UPD_IND; - ind = &pdu_ctrl_tx->llctrl.phy_upd_ind; - ind->c_to_p_phy = conn->llcp.phy_upd_ind.tx; - ind->p_to_c_phy = conn->llcp.phy_upd_ind.rx; - ind->instant = sys_cpu_to_le16(conn->llcp.phy_upd_ind.instant); - - ctrl_tx_enqueue(conn, tx); - } else if (((event_counter - conn->llcp.phy_upd_ind.instant) & - 0xFFFF) <= 0x7FFF) { - struct lll_conn *lll = &conn->lll; - struct node_rx_pdu *rx; - uint8_t old_tx, old_rx; - uint8_t phy_bitmask; - - /* Acquire additional rx node for Data length notification as - * a peripheral. - */ - if (IS_ENABLED(CONFIG_BT_PERIPHERAL) && - IS_ENABLED(CONFIG_BT_CTLR_DATA_LENGTH) && - conn->lll.role) { - rx = ll_pdu_rx_alloc(); - if (!rx) { - return; - } - - rx->hdr.link->mem = conn->llcp_rx; - conn->llcp_rx = rx; - } - -#if defined(CONFIG_BT_PERIPHERAL) && defined(CONFIG_BT_CTLR_LE_ENC) - if (conn->lll.role && (conn->periph.llcp_type != LLCP_NONE)) { - /* Local peripheral initiated PHY update completed while - * a remote central had initiated encryption procedure - */ - conn->periph.llcp_type = LLCP_NONE; - } else -#endif /* CONFIG_BT_PERIPHERAL && CONFIG_BT_CTLR_LE_ENC */ - { - /* procedure request acked */ - conn->llcp_ack = conn->llcp_req; - } - - /* supported PHYs mask */ - phy_bitmask = PHY_1M; - if (IS_ENABLED(CONFIG_BT_CTLR_PHY_2M)) { - phy_bitmask |= PHY_2M; - } - if (IS_ENABLED(CONFIG_BT_CTLR_PHY_CODED)) { - phy_bitmask |= PHY_CODED; - } - - /* apply new phy */ - old_tx = lll->phy_tx; - old_rx = lll->phy_rx; - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - uint16_t eff_tx_time = lll->max_tx_time; - uint16_t eff_rx_time = lll->max_rx_time; - uint16_t max_rx_time, max_tx_time; - - dle_max_time_get(conn, &max_rx_time, &max_tx_time); -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - - if (conn->llcp.phy_upd_ind.tx) { - if (conn->llcp.phy_upd_ind.tx & phy_bitmask) { - lll->phy_tx = conn->llcp.phy_upd_ind.tx & - phy_bitmask; - } - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - eff_tx_time = calc_eff_time(lll->max_tx_octets, - lll->phy_tx, - max_tx_time); - -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - } - if (conn->llcp.phy_upd_ind.rx) { - if (conn->llcp.phy_upd_ind.rx & phy_bitmask) { - lll->phy_rx = conn->llcp.phy_upd_ind.rx & - phy_bitmask; - } - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - eff_rx_time = - calc_eff_time(lll->max_rx_octets, lll->phy_rx, - max_rx_time); - -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - } - - /* Acquire Rx node */ - rx = conn->llcp_rx; - LL_ASSERT(rx && rx->hdr.link); - conn->llcp_rx = rx->hdr.link->mem; - - /* generate event if phy changed or initiated by cmd */ - if (!conn->llcp.phy_upd_ind.cmd && (lll->phy_tx == old_tx) && - (lll->phy_rx == old_rx)) { - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - /* enqueue rx node towards Thread */ - ll_rx_put(rx->hdr.link, rx); - - /* Release rx node that was reserved for Data Length - * notification. - */ - if (IS_ENABLED(CONFIG_BT_CTLR_DATA_LENGTH)) { - /* Get the DLE rx node reserved for ULL->LL */ - rx = conn->llcp_rx; - LL_ASSERT(rx && rx->hdr.link); - conn->llcp_rx = rx->hdr.link->mem; - - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - /* enqueue rx node towards Thread */ - ll_rx_put(rx->hdr.link, rx); - } - - ll_rx_sched(); - - return; - } - - rx->hdr.handle = lll->handle; - rx->hdr.type = NODE_RX_TYPE_PHY_UPDATE; - - upd = (void *)rx->pdu; - upd->status = 0U; - upd->tx = lll->phy_tx; - upd->rx = lll->phy_rx; - -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) - /* hold node rx until the instant's anchor point sync */ - rx_hold_put(conn, rx->hdr.link, rx); -#else /* !CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - /* enqueue rx node towards Thread */ - ll_rx_put(rx->hdr.link, rx); -#endif /* !CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - /* get a rx node for ULL->LL */ - rx = conn->llcp_rx; - LL_ASSERT(rx && rx->hdr.link); - conn->llcp_rx = rx->hdr.link->mem; - - /* Update max tx and/or max rx if changed */ - if ((eff_tx_time <= lll->max_tx_time) && - (lll->max_tx_time <= max_tx_time) && - (eff_rx_time <= lll->max_rx_time) && - (lll->max_rx_time <= max_rx_time)) { - /* Mark buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - /* enqueue rx node towards Thread */ - ll_rx_put_sched(rx->hdr.link, rx); - return; - } - lll->max_tx_time = eff_tx_time; - lll->max_rx_time = eff_rx_time; - - /* prepare length rsp structure */ - rx->hdr.handle = lll->handle; - rx->hdr.type = NODE_RX_TYPE_DC_PDU; - - struct pdu_data *pdu_rx = (void *)rx->pdu; - - pdu_rx->ll_id = PDU_DATA_LLID_CTRL; - pdu_rx->len = offsetof(struct pdu_data_llctrl, length_rsp) + - sizeof(struct pdu_data_llctrl_length_rsp); - pdu_rx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_LENGTH_RSP; - - struct pdu_data_llctrl_length_req *lr = - (void *)&pdu_rx->llctrl.length_rsp; - - lr->max_rx_octets = sys_cpu_to_le16(lll->max_rx_octets); - lr->max_tx_octets = sys_cpu_to_le16(lll->max_tx_octets); - lr->max_rx_time = sys_cpu_to_le16(lll->max_rx_time); - lr->max_tx_time = sys_cpu_to_le16(lll->max_tx_time); - -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) - /* hold node rx until the instant's anchor point sync */ - rx_hold_put(conn, rx->hdr.link, rx); -#else /* !CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - /* enqueue rx node towards Thread */ - ll_rx_put(rx->hdr.link, rx); -#endif /* !CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - - if (!IS_ENABLED(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD)) { - /* Only trigger the rx_demux mayfly when PHY and/or DLE - * node rx are not held back until the anchor point sync - */ - ll_rx_sched(); - } - } -} -#endif /* CONFIG_BT_CTLR_PHY */ - -#if defined(CONFIG_BT_PERIPHERAL) -static uint8_t conn_upd_recv(struct ll_conn *conn, memq_link_t *link, - struct node_rx_pdu **rx, struct pdu_data *pdu) -{ - uint16_t instant; - - instant = sys_le16_to_cpu(pdu->llctrl.conn_update_ind.instant); - if (((instant - conn->lll.event_counter) & 0xFFFF) > 0x7FFF) { - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - return BT_HCI_ERR_INSTANT_PASSED; - } - - /* different transaction collision */ - if (((conn->llcp_req - conn->llcp_ack) & 0x03) == 0x02) { - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - return BT_HCI_ERR_DIFF_TRANS_COLLISION; - } - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - /* Set CPR mutex, if only not already set. As a central the mutex shall - * be set, but a peripheral we accept it as new 'set' of mutex. - */ - cpr_active_check_and_set(conn); -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - - conn->llcp_cu.win_size = pdu->llctrl.conn_update_ind.win_size; - conn->llcp_cu.win_offset_us = - sys_le16_to_cpu(pdu->llctrl.conn_update_ind.win_offset) * - CONN_INT_UNIT_US; - conn->llcp_cu.interval = - sys_le16_to_cpu(pdu->llctrl.conn_update_ind.interval); - conn->llcp_cu.latency = - sys_le16_to_cpu(pdu->llctrl.conn_update_ind.latency); - conn->llcp_cu.timeout = - sys_le16_to_cpu(pdu->llctrl.conn_update_ind.timeout); - conn->llcp.conn_upd.instant = instant; - conn->llcp_cu.state = LLCP_CUI_STATE_INPROG; - conn->llcp_cu.cmd = 1U; - conn->llcp_cu.ack--; - - link->mem = conn->llcp_rx; - (*rx)->hdr.link = link; - conn->llcp_rx = *rx; - *rx = NULL; - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - if ((conn->llcp_conn_param.req != conn->llcp_conn_param.ack) && - ((conn->llcp_conn_param.state == LLCP_CPR_STATE_RSP_WAIT) || - (conn->llcp_conn_param.state == LLCP_CPR_STATE_UPD_WAIT))) { - /* Check and initiate new CPR from cache, if any */ - cpr_cache_initiate_or_complete(conn); - } -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - - return 0; -} - -static uint8_t chan_map_upd_recv(struct ll_conn *conn, struct node_rx_pdu *rx, - struct pdu_data *pdu) -{ - uint8_t err = 0U; - uint16_t instant; - - instant = sys_le16_to_cpu(pdu->llctrl.chan_map_ind.instant); - if (((instant - conn->lll.event_counter) & 0xffff) > 0x7fff) { - err = BT_HCI_ERR_INSTANT_PASSED; - - goto chan_map_upd_recv_exit; - } - - /* different transaction collision */ - if (((conn->llcp_req - conn->llcp_ack) & 0x03) == 0x02) { - err = BT_HCI_ERR_DIFF_TRANS_COLLISION; - - goto chan_map_upd_recv_exit; - } - - - memcpy(&conn->llcp.chan_map.chm[0], &pdu->llctrl.chan_map_ind.chm[0], - sizeof(conn->llcp.chan_map.chm)); - conn->llcp.chan_map.instant = instant; - conn->llcp.chan_map.initiate = 0U; - - conn->llcp_type = LLCP_CHAN_MAP; - conn->llcp_ack -= 2U; - -chan_map_upd_recv_exit: - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - return err; -} -#endif /* CONFIG_BT_PERIPHERAL */ - -static void terminate_ind_recv(struct ll_conn *conn, struct node_rx_pdu *rx, - struct pdu_data *pdu) -{ - /* Ack and then terminate */ - conn->llcp_terminate.reason_final = - pdu->llctrl.terminate_ind.error_code; - - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; -} - -#if defined(CONFIG_BT_CTLR_LE_ENC) -#if defined(CONFIG_BT_CENTRAL) -static void enc_req_reused_send(struct ll_conn *conn, struct node_tx **tx) -{ - struct pdu_data *pdu_ctrl_tx; - - pdu_ctrl_tx = (void *)(*tx)->pdu; - - ull_pdu_data_init(pdu_ctrl_tx); - - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = offsetof(struct pdu_data_llctrl, enc_req) + - sizeof(struct pdu_data_llctrl_enc_req); - pdu_ctrl_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_ENC_REQ; - memcpy(&pdu_ctrl_tx->llctrl.enc_req.rand[0], &conn->llcp_enc.rand[0], - sizeof(pdu_ctrl_tx->llctrl.enc_req.rand)); - pdu_ctrl_tx->llctrl.enc_req.ediv[0] = conn->llcp_enc.ediv[0]; - pdu_ctrl_tx->llctrl.enc_req.ediv[1] = conn->llcp_enc.ediv[1]; - - /* - * Take advantage of the fact that ivm and skdm fields, which both have - * to be filled with random data, are adjacent and use single call to - * the entropy driver. - */ - BUILD_ASSERT(offsetof(__typeof(pdu_ctrl_tx->llctrl.enc_req), ivm) == - (offsetof(__typeof(pdu_ctrl_tx->llctrl.enc_req), skdm) + - sizeof(pdu_ctrl_tx->llctrl.enc_req.skdm))); - - /* NOTE: if not sufficient random numbers, ignore waiting */ - lll_csrand_isr_get(pdu_ctrl_tx->llctrl.enc_req.skdm, - sizeof(pdu_ctrl_tx->llctrl.enc_req.skdm) + - sizeof(pdu_ctrl_tx->llctrl.enc_req.ivm)); - - ctrl_tx_enqueue(conn, *tx); - - /* dont release ctrl PDU memory */ - *tx = NULL; -} -#endif /* CONFIG_BT_CENTRAL */ - -#if defined(CONFIG_BT_PERIPHERAL) -static int enc_rsp_send(struct ll_conn *conn) -{ - struct pdu_data *pdu_ctrl_tx; - struct node_tx *tx; - - /* acquire tx mem */ - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - return -ENOBUFS; - } - - pdu_ctrl_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_ctrl_tx); - - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = offsetof(struct pdu_data_llctrl, enc_rsp) + - sizeof(struct pdu_data_llctrl_enc_rsp); - pdu_ctrl_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_ENC_RSP; - - /* - * Take advantage of the fact that ivs and skds fields, which both have - * to be filled with random data, are adjacent and use single call to - * the entropy driver. - */ - BUILD_ASSERT(offsetof(__typeof(pdu_ctrl_tx->llctrl.enc_rsp), ivs) == - (offsetof(__typeof(pdu_ctrl_tx->llctrl.enc_rsp), skds) + - sizeof(pdu_ctrl_tx->llctrl.enc_rsp.skds))); - - /* NOTE: if not sufficient random numbers, ignore waiting */ - lll_csrand_isr_get(pdu_ctrl_tx->llctrl.enc_rsp.skds, - sizeof(pdu_ctrl_tx->llctrl.enc_rsp.skds) + - sizeof(pdu_ctrl_tx->llctrl.enc_rsp.ivs)); - - /* things from peripheral stored for session key calculation */ - memcpy(&conn->llcp.encryption.skd[8], - &pdu_ctrl_tx->llctrl.enc_rsp.skds[0], 8); - memcpy(&conn->lll.ccm_rx.iv[4], - &pdu_ctrl_tx->llctrl.enc_rsp.ivs[0], 4); - - ctrl_tx_enqueue(conn, tx); - - return 0; -} -#endif /* CONFIG_BT_PERIPHERAL */ - -static int start_enc_rsp_send(struct ll_conn *conn, - struct pdu_data *pdu_ctrl_tx) -{ - struct node_tx *tx = NULL; - - if (!pdu_ctrl_tx) { - /* acquire tx mem */ - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - return -ENOBUFS; - } - - pdu_ctrl_tx = (void *)tx->pdu; - } - - /* enable transmit encryption */ - conn->lll.enc_tx = 1; - - ull_pdu_data_init(pdu_ctrl_tx); - - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = offsetof(struct pdu_data_llctrl, enc_rsp); - pdu_ctrl_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_START_ENC_RSP; - - if (tx) { - ctrl_tx_enqueue(conn, tx); - } - - return 0; -} - -static inline bool ctrl_is_unexpected(struct ll_conn *conn, uint8_t opcode) -{ - return (!conn->lll.role && - ((!conn->llcp_enc.refresh && - (opcode != PDU_DATA_LLCTRL_TYPE_TERMINATE_IND) && - (opcode != PDU_DATA_LLCTRL_TYPE_START_ENC_REQ) && - (opcode != PDU_DATA_LLCTRL_TYPE_START_ENC_RSP) && - (opcode != PDU_DATA_LLCTRL_TYPE_REJECT_IND) && - (opcode != PDU_DATA_LLCTRL_TYPE_REJECT_EXT_IND)) || - (conn->llcp_enc.refresh && - (opcode != PDU_DATA_LLCTRL_TYPE_TERMINATE_IND) && - (opcode != PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_RSP) && - (opcode != PDU_DATA_LLCTRL_TYPE_ENC_RSP) && - (opcode != PDU_DATA_LLCTRL_TYPE_START_ENC_REQ) && - (opcode != PDU_DATA_LLCTRL_TYPE_START_ENC_RSP) && - (opcode != PDU_DATA_LLCTRL_TYPE_REJECT_IND) && - (opcode != PDU_DATA_LLCTRL_TYPE_REJECT_EXT_IND)))) || - (conn->lll.role && - ((!conn->llcp_enc.refresh && - (opcode != PDU_DATA_LLCTRL_TYPE_UNKNOWN_RSP) && - (opcode != PDU_DATA_LLCTRL_TYPE_TERMINATE_IND) && - (opcode != PDU_DATA_LLCTRL_TYPE_START_ENC_RSP) && - (opcode != PDU_DATA_LLCTRL_TYPE_REJECT_IND) && - (opcode != PDU_DATA_LLCTRL_TYPE_REJECT_EXT_IND)) || - (conn->llcp_enc.refresh && - (opcode != PDU_DATA_LLCTRL_TYPE_TERMINATE_IND) && - (opcode != PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_RSP) && - (opcode != PDU_DATA_LLCTRL_TYPE_ENC_REQ) && - (opcode != PDU_DATA_LLCTRL_TYPE_START_ENC_RSP) && - (opcode != PDU_DATA_LLCTRL_TYPE_REJECT_IND) && - (opcode != PDU_DATA_LLCTRL_TYPE_REJECT_EXT_IND)))); -} - -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -static int unknown_rsp_send(struct ll_conn *conn, struct node_rx_pdu *rx, - uint8_t type) -{ - struct pdu_data *pdu; - struct node_tx *tx; - int err; - - /* Check transaction violation and get free ctrl tx PDU */ - tx = ctrl_tx_rsp_mem_acquire(conn, rx, &err); - if (!tx) { - return err; - } - - pdu = (void *)tx->pdu; - - ull_pdu_data_init(pdu); - - pdu->ll_id = PDU_DATA_LLID_CTRL; - pdu->len = offsetof(struct pdu_data_llctrl, unknown_rsp) + - sizeof(struct pdu_data_llctrl_unknown_rsp); - pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_UNKNOWN_RSP; - pdu->llctrl.unknown_rsp.type = type; - - ctrl_tx_enqueue(conn, tx); - - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - return 0; -} - -static inline uint64_t feat_get(uint8_t *features) -{ - uint64_t feat; - - feat = sys_get_le64(features) | ~LL_FEAT_BIT_MASK_VALID; - feat &= LL_FEAT_BIT_MASK; - - return feat; -} - -/* - * Perform a logical and on octet0 and keep the remaining bits of the - * first input parameter - */ -static inline uint64_t feat_land_octet0(uint64_t feat_to_keep, - uint64_t feat_octet0) -{ - uint64_t feat_result; - - feat_result = feat_to_keep & feat_octet0; - feat_result &= 0xFF; - feat_result |= feat_to_keep & LL_FEAT_FILTER_OCTET0; - - return feat_result; -} - -#if defined(CONFIG_BT_PERIPHERAL) || \ - (defined(CONFIG_BT_CENTRAL) && defined(CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG)) -static int feature_rsp_send(struct ll_conn *conn, struct node_rx_pdu *rx, - struct pdu_data *pdu_rx) -{ - struct pdu_data_llctrl_feature_req *req; - struct pdu_data *pdu_tx; - struct node_tx *tx; - uint64_t feat; - int err; - - /* Check transaction violation and get free ctrl tx PDU */ - tx = ctrl_tx_rsp_mem_acquire(conn, rx, &err); - if (!tx) { - return err; - } - - /* AND the feature set to get Feature USED */ - req = &pdu_rx->llctrl.feature_req; - conn->llcp_feature.features_conn &= feat_get(&req->features[0]); - /* - * Get all the features of peer, except octet 0. - * Octet 0 is the actual features used on the link - * See BTCore V5.2, Vol. 6, Part B, chapter 5.1.4 - */ - conn->llcp_feature.features_peer = - feat_land_octet0(feat_get(&req->features[0]), ll_feat_get()); - - /* features exchanged */ - conn->common.fex_valid = 1U; - - /* Enqueue feature response */ - pdu_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_tx); - - pdu_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_tx->len = offsetof(struct pdu_data_llctrl, feature_rsp) + - sizeof(struct pdu_data_llctrl_feature_rsp); - pdu_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_FEATURE_RSP; - (void)memset(&pdu_tx->llctrl.feature_rsp.features[0], 0x00, - sizeof(pdu_tx->llctrl.feature_rsp.features)); - /* - * On feature response we send the local supported features. - * See BTCore V5.2 VOl 6 Part B, chapter 5.1.4 - */ - feat = feat_land_octet0(ll_feat_get(), - conn->llcp_feature.features_conn); - sys_put_le64(feat, pdu_tx->llctrl.feature_rsp.features); - - ctrl_tx_sec_enqueue(conn, tx); - - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - return 0; -} -#endif /* PERIPHERAL || (CENTRAL && PER_INIT_FEAT_XCHG) */ - -#if defined(CONFIG_BT_CENTRAL) || defined(CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG) -static void feature_rsp_recv(struct ll_conn *conn, struct pdu_data *pdu_rx) -{ - struct pdu_data_llctrl_feature_rsp *rsp; - - rsp = &pdu_rx->llctrl.feature_rsp; - - /* AND the feature set to get Feature USED */ - conn->llcp_feature.features_conn &= feat_get(&rsp->features[0]); - /* - * Get all the features of peer, except octet 0. - * Octet 0 is the actual features used on the link - * See BTCore V5.2, Vol. 6, Part B, chapter 5.1.4 - */ - conn->llcp_feature.features_peer = - feat_land_octet0(feat_get(&rsp->features[0]), ll_feat_get()); - - /* features exchanged */ - conn->common.fex_valid = 1U; - - /* Procedure complete */ - conn->llcp_feature.ack = conn->llcp_feature.req; - conn->procedure_expire = 0U; -} -#endif /* CONFIG_BT_CENTRAL || CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG */ - -#if defined(CONFIG_BT_CTLR_LE_ENC) -static int pause_enc_rsp_send(struct ll_conn *conn, struct node_rx_pdu *rx, - uint8_t req) -{ - struct pdu_data *pdu_ctrl_tx; - struct node_tx *tx; - - if (req) { - /* acquire tx mem */ - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - return -ENOBUFS; - } - - /* key refresh */ - conn->llcp_enc.refresh = 1U; - } else if (!conn->lll.role) { - /* acquire tx mem */ - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - return -ENOBUFS; - } - - /* disable transmit encryption */ - conn->lll.enc_tx = 0U; - } else { - /* disable transmit encryption */ - conn->lll.enc_tx = 0U; - - goto pause_enc_rsp_send_exit; - } - - /* pause data packet rx */ - conn->llcp_enc.pause_rx = 1U; - - /* disable receive encryption */ - conn->lll.enc_rx = 0U; - - /* Enqueue pause enc rsp */ - pdu_ctrl_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_ctrl_tx); - - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = offsetof(struct pdu_data_llctrl, enc_rsp); - pdu_ctrl_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_RSP; - - ctrl_tx_enqueue(conn, tx); - -pause_enc_rsp_send_exit: - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - return 0; -} -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -static int version_ind_send(struct ll_conn *conn, struct node_rx_pdu *rx, - struct pdu_data *pdu_rx) -{ - struct pdu_data_llctrl_version_ind *v; - struct pdu_data *pdu_tx; - struct node_tx *tx; - - if (!conn->llcp_version.tx) { - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (!tx) { - return -ENOBUFS; - } - conn->llcp_version.tx = 1U; - - pdu_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_tx); - - pdu_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_tx->len = - offsetof(struct pdu_data_llctrl, version_ind) + - sizeof(struct pdu_data_llctrl_version_ind); - pdu_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_VERSION_IND; - v = &pdu_tx->llctrl.version_ind; - v->version_number = LL_VERSION_NUMBER; - v->company_id = sys_cpu_to_le16(ll_settings_company_id()); - v->sub_version_number = - sys_cpu_to_le16(ll_settings_subversion_number()); - - ctrl_tx_sec_enqueue(conn, tx); - - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - } else if (!conn->llcp_version.rx) { - /* procedure request acked */ - conn->llcp_version.ack = conn->llcp_version.req; - - /* Procedure complete */ - conn->procedure_expire = 0U; - } else { - /* Tx-ed and Rx-ed before, ignore this invalid Rx. */ - - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - return 0; - } - - v = &pdu_rx->llctrl.version_ind; - conn->llcp_version.version_number = v->version_number; - conn->llcp_version.company_id = sys_le16_to_cpu(v->company_id); - conn->llcp_version.sub_version_number = - sys_le16_to_cpu(v->sub_version_number); - conn->llcp_version.rx = 1U; - - return 0; -} - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) || defined(CONFIG_BT_CTLR_PHY) -static int reject_ext_ind_send(struct ll_conn *conn, struct node_rx_pdu *rx, - uint8_t reject_opcode, uint8_t error_code) -{ - struct pdu_data *pdu_ctrl_tx; - struct node_tx *tx; - int err; - - /* Check transaction violation and get free ctrl tx PDU */ - tx = ctrl_tx_rsp_mem_acquire(conn, rx, &err); - if (!tx) { - return err; - } - - pdu_ctrl_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_ctrl_tx); - - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = offsetof(struct pdu_data_llctrl, reject_ext_ind) + - sizeof(struct pdu_data_llctrl_reject_ext_ind); - pdu_ctrl_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_REJECT_EXT_IND; - pdu_ctrl_tx->llctrl.reject_ext_ind.reject_opcode = reject_opcode; - pdu_ctrl_tx->llctrl.reject_ext_ind.error_code = error_code; - - ctrl_tx_enqueue(conn, tx); - - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - return 0; -} -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ || PHY */ - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) -static inline int reject_ind_conn_upd_recv(struct ll_conn *conn, - struct node_rx_pdu *rx, - struct pdu_data *pdu_rx) -{ - struct pdu_data_llctrl_reject_ext_ind *rej_ext_ind; - struct node_rx_cu *cu; - struct lll_conn *lll; - void *node; - - /* Unsupported remote feature */ - lll = &conn->lll; - rej_ext_ind = (void *)&pdu_rx->llctrl.reject_ext_ind; - if (!lll->role && (rej_ext_ind->error_code == - BT_HCI_ERR_UNSUPP_REMOTE_FEATURE)) { - LL_ASSERT(conn->llcp_cu.req == conn->llcp_cu.ack); - - conn->llcp_conn_param.state = LLCP_CPR_STATE_UPD; - - conn->llcp_cu.win_size = 1U; - conn->llcp_cu.win_offset_us = 0U; - conn->llcp_cu.interval = conn->llcp_conn_param.interval_max; - conn->llcp_cu.latency = conn->llcp_conn_param.latency; - conn->llcp_cu.timeout = conn->llcp_conn_param.timeout; - conn->llcp_cu.state = LLCP_CUI_STATE_USE; - conn->llcp_cu.cmd = conn->llcp_conn_param.cmd; - conn->llcp_cu.ack--; - - return -EINVAL; - } - /* FIXME: handle unsupported LL parameters error */ - else if (rej_ext_ind->error_code != BT_HCI_ERR_LL_PROC_COLLISION) { -#if defined(CONFIG_BT_PERIPHERAL) - /* update to next ticks offset */ - if (lll->role) { - conn->periph.ticks_to_offset = - conn->llcp_conn_param.ticks_to_offset_next; - } -#endif /* CONFIG_BT_PERIPHERAL */ - } - - if (conn->llcp_conn_param.state == LLCP_CPR_STATE_RSP_WAIT) { - /* Reset CPR mutex */ - cpr_active_reset(); - - /* Check and initiate new CPR from cache, if any */ - cpr_cache_initiate_or_complete(conn); - - /* Stop procedure timeout */ - conn->procedure_expire = 0U; - } - - /* skip event generation if not cmd initiated */ - if (!conn->llcp_conn_param.cmd) { - return -EINVAL; - } - - /* generate conn update complete event with error code */ - rx->hdr.type = NODE_RX_TYPE_CONN_UPDATE; - - /* check for pdu field being aligned before populating - * connection update complete event. - */ - node = pdu_rx; - LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_cu)); - - /* prepare connection update complete structure */ - cu = node; - cu->status = rej_ext_ind->error_code; - cu->interval = lll->interval; - cu->latency = lll->latency; - cu->timeout = conn->supervision_timeout; - - return 0; -} - -static void cpr_cache_initiate_or_complete(struct ll_conn *conn) -{ - if (conn->llcp_conn_param.cache.timeout) { - conn->llcp_conn_param.status = 0U; - conn->llcp_conn_param.interval_min = - conn->llcp_conn_param.cache.interval_min; - conn->llcp_conn_param.interval_max = - conn->llcp_conn_param.cache.interval_max; - conn->llcp_conn_param.latency = - conn->llcp_conn_param.cache.latency; - conn->llcp_conn_param.timeout = - conn->llcp_conn_param.cache.timeout; - conn->llcp_conn_param.state = LLCP_CPR_STATE_REQ; - conn->llcp_conn_param.cmd = 1U; - conn->llcp_conn_param.remote = 0U; - - /* Invalidate cache */ - conn->llcp_conn_param.cache.timeout = 0U; - } else { - conn->llcp_conn_param.ack = conn->llcp_conn_param.req; - } -} - -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) -static inline int reject_ind_dle_recv(struct ll_conn *conn, - struct pdu_data *pdu_rx) -{ - struct pdu_data_llctrl_length_req *lr; - - /* Procedure complete */ - conn->llcp_length.ack = conn->llcp_length.req; - conn->procedure_expire = 0U; - - /* prepare length rsp structure */ - pdu_rx->len = offsetof(struct pdu_data_llctrl, length_rsp) + - sizeof(struct pdu_data_llctrl_length_rsp); - pdu_rx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_LENGTH_RSP; - - lr = (void *)&pdu_rx->llctrl.length_req; - lr->max_rx_octets = sys_cpu_to_le16(conn->lll.max_rx_octets); - lr->max_tx_octets = sys_cpu_to_le16(conn->lll.max_tx_octets); -#if !defined(CONFIG_BT_CTLR_PHY) - lr->max_rx_time = - sys_cpu_to_le16(PDU_DC_MAX_US(conn->lll.max_rx_octets, PHY_1M)); - lr->max_tx_time = - sys_cpu_to_le16(PDU_DC_MAX_US(conn->lll.max_tx_octets, PHY_1M)); -#else /* CONFIG_BT_CTLR_PHY */ - lr->max_rx_time = sys_cpu_to_le16(conn->lll.max_rx_time); - lr->max_tx_time = sys_cpu_to_le16(conn->lll.max_tx_time); -#endif /* CONFIG_BT_CTLR_PHY */ - - return 0; -} -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - -#if defined(CONFIG_BT_CTLR_PHY) -static inline int reject_ind_phy_upd_recv(struct ll_conn *conn, - struct node_rx_pdu *rx, - struct pdu_data *pdu_rx) -{ - struct pdu_data_llctrl_reject_ext_ind *rej_ext_ind; - struct node_rx_pu *p; - - /* Same Procedure or Different Procedure Collision */ - - /* If not same procedure, stop procedure timeout, else - * continue timer until phy upd ind is received. - */ - rej_ext_ind = (void *)&pdu_rx->llctrl.reject_ext_ind; - if (rej_ext_ind->error_code != BT_HCI_ERR_LL_PROC_COLLISION) { - /* Procedure complete */ - conn->llcp_phy.ack = conn->llcp_phy.req; - - /* Reset packet timing restrictions */ - conn->lll.phy_tx_time = conn->lll.phy_tx; - conn->llcp_phy.pause_tx = 0U; - - /* Stop procedure timeout */ - conn->procedure_expire = 0U; - } - - /* skip event generation if not cmd initiated */ - if (!conn->llcp_phy.cmd) { - return -EINVAL; - } - - /* generate phy update complete event with error code */ - rx->hdr.type = NODE_RX_TYPE_PHY_UPDATE; - - p = (void *)pdu_rx; - p->status = rej_ext_ind->error_code; - p->tx = conn->lll.phy_tx; - p->rx = conn->lll.phy_rx; - - return 0; -} -#endif /* CONFIG_BT_CTLR_PHY */ - -#if defined(CONFIG_BT_CTLR_LE_ENC) -static inline int reject_ind_enc_recv(struct ll_conn *conn) -{ - /* resume data packet rx and tx */ - conn->llcp_enc.pause_rx = 0U; - conn->llcp_enc.pause_tx = 0U; - - /* Procedure complete */ - conn->llcp_ack = conn->llcp_req; - conn->procedure_expire = 0U; - - return 0; -} - -static inline int reject_ext_ind_enc_recv(struct ll_conn *conn, - struct pdu_data *pdu_rx) -{ - struct pdu_data_llctrl_reject_ext_ind *rej_ext_ind; - - reject_ind_enc_recv(conn); - - /* enqueue as if it were a reject ind */ - rej_ext_ind = (void *)&pdu_rx->llctrl.reject_ext_ind; - pdu_rx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_REJECT_IND; - pdu_rx->llctrl.reject_ind.error_code = rej_ext_ind->error_code; - - return 0; -} -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -static inline void reject_ind_recv(struct ll_conn *conn, struct node_rx_pdu *rx, - struct pdu_data *pdu_rx) -{ - int err = -EINVAL; - - - if (0) { - -#if defined(CONFIG_BT_CTLR_LE_ENC) - } else if ((conn->llcp_ack != conn->llcp_req) && - (conn->llcp_type == LLCP_ENCRYPTION)) { - err = reject_ind_enc_recv(conn); -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -#if defined(CONFIG_BT_CTLR_PHY) - } else if (conn->llcp_phy.ack != conn->llcp_phy.req) { - struct pdu_data_llctrl_reject_ext_ind *rej_ext_ind; - struct pdu_data_llctrl_reject_ind *rej_ind; - - rej_ext_ind = (void *)&pdu_rx->llctrl.reject_ext_ind; - rej_ind = (void *)&pdu_rx->llctrl.reject_ind; - /* NOTE: Do not modify reject_opcode field which overlap with - * error_code field in reject ind PDU structure. Only copy - * error_code from reject ind to reject ext ind PDU - * structure. - */ - rej_ext_ind->error_code = rej_ind->error_code; - err = reject_ind_phy_upd_recv(conn, rx, pdu_rx); -#endif /* CONFIG_BT_CTLR_PHY */ - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - } else if (conn->llcp_conn_param.ack != conn->llcp_conn_param.req) { - struct pdu_data_llctrl_reject_ext_ind *rej_ext_ind; - struct pdu_data_llctrl_reject_ind *rej_ind; - - rej_ext_ind = (void *)&pdu_rx->llctrl.reject_ext_ind; - rej_ind = (void *)&pdu_rx->llctrl.reject_ind; - /* NOTE: Do not modify reject_opcode field which overlap with - * error_code field in reject ind PDU structure. Only copy - * error_code from reject ind to reject ext ind PDU - * structure. - */ - rej_ext_ind->error_code = rej_ind->error_code; - err = reject_ind_conn_upd_recv(conn, rx, pdu_rx); -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - } else if (conn->llcp_length.ack != conn->llcp_length.req) { - err = reject_ind_dle_recv(conn, pdu_rx); -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - } - - if (err) { - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - } -} - -static inline void reject_ext_ind_recv(struct ll_conn *conn, - struct node_rx_pdu *rx, - struct pdu_data *pdu_rx) -{ - struct pdu_data_llctrl_reject_ext_ind *rej_ext_ind; - int err = -EINVAL; - - rej_ext_ind = (void *)&pdu_rx->llctrl.reject_ext_ind; - - switch (rej_ext_ind->reject_opcode) { -#if defined(CONFIG_BT_CTLR_LE_ENC) - case PDU_DATA_LLCTRL_TYPE_ENC_REQ: - if ((conn->llcp_ack != conn->llcp_req) && - (conn->llcp_type == LLCP_ENCRYPTION)) { - err = reject_ext_ind_enc_recv(conn, pdu_rx); - } - break; -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -#if defined(CONFIG_BT_CTLR_PHY) - case PDU_DATA_LLCTRL_TYPE_PHY_REQ: - if (conn->llcp_phy.ack != conn->llcp_phy.req) { - err = reject_ind_phy_upd_recv(conn, rx, pdu_rx); - } - break; -#endif /* CONFIG_BT_CTLR_PHY */ - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - case PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ: - if (conn->llcp_conn_param.ack != conn->llcp_conn_param.req) { - err = reject_ind_conn_upd_recv(conn, rx, pdu_rx); - } - break; -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - case PDU_DATA_LLCTRL_TYPE_LENGTH_REQ: - if (conn->llcp_length.ack != conn->llcp_length.req) { - err = reject_ind_dle_recv(conn, pdu_rx); - } - break; -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - default: - /* Ignore */ - break; - } - - if (err) { - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - } -} - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) -#if !defined(CONFIG_BT_CTLR_PHY) -static void length_resp_send(struct ll_conn *conn, struct node_tx *tx, - uint16_t eff_rx_octets, uint16_t eff_tx_octets) -#else /* CONFIG_BT_CTLR_PHY */ -static void length_resp_send(struct ll_conn *conn, struct node_tx *tx, - uint16_t eff_rx_octets, uint16_t eff_rx_time, - uint16_t eff_tx_octets, uint16_t eff_tx_time) -#endif /* CONFIG_BT_CTLR_PHY */ -{ - struct pdu_data *pdu_tx; - - pdu_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_tx); - - pdu_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_tx->len = offsetof(struct pdu_data_llctrl, length_rsp) + - sizeof(struct pdu_data_llctrl_length_rsp); - pdu_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_LENGTH_RSP; - pdu_tx->llctrl.length_rsp.max_rx_octets = - sys_cpu_to_le16(eff_rx_octets); - pdu_tx->llctrl.length_rsp.max_tx_octets = - sys_cpu_to_le16(eff_tx_octets); - -#if !defined(CONFIG_BT_CTLR_PHY) - pdu_tx->llctrl.length_rsp.max_rx_time = - sys_cpu_to_le16(PDU_DC_MAX_US(eff_rx_octets, PHY_1M)); - pdu_tx->llctrl.length_rsp.max_tx_time = - sys_cpu_to_le16(PDU_DC_MAX_US(eff_tx_octets, PHY_1M)); -#else /* CONFIG_BT_CTLR_PHY */ - pdu_tx->llctrl.length_rsp.max_rx_time = sys_cpu_to_le16(eff_rx_time); - pdu_tx->llctrl.length_rsp.max_tx_time = sys_cpu_to_le16(eff_tx_time); -#endif /* CONFIG_BT_CTLR_PHY */ - - ctrl_tx_sec_enqueue(conn, tx); -} - -static inline int length_req_rsp_recv(struct ll_conn *conn, memq_link_t *link, - struct node_rx_pdu **rx, - struct pdu_data *pdu_rx) -{ - struct node_tx *tx = NULL; - uint16_t eff_rx_octets; - uint16_t eff_tx_octets; -#if defined(CONFIG_BT_CTLR_PHY) - uint16_t eff_rx_time; - uint16_t eff_tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - - /* Check for free ctrl tx PDU */ - if (pdu_rx->llctrl.opcode == PDU_DATA_LLCTRL_TYPE_LENGTH_REQ) { - int err; - - /* Check transaction violation and get free ctrl tx PDU */ - tx = ctrl_tx_rsp_mem_acquire(conn, *rx, &err); - if (!tx) { - return err; - } - } - - eff_rx_octets = conn->lll.max_rx_octets; - eff_tx_octets = conn->lll.max_tx_octets; - -#if defined(CONFIG_BT_CTLR_PHY) - eff_rx_time = conn->lll.max_rx_time; - eff_tx_time = conn->lll.max_tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - - if (/* Local idle, and Peer request then complete the Peer procedure - * with response. - */ - ((conn->llcp_length.req == conn->llcp_length.ack) && tx) || - /* or Local has active... */ - ((conn->llcp_length.req != conn->llcp_length.ack) && - /* with Local requested and Peer request then complete the - * Peer procedure with response. - */ - ((((conn->llcp_length.state == LLCP_LENGTH_STATE_REQ) || - (conn->llcp_length.state == LLCP_LENGTH_STATE_REQ_ACK_WAIT)) && - tx) || - /* with Local waiting for response, and Peer response then - * complete the Local procedure or Peer request then complete the - * Peer procedure with response. - */ - (conn->llcp_length.state == LLCP_LENGTH_STATE_RSP_WAIT)))) { - struct pdu_data_llctrl_length_req *lr; - uint16_t max_rx_octets; - uint16_t max_tx_octets; - - lr = &pdu_rx->llctrl.length_req; - - /* use the minimal of our default_tx_octets and - * peer max_rx_octets - */ - max_rx_octets = sys_le16_to_cpu(lr->max_rx_octets); - if (max_rx_octets >= PDU_DC_PAYLOAD_SIZE_MIN) { - eff_tx_octets = MIN(max_rx_octets, - conn->default_tx_octets); - } - - /* use the minimal of our max supported and - * peer max_tx_octets - */ - max_tx_octets = sys_le16_to_cpu(lr->max_tx_octets); - if (max_tx_octets >= PDU_DC_PAYLOAD_SIZE_MIN) { - eff_rx_octets = MIN(max_tx_octets, - LL_LENGTH_OCTETS_RX_MAX); - } - -#if defined(CONFIG_BT_CTLR_PHY) - uint16_t max_rx_time; - uint16_t max_tx_time; - uint16_t lr_rx_time, lr_tx_time; - - dle_max_time_get(conn, &max_rx_time, &max_tx_time); - - /* use the minimal of our default_tx_time and - * peer max_rx_time - */ - - lr_rx_time = sys_le16_to_cpu(lr->max_rx_time); - lr_tx_time = sys_le16_to_cpu(lr->max_tx_time); - - if (lr_rx_time >= PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - PHY_1M)) { - eff_tx_time = MIN(lr_rx_time, max_tx_time); -#if defined(CONFIG_BT_CTLR_PHY_CODED) - eff_tx_time = MAX(eff_tx_time, - PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - conn->lll.phy_tx)); -#endif /* CONFIG_BT_CTLR_PHY_CODED */ - } - - /* use the minimal of our max supported and - * peer max_tx_time - */ - if (lr_tx_time >= PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - PHY_1M)) { - eff_rx_time = MIN(lr_tx_time, max_rx_time); -#if defined(CONFIG_BT_CTLR_PHY_CODED) - eff_rx_time = MAX(eff_rx_time, - PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, - conn->lll.phy_rx)); -#endif /* !CONFIG_BT_CTLR_PHY_CODED */ - } -#endif /* CONFIG_BT_CTLR_PHY */ - - /* check if change in rx octets */ - if (eff_rx_octets != conn->lll.max_rx_octets) { - /* FIXME: If we want to resize Rx Pool, decide to - * nack as required when implementing. Also, - * closing the current event may be needed. - */ - - /* trigger or retain the ctrl procedure so as - * to resize the rx buffers. - */ - conn->llcp_length.rx_octets = eff_rx_octets; - conn->llcp_length.tx_octets = eff_tx_octets; - -#if defined(CONFIG_BT_CTLR_PHY) - conn->llcp_length.rx_time = eff_rx_time; - conn->llcp_length.tx_time = eff_tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - - conn->llcp_length.ack = conn->llcp_length.req - 1; - - if (tx) { - conn->llcp_length.state = - LLCP_LENGTH_STATE_RESIZE_RSP; - } else { - /* accept the effective tx */ - conn->lll.max_tx_octets = eff_tx_octets; -#if defined(CONFIG_BT_CTLR_PHY) - /* accept the effective tx time */ - conn->lll.max_tx_time = eff_tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - conn->llcp_length.state = - LLCP_LENGTH_STATE_RESIZE; - } - - link->mem = conn->llcp_rx; - (*rx)->hdr.link = link; - conn->llcp_rx = *rx; - *rx = NULL; - } else { - /* Procedure complete */ - conn->llcp_length.ack = conn->llcp_length.req; - conn->procedure_expire = 0U; - - /* No change in effective octets or time */ - if (eff_tx_octets == conn->lll.max_tx_octets && -#if defined(CONFIG_BT_CTLR_PHY) - eff_tx_time == conn->lll.max_tx_time && - eff_rx_time == conn->lll.max_rx_time && -#endif /* CONFIG_BT_CTLR_PHY */ - (1)) { - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - goto send_length_resp; - } - -#if defined(CONFIG_BT_CTLR_PHY) - /* accept the effective rx time */ - conn->lll.max_rx_time = eff_rx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - - if (tx) { - /* trigger or retain the ctrl procedure so as - * to resize the rx buffers. - */ - conn->llcp_length.rx_octets = eff_rx_octets; - conn->llcp_length.tx_octets = eff_tx_octets; - -#if defined(CONFIG_BT_CTLR_PHY) - conn->llcp_length.rx_time = eff_rx_time; - conn->llcp_length.tx_time = eff_tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - - /* Wait for rsp ack before tx change */ - conn->llcp_length.ack = - (conn->llcp_length.req - 1); - conn->llcp_length.state = - LLCP_LENGTH_STATE_RSP_ACK_WAIT; - } else { - /* accept the effective tx */ - conn->lll.max_tx_octets = eff_tx_octets; - -#if defined(CONFIG_BT_CTLR_PHY) - /* accept the effective tx time */ - conn->lll.max_tx_time = eff_tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - } - - /* prepare event parameters */ - lr->max_rx_octets = sys_cpu_to_le16(eff_rx_octets); - lr->max_tx_octets = sys_cpu_to_le16(eff_tx_octets); - -#if !defined(CONFIG_BT_CTLR_PHY) - lr->max_rx_time = - sys_cpu_to_le16(PDU_DC_MAX_US(eff_rx_octets, - PHY_1M)); - lr->max_tx_time = - sys_cpu_to_le16(PDU_DC_MAX_US(eff_tx_octets, - PHY_1M)); -#else /* CONFIG_BT_CTLR_PHY */ - lr->max_rx_time = sys_cpu_to_le16(eff_rx_time); - lr->max_tx_time = sys_cpu_to_le16(eff_tx_time); -#endif /* CONFIG_BT_CTLR_PHY */ - } - } else { - /* Drop response with no Local initiated request and duplicate - * requests. - */ - if (pdu_rx->llctrl.opcode != PDU_DATA_LLCTRL_TYPE_LENGTH_RSP) { - mem_release(tx, &mem_conn_tx_ctrl.free); - - /* Release the transacation lock, as ctrl tx PDU is not - * being enqueued. - */ - conn->common.txn_lock = 0U; - - /* Defer new request if previous in resize state */ - if (conn->llcp_length.state == - LLCP_LENGTH_STATE_RESIZE) { - return -EBUSY; - } - } - - return 0; - } - -send_length_resp: - if (tx) { - /* FIXME: if nack-ing is implemented then release tx instead - * of sending resp. - */ -#if !defined(CONFIG_BT_CTLR_PHY) - length_resp_send(conn, tx, eff_rx_octets, - eff_tx_octets); -#else /* CONFIG_BT_CTLR_PHY */ - length_resp_send(conn, tx, eff_rx_octets, - eff_rx_time, eff_tx_octets, - eff_tx_time); -#endif /* CONFIG_BT_CTLR_PHY */ - } - - return 0; -} -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - -#if defined(CONFIG_BT_CTLR_LE_PING) -static int ping_resp_send(struct ll_conn *conn, struct node_rx_pdu *rx) -{ - struct pdu_data *pdu_tx; - struct node_tx *tx; - int err; - - /* Check transaction violation and get free ctrl tx PDU */ - tx = ctrl_tx_rsp_mem_acquire(conn, rx, &err); - if (!tx) { - return err; - } - - pdu_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_tx); - - pdu_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_tx->len = offsetof(struct pdu_data_llctrl, ping_rsp) + - sizeof(struct pdu_data_llctrl_ping_rsp); - pdu_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_PING_RSP; - - ctrl_tx_sec_enqueue(conn, tx); - - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - return 0; -} -#endif /* CONFIG_BT_CTLR_LE_PING */ - -#if defined(CONFIG_BT_CTLR_PHY) -static int phy_rsp_send(struct ll_conn *conn, struct node_rx_pdu *rx, - struct pdu_data *pdu_rx) -{ - struct pdu_data_llctrl_phy_req *p; - struct pdu_data *pdu_ctrl_tx; - struct node_tx *tx; - int err; - - /* Check transaction violation and get free ctrl tx PDU */ - tx = ctrl_tx_rsp_mem_acquire(conn, rx, &err); - if (!tx) { - return err; - } - - /* Wait for peer central to complete the procedure */ - conn->llcp_phy.state = LLCP_PHY_STATE_RSP_WAIT; - if (conn->llcp_phy.ack == - conn->llcp_phy.req) { - conn->llcp_phy.ack--; - - conn->llcp_phy.cmd = 0U; - - conn->llcp_phy.tx = - conn->phy_pref_tx; - conn->llcp_phy.rx = - conn->phy_pref_rx; - - /* Start Procedure Timeout (TODO: this shall not - * replace terminate procedure). - */ - conn->procedure_expire = - conn->procedure_reload; - } - - p = &pdu_rx->llctrl.phy_req; - - conn->llcp_phy.tx &= p->rx_phys; - conn->llcp_phy.rx &= p->tx_phys; - - pdu_ctrl_tx = (void *)tx->pdu; - - ull_pdu_data_init(pdu_ctrl_tx); - - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = offsetof(struct pdu_data_llctrl, phy_rsp) + - sizeof(struct pdu_data_llctrl_phy_rsp); - pdu_ctrl_tx->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_PHY_RSP; - pdu_ctrl_tx->llctrl.phy_rsp.tx_phys = conn->phy_pref_tx; - pdu_ctrl_tx->llctrl.phy_rsp.rx_phys = conn->phy_pref_rx; - - ctrl_tx_enqueue(conn, tx); - - /* Mark for buffer for release */ - rx->hdr.type = NODE_RX_TYPE_RELEASE; - - return 0; -} - -static inline uint8_t phy_upd_ind_recv(struct ll_conn *conn, memq_link_t *link, - struct node_rx_pdu **rx, - struct pdu_data *pdu_rx) -{ - struct pdu_data_llctrl_phy_upd_ind *ind = &pdu_rx->llctrl.phy_upd_ind; - uint16_t instant; - uint8_t phy; - - /* Both tx and rx PHY unchanged */ - if (!((ind->c_to_p_phy | ind->p_to_c_phy) & 0x07)) { - struct node_rx_pu *p; - - /* Not in PHY Update Procedure or PDU in wrong state */ - if ((conn->llcp_phy.ack == conn->llcp_phy.req) || - (conn->llcp_phy.state != LLCP_PHY_STATE_RSP_WAIT)) { - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - return 0; - } - - /* Procedure complete */ - conn->llcp_phy.ack = conn->llcp_phy.req; - conn->llcp_phy.pause_tx = 0U; - conn->procedure_expire = 0U; - - /* Reset packet timing restrictions */ - conn->lll.phy_tx_time = conn->lll.phy_tx; - - /* Ignore event generation if not local cmd initiated */ - if (!conn->llcp_phy.cmd) { - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - return 0; - } - - /* generate phy update complete event */ - (*rx)->hdr.type = NODE_RX_TYPE_PHY_UPDATE; - - p = (void *)pdu_rx; - p->status = 0U; - p->tx = conn->lll.phy_tx; - p->rx = conn->lll.phy_rx; - - return 0; - } - - /* Fail on multiple PHY specified */ - phy = ind->c_to_p_phy; - if (util_ones_count_get(&phy, sizeof(phy)) > 1U) { - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - return BT_HCI_ERR_INVALID_LL_PARAM; - } - phy = ind->p_to_c_phy; - if (util_ones_count_get(&phy, sizeof(phy)) > 1U) { - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - return BT_HCI_ERR_INVALID_LL_PARAM; - } - - /* instant passed */ - instant = sys_le16_to_cpu(ind->instant); - if (((instant - conn->lll.event_counter) & 0xffff) > 0x7fff) { - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - return BT_HCI_ERR_INSTANT_PASSED; - } - - /* different transaction collision */ - if (((conn->llcp_req - conn->llcp_ack) & 0x03) == 0x02) { - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - return BT_HCI_ERR_DIFF_TRANS_COLLISION; - } - - if ((conn->llcp_phy.ack != conn->llcp_phy.req) && - (conn->llcp_phy.state == LLCP_PHY_STATE_RSP_WAIT)) { - /* Procedure complete, just wait for instant */ - conn->llcp_phy.ack = conn->llcp_phy.req; - conn->llcp_phy.pause_tx = 0U; - conn->procedure_expire = 0U; - - conn->llcp.phy_upd_ind.cmd = conn->llcp_phy.cmd; - } - - conn->llcp.phy_upd_ind.tx = ind->p_to_c_phy; - conn->llcp.phy_upd_ind.rx = ind->c_to_p_phy; - conn->llcp.phy_upd_ind.instant = instant; - conn->llcp.phy_upd_ind.initiate = 0U; - - /* Reserve the Rx-ed PHY Update Indication PDU in the connection - * context, by appending to the LLCP node rx list. We do not mark it - * for release in ULL, i.e., by returning *rx as NULL. - * PHY Update notification to HCI layer will use node rx from this - * list when at the instant. - * If data length update is supported in the Controller, then, at the - * instant we attempt to acquire an additional free node rx for Data - * Length Update notification. - */ - link->mem = conn->llcp_rx; - (*rx)->hdr.link = link; - conn->llcp_rx = *rx; - *rx = NULL; - - /* Transition to PHY Update Ind received state and wait for the - * instant. - */ - conn->llcp_type = LLCP_PHY_UPD; - conn->llcp_ack -= 2U; - - /* Enforce packet timing restrictions until the instant */ - if (conn->llcp.phy_upd_ind.tx) { - conn->lll.phy_tx_time = conn->llcp.phy_upd_ind.tx; - } - - return 0; -} -#endif /* CONFIG_BT_CTLR_PHY */ - -#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) -void event_send_cis_rsp(struct ll_conn *conn, uint16_t event_counter) -{ - struct node_tx *tx; - - /* If waiting for accept/reject from host, do nothing */ - if (((conn->llcp_cis.req - conn->llcp_cis.ack) & 0xFF) == - CIS_REQUEST_AWAIT_HOST) { - return; - } - - tx = mem_acquire(&mem_conn_tx_ctrl.free); - if (tx) { - struct pdu_data *pdu = (void *)tx->pdu; - uint16_t conn_event_count; - - ull_pdu_data_init(pdu); - - pdu->ll_id = PDU_DATA_LLID_CTRL; - pdu->llctrl.opcode = PDU_DATA_LLCTRL_TYPE_CIS_RSP; - - /* Try to request extra time to setup the CIS. If central's - * CIS_IND is delayed, or it decides to do differently, this - * still might not be possible. Only applies if instance is - * less than two events in the future. - * - * In the example below it is shown how the CIS_IND is adjusted - * by peripheral increasing the event_counter in the CIS_RSP. - * This improves the peripheral's chances of setting up the CIS - * in due time. Current event counter is left most column. - * - * Without correction (LATE) With correction (OK) - * -------------------------------------------------------- - * 10 ==> CIS_REQ E=15 10 ==> CIS_REQ E=15 - * 14 <== CIS_RSP E=15 14 <== CIS_RSP E=16 (14+2) - * 15 ==> CIS_IND E=16 15 ==> CIS_IND E=17 - * 16 ==> (+ offset) First PDU 16 Peripheral setup - * 16 Peripheral setup 17 ==> (+ offset) First PDU - * 17 Peripheral ready - * - * TODO: Port to new LLCP procedures - */ - conn_event_count = MAX(conn->llcp_cis.conn_event_count, - event_counter + 2); - - sys_put_le24(conn->llcp_cis.cis_offset_min, - pdu->llctrl.cis_rsp.cis_offset_min); - sys_put_le24(conn->llcp_cis.cis_offset_max, - pdu->llctrl.cis_rsp.cis_offset_max); - pdu->llctrl.cis_rsp.conn_event_count = - sys_cpu_to_le16(conn_event_count); - - pdu->len = offsetof(struct pdu_data_llctrl, cis_rsp) + - sizeof(struct pdu_data_llctrl_cis_rsp); - - conn->llcp_cis.state = LLCP_CIS_STATE_IND_WAIT; - - ctrl_tx_enqueue(conn, tx); - } -} - -void event_peripheral_iso_prep(struct ll_conn *conn, uint16_t event_counter, - uint32_t ticks_at_expire) -{ - struct ll_conn_iso_group *cig; - uint16_t start_event_count; - uint16_t instant_latency; - - start_event_count = conn->llcp_cis.conn_event_count; - - cig = ll_conn_iso_group_get_by_id(conn->llcp_cis.cig_id); - LL_ASSERT(cig); - -#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO_EARLY_CIG_START) - if (!cig->started) { - /* Start ISO peripheral one event before the requested instant - * for first CIS. This is done to be able to accept small CIS - * offsets. - */ - start_event_count--; - } -#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO_EARLY_CIG_START */ - - /* Start ISO peripheral one event before the requested instant */ - instant_latency = (event_counter - start_event_count) & 0xffff; - if (instant_latency <= 0x7fff) { - /* Start CIS peripheral */ - ull_conn_iso_start(conn, ticks_at_expire, - conn->llcp_cis.cis_handle, - instant_latency); - - conn->llcp_cis.state = LLCP_CIS_STATE_REQ; - conn->llcp_cis.ack = conn->llcp_cis.req; - } -} - -static uint8_t cis_req_recv(struct ll_conn *conn, memq_link_t *link, - struct node_rx_pdu **rx, struct pdu_data *pdu) -{ - struct pdu_data_llctrl_cis_req *req = &pdu->llctrl.cis_req; - struct node_rx_conn_iso_req *conn_iso_req; - uint16_t cis_handle; - uint8_t err; - uint8_t phy; - void *node; - - phy = req->c_phy; - - /* Check reqested PHYs. Returning BT_HCI_ERR_INVALID_LL_PARAM shall invoke - * sending of LL_REJECT_EXT_IND. - */ - for (uint8_t i = 0; i < 2; i++) { - /* Fail on multiple PHY specified */ - if (util_ones_count_get(&phy, sizeof(phy)) > 1U) { - return BT_HCI_ERR_INVALID_LL_PARAM; - } - - /* Fail on no PHY specified */ - if (util_ones_count_get(&phy, sizeof(phy)) == 0U) { - return BT_HCI_ERR_INVALID_LL_PARAM; - } - - /* Fail on unsupported PHY specified */ - if (((phy & PHY_2M) && - !(conn->llcp_feature.features_conn & BIT64(BT_LE_FEAT_BIT_PHY_2M))) || - ((phy & PHY_CODED) && - !(conn->llcp_feature.features_conn & BIT64(BT_LE_FEAT_BIT_PHY_CODED)))) { - return BT_HCI_ERR_INVALID_LL_PARAM; - } - - phy &= ~(PHY_1M|PHY_2M|PHY_CODED); - - /* Fail on RFU bits specified */ - if (util_ones_count_get(&phy, sizeof(phy))) { - return BT_HCI_ERR_INVALID_LL_PARAM; - } - - phy = req->p_phy; - } - - conn->llcp_cis.cig_id = req->cig_id; - conn->llcp_cis.cis_offset_min = sys_get_le24(req->cis_offset_min); - conn->llcp_cis.cis_offset_max = sys_get_le24(req->cis_offset_max); - conn->llcp_cis.conn_event_count = sys_le16_to_cpu(req->conn_event_count); - - /* Acquire resources for new CIS */ - err = ull_peripheral_iso_acquire(conn, &pdu->llctrl.cis_req, &cis_handle); - if (err) { - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - return err; - } - - conn->llcp_cis.cis_handle = cis_handle; - conn->llcp_cis.state = LLCP_CIS_STATE_RSP_WAIT; - conn->llcp_cis.ack -= 2U; - - (*rx)->hdr.type = NODE_RX_TYPE_CIS_REQUEST; - - /* check for pdu field being aligned before populating ISO - * connection request event. - */ - node = pdu; - LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_conn_iso_req)); - - conn_iso_req = node; - conn_iso_req->cig_id = req->cig_id; - conn_iso_req->cis_id = req->cis_id; - conn_iso_req->cis_handle = cis_handle; - - return 0; -} - -static uint8_t cis_ind_recv(struct ll_conn *conn, memq_link_t *link, - struct node_rx_pdu **rx, struct pdu_data *pdu) -{ - struct pdu_data_llctrl_cis_ind *ind = &pdu->llctrl.cis_ind; - uint8_t err; - - conn->llcp_cis.conn_event_count = - sys_le16_to_cpu(ind->conn_event_count); - - /* Setup CIS connection */ - err = ull_peripheral_iso_setup(&pdu->llctrl.cis_ind, - conn->llcp_cis.cig_id, - conn->llcp_cis.cis_handle); - - conn->llcp_cis.state = LLCP_CIS_STATE_INST_WAIT; - - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - return err; -} -#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO */ - -static inline void ctrl_tx_pre_ack(struct ll_conn *conn, - struct pdu_data *pdu_tx) -{ - switch (pdu_tx->llctrl.opcode) { -#if defined(CONFIG_BT_CTLR_LE_ENC) - case PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_RSP: - if (!conn->lll.role) { - break; - } - __fallthrough; -#if defined(CONFIG_BT_CENTRAL) - case PDU_DATA_LLCTRL_TYPE_ENC_REQ: - case PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_REQ: -#endif /* CONFIG_BT_CENTRAL */ -#if defined(CONFIG_BT_PERIPHERAL) - case PDU_DATA_LLCTRL_TYPE_ENC_RSP: -#endif /* CONFIG_BT_PERIPHERAL */ - /* pause data packet tx */ - conn->llcp_enc.pause_tx = 1U; - break; -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -#if defined(CONFIG_BT_CTLR_PHY) - case PDU_DATA_LLCTRL_TYPE_PHY_REQ: -#if defined(CONFIG_BT_PERIPHERAL) - case PDU_DATA_LLCTRL_TYPE_PHY_RSP: -#endif /* CONFIG_BT_PERIPHERAL */ - /* pause data packet tx */ - conn->llcp_phy.pause_tx = 1U; - break; -#endif /* CONFIG_BT_CTLR_PHY */ - - default: - /* Do nothing for other ctrl packet ack */ - break; - } -} - -static inline void ctrl_tx_ack(struct ll_conn *conn, struct node_tx **tx, - struct pdu_data *pdu_tx) -{ - switch (pdu_tx->llctrl.opcode) { - case PDU_DATA_LLCTRL_TYPE_TERMINATE_IND: - { - if (pdu_tx->llctrl.terminate_ind.error_code == - BT_HCI_ERR_REMOTE_USER_TERM_CONN) { - conn->llcp_terminate.reason_final = - BT_HCI_ERR_LOCALHOST_TERM_CONN; - } else { - conn->llcp_terminate.reason_final = - pdu_tx->llctrl.terminate_ind.error_code; - } - - /* Make (req - ack) == 3, a state indicating terminate_ind has - * been ack-ed. - */ - conn->llcp_terminate.ack--; - } - break; - - case PDU_DATA_LLCTRL_TYPE_FEATURE_RSP: - case PDU_DATA_LLCTRL_TYPE_PING_RSP: - case PDU_DATA_LLCTRL_TYPE_UNKNOWN_RSP: - /* Reset the transaction lock */ - conn->common.txn_lock = 0U; - break; - -#if defined(CONFIG_BT_CENTRAL) - case PDU_DATA_LLCTRL_TYPE_CONN_UPDATE_IND: - conn->llcp_cu.pause_tx = 0U; - break; -#endif /* CONFIG_BT_CENTRAL */ - -#if defined(CONFIG_BT_CTLR_LE_ENC) -#if defined(CONFIG_BT_CENTRAL) - case PDU_DATA_LLCTRL_TYPE_ENC_REQ: - /* things from central stored for session key calculation */ - memcpy(&conn->llcp.encryption.skd[0], - &pdu_tx->llctrl.enc_req.skdm[0], 8); - memcpy(&conn->lll.ccm_rx.iv[0], - &pdu_tx->llctrl.enc_req.ivm[0], 4); - - /* pause data packet tx */ - conn->llcp_enc.pause_tx = 1U; - - /* Start Procedure Timeout (this will not replace terminate - * procedure which always gets place before any packets - * going out, hence safe by design). - */ - conn->procedure_expire = conn->procedure_reload; - - /* Reset enc req queued state */ - conn->llcp_enc.ack = conn->llcp_enc.req; - break; -#endif /* CONFIG_BT_CENTRAL */ - -#if defined(CONFIG_BT_PERIPHERAL) - case PDU_DATA_LLCTRL_TYPE_ENC_RSP: - /* pause data packet tx */ - conn->llcp_enc.pause_tx = 1U; - break; - - case PDU_DATA_LLCTRL_TYPE_START_ENC_REQ: - /* Remember that we may have received encrypted START_ENC_RSP - * alongwith this tx ack at this point in time. - */ - conn->llcp.encryption.state = LLCP_ENC_STATE_ENC_WAIT; - break; -#endif /* CONFIG_BT_PERIPHERAL */ - - case PDU_DATA_LLCTRL_TYPE_START_ENC_RSP: - if (conn->lll.role) { - /* resume data packet rx and tx */ - conn->llcp_enc.pause_rx = 0U; - conn->llcp_enc.pause_tx = 0U; - - /* Procedure complete */ - conn->procedure_expire = 0U; - - /* procedure request acked */ - conn->llcp_ack = conn->llcp_req; - } else { - conn->llcp.encryption.state = LLCP_ENC_STATE_ENC_WAIT; - } - break; - -#if defined(CONFIG_BT_CENTRAL) - case PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_REQ: - /* pause data packet tx */ - conn->llcp_enc.pause_tx = 1U; - - /* key refresh */ - conn->llcp_enc.refresh = 1U; - - /* Start Procedure Timeout (this will not replace terminate - * procedure which always gets place before any packets - * going out, hence safe by design). - */ - conn->procedure_expire = conn->procedure_reload; - - /* Reset enc req queued state */ - conn->llcp_enc.ack = conn->llcp_enc.req; - break; -#endif /* CONFIG_BT_CENTRAL */ - - case PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_RSP: -#if defined(CONFIG_BT_CENTRAL) - if (!conn->lll.role) { - /* reused tx-ed PDU and send enc req */ - enc_req_reused_send(conn, tx); - } else -#endif /* CONFIG_BT_CENTRAL */ - { - /* pause data packet tx */ - conn->llcp_enc.pause_tx = 1U; - } - break; - - case PDU_DATA_LLCTRL_TYPE_REJECT_EXT_IND: - if (pdu_tx->llctrl.reject_ext_ind.reject_opcode != - PDU_DATA_LLCTRL_TYPE_ENC_REQ) { - /* Reset the transaction lock set by connection - * parameter request and PHY update procedure when - * sending the Reject Ext Ind PDU. - */ - conn->common.txn_lock = 0U; - - break; - } - __fallthrough; - - case PDU_DATA_LLCTRL_TYPE_REJECT_IND: - /* resume data packet rx and tx */ - conn->llcp_enc.pause_rx = 0U; - conn->llcp_enc.pause_tx = 0U; - - /* Procedure complete */ - conn->procedure_expire = 0U; - break; -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - case PDU_DATA_LLCTRL_TYPE_LENGTH_REQ: - /* wait for response */ - if (conn->llcp_length.state == LLCP_LENGTH_STATE_REQ_ACK_WAIT) { - conn->llcp_length.state = LLCP_LENGTH_STATE_RSP_WAIT; - } - break; - - case PDU_DATA_LLCTRL_TYPE_LENGTH_RSP: - /* Reset the transaction lock */ - conn->common.txn_lock = 0U; - - if (conn->llcp_length.req != conn->llcp_length.ack) { - switch (conn->llcp_length.state) { - case LLCP_LENGTH_STATE_RSP_ACK_WAIT: - case LLCP_LENGTH_STATE_RESIZE_RSP: - case LLCP_LENGTH_STATE_RESIZE_RSP_ACK_WAIT: - /* accept the effective tx */ - conn->lll.max_tx_octets = - conn->llcp_length.tx_octets; - -#if defined(CONFIG_BT_CTLR_PHY) - /* accept the effective tx time */ - conn->lll.max_tx_time = - conn->llcp_length.tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - - if (conn->llcp_length.state == - LLCP_LENGTH_STATE_RESIZE_RSP) { - conn->llcp_length.state = - LLCP_LENGTH_STATE_RESIZE; - - break; - } - - /* check cache */ - if (!conn->llcp_length.cache.tx_octets) { - /* Procedure complete */ - conn->llcp_length.ack = - conn->llcp_length.req; - conn->procedure_expire = 0U; - - break; - } - - /* Initiate cached procedure */ - conn->llcp_length.tx_octets = - conn->llcp_length.cache.tx_octets; - conn->llcp_length.cache.tx_octets = 0U; -#if defined(CONFIG_BT_CTLR_PHY) - conn->llcp_length.tx_time = - conn->llcp_length.cache.tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - conn->llcp_length.state = LLCP_LENGTH_STATE_REQ; - break; - - default: - break; - } - } - break; -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - -#if defined(CONFIG_BT_CTLR_PHY) - case PDU_DATA_LLCTRL_TYPE_PHY_REQ: - conn->llcp_phy.state = LLCP_PHY_STATE_RSP_WAIT; - __fallthrough; - -#if defined(CONFIG_BT_PERIPHERAL) - case PDU_DATA_LLCTRL_TYPE_PHY_RSP: - if (conn->lll.role) { - /* select the probable PHY with longest Tx time, which - * will be restricted to fit current - * connEffectiveMaxTxTime. - */ - uint8_t phy_tx_time[8] = {PHY_1M, PHY_1M, PHY_2M, - PHY_1M, PHY_CODED, PHY_CODED, - PHY_CODED, PHY_CODED}; - struct lll_conn *lll; - uint8_t phys; - - /* Reset the transaction lock when PHY update response - * sent by peripheral is acknowledged. - */ - if (pdu_tx->llctrl.opcode == - PDU_DATA_LLCTRL_TYPE_PHY_RSP) { - conn->common.txn_lock = 0U; - } - - lll = &conn->lll; - phys = conn->llcp_phy.tx | lll->phy_tx; - lll->phy_tx_time = phy_tx_time[phys]; - } - - /* resume data packet tx */ - conn->llcp_phy.pause_tx = 0U; - break; -#endif /* CONFIG_BT_PERIPHERAL */ - -#if defined(CONFIG_BT_CENTRAL) - case PDU_DATA_LLCTRL_TYPE_PHY_UPD_IND: - conn->lll.phy_tx_time = conn->llcp.phy_upd_ind.tx; - /* resume data packet tx */ - conn->llcp_phy.pause_tx = 0U; - break; -#endif /* CONFIG_BT_CENTRAL */ -#endif /* CONFIG_BT_CTLR_PHY */ - - default: - /* Do nothing for other ctrl packet ack */ - break; - } -} - -static inline int ctrl_rx(memq_link_t *link, struct node_rx_pdu **rx, - struct pdu_data *pdu_rx, struct ll_conn *conn) -{ - int nack = 0; - uint8_t opcode; - - opcode = pdu_rx->llctrl.opcode; - -#if defined(CONFIG_BT_CTLR_LE_ENC) - /* FIXME: do check in individual case to reduce CPU time */ - if (conn->llcp_enc.pause_rx && ctrl_is_unexpected(conn, opcode)) { - conn->llcp_terminate.reason_final = - BT_HCI_ERR_TERM_DUE_TO_MIC_FAIL; - - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - return 0; - } -#endif /* CONFIG_BT_CTLR_LE_ENC */ - - switch (opcode) { -#if defined(CONFIG_BT_PERIPHERAL) - case PDU_DATA_LLCTRL_TYPE_CONN_UPDATE_IND: - { - uint8_t err; - - if (!conn->lll.role || - PDU_DATA_LLCTRL_LEN(conn_update_ind) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - err = conn_upd_recv(conn, link, rx, pdu_rx); - if (err) { - conn->llcp_terminate.reason_final = err; -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - } else { - /* conn param req procedure, if any, is complete */ - conn->procedure_expire = 0U; -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - } - } - break; - - case PDU_DATA_LLCTRL_TYPE_CHAN_MAP_IND: - { - uint8_t err; - - if (!conn->lll.role || - PDU_DATA_LLCTRL_LEN(chan_map_ind) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - err = chan_map_upd_recv(conn, *rx, pdu_rx); - if (err) { - conn->llcp_terminate.reason_final = err; - } - } - break; -#endif /* CONFIG_BT_PERIPHERAL */ - - case PDU_DATA_LLCTRL_TYPE_TERMINATE_IND: - if (PDU_DATA_LLCTRL_LEN(terminate_ind) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - terminate_ind_recv(conn, *rx, pdu_rx); - break; - -#if defined(CONFIG_BT_CTLR_LE_ENC) -#if defined(CONFIG_BT_PERIPHERAL) - case PDU_DATA_LLCTRL_TYPE_ENC_REQ: - if (!conn->lll.role || - PDU_DATA_LLCTRL_LEN(enc_req) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - -#if defined(CONFIG_BT_CTLR_PHY) - /* LL_ENC_REQ was received while local peripheral initiated - * procedure is in progress. - */ - if (unlikely(((conn->llcp_req - conn->llcp_ack) & 0x03) == - 0x02)) { - /* Adjust ack due to decrement below, to prevent - * failures - */ - conn->llcp_ack += 2U; - - /* Store the local peripheral initiated procedure */ - LL_ASSERT(conn->periph.llcp_type == LLCP_NONE); - conn->periph.llcp_type = conn->llcp_type; - } -#endif /* CONFIG_BT_CTLR_PHY */ - -#if defined(CONFIG_BT_CTLR_FAST_ENC) - /* TODO: BT Spec. text: may finalize the sending of additional - * data channel PDUs queued in the controller. - */ - nack = enc_rsp_send(conn); - if (nack) { - break; - } - - /* Start Enc Req to be scheduled by LL api */ - conn->llcp.encryption.state = LLCP_ENC_STATE_LTK_WAIT; -#else /* CONFIG_BT_CTLR_FAST_ENC */ - /* back up rand and ediv for deferred generation of Enc Req */ - memcpy(&conn->llcp_enc.rand[0], - &pdu_rx->llctrl.enc_req.rand[0], - sizeof(conn->llcp_enc.rand)); - conn->llcp_enc.ediv[0] = pdu_rx->llctrl.enc_req.ediv[0]; - conn->llcp_enc.ediv[1] = pdu_rx->llctrl.enc_req.ediv[1]; - - /* Enc rsp to be scheduled in central prepare */ - conn->llcp.encryption.state = LLCP_ENC_STATE_INIT; - - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; -#endif /* CONFIG_BT_CTLR_FAST_ENC */ - - /* Enc Setup state machine active */ - conn->llcp_type = LLCP_ENCRYPTION; - conn->llcp_ack -= 2U; - - /* things from central stored for session key calculation */ - memcpy(&conn->llcp.encryption.skd[0], - &pdu_rx->llctrl.enc_req.skdm[0], 8); - memcpy(&conn->lll.ccm_rx.iv[0], - &pdu_rx->llctrl.enc_req.ivm[0], 4); - - /* pause rx data packets */ - conn->llcp_enc.pause_rx = 1U; - - /* Start Procedure Timeout (TODO: this shall not replace - * terminate procedure). - */ - conn->procedure_expire = conn->procedure_reload; - - break; -#endif /* CONFIG_BT_PERIPHERAL */ - -#if defined(CONFIG_BT_CENTRAL) - case PDU_DATA_LLCTRL_TYPE_ENC_RSP: - if (conn->lll.role || - PDU_DATA_LLCTRL_LEN(enc_rsp) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - /* things sent by peripheral stored for session key calculation */ - memcpy(&conn->llcp.encryption.skd[8], - &pdu_rx->llctrl.enc_rsp.skds[0], 8); - memcpy(&conn->lll.ccm_rx.iv[4], - &pdu_rx->llctrl.enc_rsp.ivs[0], 4); - - /* pause rx data packets */ - conn->llcp_enc.pause_rx = 1U; - - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - break; - - case PDU_DATA_LLCTRL_TYPE_START_ENC_REQ: - if (conn->lll.role || (conn->llcp_req == conn->llcp_ack) || - (conn->llcp_type != LLCP_ENCRYPTION) || - PDU_DATA_LLCTRL_LEN(start_enc_req) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - /* start enc rsp to be scheduled in central prepare */ - conn->llcp.encryption.state = LLCP_ENC_STATE_INPROG; - - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - break; -#endif /* CONFIG_BT_CENTRAL */ - - case PDU_DATA_LLCTRL_TYPE_START_ENC_RSP: - if ((conn->llcp_req == conn->llcp_ack) || - (conn->llcp_type != LLCP_ENCRYPTION) || - (PDU_DATA_LLCTRL_LEN(start_enc_rsp) != pdu_rx->len)) { - goto ull_conn_rx_unknown_rsp_send; - } - - if (conn->lll.role) { -#if !defined(CONFIG_BT_CTLR_FAST_ENC) - /* start enc rsp to be scheduled in peripheral prepare */ - conn->llcp.encryption.state = LLCP_ENC_STATE_INPROG; - -#else /* CONFIG_BT_CTLR_FAST_ENC */ - nack = start_enc_rsp_send(conn, NULL); - if (nack) { - break; - } -#endif /* CONFIG_BT_CTLR_FAST_ENC */ - - } else { - /* resume data packet rx and tx */ - conn->llcp_enc.pause_rx = 0U; - conn->llcp_enc.pause_tx = 0U; - - /* Procedure complete */ - conn->procedure_expire = 0U; - - /* procedure request acked */ - conn->llcp_ack = conn->llcp_req; - } - - /* enqueue the start enc resp (encryption change/refresh) */ - if (conn->llcp_enc.refresh) { - conn->llcp_enc.refresh = 0U; - - /* key refresh event */ - (*rx)->hdr.type = NODE_RX_TYPE_ENC_REFRESH; - } - break; -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -#if defined(CONFIG_BT_PERIPHERAL) - case PDU_DATA_LLCTRL_TYPE_FEATURE_REQ: - if (!conn->lll.role || - PDU_DATA_LLCTRL_LEN(feature_req) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - nack = feature_rsp_send(conn, *rx, pdu_rx); - break; -#endif /* CONFIG_BT_PERIPHERAL */ - -#if defined(CONFIG_BT_CENTRAL) && defined(CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG) - case PDU_DATA_LLCTRL_TYPE_PER_INIT_FEAT_XCHG: - if (conn->lll.role || - PDU_DATA_LLCTRL_LEN(per_init_feat_xchg) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - nack = feature_rsp_send(conn, *rx, pdu_rx); - break; -#endif /* CONFIG_BT_CENTRAL && CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG */ - -#if defined(CONFIG_BT_CENTRAL) || defined(CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG) - case PDU_DATA_LLCTRL_TYPE_FEATURE_RSP: - if ((!IS_ENABLED(CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG) && - conn->lll.role) || - PDU_DATA_LLCTRL_LEN(feature_rsp) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - feature_rsp_recv(conn, pdu_rx); - break; -#endif /* CONFIG_BT_CENTRAL || CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG */ - -#if defined(CONFIG_BT_CTLR_LE_ENC) -#if defined(CONFIG_BT_PERIPHERAL) - case PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_REQ: - if (!conn->lll.role || - PDU_DATA_LLCTRL_LEN(pause_enc_req) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - nack = pause_enc_rsp_send(conn, *rx, 1); - break; -#endif /* CONFIG_BT_PERIPHERAL */ - - case PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_RSP: - if (PDU_DATA_LLCTRL_LEN(pause_enc_rsp) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - nack = pause_enc_rsp_send(conn, *rx, 0); - break; -#endif /* CONFIG_BT_CTLR_LE_ENC */ - - case PDU_DATA_LLCTRL_TYPE_VERSION_IND: - if (PDU_DATA_LLCTRL_LEN(version_ind) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - nack = version_ind_send(conn, *rx, pdu_rx); - break; - -#if defined(CONFIG_BT_CTLR_LE_ENC) - case PDU_DATA_LLCTRL_TYPE_REJECT_IND: - if (PDU_DATA_LLCTRL_LEN(reject_ind) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - reject_ind_recv(conn, *rx, pdu_rx); - break; -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - case PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ: - if (PDU_DATA_LLCTRL_LEN(conn_param_req) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - - /* check CUI/CPR mutex for other connections having CPR in - * progress. - */ - if (cpr_active_is_set(conn)) { - /* Unsupported LL Parameter Value */ - nack = reject_ext_ind_send(conn, *rx, - PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ, - BT_HCI_ERR_UNSUPP_LL_PARAM_VAL); - break; - } - - if (!conn->lll.role) { - if ((conn->llcp_conn_param.req != - conn->llcp_conn_param.ack) && - ((conn->llcp_conn_param.state == - LLCP_CPR_STATE_REQ) || - (conn->llcp_conn_param.state == - LLCP_CPR_STATE_RSP_WAIT) || - (conn->llcp_conn_param.state == - LLCP_CPR_STATE_UPD))) { - /* Same procedure collision */ - nack = reject_ext_ind_send(conn, *rx, - PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ, - BT_HCI_ERR_LL_PROC_COLLISION); -#if defined(CONFIG_BT_CTLR_PHY) -#if defined(CONFIG_BT_CTLR_LE_ENC) - } else if (((((conn->llcp_req - conn->llcp_ack) & - 0x03) == 0x02) && - (conn->llcp_type != LLCP_ENCRYPTION)) || - (conn->llcp_phy.req != conn->llcp_phy.ack)) { -#else /* !CONFIG_BT_CTLR_LE_ENC */ - } else if ((((conn->llcp_req - conn->llcp_ack) & - 0x03) == 0x02) && - (conn->llcp_phy.req != conn->llcp_phy.ack)) { -#endif /* !CONFIG_BT_CTLR_LE_ENC */ -#else /* !CONFIG_BT_CTLR_PHY */ -#if defined(CONFIG_BT_CTLR_LE_ENC) - } else if ((((conn->llcp_req - conn->llcp_ack) & - 0x03) == 0x02) && - (conn->llcp_type != LLCP_ENCRYPTION)) { -#else /* !CONFIG_BT_CTLR_LE_ENC */ - } else if (((conn->llcp_req - conn->llcp_ack) & - 0x03) == 0x02) { -#endif /* !CONFIG_BT_CTLR_LE_ENC */ -#endif /* !CONFIG_BT_CTLR_PHY */ - /* Different procedure collision */ - nack = reject_ext_ind_send(conn, *rx, - PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ, - BT_HCI_ERR_DIFF_TRANS_COLLISION); - } else { - struct pdu_data_llctrl_conn_param_req *cpr = (void *) - &pdu_rx->llctrl.conn_param_req; - struct lll_conn *lll = &conn->lll; - - /* Extract parameters */ - uint16_t interval_min = - sys_le16_to_cpu(cpr->interval_min); - uint16_t interval_max = - sys_le16_to_cpu(cpr->interval_max); - uint16_t latency = - sys_le16_to_cpu(cpr->latency); - uint16_t timeout = - sys_le16_to_cpu(cpr->timeout); - uint16_t preferred_periodicity = - cpr->preferred_periodicity; - - /* Invalid parameters */ - if ((interval_min < CONN_INTERVAL_MIN(conn)) || - (interval_max > 3200) || - (interval_min > interval_max) || - (latency > 499) || - (timeout < 10) || - (timeout > 3200) || - ((timeout * 4U) <= - ((latency + 1) * interval_max)) || - (preferred_periodicity > interval_max)) { - nack = reject_ext_ind_send(conn, *rx, - PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ, - BT_HCI_ERR_INVALID_LL_PARAM); - break; - } - - /* save parameters to be used to select offset - */ - conn->llcp_conn_param.interval_min = - interval_min; - conn->llcp_conn_param.interval_max = - interval_max; - conn->llcp_conn_param.latency = latency; - conn->llcp_conn_param.timeout = timeout; - conn->llcp_conn_param.preferred_periodicity = - preferred_periodicity; - conn->llcp_conn_param.reference_conn_event_count = - sys_le16_to_cpu(cpr->reference_conn_event_count); - conn->llcp_conn_param.offset0 = - sys_le16_to_cpu(cpr->offset0); - conn->llcp_conn_param.offset1 = - sys_le16_to_cpu(cpr->offset1); - conn->llcp_conn_param.offset2 = - sys_le16_to_cpu(cpr->offset2); - conn->llcp_conn_param.offset3 = - sys_le16_to_cpu(cpr->offset3); - conn->llcp_conn_param.offset4 = - sys_le16_to_cpu(cpr->offset4); - conn->llcp_conn_param.offset5 = - sys_le16_to_cpu(cpr->offset5); - - /* enqueue the conn param req, if parameters - * changed, else respond. - */ - if ((conn->llcp_conn_param.interval_max != - lll->interval) || - (conn->llcp_conn_param.latency != - lll->latency) || - (conn->llcp_conn_param.timeout != conn->supervision_timeout)) { -#if defined(CONFIG_BT_CTLR_LE_ENC) - /* postpone CP request event if under - * encryption setup - */ - if (conn->llcp_enc.pause_tx) { - conn->llcp_conn_param.state = - LLCP_CPR_STATE_APP_REQ; - - /* Mark for buffer for release */ - (*rx)->hdr.type = - NODE_RX_TYPE_RELEASE; - } else -#endif /* CONFIG_BT_CTLR_LE_ENC */ - { - conn->llcp_conn_param.state = - LLCP_CPR_STATE_APP_WAIT; - } - } else { - conn->llcp_conn_param.status = 0U; - conn->llcp_conn_param.cmd = 0U; - conn->llcp_conn_param.state = - LLCP_CPR_STATE_RSP; - - /* Mark for buffer for release */ - (*rx)->hdr.type = - NODE_RX_TYPE_RELEASE; - } - - conn->llcp_conn_param.remote = 1U; - - conn->llcp_conn_param.ack--; - - /* Set CPR mutex */ - cpr_active_check_and_set(conn); - } - } else if ((conn->llcp_conn_param.req == - conn->llcp_conn_param.ack) || - (conn->llcp_conn_param.state == - LLCP_CPR_STATE_REQ) || - (conn->llcp_conn_param.state == - LLCP_CPR_STATE_RSP_WAIT)) { - struct pdu_data_llctrl_conn_param_req *cpr = (void *) - &pdu_rx->llctrl.conn_param_req; - struct lll_conn *lll = &conn->lll; - - /* Extract parameters */ - uint16_t interval_min = sys_le16_to_cpu(cpr->interval_min); - uint16_t interval_max = sys_le16_to_cpu(cpr->interval_max); - uint16_t latency = sys_le16_to_cpu(cpr->latency); - uint16_t timeout = sys_le16_to_cpu(cpr->timeout); - uint16_t preferred_periodicity = - cpr->preferred_periodicity; - - /* Invalid parameters */ - if ((interval_min < CONN_INTERVAL_MIN(conn)) || - (interval_max > 3200) || - (interval_min > interval_max) || - (latency > 499) || - (timeout < 10) || (timeout > 3200) || - ((timeout * 4U) <= - ((latency + 1) * interval_max)) || - (preferred_periodicity > interval_max)) { - nack = reject_ext_ind_send(conn, *rx, - PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ, - BT_HCI_ERR_INVALID_LL_PARAM); - break; - } - - /* resp to be generated by app, for now save - * parameters - */ - conn->llcp_conn_param.interval_min = interval_min; - conn->llcp_conn_param.interval_max = interval_max; - conn->llcp_conn_param.latency = latency; - conn->llcp_conn_param.timeout = timeout; - conn->llcp_conn_param.preferred_periodicity = - preferred_periodicity; - conn->llcp_conn_param.reference_conn_event_count = - sys_le16_to_cpu(cpr->reference_conn_event_count); - conn->llcp_conn_param.offset0 = - sys_le16_to_cpu(cpr->offset0); - conn->llcp_conn_param.offset1 = - sys_le16_to_cpu(cpr->offset1); - conn->llcp_conn_param.offset2 = - sys_le16_to_cpu(cpr->offset2); - conn->llcp_conn_param.offset3 = - sys_le16_to_cpu(cpr->offset3); - conn->llcp_conn_param.offset4 = - sys_le16_to_cpu(cpr->offset4); - conn->llcp_conn_param.offset5 = - sys_le16_to_cpu(cpr->offset5); - - /* enqueue the conn param req, if parameters changed, - * else respond - */ - if ((conn->llcp_conn_param.interval_max != - lll->interval) || - (conn->llcp_conn_param.latency != lll->latency) || - (conn->llcp_conn_param.timeout != conn->supervision_timeout)) { - conn->llcp_conn_param.state = - LLCP_CPR_STATE_APP_WAIT; - } else { - conn->llcp_conn_param.status = 0U; - conn->llcp_conn_param.cmd = 0U; - conn->llcp_conn_param.state = - LLCP_CPR_STATE_RSP; - - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - } - - conn->llcp_conn_param.remote = 1U; - - conn->llcp_conn_param.ack--; - - /* Set CPR mutex */ - cpr_active_check_and_set(conn); - } else { - /* Ignore duplicate request as peripheral is busy - * processing the previously initiated connection - * update request procedure. - */ - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - } - break; - -#if defined(CONFIG_BT_CENTRAL) - case PDU_DATA_LLCTRL_TYPE_CONN_PARAM_RSP: - if (conn->lll.role || - PDU_DATA_LLCTRL_LEN(conn_param_rsp) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - if (!conn->lll.role && - (conn->llcp_conn_param.req != - conn->llcp_conn_param.ack) && - (conn->llcp_conn_param.state == - LLCP_CPR_STATE_RSP_WAIT)) { - struct pdu_data_llctrl_conn_param_req *cpr = (void *) - &pdu_rx->llctrl.conn_param_req; - - /* Extract parameters */ - uint16_t interval_min = sys_le16_to_cpu(cpr->interval_min); - uint16_t interval_max = sys_le16_to_cpu(cpr->interval_max); - uint16_t latency = sys_le16_to_cpu(cpr->latency); - uint16_t timeout = sys_le16_to_cpu(cpr->timeout); - uint16_t preferred_periodicity = - cpr->preferred_periodicity; - - /* Invalid parameters */ - if ((interval_min < CONN_INTERVAL_MIN(conn)) || - (interval_max > 3200) || - (interval_min > interval_max) || - (latency > 499) || - (timeout < 10) || (timeout > 3200) || - ((timeout * 4U) <= - ((latency + 1) * interval_max)) || - (preferred_periodicity > interval_max)) { - nack = reject_ext_ind_send(conn, *rx, - PDU_DATA_LLCTRL_TYPE_CONN_PARAM_RSP, - BT_HCI_ERR_INVALID_LL_PARAM); - break; - } - - /* Stop procedure timeout */ - conn->procedure_expire = 0U; - - /* save parameters to be used to select offset - */ - conn->llcp_conn_param.interval_min = interval_min; - conn->llcp_conn_param.interval_max = interval_max; - conn->llcp_conn_param.latency = latency; - conn->llcp_conn_param.timeout = timeout; - conn->llcp_conn_param.preferred_periodicity = - preferred_periodicity; - conn->llcp_conn_param.reference_conn_event_count = - sys_le16_to_cpu(cpr->reference_conn_event_count); - conn->llcp_conn_param.offset0 = - sys_le16_to_cpu(cpr->offset0); - conn->llcp_conn_param.offset1 = - sys_le16_to_cpu(cpr->offset1); - conn->llcp_conn_param.offset2 = - sys_le16_to_cpu(cpr->offset2); - conn->llcp_conn_param.offset3 = - sys_le16_to_cpu(cpr->offset3); - conn->llcp_conn_param.offset4 = - sys_le16_to_cpu(cpr->offset4); - conn->llcp_conn_param.offset5 = - sys_le16_to_cpu(cpr->offset5); - - /* Perform connection update */ - conn->llcp_conn_param.state = LLCP_CPR_STATE_RSP; - } - - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - break; -#endif /* CONFIG_BT_CENTRAL */ -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - - case PDU_DATA_LLCTRL_TYPE_REJECT_EXT_IND: - if (PDU_DATA_LLCTRL_LEN(reject_ext_ind) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - reject_ext_ind_recv(conn, *rx, pdu_rx); - break; - -#if defined(CONFIG_BT_CTLR_LE_PING) - case PDU_DATA_LLCTRL_TYPE_PING_REQ: - if (PDU_DATA_LLCTRL_LEN(ping_req) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - nack = ping_resp_send(conn, *rx); - break; - - case PDU_DATA_LLCTRL_TYPE_PING_RSP: - if (PDU_DATA_LLCTRL_LEN(ping_rsp) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - /* Procedure complete */ - conn->procedure_expire = 0U; - - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - break; -#endif /* CONFIG_BT_CTLR_LE_PING */ - - case PDU_DATA_LLCTRL_TYPE_UNKNOWN_RSP: - if (PDU_DATA_LLCTRL_LEN(unknown_rsp) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } - - struct pdu_data_llctrl *llctrl = (void *)&pdu_rx->llctrl; - - if (0) { -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - } else if ((conn->llcp_conn_param.ack != - conn->llcp_conn_param.req) && - (llctrl->unknown_rsp.type == - PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ)) { - struct lll_conn *lll = &conn->lll; - struct node_rx_cu *cu; - void *node; - - /* Mark CPR as unsupported */ - conn->llcp_conn_param.disabled = 1U; - - /* TODO: check for unsupported remote feature reason */ - if (!conn->lll.role) { - LL_ASSERT(conn->llcp_cu.req == - conn->llcp_cu.ack); - - conn->llcp_conn_param.state = - LLCP_CPR_STATE_UPD; - - conn->llcp_cu.win_size = 1U; - conn->llcp_cu.win_offset_us = 0U; - conn->llcp_cu.interval = - conn->llcp_conn_param.interval_max; - conn->llcp_cu.latency = - conn->llcp_conn_param.latency; - conn->llcp_cu.timeout = - conn->llcp_conn_param.timeout; - conn->llcp_cu.state = LLCP_CUI_STATE_USE; - conn->llcp_cu.cmd = conn->llcp_conn_param.cmd; - conn->llcp_cu.ack--; - - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - break; - } - - /* Reset CPR mutex */ - cpr_active_reset(); - - /* Check and initiate new CPR from cache, if any */ - cpr_cache_initiate_or_complete(conn); - - /* skip event generation if not cmd initiated */ - if (!conn->llcp_conn_param.cmd) { - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - - break; - } - - /* generate conn upd complete event with error code */ - (*rx)->hdr.type = NODE_RX_TYPE_CONN_UPDATE; - - /* check for pdu field being aligned before populating - * connection update complete event. - */ - node = pdu_rx; - LL_ASSERT(IS_PTR_ALIGNED(node, struct node_rx_cu)); - - /* prepare connection update complete structure */ - cu = node; - cu->status = BT_HCI_ERR_UNSUPP_REMOTE_FEATURE; - cu->interval = lll->interval; - cu->latency = lll->latency; - cu->timeout = conn->supervision_timeout; -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - } else if ((conn->llcp_length.req != conn->llcp_length.ack) && - (llctrl->unknown_rsp.type == - PDU_DATA_LLCTRL_TYPE_LENGTH_REQ)) { - /* Mark length update as unsupported */ - conn->llcp_length.disabled = 1U; - - /* Procedure complete */ - conn->llcp_length.ack = conn->llcp_length.req; - - /* propagate the data length procedure to - * host - */ -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - -#if defined(CONFIG_BT_CTLR_PHY) - } else if ((conn->llcp_phy.req != conn->llcp_phy.ack) && - (llctrl->unknown_rsp.type == - PDU_DATA_LLCTRL_TYPE_PHY_REQ)) { - struct lll_conn *lll = &conn->lll; - - /* Mark phy update as unsupported */ - conn->llcp_phy.disabled = 1U; - - /* Procedure complete */ - conn->llcp_phy.ack = conn->llcp_phy.req; - conn->llcp_phy.pause_tx = 0U; - - /* Reset packet timing restrictions */ - lll->phy_tx_time = lll->phy_tx; - - /* skip event generation is not cmd initiated */ - if (conn->llcp_phy.cmd) { - struct node_rx_pu *p; - - /* generate phy update complete event */ - (*rx)->hdr.type = NODE_RX_TYPE_PHY_UPDATE; + conn_cleanup_finalize(conn); + } +} +#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO || CONFIG_BT_CTLR_CENTRAL_ISO */ - p = (void *)pdu_rx; - p->status = 0U; - p->tx = lll->phy_tx; - p->rx = lll->phy_rx; - } else { - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - } -#endif /* CONFIG_BT_CTLR_PHY */ +static void conn_cleanup_finalize(struct ll_conn *conn) +{ + struct lll_conn *lll = &conn->lll; + struct node_rx_pdu *rx; + uint32_t ticker_status; - } else { - switch (llctrl->unknown_rsp.type) { + ARG_UNUSED(rx); + ull_cp_state_set(conn, ULL_CP_DISCONNECTED); -#if defined(CONFIG_BT_CTLR_LE_PING) - case PDU_DATA_LLCTRL_TYPE_PING_REQ: - /* unknown rsp to LE Ping Req completes the - * procedure; nothing to do here. - */ + /* Update tx buffer queue handling */ +#if defined(LLCP_TX_CTRL_BUF_QUEUE_ENABLE) + ull_cp_update_tx_buffer_queue(conn); +#endif /* LLCP_TX_CTRL_BUF_QUEUE_ENABLE */ - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - break; -#endif /* CONFIG_BT_CTLR_LE_PING */ + /* flush demux-ed Tx buffer still in ULL context */ + tx_ull_flush(conn); - default: - /* TODO: enqueue the error and let HCI handle - * it. - */ - break; - } - } + /* Stop Central or Peripheral role ticker */ + ticker_status = ticker_stop(TICKER_INSTANCE_ID_CTLR, + TICKER_USER_ID_ULL_HIGH, + TICKER_ID_CONN_BASE + lll->handle, + ticker_stop_op_cb, conn); + LL_ASSERT((ticker_status == TICKER_STATUS_SUCCESS) || + (ticker_status == TICKER_STATUS_BUSY)); - /* Procedure complete */ - conn->procedure_expire = 0U; - break; + /* Invalidate the connection context */ + lll->handle = LLL_HANDLE_INVALID; -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - case PDU_DATA_LLCTRL_TYPE_LENGTH_RSP: - case PDU_DATA_LLCTRL_TYPE_LENGTH_REQ: - if (PDU_DATA_LLCTRL_LEN(length_req) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } + /* Demux and flush Tx PDUs that remain enqueued in thread context */ + ull_conn_tx_demux(UINT8_MAX); +} - nack = length_req_rsp_recv(conn, link, rx, pdu_rx); - break; -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ +static void conn_cleanup(struct ll_conn *conn, uint8_t reason) +{ + struct node_rx_pdu *rx; -#if defined(CONFIG_BT_CTLR_PHY) - case PDU_DATA_LLCTRL_TYPE_PHY_REQ: - if (PDU_DATA_LLCTRL_LEN(phy_req) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } +#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) || defined(CONFIG_BT_CTLR_CENTRAL_ISO) + struct ll_conn_iso_stream *cis; +#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO || CONFIG_BT_CTLR_CENTRAL_ISO */ - if (!conn->lll.role) { - if ((conn->llcp_phy.ack != - conn->llcp_phy.req) && - ((conn->llcp_phy.state == - LLCP_PHY_STATE_ACK_WAIT) || - (conn->llcp_phy.state == - LLCP_PHY_STATE_RSP_WAIT) || - (conn->llcp_phy.state == - LLCP_PHY_STATE_UPD))) { - /* Same procedure collision */ - nack = reject_ext_ind_send(conn, *rx, - PDU_DATA_LLCTRL_TYPE_PHY_REQ, - BT_HCI_ERR_LL_PROC_COLLISION); #if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) -#if defined(CONFIG_BT_CTLR_LE_ENC) - } else if (((((conn->llcp_req - conn->llcp_ack) & - 0x03) == 0x02) && - (conn->llcp_type != - LLCP_ENCRYPTION)) || - (conn->llcp_conn_param.req != - conn->llcp_conn_param.ack)) { -#else /* !CONFIG_BT_CTLR_LE_ENC */ - } else if ((((conn->llcp_req - conn->llcp_ack) & - 0x03) == 0x02) && - (conn->llcp_conn_param.req != - conn->llcp_conn_param.ack)) { -#endif /* !CONFIG_BT_CTLR_LE_ENC */ -#else /* !CONFIG_BT_CTLR_CONN_PARAM_REQ */ -#if defined(CONFIG_BT_CTLR_LE_ENC) - } else if ((((conn->llcp_req - conn->llcp_ack) & - 0x03) == 0x02) && - (conn->llcp_type != - LLCP_ENCRYPTION)) { -#else /* !CONFIG_BT_CTLR_LE_ENC */ - } else if (((conn->llcp_req - conn->llcp_ack) & - 0x03) == 0x02) { -#endif /* !CONFIG_BT_CTLR_LE_ENC */ -#endif /* !CONFIG_BT_CTLR_CONN_PARAM_REQ */ - /* Different procedure collision */ - nack = reject_ext_ind_send(conn, *rx, - PDU_DATA_LLCTRL_TYPE_PHY_REQ, - BT_HCI_ERR_DIFF_TRANS_COLLISION); - } else { - struct pdu_data_llctrl *c = &pdu_rx->llctrl; - struct pdu_data_llctrl_phy_req *p = - &c->phy_req; + /* Reset CPR mutex */ + cpr_active_check_and_reset(conn); +#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - conn->llcp_phy.state = - LLCP_PHY_STATE_UPD; + /* Only termination structure is populated here in ULL context + * but the actual enqueue happens in the LLL context in + * tx_lll_flush. The reason being to avoid passing the reason + * value and handle through the mayfly scheduling of the + * tx_lll_flush. + */ + rx = (void *)&conn->llcp_terminate.node_rx; + rx->hdr.handle = conn->lll.handle; + rx->hdr.type = NODE_RX_TYPE_TERMINATE; + *((uint8_t *)rx->pdu) = reason; + +#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) || defined(CONFIG_BT_CTLR_CENTRAL_ISO) + cis = ll_conn_iso_stream_get_by_acl(conn, NULL); + if (cis) { + /* Stop CIS and defer cleanup to after teardown. */ + ull_conn_iso_cis_stop(cis, conn_cleanup_iso_cis_released_cb, + reason); + return; + } +#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO || CONFIG_BT_CTLR_CENTRAL_ISO */ - if (conn->llcp_phy.ack == - conn->llcp_phy.req) { - conn->llcp_phy.ack--; + conn_cleanup_finalize(conn); +} - conn->llcp_phy.cmd = 0U; +static void tx_ull_flush(struct ll_conn *conn) +{ + struct node_tx *tx; - conn->llcp_phy.tx = - conn->phy_pref_tx; - conn->llcp_phy.rx = - conn->phy_pref_rx; - } + ull_tx_q_resume_data(&conn->tx_q); - conn->llcp_phy.tx &= p->rx_phys; - conn->llcp_phy.rx &= p->tx_phys; + tx = tx_ull_dequeue(conn, NULL); + while (tx) { + memq_link_t *link; - if (!conn->llcp_phy.tx || !conn->llcp_phy.rx) { - conn->llcp_phy.tx = 0U; - conn->llcp_phy.rx = 0U; - } + link = mem_acquire(&mem_link_tx.free); + LL_ASSERT(link); - /* pause data packet tx */ - conn->llcp_phy.pause_tx = 1U; + /* Enqueue towards LLL */ + memq_enqueue(link, tx, &conn->lll.memq_tx.tail); - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; - } - } else { - nack = phy_rsp_send(conn, *rx, pdu_rx); - } - break; + tx = tx_ull_dequeue(conn, NULL); + } +} -#if defined(CONFIG_BT_CENTRAL) - case PDU_DATA_LLCTRL_TYPE_PHY_RSP: - if (conn->lll.role || - PDU_DATA_LLCTRL_LEN(phy_rsp) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } +static void ticker_stop_op_cb(uint32_t status, void *param) +{ + static memq_link_t link; + static struct mayfly mfy = {0, 0, &link, NULL, conn_disable}; + uint32_t ret; - if (!conn->lll.role && - (conn->llcp_phy.ack != conn->llcp_phy.req) && - (conn->llcp_phy.state == LLCP_PHY_STATE_RSP_WAIT)) { - struct pdu_data_llctrl_phy_rsp *p = - &pdu_rx->llctrl.phy_rsp; + LL_ASSERT(status == TICKER_STATUS_SUCCESS); - conn->llcp_phy.state = LLCP_PHY_STATE_UPD; + /* Check if any pending LLL events that need to be aborted */ + mfy.param = param; + ret = mayfly_enqueue(TICKER_USER_ID_ULL_LOW, + TICKER_USER_ID_ULL_HIGH, 0, &mfy); + LL_ASSERT(!ret); +} - conn->llcp_phy.tx &= p->rx_phys; - conn->llcp_phy.rx &= p->tx_phys; +static void conn_disable(void *param) +{ + struct ll_conn *conn; + struct ull_hdr *hdr; - if (!conn->llcp_phy.tx || !conn->llcp_phy.rx) { - conn->llcp_phy.tx = 0U; - conn->llcp_phy.rx = 0U; - } + /* Check ref count to determine if any pending LLL events in pipeline */ + conn = param; + hdr = &conn->ull; + if (ull_ref_get(hdr)) { + static memq_link_t link; + static struct mayfly mfy = {0, 0, &link, NULL, lll_disable}; + uint32_t ret; - /* pause data packet tx */ - conn->llcp_phy.pause_tx = 1U; + mfy.param = &conn->lll; - /* Procedure timeout is stopped */ - conn->procedure_expire = 0U; - } + /* Setup disabled callback to be called when ref count + * returns to zero. + */ + LL_ASSERT(!hdr->disabled_cb); + hdr->disabled_param = mfy.param; + hdr->disabled_cb = disabled_cb; - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; + /* Trigger LLL disable */ + ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, + TICKER_USER_ID_LLL, 0, &mfy); + LL_ASSERT(!ret); + } else { + /* No pending LLL events */ + disabled_cb(&conn->lll); + } +} - break; -#endif /* CONFIG_BT_CENTRAL */ +static void disabled_cb(void *param) +{ + static memq_link_t link; + static struct mayfly mfy = {0, 0, &link, NULL, tx_lll_flush}; + uint32_t ret; -#if defined(CONFIG_BT_PERIPHERAL) - case PDU_DATA_LLCTRL_TYPE_PHY_UPD_IND: - { - uint8_t err; + mfy.param = param; + ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, + TICKER_USER_ID_LLL, 0, &mfy); + LL_ASSERT(!ret); +} - if (!conn->lll.role || - PDU_DATA_LLCTRL_LEN(phy_upd_ind) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } +static void tx_lll_flush(void *param) +{ + struct node_rx_pdu *rx; + struct lll_conn *lll; + struct ll_conn *conn; + struct node_tx *tx; + memq_link_t *link; + uint16_t handle; - err = phy_upd_ind_recv(conn, link, rx, pdu_rx); - if (err) { - conn->llcp_terminate.reason_final = err; - } - } - break; -#endif /* CONFIG_BT_PERIPHERAL */ -#endif /* CONFIG_BT_CTLR_PHY */ + /* Get reference to ULL context */ + lll = param; + conn = HDR_LLL2ULL(lll); + handle = ll_conn_handle_get(conn); -#if defined(CONFIG_BT_CTLR_MIN_USED_CHAN) -#if defined(CONFIG_BT_CENTRAL) - case PDU_DATA_LLCTRL_TYPE_MIN_USED_CHAN_IND: - if (conn->lll.role || - PDU_DATA_LLCTRL_LEN(min_used_chans_ind) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } + lll_conn_flush(handle, lll); - if (!conn->lll.role) { - struct pdu_data_llctrl_min_used_chans_ind *p = - &pdu_rx->llctrl.min_used_chans_ind; + link = memq_dequeue(lll->memq_tx.tail, &lll->memq_tx.head, + (void **)&tx); + while (link) { + uint8_t idx; + struct lll_tx *lll_tx2; -#if defined(CONFIG_BT_CTLR_PHY) - if (!(p->phys & (conn->lll.phy_tx | - conn->lll.phy_rx))) { -#else /* !CONFIG_BT_CTLR_PHY */ - if (!(p->phys & 0x01)) { -#endif /* !CONFIG_BT_CTLR_PHY */ - break; - } + idx = MFIFO_ENQUEUE_GET(conn_ack, (void **)&lll_tx2); + LL_ASSERT(lll_tx2); - if (((conn->llcp_req - conn->llcp_ack) & 0x03) == - 0x02) { - break; - } + lll_tx2->handle = LLL_HANDLE_INVALID; + lll_tx2->node = tx; - ull_chan_map_get(conn->llcp.chan_map.chm); - /* conn->llcp.chan_map.instant = 0U; filled in initiate - * state. - */ - conn->llcp.chan_map.initiate = 1U; + /* TX node UPSTREAM, i.e. Tx node ack path */ + link->next = tx->next; /* Indicates ctrl pool or data pool */ + tx->next = link; - conn->llcp_type = LLCP_CHAN_MAP; - conn->llcp_ack -= 2U; - } + MFIFO_ENQUEUE(conn_ack, idx); - /* Mark for buffer for release */ - (*rx)->hdr.type = NODE_RX_TYPE_RELEASE; + link = memq_dequeue(lll->memq_tx.tail, &lll->memq_tx.head, + (void **)&tx); + } - break; -#endif /* CONFIG_BT_CENTRAL */ -#endif /* CONFIG_BT_CTLR_MIN_USED_CHAN */ + /* Get the terminate structure reserved in the connection context. + * The terminate reason and connection handle should already be + * populated before this mayfly function was scheduled. + */ + rx = (void *)&conn->llcp_terminate.node_rx; + LL_ASSERT(rx->hdr.link); + link = rx->hdr.link; + rx->hdr.link = NULL; -#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) - case PDU_DATA_LLCTRL_TYPE_CIS_REQ: - { - uint8_t err; + /* Enqueue the terminate towards ULL context */ + ull_rx_put(link, rx); + ull_rx_sched(); +} - if (!conn->lll.role || - PDU_DATA_LLCTRL_LEN(cis_req) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } +#if defined(CONFIG_BT_CTLR_LLID_DATA_START_EMPTY) +static int empty_data_start_release(struct ll_conn *conn, struct node_tx *tx) +{ + struct pdu_data *p = (void *)tx->pdu; - err = cis_req_recv(conn, link, rx, pdu_rx); - if (err) { - if (err == BT_HCI_ERR_INVALID_LL_PARAM) { - nack = reject_ext_ind_send(conn, *rx, - PDU_DATA_LLCTRL_TYPE_CIS_REQ, - BT_HCI_ERR_UNSUPP_LL_PARAM_VAL); - } else { - conn->llcp_terminate.reason_final = err; - } - } - break; - } + if ((p->ll_id == PDU_DATA_LLID_DATA_START) && !p->len) { + conn->start_empty = 1U; - case PDU_DATA_LLCTRL_TYPE_CIS_IND: - { - uint8_t err; + ll_tx_ack_put(conn->lll.handle, tx); - if (!conn->lll.role || - PDU_DATA_LLCTRL_LEN(cis_ind) != pdu_rx->len) { - goto ull_conn_rx_unknown_rsp_send; - } + return -EINVAL; + } else if (p->len && conn->start_empty) { + conn->start_empty = 0U; - err = cis_ind_recv(conn, link, rx, pdu_rx); - if (err) { - conn->llcp_terminate.reason_final = err; + if (p->ll_id == PDU_DATA_LLID_DATA_CONTINUE) { + p->ll_id = PDU_DATA_LLID_DATA_START; } - break; - } -#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO */ - - default: -ull_conn_rx_unknown_rsp_send: - nack = unknown_rsp_send(conn, *rx, opcode); - break; } - return nack; + return 0; } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ +#endif /* CONFIG_BT_CTLR_LLID_DATA_START_EMPTY */ #if defined(CONFIG_BT_CTLR_FORCE_MD_AUTO) static uint8_t force_md_cnt_calc(struct lll_conn *lll_conn, uint32_t tx_rate) @@ -8069,8 +2121,6 @@ static uint8_t force_md_cnt_calc(struct lll_conn *lll_conn, uint32_t tx_rate) } #endif /* CONFIG_BT_CTLR_FORCE_MD_AUTO */ -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - #if defined(CONFIG_BT_CTLR_LE_ENC) /** * @brief Pause the data path of a rx queue. @@ -8525,10 +2575,15 @@ void ull_dle_local_tx_update(struct ll_conn *conn, uint16_t tx_octets, uint16_t void ull_dle_init(struct ll_conn *conn, uint8_t phy) { + /* + * TODO: + * legacy code uses the maximum of the time for 1M phy and actual phy + * for max_time_min, to be verified if that is required here as well + */ #if defined(CONFIG_BT_CTLR_PHY) const uint16_t max_time_min = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, phy); const uint16_t max_time_max = PDU_DC_MAX_US(LL_LENGTH_OCTETS_RX_MAX, phy); -#endif +#endif /* CONFIG_BT_CTLR_PHY */ /* Clear DLE data set */ memset(&conn->lll.dle, 0, sizeof(conn->lll.dle)); @@ -8598,8 +2653,6 @@ uint8_t ull_conn_lll_phy_active(struct ll_conn *conn, uint8_t phys) return 1; } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - uint8_t ull_is_lll_tx_queue_empty(struct ll_conn *conn) { return (memq_peek(conn->lll.memq_tx.head, conn->lll.memq_tx.tail, NULL) == NULL); diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_internal.h b/subsys/bluetooth/controller/ll_sw/ull_conn_internal.h index 435d328c11b7..2c76f5c83c19 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_internal.h +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_internal.h @@ -76,8 +76,6 @@ static inline void cpr_active_reset(void) } #endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - uint16_t ull_conn_event_counter(struct ll_conn *conn); void ull_conn_update_parameters(struct ll_conn *conn, uint8_t is_cu_proc, @@ -128,8 +126,6 @@ void ull_conn_pause_rx_data(struct ll_conn *conn); */ void ull_conn_resume_rx_data(struct ll_conn *conn); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - /** * @brief Check if the lower link layer transmit queue is empty */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c index 0ac351c47657..2d987323f7b3 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c @@ -33,9 +33,7 @@ #include "lll_central_iso.h" #include "lll_peripheral_iso.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#include "ull_tx_queue.h" -#endif +#include "ll_sw/ull_tx_queue.h" #include "isoal.h" @@ -1048,11 +1046,9 @@ static void cis_disabled_cb(void *param) cig->lll.num_cis--; -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) /* CIS terminated, triggers completion of CIS_TERMINATE_IND procedure */ /* Only used by local procedure, ignored for remote procedure */ conn->llcp.cis.terminate_ack = 1U; -#endif /* defined(CONFIG_BT_LL_SW_LLCP_LEGACY) */ /* Check if removed CIS has an ACL disassociation callback. Invoke * the callback to allow cleanup. diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_types.h b/subsys/bluetooth/controller/ll_sw/ull_conn_types.h index 58d444edac15..cdfdbbf9079a 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_types.h +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_types.h @@ -32,330 +32,6 @@ enum llcp { #endif /* CONFIG_BT_CTLR_PHY */ }; -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -struct ll_conn { - struct ull_hdr ull; - struct lll_conn lll; - - uint16_t connect_expire; - uint16_t supervision_timeout; - uint16_t supervision_expire; - uint16_t procedure_reload; - uint16_t procedure_expire; - -#if defined(CONFIG_BT_CTLR_LE_PING) - uint16_t appto_reload; - uint16_t appto_expire; - uint16_t apto_reload; - uint16_t apto_expire; -#endif /* CONFIG_BT_CTLR_LE_PING */ - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - uint16_t default_tx_octets; - -#if defined(CONFIG_BT_CTLR_PHY) - uint16_t default_tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - -#if defined(CONFIG_BT_CTLR_CHECK_SAME_PEER_CONN) - uint8_t own_id_addr_type:1; - uint8_t peer_id_addr_type:1; - uint8_t own_id_addr[BDADDR_SIZE]; - uint8_t peer_id_addr[BDADDR_SIZE]; -#endif /* CONFIG_BT_CTLR_CHECK_SAME_PEER_CONN */ - - union { - struct { - uint8_t fex_valid:1; - uint8_t txn_lock:1; -#if defined(CONFIG_BT_CTLR_CONN_META) - uint8_t is_must_expire:1; -#endif /* CONFIG_BT_CTLR_CONN_META */ - } common; - -#if defined(CONFIG_BT_PERIPHERAL) - struct { - uint8_t fex_valid:1; - uint8_t txn_lock:1; -#if defined(CONFIG_BT_CTLR_CONN_META) - uint8_t is_must_expire:1; -#endif /* CONFIG_BT_CTLR_CONN_META */ - uint8_t latency_cancel:1; - uint8_t sca:3; -#if defined(CONFIG_BT_CTLR_LE_ENC) - uint8_t llcp_type; -#endif /* CONFIG_BT_CTLR_LE_ENC */ -#if defined(CONFIG_BT_CTLR_CONN_RANDOM_FORCE) - uint32_t force; -#endif /* CONFIG_BT_CTLR_CONN_RANDOM_FORCE */ -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - uint32_t ticks_to_offset; -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - } periph; -#endif /* CONFIG_BT_PERIPHERAL */ - -#if defined(CONFIG_BT_CENTRAL) - struct { - uint8_t fex_valid:1; - uint8_t txn_lock:1; -#if defined(CONFIG_BT_CTLR_CONN_META) - uint8_t is_must_expire:1; -#endif /* CONFIG_BT_CTLR_CONN_META */ - uint8_t terminate_ack:1; - } central; -#endif /* CONFIG_BT_CENTRAL */ - }; - - uint8_t llcp_req; - uint8_t llcp_ack; - - uint8_t llcp_type; - - struct { - union { - struct { - uint16_t instant; - uint16_t *pdu_win_offset; - uint32_t ticks_anchor; - } conn_upd; - - struct { - uint8_t initiate:1; - uint8_t chm[5]; - uint16_t instant; - } chan_map; - -#if defined(CONFIG_BT_CTLR_PHY) - struct { - uint8_t initiate:1; - uint8_t cmd:1; - uint8_t tx:3; - uint8_t rx:3; - uint16_t instant; - } phy_upd_ind; -#endif /* CONFIG_BT_CTLR_PHY */ - }; - -#if defined(CONFIG_BT_CTLR_LE_ENC) - struct { - enum { - LLCP_ENC_STATE_INPROG, - LLCP_ENC_STATE_INIT, - LLCP_ENC_STATE_LTK_WAIT, - LLCP_ENC_STATE_ENC_WAIT, - } state:2 __packed; - uint8_t error_code; - uint8_t skd[16]; - } encryption; -#endif /* CONFIG_BT_CTLR_LE_ENC */ - } llcp; - - struct node_rx_pdu *llcp_rx; - -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) - struct node_rx_pdu *llcp_rx_hold; -#endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - - struct { - uint8_t req; - uint8_t ack; - enum { - LLCP_CUI_STATE_INPROG, - LLCP_CUI_STATE_USE, - LLCP_CUI_STATE_SELECT, - LLCP_CUI_STATE_OFFS_REQ, - LLCP_CUI_STATE_OFFS_RDY, - LLCP_CUI_STATE_REJECT, - } state:3 __packed; - uint8_t cmd:1; - uint8_t pause_tx:1; - uint16_t interval; - uint16_t latency; - uint16_t timeout; - uint32_t win_offset_us; - uint8_t win_size; - } llcp_cu; - - struct { - uint8_t req; - uint8_t ack; - /* TODO: 8, 16, 32 or 64 based on local supported features */ - uint64_t features_conn; - uint64_t features_peer; - } llcp_feature; - - struct { - uint8_t req; - uint8_t ack; - uint8_t tx:1; - uint8_t rx:1; - uint8_t version_number; - uint16_t company_id; - uint16_t sub_version_number; - } llcp_version; - - struct { - uint8_t req; - uint8_t ack; - uint8_t reason_own; - uint8_t reason_final; - /* node rx type with memory aligned storage for terminate - * reason. - * HCI will reference the value using the pdu member of - * struct node_rx_pdu. - */ - struct { - struct node_rx_hdr hdr; - union { - uint8_t pdu[0] __aligned(4); - uint8_t reason; - }; - } node_rx; - } llcp_terminate; - -#if defined(CONFIG_BT_CTLR_LE_ENC) - struct { - uint8_t req; - uint8_t ack; - uint8_t pause_rx:1; - uint8_t pause_tx:1; - uint8_t refresh:1; - uint8_t ediv[2]; - uint8_t rand[8]; - uint8_t ltk[16]; - } llcp_enc; -#endif /* CONFIG_BT_CTLR_LE_ENC */ - -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) - struct { - uint8_t req; - uint8_t ack; - enum { - LLCP_CPR_STATE_REQ, - LLCP_CPR_STATE_RSP, - LLCP_CPR_STATE_APP_REQ, - LLCP_CPR_STATE_APP_WAIT, - LLCP_CPR_STATE_RSP_WAIT, - LLCP_CPR_STATE_UPD_WAIT, - LLCP_CPR_STATE_UPD, - LLCP_CPR_STATE_OFFS_REQ, - LLCP_CPR_STATE_OFFS_RDY, - } state:4 __packed; - uint8_t cmd:1; - uint8_t remote:1; - uint8_t disabled:1; - uint8_t status; - uint16_t interval_min; - uint16_t interval_max; - uint16_t latency; - uint16_t timeout; - struct { - uint16_t interval_min; - uint16_t interval_max; - uint16_t latency; - uint16_t timeout; - } cache; - uint8_t preferred_periodicity; - uint16_t reference_conn_event_count; - uint16_t offset0; - uint16_t offset1; - uint16_t offset2; - uint16_t offset3; - uint16_t offset4; - uint16_t offset5; - uint16_t *pdu_win_offset0; - uint32_t ticks_ref; - uint32_t ticks_to_offset_next; - } llcp_conn_param; -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ - -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) - struct { - uint8_t req; - uint8_t ack; - uint8_t state:3; -#define LLCP_LENGTH_STATE_REQ 0 -#define LLCP_LENGTH_STATE_REQ_ACK_WAIT 1 -#define LLCP_LENGTH_STATE_RSP_WAIT 2 -#define LLCP_LENGTH_STATE_RSP_ACK_WAIT 3 -#define LLCP_LENGTH_STATE_RESIZE 4 -#define LLCP_LENGTH_STATE_RESIZE_RSP 5 -#define LLCP_LENGTH_STATE_RESIZE_RSP_ACK_WAIT 6 - uint8_t disabled:1; - uint16_t rx_octets; - uint16_t tx_octets; -#if defined(CONFIG_BT_CTLR_PHY) - uint16_t rx_time; - uint16_t tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - struct { - uint16_t tx_octets; -#if defined(CONFIG_BT_CTLR_PHY) - uint16_t tx_time; -#endif /* CONFIG_BT_CTLR_PHY */ - } cache; - } llcp_length; -#endif /* CONFIG_BT_CTLR_DATA_LENGTH */ - -#if defined(CONFIG_BT_CTLR_PHY) - struct { - uint8_t req; - uint8_t ack; - uint8_t state:2; -#define LLCP_PHY_STATE_REQ 0 -#define LLCP_PHY_STATE_ACK_WAIT 1 -#define LLCP_PHY_STATE_RSP_WAIT 2 -#define LLCP_PHY_STATE_UPD 3 - uint8_t tx:3; - uint8_t rx:3; - uint8_t pause_tx:1; - uint8_t flags:1; - uint8_t cmd:1; - uint8_t disabled:1; - } llcp_phy; - - uint8_t phy_pref_tx:3; - uint8_t phy_pref_rx:3; -#endif /* CONFIG_BT_CTLR_PHY */ - -#if defined(CONFIG_BT_CTLR_LLID_DATA_START_EMPTY) - /* Detect empty L2CAP start frame */ - uint8_t start_empty:1; -#endif /* CONFIG_BT_CTLR_LLID_DATA_START_EMPTY */ - - struct node_tx *tx_head; - struct node_tx *tx_ctrl; - struct node_tx *tx_ctrl_last; - struct node_tx *tx_data; - struct node_tx *tx_data_last; - - uint8_t chm_updated; - -#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) - struct { - uint8_t req; - uint8_t ack; - enum { - LLCP_CIS_STATE_REQ, - LLCP_CIS_STATE_RSP_WAIT, - LLCP_CIS_STATE_IND_WAIT, - LLCP_CIS_STATE_INST_WAIT - } state:8 __packed; - uint8_t cig_id; - uint16_t cis_handle; - uint8_t cis_id; - uint32_t cis_offset_min; - uint32_t cis_offset_max; - uint16_t conn_event_count; - } llcp_cis; -#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO */ - -#if defined(CONFIG_BT_CTLR_DF_CONN_CTE_REQ) - struct lll_df_conn_rx_params df_rx_params; -#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */ -}; -#else /* * This is for the refactored LLCP * @@ -572,7 +248,6 @@ struct ll_conn { uint8_t start_empty:1; #endif /* CONFIG_BT_CTLR_LLID_DATA_START_EMPTY */ }; /* struct ll_conn */ -#endif /* BT_LL_SW_SPLIT_LEGACY */ struct node_rx_cc { uint8_t status; diff --git a/subsys/bluetooth/controller/ll_sw/ull_filter.c b/subsys/bluetooth/controller/ll_sw/ull_filter.c index ee04a0f32996..3be6f80950d4 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_filter.c +++ b/subsys/bluetooth/controller/ll_sw/ull_filter.c @@ -33,9 +33,7 @@ #include "lll_conn.h" #include "lll_filter.h" -#if (!defined(CONFIG_BT_LL_SW_LLCP_LEGACY)) #include "ll_sw/ull_tx_queue.h" -#endif #include "ull_adv_types.h" #include "ull_scan_types.h" diff --git a/subsys/bluetooth/controller/ll_sw/ull_iso.c b/subsys/bluetooth/controller/ll_sw/ull_iso.c index c1b30256b175..41bfabac6e7f 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_iso.c @@ -36,9 +36,7 @@ #include "lll_conn_iso.h" #include "lll_iso_tx.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#include "ull_tx_queue.h" -#endif +#include "ll_sw/ull_tx_queue.h" #include "isoal.h" @@ -239,12 +237,8 @@ uint8_t ll_setup_iso_path(uint16_t handle, uint8_t path_dir, uint8_t path_id, * disallowed status. */ #if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - const uint8_t cis_waiting = (conn->llcp_cis.state == - LLCP_CIS_STATE_RSP_WAIT); -#else const uint8_t cis_waiting = ull_cp_cc_awaiting_reply(conn); -#endif + if (cis_waiting) { return BT_HCI_ERR_CMD_DISALLOWED; } diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c index 7703d9d2adcc..bddedc78b1ab 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c @@ -39,9 +39,7 @@ #include "lll_filter.h" #include "lll_conn_iso.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#include "ull_tx_queue.h" -#endif +#include "ll_sw/ull_tx_queue.h" #include "ull_adv_types.h" #include "ull_conn_types.h" @@ -54,13 +52,11 @@ #include "ll.h" -#if (!defined(CONFIG_BT_LL_SW_LLCP_LEGACY)) -#include "isoal.h" -#include "ull_iso_types.h" -#include "ull_conn_iso_types.h" +#include "ll_sw/isoal.h" +#include "ll_sw/ull_iso_types.h" +#include "ll_sw/ull_conn_iso_types.h" -#include "ull_llcp.h" -#endif +#include "ll_sw/ull_llcp.h" #include "hal/debug.h" @@ -188,10 +184,8 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, win_delay_us = WIN_DELAY_LEGACY; } -#if (!defined(CONFIG_BT_LL_SW_LLCP_LEGACY)) /* Set LLCP as connection-wise connected */ ull_cp_state_set(conn, ULL_CP_CONNECTED); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ /* calculate the window widening */ conn->periph.sca = pdu_adv->connect_ind.sca; @@ -207,15 +201,9 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, /* procedure timeouts */ conn->supervision_timeout = sys_le16_to_cpu(pdu_adv->connect_ind.timeout); -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - conn->procedure_reload = - RADIO_CONN_EVENTS((40 * 1000 * 1000), conn_interval_us); -#else /* Setup the PRT reload */ ull_cp_prt_reload_set(conn, conn_interval_us); -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) #if defined(CONFIG_BT_CTLR_CONN_ISO) uint16_t conn_accept_timeout; @@ -224,7 +212,6 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, #else conn->connect_accept_to = DEFAULT_CONNECTION_ACCEPT_TIMEOUT_US; #endif /* CONFIG_BT_CTLR_CONN_ISO */ -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ #if defined(CONFIG_BT_CTLR_LE_PING) /* APTO in no. of connection events */ @@ -355,13 +342,8 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, #if defined(CONFIG_BT_CTLR_DATA_LENGTH) #if defined(CONFIG_BT_CTLR_PHY) -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - max_tx_time = lll->max_tx_time; - max_rx_time = lll->max_rx_time; -#else max_tx_time = lll->dle.eff.max_tx_time; max_rx_time = lll->dle.eff.max_rx_time; -#endif #else /* !CONFIG_BT_CTLR_PHY */ max_tx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M); max_rx_time = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, PHY_1M); @@ -595,45 +577,11 @@ uint8_t ll_start_enc_req_send(uint16_t handle, uint8_t error_code, return BT_HCI_ERR_UNKNOWN_CONN_ID; } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if (error_code) { - if (conn->llcp_enc.refresh == 0U) { - if ((conn->llcp_req == conn->llcp_ack) || - (conn->llcp_type != LLCP_ENCRYPTION)) { - return BT_HCI_ERR_CMD_DISALLOWED; - } - - conn->llcp.encryption.error_code = error_code; - conn->llcp.encryption.state = LLCP_ENC_STATE_INPROG; - } else { - if (conn->llcp_terminate.ack != - conn->llcp_terminate.req) { - return BT_HCI_ERR_CMD_DISALLOWED; - } - - conn->llcp_terminate.reason_own = error_code; - - conn->llcp_terminate.req++; - } - } else { - if ((conn->llcp_req == conn->llcp_ack) || - (conn->llcp_type != LLCP_ENCRYPTION)) { - return BT_HCI_ERR_CMD_DISALLOWED; - } - - memcpy(&conn->llcp_enc.ltk[0], ltk, - sizeof(conn->llcp_enc.ltk)); - - conn->llcp.encryption.error_code = 0U; - conn->llcp.encryption.state = LLCP_ENC_STATE_INPROG; - } -#else /* CONFIG_BT_LL_SW_LLCP_LEGACY */ if (error_code) { return ull_cp_ltk_req_neq_reply(conn); } else { return ull_cp_ltk_req_reply(conn, ltk); } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ return 0; } @@ -698,7 +646,6 @@ static void ticker_update_latency_cancel_op_cb(uint32_t ticker_status, conn->periph.latency_cancel = 0U; } -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) #if defined(CONFIG_BT_CTLR_MIN_USED_CHAN) uint8_t ll_set_min_used_chans(uint16_t handle, uint8_t const phys, uint8_t const min_used_chans) @@ -717,4 +664,3 @@ uint8_t ll_set_min_used_chans(uint16_t handle, uint8_t const phys, return ull_cp_min_used_chans(conn, phys, min_used_chans); } #endif /* CONFIG_BT_CTLR_MIN_USED_CHAN */ -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index 7c8199c5dd4d..a27cce295ec9 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -28,9 +28,7 @@ #include "lll_peripheral_iso.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#include "ull_tx_queue.h" -#endif +#include "ll_sw/ull_tx_queue.h" #include "ull_conn_types.h" @@ -65,11 +63,7 @@ static struct ll_conn *ll_cis_get_acl_awaiting_reply(uint16_t handle, uint8_t *e for (int h = 0; h < CONFIG_BT_MAX_CONN; h++) { struct ll_conn *conn = ll_conn_get(h); -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - uint16_t cis_handle = conn->llcp_cis.cis_handle; -#else uint16_t cis_handle = ull_cp_cc_ongoing_handle(conn); -#endif if (handle == cis_handle) { /* ACL connection found */ @@ -90,11 +84,7 @@ static struct ll_conn *ll_cis_get_acl_awaiting_reply(uint16_t handle, uint8_t *e return NULL; } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - if (acl_conn->llcp_cis.state != LLCP_CIS_STATE_RSP_WAIT) { -#else if (!ull_cp_cc_awaiting_reply(acl_conn)) { -#endif LOG_ERR("Not allowed in current procedure state"); *error = BT_HCI_ERR_CMD_DISALLOWED; return NULL; @@ -110,11 +100,7 @@ uint8_t ll_cis_accept(uint16_t handle) if (acl_conn) { /* Accept request */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - acl_conn->llcp_cis.req++; -#else ull_cp_cc_accept(acl_conn); -#endif } return status; @@ -123,17 +109,12 @@ uint8_t ll_cis_accept(uint16_t handle) uint8_t ll_cis_reject(uint16_t handle, uint8_t reason) { uint8_t status = BT_HCI_ERR_SUCCESS; - -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - status = BT_HCI_ERR_CMD_DISALLOWED; -#else struct ll_conn *acl_conn = ll_cis_get_acl_awaiting_reply(handle, &status); if (acl_conn) { /* Reject request */ ull_cp_cc_reject(acl_conn, reason); } -#endif return status; } diff --git a/subsys/bluetooth/controller/ll_sw/ull_scan.c b/subsys/bluetooth/controller/ll_sw/ull_scan.c index c3d691bce995..d86337baf062 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_scan.c +++ b/subsys/bluetooth/controller/ll_sw/ull_scan.c @@ -36,10 +36,7 @@ #include "lll_conn.h" #include "lll_filter.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#include "ull_tx_queue.h" -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - +#include "ll_sw/ull_tx_queue.h" #include "ull_adv_types.h" #include "ull_filter.h" diff --git a/subsys/bluetooth/controller/ll_sw/ull_sched.c b/subsys/bluetooth/controller/ll_sw/ull_sched.c index 12ecd42d14f7..6535ffc9f9fb 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sched.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sched.c @@ -33,9 +33,7 @@ #include "lll/lll_df_types.h" #include "lll_conn.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -#include "ull_tx_queue.h" -#endif +#include "ll_sw/ull_tx_queue.h" #include "ull_adv_types.h" #include "ull_scan_types.h" diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj.conf b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj.conf deleted file mode 100644 index 62a3902ab2e0..000000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj.conf +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -CONFIG_BT=y -CONFIG_BT_SMP=y -CONFIG_BT_SIGNING=y -CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_ATT_PREPARE_COUNT=2 -CONFIG_BT_PRIVACY=y -CONFIG_BT_DEVICE_NAME="Test Database" -CONFIG_BT_DEVICE_APPEARANCE=833 -CONFIG_BT_GATT_DYNAMIC_DB=y - -CONFIG_BT_CTLR=y -CONFIG_BT_LL_SW_SPLIT=y - -CONFIG_BT_HCI_ACL_FLOW_CONTROL=y -CONFIG_BT_BUF_ACL_RX_SIZE=516 -CONFIG_BT_L2CAP_TX_MTU=512 -CONFIG_BT_DEBUG_LOG=y - -# NOTE: In order to get ACL_FLOW_CONTROL to work it is imperative that -# BT_CTRL_RX_BUFFERS is increased from its default value of 1. -CONFIG_BT_CTLR_RX_BUFFERS=3 - -# To make DEVICE Name writable... -CONFIG_BT_DEVICE_NAME_DYNAMIC=y - -CONFIG_BT_LL_SW_LLCP_LEGACY=y diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj_llcp.conf b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj_llcp.conf index baf28e68ff16..bd1d139e91e7 100644 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj_llcp.conf +++ b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj_llcp.conf @@ -26,5 +26,3 @@ CONFIG_BT_CTLR_RX_BUFFERS=3 # To make DEVICE Name writable... CONFIG_BT_DEVICE_NAME_DYNAMIC=y - -CONFIG_BT_LL_SW_LLCP=y diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut.conf b/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut.conf deleted file mode 100644 index fc351db200e9..000000000000 --- a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut.conf +++ /dev/null @@ -1,44 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -CONFIG_BT=y -CONFIG_BT_HCI_RAW=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_BROADCASTER=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_OBSERVER=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_BT_ECC=y -CONFIG_BT_TINYCRYPT_ECC=y - -# BUF_CMD_TX_SIZE must be 255 because of HCI/GEV/BV-01-C -CONFIG_BT_BUF_ACL_RX_SIZE=60 -CONFIG_BT_BUF_ACL_TX_SIZE=60 -CONFIG_BT_BUF_CMD_TX_SIZE=255 - -## -## Enabling BT_CTRL_DTM_HCI requires BT_LL_SW_SPLIT which requires BT_CTRL -## -CONFIG_BT_CTLR=y - -CONFIG_BT_LL_SW_SPLIT=y -CONFIG_BT_CTLR_CRYPTO=y -CONFIG_BT_CTLR_LE_ENC=y -CONFIG_BT_CTLR_PRIVACY=y -CONFIG_BT_CTLR_FILTER_ACCEPT_LIST=y -CONFIG_BT_CTLR_DTM_HCI=y -CONFIG_BT_CTLR_DATA_LENGTH_MAX=60 - -CONFIG_BT_LL_SW_LLCP_LEGACY=y - -# Enable extended advertising -CONFIG_BT_EXT_ADV=y -CONFIG_BT_CTLR_ADV_EXT=y -CONFIG_BT_EXT_ADV_MAX_ADV_SET=2 -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_ADV_DATA_CHAIN=y -CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=1650 -CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2 -CONFIG_BT_EXT_SCAN_BUF_SIZE=1650 -CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 -CONFIG_BT_BUF_EVT_RX_COUNT=16 -CONFIG_BT_CTLR_RX_BUFFERS=9 diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut_llcp.conf b/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut_llcp.conf index 6c5b2c2c3c26..4ec0d70242cd 100644 --- a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut_llcp.conf +++ b/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut_llcp.conf @@ -28,7 +28,6 @@ CONFIG_BT_CTLR_FILTER_ACCEPT_LIST=y CONFIG_BT_CTLR_DTM_HCI=y CONFIG_BT_CTLR_DATA_LENGTH_MAX=60 -CONFIG_BT_LL_SW_LLCP=y CONFIG_BT_CTLR_ADVANCED_FEATURES=y # LLCP Refactored controller does not support Advanced Scheduling yet CONFIG_BT_CTLR_SCHED_ADVANCED=n diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst.conf b/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst.conf deleted file mode 100644 index 276796a73636..000000000000 --- a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst.conf +++ /dev/null @@ -1,44 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -CONFIG_BT=y -CONFIG_BT_HCI_RAW=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_BT_ECC=y -CONFIG_BT_TINYCRYPT_ECC=y - -# BUF_CMD_TX_SIZE must be 255 because of HCI/GEV/BV-01-C -CONFIG_BT_BUF_ACL_RX_SIZE=60 -CONFIG_BT_BUF_ACL_TX_SIZE=60 -CONFIG_BT_BUF_CMD_TX_SIZE=255 - -## -## Enabling BT_CTRL_DTM_HCI requires BT_LL_SW which requires BT_CTRL -## -CONFIG_BT_CTLR=y - -CONFIG_BT_LL_SW_SPLIT=y -CONFIG_BT_CTLR_CRYPTO=y -CONFIG_BT_CTLR_LE_ENC=y -CONFIG_BT_CTLR_PRIVACY=y -CONFIG_BT_CTLR_FILTER_ACCEPT_LIST=y -CONFIG_BT_CTLR_DTM_HCI=y -CONFIG_BT_CTLR_DATA_LENGTH_MAX=60 - -CONFIG_BT_LL_SW_LLCP_LEGACY=y -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_PARAM_CHECK=n - -# Enable extended advertising -CONFIG_BT_EXT_ADV=y -CONFIG_BT_CTLR_ADV_EXT=y -CONFIG_BT_EXT_ADV_MAX_ADV_SET=2 -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_ADV_DATA_CHAIN=y -CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=1650 -CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2 -CONFIG_BT_EXT_SCAN_BUF_SIZE=1650 -CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 -CONFIG_BT_BUF_EVT_RX_COUNT=16 -CONFIG_BT_CTLR_RX_BUFFERS=9 diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst_llcp.conf b/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst_llcp.conf index 80fff108da77..2df7f210b6b0 100644 --- a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst_llcp.conf +++ b/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst_llcp.conf @@ -26,7 +26,6 @@ CONFIG_BT_CTLR_FILTER_ACCEPT_LIST=y CONFIG_BT_CTLR_DTM_HCI=y CONFIG_BT_CTLR_DATA_LENGTH_MAX=60 -CONFIG_BT_LL_SW_LLCP=y CONFIG_BT_CTLR_ADVANCED_FEATURES=y # LLCP Refactored controller does not support Advanced Scheduling yet CONFIG_BT_CTLR_SCHED_ADVANCED=n diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.sh deleted file mode 100755 index 96b3a056fc38..000000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# GAP regression tests based on the EDTTool -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -export SIMULATION_ID="edtt_gap" -export TEST_FILE=${CWD}"/gap.test_list" -export TEST_MODULE="gap_verification" -export PRJ_CONF_1="prj_dut_conf" -export PRJ_CONF_2="prj_tst_conf" - -${CWD}/_controller_tests_inner.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.test_list deleted file mode 100644 index 19ed590e4d7a..000000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.test_list +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -GAP/ADV/BV-01-C -GAP/ADV/BV-02-C -GAP/ADV/BV-03-C -GAP/ADV/BV-04-C -GAP/ADV/BV-05-C -GAP/ADV/BV-08-C -GAP/ADV/BV-09-C -GAP/ADV/BV-10-C -GAP/ADV/BV-11-C -GAP/ADV/BV-12-C -GAP/ADV/BV-13-C -GAP/ADV/BV-14-C -GAP/ADV/BV-15-C -GAP/ADV/BV-16-C -GAP/ADV/BV-17-C -GAP/CONN/ACEP/BV-01-C -GAP/CONN/ACEP/BV-03-C -GAP/CONN/ACEP/BV-04-C -GAP/CONN/DCON/BV-01-C -GAP/CONN/GCEP/BV-01-C -GAP/CONN/GCEP/BV-02-C -GAP/CONN/GCEP/BV-05-C -GAP/CONN/GCEP/BV-06-C -GAP/CONN/CPUP/BV-01-C -GAP/CONN/CPUP/BV-02-C -GAP/CONN/CPUP/BV-03-C -GAP/CONN/CPUP/BV-04-C -GAP/CONN/CPUP/BV-05-C -GAP/CONN/CPUP/BV-06-C -GAP/CONN/NCON/BV-01-C -GAP/CONN/NCON/BV-02-C -GAP/CONN/NCON/BV-03-C -GAP/CONN/UCON/BV-01-C -GAP/CONN/UCON/BV-02-C -GAP/CONN/UCON/BV-03-C -GAP/DISC/GENM/BV-01-C -GAP/DISC/GENM/BV-02-C -GAP/DISC/GENM/BV-03-C -GAP/DISC/GENM/BV-04-C -GAP/DISC/GENP/BV-01-C -GAP/DISC/GENP/BV-02-C -GAP/DISC/GENP/BV-04-C -GAP/DISC/GENP/BV-05-C -GAP/DISC/LIMM/BV-01-C -GAP/DISC/LIMM/BV-02-C -GAP/DISC/LIMM/BV-03-C -GAP/DISC/LIMM/BV-04-C -GAP/DISC/LIMP/BV-01-C -GAP/DISC/LIMP/BV-02-C -GAP/DISC/LIMP/BV-04-C -GAP/DISC/LIMP/BV-05-C -GAP/DISC/NONM/BV-01-C -GAP/DISC/NONM/BV-02-C -GAP/DISC/RPA/BV-01-C diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.sh deleted file mode 100755 index d8ba683a15d8..000000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# GATT regression tests based on the EDTTool -SIMULATION_ID="edtt_gatt" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 300 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${EDTT_PATH:?EDTT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${EDTT_PATH} - -Execute ./src/edttool.py -s=${SIMULATION_ID} -d=0 --transport bsim \ - -T gatt_verification -C "${CWD}/gatt.test_list" -v=${VERBOSITY_LEVEL} \ - -D=2 -devs 1 2 -RxWait=2.5e3 - -cd ${BSIM_OUT_PATH}/bin - -Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_edtt_hci_test_app_prj_tst_conf\ - -s=${SIMULATION_ID} -d=1 -v=${VERBOSITY_LEVEL} -RealEncryption=1 - -Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_edtt_gatt_test_app_prj_conf\ - -s=${SIMULATION_ID} -d=2 -v=${VERBOSITY_LEVEL} -RealEncryption=1 - -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=3 -sim_length=3600e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.test_list deleted file mode 100644 index ad5062aea97c..000000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.test_list +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -GAP/GAT/BV-01-C -GAP/GAT/BV-04-C -GAP/IDLE/NAMP/BV-01-C -GATT/SR/GAC/BV-01-C -GATT/SR/GAD/BV-01-C -GATT/SR/GAD/BV-02-C -GATT/SR/GAD/BV-03-C -GATT/SR/GAD/BV-04-C -GATT/SR/GAD/BV-05-C -GATT/SR/GAD/BV-06-C -GATT/SR/GAR/BV-01-C -GATT/SR/GAR/BI-01-C -GATT/SR/GAR/BI-02-C -GATT/SR/GAR/BI-03-C -GATT/SR/GAR/BI-04-C -GATT/SR/GAR/BV-03-C -GATT/SR/GAR/BI-06-C -GATT/SR/GAR/BI-07-C -GATT/SR/GAR/BI-09-C -GATT/SR/GAR/BI-10-C -GATT/SR/GAR/BI-11-C -GATT/SR/GAR/BV-04-C -GATT/SR/GAR/BI-12-C -GATT/SR/GAR/BI-13-C -GATT/SR/GAR/BI-14-C -GATT/SR/GAR/BI-15-C -GATT/SR/GAR/BI-16-C -GATT/SR/GAR/BI-17-C -GATT/SR/GAR/BV-05-C -GATT/SR/GAR/BI-18-C -GATT/SR/GAR/BI-19-C -GATT/SR/GAR/BI-20-C -GATT/SR/GAR/BI-21-C -GATT/SR/GAR/BI-22-C -GATT/SR/GAR/BV-06-C -GATT/SR/GAR/BV-07-C -GATT/SR/GAW/BV-01-C -GATT/SR/GAW/BV-03-C -GATT/SR/GAW/BI-02-C -GATT/SR/GAW/BI-03-C -GATT/SR/GAW/BI-04-C -GATT/SR/GAW/BI-05-C -GATT/SR/GAW/BI-06-C -GATT/SR/GAW/BV-05-C -GATT/SR/GAW/BI-07-C -GATT/SR/GAW/BI-08-C -GATT/SR/GAW/BI-09-C -GATT/SR/GAW/BI-11-C -GATT/SR/GAW/BI-12-C -GATT/SR/GAW/BI-13-C -GATT/SR/GAW/BV-08-C -GATT/SR/GAW/BV-09-C -GATT/SR/GAW/BV-11-C -GATT/SR/GAW/BI-32-C -GATT/SR/GAW/BI-33-C -GATT/SR/GAN/BV-01-C -GATT/SR/GAI/BV-01-C -GATT/SR/GAS/BV-01-C -GATT/SR/UNS/BI-01-C -GATT/SR/UNS/BI-02-C -GATT/SR/GPA/BV-01-C -GATT/SR/GPA/BV-02-C -GATT/SR/GPA/BV-03-C -GATT/SR/GPA/BV-04-C -GATT/SR/GPA/BV-05-C -GATT/SR/GPA/BV-06-C -GATT/SR/GPA/BV-07-C -GATT/SR/GPA/BV-08-C -GATT/SR/GPA/BV-12-C diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.sh deleted file mode 100755 index dbeb16c61547..000000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# HCI regression tests based on the EDTTool -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -export SIMULATION_ID="edtt_hci" -export TEST_FILE=${CWD}"/hci.test_list" -export TEST_MODULE="hci_verification" -export PRJ_CONF_1="prj_dut_conf" -export PRJ_CONF_2="prj_tst_conf" - -${CWD}/_controller_tests_inner.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.test_list deleted file mode 100644 index b2e318821043..000000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.test_list +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -HCI/CCO/BV-07-C -HCI/CCO/BV-09-C -HCI/CCO/BV-10-C -HCI/CCO/BV-11-C -HCI/CCO/BV-12-C -HCI/CCO/BV-13-C -HCI/CCO/BV-14-C -HCI/CCO/BV-15-C -HCI/CCO/BV-18-C -HCI/CFC/BV-02-C -HCI/CIN/BV-01-C -HCI/CIN/BV-03-C -HCI/CIN/BV-04-C -HCI/CIN/BV-06-C -HCI/CIN/BV-09-C -HCI/CM/BV-01-C -HCI/CM/BV-02-C -HCI/CM/BV-03-C -HCI/DDI/BI-02-C -HCI/DDI/BV-03-C -HCI/DDI/BV-04-C -HCI/DDI/BI-63-C -HCI/DDI/BI-65-C -HCI/DSU/BV-02-C -HCI/DSU/BV-03-C -HCI/DSU/BV-04-C -HCI/DSU/BV-05-C -HCI/DSU/BV-06-C -#HCI/GEV/BV-01-C # Test fails since it assumes extended advertising is not supported -HCI/HFC/BV-04-C diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.1.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.1.sh deleted file mode 100755 index 43ccb4194158..000000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.1.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# LL regression tests based on the EDTTool (part 1) - -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -export SIMULATION_ID="edtt_ll_set1" -export TEST_FILE=${CWD}"/ll.set1.test_list" -export TEST_MODULE="ll_verification" -export PRJ_CONF_1="prj_dut_conf" -export PRJ_CONF_2="prj_tst_conf" - -${CWD}/_controller_tests_inner.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.2.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.2.sh deleted file mode 100755 index f99ec00e9691..000000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.2.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# LL regression tests based on the EDTTool (part 2) - -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -export SIMULATION_ID="edtt_ll_set2" -export TEST_FILE=${CWD}"/ll.set2.test_list" -export TEST_MODULE="ll_verification" -export PRJ_CONF_1="prj_dut_conf" -export PRJ_CONF_2="prj_tst_conf" - -${CWD}/_controller_tests_inner.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set1.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set1.test_list deleted file mode 100644 index 5784eb0b063b..000000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set1.test_list +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -LL/CON/ADV/BV-01-C -LL/CON/ADV/BV-04-C -LL/CON/ADV/BV-05-C -LL/CON/ADV/BV-06-C -LL/CON/ADV/BV-09-C -LL/CON/ADV/BV-10-C -LL/CON/ADV/BV-12-C -LL/CON/ADV/BV-14-C -LL/CON/ADV/BV-15-C -LL/CON/INI/BV-01-C -LL/CON/INI/BV-02-C -LL/CON/INI/BV-06-C -LL/CON/INI/BV-07-C -LL/CON/INI/BV-08-C -LL/CON/INI/BV-09-C -LL/CON/INI/BV-10-C -LL/CON/INI/BV-11-C -LL/CON/INI/BV-12-C -LL/CON/INI/BV-16-C -LL/CON/INI/BV-17-C -LL/CON/INI/BV-18-C -LL/CON/INI/BV-19-C -LL/CON/INI/BV-20-C -LL/CON/INI/BV-21-C -LL/CON/INI/BV-23-C -LL/CON/INI/BV-24-C -LL/CON/CEN/BI-06-C -LL/CON/CEN/BV-03-C -LL/CON/CEN/BV-04-C -LL/CON/CEN/BV-05-C -LL/CON/CEN/BV-07-C -LL/CON/CEN/BV-08-C -LL/CON/CEN/BV-09-C -LL/CON/CEN/BV-13-C -LL/CON/CEN/BV-20-C -LL/CON/CEN/BV-21-C -LL/CON/CEN/BV-23-C -LL/CON/CEN/BV-24-C -LL/CON/CEN/BV-25-C -#LL/CON/CEN/BV-26-C # This test case is not valid, and will fail with CPR cache -LL/CON/CEN/BV-27-C -LL/CON/CEN/BV-29-C -LL/CON/CEN/BV-30-C -LL/CON/CEN/BV-34-C -LL/CON/CEN/BV-35-C -LL/CON/CEN/BV-41-C -LL/CON/CEN/BV-43-C -## With updated EDTT, this now fails due to error in legacy DLE handling. Fixed in refactored LLCP -#LL/CON/CEN/BV-73-C -#LL/CON/CEN/BV-74-C # Needs testcase implementation update -## With updated EDTT, this now fails due to error in legacy DLE handling. Fixed in refactored LLCP -#LL/CON/CEN/BV-76-C -#LL/CON/CEN/BV-77-C # Needs testcase implementation update -LL/CON/PER/BI-08-C -LL/CON/PER/BV-04-C -LL/CON/PER/BV-05-C -LL/CON/PER/BV-06-C -LL/CON/PER/BV-10-C -LL/CON/PER/BV-11-C -LL/CON/PER/BV-12-C -LL/CON/PER/BV-14-C -LL/CON/PER/BV-19-C -LL/CON/PER/BV-20-C -LL/CON/PER/BV-22-C -LL/CON/PER/BV-24-C -LL/CON/PER/BV-25-C -LL/CON/PER/BV-26-C -LL/CON/PER/BV-27-C diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set2.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set2.test_list deleted file mode 100644 index 5453c6c06305..000000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set2.test_list +++ /dev/null @@ -1,75 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -LL/CON/PER/BV-29-C -LL/CON/PER/BV-33-C -LL/CON/PER/BV-34-C -LL/CON/PER/BV-40-C -LL/CON/PER/BV-42-C -#LL/CON/PER/BV-77-C # Needs testcase implementation update -#LL/CON/PER/BV-78-C # Needs testcase implementation update -#LL/CON/PER/BV-80-C # Needs testcase implementation update -#LL/CON/PER/BV-81-C # Needs testcase implementation update -LL/DDI/ADV/BI-05-C -LL/DDI/ADV/BI-06-C -LL/DDI/ADV/BV-01-C -LL/DDI/ADV/BV-02-C -LL/DDI/ADV/BV-03-C -LL/DDI/ADV/BV-04-C -LL/DDI/ADV/BV-05-C -LL/DDI/ADV/BV-06-C -LL/DDI/ADV/BV-07-C -LL/DDI/ADV/BV-08-C -LL/DDI/ADV/BV-09-C -LL/DDI/ADV/BV-11-C -LL/DDI/ADV/BV-15-C -LL/DDI/ADV/BV-16-C -LL/DDI/ADV/BV-17-C -LL/DDI/ADV/BV-18-C -LL/DDI/ADV/BV-19-C -LL/DDI/ADV/BV-20-C -LL/DDI/ADV/BV-22-C -#LL/DDI/ADV/BV-27-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -LL/DDI/ADV/BV-28-C -#LL/DDI/ADV/BV-45-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -#LL/DDI/ADV/BV-47-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -#LL/DDI/ADV/BV-49-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -#LL/DDI/ADV/BV-52-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -LL/DDI/SCN/BV-01-C -LL/DDI/SCN/BV-02-C -LL/DDI/SCN/BV-03-C -LL/DDI/SCN/BV-04-C -LL/DDI/SCN/BV-05-C -LL/DDI/SCN/BV-10-C -LL/DDI/SCN/BV-11-C -LL/DDI/SCN/BV-12-C -LL/DDI/SCN/BV-13-C -LL/DDI/SCN/BV-14-C -LL/DDI/SCN/BV-15-C -LL/DDI/SCN/BV-16-C -LL/DDI/SCN/BV-17-C -LL/DDI/SCN/BV-18-C -LL/DDI/SCN/BV-26-C -LL/DDI/SCN/BV-28-C -LL/SEC/ADV/BV-02-C -LL/SEC/ADV/BV-03-C -LL/SEC/ADV/BV-04-C -LL/SEC/ADV/BV-05-C -LL/SEC/ADV/BV-06-C -LL/SEC/ADV/BV-08-C -LL/SEC/ADV/BV-09-C -LL/SEC/ADV/BV-10-C -LL/SEC/ADV/BV-11-C -LL/SEC/ADV/BV-12-C -LL/SEC/ADV/BV-13-C -LL/SEC/ADV/BV-14-C -LL/SEC/ADV/BV-15-C -LL/SEC/ADV/BV-16-C -LL/SEC/ADV/BV-17-C -LL/SEC/ADV/BV-18-C -LL/SEC/ADV/BV-20-C -LL/SEC/SCN/BV-01-C -LL/TIM/ADV/BV-03-C -LL/TIM/ADV/BV-04-C -LL/TIM/ADV/BV-05-C -LL/TIM/ADV/BV-07-C diff --git a/tests/bluetooth/controller/mock_ctrl/src/ull_conn_iso.c b/tests/bluetooth/controller/mock_ctrl/src/ull_conn_iso.c index 77d4c4e5269b..1914e156fcf8 100644 --- a/tests/bluetooth/controller/mock_ctrl/src/ull_conn_iso.c +++ b/tests/bluetooth/controller/mock_ctrl/src/ull_conn_iso.c @@ -27,9 +27,7 @@ #include "lll/lll_df_types.h" #include "lll_conn.h" -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) #include "ull_tx_queue.h" -#endif #include "isoal.h" #include "ull_iso_types.h" diff --git a/tests/bluetooth/df/connection_cte_req/prj.conf b/tests/bluetooth/df/connection_cte_req/prj.conf index 4670aad761b4..9796e6a37632 100644 --- a/tests/bluetooth/df/connection_cte_req/prj.conf +++ b/tests/bluetooth/df/connection_cte_req/prj.conf @@ -11,9 +11,6 @@ CONFIG_BT_GATT_CLIENT=y CONFIG_BT_CTLR=y CONFIG_BT_LL_SW_SPLIT=y -# Enable new implementation of LLCP -CONFIG_BT_LL_SW_LLCP=y - # Enable Direction Finding Feature including AoA and AoD CONFIG_BT_DF=y CONFIG_BT_CTLR_DF_CTE_RX=y diff --git a/tests/bluetooth/df/connection_cte_tx_params/prj.conf b/tests/bluetooth/df/connection_cte_tx_params/prj.conf index 3dcda1434799..9284e101e44c 100644 --- a/tests/bluetooth/df/connection_cte_tx_params/prj.conf +++ b/tests/bluetooth/df/connection_cte_tx_params/prj.conf @@ -10,9 +10,6 @@ CONFIG_BT_CENTRAL=y CONFIG_BT_CTLR=y CONFIG_BT_LL_SW_SPLIT=y -# Enable new implementation of LLCP -CONFIG_BT_LL_SW_LLCP=y - # Enable Direction Finding Feature including AoA and AoD CONFIG_BT_DF=y CONFIG_BT_CTLR_DF=y diff --git a/tests/bluetooth/init/prj_llcp.conf b/tests/bluetooth/init/prj_llcp.conf index 6c0d529cd923..ffa527533638 100644 --- a/tests/bluetooth/init/prj_llcp.conf +++ b/tests/bluetooth/init/prj_llcp.conf @@ -14,7 +14,6 @@ CONFIG_BT_BREDR=n CONFIG_FLASH=y CONFIG_SOC_FLASH_NRF_RADIO_SYNC_TICKER=y CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_LL_SW_LLCP=y CONFIG_ZTEST=y CONFIG_ZTEST_NEW_API=y From f6172f315946014f141ae2cbe3e9983ea0a2de05 Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Wed, 18 Jan 2023 11:27:55 +0100 Subject: [PATCH 0347/1906] Blueotooth: controller: removed delayed notification code The code that was added for delaying notifications to the host, which was only implemented for legacy controller, is removed in this commit Signed-off-by: Andries Kruithof --- subsys/bluetooth/controller/ll_sw/lll_conn.h | 8 -- .../controller/ll_sw/nordic/lll/lll_conn.c | 7 -- .../bluetooth/controller/ll_sw/ull_central.c | 7 -- subsys/bluetooth/controller/ll_sw/ull_conn.c | 95 ------------------- 4 files changed, 117 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll_conn.h b/subsys/bluetooth/controller/ll_sw/lll_conn.h index 13666d869d6a..f18e46567868 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_conn.h +++ b/subsys/bluetooth/controller/ll_sw/lll_conn.h @@ -139,14 +139,6 @@ struct lll_conn { #endif /* CONFIG_BT_CTLR_CONN_RSSI_EVENT */ #endif /* CONFIG_BT_CTLR_CONN_RSSI */ -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) -#define RX_HOLD_MASK 3U -#define RX_HOLD_REQ 1U -#define RX_HOLD_ACK 2U - uint8_t rx_hold_req; - uint8_t rx_hold_ack; -#endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - #if defined(CONFIG_BT_CTLR_CONN_META) struct lll_conn_meta conn_meta; #endif /* CONFIG_BT_CTLR_CONN_META */ diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c index a774346e9beb..b38ff0ff8dc1 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c @@ -410,13 +410,6 @@ void lll_conn_isr_rx(void *param) is_ull_rx = 0U; -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) - if (((lll->rx_hold_req - lll->rx_hold_ack) & RX_HOLD_MASK) == - RX_HOLD_REQ) { - lll->rx_hold_ack--; - } -#endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - if (tx_release) { LL_ASSERT(lll->handle != 0xFFFF); diff --git a/subsys/bluetooth/controller/ll_sw/ull_central.c b/subsys/bluetooth/controller/ll_sw/ull_central.c index 5ea7b5926bb5..a8f70f189b75 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central.c @@ -283,13 +283,6 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, conn->apto_reload; #endif /* CONFIG_BT_CTLR_LE_PING */ -/* TODO: verify if we need to enable CTLR_RX_ENQUEUE_HOLD */ -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) - conn->llcp_rx_hold = NULL; - conn_lll->rx_hold_req = 0U; - conn_lll->rx_hold_ack = 0U; -#endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - /* Re-initialize the control procedure data structures */ ull_llcp_init(conn); diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index 49a5464b2f61..c3fa89b586e7 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -74,10 +74,6 @@ LOG_MODULE_REGISTER(bt_ctlr_ull_conn); static int init_reset(void); -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) -static bool rx_hold_is_done(struct ll_conn *conn); -static void rx_hold_flush(struct ll_conn *conn); -#endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ #if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) static void tx_demux_sched(struct ll_conn *conn); #endif /* CONFIG_BT_CTLR_LOW_LAT_ULL */ @@ -850,13 +846,6 @@ int ull_conn_rx(memq_link_t *link, struct node_rx_pdu **rx) return 0; } -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) - /* TODO: is this required for refactored LLCP? */ - if (conn->llcp_rx_hold && rx_hold_is_done(conn)) { - rx_hold_flush(conn); - } -#endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - ull_cp_tx_ntf(conn); pdu_rx = (void *)(*rx)->pdu; @@ -952,19 +941,6 @@ void ull_conn_done(struct node_rx_event_done *done) return; } -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) - if (conn->llcp_rx_hold && rx_hold_is_done(conn)) { - rx_hold_flush(conn); - - /* For both CONFIG_BT_CTLR_LOW_LAT_ULL or when done events have - * separate mayfly, explicitly trigger rx_demux mayfly. In the - * later we could be here without any node rx or tx ack being - * processed hence an explicit ll_rx_sched call is necessary. - */ - ll_rx_sched(); - } -#endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - ull_cp_tx_ntf(conn); #if defined(CONFIG_BT_CTLR_LE_ENC) @@ -1470,12 +1446,6 @@ void ull_conn_tx_ack(uint16_t handle, memq_link_t *link, struct node_tx *tx) if (handle != LLL_HANDLE_INVALID) { struct ll_conn *conn = ll_conn_get(handle); -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) - if (conn->llcp_rx_hold && rx_hold_is_done(conn)) { - rx_hold_flush(conn); - } -#endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - ull_cp_tx_ack(conn, tx); } @@ -1496,14 +1466,6 @@ void ull_conn_tx_ack(uint16_t handle, memq_link_t *link, struct node_tx *tx) pdu_tx->ll_id = PDU_DATA_LLID_RESV; } else { LL_ASSERT(handle != LLL_HANDLE_INVALID); - -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) - struct ll_conn *conn = ll_conn_get(handle); - - if (conn->llcp_rx_hold && rx_hold_is_done(conn)) { - rx_hold_flush(conn); - } -#endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ } ll_tx_ack_put(handle, tx); @@ -1642,63 +1604,6 @@ static int init_reset(void) return 0; } -#if defined(CONFIG_BT_CTLR_RX_ENQUEUE_HOLD) -static void rx_hold_put(struct ll_conn *conn, memq_link_t *link, - struct node_rx_pdu *rx) -{ - struct node_rx_pdu *rx_last; - struct lll_conn *lll; - - link->mem = NULL; - rx->hdr.link = link; - - rx_last = conn->llcp_rx_hold; - while (rx_last && rx_last->hdr.link && rx_last->hdr.link->mem) { - rx_last = rx_last->hdr.link->mem; - } - - if (rx_last) { - rx_last->hdr.link->mem = rx; - } else { - conn->llcp_rx_hold = rx; - } - - lll = &conn->lll; - if (lll->rx_hold_req == lll->rx_hold_ack) { - lll->rx_hold_req++; - } -} - -static bool rx_hold_is_done(struct ll_conn *conn) -{ - return ((conn->lll.rx_hold_req - - conn->lll.rx_hold_ack) & RX_HOLD_MASK) == RX_HOLD_ACK; -} - -static void rx_hold_flush(struct ll_conn *conn) -{ - struct node_rx_pdu *rx; - struct lll_conn *lll; - - rx = conn->llcp_rx_hold; - do { - struct node_rx_hdr *hdr; - - /* traverse to next rx node */ - hdr = &rx->hdr; - rx = hdr->link->mem; - - /* enqueue rx node towards Thread */ - ll_rx_put(hdr->link, hdr); - } while (rx); - - conn->llcp_rx_hold = NULL; - lll = &conn->lll; - lll->rx_hold_req = 0U; - lll->rx_hold_ack = 0U; -} -#endif /* CONFIG_BT_CTLR_RX_ENQUEUE_HOLD */ - #if !defined(CONFIG_BT_CTLR_LOW_LAT_ULL) static void tx_demux_sched(struct ll_conn *conn) { From 729c3e3d833e4d9848f23d0b0b02d367131bd9b2 Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Thu, 19 Jan 2023 14:15:30 +0100 Subject: [PATCH 0348/1906] Bluetooth: controller: remove code related to advanced scheduling This commit removes the code related to advanced scheduling from ull_sched.c, since this code only works for the legacy controller. Implementing advanced scheduling for the refactored LLCP is tracked in its own issue Signed-off-by: Andries Kruithof --- subsys/bluetooth/controller/ll_sw/ull_sched.c | 390 +----------------- 1 file changed, 15 insertions(+), 375 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_sched.c b/subsys/bluetooth/controller/ll_sw/ull_sched.c index 6535ffc9f9fb..611ca68e837f 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sched.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sched.c @@ -47,20 +47,12 @@ #include "hal/debug.h" -#if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -static void win_offset_calc(struct ll_conn *conn_curr, uint8_t is_select, - uint32_t *ticks_to_offset_next, - uint16_t conn_interval, uint8_t *offset_max, - uint8_t *win_offset); -#endif -#endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ -#if defined(CONFIG_BT_CONN) && (defined(CONFIG_BT_CENTRAL) || defined(CONFIG_BT_LL_SW_LLCP_LEGACY)) +#if defined(CONFIG_BT_CONN) && defined(CONFIG_BT_CENTRAL) static void after_cen_offset_get(uint16_t conn_interval, uint32_t ticks_slot, uint32_t ticks_anchor, uint32_t *win_offset_us); -#endif /* CONFIG_BT_CONN && (CONFIG_BT_CENTRAL || CONFIG_BT_LL_SW_LLCP_LEGACY) */ +#endif /* CONFIG_BT_CONN && CONFIG_BT_CENTRAL */ typedef struct ull_hdr *(*ull_hdr_get_func)(uint8_t ticker_id, uint32_t *ticks_slot); @@ -226,13 +218,6 @@ void ull_sched_mfy_win_offset_use(void *param) struct ll_conn *conn = param; uint32_t ticks_slot_overhead; - /* - * TODO: update when updating the connection update procedure - */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - uint16_t win_offset; -#endif - if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { ticks_slot_overhead = MAX(conn->ull.ticks_active_to_start, conn->ull.ticks_prepare_to_start); @@ -241,21 +226,10 @@ void ull_sched_mfy_win_offset_use(void *param) } /* - * TODO: update when updating the connection update procedure + * TODO: update calculationg of the win_offset + * when updating the connection update procedure + * see the legacy code from Zephyr v3.2 for inspiration */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - after_cen_offset_get(conn->lll.interval, - (ticks_slot_overhead + conn->ull.ticks_slot), - conn->llcp.conn_upd.ticks_anchor, - &conn->llcp_cu.win_offset_us); - - win_offset = conn->llcp_cu.win_offset_us / CONN_INT_UNIT_US; - - sys_put_le16(win_offset, (void *)conn->llcp.conn_upd.pdu_win_offset); - - /* move to offset calculated state */ - conn->llcp_cu.state = LLCP_CUI_STATE_OFFS_RDY; -#endif } #if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ) @@ -264,38 +238,12 @@ void ull_sched_mfy_free_win_offset_calc(void *param) uint32_t ticks_to_offset_default = 0U; uint32_t *ticks_to_offset_next; - /* - * TODO: update when updating the connection update procedure - */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - uint8_t offset_max = 6U; - struct ll_conn *conn = param; -#endif - ticks_to_offset_next = &ticks_to_offset_default; /* * TODO: update when updating the connection update procedure + * see the legacy code from Zephyr v3.2 for inspiration */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - -#if defined(CONFIG_BT_PERIPHERAL) - if (conn->lll.role) { - conn->llcp_conn_param.ticks_to_offset_next = - conn->periph.ticks_to_offset; - - ticks_to_offset_next = - &conn->llcp_conn_param.ticks_to_offset_next; - } -#endif /* CONFIG_BT_PERIPHERAL */ - - win_offset_calc(conn, 0, ticks_to_offset_next, - conn->llcp_conn_param.interval_max, &offset_max, - (void *)conn->llcp_conn_param.pdu_win_offset0); - - /* move to offset calculated state */ - conn->llcp_conn_param.state = LLCP_CPR_STATE_OFFS_RDY; -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ } void ull_sched_mfy_win_offset_select(void *param) @@ -303,331 +251,23 @@ void ull_sched_mfy_win_offset_select(void *param) #define OFFSET_S_MAX 6 #define OFFSET_M_MAX 6 -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - uint16_t win_offset_m[OFFSET_M_MAX] = {0, }; - uint8_t offset_m_max = OFFSET_M_MAX; - struct ll_conn *conn = param; - uint8_t offset_index_s = 0U; - uint8_t has_offset_s = 0U; - uint16_t win_offset_s; - uint32_t ticks_to_offset; -#endif - /* - * TODO: update when updating the connection update procedure + * TODO: update calculation of win_offset when + * updating the connection update procedure + * see the legacy code from Zephyr v3.2 for inspiration */ -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - - ticks_to_offset = HAL_TICKER_US_TO_TICKS(conn->llcp_conn_param.offset0 * - CONN_INT_UNIT_US); - - win_offset_calc(conn, 1, &ticks_to_offset, - conn->llcp_conn_param.interval_max, &offset_m_max, - (void *)win_offset_m); - - while (offset_index_s < OFFSET_S_MAX) { - uint8_t offset_index_m = 0U; - - win_offset_s = - sys_get_le16((uint8_t *)&conn->llcp_conn_param.offset0 + - (sizeof(uint16_t) * offset_index_s)); - - while (offset_index_m < offset_m_max) { - if (win_offset_s != 0xffff) { - if (win_offset_s == - win_offset_m[offset_index_m]) { - break; - } - - has_offset_s = 1U; - } - - offset_index_m++; - } - - if (offset_index_m < offset_m_max) { - break; - } - - offset_index_s++; - } - - if (offset_index_s < OFFSET_S_MAX) { - conn->llcp_cu.win_offset_us = win_offset_s * CONN_INT_UNIT_US; - sys_put_le16(win_offset_s, - (void *)conn->llcp.conn_upd.pdu_win_offset); - /* move to offset calculated state */ - conn->llcp_cu.state = LLCP_CUI_STATE_OFFS_RDY; - } else if (!has_offset_s) { - conn->llcp_cu.win_offset_us = win_offset_m[0] * - CONN_INT_UNIT_US; - sys_put_le16(win_offset_m[0], - (void *)conn->llcp.conn_upd.pdu_win_offset); - /* move to offset calculated state */ - conn->llcp_cu.state = LLCP_CUI_STATE_OFFS_RDY; - } else { - struct pdu_data *pdu_ctrl_tx; - - /* send reject_ind_ext */ - pdu_ctrl_tx = CONTAINER_OF(conn->llcp.conn_upd.pdu_win_offset, - struct pdu_data, - llctrl.conn_update_ind.win_offset); - pdu_ctrl_tx->ll_id = PDU_DATA_LLID_CTRL; - pdu_ctrl_tx->len = - offsetof(struct pdu_data_llctrl, reject_ext_ind) + - sizeof(struct pdu_data_llctrl_reject_ext_ind); - pdu_ctrl_tx->llctrl.opcode = - PDU_DATA_LLCTRL_TYPE_REJECT_EXT_IND; - pdu_ctrl_tx->llctrl.reject_ext_ind.reject_opcode = - PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ; - pdu_ctrl_tx->llctrl.reject_ext_ind.error_code = - BT_HCI_ERR_UNSUPP_LL_PARAM_VAL; - /* move to conn param reject */ - conn->llcp_cu.state = LLCP_CUI_STATE_REJECT; - } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ - #undef OFFSET_S_MAX #undef OFFSET_M_MAX } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) -static void win_offset_calc(struct ll_conn *conn_curr, uint8_t is_select, - uint32_t *ticks_to_offset_next, - uint16_t conn_interval, uint8_t *offset_max, - uint8_t *win_offset) -{ - uint32_t ticks_prepare_reduced = 0U; - uint32_t ticks_to_expire_prev; - uint32_t ticks_slot_abs_prev; - uint32_t ticks_slot_abs = 0U; - uint32_t ticks_anchor_prev; - uint32_t ticks_to_expire; - uint8_t ticker_id_other; - uint8_t ticker_id_prev; - uint32_t ticks_anchor; - uint8_t offset_index; - uint8_t ticker_id; - uint16_t offset; - -#if defined(CONFIG_BT_CTLR_LOW_LAT) -#if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) - if (conn_curr->ull.ticks_prepare_to_start & XON_BITMASK) { - uint32_t ticks_prepare_to_start = - MAX(conn_curr->ull.ticks_active_to_start, - conn_curr->ull.ticks_preempt_to_start); - - ticks_slot_abs = conn_curr->ull.ticks_prepare_to_start & - ~XON_BITMASK; - ticks_prepare_reduced = ticks_slot_abs - ticks_prepare_to_start; - } else -#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */ - { - uint32_t ticks_prepare_to_start = - MAX(conn_curr->ull.ticks_active_to_start, - conn_curr->ull.ticks_prepare_to_start); - - ticks_slot_abs = ticks_prepare_to_start; - } -#endif - - ticks_slot_abs += conn_curr->ull.ticks_slot; - - if (conn_curr->lll.role) { - ticks_slot_abs += HAL_TICKER_US_TO_TICKS(EVENT_TIES_US); - } - - ticker_id = ticker_id_prev = ticker_id_other = TICKER_NULL; - ticks_to_expire = ticks_to_expire_prev = ticks_anchor = - ticks_anchor_prev = offset_index = offset = 0U; - ticks_slot_abs_prev = 0U; - do { - uint32_t volatile ret_cb; - struct ll_conn *conn; - uint32_t ret; - bool success; - - ret_cb = TICKER_STATUS_BUSY; - ret = ticker_next_slot_get(TICKER_INSTANCE_ID_CTLR, - TICKER_USER_ID_ULL_LOW, - &ticker_id, &ticks_anchor, - &ticks_to_expire, ticker_op_cb, - (void *)&ret_cb); - if (ret == TICKER_STATUS_BUSY) { - while (ret_cb == TICKER_STATUS_BUSY) { - ticker_job_sched(TICKER_INSTANCE_ID_CTLR, - TICKER_USER_ID_ULL_LOW); - } - } - - /* Using a local variable to address the Coverity rule: - * Incorrect expression (ASSERT_SIDE_EFFECT) - * Argument "ret_cb" of LL_ASSERT() has a side effect - * because the variable is volatile. The containing function - * might work differently in a non-debug build. - */ - success = (ret_cb == TICKER_STATUS_SUCCESS); - LL_ASSERT(success); - - if (ticker_id == TICKER_NULL) { - break; - } - - /* ticks_anchor shall not change during this loop */ - if ((ticker_id_prev != TICKER_NULL) && - (ticks_anchor != ticks_anchor_prev)) { - LL_ASSERT(0); - } - - /* consider advertiser time as available. Any other time used by - * tickers declared outside the controller is also available. - */ -#if defined(CONFIG_BT_BROADCASTER) - if ((ticker_id < TICKER_ID_ADV_BASE) || - (ticker_id > TICKER_ID_CONN_LAST)) -#else /* !CONFIG_BT_BROADCASTER */ - if ((ticker_id < TICKER_ID_SCAN_BASE) || - (ticker_id > TICKER_ID_CONN_LAST)) -#endif /* !CONFIG_BT_BROADCASTER */ - { - continue; - } - - if (ticker_id < TICKER_ID_CONN_BASE) { - /* non conn role found which could have preempted a - * conn role, hence do not consider this free space - * and any further as free slot for offset, - */ - ticker_id_other = ticker_id; - continue; - } - - /* TODO: handle scanner; for now we exit with as much we - * where able to fill (offsets). - */ - if (ticker_id_other != TICKER_NULL) { - break; - } - - conn = ll_conn_get(ticker_id - TICKER_ID_CONN_BASE); - if ((conn != conn_curr) && (is_select || !conn->lll.role)) { - uint32_t ticks_to_expire_normal = - ticks_to_expire + ticks_prepare_reduced; - uint32_t ticks_slot_margin = 0U; - uint32_t ticks_slot_abs_curr = 0U; -#if defined(CONFIG_BT_CTLR_LOW_LAT) -#if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) - if (conn->ull.ticks_prepare_to_start & XON_BITMASK) { - uint32_t ticks_prepare_to_start = - MAX(conn->ull.ticks_active_to_start, - conn->ull.ticks_preempt_to_start); - - ticks_slot_abs_curr = - conn->ull.ticks_prepare_to_start & - ~XON_BITMASK; - ticks_to_expire_normal -= - ticks_slot_abs_curr - - ticks_prepare_to_start; - } else -#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */ - { - uint32_t ticks_prepare_to_start = - MAX(conn->ull.ticks_active_to_start, - conn->ull.ticks_prepare_to_start); - - ticks_slot_abs_curr = ticks_prepare_to_start; - } -#endif - - ticks_slot_abs_curr += conn->ull.ticks_slot + - HAL_TICKER_US_TO_TICKS(CONN_INT_UNIT_US); - - if (conn->lll.role) { - ticks_slot_margin = - HAL_TICKER_US_TO_TICKS(EVENT_TIES_US); - ticks_slot_abs_curr += ticks_slot_margin; - } - - if (*ticks_to_offset_next < ticks_to_expire_normal) { - if (ticks_to_expire_prev < - *ticks_to_offset_next) { - ticks_to_expire_prev = - *ticks_to_offset_next; - } - - while ((offset_index < *offset_max) && - (ticker_ticks_diff_get( - ticks_to_expire_normal, - ticks_to_expire_prev) >= - (ticks_slot_abs_prev + ticks_slot_abs + - ticks_slot_margin))) { - offset = (ticks_to_expire_prev + - ticks_slot_abs_prev) / - HAL_TICKER_US_TO_TICKS( - CONN_INT_UNIT_US); - if (offset >= conn_interval) { - ticks_to_expire_prev = 0U; - - break; - } - - sys_put_le16(offset, - (win_offset + - (sizeof(uint16_t) * - offset_index))); - offset_index++; - - ticks_to_expire_prev += - HAL_TICKER_US_TO_TICKS( - CONN_INT_UNIT_US); - } - - *ticks_to_offset_next = ticks_to_expire_prev; - - if (offset >= conn_interval) { - break; - } - } - - ticks_anchor_prev = ticks_anchor; - ticker_id_prev = ticker_id; - ticks_to_expire_prev = ticks_to_expire_normal; - ticks_slot_abs_prev = ticks_slot_abs_curr; - } - } while (offset_index < *offset_max); - - if (ticker_id == TICKER_NULL) { - if (ticks_to_expire_prev < *ticks_to_offset_next) { - ticks_to_expire_prev = *ticks_to_offset_next; - } - - while (offset_index < *offset_max) { - offset = (ticks_to_expire_prev + ticks_slot_abs_prev) / - HAL_TICKER_US_TO_TICKS(CONN_INT_UNIT_US); - if (offset >= conn_interval) { - ticks_to_expire_prev = 0U; - - break; - } - - sys_put_le16(offset, (win_offset + (sizeof(uint16_t) * - offset_index))); - offset_index++; - - ticks_to_expire_prev += HAL_TICKER_US_TO_TICKS( - CONN_INT_UNIT_US); - } - - *ticks_to_offset_next = ticks_to_expire_prev; - } - - *offset_max = offset_index; -} -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ +/* + * TODO: probably we need a function for calculating the window offset + * see the legacy code from Zephyr v3.2 for inspiration + */ #endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ -#if defined(CONFIG_BT_CENTRAL) || defined(CONFIG_BT_LL_SW_LLCP_LEGACY) +#if defined(CONFIG_BT_CENTRAL) static void after_cen_offset_get(uint16_t conn_interval, uint32_t ticks_slot, uint32_t ticks_anchor, uint32_t *win_offset_us) @@ -666,7 +306,7 @@ static void after_cen_offset_get(uint16_t conn_interval, uint32_t ticks_slot, } } } -#endif /* CONFIG_BT_CENTRAL || CONFIG_BT_LL_SW_LLCP_LEGACY */ +#endif /* CONFIG_BT_CENTRAL */ #endif /* CONFIG_BT_CONN */ static uint8_t after_match_slot_get(uint8_t user_id, uint32_t ticks_slot_abs, From e6a3def17b368d225c7466924c7850b7f80f8a7b Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Mon, 23 Jan 2023 14:23:15 +0100 Subject: [PATCH 0349/1906] Bluetooth: controller: remove dependency for slot reservation The slot reservation code is only valid for the refactored LLCP; a guard was in place to ensure that it was not compiled in for legacy controller code. This commit removes this guard Signed-off-by: Andries Kruithof --- .../bluetooth/controller/Kconfig.ll_sw_split | 2 +- subsys/bluetooth/controller/ll_sw/ull_conn.c | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 8b2db4e890c9..f0c7e25a29fc 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -471,7 +471,7 @@ config BT_CTLR_CENTRAL_RESERVE_MAX config BT_CTLR_SLOT_RESERVATION_UPDATE bool "Update event length reservation after PHY or DLE update" - depends on !BT_LL_SW_LLCP_LEGACY && (BT_CTLR_DATA_LENGTH || BT_CTLR_PHY) + depends on (BT_CTLR_DATA_LENGTH || BT_CTLR_PHY) default y help Updates the event length reservation after a completed Data Length Update diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index c3fa89b586e7..f22019338d7b 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -1227,7 +1227,7 @@ void ull_conn_done(struct node_rx_event_done *done) lazy = lll->latency_event + 1U; } -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) && defined(CONFIG_BT_CTLR_SLOT_RESERVATION_UPDATE) +#if defined(CONFIG_BT_CTLR_SLOT_RESERVATION_UPDATE) #if defined(CONFIG_BT_CTLR_DATA_LENGTH) || defined(CONFIG_BT_CTLR_PHY) if (lll->evt_len_upd) { uint32_t ready_delay, rx_time, tx_time, ticks_slot; @@ -1268,10 +1268,10 @@ void ull_conn_done(struct node_rx_event_done *done) conn->ull.ticks_slot = ticks_slot; } #endif /* CONFIG_BT_CTLR_DATA_LENGTH || CONFIG_BT_CTLR_PHY */ -#else /* !CONFIG_BT_LL_SW_LLCP_LEGACY && CONFIG_BT_CTLR_SLOT_RESERVATION_UPDATE */ +#else /* CONFIG_BT_CTLR_SLOT_RESERVATION_UPDATE */ ticks_slot_plus = 0; ticks_slot_minus = 0; -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY && CONFIG_BT_CTLR_SLOT_RESERVATION_UPDATE */ +#endif /* CONFIG_BT_CTLR_SLOT_RESERVATION_UPDATE */ /* update conn ticker */ if (ticks_drift_plus || ticks_drift_minus || @@ -1976,8 +1976,12 @@ static int empty_data_start_release(struct ll_conn *conn, struct node_tx *tx) } #endif /* CONFIG_BT_CTLR_LLID_DATA_START_EMPTY */ +/* + * TODO: struct lll_conn *lll_conn gives a CI error that tag names + * must be unique. This may be a false positive + */ #if defined(CONFIG_BT_CTLR_FORCE_MD_AUTO) -static uint8_t force_md_cnt_calc(struct lll_conn *lll_conn, uint32_t tx_rate) +static uint8_t force_md_cnt_calc(struct lll_conn *lll_connection, uint32_t tx_rate) { uint32_t time_incoming, time_outgoing; uint8_t force_md_cnt; @@ -1986,15 +1990,15 @@ static uint8_t force_md_cnt_calc(struct lll_conn *lll_conn, uint32_t tx_rate) uint8_t phy; #if defined(CONFIG_BT_CTLR_PHY) - phy = lll_conn->phy_tx; - phy_flags = lll_conn->phy_flags; + phy = lll_connection->phy_tx; + phy_flags = lll_connection->phy_flags; #else /* !CONFIG_BT_CTLR_PHY */ phy = PHY_1M; phy_flags = 0U; #endif /* !CONFIG_BT_CTLR_PHY */ #if defined(CONFIG_BT_CTLR_LE_ENC) - mic_size = PDU_MIC_SIZE * lll_conn->enc_tx; + mic_size = PDU_MIC_SIZE * lll_connection->enc_tx; #else /* !CONFIG_BT_CTLR_LE_ENC */ mic_size = 0U; #endif /* !CONFIG_BT_CTLR_LE_ENC */ From 421585495631ce956e56d886e16dfb25da49ec3d Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Tue, 24 Jan 2023 13:30:44 +0100 Subject: [PATCH 0350/1906] Bluetooth: controller: remove refs to LLCP_LEGACY after rebase Some recent PRs included conditional compilation for KCONFIG_BT_LL_SW_LLCP_LEGACY, which must be removed. Signed-off-by: Andries Kruithof --- .../nrf5340_cpunet_bis-bt_ll_sw_split.conf | 1 - .../nrf5340_cpunet_cis-bt_ll_sw_split.conf | 1 - .../nrf5340_cpunet_df-bt_ll_sw_split.conf | 1 - .../nrf5340_cpunet_df_cis-bt_ll_sw_split.conf | 1 - .../nrf5340_cpunet_iso-bt_ll_sw_split.conf | 1 - subsys/bluetooth/controller/ll_sw/ull.c | 5 +- .../bluetooth/controller/ll_sw/ull_central.c | 2 - subsys/bluetooth/controller/ll_sw/ull_conn.c | 65 +++---------------- .../bluetooth/controller/ll_sw/ull_conn_iso.c | 25 ------- .../controller/ll_sw/ull_conn_types.h | 2 - subsys/bluetooth/controller/ll_sw/ull_sched.c | 8 +-- 11 files changed, 16 insertions(+), 96 deletions(-) diff --git a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_bis-bt_ll_sw_split.conf b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_bis-bt_ll_sw_split.conf index 06c7cc71ab17..173e2286f1c2 100644 --- a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_bis-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_bis-bt_ll_sw_split.conf @@ -70,7 +70,6 @@ CONFIG_BT_CTLR_SCAN_UNRESERVED=y CONFIG_BT_TICKER_NEXT_SLOT_GET_MATCH=y # Control Procedure -CONFIG_BT_LL_SW_LLCP=y CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=6 # ISO Broadcaster Controller diff --git a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_cis-bt_ll_sw_split.conf b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_cis-bt_ll_sw_split.conf index 333fbd4d23c4..f11609aebf6e 100644 --- a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_cis-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_cis-bt_ll_sw_split.conf @@ -67,7 +67,6 @@ CONFIG_BT_CTLR_SCAN_UNRESERVED=y CONFIG_BT_TICKER_NEXT_SLOT_GET_MATCH=y # Control Procedure -CONFIG_BT_LL_SW_LLCP=y CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=6 # ISO Connection Oriented diff --git a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_df-bt_ll_sw_split.conf b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_df-bt_ll_sw_split.conf index 7b42af99c775..0950e01f2849 100644 --- a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_df-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_df-bt_ll_sw_split.conf @@ -60,7 +60,6 @@ CONFIG_BT_CTLR_SCAN_UNRESERVED=y CONFIG_BT_TICKER_NEXT_SLOT_GET_MATCH=y # Control Procedure -CONFIG_BT_LL_SW_LLCP=y CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=6 # Direction Finding diff --git a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_df_cis-bt_ll_sw_split.conf b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_df_cis-bt_ll_sw_split.conf index 561258eaa185..d811c1e461ad 100644 --- a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_df_cis-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_df_cis-bt_ll_sw_split.conf @@ -69,7 +69,6 @@ CONFIG_BT_CTLR_SCAN_UNRESERVED=y CONFIG_BT_TICKER_NEXT_SLOT_GET_MATCH=y # Control Procedure -CONFIG_BT_LL_SW_LLCP=y CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=6 # Direction Finding diff --git a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf index b6b1efa4487f..d307d868f0f1 100644 --- a/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf +++ b/samples/bluetooth/hci_rpmsg/nrf5340_cpunet_iso-bt_ll_sw_split.conf @@ -70,7 +70,6 @@ CONFIG_BT_CTLR_SCAN_UNRESERVED=y CONFIG_BT_TICKER_NEXT_SLOT_GET_MATCH=y # Control Procedure -CONFIG_BT_LL_SW_LLCP=y CONFIG_BT_CTLR_LLCP_LOCAL_PROC_CTX_BUF_NUM=6 # ISO Broadcaster Controller diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index 224e96c7dade..c7a376e506ec 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -2784,8 +2784,7 @@ static inline int rx_demux_rx(memq_link_t *link, struct node_rx_hdr *rx) #endif /* CONFIG_BT_CTLR_ADV_EXT */ #endif /* CONFIG_BT_OBSERVER */ -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) && \ - defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) +#if defined(CONFIG_BT_CTLR_PERIPHERAL_ISO) case NODE_RX_TYPE_CIS_ESTABLISHED: { struct ll_conn *conn; @@ -2801,7 +2800,7 @@ static inline int rx_demux_rx(memq_link_t *link, struct node_rx_hdr *rx) ll_rx_put_sched(link, rx); } break; -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY && CONFIG_BT_CTLR_PERIPHERAL_ISO */ +#endif /* CONFIG_BT_CTLR_PERIPHERAL_ISO */ #if defined(CONFIG_BT_CTLR_DF_SCAN_CTE_RX) || defined(CONFIG_BT_CTLR_DF_CONN_CTE_RX) || \ defined(CONFIG_BT_CTLR_DTM_HCI_DF_IQ_REPORT) diff --git a/subsys/bluetooth/controller/ll_sw/ull_central.c b/subsys/bluetooth/controller/ll_sw/ull_central.c index a8f70f189b75..5aba4df2129e 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central.c @@ -337,9 +337,7 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, ready_delay_us = lll_radio_tx_ready_delay_get(0, 0); #endif - /* TODO(thoh-ot): Not entirely sure this is correct */ #if defined(CONFIG_BT_CTLR_DATA_LENGTH) - /* TODO: do we need to do the following? */ #if defined(CONFIG_BT_CTLR_ADV_EXT) conn_lll->dle.eff.max_tx_time = MAX(conn_lll->dle.eff.max_tx_time, PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index f22019338d7b..391ac147d4dd 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -119,41 +119,12 @@ static uint8_t force_md_cnt_calc(struct lll_conn *lll_conn, uint32_t tx_rate); (LL_LENGTH_OCTETS_TX_MAX + \ BT_CTLR_USER_TX_BUFFER_OVERHEAD)) -/* Encryption request is enqueued in thread context from the Tx buffer pool, - * so that it is serialized alongwith the already enqueued data buffers ensuring - * they are transmitted out to peer before encryption is setup. - * Allocate additional Tx buffers to accommodate simultaneous encryption setup - * across active connections. - * TODO: verify that we don't need this for the refactored LLCP - */ -#define CONN_ENC_REQ_BUFFERS 0 -#define CONN_DATA_BUFFERS (CONFIG_BT_BUF_ACL_TX_COUNT + CONN_ENC_REQ_BUFFERS) - -/** - * One connection may take up to 4 TX buffers for procedures - * simultaneously, for example 2 for encryption, 1 for termination, - * and 1 one that is in flight and has not been returned to the pool - */ -#define CONN_TX_CTRL_BUFFERS LLCP_TX_CTRL_BUF_COUNT -#define CONN_TX_CTRL_BUF_SIZE MROUND(offsetof(struct node_tx, pdu) + \ - offsetof(struct pdu_data, llctrl) + \ - PDU_DC_CTRL_TX_SIZE_MAX) - -/* Terminate procedure state values */ -#define TERM_REQ 1 -#define TERM_ACKED 3 - -/* CIS Establishment procedure state values */ -#define CIS_REQUEST_AWAIT_HOST 2 +#define CONN_DATA_BUFFERS CONFIG_BT_BUF_ACL_TX_COUNT -/* - * TODO: when the legacy LLCP is removed we can replace 'CONN_TX_CTRL_BUFFERS' - * with 'LLCP_TX_CTRL_BUF_COUNT' - */ static MFIFO_DEFINE(conn_tx, sizeof(struct lll_tx), CONN_DATA_BUFFERS); static MFIFO_DEFINE(conn_ack, sizeof(struct lll_tx), (CONN_DATA_BUFFERS + - CONN_TX_CTRL_BUFFERS)); + LLCP_TX_CTRL_BUF_COUNT)); static struct { void *free; @@ -164,7 +135,7 @@ static struct { void *free; uint8_t pool[sizeof(memq_link_t) * (CONN_DATA_BUFFERS + - CONN_TX_CTRL_BUFFERS)]; + LLCP_TX_CTRL_BUF_COUNT)]; } mem_link_tx; #if defined(CONFIG_BT_CTLR_DATA_LENGTH) @@ -984,14 +955,6 @@ void ull_conn_done(struct node_rx_event_done *done) } #endif /* CONFIG_BT_CTLR_LE_ENC */ - /* Legacy LLCP: - * Peripheral received terminate ind or - * Central received ack for the transmitted terminate ind or - * Central transmitted ack for the received terminate ind or - * there has been MIC failure - * Refactored LLCP: - * reason_final is set exactly under the above conditions - */ reason_final = conn->llcp_terminate.reason_final; if (reason_final) { conn_cleanup(conn, reason_final); @@ -1568,7 +1531,7 @@ static int init_reset(void) /* Initialize tx link pool. */ mem_init(mem_link_tx.pool, sizeof(memq_link_t), (CONN_DATA_BUFFERS + - CONN_TX_CTRL_BUFFERS), + LLCP_TX_CTRL_BUF_COUNT), &mem_link_tx.free); /* Initialize control procedure system. */ @@ -1756,10 +1719,8 @@ static void conn_cleanup_iso_cis_released_cb(struct ll_conn *conn) static void conn_cleanup_finalize(struct ll_conn *conn) { struct lll_conn *lll = &conn->lll; - struct node_rx_pdu *rx; uint32_t ticker_status; - ARG_UNUSED(rx); ull_cp_state_set(conn, ULL_CP_DISCONNECTED); /* Update tx buffer queue handling */ @@ -1921,13 +1882,13 @@ static void tx_lll_flush(void *param) (void **)&tx); while (link) { uint8_t idx; - struct lll_tx *lll_tx2; + struct lll_tx *tx_buf; - idx = MFIFO_ENQUEUE_GET(conn_ack, (void **)&lll_tx2); - LL_ASSERT(lll_tx2); + idx = MFIFO_ENQUEUE_GET(conn_ack, (void **)&tx_buf); + LL_ASSERT(tx_buf); - lll_tx2->handle = LLL_HANDLE_INVALID; - lll_tx2->node = tx; + tx_buf->handle = LLL_HANDLE_INVALID; + tx_buf->node = tx; /* TX node UPSTREAM, i.e. Tx node ack path */ link->next = tx->next; /* Indicates ctrl pool or data pool */ @@ -1949,8 +1910,7 @@ static void tx_lll_flush(void *param) rx->hdr.link = NULL; /* Enqueue the terminate towards ULL context */ - ull_rx_put(link, rx); - ull_rx_sched(); + ull_rx_put_sched(link, rx); } #if defined(CONFIG_BT_CTLR_LLID_DATA_START_EMPTY) @@ -2484,11 +2444,6 @@ void ull_dle_local_tx_update(struct ll_conn *conn, uint16_t tx_octets, uint16_t void ull_dle_init(struct ll_conn *conn, uint8_t phy) { - /* - * TODO: - * legacy code uses the maximum of the time for 1M phy and actual phy - * for max_time_min, to be verified if that is required here as well - */ #if defined(CONFIG_BT_CTLR_PHY) const uint16_t max_time_min = PDU_DC_MAX_US(PDU_DC_PAYLOAD_SIZE_MIN, phy); const uint16_t max_time_max = PDU_DC_MAX_US(LL_LENGTH_OCTETS_RX_MAX, phy); diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c index 2d987323f7b3..c3293379e296 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c @@ -299,29 +299,6 @@ void ull_conn_iso_lll_cis_established(struct lll_conn_iso_stream *cis_lll) return; } -#if defined(CONFIG_BT_LL_SW_LLCP_LEGACY) - struct node_rx_conn_iso_estab *est; - struct node_rx_pdu *node_rx; - - node_rx = ull_pdu_rx_alloc(); - if (!node_rx) { - /* No node available - try again later */ - return; - } - - node_rx->hdr.type = NODE_RX_TYPE_CIS_ESTABLISHED; - - /* TODO: Send CIS_ESTABLISHED with status != 0 in error scenarios */ - node_rx->hdr.handle = 0xFFFF; - node_rx->hdr.rx_ftr.param = cis; - - est = (void *)node_rx->pdu; - est->status = 0; - est->cis_handle = cis_lll->handle; - - ll_rx_put_sched(node_rx->hdr.link, node_rx); -#endif /* !CONFIG_BT_LL_SW_LLCP_LEGACY */ - cis->established = 1; } @@ -1074,7 +1051,6 @@ static void cis_disabled_cb(void *param) *((uint8_t *)node_terminate->pdu) = cis->terminate_reason; ll_rx_put_sched(node_terminate->hdr.link, node_terminate); -#if !defined(CONFIG_BT_LL_SW_LLCP_LEGACY) } else { conn = ll_conn_get(cis->lll.acl_handle); @@ -1082,7 +1058,6 @@ static void cis_disabled_cb(void *param) if (ull_cp_cc_awaiting_established(conn)) { ull_cp_cc_established(conn, cis->terminate_reason); } -#endif /* CONFIG_BT_LL_SW_LLCP_LEGACY */ } if (cig->lll.resume_cis == cis->lll.handle) { diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_types.h b/subsys/bluetooth/controller/ll_sw/ull_conn_types.h index cdfdbbf9079a..ad1faccdf547 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_types.h +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_types.h @@ -33,8 +33,6 @@ enum llcp { }; /* - * This is for the refactored LLCP - * * to reduce length and unreadability of the ll_conn struct the * structures inside it have been defined first */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_sched.c b/subsys/bluetooth/controller/ll_sw/ull_sched.c index 611ca68e837f..fec7ab8f3d00 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sched.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sched.c @@ -228,7 +228,7 @@ void ull_sched_mfy_win_offset_use(void *param) /* * TODO: update calculationg of the win_offset * when updating the connection update procedure - * see the legacy code from Zephyr v3.2 for inspiration + * see the legacy code from Zephyr v3.3 for inspiration */ } @@ -242,7 +242,7 @@ void ull_sched_mfy_free_win_offset_calc(void *param) /* * TODO: update when updating the connection update procedure - * see the legacy code from Zephyr v3.2 for inspiration + * see the legacy code from Zephyr v3.3 for inspiration */ } @@ -254,7 +254,7 @@ void ull_sched_mfy_win_offset_select(void *param) /* * TODO: update calculation of win_offset when * updating the connection update procedure - * see the legacy code from Zephyr v3.2 for inspiration + * see the legacy code from Zephyr v3.3 for inspiration */ #undef OFFSET_S_MAX @@ -263,7 +263,7 @@ void ull_sched_mfy_win_offset_select(void *param) /* * TODO: probably we need a function for calculating the window offset - * see the legacy code from Zephyr v3.2 for inspiration + * see the legacy code from Zephyr v3.3 for inspiration */ #endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */ From dca33a126d1765cb647c10eabeea36eafcbd0f92 Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Mon, 20 Feb 2023 15:46:38 +0100 Subject: [PATCH 0351/1906] Bluetooth: controller: update permutation script Updated the script that compiles all different permutations so that it starts with the correct configuration file Signed-off-by: Andries Kruithof --- tests/bluetooth/bsim/_compile_permutate_kconfigs.sh | 4 ++-- tests/bluetooth/bsim/ll/compile.sh | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/bluetooth/bsim/_compile_permutate_kconfigs.sh b/tests/bluetooth/bsim/_compile_permutate_kconfigs.sh index bd2d6fa02490..7f6bacb729b7 100755 --- a/tests/bluetooth/bsim/_compile_permutate_kconfigs.sh +++ b/tests/bluetooth/bsim/_compile_permutate_kconfigs.sh @@ -62,8 +62,8 @@ perm_compile() { echo "Compile with config overlay:" cat $3 fi - local app=tests/bluetooth/bsim/ll/edtt/hci_test_app - local conf_file=prj_dut.conf + local app=tests/bluetooth/bsim/edtt_ble_test_app/hci_test_app + local conf_file=prj_dut_llcp.conf local conf_overlay=$3 compile if [ ! -f ${executable_name} ]; then diff --git a/tests/bluetooth/bsim/ll/compile.sh b/tests/bluetooth/bsim/ll/compile.sh index ede4c74895e6..f9d6f7624146 100755 --- a/tests/bluetooth/bsim/ll/compile.sh +++ b/tests/bluetooth/bsim/ll/compile.sh @@ -33,12 +33,6 @@ app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ conf_file=prj_dut_llcp.conf compile app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ conf_file=prj_tst_llcp.conf compile -app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ - conf_file=prj_dut.conf compile -app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ - conf_file=prj_tst.conf compile -app=tests/bluetooth/bsim/ll/edtt/gatt_test_app \ - conf_file=prj.conf compile app=tests/bluetooth/bsim/ll/edtt/gatt_test_app \ conf_file=prj_llcp.conf compile From b8c7506681662cad5c8b8f005fa0207dcfa9ea27 Mon Sep 17 00:00:00 2001 From: Morten Priess Date: Wed, 1 Mar 2023 12:35:53 +0100 Subject: [PATCH 0352/1906] Bluetooth: controller: Keep CIS/CIG instances until ll_cig_remove This commit enables having multiple CIS/CIG setups/connects and teardowns in sequence. - For central, cig->lll.num_cis is initialized to cis_count and untouched until ll_cig_remove. The value shall indicate number of allocated instances, to ensure correct CIG traversal. - Keep CIG/CIS instances for central until ll_cig_remove - Initialize CIS instance state vars in ll_cis_create, similar to the peripheral flow. - In ll_cig_remove, always release streams and CIG instance. Do not remove paths, as this is done from host at bt_iso_chan_disconnected. - Remove unsued cis_count member in ll_conn_iso_group. - Use correct function ull_iso_lll_ack_enqueue at LLL flush to have data path respected. Signed-off-by: Morten Priess --- .../controller/ll_sw/ull_central_iso.c | 60 +++++++----------- .../bluetooth/controller/ll_sw/ull_conn_iso.c | 63 +++++++++---------- .../controller/ll_sw/ull_conn_iso_types.h | 2 +- .../controller/ll_sw/ull_peripheral_iso.c | 2 + 4 files changed, 55 insertions(+), 72 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 1ce7e016b954..f2575c1864ac 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -61,6 +61,7 @@ static void set_bn_max_pdu(bool framed, uint32_t iso_interval, /* Setup cache for CIG commit transaction */ static struct { struct ll_conn_iso_group group; + uint8_t cis_count; uint8_t c_ft; uint8_t p_ft; uint8_t cis_idx; @@ -80,10 +81,10 @@ uint8_t ll_cig_parameters_open(uint8_t cig_id, ll_iso_setup.group.p_sdu_interval = p_interval; ll_iso_setup.group.c_latency = c_latency * 1000; ll_iso_setup.group.p_latency = p_latency * 1000; - ll_iso_setup.group.cis_count = num_cis; ll_iso_setup.group.central.sca = sca; ll_iso_setup.group.central.packing = packing; ll_iso_setup.group.central.framing = framing; + ll_iso_setup.cis_count = num_cis; return BT_HCI_ERR_SUCCESS; } @@ -113,7 +114,6 @@ uint8_t ll_cis_parameters_set(uint8_t cis_id, return BT_HCI_ERR_SUCCESS; } - /* TODO: * - Drop retransmissions to stay within Max_Transmission_Latency instead of asserting * - Calculate ISO_Interval to allow SDU_Interval < ISO_Interval @@ -151,12 +151,13 @@ uint8_t ll_cig_parameters_commit(uint8_t cig_id) /* Transfer parameters from update cache and clear LLL fields */ memcpy(cig, &ll_iso_setup.group, sizeof(struct ll_conn_iso_group)); + cis_count = ll_iso_setup.cis_count; /* Setup LLL parameters */ cig->lll.handle = ll_conn_iso_group_handle_get(cig); cig->lll.role = BT_HCI_ROLE_CENTRAL; cig->lll.resume_cis = LLL_HANDLE_INVALID; - cig->lll.num_cis = 0U; + cig->lll.num_cis = cis_count; if (!cig->central.test) { /* TODO: Calculate ISO_Interval based on SDU_Interval and Max_SDU vs Max_PDU, @@ -176,9 +177,7 @@ uint8_t ll_cig_parameters_commit(uint8_t cig_id) } lll_hdr_init(&cig->lll, cig); - max_se_length = 0; - cis_count = cig->cis_count; /* 1) Acquire CIS instances and initialize instance data. * 2) Calculate SE_Length for each CIS and store the largest @@ -452,11 +451,11 @@ uint8_t ll_cig_parameters_test_open(uint8_t cig_id, uint32_t c_interval, ll_iso_setup.group.c_sdu_interval = c_interval; ll_iso_setup.group.p_sdu_interval = p_interval; ll_iso_setup.group.iso_interval = iso_interval; - ll_iso_setup.group.cis_count = num_cis; ll_iso_setup.group.central.sca = sca; ll_iso_setup.group.central.packing = packing; ll_iso_setup.group.central.framing = framing; ll_iso_setup.group.central.test = 1U; + ll_iso_setup.cis_count = num_cis; /* TODO: Perhaps move FT to LLL CIG */ ll_iso_setup.c_ft = c_ft; @@ -527,6 +526,19 @@ void ll_cis_create(uint16_t cis_handle, uint16_t acl_handle) err = util_aa_le32(cis->lll.access_addr); LL_ASSERT(!err); + /* Initialize stream states */ + cis->established = 0; + cis->teardown = 0; + cis->lll.event_count = 0; + cis->lll.sn = 0; + cis->lll.nesn = 0; + cis->lll.cie = 0; + cis->lll.flushed = 0; + cis->lll.active = 0; + cis->lll.datapath_ready_rx = 0; + + (void)memset(&cis->hdr, 0U, sizeof(cis->hdr)); + /* Initialize TX link */ if (!cis->lll.link_tx_free) { cis->lll.link_tx_free = &cis->lll.link_tx; @@ -552,7 +564,6 @@ uint8_t ll_cig_remove(uint8_t cig_id) struct ll_conn_iso_stream *cis; struct ll_conn_iso_group *cig; uint16_t handle_iter; - bool has_cis; cig = ll_conn_iso_group_get_by_id(cig_id); if (!cig) { @@ -566,7 +577,7 @@ uint8_t ll_cig_remove(uint8_t cig_id) } handle_iter = UINT16_MAX; - for (int i = 0; i < cig->cis_count; i++) { + for (int i = 0; i < cig->lll.num_cis; i++) { struct ll_conn *conn; cis = ll_conn_iso_stream_get_by_group(cig, &handle_iter); @@ -586,41 +597,16 @@ uint8_t ll_cig_remove(uint8_t cig_id) /* CIG exists and is not active */ handle_iter = UINT16_MAX; - has_cis = false; for (uint8_t i = 0U; i < cig->lll.num_cis; i++) { cis = ll_conn_iso_stream_get_by_group(cig, &handle_iter); - if (!cis) { - break; - } - - /* Remove data path and ISOAL sink/source associated with this CIS - * for both directions. - */ - ll_remove_iso_path(cis->lll.handle, BT_HCI_DATAPATH_DIR_CTLR_TO_HOST); - ll_remove_iso_path(cis->lll.handle, BT_HCI_DATAPATH_DIR_HOST_TO_CTLR); - - has_cis = true; - } - - if (has_cis) { - /* Clear configuration only - let CIS disconnection release instance */ - cig->cis_count = 0; - - return BT_HCI_ERR_SUCCESS; - } - - /* Release associated CIS contexts */ - for (uint8_t i = 0; i < cig->cis_count; i++) { - cis = ll_conn_iso_stream_get_by_group(cig, &handle_iter); - if (!cis) { - break; + if (cis) { + /* Release CIS instance */ + ll_conn_iso_stream_release(cis); } - - ll_conn_iso_stream_release(cis); } - /* No CISes associated with the CIG - release the instance */ + /* Release the CIG instance */ ll_conn_iso_group_release(cig); return BT_HCI_ERR_SUCCESS; diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c index c3293379e296..0a169f7bae17 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c @@ -32,6 +32,7 @@ #include "lll_conn_iso.h" #include "lll_central_iso.h" #include "lll_peripheral_iso.h" +#include "lll_iso_tx.h" #include "ll_sw/ull_tx_queue.h" @@ -420,6 +421,7 @@ void ull_conn_iso_cis_stop(struct ll_conn_iso_stream *cis, /* Teardown already started */ return; } + cis->teardown = 1; cis->released_cb = cis_released_cb; cis->terminate_reason = reason; @@ -721,7 +723,6 @@ void ull_conn_iso_start(struct ll_conn *conn, uint32_t ticks_at_expire, cis = ll_conn_iso_stream_get(cis_handle); cig = cis->group; - cig->lll.num_cis++; cis_offs_to_cig_ref = cig->sync_delay - cis->sync_delay; @@ -985,43 +986,46 @@ static void cis_disabled_cb(void *param) uint32_t ticker_status; struct ll_conn *conn; uint16_t handle_iter; - uint8_t is_last_cis; uint8_t cis_idx; + uint8_t active_cises; cig = HDR_LLL2ULL(param); - is_last_cis = (cig->lll.num_cis == 1U); handle_iter = UINT16_MAX; + active_cises = 0; /* Remove all CISes marked for teardown */ for (cis_idx = 0; cis_idx < cig->lll.num_cis; cis_idx++) { cis = ll_conn_iso_stream_get_by_group(cig, &handle_iter); LL_ASSERT(cis); + if (!cis->lll.active && !cis->lll.flushed) { + /* CIS is not active and not being flushed - skip it */ + continue; + } + active_cises++; + if (cis->lll.flushed) { ll_iso_stream_released_cb_t cis_released_cb; conn = ll_conn_get(cis->lll.acl_handle); cis_released_cb = cis->released_cb; - /* Remove data path and ISOAL sink/source associated with this CIS - * for both directions. - */ - ll_remove_iso_path(cis->lll.handle, BT_HCI_DATAPATH_DIR_CTLR_TO_HOST); - ll_remove_iso_path(cis->lll.handle, BT_HCI_DATAPATH_DIR_HOST_TO_CTLR); + if (IS_PERIPHERAL(cig)) { + /* Remove data path and ISOAL sink/source associated with this + * CIS for both directions. + */ + ll_remove_iso_path(cis->lll.handle, + BT_HCI_DATAPATH_DIR_CTLR_TO_HOST); + ll_remove_iso_path(cis->lll.handle, + BT_HCI_DATAPATH_DIR_HOST_TO_CTLR); - if (IS_PERIPHERAL(cig) || (cig->cis_count == 0U)) { ll_conn_iso_stream_release(cis); - - } else if (IS_CENTRAL(cig)) { - cis->established = 0U; - cis->teardown = 0U; - cis->lll.flushed = 0U; - - } else { - LL_ASSERT(0); + cig->lll.num_cis--; } - cig->lll.num_cis--; + /* CIS is no longer active */ + cis->lll.active = 0U; + active_cises--; /* CIS terminated, triggers completion of CIS_TERMINATE_IND procedure */ /* Only used by local procedure, ignored for remote procedure */ @@ -1084,10 +1088,12 @@ static void cis_disabled_cb(void *param) } } - if (is_last_cis && (cig->lll.num_cis == 0U)) { - /* This was the last CIS of the CIG. Initiate CIG teardown by + if (cig->started && !active_cises) { + /* This was the last active CIS of the CIG. Initiate CIG teardown by * stopping ticker. */ + cig->started = 0; + ticker_status = ticker_stop(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_ULL_HIGH, TICKER_ID_CONN_ISO_BASE + @@ -1107,7 +1113,7 @@ static void cis_tx_lll_flush(void *param) struct lll_conn_iso_stream *lll; struct ll_conn_iso_stream *cis; struct ll_conn_iso_group *cig; - struct node_tx *tx; + struct node_tx_iso *tx; memq_link_t *link; uint32_t ret; @@ -1123,13 +1129,9 @@ static void cis_tx_lll_flush(void *param) link = memq_dequeue(lll->memq_tx.tail, &lll->memq_tx.head, (void **)&tx); while (link) { - /* Create instant NACK, we are in LLL execution context here */ - /* FIXME: ll_tx_ack_put is not LLL callable as it is used by - * ACL connections in ULL context to dispatch ack. - */ link->next = tx->next; tx->next = link; - ll_tx_ack_put(lll->handle, tx); + ull_iso_lll_ack_enqueue(lll->handle, tx); link = memq_dequeue(lll->memq_tx.tail, &lll->memq_tx.head, (void **)&tx); @@ -1201,15 +1203,8 @@ static void cig_disabled_cb(void *param) cig = HDR_LLL2ULL(param); - if (IS_PERIPHERAL(cig) || cig->cis_count == 0) { + if (IS_PERIPHERAL(cig)) { ll_conn_iso_group_release(cig); - - } else if (IS_CENTRAL(cig)) { - /* CIG shall be released by ll_cig_remove */ - cig->started = 0; - - } else { - LL_ASSERT(0); } } diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso_types.h b/subsys/bluetooth/controller/ll_sw/ull_conn_iso_types.h index 56a21beb09eb..6c0d73bd040e 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso_types.h +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso_types.h @@ -69,7 +69,7 @@ struct ll_conn_iso_group { uint8_t started:1; /* 1 if CIG started and ticker is running */ uint8_t sca_update:4; /* (new SCA)+1 to trigger restart of ticker */ - uint8_t cis_count:5; /* Number of configured CISes in this CIG */ + union { struct { uint8_t sca; diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c index a27cce295ec9..ae370bbc779f 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral_iso.c @@ -144,6 +144,7 @@ void ull_peripheral_iso_release(uint16_t cis_handle) cig = cis->group; ll_conn_iso_stream_release(cis); + cig->lll.num_cis--; if (!cig->lll.num_cis) { ll_conn_iso_group_release(cig); @@ -262,6 +263,7 @@ uint8_t ull_peripheral_iso_acquire(struct ll_conn *acl, cis->lll.link_tx_free = NULL; *cis_handle = ll_conn_iso_stream_handle_get(cis); + cig->lll.num_cis++; return 0; } From 00c95809141eeaad49916a9849d114a31676a157 Mon Sep 17 00:00:00 2001 From: Morten Priess Date: Tue, 14 Mar 2023 15:24:04 +0100 Subject: [PATCH 0353/1906] Bluetooth: controller: Fix offset for CIG with CISes in different ACLs Calculate CIS offset of secondary CIS(es) using CIG reference point. This fixes issue with e.g. two CISes associated with separate ACL connections. Signed-off-by: Morten Priess --- .../controller/ll_sw/ull_central_iso.c | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index f2575c1864ac..34805fc2e3e7 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -632,6 +632,7 @@ uint8_t ull_central_iso_setup(uint16_t cis_handle, { struct ll_conn_iso_stream *cis; struct ll_conn_iso_group *cig; + uint16_t event_counter; struct ll_conn *conn; uint16_t handle_iter; uint32_t cis_offset; @@ -648,7 +649,8 @@ uint8_t ull_central_iso_setup(uint16_t cis_handle, } conn = ll_conn_get(cis->lll.acl_handle); - instant = MAX(*conn_event_count, ull_conn_event_counter(conn) + 1); + event_counter = ull_conn_event_counter(conn); + instant = MAX(*conn_event_count, event_counter + 1); handle_iter = UINT16_MAX; @@ -661,23 +663,29 @@ uint8_t ull_central_iso_setup(uint16_t cis_handle, #endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ /* Calculate offset for CIS */ - for (uint8_t i = 0; i < cig->cis_count; i++) { - struct ll_conn_iso_stream *c; - int16_t conn_events_since_ref; - uint32_t iso_interval_us; - uint32_t time_since_ref; - - c = ll_conn_iso_stream_get_by_group(cig, &handle_iter); - if (c->cis_id != cis->cis_id && c->lll.active) { - conn_events_since_ref = (int16_t)(instant - c->central.instant); - LL_ASSERT(conn_events_since_ref > 0); - - time_since_ref = c->offset + conn_events_since_ref * conn->lll.interval * - CONN_INT_UNIT_US; - iso_interval_us = cig->iso_interval * ISO_INT_UNIT_US; - cis_offset = time_since_ref % iso_interval_us; - break; + if (cig->started) { + uint32_t time_of_intant; + uint32_t cig_ref_point; + + /* CIG is started. Use the CIG reference point and latest ticks_at_expire + * for associated ACL, to calculate the offset. + */ + time_of_intant = isoal_get_wrapped_time_us( + HAL_TICKER_TICKS_TO_US(conn->llcp.prep.ticks_at_expire), + EVENT_OVERHEAD_START_US + + (instant - event_counter) * conn->lll.interval * CONN_INT_UNIT_US); + + cig_ref_point = cig->cig_ref_point; + while (cig_ref_point < time_of_intant) { + cig_ref_point += cig->iso_interval * ISO_INT_UNIT_US; } + + cis_offset = (cig_ref_point - time_of_intant) + + (cig->sync_delay - cis->sync_delay); + + /* We have to narrow down the min/max offset to the calculated value */ + *cis_offset_min = cis_offset; + *cis_offset_max = cis_offset; } cis->offset = cis_offset; From ceaddc81dbbd97b5e6c0f83ade7a3d51987e3084 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Sun, 12 Feb 2023 18:01:10 +0530 Subject: [PATCH 0354/1906] Bluetooth: Controller: Fix connected ISO time reservation calculation Fix Connected ISO time reservation that was missing the event start and end overhead values. Fix missing event end overhead values in ACL connection time reservation. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/ll_sw/ull_central.c | 1 + .../bluetooth/controller/ll_sw/ull_central_iso.c | 3 ++- subsys/bluetooth/controller/ll_sw/ull_conn_iso.c | 16 ++++++++++++++-- .../bluetooth/controller/ll_sw/ull_peripheral.c | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_central.c b/subsys/bluetooth/controller/ll_sw/ull_central.c index 5aba4df2129e..db32d639614b 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central.c @@ -361,6 +361,7 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US + + EVENT_OVERHEAD_END_US + ready_delay_us + max_tx_time + EVENT_IFS_US + diff --git a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c index 34805fc2e3e7..e4f57174d0eb 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central_iso.c @@ -659,7 +659,8 @@ uint8_t ull_central_iso_setup(uint16_t cis_handle, #else /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ cis_offset = MAX((HAL_TICKER_TICKS_TO_US(conn->ull.ticks_slot) + - (EVENT_TICKER_RES_MARGIN_US << 1U)), *cis_offset_min); + (EVENT_TICKER_RES_MARGIN_US << 1U)), *cis_offset_min); + #endif /* !CONFIG_BT_CTLR_JIT_SCHEDULING */ /* Calculate offset for CIS */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c index 0a169f7bae17..b90f1c5247ad 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn_iso.c @@ -886,8 +886,20 @@ void ull_conn_iso_start(struct ll_conn *conn, uint32_t ticks_at_expire, uint32_t ticks_slot_offset; uint32_t slot_us; - /* FIXME: time reservations */ - slot_us = cis->lll.sub_interval; + /* Calculate time reservations for sequential and interleaved packing as + * configured. + */ + if (IS_CENTRAL(cig)) { + /* CIG sync_delay has been calculated considering the configured + * packing. + */ + slot_us = cig->sync_delay; + } else { + /* FIXME: Time reservation for interleaved packing */ + /* Below is time reservation for sequential packing */ + slot_us = cis->lll.sub_interval * cis->lll.nse; + } + slot_us += EVENT_OVERHEAD_START_US + EVENT_OVERHEAD_END_US; /* Populate the ULL hdr with event timings overheads */ cig->ull.ticks_active_to_start = 0U; diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c index bddedc78b1ab..1c8f899de25d 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c @@ -373,6 +373,7 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); conn->ull.ticks_slot = HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US + + EVENT_OVERHEAD_END_US + ready_delay_us + max_rx_time + EVENT_IFS_US + From 0d54ca876168b7d5d28219af3f3f1a247da49209 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Tue, 14 Feb 2023 13:16:37 +0530 Subject: [PATCH 0355/1906] Bluetooth: Controller: Fix ull_prepare_dequeue for skipped events Fix ull_prepare_dequeue to not skip events when preempt does not match the event in the head of the prepare queue. The head of the prepare queue does not match when ull_prepare_dequeue has put the head of the queue to the last of the queue when it is calling lll_resume interface. This happens when there is already an active event which needs a preempt timeout to be setup and there is another non-resume event in the pipeline which now becomes the head. The fix ensure to restore the order of the events if a preempt timeout was to be setup. Currently ull_prepare_dequeue loops through all events before stopping at the original way the queue was. This is not efficient and is a scope for improvement in future. Signed-off-by: Vinayak Kariappa Chettimada --- .../controller/ll_sw/nordic/lll/lll.c | 6 +-- subsys/bluetooth/controller/ll_sw/ull.c | 48 ++++++++++++------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index b98601488b3e..0c9dceec3e05 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -916,8 +916,8 @@ static uint32_t preempt_ticker_start(struct lll_event *first, TICKER_NULL_REMAINDER, TICKER_NULL_LAZY, TICKER_NULL_SLOT, - preempt_ticker_cb, first, - ticker_start_op_cb, first); + preempt_ticker_cb, first->prepare_param.param, + ticker_start_op_cb, NULL); return ret; } @@ -993,7 +993,7 @@ static void preempt(void *param) } /* Preemptor not in pipeline */ - if (next != param) { + if (next->prepare_param.param != param) { uint32_t ret; /* Start the preempt timeout */ diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index c7a376e506ec..55f86966b9da 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -2051,6 +2051,8 @@ void *ull_prepare_dequeue_iter(uint8_t *idx) void ull_prepare_dequeue(uint8_t caller_id) { + void *param_normal_head = NULL; + void *param_normal_next = NULL; void *param_resume_head = NULL; void *param_resume_next = NULL; struct lll_event *next; @@ -2091,31 +2093,41 @@ void ull_prepare_dequeue(uint8_t caller_id) /* The prepare element was not a resume event, it would * use the radio or was enqueued back into prepare * pipeline with a preempt timeout being set. + * + * Remember the first encountered and the next element + * in the prepare pipeline so that we do not infinitely + * loop through the resume events in prepare pipeline. */ if (!is_resume) { - break; - } - - /* Remember the first encountered resume and the next - * resume element in the prepare pipeline so that we do - * not infinitely loop through the resume events in - * prepare pipeline. - */ - if (!param_resume_head) { - param_resume_head = param; - } else if (!param_resume_next) { - param_resume_next = param; + if (!param_normal_head) { + param_normal_head = param; + } else if (!param_normal_next) { + param_normal_next = param; + } + } else { + if (!param_resume_head) { + param_resume_head = param; + } else if (!param_resume_next) { + param_resume_next = param; + } } /* Stop traversing the prepare pipeline when we reach - * back to the first or next resume event where we + * back to the first or next event where we * initially started processing the prepare pipeline. */ - if (next->is_resume && - ((next->prepare_param.param == - param_resume_head) || - (next->prepare_param.param == - param_resume_next))) { + if (!next->is_aborted && + ((!next->is_resume && + ((next->prepare_param.param == + param_normal_head) || + (next->prepare_param.param == + param_normal_next))) || + (next->is_resume && + !param_normal_next && + ((next->prepare_param.param == + param_resume_head) || + (next->prepare_param.param == + param_resume_next))))) { break; } } From de9579f2974301f67cccb25408c846a0ef6b8a31 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Tue, 28 Feb 2023 11:32:46 +0530 Subject: [PATCH 0356/1906] Bluetooth: Controller: Implement CIS abort_cb to flush tx/rx Implement a custom abort_cb callback to perform Tx and Rx flush and adjust the SN/NESN values. Signed-off-by: Vinayak Kariappa Chettimada --- .../ll_sw/nordic/lll/lll_central_iso.c | 33 ++++++++++++++++++- .../ll_sw/nordic/lll/lll_peripheral_iso.c | 33 ++++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index 1510c21681e1..c1091bd6f125 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -41,6 +41,7 @@ static int init_reset(void); static int prepare_cb(struct lll_prepare_param *p); +static void abort_cb(struct lll_prepare_param *prepare_param, void *param); static void isr_tx(void *param); static void isr_rx(void *param); static void isr_prepare_subevent(void *param); @@ -92,7 +93,7 @@ void lll_central_iso_prepare(void *param) LL_ASSERT(err >= 0); /* Invoke common pipeline handling of prepare */ - err = lll_prepare(lll_is_abort_cb, lll_abort_cb, prepare_cb, 0U, param); + err = lll_prepare(lll_is_abort_cb, abort_cb, prepare_cb, 0U, param); LL_ASSERT(!err || err == -EINPROGRESS); } @@ -337,6 +338,36 @@ static int prepare_cb(struct lll_prepare_param *p) return 0; } +static void abort_cb(struct lll_prepare_param *prepare_param, void *param) +{ + int err; + + /* NOTE: This is not a prepare being cancelled */ + if (!prepare_param) { + struct lll_conn_iso_group *cig_lll = param; + struct lll_conn_iso_stream *cis_lll; + + cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, NULL); + + /* Perform event abort here. + * After event has been cleanly aborted, clean up resources + * and dispatch event done. + */ + radio_isr_set(isr_done, cis_lll); + radio_disable(); + + return; + } + + /* NOTE: Else clean the top half preparations of the aborted event + * currently in preparation pipeline. + */ + err = lll_hfclock_off(); + LL_ASSERT(err >= 0); + + lll_done(param); +} + static void isr_tx(void *param) { struct lll_conn_iso_stream *cis_lll; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index f4f234bf9d92..95961d600626 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -39,6 +39,7 @@ static int init_reset(void); static int prepare_cb(struct lll_prepare_param *p); +static void abort_cb(struct lll_prepare_param *prepare_param, void *param); static void isr_rx(void *param); static void isr_tx(void *param); static void isr_prepare_subevent(void *param); @@ -102,7 +103,7 @@ void lll_peripheral_iso_prepare(void *param) } /* Invoke common pipeline handling of prepare */ - err = lll_prepare(lll_is_abort_cb, lll_abort_cb, prepare_cb, 0U, param); + err = lll_prepare(lll_is_abort_cb, abort_cb, prepare_cb, 0U, param); LL_ASSERT(!err || err == -EINPROGRESS); } @@ -335,6 +336,36 @@ static int prepare_cb(struct lll_prepare_param *p) return 0; } +static void abort_cb(struct lll_prepare_param *prepare_param, void *param) +{ + int err; + + /* NOTE: This is not a prepare being cancelled */ + if (!prepare_param) { + struct lll_conn_iso_group *cig_lll = param; + struct lll_conn_iso_stream *cis_lll; + + cis_lll = ull_conn_iso_lll_stream_get_by_group(cig_lll, NULL); + + /* Perform event abort here. + * After event has been cleanly aborted, clean up resources + * and dispatch event done. + */ + radio_isr_set(isr_done, cis_lll); + radio_disable(); + + return; + } + + /* NOTE: Else clean the top half preparations of the aborted event + * currently in preparation pipeline. + */ + err = lll_hfclock_off(); + LL_ASSERT(err >= 0); + + lll_done(param); +} + static void isr_rx(void *param) { struct lll_conn_iso_stream *cis_lll; From 22273e34d08ce14d19d078dce22831d1cfbc67c1 Mon Sep 17 00:00:00 2001 From: Tom Burdick Date: Mon, 27 Feb 2023 10:09:45 -0600 Subject: [PATCH 0357/1906] rtio: Clear flags in prep helpers Tests were failing when the sqe was allocated on the stack for some architectures. Initialization of variables on the stack is not guaranteed to be zeroed like static data. This caused undefined behavior. Secondly if the sqe is recycled and had a flag set, there would unexpected behavior as well. Signed-off-by: Tom Burdick --- include/zephyr/rtio/rtio.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/zephyr/rtio/rtio.h b/include/zephyr/rtio/rtio.h index 516072a9e204..8a40b867eea1 100644 --- a/include/zephyr/rtio/rtio.h +++ b/include/zephyr/rtio/rtio.h @@ -318,6 +318,7 @@ static inline void rtio_sqe_prep_nop(struct rtio_sqe *sqe, void *userdata) { sqe->op = RTIO_OP_NOP; + sqe->flags = 0; sqe->iodev = iodev; sqe->userdata = userdata; } @@ -334,6 +335,7 @@ static inline void rtio_sqe_prep_read(struct rtio_sqe *sqe, { sqe->op = RTIO_OP_RX; sqe->prio = prio; + sqe->flags = 0; sqe->iodev = iodev; sqe->buf_len = len; sqe->buf = buf; @@ -352,6 +354,7 @@ static inline void rtio_sqe_prep_write(struct rtio_sqe *sqe, { sqe->op = RTIO_OP_TX; sqe->prio = prio; + sqe->flags = 0; sqe->iodev = iodev; sqe->buf_len = len; sqe->buf = buf; From 1ba0251b26085d670e417af4c12b8e3dd7a5d9c8 Mon Sep 17 00:00:00 2001 From: Tom Burdick Date: Mon, 27 Feb 2023 10:12:42 -0600 Subject: [PATCH 0358/1906] tests: rtio: Fix potential race in iodev test Race was possible though very unlikely between the atomic cas and queue push/pop operations. The outcome of the race had it shown up would have been a submission not worked on due to the timer never being started. A small critical section fixes this and clarifies where the single conumer part of the mpsc queue comes in despite there being multiple contexts which may enter that section. Signed-off-by: Tom Burdick --- .../rtio/rtio_api/src/rtio_iodev_test.h | 74 ++++++++++--------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/tests/subsys/rtio/rtio_api/src/rtio_iodev_test.h b/tests/subsys/rtio/rtio_api/src/rtio_iodev_test.h index e0f01226cdd3..f89ada68e843 100644 --- a/tests/subsys/rtio/rtio_api/src/rtio_iodev_test.h +++ b/tests/subsys/rtio/rtio_api/src/rtio_iodev_test.h @@ -13,38 +13,54 @@ #define RTIO_IODEV_TEST_H_ struct rtio_iodev_test_data { - /** - * k_timer for an asynchronous task - */ + /* k_timer for an asynchronous task */ struct k_timer timer; - /** - * Currently executing sqe - */ - atomic_ptr_t iodev_sqe; + /* Currently executing sqe */ + struct rtio_iodev_sqe *iodev_sqe; + + /* Count of submit calls */ + atomic_t submit_count; + + /* Lock around kicking off next timer */ + struct k_spinlock lock; }; -static void rtio_iodev_timer_fn(struct k_timer *tm) +static void rtio_iodev_test_next(struct rtio_iodev *iodev) { - struct rtio_iodev_test_data *data = CONTAINER_OF(tm, struct rtio_iodev_test_data, timer); - struct rtio_iodev_sqe *iodev_sqe = atomic_ptr_get(&data->iodev_sqe); - struct rtio_mpsc_node *next = - rtio_mpsc_pop((struct rtio_mpsc *)&iodev_sqe->sqe->iodev->iodev_sq); + struct rtio_iodev_test_data *data = iodev->data; + + /* The next section must be serialized to ensure single consumer semantics */ + k_spinlock_key_t key = k_spin_lock(&data->lock); + + if (data->iodev_sqe != NULL) { + goto out; + } + + struct rtio_mpsc_node *next = rtio_mpsc_pop(&iodev->iodev_sq); if (next != NULL) { struct rtio_iodev_sqe *next_sqe = CONTAINER_OF(next, struct rtio_iodev_sqe, q); - atomic_ptr_set(&data->iodev_sqe, next_sqe); - TC_PRINT("starting timer again from queued iodev_sqe %p!\n", next); + data->iodev_sqe = next_sqe; k_timer_start(&data->timer, K_MSEC(10), K_NO_WAIT); - } else { - atomic_ptr_set(&data->iodev_sqe, NULL); } - /* Complete the request with Ok and a result */ - TC_PRINT("sqe ok callback\n"); +out: + k_spin_unlock(&data->lock, key); +} +static void rtio_iodev_timer_fn(struct k_timer *tm) +{ + struct rtio_iodev_test_data *data = CONTAINER_OF(tm, struct rtio_iodev_test_data, timer); + struct rtio_iodev_sqe *iodev_sqe = data->iodev_sqe; + struct rtio_iodev *iodev = (struct rtio_iodev *)iodev_sqe->sqe->iodev; + + /* Complete the request with Ok and a result, clear the current task */ rtio_iodev_sqe_ok(iodev_sqe, 0); + data->iodev_sqe = NULL; + + rtio_iodev_test_next(iodev); } static void rtio_iodev_test_submit(struct rtio_iodev_sqe *iodev_sqe) @@ -52,22 +68,12 @@ static void rtio_iodev_test_submit(struct rtio_iodev_sqe *iodev_sqe) struct rtio_iodev *iodev = (struct rtio_iodev *)iodev_sqe->sqe->iodev; struct rtio_iodev_test_data *data = iodev->data; - /* - * If a task is already going queue up the next request in the mpsc. - */ - if (!atomic_ptr_cas(&data->iodev_sqe, NULL, iodev_sqe)) { - TC_PRINT("adding queued sqe\n"); - rtio_mpsc_push(&iodev->iodev_sq, &iodev_sqe->q); - } + atomic_inc(&data->submit_count); + + /* The only safe operation is enqueuing */ + rtio_mpsc_push(&iodev->iodev_sq, &iodev_sqe->q); - /* - * Simulate an async hardware request with a one shot timer - * - * In reality the time to complete might have some significant variance - * but this is proof enough of a working API flow. - */ - TC_PRINT("starting one shot\n"); - k_timer_start(&data->timer, K_MSEC(10), K_NO_WAIT); + rtio_iodev_test_next(iodev); } const struct rtio_iodev_api rtio_iodev_test_api = { @@ -79,7 +85,7 @@ void rtio_iodev_test_init(struct rtio_iodev *test) struct rtio_iodev_test_data *data = test->data; rtio_mpsc_init(&test->iodev_sq); - atomic_ptr_set(&data->iodev_sqe, NULL); + data->iodev_sqe = NULL; k_timer_init(&data->timer, rtio_iodev_timer_fn, NULL); } From 3f02532616f8af255425b3c896d4748bf3b75364 Mon Sep 17 00:00:00 2001 From: Tom Burdick Date: Mon, 27 Feb 2023 12:40:16 -0600 Subject: [PATCH 0359/1906] tests: rtio: Split test suites up into files The test suites have grown to cover different units really and having them in one file was becoming a bit much to scroll around in. Coincidentally found a accidental reuse of a define between the spsc and mpsc tests. Signed-off-by: Tom Burdick --- tests/subsys/rtio/rtio_api/CMakeLists.txt | 2 +- tests/subsys/rtio/rtio_api/src/main.c | 676 ------------------ tests/subsys/rtio/rtio_api/src/rtio_api.h | 19 + .../subsys/rtio/rtio_api/src/test_rtio_api.c | 293 ++++++++ .../subsys/rtio/rtio_api/src/test_rtio_mpsc.c | 179 +++++ .../subsys/rtio/rtio_api/src/test_rtio_spsc.c | 218 ++++++ 6 files changed, 710 insertions(+), 677 deletions(-) delete mode 100644 tests/subsys/rtio/rtio_api/src/main.c create mode 100644 tests/subsys/rtio/rtio_api/src/rtio_api.h create mode 100644 tests/subsys/rtio/rtio_api/src/test_rtio_api.c create mode 100644 tests/subsys/rtio/rtio_api/src/test_rtio_mpsc.c create mode 100644 tests/subsys/rtio/rtio_api/src/test_rtio_spsc.c diff --git a/tests/subsys/rtio/rtio_api/CMakeLists.txt b/tests/subsys/rtio/rtio_api/CMakeLists.txt index 68fd00d94bfc..3ece5f0c51e2 100644 --- a/tests/subsys/rtio/rtio_api/CMakeLists.txt +++ b/tests/subsys/rtio/rtio_api/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(rtio_api_test) -target_sources(app PRIVATE src/main.c) +target_sources(app PRIVATE src/test_rtio_spsc.c src/test_rtio_mpsc.c src/test_rtio_api.c) target_include_directories(app PRIVATE ${ZEPHYR_BASE}/include diff --git a/tests/subsys/rtio/rtio_api/src/main.c b/tests/subsys/rtio/rtio_api/src/main.c deleted file mode 100644 index 035acf3b1073..000000000000 --- a/tests/subsys/rtio/rtio_api/src/main.c +++ /dev/null @@ -1,676 +0,0 @@ -/* - * Copyright (c) 2021 Intel Corporation. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "rtio_iodev_test.h" - -/* - * @brief Produce and Consume a single uint32_t in the same execution context - * - * @see rtio_spsc_acquire(), rtio_spsc_produce(), rtio_spsc_consume(), rtio_spsc_release() - * - * @ingroup rtio_tests - */ -ZTEST(rtio_spsc, test_produce_consume_size1) -{ - RTIO_SPSC_DEFINE(ezspsc, uint32_t, 1); - - const uint32_t magic = 43219876; - - uint32_t *acq = rtio_spsc_acquire(&ezspsc); - - zassert_not_null(acq, "Acquire should succeed"); - - *acq = magic; - - uint32_t *acq2 = rtio_spsc_acquire(&ezspsc); - - zassert_is_null(acq2, "Acquire should fail"); - - uint32_t *cons = rtio_spsc_consume(&ezspsc); - - zassert_is_null(cons, "Consume should fail"); - - zassert_equal(rtio_spsc_consumable(&ezspsc), 0, "Consumables should be 0"); - - rtio_spsc_produce(&ezspsc); - - zassert_equal(rtio_spsc_consumable(&ezspsc), 1, "Consumables should be 1"); - - uint32_t *cons2 = rtio_spsc_consume(&ezspsc); - - zassert_equal(rtio_spsc_consumable(&ezspsc), 0, "Consumables should be 0"); - - zassert_not_null(cons2, "Consume should not fail"); - zassert_equal(*cons2, magic, "Consume value should equal magic"); - - uint32_t *cons3 = rtio_spsc_consume(&ezspsc); - - zassert_is_null(cons3, "Consume should fail"); - - - uint32_t *acq3 = rtio_spsc_acquire(&ezspsc); - - zassert_is_null(acq3, "Acquire should not succeed"); - - rtio_spsc_release(&ezspsc); - - uint32_t *acq4 = rtio_spsc_acquire(&ezspsc); - - zassert_not_null(acq4, "Acquire should succeed"); -} - -/*&* - * @brief Produce and Consume 3 items at a time in a spsc of size 4 to validate masking - * and wrap around reads/writes. - * - * @see rtio_spsc_acquire(), rtio_spsc_produce(), rtio_spsc_consume(), rtio_spsc_release() - * - * @ingroup rtio_tests - */ -ZTEST(rtio_spsc, test_produce_consume_wrap_around) -{ - RTIO_SPSC_DEFINE(ezspsc, uint32_t, 4); - - for (int i = 0; i < 10; i++) { - zassert_equal(rtio_spsc_consumable(&ezspsc), 0, "Consumables should be 0"); - for (int j = 0; j < 3; j++) { - uint32_t *entry = rtio_spsc_acquire(&ezspsc); - - zassert_not_null(entry, "Acquire should succeed"); - *entry = i * 3 + j; - rtio_spsc_produce(&ezspsc); - } - zassert_equal(rtio_spsc_consumable(&ezspsc), 3, "Consumables should be 3"); - - for (int k = 0; k < 3; k++) { - uint32_t *entry = rtio_spsc_consume(&ezspsc); - - zassert_not_null(entry, "Consume should succeed"); - zassert_equal(*entry, i * 3 + k, "Consume value should equal i*3+k"); - rtio_spsc_release(&ezspsc); - } - - zassert_equal(rtio_spsc_consumable(&ezspsc), 0, "Consumables should be 0"); - - } -} - -/** - * @brief Ensure that integer wraps continue to work. - * - * Done by setting all values to UINTPTR_MAX - 2 and writing and reading enough - * to ensure integer wraps occur. - */ -ZTEST(rtio_spsc, test_int_wrap_around) -{ - RTIO_SPSC_DEFINE(ezspsc, uint32_t, 4); - ezspsc._spsc.in = ATOMIC_INIT(UINTPTR_MAX - 2); - ezspsc._spsc.out = ATOMIC_INIT(UINTPTR_MAX - 2); - - for (int j = 0; j < 3; j++) { - uint32_t *entry = rtio_spsc_acquire(&ezspsc); - - zassert_not_null(entry, "Acquire should succeed"); - *entry = j; - rtio_spsc_produce(&ezspsc); - } - - zassert_equal(atomic_get(&ezspsc._spsc.in), UINTPTR_MAX + 1, "Spsc in should wrap"); - - for (int k = 0; k < 3; k++) { - uint32_t *entry = rtio_spsc_consume(&ezspsc); - - zassert_not_null(entry, "Consume should succeed"); - zassert_equal(*entry, k, "Consume value should equal i*3+k"); - rtio_spsc_release(&ezspsc); - } - - zassert_equal(atomic_get(&ezspsc._spsc.out), UINTPTR_MAX + 1, "Spsc out should wrap"); -} - -#define MAX_RETRIES 5 -#define SMP_ITERATIONS 100 - -RTIO_SPSC_DEFINE(spsc, uint32_t, 4); - -static void t1_consume(void *p1, void *p2, void *p3) -{ - struct rtio_spsc_spsc *ezspsc = p1; - uint32_t retries = 0; - uint32_t *val = NULL; - - for (int i = 0; i < SMP_ITERATIONS; i++) { - val = NULL; - retries = 0; - while (val == NULL && retries < MAX_RETRIES) { - val = rtio_spsc_consume(ezspsc); - retries++; - } - if (val != NULL) { - rtio_spsc_release(ezspsc); - } else { - k_yield(); - } - } -} - -static void t2_produce(void *p1, void *p2, void *p3) -{ - struct rtio_spsc_spsc *ezspsc = p1; - uint32_t retries = 0; - uint32_t *val = NULL; - - for (int i = 0; i < SMP_ITERATIONS; i++) { - val = NULL; - retries = 0; - while (val == NULL && retries < MAX_RETRIES) { - val = rtio_spsc_acquire(ezspsc); - retries++; - } - if (val != NULL) { - *val = SMP_ITERATIONS; - rtio_spsc_produce(ezspsc); - } else { - k_yield(); - } - } -} - -#define STACK_SIZE (384 + CONFIG_TEST_EXTRA_STACK_SIZE) -#define THREADS_NUM 2 - -struct thread_info { - k_tid_t tid; - int executed; - int priority; - int cpu_id; -}; -static struct thread_info tinfo[THREADS_NUM]; -static struct k_thread tthread[THREADS_NUM]; -static K_THREAD_STACK_ARRAY_DEFINE(tstack, THREADS_NUM, STACK_SIZE); - - -/** - * @brief Test that the producer and consumer are indeed thread safe - * - * This can and should be validated on SMP machines where incoherent - * memory could cause issues. - */ -ZTEST(rtio_spsc, test_spsc_threaded) -{ - - tinfo[0].tid = - k_thread_create(&tthread[0], tstack[0], STACK_SIZE, - (k_thread_entry_t)t1_consume, - &spsc, NULL, NULL, - K_PRIO_PREEMPT(5), - K_INHERIT_PERMS, K_NO_WAIT); - tinfo[1].tid = - k_thread_create(&tthread[1], tstack[1], STACK_SIZE, - (k_thread_entry_t)t2_produce, - &spsc, NULL, NULL, - K_PRIO_PREEMPT(5), - K_INHERIT_PERMS, K_NO_WAIT); - - k_thread_join(tinfo[1].tid, K_FOREVER); - k_thread_join(tinfo[0].tid, K_FOREVER); -} - -static struct rtio_mpsc push_pop_q; -static struct rtio_mpsc_node push_pop_nodes[2]; - -/* - * @brief Push and pop one element - * - * @see rtio_mpsc_push(), rtio_mpsc_pop() - * - * @ingroup rtio_tests - */ -ZTEST(rtio_mpsc, test_push_pop) -{ - - struct rtio_mpsc_node *node, *head, *stub, *next, *tail; - - rtio_mpsc_init(&push_pop_q); - - head = atomic_ptr_get(&push_pop_q.head); - tail = push_pop_q.tail; - stub = &push_pop_q.stub; - next = atomic_ptr_get(&stub->next); - - zassert_equal(head, stub, "Head should point at stub"); - zassert_equal(tail, stub, "Tail should point at stub"); - zassert_is_null(next, "Next should be null"); - - node = rtio_mpsc_pop(&push_pop_q); - zassert_is_null(node, "Pop on empty queue should return null"); - - rtio_mpsc_push(&push_pop_q, &push_pop_nodes[0]); - - head = atomic_ptr_get(&push_pop_q.head); - - zassert_equal(head, &push_pop_nodes[0], "Queue head should point at push_pop_node"); - next = atomic_ptr_get(&push_pop_nodes[0].next); - zassert_is_null(next, NULL, "push_pop_node next should point at null"); - next = atomic_ptr_get(&push_pop_q.stub.next); - zassert_equal(next, &push_pop_nodes[0], "Queue stub should point at push_pop_node"); - tail = push_pop_q.tail; - stub = &push_pop_q.stub; - zassert_equal(tail, stub, "Tail should point at stub"); - - node = rtio_mpsc_pop(&push_pop_q); - stub = &push_pop_q.stub; - - zassert_not_equal(node, stub, "Pop should not return stub"); - zassert_not_null(node, "Pop should not return null"); - zassert_equal(node, &push_pop_nodes[0], - "Pop should return push_pop_node %p, instead was %p", - &push_pop_nodes[0], node); - - node = rtio_mpsc_pop(&push_pop_q); - zassert_is_null(node, "Pop on empty queue should return null"); -} - -#define MPSC_FREEQ_SZ 8 -#define MPSC_ITERATIONS 100000 -#define MPSC_STACK_SIZE (512 + CONFIG_TEST_EXTRA_STACK_SIZE) -#define MPSC_THREADS_NUM 4 - -static struct thread_info mpsc_tinfo[MPSC_THREADS_NUM]; -static struct k_thread mpsc_thread[MPSC_THREADS_NUM]; -static K_THREAD_STACK_ARRAY_DEFINE(mpsc_stack, MPSC_THREADS_NUM, MPSC_STACK_SIZE); - -struct mpsc_node { - uint32_t id; - struct rtio_mpsc_node n; -}; - - -RTIO_SPSC_DECLARE(node_sq, struct mpsc_node, MPSC_FREEQ_SZ); - -#define SPSC_INIT(n, sz) RTIO_SPSC_INITIALIZER(sz) - -struct rtio_spsc_node_sq node_q[MPSC_THREADS_NUM] = { - LISTIFY(MPSC_THREADS_NUM, SPSC_INIT, (,), MPSC_FREEQ_SZ) -}; - -static struct rtio_mpsc mpsc_q; - -static void mpsc_consumer(void *p1, void *p2, void *p3) -{ - struct rtio_mpsc_node *n; - struct mpsc_node *nn; - - for (int i = 0; i < (MPSC_ITERATIONS)*(MPSC_THREADS_NUM - 1); i++) { - do { - n = rtio_mpsc_pop(&mpsc_q); - if (n == NULL) { - k_yield(); - } - } while (n == NULL); - - zassert_not_equal(n, &mpsc_q.stub, "mpsc should not produce stub"); - - nn = CONTAINER_OF(n, struct mpsc_node, n); - - rtio_spsc_acquire(&node_q[nn->id]); - rtio_spsc_produce(&node_q[nn->id]); - } -} - -static void mpsc_producer(void *p1, void *p2, void *p3) -{ - struct mpsc_node *n; - uint32_t id = (uint32_t)(uintptr_t)p1; - - for (int i = 0; i < MPSC_ITERATIONS; i++) { - do { - n = rtio_spsc_consume(&node_q[id]); - if (n == NULL) { - k_yield(); - } - } while (n == NULL); - - rtio_spsc_release(&node_q[id]); - n->id = id; - rtio_mpsc_push(&mpsc_q, &n->n); - } -} - -/** - * @brief Test that the producer and consumer are indeed thread safe - * - * This can and should be validated on SMP machines where incoherent - * memory could cause issues. - */ -ZTEST(rtio_mpsc, test_mpsc_threaded) -{ - rtio_mpsc_init(&mpsc_q); - - TC_PRINT("setting up mpsc producer free queues\n"); - /* Setup node free queues */ - for (int i = 0; i < MPSC_THREADS_NUM; i++) { - for (int j = 0; j < MPSC_FREEQ_SZ; j++) { - rtio_spsc_acquire(&node_q[i]); - } - rtio_spsc_produce_all(&node_q[i]); - } - - TC_PRINT("starting consumer\n"); - mpsc_tinfo[0].tid = - k_thread_create(&mpsc_thread[0], mpsc_stack[0], STACK_SIZE, - (k_thread_entry_t)mpsc_consumer, - NULL, NULL, NULL, - K_PRIO_PREEMPT(5), - K_INHERIT_PERMS, K_NO_WAIT); - - for (int i = 1; i < MPSC_THREADS_NUM; i++) { - TC_PRINT("starting producer %i\n", i); - mpsc_tinfo[i].tid = - k_thread_create(&mpsc_thread[i], mpsc_stack[i], STACK_SIZE, - (k_thread_entry_t)mpsc_producer, - (void *)(uintptr_t)i, NULL, NULL, - K_PRIO_PREEMPT(5), - K_INHERIT_PERMS, K_NO_WAIT); - } - - for (int i = 0; i < MPSC_THREADS_NUM; i++) { - TC_PRINT("joining mpsc thread %d\n", i); - k_thread_join(mpsc_tinfo[i].tid, K_FOREVER); - } -} - -RTIO_EXECUTOR_SIMPLE_DEFINE(simple_exec_simp); -RTIO_DEFINE(r_simple_simp, (struct rtio_executor *)&simple_exec_simp, 4, 4); - -RTIO_EXECUTOR_CONCURRENT_DEFINE(simple_exec_con, 1); -RTIO_DEFINE(r_simple_con, (struct rtio_executor *)&simple_exec_con, 4, 4); - -RTIO_IODEV_TEST_DEFINE(iodev_test_simple); - -/** - * @brief Test the basics of the RTIO API - * - * Ensures that we can setup an RTIO context, enqueue a request, and receive - * a completion event. - */ -void test_rtio_simple_(struct rtio *r) -{ - int res; - uintptr_t userdata[2] = {0, 1}; - struct rtio_sqe *sqe; - struct rtio_cqe *cqe; - - rtio_iodev_test_init(&iodev_test_simple); - - TC_PRINT("setting up single no-op\n"); - sqe = rtio_spsc_acquire(r->sq); - zassert_not_null(sqe, "Expected a valid sqe"); - rtio_sqe_prep_nop(sqe, (struct rtio_iodev *)&iodev_test_simple, &userdata[0]); - - TC_PRINT("submit with wait\n"); - res = rtio_submit(r, 1); - zassert_ok(res, "Should return ok from rtio_execute"); - - cqe = rtio_spsc_consume(r->cq); - zassert_not_null(cqe, "Expected a valid cqe"); - zassert_ok(cqe->result, "Result should be ok"); - zassert_equal_ptr(cqe->userdata, &userdata[0], "Expected userdata back"); - rtio_spsc_release(r->cq); -} - -ZTEST(rtio_api, test_rtio_simple) -{ - TC_PRINT("rtio simple simple\n"); - test_rtio_simple_(&r_simple_simp); - TC_PRINT("rtio simple concurrent\n"); - test_rtio_simple_(&r_simple_con); -} - -RTIO_EXECUTOR_SIMPLE_DEFINE(chain_exec_simp); -RTIO_DEFINE(r_chain_simp, (struct rtio_executor *)&chain_exec_simp, 4, 4); - -RTIO_EXECUTOR_CONCURRENT_DEFINE(chain_exec_con, 1); -RTIO_DEFINE(r_chain_con, (struct rtio_executor *)&chain_exec_con, 4, 4); - -RTIO_IODEV_TEST_DEFINE(iodev_test_chain0); -RTIO_IODEV_TEST_DEFINE(iodev_test_chain1); -struct rtio_iodev *iodev_test_chain[] = {&iodev_test_chain0, &iodev_test_chain1}; - -/** - * @brief Test chained requests - * - * Ensures that we can setup an RTIO context, enqueue a chained requests, - * and receive completion events in the correct order given the chained - * flag and multiple devices where serialization isn't guaranteed. - */ -void test_rtio_chain_(struct rtio *r) -{ - int res; - uintptr_t userdata[4] = {0, 1, 2, 3}; - struct rtio_sqe *sqe; - struct rtio_cqe *cqe; - - for (int i = 0; i < 4; i++) { - sqe = rtio_spsc_acquire(r->sq); - zassert_not_null(sqe, "Expected a valid sqe"); - rtio_sqe_prep_nop(sqe, iodev_test_chain[i % 2], - &userdata[i]); - sqe->flags |= RTIO_SQE_CHAINED; - } - - /* Clear the last one */ - sqe->flags = 0; - - TC_PRINT("submitting\n"); - res = rtio_submit(r, 4); - TC_PRINT("checking cq\n"); - zassert_ok(res, "Should return ok from rtio_execute"); - zassert_equal(rtio_spsc_consumable(r->cq), 4, "Should have 4 pending completions"); - - for (int i = 0; i < 4; i++) { - TC_PRINT("consume %d\n", i); - cqe = rtio_spsc_consume(r->cq); - zassert_not_null(cqe, "Expected a valid cqe"); - zassert_ok(cqe->result, "Result should be ok"); - zassert_equal_ptr(cqe->userdata, &userdata[i], "Expected in order completions"); - rtio_spsc_release(r->cq); - } -} - -ZTEST(rtio_api, test_rtio_chain) -{ - TC_PRINT("initializing iodev test devices\n"); - - for (int i = 0; i < 2; i++) { - rtio_iodev_test_init(iodev_test_chain[i]); - } - - TC_PRINT("rtio chain simple\n"); - test_rtio_chain_(&r_chain_simp); - TC_PRINT("rtio chain concurrent\n"); - test_rtio_chain_(&r_chain_con); -} - - -RTIO_EXECUTOR_SIMPLE_DEFINE(multi_exec_simp); -RTIO_DEFINE(r_multi_simp, (struct rtio_executor *)&multi_exec_simp, 4, 4); - -RTIO_EXECUTOR_CONCURRENT_DEFINE(multi_exec_con, 2); -RTIO_DEFINE(r_multi_con, (struct rtio_executor *)&multi_exec_con, 4, 4); - -RTIO_IODEV_TEST_DEFINE(iodev_test_multi0); -RTIO_IODEV_TEST_DEFINE(iodev_test_multi1); -struct rtio_iodev *iodev_test_multi[] = {&iodev_test_multi0, &iodev_test_multi1}; - -/** - * @brief Test multiple asynchronous chains against one iodev - */ -void test_rtio_multiple_chains_(struct rtio *r) -{ - int res; - uintptr_t userdata[4] = {0, 1, 2, 3}; - struct rtio_sqe *sqe; - struct rtio_cqe *cqe; - - for (int i = 0; i < 2; i++) { - for (int j = 0; j < 2; j++) { - sqe = rtio_spsc_acquire(r->sq); - zassert_not_null(sqe, "Expected a valid sqe"); - rtio_sqe_prep_nop(sqe, iodev_test_multi[i], - (void *)userdata[i*2 + j]); - if (j == 0) { - sqe->flags |= RTIO_SQE_CHAINED; - } else { - sqe->flags |= 0; - } - } - } - - TC_PRINT("calling submit from test case\n"); - res = rtio_submit(r, 0); - zassert_ok(res, "Should return ok from rtio_execute"); - - bool seen[4] = { 0 }; - - TC_PRINT("waiting for 4 completions\n"); - for (int i = 0; i < 4; i++) { - TC_PRINT("waiting on completion %d\n", i); - cqe = rtio_spsc_consume(r->cq); - - while (cqe == NULL) { - k_sleep(K_MSEC(1)); - cqe = rtio_spsc_consume(r->cq); - } - - zassert_not_null(cqe, "Expected a valid cqe"); - TC_PRINT("result %d, would block is %d, inval is %d\n", - cqe->result, -EWOULDBLOCK, -EINVAL); - zassert_ok(cqe->result, "Result should be ok"); - seen[(uintptr_t)cqe->userdata] = true; - if (seen[1]) { - zassert_true(seen[0], "Should see 0 before 1"); - } - if (seen[3]) { - zassert_true(seen[2], "Should see 2 before 3"); - } - rtio_spsc_release(r->cq); - } -} - -ZTEST(rtio_api, test_rtio_multiple_chains) -{ - for (int i = 0; i < 2; i++) { - rtio_iodev_test_init(iodev_test_multi[i]); - } - - TC_PRINT("rtio multiple simple\n"); - test_rtio_multiple_chains_(&r_multi_simp); - TC_PRINT("rtio_multiple concurrent\n"); - test_rtio_multiple_chains_(&r_multi_con); -} - - - -#ifdef CONFIG_USERSPACE -K_APPMEM_PARTITION_DEFINE(rtio_partition); -K_APP_BMEM(rtio_partition) uint8_t syscall_bufs[4]; -struct k_mem_domain rtio_domain; -#else -uint8_t syscall_bufs[4]; -#endif - -RTIO_EXECUTOR_SIMPLE_DEFINE(syscall_simple); -RTIO_DEFINE(r_syscall, (struct rtio_executor *)&syscall_simple, 4, 4); -RTIO_IODEV_TEST_DEFINE(iodev_test_syscall); - -void rtio_syscall_test(void *p1, void *p2, void *p3) -{ - int res; - struct rtio_sqe sqe; - struct rtio_cqe cqe; - - struct rtio *r = &r_syscall; - - for (int i = 0; i < 4; i++) { - TC_PRINT("copying sqe in from stack\n"); - /* Not really legal from userspace! Ugh */ - rtio_sqe_prep_nop(&sqe, &iodev_test_syscall, - &syscall_bufs[i]); - res = rtio_sqe_copy_in(r, &sqe, 1); - zassert_equal(res, 0, "Expected success copying sqe"); - } - - TC_PRINT("submitting\n"); - res = rtio_submit(r, 4); - - for (int i = 0; i < 4; i++) { - TC_PRINT("consume %d\n", i); - res = rtio_cqe_copy_out(r, &cqe, 1, K_FOREVER); - zassert_equal(res, 1, "Expected success copying cqe"); - zassert_ok(cqe.result, "Result should be ok"); - zassert_equal_ptr(cqe.userdata, &syscall_bufs[i], - "Expected in order completions"); - } - -} - -#ifdef CONFIG_USERSPACE -ZTEST(rtio_api, test_rtio_syscalls_usermode) -{ - struct k_mem_partition *parts[] = { -#if Z_LIBC_PARTITION_EXISTS - &z_libc_partition, -#endif - &rtio_partition - }; - - TC_PRINT("syscalls from user mode test\n"); - TC_PRINT("test iodev init\n"); - rtio_iodev_test_init(&iodev_test_syscall); - TC_PRINT("mem domain init\n"); - k_mem_domain_init(&rtio_domain, ARRAY_SIZE(parts), parts); - TC_PRINT("mem domain add current\n"); - k_mem_domain_add_thread(&rtio_domain, k_current_get()); - TC_PRINT("rtio access grant\n"); - rtio_access_grant(&r_syscall, k_current_get()); - TC_PRINT("rtio iodev access grant, ptr %p\n", &iodev_test_syscall); - k_object_access_grant(&iodev_test_syscall, k_current_get()); - TC_PRINT("user mode enter\n"); - k_thread_user_mode_enter(rtio_syscall_test, NULL, NULL, NULL); -} -#endif /* CONFIG_USERSPACE */ - - -ZTEST(rtio_api, test_rtio_syscalls) -{ - TC_PRINT("test iodev init\n"); - rtio_iodev_test_init(&iodev_test_syscall); - TC_PRINT("syscalls from kernel mode\n"); - rtio_syscall_test(NULL, NULL, NULL); -} - - - - -ZTEST_SUITE(rtio_spsc, NULL, NULL, NULL, NULL, NULL); -ZTEST_SUITE(rtio_mpsc, NULL, NULL, NULL, NULL, NULL); -ZTEST_SUITE(rtio_api, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/subsys/rtio/rtio_api/src/rtio_api.h b/tests/subsys/rtio/rtio_api/src/rtio_api.h new file mode 100644 index 000000000000..df8d46ae1f7d --- /dev/null +++ b/tests/subsys/rtio/rtio_api/src/rtio_api.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 Intel Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_TEST_RTIO_API_H_ +#define ZEPHYR_TEST_RTIO_API_H_ + +#include + +struct thread_info { + k_tid_t tid; + int executed; + int priority; + int cpu_id; +}; + +#endif /* ZEPHYR_TEST_RTIO_API_H_ */ diff --git a/tests/subsys/rtio/rtio_api/src/test_rtio_api.c b/tests/subsys/rtio/rtio_api/src/test_rtio_api.c new file mode 100644 index 000000000000..5d304e4bd7f5 --- /dev/null +++ b/tests/subsys/rtio/rtio_api/src/test_rtio_api.c @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2021 Intel Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rtio_iodev_test.h" + +RTIO_EXECUTOR_SIMPLE_DEFINE(simple_exec_simp); +RTIO_DEFINE(r_simple_simp, (struct rtio_executor *)&simple_exec_simp, 4, 4); + +RTIO_EXECUTOR_CONCURRENT_DEFINE(simple_exec_con, 1); +RTIO_DEFINE(r_simple_con, (struct rtio_executor *)&simple_exec_con, 4, 4); + +RTIO_IODEV_TEST_DEFINE(iodev_test_simple); + +/** + * @brief Test the basics of the RTIO API + * + * Ensures that we can setup an RTIO context, enqueue a request, and receive + * a completion event. + */ +void test_rtio_simple_(struct rtio *r) +{ + int res; + uintptr_t userdata[2] = {0, 1}; + struct rtio_sqe *sqe; + struct rtio_cqe *cqe; + + rtio_iodev_test_init(&iodev_test_simple); + + TC_PRINT("setting up single no-op\n"); + sqe = rtio_spsc_acquire(r->sq); + zassert_not_null(sqe, "Expected a valid sqe"); + rtio_sqe_prep_nop(sqe, (struct rtio_iodev *)&iodev_test_simple, &userdata[0]); + + TC_PRINT("submit with wait\n"); + res = rtio_submit(r, 1); + zassert_ok(res, "Should return ok from rtio_execute"); + + cqe = rtio_spsc_consume(r->cq); + zassert_not_null(cqe, "Expected a valid cqe"); + zassert_ok(cqe->result, "Result should be ok"); + zassert_equal_ptr(cqe->userdata, &userdata[0], "Expected userdata back"); + rtio_spsc_release(r->cq); +} + +ZTEST(rtio_api, test_rtio_simple) +{ + TC_PRINT("rtio simple simple\n"); + test_rtio_simple_(&r_simple_simp); + TC_PRINT("rtio simple concurrent\n"); + test_rtio_simple_(&r_simple_con); +} + +RTIO_EXECUTOR_SIMPLE_DEFINE(chain_exec_simp); +RTIO_DEFINE(r_chain_simp, (struct rtio_executor *)&chain_exec_simp, 4, 4); + +RTIO_EXECUTOR_CONCURRENT_DEFINE(chain_exec_con, 1); +RTIO_DEFINE(r_chain_con, (struct rtio_executor *)&chain_exec_con, 4, 4); + +RTIO_IODEV_TEST_DEFINE(iodev_test_chain0); +RTIO_IODEV_TEST_DEFINE(iodev_test_chain1); +struct rtio_iodev *iodev_test_chain[] = {&iodev_test_chain0, &iodev_test_chain1}; + +/** + * @brief Test chained requests + * + * Ensures that we can setup an RTIO context, enqueue a chained requests, + * and receive completion events in the correct order given the chained + * flag and multiple devices where serialization isn't guaranteed. + */ +void test_rtio_chain_(struct rtio *r) +{ + int res; + uintptr_t userdata[4] = {0, 1, 2, 3}; + struct rtio_sqe *sqe; + struct rtio_cqe *cqe; + + for (int i = 0; i < 4; i++) { + sqe = rtio_spsc_acquire(r->sq); + zassert_not_null(sqe, "Expected a valid sqe"); + rtio_sqe_prep_nop(sqe, iodev_test_chain[i % 2], + &userdata[i]); + sqe->flags |= RTIO_SQE_CHAINED; + } + + /* Clear the last one */ + sqe->flags = 0; + + TC_PRINT("submitting\n"); + res = rtio_submit(r, 4); + TC_PRINT("checking cq\n"); + zassert_ok(res, "Should return ok from rtio_execute"); + zassert_equal(rtio_spsc_consumable(r->cq), 4, "Should have 4 pending completions"); + + for (int i = 0; i < 4; i++) { + TC_PRINT("consume %d\n", i); + cqe = rtio_spsc_consume(r->cq); + zassert_not_null(cqe, "Expected a valid cqe"); + zassert_ok(cqe->result, "Result should be ok"); + zassert_equal_ptr(cqe->userdata, &userdata[i], "Expected in order completions"); + rtio_spsc_release(r->cq); + } +} + +ZTEST(rtio_api, test_rtio_chain) +{ + TC_PRINT("initializing iodev test devices\n"); + + for (int i = 0; i < 2; i++) { + rtio_iodev_test_init(iodev_test_chain[i]); + } + + TC_PRINT("rtio chain simple\n"); + test_rtio_chain_(&r_chain_simp); + TC_PRINT("rtio chain concurrent\n"); + test_rtio_chain_(&r_chain_con); +} + + +RTIO_EXECUTOR_SIMPLE_DEFINE(multi_exec_simp); +RTIO_DEFINE(r_multi_simp, (struct rtio_executor *)&multi_exec_simp, 4, 4); + +RTIO_EXECUTOR_CONCURRENT_DEFINE(multi_exec_con, 2); +RTIO_DEFINE(r_multi_con, (struct rtio_executor *)&multi_exec_con, 4, 4); + +RTIO_IODEV_TEST_DEFINE(iodev_test_multi0); +RTIO_IODEV_TEST_DEFINE(iodev_test_multi1); +struct rtio_iodev *iodev_test_multi[] = {&iodev_test_multi0, &iodev_test_multi1}; + +/** + * @brief Test multiple asynchronous chains against one iodev + */ +void test_rtio_multiple_chains_(struct rtio *r) +{ + int res; + uintptr_t userdata[4] = {0, 1, 2, 3}; + struct rtio_sqe *sqe; + struct rtio_cqe *cqe; + + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + sqe = rtio_spsc_acquire(r->sq); + zassert_not_null(sqe, "Expected a valid sqe"); + rtio_sqe_prep_nop(sqe, iodev_test_multi[i], + (void *)userdata[i*2 + j]); + if (j == 0) { + sqe->flags |= RTIO_SQE_CHAINED; + } else { + sqe->flags |= 0; + } + } + } + + TC_PRINT("calling submit from test case\n"); + res = rtio_submit(r, 0); + zassert_ok(res, "Should return ok from rtio_execute"); + + bool seen[4] = { 0 }; + + TC_PRINT("waiting for 4 completions\n"); + for (int i = 0; i < 4; i++) { + TC_PRINT("waiting on completion %d\n", i); + cqe = rtio_spsc_consume(r->cq); + + while (cqe == NULL) { + k_sleep(K_MSEC(1)); + cqe = rtio_spsc_consume(r->cq); + } + + zassert_not_null(cqe, "Expected a valid cqe"); + TC_PRINT("result %d, would block is %d, inval is %d\n", + cqe->result, -EWOULDBLOCK, -EINVAL); + zassert_ok(cqe->result, "Result should be ok"); + seen[(uintptr_t)cqe->userdata] = true; + if (seen[1]) { + zassert_true(seen[0], "Should see 0 before 1"); + } + if (seen[3]) { + zassert_true(seen[2], "Should see 2 before 3"); + } + rtio_spsc_release(r->cq); + } +} + +ZTEST(rtio_api, test_rtio_multiple_chains) +{ + for (int i = 0; i < 2; i++) { + rtio_iodev_test_init(iodev_test_multi[i]); + } + + TC_PRINT("rtio multiple simple\n"); + test_rtio_multiple_chains_(&r_multi_simp); + TC_PRINT("rtio_multiple concurrent\n"); + test_rtio_multiple_chains_(&r_multi_con); +} + + + +#ifdef CONFIG_USERSPACE +K_APPMEM_PARTITION_DEFINE(rtio_partition); +K_APP_BMEM(rtio_partition) uint8_t syscall_bufs[4]; +struct k_mem_domain rtio_domain; +#else +uint8_t syscall_bufs[4]; +#endif + +RTIO_EXECUTOR_SIMPLE_DEFINE(syscall_simple); +RTIO_DEFINE(r_syscall, (struct rtio_executor *)&syscall_simple, 4, 4); +RTIO_IODEV_TEST_DEFINE(iodev_test_syscall); + +void rtio_syscall_test(void *p1, void *p2, void *p3) +{ + int res; + struct rtio_sqe sqe; + struct rtio_cqe cqe; + + struct rtio *r = &r_syscall; + + for (int i = 0; i < 4; i++) { + TC_PRINT("copying sqe in from stack\n"); + /* Not really legal from userspace! Ugh */ + rtio_sqe_prep_nop(&sqe, &iodev_test_syscall, + &syscall_bufs[i]); + res = rtio_sqe_copy_in(r, &sqe, 1); + zassert_equal(res, 0, "Expected success copying sqe"); + } + + TC_PRINT("submitting\n"); + res = rtio_submit(r, 4); + + for (int i = 0; i < 4; i++) { + TC_PRINT("consume %d\n", i); + res = rtio_cqe_copy_out(r, &cqe, 1, K_FOREVER); + zassert_equal(res, 1, "Expected success copying cqe"); + zassert_ok(cqe.result, "Result should be ok"); + zassert_equal_ptr(cqe.userdata, &syscall_bufs[i], + "Expected in order completions"); + } +} + +#ifdef CONFIG_USERSPACE +ZTEST(rtio_api, test_rtio_syscalls_usermode) +{ + struct k_mem_partition *parts[] = { +#if Z_LIBC_PARTITION_EXISTS + &z_libc_partition, +#endif + &rtio_partition + }; + + TC_PRINT("syscalls from user mode test\n"); + TC_PRINT("test iodev init\n"); + rtio_iodev_test_init(&iodev_test_syscall); + TC_PRINT("mem domain init\n"); + k_mem_domain_init(&rtio_domain, ARRAY_SIZE(parts), parts); + TC_PRINT("mem domain add current\n"); + k_mem_domain_add_thread(&rtio_domain, k_current_get()); + TC_PRINT("rtio access grant\n"); + rtio_access_grant(&r_syscall, k_current_get()); + TC_PRINT("rtio iodev access grant, ptr %p\n", &iodev_test_syscall); + k_object_access_grant(&iodev_test_syscall, k_current_get()); + TC_PRINT("user mode enter\n"); + k_thread_user_mode_enter(rtio_syscall_test, NULL, NULL, NULL); +} +#endif /* CONFIG_USERSPACE */ + + +ZTEST(rtio_api, test_rtio_syscalls) +{ + TC_PRINT("test iodev init\n"); + rtio_iodev_test_init(&iodev_test_syscall); + TC_PRINT("syscalls from kernel mode\n"); + rtio_syscall_test(NULL, NULL, NULL); +} + +ZTEST_SUITE(rtio_api, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/subsys/rtio/rtio_api/src/test_rtio_mpsc.c b/tests/subsys/rtio/rtio_api/src/test_rtio_mpsc.c new file mode 100644 index 000000000000..561b1064f493 --- /dev/null +++ b/tests/subsys/rtio/rtio_api/src/test_rtio_mpsc.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2023 Intel Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +#include "rtio_api.h" + +static struct rtio_mpsc push_pop_q; +static struct rtio_mpsc_node push_pop_nodes[2]; + +/* + * @brief Push and pop one element + * + * @see rtio_mpsc_push(), rtio_mpsc_pop() + * + * @ingroup rtio_tests + */ +ZTEST(rtio_mpsc, test_push_pop) +{ + + struct rtio_mpsc_node *node, *head, *stub, *next, *tail; + + rtio_mpsc_init(&push_pop_q); + + head = atomic_ptr_get(&push_pop_q.head); + tail = push_pop_q.tail; + stub = &push_pop_q.stub; + next = atomic_ptr_get(&stub->next); + + zassert_equal(head, stub, "Head should point at stub"); + zassert_equal(tail, stub, "Tail should point at stub"); + zassert_is_null(next, "Next should be null"); + + node = rtio_mpsc_pop(&push_pop_q); + zassert_is_null(node, "Pop on empty queue should return null"); + + rtio_mpsc_push(&push_pop_q, &push_pop_nodes[0]); + + head = atomic_ptr_get(&push_pop_q.head); + + zassert_equal(head, &push_pop_nodes[0], "Queue head should point at push_pop_node"); + next = atomic_ptr_get(&push_pop_nodes[0].next); + zassert_is_null(next, NULL, "push_pop_node next should point at null"); + next = atomic_ptr_get(&push_pop_q.stub.next); + zassert_equal(next, &push_pop_nodes[0], "Queue stub should point at push_pop_node"); + tail = push_pop_q.tail; + stub = &push_pop_q.stub; + zassert_equal(tail, stub, "Tail should point at stub"); + + node = rtio_mpsc_pop(&push_pop_q); + stub = &push_pop_q.stub; + + zassert_not_equal(node, stub, "Pop should not return stub"); + zassert_not_null(node, "Pop should not return null"); + zassert_equal(node, &push_pop_nodes[0], + "Pop should return push_pop_node %p, instead was %p", + &push_pop_nodes[0], node); + + node = rtio_mpsc_pop(&push_pop_q); + zassert_is_null(node, "Pop on empty queue should return null"); +} + +#define MPSC_FREEQ_SZ 8 +#define MPSC_ITERATIONS 100000 +#define MPSC_STACK_SIZE (512 + CONFIG_TEST_EXTRA_STACK_SIZE) +#define MPSC_THREADS_NUM 4 + +static struct thread_info mpsc_tinfo[MPSC_THREADS_NUM]; +static struct k_thread mpsc_thread[MPSC_THREADS_NUM]; +static K_THREAD_STACK_ARRAY_DEFINE(mpsc_stack, MPSC_THREADS_NUM, MPSC_STACK_SIZE); + +struct mpsc_node { + uint32_t id; + struct rtio_mpsc_node n; +}; + + +RTIO_SPSC_DECLARE(node_sq, struct mpsc_node, MPSC_FREEQ_SZ); + +#define SPSC_INIT(n, sz) RTIO_SPSC_INITIALIZER(sz) + +struct rtio_spsc_node_sq node_q[MPSC_THREADS_NUM] = { + LISTIFY(MPSC_THREADS_NUM, SPSC_INIT, (,), MPSC_FREEQ_SZ) +}; + +static struct rtio_mpsc mpsc_q; + +static void mpsc_consumer(void *p1, void *p2, void *p3) +{ + struct rtio_mpsc_node *n; + struct mpsc_node *nn; + + for (int i = 0; i < (MPSC_ITERATIONS)*(MPSC_THREADS_NUM - 1); i++) { + do { + n = rtio_mpsc_pop(&mpsc_q); + if (n == NULL) { + k_yield(); + } + } while (n == NULL); + + zassert_not_equal(n, &mpsc_q.stub, "mpsc should not produce stub"); + + nn = CONTAINER_OF(n, struct mpsc_node, n); + + rtio_spsc_acquire(&node_q[nn->id]); + rtio_spsc_produce(&node_q[nn->id]); + } +} + +static void mpsc_producer(void *p1, void *p2, void *p3) +{ + struct mpsc_node *n; + uint32_t id = (uint32_t)(uintptr_t)p1; + + for (int i = 0; i < MPSC_ITERATIONS; i++) { + do { + n = rtio_spsc_consume(&node_q[id]); + if (n == NULL) { + k_yield(); + } + } while (n == NULL); + + rtio_spsc_release(&node_q[id]); + n->id = id; + rtio_mpsc_push(&mpsc_q, &n->n); + } +} + +/** + * @brief Test that the producer and consumer are indeed thread safe + * + * This can and should be validated on SMP machines where incoherent + * memory could cause issues. + */ +ZTEST(rtio_mpsc, test_mpsc_threaded) +{ + rtio_mpsc_init(&mpsc_q); + + TC_PRINT("setting up mpsc producer free queues\n"); + /* Setup node free queues */ + for (int i = 0; i < MPSC_THREADS_NUM; i++) { + for (int j = 0; j < MPSC_FREEQ_SZ; j++) { + rtio_spsc_acquire(&node_q[i]); + } + rtio_spsc_produce_all(&node_q[i]); + } + + TC_PRINT("starting consumer\n"); + mpsc_tinfo[0].tid = + k_thread_create(&mpsc_thread[0], mpsc_stack[0], MPSC_STACK_SIZE, + (k_thread_entry_t)mpsc_consumer, + NULL, NULL, NULL, + K_PRIO_PREEMPT(5), + K_INHERIT_PERMS, K_NO_WAIT); + + for (int i = 1; i < MPSC_THREADS_NUM; i++) { + TC_PRINT("starting producer %i\n", i); + mpsc_tinfo[i].tid = + k_thread_create(&mpsc_thread[i], mpsc_stack[i], MPSC_STACK_SIZE, + (k_thread_entry_t)mpsc_producer, + (void *)(uintptr_t)i, NULL, NULL, + K_PRIO_PREEMPT(5), + K_INHERIT_PERMS, K_NO_WAIT); + } + + for (int i = 0; i < MPSC_THREADS_NUM; i++) { + TC_PRINT("joining mpsc thread %d\n", i); + k_thread_join(mpsc_tinfo[i].tid, K_FOREVER); + } +} + +ZTEST_SUITE(rtio_mpsc, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/subsys/rtio/rtio_api/src/test_rtio_spsc.c b/tests/subsys/rtio/rtio_api/src/test_rtio_spsc.c new file mode 100644 index 000000000000..9dda0960dbce --- /dev/null +++ b/tests/subsys/rtio/rtio_api/src/test_rtio_spsc.c @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2023 Intel Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "rtio_api.h" + +/* + * @brief Produce and Consume a single uint32_t in the same execution context + * + * @see rtio_spsc_acquire(), rtio_spsc_produce(), rtio_spsc_consume(), rtio_spsc_release() + * + * @ingroup rtio_tests + */ +ZTEST(rtio_spsc, test_produce_consume_size1) +{ + RTIO_SPSC_DEFINE(ezspsc, uint32_t, 1); + + const uint32_t magic = 43219876; + + uint32_t *acq = rtio_spsc_acquire(&ezspsc); + + zassert_not_null(acq, "Acquire should succeed"); + + *acq = magic; + + uint32_t *acq2 = rtio_spsc_acquire(&ezspsc); + + zassert_is_null(acq2, "Acquire should fail"); + + uint32_t *cons = rtio_spsc_consume(&ezspsc); + + zassert_is_null(cons, "Consume should fail"); + + zassert_equal(rtio_spsc_consumable(&ezspsc), 0, "Consumables should be 0"); + + rtio_spsc_produce(&ezspsc); + + zassert_equal(rtio_spsc_consumable(&ezspsc), 1, "Consumables should be 1"); + + uint32_t *cons2 = rtio_spsc_consume(&ezspsc); + + zassert_equal(rtio_spsc_consumable(&ezspsc), 0, "Consumables should be 0"); + + zassert_not_null(cons2, "Consume should not fail"); + zassert_equal(*cons2, magic, "Consume value should equal magic"); + + uint32_t *cons3 = rtio_spsc_consume(&ezspsc); + + zassert_is_null(cons3, "Consume should fail"); + + + uint32_t *acq3 = rtio_spsc_acquire(&ezspsc); + + zassert_is_null(acq3, "Acquire should not succeed"); + + rtio_spsc_release(&ezspsc); + + uint32_t *acq4 = rtio_spsc_acquire(&ezspsc); + + zassert_not_null(acq4, "Acquire should succeed"); +} + +/*&* + * @brief Produce and Consume 3 items at a time in a spsc of size 4 to validate masking + * and wrap around reads/writes. + * + * @see rtio_spsc_acquire(), rtio_spsc_produce(), rtio_spsc_consume(), rtio_spsc_release() + * + * @ingroup rtio_tests + */ +ZTEST(rtio_spsc, test_produce_consume_wrap_around) +{ + RTIO_SPSC_DEFINE(ezspsc, uint32_t, 4); + + for (int i = 0; i < 10; i++) { + zassert_equal(rtio_spsc_consumable(&ezspsc), 0, "Consumables should be 0"); + for (int j = 0; j < 3; j++) { + uint32_t *entry = rtio_spsc_acquire(&ezspsc); + + zassert_not_null(entry, "Acquire should succeed"); + *entry = i * 3 + j; + rtio_spsc_produce(&ezspsc); + } + zassert_equal(rtio_spsc_consumable(&ezspsc), 3, "Consumables should be 3"); + + for (int k = 0; k < 3; k++) { + uint32_t *entry = rtio_spsc_consume(&ezspsc); + + zassert_not_null(entry, "Consume should succeed"); + zassert_equal(*entry, i * 3 + k, "Consume value should equal i*3+k"); + rtio_spsc_release(&ezspsc); + } + + zassert_equal(rtio_spsc_consumable(&ezspsc), 0, "Consumables should be 0"); + + } +} + +/** + * @brief Ensure that integer wraps continue to work. + * + * Done by setting all values to UINTPTR_MAX - 2 and writing and reading enough + * to ensure integer wraps occur. + */ +ZTEST(rtio_spsc, test_int_wrap_around) +{ + RTIO_SPSC_DEFINE(ezspsc, uint32_t, 4); + ezspsc._spsc.in = ATOMIC_INIT(UINTPTR_MAX - 2); + ezspsc._spsc.out = ATOMIC_INIT(UINTPTR_MAX - 2); + + for (int j = 0; j < 3; j++) { + uint32_t *entry = rtio_spsc_acquire(&ezspsc); + + zassert_not_null(entry, "Acquire should succeed"); + *entry = j; + rtio_spsc_produce(&ezspsc); + } + + zassert_equal(atomic_get(&ezspsc._spsc.in), UINTPTR_MAX + 1, "Spsc in should wrap"); + + for (int k = 0; k < 3; k++) { + uint32_t *entry = rtio_spsc_consume(&ezspsc); + + zassert_not_null(entry, "Consume should succeed"); + zassert_equal(*entry, k, "Consume value should equal i*3+k"); + rtio_spsc_release(&ezspsc); + } + + zassert_equal(atomic_get(&ezspsc._spsc.out), UINTPTR_MAX + 1, "Spsc out should wrap"); +} + +#define MAX_RETRIES 5 +#define SMP_ITERATIONS 100 + +RTIO_SPSC_DEFINE(spsc, uint32_t, 4); + +static void t1_consume(void *p1, void *p2, void *p3) +{ + struct rtio_spsc_spsc *ezspsc = p1; + uint32_t retries = 0; + uint32_t *val = NULL; + + for (int i = 0; i < SMP_ITERATIONS; i++) { + val = NULL; + retries = 0; + while (val == NULL && retries < MAX_RETRIES) { + val = rtio_spsc_consume(ezspsc); + retries++; + } + if (val != NULL) { + rtio_spsc_release(ezspsc); + } else { + k_yield(); + } + } +} + +static void t2_produce(void *p1, void *p2, void *p3) +{ + struct rtio_spsc_spsc *ezspsc = p1; + uint32_t retries = 0; + uint32_t *val = NULL; + + for (int i = 0; i < SMP_ITERATIONS; i++) { + val = NULL; + retries = 0; + while (val == NULL && retries < MAX_RETRIES) { + val = rtio_spsc_acquire(ezspsc); + retries++; + } + if (val != NULL) { + *val = SMP_ITERATIONS; + rtio_spsc_produce(ezspsc); + } else { + k_yield(); + } + } +} + + +#define STACK_SIZE (384 + CONFIG_TEST_EXTRA_STACK_SIZE) +#define THREADS_NUM 2 + +static struct thread_info tinfo[THREADS_NUM]; +static struct k_thread tthread[THREADS_NUM]; +static K_THREAD_STACK_ARRAY_DEFINE(tstack, THREADS_NUM, STACK_SIZE); + +/** + * @brief Test that the producer and consumer are indeed thread safe + * + * This can and should be validated on SMP machines where incoherent + * memory could cause issues. + */ +ZTEST(rtio_spsc, test_spsc_threaded) +{ + + tinfo[0].tid = + k_thread_create(&tthread[0], tstack[0], STACK_SIZE, + (k_thread_entry_t)t1_consume, + &spsc, NULL, NULL, + K_PRIO_PREEMPT(5), + K_INHERIT_PERMS, K_NO_WAIT); + tinfo[1].tid = + k_thread_create(&tthread[1], tstack[1], STACK_SIZE, + (k_thread_entry_t)t2_produce, + &spsc, NULL, NULL, + K_PRIO_PREEMPT(5), + K_INHERIT_PERMS, K_NO_WAIT); + + k_thread_join(tinfo[1].tid, K_FOREVER); + k_thread_join(tinfo[0].tid, K_FOREVER); +} + +ZTEST_SUITE(rtio_spsc, NULL, NULL, NULL, NULL, NULL); From 3353342e5f018cf846401d3af0c79284c1c7a55b Mon Sep 17 00:00:00 2001 From: Tom Burdick Date: Fri, 24 Feb 2023 17:43:59 -0600 Subject: [PATCH 0360/1906] rtio: Add transactional submissions Transactional submissions treat a sequence of sqes as a single atomic submission given to a single iodev and expect as a reply a single completion. This is useful for scatter gather like APIs that exist in Zephyr already for I2C and SPI. Signed-off-by: Tom Burdick --- include/zephyr/rtio/rtio.h | 16 ++ subsys/rtio/rtio_executor_concurrent.c | 184 +++++++++--------- subsys/rtio/rtio_executor_simple.c | 79 ++++++-- .../rtio/rtio_api/src/rtio_iodev_test.h | 13 +- .../subsys/rtio/rtio_api/src/test_rtio_api.c | 115 ++++++++++- 5 files changed, 286 insertions(+), 121 deletions(-) diff --git a/include/zephyr/rtio/rtio.h b/include/zephyr/rtio/rtio.h index 8a40b867eea1..df3dd72e4289 100644 --- a/include/zephyr/rtio/rtio.h +++ b/include/zephyr/rtio/rtio.h @@ -97,9 +97,25 @@ struct rtio_iodev; /** * @brief The next request in the queue should wait on this one. + * + * Chained SQEs are individual units of work describing patterns of + * ordering and failure cascading. A chained SQE must be started only + * after the one before it. They are given to the iodevs one after another. */ #define RTIO_SQE_CHAINED BIT(0) +/** + * @brief The next request in the queue is part of a transaction. + * + * Transactional SQEs are sequential parts of a unit of work. + * Only the first transactional SQE is submitted to an iodev, the + * remaining SQEs are never individually submitted but instead considered + * to be part of the transaction to the single iodev. The first sqe in the + * sequence holds the iodev that will be used and the last holds the userdata + * that will be returned in a single completion on failure/success. + */ +#define RTIO_SQE_TRANSACTION BIT(1) + /** * @} */ diff --git a/subsys/rtio/rtio_executor_concurrent.c b/subsys/rtio/rtio_executor_concurrent.c index ae6c361f0018..e5618c830540 100644 --- a/subsys/rtio/rtio_executor_concurrent.c +++ b/subsys/rtio/rtio_executor_concurrent.c @@ -49,7 +49,7 @@ static uint16_t conex_task_next(struct rtio_concurrent_executor *exc) uint16_t task_id = exc->task_in; exc->task_in++; - return task_id; + return task_id & exc->task_mask; } static inline uint16_t conex_task_id(struct rtio_concurrent_executor *exc, @@ -64,7 +64,7 @@ static void conex_sweep_task(struct rtio *r, struct rtio_concurrent_executor *ex { struct rtio_sqe *sqe = rtio_spsc_consume(r->sq); - while (sqe != NULL && sqe->flags & RTIO_SQE_CHAINED) { + while (sqe != NULL && (sqe->flags & (RTIO_SQE_CHAINED | RTIO_SQE_TRANSACTION))) { rtio_spsc_release(r->sq); sqe = rtio_spsc_consume(r->sq); } @@ -72,6 +72,13 @@ static void conex_sweep_task(struct rtio *r, struct rtio_concurrent_executor *ex rtio_spsc_release(r->sq); } +/** + * @brief Sweep like a GC of sorts old tasks that are completed in order + * + * Will only sweep tasks in the order they arrived in the submission queue. + * Meaning there might be completed tasks that could be freed but are not yet + * because something before it has not yet completed. + */ static void conex_sweep(struct rtio *r, struct rtio_concurrent_executor *exc) { /* In order sweep up */ @@ -86,21 +93,77 @@ static void conex_sweep(struct rtio *r, struct rtio_concurrent_executor *exc) } } +/** + * @brief Prepare tasks to run by iterating through the submission queue + * + * For each submission in the queue that begins a chain or transaction + * start a task if possible. Concurrency is limited by the allocated concurrency + * per executor instance. + */ +static void conex_prepare(struct rtio *r, struct rtio_concurrent_executor *exc) +{ + struct rtio_sqe *sqe; + + /* If never submitted before peek at the first item + * otherwise start back up where the last submit call + * left off + */ + if (exc->pending_sqe == NULL) { + sqe = rtio_spsc_peek(r->sq); + } else { + sqe = exc->pending_sqe; + } + + while (sqe != NULL && conex_task_free(exc)) { + /* Get the next free task id */ + uint16_t task_idx = conex_task_next(exc); + + /* Setup task */ + exc->task_cur[task_idx].sqe = sqe; + exc->task_cur[task_idx].r = r; + exc->task_status[task_idx] = CONEX_TASK_SUSPENDED; + + /* Go to the next sqe not in the current chain or transaction */ + while (sqe != NULL && (sqe->flags & (RTIO_SQE_CHAINED | RTIO_SQE_TRANSACTION))) { + sqe = rtio_spsc_next(r->sq, sqe); + } + + /* SQE is the end of the previous chain or transaction so skip it */ + sqe = rtio_spsc_next(r->sq, sqe); + } + + /* Out of available tasks so remember where we left off to begin again once tasks free up */ + exc->pending_sqe = sqe; +} + + +/** + * @brief Resume tasks that are suspended + * + * All tasks begin as suspended tasks. This kicks them off to the submissions + * associated iodev. + */ static void conex_resume(struct rtio *r, struct rtio_concurrent_executor *exc) { /* In order resume tasks */ for (uint16_t task_id = exc->task_out; task_id < exc->task_in; task_id++) { if (exc->task_status[task_id & exc->task_mask] & CONEX_TASK_SUSPENDED) { LOG_INF("resuming suspended task %d", task_id); - exc->task_status[task_id] &= ~CONEX_TASK_SUSPENDED; - rtio_iodev_submit(&exc->task_cur[task_id]); + exc->task_status[task_id & exc->task_mask] &= ~CONEX_TASK_SUSPENDED; + rtio_iodev_submit(&exc->task_cur[task_id & exc->task_mask]); } } } +/** + * @brief Sweep, Prepare, and Resume in one go + * + * Called after a completion to continue doing more work if needed. + */ static void conex_sweep_resume(struct rtio *r, struct rtio_concurrent_executor *exc) { conex_sweep(r, exc); + conex_prepare(r, exc); conex_resume(r, exc); } @@ -114,71 +177,14 @@ static void conex_sweep_resume(struct rtio *r, struct rtio_concurrent_executor * int rtio_concurrent_submit(struct rtio *r) { - LOG_INF("submit"); - struct rtio_concurrent_executor *exc = (struct rtio_concurrent_executor *)r->executor; - struct rtio_sqe *sqe; - struct rtio_sqe *last_sqe; k_spinlock_key_t key; key = k_spin_lock(&exc->lock); - /* If never submitted before peek at the first item - * otherwise start back up where the last submit call - * left off - */ - if (exc->last_sqe == NULL) { - sqe = rtio_spsc_peek(r->sq); - } else { - /* Pickup from last submit call */ - sqe = rtio_spsc_next(r->sq, exc->last_sqe); - } - - last_sqe = sqe; - while (sqe != NULL && conex_task_free(exc)) { - LOG_INF("head SQE in chain %p", sqe); - - /* Get the next task id if one exists */ - uint16_t task_idx = conex_task_next(exc); - - LOG_INF("setting up task %d", task_idx); - - /* Setup task (yes this is it) */ - exc->task_cur[task_idx].sqe = sqe; - exc->task_cur[task_idx].r = r; - exc->task_status[task_idx] = CONEX_TASK_SUSPENDED; - - LOG_INF("submitted sqe %p", sqe); - /* Go to the next sqe not in the current chain */ - while (sqe != NULL && (sqe->flags & RTIO_SQE_CHAINED)) { - sqe = rtio_spsc_next(r->sq, sqe); - } - - LOG_INF("tail SQE in chain %p", sqe); - - last_sqe = sqe; - - /* SQE is the end of the previous chain */ - sqe = rtio_spsc_next(r->sq, sqe); - } - - /* Out of available pointers, wait til others complete, note the - * first pending submission queue. May be NULL if nothing is pending. - */ - exc->pending_sqe = sqe; - - /** - * Run through the queue until the last item - * and take not of it - */ - while (sqe != NULL) { - last_sqe = sqe; - sqe = rtio_spsc_next(r->sq, sqe); - } - - /* Note the last sqe for the next submit call */ - exc->last_sqe = last_sqe; + /* Prepare tasks to run, they start in a suspended state */ + conex_prepare(r, exc); /* Resume all suspended tasks */ conex_resume(r, exc); @@ -202,14 +208,9 @@ void rtio_concurrent_ok(struct rtio_iodev_sqe *iodev_sqe, int result) /* Interrupt may occur in spsc_acquire, breaking the contract * so spin around it effectively preventing another interrupt on * this core, and another core trying to concurrently work in here. - * - * This can and should be broken up into a few sections with a try - * lock around the sweep and resume. */ key = k_spin_lock(&exc->lock); - rtio_cqe_submit(r, result, sqe->userdata); - /* Determine the task id by memory offset O(1) */ uint16_t task_id = conex_task_id(exc, iodev_sqe); @@ -218,16 +219,19 @@ void rtio_concurrent_ok(struct rtio_iodev_sqe *iodev_sqe, int result) exc->task_cur[task_id].sqe = next_sqe; rtio_iodev_submit(&exc->task_cur[task_id]); - } else { exc->task_status[task_id] |= CONEX_TASK_COMPLETE; } + bool transaction = sqe->flags & RTIO_SQE_TRANSACTION; + + while (transaction) { + sqe = rtio_spsc_next(r->sq, sqe); + transaction = sqe->flags & RTIO_SQE_TRANSACTION; + } + + rtio_cqe_submit(r, result, sqe->userdata); - /* Sweep up unused SQEs and tasks, retry suspended tasks */ - /* TODO Use a try lock here and don't bother doing it if we are already - * doing it elsewhere - */ conex_sweep_resume(r, exc); k_spin_unlock(&exc->lock, key); @@ -238,39 +242,41 @@ void rtio_concurrent_ok(struct rtio_iodev_sqe *iodev_sqe, int result) */ void rtio_concurrent_err(struct rtio_iodev_sqe *iodev_sqe, int result) { - const struct rtio_sqe *nsqe; k_spinlock_key_t key; struct rtio *r = iodev_sqe->r; const struct rtio_sqe *sqe = iodev_sqe->sqe; struct rtio_concurrent_executor *exc = (struct rtio_concurrent_executor *)r->executor; + void *userdata = sqe->userdata; + bool chained = sqe->flags & RTIO_SQE_CHAINED; + bool transaction = sqe->flags & RTIO_SQE_TRANSACTION; + uint16_t task_id = conex_task_id(exc, iodev_sqe); /* Another interrupt (and sqe complete) may occur in spsc_acquire, * breaking the contract so spin around it effectively preventing another * interrupt on this core, and another core trying to concurrently work * in here. - * - * This can and should be broken up into a few sections with a try - * lock around the sweep and resume. */ key = k_spin_lock(&exc->lock); - rtio_cqe_submit(r, result, sqe->userdata); - - /* Determine the task id : O(1) */ - uint16_t task_id = conex_task_id(exc, iodev_sqe); + if (!transaction) { + rtio_cqe_submit(r, result, userdata); + } - sqe = iodev_sqe->sqe; + /* While the last sqe was marked as chained or transactional, do more work */ + while (chained | transaction) { + sqe = rtio_spsc_next(r->sq, sqe); + chained = sqe->flags & RTIO_SQE_CHAINED; + transaction = sqe->flags & RTIO_SQE_TRANSACTION; + userdata = sqe->userdata; - /* Fail the remaining sqe's in the chain */ - if (sqe->flags & RTIO_SQE_CHAINED) { - nsqe = rtio_spsc_next(r->sq, sqe); - while (nsqe != NULL && nsqe->flags & RTIO_SQE_CHAINED) { - rtio_cqe_submit(r, -ECANCELED, nsqe->userdata); - nsqe = rtio_spsc_next(r->sq, nsqe); + if (!transaction) { + rtio_cqe_submit(r, result, userdata); + } else { + rtio_cqe_submit(r, -ECANCELED, userdata); } } - /* Task is complete (failed) */ + /* Determine the task id : O(1) */ exc->task_status[task_id] |= CONEX_TASK_COMPLETE; conex_sweep_resume(r, exc); diff --git a/subsys/rtio/rtio_executor_simple.c b/subsys/rtio/rtio_executor_simple.c index 47515f237ade..26645e8511bf 100644 --- a/subsys/rtio/rtio_executor_simple.c +++ b/subsys/rtio/rtio_executor_simple.c @@ -33,6 +33,31 @@ int rtio_simple_submit(struct rtio *r) struct rtio_sqe *sqe = rtio_spsc_consume(r->sq); + if (sqe == NULL) { + return 0; + } + + /* Some validation on the sqe to ensure no programming errors were + * made so assumptions in ok and err are valid. + */ +#ifdef CONFIG_ASSERT + __ASSERT(sqe != NULL, "Expected a valid sqe on submit call"); + + bool transaction = sqe->flags & RTIO_SQE_TRANSACTION; + bool chained = sqe->flags & RTIO_SQE_CHAINED; + + if (transaction || chained) { + struct rtio_sqe *next = rtio_spsc_next(r->sq, sqe); + + __ASSERT(next != NULL, + "sqe %p flagged as transaction (%d) or chained (%d) without subsequent sqe in queue", + sqe, transaction, chained); + } + __ASSERT(!(chained && transaction), + "sqe %p flagged as both being transaction and chained, only one is allowed", + sqe); +#endif + exc->task.sqe = sqe; exc->task.r = r; @@ -58,24 +83,38 @@ void rtio_simple_ok(struct rtio_iodev_sqe *iodev_sqe, int result) __ASSERT_NO_MSG(iodev_sqe == &exc->task); #endif + bool transaction = sqe->flags & RTIO_SQE_TRANSACTION; + + while (transaction) { + rtio_spsc_release(r->sq); + sqe = rtio_spsc_consume(r->sq); + __ASSERT_NO_MSG(sqe != NULL); + transaction = sqe->flags & RTIO_SQE_TRANSACTION; + } + void *userdata = sqe->userdata; rtio_spsc_release(r->sq); iodev_sqe->sqe = NULL; + rtio_cqe_submit(r, result, userdata); rtio_simple_submit(r); } /** * @brief Callback from an iodev describing error + * + * Some assumptions are made and should have been validated on rtio_submit + * - a sqe marked as chained or transaction has a next sqe + * - a sqe is marked either chained or transaction but not both */ void rtio_simple_err(struct rtio_iodev_sqe *iodev_sqe, int result) { - const struct rtio_sqe *nsqe; + const struct rtio_sqe *sqe = iodev_sqe->sqe; struct rtio *r = iodev_sqe->r; - const struct rtio_sqe *sqe = iodev_sqe->sqe; void *userdata = sqe->userdata; bool chained = sqe->flags & RTIO_SQE_CHAINED; + bool transaction = sqe->flags & RTIO_SQE_TRANSACTION; #ifdef CONFIG_ASSERT struct rtio_simple_executor *exc = @@ -84,29 +123,27 @@ void rtio_simple_err(struct rtio_iodev_sqe *iodev_sqe, int result) __ASSERT_NO_MSG(iodev_sqe == &exc->task); #endif - rtio_spsc_release(r->sq); iodev_sqe->sqe = NULL; - rtio_cqe_submit(r, result, sqe->userdata); - - if (chained) { - - nsqe = rtio_spsc_consume(r->sq); - while (nsqe != NULL && nsqe->flags & RTIO_SQE_CHAINED) { - userdata = nsqe->userdata; - rtio_spsc_release(r->sq); + if (!transaction) { + rtio_cqe_submit(r, result, userdata); + } + while (chained | transaction) { + sqe = rtio_spsc_consume(r->sq); + chained = sqe->flags & RTIO_SQE_CHAINED; + transaction = sqe->flags & RTIO_SQE_TRANSACTION; + userdata = sqe->userdata; + rtio_spsc_release(r->sq); + + if (!transaction) { + rtio_cqe_submit(r, result, userdata); + } else { rtio_cqe_submit(r, -ECANCELED, userdata); - nsqe = rtio_spsc_consume(r->sq); - } - - if (nsqe != NULL) { - - iodev_sqe->sqe = nsqe; - rtio_iodev_submit(iodev_sqe); } + } - } else { - /* Now we can submit the next in the queue if we aren't done */ - rtio_simple_submit(r); + iodev_sqe->sqe = rtio_spsc_consume(r->sq); + if (iodev_sqe->sqe != NULL) { + rtio_iodev_submit(iodev_sqe); } } diff --git a/tests/subsys/rtio/rtio_api/src/rtio_iodev_test.h b/tests/subsys/rtio/rtio_api/src/rtio_iodev_test.h index f89ada68e843..12435dceab7d 100644 --- a/tests/subsys/rtio/rtio_api/src/rtio_iodev_test.h +++ b/tests/subsys/rtio/rtio_api/src/rtio_iodev_test.h @@ -18,6 +18,7 @@ struct rtio_iodev_test_data { /* Currently executing sqe */ struct rtio_iodev_sqe *iodev_sqe; + const struct rtio_sqe *sqe; /* Count of submit calls */ atomic_t submit_count; @@ -43,6 +44,7 @@ static void rtio_iodev_test_next(struct rtio_iodev *iodev) struct rtio_iodev_sqe *next_sqe = CONTAINER_OF(next, struct rtio_iodev_sqe, q); data->iodev_sqe = next_sqe; + data->sqe = next_sqe->sqe; k_timer_start(&data->timer, K_MSEC(10), K_NO_WAIT); } @@ -56,10 +58,15 @@ static void rtio_iodev_timer_fn(struct k_timer *tm) struct rtio_iodev_sqe *iodev_sqe = data->iodev_sqe; struct rtio_iodev *iodev = (struct rtio_iodev *)iodev_sqe->sqe->iodev; - /* Complete the request with Ok and a result, clear the current task */ - rtio_iodev_sqe_ok(iodev_sqe, 0); - data->iodev_sqe = NULL; + if (data->sqe->flags & RTIO_SQE_TRANSACTION) { + data->sqe = rtio_spsc_next(data->iodev_sqe->r->sq, data->sqe); + k_timer_start(&data->timer, K_MSEC(10), K_NO_WAIT); + return; + } + data->iodev_sqe = NULL; + data->sqe = NULL; + rtio_iodev_sqe_ok(iodev_sqe, 0); rtio_iodev_test_next(iodev); } diff --git a/tests/subsys/rtio/rtio_api/src/test_rtio_api.c b/tests/subsys/rtio/rtio_api/src/test_rtio_api.c index 5d304e4bd7f5..ed1652058db9 100644 --- a/tests/subsys/rtio/rtio_api/src/test_rtio_api.c +++ b/tests/subsys/rtio/rtio_api/src/test_rtio_api.c @@ -21,6 +21,9 @@ #include "rtio_iodev_test.h" +/* Repeat tests to ensure they are repeatable */ +#define TEST_REPEATS 4 + RTIO_EXECUTOR_SIMPLE_DEFINE(simple_exec_simp); RTIO_DEFINE(r_simple_simp, (struct rtio_executor *)&simple_exec_simp, 4, 4); @@ -63,9 +66,13 @@ void test_rtio_simple_(struct rtio *r) ZTEST(rtio_api, test_rtio_simple) { TC_PRINT("rtio simple simple\n"); - test_rtio_simple_(&r_simple_simp); + for (int i = 0; i < TEST_REPEATS; i++) { + test_rtio_simple_(&r_simple_simp); + } TC_PRINT("rtio simple concurrent\n"); - test_rtio_simple_(&r_simple_con); + for (int i = 0; i < TEST_REPEATS; i++) { + test_rtio_simple_(&r_simple_con); + } } RTIO_EXECUTOR_SIMPLE_DEFINE(chain_exec_simp); @@ -128,12 +135,15 @@ ZTEST(rtio_api, test_rtio_chain) } TC_PRINT("rtio chain simple\n"); - test_rtio_chain_(&r_chain_simp); + for (int i = 0; i < TEST_REPEATS; i++) { + test_rtio_chain_(&r_chain_simp); + } TC_PRINT("rtio chain concurrent\n"); - test_rtio_chain_(&r_chain_con); + for (int i = 0; i < TEST_REPEATS; i++) { + test_rtio_chain_(&r_chain_con); + } } - RTIO_EXECUTOR_SIMPLE_DEFINE(multi_exec_simp); RTIO_DEFINE(r_multi_simp, (struct rtio_executor *)&multi_exec_simp, 4, 4); @@ -211,8 +221,6 @@ ZTEST(rtio_api, test_rtio_multiple_chains) test_rtio_multiple_chains_(&r_multi_con); } - - #ifdef CONFIG_USERSPACE K_APPMEM_PARTITION_DEFINE(rtio_partition); K_APP_BMEM(rtio_partition) uint8_t syscall_bufs[4]; @@ -287,7 +295,98 @@ ZTEST(rtio_api, test_rtio_syscalls) TC_PRINT("test iodev init\n"); rtio_iodev_test_init(&iodev_test_syscall); TC_PRINT("syscalls from kernel mode\n"); - rtio_syscall_test(NULL, NULL, NULL); + for (int i = 0; i < TEST_REPEATS; i++) { + rtio_syscall_test(NULL, NULL, NULL); + } +} + +RTIO_EXECUTOR_SIMPLE_DEFINE(transaction_exec_simp); +RTIO_DEFINE(r_transaction_simp, (struct rtio_executor *)&transaction_exec_simp, 4, 4); + +RTIO_EXECUTOR_CONCURRENT_DEFINE(transaction_exec_con, 2); +RTIO_DEFINE(r_transaction_con, (struct rtio_executor *)&transaction_exec_con, 4, 4); + +RTIO_IODEV_TEST_DEFINE(iodev_test_transaction0); +RTIO_IODEV_TEST_DEFINE(iodev_test_transaction1); +struct rtio_iodev *iodev_test_transaction[] = {&iodev_test_transaction0, &iodev_test_transaction1}; + +/** + * @brief Test transaction requests + * + * Ensures that we can setup an RTIO context, enqueue a transaction requests, + * and receive completion events in the correct order given the transaction + * flag and multiple devices where serialization isn't guaranteed. + */ +void test_rtio_transaction_(struct rtio *r) +{ + int res; + uintptr_t userdata[2] = {0, 1}; + struct rtio_sqe *sqe; + struct rtio_cqe *cqe; + bool seen[2] = { 0 }; + + sqe = rtio_spsc_acquire(r->sq); + zassert_not_null(sqe, "Expected a valid sqe"); + rtio_sqe_prep_nop(sqe, &iodev_test_transaction0, NULL); + sqe->flags |= RTIO_SQE_TRANSACTION; + + sqe = rtio_spsc_acquire(r->sq); + zassert_not_null(sqe, "Expected a valid sqe"); + rtio_sqe_prep_nop(sqe, NULL, + &userdata[0]); + + + sqe = rtio_spsc_acquire(r->sq); + zassert_not_null(sqe, "Expected a valid sqe"); + rtio_sqe_prep_nop(sqe, &iodev_test_transaction1, NULL); + sqe->flags |= RTIO_SQE_TRANSACTION; + + sqe = rtio_spsc_acquire(r->sq); + zassert_not_null(sqe, "Expected a valid sqe"); + rtio_sqe_prep_nop(sqe, NULL, + &userdata[1]); + + TC_PRINT("submitting userdata 0 %p, userdata 1 %p\n", &userdata[0], &userdata[1]); + res = rtio_submit(r, 2); + TC_PRINT("checking cq, completions available %lu\n", rtio_spsc_consumable(r->cq)); + zassert_ok(res, "Should return ok from rtio_execute"); + zassert_equal(rtio_spsc_consumable(r->cq), 2, "Should have 2 pending completions"); + + for (int i = 0; i < 2; i++) { + TC_PRINT("consume %d\n", i); + cqe = rtio_spsc_consume(r->cq); + zassert_not_null(cqe, "Expected a valid cqe"); + zassert_ok(cqe->result, "Result should be ok"); + uintptr_t idx = *(uintptr_t *)cqe->userdata; + + TC_PRINT("userdata is %p, value %lu\n", cqe->userdata, idx); + zassert(idx == 0 || idx == 1, "idx should be 0 or 1"); + seen[idx] = true; + rtio_spsc_release(r->cq); + } + + zassert_true(seen[0], "Should have seen transaction 0"); + zassert_true(seen[1], "Should have seen transaction 1"); } +ZTEST(rtio_api, test_rtio_transaction) +{ + TC_PRINT("initializing iodev test devices\n"); + + for (int i = 0; i < 2; i++) { + rtio_iodev_test_init(iodev_test_transaction[i]); + } + + TC_PRINT("rtio transaction simple\n"); + for (int i = 0; i < TEST_REPEATS; i++) { + test_rtio_transaction_(&r_transaction_simp); + } + TC_PRINT("rtio transaction concurrent\n"); + for (int i = 0; i < TEST_REPEATS; i++) { + test_rtio_transaction_(&r_transaction_con); + } +} + + + ZTEST_SUITE(rtio_api, NULL, NULL, NULL, NULL, NULL); From 610d307fa00f4c713aa012f4ae0e6b8bd03c1828 Mon Sep 17 00:00:00 2001 From: Tom Burdick Date: Fri, 17 Mar 2023 10:59:52 -0500 Subject: [PATCH 0361/1906] rtio: Properly track last sqe in the queue The pending_sqe logic to track where in the ring queue the concurrent executor had left off was slightly flawed. It didn't account for starting all sqes in the queue and ending back up at the beginning. Instead track the last SQE in the queue, from which the next one in the queue will the one to start next. If we happen to sweep the last known SQE in the queue, reset it to NULL so the next time prepare is called we start at the beginning of the queue again. Signed-off-by: Tom Burdick --- .../zephyr/rtio/rtio_executor_concurrent.h | 4 -- subsys/rtio/rtio_executor_concurrent.c | 48 ++++++++++--------- .../subsys/rtio/rtio_api/src/test_rtio_api.c | 6 ++- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/include/zephyr/rtio/rtio_executor_concurrent.h b/include/zephyr/rtio/rtio_executor_concurrent.h index 9ff5acdde074..26bda6bfe0a9 100644 --- a/include/zephyr/rtio/rtio_executor_concurrent.h +++ b/include/zephyr/rtio/rtio_executor_concurrent.h @@ -66,9 +66,6 @@ struct rtio_concurrent_executor { uint16_t task_in, task_out, task_mask; /* First pending sqe to start when a task becomes available */ - struct rtio_sqe *pending_sqe; - - /* Last sqe seen from the most recent submit */ struct rtio_sqe *last_sqe; /* Array of task statuses */ @@ -106,7 +103,6 @@ static const struct rtio_executor_api z_rtio_concurrent_api = { .task_in = 0, \ .task_out = 0, \ .task_mask = (concurrency)-1, \ - .pending_sqe = NULL, \ .last_sqe = NULL, \ .task_status = _task_status_##name, \ .task_cur = _task_cur_##name, \ diff --git a/subsys/rtio/rtio_executor_concurrent.c b/subsys/rtio/rtio_executor_concurrent.c index e5618c830540..c1140c4d5235 100644 --- a/subsys/rtio/rtio_executor_concurrent.c +++ b/subsys/rtio/rtio_executor_concurrent.c @@ -70,6 +70,10 @@ static void conex_sweep_task(struct rtio *r, struct rtio_concurrent_executor *ex } rtio_spsc_release(r->sq); + + if (sqe == exc->last_sqe) { + exc->last_sqe = NULL; + } } /** @@ -84,7 +88,7 @@ static void conex_sweep(struct rtio *r, struct rtio_concurrent_executor *exc) /* In order sweep up */ for (uint16_t task_id = exc->task_out; task_id < exc->task_in; task_id++) { if (exc->task_status[task_id & exc->task_mask] & CONEX_TASK_COMPLETE) { - LOG_INF("sweeping oldest task %d", task_id); + LOG_DBG("sweeping oldest task %d", task_id); conex_sweep_task(r, exc); exc->task_out++; } else { @@ -102,38 +106,45 @@ static void conex_sweep(struct rtio *r, struct rtio_concurrent_executor *exc) */ static void conex_prepare(struct rtio *r, struct rtio_concurrent_executor *exc) { - struct rtio_sqe *sqe; + struct rtio_sqe *sqe, *last_sqe; /* If never submitted before peek at the first item * otherwise start back up where the last submit call * left off */ - if (exc->pending_sqe == NULL) { + if (exc->last_sqe == NULL) { + last_sqe = NULL; sqe = rtio_spsc_peek(r->sq); } else { - sqe = exc->pending_sqe; + last_sqe = exc->last_sqe; + sqe = rtio_spsc_next(r->sq, last_sqe); } + LOG_DBG("starting at sqe %p, last %p", sqe, exc->last_sqe); + while (sqe != NULL && conex_task_free(exc)) { /* Get the next free task id */ uint16_t task_idx = conex_task_next(exc); + LOG_DBG("preparing task %d, sqe %p", task_idx, sqe); + /* Setup task */ exc->task_cur[task_idx].sqe = sqe; exc->task_cur[task_idx].r = r; exc->task_status[task_idx] = CONEX_TASK_SUSPENDED; /* Go to the next sqe not in the current chain or transaction */ - while (sqe != NULL && (sqe->flags & (RTIO_SQE_CHAINED | RTIO_SQE_TRANSACTION))) { + while (sqe->flags & (RTIO_SQE_CHAINED | RTIO_SQE_TRANSACTION)) { sqe = rtio_spsc_next(r->sq, sqe); } /* SQE is the end of the previous chain or transaction so skip it */ + last_sqe = sqe; sqe = rtio_spsc_next(r->sq, sqe); } /* Out of available tasks so remember where we left off to begin again once tasks free up */ - exc->pending_sqe = sqe; + exc->last_sqe = last_sqe; } @@ -148,25 +159,13 @@ static void conex_resume(struct rtio *r, struct rtio_concurrent_executor *exc) /* In order resume tasks */ for (uint16_t task_id = exc->task_out; task_id < exc->task_in; task_id++) { if (exc->task_status[task_id & exc->task_mask] & CONEX_TASK_SUSPENDED) { - LOG_INF("resuming suspended task %d", task_id); + LOG_DBG("resuming suspended task %d", task_id); exc->task_status[task_id & exc->task_mask] &= ~CONEX_TASK_SUSPENDED; rtio_iodev_submit(&exc->task_cur[task_id & exc->task_mask]); } } } -/** - * @brief Sweep, Prepare, and Resume in one go - * - * Called after a completion to continue doing more work if needed. - */ -static void conex_sweep_resume(struct rtio *r, struct rtio_concurrent_executor *exc) -{ - conex_sweep(r, exc); - conex_prepare(r, exc); - conex_resume(r, exc); -} - /** * @brief Submit submissions to concurrent executor * @@ -211,6 +210,8 @@ void rtio_concurrent_ok(struct rtio_iodev_sqe *iodev_sqe, int result) */ key = k_spin_lock(&exc->lock); + LOG_DBG("completed sqe %p", sqe); + /* Determine the task id by memory offset O(1) */ uint16_t task_id = conex_task_id(exc, iodev_sqe); @@ -230,9 +231,10 @@ void rtio_concurrent_ok(struct rtio_iodev_sqe *iodev_sqe, int result) transaction = sqe->flags & RTIO_SQE_TRANSACTION; } + conex_sweep(r, exc); rtio_cqe_submit(r, result, sqe->userdata); - - conex_sweep_resume(r, exc); + conex_prepare(r, exc); + conex_resume(r, exc); k_spin_unlock(&exc->lock, key); } @@ -279,7 +281,9 @@ void rtio_concurrent_err(struct rtio_iodev_sqe *iodev_sqe, int result) /* Determine the task id : O(1) */ exc->task_status[task_id] |= CONEX_TASK_COMPLETE; - conex_sweep_resume(r, exc); + conex_sweep(r, exc); + conex_prepare(r, exc); + conex_resume(r, exc); k_spin_unlock(&exc->lock, key); } diff --git a/tests/subsys/rtio/rtio_api/src/test_rtio_api.c b/tests/subsys/rtio/rtio_api/src/test_rtio_api.c index ed1652058db9..21dce9b88065 100644 --- a/tests/subsys/rtio/rtio_api/src/test_rtio_api.c +++ b/tests/subsys/rtio/rtio_api/src/test_rtio_api.c @@ -95,7 +95,7 @@ struct rtio_iodev *iodev_test_chain[] = {&iodev_test_chain0, &iodev_test_chain1} void test_rtio_chain_(struct rtio *r) { int res; - uintptr_t userdata[4] = {0, 1, 2, 3}; + uint32_t userdata[4] = {0, 1, 2, 3}; struct rtio_sqe *sqe; struct rtio_cqe *cqe; @@ -105,6 +105,7 @@ void test_rtio_chain_(struct rtio *r) rtio_sqe_prep_nop(sqe, iodev_test_chain[i % 2], &userdata[i]); sqe->flags |= RTIO_SQE_CHAINED; + TC_PRINT("produce %d, sqe %p, userdata %d\n", i, sqe, userdata[i]); } /* Clear the last one */ @@ -117,10 +118,11 @@ void test_rtio_chain_(struct rtio *r) zassert_equal(rtio_spsc_consumable(r->cq), 4, "Should have 4 pending completions"); for (int i = 0; i < 4; i++) { - TC_PRINT("consume %d\n", i); cqe = rtio_spsc_consume(r->cq); zassert_not_null(cqe, "Expected a valid cqe"); + TC_PRINT("consume %d, cqe %p, userdata %d\n", i, cqe, *(uint32_t *)cqe->userdata); zassert_ok(cqe->result, "Result should be ok"); + zassert_equal_ptr(cqe->userdata, &userdata[i], "Expected in order completions"); rtio_spsc_release(r->cq); } From bfecb77fde456659e14d1eb270fe3c0ddcf3f514 Mon Sep 17 00:00:00 2001 From: Tom Burdick Date: Mon, 6 Mar 2023 11:21:43 -0600 Subject: [PATCH 0362/1906] rtio: Make rtio_mpsc.h C++ friendly C++ requires casting void * as the implicit cast isn't enough and the C++ sample app fails to build without duplicating type information here. Do that, and wrap it in extern C allowing the C++ to include rtio_mpsc.h directly or indirectly. Signed-off-by: Tom Burdick --- include/zephyr/rtio/rtio_mpsc.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/include/zephyr/rtio/rtio_mpsc.h b/include/zephyr/rtio/rtio_mpsc.h index 77f7fa780169..f0bc78a1b41d 100644 --- a/include/zephyr/rtio/rtio_mpsc.h +++ b/include/zephyr/rtio/rtio_mpsc.h @@ -14,6 +14,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief RTIO Multiple Producer Single Consumer (MPSC) Queue API * @defgroup rtio_mpsc RTIO MPSC API @@ -94,7 +98,7 @@ static inline void rtio_mpsc_push(struct rtio_mpsc *q, struct rtio_mpsc_node *n) atomic_ptr_set(&n->next, NULL); key = arch_irq_lock(); - prev = atomic_ptr_set(&q->head, n); + prev = (struct rtio_mpsc_node *)atomic_ptr_set(&q->head, n); atomic_ptr_set(&prev->next, n); arch_irq_unlock(key); } @@ -109,7 +113,7 @@ static inline struct rtio_mpsc_node *rtio_mpsc_pop(struct rtio_mpsc *q) { struct rtio_mpsc_node *head; struct rtio_mpsc_node *tail = q->tail; - struct rtio_mpsc_node *next = atomic_ptr_get(&tail->next); + struct rtio_mpsc_node *next = (struct rtio_mpsc_node *)atomic_ptr_get(&tail->next); /* Skip over the stub/sentinel */ if (tail == &q->stub) { @@ -119,7 +123,7 @@ static inline struct rtio_mpsc_node *rtio_mpsc_pop(struct rtio_mpsc *q) q->tail = next; tail = next; - next = atomic_ptr_get(&next->next); + next = (struct rtio_mpsc_node *)atomic_ptr_get(&next->next); } /* If next is non-NULL then a valid node is found, return it */ @@ -128,7 +132,7 @@ static inline struct rtio_mpsc_node *rtio_mpsc_pop(struct rtio_mpsc *q) return tail; } - head = atomic_ptr_get(&q->head); + head = (struct rtio_mpsc_node *)atomic_ptr_get(&q->head); /* If next is NULL, and the tail != HEAD then the queue has pending * updates that can't yet be accessed. @@ -139,7 +143,7 @@ static inline struct rtio_mpsc_node *rtio_mpsc_pop(struct rtio_mpsc *q) rtio_mpsc_push(q, &q->stub); - next = atomic_ptr_get(&tail->next); + next = (struct rtio_mpsc_node *)atomic_ptr_get(&tail->next); if (next != NULL) { q->tail = next; @@ -153,4 +157,9 @@ static inline struct rtio_mpsc_node *rtio_mpsc_pop(struct rtio_mpsc *q) * @} */ +#ifdef __cplusplus +} +#endif + + #endif /* ZEPHYR_RTIO_MPSC_H_ */ From debbb69eec533e221eff9b3fd04758264285d32c Mon Sep 17 00:00:00 2001 From: Tom Burdick Date: Mon, 6 Feb 2023 21:21:16 -0600 Subject: [PATCH 0363/1906] rtio: Adds rtio_iodev_cancel_all Ability to cancel all pending requests in the queue turns out to be useful and shareable. Signed-off-by: Tom Burdick --- include/zephyr/rtio/rtio.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/zephyr/rtio/rtio.h b/include/zephyr/rtio/rtio.h index df3dd72e4289..a0a968b33102 100644 --- a/include/zephyr/rtio/rtio.h +++ b/include/zephyr/rtio/rtio.h @@ -588,6 +588,24 @@ static inline void rtio_iodev_sqe_err(struct rtio_iodev_sqe *iodev_sqe, int resu iodev_sqe->r->executor->api->err(iodev_sqe, result); } +/** + * @brief Cancel all requests that are pending for the iodev + * + * @param iodev IODev to cancel all requests for + */ +static inline void rtio_iodev_cancel_all(struct rtio_iodev *iodev) +{ + /* Clear pending requests as -ENODATA */ + struct rtio_mpsc_node *node = rtio_mpsc_pop(&iodev->iodev_sq); + + while (node != NULL) { + struct rtio_iodev_sqe *iodev_sqe = CONTAINER_OF(node, struct rtio_iodev_sqe, q); + + rtio_iodev_sqe_err(iodev_sqe, -ECANCELED); + node = rtio_mpsc_pop(&iodev->iodev_sq); + } +} + /** * Submit a completion queue event with a given result and userdata * From 2d1375f89d7fa5239a36233bcfb92336d18ba311 Mon Sep 17 00:00:00 2001 From: Tom Burdick Date: Fri, 7 Oct 2022 13:17:13 -0500 Subject: [PATCH 0364/1906] rtio: Fix consume semaphore usage When the consume semaphore is enabled always give and take from the semaphore. It's expected that rtio_cqe_consume and rtio_cqe_consume_block will be used exclusively rather than directly poking at the SPSC queues. Signed-off-by: Tom Burdick --- include/zephyr/rtio/rtio.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/include/zephyr/rtio/rtio.h b/include/zephyr/rtio/rtio.h index a0a968b33102..79984e555ed3 100644 --- a/include/zephyr/rtio/rtio.h +++ b/include/zephyr/rtio/rtio.h @@ -421,7 +421,7 @@ static inline void rtio_sqe_prep_write(struct rtio_sqe *sqe, IF_ENABLED(CONFIG_RTIO_SUBMIT_SEM, \ (static K_SEM_DEFINE(_submit_sem_##name, 0, K_SEM_MAX_LIMIT))) \ IF_ENABLED(CONFIG_RTIO_CONSUME_SEM, \ - (static K_SEM_DEFINE(_consume_sem_##name, 0, 1))) \ + (static K_SEM_DEFINE(_consume_sem_##name, 0, K_SEM_MAX_LIMIT))) \ static RTIO_SQ_DEFINE(_sq_##name, sq_sz); \ static RTIO_CQ_DEFINE(_cq_##name, cq_sz); \ STRUCT_SECTION_ITERABLE(rtio, name) = { \ @@ -515,7 +515,15 @@ static inline void rtio_sqe_drop_all(struct rtio *r) */ static inline struct rtio_cqe *rtio_cqe_consume(struct rtio *r) { +#ifdef CONFIG_RTIO_CONSUME_SEM + if (k_sem_take(r->consume_sem, K_NO_WAIT) == 0) { + return rtio_spsc_consume(r->cq); + } else { + return NULL; + } +#else return rtio_spsc_consume(r->cq); +#endif } /** @@ -532,21 +540,18 @@ static inline struct rtio_cqe *rtio_cqe_consume_block(struct rtio *r) { struct rtio_cqe *cqe; - /* TODO is there a better way? reset this in submit? */ #ifdef CONFIG_RTIO_CONSUME_SEM - k_sem_reset(r->consume_sem); -#endif + k_sem_take(r->consume_sem, K_FOREVER); + + cqe = rtio_spsc_consume(r->cq); +#else cqe = rtio_spsc_consume(r->cq); while (cqe == NULL) { cqe = rtio_spsc_consume(r->cq); -#ifdef CONFIG_RTIO_CONSUME_SEM - k_sem_take(r->consume_sem, K_FOREVER); -#else - k_yield(); -#endif } +#endif return cqe; } From c194cb76add404010600b4651d9415b10163431c Mon Sep 17 00:00:00 2001 From: Oleg Ryjkov Date: Fri, 17 Mar 2023 10:18:10 +0100 Subject: [PATCH 0365/1906] drivers: sensor: bmi270: Use bulk SPI reads BMI270 supports bulk register reads, use them to make trasnfers faster. See the discussion on https://github.com/zephyrproject-rtos/zephyr/commit/6cbb84c3eed97efa33375ae24d050abf49ee5b86#r104543405 Tested on an nrf52840 board connected to a bmi270 sensor via SPI. Signed-off-by: Oleg Ryjkov --- drivers/sensor/bmi270/bmi270_spi.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/sensor/bmi270/bmi270_spi.c b/drivers/sensor/bmi270/bmi270_spi.c index 960309ba17f6..0bab9029f332 100644 --- a/drivers/sensor/bmi270/bmi270_spi.c +++ b/drivers/sensor/bmi270/bmi270_spi.c @@ -25,7 +25,6 @@ static int bmi270_reg_read_spi(const union bmi270_bus *bus, int ret; uint8_t addr; uint8_t tmp[2]; - int i; const struct spi_buf tx_buf = { .buf = &addr, .len = 1 @@ -40,19 +39,18 @@ static int bmi270_reg_read_spi(const union bmi270_bus *bus, .count = ARRAY_SIZE(rx_buf) }; - rx_buf[0].buf = &tmp[0]; + /* First byte we read should be discarded. */ + rx_buf[0].buf = &tmp; rx_buf[0].len = 2; - rx_buf[1].len = 1; + rx_buf[1].len = len; + rx_buf[1].buf = data; - for (i = 0; i < len; i++) { - addr = (start + i) | 0x80; - rx_buf[1].buf = &data[i]; + addr = start | 0x80; - ret = spi_transceive_dt(&bus->spi, &tx, &rx); - if (ret < 0) { - LOG_DBG("spi_transceive failed %i", ret); - return ret; - } + ret = spi_transceive_dt(&bus->spi, &tx, &rx); + if (ret < 0) { + LOG_DBG("spi_transceive failed %i", ret); + return ret; } k_usleep(BMI270_SPI_ACC_DELAY_US); From 388d522c320ad8253437f13823b96a3a2bbc8765 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Thu, 9 Mar 2023 19:53:24 +0000 Subject: [PATCH 0366/1906] drivers: clock: Microchip XEC: Fix enum usage We get a compiler warning in this code with arm clang due to using the wrong enum type for the variable. The enum should be of type `enum periph_clk32k_src` so replace VBR_CLK32K_SRC_PIN_XTAL with PERIPH_CLK32K_SRC_PIN_XTAL. Signed-off-by: Kumar Gala --- drivers/clock_control/clock_control_mchp_xec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clock_control/clock_control_mchp_xec.c b/drivers/clock_control/clock_control_mchp_xec.c index 9444e2c2790a..6e1352c19473 100644 --- a/drivers/clock_control/clock_control_mchp_xec.c +++ b/drivers/clock_control/clock_control_mchp_xec.c @@ -640,7 +640,7 @@ enum periph_clk32k_src get_periph_32k_source(const struct device *dev) } else if (temp == VBR_CLK32K_SRC_PIN_SO) { src = PERIPH_CLK32K_SRC_PIN_SO; } else { - src = VBR_CLK32K_SRC_PIN_XTAL; + src = PERIPH_CLK32K_SRC_PIN_XTAL; } return src; From f27c0b490523563d98677e36443e99931567b794 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 17 Mar 2023 15:29:24 +0100 Subject: [PATCH 0367/1906] tests bsim: Change folder structure Bsim won't be limited anymore to BT tests. In preparation for adding more tests in network areas swap the tests/bluetooth/bsim with tests/bsim/bluetooth There is no other changes in this commit beyond that. Signed-off-by: Alberto Escolar Piedras --- .github/workflows/bluetooth-tests.yaml | 6 +- CODEOWNERS | 6 +- MAINTAINERS.yml | 4 +- tests/bluetooth/bsim/host/compile.sh | 57 ------------------- .../bsim => bsim/bluetooth}/README.txt | 8 +-- .../bluetooth}/_compile_permutate_kconfigs.sh | 4 +- .../bluetooth}/audio/CMakeLists.txt | 0 .../bsim => bsim/bluetooth}/audio/Kconfig | 0 .../bsim => bsim/bluetooth}/audio/README.txt | 0 .../bsim => bsim/bluetooth}/audio/compile.sh | 4 +- .../bsim => bsim/bluetooth}/audio/prj.conf | 0 .../audio/src/bap_broadcast_assistant_test.c | 0 .../audio/src/bap_scan_delegator_test.c | 0 .../audio/src/bap_unicast_client_test.c | 0 .../bluetooth}/audio/src/bap_unicast_common.c | 0 .../bluetooth}/audio/src/bap_unicast_common.h | 0 .../audio/src/bap_unicast_server_test.c | 0 .../audio/src/bass_broadcaster_test.c | 0 .../audio/src/broadcast_sink_test.c | 0 .../audio/src/broadcast_source_test.c | 0 .../bluetooth}/audio/src/cap_acceptor_test.c | 0 .../bluetooth}/audio/src/cap_initiator_test.c | 0 .../bluetooth}/audio/src/common.c | 0 .../bluetooth}/audio/src/common.h | 0 .../audio/src/csip_set_coordinator_test.c | 0 .../audio/src/csip_set_member_test.c | 0 .../bluetooth}/audio/src/has_client_test.c | 0 .../bluetooth}/audio/src/has_test.c | 0 .../bluetooth}/audio/src/ias_client_test.c | 0 .../bluetooth}/audio/src/ias_test.c | 0 .../bsim => bsim/bluetooth}/audio/src/main.c | 0 .../bluetooth}/audio/src/mcc_test.c | 0 .../bluetooth}/audio/src/mcs_test.c | 0 .../audio/src/media_controller_test.c | 0 .../bluetooth}/audio/src/micp_mic_ctlr_test.c | 0 .../bluetooth}/audio/src/micp_mic_dev_test.c | 0 .../bluetooth}/audio/src/tbs_client_test.c | 0 .../bluetooth}/audio/src/tbs_test.c | 0 .../bluetooth}/audio/src/vcp_vol_ctlr_test.c | 0 .../bluetooth}/audio/src/vcp_vol_rend_test.c | 0 .../bluetooth}/audio/test_scripts/_cap.sh | 0 .../bluetooth}/audio/test_scripts/bap_bass.sh | 6 +- .../audio/test_scripts/bap_broadcast_audio.sh | 8 +-- .../audio/test_scripts/bap_unicast_audio.sh | 4 +- .../audio/test_scripts/cap_broadcast.sh | 4 +- .../audio/test_scripts/cap_unicast.sh | 4 +- .../bluetooth}/audio/test_scripts/csip.sh | 24 ++++---- .../bluetooth}/audio/test_scripts/has.sh | 4 +- .../bluetooth}/audio/test_scripts/ias.sh | 4 +- .../bluetooth}/audio/test_scripts/mcs_mcc.sh | 4 +- .../audio/test_scripts/media_controller.sh | 6 +- .../bluetooth}/audio/test_scripts/micp.sh | 6 +- .../bluetooth}/audio/test_scripts/tbs.sh | 4 +- .../bluetooth}/audio/test_scripts/vcp.sh | 6 +- .../bsim => bsim/bluetooth}/compile.sh | 10 ++-- .../bsim => bsim/bluetooth}/compile.source | 2 +- .../bluetooth}/host/adv/chain/CMakeLists.txt | 0 .../bluetooth}/host/adv/chain/prj.conf | 0 .../bluetooth}/host/adv/chain/src/main.c | 0 .../host/adv/chain/tests_scripts/adv_chain.sh | 4 +- .../host/adv/periodic/CMakeLists.txt | 0 .../bluetooth}/host/adv/periodic/prj.conf | 0 .../host/adv/periodic/prj_long_data.conf | 0 .../bluetooth}/host/adv/periodic/src/common.c | 0 .../bluetooth}/host/adv/periodic/src/common.h | 0 .../bluetooth}/host/adv/periodic/src/main.c | 0 .../adv/periodic/src/per_adv_advertiser.c | 0 .../host/adv/periodic/src/per_adv_syncer.c | 0 .../adv/periodic/tests_scripts/per_adv.sh | 4 +- .../periodic/tests_scripts/per_adv_conn.sh | 4 +- .../tests_scripts/per_adv_conn_privacy.sh | 4 +- .../tests_scripts/per_adv_long_data.sh | 4 +- .../bluetooth}/host/adv/resume/CMakeLists.txt | 0 .../bluetooth}/host/adv/resume/prj.conf | 0 .../bluetooth}/host/adv/resume/prj_2.conf | 0 .../host/adv/resume/src/bs_bt_utils.c | 0 .../host/adv/resume/src/bs_bt_utils.h | 0 .../bluetooth}/host/adv/resume/src/dut.c | 0 .../bluetooth}/host/adv/resume/src/main.c | 0 .../bluetooth}/host/adv/resume/src/tester.c | 0 .../host/adv/resume/test_scripts/_compile.sh | 0 .../host/adv/resume/test_scripts/_env.sh | 4 +- .../adv/resume/test_scripts/run_adv_resume.sh | 0 .../resume/test_scripts/run_adv_resume_2.sh | 0 .../bluetooth}/host/att/eatt/CMakeLists.txt | 0 .../host/att/eatt/prj_autoconnect.conf | 0 .../host/att/eatt/prj_collision.conf | 0 .../host/att/eatt/prj_multiple_conn.conf | 0 .../bluetooth}/host/att/eatt/src/common.c | 0 .../bluetooth}/host/att/eatt/src/common.h | 0 .../bluetooth}/host/att/eatt/src/main.c | 0 .../host/att/eatt/src/main_autoconnect.c | 0 .../host/att/eatt/src/main_collision.c | 0 .../host/att/eatt/src/main_reconfigure.c | 0 .../att/eatt/tests_scripts/autoconnect.sh | 4 +- .../host/att/eatt/tests_scripts/collision.sh | 4 +- .../att/eatt/tests_scripts/multiple_conn.sh | 4 +- .../att/eatt/tests_scripts/reconfigure.sh | 4 +- .../host/att/eatt_notif/CMakeLists.txt | 0 .../bluetooth}/host/att/eatt_notif/prj.conf | 0 .../host/att/eatt_notif/src/client_test.c | 0 .../host/att/eatt_notif/src/common.c | 0 .../host/att/eatt_notif/src/common.h | 0 .../bluetooth}/host/att/eatt_notif/src/main.c | 0 .../host/att/eatt_notif/src/server_test.c | 0 .../att/eatt_notif/test_scripts/eatt_notif.sh | 4 +- .../host/att/mtu_update/CMakeLists.txt | 0 .../bluetooth}/host/att/mtu_update/prj.conf | 0 .../bluetooth}/host/att/mtu_update/src/main.c | 0 .../att/mtu_update/test_scripts/_compile.sh | 4 +- .../host/att/mtu_update/test_scripts/_env.sh | 2 +- .../att/mtu_update/test_scripts/run_test.sh | 0 tests/bsim/bluetooth/host/compile.sh | 57 +++++++++++++++++++ .../host/gatt/caching/CMakeLists.txt | 0 .../bluetooth}/host/gatt/caching/prj.conf | 0 .../bluetooth}/host/gatt/caching/src/common.c | 0 .../bluetooth}/host/gatt/caching/src/common.h | 0 .../host/gatt/caching/src/gatt_client_test.c | 0 .../host/gatt/caching/src/gatt_server_test.c | 0 .../bluetooth}/host/gatt/caching/src/main.c | 0 .../gatt/caching/test_scripts/_run_test.sh | 4 +- .../gatt_caching_db_hash_read_eatt.sh | 0 .../gatt_caching_db_hash_read_no_eatt.sh | 0 .../gatt_caching_out_of_sync_eatt.sh | 0 .../gatt_caching_out_of_sync_no_eatt.sh | 0 .../gatt_caching_retry_reads_eatt.sh | 0 .../gatt_caching_retry_reads_no_eatt.sh | 0 .../host/gatt/general/CMakeLists.txt | 0 .../bluetooth}/host/gatt/general/prj.conf | 0 .../bluetooth}/host/gatt/general/src/common.c | 0 .../bluetooth}/host/gatt/general/src/common.h | 0 .../host/gatt/general/src/gatt_client_test.c | 0 .../host/gatt/general/src/gatt_server_test.c | 0 .../bluetooth}/host/gatt/general/src/main.c | 0 .../host/gatt/general/test_scripts/gatt.sh | 4 +- .../host/gatt/notify/CMakeLists.txt | 0 .../bluetooth}/host/gatt/notify/prj.conf | 0 .../bluetooth}/host/gatt/notify/src/common.c | 0 .../bluetooth}/host/gatt/notify/src/common.h | 0 .../host/gatt/notify/src/gatt_client_test.c | 0 .../host/gatt/notify/src/gatt_server_test.c | 0 .../bluetooth}/host/gatt/notify/src/main.c | 0 .../gatt/notify/test_scripts/_run_test.sh | 4 +- .../gatt_notify_enhanced_enhanced.sh | 0 .../gatt_notify_enhanced_mixed.sh | 0 .../test_scripts/gatt_notify_enhanced_none.sh | 0 .../gatt_notify_enhanced_unenhanced.sh | 0 .../gatt_notify_mixed_enhanced.sh | 0 .../test_scripts/gatt_notify_mixed_mixed.sh | 0 .../test_scripts/gatt_notify_mixed_none.sh | 0 .../gatt_notify_mixed_unenhanced.sh | 0 .../test_scripts/gatt_notify_none_enhanced.sh | 0 .../test_scripts/gatt_notify_none_mixed.sh | 0 .../test_scripts/gatt_notify_none_none.sh | 0 .../gatt_notify_none_unenhanced.sh | 0 .../gatt_notify_unenhanced_enhanced.sh | 0 .../gatt_notify_unenhanced_mixed.sh | 0 .../gatt_notify_unenhanced_none.sh | 0 .../gatt_notify_unenhanced_unenhanced.sh | 0 .../host/gatt/notify_multiple/CMakeLists.txt | 0 .../host/gatt/notify_multiple/prj.conf | 0 .../host/gatt/notify_multiple/src/common.c | 0 .../host/gatt/notify_multiple/src/common.h | 0 .../notify_multiple/src/gatt_client_test.c | 0 .../notify_multiple/src/gatt_server_test.c | 0 .../host/gatt/notify_multiple/src/main.c | 0 .../test_scripts/_notify-debug.sh | 4 +- .../notify_multiple/test_scripts/notify.sh | 4 +- .../host/gatt/settings/CMakeLists.txt | 0 .../bluetooth}/host/gatt/settings/prj.conf | 0 .../bluetooth}/host/gatt/settings/prj_2.conf | 0 .../host/gatt/settings/src/client.c | 0 .../host/gatt/settings/src/gatt_utils.c | 0 .../host/gatt/settings/src/gatt_utils.h | 0 .../bluetooth}/host/gatt/settings/src/main.c | 0 .../bluetooth}/host/gatt/settings/src/main.h | 0 .../host/gatt/settings/src/server.c | 0 .../host/gatt/settings/src/settings.c | 0 .../bluetooth}/host/gatt/settings/src/utils.c | 0 .../bluetooth}/host/gatt/settings/src/utils.h | 0 .../gatt/settings/test_scripts/_compile.sh | 0 .../host/gatt/settings/test_scripts/_env.sh | 4 +- .../test_scripts/run_gatt_settings.sh | 0 .../test_scripts/run_gatt_settings_2.sh | 0 .../bluetooth}/host/gatt/write/CMakeLists.txt | 0 .../bluetooth}/host/gatt/write/prj.conf | 0 .../bluetooth}/host/gatt/write/src/main.c | 0 .../gatt/write/tests_scripts/gatt_write.sh | 4 +- .../host/l2cap/general/CMakeLists.txt | 0 .../bluetooth}/host/l2cap/general/prj.conf | 0 .../host/l2cap/general/src/common.c | 0 .../host/l2cap/general/src/common.h | 0 .../bluetooth}/host/l2cap/general/src/main.c | 0 .../host/l2cap/general/src/main_l2cap_ecred.c | 0 .../host/l2cap/general/tests_scripts/l2cap.sh | 4 +- .../host/l2cap/stress/CMakeLists.txt | 0 .../bluetooth}/host/l2cap/stress/prj.conf | 0 .../bluetooth}/host/l2cap/stress/src/common.c | 0 .../bluetooth}/host/l2cap/stress/src/common.h | 0 .../bluetooth}/host/l2cap/stress/src/main.c | 0 .../host/l2cap/stress/tests_scripts/l2cap.sh | 2 +- .../host/l2cap/userdata/CMakeLists.txt | 0 .../bluetooth}/host/l2cap/userdata/prj.conf | 0 .../host/l2cap/userdata/src/common.c | 0 .../host/l2cap/userdata/src/common.h | 0 .../bluetooth}/host/l2cap/userdata/src/main.c | 0 .../l2cap/userdata/src/main_l2cap_userdata.c | 0 .../l2cap/userdata/tests_scripts/l2cap.sh | 4 +- .../host/misc/disable/CMakeLists.txt | 0 .../bluetooth}/host/misc/disable/prj.conf | 0 .../bluetooth}/host/misc/disable/src/common.c | 0 .../bluetooth}/host/misc/disable/src/common.h | 0 .../host/misc/disable/src/gatt_client_test.c | 0 .../host/misc/disable/src/gatt_server_test.c | 0 .../bluetooth}/host/misc/disable/src/main.c | 0 .../host/misc/disable/src/main_disable.c | 0 .../misc/disable/tests_scripts/disable.sh | 2 +- .../tests_scripts/disable_with_gatt.sh | 4 +- .../host/misc/multiple_id/CMakeLists.txt | 0 .../bluetooth}/host/misc/multiple_id/prj.conf | 0 .../host/misc/multiple_id/src/main.c | 0 .../multiple_id/tests_scripts/multiple.sh | 4 +- .../host/privacy/central/CMakeLists.txt | 0 .../bluetooth}/host/privacy/central/prj.conf | 0 .../host/privacy/central/src/bs_bt_utils.c | 0 .../host/privacy/central/src/bs_bt_utils.h | 0 .../bluetooth}/host/privacy/central/src/dut.c | 0 .../host/privacy/central/src/main.c | 0 .../host/privacy/central/src/tester.c | 0 .../privacy/central/test_scripts/_compile.sh | 0 .../host/privacy/central/test_scripts/_env.sh | 2 +- .../privacy/central/test_scripts/run_test.sh | 0 .../host/privacy/device/CMakeLists.txt | 0 .../bluetooth}/host/privacy/device/README.rst | 0 .../bluetooth}/host/privacy/device/prj.conf | 0 .../device/src/test_undirected_central.c | 0 .../privacy/device/src/test_undirected_main.c | 0 .../device/src/test_undirected_peripheral.c | 0 .../privacy/device/test_scripts/_compile.sh | 0 .../host/privacy/device/test_scripts/_env.sh | 2 +- .../privacy/device/test_scripts/run_tests.sh | 0 .../host/privacy/peripheral/CMakeLists.txt | 0 .../host/privacy/peripheral/prj.conf | 0 .../host/privacy/peripheral/src/bs_bt_utils.c | 0 .../host/privacy/peripheral/src/bs_bt_utils.h | 0 .../host/privacy/peripheral/src/dut.c | 0 .../host/privacy/peripheral/src/main.c | 0 .../host/privacy/peripheral/src/tester.c | 0 .../peripheral/test_scripts/_compile.sh | 0 .../privacy/peripheral/test_scripts/_env.sh | 2 +- .../peripheral/test_scripts/run_test.sh | 0 .../bond_overwrite_allowed/CMakeLists.txt | 0 .../security/bond_overwrite_allowed/prj.conf | 0 .../bond_overwrite_allowed/src/bs_bt_utils.c | 0 .../bond_overwrite_allowed/src/bs_bt_utils.h | 0 .../bond_overwrite_allowed/src/central.c | 0 .../bond_overwrite_allowed/src/main.c | 0 .../bond_overwrite_allowed/src/peripheral.c | 0 .../test_scripts/_compile.sh | 4 +- .../test_scripts/_env.sh | 2 +- .../test_scripts/run_test.sh | 0 .../bond_overwrite_denied/CMakeLists.txt | 0 .../security/bond_overwrite_denied/prj.conf | 0 .../bond_overwrite_denied/src/bs_bt_utils.c | 0 .../bond_overwrite_denied/src/bs_bt_utils.h | 0 .../bond_overwrite_denied/src/central.c | 0 .../security/bond_overwrite_denied/src/main.c | 0 .../bond_overwrite_denied/src/peripheral.c | 0 .../test_scripts/_compile.sh | 4 +- .../test_scripts/_env.sh | 2 +- .../test_scripts/run_test.sh | 0 .../bluetooth}/ll/advx/CMakeLists.txt | 0 .../bsim => bsim/bluetooth}/ll/advx/prj.conf | 0 .../bluetooth}/ll/advx/src/main.c | 0 .../ll/advx/tests_scripts/basic_advx.sh | 4 +- .../bsim => bsim/bluetooth}/ll/compile.sh | 20 +++---- .../bluetooth}/ll/conn/CMakeLists.txt | 0 .../bluetooth}/ll/conn/README.txt | 0 .../bluetooth}/ll/conn/prj_split.conf | 0 .../bluetooth}/ll/conn/prj_split_low_lat.conf | 0 .../bluetooth}/ll/conn/prj_split_privacy.conf | 0 .../bluetooth}/ll/conn/src/main.c | 0 .../bluetooth}/ll/conn/src/test_connect1.c | 0 .../bluetooth}/ll/conn/src/test_connect2.c | 0 .../bluetooth}/ll/conn/src/test_empty.c | 0 .../basic_conn_encrypted_split.sh | 4 +- .../basic_conn_encrypted_split_privacy.sh | 4 +- .../ll/conn/tests_scripts/basic_conn_split.sh | 4 +- .../tests_scripts/basic_conn_split_low_lat.sh | 4 +- .../bluetooth}/ll/edtt/README.txt | 6 +- .../bluetooth}/ll/edtt/common/commands.h | 0 .../bluetooth}/ll/edtt/common/edtt_driver.h | 0 .../ll/edtt/common/edtt_driver_bsim.c | 0 .../ll/edtt/gatt_test_app/CMakeLists.txt | 0 .../ll/edtt/gatt_test_app/prj_llcp.conf | 0 .../edtt/gatt_test_app/src/gatt/gatt_macs.h | 0 .../edtt/gatt_test_app/src/gatt/service_a_1.c | 0 .../edtt/gatt_test_app/src/gatt/service_a_1.h | 0 .../edtt/gatt_test_app/src/gatt/service_a_2.c | 0 .../edtt/gatt_test_app/src/gatt/service_a_2.h | 0 .../edtt/gatt_test_app/src/gatt/service_a_3.c | 0 .../edtt/gatt_test_app/src/gatt/service_a_3.h | 0 .../gatt_test_app/src/gatt/service_b_1_1.c | 0 .../gatt_test_app/src/gatt/service_b_1_1.h | 0 .../gatt_test_app/src/gatt/service_b_1_2.c | 0 .../gatt_test_app/src/gatt/service_b_1_2.h | 0 .../gatt_test_app/src/gatt/service_b_1_3.c | 0 .../gatt_test_app/src/gatt/service_b_1_3.h | 0 .../gatt_test_app/src/gatt/service_b_2_1.c | 0 .../gatt_test_app/src/gatt/service_b_2_1.h | 0 .../gatt_test_app/src/gatt/service_b_2_2.c | 0 .../gatt_test_app/src/gatt/service_b_2_2.h | 0 .../gatt_test_app/src/gatt/service_b_2_3.c | 0 .../gatt_test_app/src/gatt/service_b_2_3.h | 0 .../gatt_test_app/src/gatt/service_b_3_1.c | 0 .../gatt_test_app/src/gatt/service_b_3_1.h | 0 .../gatt_test_app/src/gatt/service_b_3_2.c | 0 .../gatt_test_app/src/gatt/service_b_3_2.h | 0 .../gatt_test_app/src/gatt/service_b_3_3.c | 0 .../gatt_test_app/src/gatt/service_b_3_3.h | 0 .../gatt_test_app/src/gatt/service_b_4_1.c | 0 .../gatt_test_app/src/gatt/service_b_4_1.h | 0 .../gatt_test_app/src/gatt/service_b_4_2.c | 0 .../gatt_test_app/src/gatt/service_b_4_2.h | 0 .../gatt_test_app/src/gatt/service_b_4_3.c | 0 .../gatt_test_app/src/gatt/service_b_4_3.h | 0 .../gatt_test_app/src/gatt/service_b_5_1.c | 0 .../gatt_test_app/src/gatt/service_b_5_1.h | 0 .../gatt_test_app/src/gatt/service_b_5_2.c | 0 .../gatt_test_app/src/gatt/service_b_5_2.h | 0 .../gatt_test_app/src/gatt/service_b_5_3.c | 0 .../gatt_test_app/src/gatt/service_b_5_3.h | 0 .../gatt_test_app/src/gatt/service_c_1_1.c | 0 .../gatt_test_app/src/gatt/service_c_1_1.h | 0 .../gatt_test_app/src/gatt/service_c_1_2.c | 0 .../gatt_test_app/src/gatt/service_c_1_2.h | 0 .../gatt_test_app/src/gatt/service_c_1_3.c | 0 .../gatt_test_app/src/gatt/service_c_1_3.h | 0 .../gatt_test_app/src/gatt/service_c_2_1.c | 0 .../gatt_test_app/src/gatt/service_c_2_1.h | 0 .../gatt_test_app/src/gatt/service_c_2_2.c | 0 .../gatt_test_app/src/gatt/service_c_2_2.h | 0 .../gatt_test_app/src/gatt/service_c_2_3.c | 0 .../gatt_test_app/src/gatt/service_c_2_3.h | 0 .../edtt/gatt_test_app/src/gatt/service_d_1.c | 0 .../edtt/gatt_test_app/src/gatt/service_d_1.h | 0 .../edtt/gatt_test_app/src/gatt/service_d_2.c | 0 .../edtt/gatt_test_app/src/gatt/service_d_2.h | 0 .../edtt/gatt_test_app/src/gatt/service_d_3.c | 0 .../edtt/gatt_test_app/src/gatt/service_d_3.h | 0 .../edtt/gatt_test_app/src/gatt/service_e_2.c | 0 .../edtt/gatt_test_app/src/gatt/service_e_2.h | 0 .../edtt/gatt_test_app/src/gatt/service_e_3.c | 0 .../edtt/gatt_test_app/src/gatt/service_e_3.h | 0 .../edtt/gatt_test_app/src/gatt/service_f_1.c | 0 .../edtt/gatt_test_app/src/gatt/service_f_1.h | 0 .../ll/edtt/gatt_test_app/src/gatt/services.h | 0 .../ll/edtt/gatt_test_app/src/main.c | 0 .../ll/edtt/hci_test_app/CMakeLists.txt | 0 .../ll/edtt/hci_test_app/prj_dut_llcp.conf | 0 .../ll/edtt/hci_test_app/prj_tst_llcp.conf | 0 .../ll/edtt/hci_test_app/src/main.c | 0 .../tests_scripts/_controller_tests_inner.sh | 4 +- .../ll/edtt/tests_scripts/gap.llcp.sh | 0 .../ll/edtt/tests_scripts/gap.llcp.test_list | 0 .../ll/edtt/tests_scripts/gatt.llcp.sh | 4 +- .../ll/edtt/tests_scripts/gatt.llcp.test_list | 0 .../ll/edtt/tests_scripts/hci.llcp.sh | 0 .../ll/edtt/tests_scripts/hci.llcp.test_list | 0 .../ll/edtt/tests_scripts/ll.1.llcp.sh | 0 .../ll/edtt/tests_scripts/ll.2.llcp.sh | 0 .../edtt/tests_scripts/ll.set1.llcp.test_list | 0 .../edtt/tests_scripts/ll.set2.llcp.test_list | 0 .../bluetooth}/ll/iso/CMakeLists.txt | 0 .../bsim => bsim/bluetooth}/ll/iso/prj.conf | 0 .../bluetooth}/ll/iso/prj_vs_dp.conf | 0 .../bsim => bsim/bluetooth}/ll/iso/src/main.c | 0 .../ll/iso/tests_scripts/broadcast_iso.sh | 4 +- .../iso/tests_scripts/broadcast_iso_vs_dp.sh | 4 +- .../bluetooth}/mesh/CMakeLists.txt | 0 .../bsim => bsim/bluetooth}/mesh/README.rst | 2 +- .../bluetooth}/mesh/_mesh_test.sh | 4 +- .../bsim => bsim/bluetooth}/mesh/compile.sh | 20 +++---- .../bluetooth}/mesh/overlay_gatt.conf | 0 .../bluetooth}/mesh/overlay_low_lat.conf | 0 .../bluetooth}/mesh/overlay_pst.conf | 0 .../bsim => bsim/bluetooth}/mesh/prj.conf | 0 .../bluetooth}/mesh/prj_mesh1d1.conf | 0 .../bluetooth}/mesh/src/dfu_blob_common.c | 0 .../bluetooth}/mesh/src/dfu_blob_common.h | 0 .../bsim => bsim/bluetooth}/mesh/src/main.c | 0 .../bluetooth}/mesh/src/mesh_test.c | 0 .../bluetooth}/mesh/src/mesh_test.h | 0 .../mesh/src/settings_test_backend.c | 0 .../mesh/src/settings_test_backend.h | 0 .../bluetooth}/mesh/src/test_access.c | 0 .../bluetooth}/mesh/src/test_advertiser.c | 0 .../bluetooth}/mesh/src/test_beacon.c | 0 .../bluetooth}/mesh/src/test_blob.c | 0 .../bluetooth}/mesh/src/test_dfu.c | 0 .../bluetooth}/mesh/src/test_friendship.c | 0 .../bluetooth}/mesh/src/test_heartbeat.c | 0 .../bluetooth}/mesh/src/test_iv_index.c | 0 .../bluetooth}/mesh/src/test_lcd.c | 0 .../bluetooth}/mesh/src/test_op_agg.c | 0 .../bluetooth}/mesh/src/test_persistence.c | 0 .../bluetooth}/mesh/src/test_provision.c | 0 .../bluetooth}/mesh/src/test_replay_cache.c | 0 .../bluetooth}/mesh/src/test_sar.c | 0 .../bluetooth}/mesh/src/test_scanner.c | 0 .../bluetooth}/mesh/src/test_transport.c | 0 .../tests_scripts/access/access_cancel.sh | 0 .../tests_scripts/access/access_ext_sub.sh | 0 .../access/access_ext_sub_cap.sh | 0 .../tests_scripts/access/access_period.sh | 0 .../tests_scripts/access/access_transmit.sh | 0 .../tests_scripts/advertiser/proxy_mixin.sh | 0 .../tests_scripts/advertiser/random_order.sh | 0 .../tests_scripts/advertiser/reverse_order.sh | 0 .../tests_scripts/advertiser/send_order.sh | 0 .../tests_scripts/advertiser/tx_cb_multi.sh | 0 .../tests_scripts/advertiser/tx_cb_single.sh | 0 .../tests_scripts/beacon/beacon_interval.sh | 0 .../mesh/tests_scripts/beacon/invalid.sh | 0 .../mesh/tests_scripts/beacon/iv_update.sh | 0 .../mesh/tests_scripts/beacon/key_refresh.sh | 0 .../mesh/tests_scripts/beacon/kr_old_key.sh | 0 .../tests_scripts/beacon/multiple_netkeys.sh | 0 .../blob_mdls/blob_cli_broadcast.sh | 0 .../tests_scripts/blob_mdls/blob_cli_caps.sh | 0 .../blob_mdls/blob_cli_no_rsp.sh | 0 .../blob_mdls/blob_cli_persistent_transfer.sh | 0 .../blob_cli_persistent_transfer_pull.sh | 0 .../blob_mdls/blob_cli_trans_complete_pull.sh | 0 .../blob_mdls/blob_cli_trans_complete_push.sh | 0 .../blob_mdls/blob_cli_trans_resume_pull.sh | 0 .../blob_mdls/blob_cli_trans_resume_push.sh | 0 .../dfu/dfu_cli_persistent_transfer.sh | 0 .../tests_scripts/dfu/dfu_dist_self_update.sh | 0 .../dfu/dfu_dist_self_update_mult_targets.sh | 0 .../mesh/tests_scripts/dfu/dfu_mixed.sh | 0 .../mesh/tests_scripts/dfu/dfu_mixed_fail.sh | 0 .../mesh/tests_scripts/dfu/dfu_slot.sh | 0 .../tests_scripts/friendship/establish.sh | 0 .../friendship/establish_multi.sh | 0 .../tests_scripts/friendship/lpn_disable.sh | 0 .../tests_scripts/friendship/lpn_loopback.sh | 0 .../friendship/lpn_terminate_cb.sh | 0 .../mesh/tests_scripts/friendship/msg_frnd.sh | 0 .../tests_scripts/friendship/msg_group.sh | 0 .../mesh/tests_scripts/friendship/msg_mesh.sh | 0 .../friendship/msg_mesh_low_lat.sh | 0 .../mesh/tests_scripts/friendship/overflow.sh | 0 .../mesh/tests_scripts/friendship/poll.sh | 0 .../tests_scripts/friendship/re-establish.sh | 0 .../tests_scripts/heartbeat/sub_cb_api_all.sh | 0 .../heartbeat/sub_cb_api_unicast.sh | 0 .../tests_scripts/iv_index/iv_deferring.sh | 0 .../tests_scripts/iv_index/iv_recovery.sh | 0 .../mesh/tests_scripts/iv_index/iv_update.sh | 0 .../large_comp_data/get_comp_data_max_sdu.sh | 0 .../large_comp_data/get_comp_data_split.sh | 0 .../large_comp_data/get_metadata_max_sdu.sh | 0 .../large_comp_data/get_metadata_split.sh | 0 .../op_agg/full_status_msg_list.sh | 0 .../mesh/tests_scripts/persistence/access.sh | 0 .../mesh/tests_scripts/persistence/cfg.sh | 0 .../tests_scripts/persistence/provisioning.sh | 0 .../persistence/reprovisioning.sh | 0 .../provision/ivu_flag_one_duration.sh | 0 .../provision/ivu_flag_zero_duration.sh | 0 .../tests_scripts/provision/pb_adv_multi.sh | 0 .../tests_scripts/provision/pb_adv_no_oob.sh | 0 .../provision/pb_adv_oob_auth_ib_pk.sh | 0 .../pb_adv_oob_auth_ignore_oob_pk.sh | 0 .../provision/pb_adv_oob_auth_oob_pk.sh | 0 .../provision/pb_adv_reprovision.sh | 0 .../provision/pb_remote_nppi_robustness.sh | 0 .../provision/pb_remote_pst_ncrp.sh | 0 .../provision/pb_remote_reprovision.sh | 0 .../replay_cache/replay_attack.sh | 0 .../tests_scripts/replay_cache/rpl_frag.sh | 0 .../tests_scripts/sar/slow_transfer_test.sh | 0 .../mesh/tests_scripts/sar/stress_test.sh | 0 .../tests_scripts/scanner/invalid_ad_type.sh | 0 .../scanner/wrong_packet_length.sh | 0 .../mesh/tests_scripts/transport/group.sh | 0 .../mesh/tests_scripts/transport/loopback.sh | 0 .../tests_scripts/transport/loopback_group.sh | 0 .../transport/loopback_group_low_lat.sh | 0 .../mesh/tests_scripts/transport/seg_block.sh | 0 .../tests_scripts/transport/seg_concurrent.sh | 0 .../mesh/tests_scripts/transport/seg_fail.sh | 0 .../mesh/tests_scripts/transport/seg_ivu.sh | 0 .../mesh/tests_scripts/transport/unicast.sh | 0 .../transport/unicast_low_lat.sh | 0 .../tests_scripts/transport/unknown_app.sh | 0 .../mesh/tests_scripts/transport/va.sh | 0 .../bsim => bsim/bluetooth}/run_parallel.sh | 0 .../bsim => bsim/bluetooth}/sh_common.source | 0 500 files changed, 223 insertions(+), 223 deletions(-) delete mode 100755 tests/bluetooth/bsim/host/compile.sh rename tests/{bluetooth/bsim => bsim/bluetooth}/README.txt (58%) rename tests/{bluetooth/bsim => bsim/bluetooth}/_compile_permutate_kconfigs.sh (95%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/Kconfig (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/README.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/compile.sh (85%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/bap_broadcast_assistant_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/bap_scan_delegator_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/bap_unicast_client_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/bap_unicast_common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/bap_unicast_common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/bap_unicast_server_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/bass_broadcaster_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/broadcast_sink_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/broadcast_source_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/cap_acceptor_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/cap_initiator_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/csip_set_coordinator_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/csip_set_member_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/has_client_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/has_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/ias_client_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/ias_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/mcc_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/mcs_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/media_controller_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/micp_mic_ctlr_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/micp_mic_dev_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/tbs_client_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/tbs_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/vcp_vol_ctlr_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/src/vcp_vol_rend_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/_cap.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/bap_bass.sh (86%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/bap_broadcast_audio.sh (86%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/bap_unicast_audio.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/cap_broadcast.sh (90%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/cap_unicast.sh (90%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/csip.sh (81%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/has.sh (88%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/ias.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/mcs_mcc.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/media_controller.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/micp.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/tbs.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/audio/test_scripts/vcp.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/compile.sh (65%) rename tests/{bluetooth/bsim => bsim/bluetooth}/compile.source (97%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/chain/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/chain/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/chain/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/chain/tests_scripts/adv_chain.sh (88%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/periodic/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/periodic/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/periodic/prj_long_data.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/periodic/src/common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/periodic/src/common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/periodic/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/periodic/src/per_adv_advertiser.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/periodic/src/per_adv_syncer.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/periodic/tests_scripts/per_adv.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/periodic/tests_scripts/per_adv_conn.sh (90%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh (90%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/periodic/tests_scripts/per_adv_long_data.sh (90%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/resume/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/resume/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/resume/prj_2.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/resume/src/bs_bt_utils.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/resume/src/bs_bt_utils.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/resume/src/dut.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/resume/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/resume/src/tester.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/resume/test_scripts/_compile.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/resume/test_scripts/_env.sh (75%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/resume/test_scripts/run_adv_resume.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/adv/resume/test_scripts/run_adv_resume_2.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/prj_autoconnect.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/prj_collision.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/prj_multiple_conn.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/src/common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/src/common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/src/main_autoconnect.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/src/main_collision.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/src/main_reconfigure.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/tests_scripts/autoconnect.sh (88%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/tests_scripts/collision.sh (87%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/tests_scripts/multiple_conn.sh (88%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt/tests_scripts/reconfigure.sh (88%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt_notif/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt_notif/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt_notif/src/client_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt_notif/src/common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt_notif/src/common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt_notif/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt_notif/src/server_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/eatt_notif/test_scripts/eatt_notif.sh (88%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/mtu_update/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/mtu_update/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/mtu_update/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/mtu_update/test_scripts/_compile.sh (84%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/mtu_update/test_scripts/_env.sh (92%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/att/mtu_update/test_scripts/run_test.sh (100%) create mode 100755 tests/bsim/bluetooth/host/compile.sh rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/src/common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/src/common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/src/gatt_client_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/src/gatt_server_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/test_scripts/_run_test.sh (87%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_eatt.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_no_eatt.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_eatt.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_no_eatt.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/test_scripts/gatt_caching_retry_reads_eatt.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/caching/test_scripts/gatt_caching_retry_reads_no_eatt.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/general/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/general/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/general/src/common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/general/src/common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/general/src/gatt_client_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/general/src/gatt_server_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/general/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/general/test_scripts/gatt.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/src/common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/src/common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/src/gatt_client_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/src/gatt_server_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/_run_test.sh (87%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_enhanced_enhanced.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_enhanced_mixed.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_enhanced_none.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_enhanced_unenhanced.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_mixed_enhanced.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_mixed_mixed.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_mixed_none.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_mixed_unenhanced.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_none_enhanced.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_none_mixed.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_none_none.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_none_unenhanced.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_unenhanced_enhanced.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_unenhanced_mixed.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_unenhanced_none.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify/test_scripts/gatt_notify_unenhanced_unenhanced.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify_multiple/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify_multiple/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify_multiple/src/common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify_multiple/src/common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify_multiple/src/gatt_client_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify_multiple/src/gatt_server_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify_multiple/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify_multiple/test_scripts/_notify-debug.sh (88%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/notify_multiple/test_scripts/notify.sh (88%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/prj_2.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/src/client.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/src/gatt_utils.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/src/gatt_utils.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/src/main.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/src/server.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/src/settings.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/src/utils.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/src/utils.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/test_scripts/_compile.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/test_scripts/_env.sh (75%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/test_scripts/run_gatt_settings.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/settings/test_scripts/run_gatt_settings_2.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/write/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/write/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/write/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/gatt/write/tests_scripts/gatt_write.sh (88%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/general/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/general/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/general/src/common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/general/src/common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/general/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/general/src/main_l2cap_ecred.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/general/tests_scripts/l2cap.sh (88%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/stress/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/stress/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/stress/src/common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/stress/src/common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/stress/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/stress/tests_scripts/l2cap.sh (95%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/userdata/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/userdata/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/userdata/src/common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/userdata/src/common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/userdata/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/userdata/src/main_l2cap_userdata.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/l2cap/userdata/tests_scripts/l2cap.sh (88%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/disable/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/disable/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/disable/src/common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/disable/src/common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/disable/src/gatt_client_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/disable/src/gatt_server_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/disable/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/disable/src/main_disable.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/disable/tests_scripts/disable.sh (93%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/disable/tests_scripts/disable_with_gatt.sh (90%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/multiple_id/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/multiple_id/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/multiple_id/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/misc/multiple_id/tests_scripts/multiple.sh (88%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/central/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/central/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/central/src/bs_bt_utils.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/central/src/bs_bt_utils.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/central/src/dut.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/central/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/central/src/tester.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/central/test_scripts/_compile.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/central/test_scripts/_env.sh (92%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/central/test_scripts/run_test.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/device/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/device/README.rst (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/device/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/device/src/test_undirected_central.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/device/src/test_undirected_main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/device/src/test_undirected_peripheral.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/device/test_scripts/_compile.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/device/test_scripts/_env.sh (86%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/device/test_scripts/run_tests.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/peripheral/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/peripheral/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/peripheral/src/bs_bt_utils.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/peripheral/src/bs_bt_utils.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/peripheral/src/dut.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/peripheral/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/peripheral/src/tester.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/peripheral/test_scripts/_compile.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/peripheral/test_scripts/_env.sh (92%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/privacy/peripheral/test_scripts/run_test.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_allowed/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_allowed/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_allowed/src/bs_bt_utils.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_allowed/src/bs_bt_utils.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_allowed/src/central.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_allowed/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_allowed/src/peripheral.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_allowed/test_scripts/_compile.sh (84%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_allowed/test_scripts/_env.sh (92%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_allowed/test_scripts/run_test.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_denied/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_denied/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_denied/src/bs_bt_utils.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_denied/src/bs_bt_utils.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_denied/src/central.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_denied/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_denied/src/peripheral.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_denied/test_scripts/_compile.sh (84%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_denied/test_scripts/_env.sh (92%) rename tests/{bluetooth/bsim => bsim/bluetooth}/host/security/bond_overwrite_denied/test_scripts/run_test.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/advx/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/advx/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/advx/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/advx/tests_scripts/basic_advx.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/compile.sh (57%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/conn/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/conn/README.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/conn/prj_split.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/conn/prj_split_low_lat.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/conn/prj_split_privacy.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/conn/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/conn/src/test_connect1.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/conn/src/test_connect2.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/conn/src/test_empty.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/conn/tests_scripts/basic_conn_encrypted_split.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/conn/tests_scripts/basic_conn_split.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/conn/tests_scripts/basic_conn_split_low_lat.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/README.txt (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/common/commands.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/common/edtt_driver.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/common/edtt_driver_bsim.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/prj_llcp.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/gatt_macs.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_a_1.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_a_1.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_a_2.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_a_2.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_a_3.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_a_3.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_d_1.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_d_1.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_d_2.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_d_2.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_d_3.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_d_3.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_e_2.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_e_2.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_e_3.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_e_3.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_f_1.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/service_f_1.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/gatt/services.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/gatt_test_app/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/hci_test_app/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/hci_test_app/prj_dut_llcp.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/hci_test_app/prj_tst_llcp.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/hci_test_app/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/tests_scripts/_controller_tests_inner.sh (96%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/tests_scripts/gap.llcp.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/tests_scripts/gap.llcp.test_list (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/tests_scripts/gatt.llcp.sh (90%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/tests_scripts/gatt.llcp.test_list (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/tests_scripts/hci.llcp.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/tests_scripts/hci.llcp.test_list (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/tests_scripts/ll.1.llcp.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/tests_scripts/ll.2.llcp.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/tests_scripts/ll.set1.llcp.test_list (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/edtt/tests_scripts/ll.set2.llcp.test_list (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/iso/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/iso/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/iso/prj_vs_dp.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/iso/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/iso/tests_scripts/broadcast_iso.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh (89%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/CMakeLists.txt (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/README.rst (98%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/_mesh_test.sh (93%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/compile.sh (64%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/overlay_gatt.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/overlay_low_lat.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/overlay_pst.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/prj.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/prj_mesh1d1.conf (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/dfu_blob_common.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/dfu_blob_common.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/main.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/mesh_test.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/mesh_test.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/settings_test_backend.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/settings_test_backend.h (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_access.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_advertiser.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_beacon.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_blob.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_dfu.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_friendship.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_heartbeat.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_iv_index.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_lcd.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_op_agg.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_persistence.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_provision.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_replay_cache.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_sar.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_scanner.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/src/test_transport.c (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/access/access_cancel.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/access/access_ext_sub.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/access/access_ext_sub_cap.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/access/access_period.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/access/access_transmit.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/advertiser/proxy_mixin.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/advertiser/random_order.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/advertiser/reverse_order.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/advertiser/send_order.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/advertiser/tx_cb_multi.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/advertiser/tx_cb_single.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/beacon/beacon_interval.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/beacon/invalid.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/beacon/iv_update.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/beacon/key_refresh.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/beacon/kr_old_key.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/beacon/multiple_netkeys.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/blob_mdls/blob_cli_broadcast.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/blob_mdls/blob_cli_caps.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer_pull.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_pull.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_push.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_pull.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_push.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/dfu/dfu_cli_persistent_transfer.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/dfu/dfu_dist_self_update.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/dfu/dfu_dist_self_update_mult_targets.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/dfu/dfu_mixed.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/dfu/dfu_mixed_fail.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/dfu/dfu_slot.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/friendship/establish.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/friendship/establish_multi.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/friendship/lpn_disable.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/friendship/lpn_loopback.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/friendship/lpn_terminate_cb.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/friendship/msg_frnd.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/friendship/msg_group.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/friendship/msg_mesh.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/friendship/msg_mesh_low_lat.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/friendship/overflow.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/friendship/poll.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/friendship/re-establish.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/heartbeat/sub_cb_api_all.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/heartbeat/sub_cb_api_unicast.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/iv_index/iv_deferring.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/iv_index/iv_recovery.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/iv_index/iv_update.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/large_comp_data/get_comp_data_max_sdu.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/large_comp_data/get_comp_data_split.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/large_comp_data/get_metadata_max_sdu.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/large_comp_data/get_metadata_split.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/op_agg/full_status_msg_list.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/persistence/access.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/persistence/cfg.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/persistence/provisioning.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/persistence/reprovisioning.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/provision/ivu_flag_one_duration.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/provision/ivu_flag_zero_duration.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/provision/pb_adv_multi.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/provision/pb_adv_no_oob.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/provision/pb_adv_oob_auth_ib_pk.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/provision/pb_adv_oob_auth_ignore_oob_pk.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/provision/pb_adv_oob_auth_oob_pk.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/provision/pb_adv_reprovision.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/provision/pb_remote_nppi_robustness.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/provision/pb_remote_pst_ncrp.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/provision/pb_remote_reprovision.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/replay_cache/replay_attack.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/replay_cache/rpl_frag.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/sar/slow_transfer_test.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/sar/stress_test.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/scanner/invalid_ad_type.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/scanner/wrong_packet_length.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/transport/group.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/transport/loopback.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/transport/loopback_group.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/transport/loopback_group_low_lat.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/transport/seg_block.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/transport/seg_concurrent.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/transport/seg_fail.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/transport/seg_ivu.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/transport/unicast.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/transport/unicast_low_lat.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/transport/unknown_app.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/mesh/tests_scripts/transport/va.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/run_parallel.sh (100%) rename tests/{bluetooth/bsim => bsim/bluetooth}/sh_common.source (100%) diff --git a/.github/workflows/bluetooth-tests.yaml b/.github/workflows/bluetooth-tests.yaml index 5c4153cc1266..6a059407c814 100644 --- a/.github/workflows/bluetooth-tests.yaml +++ b/.github/workflows/bluetooth-tests.yaml @@ -6,7 +6,7 @@ on: - ".github/workflows/bluetooth-test*.yaml" - "west.yml" - "subsys/bluetooth/**" - - "tests/bluetooth/bsim/**" + - "tests/bsim/bluetooth/**" - "samples/bluetooth/**" - "boards/posix/**" - "soc/posix/**" @@ -76,9 +76,9 @@ jobs: - name: Run Bluetooth Tests with BSIM run: | export ZEPHYR_BASE=${PWD} - WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bluetooth/bsim/compile.sh + WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/bluetooth/compile.sh RESULTS_FILE=${ZEPHYR_BASE}/${bsim_bt_test_results_file} \ - SEARCH_PATH=tests/bluetooth/bsim/ tests/bluetooth/bsim/run_parallel.sh + SEARCH_PATH=tests/bsim/bluetooth/ tests/bsim/bluetooth/run_parallel.sh - name: Upload Test Results if: always() diff --git a/CODEOWNERS b/CODEOWNERS index a8e818d98273..539c3bc26cf4 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -830,9 +830,9 @@ scripts/build/gen_image_info.py @tejlmand /tests/boards/native_posix/ @aescolar @daor-oti /tests/bluetooth/ @alwa-nordic @jhedberg @Vudentz @sjanc /tests/bluetooth/controller/ @cvinayak @thoh-ot @kruithofa @erbr-ot @sjanc @ppryga -/tests/bluetooth/bsim/ @alwa-nordic @jhedberg @Vudentz @wopu-ot -/tests/bluetooth/bsim/audio/ @jhedberg @Vudentz @wopu-ot @Thalley -/tests/bluetooth/bsim/mesh/ @jhedberg @Vudentz @wopu-ot @PavelVPV +/tests/bsim/bluetooth/ @alwa-nordic @jhedberg @Vudentz @wopu-ot +/tests/bsim/bluetooth/audio/ @jhedberg @Vudentz @wopu-ot @Thalley +/tests/bsim/bluetooth/mesh/ @jhedberg @Vudentz @wopu-ot @PavelVPV /tests/bluetooth/mesh_shell/ @jhedberg @Vudentz @sjanc @PavelVPV /tests/bluetooth/tester/ @alwa-nordic @jhedberg @Vudentz @sjanc /tests/posix/ @cfriedt diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index 975b54e5ce46..a94592f0811c 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -210,7 +210,7 @@ Bluetooth: - samples/bluetooth/mesh/ - subsys/bluetooth/audio/ - include/zephyr/bluetooth/audio/ - - tests/bluetooth/bsim/audio/ + - tests/bsim/bluetooth/audio/ - tests/bluetooth/controller/ - tests/bluetooth/mesh_*/ - tests/bluetooth/mesh/ @@ -272,7 +272,7 @@ Bluetooth Audio: files: - subsys/bluetooth/audio/ - include/zephyr/bluetooth/audio/ - - tests/bluetooth/bsim/audio/ + - tests/bsim/bluetooth/audio/ - tests/bluetooth/shell/audio* labels: - "area: Bluetooth Audio" diff --git a/tests/bluetooth/bsim/host/compile.sh b/tests/bluetooth/bsim/host/compile.sh deleted file mode 100755 index 5b56fb8495b1..000000000000 --- a/tests/bluetooth/bsim/host/compile.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Compile all the applications needed by the bsim tests - -#set -x #uncomment this line for debugging -set -ue - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" -: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ - directory}" - -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" -BOARD="${BOARD:-nrf52_bsim}" -BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" - -mkdir -p ${WORK_DIR} - -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source - -app=tests/bluetooth/bsim/host/adv/resume compile -app=tests/bluetooth/bsim/host/adv/resume conf_file=prj_2.conf compile -app=tests/bluetooth/bsim/host/adv/chain compile -app=tests/bluetooth/bsim/host/adv/periodic compile -app=tests/bluetooth/bsim/host/adv/periodic conf_file=prj_long_data.conf compile - -app=tests/bluetooth/bsim/host/att/eatt conf_file=prj_collision.conf compile -app=tests/bluetooth/bsim/host/att/eatt conf_file=prj_multiple_conn.conf compile -app=tests/bluetooth/bsim/host/att/eatt conf_file=prj_autoconnect.conf compile -app=tests/bluetooth/bsim/host/att/eatt_notif conf_file=prj.conf compile -app=tests/bluetooth/bsim/host/att/mtu_update compile - -app=tests/bluetooth/bsim/host/gatt/caching compile -app=tests/bluetooth/bsim/host/gatt/general compile -app=tests/bluetooth/bsim/host/gatt/notify compile -app=tests/bluetooth/bsim/host/gatt/notify_multiple compile -app=tests/bluetooth/bsim/host/gatt/settings compile -app=tests/bluetooth/bsim/host/gatt/settings conf_file=prj_2.conf compile -app=tests/bluetooth/bsim/host/gatt/write compile - -app=tests/bluetooth/bsim/host/l2cap/general compile -app=tests/bluetooth/bsim/host/l2cap/userdata compile -app=tests/bluetooth/bsim/host/l2cap/stress compile - -app=tests/bluetooth/bsim/host/misc/disable compile -app=tests/bluetooth/bsim/host/misc/multiple_id compile - -app=tests/bluetooth/bsim/host/privacy/central compile -app=tests/bluetooth/bsim/host/privacy/peripheral compile -app=tests/bluetooth/bsim/host/privacy/device compile - -app=tests/bluetooth/bsim/host/security/bond_overwrite_allowed compile -app=tests/bluetooth/bsim/host/security/bond_overwrite_denied compile - -wait_for_background_jobs diff --git a/tests/bluetooth/bsim/README.txt b/tests/bsim/bluetooth/README.txt similarity index 58% rename from tests/bluetooth/bsim/README.txt rename to tests/bsim/bluetooth/README.txt index 9edb580bd09c..9730170b0a85 100644 --- a/tests/bluetooth/bsim/README.txt +++ b/tests/bsim/bluetooth/README.txt @@ -7,9 +7,9 @@ the needed images and execute these tests in batch. You can also run them manually if desired, but be sure to call them setting the variables they expect. For example, from Zephyr's root folder, you can run: -WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bluetooth/bsim/compile.sh -RESULTS_FILE=${ZEPHYR_BASE}/myresults.xml SEARCH_PATH=tests/bluetooth/bsim tests/bluetooth/bsim/run_parallel.sh +WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/bluetooth/compile.sh +RESULTS_FILE=${ZEPHYR_BASE}/myresults.xml SEARCH_PATH=tests/bsim/bluetooth tests/bsim/bluetooth/run_parallel.sh Or to run only a specific subset, e.g. host advertising tests: -WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bluetooth/bsim/host/compile.sh -RESULTS_FILE=${ZEPHYR_BASE}/myresults.xml SEARCH_PATH=tests/bluetooth/bsim/host/adv tests/bluetooth/bsim/run_parallel.sh +WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/bluetooth/host/compile.sh +RESULTS_FILE=${ZEPHYR_BASE}/myresults.xml SEARCH_PATH=tests/bsim/bluetooth/host/adv tests/bsim/bluetooth/run_parallel.sh diff --git a/tests/bluetooth/bsim/_compile_permutate_kconfigs.sh b/tests/bsim/bluetooth/_compile_permutate_kconfigs.sh similarity index 95% rename from tests/bluetooth/bsim/_compile_permutate_kconfigs.sh rename to tests/bsim/bluetooth/_compile_permutate_kconfigs.sh index 7f6bacb729b7..61af911041fd 100755 --- a/tests/bluetooth/bsim/_compile_permutate_kconfigs.sh +++ b/tests/bsim/bluetooth/_compile_permutate_kconfigs.sh @@ -21,7 +21,7 @@ BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source +source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source declare -a list=( @@ -62,7 +62,7 @@ perm_compile() { echo "Compile with config overlay:" cat $3 fi - local app=tests/bluetooth/bsim/edtt_ble_test_app/hci_test_app + local app=tests/bsim/bluetooth/edtt_ble_test_app/hci_test_app local conf_file=prj_dut_llcp.conf local conf_overlay=$3 compile diff --git a/tests/bluetooth/bsim/audio/CMakeLists.txt b/tests/bsim/bluetooth/audio/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/audio/CMakeLists.txt rename to tests/bsim/bluetooth/audio/CMakeLists.txt diff --git a/tests/bluetooth/bsim/audio/Kconfig b/tests/bsim/bluetooth/audio/Kconfig similarity index 100% rename from tests/bluetooth/bsim/audio/Kconfig rename to tests/bsim/bluetooth/audio/Kconfig diff --git a/tests/bluetooth/bsim/audio/README.txt b/tests/bsim/bluetooth/audio/README.txt similarity index 100% rename from tests/bluetooth/bsim/audio/README.txt rename to tests/bsim/bluetooth/audio/README.txt diff --git a/tests/bluetooth/bsim/audio/compile.sh b/tests/bsim/bluetooth/audio/compile.sh similarity index 85% rename from tests/bluetooth/bsim/audio/compile.sh rename to tests/bsim/bluetooth/audio/compile.sh index 2f0f15f2103c..62c06c3a45ad 100755 --- a/tests/bluetooth/bsim/audio/compile.sh +++ b/tests/bsim/bluetooth/audio/compile.sh @@ -18,8 +18,8 @@ BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source +source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source -app=tests/bluetooth/bsim/audio compile +app=tests/bsim/bluetooth/audio compile wait_for_background_jobs diff --git a/tests/bluetooth/bsim/audio/prj.conf b/tests/bsim/bluetooth/audio/prj.conf similarity index 100% rename from tests/bluetooth/bsim/audio/prj.conf rename to tests/bsim/bluetooth/audio/prj.conf diff --git a/tests/bluetooth/bsim/audio/src/bap_broadcast_assistant_test.c b/tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/bap_broadcast_assistant_test.c rename to tests/bsim/bluetooth/audio/src/bap_broadcast_assistant_test.c diff --git a/tests/bluetooth/bsim/audio/src/bap_scan_delegator_test.c b/tests/bsim/bluetooth/audio/src/bap_scan_delegator_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/bap_scan_delegator_test.c rename to tests/bsim/bluetooth/audio/src/bap_scan_delegator_test.c diff --git a/tests/bluetooth/bsim/audio/src/bap_unicast_client_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/bap_unicast_client_test.c rename to tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c diff --git a/tests/bluetooth/bsim/audio/src/bap_unicast_common.c b/tests/bsim/bluetooth/audio/src/bap_unicast_common.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/bap_unicast_common.c rename to tests/bsim/bluetooth/audio/src/bap_unicast_common.c diff --git a/tests/bluetooth/bsim/audio/src/bap_unicast_common.h b/tests/bsim/bluetooth/audio/src/bap_unicast_common.h similarity index 100% rename from tests/bluetooth/bsim/audio/src/bap_unicast_common.h rename to tests/bsim/bluetooth/audio/src/bap_unicast_common.h diff --git a/tests/bluetooth/bsim/audio/src/bap_unicast_server_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/bap_unicast_server_test.c rename to tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c diff --git a/tests/bluetooth/bsim/audio/src/bass_broadcaster_test.c b/tests/bsim/bluetooth/audio/src/bass_broadcaster_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/bass_broadcaster_test.c rename to tests/bsim/bluetooth/audio/src/bass_broadcaster_test.c diff --git a/tests/bluetooth/bsim/audio/src/broadcast_sink_test.c b/tests/bsim/bluetooth/audio/src/broadcast_sink_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/broadcast_sink_test.c rename to tests/bsim/bluetooth/audio/src/broadcast_sink_test.c diff --git a/tests/bluetooth/bsim/audio/src/broadcast_source_test.c b/tests/bsim/bluetooth/audio/src/broadcast_source_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/broadcast_source_test.c rename to tests/bsim/bluetooth/audio/src/broadcast_source_test.c diff --git a/tests/bluetooth/bsim/audio/src/cap_acceptor_test.c b/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/cap_acceptor_test.c rename to tests/bsim/bluetooth/audio/src/cap_acceptor_test.c diff --git a/tests/bluetooth/bsim/audio/src/cap_initiator_test.c b/tests/bsim/bluetooth/audio/src/cap_initiator_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/cap_initiator_test.c rename to tests/bsim/bluetooth/audio/src/cap_initiator_test.c diff --git a/tests/bluetooth/bsim/audio/src/common.c b/tests/bsim/bluetooth/audio/src/common.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/common.c rename to tests/bsim/bluetooth/audio/src/common.c diff --git a/tests/bluetooth/bsim/audio/src/common.h b/tests/bsim/bluetooth/audio/src/common.h similarity index 100% rename from tests/bluetooth/bsim/audio/src/common.h rename to tests/bsim/bluetooth/audio/src/common.h diff --git a/tests/bluetooth/bsim/audio/src/csip_set_coordinator_test.c b/tests/bsim/bluetooth/audio/src/csip_set_coordinator_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/csip_set_coordinator_test.c rename to tests/bsim/bluetooth/audio/src/csip_set_coordinator_test.c diff --git a/tests/bluetooth/bsim/audio/src/csip_set_member_test.c b/tests/bsim/bluetooth/audio/src/csip_set_member_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/csip_set_member_test.c rename to tests/bsim/bluetooth/audio/src/csip_set_member_test.c diff --git a/tests/bluetooth/bsim/audio/src/has_client_test.c b/tests/bsim/bluetooth/audio/src/has_client_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/has_client_test.c rename to tests/bsim/bluetooth/audio/src/has_client_test.c diff --git a/tests/bluetooth/bsim/audio/src/has_test.c b/tests/bsim/bluetooth/audio/src/has_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/has_test.c rename to tests/bsim/bluetooth/audio/src/has_test.c diff --git a/tests/bluetooth/bsim/audio/src/ias_client_test.c b/tests/bsim/bluetooth/audio/src/ias_client_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/ias_client_test.c rename to tests/bsim/bluetooth/audio/src/ias_client_test.c diff --git a/tests/bluetooth/bsim/audio/src/ias_test.c b/tests/bsim/bluetooth/audio/src/ias_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/ias_test.c rename to tests/bsim/bluetooth/audio/src/ias_test.c diff --git a/tests/bluetooth/bsim/audio/src/main.c b/tests/bsim/bluetooth/audio/src/main.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/main.c rename to tests/bsim/bluetooth/audio/src/main.c diff --git a/tests/bluetooth/bsim/audio/src/mcc_test.c b/tests/bsim/bluetooth/audio/src/mcc_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/mcc_test.c rename to tests/bsim/bluetooth/audio/src/mcc_test.c diff --git a/tests/bluetooth/bsim/audio/src/mcs_test.c b/tests/bsim/bluetooth/audio/src/mcs_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/mcs_test.c rename to tests/bsim/bluetooth/audio/src/mcs_test.c diff --git a/tests/bluetooth/bsim/audio/src/media_controller_test.c b/tests/bsim/bluetooth/audio/src/media_controller_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/media_controller_test.c rename to tests/bsim/bluetooth/audio/src/media_controller_test.c diff --git a/tests/bluetooth/bsim/audio/src/micp_mic_ctlr_test.c b/tests/bsim/bluetooth/audio/src/micp_mic_ctlr_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/micp_mic_ctlr_test.c rename to tests/bsim/bluetooth/audio/src/micp_mic_ctlr_test.c diff --git a/tests/bluetooth/bsim/audio/src/micp_mic_dev_test.c b/tests/bsim/bluetooth/audio/src/micp_mic_dev_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/micp_mic_dev_test.c rename to tests/bsim/bluetooth/audio/src/micp_mic_dev_test.c diff --git a/tests/bluetooth/bsim/audio/src/tbs_client_test.c b/tests/bsim/bluetooth/audio/src/tbs_client_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/tbs_client_test.c rename to tests/bsim/bluetooth/audio/src/tbs_client_test.c diff --git a/tests/bluetooth/bsim/audio/src/tbs_test.c b/tests/bsim/bluetooth/audio/src/tbs_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/tbs_test.c rename to tests/bsim/bluetooth/audio/src/tbs_test.c diff --git a/tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c b/tests/bsim/bluetooth/audio/src/vcp_vol_ctlr_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c rename to tests/bsim/bluetooth/audio/src/vcp_vol_ctlr_test.c diff --git a/tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c b/tests/bsim/bluetooth/audio/src/vcp_vol_rend_test.c similarity index 100% rename from tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c rename to tests/bsim/bluetooth/audio/src/vcp_vol_rend_test.c diff --git a/tests/bluetooth/bsim/audio/test_scripts/_cap.sh b/tests/bsim/bluetooth/audio/test_scripts/_cap.sh similarity index 100% rename from tests/bluetooth/bsim/audio/test_scripts/_cap.sh rename to tests/bsim/bluetooth/audio/test_scripts/_cap.sh diff --git a/tests/bluetooth/bsim/audio/test_scripts/bap_bass.sh b/tests/bsim/bluetooth/audio/test_scripts/bap_bass.sh similarity index 86% rename from tests/bluetooth/bsim/audio/test_scripts/bap_bass.sh rename to tests/bsim/bluetooth/audio/test_scripts/bap_bass.sh index a6130e08d35a..7a08b12313f6 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/bap_bass.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/bap_bass.sh @@ -26,15 +26,15 @@ cd ${BSIM_OUT_PATH}/bin printf "\n\n======== Running BASS and BASS client test =========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=bap_scan_delegator \ -rs=24 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 \ -testid=bap_broadcast_assistant -rs=46 - Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ + Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 -testid=bass_broadcaster -rs=69 # Simulation time should be larger than the WAIT_TIME in common.h diff --git a/tests/bluetooth/bsim/audio/test_scripts/bap_broadcast_audio.sh b/tests/bsim/bluetooth/audio/test_scripts/bap_broadcast_audio.sh similarity index 86% rename from tests/bluetooth/bsim/audio/test_scripts/bap_broadcast_audio.sh rename to tests/bsim/bluetooth/audio/test_scripts/bap_broadcast_audio.sh index 2a4aa16ea5c4..2e5b7d4c2d29 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/bap_broadcast_audio.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/bap_broadcast_audio.sh @@ -27,11 +27,11 @@ printf "\n\n======== Broadcaster test =========\n\n" SIMULATION_ID="broadcaster" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=broadcast_source -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=broadcast_sink -rs=27 # Simulation time should be larger than the WAIT_TIME in common.h @@ -46,11 +46,11 @@ printf "\n\n======== Broadcaster sink disconnect test =========\n\n" SIMULATION_ID="broadcaster_sink_disconnect" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=broadcast_source -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 \ -testid=broadcast_sink_disconnect -rs=27 diff --git a/tests/bluetooth/bsim/audio/test_scripts/bap_unicast_audio.sh b/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio.sh similarity index 89% rename from tests/bluetooth/bsim/audio/test_scripts/bap_unicast_audio.sh rename to tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio.sh index a1e34d1826da..9d9b82ea9bc9 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/bap_unicast_audio.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio.sh @@ -26,11 +26,11 @@ cd ${BSIM_OUT_PATH}/bin printf "\n\n======== Unicast Audio test =========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=unicast_client -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=unicast_server -rs=27 # Simulation time should be larger than the WAIT_TIME in common.h diff --git a/tests/bluetooth/bsim/audio/test_scripts/cap_broadcast.sh b/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast.sh similarity index 90% rename from tests/bluetooth/bsim/audio/test_scripts/cap_broadcast.sh rename to tests/bsim/bluetooth/audio/test_scripts/cap_broadcast.sh index bf130c1d7c9c..5f448cf2279c 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/cap_broadcast.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast.sh @@ -26,10 +26,10 @@ cd ${BSIM_OUT_PATH}/bin printf "\n\n======== Running CAP broadcast test =========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=cap_acceptor_broadcast -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=cap_initiator_broadcast -rs=46 # Simulation time should be larger than the WAIT_TIME in common.h diff --git a/tests/bluetooth/bsim/audio/test_scripts/cap_unicast.sh b/tests/bsim/bluetooth/audio/test_scripts/cap_unicast.sh similarity index 90% rename from tests/bluetooth/bsim/audio/test_scripts/cap_unicast.sh rename to tests/bsim/bluetooth/audio/test_scripts/cap_unicast.sh index d8b11220a778..f0ed6f2c3bb8 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/cap_unicast.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/cap_unicast.sh @@ -26,10 +26,10 @@ cd ${BSIM_OUT_PATH}/bin printf "\n\n======== Running CAP unicast test =========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=cap_acceptor_unicast -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=cap_initiator_unicast -rs=46 # Simulation time should be larger than the WAIT_TIME in common.h diff --git a/tests/bluetooth/bsim/audio/test_scripts/csip.sh b/tests/bsim/bluetooth/audio/test_scripts/csip.sh similarity index 81% rename from tests/bluetooth/bsim/audio/test_scripts/csip.sh rename to tests/bsim/bluetooth/audio/test_scripts/csip.sh index 494870109526..20b307a2ff8f 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/csip.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/csip.sh @@ -31,19 +31,19 @@ printf "\n\n======== Running normal test ========\n\n" SIMULATION_ID="csip" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=csip_set_coordinator \ -RealEncryption=1 -rs=1 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=csip_set_member \ -RealEncryption=1 -rs=2 -argstest rank 1 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 -testid=csip_set_member \ -RealEncryption=1 -rs=3 -argstest rank 2 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=3 -testid=csip_set_member \ -RealEncryption=1 -rs=4 -argstest rank 3 @@ -62,19 +62,19 @@ PROCESS_IDS=""; SIMULATION_ID="csip_forced_release" printf "\n\n======== Running test with forced release of lock ========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=csip_set_coordinator \ -RealEncryption=1 -rs=1 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=csip_set_member \ -RealEncryption=1 -rs=2 -argstest rank 1 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 -testid=csip_set_member \ -RealEncryption=1 -rs=3 -argstest rank 2 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=3 -testid=csip_set_member_release \ -RealEncryption=1 -rs=4 -argstest rank 3 @@ -91,19 +91,19 @@ done SIMULATION_ID="csip_sirk_encrypted" printf "\n\n======== Running test with SIRK encrypted ========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=csip_set_coordinator \ -RealEncryption=1 -rs=1 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=csip_set_member_enc \ -RealEncryption=1 -rs=2 -argstest rank 1 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 -testid=csip_set_member_enc \ -RealEncryption=1 -rs=3 -argstest rank 2 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=3 -testid=csip_set_member_enc \ -RealEncryption=1 -rs=4 -argstest rank 3 diff --git a/tests/bluetooth/bsim/audio/test_scripts/has.sh b/tests/bsim/bluetooth/audio/test_scripts/has.sh similarity index 88% rename from tests/bluetooth/bsim/audio/test_scripts/has.sh rename to tests/bsim/bluetooth/audio/test_scripts/has.sh index 65fadd1e175b..b35c7c131862 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/has.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/has.sh @@ -26,10 +26,10 @@ cd ${BSIM_OUT_PATH}/bin printf "\n\n======== Running HAS main (API) test =========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=has -rs=24 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=has_client -rs=46 Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ diff --git a/tests/bluetooth/bsim/audio/test_scripts/ias.sh b/tests/bsim/bluetooth/audio/test_scripts/ias.sh similarity index 89% rename from tests/bluetooth/bsim/audio/test_scripts/ias.sh rename to tests/bsim/bluetooth/audio/test_scripts/ias.sh index a3df49073b43..a310c1dd232a 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/ias.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/ias.sh @@ -26,10 +26,10 @@ cd ${BSIM_OUT_PATH}/bin printf "\n\n======== Running IAS main (API) test =========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=ias -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=ias_client -rs=6 # Simulation time should be larger than the WAIT_TIME in common.h diff --git a/tests/bluetooth/bsim/audio/test_scripts/mcs_mcc.sh b/tests/bsim/bluetooth/audio/test_scripts/mcs_mcc.sh similarity index 89% rename from tests/bluetooth/bsim/audio/test_scripts/mcs_mcc.sh rename to tests/bsim/bluetooth/audio/test_scripts/mcs_mcc.sh index 35146c77473c..679b3026af1b 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/mcs_mcc.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/mcs_mcc.sh @@ -26,10 +26,10 @@ cd ${BSIM_OUT_PATH}/bin printf "\n\n======== Running MCS and MCC test =========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=mcc -rs=46 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=mcs -rs=23 # Simulation time should be larger than the WAIT_TIME in common.h diff --git a/tests/bluetooth/bsim/audio/test_scripts/media_controller.sh b/tests/bsim/bluetooth/audio/test_scripts/media_controller.sh similarity index 89% rename from tests/bluetooth/bsim/audio/test_scripts/media_controller.sh rename to tests/bsim/bluetooth/audio/test_scripts/media_controller.sh index a88d6bfda8a5..16a913a7daca 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/media_controller.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/media_controller.sh @@ -26,7 +26,7 @@ cd ${BSIM_OUT_PATH}/bin printf "\n\n======== Running media controller local_player test =========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=media_controller_local_player -rs=23 # Simulation time should be larger than the WAIT_TIME in common.h @@ -39,10 +39,10 @@ done printf "\n\n======== Running media controller remote_player test =========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=media_controller_remote_player -rs=46 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=media_controller_server -rs=23 # Simulation time should be larger than the WAIT_TIME in common.h diff --git a/tests/bluetooth/bsim/audio/test_scripts/micp.sh b/tests/bsim/bluetooth/audio/test_scripts/micp.sh similarity index 89% rename from tests/bluetooth/bsim/audio/test_scripts/micp.sh rename to tests/bsim/bluetooth/audio/test_scripts/micp.sh index 562dbe4439cb..06c201319d3b 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/micp.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/micp.sh @@ -26,7 +26,7 @@ cd ${BSIM_OUT_PATH}/bin printf "\n\n==== Running MICP Microphone Device Only (API) test ====n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=micp_mic_dev_only -rs=23 # Simulation time should be larger than the WAIT_TIME in common.h @@ -39,10 +39,10 @@ done printf "\n\n==== Running MICP Microphone Device and MICP Microphone Controller test ====n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=micp_mic_dev -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=micp_mic_ctlr -rs=46 # Simulation time should be larger than the WAIT_TIME in common.h diff --git a/tests/bluetooth/bsim/audio/test_scripts/tbs.sh b/tests/bsim/bluetooth/audio/test_scripts/tbs.sh similarity index 89% rename from tests/bluetooth/bsim/audio/test_scripts/tbs.sh rename to tests/bsim/bluetooth/audio/test_scripts/tbs.sh index cb73fb0f039a..84b44a29decf 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/tbs.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/tbs.sh @@ -25,10 +25,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=tbs -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=tbs_client -rs=6 # Simulation time should be larger than the WAIT_TIME in common.h diff --git a/tests/bluetooth/bsim/audio/test_scripts/vcp.sh b/tests/bsim/bluetooth/audio/test_scripts/vcp.sh similarity index 89% rename from tests/bluetooth/bsim/audio/test_scripts/vcp.sh rename to tests/bsim/bluetooth/audio/test_scripts/vcp.sh index fb170d911db8..56e28e78aad4 100755 --- a/tests/bluetooth/bsim/audio/test_scripts/vcp.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/vcp.sh @@ -26,7 +26,7 @@ cd ${BSIM_OUT_PATH}/bin printf "\n\n======== Running VCP Volume Renderer standalone (API) test =========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=vcp_vol_rend_standalone -rs=23 # Simulation time should be larger than the WAIT_TIME in common.h @@ -39,10 +39,10 @@ done printf "\n\n======== Running VCP Volume Renderer and VCP Volume Controller test =========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=vcp_vol_rend -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=vcp_vol_ctlr -rs=46 # Simulation time should be larger than the WAIT_TIME in common.h diff --git a/tests/bluetooth/bsim/compile.sh b/tests/bsim/bluetooth/compile.sh similarity index 65% rename from tests/bluetooth/bsim/compile.sh rename to tests/bsim/bluetooth/compile.sh index 858138a5659c..eceee81e5efb 100755 --- a/tests/bluetooth/bsim/compile.sh +++ b/tests/bsim/bluetooth/compile.sh @@ -18,11 +18,11 @@ BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/sh_common.source +source ${ZEPHYR_BASE}/tests/bsim/bluetooth/sh_common.source -run_in_background ${ZEPHYR_BASE}/tests/bluetooth/bsim/audio/compile.sh -run_in_background ${ZEPHYR_BASE}/tests/bluetooth/bsim/host/compile.sh -run_in_background ${ZEPHYR_BASE}/tests/bluetooth/bsim/ll/compile.sh -run_in_background ${ZEPHYR_BASE}/tests/bluetooth/bsim/mesh/compile.sh +run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/audio/compile.sh +run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/host/compile.sh +run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/ll/compile.sh +run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/mesh/compile.sh wait_for_background_jobs diff --git a/tests/bluetooth/bsim/compile.source b/tests/bsim/bluetooth/compile.source similarity index 97% rename from tests/bluetooth/bsim/compile.source rename to tests/bsim/bluetooth/compile.source index 0107f713517c..cc54fb6bddc8 100644 --- a/tests/bluetooth/bsim/compile.source +++ b/tests/bsim/bluetooth/compile.source @@ -1,7 +1,7 @@ # Copyright 2018 Oticon A/S # SPDX-License-Identifier: Apache-2.0 -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/sh_common.source +source ${ZEPHYR_BASE}/tests/bsim/bluetooth/sh_common.source function print_error_info(){ echo -e "\033[0;31mFailure building ${app} ${conf_file} for ${BOARD}\033[0m\n\ diff --git a/tests/bluetooth/bsim/host/adv/chain/CMakeLists.txt b/tests/bsim/bluetooth/host/adv/chain/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/adv/chain/CMakeLists.txt rename to tests/bsim/bluetooth/host/adv/chain/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/adv/chain/prj.conf b/tests/bsim/bluetooth/host/adv/chain/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/adv/chain/prj.conf rename to tests/bsim/bluetooth/host/adv/chain/prj.conf diff --git a/tests/bluetooth/bsim/host/adv/chain/src/main.c b/tests/bsim/bluetooth/host/adv/chain/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/adv/chain/src/main.c rename to tests/bsim/bluetooth/host/adv/chain/src/main.c diff --git a/tests/bluetooth/bsim/host/adv/chain/tests_scripts/adv_chain.sh b/tests/bsim/bluetooth/host/adv/chain/tests_scripts/adv_chain.sh similarity index 88% rename from tests/bluetooth/bsim/host/adv/chain/tests_scripts/adv_chain.sh rename to tests/bsim/bluetooth/host/adv/chain/tests_scripts/adv_chain.sh index 0ce63588fa59..28b608efd349 100755 --- a/tests/bluetooth/bsim/host/adv/chain/tests_scripts/adv_chain.sh +++ b/tests/bsim/bluetooth/host/adv/chain/tests_scripts/adv_chain.sh @@ -24,10 +24,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_chain_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_chain_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=adv -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_chain_prj_conf\ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_chain_prj_conf\ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=scan Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/adv/periodic/CMakeLists.txt b/tests/bsim/bluetooth/host/adv/periodic/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/adv/periodic/CMakeLists.txt rename to tests/bsim/bluetooth/host/adv/periodic/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/adv/periodic/prj.conf b/tests/bsim/bluetooth/host/adv/periodic/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/adv/periodic/prj.conf rename to tests/bsim/bluetooth/host/adv/periodic/prj.conf diff --git a/tests/bluetooth/bsim/host/adv/periodic/prj_long_data.conf b/tests/bsim/bluetooth/host/adv/periodic/prj_long_data.conf similarity index 100% rename from tests/bluetooth/bsim/host/adv/periodic/prj_long_data.conf rename to tests/bsim/bluetooth/host/adv/periodic/prj_long_data.conf diff --git a/tests/bluetooth/bsim/host/adv/periodic/src/common.c b/tests/bsim/bluetooth/host/adv/periodic/src/common.c similarity index 100% rename from tests/bluetooth/bsim/host/adv/periodic/src/common.c rename to tests/bsim/bluetooth/host/adv/periodic/src/common.c diff --git a/tests/bluetooth/bsim/host/adv/periodic/src/common.h b/tests/bsim/bluetooth/host/adv/periodic/src/common.h similarity index 100% rename from tests/bluetooth/bsim/host/adv/periodic/src/common.h rename to tests/bsim/bluetooth/host/adv/periodic/src/common.h diff --git a/tests/bluetooth/bsim/host/adv/periodic/src/main.c b/tests/bsim/bluetooth/host/adv/periodic/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/adv/periodic/src/main.c rename to tests/bsim/bluetooth/host/adv/periodic/src/main.c diff --git a/tests/bluetooth/bsim/host/adv/periodic/src/per_adv_advertiser.c b/tests/bsim/bluetooth/host/adv/periodic/src/per_adv_advertiser.c similarity index 100% rename from tests/bluetooth/bsim/host/adv/periodic/src/per_adv_advertiser.c rename to tests/bsim/bluetooth/host/adv/periodic/src/per_adv_advertiser.c diff --git a/tests/bluetooth/bsim/host/adv/periodic/src/per_adv_syncer.c b/tests/bsim/bluetooth/host/adv/periodic/src/per_adv_syncer.c similarity index 100% rename from tests/bluetooth/bsim/host/adv/periodic/src/per_adv_syncer.c rename to tests/bsim/bluetooth/host/adv/periodic/src/per_adv_syncer.c diff --git a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv.sh b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv.sh similarity index 89% rename from tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv.sh rename to tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv.sh index 19dd00fbcff4..3d1e189a7764 100755 --- a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv.sh +++ b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv.sh @@ -24,11 +24,11 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_periodic_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \ -testid=per_adv_advertiser -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_periodic_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \ -testid=per_adv_syncer -rs=6 diff --git a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_conn.sh b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn.sh similarity index 90% rename from tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_conn.sh rename to tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn.sh index d7c18d018782..70dbdb101b10 100755 --- a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_conn.sh +++ b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn.sh @@ -24,11 +24,11 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_periodic_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \ -testid=per_adv_conn_advertiser -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_periodic_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \ -testid=per_adv_conn_syncer -rs=6 diff --git a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh similarity index 90% rename from tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh rename to tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh index c85c52653f20..eede26ce116e 100755 --- a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh +++ b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh @@ -24,11 +24,11 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_periodic_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \ -testid=per_adv_conn_privacy_advertiser -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_periodic_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \ -testid=per_adv_conn_privacy_syncer -rs=6 diff --git a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_long_data.sh b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_long_data.sh similarity index 90% rename from tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_long_data.sh rename to tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_long_data.sh index 870c73d4513f..6b4e65438bc9 100755 --- a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_long_data.sh +++ b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_long_data.sh @@ -24,11 +24,11 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_long_data_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_periodic_prj_long_data_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \ -testid=per_adv_long_data_advertiser -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_long_data_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_periodic_prj_long_data_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \ -testid=per_adv_long_data_syncer -rs=6 diff --git a/tests/bluetooth/bsim/host/adv/resume/CMakeLists.txt b/tests/bsim/bluetooth/host/adv/resume/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/adv/resume/CMakeLists.txt rename to tests/bsim/bluetooth/host/adv/resume/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/adv/resume/prj.conf b/tests/bsim/bluetooth/host/adv/resume/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/adv/resume/prj.conf rename to tests/bsim/bluetooth/host/adv/resume/prj.conf diff --git a/tests/bluetooth/bsim/host/adv/resume/prj_2.conf b/tests/bsim/bluetooth/host/adv/resume/prj_2.conf similarity index 100% rename from tests/bluetooth/bsim/host/adv/resume/prj_2.conf rename to tests/bsim/bluetooth/host/adv/resume/prj_2.conf diff --git a/tests/bluetooth/bsim/host/adv/resume/src/bs_bt_utils.c b/tests/bsim/bluetooth/host/adv/resume/src/bs_bt_utils.c similarity index 100% rename from tests/bluetooth/bsim/host/adv/resume/src/bs_bt_utils.c rename to tests/bsim/bluetooth/host/adv/resume/src/bs_bt_utils.c diff --git a/tests/bluetooth/bsim/host/adv/resume/src/bs_bt_utils.h b/tests/bsim/bluetooth/host/adv/resume/src/bs_bt_utils.h similarity index 100% rename from tests/bluetooth/bsim/host/adv/resume/src/bs_bt_utils.h rename to tests/bsim/bluetooth/host/adv/resume/src/bs_bt_utils.h diff --git a/tests/bluetooth/bsim/host/adv/resume/src/dut.c b/tests/bsim/bluetooth/host/adv/resume/src/dut.c similarity index 100% rename from tests/bluetooth/bsim/host/adv/resume/src/dut.c rename to tests/bsim/bluetooth/host/adv/resume/src/dut.c diff --git a/tests/bluetooth/bsim/host/adv/resume/src/main.c b/tests/bsim/bluetooth/host/adv/resume/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/adv/resume/src/main.c rename to tests/bsim/bluetooth/host/adv/resume/src/main.c diff --git a/tests/bluetooth/bsim/host/adv/resume/src/tester.c b/tests/bsim/bluetooth/host/adv/resume/src/tester.c similarity index 100% rename from tests/bluetooth/bsim/host/adv/resume/src/tester.c rename to tests/bsim/bluetooth/host/adv/resume/src/tester.c diff --git a/tests/bluetooth/bsim/host/adv/resume/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/adv/resume/test_scripts/_compile.sh similarity index 100% rename from tests/bluetooth/bsim/host/adv/resume/test_scripts/_compile.sh rename to tests/bsim/bluetooth/host/adv/resume/test_scripts/_compile.sh diff --git a/tests/bluetooth/bsim/host/adv/resume/test_scripts/_env.sh b/tests/bsim/bluetooth/host/adv/resume/test_scripts/_env.sh similarity index 75% rename from tests/bluetooth/bsim/host/adv/resume/test_scripts/_env.sh rename to tests/bsim/bluetooth/host/adv/resume/test_scripts/_env.sh index 2b315a1e9f52..98dff68bc08c 100755 --- a/tests/bluetooth/bsim/host/adv/resume/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/adv/resume/test_scripts/_env.sh @@ -9,5 +9,5 @@ bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" test_name="$(basename "$(realpath "$bash_source_dir/..")")" bsim_bin="${BSIM_OUT_PATH}/bin" BOARD="${BOARD:-nrf52_bsim}" -test_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_adv_resume_prj_conf" -test_2_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_adv_resume_prj_2_conf" +test_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_adv_resume_prj_conf" +test_2_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_adv_resume_prj_2_conf" diff --git a/tests/bluetooth/bsim/host/adv/resume/test_scripts/run_adv_resume.sh b/tests/bsim/bluetooth/host/adv/resume/test_scripts/run_adv_resume.sh similarity index 100% rename from tests/bluetooth/bsim/host/adv/resume/test_scripts/run_adv_resume.sh rename to tests/bsim/bluetooth/host/adv/resume/test_scripts/run_adv_resume.sh diff --git a/tests/bluetooth/bsim/host/adv/resume/test_scripts/run_adv_resume_2.sh b/tests/bsim/bluetooth/host/adv/resume/test_scripts/run_adv_resume_2.sh similarity index 100% rename from tests/bluetooth/bsim/host/adv/resume/test_scripts/run_adv_resume_2.sh rename to tests/bsim/bluetooth/host/adv/resume/test_scripts/run_adv_resume_2.sh diff --git a/tests/bluetooth/bsim/host/att/eatt/CMakeLists.txt b/tests/bsim/bluetooth/host/att/eatt/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt/CMakeLists.txt rename to tests/bsim/bluetooth/host/att/eatt/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/att/eatt/prj_autoconnect.conf b/tests/bsim/bluetooth/host/att/eatt/prj_autoconnect.conf similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt/prj_autoconnect.conf rename to tests/bsim/bluetooth/host/att/eatt/prj_autoconnect.conf diff --git a/tests/bluetooth/bsim/host/att/eatt/prj_collision.conf b/tests/bsim/bluetooth/host/att/eatt/prj_collision.conf similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt/prj_collision.conf rename to tests/bsim/bluetooth/host/att/eatt/prj_collision.conf diff --git a/tests/bluetooth/bsim/host/att/eatt/prj_multiple_conn.conf b/tests/bsim/bluetooth/host/att/eatt/prj_multiple_conn.conf similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt/prj_multiple_conn.conf rename to tests/bsim/bluetooth/host/att/eatt/prj_multiple_conn.conf diff --git a/tests/bluetooth/bsim/host/att/eatt/src/common.c b/tests/bsim/bluetooth/host/att/eatt/src/common.c similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt/src/common.c rename to tests/bsim/bluetooth/host/att/eatt/src/common.c diff --git a/tests/bluetooth/bsim/host/att/eatt/src/common.h b/tests/bsim/bluetooth/host/att/eatt/src/common.h similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt/src/common.h rename to tests/bsim/bluetooth/host/att/eatt/src/common.h diff --git a/tests/bluetooth/bsim/host/att/eatt/src/main.c b/tests/bsim/bluetooth/host/att/eatt/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt/src/main.c rename to tests/bsim/bluetooth/host/att/eatt/src/main.c diff --git a/tests/bluetooth/bsim/host/att/eatt/src/main_autoconnect.c b/tests/bsim/bluetooth/host/att/eatt/src/main_autoconnect.c similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt/src/main_autoconnect.c rename to tests/bsim/bluetooth/host/att/eatt/src/main_autoconnect.c diff --git a/tests/bluetooth/bsim/host/att/eatt/src/main_collision.c b/tests/bsim/bluetooth/host/att/eatt/src/main_collision.c similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt/src/main_collision.c rename to tests/bsim/bluetooth/host/att/eatt/src/main_collision.c diff --git a/tests/bluetooth/bsim/host/att/eatt/src/main_reconfigure.c b/tests/bsim/bluetooth/host/att/eatt/src/main_reconfigure.c similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt/src/main_reconfigure.c rename to tests/bsim/bluetooth/host/att/eatt/src/main_reconfigure.c diff --git a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/autoconnect.sh b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/autoconnect.sh similarity index 88% rename from tests/bluetooth/bsim/host/att/eatt/tests_scripts/autoconnect.sh rename to tests/bsim/bluetooth/host/att/eatt/tests_scripts/autoconnect.sh index a1a0e4eccd53..3aa2c68bee68 100755 --- a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/autoconnect.sh +++ b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/autoconnect.sh @@ -22,10 +22,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_autoconnect_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_prj_autoconnect_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central_autoconnect -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_autoconnect_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_prj_autoconnect_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral_autoconnect Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/collision.sh b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/collision.sh similarity index 87% rename from tests/bluetooth/bsim/host/att/eatt/tests_scripts/collision.sh rename to tests/bsim/bluetooth/host/att/eatt/tests_scripts/collision.sh index b040d7b69581..eae7e1e99665 100755 --- a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/collision.sh +++ b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/collision.sh @@ -22,10 +22,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_collision_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_prj_collision_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_collision_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_prj_collision_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/multiple_conn.sh b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/multiple_conn.sh similarity index 88% rename from tests/bluetooth/bsim/host/att/eatt/tests_scripts/multiple_conn.sh rename to tests/bsim/bluetooth/host/att/eatt/tests_scripts/multiple_conn.sh index 0fe8fad56a3c..d5f3482885df 100755 --- a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/multiple_conn.sh +++ b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/multiple_conn.sh @@ -22,10 +22,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_multiple_conn_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_prj_multiple_conn_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_multiple_conn_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_prj_multiple_conn_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/reconfigure.sh b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/reconfigure.sh similarity index 88% rename from tests/bluetooth/bsim/host/att/eatt/tests_scripts/reconfigure.sh rename to tests/bsim/bluetooth/host/att/eatt/tests_scripts/reconfigure.sh index c927000c04e5..599329ce2b58 100755 --- a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/reconfigure.sh +++ b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/reconfigure.sh @@ -22,10 +22,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_autoconnect_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_prj_autoconnect_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central_reconfigure -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_autoconnect_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_prj_autoconnect_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral_reconfigure Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/CMakeLists.txt b/tests/bsim/bluetooth/host/att/eatt_notif/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt_notif/CMakeLists.txt rename to tests/bsim/bluetooth/host/att/eatt_notif/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/prj.conf b/tests/bsim/bluetooth/host/att/eatt_notif/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt_notif/prj.conf rename to tests/bsim/bluetooth/host/att/eatt_notif/prj.conf diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/src/client_test.c b/tests/bsim/bluetooth/host/att/eatt_notif/src/client_test.c similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt_notif/src/client_test.c rename to tests/bsim/bluetooth/host/att/eatt_notif/src/client_test.c diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/src/common.c b/tests/bsim/bluetooth/host/att/eatt_notif/src/common.c similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt_notif/src/common.c rename to tests/bsim/bluetooth/host/att/eatt_notif/src/common.c diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/src/common.h b/tests/bsim/bluetooth/host/att/eatt_notif/src/common.h similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt_notif/src/common.h rename to tests/bsim/bluetooth/host/att/eatt_notif/src/common.h diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/src/main.c b/tests/bsim/bluetooth/host/att/eatt_notif/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt_notif/src/main.c rename to tests/bsim/bluetooth/host/att/eatt_notif/src/main.c diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/src/server_test.c b/tests/bsim/bluetooth/host/att/eatt_notif/src/server_test.c similarity index 100% rename from tests/bluetooth/bsim/host/att/eatt_notif/src/server_test.c rename to tests/bsim/bluetooth/host/att/eatt_notif/src/server_test.c diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/test_scripts/eatt_notif.sh b/tests/bsim/bluetooth/host/att/eatt_notif/test_scripts/eatt_notif.sh similarity index 88% rename from tests/bluetooth/bsim/host/att/eatt_notif/test_scripts/eatt_notif.sh rename to tests/bsim/bluetooth/host/att/eatt_notif/test_scripts/eatt_notif.sh index 50201e43ae0e..0d3bcb2967d3 100755 --- a/tests/bluetooth/bsim/host/att/eatt_notif/test_scripts/eatt_notif.sh +++ b/tests/bsim/bluetooth/host/att/eatt_notif/test_scripts/eatt_notif.sh @@ -24,10 +24,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_notif_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_notif_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=client -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_notif_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_notif_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=server Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/att/mtu_update/CMakeLists.txt b/tests/bsim/bluetooth/host/att/mtu_update/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/att/mtu_update/CMakeLists.txt rename to tests/bsim/bluetooth/host/att/mtu_update/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/att/mtu_update/prj.conf b/tests/bsim/bluetooth/host/att/mtu_update/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/att/mtu_update/prj.conf rename to tests/bsim/bluetooth/host/att/mtu_update/prj.conf diff --git a/tests/bluetooth/bsim/host/att/mtu_update/src/main.c b/tests/bsim/bluetooth/host/att/mtu_update/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/att/mtu_update/src/main.c rename to tests/bsim/bluetooth/host/att/mtu_update/src/main.c diff --git a/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh similarity index 84% rename from tests/bluetooth/bsim/host/att/mtu_update/test_scripts/_compile.sh rename to tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh index 10d6a94dc96b..282f454f30b5 100755 --- a/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh @@ -18,5 +18,5 @@ BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" INCR_BUILD=1 mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source -app="tests/bluetooth/bsim/$test_name" compile +source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source +app="tests/bsim/bluetooth/$test_name" compile diff --git a/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/_env.sh b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_env.sh similarity index 92% rename from tests/bluetooth/bsim/host/att/mtu_update/test_scripts/_env.sh rename to tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_env.sh index e8480ac6df6d..30ba589fe88a 100755 --- a/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_env.sh @@ -11,7 +11,7 @@ bsim_bin="${BSIM_OUT_PATH}/bin" verbosity_level=2 BOARD="${BOARD:-nrf52_bsim}" simulation_id="$test_name" -central_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_att_mtu_update_prj_conf" +central_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_att_mtu_update_prj_conf" peripheral_exe="${central_exe}" function print_var { diff --git a/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/run_test.sh b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/run_test.sh similarity index 100% rename from tests/bluetooth/bsim/host/att/mtu_update/test_scripts/run_test.sh rename to tests/bsim/bluetooth/host/att/mtu_update/test_scripts/run_test.sh diff --git a/tests/bsim/bluetooth/host/compile.sh b/tests/bsim/bluetooth/host/compile.sh new file mode 100755 index 000000000000..6358ec2ce05e --- /dev/null +++ b/tests/bsim/bluetooth/host/compile.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +# Compile all the applications needed by the bsim tests + +#set -x #uncomment this line for debugging +set -ue + +: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" +: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ + directory}" + +WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" +BOARD="${BOARD:-nrf52_bsim}" +BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" + +mkdir -p ${WORK_DIR} + +source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source + +app=tests/bsim/bluetooth/host/adv/resume compile +app=tests/bsim/bluetooth/host/adv/resume conf_file=prj_2.conf compile +app=tests/bsim/bluetooth/host/adv/chain compile +app=tests/bsim/bluetooth/host/adv/periodic compile +app=tests/bsim/bluetooth/host/adv/periodic conf_file=prj_long_data.conf compile + +app=tests/bsim/bluetooth/host/att/eatt conf_file=prj_collision.conf compile +app=tests/bsim/bluetooth/host/att/eatt conf_file=prj_multiple_conn.conf compile +app=tests/bsim/bluetooth/host/att/eatt conf_file=prj_autoconnect.conf compile +app=tests/bsim/bluetooth/host/att/eatt_notif conf_file=prj.conf compile +app=tests/bsim/bluetooth/host/att/mtu_update compile + +app=tests/bsim/bluetooth/host/gatt/caching compile +app=tests/bsim/bluetooth/host/gatt/general compile +app=tests/bsim/bluetooth/host/gatt/notify compile +app=tests/bsim/bluetooth/host/gatt/notify_multiple compile +app=tests/bsim/bluetooth/host/gatt/settings compile +app=tests/bsim/bluetooth/host/gatt/settings conf_file=prj_2.conf compile +app=tests/bsim/bluetooth/host/gatt/write compile + +app=tests/bsim/bluetooth/host/l2cap/general compile +app=tests/bsim/bluetooth/host/l2cap/userdata compile +app=tests/bsim/bluetooth/host/l2cap/stress compile + +app=tests/bsim/bluetooth/host/misc/disable compile +app=tests/bsim/bluetooth/host/misc/multiple_id compile + +app=tests/bsim/bluetooth/host/privacy/central compile +app=tests/bsim/bluetooth/host/privacy/peripheral compile +app=tests/bsim/bluetooth/host/privacy/device compile + +app=tests/bsim/bluetooth/host/security/bond_overwrite_allowed compile +app=tests/bsim/bluetooth/host/security/bond_overwrite_denied compile + +wait_for_background_jobs diff --git a/tests/bluetooth/bsim/host/gatt/caching/CMakeLists.txt b/tests/bsim/bluetooth/host/gatt/caching/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/gatt/caching/CMakeLists.txt rename to tests/bsim/bluetooth/host/gatt/caching/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/gatt/caching/prj.conf b/tests/bsim/bluetooth/host/gatt/caching/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/gatt/caching/prj.conf rename to tests/bsim/bluetooth/host/gatt/caching/prj.conf diff --git a/tests/bluetooth/bsim/host/gatt/caching/src/common.c b/tests/bsim/bluetooth/host/gatt/caching/src/common.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/caching/src/common.c rename to tests/bsim/bluetooth/host/gatt/caching/src/common.c diff --git a/tests/bluetooth/bsim/host/gatt/caching/src/common.h b/tests/bsim/bluetooth/host/gatt/caching/src/common.h similarity index 100% rename from tests/bluetooth/bsim/host/gatt/caching/src/common.h rename to tests/bsim/bluetooth/host/gatt/caching/src/common.h diff --git a/tests/bluetooth/bsim/host/gatt/caching/src/gatt_client_test.c b/tests/bsim/bluetooth/host/gatt/caching/src/gatt_client_test.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/caching/src/gatt_client_test.c rename to tests/bsim/bluetooth/host/gatt/caching/src/gatt_client_test.c diff --git a/tests/bluetooth/bsim/host/gatt/caching/src/gatt_server_test.c b/tests/bsim/bluetooth/host/gatt/caching/src/gatt_server_test.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/caching/src/gatt_server_test.c rename to tests/bsim/bluetooth/host/gatt/caching/src/gatt_server_test.c diff --git a/tests/bluetooth/bsim/host/gatt/caching/src/main.c b/tests/bsim/bluetooth/host/gatt/caching/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/caching/src/main.c rename to tests/bsim/bluetooth/host/gatt/caching/src/main.c diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/_run_test.sh b/tests/bsim/bluetooth/host/gatt/caching/test_scripts/_run_test.sh similarity index 87% rename from tests/bluetooth/bsim/host/gatt/caching/test_scripts/_run_test.sh rename to tests/bsim/bluetooth/host/gatt/caching/test_scripts/_run_test.sh index 3be231bc03d4..478febd7484f 100755 --- a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/_run_test.sh +++ b/tests/bsim/bluetooth/host/gatt/caching/test_scripts/_run_test.sh @@ -23,10 +23,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_caching_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_caching_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=${client_id} -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_caching_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_caching_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=${server_id} Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_eatt.sh b/tests/bsim/bluetooth/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_eatt.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_eatt.sh rename to tests/bsim/bluetooth/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_eatt.sh diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_no_eatt.sh b/tests/bsim/bluetooth/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_no_eatt.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_no_eatt.sh rename to tests/bsim/bluetooth/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_no_eatt.sh diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_eatt.sh b/tests/bsim/bluetooth/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_eatt.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_eatt.sh rename to tests/bsim/bluetooth/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_eatt.sh diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_no_eatt.sh b/tests/bsim/bluetooth/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_no_eatt.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_no_eatt.sh rename to tests/bsim/bluetooth/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_no_eatt.sh diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_retry_reads_eatt.sh b/tests/bsim/bluetooth/host/gatt/caching/test_scripts/gatt_caching_retry_reads_eatt.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_retry_reads_eatt.sh rename to tests/bsim/bluetooth/host/gatt/caching/test_scripts/gatt_caching_retry_reads_eatt.sh diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_retry_reads_no_eatt.sh b/tests/bsim/bluetooth/host/gatt/caching/test_scripts/gatt_caching_retry_reads_no_eatt.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_retry_reads_no_eatt.sh rename to tests/bsim/bluetooth/host/gatt/caching/test_scripts/gatt_caching_retry_reads_no_eatt.sh diff --git a/tests/bluetooth/bsim/host/gatt/general/CMakeLists.txt b/tests/bsim/bluetooth/host/gatt/general/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/gatt/general/CMakeLists.txt rename to tests/bsim/bluetooth/host/gatt/general/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/gatt/general/prj.conf b/tests/bsim/bluetooth/host/gatt/general/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/gatt/general/prj.conf rename to tests/bsim/bluetooth/host/gatt/general/prj.conf diff --git a/tests/bluetooth/bsim/host/gatt/general/src/common.c b/tests/bsim/bluetooth/host/gatt/general/src/common.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/general/src/common.c rename to tests/bsim/bluetooth/host/gatt/general/src/common.c diff --git a/tests/bluetooth/bsim/host/gatt/general/src/common.h b/tests/bsim/bluetooth/host/gatt/general/src/common.h similarity index 100% rename from tests/bluetooth/bsim/host/gatt/general/src/common.h rename to tests/bsim/bluetooth/host/gatt/general/src/common.h diff --git a/tests/bluetooth/bsim/host/gatt/general/src/gatt_client_test.c b/tests/bsim/bluetooth/host/gatt/general/src/gatt_client_test.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/general/src/gatt_client_test.c rename to tests/bsim/bluetooth/host/gatt/general/src/gatt_client_test.c diff --git a/tests/bluetooth/bsim/host/gatt/general/src/gatt_server_test.c b/tests/bsim/bluetooth/host/gatt/general/src/gatt_server_test.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/general/src/gatt_server_test.c rename to tests/bsim/bluetooth/host/gatt/general/src/gatt_server_test.c diff --git a/tests/bluetooth/bsim/host/gatt/general/src/main.c b/tests/bsim/bluetooth/host/gatt/general/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/general/src/main.c rename to tests/bsim/bluetooth/host/gatt/general/src/main.c diff --git a/tests/bluetooth/bsim/host/gatt/general/test_scripts/gatt.sh b/tests/bsim/bluetooth/host/gatt/general/test_scripts/gatt.sh similarity index 89% rename from tests/bluetooth/bsim/host/gatt/general/test_scripts/gatt.sh rename to tests/bsim/bluetooth/host/gatt/general/test_scripts/gatt.sh index a5f1c1a10fb6..53be981b1178 100755 --- a/tests/bluetooth/bsim/host/gatt/general/test_scripts/gatt.sh +++ b/tests/bsim/bluetooth/host/gatt/general/test_scripts/gatt.sh @@ -25,10 +25,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_general_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_general_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=gatt_client -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_general_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_general_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=gatt_server Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/gatt/notify/CMakeLists.txt b/tests/bsim/bluetooth/host/gatt/notify/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/CMakeLists.txt rename to tests/bsim/bluetooth/host/gatt/notify/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/gatt/notify/prj.conf b/tests/bsim/bluetooth/host/gatt/notify/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/prj.conf rename to tests/bsim/bluetooth/host/gatt/notify/prj.conf diff --git a/tests/bluetooth/bsim/host/gatt/notify/src/common.c b/tests/bsim/bluetooth/host/gatt/notify/src/common.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/src/common.c rename to tests/bsim/bluetooth/host/gatt/notify/src/common.c diff --git a/tests/bluetooth/bsim/host/gatt/notify/src/common.h b/tests/bsim/bluetooth/host/gatt/notify/src/common.h similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/src/common.h rename to tests/bsim/bluetooth/host/gatt/notify/src/common.h diff --git a/tests/bluetooth/bsim/host/gatt/notify/src/gatt_client_test.c b/tests/bsim/bluetooth/host/gatt/notify/src/gatt_client_test.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/src/gatt_client_test.c rename to tests/bsim/bluetooth/host/gatt/notify/src/gatt_client_test.c diff --git a/tests/bluetooth/bsim/host/gatt/notify/src/gatt_server_test.c b/tests/bsim/bluetooth/host/gatt/notify/src/gatt_server_test.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/src/gatt_server_test.c rename to tests/bsim/bluetooth/host/gatt/notify/src/gatt_server_test.c diff --git a/tests/bluetooth/bsim/host/gatt/notify/src/main.c b/tests/bsim/bluetooth/host/gatt/notify/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/src/main.c rename to tests/bsim/bluetooth/host/gatt/notify/src/main.c diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/_run_test.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/_run_test.sh similarity index 87% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/_run_test.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/_run_test.sh index 6229a794db60..bd79acb3fdd7 100755 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/_run_test.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/_run_test.sh @@ -23,10 +23,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_notify_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_notify_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=${client_id} -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_notify_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_notify_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=${server_id} Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_enhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_enhanced.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_enhanced.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_enhanced.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_mixed.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_mixed.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_mixed.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_mixed.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_none.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_none.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_none.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_none.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_unenhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_unenhanced.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_unenhanced.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_unenhanced.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_enhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_enhanced.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_enhanced.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_enhanced.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_mixed.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_mixed.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_mixed.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_mixed.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_none.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_none.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_none.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_none.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_unenhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_unenhanced.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_unenhanced.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_unenhanced.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_enhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_enhanced.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_enhanced.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_enhanced.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_mixed.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_mixed.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_mixed.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_mixed.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_none.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_none.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_none.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_none.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_unenhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_unenhanced.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_unenhanced.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_unenhanced.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_enhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_enhanced.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_enhanced.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_enhanced.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_mixed.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_mixed.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_mixed.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_mixed.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_none.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_none.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_none.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_none.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_unenhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_unenhanced.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_unenhanced.sh rename to tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_unenhanced.sh diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/CMakeLists.txt b/tests/bsim/bluetooth/host/gatt/notify_multiple/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify_multiple/CMakeLists.txt rename to tests/bsim/bluetooth/host/gatt/notify_multiple/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/prj.conf b/tests/bsim/bluetooth/host/gatt/notify_multiple/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify_multiple/prj.conf rename to tests/bsim/bluetooth/host/gatt/notify_multiple/prj.conf diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/common.c b/tests/bsim/bluetooth/host/gatt/notify_multiple/src/common.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify_multiple/src/common.c rename to tests/bsim/bluetooth/host/gatt/notify_multiple/src/common.c diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/common.h b/tests/bsim/bluetooth/host/gatt/notify_multiple/src/common.h similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify_multiple/src/common.h rename to tests/bsim/bluetooth/host/gatt/notify_multiple/src/common.h diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/gatt_client_test.c b/tests/bsim/bluetooth/host/gatt/notify_multiple/src/gatt_client_test.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify_multiple/src/gatt_client_test.c rename to tests/bsim/bluetooth/host/gatt/notify_multiple/src/gatt_client_test.c diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/gatt_server_test.c b/tests/bsim/bluetooth/host/gatt/notify_multiple/src/gatt_server_test.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify_multiple/src/gatt_server_test.c rename to tests/bsim/bluetooth/host/gatt/notify_multiple/src/gatt_server_test.c diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/main.c b/tests/bsim/bluetooth/host/gatt/notify_multiple/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/notify_multiple/src/main.c rename to tests/bsim/bluetooth/host/gatt/notify_multiple/src/main.c diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/test_scripts/_notify-debug.sh b/tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/_notify-debug.sh similarity index 88% rename from tests/bluetooth/bsim/host/gatt/notify_multiple/test_scripts/_notify-debug.sh rename to tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/_notify-debug.sh index f8adec17950b..29ac8e41794e 100755 --- a/tests/bluetooth/bsim/host/gatt/notify_multiple/test_scripts/_notify-debug.sh +++ b/tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/_notify-debug.sh @@ -28,11 +28,11 @@ if [[ $2 == "debug" ]]; then fi if [[ $1 == "client" ]]; then -$GDB_P ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_notify_multiple_prj_conf \ +$GDB_P ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_notify_multiple_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=gatt_client elif [[ $1 == "server" ]]; then -$GDB_P ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_notify_multiple_prj_conf \ +$GDB_P ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_notify_multiple_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=gatt_server else diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/test_scripts/notify.sh b/tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/notify.sh similarity index 88% rename from tests/bluetooth/bsim/host/gatt/notify_multiple/test_scripts/notify.sh rename to tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/notify.sh index b70d41ebdf00..ee243473bea3 100755 --- a/tests/bluetooth/bsim/host/gatt/notify_multiple/test_scripts/notify.sh +++ b/tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/notify.sh @@ -22,10 +22,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_notify_multiple_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_notify_multiple_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=gatt_client -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_notify_multiple_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_notify_multiple_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=gatt_server Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/gatt/settings/CMakeLists.txt b/tests/bsim/bluetooth/host/gatt/settings/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/CMakeLists.txt rename to tests/bsim/bluetooth/host/gatt/settings/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/gatt/settings/prj.conf b/tests/bsim/bluetooth/host/gatt/settings/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/prj.conf rename to tests/bsim/bluetooth/host/gatt/settings/prj.conf diff --git a/tests/bluetooth/bsim/host/gatt/settings/prj_2.conf b/tests/bsim/bluetooth/host/gatt/settings/prj_2.conf similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/prj_2.conf rename to tests/bsim/bluetooth/host/gatt/settings/prj_2.conf diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/client.c b/tests/bsim/bluetooth/host/gatt/settings/src/client.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/src/client.c rename to tests/bsim/bluetooth/host/gatt/settings/src/client.c diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/gatt_utils.c b/tests/bsim/bluetooth/host/gatt/settings/src/gatt_utils.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/src/gatt_utils.c rename to tests/bsim/bluetooth/host/gatt/settings/src/gatt_utils.c diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/gatt_utils.h b/tests/bsim/bluetooth/host/gatt/settings/src/gatt_utils.h similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/src/gatt_utils.h rename to tests/bsim/bluetooth/host/gatt/settings/src/gatt_utils.h diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/main.c b/tests/bsim/bluetooth/host/gatt/settings/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/src/main.c rename to tests/bsim/bluetooth/host/gatt/settings/src/main.c diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/main.h b/tests/bsim/bluetooth/host/gatt/settings/src/main.h similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/src/main.h rename to tests/bsim/bluetooth/host/gatt/settings/src/main.h diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/server.c b/tests/bsim/bluetooth/host/gatt/settings/src/server.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/src/server.c rename to tests/bsim/bluetooth/host/gatt/settings/src/server.c diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/settings.c b/tests/bsim/bluetooth/host/gatt/settings/src/settings.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/src/settings.c rename to tests/bsim/bluetooth/host/gatt/settings/src/settings.c diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/utils.c b/tests/bsim/bluetooth/host/gatt/settings/src/utils.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/src/utils.c rename to tests/bsim/bluetooth/host/gatt/settings/src/utils.c diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/utils.h b/tests/bsim/bluetooth/host/gatt/settings/src/utils.h similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/src/utils.h rename to tests/bsim/bluetooth/host/gatt/settings/src/utils.h diff --git a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/gatt/settings/test_scripts/_compile.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/test_scripts/_compile.sh rename to tests/bsim/bluetooth/host/gatt/settings/test_scripts/_compile.sh diff --git a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/_env.sh b/tests/bsim/bluetooth/host/gatt/settings/test_scripts/_env.sh similarity index 75% rename from tests/bluetooth/bsim/host/gatt/settings/test_scripts/_env.sh rename to tests/bsim/bluetooth/host/gatt/settings/test_scripts/_env.sh index aba0945a3c43..348f8ec6d427 100755 --- a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/gatt/settings/test_scripts/_env.sh @@ -9,5 +9,5 @@ bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" test_name="$(basename "$(realpath "$bash_source_dir/..")")" bsim_bin="${BSIM_OUT_PATH}/bin" BOARD="${BOARD:-nrf52_bsim}" -test_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_gatt_settings_prj_conf" -test_2_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_gatt_settings_prj_2_conf" +test_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_gatt_settings_prj_conf" +test_2_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_gatt_settings_prj_2_conf" diff --git a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings.sh b/tests/bsim/bluetooth/host/gatt/settings/test_scripts/run_gatt_settings.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings.sh rename to tests/bsim/bluetooth/host/gatt/settings/test_scripts/run_gatt_settings.sh diff --git a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings_2.sh b/tests/bsim/bluetooth/host/gatt/settings/test_scripts/run_gatt_settings_2.sh similarity index 100% rename from tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings_2.sh rename to tests/bsim/bluetooth/host/gatt/settings/test_scripts/run_gatt_settings_2.sh diff --git a/tests/bluetooth/bsim/host/gatt/write/CMakeLists.txt b/tests/bsim/bluetooth/host/gatt/write/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/gatt/write/CMakeLists.txt rename to tests/bsim/bluetooth/host/gatt/write/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/gatt/write/prj.conf b/tests/bsim/bluetooth/host/gatt/write/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/gatt/write/prj.conf rename to tests/bsim/bluetooth/host/gatt/write/prj.conf diff --git a/tests/bluetooth/bsim/host/gatt/write/src/main.c b/tests/bsim/bluetooth/host/gatt/write/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/gatt/write/src/main.c rename to tests/bsim/bluetooth/host/gatt/write/src/main.c diff --git a/tests/bluetooth/bsim/host/gatt/write/tests_scripts/gatt_write.sh b/tests/bsim/bluetooth/host/gatt/write/tests_scripts/gatt_write.sh similarity index 88% rename from tests/bluetooth/bsim/host/gatt/write/tests_scripts/gatt_write.sh rename to tests/bsim/bluetooth/host/gatt/write/tests_scripts/gatt_write.sh index 3f087de656f6..30c05ea3a8a5 100755 --- a/tests/bluetooth/bsim/host/gatt/write/tests_scripts/gatt_write.sh +++ b/tests/bsim/bluetooth/host/gatt/write/tests_scripts/gatt_write.sh @@ -23,10 +23,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_write_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_write_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_write_prj_conf\ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_write_prj_conf\ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/l2cap/general/CMakeLists.txt b/tests/bsim/bluetooth/host/l2cap/general/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/general/CMakeLists.txt rename to tests/bsim/bluetooth/host/l2cap/general/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/l2cap/general/prj.conf b/tests/bsim/bluetooth/host/l2cap/general/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/general/prj.conf rename to tests/bsim/bluetooth/host/l2cap/general/prj.conf diff --git a/tests/bluetooth/bsim/host/l2cap/general/src/common.c b/tests/bsim/bluetooth/host/l2cap/general/src/common.c similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/general/src/common.c rename to tests/bsim/bluetooth/host/l2cap/general/src/common.c diff --git a/tests/bluetooth/bsim/host/l2cap/general/src/common.h b/tests/bsim/bluetooth/host/l2cap/general/src/common.h similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/general/src/common.h rename to tests/bsim/bluetooth/host/l2cap/general/src/common.h diff --git a/tests/bluetooth/bsim/host/l2cap/general/src/main.c b/tests/bsim/bluetooth/host/l2cap/general/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/general/src/main.c rename to tests/bsim/bluetooth/host/l2cap/general/src/main.c diff --git a/tests/bluetooth/bsim/host/l2cap/general/src/main_l2cap_ecred.c b/tests/bsim/bluetooth/host/l2cap/general/src/main_l2cap_ecred.c similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/general/src/main_l2cap_ecred.c rename to tests/bsim/bluetooth/host/l2cap/general/src/main_l2cap_ecred.c diff --git a/tests/bluetooth/bsim/host/l2cap/general/tests_scripts/l2cap.sh b/tests/bsim/bluetooth/host/l2cap/general/tests_scripts/l2cap.sh similarity index 88% rename from tests/bluetooth/bsim/host/l2cap/general/tests_scripts/l2cap.sh rename to tests/bsim/bluetooth/host/l2cap/general/tests_scripts/l2cap.sh index 16f33b905956..54cf6c756158 100755 --- a/tests/bluetooth/bsim/host/l2cap/general/tests_scripts/l2cap.sh +++ b/tests/bsim/bluetooth/host/l2cap/general/tests_scripts/l2cap.sh @@ -23,10 +23,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_l2cap_general_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_l2cap_general_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -rs=43 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_l2cap_general_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_l2cap_general_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral -rs=42 Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/l2cap/stress/CMakeLists.txt b/tests/bsim/bluetooth/host/l2cap/stress/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/stress/CMakeLists.txt rename to tests/bsim/bluetooth/host/l2cap/stress/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/l2cap/stress/prj.conf b/tests/bsim/bluetooth/host/l2cap/stress/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/stress/prj.conf rename to tests/bsim/bluetooth/host/l2cap/stress/prj.conf diff --git a/tests/bluetooth/bsim/host/l2cap/stress/src/common.c b/tests/bsim/bluetooth/host/l2cap/stress/src/common.c similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/stress/src/common.c rename to tests/bsim/bluetooth/host/l2cap/stress/src/common.c diff --git a/tests/bluetooth/bsim/host/l2cap/stress/src/common.h b/tests/bsim/bluetooth/host/l2cap/stress/src/common.h similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/stress/src/common.h rename to tests/bsim/bluetooth/host/l2cap/stress/src/common.h diff --git a/tests/bluetooth/bsim/host/l2cap/stress/src/main.c b/tests/bsim/bluetooth/host/l2cap/stress/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/stress/src/main.c rename to tests/bsim/bluetooth/host/l2cap/stress/src/main.c diff --git a/tests/bluetooth/bsim/host/l2cap/stress/tests_scripts/l2cap.sh b/tests/bsim/bluetooth/host/l2cap/stress/tests_scripts/l2cap.sh similarity index 95% rename from tests/bluetooth/bsim/host/l2cap/stress/tests_scripts/l2cap.sh rename to tests/bsim/bluetooth/host/l2cap/stress/tests_scripts/l2cap.sh index adb71fc3378e..e556fad38e24 100755 --- a/tests/bluetooth/bsim/host/l2cap/stress/tests_scripts/l2cap.sh +++ b/tests/bsim/bluetooth/host/l2cap/stress/tests_scripts/l2cap.sh @@ -24,7 +24,7 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -bsim_exe=./bs_${BOARD}_tests_bluetooth_bsim_host_l2cap_stress_prj_conf +bsim_exe=./bs_${BOARD}_tests_bsim_bluetooth_host_l2cap_stress_prj_conf Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -rs=43 diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/CMakeLists.txt b/tests/bsim/bluetooth/host/l2cap/userdata/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/userdata/CMakeLists.txt rename to tests/bsim/bluetooth/host/l2cap/userdata/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/prj.conf b/tests/bsim/bluetooth/host/l2cap/userdata/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/userdata/prj.conf rename to tests/bsim/bluetooth/host/l2cap/userdata/prj.conf diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/src/common.c b/tests/bsim/bluetooth/host/l2cap/userdata/src/common.c similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/userdata/src/common.c rename to tests/bsim/bluetooth/host/l2cap/userdata/src/common.c diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/src/common.h b/tests/bsim/bluetooth/host/l2cap/userdata/src/common.h similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/userdata/src/common.h rename to tests/bsim/bluetooth/host/l2cap/userdata/src/common.h diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/src/main.c b/tests/bsim/bluetooth/host/l2cap/userdata/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/userdata/src/main.c rename to tests/bsim/bluetooth/host/l2cap/userdata/src/main.c diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/src/main_l2cap_userdata.c b/tests/bsim/bluetooth/host/l2cap/userdata/src/main_l2cap_userdata.c similarity index 100% rename from tests/bluetooth/bsim/host/l2cap/userdata/src/main_l2cap_userdata.c rename to tests/bsim/bluetooth/host/l2cap/userdata/src/main_l2cap_userdata.c diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/tests_scripts/l2cap.sh b/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/l2cap.sh similarity index 88% rename from tests/bluetooth/bsim/host/l2cap/userdata/tests_scripts/l2cap.sh rename to tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/l2cap.sh index 45a84515151a..05637864fe6d 100755 --- a/tests/bluetooth/bsim/host/l2cap/userdata/tests_scripts/l2cap.sh +++ b/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/l2cap.sh @@ -24,10 +24,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_l2cap_userdata_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_l2cap_userdata_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_l2cap_userdata_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_l2cap_userdata_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/misc/disable/CMakeLists.txt b/tests/bsim/bluetooth/host/misc/disable/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/misc/disable/CMakeLists.txt rename to tests/bsim/bluetooth/host/misc/disable/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/misc/disable/prj.conf b/tests/bsim/bluetooth/host/misc/disable/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/misc/disable/prj.conf rename to tests/bsim/bluetooth/host/misc/disable/prj.conf diff --git a/tests/bluetooth/bsim/host/misc/disable/src/common.c b/tests/bsim/bluetooth/host/misc/disable/src/common.c similarity index 100% rename from tests/bluetooth/bsim/host/misc/disable/src/common.c rename to tests/bsim/bluetooth/host/misc/disable/src/common.c diff --git a/tests/bluetooth/bsim/host/misc/disable/src/common.h b/tests/bsim/bluetooth/host/misc/disable/src/common.h similarity index 100% rename from tests/bluetooth/bsim/host/misc/disable/src/common.h rename to tests/bsim/bluetooth/host/misc/disable/src/common.h diff --git a/tests/bluetooth/bsim/host/misc/disable/src/gatt_client_test.c b/tests/bsim/bluetooth/host/misc/disable/src/gatt_client_test.c similarity index 100% rename from tests/bluetooth/bsim/host/misc/disable/src/gatt_client_test.c rename to tests/bsim/bluetooth/host/misc/disable/src/gatt_client_test.c diff --git a/tests/bluetooth/bsim/host/misc/disable/src/gatt_server_test.c b/tests/bsim/bluetooth/host/misc/disable/src/gatt_server_test.c similarity index 100% rename from tests/bluetooth/bsim/host/misc/disable/src/gatt_server_test.c rename to tests/bsim/bluetooth/host/misc/disable/src/gatt_server_test.c diff --git a/tests/bluetooth/bsim/host/misc/disable/src/main.c b/tests/bsim/bluetooth/host/misc/disable/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/misc/disable/src/main.c rename to tests/bsim/bluetooth/host/misc/disable/src/main.c diff --git a/tests/bluetooth/bsim/host/misc/disable/src/main_disable.c b/tests/bsim/bluetooth/host/misc/disable/src/main_disable.c similarity index 100% rename from tests/bluetooth/bsim/host/misc/disable/src/main_disable.c rename to tests/bsim/bluetooth/host/misc/disable/src/main_disable.c diff --git a/tests/bluetooth/bsim/host/misc/disable/tests_scripts/disable.sh b/tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable.sh similarity index 93% rename from tests/bluetooth/bsim/host/misc/disable/tests_scripts/disable.sh rename to tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable.sh index 9ee0539fd267..b3e390f82d59 100755 --- a/tests/bluetooth/bsim/host/misc/disable/tests_scripts/disable.sh +++ b/tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable.sh @@ -23,7 +23,7 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_misc_disable_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_misc_disable_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=disable Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/misc/disable/tests_scripts/disable_with_gatt.sh b/tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable_with_gatt.sh similarity index 90% rename from tests/bluetooth/bsim/host/misc/disable/tests_scripts/disable_with_gatt.sh rename to tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable_with_gatt.sh index 847718012a6b..fef45b2f61d8 100755 --- a/tests/bluetooth/bsim/host/misc/disable/tests_scripts/disable_with_gatt.sh +++ b/tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable_with_gatt.sh @@ -26,10 +26,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_misc_disable_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_misc_disable_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=gatt_client -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_misc_disable_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_misc_disable_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=gatt_server Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/misc/multiple_id/CMakeLists.txt b/tests/bsim/bluetooth/host/misc/multiple_id/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/misc/multiple_id/CMakeLists.txt rename to tests/bsim/bluetooth/host/misc/multiple_id/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/misc/multiple_id/prj.conf b/tests/bsim/bluetooth/host/misc/multiple_id/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/misc/multiple_id/prj.conf rename to tests/bsim/bluetooth/host/misc/multiple_id/prj.conf diff --git a/tests/bluetooth/bsim/host/misc/multiple_id/src/main.c b/tests/bsim/bluetooth/host/misc/multiple_id/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/misc/multiple_id/src/main.c rename to tests/bsim/bluetooth/host/misc/multiple_id/src/main.c diff --git a/tests/bluetooth/bsim/host/misc/multiple_id/tests_scripts/multiple.sh b/tests/bsim/bluetooth/host/misc/multiple_id/tests_scripts/multiple.sh similarity index 88% rename from tests/bluetooth/bsim/host/misc/multiple_id/tests_scripts/multiple.sh rename to tests/bsim/bluetooth/host/misc/multiple_id/tests_scripts/multiple.sh index 37c6d382593d..e8c24354d055 100755 --- a/tests/bluetooth/bsim/host/misc/multiple_id/tests_scripts/multiple.sh +++ b/tests/bsim/bluetooth/host/misc/multiple_id/tests_scripts/multiple.sh @@ -23,10 +23,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_misc_multiple_id_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_misc_multiple_id_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_misc_multiple_id_prj_conf\ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_misc_multiple_id_prj_conf\ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/host/privacy/central/CMakeLists.txt b/tests/bsim/bluetooth/host/privacy/central/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/privacy/central/CMakeLists.txt rename to tests/bsim/bluetooth/host/privacy/central/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/privacy/central/prj.conf b/tests/bsim/bluetooth/host/privacy/central/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/privacy/central/prj.conf rename to tests/bsim/bluetooth/host/privacy/central/prj.conf diff --git a/tests/bluetooth/bsim/host/privacy/central/src/bs_bt_utils.c b/tests/bsim/bluetooth/host/privacy/central/src/bs_bt_utils.c similarity index 100% rename from tests/bluetooth/bsim/host/privacy/central/src/bs_bt_utils.c rename to tests/bsim/bluetooth/host/privacy/central/src/bs_bt_utils.c diff --git a/tests/bluetooth/bsim/host/privacy/central/src/bs_bt_utils.h b/tests/bsim/bluetooth/host/privacy/central/src/bs_bt_utils.h similarity index 100% rename from tests/bluetooth/bsim/host/privacy/central/src/bs_bt_utils.h rename to tests/bsim/bluetooth/host/privacy/central/src/bs_bt_utils.h diff --git a/tests/bluetooth/bsim/host/privacy/central/src/dut.c b/tests/bsim/bluetooth/host/privacy/central/src/dut.c similarity index 100% rename from tests/bluetooth/bsim/host/privacy/central/src/dut.c rename to tests/bsim/bluetooth/host/privacy/central/src/dut.c diff --git a/tests/bluetooth/bsim/host/privacy/central/src/main.c b/tests/bsim/bluetooth/host/privacy/central/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/privacy/central/src/main.c rename to tests/bsim/bluetooth/host/privacy/central/src/main.c diff --git a/tests/bluetooth/bsim/host/privacy/central/src/tester.c b/tests/bsim/bluetooth/host/privacy/central/src/tester.c similarity index 100% rename from tests/bluetooth/bsim/host/privacy/central/src/tester.c rename to tests/bsim/bluetooth/host/privacy/central/src/tester.c diff --git a/tests/bluetooth/bsim/host/privacy/central/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/privacy/central/test_scripts/_compile.sh similarity index 100% rename from tests/bluetooth/bsim/host/privacy/central/test_scripts/_compile.sh rename to tests/bsim/bluetooth/host/privacy/central/test_scripts/_compile.sh diff --git a/tests/bluetooth/bsim/host/privacy/central/test_scripts/_env.sh b/tests/bsim/bluetooth/host/privacy/central/test_scripts/_env.sh similarity index 92% rename from tests/bluetooth/bsim/host/privacy/central/test_scripts/_env.sh rename to tests/bsim/bluetooth/host/privacy/central/test_scripts/_env.sh index a196afdadeb8..44e2f07ee4c1 100755 --- a/tests/bluetooth/bsim/host/privacy/central/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/privacy/central/test_scripts/_env.sh @@ -12,7 +12,7 @@ bsim_bin="${BSIM_OUT_PATH}/bin" verbosity_level=2 BOARD="${BOARD:-nrf52_bsim}" simulation_id="$test_name" -central_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_privacy_central_prj_conf" +central_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_privacy_central_prj_conf" peripheral_exe="${central_exe}" function print_var { diff --git a/tests/bluetooth/bsim/host/privacy/central/test_scripts/run_test.sh b/tests/bsim/bluetooth/host/privacy/central/test_scripts/run_test.sh similarity index 100% rename from tests/bluetooth/bsim/host/privacy/central/test_scripts/run_test.sh rename to tests/bsim/bluetooth/host/privacy/central/test_scripts/run_test.sh diff --git a/tests/bluetooth/bsim/host/privacy/device/CMakeLists.txt b/tests/bsim/bluetooth/host/privacy/device/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/privacy/device/CMakeLists.txt rename to tests/bsim/bluetooth/host/privacy/device/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/privacy/device/README.rst b/tests/bsim/bluetooth/host/privacy/device/README.rst similarity index 100% rename from tests/bluetooth/bsim/host/privacy/device/README.rst rename to tests/bsim/bluetooth/host/privacy/device/README.rst diff --git a/tests/bluetooth/bsim/host/privacy/device/prj.conf b/tests/bsim/bluetooth/host/privacy/device/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/privacy/device/prj.conf rename to tests/bsim/bluetooth/host/privacy/device/prj.conf diff --git a/tests/bluetooth/bsim/host/privacy/device/src/test_undirected_central.c b/tests/bsim/bluetooth/host/privacy/device/src/test_undirected_central.c similarity index 100% rename from tests/bluetooth/bsim/host/privacy/device/src/test_undirected_central.c rename to tests/bsim/bluetooth/host/privacy/device/src/test_undirected_central.c diff --git a/tests/bluetooth/bsim/host/privacy/device/src/test_undirected_main.c b/tests/bsim/bluetooth/host/privacy/device/src/test_undirected_main.c similarity index 100% rename from tests/bluetooth/bsim/host/privacy/device/src/test_undirected_main.c rename to tests/bsim/bluetooth/host/privacy/device/src/test_undirected_main.c diff --git a/tests/bluetooth/bsim/host/privacy/device/src/test_undirected_peripheral.c b/tests/bsim/bluetooth/host/privacy/device/src/test_undirected_peripheral.c similarity index 100% rename from tests/bluetooth/bsim/host/privacy/device/src/test_undirected_peripheral.c rename to tests/bsim/bluetooth/host/privacy/device/src/test_undirected_peripheral.c diff --git a/tests/bluetooth/bsim/host/privacy/device/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/privacy/device/test_scripts/_compile.sh similarity index 100% rename from tests/bluetooth/bsim/host/privacy/device/test_scripts/_compile.sh rename to tests/bsim/bluetooth/host/privacy/device/test_scripts/_compile.sh diff --git a/tests/bluetooth/bsim/host/privacy/device/test_scripts/_env.sh b/tests/bsim/bluetooth/host/privacy/device/test_scripts/_env.sh similarity index 86% rename from tests/bluetooth/bsim/host/privacy/device/test_scripts/_env.sh rename to tests/bsim/bluetooth/host/privacy/device/test_scripts/_env.sh index 0b4455c92511..bb1b50678cce 100755 --- a/tests/bluetooth/bsim/host/privacy/device/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/privacy/device/test_scripts/_env.sh @@ -12,4 +12,4 @@ bsim_bin="${BSIM_OUT_PATH}/bin" verbosity_level=2 BOARD="${BOARD:-nrf52_bsim}" simulation_id="$test_name" -test_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_privacy_device_prj_conf" +test_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_privacy_device_prj_conf" diff --git a/tests/bluetooth/bsim/host/privacy/device/test_scripts/run_tests.sh b/tests/bsim/bluetooth/host/privacy/device/test_scripts/run_tests.sh similarity index 100% rename from tests/bluetooth/bsim/host/privacy/device/test_scripts/run_tests.sh rename to tests/bsim/bluetooth/host/privacy/device/test_scripts/run_tests.sh diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/CMakeLists.txt b/tests/bsim/bluetooth/host/privacy/peripheral/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/privacy/peripheral/CMakeLists.txt rename to tests/bsim/bluetooth/host/privacy/peripheral/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/prj.conf b/tests/bsim/bluetooth/host/privacy/peripheral/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/privacy/peripheral/prj.conf rename to tests/bsim/bluetooth/host/privacy/peripheral/prj.conf diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/src/bs_bt_utils.c b/tests/bsim/bluetooth/host/privacy/peripheral/src/bs_bt_utils.c similarity index 100% rename from tests/bluetooth/bsim/host/privacy/peripheral/src/bs_bt_utils.c rename to tests/bsim/bluetooth/host/privacy/peripheral/src/bs_bt_utils.c diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/src/bs_bt_utils.h b/tests/bsim/bluetooth/host/privacy/peripheral/src/bs_bt_utils.h similarity index 100% rename from tests/bluetooth/bsim/host/privacy/peripheral/src/bs_bt_utils.h rename to tests/bsim/bluetooth/host/privacy/peripheral/src/bs_bt_utils.h diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/src/dut.c b/tests/bsim/bluetooth/host/privacy/peripheral/src/dut.c similarity index 100% rename from tests/bluetooth/bsim/host/privacy/peripheral/src/dut.c rename to tests/bsim/bluetooth/host/privacy/peripheral/src/dut.c diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/src/main.c b/tests/bsim/bluetooth/host/privacy/peripheral/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/privacy/peripheral/src/main.c rename to tests/bsim/bluetooth/host/privacy/peripheral/src/main.c diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/src/tester.c b/tests/bsim/bluetooth/host/privacy/peripheral/src/tester.c similarity index 100% rename from tests/bluetooth/bsim/host/privacy/peripheral/src/tester.c rename to tests/bsim/bluetooth/host/privacy/peripheral/src/tester.c diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_compile.sh similarity index 100% rename from tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/_compile.sh rename to tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_compile.sh diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/_env.sh b/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_env.sh similarity index 92% rename from tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/_env.sh rename to tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_env.sh index 9731c7178f59..ac2d2d5888ef 100755 --- a/tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_env.sh @@ -12,7 +12,7 @@ bsim_bin="${BSIM_OUT_PATH}/bin" verbosity_level=2 BOARD="${BOARD:-nrf52_bsim}" simulation_id="$test_name" -central_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_privacy_peripheral_prj_conf" +central_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_privacy_peripheral_prj_conf" peripheral_exe="${central_exe}" function print_var { diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/run_test.sh b/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/run_test.sh similarity index 100% rename from tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/run_test.sh rename to tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/run_test.sh diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/CMakeLists.txt b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_allowed/CMakeLists.txt rename to tests/bsim/bluetooth/host/security/bond_overwrite_allowed/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/prj.conf b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_allowed/prj.conf rename to tests/bsim/bluetooth/host/security/bond_overwrite_allowed/prj.conf diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/bs_bt_utils.c b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/src/bs_bt_utils.c similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/bs_bt_utils.c rename to tests/bsim/bluetooth/host/security/bond_overwrite_allowed/src/bs_bt_utils.c diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/bs_bt_utils.h b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/src/bs_bt_utils.h similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/bs_bt_utils.h rename to tests/bsim/bluetooth/host/security/bond_overwrite_allowed/src/bs_bt_utils.h diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/central.c b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/src/central.c similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/central.c rename to tests/bsim/bluetooth/host/security/bond_overwrite_allowed/src/central.c diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/main.c b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/main.c rename to tests/bsim/bluetooth/host/security/bond_overwrite_allowed/src/main.c diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/peripheral.c b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/src/peripheral.c similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/peripheral.c rename to tests/bsim/bluetooth/host/security/bond_overwrite_allowed/src/peripheral.c diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh similarity index 84% rename from tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/_compile.sh rename to tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh index 7792a05565c1..8a431f173c60 100755 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh @@ -18,5 +18,5 @@ BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" INCR_BUILD=1 mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source -app="tests/bluetooth/bsim/$test_name" compile +source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source +app="tests/bsim/bluetooth/$test_name" compile diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/_env.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_env.sh similarity index 92% rename from tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/_env.sh rename to tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_env.sh index 4f2af9867047..f0005e331cc6 100755 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_env.sh @@ -11,7 +11,7 @@ bsim_bin="${BSIM_OUT_PATH}/bin" verbosity_level=2 BOARD="${BOARD:-nrf52_bsim}" simulation_id="$test_name" -central_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_${test_name}_prj_conf" +central_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_${test_name}_prj_conf" peripheral_exe="${central_exe}" function print_var { diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/run_test.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/run_test.sh similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/run_test.sh rename to tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/run_test.sh diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/CMakeLists.txt b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_denied/CMakeLists.txt rename to tests/bsim/bluetooth/host/security/bond_overwrite_denied/CMakeLists.txt diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/prj.conf b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/prj.conf similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_denied/prj.conf rename to tests/bsim/bluetooth/host/security/bond_overwrite_denied/prj.conf diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/bs_bt_utils.c b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/src/bs_bt_utils.c similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/bs_bt_utils.c rename to tests/bsim/bluetooth/host/security/bond_overwrite_denied/src/bs_bt_utils.c diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/bs_bt_utils.h b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/src/bs_bt_utils.h similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/bs_bt_utils.h rename to tests/bsim/bluetooth/host/security/bond_overwrite_denied/src/bs_bt_utils.h diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/central.c b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/src/central.c similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/central.c rename to tests/bsim/bluetooth/host/security/bond_overwrite_denied/src/central.c diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/main.c b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/src/main.c similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/main.c rename to tests/bsim/bluetooth/host/security/bond_overwrite_denied/src/main.c diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/peripheral.c b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/src/peripheral.c similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/peripheral.c rename to tests/bsim/bluetooth/host/security/bond_overwrite_denied/src/peripheral.c diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh similarity index 84% rename from tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/_compile.sh rename to tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh index 7792a05565c1..8a431f173c60 100755 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh @@ -18,5 +18,5 @@ BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" INCR_BUILD=1 mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source -app="tests/bluetooth/bsim/$test_name" compile +source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source +app="tests/bsim/bluetooth/$test_name" compile diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/_env.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_env.sh similarity index 92% rename from tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/_env.sh rename to tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_env.sh index 3097cb4bc17f..982ba75d4f5f 100755 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_env.sh @@ -11,7 +11,7 @@ bsim_bin="${BSIM_OUT_PATH}/bin" verbosity_level=2 BOARD="${BOARD:-nrf52_bsim}" simulation_id="$test_name" -central_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_${test_name}_prj_conf" +central_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_${test_name}_prj_conf" peripheral_exe="${central_exe}" function print_var { diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/run_test.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/run_test.sh similarity index 100% rename from tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/run_test.sh rename to tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/run_test.sh diff --git a/tests/bluetooth/bsim/ll/advx/CMakeLists.txt b/tests/bsim/bluetooth/ll/advx/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/ll/advx/CMakeLists.txt rename to tests/bsim/bluetooth/ll/advx/CMakeLists.txt diff --git a/tests/bluetooth/bsim/ll/advx/prj.conf b/tests/bsim/bluetooth/ll/advx/prj.conf similarity index 100% rename from tests/bluetooth/bsim/ll/advx/prj.conf rename to tests/bsim/bluetooth/ll/advx/prj.conf diff --git a/tests/bluetooth/bsim/ll/advx/src/main.c b/tests/bsim/bluetooth/ll/advx/src/main.c similarity index 100% rename from tests/bluetooth/bsim/ll/advx/src/main.c rename to tests/bsim/bluetooth/ll/advx/src/main.c diff --git a/tests/bluetooth/bsim/ll/advx/tests_scripts/basic_advx.sh b/tests/bsim/bluetooth/ll/advx/tests_scripts/basic_advx.sh similarity index 89% rename from tests/bluetooth/bsim/ll/advx/tests_scripts/basic_advx.sh rename to tests/bsim/bluetooth/ll/advx/tests_scripts/basic_advx.sh index 5379d8bf7007..056378febf30 100755 --- a/tests/bluetooth/bsim/ll/advx/tests_scripts/basic_advx.sh +++ b/tests/bsim/bluetooth/ll/advx/tests_scripts/basic_advx.sh @@ -24,10 +24,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_advx_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_advx_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=advx -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_advx_prj_conf\ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_advx_prj_conf\ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=scanx Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/ll/compile.sh b/tests/bsim/bluetooth/ll/compile.sh similarity index 57% rename from tests/bluetooth/bsim/ll/compile.sh rename to tests/bsim/bluetooth/ll/compile.sh index f9d6f7624146..fcc361229564 100755 --- a/tests/bluetooth/bsim/ll/compile.sh +++ b/tests/bsim/bluetooth/ll/compile.sh @@ -18,22 +18,22 @@ BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source +source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source -app=tests/bluetooth/bsim/ll/advx compile +app=tests/bsim/bluetooth/ll/advx compile -app=tests/bluetooth/bsim/ll/conn conf_file=prj_split.conf compile -app=tests/bluetooth/bsim/ll/conn conf_file=prj_split_privacy.conf compile -app=tests/bluetooth/bsim/ll/conn conf_file=prj_split_low_lat.conf compile +app=tests/bsim/bluetooth/ll/conn conf_file=prj_split.conf compile +app=tests/bsim/bluetooth/ll/conn conf_file=prj_split_privacy.conf compile +app=tests/bsim/bluetooth/ll/conn conf_file=prj_split_low_lat.conf compile -app=tests/bluetooth/bsim/ll/iso compile -app=tests/bluetooth/bsim/ll/iso conf_file=prj_vs_dp.conf compile +app=tests/bsim/bluetooth/ll/iso compile +app=tests/bsim/bluetooth/ll/iso conf_file=prj_vs_dp.conf compile -app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ +app=tests/bsim/bluetooth/ll/edtt/hci_test_app \ conf_file=prj_dut_llcp.conf compile -app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ +app=tests/bsim/bluetooth/ll/edtt/hci_test_app \ conf_file=prj_tst_llcp.conf compile -app=tests/bluetooth/bsim/ll/edtt/gatt_test_app \ +app=tests/bsim/bluetooth/ll/edtt/gatt_test_app \ conf_file=prj_llcp.conf compile wait_for_background_jobs diff --git a/tests/bluetooth/bsim/ll/conn/CMakeLists.txt b/tests/bsim/bluetooth/ll/conn/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/ll/conn/CMakeLists.txt rename to tests/bsim/bluetooth/ll/conn/CMakeLists.txt diff --git a/tests/bluetooth/bsim/ll/conn/README.txt b/tests/bsim/bluetooth/ll/conn/README.txt similarity index 100% rename from tests/bluetooth/bsim/ll/conn/README.txt rename to tests/bsim/bluetooth/ll/conn/README.txt diff --git a/tests/bluetooth/bsim/ll/conn/prj_split.conf b/tests/bsim/bluetooth/ll/conn/prj_split.conf similarity index 100% rename from tests/bluetooth/bsim/ll/conn/prj_split.conf rename to tests/bsim/bluetooth/ll/conn/prj_split.conf diff --git a/tests/bluetooth/bsim/ll/conn/prj_split_low_lat.conf b/tests/bsim/bluetooth/ll/conn/prj_split_low_lat.conf similarity index 100% rename from tests/bluetooth/bsim/ll/conn/prj_split_low_lat.conf rename to tests/bsim/bluetooth/ll/conn/prj_split_low_lat.conf diff --git a/tests/bluetooth/bsim/ll/conn/prj_split_privacy.conf b/tests/bsim/bluetooth/ll/conn/prj_split_privacy.conf similarity index 100% rename from tests/bluetooth/bsim/ll/conn/prj_split_privacy.conf rename to tests/bsim/bluetooth/ll/conn/prj_split_privacy.conf diff --git a/tests/bluetooth/bsim/ll/conn/src/main.c b/tests/bsim/bluetooth/ll/conn/src/main.c similarity index 100% rename from tests/bluetooth/bsim/ll/conn/src/main.c rename to tests/bsim/bluetooth/ll/conn/src/main.c diff --git a/tests/bluetooth/bsim/ll/conn/src/test_connect1.c b/tests/bsim/bluetooth/ll/conn/src/test_connect1.c similarity index 100% rename from tests/bluetooth/bsim/ll/conn/src/test_connect1.c rename to tests/bsim/bluetooth/ll/conn/src/test_connect1.c diff --git a/tests/bluetooth/bsim/ll/conn/src/test_connect2.c b/tests/bsim/bluetooth/ll/conn/src/test_connect2.c similarity index 100% rename from tests/bluetooth/bsim/ll/conn/src/test_connect2.c rename to tests/bsim/bluetooth/ll/conn/src/test_connect2.c diff --git a/tests/bluetooth/bsim/ll/conn/src/test_empty.c b/tests/bsim/bluetooth/ll/conn/src/test_empty.c similarity index 100% rename from tests/bluetooth/bsim/ll/conn/src/test_empty.c rename to tests/bsim/bluetooth/ll/conn/src/test_empty.c diff --git a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_encrypted_split.sh b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split.sh similarity index 89% rename from tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_encrypted_split.sh rename to tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split.sh index 460d46a8e4f9..c2bf39cac132 100755 --- a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_encrypted_split.sh +++ b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split.sh @@ -24,11 +24,11 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_conn_prj_split_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1 \ -testid=peripheral -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_conn_prj_split_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=1 \ -testid=central_encrypted -rs=6 diff --git a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh similarity index 89% rename from tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh rename to tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh index 09a4e14e0700..7062aaeab472 100755 --- a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh +++ b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh @@ -25,12 +25,12 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_privacy_conf \ + ./bs_${BOARD}_tests_bsim_bluetooth_ll_conn_prj_split_privacy_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1 \ -testid=peripheral -rs=23 Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_privacy_conf \ + ./bs_${BOARD}_tests_bsim_bluetooth_ll_conn_prj_split_privacy_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=1 \ -testid=central_encrypted -rs=6 diff --git a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_split.sh b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split.sh similarity index 89% rename from tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_split.sh rename to tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split.sh index bd70e2c47670..1106e44ca5c2 100755 --- a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_split.sh +++ b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split.sh @@ -24,11 +24,11 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_conn_prj_split_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \ -testid=peripheral -rs=23 -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_conf\ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_conn_prj_split_conf\ -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \ -testid=central -rs=6 diff --git a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_split_low_lat.sh b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split_low_lat.sh similarity index 89% rename from tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_split_low_lat.sh rename to tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split_low_lat.sh index f4ce0fc9b234..a3fa4abd1466 100755 --- a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_split_low_lat.sh +++ b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split_low_lat.sh @@ -25,12 +25,12 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_low_lat_conf \ + ./bs_${BOARD}_tests_bsim_bluetooth_ll_conn_prj_split_low_lat_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \ -testid=peripheral -rs=23 Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_low_lat_conf \ + ./bs_${BOARD}_tests_bsim_bluetooth_ll_conn_prj_split_low_lat_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \ -testid=central -rs=6 diff --git a/tests/bluetooth/bsim/ll/edtt/README.txt b/tests/bsim/bluetooth/ll/edtt/README.txt similarity index 89% rename from tests/bluetooth/bsim/ll/edtt/README.txt rename to tests/bsim/bluetooth/ll/edtt/README.txt index dfb31709fc7f..104662dc4cad 100644 --- a/tests/bluetooth/bsim/ll/edtt/README.txt +++ b/tests/bsim/bluetooth/ll/edtt/README.txt @@ -53,11 +53,11 @@ In short the whole process being: ``` cd ${ZEPHYR_BASE} && source zephyr-env.sh #Compile all apps: -WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bluetooth/bsim/compile.sh +WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/bluetooth/compile.sh #run all tests -RESULTS_FILE=${ZEPHYR_BASE}/banana.xml SEARCH_PATH=tests/bluetooth/bsim/ll/edtt/ tests/bluetooth/bsim/run_parallel.sh +RESULTS_FILE=${ZEPHYR_BASE}/banana.xml SEARCH_PATH=tests/bsim/bluetooth/ll/edtt/ tests/bsim/bluetooth/run_parallel.sh #or just run one set: -tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.sh +tests/bsim/bluetooth/ll/edtt/tests_scripts/hci.sh ``` diff --git a/tests/bluetooth/bsim/ll/edtt/common/commands.h b/tests/bsim/bluetooth/ll/edtt/common/commands.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/common/commands.h rename to tests/bsim/bluetooth/ll/edtt/common/commands.h diff --git a/tests/bluetooth/bsim/ll/edtt/common/edtt_driver.h b/tests/bsim/bluetooth/ll/edtt/common/edtt_driver.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/common/edtt_driver.h rename to tests/bsim/bluetooth/ll/edtt/common/edtt_driver.h diff --git a/tests/bluetooth/bsim/ll/edtt/common/edtt_driver_bsim.c b/tests/bsim/bluetooth/ll/edtt/common/edtt_driver_bsim.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/common/edtt_driver_bsim.c rename to tests/bsim/bluetooth/ll/edtt/common/edtt_driver_bsim.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/CMakeLists.txt b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/CMakeLists.txt rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/CMakeLists.txt diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj_llcp.conf b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/prj_llcp.conf similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj_llcp.conf rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/prj_llcp.conf diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/gatt_macs.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/gatt_macs.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/gatt_macs.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/gatt_macs.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_1.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_a_1.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_1.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_a_1.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_1.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_a_1.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_1.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_a_1.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_2.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_a_2.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_2.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_a_2.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_2.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_a_2.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_2.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_a_2.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_3.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_a_3.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_3.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_a_3.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_3.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_a_3.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_3.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_a_3.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_1.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_d_1.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_1.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_d_1.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_1.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_d_1.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_1.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_d_1.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_2.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_d_2.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_2.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_d_2.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_2.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_d_2.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_2.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_d_2.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_3.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_d_3.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_3.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_d_3.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_3.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_d_3.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_3.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_d_3.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_2.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_e_2.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_2.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_e_2.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_2.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_e_2.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_2.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_e_2.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_3.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_e_3.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_3.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_e_3.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_3.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_e_3.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_3.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_e_3.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_f_1.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_f_1.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_f_1.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_f_1.c diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_f_1.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_f_1.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_f_1.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/service_f_1.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/services.h b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/services.h similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/services.h rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/gatt/services.h diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/main.c b/tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/main.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/main.c rename to tests/bsim/bluetooth/ll/edtt/gatt_test_app/src/main.c diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/CMakeLists.txt b/tests/bsim/bluetooth/ll/edtt/hci_test_app/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/hci_test_app/CMakeLists.txt rename to tests/bsim/bluetooth/ll/edtt/hci_test_app/CMakeLists.txt diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut_llcp.conf b/tests/bsim/bluetooth/ll/edtt/hci_test_app/prj_dut_llcp.conf similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut_llcp.conf rename to tests/bsim/bluetooth/ll/edtt/hci_test_app/prj_dut_llcp.conf diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst_llcp.conf b/tests/bsim/bluetooth/ll/edtt/hci_test_app/prj_tst_llcp.conf similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst_llcp.conf rename to tests/bsim/bluetooth/ll/edtt/hci_test_app/prj_tst_llcp.conf diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/src/main.c b/tests/bsim/bluetooth/ll/edtt/hci_test_app/src/main.c similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/hci_test_app/src/main.c rename to tests/bsim/bluetooth/ll/edtt/hci_test_app/src/main.c diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/_controller_tests_inner.sh b/tests/bsim/bluetooth/ll/edtt/tests_scripts/_controller_tests_inner.sh similarity index 96% rename from tests/bluetooth/bsim/ll/edtt/tests_scripts/_controller_tests_inner.sh rename to tests/bsim/bluetooth/ll/edtt/tests_scripts/_controller_tests_inner.sh index 440f2039b084..a7b0592b22ae 100755 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/_controller_tests_inner.sh +++ b/tests/bsim/bluetooth/ll/edtt/tests_scripts/_controller_tests_inner.sh @@ -101,11 +101,11 @@ Execute ./src/edttool.py -s=${SIMULATION_ID} -d=2 --transport bsim \ cd ${BSIM_OUT_PATH}/bin Execute \ - ${RR_ARGS_1} ./bs_${BOARD}_tests_bluetooth_bsim_ll_edtt_hci_test_app_${PRJ_CONF_1}\ + ${RR_ARGS_1} ./bs_${BOARD}_tests_bsim_bluetooth_ll_edtt_hci_test_app_${PRJ_CONF_1}\ -s=${SIMULATION_ID} -d=0 -v=${VERBOSITY_LEVEL_DEV1} -RealEncryption=1 Execute \ - ${RR_ARGS_2} ./bs_${BOARD}_tests_bluetooth_bsim_ll_edtt_hci_test_app_${PRJ_CONF_2}\ + ${RR_ARGS_2} ./bs_${BOARD}_tests_bsim_bluetooth_ll_edtt_hci_test_app_${PRJ_CONF_2}\ -s=${SIMULATION_ID} -d=1 -v=${VERBOSITY_LEVEL_DEV2} -RealEncryption=1 Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL_PHY} -s=${SIMULATION_ID} \ diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.llcp.sh b/tests/bsim/bluetooth/ll/edtt/tests_scripts/gap.llcp.sh similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.llcp.sh rename to tests/bsim/bluetooth/ll/edtt/tests_scripts/gap.llcp.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.llcp.test_list b/tests/bsim/bluetooth/ll/edtt/tests_scripts/gap.llcp.test_list similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.llcp.test_list rename to tests/bsim/bluetooth/ll/edtt/tests_scripts/gap.llcp.test_list diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.llcp.sh b/tests/bsim/bluetooth/ll/edtt/tests_scripts/gatt.llcp.sh similarity index 90% rename from tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.llcp.sh rename to tests/bsim/bluetooth/ll/edtt/tests_scripts/gatt.llcp.sh index 382e56a5241b..f30f866923e4 100755 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.llcp.sh +++ b/tests/bsim/bluetooth/ll/edtt/tests_scripts/gatt.llcp.sh @@ -32,11 +32,11 @@ Execute ./src/edttool.py -s=${SIMULATION_ID} -d=0 --transport bsim \ cd ${BSIM_OUT_PATH}/bin Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_edtt_hci_test_app_prj_tst_llcp_conf\ + ./bs_${BOARD}_tests_bsim_bluetooth_ll_edtt_hci_test_app_prj_tst_llcp_conf\ -s=${SIMULATION_ID} -d=1 -v=${VERBOSITY_LEVEL} -RealEncryption=1 Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_edtt_gatt_test_app_prj_llcp_conf\ + ./bs_${BOARD}_tests_bsim_bluetooth_ll_edtt_gatt_test_app_prj_llcp_conf\ -s=${SIMULATION_ID} -d=2 -v=${VERBOSITY_LEVEL} -RealEncryption=1 Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.llcp.test_list b/tests/bsim/bluetooth/ll/edtt/tests_scripts/gatt.llcp.test_list similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.llcp.test_list rename to tests/bsim/bluetooth/ll/edtt/tests_scripts/gatt.llcp.test_list diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.llcp.sh b/tests/bsim/bluetooth/ll/edtt/tests_scripts/hci.llcp.sh similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.llcp.sh rename to tests/bsim/bluetooth/ll/edtt/tests_scripts/hci.llcp.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.llcp.test_list b/tests/bsim/bluetooth/ll/edtt/tests_scripts/hci.llcp.test_list similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.llcp.test_list rename to tests/bsim/bluetooth/ll/edtt/tests_scripts/hci.llcp.test_list diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.1.llcp.sh b/tests/bsim/bluetooth/ll/edtt/tests_scripts/ll.1.llcp.sh similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.1.llcp.sh rename to tests/bsim/bluetooth/ll/edtt/tests_scripts/ll.1.llcp.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.2.llcp.sh b/tests/bsim/bluetooth/ll/edtt/tests_scripts/ll.2.llcp.sh similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.2.llcp.sh rename to tests/bsim/bluetooth/ll/edtt/tests_scripts/ll.2.llcp.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set1.llcp.test_list b/tests/bsim/bluetooth/ll/edtt/tests_scripts/ll.set1.llcp.test_list similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set1.llcp.test_list rename to tests/bsim/bluetooth/ll/edtt/tests_scripts/ll.set1.llcp.test_list diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set2.llcp.test_list b/tests/bsim/bluetooth/ll/edtt/tests_scripts/ll.set2.llcp.test_list similarity index 100% rename from tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set2.llcp.test_list rename to tests/bsim/bluetooth/ll/edtt/tests_scripts/ll.set2.llcp.test_list diff --git a/tests/bluetooth/bsim/ll/iso/CMakeLists.txt b/tests/bsim/bluetooth/ll/iso/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/ll/iso/CMakeLists.txt rename to tests/bsim/bluetooth/ll/iso/CMakeLists.txt diff --git a/tests/bluetooth/bsim/ll/iso/prj.conf b/tests/bsim/bluetooth/ll/iso/prj.conf similarity index 100% rename from tests/bluetooth/bsim/ll/iso/prj.conf rename to tests/bsim/bluetooth/ll/iso/prj.conf diff --git a/tests/bluetooth/bsim/ll/iso/prj_vs_dp.conf b/tests/bsim/bluetooth/ll/iso/prj_vs_dp.conf similarity index 100% rename from tests/bluetooth/bsim/ll/iso/prj_vs_dp.conf rename to tests/bsim/bluetooth/ll/iso/prj_vs_dp.conf diff --git a/tests/bluetooth/bsim/ll/iso/src/main.c b/tests/bsim/bluetooth/ll/iso/src/main.c similarity index 100% rename from tests/bluetooth/bsim/ll/iso/src/main.c rename to tests/bsim/bluetooth/ll/iso/src/main.c diff --git a/tests/bluetooth/bsim/ll/iso/tests_scripts/broadcast_iso.sh b/tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso.sh similarity index 89% rename from tests/bluetooth/bsim/ll/iso/tests_scripts/broadcast_iso.sh rename to tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso.sh index 4a576327cc1e..bbec1b2c7124 100755 --- a/tests/bluetooth/bsim/ll/iso/tests_scripts/broadcast_iso.sh +++ b/tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso.sh @@ -24,10 +24,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_iso_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_iso_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=receive -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_iso_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_iso_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=broadcast Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh b/tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh similarity index 89% rename from tests/bluetooth/bsim/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh rename to tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh index 6d7a98cf1231..62b737314672 100755 --- a/tests/bluetooth/bsim/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh +++ b/tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh @@ -24,10 +24,10 @@ BOARD="${BOARD:-nrf52_bsim}" cd ${BSIM_OUT_PATH}/bin -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_iso_prj_vs_dp_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_iso_prj_vs_dp_conf \ -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=receive_vs_dp -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_iso_prj_conf \ +Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_iso_prj_conf \ -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=broadcast Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ diff --git a/tests/bluetooth/bsim/mesh/CMakeLists.txt b/tests/bsim/bluetooth/mesh/CMakeLists.txt similarity index 100% rename from tests/bluetooth/bsim/mesh/CMakeLists.txt rename to tests/bsim/bluetooth/mesh/CMakeLists.txt diff --git a/tests/bluetooth/bsim/mesh/README.rst b/tests/bsim/bluetooth/mesh/README.rst similarity index 98% rename from tests/bluetooth/bsim/mesh/README.rst rename to tests/bsim/bluetooth/mesh/README.rst index f2c44759f2ca..787b0084f0b5 100644 --- a/tests/bluetooth/bsim/mesh/README.rst +++ b/tests/bsim/bluetooth/mesh/README.rst @@ -50,7 +50,7 @@ Then separately, call ...code-block:: - gdb bs_nrf52_bsim_tests_bluetooth_bsim_mesh_prj_conf \ + gdb bs_nrf52_bsim_tests_bsim_bluetooth_mesh_prj_conf \ -s=mesh_transport_seg_block -d=0 -RealEncryption=1 \ -testid=transport_tx_seg_block diff --git a/tests/bluetooth/bsim/mesh/_mesh_test.sh b/tests/bsim/bluetooth/mesh/_mesh_test.sh similarity index 93% rename from tests/bluetooth/bsim/mesh/_mesh_test.sh rename to tests/bsim/bluetooth/mesh/_mesh_test.sh index bd303163428e..0827585f3c98 100755 --- a/tests/bluetooth/bsim/mesh/_mesh_test.sh +++ b/tests/bsim/bluetooth/mesh/_mesh_test.sh @@ -68,9 +68,9 @@ function RunTest(){ conf=${conf:-prj_conf} if [ ${overlay} ]; then - exe_name=./bs_${BOARD}_tests_bluetooth_bsim_mesh_${conf}_${overlay} + exe_name=./bs_${BOARD}_tests_bsim_bluetooth_mesh_${conf}_${overlay} else - exe_name=./bs_${BOARD}_tests_bluetooth_bsim_mesh_${conf} + exe_name=./bs_${BOARD}_tests_bsim_bluetooth_mesh_${conf} fi Execute \ diff --git a/tests/bluetooth/bsim/mesh/compile.sh b/tests/bsim/bluetooth/mesh/compile.sh similarity index 64% rename from tests/bluetooth/bsim/mesh/compile.sh rename to tests/bsim/bluetooth/mesh/compile.sh index d1c2df42c025..635d84654548 100755 --- a/tests/bluetooth/bsim/mesh/compile.sh +++ b/tests/bsim/bluetooth/mesh/compile.sh @@ -18,18 +18,18 @@ BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source - -app=tests/bluetooth/bsim/mesh compile -app=tests/bluetooth/bsim/mesh conf_overlay=overlay_low_lat.conf compile -app=tests/bluetooth/bsim/mesh conf_overlay=overlay_pst.conf compile -app=tests/bluetooth/bsim/mesh conf_overlay=overlay_gatt.conf compile -app=tests/bluetooth/bsim/mesh conf_file=prj_mesh1d1.conf compile -app=tests/bluetooth/bsim/mesh \ +source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source + +app=tests/bsim/bluetooth/mesh compile +app=tests/bsim/bluetooth/mesh conf_overlay=overlay_low_lat.conf compile +app=tests/bsim/bluetooth/mesh conf_overlay=overlay_pst.conf compile +app=tests/bsim/bluetooth/mesh conf_overlay=overlay_gatt.conf compile +app=tests/bsim/bluetooth/mesh conf_file=prj_mesh1d1.conf compile +app=tests/bsim/bluetooth/mesh \ conf_file=prj_mesh1d1.conf conf_overlay=overlay_pst.conf compile -app=tests/bluetooth/bsim/mesh \ +app=tests/bsim/bluetooth/mesh \ conf_file=prj_mesh1d1.conf conf_overlay=overlay_gatt.conf compile -app=tests/bluetooth/bsim/mesh \ +app=tests/bsim/bluetooth/mesh \ conf_file=prj_mesh1d1.conf conf_overlay=overlay_low_lat.conf compile wait_for_background_jobs diff --git a/tests/bluetooth/bsim/mesh/overlay_gatt.conf b/tests/bsim/bluetooth/mesh/overlay_gatt.conf similarity index 100% rename from tests/bluetooth/bsim/mesh/overlay_gatt.conf rename to tests/bsim/bluetooth/mesh/overlay_gatt.conf diff --git a/tests/bluetooth/bsim/mesh/overlay_low_lat.conf b/tests/bsim/bluetooth/mesh/overlay_low_lat.conf similarity index 100% rename from tests/bluetooth/bsim/mesh/overlay_low_lat.conf rename to tests/bsim/bluetooth/mesh/overlay_low_lat.conf diff --git a/tests/bluetooth/bsim/mesh/overlay_pst.conf b/tests/bsim/bluetooth/mesh/overlay_pst.conf similarity index 100% rename from tests/bluetooth/bsim/mesh/overlay_pst.conf rename to tests/bsim/bluetooth/mesh/overlay_pst.conf diff --git a/tests/bluetooth/bsim/mesh/prj.conf b/tests/bsim/bluetooth/mesh/prj.conf similarity index 100% rename from tests/bluetooth/bsim/mesh/prj.conf rename to tests/bsim/bluetooth/mesh/prj.conf diff --git a/tests/bluetooth/bsim/mesh/prj_mesh1d1.conf b/tests/bsim/bluetooth/mesh/prj_mesh1d1.conf similarity index 100% rename from tests/bluetooth/bsim/mesh/prj_mesh1d1.conf rename to tests/bsim/bluetooth/mesh/prj_mesh1d1.conf diff --git a/tests/bluetooth/bsim/mesh/src/dfu_blob_common.c b/tests/bsim/bluetooth/mesh/src/dfu_blob_common.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/dfu_blob_common.c rename to tests/bsim/bluetooth/mesh/src/dfu_blob_common.c diff --git a/tests/bluetooth/bsim/mesh/src/dfu_blob_common.h b/tests/bsim/bluetooth/mesh/src/dfu_blob_common.h similarity index 100% rename from tests/bluetooth/bsim/mesh/src/dfu_blob_common.h rename to tests/bsim/bluetooth/mesh/src/dfu_blob_common.h diff --git a/tests/bluetooth/bsim/mesh/src/main.c b/tests/bsim/bluetooth/mesh/src/main.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/main.c rename to tests/bsim/bluetooth/mesh/src/main.c diff --git a/tests/bluetooth/bsim/mesh/src/mesh_test.c b/tests/bsim/bluetooth/mesh/src/mesh_test.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/mesh_test.c rename to tests/bsim/bluetooth/mesh/src/mesh_test.c diff --git a/tests/bluetooth/bsim/mesh/src/mesh_test.h b/tests/bsim/bluetooth/mesh/src/mesh_test.h similarity index 100% rename from tests/bluetooth/bsim/mesh/src/mesh_test.h rename to tests/bsim/bluetooth/mesh/src/mesh_test.h diff --git a/tests/bluetooth/bsim/mesh/src/settings_test_backend.c b/tests/bsim/bluetooth/mesh/src/settings_test_backend.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/settings_test_backend.c rename to tests/bsim/bluetooth/mesh/src/settings_test_backend.c diff --git a/tests/bluetooth/bsim/mesh/src/settings_test_backend.h b/tests/bsim/bluetooth/mesh/src/settings_test_backend.h similarity index 100% rename from tests/bluetooth/bsim/mesh/src/settings_test_backend.h rename to tests/bsim/bluetooth/mesh/src/settings_test_backend.h diff --git a/tests/bluetooth/bsim/mesh/src/test_access.c b/tests/bsim/bluetooth/mesh/src/test_access.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_access.c rename to tests/bsim/bluetooth/mesh/src/test_access.c diff --git a/tests/bluetooth/bsim/mesh/src/test_advertiser.c b/tests/bsim/bluetooth/mesh/src/test_advertiser.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_advertiser.c rename to tests/bsim/bluetooth/mesh/src/test_advertiser.c diff --git a/tests/bluetooth/bsim/mesh/src/test_beacon.c b/tests/bsim/bluetooth/mesh/src/test_beacon.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_beacon.c rename to tests/bsim/bluetooth/mesh/src/test_beacon.c diff --git a/tests/bluetooth/bsim/mesh/src/test_blob.c b/tests/bsim/bluetooth/mesh/src/test_blob.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_blob.c rename to tests/bsim/bluetooth/mesh/src/test_blob.c diff --git a/tests/bluetooth/bsim/mesh/src/test_dfu.c b/tests/bsim/bluetooth/mesh/src/test_dfu.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_dfu.c rename to tests/bsim/bluetooth/mesh/src/test_dfu.c diff --git a/tests/bluetooth/bsim/mesh/src/test_friendship.c b/tests/bsim/bluetooth/mesh/src/test_friendship.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_friendship.c rename to tests/bsim/bluetooth/mesh/src/test_friendship.c diff --git a/tests/bluetooth/bsim/mesh/src/test_heartbeat.c b/tests/bsim/bluetooth/mesh/src/test_heartbeat.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_heartbeat.c rename to tests/bsim/bluetooth/mesh/src/test_heartbeat.c diff --git a/tests/bluetooth/bsim/mesh/src/test_iv_index.c b/tests/bsim/bluetooth/mesh/src/test_iv_index.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_iv_index.c rename to tests/bsim/bluetooth/mesh/src/test_iv_index.c diff --git a/tests/bluetooth/bsim/mesh/src/test_lcd.c b/tests/bsim/bluetooth/mesh/src/test_lcd.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_lcd.c rename to tests/bsim/bluetooth/mesh/src/test_lcd.c diff --git a/tests/bluetooth/bsim/mesh/src/test_op_agg.c b/tests/bsim/bluetooth/mesh/src/test_op_agg.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_op_agg.c rename to tests/bsim/bluetooth/mesh/src/test_op_agg.c diff --git a/tests/bluetooth/bsim/mesh/src/test_persistence.c b/tests/bsim/bluetooth/mesh/src/test_persistence.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_persistence.c rename to tests/bsim/bluetooth/mesh/src/test_persistence.c diff --git a/tests/bluetooth/bsim/mesh/src/test_provision.c b/tests/bsim/bluetooth/mesh/src/test_provision.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_provision.c rename to tests/bsim/bluetooth/mesh/src/test_provision.c diff --git a/tests/bluetooth/bsim/mesh/src/test_replay_cache.c b/tests/bsim/bluetooth/mesh/src/test_replay_cache.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_replay_cache.c rename to tests/bsim/bluetooth/mesh/src/test_replay_cache.c diff --git a/tests/bluetooth/bsim/mesh/src/test_sar.c b/tests/bsim/bluetooth/mesh/src/test_sar.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_sar.c rename to tests/bsim/bluetooth/mesh/src/test_sar.c diff --git a/tests/bluetooth/bsim/mesh/src/test_scanner.c b/tests/bsim/bluetooth/mesh/src/test_scanner.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_scanner.c rename to tests/bsim/bluetooth/mesh/src/test_scanner.c diff --git a/tests/bluetooth/bsim/mesh/src/test_transport.c b/tests/bsim/bluetooth/mesh/src/test_transport.c similarity index 100% rename from tests/bluetooth/bsim/mesh/src/test_transport.c rename to tests/bsim/bluetooth/mesh/src/test_transport.c diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_cancel.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_cancel.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/access/access_cancel.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/access/access_cancel.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_ext_sub.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_ext_sub.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/access/access_ext_sub.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/access/access_ext_sub.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_ext_sub_cap.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_ext_sub_cap.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/access/access_ext_sub_cap.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/access/access_ext_sub_cap.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_period.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_period.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/access/access_period.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/access/access_period.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_transmit.sh b/tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/access/access_transmit.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/access/access_transmit.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/proxy_mixin.sh b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/proxy_mixin.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/advertiser/proxy_mixin.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/advertiser/proxy_mixin.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/random_order.sh b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/random_order.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/advertiser/random_order.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/advertiser/random_order.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/reverse_order.sh b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/reverse_order.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/advertiser/reverse_order.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/advertiser/reverse_order.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/send_order.sh b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/send_order.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/advertiser/send_order.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/advertiser/send_order.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/tx_cb_multi.sh b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/tx_cb_multi.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/advertiser/tx_cb_multi.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/advertiser/tx_cb_multi.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/tx_cb_single.sh b/tests/bsim/bluetooth/mesh/tests_scripts/advertiser/tx_cb_single.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/advertiser/tx_cb_single.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/advertiser/tx_cb_single.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/beacon_interval.sh b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/beacon_interval.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/beacon/beacon_interval.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/beacon/beacon_interval.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/invalid.sh b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/invalid.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/beacon/invalid.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/beacon/invalid.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/iv_update.sh b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/iv_update.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/beacon/iv_update.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/beacon/iv_update.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/key_refresh.sh b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/key_refresh.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/beacon/key_refresh.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/beacon/key_refresh.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/kr_old_key.sh b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/kr_old_key.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/beacon/kr_old_key.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/beacon/kr_old_key.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/multiple_netkeys.sh b/tests/bsim/bluetooth/mesh/tests_scripts/beacon/multiple_netkeys.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/beacon/multiple_netkeys.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/beacon/multiple_netkeys.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_broadcast.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_broadcast.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_broadcast.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_caps.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_caps.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_caps.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer_pull.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer_pull.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer_pull.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer_pull.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_pull.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_pull.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_pull.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_pull.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_push.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_push.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_push.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_push.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_pull.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_pull.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_pull.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_pull.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_push.sh b/tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_push.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_push.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_push.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_cli_persistent_transfer.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_persistent_transfer.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_cli_persistent_transfer.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_cli_persistent_transfer.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_dist_self_update.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_dist_self_update.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_dist_self_update.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_dist_self_update.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_dist_self_update_mult_targets.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_dist_self_update_mult_targets.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_dist_self_update_mult_targets.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_dist_self_update_mult_targets.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_mixed.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_mixed.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_mixed.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_mixed.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_mixed_fail.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_mixed_fail.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_mixed_fail.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_mixed_fail.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_slot.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_slot.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_slot.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/establish.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/establish.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/friendship/establish.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/friendship/establish.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/establish_multi.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/establish_multi.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/friendship/establish_multi.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/friendship/establish_multi.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_disable.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_disable.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_disable.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_disable.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_loopback.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_loopback.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_loopback.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_loopback.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_terminate_cb.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_terminate_cb.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_terminate_cb.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/friendship/lpn_terminate_cb.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_frnd.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_frnd.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_frnd.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_frnd.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_group.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_group.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_group.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_group.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_mesh.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_mesh.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_mesh.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_mesh.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_mesh_low_lat.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_mesh_low_lat.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_mesh_low_lat.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/friendship/msg_mesh_low_lat.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/overflow.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/overflow.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/friendship/overflow.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/friendship/overflow.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/poll.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/poll.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/friendship/poll.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/friendship/poll.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/re-establish.sh b/tests/bsim/bluetooth/mesh/tests_scripts/friendship/re-establish.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/friendship/re-establish.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/friendship/re-establish.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/heartbeat/sub_cb_api_all.sh b/tests/bsim/bluetooth/mesh/tests_scripts/heartbeat/sub_cb_api_all.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/heartbeat/sub_cb_api_all.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/heartbeat/sub_cb_api_all.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/heartbeat/sub_cb_api_unicast.sh b/tests/bsim/bluetooth/mesh/tests_scripts/heartbeat/sub_cb_api_unicast.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/heartbeat/sub_cb_api_unicast.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/heartbeat/sub_cb_api_unicast.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_deferring.sh b/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_deferring.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_deferring.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_deferring.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_recovery.sh b/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_recovery.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_recovery.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_recovery.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_update.sh b/tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_update.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_update.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/iv_index/iv_update.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_comp_data_max_sdu.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp_data_max_sdu.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_comp_data_max_sdu.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp_data_max_sdu.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_comp_data_split.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp_data_split.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_comp_data_split.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_comp_data_split.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_metadata_max_sdu.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_metadata_max_sdu.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_metadata_max_sdu.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_metadata_max_sdu.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_metadata_split.sh b/tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_metadata_split.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_metadata_split.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/large_comp_data/get_metadata_split.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/op_agg/full_status_msg_list.sh b/tests/bsim/bluetooth/mesh/tests_scripts/op_agg/full_status_msg_list.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/op_agg/full_status_msg_list.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/op_agg/full_status_msg_list.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/persistence/access.sh b/tests/bsim/bluetooth/mesh/tests_scripts/persistence/access.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/persistence/access.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/persistence/access.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/persistence/cfg.sh b/tests/bsim/bluetooth/mesh/tests_scripts/persistence/cfg.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/persistence/cfg.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/persistence/cfg.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/persistence/provisioning.sh b/tests/bsim/bluetooth/mesh/tests_scripts/persistence/provisioning.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/persistence/provisioning.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/persistence/provisioning.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/persistence/reprovisioning.sh b/tests/bsim/bluetooth/mesh/tests_scripts/persistence/reprovisioning.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/persistence/reprovisioning.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/persistence/reprovisioning.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/ivu_flag_one_duration.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/ivu_flag_one_duration.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/provision/ivu_flag_one_duration.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/provision/ivu_flag_one_duration.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/ivu_flag_zero_duration.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/ivu_flag_zero_duration.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/provision/ivu_flag_zero_duration.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/provision/ivu_flag_zero_duration.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_multi.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_multi.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_multi.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_multi.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_no_oob.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_no_oob.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_no_oob.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_no_oob.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_ib_pk.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_ib_pk.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_ib_pk.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_ib_pk.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_ignore_oob_pk.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_ignore_oob_pk.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_ignore_oob_pk.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_ignore_oob_pk.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_oob_pk.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_oob_pk.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_oob_pk.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_oob_auth_oob_pk.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_reprovision.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_reprovision.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_reprovision.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_adv_reprovision.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_nppi_robustness.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_nppi_robustness.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_nppi_robustness.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_nppi_robustness.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_pst_ncrp.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_pst_ncrp.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_pst_ncrp.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_pst_ncrp.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_reprovision.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_reprovision.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_reprovision.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_reprovision.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/replay_cache/replay_attack.sh b/tests/bsim/bluetooth/mesh/tests_scripts/replay_cache/replay_attack.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/replay_cache/replay_attack.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/replay_cache/replay_attack.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/replay_cache/rpl_frag.sh b/tests/bsim/bluetooth/mesh/tests_scripts/replay_cache/rpl_frag.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/replay_cache/rpl_frag.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/replay_cache/rpl_frag.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/sar/slow_transfer_test.sh b/tests/bsim/bluetooth/mesh/tests_scripts/sar/slow_transfer_test.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/sar/slow_transfer_test.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/sar/slow_transfer_test.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/sar/stress_test.sh b/tests/bsim/bluetooth/mesh/tests_scripts/sar/stress_test.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/sar/stress_test.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/sar/stress_test.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/scanner/invalid_ad_type.sh b/tests/bsim/bluetooth/mesh/tests_scripts/scanner/invalid_ad_type.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/scanner/invalid_ad_type.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/scanner/invalid_ad_type.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/scanner/wrong_packet_length.sh b/tests/bsim/bluetooth/mesh/tests_scripts/scanner/wrong_packet_length.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/scanner/wrong_packet_length.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/scanner/wrong_packet_length.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/group.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/group.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/transport/group.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/transport/group.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback_group.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback_group.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback_group.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback_group.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback_group_low_lat.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback_group_low_lat.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback_group_low_lat.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/transport/loopback_group_low_lat.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_block.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_block.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_block.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_block.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_concurrent.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_concurrent.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_concurrent.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_concurrent.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_fail.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_fail.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_fail.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_fail.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_ivu.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_ivu.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_ivu.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/transport/seg_ivu.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/unicast.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/unicast.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/transport/unicast.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/transport/unicast.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/unicast_low_lat.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/unicast_low_lat.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/transport/unicast_low_lat.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/transport/unicast_low_lat.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/unknown_app.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/unknown_app.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/transport/unknown_app.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/transport/unknown_app.sh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/va.sh b/tests/bsim/bluetooth/mesh/tests_scripts/transport/va.sh similarity index 100% rename from tests/bluetooth/bsim/mesh/tests_scripts/transport/va.sh rename to tests/bsim/bluetooth/mesh/tests_scripts/transport/va.sh diff --git a/tests/bluetooth/bsim/run_parallel.sh b/tests/bsim/bluetooth/run_parallel.sh similarity index 100% rename from tests/bluetooth/bsim/run_parallel.sh rename to tests/bsim/bluetooth/run_parallel.sh diff --git a/tests/bluetooth/bsim/sh_common.source b/tests/bsim/bluetooth/sh_common.source similarity index 100% rename from tests/bluetooth/bsim/sh_common.source rename to tests/bsim/bluetooth/sh_common.source From 459935c09d069b5015e2623627d9a526f10a3ed5 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Sun, 12 Mar 2023 00:54:25 +0000 Subject: [PATCH 0368/1906] doc: west: fix WestCommand self.configuration -> self.config WestCommand has no .configuration field, it's .config. In the same (and cursed!) sentence, also fix the broken link to west.command.WestCommand by switching the link target from the unusual `py:class::` to the common `autoclass::` used by all other classes in the same page. I don't understand why that fixes the hyperlink but it works and it's consistent. Signed-off-by: Marc Herbert --- doc/develop/west/west-apis.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/develop/west/west-apis.rst b/doc/develop/west/west-apis.rst index 92eb8e7bf5d0..e3e7e3935667 100644 --- a/doc/develop/west/west-apis.rst +++ b/doc/develop/west/west-apis.rst @@ -34,7 +34,7 @@ provided. WestCommand =========== -.. py:class:: west.commands.WestCommand +.. autoclass:: west.commands.WestCommand Instance attributes: @@ -223,7 +223,7 @@ Since west v0.13, the recommended class for reading this is :py:class:`west.configuration.Configuration`. Note that if you are writing a :ref:`west extension `, you can -access the current ``Configuration`` object as ``self.configuration``. See +access the current ``Configuration`` object as ``self.config``. See :py:class:`west.commands.WestCommand`. Configuration API From d21559d23974e439876f9d639ea3052051f84828 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 17 Mar 2023 18:06:58 +0100 Subject: [PATCH 0369/1906] ci: bluetooth worflow: Do not install parallel Parallel is already installed in the docker image. Let's save a few seconds in each CI run. Signed-off-by: Alberto Escolar Piedras --- .github/workflows/bluetooth-tests.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/bluetooth-tests.yaml b/.github/workflows/bluetooth-tests.yaml index 6a059407c814..36553b38a01e 100644 --- a/.github/workflows/bluetooth-tests.yaml +++ b/.github/workflows/bluetooth-tests.yaml @@ -67,12 +67,6 @@ jobs: west update --path-cache /github/cache/zephyrproject 2>&1 1> west.update.log || west update --path-cache /github/cache/zephyrproject 2>&1 1> west.update.log || ( rm -rf ../modules ../bootloader ../tools && west update --path-cache /github/cache/zephyrproject) west forall -c 'git reset --hard HEAD' - - name: Install parallel - run: | - sudo apt-get update - sudo apt-get install -y parallel - parallel --version - - name: Run Bluetooth Tests with BSIM run: | export ZEPHYR_BASE=${PWD} From e701ec5efce8c9f5799c9616051ae99891c07c87 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Sun, 19 Mar 2023 03:39:12 +0900 Subject: [PATCH 0370/1906] ci: assigner: Use ubuntu-22.04 virtual environment This commit updates the pull request assigner workflow to use the Ubuntu 22.04 virtual environment. Signed-off-by: Stephanos Ioannidis --- .github/workflows/assigner.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/assigner.yml b/.github/workflows/assigner.yml index 6508cf7ec865..872931590563 100644 --- a/.github/workflows/assigner.yml +++ b/.github/workflows/assigner.yml @@ -15,7 +15,7 @@ jobs: assignment: name: Pull Request Assignment if: github.event.pull_request.draft == false - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Install Python dependencies From 44a8b70cccafe312a1a091de48a5ba204dadd6bb Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Sun, 19 Mar 2023 03:41:01 +0900 Subject: [PATCH 0371/1906] ci: manifest: Use ubuntu-22.04 virtual environment This commit updates the manifest workflow to use the Ubuntu 22.04 virtual environment. Signed-off-by: Stephanos Ioannidis --- .github/workflows/manifest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/manifest.yml b/.github/workflows/manifest.yml index edec1cb0d31b..1ea0031fb564 100644 --- a/.github/workflows/manifest.yml +++ b/.github/workflows/manifest.yml @@ -4,7 +4,7 @@ on: jobs: contribs: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 name: Manifest steps: - name: Checkout the code From 00ded3346c5edd9aafb71e7aca172bfdaf6dc5fb Mon Sep 17 00:00:00 2001 From: Joel Guittet Date: Fri, 10 Mar 2023 10:30:04 +0100 Subject: [PATCH 0372/1906] bindings: add grove header Add bindind support for Grove header. Signed-off-by: Joel Guittet --- dts/bindings/gpio/grove-header.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 dts/bindings/gpio/grove-header.yaml diff --git a/dts/bindings/gpio/grove-header.yaml b/dts/bindings/gpio/grove-header.yaml new file mode 100644 index 000000000000..eaaec78baff4 --- /dev/null +++ b/dts/bindings/gpio/grove-header.yaml @@ -0,0 +1,17 @@ +# Copyright (c) 2023 Joel Guittet +# SPDX-License-Identifier: Apache-2.0 + +description: | + GPIO pins exposing on Grove 4 pins headers. + + This binding provides a nexus mapping for 2 pins as depicted below. + + 0 SCL/RXD/A/IN + 1 SDA/TXD/B/OUT + - VCC + - GND + + +compatible: "grove-header" + +include: [gpio-nexus.yaml, base.yaml] From ec6122cd98beafe05a0910bac2df09f1688ef4d9 Mon Sep 17 00:00:00 2001 From: Joel Guittet Date: Fri, 10 Mar 2023 10:30:27 +0100 Subject: [PATCH 0373/1906] wio terminal: add grove headers Add Grove headers to the Wio Terminal board. Signed-off-by: Joel Guittet --- boards/arm/wio_terminal/grove_connectors.dtsi | 25 +++++++++++++++++++ boards/arm/wio_terminal/wio_terminal.dts | 1 + 2 files changed, 26 insertions(+) create mode 100644 boards/arm/wio_terminal/grove_connectors.dtsi diff --git a/boards/arm/wio_terminal/grove_connectors.dtsi b/boards/arm/wio_terminal/grove_connectors.dtsi new file mode 100644 index 000000000000..c8c213ac79a0 --- /dev/null +++ b/boards/arm/wio_terminal/grove_connectors.dtsi @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Joel Guittet + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + grove_header0: grove_header0 { + compatible = "grove-header"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <0 0 &portb 8 0>, /* A0/D0 */ + <1 0 &portb 9 0>; /* A1/D1 */ + }; + grove_header1: grove_header1 { + compatible = "grove-header"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <0 0 &porta 16 0>, /* I2C1_SCL */ + <1 0 &porta 17 0>; /* I2C1_SDA */ + }; +}; + +grove_i2c1: &sercom3 {}; diff --git a/boards/arm/wio_terminal/wio_terminal.dts b/boards/arm/wio_terminal/wio_terminal.dts index 377c296b6202..32b63554b28d 100644 --- a/boards/arm/wio_terminal/wio_terminal.dts +++ b/boards/arm/wio_terminal/wio_terminal.dts @@ -6,6 +6,7 @@ /dts-v1/; #include #include "wio_terminal-pinctrl.dtsi" +#include "grove_connectors.dtsi" #include "raspberrypi_40pins_connector.dtsi" #include From abb93d4089bf195a7e78d90a0960ef8e0b119d9a Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Fri, 7 Jan 2022 15:46:45 +0000 Subject: [PATCH 0374/1906] fs: Prevent mounting file system re-using private data The commit changes the fs_mount to not allow mounting same system, with the same private data pointer, at two different mount paths. Signed-off-by: Dominik Ermel --- subsys/fs/fs.c | 6 ++++ tests/subsys/fs/fs_api/src/test_fs_dir_file.c | 33 ++++++++++++++----- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/subsys/fs/fs.c b/subsys/fs/fs.c index f8460dc3cb67..94b7c918c31e 100644 --- a/subsys/fs/fs.c +++ b/subsys/fs/fs.c @@ -677,6 +677,12 @@ int fs_mount(struct fs_mount_t *mp) continue; } + CHECKIF(mp->fs_data == itr->fs_data) { + LOG_ERR("file system already mounted!!"); + rc = -EBUSY; + goto mount_err; + } + if (strncmp(mp->mnt_point, itr->mnt_point, len) == 0) { LOG_ERR("mount point already exists!!"); rc = -EBUSY; diff --git a/tests/subsys/fs/fs_api/src/test_fs_dir_file.c b/tests/subsys/fs/fs_api/src/test_fs_dir_file.c index 82ed483bfac6..3b8232714a15 100644 --- a/tests/subsys/fs/fs_api/src/test_fs_dir_file.c +++ b/tests/subsys/fs/fs_api/src/test_fs_dir_file.c @@ -19,59 +19,72 @@ #include struct fs_file_system_t null_fs = {NULL}; -static struct test_fs_data test_data; +static struct test_fs_data test_data; static struct fs_mount_t test_fs_mnt_1 = { .type = TEST_FS_1, .mnt_point = TEST_FS_MNTP, .fs_data = &test_data, }; +static struct fs_mount_t test_fs_mnt_already_mounted_same_data = { + .type = TEST_FS_2, + .mnt_point = "/OTHER", + .fs_data = &test_data, +}; + +static struct test_fs_data test_data1; static struct fs_mount_t test_fs_mnt_unsupported_fs = { .type = FS_TYPE_EXTERNAL_BASE, .mnt_point = "/MMCBLOCK:", - .fs_data = &test_data, + .fs_data = &test_data1, }; /* invalid name of mount point, not start with '/' */ +static struct test_fs_data test_data2; static struct fs_mount_t test_fs_mnt_invalid_root_1 = { .type = TEST_FS_2, .mnt_point = "SDA:", - .fs_data = &test_data, + .fs_data = &test_data2, }; /* length of the name of mount point is too short */ +static struct test_fs_data test_data3; static struct fs_mount_t test_fs_mnt_invalid_root_2 = { .type = TEST_FS_2, .mnt_point = "/", - .fs_data = &test_data, + .fs_data = &test_data3, }; /* NULL mount point */ +static struct test_fs_data test_data4; static struct fs_mount_t test_fs_mnt_invalid_root_3 = { .type = TEST_FS_2, .mnt_point = NULL, - .fs_data = &test_data, + .fs_data = &test_data4, }; +static struct test_fs_data test_data5; static struct fs_mount_t test_fs_mnt_already_mounted = { .type = TEST_FS_2, .mnt_point = TEST_FS_MNTP, - .fs_data = &test_data, + .fs_data = &test_data5, }; /* for test_fs, name of mount point must end with ':' */ +static struct test_fs_data test_data6; static struct fs_mount_t test_fs_mnt_invalid_mntp = { .type = TEST_FS_2, .mnt_point = "/SDA", - .fs_data = &test_data, + .fs_data = &test_data6, }; #define NOOP_MNTP "/SDCD:" +static struct test_fs_data test_data7; static struct fs_mount_t test_fs_mnt_no_op = { .type = TEST_FS_2, .mnt_point = NOOP_MNTP, - .fs_data = &test_data, + .fs_data = &test_data7, }; static struct fs_file_t filep; @@ -148,6 +161,10 @@ void test_mount(void) ret = fs_mount(&test_fs_mnt_already_mounted); zassert_not_equal(ret, 0, "Mount to a mounted dir"); + TC_PRINT("Mount using same private data as already mounted system\n"); + ret = fs_mount(&test_fs_mnt_already_mounted_same_data); + zassert_equal(ret, -EBUSY, "Re-mount using same data should have failed"); + fs_unregister(TEST_FS_2, &temp_fs); memset(&null_fs, 0, sizeof(null_fs)); fs_register(TEST_FS_2, &null_fs); From 4eb7ff1fe79772a6256a888551dc140df4caedf0 Mon Sep 17 00:00:00 2001 From: Ryan McClelland Date: Wed, 23 Nov 2022 21:14:07 -0800 Subject: [PATCH 0375/1906] drivers: counter: add st,stm32-counter to stm32h7 The STM32H7 was missing definitions in it's devicetree include for the stm32-counter Signed-off-by: Ryan McClelland --- dts/arm/st/h7/stm32h7.dtsi | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/dts/arm/st/h7/stm32h7.dtsi b/dts/arm/st/h7/stm32h7.dtsi index 4dee62727c59..88a42636a6ce 100644 --- a/dts/arm/st/h7/stm32h7.dtsi +++ b/dts/arm/st/h7/stm32h7.dtsi @@ -528,6 +528,11 @@ status = "disabled"; #pwm-cells = <3>; }; + + counter { + compatible = "st,stm32-counter"; + status = "disabled"; + }; }; timers3: timers@40000400 { @@ -545,6 +550,11 @@ status = "disabled"; #pwm-cells = <3>; }; + + counter { + compatible = "st,stm32-counter"; + status = "disabled"; + }; }; timers4: timers@40000800 { @@ -562,6 +572,11 @@ status = "disabled"; #pwm-cells = <3>; }; + + counter { + compatible = "st,stm32-counter"; + status = "disabled"; + }; }; timers5: timers@40000c00 { @@ -579,6 +594,11 @@ status = "disabled"; #pwm-cells = <3>; }; + + counter { + compatible = "st,stm32-counter"; + status = "disabled"; + }; }; timers6: timers@40001000 { @@ -590,6 +610,11 @@ interrupt-names = "global"; st,prescaler = <0>; status = "disabled"; + + counter { + compatible = "st,stm32-counter"; + status = "disabled"; + }; }; timers7: timers@40001400 { @@ -601,6 +626,11 @@ interrupt-names = "global"; st,prescaler = <0>; status = "disabled"; + + counter { + compatible = "st,stm32-counter"; + status = "disabled"; + }; }; timers8: timers@40010400 { @@ -635,6 +665,11 @@ status = "disabled"; #pwm-cells = <3>; }; + + counter { + compatible = "st,stm32-counter"; + status = "disabled"; + }; }; timers13: timers@40001c00 { @@ -652,6 +687,11 @@ status = "disabled"; #pwm-cells = <3>; }; + + counter { + compatible = "st,stm32-counter"; + status = "disabled"; + }; }; timers14: timers@40002000 { @@ -669,6 +709,11 @@ status = "disabled"; #pwm-cells = <3>; }; + + counter { + compatible = "st,stm32-counter"; + status = "disabled"; + }; }; timers15: timers@40014000 { @@ -686,6 +731,11 @@ status = "disabled"; #pwm-cells = <3>; }; + + counter { + compatible = "st,stm32-counter"; + status = "disabled"; + }; }; timers16: timers@40014400 { @@ -703,6 +753,11 @@ status = "disabled"; #pwm-cells = <3>; }; + + counter { + compatible = "st,stm32-counter"; + status = "disabled"; + }; }; timers17: timers@40014800 { @@ -720,6 +775,11 @@ status = "disabled"; #pwm-cells = <3>; }; + + counter { + compatible = "st,stm32-counter"; + status = "disabled"; + }; }; lptim1: timers@40002400 { From 63652b38a16797fd5879066a683954e1b684a5c2 Mon Sep 17 00:00:00 2001 From: Ryan McClelland Date: Mon, 28 Nov 2022 17:40:04 -0800 Subject: [PATCH 0376/1906] tests: drivers: counter: basic_api: add overlay for stm32h747i_disco_m7 Add overlay for stm32h747i_disco_m7 to enable counter_basic_api tests on this board. The prescalers of the timers will result in a counter frequency of 1 MHz. Signed-off-by: Ryan McClelland --- .../boards/stm32h747i_disco_m7.overlay | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tests/drivers/counter/counter_basic_api/boards/stm32h747i_disco_m7.overlay diff --git a/tests/drivers/counter/counter_basic_api/boards/stm32h747i_disco_m7.overlay b/tests/drivers/counter/counter_basic_api/boards/stm32h747i_disco_m7.overlay new file mode 100644 index 000000000000..87d4899af112 --- /dev/null +++ b/tests/drivers/counter/counter_basic_api/boards/stm32h747i_disco_m7.overlay @@ -0,0 +1,87 @@ +&timers2 { + st,prescaler = <239>; + counter { + status = "okay"; + }; +}; + +&timers3 { + st,prescaler = <239>; + counter { + status = "okay"; + }; +}; + +&timers4 { + st,prescaler = <239>; + counter { + status = "okay"; + }; +}; + +&timers5 { + st,prescaler = <239>; + counter { + status = "okay"; + }; +}; + +&timers6 { + st,prescaler = <239>; + counter { + status = "okay"; + }; +}; + +&timers7 { + st,prescaler = <239>; + counter { + status = "okay"; + }; +}; + +&timers12 { + st,prescaler = <239>; + counter { + status = "okay"; + }; +}; + +&timers13 { + st,prescaler = <239>; + counter { + status = "okay"; + }; +}; + +&timers14 { + st,prescaler = <239>; + counter { + status = "okay"; + }; +}; + +&timers15 { + st,prescaler = <239>; + counter { + status = "okay"; + }; +}; + +&timers16 { + st,prescaler = <239>; + counter { + status = "okay"; + }; +}; + +&timers17 { + st,prescaler = <239>; + counter { + status = "okay"; + }; +}; + +&rtc { + status = "disabled"; +}; From cc1c3ac58eb72c84e8500e09fc694cb4155d760f Mon Sep 17 00:00:00 2001 From: Aleksander Wasaznik Date: Fri, 17 Mar 2023 10:01:19 +0100 Subject: [PATCH 0377/1906] Shell: Add missing include `include/zephyr/shell/shell_string_conv.h` uses `bool` from `stdbool.h`, but the include was missing. Signed-off-by: Aleksander Wasaznik --- include/zephyr/shell/shell_string_conv.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/zephyr/shell/shell_string_conv.h b/include/zephyr/shell/shell_string_conv.h index 4ecb992125eb..a38a5cc2ef9b 100644 --- a/include/zephyr/shell/shell_string_conv.h +++ b/include/zephyr/shell/shell_string_conv.h @@ -7,6 +7,7 @@ #ifndef SHELL_STRING_CONV_H__ #define SHELL_STRING_CONV_H__ +#include #include #ifdef __cplusplus From 6b6178be30c3f004bc21dfc15e38460b9d534f58 Mon Sep 17 00:00:00 2001 From: Aleksander Wasaznik Date: Tue, 17 Jan 2023 13:19:30 +0100 Subject: [PATCH 0378/1906] Bluetooth: Shell: Make `gatt notify` more general Make `gatt notify` take the source handle and the data to send. Signed-off-by: Aleksander Wasaznik --- subsys/bluetooth/shell/gatt.c | 88 +++++++++++++++++++++++++--------- tests/bluetooth/shell/prj.conf | 3 ++ 2 files changed, 68 insertions(+), 23 deletions(-) diff --git a/subsys/bluetooth/shell/gatt.c b/subsys/bluetooth/shell/gatt.c index 21e43a586327..8fac8bdc6637 100644 --- a/subsys/bluetooth/shell/gatt.c +++ b/subsys/bluetooth/shell/gatt.c @@ -12,9 +12,12 @@ #include #include #include +#include #include #include +#include #include +#include #include #include @@ -561,7 +564,8 @@ static uint8_t notify_func(struct bt_conn *conn, return BT_GATT_ITER_STOP; } - shell_print(ctx_shell, "Notification: data %p length %u", data, length); + shell_print(ctx_shell, "Notification: length %u", length); + shell_hexdump(ctx_shell, data, length); return BT_GATT_ITER_CONTINUE; } @@ -946,43 +950,81 @@ static int cmd_unregister_test_svc(const struct shell *sh, return 0; } -static void notify_cb(struct bt_conn *conn, void *user_data) +static uint8_t found_attr(const struct bt_gatt_attr *attr, uint16_t handle, + void *user_data) { - const struct shell *sh = user_data; + const struct bt_gatt_attr **found = user_data; - shell_print(sh, "Nofication sent to conn %p", conn); + *found = attr; + + return BT_GATT_ITER_STOP; +} + +static const struct bt_gatt_attr *find_attr(uint16_t handle) +{ + const struct bt_gatt_attr *attr = NULL; + + bt_gatt_foreach_attr(handle, handle, found_attr, &attr); + + return attr; } static int cmd_notify(const struct shell *sh, size_t argc, char *argv[]) { - struct bt_gatt_notify_params params; - uint8_t data = 0; + const struct bt_gatt_attr *attr; + int err; + size_t data_len; + unsigned long handle; + static char data[CHAR_SIZE_MAX]; - if (!echo_enabled) { - shell_error(sh, "No clients have enabled notifications for the vnd1_echo CCC."); - return -ENOEXEC; - } + const char *arg_handle = argv[1]; + const char *arg_data = argv[2]; + size_t arg_data_len = strlen(arg_data); - if (argc > 1) { - data = strtoul(argv[1], NULL, 16); + err = 0; + handle = shell_strtoul(arg_handle, 16, &err); + if (err) { + shell_error(sh, "Handle '%s': Not a valid hex number.", arg_handle); + return -EINVAL; + } + + if (!IN_RANGE(handle, BT_ATT_FIRST_ATTRIBUTE_HANDLE, BT_ATT_LAST_ATTRIBUTE_HANDLE)) { + shell_error(sh, "Handle 0x%lx: Impossible value.", handle); + return -EINVAL; } - memset(¶ms, 0, sizeof(params)); + if ((arg_data_len / 2) > CHAR_SIZE_MAX) { + shell_error(sh, "Data: Size exceeds legal attribute size."); + return -EINVAL; + } + + data_len = hex2bin(arg_data, arg_data_len, data, sizeof(data)); + if (data_len == 0 && arg_data_len != 0) { + shell_error(sh, "Data: Bad hex."); + return -EINVAL; + } - params.uuid = &vnd1_echo_uuid.uuid; - params.attr = vnd1_attrs; - params.data = &data; - params.len = sizeof(data); - params.func = notify_cb; - params.user_data = (void *)sh; - SET_CHAN_OPT_ANY(params); + attr = find_attr(handle); + if (!attr) { + shell_error(sh, "Handle 0x%lx: Local attribute not found.", handle); + return -EINVAL; + } - bt_gatt_notify_cb(NULL, ¶ms); + err = bt_gatt_notify(NULL, attr, data, data_len); + if (err) { + shell_error(sh, "bt_gatt_notify errno %d (%s)", -err, strerror(-err)); + } - return 0; + return err; } #if defined(CONFIG_BT_GATT_NOTIFY_MULTIPLE) +static void notify_cb(struct bt_conn *conn, void *user_data) +{ + const struct shell *sh = user_data; + + shell_print(sh, "Nofication sent to conn %p", conn); +} static int cmd_notify_mult(const struct shell *sh, size_t argc, char *argv[]) { const size_t max_cnt = CONFIG_BT_L2CAP_TX_BUF_COUNT; @@ -1294,7 +1336,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(gatt_cmds, SHELL_CMD_ARG(unregister, NULL, "unregister pre-predefined test service", cmd_unregister_test_svc, 1, 0), - SHELL_CMD_ARG(notify, NULL, "[data]", cmd_notify, 1, 1), + SHELL_CMD_ARG(notify, NULL, " ", cmd_notify, 3, 0), #if defined(CONFIG_BT_GATT_NOTIFY_MULTIPLE) SHELL_CMD_ARG(notify-mult, NULL, "count [data]", cmd_notify_mult, 2, 1), #endif /* CONFIG_BT_GATT_NOTIFY_MULTIPLE */ diff --git a/tests/bluetooth/shell/prj.conf b/tests/bluetooth/shell/prj.conf index 665bf936a1ae..e7657ddc8b87 100644 --- a/tests/bluetooth/shell/prj.conf +++ b/tests/bluetooth/shell/prj.conf @@ -62,3 +62,6 @@ CONFIG_BT_ISO_PERIPHERAL=y # kernel log-level bt_l2cap 2 # kernel log-level bt_att 4 CONFIG_LOG_RUNTIME_FILTERING=y + +# Errno message table. Disable to save ROM. +CONFIG_MINIMAL_LIBC_STRING_ERROR_TABLE=y From 20d747815df88b65b746455c756cf70d026b0073 Mon Sep 17 00:00:00 2001 From: Aleksander Wasaznik Date: Thu, 16 Mar 2023 15:26:33 +0100 Subject: [PATCH 0379/1906] Bluetooth: Shell: Remove ad-hoc `CHAR_SIZE_MAX` Remove ad-hoc `CHAR_SIZE_MAX` in favor of `BT_ATT_MAX_ATTRIBUTE_LEN`. The maximum size of an attribute is the same as the maximum size of a characteristic. Signed-off-by: Aleksander Wasaznik --- subsys/bluetooth/shell/gatt.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/subsys/bluetooth/shell/gatt.c b/subsys/bluetooth/shell/gatt.c index 8fac8bdc6637..13e3f6fa05a3 100644 --- a/subsys/bluetooth/shell/gatt.c +++ b/subsys/bluetooth/shell/gatt.c @@ -28,8 +28,6 @@ #include "bt.h" -#define CHAR_SIZE_MAX 512 - #if defined(CONFIG_BT_GATT_CLIENT) || defined(CONFIG_BT_GATT_DYNAMIC_DB) extern uint8_t selected_id; @@ -426,7 +424,7 @@ static int cmd_read_uuid(const struct shell *sh, size_t argc, char *argv[]) } static struct bt_gatt_write_params write_params; -static uint8_t gatt_write_buf[CHAR_SIZE_MAX]; +static uint8_t gatt_write_buf[BT_ATT_MAX_ATTRIBUTE_LEN]; static void write_func(struct bt_conn *conn, uint8_t err, struct bt_gatt_write_params *params) @@ -975,7 +973,7 @@ static int cmd_notify(const struct shell *sh, size_t argc, char *argv[]) int err; size_t data_len; unsigned long handle; - static char data[CHAR_SIZE_MAX]; + static char data[BT_ATT_MAX_ATTRIBUTE_LEN]; const char *arg_handle = argv[1]; const char *arg_data = argv[2]; @@ -987,17 +985,17 @@ static int cmd_notify(const struct shell *sh, size_t argc, char *argv[]) shell_error(sh, "Handle '%s': Not a valid hex number.", arg_handle); return -EINVAL; } - + if (!IN_RANGE(handle, BT_ATT_FIRST_ATTRIBUTE_HANDLE, BT_ATT_LAST_ATTRIBUTE_HANDLE)) { shell_error(sh, "Handle 0x%lx: Impossible value.", handle); return -EINVAL; } - if ((arg_data_len / 2) > CHAR_SIZE_MAX) { + if ((arg_data_len / 2) > BT_ATT_MAX_ATTRIBUTE_LEN) { shell_error(sh, "Data: Size exceeds legal attribute size."); return -EINVAL; } - + data_len = hex2bin(arg_data, arg_data_len, data, sizeof(data)); if (data_len == 0 && arg_data_len != 0) { shell_error(sh, "Data: Bad hex."); @@ -1099,7 +1097,7 @@ static struct bt_uuid_128 met_svc_uuid = BT_UUID_INIT_128( static const struct bt_uuid_128 met_char_uuid = BT_UUID_INIT_128( BT_UUID_128_ENCODE(0x12345678, 0x1234, 0x5678, 0x1234, 0x56789abcde02)); -static uint8_t met_char_value[CHAR_SIZE_MAX] = { +static uint8_t met_char_value[BT_ATT_MAX_ATTRIBUTE_LEN] = { 'M', 'e', 't', 'r', 'i', 'c', 's' }; static ssize_t read_met(struct bt_conn *conn, const struct bt_gatt_attr *attr, @@ -1108,7 +1106,7 @@ static ssize_t read_met(struct bt_conn *conn, const struct bt_gatt_attr *attr, const char *value = attr->user_data; uint16_t value_len; - value_len = MIN(strlen(value), CHAR_SIZE_MAX); + value_len = MIN(strlen(value), BT_ATT_MAX_ATTRIBUTE_LEN); return bt_gatt_attr_read(conn, attr, buf, len, offset, value, value_len); From 7a85983ebcf283b521331695fc80a49c623cc395 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Tue, 7 Mar 2023 15:29:00 +0100 Subject: [PATCH 0380/1906] xtensa: remove ELF section address rewriting Now rimage can handle both cached and uncached addresses correctly, ELF rewriting isn't needed any more. Signed-off-by: Guennadi Liakhovetski --- soc/xtensa/intel_adsp/common/CMakeLists.txt | 4 -- soc/xtensa/intel_adsp/common/fix_elf_addrs.py | 51 ------------------- 2 files changed, 55 deletions(-) delete mode 100755 soc/xtensa/intel_adsp/common/fix_elf_addrs.py diff --git a/soc/xtensa/intel_adsp/common/CMakeLists.txt b/soc/xtensa/intel_adsp/common/CMakeLists.txt index c9ed156b891b..1d480f5a0f46 100644 --- a/soc/xtensa/intel_adsp/common/CMakeLists.txt +++ b/soc/xtensa/intel_adsp/common/CMakeLists.txt @@ -30,7 +30,6 @@ zephyr_library_link_libraries(INTEL_ADSP_COMMON) target_include_directories(INTEL_ADSP_COMMON INTERFACE include) target_link_libraries(INTEL_ADSP_COMMON INTERFACE intel_adsp_common) -set(ELF_FIX ${PYTHON_EXECUTABLE} ${SOC_DIR}/${ARCH}/${SOC_FAMILY}/common/fix_elf_addrs.py) set(KERNEL_REMAPPED ${CMAKE_BINARY_DIR}/zephyr/${KERNEL_NAME}-remapped.elf) set(EXTMAN ${CMAKE_BINARY_DIR}/zephyr/extman.bin) @@ -74,9 +73,6 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/zephyr/${KERNEL_NAME}.elf ${KERNEL_REMAPPED} - COMMAND ${ELF_FIX} ${CMAKE_OBJCOPY} ${KERNEL_REMAPPED} - ${CONFIG_XTENSA_CACHED_REGION} ${CONFIG_XTENSA_UNCACHED_REGION} - # Extract modules for rimage COMMAND ${CMAKE_OBJCOPY} --only-section .imr diff --git a/soc/xtensa/intel_adsp/common/fix_elf_addrs.py b/soc/xtensa/intel_adsp/common/fix_elf_addrs.py deleted file mode 100755 index c9a75e1dcd71..000000000000 --- a/soc/xtensa/intel_adsp/common/fix_elf_addrs.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (c) 2020-2022 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -# ADSP devices have their RAM regions mapped twice. The first mapping -# is set in the CPU to bypass the L1 cache, and so access through -# pointers in that region is coherent between CPUs (but slow). The -# second region accesses the same memory through the L1 cache and -# requires careful flushing when used with shared data. -# -# This distinction is exposed in the linker script, where some symbols -# (e.g. stack regions) are linked into cached memory, but others -# (general kernel memory) are not. But the rimage signing tool -# doesn't understand that and fails if regions aren't contiguous. -# -# Walk the sections in the ELF file, changing the VMA/LMA of each -# uncached section to the equivalent address in the cached area of -# memory. - -import os -import sys -from elftools.elf.elffile import ELFFile - -objcopy_bin = sys.argv[1] -elffile = sys.argv[2] -cached_reg = int(sys.argv[3]) -uncached_reg = int(sys.argv[4]) - -uc_min = uncached_reg << 29 -uc_max = uc_min | 0x1fffffff -cache_off = "0x%x" % ((cached_reg - uncached_reg) << 29) - -fixup =[] -with open(elffile, "rb") as fd: - elf = ELFFile(fd) - for s in elf.iter_sections(): - addr = s.header.sh_addr - if uc_min <= addr <= uc_max and s.header.sh_size != 0: - print(f"fix_elf_addrs.py: Moving section {s.name} to cached SRAM region") - fixup.append(s.name) - -for s in fixup: - # Note redirect: the sof-derived linker scripts currently emit - # some zero-length sections at address zero. This is benign, and - # the linker is happy, but objcopy will emit an unsilenceable - # error (no --quiet option, no -Werror=no-whatever, nothing). - # Just swallow the error stream for now pending rework to the - # linker framework. - cmd = f"{objcopy_bin} --change-section-address {s}+{cache_off} {elffile} 2>{os.devnull}" - os.system(cmd) From 2da26be77b0a51e7f7cf4c1a996b621f204350d5 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 15:52:21 -0600 Subject: [PATCH 0381/1906] drivers: sensor: Document sensor trigger pointer storage in API Updates the sensor driver API documentation to state that the driver will store the user-supplied sensor trigger as a pointer rather than a copy. Signed-off-by: Maureen Helm --- include/zephyr/drivers/sensor.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/zephyr/drivers/sensor.h b/include/zephyr/drivers/sensor.h index 0c864e3bea8f..e7f5ceba5bfe 100644 --- a/include/zephyr/drivers/sensor.h +++ b/include/zephyr/drivers/sensor.h @@ -474,6 +474,11 @@ static inline int z_impl_sensor_attr_get(const struct device *dev, * driver. It is currently up to the caller to ensure that the handler * does not overflow the stack. * + * The user-allocated trigger will be stored by the driver as a pointer, rather + * than a copy, and passed back to the handler. This enables the handler to use + * CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a + * larger struct and requires that the trigger is not allocated on the stack. + * * @funcprops \supervisor * * @param dev Pointer to the sensor device From 99ebc9f4a5e865847b730540fbc06ac916d1e817 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 15:59:15 -0600 Subject: [PATCH 0382/1906] doc: release: Document sensor driver API clarification for v3.4 Updates the release notes to document a clarification to the sensor driver API on sensor triggers. Signed-off-by: Maureen Helm --- doc/releases/release-notes-3.4.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/releases/release-notes-3.4.rst b/doc/releases/release-notes-3.4.rst index 8e22e0d138e0..818f7cf7811c 100644 --- a/doc/releases/release-notes-3.4.rst +++ b/doc/releases/release-notes-3.4.rst @@ -104,6 +104,14 @@ Changes in this release | :kconfig:option:`CONFIG_HWINFO` | +--------------------------------------------------+ +* The sensor driver API clarified :c:func:`sensor_trigger_set` to state that + the user-allocated sensor trigger will be stored by the driver as a pointer, + rather than a copy, and passed back to the handler. This enables the handler + to use :c:macro:`CONTAINER_OF` to retrieve a context pointer when the trigger + is embedded in a larger struct and requires that the trigger is not allocated + on the stack. Applications that allocate a sensor trigger on the stack need + to be updated. + Removed APIs in this release ============================ From ae5342afbac8a84588f4b74432989a82bf57b5a1 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 12:43:12 -0600 Subject: [PATCH 0383/1906] drivers: sensor: adt7420: Store sensor trigger as a pointer Fixes the adt7420 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/adt7420/adt7420.h | 2 +- drivers/sensor/adt7420/adt7420_trigger.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/sensor/adt7420/adt7420.h b/drivers/sensor/adt7420/adt7420.h index 3974c499a0f5..cd0ba7c4de0c 100644 --- a/drivers/sensor/adt7420/adt7420.h +++ b/drivers/sensor/adt7420/adt7420.h @@ -64,7 +64,7 @@ struct adt7420_data { struct gpio_callback gpio_cb; sensor_trigger_handler_t th_handler; - struct sensor_trigger th_trigger; + const struct sensor_trigger *th_trigger; const struct device *dev; diff --git a/drivers/sensor/adt7420/adt7420_trigger.c b/drivers/sensor/adt7420/adt7420_trigger.c index f26bf4939e86..895a8f33ed26 100644 --- a/drivers/sensor/adt7420/adt7420_trigger.c +++ b/drivers/sensor/adt7420/adt7420_trigger.c @@ -53,7 +53,7 @@ static void process_int(const struct device *dev) } if (drv_data->th_handler != NULL) { - drv_data->th_handler(dev, &drv_data->th_trigger); + drv_data->th_handler(dev, drv_data->th_trigger); } setup_int(dev, true); @@ -114,7 +114,7 @@ int adt7420_trigger_set(const struct device *dev, drv_data->th_handler = handler; if (handler != NULL) { - drv_data->th_trigger = *trig; + drv_data->th_trigger = trig; setup_int(dev, true); From cb51090d3a45ac032dc771fe48b53b40f212a47b Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 12:56:30 -0600 Subject: [PATCH 0384/1906] drivers: sensor: adxl362: Store sensor trigger as a pointer Fixes the adxl362 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/adxl362/adxl362.h | 6 +++--- drivers/sensor/adxl362/adxl362_trigger.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/sensor/adxl362/adxl362.h b/drivers/sensor/adxl362/adxl362.h index 2eadbb32703e..5dea56e107a7 100644 --- a/drivers/sensor/adxl362/adxl362.h +++ b/drivers/sensor/adxl362/adxl362.h @@ -198,11 +198,11 @@ struct adxl362_data { struct k_mutex trigger_mutex; sensor_trigger_handler_t inact_handler; - struct sensor_trigger inact_trigger; + const struct sensor_trigger *inact_trigger; sensor_trigger_handler_t act_handler; - struct sensor_trigger act_trigger; + const struct sensor_trigger *act_trigger; sensor_trigger_handler_t drdy_handler; - struct sensor_trigger drdy_trigger; + const struct sensor_trigger *drdy_trigger; #if defined(CONFIG_ADXL362_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_ADXL362_THREAD_STACK_SIZE); diff --git a/drivers/sensor/adxl362/adxl362_trigger.c b/drivers/sensor/adxl362/adxl362_trigger.c index 9147c57545f0..5ebe8739dd55 100644 --- a/drivers/sensor/adxl362/adxl362_trigger.c +++ b/drivers/sensor/adxl362/adxl362_trigger.c @@ -31,19 +31,19 @@ static void adxl362_thread_cb(const struct device *dev) k_mutex_lock(&drv_data->trigger_mutex, K_FOREVER); if (drv_data->inact_handler != NULL) { if (ADXL362_STATUS_CHECK_INACT(status_buf)) { - drv_data->inact_handler(dev, &drv_data->inact_trigger); + drv_data->inact_handler(dev, drv_data->inact_trigger); } } if (drv_data->act_handler != NULL) { if (ADXL362_STATUS_CHECK_ACTIVITY(status_buf)) { - drv_data->act_handler(dev, &drv_data->act_trigger); + drv_data->act_handler(dev, drv_data->act_trigger); } } if (drv_data->drdy_handler != NULL && ADXL362_STATUS_CHECK_DATA_READY(status_buf)) { - drv_data->drdy_handler(dev, &drv_data->drdy_trigger); + drv_data->drdy_handler(dev, drv_data->drdy_trigger); } k_mutex_unlock(&drv_data->trigger_mutex); } @@ -95,7 +95,7 @@ int adxl362_trigger_set(const struct device *dev, case SENSOR_TRIG_MOTION: k_mutex_lock(&drv_data->trigger_mutex, K_FOREVER); drv_data->act_handler = handler; - drv_data->act_trigger = *trig; + drv_data->act_trigger = trig; k_mutex_unlock(&drv_data->trigger_mutex); int_mask = ADXL362_INTMAP1_ACT; /* Clear activity and inactivity interrupts */ @@ -104,7 +104,7 @@ int adxl362_trigger_set(const struct device *dev, case SENSOR_TRIG_STATIONARY: k_mutex_lock(&drv_data->trigger_mutex, K_FOREVER); drv_data->inact_handler = handler; - drv_data->inact_trigger = *trig; + drv_data->inact_trigger = trig; k_mutex_unlock(&drv_data->trigger_mutex); int_mask = ADXL362_INTMAP1_INACT; /* Clear activity and inactivity interrupts */ @@ -113,7 +113,7 @@ int adxl362_trigger_set(const struct device *dev, case SENSOR_TRIG_DATA_READY: k_mutex_lock(&drv_data->trigger_mutex, K_FOREVER); drv_data->drdy_handler = handler; - drv_data->drdy_trigger = *trig; + drv_data->drdy_trigger = trig; k_mutex_unlock(&drv_data->trigger_mutex); int_mask = ADXL362_INTMAP1_DATA_READY; adxl362_clear_data_ready(dev); From a8b74ff5e7748983c3ed5108d822f1b5220c562b Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 12:57:27 -0600 Subject: [PATCH 0385/1906] drivers: sensor: adxl372: Store sensor trigger as a pointer Fixes the adxl372 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/adxl372/adxl372.h | 4 ++-- drivers/sensor/adxl372/adxl372_trigger.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/sensor/adxl372/adxl372.h b/drivers/sensor/adxl372/adxl372.h index 1a5c6862e59e..39d1959b2204 100644 --- a/drivers/sensor/adxl372/adxl372.h +++ b/drivers/sensor/adxl372/adxl372.h @@ -306,9 +306,9 @@ struct adxl372_data { struct gpio_callback gpio_cb; sensor_trigger_handler_t th_handler; - struct sensor_trigger th_trigger; + const struct sensor_trigger *th_trigger; sensor_trigger_handler_t drdy_handler; - struct sensor_trigger drdy_trigger; + const struct sensor_trigger *drdy_trigger; const struct device *dev; #if defined(CONFIG_ADXL372_TRIGGER_OWN_THREAD) diff --git a/drivers/sensor/adxl372/adxl372_trigger.c b/drivers/sensor/adxl372/adxl372_trigger.c index f9ce47dd5469..bde1ab6bc211 100644 --- a/drivers/sensor/adxl372/adxl372_trigger.c +++ b/drivers/sensor/adxl372/adxl372_trigger.c @@ -34,17 +34,17 @@ static void adxl372_thread_cb(const struct device *dev) */ if (cfg->max_peak_detect_mode && ADXL372_STATUS_2_INACT(status2)) { - drv_data->th_handler(dev, &drv_data->th_trigger); + drv_data->th_handler(dev, drv_data->th_trigger); } else if (!cfg->max_peak_detect_mode && (ADXL372_STATUS_2_INACT(status2) || ADXL372_STATUS_2_ACTIVITY(status2))) { - drv_data->th_handler(dev, &drv_data->th_trigger); + drv_data->th_handler(dev, drv_data->th_trigger); } } if ((drv_data->drdy_handler != NULL) && ADXL372_STATUS_1_DATA_RDY(status1)) { - drv_data->drdy_handler(dev, &drv_data->drdy_trigger); + drv_data->drdy_handler(dev, drv_data->drdy_trigger); } ret = gpio_pin_interrupt_configure_dt(&cfg->interrupt, @@ -105,13 +105,13 @@ int adxl372_trigger_set(const struct device *dev, switch (trig->type) { case SENSOR_TRIG_THRESHOLD: drv_data->th_handler = handler; - drv_data->th_trigger = *trig; + drv_data->th_trigger = trig; int_mask = ADXL372_INT1_MAP_ACT_MSK | ADXL372_INT1_MAP_INACT_MSK; break; case SENSOR_TRIG_DATA_READY: drv_data->drdy_handler = handler; - drv_data->drdy_trigger = *trig; + drv_data->drdy_trigger = trig; int_mask = ADXL372_INT1_MAP_DATA_RDY_MSK; break; default: From 9d74370e743fb07c61ba1bae6bf54e8170554b76 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 12:58:45 -0600 Subject: [PATCH 0386/1906] drivers: sensor: amg88xx: Store sensor trigger as a pointer Fixes the amg88xx sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/amg88xx/amg88xx.h | 4 ++-- drivers/sensor/amg88xx/amg88xx_trigger.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/sensor/amg88xx/amg88xx.h b/drivers/sensor/amg88xx/amg88xx.h index 38cf54b42f59..fbdd4e807fdf 100644 --- a/drivers/sensor/amg88xx/amg88xx.h +++ b/drivers/sensor/amg88xx/amg88xx.h @@ -81,10 +81,10 @@ struct amg88xx_data { struct gpio_callback gpio_cb; sensor_trigger_handler_t drdy_handler; - struct sensor_trigger drdy_trigger; + const struct sensor_trigger *drdy_trigger; sensor_trigger_handler_t th_handler; - struct sensor_trigger th_trigger; + const struct sensor_trigger *th_trigger; #if defined(CONFIG_AMG88XX_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_AMG88XX_THREAD_STACK_SIZE); diff --git a/drivers/sensor/amg88xx/amg88xx_trigger.c b/drivers/sensor/amg88xx/amg88xx_trigger.c index 8df8eb07f927..9afcbef39f36 100644 --- a/drivers/sensor/amg88xx/amg88xx_trigger.c +++ b/drivers/sensor/amg88xx/amg88xx_trigger.c @@ -102,11 +102,11 @@ static void amg88xx_thread_cb(const struct device *dev) } if (drv_data->drdy_handler != NULL) { - drv_data->drdy_handler(dev, &drv_data->drdy_trigger); + drv_data->drdy_handler(dev, drv_data->drdy_trigger); } if (drv_data->th_handler != NULL) { - drv_data->th_handler(dev, &drv_data->th_trigger); + drv_data->th_handler(dev, drv_data->th_trigger); } amg88xx_setup_int(config, true); @@ -151,7 +151,7 @@ int amg88xx_trigger_set(const struct device *dev, if (trig->type == SENSOR_TRIG_THRESHOLD) { drv_data->th_handler = handler; - drv_data->th_trigger = *trig; + drv_data->th_trigger = trig; } else { LOG_ERR("Unsupported sensor trigger"); return -ENOTSUP; From ad07044679c9f430aa9596f0317a06228fd1a262 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 13:02:46 -0600 Subject: [PATCH 0387/1906] drivers: sensor: bma280: Store sensor trigger as a pointer Fixes the bma280 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/bma280/bma280.h | 4 ++-- drivers/sensor/bma280/bma280_trigger.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/sensor/bma280/bma280.h b/drivers/sensor/bma280/bma280.h index 05d3573a6c3e..8857ade6fda6 100644 --- a/drivers/sensor/bma280/bma280.h +++ b/drivers/sensor/bma280/bma280.h @@ -123,10 +123,10 @@ struct bma280_data { const struct device *dev; struct gpio_callback gpio_cb; - struct sensor_trigger data_ready_trigger; + const struct sensor_trigger *data_ready_trigger; sensor_trigger_handler_t data_ready_handler; - struct sensor_trigger any_motion_trigger; + const struct sensor_trigger *any_motion_trigger; sensor_trigger_handler_t any_motion_handler; #if defined(CONFIG_BMA280_TRIGGER_OWN_THREAD) diff --git a/drivers/sensor/bma280/bma280_trigger.c b/drivers/sensor/bma280/bma280_trigger.c index 06125a4e66a9..7478483f05e8 100644 --- a/drivers/sensor/bma280/bma280_trigger.c +++ b/drivers/sensor/bma280/bma280_trigger.c @@ -99,7 +99,7 @@ static void bma280_thread_cb(const struct device *dev) drv_data->data_ready_handler != NULL && err == 0) { drv_data->data_ready_handler(dev, - &drv_data->data_ready_trigger); + drv_data->data_ready_trigger); } /* check for any motion */ @@ -109,7 +109,7 @@ static void bma280_thread_cb(const struct device *dev) drv_data->any_motion_handler != NULL && err == 0) { drv_data->any_motion_handler(dev, - &drv_data->data_ready_trigger); + drv_data->any_motion_trigger); /* clear latched interrupt */ err = i2c_reg_update_byte_dt(&config->i2c, @@ -170,7 +170,7 @@ int bma280_trigger_set(const struct device *dev, if (handler == NULL) { return 0; } - drv_data->data_ready_trigger = *trig; + drv_data->data_ready_trigger = trig; /* enable data ready interrupt */ if (i2c_reg_update_byte_dt(&config->i2c, @@ -193,7 +193,7 @@ int bma280_trigger_set(const struct device *dev, if (handler == NULL) { return 0; } - drv_data->any_motion_trigger = *trig; + drv_data->any_motion_trigger = trig; /* enable any-motion interrupt */ if (i2c_reg_update_byte_dt(&config->i2c, From 7875025cdb09c0f5bae41964ced9efff1e4e2fd9 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 13:03:35 -0600 Subject: [PATCH 0388/1906] drivers: sensor: bmc150_magn: Store sensor trigger as a pointer Fixes the bmc150_magn sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/bmc150_magn/bmc150_magn.h | 2 +- drivers/sensor/bmc150_magn/bmc150_magn_trigger.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/sensor/bmc150_magn/bmc150_magn.h b/drivers/sensor/bmc150_magn/bmc150_magn.h index 7a7ea67984c8..8056cc36ba99 100644 --- a/drivers/sensor/bmc150_magn/bmc150_magn.h +++ b/drivers/sensor/bmc150_magn/bmc150_magn.h @@ -120,7 +120,7 @@ struct bmc150_magn_data { const struct device *gpio_drdy; const struct device *dev; struct gpio_callback gpio_cb; - struct sensor_trigger trigger_drdy; + const struct sensor_trigger *trigger_drdy; sensor_trigger_handler_t handler_drdy; #endif diff --git a/drivers/sensor/bmc150_magn/bmc150_magn_trigger.c b/drivers/sensor/bmc150_magn/bmc150_magn_trigger.c index 017d0896bddf..dc21d1cbee3a 100644 --- a/drivers/sensor/bmc150_magn/bmc150_magn_trigger.c +++ b/drivers/sensor/bmc150_magn/bmc150_magn_trigger.c @@ -49,7 +49,7 @@ int bmc150_magn_trigger_set(const struct device *dev, } data->handler_drdy = handler; - data->trigger_drdy = *trig; + data->trigger_drdy = trig; if (i2c_reg_update_byte_dt(&config->i2c, BMC150_MAGN_REG_INT_DRDY, @@ -96,7 +96,7 @@ static void bmc150_magn_thread_main(struct bmc150_magn_data *data) } if (data->handler_drdy) { - data->handler_drdy(data->dev, &data->trigger_drdy); + data->handler_drdy(data->dev, data->trigger_drdy); } setup_drdy(data->dev, true); From 666a0dffd253c24d2237e3a698b0caee3e134ad2 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 13:07:09 -0600 Subject: [PATCH 0389/1906] drivers: sensor: bmg160: Store sensor trigger as a pointer Fixes the bmg160 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/bmg160/bmg160.h | 2 ++ drivers/sensor/bmg160/bmg160_trigger.c | 20 ++++++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/sensor/bmg160/bmg160.h b/drivers/sensor/bmg160/bmg160.h index da2103f945b3..fb5b7e477ca7 100644 --- a/drivers/sensor/bmg160/bmg160.h +++ b/drivers/sensor/bmg160/bmg160.h @@ -198,7 +198,9 @@ struct bmg160_device_data { #endif #ifdef CONFIG_BMG160_TRIGGER sensor_trigger_handler_t anymotion_handler; + const struct sensor_trigger *anymotion_trig; sensor_trigger_handler_t drdy_handler; + const struct sensor_trigger *drdy_trig; #endif int16_t raw_gyro_xyz[3]; uint16_t scale; diff --git a/drivers/sensor/bmg160/bmg160_trigger.c b/drivers/sensor/bmg160/bmg160_trigger.c index 95c1ae1b5463..ee3386bd74e3 100644 --- a/drivers/sensor/bmg160/bmg160_trigger.c +++ b/drivers/sensor/bmg160/bmg160_trigger.c @@ -45,6 +45,7 @@ static void bmg160_gpio_callback(const struct device *port, } static int bmg160_anymotion_set(const struct device *dev, + const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { struct bmg160_device_data *bmg160 = dev->data; @@ -62,11 +63,13 @@ static int bmg160_anymotion_set(const struct device *dev, } bmg160->anymotion_handler = handler; + bmg160->anymotion_trig = trig; return 0; } static int bmg160_drdy_set(const struct device *dev, + const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { struct bmg160_device_data *bmg160 = dev->data; @@ -78,6 +81,7 @@ static int bmg160_drdy_set(const struct device *dev, } bmg160->drdy_handler = handler; + bmg160->drdy_trig = trig; return 0; } @@ -128,9 +132,9 @@ int bmg160_trigger_set(const struct device *dev, } if (trig->type == SENSOR_TRIG_DELTA) { - return bmg160_anymotion_set(dev, handler); + return bmg160_anymotion_set(dev, trig, handler); } else if (trig->type == SENSOR_TRIG_DATA_READY) { - return bmg160_drdy_set(dev, handler); + return bmg160_drdy_set(dev, trig, handler); } return -ENOTSUP; @@ -139,13 +143,9 @@ int bmg160_trigger_set(const struct device *dev, static int bmg160_handle_anymotion_int(const struct device *dev) { struct bmg160_device_data *bmg160 = dev->data; - struct sensor_trigger any_trig = { - .type = SENSOR_TRIG_DELTA, - .chan = SENSOR_CHAN_GYRO_XYZ, - }; if (bmg160->anymotion_handler) { - bmg160->anymotion_handler(dev, &any_trig); + bmg160->anymotion_handler(dev, bmg160->anymotion_trig); } return 0; @@ -154,13 +154,9 @@ static int bmg160_handle_anymotion_int(const struct device *dev) static int bmg160_handle_dataready_int(const struct device *dev) { struct bmg160_device_data *bmg160 = dev->data; - struct sensor_trigger drdy_trig = { - .type = SENSOR_TRIG_DATA_READY, - .chan = SENSOR_CHAN_GYRO_XYZ, - }; if (bmg160->drdy_handler) { - bmg160->drdy_handler(dev, &drdy_trig); + bmg160->drdy_handler(dev, bmg160->drdy_trig); } return 0; From eac3ac2d8718acf482c73c93125272df54bc7535 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 13:07:59 -0600 Subject: [PATCH 0390/1906] drivers: sensor: bmi160: Store sensor trigger as a pointer Fixes the bmi160 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/bmi160/bmi160.h | 3 +++ drivers/sensor/bmi160/bmi160_trigger.c | 26 +++++++++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/sensor/bmi160/bmi160.h b/drivers/sensor/bmi160/bmi160.h index a9fed0dba67f..1399d88b76c9 100644 --- a/drivers/sensor/bmi160/bmi160.h +++ b/drivers/sensor/bmi160/bmi160.h @@ -504,10 +504,13 @@ struct bmi160_data { #ifdef CONFIG_BMI160_TRIGGER #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) sensor_trigger_handler_t handler_drdy_acc; + const struct sensor_trigger *trig_drdy_acc; sensor_trigger_handler_t handler_anymotion; + const struct sensor_trigger *trig_anymotion; #endif #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) sensor_trigger_handler_t handler_drdy_gyr; + const struct sensor_trigger *trig_drdy_gyr; #endif #endif /* CONFIG_BMI160_TRIGGER */ }; diff --git a/drivers/sensor/bmi160/bmi160_trigger.c b/drivers/sensor/bmi160/bmi160_trigger.c index 532337658a25..cd73f3201860 100644 --- a/drivers/sensor/bmi160/bmi160_trigger.c +++ b/drivers/sensor/bmi160/bmi160_trigger.c @@ -17,34 +17,25 @@ LOG_MODULE_DECLARE(BMI160, CONFIG_SENSOR_LOG_LEVEL); static void bmi160_handle_anymotion(const struct device *dev) { struct bmi160_data *data = dev->data; - struct sensor_trigger anym_trigger = { - .type = SENSOR_TRIG_DELTA, - .chan = SENSOR_CHAN_ACCEL_XYZ, - }; if (data->handler_anymotion) { - data->handler_anymotion(dev, &anym_trigger); + data->handler_anymotion(dev, data->trig_anymotion); } } static void bmi160_handle_drdy(const struct device *dev, uint8_t status) { struct bmi160_data *data = dev->data; - struct sensor_trigger drdy_trigger = { - .type = SENSOR_TRIG_DATA_READY, - }; #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) if (data->handler_drdy_acc && (status & BMI160_STATUS_ACC_DRDY)) { - drdy_trigger.chan = SENSOR_CHAN_ACCEL_XYZ; - data->handler_drdy_acc(dev, &drdy_trigger); + data->handler_drdy_acc(dev, data->trig_drdy_acc); } #endif #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) if (data->handler_drdy_gyr && (status & BMI160_STATUS_GYR_DRDY)) { - drdy_trigger.chan = SENSOR_CHAN_GYRO_XYZ; - data->handler_drdy_gyr(dev, &drdy_trigger); + data->handler_drdy_gyr(dev, data->trig_drdy_gyr); } #endif } @@ -118,6 +109,7 @@ static void bmi160_gpio_callback(const struct device *port, static int bmi160_trigger_drdy_set(const struct device *dev, enum sensor_channel chan, + const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { struct bmi160_data *data = dev->data; @@ -126,6 +118,7 @@ static int bmi160_trigger_drdy_set(const struct device *dev, #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) if (chan == SENSOR_CHAN_ACCEL_XYZ) { data->handler_drdy_acc = handler; + data->trig_drdy_acc = trig; } if (data->handler_drdy_acc) { @@ -136,6 +129,7 @@ static int bmi160_trigger_drdy_set(const struct device *dev, #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) if (chan == SENSOR_CHAN_GYRO_XYZ) { data->handler_drdy_gyr = handler; + data->trig_drdy_gyr = trig; } if (data->handler_drdy_gyr) { @@ -153,12 +147,14 @@ static int bmi160_trigger_drdy_set(const struct device *dev, #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) static int bmi160_trigger_anym_set(const struct device *dev, + const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { struct bmi160_data *data = dev->data; uint8_t anym_en = 0U; data->handler_anymotion = handler; + data->trig_anymotion = trig; if (handler) { anym_en = BMI160_INT_ANYM_X_EN | @@ -179,9 +175,9 @@ static int bmi160_trigger_set_acc(const struct device *dev, sensor_trigger_handler_t handler) { if (trig->type == SENSOR_TRIG_DATA_READY) { - return bmi160_trigger_drdy_set(dev, trig->chan, handler); + return bmi160_trigger_drdy_set(dev, trig->chan, trig, handler); } else if (trig->type == SENSOR_TRIG_DELTA) { - return bmi160_trigger_anym_set(dev, handler); + return bmi160_trigger_anym_set(dev, trig, handler); } return -ENOTSUP; @@ -238,7 +234,7 @@ static int bmi160_trigger_set_gyr(const struct device *dev, sensor_trigger_handler_t handler) { if (trig->type == SENSOR_TRIG_DATA_READY) { - return bmi160_trigger_drdy_set(dev, trig->chan, handler); + return bmi160_trigger_drdy_set(dev, trig->chan, trig, handler); } return -ENOTSUP; From 7f59286f988ec78efe23fa06bc0f44635e778e4c Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 13:08:41 -0600 Subject: [PATCH 0391/1906] drivers: sensor: bmp388: Store sensor trigger as a pointer Fixes the bmp388 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/bmp388/bmp388.h | 1 + drivers/sensor/bmp388/bmp388_trigger.c | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/sensor/bmp388/bmp388.h b/drivers/sensor/bmp388/bmp388.h index aa87309f29ad..b02a7f77ccc1 100644 --- a/drivers/sensor/bmp388/bmp388.h +++ b/drivers/sensor/bmp388/bmp388.h @@ -184,6 +184,7 @@ struct bmp388_data { #ifdef CONFIG_BMP388_TRIGGER sensor_trigger_handler_t handler_drdy; + const struct sensor_trigger *trig_drdy; #endif /* CONFIG_BMP388_TRIGGER */ }; diff --git a/drivers/sensor/bmp388/bmp388_trigger.c b/drivers/sensor/bmp388/bmp388_trigger.c index dd9cb1c686e7..f6105e99e3d0 100644 --- a/drivers/sensor/bmp388/bmp388_trigger.c +++ b/drivers/sensor/bmp388/bmp388_trigger.c @@ -25,13 +25,8 @@ static void bmp388_handle_interrupts(const void *arg) const struct device *dev = (const struct device *)arg; struct bmp388_data *data = dev->data; - struct sensor_trigger drdy_trigger = { - .type = SENSOR_TRIG_DATA_READY, - .chan = SENSOR_CHAN_PRESS, - }; - if (data->handler_drdy) { - data->handler_drdy(dev, &drdy_trigger); + data->handler_drdy(dev, data->trig_drdy); } } @@ -115,6 +110,7 @@ int bmp388_trigger_set( } data->handler_drdy = handler; + data->trig_drdy = trig; return 0; } From 9024a3cf97afcb87e235083f4cb2799912dde45e Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 13:09:16 -0600 Subject: [PATCH 0392/1906] drivers: sensor: bq274xx: Store sensor trigger as a pointer Fixes the bq274xx sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/bq274xx/bq274xx.h | 1 + drivers/sensor/bq274xx/bq274xx_trigger.c | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/sensor/bq274xx/bq274xx.h b/drivers/sensor/bq274xx/bq274xx.h index 2306fb9bb61b..bd099f04014c 100644 --- a/drivers/sensor/bq274xx/bq274xx.h +++ b/drivers/sensor/bq274xx/bq274xx.h @@ -97,6 +97,7 @@ struct bq274xx_data { const struct device *dev; struct gpio_callback ready_callback; sensor_trigger_handler_t ready_handler; + const struct sensor_trigger *ready_trig; #ifdef CONFIG_BQ274XX_TRIGGER_OWN_THREAD struct k_sem sem; diff --git a/drivers/sensor/bq274xx/bq274xx_trigger.c b/drivers/sensor/bq274xx/bq274xx_trigger.c index 207f82d708a3..6bb7207b8708 100644 --- a/drivers/sensor/bq274xx/bq274xx_trigger.c +++ b/drivers/sensor/bq274xx/bq274xx_trigger.c @@ -22,13 +22,8 @@ static void bq274xx_handle_interrupts(const struct device *dev) { struct bq274xx_data *data = dev->data; - struct sensor_trigger trig = { - .type = SENSOR_TRIG_DATA_READY, - .chan = SENSOR_CHAN_ALL, - }; - if (data->ready_handler) { - data->ready_handler(dev, &trig); + data->ready_handler(dev, data->ready_trig); } } @@ -130,6 +125,7 @@ int bq274xx_trigger_set(const struct device *dev, } data->ready_handler = handler; + data->ready_trig = trig; if (handler) { status = gpio_pin_configure_dt(&config->int_gpios, GPIO_INPUT); From c45595e1643bcff42523a050e3442f64499ab6ae Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 13:09:53 -0600 Subject: [PATCH 0393/1906] drivers: sensor: ccs811: Store sensor trigger as a pointer Fixes the ccs811 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/ccs811/ccs811.h | 2 +- drivers/sensor/ccs811/ccs811_trigger.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/sensor/ccs811/ccs811.h b/drivers/sensor/ccs811/ccs811.h index 5e35ad09a643..91bca8e7a9ae 100644 --- a/drivers/sensor/ccs811/ccs811.h +++ b/drivers/sensor/ccs811/ccs811.h @@ -58,7 +58,7 @@ struct ccs811_data { */ struct gpio_callback gpio_cb; sensor_trigger_handler_t handler; - struct sensor_trigger trigger; + const struct sensor_trigger *trigger; #if defined(CONFIG_CCS811_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_CCS811_THREAD_STACK_SIZE); struct k_sem gpio_sem; diff --git a/drivers/sensor/ccs811/ccs811_trigger.c b/drivers/sensor/ccs811/ccs811_trigger.c index 324b1a043fd5..c01d9629ad6d 100644 --- a/drivers/sensor/ccs811/ccs811_trigger.c +++ b/drivers/sensor/ccs811/ccs811_trigger.c @@ -77,7 +77,7 @@ static void process_irq(const struct device *dev) struct ccs811_data *data = dev->data; if (data->handler != NULL) { - data->handler(dev, &data->trigger); + data->handler(dev, data->trigger); } if (data->handler != NULL) { @@ -159,7 +159,7 @@ int ccs811_trigger_set(const struct device *dev, } if (rc == 0) { - drv_data->trigger = *trig; + drv_data->trigger = trig; setup_irq(dev, true); if (gpio_pin_get_dt(&config->irq_gpio) > 0) { From 77cb3aeeb5da6cbd224804cde62ac0ec456923c8 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 13:10:31 -0600 Subject: [PATCH 0394/1906] drivers: sensor: fdc2x1x: Store sensor trigger as a pointer Fixes the fdc2x1x sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/fdc2x1x/fdc2x1x.h | 2 +- drivers/sensor/fdc2x1x/fdc2x1x_trigger.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/sensor/fdc2x1x/fdc2x1x.h b/drivers/sensor/fdc2x1x/fdc2x1x.h index 5315559d682d..33b94168d677 100644 --- a/drivers/sensor/fdc2x1x/fdc2x1x.h +++ b/drivers/sensor/fdc2x1x/fdc2x1x.h @@ -155,7 +155,7 @@ struct fdc2x1x_data { struct k_mutex trigger_mutex; sensor_trigger_handler_t drdy_handler; - struct sensor_trigger drdy_trigger; + const struct sensor_trigger *drdy_trigger; const struct device *dev; #ifdef CONFIG_FDC2X1X_TRIGGER_OWN_THREAD diff --git a/drivers/sensor/fdc2x1x/fdc2x1x_trigger.c b/drivers/sensor/fdc2x1x/fdc2x1x_trigger.c index e710a720787d..0ca10f59864f 100644 --- a/drivers/sensor/fdc2x1x/fdc2x1x_trigger.c +++ b/drivers/sensor/fdc2x1x/fdc2x1x_trigger.c @@ -41,7 +41,7 @@ static void fdc2x1x_thread_cb(const struct device *dev) k_mutex_lock(&drv_data->trigger_mutex, K_FOREVER); if ((drv_data->drdy_handler != NULL) && FDC2X1X_STATUS_DRDY(status)) { - drv_data->drdy_handler(dev, &drv_data->drdy_trigger); + drv_data->drdy_handler(dev, drv_data->drdy_trigger); } k_mutex_unlock(&drv_data->trigger_mutex); } @@ -93,7 +93,7 @@ int fdc2x1x_trigger_set(const struct device *dev, case SENSOR_TRIG_DATA_READY: k_mutex_lock(&drv_data->trigger_mutex, K_FOREVER); drv_data->drdy_handler = handler; - drv_data->drdy_trigger = *trig; + drv_data->drdy_trigger = trig; k_mutex_unlock(&drv_data->trigger_mutex); int_mask = FDC2X1X_ERROR_CONFIG_DRDY_2INT_MSK; From 2a72e0eaf3651e90ee0aaed4973b19c21ad706d3 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 13:11:04 -0600 Subject: [PATCH 0395/1906] drivers: sensor: fxas21002: Store sensor trigger as a pointer Fixes the fxas21002 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/fxas21002/fxas21002.h | 1 + drivers/sensor/fxas21002/fxas21002_trigger.c | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/sensor/fxas21002/fxas21002.h b/drivers/sensor/fxas21002/fxas21002.h index 7e47c0d1fb6c..b70f98cb8c5a 100644 --- a/drivers/sensor/fxas21002/fxas21002.h +++ b/drivers/sensor/fxas21002/fxas21002.h @@ -110,6 +110,7 @@ struct fxas21002_data { const struct device *dev; struct gpio_callback gpio_cb; sensor_trigger_handler_t drdy_handler; + const struct sensor_trigger *drdy_trig; #endif #ifdef CONFIG_FXAS21002_TRIGGER_OWN_THREAD K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_FXAS21002_THREAD_STACK_SIZE); diff --git a/drivers/sensor/fxas21002/fxas21002_trigger.c b/drivers/sensor/fxas21002/fxas21002_trigger.c index e705cfb83b19..5e11c0405656 100644 --- a/drivers/sensor/fxas21002/fxas21002_trigger.c +++ b/drivers/sensor/fxas21002/fxas21002_trigger.c @@ -37,13 +37,8 @@ static int fxas21002_handle_drdy_int(const struct device *dev) { struct fxas21002_data *data = dev->data; - struct sensor_trigger drdy_trig = { - .type = SENSOR_TRIG_DATA_READY, - .chan = SENSOR_CHAN_ALL, - }; - if (data->drdy_handler) { - data->drdy_handler(dev, &drdy_trig); + data->drdy_handler(dev, data->drdy_trig); } return 0; @@ -113,6 +108,7 @@ int fxas21002_trigger_set(const struct device *dev, case SENSOR_TRIG_DATA_READY: mask = FXAS21002_CTRLREG2_CFG_EN_MASK; data->drdy_handler = handler; + data->drdy_trig = trig; break; default: LOG_ERR("Unsupported sensor trigger"); From e20357e7ac94251ca69abd527736a43d775ee0e9 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 7 Mar 2023 13:13:19 -0600 Subject: [PATCH 0396/1906] drivers: sensor: fxos8700: Store sensor trigger as a pointer Fixes the fxos8700 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/fxos8700/fxos8700.h | 5 +++ drivers/sensor/fxos8700/fxos8700_trigger.c | 36 ++++++++-------------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/drivers/sensor/fxos8700/fxos8700.h b/drivers/sensor/fxos8700/fxos8700.h index 88c83755a284..a044a56b95dc 100644 --- a/drivers/sensor/fxos8700/fxos8700.h +++ b/drivers/sensor/fxos8700/fxos8700.h @@ -193,16 +193,21 @@ struct fxos8700_data { const struct device *dev; struct gpio_callback gpio_cb; sensor_trigger_handler_t drdy_handler; + const struct sensor_trigger *drdy_trig; #endif #ifdef CONFIG_FXOS8700_PULSE sensor_trigger_handler_t tap_handler; + const struct sensor_trigger *tap_trig; sensor_trigger_handler_t double_tap_handler; + const struct sensor_trigger *double_tap_trig; #endif #ifdef CONFIG_FXOS8700_MOTION sensor_trigger_handler_t motion_handler; + const struct sensor_trigger *motion_trig; #endif #ifdef CONFIG_FXOS8700_MAG_VECM sensor_trigger_handler_t m_vecm_handler; + const struct sensor_trigger *m_vecm_trig; #endif #ifdef CONFIG_FXOS8700_TRIGGER_OWN_THREAD K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_FXOS8700_THREAD_STACK_SIZE); diff --git a/drivers/sensor/fxos8700/fxos8700_trigger.c b/drivers/sensor/fxos8700/fxos8700_trigger.c index fabfbd76d0ba..2eb6bb74b305 100644 --- a/drivers/sensor/fxos8700/fxos8700_trigger.c +++ b/drivers/sensor/fxos8700/fxos8700_trigger.c @@ -37,13 +37,8 @@ static int fxos8700_handle_drdy_int(const struct device *dev) { struct fxos8700_data *data = dev->data; - struct sensor_trigger drdy_trig = { - .type = SENSOR_TRIG_DATA_READY, - .chan = SENSOR_CHAN_ALL, - }; - if (data->drdy_handler) { - data->drdy_handler(dev, &drdy_trig); + data->drdy_handler(dev, data->drdy_trig); } return 0; @@ -55,12 +50,9 @@ static int fxos8700_handle_pulse_int(const struct device *dev) const struct fxos8700_config *config = dev->config; struct fxos8700_data *data = dev->data; sensor_trigger_handler_t handler = NULL; + const struct sensor_trigger *trig = NULL; uint8_t pulse_source; - struct sensor_trigger pulse_trig = { - .chan = SENSOR_CHAN_ALL, - }; - k_sem_take(&data->sem, K_FOREVER); if (config->ops->byte_read(dev, FXOS8700_REG_PULSE_SRC, @@ -71,15 +63,15 @@ static int fxos8700_handle_pulse_int(const struct device *dev) k_sem_give(&data->sem); if (pulse_source & FXOS8700_PULSE_SRC_DPE) { - pulse_trig.type = SENSOR_TRIG_DOUBLE_TAP; handler = data->double_tap_handler; + trig = data->double_tap_trig; } else { - pulse_trig.type = SENSOR_TRIG_TAP; handler = data->tap_handler; + trig = data->tap_trig; } if (handler) { - handler(dev, &pulse_trig); + handler(dev, trig); } return 0; @@ -94,10 +86,6 @@ static int fxos8700_handle_motion_int(const struct device *dev) sensor_trigger_handler_t handler = data->motion_handler; uint8_t motion_source; - struct sensor_trigger motion_trig = { - .chan = SENSOR_CHAN_ALL, - }; - k_sem_take(&data->sem, K_FOREVER); if (config->ops->byte_read(dev, FXOS8700_REG_FF_MT_SRC, @@ -109,7 +97,7 @@ static int fxos8700_handle_motion_int(const struct device *dev) if (handler) { LOG_DBG("FF_MT_SRC 0x%x", motion_source); - handler(dev, &motion_trig); + handler(dev, data->motion_trig); } return 0; @@ -121,13 +109,8 @@ static int fxos8700_handle_m_vecm_int(const struct device *dev) { struct fxos8700_data *data = dev->data; - struct sensor_trigger m_vecm_trig = { - .type = FXOS8700_TRIG_M_VECM, - .chan = SENSOR_CHAN_MAGN_XYZ, - }; - if (data->m_vecm_handler) { - data->m_vecm_handler(dev, &m_vecm_trig); + data->m_vecm_handler(dev, data->m_vecm_trig); } return 0; @@ -220,27 +203,32 @@ int fxos8700_trigger_set(const struct device *dev, case SENSOR_TRIG_DATA_READY: mask = FXOS8700_DRDY_MASK; data->drdy_handler = handler; + data->drdy_trig = trig; break; #ifdef CONFIG_FXOS8700_PULSE case SENSOR_TRIG_TAP: mask = FXOS8700_PULSE_MASK; data->tap_handler = handler; + data->tap_trig = trig; break; case SENSOR_TRIG_DOUBLE_TAP: mask = FXOS8700_PULSE_MASK; data->double_tap_handler = handler; + data->double_tap_trig = trig; break; #endif #ifdef CONFIG_FXOS8700_MOTION case SENSOR_TRIG_DELTA: mask = FXOS8700_MOTION_MASK; data->motion_handler = handler; + data->motion_trig = trig; break; #endif #ifdef CONFIG_FXOS8700_MAG_VECM case FXOS8700_TRIG_M_VECM: mask = FXOS8700_VECM_MASK; data->m_vecm_handler = handler; + data->m_vecm_trig = trig; break; #endif default: From 1b05a2ce8b5697226b1d69ea041fe24da1757621 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 8 Mar 2023 15:45:36 -0600 Subject: [PATCH 0397/1906] drivers: sensor: grow_r502a: Store sensor trigger as a pointer Fixes the grow_r502a sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/grow_r502a/grow_r502a.h | 2 +- drivers/sensor/grow_r502a/grow_r502a_trigger.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/sensor/grow_r502a/grow_r502a.h b/drivers/sensor/grow_r502a/grow_r502a.h index 2cfc7305cefa..c8374fb17d3d 100644 --- a/drivers/sensor/grow_r502a/grow_r502a.h +++ b/drivers/sensor/grow_r502a/grow_r502a.h @@ -171,7 +171,7 @@ struct grow_r502a_data { struct gpio_callback gpio_cb; sensor_trigger_handler_t th_handler; - struct sensor_trigger th_trigger; + const struct sensor_trigger *th_trigger; #if defined(CONFIG_GROW_R502A_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_GROW_R502A_THREAD_STACK_SIZE); struct k_sem gpio_sem; diff --git a/drivers/sensor/grow_r502a/grow_r502a_trigger.c b/drivers/sensor/grow_r502a/grow_r502a_trigger.c index 60a07adae96a..4b055439409d 100644 --- a/drivers/sensor/grow_r502a/grow_r502a_trigger.c +++ b/drivers/sensor/grow_r502a/grow_r502a_trigger.c @@ -32,7 +32,7 @@ static void process_int(const struct device *dev) struct grow_r502a_data *drv_data = dev->data; if (drv_data->th_handler != NULL) { - drv_data->th_handler(dev, &drv_data->th_trigger); + drv_data->th_handler(dev, drv_data->th_trigger); } setup_int(dev, true); } @@ -45,7 +45,7 @@ int grow_r502a_trigger_set(const struct device *dev, if ((enum sensor_trigger_type_grow_r502a)trig->type == SENSOR_TRIG_TOUCH) { drv_data->th_handler = handler; - drv_data->th_trigger = *trig; + drv_data->th_trigger = trig; setup_int(dev, true); } else { LOG_ERR("Unsupported sensor trigger"); From 73ddc98ea00f4e1317c18aff5e473c6156f17450 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 8 Mar 2023 15:46:26 -0600 Subject: [PATCH 0398/1906] drivers: sensor: hmc5883l: Store sensor trigger as a pointer Fixes the hmc5883l sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/hmc5883l/hmc5883l.h | 2 +- drivers/sensor/hmc5883l/hmc5883l_trigger.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/sensor/hmc5883l/hmc5883l.h b/drivers/sensor/hmc5883l/hmc5883l.h index f9ab0d2631bd..b05b81b21695 100644 --- a/drivers/sensor/hmc5883l/hmc5883l.h +++ b/drivers/sensor/hmc5883l/hmc5883l.h @@ -52,7 +52,7 @@ struct hmc5883l_data { const struct device *dev; struct gpio_callback gpio_cb; - struct sensor_trigger data_ready_trigger; + const struct sensor_trigger *data_ready_trigger; sensor_trigger_handler_t data_ready_handler; #if defined(CONFIG_HMC5883L_TRIGGER_OWN_THREAD) diff --git a/drivers/sensor/hmc5883l/hmc5883l_trigger.c b/drivers/sensor/hmc5883l/hmc5883l_trigger.c index 4e9439606cfb..f6eb8fdf30d3 100644 --- a/drivers/sensor/hmc5883l/hmc5883l_trigger.c +++ b/drivers/sensor/hmc5883l/hmc5883l_trigger.c @@ -37,7 +37,7 @@ int hmc5883l_trigger_set(const struct device *dev, return 0; } - drv_data->data_ready_trigger = *trig; + drv_data->data_ready_trigger = trig; gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_EDGE_TO_ACTIVE); @@ -70,7 +70,7 @@ static void hmc5883l_thread_cb(const struct device *dev) if (drv_data->data_ready_handler != NULL) { drv_data->data_ready_handler(dev, - &drv_data->data_ready_trigger); + drv_data->data_ready_trigger); } gpio_pin_interrupt_configure_dt(&config->int_gpio, From 466c5501bce7a4429fb44f5423c75a18c4c1f075 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 8 Mar 2023 15:47:32 -0600 Subject: [PATCH 0399/1906] drivers: sensor: hts221: Store sensor trigger as a pointer Fixes the hts221 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/hts221/hts221.h | 2 +- drivers/sensor/hts221/hts221_trigger.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/sensor/hts221/hts221.h b/drivers/sensor/hts221/hts221.h index a20f57a17302..e0af57c13260 100644 --- a/drivers/sensor/hts221/hts221.h +++ b/drivers/sensor/hts221/hts221.h @@ -43,7 +43,7 @@ struct hts221_data { const struct device *dev; struct gpio_callback drdy_cb; - struct sensor_trigger data_ready_trigger; + const struct sensor_trigger *data_ready_trigger; sensor_trigger_handler_t data_ready_handler; #if defined(CONFIG_HTS221_TRIGGER_OWN_THREAD) diff --git a/drivers/sensor/hts221/hts221_trigger.c b/drivers/sensor/hts221/hts221_trigger.c index 314b666ab3ee..404f84d94176 100644 --- a/drivers/sensor/hts221/hts221_trigger.c +++ b/drivers/sensor/hts221/hts221_trigger.c @@ -45,7 +45,7 @@ static void process_drdy(const struct device *dev) struct hts221_data *data = dev->data; if (data->data_ready_handler != NULL) { - data->data_ready_handler(dev, &data->data_ready_trigger); + data->data_ready_handler(dev, data->data_ready_trigger); } if (data->data_ready_handler != NULL) { @@ -69,7 +69,7 @@ int hts221_trigger_set(const struct device *dev, return 0; } - data->data_ready_trigger = *trig; + data->data_ready_trigger = trig; setup_drdy(dev, true); From 1ea5bb32f3f45aacaf80047d96f194349c02eab5 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 8 Mar 2023 15:48:52 -0600 Subject: [PATCH 0400/1906] drivers: sensor: icm42605: Store sensor trigger as a pointer Fixes the icm42605 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/icm42605/icm42605.c | 8 ++++---- drivers/sensor/icm42605/icm42605.h | 6 +++--- drivers/sensor/icm42605/icm42605_trigger.c | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/sensor/icm42605/icm42605.c b/drivers/sensor/icm42605/icm42605.c index 82d3af8f1d97..3f91c2f53f7f 100644 --- a/drivers/sensor/icm42605/icm42605.c +++ b/drivers/sensor/icm42605/icm42605.c @@ -134,23 +134,23 @@ int icm42605_tap_fetch(const struct device *dev) result = inv_spi_read(&cfg->spi, REG_APEX_DATA4, drv_data->fifo_data, 1); if (drv_data->fifo_data[0] & APEX_TAP) { - if (drv_data->tap_trigger.type == + if (drv_data->tap_trigger->type == SENSOR_TRIG_TAP) { if (drv_data->tap_handler) { LOG_DBG("Single Tap detected"); drv_data->tap_handler(dev - , &drv_data->tap_trigger); + , drv_data->tap_trigger); } } else { LOG_ERR("Trigger type is mismatched"); } } else if (drv_data->fifo_data[0] & APEX_DOUBLE_TAP) { - if (drv_data->double_tap_trigger.type == + if (drv_data->double_tap_trigger->type == SENSOR_TRIG_DOUBLE_TAP) { if (drv_data->double_tap_handler) { LOG_DBG("Double Tap detected"); drv_data->double_tap_handler(dev - , &drv_data->tap_trigger); + , drv_data->tap_trigger); } } else { LOG_ERR("Trigger type is mismatched"); diff --git a/drivers/sensor/icm42605/icm42605.h b/drivers/sensor/icm42605/icm42605.h index 29e16208cfb0..48286e932e46 100644 --- a/drivers/sensor/icm42605/icm42605.h +++ b/drivers/sensor/icm42605/icm42605.h @@ -47,13 +47,13 @@ struct icm42605_data { const struct device *dev; struct gpio_callback gpio_cb; - struct sensor_trigger data_ready_trigger; + const struct sensor_trigger *data_ready_trigger; sensor_trigger_handler_t data_ready_handler; - struct sensor_trigger tap_trigger; + const struct sensor_trigger *tap_trigger; sensor_trigger_handler_t tap_handler; - struct sensor_trigger double_tap_trigger; + const struct sensor_trigger *double_tap_trigger; sensor_trigger_handler_t double_tap_handler; #ifdef CONFIG_ICM42605_TRIGGER diff --git a/drivers/sensor/icm42605/icm42605_trigger.c b/drivers/sensor/icm42605/icm42605_trigger.c index 08da99e40e9b..a498b2a349a4 100644 --- a/drivers/sensor/icm42605/icm42605_trigger.c +++ b/drivers/sensor/icm42605/icm42605_trigger.c @@ -37,14 +37,14 @@ int icm42605_trigger_set(const struct device *dev, if (trig->type == SENSOR_TRIG_DATA_READY) { drv_data->data_ready_handler = handler; - drv_data->data_ready_trigger = *trig; + drv_data->data_ready_trigger = trig; } else if (trig->type == SENSOR_TRIG_TAP) { drv_data->tap_handler = handler; - drv_data->tap_trigger = *trig; + drv_data->tap_trigger = trig; drv_data->tap_en = true; } else if (trig->type == SENSOR_TRIG_DOUBLE_TAP) { drv_data->double_tap_handler = handler; - drv_data->double_tap_trigger = *trig; + drv_data->double_tap_trigger = trig; drv_data->tap_en = true; } else { return -ENOTSUP; @@ -78,7 +78,7 @@ static void icm42605_thread_cb(const struct device *dev) if (drv_data->data_ready_handler != NULL) { drv_data->data_ready_handler(dev, - &drv_data->data_ready_trigger); + drv_data->data_ready_trigger); } if (drv_data->tap_handler != NULL || From e0e4fa5d437d8aabf174d7a5137d33bb5022ca90 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 8 Mar 2023 15:49:27 -0600 Subject: [PATCH 0401/1906] drivers: sensor: iis2dh: Store sensor trigger as a pointer Fixes the iis2dh sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/iis2dh/iis2dh.h | 1 + drivers/sensor/iis2dh/iis2dh_trigger.c | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/sensor/iis2dh/iis2dh.h b/drivers/sensor/iis2dh/iis2dh.h index 0959c7fa5060..b8ee988ab75a 100644 --- a/drivers/sensor/iis2dh/iis2dh.h +++ b/drivers/sensor/iis2dh/iis2dh.h @@ -65,6 +65,7 @@ struct iis2dh_data { const struct device *dev; struct gpio_callback gpio_cb; sensor_trigger_handler_t drdy_handler; + const struct sensor_trigger *drdy_trig; #if defined(CONFIG_IIS2DH_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_IIS2DH_THREAD_STACK_SIZE); struct k_thread thread; diff --git a/drivers/sensor/iis2dh/iis2dh_trigger.c b/drivers/sensor/iis2dh/iis2dh_trigger.c index 623670dc08e7..69c807524519 100644 --- a/drivers/sensor/iis2dh/iis2dh_trigger.c +++ b/drivers/sensor/iis2dh/iis2dh_trigger.c @@ -55,6 +55,7 @@ int iis2dh_trigger_set(const struct device *dev, switch (trig->type) { case SENSOR_TRIG_DATA_READY: iis2dh->drdy_handler = handler; + iis2dh->drdy_trig = trig; if (state) { /* dummy read: re-trigger interrupt */ iis2dh_acceleration_raw_get(iis2dh->ctx, raw); @@ -70,13 +71,8 @@ static int iis2dh_handle_drdy_int(const struct device *dev) { struct iis2dh_data *data = dev->data; - struct sensor_trigger drdy_trig = { - .type = SENSOR_TRIG_DATA_READY, - .chan = SENSOR_CHAN_ALL, - }; - if (data->drdy_handler) { - data->drdy_handler(dev, &drdy_trig); + data->drdy_handler(dev, data->drdy_trig); } return 0; From 7b4ea85a0badad39f8af5aeb28a9781d5299c7ea Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 8 Mar 2023 15:50:19 -0600 Subject: [PATCH 0402/1906] drivers: sensor: iis2dlpc: Store sensor trigger as a pointer Fixes the iis2dlpc sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/iis2dlpc/iis2dlpc.h | 4 +++ drivers/sensor/iis2dlpc/iis2dlpc_trigger.c | 32 ++++++---------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/drivers/sensor/iis2dlpc/iis2dlpc.h b/drivers/sensor/iis2dlpc/iis2dlpc.h index 72f11cc72dad..2795c77620e0 100644 --- a/drivers/sensor/iis2dlpc/iis2dlpc.h +++ b/drivers/sensor/iis2dlpc/iis2dlpc.h @@ -95,12 +95,16 @@ struct iis2dlpc_data { uint8_t gpio_pin; struct gpio_callback gpio_cb; sensor_trigger_handler_t drdy_handler; + const struct sensor_trigger *drdy_trig; #ifdef CONFIG_IIS2DLPC_TAP sensor_trigger_handler_t tap_handler; + const struct sensor_trigger *tap_trig; sensor_trigger_handler_t double_tap_handler; + const struct sensor_trigger *double_tap_trig; #endif /* CONFIG_IIS2DLPC_TAP */ #ifdef CONFIG_IIS2DLPC_ACTIVITY sensor_trigger_handler_t activity_handler; + const struct sensor_trigger *activity_trig; #endif /* CONFIG_IIS2DLPC_ACTIVITY */ #if defined(CONFIG_IIS2DLPC_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_IIS2DLPC_THREAD_STACK_SIZE); diff --git a/drivers/sensor/iis2dlpc/iis2dlpc_trigger.c b/drivers/sensor/iis2dlpc/iis2dlpc_trigger.c index aecc2ee2522c..06f2e251e39e 100644 --- a/drivers/sensor/iis2dlpc/iis2dlpc_trigger.c +++ b/drivers/sensor/iis2dlpc/iis2dlpc_trigger.c @@ -102,6 +102,7 @@ int iis2dlpc_trigger_set(const struct device *dev, switch (trig->type) { case SENSOR_TRIG_DATA_READY: iis2dlpc->drdy_handler = handler; + iis2dlpc->drdy_trig = trig; if (state) { /* dummy read: re-trigger interrupt */ iis2dlpc_acceleration_raw_get(ctx, raw); @@ -110,14 +111,17 @@ int iis2dlpc_trigger_set(const struct device *dev, #ifdef CONFIG_IIS2DLPC_TAP case SENSOR_TRIG_TAP: iis2dlpc->tap_handler = handler; + iis2dlpc->tap_trig = trig; return iis2dlpc_enable_int(dev, SENSOR_TRIG_TAP, state); case SENSOR_TRIG_DOUBLE_TAP: iis2dlpc->double_tap_handler = handler; + iis2dlpc->double_tap_trig = trig; return iis2dlpc_enable_int(dev, SENSOR_TRIG_DOUBLE_TAP, state); #endif /* CONFIG_IIS2DLPC_TAP */ #ifdef CONFIG_IIS2DLPC_ACTIVITY case SENSOR_TRIG_DELTA: iis2dlpc->activity_handler = handler; + iis2dlpc->activity_trig = trig; return iis2dlpc_enable_int(dev, SENSOR_TRIG_DELTA, state); #endif /* CONFIG_IIS2DLPC_ACTIVITY */ default: @@ -130,13 +134,8 @@ static int iis2dlpc_handle_drdy_int(const struct device *dev) { struct iis2dlpc_data *data = dev->data; - struct sensor_trigger drdy_trig = { - .type = SENSOR_TRIG_DATA_READY, - .chan = SENSOR_CHAN_ALL, - }; - if (data->drdy_handler) { - data->drdy_handler(dev, &drdy_trig); + data->drdy_handler(dev, data->drdy_trig); } return 0; @@ -148,13 +147,8 @@ static int iis2dlpc_handle_activity_int(const struct device *dev) struct iis2dlpc_data *data = dev->data; sensor_trigger_handler_t handler = data->activity_handler; - struct sensor_trigger tap_trig = { - .type = SENSOR_TRIG_DELTA, - .chan = SENSOR_CHAN_ALL, - }; - if (handler) { - handler(dev, &tap_trig); + handler(dev, data->activity_trig); } return 0; @@ -167,13 +161,8 @@ static int iis2dlpc_handle_single_tap_int(const struct device *dev) struct iis2dlpc_data *data = dev->data; sensor_trigger_handler_t handler = data->tap_handler; - struct sensor_trigger tap_trig = { - .type = SENSOR_TRIG_TAP, - .chan = SENSOR_CHAN_ALL, - }; - if (handler) { - handler(dev, &tap_trig); + handler(dev, data->tap_trig); } return 0; @@ -184,13 +173,8 @@ static int iis2dlpc_handle_double_tap_int(const struct device *dev) struct iis2dlpc_data *data = dev->data; sensor_trigger_handler_t handler = data->double_tap_handler; - struct sensor_trigger tap_trig = { - .type = SENSOR_TRIG_DOUBLE_TAP, - .chan = SENSOR_CHAN_ALL, - }; - if (handler) { - handler(dev, &tap_trig); + handler(dev, data->double_tap_trig); } return 0; From 99f9ef36afabe7ba63d78d29f0da524b0a6c4abb Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 8 Mar 2023 15:51:01 -0600 Subject: [PATCH 0403/1906] drivers: sensor: iis2iclx: Store sensor trigger as a pointer Fixes the iis2iclx sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/iis2iclx/iis2iclx.h | 2 ++ drivers/sensor/iis2iclx/iis2iclx_trigger.c | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/sensor/iis2iclx/iis2iclx.h b/drivers/sensor/iis2iclx/iis2iclx.h index ab7a60dbe541..6605be5851c6 100644 --- a/drivers/sensor/iis2iclx/iis2iclx.h +++ b/drivers/sensor/iis2iclx/iis2iclx.h @@ -86,7 +86,9 @@ struct iis2iclx_data { #ifdef CONFIG_IIS2ICLX_TRIGGER struct gpio_callback gpio_cb; sensor_trigger_handler_t handler_drdy_acc; + const struct sensor_trigger *trig_drdy_acc; sensor_trigger_handler_t handler_drdy_temp; + const struct sensor_trigger *trig_drdy_temp; #if defined(CONFIG_IIS2ICLX_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_IIS2ICLX_THREAD_STACK_SIZE); diff --git a/drivers/sensor/iis2iclx/iis2iclx_trigger.c b/drivers/sensor/iis2iclx/iis2iclx_trigger.c index 0ef2227708a4..da0feb493589 100644 --- a/drivers/sensor/iis2iclx/iis2iclx_trigger.c +++ b/drivers/sensor/iis2iclx/iis2iclx_trigger.c @@ -101,6 +101,7 @@ int iis2iclx_trigger_set(const struct device *dev, if (trig->chan == SENSOR_CHAN_ACCEL_XYZ) { iis2iclx->handler_drdy_acc = handler; + iis2iclx->trig_drdy_acc = trig; if (handler) { return iis2iclx_enable_xl_int(dev, IIS2ICLX_EN_BIT); } else { @@ -110,6 +111,7 @@ int iis2iclx_trigger_set(const struct device *dev, #if defined(CONFIG_IIS2ICLX_ENABLE_TEMP) else if (trig->chan == SENSOR_CHAN_DIE_TEMP) { iis2iclx->handler_drdy_temp = handler; + iis2iclx->trig_drdy_temp = trig; if (handler) { return iis2iclx_enable_t_int(dev, IIS2ICLX_EN_BIT); } else { @@ -128,9 +130,6 @@ int iis2iclx_trigger_set(const struct device *dev, static void iis2iclx_handle_interrupt(const struct device *dev) { struct iis2iclx_data *iis2iclx = dev->data; - struct sensor_trigger drdy_trigger = { - .type = SENSOR_TRIG_DATA_READY, - }; const struct iis2iclx_config *cfg = dev->config; iis2iclx_status_reg_t status; @@ -150,12 +149,12 @@ static void iis2iclx_handle_interrupt(const struct device *dev) } if ((status.xlda) && (iis2iclx->handler_drdy_acc != NULL)) { - iis2iclx->handler_drdy_acc(dev, &drdy_trigger); + iis2iclx->handler_drdy_acc(dev, iis2iclx->trig_drdy_acc); } #if defined(CONFIG_IIS2ICLX_ENABLE_TEMP) if ((status.tda) && (iis2iclx->handler_drdy_temp != NULL)) { - iis2iclx->handler_drdy_temp(dev, &drdy_trigger); + iis2iclx->handler_drdy_temp(dev, iis2iclx->trig_drdy_temp); } #endif } From b079316b4e3e55720231ca08fcb7df0e4e12268b Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 8 Mar 2023 15:51:41 -0600 Subject: [PATCH 0404/1906] drivers: sensor: iis2mdc: Store sensor trigger as a pointer Fixes the iis2mdc sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/iis2mdc/iis2mdc.h | 1 + drivers/sensor/iis2mdc/iis2mdc_trigger.c | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/sensor/iis2mdc/iis2mdc.h b/drivers/sensor/iis2mdc/iis2mdc.h index fe70d0539128..3f688b183f9d 100644 --- a/drivers/sensor/iis2mdc/iis2mdc.h +++ b/drivers/sensor/iis2mdc/iis2mdc.h @@ -59,6 +59,7 @@ struct iis2mdc_data { struct gpio_callback gpio_cb; sensor_trigger_handler_t handler_drdy; + const struct sensor_trigger *trig_drdy; #if defined(CONFIG_IIS2MDC_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_IIS2MDC_THREAD_STACK_SIZE); diff --git a/drivers/sensor/iis2mdc/iis2mdc_trigger.c b/drivers/sensor/iis2mdc/iis2mdc_trigger.c index c98dd6061fc2..7c911ec72dee 100644 --- a/drivers/sensor/iis2mdc/iis2mdc_trigger.c +++ b/drivers/sensor/iis2mdc/iis2mdc_trigger.c @@ -36,6 +36,7 @@ int iis2mdc_trigger_set(const struct device *dev, if (trig->chan == SENSOR_CHAN_MAGN_XYZ) { iis2mdc->handler_drdy = handler; + iis2mdc->trig_drdy = trig; if (handler) { /* fetch raw data sample: re-trigger lost interrupt */ iis2mdc_magnetic_raw_get(iis2mdc->ctx, raw); @@ -54,12 +55,9 @@ static void iis2mdc_handle_interrupt(const struct device *dev) { struct iis2mdc_data *iis2mdc = dev->data; const struct iis2mdc_dev_config *const config = dev->config; - struct sensor_trigger drdy_trigger = { - .type = SENSOR_TRIG_DATA_READY, - }; if (iis2mdc->handler_drdy != NULL) { - iis2mdc->handler_drdy(dev, &drdy_trigger); + iis2mdc->handler_drdy(dev, iis2mdc->trig_drdy); } gpio_pin_interrupt_configure_dt(&config->gpio_drdy, From 3c89bbf87676fe1c2aaf202104b6d7957b29799d Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Tue, 14 Mar 2023 13:28:36 +0100 Subject: [PATCH 0405/1906] drivers: can: reset statistics when starting the CAN controller Reset CAN controller statistics when starting the CAN controller. Signed-off-by: Henrik Brix Andersen --- drivers/can/can_mcux_flexcan.c | 3 ++- drivers/can/can_rcar.c | 2 ++ drivers/can/can_stm32.c | 2 ++ include/zephyr/drivers/can.h | 12 ++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/can/can_mcux_flexcan.c b/drivers/can/can_mcux_flexcan.c index d11e1085d013..064b3814f55d 100644 --- a/drivers/can/can_mcux_flexcan.c +++ b/drivers/can/can_mcux_flexcan.c @@ -204,7 +204,8 @@ static int mcux_flexcan_start(const struct device *dev) } } - /* Clear error counters */ + /* Reset statistics and clear error counters */ + CAN_STATS_RESET(dev); config->base->ECR &= ~(CAN_ECR_TXERRCNT_MASK | CAN_ECR_RXERRCNT_MASK); /* Delay this until start since setting the timing automatically exits freeze mode */ diff --git a/drivers/can/can_rcar.c b/drivers/can/can_rcar.c index 3c5f38e971b3..a96083458a04 100644 --- a/drivers/can/can_rcar.c +++ b/drivers/can/can_rcar.c @@ -592,6 +592,8 @@ static int can_rcar_start(const struct device *dev) k_mutex_lock(&data->inst_mutex, K_FOREVER); + CAN_STATS_RESET(dev); + ret = can_rcar_enter_operation_mode(config); if (ret != 0) { LOG_ERR("failed to enter operation mode (err %d)", ret); diff --git a/drivers/can/can_stm32.c b/drivers/can/can_stm32.c index 19c8a727bf2b..97af9c953845 100644 --- a/drivers/can/can_stm32.c +++ b/drivers/can/can_stm32.c @@ -383,6 +383,8 @@ static int can_stm32_start(const struct device *dev) } } + CAN_STATS_RESET(dev); + ret = can_stm32_leave_init_mode(can); if (ret < 0) { LOG_ERR("Failed to leave init mode"); diff --git a/include/zephyr/drivers/can.h b/include/zephyr/drivers/can.h index 3475f5541248..600b0fda3eb3 100644 --- a/include/zephyr/drivers/can.h +++ b/include/zephyr/drivers/can.h @@ -579,6 +579,17 @@ struct can_device_state { #define CAN_STATS_RX_OVERRUN_INC(dev_) \ STATS_INC(Z_CAN_GET_STATS(dev_), rx_overrun) +/** + * @brief Zero all statistics for a CAN device + * + * The driver is reponsible for resetting the statistics before starting the CAN + * controller. + * + * @param dev_ Pointer to the device structure for the driver instance. + */ +#define CAN_STATS_RESET(dev_) \ + stats_reset(&(Z_CAN_GET_STATS(dev_).s_hdr)) + /** @cond INTERNAL_HIDDEN */ /** @@ -647,6 +658,7 @@ struct can_device_state { #define CAN_STATS_FORM_ERROR_INC(dev_) #define CAN_STATS_ACK_ERROR_INC(dev_) #define CAN_STATS_RX_OVERRUN_INC(dev_) +#define CAN_STATS_RESET(dev_) #define CAN_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, \ prio, api, ...) \ From 65aae9cbfb7b87cd12f525c58d4dd4036bfcc722 Mon Sep 17 00:00:00 2001 From: Krishna T Date: Wed, 15 Mar 2023 13:14:04 +0530 Subject: [PATCH 0406/1906] net: wifi: Use micro seconds for precision for TWT intervals In order to take granular input use micro seconds as input for TWT intervals, this helps us in providing inputs such as 65.28ms without the need of using floating points. This also expands the TWT wake interval range to 262.144ms, earlier as we want to use uint8, limited to 256ms. Also, remove the units from the variable names, this is unnecessary and also avoids doing breaking changes. Update release notes as this is a breaking change, both type and variable names are changed. Signed-off-by: Krishna T --- doc/releases/release-notes-3.4.rst | 3 +++ include/zephyr/net/wifi_mgmt.h | 10 +++++----- subsys/net/l2/wifi/wifi_shell.c | 30 +++++++++++++++--------------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/doc/releases/release-notes-3.4.rst b/doc/releases/release-notes-3.4.rst index 818f7cf7811c..85558ed98f39 100644 --- a/doc/releases/release-notes-3.4.rst +++ b/doc/releases/release-notes-3.4.rst @@ -340,6 +340,9 @@ Trusted Firmware-M Networking ********** +* Wi-Fi + + * TWT intervals are changed from milli-seconds to micro-seconds, interval variables are also renamed. USB *** diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 365788996a79..148a1266c8d1 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -212,13 +212,13 @@ struct wifi_twt_params { union { struct { /* Interval = Wake up time + Sleeping time */ - uint32_t twt_interval_ms; + uint64_t twt_interval; bool responder; bool trigger; bool implicit; bool announce; /* Wake up time */ - uint8_t twt_wake_interval_ms; + uint32_t twt_wake_interval; } setup; struct { /* Only for Teardown */ @@ -229,10 +229,10 @@ struct wifi_twt_params { /* Flow ID is only 3 bits */ #define WIFI_MAX_TWT_FLOWS 8 -#define WIFI_MAX_TWT_INTERVAL_MS 0x7FFFFFFF +#define WIFI_MAX_TWT_INTERVAL_US (ULONG_MAX - 1) struct wifi_twt_flow_info { /* Interval = Wake up time + Sleeping time */ - uint32_t twt_interval_ms; + uint64_t twt_interval; /* Map requests to responses */ uint8_t dialog_token; /* Map setup with teardown */ @@ -243,7 +243,7 @@ struct wifi_twt_flow_info { bool implicit; bool announce; /* Wake up time */ - uint8_t twt_wake_interval_ms; + uint32_t twt_wake_interval; }; struct wifi_ps_config { diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index e5f6785e26f9..1ea6970ed2f9 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -160,10 +160,10 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb) /* If accepted, then no need to print TWT params */ if (resp->setup_cmd != WIFI_TWT_SETUP_CMD_ACCEPT) { print(context.sh, SHELL_NORMAL, - "TWT parameters: trigger: %s wake_interval: %d ms, interval: %d ms\n", + "TWT parameters: trigger: %s wake_interval: %d us, interval: %lld us\n", resp->setup.trigger ? "trigger" : "no_trigger", - resp->setup.twt_wake_interval_ms, - resp->setup.twt_interval_ms); + resp->setup.twt_wake_interval, + resp->setup.twt_interval); } } else { print(context.sh, SHELL_NORMAL, "TWT response timed out\n"); @@ -478,10 +478,10 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[]) config.twt_flows[i].trigger ? "true" : "false"); shell_fprintf(sh, SHELL_NORMAL, "TWT announce: %s\n", config.twt_flows[i].announce ? "true" : "false"); - shell_fprintf(sh, SHELL_NORMAL, "TWT wake interval: %d ms\n", - config.twt_flows[i].twt_wake_interval_ms); - shell_fprintf(sh, SHELL_NORMAL, "TWT interval: %d ms\n", - config.twt_flows[i].twt_interval_ms); + shell_fprintf(sh, SHELL_NORMAL, "TWT wake interval: %d us\n", + config.twt_flows[i].twt_wake_interval); + shell_fprintf(sh, SHELL_NORMAL, "TWT interval: %lld us\n", + config.twt_flows[i].twt_interval); shell_fprintf(sh, SHELL_NORMAL, "========================\n"); } } @@ -599,9 +599,9 @@ static int cmd_wifi_twt_setup_quick(const struct shell *sh, size_t argc, params.setup.trigger = 1; params.setup.announce = 0; - if (!parse_number(sh, (long *)¶ms.setup.twt_wake_interval_ms, argv[idx++], 1, 255) || - !parse_number(sh, (long *)¶ms.setup.twt_interval_ms, argv[idx++], 1, - WIFI_MAX_TWT_INTERVAL_MS)) + if (!parse_number(sh, (long *)¶ms.setup.twt_wake_interval, argv[idx++], 1, 255) || + !parse_number(sh, (long *)¶ms.setup.twt_interval, argv[idx++], 1, + WIFI_MAX_TWT_INTERVAL_US)) return -EINVAL; if (net_mgmt(NET_REQUEST_WIFI_TWT, iface, ¶ms, sizeof(params))) { @@ -648,9 +648,9 @@ static int cmd_wifi_twt_setup(const struct shell *sh, size_t argc, !parse_number(sh, (long *)¶ms.setup.trigger, argv[idx++], 0, 1) || !parse_number(sh, (long *)¶ms.setup.implicit, argv[idx++], 0, 1) || !parse_number(sh, (long *)¶ms.setup.announce, argv[idx++], 0, 1) || - !parse_number(sh, (long *)¶ms.setup.twt_wake_interval_ms, argv[idx++], 1, 255) || - !parse_number(sh, (long *)¶ms.setup.twt_interval_ms, argv[idx++], 1, - WIFI_MAX_TWT_INTERVAL_MS)) + !parse_number(sh, (long *)¶ms.setup.twt_wake_interval, argv[idx++], 1, 255) || + !parse_number(sh, (long *)¶ms.setup.twt_interval, argv[idx++], 1, + WIFI_MAX_TWT_INTERVAL_US)) return -EINVAL; params.negotiation_type = neg_type; @@ -849,13 +849,13 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap, SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops, SHELL_CMD(quick_setup, NULL, " Start a TWT flow with defaults:\n" - " \n", + " \n", cmd_wifi_twt_setup_quick), SHELL_CMD(setup, NULL, " Start a TWT flow:\n" "\n" "\n" " " - " \n", + " \n", cmd_wifi_twt_setup), SHELL_CMD(teardown, NULL, " Teardown a TWT flow:\n" "\n" From 5e6c733006d83546d56de90150e8a7b1cde0df9c Mon Sep 17 00:00:00 2001 From: Krishna T Date: Wed, 15 Mar 2023 14:44:39 +0530 Subject: [PATCH 0407/1906] net: wifi: Use a macro for TWT wake interval Remove the magic number 255, esp. now that we support 262.144ms. Signed-off-by: Krishna T --- include/zephyr/net/wifi_mgmt.h | 2 ++ subsys/net/l2/wifi/wifi_shell.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 148a1266c8d1..21282f05a1c9 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -230,6 +230,8 @@ struct wifi_twt_params { /* Flow ID is only 3 bits */ #define WIFI_MAX_TWT_FLOWS 8 #define WIFI_MAX_TWT_INTERVAL_US (ULONG_MAX - 1) +/* 256 (u8) * 1TU */ +#define WIFI_MAX_TWT_WAKE_INTERVAL_US 262144 struct wifi_twt_flow_info { /* Interval = Wake up time + Sleeping time */ uint64_t twt_interval; diff --git a/subsys/net/l2/wifi/wifi_shell.c b/subsys/net/l2/wifi/wifi_shell.c index 1ea6970ed2f9..8694eeb0cb72 100644 --- a/subsys/net/l2/wifi/wifi_shell.c +++ b/subsys/net/l2/wifi/wifi_shell.c @@ -599,7 +599,8 @@ static int cmd_wifi_twt_setup_quick(const struct shell *sh, size_t argc, params.setup.trigger = 1; params.setup.announce = 0; - if (!parse_number(sh, (long *)¶ms.setup.twt_wake_interval, argv[idx++], 1, 255) || + if (!parse_number(sh, (long *)¶ms.setup.twt_wake_interval, argv[idx++], + 1, WIFI_MAX_TWT_WAKE_INTERVAL_US) || !parse_number(sh, (long *)¶ms.setup.twt_interval, argv[idx++], 1, WIFI_MAX_TWT_INTERVAL_US)) return -EINVAL; @@ -648,7 +649,8 @@ static int cmd_wifi_twt_setup(const struct shell *sh, size_t argc, !parse_number(sh, (long *)¶ms.setup.trigger, argv[idx++], 0, 1) || !parse_number(sh, (long *)¶ms.setup.implicit, argv[idx++], 0, 1) || !parse_number(sh, (long *)¶ms.setup.announce, argv[idx++], 0, 1) || - !parse_number(sh, (long *)¶ms.setup.twt_wake_interval, argv[idx++], 1, 255) || + !parse_number(sh, (long *)¶ms.setup.twt_wake_interval, argv[idx++], 1, + WIFI_MAX_TWT_WAKE_INTERVAL_US) || !parse_number(sh, (long *)¶ms.setup.twt_interval, argv[idx++], 1, WIFI_MAX_TWT_INTERVAL_US)) return -EINVAL; From 1c7feb3fd493505595912006a06805ba3369f2f4 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Thu, 16 Mar 2023 13:56:18 +0100 Subject: [PATCH 0408/1906] drivers: can: shell: show min/max timing parameters Include the minimum/maximum timing parameters when showing details about a CAN controller. Signed-off-by: Henrik Brix Andersen --- drivers/can/can_shell.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/can/can_shell.c b/drivers/can/can_shell.c index 5e0ad6d87227..a3dacc099f8d 100644 --- a/drivers/can/can_shell.c +++ b/drivers/can/can_shell.c @@ -273,6 +273,8 @@ static int cmd_can_stop(const struct shell *sh, size_t argc, char **argv) static int cmd_can_show(const struct shell *sh, size_t argc, char **argv) { const struct device *dev = device_get_binding(argv[1]); + const struct can_timing *timing_min; + const struct can_timing *timing_max; struct can_bus_err_cnt err_cnt; enum can_state state; uint32_t max_bitrate = 0; @@ -336,6 +338,30 @@ static int cmd_can_show(const struct shell *sh, size_t argc, char **argv) shell_print(sh, "rx errors: %d", err_cnt.rx_err_cnt); shell_print(sh, "tx errors: %d", err_cnt.tx_err_cnt); + timing_min = can_get_timing_min(dev); + timing_max = can_get_timing_max(dev); + + shell_print(sh, "timing: sjw %u..%u, prop_seg %u..%u, " + "phase_seg1 %u..%u, phase_seg2 %u..%u, prescaler %u..%u", + timing_min->sjw, timing_max->sjw, + timing_min->prop_seg, timing_max->prop_seg, + timing_min->phase_seg1, timing_max->phase_seg1, + timing_min->phase_seg2, timing_max->phase_seg2, + timing_min->prescaler, timing_max->prescaler); + + if (IS_ENABLED(CONFIG_CAN_FD_MODE) && (cap & CAN_MODE_FD) != 0) { + timing_min = can_get_timing_data_min(dev); + timing_max = can_get_timing_data_max(dev); + + shell_print(sh, "timing data: sjw %u..%u, prop_seg %u..%u, " + "phase_seg1 %u..%u, phase_seg2 %u..%u, prescaler %u..%u", + timing_min->sjw, timing_max->sjw, + timing_min->prop_seg, timing_max->prop_seg, + timing_min->phase_seg1, timing_max->phase_seg1, + timing_min->phase_seg2, timing_max->phase_seg2, + timing_min->prescaler, timing_max->prescaler); + } + return 0; } From 37b3a11d72456ee986efaab64808cbbcd81a824b Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Thu, 16 Mar 2023 13:57:55 +0100 Subject: [PATCH 0409/1906] drivers: can: shell: add debug log for calculated timing parameters Add debug logs for the timing parameters calculated by the shell commands. Signed-off-by: Henrik Brix Andersen --- drivers/can/can_shell.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/can/can_shell.c b/drivers/can/can_shell.c index a3dacc099f8d..a6e3e8045af1 100644 --- a/drivers/can/can_shell.c +++ b/drivers/can/can_shell.c @@ -421,6 +421,10 @@ static int cmd_can_bitrate_set(const struct shell *sh, size_t argc, char **argv) timing.sjw); } + LOG_DBG("sjw %u, prop_seg %u, phase_seg1 %u, phase_seg2 %u, prescaler %u", + timing.sjw, timing.prop_seg, timing.phase_seg1, timing.phase_seg2, + timing.prescaler); + err = can_set_timing(dev, &timing); if (err != 0) { shell_error(sh, "failed to set timing (err %d)", err); @@ -495,6 +499,10 @@ static int cmd_can_dbitrate_set(const struct shell *sh, size_t argc, char **argv timing.sjw); } + LOG_DBG("sjw %u, prop_seg %u, phase_seg1 %u, phase_seg2 %u, prescaler %u", + timing.sjw, timing.prop_seg, timing.phase_seg1, timing.phase_seg2, + timing.prescaler); + err = can_set_timing_data(dev, &timing); if (err != 0) { shell_error(sh, "failed to set data timing (err %d)", err); From 3c6b7dc35a47226e052fa25c56b7b1891026e44d Mon Sep 17 00:00:00 2001 From: Georges Oates_Larsen Date: Thu, 19 Jan 2023 14:17:55 -0800 Subject: [PATCH 0410/1906] net: dummy L2 for offloaded ifaces Adds dummy link layer for offloaded ifaces, allowing ifaces to directly receive l2_enable calls Signed-off-by: Georges Oates_Larsen --- drivers/modem/hl7800.c | 5 +- drivers/modem/quectel-bg9x.c | 4 +- drivers/modem/quectel-bg9x.h | 1 + drivers/modem/simcom-sim7080.c | 5 +- drivers/modem/ublox-sara-r4.c | 5 +- drivers/modem/wncm14a2a.c | 5 +- drivers/wifi/esp_at/esp.c | 14 ++--- drivers/wifi/eswifi/eswifi_core.c | 12 ++-- drivers/wifi/simplelink/simplelink.c | 8 +-- drivers/wifi/winc1500/wifi_winc1500.c | 12 ++-- include/zephyr/net/net_if.h | 1 + include/zephyr/net/net_l2.h | 5 ++ include/zephyr/net/offloaded_netdev.h | 58 +++++++++++++++++++ include/zephyr/net/wifi_mgmt.h | 3 +- subsys/net/ip/net_if.c | 8 --- subsys/net/l2/CMakeLists.txt | 4 ++ subsys/net/l2/offloaded_netdev/CMakeLists.txt | 5 ++ .../l2/offloaded_netdev/offloaded_netdev.c | 22 +++++++ tests/net/all/src/main.c | 18 ++++-- .../net/socket/offload_dispatcher/src/main.c | 9 +-- 20 files changed, 153 insertions(+), 51 deletions(-) create mode 100644 include/zephyr/net/offloaded_netdev.h create mode 100644 subsys/net/l2/offloaded_netdev/CMakeLists.txt create mode 100644 subsys/net/l2/offloaded_netdev/offloaded_netdev.c diff --git a/drivers/modem/hl7800.c b/drivers/modem/hl7800.c index 792f0c84e189..c80787e806e9 100644 --- a/drivers/modem/hl7800.c +++ b/drivers/modem/hl7800.c @@ -29,6 +29,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_MODEM_LOG_LEVEL); #include #include #include +#include #if defined(CONFIG_NET_IPV6) #include "ipv6.h" #endif @@ -6424,8 +6425,8 @@ static void offload_iface_init(struct net_if *iface) } } -static struct net_if_api api_funcs = { - .init = offload_iface_init, +static struct offloaded_if_api api_funcs = { + .iface_api.init = offload_iface_init, }; NET_DEVICE_DT_INST_OFFLOAD_DEFINE(0, hl7800_init, NULL, &ictx, diff --git a/drivers/modem/quectel-bg9x.c b/drivers/modem/quectel-bg9x.c index 75d49c4cafc8..40baa2c21d63 100644 --- a/drivers/modem/quectel-bg9x.c +++ b/drivers/modem/quectel-bg9x.c @@ -1096,8 +1096,8 @@ static void modem_net_iface_init(struct net_if *iface) net_if_socket_offload_set(iface, offload_socket); } -static struct net_if_api api_funcs = { - .init = modem_net_iface_init, +static struct offloaded_if_api api_funcs = { + .iface_api.init = modem_net_iface_init, }; static bool offload_is_supported(int family, int type, int proto) diff --git a/drivers/modem/quectel-bg9x.h b/drivers/modem/quectel-bg9x.h index a4541b0af1b9..899f1ece8877 100644 --- a/drivers/modem/quectel-bg9x.h +++ b/drivers/modem/quectel-bg9x.h @@ -15,6 +15,7 @@ #include #include +#include #include #include diff --git a/drivers/modem/simcom-sim7080.c b/drivers/modem/simcom-sim7080.c index f92a885cfee7..a9256d9a45d3 100644 --- a/drivers/modem/simcom-sim7080.c +++ b/drivers/modem/simcom-sim7080.c @@ -7,6 +7,7 @@ #define DT_DRV_COMPAT simcom_sim7080 #include +#include LOG_MODULE_REGISTER(modem_simcom_sim7080, CONFIG_MODEM_LOG_LEVEL); #include @@ -760,8 +761,8 @@ const struct socket_dns_offload offload_dns_ops = { .freeaddrinfo = offload_freeaddrinfo, }; -static struct net_if_api api_funcs = { - .init = modem_net_iface_init, +static struct offloaded_if_api api_funcs = { + .iface_api.init = modem_net_iface_init, }; static bool offload_is_supported(int family, int type, int proto) diff --git a/drivers/modem/ublox-sara-r4.c b/drivers/modem/ublox-sara-r4.c index d1f32165d6cd..29587839757c 100644 --- a/drivers/modem/ublox-sara-r4.c +++ b/drivers/modem/ublox-sara-r4.c @@ -19,6 +19,7 @@ LOG_MODULE_REGISTER(modem_ublox_sara_r4, CONFIG_MODEM_LOG_LEVEL); #include #include +#include #include #if defined(CONFIG_MODEM_UBLOX_SARA_AUTODETECT_APN) @@ -2103,8 +2104,8 @@ static void modem_net_iface_init(struct net_if *iface) net_if_socket_offload_set(iface, offload_socket); } -static struct net_if_api api_funcs = { - .init = modem_net_iface_init, +static struct offloaded_if_api api_funcs = { + .iface_api.init = modem_net_iface_init, }; static const struct modem_cmd response_cmds[] = { diff --git a/drivers/modem/wncm14a2a.c b/drivers/modem/wncm14a2a.c index ca805a1409f3..1dc0a7332a23 100644 --- a/drivers/modem/wncm14a2a.c +++ b/drivers/modem/wncm14a2a.c @@ -25,6 +25,7 @@ LOG_MODULE_REGISTER(LOG_DOMAIN); #include #include #include +#include #include #if defined(CONFIG_NET_IPV6) #include "ipv6.h" @@ -1773,8 +1774,8 @@ static void offload_iface_init(struct net_if *iface) ctx->iface = iface; } -static struct net_if_api api_funcs = { - .init = offload_iface_init, +static struct offloaded_if_api api_funcs = { + .iface_api.init = offload_iface_init, }; NET_DEVICE_DT_INST_OFFLOAD_DEFINE(0, wncm14a2a_init, NULL, diff --git a/drivers/wifi/esp_at/esp.c b/drivers/wifi/esp_at/esp.c index 4236c91f7267..b1dcd9d6befc 100644 --- a/drivers/wifi/esp_at/esp.c +++ b/drivers/wifi/esp_at/esp.c @@ -1217,13 +1217,13 @@ static void esp_iface_init(struct net_if *iface) } static const struct net_wifi_mgmt_offload esp_api = { - .wifi_iface.init = esp_iface_init, - .scan = esp_mgmt_scan, - .connect = esp_mgmt_connect, - .disconnect = esp_mgmt_disconnect, - .ap_enable = esp_mgmt_ap_enable, - .ap_disable = esp_mgmt_ap_disable, - .iface_status = esp_mgmt_iface_status, + .wifi_iface.iface_api.init = esp_iface_init, + .scan = esp_mgmt_scan, + .connect = esp_mgmt_connect, + .disconnect = esp_mgmt_disconnect, + .ap_enable = esp_mgmt_ap_enable, + .ap_disable = esp_mgmt_ap_disable, + .iface_status = esp_mgmt_iface_status, }; static int esp_init(const struct device *dev); diff --git a/drivers/wifi/eswifi/eswifi_core.c b/drivers/wifi/eswifi/eswifi_core.c index b6960ffd8cdf..79e403c09b13 100644 --- a/drivers/wifi/eswifi/eswifi_core.c +++ b/drivers/wifi/eswifi/eswifi_core.c @@ -679,12 +679,12 @@ static int eswifi_init(const struct device *dev) } static const struct net_wifi_mgmt_offload eswifi_offload_api = { - .wifi_iface.init = eswifi_iface_init, - .scan = eswifi_mgmt_scan, - .connect = eswifi_mgmt_connect, - .disconnect = eswifi_mgmt_disconnect, - .ap_enable = eswifi_mgmt_ap_enable, - .ap_disable = eswifi_mgmt_ap_disable, + .wifi_iface.iface_api.init = eswifi_iface_init, + .scan = eswifi_mgmt_scan, + .connect = eswifi_mgmt_connect, + .disconnect = eswifi_mgmt_disconnect, + .ap_enable = eswifi_mgmt_ap_enable, + .ap_disable = eswifi_mgmt_ap_disable, }; NET_DEVICE_DT_INST_OFFLOAD_DEFINE(0, eswifi_init, NULL, diff --git a/drivers/wifi/simplelink/simplelink.c b/drivers/wifi/simplelink/simplelink.c index a60ac990b636..b75329e49f43 100644 --- a/drivers/wifi/simplelink/simplelink.c +++ b/drivers/wifi/simplelink/simplelink.c @@ -264,10 +264,10 @@ static void simplelink_iface_init(struct net_if *iface) } static const struct net_wifi_mgmt_offload simplelink_api = { - .wifi_iface.init = simplelink_iface_init, - .scan = simplelink_mgmt_scan, - .connect = simplelink_mgmt_connect, - .disconnect = simplelink_mgmt_disconnect, + .wifi_iface.iface_api.init = simplelink_iface_init, + .scan = simplelink_mgmt_scan, + .connect = simplelink_mgmt_connect, + .disconnect = simplelink_mgmt_disconnect, }; static int simplelink_init(const struct device *dev) diff --git a/drivers/wifi/winc1500/wifi_winc1500.c b/drivers/wifi/winc1500/wifi_winc1500.c index 94049a9ab6f9..329e18a8a68c 100644 --- a/drivers/wifi/winc1500/wifi_winc1500.c +++ b/drivers/wifi/winc1500/wifi_winc1500.c @@ -1100,12 +1100,12 @@ static void winc1500_iface_init(struct net_if *iface) } static const struct net_wifi_mgmt_offload winc1500_api = { - .wifi_iface.init = winc1500_iface_init, - .scan = winc1500_mgmt_scan, - .connect = winc1500_mgmt_connect, - .disconnect = winc1500_mgmt_disconnect, - .ap_enable = winc1500_mgmt_ap_enable, - .ap_disable = winc1500_mgmt_ap_disable, + .wifi_iface.iface_api.init = winc1500_iface_init, + .scan = winc1500_mgmt_scan, + .connect = winc1500_mgmt_connect, + .disconnect = winc1500_mgmt_disconnect, + .ap_enable = winc1500_mgmt_ap_enable, + .ap_disable = winc1500_mgmt_ap_disable, }; static int winc1500_init(const struct device *dev) diff --git a/include/zephyr/net/net_if.h b/include/zephyr/net/net_if.h index 31928ddde480..58bf925ee6ff 100644 --- a/include/zephyr/net/net_if.h +++ b/include/zephyr/net/net_if.h @@ -2468,6 +2468,7 @@ struct net_if_api { NET_IF_DEV_GET_NAME(dev_id, sfx)) = { \ .dev = &(DEVICE_NAME_GET(dev_id)), \ .mtu = _mtu, \ + .l2 = &(NET_L2_GET_NAME(OFFLOADED_NETDEV)), \ }; \ static Z_DECL_ALIGN(struct net_if) \ NET_IF_GET_NAME(dev_id, sfx)[NET_IF_MAX_CONFIGS] \ diff --git a/include/zephyr/net/net_l2.h b/include/zephyr/net/net_l2.h index 1c792cf896dc..98ce34d2aef1 100644 --- a/include/zephyr/net/net_l2.h +++ b/include/zephyr/net/net_l2.h @@ -95,6 +95,11 @@ NET_L2_DECLARE_PUBLIC(VIRTUAL_L2); NET_L2_DECLARE_PUBLIC(DUMMY_L2); #endif /* CONFIG_NET_L2_DUMMY */ +#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_SOCKETS_OFFLOAD) +#define OFFLOADED_NETDEV_L2 OFFLOADED_NETDEV +NET_L2_DECLARE_PUBLIC(OFFLOADED_NETDEV_L2); +#endif /* CONFIG_NET_L2_ETHERNET */ + #ifdef CONFIG_NET_L2_ETHERNET #define ETHERNET_L2 ETHERNET NET_L2_DECLARE_PUBLIC(ETHERNET_L2); diff --git a/include/zephyr/net/offloaded_netdev.h b/include/zephyr/net/offloaded_netdev.h new file mode 100644 index 000000000000..5f778680ba27 --- /dev/null +++ b/include/zephyr/net/offloaded_netdev.h @@ -0,0 +1,58 @@ +/** @file + * @brief Offloaded network device iface API + * + * This is not to be included by the application. + */ + +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_OFFLOADED_NETDEV_H_ +#define ZEPHYR_INCLUDE_OFFLOADED_NETDEV_H_ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Offloaded Net Devices + * @defgroup offloaded_netdev Offloaded Net Devices + * @ingroup networking + * @{ + */ + +/** + * @brief Extended net_if_api for offloaded ifaces/network devices, allowing handling of + * admin up/down state changes + */ +struct offloaded_if_api { + /** + * The net_if_api must be placed in first position in this + * struct so that we are compatible with network interface API. + */ + struct net_if_api iface_api; + + /** Enable or disable the device (in response to admin state change) */ + int (*enable)(const struct net_if *iface, bool state); +}; + +/* Ensure offloaded_if_api is compatible with net_if_api */ +BUILD_ASSERT(offsetof(struct offloaded_if_api, iface_api) == 0); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_OFFLOADED_NETDEV_H_ */ diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 21282f05a1c9..b4538ec853e4 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -15,6 +15,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -288,7 +289,7 @@ struct net_wifi_mgmt_offload { #ifdef CONFIG_WIFI_USE_NATIVE_NETWORKING struct ethernet_api wifi_iface; #else - struct net_if_api wifi_iface; + struct offloaded_if_api wifi_iface; #endif /* cb parameter is the cb that should be called for each diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 1b6f5a6d51d7..aa94c5b92e5a 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -4202,10 +4202,6 @@ int net_if_up(struct net_if *iface) goto out; } - if (is_iface_offloaded(iface)) { - goto done; - } - /* If the L2 does not support enable just set the flag */ if (!net_if_l2(iface) || !net_if_l2(iface)->enable) { goto done; @@ -4246,10 +4242,6 @@ int net_if_down(struct net_if *iface) leave_mcast_all(iface); leave_ipv4_mcast_all(iface); - if (is_iface_offloaded(iface)) { - goto done; - } - /* If the L2 does not support enable just clear the flag */ if (!net_if_l2(iface) || !net_if_l2(iface)->enable) { goto done; diff --git a/subsys/net/l2/CMakeLists.txt b/subsys/net/l2/CMakeLists.txt index 18782862be7c..0d68a4ef7918 100644 --- a/subsys/net/l2/CMakeLists.txt +++ b/subsys/net/l2/CMakeLists.txt @@ -12,6 +12,10 @@ if(CONFIG_NET_L2_DUMMY) add_subdirectory(dummy) endif() +if (CONFIG_NET_OFFLOAD OR CONFIG_NET_SOCKETS_OFFLOAD) + add_subdirectory(offloaded_netdev) +endif() + if(CONFIG_NET_L2_ETHERNET) add_subdirectory(ethernet) endif() diff --git a/subsys/net/l2/offloaded_netdev/CMakeLists.txt b/subsys/net/l2/offloaded_netdev/CMakeLists.txt new file mode 100644 index 000000000000..9cc64a7b9367 --- /dev/null +++ b/subsys/net/l2/offloaded_netdev/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright (c) 2022 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() +zephyr_library_sources(offloaded_netdev.c) diff --git a/subsys/net/l2/offloaded_netdev/offloaded_netdev.c b/subsys/net/l2/offloaded_netdev/offloaded_netdev.c new file mode 100644 index 000000000000..12fd3d007d12 --- /dev/null +++ b/subsys/net/l2/offloaded_netdev/offloaded_netdev.c @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +static inline int offloaded_netdev_if_enable(struct net_if *iface, bool state) +{ + const struct offloaded_if_api *off_if = net_if_get_device(iface)->api; + + if (!off_if || !(off_if->enable)) { + return 0; + } + + return off_if->enable(iface, state); +} + +NET_L2_INIT(OFFLOADED_NETDEV, NULL, NULL, offloaded_netdev_if_enable, NULL); diff --git a/tests/net/all/src/main.c b/tests/net/all/src/main.c index 83d5bfbff009..7e63508f8505 100644 --- a/tests/net/all/src/main.c +++ b/tests/net/all/src/main.c @@ -18,23 +18,31 @@ LOG_MODULE_REGISTER(net_test, LOG_LEVEL_DBG); #include #include #include +#include + +/* Create blank dummy and offloaded APIs */ +static struct offloaded_if_api offload_dev_api; +static const struct dummy_api dummy_dev_api; static struct offload_context { void *none; } offload_context_data = { .none = NULL }; -static struct dummy_api offload_if_api = { - .iface_api.init = NULL, - .send = NULL, -}; +/* Create blank dummy and offloaded net devices */ +NET_DEVICE_INIT(dummy_dev, "dummy_dev", + NULL, NULL, + NULL, NULL, + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &dummy_dev_api, + DUMMY_L2, NET_L2_GET_CTX_TYPE(DUMMY_L2), 0); NET_DEVICE_OFFLOAD_INIT(net_offload, "net_offload", NULL, NULL, &offload_context_data, NULL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, - &offload_if_api, 0); + &offload_dev_api, 0); ZTEST(net_compile_all_test, test_ok) { diff --git a/tests/net/socket/offload_dispatcher/src/main.c b/tests/net/socket/offload_dispatcher/src/main.c index cf0d9f2d1614..d6469c1d51c7 100644 --- a/tests/net/socket/offload_dispatcher/src/main.c +++ b/tests/net/socket/offload_dispatcher/src/main.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -306,8 +307,8 @@ static void offloaded_1_iface_init(struct net_if *iface) net_if_socket_offload_set(iface, offload_1_socket); } -static struct net_if_api offloaded_1_if_api = { - .init = offloaded_1_iface_init, +static struct offloaded_if_api offloaded_1_if_api = { + .iface_api.init = offloaded_1_iface_init, }; NET_DEVICE_OFFLOAD_INIT(offloaded_1, "offloaded_1", offloaded_1_init, NULL, @@ -376,8 +377,8 @@ static void offloaded_2_iface_init(struct net_if *iface) net_if_socket_offload_set(iface, offload_2_socket); } -static struct net_if_api offloaded_2_if_api = { - .init = offloaded_2_iface_init, +static struct offloaded_if_api offloaded_2_if_api = { + .iface_api.init = offloaded_2_iface_init, }; NET_DEVICE_OFFLOAD_INIT(offloaded_2, "offloaded_2", offloaded_2_init, NULL, From cac932d849145555f6af882f681b8d1aceed62ad Mon Sep 17 00:00:00 2001 From: Georges Oates_Larsen Date: Thu, 19 Jan 2023 14:20:38 -0800 Subject: [PATCH 0411/1906] tests: net: Add tests for offloaded_netdev Adds integration tests for offloaded_netdev iface API extension Signed-off-by: Georges Oates_Larsen --- tests/net/offloaded_netdev/CMakeLists.txt | 9 + tests/net/offloaded_netdev/prj.conf | 10 + tests/net/offloaded_netdev/src/main.c | 343 ++++++++++++++++++++++ tests/net/offloaded_netdev/testcase.yaml | 6 + 4 files changed, 368 insertions(+) create mode 100644 tests/net/offloaded_netdev/CMakeLists.txt create mode 100644 tests/net/offloaded_netdev/prj.conf create mode 100644 tests/net/offloaded_netdev/src/main.c create mode 100644 tests/net/offloaded_netdev/testcase.yaml diff --git a/tests/net/offloaded_netdev/CMakeLists.txt b/tests/net/offloaded_netdev/CMakeLists.txt new file mode 100644 index 000000000000..07637dbc989b --- /dev/null +++ b/tests/net/offloaded_netdev/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(offloaded_netdev) + +target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/net/ip) +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/net/offloaded_netdev/prj.conf b/tests/net/offloaded_netdev/prj.conf new file mode 100644 index 000000000000..8bdc82930bb4 --- /dev/null +++ b/tests/net/offloaded_netdev/prj.conf @@ -0,0 +1,10 @@ +CONFIG_NETWORKING=y +CONFIG_NET_TEST=y +CONFIG_NET_SOCKETS=y +CONFIG_NET_SOCKETS_OFFLOAD=y +CONFIG_NET_LOG=y +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_TEST_USERSPACE=y +CONFIG_NET_OFFLOAD=y +CONFIG_TEST_RANDOM_GENERATOR=y diff --git a/tests/net/offloaded_netdev/src/main.c b/tests/net/offloaded_netdev/src/main.c new file mode 100644 index 000000000000..7ceb3295b607 --- /dev/null +++ b/tests/net/offloaded_netdev/src/main.c @@ -0,0 +1,343 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +/* Offloaded L2 initializer, mandatory for offloaded L2s */ +static int offload_l2_init(const struct device *dev) +{ + ARG_UNUSED(dev); + + return 0; +} + +/* Dummy socket creator for socket-offloaded ifaces */ +int offload_socket(int family, int type, int proto) +{ + return -1; +} + +/* Dummy offload API for net-offloaded ifaces */ +struct net_offload net_offload_api; + +/* Dummy init function for socket-offloaded ifaces */ +static void sock_offload_l2_iface_init(struct net_if *iface) +{ + /* This must be called, and the passed-in socket creator cannot be NULL, + * or the iface will not be recognized as offloaded + */ + net_if_socket_offload_set(iface, offload_socket); + net_if_flag_set(iface, NET_IF_NO_AUTO_START); +} + +/* Dummy init function for net-offloaded ifaces */ +static void net_offload_l2_iface_init(struct net_if *iface) +{ + /* Reviewers: Is there a better way to do this? + * I couldn't find any actual examples in the source + */ + iface->if_dev->offload = &net_offload_api; + net_if_flag_set(iface, NET_IF_NO_AUTO_START); +} + +/* Tracks the total number of ifaces that are up (theoretically). */ +atomic_t up_count = ATOMIC_INIT(0); + +/* Tracks the total number of times that the offload_impl_enable callback was called. */ +atomic_t call_count = ATOMIC_INIT(0); + +/* Expected return value from offload_impl_enable */ +atomic_t retval = ATOMIC_INIT(0); + +/* Functionality under test */ +static int offload_impl_enable(const struct net_if *iface, bool enabled) +{ + atomic_inc(&call_count); + if (enabled) { + atomic_inc(&up_count); + } else { + atomic_dec(&up_count); + } + return atomic_get(&retval); +} + +/* Net-dev APIs for L2s with offloaded sockets, with and without .enable */ +static struct offloaded_if_api sock_offloaded_impl_api = { + .iface_api.init = sock_offload_l2_iface_init, + .enable = offload_impl_enable +}; + +static struct offloaded_if_api sock_offloaded_no_impl_api = { + .iface_api.init = sock_offload_l2_iface_init +}; + +/* Net-dev APIs for L2s that are net-offloaded, with and without .enable */ +static struct offloaded_if_api net_offloaded_impl_api = { + .iface_api.init = net_offload_l2_iface_init, + .enable = offload_impl_enable +}; + +static struct offloaded_if_api net_offloaded_no_impl_api = { + .iface_api.init = net_offload_l2_iface_init +}; + + +/* Socket-offloaded netdevs, with and without .enable */ +NET_DEVICE_OFFLOAD_INIT(sock_offload_test_impl, "sock_offload_test_impl", + offload_l2_init, NULL, + NULL, NULL, + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &sock_offloaded_impl_api, 0); + +NET_DEVICE_OFFLOAD_INIT(sock_offload_test_no_impl, "sock_offload_test_no_impl", + offload_l2_init, NULL, + NULL, NULL, + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &sock_offloaded_no_impl_api, 0); + +/* Net-offloaded netdevs, with and without .enable */ +NET_DEVICE_OFFLOAD_INIT(net_offload_test_impl, "net_offload_test_impl", + offload_l2_init, NULL, + NULL, NULL, + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &net_offloaded_impl_api, 0); + +NET_DEVICE_OFFLOAD_INIT(net_offload_test_no_impl, "net_offload_test_no_impl", + offload_l2_init, NULL, + NULL, NULL, + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, + &net_offloaded_no_impl_api, 0); + +static void net_offloaded_netdev_before(void *fixture) +{ + ARG_UNUSED(fixture); + + /* Default to successful return value */ + atomic_set(&retval, 0); + + /* Reset all ifaces */ + net_if_down(NET_IF_GET(sock_offload_test_impl, 0)); + net_if_down(NET_IF_GET(sock_offload_test_no_impl, 0)); + net_if_down(NET_IF_GET(net_offload_test_impl, 0)); + net_if_down(NET_IF_GET(net_offload_test_impl, 0)); + + /* Reset counters */ + atomic_set(&call_count, 0); + atomic_set(&up_count, 0); +} + +ZTEST(net_offloaded_netdev, test_up_down_sock_off_impl) +{ + struct net_if *test_iface = NET_IF_GET(sock_offload_test_impl, 0); + + /* Verify iface under test is down before test */ + zassert_false(net_if_is_admin_up(test_iface), + "Iface under test must be admin-down before test"); + + /* Bring iface up. */ + (void)net_if_up(test_iface); + + /* Verify that a single iface went up once (according to the enable callback) */ + zassert_equal(atomic_get(&call_count), 1, + "Bad transition-count, offload_impl_enable not called correctly"); + zassert_equal(atomic_get(&up_count), 1, + "Bad up-count, offload_impl_enable not called correctly"); + zassert_true(net_if_is_admin_up(test_iface), + "Iface under test should be up after net_if_up"); + + /* Bring iface down */ + (void)net_if_down(test_iface); + + /* Verify that a single iface went down once (according to the enable callback)*/ + zassert_equal(atomic_get(&call_count), 2, + "Bad transition-count, offload_impl_enable not called correctly"); + zassert_equal(atomic_get(&up_count), 0, + "Bad up-count, offload_impl_enable not called correctly"); + zassert_false(net_if_is_admin_up(test_iface), + "Iface under test should be down after net_if_down"); +} + +ZTEST(net_offloaded_netdev, test_up_down_sock_off_no_impl) +{ + struct net_if *test_iface = NET_IF_GET(sock_offload_test_no_impl, 0); + + /* Verify iface under test is down before test */ + zassert_false(net_if_is_admin_up(test_iface), + "Iface under test must be admin-down before test"); + + /* Bring iface up */ + (void)net_if_up(test_iface); + + /* Verify that the iface went up, but callbacks were not fired*/ + zassert_equal(atomic_get(&call_count), 0, + "offload_impl_enable was called unexpectedly"); + zassert_equal(atomic_get(&up_count), 0, + "offload_impl_enable was called unexpectedly"); + zassert_true(net_if_is_admin_up(test_iface), + "Iface under test should be up after net_if_up"); + + /* Bring iface down */ + (void)net_if_down(test_iface); + + /* Verify that the iface went down, but callbacks were not fired*/ + zassert_equal(atomic_get(&call_count), 0, + "offload_impl_enable was called unexpectedly"); + zassert_equal(atomic_get(&up_count), 0, + "offload_impl_enable was called unexpectedly"); + zassert_false(net_if_is_admin_up(test_iface), + "Iface under test should be down after net_if_down"); +} + +ZTEST(net_offloaded_netdev, test_up_down_net_off_impl) +{ + struct net_if *test_iface = NET_IF_GET(net_offload_test_impl, 0); + + /* Verify iface under test is down before test */ + zassert_false(net_if_is_admin_up(test_iface), + "Iface under test must be admin-down before test"); + + /* Bring iface up. */ + (void)net_if_up(test_iface); + + /* Verify that a single iface went up once (according to the enable callback) */ + zassert_equal(atomic_get(&call_count), 1, + "Bad transition-count, offload_impl_enable not called correctly"); + zassert_equal(atomic_get(&up_count), 1, + "Bad up-count, offload_impl_enable not called correctly"); + zassert_true(net_if_is_admin_up(test_iface), + "Iface under test should be up after net_if_up"); + + /* Bring iface down */ + (void)net_if_down(test_iface); + + /* Verify that a single iface went down once (according to the enable callback)*/ + zassert_equal(atomic_get(&call_count), 2, + "Bad transition-count, offload_impl_enable not called correctly"); + zassert_equal(atomic_get(&up_count), 0, + "Bad up-count, offload_impl_enable not called correctly"); + zassert_false(net_if_is_admin_up(test_iface), + "Iface under test should be down after net_if_down"); +} + +ZTEST(net_offloaded_netdev, test_up_down_net_off_no_impl) +{ + struct net_if *test_iface = NET_IF_GET(net_offload_test_no_impl, 0); + + /* Verify iface under test is down before test */ + zassert_false(net_if_is_admin_up(test_iface), + "Iface under test must be admin-down before test"); + + /* Bring iface up */ + (void)net_if_up(test_iface); + + /* Verify that the iface went up, but callbacks were not fired*/ + zassert_equal(atomic_get(&call_count), 0, + "offload_impl_enable was called unexpectedly"); + zassert_equal(atomic_get(&up_count), 0, + "offload_impl_enable was called unexpectedly"); + zassert_true(net_if_is_admin_up(test_iface), + "Iface under test should be up after net_if_up"); + + /* Bring iface down */ + (void)net_if_down(test_iface); + + /* Verify that the iface went down, but callbacks were not fired*/ + zassert_equal(atomic_get(&call_count), 0, + "offload_impl_enable was called unexpectedly"); + zassert_equal(atomic_get(&up_count), 0, + "offload_impl_enable was called unexpectedly"); + zassert_false(net_if_is_admin_up(test_iface), + "Iface under test should be down after net_if_down"); +} + +ZTEST(net_offloaded_netdev, test_up_down_sock_off_impl_double) +{ + struct net_if *test_iface = NET_IF_GET(sock_offload_test_impl, 0); + + /* Verify iface under test is down before test */ + zassert_false(net_if_is_admin_up(test_iface), + "Iface under test must be admin-down before test"); + + /* Bring iface up twice */ + (void)net_if_up(test_iface); + (void)net_if_up(test_iface); + + /* Verify that a single iface went up once (according to the enable callback)*/ + zassert_equal(atomic_get(&call_count), 1, + "Bad transition-count, offload_impl_enable not called correctly"); + zassert_equal(atomic_get(&up_count), 1, + "Bad up-count, offload_impl_enable not called correctly"); + zassert_true(net_if_is_admin_up(test_iface), + "Iface under test should be up after net_if_up"); + + /* Verify that a single iface went down once (according to the enable callback)*/ + (void)net_if_down(test_iface); + (void)net_if_down(test_iface); + + /* Verify appropriate calls were made */ + zassert_equal(atomic_get(&call_count), 2, + "Bad transition-count, offload_impl_enable not called correctly"); + zassert_equal(atomic_get(&up_count), 0, + "Bad up-count, offload_impl_enable not called correctly"); + zassert_false(net_if_is_admin_up(test_iface), + "Iface under test should be down after net_if_down"); +} + +ZTEST(net_offloaded_netdev, test_up_down_sock_off_impl_fail_up) +{ + struct net_if *test_iface = NET_IF_GET(sock_offload_test_impl, 0); + + /* Verify iface under test is down before test */ + zassert_false(net_if_is_admin_up(test_iface), + "Iface under test must be admin-down before test"); + + /* Instruct the enable callback to fail */ + atomic_set(&retval, -E2BIG); + + /* Expect net_if_up to fail accordingly */ + zassert_equal(net_if_up(test_iface), -E2BIG, + "net_if_up should forward error returned from offload_impl_enabled"); + + /* Verify that the iface failed to go up */ + zassert_false(net_if_is_admin_up(test_iface), + "Iface under test should have failed to go up"); +} + +ZTEST(net_offloaded_netdev, test_up_down_sock_off_impl_fail_down) +{ + struct net_if *test_iface = NET_IF_GET(sock_offload_test_impl, 0); + + /* Bring iface up before test */ + (void) net_if_up(test_iface); + + /* Instruct the enable callback to fail */ + atomic_set(&retval, -EADDRINUSE); + + + /* Expect net_if_down to fail accordingly */ + zassert_equal(net_if_down(test_iface), -EADDRINUSE, + "net_if_down should forward error returned from offload_impl_enabled"); + + /* Verify that the iface failed to go down */ + zassert_true(net_if_is_admin_up(test_iface), + "Iface under test should have failed to go up"); +} + + +ZTEST_SUITE(net_offloaded_netdev, NULL, NULL, net_offloaded_netdev_before, NULL, NULL); diff --git a/tests/net/offloaded_netdev/testcase.yaml b/tests/net/offloaded_netdev/testcase.yaml new file mode 100644 index 000000000000..81296cf4f456 --- /dev/null +++ b/tests/net/offloaded_netdev/testcase.yaml @@ -0,0 +1,6 @@ +common: + min_ram: 16 + depends_on: netif +tests: + net.offloaded_netdev: + tags: net iface userspace From c8e1b1e264060bc4e39fde376b0d1a4bc1db3dad Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 16 Mar 2023 17:18:08 +0100 Subject: [PATCH 0412/1906] Bluetooth: Audio: Move audio shell to audio directory Move all audio related shell implementations to the audio directory, to use the same structure as Mesh. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/CMakeLists.txt | 2 + subsys/bluetooth/audio/shell/CMakeLists.txt | 79 +++++++++++++++++++ subsys/bluetooth/audio/shell/audio.h | 25 ++++++ subsys/bluetooth/{ => audio}/shell/bap.c | 2 +- .../shell/bap_broadcast_assistant.c | 4 +- .../{ => audio}/shell/bap_scan_delegator.c | 2 +- .../{ => audio}/shell/cap_acceptor.c | 2 +- .../{ => audio}/shell/cap_initiator.c | 2 +- .../{ => audio}/shell/csip_set_coordinator.c | 2 +- .../{ => audio}/shell/csip_set_member.c | 2 +- subsys/bluetooth/{ => audio}/shell/has.c | 2 +- .../bluetooth/{ => audio}/shell/has_client.c | 2 +- subsys/bluetooth/{ => audio}/shell/mcc.c | 6 +- .../{ => audio}/shell/media_controller.c | 4 +- .../{ => audio}/shell/micp_mic_ctlr.c | 2 +- .../{ => audio}/shell/micp_mic_dev.c | 2 +- subsys/bluetooth/{ => audio}/shell/mpl.c | 4 +- subsys/bluetooth/{ => audio}/shell/tbs.c | 2 +- .../bluetooth/{ => audio}/shell/tbs_client.c | 2 +- .../{ => audio}/shell/vcp_vol_ctlr.c | 2 +- .../{ => audio}/shell/vcp_vol_rend.c | 2 +- subsys/bluetooth/shell/CMakeLists.txt | 76 ------------------ subsys/bluetooth/shell/bt.c | 1 + subsys/bluetooth/shell/bt.h | 6 -- 24 files changed, 130 insertions(+), 105 deletions(-) create mode 100644 subsys/bluetooth/audio/shell/CMakeLists.txt create mode 100644 subsys/bluetooth/audio/shell/audio.h rename subsys/bluetooth/{ => audio}/shell/bap.c (99%) rename subsys/bluetooth/{ => audio}/shell/bap_broadcast_assistant.c (99%) rename subsys/bluetooth/{ => audio}/shell/bap_scan_delegator.c (99%) rename subsys/bluetooth/{ => audio}/shell/cap_acceptor.c (99%) rename subsys/bluetooth/{ => audio}/shell/cap_initiator.c (98%) rename subsys/bluetooth/{ => audio}/shell/csip_set_coordinator.c (99%) rename subsys/bluetooth/{ => audio}/shell/csip_set_member.c (99%) rename subsys/bluetooth/{ => audio}/shell/has.c (99%) rename subsys/bluetooth/{ => audio}/shell/has_client.c (99%) rename subsys/bluetooth/{ => audio}/shell/mcc.c (99%) rename subsys/bluetooth/{ => audio}/shell/media_controller.c (99%) rename subsys/bluetooth/{ => audio}/shell/micp_mic_ctlr.c (99%) rename subsys/bluetooth/{ => audio}/shell/micp_mic_dev.c (99%) rename subsys/bluetooth/{ => audio}/shell/mpl.c (99%) rename subsys/bluetooth/{ => audio}/shell/tbs.c (99%) rename subsys/bluetooth/{ => audio}/shell/tbs_client.c (99%) rename subsys/bluetooth/{ => audio}/shell/vcp_vol_ctlr.c (99%) rename subsys/bluetooth/{ => audio}/shell/vcp_vol_rend.c (99%) diff --git a/subsys/bluetooth/audio/CMakeLists.txt b/subsys/bluetooth/audio/CMakeLists.txt index e49db297e0bf..c72f580d0b70 100644 --- a/subsys/bluetooth/audio/CMakeLists.txt +++ b/subsys/bluetooth/audio/CMakeLists.txt @@ -1,5 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 +add_subdirectory_ifdef(CONFIG_BT_SHELL shell) + zephyr_library() zephyr_library_sources( audio.c diff --git a/subsys/bluetooth/audio/shell/CMakeLists.txt b/subsys/bluetooth/audio/shell/CMakeLists.txt new file mode 100644 index 000000000000..47e90c5b79be --- /dev/null +++ b/subsys/bluetooth/audio/shell/CMakeLists.txt @@ -0,0 +1,79 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() +zephyr_library_link_libraries(subsys__bluetooth) + +zephyr_library_sources_ifdef( + CONFIG_BT_VCP_VOL_REND + vcp_vol_rend.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_VCP_VOL_CTLR + vcp_vol_ctlr.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_MICP_MIC_DEV + micp_mic_dev.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_MICP_MIC_CTLR + micp_mic_ctlr.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_CSIP_SET_MEMBER + csip_set_member.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_CSIP_SET_COORDINATOR + csip_set_coordinator.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_TBS + tbs.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_TBS_CLIENT + tbs_client.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_MPL + mpl.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_MCC + mcc.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_MCS + media_controller.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_HAS_PRESET_SUPPORT + has.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER + cap_acceptor.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_CAP_INITIATOR + cap_initiator.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_HAS_CLIENT + has_client.c + ) +# We use BT_BAP_STREAM as a common ground for audio, as that is set whenever +# any audio stream functionality is enabled. +zephyr_library_sources_ifdef( + CONFIG_BT_BAP_STREAM + bap.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_BAP_SCAN_DELEGATOR + bap_scan_delegator.c + ) +zephyr_library_sources_ifdef( + CONFIG_BT_BAP_BROADCAST_ASSISTANT + bap_broadcast_assistant.c + ) diff --git a/subsys/bluetooth/audio/shell/audio.h b/subsys/bluetooth/audio/shell/audio.h new file mode 100644 index 000000000000..1776812637d5 --- /dev/null +++ b/subsys/bluetooth/audio/shell/audio.h @@ -0,0 +1,25 @@ +/** @file + * @brief Bluetooth audio shell functions + * + * This is not to be included by the application. + */ + +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __AUDIO_H +#define __AUDIO_H + +#include + +extern struct bt_csip_set_member_svc_inst *svc_inst; + +ssize_t audio_ad_data_add(struct bt_data *data, const size_t data_size, const bool discoverable, + const bool connectable); +ssize_t audio_pa_data_add(struct bt_data *data_array, const size_t data_array_size); +ssize_t csis_ad_data_add(struct bt_data *data, const size_t data_size, const bool discoverable); + +#endif /* __AUDIO_H */ diff --git a/subsys/bluetooth/shell/bap.c b/subsys/bluetooth/audio/shell/bap.c similarity index 99% rename from subsys/bluetooth/shell/bap.c rename to subsys/bluetooth/audio/shell/bap.c index 72d4fb77b73b..43cf8b7f6ee3 100644 --- a/subsys/bluetooth/shell/bap.c +++ b/subsys/bluetooth/audio/shell/bap.c @@ -25,7 +25,7 @@ #include #include -#include "bt.h" +#include "shell/bt.h" #define LOCATION BT_AUDIO_LOCATION_FRONT_LEFT #define CONTEXT BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA diff --git a/subsys/bluetooth/shell/bap_broadcast_assistant.c b/subsys/bluetooth/audio/shell/bap_broadcast_assistant.c similarity index 99% rename from subsys/bluetooth/shell/bap_broadcast_assistant.c rename to subsys/bluetooth/audio/shell/bap_broadcast_assistant.c index 5af44c936279..342a62b86b70 100644 --- a/subsys/bluetooth/shell/bap_broadcast_assistant.c +++ b/subsys/bluetooth/audio/shell/bap_broadcast_assistant.c @@ -18,8 +18,8 @@ #include #include #include -#include "bt.h" -#include "../host/hci_core.h" +#include "shell/bt.h" +#include "../../host/hci_core.h" static void bap_broadcast_assistant_discover_cb(struct bt_conn *conn, int err, uint8_t recv_state_count) diff --git a/subsys/bluetooth/shell/bap_scan_delegator.c b/subsys/bluetooth/audio/shell/bap_scan_delegator.c similarity index 99% rename from subsys/bluetooth/shell/bap_scan_delegator.c rename to subsys/bluetooth/audio/shell/bap_scan_delegator.c index c355df42defa..4e452a2d258b 100644 --- a/subsys/bluetooth/shell/bap_scan_delegator.c +++ b/subsys/bluetooth/audio/shell/bap_scan_delegator.c @@ -16,7 +16,7 @@ #include #include #include -#include "bt.h" +#include "shell/bt.h" static void pa_synced(struct bt_bap_scan_delegator_recv_state *recv_state, const struct bt_le_per_adv_sync_synced_info *info) diff --git a/subsys/bluetooth/shell/cap_acceptor.c b/subsys/bluetooth/audio/shell/cap_acceptor.c similarity index 99% rename from subsys/bluetooth/shell/cap_acceptor.c rename to subsys/bluetooth/audio/shell/cap_acceptor.c index 34cd5efb380c..63e5b1c791ec 100644 --- a/subsys/bluetooth/shell/cap_acceptor.c +++ b/subsys/bluetooth/audio/shell/cap_acceptor.c @@ -13,7 +13,7 @@ #include #include #include -#include "bt.h" +#include "shell/bt.h" extern const struct shell *ctx_shell; static struct bt_csip_set_member_svc_inst *cap_csip_svc_inst; diff --git a/subsys/bluetooth/shell/cap_initiator.c b/subsys/bluetooth/audio/shell/cap_initiator.c similarity index 98% rename from subsys/bluetooth/shell/cap_initiator.c rename to subsys/bluetooth/audio/shell/cap_initiator.c index 06519b99687a..a68a255ed398 100644 --- a/subsys/bluetooth/shell/cap_initiator.c +++ b/subsys/bluetooth/audio/shell/cap_initiator.c @@ -15,7 +15,7 @@ #include #include -#include "bt.h" +#include "shell/bt.h" #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) diff --git a/subsys/bluetooth/shell/csip_set_coordinator.c b/subsys/bluetooth/audio/shell/csip_set_coordinator.c similarity index 99% rename from subsys/bluetooth/shell/csip_set_coordinator.c rename to subsys/bluetooth/audio/shell/csip_set_coordinator.c index 7d15942310e1..acf45fa79354 100644 --- a/subsys/bluetooth/shell/csip_set_coordinator.c +++ b/subsys/bluetooth/audio/shell/csip_set_coordinator.c @@ -18,7 +18,7 @@ #include #include -#include "bt.h" +#include "shell/bt.h" #include diff --git a/subsys/bluetooth/shell/csip_set_member.c b/subsys/bluetooth/audio/shell/csip_set_member.c similarity index 99% rename from subsys/bluetooth/shell/csip_set_member.c rename to subsys/bluetooth/audio/shell/csip_set_member.c index 0eccb3b35a03..7f382a8f522d 100644 --- a/subsys/bluetooth/shell/csip_set_member.c +++ b/subsys/bluetooth/audio/shell/csip_set_member.c @@ -17,7 +17,7 @@ #include #include #include -#include "bt.h" +#include "shell/bt.h" extern const struct shell *ctx_shell; struct bt_csip_set_member_svc_inst *svc_inst; diff --git a/subsys/bluetooth/shell/has.c b/subsys/bluetooth/audio/shell/has.c similarity index 99% rename from subsys/bluetooth/shell/has.c rename to subsys/bluetooth/audio/shell/has.c index 1e647792594a..480059ef0f04 100644 --- a/subsys/bluetooth/shell/has.c +++ b/subsys/bluetooth/audio/shell/has.c @@ -15,7 +15,7 @@ #include #include -#include "bt.h" +#include "shell/bt.h" static int preset_select(uint8_t index, bool sync) { diff --git a/subsys/bluetooth/shell/has_client.c b/subsys/bluetooth/audio/shell/has_client.c similarity index 99% rename from subsys/bluetooth/shell/has_client.c rename to subsys/bluetooth/audio/shell/has_client.c index a10a430a5de3..520304369fdf 100644 --- a/subsys/bluetooth/shell/has_client.c +++ b/subsys/bluetooth/audio/shell/has_client.c @@ -15,7 +15,7 @@ #include #include -#include "bt.h" +#include "shell/bt.h" static struct bt_has *inst; diff --git a/subsys/bluetooth/shell/mcc.c b/subsys/bluetooth/audio/shell/mcc.c similarity index 99% rename from subsys/bluetooth/shell/mcc.c rename to subsys/bluetooth/audio/shell/mcc.c index 80586dc9c9cd..7432b01b7f08 100644 --- a/subsys/bluetooth/shell/mcc.c +++ b/subsys/bluetooth/audio/shell/mcc.c @@ -15,11 +15,11 @@ #include #include -#include "bt.h" +#include "shell/bt.h" #include -#include "../services/ots/ots_client_internal.h" -#include "../audio/media_proxy_internal.h" +#include "../../services/ots/ots_client_internal.h" +#include "../media_proxy_internal.h" #include diff --git a/subsys/bluetooth/shell/media_controller.c b/subsys/bluetooth/audio/shell/media_controller.c similarity index 99% rename from subsys/bluetooth/shell/media_controller.c rename to subsys/bluetooth/audio/shell/media_controller.c index d4c323e5603d..a291e47dc0e8 100644 --- a/subsys/bluetooth/shell/media_controller.c +++ b/subsys/bluetooth/audio/shell/media_controller.c @@ -14,11 +14,11 @@ #include #include -#include "bt.h" +#include "shell/bt.h" #include #include -#include "../audio/media_proxy_internal.h" /* For MPL_NO_TRACK_ID - TODO: Fix */ +#include "../media_proxy_internal.h" /* For MPL_NO_TRACK_ID - TODO: Fix */ #include diff --git a/subsys/bluetooth/shell/micp_mic_ctlr.c b/subsys/bluetooth/audio/shell/micp_mic_ctlr.c similarity index 99% rename from subsys/bluetooth/shell/micp_mic_ctlr.c rename to subsys/bluetooth/audio/shell/micp_mic_ctlr.c index 0639c18d2be1..086155b70b68 100644 --- a/subsys/bluetooth/shell/micp_mic_ctlr.c +++ b/subsys/bluetooth/audio/shell/micp_mic_ctlr.c @@ -14,7 +14,7 @@ #include #include -#include "bt.h" +#include "shell/bt.h" static struct bt_micp_mic_ctlr *mic_ctlr; #if defined(CONFIG_BT_MICP_MIC_CTLR_AICS) diff --git a/subsys/bluetooth/shell/micp_mic_dev.c b/subsys/bluetooth/audio/shell/micp_mic_dev.c similarity index 99% rename from subsys/bluetooth/shell/micp_mic_dev.c rename to subsys/bluetooth/audio/shell/micp_mic_dev.c index e1f761ddc415..6e4ace111b59 100644 --- a/subsys/bluetooth/shell/micp_mic_dev.c +++ b/subsys/bluetooth/audio/shell/micp_mic_dev.c @@ -14,7 +14,7 @@ #include #include -#include "bt.h" +#include "shell/bt.h" static void micp_mic_dev_mute_cb(uint8_t mute) { diff --git a/subsys/bluetooth/shell/mpl.c b/subsys/bluetooth/audio/shell/mpl.c similarity index 99% rename from subsys/bluetooth/shell/mpl.c rename to subsys/bluetooth/audio/shell/mpl.c index eb1669410ab1..fe0c986cc03b 100644 --- a/subsys/bluetooth/shell/mpl.c +++ b/subsys/bluetooth/audio/shell/mpl.c @@ -14,10 +14,10 @@ #include #include -#include "bt.h" +#include "shell/bt.h" #include -#include "../audio/mpl_internal.h" +#include "../mpl_internal.h" #include diff --git a/subsys/bluetooth/shell/tbs.c b/subsys/bluetooth/audio/shell/tbs.c similarity index 99% rename from subsys/bluetooth/shell/tbs.c rename to subsys/bluetooth/audio/shell/tbs.c index d829c087cc19..a188d87f31f1 100644 --- a/subsys/bluetooth/shell/tbs.c +++ b/subsys/bluetooth/audio/shell/tbs.c @@ -14,7 +14,7 @@ #include -#include "bt.h" +#include "shell/bt.h" static struct bt_conn *tbs_authorized_conn; static bool cbs_registered; diff --git a/subsys/bluetooth/shell/tbs_client.c b/subsys/bluetooth/audio/shell/tbs_client.c similarity index 99% rename from subsys/bluetooth/shell/tbs_client.c rename to subsys/bluetooth/audio/shell/tbs_client.c index a9bd49fbf42b..3295ff865e48 100644 --- a/subsys/bluetooth/shell/tbs_client.c +++ b/subsys/bluetooth/audio/shell/tbs_client.c @@ -22,7 +22,7 @@ #include #include -#include "bt.h" +#include "shell/bt.h" static int cmd_tbs_client_discover(const struct shell *sh, size_t argc, char *argv[]) diff --git a/subsys/bluetooth/shell/vcp_vol_ctlr.c b/subsys/bluetooth/audio/shell/vcp_vol_ctlr.c similarity index 99% rename from subsys/bluetooth/shell/vcp_vol_ctlr.c rename to subsys/bluetooth/audio/shell/vcp_vol_ctlr.c index 7e0afa3b53ad..90fa26bb1a0d 100644 --- a/subsys/bluetooth/shell/vcp_vol_ctlr.c +++ b/subsys/bluetooth/audio/shell/vcp_vol_ctlr.c @@ -13,7 +13,7 @@ #include #include -#include "bt.h" +#include "shell/bt.h" static struct bt_vcp_vol_ctlr *vol_ctlr; static struct bt_vcp_included vcp_included; diff --git a/subsys/bluetooth/shell/vcp_vol_rend.c b/subsys/bluetooth/audio/shell/vcp_vol_rend.c similarity index 99% rename from subsys/bluetooth/shell/vcp_vol_rend.c rename to subsys/bluetooth/audio/shell/vcp_vol_rend.c index 729cd4149f77..9fb2287d6ba1 100644 --- a/subsys/bluetooth/shell/vcp_vol_rend.c +++ b/subsys/bluetooth/audio/shell/vcp_vol_rend.c @@ -15,7 +15,7 @@ #include #include -#include "bt.h" +#include "shell/bt.h" static struct bt_vcp_included vcp_included; diff --git a/subsys/bluetooth/shell/CMakeLists.txt b/subsys/bluetooth/shell/CMakeLists.txt index f0d0c48c41d7..6c8509fcd8a1 100644 --- a/subsys/bluetooth/shell/CMakeLists.txt +++ b/subsys/bluetooth/shell/CMakeLists.txt @@ -25,82 +25,6 @@ zephyr_library_sources_ifdef( CONFIG_BT_ISO iso.c ) -zephyr_library_sources_ifdef( - CONFIG_BT_VCP_VOL_REND - vcp_vol_rend.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_VCP_VOL_CTLR - vcp_vol_ctlr.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_MICP_MIC_DEV - micp_mic_dev.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_MICP_MIC_CTLR - micp_mic_ctlr.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_CSIP_SET_MEMBER - csip_set_member.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_CSIP_SET_COORDINATOR - csip_set_coordinator.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_TBS - tbs.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_TBS_CLIENT - tbs_client.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_MPL - mpl.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_MCC - mcc.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_MCS - media_controller.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_HAS_PRESET_SUPPORT - has.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER - cap_acceptor.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_CAP_INITIATOR - cap_initiator.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_HAS_CLIENT - has_client.c - ) -# We use BT_BAP_STREAM as a common ground for audio, as that is set whenever -# any audio stream functionality is enabled. -zephyr_library_sources_ifdef( - CONFIG_BT_BAP_STREAM - bap.c - ) - -zephyr_library_sources_ifdef( - CONFIG_BT_BAP_SCAN_DELEGATOR - bap_scan_delegator.c - ) -zephyr_library_sources_ifdef( - CONFIG_BT_BAP_BROADCAST_ASSISTANT - bap_broadcast_assistant.c - ) - zephyr_library_sources_ifdef( CONFIG_BT_IAS ias.c diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index a7f135b09bea..5644bf08242f 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -41,6 +41,7 @@ #include "bt.h" #include "ll.h" #include "hci.h" +#include "../audio/shell/audio.h" static bool no_settings_load; diff --git a/subsys/bluetooth/shell/bt.h b/subsys/bluetooth/shell/bt.h index 9c0a2a408a28..76772f85bf56 100644 --- a/subsys/bluetooth/shell/bt.h +++ b/subsys/bluetooth/shell/bt.h @@ -18,7 +18,6 @@ extern const struct shell *ctx_shell; extern struct bt_conn *default_conn; -extern struct bt_csip_set_member_svc_inst *svc_inst; #if defined(CONFIG_BT_ISO) extern struct bt_iso_chan iso_chan; @@ -33,10 +32,5 @@ extern struct bt_le_per_adv_sync *per_adv_syncs[CONFIG_BT_PER_ADV_SYNC_MAX]; #endif /* CONFIG_BT_EXT_ADV */ void conn_addr_str(struct bt_conn *conn, char *addr, size_t len); -ssize_t audio_ad_data_add(struct bt_data *data, const size_t data_size, const bool discoverable, - const bool connectable); -ssize_t audio_pa_data_add(struct bt_data *data_array, - const size_t data_array_size); -ssize_t csis_ad_data_add(struct bt_data *data, const size_t data_size, const bool discoverable); #endif /* __BT_H */ From 6c8ef27a770697a81b0c0512eeb62e497f814b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Fri, 17 Mar 2023 13:24:42 +0100 Subject: [PATCH 0413/1906] drivers: counter: stm32_rtc: enable backup domain only when supported MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The STM32C0-series does not have a backup domain, this patch enables us to extend this driver to the C0-series. Signed-off-by: Benjamin Björnsson --- drivers/counter/counter_ll_stm32_rtc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/counter/counter_ll_stm32_rtc.c b/drivers/counter/counter_ll_stm32_rtc.c index 4549a79ffb38..eadd60ffe875 100644 --- a/drivers/counter/counter_ll_stm32_rtc.c +++ b/drivers/counter/counter_ll_stm32_rtc.c @@ -402,7 +402,9 @@ static int rtc_stm32_init(const struct device *dev) /* Enable Backup access */ z_stm32_hsem_lock(CFG_HW_RCC_SEMID, HSEM_LOCK_DEFAULT_RETRY); +#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPR_DBP) LL_PWR_EnableBkUpAccess(); +#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */ /* Enable RTC clock source */ if (clock_control_configure(clk, From c02688a30819470c58fecfe76f3480ee4f104ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Fri, 17 Mar 2023 13:24:58 +0100 Subject: [PATCH 0414/1906] drivers: counter: add support for rtc in STM32C0-series MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit extends the rtc counter driver to work on the STM32C0-series. Signed-off-by: Benjamin Björnsson --- drivers/counter/Kconfig.stm32_rtc | 2 +- drivers/counter/counter_ll_stm32_rtc.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/counter/Kconfig.stm32_rtc b/drivers/counter/Kconfig.stm32_rtc index 0998ca372e10..52de35bd57a7 100644 --- a/drivers/counter/Kconfig.stm32_rtc +++ b/drivers/counter/Kconfig.stm32_rtc @@ -13,7 +13,7 @@ menuconfig COUNTER_RTC_STM32 select USE_STM32_LL_EXTI help Build RTC driver for STM32 SoCs. - Tested on STM32 F0, F2, F3, F4, F7, G0, G4, H7, L1, L4, L5, U5 series + Tested on STM32 C0, F0, F2, F3, F4, F7, G0, G4, H7, L1, L4, L5, U5 series if COUNTER_RTC_STM32 diff --git a/drivers/counter/counter_ll_stm32_rtc.c b/drivers/counter/counter_ll_stm32_rtc.c index eadd60ffe875..511ec21846d3 100644 --- a/drivers/counter/counter_ll_stm32_rtc.c +++ b/drivers/counter/counter_ll_stm32_rtc.c @@ -37,7 +37,8 @@ LOG_MODULE_REGISTER(counter_rtc_stm32, CONFIG_COUNTER_LOG_LEVEL); #if defined(CONFIG_SOC_SERIES_STM32L4X) #define RTC_EXTI_LINE LL_EXTI_LINE_18 -#elif defined(CONFIG_SOC_SERIES_STM32G0X) +#elif defined(CONFIG_SOC_SERIES_STM32C0X) \ + || defined(CONFIG_SOC_SERIES_STM32G0X) #define RTC_EXTI_LINE LL_EXTI_LINE_19 #elif defined(CONFIG_SOC_SERIES_STM32F4X) \ || defined(CONFIG_SOC_SERIES_STM32F0X) \ @@ -371,7 +372,9 @@ void rtc_stm32_isr(const struct device *dev) #if defined(CONFIG_SOC_SERIES_STM32H7X) && defined(CONFIG_CPU_CORTEX_M4) LL_C2_EXTI_ClearFlag_0_31(RTC_EXTI_LINE); -#elif defined(CONFIG_SOC_SERIES_STM32G0X) || defined(CONFIG_SOC_SERIES_STM32L5X) +#elif defined(CONFIG_SOC_SERIES_STM32C0X) \ + || defined(CONFIG_SOC_SERIES_STM32G0X) \ + || defined(CONFIG_SOC_SERIES_STM32L5X) LL_EXTI_ClearRisingFlag_0_31(RTC_EXTI_LINE); #elif defined(CONFIG_SOC_SERIES_STM32U5X) /* in STM32U5 family RTC is not connected to EXTI */ From 71c83df0952b483b2f33a67b3dba0d7a7341a073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Fri, 17 Mar 2023 13:25:02 +0100 Subject: [PATCH 0415/1906] dts: arm: stm32c0: Add rtc node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add rtc node to the STM32C0-series. Signed-off-by: Benjamin Björnsson --- dts/arm/st/c0/stm32c0.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dts/arm/st/c0/stm32c0.dtsi b/dts/arm/st/c0/stm32c0.dtsi index 610408c4e567..7595005f38c3 100644 --- a/dts/arm/st/c0/stm32c0.dtsi +++ b/dts/arm/st/c0/stm32c0.dtsi @@ -142,6 +142,15 @@ }; }; + rtc: rtc@40002800 { + compatible = "st,stm32-rtc"; + reg = <0x40002800 0x400>; + interrupts = <2 0>; + clocks = <&rcc STM32_CLOCK_BUS_APB1 0x00000400>; + prescaler = <32768>; + status = "disabled"; + }; + usart1: serial@40013800 { compatible = "st,stm32-usart", "st,stm32-uart"; reg = <0x40013800 0x400>; From 739651b54526c5a8b200d03b0762fee4d8639fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Fri, 17 Mar 2023 13:25:08 +0100 Subject: [PATCH 0416/1906] boards: arm: nucleo_c031c6: Enable rtc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable rtc and update documentation to include counter support. Signed-off-by: Benjamin Björnsson --- boards/arm/nucleo_c031c6/doc/index.rst | 2 ++ boards/arm/nucleo_c031c6/nucleo_c031c6.dts | 10 ++++++++++ boards/arm/nucleo_c031c6/nucleo_c031c6.yaml | 1 + 3 files changed, 13 insertions(+) diff --git a/boards/arm/nucleo_c031c6/doc/index.rst b/boards/arm/nucleo_c031c6/doc/index.rst index 9c1a4c02f2aa..448d34fd365c 100644 --- a/boards/arm/nucleo_c031c6/doc/index.rst +++ b/boards/arm/nucleo_c031c6/doc/index.rst @@ -74,6 +74,8 @@ The Zephyr nucleo_c031c6 board configuration supports the following hardware fea +-----------+------------+-------------------------------------+ | CLOCK | on-chip | reset and clock control | +-----------+------------+-------------------------------------+ +| RTC | on-chip | counter | ++-----------+------------+-------------------------------------+ Other hardware features are not yet supported in this Zephyr port. diff --git a/boards/arm/nucleo_c031c6/nucleo_c031c6.dts b/boards/arm/nucleo_c031c6/nucleo_c031c6.dts index a7ae659be906..cdc63c92b4a1 100644 --- a/boards/arm/nucleo_c031c6/nucleo_c031c6.dts +++ b/boards/arm/nucleo_c031c6/nucleo_c031c6.dts @@ -43,6 +43,10 @@ }; }; +&clk_lse { + status = "okay"; +}; + &clk_hse { clock-frequency = ; status = "okay"; @@ -67,3 +71,9 @@ current-speed = <115200>; status = "okay"; }; + +&rtc { + clocks = <&rcc STM32_CLOCK_BUS_APB1 0x00000400>, + <&rcc STM32_SRC_LSE RTC_SEL(1)>; + status = "okay"; +}; diff --git a/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml b/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml index 95cbece59819..dcde51e7f897 100644 --- a/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml +++ b/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml @@ -8,5 +8,6 @@ toolchain: - xtools supported: - gpio + - counter ram: 12 flash: 32 From 20dce8c6a8ca1ef764001db1cb3e8f63458d59b1 Mon Sep 17 00:00:00 2001 From: Ben Marsh Date: Fri, 17 Mar 2023 13:49:18 +0000 Subject: [PATCH 0417/1906] boards: arm: stm32h735g_disco: Add counter support Add counter to the supported features of the stm32h735g_disco board Signed-off-by: Ben Marsh --- boards/arm/stm32h735g_disco/stm32h735g_disco.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/boards/arm/stm32h735g_disco/stm32h735g_disco.yaml b/boards/arm/stm32h735g_disco/stm32h735g_disco.yaml index 7723332ad6ad..16d056e600da 100644 --- a/boards/arm/stm32h735g_disco/stm32h735g_disco.yaml +++ b/boards/arm/stm32h735g_disco/stm32h735g_disco.yaml @@ -14,3 +14,4 @@ supported: - netif:eth - memc - adc + - counter From 1cec2af0cb2923afb13e30c877a94599a664a111 Mon Sep 17 00:00:00 2001 From: Ben Marsh Date: Fri, 17 Mar 2023 13:52:41 +0000 Subject: [PATCH 0418/1906] tests: drivers: counter: counter_basic_api: Add stm32h735g_disco overlay Add overlay for stm32h735g_disco board to enable counter_basic_api tests on this board Signed-off-by: Ben Marsh --- .../counter_basic_api/boards/stm32h735g_disco.overlay | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/drivers/counter/counter_basic_api/boards/stm32h735g_disco.overlay diff --git a/tests/drivers/counter/counter_basic_api/boards/stm32h735g_disco.overlay b/tests/drivers/counter/counter_basic_api/boards/stm32h735g_disco.overlay new file mode 100644 index 000000000000..680418ecc3a2 --- /dev/null +++ b/tests/drivers/counter/counter_basic_api/boards/stm32h735g_disco.overlay @@ -0,0 +1,10 @@ +&timers2 { + st,prescaler = <83>; + counter { + status = "okay"; + }; +}; + +&rtc { + status = "disabled"; +}; From 4e6c50646acfe8ef8d83b1855f7aeed9340a5347 Mon Sep 17 00:00:00 2001 From: Ben Marsh Date: Fri, 17 Mar 2023 13:55:25 +0000 Subject: [PATCH 0419/1906] samples: drivers: counter: alarm: Add support for stm32h735g_disco Add the stm32h735g_disco board to the supported boards for the counter alarm sample Signed-off-by: Ben Marsh --- .../drivers/counter/alarm/boards/stm32h735g_disco.overlay | 6 ++++++ samples/drivers/counter/alarm/sample.yaml | 2 +- samples/drivers/counter/alarm/src/main.c | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 samples/drivers/counter/alarm/boards/stm32h735g_disco.overlay diff --git a/samples/drivers/counter/alarm/boards/stm32h735g_disco.overlay b/samples/drivers/counter/alarm/boards/stm32h735g_disco.overlay new file mode 100644 index 000000000000..00a10669ba0d --- /dev/null +++ b/samples/drivers/counter/alarm/boards/stm32h735g_disco.overlay @@ -0,0 +1,6 @@ +&timers2 { + st,prescaler = <83>; + counter { + status = "okay"; + }; +}; diff --git a/samples/drivers/counter/alarm/sample.yaml b/samples/drivers/counter/alarm/sample.yaml index 642201e0d3bb..9e826072aba0 100644 --- a/samples/drivers/counter/alarm/sample.yaml +++ b/samples/drivers/counter/alarm/sample.yaml @@ -9,7 +9,7 @@ tests: bl5340_dvk_cpuapp gd32e103v_eval gd32e507z_eval gd32f403z_eval gd32f450i_eval gd32f450z_eval gd32e507v_start gd32f407v_start gd32f450v_start - gd32f470i_eval + gd32f470i_eval stm32h735g_disco integration_platforms: - nucleo_f746zg harness_config: diff --git a/samples/drivers/counter/alarm/src/main.c b/samples/drivers/counter/alarm/src/main.c index c6ccb4adc541..82005e5b1cae 100644 --- a/samples/drivers/counter/alarm/src/main.c +++ b/samples/drivers/counter/alarm/src/main.c @@ -23,6 +23,8 @@ struct counter_alarm_cfg alarm_cfg; #define TIMER DT_NODELABEL(extrtc0) #elif defined(CONFIG_COUNTER_RTC0) #define TIMER DT_NODELABEL(rtc0) +#elif defined(CONFIG_COUNTER_TIMER_STM32) +#define TIMER DT_INST(0, st_stm32_counter) #elif defined(CONFIG_COUNTER_RTC_STM32) #define TIMER DT_INST(0, st_stm32_rtc) #elif defined(CONFIG_COUNTER_NATIVE_POSIX) From 2122efee1cfbfd171510f3b5f6f31cfc95cc6aa2 Mon Sep 17 00:00:00 2001 From: Yanqin Wei Date: Tue, 14 Feb 2023 16:01:40 +0800 Subject: [PATCH 0420/1906] include: arch: add macro for mpu memory configuration Add noncache memory attribute and memory-region-mpu compatible macro for Armv8r64. Signed-off-by: Yanqin Wei --- include/zephyr/arch/arm64/cortex_r/arm_mpu.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/include/zephyr/arch/arm64/cortex_r/arm_mpu.h b/include/zephyr/arch/arm64/cortex_r/arm_mpu.h index e3944a770dd8..12280f49eb4d 100644 --- a/include/zephyr/arch/arm64/cortex_r/arm_mpu.h +++ b/include/zephyr/arch/arm64/cortex_r/arm_mpu.h @@ -1,7 +1,7 @@ /* * Copyright (c) 2018 Linaro Limited. * Copyright (c) 2018 Nordic Semiconductor ASA. - * Copyright (c) 2021 Arm Limited (or its affiliates). All rights reserved. + * Copyright (c) 2021-2023 Arm Limited (or its affiliates). All rights reserved. * * SPDX-License-Identifier: Apache-2.0 */ @@ -148,6 +148,14 @@ .mair_idx = MPU_MAIR_INDEX_SRAM, \ } +#define REGION_RAM_NOCACHE_ATTR \ + { \ + /* AP, XN, SH */ \ + .rbar = NOT_EXEC | P_RW_U_NA_Msk | NON_SHAREABLE_Msk, \ + /* Cache-ability */ \ + .mair_idx = MPU_MAIR_INDEX_SRAM_NOCACHE, \ + } + #define REGION_RAM_TEXT_ATTR \ { \ /* AP, XN, SH */ \ @@ -219,6 +227,14 @@ struct arm_mpu_config { .attr = _attr, \ } +#define MPU_REGION_ENTRY_FROM_DTS(_name, _base, _size, _attr) \ + { \ + .name = _name, \ + .base = _base, \ + .limit = _base + _size, \ + .attr = _attr, \ + } + #define K_MEM_PARTITION_P_RW_U_RW ((k_mem_partition_attr_t) \ {(P_RW_U_RW_Msk), MPU_MAIR_INDEX_SRAM}) #define K_MEM_PARTITION_P_RW_U_NA ((k_mem_partition_attr_t) \ From a1f55c63b37dd642733510364186184a3bfa5861 Mon Sep 17 00:00:00 2001 From: Yanqin Wei Date: Tue, 14 Feb 2023 14:40:20 +0800 Subject: [PATCH 0421/1906] soc: fvp_aemv8r: add mpu region from device tree Some platforms need to define multiple memory regions with various attribute. This patch adds dts defined regions in the mpu configuration. The memory attribute can be set in the device tree. Signed-off-by: Yanqin Wei --- soc/arm64/arm/fvp_aemv8r/arm_mpu_regions.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/soc/arm64/arm/fvp_aemv8r/arm_mpu_regions.c b/soc/arm64/arm/fvp_aemv8r/arm_mpu_regions.c index 22b4822360b3..97b08d418b4f 100644 --- a/soc/arm64/arm/fvp_aemv8r/arm_mpu_regions.c +++ b/soc/arm64/arm/fvp_aemv8r/arm_mpu_regions.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Arm Limited (or its affiliates). All rights reserved. + * Copyright (c) 2021-2023 Arm Limited (or its affiliates). All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ @@ -7,6 +7,7 @@ #include #include +#include #include #define DEVICE_REGION_START 0x80000000UL @@ -46,7 +47,10 @@ static const struct arm_mpu_region mpu_regions[] = { MPU_REGION_ENTRY("DEVICE", DEVICE_REGION_START, DEVICE_REGION_END, - REGION_DEVICE_ATTR) + REGION_DEVICE_ATTR), + + /* Extra regions defined in device tree */ + LINKER_DT_REGION_MPU(MPU_REGION_ENTRY_FROM_DTS) }; const struct arm_mpu_config mpu_config = { From 2e43a483de7461fa4d8e59cde4c88c50fdd6a8c9 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 17 Mar 2023 12:36:39 +0000 Subject: [PATCH 0422/1906] samples: zbus: uart_bridge: Replace prj_ files with overlays Replaces the old prj_.conf files with board overlays instead. Signed-off-by: Jamie McCrae --- .../zbus/uart_bridge/boards/hifive1_revb.conf | 4 ++++ .../zbus/uart_bridge/boards/native_posix.conf | 1 + .../zbus/uart_bridge/boards/native_posix_64.conf | 1 + .../subsys/zbus/uart_bridge/prj_hifive1_revb.conf | 14 -------------- .../subsys/zbus/uart_bridge/prj_native_posix.conf | 10 ---------- .../zbus/uart_bridge/prj_native_posix_64.conf | 11 ----------- 6 files changed, 6 insertions(+), 35 deletions(-) create mode 100644 samples/subsys/zbus/uart_bridge/boards/hifive1_revb.conf create mode 100644 samples/subsys/zbus/uart_bridge/boards/native_posix.conf create mode 100644 samples/subsys/zbus/uart_bridge/boards/native_posix_64.conf delete mode 100644 samples/subsys/zbus/uart_bridge/prj_hifive1_revb.conf delete mode 100644 samples/subsys/zbus/uart_bridge/prj_native_posix.conf delete mode 100644 samples/subsys/zbus/uart_bridge/prj_native_posix_64.conf diff --git a/samples/subsys/zbus/uart_bridge/boards/hifive1_revb.conf b/samples/subsys/zbus/uart_bridge/boards/hifive1_revb.conf new file mode 100644 index 000000000000..28df73125336 --- /dev/null +++ b/samples/subsys/zbus/uart_bridge/boards/hifive1_revb.conf @@ -0,0 +1,4 @@ +CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_UART_SIFIVE_PORT_1=y +CONFIG_UART_SIFIVE_PORT_1_TXCNT_IRQ=1 +CONFIG_UART_SIFIVE_PORT_1_RXCNT_IRQ=1 diff --git a/samples/subsys/zbus/uart_bridge/boards/native_posix.conf b/samples/subsys/zbus/uart_bridge/boards/native_posix.conf new file mode 100644 index 000000000000..b552360756ca --- /dev/null +++ b/samples/subsys/zbus/uart_bridge/boards/native_posix.conf @@ -0,0 +1 @@ +CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE=y diff --git a/samples/subsys/zbus/uart_bridge/boards/native_posix_64.conf b/samples/subsys/zbus/uart_bridge/boards/native_posix_64.conf new file mode 100644 index 000000000000..b552360756ca --- /dev/null +++ b/samples/subsys/zbus/uart_bridge/boards/native_posix_64.conf @@ -0,0 +1 @@ +CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE=y diff --git a/samples/subsys/zbus/uart_bridge/prj_hifive1_revb.conf b/samples/subsys/zbus/uart_bridge/prj_hifive1_revb.conf deleted file mode 100644 index 663c0d3ddfc3..000000000000 --- a/samples/subsys/zbus/uart_bridge/prj_hifive1_revb.conf +++ /dev/null @@ -1,14 +0,0 @@ -CONFIG_LOG=y -CONFIG_LOG_MODE_MINIMAL=y -CONFIG_THREAD_NAME=y - -CONFIG_SERIAL=y -CONFIG_UART_LINE_CTRL=n -CONFIG_UART_INTERRUPT_DRIVEN=y -CONFIG_UART_SIFIVE_PORT_1=y -CONFIG_UART_SIFIVE_PORT_1_TXCNT_IRQ=1 -CONFIG_UART_SIFIVE_PORT_1_RXCNT_IRQ=1 - -CONFIG_ZBUS=y -CONFIG_ZBUS_LOG_LEVEL_DBG=y -CONFIG_ZBUS_CHANNEL_NAME=y diff --git a/samples/subsys/zbus/uart_bridge/prj_native_posix.conf b/samples/subsys/zbus/uart_bridge/prj_native_posix.conf deleted file mode 100644 index 0f973b533c0e..000000000000 --- a/samples/subsys/zbus/uart_bridge/prj_native_posix.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_LOG=y -CONFIG_LOG_MODE_MINIMAL=y -CONFIG_THREAD_NAME=y -CONFIG_SERIAL=y -CONFIG_UART_LINE_CTRL=n -CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE=y - -CONFIG_ZBUS=y -CONFIG_ZBUS_LOG_LEVEL_DBG=y -CONFIG_ZBUS_CHANNEL_NAME=y diff --git a/samples/subsys/zbus/uart_bridge/prj_native_posix_64.conf b/samples/subsys/zbus/uart_bridge/prj_native_posix_64.conf deleted file mode 100644 index 59061f86ae5e..000000000000 --- a/samples/subsys/zbus/uart_bridge/prj_native_posix_64.conf +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG_LOG=y -CONFIG_LOG_MODE_MINIMAL=y -CONFIG_THREAD_NAME=y - -CONFIG_SERIAL=y -CONFIG_UART_LINE_CTRL=n -CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE=y - -CONFIG_ZBUS=y -CONFIG_ZBUS_LOG_LEVEL_DBG=y -CONFIG_ZBUS_CHANNEL_NAME=y From e3525fc763ed58c4f65735d0fd7b21479b7973a3 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 17 Mar 2023 12:39:00 +0000 Subject: [PATCH 0423/1906] samples: zbus: remote_mock: Replace prj_ files with overlays Replaces the old prj_.conf files with board overlays instead. Signed-off-by: Jamie McCrae --- .../zbus/remote_mock/boards/hifive1_revb.conf | 3 +++ .../zbus/remote_mock/boards/native_posix.conf | 2 ++ .../zbus/remote_mock/prj_hifive1_revb.conf | 18 ------------------ .../zbus/remote_mock/prj_native_posix.conf | 17 ----------------- 4 files changed, 5 insertions(+), 35 deletions(-) create mode 100644 samples/subsys/zbus/remote_mock/boards/hifive1_revb.conf create mode 100644 samples/subsys/zbus/remote_mock/boards/native_posix.conf delete mode 100644 samples/subsys/zbus/remote_mock/prj_hifive1_revb.conf delete mode 100644 samples/subsys/zbus/remote_mock/prj_native_posix.conf diff --git a/samples/subsys/zbus/remote_mock/boards/hifive1_revb.conf b/samples/subsys/zbus/remote_mock/boards/hifive1_revb.conf new file mode 100644 index 000000000000..51a28b66435c --- /dev/null +++ b/samples/subsys/zbus/remote_mock/boards/hifive1_revb.conf @@ -0,0 +1,3 @@ +CONFIG_UART_SIFIVE_PORT_1=y +CONFIG_UART_SIFIVE_PORT_1_TXCNT_IRQ=1 +CONFIG_UART_SIFIVE_PORT_1_RXCNT_IRQ=1 diff --git a/samples/subsys/zbus/remote_mock/boards/native_posix.conf b/samples/subsys/zbus/remote_mock/boards/native_posix.conf new file mode 100644 index 000000000000..46f5f4e5f3e6 --- /dev/null +++ b/samples/subsys/zbus/remote_mock/boards/native_posix.conf @@ -0,0 +1,2 @@ +CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE=y +CONFIG_NATIVE_POSIX_SLOWDOWN_TO_REAL_TIME=y diff --git a/samples/subsys/zbus/remote_mock/prj_hifive1_revb.conf b/samples/subsys/zbus/remote_mock/prj_hifive1_revb.conf deleted file mode 100644 index ec97403630f6..000000000000 --- a/samples/subsys/zbus/remote_mock/prj_hifive1_revb.conf +++ /dev/null @@ -1,18 +0,0 @@ -CONFIG_LOG=y -CONFIG_LOG_MODE_MINIMAL=y -CONFIG_THREAD_NAME=y -CONFIG_ASSERT=y - -CONFIG_SERIAL=y -CONFIG_UART_LINE_CTRL=n -CONFIG_UART_SIFIVE_PORT_1=y -CONFIG_UART_SIFIVE_PORT_1_TXCNT_IRQ=1 -CONFIG_UART_SIFIVE_PORT_1_RXCNT_IRQ=1 - -CONFIG_NET_BUF=y -CONFIG_NET_BUF_LOG=y -CONFIG_NET_BUF_SIMPLE_LOG=y - -CONFIG_ZBUS=y -CONFIG_ZBUS_LOG_LEVEL_DBG=y -CONFIG_ZBUS_CHANNEL_NAME=y diff --git a/samples/subsys/zbus/remote_mock/prj_native_posix.conf b/samples/subsys/zbus/remote_mock/prj_native_posix.conf deleted file mode 100644 index 0daf4fb4af71..000000000000 --- a/samples/subsys/zbus/remote_mock/prj_native_posix.conf +++ /dev/null @@ -1,17 +0,0 @@ -CONFIG_LOG=y -CONFIG_LOG_MODE_MINIMAL=y -CONFIG_THREAD_NAME=y -CONFIG_ASSERT=y - -CONFIG_SERIAL=y -CONFIG_UART_LINE_CTRL=n -CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE=y -CONFIG_NATIVE_POSIX_SLOWDOWN_TO_REAL_TIME=y - -CONFIG_NET_BUF=y -CONFIG_NET_BUF_LOG=y -CONFIG_NET_BUF_SIMPLE_LOG=y - -CONFIG_ZBUS=y -CONFIG_ZBUS_LOG_LEVEL_DBG=y -CONFIG_ZBUS_CHANNEL_NAME=y From cd4453d565b7d31994d79c6cd0d3f98ae7b3686c Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 17 Mar 2023 12:49:05 +0000 Subject: [PATCH 0424/1906] samples: drivers: ps2: Replace prj_ files with overlays Replaces the old prj_.conf files with board overlays instead. Signed-off-by: Jamie McCrae --- samples/drivers/ps2/boards/mec15xxevb_assy6853.conf | 2 ++ samples/drivers/ps2/prj_mec15xxevb_assy6853.conf | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) create mode 100644 samples/drivers/ps2/boards/mec15xxevb_assy6853.conf delete mode 100644 samples/drivers/ps2/prj_mec15xxevb_assy6853.conf diff --git a/samples/drivers/ps2/boards/mec15xxevb_assy6853.conf b/samples/drivers/ps2/boards/mec15xxevb_assy6853.conf new file mode 100644 index 000000000000..47deb72e77dc --- /dev/null +++ b/samples/drivers/ps2/boards/mec15xxevb_assy6853.conf @@ -0,0 +1,2 @@ +CONFIG_CONSOLE=y +CONFIG_LOG=y diff --git a/samples/drivers/ps2/prj_mec15xxevb_assy6853.conf b/samples/drivers/ps2/prj_mec15xxevb_assy6853.conf deleted file mode 100644 index e185aaed42bc..000000000000 --- a/samples/drivers/ps2/prj_mec15xxevb_assy6853.conf +++ /dev/null @@ -1,4 +0,0 @@ -# PS2 + mec15xxevb_assy6853 -CONFIG_CONSOLE=y -CONFIG_LOG=y -CONFIG_PS2=y From 34863c9f4e45975234a6c6e578c5afaa7e3b7f11 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 17 Mar 2023 12:50:23 +0000 Subject: [PATCH 0425/1906] samples: drivers: kscan: Replace prj_ files with overlays Replaces the old prj_.conf files with board overlays instead. Signed-off-by: Jamie McCrae --- .../mec15xxevb_assy6853.conf} | 2 -- 1 file changed, 2 deletions(-) rename samples/drivers/kscan/{prj_mec15xxevb_assy6853.conf => boards/mec15xxevb_assy6853.conf} (60%) diff --git a/samples/drivers/kscan/prj_mec15xxevb_assy6853.conf b/samples/drivers/kscan/boards/mec15xxevb_assy6853.conf similarity index 60% rename from samples/drivers/kscan/prj_mec15xxevb_assy6853.conf rename to samples/drivers/kscan/boards/mec15xxevb_assy6853.conf index a92e4604f566..1eed72b67d5e 100644 --- a/samples/drivers/kscan/prj_mec15xxevb_assy6853.conf +++ b/samples/drivers/kscan/boards/mec15xxevb_assy6853.conf @@ -1,5 +1,3 @@ -# kscan + mec15xxevb_assy6853 CONFIG_CONSOLE=y CONFIG_LOG=y CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=100 -CONFIG_KSCAN=y From 2398ac1815afac265316386f7a2bd6a80df0b2ac Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 17 Mar 2023 12:52:50 +0000 Subject: [PATCH 0426/1906] samples: drivers: espi: Replace prj_ files with overlays Replaces the old prj_.conf files with board overlays instead. Signed-off-by: Jamie McCrae --- .../mec1501modular_assy6885.conf} | 2 -- .../mec15xxevb_assy6853.conf} | 2 -- .../espi/{prj_npcx9m6f_evb.conf => boards/npcx7m6fb_evb.conf} | 2 -- .../espi/{prj_npcx7m6fb_evb.conf => boards/npcx9m6f_evb.conf} | 2 -- 4 files changed, 8 deletions(-) rename samples/drivers/espi/{prj_mec1501modular_assy6885.conf => boards/mec1501modular_assy6885.conf} (88%) rename samples/drivers/espi/{prj_mec15xxevb_assy6853.conf => boards/mec15xxevb_assy6853.conf} (89%) rename samples/drivers/espi/{prj_npcx9m6f_evb.conf => boards/npcx7m6fb_evb.conf} (82%) rename samples/drivers/espi/{prj_npcx7m6fb_evb.conf => boards/npcx9m6f_evb.conf} (82%) diff --git a/samples/drivers/espi/prj_mec1501modular_assy6885.conf b/samples/drivers/espi/boards/mec1501modular_assy6885.conf similarity index 88% rename from samples/drivers/espi/prj_mec1501modular_assy6885.conf rename to samples/drivers/espi/boards/mec1501modular_assy6885.conf index a4d3129ffaf7..5246d0e95b98 100644 --- a/samples/drivers/espi/prj_mec1501modular_assy6885.conf +++ b/samples/drivers/espi/boards/mec1501modular_assy6885.conf @@ -1,5 +1,3 @@ -# eSPI + mec1501modular_assy6885 -CONFIG_ESPI=y CONFIG_LOG=y CONFIG_LOG_BUFFER_SIZE=4096 CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=100 diff --git a/samples/drivers/espi/prj_mec15xxevb_assy6853.conf b/samples/drivers/espi/boards/mec15xxevb_assy6853.conf similarity index 89% rename from samples/drivers/espi/prj_mec15xxevb_assy6853.conf rename to samples/drivers/espi/boards/mec15xxevb_assy6853.conf index 8ed09e105ab2..62985ba39b6f 100644 --- a/samples/drivers/espi/prj_mec15xxevb_assy6853.conf +++ b/samples/drivers/espi/boards/mec15xxevb_assy6853.conf @@ -1,5 +1,3 @@ -# eSPI + mec15xxevb_assy6853 -CONFIG_ESPI=y CONFIG_LOG=y CONFIG_LOG_BUFFER_SIZE=4096 CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=100 diff --git a/samples/drivers/espi/prj_npcx9m6f_evb.conf b/samples/drivers/espi/boards/npcx7m6fb_evb.conf similarity index 82% rename from samples/drivers/espi/prj_npcx9m6f_evb.conf rename to samples/drivers/espi/boards/npcx7m6fb_evb.conf index 63f1084eb585..70b72c9f467d 100644 --- a/samples/drivers/espi/prj_npcx9m6f_evb.conf +++ b/samples/drivers/espi/boards/npcx7m6fb_evb.conf @@ -1,4 +1,3 @@ -# eSPI + npcx9m6f_evb CONFIG_LOG=y CONFIG_LOG_BUFFER_SIZE=4096 CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=100 @@ -6,5 +5,4 @@ CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=100 # Not supported yet CONFIG_ESPI_AUTOMATIC_WARNING_ACKNOWLEDGE=n -CONFIG_ESPI=y CONFIG_ESPI_FLASH_CHANNEL=y diff --git a/samples/drivers/espi/prj_npcx7m6fb_evb.conf b/samples/drivers/espi/boards/npcx9m6f_evb.conf similarity index 82% rename from samples/drivers/espi/prj_npcx7m6fb_evb.conf rename to samples/drivers/espi/boards/npcx9m6f_evb.conf index d6852ab46ff5..70b72c9f467d 100644 --- a/samples/drivers/espi/prj_npcx7m6fb_evb.conf +++ b/samples/drivers/espi/boards/npcx9m6f_evb.conf @@ -1,4 +1,3 @@ -# eSPI + npcx7m6fb_evb CONFIG_LOG=y CONFIG_LOG_BUFFER_SIZE=4096 CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=100 @@ -6,5 +5,4 @@ CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=100 # Not supported yet CONFIG_ESPI_AUTOMATIC_WARNING_ACKNOWLEDGE=n -CONFIG_ESPI=y CONFIG_ESPI_FLASH_CHANNEL=y From 3e3cee7f11a7c38796943658a6d827b30d16c15f Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 17 Mar 2023 13:01:14 +0000 Subject: [PATCH 0427/1906] samples: bluetooth: mesh_demo: Replace prj_ files with overlays Replaces the old prj_.conf files with board overlays instead. Signed-off-by: Jamie McCrae --- .../bbc_microbit.conf} | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) rename samples/bluetooth/mesh_demo/{prj_bbc_microbit.conf => boards/bbc_microbit.conf} (54%) diff --git a/samples/bluetooth/mesh_demo/prj_bbc_microbit.conf b/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf similarity index 54% rename from samples/bluetooth/mesh_demo/prj_bbc_microbit.conf rename to samples/bluetooth/mesh_demo/boards/bbc_microbit.conf index 9f46c3b60749..385abb88be4d 100644 --- a/samples/bluetooth/mesh_demo/prj_bbc_microbit.conf +++ b/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf @@ -7,34 +7,16 @@ CONFIG_MICROBIT_DISPLAY=y CONFIG_PWM=y CONFIG_PWM_NRF5_SW=y -CONFIG_BT=y +CONFIG_BT_TINYCRYPT_ECC=n CONFIG_BT_RX_STACK_SIZE=1280 CONFIG_BT_CTLR_DUP_FILTER_LEN=0 -CONFIG_BT_OBSERVER=y -CONFIG_BT_BROADCASTER=y CONFIG_BT_PHY_UPDATE=n CONFIG_BT_DATA_LEN_UPDATE=n CONFIG_BT_EXT_ADV=n CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=15 -CONFIG_BT_MESH=y -CONFIG_BT_MESH_RELAY=y CONFIG_BT_MESH_SEG_BUFS=6 -CONFIG_BT_MESH_SUBNET_COUNT=1 -CONFIG_BT_MESH_APP_KEY_COUNT=1 -CONFIG_BT_MESH_MODEL_GROUP_COUNT=2 CONFIG_BT_MESH_ADV_BUF_COUNT=3 -CONFIG_BT_MESH_LOOPBACK_BUFS=8 -CONFIG_BT_MESH_PB_ADV=n CONFIG_BT_MESH_RELAY_BUF_COUNT=2 CONFIG_BT_MESH_MSG_CACHE_SIZE=2 -CONFIG_BT_MESH_CFG_CLI=y CONFIG_BT_MESH_BEACON_ENABLED=n - -CONFIG_BT_SETTINGS=y -CONFIG_FLASH=y -CONFIG_FLASH_PAGE_LAYOUT=y -CONFIG_FLASH_MAP=y -CONFIG_NVS=y -CONFIG_SETTINGS=y -CONFIG_BT_MESH_RPL_STORE_TIMEOUT=600 From 7bc1450efeb2cbd8db04d2ce3db49d0672ff1fcc Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 17 Mar 2023 13:05:25 +0000 Subject: [PATCH 0428/1906] samples: bluetooth: mesh: Replace prj_ files with overlays Replaces the old prj_.conf files with board overlays instead. Signed-off-by: Jamie McCrae --- .../bluetooth/mesh/boards/bbc_microbit.conf | 32 ++++++++++ samples/bluetooth/mesh/prj_bbc_microbit.conf | 64 ------------------- 2 files changed, 32 insertions(+), 64 deletions(-) create mode 100644 samples/bluetooth/mesh/boards/bbc_microbit.conf delete mode 100644 samples/bluetooth/mesh/prj_bbc_microbit.conf diff --git a/samples/bluetooth/mesh/boards/bbc_microbit.conf b/samples/bluetooth/mesh/boards/bbc_microbit.conf new file mode 100644 index 000000000000..afe8619c8b40 --- /dev/null +++ b/samples/bluetooth/mesh/boards/bbc_microbit.conf @@ -0,0 +1,32 @@ +CONFIG_INIT_STACKS=y +CONFIG_ISR_STACK_SIZE=768 +CONFIG_MAIN_STACK_SIZE=512 +CONFIG_DISPLAY=y +CONFIG_MICROBIT_DISPLAY=y +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1024 +CONFIG_MICROBIT_DISPLAY_STR_MAX=5 +CONFIG_GPIO=y + +CONFIG_PM=n + +CONFIG_FLASH_PAGE_LAYOUT=y + +CONFIG_BT_RX_STACK_SIZE=1100 +CONFIG_BT_BUF_EVT_RX_COUNT=3 +CONFIG_BT_BUF_ACL_RX_COUNT=3 +CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=3 +CONFIG_BT_EXT_ADV=n + +CONFIG_BT_BROADCASTER=y + +CONFIG_BT_CTLR_LE_PING=n +CONFIG_BT_CTLR_CHAN_SEL_2=n +CONFIG_BT_CTLR_ADV_EXT=n + +CONFIG_BT_MESH_ADV_BUF_COUNT=3 +CONFIG_BT_MESH_SEG_BUFS=3 +CONFIG_BT_MESH_LOOPBACK_BUFS=1 +CONFIG_BT_MESH_SUBNET_COUNT=1 +CONFIG_BT_MESH_APP_KEY_COUNT=1 +CONFIG_BT_MESH_MODEL_GROUP_COUNT=1 +CONFIG_BT_MESH_LABEL_COUNT=0 diff --git a/samples/bluetooth/mesh/prj_bbc_microbit.conf b/samples/bluetooth/mesh/prj_bbc_microbit.conf deleted file mode 100644 index 1ba4f2b4c021..000000000000 --- a/samples/bluetooth/mesh/prj_bbc_microbit.conf +++ /dev/null @@ -1,64 +0,0 @@ -CONFIG_INIT_STACKS=y -CONFIG_ISR_STACK_SIZE=768 -CONFIG_MAIN_STACK_SIZE=512 -CONFIG_DISPLAY=y -CONFIG_MICROBIT_DISPLAY=y -CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1024 -CONFIG_MICROBIT_DISPLAY_STR_MAX=5 -CONFIG_GPIO=y - -CONFIG_PM=n - -CONFIG_BT_SETTINGS=y -CONFIG_FLASH=y -CONFIG_FLASH_PAGE_LAYOUT=y -CONFIG_FLASH_MAP=y -CONFIG_NVS=y -CONFIG_SETTINGS=y - -CONFIG_BT=y -CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_RX_STACK_SIZE=1100 -CONFIG_BT_BUF_EVT_RX_COUNT=3 -CONFIG_BT_BUF_ACL_RX_COUNT=3 -CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=3 -CONFIG_BT_EXT_ADV=n - -CONFIG_BT_CTLR_DUP_FILTER_LEN=0 -CONFIG_BT_OBSERVER=y -CONFIG_BT_BROADCASTER=y - -CONFIG_BT_CTLR_LE_ENC=n -CONFIG_BT_CTLR_LE_PING=n -CONFIG_BT_DATA_LEN_UPDATE=n -CONFIG_BT_PHY_UPDATE=n -CONFIG_BT_CTLR_CHAN_SEL_2=n -CONFIG_BT_CTLR_MIN_USED_CHAN=n -CONFIG_BT_CTLR_ADV_EXT=n -CONFIG_BT_CTLR_PRIVACY=n - -CONFIG_BT_MESH=y -CONFIG_BT_MESH_ADV_BUF_COUNT=3 -CONFIG_BT_MESH_SEG_BUFS=3 -CONFIG_BT_MESH_RELAY=n -CONFIG_BT_MESH_LOOPBACK_BUFS=1 -#CONFIG_BT_MESH_LOW_POWER=y - -#CONFIG_BT_MESH_SELF_TEST=y -#CONFIG_BT_MESH_IV_UPDATE_TEST=y - -CONFIG_BT_MESH_SUBNET_COUNT=1 -CONFIG_BT_MESH_APP_KEY_COUNT=1 -CONFIG_BT_MESH_MODEL_GROUP_COUNT=1 -CONFIG_BT_MESH_LABEL_COUNT=0 - -#CONFIG_BT_DEBUG_LOG=y - -#CONFIG_BT_MESH_LOG_LEVEL_DBG=y -#CONFIG_BT_MESH_NET_LOG_LEVEL_DBG=y -#CONFIG_BT_MESH_TRANS_LOG_LEVEL_DBG=y -#CONFIG_BT_MESH_LOG_LEVEL_DBG=y -#CONFIG_BT_MESH_BEACON_LOG_LEVEL_DBG=y -#CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y -#CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y -#CONFIG_BT_MESH_ACCESS_LOG_LEVEL_DBG=y From 4294d43bc9fbffccbdf01872f09b1b366128253d Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 17 Mar 2023 13:19:00 +0000 Subject: [PATCH 0429/1906] tests: fs: fcb: Replace prj_ files with overlays Replaces the old prj_.conf files with board overlays instead. Signed-off-by: Jamie McCrae --- tests/subsys/fs/fcb/boards/nrf51dk_nrf51422.conf | 2 ++ tests/subsys/fs/fcb/boards/nrf52840dk_nrf52840.conf | 2 ++ tests/subsys/fs/fcb/boards/nrf52dk_nrf52832.conf | 2 ++ tests/subsys/fs/fcb/boards/nucleo_h743zi.conf | 3 +++ tests/subsys/fs/fcb/boards/qemu_x86.conf | 1 + tests/subsys/fs/fcb/prj.conf | 2 -- tests/subsys/fs/fcb/prj_native_posix.conf | 8 -------- tests/subsys/fs/fcb/prj_native_posix_64.conf | 8 -------- tests/subsys/fs/fcb/prj_nucleo_h743zi.conf | 12 ------------ tests/subsys/fs/fcb/prj_qemu_x86.conf | 9 --------- 10 files changed, 10 insertions(+), 39 deletions(-) create mode 100644 tests/subsys/fs/fcb/boards/nrf51dk_nrf51422.conf create mode 100644 tests/subsys/fs/fcb/boards/nrf52840dk_nrf52840.conf create mode 100644 tests/subsys/fs/fcb/boards/nrf52dk_nrf52832.conf create mode 100644 tests/subsys/fs/fcb/boards/nucleo_h743zi.conf create mode 100644 tests/subsys/fs/fcb/boards/qemu_x86.conf delete mode 100644 tests/subsys/fs/fcb/prj_native_posix.conf delete mode 100644 tests/subsys/fs/fcb/prj_native_posix_64.conf delete mode 100644 tests/subsys/fs/fcb/prj_nucleo_h743zi.conf delete mode 100644 tests/subsys/fs/fcb/prj_qemu_x86.conf diff --git a/tests/subsys/fs/fcb/boards/nrf51dk_nrf51422.conf b/tests/subsys/fs/fcb/boards/nrf51dk_nrf51422.conf new file mode 100644 index 000000000000..31ccb5002e5c --- /dev/null +++ b/tests/subsys/fs/fcb/boards/nrf51dk_nrf51422.conf @@ -0,0 +1,2 @@ +CONFIG_ARM_MPU=n +CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y diff --git a/tests/subsys/fs/fcb/boards/nrf52840dk_nrf52840.conf b/tests/subsys/fs/fcb/boards/nrf52840dk_nrf52840.conf new file mode 100644 index 000000000000..31ccb5002e5c --- /dev/null +++ b/tests/subsys/fs/fcb/boards/nrf52840dk_nrf52840.conf @@ -0,0 +1,2 @@ +CONFIG_ARM_MPU=n +CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y diff --git a/tests/subsys/fs/fcb/boards/nrf52dk_nrf52832.conf b/tests/subsys/fs/fcb/boards/nrf52dk_nrf52832.conf new file mode 100644 index 000000000000..31ccb5002e5c --- /dev/null +++ b/tests/subsys/fs/fcb/boards/nrf52dk_nrf52832.conf @@ -0,0 +1,2 @@ +CONFIG_ARM_MPU=n +CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y diff --git a/tests/subsys/fs/fcb/boards/nucleo_h743zi.conf b/tests/subsys/fs/fcb/boards/nucleo_h743zi.conf new file mode 100644 index 000000000000..2ac67b21f17a --- /dev/null +++ b/tests/subsys/fs/fcb/boards/nucleo_h743zi.conf @@ -0,0 +1,3 @@ +CONFIG_ARM_MPU=n +CONFIG_MAIN_STACK_SIZE=4096 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 diff --git a/tests/subsys/fs/fcb/boards/qemu_x86.conf b/tests/subsys/fs/fcb/boards/qemu_x86.conf new file mode 100644 index 000000000000..498f172bae23 --- /dev/null +++ b/tests/subsys/fs/fcb/boards/qemu_x86.conf @@ -0,0 +1 @@ +CONFIG_FLASH_SIMULATOR_UNALIGNED_READ=y diff --git a/tests/subsys/fs/fcb/prj.conf b/tests/subsys/fs/fcb/prj.conf index 8e42e60e682d..e41051fb35a7 100644 --- a/tests/subsys/fs/fcb/prj.conf +++ b/tests/subsys/fs/fcb/prj.conf @@ -3,8 +3,6 @@ CONFIG_STDOUT_CONSOLE=y CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_FLASH_MAP=y -CONFIG_ARM_MPU=n CONFIG_FCB=y CONFIG_FCB_ALLOW_FIXED_ENDMARKER=y -CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/fs/fcb/prj_native_posix.conf b/tests/subsys/fs/fcb/prj_native_posix.conf deleted file mode 100644 index e41051fb35a7..000000000000 --- a/tests/subsys/fs/fcb/prj_native_posix.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_STDOUT_CONSOLE=y -CONFIG_FLASH=y -CONFIG_FLASH_PAGE_LAYOUT=y -CONFIG_FLASH_MAP=y -CONFIG_FCB=y -CONFIG_FCB_ALLOW_FIXED_ENDMARKER=y -CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/fs/fcb/prj_native_posix_64.conf b/tests/subsys/fs/fcb/prj_native_posix_64.conf deleted file mode 100644 index e41051fb35a7..000000000000 --- a/tests/subsys/fs/fcb/prj_native_posix_64.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_STDOUT_CONSOLE=y -CONFIG_FLASH=y -CONFIG_FLASH_PAGE_LAYOUT=y -CONFIG_FLASH_MAP=y -CONFIG_FCB=y -CONFIG_FCB_ALLOW_FIXED_ENDMARKER=y -CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/fs/fcb/prj_nucleo_h743zi.conf b/tests/subsys/fs/fcb/prj_nucleo_h743zi.conf deleted file mode 100644 index a2b93769a943..000000000000 --- a/tests/subsys/fs/fcb/prj_nucleo_h743zi.conf +++ /dev/null @@ -1,12 +0,0 @@ -# General Zephyr configurations -CONFIG_ZTEST=y -CONFIG_STDOUT_CONSOLE=y -CONFIG_FLASH=y -CONFIG_FLASH_PAGE_LAYOUT=y -CONFIG_FLASH_MAP=y -CONFIG_ARM_MPU=n -CONFIG_FCB=y -CONFIG_FCB_ALLOW_FIXED_ENDMARKER=y -CONFIG_MAIN_STACK_SIZE=4096 -CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 -CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/fs/fcb/prj_qemu_x86.conf b/tests/subsys/fs/fcb/prj_qemu_x86.conf deleted file mode 100644 index 1e7d39b2c4d4..000000000000 --- a/tests/subsys/fs/fcb/prj_qemu_x86.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_STDOUT_CONSOLE=y -CONFIG_FLASH=y -CONFIG_FLASH_PAGE_LAYOUT=y -CONFIG_FLASH_MAP=y -CONFIG_FCB=y -CONFIG_FCB_ALLOW_FIXED_ENDMARKER=y -CONFIG_FLASH_SIMULATOR_UNALIGNED_READ=y -CONFIG_ZTEST_NEW_API=y From 3ad67c891d3e0be04b223f90646a054365926974 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 17 Mar 2023 13:52:59 +0000 Subject: [PATCH 0430/1906] tests: fs: fat_fs_api: Simplify configuration Simplifies configuration by removing un-needed files Signed-off-by: Jamie McCrae --- tests/subsys/fs/fat_fs_api/prj.conf | 2 -- tests/subsys/fs/fat_fs_api/prj_native_posix.conf | 9 --------- tests/subsys/fs/fat_fs_api/prj_native_posix_64.conf | 9 --------- 3 files changed, 20 deletions(-) delete mode 100644 tests/subsys/fs/fat_fs_api/prj_native_posix.conf delete mode 100644 tests/subsys/fs/fat_fs_api/prj_native_posix_64.conf diff --git a/tests/subsys/fs/fat_fs_api/prj.conf b/tests/subsys/fs/fat_fs_api/prj.conf index 7bd67dd3078e..3a46ae26ed6d 100644 --- a/tests/subsys/fs/fat_fs_api/prj.conf +++ b/tests/subsys/fs/fat_fs_api/prj.conf @@ -3,8 +3,6 @@ CONFIG_FILE_SYSTEM_MKFS=y CONFIG_LOG=y CONFIG_FAT_FILESYSTEM_ELM=y CONFIG_DISK_DRIVER_FLASH=y -CONFIG_SPI=y -CONFIG_GPIO=y CONFIG_ZTEST=y CONFIG_ZTEST_NEW_API=y CONFIG_FLASH=y diff --git a/tests/subsys/fs/fat_fs_api/prj_native_posix.conf b/tests/subsys/fs/fat_fs_api/prj_native_posix.conf deleted file mode 100644 index 3a46ae26ed6d..000000000000 --- a/tests/subsys/fs/fat_fs_api/prj_native_posix.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_FILE_SYSTEM=y -CONFIG_FILE_SYSTEM_MKFS=y -CONFIG_LOG=y -CONFIG_FAT_FILESYSTEM_ELM=y -CONFIG_DISK_DRIVER_FLASH=y -CONFIG_ZTEST=y -CONFIG_ZTEST_NEW_API=y -CONFIG_FLASH=y -CONFIG_FLASH_MAP=y diff --git a/tests/subsys/fs/fat_fs_api/prj_native_posix_64.conf b/tests/subsys/fs/fat_fs_api/prj_native_posix_64.conf deleted file mode 100644 index 3a46ae26ed6d..000000000000 --- a/tests/subsys/fs/fat_fs_api/prj_native_posix_64.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_FILE_SYSTEM=y -CONFIG_FILE_SYSTEM_MKFS=y -CONFIG_LOG=y -CONFIG_FAT_FILESYSTEM_ELM=y -CONFIG_DISK_DRIVER_FLASH=y -CONFIG_ZTEST=y -CONFIG_ZTEST_NEW_API=y -CONFIG_FLASH=y -CONFIG_FLASH_MAP=y From 5bc019d7139404e9e9c4902e4f435a7e38046257 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 20 Mar 2023 08:27:18 +0000 Subject: [PATCH 0431/1906] samples: tracing: Replace prj_ files with overlays Replaces the old prj_.conf files with board overlays instead. Signed-off-by: Jamie McCrae --- .../tracing/{prj_native_posix.conf => boards/native_posix.conf} | 0 samples/subsys/tracing/sample.yaml | 1 - 2 files changed, 1 deletion(-) rename samples/subsys/tracing/{prj_native_posix.conf => boards/native_posix.conf} (100%) diff --git a/samples/subsys/tracing/prj_native_posix.conf b/samples/subsys/tracing/boards/native_posix.conf similarity index 100% rename from samples/subsys/tracing/prj_native_posix.conf rename to samples/subsys/tracing/boards/native_posix.conf diff --git a/samples/subsys/tracing/sample.yaml b/samples/subsys/tracing/sample.yaml index 09a179a9a398..a16939f22e8e 100644 --- a/samples/subsys/tracing/sample.yaml +++ b/samples/subsys/tracing/sample.yaml @@ -39,7 +39,6 @@ tests: extra_args: CONF_FILE="prj_usb_ctf.conf" sample.tracing.transport.native_posix: platform_allow: native_posix - extra_args: CONF_FILE="prj_native_posix.conf" sample.tracing.transport.native_posix.ctf: platform_allow: native_posix extra_args: CONF_FILE="prj_native_posix_ctf.conf" From 192f64f73cde0e1cc69c5f792927cc3430b1acc6 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 20 Mar 2023 08:29:50 +0000 Subject: [PATCH 0432/1906] tests: drivers: eeprom: api: Replace prj_ files with overlays Replaces the old prj_.conf files with board overlays instead. Signed-off-by: Jamie McCrae --- .../eeprom/api/{prj_qemu_x86.conf => boards/qemu_x86.conf} | 4 ---- 1 file changed, 4 deletions(-) rename tests/drivers/eeprom/api/{prj_qemu_x86.conf => boards/qemu_x86.conf} (51%) diff --git a/tests/drivers/eeprom/api/prj_qemu_x86.conf b/tests/drivers/eeprom/api/boards/qemu_x86.conf similarity index 51% rename from tests/drivers/eeprom/api/prj_qemu_x86.conf rename to tests/drivers/eeprom/api/boards/qemu_x86.conf index 8592575d7dc1..b41113139f07 100644 --- a/tests/drivers/eeprom/api/prj_qemu_x86.conf +++ b/tests/drivers/eeprom/api/boards/qemu_x86.conf @@ -1,7 +1,3 @@ -CONFIG_ZTEST=y -CONFIG_ZTEST_NEW_API=y -CONFIG_TEST_USERSPACE=y -CONFIG_EEPROM=y CONFIG_EEPROM_SIMULATOR=y CONFIG_EEPROM_EMULATOR=y CONFIG_EEPROM_INIT_PRIORITY=75 From abc33f61e581060c1d82c1d403ee25cd439f78ef Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 20 Mar 2023 08:33:36 +0000 Subject: [PATCH 0433/1906] tests: dfu: mcuboot: Replace prj_ files with overlays Replaces the old prj_.conf files with board overlays instead. Signed-off-by: Jamie McCrae --- tests/subsys/dfu/mcuboot/boards/nrf52840dk_nrf52840.conf | 1 + tests/subsys/dfu/mcuboot/prj.conf | 1 - tests/subsys/dfu/mcuboot/prj_native_posix.conf | 9 --------- tests/subsys/dfu/mcuboot/prj_native_posix_64.conf | 9 --------- 4 files changed, 1 insertion(+), 19 deletions(-) create mode 100644 tests/subsys/dfu/mcuboot/boards/nrf52840dk_nrf52840.conf delete mode 100644 tests/subsys/dfu/mcuboot/prj_native_posix.conf delete mode 100644 tests/subsys/dfu/mcuboot/prj_native_posix_64.conf diff --git a/tests/subsys/dfu/mcuboot/boards/nrf52840dk_nrf52840.conf b/tests/subsys/dfu/mcuboot/boards/nrf52840dk_nrf52840.conf new file mode 100644 index 000000000000..b695c18ab28d --- /dev/null +++ b/tests/subsys/dfu/mcuboot/boards/nrf52840dk_nrf52840.conf @@ -0,0 +1 @@ +CONFIG_ARM_MPU=n diff --git a/tests/subsys/dfu/mcuboot/prj.conf b/tests/subsys/dfu/mcuboot/prj.conf index 3807279f430d..ebef72eb7e85 100644 --- a/tests/subsys/dfu/mcuboot/prj.conf +++ b/tests/subsys/dfu/mcuboot/prj.conf @@ -6,5 +6,4 @@ CONFIG_STREAM_FLASH=y CONFIG_IMG_MANAGER=y CONFIG_MCUBOOT_IMG_MANAGER=y CONFIG_IMG_BLOCK_BUF_SIZE=512 -CONFIG_ARM_MPU=n CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/dfu/mcuboot/prj_native_posix.conf b/tests/subsys/dfu/mcuboot/prj_native_posix.conf deleted file mode 100644 index ebef72eb7e85..000000000000 --- a/tests/subsys/dfu/mcuboot/prj_native_posix.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_STDOUT_CONSOLE=y -CONFIG_FLASH=y -CONFIG_FLASH_MAP=y -CONFIG_STREAM_FLASH=y -CONFIG_IMG_MANAGER=y -CONFIG_MCUBOOT_IMG_MANAGER=y -CONFIG_IMG_BLOCK_BUF_SIZE=512 -CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/dfu/mcuboot/prj_native_posix_64.conf b/tests/subsys/dfu/mcuboot/prj_native_posix_64.conf deleted file mode 100644 index ebef72eb7e85..000000000000 --- a/tests/subsys/dfu/mcuboot/prj_native_posix_64.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_STDOUT_CONSOLE=y -CONFIG_FLASH=y -CONFIG_FLASH_MAP=y -CONFIG_STREAM_FLASH=y -CONFIG_IMG_MANAGER=y -CONFIG_MCUBOOT_IMG_MANAGER=y -CONFIG_IMG_BLOCK_BUF_SIZE=512 -CONFIG_ZTEST_NEW_API=y From 7e77084cc3babf39bf3bb57a1f19344f83d0bf6d Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 20 Mar 2023 08:35:24 +0000 Subject: [PATCH 0434/1906] tests: dfu: img_util: Replace prj_ files with overlays Replaces the old prj_.conf files with board overlays instead. Signed-off-by: Jamie McCrae --- .../dfu/img_util/boards/nrf52840dk_nrf52840.conf | 1 + tests/subsys/dfu/img_util/prj.conf | 1 - tests/subsys/dfu/img_util/prj_native_posix.conf | 10 ---------- tests/subsys/dfu/img_util/prj_native_posix_64.conf | 10 ---------- 4 files changed, 1 insertion(+), 21 deletions(-) create mode 100644 tests/subsys/dfu/img_util/boards/nrf52840dk_nrf52840.conf delete mode 100644 tests/subsys/dfu/img_util/prj_native_posix.conf delete mode 100644 tests/subsys/dfu/img_util/prj_native_posix_64.conf diff --git a/tests/subsys/dfu/img_util/boards/nrf52840dk_nrf52840.conf b/tests/subsys/dfu/img_util/boards/nrf52840dk_nrf52840.conf new file mode 100644 index 000000000000..b695c18ab28d --- /dev/null +++ b/tests/subsys/dfu/img_util/boards/nrf52840dk_nrf52840.conf @@ -0,0 +1 @@ +CONFIG_ARM_MPU=n diff --git a/tests/subsys/dfu/img_util/prj.conf b/tests/subsys/dfu/img_util/prj.conf index ff14175cdf8d..b8183095aaf4 100644 --- a/tests/subsys/dfu/img_util/prj.conf +++ b/tests/subsys/dfu/img_util/prj.conf @@ -7,5 +7,4 @@ CONFIG_IMG_MANAGER=y CONFIG_IMG_ENABLE_IMAGE_CHECK=y CONFIG_MCUBOOT_IMG_MANAGER=y CONFIG_IMG_BLOCK_BUF_SIZE=512 -CONFIG_ARM_MPU=n CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/dfu/img_util/prj_native_posix.conf b/tests/subsys/dfu/img_util/prj_native_posix.conf deleted file mode 100644 index b8183095aaf4..000000000000 --- a/tests/subsys/dfu/img_util/prj_native_posix.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_STDOUT_CONSOLE=y -CONFIG_FLASH=y -CONFIG_FLASH_MAP=y -CONFIG_STREAM_FLASH=y -CONFIG_IMG_MANAGER=y -CONFIG_IMG_ENABLE_IMAGE_CHECK=y -CONFIG_MCUBOOT_IMG_MANAGER=y -CONFIG_IMG_BLOCK_BUF_SIZE=512 -CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/dfu/img_util/prj_native_posix_64.conf b/tests/subsys/dfu/img_util/prj_native_posix_64.conf deleted file mode 100644 index b8183095aaf4..000000000000 --- a/tests/subsys/dfu/img_util/prj_native_posix_64.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_ZTEST=y -CONFIG_STDOUT_CONSOLE=y -CONFIG_FLASH=y -CONFIG_FLASH_MAP=y -CONFIG_STREAM_FLASH=y -CONFIG_IMG_MANAGER=y -CONFIG_IMG_ENABLE_IMAGE_CHECK=y -CONFIG_MCUBOOT_IMG_MANAGER=y -CONFIG_IMG_BLOCK_BUF_SIZE=512 -CONFIG_ZTEST_NEW_API=y From fbdd4ee379784c7e931caf0add5243aa8eebc176 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 20 Mar 2023 08:39:55 +0000 Subject: [PATCH 0435/1906] cmake: Add warning when using prj_.conf file Adds a warning that this method of configuration is deprecated. Signed-off-by: Jamie McCrae --- cmake/modules/configuration_files.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/modules/configuration_files.cmake b/cmake/modules/configuration_files.cmake index 5ed9777816b0..74fc7cecbb64 100644 --- a/cmake/modules/configuration_files.cmake +++ b/cmake/modules/configuration_files.cmake @@ -67,6 +67,8 @@ elseif(CACHED_CONF_FILE) set(CONF_FILE ${CACHED_CONF_FILE}) elseif(EXISTS ${APPLICATION_CONFIG_DIR}/prj_${BOARD}.conf) set(CONF_FILE ${APPLICATION_CONFIG_DIR}/prj_${BOARD}.conf) + message(WARNING "Note that `prj_.conf` files are deprecated and should be " + "replaced with board Kconfig fragments instead.") elseif(EXISTS ${APPLICATION_CONFIG_DIR}/prj.conf) set(CONF_FILE ${APPLICATION_CONFIG_DIR}/prj.conf) set(CONF_FILE_INCLUDE_FRAGMENTS true) From c18e7f3ec172dc32deaaa2fa13e304cbbfd7b8c3 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 20 Mar 2023 08:41:55 +0000 Subject: [PATCH 0436/1906] docs: release: 3.4: Add note on prj_.conf deprecation Adds a note that this method of configuration is now deprecated. Signed-off-by: Jamie McCrae --- doc/releases/release-notes-3.4.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/releases/release-notes-3.4.rst b/doc/releases/release-notes-3.4.rst index 85558ed98f39..82ae508eea24 100644 --- a/doc/releases/release-notes-3.4.rst +++ b/doc/releases/release-notes-3.4.rst @@ -118,6 +118,11 @@ Removed APIs in this release Deprecated in this release ========================== +* Configuring applications with ``prj_.conf`` files has been deprecated, + this should be replaced by using a prj.conf with the common configuration and + board-specific configuration in board Kconfig fragments in the ``boards`` + folder of the application. + Stable API changes in this release ================================== From 86e1740cfccc1146771e164a7c769b18bb569a97 Mon Sep 17 00:00:00 2001 From: Robert Hancock Date: Wed, 15 Mar 2023 16:55:40 +0000 Subject: [PATCH 0437/1906] serial: xilinx: uartlite: Fix infinite spin in xlnx_uartlite_fifo_read The xlnx_uartlite_fifo_read function would spin indefinitely if there was less data available in the RX FIFO than the size of the passed-in buffer. This call is supposed to be non-blocking. Fixed to break out of the loop if there are no more bytes left in the RX FIFO. Signed-off-by: Robert Hancock --- drivers/serial/uart_xlnx_uartlite.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/serial/uart_xlnx_uartlite.c b/drivers/serial/uart_xlnx_uartlite.c index fa8aaf8a6242..a5a27198d2ad 100644 --- a/drivers/serial/uart_xlnx_uartlite.c +++ b/drivers/serial/uart_xlnx_uartlite.c @@ -214,6 +214,9 @@ static int xlnx_uartlite_fifo_read(const struct device *dev, uint8_t *rx_data, rx_data[count++] = xlnx_uartlite_read_rx_fifo(dev); } k_spin_unlock(&data->rx_lock, key); + if (!(status & STAT_REG_RX_FIFO_VALID_DATA)) { + break; + } } return count; From 9f8913c4e049caa6f9fc3d1ac39d495beb5586ec Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Thu, 16 Mar 2023 14:58:27 +0000 Subject: [PATCH 0438/1906] toolchain: Add ARMClang to gcc related toolchain flags check Add ARMClang similar to LLVM to check to skip GCC specific flags Signed-off-by: Kumar Gala --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2c5b7ab05b4..72d9e28df728 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -408,7 +408,8 @@ zephyr_compile_options(${COMPILER_OPT_AS_LIST}) # TODO: Include arch compiler options at this point. if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang" AND - NOT CMAKE_C_COMPILER_ID STREQUAL "IntelLLVM") + NOT CMAKE_C_COMPILER_ID STREQUAL "IntelLLVM" AND + NOT CMAKE_C_COMPILER_ID STREQUAL "ARMClang") # GCC assumed zephyr_cc_option(-fno-reorder-functions) From 0866ea4e2176999b145ca04e2ef4859e55a1928f Mon Sep 17 00:00:00 2001 From: Armin Brauns Date: Mon, 13 Feb 2023 10:53:06 +0100 Subject: [PATCH 0439/1906] include: drivers: fix typo in gpio.h Rising/Falling, not Rising/Failing Signed-off-by: Armin Brauns --- include/zephyr/drivers/gpio.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/zephyr/drivers/gpio.h b/include/zephyr/drivers/gpio.h index 7a9b967357af..d9b7a685ab39 100644 --- a/include/zephyr/drivers/gpio.h +++ b/include/zephyr/drivers/gpio.h @@ -513,7 +513,8 @@ enum gpio_int_mode { enum gpio_int_trig { /* Trigger detection when input state is (or transitions to) - * physical low. (Edge Failing or Active Low) */ + * physical low. (Edge Falling or Active Low) + */ GPIO_INT_TRIG_LOW = GPIO_INT_LOW_0, /* Trigger detection when input state is (or transitions to) * physical high. (Edge Rising or Active High) */ From 8f8300d5fe48ee31003cb019e628df04feb16a1b Mon Sep 17 00:00:00 2001 From: Armin Brauns Date: Mon, 13 Feb 2023 14:45:04 +0100 Subject: [PATCH 0440/1906] dts: bindings: deduplicate mcp23xxx bindings The only difference between mcp230xx and mcp23sxx is I2C vs. SPI. Signed-off-by: Armin Brauns --- dts/bindings/gpio/microchip,mcp230xx.yaml | 16 +------------- dts/bindings/gpio/microchip,mcp23sxx.yaml | 18 +--------------- dts/bindings/gpio/microchip,mcp23xxx.yaml | 26 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 32 deletions(-) create mode 100644 dts/bindings/gpio/microchip,mcp23xxx.yaml diff --git a/dts/bindings/gpio/microchip,mcp230xx.yaml b/dts/bindings/gpio/microchip,mcp230xx.yaml index 7fcb455d0c05..fdc56ef19643 100644 --- a/dts/bindings/gpio/microchip,mcp230xx.yaml +++ b/dts/bindings/gpio/microchip,mcp230xx.yaml @@ -9,18 +9,4 @@ description: | compatible: "microchip,mcp230xx" -include: [gpio-controller.yaml, i2c-device.yaml] - -properties: - ngpios: - type: int - enum: - - 8 - - 16 - required: true - description: | - Number of gpios supported by the chip. - -gpio-cells: - - pin - - flags +include: ["microchip,mcp23xxx.yaml", i2c-device.yaml] diff --git a/dts/bindings/gpio/microchip,mcp23sxx.yaml b/dts/bindings/gpio/microchip,mcp23sxx.yaml index cf7ff1c3d2f8..afc7ecafe1c8 100644 --- a/dts/bindings/gpio/microchip,mcp23sxx.yaml +++ b/dts/bindings/gpio/microchip,mcp23sxx.yaml @@ -10,20 +10,4 @@ description: | compatible: "microchip,mcp23sxx" -include: [gpio-controller.yaml, spi-device.yaml] - -properties: - "#gpio-cells": - const: 2 - - ngpios: - type: int - required: true - enum: - - 8 - - 16 - description: Number of gpios supported - -gpio-cells: - - pin - - flags +include: ["microchip,mcp23xxx.yaml", spi-device.yaml] diff --git a/dts/bindings/gpio/microchip,mcp23xxx.yaml b/dts/bindings/gpio/microchip,mcp23xxx.yaml new file mode 100644 index 000000000000..62c0dc4288a4 --- /dev/null +++ b/dts/bindings/gpio/microchip,mcp23xxx.yaml @@ -0,0 +1,26 @@ +# +# Copyright (c) 2020 Geanix ApS +# Copyright (c) 2021 Peter Johanson +# Copyright (c) 2021 metraTec GmbH +# +# SPDX-License-Identifier: Apache-2.0 +# + +include: [gpio-controller.yaml] + +properties: + "#gpio-cells": + const: 2 + + ngpios: + type: int + enum: + - 8 + - 16 + required: true + description: | + Number of gpios supported by the chip. + +gpio-cells: + - pin + - flags From 1a566e6a7f6d7b345821e336cb6963afc258f168 Mon Sep 17 00:00:00 2001 From: Armin Brauns Date: Mon, 13 Feb 2023 14:37:23 +0100 Subject: [PATCH 0441/1906] drivers: gpio: mcp23xxx: fix typo Should be the Output LATch register. "IK" is one key away from "OL" on QWERTY keyboards. This define wasn't actually used anywhere. Signed-off-by: Armin Brauns --- drivers/gpio/gpio_mcp23xxx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpio_mcp23xxx.h b/drivers/gpio/gpio_mcp23xxx.h index f45b68d48e39..abfea64c978e 100644 --- a/drivers/gpio/gpio_mcp23xxx.h +++ b/drivers/gpio/gpio_mcp23xxx.h @@ -32,7 +32,7 @@ #define REG_INTF 0x07 #define REG_INTCAP 0x08 #define REG_GPIO 0x09 -#define REG_IKAT 0x0A +#define REG_OLAT 0x0A #define MCP23SXX_ADDR 0x40 #define MCP23SXX_READBIT 0x01 From 0db9785892b8344799a078ba2b58a146cec7731d Mon Sep 17 00:00:00 2001 From: Armin Brauns Date: Mon, 13 Feb 2023 10:15:11 +0100 Subject: [PATCH 0442/1906] drivers: gpio: mcp23xxx: support pin interrupts No single-edge interrupts for now, since they are not supported in hardware. Signed-off-by: Armin Brauns --- drivers/gpio/gpio_mcp230xx.c | 1 + drivers/gpio/gpio_mcp23sxx.c | 1 + drivers/gpio/gpio_mcp23xxx.c | 225 +++++++++++++++++++++- drivers/gpio/gpio_mcp23xxx.h | 8 + dts/bindings/gpio/microchip,mcp23xxx.yaml | 5 + 5 files changed, 238 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio_mcp230xx.c b/drivers/gpio/gpio_mcp230xx.c index 484c4bfd768b..054012e69a2b 100644 --- a/drivers/gpio/gpio_mcp230xx.c +++ b/drivers/gpio/gpio_mcp230xx.c @@ -92,6 +92,7 @@ static int mcp230xx_bus_is_ready(const struct device *dev) .bus = { \ .i2c = I2C_DT_SPEC_INST_GET(inst), \ }, \ + .gpio_int = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \ .ngpios = DT_INST_PROP(inst, ngpios), \ .read_fn = mcp230xx_read_port_regs, \ .write_fn = mcp230xx_write_port_regs, \ diff --git a/drivers/gpio/gpio_mcp23sxx.c b/drivers/gpio/gpio_mcp23sxx.c index 656627487a7c..86ecee8fc6a5 100644 --- a/drivers/gpio/gpio_mcp23sxx.c +++ b/drivers/gpio/gpio_mcp23sxx.c @@ -132,6 +132,7 @@ static int mcp23sxx_bus_is_ready(const struct device *dev) SPI_OP_MODE_MASTER | SPI_MODE_CPOL | \ SPI_MODE_CPHA | SPI_WORD_SET(8), 0) \ }, \ + .gpio_int = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \ .ngpios = DT_INST_PROP(inst, ngpios), \ .read_fn = mcp23sxx_read_port_regs, \ .write_fn = mcp23sxx_write_port_regs, \ diff --git a/drivers/gpio/gpio_mcp23xxx.c b/drivers/gpio/gpio_mcp23xxx.c index 1d84514ff219..aa059ed80057 100644 --- a/drivers/gpio/gpio_mcp23xxx.c +++ b/drivers/gpio/gpio_mcp23xxx.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -68,6 +69,32 @@ static int write_port_regs(const struct device *dev, uint8_t reg, uint16_t value return config->write_fn(dev, reg, value); } +/** + * @brief Writes to the IOCON register of the mcp23xxx. + * + * IOCON is the only register that is not 16 bits wide on 16-pin devices; instead, it is mirrored in + * two adjacent memory locations. Because the underlying `write_fn` always does a 16-bit write for + * 16-pin devices, make sure we write the same value to both IOCON locations. + * + * @param dev The mcp23xxx device. + * @param value the IOCON value to write + * + * @return 0 if successful. Otherwise <0 will be returned. + */ +static int write_iocon(const struct device *dev, uint8_t value) +{ + struct mcp23xxx_drv_data *drv_data = dev->data; + + uint16_t extended_value = value | (value << 8); + int ret = write_port_regs(dev, REG_IOCON, extended_value); + + if (ret == 0) { + drv_data->reg_cache.iocon = extended_value; + } + + return ret; +} + /** * @brief Setup the pin direction. * @@ -255,7 +282,157 @@ static int mcp23xxx_port_toggle_bits(const struct device *dev, uint32_t mask) static int mcp23xxx_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin, enum gpio_int_mode mode, enum gpio_int_trig trig) { - return -ENOTSUP; + struct mcp23xxx_drv_data *drv_data = dev->data; + const struct mcp23xxx_config *config = dev->config; + + if (!config->gpio_int.port) { + return -ENOTSUP; + } + + if (k_is_in_isr()) { + return -EWOULDBLOCK; + } + + k_sem_take(&drv_data->lock, K_FOREVER); + + uint16_t gpinten = drv_data->reg_cache.gpinten; + uint16_t defval = drv_data->reg_cache.defval; + uint16_t intcon = drv_data->reg_cache.intcon; + + int ret; + + switch (mode) { + case GPIO_INT_MODE_DISABLED: + gpinten &= ~BIT(pin); + break; + + case GPIO_INT_MODE_LEVEL: + gpinten |= BIT(pin); + intcon |= BIT(pin); + + switch (trig) { + case GPIO_INT_TRIG_LOW: + defval |= BIT(pin); + break; + case GPIO_INT_TRIG_HIGH: + defval &= ~BIT(pin); + break; + case GPIO_INT_TRIG_BOTH: + /* can't happen */ + ret = -ENOTSUP; + goto done; + } + break; + + case GPIO_INT_MODE_EDGE: + gpinten |= BIT(pin); + intcon &= ~BIT(pin); + + switch (trig) { + case GPIO_INT_TRIG_LOW: + case GPIO_INT_TRIG_HIGH: + LOG_ERR("mcp23xxx does not support single-edge interrupts"); + ret = -ENOTSUP; + goto done; + case GPIO_INT_TRIG_BOTH: + break; + } + break; + } + + ret = write_port_regs(dev, REG_GPINTEN, gpinten); + if (ret != 0) { + goto done; + } + drv_data->reg_cache.gpinten = gpinten; + + ret = write_port_regs(dev, REG_DEFVAL, defval); + if (ret != 0) { + goto done; + } + drv_data->reg_cache.defval = defval; + + ret = write_port_regs(dev, REG_INTCON, intcon); + if (ret != 0) { + goto done; + } + drv_data->reg_cache.intcon = intcon; + +done: + k_sem_give(&drv_data->lock); + + return ret; +} + +static int mcp23xxx_manage_callback(const struct device *dev, struct gpio_callback *callback, + bool set) +{ + struct mcp23xxx_drv_data *drv_data = dev->data; + const struct mcp23xxx_config *config = dev->config; + + if (!config->gpio_int.port) { + return -ENOTSUP; + } + + if (k_is_in_isr()) { + return -EWOULDBLOCK; + } + + k_sem_take(&drv_data->lock, K_FOREVER); + + int ret = gpio_manage_callback(&drv_data->callbacks, callback, set); + + k_sem_give(&drv_data->lock); + + return ret; +} + +static void mcp23xxx_work_handler(struct k_work *work) +{ + struct mcp23xxx_drv_data *drv_data = CONTAINER_OF(work, struct mcp23xxx_drv_data, work); + const struct device *dev = drv_data->dev; + + int ret; + + k_sem_take(&drv_data->lock, K_FOREVER); + + uint16_t intf; + + ret = read_port_regs(dev, REG_INTF, &intf); + if (ret != 0) { + LOG_ERR("Failed to read INTF"); + goto done; + } + + if (!intf) { + /* Probable cause: REG_GPIO was read from somewhere else before the interrupt + * handler had a chance to run + */ + LOG_ERR("Spurious interrupt"); + goto done; + } + + uint16_t intcap; + + /* Read INTCAP to acknowledge the interrupt */ + ret = read_port_regs(dev, REG_INTCAP, &intcap); + if (ret != 0) { + LOG_ERR("Failed to read INTCAP"); + goto done; + } + + gpio_fire_callbacks(&drv_data->callbacks, dev, intf); +done: + k_sem_give(&drv_data->lock); +} + +static void mcp23xxx_int_gpio_handler(const struct device *port, struct gpio_callback *cb, + gpio_port_pins_t pins) +{ + struct mcp23xxx_drv_data *drv_data = + CONTAINER_OF(cb, struct mcp23xxx_drv_data, int_gpio_cb); + + k_work_submit(&drv_data->work); } const struct gpio_driver_api gpio_mcp23xxx_api_table = { @@ -266,6 +443,7 @@ const struct gpio_driver_api gpio_mcp23xxx_api_table = { .port_clear_bits_raw = mcp23xxx_port_clear_bits_raw, .port_toggle_bits = mcp23xxx_port_toggle_bits, .pin_interrupt_configure = mcp23xxx_pin_interrupt_configure, + .manage_callback = mcp23xxx_manage_callback, }; /** @@ -290,7 +468,50 @@ int gpio_mcp23xxx_init(const struct device *dev) return err; } - k_sem_init(&drv_data->lock, 1, 1); + k_sem_init(&drv_data->lock, 0, 1); + + /* If the INT line is available, configure the callback for it. */ + if (config->gpio_int.port) { + if (config->ngpios == 16) { + /* send both ports' interrupts through one IRQ pin */ + err = write_iocon(dev, REG_IOCON_MIRROR); + + if (err != 0) { + LOG_ERR("Failed to enable mirrored IRQ pins: %d", err); + return -EIO; + } + } + + if (!device_is_ready(config->gpio_int.port)) { + LOG_ERR("INT port is not ready"); + return -ENODEV; + } + + drv_data->dev = dev; + k_work_init(&drv_data->work, mcp23xxx_work_handler); + + err = gpio_pin_configure_dt(&config->gpio_int, GPIO_INPUT); + if (err != 0) { + LOG_ERR("Failed to configure INT line: %d", err); + return -EIO; + } + + gpio_init_callback(&drv_data->int_gpio_cb, mcp23xxx_int_gpio_handler, + BIT(config->gpio_int.pin)); + err = gpio_add_callback(config->gpio_int.port, &drv_data->int_gpio_cb); + if (err != 0) { + LOG_ERR("Failed to add INT callback: %d", err); + return -EIO; + } + + err = gpio_pin_interrupt_configure_dt(&config->gpio_int, GPIO_INT_EDGE_TO_ACTIVE); + if (err != 0) { + LOG_ERR("Failed to configure INT interrupt: %d", err); + return -EIO; + } + } + + k_sem_give(&drv_data->lock); return 0; } diff --git a/drivers/gpio/gpio_mcp23xxx.h b/drivers/gpio/gpio_mcp23xxx.h index abfea64c978e..dda599ba5fba 100644 --- a/drivers/gpio/gpio_mcp23xxx.h +++ b/drivers/gpio/gpio_mcp23xxx.h @@ -34,6 +34,8 @@ #define REG_GPIO 0x09 #define REG_OLAT 0x0A +#define REG_IOCON_MIRROR BIT(6) + #define MCP23SXX_ADDR 0x40 #define MCP23SXX_READBIT 0x01 @@ -55,6 +57,8 @@ struct mcp23xxx_config { #endif /* CONFIG_GPIO_MCP23SXX */ } bus; + struct gpio_dt_spec gpio_int; + uint8_t ngpios; mcp23xxx_read_port_regs read_fn; mcp23xxx_write_port_regs write_fn; @@ -67,6 +71,10 @@ struct mcp23xxx_drv_data { struct gpio_driver_data data; struct k_sem lock; + sys_slist_t callbacks; + const struct device *dev; + struct gpio_callback int_gpio_cb; + struct k_work work; struct { uint16_t iodir; diff --git a/dts/bindings/gpio/microchip,mcp23xxx.yaml b/dts/bindings/gpio/microchip,mcp23xxx.yaml index 62c0dc4288a4..46f350f66d30 100644 --- a/dts/bindings/gpio/microchip,mcp23xxx.yaml +++ b/dts/bindings/gpio/microchip,mcp23xxx.yaml @@ -12,6 +12,11 @@ properties: "#gpio-cells": const: 2 + int-gpios: + type: phandle-array + description: | + GPIO connected to the controller INT pin. This pin is active-low. + ngpios: type: int enum: From 07af23c1c66315b6cb3029bb47ce32f1bf452ec1 Mon Sep 17 00:00:00 2001 From: Armin Brauns Date: Mon, 13 Feb 2023 10:52:39 +0100 Subject: [PATCH 0443/1906] drivers: gpio: mcp23xxx: support single-edge interrupts An interrupt is triggered for every edge, but only the desired edges cause a callback to be called. Signed-off-by: Armin Brauns --- drivers/gpio/gpio_mcp23xxx.c | 17 ++++++++++++++--- drivers/gpio/gpio_mcp23xxx.h | 3 +++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpio_mcp23xxx.c b/drivers/gpio/gpio_mcp23xxx.c index aa059ed80057..22655a29bb96 100644 --- a/drivers/gpio/gpio_mcp23xxx.c +++ b/drivers/gpio/gpio_mcp23xxx.c @@ -330,11 +330,16 @@ static int mcp23xxx_pin_interrupt_configure(const struct device *dev, gpio_pin_t switch (trig) { case GPIO_INT_TRIG_LOW: + drv_data->rising_edge_ints &= ~BIT(pin); + drv_data->falling_edge_ints |= BIT(pin); + break; case GPIO_INT_TRIG_HIGH: - LOG_ERR("mcp23xxx does not support single-edge interrupts"); - ret = -ENOTSUP; - goto done; + drv_data->rising_edge_ints |= BIT(pin); + drv_data->falling_edge_ints &= ~BIT(pin); + break; case GPIO_INT_TRIG_BOTH: + drv_data->rising_edge_ints |= BIT(pin); + drv_data->falling_edge_ints |= BIT(pin); break; } break; @@ -421,6 +426,12 @@ static void mcp23xxx_work_handler(struct k_work *work) goto done; } + /* mcp23xxx does not support single-edge interrupts in hardware, filter them out manually */ + uint16_t level_ints = drv_data->reg_cache.gpinten & drv_data->reg_cache.intcon; + + intf &= level_ints | (intcap & drv_data->rising_edge_ints) | + (~intcap & drv_data->falling_edge_ints); + gpio_fire_callbacks(&drv_data->callbacks, dev, intf); done: k_sem_give(&drv_data->lock); diff --git a/drivers/gpio/gpio_mcp23xxx.h b/drivers/gpio/gpio_mcp23xxx.h index dda599ba5fba..2ca000890b26 100644 --- a/drivers/gpio/gpio_mcp23xxx.h +++ b/drivers/gpio/gpio_mcp23xxx.h @@ -76,6 +76,9 @@ struct mcp23xxx_drv_data { struct gpio_callback int_gpio_cb; struct k_work work; + uint16_t rising_edge_ints; + uint16_t falling_edge_ints; + struct { uint16_t iodir; uint16_t ipol; From 01e8b3445e492966b024c0bd1bf66a0ba6ce219b Mon Sep 17 00:00:00 2001 From: Armin Brauns Date: Tue, 14 Feb 2023 10:20:44 +0100 Subject: [PATCH 0444/1906] drivers: gpio: mcp23xxx: add support for reset pin This allows the device to be reset to a known state before initialization. Signed-off-by: Armin Brauns --- drivers/gpio/gpio_mcp230xx.c | 1 + drivers/gpio/gpio_mcp23sxx.c | 1 + drivers/gpio/gpio_mcp23xxx.c | 19 +++++++++++++++++++ drivers/gpio/gpio_mcp23xxx.h | 1 + dts/bindings/gpio/microchip,mcp23xxx.yaml | 5 +++++ 5 files changed, 27 insertions(+) diff --git a/drivers/gpio/gpio_mcp230xx.c b/drivers/gpio/gpio_mcp230xx.c index 054012e69a2b..fabf0f00ce95 100644 --- a/drivers/gpio/gpio_mcp230xx.c +++ b/drivers/gpio/gpio_mcp230xx.c @@ -93,6 +93,7 @@ static int mcp230xx_bus_is_ready(const struct device *dev) .i2c = I2C_DT_SPEC_INST_GET(inst), \ }, \ .gpio_int = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \ + .gpio_reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \ .ngpios = DT_INST_PROP(inst, ngpios), \ .read_fn = mcp230xx_read_port_regs, \ .write_fn = mcp230xx_write_port_regs, \ diff --git a/drivers/gpio/gpio_mcp23sxx.c b/drivers/gpio/gpio_mcp23sxx.c index 86ecee8fc6a5..0ee2f73070d1 100644 --- a/drivers/gpio/gpio_mcp23sxx.c +++ b/drivers/gpio/gpio_mcp23sxx.c @@ -133,6 +133,7 @@ static int mcp23sxx_bus_is_ready(const struct device *dev) SPI_MODE_CPHA | SPI_WORD_SET(8), 0) \ }, \ .gpio_int = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), \ + .gpio_reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \ .ngpios = DT_INST_PROP(inst, ngpios), \ .read_fn = mcp23sxx_read_port_regs, \ .write_fn = mcp23sxx_write_port_regs, \ diff --git a/drivers/gpio/gpio_mcp23xxx.c b/drivers/gpio/gpio_mcp23xxx.c index 22655a29bb96..38d7ea26da3a 100644 --- a/drivers/gpio/gpio_mcp23xxx.c +++ b/drivers/gpio/gpio_mcp23xxx.c @@ -23,6 +23,8 @@ #include LOG_MODULE_REGISTER(gpio_mcp23xxx); +#define MCP23XXX_RESET_TIME_US 1 + /** * @brief Reads given register from mcp23xxx. * @@ -481,6 +483,23 @@ int gpio_mcp23xxx_init(const struct device *dev) k_sem_init(&drv_data->lock, 0, 1); + /* If the RESET line is available, pulse it. */ + if (config->gpio_reset.port) { + err = gpio_pin_configure_dt(&config->gpio_reset, GPIO_OUTPUT_ACTIVE); + if (err != 0) { + LOG_ERR("Failed to configure RESET line: %d", err); + return -EIO; + } + + k_usleep(MCP23XXX_RESET_TIME_US); + + err = gpio_pin_set_dt(&config->gpio_reset, 0); + if (err != 0) { + LOG_ERR("Failed to deactivate RESET line: %d", err); + return -EIO; + } + } + /* If the INT line is available, configure the callback for it. */ if (config->gpio_int.port) { if (config->ngpios == 16) { diff --git a/drivers/gpio/gpio_mcp23xxx.h b/drivers/gpio/gpio_mcp23xxx.h index 2ca000890b26..b741cc957d7a 100644 --- a/drivers/gpio/gpio_mcp23xxx.h +++ b/drivers/gpio/gpio_mcp23xxx.h @@ -58,6 +58,7 @@ struct mcp23xxx_config { } bus; struct gpio_dt_spec gpio_int; + struct gpio_dt_spec gpio_reset; uint8_t ngpios; mcp23xxx_read_port_regs read_fn; diff --git a/dts/bindings/gpio/microchip,mcp23xxx.yaml b/dts/bindings/gpio/microchip,mcp23xxx.yaml index 46f350f66d30..9c0da2b433f1 100644 --- a/dts/bindings/gpio/microchip,mcp23xxx.yaml +++ b/dts/bindings/gpio/microchip,mcp23xxx.yaml @@ -17,6 +17,11 @@ properties: description: | GPIO connected to the controller INT pin. This pin is active-low. + reset-gpios: + type: phandle-array + description: | + GPIO connected to the controller RESET pin. This pin is active-low. + ngpios: type: int enum: From bcf1e8150bdc8e21cae722ff5138cc4c77168cc4 Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Fri, 17 Mar 2023 09:30:41 +0100 Subject: [PATCH 0445/1906] drivers: ieee802154: Fix `csl_rx_time` overflow issue for NRF5 and clean up redundant static functions convert `csl_rx_time` to uint32_t and remove redundant `nrf5_schedule_rx` `nrf5_config_csl_period` and `nrf5_receive_at` static functions. `csl_rx_time` has been passed as uint32. It is compared to uint64 value returned by `nrf_802154_sl_timer_current_time_get` in `nrf_802154_ie_writer.c` which leads to wrong calculation of phase in CSL. Signed-off-by: Maciej Baczmanski --- drivers/ieee802154/ieee802154_nrf5.c | 68 ++++++++++------------------ drivers/ieee802154/ieee802154_nrf5.h | 3 -- 2 files changed, 23 insertions(+), 48 deletions(-) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index 650ff10b6b93..b05fad58a87e 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -839,47 +839,6 @@ static void nrf5_config_mac_keys(struct ieee802154_key *mac_keys) } #endif /* CONFIG_IEEE802154_2015 */ -#if defined(CONFIG_IEEE802154_CSL_ENDPOINT) -static void nrf5_receive_at(uint32_t start, uint32_t duration, uint8_t channel, uint32_t id) -{ - /* - * Workaround until OpenThread (the only CSL user in Zephyr so far) is able to schedule - * RX windows using 64-bit time. - */ - uint64_t rx_time = target_time_convert_to_64_bits(start); - - nrf_802154_receive_at(rx_time, duration, channel, id); -} - -static void nrf5_config_csl_period(uint16_t period) -{ - nrf_802154_csl_writer_period_set(period); - - /* Update the CSL anchor time to match the nearest requested CSL window, so that - * the proper CSL Phase in the transmitted CSL Information Elements can be injected. - */ - if (period > 0) { - nrf_802154_csl_writer_anchor_time_set(nrf5_data.csl_rx_time); - } -} - -static void nrf5_schedule_rx(uint8_t channel, uint32_t start, uint32_t duration) -{ - nrf5_receive_at(start, duration, channel, DRX_SLOT_RX); - - /* Update the CSL anchor time to match the nearest requested CSL window, so that - * the proper CSL Phase in the transmitted CSL Information Elements can be injected. - * - * Note that even if the nrf5_schedule_rx function is not called in time (for example - * due to the call being blocked by higher priority threads) and the delayed reception - * window is not scheduled, the CSL phase will still be calculated as if the following - * reception windows were at times anchor_time + n * csl_period. The previously set - * anchor_time will be used for calculations. - */ - nrf_802154_csl_writer_anchor_time_set(nrf5_data.csl_rx_time); -} -#endif /* CONFIG_IEEE802154_CSL_ENDPOINT */ - static int nrf5_configure(const struct device *dev, enum ieee802154_config_type type, const struct ieee802154_config *config) @@ -988,16 +947,35 @@ static int nrf5_configure(const struct device *dev, #if defined(CONFIG_IEEE802154_CSL_ENDPOINT) case IEEE802154_CONFIG_CSL_RX_TIME: - nrf5_data.csl_rx_time = config->csl_rx_time; + /* + * `target_time_convert_to_64_bits()` is a workaround until OpenThread (the only + * CSL user in Zephyr so far) is able to schedule RX windows using 64-bit time. + */ + uint64_t csl_rx_time = target_time_convert_to_64_bits(config->csl_rx_time); + + nrf_802154_csl_writer_anchor_time_set(csl_rx_time); break; case IEEE802154_CONFIG_RX_SLOT: - nrf5_schedule_rx(config->rx_slot.channel, config->rx_slot.start, - config->rx_slot.duration); + /* Note that even if the nrf_802154_receive_at function is not called in time + * (for example due to the call being blocked by higher priority threads) and + * the delayed reception window is not scheduled, the CSL phase will still be + * calculated as if the following reception windows were at times + * anchor_time + n * csl_period. The previously set + * anchor_time will be used for calculations. + * + * `target_time_convert_to_64_bits()` is a workaround until OpenThread + * (the only CSL user in Zephyr so far) is able to schedule RX windows + * using 64-bit time. + */ + uint64_t start = target_time_convert_to_64_bits(config->rx_slot.start); + + nrf_802154_receive_at(start, config->rx_slot.duration, config->rx_slot.channel, + DRX_SLOT_RX); break; case IEEE802154_CONFIG_CSL_PERIOD: - nrf5_config_csl_period(config->csl_period); + nrf_802154_csl_writer_period_set(config->csl_period); break; #endif /* CONFIG_IEEE802154_CSL_ENDPOINT */ diff --git a/drivers/ieee802154/ieee802154_nrf5.h b/drivers/ieee802154/ieee802154_nrf5.h index e79d1204a24b..b5a39ce8dfd5 100644 --- a/drivers/ieee802154/ieee802154_nrf5.h +++ b/drivers/ieee802154/ieee802154_nrf5.h @@ -84,9 +84,6 @@ struct nrf5_802154_data { /* Capabilities of the network interface. */ enum ieee802154_hw_caps capabilities; - /* Next CSL receive time */ - uint32_t csl_rx_time; - /* Indicates if currently processed TX frame is secured. */ bool tx_frame_is_secured; From 85d1a27a3d009ef8feca85334f422e9fad7fc20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Battrel?= Date: Fri, 17 Mar 2023 14:20:38 +0100 Subject: [PATCH 0446/1906] Bluetooth: Host: Document `bt_conn_set_security` behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Document `bt_conn_set_security` behavior; `sec` has no effect on the security level selected for the pairing process. The selection is instead controlled by the values of the registered `bt_conn_auth_cb`. Signed-off-by: Théo Battrel Co-authored-by: Aleksander Wasaznik --- include/zephyr/bluetooth/conn.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/zephyr/bluetooth/conn.h b/include/zephyr/bluetooth/conn.h index 8cefb6cd797b..a3316e9803b4 100644 --- a/include/zephyr/bluetooth/conn.h +++ b/include/zephyr/bluetooth/conn.h @@ -758,9 +758,11 @@ int bt_le_set_auto_conn(const bt_addr_le_t *addr, * strong key this function does nothing. * * If the device has no bond information for the peer and is not already paired - * then the pairing procedure will be initiated. If the device has bond - * information or is already paired and the keys are too weak then the pairing - * procedure will be initiated. + * then the pairing procedure will be initiated. Note that @p sec has no effect + * on the security level selected for the pairing process. The selection is + * instead controlled by the values of the registered @ref bt_conn_auth_cb. If + * the device has bond information or is already paired and the keys are too + * weak then the pairing procedure will be initiated. * * This function may return error if required level of security is not possible * to achieve due to local or remote device limitation (e.g., input output From b308d83d458add9b1421bbd5171859ede36f36b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Fri, 17 Mar 2023 16:35:28 +0100 Subject: [PATCH 0447/1906] drivers: watchdog: add watchdog support on STM32C0-series MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for independent watchdog and window watchdog on the STM32C0-series. Signed-off-by: Benjamin Björnsson --- drivers/watchdog/wdt_iwdg_stm32.c | 2 +- drivers/watchdog/wdt_wwdg_stm32.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/watchdog/wdt_iwdg_stm32.c b/drivers/watchdog/wdt_iwdg_stm32.c index df3d42d83a7c..57f250c3dfa9 100644 --- a/drivers/watchdog/wdt_iwdg_stm32.c +++ b/drivers/watchdog/wdt_iwdg_stm32.c @@ -92,7 +92,7 @@ static int iwdg_stm32_setup(const struct device *dev, uint8_t options) if (options & WDT_OPT_PAUSE_HALTED_BY_DBG) { #if defined(CONFIG_SOC_SERIES_STM32F0X) LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_DBGMCU); -#elif defined(CONFIG_SOC_SERIES_STM32G0X) +#elif defined(CONFIG_SOC_SERIES_STM32C0X) || defined(CONFIG_SOC_SERIES_STM32G0X) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_DBGMCU); #elif defined(CONFIG_SOC_SERIES_STM32L0X) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_DBGMCU); diff --git a/drivers/watchdog/wdt_wwdg_stm32.c b/drivers/watchdog/wdt_wwdg_stm32.c index f75bade6ae45..b6e7d90a1a08 100644 --- a/drivers/watchdog/wdt_wwdg_stm32.c +++ b/drivers/watchdog/wdt_wwdg_stm32.c @@ -170,7 +170,7 @@ static int wwdg_stm32_setup(const struct device *dev, uint8_t options) LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_DBGMCU); #elif defined(CONFIG_SOC_SERIES_STM32L0X) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_DBGMCU); -#elif defined(CONFIG_SOC_SERIES_STM32G0X) +#elif defined(CONFIG_SOC_SERIES_STM32C0X) || defined(CONFIG_SOC_SERIES_STM32G0X) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_DBGMCU); #endif #if defined(CONFIG_SOC_SERIES_STM32H7X) From db78d113521c3b936872593c8c55b98b065cd100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Fri, 17 Mar 2023 16:38:51 +0100 Subject: [PATCH 0448/1906] dts: arm: stm32c0: Add watchdog nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add nodes for independent watchdog and window watchdog. Signed-off-by: Benjamin Björnsson --- dts/arm/st/c0/stm32c0.dtsi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dts/arm/st/c0/stm32c0.dtsi b/dts/arm/st/c0/stm32c0.dtsi index 7595005f38c3..d0fed77abf84 100644 --- a/dts/arm/st/c0/stm32c0.dtsi +++ b/dts/arm/st/c0/stm32c0.dtsi @@ -151,6 +151,20 @@ status = "disabled"; }; + wwdg: watchdog@40002c00 { + compatible = "st,stm32-window-watchdog"; + reg = <0x40002C00 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1 0x00000800>; + interrupts = <0 2>; + status = "disabled"; + }; + + iwdg: watchdog@40003000 { + compatible = "st,stm32-watchdog"; + reg = <0x40003000 0x400>; + status = "disabled"; + }; + usart1: serial@40013800 { compatible = "st,stm32-usart", "st,stm32-uart"; reg = <0x40013800 0x400>; From 991af08e2273bd5f803e52f3be1cdf716e33590c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Fri, 17 Mar 2023 16:39:58 +0100 Subject: [PATCH 0449/1906] boards: arm: nucleo_c031c6: Enable independent watchdog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable independent watchdog and update documentation to include support for independent watchdog and window watchdog. Signed-off-by: Benjamin Björnsson --- boards/arm/nucleo_c031c6/doc/index.rst | 4 ++++ boards/arm/nucleo_c031c6/nucleo_c031c6.dts | 5 +++++ boards/arm/nucleo_c031c6/nucleo_c031c6.yaml | 1 + 3 files changed, 10 insertions(+) diff --git a/boards/arm/nucleo_c031c6/doc/index.rst b/boards/arm/nucleo_c031c6/doc/index.rst index 448d34fd365c..c9ef5c00a59e 100644 --- a/boards/arm/nucleo_c031c6/doc/index.rst +++ b/boards/arm/nucleo_c031c6/doc/index.rst @@ -76,6 +76,10 @@ The Zephyr nucleo_c031c6 board configuration supports the following hardware fea +-----------+------------+-------------------------------------+ | RTC | on-chip | counter | +-----------+------------+-------------------------------------+ +| IWDG | on-chip | independent watchdog | ++-----------+------------+-------------------------------------+ +| WWDG | on-chip | window watchdog | ++-----------+------------+-------------------------------------+ Other hardware features are not yet supported in this Zephyr port. diff --git a/boards/arm/nucleo_c031c6/nucleo_c031c6.dts b/boards/arm/nucleo_c031c6/nucleo_c031c6.dts index cdc63c92b4a1..a53220969df1 100644 --- a/boards/arm/nucleo_c031c6/nucleo_c031c6.dts +++ b/boards/arm/nucleo_c031c6/nucleo_c031c6.dts @@ -40,6 +40,7 @@ aliases { led0 = &green_led_4; sw0 = &user_button; + watchdog0 = &iwdg; }; }; @@ -77,3 +78,7 @@ <&rcc STM32_SRC_LSE RTC_SEL(1)>; status = "okay"; }; + +&iwdg { + status = "okay"; +}; diff --git a/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml b/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml index dcde51e7f897..8646b2bf30ea 100644 --- a/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml +++ b/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml @@ -9,5 +9,6 @@ toolchain: supported: - gpio - counter + - watchdog ram: 12 flash: 32 From 5720f1eae71f607d69f1a338dc4f44f202cb34ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Fri, 17 Mar 2023 16:53:53 +0100 Subject: [PATCH 0450/1906] tests: drivers: wdt_basic_api: Add nucleo c031c6 as allowed platform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add nucleo c031c6 as allowed platform for iwdg and wwdg tests to verify functionality on the STM32C0-series. Signed-off-by: Benjamin Björnsson --- tests/drivers/watchdog/wdt_basic_api/testcase.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/drivers/watchdog/wdt_basic_api/testcase.yaml b/tests/drivers/watchdog/wdt_basic_api/testcase.yaml index d98e85359391..7501fdc5619b 100644 --- a/tests/drivers/watchdog/wdt_basic_api/testcase.yaml +++ b/tests/drivers/watchdog/wdt_basic_api/testcase.yaml @@ -15,7 +15,7 @@ tests: platform_allow: nucleo_f091rc nucleo_f103rb nucleo_f207zg stm32f3_disco nucleo_f429zi nucleo_f746zg nucleo_g071rb nucleo_g474re nucleo_l073rz nucleo_l152re nucleo_l4r5zi stm32l562e_dk nucleo_wb55rg nucleo_wl55jc - b_u585i_iot02a nucleo_u575zi_q + b_u585i_iot02a nucleo_u575zi_q nucleo_c031c6 integration_platforms: - nucleo_f091rc drivers.watchdog.stm32wwdg_h7: @@ -28,7 +28,7 @@ tests: platform_allow: nucleo_f091rc nucleo_f103rb nucleo_f207zg stm32f3_disco nucleo_f429zi nucleo_f746zg nucleo_g071rb nucleo_g474re nucleo_l073rz nucleo_l152re nucleo_l4r5zi stm32l562e_dk nucleo_wb55rg nucleo_wl55jc - b_u585i_iot02a nucleo_u575zi_q nucleo_h753zi nucleo_h743zi + b_u585i_iot02a nucleo_u575zi_q nucleo_h753zi nucleo_h743zi nucleo_c031c6 integration_platforms: - nucleo_f091rc drivers.watchdog.mec15xxevb_assy6853: From d6e54a417a06b1b8394f6a35fefbce2a375bccee Mon Sep 17 00:00:00 2001 From: Krishna T Date: Mon, 20 Mar 2023 00:56:24 +0530 Subject: [PATCH 0451/1906] net: zperf: Make Zperf worker thread priority configurable This helps us test impact of scheduling on traffic. Signed-off-by: Krishna T --- subsys/net/lib/zperf/Kconfig | 6 ++++++ subsys/net/lib/zperf/zperf_common.c | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/zperf/Kconfig b/subsys/net/lib/zperf/Kconfig index d4416fab2e89..eb20087f6097 100644 --- a/subsys/net/lib/zperf/Kconfig +++ b/subsys/net/lib/zperf/Kconfig @@ -11,6 +11,12 @@ menuconfig NET_ZPERF if NET_ZPERF +config ZPERF_WORK_Q_THREAD_PRIORITY + int "zperf work queue thread priority" + default NUM_PREEMPT_PRIORITIES + help + Priority of the thread that handles zperf work queue. + module = NET_ZPERF module-dep = NET_LOG module-str = Log level for zperf diff --git a/subsys/net/lib/zperf/zperf_common.c b/subsys/net/lib/zperf/zperf_common.c index f303fc30eccf..f3e24433564c 100644 --- a/subsys/net/lib/zperf/zperf_common.c +++ b/subsys/net/lib/zperf/zperf_common.c @@ -12,7 +12,6 @@ LOG_MODULE_REGISTER(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL); -#define ZPERF_WORK_Q_THREAD_PRIORITY K_LOWEST_APPLICATION_THREAD_PRIO #define ZPERF_WORK_Q_STACK_SIZE 2048 /* Get some useful debug routings from net_private.h, requires * that NET_LOG_ENABLED is set. @@ -219,7 +218,7 @@ static int zperf_init(const struct device *unused) k_work_queue_init(&zperf_work_q); k_work_queue_start(&zperf_work_q, zperf_work_q_stack, K_THREAD_STACK_SIZEOF(zperf_work_q_stack), - ZPERF_WORK_Q_THREAD_PRIORITY, NULL); + CONFIG_ZPERF_WORK_Q_THREAD_PRIORITY, NULL); k_thread_name_set(&zperf_work_q.thread, "zperf_work_q"); zperf_udp_uploader_init(); From 36c46afbb91bb7a6de971ae803ec350eb0a38f33 Mon Sep 17 00:00:00 2001 From: Krishna T Date: Mon, 20 Mar 2023 00:58:23 +0530 Subject: [PATCH 0452/1906] net: zperf: Make Zperf worker thread stack size configurable All stack sizes should be configurable for memory adjustements. Signed-off-by: Krishna T --- subsys/net/lib/zperf/Kconfig | 6 ++++++ subsys/net/lib/zperf/zperf_common.c | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/zperf/Kconfig b/subsys/net/lib/zperf/Kconfig index eb20087f6097..204144a805bc 100644 --- a/subsys/net/lib/zperf/Kconfig +++ b/subsys/net/lib/zperf/Kconfig @@ -17,6 +17,12 @@ config ZPERF_WORK_Q_THREAD_PRIORITY help Priority of the thread that handles zperf work queue. +config ZPERF_WORK_Q_STACK_SIZE + int "zperf work queue thread stack size" + default 2048 + help + Stack size of the thread that handles zperf work queue. + module = NET_ZPERF module-dep = NET_LOG module-str = Log level for zperf diff --git a/subsys/net/lib/zperf/zperf_common.c b/subsys/net/lib/zperf/zperf_common.c index f3e24433564c..1c82c09ec70d 100644 --- a/subsys/net/lib/zperf/zperf_common.c +++ b/subsys/net/lib/zperf/zperf_common.c @@ -12,7 +12,6 @@ LOG_MODULE_REGISTER(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL); -#define ZPERF_WORK_Q_STACK_SIZE 2048 /* Get some useful debug routings from net_private.h, requires * that NET_LOG_ENABLED is set. */ @@ -41,7 +40,7 @@ struct sockaddr_in *zperf_get_sin(void) return &in4_addr_my; } -K_THREAD_STACK_DEFINE(zperf_work_q_stack, ZPERF_WORK_Q_STACK_SIZE); +K_THREAD_STACK_DEFINE(zperf_work_q_stack, CONFIG_ZPERF_WORK_Q_STACK_SIZE); static struct k_work_q zperf_work_q; From 14ec9e9dcb875505d9142e3b6ffb77146516dbfb Mon Sep 17 00:00:00 2001 From: Nikolay Agishev Date: Thu, 16 Mar 2023 11:22:21 +0400 Subject: [PATCH 0453/1906] ARC: Add MWDT support into qemu_arc_hs platform Add Metaware toolchain into qemu_arc_hs* platforms Signed-off-by: Nikolay Agishev --- boards/arc/qemu_arc/qemu_arc_hs.yaml | 1 + soc/arc/snps_qemu/CMakeLists.txt | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/boards/arc/qemu_arc/qemu_arc_hs.yaml b/boards/arc/qemu_arc/qemu_arc_hs.yaml index 2ead7ebff938..05b4428710f1 100644 --- a/boards/arc/qemu_arc/qemu_arc_hs.yaml +++ b/boards/arc/qemu_arc/qemu_arc_hs.yaml @@ -6,6 +6,7 @@ arch: arc toolchain: - zephyr - cross-compile + - arcmwdt testing: default: true ignore_tags: diff --git a/soc/arc/snps_qemu/CMakeLists.txt b/soc/arc/snps_qemu/CMakeLists.txt index cf3a34062ec1..c77f0003c4ce 100644 --- a/soc/arc/snps_qemu/CMakeLists.txt +++ b/soc/arc/snps_qemu/CMakeLists.txt @@ -1,5 +1,21 @@ # SPDX-License-Identifier: Apache-2.0 -if(CONFIG_ISA_ARCV2) - zephyr_compile_options(-mno-sdata) +if(COMPILER STREQUAL gcc) + zephyr_compile_options(-mcpu=${GCC_M_CPU}) + + zephyr_compile_options_ifdef(CONFIG_ISA_ARCV2 -mno-sdata) + +else() + + zephyr_compile_options_ifdef(CONFIG_SOC_QEMU_ARC_HS -arcv2hs -core2 -Xatomic + -Xunaligned -Xcode_density -Xswap -Xbitscan + -Xmpy_option=qmpyh -Xshift_assist -Xbarrel_shifter + -Xtimer0 -Xtimer1) + + zephyr_ld_option_ifdef(CONFIG_SOC_QEMU_ARC_HS -Hlib=hs38_full) + + if(NOT CONFIG_SOC_QEMU_ARC_HS) + message(WARNING "QEMU ARC platforms other than HS are not supported yet with MW toolchain") + endif() + endif() From a2e5d1dcd2287115dbef78a368f411935129816b Mon Sep 17 00:00:00 2001 From: Marcin Niestroj Date: Thu, 16 Mar 2023 12:23:32 +0100 Subject: [PATCH 0454/1906] drivers: wifi: esp32: register rxcb after wifi init Move esp_wifi_internal_reg_rxcb() after esp_wifi_init(), so that wifi_connect() is successful. Fixes: 690f65dbd9a0 ("drivers: wifi: esp32: fix possible interface null pointer") Signed-off-by: Marcin Niestroj --- drivers/wifi/esp32/src/esp_wifi_drv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/wifi/esp32/src/esp_wifi_drv.c b/drivers/wifi/esp32/src/esp_wifi_drv.c index 54f07dd8b897..483e75eb50d7 100644 --- a/drivers/wifi/esp32/src/esp_wifi_drv.c +++ b/drivers/wifi/esp32/src/esp_wifi_drv.c @@ -433,11 +433,11 @@ static void esp32_wifi_init(struct net_if *iface) ethernet_init(iface); net_if_carrier_off(iface); - esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_STA, eth_esp32_rx); - wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT(); esp_err_t ret = esp_wifi_init(&config); + esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_STA, eth_esp32_rx); + ret |= esp_wifi_set_mode(ESP32_WIFI_MODE_STA); ret |= esp_wifi_start(); From 4939463dc2a8ce3e3503ec8fd7c5cd019079c080 Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Mon, 20 Mar 2023 09:15:12 +0100 Subject: [PATCH 0455/1906] samples: shields: x_nucleo_53l0a1: Add missing prj.conf This sample was missing a proj.conf which is required for any zephyr application. Signed-off-by: Erwan Gouriou --- samples/shields/x_nucleo_53l0a1/prj.conf | 1 + 1 file changed, 1 insertion(+) create mode 100644 samples/shields/x_nucleo_53l0a1/prj.conf diff --git a/samples/shields/x_nucleo_53l0a1/prj.conf b/samples/shields/x_nucleo_53l0a1/prj.conf new file mode 100644 index 000000000000..b2a4ba591044 --- /dev/null +++ b/samples/shields/x_nucleo_53l0a1/prj.conf @@ -0,0 +1 @@ +# nothing here From 758e58a1b68f7307978941323e377990f21d388e Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 17 Mar 2023 16:33:05 +0100 Subject: [PATCH 0456/1906] ci: Switch to CI image v0.25.1 Which includes the latest babblesim (v2.0.1) which is required to enable 802.15.4 Signed-off-by: Alberto Escolar Piedras --- .github/workflows/bluetooth-tests.yaml | 2 +- .github/workflows/clang.yaml | 2 +- .github/workflows/codecov.yaml | 2 +- .github/workflows/twister.yaml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/bluetooth-tests.yaml b/.github/workflows/bluetooth-tests.yaml index 36553b38a01e..23f7f0e1610a 100644 --- a/.github/workflows/bluetooth-tests.yaml +++ b/.github/workflows/bluetooth-tests.yaml @@ -21,7 +21,7 @@ jobs: if: github.repository_owner == 'zephyrproject-rtos' runs-on: zephyr-runner-linux-x64-4xlarge container: - image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 + image: ghcr.io/zephyrproject-rtos/ci:v0.25.1 options: '--entrypoint /bin/bash' volumes: - /repo-cache/zephyrproject:/github/cache/zephyrproject diff --git a/.github/workflows/clang.yaml b/.github/workflows/clang.yaml index 214bf6fe2178..9c2a32c9701d 100644 --- a/.github/workflows/clang.yaml +++ b/.github/workflows/clang.yaml @@ -11,7 +11,7 @@ jobs: if: github.repository_owner == 'zephyrproject-rtos' runs-on: zephyr-runner-linux-x64-4xlarge container: - image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 + image: ghcr.io/zephyrproject-rtos/ci:v0.25.1 options: '--entrypoint /bin/bash' volumes: - /repo-cache/zephyrproject:/github/cache/zephyrproject diff --git a/.github/workflows/codecov.yaml b/.github/workflows/codecov.yaml index 7a1ceb30a56b..972931407710 100644 --- a/.github/workflows/codecov.yaml +++ b/.github/workflows/codecov.yaml @@ -13,7 +13,7 @@ jobs: if: github.repository == 'zephyrproject-rtos/zephyr' runs-on: zephyr-runner-linux-x64-4xlarge container: - image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 + image: ghcr.io/zephyrproject-rtos/ci:v0.25.1 options: '--entrypoint /bin/bash' volumes: - /repo-cache/zephyrproject:/github/cache/zephyrproject diff --git a/.github/workflows/twister.yaml b/.github/workflows/twister.yaml index eb0a620b2eec..e54836ef3aae 100644 --- a/.github/workflows/twister.yaml +++ b/.github/workflows/twister.yaml @@ -22,7 +22,7 @@ jobs: if: github.repository_owner == 'zephyrproject-rtos' runs-on: zephyr-runner-linux-x64-4xlarge container: - image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 + image: ghcr.io/zephyrproject-rtos/ci:v0.25.1 options: '--entrypoint /bin/bash' volumes: - /repo-cache/zephyrproject:/github/cache/zephyrproject @@ -120,7 +120,7 @@ jobs: needs: twister-build-prep if: needs.twister-build-prep.outputs.size != 0 container: - image: ghcr.io/zephyrproject-rtos/ci:v0.25.0 + image: ghcr.io/zephyrproject-rtos/ci:v0.25.1 options: '--entrypoint /bin/bash' volumes: - /repo-cache/zephyrproject:/github/cache/zephyrproject From 61f9d4ba40bdcde8c0fe17e8eeea34e7e551df8d Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Fri, 17 Mar 2023 15:27:31 +0000 Subject: [PATCH 0457/1906] linker: Fix handling of _static_thread_data section _static_thread_data should be in ROM as its static data. So move it from common-ram.cmake to common-rom.cmake and fix it the params we call zephyr_iterable_section with. Signed-off-by: Kumar Gala --- cmake/linker_script/common/common-ram.cmake | 2 -- cmake/linker_script/common/common-rom.cmake | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/linker_script/common/common-ram.cmake b/cmake/linker_script/common/common-ram.cmake index 03c7960105ef..68f33361f851 100644 --- a/cmake/linker_script/common/common-ram.cmake +++ b/cmake/linker_script/common/common-ram.cmake @@ -35,8 +35,6 @@ zephyr_linker_section_configure(SECTION initshell zephyr_linker_section(NAME log_dynamic GROUP DATA_REGION NOINPUT) zephyr_linker_section_configure(SECTION log_dynamic KEEP INPUT ".log_dynamic_*") -zephyr_iterable_section(NAME _static_thread_data GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) - if(CONFIG_USERSPACE) # All kernel objects within are assumed to be either completely # initialized at build time, or initialized automatically at runtime diff --git a/cmake/linker_script/common/common-rom.cmake b/cmake/linker_script/common/common-rom.cmake index fc882b7824d4..ca6a396ecc46 100644 --- a/cmake/linker_script/common/common-rom.cmake +++ b/cmake/linker_script/common/common-rom.cmake @@ -191,3 +191,5 @@ zephyr_linker_section_configure(SECTION zephyr_dbg_info INPUT ".zephyr_dbg_info" zephyr_linker_section(NAME device_handles KVMA RAM_REGION GROUP RODATA_REGION NOINPUT ${XIP_ALIGN_WITH_INPUT} ENDALIGN 16) zephyr_linker_section_configure(SECTION device_handles INPUT .__device_handles_pass1* KEEP SORT NAME PASS LINKER_DEVICE_HANDLES_PASS1) zephyr_linker_section_configure(SECTION device_handles INPUT .__device_handles_pass2* KEEP SORT NAME PASS NOT LINKER_DEVICE_HANDLES_PASS1) + +zephyr_iterable_section(NAME _static_thread_data KVMA RAM_REGION GROUP RODATA_REGION SUBALIGN 4) From b011c1e36c4cd3ecf262bd20193de0898cb5b6fb Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Fri, 17 Mar 2023 16:02:47 +0100 Subject: [PATCH 0458/1906] Bluetooth: BAP: Add missing Unicast client CB NULL check Add missing check before calling unicast_client_cbs->release. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/bap_unicast_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index fcec2eb4bf9c..ec8e7a6b935d 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -567,7 +567,7 @@ static int unicast_client_ep_idle_state(struct bt_bap_ep *ep) */ client_ep->release_requested = false; - if (unicast_client_cbs->release != NULL) { + if (unicast_client_cbs != NULL && unicast_client_cbs->release != NULL) { unicast_client_cbs->release(stream, BT_BAP_ASCS_RSP_CODE_SUCCESS, BT_BAP_ASCS_REASON_NONE); } From 51ff3e630b868c80c030904d5a56e47c5402023e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Thu, 9 Mar 2023 08:34:10 +0100 Subject: [PATCH 0459/1906] Bluetooth: Mesh: Do not transfer FW to targets in Verify Phase in DFU MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These targets already received FW so there is no point to transfering it again. What's more, these targets will not accept transfer and will be dropped by DFU Client. If FW is already received DFU Client should skip transfer and proceed to refresh procedure. Signed-off-by: Krzysztof Kopyściński --- subsys/bluetooth/mesh/dfu_cli.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/subsys/bluetooth/mesh/dfu_cli.c b/subsys/bluetooth/mesh/dfu_cli.c index fcf9b71a3773..165a3b0da106 100644 --- a/subsys/bluetooth/mesh/dfu_cli.c +++ b/subsys/bluetooth/mesh/dfu_cli.c @@ -427,24 +427,29 @@ static void initiate(struct bt_mesh_dfu_cli *cli) blob_cli_broadcast(&cli->blob, &tx); } -static void skip_cli_from_broadcast(struct bt_mesh_dfu_cli *cli, bool skip) +static void skip_targets_from_broadcast(struct bt_mesh_dfu_cli *cli, bool skip) { struct bt_mesh_dfu_target *target; TARGETS_FOR_EACH(cli, target) { - if (bt_mesh_has_addr(target->blob.addr)) { + /* If distributor is in the targets list, or target is in Verify phase, + * disable it until Retrieve Capabilities and BLOB Transfer procedures + * are completed. + */ + if (bt_mesh_has_addr(target->blob.addr) || + target->phase == BT_MESH_DFU_PHASE_VERIFY) { target->blob.skip = skip; break; } } } -static bool is_self_update(struct bt_mesh_dfu_cli *cli) +static bool transfer_skip(struct bt_mesh_dfu_cli *cli) { struct bt_mesh_dfu_target *target; TARGETS_FOR_EACH(cli, target) { - if (!bt_mesh_has_addr(target->blob.addr)) { + if (!bt_mesh_has_addr(target->blob.addr) || !target->blob.skip) { return false; } } @@ -464,17 +469,16 @@ static void transfer(struct bt_mesh_blob_cli *b) return; } - if (is_self_update(cli)) { - /* If distributor only updates itself, proceed to the refresh step immediately. */ + skip_targets_from_broadcast(cli, true); + + if (transfer_skip(cli)) { + /* If distributor only updates itself, or all targets are in Verify phase, + * proceed to the refresh step immediately. + */ refresh(cli); return; } - /* If distributor is in the targets list, disable it until Retrieve Capabilities and BLOB - * Transfer procedures are completed. - */ - skip_cli_from_broadcast(cli, true); - if (cli->xfer.flags & FLAG_RESUME) { cli->xfer.flags ^= FLAG_RESUME; err = bt_mesh_blob_cli_resume(b); @@ -527,7 +531,7 @@ static void refresh(struct bt_mesh_dfu_cli *cli) /* If distributor is in the targets list, enable it again so it participates in Distribute * Firmware procedure. */ - skip_cli_from_broadcast(cli, false); + skip_targets_from_broadcast(cli, false); blob_cli_broadcast(&cli->blob, &tx); } From b0e91368a2574af4ee2faea3e1dd8dc38582dea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Thu, 9 Mar 2023 09:13:42 +0100 Subject: [PATCH 0460/1906] Bluetooth: Mesh: fix FW Update procedure recovery on on DFU Server side MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If device rebooted while in `BT_MESH_DFU_PHASE_TRANSFER_ACTIVE` phase we should not recover into it, but set `BT_MESH_DFU_PHASE_TRANSFER_ERR` instead. It's because we no longer remember which block is currently transfered so new FW Update Start must be received and transfer restarted. If device rebooted while in `BT_MESH_DFU_PHASE_VERIFY_OK` it means we didn't manage to apply image before reboot. We should enter `BT_MESH_DFU_PHASE_VERIFY_FAIL` phase, which will allow to verify it again and possibly apply. This is with agreement to specification regarding receiving FW Update Start when FW is already received. This commit also alligns handle_start with specification: when FW is already received, we should set phase to `BT_MESH_DFU_PHASE_VERIFY`, send Status message, then proceed to Verify. Previously, `verify` was called before sending status, so status contained phase set to `BT_MESH_DFU_PHASE_VERIFY_OK` or `BT_MESH_DFU_PHASE_VERIFY_FAIL`. This would prevent DFU Client enter refresh procedure. `blob_recover` also expects BT_MESH_DFU_PHASE_TRANSFER_ERR now. Signed-off-by: Krzysztof Kopyściński --- subsys/bluetooth/mesh/dfu_srv.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/mesh/dfu_srv.c b/subsys/bluetooth/mesh/dfu_srv.c index 879781ee9d56..282a40074c9d 100644 --- a/subsys/bluetooth/mesh/dfu_srv.c +++ b/subsys/bluetooth/mesh/dfu_srv.c @@ -332,8 +332,10 @@ static int handle_start(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, status = BT_MESH_DFU_SUCCESS; srv->update.idx = idx; srv->blob.state.xfer.id = blob_id; + srv->update.phase = BT_MESH_DFU_PHASE_VERIFY; + update_status_rsp(srv, ctx, status, NULL); verify(srv); - goto rsp; + return 0; } if (err == -ENOMEM) { @@ -471,6 +473,13 @@ static int dfu_srv_settings_set(struct bt_mesh_model *mod, const char *name, LOG_DBG("Recovered transfer (phase: %u, idx: %u)", srv->update.phase, srv->update.idx); + if (srv->update.phase == BT_MESH_DFU_PHASE_TRANSFER_ACTIVE) { + LOG_DBG("Settings recovered mid-transfer, setting transfer error"); + srv->update.phase = BT_MESH_DFU_PHASE_TRANSFER_ERR; + } else if (srv->update.phase == BT_MESH_DFU_PHASE_VERIFY_OK) { + LOG_DBG("Settings recovered before application, setting verification fail"); + srv->update.phase = BT_MESH_DFU_PHASE_VERIFY_FAIL; + } return 0; } @@ -521,7 +530,7 @@ static int blob_recover(struct bt_mesh_blob_srv *b, CONTAINER_OF(b, struct bt_mesh_dfu_srv, blob); if (!srv->cb->recover || - srv->update.phase != BT_MESH_DFU_PHASE_TRANSFER_ACTIVE || + srv->update.phase != BT_MESH_DFU_PHASE_TRANSFER_ERR || srv->update.idx >= srv->img_count) { return -ENOTSUP; } From 8194c3466976e9d68031bfb97ccc7972d05196a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Thu, 16 Mar 2023 13:16:27 +0100 Subject: [PATCH 0461/1906] Bluetooth: Mesh: allow user to define BLOB ID for bt_mesh_dfu_cli_send MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User can now use self-defined BLOB ID for transfer instead of using random one each time. This allows to send multiple FW Update Start messages with same BLOB ID, for example to resume previous one. Signed-off-by: Krzysztof Kopyściński --- include/zephyr/bluetooth/mesh/dfu_cli.h | 2 ++ subsys/bluetooth/mesh/dfd_srv.c | 2 +- subsys/bluetooth/mesh/dfu_cli.c | 7 ++++++- subsys/bluetooth/mesh/shell/dfu.c | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/zephyr/bluetooth/mesh/dfu_cli.h b/include/zephyr/bluetooth/mesh/dfu_cli.h index ce8ec341e14d..51f534f2828c 100644 --- a/include/zephyr/bluetooth/mesh/dfu_cli.h +++ b/include/zephyr/bluetooth/mesh/dfu_cli.h @@ -221,6 +221,8 @@ struct bt_mesh_dfu_cli_xfer_blob_params { /** Firmware Update Client transfer parameters: */ struct bt_mesh_dfu_cli_xfer { + /** BLOB ID to use for this transfer, or 0 to set it randomly. */ + uint64_t blob_id; /** DFU image slot to transfer. */ const struct bt_mesh_dfu_slot *slot; /** Transfer mode (Push (Push BLOB Transfer Mode) or Pull (Pull BLOB Transfer Mode)) */ diff --git a/subsys/bluetooth/mesh/dfd_srv.c b/subsys/bluetooth/mesh/dfd_srv.c index 0efdab7fccbe..2898ca39a39f 100644 --- a/subsys/bluetooth/mesh/dfd_srv.c +++ b/subsys/bluetooth/mesh/dfd_srv.c @@ -838,7 +838,7 @@ enum bt_mesh_dfd_status bt_mesh_dfd_srv_start(struct bt_mesh_dfd_srv *srv, struct bt_mesh_dfd_start_params *params) { int err, i; - struct bt_mesh_dfu_cli_xfer xfer; + struct bt_mesh_dfu_cli_xfer xfer = { 0 }; if (!srv->target_cnt) { return BT_MESH_DFD_ERR_RECEIVERS_LIST_EMPTY; diff --git a/subsys/bluetooth/mesh/dfu_cli.c b/subsys/bluetooth/mesh/dfu_cli.c index 165a3b0da106..63c6f1538326 100644 --- a/subsys/bluetooth/mesh/dfu_cli.c +++ b/subsys/bluetooth/mesh/dfu_cli.c @@ -997,7 +997,12 @@ int bt_mesh_dfu_cli_send(struct bt_mesh_dfu_cli *cli, cli->xfer.blob.mode = xfer->mode; cli->xfer.blob.size = xfer->slot->size; - sys_rand_get(&cli->xfer.blob.id, sizeof(cli->xfer.blob.id)); + + if (xfer->blob_id == 0) { + sys_rand_get(&cli->xfer.blob.id, sizeof(cli->xfer.blob.id)); + } else { + cli->xfer.blob.id = xfer->blob_id; + } cli->xfer.io = io; cli->blob.inputs = inputs; diff --git a/subsys/bluetooth/mesh/shell/dfu.c b/subsys/bluetooth/mesh/shell/dfu.c index b4268e89c522..8b49ee01674e 100644 --- a/subsys/bluetooth/mesh/shell/dfu.c +++ b/subsys/bluetooth/mesh/shell/dfu.c @@ -723,7 +723,7 @@ static int cmd_dfu_target_check(const struct shell *sh, size_t argc, char *argv[ static int cmd_dfu_send(const struct shell *sh, size_t argc, char *argv[]) { struct bt_mesh_dfu_cli_xfer_blob_params blob_params; - struct bt_mesh_dfu_cli_xfer xfer; + struct bt_mesh_dfu_cli_xfer xfer = { 0 }; uint8_t slot_idx; uint16_t group; int err = 0; From 018bdf50227fee26ad3adc2251e53e0600889af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Thu, 23 Feb 2023 09:01:41 +0100 Subject: [PATCH 0462/1906] tests: Bluetooth: Mesh: Test DFU Server update phase and img recovery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds BSim tests for DFU Server, where Firmware Distribution procedure is stopped at given point. DFU Server is expected to save phase and image index in persistent storage. Then new test is executed that simulates reboot of device. Settings file is not cleared and after setup device is expected to restore its DFU Server with correct phase and idx. Signed-off-by: Krzysztof Kopyściński --- tests/bsim/bluetooth/mesh/src/test_dfu.c | 305 +++++++++++++++++- .../tests_scripts/dfu/dfu_srv_persistence.sh | 52 +++ 2 files changed, 355 insertions(+), 2 deletions(-) create mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_srv_persistence.sh diff --git a/tests/bsim/bluetooth/mesh/src/test_dfu.c b/tests/bsim/bluetooth/mesh/src/test_dfu.c index 46283496f115..8e0156f3e121 100644 --- a/tests/bsim/bluetooth/mesh/src/test_dfu.c +++ b/tests/bsim/bluetooth/mesh/src/test_dfu.c @@ -23,6 +23,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF); #define DIST_ADDR 0x0001 #define TARGET_ADDR 0x0100 #define IMPOSTER_MODEL_ID 0xe000 +#define TEST_BLOB_ID 0xaabbccdd struct bind_params { uint16_t model_id; @@ -32,6 +33,10 @@ struct bind_params { static uint8_t dev_key[16] = { 0xdd }; static struct k_sem dfu_dist_ended; +static struct k_sem dfu_started; +static struct k_sem dfu_verifying; +static struct k_sem dfu_verify_failed; +static struct k_sem dfu_applying; static struct k_sem dfu_ended; static struct bt_mesh_prov prov; @@ -49,6 +54,9 @@ static struct bt_mesh_sar_cfg_cli sar_cfg_cli; static int dfu_targets_cnt; static bool dfu_fail_confirm; +static bool recover; + +static enum bt_mesh_dfu_phase expected_stop_phase; static void test_args_parse(int argc, char *argv[]) { @@ -67,6 +75,20 @@ static void test_args_parse(int argc, char *argv[]) .option = "fail-confirm", .descript = "Request target to fail confirm step" }, + { + .dest = &expected_stop_phase, + .type = 'i', + .name = "{none, start, verify, verify-ok, verify-fail, apply}", + .option = "expected-phase", + .descript = "Expected DFU Server phase value restored from flash" + }, + { + .dest = &recover, + .type = 'b', + .name = "{0, 1}", + .option = "recover", + .descript = "Recover DFU server phase" + }, }; bs_args_parse_all_cmd_line(argc, argv, args_struct); @@ -172,6 +194,10 @@ static int target_dfu_start(struct bt_mesh_dfu_srv *srv, *io = &dummy_blob_io; + if (expected_stop_phase == BT_MESH_DFU_PHASE_APPLYING) { + return -EALREADY; + } + return 0; } @@ -185,8 +211,17 @@ static void target_dfu_transfer_end(struct bt_mesh_dfu_srv *srv, const struct bt ASSERT_TRUE(expect_dfu_xfer_end); ASSERT_TRUE(success); + if (expected_stop_phase == BT_MESH_DFU_PHASE_VERIFY) { + k_sem_give(&dfu_verifying); + return; + } + if (dfu_verify_fail) { bt_mesh_dfu_srv_rejected(srv); + if (expected_stop_phase == BT_MESH_DFU_PHASE_VERIFY_FAIL) { + k_sem_give(&dfu_verify_failed); + return; + } } else { bt_mesh_dfu_srv_verified(srv); } @@ -198,7 +233,11 @@ static int target_dfu_recover(struct bt_mesh_dfu_srv *srv, const struct bt_mesh_dfu_img *img, const struct bt_mesh_blob_io **io) { - FAIL("Not supported"); + if (!recover) { + FAIL("Not supported"); + } + + *io = &dummy_blob_io; return 0; } @@ -207,6 +246,13 @@ static bool expect_dfu_apply = true; static int target_dfu_apply(struct bt_mesh_dfu_srv *srv, const struct bt_mesh_dfu_img *img) { + if (expected_stop_phase == BT_MESH_DFU_PHASE_VERIFY_OK) { + k_sem_give(&dfu_verifying); + } else if (expected_stop_phase == BT_MESH_DFU_PHASE_APPLYING) { + k_sem_give(&dfu_applying); + return 0; + } + ASSERT_TRUE(expect_dfu_apply); bt_mesh_dfu_srv_applied(srv); @@ -273,6 +319,10 @@ static const struct bt_mesh_comp dist_comp_self_update = { .elem_count = 2, }; +static const struct bt_mesh_model_op model_dummy_op[] = { + BT_MESH_MODEL_OP_END +}; + static const struct bt_mesh_comp target_comp = { .elem = (struct bt_mesh_elem[]){ @@ -281,6 +331,15 @@ static const struct bt_mesh_comp target_comp = { BT_MESH_MODEL_CFG_CLI(&cfg_cli), BT_MESH_MODEL_SAR_CFG_SRV, BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), + /* Imposter model without custom handlers is used + * so device testing persistent storage can be + * configured using both `target_comp` and + * `srv_caps_broken_comp`. If these compositions + * have different model count and order + * loading settings will fail. + */ + BT_MESH_MODEL_CB(IMPOSTER_MODEL_ID, + model_dummy_op, NULL, NULL, NULL), BT_MESH_MODEL_DFU_SRV(&dfu_srv)), BT_MESH_MODEL_NONE), }, @@ -733,6 +792,7 @@ static void test_target_dfu_unprov(void) static struct { struct bt_mesh_blob_cli_inputs inputs; + struct bt_mesh_blob_target_pull pull[7]; struct bt_mesh_dfu_target targets[7]; uint8_t target_count; struct bt_mesh_dfu_cli_xfer xfer; @@ -752,6 +812,11 @@ static void dfu_cli_inputs_prepare(uint16_t group) memset(&dfu_cli_xfer.targets[i], 0, sizeof(struct bt_mesh_dfu_target)); dfu_cli_xfer.targets[i].blob.addr = addr; + if (recover) { + memset(&dfu_cli_xfer.pull[i].missing, 1, + ceiling_fraction(CONFIG_BT_MESH_BLOB_CHUNK_COUNT_MAX, 8)); + dfu_cli_xfer.targets[i].blob.pull = &dfu_cli_xfer.pull[i]; + } sys_slist_append(&dfu_cli_xfer.inputs.targets, &dfu_cli_xfer.targets[i].blob.n); } @@ -778,7 +843,19 @@ static void dfu_cli_suspended(struct bt_mesh_dfu_cli *cli) static void dfu_cli_ended(struct bt_mesh_dfu_cli *cli, enum bt_mesh_dfu_status reason) { - ASSERT_EQUAL(BT_MESH_DFU_SUCCESS, reason); + if (expected_stop_phase == BT_MESH_DFU_PHASE_IDLE || + expected_stop_phase == BT_MESH_DFU_PHASE_VERIFY_OK) { + ASSERT_EQUAL(BT_MESH_DFU_SUCCESS, reason); + } + + if (expected_stop_phase == BT_MESH_DFU_PHASE_TRANSFER_ACTIVE) { + k_sem_give(&dfu_started); + } else if (expected_stop_phase == BT_MESH_DFU_PHASE_VERIFY) { + k_sem_give(&dfu_verifying); + } else if (expected_stop_phase == BT_MESH_DFU_PHASE_VERIFY_FAIL) { + k_sem_give(&dfu_verify_failed); + } + k_sem_give(&dfu_ended); } @@ -846,6 +923,22 @@ static void cli_common_fail_on_init(void) dfu_cli_inputs_prepare(0); dfu_cli_xfer.xfer.mode = BT_MESH_BLOB_XFER_MODE_PUSH; dfu_cli_xfer.xfer.slot = slot; + dfu_cli_xfer.xfer.blob_id = TEST_BLOB_ID; +} + +static void cli_common_init_recover(void) +{ + const struct bt_mesh_dfu_slot *slot; + + bt_mesh_test_cfg_set(NULL, 300); + bt_mesh_device_setup(&prov, &cli_comp); + + ASSERT_TRUE(slot_add(&slot)); + + dfu_cli_inputs_prepare(0); + dfu_cli_xfer.xfer.mode = BT_MESH_BLOB_XFER_MODE_PUSH; + dfu_cli_xfer.xfer.slot = slot; + dfu_cli_xfer.xfer.blob_id = TEST_BLOB_ID; } static void test_cli_fail_on_persistency(void) @@ -941,12 +1034,117 @@ static void test_cli_fail_on_persistency(void) PASS(); } +static void test_cli_stop(void) +{ + int err; + + (void)target_srv_add(TARGET_ADDR + 1, true); + + switch (expected_stop_phase) { + case BT_MESH_DFU_PHASE_TRANSFER_ACTIVE: + cli_common_fail_on_init(); + + err = bt_mesh_dfu_cli_send(&dfu_cli, &dfu_cli_xfer.inputs, &dummy_blob_io, + &dfu_cli_xfer.xfer); + if (err) { + FAIL("DFU Client send failed (err: %d)", err); + } + + if (k_sem_take(&dfu_started, K_SECONDS(200))) { + FAIL("Firmware transfer failed"); + } + + ASSERT_EQUAL(BT_MESH_DFU_ERR_INTERNAL, dfu_cli_xfer.targets[0].status); + ASSERT_EQUAL(BT_MESH_DFU_PHASE_TRANSFER_ACTIVE, dfu_cli_xfer.targets[0].phase); + break; + case BT_MESH_DFU_PHASE_VERIFY: + cli_common_init_recover(); + + err = bt_mesh_dfu_cli_send(&dfu_cli, &dfu_cli_xfer.inputs, &dummy_blob_io, + &dfu_cli_xfer.xfer); + if (err) { + FAIL("DFU Client resume failed (err: %d)", err); + } + + if (k_sem_take(&dfu_verifying, K_SECONDS(200))) { + FAIL("Firmware transfer failed"); + } + ASSERT_EQUAL(BT_MESH_DFU_ERR_INTERNAL, dfu_cli_xfer.targets[0].status); + ASSERT_EQUAL(BT_MESH_DFU_PHASE_VERIFY, dfu_cli_xfer.targets[0].phase); + + break; + case BT_MESH_DFU_PHASE_VERIFY_OK: + /* Nothing to do here on distributor side, target must verify image */ + break; + case BT_MESH_DFU_PHASE_VERIFY_FAIL: + cli_common_fail_on_init(); + + err = bt_mesh_dfu_cli_send(&dfu_cli, &dfu_cli_xfer.inputs, &dummy_blob_io, + &dfu_cli_xfer.xfer); + if (err) { + FAIL("DFU Client send failed (err: %d)", err); + } + + if (k_sem_take(&dfu_verify_failed, K_SECONDS(200))) { + FAIL("Firmware transfer failed"); + } + + ASSERT_EQUAL(BT_MESH_DFU_ERR_WRONG_PHASE, dfu_cli_xfer.targets[0].status); + ASSERT_EQUAL(BT_MESH_DFU_PHASE_VERIFY_FAIL, dfu_cli_xfer.targets[0].phase); + break; + case BT_MESH_DFU_PHASE_APPLYING: + cli_common_init_recover(); + + err = bt_mesh_dfu_cli_send(&dfu_cli, &dfu_cli_xfer.inputs, &dummy_blob_io, + &dfu_cli_xfer.xfer); + + if (err) { + FAIL("DFU Client send failed (err: %d)", err); + } + if (k_sem_take(&dfu_ended, K_SECONDS(200))) { + FAIL("Firmware transfer failed"); + } + + bt_mesh_dfu_cli_apply(&dfu_cli); + if (k_sem_take(&dfu_cli_applied_sem, K_SECONDS(200))) { + /* This will time out as target will reboot before applying */ + } + ASSERT_EQUAL(BT_MESH_DFU_ERR_INTERNAL, dfu_cli_xfer.targets[0].status); + ASSERT_EQUAL(BT_MESH_DFU_PHASE_APPLYING, dfu_cli_xfer.targets[0].phase); + break; + case BT_MESH_DFU_PHASE_APPLY_SUCCESS: + cli_common_init_recover(); + + dfu_cli.xfer.state = 5; + dfu_cli.xfer.slot = dfu_cli_xfer.xfer.slot; + dfu_cli.xfer.blob.id = TEST_BLOB_ID; + dfu_cli_xfer.xfer.mode = BT_MESH_BLOB_XFER_MODE_PUSH; + + dfu_cli.blob.inputs = &dfu_cli_xfer.inputs; + + err = bt_mesh_dfu_cli_confirm(&dfu_cli); + if (err) { + FAIL("DFU Client confirm failed (err: %d)", err); + } + + ASSERT_EQUAL(BT_MESH_DFU_SUCCESS, dfu_cli_xfer.targets[0].status); + ASSERT_EQUAL(BT_MESH_DFU_PHASE_IDLE, dfu_cli_xfer.targets[0].phase); + + PASS(); + break; + default: + break; + } + PASS(); +} + static struct k_sem caps_get_sem; static int mock_handle_caps_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { LOG_WRN("Rejecting BLOB Information Get message"); + k_sem_give(&caps_get_sem); return 0; @@ -973,6 +1171,37 @@ static const struct bt_mesh_comp srv_caps_broken_comp = { .elem_count = 1, }; +static int mock_handle_chunks(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) +{ + LOG_WRN("Skipping receiving block"); + + k_sem_give(&dfu_started); + + return 0; +} + +static const struct bt_mesh_model_op model_caps_op2[] = { + { BT_MESH_BLOB_OP_CHUNK, 0, mock_handle_chunks }, + BT_MESH_MODEL_OP_END +}; + +static const struct bt_mesh_comp broken_target_comp = { + .elem = + (struct bt_mesh_elem[]){ + BT_MESH_ELEM(1, + MODEL_LIST(BT_MESH_MODEL_CFG_SRV, + BT_MESH_MODEL_CFG_CLI(&cfg_cli), + BT_MESH_MODEL_SAR_CFG_SRV, + BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), + BT_MESH_MODEL_CB(IMPOSTER_MODEL_ID, + model_caps_op2, NULL, NULL, NULL), + BT_MESH_MODEL_DFU_SRV(&dfu_srv)), + BT_MESH_MODEL_NONE), + }, + .elem_count = 1, +}; + static struct k_sem update_get_sem; static int mock_handle_update_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, @@ -1148,6 +1377,72 @@ static void test_target_fail_on_nothing(void) PASS(); } +static void test_target_dfu_stop(void) +{ + dfu_target_effect = BT_MESH_DFU_EFFECT_NONE; + + if (!recover) { + settings_test_backend_clear(); + bt_mesh_test_cfg_set(NULL, WAIT_TIME); + + common_fail_on_target_init(expected_stop_phase == BT_MESH_DFU_PHASE_VERIFY_FAIL ? + &target_comp : &broken_target_comp); + target_prov_and_conf_with_imposer(); + + if (expected_stop_phase == BT_MESH_DFU_PHASE_VERIFY_FAIL) { + dfu_verify_fail = true; + if (k_sem_take(&dfu_verify_failed, K_SECONDS(DFU_TIMEOUT))) { + FAIL("Phase not reached"); + } + } else { + /* Stop at BT_MESH_DFU_PHASE_TRANSFER_ACTIVE */ + if (k_sem_take(&dfu_started, K_SECONDS(DFU_TIMEOUT))) { + FAIL("Phase not reached"); + } + } + + ASSERT_EQUAL(expected_stop_phase, dfu_srv.update.phase); + PASS(); + return; + } + + bt_mesh_device_setup(&prov, &target_comp); + bt_mesh_test_cfg_set(NULL, WAIT_TIME); + + switch (expected_stop_phase) { + case BT_MESH_DFU_PHASE_VERIFY: + ASSERT_EQUAL(BT_MESH_DFU_PHASE_TRANSFER_ERR, dfu_srv.update.phase); + if (k_sem_take(&dfu_verifying, K_SECONDS(DFU_TIMEOUT))) { + FAIL("Phase not reached"); + } + ASSERT_EQUAL(BT_MESH_DFU_PHASE_VERIFY, dfu_srv.update.phase); + break; + case BT_MESH_DFU_PHASE_VERIFY_OK: + ASSERT_EQUAL(BT_MESH_DFU_PHASE_VERIFY, dfu_srv.update.phase); + bt_mesh_dfu_srv_verified(&dfu_srv); + ASSERT_EQUAL(BT_MESH_DFU_PHASE_VERIFY_OK, dfu_srv.update.phase); + break; + case BT_MESH_DFU_PHASE_APPLYING: + ASSERT_EQUAL(BT_MESH_DFU_PHASE_VERIFY_FAIL, dfu_srv.update.phase); + if (k_sem_take(&dfu_applying, K_SECONDS(DFU_TIMEOUT))) { + FAIL("Phase not reached"); + } + ASSERT_EQUAL(BT_MESH_DFU_PHASE_APPLYING, dfu_srv.update.phase); + break; + case BT_MESH_DFU_PHASE_APPLY_SUCCESS: + ASSERT_EQUAL(BT_MESH_DFU_PHASE_APPLYING, dfu_srv.update.phase); + bt_mesh_dfu_srv_applied(&dfu_srv); + ASSERT_EQUAL(BT_MESH_DFU_PHASE_IDLE, dfu_srv.update.phase); + break; + default: + FAIL("Wrong expected phase"); + break; + } + + ASSERT_EQUAL(0, dfu_srv.update.idx); + PASS(); +} + static void test_pre_init(void) { k_sem_init(&dfu_dist_ended, 0, 1); @@ -1160,6 +1455,10 @@ static void test_pre_init(void) k_sem_init(&dfu_cli_applied_sem, 0, 1); k_sem_init(&dfu_cli_confirmed_sem, 0, 1); k_sem_init(&lost_target_sem, 0, 1); + k_sem_init(&dfu_started, 0, 1); + k_sem_init(&dfu_verifying, 0, 1); + k_sem_init(&dfu_verify_failed, 0, 1); + k_sem_init(&dfu_applying, 0, 1); } #define TEST_CASE(role, name, description) \ @@ -1181,6 +1480,7 @@ static const struct bst_test_instance test_dfu[] = { TEST_CASE(dist, dfu_slot_delete_all, "Distributor deletes all image slots"), TEST_CASE(dist, dfu_slot_check_delete_all, "Distributor checks if all slots are removed from persistent storage"), + TEST_CASE(cli, stop, "DFU Client stops at configured point of Firmware Distribution"), TEST_CASE(cli, fail_on_persistency, "DFU Client doesn't give up DFU Transfer"), TEST_CASE(target, dfu_no_change, "Target node, Comp Data stays unchanged"), @@ -1193,6 +1493,7 @@ static const struct bst_test_instance test_dfu[] = { TEST_CASE(target, fail_on_verify, "Server rejects fw at Refresh step"), TEST_CASE(target, fail_on_apply, "Server failing on Fw Update Apply msg"), TEST_CASE(target, fail_on_nothing, "Non-failing server"), + TEST_CASE(target, dfu_stop, "Server stops FD procedure at configured step"), BSTEST_END_MARKER }; diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_srv_persistence.sh b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_srv_persistence.sh new file mode 100755 index 000000000000..72982bec50ff --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/dfu/dfu_srv_persistence.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +# Note: +# Tests must be added in pairs and in sequence. +# First test pair: executes Receive Firmware procedure up to certain point using distributor and +# target. +# Second test pair: tests are executed with `recover` enabled. This means target will recover +# settings from persistent storage, which will allow to verify if stored DFU server's phase and +# image index were loaded correctly. +# Test cases are designed to be run using single target. `dfu_cli_stop` test case in recovery part +# plays dummy role, and is there to keep order of settings files being loaded. +conf=prj_mesh1d1_conf +overlay=overlay_pst_conf +RunTest dfu_dist_recover_phase dfu_cli_stop dfu_target_dfu_stop -- -argstest \ + recover=0 expected-phase=2 + +conf=prj_mesh1d1_conf +overlay=overlay_pst_conf +RunTest dfu_dist_recover_phase dfu_cli_stop dfu_target_dfu_stop -- -argstest \ + recover=1 expected-phase=3 + +conf=prj_mesh1d1_conf +overlay=overlay_pst_conf +RunTest dfu_dist_recover_phase dfu_cli_stop dfu_target_dfu_stop -- -argstest \ + recover=1 expected-phase=4 + +conf=prj_mesh1d1_conf +overlay=overlay_pst_conf +RunTest dfu_dist_recover_phase dfu_cli_stop dfu_target_dfu_stop -- -argstest \ + recover=1 expected-phase=6 + +# Use phase `BT_MESH_DFU_PHASE_APPLY_SUCCESS` as marker to bring whole procedure to an end +conf=prj_mesh1d1_conf +overlay=overlay_pst_conf +RunTest dfu_dist_recover_phase dfu_cli_stop dfu_target_dfu_stop -- -argstest \ + recover=1 expected-phase=8 + +# To test recovery from Verify Fail begin new distribution that will end there, +# reboot devices and continue to Applying. +conf=prj_mesh1d1_conf +overlay=overlay_pst_conf +RunTest dfu_dist_recover_phase dfu_cli_stop dfu_target_dfu_stop -- -argstest \ + recover=0 expected-phase=5 + +conf=prj_mesh1d1_conf +overlay=overlay_pst_conf +RunTest dfu_dist_recover_phase dfu_cli_stop dfu_target_dfu_stop -- -argstest \ + recover=1 expected-phase=6 From 837091c05627950adfbd8bc47fe57560ec39607d Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Fri, 17 Mar 2023 10:14:47 +0100 Subject: [PATCH 0463/1906] west.yml: Update nanopb to 0.4.7 Update nanopb to the latest released version 0.4.7. This fixes a recurring issue where the python-protobuf breaks with the protoc compiler and forces a pure python implementation. Signed-off-by: Pieter De Gendt --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index f2c77d6f5344..e56cf9bd10c6 100644 --- a/west.yml +++ b/west.yml @@ -189,7 +189,7 @@ manifest: - debug revision: 0d521d8055f3b2b4842f728b0365d3f0ece9c37f - name: nanopb - revision: dc4deed54fd4c7e1935e3b6387eedf21bb45dc38 + revision: 42fa8b211e946b90b9d968523fce7b1cfe27617e path: modules/lib/nanopb - name: net-tools revision: e0828aa9629b533644dc96ff6d1295c939bd713c From da04b42fa4b28127a300e309bcd27cfeb0dd7c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20S=C3=A6ther?= Date: Sat, 18 Mar 2023 16:52:41 +0100 Subject: [PATCH 0464/1906] samples: bluetooth: BTHome sensor template fix whitespace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whitespace fix. Signed-off-by: Ole Sæther Signed-off-by: Jonathan Rico --- samples/bluetooth/bthome_sensor_template/src/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/bluetooth/bthome_sensor_template/src/main.c b/samples/bluetooth/bthome_sensor_template/src/main.c index fcfa5103a6fb..b68bec8cc131 100644 --- a/samples/bluetooth/bthome_sensor_template/src/main.c +++ b/samples/bluetooth/bthome_sensor_template/src/main.c @@ -8,13 +8,13 @@ #include #define SERVICE_DATA_LEN 9 -#define SERVICE_UUID 0xfcd2 /* BTHome service UUID */ +#define SERVICE_UUID 0xfcd2 /* BTHome service UUID */ #define IDX_TEMPL 4 /* Index of lo byte of temp in service data*/ #define IDX_TEMPH 5 /* Index of hi byte of temp in service data*/ #define ADV_PARAM BT_LE_ADV_PARAM(BT_LE_ADV_OPT_USE_IDENTITY, \ - BT_GAP_ADV_SLOW_INT_MIN, \ - BT_GAP_ADV_SLOW_INT_MAX, NULL) + BT_GAP_ADV_SLOW_INT_MIN, \ + BT_GAP_ADV_SLOW_INT_MAX, NULL) static uint8_t service_data[SERVICE_DATA_LEN] = { From db193332fa13379ff6858b76702152b471463f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Mon, 20 Mar 2023 10:32:06 +0100 Subject: [PATCH 0465/1906] drivers: clock_control: correct enable / disable of backup domain on STM32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The U5-series was missed when adding if-defs around enable / disable of the backup domain access, this patch makes sure the U5-series is handled correctly. Signed-off-by: Benjamin Björnsson --- drivers/clock_control/clock_stm32_ll_common.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/clock_control/clock_stm32_ll_common.c b/drivers/clock_control/clock_stm32_ll_common.c index 03ff2924562e..b30355149a78 100644 --- a/drivers/clock_control/clock_stm32_ll_common.c +++ b/drivers/clock_control/clock_stm32_ll_common.c @@ -622,13 +622,13 @@ static void set_up_fixed_clock_sources(void) z_stm32_hsem_lock(CFG_HW_RCC_SEMID, HSEM_LOCK_DEFAULT_RETRY); -#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) +#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPR_DBP) /* Set the DBP bit in the Power control register 1 (PWR_CR1) */ LL_PWR_EnableBkUpAccess(); while (!LL_PWR_IsEnabledBkUpAccess()) { /* Wait for Backup domain access */ } -#endif /* PWR_CR_DBP || PWR_CR1_DBP */ +#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */ #if STM32_LSE_DRIVING /* Configure driving capability */ @@ -653,9 +653,9 @@ static void set_up_fixed_clock_sources(void) } #endif /* RCC_BDCR_LSESYSEN */ -#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) +#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPR_DBP) LL_PWR_DisableBkUpAccess(); -#endif /* PWR_CR_DBP || PWR_CR1_DBP */ +#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */ z_stm32_hsem_unlock(CFG_HW_RCC_SEMID); } From 2fedb306f74187c280b594b754d61c0100e21091 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Wed, 22 Feb 2023 12:34:27 +0000 Subject: [PATCH 0466/1906] drivers: Add retained memory driver interface Adds a new driver interface for retained memory devices which can be used to store data and have it retained whilst the device is powered thorugh different application execution states (though this data may be lost in low power states). Signed-off-by: Jamie McCrae --- drivers/CMakeLists.txt | 1 + drivers/Kconfig | 1 + drivers/retained_mem/CMakeLists.txt | 3 + drivers/retained_mem/Kconfig | 22 +++ drivers/retained_mem/retained_mem_handlers.c | 40 ++++ include/zephyr/drivers/retained_mem.h | 195 +++++++++++++++++++ 6 files changed, 262 insertions(+) create mode 100644 drivers/retained_mem/CMakeLists.txt create mode 100644 drivers/retained_mem/Kconfig create mode 100644 drivers/retained_mem/retained_mem_handlers.c create mode 100644 include/zephyr/drivers/retained_mem.h diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 63af95cedd89..eb626f2868a7 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -62,6 +62,7 @@ add_subdirectory_ifdef(CONFIG_PTP_CLOCK ptp_clock) add_subdirectory_ifdef(CONFIG_PWM pwm) add_subdirectory_ifdef(CONFIG_REGULATOR regulator) add_subdirectory_ifdef(CONFIG_RESET reset) +add_subdirectory_ifdef(CONFIG_RETAINED_MEM retained_mem) add_subdirectory_ifdef(CONFIG_SDHC sdhc) add_subdirectory_ifdef(CONFIG_SENSOR sensor) add_subdirectory_ifdef(CONFIG_SERIAL_HAS_DRIVER serial) diff --git a/drivers/Kconfig b/drivers/Kconfig index d4259816ade4..e462c28a440d 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -63,6 +63,7 @@ source "drivers/ptp_clock/Kconfig" source "drivers/pwm/Kconfig" source "drivers/regulator/Kconfig" source "drivers/reset/Kconfig" +source "drivers/retained_mem/Kconfig" source "drivers/sdhc/Kconfig" source "drivers/sensor/Kconfig" source "drivers/serial/Kconfig" diff --git a/drivers/retained_mem/CMakeLists.txt b/drivers/retained_mem/CMakeLists.txt new file mode 100644 index 000000000000..28a0cecce8ac --- /dev/null +++ b/drivers/retained_mem/CMakeLists.txt @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() diff --git a/drivers/retained_mem/Kconfig b/drivers/retained_mem/Kconfig new file mode 100644 index 000000000000..1b76aeed48ed --- /dev/null +++ b/drivers/retained_mem/Kconfig @@ -0,0 +1,22 @@ +# Copyright (c) Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +menuconfig RETAINED_MEM + bool "Retained memory support" + help + Enables support for drivers that can retain their data whilst the + device is powered (may be lost in low power states). + +if RETAINED_MEM + +config RETAINED_MEM_INIT_PRIORITY + int "Retained memory devices init priority" + default 40 + help + Retained memory devices initialization priority, + +module = RETAINED_MEM +module-str = retained_mem +source "subsys/logging/Kconfig.template.log_config" + +endif # RETAINED_MEM diff --git a/drivers/retained_mem/retained_mem_handlers.c b/drivers/retained_mem/retained_mem_handlers.c new file mode 100644 index 000000000000..265ae7b15fd9 --- /dev/null +++ b/drivers/retained_mem/retained_mem_handlers.c @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023, Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +static inline ssize_t z_vrfy_retained_mem_size(const struct device *dev) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_RETAINED_MEM)); + return z_impl_retained_mem_size(dev); +} +#include + +static inline int z_vrfy_retained_mem_read(const struct device *dev, off_t offset, + uint8_t *buffer, size_t size) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_RETAINED_MEM)); + Z_OOPS(Z_SYSCALL_MEMORY_WRITE(buffer, size)); + return z_impl_retained_mem_read(dev, offset, buffer, size); +} +#include + +static inline int z_vrfy_retained_mem_write(const struct device *dev, off_t offset, + const uint8_t *buffer, size_t size) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_RETAINED_MEM)); + Z_OOPS(Z_SYSCALL_MEMORY_READ(buffer, size)); + return z_impl_retained_mem_write(dev, offset, buffer, size); +} +#include + +static inline int z_vrfy_retained_mem_clear(const struct device *dev) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_RETAINED_MEM)); + return z_impl_retained_mem_clear(dev); +} +#include diff --git a/include/zephyr/drivers/retained_mem.h b/include/zephyr/drivers/retained_mem.h new file mode 100644 index 000000000000..18bfffed0999 --- /dev/null +++ b/include/zephyr/drivers/retained_mem.h @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Public API for retained memory drivers + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_RETAINED_MEM_ +#define ZEPHYR_INCLUDE_DRIVERS_RETAINED_MEM_ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +BUILD_ASSERT(!(sizeof(off_t) > sizeof(size_t)), + "Size of off_t must be equal or less than size of size_t"); + +/** + * @brief Retained memory driver interface + * @defgroup retained_mem_interface Retained memory driver interface + * @ingroup io_interfaces + * @{ + */ + +/** + * @typedef retained_mem_size_api + * @brief Callback API to get size of retained memory area. + * See retained_mem_size() for argument description. + */ +typedef ssize_t (*retained_mem_size_api)(const struct device *dev); + +/** + * @typedef retained_mem_read_api + * @brief Callback API to read from retained memory area. + * See retained_mem_read() for argument description. + */ +typedef int (*retained_mem_read_api)(const struct device *dev, off_t offset, uint8_t *buffer, + size_t size); + +/** + * @typedef retained_mem_write_api + * @brief Callback API to write to retained memory area. + * See retained_mem_write() for argument description. + */ +typedef int (*retained_mem_write_api)(const struct device *dev, off_t offset, + const uint8_t *buffer, size_t size); + +/** + * @typedef retained_mem_clear_api + * @brief Callback API to clear retained memory area (reset all data to 0x00). + * See retained_mem_clear() for argument description. + */ +typedef int (*retained_mem_clear_api)(const struct device *dev); + +/** + * @brief Retained memory driver API + * API which can be used by a device to store data in a retained memory area. Retained memory is + * memory that is retained while the device is powered but is lost when power to the device is + * lost (note that low power modes in some devices may clear the data also). This may be in a + * non-initialised RAM region, or in specific registers, but is not reset when a different + * application begins execution or the device is rebooted (without power loss). It must support + * byte-level reading and writing without a need to erase data before writing. + * + * Note that drivers must implement all functions, none of the functions are optional. + */ +struct retained_mem_driver_api { + retained_mem_size_api size; + retained_mem_read_api read; + retained_mem_write_api write; + retained_mem_clear_api clear; +}; + +/** + * @brief Returns the size of the retained memory area. + * + * @param dev Retained memory device to use. + * + * @retval Positive value indicating size in bytes on success, else negative errno + * code. + */ +__syscall ssize_t retained_mem_size(const struct device *dev); + +static inline ssize_t z_impl_retained_mem_size(const struct device *dev) +{ + struct retained_mem_driver_api *api = (struct retained_mem_driver_api *)dev->api; + + return api->size(dev); +} + +/** + * @brief Reads data from the Retained memory area. + * + * @param dev Retained memory device to use. + * @param offset Offset to read data from. + * @param buffer Buffer to store read data in. + * @param size Size of data to read. + * + * @retval 0 on success else negative errno code. + */ +__syscall int retained_mem_read(const struct device *dev, off_t offset, uint8_t *buffer, + size_t size); + +static inline int z_impl_retained_mem_read(const struct device *dev, off_t offset, + uint8_t *buffer, size_t size) +{ + struct retained_mem_driver_api *api = (struct retained_mem_driver_api *)dev->api; + size_t area_size; + + /* Validate user-supplied parameters */ + if (size == 0) { + return 0; + } + + area_size = api->size(dev); + + if (offset < 0 || size > area_size || (area_size - size) < (size_t)offset) { + return -EINVAL; + } + + return api->read(dev, offset, buffer, size); +} + +/** + * @brief Writes data to the Retained memory area - underlying data does not need to + * be cleared prior to writing. + * + * @param dev Retained memory device to use. + * @param offset Offset to write data to. + * @param buffer Data to write. + * @param size Size of data to be written. + * + * @retval 0 on success else negative errno code. + */ +__syscall int retained_mem_write(const struct device *dev, off_t offset, const uint8_t *buffer, + size_t size); + +static inline int z_impl_retained_mem_write(const struct device *dev, off_t offset, + const uint8_t *buffer, size_t size) +{ + struct retained_mem_driver_api *api = (struct retained_mem_driver_api *)dev->api; + size_t area_size; + + /* Validate user-supplied parameters */ + if (size == 0) { + return 0; + } + + area_size = api->size(dev); + + if (offset < 0 || size > area_size || (area_size - size) < (size_t)offset) { + return -EINVAL; + } + + return api->write(dev, offset, buffer, size); +} + +/** + * @brief Clears data in the retained memory area by setting it to 0x00. + * + * @param dev Retained memory device to use. + * + * @retval 0 on success else negative errno code. + */ +__syscall int retained_mem_clear(const struct device *dev); + +static inline int z_impl_retained_mem_clear(const struct device *dev) +{ + struct retained_mem_driver_api *api = (struct retained_mem_driver_api *)dev->api; + + return api->clear(dev); +} + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#include + +#endif /* ZEPHYR_INCLUDE_DRIVERS_RETAINED_MEM_ */ From 9bda013e5d37f0e5705c459e6ae263a8debe7226 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Wed, 22 Feb 2023 12:54:13 +0000 Subject: [PATCH 0467/1906] drivers: retained_mem: Add nRF GPREGRET driver Adds a driver for the Nordic nRF GPREGRET registers and adds entries to the SoCs for this peripheral. Signed-off-by: Jamie McCrae --- drivers/retained_mem/CMakeLists.txt | 1 + drivers/retained_mem/Kconfig | 2 + drivers/retained_mem/Kconfig.nrf | 10 ++ .../retained_mem/retained_mem_nrf_gpregret.c | 136 ++++++++++++++++++ dts/arm/nordic/nrf51822.dtsi | 8 ++ dts/arm/nordic/nrf52805.dtsi | 14 ++ dts/arm/nordic/nrf52810.dtsi | 14 ++ dts/arm/nordic/nrf52811.dtsi | 14 ++ dts/arm/nordic/nrf52820.dtsi | 14 ++ dts/arm/nordic/nrf52832.dtsi | 14 ++ dts/arm/nordic/nrf52833.dtsi | 14 ++ dts/arm/nordic/nrf52840.dtsi | 14 ++ .../nordic/nrf5340_cpuapp_peripherals.dtsi | 14 ++ dts/arm/nordic/nrf5340_cpunet.dtsi | 14 ++ dts/arm/nordic/nrf9160_common.dtsi | 14 ++ .../retained_mem/nordic,nrf-gpreget.yaml | 12 ++ 16 files changed, 309 insertions(+) create mode 100644 drivers/retained_mem/Kconfig.nrf create mode 100644 drivers/retained_mem/retained_mem_nrf_gpregret.c create mode 100644 dts/bindings/retained_mem/nordic,nrf-gpreget.yaml diff --git a/drivers/retained_mem/CMakeLists.txt b/drivers/retained_mem/CMakeLists.txt index 28a0cecce8ac..027db434a327 100644 --- a/drivers/retained_mem/CMakeLists.txt +++ b/drivers/retained_mem/CMakeLists.txt @@ -1,3 +1,4 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_library() +zephyr_library_sources_ifdef(CONFIG_RETAINED_MEM_NRF_GPREGRET retained_mem_nrf_gpregret.c) diff --git a/drivers/retained_mem/Kconfig b/drivers/retained_mem/Kconfig index 1b76aeed48ed..c8cd06b6920a 100644 --- a/drivers/retained_mem/Kconfig +++ b/drivers/retained_mem/Kconfig @@ -19,4 +19,6 @@ module = RETAINED_MEM module-str = retained_mem source "subsys/logging/Kconfig.template.log_config" +source "drivers/retained_mem/Kconfig.nrf" + endif # RETAINED_MEM diff --git a/drivers/retained_mem/Kconfig.nrf b/drivers/retained_mem/Kconfig.nrf new file mode 100644 index 000000000000..5f94b75aa888 --- /dev/null +++ b/drivers/retained_mem/Kconfig.nrf @@ -0,0 +1,10 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config RETAINED_MEM_NRF_GPREGRET + bool "nRF GPREGRET driver" + default y + depends on DT_HAS_NORDIC_NRF_GPREGRET_ENABLED + help + Enable driver for Nordic nRF GPREGRET-based retained memory + register support. diff --git a/drivers/retained_mem/retained_mem_nrf_gpregret.c b/drivers/retained_mem/retained_mem_nrf_gpregret.c new file mode 100644 index 000000000000..43fc486aeaa7 --- /dev/null +++ b/drivers/retained_mem/retained_mem_nrf_gpregret.c @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2023, Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT nordic_nrf_gpregret + +#include +#include +#include +#include +#include +#include +#include + +LOG_MODULE_REGISTER(retained_mem_nrf_gpregret, CONFIG_RETAINED_MEM_LOG_LEVEL); + +#ifdef CONFIG_MULTITHREADING +struct nrf_gpregret_data { + struct k_mutex lock; +}; +#endif + +struct nrf_gpregret_config { + uint8_t *addr; + size_t size; +}; + +static inline void nrf_gpregret_lock_take(const struct device *dev) +{ +#ifdef CONFIG_MULTITHREADING + struct nrf_gpregret_data *data = dev->data; + + k_mutex_lock(&data->lock, K_FOREVER); +#else + ARG_UNUSED(dev); +#endif +} + +static inline void nrf_gpregret_lock_release(const struct device *dev) +{ +#ifdef CONFIG_MULTITHREADING + struct nrf_gpregret_data *data = dev->data; + + k_mutex_unlock(&data->lock); +#else + ARG_UNUSED(dev); +#endif +} + +static int nrf_gpregret_init(const struct device *dev) +{ +#ifdef CONFIG_MULTITHREADING + struct nrf_gpregret_data *data = dev->data; + + k_mutex_init(&data->lock); +#endif + + return 0; +} + +static ssize_t nrf_gpregret_size(const struct device *dev) +{ + const struct nrf_gpregret_config *config = dev->config; + + return (ssize_t)config->size; +} + +static int nrf_gpregret_read(const struct device *dev, off_t offset, uint8_t *buffer, size_t size) +{ + const struct nrf_gpregret_config *config = dev->config; + + nrf_gpregret_lock_take(dev); + + memcpy(buffer, (config->addr + offset), size); + + nrf_gpregret_lock_release(dev); + + return 0; +} + +static int nrf_gpregret_write(const struct device *dev, off_t offset, const uint8_t *buffer, + size_t size) +{ + const struct nrf_gpregret_config *config = dev->config; + + nrf_gpregret_lock_take(dev); + + memcpy((config->addr + offset), buffer, size); + + nrf_gpregret_lock_release(dev); + + return 0; +} + +static int nrf_gpregret_clear(const struct device *dev) +{ + const struct nrf_gpregret_config *config = dev->config; + + nrf_gpregret_lock_take(dev); + + memset(config->addr, 0, config->size); + + nrf_gpregret_lock_release(dev); + + return 0; +} + +static const struct retained_mem_driver_api nrf_gpregret_api = { + .size = nrf_gpregret_size, + .read = nrf_gpregret_read, + .write = nrf_gpregret_write, + .clear = nrf_gpregret_clear, +}; + +#define NRF_GPREGRET_DEVICE(inst) \ + IF_ENABLED(CONFIG_MULTITHREADING, \ + (static struct nrf_gpregret_data nrf_gpregret_data_##inst;) \ + ) \ + static const struct nrf_gpregret_config nrf_gpregret_config_##inst = { \ + .addr = (uint8_t *)DT_INST_REG_ADDR(inst), \ + .size = DT_INST_REG_SIZE(inst), \ + }; \ + DEVICE_DT_INST_DEFINE(inst, \ + &nrf_gpregret_init, \ + NULL, \ + COND_CODE_1(CONFIG_MULTITHREADING, \ + (&nrf_gpregret_data_##inst), (NULL) \ + ), \ + &nrf_gpregret_config_##inst, \ + POST_KERNEL, \ + CONFIG_RETAINED_MEM_INIT_PRIORITY, \ + &nrf_gpregret_api); + +DT_INST_FOREACH_STATUS_OKAY(NRF_GPREGRET_DEVICE) diff --git a/dts/arm/nordic/nrf51822.dtsi b/dts/arm/nordic/nrf51822.dtsi index f9997347f9b7..1a8cf741708d 100644 --- a/dts/arm/nordic/nrf51822.dtsi +++ b/dts/arm/nordic/nrf51822.dtsi @@ -42,6 +42,14 @@ reg = <0x40000000 0x1000>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; + #address-cells = <1>; + #size-cells = <1>; + + gpregret1: gpregret1@4000051c { + compatible = "nordic,nrf-gpregret"; + reg = <0x4000051c 0x1>; + status = "okay"; + }; }; clock: clock@40000000 { diff --git a/dts/arm/nordic/nrf52805.dtsi b/dts/arm/nordic/nrf52805.dtsi index 43f13e1a48ad..b4db33bd766b 100644 --- a/dts/arm/nordic/nrf52805.dtsi +++ b/dts/arm/nordic/nrf52805.dtsi @@ -53,6 +53,20 @@ reg = <0x40000000 0x1000>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; + #address-cells = <1>; + #size-cells = <1>; + + gpregret1: gpregret1@4000051c { + compatible = "nordic,nrf-gpregret"; + reg = <0x4000051c 0x1>; + status = "okay"; + }; + + gpregret2: gpregret2@40000520 { + compatible = "nordic,nrf-gpregret"; + reg = <0x40000520 0x1>; + status = "okay"; + }; }; bprot: bprot@40000000 { diff --git a/dts/arm/nordic/nrf52810.dtsi b/dts/arm/nordic/nrf52810.dtsi index d799004cbc95..88fd7280df50 100644 --- a/dts/arm/nordic/nrf52810.dtsi +++ b/dts/arm/nordic/nrf52810.dtsi @@ -57,6 +57,20 @@ reg = <0x40000000 0x1000>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; + #address-cells = <1>; + #size-cells = <1>; + + gpregret1: gpregret1@4000051c { + compatible = "nordic,nrf-gpregret"; + reg = <0x4000051c 0x1>; + status = "okay"; + }; + + gpregret2: gpregret2@40000520 { + compatible = "nordic,nrf-gpregret"; + reg = <0x40000520 0x1>; + status = "okay"; + }; }; bprot: bprot@40000000 { diff --git a/dts/arm/nordic/nrf52811.dtsi b/dts/arm/nordic/nrf52811.dtsi index 5cb0dce0909c..945d2af959ae 100644 --- a/dts/arm/nordic/nrf52811.dtsi +++ b/dts/arm/nordic/nrf52811.dtsi @@ -61,6 +61,20 @@ reg = <0x40000000 0x1000>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; + #address-cells = <1>; + #size-cells = <1>; + + gpregret1: gpregret1@4000051c { + compatible = "nordic,nrf-gpregret"; + reg = <0x4000051c 0x1>; + status = "okay"; + }; + + gpregret2: gpregret2@40000520 { + compatible = "nordic,nrf-gpregret"; + reg = <0x40000520 0x1>; + status = "okay"; + }; }; bprot: bprot@40000000 { diff --git a/dts/arm/nordic/nrf52820.dtsi b/dts/arm/nordic/nrf52820.dtsi index 0a0bc7ab8d5a..f42c7e5daf58 100644 --- a/dts/arm/nordic/nrf52820.dtsi +++ b/dts/arm/nordic/nrf52820.dtsi @@ -62,6 +62,20 @@ reg = <0x40000000 0x1000>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; + #address-cells = <1>; + #size-cells = <1>; + + gpregret1: gpregret1@4000051c { + compatible = "nordic,nrf-gpregret"; + reg = <0x4000051c 0x1>; + status = "okay"; + }; + + gpregret2: gpregret2@40000520 { + compatible = "nordic,nrf-gpregret"; + reg = <0x40000520 0x1>; + status = "okay"; + }; }; radio: radio@40001000 { diff --git a/dts/arm/nordic/nrf52832.dtsi b/dts/arm/nordic/nrf52832.dtsi index 55866efdb8b4..02551e4c680d 100644 --- a/dts/arm/nordic/nrf52832.dtsi +++ b/dts/arm/nordic/nrf52832.dtsi @@ -57,6 +57,20 @@ reg = <0x40000000 0x1000>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; + #address-cells = <1>; + #size-cells = <1>; + + gpregret1: gpregret1@4000051c { + compatible = "nordic,nrf-gpregret"; + reg = <0x4000051c 0x1>; + status = "okay"; + }; + + gpregret2: gpregret2@40000520 { + compatible = "nordic,nrf-gpregret"; + reg = <0x40000520 0x1>; + status = "okay"; + }; }; bprot: bprot@40000000 { diff --git a/dts/arm/nordic/nrf52833.dtsi b/dts/arm/nordic/nrf52833.dtsi index cc12365e9d9f..c59be8d74ade 100644 --- a/dts/arm/nordic/nrf52833.dtsi +++ b/dts/arm/nordic/nrf52833.dtsi @@ -61,6 +61,20 @@ reg = <0x40000000 0x1000>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; + #address-cells = <1>; + #size-cells = <1>; + + gpregret1: gpregret1@4000051c { + compatible = "nordic,nrf-gpregret"; + reg = <0x4000051c 0x1>; + status = "okay"; + }; + + gpregret2: gpregret2@40000520 { + compatible = "nordic,nrf-gpregret"; + reg = <0x40000520 0x1>; + status = "okay"; + }; }; radio: radio@40001000 { diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index fc69434632cb..b79a4d3899c7 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -57,6 +57,20 @@ reg = <0x40000000 0x1000>; interrupts = <0 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; + #address-cells = <1>; + #size-cells = <1>; + + gpregret1: gpregret1@4000051c { + compatible = "nordic,nrf-gpregret"; + reg = <0x4000051c 0x1>; + status = "okay"; + }; + + gpregret2: gpregret2@40000520 { + compatible = "nordic,nrf-gpregret"; + reg = <0x40000520 0x1>; + status = "okay"; + }; }; radio: radio@40001000 { diff --git a/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi b/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi index 38fa50992035..729b977af034 100644 --- a/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi @@ -34,6 +34,20 @@ power: power@5000 { reg = <0x5000 0x1000>; interrupts = <5 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; + #address-cells = <1>; + #size-cells = <1>; + + gpregret1: gpregret1@551c { + compatible = "nordic,nrf-gpregret"; + reg = <0x551c 0x1>; + status = "okay"; + }; + + gpregret2: gpregret2@5520 { + compatible = "nordic,nrf-gpregret"; + reg = <0x5520 0x1>; + status = "okay"; + }; }; reset: reset-controller@5000 { diff --git a/dts/arm/nordic/nrf5340_cpunet.dtsi b/dts/arm/nordic/nrf5340_cpunet.dtsi index 3ba45d0b7cdb..76eadce06549 100644 --- a/dts/arm/nordic/nrf5340_cpunet.dtsi +++ b/dts/arm/nordic/nrf5340_cpunet.dtsi @@ -65,6 +65,20 @@ reg = <0x41005000 0x1000>; interrupts = <5 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; + #address-cells = <1>; + #size-cells = <1>; + + gpregret1: gpregret1@4100551c { + compatible = "nordic,nrf-gpregret"; + reg = <0x4100551c 0x1>; + status = "okay"; + }; + + gpregret2: gpregret2@41005520 { + compatible = "nordic,nrf-gpregret"; + reg = <0x41005520 0x1>; + status = "okay"; + }; }; radio: radio@41008000 { diff --git a/dts/arm/nordic/nrf9160_common.dtsi b/dts/arm/nordic/nrf9160_common.dtsi index 162a20465975..5baf0578c224 100644 --- a/dts/arm/nordic/nrf9160_common.dtsi +++ b/dts/arm/nordic/nrf9160_common.dtsi @@ -339,6 +339,20 @@ power: power@5000 { reg = <0x5000 0x1000>; interrupts = <5 NRF_DEFAULT_IRQ_PRIORITY>; status = "okay"; + #address-cells = <1>; + #size-cells = <1>; + + gpregret1: gpregret1@551c { + compatible = "nordic,nrf-gpregret"; + reg = <0x551c 0x1>; + status = "okay"; + }; + + gpregret2: gpregret2@5520 { + compatible = "nordic,nrf-gpregret"; + reg = <0x5520 0x1>; + status = "okay"; + }; }; wdt: wdt0: watchdog@18000 { diff --git a/dts/bindings/retained_mem/nordic,nrf-gpreget.yaml b/dts/bindings/retained_mem/nordic,nrf-gpreget.yaml new file mode 100644 index 000000000000..8f136be4b329 --- /dev/null +++ b/dts/bindings/retained_mem/nordic,nrf-gpreget.yaml @@ -0,0 +1,12 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: Nordic GPREGRET (General Purpose Register Retention) device. + +compatible: "nordic,nrf-gpregret" + +include: base.yaml + +properties: + reg: + required: true From 5bae23b89171ef4db5665ae7ec84038cb61e2802 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Wed, 22 Feb 2023 13:29:37 +0000 Subject: [PATCH 0468/1906] drivers: retained_mem: Add RAM driver Adds a non-initialised RAM-based retained memory driver. Signed-off-by: Jamie McCrae --- drivers/retained_mem/CMakeLists.txt | 1 + drivers/retained_mem/Kconfig | 2 + drivers/retained_mem/Kconfig.zephyr | 9 ++ .../retained_mem/retained_mem_zephyr_ram.c | 139 ++++++++++++++++++ .../retained_mem/zephyr,retained-ram.yaml | 8 + 5 files changed, 159 insertions(+) create mode 100644 drivers/retained_mem/Kconfig.zephyr create mode 100644 drivers/retained_mem/retained_mem_zephyr_ram.c create mode 100644 dts/bindings/retained_mem/zephyr,retained-ram.yaml diff --git a/drivers/retained_mem/CMakeLists.txt b/drivers/retained_mem/CMakeLists.txt index 027db434a327..c3c9ea6d0bdd 100644 --- a/drivers/retained_mem/CMakeLists.txt +++ b/drivers/retained_mem/CMakeLists.txt @@ -2,3 +2,4 @@ zephyr_library() zephyr_library_sources_ifdef(CONFIG_RETAINED_MEM_NRF_GPREGRET retained_mem_nrf_gpregret.c) +zephyr_library_sources_ifdef(CONFIG_RETAINED_MEM_ZEPHYR_RAM retained_mem_zephyr_ram.c) diff --git a/drivers/retained_mem/Kconfig b/drivers/retained_mem/Kconfig index c8cd06b6920a..c8a9862dfe06 100644 --- a/drivers/retained_mem/Kconfig +++ b/drivers/retained_mem/Kconfig @@ -21,4 +21,6 @@ source "subsys/logging/Kconfig.template.log_config" source "drivers/retained_mem/Kconfig.nrf" +source "drivers/retained_mem/Kconfig.zephyr" + endif # RETAINED_MEM diff --git a/drivers/retained_mem/Kconfig.zephyr b/drivers/retained_mem/Kconfig.zephyr new file mode 100644 index 000000000000..4a4231c4968a --- /dev/null +++ b/drivers/retained_mem/Kconfig.zephyr @@ -0,0 +1,9 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config RETAINED_MEM_ZEPHYR_RAM + bool "Generic Zephyr RAM retained memory driver" + default y + depends on DT_HAS_ZEPHYR_RETAINED_RAM_ENABLED + help + Enable driver for retained memory in RAM. diff --git a/drivers/retained_mem/retained_mem_zephyr_ram.c b/drivers/retained_mem/retained_mem_zephyr_ram.c new file mode 100644 index 000000000000..55c86c392c23 --- /dev/null +++ b/drivers/retained_mem/retained_mem_zephyr_ram.c @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2023, Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT zephyr_retained_ram + +#include +#include +#include +#include +#include +#include +#include + +LOG_MODULE_REGISTER(retained_mem_zephyr_ram, CONFIG_RETAINED_MEM_LOG_LEVEL); + +#ifdef CONFIG_MULTITHREADING +struct zephyr_retained_mem_ram_data { + struct k_mutex lock; +}; +#endif + +struct zephyr_retained_mem_ram_config { + uint8_t *address; + size_t size; +}; + +static inline void zephyr_retained_mem_ram_lock_take(const struct device *dev) +{ +#ifdef CONFIG_MULTITHREADING + struct zephyr_retained_mem_ram_data *data = dev->data; + + k_mutex_lock(&data->lock, K_FOREVER); +#else + ARG_UNUSED(dev); +#endif +} + +static inline void zephyr_retained_mem_ram_lock_release(const struct device *dev) +{ +#ifdef CONFIG_MULTITHREADING + struct zephyr_retained_mem_ram_data *data = dev->data; + + k_mutex_unlock(&data->lock); +#else + ARG_UNUSED(dev); +#endif +} + +static int zephyr_retained_mem_ram_init(const struct device *dev) +{ +#ifdef CONFIG_MULTITHREADING + struct zephyr_retained_mem_ram_data *data = dev->data; + + k_mutex_init(&data->lock); +#endif + + return 0; +} + +static ssize_t zephyr_retained_mem_ram_size(const struct device *dev) +{ + const struct zephyr_retained_mem_ram_config *config = dev->config; + + return (ssize_t)config->size; +} + +static int zephyr_retained_mem_ram_read(const struct device *dev, off_t offset, uint8_t *buffer, + size_t size) +{ + const struct zephyr_retained_mem_ram_config *config = dev->config; + + zephyr_retained_mem_ram_lock_take(dev); + + memcpy(buffer, (config->address + offset), size); + + zephyr_retained_mem_ram_lock_release(dev); + + return 0; +} + +static int zephyr_retained_mem_ram_write(const struct device *dev, off_t offset, + const uint8_t *buffer, size_t size) +{ + const struct zephyr_retained_mem_ram_config *config = dev->config; + + zephyr_retained_mem_ram_lock_take(dev); + + memcpy((config->address + offset), buffer, size); + + zephyr_retained_mem_ram_lock_release(dev); + + return 0; +} + +static int zephyr_retained_mem_ram_clear(const struct device *dev) +{ + const struct zephyr_retained_mem_ram_config *config = dev->config; + + zephyr_retained_mem_ram_lock_take(dev); + + memset(config->address, 0, config->size); + + zephyr_retained_mem_ram_lock_release(dev); + + return 0; +} + +static const struct retained_mem_driver_api zephyr_retained_mem_ram_api = { + .size = zephyr_retained_mem_ram_size, + .read = zephyr_retained_mem_ram_read, + .write = zephyr_retained_mem_ram_write, + .clear = zephyr_retained_mem_ram_clear, +}; + +#define ZEPHYR_RETAINED_MEM_RAM_DEVICE(inst) \ + IF_ENABLED(CONFIG_MULTITHREADING, \ + (static struct zephyr_retained_mem_ram_data \ + zephyr_retained_mem_ram_data_##inst;) \ + ) \ + static const struct zephyr_retained_mem_ram_config \ + zephyr_retained_mem_ram_config_##inst = { \ + .address = (uint8_t *)DT_REG_ADDR(DT_PARENT(DT_INST(inst, DT_DRV_COMPAT))), \ + .size = DT_REG_SIZE(DT_PARENT(DT_INST(inst, DT_DRV_COMPAT))), \ + }; \ + DEVICE_DT_INST_DEFINE(inst, \ + &zephyr_retained_mem_ram_init, \ + NULL, \ + COND_CODE_1(CONFIG_MULTITHREADING, \ + (&zephyr_retained_mem_ram_data_##inst), (NULL) \ + ), \ + &zephyr_retained_mem_ram_config_##inst, \ + POST_KERNEL, \ + CONFIG_RETAINED_MEM_INIT_PRIORITY, \ + &zephyr_retained_mem_ram_api); + +DT_INST_FOREACH_STATUS_OKAY(ZEPHYR_RETAINED_MEM_RAM_DEVICE) diff --git a/dts/bindings/retained_mem/zephyr,retained-ram.yaml b/dts/bindings/retained_mem/zephyr,retained-ram.yaml new file mode 100644 index 000000000000..4a543304d851 --- /dev/null +++ b/dts/bindings/retained_mem/zephyr,retained-ram.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: Unitialised RAM-based retained memory area. + +compatible: "zephyr,retained-ram" + +include: base.yaml From 1abeb6df8dc0aae0f515056fadce9239897d852c Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 23 Feb 2023 09:29:43 +0000 Subject: [PATCH 0469/1906] tests: drivers: Add API test for retained_mem Adds a test for the retained memory driver interface using GPREGRET and RAM backends for the nrf52840dk_nrf52840 board and RAM backend for qemu_cortex_m3 board. Signed-off-by: Jamie McCrae --- tests/drivers/retained_mem/api/CMakeLists.txt | 12 +++ tests/drivers/retained_mem/api/Kconfig | 14 ++++ .../api/boards/nrf52840dk_nrf52840.conf | 1 + .../api/boards/nrf52840dk_nrf52840.overlay | 5 ++ .../api/boards/nrf52840dk_nrf52840_ram.conf | 1 + .../boards/nrf52840dk_nrf52840_ram.overlay | 29 +++++++ .../api/boards/qemu_cortex_m3.overlay | 23 ++++++ tests/drivers/retained_mem/api/prj.conf | 3 + tests/drivers/retained_mem/api/src/main.c | 80 +++++++++++++++++++ tests/drivers/retained_mem/api/testcase.yaml | 12 +++ 10 files changed, 180 insertions(+) create mode 100644 tests/drivers/retained_mem/api/CMakeLists.txt create mode 100644 tests/drivers/retained_mem/api/Kconfig create mode 100644 tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840.conf create mode 100644 tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840.overlay create mode 100644 tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840_ram.conf create mode 100644 tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840_ram.overlay create mode 100644 tests/drivers/retained_mem/api/boards/qemu_cortex_m3.overlay create mode 100644 tests/drivers/retained_mem/api/prj.conf create mode 100644 tests/drivers/retained_mem/api/src/main.c create mode 100644 tests/drivers/retained_mem/api/testcase.yaml diff --git a/tests/drivers/retained_mem/api/CMakeLists.txt b/tests/drivers/retained_mem/api/CMakeLists.txt new file mode 100644 index 000000000000..014c1ce52b5f --- /dev/null +++ b/tests/drivers/retained_mem/api/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (c) 2023 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(retained_mem_api) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/drivers/retained_mem/api/Kconfig b/tests/drivers/retained_mem/api/Kconfig new file mode 100644 index 000000000000..1da006176ee8 --- /dev/null +++ b/tests/drivers/retained_mem/api/Kconfig @@ -0,0 +1,14 @@ +# +# Copyright (c) 2023, Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# + +mainmenu "Retained memory test" + +config RETAINED_MEM_SIZE_LIMITED + bool "Size limited test" + help + Will limit data size for test to 1 byte instead of 10 bytes + +source "Kconfig.zephyr" diff --git a/tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840.conf b/tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840.conf new file mode 100644 index 000000000000..5770598b8fc4 --- /dev/null +++ b/tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840.conf @@ -0,0 +1 @@ +CONFIG_RETAINED_MEM_SIZE_LIMITED=y diff --git a/tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840.overlay b/tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840.overlay new file mode 100644 index 000000000000..308976c0d92e --- /dev/null +++ b/tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840.overlay @@ -0,0 +1,5 @@ +/ { + aliases { + retainedmemtestdevice = &gpregret1; + }; +}; diff --git a/tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840_ram.conf b/tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840_ram.conf new file mode 100644 index 000000000000..4c12994e097f --- /dev/null +++ b/tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840_ram.conf @@ -0,0 +1 @@ +CONFIG_RETAINED_MEM_NRF_GPREGRET=n diff --git a/tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840_ram.overlay b/tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840_ram.overlay new file mode 100644 index 000000000000..c46497e2cb68 --- /dev/null +++ b/tests/drivers/retained_mem/api/boards/nrf52840dk_nrf52840_ram.overlay @@ -0,0 +1,29 @@ +/ { + sram@2003FFE0 { + compatible = "zephyr,memory-region", "mmio-sram"; + reg = <0x2003FFE0 0x20>; + zephyr,memory-region = "RetainedMem"; + status = "okay"; + + retainedmem0: retainedmem { + compatible = "zephyr,retained-ram"; + status = "okay"; + }; + }; + + aliases { + retainedmemtestdevice = &retainedmem0; + }; +}; + +&gpregret1 { + status = "disabled"; +}; + +&gpregret2 { + status = "disabled"; +}; + +&sram0 { + reg = <0x20000000 DT_SIZE_K(252)>; +}; diff --git a/tests/drivers/retained_mem/api/boards/qemu_cortex_m3.overlay b/tests/drivers/retained_mem/api/boards/qemu_cortex_m3.overlay new file mode 100644 index 000000000000..7ec47a07409f --- /dev/null +++ b/tests/drivers/retained_mem/api/boards/qemu_cortex_m3.overlay @@ -0,0 +1,23 @@ +#include + +/ { + sram@2000FFE0 { + compatible = "zephyr,memory-region", "mmio-sram"; + reg = <0x2000FFE0 0x20>; + zephyr,memory-region = "Retention"; + status = "okay"; + + retainedmem0: retainedmem { + compatible = "zephyr,retained-ram"; + status = "okay"; + }; + }; + + aliases { + retainedmemtestdevice = &retainedmem0; + }; +}; + +&sram0 { + reg = <0x20000000 DT_SIZE_K(60)>; +}; diff --git a/tests/drivers/retained_mem/api/prj.conf b/tests/drivers/retained_mem/api/prj.conf new file mode 100644 index 000000000000..bc2d8751acb3 --- /dev/null +++ b/tests/drivers/retained_mem/api/prj.conf @@ -0,0 +1,3 @@ +CONFIG_RETAINED_MEM=y +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y diff --git a/tests/drivers/retained_mem/api/src/main.c b/tests/drivers/retained_mem/api/src/main.c new file mode 100644 index 000000000000..1567e77a82d6 --- /dev/null +++ b/tests/drivers/retained_mem/api/src/main.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2023, Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include + +const static struct device *retained_mem_test_device = DEVICE_DT_GET(DT_ALIAS( + retainedmemtestdevice)); + +#if CONFIG_RETAINED_MEM_SIZE_LIMITED +/* For size-limited tests, use data size of 1 byte */ +static uint8_t data[1] = { + 0x5b, +}; +static uint8_t empty_data[1] = { + 0x00, +}; +static uint8_t buffer[1]; +#else +/* For other devices, use data size of 10 bytes */ +static uint8_t data[10] = { + 0x23, 0x82, 0xa8, 0x7b, 0xde, 0x18, 0x00, 0xff, 0x8e, 0xd6, +}; +static uint8_t empty_data[10] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +static uint8_t buffer[10]; +#endif + +ZTEST(retained_mem_api, test_read_write) +{ + int32_t rc; + + rc = retained_mem_write(retained_mem_test_device, 0, data, sizeof(data)); + zassert_equal(rc, 0, "Return code should be success"); + + memset(buffer, 0, sizeof(buffer)); + + rc = retained_mem_read(retained_mem_test_device, 0, buffer, sizeof(buffer)); + zassert_equal(rc, 0, "Return code should be success"); + + zassert_mem_equal(data, buffer, sizeof(data), "Expected written data to match"); +} + +ZTEST(retained_mem_api, test_size) +{ + int32_t rc; + + rc = retained_mem_size(retained_mem_test_device); + zassume_between_inclusive(rc, 1, 0x4000, "Retained memory size is not valid"); +} + +ZTEST(retained_mem_api, test_clear) +{ + int32_t rc; + + rc = retained_mem_clear(retained_mem_test_device); + zassert_equal(rc, 0, "Return code should be success"); + + rc = retained_mem_write(retained_mem_test_device, 0, data, sizeof(data)); + zassert_equal(rc, 0, "Return code should be success"); + + rc = retained_mem_read(retained_mem_test_device, 0, buffer, sizeof(buffer)); + zassert_equal(rc, 0, "Return code should be success"); + + zassert_mem_equal(data, buffer, sizeof(data), "Expected written data to match"); + + rc = retained_mem_clear(retained_mem_test_device); + zassert_equal(rc, 0, "Return code should be success"); + + rc = retained_mem_read(retained_mem_test_device, 0, buffer, sizeof(buffer)); + zassert_equal(rc, 0, "Return code should be success"); + + zassert_mem_equal(empty_data, buffer, sizeof(empty_data), "Expected data to be 0x00's"); +} + +ZTEST_SUITE(retained_mem_api, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/drivers/retained_mem/api/testcase.yaml b/tests/drivers/retained_mem/api/testcase.yaml new file mode 100644 index 000000000000..704199758e4a --- /dev/null +++ b/tests/drivers/retained_mem/api/testcase.yaml @@ -0,0 +1,12 @@ +tests: + drivers.retained_mem.api.gpregret: + platform_allow: nrf52840dk_nrf52840 + tags: drivers retained_mem + drivers.retained_mem.api.ram: + platform_allow: qemu_cortex_m3 + tags: drivers retained_mem + drivers.retained_mem.api.ram.nrf52840dk_nrf52840: + platform_allow: nrf52840dk_nrf52840 + extra_args: DTC_OVERLAY_FILE="boards/nrf52840dk_nrf52840_ram.overlay" + OVERLAY_CONFIG="boards/nrf52840dk_nrf52840_ram.conf" + tags: drivers retained_mem From 44a7a75b193dac8a9c206864ccfe0a17f804d51e Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 23 Feb 2023 09:33:16 +0000 Subject: [PATCH 0470/1906] doc: release: 3.4: Add retained_mem driver Adds details on the new retained memory driver. Signed-off-by: Jamie McCrae --- doc/releases/release-notes-3.4.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/releases/release-notes-3.4.rst b/doc/releases/release-notes-3.4.rst index 82ae508eea24..6eb9c1622c0c 100644 --- a/doc/releases/release-notes-3.4.rst +++ b/doc/releases/release-notes-3.4.rst @@ -313,6 +313,11 @@ Drivers and Sensors * PECI +* Retained memory + + * Retained memory (retained_mem) driver has been added with backends for + Nordic nRF GPREGRET, and uninitialised RAM. + Trusted Firmware-M ****************** * Pin control From 02059bc692220b2a5e5b35231594e7be7b1da3ba Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 23 Feb 2023 10:27:21 +0000 Subject: [PATCH 0471/1906] MAINTAINERS: Add retained memory section and assign to self Adds an entry for the retained memory area and assign myself to it. Signed-off-by: Jamie McCrae --- MAINTAINERS.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index a94592f0811c..742c106acaea 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -1073,6 +1073,18 @@ Release Notes: labels: - "area: Regulators" +"Drivers: Retained Memory": + status: maintained + maintainers: + - nordicjm + files: + - drivers/retained_mem/ + - dts/bindings/retained_mem/ + - include/zephyr/drivers/retained_mem.h + - tests/drivers/retained_mem/ + labels: + - "area: Retained Memory" + "Drivers: PCI": status: maintained maintainers: From 69cb35e3acc8df77c00fdd0a20157274ed38eac5 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 27 Feb 2023 08:21:17 +0000 Subject: [PATCH 0472/1906] doc: Add retained memory API and mark as experimental Adds the the retained memory API to the list and marks it as experimental. Signed-off-by: Jamie McCrae --- doc/develop/api/overview.rst | 4 ++++ doc/hardware/peripherals/index.rst | 1 + doc/hardware/peripherals/retained_mem.rst | 24 +++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 doc/hardware/peripherals/retained_mem.rst diff --git a/doc/develop/api/overview.rst b/doc/develop/api/overview.rst index b3c024833658..7cdf1b6bdde2 100644 --- a/doc/develop/api/overview.rst +++ b/doc/develop/api/overview.rst @@ -237,6 +237,10 @@ between major releases are available in the :ref:`zephyr_release_notes`. - Experimental - 2.4 + * - :ref:`retained_mem_api` + - Experimental + - 3.4 + * - :ref:`reset_api` - Experimental - 3.1 diff --git a/doc/hardware/peripherals/index.rst b/doc/hardware/peripherals/index.rst index 8d860cc2c94d..136044246a88 100644 --- a/doc/hardware/peripherals/index.rst +++ b/doc/hardware/peripherals/index.rst @@ -34,6 +34,7 @@ Peripherals ps2.rst peci.rst regulators.rst + retained_mem.rst reset.rst rtc.rst sdhc.rst diff --git a/doc/hardware/peripherals/retained_mem.rst b/doc/hardware/peripherals/retained_mem.rst new file mode 100644 index 000000000000..a346c2e9f7bc --- /dev/null +++ b/doc/hardware/peripherals/retained_mem.rst @@ -0,0 +1,24 @@ +.. _retained_mem_api: + +Retained memory +############### + +Overview +******** + +The retained memory driver API provides a way of reading from/writing to memory +areas whereby the contents of the memory is retained whilst the device is +powered (data may be lost in low power modes). + +Configuration Options +********************* + +Related configuration options: + +* :kconfig:option:`CONFIG_RETAINED_MEM` +* :kconfig:option:`CONFIG_RETAINED_MEM_INIT_PRIORITY` + +API Reference +************* + +.. doxygengroup:: retained_mem_interface From 417d704b86503132a577840874be52d10f7d7fc7 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 27 Feb 2023 09:24:58 +0000 Subject: [PATCH 0473/1906] soc: arm: nordic: Add GPREGRET register validation Adds validation for Nordic nRF GPREGRET registers. Signed-off-by: Jamie McCrae --- soc/arm/nordic_nrf/validate_base_addresses.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/soc/arm/nordic_nrf/validate_base_addresses.c b/soc/arm/nordic_nrf/validate_base_addresses.c index 153301441bef..58aaa5a75134 100644 --- a/soc/arm/nordic_nrf/validate_base_addresses.c +++ b/soc/arm/nordic_nrf/validate_base_addresses.c @@ -60,6 +60,16 @@ #define NRF_WDT0 NRF_WDT #endif +#if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF52X) +#if !defined(NRF_POWER_GPREGRET1) && defined(NRF_POWER_BASE) +#define NRF_POWER_GPREGRET1 (0x51c + NRF_POWER_BASE) +#endif + +#if !defined(NRF_POWER_GPREGRET2) && defined(NRF_POWER_BASE) +#define NRF_POWER_GPREGRET2 (0x520 + NRF_POWER_BASE) +#endif +#endif + /** * Check that a devicetree node's "reg" base address matches the * correct value from the MDK. @@ -189,3 +199,9 @@ CHECK_DT_REG(vmc, NRF_VMC); CHECK_DT_REG(wdt, NRF_WDT0); /* this should be the same node as wdt0 */ CHECK_DT_REG(wdt0, NRF_WDT0); CHECK_DT_REG(wdt1, NRF_WDT1); + +/* nRF51/nRF52-specific addresses */ +#if defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF52X) +CHECK_DT_REG(gpregret1, NRF_POWER_GPREGRET1); +CHECK_DT_REG(gpregret2, NRF_POWER_GPREGRET2); +#endif From 356700709924560e3a422045e6c1e69f56aade3b Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Mon, 20 Mar 2023 10:33:17 +0100 Subject: [PATCH 0474/1906] samples: bluetooth: mesh: Fix bbc_microbit overlay Fixes mesh sample overlay for bbc_microbit introduced after https://github.com/zephyrproject-rtos/zephyr/pull/55927 Signed-off-by: Pavel Vasilyev --- .../bluetooth/mesh/boards/bbc_microbit.conf | 16 +++++++------ samples/bluetooth/mesh/prj.conf | 24 +++++++------------ 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/samples/bluetooth/mesh/boards/bbc_microbit.conf b/samples/bluetooth/mesh/boards/bbc_microbit.conf index afe8619c8b40..26fb05301c1c 100644 --- a/samples/bluetooth/mesh/boards/bbc_microbit.conf +++ b/samples/bluetooth/mesh/boards/bbc_microbit.conf @@ -9,23 +9,25 @@ CONFIG_GPIO=y CONFIG_PM=n -CONFIG_FLASH_PAGE_LAYOUT=y - +CONFIG_BT_PERIPHERAL=n +CONFIG_BT_EXT_ADV=n CONFIG_BT_RX_STACK_SIZE=1100 CONFIG_BT_BUF_EVT_RX_COUNT=3 CONFIG_BT_BUF_ACL_RX_COUNT=3 CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=3 -CONFIG_BT_EXT_ADV=n -CONFIG_BT_BROADCASTER=y - -CONFIG_BT_CTLR_LE_PING=n -CONFIG_BT_CTLR_CHAN_SEL_2=n CONFIG_BT_CTLR_ADV_EXT=n CONFIG_BT_MESH_ADV_BUF_COUNT=3 CONFIG_BT_MESH_SEG_BUFS=3 +CONFIG_BT_MESH_RELAY=n CONFIG_BT_MESH_LOOPBACK_BUFS=1 + +CONFIG_BT_MESH_PB_GATT=n +CONFIG_BT_MESH_GATT_PROXY=n +CONFIG_BT_MESH_MODEL_EXTENSIONS=n +CONFIG_BT_MESH_FRIEND=n + CONFIG_BT_MESH_SUBNET_COUNT=1 CONFIG_BT_MESH_APP_KEY_COUNT=1 CONFIG_BT_MESH_MODEL_GROUP_COUNT=1 diff --git a/samples/bluetooth/mesh/prj.conf b/samples/bluetooth/mesh/prj.conf index 83a38ef3c893..cd8819616be4 100644 --- a/samples/bluetooth/mesh/prj.conf +++ b/samples/bluetooth/mesh/prj.conf @@ -7,19 +7,21 @@ CONFIG_NVS=y CONFIG_SETTINGS=y CONFIG_HWINFO=y +CONFIG_BT=y +CONFIG_BT_TINYCRYPT_ECC=y +CONFIG_BT_L2CAP_TX_BUF_COUNT=5 +CONFIG_BT_PERIPHERAL=y CONFIG_BT_OBSERVER=y +CONFIG_BT_BROADCASTER=y + CONFIG_BT_CTLR_DUP_FILTER_LEN=0 CONFIG_BT_CTLR_LE_ENC=n +CONFIG_BT_CTLR_LE_PING=n CONFIG_BT_DATA_LEN_UPDATE=n CONFIG_BT_PHY_UPDATE=n CONFIG_BT_CTLR_MIN_USED_CHAN=n CONFIG_BT_CTLR_PRIVACY=n - -CONFIG_BT_PERIPHERAL=y - -CONFIG_BT=y -CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_L2CAP_TX_BUF_COUNT=5 +CONFIG_BT_CTLR_CHAN_SEL_2=n CONFIG_BT_MESH=y CONFIG_BT_MESH_MODEL_EXTENSIONS=y @@ -29,17 +31,7 @@ CONFIG_BT_MESH_PB_GATT=y CONFIG_BT_MESH_PB_ADV=y CONFIG_BT_MESH_GATT_PROXY=y -#CONFIG_BT_MESH_LOW_POWER=y -#CONFIG_BT_MESH_LPN_SCAN_LATENCY=30 -#CONFIG_BT_MESH_LPN_RECV_DELAY=40 -#CONFIG_BT_MESH_LPN_POLL_TIMEOUT=300 - CONFIG_BT_MESH_SUBNET_COUNT=2 CONFIG_BT_MESH_APP_KEY_COUNT=2 CONFIG_BT_MESH_MODEL_GROUP_COUNT=2 CONFIG_BT_MESH_LABEL_COUNT=3 - -CONFIG_BT_DEBUG_LOG=y - -CONFIG_BT_MESH_LOG_LEVEL_DBG=y -CONFIG_BT_MESH_MODEL_LOG_LEVEL_DBG=y From dba8d0c45f09714423aafb9c32e186f3cf276cc8 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Mon, 20 Mar 2023 10:43:15 +0100 Subject: [PATCH 0475/1906] samples: bluetooth: mesh_demo: Fix bbc_microbit overlay Return original configuration for bbc_microbit before this PR https://github.com/zephyrproject-rtos/zephyr/pull/55927 Signed-off-by: Pavel Vasilyev --- samples/bluetooth/mesh_demo/boards/bbc_microbit.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf b/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf index 385abb88be4d..6fc00e1b4212 100644 --- a/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf +++ b/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf @@ -7,7 +7,6 @@ CONFIG_MICROBIT_DISPLAY=y CONFIG_PWM=y CONFIG_PWM_NRF5_SW=y -CONFIG_BT_TINYCRYPT_ECC=n CONFIG_BT_RX_STACK_SIZE=1280 CONFIG_BT_CTLR_DUP_FILTER_LEN=0 CONFIG_BT_PHY_UPDATE=n @@ -20,3 +19,4 @@ CONFIG_BT_MESH_ADV_BUF_COUNT=3 CONFIG_BT_MESH_RELAY_BUF_COUNT=2 CONFIG_BT_MESH_MSG_CACHE_SIZE=2 CONFIG_BT_MESH_BEACON_ENABLED=n +CONFIG_BT_MESH_LABEL_COUNT=1 From f2d9b74da135bf0170dbe2109ad616543b9e529a Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Mon, 20 Mar 2023 11:08:34 +0100 Subject: [PATCH 0476/1906] tests bsim: Move common scripts one level up These scripts are common for bluetooth and other tests Let's move them one level up. Signed-off-by: Alberto Escolar Piedras --- .github/workflows/bluetooth-tests.yaml | 4 ++-- tests/bsim/{bluetooth => }/README.txt | 6 +++--- tests/bsim/bluetooth/_compile_permutate_kconfigs.sh | 2 +- tests/bsim/bluetooth/audio/compile.sh | 2 +- .../bluetooth/host/att/mtu_update/test_scripts/_compile.sh | 2 +- tests/bsim/bluetooth/host/compile.sh | 2 +- .../bond_overwrite_allowed/test_scripts/_compile.sh | 2 +- .../security/bond_overwrite_denied/test_scripts/_compile.sh | 2 +- tests/bsim/bluetooth/ll/compile.sh | 2 +- tests/bsim/bluetooth/ll/edtt/README.txt | 4 ++-- tests/bsim/bluetooth/mesh/compile.sh | 2 +- tests/bsim/{bluetooth => }/compile.sh | 2 +- tests/bsim/{bluetooth => }/compile.source | 2 +- tests/bsim/{bluetooth => }/run_parallel.sh | 0 tests/bsim/{bluetooth => }/sh_common.source | 0 15 files changed, 17 insertions(+), 17 deletions(-) rename tests/bsim/{bluetooth => }/README.txt (79%) rename tests/bsim/{bluetooth => }/compile.sh (93%) rename tests/bsim/{bluetooth => }/compile.source (97%) rename tests/bsim/{bluetooth => }/run_parallel.sh (100%) rename tests/bsim/{bluetooth => }/sh_common.source (100%) diff --git a/.github/workflows/bluetooth-tests.yaml b/.github/workflows/bluetooth-tests.yaml index 23f7f0e1610a..0d7df7eb2bd6 100644 --- a/.github/workflows/bluetooth-tests.yaml +++ b/.github/workflows/bluetooth-tests.yaml @@ -70,9 +70,9 @@ jobs: - name: Run Bluetooth Tests with BSIM run: | export ZEPHYR_BASE=${PWD} - WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/bluetooth/compile.sh + WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/compile.sh RESULTS_FILE=${ZEPHYR_BASE}/${bsim_bt_test_results_file} \ - SEARCH_PATH=tests/bsim/bluetooth/ tests/bsim/bluetooth/run_parallel.sh + SEARCH_PATH=tests/bsim/ tests/bsim/run_parallel.sh - name: Upload Test Results if: always() diff --git a/tests/bsim/bluetooth/README.txt b/tests/bsim/README.txt similarity index 79% rename from tests/bsim/bluetooth/README.txt rename to tests/bsim/README.txt index 9730170b0a85..3a177170ae9e 100644 --- a/tests/bsim/bluetooth/README.txt +++ b/tests/bsim/README.txt @@ -7,9 +7,9 @@ the needed images and execute these tests in batch. You can also run them manually if desired, but be sure to call them setting the variables they expect. For example, from Zephyr's root folder, you can run: -WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/bluetooth/compile.sh -RESULTS_FILE=${ZEPHYR_BASE}/myresults.xml SEARCH_PATH=tests/bsim/bluetooth tests/bsim/bluetooth/run_parallel.sh +WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/compile.sh +RESULTS_FILE=${ZEPHYR_BASE}/myresults.xml SEARCH_PATH=tests/bsim tests/bsim/run_parallel.sh Or to run only a specific subset, e.g. host advertising tests: WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/bluetooth/host/compile.sh -RESULTS_FILE=${ZEPHYR_BASE}/myresults.xml SEARCH_PATH=tests/bsim/bluetooth/host/adv tests/bsim/bluetooth/run_parallel.sh +RESULTS_FILE=${ZEPHYR_BASE}/myresults.xml SEARCH_PATH=tests/bsim/bluetooth/host/adv tests/bsim/run_parallel.sh diff --git a/tests/bsim/bluetooth/_compile_permutate_kconfigs.sh b/tests/bsim/bluetooth/_compile_permutate_kconfigs.sh index 61af911041fd..50260320e9df 100755 --- a/tests/bsim/bluetooth/_compile_permutate_kconfigs.sh +++ b/tests/bsim/bluetooth/_compile_permutate_kconfigs.sh @@ -21,7 +21,7 @@ BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source +source ${ZEPHYR_BASE}/tests/bsim/compile.source declare -a list=( diff --git a/tests/bsim/bluetooth/audio/compile.sh b/tests/bsim/bluetooth/audio/compile.sh index 62c06c3a45ad..a77799ea4771 100755 --- a/tests/bsim/bluetooth/audio/compile.sh +++ b/tests/bsim/bluetooth/audio/compile.sh @@ -18,7 +18,7 @@ BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source +source ${ZEPHYR_BASE}/tests/bsim/compile.source app=tests/bsim/bluetooth/audio compile diff --git a/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh index 282f454f30b5..d6498bd21211 100755 --- a/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh @@ -18,5 +18,5 @@ BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" INCR_BUILD=1 mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source +source ${ZEPHYR_BASE}/tests/bsim/compile.source app="tests/bsim/bluetooth/$test_name" compile diff --git a/tests/bsim/bluetooth/host/compile.sh b/tests/bsim/bluetooth/host/compile.sh index 6358ec2ce05e..eada545d8b5f 100755 --- a/tests/bsim/bluetooth/host/compile.sh +++ b/tests/bsim/bluetooth/host/compile.sh @@ -18,7 +18,7 @@ BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source +source ${ZEPHYR_BASE}/tests/bsim/compile.source app=tests/bsim/bluetooth/host/adv/resume compile app=tests/bsim/bluetooth/host/adv/resume conf_file=prj_2.conf compile diff --git a/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh index 8a431f173c60..33be3b19feb9 100755 --- a/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh @@ -18,5 +18,5 @@ BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" INCR_BUILD=1 mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source +source ${ZEPHYR_BASE}/tests/bsim/compile.source app="tests/bsim/bluetooth/$test_name" compile diff --git a/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh index 8a431f173c60..33be3b19feb9 100755 --- a/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh @@ -18,5 +18,5 @@ BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" INCR_BUILD=1 mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source +source ${ZEPHYR_BASE}/tests/bsim/compile.source app="tests/bsim/bluetooth/$test_name" compile diff --git a/tests/bsim/bluetooth/ll/compile.sh b/tests/bsim/bluetooth/ll/compile.sh index fcc361229564..8451406aa628 100755 --- a/tests/bsim/bluetooth/ll/compile.sh +++ b/tests/bsim/bluetooth/ll/compile.sh @@ -18,7 +18,7 @@ BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source +source ${ZEPHYR_BASE}/tests/bsim/compile.source app=tests/bsim/bluetooth/ll/advx compile diff --git a/tests/bsim/bluetooth/ll/edtt/README.txt b/tests/bsim/bluetooth/ll/edtt/README.txt index 104662dc4cad..249f224b3473 100644 --- a/tests/bsim/bluetooth/ll/edtt/README.txt +++ b/tests/bsim/bluetooth/ll/edtt/README.txt @@ -53,10 +53,10 @@ In short the whole process being: ``` cd ${ZEPHYR_BASE} && source zephyr-env.sh #Compile all apps: -WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/bluetooth/compile.sh +WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/bluetooth/ll/compile.sh #run all tests -RESULTS_FILE=${ZEPHYR_BASE}/banana.xml SEARCH_PATH=tests/bsim/bluetooth/ll/edtt/ tests/bsim/bluetooth/run_parallel.sh +RESULTS_FILE=${ZEPHYR_BASE}/banana.xml SEARCH_PATH=tests/bsim/bluetooth/ll/edtt/ tests/bsim/run_parallel.sh #or just run one set: tests/bsim/bluetooth/ll/edtt/tests_scripts/hci.sh diff --git a/tests/bsim/bluetooth/mesh/compile.sh b/tests/bsim/bluetooth/mesh/compile.sh index 635d84654548..d0c3f91f4bb5 100755 --- a/tests/bsim/bluetooth/mesh/compile.sh +++ b/tests/bsim/bluetooth/mesh/compile.sh @@ -18,7 +18,7 @@ BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bsim/bluetooth/compile.source +source ${ZEPHYR_BASE}/tests/bsim/compile.source app=tests/bsim/bluetooth/mesh compile app=tests/bsim/bluetooth/mesh conf_overlay=overlay_low_lat.conf compile diff --git a/tests/bsim/bluetooth/compile.sh b/tests/bsim/compile.sh similarity index 93% rename from tests/bsim/bluetooth/compile.sh rename to tests/bsim/compile.sh index eceee81e5efb..39e07d1313df 100755 --- a/tests/bsim/bluetooth/compile.sh +++ b/tests/bsim/compile.sh @@ -18,7 +18,7 @@ BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bsim/bluetooth/sh_common.source +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/audio/compile.sh run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/host/compile.sh diff --git a/tests/bsim/bluetooth/compile.source b/tests/bsim/compile.source similarity index 97% rename from tests/bsim/bluetooth/compile.source rename to tests/bsim/compile.source index cc54fb6bddc8..1f8673c4973f 100644 --- a/tests/bsim/bluetooth/compile.source +++ b/tests/bsim/compile.source @@ -1,7 +1,7 @@ # Copyright 2018 Oticon A/S # SPDX-License-Identifier: Apache-2.0 -source ${ZEPHYR_BASE}/tests/bsim/bluetooth/sh_common.source +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source function print_error_info(){ echo -e "\033[0;31mFailure building ${app} ${conf_file} for ${BOARD}\033[0m\n\ diff --git a/tests/bsim/bluetooth/run_parallel.sh b/tests/bsim/run_parallel.sh similarity index 100% rename from tests/bsim/bluetooth/run_parallel.sh rename to tests/bsim/run_parallel.sh diff --git a/tests/bsim/bluetooth/sh_common.source b/tests/bsim/sh_common.source similarity index 100% rename from tests/bsim/bluetooth/sh_common.source rename to tests/bsim/sh_common.source From 4235028ab3f4cf678acbe115fe34fc915b6018aa Mon Sep 17 00:00:00 2001 From: Emilio Benavente Date: Fri, 3 Mar 2023 15:54:48 -0600 Subject: [PATCH 0477/1906] boards: arm: mimxrt1024_evk: Added flexpwm pinctrl Added pinctrl for FlexPWM on the mimxrt1024 Since there is a possible collision with the ADC driver I have added the devicetree pixmux example in an overlay file to still demonstrate how to structure the pwm. Signed-off-by: Emilio Benavente --- boards/arm/mimxrt1024_evk/mimxrt1024_evk-pinctrl.dtsi | 10 ++++++++++ .../drivers/pwm/pwm_api/boards/mimxrt1024_evk.overlay | 11 +++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/drivers/pwm/pwm_api/boards/mimxrt1024_evk.overlay diff --git a/boards/arm/mimxrt1024_evk/mimxrt1024_evk-pinctrl.dtsi b/boards/arm/mimxrt1024_evk/mimxrt1024_evk-pinctrl.dtsi index 60cf68d6a3fb..3e27286cc234 100644 --- a/boards/arm/mimxrt1024_evk/mimxrt1024_evk-pinctrl.dtsi +++ b/boards/arm/mimxrt1024_evk/mimxrt1024_evk-pinctrl.dtsi @@ -305,5 +305,15 @@ }; }; + pinmux_flexpwm1: pinmux_flexpwm1 { + group0 { + pinmux = <&iomuxc_gpio_ad_b1_10_flexpwm1_pwma2>; + drive-strength = "r0-4"; + bias-pull-up; + bias-pull-up-value = "47k"; + slew-rate = "slow"; + nxp,speed = "100-mhz"; + }; + }; }; diff --git a/tests/drivers/pwm/pwm_api/boards/mimxrt1024_evk.overlay b/tests/drivers/pwm/pwm_api/boards/mimxrt1024_evk.overlay new file mode 100644 index 000000000000..67da45681e29 --- /dev/null +++ b/tests/drivers/pwm/pwm_api/boards/mimxrt1024_evk.overlay @@ -0,0 +1,11 @@ +/ { + aliases { + pwm-0 = &flexpwm1_pwm2; + }; +}; + +&flexpwm1_pwm2 { + pinctrl-0 = <&pinmux_flexpwm1>; + pinctrl-names = "default"; + status = "okay"; +}; From 89ef7614f36c4e43762a9d6c5387a74bbd71a796 Mon Sep 17 00:00:00 2001 From: Emilio Benavente Date: Fri, 3 Mar 2023 13:21:50 -0600 Subject: [PATCH 0478/1906] boards: arm: mimxrt1024_evk: Added FlexPWM Docs Documented the FlexPWM pins for the mimxrt1024_evk Signed-off-by: Emilio Benavente --- boards/arm/mimxrt1024_evk/doc/index.rst | 2 ++ boards/arm/mimxrt1024_evk/mimxrt1024_evk.yaml | 1 + 2 files changed, 3 insertions(+) diff --git a/boards/arm/mimxrt1024_evk/doc/index.rst b/boards/arm/mimxrt1024_evk/doc/index.rst index b957a014113f..b1dcdf9b940e 100644 --- a/boards/arm/mimxrt1024_evk/doc/index.rst +++ b/boards/arm/mimxrt1024_evk/doc/index.rst @@ -168,6 +168,8 @@ The MIMXRT1024 SoC has five pairs of pinmux/gpio controllers. +---------------+-----------------+---------------------------+ | GPIO_AD_B1_10 | ADC1 | ADC1 Channel 10 | +---------------+-----------------+---------------------------+ +| GPIO_AD_B1_10 | FLEXPWM1 | FLEXPWM1 Channel A2 | ++---------------+-----------------+---------------------------+ System Clock ============ diff --git a/boards/arm/mimxrt1024_evk/mimxrt1024_evk.yaml b/boards/arm/mimxrt1024_evk/mimxrt1024_evk.yaml index 90451be71e65..0305793dd0d2 100644 --- a/boards/arm/mimxrt1024_evk/mimxrt1024_evk.yaml +++ b/boards/arm/mimxrt1024_evk/mimxrt1024_evk.yaml @@ -24,3 +24,4 @@ supported: - sdhc - adc - usb_device + - pwm From 2e7c02bef620ad0e0f6d0c5bdb1ace0ce120c9cf Mon Sep 17 00:00:00 2001 From: Sebastian Panceac Date: Wed, 21 Sep 2022 18:57:36 +0300 Subject: [PATCH 0479/1906] Bluetooth: pairing: OOB: Separate LE SC OOB from legacy OOB logic Some systems can support only legacy OOB pairing while others only LE SC OOB pairing. The existent API function "bt_set_oob_data_flag" was removed. Two new API functions were added: * "bt_le_oob_set_legacy_flag" to signal that legacy OOB pairing is used * "bt_le_oob_set_sc_flag" to signal that LE SC OOB pairing is used The code will now advertise the presence of OOB flag depending on the type of pairing method(SC vs legacy) Signed-off-by: Sebastian Panceac --- doc/releases/release-notes-3.4.rst | 4 ++++ include/zephyr/bluetooth/conn.h | 18 ++++++++++----- subsys/bluetooth/host/smp.c | 33 ++++++++++++++++++++++------ subsys/bluetooth/shell/bt.c | 6 ++--- tests/bluetooth/tester/src/btp_gap.c | 4 ++-- 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/doc/releases/release-notes-3.4.rst b/doc/releases/release-notes-3.4.rst index 6eb9c1622c0c..02229e81e07e 100644 --- a/doc/releases/release-notes-3.4.rst +++ b/doc/releases/release-notes-3.4.rst @@ -126,6 +126,10 @@ Deprecated in this release Stable API changes in this release ================================== +* Removed `bt_set_oob_data_flag` and replaced it with two new API calls: + * :c:func:`bt_le_oob_set_sc_flag` for setting/clearing OOB flag in SC pairing + * :c:func:`bt_le_oob_set_legacy_flag` for setting/clearing OOB flag in legacy paring + New APIs in this release ======================== diff --git a/include/zephyr/bluetooth/conn.h b/include/zephyr/bluetooth/conn.h index a3316e9803b4..dd0c1f8f182c 100644 --- a/include/zephyr/bluetooth/conn.h +++ b/include/zephyr/bluetooth/conn.h @@ -1046,15 +1046,21 @@ void bt_conn_cb_register(struct bt_conn_cb *cb); */ void bt_set_bondable(bool enable); -/** @brief Allow/disallow remote OOB data to be used for pairing. +/** @brief Allow/disallow remote LE SC OOB data to be used for pairing. * - * Set/clear the OOB data flag for SMP Pairing Request/Response data. - * The initial value of this flag depends on BT_OOB_DATA_PRESENT Kconfig - * setting. + * Set/clear the OOB data flag for LE SC SMP Pairing Request/Response data. * - * @param enable Value allowing/disallowing remote OOB data. + * @param enable Value allowing/disallowing remote LE SC OOB data. */ -void bt_set_oob_data_flag(bool enable); +void bt_le_oob_set_sc_flag(bool enable); + +/** @brief Allow/disallow remote legacy OOB data to be used for pairing. + * + * Set/clear the OOB data flag for legacy SMP Pairing Request/Response data. + * + * @param enable Value allowing/disallowing remote legacy OOB data. + */ +void bt_le_oob_set_legacy_flag(bool enable); /** @brief Set OOB Temporary Key to be used for pairing * diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 43417ef06b49..31a9134c7ea2 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -277,7 +277,8 @@ static struct bt_smp_br bt_smp_br_pool[CONFIG_BT_MAX_CONN]; static struct bt_smp bt_smp_pool[CONFIG_BT_MAX_CONN]; static bool bondable = IS_ENABLED(CONFIG_BT_BONDABLE); -static bool oobd_present; +static bool sc_oobd_present; +static bool legacy_oobd_present; static bool sc_supported; static const uint8_t *sc_public_key; static K_SEM_DEFINE(sc_local_pkey_ready, 0, 1); @@ -2555,9 +2556,14 @@ void bt_set_bondable(bool enable) bondable = enable; } -void bt_set_oob_data_flag(bool enable) +void bt_le_oob_set_sc_flag(bool enable) { - oobd_present = enable; + sc_oobd_present = enable; +} + +void bt_le_oob_set_legacy_flag(bool enable) +{ + legacy_oobd_present = enable; } static uint8_t get_auth(struct bt_smp *smp, uint8_t auth) @@ -2860,8 +2866,6 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf) rsp->auth_req = get_auth(smp, req->auth_req); rsp->io_capability = get_io_capa(smp); - rsp->oob_flag = oobd_present ? BT_SMP_OOB_PRESENT : - BT_SMP_OOB_NOT_PRESENT; rsp->max_key_size = BT_SMP_MAX_ENC_KEY_SIZE; rsp->init_key_dist = (req->init_key_dist & RECV_KEYS); rsp->resp_key_dist = (req->resp_key_dist & SEND_KEYS); @@ -2874,6 +2878,14 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf) rsp->resp_key_dist &= SEND_KEYS_SC; } + if (atomic_test_bit(smp->flags, SMP_FLAG_SC)) { + rsp->oob_flag = sc_oobd_present ? BT_SMP_OOB_PRESENT : + BT_SMP_OOB_NOT_PRESENT; + } else { + rsp->oob_flag = legacy_oobd_present ? BT_SMP_OOB_PRESENT : + BT_SMP_OOB_NOT_PRESENT; + } + if ((rsp->auth_req & BT_SMP_AUTH_CT2) && (req->auth_req & BT_SMP_AUTH_CT2)) { atomic_set_bit(smp->flags, SMP_FLAG_CT2); @@ -3039,8 +3051,15 @@ static int smp_send_pairing_req(struct bt_conn *conn) req->auth_req = get_auth(smp, BT_SMP_AUTH_DEFAULT); req->io_capability = get_io_capa(smp); - req->oob_flag = oobd_present ? BT_SMP_OOB_PRESENT : - BT_SMP_OOB_NOT_PRESENT; + + if (req->auth_req & BT_SMP_AUTH_SC) { + req->oob_flag = sc_oobd_present ? BT_SMP_OOB_PRESENT : + BT_SMP_OOB_NOT_PRESENT; + } else { + req->oob_flag = legacy_oobd_present ? BT_SMP_OOB_PRESENT : + BT_SMP_OOB_NOT_PRESENT; + } + req->max_key_size = BT_SMP_MAX_ENC_KEY_SIZE; if (req->auth_req & BT_SMP_AUTH_BONDING) { diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index 5644bf08242f..b52d30d1d28a 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -721,7 +721,7 @@ static void bt_ready(int err) } if (IS_ENABLED(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY)) { - bt_set_oob_data_flag(true); + bt_le_oob_set_legacy_flag(true); } #if defined(CONFIG_BT_OBSERVER) @@ -2836,7 +2836,7 @@ static int cmd_oob_remote(const struct shell *sh, size_t argc, sizeof(oob_remote.le_sc_data.r)); hex2bin(argv[4], strlen(argv[4]), oob_remote.le_sc_data.c, sizeof(oob_remote.le_sc_data.c)); - bt_set_oob_data_flag(true); + bt_le_oob_set_sc_flag(true); } else { shell_help(sh); return -ENOEXEC; @@ -2848,7 +2848,7 @@ static int cmd_oob_remote(const struct shell *sh, size_t argc, static int cmd_oob_clear(const struct shell *sh, size_t argc, char *argv[]) { memset(&oob_remote, 0, sizeof(oob_remote)); - bt_set_oob_data_flag(false); + bt_le_oob_set_sc_flag(false); return 0; } diff --git a/tests/bluetooth/tester/src/btp_gap.c b/tests/bluetooth/tester/src/btp_gap.c index dbd409cd339f..e7a3973b05f5 100644 --- a/tests/bluetooth/tester/src/btp_gap.c +++ b/tests/bluetooth/tester/src/btp_gap.c @@ -429,7 +429,7 @@ static uint8_t set_oob_sc_remote_data(const void *cmd, uint16_t cmd_len, const struct btp_gap_oob_sc_set_remote_data_cmd *cp = cmd; cb.oob_data_request = oob_data_request; - bt_set_oob_data_flag(true); + bt_le_oob_set_sc_flag(true); /* Note that the .addr field * will be set by the oob_data_request callback @@ -1183,7 +1183,7 @@ static uint8_t set_oob_legacy_data(const void *cmd, uint16_t cmd_len, memcpy(oob_legacy_tk, cp->oob_data, 16); - bt_set_oob_data_flag(true); + bt_le_oob_set_legacy_flag(true); cb.oob_data_request = oob_data_request; return BTP_STATUS_SUCCESS; From a2dd232410a8aafad780d27fd5f011dae1a80a6b Mon Sep 17 00:00:00 2001 From: Hein Wessels Date: Fri, 27 Jan 2023 09:51:23 +0100 Subject: [PATCH 0480/1906] drivers: adc: stm32: dma support Sampling multiple adc channels at once using dma Only verified to be working on nucleo_h743zi Signed-off-by: Hein Wessels --- drivers/adc/Kconfig.stm32 | 15 ++- drivers/adc/adc_stm32.c | 245 +++++++++++++++++++++++++++++++++++++- 2 files changed, 253 insertions(+), 7 deletions(-) diff --git a/drivers/adc/Kconfig.stm32 b/drivers/adc/Kconfig.stm32 index 1998f051b584..3752ea0af67f 100644 --- a/drivers/adc/Kconfig.stm32 +++ b/drivers/adc/Kconfig.stm32 @@ -4,6 +4,7 @@ # Copyright (c) 2019 Endre Karlson # Copyright (c) 2019 Song Qiang # Copyright (c) 2021 Marius Scholtz, RIC Electronics +# Copyright (c) 2022 Hein Wessels, Nobleo Technology # SPDX-License-Identifier: Apache-2.0 config ADC_STM32 @@ -13,12 +14,24 @@ config ADC_STM32 help Enable the driver implementation for the stm32xx ADC +if ADC_STM32 + +config ADC_STM32_DMA + bool "STM32 MCU ADC DMA Support" + select DMA + help + Enable the ADC DMA mode for ADC instances + that enable dma channels in their device tree node. + if SOC_SERIES_STM32F2X || SOC_SERIES_STM32F4X || SOC_SERIES_STM32F7X || SOC_SERIES_STM32G4X config ADC_STM32_SHARED_IRQS bool "STM32 ADC shared interrupts" default y - depends on ADC_STM32 + depends on ADC_STM32 && !ADC_STM32_DMA help Enable the use of shared interrupts for families that only have a single interrupt for all ADC's + +endif + endif diff --git a/drivers/adc/adc_stm32.c b/drivers/adc/adc_stm32.c index 5273fdb6bed5..df57613020f0 100644 --- a/drivers/adc/adc_stm32.c +++ b/drivers/adc/adc_stm32.c @@ -24,6 +24,13 @@ #include #endif /* CONFIG_SOC_SERIES_STM32U5X */ +#ifdef CONFIG_ADC_STM32_DMA +#include +#include +#include +#include +#endif + #define ADC_CONTEXT_USES_KERNEL_TIMER #define ADC_CONTEXT_ENABLE_ON_COMPLETE #include "adc_context.h" @@ -246,6 +253,18 @@ static const uint32_t table_samp_time[] = { /* External channels (maximum). */ #define STM32_CHANNEL_COUNT 20 +#ifdef CONFIG_ADC_STM32_DMA +struct stream { + const struct device *dma_dev; + uint32_t channel; + struct dma_config dma_cfg; + struct dma_block_config dma_blk_cfg; + uint8_t priority; + bool src_addr_increment; + bool dst_addr_increment; +}; +#endif /* CONFIG_ADC_STM32_DMA */ + struct adc_stm32_data { struct adc_context ctx; const struct device *dev; @@ -261,6 +280,11 @@ struct adc_stm32_data { defined(CONFIG_SOC_SERIES_STM32L0X) int8_t acq_time_index; #endif + +#ifdef CONFIG_ADC_STM32_DMA + volatile int dma_error; + struct stream dma; +#endif }; struct adc_stm32_cfg { @@ -277,7 +301,108 @@ struct adc_stm32_cfg { static bool init_irq = true; #endif -static int check_buffer_size(const struct adc_sequence *sequence, +#ifdef CONFIG_ADC_STM32_DMA +static int adc_stm32_dma_start(const struct device *dev, + void *buffer, size_t channel_count) +{ + const struct adc_stm32_cfg *config = dev->config; + ADC_TypeDef *adc = (ADC_TypeDef *)config->base; + struct adc_stm32_data *data = dev->data; + struct dma_block_config *blk_cfg; + int ret; + + struct stream *dma = &data->dma; + + blk_cfg = &dma->dma_blk_cfg; + + /* prepare the block */ + blk_cfg->block_size = channel_count * sizeof(int16_t); + + /* Source and destination */ + blk_cfg->source_address = (uint32_t)LL_ADC_DMA_GetRegAddr(adc, LL_ADC_DMA_REG_REGULAR_DATA); + blk_cfg->source_addr_adj = DMA_ADDR_ADJ_NO_CHANGE; + blk_cfg->source_reload_en = 0; + + blk_cfg->dest_address = (uint32_t)buffer; + blk_cfg->dest_addr_adj = DMA_ADDR_ADJ_INCREMENT; + blk_cfg->dest_reload_en = 0; + + /* Manually set the FIFO threshold to 1/4 because the + * dmamux DTS entry does not contain fifo threshold + */ + blk_cfg->fifo_mode_control = 0; + + /* direction is given by the DT */ + dma->dma_cfg.head_block = blk_cfg; + dma->dma_cfg.user_data = data; + + ret = dma_config(data->dma.dma_dev, data->dma.channel, + &dma->dma_cfg); + if (ret != 0) { + LOG_ERR("Problem setting up DMA: %d", ret); + return ret; + } + + /* Allow ADC to create DMA request and set to one-shot mode, + * as implemented in HAL drivers, if applicable. + */ +#if defined(ADC_VER_V5_V90) + if (adc == ADC3) { + LL_ADC_REG_SetDMATransferMode(adc, + ADC3_CFGR_DMACONTREQ(LL_ADC_REG_DMA_TRANSFER_LIMITED)); + LL_ADC_EnableDMAReq(adc); + } else { + LL_ADC_REG_SetDataTransferMode(adc, + ADC_CFGR_DMACONTREQ(LL_ADC_REG_DMA_TRANSFER_LIMITED)); + } +#elif defined(ADC_VER_V5_X) + LL_ADC_REG_SetDataTransferMode(adc, LL_ADC_REG_DMA_TRANSFER_LIMITED); +#endif + + data->dma_error = 0; + ret = dma_start(data->dma.dma_dev, data->dma.channel); + if (ret != 0) { + LOG_ERR("Problem starting DMA: %d", ret); + return ret; + } + + LOG_DBG("DMA started"); + + return ret; +} +#endif /* CONFIG_ADC_STM32_DMA */ + +#if defined(CONFIG_ADC_STM32_DMA) && defined(CONFIG_SOC_SERIES_STM32H7X) +/* Returns true if given buffer is in a non-cacheable SRAM region. + * This is determined using the device tree, meaning the .nocache region won't work. + * The entire buffer must be in a single region. + * An example of how the SRAM region can be defined in the DTS: + * &sram4 { + * zephyr,memory-region-mpu = "RAM_NOCACHE"; + * }; + */ +static bool address_in_non_cacheable_sram(const uint16_t *buffer, const uint16_t size) +{ + /* Default if no valid SRAM region found or buffer+size not located in a single region */ + bool cachable = false; +#define IS_NON_CACHEABLE_REGION_FN(node_id) \ + COND_CODE_1(DT_NODE_HAS_PROP(node_id, zephyr_memory_region_mpu), ({ \ + const uint32_t region_start = DT_REG_ADDR(node_id); \ + const uint32_t region_end = region_start + DT_REG_SIZE(node_id); \ + if (((uint32_t)buffer >= region_start) && \ + (((uint32_t)buffer + size) < region_end)) { \ + cachable = strcmp(DT_PROP(node_id, zephyr_memory_region_mpu), \ + "RAM_NOCACHE") == 0; \ + } \ + }), \ + (EMPTY)) + DT_FOREACH_STATUS_OKAY(mmio_sram, IS_NON_CACHEABLE_REGION_FN); + + return cachable; +} +#endif /* defined(CONFIG_ADC_STM32_DMA) && defined(CONFIG_SOC_SERIES_STM32H7X) */ + +static int check_buffer(const struct adc_sequence *sequence, uint8_t active_channels) { size_t needed_buffer_size; @@ -294,6 +419,14 @@ static int check_buffer_size(const struct adc_sequence *sequence, return -ENOMEM; } +#if defined(CONFIG_ADC_STM32_DMA) && defined(CONFIG_SOC_SERIES_STM32H7X) + /* Buffer is forced to be in non-cacheable SRAM region to avoid cache maintenance */ + if (!address_in_non_cacheable_sram(sequence->buffer, needed_buffer_size)) { + LOG_ERR("Supplied buffer is not in a non-cacheable region according to DTS."); + return -EINVAL; + } +#endif + return 0; } @@ -649,6 +782,43 @@ static void adc_stm32_teardown_channels(const struct device *dev) adc_stm32_enable(adc); } +#ifdef CONFIG_ADC_STM32_DMA +static void dma_callback(const struct device *dev, void *user_data, + uint32_t channel, int status) +{ + /* user_data directly holds the adc device */ + struct adc_stm32_data *data = user_data; + const struct adc_stm32_cfg *config = dev->config; + ADC_TypeDef *adc = (ADC_TypeDef *)config->base; + + LOG_DBG("dma callback"); + + if (channel == data->dma.channel) { + if (LL_ADC_IsActiveFlag_OVR(adc) || (status == 0)) { + data->samples_count = data->channel_count; + data->buffer += data->channel_count; + /* Stop the DMA engine, only to start it again when the callback returns + * ADC_ACTION_REPEAT or ADC_ACTION_CONTINUE, or the number of samples + * haven't been reached Starting the DMA engine is done + * within adc_context_start_sampling + */ + dma_stop(data->dma.dma_dev, data->dma.channel); + LL_ADC_ClearFlag_OVR(adc); + /* No need to invalidate the cache because it's assumed that + * the address is in a non-cacheable SRAM region. + */ + adc_context_on_sampling_done(&data->ctx, dev); + } else { + LOG_ERR("DMA sampling complete, but DMA reported error %d", status); + data->dma_error = status; + LL_ADC_REG_StopConversion(adc); + dma_stop(data->dma.dma_dev, data->dma.channel); + adc_context_complete(&data->ctx, status); + } + } +} +#endif /* CONFIG_ADC_STM32_DMA */ + static int start_read(const struct device *dev, const struct adc_sequence *sequence) { @@ -814,7 +984,7 @@ static int start_read(const struct device *dev, #endif } - err = check_buffer_size(sequence, data->channel_count); + err = check_buffer(sequence, data->channel_count); if (err) { return err; } @@ -917,6 +1087,9 @@ static int start_read(const struct device *dev, */ adc_stm32_enable(adc); + LL_ADC_ClearFlag_OVR(adc); + +#if !defined(CONFIG_ADC_STM32_DMA) #if defined(CONFIG_SOC_SERIES_STM32F0X) || \ defined(STM32F3X_ADC_V1_1) || \ defined(CONFIG_SOC_SERIES_STM32L0X) || \ @@ -935,11 +1108,18 @@ static int start_read(const struct device *dev, #else LL_ADC_EnableIT_EOCS(adc); #endif +#endif /* CONFIG_ADC_STM32_DMA */ + /* This call will start the DMA */ adc_context_start_read(&data->ctx, sequence); int result = adc_context_wait_for_completion(&data->ctx); +#ifdef CONFIG_ADC_STM32_DMA + /* check if there's anything wrong with dma start */ + result = (data->dma_error ? data->dma_error : result); +#endif + return result; } @@ -950,6 +1130,9 @@ static void adc_context_start_sampling(struct adc_context *ctx) data->repeat_buffer = data->buffer; +#ifdef CONFIG_ADC_STM32_DMA + adc_stm32_dma_start(data->dev, data->buffer, data->channel_count); +#endif adc_stm32_start_conversion(data->dev); } @@ -964,6 +1147,7 @@ static void adc_context_update_buffer_pointer(struct adc_context *ctx, } } +#ifndef CONFIG_ADC_STM32_DMA static void adc_stm32_isr(const struct device *dev) { struct adc_stm32_data *data = dev->data; @@ -981,6 +1165,7 @@ static void adc_stm32_isr(const struct device *dev) LOG_DBG("%s ISR triggered.", dev->name); } +#endif /* !CONFIG_ADC_STM32_DMA */ static void adc_context_on_complete(struct adc_context *ctx, int status) { @@ -1147,7 +1332,7 @@ static int adc_stm32_init(const struct device *dev) ADC_TypeDef *adc = (ADC_TypeDef *)config->base; int err; - LOG_DBG("Initializing...."); + LOG_DBG("Initializing %s", dev->name); if (!device_is_ready(clk)) { LOG_ERR("clock control device not ready"); @@ -1184,6 +1369,14 @@ static int adc_stm32_init(const struct device *dev) LL_PWR_EnableVDDA(); #endif /* CONFIG_SOC_SERIES_STM32U5X */ +#ifdef CONFIG_ADC_STM32_DMA + if ((data->dma.dma_dev != NULL) && + !device_is_ready(data->dma.dma_dev)) { + LOG_ERR("%s device not ready", data->dma.dma_dev->name); + return -ENODEV; + } +#endif + #if defined(CONFIG_SOC_SERIES_STM32L4X) || \ defined(CONFIG_SOC_SERIES_STM32L5X) || \ defined(CONFIG_SOC_SERIES_STM32WBX) || \ @@ -1402,9 +1595,47 @@ static void adc_stm32_irq_init(void) #define ADC_STM32_IRQ_CONFIG(index) #define ADC_STM32_IRQ_FUNC(index) \ - .irq_cfg_func = adc_stm32_irq_init, \ + .irq_cfg_func = adc_stm32_irq_init, +#define ADC_DMA_CHANNEL(id, dir, DIR, src, dest) + +#elif defined(CONFIG_ADC_STM32_DMA) /* !CONFIG_ADC_STM32_SHARED_IRQS */ + +#define ADC_DMA_CHANNEL_INIT(index, name, dir_cap, src_dev, dest_dev) \ + .dma = { \ + .dma_dev = DEVICE_DT_GET(STM32_DMA_CTLR(index, name)), \ + .channel = DT_INST_DMAS_CELL_BY_NAME(index, name, channel), \ + .dma_cfg = { \ + .dma_slot = STM32_DMA_SLOT(index, name, slot), \ + .channel_direction = STM32_DMA_CONFIG_DIRECTION( \ + STM32_DMA_CHANNEL_CONFIG(index, name)), \ + .source_data_size = STM32_DMA_CONFIG_##src_dev##_DATA_SIZE( \ + STM32_DMA_CHANNEL_CONFIG(index, name)), \ + .dest_data_size = STM32_DMA_CONFIG_##dest_dev##_DATA_SIZE( \ + STM32_DMA_CHANNEL_CONFIG(index, name)), \ + .source_burst_length = 1, /* SINGLE transfer */ \ + .dest_burst_length = 1, /* SINGLE transfer */ \ + .channel_priority = STM32_DMA_CONFIG_PRIORITY( \ + STM32_DMA_CHANNEL_CONFIG(index, name)), \ + .dma_callback = dma_callback, \ + .block_count = 2, \ + }, \ + .src_addr_increment = STM32_DMA_CONFIG_##src_dev##_ADDR_INC( \ + STM32_DMA_CHANNEL_CONFIG(index, name)), \ + .dst_addr_increment = STM32_DMA_CONFIG_##dest_dev##_ADDR_INC( \ + STM32_DMA_CHANNEL_CONFIG(index, name)), \ + } -#else +#define ADC_DMA_CHANNEL(id, dir, DIR, src, dest) \ + COND_CODE_1(DT_INST_DMAS_HAS_NAME(id, dir), \ + (ADC_DMA_CHANNEL_INIT(id, dir, DIR, src, dest)), \ + (EMPTY)) + +#define ADC_STM32_IRQ_CONFIG(index) \ +static void adc_stm32_cfg_func_##index(void){ EMPTY } +#define ADC_STM32_IRQ_FUNC(index) \ + .irq_cfg_func = adc_stm32_cfg_func_##index, + +#else /* CONFIG_ADC_STM32_DMA */ #define ADC_STM32_IRQ_CONFIG(index) \ static void adc_stm32_cfg_func_##index(void) \ @@ -1416,8 +1647,9 @@ static void adc_stm32_cfg_func_##index(void) \ } #define ADC_STM32_IRQ_FUNC(index) \ .irq_cfg_func = adc_stm32_cfg_func_##index, +#define ADC_DMA_CHANNEL(id, dir, DIR, src, dest) -#endif /* CONFIG_ADC_STM32_SHARED_IRQS */ +#endif /* CONFIG_ADC_STM32_DMA && CONFIG_ADC_STM32_SHARED_IRQS */ #define ADC_STM32_INIT(index) \ @@ -1443,6 +1675,7 @@ static struct adc_stm32_data adc_stm32_data_##index = { \ ADC_CONTEXT_INIT_TIMER(adc_stm32_data_##index, ctx), \ ADC_CONTEXT_INIT_LOCK(adc_stm32_data_##index, ctx), \ ADC_CONTEXT_INIT_SYNC(adc_stm32_data_##index, ctx), \ + ADC_DMA_CHANNEL(index, dmamux, NULL, PERIPHERAL, MEMORY) \ }; \ \ DEVICE_DT_INST_DEFINE(index, \ From 6e21ebf2e03259db8ae216314ced9ed84eb3a0cd Mon Sep 17 00:00:00 2001 From: Hein Wessels Date: Tue, 24 Jan 2023 10:46:21 +0100 Subject: [PATCH 0481/1906] tests: drivers: adc_dma: wrap nxp specifc functionality This test contained NXP specific functions, for example the counter trigger, which is not required for all ADC DMA implementations. Also moved NXP specific kconfigs to appropriate board files Signed-off-by: Hein Wessels --- .../drivers/adc/adc_dma/boards/frdm_k64f.conf | 3 +++ .../drivers/adc/adc_dma/boards/frdm_k82f.conf | 3 +++ tests/drivers/adc/adc_dma/prj.conf | 3 --- tests/drivers/adc/adc_dma/src/test_adc.c | 24 +++++++++++++++---- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/tests/drivers/adc/adc_dma/boards/frdm_k64f.conf b/tests/drivers/adc/adc_dma/boards/frdm_k64f.conf index 5692079a8ffa..a0c2eeaa0db3 100644 --- a/tests/drivers/adc/adc_dma/boards/frdm_k64f.conf +++ b/tests/drivers/adc/adc_dma/boards/frdm_k64f.conf @@ -5,3 +5,6 @@ # CONFIG_ADC_MCUX_ADC16_ENABLE_EDMA=y +CONFIG_ADC_MCUX_ADC16_HW_TRIGGER=y +CONFIG_COUNTER=y +CONFIG_ADC_ASYNC=y diff --git a/tests/drivers/adc/adc_dma/boards/frdm_k82f.conf b/tests/drivers/adc/adc_dma/boards/frdm_k82f.conf index 5692079a8ffa..a0c2eeaa0db3 100644 --- a/tests/drivers/adc/adc_dma/boards/frdm_k82f.conf +++ b/tests/drivers/adc/adc_dma/boards/frdm_k82f.conf @@ -5,3 +5,6 @@ # CONFIG_ADC_MCUX_ADC16_ENABLE_EDMA=y +CONFIG_ADC_MCUX_ADC16_HW_TRIGGER=y +CONFIG_COUNTER=y +CONFIG_ADC_ASYNC=y diff --git a/tests/drivers/adc/adc_dma/prj.conf b/tests/drivers/adc/adc_dma/prj.conf index 921de12078f8..806d50a48d82 100644 --- a/tests/drivers/adc/adc_dma/prj.conf +++ b/tests/drivers/adc/adc_dma/prj.conf @@ -2,10 +2,7 @@ CONFIG_ZTEST=y CONFIG_ZTEST_NEW_API=y CONFIG_ADC=y -CONFIG_ADC_ASYNC=y CONFIG_ADC_LOG_LEVEL_INF=y CONFIG_HEAP_MEM_POOL_SIZE=1024 CONFIG_TEST_USERSPACE=y CONFIG_DMA=y -CONFIG_COUNTER=y -CONFIG_ADC_MCUX_ADC16_HW_TRIGGER=y diff --git a/tests/drivers/adc/adc_dma/src/test_adc.c b/tests/drivers/adc/adc_dma/src/test_adc.c index be5d2c4d6147..efbf6876af79 100644 --- a/tests/drivers/adc/adc_dma/src/test_adc.c +++ b/tests/drivers/adc/adc_dma/src/test_adc.c @@ -21,6 +21,8 @@ #define ADC_REFERENCE ADC_REF_INTERNAL #define ADC_ACQUISITION_TIME ADC_ACQ_TIME_DEFAULT #define ADC_1ST_CHANNEL_ID 26 +#define COUNTER_NODE_NAME pit0 +#define HW_TRIGGER_INTERVAL (2U) #elif defined(CONFIG_BOARD_FRDM_K82F) @@ -30,15 +32,19 @@ #define ADC_REFERENCE ADC_REF_INTERNAL #define ADC_ACQUISITION_TIME ADC_ACQ_TIME_DEFAULT #define ADC_1ST_CHANNEL_ID 26 +#define COUNTER_NODE_NAME pit0 +#define HW_TRIGGER_INTERVAL (2U) #endif -#define HW_TRIGGER_INTERVAL (2U) /* for DMA HW trigger interval need large than HW trigger interval*/ #define SAMPLE_INTERVAL_US (10000U) #define BUFFER_SIZE 24 +#ifndef ALIGNMENT #define ALIGNMENT DMA_BUF_ADDR_ALIGNMENT(DT_NODELABEL(test_dma)) +#endif + static ZTEST_BMEM __aligned(ALIGNMENT) int16_t m_sample_buffer[BUFFER_SIZE]; static ZTEST_BMEM __aligned(ALIGNMENT) int16_t m_sample_buffer2[2][BUFFER_SIZE]; static int current_buf_inx; @@ -78,6 +84,7 @@ const struct device *get_adc_device(void) const struct device *get_count_device(void) { +#if defined(COUNTER_NODE_NAME) const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(pit0)); if (!device_is_ready(dev)) { @@ -86,12 +93,16 @@ const struct device *get_count_device(void) } return dev; +#else + return NULL; +#endif } -static void init_pit(void) +#if defined(COUNTER_NODE_NAME) +static void init_counter(void) { int err; - const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(pit0)); + const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(COUNTER_NODE_NAME)); struct counter_top_cfg top_cfg = { .callback = NULL, .user_data = NULL, .flags = 0 }; @@ -104,6 +115,7 @@ static void init_pit(void) zassert_equal(0, err, "%s: Counter failed to set top value (err: %d)", dev->name, err); } +#endif static const struct device *init_adc(void) { @@ -126,7 +138,9 @@ static const struct device *init_adc(void) (void)memset(m_sample_buffer, 0, sizeof(m_sample_buffer)); - init_pit(); +#if defined(COUNTER_NODE_NAME) + init_counter(); +#endif return adc_dev; } @@ -245,7 +259,7 @@ static int test_task_asynchronous_call(void) const struct adc_sequence_options options = { .extra_samplings = 4, /* Start consecutive samplings as fast as possible. */ - .interval_us = HW_TRIGGER_INTERVAL, + .interval_us = 0, }; const struct adc_sequence sequence = { .options = &options, From 9d314faf28e19ed75d5b3d27f742ad0a56a9de72 Mon Sep 17 00:00:00 2001 From: Hein Wessels Date: Mon, 13 Mar 2023 11:52:38 +0100 Subject: [PATCH 0482/1906] tests: drivers: adc_dma: remove test userspace These test uses DMA which sometimes require buffers to be placed in custom specific section. This is not compatible with ztest userspace, which requires variables to be placed in a specific partition. Signed-off-by: Hein Wessels --- tests/drivers/adc/adc_dma/prj.conf | 2 -- tests/drivers/adc/adc_dma/src/main.c | 19 +---------- tests/drivers/adc/adc_dma/src/test_adc.c | 42 ++++++------------------ 3 files changed, 11 insertions(+), 52 deletions(-) diff --git a/tests/drivers/adc/adc_dma/prj.conf b/tests/drivers/adc/adc_dma/prj.conf index 806d50a48d82..81a73e12de1a 100644 --- a/tests/drivers/adc/adc_dma/prj.conf +++ b/tests/drivers/adc/adc_dma/prj.conf @@ -3,6 +3,4 @@ CONFIG_ZTEST_NEW_API=y CONFIG_ADC=y CONFIG_ADC_LOG_LEVEL_INF=y -CONFIG_HEAP_MEM_POOL_SIZE=1024 -CONFIG_TEST_USERSPACE=y CONFIG_DMA=y diff --git a/tests/drivers/adc/adc_dma/src/main.c b/tests/drivers/adc/adc_dma/src/main.c index a1f73c339d52..2e968001c976 100644 --- a/tests/drivers/adc/adc_dma/src/main.c +++ b/tests/drivers/adc/adc_dma/src/main.c @@ -8,21 +8,4 @@ #include #include -extern const struct device *get_adc_device(void); -extern const struct device *get_count_device(void); -extern struct k_poll_signal async_sig; - -void *adc_dma_setup(void) -{ - k_object_access_grant(get_adc_device(), k_current_get()); - k_object_access_grant(get_count_device(), k_current_get()); -#ifdef CONFIG_ADC_ASYNC - k_object_access_grant(&async_sig, k_current_get()); - k_poll_signal_init(&async_sig); - k_thread_system_pool_assign(k_current_get()); -#endif - - return NULL; -} - -ZTEST_SUITE(adc_dma, NULL, adc_dma_setup, NULL, NULL, NULL); +ZTEST_SUITE(adc_dma, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/drivers/adc/adc_dma/src/test_adc.c b/tests/drivers/adc/adc_dma/src/test_adc.c index efbf6876af79..c1578022497a 100644 --- a/tests/drivers/adc/adc_dma/src/test_adc.c +++ b/tests/drivers/adc/adc_dma/src/test_adc.c @@ -45,10 +45,14 @@ #define ALIGNMENT DMA_BUF_ADDR_ALIGNMENT(DT_NODELABEL(test_dma)) #endif -static ZTEST_BMEM __aligned(ALIGNMENT) int16_t m_sample_buffer[BUFFER_SIZE]; -static ZTEST_BMEM __aligned(ALIGNMENT) int16_t m_sample_buffer2[2][BUFFER_SIZE]; +static __aligned(ALIGNMENT) int16_t m_sample_buffer[BUFFER_SIZE]; +static __aligned(ALIGNMENT) int16_t m_sample_buffer2[2][BUFFER_SIZE]; static int current_buf_inx; +#if defined(CONFIG_ADC_ASYNC) +static struct k_poll_signal async_sig; +#endif + static const struct adc_channel_cfg m_1st_channel_cfg = { .gain = ADC_GAIN, .reference = ADC_REFERENCE, @@ -70,34 +74,6 @@ static const struct adc_channel_cfg m_2nd_channel_cfg = { }; #endif /* defined(ADC_2ND_CHANNEL_ID) */ -const struct device *get_adc_device(void) -{ - const struct device *const dev = DEVICE_DT_GET(ADC_DEVICE_NODE); - - if (!device_is_ready(dev)) { - printk("ADC device is not ready\n"); - return NULL; - } - - return dev; -} - -const struct device *get_count_device(void) -{ -#if defined(COUNTER_NODE_NAME) - const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(pit0)); - - if (!device_is_ready(dev)) { - printk("count device is not ready\n"); - return NULL; - } - - return dev; -#else - return NULL; -#endif -} - #if defined(COUNTER_NODE_NAME) static void init_counter(void) { @@ -138,6 +114,10 @@ static const struct device *init_adc(void) (void)memset(m_sample_buffer, 0, sizeof(m_sample_buffer)); +#if defined(CONFIG_ADC_ASYNC) + k_poll_signal_init(&async_sig); +#endif + #if defined(COUNTER_NODE_NAME) init_counter(); #endif @@ -251,8 +231,6 @@ ZTEST_USER(adc_dma, test_adc_sample_two_channels) * test_adc_asynchronous_call */ #if defined(CONFIG_ADC_ASYNC) -struct k_poll_signal async_sig; - static int test_task_asynchronous_call(void) { int ret; From a0e6fe34e038fb2d661f7fe61e7bb1a1ee3136e9 Mon Sep 17 00:00:00 2001 From: Hein Wessels Date: Mon, 13 Mar 2023 12:54:25 +0100 Subject: [PATCH 0483/1906] tests: drivers: adc_dma: add nucleo_h743zi Adds nucleo_h732zi ADC DMA unit tests with multiple channels. The STM32 ADC DMA driver requires the buffers to be placed in a non-cacheable memory region as defined by the DMA. Therefore this adds configurability to the test to change the region the buffer is placed in. Signed-off-by: Hein Wessels --- .../adc/adc_dma/boards/nucleo_h743zi.conf | 8 +++++ .../adc/adc_dma/boards/nucleo_h743zi.overlay | 34 +++++++++++++++++++ tests/drivers/adc/adc_dma/src/test_adc.c | 31 +++++++++++++++-- 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 tests/drivers/adc/adc_dma/boards/nucleo_h743zi.conf create mode 100644 tests/drivers/adc/adc_dma/boards/nucleo_h743zi.overlay diff --git a/tests/drivers/adc/adc_dma/boards/nucleo_h743zi.conf b/tests/drivers/adc/adc_dma/boards/nucleo_h743zi.conf new file mode 100644 index 000000000000..675ebf0d5aa6 --- /dev/null +++ b/tests/drivers/adc/adc_dma/boards/nucleo_h743zi.conf @@ -0,0 +1,8 @@ +# +# Copyright (c) 2023 Nobleo Technology +# +# SPDX-License-Identifier: Apache-2.0 +# + +CONFIG_ADC_STM32_DMA=y +CONFIG_ADC_ASYNC=y diff --git a/tests/drivers/adc/adc_dma/boards/nucleo_h743zi.overlay b/tests/drivers/adc/adc_dma/boards/nucleo_h743zi.overlay new file mode 100644 index 000000000000..af004e793710 --- /dev/null +++ b/tests/drivers/adc/adc_dma/boards/nucleo_h743zi.overlay @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Nobleo Technology + * + * SPDX-License-Identifier: Apache-2.0 + */ +&adc1 { + dmas = < &dmamux1 0 9 (STM32_DMA_PERIPH_TO_MEMORY | + STM32_DMA_MEM_INC | STM32_DMA_MEM_16BITS | STM32_DMA_PERIPH_16BITS) >; + dma-names = "dmamux"; + + #address-cells = <1>; + #size-cells = <0>; + + channel@1 { + reg = <1>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <12>; + }; +}; + +/* ADC driver expects a buffer in a non-cachable memory region */ +&sram4 { + zephyr,memory-region-mpu = "RAM_NOCACHE"; +}; + +&dma1 { + status = "okay"; +}; + +test_dma: &dmamux1 { + status = "okay"; +}; diff --git a/tests/drivers/adc/adc_dma/src/test_adc.c b/tests/drivers/adc/adc_dma/src/test_adc.c index c1578022497a..248f3546da90 100644 --- a/tests/drivers/adc/adc_dma/src/test_adc.c +++ b/tests/drivers/adc/adc_dma/src/test_adc.c @@ -35,6 +35,33 @@ #define COUNTER_NODE_NAME pit0 #define HW_TRIGGER_INTERVAL (2U) +#elif defined(CONFIG_BOARD_NUCLEO_H743ZI) + +#define ADC_DEVICE_NODE DT_INST(0, st_stm32_adc) +#define ADC_RESOLUTION 12 +#define ADC_GAIN ADC_GAIN_1 +#define ADC_REFERENCE ADC_REF_INTERNAL +#define ADC_ACQUISITION_TIME ADC_ACQ_TIME_DEFAULT +#define ADC_1ST_CHANNEL_ID 1 +#define ADC_2ND_CHANNEL_ID 7 +#define ALIGNMENT 32 +#define BUFFER_MEM_REGION __attribute__((__section__(".sram4"))) + +#endif + +/* Invalid value that is not supposed to be written by the driver. It is used + * to mark the sample buffer entries as empty. If needed, it can be overridden + * for a particular board by providing a specific definition above. + */ +#if !defined(INVALID_ADC_VALUE) +#define INVALID_ADC_VALUE SHRT_MIN +#endif + +/* Memory region where buffers will be placed. By default placed in ZTEST_BMEM + * but can be overwritten for a particular board. + */ +#if !defined(BUFFER_MEM_REGION) +#define BUFFER_MEM_REGION EMPTY #endif /* for DMA HW trigger interval need large than HW trigger interval*/ @@ -45,8 +72,8 @@ #define ALIGNMENT DMA_BUF_ADDR_ALIGNMENT(DT_NODELABEL(test_dma)) #endif -static __aligned(ALIGNMENT) int16_t m_sample_buffer[BUFFER_SIZE]; -static __aligned(ALIGNMENT) int16_t m_sample_buffer2[2][BUFFER_SIZE]; +static BUFFER_MEM_REGION __aligned(ALIGNMENT) int16_t m_sample_buffer[BUFFER_SIZE]; +static BUFFER_MEM_REGION __aligned(ALIGNMENT) int16_t m_sample_buffer2[2][BUFFER_SIZE]; static int current_buf_inx; #if defined(CONFIG_ADC_ASYNC) From 7e4de9363f8a6edb1e7b92c0a52c4aa650255f20 Mon Sep 17 00:00:00 2001 From: Hein Wessels Date: Mon, 13 Mar 2023 11:22:58 +0100 Subject: [PATCH 0484/1906] tests: drivers: adc_dma: fix buffer state not being verified Previously the contents of buffers after an ADC DMA read was simply printed, but not verified with an zassert that the value was updated. This commit updates it to be similar to the adc_api test that fills the buffer initially with a known value, which is then used to ensure the ADC DMA functioned successfully. Signed-off-by: Hein Wessels --- tests/drivers/adc/adc_dma/src/test_adc.c | 28 ++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/drivers/adc/adc_dma/src/test_adc.c b/tests/drivers/adc/adc_dma/src/test_adc.c index 248f3546da90..2a65681f9d68 100644 --- a/tests/drivers/adc/adc_dma/src/test_adc.c +++ b/tests/drivers/adc/adc_dma/src/test_adc.c @@ -122,7 +122,7 @@ static void init_counter(void) static const struct device *init_adc(void) { - int ret; + int i, ret; const struct device *const adc_dev = DEVICE_DT_GET(ADC_DEVICE_NODE); zassert_true(device_is_ready(adc_dev), "ADC device is not ready"); @@ -139,7 +139,11 @@ static const struct device *init_adc(void) ret); #endif /* defined(ADC_2ND_CHANNEL_ID) */ - (void)memset(m_sample_buffer, 0, sizeof(m_sample_buffer)); + for (i = 0; i < BUFFER_SIZE; ++i) { + m_sample_buffer[i] = INVALID_ADC_VALUE; + m_sample_buffer2[0][i] = INVALID_ADC_VALUE; + m_sample_buffer2[1][i] = INVALID_ADC_VALUE; + } #if defined(CONFIG_ADC_ASYNC) k_poll_signal_init(&async_sig); @@ -164,8 +168,16 @@ static void check_samples(int expected_count) if (i && i % 10 == 0) { TC_PRINT("\n"); } + + if (i < expected_count) { + zassert_not_equal(INVALID_ADC_VALUE, sample_value, + "[%u] should be filled", i); + } else { + zassert_equal(INVALID_ADC_VALUE, sample_value, + "[%u] should be empty", i); + } } - TC_PRINT("%d sampled\n", BUFFER_SIZE); + TC_PRINT("\n"); } static void check_samples2(int expected_count) @@ -180,8 +192,16 @@ static void check_samples2(int expected_count) if (i && i % 10 == 0) { TC_PRINT("\n"); } + + if (i < expected_count) { + zassert_not_equal(INVALID_ADC_VALUE, sample_value, + "[%u] should be filled", i); + } else { + zassert_equal(INVALID_ADC_VALUE, sample_value, + "[%u] should be empty", i); + } } - TC_PRINT("%d sampled\n", BUFFER_SIZE); + TC_PRINT("\n"); } /* From a3288252ffa815eb77d2854156d879c01b10fbb4 Mon Sep 17 00:00:00 2001 From: Zack Cornelius Date: Fri, 21 Jan 2022 11:39:09 -0600 Subject: [PATCH 0485/1906] drivers: flash: nrf_qspi_nor: Add runtime PM Add PM_DEVICE_RUNTIME support to nordic QSPI NOR flash driver, putting the QSPI peripheral and flash ship into DPD if available Signed-off-by: Zack Cornelius --- drivers/flash/nrf_qspi_nor.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index b97efba146e0..f564e0f282c5 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -174,7 +175,9 @@ BUILD_ASSERT(DT_INST_PROP(0, address_size_32), "After entering 4 byte addressing mode, 4 byte addressing is expected"); #endif +#ifndef CONFIG_PM_DEVICE_RUNTIME static bool qspi_initialized; +#endif static int qspi_device_init(const struct device *dev); static void qspi_device_uninit(const struct device *dev); @@ -350,6 +353,9 @@ static void qspi_handler(nrfx_qspi_evt_t event, void *p_context) static int qspi_device_init(const struct device *dev) { +#ifdef CONFIG_PM_DEVICE_RUNTIME + return pm_device_runtime_get(dev); +#else struct qspi_nor_data *dev_data = dev->data; nrfx_err_t res; int ret = 0; @@ -377,10 +383,18 @@ static int qspi_device_init(const struct device *dev) qspi_unlock(dev); return ret; +#endif } static void qspi_device_uninit(const struct device *dev) { +#ifdef CONFIG_PM_DEVICE_RUNTIME + int ret = pm_device_runtime_put(dev); + + if (ret < 0) { + LOG_ERR("Failed to schedule device sleep: %d", ret); + } +#else bool last = true; qspi_lock(dev); @@ -408,6 +422,7 @@ static void qspi_device_uninit(const struct device *dev) } qspi_unlock(dev); +#endif } /* QSPI send custom command. @@ -1171,7 +1186,16 @@ static int qspi_nor_configure(const struct device *dev) return ret; } +#ifdef CONFIG_PM_DEVICE_RUNTIME + ret = pm_device_runtime_enable(dev); + if (ret < 0) { + LOG_ERR("Failed to enable runtime power management: %d", ret); + } else { + LOG_DBG("Runtime power management enabled"); + } +#else qspi_device_uninit(dev); +#endif /* now the spi bus is configured, we can verify the flash id */ if (qspi_nor_read_id(dev) != 0) { @@ -1317,10 +1341,13 @@ static int qspi_nor_pm_action(const struct device *dev, switch (action) { case PM_DEVICE_ACTION_SUSPEND: +#ifndef CONFIG_PM_DEVICE_RUNTIME + /* If PM_DEVICE_RUNTIME, we don't uninit after RESUME */ ret = qspi_device_init(dev); if (ret < 0) { return ret; } +#endif if (nrfx_qspi_mem_busy_check() != NRFX_SUCCESS) { return -EBUSY; @@ -1357,7 +1384,10 @@ static int qspi_nor_pm_action(const struct device *dev, return ret; } +#ifndef CONFIG_PM_DEVICE_RUNTIME + /* If PM_DEVICE_RUNTIME, we're immediately going to use the device */ qspi_device_uninit(dev); +#endif break; default: From 047ee8ca5fb89bbd7d1b13738bc73e3aa533bff9 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 2 Feb 2023 21:51:45 -0800 Subject: [PATCH 0486/1906] modules/picolibc: Include clang+cmake and old GCC changes This updates west.yml to pull the version of picolibc that includes both the patches in #54391 as well as the fix providing compatibility for the 'deprecated' attribute when using GCC versions before 4.5, such as the GCC based XCC compiler. Changes for 'weak' attributes were added to avoid using inline asm statements for compilers that support the necessary attributes. This commit is synchronized with Zephyr SDK: https://github.com/zephyrproject-rtos/sdk-ng/pull/650 Signed-off-by: Keith Packard --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index e56cf9bd10c6..6a0215dd59fd 100644 --- a/west.yml +++ b/west.yml @@ -207,7 +207,7 @@ manifest: path: modules/lib/openthread - name: picolibc path: modules/lib/picolibc - revision: 2097f26ce7dee36922b22ce048c09cd073ebae3d + revision: 0694a78fc08b3300c7db79602c46ba0a64428c8e - name: segger revision: e2ff2200556e8a8f962921444275c04971a2bb3d path: modules/debug/segger From 51f452bbf005ca81c10916e24e93c4a4524769d5 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Mon, 20 Mar 2023 12:25:25 +0100 Subject: [PATCH 0487/1906] tests: drivers: counter: Relax timing requirement In short_relative_capable test it is possible that short alarm setting is repeated few times and it is possible that alarm does not expire shortely after setting. Increase the delay after expiration is checked. Signed-off-by: Krzysztof Chruscinski --- tests/drivers/counter/counter_basic_api/src/test_counter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/drivers/counter/counter_basic_api/src/test_counter.c b/tests/drivers/counter/counter_basic_api/src/test_counter.c index ba23ca4a2683..1ce2a221a0fa 100644 --- a/tests/drivers/counter/counter_basic_api/src/test_counter.c +++ b/tests/drivers/counter/counter_basic_api/src/test_counter.c @@ -804,7 +804,7 @@ static void test_short_relative_alarm_instance(const struct device *dev) dev->name, err); /* wait to ensure that tick+1 timeout will expire. */ - k_busy_wait(3*tick_us); + k_busy_wait(10 * tick_us); cnt = IS_ENABLED(CONFIG_ZERO_LATENCY_IRQS) ? alarm_cnt : k_sem_count_get(&alarm_cnt_sem); From 93619d7b738308f57c5a7faad06e021bdc87d9e1 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Mon, 20 Mar 2023 12:27:27 +0100 Subject: [PATCH 0488/1906] drivers: counter: nrfx_rtc: Use clock control when driver enabled RTC shall enabled LF clock only if CLOCK_CONTROL driver is enabled. Signed-off-by: Krzysztof Chruscinski --- drivers/counter/counter_nrfx_rtc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/counter/counter_nrfx_rtc.c b/drivers/counter/counter_nrfx_rtc.c index 3470cbfa03ff..7d97a97469f4 100644 --- a/drivers/counter/counter_nrfx_rtc.c +++ b/drivers/counter/counter_nrfx_rtc.c @@ -4,9 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ #include +#include +#ifdef CONFIG_CLOCK_CONTROL_NRF #include #include -#include +#endif #include #ifdef DPPI_PRESENT #include @@ -541,7 +543,9 @@ static int init_rtc(const struct device *dev, uint32_t prescaler) NRF_RTC_Type *rtc = nrfx_config->rtc; int err; +#ifdef CONFIG_CLOCK_CONTROL_NRF z_nrf_clock_control_lf_on(CLOCK_CONTROL_NRF_LF_START_NOWAIT); +#endif nrf_rtc_prescaler_set(rtc, prescaler); From 077153511931d8b3aac9477fa5f0c7ffbd809351 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 15 Mar 2023 10:05:45 +0100 Subject: [PATCH 0489/1906] net: sockets: Update zsock_poll() API documentation It is no longer true that zsock_poll() works only with networking sockets, we now support for example eventfd objects which can also be polled. Therefore just remove the outdated comment in the zsock_poll() documentation, as it is misleading. Signed-off-by: Robert Lubos --- include/zephyr/net/socket.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/zephyr/net/socket.h b/include/zephyr/net/socket.h index 54d092884ef7..1209bc0cc736 100644 --- a/include/zephyr/net/socket.h +++ b/include/zephyr/net/socket.h @@ -458,8 +458,7 @@ __syscall int zsock_fcntl(int sock, int cmd, int flags); * @rst * See `POSIX.1-2017 article * `__ - * for normative description. (In Zephyr this function works only with - * sockets, not arbitrary file descriptors.) + * for normative description. * This function is also exposed as ``poll()`` * if :kconfig:option:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined (in which case * it may conflict with generic POSIX ``poll()`` function). From 3da59df974172c828cbea0c0aa7b1831d805d016 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 14 Mar 2023 13:00:11 +0100 Subject: [PATCH 0490/1906] tests: net: sockets: tcp: Extend SO_RCVBUF/SO_SNDBUF tests Add new test cases for SO_RCVBUF/SO_SNDBUF which verify that setting those options actually affects the RX/TX window sizes at the TCP level. Existing tests only verified whether the options can be set/read correctly. Signed-off-by: Robert Lubos --- tests/net/socket/tcp/src/main.c | 98 +++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/tests/net/socket/tcp/src/main.c b/tests/net/socket/tcp/src/main.c index 048c03ab3e25..49c28897aaac 100644 --- a/tests/net/socket/tcp/src/main.c +++ b/tests/net/socket/tcp/src/main.c @@ -1101,6 +1101,55 @@ ZTEST(net_socket_tcp, test_so_rcvbuf) test_context_cleanup(); } +ZTEST(net_socket_tcp, test_so_rcvbuf_win_size) +{ + int rv; + int c_sock; + int s_sock; + int new_sock; + struct sockaddr_in c_saddr; + struct sockaddr_in s_saddr; + struct sockaddr addr; + socklen_t addrlen = sizeof(addr); + char tx_buf[] = TEST_STR_SMALL; + int buf_optval = sizeof(TEST_STR_SMALL); + + prepare_sock_tcp_v4(MY_IPV4_ADDR, ANY_PORT, &c_sock, &c_saddr); + prepare_sock_tcp_v4(MY_IPV4_ADDR, SERVER_PORT, &s_sock, &s_saddr); + + test_bind(s_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr)); + test_listen(s_sock); + + test_connect(c_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr)); + + test_accept(s_sock, &new_sock, &addr, &addrlen); + zassert_equal(addrlen, sizeof(struct sockaddr_in), "wrong addrlen"); + + /* Lower server-side RX window size. */ + rv = setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval, + sizeof(buf_optval)); + zassert_equal(rv, 0, "setsockopt failed (%d)", errno); + + rv = send(c_sock, tx_buf, sizeof(tx_buf), MSG_DONTWAIT); + zassert_equal(rv, sizeof(tx_buf), "Unexpected return code %d", rv); + + /* Window should've dropped to 0, so the ACK will be delayed - wait for + * it to arrive, so that the client is aware of the new window size. + */ + k_msleep(150); + + /* Client should not be able to send now (RX window full). */ + rv = send(c_sock, tx_buf, 1, MSG_DONTWAIT); + zassert_equal(rv, -1, "Unexpected return code %d", rv); + zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno); + + test_close(c_sock); + test_close(new_sock); + test_close(s_sock); + + test_context_cleanup(); +} + ZTEST(net_socket_tcp, test_so_sndbuf) { struct sockaddr_in bind_addr4; @@ -1141,6 +1190,55 @@ ZTEST(net_socket_tcp, test_so_sndbuf) test_context_cleanup(); } +ZTEST(net_socket_tcp, test_so_sndbuf_win_size) +{ + int rv; + int c_sock; + int s_sock; + int new_sock; + struct sockaddr_in c_saddr; + struct sockaddr_in s_saddr; + struct sockaddr addr; + socklen_t addrlen = sizeof(addr); + char tx_buf[] = TEST_STR_SMALL; + int buf_optval = sizeof(TEST_STR_SMALL); + + prepare_sock_tcp_v4(MY_IPV4_ADDR, ANY_PORT, &c_sock, &c_saddr); + prepare_sock_tcp_v4(MY_IPV4_ADDR, SERVER_PORT, &s_sock, &s_saddr); + + /* Lower client-side TX window size. */ + rv = setsockopt(c_sock, SOL_SOCKET, SO_SNDBUF, &buf_optval, + sizeof(buf_optval)); + zassert_equal(rv, 0, "setsockopt failed (%d)", errno); + + test_bind(s_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr)); + test_listen(s_sock); + + test_connect(c_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr)); + + test_accept(s_sock, &new_sock, &addr, &addrlen); + zassert_equal(addrlen, sizeof(struct sockaddr_in), "wrong addrlen"); + + /* Make sure the ACK from the server does not arrive. */ + loopback_set_packet_drop_ratio(1.0f); + + rv = send(c_sock, tx_buf, sizeof(tx_buf), MSG_DONTWAIT); + zassert_equal(rv, sizeof(tx_buf), "Unexpected return code %d", rv); + + /* Client should not be able to send now (TX window full). */ + rv = send(c_sock, tx_buf, 1, MSG_DONTWAIT); + zassert_equal(rv, -1, "Unexpected return code %d", rv); + zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno); + + restore_packet_loss_ratio(); + + test_close(c_sock); + test_close(new_sock); + test_close(s_sock); + + test_context_cleanup(); +} + ZTEST(net_socket_tcp, test_v4_so_rcvtimeo) { int c_sock; From e67374e47afbe52c43f61a910b853327c27eeea2 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Mon, 13 Mar 2023 17:03:50 +0100 Subject: [PATCH 0491/1906] net: tcp: Rework TCP SO_RCVBUF/SO_SNDBUF option handling SO_RCVBUF option processing at the TCP level was broken. The option value was only checked once, when the TCP context was allocated. This made little sense, as at this point the option would not even get a chance to have custom value. If the user modified the option after the socket (net_context) was created, it had no effect on the TCP operation. This commit fixes this, by checking the option value whenever new packet is processed, so that the configured window size is updated at the TCP level before we report it in the TCP ACK. In order to achieve this, introduce a new helper function, to refresh the configured window sizes, to avoid bloating `tcp_in()` even further. Signed-off-by: Robert Lubos --- subsys/net/ip/tcp.c | 120 ++++++++++++++++++++---------------- subsys/net/ip/tcp_private.h | 1 + 2 files changed, 68 insertions(+), 53 deletions(-) diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index a08049aa6ba8..426c60ed5616 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -36,7 +36,7 @@ LOG_MODULE_REGISTER(net_tcp, CONFIG_NET_TCP_LOG_LEVEL); static int tcp_rto = CONFIG_NET_TCP_INIT_RETRANSMISSION_TIMEOUT; static int tcp_retries = CONFIG_NET_TCP_RETRY_COUNT; static int tcp_fin_timeout_ms; -static int tcp_window = +static int tcp_rx_window = #if (CONFIG_NET_TCP_MAX_RECV_WINDOW_SIZE != 0) CONFIG_NET_TCP_MAX_RECV_WINDOW_SIZE; #else @@ -46,6 +46,16 @@ static int tcp_window = CONFIG_NET_BUF_DATA_POOL_SIZE / 3; #endif /* CONFIG_NET_BUF_FIXED_DATA_SIZE */ #endif +static int tcp_tx_window = +#if (CONFIG_NET_TCP_MAX_SEND_WINDOW_SIZE != 0) + CONFIG_NET_TCP_MAX_SEND_WINDOW_SIZE; +#else +#if defined(CONFIG_NET_BUF_FIXED_DATA_SIZE) + (CONFIG_NET_BUF_TX_COUNT * CONFIG_NET_BUF_DATA_SIZE) / 3; +#else + CONFIG_NET_BUF_DATA_POOL_SIZE / 3; +#endif /* CONFIG_NET_BUF_FIXED_DATA_SIZE */ +#endif #ifdef CONFIG_NET_TCP_RANDOMIZED_RTO #define TCP_RTO_MS (conn->rto) #else @@ -748,8 +758,10 @@ static int tcp_update_recv_wnd(struct tcp *conn, int32_t delta) bool short_win_after; new_win = conn->recv_win + delta; - if (new_win < 0 || new_win > UINT16_MAX) { - return -EINVAL; + if (new_win < 0) { + new_win = 0; + } else if (new_win > conn->recv_win_max) { + new_win = conn->recv_win_max; } short_win_before = tcp_short_window(conn); @@ -1416,12 +1428,10 @@ static void tcp_conn_ref(struct tcp *conn) NET_DBG("conn: %p, ref_count: %d", conn, ref_count); } -static struct tcp *tcp_conn_alloc(struct net_context *context) +static struct tcp *tcp_conn_alloc(void) { struct tcp *conn = NULL; int ret; - int recv_window = 0; - size_t len; ret = k_mem_slab_alloc(&tcp_conns_slab, (void **)&conn, K_NO_WAIT); if (ret) { @@ -1453,22 +1463,15 @@ static struct tcp *tcp_conn_alloc(struct net_context *context) conn->in_connect = false; conn->state = TCP_LISTEN; - conn->recv_win_max = tcp_window; + conn->recv_win_max = tcp_rx_window; + conn->recv_win = conn->recv_win_max; + conn->send_win_max = MAX(tcp_tx_window, NET_IPV6_MTU); + conn->send_win = conn->send_win_max; conn->tcp_nodelay = false; #ifdef CONFIG_NET_TCP_FAST_RETRANSMIT conn->dup_ack_cnt = 0; #endif - /* Set the recv_win with the rcvbuf configured for the socket. */ - if (IS_ENABLED(CONFIG_NET_CONTEXT_RCVBUF) && - net_context_get_option(context, NET_OPT_RCVBUF, &recv_window, &len) == 0) { - if (recv_window != 0) { - conn->recv_win_max = recv_window; - } - } - - conn->recv_win = conn->recv_win_max; - /* The ISN value will be set when we get the connection attempt or * when trying to create a connection. */ @@ -1509,7 +1512,7 @@ int net_tcp_get(struct net_context *context) k_mutex_lock(&tcp_lock, K_FOREVER); - conn = tcp_conn_alloc(context); + conn = tcp_conn_alloc(); if (conn == NULL) { ret = -ENOMEM; goto out; @@ -2017,6 +2020,45 @@ static void tcp_out_of_order_data(struct tcp *conn, struct net_pkt *pkt, tcp_queue_recv_data(conn, pkt, data_len, seq); } +static void tcp_check_sock_options(struct tcp *conn) +{ + int sndbuf_opt = 0; + int rcvbuf_opt = 0; + + if (IS_ENABLED(CONFIG_NET_CONTEXT_SNDBUF)) { + (void)net_context_get_option(conn->context, NET_OPT_SNDBUF, + &sndbuf_opt, NULL); + } + + if (IS_ENABLED(CONFIG_NET_CONTEXT_RCVBUF)) { + (void)net_context_get_option(conn->context, NET_OPT_RCVBUF, + &rcvbuf_opt, NULL); + } + + if (sndbuf_opt > 0 && sndbuf_opt != conn->send_win_max) { + k_mutex_lock(&conn->lock, K_FOREVER); + + conn->send_win_max = sndbuf_opt; + if (conn->send_win > conn->send_win_max) { + conn->send_win = conn->send_win_max; + } + + k_mutex_unlock(&conn->lock); + } + + if (rcvbuf_opt > 0 && rcvbuf_opt != conn->recv_win_max) { + int diff; + + k_mutex_lock(&conn->lock, K_FOREVER); + + diff = rcvbuf_opt - conn->recv_win_max; + conn->recv_win_max = rcvbuf_opt; + tcp_update_recv_wnd(conn, diff); + + k_mutex_unlock(&conn->lock); + } +} + /* TCP state machine, everything happens here */ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) { @@ -2031,7 +2073,6 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) struct k_fifo *recv_data_fifo; size_t len; int ret; - int sndbuf_opt = 0; int close_status = 0; enum net_verdict verdict = NET_DROP; @@ -2040,10 +2081,8 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) fl = th_flags(th) & ~(ECN | CWR); } - if (IS_ENABLED(CONFIG_NET_CONTEXT_SNDBUF) && - conn->state != TCP_SYN_SENT) { - (void)net_context_get_option(conn->context, NET_OPT_SNDBUF, - &sndbuf_opt, NULL); + if (conn->state != TCP_SYN_SENT) { + tcp_check_sock_options(conn); } k_mutex_lock(&conn->lock, K_FOREVER); @@ -2098,37 +2137,12 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt) } if (th) { - size_t max_win; - conn->send_win = ntohs(th_win(th)); + if (conn->send_win > conn->send_win_max) { + NET_DBG("Lowering send window from %u to %u", + conn->send_win, conn->send_win_max); -#if defined(CONFIG_NET_TCP_MAX_SEND_WINDOW_SIZE) - if (CONFIG_NET_TCP_MAX_SEND_WINDOW_SIZE) { - max_win = CONFIG_NET_TCP_MAX_SEND_WINDOW_SIZE; - } else -#endif - { - /* Adjust the window so that we do not run out of bufs - * while waiting acks. - */ -#if defined(CONFIG_NET_BUF_FIXED_DATA_SIZE) - max_win = (CONFIG_NET_BUF_TX_COUNT * - CONFIG_NET_BUF_DATA_SIZE) / 3; -#else - max_win = CONFIG_NET_BUF_DATA_POOL_SIZE / 3; -#endif /* CONFIG_NET_BUF_FIXED_DATA_SIZE */ - } - - if (sndbuf_opt > 0) { - max_win = sndbuf_opt; - } - - max_win = MAX(max_win, NET_IPV6_MTU); - if ((size_t)conn->send_win > max_win) { - NET_DBG("Lowering send window from %zd to %zd", - (size_t)conn->send_win, max_win); - - conn->send_win = max_win; + conn->send_win = conn->send_win_max; } if (conn->send_win == 0) { @@ -3257,7 +3271,7 @@ enum net_verdict tp_input(struct net_conn *net_conn, tp_new_find_and_apply(tp_new, "tcp_rto", &tcp_rto, TP_INT); tp_new_find_and_apply(tp_new, "tcp_retries", &tcp_retries, TP_INT); - tp_new_find_and_apply(tp_new, "tcp_window", &tcp_window, + tp_new_find_and_apply(tp_new, "tcp_window", &tcp_rx_window, TP_INT); tp_new_find_and_apply(tp_new, "tp_trace", &tp_trace, TP_BOOL); break; diff --git a/subsys/net/ip/tcp_private.h b/subsys/net/ip/tcp_private.h index 952e13939997..fc370d188b4b 100644 --- a/subsys/net/ip/tcp_private.h +++ b/subsys/net/ip/tcp_private.h @@ -267,6 +267,7 @@ struct tcp { /* TCP connection */ uint32_t ack; uint16_t recv_win_max; uint16_t recv_win; + uint16_t send_win_max; uint16_t send_win; #ifdef CONFIG_NET_TCP_RANDOMIZED_RTO uint16_t rto; From 159559b807ad6ff395eb1888392971d28fd063e4 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Mon, 13 Mar 2023 13:54:28 +0100 Subject: [PATCH 0492/1906] tests: net: sockets: tcp: Add SO_SNDTIMEO test cases Add test cases which verify that the TX timeouts configured with SO_SNDTIMEO work correctly. Signed-off-by: Robert Lubos --- tests/net/socket/tcp/prj.conf | 1 + tests/net/socket/tcp/src/main.c | 122 ++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/tests/net/socket/tcp/prj.conf b/tests/net/socket/tcp/prj.conf index ba0786ec6551..9a3b2361061d 100644 --- a/tests/net/socket/tcp/prj.conf +++ b/tests/net/socket/tcp/prj.conf @@ -43,5 +43,6 @@ CONFIG_ZTEST_NEW_API=y CONFIG_ZTEST_STACK_SIZE=2048 CONFIG_NET_CONTEXT_RCVTIMEO=y +CONFIG_NET_CONTEXT_SNDTIMEO=y CONFIG_NET_CONTEXT_RCVBUF=y CONFIG_NET_CONTEXT_SNDBUF=y diff --git a/tests/net/socket/tcp/src/main.c b/tests/net/socket/tcp/src/main.c index 49c28897aaac..7825a5ca748c 100644 --- a/tests/net/socket/tcp/src/main.c +++ b/tests/net/socket/tcp/src/main.c @@ -1373,6 +1373,128 @@ ZTEST(net_socket_tcp, test_v6_so_rcvtimeo) test_context_cleanup(); } +ZTEST(net_socket_tcp, test_v4_so_sndtimeo) +{ + int rv; + int c_sock; + int s_sock; + int new_sock; + struct sockaddr_in c_saddr; + struct sockaddr_in s_saddr; + struct sockaddr addr; + socklen_t addrlen = sizeof(addr); + uint32_t start_time, time_diff; + char tx_buf[] = TEST_STR_SMALL; + int buf_optval = sizeof(TEST_STR_SMALL); + struct timeval timeo_optval = { + .tv_sec = 0, + .tv_usec = 200000, + }; + + prepare_sock_tcp_v4(MY_IPV4_ADDR, ANY_PORT, &c_sock, &c_saddr); + prepare_sock_tcp_v4(MY_IPV4_ADDR, SERVER_PORT, &s_sock, &s_saddr); + + test_bind(s_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr)); + test_listen(s_sock); + + test_connect(c_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr)); + + test_accept(s_sock, &new_sock, &addr, &addrlen); + zassert_equal(addrlen, sizeof(struct sockaddr_in), "wrong addrlen"); + + rv = setsockopt(c_sock, SOL_SOCKET, SO_SNDTIMEO, &timeo_optval, + sizeof(timeo_optval)); + zassert_equal(rv, 0, "setsockopt failed (%d)", errno); + + /* Simulate window full scenario with SO_RCVBUF option. */ + rv = setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval, + sizeof(buf_optval)); + zassert_equal(rv, 0, "setsockopt failed (%d)", errno); + + rv = send(c_sock, tx_buf, sizeof(tx_buf), MSG_DONTWAIT); + zassert_equal(rv, sizeof(tx_buf), "Unexpected return code %d", rv); + + /* Wait for ACK (empty window). */ + k_msleep(150); + + /* Client should not be able to send now and time out after SO_SNDTIMEO */ + start_time = k_uptime_get_32(); + rv = send(c_sock, tx_buf, 1, 0); + time_diff = k_uptime_get_32() - start_time; + + zassert_equal(rv, -1, "Unexpected return code %d", rv); + zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno); + zassert_true(time_diff >= 200, "Expected timeout after 200ms but " + "was %dms", time_diff); + + test_close(c_sock); + test_close(new_sock); + test_close(s_sock); + + test_context_cleanup(); +} + +ZTEST(net_socket_tcp, test_v6_so_sndtimeo) +{ + int rv; + int c_sock; + int s_sock; + int new_sock; + struct sockaddr_in6 c_saddr; + struct sockaddr_in6 s_saddr; + struct sockaddr addr; + socklen_t addrlen = sizeof(addr); + uint32_t start_time, time_diff; + char tx_buf[] = TEST_STR_SMALL; + int buf_optval = sizeof(TEST_STR_SMALL); + struct timeval timeo_optval = { + .tv_sec = 0, + .tv_usec = 500000, + }; + + prepare_sock_tcp_v6(MY_IPV6_ADDR, ANY_PORT, &c_sock, &c_saddr); + prepare_sock_tcp_v6(MY_IPV6_ADDR, SERVER_PORT, &s_sock, &s_saddr); + + test_bind(s_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr)); + test_listen(s_sock); + + test_connect(c_sock, (struct sockaddr *)&s_saddr, sizeof(s_saddr)); + + test_accept(s_sock, &new_sock, &addr, &addrlen); + zassert_equal(addrlen, sizeof(struct sockaddr_in6), "wrong addrlen"); + + rv = setsockopt(c_sock, SOL_SOCKET, SO_SNDTIMEO, &timeo_optval, + sizeof(timeo_optval)); + zassert_equal(rv, 0, "setsockopt failed (%d)", errno); + + /* Simulate window full scenario with SO_RCVBUF option. */ + rv = setsockopt(new_sock, SOL_SOCKET, SO_RCVBUF, &buf_optval, + sizeof(buf_optval)); + zassert_equal(rv, 0, "setsockopt failed (%d)", errno); + + rv = send(c_sock, tx_buf, sizeof(tx_buf), MSG_DONTWAIT); + zassert_equal(rv, sizeof(tx_buf), "Unexpected return code %d", rv); + + /* Wait for ACK (empty window). */ + k_msleep(150); + + /* Client should not be able to send now and time out after SO_SNDTIMEO */ + start_time = k_uptime_get_32(); + rv = send(c_sock, tx_buf, 1, 0); + time_diff = k_uptime_get_32() - start_time; + + zassert_equal(rv, -1, "Unexpected return code %d", rv); + zassert_equal(errno, EAGAIN, "Unexpected errno value: %d", errno); + zassert_true(time_diff >= 500, "Expected timeout after 500ms but " + "was %dms", time_diff); + + test_close(c_sock); + test_close(new_sock); + test_close(s_sock); + + test_context_cleanup(); +} + struct test_msg_waitall_data { struct k_work_delayable tx_work; int sock; From 616797c4296c12a9de52d3e1973d33fff0666d38 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Mon, 13 Mar 2023 15:46:09 +0100 Subject: [PATCH 0493/1906] net: sockets: Add helper function for recalculating remaining timeout The timeout recalculation logic was duplicated across several routines, therefore it makes sense to make a helper function out of it, especially, that the same functionality would be needed for the send routines. Signed-off-by: Robert Lubos --- subsys/net/lib/sockets/sockets.c | 48 ++++++++++++-------------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/subsys/net/lib/sockets/sockets.c b/subsys/net/lib/sockets/sockets.c index b72c0751b3c4..6daef430ec5d 100644 --- a/subsys/net/lib/sockets/sockets.c +++ b/subsys/net/lib/sockets/sockets.c @@ -735,6 +735,20 @@ static int send_check_and_wait(struct net_context *ctx, int status, return -1; } +static void timeout_recalc(uint64_t end, k_timeout_t *timeout) +{ + if (!K_TIMEOUT_EQ(*timeout, K_NO_WAIT) && + !K_TIMEOUT_EQ(*timeout, K_FOREVER)) { + int64_t remaining = end - sys_clock_tick_get(); + + if (remaining <= 0) { + *timeout = K_NO_WAIT; + } else { + *timeout = Z_TIMEOUT_TICKS(remaining); + } + } +} + ssize_t zsock_sendto_ctx(struct net_context *ctx, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen) @@ -1340,16 +1354,7 @@ static inline ssize_t zsock_recv_stream(struct net_context *ctx, } /* Update the timeout value in case loop is repeated. */ - if (!K_TIMEOUT_EQ(timeout, K_NO_WAIT) && - !K_TIMEOUT_EQ(timeout, K_FOREVER)) { - int64_t remaining = end - sys_clock_tick_get(); - - if (remaining <= 0) { - timeout = K_NO_WAIT; - } else { - timeout = Z_TIMEOUT_TICKS(remaining); - } - } + timeout_recalc(end, &timeout); } while ((recv_len == 0) || (waitall && (recv_len < max_len))); if (!(flags & ZSOCK_MSG_PEEK)) { @@ -1629,16 +1634,7 @@ int zsock_poll_internal(struct zsock_pollfd *fds, int nfds, k_timeout_t timeout) fds, nfds, poll_timeout); } - if (!K_TIMEOUT_EQ(timeout, K_NO_WAIT) && - !K_TIMEOUT_EQ(timeout, K_FOREVER)) { - int64_t remaining = end - sys_clock_tick_get(); - - if (remaining <= 0) { - timeout = K_NO_WAIT; - } else { - timeout = Z_TIMEOUT_TICKS(remaining); - } - } + timeout_recalc(end, &timeout); do { ret = k_poll(poll_events, pev - poll_events, timeout); @@ -1697,19 +1693,11 @@ int zsock_poll_internal(struct zsock_pollfd *fds, int nfds, k_timeout_t timeout) break; } + timeout_recalc(end, &timeout); + if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) { break; } - - if (!K_TIMEOUT_EQ(timeout, K_FOREVER)) { - int64_t remaining = end - sys_clock_tick_get(); - - if (remaining <= 0) { - break; - } else { - timeout = Z_TIMEOUT_TICKS(remaining); - } - } } } while (retry); From 66ae9153a67285cb0c5fdd6d6b2435ebbe9b8836 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Mon, 13 Mar 2023 15:48:25 +0100 Subject: [PATCH 0494/1906] net: sockets: Fix SO_SNDTIMEO handling The TX timeout configured with SO_SNDTIMEO on a socket did not work properly. If the timeout was set on a socket, the TX would work as if the socket was put into non-blocking mode. This commit fixes this. Signed-off-by: Robert Lubos --- subsys/net/lib/sockets/sockets.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/subsys/net/lib/sockets/sockets.c b/subsys/net/lib/sockets/sockets.c index 6daef430ec5d..da462efd85ab 100644 --- a/subsys/net/lib/sockets/sockets.c +++ b/subsys/net/lib/sockets/sockets.c @@ -669,7 +669,7 @@ static int send_check_and_wait(struct net_context *ctx, int status, { int64_t remaining; - if (!K_TIMEOUT_EQ(timeout, K_FOREVER)) { + if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) { goto out; } @@ -695,6 +695,11 @@ static int send_check_and_wait(struct net_context *ctx, int status, goto out; } + if (!K_TIMEOUT_EQ(timeout, K_FOREVER)) { + *retry_timeout = + MIN(*retry_timeout, k_ticks_to_ms_floor32(timeout.ticks)); + } + if (ctx->cond.lock) { (void)k_mutex_unlock(ctx->cond.lock); } @@ -756,6 +761,7 @@ ssize_t zsock_sendto_ctx(struct net_context *ctx, const void *buf, size_t len, k_timeout_t timeout = K_FOREVER; uint32_t retry_timeout = WAIT_BUFS_INITIAL_MS; uint64_t buf_timeout = 0; + uint64_t end; int status; if ((flags & ZSOCK_MSG_DONTWAIT) || sock_is_nonblock(ctx)) { @@ -765,6 +771,8 @@ ssize_t zsock_sendto_ctx(struct net_context *ctx, const void *buf, size_t len, buf_timeout = sys_clock_timeout_end_calc(MAX_WAIT_BUFS); } + end = sys_clock_timeout_end_calc(timeout); + /* Register the callback before sending in order to receive the response * from the peer. */ @@ -792,6 +800,9 @@ ssize_t zsock_sendto_ctx(struct net_context *ctx, const void *buf, size_t len, return status; } + /* Update the timeout value in case loop is repeated. */ + timeout_recalc(end, &timeout); + continue; } @@ -846,6 +857,7 @@ ssize_t zsock_sendmsg_ctx(struct net_context *ctx, const struct msghdr *msg, k_timeout_t timeout = K_FOREVER; uint32_t retry_timeout = WAIT_BUFS_INITIAL_MS; uint64_t buf_timeout = 0; + uint64_t end; int status; if ((flags & ZSOCK_MSG_DONTWAIT) || sock_is_nonblock(ctx)) { @@ -855,6 +867,8 @@ ssize_t zsock_sendmsg_ctx(struct net_context *ctx, const struct msghdr *msg, buf_timeout = sys_clock_timeout_end_calc(MAX_WAIT_BUFS); } + end = sys_clock_timeout_end_calc(timeout); + while (1) { status = net_context_sendmsg(ctx, msg, flags, NULL, timeout, NULL); if (status < 0) { @@ -866,6 +880,9 @@ ssize_t zsock_sendmsg_ctx(struct net_context *ctx, const struct msghdr *msg, return status; } + /* Update the timeout value in case loop is repeated. */ + timeout_recalc(end, &timeout); + continue; } } From 45d9960bc631fd3b235e5c231bbdb6eb39ba1b11 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Thu, 2 Mar 2023 16:28:09 +0100 Subject: [PATCH 0495/1906] samples: net: sockets: echo_client: Fix userspace crash k_work_* APIs cannot be used from user threads, hence it has to be replaced with some other solution to retain userspace functionality in the sample. This commit reworks the sample as follows: * Replace delayed work items with combination of k_timer and a dedicated thread to send UDP packets. k_poll_signal is used for communication between k_timer callback and UDP thread. * As kernel objects should not be placed in a memory modifiable from user threads, declare a separate structure for them, and link it with the client context structure with a pointer. * k_timer_init() is not a system call, therefore it has to be called from supervisor thread. Therefore, add an additional function to initialize UDP, and use it to initialize kernel objects used by the UDP module and grant access for the main thread before it becomes an user thread. UDP thread inherits permissions from the parent (main thread). Signed-off-by: Robert Lubos --- samples/net/sockets/echo_client/src/common.h | 18 +- .../net/sockets/echo_client/src/echo-client.c | 1 + samples/net/sockets/echo_client/src/udp.c | 159 +++++++++++++++--- 3 files changed, 150 insertions(+), 28 deletions(-) diff --git a/samples/net/sockets/echo_client/src/common.h b/samples/net/sockets/echo_client/src/common.h index 83f5ec27e46d..debfa3fbb652 100644 --- a/samples/net/sockets/echo_client/src/common.h +++ b/samples/net/sockets/echo_client/src/common.h @@ -5,6 +5,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + /* Value of 0 will cause the IP stack to select next free port */ #define MY_PORT 0 @@ -27,17 +29,23 @@ extern struct k_mem_domain app_domain; #define THREAD_PRIORITY K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1) #endif +#define UDP_STACK_SIZE 2048 + +struct udp_control { + struct k_poll_signal tx_signal; + struct k_timer tx_timer; + struct k_timer rx_timer; +}; + struct data { const char *proto; struct { int sock; - /* Work controlling udp data sending */ - struct k_work_delayable recv; - struct k_work_delayable transmit; uint32_t expecting; uint32_t counter; uint32_t mtu; + struct udp_control *ctrl; } udp; struct { @@ -65,6 +73,10 @@ extern const char lorem_ipsum[]; extern const int ipsum_len; extern struct configs conf; +/* init_udp initializes kernel objects, hence it has to be called from + * supervisor thread. + */ +void init_udp(void); int start_udp(void); int process_udp(void); void stop_udp(void); diff --git a/samples/net/sockets/echo_client/src/echo-client.c b/samples/net/sockets/echo_client/src/echo-client.c index 84c6322f5619..b089774cc3ea 100644 --- a/samples/net/sockets/echo_client/src/echo-client.c +++ b/samples/net/sockets/echo_client/src/echo-client.c @@ -275,6 +275,7 @@ static void init_app(void) } init_vlan(); + init_udp(); } static int start_client(void) diff --git a/samples/net/sockets/echo_client/src/udp.c b/samples/net/sockets/echo_client/src/udp.c index 62b3490070bd..6b52615ff280 100644 --- a/samples/net/sockets/echo_client/src/udp.c +++ b/samples/net/sockets/echo_client/src/udp.c @@ -27,6 +27,111 @@ LOG_MODULE_DECLARE(net_echo_client_sample, LOG_LEVEL_DBG); static APP_BMEM char recv_buf[RECV_BUF_SIZE]; +static K_THREAD_STACK_DEFINE(udp_tx_thread_stack, UDP_STACK_SIZE); +static struct k_thread udp_tx_thread; + +/* Kernel objects should not be placed in a memory area accessible from user + * threads. + */ +static struct udp_control udp4_ctrl, udp6_ctrl; +static struct k_poll_signal udp_kill; + +static int send_udp_data(struct data *data); +static void wait_reply(struct k_timer *timer); +static void wait_transmit(struct k_timer *timer); + +static void process_udp_tx(void) +{ + struct k_poll_event events[] = { + K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, + K_POLL_MODE_NOTIFY_ONLY, + &udp_kill), +#if defined(CONFIG_NET_IPV4) + K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, + K_POLL_MODE_NOTIFY_ONLY, + &udp4_ctrl.tx_signal), +#endif +#if defined(CONFIG_NET_IPV6) + K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, + K_POLL_MODE_NOTIFY_ONLY, + &udp6_ctrl.tx_signal), +#endif + }; + + while (true) { + k_poll(events, ARRAY_SIZE(events), K_FOREVER); + + for (int i = 0; i < ARRAY_SIZE(events); i++) { + unsigned int signaled; + int result; + + k_poll_signal_check(events[i].signal, &signaled, &result); + if (signaled == 0) { + continue; + } + + k_poll_signal_reset(events[i].signal); + events[i].state = K_POLL_STATE_NOT_READY; + + if (events[i].signal == &udp_kill) { + return; + } else if (events[i].signal == &udp4_ctrl.tx_signal) { + send_udp_data(&conf.ipv4); + } else if (events[i].signal == &udp6_ctrl.tx_signal) { + send_udp_data(&conf.ipv6); + } + } + } +} + +static void udp_control_init(struct udp_control *ctrl) +{ + k_timer_init(&ctrl->rx_timer, wait_reply, NULL); + k_timer_init(&ctrl->tx_timer, wait_transmit, NULL); + k_poll_signal_init(&ctrl->tx_signal); +} + +static void udp_control_access_grant(struct udp_control *ctrl) +{ + k_thread_access_grant(k_current_get(), + &ctrl->rx_timer, + &ctrl->tx_timer, + &ctrl->tx_signal); +} + +void init_udp(void) +{ + /* k_timer_init() is not a system call, therefore initialize kernel + * objects here. + */ + if (IS_ENABLED(CONFIG_NET_IPV4)) { + udp_control_init(&udp4_ctrl); + conf.ipv4.udp.ctrl = &udp4_ctrl; + } + + if (IS_ENABLED(CONFIG_NET_IPV6)) { + udp_control_init(&udp6_ctrl); + conf.ipv6.udp.ctrl = &udp6_ctrl; + } + + k_poll_signal_init(&udp_kill); + + if (IS_ENABLED(CONFIG_USERSPACE)) { + k_thread_access_grant(k_current_get(), + &udp_tx_thread, + &udp_tx_thread_stack, + &udp_kill); + + if (IS_ENABLED(CONFIG_NET_IPV4)) { + udp_control_access_grant(&udp4_ctrl); + } + + if (IS_ENABLED(CONFIG_NET_IPV6)) { + udp_control_access_grant(&udp6_ctrl); + } + } +} + static int send_udp_data(struct data *data) { int ret; @@ -40,7 +145,7 @@ static int send_udp_data(struct data *data) LOG_DBG("%s UDP: Sent %d bytes", data->proto, data->udp.expecting); - k_work_reschedule(&data->udp.recv, UDP_WAIT); + k_timer_start(&data->udp.ctrl->rx_timer, UDP_WAIT, K_NO_WAIT); return ret < 0 ? -EIO : 0; } @@ -60,24 +165,23 @@ static int compare_udp_data(struct data *data, const char *buf, uint32_t receive return 0; } -static void wait_reply(struct k_work *work) +static void wait_reply(struct k_timer *timer) { - struct k_work_delayable *dwork = k_work_delayable_from_work(work); /* This means that we did not receive response in time. */ - struct data *data = CONTAINER_OF(dwork, struct data, udp.recv); + struct udp_control *ctrl = CONTAINER_OF(timer, struct udp_control, rx_timer); + struct data *data = (ctrl == conf.ipv4.udp.ctrl) ? &conf.ipv4 : &conf.ipv6; LOG_ERR("UDP %s: Data packet not received", data->proto); /* Send a new packet at this point */ - send_udp_data(data); + k_poll_signal_raise(&ctrl->tx_signal, 0); } -static void wait_transmit(struct k_work *work) +static void wait_transmit(struct k_timer *timer) { - struct k_work_delayable *dwork = k_work_delayable_from_work(work); - struct data *data = CONTAINER_OF(dwork, struct data, udp.transmit); + struct udp_control *ctrl = CONTAINER_OF(timer, struct udp_control, tx_timer); - send_udp_data(data); + k_poll_signal_raise(&ctrl->tx_signal, 0); } static int start_udp_proto(struct data *data, struct sockaddr *addr, @@ -85,9 +189,6 @@ static int start_udp_proto(struct data *data, struct sockaddr *addr, { int ret; - k_work_init_delayable(&data->udp.recv, wait_reply); - k_work_init_delayable(&data->udp.transmit, wait_transmit); - #if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS) data->udp.sock = socket(addr->sa_family, SOCK_DGRAM, IPPROTO_DTLS_1_2); #else @@ -170,14 +271,13 @@ static int process_udp_proto(struct data *data) data->udp.counter); } - k_work_cancel_delayable(&data->udp.recv); + k_timer_stop(&data->udp.ctrl->rx_timer); /* Do not flood the link if we have also TCP configured */ if (IS_ENABLED(CONFIG_NET_TCP)) { - k_work_reschedule(&data->udp.transmit, UDP_SLEEP); - ret = 0; + k_timer_start(&data->udp.ctrl->tx_timer, UDP_SLEEP, K_NO_WAIT); } else { - ret = send_udp_data(data); + k_poll_signal_raise(&data->udp.ctrl->tx_signal, 0); } return ret; @@ -215,15 +315,22 @@ int start_udp(void) } } + k_thread_create(&udp_tx_thread, udp_tx_thread_stack, + K_THREAD_STACK_SIZEOF(udp_tx_thread_stack), + (k_thread_entry_t)process_udp_tx, + NULL, NULL, NULL, THREAD_PRIORITY, + IS_ENABLED(CONFIG_USERSPACE) ? + K_USER | K_INHERIT_PERMS : 0, + K_NO_WAIT); + + k_thread_name_set(&udp_tx_thread, "udp_tx"); + if (IS_ENABLED(CONFIG_NET_IPV6)) { - ret = send_udp_data(&conf.ipv6); - if (ret < 0) { - return ret; - } + k_poll_signal_raise(&conf.ipv6.udp.ctrl->tx_signal, 0); } if (IS_ENABLED(CONFIG_NET_IPV4)) { - ret = send_udp_data(&conf.ipv4); + k_poll_signal_raise(&conf.ipv4.udp.ctrl->tx_signal, 0); } return ret; @@ -253,8 +360,8 @@ int process_udp(void) void stop_udp(void) { if (IS_ENABLED(CONFIG_NET_IPV6)) { - k_work_cancel_delayable(&conf.ipv6.udp.recv); - k_work_cancel_delayable(&conf.ipv6.udp.transmit); + k_timer_stop(&udp6_ctrl.tx_timer); + k_timer_stop(&udp6_ctrl.rx_timer); if (conf.ipv6.udp.sock >= 0) { (void)close(conf.ipv6.udp.sock); @@ -262,11 +369,13 @@ void stop_udp(void) } if (IS_ENABLED(CONFIG_NET_IPV4)) { - k_work_cancel_delayable(&conf.ipv4.udp.recv); - k_work_cancel_delayable(&conf.ipv4.udp.transmit); + k_timer_stop(&udp4_ctrl.tx_timer); + k_timer_stop(&udp4_ctrl.rx_timer); if (conf.ipv4.udp.sock >= 0) { (void)close(conf.ipv4.udp.sock); } } + + k_poll_signal_raise(&udp_kill, 0); } From a7a051801be010f844bc7a480088e6bb443e4f2b Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Fri, 17 Mar 2023 14:43:31 +0100 Subject: [PATCH 0496/1906] boards: arm: nordic: Cleanup timers setup All boards were enabling timer0-2 instances. Git history shows that it is the result of copy-pasting. It is redundant thus removing. Signed-off-by: Krzysztof Chruscinski --- .../arm/actinius_icarus/actinius_icarus_common.dts | 12 ------------ .../actinius_icarus_bee_common.dts | 12 ------------ .../actinius_icarus_som_common.dts | 12 ------------ .../actinius_icarus_som_dk_common.dts | 12 ------------ boards/arm/bl5340_dvk/bl5340_dvk_cpuapp_common.dts | 12 ------------ boards/arm/bl5340_dvk/bl5340_dvk_cpunet.dts | 12 ------------ .../circuitdojo_feather_nrf9160_common.dts | 12 ------------ .../nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi | 12 ------------ .../nrf5340_audio_dk_nrf5340_cpunet.dts | 12 ------------ .../arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common.dts | 12 ------------ .../nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpunet.dts | 12 ------------ .../nrf9160_innblue21/nrf9160_innblue21_common.dts | 12 ------------ .../nrf9160_innblue22/nrf9160_innblue22_common.dts | 12 ------------ .../nrf9160dk_nrf9160/nrf9160dk_nrf9160_common.dts | 12 ------------ .../sparkfun_thing_plus_nrf9160_common.dts | 12 ------------ .../arm/thingy53_nrf5340/thingy53_nrf5340_common.dts | 12 ------------ .../arm/thingy53_nrf5340/thingy53_nrf5340_cpunet.dts | 12 ------------ 17 files changed, 204 deletions(-) diff --git a/boards/arm/actinius_icarus/actinius_icarus_common.dts b/boards/arm/actinius_icarus/actinius_icarus_common.dts index a98231ace4d3..65bb762097e3 100644 --- a/boards/arm/actinius_icarus/actinius_icarus_common.dts +++ b/boards/arm/actinius_icarus/actinius_icarus_common.dts @@ -164,18 +164,6 @@ pinctrl-names = "default", "sleep"; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash0 { partitions { compatible = "fixed-partitions"; diff --git a/boards/arm/actinius_icarus_bee/actinius_icarus_bee_common.dts b/boards/arm/actinius_icarus_bee/actinius_icarus_bee_common.dts index 6934b1bb8da1..a12c85197c19 100644 --- a/boards/arm/actinius_icarus_bee/actinius_icarus_bee_common.dts +++ b/boards/arm/actinius_icarus_bee/actinius_icarus_bee_common.dts @@ -155,18 +155,6 @@ pinctrl-names = "default", "sleep"; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash0 { partitions { compatible = "fixed-partitions"; diff --git a/boards/arm/actinius_icarus_som/actinius_icarus_som_common.dts b/boards/arm/actinius_icarus_som/actinius_icarus_som_common.dts index 14240fca8fad..23303c9497ed 100644 --- a/boards/arm/actinius_icarus_som/actinius_icarus_som_common.dts +++ b/boards/arm/actinius_icarus_som/actinius_icarus_som_common.dts @@ -65,18 +65,6 @@ }; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash0 { partitions { compatible = "fixed-partitions"; diff --git a/boards/arm/actinius_icarus_som_dk/actinius_icarus_som_dk_common.dts b/boards/arm/actinius_icarus_som_dk/actinius_icarus_som_dk_common.dts index 458c68de9d0d..6a97ac14eb36 100644 --- a/boards/arm/actinius_icarus_som_dk/actinius_icarus_som_dk_common.dts +++ b/boards/arm/actinius_icarus_som_dk/actinius_icarus_som_dk_common.dts @@ -154,18 +154,6 @@ neopixel_spi: &spi1 { pinctrl-names = "default", "sleep"; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash0 { partitions { compatible = "fixed-partitions"; diff --git a/boards/arm/bl5340_dvk/bl5340_dvk_cpuapp_common.dts b/boards/arm/bl5340_dvk/bl5340_dvk_cpuapp_common.dts index 6101acdbe255..be8ee3710fcc 100644 --- a/boards/arm/bl5340_dvk/bl5340_dvk_cpuapp_common.dts +++ b/boards/arm/bl5340_dvk/bl5340_dvk_cpuapp_common.dts @@ -235,18 +235,6 @@ pinctrl-names = "default", "sleep"; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &qspi { status = "okay"; pinctrl-0 = <&qspi_default>; diff --git a/boards/arm/bl5340_dvk/bl5340_dvk_cpunet.dts b/boards/arm/bl5340_dvk/bl5340_dvk_cpunet.dts index 4a75d608af91..1add49835bc0 100644 --- a/boards/arm/bl5340_dvk/bl5340_dvk_cpunet.dts +++ b/boards/arm/bl5340_dvk/bl5340_dvk_cpunet.dts @@ -48,18 +48,6 @@ pinctrl-names = "default", "sleep"; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash1 { partitions { compatible = "fixed-partitions"; diff --git a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_common.dts b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_common.dts index d80922491071..44c483f84f67 100644 --- a/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_common.dts +++ b/boards/arm/circuitdojo_feather_nrf9160/circuitdojo_feather_nrf9160_common.dts @@ -171,18 +171,6 @@ }; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash0 { partitions { diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi index 66c829570335..d603c019c575 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_common.dtsi @@ -229,18 +229,6 @@ pinctrl-names = "default", "sleep"; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash0 { partitions { compatible = "fixed-partitions"; diff --git a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpunet.dts b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpunet.dts index 100216f1a43f..11244f82c5cb 100644 --- a/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpunet.dts +++ b/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpunet.dts @@ -46,18 +46,6 @@ pinctrl-names = "default", "sleep"; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash1 { partitions { diff --git a/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common.dts b/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common.dts index 4ba125fc9e00..220256ec78bf 100644 --- a/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common.dts +++ b/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common.dts @@ -198,18 +198,6 @@ }; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - arduino_serial: &uart1 { compatible = "nordic,nrf-uarte"; current-speed = <115200>; diff --git a/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpunet.dts b/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpunet.dts index f45e0619b1af..61403bc1d579 100644 --- a/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpunet.dts +++ b/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpunet.dts @@ -153,18 +153,6 @@ arduino_spi: &spi0 { pinctrl-names = "default", "sleep"; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash1 { partitions { diff --git a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_common.dts b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_common.dts index e5180382ee47..880f0eea7e65 100644 --- a/boards/arm/nrf9160_innblue21/nrf9160_innblue21_common.dts +++ b/boards/arm/nrf9160_innblue21/nrf9160_innblue21_common.dts @@ -157,18 +157,6 @@ pinctrl-names = "default", "sleep"; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash0 { partitions { diff --git a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_common.dts b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_common.dts index f7f7b471cd4a..f4be692993c3 100644 --- a/boards/arm/nrf9160_innblue22/nrf9160_innblue22_common.dts +++ b/boards/arm/nrf9160_innblue22/nrf9160_innblue22_common.dts @@ -160,18 +160,6 @@ pinctrl-names = "default", "sleep"; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash0 { partitions { diff --git a/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_common.dts b/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_common.dts index f0706aa70daa..02fbac841ab4 100644 --- a/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_common.dts +++ b/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_common.dts @@ -211,18 +211,6 @@ arduino_spi: &spi3 { pinctrl-names = "default", "sleep"; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash0 { partitions { diff --git a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_common.dts b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_common.dts index 79f44d03bf1e..88adec18728a 100644 --- a/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_common.dts +++ b/boards/arm/sparkfun_thing_plus_nrf9160/sparkfun_thing_plus_nrf9160_common.dts @@ -162,18 +162,6 @@ }; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash0 { partitions { compatible = "fixed-partitions"; diff --git a/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dts b/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dts index 4c5b1d91b13b..62403423b9c5 100644 --- a/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dts +++ b/boards/arm/thingy53_nrf5340/thingy53_nrf5340_common.dts @@ -249,18 +249,6 @@ }; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash0 { partitions { compatible = "fixed-partitions"; diff --git a/boards/arm/thingy53_nrf5340/thingy53_nrf5340_cpunet.dts b/boards/arm/thingy53_nrf5340/thingy53_nrf5340_cpunet.dts index e1461288e810..25eefde08ab6 100644 --- a/boards/arm/thingy53_nrf5340/thingy53_nrf5340_cpunet.dts +++ b/boards/arm/thingy53_nrf5340/thingy53_nrf5340_cpunet.dts @@ -94,18 +94,6 @@ pinctrl-names = "default", "sleep"; }; -&timer0 { - status = "okay"; -}; - -&timer1 { - status = "okay"; -}; - -&timer2 { - status = "okay"; -}; - &flash1 { partitions { From 656b0e642698be47b44931ea1b81ccf60f4b34cb Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Thu, 16 Mar 2023 13:48:40 +0100 Subject: [PATCH 0497/1906] drivers: counter: Adapt to use device tree Modifying counter drivers (rtc and timer) to rely completely on device tree and not on Kconfig of MDK flags. Adapting dtsi for all SoCs and adapting test configuration. Signed-off-by: Krzysztof Chruscinski --- drivers/counter/Kconfig.nrfx | 108 ++------------ drivers/counter/counter_nrfx_rtc.c | 59 ++++---- drivers/counter/counter_nrfx_timer.c | 135 ++++++++---------- dts/arm/nordic/nrf51822.dtsi | 13 +- dts/arm/nordic/nrf52805.dtsi | 13 +- dts/arm/nordic/nrf52810.dtsi | 13 +- dts/arm/nordic/nrf52811.dtsi | 13 +- dts/arm/nordic/nrf52820.dtsi | 16 ++- dts/arm/nordic/nrf52832.dtsi | 21 +-- dts/arm/nordic/nrf52833.dtsi | 21 +-- dts/arm/nordic/nrf52840.dtsi | 21 +-- .../nordic/nrf5340_cpuapp_peripherals.dtsi | 7 +- dts/arm/nordic/nrf5340_cpunet.dtsi | 7 +- dts/arm/nordic/nrf9160_common.dtsi | 7 +- dts/bindings/rtc/nordic,nrf-rtc.yaml | 4 + dts/bindings/timer/nordic,nrf-timer.yaml | 9 ++ samples/boards/nrf/clock_skew/app.overlay | 3 + samples/boards/nrf/clock_skew/prj.conf | 2 - .../boards/nrf51dk_nrf51422.conf | 4 - .../boards/nrf51dk_nrf51422.overlay | 8 ++ .../boards/nrf52833dk_nrf52833.conf | 7 - .../boards/nrf52833dk_nrf52833.overlay | 10 ++ .../boards/nrf52840dk_nrf52811.conf | 4 - .../boards/nrf52840dk_nrf52811.overlay | 8 ++ .../boards/nrf52840dk_nrf52840.conf | 7 - .../boards/nrf52840dk_nrf52840.overlay | 10 ++ .../boards/nrf52840dk_nrf52840_zli.conf | 14 -- .../boards/nrf52840dk_nrf52840_zli.overlay | 23 +++ .../boards/nrf52dk_nrf52810.conf | 4 - .../boards/nrf52dk_nrf52810.overlay | 8 ++ .../boards/nrf52dk_nrf52832.conf | 7 - .../boards/nrf52dk_nrf52832.overlay | 15 ++ .../boards/nrf9160dk_nrf9160.conf | 4 - .../boards/nrf9160dk_nrf9160.overlay | 8 ++ .../counter_basic_api/src/test_counter.c | 69 +-------- .../counter/counter_basic_api/testcase.yaml | 6 +- .../fixed_top/boards/nrf52840dk_nrf52840.conf | 2 - .../fixed_top/nrf52840dk_nrf52840.overlay | 2 + .../fixed_top/src/test_counter_fixed_top.c | 42 +++--- .../boards/nrf52840dk_nrf52840.conf | 2 - .../boards/nrf52840dk_nrf52840.overlay | 4 + .../boards/nrf5340dk_nrf5340_cpuapp.conf | 2 - .../boards/nrf5340dk_nrf5340_cpuapp.overlay | 4 + .../boards/nrf9160dk_nrf9160.conf | 2 - .../boards/nrf9160dk_nrf9160.overlay | 4 + .../drivers/uart/uart_mix_fifo_poll/prj.conf | 1 + .../boards/nrf52840dk_nrf52840_counter.conf | 4 - .../nrf52840dk_nrf52840_counter.overlay | 1 + .../busy_sim/boards/nrf52840dk_nrf52840.conf | 1 - 49 files changed, 347 insertions(+), 412 deletions(-) create mode 100644 samples/boards/nrf/clock_skew/app.overlay delete mode 100644 tests/drivers/counter/counter_basic_api/boards/nrf51dk_nrf51422.conf delete mode 100644 tests/drivers/counter/counter_basic_api/boards/nrf52833dk_nrf52833.conf delete mode 100644 tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52811.conf delete mode 100644 tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840.conf delete mode 100644 tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840_zli.conf create mode 100644 tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840_zli.overlay delete mode 100644 tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52810.conf delete mode 100644 tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52832.conf delete mode 100644 tests/drivers/counter/counter_basic_api/boards/nrf9160dk_nrf9160.conf delete mode 100644 tests/drivers/counter/counter_nrf_rtc/fixed_top/boards/nrf52840dk_nrf52840.conf delete mode 100644 tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.conf delete mode 100644 tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.conf delete mode 100644 tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.conf delete mode 100644 tests/ztest/busy_sim/boards/nrf52840dk_nrf52840.conf diff --git a/drivers/counter/Kconfig.nrfx b/drivers/counter/Kconfig.nrfx index 17d1e09bcbde..321cf9de6347 100644 --- a/drivers/counter/Kconfig.nrfx +++ b/drivers/counter/Kconfig.nrfx @@ -2,109 +2,25 @@ # SPDX-License-Identifier: Apache-2.0 config COUNTER_NRF_TIMER - bool + def_bool y + depends on DT_HAS_NORDIC_NRF_TIMER_ENABLED config COUNTER_NRF_RTC - bool - -config COUNTER_TIMER0 - bool "Counter on TIMER0" - depends on HAS_HW_NRF_TIMER0 - depends on !NRF_HW_TIMER0_RESERVED - select COUNTER_NRF_TIMER - -config COUNTER_TIMER0_ZLI - bool "Event in ZLI interrupt context" - depends on COUNTER_TIMER0 - depends on ZERO_LATENCY_IRQS - -config COUNTER_TIMER1 - bool "Counter on TIMER1" - depends on HAS_HW_NRF_TIMER1 - depends on !NRF_HW_TIMER1_RESERVED - select COUNTER_NRF_TIMER - -config COUNTER_TIMER1_ZLI - bool "Event in ZLI interrupt context" - depends on COUNTER_TIMER1 - depends on ZERO_LATENCY_IRQS - -config COUNTER_TIMER2 - bool "Counter on TIMER2" - depends on HAS_HW_NRF_TIMER2 - depends on !NRF_HW_TIMER2_RESERVED - select COUNTER_NRF_TIMER - -config COUNTER_TIMER2_ZLI - bool "Event in ZLI interrupt context" - depends on COUNTER_TIMER2 - depends on ZERO_LATENCY_IRQS - -config COUNTER_TIMER3 - bool "Counter on TIMER3" - depends on HAS_HW_NRF_TIMER3 - depends on !NRF_HW_TIMER3_RESERVED - select COUNTER_NRF_TIMER - -config COUNTER_TIMER3_ZLI - bool "Event in ZLI interrupt context" - depends on COUNTER_TIMER3 - depends on ZERO_LATENCY_IRQS - -config COUNTER_TIMER4 - bool "Counter on TIMER4" - depends on HAS_HW_NRF_TIMER4 - depends on !NRF_HW_TIMER4_RESERVED - select COUNTER_NRF_TIMER - -config COUNTER_TIMER4_ZLI - bool "Event in ZLI interrupt context" - depends on COUNTER_TIMER4 - depends on ZERO_LATENCY_IRQS - -config COUNTER_RTC0 - bool "Counter on RTC0" - depends on HAS_HW_NRF_RTC0 - depends on !NRF_HW_RTC0_RESERVED - select COUNTER_NRF_RTC - -config COUNTER_RTC0_ZLI - bool "Event in ZLI interrupt context" - depends on COUNTER_RTC0 - depends on ZERO_LATENCY_IRQS - -config COUNTER_RTC1 - bool "Counter on RTC1" - depends on HAS_HW_NRF_RTC1 - depends on !NRF_HW_RTC1_RESERVED - select COUNTER_NRF_RTC - -config COUNTER_RTC1_ZLI - bool "Event in ZLI interrupt context" - depends on COUNTER_RTC1 - depends on ZERO_LATENCY_IRQS - -config COUNTER_RTC2 - bool "Counter on RTC2" - depends on HAS_HW_NRF_RTC2 - depends on !NRF_HW_RTC2_RESERVED - select COUNTER_NRF_RTC - -config COUNTER_RTC2_ZLI - bool "Event in ZLI interrupt context" - depends on COUNTER_RTC2 - depends on ZERO_LATENCY_IRQS + def_bool y + depends on DT_HAS_NORDIC_NRF_RTC_ENABLED # Internal flag which detects if PPI wrap feature is enabled for any instance config COUNTER_RTC_WITH_PPI_WRAP - def_bool ($(dt_nodelabel_bool_prop,rtc0,ppi-wrap) && COUNTER_RTC0) || \ - ($(dt_nodelabel_bool_prop,rtc1,ppi-wrap) && COUNTER_RTC1) || \ - ($(dt_nodelabel_bool_prop,rtc2,ppi-wrap) && COUNTER_RTC2) + def_bool $(dt_nodelabel_bool_prop,rtc0,ppi-wrap) || \ + $(dt_nodelabel_bool_prop,rtc1,ppi-wrap) || \ + $(dt_nodelabel_bool_prop,rtc2,ppi-wrap) + depends on COUNTER_NRF_RTC select NRFX_PPI if HAS_HW_NRF_PPI select NRFX_DPPI if HAS_HW_NRF_DPPIC # Internal flag which detects if fixed top feature is enabled for any instance config COUNTER_RTC_CUSTOM_TOP_SUPPORT - def_bool (!$(dt_nodelabel_bool_prop,rtc0,fixed-top) && COUNTER_RTC0) || \ - (!$(dt_nodelabel_bool_prop,rtc1,fixed-top) && COUNTER_RTC1) || \ - (!$(dt_nodelabel_bool_prop,rtc2,fixed-top) && COUNTER_RTC2) + def_bool !$(dt_nodelabel_bool_prop,rtc0,fixed-top) || \ + !$(dt_nodelabel_bool_prop,rtc1,fixed-top) || \ + !$(dt_nodelabel_bool_prop,rtc2,fixed-top) + depends on COUNTER_NRF_RTC diff --git a/drivers/counter/counter_nrfx_rtc.c b/drivers/counter/counter_nrfx_rtc.c index 7d97a97469f4..b21f49d60f07 100644 --- a/drivers/counter/counter_nrfx_rtc.c +++ b/drivers/counter/counter_nrfx_rtc.c @@ -30,6 +30,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_COUNTER_LOG_LEVEL); #define DBG(...) LOG_INST_DBG( \ ((const struct counter_nrfx_config *)dev->config)->log, __VA_ARGS__) +#define DT_DRV_COMPAT nordic_nrf_rtc + #define COUNTER_MAX_TOP_VALUE RTC_COUNTER_COUNTER_Msk #define COUNTER_GET_TOP_CH(dev) counter_get_num_of_channels(dev) @@ -388,7 +390,7 @@ static int ppi_setup(const struct device *dev, uint8_t chan) } nrf_rtc_subscribe_set(rtc, NRF_RTC_TASK_CLEAR, data->ppi_ch); - nrf_rtc_publish_set(rtc->p_reg, evt, data->ppi_ch); + nrf_rtc_publish_set(rtc, evt, data->ppi_ch); (void)nrfx_dppi_channel_enable(data->ppi_ch); #else /* DPPI_PRESENT */ uint32_t evt_addr; @@ -422,7 +424,6 @@ static void ppi_free(const struct device *dev, uint8_t chan) } nrf_rtc_event_disable(rtc, RTC_CHANNEL_INT_MASK(chan)); #ifdef DPPI_PRESENT - NRF_RTC_Type *rtc = nrfx_config->rtc; nrf_rtc_event_t evt = RTC_CHANNEL_EVENT_ADDR(chan); (void)nrfx_dppi_channel_disable(ppi_ch); @@ -674,72 +675,60 @@ static const struct counter_driver_api counter_nrfx_driver_api = { * are indexed by peripheral number, so DT_INST APIs won't work. */ -#define RTC(idx) DT_NODELABEL(rtc##idx) -#define RTC_PROP(idx, prop) DT_PROP(RTC(idx), prop) - #define RTC_IRQ_CONNECT(idx) \ - COND_CODE_1(CONFIG_COUNTER_RTC##idx##_ZLI, \ - (IRQ_DIRECT_CONNECT(DT_IRQN(RTC(idx)), \ - DT_IRQ(RTC(idx), priority), \ + COND_CODE_1(DT_INST_PROP(idx, zli), \ + (IRQ_DIRECT_CONNECT(DT_INST_IRQN(idx), \ + DT_INST_IRQ(idx, priority), \ counter_rtc##idx##_isr_wrapper, \ IRQ_ZERO_LATENCY)), \ - (IRQ_CONNECT(DT_IRQN(RTC(idx)), DT_IRQ(RTC(idx), priority), \ - irq_handler, DEVICE_DT_GET(RTC(idx)), 0)) \ + (IRQ_CONNECT(DT_INST_IRQN(idx), DT_INST_IRQ(idx, priority), \ + irq_handler, DEVICE_DT_INST_GET(idx), 0)) \ ) #define COUNTER_NRF_RTC_DEVICE(idx) \ - BUILD_ASSERT((RTC_PROP(idx, prescaler) - 1) <= \ + BUILD_ASSERT((DT_INST_PROP(idx, prescaler) - 1) <= \ RTC_PRESCALER_PRESCALER_Msk, \ "RTC prescaler out of range"); \ - COND_CODE_1(CONFIG_COUNTER_RTC##idx##_ZLI, ( \ + COND_CODE_1(DT_INST_PROP(idx, zli), ( \ ISR_DIRECT_DECLARE(counter_rtc##idx##_isr_wrapper) \ { \ - irq_handler(DEVICE_DT_GET(RTC(idx))); \ + irq_handler(DEVICE_DT_INST_GET(idx)); \ /* No rescheduling, it shall not access zephyr primitives. */ \ return 0; \ }), ()) \ static int counter_##idx##_init(const struct device *dev) \ { \ RTC_IRQ_CONNECT(idx); \ - return init_rtc(dev, RTC_PROP(idx, prescaler) - 1); \ + return init_rtc(dev, DT_INST_PROP(idx, prescaler) - 1); \ } \ static struct counter_nrfx_data counter_##idx##_data; \ static struct counter_nrfx_ch_data \ - counter##idx##_ch_data[RTC##idx##_CC_NUM]; \ + counter##idx##_ch_data[DT_INST_PROP(idx, cc_num)]; \ LOG_INSTANCE_REGISTER(LOG_MODULE_NAME, idx, CONFIG_COUNTER_LOG_LEVEL); \ static const struct counter_nrfx_config nrfx_counter_##idx##_config = {\ .info = { \ .max_top_value = COUNTER_MAX_TOP_VALUE, \ - .freq = RTC_PROP(idx, clock_frequency) / \ - RTC_PROP(idx, prescaler), \ + .freq = DT_INST_PROP(idx, clock_frequency) / \ + DT_INST_PROP(idx, prescaler), \ .flags = COUNTER_CONFIG_INFO_COUNT_UP, \ - .channels = RTC_PROP(idx, fixed_top) ? \ - RTC##idx##_CC_NUM : RTC##idx##_CC_NUM - 1 \ + .channels = DT_INST_PROP(idx, fixed_top) \ + ? DT_INST_PROP(idx, cc_num) \ + : DT_INST_PROP(idx, cc_num) - 1 \ }, \ .ch_data = counter##idx##_ch_data, \ - .rtc = (NRF_RTC_Type *)DT_REG_ADDR(RTC(idx)), \ + .rtc = (NRF_RTC_Type *)DT_INST_REG_ADDR(idx), \ IF_ENABLED(CONFIG_COUNTER_RTC_WITH_PPI_WRAP, \ - (.use_ppi = RTC_PROP(idx, ppi_wrap),)) \ + (.use_ppi = DT_INST_PROP(idx, ppi_wrap),)) \ IF_ENABLED(CONFIG_COUNTER_RTC_CUSTOM_TOP_SUPPORT, \ - (.fixed_top = RTC_PROP(idx, fixed_top),)) \ + (.fixed_top = DT_INST_PROP(idx, fixed_top),)) \ LOG_INSTANCE_PTR_INIT(log, LOG_MODULE_NAME, idx) \ }; \ - DEVICE_DT_DEFINE(RTC(idx), \ + DEVICE_DT_INST_DEFINE(idx, \ counter_##idx##_init, \ NULL, \ &counter_##idx##_data, \ &nrfx_counter_##idx##_config.info, \ PRE_KERNEL_1, CONFIG_COUNTER_INIT_PRIORITY, \ - &counter_nrfx_driver_api) - -#ifdef CONFIG_COUNTER_RTC0 -COUNTER_NRF_RTC_DEVICE(0); -#endif - -#ifdef CONFIG_COUNTER_RTC1 -COUNTER_NRF_RTC_DEVICE(1); -#endif + &counter_nrfx_driver_api); -#ifdef CONFIG_COUNTER_RTC2 -COUNTER_NRF_RTC_DEVICE(2); -#endif +DT_INST_FOREACH_STATUS_OKAY(COUNTER_NRF_RTC_DEVICE) diff --git a/drivers/counter/counter_nrfx_timer.c b/drivers/counter/counter_nrfx_timer.c index c1625480a589..df5b61752573 100644 --- a/drivers/counter/counter_nrfx_timer.c +++ b/drivers/counter/counter_nrfx_timer.c @@ -13,6 +13,8 @@ #include LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL); +#define DT_DRV_COMPAT nordic_nrf_timer + #define TIMER_CLOCK(timer_instance) NRF_TIMER_BASE_FREQUENCY_GET(timer_instance) #define CC_TO_ID(cc_num) (cc_num - 2) @@ -389,83 +391,60 @@ static const struct counter_driver_api counter_nrfx_driver_api = { * are indexed by peripheral number, so DT_INST APIs won't work. */ -#define TIMER(idx) DT_NODELABEL(timer##idx) -#define TIMER_PROP(idx, prop) DT_PROP(TIMER(idx), prop) - -#define TIMER_IRQ_CONNECT(idx) \ - COND_CODE_1(CONFIG_COUNTER_TIMER##idx##_ZLI, \ - (IRQ_DIRECT_CONNECT(DT_IRQN(TIMER(idx)), \ - DT_IRQ(TIMER(idx), priority), \ - counter_timer##idx##_isr_wrapper, \ - IRQ_ZERO_LATENCY)), \ - (IRQ_CONNECT(DT_IRQN(TIMER(idx)), DT_IRQ(TIMER(idx), priority),\ - irq_handler, DEVICE_DT_GET(TIMER(idx)), 0)) \ +#define TIMER_IRQ_CONNECT(idx) \ + COND_CODE_1(DT_INST_PROP(idx, zli), \ + (IRQ_DIRECT_CONNECT(DT_INST_IRQN(idx), \ + DT_INST_IRQ(idx, priority), \ + counter_timer##idx##_isr_wrapper, \ + IRQ_ZERO_LATENCY)), \ + (IRQ_CONNECT(DT_INST_IRQN(idx), DT_INST_IRQ(idx, priority), \ + irq_handler, DEVICE_DT_INST_GET(idx), 0)) \ ) -#define COUNTER_NRFX_TIMER_DEVICE(idx) \ - BUILD_ASSERT(TIMER_PROP(idx, prescaler) <= \ - TIMER_PRESCALER_PRESCALER_Msk, \ - "TIMER prescaler out of range"); \ - COND_CODE_1(CONFIG_COUNTER_TIMER##idx##_ZLI, ( \ - ISR_DIRECT_DECLARE(counter_timer##idx##_isr_wrapper) \ - { \ - irq_handler(DEVICE_DT_GET(TIMER(idx))); \ - /* No rescheduling, it shall not access zephyr primitives. */ \ - return 0; \ - }), ()) \ - static int counter_##idx##_init(const struct device *dev) \ - { \ - TIMER_IRQ_CONNECT(idx); \ - static const struct counter_timer_config config = { \ - .prescaler = TIMER_PROP(idx, prescaler), \ - .mode = NRF_TIMER_MODE_TIMER, \ - .bit_width = (TIMER##idx##_MAX_SIZE == 32) ? \ - NRF_TIMER_BIT_WIDTH_32 : \ - NRF_TIMER_BIT_WIDTH_16, \ - }; \ - return init_timer(dev, &config); \ - } \ - static struct counter_nrfx_data counter_##idx##_data; \ - static struct counter_nrfx_ch_data \ - counter##idx##_ch_data[CC_TO_ID(TIMER##idx##_CC_NUM)]; \ - LOG_INSTANCE_REGISTER(LOG_MODULE_NAME, idx, CONFIG_COUNTER_LOG_LEVEL); \ - static const struct counter_nrfx_config nrfx_counter_##idx##_config = {\ - .info = { \ - .max_top_value = (TIMER##idx##_MAX_SIZE == 32) ? \ - 0xffffffff : 0x0000ffff, \ - .freq = TIMER_CLOCK(NRF_TIMER##idx) / \ - (1 << TIMER_PROP(idx, prescaler)), \ - .flags = COUNTER_CONFIG_INFO_COUNT_UP, \ - .channels = CC_TO_ID(TIMER##idx##_CC_NUM), \ - }, \ - .ch_data = counter##idx##_ch_data, \ - .timer = (NRF_TIMER_Type *)DT_REG_ADDR(TIMER(idx)), \ - LOG_INSTANCE_PTR_INIT(log, LOG_MODULE_NAME, idx) \ - }; \ - DEVICE_DT_DEFINE(TIMER(idx), \ - counter_##idx##_init, \ - NULL, \ - &counter_##idx##_data, \ - &nrfx_counter_##idx##_config.info, \ - PRE_KERNEL_1, CONFIG_COUNTER_INIT_PRIORITY, \ - &counter_nrfx_driver_api) - -#ifdef CONFIG_COUNTER_TIMER0 -COUNTER_NRFX_TIMER_DEVICE(0); -#endif - -#ifdef CONFIG_COUNTER_TIMER1 -COUNTER_NRFX_TIMER_DEVICE(1); -#endif - -#ifdef CONFIG_COUNTER_TIMER2 -COUNTER_NRFX_TIMER_DEVICE(2); -#endif - -#ifdef CONFIG_COUNTER_TIMER3 -COUNTER_NRFX_TIMER_DEVICE(3); -#endif - -#ifdef CONFIG_COUNTER_TIMER4 -COUNTER_NRFX_TIMER_DEVICE(4); -#endif +#define COUNTER_NRFX_TIMER_DEVICE(idx) \ + BUILD_ASSERT(DT_INST_PROP(idx, prescaler) <= \ + TIMER_PRESCALER_PRESCALER_Msk, \ + "TIMER prescaler out of range"); \ + COND_CODE_1(DT_INST_PROP(idx, zli), ( \ + ISR_DIRECT_DECLARE(counter_timer##idx##_isr_wrapper) \ + { \ + irq_handler(DEVICE_DT_INST_GET(idx)); \ + /* No rescheduling, it shall not access zephyr primitives. */ \ + return 0; \ + }), ()) \ + static int counter_##idx##_init(const struct device *dev) \ + { \ + TIMER_IRQ_CONNECT(idx); \ + static const struct counter_timer_config config = { \ + .prescaler = DT_INST_PROP(idx, prescaler), \ + .mode = NRF_TIMER_MODE_TIMER, \ + .bit_width = (DT_INST_PROP(idx, max_bit_width) == 32) ? \ + NRF_TIMER_BIT_WIDTH_32 : NRF_TIMER_BIT_WIDTH_16, \ + }; \ + return init_timer(dev, &config); \ + } \ + static struct counter_nrfx_data counter_##idx##_data; \ + static struct counter_nrfx_ch_data \ + counter##idx##_ch_data[CC_TO_ID(DT_INST_PROP(idx, cc_num))]; \ + LOG_INSTANCE_REGISTER(LOG_MODULE_NAME, idx, CONFIG_COUNTER_LOG_LEVEL); \ + static const struct counter_nrfx_config nrfx_counter_##idx##_config = { \ + .info = { \ + .max_top_value = (uint32_t)BIT64_MASK(DT_INST_PROP(idx, max_bit_width)),\ + .freq = TIMER_CLOCK((NRF_TIMER_Type *)DT_INST_REG_ADDR(idx)) / \ + BIT(DT_INST_PROP(idx, prescaler)), \ + .flags = COUNTER_CONFIG_INFO_COUNT_UP, \ + .channels = CC_TO_ID(DT_INST_PROP(idx, cc_num)), \ + }, \ + .ch_data = counter##idx##_ch_data, \ + .timer = (NRF_TIMER_Type *)DT_INST_REG_ADDR(idx), \ + LOG_INSTANCE_PTR_INIT(log, LOG_MODULE_NAME, idx) \ + }; \ + DEVICE_DT_INST_DEFINE(idx, \ + counter_##idx##_init, \ + NULL, \ + &counter_##idx##_data, \ + &nrfx_counter_##idx##_config.info, \ + PRE_KERNEL_1, CONFIG_COUNTER_INIT_PRIORITY, \ + &counter_nrfx_driver_api); + +DT_INST_FOREACH_STATUS_OKAY(COUNTER_NRFX_TIMER_DEVICE) diff --git a/dts/arm/nordic/nrf51822.dtsi b/dts/arm/nordic/nrf51822.dtsi index 1a8cf741708d..3fa875ac9003 100644 --- a/dts/arm/nordic/nrf51822.dtsi +++ b/dts/arm/nordic/nrf51822.dtsi @@ -142,27 +142,30 @@ timer0: timer@40008000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40008000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <8 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer1: timer@40009000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40009000 0x1000>; cc-num = <4>; + max-bit-width = <16>; interrupts = <9 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer2: timer@4000a000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4000a000 0x1000>; cc-num = <4>; + max-bit-width = <16>; interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -172,7 +175,7 @@ reg = <0x4000b000 0x1000>; cc-num = <3>; interrupts = <11 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -217,7 +220,7 @@ reg = <0x40011000 0x1000>; cc-num = <4>; interrupts = <17 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; diff --git a/dts/arm/nordic/nrf52805.dtsi b/dts/arm/nordic/nrf52805.dtsi index b4db33bd766b..ee89039448d8 100644 --- a/dts/arm/nordic/nrf52805.dtsi +++ b/dts/arm/nordic/nrf52805.dtsi @@ -143,27 +143,30 @@ timer0: timer@40008000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40008000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <8 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer1: timer@40009000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40009000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <9 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer2: timer@4000a000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4000a000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -173,7 +176,7 @@ reg = <0x4000b000 0x1000>; cc-num = <3>; interrupts = <11 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -219,7 +222,7 @@ reg = <0x40011000 0x1000>; cc-num = <4>; interrupts = <17 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; diff --git a/dts/arm/nordic/nrf52810.dtsi b/dts/arm/nordic/nrf52810.dtsi index 88fd7280df50..da166f1ed966 100644 --- a/dts/arm/nordic/nrf52810.dtsi +++ b/dts/arm/nordic/nrf52810.dtsi @@ -146,27 +146,30 @@ }; timer0: timer@40008000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40008000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <8 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer1: timer@40009000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40009000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <9 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer2: timer@4000a000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4000a000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -176,7 +179,7 @@ reg = <0x4000b000 0x1000>; cc-num = <3>; interrupts = <11 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -222,7 +225,7 @@ reg = <0x40011000 0x1000>; cc-num = <4>; interrupts = <17 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; diff --git a/dts/arm/nordic/nrf52811.dtsi b/dts/arm/nordic/nrf52811.dtsi index 945d2af959ae..ade3f54e9041 100644 --- a/dts/arm/nordic/nrf52811.dtsi +++ b/dts/arm/nordic/nrf52811.dtsi @@ -177,27 +177,30 @@ timer0: timer@40008000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40008000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <8 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer1: timer@40009000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40009000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <9 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer2: timer@4000a000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4000a000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -207,7 +210,7 @@ reg = <0x4000b000 0x1000>; cc-num = <3>; interrupts = <11 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -253,7 +256,7 @@ reg = <0x40011000 0x1000>; cc-num = <4>; interrupts = <17 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; diff --git a/dts/arm/nordic/nrf52820.dtsi b/dts/arm/nordic/nrf52820.dtsi index f42c7e5daf58..83e882df2819 100644 --- a/dts/arm/nordic/nrf52820.dtsi +++ b/dts/arm/nordic/nrf52820.dtsi @@ -175,27 +175,30 @@ timer0: timer@40008000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40008000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <8 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer1: timer@40009000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40009000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <9 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer2: timer@4000a000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4000a000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -205,7 +208,7 @@ reg = <0x4000b000 0x1000>; cc-num = <3>; interrupts = <11 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -251,7 +254,7 @@ reg = <0x40011000 0x1000>; cc-num = <4>; interrupts = <17 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -315,9 +318,10 @@ timer3: timer@4001a000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4001a000 0x1000>; cc-num = <6>; + max-bit-width = <32>; interrupts = <26 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; diff --git a/dts/arm/nordic/nrf52832.dtsi b/dts/arm/nordic/nrf52832.dtsi index 02551e4c680d..c82d992d1a47 100644 --- a/dts/arm/nordic/nrf52832.dtsi +++ b/dts/arm/nordic/nrf52832.dtsi @@ -188,27 +188,30 @@ timer0: timer@40008000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40008000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <8 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer1: timer@40009000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40009000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <9 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer2: timer@4000a000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4000a000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -218,7 +221,7 @@ reg = <0x4000b000 0x1000>; cc-num = <3>; interrupts = <11 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -264,7 +267,7 @@ reg = <0x40011000 0x1000>; cc-num = <4>; interrupts = <17 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -334,18 +337,20 @@ timer3: timer@4001a000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4001a000 0x1000>; cc-num = <6>; + max-bit-width = <32>; interrupts = <26 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer4: timer@4001b000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4001b000 0x1000>; cc-num = <6>; + max-bit-width = <32>; interrupts = <27 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -430,7 +435,7 @@ reg = <0x40024000 0x1000>; cc-num = <4>; interrupts = <36 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; diff --git a/dts/arm/nordic/nrf52833.dtsi b/dts/arm/nordic/nrf52833.dtsi index c59be8d74ade..37390dfc9fe6 100644 --- a/dts/arm/nordic/nrf52833.dtsi +++ b/dts/arm/nordic/nrf52833.dtsi @@ -195,27 +195,30 @@ timer0: timer@40008000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40008000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <8 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer1: timer@40009000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40009000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <9 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer2: timer@4000a000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4000a000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -225,7 +228,7 @@ reg = <0x4000b000 0x1000>; cc-num = <3>; interrupts = <11 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -271,7 +274,7 @@ reg = <0x40011000 0x1000>; cc-num = <4>; interrupts = <17 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -341,18 +344,20 @@ timer3: timer@4001a000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4001a000 0x1000>; cc-num = <6>; + max-bit-width = <32>; interrupts = <26 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer4: timer@4001b000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4001b000 0x1000>; cc-num = <6>; + max-bit-width = <32>; interrupts = <27 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -444,7 +449,7 @@ reg = <0x40024000 0x1000>; cc-num = <4>; interrupts = <36 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index b79a4d3899c7..3efa10b25e30 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -190,27 +190,30 @@ timer0: timer@40008000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40008000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <8 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer1: timer@40009000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x40009000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <9 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer2: timer@4000a000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4000a000 0x1000>; cc-num = <4>; + max-bit-width = <32>; interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -220,7 +223,7 @@ reg = <0x4000b000 0x1000>; cc-num = <3>; interrupts = <11 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -266,7 +269,7 @@ reg = <0x40011000 0x1000>; cc-num = <4>; interrupts = <17 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -336,18 +339,20 @@ timer3: timer@4001a000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4001a000 0x1000>; cc-num = <6>; + max-bit-width = <32>; interrupts = <26 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; timer4: timer@4001b000 { compatible = "nordic,nrf-timer"; - status = "okay"; + status = "disabled"; reg = <0x4001b000 0x1000>; cc-num = <6>; + max-bit-width = <32>; interrupts = <27 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -439,7 +444,7 @@ reg = <0x40024000 0x1000>; cc-num = <4>; interrupts = <36 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; diff --git a/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi b/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi index 729b977af034..09267d53eb27 100644 --- a/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi @@ -242,6 +242,7 @@ timer0: timer@f000 { status = "disabled"; reg = <0xf000 0x1000>; cc-num = <6>; + max-bit-width = <32>; interrupts = <15 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -251,6 +252,7 @@ timer1: timer@10000 { status = "disabled"; reg = <0x10000 0x1000>; cc-num = <6>; + max-bit-width = <32>; interrupts = <16 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -260,6 +262,7 @@ timer2: timer@11000 { status = "disabled"; reg = <0x11000 0x1000>; cc-num = <6>; + max-bit-width = <32>; interrupts = <17 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -269,7 +272,7 @@ rtc0: rtc@14000 { reg = <0x14000 0x1000>; cc-num = <4>; interrupts = <20 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -279,7 +282,7 @@ rtc1: rtc@15000 { reg = <0x15000 0x1000>; cc-num = <4>; interrupts = <21 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; diff --git a/dts/arm/nordic/nrf5340_cpunet.dtsi b/dts/arm/nordic/nrf5340_cpunet.dtsi index 76eadce06549..69069f5d9e0b 100644 --- a/dts/arm/nordic/nrf5340_cpunet.dtsi +++ b/dts/arm/nordic/nrf5340_cpunet.dtsi @@ -123,6 +123,7 @@ status = "disabled"; reg = <0x4100c000 0x1000>; cc-num = <8>; + max-bit-width = <32>; interrupts = <12 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -160,7 +161,7 @@ reg = <0x41011000 0x1000>; cc-num = <4>; interrupts = <17 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; }; mbox: ipc: mbox@41012000 { @@ -224,7 +225,7 @@ reg = <0x41016000 0x1000>; cc-num = <4>; interrupts = <22 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; }; timer1: timer@41018000 { @@ -232,6 +233,7 @@ status = "disabled"; reg = <0x41018000 0x1000>; cc-num = <8>; + max-bit-width = <32>; interrupts = <24 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -241,6 +243,7 @@ status = "disabled"; reg = <0x41019000 0x1000>; cc-num = <8>; + max-bit-width = <32>; interrupts = <25 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; diff --git a/dts/arm/nordic/nrf9160_common.dtsi b/dts/arm/nordic/nrf9160_common.dtsi index 5baf0578c224..49e23554b853 100644 --- a/dts/arm/nordic/nrf9160_common.dtsi +++ b/dts/arm/nordic/nrf9160_common.dtsi @@ -312,7 +312,7 @@ rtc0: rtc@14000 { reg = <0x14000 0x1000>; cc-num = <4>; interrupts = <20 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -322,7 +322,7 @@ rtc1: rtc@15000 { reg = <0x15000 0x1000>; cc-num = <4>; interrupts = <21 NRF_DEFAULT_IRQ_PRIORITY>; - status = "okay"; + status = "disabled"; clock-frequency = <32768>; prescaler = <1>; }; @@ -367,6 +367,7 @@ timer0: timer@f000 { status = "disabled"; reg = <0xf000 0x1000>; cc-num = <6>; + max-bit-width = <32>; interrupts = <15 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -376,6 +377,7 @@ timer1: timer@10000 { status = "disabled"; reg = <0x10000 0x1000>; cc-num = <6>; + max-bit-width = <32>; interrupts = <16 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; @@ -385,6 +387,7 @@ timer2: timer@11000 { status = "disabled"; reg = <0x11000 0x1000>; cc-num = <6>; + max-bit-width = <32>; interrupts = <17 NRF_DEFAULT_IRQ_PRIORITY>; prescaler = <0>; }; diff --git a/dts/bindings/rtc/nordic,nrf-rtc.yaml b/dts/bindings/rtc/nordic,nrf-rtc.yaml index b04a2bd9d36c..49d868d3e10e 100644 --- a/dts/bindings/rtc/nordic,nrf-rtc.yaml +++ b/dts/bindings/rtc/nordic,nrf-rtc.yaml @@ -33,3 +33,7 @@ properties: fixed-top: type: boolean description: Enable fixed top value + + zli: + type: boolean + description: Enable event handler in the ZLI (Zero latency interrupt) context diff --git a/dts/bindings/timer/nordic,nrf-timer.yaml b/dts/bindings/timer/nordic,nrf-timer.yaml index 914c8ee40a09..8a961f34f883 100644 --- a/dts/bindings/timer/nordic,nrf-timer.yaml +++ b/dts/bindings/timer/nordic,nrf-timer.yaml @@ -16,6 +16,11 @@ properties: required: true description: Number of capture/compare (CC) registers available + max-bit-width: + type: int + required: true + description: Maximum bit width supported + interrupts: required: true @@ -23,3 +28,7 @@ properties: type: int required: true description: Prescaler value determines frequency (base_frequency/2^prescaler) + + zli: + type: boolean + description: Enable event handler in the ZLI (Zero latency interrupt) context diff --git a/samples/boards/nrf/clock_skew/app.overlay b/samples/boards/nrf/clock_skew/app.overlay new file mode 100644 index 000000000000..241947b06437 --- /dev/null +++ b/samples/boards/nrf/clock_skew/app.overlay @@ -0,0 +1,3 @@ +&timer0 { + status = "okay"; +}; diff --git a/samples/boards/nrf/clock_skew/prj.conf b/samples/boards/nrf/clock_skew/prj.conf index db7c52c95bc8..8ef0d31e37ab 100644 --- a/samples/boards/nrf/clock_skew/prj.conf +++ b/samples/boards/nrf/clock_skew/prj.conf @@ -1,5 +1,3 @@ -#CONFIG_CLOCK_CONTROL=y CONFIG_COUNTER=y -CONFIG_COUNTER_TIMER0=y CONFIG_NEWLIB_LIBC=y CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf51dk_nrf51422.conf b/tests/drivers/counter/counter_basic_api/boards/nrf51dk_nrf51422.conf deleted file mode 100644 index 25d7ba83ed08..000000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf51dk_nrf51422.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_RTC0=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf51dk_nrf51422.overlay b/tests/drivers/counter/counter_basic_api/boards/nrf51dk_nrf51422.overlay index ee8a3cd10eec..e3373c037a67 100644 --- a/tests/drivers/counter/counter_basic_api/boards/nrf51dk_nrf51422.overlay +++ b/tests/drivers/counter/counter_basic_api/boards/nrf51dk_nrf51422.overlay @@ -1,11 +1,19 @@ &timer0 { + status = "okay"; prescaler = <4>; }; &timer1 { + status = "okay"; prescaler = <4>; }; &timer2 { + status = "okay"; prescaler = <4>; }; + +&rtc0 { + status = "okay"; + ppi-wrap; +}; diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52833dk_nrf52833.conf b/tests/drivers/counter/counter_basic_api/boards/nrf52833dk_nrf52833.conf deleted file mode 100644 index bd6b714b18aa..000000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52833dk_nrf52833.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_TIMER3=y -CONFIG_COUNTER_TIMER4=y -CONFIG_COUNTER_RTC0=y -CONFIG_COUNTER_RTC2=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52833dk_nrf52833.overlay b/tests/drivers/counter/counter_basic_api/boards/nrf52833dk_nrf52833.overlay index a795afb4b178..4a67fd345ca9 100644 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52833dk_nrf52833.overlay +++ b/tests/drivers/counter/counter_basic_api/boards/nrf52833dk_nrf52833.overlay @@ -1,23 +1,33 @@ &timer0 { + status = "okay"; prescaler = <4>; }; &timer1 { + status = "okay"; prescaler = <4>; }; &timer2 { + status = "okay"; prescaler = <4>; }; &timer3 { + status = "okay"; prescaler = <4>; }; &timer4 { + status = "okay"; prescaler = <4>; }; &rtc0 { + status = "okay"; +}; + +&rtc2 { + status = "okay"; ppi-wrap; }; diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52811.conf b/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52811.conf deleted file mode 100644 index 25d7ba83ed08..000000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52811.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_RTC0=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52811.overlay b/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52811.overlay index ee8a3cd10eec..e3373c037a67 100644 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52811.overlay +++ b/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52811.overlay @@ -1,11 +1,19 @@ &timer0 { + status = "okay"; prescaler = <4>; }; &timer1 { + status = "okay"; prescaler = <4>; }; &timer2 { + status = "okay"; prescaler = <4>; }; + +&rtc0 { + status = "okay"; + ppi-wrap; +}; diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840.conf b/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840.conf deleted file mode 100644 index bd6b714b18aa..000000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_TIMER3=y -CONFIG_COUNTER_TIMER4=y -CONFIG_COUNTER_RTC0=y -CONFIG_COUNTER_RTC2=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840.overlay b/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840.overlay index a795afb4b178..3c1eff868ffd 100644 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840.overlay +++ b/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840.overlay @@ -1,23 +1,33 @@ &timer0 { + status = "okay"; prescaler = <4>; }; &timer1 { + status = "okay"; prescaler = <4>; }; &timer2 { + status = "okay"; prescaler = <4>; }; &timer3 { + status = "okay"; prescaler = <4>; }; &timer4 { + status = "okay"; prescaler = <4>; }; &rtc0 { + status = "okay"; ppi-wrap; }; + +&rtc2 { + status = "okay"; +}; diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840_zli.conf b/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840_zli.conf deleted file mode 100644 index 39ddf4af3a29..000000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840_zli.conf +++ /dev/null @@ -1,14 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER0_ZLI=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER1_ZLI=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_TIMER2_ZLI=y -CONFIG_COUNTER_TIMER3=y -CONFIG_COUNTER_TIMER3_ZLI=y -CONFIG_COUNTER_TIMER4=y -CONFIG_COUNTER_TIMER4_ZLI=y -CONFIG_COUNTER_RTC0=y -CONFIG_COUNTER_RTC0_ZLI=y -CONFIG_COUNTER_RTC2=y -CONFIG_COUNTER_RTC2_ZLI=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840_zli.overlay b/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840_zli.overlay new file mode 100644 index 000000000000..ee6855640cf9 --- /dev/null +++ b/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840_zli.overlay @@ -0,0 +1,23 @@ +&timer0 { + zli; +}; + +&timer1 { + zli; +}; + +&timer2 { + zli; +}; + +&timer3 { + zli; +}; + +&timer4 { + zli; +}; + +&rtc0 { + zli; +}; diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52810.conf b/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52810.conf deleted file mode 100644 index 25d7ba83ed08..000000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52810.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_RTC0=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52810.overlay b/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52810.overlay index ee8a3cd10eec..e3373c037a67 100644 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52810.overlay +++ b/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52810.overlay @@ -1,11 +1,19 @@ &timer0 { + status = "okay"; prescaler = <4>; }; &timer1 { + status = "okay"; prescaler = <4>; }; &timer2 { + status = "okay"; prescaler = <4>; }; + +&rtc0 { + status = "okay"; + ppi-wrap; +}; diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52832.conf b/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52832.conf deleted file mode 100644 index bd6b714b18aa..000000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52832.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_TIMER3=y -CONFIG_COUNTER_TIMER4=y -CONFIG_COUNTER_RTC0=y -CONFIG_COUNTER_RTC2=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52832.overlay b/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52832.overlay index cb221799098b..f8a1dc7efd73 100644 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52832.overlay +++ b/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52832.overlay @@ -1,19 +1,34 @@ &timer0 { + status = "okay"; prescaler = <4>; }; &timer1 { + status = "okay"; prescaler = <4>; }; &timer2 { + status = "okay"; prescaler = <4>; }; &timer3 { + status = "okay"; prescaler = <4>; }; &timer4 { + status = "okay"; prescaler = <4>; }; + +&rtc0 { + status = "okay"; + ppi-wrap; +}; + +&rtc2 { + status = "okay"; + ppi-wrap; +}; diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf9160dk_nrf9160.conf b/tests/drivers/counter/counter_basic_api/boards/nrf9160dk_nrf9160.conf deleted file mode 100644 index 25d7ba83ed08..000000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf9160dk_nrf9160.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_RTC0=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf9160dk_nrf9160.overlay b/tests/drivers/counter/counter_basic_api/boards/nrf9160dk_nrf9160.overlay index ee8a3cd10eec..e3373c037a67 100644 --- a/tests/drivers/counter/counter_basic_api/boards/nrf9160dk_nrf9160.overlay +++ b/tests/drivers/counter/counter_basic_api/boards/nrf9160dk_nrf9160.overlay @@ -1,11 +1,19 @@ &timer0 { + status = "okay"; prescaler = <4>; }; &timer1 { + status = "okay"; prescaler = <4>; }; &timer2 { + status = "okay"; prescaler = <4>; }; + +&rtc0 { + status = "okay"; + ppi-wrap; +}; diff --git a/tests/drivers/counter/counter_basic_api/src/test_counter.c b/tests/drivers/counter/counter_basic_api/src/test_counter.c index 1ce2a221a0fa..9a3dc6260e9d 100644 --- a/tests/drivers/counter/counter_basic_api/src/test_counter.c +++ b/tests/drivers/counter/counter_basic_api/src/test_counter.c @@ -28,29 +28,11 @@ struct counter_alarm_cfg alarm_cfg2; DT_FOREACH_STATUS_OKAY(compat, DEVICE_DT_GET_AND_COMMA) static const struct device *const devices[] = { -#ifdef CONFIG_COUNTER_TIMER0 - /* Nordic TIMER0 may be reserved for Bluetooth */ - DEVICE_DT_GET(DT_NODELABEL(timer0)), +#ifdef CONFIG_COUNTER_NRF_TIMER + DEVS_FOR_DT_COMPAT(nordic_nrf_timer) #endif -#ifdef CONFIG_COUNTER_TIMER1 - DEVICE_DT_GET(DT_NODELABEL(timer1)), -#endif -#ifdef CONFIG_COUNTER_TIMER2 - DEVICE_DT_GET(DT_NODELABEL(timer2)), -#endif -#ifdef CONFIG_COUNTER_TIMER3 - DEVICE_DT_GET(DT_NODELABEL(timer3)), -#endif -#ifdef CONFIG_COUNTER_TIMER4 - DEVICE_DT_GET(DT_NODELABEL(timer4)), -#endif -#ifdef CONFIG_COUNTER_RTC0 - /* Nordic RTC0 may be reserved for Bluetooth */ - DEVICE_DT_GET(DT_NODELABEL(rtc0)), -#endif - /* Nordic RTC1 is used for the system clock */ -#ifdef CONFIG_COUNTER_RTC2 - DEVICE_DT_GET(DT_NODELABEL(rtc2)), +#ifdef CONFIG_COUNTER_NRF_RTC + DEVS_FOR_DT_COMPAT(nordic_nrf_rtc) #endif #ifdef CONFIG_COUNTER_TIMER_STM32 #define STM32_COUNTER_DEV(idx) \ @@ -938,47 +920,8 @@ static bool reliable_cancel_capable(const struct device *dev) { /* Test performed only for NRF_RTC instances. Other probably will fail. */ -#ifdef CONFIG_COUNTER_RTC0 - /* Nordic RTC0 may be reserved for Bluetooth */ - if (dev == DEVICE_DT_GET(DT_NODELABEL(rtc0))) { - return true; - } -#endif - -#ifdef CONFIG_COUNTER_RTC2 - if (dev == DEVICE_DT_GET(DT_NODELABEL(rtc2))) { - return true; - } -#endif - -#ifdef CONFIG_COUNTER_TIMER0 - if (dev == DEVICE_DT_GET(DT_NODELABEL(timer0))) { - return true; - } -#endif - -#ifdef CONFIG_COUNTER_TIMER1 - if (dev == DEVICE_DT_GET(DT_NODELABEL(timer1))) { - return true; - } -#endif - -#ifdef CONFIG_COUNTER_TIMER2 - if (dev == DEVICE_DT_GET(DT_NODELABEL(timer2))) { - return true; - } -#endif - -#ifdef CONFIG_COUNTER_TIMER3 - if (dev == DEVICE_DT_GET(DT_NODELABEL(timer3))) { - return true; - } -#endif - -#ifdef CONFIG_COUNTER_TIMER4 - if (dev == DEVICE_DT_GET(DT_NODELABEL(timer4))) { - return true; - } +#if defined(CONFIG_COUNTER_NRF_RTC) || defined(CONFIG_COUNTER_NRF_TIMER) + return true; #endif #ifdef CONFIG_COUNTER_TIMER_STM32 if (single_channel_alarm_capable(dev)) { diff --git a/tests/drivers/counter/counter_basic_api/testcase.yaml b/tests/drivers/counter/counter_basic_api/testcase.yaml index 2bca7526ebb8..ae78db44f2a3 100644 --- a/tests/drivers/counter/counter_basic_api/testcase.yaml +++ b/tests/drivers/counter/counter_basic_api/testcase.yaml @@ -10,5 +10,7 @@ tests: depends_on: counter platform_allow: nrf52840dk_nrf52840 timeout: 400 - extra_args: > - OVERLAY_CONFIG="zli.conf;boards/nrf52840dk_nrf52840_zli.conf" + extra_configs: + - CONFIG_ZERO_LATENCY_IRQS=y + extra_args: + DTC_OVERLAY_FILE="boards/nrf52840dk_nrf52840.overlay;boards/nrf52840dk_nrf52840_zli.overlay" diff --git a/tests/drivers/counter/counter_nrf_rtc/fixed_top/boards/nrf52840dk_nrf52840.conf b/tests/drivers/counter/counter_nrf_rtc/fixed_top/boards/nrf52840dk_nrf52840.conf deleted file mode 100644 index 796a77839c33..000000000000 --- a/tests/drivers/counter/counter_nrf_rtc/fixed_top/boards/nrf52840dk_nrf52840.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_COUNTER_RTC0=y -CONFIG_COUNTER_RTC2=y diff --git a/tests/drivers/counter/counter_nrf_rtc/fixed_top/nrf52840dk_nrf52840.overlay b/tests/drivers/counter/counter_nrf_rtc/fixed_top/nrf52840dk_nrf52840.overlay index cd64b6deb0f8..ebfed9cf9032 100644 --- a/tests/drivers/counter/counter_nrf_rtc/fixed_top/nrf52840dk_nrf52840.overlay +++ b/tests/drivers/counter/counter_nrf_rtc/fixed_top/nrf52840dk_nrf52840.overlay @@ -1,6 +1,8 @@ &rtc0 { + status = "okay"; fixed-top; }; &rtc2 { + status = "okay"; fixed-top; }; diff --git a/tests/drivers/counter/counter_nrf_rtc/fixed_top/src/test_counter_fixed_top.c b/tests/drivers/counter/counter_nrf_rtc/fixed_top/src/test_counter_fixed_top.c index 70056e431549..ba6666449cef 100644 --- a/tests/drivers/counter/counter_nrf_rtc/fixed_top/src/test_counter_fixed_top.c +++ b/tests/drivers/counter/counter_nrf_rtc/fixed_top/src/test_counter_fixed_top.c @@ -13,19 +13,31 @@ LOG_MODULE_REGISTER(test); static volatile uint32_t top_cnt; +#define DEVICE_DT_GET_AND_COMMA(node_id) DEVICE_DT_GET(node_id), +/* Generate a list of devices for all instances of the "compat" */ +#define DEVS_FOR_DT_COMPAT(compat) \ + DT_FOREACH_STATUS_OKAY(compat, DEVICE_DT_GET_AND_COMMA) + +#define DEVICE_DT_GET_REG_AND_COMMA(node_id) (NRF_RTC_Type *)DT_REG_ADDR(node_id), +/* Generate a list of devices for all instances of the "compat" */ +#define REGS_FOR_DT_COMPAT(compat) \ + DT_FOREACH_STATUS_OKAY(compat, DEVICE_DT_GET_REG_AND_COMMA) + static const struct device *const devices[] = { -#ifdef CONFIG_COUNTER_RTC0 - /* Nordic RTC0 may be reserved for Bluetooth */ - DEVICE_DT_GET(DT_NODELABEL(rtc0)), +#ifdef CONFIG_COUNTER_NRF_RTC + DEVS_FOR_DT_COMPAT(nordic_nrf_rtc) #endif - /* Nordic RTC1 is used for the system clock */ -#ifdef CONFIG_COUNTER_RTC2 - DEVICE_DT_GET(DT_NODELABEL(rtc2)), + +}; + +static NRF_RTC_Type *const regs[] = { +#ifdef CONFIG_COUNTER_NRF_RTC + REGS_FOR_DT_COMPAT(nordic_nrf_rtc) #endif }; -typedef void (*counter_test_func_t)(const struct device *dev); +typedef void (*counter_test_func_t)(int idx); static void counter_setup_instance(const struct device *dev) { @@ -45,15 +57,16 @@ static void test_all_instances(counter_test_func_t func) { for (int i = 0; i < ARRAY_SIZE(devices); i++) { counter_setup_instance(devices[i]); - func(devices[i]); + func(i); counter_tear_down_instance(devices[i]); /* Allow logs to be printed. */ k_sleep(K_MSEC(100)); } } -static void test_set_custom_top_value_fails_on_instance(const struct device *dev) +static void test_set_custom_top_value_fails_on_instance(int idx) { + const struct device *dev = devices[idx]; int err; struct counter_top_cfg top_cfg = { .callback = NULL, @@ -76,8 +89,10 @@ static void top_handler(const struct device *dev, void *user_data) top_cnt++; } -static void test_top_handler_on_instance(const struct device *dev) +static void test_top_handler_on_instance(int idx) { + const struct device *dev = devices[idx]; + NRF_RTC_Type *reg = regs[idx]; uint32_t tmp_top_cnt; int err; struct counter_top_cfg top_cfg = { @@ -90,12 +105,7 @@ static void test_top_handler_on_instance(const struct device *dev) err = counter_set_top_value(dev, &top_cfg); zassert_equal(0, err, "%s: Unexpected error code (%d)", dev->name, err); -#ifdef CONFIG_COUNTER_RTC0 - nrf_rtc_task_trigger(NRF_RTC0, NRF_RTC_TASK_TRIGGER_OVERFLOW); -#endif -#ifdef CONFIG_COUNTER_RTC2 - nrf_rtc_task_trigger(NRF_RTC2, NRF_RTC_TASK_TRIGGER_OVERFLOW); -#endif + nrf_rtc_task_trigger(reg, NRF_RTC_TASK_TRIGGER_OVERFLOW); counter_start(dev); k_busy_wait(10000); diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.conf b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.conf deleted file mode 100644 index b77788bd0e54..000000000000 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_COUNTER=y -CONFIG_COUNTER_TIMER0=y diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.overlay b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.overlay index 773953fefa21..23683b8910ec 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.overlay +++ b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.overlay @@ -63,3 +63,7 @@ &rtc1 { interrupts = <17 2>; }; + +&timer0 { + status = "okay"; +}; diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.conf b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.conf deleted file mode 100644 index b77788bd0e54..000000000000 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_COUNTER=y -CONFIG_COUNTER_TIMER0=y diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.overlay b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.overlay index 277ee171f0d1..897d1ea07c4f 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.overlay +++ b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -34,3 +34,7 @@ &rtc1 { interrupts = <21 2>; }; + +&timer0 { + status = "okay"; +}; diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.conf b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.conf deleted file mode 100644 index b77788bd0e54..000000000000 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_COUNTER=y -CONFIG_COUNTER_TIMER0=y diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.overlay b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.overlay index 5f39e3e5ce25..f43044e17267 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.overlay +++ b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.overlay @@ -34,3 +34,7 @@ &rtc1 { interrupts = <21 2>; }; + +&timer0 { + status = "okay"; +}; diff --git a/tests/drivers/uart/uart_mix_fifo_poll/prj.conf b/tests/drivers/uart/uart_mix_fifo_poll/prj.conf index 546be0ba6d42..ec19f1d90b5f 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/prj.conf +++ b/tests/drivers/uart/uart_mix_fifo_poll/prj.conf @@ -6,6 +6,7 @@ CONFIG_ZTEST_THREAD_PRIORITY=5 CONFIG_MAIN_STACK_SIZE=2048 CONFIG_ZTEST_STACK_SIZE=2048 CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_COUNTER=y # CONFIG_NO_OPTIMIZATIONS=y # CONFIG_LOG_MODE_MINIMAL=n diff --git a/tests/drivers/watchdog/wdt_basic_api/boards/nrf52840dk_nrf52840_counter.conf b/tests/drivers/watchdog/wdt_basic_api/boards/nrf52840dk_nrf52840_counter.conf index f3a4f1c2911a..35a9b2735c6e 100644 --- a/tests/drivers/watchdog/wdt_basic_api/boards/nrf52840dk_nrf52840_counter.conf +++ b/tests/drivers/watchdog/wdt_basic_api/boards/nrf52840dk_nrf52840_counter.conf @@ -1,8 +1,4 @@ # Disable hardware watchdog CONFIG_WDT_NRFX=n CONFIG_NRFX_WDT0=n - -# Setup counter on TIMER0 with ZLI enabled -CONFIG_COUNTER_TIMER0=y CONFIG_ZERO_LATENCY_IRQS=y -CONFIG_COUNTER_TIMER0_ZLI=y diff --git a/tests/drivers/watchdog/wdt_basic_api/boards/nrf52840dk_nrf52840_counter.overlay b/tests/drivers/watchdog/wdt_basic_api/boards/nrf52840dk_nrf52840_counter.overlay index 42eaba62c2d9..633f972221a8 100644 --- a/tests/drivers/watchdog/wdt_basic_api/boards/nrf52840dk_nrf52840_counter.overlay +++ b/tests/drivers/watchdog/wdt_basic_api/boards/nrf52840dk_nrf52840_counter.overlay @@ -7,6 +7,7 @@ &timer0 { status = "okay"; interrupts = <8 0>; + zli; }; &wdt0 { diff --git a/tests/ztest/busy_sim/boards/nrf52840dk_nrf52840.conf b/tests/ztest/busy_sim/boards/nrf52840dk_nrf52840.conf deleted file mode 100644 index 36f0e7aeaec8..000000000000 --- a/tests/ztest/busy_sim/boards/nrf52840dk_nrf52840.conf +++ /dev/null @@ -1 +0,0 @@ -CONFIG_COUNTER_TIMER0=y From d25b0318e6a58ec08ae3275416b9c715040c4c47 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Fri, 17 Mar 2023 09:56:01 +0100 Subject: [PATCH 0498/1906] tests: drivers: counter: maxim_ds3231: Remove unused test Remove test which was copied from counter_basic_api and it was always skipped. Signed-off-by: Krzysztof Chruscinski --- .../maxim_ds3231_api/src/test_counter.c | 112 ------------------ 1 file changed, 112 deletions(-) diff --git a/tests/drivers/counter/maxim_ds3231_api/src/test_counter.c b/tests/drivers/counter/maxim_ds3231_api/src/test_counter.c index 044aad3c2db4..e2b8ad00495a 100644 --- a/tests/drivers/counter/maxim_ds3231_api/src/test_counter.c +++ b/tests/drivers/counter/maxim_ds3231_api/src/test_counter.c @@ -717,118 +717,6 @@ ZTEST(counter_callback, test_short_relative_alarm) short_relative_capable); } -/* Test checks if cancelled alarm does not get triggered when new alarm is - * configured at the point where previous alarm was about to expire. - */ -static void test_cancelled_alarm_does_not_expire_instance(const struct device *dev) -{ - int err; - uint32_t alarm_cnt; - uint32_t us = 1000; - uint32_t ticks = counter_us_to_ticks(dev, us); - - us = (uint32_t)counter_ticks_to_us(dev, ticks); - - struct counter_alarm_cfg alarm_cfg = { - .callback = alarm_handler, - .flags = COUNTER_ALARM_CFG_ABSOLUTE, - .user_data = NULL - }; - - err = counter_start(dev); - zassert_equal(0, err, "%s: Unexpected error", dev->name); - - - for (int i = 0; i < us / 2; ++i) { - err = counter_get_value(dev, &(alarm_cfg.ticks)); - zassert_true(err == 0, "%s: Counter read failed (err: %d)", - dev->name, err); - - alarm_cfg.ticks += ticks; - err = counter_set_channel_alarm(dev, 0, &alarm_cfg); - zassert_equal(0, err, "%s: Failed to set an alarm (err: %d)", - dev->name, err); - - err = counter_cancel_channel_alarm(dev, 0); - zassert_equal(0, err, "%s: Failed to cancel an alarm (err: %d)", - dev->name, err); - - k_sleep(K_USEC(us / 2 + i)); - - alarm_cfg.ticks = alarm_cfg.ticks + 2 * alarm_cfg.ticks; - err = counter_set_channel_alarm(dev, 0, &alarm_cfg); - zassert_equal(0, err, "%s: Failed to set an alarm (err: %d)", - dev->name, err); - - /* wait to ensure that tick+1 timeout will expire. */ - k_sleep(K_USEC(us)); - - err = counter_cancel_channel_alarm(dev, 0); - zassert_equal(0, err, "%s: Failed to cancel an alarm (err: %d)", - dev->name, err); - - alarm_cnt = k_sem_count_get(&alarm_cnt_sem); - zassert_equal(0, alarm_cnt, - "%s: Expected %d callbacks, got %d\n", - dev->name, 0, alarm_cnt); - } -} - -static bool reliable_cancel_capable(const struct device *dev) -{ - /* Test performed only for NRF_RTC instances. Other probably will fail. - */ -#ifdef CONFIG_COUNTER_RTC0 - /* Nordic RTC0 may be reserved for Bluetooth */ - if (dev == DEVICE_DT_GET(DT_NODELABEL(rtc0))) { - return true; - } -#endif - -#ifdef CONFIG_COUNTER_RTC2 - if (dev == DEVICE_DT_GET(DT_NODELABEL(rtc2))) { - return true; - } -#endif - -#ifdef CONFIG_COUNTER_TIMER0 - if (dev == DEVICE_DT_GET(DT_NODELABEL(timer0))) { - return true; - } -#endif - -#ifdef CONFIG_COUNTER_TIMER1 - if (dev == DEVICE_DT_GET(DT_NODELABEL(timer1))) { - return true; - } -#endif - -#ifdef CONFIG_COUNTER_TIMER2 - if (dev == DEVICE_DT_GET(DT_NODELABEL(timer2))) { - return true; - } -#endif - -#ifdef CONFIG_COUNTER_TIMER3 - if (dev == DEVICE_DT_GET(DT_NODELABEL(timer3))) { - return true; - } -#endif - -#ifdef CONFIG_COUNTER_TIMER4 - if (dev == DEVICE_DT_GET(DT_NODELABEL(timer4))) { - return true; - } -#endif - return false; -} - -ZTEST(counter_callback, test_cancelled_alarm_does_not_expire) -{ - test_all_instances(test_cancelled_alarm_does_not_expire_instance, - reliable_cancel_capable); -} - static void test_ds3231_synchronize(void) { const struct device *dev = devices[0]; From 9a73b9c80dfa13755c0bed340045b696650d2f53 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Fri, 17 Mar 2023 11:20:33 +0100 Subject: [PATCH 0499/1906] hal_nordic: Change scheme for RTC and TIMER reservation In general, RTC and TIMER driver implements counter API but there are exception when those peripherals are used in a custom way (e.g. for system timer or bluetooth). In that case, system must prevent using counter based on a reserved instance. Previously, it was managed by Kconfig options but that cannot be maintained when switching to devicetree configuration of the counter driver. A new approach removes Kconfig options and instead adds static asserts in the files which are using direct peripherals. Those asserts check if given node is not enabled in the device tree. Signed-off-by: Krzysztof Chruscinski --- drivers/timer/Kconfig.nrf_rtc | 1 - drivers/timer/nrf_rtc_timer.c | 3 +++ modules/hal_nordic/Kconfig | 1 - .../radio/platform/nrf_802154_random_zephyr.c | 4 +++ soc/arm/nordic_nrf/Kconfig.peripherals | 25 ------------------- subsys/bluetooth/controller/Kconfig | 2 -- .../ll_sw/nordic/hal/nrf5/radio/radio.c | 4 +++ .../nordic/hal/nrf5/radio/radio_sim_nrfxx.h | 3 +++ 8 files changed, 14 insertions(+), 29 deletions(-) diff --git a/drivers/timer/Kconfig.nrf_rtc b/drivers/timer/Kconfig.nrf_rtc index 853af3a0958b..f332113c00ad 100644 --- a/drivers/timer/Kconfig.nrf_rtc +++ b/drivers/timer/Kconfig.nrf_rtc @@ -8,7 +8,6 @@ config NRF_RTC_TIMER depends on CLOCK_CONTROL depends on SOC_COMPATIBLE_NRF select TICKLESS_CAPABLE - select NRF_HW_RTC1_RESERVED help This module implements a kernel device driver for the nRF Real Time Counter NRF_RTC1 and provides the standard "system clock driver" diff --git a/drivers/timer/nrf_rtc_timer.c b/drivers/timer/nrf_rtc_timer.c index 870b3f2819ea..bef69af38bde 100644 --- a/drivers/timer/nrf_rtc_timer.c +++ b/drivers/timer/nrf_rtc_timer.c @@ -25,6 +25,9 @@ #define RTC_CH_COUNT RTC1_CC_NUM BUILD_ASSERT(CHAN_COUNT <= RTC_CH_COUNT, "Not enough compare channels"); +/* Ensure that counter driver for RTC1 is not enabled. */ +BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(RTC_LABEL), disabled), + "Counter for RTC1 must be disabled"); #define COUNTER_BIT_WIDTH 24U #define COUNTER_SPAN BIT(COUNTER_BIT_WIDTH) diff --git a/modules/hal_nordic/Kconfig b/modules/hal_nordic/Kconfig index 0e904c660695..092ecd07a7b5 100644 --- a/modules/hal_nordic/Kconfig +++ b/modules/hal_nordic/Kconfig @@ -23,7 +23,6 @@ menuconfig NRF_802154_RADIO_DRIVER depends on HAS_HW_NRF_RADIO_IEEE802154 select DYNAMIC_INTERRUPTS select ENTROPY_GENERATOR - select NRF_HW_TIMER1_RESERVED help This option enables nRF IEEE 802.15.4 radio driver in Zephyr. Note, that beside the radio peripheral itself, this drivers occupies several diff --git a/modules/hal_nordic/nrf_802154/radio/platform/nrf_802154_random_zephyr.c b/modules/hal_nordic/nrf_802154/radio/platform/nrf_802154_random_zephyr.c index 7645601343b7..6b78cd6198b5 100644 --- a/modules/hal_nordic/nrf_802154/radio/platform/nrf_802154_random_zephyr.c +++ b/modules/hal_nordic/nrf_802154/radio/platform/nrf_802154_random_zephyr.c @@ -8,6 +8,10 @@ #include #include +/* Ensure that counter driver for TIMER1 is not enabled. */ +BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(timer1), disabled), + "Counter for TIMER1 must be disabled"); + static uint32_t state; static uint32_t next(void) diff --git a/soc/arm/nordic_nrf/Kconfig.peripherals b/soc/arm/nordic_nrf/Kconfig.peripherals index f5ae9041b6e7..de3da1f9b7d4 100644 --- a/soc/arm/nordic_nrf/Kconfig.peripherals +++ b/soc/arm/nordic_nrf/Kconfig.peripherals @@ -299,28 +299,3 @@ config HAS_HW_NRF_WDT0 config HAS_HW_NRF_WDT1 def_bool $(dt_nodelabel_enabled_with_compat,wdt1,$(DT_COMPAT_NORDIC_NRF_WDT)) - -# Reserved HW peripherals -config NRF_HW_TIMER0_RESERVED - bool - -config NRF_HW_TIMER1_RESERVED - bool - -config NRF_HW_TIMER2_RESERVED - bool - -config NRF_HW_TIMER3_RESERVED - bool - -config NRF_HW_TIMER4_RESERVED - bool - -config NRF_HW_RTC0_RESERVED - bool - -config NRF_HW_RTC1_RESERVED - bool - -config NRF_HW_RTC2_RESERVED - bool diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 63c7b83bc3f8..ef792cf0fb8c 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -108,8 +108,6 @@ choice BT_LL_CHOICE config BT_LL_SW_SPLIT bool "Software-based BLE Link Layer" select ENTROPY_GENERATOR - select NRF_HW_TIMER0_RESERVED - select NRF_HW_RTC0_RESERVED help Use Zephyr software BLE Link Layer ULL LLL split implementation. diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index 1af23246bd64..85dcf4ec3f9e 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -29,6 +29,10 @@ #include "radio_internal.h" +/* Ensure that counter driver for RTC0 is not enabled. */ +BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(rtc0), disabled), + "Counter for RTC0 must be disabled"); + /* Converts the GPIO controller in a FEM property's GPIO specification * to its nRF register map pointer. * diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h index 317638eeabf7..3090ee09cf12 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h @@ -187,6 +187,9 @@ #if defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) #undef EVENT_TIMER #define EVENT_TIMER NRF_TIMER0 +/* Ensure that counter driver for TIMER0 is not enabled. */ +BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(timer0), disabled), + "Counter for TIMER0 must be disabled"); #define SW_SWITCH_TIMER EVENT_TIMER #define SW_SWITCH_TIMER_EVTS_COMP_BASE 0 #else /* !CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */ From 5af49c1e3552e241b4dc05b7525bc32c868a10dd Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Mon, 20 Mar 2023 11:49:14 +0100 Subject: [PATCH 0500/1906] hal_nordic: Add protection against resource conflict Add check in CMake files to prevent resource overlap for TIMER0, TIMER1, RTC0. Signed-off-by: Krzysztof Chruscinski --- modules/hal_nordic/nrf_802154/CMakeLists.txt | 7 +++++++ .../radio/platform/nrf_802154_random_zephyr.c | 4 ---- .../controller/ll_sw/nordic/hal/nrf5/radio/radio.c | 4 ---- .../ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h | 3 --- subsys/bluetooth/controller/ll_sw/nrf.cmake | 12 ++++++++++++ 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/modules/hal_nordic/nrf_802154/CMakeLists.txt b/modules/hal_nordic/nrf_802154/CMakeLists.txt index 1ec8afbfdfb9..c51bcc7eed6b 100644 --- a/modules/hal_nordic/nrf_802154/CMakeLists.txt +++ b/modules/hal_nordic/nrf_802154/CMakeLists.txt @@ -5,6 +5,13 @@ zephyr_library_named(nrf-802154-platform) zephyr_interface_library_named(zephyr-802154-interface) if (CONFIG_NRF_802154_RADIO_DRIVER) + dt_nodelabel(timer1_node NODELABEL "timer1") + dt_node_has_status(status_result PATH ${timer1_node} STATUS okay) + if (${status_result}) + message(FATAL_ERROR "Resource conflict. IEEE802.15.4 Radio driver requires TIMER1 but " + "timer1 node is enabled (for counter driver).") + endif() + target_sources(nrf-802154-platform PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/radio/platform/nrf_802154_random_zephyr.c diff --git a/modules/hal_nordic/nrf_802154/radio/platform/nrf_802154_random_zephyr.c b/modules/hal_nordic/nrf_802154/radio/platform/nrf_802154_random_zephyr.c index 6b78cd6198b5..7645601343b7 100644 --- a/modules/hal_nordic/nrf_802154/radio/platform/nrf_802154_random_zephyr.c +++ b/modules/hal_nordic/nrf_802154/radio/platform/nrf_802154_random_zephyr.c @@ -8,10 +8,6 @@ #include #include -/* Ensure that counter driver for TIMER1 is not enabled. */ -BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(timer1), disabled), - "Counter for TIMER1 must be disabled"); - static uint32_t state; static uint32_t next(void) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index 85dcf4ec3f9e..1af23246bd64 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -29,10 +29,6 @@ #include "radio_internal.h" -/* Ensure that counter driver for RTC0 is not enabled. */ -BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(rtc0), disabled), - "Counter for RTC0 must be disabled"); - /* Converts the GPIO controller in a FEM property's GPIO specification * to its nRF register map pointer. * diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h index 3090ee09cf12..317638eeabf7 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_sim_nrfxx.h @@ -187,9 +187,6 @@ #if defined(CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER) #undef EVENT_TIMER #define EVENT_TIMER NRF_TIMER0 -/* Ensure that counter driver for TIMER0 is not enabled. */ -BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(timer0), disabled), - "Counter for TIMER0 must be disabled"); #define SW_SWITCH_TIMER EVENT_TIMER #define SW_SWITCH_TIMER_EVTS_COMP_BASE 0 #else /* !CONFIG_BT_CTLR_SW_SWITCH_SINGLE_TIMER */ diff --git a/subsys/bluetooth/controller/ll_sw/nrf.cmake b/subsys/bluetooth/controller/ll_sw/nrf.cmake index a0a6324e1009..909734b62cf0 100644 --- a/subsys/bluetooth/controller/ll_sw/nrf.cmake +++ b/subsys/bluetooth/controller/ll_sw/nrf.cmake @@ -1,6 +1,18 @@ # SPDX-License-Identifier: Apache-2.0 if(CONFIG_BT_LL_SW_SPLIT) + dt_nodelabel(rtc0_node NODELABEL "rtc0") + dt_node_has_status(status_result PATH ${rtc0_node} STATUS okay) + if (${status_result}) + message(FATAL_ERROR "Resource conflict. Bluetooth Link Layer requires RTC0 but " + "rtc0 node is enabled (for counter driver).") + endif() + dt_nodelabel(timer0_node NODELABEL "timer0") + dt_node_has_status(status_result PATH ${timer0_node} STATUS okay) + if (${status_result}) + message(FATAL_ERROR "Resource conflict. Bluetooth Link Layer requires TIMER0 but " + "timer0 node is enabled (for counter driver).") + endif() zephyr_library_sources( ll_sw/nordic/lll/lll.c ll_sw/nordic/lll/lll_clock.c From 369ffb4929cd5a0f2253e0fdaf15b70ec275c3aa Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Mon, 20 Mar 2023 16:19:17 +0100 Subject: [PATCH 0501/1906] hal_nordic: Add protection against resource conflict (take 2) Commit will be squeezed once agreement is reached. Signed-off-by: Krzysztof Chruscinski --- modules/hal_nordic/Kconfig | 1 + modules/hal_nordic/nrf_802154/CMakeLists.txt | 7 ------- subsys/bluetooth/controller/Kconfig.ll_sw_split | 2 ++ subsys/bluetooth/controller/ll_sw/nrf.cmake | 12 ------------ 4 files changed, 3 insertions(+), 19 deletions(-) diff --git a/modules/hal_nordic/Kconfig b/modules/hal_nordic/Kconfig index 092ecd07a7b5..f842d2cb646b 100644 --- a/modules/hal_nordic/Kconfig +++ b/modules/hal_nordic/Kconfig @@ -23,6 +23,7 @@ menuconfig NRF_802154_RADIO_DRIVER depends on HAS_HW_NRF_RADIO_IEEE802154 select DYNAMIC_INTERRUPTS select ENTROPY_GENERATOR + depends on !$(dt_nodelabel_enabled,timer1) help This option enables nRF IEEE 802.15.4 radio driver in Zephyr. Note, that beside the radio peripheral itself, this drivers occupies several diff --git a/modules/hal_nordic/nrf_802154/CMakeLists.txt b/modules/hal_nordic/nrf_802154/CMakeLists.txt index c51bcc7eed6b..1ec8afbfdfb9 100644 --- a/modules/hal_nordic/nrf_802154/CMakeLists.txt +++ b/modules/hal_nordic/nrf_802154/CMakeLists.txt @@ -5,13 +5,6 @@ zephyr_library_named(nrf-802154-platform) zephyr_interface_library_named(zephyr-802154-interface) if (CONFIG_NRF_802154_RADIO_DRIVER) - dt_nodelabel(timer1_node NODELABEL "timer1") - dt_node_has_status(status_result PATH ${timer1_node} STATUS okay) - if (${status_result}) - message(FATAL_ERROR "Resource conflict. IEEE802.15.4 Radio driver requires TIMER1 but " - "timer1 node is enabled (for counter driver).") - endif() - target_sources(nrf-802154-platform PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/radio/platform/nrf_802154_random_zephyr.c diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index f0c7e25a29fc..7971b18c58d4 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -55,6 +55,8 @@ config BT_LLL_VENDOR_NORDIC select BT_TICKER_LAZY_GET if BT_CTLR_ADV_PERIODIC default y + depends on !$(dt_nodelabel_enabled,timer0) + depends on !$(dt_nodelabel_enabled,rtc0) help Use Nordic Lower Link Layer implementation. diff --git a/subsys/bluetooth/controller/ll_sw/nrf.cmake b/subsys/bluetooth/controller/ll_sw/nrf.cmake index 909734b62cf0..a0a6324e1009 100644 --- a/subsys/bluetooth/controller/ll_sw/nrf.cmake +++ b/subsys/bluetooth/controller/ll_sw/nrf.cmake @@ -1,18 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 if(CONFIG_BT_LL_SW_SPLIT) - dt_nodelabel(rtc0_node NODELABEL "rtc0") - dt_node_has_status(status_result PATH ${rtc0_node} STATUS okay) - if (${status_result}) - message(FATAL_ERROR "Resource conflict. Bluetooth Link Layer requires RTC0 but " - "rtc0 node is enabled (for counter driver).") - endif() - dt_nodelabel(timer0_node NODELABEL "timer0") - dt_node_has_status(status_result PATH ${timer0_node} STATUS okay) - if (${status_result}) - message(FATAL_ERROR "Resource conflict. Bluetooth Link Layer requires TIMER0 but " - "timer0 node is enabled (for counter driver).") - endif() zephyr_library_sources( ll_sw/nordic/lll/lll.c ll_sw/nordic/lll/lll_clock.c From d4ed0d7a2de8530923b8a53b7cc6328e2e4cd3f7 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Thu, 16 Mar 2023 14:58:04 +0000 Subject: [PATCH 0502/1906] tests: lib: mem_alloc: skip reallocarray test on arm clang The arm clang toolchain provides its own libc and that libc doesn't implement reallocarray, so skip the test like we do on newlib. Signed-off-by: Kumar Gala --- tests/lib/mem_alloc/src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lib/mem_alloc/src/main.c b/tests/lib/mem_alloc/src/main.c index fde99723602f..228256d79d04 100644 --- a/tests/lib/mem_alloc/src/main.c +++ b/tests/lib/mem_alloc/src/main.c @@ -242,10 +242,10 @@ ZTEST(c_lib_dynamic_memalloc, test_realloc) * * @see malloc(), reallocarray(), free() */ -#ifdef CONFIG_NEWLIB_LIBC +#if defined(CONFIG_NEWLIB_LIBC) || defined(CONFIG_ARMCLANG_STD_LIBC) ZTEST(c_lib_dynamic_memalloc, test_reallocarray) { - /* reallocarray not implemented for newlib */ + /* reallocarray not implemented for newlib or arm libc */ ztest_test_skip(); } ZTEST(c_lib_dynamic_memalloc, test_calloc) From 9889e8e20a4ffe1f442f499d51e55fa7cb73c806 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Sun, 19 Mar 2023 21:31:55 +0000 Subject: [PATCH 0503/1906] input: move the listener section in common-rom Move the input listener section declaration in common-rom-misc.ld instead of using a custom input.ld file. This seems to be the common practice for upstream iterable sections and seems to solve a compatibility issue where the section was getting allocated incorrectly on esp32 based platforms. Signed-off-by: Fabio Baltieri --- include/zephyr/linker/common-rom/common-rom-misc.ld | 4 ++++ subsys/input/CMakeLists.txt | 2 -- subsys/input/input.ld | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) delete mode 100644 subsys/input/input.ld diff --git a/include/zephyr/linker/common-rom/common-rom-misc.ld b/include/zephyr/linker/common-rom/common-rom-misc.ld index 310c1ec763a9..3eef80f00af5 100644 --- a/include/zephyr/linker/common-rom/common-rom-misc.ld +++ b/include/zephyr/linker/common-rom/common-rom-misc.ld @@ -16,6 +16,10 @@ ITERABLE_SECTION_ROM(mcumgr_handler, 4) #endif +#if defined(CONFIG_INPUT) + ITERABLE_SECTION_ROM(input_listener, 4) +#endif + #if defined(CONFIG_EMUL) SECTION_DATA_PROLOGUE(emulators_section,,) { diff --git a/subsys/input/CMakeLists.txt b/subsys/input/CMakeLists.txt index 5356cf887855..6a5b1c4bc13b 100644 --- a/subsys/input/CMakeLists.txt +++ b/subsys/input/CMakeLists.txt @@ -3,5 +3,3 @@ zephyr_library() zephyr_library_sources(input.c) - -zephyr_linker_sources(SECTIONS input.ld) diff --git a/subsys/input/input.ld b/subsys/input/input.ld deleted file mode 100644 index 8aa4e98dc4b7..000000000000 --- a/subsys/input/input.ld +++ /dev/null @@ -1 +0,0 @@ -ITERABLE_SECTION_ROM(input_listener, 4) From 16e9362ba07deedc28de6176ee3efba390b73272 Mon Sep 17 00:00:00 2001 From: Evgeniy Paltsev Date: Sat, 18 Mar 2023 23:32:43 +0000 Subject: [PATCH 0504/1906] ARC: SMP: fix IDU mask setup Fix IDU mask setup: * fix GENMASK usage to avoid generating mask to one extra cpu (which doesn't exist in configuration) * use arch_num_cpus() instead of CONFIG_MP_NUM_CPUS to allow having some cpu's disabled (with detection in runtime) Signed-off-by: Eugeniy Paltsev Signed-off-by: Evgeniy Paltsev --- drivers/interrupt_controller/intc_arcv2_irq_unit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/interrupt_controller/intc_arcv2_irq_unit.c b/drivers/interrupt_controller/intc_arcv2_irq_unit.c index 4a060736ce8c..42863fd8cb5e 100644 --- a/drivers/interrupt_controller/intc_arcv2_irq_unit.c +++ b/drivers/interrupt_controller/intc_arcv2_irq_unit.c @@ -67,7 +67,7 @@ static int arc_shared_intc_update_post_smp(const struct device *unused) for (uint32_t i = 0; i < (CONFIG_NUM_IRQS - ARC_CONNECT_IDU_IRQ_START); i++) { /* TODO: take arc_connect_spinlock one time to avoid locking/unlocking every time */ - z_arc_connect_idu_set_dest(i, GENMASK(CONFIG_MP_NUM_CPUS, 0)); + z_arc_connect_idu_set_dest(i, GENMASK((arch_num_cpus() - 1), 0)); } z_arc_connect_idu_enable(); From d4d0907ede61fceb1e2200ee2867b9a4371917f1 Mon Sep 17 00:00:00 2001 From: Evgeniy Paltsev Date: Mon, 20 Mar 2023 19:57:56 +0000 Subject: [PATCH 0505/1906] ARC: SMP: simplify CPU mask generation with BIT_MASK Simplify CPU mask generation by replacing GENMASK with BIT_MASK. Signed-off-by: Eugeniy Paltsev Signed-off-by: Evgeniy Paltsev --- drivers/interrupt_controller/intc_arcv2_irq_unit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/interrupt_controller/intc_arcv2_irq_unit.c b/drivers/interrupt_controller/intc_arcv2_irq_unit.c index 42863fd8cb5e..c3acee26ea71 100644 --- a/drivers/interrupt_controller/intc_arcv2_irq_unit.c +++ b/drivers/interrupt_controller/intc_arcv2_irq_unit.c @@ -67,7 +67,7 @@ static int arc_shared_intc_update_post_smp(const struct device *unused) for (uint32_t i = 0; i < (CONFIG_NUM_IRQS - ARC_CONNECT_IDU_IRQ_START); i++) { /* TODO: take arc_connect_spinlock one time to avoid locking/unlocking every time */ - z_arc_connect_idu_set_dest(i, GENMASK((arch_num_cpus() - 1), 0)); + z_arc_connect_idu_set_dest(i, BIT_MASK(arch_num_cpus())); } z_arc_connect_idu_enable(); From add1397e4a8d7733ba9421d9fd5667cc296e263f Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Mon, 20 Mar 2023 11:09:38 +0100 Subject: [PATCH 0506/1906] tests/bsim/bluetooth: Tests scripts refactor Move common parts to common scripts, and clean up some unnecessary content. Signed-off-by: Alberto Escolar Piedras --- tests/bsim/bluetooth/audio/compile.sh | 5 +-- .../bluetooth/audio/test_scripts/bap_bass.sh | 22 ++---------- .../audio/test_scripts/bap_broadcast_audio.sh | 26 +++----------- .../audio/test_scripts/bap_unicast_audio.sh | 23 ++---------- .../audio/test_scripts/cap_broadcast.sh | 22 ++---------- .../audio/test_scripts/cap_unicast.sh | 22 ++---------- .../bsim/bluetooth/audio/test_scripts/csip.sh | 33 ++++------------- .../bsim/bluetooth/audio/test_scripts/has.sh | 24 +++---------- .../bsim/bluetooth/audio/test_scripts/ias.sh | 24 +++---------- .../bluetooth/audio/test_scripts/mcs_mcc.sh | 24 +++---------- .../audio/test_scripts/media_controller.sh | 28 +++------------ .../bsim/bluetooth/audio/test_scripts/micp.sh | 28 +++------------ .../bsim/bluetooth/audio/test_scripts/tbs.sh | 20 ++--------- .../bsim/bluetooth/audio/test_scripts/vcp.sh | 28 +++------------ .../host/adv/chain/tests_scripts/adv_chain.sh | 23 +++--------- .../adv/periodic/tests_scripts/per_adv.sh | 24 +++---------- .../periodic/tests_scripts/per_adv_conn.sh | 24 +++---------- .../tests_scripts/per_adv_conn_privacy.sh | 24 +++---------- .../tests_scripts/per_adv_long_data.sh | 24 +++---------- .../host/adv/resume/test_scripts/_env.sh | 2 -- .../adv/resume/test_scripts/run_adv_resume.sh | 22 ++---------- .../resume/test_scripts/run_adv_resume_2.sh | 22 ++---------- .../att/eatt/tests_scripts/autoconnect.sh | 23 +++--------- .../host/att/eatt/tests_scripts/collision.sh | 23 +++--------- .../att/eatt/tests_scripts/multiple_conn.sh | 23 +++--------- .../att/eatt/tests_scripts/reconfigure.sh | 23 +++--------- .../att/eatt_notif/test_scripts/eatt_notif.sh | 23 +++--------- .../att/mtu_update/test_scripts/_compile.sh | 5 +-- .../host/att/mtu_update/test_scripts/_env.sh | 15 -------- .../att/mtu_update/test_scripts/run_test.sh | 26 ++++---------- tests/bsim/bluetooth/host/compile.sh | 3 +- .../gatt/caching/test_scripts/_run_test.sh | 25 +++---------- .../host/gatt/general/test_scripts/gatt.sh | 24 +++---------- .../gatt/notify/test_scripts/_run_test.sh | 26 +++----------- .../gatt_notify_enhanced_enhanced.sh | 2 -- .../gatt_notify_enhanced_mixed.sh | 2 -- .../test_scripts/gatt_notify_enhanced_none.sh | 2 -- .../gatt_notify_enhanced_unenhanced.sh | 2 -- .../gatt_notify_mixed_enhanced.sh | 2 -- .../test_scripts/gatt_notify_mixed_mixed.sh | 2 -- .../test_scripts/gatt_notify_mixed_none.sh | 2 -- .../gatt_notify_mixed_unenhanced.sh | 2 -- .../test_scripts/gatt_notify_none_enhanced.sh | 2 -- .../test_scripts/gatt_notify_none_mixed.sh | 2 -- .../test_scripts/gatt_notify_none_none.sh | 2 -- .../gatt_notify_none_unenhanced.sh | 2 -- .../gatt_notify_unenhanced_enhanced.sh | 2 -- .../gatt_notify_unenhanced_mixed.sh | 2 -- .../gatt_notify_unenhanced_none.sh | 2 -- .../gatt_notify_unenhanced_unenhanced.sh | 2 -- .../test_scripts/_notify-debug.sh | 2 -- .../notify_multiple/test_scripts/notify.sh | 24 +++---------- .../gatt/settings/test_scripts/_compile.sh | 2 +- .../host/gatt/settings/test_scripts/_env.sh | 2 -- .../test_scripts/run_gatt_settings.sh | 24 +++---------- .../test_scripts/run_gatt_settings_2.sh | 24 +++---------- .../gatt/write/tests_scripts/gatt_write.sh | 23 +++--------- .../host/l2cap/general/tests_scripts/l2cap.sh | 23 +++--------- .../host/l2cap/stress/tests_scripts/l2cap.sh | 24 +++---------- .../l2cap/userdata/tests_scripts/l2cap.sh | 25 +++---------- .../misc/disable/tests_scripts/disable.sh | 23 +++--------- .../tests_scripts/disable_with_gatt.sh | 23 +++--------- .../multiple_id/tests_scripts/multiple.sh | 23 +++--------- .../privacy/central/test_scripts/_compile.sh | 5 +-- .../host/privacy/central/test_scripts/_env.sh | 17 --------- .../privacy/central/test_scripts/run_test.sh | 27 +++----------- .../privacy/device/test_scripts/run_tests.sh | 26 ++------------ .../peripheral/test_scripts/_compile.sh | 2 +- .../privacy/peripheral/test_scripts/_env.sh | 17 --------- .../peripheral/test_scripts/run_test.sh | 25 +++---------- .../test_scripts/_compile.sh | 4 +-- .../test_scripts/_env.sh | 15 -------- .../test_scripts/run_test.sh | 24 +++---------- .../test_scripts/_compile.sh | 4 +-- .../test_scripts/run_test.sh | 23 +++--------- .../ll/advx/tests_scripts/basic_advx.sh | 23 +++--------- tests/bsim/bluetooth/ll/compile.sh | 4 +-- .../basic_conn_encrypted_split.sh | 23 +++--------- .../basic_conn_encrypted_split_privacy.sh | 23 +++--------- .../ll/conn/tests_scripts/basic_conn_split.sh | 23 +++--------- .../tests_scripts/basic_conn_split_low_lat.sh | 23 +++--------- .../tests_scripts/_controller_tests_inner.sh | 31 ++++++---------- .../ll/edtt/tests_scripts/gatt.llcp.sh | 23 +++--------- .../ll/iso/tests_scripts/broadcast_iso.sh | 23 +++--------- .../iso/tests_scripts/broadcast_iso_vs_dp.sh | 23 +++--------- tests/bsim/bluetooth/mesh/_mesh_test.sh | 35 ++----------------- tests/bsim/bluetooth/mesh/compile.sh | 3 -- tests/bsim/compile.sh | 4 +-- tests/bsim/sh_common.source | 34 +++++++++++++++++- 89 files changed, 277 insertions(+), 1214 deletions(-) diff --git a/tests/bsim/bluetooth/audio/compile.sh b/tests/bsim/bluetooth/audio/compile.sh index a77799ea4771..c06c5a1e67b0 100755 --- a/tests/bsim/bluetooth/audio/compile.sh +++ b/tests/bsim/bluetooth/audio/compile.sh @@ -7,13 +7,14 @@ #set -x #uncomment this line for debugging set -ue -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" + + : "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ directory}" WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" -BOARD="${BOARD:-nrf52_bsim}" + BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} diff --git a/tests/bsim/bluetooth/audio/test_scripts/bap_bass.sh b/tests/bsim/bluetooth/audio/test_scripts/bap_bass.sh index 7a08b12313f6..cc0f059379a5 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/bap_bass.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/bap_bass.sh @@ -6,21 +6,9 @@ SIMULATION_ID="bass" VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 +EXECUTE_TIMEOUT=20 -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source cd ${BSIM_OUT_PATH}/bin @@ -41,8 +29,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -D=3 \ -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/audio/test_scripts/bap_broadcast_audio.sh b/tests/bsim/bluetooth/audio/test_scripts/bap_broadcast_audio.sh index 2e5b7d4c2d29..10e9af21bbe5 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/bap_broadcast_audio.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/bap_broadcast_audio.sh @@ -5,21 +5,9 @@ # SPDX-License-Identifier: Apache-2.0 VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 +EXECUTE_TIMEOUT=20 -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source cd ${BSIM_OUT_PATH}/bin @@ -38,9 +26,7 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=2 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done +wait_for_background_jobs printf "\n\n======== Broadcaster sink disconnect test =========\n\n" @@ -58,8 +44,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=2 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio.sh b/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio.sh index 9d9b82ea9bc9..5fd562a29f8d 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio.sh @@ -6,21 +6,9 @@ SIMULATION_ID="unicast_audio" VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 +EXECUTE_TIMEOUT=20 -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source cd ${BSIM_OUT_PATH}/bin @@ -29,7 +17,6 @@ printf "\n\n======== Unicast Audio test =========\n\n" Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=unicast_client -rs=23 - Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=unicast_server -rs=27 @@ -37,8 +24,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=2 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast.sh b/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast.sh index 5f448cf2279c..a18573e2192d 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/cap_broadcast.sh @@ -6,21 +6,9 @@ SIMULATION_ID="cap_broadcast" VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 +EXECUTE_TIMEOUT=20 -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source cd ${BSIM_OUT_PATH}/bin @@ -36,8 +24,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=2 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/audio/test_scripts/cap_unicast.sh b/tests/bsim/bluetooth/audio/test_scripts/cap_unicast.sh index f0ed6f2c3bb8..e657ac958eed 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/cap_unicast.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/cap_unicast.sh @@ -6,21 +6,9 @@ SIMULATION_ID="cap_unicast" VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 +EXECUTE_TIMEOUT=20 -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source cd ${BSIM_OUT_PATH}/bin @@ -36,8 +24,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=2 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/audio/test_scripts/csip.sh b/tests/bsim/bluetooth/audio/test_scripts/csip.sh index 20b307a2ff8f..1490b3432fdd 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/csip.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/csip.sh @@ -7,22 +7,10 @@ # Basic CSIP test. A set coordinator connects to multiple set members # lock thems, unlocks them and disconnects. -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +VERBOSITY_LEVEL=2 +EXECUTE_TIMEOUT=20 cd ${BSIM_OUT_PATH}/bin @@ -51,11 +39,7 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=4 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -PROCESS_IDS=""; +wait_for_background_jobs # TEST WITH FORCE RELEASE @@ -82,9 +66,7 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=4 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done +wait_for_background_jobs # TEST WITH SIRK ENC @@ -111,7 +93,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=4 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/audio/test_scripts/has.sh b/tests/bsim/bluetooth/audio/test_scripts/has.sh index b35c7c131862..e2bface0396a 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/has.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/has.sh @@ -4,23 +4,11 @@ # # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + SIMULATION_ID="has" VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=20 cd ${BSIM_OUT_PATH}/bin @@ -35,8 +23,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=2 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/audio/test_scripts/ias.sh b/tests/bsim/bluetooth/audio/test_scripts/ias.sh index a310c1dd232a..3547d6996e8d 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/ias.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/ias.sh @@ -4,23 +4,11 @@ # # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + SIMULATION_ID="ias" VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=20 cd ${BSIM_OUT_PATH}/bin @@ -36,8 +24,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=2 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/audio/test_scripts/mcs_mcc.sh b/tests/bsim/bluetooth/audio/test_scripts/mcs_mcc.sh index 679b3026af1b..1e31932efe77 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/mcs_mcc.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/mcs_mcc.sh @@ -4,23 +4,11 @@ # # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + SIMULATION_ID="mcs_mcc" VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=20 cd ${BSIM_OUT_PATH}/bin @@ -36,8 +24,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=2 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/audio/test_scripts/media_controller.sh b/tests/bsim/bluetooth/audio/test_scripts/media_controller.sh index 16a913a7daca..ab036d39497b 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/media_controller.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/media_controller.sh @@ -4,23 +4,11 @@ # # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + SIMULATION_ID="media_controller" VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=20 cd ${BSIM_OUT_PATH}/bin @@ -33,9 +21,7 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=1 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done +wait_for_background_jobs printf "\n\n======== Running media controller remote_player test =========\n\n" @@ -49,8 +35,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=2 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/audio/test_scripts/micp.sh b/tests/bsim/bluetooth/audio/test_scripts/micp.sh index 06c201319d3b..3117f6651169 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/micp.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/micp.sh @@ -4,23 +4,11 @@ # # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + SIMULATION_ID="micp" VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=20 cd ${BSIM_OUT_PATH}/bin @@ -33,9 +21,7 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=1 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done +wait_for_background_jobs printf "\n\n==== Running MICP Microphone Device and MICP Microphone Controller test ====n\n" @@ -49,8 +35,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=2 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/audio/test_scripts/tbs.sh b/tests/bsim/bluetooth/audio/test_scripts/tbs.sh index 84b44a29decf..e5f9e09fbd51 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/tbs.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/tbs.sh @@ -7,21 +7,10 @@ SIMULATION_ID="tbs_ccp" VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=20 cd ${BSIM_OUT_PATH}/bin @@ -35,7 +24,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=2 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/audio/test_scripts/vcp.sh b/tests/bsim/bluetooth/audio/test_scripts/vcp.sh index 56e28e78aad4..0be421894baa 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/vcp.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/vcp.sh @@ -4,23 +4,11 @@ # # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + SIMULATION_ID="vcp" VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=20 cd ${BSIM_OUT_PATH}/bin @@ -33,9 +21,7 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=1 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done +wait_for_background_jobs printf "\n\n======== Running VCP Volume Renderer and VCP Volume Controller test =========\n\n" @@ -49,8 +35,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=2 -sim_length=60e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/adv/chain/tests_scripts/adv_chain.sh b/tests/bsim/bluetooth/host/adv/chain/tests_scripts/adv_chain.sh index 28b608efd349..ab3f1c078967 100755 --- a/tests/bsim/bluetooth/host/adv/chain/tests_scripts/adv_chain.sh +++ b/tests/bsim/bluetooth/host/adv/chain/tests_scripts/adv_chain.sh @@ -4,23 +4,11 @@ # Validate Extended Advertising AD Data fragment operation, PDU chaining and # Extended Scanning of chain PDUs +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + simulation_id="adv_chain" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 10 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=10 cd ${BSIM_OUT_PATH}/bin @@ -33,7 +21,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_chain_prj_conf\ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=10e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv.sh b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv.sh index 3d1e189a7764..aa2e8249fae7 100755 --- a/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv.sh +++ b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv.sh @@ -4,23 +4,12 @@ # Basic periodic advertising sync test: an advertiser advertises with periodic # advertising, and a scanner scans for and syncs to the periodic advertising. -simulation_id="per_adv" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 10 $@ & process_ids="$process_ids $!" -} -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +simulation_id="per_adv" +verbosity_level=2 +EXECUTE_TIMEOUT=10 cd ${BSIM_OUT_PATH}/bin @@ -35,7 +24,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_periodic_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=20e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn.sh b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn.sh index 70dbdb101b10..de535d787270 100755 --- a/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn.sh +++ b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn.sh @@ -4,23 +4,12 @@ # Basic periodic advertising sync test: an advertiser advertises with periodic # advertising, and a scanner scans for and syncs to the periodic advertising. -simulation_id="per_adv_conn" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 10 $@ & process_ids="$process_ids $!" -} -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +simulation_id="per_adv_conn" +verbosity_level=2 +EXECUTE_TIMEOUT=10 cd ${BSIM_OUT_PATH}/bin @@ -35,7 +24,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_periodic_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=20e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh index eede26ce116e..d7d2ad91414a 100755 --- a/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh +++ b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh @@ -4,23 +4,12 @@ # Basic periodic advertising sync test: an advertiser advertises with periodic # advertising, and a scanner scans for and syncs to the periodic advertising. -simulation_id="per_adv_conn_privacy" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 10 $@ & process_ids="$process_ids $!" -} -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +simulation_id="per_adv_conn_privacy" +verbosity_level=2 +EXECUTE_TIMEOUT=10 cd ${BSIM_OUT_PATH}/bin @@ -35,7 +24,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_periodic_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=20e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_long_data.sh b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_long_data.sh index 6b4e65438bc9..7cac7527c99a 100755 --- a/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_long_data.sh +++ b/tests/bsim/bluetooth/host/adv/periodic/tests_scripts/per_adv_long_data.sh @@ -4,23 +4,12 @@ # Basic periodic advertising sync test: an advertiser advertises with periodic # advertising, and a scanner scans for and syncs to the periodic advertising. -simulation_id="per_adv_long_data" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 10 $@ & process_ids="$process_ids $!" -} -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +simulation_id="per_adv_long_data" +verbosity_level=2 +EXECUTE_TIMEOUT=10 cd ${BSIM_OUT_PATH}/bin @@ -35,7 +24,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_adv_periodic_prj_long_data_conf Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=20e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/adv/resume/test_scripts/_env.sh b/tests/bsim/bluetooth/host/adv/resume/test_scripts/_env.sh index 98dff68bc08c..ccd11480a19c 100755 --- a/tests/bsim/bluetooth/host/adv/resume/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/adv/resume/test_scripts/_env.sh @@ -4,8 +4,6 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - test_name="$(basename "$(realpath "$bash_source_dir/..")")" bsim_bin="${BSIM_OUT_PATH}/bin" BOARD="${BOARD:-nrf52_bsim}" diff --git a/tests/bsim/bluetooth/host/adv/resume/test_scripts/run_adv_resume.sh b/tests/bsim/bluetooth/host/adv/resume/test_scripts/run_adv_resume.sh index 8d00beddf0a1..ee9d971fb230 100755 --- a/tests/bsim/bluetooth/host/adv/resume/test_scripts/run_adv_resume.sh +++ b/tests/bsim/bluetooth/host/adv/resume/test_scripts/run_adv_resume.sh @@ -5,25 +5,12 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -# Read variable definitions output by _env.sh source "${bash_source_dir}/_env.sh" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source simulation_id="${test_name}" verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +EXECUTE_TIMEOUT=30 cd ${BSIM_OUT_PATH}/bin @@ -43,7 +30,4 @@ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ # gdb --args "$test_exe" \ # -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral -RealEncryption=1 -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/adv/resume/test_scripts/run_adv_resume_2.sh b/tests/bsim/bluetooth/host/adv/resume/test_scripts/run_adv_resume_2.sh index c7f375656271..b7f29d1b05c2 100755 --- a/tests/bsim/bluetooth/host/adv/resume/test_scripts/run_adv_resume_2.sh +++ b/tests/bsim/bluetooth/host/adv/resume/test_scripts/run_adv_resume_2.sh @@ -5,25 +5,12 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -# Read variable definitions output by _env.sh source "${bash_source_dir}/_env.sh" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source simulation_id="${test_name}_2" verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +EXECUTE_TIMEOUT=30 cd ${BSIM_OUT_PATH}/bin @@ -36,7 +23,4 @@ Execute "$test_2_exe" \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s="${simulation_id}" \ -D=2 -sim_length=10e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/att/eatt/tests_scripts/autoconnect.sh b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/autoconnect.sh index 3aa2c68bee68..ac420c136e7c 100755 --- a/tests/bsim/bluetooth/host/att/eatt/tests_scripts/autoconnect.sh +++ b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/autoconnect.sh @@ -2,23 +2,11 @@ # Copyright (c) 2022 Nordic Semiconductor # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + simulation_id="connection" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -31,7 +19,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_prj_autoconnect_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=200e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/att/eatt/tests_scripts/collision.sh b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/collision.sh index eae7e1e99665..75da68b029b0 100755 --- a/tests/bsim/bluetooth/host/att/eatt/tests_scripts/collision.sh +++ b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/collision.sh @@ -2,23 +2,11 @@ # Copyright (c) 2022 Nordic Semiconductor # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + simulation_id="collision" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -31,7 +19,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_prj_collision_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=200e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/att/eatt/tests_scripts/multiple_conn.sh b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/multiple_conn.sh index d5f3482885df..5cc4ec693a00 100755 --- a/tests/bsim/bluetooth/host/att/eatt/tests_scripts/multiple_conn.sh +++ b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/multiple_conn.sh @@ -2,23 +2,11 @@ # Copyright (c) 2022 Nordic Semiconductor # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + simulation_id="multiple_conn" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -31,7 +19,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_prj_multiple_conn_conf Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=200e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/att/eatt/tests_scripts/reconfigure.sh b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/reconfigure.sh index 599329ce2b58..2a9000b24291 100755 --- a/tests/bsim/bluetooth/host/att/eatt/tests_scripts/reconfigure.sh +++ b/tests/bsim/bluetooth/host/att/eatt/tests_scripts/reconfigure.sh @@ -2,23 +2,11 @@ # Copyright (c) 2022 Nordic Semiconductor # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + simulation_id="reconfigure" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -31,7 +19,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_prj_autoconnect_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/att/eatt_notif/test_scripts/eatt_notif.sh b/tests/bsim/bluetooth/host/att/eatt_notif/test_scripts/eatt_notif.sh index 0d3bcb2967d3..3385b6fe6dc7 100755 --- a/tests/bsim/bluetooth/host/att/eatt_notif/test_scripts/eatt_notif.sh +++ b/tests/bsim/bluetooth/host/att/eatt_notif/test_scripts/eatt_notif.sh @@ -4,23 +4,11 @@ # EATT notification reliability test +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + simulation_id="eatt_notif" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -33,7 +21,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_att_eatt_notif_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh index d6498bd21211..c6f204574bd6 100755 --- a/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh @@ -6,10 +6,7 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" # Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") - - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +source "${bash_source_dir}/_env.sh" : "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" diff --git a/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_env.sh b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_env.sh index 30ba589fe88a..8d101eabcdda 100755 --- a/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_env.sh @@ -13,18 +13,3 @@ BOARD="${BOARD:-nrf52_bsim}" simulation_id="$test_name" central_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_att_mtu_update_prj_conf" peripheral_exe="${central_exe}" - -function print_var { - # Print a shell-sourceable variable definition. - local var_name="$1" - local var_repr="${!var_name@Q}" - echo "$var_name=$var_repr" -} - -print_var test_name -print_var bsim_bin -print_var verbosity_level -print_var BOARD -print_var simulation_id -print_var central_exe -print_var peripheral_exe diff --git a/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/run_test.sh b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/run_test.sh index 896508f9ed1d..087aa9385d4e 100755 --- a/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/run_test.sh +++ b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/run_test.sh @@ -5,23 +5,12 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") +source "${bash_source_dir}/_env.sh" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +simulation_id="$test_name" +verbosity_level=2 +EXECUTE_TIMEOUT=30 cd ${BSIM_OUT_PATH}/bin @@ -34,7 +23,4 @@ Execute "$peripheral_exe" \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/compile.sh b/tests/bsim/bluetooth/host/compile.sh index eada545d8b5f..3a06e04165ec 100755 --- a/tests/bsim/bluetooth/host/compile.sh +++ b/tests/bsim/bluetooth/host/compile.sh @@ -7,13 +7,12 @@ #set -x #uncomment this line for debugging set -ue -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" : "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ directory}" WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" -BOARD="${BOARD:-nrf52_bsim}" + BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} diff --git a/tests/bsim/bluetooth/host/gatt/caching/test_scripts/_run_test.sh b/tests/bsim/bluetooth/host/gatt/caching/test_scripts/_run_test.sh index 478febd7484f..932e7c23a768 100755 --- a/tests/bsim/bluetooth/host/gatt/caching/test_scripts/_run_test.sh +++ b/tests/bsim/bluetooth/host/gatt/caching/test_scripts/_run_test.sh @@ -2,24 +2,10 @@ # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & - process_ids="$process_ids $!" -} +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +verbosity_level=2 +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -32,7 +18,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_caching_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/gatt/general/test_scripts/gatt.sh b/tests/bsim/bluetooth/host/gatt/general/test_scripts/gatt.sh index 53be981b1178..eb6f22ace1a1 100755 --- a/tests/bsim/bluetooth/host/gatt/general/test_scripts/gatt.sh +++ b/tests/bsim/bluetooth/host/gatt/general/test_scripts/gatt.sh @@ -5,23 +5,12 @@ # Basic GATT test: A central acting as a GATT client scans for and connects # to a peripheral acting as a GATT server. The GATT client will then attempt # to write and read to and from a few GATT characteristics. -simulation_id="gatt" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +simulation_id="gatt" +verbosity_level=2 +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -34,7 +23,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_general_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/_run_test.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/_run_test.sh index bd79acb3fdd7..4d02d42a00c6 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/_run_test.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/_run_test.sh @@ -1,25 +1,12 @@ #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 +set -eu -verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +verbosity_level=2 +EXECUTE_TIMEOUT=30 cd ${BSIM_OUT_PATH}/bin @@ -32,7 +19,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_notify_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_enhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_enhanced.sh index 68cf94099941..d8516fa35de1 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_enhanced.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_enhanced.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_enhanced_enhanced" \ server_id="gatt_server_enhanced" \ client_id="gatt_client_enhanced" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_mixed.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_mixed.sh index 75a4b9d83c91..4d82408fb912 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_mixed.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_mixed.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_enhanced_mixed" \ server_id="gatt_server_enhanced" \ client_id="gatt_client_mixed" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_none.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_none.sh index e89b16ca20e2..13a4e67e1f0e 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_none.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_none.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_enhanced_none" \ server_id="gatt_server_enhanced" \ client_id="gatt_client_none" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_unenhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_unenhanced.sh index 5cc85731633e..480fbabf467d 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_unenhanced.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_enhanced_unenhanced.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_enhanced_unenhanced" \ server_id="gatt_server_enhanced" \ client_id="gatt_client_unenhanced" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_enhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_enhanced.sh index a4ecf9d429b5..16827e3988bf 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_enhanced.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_enhanced.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_mixed_enhanced" \ server_id="gatt_server_mixed" \ client_id="gatt_client_enhanced" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_mixed.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_mixed.sh index a9f38d8f37ff..ed0a3e4f61e8 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_mixed.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_mixed.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_mixed_mixed" \ server_id="gatt_server_mixed" \ client_id="gatt_client_mixed" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_none.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_none.sh index 80afe822cfd4..944d91f575ee 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_none.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_none.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_mixed_none" \ server_id="gatt_server_mixed" \ client_id="gatt_client_none" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_unenhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_unenhanced.sh index 9ff73b2de4bd..25d0f9839451 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_unenhanced.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_mixed_unenhanced.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_mixed_unenhanced" \ server_id="gatt_server_mixed" \ client_id="gatt_client_unenhanced" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_enhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_enhanced.sh index 74eedd15ddcd..514b8508ea98 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_enhanced.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_enhanced.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_none_enhanced" \ server_id="gatt_server_none" \ client_id="gatt_client_enhanced" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_mixed.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_mixed.sh index 02541c6db749..7c74575a9f94 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_mixed.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_mixed.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_none_mixed" \ server_id="gatt_server_none" \ client_id="gatt_client_mixed" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_none.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_none.sh index 6642f8ed2b56..1d988718f242 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_none.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_none.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_none_none" \ server_id="gatt_server_none" \ client_id="gatt_client_none" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_unenhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_unenhanced.sh index 2f2764186c76..9c8425e376f7 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_unenhanced.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_none_unenhanced.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_none_unenhanced" \ server_id="gatt_server_none" \ client_id="gatt_client_unenhanced" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_enhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_enhanced.sh index ab91b23437dd..4c7c499f166f 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_enhanced.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_enhanced.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_unenhanced_enhanced" \ server_id="gatt_server_unenhanced" \ client_id="gatt_client_enhanced" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_mixed.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_mixed.sh index 57063ac272b0..4a0fdef0243c 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_mixed.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_mixed.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_unenhanced_mixed" \ server_id="gatt_server_unenhanced" \ client_id="gatt_client_mixed" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_none.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_none.sh index df360db4e5e4..5b705823e724 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_none.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_none.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_unenhanced_none" \ server_id="gatt_server_unenhanced" \ client_id="gatt_client_none" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_unenhanced.sh b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_unenhanced.sh index 7b624969d5d6..7da2f2ae39bb 100755 --- a/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_unenhanced.sh +++ b/tests/bsim/bluetooth/host/gatt/notify/test_scripts/gatt_notify_unenhanced_unenhanced.sh @@ -1,4 +1,3 @@ - #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 @@ -7,4 +6,3 @@ simulation_id="gatt_notify_unenhanced_unenhanced" \ server_id="gatt_server_unenhanced" \ client_id="gatt_client_unenhanced" \ $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/_notify-debug.sh b/tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/_notify-debug.sh index 29ac8e41794e..08de518bec4a 100755 --- a/tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/_notify-debug.sh +++ b/tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/_notify-debug.sh @@ -11,10 +11,8 @@ # GDB can be run on the two devices at the same time without issues, just append # `debug` when running the script. - simulation_id="notify_multiple" verbosity_level=2 -process_ids=""; exit_code=0 : "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" diff --git a/tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/notify.sh b/tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/notify.sh index ee243473bea3..b4cf3fd91a31 100755 --- a/tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/notify.sh +++ b/tests/bsim/bluetooth/host/gatt/notify_multiple/test_scripts/notify.sh @@ -1,24 +1,13 @@ #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 +set -eu + +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source simulation_id="notify_multiple" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -31,7 +20,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_notify_multiple_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/gatt/settings/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/gatt/settings/test_scripts/_compile.sh index 1805af4f4256..cd43f722c839 100755 --- a/tests/bsim/bluetooth/host/gatt/settings/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/gatt/settings/test_scripts/_compile.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash # Copyright 2023 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 - set -eu + bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" # Read variable definitions output by _env.sh diff --git a/tests/bsim/bluetooth/host/gatt/settings/test_scripts/_env.sh b/tests/bsim/bluetooth/host/gatt/settings/test_scripts/_env.sh index 348f8ec6d427..22e1f9e65184 100755 --- a/tests/bsim/bluetooth/host/gatt/settings/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/gatt/settings/test_scripts/_env.sh @@ -4,8 +4,6 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - test_name="$(basename "$(realpath "$bash_source_dir/..")")" bsim_bin="${BSIM_OUT_PATH}/bin" BOARD="${BOARD:-nrf52_bsim}" diff --git a/tests/bsim/bluetooth/host/gatt/settings/test_scripts/run_gatt_settings.sh b/tests/bsim/bluetooth/host/gatt/settings/test_scripts/run_gatt_settings.sh index dfa2fa9fe0e3..269ecbc9072d 100755 --- a/tests/bsim/bluetooth/host/gatt/settings/test_scripts/run_gatt_settings.sh +++ b/tests/bsim/bluetooth/host/gatt/settings/test_scripts/run_gatt_settings.sh @@ -1,27 +1,16 @@ #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 - set -eu + bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" source "${bash_source_dir}/_env.sh" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + simulation_id="${test_name}" verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +EXECUTE_TIMEOUT=30 cd ${BSIM_OUT_PATH}/bin @@ -57,7 +46,4 @@ Execute "$test_exe" -v=${verbosity_level} \ Execute "$test_exe" -v=${verbosity_level} \ -s="${simulation_id}" -d=7 -testid=client -RealEncryption=1 -argstest 0 0 "client" -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/gatt/settings/test_scripts/run_gatt_settings_2.sh b/tests/bsim/bluetooth/host/gatt/settings/test_scripts/run_gatt_settings_2.sh index fb6d4e6f45a6..873a0e670b01 100755 --- a/tests/bsim/bluetooth/host/gatt/settings/test_scripts/run_gatt_settings_2.sh +++ b/tests/bsim/bluetooth/host/gatt/settings/test_scripts/run_gatt_settings_2.sh @@ -1,27 +1,16 @@ #!/usr/bin/env bash # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 - set -eu + bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" source "${bash_source_dir}/_env.sh" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + simulation_id="${test_name}_2" verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -57,7 +46,4 @@ Execute "$test_2_exe" -v=${verbosity_level} \ Execute "$test_2_exe" -v=${verbosity_level} \ -s="${simulation_id}" -d=7 -testid=client -RealEncryption=1 -argstest 0 0 "client_2" -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/gatt/write/tests_scripts/gatt_write.sh b/tests/bsim/bluetooth/host/gatt/write/tests_scripts/gatt_write.sh index 30c05ea3a8a5..749e6a6425df 100755 --- a/tests/bsim/bluetooth/host/gatt/write/tests_scripts/gatt_write.sh +++ b/tests/bsim/bluetooth/host/gatt/write/tests_scripts/gatt_write.sh @@ -2,24 +2,12 @@ # Copyright 2018 Oticon A/S # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # Multiple connection between two devices with multiple peripheral identity simulation_id="gatt_write" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 60 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=60 cd ${BSIM_OUT_PATH}/bin @@ -32,7 +20,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_gatt_write_prj_conf\ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/l2cap/general/tests_scripts/l2cap.sh b/tests/bsim/bluetooth/host/l2cap/general/tests_scripts/l2cap.sh index 54cf6c756158..adfae72c4595 100755 --- a/tests/bsim/bluetooth/host/l2cap/general/tests_scripts/l2cap.sh +++ b/tests/bsim/bluetooth/host/l2cap/general/tests_scripts/l2cap.sh @@ -2,24 +2,12 @@ # Copyright (c) 2022 Nordic Semiconductor # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # EATT test simulation_id="l2cap_ecred" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -32,7 +20,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_l2cap_general_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/l2cap/stress/tests_scripts/l2cap.sh b/tests/bsim/bluetooth/host/l2cap/stress/tests_scripts/l2cap.sh index e556fad38e24..1ef8cdc9d15e 100755 --- a/tests/bsim/bluetooth/host/l2cap/stress/tests_scripts/l2cap.sh +++ b/tests/bsim/bluetooth/host/l2cap/stress/tests_scripts/l2cap.sh @@ -2,25 +2,12 @@ # Copyright (c) 2022 Nordic Semiconductor # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # EATT test simulation_id="l2cap_stress" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - # timeout 30 $@ & process_ids="$process_ids $!" - $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -37,7 +24,4 @@ Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=6 -testid=per Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} -D=7 -sim_length=270e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/l2cap.sh b/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/l2cap.sh index 05637864fe6d..6700f12781b8 100755 --- a/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/l2cap.sh +++ b/tests/bsim/bluetooth/host/l2cap/userdata/tests_scripts/l2cap.sh @@ -2,25 +2,11 @@ # Copyright (c) 2022 Nordic Semiconductor # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + simulation_id="l2cap_ecred_userdata" verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -33,7 +19,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_l2cap_userdata_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=30e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable.sh b/tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable.sh index b3e390f82d59..8fb3bfa648e0 100755 --- a/tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable.sh +++ b/tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable.sh @@ -2,24 +2,12 @@ # Copyright (c) 2022 Nordic Semiconductor # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # Disable test: bt_enable and bt_disable are called in a loop. simulation_id="disable_test" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -29,7 +17,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_misc_disable_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=1 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable_with_gatt.sh b/tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable_with_gatt.sh index fef45b2f61d8..5c3d8916c6b0 100755 --- a/tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable_with_gatt.sh +++ b/tests/bsim/bluetooth/host/misc/disable/tests_scripts/disable_with_gatt.sh @@ -2,27 +2,15 @@ # Copyright 2022 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # Disable with GATT test: A central acting as a GATT client scans for and connects # to a peripheral acting as a GATT server. The GATT client will then attempt # to write and read to and from a few GATT characteristics. Both the central and # peripheral then disable bluetooth and the test repeats. simulation_id="disable_with_gatt" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -35,7 +23,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_misc_disable_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=600e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/misc/multiple_id/tests_scripts/multiple.sh b/tests/bsim/bluetooth/host/misc/multiple_id/tests_scripts/multiple.sh index e8c24354d055..c5e1cfdd2422 100755 --- a/tests/bsim/bluetooth/host/misc/multiple_id/tests_scripts/multiple.sh +++ b/tests/bsim/bluetooth/host/misc/multiple_id/tests_scripts/multiple.sh @@ -2,24 +2,12 @@ # Copyright 2018 Oticon A/S # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # Multiple connection between two devices with multiple peripheral identity simulation_id="multiple" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 1800 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=1800 cd ${BSIM_OUT_PATH}/bin @@ -32,7 +20,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_host_misc_multiple_id_prj_conf\ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=4500e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/privacy/central/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/privacy/central/test_scripts/_compile.sh index e7a3d65a2a4b..ccdf03b687fc 100755 --- a/tests/bsim/bluetooth/host/privacy/central/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/privacy/central/test_scripts/_compile.sh @@ -5,15 +5,12 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") - +source "${bash_source_dir}/_env.sh" : "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" : "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" - WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}" BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" diff --git a/tests/bsim/bluetooth/host/privacy/central/test_scripts/_env.sh b/tests/bsim/bluetooth/host/privacy/central/test_scripts/_env.sh index 44e2f07ee4c1..18c60bb7c453 100755 --- a/tests/bsim/bluetooth/host/privacy/central/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/privacy/central/test_scripts/_env.sh @@ -5,8 +5,6 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - test_name="$(basename "$(realpath "$bash_source_dir/..")")" bsim_bin="${BSIM_OUT_PATH}/bin" verbosity_level=2 @@ -14,18 +12,3 @@ BOARD="${BOARD:-nrf52_bsim}" simulation_id="$test_name" central_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_privacy_central_prj_conf" peripheral_exe="${central_exe}" - -function print_var { - # Print a shell-sourceable variable definition. - local var_name="$1" - local var_repr="${!var_name@Q}" - echo "$var_name=$var_repr" -} - -print_var test_name -print_var bsim_bin -print_var verbosity_level -print_var BOARD -print_var simulation_id -print_var central_exe -print_var peripheral_exe diff --git a/tests/bsim/bluetooth/host/privacy/central/test_scripts/run_test.sh b/tests/bsim/bluetooth/host/privacy/central/test_scripts/run_test.sh index e2a80ba51f4f..3ba95eab78cc 100755 --- a/tests/bsim/bluetooth/host/privacy/central/test_scripts/run_test.sh +++ b/tests/bsim/bluetooth/host/privacy/central/test_scripts/run_test.sh @@ -1,27 +1,14 @@ #!/usr/bin/env bash # Copyright 2023 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 - set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") -process_ids="" -exit_code=0 +bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} +source "${bash_source_dir}/_env.sh" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +EXECUTE_TIMEOUT=30 cd ${BSIM_OUT_PATH}/bin @@ -34,8 +21,4 @@ Execute "$peripheral_exe" \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done - -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/privacy/device/test_scripts/run_tests.sh b/tests/bsim/bluetooth/host/privacy/device/test_scripts/run_tests.sh index 6c9ad8a0bbd1..3a16a37c51de 100755 --- a/tests/bsim/bluetooth/host/privacy/device/test_scripts/run_tests.sh +++ b/tests/bsim/bluetooth/host/privacy/device/test_scripts/run_tests.sh @@ -5,23 +5,10 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -# Read variable definitions output by _env.sh source "${bash_source_dir}/_env.sh" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +EXECUTE_TIMEOUT=30 cd ${BSIM_OUT_PATH}/bin @@ -75,11 +62,4 @@ for args in ${TEST_ARGS[@]}; do done done -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" - if [ ${exit_code} -ne 0 ]; then - exit_code=1 - fi -done - -exit $exit_code # the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_compile.sh index e7a3d65a2a4b..2b3b54a10021 100755 --- a/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_compile.sh @@ -6,7 +6,7 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" # Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") +source "${bash_source_dir}/_env.sh" : "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" diff --git a/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_env.sh b/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_env.sh index ac2d2d5888ef..2e3593a3df4b 100755 --- a/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_env.sh @@ -5,8 +5,6 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - test_name="$(basename "$(realpath "$bash_source_dir/..")")" bsim_bin="${BSIM_OUT_PATH}/bin" verbosity_level=2 @@ -14,18 +12,3 @@ BOARD="${BOARD:-nrf52_bsim}" simulation_id="$test_name" central_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_privacy_peripheral_prj_conf" peripheral_exe="${central_exe}" - -function print_var { - # Print a shell-sourceable variable definition. - local var_name="$1" - local var_repr="${!var_name@Q}" - echo "$var_name=$var_repr" -} - -print_var test_name -print_var bsim_bin -print_var verbosity_level -print_var BOARD -print_var simulation_id -print_var central_exe -print_var peripheral_exe diff --git a/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/run_test.sh b/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/run_test.sh index 8a28a5be46a2..30c4f6bee15e 100755 --- a/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/run_test.sh +++ b/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/run_test.sh @@ -5,23 +5,10 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") +source "${bash_source_dir}/_env.sh" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +EXECUTE_TIMEOUT=30 cd ${BSIM_OUT_PATH}/bin @@ -34,8 +21,4 @@ Execute "$peripheral_exe" \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=120e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done - -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh index 33be3b19feb9..2b722ca2a69f 100755 --- a/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh @@ -6,10 +6,8 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" # Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") +source "${bash_source_dir}/_env.sh" - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" : "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" diff --git a/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_env.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_env.sh index f0005e331cc6..102e63a5ef1a 100755 --- a/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_env.sh +++ b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_env.sh @@ -13,18 +13,3 @@ BOARD="${BOARD:-nrf52_bsim}" simulation_id="$test_name" central_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_${test_name}_prj_conf" peripheral_exe="${central_exe}" - -function print_var { - # Print a shell-sourceable variable definition. - local var_name="$1" - local var_repr="${!var_name@Q}" - echo "$var_name=$var_repr" -} - -print_var test_name -print_var bsim_bin -print_var verbosity_level -print_var BOARD -print_var simulation_id -print_var central_exe -print_var peripheral_exe diff --git a/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/run_test.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/run_test.sh index fe5fcfdb1944..3aecac00ee0d 100755 --- a/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/run_test.sh +++ b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/run_test.sh @@ -5,23 +5,10 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") +source "${bash_source_dir}/_env.sh" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +EXECUTE_TIMEOUT=30 cd ${BSIM_OUT_PATH}/bin @@ -34,7 +21,4 @@ Execute "$peripheral_exe" \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh index 33be3b19feb9..2b722ca2a69f 100755 --- a/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh @@ -6,10 +6,8 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" # Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") +source "${bash_source_dir}/_env.sh" - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" : "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" diff --git a/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/run_test.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/run_test.sh index fe5fcfdb1944..6f00e23c70c3 100755 --- a/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/run_test.sh +++ b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/run_test.sh @@ -6,22 +6,10 @@ set -eu bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" # Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") +source "${bash_source_dir}/_env.sh" +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +EXECUTE_TIMEOUT=30 cd ${BSIM_OUT_PATH}/bin @@ -34,7 +22,4 @@ Execute "$peripheral_exe" \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/advx/tests_scripts/basic_advx.sh b/tests/bsim/bluetooth/ll/advx/tests_scripts/basic_advx.sh index 056378febf30..0fc0a93a1120 100755 --- a/tests/bsim/bluetooth/ll/advx/tests_scripts/basic_advx.sh +++ b/tests/bsim/bluetooth/ll/advx/tests_scripts/basic_advx.sh @@ -2,25 +2,13 @@ # Copyright 2018 Oticon A/S # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # Basic connection test: a central connects to a peripheral and expects a # notification, using the split controller (ULL LLL) simulation_id="basic_advx" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=120 cd ${BSIM_OUT_PATH}/bin @@ -33,7 +21,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_advx_prj_conf\ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=60e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/compile.sh b/tests/bsim/bluetooth/ll/compile.sh index 8451406aa628..ff5b86d68c90 100755 --- a/tests/bsim/bluetooth/ll/compile.sh +++ b/tests/bsim/bluetooth/ll/compile.sh @@ -6,14 +6,12 @@ #set -x #uncomment this line for debugging set -ue - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" : "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ directory}" WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" -BOARD="${BOARD:-nrf52_bsim}" + BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} diff --git a/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split.sh b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split.sh index c2bf39cac132..150b2fd2960e 100755 --- a/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split.sh +++ b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split.sh @@ -2,25 +2,13 @@ # Copyright 2018 Oticon A/S # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # Basic connection test: a central connects to a peripheral and expects a # notification simulation_id="basic_conn_encr_split" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 5 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=5 cd ${BSIM_OUT_PATH}/bin @@ -35,7 +23,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_conn_prj_split_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=20e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh index 7062aaeab472..53293f0bb129 100755 --- a/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh +++ b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh @@ -2,25 +2,13 @@ # Copyright 2018 Oticon A/S # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # Basic connection test: a central connects to a peripheral and expects a # notification simulation_id="basic_conn_encr_split_privacy" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 5 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=5 cd ${BSIM_OUT_PATH}/bin @@ -37,7 +25,4 @@ Execute \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=20e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split.sh b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split.sh index 1106e44ca5c2..621ab1d37200 100755 --- a/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split.sh +++ b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split.sh @@ -2,25 +2,13 @@ # Copyright 2018 Oticon A/S # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # Basic connection test: a central connects to a peripheral and expects a # notification, using the split controller (ULL LLL) simulation_id="basic_conn_split" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 5 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=5 cd ${BSIM_OUT_PATH}/bin @@ -35,7 +23,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_conn_prj_split_conf\ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=20e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split_low_lat.sh b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split_low_lat.sh index a3fa4abd1466..4e7f993c4562 100755 --- a/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split_low_lat.sh +++ b/tests/bsim/bluetooth/ll/conn/tests_scripts/basic_conn_split_low_lat.sh @@ -2,25 +2,13 @@ # Copyright 2018 Oticon A/S # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # Basic connection test: a central connects to a peripheral and expects a # notification, using the split controller (ULL LLL) in Low Latency Variant simulation_id="basic_conn_split_low_lat" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 5 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=5 cd ${BSIM_OUT_PATH}/bin @@ -37,7 +25,4 @@ Execute \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=20e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/edtt/tests_scripts/_controller_tests_inner.sh b/tests/bsim/bluetooth/ll/edtt/tests_scripts/_controller_tests_inner.sh index a7b0592b22ae..e75f6ffbe357 100755 --- a/tests/bsim/bluetooth/ll/edtt/tests_scripts/_controller_tests_inner.sh +++ b/tests/bsim/bluetooth/ll/edtt/tests_scripts/_controller_tests_inner.sh @@ -44,9 +44,10 @@ VERBOSITY_LEVEL_DEVS=${VERBOSITY_LEVEL_DEVS:-${VERBOSITY_LEVEL}} VERBOSITY_LEVEL_DEV1=${VERBOSITY_LEVEL_1:-${VERBOSITY_LEVEL_DEVS}} VERBOSITY_LEVEL_DEV2=${VERBOSITY_LEVEL_2:-${VERBOSITY_LEVEL_DEVS}} -PROCESS_IDS=""; EXIT_CODE=0 -function Execute(){ +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + +function _Execute(){ local rr= if [ "rr" = "$1" ]; then local devno=$2 @@ -56,19 +57,12 @@ function Execute(){ rm -rf ${out} rr="rr record -o ${out}" fi - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 300 ${rr} $@ & PROCESS_IDS="$PROCESS_IDS $!" + check_program_exists $1 + run_in_background timeout 300 ${rr} $@ } -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${EDTT_PATH:?EDTT_PATH must be defined}" -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +: "${EDTT_PATH:?EDTT_PATH must be defined}" #Give a default value to PRJ_CONF_x if it does not have one yet: PRJ_CONF="${PRJ_CONF:-prj_dut_conf}" @@ -94,24 +88,21 @@ fi cd ${EDTT_PATH} -Execute ./src/edttool.py -s=${SIMULATION_ID} -d=2 --transport bsim \ +_Execute ./src/edttool.py -s=${SIMULATION_ID} -d=2 --transport bsim \ -T $TEST_MODULE -C $TEST_FILE -v=${VERBOSITY_LEVEL_EDTT} -S -l --low-level-device-nbr=3 \ -D=2 -devs 0 1 -RxWait=2.5e3 cd ${BSIM_OUT_PATH}/bin -Execute \ +_Execute \ ${RR_ARGS_1} ./bs_${BOARD}_tests_bsim_bluetooth_ll_edtt_hci_test_app_${PRJ_CONF_1}\ -s=${SIMULATION_ID} -d=0 -v=${VERBOSITY_LEVEL_DEV1} -RealEncryption=1 -Execute \ +_Execute \ ${RR_ARGS_2} ./bs_${BOARD}_tests_bsim_bluetooth_ll_edtt_hci_test_app_${PRJ_CONF_2}\ -s=${SIMULATION_ID} -d=1 -v=${VERBOSITY_LEVEL_DEV2} -RealEncryption=1 -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL_PHY} -s=${SIMULATION_ID} \ +_Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL_PHY} -s=${SIMULATION_ID} \ -D=4 -sim_length=3600e6 -dump_imm $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/edtt/tests_scripts/gatt.llcp.sh b/tests/bsim/bluetooth/ll/edtt/tests_scripts/gatt.llcp.sh index f30f866923e4..d16b743435d7 100755 --- a/tests/bsim/bluetooth/ll/edtt/tests_scripts/gatt.llcp.sh +++ b/tests/bsim/bluetooth/ll/edtt/tests_scripts/gatt.llcp.sh @@ -2,27 +2,17 @@ # Copyright 2019 Oticon A/S # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # GATT regression tests based on the EDTTool SIMULATION_ID="edtt_gatt_llcp" VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" +EXECUTE_TIMEOUT=300 -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 300 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} +CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" : "${EDTT_PATH:?EDTT_PATH must be defined}" -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - cd ${EDTT_PATH} Execute ./src/edttool.py -s=${SIMULATION_ID} -d=0 --transport bsim \ @@ -42,7 +32,4 @@ Execute \ Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ -D=3 -sim_length=3600e6 $@ -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done -exit $EXIT_CODE #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso.sh b/tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso.sh index bbec1b2c7124..2f9be4c3d8f6 100755 --- a/tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso.sh +++ b/tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso.sh @@ -2,25 +2,13 @@ # Copyright 2020 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # Basic ISO broadcast test: a broadcaster transmits a BIS and a receiver listens # to the BIS. simulation_id="broadcast_iso" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=30 cd ${BSIM_OUT_PATH}/bin @@ -33,7 +21,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_iso_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=30e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh b/tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh index 62b737314672..1e1fde1247dc 100755 --- a/tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh +++ b/tests/bsim/bluetooth/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh @@ -2,25 +2,13 @@ # Copyright 2020 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + # Basic ISO broadcast test: a broadcaster transmits a BIS and a receiver listens # to the BIS, and recevied SDUs are emitted via vendor data path implementation. simulation_id="broadcast_iso_vs_dp" verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" +EXECUTE_TIMEOUT=30 cd ${BSIM_OUT_PATH}/bin @@ -33,7 +21,4 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_ll_iso_prj_conf \ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ -D=2 -sim_length=30e6 $@ -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 +wait_for_background_jobs diff --git a/tests/bsim/bluetooth/mesh/_mesh_test.sh b/tests/bsim/bluetooth/mesh/_mesh_test.sh index 0827585f3c98..2b2d0b4c52d4 100755 --- a/tests/bsim/bluetooth/mesh/_mesh_test.sh +++ b/tests/bsim/bluetooth/mesh/_mesh_test.sh @@ -1,27 +1,9 @@ # Copyright 2021 Nordic Semiconductor # SPDX-License-Identifier: Apache-2.0 -process_ids=(); exit_code=0 +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source -trap ctrl_c INT - -function ctrl_c() { - echo "Aborted by CTRL-C" - conf=${conf:-prj_conf} - - for process_id in ${process_ids[@]}; do - kill -15 $process_id - done -} - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 300 $@ & process_ids+=( $! ) -} +EXECUTE_TIMEOUT=300 function Skip(){ for i in "${SKIP[@]}" ; do @@ -86,16 +68,5 @@ function RunTest(){ Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=$s_id -D=$count -argschannel -at=35 - for process_id in ${process_ids[@]}; do - wait $process_id || let "exit_code=$?" - done - - if [ "$exit_code" != "0" ] ; then - exit $exit_code #the last exit code != 0 - fi + wait_for_background_jobs } - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" diff --git a/tests/bsim/bluetooth/mesh/compile.sh b/tests/bsim/bluetooth/mesh/compile.sh index d0c3f91f4bb5..c00048b4195b 100755 --- a/tests/bsim/bluetooth/mesh/compile.sh +++ b/tests/bsim/bluetooth/mesh/compile.sh @@ -6,14 +6,11 @@ #set -x #uncomment this line for debugging set -ue - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" : "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ directory}" WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" -BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} diff --git a/tests/bsim/compile.sh b/tests/bsim/compile.sh index 39e07d1313df..beec89f937c9 100755 --- a/tests/bsim/compile.sh +++ b/tests/bsim/compile.sh @@ -6,14 +6,12 @@ #set -x #uncomment this line for debugging set -ue - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" : "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ directory}" WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" -BOARD="${BOARD:-nrf52_bsim}" + BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" mkdir -p ${WORK_DIR} diff --git a/tests/bsim/sh_common.source b/tests/bsim/sh_common.source index 25c59d3f3c5b..000ea36cd0c0 100644 --- a/tests/bsim/sh_common.source +++ b/tests/bsim/sh_common.source @@ -3,6 +3,12 @@ _process_ids=""; +#All user scripts require these variable, let's check for them here already +: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" + +#Give a default value to BOARD if it does not have one yet: +BOARD="${BOARD:-nrf52_bsim}" + function run_in_background(){ $@ & _process_ids="$_process_ids $!" } @@ -12,5 +18,31 @@ function wait_for_background_jobs(){ for process_id in $_process_ids; do wait $process_id || let "exit_code=$?" done - exit $exit_code #the last exit code != 0 + [ $exit_code -eq 0 ] || exit $exit_code +} + +trap ctrl_c INT + +function ctrl_c() { + echo "Aborted by CTRL-C" + + for process_id in $_process_ids; do + kill -15 $process_id + done +} + +function check_program_exists() { + if [ ! -f $1 ]; then + echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ + compile it?)\e[39m" + exit 1 + fi } + +function Execute() { + EXECUTE_TIMEOUT="${EXECUTE_TIMEOUT:-30}" + + check_program_exists $1 + run_in_background timeout ${EXECUTE_TIMEOUT} $@ +} + From 6b4b0d4ca6c7643dbe5dcc310fa2938571422c52 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Mon, 20 Mar 2023 15:20:50 +0100 Subject: [PATCH 0507/1906] tests/bsim: Correct default build path The default build path was the old one in some scripts and READMEs. Correct it. Signed-off-by: Alberto Escolar Piedras --- tests/bsim/README.txt | 4 ++-- .../bluetooth/host/att/mtu_update/test_scripts/_compile.sh | 2 +- .../bluetooth/host/privacy/central/test_scripts/_compile.sh | 2 +- .../host/privacy/peripheral/test_scripts/_compile.sh | 2 +- .../security/bond_overwrite_allowed/test_scripts/_compile.sh | 2 +- .../security/bond_overwrite_denied/test_scripts/_compile.sh | 2 +- tests/bsim/bluetooth/ll/edtt/README.txt | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/bsim/README.txt b/tests/bsim/README.txt index 3a177170ae9e..4a5e6d473662 100644 --- a/tests/bsim/README.txt +++ b/tests/bsim/README.txt @@ -7,9 +7,9 @@ the needed images and execute these tests in batch. You can also run them manually if desired, but be sure to call them setting the variables they expect. For example, from Zephyr's root folder, you can run: -WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/compile.sh +WORK_DIR=${ZEPHYR_BASE}/bsim_out tests/bsim/compile.sh RESULTS_FILE=${ZEPHYR_BASE}/myresults.xml SEARCH_PATH=tests/bsim tests/bsim/run_parallel.sh Or to run only a specific subset, e.g. host advertising tests: -WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/bluetooth/host/compile.sh +WORK_DIR=${ZEPHYR_BASE}/bsim_out tests/bsim/bluetooth/host/compile.sh RESULTS_FILE=${ZEPHYR_BASE}/myresults.xml SEARCH_PATH=tests/bsim/bluetooth/host/adv tests/bsim/run_parallel.sh diff --git a/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh index c6f204574bd6..2eedd8970c61 100755 --- a/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/att/mtu_update/test_scripts/_compile.sh @@ -10,7 +10,7 @@ source "${bash_source_dir}/_env.sh" : "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}" +WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" INCR_BUILD=1 diff --git a/tests/bsim/bluetooth/host/privacy/central/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/privacy/central/test_scripts/_compile.sh index ccdf03b687fc..f18037667942 100755 --- a/tests/bsim/bluetooth/host/privacy/central/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/privacy/central/test_scripts/_compile.sh @@ -11,7 +11,7 @@ source "${bash_source_dir}/_env.sh" : "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}" +WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" INCR_BUILD=1 diff --git a/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_compile.sh index 2b3b54a10021..f5f96ba5bd1d 100755 --- a/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/privacy/peripheral/test_scripts/_compile.sh @@ -14,7 +14,7 @@ source "${bash_source_dir}/_env.sh" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}" +WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" INCR_BUILD=1 diff --git a/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh index 2b722ca2a69f..878c256b8912 100755 --- a/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/security/bond_overwrite_allowed/test_scripts/_compile.sh @@ -11,7 +11,7 @@ source "${bash_source_dir}/_env.sh" : "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}" +WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" INCR_BUILD=1 diff --git a/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh index 2b722ca2a69f..878c256b8912 100755 --- a/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh +++ b/tests/bsim/bluetooth/host/security/bond_overwrite_denied/test_scripts/_compile.sh @@ -11,7 +11,7 @@ source "${bash_source_dir}/_env.sh" : "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" : "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}" +WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" INCR_BUILD=1 diff --git a/tests/bsim/bluetooth/ll/edtt/README.txt b/tests/bsim/bluetooth/ll/edtt/README.txt index 249f224b3473..8978a328ebf1 100644 --- a/tests/bsim/bluetooth/ll/edtt/README.txt +++ b/tests/bsim/bluetooth/ll/edtt/README.txt @@ -53,7 +53,7 @@ In short the whole process being: ``` cd ${ZEPHYR_BASE} && source zephyr-env.sh #Compile all apps: -WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/bluetooth/ll/compile.sh +WORK_DIR=${ZEPHYR_BASE}/bsim_out tests/bsim/bluetooth/ll/compile.sh #run all tests RESULTS_FILE=${ZEPHYR_BASE}/banana.xml SEARCH_PATH=tests/bsim/bluetooth/ll/edtt/ tests/bsim/run_parallel.sh From b71f9f27029764ac89960e33febd76df493aca8f Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 12 Jul 2022 15:43:08 +0200 Subject: [PATCH 0508/1906] Bluetooth: Audio: Implement CAP unicast audio start Implement the CAP unicast start procedure, which will put one or more CAP streams from the idle state to the streaming state, across or more ACL connections. Signed-off-by: Emil Gydesen --- include/zephyr/bluetooth/audio/cap.h | 51 ++- subsys/bluetooth/audio/Kconfig.cap | 5 + subsys/bluetooth/audio/cap_initiator.c | 570 ++++++++++++++++++++++++- subsys/bluetooth/audio/cap_internal.h | 7 + subsys/bluetooth/audio/cap_stream.c | 35 +- 5 files changed, 640 insertions(+), 28 deletions(-) diff --git a/include/zephyr/bluetooth/audio/cap.h b/include/zephyr/bluetooth/audio/cap.h index 4887f6ac32c1..9afa97a69902 100644 --- a/include/zephyr/bluetooth/audio/cap.h +++ b/include/zephyr/bluetooth/audio/cap.h @@ -139,7 +139,7 @@ union bt_cap_set_member { struct bt_conn *member; /** CSIP Coordinated Set struct used if type is BT_CAP_SET_TYPE_CSIP. */ - struct bt_csip_set_coordinator_set_member *csip; + struct bt_csip_set_coordinator_csis_inst *csip; }; struct bt_cap_stream { @@ -156,22 +156,15 @@ struct bt_cap_stream { */ void bt_cap_stream_ops_register(struct bt_cap_stream *stream, struct bt_bap_stream_ops *ops); -struct bt_cap_unicast_audio_start_param { - /** The type of the set. */ - enum bt_cap_set_type type; +struct bt_cap_unicast_audio_start_stream_param { + /** Coordinated or ad-hoc set member. */ + union bt_cap_set_member member; - /** The number of set members in @p members and number of streams in @p streams. */ - size_t count; + /** @brief Stream for the @p member */ + struct bt_cap_stream *stream; - /** Coordinated or ad-hoc set members. */ - union bt_cap_set_member **members; - - /** @brief Streams for the @p members - * - * stream[i] will be associated with members[i] if not already - * initialized, else the stream will be verified against the member. - */ - struct bt_cap_stream **streams; + /** Endpoint reference for the @p stream */ + struct bt_bap_ep *ep; /** * @brief Codec configuration. @@ -180,10 +173,30 @@ struct bt_cap_unicast_audio_start_param { * (@ref BT_AUDIO_METADATA_TYPE_CCID_LIST) as well as a non-0 * stream context (@ref BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT) bitfield. */ - const struct bt_codec *codec; + struct bt_codec *codec; /** Quality of Service configuration. */ - const struct bt_codec_qos *qos; + struct bt_codec_qos *qos; +}; + +struct bt_cap_unicast_audio_start_param { + /** The type of the set. */ + enum bt_cap_set_type type; + + /** The number of parameters in @p stream_params */ + size_t count; + + /** Array of stream parameters */ + struct bt_cap_unicast_audio_start_stream_param *stream_params; + + /** @brief Unicast Group packing mode. + * + * @ref BT_ISO_PACKING_SEQUENTIAL or @ref BT_ISO_PACKING_INTERLEAVED. + * + * @note This is a recommendation to the controller, which the + * controller may ignore. + */ + uint8_t packing; }; /** @@ -207,12 +220,12 @@ int bt_cap_initiator_register_cb(const struct bt_cap_initiator_cb *cb); * to be enabled. * * @param[in] param Parameters to start the audio streams. - * @param[out] unicast_group Pointer to the unicast group created. + * @param[out] unicast_group Pointer to the unicast group. * * @return 0 on success or negative error value on failure. */ int bt_cap_initiator_unicast_audio_start(const struct bt_cap_unicast_audio_start_param *param, - struct bt_bap_unicast_group **unicast_group); + struct bt_bap_unicast_group *unicast_group); /** * @brief Update unicast audio streams for a unicast group. diff --git a/subsys/bluetooth/audio/Kconfig.cap b/subsys/bluetooth/audio/Kconfig.cap index e821d38dd3a7..42f80df46d7b 100644 --- a/subsys/bluetooth/audio/Kconfig.cap +++ b/subsys/bluetooth/audio/Kconfig.cap @@ -46,6 +46,11 @@ config BT_CAP_INITIATOR help Enabling this will enable the CAP Initiator role. +module = BT_CAP_INITIATOR +legacy-debug-sym = BT_DEBUG_CAP_INITIATOR +module-str = "Common Audio Profile Initiator" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + config BT_DEBUG_CAP_INITIATOR bool "Common Audio Profile Initiator debug" select DEPRECATED diff --git a/subsys/bluetooth/audio/cap_initiator.c b/subsys/bluetooth/audio/cap_initiator.c index 1a4d68b1c1e9..d92a1dd090bb 100644 --- a/subsys/bluetooth/audio/cap_initiator.c +++ b/subsys/bluetooth/audio/cap_initiator.c @@ -6,8 +6,9 @@ #include #include -#include +#include #include +#include #include "cap_internal.h" #include "csip_internal.h" #include "bap_endpoint.h" @@ -40,8 +41,6 @@ int bt_cap_initiator_register_cb(const struct bt_cap_initiator_cb *cb) return 0; } -#if defined(CONFIG_BT_BAP_BROADCAST_SOURCE) - static bool cap_initiator_valid_metadata(const struct bt_codec_data meta[], size_t meta_count) { @@ -69,6 +68,8 @@ static bool cap_initiator_valid_metadata(const struct bt_codec_data meta[], return stream_context_found; } +#if defined(CONFIG_BT_BAP_BROADCAST_SOURCE) + static bool cap_initiator_broadcast_audio_start_valid_param( const struct bt_cap_initiator_broadcast_create_param *param) { @@ -190,15 +191,83 @@ int bt_cap_initiator_broadcast_get_base(struct bt_cap_broadcast_source *source, #endif /* CONFIG_BT_BAP_BROADCAST_SOURCE */ #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) -static const struct bt_uuid *cas_uuid = BT_UUID_CAS; +enum { + CAP_UNICAST_PROC_STATE_ACTIVE, + CAP_UNICAST_PROC_STATE_ABORTED, + + CAP_UNICAST_PROC_STATE_FLAG_NUM, +} cap_unicast_proc_state; + +struct cap_unicast_proc { + ATOMIC_DEFINE(flags, CAP_UNICAST_PROC_STATE_FLAG_NUM); + size_t stream_cnt; + size_t stream_initiated_cnt; + size_t stream_done_cnt; + int err; + struct bt_conn *failed_conn; + struct bt_cap_stream *streams[CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT]; +}; struct cap_unicast_client { + struct bt_conn *conn; struct bt_gatt_discover_params param; uint16_t csis_start_handle; const struct bt_csip_set_coordinator_csis_inst *csis_inst; + bool cas_found; }; static struct cap_unicast_client bt_cap_unicast_clients[CONFIG_BT_MAX_CONN]; +static const struct bt_uuid *cas_uuid = BT_UUID_CAS; +static struct cap_unicast_proc active_proc; + +static void cap_initiator_disconnected(struct bt_conn *conn, uint8_t reason) +{ + struct cap_unicast_client *client; + + client = &bt_cap_unicast_clients[bt_conn_index(conn)]; + + if (client->conn != NULL) { + bt_conn_unref(client->conn); + } + (void)memset(client, 0, sizeof(*client)); + + /* Check if the disconnecting connection is part of the current active + * procedure, and abort it if it is. + */ + if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ACTIVE) && + !atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED)) { + for (size_t i = 0U; i < active_proc.stream_initiated_cnt; i++) { + if (active_proc.streams[i]->bap_stream.conn == conn) { + active_proc.err = -ENOTCONN; + active_proc.failed_conn = conn; + atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED); + break; + } + } + } +} + +BT_CONN_CB_DEFINE(conn_callbacks) = { + .disconnected = cap_initiator_disconnected, +}; + +static struct cap_unicast_client *lookup_unicast_client_by_csis( + const struct bt_csip_set_coordinator_csis_inst *csis_inst) +{ + if (csis_inst == NULL) { + return NULL; + } + + for (size_t i = 0U; i < ARRAY_SIZE(bt_cap_unicast_clients); i++) { + struct cap_unicast_client *client = &bt_cap_unicast_clients[i]; + + if (client->csis_inst == csis_inst) { + return client; + } + } + + return NULL; +} static void csis_client_discover_cb(struct bt_conn *conn, const struct bt_csip_set_coordinator_set_member *member, @@ -309,8 +378,14 @@ static uint8_t cap_unicast_discover_cas_cb(struct bt_conn *conn, } } else { const struct bt_gatt_service_val *prim_service = attr->user_data; + struct cap_unicast_client *client = CONTAINER_OF(params, + struct cap_unicast_client, + param); int err; + client->cas_found = true; + client->conn = bt_conn_ref(conn); + if (attr->handle == prim_service->end_handle) { LOG_DBG("Found CAS without CSIS"); cap_cb->unicast_discovery_complete(conn, 0, NULL); @@ -372,14 +447,495 @@ int bt_cap_initiator_unicast_discover(struct bt_conn *conn) return err; } +static bool cap_stream_in_active_proc(const struct bt_cap_stream *cap_stream) +{ + if (!atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ACTIVE)) { + return false; + } + + for (size_t i = 0U; i < active_proc.stream_cnt; i++) { + if (active_proc.streams[i] == cap_stream) { + return true; + } + } + + return false; +} + +static bool valid_unicast_audio_start_param(const struct bt_cap_unicast_audio_start_param *param, + struct bt_bap_unicast_group *unicast_group) +{ + CHECKIF(param == NULL) { + LOG_DBG("param is NULL"); + return false; + } + + CHECKIF(param->count == 0) { + LOG_DBG("Invalid param->count: %u", param->count); + return false; + } + + CHECKIF(param->stream_params == NULL) { + LOG_DBG("param->stream_params is NULL"); + return false; + } + + CHECKIF(param->count > CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT) { + LOG_DBG("param->count (%zu) is larger than " + "CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT (%d)", + param->count, + CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT); + return false; + } + + for (size_t i = 0U; i < param->count; i++) { + const struct bt_cap_unicast_audio_start_stream_param *stream_param = + ¶m->stream_params[i]; + const union bt_cap_set_member *member = &stream_param->member; + const struct bt_cap_stream *cap_stream = stream_param->stream; + const struct bt_codec *codec = stream_param->codec; + const struct bt_bap_stream *bap_stream; + + CHECKIF(stream_param->codec == NULL) { + LOG_DBG("param->stream_params[%zu].codec is NULL", i); + return false; + } + + CHECKIF(!cap_initiator_valid_metadata(codec->meta, + codec->meta_count)) { + LOG_DBG("param->stream_params[%zu].codec is invalid", + i); + return false; + } + + CHECKIF(stream_param->ep == NULL) { + LOG_DBG("param->stream_params[%zu].ep is NULL", i); + return false; + } + + CHECKIF(stream_param->qos == NULL) { + LOG_DBG("param->stream_params[%zu].qos is NULL", i); + return false; + } + + CHECKIF(member == NULL) { + LOG_DBG("param->stream_params[%zu].member is NULL", i); + return false; + } + + if (param->type == BT_CAP_SET_TYPE_AD_HOC) { + struct cap_unicast_client *client; + + CHECKIF(member->member == NULL) { + LOG_DBG("param->members[%zu] is NULL", i); + return false; + } + + client = &bt_cap_unicast_clients[bt_conn_index(member->member)]; + + if (!client->cas_found) { + LOG_DBG("CAS was not found for param->members[%zu]", i); + return false; + } + } + + if (param->type == BT_CAP_SET_TYPE_CSIP) { + struct cap_unicast_client *client; + + CHECKIF(member->csip == NULL) { + LOG_DBG("param->csip.set[%zu] is NULL", i); + return false; + } + + client = lookup_unicast_client_by_csis(member->csip); + if (client == NULL) { + LOG_DBG("CSIS was not found for param->members[%zu]", i); + return false; + } + } + + CHECKIF(cap_stream == NULL) { + LOG_DBG("param->streams[%zu] is NULL", i); + return false; + } + + bap_stream = &cap_stream->bap_stream; + + CHECKIF(bap_stream->ep != NULL) { + LOG_DBG("param->streams[%zu] is already started", i); + return false; + } + + CHECKIF(bap_stream->group == NULL) { + LOG_DBG("param->streams[%zu] is not in a unicast group", i); + return false; + } + + CHECKIF(bap_stream->group != unicast_group) { + LOG_DBG("param->streams[%zu] is not in this group %p", i, unicast_group); + return false; + } + + for (size_t j = 0U; j < i; j++) { + if (param->stream_params[j].stream == cap_stream) { + LOG_DBG("param->stream_params[%zu] (%p) is " + "duplicated by " + "param->stream_params[%zu] (%p)", + j, param->stream_params[j].stream, + i, cap_stream); + return false; + } + } + } + + return true; +} + +static int cap_initiator_unicast_audio_configure( + const struct bt_cap_unicast_audio_start_param *param) +{ + /** TODO: If this is a CSIP set, then the order of the procedures may + * not match the order in the parameters, and the CSIP ordered access + * procedure should be used. + */ + + /* Store the information about the active procedure so that we can + * continue the procedure after each step + */ + atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ACTIVE); + active_proc.stream_cnt = param->count; + + for (size_t i = 0U; i < param->count; i++) { + struct bt_cap_unicast_audio_start_stream_param *stream_param = + ¶m->stream_params[i]; + union bt_cap_set_member *member = &stream_param->member; + struct bt_cap_stream *cap_stream = stream_param->stream; + struct bt_bap_stream *bap_stream = &cap_stream->bap_stream; + struct bt_bap_ep *ep = stream_param->ep; + struct bt_codec *codec = stream_param->codec; + struct bt_conn *conn; + int err; + + if (param->type == BT_CAP_SET_TYPE_AD_HOC) { + conn = member->member; + } else { + struct cap_unicast_client *client; + + /* We have verified that `client` wont be NULL in + * `valid_unicast_audio_start_param`. + */ + client = lookup_unicast_client_by_csis(member->csip); + __ASSERT(client != NULL, "client is NULL"); + conn = client->conn; + } + + /* Ensure that ops are registered before any procedures are started */ + bt_cap_stream_ops_register_bap(cap_stream); + + active_proc.streams[i] = cap_stream; + + err = bt_bap_stream_config(conn, bap_stream, ep, codec); + if (err != 0) { + LOG_DBG("bt_bap_stream_config failed for param->stream_params[%zu]: %d", + i, err); + + if (i > 0U) { + atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED); + } else { + (void)memset(&active_proc, 0, sizeof(active_proc)); + } + + return err; + } + + active_proc.stream_initiated_cnt++; + } + + return 0; +} + +static void cap_initiator_unicast_audio_start_complete(void) +{ + struct bt_bap_unicast_group *unicast_group; + struct bt_conn *failed_conn; + int err; + + /* All streams in the procedure share the same unicast group, so we just + * use the reference from the first stream + */ + unicast_group = (struct bt_bap_unicast_group *)active_proc.streams[0]->bap_stream.group; + failed_conn = active_proc.failed_conn; + err = active_proc.err; + + (void)memset(&active_proc, 0, sizeof(active_proc)); + if (cap_cb != NULL && cap_cb->unicast_start_complete != NULL) { + cap_cb->unicast_start_complete(unicast_group, err, failed_conn); + } +} + int bt_cap_initiator_unicast_audio_start(const struct bt_cap_unicast_audio_start_param *param, - struct bt_bap_unicast_group **unicast_group) + struct bt_bap_unicast_group *unicast_group) { - return -ENOSYS; + if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ACTIVE)) { + LOG_DBG("A CAP procedure is already in progress"); + + return -EBUSY; + } + + CHECKIF(unicast_group == NULL) { + LOG_DBG("unicast_group is NULL"); + return -EINVAL; + } + + if (!valid_unicast_audio_start_param(param, unicast_group)) { + return -EINVAL; + } + + return cap_initiator_unicast_audio_configure(param); +} + +void bt_cap_initiator_codec_configured(struct bt_cap_stream *cap_stream) +{ + struct bt_conn *conns[MIN(CONFIG_BT_MAX_CONN, + CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT)]; + struct bt_bap_unicast_group *unicast_group; + + if (!cap_stream_in_active_proc(cap_stream)) { + /* State change happened outside of a procedure; ignore */ + return; + } + + active_proc.stream_done_cnt++; + + LOG_DBG("Stream %p configured (%zu/%zu streams done)", cap_stream, + active_proc.stream_done_cnt, active_proc.stream_cnt); + + if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + /* Not yet finished, wait for all */ + return; + } else if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED)) { + if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { + cap_initiator_unicast_audio_start_complete(); + } + + return; + } + + /* The QoS Configure procedure works on a set of connections and a + * unicast group, so we generate a list of unique connection pointers + * for the procedure + */ + (void)memset(conns, 0, sizeof(conns)); + for (size_t i = 0U; i < active_proc.stream_cnt; i++) { + struct bt_conn *stream_conn = active_proc.streams[i]->bap_stream.conn; + struct bt_conn **free_conn = NULL; + bool already_added = false; + + for (size_t j = 0U; j < ARRAY_SIZE(conns); j++) { + if (stream_conn == conns[j]) { + already_added = true; + break; + } else if (conns[j] == NULL && free_conn == NULL) { + free_conn = &conns[j]; + } + } + + if (already_added) { + continue; + } + + __ASSERT(free_conn, "No free conns"); + *free_conn = stream_conn; + } + + /* All streams in the procedure share the same unicast group, so we just + * use the reference from the first stream + */ + unicast_group = (struct bt_bap_unicast_group *)active_proc.streams[0]->bap_stream.group; + active_proc.stream_done_cnt = 0U; + active_proc.stream_initiated_cnt = 0U; + for (size_t i = 0U; i < ARRAY_SIZE(conns); i++) { + int err; + + /* When conns[i] is NULL, we have QoS Configured all unique connections */ + if (conns[i] == NULL) { + break; + } + + err = bt_bap_stream_qos(conns[i], unicast_group); + if (err != 0) { + LOG_DBG("Failed to set stream QoS for conn %p and group %p: %d", + (void *)conns[i], unicast_group, err); + + /* End or mark procedure as aborted. + * If we have sent any requests over air, we will abort + * once all sent requests has completed + */ + active_proc.err = err; + active_proc.failed_conn = conns[i]; + if (i == 0U) { + cap_initiator_unicast_audio_start_complete(); + } else { + atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED); + } + + return; + } + + active_proc.stream_initiated_cnt++; + } } +void bt_cap_initiator_qos_configured(struct bt_cap_stream *cap_stream) +{ + if (!cap_stream_in_active_proc(cap_stream)) { + /* State change happened outside of a procedure; ignore */ + return; + } + + active_proc.stream_done_cnt++; + + LOG_DBG("Stream %p QoS configured (%zu/%zu streams done)", cap_stream, + active_proc.stream_done_cnt, active_proc.stream_cnt); + + if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + /* Not yet finished, wait for all */ + return; + } else if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED)) { + if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { + cap_initiator_unicast_audio_start_complete(); + } + + return; + } + + active_proc.stream_done_cnt = 0U; + active_proc.stream_initiated_cnt = 0U; + + for (size_t i = 0U; i < active_proc.stream_cnt; i++) { + struct bt_cap_stream *cap_stream = active_proc.streams[i]; + struct bt_bap_stream *bap_stream = &cap_stream->bap_stream; + int err; + + /* TODO: Add metadata */ + err = bt_bap_stream_enable(bap_stream, + bap_stream->codec->meta, + bap_stream->codec->meta_count); + if (err != 0) { + LOG_DBG("Failed to enable stream %p: %d", + cap_stream, err); + + /* End or mark procedure as aborted. + * If we have sent any requests over air, we will abort + * once all sent requests has completed + */ + active_proc.err = err; + active_proc.failed_conn = bap_stream->conn; + if (i == 0U) { + cap_initiator_unicast_audio_start_complete(); + } else { + atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED); + } + + return; + } + } +} + +void bt_cap_initiator_enabled(struct bt_cap_stream *cap_stream) +{ + struct bt_bap_stream *bap_stream; + int err; + + if (!cap_stream_in_active_proc(cap_stream)) { + /* State change happened outside of a procedure; ignore */ + return; + } + + active_proc.stream_done_cnt++; + + LOG_DBG("Stream %p enabled (%zu/%zu streams done)", cap_stream, active_proc.stream_done_cnt, + active_proc.stream_cnt); + + if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + /* Not yet finished, wait for all */ + return; + } else if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED)) { + if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { + cap_initiator_unicast_audio_start_complete(); + } + + return; + } + + active_proc.stream_done_cnt = 0U; + active_proc.stream_initiated_cnt = 0U; + + bap_stream = &active_proc.streams[0]->bap_stream; + + /* Since bt_bap_stream_start connects the ISO, we can, at this point, + * only do this one by one due to a restriction in the ISO layer + * (maximum 1 outstanding ISO connection request at any one time). + */ + err = bt_bap_stream_start(bap_stream); + if (err != 0) { + LOG_DBG("Failed to start stream %p: %d", active_proc.streams[0], err); + + /* End and mark procedure as aborted. + * If we have sent any requests over air, we will abort + * once all sent requests has completed + */ + active_proc.err = err; + active_proc.failed_conn = bap_stream->conn; + cap_initiator_unicast_audio_start_complete(); + + return; + } +} + +void bt_cap_initiator_started(struct bt_cap_stream *cap_stream) +{ + if (!cap_stream_in_active_proc(cap_stream)) { + /* State change happened outside of a procedure; ignore */ + return; + } + + active_proc.stream_done_cnt++; + + LOG_DBG("Stream %p started (%zu/%zu streams done)", cap_stream, active_proc.stream_done_cnt, + active_proc.stream_cnt); + + /* Since bt_bap_stream_start connects the ISO, we can, at this point, + * only do this one by one due to a restriction in the ISO layer + * (maximum 1 outstanding ISO connection request at any one time). + */ + if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + struct bt_cap_stream *next = active_proc.streams[active_proc.stream_done_cnt]; + struct bt_bap_stream *bap_stream = &next->bap_stream; + int err; + + /* Not yet finished, start next */ + err = bt_bap_stream_start(bap_stream); + if (err != 0) { + LOG_DBG("Failed to start stream %p: %d", next, err); + + /* End and mark procedure as aborted. + * If we have sent any requests over air, we will abort + * once all sent requests has completed + */ + active_proc.err = err; + active_proc.failed_conn = bap_stream->conn; + cap_initiator_unicast_audio_start_complete(); + } + } else { + cap_initiator_unicast_audio_start_complete(); + } +} + + int bt_cap_initiator_unicast_audio_update(struct bt_bap_unicast_group *unicast_group, - uint8_t meta_count, const struct bt_codec_data *meta) + uint8_t meta_count, + const struct bt_codec_data *meta) { return -ENOSYS; } diff --git a/subsys/bluetooth/audio/cap_internal.h b/subsys/bluetooth/audio/cap_internal.h index b735af8e1bff..c3a5f8c4783b 100644 --- a/subsys/bluetooth/audio/cap_internal.h +++ b/subsys/bluetooth/audio/cap_internal.h @@ -8,5 +8,12 @@ #include #include +#include bool bt_cap_acceptor_ccid_exist(const struct bt_conn *conn, uint8_t ccid); + +void bt_cap_initiator_codec_configured(struct bt_cap_stream *cap_stream); +void bt_cap_initiator_qos_configured(struct bt_cap_stream *cap_stream); +void bt_cap_initiator_enabled(struct bt_cap_stream *cap_stream); +void bt_cap_initiator_started(struct bt_cap_stream *cap_stream); +void bt_cap_stream_ops_register_bap(struct bt_cap_stream *cap_stream); diff --git a/subsys/bluetooth/audio/cap_stream.c b/subsys/bluetooth/audio/cap_stream.c index 7594497d05d3..0a458efa09d5 100644 --- a/subsys/bluetooth/audio/cap_stream.c +++ b/subsys/bluetooth/audio/cap_stream.c @@ -6,6 +6,8 @@ #include +#include "cap_internal.h" + #if defined(CONFIG_BT_BAP_UNICAST) static void cap_stream_configured_cb(struct bt_bap_stream *bap_stream, const struct bt_codec_qos_pref *pref) @@ -15,6 +17,10 @@ static void cap_stream_configured_cb(struct bt_bap_stream *bap_stream, bap_stream); struct bt_bap_stream_ops *ops = cap_stream->ops; + if (IS_ENABLED(CONFIG_BT_CAP_INITIATOR)) { + bt_cap_initiator_codec_configured(cap_stream); + } + if (ops != NULL && ops->configured != NULL) { ops->configured(bap_stream, pref); } @@ -27,6 +33,10 @@ static void cap_stream_qos_set_cb(struct bt_bap_stream *bap_stream) bap_stream); struct bt_bap_stream_ops *ops = cap_stream->ops; + if (IS_ENABLED(CONFIG_BT_CAP_INITIATOR)) { + bt_cap_initiator_qos_configured(cap_stream); + } + if (ops != NULL && ops->qos_set != NULL) { ops->qos_set(bap_stream); } @@ -39,6 +49,10 @@ static void cap_stream_enabled_cb(struct bt_bap_stream *bap_stream) bap_stream); struct bt_bap_stream_ops *ops = cap_stream->ops; + if (IS_ENABLED(CONFIG_BT_CAP_INITIATOR)) { + bt_cap_initiator_enabled(cap_stream); + } + if (ops != NULL && ops->enabled != NULL) { ops->enabled(bap_stream); } @@ -89,6 +103,10 @@ static void cap_stream_started_cb(struct bt_bap_stream *bap_stream) bap_stream); struct bt_bap_stream_ops *ops = cap_stream->ops; + if (IS_ENABLED(CONFIG_BT_CAP_INITIATOR)) { + bt_cap_initiator_started(cap_stream); + } + if (ops != NULL && ops->started != NULL) { ops->started(bap_stream); } @@ -154,8 +172,21 @@ static struct bt_bap_stream_ops bap_stream_ops = { #endif /* CONFIG_BT_BAP_UNICAST || CONFIG_BT_BAP_BROADCAST_SOURCE */ }; -void bt_cap_stream_ops_register(struct bt_cap_stream *stream, struct bt_bap_stream_ops *ops) +void bt_cap_stream_ops_register_bap(struct bt_cap_stream *cap_stream) +{ + bt_bap_stream_cb_register(&cap_stream->bap_stream, &bap_stream_ops); +} + +void bt_cap_stream_ops_register(struct bt_cap_stream *stream, + struct bt_bap_stream_ops *ops) { stream->ops = ops; - bt_bap_stream_cb_register(&stream->bap_stream, &bap_stream_ops); + + /* For the broadcast sink role, this is the only way we can ensure that + * the BAP callbacks are registered, as there are no CAP broadcast sink + * procedures that we can use to register the callbacks in other ways. + */ + if (IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SINK)) { + bt_cap_stream_ops_register_bap(stream); + } } From 6866cd30e8ec9b277f66467e3e29882e26266c27 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 18 Aug 2022 13:36:48 +0200 Subject: [PATCH 0509/1906] Bluetooth: Audio: Add support for CAP unicast start in shell This modifies the audio.c shell module to support multiple connections. This adds support for the cap_initiator unicast-start command, which supports multiple endpoints on multiple devices. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/shell/bap.c | 139 +++++----- subsys/bluetooth/audio/shell/cap_initiator.c | 267 ++++++++++++++++++- subsys/bluetooth/shell/bt.h | 21 ++ 3 files changed, 364 insertions(+), 63 deletions(-) diff --git a/subsys/bluetooth/audio/shell/bap.c b/subsys/bluetooth/audio/shell/bap.c index 43cf8b7f6ee3..f836ead10ea1 100644 --- a/subsys/bluetooth/audio/shell/bap.c +++ b/subsys/bluetooth/audio/shell/bap.c @@ -52,10 +52,10 @@ static const struct bt_codec_qos_pref qos_pref = BT_CODEC_QOS_PREF(true, BT_GAP_ #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) static struct bt_bap_unicast_group *default_unicast_group; #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 -static struct bt_bap_ep *snks[CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT]; +struct bt_bap_ep *snks[CONFIG_BT_MAX_CONN][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT]; #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 */ #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 -static struct bt_bap_ep *srcs[CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT]; +struct bt_bap_ep *srcs[CONFIG_BT_MAX_CONN][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT]; #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 */ #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ #endif /* CONFIG_BT_BAP_UNICAST */ @@ -75,11 +75,6 @@ static struct bt_bap_stream *default_stream; static uint16_t seq_num; static size_t rx_cnt; -struct named_lc3_preset { - const char *name; - struct bt_bap_lc3_preset preset; -}; - static const struct named_lc3_preset lc3_unicast_presets[] = { {"8_1_1", BT_BAP_LC3_UNICAST_PRESET_8_1_1(LOCATION, CONTEXT)}, {"8_2_1", BT_BAP_LC3_UNICAST_PRESET_8_2_1(LOCATION, CONTEXT)}, @@ -153,8 +148,8 @@ static const struct named_lc3_preset lc3_broadcast_presets[] = { }; /* Default to 16_2_1 */ -static const struct named_lc3_preset *default_sink_preset = &lc3_unicast_presets[3]; -static const struct named_lc3_preset *default_source_preset = &lc3_unicast_presets[3]; +const struct named_lc3_preset *default_sink_preset = &lc3_unicast_presets[3]; +const struct named_lc3_preset *default_source_preset = &lc3_unicast_presets[3]; static const struct named_lc3_preset *default_broadcast_source_preset = &lc3_broadcast_presets[3]; static bool initialized; @@ -713,48 +708,60 @@ static int set_metadata(struct bt_codec *codec, const char *meta_str) #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) static uint8_t stream_dir(const struct bt_bap_stream *stream) { + if (stream->conn) { + uint8_t conn_index = bt_conn_index(stream->conn); + #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 - for (size_t i = 0; i < ARRAY_SIZE(snks); i++) { - if (snks[i] != NULL && stream->ep == snks[i]) { - return BT_AUDIO_DIR_SINK; + for (size_t i = 0; i < ARRAY_SIZE(snks[conn_index]); i++) { + const struct bt_bap_ep *snk_ep = snks[conn_index][i]; + + if (snk_ep != NULL && stream->ep == snk_ep) { + return BT_AUDIO_DIR_SINK; + } } - } #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 */ #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 - for (size_t i = 0; i < ARRAY_SIZE(srcs); i++) { - if (srcs[i] != NULL && stream->ep == srcs[i]) { - return BT_AUDIO_DIR_SOURCE; + for (size_t i = 0; i < ARRAY_SIZE(srcs[conn_index]); i++) { + const struct bt_bap_ep *src_ep = srcs[conn_index][i]; + + if (src_ep != NULL && stream->ep == src_ep) { + return BT_AUDIO_DIR_SOURCE; + } } - } #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 */ + } __ASSERT(false, "Invalid stream"); return 0; } -static void print_remote_codec(struct bt_codec *codec, uint8_t index, enum bt_audio_dir dir) +static void print_remote_codec(const struct bt_conn *conn, struct bt_codec *codec, uint8_t index, + enum bt_audio_dir dir) { - shell_print(ctx_shell, "#%u: codec %p dir 0x%02x", index, codec, dir); + shell_print(ctx_shell, "conn %p: #%u: codec %p dir 0x%02x", + conn, index, codec, dir); print_codec(codec); } #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 -static void add_sink(struct bt_bap_ep *ep, uint8_t index) +static void add_sink(const struct bt_conn *conn, struct bt_bap_ep *ep, + uint8_t index) { - shell_print(ctx_shell, "Sink #%u: ep %p", index, ep); + shell_print(ctx_shell, "Conn: %p, Sink #%u: ep %p", conn, index, ep); - snks[index] = ep; + snks[bt_conn_index(conn)][index] = ep; } #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 */ #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 -static void add_source(struct bt_bap_ep *ep, uint8_t index) +static void add_source(const struct bt_conn *conn, struct bt_bap_ep *ep, + uint8_t index) { - shell_print(ctx_shell, "Source #%u: ep %p", index, ep); + shell_print(ctx_shell, "Conn: %p, Source #%u: ep %p", conn, index, ep); - srcs[index] = ep; + srcs[bt_conn_index(conn)][index] = ep; } #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 */ @@ -762,20 +769,20 @@ static void discover_cb(struct bt_conn *conn, struct bt_codec *codec, struct bt_ struct bt_bap_unicast_client_discover_params *params) { if (codec != NULL) { - print_remote_codec(codec, params->num_caps, params->dir); + print_remote_codec(conn, codec, params->num_caps, params->dir); return; } if (ep) { #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 if (params->dir == BT_AUDIO_DIR_SINK) { - add_sink(ep, params->num_eps); + add_sink(conn, ep, params->num_eps); } #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 */ #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 if (params->dir == BT_AUDIO_DIR_SOURCE) { - add_source(ep, params->num_eps); + add_source(conn, ep, params->num_eps); } #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0*/ @@ -791,20 +798,20 @@ static void discover_all(struct bt_conn *conn, struct bt_codec *codec, struct bt struct bt_bap_unicast_client_discover_params *params) { if (codec != NULL) { - print_remote_codec(codec, params->num_caps, params->dir); + print_remote_codec(conn, codec, params->num_caps, params->dir); return; } if (ep) { #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 if (params->dir == BT_AUDIO_DIR_SINK) { - add_sink(ep, params->num_eps); + add_sink(conn, ep, params->num_eps); } #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 */ #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 if (params->dir == BT_AUDIO_DIR_SOURCE) { - add_source(ep, params->num_eps); + add_source(conn, ep, params->num_eps); } #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0*/ @@ -965,12 +972,14 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) struct unicast_stream *uni_stream; struct bt_bap_ep *ep = NULL; unsigned long index; + uint8_t conn_index; int err = 0; if (!default_conn) { shell_error(sh, "Not connected"); return -ENOEXEC; } + conn_index = bt_conn_index(default_conn); if (default_stream == NULL) { default_stream = &unicast_streams[0].stream; @@ -993,14 +1002,14 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 } else if (!strcmp(argv[1], "sink")) { - ep = snks[index]; + ep = snks[conn_index][index]; named_preset = default_sink_preset; #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 */ #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 } else if (!strcmp(argv[1], "source")) { - ep = srcs[index]; + ep = srcs[conn_index][index]; named_preset = default_source_preset; #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 */ @@ -1497,50 +1506,59 @@ static int cmd_disable(const struct shell *sh, size_t argc, char *argv[]) return 0; } -static int cmd_list(const struct shell *sh, size_t argc, char *argv[]) +#if defined(CONFIG_BT_BAP_UNICAST_CLIENT) +static void conn_list_eps(struct bt_conn *conn, void *data) { - int i; - - shell_print(sh, "Configured Channels:"); + const struct shell *sh = (const struct shell *)data; + uint8_t conn_index = bt_conn_index(conn); - for (i = 0; i < ARRAY_SIZE(unicast_streams); i++) { - struct bt_bap_stream *stream = &unicast_streams[i].stream; - - if (stream->conn) { - shell_print(sh, " %s#%u: stream %p ep %p group %p", - stream == default_stream ? "*" : " ", i, - stream, stream->ep, stream->group); - } - } + shell_print(sh, "Conn: %p", conn); + shell_print(sh, " Sinks:"); -#if defined(CONFIG_BT_BAP_UNICAST_CLIENT) #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 - shell_print(sh, "Sinks:"); - - for (i = 0; i < ARRAY_SIZE(snks); i++) { - struct bt_bap_ep *ep = snks[i]; + for (size_t i = 0U; i < ARRAY_SIZE(snks[conn_index]); i++) { + const struct bt_bap_ep *ep = snks[conn_index][i]; - if (ep) { - shell_print(sh, " #%u: ep %p", i, ep); + if (ep != NULL) { + shell_print(sh, " #%u: ep %p", i, ep); } } #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 */ #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 - shell_print(sh, "Sources:"); + shell_print(sh, " Sources:"); - for (i = 0; i < ARRAY_SIZE(srcs); i++) { - struct bt_bap_ep *ep = srcs[i]; + for (size_t i = 0U; i < ARRAY_SIZE(srcs[conn_index]); i++) { + const struct bt_bap_ep *ep = srcs[conn_index][i]; - if (ep) { - shell_print(sh, " #%u: ep %p", i, ep); + if (ep != NULL) { + shell_print(sh, " #%u: ep %p", i, ep); } } #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 */ +} #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ +#if defined(CONFIG_BT_BAP_UNICAST_CLIENT) +static int cmd_list(const struct shell *sh, size_t argc, char *argv[]) +{ + shell_print(sh, "Configured Channels:"); + + for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) { + struct bt_bap_stream *stream = &unicast_streams[i].stream; + + if (stream->conn != NULL) { + shell_print(sh, " %s#%u: stream %p dir 0x%02x group %p", + stream == default_stream ? "*" : " ", i, stream, + stream_dir(stream), stream->group); + } + } + + bt_conn_foreach(BT_CONN_TYPE_LE, conn_list_eps, (void *)sh); + return 0; } +#endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ static int cmd_release(const struct shell *sh, size_t argc, char *argv[]) { @@ -2523,6 +2541,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_CMD_ARG(qos, NULL, "Send QoS configure for Unicast Group", cmd_qos, 1, 0), SHELL_CMD_ARG(enable, NULL, "[context]", cmd_enable, 1, 1), SHELL_CMD_ARG(stop, NULL, NULL, cmd_stop, 1, 0), + SHELL_CMD_ARG(list, NULL, NULL, cmd_list, 1, 0), #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ #if defined(CONFIG_BT_BAP_UNICAST_SERVER) SHELL_CMD_ARG(print_ase_info, NULL, "Print ASE info for default connection", @@ -2532,8 +2551,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_CMD_ARG(start, NULL, NULL, cmd_start, 1, 0), SHELL_CMD_ARG(disable, NULL, NULL, cmd_disable, 1, 0), SHELL_CMD_ARG(release, NULL, NULL, cmd_release, 1, 0), - SHELL_CMD_ARG(list, NULL, NULL, cmd_list, 1, 0), - SHELL_CMD_ARG(select_unicast, NULL, "", cmd_select_unicast, 2, 0), + SHELL_CMD_ARG(select_unicast, NULL, "", + cmd_select_unicast, 2, 0), #endif /* CONFIG_BT_BAP_UNICAST */ SHELL_CMD_ARG(preset, NULL, " [preset]", cmd_preset, 2, 1), SHELL_CMD_ARG(send, NULL, "Send to Audio Stream [data]", cmd_send, 1, 1), diff --git a/subsys/bluetooth/audio/shell/cap_initiator.c b/subsys/bluetooth/audio/shell/cap_initiator.c index a68a255ed398..c78d1715394b 100644 --- a/subsys/bluetooth/audio/shell/cap_initiator.c +++ b/subsys/bluetooth/audio/shell/cap_initiator.c @@ -18,6 +18,16 @@ #include "shell/bt.h" #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) +#define CAP_UNICAST_CLIENT_STREAM_COUNT (CONFIG_BT_MAX_CONN * \ + (CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT + \ + CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT)) + +static struct cap_unicast_stream { + struct bt_cap_stream stream; + struct bt_codec codec; + struct bt_codec_qos qos; +} unicast_client_streams[CAP_UNICAST_CLIENT_STREAM_COUNT]; +static struct bt_bap_unicast_group *default_unicast_group; static void cap_discover_cb(struct bt_conn *conn, int err, const struct bt_csip_set_coordinator_csis_inst *csis_inst) @@ -31,8 +41,20 @@ static void cap_discover_cb(struct bt_conn *conn, int err, csis_inst == NULL ? "" : " with CSIS"); } +static void cap_unicast_start_complete_cb(struct bt_bap_unicast_group *unicast_group, + int err, struct bt_conn *conn) +{ + if (err != 0) { + shell_error(ctx_shell, "Unicast start failed for conn %p (%d)", + conn, err); + } else { + shell_print(ctx_shell, "Unicast start completed"); + } +} + static struct bt_cap_initiator_cb cbs = { .unicast_discovery_complete = cap_discover_cb, + .unicast_start_complete = cap_unicast_start_complete_cb, }; static int cmd_cap_initiator_discover(const struct shell *sh, size_t argc, @@ -63,6 +85,239 @@ static int cmd_cap_initiator_discover(const struct shell *sh, size_t argc, return err; } +static void populate_connected_conns(struct bt_conn *conn, void *data) +{ + struct bt_conn **connected_conns = (struct bt_conn **)data; + + for (int i = 0; i < CONFIG_BT_MAX_CONN; i++) { + if (connected_conns[i] == NULL) { + connected_conns[i] = conn; + return; + } + } +} + +static void cap_copy_preset(struct cap_unicast_stream *uni_stream, + const struct named_lc3_preset *name_preset) +{ + memcpy(&uni_stream->qos, &name_preset->preset.qos, sizeof(uni_stream->qos)); + memcpy(&uni_stream->codec, &name_preset->preset.codec, sizeof(uni_stream->codec)); + + /* Need to update the `bt_data.data` pointer to the new value after copying the codec */ + for (size_t i = 0U; i < ARRAY_SIZE(uni_stream->codec.data); i++) { + struct bt_codec_data *data = &uni_stream->codec.data[i]; + + data->data.data = data->value; + } + + for (size_t i = 0U; i < ARRAY_SIZE(uni_stream->codec.meta); i++) { + struct bt_codec_data *data = &uni_stream->codec.meta[i]; + + data->data.data = data->value; + } +} + +static int cmd_cap_initiator_unicast_start(const struct shell *sh, size_t argc, + char *argv[]) +{ + struct bt_bap_unicast_group_stream_param + group_stream_params[CAP_UNICAST_CLIENT_STREAM_COUNT] = {0}; + struct bt_bap_unicast_group_stream_pair_param + pair_params[CAP_UNICAST_CLIENT_STREAM_COUNT] = {0}; + struct bt_cap_unicast_audio_start_stream_param + stream_param[CAP_UNICAST_CLIENT_STREAM_COUNT] = {0}; + struct bt_conn *connected_conns[CONFIG_BT_MAX_CONN] = {0}; + struct bt_cap_unicast_audio_start_param start_param = {0}; + struct bt_bap_unicast_group_param group_param = {0}; + size_t source_cnt = 1U; + ssize_t conn_cnt = 1U; + size_t sink_cnt = 1U; + size_t pair_cnt = 0U; + int err = 0; + + if (default_conn == NULL) { + shell_error(sh, "Not connected"); + return -ENOEXEC; + } + + start_param.type = BT_CAP_SET_TYPE_AD_HOC; + + for (size_t argn = 1; argn < argc; argn++) { + const char *arg = argv[argn]; + + if (strcmp(arg, "csip") == 0) { + start_param.type = BT_CAP_SET_TYPE_CSIP; + } else if (strcmp(arg, "sinks") == 0) { + if (++argn == argc) { + shell_help(sh); + + return SHELL_CMD_HELP_PRINTED; + } + + sink_cnt = shell_strtoul(argv[argn], 10, &err); + } else if (strcmp(arg, "sources") == 0) { + if (++argn == argc) { + shell_help(sh); + + return SHELL_CMD_HELP_PRINTED; + } + + source_cnt = shell_strtoul(argv[argn], 10, &err); + } else if (strcmp(arg, "conns") == 0) { + if (++argn == argc) { + shell_help(sh); + + return SHELL_CMD_HELP_PRINTED; + } + + if (strcmp(argv[argn], "all") == 0) { + conn_cnt = CONFIG_BT_MAX_CONN; + } else { + conn_cnt = shell_strtoul(argv[argn], 10, &err); + + /* Ensure that we do not iterate over more conns + * than the array supports + */ + conn_cnt = MIN(conn_cnt, ARRAY_SIZE(connected_conns)); + } + } else { + shell_help(sh); + + return SHELL_CMD_HELP_PRINTED; + } + + if (err != 0) { + shell_error(sh, "Failed to parse argument: %s: %s (%d)", + arg, argv[argn], err); + + return err; + } + } + + shell_print(sh, "Setting up %u sinks and %u sources on each (%u) conn", sink_cnt, + source_cnt, conn_cnt); + + /* Populate the array of connected connections */ + (void)memset(connected_conns, 0, sizeof(connected_conns)); + bt_conn_foreach(BT_CONN_TYPE_LE, populate_connected_conns, + (void *)connected_conns); + + start_param.count = 0U; + start_param.stream_params = stream_param; + for (size_t i = 0; i < conn_cnt; i++) { + struct bt_conn *conn = connected_conns[i]; + size_t conn_src_cnt = 0U; + size_t conn_snk_cnt = 0U; + + if (conn == NULL) { + break; + } + +#if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 + conn_snk_cnt = sink_cnt; + for (size_t i = 0U; i < sink_cnt; i++) { + struct bt_cap_stream *stream = + &unicast_client_streams[start_param.count].stream; + struct cap_unicast_stream *uni_stream = + CONTAINER_OF(stream, struct cap_unicast_stream, stream); + struct bt_bap_ep *snk_ep = snks[bt_conn_index(conn)][i]; + + if (snk_ep == NULL) { + shell_info(sh, "Could only setup %zu/%zu sink endpoints", + i, sink_cnt); + conn_snk_cnt = i; + break; + } + + stream_param[start_param.count].member.member = conn; + stream_param[start_param.count].stream = stream; + stream_param[start_param.count].ep = snk_ep; + cap_copy_preset(uni_stream, default_sink_preset); + stream_param[start_param.count].codec = &uni_stream->codec; + stream_param[start_param.count].qos = &uni_stream->qos; + + group_stream_params[start_param.count].qos = + stream_param[start_param.count].qos; + group_stream_params[start_param.count].stream = + &stream_param[start_param.count].stream->bap_stream; + pair_params[pair_cnt + i].tx_param = + &group_stream_params[start_param.count]; + + start_param.count++; + } +#endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 */ + +#if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 + conn_src_cnt = source_cnt; + for (size_t i = 0U; i < source_cnt; i++) { + struct bt_cap_stream *stream = + &unicast_client_streams[start_param.count].stream; + struct cap_unicast_stream *uni_stream = + CONTAINER_OF(stream, struct cap_unicast_stream, stream); + struct bt_bap_ep *src_ep = srcs[bt_conn_index(conn)][i]; + + if (src_ep == NULL) { + shell_info(sh, "Could only setup %zu/%zu source endpoints", + i, source_cnt); + conn_src_cnt = i; + break; + } + + stream_param[start_param.count].member.member = conn; + stream_param[start_param.count].stream = stream; + stream_param[start_param.count].ep = src_ep; + cap_copy_preset(uni_stream, default_source_preset); + stream_param[start_param.count].codec = &uni_stream->codec; + stream_param[start_param.count].qos = &uni_stream->qos; + + group_stream_params[start_param.count].qos = + stream_param[start_param.count].qos; + group_stream_params[start_param.count].stream = + &stream_param[start_param.count].stream->bap_stream; + pair_params[pair_cnt + i].rx_param = + &group_stream_params[start_param.count]; + + start_param.count++; + } +#endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0 */ + + /* Increment pair count with the max of sink and source for this connection, as + * we cannot have pairs across connections + */ + pair_cnt += MAX(conn_snk_cnt, conn_src_cnt); + } + + if (pair_cnt == 0U) { + shell_error(sh, "No streams to setup"); + + return -ENOEXEC; + } + + group_param.packing = BT_ISO_PACKING_SEQUENTIAL; + group_param.params_count = pair_cnt; + group_param.params = pair_params; + + if (default_unicast_group == NULL) { + err = bt_bap_unicast_group_create(&group_param, &default_unicast_group); + if (err != 0) { + shell_print(sh, "Failed to create group: %d", err); + + return -ENOEXEC; + } + } + + shell_print(sh, "Starting %zu streams", start_param.count); + + err = bt_cap_initiator_unicast_audio_start(&start_param, default_unicast_group); + if (err != 0) { + shell_print(sh, "Failed to start unicast audio: %d", err); + + return -ENOEXEC; + } + + return 0; +} + #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ static int cmd_cap_initiator(const struct shell *sh, size_t argc, char **argv) @@ -79,10 +334,16 @@ static int cmd_cap_initiator(const struct shell *sh, size_t argc, char **argv) SHELL_STATIC_SUBCMD_SET_CREATE(cap_initiator_cmds, #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) - SHELL_CMD_ARG(discover, NULL, "Discover CAS", - cmd_cap_initiator_discover, 1, 0), + SHELL_CMD_ARG(discover, NULL, + "Discover CAS", cmd_cap_initiator_discover, 1, 0), + SHELL_CMD_ARG(unicast-start, NULL, + "Unicast Start [csip] [sinks (default 1)] " + "[sources (default 1)] " + "[conns ( | all) (default 1)]", + cmd_cap_initiator_unicast_start, 1, 7), #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ - SHELL_SUBCMD_SET_END); + SHELL_SUBCMD_SET_END +); SHELL_CMD_ARG_REGISTER(cap_initiator, &cap_initiator_cmds, "Bluetooth CAP initiator shell commands", diff --git a/subsys/bluetooth/shell/bt.h b/subsys/bluetooth/shell/bt.h index 76772f85bf56..19b644159b0e 100644 --- a/subsys/bluetooth/shell/bt.h +++ b/subsys/bluetooth/shell/bt.h @@ -31,6 +31,27 @@ extern struct bt_le_per_adv_sync *per_adv_syncs[CONFIG_BT_PER_ADV_SYNC_MAX]; #endif /* CONFIG_BT_PER_ADV_SYNC */ #endif /* CONFIG_BT_EXT_ADV */ +#if defined(CONFIG_BT_AUDIO) +/* Must guard before including audio.h as audio.h uses Kconfigs guarded by + * CONFIG_BT_AUDIO + */ +#include +#include + +struct named_lc3_preset { + const char *name; + struct bt_bap_lc3_preset preset; +}; + +#if defined(CONFIG_BT_BAP_UNICAST_CLIENT) + +extern struct bt_bap_ep *snks[CONFIG_BT_MAX_CONN][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT]; +extern struct bt_bap_ep *srcs[CONFIG_BT_MAX_CONN][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT]; +extern const struct named_lc3_preset *default_sink_preset; +extern const struct named_lc3_preset *default_source_preset; +#endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ +#endif /* CONFIG_BT_AUDIO */ + void conn_addr_str(struct bt_conn *conn, char *addr, size_t len); #endif /* __BT_H */ From e4d072511255706eb7349fe3cf86eeafadda3095 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 18 Aug 2022 13:37:59 +0200 Subject: [PATCH 0510/1906] tests: Bluetooth: Audio: Add CAP unicast start BSIM test The test only works partially until the controller and babblesim supports ISO, as it needs that in order to perform the unicast start procedure. Signed-off-by: Emil Gydesen --- .../bluetooth/audio/src/cap_acceptor_test.c | 336 +++++++++++++++++- .../bluetooth/audio/src/cap_initiator_test.c | 228 +++++++++++- 2 files changed, 551 insertions(+), 13 deletions(-) diff --git a/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c b/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c index 90c18abd620c..c9920695f2eb 100644 --- a/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c @@ -15,6 +15,11 @@ extern enum bst_result_t bst_result; +#define SINK_CONTEXT BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | \ + BT_AUDIO_CONTEXT_TYPE_MEDIA | \ + BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL +#define SOURCE_CONTEXT BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS + CREATE_FLAG(flag_broadcaster_found); CREATE_FLAG(flag_base_received); CREATE_FLAG(flag_pa_synced); @@ -24,8 +29,16 @@ CREATE_FLAG(flag_pa_sync_lost); static struct bt_bap_broadcast_sink *g_broadcast_sink; static struct bt_cap_stream broadcast_sink_streams[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT]; -static struct bt_bap_lc3_preset broadcast_preset_16_2_1 = BT_BAP_LC3_BROADCAST_PRESET_16_2_1( - BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); +static struct bt_bap_lc3_preset unicast_preset_16_2_1 = + BT_BAP_LC3_UNICAST_PRESET_16_2_1(BT_AUDIO_LOCATION_FRONT_LEFT, + SINK_CONTEXT); +static struct bt_bap_lc3_preset broadcast_preset_16_2_1 = + BT_BAP_LC3_BROADCAST_PRESET_16_2_1(BT_AUDIO_LOCATION_FRONT_LEFT, + BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); + +static const struct bt_codec_qos_pref unicast_qos_pref = + BT_CODEC_QOS_PREF(true, BT_GAP_LE_PHY_2M, 0u, 60u, 20000u, 40000u, 20000u, 40000u); + static K_SEM_DEFINE(sem_broadcast_started, 0U, ARRAY_SIZE(broadcast_sink_streams)); static K_SEM_DEFINE(sem_broadcast_stopped, 0U, ARRAY_SIZE(broadcast_sink_streams)); @@ -37,6 +50,13 @@ static K_SEM_DEFINE(sem_broadcast_stopped, 0U, ARRAY_SIZE(broadcast_sink_streams static const uint32_t bis_index_mask = BIT_MASK(ARRAY_SIZE(broadcast_sink_streams) + 1U); static uint32_t bis_index_bitfield; +#define UNICAST_CHANNEL_COUNT_1 BIT(0) + +static struct bt_cap_stream unicast_streams[CONFIG_BT_ASCS_ASE_SNK_COUNT + + CONFIG_BT_ASCS_ASE_SRC_COUNT]; + +CREATE_FLAG(flag_unicast_stream_configured); + static bool scan_recv_cb(const struct bt_le_scan_recv_info *info, struct net_buf_simple *ad, uint32_t broadcast_id) @@ -185,6 +205,34 @@ static void recv_cb(struct bt_bap_stream *stream, const struct bt_iso_recv_info static struct bt_bap_stream_ops broadcast_stream_ops = { .started = started_cb, .stopped = stopped_cb, .recv = recv_cb}; +static void unicast_stream_enabled_cb(struct bt_bap_stream *stream) +{ + struct bt_bap_ep_info ep_info; + int err; + + printk("Enabled: stream %p\n", stream); + + err = bt_bap_ep_get_info(stream->ep, &ep_info); + if (err != 0) { + FAIL("Failed to get ep info: %d\n", err); + return; + } + + if (ep_info.dir == BT_AUDIO_DIR_SINK) { + /* Automatically do the receiver start ready operation */ + err = bt_bap_stream_start(stream); + + if (err != 0) { + FAIL("Failed to start stream: %d\n", err); + return; + } + } +} + +static struct bt_bap_stream_ops unicast_stream_ops = { + .enabled = unicast_stream_enabled_cb, +}; + /* TODO: Expand with CAP service data */ static const struct bt_data cap_acceptor_ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), @@ -193,15 +241,258 @@ static const struct bt_data cap_acceptor_ad[] = { static struct bt_csip_set_member_svc_inst *csip_set_member; +static struct bt_bap_stream *unicast_stream_alloc(void) +{ + for (size_t i = 0; i < ARRAY_SIZE(unicast_streams); i++) { + struct bt_bap_stream *stream = &unicast_streams[i].bap_stream; + + if (!stream->conn) { + return stream; + } + } + + return NULL; +} + +static int unicast_server_config(struct bt_conn *conn, const struct bt_bap_ep *ep, + enum bt_audio_dir dir, const struct bt_codec *codec, + struct bt_bap_stream **stream, + struct bt_codec_qos_pref *const pref) +{ + printk("ASE Codec Config: conn %p ep %p dir %u\n", conn, ep, dir); + + print_codec(codec); + + *stream = unicast_stream_alloc(); + if (*stream == NULL) { + printk("No streams available\n"); + + return -ENOMEM; + } + + printk("ASE Codec Config stream %p\n", *stream); + + SET_FLAG(flag_unicast_stream_configured); + + *pref = unicast_qos_pref; + + return 0; +} + +static int unicast_server_reconfig(struct bt_bap_stream *stream, enum bt_audio_dir dir, + const struct bt_codec *codec, + struct bt_codec_qos_pref *const pref) +{ + printk("ASE Codec Reconfig: stream %p\n", stream); + + print_codec(codec); + + *pref = unicast_qos_pref; + + /* We only support one QoS at the moment, reject changes */ + return -ENOEXEC; +} + +static int unicast_server_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos) +{ + printk("QoS: stream %p qos %p\n", stream, qos); + + print_qos(qos); + + return 0; +} + +static int unicast_server_enable(struct bt_bap_stream *stream, const struct bt_codec_data *meta, + size_t meta_count) +{ + printk("Enable: stream %p meta_count %zu\n", stream, meta_count); + + return 0; +} + +static int unicast_server_start(struct bt_bap_stream *stream) +{ + printk("Start: stream %p\n", stream); + + return 0; +} + +static bool valid_metadata_type(uint8_t type, uint8_t len) +{ + switch (type) { + case BT_AUDIO_METADATA_TYPE_PREF_CONTEXT: + case BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT: + if (len != 2) { + return false; + } + + return true; + case BT_AUDIO_METADATA_TYPE_STREAM_LANG: + if (len != 3) { + return false; + } + + return true; + case BT_AUDIO_METADATA_TYPE_PARENTAL_RATING: + if (len != 1) { + return false; + } + + return true; + case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 1 - 255 octets */ + case BT_AUDIO_METADATA_TYPE_VENDOR: /* 1 - 255 octets */ + if (len < 1) { + return false; + } + + return true; + case BT_AUDIO_METADATA_TYPE_CCID_LIST: /* 2 - 254 octets */ + if (len < 2) { + return false; + } + + return true; + case BT_AUDIO_METADATA_TYPE_PROGRAM_INFO: /* 0 - 255 octets */ + case BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI: /* 0 - 255 octets */ + return true; + default: + return false; + } +} + +static int unicast_server_metadata(struct bt_bap_stream *stream, const struct bt_codec_data *meta, + size_t meta_count) +{ + printk("Metadata: stream %p meta_count %zu\n", stream, meta_count); + + for (size_t i = 0; i < meta_count; i++) { + if (!valid_metadata_type(meta->data.type, meta->data.data_len)) { + printk("Invalid metadata type %u or length %u\n", + meta->data.type, meta->data.data_len); + + return -EINVAL; + } + } + + return 0; +} + +static int unicast_server_disable(struct bt_bap_stream *stream) +{ + printk("Disable: stream %p\n", stream); + + return 0; +} + +static int unicast_server_stop(struct bt_bap_stream *stream) +{ + printk("Stop: stream %p\n", stream); + + return 0; +} + +static int unicast_server_release(struct bt_bap_stream *stream) +{ + printk("Release: stream %p\n", stream); + + return 0; +} + +static struct bt_bap_unicast_server_cb unicast_server_cbs = { + .config = unicast_server_config, + .reconfig = unicast_server_reconfig, + .qos = unicast_server_qos, + .enable = unicast_server_enable, + .start = unicast_server_start, + .metadata = unicast_server_metadata, + .disable = unicast_server_disable, + .stop = unicast_server_stop, + .release = unicast_server_release, +}; + +static void set_location(void) +{ + int err; + + if (IS_ENABLED(CONFIG_BT_PAC_SNK_LOC)) { + err = bt_pacs_set_location(BT_AUDIO_DIR_SINK, + BT_AUDIO_LOCATION_FRONT_CENTER); + if (err != 0) { + FAIL("Failed to set sink location (err %d)\n", err); + return; + } + } + + if (IS_ENABLED(CONFIG_BT_PAC_SRC_LOC)) { + err = bt_pacs_set_location(BT_AUDIO_DIR_SOURCE, + BT_AUDIO_LOCATION_FRONT_LEFT | + BT_AUDIO_LOCATION_FRONT_RIGHT); + if (err != 0) { + FAIL("Failed to set source location (err %d)\n", err); + return; + } + } + + printk("Location successfully set\n"); +} + +static int set_supported_contexts(void) +{ + int err; + + if (IS_ENABLED(CONFIG_BT_PAC_SNK)) { + err = bt_pacs_set_supported_contexts(BT_AUDIO_DIR_SINK, SINK_CONTEXT); + if (err != 0) { + printk("Failed to set sink supported contexts (err %d)\n", + err); + + return err; + } + } + + if (IS_ENABLED(CONFIG_BT_PAC_SRC)) { + err = bt_pacs_set_supported_contexts(BT_AUDIO_DIR_SOURCE, SOURCE_CONTEXT); + if (err != 0) { + printk("Failed to set source supported contexts (err %d)\n", + err); + + return err; + } + } + + printk("Supported contexts successfully set\n"); + + return 0; +} + +static void set_available_contexts(void) +{ + int err; + + err = bt_pacs_set_available_contexts(BT_AUDIO_DIR_SINK, SINK_CONTEXT); + if (IS_ENABLED(CONFIG_BT_PAC_SNK) && err != 0) { + FAIL("Failed to set sink available contexts (err %d)\n", err); + return; + } + + err = bt_pacs_set_available_contexts(BT_AUDIO_DIR_SOURCE, SOURCE_CONTEXT); + if (IS_ENABLED(CONFIG_BT_PAC_SRC) && err != 0) { + FAIL("Failed to set source available contexts (err %d)\n", err); + return; + } + + printk("Available contexts successfully set\n"); +} + static void init(void) { - struct bt_csip_set_member_register_param csip_set_member_param = { + const struct bt_csip_set_member_register_param csip_set_member_param = { .set_size = 3, .rank = 1, .lockable = true, /* Using the CSIP_SET_MEMBER test sample SIRK */ .set_sirk = { 0xcd, 0xcc, 0x72, 0xdd, 0x86, 0x8c, 0xcd, 0xce, - 0x22, 0xfd, 0xa1, 0x21, 0x09, 0x7d, 0x7d, 0x45 }, + 0x22, 0xfd, 0xa1, 0x21, 0x09, 0x7d, 0x7d, 0x45 }, }; int err; @@ -215,8 +506,7 @@ static void init(void) printk("Bluetooth initialized\n"); if (IS_ENABLED(CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER)) { - err = bt_cap_acceptor_register(&csip_set_member_param, - &csip_set_member); + err = bt_cap_acceptor_register(&csip_set_member_param, &csip_set_member); if (err != 0) { FAIL("CAP acceptor failed to register (err %d)\n", err); return; @@ -224,8 +514,32 @@ static void init(void) } if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_SERVER)) { + static struct bt_pacs_cap unicast_cap = { + .codec = &unicast_preset_16_2_1.codec, + }; + + err = bt_pacs_cap_register(BT_AUDIO_DIR_SINK, &unicast_cap); + if (err != 0) { + FAIL("Broadcast capability register failed (err %d)\n", + err); + + return; + } + + err = bt_bap_unicast_server_register_cb(&unicast_server_cbs); + if (err != 0) { + FAIL("Failed to register unicast server callbacks (err %d)\n", + err); + + return; + } + + for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) { + bt_cap_stream_ops_register(&unicast_streams[i], &unicast_stream_ops); + } + err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, cap_acceptor_ad, - ARRAY_SIZE(cap_acceptor_ad), NULL, 0); + ARRAY_SIZE(cap_acceptor_ad), NULL, 0); if (err != 0) { FAIL("Advertising failed to start (err %d)\n", err); return; @@ -233,11 +547,11 @@ static void init(void) } if (IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SINK)) { - static struct bt_pacs_cap cap = { + static struct bt_pacs_cap broadcast_cap = { .codec = &broadcast_preset_16_2_1.codec, }; - err = bt_pacs_cap_register(BT_AUDIO_DIR_SINK, &cap); + err = bt_pacs_cap_register(BT_AUDIO_DIR_SINK, &broadcast_cap); if (err != 0) { FAIL("Broadcast capability register failed (err %d)\n", err); @@ -256,6 +570,10 @@ static void init(void) &broadcast_stream_ops); } } + + set_supported_contexts(); + set_available_contexts(); + set_location(); } static void test_cap_acceptor_unicast(void) diff --git a/tests/bsim/bluetooth/audio/src/cap_initiator_test.c b/tests/bsim/bluetooth/audio/src/cap_initiator_test.c index 46d465e27001..04589a6440e1 100644 --- a/tests/bsim/bluetooth/audio/src/cap_initiator_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_initiator_test.c @@ -9,35 +9,50 @@ #include #include #include +#include #include "common.h" #include "bap_unicast_common.h" +#if defined(CONFIG_BT_BAP_BROADCAST_SOURCE) +#define BROADCAST_STREMT_CNT CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT +#else +#define BROADCAST_STREMT_CNT 0 +#endif /* CONFIG_BT_BAP_BROADCAST_SOURCE */ /* When BROADCAST_ENQUEUE_COUNT > 1 we can enqueue enough buffers to ensure that * the controller is never idle */ #define BROADCAST_ENQUEUE_COUNT 2U -#define TOTAL_BUF_NEEDED (BROADCAST_ENQUEUE_COUNT * CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT) +#define TOTAL_BUF_NEEDED (BROADCAST_ENQUEUE_COUNT * BROADCAST_STREMT_CNT) BUILD_ASSERT(CONFIG_BT_ISO_TX_BUF_COUNT >= TOTAL_BUF_NEEDED, "CONFIG_BT_ISO_TX_BUF_COUNT should be at least " - "BROADCAST_ENQUEUE_COUNT * CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT"); + "BROADCAST_ENQUEUE_COUNT * BROADCAST_STREMT_CNT"); NET_BUF_POOL_FIXED_DEFINE(tx_pool, TOTAL_BUF_NEEDED, BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), 8, NULL); extern enum bst_result_t bst_result; -static struct bt_cap_stream broadcast_source_streams[CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT]; +static struct bt_cap_stream broadcast_source_streams[BROADCAST_STREMT_CNT]; static struct bt_cap_stream *broadcast_streams[ARRAY_SIZE(broadcast_source_streams)]; static struct bt_bap_lc3_preset broadcast_preset_16_2_1 = BT_BAP_LC3_BROADCAST_PRESET_16_2_1( BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_MEDIA); +static struct bt_bap_lc3_preset unicast_preset_16_2_1 = + BT_BAP_LC3_UNICAST_PRESET_16_2_1(BT_AUDIO_LOCATION_FRONT_LEFT, + BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); + +static struct bt_cap_stream unicast_client_streams[CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT]; +static struct bt_bap_ep *unicast_sink_eps[CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT]; + static K_SEM_DEFINE(sem_broadcast_started, 0U, ARRAY_SIZE(broadcast_streams)); static K_SEM_DEFINE(sem_broadcast_stopped, 0U, ARRAY_SIZE(broadcast_streams)); CREATE_FLAG(flag_discovered); +CREATE_FLAG(flag_started); CREATE_FLAG(flag_mtu_exchanged); +CREATE_FLAG(flag_sink_discovered); CREATE_FLAG(flag_broadcast_stopping); static void broadcast_started_cb(struct bt_bap_stream *stream) @@ -100,6 +115,63 @@ static struct bt_bap_stream_ops broadcast_stream_ops = {.started = broadcast_sta .stopped = broadcast_stopped_cb, .sent = broadcast_sent_cb}; + +static void unicast_stream_configured(struct bt_bap_stream *stream, + const struct bt_codec_qos_pref *pref) +{ + printk("Configured stream %p\n", stream); + + /* TODO: The preference should be used/taken into account when + * setting the QoS + */ +} + +static void unicast_stream_qos_set(struct bt_bap_stream *stream) +{ + printk("QoS set stream %p\n", stream); +} + +static void unicast_stream_enabled(struct bt_bap_stream *stream) +{ + printk("Enabled stream %p\n", stream); +} + +static void unicast_stream_started(struct bt_bap_stream *stream) +{ + printk("Started stream %p\n", stream); +} + +static void unicast_stream_metadata_updated(struct bt_bap_stream *stream) +{ + printk("Metadata updated stream %p\n", stream); +} + +static void unicast_stream_disabled(struct bt_bap_stream *stream) +{ + printk("Disabled stream %p\n", stream); +} + +static void unicast_stream_stopped(struct bt_bap_stream *stream, uint8_t reason) +{ + printk("Stopped stream with reason 0x%02X%p\n", stream, reason); +} + +static void unicast_stream_released(struct bt_bap_stream *stream) +{ + printk("Released stream %p\n", stream); +} + +static struct bt_bap_stream_ops unicast_stream_ops = { + .configured = unicast_stream_configured, + .qos_set = unicast_stream_qos_set, + .enabled = unicast_stream_enabled, + .started = unicast_stream_started, + .metadata_updated = unicast_stream_metadata_updated, + .disabled = unicast_stream_disabled, + .stopped = unicast_stream_stopped, + .released = unicast_stream_released, +}; + static void cap_discovery_complete_cb(struct bt_conn *conn, int err, const struct bt_csip_set_coordinator_csis_inst *csis_inst) { @@ -124,10 +196,77 @@ static void cap_discovery_complete_cb(struct bt_conn *conn, int err, SET_FLAG(flag_discovered); } +static void unicast_start_complete_cb(struct bt_bap_unicast_group *unicast_group, + int err, struct bt_conn *conn) +{ + if (err != 0) { + FAIL("Failed to start (failing conn %p): %d", conn, err); + + return; + } + + SET_FLAG(flag_started); +} + static struct bt_cap_initiator_cb cap_cb = { - .unicast_discovery_complete = cap_discovery_complete_cb + .unicast_discovery_complete = cap_discovery_complete_cb, + .unicast_start_complete = unicast_start_complete_cb, }; +static void add_remote_sink(struct bt_bap_ep *ep, uint8_t index) +{ + printk("Sink #%u: ep %p\n", index, ep); + + unicast_sink_eps[index] = ep; +} + +static void print_remote_codec(struct bt_codec *codec, int index, enum bt_audio_dir dir) +{ + printk("#%u: codec %p dir 0x%02x\n", index, codec, dir); + + print_codec(codec); +} + +static void discover_sink_cb(struct bt_conn *conn, struct bt_codec *codec, struct bt_bap_ep *ep, + struct bt_bap_unicast_client_discover_params *params) +{ + static bool codec_found; + static bool endpoint_found; + + if (params->err != 0) { + FAIL("Discovery failed: %d\n", params->err); + return; + } + + if (codec != NULL) { + print_remote_codec(codec, params->num_caps, params->dir); + codec_found = true; + + return; + } + + if (ep != NULL) { + if (params->dir == BT_AUDIO_DIR_SINK) { + add_remote_sink(ep, params->num_eps); + endpoint_found = true; + } else { + FAIL("Invalid param dir: %u\n", params->dir); + } + + return; + } + + printk("Sink discover complete\n"); + + (void)memset(params, 0, sizeof(*params)); + + if (endpoint_found && codec_found) { + SET_FLAG(flag_sink_discovered); + } else { + FAIL("Did not discover endpoint and codec\n"); + } +} + static void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx) { printk("MTU exchanged\n"); @@ -157,6 +296,13 @@ static void init(void) return; } + for (size_t i = 0; i < ARRAY_SIZE(broadcast_streams); i++) { + bt_cap_stream_ops_register(&unicast_client_streams[i], + &unicast_stream_ops); + } + } + + if (IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SINK)) { (void)memset(broadcast_source_streams, 0, sizeof(broadcast_source_streams)); @@ -182,6 +328,23 @@ static void scan_and_connect(void) WAIT_FOR_FLAG(flag_connected); } +static void discover_sink(void) +{ + static struct bt_bap_unicast_client_discover_params params; + int err; + + params.func = discover_sink_cb; + params.dir = BT_AUDIO_DIR_SINK; + + err = bt_bap_unicast_client_discover(default_conn, ¶ms); + if (err != 0) { + printk("Failed to discover sink: %d\n", err); + return; + } + + WAIT_FOR_FLAG(flag_sink_discovered); +} + static void discover_cas(void) { int err; @@ -197,8 +360,59 @@ static void discover_cas(void) WAIT_FOR_FLAG(flag_discovered); } +static void unicast_group_create(struct bt_bap_unicast_group **out_unicast_group) +{ + struct bt_bap_unicast_group_stream_param group_stream_params; + struct bt_bap_unicast_group_stream_pair_param pair_params; + struct bt_bap_unicast_group_param group_param; + int err; + + group_stream_params.qos = &unicast_preset_16_2_1.qos; + group_stream_params.stream = &unicast_client_streams[0].bap_stream; + pair_params.tx_param = &group_stream_params; + pair_params.rx_param = NULL; + + group_param.packing = BT_ISO_PACKING_SEQUENTIAL; + group_param.params_count = 1; + group_param.params = &pair_params; + + err = bt_bap_unicast_group_create(&group_param, out_unicast_group); + if (err != 0) { + FAIL("Failed to create group: %d\n", err); + return; + } +} + +static void unicast_audio_start(struct bt_bap_unicast_group *unicast_group) +{ + struct bt_cap_unicast_audio_start_stream_param stream_param[1]; + struct bt_cap_unicast_audio_start_param param; + int err; + + param.type = BT_CAP_SET_TYPE_AD_HOC; + param.count = 1u; + param.stream_params = stream_param; + stream_param[0].member.member = default_conn; + stream_param[0].stream = &unicast_client_streams[0]; + stream_param[0].ep = unicast_sink_eps[0]; + stream_param[0].codec = &unicast_preset_16_2_1.codec; + stream_param[0].qos = &unicast_preset_16_2_1.qos; + + UNSET_FLAG(flag_started); + + err = bt_cap_initiator_unicast_audio_start(¶m, unicast_group); + if (err != 0) { + FAIL("Failed to start unicast audio: %d\n", err); + return; + } + + WAIT_FOR_FLAG(flag_started); +} + static void test_cap_initiator_unicast(void) { + struct bt_bap_unicast_group *unicast_group; + init(); scan_and_connect(); @@ -207,6 +421,12 @@ static void test_cap_initiator_unicast(void) discover_cas(); + discover_sink(); + + unicast_group_create(&unicast_group); + + unicast_audio_start(unicast_group); + PASS("CAP initiator unicast passed\n"); } From f7f69b6ff0b3f7d488a581fc7477f21469ee8696 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 18 Aug 2022 15:41:53 +0200 Subject: [PATCH 0511/1906] Bluetooth: Audio: Implement CAP unicast metadata update Implement the CAP unicast metadata update procedure. The procedure lets an application update the metadata of one or more CAP streams in a single function call, while also ensuring that the provided metadata follows the requirement from CAP. Signed-off-by: Emil Gydesen --- include/zephyr/bluetooth/audio/cap.h | 35 ++++-- subsys/bluetooth/audio/cap_initiator.c | 152 ++++++++++++++++++++++++- subsys/bluetooth/audio/cap_internal.h | 1 + subsys/bluetooth/audio/cap_stream.c | 4 + 4 files changed, 176 insertions(+), 16 deletions(-) diff --git a/include/zephyr/bluetooth/audio/cap.h b/include/zephyr/bluetooth/audio/cap.h index 9afa97a69902..c0ad10e936ad 100644 --- a/include/zephyr/bluetooth/audio/cap.h +++ b/include/zephyr/bluetooth/audio/cap.h @@ -88,15 +88,12 @@ struct bt_cap_initiator_cb { /** * @brief Callback for bt_cap_initiator_unicast_audio_update(). * - * @param unicast_group The unicast group pointer supplied to - * bt_cap_initiator_unicast_audio_update(). * @param err 0 if success, else BT_GATT_ERR() with a * specific ATT (BT_ATT_ERR_*) error code. * @param conn Pointer to the connection where the error * occurred. NULL if @p err is 0. */ - void (*unicast_update_complete)(struct bt_bap_unicast_group *unicast_group, - int err, struct bt_conn *conn); + void (*unicast_update_complete)(int err, struct bt_conn *conn); /** * @brief Callback for bt_cap_initiator_unicast_audio_stop(). @@ -199,6 +196,21 @@ struct bt_cap_unicast_audio_start_param { uint8_t packing; }; +struct bt_cap_unicast_audio_update_param { + /** @brief Stream for the @p member */ + struct bt_cap_stream *stream; + + /** The number of entries in @p meta. */ + size_t meta_count; + + /** @brief The new metadata. + * + * The metadata shall a list of CCIDs as + * well as a non-0 context bitfield. + */ + struct bt_codec_data *meta; +}; + /** * @brief Register Common Audio Profile callbacks * @@ -228,22 +240,21 @@ int bt_cap_initiator_unicast_audio_start(const struct bt_cap_unicast_audio_start struct bt_bap_unicast_group *unicast_group); /** - * @brief Update unicast audio streams for a unicast group. + * @brief Update unicast audio streams. + * + * This will update the metadata of one or more streams. * * @note @kconfig{CONFIG_BT_CAP_INITIATOR} and * @kconfig{CONFIG_BT_BAP_UNICAST_CLIENT} must be enabled for this function * to be enabled. * - * @param unicast_group The group of unicast devices to update. - * @param meta_count The number of entries in @p meta. - * @param meta The new metadata. The metadata shall contain a list of - * CCIDs as well as a non-0 context bitfield. + * @param params Array of update parameters. + * @param count The number of entries in @p params. * * @return 0 on success or negative error value on failure. */ -int bt_cap_initiator_unicast_audio_update(struct bt_bap_unicast_group *unicast_group, - uint8_t meta_count, - const struct bt_codec_data *meta); +int bt_cap_initiator_unicast_audio_update(const struct bt_cap_unicast_audio_update_param params[], + size_t count); /** * @brief Stop unicast audio streams for a unicast group. diff --git a/subsys/bluetooth/audio/cap_initiator.c b/subsys/bluetooth/audio/cap_initiator.c index d92a1dd090bb..4fe2ee6a6535 100644 --- a/subsys/bluetooth/audio/cap_initiator.c +++ b/subsys/bluetooth/audio/cap_initiator.c @@ -22,6 +22,8 @@ BUILD_ASSERT(sizeof(struct bt_bap_broadcast_source_create_param) == LOG_MODULE_REGISTER(bt_cap_initiator, CONFIG_BT_CAP_INITIATOR_LOG_LEVEL); +#include "common/bt_str.h" + static const struct bt_cap_initiator_cb *cap_cb; int bt_cap_initiator_register_cb(const struct bt_cap_initiator_cb *cb) @@ -46,11 +48,17 @@ static bool cap_initiator_valid_metadata(const struct bt_codec_data meta[], { bool stream_context_found; + LOG_DBG("meta %p count %zu", meta, meta_count); + /* Streaming Audio Context shall be present in CAP */ stream_context_found = false; for (size_t i = 0U; i < meta_count; i++) { const struct bt_data *metadata = &meta[i].data; + LOG_DBG("metadata %p type %u len %u data %s", + metadata, metadata->type, metadata->data_len, + bt_hex(metadata->data, metadata->data_len)); + if (metadata->type == BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT) { if (metadata->data_len != 2) { /* Stream context size */ return false; @@ -932,12 +940,148 @@ void bt_cap_initiator_started(struct bt_cap_stream *cap_stream) } } +static void cap_initiator_unicast_audio_update_complete(void) +{ + struct bt_conn *failed_conn; + int err; + + failed_conn = active_proc.failed_conn; + err = active_proc.err; + + (void)memset(&active_proc, 0, sizeof(active_proc)); + if (cap_cb != NULL && cap_cb->unicast_update_complete != NULL) { + cap_cb->unicast_update_complete(err, failed_conn); + } +} -int bt_cap_initiator_unicast_audio_update(struct bt_bap_unicast_group *unicast_group, - uint8_t meta_count, - const struct bt_codec_data *meta) +static bool can_update_metadata(const struct bt_bap_stream *bap_stream) { - return -ENOSYS; + struct bt_bap_ep_info ep_info; + int err; + + if (bap_stream->conn == NULL) { + return false; + } + + err = bt_bap_ep_get_info(bap_stream->ep, &ep_info); + if (err != 0) { + LOG_DBG("Failed to get endpoint info %p: %d", bap_stream, err); + + return false; + } + + return ep_info.state == BT_BAP_EP_STATE_ENABLING || + ep_info.state == BT_BAP_EP_STATE_STREAMING; +} + +int bt_cap_initiator_unicast_audio_update(const struct bt_cap_unicast_audio_update_param params[], + size_t count) +{ + if (atomic_test_bit(active_proc.flags, + CAP_UNICAST_PROC_STATE_ACTIVE)) { + LOG_DBG("A CAP procedure is already in progress"); + + return -EBUSY; + } + + for (size_t i = 0U; i < count; i++) { + CHECKIF(params[i].stream == NULL) { + LOG_DBG("params[%zu].stream is NULL", i); + + return -EINVAL; + } + + CHECKIF(params[i].stream->bap_stream.conn == NULL) { + LOG_DBG("params[%zu].stream->bap_stream.conn is NULL", i); + + return -EINVAL; + } + + CHECKIF(!cap_initiator_valid_metadata(params[i].meta, + params[i].meta_count)) { + LOG_DBG("params[%zu].meta is invalid", i); + + return -EINVAL; + } + + for (size_t j = 0U; j < i; j++) { + if (params[j].stream == params[i].stream) { + LOG_DBG("param.streams[%zu] is duplicated by param.streams[%zu]", + j, i); + return -EINVAL; + } + } + + if (!can_update_metadata(¶ms[i].stream->bap_stream)) { + LOG_DBG("params[%zu].stream is not in right state to be updated", i); + + return -EINVAL; + } + } + + atomic_set_bit(active_proc.flags, + CAP_UNICAST_PROC_STATE_ACTIVE); + active_proc.stream_cnt = count; + + /** TODO: If this is a CSIP set, then the order of the procedures may + * not match the order in the parameters, and the CSIP ordered access + * procedure should be used. + */ + for (size_t i = 0U; i < count; i++) { + int err; + + active_proc.streams[i] = params[i].stream; + + err = bt_bap_stream_metadata(¶ms[i].stream->bap_stream, params[i].meta, + params[i].meta_count); + if (err != 0) { + LOG_DBG("Failed to update metadata for stream %p: %d", + params[i].stream, err); + + active_proc.err = err; + active_proc.failed_conn = params[i].stream->bap_stream.conn; + + if (i > 0U) { + atomic_set_bit(active_proc.flags, + CAP_UNICAST_PROC_STATE_ABORTED); + } else { + (void)memset(&active_proc, 0, + sizeof(active_proc)); + } + + return err; + } + + active_proc.stream_initiated_cnt++; + } + + return 0; +} + +void bt_cap_initiator_metadata_updated(struct bt_cap_stream *cap_stream) +{ + if (!cap_stream_in_active_proc(cap_stream)) { + /* State change happened outside of a procedure; ignore */ + return; + } + + active_proc.stream_done_cnt++; + + LOG_DBG("Stream %p QoS metadata updated (%zu/%zu streams done)", cap_stream, + active_proc.stream_done_cnt, active_proc.stream_cnt); + + if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + /* Not yet finished, wait for all */ + return; + } else if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED)) { + if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { + cap_initiator_unicast_audio_update_complete(); + } + + return; + } + + cap_initiator_unicast_audio_update_complete(); } int bt_cap_initiator_unicast_audio_stop(struct bt_bap_unicast_group *unicast_group) diff --git a/subsys/bluetooth/audio/cap_internal.h b/subsys/bluetooth/audio/cap_internal.h index c3a5f8c4783b..a902321cb907 100644 --- a/subsys/bluetooth/audio/cap_internal.h +++ b/subsys/bluetooth/audio/cap_internal.h @@ -16,4 +16,5 @@ void bt_cap_initiator_codec_configured(struct bt_cap_stream *cap_stream); void bt_cap_initiator_qos_configured(struct bt_cap_stream *cap_stream); void bt_cap_initiator_enabled(struct bt_cap_stream *cap_stream); void bt_cap_initiator_started(struct bt_cap_stream *cap_stream); +void bt_cap_initiator_metadata_updated(struct bt_cap_stream *cap_stream); void bt_cap_stream_ops_register_bap(struct bt_cap_stream *cap_stream); diff --git a/subsys/bluetooth/audio/cap_stream.c b/subsys/bluetooth/audio/cap_stream.c index 0a458efa09d5..9e53d2dce5a3 100644 --- a/subsys/bluetooth/audio/cap_stream.c +++ b/subsys/bluetooth/audio/cap_stream.c @@ -65,6 +65,10 @@ static void cap_stream_metadata_updated_cb(struct bt_bap_stream *bap_stream) bap_stream); struct bt_bap_stream_ops *ops = cap_stream->ops; + if (IS_ENABLED(CONFIG_BT_CAP_INITIATOR)) { + bt_cap_initiator_metadata_updated(cap_stream); + } + if (ops != NULL && ops->metadata_updated != NULL) { ops->metadata_updated(bap_stream); } From 67925d397aa627778955a66fc491f8260d80e10a Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 18 Aug 2022 17:34:13 +0200 Subject: [PATCH 0512/1906] Bluetooth: Audio: Add CAP unicast update shell command Add shell command for the CAP unicast update procedure. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/shell/cap_initiator.c | 134 +++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/subsys/bluetooth/audio/shell/cap_initiator.c b/subsys/bluetooth/audio/shell/cap_initiator.c index c78d1715394b..5b0a6fc3db29 100644 --- a/subsys/bluetooth/audio/shell/cap_initiator.c +++ b/subsys/bluetooth/audio/shell/cap_initiator.c @@ -52,9 +52,20 @@ static void cap_unicast_start_complete_cb(struct bt_bap_unicast_group *unicast_g } } +static void unicast_update_complete_cb(int err, struct bt_conn *conn) +{ + if (err != 0) { + shell_error(ctx_shell, "Unicast update failed for conn %p (%d)", + conn, err); + } else { + shell_print(ctx_shell, "Unicast updated completed"); + } +} + static struct bt_cap_initiator_cb cbs = { .unicast_discovery_complete = cap_discover_cb, .unicast_start_complete = cap_unicast_start_complete_cb, + .unicast_update_complete = unicast_update_complete_cb }; static int cmd_cap_initiator_discover(const struct shell *sh, size_t argc, @@ -318,6 +329,124 @@ static int cmd_cap_initiator_unicast_start(const struct shell *sh, size_t argc, return 0; } +static int cmd_cap_initiator_unicast_list(const struct shell *sh, size_t argc, + char *argv[]) +{ + for (size_t i = 0U; i < ARRAY_SIZE(unicast_client_streams); i++) { + if (unicast_client_streams[i].stream.bap_stream.conn == NULL) { + break; + } + + shell_print(sh, "Stream #%zu: %p", i, &unicast_client_streams[i].stream); + } + return 0; +} + +static int cmd_cap_initiator_unicast_update(const struct shell *sh, size_t argc, + char *argv[]) +{ + struct bt_cap_unicast_audio_update_param params[CAP_UNICAST_CLIENT_STREAM_COUNT]; + size_t count; + int err = 0; + + if (default_conn == NULL) { + shell_error(sh, "Not connected"); + return -ENOEXEC; + } + + count = 0; + + if (argc == 2 && strcmp(argv[1], "all") == 0) { + for (size_t i = 0U; i < ARRAY_SIZE(unicast_client_streams); i++) { + struct bt_cap_stream *stream = &unicast_client_streams[i].stream; + struct cap_unicast_stream *uni_stream = + CONTAINER_OF(stream, struct cap_unicast_stream, stream); + struct bt_bap_ep_info ep_info; + + if (stream->bap_stream.conn == NULL) { + break; + } + + err = bt_bap_ep_get_info(stream->bap_stream.ep, &ep_info); + if (err != 0) { + shell_error(sh, "Failed to get endpoint info: %d", err); + + return -ENOEXEC; + } + + params[count].stream = stream; + + if (ep_info.dir == BT_AUDIO_DIR_SINK) { + cap_copy_preset(uni_stream, default_sink_preset); + } else { + cap_copy_preset(uni_stream, default_source_preset); + } + + params[count].meta = uni_stream->codec.meta; + params[count].meta_count = uni_stream->codec.meta_count; + + count++; + } + + } else { + for (size_t i = 1U; i < argc; i++) { + struct bt_cap_stream *stream = (void *)shell_strtoul(argv[i], 16, &err); + struct cap_unicast_stream *uni_stream = + CONTAINER_OF(stream, struct cap_unicast_stream, stream); + struct bt_bap_ep_info ep_info; + + if (err != 0) { + shell_error(sh, "Failed to parse stream argument %s: %d", + argv[i], err); + + return err; + } + + if (!PART_OF_ARRAY(unicast_client_streams, stream)) { + shell_error(sh, "Pointer %p is not a CAP stream pointer", + stream); + + return -ENOEXEC; + } + + err = bt_bap_ep_get_info(stream->bap_stream.ep, &ep_info); + if (err != 0) { + shell_error(sh, "Failed to get endpoint info: %d", err); + + return -ENOEXEC; + } + + params[count].stream = stream; + + if (ep_info.dir == BT_AUDIO_DIR_SINK) { + cap_copy_preset(uni_stream, default_sink_preset); + } else { + cap_copy_preset(uni_stream, default_source_preset); + } + + params[count].meta = uni_stream->codec.meta; + params[count].meta_count = uni_stream->codec.meta_count; + + count++; + } + } + + if (count == 0) { + shell_error(sh, "No streams to update"); + + return -ENOEXEC; + } + + shell_print(sh, "Updating %zu streams", count); + + err = bt_cap_initiator_unicast_audio_update(params, count); + if (err != 0) { + shell_print(sh, "Failed to update unicast audio: %d", err); + } + + return err; +} + #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ static int cmd_cap_initiator(const struct shell *sh, size_t argc, char **argv) @@ -341,6 +470,11 @@ SHELL_STATIC_SUBCMD_SET_CREATE(cap_initiator_cmds, "[sources (default 1)] " "[conns ( | all) (default 1)]", cmd_cap_initiator_unicast_start, 1, 7), + SHELL_CMD_ARG(unicast-list, NULL, "Unicast list streams", + cmd_cap_initiator_unicast_list, 1, 0), + SHELL_CMD_ARG(unicast-update, NULL, "Unicast Update ", + cmd_cap_initiator_unicast_update, 2, + CAP_UNICAST_CLIENT_STREAM_COUNT), #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ SHELL_SUBCMD_SET_END ); From 9ce647ba797f57a90307efdca294dc15e364b9d2 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 31 Aug 2022 09:48:35 +0200 Subject: [PATCH 0513/1906] Bluetooth: Audio: Implement CAP unicast stop procedure Implements the CAP unicast stop procedures, which is used to stop (either disable or release) multiple streams. Signed-off-by: Emil Gydesen --- include/zephyr/bluetooth/audio/cap.h | 6 ++ subsys/bluetooth/audio/Kconfig.cap | 5 + subsys/bluetooth/audio/cap_initiator.c | 132 ++++++++++++++++++++++++- subsys/bluetooth/audio/cap_internal.h | 1 + subsys/bluetooth/audio/cap_stream.c | 24 +++++ 5 files changed, 167 insertions(+), 1 deletion(-) diff --git a/include/zephyr/bluetooth/audio/cap.h b/include/zephyr/bluetooth/audio/cap.h index c0ad10e936ad..36c50e036ec8 100644 --- a/include/zephyr/bluetooth/audio/cap.h +++ b/include/zephyr/bluetooth/audio/cap.h @@ -98,6 +98,12 @@ struct bt_cap_initiator_cb { /** * @brief Callback for bt_cap_initiator_unicast_audio_stop(). * + * If @p err is 0, then @p unicast_group has been deleted and can no + * longer be used. + * + * If @p err is not 0 and @p conn is NULL, then the deletion of the + * @p unicast_group failed with @p err as the error. + * * @param unicast_group The unicast group pointer supplied to * bt_cap_initiator_unicast_audio_stop(). * @param err 0 if success, else BT_GATT_ERR() with a diff --git a/subsys/bluetooth/audio/Kconfig.cap b/subsys/bluetooth/audio/Kconfig.cap index 42f80df46d7b..9f71d61b720f 100644 --- a/subsys/bluetooth/audio/Kconfig.cap +++ b/subsys/bluetooth/audio/Kconfig.cap @@ -63,3 +63,8 @@ module = BT_CAP_INITIATOR legacy-debug-sym = BT_DEBUG_CAP_INITIATOR module-str = "Common Audio Profile Initiator" source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +parent-module = BT +module = BT_CAP_STREAM +module-str = "Common Audio Profile Stream" +source "subsys/logging/Kconfig.template.log_config_inherit" diff --git a/subsys/bluetooth/audio/cap_initiator.c b/subsys/bluetooth/audio/cap_initiator.c index 4fe2ee6a6535..db651bb3ab64 100644 --- a/subsys/bluetooth/audio/cap_initiator.c +++ b/subsys/bluetooth/audio/cap_initiator.c @@ -214,6 +214,7 @@ struct cap_unicast_proc { int err; struct bt_conn *failed_conn; struct bt_cap_stream *streams[CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT]; + struct bt_bap_unicast_group *unicast_group; }; struct cap_unicast_client { @@ -699,6 +700,8 @@ int bt_cap_initiator_unicast_audio_start(const struct bt_cap_unicast_audio_start return -EINVAL; } + active_proc.unicast_group = unicast_group; + return cap_initiator_unicast_audio_configure(param); } @@ -1084,9 +1087,136 @@ void bt_cap_initiator_metadata_updated(struct bt_cap_stream *cap_stream) cap_initiator_unicast_audio_update_complete(); } +static void cap_initiator_unicast_audio_stop_complete(void) +{ + struct bt_bap_unicast_group *unicast_group; + struct bt_conn *failed_conn; + int err; + + unicast_group = active_proc.unicast_group; + failed_conn = active_proc.failed_conn; + err = active_proc.err; + + (void)memset(&active_proc, 0, sizeof(active_proc)); + + if (cap_cb != NULL && cap_cb->unicast_stop_complete != NULL) { + cap_cb->unicast_stop_complete(unicast_group, err, failed_conn); + } +} + +static bool can_release(const struct bt_bap_stream *bap_stream) +{ + struct bt_bap_ep_info ep_info; + int err; + + if (bap_stream->conn == NULL) { + return false; + } + + err = bt_bap_ep_get_info(bap_stream->ep, &ep_info); + if (err != 0) { + LOG_DBG("Failed to get endpoint info %p: %d", bap_stream, err); + + return false; + } + + return ep_info.state != BT_BAP_EP_STATE_IDLE; +} + int bt_cap_initiator_unicast_audio_stop(struct bt_bap_unicast_group *unicast_group) { - return -ENOSYS; + struct bt_bap_stream *bap_stream; + size_t stream_cnt; + + if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ACTIVE)) { + LOG_DBG("A CAP procedure is already in progress"); + + return -EBUSY; + } + + CHECKIF(unicast_group == NULL) { + LOG_DBG("unicast_group is NULL"); + return -EINVAL; + } + + stream_cnt = 0U; + SYS_SLIST_FOR_EACH_CONTAINER(&unicast_group->streams, bap_stream, _node) { + if (can_release(bap_stream)) { + stream_cnt++; + } + } + + if (stream_cnt == 0U) { + LOG_DBG("All streams are already stopped"); + + return -EALREADY; + } + + atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ACTIVE); + active_proc.stream_cnt = stream_cnt; + active_proc.unicast_group = unicast_group; + + /** TODO: If this is a CSIP set, then the order of the procedures may + * not match the order in the parameters, and the CSIP ordered access + * procedure should be used. + */ + SYS_SLIST_FOR_EACH_CONTAINER(&unicast_group->streams, bap_stream, _node) { + struct bt_cap_stream *cap_stream = + CONTAINER_OF(bap_stream, struct bt_cap_stream, bap_stream); + int err; + + if (!can_release(bap_stream)) { + continue; + } + + active_proc.streams[active_proc.stream_initiated_cnt] = cap_stream; + + err = bt_bap_stream_release(bap_stream); + if (err != 0) { + LOG_DBG("Failed to stop bap_stream %p: %d", bap_stream, err); + + active_proc.err = err; + active_proc.failed_conn = bap_stream->conn; + + if (active_proc.stream_initiated_cnt > 0U) { + atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED); + } else { + (void)memset(&active_proc, 0, sizeof(active_proc)); + } + + return err; + } + + active_proc.stream_initiated_cnt++; + } + + return 0; +} + +void bt_cap_initiator_released(struct bt_cap_stream *cap_stream) +{ + if (!cap_stream_in_active_proc(cap_stream)) { + /* State change happened outside of a procedure; ignore */ + return; + } + + active_proc.stream_done_cnt++; + + LOG_DBG("Stream %p released (%zu/%zu streams done)", cap_stream, + active_proc.stream_done_cnt, active_proc.stream_cnt); + + if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + /* Not yet finished, wait for all */ + return; + } else if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED)) { + if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { + cap_initiator_unicast_audio_stop_complete(); + } + + return; + } + + cap_initiator_unicast_audio_stop_complete(); } #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ diff --git a/subsys/bluetooth/audio/cap_internal.h b/subsys/bluetooth/audio/cap_internal.h index a902321cb907..ac07f3f817c4 100644 --- a/subsys/bluetooth/audio/cap_internal.h +++ b/subsys/bluetooth/audio/cap_internal.h @@ -17,4 +17,5 @@ void bt_cap_initiator_qos_configured(struct bt_cap_stream *cap_stream); void bt_cap_initiator_enabled(struct bt_cap_stream *cap_stream); void bt_cap_initiator_started(struct bt_cap_stream *cap_stream); void bt_cap_initiator_metadata_updated(struct bt_cap_stream *cap_stream); +void bt_cap_initiator_released(struct bt_cap_stream *cap_stream); void bt_cap_stream_ops_register_bap(struct bt_cap_stream *cap_stream); diff --git a/subsys/bluetooth/audio/cap_stream.c b/subsys/bluetooth/audio/cap_stream.c index 9e53d2dce5a3..3e5a9f3fc8f7 100644 --- a/subsys/bluetooth/audio/cap_stream.c +++ b/subsys/bluetooth/audio/cap_stream.c @@ -8,6 +8,10 @@ #include "cap_internal.h" +#include + +LOG_MODULE_REGISTER(bt_cap_stream, CONFIG_BT_CAP_STREAM_LOG_LEVEL); + #if defined(CONFIG_BT_BAP_UNICAST) static void cap_stream_configured_cb(struct bt_bap_stream *bap_stream, const struct bt_codec_qos_pref *pref) @@ -17,6 +21,8 @@ static void cap_stream_configured_cb(struct bt_bap_stream *bap_stream, bap_stream); struct bt_bap_stream_ops *ops = cap_stream->ops; + LOG_DBG("%p", cap_stream); + if (IS_ENABLED(CONFIG_BT_CAP_INITIATOR)) { bt_cap_initiator_codec_configured(cap_stream); } @@ -33,6 +39,8 @@ static void cap_stream_qos_set_cb(struct bt_bap_stream *bap_stream) bap_stream); struct bt_bap_stream_ops *ops = cap_stream->ops; + LOG_DBG("%p", cap_stream); + if (IS_ENABLED(CONFIG_BT_CAP_INITIATOR)) { bt_cap_initiator_qos_configured(cap_stream); } @@ -49,6 +57,8 @@ static void cap_stream_enabled_cb(struct bt_bap_stream *bap_stream) bap_stream); struct bt_bap_stream_ops *ops = cap_stream->ops; + LOG_DBG("%p", cap_stream); + if (IS_ENABLED(CONFIG_BT_CAP_INITIATOR)) { bt_cap_initiator_enabled(cap_stream); } @@ -65,6 +75,8 @@ static void cap_stream_metadata_updated_cb(struct bt_bap_stream *bap_stream) bap_stream); struct bt_bap_stream_ops *ops = cap_stream->ops; + LOG_DBG("%p", cap_stream); + if (IS_ENABLED(CONFIG_BT_CAP_INITIATOR)) { bt_cap_initiator_metadata_updated(cap_stream); } @@ -81,6 +93,8 @@ static void cap_stream_disabled_cb(struct bt_bap_stream *bap_stream) bap_stream); struct bt_bap_stream_ops *ops = cap_stream->ops; + LOG_DBG("%p", cap_stream); + if (ops != NULL && ops->disabled != NULL) { ops->disabled(bap_stream); } @@ -93,6 +107,12 @@ static void cap_stream_released_cb(struct bt_bap_stream *bap_stream) bap_stream); struct bt_bap_stream_ops *ops = cap_stream->ops; + LOG_DBG("%p", cap_stream); + + if (IS_ENABLED(CONFIG_BT_CAP_INITIATOR)) { + bt_cap_initiator_released(cap_stream); + } + if (ops != NULL && ops->released != NULL) { ops->released(bap_stream); } @@ -107,6 +127,8 @@ static void cap_stream_started_cb(struct bt_bap_stream *bap_stream) bap_stream); struct bt_bap_stream_ops *ops = cap_stream->ops; + LOG_DBG("%p", cap_stream); + if (IS_ENABLED(CONFIG_BT_CAP_INITIATOR)) { bt_cap_initiator_started(cap_stream); } @@ -123,6 +145,8 @@ static void cap_stream_stopped_cb(struct bt_bap_stream *bap_stream, uint8_t reas bap_stream); struct bt_bap_stream_ops *ops = cap_stream->ops; + LOG_DBG("%p", cap_stream); + if (ops != NULL && ops->stopped != NULL) { ops->stopped(bap_stream, reason); } From 90537df38a69c549865ef0fd903601debaf2fb46 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 31 Aug 2022 14:43:13 +0200 Subject: [PATCH 0514/1906] Bluetooth: Audio: Add CAP unicast stop shell command Add shell command for the CAP unicast stop procedure. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/shell/cap_initiator.c | 53 +++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/audio/shell/cap_initiator.c b/subsys/bluetooth/audio/shell/cap_initiator.c index 5b0a6fc3db29..99b71ab181ae 100644 --- a/subsys/bluetooth/audio/shell/cap_initiator.c +++ b/subsys/bluetooth/audio/shell/cap_initiator.c @@ -62,10 +62,38 @@ static void unicast_update_complete_cb(int err, struct bt_conn *conn) } } +static void unicast_stop_complete_cb(struct bt_bap_unicast_group *unicast_group, int err, + struct bt_conn *conn) +{ + if (default_unicast_group != unicast_group) { + /* ignore */ + return; + } + + if (err != 0) { + shell_error(ctx_shell, + "Unicast stop failed for group %p and conn %p (%d)", + unicast_group, conn, err); + } else { + shell_print(ctx_shell, + "Unicast stopped for group %p completed", + default_unicast_group); + + err = bt_bap_unicast_group_delete(unicast_group); + if (err != 0) { + shell_error(ctx_shell, "Failed to delete unicast group %p: %d", + unicast_group, err); + } else { + default_unicast_group = NULL; + } + } +} + static struct bt_cap_initiator_cb cbs = { .unicast_discovery_complete = cap_discover_cb, .unicast_start_complete = cap_unicast_start_complete_cb, - .unicast_update_complete = unicast_update_complete_cb + .unicast_update_complete = unicast_update_complete_cb, + .unicast_stop_complete = unicast_stop_complete_cb, }; static int cmd_cap_initiator_discover(const struct shell *sh, size_t argc, @@ -447,6 +475,27 @@ static int cmd_cap_initiator_unicast_update(const struct shell *sh, size_t argc, return err; } +static int cmd_cap_initiator_unicast_stop(const struct shell *sh, size_t argc, + char *argv[]) +{ + int err = 0; + + if (default_conn == NULL) { + shell_error(sh, "Not connected"); + return -ENOEXEC; + } else if (default_unicast_group == NULL) { + shell_error(sh, "No unicast group starteds"); + return -ENOEXEC; + } + + err = bt_cap_initiator_unicast_audio_stop(default_unicast_group); + if (err != 0) { + shell_print(sh, "Failed to update unicast audio: %d", err); + } + + return err; +} + #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ static int cmd_cap_initiator(const struct shell *sh, size_t argc, char **argv) @@ -475,6 +524,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(cap_initiator_cmds, SHELL_CMD_ARG(unicast-update, NULL, "Unicast Update ", cmd_cap_initiator_unicast_update, 2, CAP_UNICAST_CLIENT_STREAM_COUNT), + SHELL_CMD_ARG(unicast-stop, NULL, "Unicast stop all streams", + cmd_cap_initiator_unicast_stop, 1, 0), #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ SHELL_SUBCMD_SET_END ); From e1356612a9f441384e3bec64e23711cc55bd13a8 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 23 Feb 2023 16:00:01 +0100 Subject: [PATCH 0515/1906] Tests: Bluetooth: Add CAP unicast update test Add test to run the CAP initiator unicast update API. Signed-off-by: Emil Gydesen --- .../bluetooth/audio/src/cap_initiator_test.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/bsim/bluetooth/audio/src/cap_initiator_test.c b/tests/bsim/bluetooth/audio/src/cap_initiator_test.c index 04589a6440e1..b96e87fdaa3d 100644 --- a/tests/bsim/bluetooth/audio/src/cap_initiator_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_initiator_test.c @@ -51,6 +51,7 @@ static K_SEM_DEFINE(sem_broadcast_stopped, 0U, ARRAY_SIZE(broadcast_streams)); CREATE_FLAG(flag_discovered); CREATE_FLAG(flag_started); +CREATE_FLAG(flag_updated); CREATE_FLAG(flag_mtu_exchanged); CREATE_FLAG(flag_sink_discovered); CREATE_FLAG(flag_broadcast_stopping); @@ -208,9 +209,21 @@ static void unicast_start_complete_cb(struct bt_bap_unicast_group *unicast_group SET_FLAG(flag_started); } +static void unicast_update_complete_cb(int err, struct bt_conn *conn) +{ + if (err != 0) { + FAIL("Failed to update (failing conn %p): %d", conn, err); + + return; + } + + SET_FLAG(flag_updated); +} + static struct bt_cap_initiator_cb cap_cb = { .unicast_discovery_complete = cap_discovery_complete_cb, .unicast_start_complete = unicast_start_complete_cb, + .unicast_update_complete = unicast_update_complete_cb, }; static void add_remote_sink(struct bt_bap_ep *ep, uint8_t index) @@ -409,6 +422,26 @@ static void unicast_audio_start(struct bt_bap_unicast_group *unicast_group) WAIT_FOR_FLAG(flag_started); } +static void unicast_audio_update(void) +{ + struct bt_cap_unicast_audio_update_param param; + int err; + + param.stream = &unicast_client_streams[0]; + param.meta = unicast_preset_16_2_1.codec.meta; + param.meta_count = unicast_preset_16_2_1.codec.meta_count; + + UNSET_FLAG(flag_updated); + + err = bt_cap_initiator_unicast_audio_update(¶m, 1); + if (err != 0) { + FAIL("Failed to update unicast audio: %d\n", err); + return; + } + + WAIT_FOR_FLAG(flag_updated); +} + static void test_cap_initiator_unicast(void) { struct bt_bap_unicast_group *unicast_group; @@ -427,6 +460,8 @@ static void test_cap_initiator_unicast(void) unicast_audio_start(unicast_group); + unicast_audio_update(); + PASS("CAP initiator unicast passed\n"); } From fe035609892516af277719783a3d5c473626572e Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Thu, 23 Feb 2023 16:06:14 +0100 Subject: [PATCH 0516/1906] Tests: Bluetooth: Add unicast stop to CAP tests Add test of the unicast stop procedure for the CAP initiator. Signed-off-by: Emil Gydesen --- .../bluetooth/audio/src/cap_initiator_test.c | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/bsim/bluetooth/audio/src/cap_initiator_test.c b/tests/bsim/bluetooth/audio/src/cap_initiator_test.c index b96e87fdaa3d..9ad48bbe2f1d 100644 --- a/tests/bsim/bluetooth/audio/src/cap_initiator_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_initiator_test.c @@ -52,6 +52,7 @@ static K_SEM_DEFINE(sem_broadcast_stopped, 0U, ARRAY_SIZE(broadcast_streams)); CREATE_FLAG(flag_discovered); CREATE_FLAG(flag_started); CREATE_FLAG(flag_updated); +CREATE_FLAG(flag_stopped); CREATE_FLAG(flag_mtu_exchanged); CREATE_FLAG(flag_sink_discovered); CREATE_FLAG(flag_broadcast_stopping); @@ -220,10 +221,23 @@ static void unicast_update_complete_cb(int err, struct bt_conn *conn) SET_FLAG(flag_updated); } +static void unicast_stop_complete_cb(struct bt_bap_unicast_group *unicast_group, int err, + struct bt_conn *conn) +{ + if (err != 0) { + FAIL("Failed to stop (failing conn %p): %d", conn, err); + + return; + } + + SET_FLAG(flag_stopped); +} + static struct bt_cap_initiator_cb cap_cb = { .unicast_discovery_complete = cap_discovery_complete_cb, .unicast_start_complete = unicast_start_complete_cb, .unicast_update_complete = unicast_update_complete_cb, + .unicast_stop_complete = unicast_stop_complete_cb, }; static void add_remote_sink(struct bt_bap_ep *ep, uint8_t index) @@ -442,6 +456,32 @@ static void unicast_audio_update(void) WAIT_FOR_FLAG(flag_updated); } +static void unicast_audio_stop(struct bt_bap_unicast_group *unicast_group) +{ + int err; + + UNSET_FLAG(flag_stopped); + + err = bt_cap_initiator_unicast_audio_stop(unicast_group); + if (err != 0) { + FAIL("Failed to start unicast audio: %d\n", err); + return; + } + + WAIT_FOR_FLAG(flag_stopped); +} + +static void unicast_group_delete(struct bt_bap_unicast_group *unicast_group) +{ + int err; + + err = bt_bap_unicast_group_delete(unicast_group); + if (err != 0) { + FAIL("Failed to create group: %d\n", err); + return; + } +} + static void test_cap_initiator_unicast(void) { struct bt_bap_unicast_group *unicast_group; @@ -462,6 +502,11 @@ static void test_cap_initiator_unicast(void) unicast_audio_update(); + unicast_audio_stop(unicast_group); + + unicast_group_delete(unicast_group); + unicast_group = NULL; + PASS("CAP initiator unicast passed\n"); } From 3ab925ecefaac28c66200fec27743be89bb06761 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Fri, 24 Feb 2023 17:32:15 +0100 Subject: [PATCH 0517/1906] Bluetooth: Audio: CAP Initiator handle unexpected ASE changes When performing the CAP Unicast Start procedure, the remote server(s) may change the state of the ASE before the procedure is complete. If the state change is unexpected, we stop the procedure and call the callback, and then the caller can decide what to do after that (presumably call the stop procedure for the streams that may be setup). Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/cap_initiator.c | 200 ++++++++++++++++++------- 1 file changed, 145 insertions(+), 55 deletions(-) diff --git a/subsys/bluetooth/audio/cap_initiator.c b/subsys/bluetooth/audio/cap_initiator.c index db651bb3ab64..c33fcbdb6b46 100644 --- a/subsys/bluetooth/audio/cap_initiator.c +++ b/subsys/bluetooth/audio/cap_initiator.c @@ -206,11 +206,22 @@ enum { CAP_UNICAST_PROC_STATE_FLAG_NUM, } cap_unicast_proc_state; +enum cap_unicast_subproc_type { + CAP_UNICAST_SUBPROC_TYPE_NONE, + CAP_UNICAST_SUBPROC_TYPE_CODEC_CONFIG, + CAP_UNICAST_SUBPROC_TYPE_QOS_CONFIG, + CAP_UNICAST_SUBPROC_TYPE_ENABLE, + CAP_UNICAST_SUBPROC_TYPE_START, + CAP_UNICAST_SUBPROC_TYPE_META_UPDATE, + CAP_UNICAST_SUBPROC_TYPE_RELEASE, +}; + struct cap_unicast_proc { - ATOMIC_DEFINE(flags, CAP_UNICAST_PROC_STATE_FLAG_NUM); + ATOMIC_DEFINE(proc_state_flags, CAP_UNICAST_PROC_STATE_FLAG_NUM); size_t stream_cnt; size_t stream_initiated_cnt; size_t stream_done_cnt; + enum cap_unicast_subproc_type subproc_type; int err; struct bt_conn *failed_conn; struct bt_cap_stream *streams[CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT]; @@ -229,6 +240,13 @@ static struct cap_unicast_client bt_cap_unicast_clients[CONFIG_BT_MAX_CONN]; static const struct bt_uuid *cas_uuid = BT_UUID_CAS; static struct cap_unicast_proc active_proc; +static void cap_set_subproc(enum cap_unicast_subproc_type subproc_type) +{ + active_proc.stream_done_cnt = 0U; + active_proc.stream_initiated_cnt = 0U; + active_proc.subproc_type = subproc_type; +} + static void cap_initiator_disconnected(struct bt_conn *conn, uint8_t reason) { struct cap_unicast_client *client; @@ -243,13 +261,16 @@ static void cap_initiator_disconnected(struct bt_conn *conn, uint8_t reason) /* Check if the disconnecting connection is part of the current active * procedure, and abort it if it is. */ - if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ACTIVE) && - !atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED)) { + if (atomic_test_bit(active_proc.proc_state_flags, + CAP_UNICAST_PROC_STATE_ACTIVE) && + !atomic_test_bit(active_proc.proc_state_flags, + CAP_UNICAST_PROC_STATE_ABORTED)) { for (size_t i = 0U; i < active_proc.stream_initiated_cnt; i++) { if (active_proc.streams[i]->bap_stream.conn == conn) { active_proc.err = -ENOTCONN; active_proc.failed_conn = conn; - atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED); + atomic_set_bit(active_proc.proc_state_flags, + CAP_UNICAST_PROC_STATE_ABORTED); break; } } @@ -458,7 +479,7 @@ int bt_cap_initiator_unicast_discover(struct bt_conn *conn) static bool cap_stream_in_active_proc(const struct bt_cap_stream *cap_stream) { - if (!atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ACTIVE)) { + if (!atomic_test_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ACTIVE)) { return false; } @@ -611,9 +632,11 @@ static int cap_initiator_unicast_audio_configure( /* Store the information about the active procedure so that we can * continue the procedure after each step */ - atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ACTIVE); + atomic_set_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ACTIVE); active_proc.stream_cnt = param->count; + cap_set_subproc(CAP_UNICAST_SUBPROC_TYPE_CODEC_CONFIG); + for (size_t i = 0U; i < param->count; i++) { struct bt_cap_unicast_audio_start_stream_param *stream_param = ¶m->stream_params[i]; @@ -649,7 +672,8 @@ static int cap_initiator_unicast_audio_configure( i, err); if (i > 0U) { - atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED); + atomic_set_bit(active_proc.proc_state_flags, + CAP_UNICAST_PROC_STATE_ABORTED); } else { (void)memset(&active_proc, 0, sizeof(active_proc)); } @@ -685,7 +709,7 @@ static void cap_initiator_unicast_audio_start_complete(void) int bt_cap_initiator_unicast_audio_start(const struct bt_cap_unicast_audio_start_param *param, struct bt_bap_unicast_group *unicast_group) { - if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ACTIVE)) { + if (atomic_test_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ACTIVE)) { LOG_DBG("A CAP procedure is already in progress"); return -EBUSY; @@ -716,15 +740,30 @@ void bt_cap_initiator_codec_configured(struct bt_cap_stream *cap_stream) return; } - active_proc.stream_done_cnt++; + if (active_proc.subproc_type == CAP_UNICAST_SUBPROC_TYPE_RELEASE) { + /* When releasing a stream, it may go into the codec configured state if + * the unicast server caches the configuration - We treat it as a release + */ + bt_cap_initiator_released(cap_stream); + return; + } else if (active_proc.subproc_type != CAP_UNICAST_SUBPROC_TYPE_CODEC_CONFIG) { + /* Unexpected callback - Abort */ + active_proc.err = -EBADMSG; + atomic_set_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED); + } else { + active_proc.stream_done_cnt++; - LOG_DBG("Stream %p configured (%zu/%zu streams done)", cap_stream, - active_proc.stream_done_cnt, active_proc.stream_cnt); + LOG_DBG("Stream %p configured (%zu/%zu streams done)", + cap_stream, active_proc.stream_done_cnt, + active_proc.stream_cnt); - if (active_proc.stream_done_cnt < active_proc.stream_cnt) { - /* Not yet finished, wait for all */ - return; - } else if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED)) { + if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + /* Not yet finished, wait for all */ + return; + } + } + + if (atomic_test_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED)) { if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { cap_initiator_unicast_audio_start_complete(); } @@ -763,8 +802,8 @@ void bt_cap_initiator_codec_configured(struct bt_cap_stream *cap_stream) * use the reference from the first stream */ unicast_group = (struct bt_bap_unicast_group *)active_proc.streams[0]->bap_stream.group; - active_proc.stream_done_cnt = 0U; - active_proc.stream_initiated_cnt = 0U; + cap_set_subproc(CAP_UNICAST_SUBPROC_TYPE_QOS_CONFIG); + for (size_t i = 0U; i < ARRAY_SIZE(conns); i++) { int err; @@ -787,7 +826,8 @@ void bt_cap_initiator_codec_configured(struct bt_cap_stream *cap_stream) if (i == 0U) { cap_initiator_unicast_audio_start_complete(); } else { - atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED); + atomic_set_bit(active_proc.proc_state_flags, + CAP_UNICAST_PROC_STATE_ABORTED); } return; @@ -804,15 +844,24 @@ void bt_cap_initiator_qos_configured(struct bt_cap_stream *cap_stream) return; } - active_proc.stream_done_cnt++; + if (active_proc.subproc_type != CAP_UNICAST_SUBPROC_TYPE_QOS_CONFIG) { + /* Unexpected callback - Abort */ + active_proc.err = -EBADMSG; + atomic_set_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED); + } else { + active_proc.stream_done_cnt++; - LOG_DBG("Stream %p QoS configured (%zu/%zu streams done)", cap_stream, - active_proc.stream_done_cnt, active_proc.stream_cnt); + LOG_DBG("Stream %p QoS configured (%zu/%zu streams done)", + cap_stream, active_proc.stream_done_cnt, + active_proc.stream_cnt); - if (active_proc.stream_done_cnt < active_proc.stream_cnt) { - /* Not yet finished, wait for all */ - return; - } else if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED)) { + if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + /* Not yet finished, wait for all */ + return; + } + } + + if (atomic_test_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED)) { if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { cap_initiator_unicast_audio_start_complete(); } @@ -820,8 +869,7 @@ void bt_cap_initiator_qos_configured(struct bt_cap_stream *cap_stream) return; } - active_proc.stream_done_cnt = 0U; - active_proc.stream_initiated_cnt = 0U; + cap_set_subproc(CAP_UNICAST_SUBPROC_TYPE_ENABLE); for (size_t i = 0U; i < active_proc.stream_cnt; i++) { struct bt_cap_stream *cap_stream = active_proc.streams[i]; @@ -845,7 +893,8 @@ void bt_cap_initiator_qos_configured(struct bt_cap_stream *cap_stream) if (i == 0U) { cap_initiator_unicast_audio_start_complete(); } else { - atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED); + atomic_set_bit(active_proc.proc_state_flags, + CAP_UNICAST_PROC_STATE_ABORTED); } return; @@ -863,15 +912,24 @@ void bt_cap_initiator_enabled(struct bt_cap_stream *cap_stream) return; } - active_proc.stream_done_cnt++; + if (active_proc.subproc_type != CAP_UNICAST_SUBPROC_TYPE_ENABLE) { + /* Unexpected callback - Abort */ + active_proc.err = -EBADMSG; + atomic_set_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED); + } else { + active_proc.stream_done_cnt++; - LOG_DBG("Stream %p enabled (%zu/%zu streams done)", cap_stream, active_proc.stream_done_cnt, - active_proc.stream_cnt); + LOG_DBG("Stream %p enabled (%zu/%zu streams done)", + cap_stream, active_proc.stream_done_cnt, + active_proc.stream_cnt); - if (active_proc.stream_done_cnt < active_proc.stream_cnt) { - /* Not yet finished, wait for all */ - return; - } else if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED)) { + if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + /* Not yet finished, wait for all */ + return; + } + } + + if (atomic_test_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED)) { if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { cap_initiator_unicast_audio_start_complete(); } @@ -879,8 +937,7 @@ void bt_cap_initiator_enabled(struct bt_cap_stream *cap_stream) return; } - active_proc.stream_done_cnt = 0U; - active_proc.stream_initiated_cnt = 0U; + cap_set_subproc(CAP_UNICAST_SUBPROC_TYPE_START); bap_stream = &active_proc.streams[0]->bap_stream; @@ -911,10 +968,17 @@ void bt_cap_initiator_started(struct bt_cap_stream *cap_stream) return; } - active_proc.stream_done_cnt++; + if (active_proc.subproc_type != CAP_UNICAST_SUBPROC_TYPE_START) { + /* Unexpected callback - Abort */ + active_proc.err = -EBADMSG; + atomic_set_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED); + } else { + active_proc.stream_done_cnt++; - LOG_DBG("Stream %p started (%zu/%zu streams done)", cap_stream, active_proc.stream_done_cnt, - active_proc.stream_cnt); + LOG_DBG("Stream %p started (%zu/%zu streams done)", + cap_stream, active_proc.stream_done_cnt, + active_proc.stream_cnt); + } /* Since bt_bap_stream_start connects the ISO, we can, at this point, * only do this one by one due to a restriction in the ISO layer @@ -980,7 +1044,7 @@ static bool can_update_metadata(const struct bt_bap_stream *bap_stream) int bt_cap_initiator_unicast_audio_update(const struct bt_cap_unicast_audio_update_param params[], size_t count) { - if (atomic_test_bit(active_proc.flags, + if (atomic_test_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ACTIVE)) { LOG_DBG("A CAP procedure is already in progress"); @@ -1022,10 +1086,12 @@ int bt_cap_initiator_unicast_audio_update(const struct bt_cap_unicast_audio_upda } } - atomic_set_bit(active_proc.flags, + atomic_set_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ACTIVE); active_proc.stream_cnt = count; + cap_set_subproc(CAP_UNICAST_SUBPROC_TYPE_META_UPDATE); + /** TODO: If this is a CSIP set, then the order of the procedures may * not match the order in the parameters, and the CSIP ordered access * procedure should be used. @@ -1045,7 +1111,7 @@ int bt_cap_initiator_unicast_audio_update(const struct bt_cap_unicast_audio_upda active_proc.failed_conn = params[i].stream->bap_stream.conn; if (i > 0U) { - atomic_set_bit(active_proc.flags, + atomic_set_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED); } else { (void)memset(&active_proc, 0, @@ -1068,15 +1134,24 @@ void bt_cap_initiator_metadata_updated(struct bt_cap_stream *cap_stream) return; } - active_proc.stream_done_cnt++; + if (active_proc.subproc_type != CAP_UNICAST_SUBPROC_TYPE_META_UPDATE) { + /* Unexpected callback - Abort */ + active_proc.err = -EBADMSG; + atomic_set_bit(active_proc.proc_state_flags, + CAP_UNICAST_PROC_STATE_ABORTED); + } else { + active_proc.stream_done_cnt++; - LOG_DBG("Stream %p QoS metadata updated (%zu/%zu streams done)", cap_stream, - active_proc.stream_done_cnt, active_proc.stream_cnt); + LOG_DBG("Stream %p QoS metadata updated (%zu/%zu streams done)", + cap_stream, active_proc.stream_done_cnt, + active_proc.stream_cnt); + } if (active_proc.stream_done_cnt < active_proc.stream_cnt) { /* Not yet finished, wait for all */ return; - } else if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED)) { + } else if (atomic_test_bit(active_proc.proc_state_flags, + CAP_UNICAST_PROC_STATE_ABORTED)) { if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { cap_initiator_unicast_audio_update_complete(); } @@ -1128,7 +1203,8 @@ int bt_cap_initiator_unicast_audio_stop(struct bt_bap_unicast_group *unicast_gro struct bt_bap_stream *bap_stream; size_t stream_cnt; - if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ACTIVE)) { + if (atomic_test_bit(active_proc.proc_state_flags, + CAP_UNICAST_PROC_STATE_ACTIVE)) { LOG_DBG("A CAP procedure is already in progress"); return -EBUSY; @@ -1152,10 +1228,13 @@ int bt_cap_initiator_unicast_audio_stop(struct bt_bap_unicast_group *unicast_gro return -EALREADY; } - atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ACTIVE); + atomic_set_bit(active_proc.proc_state_flags, + CAP_UNICAST_PROC_STATE_ACTIVE); active_proc.stream_cnt = stream_cnt; active_proc.unicast_group = unicast_group; + cap_set_subproc(CAP_UNICAST_SUBPROC_TYPE_RELEASE); + /** TODO: If this is a CSIP set, then the order of the procedures may * not match the order in the parameters, and the CSIP ordered access * procedure should be used. @@ -1179,9 +1258,11 @@ int bt_cap_initiator_unicast_audio_stop(struct bt_bap_unicast_group *unicast_gro active_proc.failed_conn = bap_stream->conn; if (active_proc.stream_initiated_cnt > 0U) { - atomic_set_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED); + atomic_set_bit(active_proc.proc_state_flags, + CAP_UNICAST_PROC_STATE_ABORTED); } else { - (void)memset(&active_proc, 0, sizeof(active_proc)); + (void)memset(&active_proc, 0, + sizeof(active_proc)); } return err; @@ -1200,15 +1281,24 @@ void bt_cap_initiator_released(struct bt_cap_stream *cap_stream) return; } - active_proc.stream_done_cnt++; + if (active_proc.subproc_type != CAP_UNICAST_SUBPROC_TYPE_RELEASE) { + /* Unexpected callback - Abort */ + active_proc.err = -EBADMSG; + atomic_set_bit(active_proc.proc_state_flags, + CAP_UNICAST_PROC_STATE_ABORTED); + } else { + active_proc.stream_done_cnt++; - LOG_DBG("Stream %p released (%zu/%zu streams done)", cap_stream, - active_proc.stream_done_cnt, active_proc.stream_cnt); + LOG_DBG("Stream %p released (%zu/%zu streams done)", + cap_stream, active_proc.stream_done_cnt, + active_proc.stream_cnt); + } if (active_proc.stream_done_cnt < active_proc.stream_cnt) { /* Not yet finished, wait for all */ return; - } else if (atomic_test_bit(active_proc.flags, CAP_UNICAST_PROC_STATE_ABORTED)) { + } else if (atomic_test_bit(active_proc.proc_state_flags, + CAP_UNICAST_PROC_STATE_ABORTED)) { if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { cap_initiator_unicast_audio_stop_complete(); } From 4eb92f2d29cb8302f0215fd8a5e083ad2fcf14f1 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 1 Mar 2023 16:23:05 +0100 Subject: [PATCH 0518/1906] doc: Bluetooth: Add CAP documentation Add documentation for CAP by adding the reference to the API document. Signed-off-by: Emil Gydesen --- doc/connectivity/bluetooth/api/cap.rst | 10 ++ doc/connectivity/bluetooth/api/index.rst | 2 + doc/connectivity/bluetooth/api/shell/cap.rst | 139 ++++++++++++++++++ .../bluetooth/bluetooth-audio-arch.rst | 24 ++- doc/connectivity/bluetooth/img/cap_proc.svg | 3 + doc/connectivity/bluetooth/img/gaf.svg | 2 +- doc/connectivity/bluetooth/img/zephyr_gaf.svg | 2 +- 7 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 doc/connectivity/bluetooth/api/cap.rst create mode 100644 doc/connectivity/bluetooth/api/shell/cap.rst create mode 100644 doc/connectivity/bluetooth/img/cap_proc.svg diff --git a/doc/connectivity/bluetooth/api/cap.rst b/doc/connectivity/bluetooth/api/cap.rst new file mode 100644 index 000000000000..2d6e5d4d6d6b --- /dev/null +++ b/doc/connectivity/bluetooth/api/cap.rst @@ -0,0 +1,10 @@ +.. _bluetooth_cap: + +Commmon Audio Profile +##################### + + +API Reference +************* + +.. doxygengroup:: bt_cap diff --git a/doc/connectivity/bluetooth/api/index.rst b/doc/connectivity/bluetooth/api/index.rst index bc3e8c61e7de..80713940ed04 100644 --- a/doc/connectivity/bluetooth/api/index.rst +++ b/doc/connectivity/bluetooth/api/index.rst @@ -9,6 +9,7 @@ Bluetooth APIs att.rst audio.rst bap.rst + cap.rst connection_mgmt.rst controller.rst coordinated_sets.rst @@ -31,6 +32,7 @@ Bluetooth APIs shell/bap.rst shell/bap_broadcast_assistant.rst shell/bap_scan_delegator.rst + shell/cap.rst shell/ccp.rst shell/csip.rst shell/iso.rst diff --git a/doc/connectivity/bluetooth/api/shell/cap.rst b/doc/connectivity/bluetooth/api/shell/cap.rst new file mode 100644 index 000000000000..74bf5bac72fc --- /dev/null +++ b/doc/connectivity/bluetooth/api/shell/cap.rst @@ -0,0 +1,139 @@ +Bluetooth: Common Audio Profile Shell +##################################### + +This document describes how to run the Common Audio Profile functionality. + +CAP Acceptor +************ + +The Acceptor will typically be a resource-constrained device, such as a headset, earbud or hearing +aid. The Acceptor can initialize a Coordinated Set Identification Service instance, if it is in +a pair with one or more other CAP Acceptors. + +Using the CAP Acceptor +====================== + +When the Bluetooth stack has been initialized (:code:`bt init`), the Acceptor can be registered by +by calling :code:`cap_acceptor init`, which will register the CAS and CSIS services, as well as +register callbacks. + +.. code-block:: console + + + cap_acceptor --help + cap_acceptor - Bluetooth CAP acceptor shell commands + Subcommands: + init :Initialize the service and register callbacks [size ] + [rank ] [not-lockable] [sirk ] + lock :Lock the set + release :Release the set [force] + print_sirk :Print the currently used SIRK + set_sirk_rsp :Set the response used in SIRK requests + +Besides initializing the CAS and the CSIS, there are also commands to lock and release the CSIS +instance, as well as printing and modifying access to the SIRK of the CSIS. + + +CAP Initiator +************* + +The Initiator will typically be a resource-rich device, such as a phone or PC. The Initiator can +discover CAP Acceptors's CAS and optional CSIS services. The CSIS service can be read to provide +information about other CAP Acceptors in the same Coordinated Set. The Initiator can execute +stream control procedures on sets of devices, either ad-hoc or Coordinated, and thus provides an +easy way to setup multiple streams on multiple devices at once. + +Using the CAP Initiator +======================= + +When the Bluetooth stack has been initialized (:code:`bt init`), the Initiator can discover CAS and +the optionally included CSIS instance by calling (:code:`cap_initiator discover`). + +.. code-block:: console + + cap_initiator --help + cap_initiator - Bluetooth CAP initiator shell commands + Subcommands: + discover :Discover CAS + unicast-start :Unicast Start [csip] [sinks (default 1)] [sources + (default 1)] [conns ( | all) (default 1)] + unicast-list :Unicast list streams + unicast-update :Unicast Update + unicast-stop :Unicast stop all streams + +Before being able to perform any stream operation, the device must also perform the +:code:`bap discover` operation to discover the ASEs and PAC records. The :code:`bap init` +command also needs to be called. + +When connected +-------------- + +Discovering CAS and CSIS on a device: + +.. code-block:: console + + uart:~$ cap_initiator discover + discovery completed with CSIS + + +Discovering ASEs and PAC records on a device: + +.. code-block:: console + + uart:~$ bap discover + conn 0x81cc260: #0: codec 0x81d5b28 dir 0x01 + codec 0x06 cid 0x0000 vid 0x0000 count 5 + data #0: type 0x01 len 2 + 00000000: f5 |. | + data #1: type 0x02 len 1 + data #2: type 0x03 len 1 + data #3: type 0x04 len 4 + 00000000: 1e 00 f0 |... | + data #4: type 0x05 len 1 + meta #0: type 0x01 len 2 + 00000000: 06 |. | + dir 1 loc 1 + snk ctx 6 src ctx 6 + Conn: 0x81cc260, Sink #0: ep 0x81e4248 + Conn: 0x81cc260, Sink #1: ep 0x81e46a8 + conn 0x81cc260: #0: codec 0x81d5f00 dir 0x02 + codec 0x06 cid 0x0000 vid 0x0000 count 5 + data #0: type 0x01 len 2 + 00000000: f5 |. | + data #1: type 0x02 len 1 + data #2: type 0x03 len 1 + data #3: type 0x04 len 4 + 00000000: 1e 00 f0 |... | + data #4: type 0x05 len 1 + meta #0: type 0x01 len 2 + 00000000: 06 |. | + dir 2 loc 1 + snk ctx 6 src ctx 6 + Conn: 0x81cc260, Source #0: ep 0x81e5c88 + Conn: 0x81cc260, Source #1: ep 0x81e60e8 + Discover complete: err 0 + +Both of the above commands should be done for each device that you want to use in the set. +To use multiple devices, simply connect to more and then use :code:`bt select` the device to execute +the commands on. + +Once all devices have been connected and the respective discovery commands have been called, the +:code:`cap_initiator unicast-start` command can be used to put one or more streams into the +streaming state. + +.. code-block:: console + + uart:~$ cap_initiator unicast-start sinks 1 sources 0 conns all + Setting up 1 sinks and 0 sources on each (2) conn + Starting 1 streams + Unicast start completed + +To stop all the streams that has been started, the :code:`cap_initiator unicast-stop` command can be +used. + + +.. code-block:: console + + uart:~$ cap_initiator unicast-stop + Unicast stopped for group 0x81e41c0 completed diff --git a/doc/connectivity/bluetooth/bluetooth-audio-arch.rst b/doc/connectivity/bluetooth/bluetooth-audio-arch.rst index 121169658dfb..6633aaf40cd3 100644 --- a/doc/connectivity/bluetooth/bluetooth-audio-arch.rst +++ b/doc/connectivity/bluetooth/bluetooth-audio-arch.rst @@ -43,10 +43,6 @@ GAF has been implemented in Zephyr with the following structure. Zephyr Generic Audio Framework -Currently CAP (and CAS) as well as CCP (and TBS) are not yet implemented in -Zephyr. Similarly the top-level profiles TMAP and HAP are also not yet -implemented. - Using the Bluetooth Audio Stack =============================== @@ -63,6 +59,26 @@ rendering/capture control profiles, or vice versa. Using the higher layer profiles will however typically provide a better user experience and better interoperability with other devices. +Common Audio Profile (CAP) +-------------------------- + +The Common Audio Profile introduces restrictions and requirements on the lower layer profiles. +The procedures in CAP works on one or more streams for one or more devices. Is it thus possible via +CAP to do a single function call to setup multiple streams across multiple devices. + +:numref:`bluetooth_audio_arch_cap_proc` shows a complete structure of the procedures in CAP and +how they correspond to procedures from the other profiles. The circles with I, A and C show whether +the procedure has active involvement or requirements from the CAP Initiator, CAP Accept and CAP +Commander roles respectively. + +.. _bluetooth_audio_arch_cap_proc: +.. figure:: img/cap_proc.svg + :align: center + :alt: Common Audio Profile Procedures + + Common Audio Profile Procedures + +The API reference for CAP can be found in :ref:`Common Audio Profile `. Stream Control (BAP) -------------------- diff --git a/doc/connectivity/bluetooth/img/cap_proc.svg b/doc/connectivity/bluetooth/img/cap_proc.svg new file mode 100644 index 000000000000..ef476096ad21 --- /dev/null +++ b/doc/connectivity/bluetooth/img/cap_proc.svg @@ -0,0 +1,3 @@ + + +
CSIP
CSIP
BAP
BAP
VCP
VCP
MICP
MICP
CCP
CCP
MCP
MCP
CAP
CAP
Unicast Audio Start
Unicast Audio Start
Unicast Audio Update
Unicast Audio Update
Unicast Audio Stop
Unicast Audio Stop
Broadcast Audio Start
Broadcast Audio Start
Broadcast Audio Update
Broadcast Audio Update
Broadcast Audio Stop
Broadcast Audio Stop
Change Volume
Change Volume
Change Volume Offset
Change Volume Offset
Change Volume Mute
Change Volume Mute
Microphone Mute State
Microphone Mute State
Change Microphone Gain Setting
Change Microphone Gain Setting
Find Content Control Service
Find Content Control Service
Discovery
Discovery
Discovery
Discovery
Coordinated Set Dsicovery
Coordinated Set Dsicovery
Set Members Discovery
Set Members Discovery
Lock Request
Lock Request
Lock Release
Lock Release
For all connected procedures for CSIP sets
F...
Ordered Access
Ordered Access
Audio Role Discovery
Audio Role Discovery
Audio Capability Discovery
Audio Capability Discovery
ASE ID Discovery
ASE ID Discovery
Supported Audio Context Discovery
Supported Audio Context Discovery
Available Audio Context Discovery
Available Audio Context Discovery
Codec Configuration
Codec Configuration
QoS Configuration
QoS Configuration
Enabling ASE
Enabling ASE
Updating unicast metadata
Updating unicast metadata
Disabling ASE
Disabling ASE
Releasing ASE
Releasing ASE
Configure broadcast source
Configure broadcast source
Reconfigure broadcast source
Reconfigure broadcast source
Broadcast audio establishment
Broadcast audio establishment
Broadcast Audio Metadata update
Broadcast Audio Metadata update
Broadcast Audio Disable
Broadcast Audio Disable
Broadcast Audio Release
Broadcast Audio Release
Broadcast Audio Synchronization
Broadcast Audio Synchronization
Configure volume state notifications
Configure volume state notifications
Read Volume State
Read Volume State
Configure Volume flag notifications
Configure Volume flag notifications
Read Volume Flags
Read Volume Flags
Set Initial Volume
Set Initial Volume
Relative Volume Down
Relative Volume Down
Relative Volume Up
Relative Volume Up
Unmute and Relative Volume Down
Unmute and Relative Volume Down
Unmute and Relative volume Up
Unmute and Relative volume Up
Set Absolute Volume
Set Absolute Volume
Unmute
Unmute
Mute
Mute
Configure volume offset state notifications
Configure volume offset state notifications
Read Volume Offset State
Read Volume Offset State
Configure Audio Locaiton notifications
Configure Audio Locaiton notifications
Read Audio Location
Read Audio Location
Set Volume Offset
Set Volume Offset
Configure audio output description notifications
Configure audio output description notifications
Read Audio Output Description
Read Audio Output Description
Set Audio Output Description
Set Audio Output Description
Configure Audio input state notifications
Configure Audio input state notifications
Read Audio Input State
Read Audio Input State
Read Gain Setting Properties
Read Gain Setting Properties
Read Audio Input Type
Read Audio Input Type
Configure Audio Input Status Notifications
Configure Audio Input Status Notifications
Read Audio Input Status
Read Audio Input Status
Set Gain Setting
Set Gain Setting
Unmute
Unmute
Mute
Mute
Set Manual Gain Mode
Set Manual Gain Mode
Set Automatic Gain Mode
Set Automatic Gain Mode
Configure Audio Input Description
Configure Audio Input Description
Read Audio Input Description
Read Audio Input Description
Set Audio Input Description
Set Audio Input Description
Discovery
Discovery
Configure mute notifications
Configure mute notifications
Read Mute State
Read Mute State
Set Mute State
Set Mute State
Configure Audio input state notifications
Configure Audio input state notifications
Read Audio Input State
Read Audio Input State
Read Gain Setting Properties
Read Gain Setting Properties
Read Audio Input Type
Read Audio Input Type
Configure Audio Input Status Notifications
Configure Audio Input Status Notifications
Read Audio Input Status
Read Audio Input Status
Set Gain Setting
Set Gain Setting
Unmute
Unmute
Mute
Mute
Set Manual Gain Mode
Set Manual Gain Mode
Set Automatic Gain Mode
Set Automatic Gain Mode
Configure Audio Input Description
Configure Audio Input Description
Read Audio Input Description
Read Audio Input Description
Set Audio Input Description
Set Audio Input Description
Discovery
Discovery
Discovery
Discovery
Read Bearer Provide Name
Read Bearer Provide Name
Read Bearer UCI
Read Bearer UCI
Read Bearer Technology
Read Bearer Technology
Read Bearer URI Schemes Supported List
Read Bearer URI Schemes Supported List
Read Bearer Signal Strength
Read Bearer Signal Strength
Read Bearer Signal Strength Reporting Interval
Read Bearer Signal Strength Reporting Interval
Set Bearer Signal Strength Reporting Interval
Set Bearer Signal Strength Reporting Interval
Reader List Current Calls
Reader List Current Calls
Read Content Control ID
Read Content Control ID
Read Incoming Clal Target Bearer URI
Read Incoming Clal Target Bearer URI
Read Status Flags
Read Status Flags
Read Call State
Read Call State
Answer Incoming Call
Answer Incoming Call
Terminate Call
Terminate Call
Move Call To Local Hold
Move Call To Local Hold
Move Locally Held Call To Active Call
Move Locally Held Call To Active Call
Move Locally And Remotely Held Call To Remotely Held Call
Move Locally And Remotely Held Call To Remotely Held Ca...
Originate Call
Originate Call
Join Calls
Join Calls
Read Call Control Point Optional Opcodes
Read Call Control Point Optional Opcodes
Read Incoming Call
Read Incoming Call
Read Call Friendly Name
Read Call Friendly Name
Discovery
Discovery
Read Media Information
Read Media Information
Read Media Player Icon Object Information
Read Media Player Icon Object Information
Read Track Title
Read Track Title
Set Absolute Track Position
Set Absolute Track Position
Set Relative Track Position 
Set Relative Track Position 
Read Playback Speed
Read Playback Speed
Read Track Duration
Read Track Duration
Read Track Position
Read Track Position
Set Playback Speed
Set Playback Speed
Read Seeking Speek
Read Seeking Speek
Read Current Track Segments Object Information
Read Current Track Segments Object Information
Read Current Track Object Information
Read Current Track Object Information
Set Current Track Object ID
Set Current Track Object ID
Read Next Track Object Information
Read Next Track Object Information
Set Next Track Object ID
Set Next Track Object ID
Track Discovery – Discover by Current Group Object ID
Track Discovery – Discover by Current Group Object ID
Set Current Group Object ID
Set Current Group Object ID
Read Parent Group Object Information
Read Parent Group Object Information
Read Playing Order
Read Playing Order
Set Playing Order
Set Playing Order
Read Playing Order Supported
Read Playing Order Supported
Read Media State
Read Media State
Play Current Track
Play Current Track
Pause Current Track
Pause Current Track
Fast Forward Fast Rewind
Fast Forward Fast Rewind
Stop Current Track
Stop Current Track
Move to Previous Segment
Move to Previous Segment
Move to Previous Segment
Move to Previous Segment
Move to Next Segment
Move to Next Segment
Move to First Segment
Move to First Segment
Move to Last Segment
Move to Last Segment
Move to Segment Number
Move to Segment Number
Move to Previous Track
Move to Previous Track
Move to Next Track
Move to Next Track
Move to First Track
Move to First Track
Move to Last Track
Move to Last Track
Move to Previous Group
Move to Previous Group
Move to Next Group
Move to Next Group
Move to First Group
Move to First Group
Move to Last Group
Move to Last Group
Move to Group Number
Move to Group Number
Read Media Control Point Opcodes Supported
Read Media Control Point Opcodes Supported
Search
Search
Read Content Control ID
Read Content Control ID
C
C
I
I
I
I
A
A
I
I
A
A
I
I
A
A
I
I
I
I
I
I
C
C
C
C
C
C
C
C
C
C
C
C
Broadcast Audio Reception Start
Broadcast Audio Reception Start
Adding Broadcast Sources
Adding Broadcast Sources
Modifying Broadcast Sources
Modifying Broadcast Sources
SyncInfo Transfer
SyncInfo Transfer
Setting Broadcast Code
Setting Broadcast Code
Removing Broadcast Sources
Removing Broadcast Sources
Broadcast Audio Reception Stop
Broadcast Audio Reception Stop
Broadcast to Unicast Audio Handover
Broadcast to Unicast Audio Handover
Unicast to Broadcast Audio Handover
Unicast to Broadcast Audio Handover
C
C
C
C
I
I
I
I
Distribute Broadcast_Code
Distribute Broadcast_Code
C
C
A
A
A
A
Text is not SVG - cannot display
\ No newline at end of file diff --git a/doc/connectivity/bluetooth/img/gaf.svg b/doc/connectivity/bluetooth/img/gaf.svg index 6c4cd2276f61..1cc2739b5342 100644 --- a/doc/connectivity/bluetooth/img/gaf.svg +++ b/doc/connectivity/bluetooth/img/gaf.svg @@ -1,4 +1,4 @@ -
Generic Audio Framework
















Generic Audio Framework...
Stream Control
Stream Control
Rendering and Capture Control
Rendering and Capture Control
Content Control
Content Control
BAP



BAP...
PACS
PACS
ACSS
ACSS
BASS
BASS
MCP


 
MCP...
MCS
MCS
CCP


 
CCP...
TBS
TBS
CSIP


 
CSIP...
CSIS
CSIS
MICP


 
MICP...
MICS
MICS
VCP


 
VCP...
VCS
VCS
VOCS
VOCS
AICS
AICS
CAP


 
CAP...
CAS
CAS
TMAP


 
TMAP...
TMAS
TMAS
HAP


 
HAP...
HAS
HAS
BAS
BAS
IAS
IAS
AICS
AICS
PBP



PBP...
Text is not SVG - cannot display
\ No newline at end of file +
Generic Audio Framework
















Generic Audio Framework...
Stream Control
Stream Control
Rendering and Capture Control
Rendering and Capture Control
Content Control
Content Control
BAP



BAP...
PACS
PACS
ACSS
ACSS
BASS
BASS
MCP


 
MCP...
MCS
MCS
CCP


 
CCP...
TBS
TBS
CSIP


 
CSIP...
CSIS
CSIS
MICP


 
MICP...
MICS
MICS
VCP


 
VCP...
VCS
VCS
VOCS
VOCS
AICS
AICS
CAP


 
CAP...
CAS
CAS
TMAP


 
TMAP...
TMAS
TMAS
HAP


 
HAP...
HAS
HAS
BAS
BAS
IAS
IAS
AICS
AICS
PBP



PBP...
Transition and Coordination Control
Transition and Coordination Contr...
Text is not SVG - cannot display
\ No newline at end of file diff --git a/doc/connectivity/bluetooth/img/zephyr_gaf.svg b/doc/connectivity/bluetooth/img/zephyr_gaf.svg index 2e1b8dcbb539..9eea9a77e7b1 100644 --- a/doc/connectivity/bluetooth/img/zephyr_gaf.svg +++ b/doc/connectivity/bluetooth/img/zephyr_gaf.svg @@ -1,4 +1,4 @@ -
Generic Audio Framework















Generic Audio Framework...
Content Control
Content Control
Media Proxy




 



 
Media Proxy...
Stream Control
Stream Control
Rendering and Capture Control
Rendering and Capture Control
BAP



BAP...
audio.h
audio.h
MCP


 
MCP...
mcs.h
mcs.h
CSIP


 
CSIP...
csip.h
csip.h
MICP


 
MICP...
micp.h
micp.h
VCP


 
VCP...
vcp.h
vcp.h
vocs.h
vocs.h
aics.h
aics.h
aics.h
aics.h
media_proxy.h
media_proxy.h
Text is not SVG - cannot display
+
Generic Audio Framework

























Generic Audio Framework...
Content Control
Content Control
Stream Control
Stream Control
Rendering and Capture Control
Rendering and Capture Control
BAP



BAP...
bap.h
bap.h
MCP


 
MCP...
mcs.h
mcs.h
MICP


 
MICP...
mics.h
mics.h
VCP


 
VCP...
vcs.h
vcs.h
vocs.h
vocs.h
aics.h
aics.h
aics.h
aics.h
Transition and Coordination Control
Transition and Coordination Cont...
CAP
CAP
cap.h
cap.h
CSIP


 
CSIP...
csis.h
csis.h
CCP
CCP
tbs.h
tbs.h
audio.h
audio.h
Text is not SVG - cannot display
\ No newline at end of file From 3186fce98eea32b2c59c07d7c6288991fd2cb316 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Mon, 6 Mar 2023 19:42:07 +0100 Subject: [PATCH 0519/1906] Bluetooth: Audio: Shell: Use same streams and group for BAP and CAP Use the same unicast streams and group for the BAP and CAP shell commands. This results in maximum flexibility, as well as the niceness of use from CAP, as well as less memory usage. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/shell/bap.c | 45 +++++++----------- subsys/bluetooth/audio/shell/cap_initiator.c | 49 +++++++++----------- subsys/bluetooth/shell/bt.h | 23 +++++++++ 3 files changed, 62 insertions(+), 55 deletions(-) diff --git a/subsys/bluetooth/audio/shell/bap.c b/subsys/bluetooth/audio/shell/bap.c index f836ead10ea1..537e4be1bdc0 100644 --- a/subsys/bluetooth/audio/shell/bap.c +++ b/subsys/bluetooth/audio/shell/bap.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "shell/bt.h" @@ -31,26 +32,15 @@ #define CONTEXT BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA #if defined(CONFIG_BT_BAP_UNICAST) -#define UNICAST_SERVER_STREAM_COUNT \ - COND_CODE_1(CONFIG_BT_ASCS, \ - (CONFIG_BT_ASCS_ASE_SNK_COUNT + CONFIG_BT_ASCS_ASE_SRC_COUNT), (0)) -#define UNICAST_CLIENT_STREAM_COUNT \ - COND_CODE_1(CONFIG_BT_BAP_UNICAST_CLIENT, \ - (CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT + \ - CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT), \ - (0)) - -static struct unicast_stream { - struct bt_bap_stream stream; - struct bt_codec codec; - struct bt_codec_qos qos; -} unicast_streams[UNICAST_SERVER_STREAM_COUNT + UNICAST_CLIENT_STREAM_COUNT]; + +struct unicast_stream unicast_streams[CONFIG_BT_MAX_CONN * + (UNICAST_SERVER_STREAM_COUNT + UNICAST_CLIENT_STREAM_COUNT)]; static const struct bt_codec_qos_pref qos_pref = BT_CODEC_QOS_PREF(true, BT_GAP_LE_PHY_2M, 0u, 60u, 20000u, 40000u, 20000u, 40000u); #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) -static struct bt_bap_unicast_group *default_unicast_group; +struct bt_bap_unicast_group *default_unicast_group; #if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 struct bt_bap_ep *snks[CONFIG_BT_MAX_CONN][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT]; #endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 */ @@ -423,9 +413,9 @@ static void set_unicast_stream(struct bt_bap_stream *stream) { default_stream = stream; - for (size_t i = 0; i < ARRAY_SIZE(unicast_streams); i++) { - if (stream == &unicast_streams[i].stream) { - shell_print(ctx_shell, "Default stream: %zu", i + 1); + for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) { + if (stream == &unicast_streams[i].stream.bap_stream) { + shell_print(ctx_shell, "Default stream: %u", i + 1); } } } @@ -457,7 +447,7 @@ static int cmd_select_unicast(const struct shell *sh, size_t argc, char *argv[]) return -ENOEXEC; } - stream = &unicast_streams[index].stream; + stream = &unicast_streams[index].stream.bap_stream; set_unicast_stream(stream); @@ -467,7 +457,7 @@ static int cmd_select_unicast(const struct shell *sh, size_t argc, char *argv[]) static struct bt_bap_stream *stream_alloc(void) { for (size_t i = 0; i < ARRAY_SIZE(unicast_streams); i++) { - struct bt_bap_stream *stream = &unicast_streams[i].stream; + struct bt_bap_stream *stream = &unicast_streams[i].stream.bap_stream; if (!stream->conn) { return stream; @@ -982,7 +972,7 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) conn_index = bt_conn_index(default_conn); if (default_stream == NULL) { - default_stream = &unicast_streams[0].stream; + default_stream = &unicast_streams[0].stream.bap_stream; } index = shell_strtoul(argv[2], 0, &err); @@ -1122,7 +1112,6 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) return -ENOEXEC; } } else { - err = bt_bap_stream_config(default_conn, default_stream, ep, &uni_stream->codec); if (err != 0) { shell_error(sh, "Unable to config stream: %d", err); @@ -1273,7 +1262,7 @@ static int create_unicast_group(const struct shell *sh) memset(&group_param, 0, sizeof(group_param)); for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) { - struct bt_bap_stream *stream = &unicast_streams[i].stream; + struct bt_bap_stream *stream = &unicast_streams[i].stream.bap_stream; struct unicast_stream *uni_stream = CONTAINER_OF(stream, struct unicast_stream, stream); @@ -1545,7 +1534,7 @@ static int cmd_list(const struct shell *sh, size_t argc, char *argv[]) shell_print(sh, "Configured Channels:"); for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) { - struct bt_bap_stream *stream = &unicast_streams[i].stream; + struct bt_bap_stream *stream = &unicast_streams[i].stream.bap_stream; if (stream->conn != NULL) { shell_print(sh, " %s#%u: stream %p dir 0x%02x group %p", @@ -1819,10 +1808,12 @@ static void stream_released_cb(struct bt_bap_stream *stream) bool group_can_be_deleted = true; for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) { - if (unicast_streams[i].stream.ep != NULL) { + const struct bt_bap_stream *stream = &unicast_streams[i].stream.bap_stream; + + if (stream->ep != NULL) { struct bt_bap_ep_info ep_info; - bt_bap_ep_get_info(unicast_streams[i].stream.ep, &ep_info); + bt_bap_ep_get_info(stream->ep, &ep_info); if (ep_info.state != BT_BAP_EP_STATE_CODEC_CONFIGURED && ep_info.state != BT_BAP_EP_STATE_IDLE) { @@ -2356,7 +2347,7 @@ static int cmd_init(const struct shell *sh, size_t argc, char *argv[]) #if defined(CONFIG_BT_BAP_UNICAST) for (i = 0; i < ARRAY_SIZE(unicast_streams); i++) { - bt_bap_stream_cb_register(&unicast_streams[i].stream, &stream_ops); + bt_bap_stream_cb_register(&unicast_streams[i].stream.bap_stream, &stream_ops); } #endif /* CONFIG_BT_BAP_UNICAST */ diff --git a/subsys/bluetooth/audio/shell/cap_initiator.c b/subsys/bluetooth/audio/shell/cap_initiator.c index 99b71ab181ae..56a5b8bebd19 100644 --- a/subsys/bluetooth/audio/shell/cap_initiator.c +++ b/subsys/bluetooth/audio/shell/cap_initiator.c @@ -18,16 +18,7 @@ #include "shell/bt.h" #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) -#define CAP_UNICAST_CLIENT_STREAM_COUNT (CONFIG_BT_MAX_CONN * \ - (CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT + \ - CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT)) - -static struct cap_unicast_stream { - struct bt_cap_stream stream; - struct bt_codec codec; - struct bt_codec_qos qos; -} unicast_client_streams[CAP_UNICAST_CLIENT_STREAM_COUNT]; -static struct bt_bap_unicast_group *default_unicast_group; +#define CAP_UNICAST_CLIENT_STREAM_COUNT ARRAY_SIZE(unicast_streams) static void cap_discover_cb(struct bt_conn *conn, int err, const struct bt_csip_set_coordinator_csis_inst *csis_inst) @@ -136,11 +127,12 @@ static void populate_connected_conns(struct bt_conn *conn, void *data) } } -static void cap_copy_preset(struct cap_unicast_stream *uni_stream, +static void cap_copy_preset(struct unicast_stream *uni_stream, const struct named_lc3_preset *name_preset) { memcpy(&uni_stream->qos, &name_preset->preset.qos, sizeof(uni_stream->qos)); - memcpy(&uni_stream->codec, &name_preset->preset.codec, sizeof(uni_stream->codec)); + memcpy(&uni_stream->codec, &name_preset->preset.codec, + sizeof(uni_stream->codec)); /* Need to update the `bt_data.data` pointer to the new value after copying the codec */ for (size_t i = 0U; i < ARRAY_SIZE(uni_stream->codec.data); i++) { @@ -256,9 +248,9 @@ static int cmd_cap_initiator_unicast_start(const struct shell *sh, size_t argc, conn_snk_cnt = sink_cnt; for (size_t i = 0U; i < sink_cnt; i++) { struct bt_cap_stream *stream = - &unicast_client_streams[start_param.count].stream; - struct cap_unicast_stream *uni_stream = - CONTAINER_OF(stream, struct cap_unicast_stream, stream); + &unicast_streams[start_param.count].stream; + struct unicast_stream *uni_stream = + CONTAINER_OF(stream, struct unicast_stream, stream); struct bt_bap_ep *snk_ep = snks[bt_conn_index(conn)][i]; if (snk_ep == NULL) { @@ -290,9 +282,9 @@ static int cmd_cap_initiator_unicast_start(const struct shell *sh, size_t argc, conn_src_cnt = source_cnt; for (size_t i = 0U; i < source_cnt; i++) { struct bt_cap_stream *stream = - &unicast_client_streams[start_param.count].stream; - struct cap_unicast_stream *uni_stream = - CONTAINER_OF(stream, struct cap_unicast_stream, stream); + &unicast_streams[start_param.count].stream; + struct unicast_stream *uni_stream = + CONTAINER_OF(stream, struct unicast_stream, stream); struct bt_bap_ep *src_ep = srcs[bt_conn_index(conn)][i]; if (src_ep == NULL) { @@ -360,12 +352,12 @@ static int cmd_cap_initiator_unicast_start(const struct shell *sh, size_t argc, static int cmd_cap_initiator_unicast_list(const struct shell *sh, size_t argc, char *argv[]) { - for (size_t i = 0U; i < ARRAY_SIZE(unicast_client_streams); i++) { - if (unicast_client_streams[i].stream.bap_stream.conn == NULL) { + for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) { + if (unicast_streams[i].stream.bap_stream.conn == NULL) { break; } - shell_print(sh, "Stream #%zu: %p", i, &unicast_client_streams[i].stream); + shell_print(sh, "Stream #%zu: %p", i, &unicast_streams[i].stream); } return 0; } @@ -385,10 +377,10 @@ static int cmd_cap_initiator_unicast_update(const struct shell *sh, size_t argc, count = 0; if (argc == 2 && strcmp(argv[1], "all") == 0) { - for (size_t i = 0U; i < ARRAY_SIZE(unicast_client_streams); i++) { - struct bt_cap_stream *stream = &unicast_client_streams[i].stream; - struct cap_unicast_stream *uni_stream = - CONTAINER_OF(stream, struct cap_unicast_stream, stream); + for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) { + struct bt_cap_stream *stream = &unicast_streams[i].stream; + struct unicast_stream *uni_stream = + CONTAINER_OF(stream, struct unicast_stream, stream); struct bt_bap_ep_info ep_info; if (stream->bap_stream.conn == NULL) { @@ -404,6 +396,7 @@ static int cmd_cap_initiator_unicast_update(const struct shell *sh, size_t argc, params[count].stream = stream; + if (ep_info.dir == BT_AUDIO_DIR_SINK) { cap_copy_preset(uni_stream, default_sink_preset); } else { @@ -419,8 +412,8 @@ static int cmd_cap_initiator_unicast_update(const struct shell *sh, size_t argc, } else { for (size_t i = 1U; i < argc; i++) { struct bt_cap_stream *stream = (void *)shell_strtoul(argv[i], 16, &err); - struct cap_unicast_stream *uni_stream = - CONTAINER_OF(stream, struct cap_unicast_stream, stream); + struct unicast_stream *uni_stream = + CONTAINER_OF(stream, struct unicast_stream, stream); struct bt_bap_ep_info ep_info; if (err != 0) { @@ -430,7 +423,7 @@ static int cmd_cap_initiator_unicast_update(const struct shell *sh, size_t argc, return err; } - if (!PART_OF_ARRAY(unicast_client_streams, stream)) { + if (!PART_OF_ARRAY(unicast_streams, stream)) { shell_error(sh, "Pointer %p is not a CAP stream pointer", stream); diff --git a/subsys/bluetooth/shell/bt.h b/subsys/bluetooth/shell/bt.h index 19b644159b0e..0a7fb1a0f66a 100644 --- a/subsys/bluetooth/shell/bt.h +++ b/subsys/bluetooth/shell/bt.h @@ -37,19 +37,42 @@ extern struct bt_le_per_adv_sync *per_adv_syncs[CONFIG_BT_PER_ADV_SYNC_MAX]; */ #include #include +#include struct named_lc3_preset { const char *name; struct bt_bap_lc3_preset preset; }; +#if defined(CONFIG_BT_BAP_UNICAST) + +#define UNICAST_SERVER_STREAM_COUNT \ + COND_CODE_1(CONFIG_BT_ASCS, (CONFIG_BT_ASCS_ASE_SNK_COUNT + CONFIG_BT_ASCS_ASE_SRC_COUNT), \ + (0)) +#define UNICAST_CLIENT_STREAM_COUNT \ + COND_CODE_1(CONFIG_BT_BAP_UNICAST_CLIENT, \ + (CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT + \ + CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT), \ + (0)) + +struct unicast_stream { + struct bt_cap_stream stream; + struct bt_codec codec; + struct bt_codec_qos qos; +}; + +extern struct unicast_stream unicast_streams[CONFIG_BT_MAX_CONN * (UNICAST_SERVER_STREAM_COUNT + + UNICAST_CLIENT_STREAM_COUNT)]; + #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) +extern struct bt_bap_unicast_group *default_unicast_group; extern struct bt_bap_ep *snks[CONFIG_BT_MAX_CONN][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT]; extern struct bt_bap_ep *srcs[CONFIG_BT_MAX_CONN][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT]; extern const struct named_lc3_preset *default_sink_preset; extern const struct named_lc3_preset *default_source_preset; #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ +#endif /* CONFIG_BT_BAP_UNICAST */ #endif /* CONFIG_BT_AUDIO */ void conn_addr_str(struct bt_conn *conn, char *addr, size_t len); From c97fa8fda33cf20f8ba8e54ae4f04a0cd3bb96d3 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 7 Mar 2023 14:10:55 +0100 Subject: [PATCH 0520/1906] Bluetooth: Audio: CAP initiator streamline procedure states Add new helper functions to increase readability and to ensure correctness when aborting procedures. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/cap_initiator.c | 165 +++++++++++++------------ 1 file changed, 85 insertions(+), 80 deletions(-) diff --git a/subsys/bluetooth/audio/cap_initiator.c b/subsys/bluetooth/audio/cap_initiator.c index c33fcbdb6b46..81839ab51efb 100644 --- a/subsys/bluetooth/audio/cap_initiator.c +++ b/subsys/bluetooth/audio/cap_initiator.c @@ -218,8 +218,11 @@ enum cap_unicast_subproc_type { struct cap_unicast_proc { ATOMIC_DEFINE(proc_state_flags, CAP_UNICAST_PROC_STATE_FLAG_NUM); + /* Total number of streams in the procedure*/ size_t stream_cnt; + /* Number of streams where a subprocedure have been started */ size_t stream_initiated_cnt; + /* Number of streams done with the procedure */ size_t stream_done_cnt; enum cap_unicast_subproc_type subproc_type; int err; @@ -247,6 +250,53 @@ static void cap_set_subproc(enum cap_unicast_subproc_type subproc_type) active_proc.subproc_type = subproc_type; } +static bool cap_proc_is_active(void) +{ + return atomic_test_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ACTIVE); +} + +static bool cap_proc_is_aborted(void) +{ + return atomic_test_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED); +} + +static bool cap_proc_all_streams_handled(void) +{ + return active_proc.stream_done_cnt == active_proc.stream_initiated_cnt; +} + +static bool cap_proc_is_done(void) +{ + return active_proc.stream_done_cnt == active_proc.stream_cnt; +} + +static void cap_abort_proc(struct bt_conn *conn, int err) +{ + if (cap_proc_is_aborted()) { + /* no-op */ + return; + } + + active_proc.err = err; + active_proc.failed_conn = conn; + atomic_set_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED); +} + +static bool cap_conn_in_active_proc(const struct bt_conn *conn) +{ + if (!cap_proc_is_active()) { + return false; + } + + for (size_t i = 0U; i < active_proc.stream_initiated_cnt; i++) { + if (active_proc.streams[i]->bap_stream.conn == conn) { + return true; + } + } + + return false; +} + static void cap_initiator_disconnected(struct bt_conn *conn, uint8_t reason) { struct cap_unicast_client *client; @@ -258,22 +308,8 @@ static void cap_initiator_disconnected(struct bt_conn *conn, uint8_t reason) } (void)memset(client, 0, sizeof(*client)); - /* Check if the disconnecting connection is part of the current active - * procedure, and abort it if it is. - */ - if (atomic_test_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ACTIVE) && - !atomic_test_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ABORTED)) { - for (size_t i = 0U; i < active_proc.stream_initiated_cnt; i++) { - if (active_proc.streams[i]->bap_stream.conn == conn) { - active_proc.err = -ENOTCONN; - active_proc.failed_conn = conn; - atomic_set_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ABORTED); - break; - } - } + if (cap_conn_in_active_proc(conn)) { + cap_abort_proc(conn, -ENOTCONN); } } @@ -479,7 +515,7 @@ int bt_cap_initiator_unicast_discover(struct bt_conn *conn) static bool cap_stream_in_active_proc(const struct bt_cap_stream *cap_stream) { - if (!atomic_test_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ACTIVE)) { + if (!cap_proc_is_active()) { return false; } @@ -672,8 +708,7 @@ static int cap_initiator_unicast_audio_configure( i, err); if (i > 0U) { - atomic_set_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ABORTED); + cap_abort_proc(bap_stream->conn, err); } else { (void)memset(&active_proc, 0, sizeof(active_proc)); } @@ -709,7 +744,7 @@ static void cap_initiator_unicast_audio_start_complete(void) int bt_cap_initiator_unicast_audio_start(const struct bt_cap_unicast_audio_start_param *param, struct bt_bap_unicast_group *unicast_group) { - if (atomic_test_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ACTIVE)) { + if (cap_proc_is_active()) { LOG_DBG("A CAP procedure is already in progress"); return -EBUSY; @@ -748,8 +783,7 @@ void bt_cap_initiator_codec_configured(struct bt_cap_stream *cap_stream) return; } else if (active_proc.subproc_type != CAP_UNICAST_SUBPROC_TYPE_CODEC_CONFIG) { /* Unexpected callback - Abort */ - active_proc.err = -EBADMSG; - atomic_set_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED); + cap_abort_proc(cap_stream->bap_stream.conn, -EBADMSG); } else { active_proc.stream_done_cnt++; @@ -757,14 +791,14 @@ void bt_cap_initiator_codec_configured(struct bt_cap_stream *cap_stream) cap_stream, active_proc.stream_done_cnt, active_proc.stream_cnt); - if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + if (!cap_proc_is_done()) { /* Not yet finished, wait for all */ return; } } - if (atomic_test_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED)) { - if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { + if (cap_proc_is_aborted()) { + if (cap_proc_all_streams_handled()) { cap_initiator_unicast_audio_start_complete(); } @@ -821,13 +855,9 @@ void bt_cap_initiator_codec_configured(struct bt_cap_stream *cap_stream) * If we have sent any requests over air, we will abort * once all sent requests has completed */ - active_proc.err = err; - active_proc.failed_conn = conns[i]; + cap_abort_proc(conns[i], err); if (i == 0U) { cap_initiator_unicast_audio_start_complete(); - } else { - atomic_set_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ABORTED); } return; @@ -846,8 +876,7 @@ void bt_cap_initiator_qos_configured(struct bt_cap_stream *cap_stream) if (active_proc.subproc_type != CAP_UNICAST_SUBPROC_TYPE_QOS_CONFIG) { /* Unexpected callback - Abort */ - active_proc.err = -EBADMSG; - atomic_set_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED); + cap_abort_proc(cap_stream->bap_stream.conn, -EBADMSG); } else { active_proc.stream_done_cnt++; @@ -855,14 +884,14 @@ void bt_cap_initiator_qos_configured(struct bt_cap_stream *cap_stream) cap_stream, active_proc.stream_done_cnt, active_proc.stream_cnt); - if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + if (!cap_proc_is_done()) { /* Not yet finished, wait for all */ return; } } - if (atomic_test_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED)) { - if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { + if (cap_proc_is_aborted()) { + if (cap_proc_all_streams_handled()) { cap_initiator_unicast_audio_start_complete(); } @@ -888,13 +917,9 @@ void bt_cap_initiator_qos_configured(struct bt_cap_stream *cap_stream) * If we have sent any requests over air, we will abort * once all sent requests has completed */ - active_proc.err = err; - active_proc.failed_conn = bap_stream->conn; + cap_abort_proc(bap_stream->conn, err); if (i == 0U) { cap_initiator_unicast_audio_start_complete(); - } else { - atomic_set_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ABORTED); } return; @@ -914,8 +939,7 @@ void bt_cap_initiator_enabled(struct bt_cap_stream *cap_stream) if (active_proc.subproc_type != CAP_UNICAST_SUBPROC_TYPE_ENABLE) { /* Unexpected callback - Abort */ - active_proc.err = -EBADMSG; - atomic_set_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED); + cap_abort_proc(cap_stream->bap_stream.conn, -EBADMSG); } else { active_proc.stream_done_cnt++; @@ -923,14 +947,14 @@ void bt_cap_initiator_enabled(struct bt_cap_stream *cap_stream) cap_stream, active_proc.stream_done_cnt, active_proc.stream_cnt); - if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + if (!cap_proc_is_done()) { /* Not yet finished, wait for all */ return; } } - if (atomic_test_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED)) { - if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { + if (cap_proc_is_aborted()) { + if (cap_proc_all_streams_handled()) { cap_initiator_unicast_audio_start_complete(); } @@ -953,8 +977,7 @@ void bt_cap_initiator_enabled(struct bt_cap_stream *cap_stream) * If we have sent any requests over air, we will abort * once all sent requests has completed */ - active_proc.err = err; - active_proc.failed_conn = bap_stream->conn; + cap_abort_proc(bap_stream->conn, err); cap_initiator_unicast_audio_start_complete(); return; @@ -970,8 +993,7 @@ void bt_cap_initiator_started(struct bt_cap_stream *cap_stream) if (active_proc.subproc_type != CAP_UNICAST_SUBPROC_TYPE_START) { /* Unexpected callback - Abort */ - active_proc.err = -EBADMSG; - atomic_set_bit(active_proc.proc_state_flags, CAP_UNICAST_PROC_STATE_ABORTED); + cap_abort_proc(cap_stream->bap_stream.conn, -EBADMSG); } else { active_proc.stream_done_cnt++; @@ -984,7 +1006,7 @@ void bt_cap_initiator_started(struct bt_cap_stream *cap_stream) * only do this one by one due to a restriction in the ISO layer * (maximum 1 outstanding ISO connection request at any one time). */ - if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + if (!cap_proc_is_done()) { struct bt_cap_stream *next = active_proc.streams[active_proc.stream_done_cnt]; struct bt_bap_stream *bap_stream = &next->bap_stream; int err; @@ -998,8 +1020,7 @@ void bt_cap_initiator_started(struct bt_cap_stream *cap_stream) * If we have sent any requests over air, we will abort * once all sent requests has completed */ - active_proc.err = err; - active_proc.failed_conn = bap_stream->conn; + cap_abort_proc(bap_stream->conn, err); cap_initiator_unicast_audio_start_complete(); } } else { @@ -1044,8 +1065,7 @@ static bool can_update_metadata(const struct bt_bap_stream *bap_stream) int bt_cap_initiator_unicast_audio_update(const struct bt_cap_unicast_audio_update_param params[], size_t count) { - if (atomic_test_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ACTIVE)) { + if (cap_proc_is_active()) { LOG_DBG("A CAP procedure is already in progress"); return -EBUSY; @@ -1107,12 +1127,8 @@ int bt_cap_initiator_unicast_audio_update(const struct bt_cap_unicast_audio_upda LOG_DBG("Failed to update metadata for stream %p: %d", params[i].stream, err); - active_proc.err = err; - active_proc.failed_conn = params[i].stream->bap_stream.conn; - if (i > 0U) { - atomic_set_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ABORTED); + cap_abort_proc(params[i].stream->bap_stream.conn, err); } else { (void)memset(&active_proc, 0, sizeof(active_proc)); @@ -1136,9 +1152,7 @@ void bt_cap_initiator_metadata_updated(struct bt_cap_stream *cap_stream) if (active_proc.subproc_type != CAP_UNICAST_SUBPROC_TYPE_META_UPDATE) { /* Unexpected callback - Abort */ - active_proc.err = -EBADMSG; - atomic_set_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ABORTED); + cap_abort_proc(cap_stream->bap_stream.conn, -EBADMSG); } else { active_proc.stream_done_cnt++; @@ -1147,12 +1161,11 @@ void bt_cap_initiator_metadata_updated(struct bt_cap_stream *cap_stream) active_proc.stream_cnt); } - if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + if (!cap_proc_is_done()) { /* Not yet finished, wait for all */ return; - } else if (atomic_test_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ABORTED)) { - if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { + } else if (cap_proc_is_aborted()) { + if (cap_proc_all_streams_handled()) { cap_initiator_unicast_audio_update_complete(); } @@ -1203,8 +1216,7 @@ int bt_cap_initiator_unicast_audio_stop(struct bt_bap_unicast_group *unicast_gro struct bt_bap_stream *bap_stream; size_t stream_cnt; - if (atomic_test_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ACTIVE)) { + if (cap_proc_is_active()) { LOG_DBG("A CAP procedure is already in progress"); return -EBUSY; @@ -1254,12 +1266,8 @@ int bt_cap_initiator_unicast_audio_stop(struct bt_bap_unicast_group *unicast_gro if (err != 0) { LOG_DBG("Failed to stop bap_stream %p: %d", bap_stream, err); - active_proc.err = err; - active_proc.failed_conn = bap_stream->conn; - if (active_proc.stream_initiated_cnt > 0U) { - atomic_set_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ABORTED); + cap_abort_proc(bap_stream->conn, err); } else { (void)memset(&active_proc, 0, sizeof(active_proc)); @@ -1283,9 +1291,7 @@ void bt_cap_initiator_released(struct bt_cap_stream *cap_stream) if (active_proc.subproc_type != CAP_UNICAST_SUBPROC_TYPE_RELEASE) { /* Unexpected callback - Abort */ - active_proc.err = -EBADMSG; - atomic_set_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ABORTED); + cap_abort_proc(cap_stream->bap_stream.conn, -EBADMSG); } else { active_proc.stream_done_cnt++; @@ -1294,12 +1300,11 @@ void bt_cap_initiator_released(struct bt_cap_stream *cap_stream) active_proc.stream_cnt); } - if (active_proc.stream_done_cnt < active_proc.stream_cnt) { + if (!cap_proc_is_done()) { /* Not yet finished, wait for all */ return; - } else if (atomic_test_bit(active_proc.proc_state_flags, - CAP_UNICAST_PROC_STATE_ABORTED)) { - if (active_proc.stream_done_cnt == active_proc.stream_initiated_cnt) { + } else if (cap_proc_is_aborted()) { + if (cap_proc_all_streams_handled()) { cap_initiator_unicast_audio_stop_complete(); } From a3d7fdafd661ccc42228f44fe2a5df097b1cb016 Mon Sep 17 00:00:00 2001 From: Joel Guittet Date: Wed, 15 Feb 2023 08:57:11 +0100 Subject: [PATCH 0521/1906] hawkbit: fix memory issue with mcuboot_img_header size Fix a memory issue when calling boot_read_bank_header the length should be the size of `struct mcuboot_img_header`. Fixes #54459. Signed-off-by: Joel Guittet --- subsys/mgmt/hawkbit/hawkbit_firmware.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/mgmt/hawkbit/hawkbit_firmware.c b/subsys/mgmt/hawkbit/hawkbit_firmware.c index acccc6081123..110d63c52098 100644 --- a/subsys/mgmt/hawkbit/hawkbit_firmware.c +++ b/subsys/mgmt/hawkbit/hawkbit_firmware.c @@ -13,7 +13,7 @@ bool hawkbit_get_firmware_version(char *version, int version_len) struct mcuboot_img_header header; if (boot_read_bank_header(FIXED_PARTITION_ID(slot0_partition), &header, - version_len) != 0) { + sizeof(header)) != 0) { return false; } From b6df4ec38878c758cc1a03ef116ab78ef1a0d445 Mon Sep 17 00:00:00 2001 From: Joel Guittet Date: Fri, 17 Mar 2023 22:08:52 +0100 Subject: [PATCH 0522/1906] hawkbit: check mcuboot header version Checking mcuboot header version prior to use the content of the header structure. Signed-off-by: Joel Guittet --- subsys/mgmt/hawkbit/hawkbit_firmware.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/subsys/mgmt/hawkbit/hawkbit_firmware.c b/subsys/mgmt/hawkbit/hawkbit_firmware.c index 110d63c52098..f070fa65ea53 100644 --- a/subsys/mgmt/hawkbit/hawkbit_firmware.c +++ b/subsys/mgmt/hawkbit/hawkbit_firmware.c @@ -17,6 +17,10 @@ bool hawkbit_get_firmware_version(char *version, int version_len) return false; } + if (header.mcuboot_version != 1) { + return false; + } + snprintk(version, version_len, "%d.%d.%d", header.h.v1.sem_ver.major, header.h.v1.sem_ver.minor, header.h.v1.sem_ver.revision); From 4d57f641935c609a99e95c7dbfcbaea1da5e7583 Mon Sep 17 00:00:00 2001 From: Jeppe Odgaard Date: Mon, 6 Mar 2023 11:45:13 +0100 Subject: [PATCH 0523/1906] drivers: watchdog: Add TI TPS382x driver Add support for the TI TPS382x series. The IC has an input pin which should be toggled by the processor and a output pin which should be connected to the RESET input of the processor. The timeout is not configurable. This device can be used by devices which does not have any internal hardware watchdog device. Signed-off-by: Jeppe Odgaard --- drivers/watchdog/CMakeLists.txt | 1 + drivers/watchdog/Kconfig | 2 + drivers/watchdog/Kconfig.ti_tps382x | 12 ++++ drivers/watchdog/wdt_ti_tps382x.c | 96 +++++++++++++++++++++++++++ dts/bindings/watchdog/ti,tps382x.yaml | 31 +++++++++ 5 files changed, 142 insertions(+) create mode 100644 drivers/watchdog/Kconfig.ti_tps382x create mode 100644 drivers/watchdog/wdt_ti_tps382x.c create mode 100644 dts/bindings/watchdog/ti,tps382x.yaml diff --git a/drivers/watchdog/CMakeLists.txt b/drivers/watchdog/CMakeLists.txt index 913b4091e5b3..e4f25a098e04 100644 --- a/drivers/watchdog/CMakeLists.txt +++ b/drivers/watchdog/CMakeLists.txt @@ -30,6 +30,7 @@ zephyr_library_sources_ifdef(CONFIG_WDT_XEC wdt_mchp_xec.c) zephyr_library_sources_ifdef(CONFIG_WDT_COUNTER wdt_counter.c) zephyr_library_sources_ifdef(CONFIG_WDT_NXP_S32 wdt_nxp_s32.c) zephyr_library_sources_ifdef(CONFIG_WDT_SMARTBOND wdt_smartbond.c) +zephyr_library_sources_ifdef(CONFIG_WDT_TI_TPS382X wdt_ti_tps382x.c) zephyr_library_sources_ifdef(CONFIG_WDT_DW wdt_dw.c) diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 9bc18b28669c..05f43080445e 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -98,4 +98,6 @@ source "drivers/watchdog/Kconfig.dw" source "drivers/watchdog/Kconfig.smartbond" +source "drivers/watchdog/Kconfig.ti_tps382x" + endif # WATCHDOG diff --git a/drivers/watchdog/Kconfig.ti_tps382x b/drivers/watchdog/Kconfig.ti_tps382x new file mode 100644 index 000000000000..9ff0400af3ef --- /dev/null +++ b/drivers/watchdog/Kconfig.ti_tps382x @@ -0,0 +1,12 @@ +# Copyright (c) 2023 Prevas A/S +# +# SPDX-License-Identifier: Apache-2.0 + +config WDT_TI_TPS382X + bool "External TI TPS382x Watchdog (WDT) Driver" + default y + depends on DT_HAS_TI_TPS382X_ENABLED + depends on GPIO + help + Enable WDT driver for TI TPS382x. This is an external IC and requires + a GPIO connection from the processor. diff --git a/drivers/watchdog/wdt_ti_tps382x.c b/drivers/watchdog/wdt_ti_tps382x.c new file mode 100644 index 000000000000..c9e94310c3f5 --- /dev/null +++ b/drivers/watchdog/wdt_ti_tps382x.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023, Prevas A/S + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT ti_tps382x + +#include +#include +#include +#include + +LOG_MODULE_REGISTER(wdt_ti_tps382x, CONFIG_WDT_LOG_LEVEL); + +struct ti_tps382x_config { + struct gpio_dt_spec wdi_gpio; + int timeout; +}; + +static int ti_tps382x_init(const struct device *dev) +{ + const struct ti_tps382x_config *config = dev->config; + + if (!gpio_is_ready_dt(&config->wdi_gpio)) { + LOG_ERR("WDI gpio not ready"); + return -ENODEV; + } + + return 0; +} + +static int ti_tps382x_setup(const struct device *dev, uint8_t options) +{ + const struct ti_tps382x_config *config = dev->config; + + return gpio_pin_configure_dt(&config->wdi_gpio, GPIO_OUTPUT); +} + +static int ti_tps382x_disable(const struct device *dev) +{ + const struct ti_tps382x_config *config = dev->config; + + /* The watchdog timer can be disabled by disconnecting the WDI pin from + * the system. Do this by changing the gpio to an input (tri-state). + */ + return gpio_pin_configure_dt(&config->wdi_gpio, GPIO_INPUT); +} + +static int ti_tps382x_install_timeout(const struct device *dev, + const struct wdt_timeout_cfg *cfg) +{ + const struct ti_tps382x_config *config = dev->config; + + if (cfg->window.max != config->timeout) { + LOG_ERR("Upper limit of watchdog timeout must be %d not %u", + config->timeout, cfg->window.max); + return -EINVAL; + } else if (cfg->window.min != 0) { + LOG_ERR("Window timeouts not supported"); + return -EINVAL; + } else if (cfg->callback != NULL) { + LOG_ERR("Callbacks not supported"); + return -EINVAL; + } + + return 0; +} + +static int ti_tps382x_feed(const struct device *dev, int channel_id) +{ + const struct ti_tps382x_config *config = dev->config; + + return gpio_pin_toggle_dt(&config->wdi_gpio); +} + +static const struct wdt_driver_api ti_tps382x_api = { + .setup = ti_tps382x_setup, + .disable = ti_tps382x_disable, + .install_timeout = ti_tps382x_install_timeout, + .feed = ti_tps382x_feed, +}; + +#define WDT_TI_TPS382X_INIT(n) \ + static const struct ti_tps382x_config ti_tps382x_##n##config = { \ + .wdi_gpio = GPIO_DT_SPEC_INST_GET(n, wdi_gpios), \ + .timeout = DT_INST_PROP(n, timeout_period), \ + }; \ + \ + DEVICE_DT_INST_DEFINE( \ + n, ti_tps382x_init, NULL, NULL, &ti_tps382x_##n##config, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ + &ti_tps382x_api \ + ); + +DT_INST_FOREACH_STATUS_OKAY(WDT_TI_TPS382X_INIT); diff --git a/dts/bindings/watchdog/ti,tps382x.yaml b/dts/bindings/watchdog/ti,tps382x.yaml new file mode 100644 index 000000000000..c6f1e1cd1c64 --- /dev/null +++ b/dts/bindings/watchdog/ti,tps382x.yaml @@ -0,0 +1,31 @@ +# Copyright (c) 2023, Prevas A/S + +description: Watchdog driver for external IC (TPS382x) + +compatible: "ti,tps382x" + +include: base.yaml + +properties: + wdi-gpios: + type: phandle-array + required: true + description: + WDI gpio. If WDI remains high or low longer than the timeout period, + then reset is triggered. The reset has a typical delay time of 200 ms for + TPS3823/4/8, TPS3823A. The timer clears when reset is asserted or + when WDI sees a rising edge or a falling edge. If unused, the WDI + connection must be high impedance to prevent it from causing a reset + event. + + timeout-period: + type: int + default: 1600 + description: + Time-out period in milliseconds. Typical for TPS3823/4/8 and TPS3823A is + 1.6 seconds but minimum is 0.9. To avoid false positive watchdog reset + the watchdog should be kicked within the minimum timeout period. The kick + interval also needs to compensate for MCU clock tolerances which means it + should be kicked with an interval less than 0.9 seconds. If this device + is used as fallback for the task watchdog this can be achieved by setting + e.g. TASK_WDT_MIN_TIMEOUT to 850 and TASK_WDT_HW_FALLBACK_DELAY to 750. From 052a057dafdc07611ef400aeb1efd9b6f3560139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Barna=C5=9B?= Date: Tue, 7 Mar 2023 15:48:49 +0100 Subject: [PATCH 0524/1906] usbc: fix assignment of value for PDOs count in get_snk_cap callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of assigning the address of value to the temporary function parameter, there should be a dereference of the pointer and assignment of PDOs count to it. Signed-off-by: Michał Barnaś --- samples/subsys/usb_c/sink/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/subsys/usb_c/sink/src/main.c b/samples/subsys/usb_c/sink/src/main.c index fad7cc88bad5..5071dba66809 100644 --- a/samples/subsys/usb_c/sink/src/main.c +++ b/samples/subsys/usb_c/sink/src/main.c @@ -178,7 +178,7 @@ static int port1_policy_cb_get_snk_cap(const struct device *dev, struct port1_data_t *dpm_data = usbc_get_dpm_data(dev); *pdos = dpm_data->snk_caps; - num_pdos = &dpm_data->snk_cap_cnt; + *num_pdos = dpm_data->snk_cap_cnt; return 0; } From 53082e8ce5f09e6ca49fbb0d2c953bb0ae962719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hidalgo=20Mu=C3=B1oz=20de=20Rivera?= Date: Wed, 8 Mar 2023 21:03:43 +0100 Subject: [PATCH 0525/1906] samples: Updated README for thermometer sample MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated README.txt to .rst format. Signed-off-by: Alejandro Hidalgo Muñoz de Rivera --- samples/sensor/thermometer/README.rst | 31 +++++++++++++++++++++++++++ samples/sensor/thermometer/README.txt | 22 ------------------- 2 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 samples/sensor/thermometer/README.rst delete mode 100644 samples/sensor/thermometer/README.txt diff --git a/samples/sensor/thermometer/README.rst b/samples/sensor/thermometer/README.rst new file mode 100644 index 000000000000..07f3f3a07d77 --- /dev/null +++ b/samples/sensor/thermometer/README.rst @@ -0,0 +1,31 @@ +.. _thermometer-samples: + +Thermometer sample +################## + +Overview +******** + +A simple thermometer example, which writes the temperature to the console once per second. + +Building and Running +******************** + +It can be built and executed on bbc_microbit as follows: + +.. zephyr-app-commands:: + :zephyr-app: samples/sensor/thermometer + :board: bbc_microbit + :goals: build + :compact: + +Sample Output +============= + +.. code-block:: console + + Thermometer Example! + arm temp device is 0x20000184, name is TEMP_0 + Temperature is 29.5C + Temperature is 29.5C + Temperature is 29.5C diff --git a/samples/sensor/thermometer/README.txt b/samples/sensor/thermometer/README.txt deleted file mode 100644 index aca938a1acf0..000000000000 --- a/samples/sensor/thermometer/README.txt +++ /dev/null @@ -1,22 +0,0 @@ -Title: Thermometer - -Description: - -A simple thermometer example - --------------------------------------------------------------------------------- - -Building and Running Project: - -This project writes the temperature to the console once per second. -It can be built and executed on bbc_microbit as follows: - - make - -Sample Output: - -Thermometer Example! -arm temp device is 0x20000184, name is TEMP_0 -Temperature is 29.5C -Temperature is 29.5C -Temperature is 29.5C From fa7170b846d6c9ce518c181bb8e5c78963bc3953 Mon Sep 17 00:00:00 2001 From: Nicolas VINCENT Date: Mon, 13 Mar 2023 15:17:29 +0100 Subject: [PATCH 0526/1906] west: runner: Use --verify and --verify-only with openocd and hex files the options --verify and --verify-only where only used when flashing elf files and were ignored for flashing hex files for example when using openocd runner. The command to verify the image is now dependant on the presence of --verify or --verify-only, and the load command is not executed if --verify-only is provided. Signed-off-by: Nicolas VINCENT --- scripts/west_commands/runners/openocd.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/west_commands/runners/openocd.py b/scripts/west_commands/runners/openocd.py index 6f4db76db2e0..0346935a22e5 100644 --- a/scripts/west_commands/runners/openocd.py +++ b/scripts/west_commands/runners/openocd.py @@ -253,12 +253,20 @@ def do_flash(self, **kwargs): post_verify_cmd.append("-c") post_verify_cmd.append(i) + load_image = [] + if not self.do_verify_only: + load_image = ['-c', self.reset_halt_cmd, + '-c', self.load_cmd + ' ' + hex_name] + + verify_image = [] + if self.do_verify or self.do_verify_only: + verify_image = ['-c', self.reset_halt_cmd, + '-c', self.verify_cmd + ' ' + hex_name] + cmd = (self.openocd_cmd + self.serial + self.cfg_cmd + pre_init_cmd + self.init_arg + self.targets_arg + - pre_load_cmd + ['-c', self.reset_halt_cmd, - '-c', self.load_cmd + ' ' + hex_name, - '-c', self.reset_halt_cmd] + - ['-c', self.verify_cmd + ' ' + hex_name] + + pre_load_cmd + load_image + + verify_image + post_verify_cmd + ['-c', 'reset run', '-c', 'shutdown']) From 0548584d4d863c852135c434e07a497bcb46557e Mon Sep 17 00:00:00 2001 From: Marc Desvaux Date: Fri, 10 Mar 2023 14:08:18 +0100 Subject: [PATCH 0527/1906] drivers: gpio/exti: stm32: Use st,stm32g0-exti compatible remove all #ifdef CONFIG_SOC_SERIES_STM32xx before to add a st,stm32g0-exti compatible added to the matching targets: C0/G0/U5/L5/MP1: Signed-off-by: Marc Desvaux --- drivers/gpio/gpio_stm32.c | 22 ++++--------------- .../interrupt_controller/intc_exti_stm32.c | 12 ++-------- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/drivers/gpio/gpio_stm32.c b/drivers/gpio/gpio_stm32.c index 8edb92d54a73..672b47b2f587 100644 --- a/drivers/gpio/gpio_stm32.c +++ b/drivers/gpio/gpio_stm32.c @@ -297,12 +297,7 @@ static inline uint32_t gpio_stm32_pin_to_exti_line(int pin) #if defined(CONFIG_SOC_SERIES_STM32L0X) || \ defined(CONFIG_SOC_SERIES_STM32F0X) return ((pin % 4 * 4) << 16) | (pin / 4); -#elif defined(CONFIG_SOC_SERIES_STM32MP1X) - return (((pin * 8) % 32) << 16) | (pin / 4); -#elif defined(CONFIG_SOC_SERIES_STM32C0X) || \ - defined(CONFIG_SOC_SERIES_STM32G0X) || \ - defined(CONFIG_SOC_SERIES_STM32L5X) || \ - defined(CONFIG_SOC_SERIES_STM32U5X) +#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32g0_exti) return ((pin & 0x3) << (16 + 3)) | (pin >> 2); #else return (0xF << ((pin % 4 * 4) + 16)) | (pin / 4); @@ -328,12 +323,8 @@ static void gpio_stm32_set_exti_source(int port, int pin) #ifdef CONFIG_SOC_SERIES_STM32F1X LL_GPIO_AF_SetEXTISource(port, line); -#elif CONFIG_SOC_SERIES_STM32MP1X - LL_EXTI_SetEXTISource(port, line); -#elif defined(CONFIG_SOC_SERIES_STM32C0X) || \ - defined(CONFIG_SOC_SERIES_STM32G0X) || \ - defined(CONFIG_SOC_SERIES_STM32L5X) || \ - defined(CONFIG_SOC_SERIES_STM32U5X) + +#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32g0_exti) LL_EXTI_SetEXTISource(port, line); #else LL_SYSCFG_SetEXTISource(port, line); @@ -348,12 +339,7 @@ static int gpio_stm32_get_exti_source(int pin) #ifdef CONFIG_SOC_SERIES_STM32F1X port = LL_GPIO_AF_GetEXTISource(line); -#elif CONFIG_SOC_SERIES_STM32MP1X - port = LL_EXTI_GetEXTISource(line); -#elif defined(CONFIG_SOC_SERIES_STM32C0X) || \ - defined(CONFIG_SOC_SERIES_STM32G0X) || \ - defined(CONFIG_SOC_SERIES_STM32L5X) || \ - defined(CONFIG_SOC_SERIES_STM32U5X) +#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32g0_exti) port = LL_EXTI_GetEXTISource(line); #else port = LL_SYSCFG_GetEXTISource(line); diff --git a/drivers/interrupt_controller/intc_exti_stm32.c b/drivers/interrupt_controller/intc_exti_stm32.c index bb3f5d88c665..85e7f26d6753 100644 --- a/drivers/interrupt_controller/intc_exti_stm32.c +++ b/drivers/interrupt_controller/intc_exti_stm32.c @@ -94,11 +94,7 @@ void stm32_exti_disable(int line) static inline int stm32_exti_is_pending(int line) { if (line < 32) { -#if defined(CONFIG_SOC_SERIES_STM32MP1X) || \ - defined(CONFIG_SOC_SERIES_STM32C0X) || \ - defined(CONFIG_SOC_SERIES_STM32G0X) || \ - defined(CONFIG_SOC_SERIES_STM32L5X) || \ - defined(CONFIG_SOC_SERIES_STM32U5X) +#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32g0_exti) return (LL_EXTI_IsActiveRisingFlag_0_31(1 << line) || LL_EXTI_IsActiveFallingFlag_0_31(1 << line)); #elif defined(CONFIG_SOC_SERIES_STM32H7X) && defined(CONFIG_CPU_CORTEX_M4) @@ -120,11 +116,7 @@ static inline int stm32_exti_is_pending(int line) static inline void stm32_exti_clear_pending(int line) { if (line < 32) { -#if defined(CONFIG_SOC_SERIES_STM32MP1X) || \ - defined(CONFIG_SOC_SERIES_STM32C0X) || \ - defined(CONFIG_SOC_SERIES_STM32G0X) || \ - defined(CONFIG_SOC_SERIES_STM32L5X) || \ - defined(CONFIG_SOC_SERIES_STM32U5X) +#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32g0_exti) LL_EXTI_ClearRisingFlag_0_31(1 << line); LL_EXTI_ClearFallingFlag_0_31(1 << line); #elif defined(CONFIG_SOC_SERIES_STM32H7X) && defined(CONFIG_CPU_CORTEX_M4) From 7e11533657185b9c03dbe953d55863f334a2e65e Mon Sep 17 00:00:00 2001 From: Marc Desvaux Date: Thu, 16 Mar 2023 09:54:55 +0100 Subject: [PATCH 0528/1906] dts: arm: st: Introduce a st,stm32g0-exti compatible Introduce a st,stm32g0-exti compatible added to the matching targets: C0/G0/U5/L5/MP1: Signed-off-by: Marc Desvaux --- dts/arm/st/c0/stm32c0.dtsi | 2 +- dts/arm/st/g0/stm32g0.dtsi | 2 +- dts/arm/st/l5/stm32l5.dtsi | 2 +- dts/arm/st/mp1/stm32mp157.dtsi | 2 +- dts/arm/st/u5/stm32u5.dtsi | 2 +- .../interrupt-controller/st,stm32g0-exti.yaml | 12 ++++++++++++ 6 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 dts/bindings/interrupt-controller/st,stm32g0-exti.yaml diff --git a/dts/arm/st/c0/stm32c0.dtsi b/dts/arm/st/c0/stm32c0.dtsi index d0fed77abf84..ee4057dd0405 100644 --- a/dts/arm/st/c0/stm32c0.dtsi +++ b/dts/arm/st/c0/stm32c0.dtsi @@ -93,7 +93,7 @@ }; exti: interrupt-controller@40021800 { - compatible = "st,stm32-exti"; + compatible = "st,stm32g0-exti", "st,stm32-exti"; interrupt-controller; #interrupt-cells = <1>; reg = <0x40021800 0x400>; diff --git a/dts/arm/st/g0/stm32g0.dtsi b/dts/arm/st/g0/stm32g0.dtsi index 8e930eb15cef..90444c6683dd 100644 --- a/dts/arm/st/g0/stm32g0.dtsi +++ b/dts/arm/st/g0/stm32g0.dtsi @@ -123,7 +123,7 @@ }; exti: interrupt-controller@40021800 { - compatible = "st,stm32-exti"; + compatible = "st,stm32g0-exti", "st,stm32-exti"; interrupt-controller; #interrupt-cells = <1>; reg = <0x40021800 0x400>; diff --git a/dts/arm/st/l5/stm32l5.dtsi b/dts/arm/st/l5/stm32l5.dtsi index 3f7deca28a30..075896668eaf 100644 --- a/dts/arm/st/l5/stm32l5.dtsi +++ b/dts/arm/st/l5/stm32l5.dtsi @@ -155,7 +155,7 @@ }; exti: interrupt-controller@4000f400 { - compatible = "st,stm32-exti"; + compatible = "st,stm32g0-exti", "st,stm32-exti"; interrupt-controller; #interrupt-cells = <1>; reg = <0x4000f400 0x400>; diff --git a/dts/arm/st/mp1/stm32mp157.dtsi b/dts/arm/st/mp1/stm32mp157.dtsi index 647ebbf7ac2f..95f02eff6e09 100644 --- a/dts/arm/st/mp1/stm32mp157.dtsi +++ b/dts/arm/st/mp1/stm32mp157.dtsi @@ -52,7 +52,7 @@ }; exti: interrupt-controller@5000d000 { - compatible = "st,stm32-exti"; + compatible = "st,stm32g0-exti", "st,stm32-exti"; interrupt-controller; #interrupt-cells = <1>; reg = <0x5000d000 0x400>; diff --git a/dts/arm/st/u5/stm32u5.dtsi b/dts/arm/st/u5/stm32u5.dtsi index 790e3864bff4..54142f7634e5 100644 --- a/dts/arm/st/u5/stm32u5.dtsi +++ b/dts/arm/st/u5/stm32u5.dtsi @@ -167,7 +167,7 @@ }; exti: interrupt-controller@46022000 { - compatible = "st,stm32-exti"; + compatible = "st,stm32g0-exti", "st,stm32-exti"; interrupt-controller; #interrupt-cells = <1>; reg = <0x46022000 0x400>; diff --git a/dts/bindings/interrupt-controller/st,stm32g0-exti.yaml b/dts/bindings/interrupt-controller/st,stm32g0-exti.yaml new file mode 100644 index 000000000000..55d860cb9980 --- /dev/null +++ b/dts/bindings/interrupt-controller/st,stm32g0-exti.yaml @@ -0,0 +1,12 @@ +# Copyright (c) 2023, STMicroelectronics + +# SPDX-License-Identifier: Apache-2.0 + +description: | + STM32 controller + This compatible stands for all interrupt-controller blocks for the + STM32C0/G0/L5/mp/u5. + +compatible: "st,stm32g0-exti" + +include: st,stm32-exti.yaml From 14bd189f007334bab3f3754be3a29a17838e3a3b Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Fri, 17 Mar 2023 13:33:19 +0100 Subject: [PATCH 0529/1906] Bluetooth: ascs: Fix ASE Codec Config PDU length validation This moves ASE Control PDU length validation before request processing. If the PDU length is not as expected, the operation shall be considered as invalid. Thus shall be rejected. ASCS_v1.0; 5 ASE Control operations "A client-initiated ASE Control operation shall be defined as an invalid length operation if the total length of all parameters written by the client is not equal to the total length of all fixed parameters plus the length of any variable length parameters for that operation" Fixes: #55747 Fixes: #55748 Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 60 ++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 21ced50f73c6..86f319d98c5e 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -1564,46 +1564,70 @@ int bt_ascs_config_ase(struct bt_conn *conn, struct bt_bap_stream *stream, struc return 0; } -static ssize_t ascs_config(struct bt_ascs *ascs, struct net_buf_simple *buf) +static bool codec_config_len_is_valid(struct net_buf_simple *buf) { const struct bt_ascs_config_op *req; - const struct bt_ascs_config *cfg; - int i; + struct net_buf_simple_state state; + + net_buf_simple_save(buf, &state); if (buf->len < sizeof(*req)) { LOG_WRN("Malformed ASE Config"); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); + return false; } req = net_buf_simple_pull_mem(buf, sizeof(*req)); - - LOG_DBG("num_ases %u", req->num_ases); - if (req->num_ases < 1) { LOG_WRN("Number_of_ASEs parameter value is less than 1"); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - } else if (buf->len < req->num_ases * sizeof(*cfg)) { - LOG_WRN("Malformed ASE Config: len %u < %zu", buf->len, - req->num_ases * sizeof(*cfg)); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); + return false; } - for (i = 0; i < req->num_ases; i++) { - struct bt_ascs_ase *ase; - int err; + for (uint8_t i = 0U; i < req->num_ases; i++) { + const struct bt_ascs_config *cfg; if (buf->len < sizeof(*cfg)) { LOG_WRN("Malformed ASE Config: len %u < %zu", buf->len, sizeof(*cfg)); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); + return false; } cfg = net_buf_simple_pull_mem(buf, sizeof(*cfg)); - if (buf->len < cfg->cc_len) { LOG_WRN("Malformed ASE Codec Config len %u != %u", buf->len, cfg->cc_len); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); + return false; } + (void)net_buf_simple_pull_mem(buf, cfg->cc_len); + } + + if (buf->len > 0) { + LOG_WRN("Unexpected data"); + return false; + } + + net_buf_simple_restore(buf, &state); + + return true; +} + +static ssize_t ascs_config(struct bt_ascs *ascs, struct net_buf_simple *buf) +{ + const struct bt_ascs_config_op *req; + const struct bt_ascs_config *cfg; + + if (!codec_config_len_is_valid(buf)) { + return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); + } + + req = net_buf_simple_pull_mem(buf, sizeof(*req)); + + LOG_DBG("num_ases %u", req->num_ases); + + for (uint8_t i = 0; i < req->num_ases; i++) { + struct bt_ascs_ase *ase; + int err; + + cfg = net_buf_simple_pull_mem(buf, sizeof(*cfg)); + LOG_DBG("ase 0x%02x cc_len %u", cfg->ase, cfg->cc_len); if (!cfg->ase || cfg->ase > ASE_COUNT) { From 1ece7a6779c02250ef868f7cbe59cf374add00e9 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Mon, 20 Mar 2023 14:12:29 +0100 Subject: [PATCH 0530/1906] Bluetooth: audio_ ascs: Fix possible dereference of free'd ASE This fixes possible dereference of free'd bt_ascs_ase object. The ASE without ISO connection that goes to Releasing state will be automously transitioned to Idle state. Thus, the `ase` object might not be vaild anymore. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 86f319d98c5e..d546fd7f048c 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -967,6 +967,7 @@ static void ascs_cp_rsp_success(uint8_t id, uint8_t op) static void ase_release(struct bt_ascs_ase *ase) { + uint8_t ase_id = ASE_ID(ase); int err; LOG_DBG("ase %p state %s", ase, bt_bap_ep_state_str(ase->ep.status.state)); @@ -983,14 +984,14 @@ static void ase_release(struct bt_ascs_ase *ase) } if (err) { - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_RELEASE_OP, err, - BT_BAP_ASCS_REASON_NONE); + ascs_cp_rsp_add_errno(ase_id, BT_ASCS_RELEASE_OP, err, BT_BAP_ASCS_REASON_NONE); return; } ascs_ep_set_state(&ase->ep, BT_BAP_EP_STATE_RELEASING); + /* At this point, `ase` object might have been free'd if automously went to Idle */ - ascs_cp_rsp_success(ASE_ID(ase), BT_ASCS_RELEASE_OP); + ascs_cp_rsp_success(ase_id, BT_ASCS_RELEASE_OP); } static void ase_disable(struct bt_ascs_ase *ase) @@ -1061,9 +1062,6 @@ static void disconnected(struct bt_conn *conn, uint8_t reason) stream = ase->ep.stream; if (ase->ep.status.state != BT_BAP_EP_STATE_IDLE) { - /* ase_process will handle the final state transition into idle - * state, where the ase finally will be deallocated - */ ase_release(ase); if (stream != NULL) { From fef4c4e7ea01d763415a000f5a4f4156963bc940 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Mon, 20 Mar 2023 14:23:50 +0100 Subject: [PATCH 0531/1906] Bluetooth: audio: ascs: Fix ASE release from QoS configured This fixes ASE release from QoS configured state. The `ops->released` callback was not called and the `bt_ascs_ase` was not returned to the pool, because `stream` object was already detached. Fixes: #55900 Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index d546fd7f048c..aa87d7594377 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -229,6 +229,8 @@ void ascs_ep_set_state(struct bt_bap_ep *ep, uint8_t state) switch (state) { case BT_BAP_EP_STATE_IDLE: + bt_bap_stream_detach(stream); + if (ops->released != NULL) { ops->released(stream); } @@ -394,7 +396,6 @@ void ascs_ep_set_state(struct bt_bap_ep *ep, uint8_t state) bt_bap_iso_unbind_ep(ep->iso, ep); } - bt_bap_stream_detach(stream); ascs_ep_set_state(ep, BT_BAP_EP_STATE_IDLE); } else { /* Either the client or the server may disconnect the From a52bd0d2e9b49377db065f7a5c84c4a033ae4bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Sun, 19 Mar 2023 11:27:32 +0100 Subject: [PATCH 0532/1906] drivers: pwm: pwm_stm32: Add PWM support on STM32C0-seris MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for PWM on the STM32C0-series. Signed-off-by: Benjamin Björnsson --- drivers/pwm/pwm_stm32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm_stm32.c b/drivers/pwm/pwm_stm32.c index 2e85e533e71b..bb43cf8ee254 100644 --- a/drivers/pwm/pwm_stm32.c +++ b/drivers/pwm/pwm_stm32.c @@ -174,7 +174,8 @@ static int get_tim_clk(const struct stm32_pclken *pclken, uint32_t *tim_clk) if (pclken->bus == STM32_CLOCK_BUS_APB1) { apb_psc = STM32_APB1_PRESCALER; } -#if !defined(CONFIG_SOC_SERIES_STM32F0X) && !defined(CONFIG_SOC_SERIES_STM32G0X) +#if !defined(CONFIG_SOC_SERIES_STM32C0X) && !defined(CONFIG_SOC_SERIES_STM32F0X) && \ + !defined(CONFIG_SOC_SERIES_STM32G0X) else { apb_psc = STM32_APB2_PRESCALER; } From 8f3514d7381565cecb090a6d27086113f052e770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Sun, 19 Mar 2023 11:28:34 +0100 Subject: [PATCH 0533/1906] dts: arm: stm32c0: Add timer and PWM nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add nodes for timers and PWMs on STM32C0-series. Signed-off-by: Benjamin Björnsson --- dts/arm/st/c0/stm32c0.dtsi | 87 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/dts/arm/st/c0/stm32c0.dtsi b/dts/arm/st/c0/stm32c0.dtsi index ee4057dd0405..ee33f526c6cc 100644 --- a/dts/arm/st/c0/stm32c0.dtsi +++ b/dts/arm/st/c0/stm32c0.dtsi @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include @@ -182,6 +184,91 @@ interrupts = <28 0>; status = "disabled"; }; + + timers1: timers@40012c00 { + compatible = "st,stm32-timers"; + reg = <0x40012C00 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1_2 0x00000800>; + resets = <&rctl STM32_RESET(APB1H, 11U)>; + interrupts = <13 0>, <14 0>; + interrupt-names = "brk_up_trg_com", "cc"; + st,prescaler = <0>; + status = "disabled"; + + pwm { + compatible = "st,stm32-pwm"; + status = "disabled"; + #pwm-cells = <3>; + }; + }; + + timers3: timers@40000400 { + compatible = "st,stm32-timers"; + reg = <0x40000400 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1 0x00000002>; + resets = <&rctl STM32_RESET(APB1L, 1U)>; + interrupts = <16 0>; + interrupt-names = "global"; + st,prescaler = <0>; + status = "disabled"; + + pwm { + compatible = "st,stm32-pwm"; + status = "disabled"; + #pwm-cells = <3>; + }; + }; + + timers14: timers@40002000 { + compatible = "st,stm32-timers"; + reg = <0x40002000 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1_2 0x00008000>; + resets = <&rctl STM32_RESET(APB1H, 15U)>; + interrupts = <19 0>; + interrupt-names = "global"; + st,prescaler = <0>; + status = "disabled"; + + pwm { + compatible = "st,stm32-pwm"; + status = "disabled"; + #pwm-cells = <3>; + }; + }; + + timers16: timers@40014400 { + compatible = "st,stm32-timers"; + reg = <0x40014400 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1_2 0x00020000>; + resets = <&rctl STM32_RESET(APB1H, 17U)>; + interrupts = <21 0>; + interrupt-names = "global"; + st,prescaler = <0>; + status = "disabled"; + + pwm { + compatible = "st,stm32-pwm"; + status = "disabled"; + #pwm-cells = <3>; + }; + }; + + timers17: timers@40014800 { + compatible = "st,stm32-timers"; + reg = <0x40014800 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1_2 0x00040000>; + resets = <&rctl STM32_RESET(APB1H, 18U)>; + interrupts = <22 0>; + interrupt-names = "global"; + st,prescaler = <0>; + status = "disabled"; + + pwm { + compatible = "st,stm32-pwm"; + status = "disabled"; + #pwm-cells = <3>; + }; + }; }; }; From 9e209c8ccebd0baac6d405835d09db5174f74236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Mon, 20 Mar 2023 18:15:12 +0100 Subject: [PATCH 0534/1906] boards: arm: nucleo_c031c6: add pwm-led MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add PWM LED node and update documentation. Signed-off-by: Benjamin Björnsson --- boards/arm/nucleo_c031c6/doc/index.rst | 2 ++ boards/arm/nucleo_c031c6/nucleo_c031c6.dts | 20 ++++++++++++++++++++ boards/arm/nucleo_c031c6/nucleo_c031c6.yaml | 1 + 3 files changed, 23 insertions(+) diff --git a/boards/arm/nucleo_c031c6/doc/index.rst b/boards/arm/nucleo_c031c6/doc/index.rst index c9ef5c00a59e..a525635b395d 100644 --- a/boards/arm/nucleo_c031c6/doc/index.rst +++ b/boards/arm/nucleo_c031c6/doc/index.rst @@ -80,6 +80,8 @@ The Zephyr nucleo_c031c6 board configuration supports the following hardware fea +-----------+------------+-------------------------------------+ | WWDG | on-chip | window watchdog | +-----------+------------+-------------------------------------+ +| PWM | on-chip | pwm | ++-----------+------------+-------------------------------------+ Other hardware features are not yet supported in this Zephyr port. diff --git a/boards/arm/nucleo_c031c6/nucleo_c031c6.dts b/boards/arm/nucleo_c031c6/nucleo_c031c6.dts index a53220969df1..de14fefe4f03 100644 --- a/boards/arm/nucleo_c031c6/nucleo_c031c6.dts +++ b/boards/arm/nucleo_c031c6/nucleo_c031c6.dts @@ -28,6 +28,14 @@ }; }; + pwmleds { + compatible = "pwm-leds"; + + green_pwm_led: green_pwm_led { + pwms = <&pwm1 1 PWM_MSEC(20) PWM_POLARITY_NORMAL>; + }; + }; + gpio_keys { compatible = "gpio-keys"; user_button: button { @@ -39,6 +47,7 @@ aliases { led0 = &green_led_4; + pwm-led0 = &green_pwm_led; sw0 = &user_button; watchdog0 = &iwdg; }; @@ -82,3 +91,14 @@ &iwdg { status = "okay"; }; + +&timers1 { + st,prescaler = <10000>; + status = "okay"; + + pwm1: pwm { + pinctrl-0 = <&tim1_ch1_pa5>; + pinctrl-names = "default"; + status = "okay"; + }; +}; diff --git a/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml b/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml index 8646b2bf30ea..f6839051e993 100644 --- a/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml +++ b/boards/arm/nucleo_c031c6/nucleo_c031c6.yaml @@ -10,5 +10,6 @@ supported: - gpio - counter - watchdog + - pwm ram: 12 flash: 32 From ada6881d4794cd72973c5dda8ced65f5202e848f Mon Sep 17 00:00:00 2001 From: Francois Gervais Date: Fri, 10 Feb 2023 13:03:32 -0500 Subject: [PATCH 0535/1906] modules: hal_nordic: check if `gpio1` is enabled The build will fail if `gpio1` is disabled in an overlay. For example: ``` &gpio1 { status = "disabled"; }; ``` Signed-off-by: Francois Gervais --- .../sl_opensource/platform/nrf_802154_gpiote_zephyr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_gpiote_zephyr.c b/modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_gpiote_zephyr.c index 55a9dcec3430..e7cc9ec5b9d2 100644 --- a/modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_gpiote_zephyr.c +++ b/modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_gpiote_zephyr.c @@ -55,7 +55,7 @@ void nrf_802154_gpiote_init(void) GPIO_PULL_UP : GPIO_PULL_DOWN; -#if DT_NODE_EXISTS(DT_NODELABEL(gpio1)) +#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) if (use_port_1) { dev = DEVICE_DT_GET(DT_NODELABEL(gpio1)); } else { From 2ffe890b6af377199ee6cbae74d07ed17e05a904 Mon Sep 17 00:00:00 2001 From: Freddie Yang Date: Tue, 14 Mar 2023 16:05:21 +0800 Subject: [PATCH 0536/1906] Bluetooth: Host: add appearance values Assigned values last modified on 2023-01-05. Signed-off-by: Freddie Yang --- include/zephyr/bluetooth/gap.h | 303 +++++++++++++++++++++++++++++++++ 1 file changed, 303 insertions(+) diff --git a/include/zephyr/bluetooth/gap.h b/include/zephyr/bluetooth/gap.h index dddcf4ef5132..069f1eaa0b8f 100644 --- a/include/zephyr/bluetooth/gap.h +++ b/include/zephyr/bluetooth/gap.h @@ -78,6 +78,309 @@ extern "C" { #define BT_LE_AD_GENERAL 0x02 /* General Discoverable */ #define BT_LE_AD_NO_BREDR 0x04 /* BR/EDR not supported */ +/* Appearance Values Last Modified on 2023-01-05 */ +#define BT_APPEARANCE_UNKNOWN 0x0000 /* Generic Unknown */ +#define BT_APPEARANCE_GENERIC_PHONE 0x0040 /* Generic Phone */ +#define BT_APPEARANCE_GENERIC_COMPUTER 0x0080 /* Generic Computer */ +#define BT_APPEARANCE_COMPUTER_DESKTOP_WORKSTATION 0x0081 /* Desktop Workstation */ +#define BT_APPEARANCE_COMPUTER_SERVER_CLASS 0x0082 /* Server-class Computer */ +#define BT_APPEARANCE_COMPUTER_LAPTOP 0x0083 /* Laptop */ +#define BT_APPEARANCE_COMPUTER_HANDHELD_PCPDA 0x0084 /* Handheld PC/PDA (clamshell) */ +#define BT_APPEARANCE_COMPUTER_PALMSIZE_PCPDA 0x0085 /* Palm­size PC/PDA */ +#define BT_APPEARANCE_COMPUTER_WEARABLE_COMPUTER 0x0086 /* Wearable computer (watch size) */ +#define BT_APPEARANCE_COMPUTER_TABLET 0x0087 /* Tablet */ +#define BT_APPEARANCE_COMPUTER_DOCKING_STATION 0x0088 /* Docking Station */ +#define BT_APPEARANCE_COMPUTER_ALL_IN_ONE 0x0089 /* All in One */ +#define BT_APPEARANCE_COMPUTER_BLADE_SERVER 0x008A /* Blade Server */ +#define BT_APPEARANCE_COMPUTER_CONVERTIBLE 0x008B /* Convertible */ +#define BT_APPEARANCE_COMPUTER_DETACHABLE 0x008C /* Detachable */ +#define BT_APPEARANCE_COMPUTER_IOT_GATEWAY 0x008D /* IoT Gateway */ +#define BT_APPEARANCE_COMPUTER_MINI_PC 0x008E /* Mini PC */ +#define BT_APPEARANCE_COMPUTER_STICK_PC 0x008F /* Stick PC */ +#define BT_APPEARANCE_GENERIC_WATCH 0x00C0 /* Generic Watch */ +#define BT_APPEARANCE_SPORTS_WATCH 0x00C1 /* Sports Watch */ +#define BT_APPEARANCE_SMARTWATCH 0x00C2 /* Smartwatch */ +#define BT_APPEARANCE_GENERIC_CLOCK 0x0100 /* Generic Clock */ +#define BT_APPEARANCE_GENERIC_DISPLAY 0x0140 /* Generic Display */ +#define BT_APPEARANCE_GENERIC_REMOTE 0x0180 /* Generic Remote Control */ +#define BT_APPEARANCE_GENERIC_EYEGLASSES 0x01C0 /* Generic Eye-glasses */ +#define BT_APPEARANCE_GENERIC_TAG 0x0200 /* Generic Tag */ +#define BT_APPEARANCE_GENERIC_KEYRING 0x0240 /* Generic Keyring */ +#define BT_APPEARANCE_GENERIC_MEDIA_PLAYER 0x0280 /* Generic Media Player */ +#define BT_APPEARANCE_GENERIC_BARCODE_SCANNER 0x02C0 /* Generic Barcode Scanner */ +#define BT_APPEARANCE_GENERIC_THERMOMETER 0x0300 /* Generic Thermometer */ +#define BT_APPEARANCE_THERMOMETER_EAR 0x0301 /* Ear Thermometer */ +#define BT_APPEARANCE_GENERIC_HEART_RATE 0x0340 /* Generic Heart Rate Sensor */ +#define BT_APPEARANCE_HEART_RATE_BELT 0x0341 /* Heart Rate Belt */ +#define BT_APPEARANCE_GENERIC_BLOOD_PRESSURE 0x0380 /* Generic Blood Pressure */ +#define BT_APPEARANCE_BLOOD_PRESSURE_ARM 0x0381 /* Arm Blood Pressure */ +#define BT_APPEARANCE_BLOOD_PRESSURE_WRIST 0x0382 /* Wrist Blood Pressure */ +#define BT_APPEARANCE_GENERIC_HID 0x03C0 /* Generic Human Interface Device */ +#define BT_APPEARANCE_HID_KEYBOARD 0x03C1 /* Keyboard */ +#define BT_APPEARANCE_HID_MOUSE 0x03C2 /* Mouse */ +#define BT_APPEARANCE_HID_JOYSTICK 0x03C3 /* Joystick */ +#define BT_APPEARANCE_HID_GAMEPAD 0x03C4 /* Gamepad */ +#define BT_APPEARANCE_HID_DIGITIZER_TABLET 0x03C5 /* Digitizer Tablet */ +#define BT_APPEARANCE_HID_CARD_READER 0x03C6 /* Card Reader */ +#define BT_APPEARANCE_HID_DIGITAL_PEN 0x03C7 /* Digital Pen */ +#define BT_APPEARANCE_HID_BARCODE_SCANNER 0x03C8 /* Barcode Scanner */ +#define BT_APPEARANCE_HID_TOUCHPAD 0x03C9 /* Touchpad */ +#define BT_APPEARANCE_HID_PRESENTATION_REMOTE 0x03CA /* Presentation Remote */ +#define BT_APPEARANCE_GENERIC_GLUCOSE 0x0400 /* Generic Glucose Meter */ +#define BT_APPEARANCE_GENERIC_WALKING 0x0440 /* Generic Running Walking Sensor */ +#define BT_APPEARANCE_WALKING_IN_SHOE 0x0441 /* In-Shoe Running Walking Sensor */ +#define BT_APPEARANCE_WALKING_ON_SHOE 0x0442 /* On-Shoe Running Walking Sensor */ +#define BT_APPEARANCE_WALKING_ON_HIP 0x0443 /* On-Hip Running Walking Sensor */ +#define BT_APPEARANCE_GENERIC_CYCLING 0x0480 /* Generic Cycling */ +#define BT_APPEARANCE_CYCLING_COMPUTER 0x0481 /* Cycling Computer */ +#define BT_APPEARANCE_CYCLING_SPEED 0x0482 /* Speed Sensor */ +#define BT_APPEARANCE_CYCLING_CADENCE 0x0483 /* Cadence Sensor */ +#define BT_APPEARANCE_CYCLING_POWER 0x0484 /* Power Sensor */ +#define BT_APPEARANCE_CYCLING_SPEED_CADENCE 0x0485 /* Speed and Cadence Sensor */ +#define BT_APPEARANCE_GENERIC_CONTROL_DEVICE 0x04C0 /* Generic Control Device */ +#define BT_APPEARANCE_CONTROL_SWITCH 0x04C1 /* Switch */ +#define BT_APPEARANCE_CONTROL_MULTI_SWITCH 0x04C2 /* Multi-switch */ +#define BT_APPEARANCE_CONTROL_BUTTON 0x04C3 /* Button */ +#define BT_APPEARANCE_CONTROL_SLIDER 0x04C4 /* Slider */ +#define BT_APPEARANCE_CONTROL_ROTARY_SWITCH 0x04C5 /* Rotary Switch */ +#define BT_APPEARANCE_CONTROL_TOUCH_PANEL 0x04C6 /* Touch Panel */ +#define BT_APPEARANCE_CONTROL_SINGLE_SWITCH 0x04C7 /* Single Switch */ +#define BT_APPEARANCE_CONTROL_DOUBLE_SWITCH 0x04C8 /* Double Switch */ +#define BT_APPEARANCE_CONTROL_TRIPLE_SWITCH 0x04C9 /* Triple Switch */ +#define BT_APPEARANCE_CONTROL_BATTERY_SWITCH 0x04CA /* Battery Switch */ +#define BT_APPEARANCE_CONTROL_ENERGY_HARVESTING_SWITCH 0x04CB /* Energy Harvesting Switch */ +#define BT_APPEARANCE_CONTROL_PUSH_BUTTON 0x04CC /* Push Button */ +#define BT_APPEARANCE_GENERIC_NETWORK_DEVICE 0x0500 /* Generic Network Device */ +#define BT_APPEARANCE_NETWORK_ACCESS_POINT 0x0501 /* Access Point */ +#define BT_APPEARANCE_NETWORK_MESH_DEVICE 0x0502 /* Mesh Device */ +#define BT_APPEARANCE_NETWORK_MESH_PROXY 0x0503 /* Mesh Network Proxy */ +#define BT_APPEARANCE_GENERIC_SENSOR 0x0540 /* Generic Sensor */ +#define BT_APPEARANCE_SENSOR_MOTION 0x0541 /* Motion Sensor */ +#define BT_APPEARANCE_SENSOR_AIR_QUALITY 0x0542 /* Air quality Sensor */ +#define BT_APPEARANCE_SENSOR_TEMPERATURE 0x0543 /* Temperature Sensor */ +#define BT_APPEARANCE_SENSOR_HUMIDITY 0x0544 /* Humidity Sensor */ +#define BT_APPEARANCE_SENSOR_LEAK 0x0545 /* Leak Sensor */ +#define BT_APPEARANCE_SENSOR_SMOKE 0x0546 /* Smoke Sensor */ +#define BT_APPEARANCE_SENSOR_OCCUPANCY 0x0547 /* Occupancy Sensor */ +#define BT_APPEARANCE_SENSOR_CONTACT 0x0548 /* Contact Sensor */ +#define BT_APPEARANCE_SENSOR_CARBON_MONOXIDE 0x0549 /* Carbon Monoxide Sensor */ +#define BT_APPEARANCE_SENSOR_CARBON_DIOXIDE 0x054A /* Carbon Dioxide Sensor */ +#define BT_APPEARANCE_SENSOR_AMBIENT_LIGHT 0x054B /* Ambient Light Sensor */ +#define BT_APPEARANCE_SENSOR_ENERGY 0x054C /* Energy Sensor */ +#define BT_APPEARANCE_SENSOR_COLOR_LIGHT 0x054D /* Color Light Sensor */ +#define BT_APPEARANCE_SENSOR_RAIN 0x054E /* Rain Sensor */ +#define BT_APPEARANCE_SENSOR_FIRE 0x054F /* Fire Sensor */ +#define BT_APPEARANCE_SENSOR_WIND 0x0550 /* Wind Sensor */ +#define BT_APPEARANCE_SENSOR_PROXIMITY 0x0551 /* Proximity Sensor */ +#define BT_APPEARANCE_SENSOR_MULTI 0x0552 /* Multi-Sensor */ +#define BT_APPEARANCE_SENSOR_FLUSH_MOUNTED 0x0553 /* Flush Mounted Sensor */ +#define BT_APPEARANCE_SENSOR_CEILING_MOUNTED 0x0554 /* Ceiling Mounted Sensor */ +#define BT_APPEARANCE_SENSOR_WALL_MOUNTED 0x0555 /* Wall Mounted Sensor */ +#define BT_APPEARANCE_MULTISENSOR 0x0556 /* Multisensor */ +#define BT_APPEARANCE_SENSOR_ENERGY_METER 0x0557 /* Energy Meter */ +#define BT_APPEARANCE_SENSOR_FLAME_DETECTOR 0x0558 /* Flame Detector */ +#define BT_APPEARANCE_SENSOR_VEHICLE_TIRE_PRESSURE 0x0559 /* Vehicle Tire Pressure Sensor */ +#define BT_APPEARANCE_GENERIC_LIGHT_FIXTURES 0x0580 /* Generic Light Fixtures */ +#define BT_APPEARANCE_LIGHT_FIXTURES_WALL 0x0581 /* Wall Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_CEILING 0x0582 /* Ceiling Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_FLOOR 0x0583 /* Floor Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_CABINET 0x0584 /* Cabinet Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_DESK 0x0585 /* Desk Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_TROFFER 0x0586 /* Troffer Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_PENDANT 0x0587 /* Pendant Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_IN_GROUND 0x0588 /* In-ground Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_FLOOD 0x0589 /* Flood Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_UNDERWATER 0x058A /* Underwater Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_BOLLARD_WITH 0x058B /* Bollard with Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_PATHWAY 0x058C /* Pathway Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_GARDEN 0x058D /* Garden Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_POLE_TOP 0x058E /* Pole-top Light */ +#define BT_APPEARANCE_SPOT_LIGHT 0x058F /* Spotlight */ +#define BT_APPEARANCE_LIGHT_FIXTURES_LINEAR 0x0590 /* Linear Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_STREET 0x0591 /* Street Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_SHELVES 0x0592 /* Shelves Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_BAY 0x0593 /* Bay Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_EMERGENCY_EXIT 0x0594 /* Emergency Exit Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_CONTROLLER 0x0595 /* Light Controller */ +#define BT_APPEARANCE_LIGHT_FIXTURES_DRIVER 0x0596 /* Light Driver */ +#define BT_APPEARANCE_LIGHT_FIXTURES_BULB 0x0597 /* Bulb */ +#define BT_APPEARANCE_LIGHT_FIXTURES_LOW_BAY 0x0598 /* Low-bay Light */ +#define BT_APPEARANCE_LIGHT_FIXTURES_HIGH_BAY 0x0599 /* High-bay Light */ +#define BT_APPEARANCE_GENERIC_FAN 0x05C0 /* Generic Fan */ +#define BT_APPEARANCE_FAN_CEILING 0x05C1 /* Ceiling Fan */ +#define BT_APPEARANCE_FAN_AXIAL 0x05C2 /* Axial Fan */ +#define BT_APPEARANCE_FAN_EXHAUST 0x05C3 /* Exhaust Fan */ +#define BT_APPEARANCE_FAN_PEDESTAL 0x05C4 /* Pedestal Fan */ +#define BT_APPEARANCE_FAN_DESK 0x05C5 /* Desk Fan */ +#define BT_APPEARANCE_FAN_WALL 0x05C6 /* Wall Fan */ +#define BT_APPEARANCE_GENERIC_HVAC 0x0600 /* Generic HVAC */ +#define BT_APPEARANCE_HVAC_THERMOSTAT 0x0601 /* Thermostat */ +#define BT_APPEARANCE_HVAC_HUMIDIFIER 0x0602 /* Humidifier */ +#define BT_APPEARANCE_HVAC_DEHUMIDIFIER 0x0603 /* De-humidifier */ +#define BT_APPEARANCE_HVAC_HEATER 0x0604 /* Heater */ +#define BT_APPEARANCE_HVAC_RADIATOR 0x0605 /* Radiator */ +#define BT_APPEARANCE_HVAC_BOILER 0x0606 /* Boiler */ +#define BT_APPEARANCE_HVAC_HEAT_PUMP 0x0607 /* Heat Pump */ +#define BT_APPEARANCE_HVAC_INFRARED_HEATER 0x0608 /* Infrared Heater */ +#define BT_APPEARANCE_HVAC_RADIANT_PANEL_HEATER 0x0609 /* Radiant Panel Heater */ +#define BT_APPEARANCE_HVAC_FAN_HEATER 0x060A /* Fan Heater */ +#define BT_APPEARANCE_HVAC_AIR_CURTAIN 0x060B /* Air Curtain */ +#define BT_APPEARANCE_GENERIC_AIR_CONDITIONING 0x0640 /* Generic Air Conditioning */ +#define BT_APPEARANCE_GENERIC_HUMIDIFIER 0x0680 /* Generic Humidifier */ +#define BT_APPEARANCE_GENERIC_HEATING 0x06C0 /* Generic Heating */ +#define BT_APPEARANCE_HEATING_RADIATOR 0x06C1 /* Radiator */ +#define BT_APPEARANCE_HEATING_BOILER 0x06C2 /* Boiler */ +#define BT_APPEARANCE_HEATING_HEAT_PUMP 0x06C3 /* Heat Pump */ +#define BT_APPEARANCE_HEATING_INFRARED_HEATER 0x06C4 /* Infrared Heater */ +#define BT_APPEARANCE_HEATING_RADIANT_PANEL_HEATER 0x06C5 /* Radiant Panel Heater */ +#define BT_APPEARANCE_HEATING_FAN_HEATER 0x06C6 /* Fan Heater */ +#define BT_APPEARANCE_HEATING_AIR_CURTAIN 0x06C7 /* Air Curtain */ +#define BT_APPEARANCE_GENERIC_ACCESS_CONTROL 0x0700 /* Generic Access Control */ +#define BT_APPEARANCE_CONTROL_ACCESS_DOOR 0x0701 /* Access Door */ +#define BT_APPEARANCE_CONTROL_GARAGE_DOOR 0x0702 /* Garage Door */ +#define BT_APPEARANCE_CONTROL_EMERGENCY_EXIT_DOOR 0x0703 /* Emergency Exit Door */ +#define BT_APPEARANCE_CONTROL_ACCESS_LOCK 0x0704 /* Access Lock */ +#define BT_APPEARANCE_CONTROL_ELEVATOR 0x0705 /* Elevator */ +#define BT_APPEARANCE_CONTROL_WINDOW 0x0706 /* Window */ +#define BT_APPEARANCE_CONTROL_ENTRANCE_GATE 0x0707 /* Entrance Gate */ +#define BT_APPEARANCE_CONTROL_DOOR_LOCK 0x0708 /* Door Lock */ +#define BT_APPEARANCE_CONTROL_LOCKER 0x0709 /* Locker */ +#define BT_APPEARANCE_GENERIC_MOTORIZED_DEVICE 0x0740 /* Generic Motorized Device */ +#define BT_APPEARANCE_MOTORIZED_GATE 0x0741 /* Motorized Gate */ +#define BT_APPEARANCE_MOTORIZED_AWNING 0x0742 /* Awning */ +#define BT_APPEARANCE_MOTORIZED_BLINDS_OR_SHADES 0x0743 /* Blinds or Shades */ +#define BT_APPEARANCE_MOTORIZED_CURTAINS 0x0744 /* Curtains */ +#define BT_APPEARANCE_MOTORIZED_SCREEN 0x0745 /* Screen */ +#define BT_APPEARANCE_GENERIC_POWER_DEVICE 0x0780 /* Generic Power Device */ +#define BT_APPEARANCE_POWER_OUTLET 0x0781 /* Power Outlet */ +#define BT_APPEARANCE_POWER_STRIP 0x0782 /* Power Strip */ +#define BT_APPEARANCE_POWER_PLUG 0x0783 /* Plug */ +#define BT_APPEARANCE_POWER_SUPPLY 0x0784 /* Power Supply */ +#define BT_APPEARANCE_POWER_LED_DRIVER 0x0785 /* LED Driver */ +#define BT_APPEARANCE_POWER_FLUORESCENT_LAMP_GEAR 0x0786 /* Fluorescent Lamp Gear */ +#define BT_APPEARANCE_POWER_HID_LAMP_GEAR 0x0787 /* HID Lamp Gear */ +#define BT_APPEARANCE_POWER_CHARGE_CASE 0x0788 /* Charge Case */ +#define BT_APPEARANCE_POWER_POWER_BANK 0x0789 /* Power Bank */ +#define BT_APPEARANCE_GENERIC_LIGHT_SOURCE 0x07C0 /* Generic Light Source */ +#define BT_APPEARANCE_LIGHT_SOURCE_INCANDESCENT_BULB 0x07C1 /* Incandescent Light Bulb */ +#define BT_APPEARANCE_LIGHT_SOURCE_LED_LAMP 0x07C2 /* LED Lamp */ +#define BT_APPEARANCE_LIGHT_SOURCE_HID_LAMP 0x07C3 /* HID Lamp */ +#define BT_APPEARANCE_LIGHT_SOURCE_FLUORESCENT_LAMP 0x07C4 /* Fluorescent Lamp */ +#define BT_APPEARANCE_LIGHT_SOURCE_LED_ARRAY 0x07C5 /* LED Array */ +#define BT_APPEARANCE_LIGHT_SOURCE_MULTICOLOR_LED_ARRAY 0x07C6 /* Multi-Color LED Array */ +#define BT_APPEARANCE_LIGHT_SOURCE_LOW_VOLTAGE_HALOGEN 0x07C7 /* Low voltage halogen */ +#define BT_APPEARANCE_LIGHT_SOURCE_OLED 0x07C8 /* Organic light emitting diode */ +#define BT_APPEARANCE_GENERIC_WINDOW_COVERING 0x0800 /* Generic Window Covering */ +#define BT_APPEARANCE_WINDOW_SHADES 0x0801 /* Window Shades */ +#define BT_APPEARANCE_WINDOW_BLINDS 0x0802 /* Window Blinds */ +#define BT_APPEARANCE_WINDOW_AWNING 0x0803 /* Window Awning */ +#define BT_APPEARANCE_WINDOW_CURTAIN 0x0804 /* Window Curtain */ +#define BT_APPEARANCE_WINDOW_EXTERIOR_SHUTTER 0x0805 /* Exterior Shutter */ +#define BT_APPEARANCE_WINDOW_EXTERIOR_SCREEN 0x0806 /* Exterior Screen */ +#define BT_APPEARANCE_GENERIC_AUDIO_SINK 0x0840 /* Generic Audio Sink */ +#define BT_APPEARANCE_AUDIO_SINK_STANDALONE_SPEAKER 0x0841 /* Standalone Speaker */ +#define BT_APPEARANCE_AUDIO_SINK_SOUNDBAR 0x0842 /* Soundbar */ +#define BT_APPEARANCE_AUDIO_SINK_BOOKSHELF_SPEAKER 0x0843 /* Bookshelf Speaker */ +#define BT_APPEARANCE_AUDIO_SINK_STANDMOUNTED_SPEAKER 0x0844 /* Standmounted Speaker */ +#define BT_APPEARANCE_AUDIO_SINK_SPEAKERPHONE 0x0845 /* Speakerphone */ +#define BT_APPEARANCE_GENERIC_AUDIO_SOURCE 0x0880 /* Generic Audio Source */ +#define BT_APPEARANCE_AUDIO_SOURCE_MICROPHONE 0x0881 /* Microphone */ +#define BT_APPEARANCE_AUDIO_SOURCE_ALARM 0x0882 /* Alarm */ +#define BT_APPEARANCE_AUDIO_SOURCE_BELL 0x0883 /* Bell */ +#define BT_APPEARANCE_AUDIO_SOURCE_HORN 0x0884 /* Horn */ +#define BT_APPEARANCE_AUDIO_SOURCE_BROADCASTING_DEVICE 0x0885 /* Broadcasting Device */ +#define BT_APPEARANCE_AUDIO_SOURCE_SERVICE_DESK 0x0886 /* Service Desk */ +#define BT_APPEARANCE_AUDIO_SOURCE_KIOSK 0x0887 /* Kiosk */ +#define BT_APPEARANCE_AUDIO_SOURCE_BROADCASTING_ROOM 0x0888 /* Broadcasting Room */ +#define BT_APPEARANCE_AUDIO_SOURCE_AUDITORIUM 0x0889 /* Auditorium */ +#define BT_APPEARANCE_GENERIC_MOTORIZED_VEHICLE 0x08C0 /* Generic Motorized Vehicle */ +#define BT_APPEARANCE_VEHICLE_CAR 0x08C1 /* Car */ +#define BT_APPEARANCE_VEHICLE_LARGE_GOODS 0x08C2 /* Large Goods Vehicle */ +#define BT_APPEARANCE_VEHICLE_TWO_WHEELED 0x08C3 /* 2-Wheeled Vehicle */ +#define BT_APPEARANCE_VEHICLE_MOTORBIKE 0x08C4 /* Motorbike */ +#define BT_APPEARANCE_VEHICLE_SCOOTER 0x08C5 /* Scooter */ +#define BT_APPEARANCE_VEHICLE_MOPED 0x08C6 /* Moped */ +#define BT_APPEARANCE_VEHICLE_THREE_WHEELED 0x08C7 /* 3-Wheeled Vehicle */ +#define BT_APPEARANCE_VEHICLE_LIGHT 0x08C8 /* Light Vehicle */ +#define BT_APPEARANCE_VEHICLE_QUAD_BIKE 0x08C9 /* Quad Bike */ +#define BT_APPEARANCE_VEHICLE_MINIBUS 0x08CA /* Minibus */ +#define BT_APPEARANCE_VEHICLE_BUS 0x08CB /* Bus */ +#define BT_APPEARANCE_VEHICLE_TROLLEY 0x08CC /* Trolley */ +#define BT_APPEARANCE_VEHICLE_AGRICULTURAL 0x08CD /* Agricultural Vehicle */ +#define BT_APPEARANCE_VEHICLE_CAMPER_OR_CARAVAN 0x08CE /* Camper/Caravan */ +#define BT_APPEARANCE_VEHICLE_RECREATIONAL 0x08CF /* Recreational Vehicle/Motor Home */ +#define BT_APPEARANCE_GENERIC_DOMESTIC_APPLIANCE 0x0900 /* Generic Domestic Appliance */ +#define BT_APPEARANCE_APPLIANCE_REFRIGERATOR 0x0901 /* Refrigerator */ +#define BT_APPEARANCE_APPLIANCE_FREEZER 0x0902 /* Freezer */ +#define BT_APPEARANCE_APPLIANCE_OVEN 0x0903 /* Oven */ +#define BT_APPEARANCE_APPLIANCE_MICROWAVE 0x0904 /* Microwave */ +#define BT_APPEARANCE_APPLIANCE_TOASTER 0x0905 /* Toaster */ +#define BT_APPEARANCE_APPLIANCE_WASHING_MACHINE 0x0906 /* Washing Machine */ +#define BT_APPEARANCE_APPLIANCE_DRYER 0x0907 /* Dryer */ +#define BT_APPEARANCE_APPLIANCE_COFFEE_MAKER 0x0908 /* Coffee maker */ +#define BT_APPEARANCE_APPLIANCE_CLOTHES_IRON 0x0909 /* Clothes iron */ +#define BT_APPEARANCE_APPLIANCE_CURLING_IRON 0x090A /* Curling iron */ +#define BT_APPEARANCE_APPLIANCE_HAIR_DRYER 0x090B /* Hair dryer */ +#define BT_APPEARANCE_APPLIANCE_VACUUM_CLEANER 0x090C /* Vacuum cleaner */ +#define BT_APPEARANCE_APPLIANCE_ROBOTIC_VACUUM_CLEANER 0x090D /* Robotic vacuum cleaner */ +#define BT_APPEARANCE_APPLIANCE_RICE_COOKER 0x090E /* Rice cooker */ +#define BT_APPEARANCE_APPLIANCE_CLOTHES_STEAMER 0x090F /* Clothes steamer */ +#define BT_APPEARANCE_GENERIC_WEARABLE_AUDIO_DEVICE 0x0940 /* Generic Wearable Audio Device */ +#define BT_APPEARANCE_WEARABLE_AUDIO_DEVICE_EARBUD 0x0941 /* Earbud */ +#define BT_APPEARANCE_WEARABLE_AUDIO_DEVICE_HEADSET 0x0942 /* Headset */ +#define BT_APPEARANCE_WEARABLE_AUDIO_DEVICE_HEADPHONES 0x0943 /* Headphones */ +#define BT_APPEARANCE_WEARABLE_AUDIO_DEVICE_NECK_BAND 0x0944 /* Neck Band */ +#define BT_APPEARANCE_GENERIC_AIRCRAFT 0x0980 /* Generic Aircraft */ +#define BT_APPEARANCE_AIRCRAFT_LIGHT 0x0981 /* Light Aircraft */ +#define BT_APPEARANCE_AIRCRAFT_MICROLIGHT 0x0982 /* Microlight */ +#define BT_APPEARANCE_AIRCRAFT_PARAGLIDER 0x0983 /* Paraglider */ +#define BT_APPEARANCE_AIRCRAFT_LARGE_PASSENGER 0x0984 /* Large Passenger Aircraft */ +#define BT_APPEARANCE_GENERIC_AV_EQUIPMENT 0x09C0 /* Generic AV Equipment */ +#define BT_APPEARANCE_AV_EQUIPMENT_AMPLIFIER 0x09C1 /* Amplifier */ +#define BT_APPEARANCE_AV_EQUIPMENT_RECEIVER 0x09C2 /* Receiver */ +#define BT_APPEARANCE_AV_EQUIPMENT_RADIO 0x09C3 /* Radio */ +#define BT_APPEARANCE_AV_EQUIPMENT_TUNER 0x09C4 /* Tuner */ +#define BT_APPEARANCE_AV_EQUIPMENT_TURNTABLE 0x09C5 /* Turntable */ +#define BT_APPEARANCE_AV_EQUIPMENT_CD_PLAYER 0x09C6 /* CD Player */ +#define BT_APPEARANCE_AV_EQUIPMENT_DVD_PLAYER 0x09C7 /* DVD Player */ +#define BT_APPEARANCE_AV_EQUIPMENT_BLURAY_PLAYER 0x09C8 /* Bluray Player */ +#define BT_APPEARANCE_AV_EQUIPMENT_OPTICAL_DISC_PLAYER 0x09C9 /* Optical Disc Player */ +#define BT_APPEARANCE_AV_EQUIPMENT_SET_TOP_BOX 0x09CA /* Set-Top Box */ +#define BT_APPEARANCE_GENERIC_DISPLAY_EQUIPMENT 0x0A00 /* Generic Display Equipment */ +#define BT_APPEARANCE_DISPLAY_EQUIPMENT_TELEVISION 0x0A01 /* Television */ +#define BT_APPEARANCE_DISPLAY_EQUIPMENT_MONITOR 0x0A02 /* Monitor */ +#define BT_APPEARANCE_DISPLAY_EQUIPMENT_PROJECTOR 0x0A03 /* Projector */ +#define BT_APPEARANCE_GENERIC_HEARING_AID 0x0A40 /* Generic Hearing aid */ +#define BT_APPEARANCE_HEARING_AID_IN_EAR 0x0A41 /* In-ear hearing aid */ +#define BT_APPEARANCE_HEARING_AID_BEHIND_EAR 0x0A42 /* Behind-ear hearing aid */ +#define BT_APPEARANCE_HEARING_AID_COCHLEAR_IMPLANT 0x0A43 /* Cochlear Implant */ +#define BT_APPEARANCE_GENERIC_GAMING 0x0A80 /* Generic Gaming */ +#define BT_APPEARANCE_HOME_VIDEO_GAME_CONSOLE 0x0A81 /* Home Video Game Console */ +#define BT_APPEARANCE_PORTABLE_HANDHELD_CONSOLE 0x0A82 /* Portable handheld console */ +#define BT_APPEARANCE_GENERIC_SIGNAGE 0x0AC0 /* Generic Signage */ +#define BT_APPEARANCE_SIGNAGE_DIGITAL 0x0AC1 /* Digital Signage */ +#define BT_APPEARANCE_SIGNAGE_ELECTRONIC_LABEL 0x0AC2 /* Electronic Label */ +#define BT_APPEARANCE_GENERIC_PULSE_OXIMETER 0x0C40 /* Generic Pulse Oximeter */ +#define BT_APPEARANCE_PULSE_OXIMETER_FINGERTIP 0x0C41 /* Fingertip Pulse Oximeter */ +#define BT_APPEARANCE_PULSE_OXIMETER_WRIST 0x0C42 /* Wrist Worn Pulse Oximeter */ +#define BT_APPEARANCE_GENERIC_WEIGHT_SCALE 0x0C80 /* Generic Weight Scale */ +#define BT_APPEARANCE_GENERIC_PERSONAL_MOBILITY_DEVICE 0x0CC0 /* Generic Personal Mobility Device */ +#define BT_APPEARANCE_MOBILITY_POWERED_WHEELCHAIR 0x0CC1 /* Powered Wheelchair */ +#define BT_APPEARANCE_MOBILITY_SCOOTER 0x0CC2 /* Mobility Scooter */ +#define BT_APPEARANCE_CONTINUOUS_GLUCOSE_MONITOR 0x0D00 /* Continuous Glucose Monitor */ +#define BT_APPEARANCE_GENERIC_INSULIN_PUMP 0x0D40 /* Generic Insulin Pump */ +#define BT_APPEARANCE_INSULIN_PUMP_DURABLE 0x0D41 /* Insulin Pump, durable pump */ +#define BT_APPEARANCE_INSULIN_PUMP_PATCH 0x0D44 /* Insulin Pump, patch pump */ +#define BT_APPEARANCE_INSULIN_PEN 0x0D48 /* Insulin Pen */ +#define BT_APPEARANCE_GENERIC_MEDICATION_DELIVERY 0x0D80 /* Generic Medication Delivery */ +#define BT_APPEARANCE_GENERIC_SPIROMETER 0x0DC0 /* Generic Spirometer */ +#define BT_APPEARANCE_SPIROMETER_HANDHELD 0x0DC1 /* Handheld Spirometer */ +#define BT_APPEARANCE_GENERIC_OUTDOOR_SPORTS 0x1440 /* Generic Outdoor Sports Activity */ +#define BT_APPEARANCE_OUTDOOR_SPORTS_LOCATION 0x1441 /* Location Display */ +#define BT_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV 0x1442 /* Location and Navigation Display */ +#define BT_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD 0x1443 /* Location Pod */ +#define BT_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD_AND_NAV 0x1444 /* Location and Navigation Pod */ + /* Defined GAP timers */ #define BT_GAP_SCAN_FAST_INTERVAL 0x0060 /* 60 ms */ #define BT_GAP_SCAN_FAST_WINDOW 0x0030 /* 30 ms */ From 497fe56019d08aa7471bd3cfcc256e5df610ca51 Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sat, 18 Mar 2023 10:26:46 +0900 Subject: [PATCH 0537/1906] boards: riscv: hifive1: Add GPIO-controlled LEDs Add GPIO-controlled LEDs and alias them as led0, led1, led2. Rename the PWM controlled LEDs to pwmled0, pwmled2, pwmled2. Signed-off-by: TOKITA Hiroshi --- boards/riscv/hifive1/hifive1.dts | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/boards/riscv/hifive1/hifive1.dts b/boards/riscv/hifive1/hifive1.dts index 68c5f1d151df..2034d10bc95f 100644 --- a/boards/riscv/hifive1/hifive1.dts +++ b/boards/riscv/hifive1/hifive1.dts @@ -10,10 +10,14 @@ / { model = "SiFive HiFive 1"; compatible = "sifive,hifive1"; + aliases { - pwm-led0 = &led0; - pwm-led1 = &led1; - pwm-led2 = &led2; + led0 = &led0; + led1 = &led1; + led2 = &led2; + pwm-led0 = &pwmled0; + pwm-led1 = &pwmled1; + pwm-led2 = &pwmled2; watchdog0 = &wdog0; }; @@ -25,16 +29,32 @@ }; leds { - compatible = "pwm-leds"; + compatible = "gpio-leds"; led0: led_0 { - pwms = <&pwm1 1 PWM_MSEC(20)>; + gpios = <&gpio0 19 GPIO_ACTIVE_LOW>; label = "Green LED"; }; led1: led_1 { - pwms = <&pwm1 2 PWM_MSEC(20)>; + gpios = <&gpio0 21 GPIO_ACTIVE_LOW>; label = "Blue LED"; }; led2: led_2 { + gpios = <&gpio0 22 GPIO_ACTIVE_LOW>; + label = "Red LED"; + }; + }; + + pwmleds { + compatible = "pwm-leds"; + pwmled0: pwmled_0 { + pwms = <&pwm1 1 PWM_MSEC(20)>; + label = "Green LED"; + }; + pwmled1: pwmled_1 { + pwms = <&pwm1 2 PWM_MSEC(20)>; + label = "Blue LED"; + }; + pwmled2: pwmled_2 { pwms = <&pwm1 3 PWM_MSEC(20)>; label = "Red LED"; }; From dee6f87b3c784c64e9ce4656de8c78195d734cae Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Sun, 19 Mar 2023 21:29:17 +0000 Subject: [PATCH 0538/1906] samples: input_dump: handle events with no device set Input events with no associated device structure are valid. Handle them in the sample by printing NULL instead of crashing trying to lookup the device name. Signed-off-by: Fabio Baltieri --- samples/subsys/input/input_dump/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/subsys/input/input_dump/src/main.c b/samples/subsys/input/input_dump/src/main.c index fd7ade7afd0b..f8d038621bf4 100644 --- a/samples/subsys/input/input_dump/src/main.c +++ b/samples/subsys/input/input_dump/src/main.c @@ -10,7 +10,7 @@ static void input_cb(struct input_event *evt) { printf("input event: dev=%-16s %3s type=%2x code=%3d value=%d\n", - evt->dev->name, + evt->dev ? evt->dev->name : "NULL", evt->sync ? "SYN" : "", evt->type, evt->code, From b9f9f1ba9c1eb76ad1079c74d9da543299ba4b72 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 15 Mar 2023 09:39:29 +0530 Subject: [PATCH 0539/1906] Bluetooth: Controller: Refactor CMakelists.txt for consistency Refactor the Bluetooth Controller's CMakelists.txt to consistently use zephyr_library_sources_ifdef() and zephyr_library_include_directories_ifdef(). Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/CMakeLists.txt | 283 +++++++++++---------- 1 file changed, 146 insertions(+), 137 deletions(-) diff --git a/subsys/bluetooth/controller/CMakeLists.txt b/subsys/bluetooth/controller/CMakeLists.txt index 1909bd46fb93..0b968cf1cfd2 100644 --- a/subsys/bluetooth/controller/CMakeLists.txt +++ b/subsys/bluetooth/controller/CMakeLists.txt @@ -1,6 +1,13 @@ # SPDX-License-Identifier: Apache-2.0 +if(CONFIG_BT_CTLR_ADVANCED_FEATURES) + message(WARNING "\nCONFIG_BT_CTLR_ADVANCED_FEATURES=y, Advanced Features' " + "default value change could change Zephyr Bluetooth " + "Controller's functional behavior.") +endif() + zephyr_library() + zephyr_library_sources( util/mem.c util/memq.c @@ -8,170 +15,172 @@ zephyr_library_sources( util/dbuf.c util/util.c ticker/ticker.c - ll_sw/ll_addr.c + ll_sw/ll_feat.c ll_sw/ll_tx_pwr.c + ll_sw/ll_addr.c + ll_sw/ull.c + ll_sw/lll_common.c hci/hci_driver.c hci/hci.c ) -zephyr_library_sources_ifdef( - CONFIG_BT_CTLR_CRYPTO - crypto/crypto.c - ) +if(CONFIG_BT_BROADCASTER) + zephyr_library_sources( + ll_sw/ull_adv.c + ) + zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_ADV_EXT + ll_sw/ull_adv_aux.c + ) + zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_ADV_PERIODIC + ll_sw/ull_adv_sync.c + ) + zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_ADV_ISO + ll_sw/ull_adv_iso.c + ) +endif() -if(CONFIG_BT_LL_SW_SPLIT) - if(CONFIG_BT_CTLR_ADVANCED_FEATURES) - message(WARNING "\nCONFIG_BT_CTLR_ADVANCED_FEATURES=y, Advanced Features' " - "default value change could change Zephyr Bluetooth " - "Controller's functional behavior.") - endif() +if(CONFIG_BT_OBSERVER) zephyr_library_sources( - ll_sw/ll_feat.c - ll_sw/ull.c - ll_sw/lll_common.c + ll_sw/ull_scan.c ) - if(CONFIG_BT_BROADCASTER) - zephyr_library_sources( - ll_sw/ull_adv.c - ) - zephyr_library_sources_ifdef( - CONFIG_BT_CTLR_ADV_EXT - ll_sw/ull_adv_aux.c - ) - zephyr_library_sources_ifdef( - CONFIG_BT_CTLR_ADV_PERIODIC - ll_sw/ull_adv_sync.c - ) - zephyr_library_sources_ifdef( - CONFIG_BT_CTLR_ADV_ISO - ll_sw/ull_adv_iso.c - ) - endif() - if(CONFIG_BT_OBSERVER) - zephyr_library_sources( - ll_sw/ull_scan.c - ) - zephyr_library_sources_ifdef( - CONFIG_BT_CTLR_ADV_EXT - ll_sw/ull_scan_aux.c - ) - zephyr_library_sources_ifdef( - CONFIG_BT_CTLR_SYNC_PERIODIC - ll_sw/ull_sync.c - ) - zephyr_library_sources_ifdef( - CONFIG_BT_CTLR_SYNC_ISO - ll_sw/ull_sync_iso.c - ) - endif() - if(CONFIG_BT_CONN) - zephyr_library_sources( - ll_sw/ull_conn.c - ) - zephyr_library_sources_ifdef( - CONFIG_BT_CTLR_PHY - ll_sw/ull_llcp_phy.c - ) - zephyr_library_sources_ifdef( - CONFIG_BT_CTLR_LE_ENC - ll_sw/ull_llcp_enc.c - ) - if (CONFIG_BT_CTLR_PERIPHERAL_ISO OR - CONFIG_BT_CTLR_CENTRAL_ISO) - zephyr_library_sources( - ll_sw/ull_llcp_cc.c - ) - endif() - zephyr_library_sources( - ll_sw/ull_tx_queue.c - ll_sw/ull_llcp.c - ll_sw/ull_llcp_common.c - ll_sw/ull_llcp_local.c - ll_sw/ull_llcp_pdu.c - ll_sw/ull_llcp_conn_upd.c - ll_sw/ull_llcp_chmu.c - ll_sw/ull_llcp_remote.c - ) - if(CONFIG_BT_PERIPHERAL) - zephyr_library_sources( - ll_sw/ull_peripheral.c - ) - zephyr_library_sources_ifdef( - CONFIG_BT_CTLR_PERIPHERAL_ISO - ll_sw/ull_peripheral_iso.c - ) - endif() - if(CONFIG_BT_CENTRAL) - zephyr_library_sources( - ll_sw/ull_central.c - ) - zephyr_library_sources_ifdef( - CONFIG_BT_CTLR_CENTRAL_ISO - ll_sw/ull_central_iso.c - ) - endif() - endif() - if(CONFIG_BT_CTLR_SCHED_ADVANCED) - zephyr_library_sources( - ll_sw/ull_sched.c + zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_ADV_EXT + ll_sw/ull_scan_aux.c ) - endif() - if(CONFIG_BT_CTLR_DF) - zephyr_library_sources( - ll_sw/ull_df.c - ) - endif() - if(CONFIG_BT_CTLR_CONN_ISO) - zephyr_library_sources( - ll_sw/ull_conn_iso.c - ) - endif() - if(CONFIG_BT_CTLR_ISO) - zephyr_library_sources( - ll_sw/ull_iso.c - ll_sw/isoal.c - ) - endif() - if(CONFIG_BT_CONN OR - (CONFIG_BT_BROADCASTER AND - CONFIG_BT_CTLR_ADV_EXT) OR - CONFIG_BT_CTLR_ADV_PERIODIC OR - CONFIG_BT_CTLR_SYNC_PERIODIC) - zephyr_library_sources( - ll_sw/ull_chan.c - ll_sw/lll_chan.c - ) - endif() - if(CONFIG_BT_CTLR_FILTER_ACCEPT_LIST OR - CONFIG_BT_CTLR_SYNC_PERIODIC_ADV_LIST) + zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_SYNC_PERIODIC + ll_sw/ull_sync.c + ) + zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_SYNC_ISO + ll_sw/ull_sync_iso.c + ) +endif() + +if(CONFIG_BT_CONN) + zephyr_library_sources( + ll_sw/ull_conn.c + ) + zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_LE_ENC + ll_sw/ull_llcp_enc.c + ) + zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_PHY + ll_sw/ull_llcp_phy.c + ) + if (CONFIG_BT_CTLR_PERIPHERAL_ISO OR + CONFIG_BT_CTLR_CENTRAL_ISO) zephyr_library_sources( - ll_sw/ull_filter.c + ll_sw/ull_llcp_cc.c ) endif() + zephyr_library_sources( + ll_sw/ull_tx_queue.c + ll_sw/ull_llcp.c + ll_sw/ull_llcp_common.c + ll_sw/ull_llcp_local.c + ll_sw/ull_llcp_pdu.c + ll_sw/ull_llcp_conn_upd.c + ll_sw/ull_llcp_chmu.c + ll_sw/ull_llcp_remote.c + ) + zephyr_library_sources_ifdef( + CONFIG_BT_PERIPHERAL + ll_sw/ull_peripheral.c + ) + zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_PERIPHERAL_ISO + ll_sw/ull_peripheral_iso.c + ) + zephyr_library_sources_ifdef( + CONFIG_BT_CENTRAL + ll_sw/ull_central.c + ) zephyr_library_sources_ifdef( - CONFIG_BT_HCI_MESH_EXT - ll_sw/ll_mesh.c + CONFIG_BT_CTLR_CENTRAL_ISO + ll_sw/ull_central_iso.c ) - add_subdirectory_ifdef(CONFIG_BT_CTLR_COEX_DRIVERS coex) endif() -if(CONFIG_SOC_COMPATIBLE_NRF) - include(ll_sw/nrf.cmake) -elseif(CONFIG_SOC_OPENISA_RV32M1_RISCV32) - include(ll_sw/openisa.cmake) +zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_SCHED_ADVANCED + ll_sw/ull_sched.c + ) + +zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_DF + ll_sw/ull_df.c + ) + +zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_CONN_ISO + ll_sw/ull_conn_iso.c + ) + +zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_ISO + ll_sw/ull_iso.c + ll_sw/isoal.c + ) + +if(CONFIG_BT_CONN OR + (CONFIG_BT_BROADCASTER AND + CONFIG_BT_CTLR_ADV_EXT) OR + CONFIG_BT_CTLR_ADV_PERIODIC OR + CONFIG_BT_CTLR_SYNC_PERIODIC) + zephyr_library_sources( + ll_sw/ull_chan.c + ll_sw/lll_chan.c + ) +endif() + +if(CONFIG_BT_CTLR_FILTER_ACCEPT_LIST OR + CONFIG_BT_CTLR_SYNC_PERIODIC_ADV_LIST) + zephyr_library_sources( + ll_sw/ull_filter.c + ) endif() +zephyr_library_sources_ifdef( + CONFIG_BT_HCI_MESH_EXT + ll_sw/ll_mesh.c + ) + zephyr_library_sources_ifdef( CONFIG_BT_CTLR_SETTINGS ll_sw/ll_settings.c -) + ) + +zephyr_library_sources_ifdef( + CONFIG_BT_CTLR_CRYPTO + crypto/crypto.c + ) + +add_subdirectory_ifdef( + CONFIG_BT_CTLR_COEX_DRIVERS + coex + ) + +if(CONFIG_SOC_COMPATIBLE_NRF) + include(ll_sw/nrf.cmake) +elseif(CONFIG_SOC_OPENISA_RV32M1_RISCV32) + include(ll_sw/openisa.cmake) +endif() zephyr_library_include_directories( . include - ../crypto ) +zephyr_library_include_directories_ifdef( + CONFIG_BT_CTLR_CRYPTO + ../crypto +) + zephyr_library_compile_options_ifdef( CONFIG_BT_CTLR_OPTIMIZE_FOR_SPEED ${OPTIMIZE_FOR_SPEED_FLAG} From 643723479fddb7651764120ef8e36c13d392b46a Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 15 Mar 2023 09:39:29 +0530 Subject: [PATCH 0540/1906] drivers: flash: nRF: Move sync ticker to Subsys Bluetooth Controller Move the SoC Flash nRF sync ticker implementation into Bluetooth Controller Subsystem folder, as internal headers are included. Signed-off-by: Vinayak Kariappa Chettimada --- drivers/flash/CMakeLists.txt | 7 ------- subsys/bluetooth/controller/CMakeLists.txt | 10 ++++++++++ .../controller}/flash/soc_flash_nrf_ticker.c | 14 +++++++------- 3 files changed, 17 insertions(+), 14 deletions(-) rename {drivers => subsys/bluetooth/controller}/flash/soc_flash_nrf_ticker.c (98%) diff --git a/drivers/flash/CMakeLists.txt b/drivers/flash/CMakeLists.txt index a9b11e0d7a30..0d474daa4389 100644 --- a/drivers/flash/CMakeLists.txt +++ b/drivers/flash/CMakeLists.txt @@ -10,7 +10,6 @@ zephyr_library_sources_ifdef(CONFIG_FLASH_SIMULATOR flash_simulator.c) zephyr_library_sources_ifdef(CONFIG_SPI_FLASH_AT45 spi_flash_at45.c) zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_ITE_IT8XXX2 flash_ite_it8xxx2.c) zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_NRF soc_flash_nrf.c) -zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_NRF_RADIO_SYNC_TICKER soc_flash_nrf_ticker.c) zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_MCUX soc_flash_mcux.c) zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_LPC soc_flash_lpc.c) zephyr_library_sources_ifdef(CONFIG_FLASH_PAGE_LAYOUT flash_page_layout.c) @@ -84,11 +83,5 @@ zephyr_library_include_directories_ifdef( ${ZEPHYR_BASE}/drivers/memc ) -zephyr_library_include_directories_ifdef( - CONFIG_SOC_FLASH_NRF_RADIO_SYNC_TICKER - ${ZEPHYR_BASE}/subsys/bluetooth - ${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/nordic - ) - zephyr_library_sources_ifdef(CONFIG_FLASH_SHELL flash_shell.c) zephyr_library_sources_ifdef(CONFIG_FLASH_JESD216 jesd216.c) diff --git a/subsys/bluetooth/controller/CMakeLists.txt b/subsys/bluetooth/controller/CMakeLists.txt index 0b968cf1cfd2..679272fab93a 100644 --- a/subsys/bluetooth/controller/CMakeLists.txt +++ b/subsys/bluetooth/controller/CMakeLists.txt @@ -160,6 +160,11 @@ zephyr_library_sources_ifdef( crypto/crypto.c ) +zephyr_library_sources_ifdef( + CONFIG_SOC_FLASH_NRF_RADIO_SYNC_TICKER + flash/soc_flash_nrf_ticker.c + ) + add_subdirectory_ifdef( CONFIG_BT_CTLR_COEX_DRIVERS coex @@ -181,6 +186,11 @@ zephyr_library_include_directories_ifdef( ../crypto ) +zephyr_library_include_directories_ifdef( + CONFIG_SOC_FLASH_NRF_RADIO_SYNC_TICKER + ${ZEPHYR_BASE}/drivers/flash +) + zephyr_library_compile_options_ifdef( CONFIG_BT_CTLR_OPTIMIZE_FOR_SPEED ${OPTIMIZE_FOR_SPEED_FLAG} diff --git a/drivers/flash/soc_flash_nrf_ticker.c b/subsys/bluetooth/controller/flash/soc_flash_nrf_ticker.c similarity index 98% rename from drivers/flash/soc_flash_nrf_ticker.c rename to subsys/bluetooth/controller/flash/soc_flash_nrf_ticker.c index 989a163ca13c..8b9696e988b6 100644 --- a/drivers/flash/soc_flash_nrf_ticker.c +++ b/subsys/bluetooth/controller/flash/soc_flash_nrf_ticker.c @@ -6,18 +6,18 @@ #include +#include #include #include #include -#include - -#include "soc_flash_nrf.h" - #include #include -#include "controller/hal/ticker.h" -#include "controller/ticker/ticker.h" -#include "controller/include/ll.h" + +#include "hal/ticker.h" +#include "ticker/ticker.h" +#include "ll.h" + +#include "soc_flash_nrf.h" #define FLASH_RADIO_ABORT_DELAY_US 1500 #define FLASH_RADIO_WORK_DELAY_US 200 From a693b9b33bda32cb6c250dba442a8f5a19c76efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Battrel?= Date: Mon, 27 Feb 2023 14:28:30 +0100 Subject: [PATCH 0541/1906] Bluetooth: Host: Add Encrypted Advertising Data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create a new Bluetooth library and add Encrypted Advertising Data to it. Encrypted Advertising Data is a new feature from the Bluetooth Core Specification 5.4. It provides a way to communicate encrypted data in advertising, scan response and EIR packets. To do that it introduce a new advertising data type called `Encrypted Advertising Data`. Also, it introduce a new characteristic called `Encrypted Data Key Material`, this provides a way to share the key material. The library add two main functions `bt_ead_encrypt` and `bt_ead_decrypt`. Two helper functions are added to `bluetooth.h`. `bt_data_get_len` and `bt_data_serialize`, the first one allow the user to get the total size of a set of `bt_data` structures; the second one generate a spec compliant bytes array from a `bt_data` structure. The last one is useful because `bt_ead_encrypt` take as input those kind of bytes array. Signed-off-by: Théo Battrel --- include/zephyr/bluetooth/bluetooth.h | 28 +++ include/zephyr/bluetooth/ead.h | 92 +++++++++ include/zephyr/bluetooth/gap.h | 1 + subsys/bluetooth/CMakeLists.txt | 2 + subsys/bluetooth/Kconfig | 1 + subsys/bluetooth/lib/CMakeLists.txt | 3 + subsys/bluetooth/lib/Kconfig | 14 ++ subsys/bluetooth/lib/ead.c | 274 +++++++++++++++++++++++++++ 8 files changed, 415 insertions(+) create mode 100644 include/zephyr/bluetooth/ead.h create mode 100644 subsys/bluetooth/lib/CMakeLists.txt create mode 100644 subsys/bluetooth/lib/Kconfig create mode 100644 subsys/bluetooth/lib/ead.c diff --git a/include/zephyr/bluetooth/bluetooth.h b/include/zephyr/bluetooth/bluetooth.h index e8dbaa42497b..f448f683691a 100644 --- a/include/zephyr/bluetooth/bluetooth.h +++ b/include/zephyr/bluetooth/bluetooth.h @@ -388,6 +388,34 @@ struct bt_data { BT_DATA(_type, ((uint8_t []) { _bytes }), \ sizeof((uint8_t []) { _bytes })) +/** + * @brief Get the total size (in bytes) of a given set of @ref bt_data + * structures. + * + * @param[in] data Array of @ref bt_data structures. + * @param[in] data_count Number of @ref bt_data structures in @p data. + * + * @return Size of the concatenated data, built from the @ref bt_data structure + * set. + */ +size_t bt_data_get_len(const struct bt_data data[], size_t data_count); + +/** + * @brief Serialize a @ref bt_data struct into an advertising structure (a flat + * byte array). + * + * The data are formatted according to the Bluetooth Core Specification v. 5.4, + * vol. 3, part C, 11. + * + * @param[in] input Single @ref bt_data structure to read from. + * @param[out] output Buffer large enough to store the advertising structure in + * @p input. The size of it must be at least the size of the + * `input->data_len + 2` (for the type and the length). + * + * @return Number of bytes written in @p output. + */ +size_t bt_data_serialize(const struct bt_data *input, uint8_t *output); + /** Advertising options */ enum { /** Convenience value when no options are specified. */ diff --git a/include/zephyr/bluetooth/ead.h b/include/zephyr/bluetooth/ead.h new file mode 100644 index 000000000000..8a166d0ec271 --- /dev/null +++ b/include/zephyr/bluetooth/ead.h @@ -0,0 +1,92 @@ +/* Copyright (c) 2023 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include + +#include + +/** Randomizer size in bytes */ +#define BT_EAD_RANDOMIZER_SIZE 5 +/** Key size in bytes */ +#define BT_EAD_KEY_SIZE 16 +/** Initialisation Vector size in bytes */ +#define BT_EAD_IV_SIZE 8 +/** MIC size in bytes */ +#define BT_EAD_MIC_SIZE 4 + +/** Get the size (in bytes) of the encrypted advertising data for a given + * payload size in bytes. + */ +#define BT_EAD_ENCRYPTED_PAYLOAD_SIZE(payload_size) \ + ((payload_size) + BT_EAD_RANDOMIZER_SIZE + BT_EAD_MIC_SIZE) + +/** Get the size (in bytes) of the decrypted payload for a given payload size in + * bytes. + */ +#define BT_EAD_DECRYPTED_PAYLOAD_SIZE(encrypted_payload_size) \ + ((encrypted_payload_size) - (BT_EAD_RANDOMIZER_SIZE + BT_EAD_MIC_SIZE)) + +/** + * @brief Encrypt and authenticate the given advertising data. + * + * The resulting data in @p encrypted_payload will look like that: + * - Randomizer is added in the @ref BT_EAD_RANDOMIZER_SIZE first bytes; + * - Encrypted payload is added ( @p payload_size bytes); + * - MIC is added in the last @ref BT_EAD_MIC_SIZE bytes. + * + * @attention The function must be called each time the RPA is updated or the + * data are modified. + * + * @note The term `advertising structure` is used to describe the advertising + * data with the advertising type and the length of those two. + * + * @param[in] session_key Key of @ref BT_EAD_KEY_SIZE bytes used for the + * encryption. + * @param[in] iv Initialisation Vector used to generate the nonce. It must be + * changed each time the Session Key changes. + * @param[in] payload Advertising Data to encrypt. Can be multiple advertising + * structures that are concatenated. + * @param[in] payload_size Size of the Advertising Data to encrypt. + * @param[out] encrypted_payload Encrypted Ad Data including the Randomizer and + * the MIC. Size must be at least @ref BT_EAD_RANDOMIZER_SIZE + @p + * payload_size + @ref BT_EAD_MIC_SIZE. Use @ref + * BT_EAD_ENCRYPTED_PAYLOAD_SIZE to get the right size. + * + * @retval 0 Data have been correctly encrypted and authenticated. + * @retval -EIO Error occurred during the encryption or the authentication. + * @retval -EINVAL One of the argument is a NULL pointer. + * @retval -ECANCELED Error occurred during the random number generation. + */ +int bt_ead_encrypt(const uint8_t session_key[BT_EAD_KEY_SIZE], const uint8_t iv[BT_EAD_IV_SIZE], + const uint8_t *payload, size_t payload_size, uint8_t *encrypted_payload); + +/** + * @brief Decrypt and authenticate the given encrypted advertising data. + * + * @note The term `advertising structure` is used to describe the advertising + * data with the advertising type and the length of those two. + * + * @param[in] session_key Key of 16 bytes used for the encryption. + * @param[in] iv Initialisation Vector used to generate the `nonce`. + * @param[in] encrypted_payload Encrypted Advertising Data received. This + * should only contain the advertising data from the received + * advertising structure, not the length nor the type. + * @param[in] encrypted_payload_size Size of the received advertising data in + * bytes. Should be equal to the length field of the received + * advertising structure, minus the size of the type (1 byte). + * @param[out] payload Decrypted advertising payload. Use @ref + * BT_EAD_DECRYPTED_PAYLOAD_SIZE to get the right size. + * + * @retval 0 Data have been correctly decrypted and authenticated. + * @retval -EIO Error occurred during the decryption or the authentication. + * @retval -EINVAL One of the argument is a NULL pointer or @p + * encrypted_payload_size is less than @ref + * BT_EAD_RANDOMIZER_SIZE + @ref BT_EAD_MIC_SIZE. + */ +int bt_ead_decrypt(const uint8_t session_key[BT_EAD_KEY_SIZE], const uint8_t iv[BT_EAD_IV_SIZE], + const uint8_t *encrypted_payload, size_t encrypted_payload_size, + uint8_t *payload); diff --git a/include/zephyr/bluetooth/gap.h b/include/zephyr/bluetooth/gap.h index 069f1eaa0b8f..ed76372b573c 100644 --- a/include/zephyr/bluetooth/gap.h +++ b/include/zephyr/bluetooth/gap.h @@ -70,6 +70,7 @@ extern "C" { #define BT_DATA_CSIS_RSI 0x2e /* CSIS Random Set ID type */ #define BT_DATA_ADV_INT_LONG 0x2f /* Advertising Interval long */ #define BT_DATA_BROADCAST_NAME 0x30 /* Broadcast Name */ +#define BT_DATA_ENCRYPTED_AD_DATA 0x31 /* Encrypted Advertising Data */ #define BT_DATA_3D_INFO 0x3D /* 3D Information Data */ #define BT_DATA_MANUFACTURER_DATA 0xff /* Manufacturer Specific Data */ diff --git a/subsys/bluetooth/CMakeLists.txt b/subsys/bluetooth/CMakeLists.txt index a670ad2901bc..f0a0349133e2 100644 --- a/subsys/bluetooth/CMakeLists.txt +++ b/subsys/bluetooth/CMakeLists.txt @@ -17,3 +17,5 @@ if(CONFIG_BT_CTLR AND CONFIG_BT_LL_SW_SPLIT) endif() zephyr_include_directories(${ZEPHYR_BASE}/subsys/bluetooth) + +add_subdirectory(lib) diff --git a/subsys/bluetooth/Kconfig b/subsys/bluetooth/Kconfig index 5d4d42e651ef..83c4d9d7cccc 100644 --- a/subsys/bluetooth/Kconfig +++ b/subsys/bluetooth/Kconfig @@ -187,6 +187,7 @@ rsource "host/Kconfig" rsource "controller/Kconfig" rsource "shell/Kconfig" rsource "crypto/Kconfig" +rsource "lib/Kconfig" endif # BT_HCI diff --git a/subsys/bluetooth/lib/CMakeLists.txt b/subsys/bluetooth/lib/CMakeLists.txt new file mode 100644 index 000000000000..579822153501 --- /dev/null +++ b/subsys/bluetooth/lib/CMakeLists.txt @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_sources_ifdef(CONFIG_BT_EAD ead.c) diff --git a/subsys/bluetooth/lib/Kconfig b/subsys/bluetooth/lib/Kconfig new file mode 100644 index 000000000000..d5c1cf073065 --- /dev/null +++ b/subsys/bluetooth/lib/Kconfig @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config BT_EAD + bool "Encrypted Advertising Data [EXPERIMENTAL]" + select EXPERIMENTAL + select BT_HOST_CCM + help + Enable the Encrypted Advertising Data library + +parent-module = BT +module = BT_EAD +module-str = "Bluetooth Encrypted Advertising Data" +source "subsys/logging/Kconfig.template.log_config_inherit" diff --git a/subsys/bluetooth/lib/ead.c b/subsys/bluetooth/lib/ead.c new file mode 100644 index 000000000000..69b78fa62ac3 --- /dev/null +++ b/subsys/bluetooth/lib/ead.c @@ -0,0 +1,274 @@ +/* Copyright (c) 2023 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include +#include + +#include + +#include + +/** nonce size in bytes */ +#define BT_EAD_NONCE_SIZE 13 + +/* This value is used to set the directionBit of the CCM nonce to the MSB of the Randomizer field + * (see Supplement to the Bluetooth Core Specification v11, Part A 1.23.3) + */ +#define BT_EAD_RANDOMIZER_DIRECTION_BIT 7 + +/** Additional Authenticated Data size in bytes */ +#define BT_EAD_AAD_SIZE 1 + +/* Fixed value used for the Additional Authenticated Data (see Supplement to the Bluetooth Core + * Specification v11, Part A 1.23.3) + */ +static uint8_t bt_ead_aad[] = {0xEA}; +BUILD_ASSERT(sizeof(bt_ead_aad) == BT_EAD_AAD_SIZE); + +LOG_MODULE_REGISTER(bt_encrypted_ad_data, CONFIG_BT_EAD_LOG_LEVEL); + +static int bt_ead_generate_randomizer(uint8_t randomizer[BT_EAD_RANDOMIZER_SIZE]) +{ + int err; + + err = bt_rand(randomizer, BT_EAD_RANDOMIZER_SIZE); + + if (err != 0) { + return -ECANCELED; + } + + /* From Supplement to the Bluetooth Core Specification v11, Part A 1.23.3: The directionBit + * of the CCM nonce shall be set to the most significant bit of the Randomizer field. + */ + randomizer[4] |= 1 << BT_EAD_RANDOMIZER_DIRECTION_BIT; + + return 0; +} + +static int bt_ead_generate_nonce(const uint8_t iv[BT_EAD_IV_SIZE], + const uint8_t randomizer[BT_EAD_RANDOMIZER_SIZE], uint8_t *nonce) +{ + uint8_t new_randomizer[BT_EAD_RANDOMIZER_SIZE]; + + if (randomizer == NULL) { + int err; + + err = bt_ead_generate_randomizer(new_randomizer); + + if (err != 0) { + LOG_DBG("Failed to generate Randomizer"); + return -ECANCELED; + } + + randomizer = new_randomizer; + } + + memcpy(&nonce[0], randomizer, BT_EAD_RANDOMIZER_SIZE); + memcpy(&nonce[BT_EAD_RANDOMIZER_SIZE], iv, BT_EAD_IV_SIZE); + + return 0; +} + +size_t bt_data_get_len(const struct bt_data data[], size_t data_count) +{ + size_t total_len = 0; + + for (size_t i = 0; i < data_count; i++) { + total_len += sizeof(data[i].data_len) + sizeof(data[i].type) + data[i].data_len; + } + + return total_len; +} + +size_t bt_data_serialize(const struct bt_data *input, uint8_t *output) +{ + CHECKIF(input == NULL) { + LOG_DBG("input is NULL"); + return 0; + } + + CHECKIF(output == NULL) { + LOG_DBG("output_ad_structure is NULL"); + return 0; + } + + uint8_t ad_data_len = input->data_len; + uint8_t data_len = ad_data_len + 1; + + output[0] = data_len; + output[1] = input->type; + + memcpy(&output[2], input->data, ad_data_len); + + return data_len + 1; +} + +static int ead_encrypt(const uint8_t session_key[BT_EAD_KEY_SIZE], const uint8_t iv[BT_EAD_IV_SIZE], + const uint8_t randomizer[BT_EAD_RANDOMIZER_SIZE], const uint8_t *payload, + size_t payload_size, uint8_t *encrypted_payload) +{ + int err; + uint8_t nonce[BT_EAD_NONCE_SIZE]; + size_t ead_size = BT_EAD_RANDOMIZER_SIZE + payload_size + BT_EAD_MIC_SIZE; + + err = bt_ead_generate_nonce(iv, randomizer, nonce); + if (err != 0) { + return -ECANCELED; + } + + memcpy(encrypted_payload, nonce, BT_EAD_RANDOMIZER_SIZE); + + err = bt_ccm_encrypt(session_key, nonce, payload, payload_size, bt_ead_aad, BT_EAD_AAD_SIZE, + &encrypted_payload[BT_EAD_RANDOMIZER_SIZE], BT_EAD_MIC_SIZE); + if (err != 0) { + LOG_DBG("Failed to encrypt the payload (bt_ccm_encrypt err %d)", err); + return -EIO; + } + + LOG_HEXDUMP_DBG(encrypted_payload, ead_size, "Encrypted Data: "); + + return 0; +} + +int bt_ead_encrypt(const uint8_t session_key[BT_EAD_KEY_SIZE], const uint8_t iv[BT_EAD_IV_SIZE], + const uint8_t *payload, size_t payload_size, uint8_t *encrypted_payload) +{ + CHECKIF(session_key == NULL) { + LOG_DBG("session_key is NULL"); + return -EINVAL; + } + + CHECKIF(iv == NULL) { + LOG_DBG("iv is NULL"); + return -EINVAL; + } + + CHECKIF(payload == NULL) { + LOG_DBG("payload is NULL"); + return -EINVAL; + } + + CHECKIF(encrypted_payload == NULL) { + LOG_DBG("encrypted_payload is NULL"); + return -EINVAL; + } + + if (payload_size == 0) { + LOG_WRN("payload_size is set to 0. The encrypted result will only contain the " + "Randomizer and the MIC."); + } + + return ead_encrypt(session_key, iv, NULL, payload, payload_size, encrypted_payload); +} + +#if defined(CONFIG_BT_TESTING) + +int bt_test_ead_encrypt(const uint8_t session_key[BT_EAD_KEY_SIZE], + const uint8_t iv[BT_EAD_IV_SIZE], + const uint8_t randomizer[BT_EAD_RANDOMIZER_SIZE], const uint8_t *payload, + size_t payload_size, uint8_t *encrypted_payload) +{ + CHECKIF(session_key == NULL) { + LOG_DBG("session_key is NULL"); + return -EINVAL; + } + + CHECKIF(iv == NULL) { + LOG_DBG("iv is NULL"); + return -EINVAL; + } + + CHECKIF(randomizer == NULL) { + LOG_DBG("randomizer is NULL"); + return -EINVAL; + } + + CHECKIF(payload == NULL) { + LOG_DBG("payload is NULL"); + return -EINVAL; + } + + CHECKIF(encrypted_payload == NULL) { + LOG_DBG("encrypted_payload is NULL"); + return -EINVAL; + } + + if (payload_size == 0) { + LOG_WRN("payload_size is set to 0. The encrypted result will be filled with only " + "the Randomizer and the MIC."); + } + + return ead_encrypt(session_key, iv, randomizer, payload, payload_size, encrypted_payload); +} + +#endif /* CONFIG_BT_TESTING */ + +static int ead_decrypt(const uint8_t session_key[BT_EAD_KEY_SIZE], const uint8_t iv[BT_EAD_IV_SIZE], + const uint8_t *encrypted_payload, size_t encrypted_payload_size, + uint8_t *payload) +{ + int err; + uint8_t nonce[BT_EAD_NONCE_SIZE]; + const uint8_t *encrypted_ad_data = &encrypted_payload[BT_EAD_RANDOMIZER_SIZE]; + size_t encrypted_ad_data_size = encrypted_payload_size - BT_EAD_RANDOMIZER_SIZE; + size_t payload_size = encrypted_ad_data_size - BT_EAD_MIC_SIZE; + + const uint8_t *randomizer = encrypted_payload; + + err = bt_ead_generate_nonce(iv, randomizer, nonce); + if (err != 0) { + return -EIO; + } + + LOG_HEXDUMP_DBG(encrypted_ad_data, encrypted_ad_data_size, "Encrypted Data: "); + + err = bt_ccm_decrypt(session_key, nonce, encrypted_ad_data, payload_size, bt_ead_aad, + BT_EAD_AAD_SIZE, payload, BT_EAD_MIC_SIZE); + LOG_HEXDUMP_DBG(payload, payload_size, "Decrypted Data: "); + if (err != 0) { + LOG_DBG("Failed to decrypt the data (bt_ccm_decrypt err %d)", err); + return -EIO; + } + + return 0; +} + +int bt_ead_decrypt(const uint8_t session_key[BT_EAD_KEY_SIZE], const uint8_t iv[BT_EAD_IV_SIZE], + const uint8_t *encrypted_payload, size_t encrypted_payload_size, + uint8_t *payload) +{ + CHECKIF(session_key == NULL) { + LOG_DBG("session_key is NULL"); + return -EINVAL; + } + + CHECKIF(iv == NULL) { + LOG_DBG("iv is NULL"); + return -EINVAL; + } + + CHECKIF(encrypted_payload == NULL) { + LOG_DBG("encrypted_payload is NULL"); + return -EINVAL; + } + + CHECKIF(payload == NULL) { + LOG_DBG("payload is NULL"); + return -EINVAL; + } + + if (encrypted_payload_size < BT_EAD_RANDOMIZER_SIZE + BT_EAD_MIC_SIZE) { + LOG_DBG("encrypted_payload_size is not large enough."); + return -EINVAL; + } else if (encrypted_payload_size == BT_EAD_RANDOMIZER_SIZE + BT_EAD_MIC_SIZE) { + LOG_WRN("encrypted_payload_size not large enough to contain encrypted data."); + } + + return ead_decrypt(session_key, iv, encrypted_payload, encrypted_payload_size, payload); +} From acfe688c4e1b6ba985bfde0ee38495c78ab06923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Battrel?= Date: Mon, 27 Feb 2023 14:41:22 +0100 Subject: [PATCH 0542/1906] Bluetooth: Tests: Encrypted Advertising Data test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a new BabbleSim test that use the sample data from the Supplement to the Bluetooth Core Specification to validate the Encrypted Advertising Data feature implementation. Signed-off-by: Théo Battrel --- .../encrypted/css_sample_data/CMakeLists.txt | 25 ++++ .../adv/encrypted/css_sample_data/prj.conf | 17 +++ .../encrypted/css_sample_data/src/central.c | 109 ++++++++++++++ .../encrypted/css_sample_data/src/common.c | 39 +++++ .../encrypted/css_sample_data/src/common.h | 137 ++++++++++++++++++ .../adv/encrypted/css_sample_data/src/main.c | 65 +++++++++ .../css_sample_data/src/peripheral.c | 114 +++++++++++++++ .../css_sample_data/test_scripts/_compile.sh | 11 ++ .../css_sample_data/test_scripts/_env.sh | 15 ++ .../css_sample_data/test_scripts/run_tests.sh | 67 +++++++++ tests/bsim/bluetooth/host/compile.sh | 1 + 11 files changed, 600 insertions(+) create mode 100644 tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/CMakeLists.txt create mode 100644 tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/prj.conf create mode 100644 tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/central.c create mode 100644 tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/common.c create mode 100644 tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/common.h create mode 100644 tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/main.c create mode 100644 tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/peripheral.c create mode 100755 tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/test_scripts/_compile.sh create mode 100755 tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/test_scripts/_env.sh create mode 100755 tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/test_scripts/run_tests.sh diff --git a/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/CMakeLists.txt b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/CMakeLists.txt new file mode 100644 index 000000000000..c84c4e378824 --- /dev/null +++ b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/CMakeLists.txt @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +if(NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) + message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set \ + the environment variable BSIM_COMPONENTS_PATH to point to its \ + components folder. More information can be found in \ + https://babblesim.github.io/folder_structure_and_env.html") +endif() + +find_package(Zephyr HINTS $ENV{ZEPHYR_BASE}) +project(bsim_test_ead_css_sample_data) + +target_sources(app PRIVATE + src/main.c + src/common.c + src/central.c + src/peripheral.c +) + +zephyr_include_directories( + $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ + $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ +) diff --git a/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/prj.conf b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/prj.conf new file mode 100644 index 000000000000..97c3bbf7c957 --- /dev/null +++ b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/prj.conf @@ -0,0 +1,17 @@ +CONFIG_BT=y +CONFIG_BT_CENTRAL=y +CONFIG_BT_PERIPHERAL=y +CONFIG_BT_DEVICE_NAME="EAD CSS Sample Data" + +CONFIG_BT_SMP=y +CONFIG_BT_EXT_ADV=y + +CONFIG_BT_EAD=y + +CONFIG_LOG=y +CONFIG_BT_EAD_LOG_LEVEL_DBG=y + +CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=191 +CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=191 + +CONFIG_BT_TESTING=y diff --git a/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/central.c b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/central.c new file mode 100644 index 000000000000..ee2fa5d3da80 --- /dev/null +++ b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/central.c @@ -0,0 +1,109 @@ +/* Copyright (c) 2023 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "common.h" + +extern const struct test_sample_data *sample_data; + +extern int data_set; + +static bool data_parse_cb(struct bt_data *data, void *user_data) +{ + if (data->type == BT_DATA_ENCRYPTED_AD_DATA) { + int err; + uint8_t decrypted_payload[sample_data->size_ad_data]; + struct net_buf_simple decrypted_buf; + size_t decrypted_data_size = BT_EAD_DECRYPTED_PAYLOAD_SIZE(data->data_len); + + if (decrypted_data_size != sample_data->size_ad_data) { + LOG_ERR("Size of decrypted data: %d", decrypted_data_size); + LOG_ERR("Size of sample data: %d", sample_data->size_ad_data); + FAIL("Computed size of data does not match the size of the data from the " + "sample. (data set %d)\n", + data_set); + } + + if (memcmp(sample_data->randomizer_little_endian, data->data, + BT_EAD_RANDOMIZER_SIZE) != 0) { + LOG_ERR("Received Randomizer: %s", + bt_hex(data->data, BT_EAD_RANDOMIZER_SIZE)); + LOG_ERR("Expected Randomizer from sample: %s", + bt_hex(sample_data->randomizer_little_endian, + BT_EAD_RANDOMIZER_SIZE)); + FAIL("Received Randomizer does not match the expected one.\n"); + } + + net_buf_simple_init_with_data(&decrypted_buf, decrypted_payload, + decrypted_data_size); + + err = bt_ead_decrypt(sample_data->session_key, sample_data->iv, data->data, + data->data_len, decrypted_buf.data); + if (err != 0) { + FAIL("Error during decryption.\n"); + } else if (memcmp(decrypted_buf.data, sample_data->ad_data, decrypted_data_size)) { + LOG_HEXDUMP_ERR(decrypted_buf.data, decrypted_data_size, + "Decrypted data from bt_ead_decrypt:"); + LOG_HEXDUMP_ERR(sample_data->ad_data, sample_data->size_ad_data, + "Expected data from sample:"); + FAIL("Decrypted AD data does not match expected sample data. (data set " + "%d)\n", + data_set); + } + + LOG_HEXDUMP_DBG(decrypted_buf.data, decrypted_data_size, "Raw decrypted data: "); + + bt_data_parse(&decrypted_buf, &data_parse_cb, NULL); + + PASS("Central test passed. (data set %d)\n", data_set); + + return false; + } + + LOG_DBG("Parsed data:"); + LOG_DBG("len : %d", data->data_len); + LOG_DBG("type: 0x%02x", data->type); + LOG_HEXDUMP_DBG(data->data, data->data_len, "data:"); + + return true; +} + +static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, + struct net_buf_simple *ad) +{ + char addr_str[BT_ADDR_LE_STR_LEN]; + + bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); + + LOG_DBG("Device found: %s (RSSI %d)", addr_str, rssi); + + bt_data_parse(ad, &data_parse_cb, NULL); +} + +static void start_scan(void) +{ + int err; + + err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); + if (err) { + FAIL("Scanning failed to start (err %d)\n", err); + } + + LOG_DBG("Scanning successfully started"); +} + +void test_central(void) +{ + int err; + + LOG_DBG("Central device. (data set %d)", data_set); + + err = bt_enable(NULL); + if (err) { + FAIL("Bluetooth init failed (err %d)\n", err); + } + + LOG_DBG("Bluetooth initialized"); + + start_scan(); +} diff --git a/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/common.c b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/common.c new file mode 100644 index 000000000000..0f1f42d070ff --- /dev/null +++ b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/common.c @@ -0,0 +1,39 @@ +/* Copyright (c) 2023 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "common.h" + +#include "bs_cmd_line.h" + +#define SAMPLE_DATA_SET_SIZE 2 +static const struct test_sample_data *sample_data_set[] = { + &sample_data_1, + &sample_data_2, +}; +BUILD_ASSERT(ARRAY_SIZE(sample_data_set) == SAMPLE_DATA_SET_SIZE); + +const struct test_sample_data *sample_data; + +int data_set; + +void test_args_parse(int argc, char *argv[]) +{ + bs_args_struct_t args_struct[] = { + { + .dest = &data_set, + .type = 'i', + .name = "{1, 2}", + .option = "data-set", + .descript = "Sample data set ID", + }, + }; + + bs_args_parse_all_cmd_line(argc, argv, args_struct); + + if (data_set < 1 || data_set > SAMPLE_DATA_SET_SIZE) { + data_set = 1; + } + + sample_data = sample_data_set[data_set - 1]; +} diff --git a/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/common.h b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/common.h new file mode 100644 index 000000000000..91a5ff325bb6 --- /dev/null +++ b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/common.h @@ -0,0 +1,137 @@ +/* Copyright (c) 2023 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include + +#include + +#include "common/bt_str.h" + +#include "bs_tracing.h" +#include "bstests.h" + +/** + * @brief Encrypt and authenticate the given advertising data. + * + * This is the same function as @ref bt_ead_encrypt except this one adds the @p + * randomizer parameter to let the user set the randomizer value. + * + * @note This function should only be used for testing purposes, it is only + * available when @kconfig{CONFIG_BT_TESTING} is enabled. + * + * @param[in] session_key Key of @ref BT_EAD_KEY_SIZE bytes used for the + * encryption. + * @param[in] iv Initialisation Vector used to generate the nonce. It must be + * changed each time the Session Key changes. + * @param[in] randomizer Randomizer value used to generate the nonce. The value + * is also placed in front of the encrypted advertising data. + * @param[in] payload Advertising Data to encrypt. Can be multiple advertising + * structures that are concatenated. + * @param[in] payload_size Size of the Advertising Data to encrypt. + * @param[out] encrypted_payload Encrypted Ad Data including the Randomizer and + * the MIC. Size must be at least @ref BT_EAD_RANDOMIZER_SIZE + @p + * payload_size + @ref BT_EAD_MIC_SIZE. Use @ref + * BT_EAD_ENCRYPTED_PAYLOAD_SIZE to get the right size. + * + * @retval 0 Data have been correctly encrypted and authenticated. + * @retval -EIO Error occurred during the encryption or the authentication. + * @retval -EINVAL One of the argument is a NULL pointer. + */ +int bt_test_ead_encrypt(const uint8_t session_key[BT_EAD_KEY_SIZE], + const uint8_t iv[BT_EAD_IV_SIZE], + const uint8_t randomizer[BT_EAD_RANDOMIZER_SIZE], const uint8_t *payload, + size_t payload_size, uint8_t *encrypted_payload); + +#define FAIL(...) \ + do { \ + bst_result = Failed; \ + bs_trace_error_time_line(__VA_ARGS__); \ + } while (0) + +#define PASS(...) \ + do { \ + bst_result = Passed; \ + bs_trace_info_time(1, __VA_ARGS__); \ + } while (0) + +extern enum bst_result_t bst_result; + +#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t) false +#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true) +#define GET_FLAG(flag) (bool)atomic_get(&flag) +#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false) +#define WAIT_FOR_FLAG(flag) \ + while (!(bool)atomic_get(&flag)) { \ + (void)k_sleep(K_MSEC(1)); \ + } + +LOG_MODULE_DECLARE(bt_bsim_ead_sample_data, CONFIG_BT_EAD_LOG_LEVEL); + +struct test_sample_data { + const uint8_t session_key[BT_EAD_KEY_SIZE]; + const uint8_t iv[BT_EAD_IV_SIZE]; + const uint8_t randomizer_little_endian[BT_EAD_RANDOMIZER_SIZE]; + const uint8_t *ad_data; + const size_t size_ad_data; + const uint8_t *ead; + const size_t size_ead; +}; + +/* Encrypted Advertising Data Set 1 (ref: Supplement to the Bluetooth Core + * Specification v11, Part A, 2.3.1) + */ + +#define SIZE_SAMPLE_AD_DATA_1 20 +static const uint8_t sample_ad_data_1[] = {0x0F, 0x09, 0x53, 0x68, 0x6F, 0x72, 0x74, + 0x20, 0x4D, 0x69, 0x6E, 0x69, 0x2D, 0x42, + 0x75, 0x73, 0x03, 0x19, 0x0A, 0x8C}; +BUILD_ASSERT(sizeof(sample_ad_data_1) == SIZE_SAMPLE_AD_DATA_1); + +#define SIZE_SAMPLE_EAD_1 29 +static const uint8_t sample_ead_1[] = { + 0x18, 0xE1, 0x57, 0xCA, 0xDE, 0x74, 0xE4, 0xDC, 0xAF, 0xDC, 0x51, 0xC7, 0x28, 0x28, 0x10, + 0xC2, 0x21, 0x7F, 0x0E, 0x4C, 0xEF, 0x43, 0x43, 0x18, 0x1F, 0xBA, 0x00, 0x69, 0xCC, +}; +BUILD_ASSERT(sizeof(sample_ead_1) == SIZE_SAMPLE_EAD_1); + +static const struct test_sample_data sample_data_1 = { + .session_key = {0x57, 0xA9, 0xDA, 0x12, 0xD1, 0x2E, 0x6E, 0x13, 0x1E, 0x20, 0x61, 0x2A, + 0xD1, 0x0A, 0x6A, 0x19}, + .iv = {0x9E, 0x7A, 0x00, 0xEF, 0xB1, 0x7A, 0xE7, 0x46}, + .randomizer_little_endian = {0x18, 0xE1, 0x57, 0xCA, 0xDE}, + .ad_data = sample_ad_data_1, + .size_ad_data = SIZE_SAMPLE_AD_DATA_1, + .ead = sample_ead_1, + .size_ead = SIZE_SAMPLE_EAD_1, +}; + +/* Encrypted Advertising Data Set 2 (ref: Supplement to the Bluetooth Core + * Specification v11, Part A, 2.3.2) + */ + +#define SIZE_SAMPLE_AD_DATA_2 20 +static const uint8_t sample_ad_data_2[] = {0x0F, 0x09, 0x53, 0x68, 0x6F, 0x72, 0x74, + 0x20, 0x4D, 0x69, 0x6E, 0x69, 0x2D, 0x42, + 0x75, 0x73, 0x03, 0x19, 0x0A, 0x8C}; +BUILD_ASSERT(sizeof(sample_ad_data_2) == SIZE_SAMPLE_AD_DATA_2); + +#define SIZE_SAMPLE_EAD_2 29 +static const uint8_t sample_ead_2[] = {0x8d, 0x1c, 0x97, 0x6e, 0x7a, 0x35, 0x44, 0x40, 0x76, 0x12, + 0x57, 0x88, 0xc2, 0x38, 0xa5, 0x8e, 0x8b, 0xd9, 0xcf, 0xf0, + 0xde, 0xfe, 0x25, 0x1a, 0x8e, 0x72, 0x75, 0x45, 0x4c}; +BUILD_ASSERT(sizeof(sample_ead_2) == SIZE_SAMPLE_EAD_2); + +static const struct test_sample_data sample_data_2 = { + .session_key = {0x57, 0xA9, 0xDA, 0x12, 0xD1, 0x2E, 0x6E, 0x13, 0x1E, 0x20, 0x61, 0x2A, + 0xD1, 0x0A, 0x6A, 0x19}, + .iv = {0x9E, 0x7A, 0x00, 0xEF, 0xB1, 0x7A, 0xE7, 0x46}, + .randomizer_little_endian = {0x8D, 0x1C, 0x97, 0x6E, 0x7A}, + .ad_data = sample_ad_data_2, + .size_ad_data = SIZE_SAMPLE_AD_DATA_2, + .ead = sample_ead_2, + .size_ead = SIZE_SAMPLE_EAD_2, +}; diff --git a/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/main.c b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/main.c new file mode 100644 index 000000000000..bc4ac042030d --- /dev/null +++ b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/main.c @@ -0,0 +1,65 @@ +/* Copyright (c) 2023 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "bs_types.h" +#include "bs_tracing.h" +#include "bstests.h" + +#include +LOG_MODULE_REGISTER(bt_bsim_ead_sample_data, CONFIG_BT_EAD_LOG_LEVEL); + +extern enum bst_result_t bst_result; + +#define WAIT_TIME_S 20 +#define WAIT_TIME (WAIT_TIME_S * 1e6) + +extern void test_central(void); +extern void test_peripheral(void); +extern void test_args_parse(int argc, char *argv[]); + +void test_tick(bs_time_t HW_device_time) +{ + if (bst_result != Passed) { + bst_result = Failed; + bs_trace_error_time_line("Test failed (not passed after %d seconds)\n", + WAIT_TIME_S); + } +} + +static void test_ead_sample_data_init(void) +{ + bst_ticker_set_next_tick_absolute(WAIT_TIME); + bst_result = In_progress; +} + +static const struct bst_test_instance test_def[] = { + { + .test_id = "central", + .test_descr = "Central device", + .test_post_init_f = test_ead_sample_data_init, + .test_tick_f = test_tick, + .test_main_f = test_central, + .test_args_f = test_args_parse, + }, + { + .test_id = "peripheral", + .test_descr = "Peripheral device", + .test_post_init_f = test_ead_sample_data_init, + .test_tick_f = test_tick, + .test_main_f = test_peripheral, + .test_args_f = test_args_parse, + }, + BSTEST_END_MARKER}; + +struct bst_test_list *test_encrypted_ad_data_install(struct bst_test_list *tests) +{ + return bst_add_tests(tests, test_def); +} + +bst_test_install_t test_installers[] = {test_encrypted_ad_data_install, NULL}; + +void main(void) +{ + bst_main(); +} diff --git a/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/peripheral.c b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/peripheral.c new file mode 100644 index 000000000000..fd9b6e9d5f8e --- /dev/null +++ b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/src/peripheral.c @@ -0,0 +1,114 @@ +/* Copyright (c) 2023 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "common.h" + +extern const struct test_sample_data *sample_data; + +extern int data_set; + +static void create_adv(struct bt_le_ext_adv **adv) +{ + int err; + struct bt_le_adv_param params; + + memset(¶ms, 0, sizeof(struct bt_le_adv_param)); + + params.options |= BT_LE_ADV_OPT_CONNECTABLE; + params.options |= BT_LE_ADV_OPT_EXT_ADV; + + params.id = BT_ID_DEFAULT; + params.sid = 0; + params.interval_min = BT_GAP_ADV_SLOW_INT_MIN; + params.interval_max = BT_GAP_ADV_SLOW_INT_MAX; + + err = bt_le_ext_adv_create(¶ms, NULL, adv); + if (err) { + FAIL("Failed to create advertiser (%d)\n", err); + } +} + +static void start_adv(struct bt_le_ext_adv *adv) +{ + int err; + int32_t timeout = 0; + uint8_t num_events = 0; + + struct bt_le_ext_adv_start_param start_params; + + start_params.timeout = timeout; + start_params.num_events = num_events; + + err = bt_le_ext_adv_start(adv, &start_params); + if (err) { + FAIL("Failed to start advertiser (%d)\n", err); + } + + LOG_DBG("Advertiser started"); +} + +static void set_ad_data(struct bt_le_ext_adv *adv) +{ + int err; + + uint8_t ead[sample_data->size_ead]; + struct bt_data ead_struct; + size_t size_ad_data = sample_data->size_ad_data; + size_t size_ead = BT_EAD_ENCRYPTED_PAYLOAD_SIZE(size_ad_data); + + if (size_ead != sample_data->size_ead) { + LOG_ERR("Size of ead: %zu\n", size_ead); + LOG_ERR("Size of sample_ead: %zu", sample_data->size_ead); + FAIL("Computed size of encrypted data does not match the size of the encrypted " + "data from the sample. (data set %d)\n", + data_set); + } + + err = bt_test_ead_encrypt(sample_data->session_key, sample_data->iv, + sample_data->randomizer_little_endian, sample_data->ad_data, + size_ad_data, ead); + if (err != 0) { + FAIL("Error during encryption.\n"); + } else if (memcmp(ead, sample_data->ead, sample_data->size_ead) != 0) { + LOG_HEXDUMP_ERR(ead, size_ead, "Encrypted data from bt_ead_encrypt:"); + LOG_HEXDUMP_ERR(sample_data->ead, sample_data->size_ead, + "Encrypted data from sample:"); + FAIL("Encrypted AD data does not match the ones provided in the sample. (data set " + "%d)\n", + data_set); + } + + LOG_HEXDUMP_DBG(ead, size_ead, "Encrypted data:"); + + ead_struct.data_len = size_ead; + ead_struct.type = BT_DATA_ENCRYPTED_AD_DATA; + ead_struct.data = ead; + + err = bt_le_ext_adv_set_data(adv, &ead_struct, 1, NULL, 0); + if (err) { + FAIL("Failed to set advertising data (%d)\n", err); + } + + PASS("Peripheral test passed. (data set %d)\n", data_set); +} + +void test_peripheral(void) +{ + int err; + struct bt_le_ext_adv *adv = NULL; + + LOG_DBG("Peripheral device. (data set %d)", data_set); + + err = bt_enable(NULL); + if (err) { + FAIL("Bluetooth init failed (err %d)\n", err); + } + + LOG_DBG("Bluetooth initialized"); + + create_adv(&adv); + start_adv(adv); + + set_ad_data(adv); +} diff --git a/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/test_scripts/_compile.sh b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/test_scripts/_compile.sh new file mode 100755 index 000000000000..42376ab52319 --- /dev/null +++ b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/test_scripts/_compile.sh @@ -0,0 +1,11 @@ +#!/bin/env bash +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +set -eu +bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" + +source "${bash_source_dir}/_env.sh" + +west build -b nrf52_bsim && \ + cp -v build/zephyr/zephyr.exe "${test_exe}" diff --git a/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/test_scripts/_env.sh b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/test_scripts/_env.sh new file mode 100755 index 000000000000..c0d2ab3b7ebb --- /dev/null +++ b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/test_scripts/_env.sh @@ -0,0 +1,15 @@ +#!/bin/env bash +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +set -eu +bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" + +: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" + +test_name="$(basename "$(realpath "$bash_source_dir/..")")" +bsim_bin="${BSIM_OUT_PATH}/bin" +verbosity_level=2 +BOARD="${BOARD:-nrf52_bsim}" +simulation_id="$test_name" +test_exe="${bsim_bin}/bs_${BOARD}_tests_bsim_bluetooth_host_adv_encrypted_${test_name}_prj_conf" diff --git a/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/test_scripts/run_tests.sh b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/test_scripts/run_tests.sh new file mode 100755 index 000000000000..13dc7f31ef2f --- /dev/null +++ b/tests/bsim/bluetooth/host/adv/encrypted/css_sample_data/test_scripts/run_tests.sh @@ -0,0 +1,67 @@ +#!/bin/env bash +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +set -eu +bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" + +# Read variable definitions output by _env.sh +source "${bash_source_dir}/_env.sh" + +process_ids="" +exit_code=0 + +function Execute() { + if [ ! -f $1 ]; then + echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ + compile it?)\e[39m" + exit 1 + fi + timeout 30 $@ & + process_ids="$process_ids $!" +} + +: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" + +cd ${BSIM_OUT_PATH}/bin + +data_set=1 + +Execute "$test_exe" \ + -v=${verbosity_level} -s="${simulation_id}_${data_set}" -d=0 -testid=central \ + -RealEncryption=1 -argstest data-set="${data_set}" + +Execute "$test_exe" \ + -v=${verbosity_level} -s="${simulation_id}_${data_set}" -d=1 -testid=peripheral \ + -RealEncryption=1 -argstest data-set="${data_set}" + +Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s="${simulation_id}_${data_set}" \ + -D=2 -sim_length=60e6 $@ + +for process_id in $process_ids; do + wait $process_id || let "exit_code=$?" +done +process_ids='' + +data_set=2 + +Execute "$test_exe" \ + -v=${verbosity_level} -s="${simulation_id}_${data_set}" -d=0 -testid=central \ + -RealEncryption=1 -argstest data-set="${data_set}" + +Execute "$test_exe" \ + -v=${verbosity_level} -s="${simulation_id}_${data_set}" -d=1 -testid=peripheral \ + -RealEncryption=1 -argstest data-set="${data_set}" + +Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s="${simulation_id}_${data_set}" \ + -D=2 -sim_length=60e6 $@ + +for process_id in $process_ids; do + wait $process_id || let "exit_code=$?" +done + +if [ ${exit_code} -ne 0 ]; then + exit_code=1 +fi + +exit $exit_code # the last exit code != 0 diff --git a/tests/bsim/bluetooth/host/compile.sh b/tests/bsim/bluetooth/host/compile.sh index 3a06e04165ec..5fc79ab42536 100755 --- a/tests/bsim/bluetooth/host/compile.sh +++ b/tests/bsim/bluetooth/host/compile.sh @@ -24,6 +24,7 @@ app=tests/bsim/bluetooth/host/adv/resume conf_file=prj_2.conf compile app=tests/bsim/bluetooth/host/adv/chain compile app=tests/bsim/bluetooth/host/adv/periodic compile app=tests/bsim/bluetooth/host/adv/periodic conf_file=prj_long_data.conf compile +app=tests/bsim/bluetooth/host/adv/encrypted/css_sample_data compile app=tests/bsim/bluetooth/host/att/eatt conf_file=prj_collision.conf compile app=tests/bsim/bluetooth/host/att/eatt conf_file=prj_multiple_conn.conf compile From 3d44508c387b8b1c0912b909db44901f0a2355f6 Mon Sep 17 00:00:00 2001 From: Ramesh Babu B Date: Fri, 17 Mar 2023 19:20:39 +0530 Subject: [PATCH 0543/1906] drivers: spi: Add Intel SPI penwell driver Added support for intel pch penwell spi driver. Signed-off-by: Ramesh Babu B --- drivers/spi/CMakeLists.txt | 1 + drivers/spi/Kconfig | 2 + drivers/spi/Kconfig.pw | 18 + drivers/spi/spi_pw.c | 897 ++++++++++++++++++++++++ drivers/spi/spi_pw.h | 224 ++++++ dts/bindings/spi/intel,penwell-spi.yaml | 40 ++ 6 files changed, 1182 insertions(+) create mode 100644 drivers/spi/Kconfig.pw create mode 100644 drivers/spi/spi_pw.c create mode 100644 drivers/spi/spi_pw.h create mode 100644 dts/bindings/spi/intel,penwell-spi.yaml diff --git a/drivers/spi/CMakeLists.txt b/drivers/spi/CMakeLists.txt index 54a2d5f569ad..d86005d489bf 100644 --- a/drivers/spi/CMakeLists.txt +++ b/drivers/spi/CMakeLists.txt @@ -35,6 +35,7 @@ zephyr_library_sources_ifdef(CONFIG_SPI_PL022 spi_pl022.c) zephyr_library_sources_ifdef(CONFIG_SPI_ANDES_ATCSPI200 spi_andes_atcspi200.c) zephyr_library_sources_ifdef(CONFIG_NXP_S32_SPI spi_nxp_s32.c) zephyr_library_sources_ifdef(CONFIG_SPI_XMC4XXX spi_xmc4xxx.c) +zephyr_library_sources_ifdef(CONFIG_SPI_PW spi_pw.c) zephyr_library_sources_ifdef(CONFIG_SPI_ASYNC spi_signal.c) zephyr_library_sources_ifdef(CONFIG_USERSPACE spi_handlers.c) diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index df2fa6a5c826..79708f6b4200 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -109,4 +109,6 @@ source "drivers/spi/Kconfig.nxp_s32" source "drivers/spi/Kconfig.xmc4xxx" +source "drivers/spi/Kconfig.pw" + endif # SPI diff --git a/drivers/spi/Kconfig.pw b/drivers/spi/Kconfig.pw new file mode 100644 index 000000000000..9e6b7400f2b6 --- /dev/null +++ b/drivers/spi/Kconfig.pw @@ -0,0 +1,18 @@ +# Copyright (c) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +menuconfig SPI_PW + bool "Penwell SPI driver" + default y + depends on DT_HAS_INTEL_PENWELL_SPI_ENABLED + help + Enable the Penwell SPI driver. + +if SPI_PW + +config SPI_PW_INTERRUPT + bool "Penwell SPI Interrupt mode Support" + help + Enable Interrupt support for the SPI Driver. + +endif # SPI_PW diff --git a/drivers/spi/spi_pw.c b/drivers/spi/spi_pw.c new file mode 100644 index 000000000000..e2abeefe1ce9 --- /dev/null +++ b/drivers/spi/spi_pw.c @@ -0,0 +1,897 @@ +/* + * Copyright (c) 2023 Intel Corporation. + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT intel_penwell_spi + +#include +#include +#include +#include +#include + +#if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie) +BUILD_ASSERT(IS_ENABLED(CONFIG_PCIE), "DT need CONFIG_PCIE"); +#include +#endif + +#include +LOG_MODULE_REGISTER(spi_pw, CONFIG_SPI_LOG_LEVEL); + +#include "spi_pw.h" + +static uint32_t spi_pw_reg_read(const struct device *dev, uint32_t offset) +{ + return sys_read32(DEVICE_MMIO_GET(dev) + offset); +} + +static void spi_pw_reg_write(const struct device *dev, + uint32_t offset, + uint32_t val) +{ + return sys_write32(val, DEVICE_MMIO_GET(dev) + offset); +} + +static void spi_pw_ssp_reset(const struct device *dev) +{ + /* Bring the controller from reset state in to operational mode */ + spi_pw_reg_write(dev, PW_SPI_REG_RESETS, 0x00); + spi_pw_reg_write(dev, PW_SPI_REG_RESETS, PW_SPI_INST_RESET); +} + +#ifndef CONFIG_SPI_PW_INTERRUPT +static bool is_spi_transfer_ongoing(struct spi_pw_data *spi) +{ + return spi_context_tx_on(&spi->ctx) || spi_context_rx_on(&spi->ctx); +} +#endif + +static void spi_pw_enable_cs_hw_ctrl(const struct device *dev) +{ + uint32_t cs_ctrl; + + cs_ctrl = spi_pw_reg_read(dev, PW_SPI_REG_CS_CTRL); + cs_ctrl &= PW_SPI_CS_CTRL_HW_MODE; + spi_pw_reg_write(dev, PW_SPI_REG_CS_CTRL, cs_ctrl); +} + +static void spi_pw_cs_sw_ctrl(const struct device *dev, bool enable) +{ + uint32_t cs_ctrl; + + cs_ctrl = spi_pw_reg_read(dev, PW_SPI_REG_CS_CTRL); + cs_ctrl &= ~(PW_SPI_CS_CTRL_CS_MASK); + /* Enable chip select software control method */ + cs_ctrl |= PW_SPI_CS_CTRL_SW_MODE; + + if (enable) { + cs_ctrl &= PW_SPI_CS_LOW; + } else { + cs_ctrl |= PW_SPI_CS_HIGH; + } + + spi_pw_reg_write(dev, PW_SPI_REG_CS_CTRL, cs_ctrl); +} + +#ifdef CONFIG_SPI_PW_INTERRUPT +static void spi_pw_intr_enable(const struct device *dev, bool rx_mask) +{ + uint32_t ctrlr1; + + ctrlr1 = spi_pw_reg_read(dev, PW_SPI_REG_CTRLR1); + if (rx_mask) { + ctrlr1 |= PW_SPI_INTR_BITS; + } else { + ctrlr1 |= PW_SPI_INTR_BITS; + ctrlr1 &= ~(PW_SPI_INTR_MASK_RX); + } + spi_pw_reg_write(dev, PW_SPI_REG_CTRLR1, ctrlr1); +} + +static void spi_pw_intr_disable(const struct device *dev) +{ + uint32_t ctrlr1; + + ctrlr1 = spi_pw_reg_read(dev, PW_SPI_REG_CTRLR1); + ctrlr1 &= ~(PW_SPI_INTR_BITS); + spi_pw_reg_write(dev, PW_SPI_REG_CTRLR1, ctrlr1); +} +#endif + +static void spi_pw_ssp_enable(const struct device *dev) +{ + uint32_t ctrlr0; + + ctrlr0 = spi_pw_reg_read(dev, PW_SPI_REG_CTRLR0); + ctrlr0 |= PW_SPI_CTRLR0_SSE_BIT; + spi_pw_reg_write(dev, PW_SPI_REG_CTRLR0, ctrlr0); + +} + +static void spi_pw_ssp_disable(const struct device *dev) +{ + uint32_t ctrlr0; + + ctrlr0 = spi_pw_reg_read(dev, PW_SPI_REG_CTRLR0); + ctrlr0 &= ~(PW_SPI_CTRLR0_SSE_BIT); + spi_pw_reg_write(dev, PW_SPI_REG_CTRLR0, ctrlr0); +} + +static bool is_pw_ssp_busy(const struct device *dev) +{ + uint32_t status; + + status = spi_pw_reg_read(dev, PW_SPI_REG_SSSR); + return (status & PW_SPI_SSSR_BSY_BIT) ? true : false; +} + +static uint8_t spi_pw_get_frame_size(const struct spi_config *config) +{ + uint8_t dfs = SPI_WORD_SIZE_GET(config->operation); + + dfs /= PW_SPI_WIDTH_8BITS; + + if ((dfs == 0) || (dfs > PW_SPI_FRAME_SIZE_4_BYTES)) { + LOG_WRN("Unsupported dfs, 1-byte size will be used"); + dfs = PW_SPI_FRAME_SIZE_1_BYTE; + } + + return dfs; +} + +void spi_pw_cs_ctrl_enable(const struct device *dev, bool enable) +{ + struct spi_pw_data *spi = dev->data; + + if (enable == true) { + if (spi->cs_mode == CS_SW_MODE) { + spi_pw_cs_sw_ctrl(dev, true); + } else if (spi->cs_mode == CS_GPIO_MODE) { + spi_context_cs_control(&spi->ctx, true); + } + } else { + if (spi->cs_mode == CS_SW_MODE) { + spi_pw_cs_sw_ctrl(dev, false); + } else if (spi->cs_mode == CS_GPIO_MODE) { + spi_context_cs_control(&spi->ctx, false); + } + } +} + +static void spi_pw_cs_ctrl_init(const struct device *dev) +{ + uint32_t cs_ctrl; + struct spi_pw_data *spi = dev->data; + + /* Enable chip select output CS0/CS1 */ + cs_ctrl = spi_pw_reg_read(dev, PW_SPI_REG_CS_CTRL); + + if (spi->cs_output == PW_SPI_CS1_OUTPUT_SELECT) { + cs_ctrl &= ~(PW_SPI_CS_CTRL_CS_MASK << PW_SPI_CS_EN_SHIFT); + /* Set chip select CS1 */ + cs_ctrl |= PW_SPI_CS1_SELECT; + } else { + /* Set chip select CS0 */ + cs_ctrl &= ~(PW_SPI_CS_CTRL_CS_MASK << PW_SPI_CS_EN_SHIFT); + } + + spi_pw_reg_write(dev, PW_SPI_REG_CS_CTRL, cs_ctrl); + + if (spi->cs_mode == CS_HW_MODE) { + spi_pw_enable_cs_hw_ctrl(dev); + } else if (spi->cs_mode == CS_SW_MODE) { + spi_pw_cs_sw_ctrl(dev, false); + } else if (spi->cs_mode == CS_GPIO_MODE) { + spi_pw_cs_sw_ctrl(dev, false); + } +} + +static void spi_pw_tx_thld_set(const struct device *dev) +{ + uint32_t reg_data; + + /* Tx threshold */ + reg_data = spi_pw_reg_read(dev, PW_SPI_REG_SITF); + /* mask high water mark bits in tx fifo reg */ + reg_data &= ~(PW_SPI_WM_MASK); + /* mask low water mark bits in tx fifo reg */ + reg_data &= ~(PW_SPI_WM_MASK << PW_SPI_SITF_LWMTF_SHIFT); + reg_data |= (PW_SPI_SITF_HIGH_WM_DFLT | PW_SPI_SITF_LOW_WM_DFLT); + spi_pw_reg_write(dev, PW_SPI_REG_SITF, reg_data); +} + +static void spi_pw_rx_thld_set(const struct device *dev, + struct spi_pw_data *spi) +{ + uint32_t reg_data; + + /* Rx threshold */ + reg_data = spi_pw_reg_read(dev, PW_SPI_REG_SIRF); + reg_data = (uint32_t) ~(PW_SPI_WM_MASK); + reg_data = PW_SPI_SIRF_WM_DFLT; + if (spi->ctx.rx_len && spi->ctx.rx_len < spi->fifo_depth) { + reg_data = spi->ctx.rx_len - 1; + } + spi_pw_reg_write(dev, PW_SPI_REG_SIRF, reg_data); +} + +static int spi_pw_set_data_size(const struct device *dev, + const struct spi_config *config) +{ + uint32_t ctrlr0; + + ctrlr0 = spi_pw_reg_read(dev, PW_SPI_REG_CTRLR0); + + /* Full duplex mode */ + ctrlr0 &= ~(PW_SPI_CTRLR0_MOD_BIT); + + ctrlr0 &= PW_SPI_CTRLR0_DATA_MASK; + ctrlr0 &= PW_SPI_CTRLR0_EDSS_MASK; + + /* Set the word size */ + if (SPI_WORD_SIZE_GET(config->operation) == 4) { + ctrlr0 |= PW_SPI_DATA_SIZE_4_BIT; + } else if (SPI_WORD_SIZE_GET(config->operation) == 8) { + ctrlr0 |= PW_SPI_DATA_SIZE_8_BIT; + } else if (SPI_WORD_SIZE_GET(config->operation) == 16) { + ctrlr0 |= PW_SPI_DATA_SIZE_16_BIT; + } else if (SPI_WORD_SIZE_GET(config->operation) == 32) { + ctrlr0 |= PW_SPI_DATA_SIZE_32_BIT; + } else { + LOG_ERR("Invalid word size"); + return -ENOTSUP; + } + + spi_pw_reg_write(dev, PW_SPI_REG_CTRLR0, ctrlr0); + + return 0; +} + +static void spi_pw_config_phase_polarity(const struct device *dev, + const struct spi_config *config) +{ + uint8_t mode; + uint32_t ctrlr1; + + ctrlr1 = spi_pw_reg_read(dev, PW_SPI_REG_CTRLR1); + + mode = (SPI_MODE_GET(config->operation) & SPI_MODE_CPOL) | + (SPI_MODE_GET(config->operation) & SPI_MODE_CPHA); + + LOG_DBG("mode: 0x%x", (mode >> 1)); + switch (mode >> 1) { + case SPI_PW_MODE0: + ctrlr1 &= ~(PW_SPI_CTRL1_SPO_SPH_MASK); + ctrlr1 &= ~(PW_SPI_CTRL1_SPO_BIT); + ctrlr1 &= ~(PW_SPI_CTRL1_SPH_BIT); + break; + case SPI_PW_MODE1: + ctrlr1 &= ~(PW_SPI_CTRL1_SPO_SPH_MASK); + ctrlr1 |= PW_SPI_CTRL1_SPO_BIT; + ctrlr1 &= ~(PW_SPI_CTRL1_SPH_BIT); + break; + case SPI_PW_MODE2: + ctrlr1 &= ~(PW_SPI_CTRL1_SPO_SPH_MASK); + ctrlr1 &= ~(PW_SPI_CTRL1_SPO_BIT); + ctrlr1 |= PW_SPI_CTRL1_SPH_BIT; + break; + case SPI_PW_MODE3: + ctrlr1 |= PW_SPI_CTRL1_SPO_BIT; + ctrlr1 |= PW_SPI_CTRL1_SPH_BIT; + break; + } + + /* Set Polarity & Phase */ + spi_pw_reg_write(dev, PW_SPI_REG_CTRLR1, ctrlr1); +} + +static void spi_pw_enable_clk(const struct device *dev) +{ + uint32_t clks; + + /*Update M:N value & enable clock */ + clks = spi_pw_reg_read(dev, PW_SPI_REG_CLKS); + clks &= ~(PW_SPI_CLKS_MVAL_MASK); + clks &= ~(PW_SPI_CLKS_NVAL_MASK); + clks |= (PW_SPI_CLKS_MVAL | PW_SPI_CLKS_NVAL | + PW_SPI_CLKS_EN_BIT | PW_SPI_CLKS_UPDATE_BIT); + spi_pw_reg_write(dev, PW_SPI_REG_CLKS, clks); +} + +static void spi_pw_config_clk(const struct device *dev, + const struct spi_pw_config *info, + const struct spi_config *config) +{ + uint32_t ctrlr0, scr; + + /* Update scr control bits */ + if (!config->frequency) { + scr = PW_SPI_BR_2MHZ; + } else if (config->frequency > PW_SPI_BR_MAX_FRQ) { + scr = (info->clock_freq / PW_SPI_BR_MAX_FRQ) - 1; + } else { + scr = (info->clock_freq / config->frequency) - 1; + } + ctrlr0 = spi_pw_reg_read(dev, PW_SPI_REG_CTRLR0); + + ctrlr0 &= ~(PW_SPI_SCR_MASK); + ctrlr0 |= (scr << PW_SPI_SCR_SHIFT); + spi_pw_reg_write(dev, PW_SPI_REG_CTRLR0, ctrlr0); +} + +static void spi_pw_completed(const struct device *dev, int err) +{ + struct spi_pw_data *spi = dev->data; + + if (!err && (spi_context_tx_on(&spi->ctx) || + spi_context_rx_on(&spi->ctx))) { + return; + } + + /* need to give time for FIFOs to drain before issuing more commands */ + while (is_pw_ssp_busy(dev)) { + } + +#ifdef CONFIG_SPI_PW_INTERRUPT + /* Disabling interrupts */ + spi_pw_intr_disable(dev); +#endif + + /* Disabling the controller operation, which also clear's all status bits + * in status register + */ + spi_pw_ssp_disable(dev); + + spi_pw_cs_ctrl_enable(dev, false); + + LOG_DBG("SPI transaction completed %s error\n", + err ? "with" : "without"); + + spi_context_complete(&spi->ctx, dev, err); +} + +static void spi_pw_clear_intr(const struct device *dev) +{ + uint32_t sssr; + + sssr = spi_pw_reg_read(dev, PW_SPI_REG_SSSR); + sssr &= ~(PW_SPI_INTR_ERRORS_MASK); + spi_pw_reg_write(dev, PW_SPI_REG_SSSR, sssr); +} + +static int spi_pw_get_tx_fifo_level(const struct device *dev) +{ + uint32_t tx_fifo_level; + + tx_fifo_level = spi_pw_reg_read(dev, PW_SPI_REG_SITF); + + tx_fifo_level = ((tx_fifo_level & PW_SPI_SITF_SITFL_MASK) >> + PW_SPI_SITF_SITFL_SHIFT); + + return tx_fifo_level; +} + +static int spi_pw_get_rx_fifo_level(const struct device *dev) +{ + uint32_t rx_fifo_level; + + rx_fifo_level = spi_pw_reg_read(dev, PW_SPI_REG_SIRF); + rx_fifo_level = ((rx_fifo_level & PW_SPI_SIRF_SIRFL_MASK) >> + PW_SPI_SIRF_SIRFL_SHIFT); + + return rx_fifo_level; +} + +static void spi_pw_reset_tx_fifo_level(const struct device *dev) +{ + uint32_t tx_fifo_level; + + tx_fifo_level = spi_pw_reg_read(dev, PW_SPI_REG_SITF); + tx_fifo_level &= ~(PW_SPI_SITF_SITFL_MASK); + spi_pw_reg_write(dev, PW_SPI_REG_SITF, tx_fifo_level); + +} + +static void spi_pw_update_rx_fifo_level(uint32_t len, + const struct device *dev) +{ + uint32_t rx_fifo_level; + + rx_fifo_level = spi_pw_reg_read(dev, PW_SPI_REG_SIRF); + rx_fifo_level &= ~(PW_SPI_SIRF_SIRFL_MASK); + rx_fifo_level |= (len << PW_SPI_SIRF_SIRFL_SHIFT); + spi_pw_reg_write(dev, PW_SPI_REG_SIRF, rx_fifo_level); +} + +static void spi_pw_tx_data(const struct device *dev) +{ + struct spi_pw_data *spi = dev->data; + uint32_t data = 0U; + int32_t fifo_len; + + if (spi_context_rx_on(&spi->ctx)) { + fifo_len = spi->fifo_depth - + spi_pw_get_tx_fifo_level(dev) - + spi_pw_get_rx_fifo_level(dev); + if (fifo_len < 0) { + fifo_len = 0U; + } + } else { + fifo_len = spi->fifo_depth - spi_pw_get_tx_fifo_level(dev); + } + + while (fifo_len > 0) { + if (spi_context_tx_buf_on(&spi->ctx)) { + switch (spi->dfs) { + case 1: + data = UNALIGNED_GET((uint8_t *) + (spi->ctx.tx_buf)); + break; + case 2: + data = UNALIGNED_GET((uint16_t *) + (spi->ctx.tx_buf)); + break; + case 4: + data = UNALIGNED_GET((uint32_t *) + (spi->ctx.tx_buf)); + break; + } + } else if (spi_context_rx_on(&spi->ctx)) { + if ((int)(spi->ctx.rx_len - spi->fifo_diff) <= 0) { + break; + } + + data = 0U; + } else if (spi_context_tx_on(&spi->ctx)) { + data = 0U; + } else { + break; + } + + spi_pw_reg_write(dev, PW_SPI_REG_SSDR, data); + + spi_context_update_tx(&spi->ctx, spi->dfs, 1); + spi->fifo_diff++; + fifo_len--; + } + + if (!spi_context_tx_on(&spi->ctx)) { + spi_pw_reset_tx_fifo_level(dev); + } +} + +static void spi_pw_rx_data(const struct device *dev) +{ + struct spi_pw_data *spi = dev->data; + + while (spi_pw_get_rx_fifo_level(dev)) { + uint32_t data = spi_pw_reg_read(dev, PW_SPI_REG_SSDR); + + if (spi_context_rx_buf_on(&spi->ctx)) { + switch (spi->dfs) { + case 1: + UNALIGNED_PUT(data, + (uint8_t *)spi->ctx.rx_buf); + break; + case 2: + UNALIGNED_PUT(data, + (uint16_t *)spi->ctx.rx_buf); + break; + case 4: + UNALIGNED_PUT(data, + (uint32_t *)spi->ctx.rx_buf); + break; + } + } + + spi_context_update_rx(&spi->ctx, spi->dfs, 1); + spi->fifo_diff--; + } + + if (!spi->ctx.rx_len && spi->ctx.tx_len < spi->fifo_depth) { + spi_pw_update_rx_fifo_level(spi->ctx.tx_len - 1, dev); + } else if (spi_pw_get_rx_fifo_level(dev) >= spi->ctx.rx_len) { + spi_pw_update_rx_fifo_level(spi->ctx.rx_len - 1, dev); + } +} + +static int spi_pw_transfer(const struct device *dev) +{ + uint32_t intr_status; + int err; + + intr_status = spi_pw_reg_read(dev, PW_SPI_REG_SSSR); + + if (intr_status & PW_SPI_SSSR_ROR_BIT) { + LOG_ERR("Receive FIFO overrun"); + err = -EIO; + goto out; + } + + if (intr_status & PW_SPI_SSSR_TUR_BIT) { + LOG_ERR("Transmit FIFO underrun"); + err = -EIO; + goto out; + } + + if (intr_status & PW_SPI_SSSR_TINT_BIT) { + LOG_ERR("Receiver timeout interrupt"); + err = -EIO; + goto out; + } + + err = 0; + + if (intr_status & PW_SPI_SSSR_RNE_BIT) { + spi_pw_rx_data(dev); + } + + if (intr_status & PW_SPI_SSSR_TNF_BIT) { + spi_pw_tx_data(dev); + } + +out: + if (err) { + spi_pw_clear_intr(dev); + } + + return err; +} + +static int spi_pw_configure(const struct device *dev, + const struct spi_pw_config *info, + struct spi_pw_data *spi, + const struct spi_config *config) +{ + int err; + + /* At this point, it's mandatory to set this on the context! */ + spi->ctx.config = config; + + if (!spi->ctx.config->cs) { + if (spi->cs_mode == CS_GPIO_MODE) { + LOG_DBG("cs gpio is NULL, switch to hw mode"); + spi->cs_mode = CS_HW_MODE; + spi_pw_enable_cs_hw_ctrl(dev); + } + } + + if (config->operation & SPI_HALF_DUPLEX) { + LOG_ERR("Half-duplex not supported"); + return -ENOTSUP; + } + + /* Verify if requested op mode is relevant to this controller */ + if (config->operation & SPI_OP_MODE_SLAVE) { + LOG_ERR("Slave mode not supported"); + return -ENOTSUP; + } + + if ((config->operation & SPI_TRANSFER_LSB) || + (IS_ENABLED(CONFIG_SPI_EXTENDED_MODES) && + (config->operation & (SPI_LINES_DUAL | + SPI_LINES_QUAD | + SPI_LINES_OCTAL)))) { + LOG_ERR("Extended mode Unsupported configuration"); + return -EINVAL; + } + + if (config->operation & SPI_FRAME_FORMAT_TI) { + LOG_ERR("TI frame format not supported"); + return -ENOTSUP; + } + + if (config->operation & SPI_HOLD_ON_CS) { + LOG_ERR("Chip select hold not supported"); + return -ENOTSUP; + } + + /* Set mode & data size */ + err = spi_pw_set_data_size(dev, config); + + if (err) { + LOG_ERR("Invalid data size"); + return -ENOTSUP; + } + + /* Set Polarity & Phase */ + spi_pw_config_phase_polarity(dev, config); + + /* enable clock */ + spi_pw_enable_clk(dev); + + /* configure */ + spi_pw_config_clk(dev, info, config); + + return 0; +} + +static int transceive(const struct device *dev, + const struct spi_config *config, + const struct spi_buf_set *tx_bufs, + const struct spi_buf_set *rx_bufs, + bool asynchronous, + spi_callback_t cb, + void *userdata) +{ + const struct spi_pw_config *info = dev->config; + struct spi_pw_data *spi = dev->data; + int err; + + if (!tx_bufs && !rx_bufs) { + LOG_ERR(" Tx & Rx buff null"); + return 0; + } + + if (asynchronous) { + LOG_ERR("Async not supported"); + return -ENOTSUP; + } + + spi_context_lock(&spi->ctx, asynchronous, cb, userdata, config); + + /* Configure */ + err = spi_pw_configure(dev, info, spi, config); + if (err) { + LOG_ERR("spi pw config fail"); + goto out; + } + + /* Frame size in number of data bytes */ + spi->dfs = spi_pw_get_frame_size(config); + spi_context_buffers_setup(&spi->ctx, tx_bufs, rx_bufs, + spi->dfs); + + spi->fifo_diff = 0U; + + /* Tx threshold */ + spi_pw_tx_thld_set(dev); + + /* Rx threshold */ + spi_pw_rx_thld_set(dev, spi); + + spi_pw_cs_ctrl_enable(dev, true); + + /* Enable ssp operation */ + spi_pw_ssp_enable(dev); + +#ifdef CONFIG_SPI_PW_INTERRUPT + LOG_DBG("Interrupt Mode"); + + /* Enable interrupts */ + if (rx_bufs) { + spi_pw_intr_enable(dev, true); + } else { + spi_pw_intr_enable(dev, false); + } + + err = spi_context_wait_for_completion(&spi->ctx); +#else + LOG_DBG("Polling Mode"); + + do { + err = spi_pw_transfer(dev); + } while ((!err) && is_spi_transfer_ongoing(spi)); + + spi_pw_completed(dev, err); +#endif + +out: + spi_context_release(&spi->ctx, err); + return err; +} + +static int spi_pw_transceive(const struct device *dev, + const struct spi_config *config, + const struct spi_buf_set *tx_bufs, + const struct spi_buf_set *rx_bufs) +{ + LOG_DBG("%p, %p, %p\n", dev, tx_bufs, rx_bufs); + return transceive(dev, config, tx_bufs, rx_bufs, + false, NULL, NULL); +} + +#ifdef CONFIG_SPI_ASYNC +static int spi_pw_transceive_async(const struct device *dev, + const struct spi_config *config, + const struct spi_buf_set *tx_bufs, + const struct spi_buf_set *rx_bufs, + spi_callback_t cb, + void *userdata) +{ + LOG_DBG("%p, %p, %p, %p, %p\n", dev, tx_bufs, rx_bufs, + cb, userdata); + + return transceive(dev, config, tx_bufs, rx_bufs, true, + cb, userdata); +} +#endif /* CONFIG_SPI_ASYNC */ + +static int spi_pw_release(const struct device *dev, + const struct spi_config *config) +{ + struct spi_pw_data *spi = dev->data; + + if (!spi_context_configured(&spi->ctx, config)) { + return -EINVAL; + } + + spi_context_unlock_unconditionally(&spi->ctx); + + return 0; +} + +#ifdef CONFIG_SPI_PW_INTERRUPT +static void spi_pw_isr(const void *arg) +{ + const struct device *dev = (const struct device *)arg; + int err; + + err = spi_pw_transfer(dev); + spi_pw_completed(dev, err); +} +#endif + +static const struct spi_driver_api pw_spi_api = { + .transceive = spi_pw_transceive, + .release = spi_pw_release, +#ifdef CONFIG_SPI_ASYNC + .transceive_async = spi_pw_transceive_async, +#endif /* CONFIG_SPI_ASYNC */ +}; + +static int spi_pw_init(const struct device *dev) +{ + const struct spi_pw_config *info = dev->config; + struct spi_pw_data *spi = dev->data; + int err; + +#if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie) + if (info->pcie) { + struct pcie_bar mbar; + + if (info->pcie->bdf == PCIE_BDF_NONE) { + LOG_ERR("Cannot probe PCI device"); + return -ENODEV; + } + + if (!pcie_probe_mbar(info->pcie->bdf, 0, &mbar)) { + LOG_ERR("MBAR not found"); + return -EINVAL; + } + + pcie_set_cmd(info->pcie->bdf, PCIE_CONF_CMDSTAT_MEM, + true); + + device_map(DEVICE_MMIO_RAM_PTR(dev), mbar.phys_addr, + mbar.size, K_MEM_CACHE_NONE); + + pcie_set_cmd(info->pcie->bdf, + PCIE_CONF_CMDSTAT_MASTER, + true); + + } else { + DEVICE_MMIO_MAP(dev, K_MEM_CACHE_NONE); + } +#else + DEVICE_MMIO_MAP(dev, K_MEM_CACHE_NONE); +#endif + + /* Bring ssp out of reset */ + spi_pw_ssp_reset(dev); + + /* Disable ssp operation */ + spi_pw_ssp_disable(dev); + + /* Chip select control */ + spi_pw_cs_ctrl_init(dev); + +#if defined(CONFIG_SPI_PW_INTERRUPT) + /* Mask interrupts */ + spi_pw_intr_disable(dev); + + /* Init and connect IRQ */ + info->irq_config(dev); +#endif + + if (spi->cs_mode == CS_GPIO_MODE) { + err = spi_context_cs_configure_all(&spi->ctx); + if (err < 0) { + LOG_ERR("Failed to configure CS pins: %d", err); + return err; + } + } + + spi_context_unlock_unconditionally(&spi->ctx); + + LOG_DBG("SPI pw init success"); + + return 0; +} + +#define INIT_PCIE0(n) +#define INIT_PCIE1(n) DEVICE_PCIE_INST_INIT(n, pcie), +#define INIT_PCIE(n) _CONCAT(INIT_PCIE, DT_INST_ON_BUS(n, pcie))(n) + +#define DEFINE_PCIE0(n) +#define DEFINE_PCIE1(n) DEVICE_PCIE_INST_DECLARE(n) +#define SPI_PCIE_DEFINE(n) _CONCAT(DEFINE_PCIE, DT_INST_ON_BUS(n, pcie))(n) + +#ifdef CONFIG_SPI_PW_INTERRUPT + +#define SPI_INTEL_IRQ_FLAGS_SENSE0(n) 0 +#define SPI_INTEL_IRQ_FLAGS_SENSE1(n) DT_INST_IRQ(n, sense) +#define SPI_INTEL_IRQ_FLAGS(n) \ + _CONCAT(SPI_INTEL_IRQ_FLAGS_SENSE, DT_INST_IRQ_HAS_CELL(n, sense))(n) + +#define SPI_INTEL_IRQ_INIT(n) \ + BUILD_ASSERT(IS_ENABLED(CONFIG_DYNAMIC_INTERRUPTS), \ + "SPI PCIe requires dynamic interrupts"); \ + static void spi_##n##_irq_init(const struct device *dev) \ + { \ + const struct spi_pw_config *info = dev->config; \ + unsigned int irq; \ + if (DT_INST_IRQN(n) == PCIE_IRQ_DETECT) { \ + irq = pcie_alloc_irq(info->pcie->bdf); \ + if (irq == PCIE_CONF_INTR_IRQ_NONE) { \ + return; \ + } \ + } else { \ + irq = DT_INST_IRQN(n); \ + pcie_conf_write(info->pcie->bdf, \ + PCIE_CONF_INTR, irq); \ + } \ + pcie_connect_dynamic_irq(info->pcie->bdf, irq, \ + DT_INST_IRQ(n, priority), \ + (void (*)(const void *))spi_pw_isr, \ + DEVICE_DT_INST_GET(n), \ + SPI_INTEL_IRQ_FLAGS(n)); \ + pcie_irq_enable(info->pcie->bdf, irq); \ + LOG_DBG("lpass spi Configure irq %d", irq); \ + } + +#define SPI_PW_DEV_INIT(n) \ + static struct spi_pw_data spi_##n##_data = { \ + SPI_CONTEXT_INIT_LOCK(spi_##n##_data, ctx), \ + SPI_CONTEXT_INIT_SYNC(spi_##n##_data, ctx), \ + SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(n), ctx) \ + .cs_mode = DT_INST_PROP(n, pw_cs_mode), \ + .cs_output = DT_INST_PROP(n, pw_cs_output), \ + .fifo_depth = DT_INST_PROP(n, pw_fifo_depth), \ + }; \ + SPI_PCIE_DEFINE(n); \ + SPI_INTEL_IRQ_INIT(n) \ + static const struct spi_pw_config spi_##n##_config = { \ + .irq_config = spi_##n##_irq_init, \ + .clock_freq = DT_INST_PROP(n, clock_frequency), \ + INIT_PCIE(n) \ + }; \ + DEVICE_DT_INST_DEFINE(n, spi_pw_init, NULL, \ + &spi_##n##_data, &spi_##n##_config, \ + POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, \ + &pw_spi_api); +#else + +#define SPI_PW_DEV_INIT(n) \ + static struct spi_pw_data spi_##n##_data = { \ + SPI_CONTEXT_INIT_LOCK(spi_##n##_data, ctx), \ + SPI_CONTEXT_INIT_SYNC(spi_##n##_data, ctx), \ + SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(n), ctx) \ + .cs_mode = DT_INST_PROP(n, pw_cs_mode), \ + .cs_output = DT_INST_PROP(n, pw_cs_output), \ + .fifo_depth = DT_INST_PROP(n, pw_fifo_depth), \ + }; \ + SPI_PCIE_DEFINE(n); \ + static const struct spi_pw_config spi_##n##_config = { \ + .clock_freq = DT_INST_PROP(n, clock_frequency), \ + INIT_PCIE(n) \ + }; \ + DEVICE_DT_INST_DEFINE(n, spi_pw_init, NULL, \ + &spi_##n##_data, &spi_##n##_config, \ + POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, \ + &pw_spi_api); + +#endif + +DT_INST_FOREACH_STATUS_OKAY(SPI_PW_DEV_INIT) diff --git a/drivers/spi/spi_pw.h b/drivers/spi/spi_pw.h new file mode 100644 index 000000000000..09bf7ee73838 --- /dev/null +++ b/drivers/spi/spi_pw.h @@ -0,0 +1,224 @@ +/* spi_pw.h - Penwell SPI driver definitions */ + +/* + * Copyright (c) 2023 Intel Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_DRIVERS_SPI_SPI_PW_H_ +#define ZEPHYR_DRIVERS_SPI_SPI_PW_H_ + +#include "spi_context.h" + +/* lpss penwell spi registers */ +#define PW_SPI_REG_CTRLR0 0x00 +#define PW_SPI_REG_CTRLR1 0x04 +#define PW_SPI_REG_SSSR 0x08 +#define PW_SPI_REG_SSDR 0x10 +#define PW_SPI_REG_SSTO 0x28 +#define PW_SPI_REG_SITF 0x44 +#define PW_SPI_REG_SIRF 0x48 + +#define PW_SPI_REG_CLKS 0x200 +#define PW_SPI_REG_RESETS 0x204 +#define PW_SPI_REG_ACTIVE_LTR 0x210 +#define PW_SPI_REG_IDLE_LTR 0x217 +#define PW_SPI_REG_TX_BIT_COUNT 0x218 +#define PW_SPI_REG_RX_BIT_COUNT 0x21c +#define PW_SPI_REG_DMA_FINISH_DIS 0x220 + +#define PW_SPI_REG_CS_CTRL 0x224 +#define PW_SPI_REG_SW_SCRATCH 0x228 +#define PW_SPI_REG_CLK_GATE 0x238 +#define PW_SPI_REG_REMAP_ADDR_LO 0x240 +#define PW_SPI_REG_REMAP_ADDR_HI 0x244 +#define PW_SPI_REG_DEV_IDLE_CTRL 0x24c +#define PW_SPI_REG_DEL_RX_CLK 0x250 +#define PW_SPI_REG_CAP 0x2fc + +/* CTRLR0 settings */ +#define PW_SPI_CTRLR0_SSE_BIT BIT(7) +#define PW_SPI_CTRLR0_EDSS_BIT BIT(20) +#define PW_SPI_CTRLR0_RIM_BIT BIT(22) +#define PW_SPI_CTRLR0_TIM_BIT BIT(23) +#define PW_SPI_CTRLR0_MOD_BIT BIT(31) + +#define PW_SPI_CTRLR0_DATA_MASK (~(0xf << 0)) +#define PW_SPI_CTRLR0_EDSS_MASK (~(0x1 << 20)) + +/* Data size set bits sscr0[3:0] */ +#define PW_SPI_DATA_SIZE_4_BIT 0x3 +#define PW_SPI_DATA_SIZE_8_BIT 0x7 +#define PW_SPI_DATA_SIZE_16_BIT 0xf +#define PW_SPI_DATA_SIZE_32_BIT (PW_SPI_CTRLR0_EDSS_BIT | \ + PW_SPI_DATA_SIZE_16_BIT) +/* Frame format sscr0[5:4] */ +#define PW_SPI_FRF_MOTOROLA (~(0x3 << 4)) + +/* SSP Baud rate sscr0[19:8] */ +#define PW_SPI_BR_2MHZ 0x31 +#define PW_SPI_BR_4MHZ 0x18 +#define PW_SPI_BR_5MHZ 0x13 +#define PW_SPI_BR_10MHZ 0x9 +#define PW_SPI_BR_20MHZ 0x5 +#define PW_SPI_BR_MAX_FRQ 20000000 /* 20 MHz */ +/* [19:8] 12 bits */ +#define PW_SPI_SCR_MASK (BIT_MASK(12) << 8) +#define PW_SPI_SCR_SHIFT 0x8 + +/* CTRLR1 settings */ +#define PW_SPI_CTRL1_RIE_BIT BIT(0) +#define PW_SPI_CTRL1_TIE_BIT BIT(1) +#define PW_SPI_CTRL1_LBM_BIT BIT(2) +#define PW_SPI_CTRL1_SPO_BIT BIT(3) +#define PW_SPI_CTRL1_SPH_BIT BIT(4) +#define PW_SPI_CTRL1_IFS_BIT BIT(16) +#define PW_SPI_CTRL1_TINTE_BIT BIT(19) +#define PW_SPI_CTRL1_RSRE_BIT BIT(20) +#define PW_SPI_CTRL1_TSRE_BIT BIT(21) +#define PW_SPI_CTRL1_TRAIL_BIT BIT(22) +#define PW_SPI_CTRL1_RWOT_BIT BIT(23) + +/* [4:3] phase & polarity mask */ +#define PW_SPI_CTRL1_SPO_SPH_MASK (BIT_MASK(2) << 3) + +/* Status Register */ +#define PW_SPI_SSSR_TNF_BIT BIT(2) +#define PW_SPI_SSSR_RNE_BIT BIT(3) +#define PW_SPI_SSSR_BSY_BIT BIT(4) +#define PW_SPI_SSSR_TFS_BIT BIT(5) +#define PW_SPI_SSSR_RFS_BIT BIT(6) +#define PW_SPI_SSSR_ROR_BIT BIT(7) +#define PW_SPI_SSSR_PINT_BIT BIT(18) +#define PW_SPI_SSSR_TINT_BIT BIT(19) +#define PW_SPI_SSSR_TUR_BIT BIT(21) + +/* SPI Tx FIFO Higher Water Mark [5:0] */ +#define PW_SPI_SITF_HWM_1_ENTRY 0x1 +#define PW_SPI_SITF_HWM_4_ENTRY 0x4 +#define PW_SPI_SITF_HWM_8_ENTRY 0x8 +#define PW_SPI_SITF_HWM_16_ENTRY 0x10 +#define PW_SPI_SITF_HWM_32_ENTRY 0x20 +#define PW_SPI_SITF_HWM_64_ENTRY 0x40 + +/* SPI Tx FIFO Lower Water Mark[13:8] */ +#define PW_SPI_SITF_LWM_2_ENTRY (BIT(0) << 8) +#define PW_SPI_SITF_LWM_3_ENTRY (BIT(1) << 8) +#define PW_SPI_SITF_LWM_4_ENTRY ((BIT(1) | BIT(0)) << 8) + +/* SPI Tx FIFO Level SITF[21:16] */ +#define PW_SPI_SITF_SITFL_MASK (BIT_MASK(6) << 16) + +#define PW_SPI_SITF_SITFL_SHIFT 0x10 + +/* SPI Rx FIFO water mark */ +#define PW_SPI_SIRF_WMRF_1_ENTRY 0x1 +#define PW_SPI_SIRF_WMRF_2_ENTRY 0x2 +#define PW_SPI_SIRF_WMRF_4_ENTRY 0x4 +#define PW_SPI_SITF_WMRF_8_ENTRY 0x8 +#define PW_SPI_SITF_WMRF_16_ENTRY 0x10 +#define PW_SPI_SITF_WMRF_32_ENTRY 0x20 +#define PW_SPI_SITF_WMRF_64_ENTRY 0x40 + +/* SPI Rx FIFO Level RITF[13:8] */ +#define PW_SPI_SIRF_SIRFL_MASK (BIT_MASK(6) << 8) +#define PW_SPI_SIRF_SIRFL_SHIFT 0x8 + +/* Threshold default value */ +#define PW_SPI_WM_MASK BIT_MASK(6) +#define PW_SPI_SITF_LWMTF_SHIFT 0x8 +#define PW_SPI_SITF_LOW_WM_DFLT BIT(PW_SPI_SITF_LWMTF_SHIFT) +#define PW_SPI_SITF_HIGH_WM_DFLT 0x20 +#define PW_SPI_SIRF_WM_DFLT 0x28 + +/* Clocks */ +#define PW_SPI_CLKS_EN_BIT BIT(0) +#define PW_SPI_CLKS_MVAL BIT(1) +#define PW_SPI_CLKS_NVAL BIT(16) +#define PW_SPI_CLKS_UPDATE_BIT BIT(31) + +/* mval mask [15:1] */ +#define PW_SPI_CLKS_MVAL_MASK (BIT_MASK(15) << 1) + +/* nval mask [30:16] */ +#define PW_SPI_CLKS_NVAL_MASK (BIT_MASK(15) << 16) + +/* SPI chip select control */ +#define PW_SPI_CS_MODE_BIT 0 +#define PW_SPI_CS_STATE_BIT 1 +#define PW_SPI_CS0_POL_BIT 12 +#define PW_SPI_CS1_POL_BIT 13 + +/* ssp interrupt error bits */ +#define PW_SPI_INTR_ERRORS_MASK (PW_SPI_SSSR_TUR_BIT | \ + PW_SPI_SSSR_ROR_BIT | \ + PW_SPI_SSSR_TINT_BIT) + +/* ssp interrupt bits */ +#define PW_SPI_INTR_BITS (PW_SPI_CTRL1_TIE_BIT | \ + PW_SPI_CTRL1_RIE_BIT | \ + PW_SPI_CTRL1_TINTE_BIT) + +#define PW_SPI_INTR_MASK_TX (~(PW_SPI_CTRL1_TIE_BIT | \ + PW_SPI_CTRL1_TINTE_BIT)) + +#define PW_SPI_INTR_MASK_RX (PW_SPI_CTRL1_RIE_BIT) + +/* SSP & DMA reset */ +#define PW_SPI_INST_RESET 0x7 + +/* Chip select control */ +#define PW_SPI_CS_CTRL_SW_MODE BIT(0) +#define PW_SPI_CS_HIGH BIT(1) +#define PW_SPI_CS_LOW (~(PW_SPI_CS_HIGH)) +#define PW_SPI_CS_CTRL_CS_MASK 0x3 +#define PW_SPI_CS_EN_SHIFT 0x8 +#define PW_SPI_CS0_SELECT (~(BIT(PW_SPI_CS_EN_SHIFT))) +#define PW_SPI_CS1_SELECT BIT(PW_SPI_CS_EN_SHIFT) +#define PW_SPI_CS_CTRL_HW_MODE (~(PW_SPI_CS_CTRL_SW_MODE)) + +#define PW_SPI_WIDTH_8BITS 8 +#define PW_SPI_FRAME_SIZE_1_BYTE 1 +#define PW_SPI_FRAME_SIZE_2_BYTES 2 +#define PW_SPI_FRAME_SIZE_4_BYTES 4 + +#define PW_SPI_CS1_OUTPUT_SELECT 1 + +enum spi_pw_spo_sph_mode { + SPI_PW_MODE0 = 0, + SPI_PW_MODE1, + SPI_PW_MODE2, + SPI_PW_MODE3, +}; + +enum spi_pw_cs_mode { + CS_HW_MODE = 0, + CS_SW_MODE, + CS_GPIO_MODE, +}; + +struct spi_pw_config { + uint32_t id; +#ifdef CONFIG_SPI_PW_INTERRUPT + void (*irq_config)(const struct device *dev); +#endif + uint32_t clock_freq; + uint8_t op_modes; +#if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie) + struct pcie_dev *pcie; +#endif +}; + +struct spi_pw_data { + DEVICE_MMIO_RAM; + struct spi_context ctx; + uint8_t dfs; + uint8_t fifo_diff; + uint8_t cs_mode; + uint8_t cs_output; + uint32_t id; + uint8_t fifo_depth; +}; + +#endif /* ZEPHYR_DRIVERS_SPI_SPI_PW_H_ */ diff --git a/dts/bindings/spi/intel,penwell-spi.yaml b/dts/bindings/spi/intel,penwell-spi.yaml new file mode 100644 index 000000000000..fa02b823a9f9 --- /dev/null +++ b/dts/bindings/spi/intel,penwell-spi.yaml @@ -0,0 +1,40 @@ +# Copyright (c) 2023 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +description: Intel Penwell SPI + +compatible: "intel,penwell-spi" + +include: [spi-controller.yaml, pcie-device.yaml] + +properties: + interrupts: + required: true + + cs-gpios: + required: true + + pw,cs-mode: + type: int + required: true + description: | + Chip select configuration. possible values: + 0: Hardware + 1: Software + 2: GPIO + + pw,cs-output: + type: int + required: true + description: | + Use GSPI chip select CS0 or CS1. GSPI 0, 1 & 2 instance supports both chip selects. + It can be configured with this DTS property. By default, CS0 is set. + Chip select output possible values: + 0: CS0 + 1: CS1 + + pw,fifo-depth: + type: int + required: true + description: SPI controller with embedded Tx and Rx FIFOs. From 8de6b50b1411173ed484dca07743c739fd4b06ad Mon Sep 17 00:00:00 2001 From: Ramesh Babu B Date: Fri, 17 Mar 2023 19:43:20 +0530 Subject: [PATCH 0544/1906] dts: x86: intel: raptor_lake: Add SPI instances Added SPI instances in raptor_lake dtsi file. Signed-off-by: Ramesh Babu B --- dts/x86/intel/raptor_lake.dtsi | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/dts/x86/intel/raptor_lake.dtsi b/dts/x86/intel/raptor_lake.dtsi index 8570fdd7445b..55e21825a095 100644 --- a/dts/x86/intel/raptor_lake.dtsi +++ b/dts/x86/intel/raptor_lake.dtsi @@ -7,6 +7,7 @@ #include #include #include +#include / { cpus { @@ -143,6 +144,54 @@ status = "disabled"; }; + + spi0: spi0 { + compatible = "intel,penwell-spi"; + vendor-id = <0x8086>; + device-id = <0x7aaa>; + #address-cells = <1>; + #size-cells = <0>; + pw,cs-mode = <0>; + pw,cs-output = <0>; + pw,fifo-depth = <64>; + cs-gpios = <&gpio_0_i 15 GPIO_ACTIVE_LOW>; + clock-frequency = <100000000>; + interrupts = ; + interrupt-parent = <&intc>; + status = "okay"; + }; + + spi1: spi1 { + compatible = "intel,penwell-spi"; + vendor-id = <0x8086>; + device-id = <0x7aab>; + #address-cells = <1>; + #size-cells = <0>; + pw,cs-mode = <0>; + pw,cs-output = <0>; + pw,fifo-depth = <64>; + cs-gpios = <&gpio_0_i 19 GPIO_ACTIVE_LOW>; + clock-frequency = <100000000>; + interrupts = ; + interrupt-parent = <&intc>; + status = "disabled"; + }; + + spi2: spi2 { + compatible = "intel,penwell-spi"; + vendor-id = <0x8086>; + device-id = <0x7afb>; + #address-cells = <1>; + #size-cells = <0>; + pw,cs-mode = <0>; + pw,cs-output = <0>; + pw,fifo-depth = <64>; + cs-gpios = <&gpio_0_r 12 GPIO_ACTIVE_LOW>; + clock-frequency = <100000000>; + interrupts = ; + interrupt-parent = <&intc>; + status = "disabled"; + }; }; soc { From 5df7d93c82f12034897fc14460556ed2f0620c78 Mon Sep 17 00:00:00 2001 From: Ramesh Babu B Date: Fri, 17 Mar 2023 19:47:26 +0530 Subject: [PATCH 0545/1906] tests: drivers: spi: Enable spi_loopback on RPL CRB Configure through an overlay file, the rpl_crb board for running the tests/drivers/spi/spi_loopback. Signed-off-by: Ramesh Babu B --- .../spi/spi_loopback/boards/rpl_crb.conf | 4 ++++ .../spi/spi_loopback/boards/rpl_crb.overlay | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/drivers/spi/spi_loopback/boards/rpl_crb.conf create mode 100644 tests/drivers/spi/spi_loopback/boards/rpl_crb.overlay diff --git a/tests/drivers/spi/spi_loopback/boards/rpl_crb.conf b/tests/drivers/spi/spi_loopback/boards/rpl_crb.conf new file mode 100644 index 000000000000..469a8f7c4451 --- /dev/null +++ b/tests/drivers/spi/spi_loopback/boards/rpl_crb.conf @@ -0,0 +1,4 @@ +CONFIG_SPI=y +CONFIG_SPI_ASYNC=n +CONFIG_GPIO=y +CONFIG_SPI_LOOPBACK_MODE_LOOP=y diff --git a/tests/drivers/spi/spi_loopback/boards/rpl_crb.overlay b/tests/drivers/spi/spi_loopback/boards/rpl_crb.overlay new file mode 100644 index 000000000000..3eeba84cf265 --- /dev/null +++ b/tests/drivers/spi/spi_loopback/boards/rpl_crb.overlay @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* External Loopback: Short MOSI (J7H4.3) & MISO (J7H4.5) */ + +&spi0 { + pw,cs-mode = <0>; + pw,cs-output = <0>; + status = "okay"; + + slow@0 { + compatible = "test-spi-loopback-slow"; + reg = <0>; + spi-max-frequency = <500000>; + }; + fast@0 { + compatible = "test-spi-loopback-fast"; + reg = <0>; + spi-max-frequency = <16000000>; + }; +}; From d6df87a92e20475df3a8be9a46bc825c2c62797d Mon Sep 17 00:00:00 2001 From: Conor Paxton Date: Tue, 7 Mar 2023 15:14:34 +0000 Subject: [PATCH 0546/1906] dts: mpfs_icicle: cleanup use of whitespace Some lines of the mpfs_icicle Devicetree contained a jumble of white space and tabs. Just use tabs Signed-off-by: Conor Paxton --- dts/riscv/mpfs-icicle.dtsi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dts/riscv/mpfs-icicle.dtsi b/dts/riscv/mpfs-icicle.dtsi index ad1a7775baeb..435ba585e1d6 100644 --- a/dts/riscv/mpfs-icicle.dtsi +++ b/dts/riscv/mpfs-icicle.dtsi @@ -104,10 +104,10 @@ clint: clint@2000000 { compatible = "sifive,clint0"; interrupts-extended = <&hlic0 3 &hlic0 7 - &hlic1 3 &hlic1 7 - &hlic2 3 &hlic2 7 - &hlic3 3 &hlic3 7 - &hlic4 3 &hlic4 7>; + &hlic1 3 &hlic1 7 + &hlic2 3 &hlic2 7 + &hlic3 3 &hlic3 7 + &hlic4 3 &hlic4 7>; interrupt-names = "soft0", "timer0", "soft1", "timer1", "soft2", "timer2", "soft3", "timer3", "soft4", "timer4"; @@ -122,8 +122,8 @@ interrupts-extended = <&hlic0 11 &hlic1 11>; reg = <0x0c000000 0x00002000 - 0x0c002000 0x001fe000 - 0x0c200000 0x3e000000>; + 0x0c002000 0x001fe000 + 0x0c200000 0x3e000000>; reg-names = "prio", "irq_en", "reg"; riscv,max-priority = <7>; riscv,ndev = <187>; From b73f6b3d2b8cba97d1b525941b6cf5e91f08eace Mon Sep 17 00:00:00 2001 From: Conor Paxton Date: Tue, 7 Mar 2023 15:35:12 +0000 Subject: [PATCH 0547/1906] dts: mpfs_icicle: add all uart nodes to the Devicetree Microchips PolarFire-SoC Icicle Kit has 4x UART interfaces available via single micro USB and 1x UART for programming and debugging via micro USB. Add the remaining UARTs to the Devicetree Signed-off-by: Conor Paxton --- dts/riscv/mpfs-icicle.dtsi | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/dts/riscv/mpfs-icicle.dtsi b/dts/riscv/mpfs-icicle.dtsi index 435ba585e1d6..5b130413f63a 100644 --- a/dts/riscv/mpfs-icicle.dtsi +++ b/dts/riscv/mpfs-icicle.dtsi @@ -140,6 +140,50 @@ status = "disabled"; }; + uart1: uart@20100000 { + compatible = "ns16550"; + reg = <0x20100000 0x1000>; + clock-frequency = <150000000>; + current-speed = <115200>; + interrupt-parent = <&plic>; + interrupts = <91 1>; + reg-shift = <2>; + status = "disabled"; + }; + + uart2: uart@20102000 { + compatible = "ns16550"; + reg = <0x20102000 0x1000>; + clock-frequency = <150000000>; + current-speed = <115200>; + interrupt-parent = <&plic>; + interrupts = <92 1>; + reg-shift = <2>; + status = "disabled"; + }; + + uart3: uart@20104000 { + compatible = "ns16550"; + reg = <0x20104000 0x1000>; + clock-frequency = <150000000>; + current-speed = <115200>; + interrupt-parent = <&plic>; + interrupts = <93 1>; + reg-shift = <2>; + status = "disabled"; + }; + + uart4: uart@20106000 { + compatible = "ns16550"; + reg = <0x20106000 0x1000>; + clock-frequency = <150000000>; + current-speed = <115200>; + interrupt-parent = <&plic>; + interrupts = <94 1>; + reg-shift = <2>; + status = "disabled"; + }; + qspi0: spi@21000000 { compatible = "microchip,mpfs-qspi"; #address-cells = <1>; From 032b3d121d91bacecad14c565645fcc0875ea363 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 21 Mar 2023 13:29:26 +0100 Subject: [PATCH 0548/1906] net: openthread: Fix OPENTHREAD_CONFIG_TCP_ENABLE redefinition warning OPENTHREAD_CONFIG_TCP_ENABLE is now set by the OpenThread build system, based on the CONFIG_OPENTHREAD_CLI_TCP_ENABLE Kconfig entry. Setting this symbol in the config file is therefore redundant, and causes multiple build warnings. Signed-off-by: Robert Lubos --- .../openthread/platform/openthread-core-zephyr-config.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/modules/openthread/platform/openthread-core-zephyr-config.h b/modules/openthread/platform/openthread-core-zephyr-config.h index 50a3fc73ea7e..76c87ebd8206 100644 --- a/modules/openthread/platform/openthread-core-zephyr-config.h +++ b/modules/openthread/platform/openthread-core-zephyr-config.h @@ -357,14 +357,6 @@ #define OPENTHREAD_CONFIG_IP6_MAX_EXT_MCAST_ADDRS CONFIG_OPENTHREAD_IP6_MAX_EXT_MCAST_ADDRS #endif /* CONFIG_OPENTHREAD_IP6_MAX_EXT_MCAST_ADDRS */ -/** - * @def OPENTHREAD_CONFIG_TCP_ENABLE - * - * Enable TCP. - * - */ -#define OPENTHREAD_CONFIG_TCP_ENABLE IS_ENABLED(CONFIG_OPENTHREAD_TCP_ENABLE) - /** * @def OPENTHREAD_CONFIG_CLI_TCP_ENABLE * From 4b50281fca724496b276afb9d1b5020986e1b4f2 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 8 Mar 2023 09:39:21 +0100 Subject: [PATCH 0549/1906] nrf52_bsim: Add replacement for nrfx's nrfx_coredep_delay_us() Provide a replacement for this board for the nordic HAL nrfx nrfx_coredep_delay_us() This function is a busy wait, which in the HAL relies on the ARM DWT or assembler, but which in this board can just utilize the same busy_wait mechanism provided for k_busy_wait() Signed-off-by: Alberto Escolar Piedras --- boards/posix/nrf52_bsim/CMakeLists.txt | 1 + boards/posix/nrf52_bsim/soc/nrfx_coredep.c | 23 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 boards/posix/nrf52_bsim/soc/nrfx_coredep.c diff --git a/boards/posix/nrf52_bsim/CMakeLists.txt b/boards/posix/nrf52_bsim/CMakeLists.txt index 2d5528dcf999..7f43853b5af2 100644 --- a/boards/posix/nrf52_bsim/CMakeLists.txt +++ b/boards/posix/nrf52_bsim/CMakeLists.txt @@ -30,6 +30,7 @@ zephyr_library_sources( time_machine.c trace_hook.c cmsis.c + soc/nrfx_coredep.c ) zephyr_library_include_directories( diff --git a/boards/posix/nrf52_bsim/soc/nrfx_coredep.c b/boards/posix/nrf52_bsim/soc/nrfx_coredep.c new file mode 100644 index 000000000000..e0521b5effa7 --- /dev/null +++ b/boards/posix/nrf52_bsim/soc/nrfx_coredep.c @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* + * Replacement for the nrfx nrfx_coredep_delay_us() + * which busy waits for the given number of microseconds. + * + * This function will replace at *link* time the + * nrfx one which had been marked as weak. + */ +void nrfx_coredep_delay_us(uint32_t time_us) +{ + if (time_us == 0) { + return; + } + arch_busy_wait(time_us); +} From 464dfc14a44a13c36410780ee4b9caef87f7fd4a Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 16 Mar 2023 15:45:27 +0100 Subject: [PATCH 0550/1906] nrf52_bsim: Provide replacement for soc_secure_read_deviceid() Provide a replacement for the original functionality from nRF's soc/arm/nordic_nrf/common/soc_secure.h Signed-off-by: Alberto Escolar Piedras --- boards/posix/nrf52_bsim/CMakeLists.txt | 2 ++ boards/posix/nrf52_bsim/soc/soc_secure.h | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 boards/posix/nrf52_bsim/soc/soc_secure.h diff --git a/boards/posix/nrf52_bsim/CMakeLists.txt b/boards/posix/nrf52_bsim/CMakeLists.txt index 7f43853b5af2..49068403033d 100644 --- a/boards/posix/nrf52_bsim/CMakeLists.txt +++ b/boards/posix/nrf52_bsim/CMakeLists.txt @@ -33,6 +33,8 @@ zephyr_library_sources( soc/nrfx_coredep.c ) +zephyr_include_directories(soc) + zephyr_library_include_directories( $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ diff --git a/boards/posix/nrf52_bsim/soc/soc_secure.h b/boards/posix/nrf52_bsim/soc/soc_secure.h new file mode 100644 index 000000000000..667823334d00 --- /dev/null +++ b/boards/posix/nrf52_bsim/soc/soc_secure.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * Replacement for Nordic's nrf soc/arm/nordic_nrf/common/soc_secure.h + */ +#ifndef BOARDS_POSIX_NRF52_BSIM_SOC_SECURE_H +#define BOARDS_POSIX_NRF52_BSIM_SOC_SECURE_H + + +#include +#include +#include + +static inline void soc_secure_read_deviceid(uint32_t deviceid[2]) +{ + deviceid[0] = nrf_ficr_deviceid_get(NRF_FICR, 0); + deviceid[1] = nrf_ficr_deviceid_get(NRF_FICR, 1); +} + +#endif /* BOARDS_POSIX_NRF52_BSIM_SOC_SECURE_H */ From 06b22ebf73a4a6470f0f92095fd5ee6e30cfa6f8 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 16 Mar 2023 15:42:54 +0100 Subject: [PATCH 0551/1906] nrf52_bsim: Provide definition of IRQ_ZERO_LATENCY As it is required by some drivers. Signed-off-by: Alberto Escolar Piedras --- boards/posix/nrf52_bsim/board_irq.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/boards/posix/nrf52_bsim/board_irq.h b/boards/posix/nrf52_bsim/board_irq.h index 6c1d202f825a..372dadab3324 100644 --- a/boards/posix/nrf52_bsim/board_irq.h +++ b/boards/posix/nrf52_bsim/board_irq.h @@ -80,6 +80,8 @@ extern void posix_irq_check_idle_exit(void); #define ARCH_ISR_DIRECT_PM() do { } while (false) #endif +#define IRQ_ZERO_LATENCY BIT(1) /* Unused in this board*/ + #ifdef __cplusplus } #endif From 52ae41a3c4fbedd65600c6c5440020c18633c134 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 16 Mar 2023 15:38:01 +0100 Subject: [PATCH 0552/1906] nrf52_bsim: Default NRF_802154_TEMPERATURE_UPDATE to n To allow enabling the 802.15.4 driver even though we do not have the temporature sensor modelled. Signed-off-by: Alberto Escolar Piedras --- boards/posix/nrf52_bsim/Kconfig.defconfig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/boards/posix/nrf52_bsim/Kconfig.defconfig b/boards/posix/nrf52_bsim/Kconfig.defconfig index ad3630d060c5..8d0de5ee6f70 100644 --- a/boards/posix/nrf52_bsim/Kconfig.defconfig +++ b/boards/posix/nrf52_bsim/Kconfig.defconfig @@ -25,6 +25,13 @@ config BT_CTLR default y depends on BT +# The simulated nRF52 HW models do not include yet the TEMP peripheral +# So we disable its default usage by the 15.4 driver +# Otherwise it would be set by default, and NRF_802154_SL_OPENSOURCE +# would require TEMP_NRF5, which requires the missing HW model +config NRF_802154_TEMPERATURE_UPDATE + default n + if LOG # For this board we can log synchronously without any problem From ef6c91411c44243e6c1a1647bc100322147889c8 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 17 Mar 2023 11:23:12 +0100 Subject: [PATCH 0553/1906] tests bsim bap_unicast_audio: Avoid randomness failure The current seed causes a failure with the updated HW models due to a change in the random draw, that happens to unluckily cause the test to fail. Avoide it with a different random seed. This is due to a known issue in the controller, which is being worked on by the maintainer. Signed-off-by: Alberto Escolar Piedras --- tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio.sh b/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio.sh index 5fd562a29f8d..425f20ccff36 100755 --- a/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio.sh +++ b/tests/bsim/bluetooth/audio/test_scripts/bap_unicast_audio.sh @@ -18,7 +18,7 @@ Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=unicast_client -rs=23 Execute ./bs_${BOARD}_tests_bsim_bluetooth_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=unicast_server -rs=27 + -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=unicast_server -rs=28 # Simulation time should be larger than the WAIT_TIME in common.h Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ From a5883e6f4596254a4c9aff35f646349bf4fa85cf Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Mon, 30 Jan 2023 16:44:57 +0100 Subject: [PATCH 0554/1906] manifest: Fetch latests nrf52 HW models w 802.15.4 support Update to the latest nrf52 HW models which include a multitude of updates, including support for 802.15.4 in the radio. NOTE!: Requires the updated Babblesim v2 dev-phy API, with the new Rx continuation on header evaluation mechanism. Signed-off-by: Alberto Escolar Piedras --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 6a0215dd59fd..22f3a67a77b9 100644 --- a/west.yml +++ b/west.yml @@ -197,7 +197,7 @@ manifest: groups: - tools - name: nrf_hw_models - revision: ad21dabc84c6574944d978cce2079dbe1ede38c6 + revision: feb3e555f7745dc4fd0a16403f5d81a7ea7359b0 path: modules/bsim_hw_models/nrf_hw_models - name: open-amp revision: aedcc262f93bbb1b0c2f58026911575729b7465c From e0ccc37ea521788c9a2b2f4f4ed39a02db8a3a01 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 16 Mar 2023 15:43:34 +0100 Subject: [PATCH 0555/1906] nrf52_bsim: Provide more CMSIS headers and definitions Including Exclusive store load and status clear. Signed-off-by: Alberto Escolar Piedras --- boards/posix/nrf52_bsim/CMakeLists.txt | 3 +- boards/posix/nrf52_bsim/board_irq.h | 2 + boards/posix/nrf52_bsim/{ => cmsis}/cmsis.c | 19 ++- boards/posix/nrf52_bsim/{ => cmsis}/cmsis.h | 37 ++--- .../nrf52_bsim/{ => cmsis}/cmsis_compiler.h | 0 boards/posix/nrf52_bsim/cmsis/cmsis_instr.h | 154 ++++++++++++++++++ boards/posix/nrf52_bsim/irq_handler.c | 9 +- 7 files changed, 189 insertions(+), 35 deletions(-) rename boards/posix/nrf52_bsim/{ => cmsis}/cmsis.c (84%) rename boards/posix/nrf52_bsim/{ => cmsis}/cmsis.h (57%) rename boards/posix/nrf52_bsim/{ => cmsis}/cmsis_compiler.h (100%) create mode 100644 boards/posix/nrf52_bsim/cmsis/cmsis_instr.h diff --git a/boards/posix/nrf52_bsim/CMakeLists.txt b/boards/posix/nrf52_bsim/CMakeLists.txt index 49068403033d..19bb7935d888 100644 --- a/boards/posix/nrf52_bsim/CMakeLists.txt +++ b/boards/posix/nrf52_bsim/CMakeLists.txt @@ -29,11 +29,12 @@ zephyr_library_sources( main.c time_machine.c trace_hook.c - cmsis.c + cmsis/cmsis.c soc/nrfx_coredep.c ) zephyr_include_directories(soc) +zephyr_include_directories(cmsis) zephyr_library_include_directories( $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ diff --git a/boards/posix/nrf52_bsim/board_irq.h b/boards/posix/nrf52_bsim/board_irq.h index 372dadab3324..e333b419032a 100644 --- a/boards/posix/nrf52_bsim/board_irq.h +++ b/boards/posix/nrf52_bsim/board_irq.h @@ -19,6 +19,8 @@ void posix_isr_declare(unsigned int irq_p, int flags, void isr_p(const void *), const void *isr_param_p); void posix_irq_priority_set(unsigned int irq, unsigned int prio, uint32_t flags); +void nrfbsim_WFE_model(void); +void nrfbsim_SEV_model(void); /** * Configure a static interrupt. diff --git a/boards/posix/nrf52_bsim/cmsis.c b/boards/posix/nrf52_bsim/cmsis/cmsis.c similarity index 84% rename from boards/posix/nrf52_bsim/cmsis.c rename to boards/posix/nrf52_bsim/cmsis/cmsis.c index 9e8c85800e81..bf431d9ed3e4 100644 --- a/boards/posix/nrf52_bsim/cmsis.c +++ b/boards/posix/nrf52_bsim/cmsis/cmsis.c @@ -10,6 +10,7 @@ #include "posix_core.h" #include "posix_board_if.h" #include "board_soc.h" +#include "bs_tracing.h" /* * Replacement for ARMs NVIC functions() @@ -46,8 +47,7 @@ uint32_t NVIC_GetPriority(IRQn_Type IRQn) void NVIC_SystemReset(void) { - posix_print_warning("%s called. Exiting\n", __func__); - posix_exit(1); + bs_trace_error_time_line("%s called. Exiting\n", __func__); } /* @@ -72,3 +72,18 @@ void __set_PRIMASK(uint32_t primask) { hw_irq_ctrl_change_lock(primask != 0); } + +void __WFE(void) +{ + nrfbsim_WFE_model(); +} + +void __WFI(void) +{ + __WFE(); +} + +void __SEV(void) +{ + nrfbsim_SEV_model(); +} diff --git a/boards/posix/nrf52_bsim/cmsis.h b/boards/posix/nrf52_bsim/cmsis/cmsis.h similarity index 57% rename from boards/posix/nrf52_bsim/cmsis.h rename to boards/posix/nrf52_bsim/cmsis/cmsis.h index a068aa6bb1d8..f40ae49a9b78 100644 --- a/boards/posix/nrf52_bsim/cmsis.h +++ b/boards/posix/nrf52_bsim/cmsis/cmsis.h @@ -12,40 +12,27 @@ #ifndef BOARDS_POSIX_NRF52_BSIM_CMSIS_H #define BOARDS_POSIX_NRF52_BSIM_CMSIS_H +#include +#include "cmsis_instr.h" +#include "nrf52833.h" + #ifdef __cplusplus extern "C" { #endif -/* Implement the following ARM intrinsics as no-op: - * - ARM Data Synchronization Barrier - * - ARM Data Memory Synchronization Barrier - * - ARM Instruction Synchronization Barrier - * - ARM No Operation - */ -#ifndef __DMB -#define __DMB() -#endif - -#ifndef __DSB -#define __DSB() -#endif - -#ifndef __ISB -#define __ISB() -#endif - -#ifndef __NOP -#define __NOP() -#endif - void __enable_irq(void); - void __disable_irq(void); - uint32_t __get_PRIMASK(void); - void __set_PRIMASK(uint32_t primask); +void NVIC_SetPendingIRQ(IRQn_Type IRQn); +void NVIC_ClearPendingIRQ(IRQn_Type IRQn); +void NVIC_DisableIRQ(IRQn_Type IRQn); +void NVIC_EnableIRQ(IRQn_Type IRQn); +void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority); +uint32_t NVIC_GetPriority(IRQn_Type IRQn); +void NVIC_SystemReset(void); + #ifdef __cplusplus } #endif diff --git a/boards/posix/nrf52_bsim/cmsis_compiler.h b/boards/posix/nrf52_bsim/cmsis/cmsis_compiler.h similarity index 100% rename from boards/posix/nrf52_bsim/cmsis_compiler.h rename to boards/posix/nrf52_bsim/cmsis/cmsis_compiler.h diff --git a/boards/posix/nrf52_bsim/cmsis/cmsis_instr.h b/boards/posix/nrf52_bsim/cmsis/cmsis_instr.h new file mode 100644 index 000000000000..978b1d8c349f --- /dev/null +++ b/boards/posix/nrf52_bsim/cmsis/cmsis_instr.h @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * Copyright (c) 2020 Oticon A/S + * Copyright (c) 2009-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * This header defines replacements for inline + * ARM Cortex-M CMSIS intrinsics. + */ + +#ifndef BOARDS_POSIX_NRF52_BSIM_CMSIS_INSTR_H +#define BOARDS_POSIX_NRF52_BSIM_CMSIS_INSTR_H + +/* Implement the following ARM intrinsics as no-op: + * - ARM Data Synchronization Barrier + * - ARM Data Memory Synchronization Barrier + * - ARM Instruction Synchronization Barrier + * - ARM No Operation + */ +#ifndef __DMB +#define __DMB() +#endif + +#ifndef __DSB +#define __DSB() +#endif + +#ifndef __ISB +#define __ISB() +#endif + +#ifndef __NOP +#define __NOP() +#endif + +void __WFE(void); +void __WFI(void); +void __SEV(void); + +/* + * Implement the following ARM intrinsics as non-exclusive accesses + * + * - STR Exclusive(8,16 & 32bit) (__STREX{B,H,W}) + * - LDR Exclusive(8,16 & 32bit) (__LDREX{B,H,W}) + * - CLREX : Exclusive lock removal (__CLREX) - no-op + * + * Description: + * These accesses always succeed, and do NOT set any kind of internal + * exclusive access flag; + * There is no local/global memory monitors, MPU control of what are + * shareable regions, exclusive reservations granules, automatic clearing + * on context switch, or so. + * + * This should be enough for the expected uses of LDR/STREXB + * (locking mutexes or guarding other atomic operations, inside a few lines + * of code in the same function): As the POSIX arch will not make an embedded + * thread lose context while just executing its own code, and it does not + * allow parallel embedded SW threads to execute at the same exact time, + * there is no actual need to protect atomicity. + * + * But as this ARM exclusive access monitor mechanism can in principle be + * used for other, unexpected, purposes, this simple replacement may not be + * enough. + */ + +/** + * \brief Pretend to execute a STR Exclusive (8 bit) + * \details Executes a ~exclusive~ STR instruction for 8 bit values. + * \param [in] value Value to store + * \param [in] ptr Pointer to location + * \return 0 Function succeeded (always) + */ +static inline uint32_t __STREXB(uint8_t value, volatile uint8_t *ptr) +{ + *ptr = value; + return 0; +} + +/** + * \brief Pretend to execute a STR Exclusive (16 bit) + * \details Executes a ~exclusive~ STR instruction for 16 bit values. + * \param [in] value Value to store + * \param [in] ptr Pointer to location + * \return 0 Function succeeded (always) + */ +static inline uint32_t __STREXH(uint16_t value, volatile uint16_t *ptr) +{ + *ptr = value; + return 0; +} + +/** + * \brief Pretend to execute a STR Exclusive (32 bit) + * \details Executes a ~exclusive~ STR instruction for 32 bit values. + * \param [in] value Value to store + * \param [in] ptr Pointer to location + * \return 0 Function succeeded (always) + */ +static inline uint32_t __STREXW(uint32_t value, volatile uint32_t *ptr) +{ + *ptr = value; + return 0; +} + +/** + * \brief Pretend to execute a LDR Exclusive (8 bit) + * \details Executes an ~exclusive~ LDR instruction for 8 bit value. + * Meaning, it does not set a exclusive lock, + * instead just loads the stored value + * \param [in] ptr Pointer to data + * \return value of type uint8_t at (*ptr) + */ +static inline uint8_t __LDREXB(volatile uint8_t *ptr) +{ + return *ptr; +} + +/** + * \brief Pretend to execute a LDR Exclusive (16 bit) + * \details Executes an ~exclusive~ LDR instruction for 16 bit value. + * Meaning, it does not set a exclusive lock, + * instead just loads the stored value + * \param [in] ptr Pointer to data + * \return value of type uint8_t at (*ptr) + */ +static inline uint16_t __LDREXH(volatile uint16_t *ptr) +{ + return *ptr; +} + +/** + * \brief Pretend to execute a LDR Exclusive (32 bit) + * \details Executes an ~exclusive~ LDR instruction for 32 bit value. + * Meaning, it does not set a exclusive lock, + * instead just loads the stored value + * \param [in] ptr Pointer to data + * \return value of type uint8_t at (*ptr) + */ +static inline uint32_t __LDREXW(volatile uint32_t *ptr) +{ + return *ptr; +} + +/** + * \brief Pretend to remove the exclusive lock + * \details The real function would removes the exclusive lock which is created + * by LDREX, this one does nothing + */ +static inline void __CLREX(void) { /* Nothing to be done */ } + +#endif /* BOARDS_POSIX_NRF52_BSIM_CMSIS_INSTR_H */ diff --git a/boards/posix/nrf52_bsim/irq_handler.c b/boards/posix/nrf52_bsim/irq_handler.c index 104cbd0fbbcf..c14d197daa88 100644 --- a/boards/posix/nrf52_bsim/irq_handler.c +++ b/boards/posix/nrf52_bsim/irq_handler.c @@ -327,7 +327,7 @@ void posix_irq_offload(void (*routine)(const void *), const void *parameter) */ static bool CPU_event_set_flag; -void __WFE(void) +void nrfbsim_WFE_model(void) { if (CPU_event_set_flag == false) { CPU_will_be_awaken_from_WFE = true; @@ -337,12 +337,7 @@ void __WFE(void) CPU_event_set_flag = false; } -void __WFI(void) -{ - __WFE(); -} - -void __SEV(void) +void nrfbsim_SEV_model(void) { CPU_event_set_flag = true; } From f9b130d838bbc1e7815df5dbe90547d3e2217fbb Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 16 Mar 2023 15:39:19 +0100 Subject: [PATCH 0556/1906] nrf52_bsim: Enable building Nordic HAL drivers for this board Namely the 802.15.4 driver. This commit just allows selecting it. It does not enale it by default. Signed-off-by: Alberto Escolar Piedras --- boards/posix/nrf52_bsim/Kconfig.board | 1 + 1 file changed, 1 insertion(+) diff --git a/boards/posix/nrf52_bsim/Kconfig.board b/boards/posix/nrf52_bsim/Kconfig.board index 56452a4e18c3..cbf192279bd7 100644 --- a/boards/posix/nrf52_bsim/Kconfig.board +++ b/boards/posix/nrf52_bsim/Kconfig.board @@ -11,6 +11,7 @@ config BOARD_NRF52_BSIM select NRF_RTC_TIMER select CLOCK_CONTROL select HAS_NRFX + select HAS_NORDIC_DRIVERS help Will produce a console Linux process which can be executed natively. It needs the BabbleSim simulator both in compile time and to execute From 361f443e1b0bef12a47c22317bd72f25bea04a78 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 16 Mar 2023 15:41:14 +0100 Subject: [PATCH 0557/1906] nrf52_bsim: Enable 802.15.4 support in DTS Enable the 802.15.4 RADIO HW in DTS. Signed-off-by: Alberto Escolar Piedras --- boards/posix/nrf52_bsim/nrf52_bsim.dts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/boards/posix/nrf52_bsim/nrf52_bsim.dts b/boards/posix/nrf52_bsim/nrf52_bsim.dts index 224462c2b5e5..8d6bc54311b9 100644 --- a/boards/posix/nrf52_bsim/nrf52_bsim.dts +++ b/boards/posix/nrf52_bsim/nrf52_bsim.dts @@ -23,7 +23,6 @@ /delete-property/ uart-0; /delete-property/ uart-1; /delete-property/ adc-0; - /delete-property/ gpio-0; /delete-property/ gpio-1; /delete-property/ gpiote-0; /delete-property/ wdt-0; @@ -36,6 +35,7 @@ chosen { /delete-property/ zephyr,flash-controller; + zephyr,ieee802154 = &ieee802154; }; soc { @@ -45,7 +45,6 @@ /delete-node/ uart@40002000; /delete-node/ uart@40028000; /delete-node/ gpiote@40006000; - /delete-node/ gpio@50000000; /delete-node/ gpio@50000300; /delete-node/ i2c@40003000; /delete-node/ i2c@40004000; @@ -70,6 +69,16 @@ &radio { /* These features are not yet supported by the RADIO model */ /delete-property/ dfe-supported; - /delete-property/ ieee802154-supported; /delete-property/ ble-coded-phy-supported; }; + +&ieee802154 { + status = "okay"; +}; + +&gpio0 { + /* Needed by + * modules/hal_nordic/nrf_802154/sl_opensource/platform/nrf_802154_gpiote_zephyr.c + */ + status = "okay"; +}; From 15d4545a335550642baf00c9036debf12e3580c7 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 17 Mar 2023 15:14:05 +0100 Subject: [PATCH 0558/1906] nrf52_bsim: docs: Minor update The EGU has been modelled now. Add it to the list of supported peripherals. Signed-off-by: Alberto Escolar Piedras --- boards/posix/nrf52_bsim/doc/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/boards/posix/nrf52_bsim/doc/index.rst b/boards/posix/nrf52_bsim/doc/index.rst index 31d754dea86d..82df5072c583 100644 --- a/boards/posix/nrf52_bsim/doc/index.rst +++ b/boards/posix/nrf52_bsim/doc/index.rst @@ -25,6 +25,7 @@ This board models some of the NRF52 SOC peripherals: * Accelerated address resolver * Clock control * PPI (Programmable Peripheral Interconnect) +* EGU (Event Generator Unit) The nrf52_bsim board definition uses the POSIX architecture to run applications natively on the development system, this has the benefit of From a3ac4421d27bbe69da65191e48b8a9daee3f6531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Battrel?= Date: Mon, 20 Mar 2023 14:33:26 +0100 Subject: [PATCH 0559/1906] Bluetooth: Tests: Fix `bt_buf_get_evt` test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #55957. The `bt_buf_get_evt` test was using `net_buf` structures without allocating it properly. Signed-off-by: Théo Battrel --- tests/bluetooth/host/buf/bt_buf_get_evt/src/main.c | 12 ++++++++---- .../buf/bt_buf_get_evt/src/test_suite_hci_evt_cmd.c | 12 ++++++++---- .../src/test_suite_hci_evt_num_completed_packets.c | 12 ++++++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tests/bluetooth/host/buf/bt_buf_get_evt/src/main.c b/tests/bluetooth/host/buf/bt_buf_get_evt/src/main.c index df88ce959f2e..a17aee2b204e 100644 --- a/tests/bluetooth/host/buf/bt_buf_get_evt/src/main.c +++ b/tests/bluetooth/host/buf/bt_buf_get_evt/src/main.c @@ -92,7 +92,9 @@ static struct net_buf_pool *get_memory_pool(bool discardable) */ ZTEST(bt_buf_get_evt_default_events_returns_not_null, test_returns_not_null) { - static struct net_buf expected_buf; + const size_t user_data_size = sizeof(struct bt_buf_data); + uint8_t expected_buf_data[sizeof(struct net_buf) + user_data_size]; + struct net_buf *expected_buf = (struct net_buf *)expected_buf_data; struct net_buf *returned_buf; uint8_t returned_buffer_type; k_timeout_t timeout = Z_TIMEOUT_TICKS(1000); @@ -100,6 +102,8 @@ ZTEST(bt_buf_get_evt_default_events_returns_not_null, test_returns_not_null) uint8_t evt; bool discardable; + expected_buf->user_data_size = user_data_size; + for (size_t i = 0; i < (ARRAY_SIZE(testing_params_lut)); i++) { /* Register resets */ @@ -113,15 +117,15 @@ ZTEST(bt_buf_get_evt_default_events_returns_not_null, test_returns_not_null) evt != BT_HCI_EVT_NUM_COMPLETED_PACKETS), "Invalid event type %u to this test", evt); - net_buf_alloc_fixed_fake.return_val = &expected_buf; + net_buf_alloc_fixed_fake.return_val = expected_buf; returned_buf = bt_buf_get_evt(evt, discardable, timeout); expect_single_call_net_buf_alloc(get_memory_pool(discardable), &timeout); - expect_single_call_net_buf_reserve(&expected_buf); + expect_single_call_net_buf_reserve(expected_buf); expect_not_called_net_buf_ref(); - zassert_equal(returned_buf, &expected_buf, + zassert_equal(returned_buf, expected_buf, "bt_buf_get_evt() returned incorrect buffer pointer value"); returned_buffer_type = bt_buf_get_type(returned_buf); diff --git a/tests/bluetooth/host/buf/bt_buf_get_evt/src/test_suite_hci_evt_cmd.c b/tests/bluetooth/host/buf/bt_buf_get_evt/src/test_suite_hci_evt_cmd.c index 3574f6ced026..8c4c1ca0b5eb 100644 --- a/tests/bluetooth/host/buf/bt_buf_get_evt/src/test_suite_hci_evt_cmd.c +++ b/tests/bluetooth/host/buf/bt_buf_get_evt/src/test_suite_hci_evt_cmd.c @@ -110,7 +110,9 @@ ZTEST(bt_buf_get_evt_cmd_type_returns_null, test_return_value_matches_bt_buf_get ZTEST(bt_buf_get_evt_cmd_type_returns_not_null, test_return_value_matches_bt_buf_get_cmd_complete_not_null) { - static struct net_buf expected_buf; + const size_t user_data_size = sizeof(struct bt_buf_data); + uint8_t *expected_buf_data[sizeof(struct net_buf) + user_data_size]; + struct net_buf *expected_buf = (struct net_buf *)expected_buf_data; struct net_buf *returned_buf; uint8_t returned_buffer_type; k_timeout_t timeout = Z_TIMEOUT_TICKS(1000); @@ -118,6 +120,8 @@ ZTEST(bt_buf_get_evt_cmd_type_returns_not_null, uint8_t evt; bool discardable; + expected_buf->user_data_size = user_data_size; + for (size_t i = 0; i < (ARRAY_SIZE(testing_params_lut)); i++) { /* Register resets */ @@ -131,15 +135,15 @@ ZTEST(bt_buf_get_evt_cmd_type_returns_not_null, "Invalid event type %u to this test", evt); bt_dev.sent_cmd = NULL; - net_buf_alloc_fixed_fake.return_val = &expected_buf; + net_buf_alloc_fixed_fake.return_val = expected_buf; returned_buf = bt_buf_get_evt(evt, discardable, timeout); expect_single_call_net_buf_alloc(get_memory_pool(), &timeout); - expect_single_call_net_buf_reserve(&expected_buf); + expect_single_call_net_buf_reserve(expected_buf); expect_not_called_net_buf_ref(); - zassert_equal(returned_buf, &expected_buf, + zassert_equal(returned_buf, expected_buf, "bt_buf_get_evt() returned incorrect buffer pointer value"); returned_buffer_type = bt_buf_get_type(returned_buf); diff --git a/tests/bluetooth/host/buf/bt_buf_get_evt/src/test_suite_hci_evt_num_completed_packets.c b/tests/bluetooth/host/buf/bt_buf_get_evt/src/test_suite_hci_evt_num_completed_packets.c index dcd9fc7f12ef..c7f9f716b882 100644 --- a/tests/bluetooth/host/buf/bt_buf_get_evt/src/test_suite_hci_evt_num_completed_packets.c +++ b/tests/bluetooth/host/buf/bt_buf_get_evt/src/test_suite_hci_evt_num_completed_packets.c @@ -62,7 +62,9 @@ ZTEST_SUITE(bt_buf_get_evt_num_completed_pkts_type, NULL, NULL, NULL, NULL, NULL */ ZTEST(bt_buf_get_evt_num_completed_pkts_type, test_returns_not_null) { - static struct net_buf expected_buf; + const size_t user_data_size = sizeof(struct bt_buf_data); + uint8_t *expected_buf_data[sizeof(struct net_buf) + user_data_size]; + struct net_buf *expected_buf = (struct net_buf *)expected_buf_data; struct net_buf *returned_buf; uint8_t returned_buffer_type; k_timeout_t timeout = Z_TIMEOUT_TICKS(1000); @@ -70,6 +72,8 @@ ZTEST(bt_buf_get_evt_num_completed_pkts_type, test_returns_not_null) uint8_t evt; bool discardable; + expected_buf->user_data_size = user_data_size; + for (size_t i = 0; i < (ARRAY_SIZE(testing_params_lut)); i++) { /* Register resets */ @@ -82,15 +86,15 @@ ZTEST(bt_buf_get_evt_num_completed_pkts_type, test_returns_not_null) zassert_true((evt == BT_HCI_EVT_NUM_COMPLETED_PACKETS), "Invalid event type %u to this test", evt); - net_buf_alloc_fixed_fake.return_val = &expected_buf; + net_buf_alloc_fixed_fake.return_val = expected_buf; returned_buf = bt_buf_get_evt(evt, discardable, timeout); expect_single_call_net_buf_alloc(get_memory_pool(discardable), &timeout); - expect_single_call_net_buf_reserve(&expected_buf); + expect_single_call_net_buf_reserve(expected_buf); expect_not_called_net_buf_ref(); - zassert_equal(returned_buf, &expected_buf, + zassert_equal(returned_buf, expected_buf, "bt_buf_get_evt() returned incorrect buffer pointer value"); returned_buffer_type = bt_buf_get_type(returned_buf); From 40f0ea9f74c0b467e5dce1fa6973039630922d4d Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Tue, 21 Mar 2023 11:52:24 +0100 Subject: [PATCH 0560/1906] tests/bsim compile: Add support for multiple conf files And configuration files with paths, quotes, etc. Now it is possible to do, for example conf_file='myprj.conf;boards/board_name.conf' to provide both a project configuration and an overlay Signed-off-by: Alberto Escolar Piedras --- tests/bsim/compile.source | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/bsim/compile.source b/tests/bsim/compile.source index 1f8673c4973f..998265a48f49 100644 --- a/tests/bsim/compile.source +++ b/tests/bsim/compile.source @@ -22,21 +22,16 @@ function _compile(){ local cc_flags="${cc_flags:-"-Werror"}" if [ "${conf_overlay}" ]; then - local exe_name="${exe_name:-bs_${BOARD}_${app}_${conf_file}_${conf_overlay}}" + local exe_basename="${exe_name:-bs_${BOARD}_${app}_${conf_file}_${conf_overlay}}" else - local exe_name="${exe_name:-bs_${BOARD}_${app}_${conf_file}}" + local exe_basename="${exe_name:-bs_${BOARD}_${app}_${conf_file}}" fi - local exe_name=${exe_name//\//_} - local exe_name=${exe_name//./_} - local exe_name=${BSIM_OUT_PATH}/bin/$exe_name + local exe_basename=$(echo ${exe_basename} | tr \"/\\.\; _ ) + local exe_name=${BSIM_OUT_PATH}/bin/$exe_basename local map_file_name=${exe_name}.Tsymbols - if [ "${conf_overlay}" ]; then - local this_dir=${WORK_DIR}/${app}/${conf_file}_${conf_overlay} - else - local this_dir=${WORK_DIR}/${app}/${conf_file} - fi + local this_dir=${WORK_DIR}/${app}/${exe_basename} local modules_arg="${ZEPHYR_MODULES:+-DZEPHYR_MODULES=${ZEPHYR_MODULES}}" From a20046b5b037c9ec9d8901f84beaffd9ede5b601 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Tue, 21 Mar 2023 12:12:22 +0100 Subject: [PATCH 0561/1906] tests/bsim compile: Do not provide prj conf if default Do not provide the defautl prj.conf to cmake, as that causes it to not use the board overlays, which is not what users would normally expect. Signed-off-by: Alberto Escolar Piedras --- tests/bsim/compile.source | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/bsim/compile.source b/tests/bsim/compile.source index 998265a48f49..22ff8eebf373 100644 --- a/tests/bsim/compile.source +++ b/tests/bsim/compile.source @@ -39,8 +39,11 @@ function _compile(){ local ret=0 - local cmake_cmd=(cmake -GNinja -DBOARD_ROOT=${BOARD_ROOT} -DBOARD=${BOARD} \ - -DCONF_FILE=${conf_file} -DOVERLAY_CONFIG=${conf_overlay} \ + local cmake_cmd=(cmake -GNinja -DBOARD_ROOT=${BOARD_ROOT} -DBOARD=${BOARD}) + if [ $conf_file != "prj.conf" ]; then + local cmake_cmd+=( -DCONF_FILE=${conf_file}) + fi + local cmake_cmd+=( -DOVERLAY_CONFIG=${conf_overlay} \ ${modules_arg} \ ${cmake_args} -DCMAKE_C_FLAGS=\"${cc_flags}\" ${app_root}/${app}) From d44e36d4388dc20a0f66ba6b742efb5356a25238 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Tue, 21 Mar 2023 15:11:02 +0100 Subject: [PATCH 0562/1906] ci: bluetooth worflow: Rename to Bsim This workflow and tests do not cover just Bluetooth anymore but also cover other networking areas. Rename the workflow and artifacts for clarity. Signed-off-by: Alberto Escolar Piedras --- ...s-publish.yaml => bsim-tests-publish.yaml} | 16 +++++++------- .../{bluetooth-tests.yaml => bsim-tests.yaml} | 21 ++++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) rename .github/workflows/{bluetooth-tests-publish.yaml => bsim-tests-publish.yaml} (62%) rename .github/workflows/{bluetooth-tests.yaml => bsim-tests.yaml} (86%) diff --git a/.github/workflows/bluetooth-tests-publish.yaml b/.github/workflows/bsim-tests-publish.yaml similarity index 62% rename from .github/workflows/bluetooth-tests-publish.yaml rename to .github/workflows/bsim-tests-publish.yaml index 3cf6572c4a02..05cea30c5b70 100644 --- a/.github/workflows/bluetooth-tests-publish.yaml +++ b/.github/workflows/bsim-tests-publish.yaml @@ -1,13 +1,13 @@ -name: Publish Bluetooth Tests Results +name: Publish BabbleSim Tests Results on: workflow_run: - workflows: ["Bluetooth Tests"] + workflows: ["BabbleSim Tests"] types: - completed jobs: - bluetooth-test-results: - name: "Publish Bluetooth Test Results" + bsim-test-results: + name: "Publish BabbleSim Test Results" runs-on: ubuntu-20.04 if: github.event.workflow_run.conclusion != 'skipped' @@ -15,15 +15,15 @@ jobs: - name: Download artifacts uses: dawidd6/action-download-artifact@v2 with: - workflow: bluetooth-tests.yaml + workflow: bsim-tests.yaml run_id: ${{ github.event.workflow_run.id }} - - name: Publish Bluetooth Test Results + - name: Publish BabbleSim Test Results uses: EnricoMi/publish-unit-test-result-action@v1 with: - check_name: Bluetooth Test Results + check_name: BabbleSim Test Results comment_mode: off commit: ${{ github.event.workflow_run.head_sha }} event_file: event/event.json event_name: ${{ github.event.workflow_run.event }} - files: "bluetooth-test-results/**/bsim_results.xml" + files: "bsim-test-results/**/bsim_results.xml" diff --git a/.github/workflows/bluetooth-tests.yaml b/.github/workflows/bsim-tests.yaml similarity index 86% rename from .github/workflows/bluetooth-tests.yaml rename to .github/workflows/bsim-tests.yaml index 0d7df7eb2bd6..e04275dc6177 100644 --- a/.github/workflows/bluetooth-tests.yaml +++ b/.github/workflows/bsim-tests.yaml @@ -1,13 +1,14 @@ -name: Bluetooth Tests +name: BabbleSim Tests on: pull_request: paths: - - ".github/workflows/bluetooth-test*.yaml" + - ".github/workflows/bsim-test*.yaml" - "west.yml" - "subsys/bluetooth/**" - - "tests/bsim/bluetooth/**" + - "tests/bsim/**" - "samples/bluetooth/**" + - "samples/net/sockets/echo_*/**" - "boards/posix/**" - "soc/posix/**" - "arch/posix/**" @@ -17,7 +18,7 @@ concurrency: cancel-in-progress: true jobs: - bluetooth-test: + bsim-test: if: github.repository_owner == 'zephyrproject-rtos' runs-on: zephyr-runner-linux-x64-4xlarge container: @@ -31,7 +32,7 @@ jobs: BSIM_OUT_PATH: /opt/bsim/ BSIM_COMPONENTS_PATH: /opt/bsim/components EDTT_PATH: ../tools/edtt - bsim_bt_test_results_file: ./bsim_bt_out/bsim_results.xml + bsim_test_results_file: ./bsim_out/bsim_results.xml steps: - name: Apply container owner mismatch workaround run: | @@ -67,20 +68,20 @@ jobs: west update --path-cache /github/cache/zephyrproject 2>&1 1> west.update.log || west update --path-cache /github/cache/zephyrproject 2>&1 1> west.update.log || ( rm -rf ../modules ../bootloader ../tools && west update --path-cache /github/cache/zephyrproject) west forall -c 'git reset --hard HEAD' - - name: Run Bluetooth Tests with BSIM + - name: Run Networking Tests with BSIM run: | export ZEPHYR_BASE=${PWD} - WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bsim/compile.sh - RESULTS_FILE=${ZEPHYR_BASE}/${bsim_bt_test_results_file} \ + WORK_DIR=${ZEPHYR_BASE}/bsim_out tests/bsim/compile.sh + RESULTS_FILE=${ZEPHYR_BASE}/${bsim_test_results_file} \ SEARCH_PATH=tests/bsim/ tests/bsim/run_parallel.sh - name: Upload Test Results if: always() uses: actions/upload-artifact@v3 with: - name: bluetooth-test-results + name: bsim-test-results path: | - ./bsim_bt_out/bsim_results.xml + ./bsim_out/bsim_results.xml ${{ github.event_path }} - name: Upload Event Details From cadd6e6fa4d801ee09f73332e8fe342df5493e7e Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Wed, 22 Mar 2023 02:46:21 +0900 Subject: [PATCH 0563/1906] ci: backport_issue_check: Use ubuntu-22.04 virtual environment This commit updates the pull request backport issue check workflow to use the Ubuntu 22.04 virtual environment. Signed-off-by: Stephanos Ioannidis --- .github/workflows/backport_issue_check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backport_issue_check.yml b/.github/workflows/backport_issue_check.yml index 98f964d6d966..a66edd318f7d 100644 --- a/.github/workflows/backport_issue_check.yml +++ b/.github/workflows/backport_issue_check.yml @@ -8,7 +8,7 @@ on: jobs: backport: name: Backport Issue Check - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 if: github.repository == 'zephyrproject-rtos/zephyr' steps: From e40859f787128b9a8e000b51009502278fc59586 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Mon, 20 Mar 2023 17:05:49 +0200 Subject: [PATCH 0564/1906] Revert "dma: dw: Do not program SAR/DAR and CTL_HI/LO when using HW LLI" Failures are seen with SOF digital mic capture test cases on Intel cAVS2.5 platforms if the SAR/DAR/CTL writes are skipped. This reverts commit 08d9efb202cc4f436c7321fd49130c21a525e90d. Signed-off-by: Kai Vehmanen --- drivers/dma/dma_dw_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/dma/dma_dw_common.c b/drivers/dma/dma_dw_common.c index 16fd3c875b8f..87bc48d3c2fa 100644 --- a/drivers/dma/dma_dw_common.c +++ b/drivers/dma/dma_dw_common.c @@ -475,7 +475,8 @@ int dw_dma_start(const struct device *dev, uint32_t channel) dw_write(dev_cfg->base, DW_LLP(channel), llp); LOG_DBG("ctrl_lo %x, masked ctrl_lo %x, LLP %x", lli->ctrl_lo, masked_ctrl_lo, dw_read(dev_cfg->base, DW_LLP(channel))); -#else +#endif /* CONFIG_DMA_DW_HW_LLI */ + /* channel needs to start from scratch, so write SAR and DAR */ dw_write(dev_cfg->base, DW_SAR(channel), lli->sar); dw_write(dev_cfg->base, DW_DAR(channel), lli->dar); @@ -483,7 +484,6 @@ int dw_dma_start(const struct device *dev, uint32_t channel) /* program CTL_LO and CTL_HI */ dw_write(dev_cfg->base, DW_CTRL_LOW(channel), lli->ctrl_lo); dw_write(dev_cfg->base, DW_CTRL_HIGH(channel), lli->ctrl_hi); -#endif /* CONFIG_DMA_DW_HW_LLI */ /* program CFG_LO and CFG_HI */ dw_write(dev_cfg->base, DW_CFG_LOW(channel), chan_data->cfg_lo); From b8d3e9c50ed4f5e1ea87e8a4b89ac42c6aa64cd1 Mon Sep 17 00:00:00 2001 From: Hanf Gai Date: Mon, 6 Mar 2023 13:20:22 +0000 Subject: [PATCH 0565/1906] doc: connectivity: bluetooth: sync function name sync function name `bt_conn_le_create` with the code. Signed-off-by: Hanf Gai --- doc/connectivity/bluetooth/api/connection_mgmt.rst | 2 +- doc/connectivity/bluetooth/bluetooth-arch.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/connectivity/bluetooth/api/connection_mgmt.rst b/doc/connectivity/bluetooth/api/connection_mgmt.rst index fa6dfc24d07e..3a3d8d02a827 100644 --- a/doc/connectivity/bluetooth/api/connection_mgmt.rst +++ b/doc/connectivity/bluetooth/api/connection_mgmt.rst @@ -22,7 +22,7 @@ define callbacks for connection & disconnection events, as well as other events related to a connection such as a change in the security level or the connection parameters. When acting as a central the application will also get hold of the connection object through the return value of the -:c:func:`bt_conn_create_le` API. +:c:func:`bt_conn_le_create` API. API Reference ************* diff --git a/doc/connectivity/bluetooth/bluetooth-arch.rst b/doc/connectivity/bluetooth/bluetooth-arch.rst index d91ffa813799..3b69b00fc123 100644 --- a/doc/connectivity/bluetooth/bluetooth-arch.rst +++ b/doc/connectivity/bluetooth/bluetooth-arch.rst @@ -280,7 +280,7 @@ To initially discover a device to connect to the application will likely use the :c:func:`bt_le_scan_start` API, wait for an appropriate device to be found (using the scan callback), stop scanning using :c:func:`bt_le_scan_stop` and then connect to the device using -:c:func:`bt_conn_create_le`. If the central wants to keep +:c:func:`bt_conn_le_create`. If the central wants to keep automatically reconnecting to the peripheral it should use the :c:func:`bt_le_set_auto_conn` API. From 712dab4f04a9c91536aa36131cba6a051c909957 Mon Sep 17 00:00:00 2001 From: Anisetti Avinash Krishna Date: Fri, 17 Mar 2023 09:02:34 +0530 Subject: [PATCH 0566/1906] drivers: serial: ns16550: Fixed set_baud_rate usage in line ctrl set Added pclk parameter to set_baud_rate function in line_ctrl_set api which was missed during update of set_baud_rate function definition update. Signed-off-by: Anisetti Avinash Krishna --- drivers/serial/uart_ns16550.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/serial/uart_ns16550.c b/drivers/serial/uart_ns16550.c index ae737949de0d..13ba59951f3b 100644 --- a/drivers/serial/uart_ns16550.c +++ b/drivers/serial/uart_ns16550.c @@ -950,12 +950,21 @@ static int uart_ns16550_line_ctrl_set(const struct device *dev, uint32_t ctrl, uint32_t val) { struct uart_ns16550_dev_data *data = dev->data; - uint32_t mdc, chg; + const struct uart_ns16550_device_config *const dev_cfg = dev->config; + uint32_t mdc, chg, pclk = 0U; k_spinlock_key_t key; + if (dev_cfg->sys_clk_freq != 0U) { + pclk = dev_cfg->sys_clk_freq; + } else { + if (device_is_ready(dev_cfg->clock_dev)) { + clock_control_get_rate(dev_cfg->clock_dev, dev_cfg->clock_subsys, &pclk); + } + } + switch (ctrl) { case UART_LINE_CTRL_BAUD_RATE: - set_baud_rate(dev, val); + set_baud_rate(dev, val, pclk); return 0; case UART_LINE_CTRL_RTS: From 00991e47205cce72a25151a650de7b5a8d85f1a6 Mon Sep 17 00:00:00 2001 From: Anisetti Avinash Krishna Date: Fri, 17 Mar 2023 13:06:54 +0530 Subject: [PATCH 0567/1906] drivers: serial: ns16550: Moved PCIe probe to init function Moved PCIe probe from configure function to init function because whenever uart_configure api is called MMIO address is getting updated. Signed-off-by: Anisetti Avinash Krishna --- drivers/serial/uart_ns16550.c | 54 ++++++++++++++++------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/drivers/serial/uart_ns16550.c b/drivers/serial/uart_ns16550.c index 13ba59951f3b..8fc832ae4a43 100644 --- a/drivers/serial/uart_ns16550.c +++ b/drivers/serial/uart_ns16550.c @@ -332,38 +332,12 @@ static int uart_ns16550_configure(const struct device *dev, k_spinlock_key_t key = k_spin_lock(&dev_data->lock); - ARG_UNUSED(dev_data); - ARG_UNUSED(dev_cfg); - #if defined(CONFIG_PINCTRL) if (dev_cfg->pincfg != NULL) { pinctrl_apply_state(dev_cfg->pincfg, PINCTRL_STATE_DEFAULT); } #endif -#ifndef CONFIG_UART_NS16550_ACCESS_IOPORT -#if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie) - if (dev_cfg->pcie) { - struct pcie_bar mbar; - - if (dev_cfg->pcie->bdf == PCIE_BDF_NONE) { - ret = -EINVAL; - goto out; - } - - pcie_probe_mbar(dev_cfg->pcie->bdf, 0, &mbar); - pcie_set_cmd(dev_cfg->pcie->bdf, PCIE_CONF_CMDSTAT_MEM, true); - - device_map(DEVICE_MMIO_RAM_PTR(dev), mbar.phys_addr, mbar.size, - K_MEM_CACHE_NONE); - } else -#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie) */ - { - /* Map directly from DTS */ - DEVICE_MMIO_MAP(dev, K_MEM_CACHE_NONE); - } -#endif /* UART_NS15660_ACCESS_IOPORT */ - #ifdef CONFIG_UART_INTERRUPT_DRIVEN dev_data->iir_cache = 0U; #endif @@ -524,17 +498,39 @@ static int uart_ns16550_config_get(const struct device *dev, static int uart_ns16550_init(const struct device *dev) { struct uart_ns16550_dev_data *data = dev->data; + const struct uart_ns16550_device_config *dev_cfg = dev->config; int ret; + ARG_UNUSED(dev_cfg); + +#ifndef CONFIG_UART_NS16550_ACCESS_IOPORT +#if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie) + if (dev_cfg->pcie) { + struct pcie_bar mbar; + + if (dev_cfg->pcie->bdf == PCIE_BDF_NONE) { + return -EINVAL; + } + + pcie_probe_mbar(dev_cfg->pcie->bdf, 0, &mbar); + pcie_set_cmd(dev_cfg->pcie->bdf, PCIE_CONF_CMDSTAT_MEM, true); + + device_map(DEVICE_MMIO_RAM_PTR(dev), mbar.phys_addr, mbar.size, + K_MEM_CACHE_NONE); + } else +#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie) */ + { + /* Map directly from DTS */ + DEVICE_MMIO_MAP(dev, K_MEM_CACHE_NONE); + } +#endif /* !UART_NS15660_ACCESS_IOPORT */ ret = uart_ns16550_configure(dev, &data->uart_config); if (ret != 0) { return ret; } #ifdef CONFIG_UART_INTERRUPT_DRIVEN - const struct uart_ns16550_device_config *config = dev->config; - - config->irq_config_func(dev); + dev_cfg->irq_config_func(dev); #endif return 0; From fbe930ad0e3c40ffda73ab9c40ec497e28ac507d Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Fri, 17 Mar 2023 11:43:15 +0100 Subject: [PATCH 0568/1906] driver: gpdma: balance the pm usage Because the DMA driver allows multiple start and stop calls for the same instance and the same channel, we cannot rely on the error codes returned by these functions to notify the device's power manager that a device is still in use. Signed-off-by: Tomasz Leman --- drivers/dma/dma_dw_common.c | 4 +++- drivers/dma/dma_intel_adsp_gpdma.c | 31 ++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/drivers/dma/dma_dw_common.c b/drivers/dma/dma_dw_common.c index 87bc48d3c2fa..d216dd00b0f4 100644 --- a/drivers/dma/dma_dw_common.c +++ b/drivers/dma/dma_dw_common.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "dma_dw_common.h" @@ -508,6 +509,7 @@ int dw_dma_start(const struct device *dev, uint32_t channel) /* enable the channel */ dw_write(dev_cfg->base, DW_DMA_CHAN_EN, DW_CHAN_UNMASK(channel)); + ret = pm_device_runtime_get(dev); out: return ret; @@ -577,7 +579,7 @@ int dw_dma_stop(const struct device *dev, uint32_t channel) } #endif chan_data->state = DW_DMA_IDLE; - + ret = pm_device_runtime_put(dev); out: return ret; } diff --git a/drivers/dma/dma_intel_adsp_gpdma.c b/drivers/dma/dma_intel_adsp_gpdma.c index 5d673e36cee1..2435fdbf6883 100644 --- a/drivers/dma/dma_intel_adsp_gpdma.c +++ b/drivers/dma/dma_intel_adsp_gpdma.c @@ -161,7 +161,24 @@ static int intel_adsp_gpdma_config(const struct device *dev, uint32_t channel, static int intel_adsp_gpdma_start(const struct device *dev, uint32_t channel) { - int ret; + int ret = 0; + bool first_use = false; + enum pm_device_state state; + + /* We need to power-up device before using it. So in case of a GPDMA, we need to check if + * the current instance is already active, and if not, we let the power manager know that + * we want to use it. + */ + if (pm_device_state_get(dev, &state) != -ENOSYS) { + first_use = state != PM_DEVICE_STATE_ACTIVE; + if (first_use) { + ret = pm_device_runtime_get(dev); + } + } + + if (ret < 0) { + return ret; + } intel_adsp_gpdma_llp_enable(dev, channel); ret = dw_dma_start(dev, channel); @@ -169,8 +186,12 @@ static int intel_adsp_gpdma_start(const struct device *dev, uint32_t channel) intel_adsp_gpdma_llp_disable(dev, channel); } - if (ret == 0) { - ret = pm_device_runtime_get(dev); + /* Device usage is counted by the calls of dw_dma_start and dw_dma_stop. For the first use, + * we need to make sure that the pm_device_runtime_get and pm_device_runtime_put functions + * calls are balanced. + */ + if (first_use) { + ret = pm_device_runtime_put(dev); } return ret; @@ -178,12 +199,10 @@ static int intel_adsp_gpdma_start(const struct device *dev, uint32_t channel) static int intel_adsp_gpdma_stop(const struct device *dev, uint32_t channel) { - int ret; + int ret = dw_dma_stop(dev, channel); - ret = dw_dma_stop(dev, channel); if (ret == 0) { intel_adsp_gpdma_llp_disable(dev, channel); - ret = pm_device_runtime_put(dev); } return ret; From dc8f02309883f623253bf3f0ab84979cd03fb3c7 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 21 Mar 2023 12:43:28 +0100 Subject: [PATCH 0569/1906] net: ipv6: Fix Kconfig dependencies when native IPv6 is disabled In case native IPv6 is disabled, Kconfig entries related to native IPv6 stack should not be enabled. Otherwise, circular dependencies can be created if native stack is disabled, as in case of recent changes in NET_IPV6_RA_RDNSS option (where a dependency for a native stack module was enabled). Signed-off-by: Robert Lubos --- subsys/net/ip/Kconfig.ipv6 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/subsys/net/ip/Kconfig.ipv6 b/subsys/net/ip/Kconfig.ipv6 index e9b8916d3824..b776d3756eb4 100644 --- a/subsys/net/ip/Kconfig.ipv6 +++ b/subsys/net/ip/Kconfig.ipv6 @@ -37,6 +37,8 @@ config NET_IF_IPV6_PREFIX_COUNT int "Max number of IPv6 prefixes per network interface" default 2 +if NET_NATIVE_IPV6 + config NET_INITIAL_HOP_LIMIT int "Initial hop limit for a connection" default 64 @@ -190,4 +192,5 @@ module-str = Log level for IPv6 neighbor cache module-help = Enables IPv6 Neighbor Cache code to output debug messages. source "subsys/net/Kconfig.template.log_config.net" +endif # NET_NATIVE_IPV6 endif # NET_IPV6 From 483126f492eaefd1bbd9daf7543a5dfd6a429795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Battrel?= Date: Tue, 21 Mar 2023 14:10:09 +0100 Subject: [PATCH 0570/1906] Bluetooth: Host: Move new `bt_data` functions to `data.c` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move newly added `bt_data_get_len` and `bt_data_serialize` from `ead.c` to `data.c`. Also, removed unnecessary include of `zephyr/kernel.h`. Signed-off-by: Théo Battrel --- subsys/bluetooth/host/data.c | 37 +++++++++++++++++++++++++++++++++++- subsys/bluetooth/lib/ead.c | 34 --------------------------------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/subsys/bluetooth/host/data.c b/subsys/bluetooth/host/data.c index 151dba181291..4afd9aad0a78 100644 --- a/subsys/bluetooth/host/data.c +++ b/subsys/bluetooth/host/data.c @@ -5,7 +5,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include + #include #define LOG_LEVEL CONFIG_BT_HCI_CORE_LOG_LEVEL @@ -43,3 +44,37 @@ void bt_data_parse(struct net_buf_simple *ad, net_buf_simple_pull(ad, len - 1); } } + +size_t bt_data_get_len(const struct bt_data data[], size_t data_count) +{ + size_t total_len = 0; + + for (size_t i = 0; i < data_count; i++) { + total_len += sizeof(data[i].data_len) + sizeof(data[i].type) + data[i].data_len; + } + + return total_len; +} + +size_t bt_data_serialize(const struct bt_data *input, uint8_t *output) +{ + CHECKIF(input == NULL) { + LOG_DBG("input is NULL"); + return 0; + } + + CHECKIF(output == NULL) { + LOG_DBG("output is NULL"); + return 0; + } + + uint8_t ad_data_len = input->data_len; + uint8_t data_len = ad_data_len + 1; + + output[0] = data_len; + output[1] = input->type; + + memcpy(&output[2], input->data, ad_data_len); + + return data_len + 1; +} diff --git a/subsys/bluetooth/lib/ead.c b/subsys/bluetooth/lib/ead.c index 69b78fa62ac3..40e07e9c2688 100644 --- a/subsys/bluetooth/lib/ead.c +++ b/subsys/bluetooth/lib/ead.c @@ -75,40 +75,6 @@ static int bt_ead_generate_nonce(const uint8_t iv[BT_EAD_IV_SIZE], return 0; } -size_t bt_data_get_len(const struct bt_data data[], size_t data_count) -{ - size_t total_len = 0; - - for (size_t i = 0; i < data_count; i++) { - total_len += sizeof(data[i].data_len) + sizeof(data[i].type) + data[i].data_len; - } - - return total_len; -} - -size_t bt_data_serialize(const struct bt_data *input, uint8_t *output) -{ - CHECKIF(input == NULL) { - LOG_DBG("input is NULL"); - return 0; - } - - CHECKIF(output == NULL) { - LOG_DBG("output_ad_structure is NULL"); - return 0; - } - - uint8_t ad_data_len = input->data_len; - uint8_t data_len = ad_data_len + 1; - - output[0] = data_len; - output[1] = input->type; - - memcpy(&output[2], input->data, ad_data_len); - - return data_len + 1; -} - static int ead_encrypt(const uint8_t session_key[BT_EAD_KEY_SIZE], const uint8_t iv[BT_EAD_IV_SIZE], const uint8_t randomizer[BT_EAD_RANDOMIZER_SIZE], const uint8_t *payload, size_t payload_size, uint8_t *encrypted_payload) From 8851a83e182445b44bdd36f03f57bb6caced1498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hidalgo=20Mu=C3=B1oz=20de=20Rivera?= Date: Tue, 7 Mar 2023 20:36:08 +0100 Subject: [PATCH 0571/1906] samples: Added README for watchdog sample MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added README for watchdog sample in rst format Signed-off-by: Alejandro Hidalgo Muñoz de Rivera --- samples/drivers/watchdog/README.rst | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 samples/drivers/watchdog/README.rst diff --git a/samples/drivers/watchdog/README.rst b/samples/drivers/watchdog/README.rst new file mode 100644 index 000000000000..54f95cb032b6 --- /dev/null +++ b/samples/drivers/watchdog/README.rst @@ -0,0 +1,55 @@ +.. _watchdog-sample: + +Watchdog Sample +############### + +Overview +******** + +This sample demonstrates how to use the watchdog driver API. + +A typical use case for a watchdog is that the board is restarted in case some piece of code +is kept in an infinite loop. + +Building and Running +******************** + +In this sample, a watchdog callback is used to handle a timeout event once. This functionality is used to request an action before the board +restarts due to a timeout event in the watchdog driver. + +The watchdog peripheral is configured in the board's ``.dts`` file. Make sure that the watchdog is enabled +using the configuration file in ``boards`` folder. + +Building and Running for ST Nucleo F091RC +========================================= + +The sample can be built and executed for the +:ref:`nucleo_f091rc_board` as follows: + +.. zephyr-app-commands:: + :zephyr-app: samples/drivers/watchdog + :board: nucleo_f091rc + :goals: build flash + :compact: + +To build for another board, change "nucleo_f091rc" to the name of that board and provide a corresponding devicetree overlay. + +Sample output +============= + +You should get a similar output as below: + +.. code-block:: console + + Watchdog sample application + Attempting to test pre-reset callback + Feeding watchdog 5 times + Feeding watchdog... + Feeding watchdog... + Feeding watchdog... + Feeding watchdog... + Feeding watchdog... + Waiting for reset... + Handled things..ready to reset + +.. note:: After the last message, the board will reset and the sequence will start again From 18af9f0f61b7e1ac307cd64cd0bdba6b5fcef7ce Mon Sep 17 00:00:00 2001 From: Peter Mitsis Date: Tue, 21 Mar 2023 13:53:29 -0400 Subject: [PATCH 0572/1906] kernel: Add missing stdbool.h to kernel/stats.h The structure k_cycle_stats uses the bool type. Consequently it should include the stdbool.h header file. Fixes #55972 Signed-off-by: Peter Mitsis --- include/zephyr/kernel/stats.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/zephyr/kernel/stats.h b/include/zephyr/kernel/stats.h index e5d4083a09e3..68f58b580183 100644 --- a/include/zephyr/kernel/stats.h +++ b/include/zephyr/kernel/stats.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Intel Corporation + * Copyright (c) 2021,2023, Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,6 +8,7 @@ #define ZEPHYR_INCLUDE_KERNEL_STATS_H_ #include +#include /* * [k_cycle_stats] is used to track internal statistics about both thread From cb953a4255eefc20f441a1f1d55834556d63832a Mon Sep 17 00:00:00 2001 From: Vaishnav Achath Date: Tue, 18 Oct 2022 21:35:51 +0530 Subject: [PATCH 0573/1906] soc: arm: ti_simplelink: Add support for TI CC13X2X7 SoC series MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Product URL: https://www.ti.com/product/CC1352P7 Datasheet : https://www.ti.com/lit/ds/symlink/cc1352p7.pdf Features: Powerful 48-MHz Arm® Cortex®-M4F processor * 704KB flash program memory * 256KB of ROM for protocols and library functions * 8KB of cache SRAM * 144KB of ultra-low leakage SRAM with parity for high-reliability operation * Dual-band Sub-1 GHz and 2.4 GHz operation Updates: * Remove CC1352P7_LaunchXL due to compliance checks * Add CC1352P7 updates * Update hal_ti for CC1352P7 support * Remove blank line at end of modules/Kconfig.simplelink * Split struct and typedef for pinctrl_soc_pin/pinctrl_soc_pin_t * Reference cc13x2_cc26x2/pinctrl_soc.h * Reference cc13x2_cc26x2/soc.h Signed-off-by: Vaishnav Achath --- dts/arm/ti/cc1352r7.dtsi | 31 +++ modules/Kconfig.simplelink | 3 + .../cc13x2x7_cc26x2x7/CMakeLists.txt | 11 + .../Kconfig.defconfig.cc1352r7 | 9 + .../Kconfig.defconfig.cc2652r7 | 8 + .../Kconfig.defconfig.series | 47 +++++ .../cc13x2x7_cc26x2x7/Kconfig.series | 18 ++ .../cc13x2x7_cc26x2x7/Kconfig.soc | 68 ++++++ .../ti_simplelink/cc13x2x7_cc26x2x7/ccfg.c | 26 +++ .../ti_simplelink/cc13x2x7_cc26x2x7/ccfg.ld | 15 ++ .../ti_simplelink/cc13x2x7_cc26x2x7/linker.ld | 8 + .../cc13x2x7_cc26x2x7/pinctrl_soc.h | 7 + .../ti_simplelink/cc13x2x7_cc26x2x7/power.c | 194 ++++++++++++++++++ soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/soc.c | 21 ++ soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/soc.h | 7 + .../src/arm_irq_vector_table.c | 2 +- west.yml | 2 +- 17 files changed, 475 insertions(+), 2 deletions(-) create mode 100644 dts/arm/ti/cc1352r7.dtsi create mode 100644 soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/CMakeLists.txt create mode 100644 soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.defconfig.cc1352r7 create mode 100644 soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.defconfig.cc2652r7 create mode 100644 soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.defconfig.series create mode 100644 soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.series create mode 100644 soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.soc create mode 100644 soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/ccfg.c create mode 100644 soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/ccfg.ld create mode 100644 soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/linker.ld create mode 100644 soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/pinctrl_soc.h create mode 100644 soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/power.c create mode 100644 soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/soc.c create mode 100644 soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/soc.h diff --git a/dts/arm/ti/cc1352r7.dtsi b/dts/arm/ti/cc1352r7.dtsi new file mode 100644 index 000000000000..0b098c81c81f --- /dev/null +++ b/dts/arm/ti/cc1352r7.dtsi @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2019 Brett Witherspoon + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/ { + sram0: memory@20000000 { + reg = <0x20000000 DT_SIZE_K(144)>; + }; +}; + +&flash0 { + reg = <0x0 DT_SIZE_K(704)>; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + /* CCFG registers occupy the last 88 bytes of flash */ + ti_ccfg_partition: partition@affa8 { + compatible = "zephyr,memory-region"; + reg = <0xaffa8 88>; + zephyr,memory-region = "FLASH_CCFG"; + }; + }; +}; diff --git a/modules/Kconfig.simplelink b/modules/Kconfig.simplelink index 4506a916bbb1..cbcf1766d6b2 100644 --- a/modules/Kconfig.simplelink +++ b/modules/Kconfig.simplelink @@ -29,3 +29,6 @@ config HAS_MSP432P4XXSDK config HAS_CC13X2_CC26X2_SDK bool + +config HAS_CC13X2X7_CC26X2X7_SDK + bool diff --git a/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/CMakeLists.txt b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/CMakeLists.txt new file mode 100644 index 000000000000..4a2a41c5a5f2 --- /dev/null +++ b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright (c) 2022 Vaishnav Achath +# +# SPDX-License-Identifier: Apache-2.0 + +zephyr_sources(soc.c) +zephyr_sources(ccfg.c) + +zephyr_library_sources_ifdef(CONFIG_PM power.c) +zephyr_library_sources_ifdef(CONFIG_PM_DEVICE power.c) + +zephyr_linker_sources_ifdef(CONFIG_HAS_TI_CCFG SECTIONS ccfg.ld) diff --git a/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.defconfig.cc1352r7 b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.defconfig.cc1352r7 new file mode 100644 index 000000000000..fabdeedf2d60 --- /dev/null +++ b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.defconfig.cc1352r7 @@ -0,0 +1,9 @@ +# Texas Instruments SimpleLink CC1352R +# +# Copyright (c) 2022 Vaishnav Achath +# +# SPDX-License-Identifier: Apache-2.0 + +config SOC + default "cc1352r7" + depends on SOC_CC1352R7 diff --git a/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.defconfig.cc2652r7 b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.defconfig.cc2652r7 new file mode 100644 index 000000000000..2ba4afb87674 --- /dev/null +++ b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.defconfig.cc2652r7 @@ -0,0 +1,8 @@ +# Texas Instruments SimpleLink CC2652R + +# Copyright (c) 2022 Vaishnav Achath +# SPDX-License-Identifier: Apache-2.0 + +config SOC + default "cc2652r7" + depends on SOC_CC2652R7 diff --git a/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.defconfig.series b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.defconfig.series new file mode 100644 index 000000000000..ede32e927010 --- /dev/null +++ b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.defconfig.series @@ -0,0 +1,47 @@ +# Texas Instruments SimpleLink CC13x2 / CC26x2 + +# Copyright (c) 2022 Vaishnav Achath +# SPDX-License-Identifier: Apache-2.0 + +if SOC_SERIES_CC13X2X7_CC26X2X7 + +source "soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.defconfig.cc*" + +config SOC_SERIES + default "cc13x2x7_cc26x2x7" + +config SYS_CLOCK_HW_CYCLES_PER_SEC + default 32768 + +# Note that when using the RTC as system clock, this needs to be 32768 +# to reduce truncation errors from accumulating due to conversion to/from +# time, ticks, and HW cycles +config SYS_CLOCK_TICKS_PER_SEC + default 32768 + +config NUM_IRQS + default 38 + +if IEEE802154 + +config IEEE802154_CC13XX_CC26XX + # required for linking with PowerCC26X2_config in + # soc/arm/ti_simplelink/cc13x2_cc26x2/power.c + select PM + +config IEEE802154_CC13XX_CC26XX_SUB_GHZ + # required for linking with PowerCC26X2_config in + # soc/arm/ti_simplelink/cc13x2_cc26x2/power.c + select PM + +endif # IEEE802154 + +if BT + +config BLE_CC13XX_CC26XX + bool + default y + +endif # BT + +endif # SOC_SERIES_CC13X2X7_CC26X2X7 diff --git a/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.series b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.series new file mode 100644 index 000000000000..a937b6c521c1 --- /dev/null +++ b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.series @@ -0,0 +1,18 @@ +# Texas Instruments SimpleLink CC13x2 / CC26x2 + +# Copyright (c) 2022 Vaishnav Achath +# SPDX-License-Identifier: Apache-2.0 + +config SOC_SERIES_CC13X2X7_CC26X2X7 + bool "TI SimpleLink Family CC13x2x7/ CC26x2x7" + select ARM + select CPU_CORTEX_M4 + select CPU_HAS_ARM_MPU + select DYNAMIC_INTERRUPTS + select CPU_CORTEX_M_HAS_DWT + select CPU_HAS_FPU + select SOC_FAMILY_TISIMPLELINK + select HAS_CC13X2X7_CC26X2X7_SDK + select HAS_TI_CCFG if !BOOTLOADER_MCUBOOT + help + Enable support for TI SimpleLink CC13x2x7 / CC26x2x7 SoCs diff --git a/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.soc b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.soc new file mode 100644 index 000000000000..74fae9acafd0 --- /dev/null +++ b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/Kconfig.soc @@ -0,0 +1,68 @@ +# Texas Instruments SimpleLink CC13x2 / CC26x2 + +# Copyright (c) 2022 Vaishnav Achath +# SPDX-License-Identifier: Apache-2.0 + +choice + prompt "TI SimpleLink MCU Selection" + depends on SOC_SERIES_CC13X2X7_CC26X2X7 + +config SOC_CC2652R7 + bool "CC2652R7" + +config SOC_CC1352R7 + bool "CC1352R7" + +config SOC_CC2652P7 + bool "CC2652P7" + +config SOC_CC1352P7 + bool "CC1352P7" + +endchoice + +menu "Customer Configuration (CCFG)" +depends on SOC_SERIES_CC13X2X7_CC26X2X7 + +config CC13X2_CC26X2_BOOST_MODE + bool "Radio boost mode (VDDR_HH)" + help + Enable the radio boost mode +14dBm (sets CCFG_FORCE_VDDR_HH to 1). + +config CC13X2_CC26X2_HAS_CUSTOM_RF_HWATTRS + bool "Board defines custom RFCC26XX hwAttrs structure" + help + The board defines its own RFCC26XX_hwAttrs structure (e.g., for + custom antenna switching callback). + +config CC13X2_CC26X2_BOOTLOADER_ENABLE + bool "ROM bootloader" + help + Enable the serial bootloader which resides in ROM on CC13xx / CC26xx + devices. + +config CC13X2_CC26X2_BOOTLOADER_BACKDOOR_ENABLE + bool "ROM bootloader backdoor" + depends on CC13X2_CC26X2_BOOTLOADER_ENABLE + help + Enable the ROM bootloader backdoor which starts the bootloader if the + associated pin is at the correct logic level on reset. + +config CC13X2_CC26X2_BOOTLOADER_BACKDOOR_PIN + int "ROM bootloader backdoor pin" + depends on CC13X2_CC26X2_BOOTLOADER_BACKDOOR_ENABLE + range 0 255 + default 255 + help + Set the pin that is level checked if the bootloader backdoor is + enabled. + +config CC13X2_CC26X2_BOOTLOADER_BACKDOOR_LEVEL + int "ROM bootloader backdoor level" + depends on CC13X2_CC26X2_BOOTLOADER_BACKDOOR_ENABLE + range 0 1 + default 0 + help + Set the active level of the pin selected for the bootloader backdoor. + +endmenu diff --git a/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/ccfg.c b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/ccfg.c new file mode 100644 index 000000000000..148a128d6202 --- /dev/null +++ b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/ccfg.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 Vaishnav Achath + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifdef CONFIG_CC13X2_CC26X2_BOOST_MODE +#define CCFG_FORCE_VDDR_HH 1 +#endif + +#ifdef CONFIG_CC13X2_CC26X2_BOOTLOADER_ENABLE +#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0xC5 +#else +#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0x00 +#endif /* CONFIG_CC13X2_CC26X2_BOOTLOADER_ENABLE */ + +#ifdef CONFIG_CC13X2_CC26X2_BOOTLOADER_BACKDOOR_ENABLE +#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xC5 +#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER CONFIG_CC13X2_CC26X2_BOOTLOADER_BACKDOOR_PIN +#define SET_CCFG_BL_CONFIG_BL_LEVEL CONFIG_CC13X2_CC26X2_BOOTLOADER_BACKDOOR_LEVEL +#else +#define SET_CCFG_BL_CONFIG_BL_ENABLE 0x00 +#endif /* CONFIG_CC13X2_CC26X2_BOOTLOADER_BACKDOOR_ENABLE */ + +/* TI recommends setting CCFG values and then including the TI provided ccfg.c */ +#include diff --git a/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/ccfg.ld b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/ccfg.ld new file mode 100644 index 000000000000..e0e7edbaa0b6 --- /dev/null +++ b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/ccfg.ld @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2021, Commonwealth Scientific and Industrial Research + * Organisation (CSIRO) ABN 41 687 119 230. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +GROUP_START(FLASH_CCFG) + +SECTION_PROLOGUE(.ti_ccfg,,) +{ + KEEP(*(_TI_CCFG_SECTION_NAME)) +} GROUP_LINK_IN(LINKER_DT_NODE_REGION_NAME(DT_NODELABEL(ti_ccfg_partition))) + +GROUP_END(FLASH_CCFG) diff --git a/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/linker.ld b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/linker.ld new file mode 100644 index 000000000000..f7ba43c42ca7 --- /dev/null +++ b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/linker.ld @@ -0,0 +1,8 @@ +/* linker.ld - Linker command/script file + * + * Copyright (c) 2022 Vaishnav Achath + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include diff --git a/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/pinctrl_soc.h b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/pinctrl_soc.h new file mode 100644 index 000000000000..2c9678801f7d --- /dev/null +++ b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/pinctrl_soc.h @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2022 Vaishnav Achath + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "../cc13x2_cc26x2/pinctrl_soc.h" diff --git a/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/power.c b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/power.c new file mode 100644 index 000000000000..cdb54233dcb1 --- /dev/null +++ b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/power.c @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2019 Linaro Limited. + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + +#include +#include +#include + +#include +#define LOG_LEVEL CONFIG_SOC_LOG_LEVEL +LOG_MODULE_REGISTER(soc); + +const PowerCC26X2_Config PowerCC26X2_config = { +#if defined(CONFIG_IEEE802154_CC13XX_CC26XX) \ + || defined(CONFIG_BLE_CC13XX_CC26XX) \ + || defined(CONFIG_IEEE802154_CC13XX_CC26XX_SUB_GHZ) + .policyInitFxn = NULL, + .policyFxn = NULL, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = false, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true +#else +/* Configuring TI Power module to not use its policy function (we use Zephyr's + * instead), and disable oscillator calibration functionality for now. + */ + .policyInitFxn = NULL, + .policyFxn = NULL, + .calibrateFxn = NULL, + .enablePolicy = false, + .calibrateRCOSC_LF = false, + .calibrateRCOSC_HF = false +#endif +}; + +extern PowerCC26X2_ModuleState PowerCC26X2_module; + +#ifdef CONFIG_PM +/* + * Power state mapping: + * PM_STATE_SUSPEND_TO_IDLE: Idle + * PM_STATE_STANDBY: Standby + * PM_STATE_SUSPEND_TO_RAM | PM_STATE_SUSPEND_TO_DISK: Shutdown + */ + +/* Invoke Low Power/System Off specific Tasks */ +__weak void pm_state_set(enum pm_state state, uint8_t substate_id) +{ + ARG_UNUSED(substate_id); + + uint32_t modeVIMS; + uint32_t constraints; + + LOG_DBG("SoC entering power state %d", state); + + /* Switch to using PRIMASK instead of BASEPRI register, since + * we are only able to wake up from standby while using PRIMASK. + */ + /* Set PRIMASK */ + CPUcpsid(); + /* Set BASEPRI to 0 */ + irq_unlock(0); + + switch (state) { + case PM_STATE_SUSPEND_TO_IDLE: + /* query the declared constraints */ + constraints = Power_getConstraintMask(); + /* 1. Get the current VIMS mode */ + do { + modeVIMS = VIMSModeGet(VIMS_BASE); + } while (modeVIMS == VIMS_MODE_CHANGING); + + /* 2. Configure flash to remain on in IDLE or not and keep + * VIMS powered on if it is configured as GPRAM + * 3. Always keep cache retention ON in IDLE + * 4. Turn off the CPU power domain + * 5. Ensure any possible outstanding AON writes complete + * 6. Enter IDLE + */ + if ((constraints & (1 << PowerCC26XX_NEED_FLASH_IN_IDLE)) || + (modeVIMS == VIMS_MODE_DISABLED)) { + SysCtrlIdle(VIMS_ON_BUS_ON_MODE); + } else { + SysCtrlIdle(VIMS_ON_CPU_ON_MODE); + } + + /* 7. Make sure MCU and AON are in sync after wakeup */ + SysCtrlAonUpdate(); + break; + + case PM_STATE_STANDBY: + /* go to standby mode */ + Power_sleep(PowerCC26XX_STANDBY); + break; + case PM_STATE_SUSPEND_TO_RAM: + __fallthrough; + case PM_STATE_SUSPEND_TO_DISK: + __fallthrough; + case PM_STATE_SOFT_OFF: + Power_shutdown(0, 0); + break; + default: + LOG_DBG("Unsupported power state %u", state); + break; + } + + LOG_DBG("SoC leaving power state %d", state); +} + +/* Handle SOC specific activity after Low Power Mode Exit */ +__weak void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id) +{ + ARG_UNUSED(state); + ARG_UNUSED(substate_id); + + /* + * System is now in active mode. Reenable interrupts which were disabled + * when OS started idling code. + */ + CPUcpsie(); +} +#endif /* CONFIG_PM */ + +/* Initialize TI Power module */ +static int power_initialize(const struct device *dev) +{ + unsigned int ret; + + ARG_UNUSED(dev); + + ret = irq_lock(); + Power_init(); + irq_unlock(ret); + + return 0; +} + +/* + * Unlatch IO pins after waking up from shutdown + * This needs to be called during POST_KERNEL in order for "Booting Zephyr" + * message to show up + */ +static int unlatch_pins(const struct device *dev) +{ + /* Get the reason for reset. */ + uint32_t rSrc = SysCtrlResetSourceGet(); + + if (rSrc == RSTSRC_WAKEUP_FROM_SHUTDOWN) { + PowerCtrlPadSleepDisable(); + } + + return 0; +} + +/* + * ======== PowerCC26XX_schedulerDisable ======== + */ +void PowerCC26XX_schedulerDisable(void) +{ + /* + * We are leaving this empty because Zephyr's + * scheduler would not get to run with interrupts being disabled + * in the context of Power_sleep() in any case. + */ +} + +/* + * ======== PowerCC26XX_schedulerRestore ======== + */ +void PowerCC26XX_schedulerRestore(void) +{ + /* + * We are leaving this empty because Zephyr's + * scheduler would not get to run with interrupts being disabled + * in the context of Power_sleep() in any case. + */ +} + +SYS_INIT(power_initialize, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); +SYS_INIT(unlatch_pins, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/soc.c b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/soc.c new file mode 100644 index 000000000000..ac126bdab292 --- /dev/null +++ b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/soc.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Vaishnav Achath + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include + +static int ti_cc13x2_cc26x2_init(const struct device *dev) +{ + ARG_UNUSED(dev); + + /* Performs necessary trim of the device. */ + SetupTrimDevice(); + + return 0; +} + +SYS_INIT(ti_cc13x2_cc26x2_init, PRE_KERNEL_1, 0); diff --git a/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/soc.h b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/soc.h new file mode 100644 index 000000000000..c0f578f417d5 --- /dev/null +++ b/soc/arm/ti_simplelink/cc13x2x7_cc26x2x7/soc.h @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2022 Vaishnav Achath + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "../cc13x2_cc26x2/soc.h" diff --git a/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c b/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c index 0057491c0fa7..f51291cd958f 100644 --- a/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c +++ b/tests/arch/arm/arm_irq_vector_table/src/arm_irq_vector_table.c @@ -216,7 +216,7 @@ vth __irq_vector_table _irq_vector_table[] = { }; #endif #endif -#elif defined(CONFIG_SOC_SERIES_CC13X2_CC26X2) +#elif defined(CONFIG_SOC_SERIES_CC13X2_CC26X2) || defined(CONFIG_SOC_SERIES_CC13X2X7_CC26X2X7) /* TI CC13x2/CC26x2 based platforms also employ a Hardware RTC peripheral * to implement the Kernel system timer, instead of the ARM Cortex-M * SysTick. Therefore, a pointer to the timer ISR needs to be added in diff --git a/west.yml b/west.yml index 22f3a67a77b9..b67a39d8b8df 100644 --- a/west.yml +++ b/west.yml @@ -139,7 +139,7 @@ manifest: groups: - hal - name: hal_ti - revision: 5e7d5cd584047699c9fd279923120cb25ba3dda7 + revision: cd40806ee15f4f8f73e1561d3c0e9d99444ea8f0 path: modules/hal/ti groups: - hal From f36be35600288d991f97fec99c4e444a1de29247 Mon Sep 17 00:00:00 2001 From: Jason Kridner Date: Sat, 18 Mar 2023 20:47:44 -0400 Subject: [PATCH 0574/1906] scripts: compliance: allow webp image files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WebP images are smaller for similar resolutions and quality while being compatible with web browsers and other image processing tools. For higher resolution images, be sure to limit the display size to make the rendered pages look reasonable. This was approved by Benjamin Cabé (@kartben) in this discussion thread: https://github.com/zephyrproject-rtos/zephyr/pull/55488#issuecomment-1461792751 Signed-off-by: Jason Kridner --- scripts/ci/check_compliance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index 63fa4a3371be..4f2e6427d90c 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -944,7 +944,7 @@ class BinaryFiles(ComplianceTest): def run(self): BINARY_ALLOW_PATHS = ("doc/", "boards/", "samples/") # svg files are always detected as binary, see .gitattributes - BINARY_ALLOW_EXT = (".jpg", ".jpeg", ".png", ".svg") + BINARY_ALLOW_EXT = (".jpg", ".jpeg", ".png", ".svg", ".webp") for stat in git("diff", "--numstat", "--diff-filter=A", COMMIT_RANGE).splitlines(): From a57810dc3b1ea9f1a39f6f3b8ae213700925bd6c Mon Sep 17 00:00:00 2001 From: Jason Kridner Date: Mon, 6 Mar 2023 11:18:45 -0500 Subject: [PATCH 0575/1906] boards: arm: add BeagleConnect Freedom Add support for BeagleConnect Freedom, a TI CC1352P7 based development board with enclosure and antenna featuring BLE and SubGHz wireless, 2x mikroBUS sockets, external flash, light, temperature/humidity sensors, USB-to-UART bridge, buzzer and battery charger. See https://beagleconnect.org for details. Previous closed pull requests: * https://github.com/zephyrproject-rtos/zephyr/pull/38718 * https://github.com/zephyrproject-rtos/zephyr/pull/36703 Cc: Chris Friedt Signed-off-by: Jason Kridner Signed-off-by: Vaishnav Achath Signed-off-by: Erik Larson Signed-off-by: Yadnik Bendale Signed-off-by: Baozhu Zuo --- boards/arm/beagle_bcf/CMakeLists.txt | 8 + boards/arm/beagle_bcf/Kconfig.board | 21 ++ boards/arm/beagle_bcf/Kconfig.defconfig | 12 + .../beagleconnect_freedom-pinctrl.dtsi | 94 ++++++++ .../arm/beagle_bcf/beagleconnect_freedom.dts | 214 ++++++++++++++++++ .../arm/beagle_bcf/beagleconnect_freedom.yaml | 15 ++ .../beagleconnect_freedom_defconfig | 19 ++ boards/arm/beagle_bcf/board.cmake | 9 + boards/arm/beagle_bcf/board_antenna.c | 117 ++++++++++ .../doc/img/beagleconnect_freedom.webp | Bin 0 -> 18066 bytes .../beagleconnect_freedom_back_annotated.webp | Bin 0 -> 65866 bytes ...beagleconnect_freedom_front_annotated.webp | Bin 0 -> 81452 bytes boards/arm/beagle_bcf/doc/index.rst | 142 ++++++++++++ west.yml | 2 +- 14 files changed, 652 insertions(+), 1 deletion(-) create mode 100644 boards/arm/beagle_bcf/CMakeLists.txt create mode 100644 boards/arm/beagle_bcf/Kconfig.board create mode 100644 boards/arm/beagle_bcf/Kconfig.defconfig create mode 100644 boards/arm/beagle_bcf/beagleconnect_freedom-pinctrl.dtsi create mode 100644 boards/arm/beagle_bcf/beagleconnect_freedom.dts create mode 100644 boards/arm/beagle_bcf/beagleconnect_freedom.yaml create mode 100644 boards/arm/beagle_bcf/beagleconnect_freedom_defconfig create mode 100644 boards/arm/beagle_bcf/board.cmake create mode 100644 boards/arm/beagle_bcf/board_antenna.c create mode 100644 boards/arm/beagle_bcf/doc/img/beagleconnect_freedom.webp create mode 100644 boards/arm/beagle_bcf/doc/img/beagleconnect_freedom_back_annotated.webp create mode 100644 boards/arm/beagle_bcf/doc/img/beagleconnect_freedom_front_annotated.webp create mode 100644 boards/arm/beagle_bcf/doc/index.rst diff --git a/boards/arm/beagle_bcf/CMakeLists.txt b/boards/arm/beagle_bcf/CMakeLists.txt new file mode 100644 index 000000000000..165ab5220a8d --- /dev/null +++ b/boards/arm/beagle_bcf/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() +zephyr_library_sources( + board_antenna.c + ) + +zephyr_library_compile_definitions("DeviceFamily_CC13X2X7") diff --git a/boards/arm/beagle_bcf/Kconfig.board b/boards/arm/beagle_bcf/Kconfig.board new file mode 100644 index 000000000000..f56ad623fa41 --- /dev/null +++ b/boards/arm/beagle_bcf/Kconfig.board @@ -0,0 +1,21 @@ +# BeagleConnect Freedom board configuration + +# Copyright (c) 2020 Erik Larson +# Copyright (c) 2021 Jason Kridner, BeagleBoard.org Foundation +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_BEAGLECONNECT_FREEDOM + bool "BeagleConnect Freedom" + depends on SOC_CC1352P7 + +if BOARD_BEAGLECONNECT_FREEDOM + +config BOARD_ANTENNA_INIT_PRIO + int "Board antenna switch initialization priority" + default 70 + help + Set the priority for board init, must be greater than + KERNEL_INIT_PRIORITY_DEVICE but smaller than + IEEE802154_CC13XX_CC26XX_SUB_GHZ_INIT_PRIO. + +endif # BOARD_BEAGLECONNECT_FREEDOM diff --git a/boards/arm/beagle_bcf/Kconfig.defconfig b/boards/arm/beagle_bcf/Kconfig.defconfig new file mode 100644 index 000000000000..6dcf6a6824d1 --- /dev/null +++ b/boards/arm/beagle_bcf/Kconfig.defconfig @@ -0,0 +1,12 @@ +# BeagleConnect Freedom board configuration + +# Copyright (c) 2020 Erik Larson +# Copyright (c) 2020 Jason Kridner, BeagleBoard.org Foundation +# SPDX-License-Identifier: Apache-2.0 + +if BOARD_BEAGLECONNECT_FREEDOM + +config BOARD + default "beagleconnect_freedom" + +endif # BOARD_BEAGLECONNECT_FREEDOM diff --git a/boards/arm/beagle_bcf/beagleconnect_freedom-pinctrl.dtsi b/boards/arm/beagle_bcf/beagleconnect_freedom-pinctrl.dtsi new file mode 100644 index 000000000000..201de3fc4b02 --- /dev/null +++ b/boards/arm/beagle_bcf/beagleconnect_freedom-pinctrl.dtsi @@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2022 Vaishnav Achath + * + */ + +#include + +&pinctrl { + /* UART0 */ + uart0_tx_default: uart0_tx_default { + pinmux = <13 IOC_PORT_MCU_UART0_TX>; + bias-disable; + }; + uart0_rx_default: uart0_rx_default { + pinmux = <12 IOC_PORT_MCU_UART0_RX>; + bias-disable; + input-enable; + }; + + /* UART1 */ + uart1_tx_default: uart1_tx_default { + pinmux = <22 IOC_PORT_MCU_UART1_TX>; + bias-disable; + }; + uart1_rx_default: uart1_rx_default { + pinmux = <21 IOC_PORT_MCU_UART1_RX>; + bias-disable; + input-enable; + }; + + /* I2C0 */ + i2c0_scl_default: i2c0_scl_default { + pinmux = <25 IOC_PORT_MCU_I2C_MSSCL>; + bias-pull-up; + drive-open-drain; + input-enable; + }; + i2c0_sda_default: i2c0_sda_default { + pinmux = <26 IOC_PORT_MCU_I2C_MSSDA>; + bias-pull-up; + drive-open-drain; + input-enable; + }; + i2c0_scl_sleep: i2c0_scl_sleep { + pinmux = <25 IOC_PORT_GPIO>; + bias-disable; + }; + i2c0_sda_sleep: i2c0_sda_sleep { + pinmux = <26 IOC_PORT_GPIO>; + bias-disable; + }; + + /* SPI0 */ + spi0_sck_default: spi0_sck_default { + pinmux = <10 IOC_PORT_MCU_SSI0_CLK>; + bias-disable; + }; + spi0_mosi_default: spi0_mosi_default { + pinmux = <9 IOC_PORT_MCU_SSI0_TX>; + bias-disable; + }; + spi0_miso_default: spi0_miso_default { + pinmux = <11 IOC_PORT_MCU_SSI0_RX>; + bias-disable; + input-enable; + }; + spi0_cs0_default: spi0_cs0_default { + pinmux = <8 IOC_PORT_GPIO>; + bias-disable; + }; + spi0_cs1_default: spi0_cs1_default { + pinmux = <28 IOC_PORT_GPIO>; + bias-disable; + }; + spi0_cs2_default: spi0_cs2_default { + pinmux = <27 IOC_PORT_GPIO>; + bias-disable; + }; + + /* On-board antenna pinmux states */ + board_ant_tx_pa_off: board_ant_tx_pa_off { + pinmux = <29 IOC_PORT_GPIO>; + }; + board_ant_tx_pa_on: board_ant_tx_pa_on { + pinmux = <29 IOC_PORT_RFC_GPO3>; + }; + board_ant_subg_off: board_ant_subg_off { + pinmux = <30 IOC_PORT_GPIO>; + }; + board_ant_subg_on: board_ant_subg_on { + pinmux = <30 IOC_PORT_RFC_GPO0>; + }; +}; diff --git a/boards/arm/beagle_bcf/beagleconnect_freedom.dts b/boards/arm/beagle_bcf/beagleconnect_freedom.dts new file mode 100644 index 000000000000..154928bc8c79 --- /dev/null +++ b/boards/arm/beagle_bcf/beagleconnect_freedom.dts @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2020 Erik Larson + * Copyright (c) 2020-2022 Jason Kridner, BeagleBoard.org Foundation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; + +#include +#include "beagleconnect_freedom-pinctrl.dtsi" + +#define BTN_GPIO_FLAGS (GPIO_ACTIVE_LOW | GPIO_PULL_UP) + +/ { + model = "BeagleConnect Freedom"; + compatible = "beagle,beagleconnect-freedom"; + + aliases { + led0 = &led0; + sw0 = &button0; + mcuboot-button0 = &button0; + sensor0 = &light; + sensor1 = &humidity; + spi-flash0 = &spi_flash0; + }; + + chosen { + zephyr,sram = &sram0; + zephyr,console = &uart0; + zephyr,shell-uart = &uart0; + zephyr,flash = &flash0; + zephyr,ieee802154 = &ieee802154g; + zephyr,code-partition = &slot0_partition; + }; + + gpio_keys { + compatible = "gpio-keys"; + button0: button_0 { + gpios = <&gpio0 15 GPIO_ACTIVE_LOW>; + }; + }; + + leds: leds { + compatible = "gpio-leds"; + led0: led_0 { + gpios = <&gpio0 18 GPIO_ACTIVE_HIGH>; // 2.4GHz TX/RX + }; + + /* U.FL connector switch */ + rf_sw: rf_sw { + gpios = + <&gpio0 29 GPIO_ACTIVE_HIGH>, // SubG TX +20dB + <&gpio0 30 GPIO_ACTIVE_HIGH>; // SubG TX/RX 0dB + }; + }; + + sens_i2c: sensor-switch { + status = "okay"; + compatible = "ti,ts5a2066"; + #address-cells = <1>; + #size-cells = <0>; + controller = <&i2c0>; + gpios = <&gpio0 14 GPIO_ACTIVE_HIGH>; + + light: opt3001-light@44 { + status = "okay"; + compatible = "ti,opt3001"; + reg = <0x44>; + }; + + humidity: hdc2010-humidity@41 { + status = "okay"; + compatible = "ti,hdc2010"; + reg = <0x41>; + }; + }; + + power-states { + idle: idle { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + min-residency-us = <1000>; + }; + + standby: standby { + compatible = "zephyr,power-state"; + power-state-name = "standby"; + min-residency-us = <5000>; + exit-latency-us = <240>; + }; + }; +}; + +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + /* Allocate 128 KiB for mcuboot */ + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x00020000>; + }; + + /* Allocate 568 KiB for application (avoid touching CCFG) */ + slot0_partition: partition@20000 { + label = "image-0"; + reg = <0x00020000 0x0008e000>; + }; + }; +}; + +&cpu0 { + clock-frequency = <48000000>; + cpu-power-states = <&idle &standby>; +}; + +&trng { + status = "okay"; +}; + +&gpio0 { + status = "okay"; +}; + +/* Side away from battery connector (with MSP430) */ +&uart0 { + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&uart0_rx_default &uart0_tx_default>; + pinctrl-names = "default"; +}; + +/* Side with battery connector (with CC1352 and not MSP430) */ +&uart1 { + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&uart1_rx_default &uart1_tx_default>; + pinctrl-names = "default"; +}; + +&i2c0 { + status = "okay"; + clock-frequency = ; + pinctrl-0 = <&i2c0_scl_default &i2c0_sda_default>; + pinctrl-1 = <&i2c0_scl_sleep &i2c0_sda_sleep>; + pinctrl-names = "default", "sleep"; + + mcu: msp430-usbbridge@4 { + compatible = "beagle,usbbridge"; + reg = <0x4>; + }; +}; + +&spi0 { + status = "okay"; + pinctrl-0 = <&spi0_sck_default &spi0_mosi_default + &spi0_miso_default &spi0_cs0_default + &spi0_cs1_default &spi0_cs2_default>; + pinctrl-names = "default"; + cs-gpios = <&gpio0 8 GPIO_ACTIVE_LOW>, // SPI flash + <&gpio0 28 GPIO_ACTIVE_LOW>, // mikroBUS port 1 + <&gpio0 27 GPIO_ACTIVE_LOW>; // mikroBUS port 2 + + spi_flash0: gd25q16c@0 { + compatible = "jedec,spi-nor"; + reg = <0>; + spi-max-frequency = <2000000>; + size = <0x200000>; + //has-be32k; + has-dpd; + t-enter-dpd = <20000>; + t-exit-dpd = <100000>; + jedec-id = [c8 40 15]; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + /* Allocate 568 KiB for application */ + slot1_partition: partition@0 { + label = "image-1"; + reg = <0x00000000 0x0008e000>; + }; + + /* Allocate 128 KiB scratch for image swap */ + scratch_partition: partition@8e000 { + label = "image-scratch"; + reg = <0x0008e000 0x00020000>; + }; + + /* Allocate 1 MiB storage partition */ + storage_partition: partition@ae000 { + label = "storage"; + reg = <0x000ae000 DT_SIZE_K(1024)>; + }; + }; + }; +}; + +&rtc { + status = "okay"; +}; + +&ieee802154 { + status = "okay"; +}; + +&ieee802154g { + status = "okay"; +}; diff --git a/boards/arm/beagle_bcf/beagleconnect_freedom.yaml b/boards/arm/beagle_bcf/beagleconnect_freedom.yaml new file mode 100644 index 000000000000..d85ea8bd355f --- /dev/null +++ b/boards/arm/beagle_bcf/beagleconnect_freedom.yaml @@ -0,0 +1,15 @@ +identifier: beagleconnect_freedom +name: BeagleConnect Freedom +type: mcu +arch: arm +ram: 144 +flash: 704 +toolchain: + - zephyr + - gnuarmemb + - xtools +supported: + - gpio + - i2c + - spi + - uart diff --git a/boards/arm/beagle_bcf/beagleconnect_freedom_defconfig b/boards/arm/beagle_bcf/beagleconnect_freedom_defconfig new file mode 100644 index 000000000000..dce21b525e6d --- /dev/null +++ b/boards/arm/beagle_bcf/beagleconnect_freedom_defconfig @@ -0,0 +1,19 @@ +# +# Copyright (c) 2020 Erik Larson +# Copyright (c) 2020 Jason Kridner, BeagleBoard.org Foundation +# +# SPDX-License-Identifier: Apache-2.0 +# + +CONFIG_SOC_SERIES_CC13X2X7_CC26X2X7=y +CONFIG_SOC_CC1352P7=y +CONFIG_BOARD_BEAGLECONNECT_FREEDOM=y +CONFIG_BUILD_OUTPUT_HEX=y +# custom callback for the antenna switch +CONFIG_CC13X2_CC26X2_HAS_CUSTOM_RF_HWATTRS=y +CONFIG_CC13X2_CC26X2_BOOTLOADER_ENABLE=y +CONFIG_CC13X2_CC26X2_BOOTLOADER_BACKDOOR_ENABLE=y +CONFIG_CC13X2_CC26X2_BOOTLOADER_BACKDOOR_PIN=15 +# Enable MPU and hardware stack protection +CONFIG_ARM_MPU=y +CONFIG_HW_STACK_PROTECTION=y diff --git a/boards/arm/beagle_bcf/board.cmake b/boards/arm/beagle_bcf/board.cmake new file mode 100644 index 000000000000..84d7457e7b1b --- /dev/null +++ b/boards/arm/beagle_bcf/board.cmake @@ -0,0 +1,9 @@ +# Copyright (c) 2020 Erik Larson +# Copyright (c) 2022 Jason Kridner, BeagleBoard.org Foundation +# +# SPDX-License-Identifier: Apache-2.0 + +# Download cc2538-bsl.py from https://git.beagleboard.org/beagleconnect/zephyr/cc2538-bsl/-/tags/2.1-bcf + +board_set_flasher_ifnset(misc-flasher) +board_finalize_runner_args(misc-flasher $ENV{ZEPHYR_BASE}/boards/arm/beagle_bcf/cc2538-bsl.py -w) diff --git a/boards/arm/beagle_bcf/board_antenna.c b/boards/arm/beagle_bcf/board_antenna.c new file mode 100644 index 000000000000..005aad042b5b --- /dev/null +++ b/boards/arm/beagle_bcf/board_antenna.c @@ -0,0 +1,117 @@ +/* SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2021 Florin Stancu + * Copyright (c) 2021 Jason Kridner, BeagleBoard.org Foundation + * + */ + +/* + * Implements the RF driver callback to configure the on-board antenna + * switch. + */ + +#include +#include +#include + +#include +#include +#include +#include + +/* DIOs for RF antenna paths */ +#define BOARD_RF_HIGH_PA 29 /* TODO: pull from DT */ +#define BOARD_RF_SUB1GHZ 30 /* TODO: pull from DT */ + +static void board_cc13xx_rf_callback(RF_Handle client, RF_GlobalEvent events, + void *arg); + + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = INT_PRI_LEVEL7, + .swiPriority = 0, + .xoscHfAlwaysNeeded = true, + /* RF driver callback for custom antenna switching */ + .globalCallback = board_cc13xx_rf_callback, + /* Subscribe to events */ + .globalEventMask = (RF_GlobalEventRadioSetup | + RF_GlobalEventRadioPowerDown), +}; + +/** + * Antenna switch GPIO init routine. + */ +static int board_antenna_init(const struct device *dev) +{ + ARG_UNUSED(dev); + + /* set all paths to low */ + IOCPinTypeGpioOutput(BOARD_RF_HIGH_PA); + GPIO_setOutputEnableDio(BOARD_RF_HIGH_PA, GPIO_OUTPUT_DISABLE); + IOCPinTypeGpioOutput(BOARD_RF_SUB1GHZ); + GPIO_setOutputEnableDio(BOARD_RF_SUB1GHZ, GPIO_OUTPUT_DISABLE); + return 0; +} + +SYS_INIT(board_antenna_init, POST_KERNEL, CONFIG_BOARD_ANTENNA_INIT_PRIO); + +void board_cc13xx_rf_callback(RF_Handle client, RF_GlobalEvent events, void *arg) +{ + bool sub1GHz = false; + uint8_t loDivider = 0; + + /* Switch off all paths first. Needs to be done anyway in every sub-case below. */ + GPIO_setOutputEnableDio(BOARD_RF_HIGH_PA, GPIO_OUTPUT_DISABLE); + GPIO_setOutputEnableDio(BOARD_RF_SUB1GHZ, GPIO_OUTPUT_DISABLE); + + if (events & RF_GlobalEventRadioSetup) { + /* Decode the current PA configuration. */ + RF_TxPowerTable_PAType paType = (RF_TxPowerTable_PAType) + RF_getTxPower(client).paType; + /* Decode the generic argument as a setup command. */ + RF_RadioSetup *setupCommand = (RF_RadioSetup *)arg; + + switch (setupCommand->common.commandNo) { + case (CMD_RADIO_SETUP): + case (CMD_BLE5_RADIO_SETUP): + loDivider = RF_LODIVIDER_MASK & setupCommand->common.loDivider; + /* Sub-1GHz front-end. */ + if (loDivider != 0) + sub1GHz = true; + break; + case (CMD_PROP_RADIO_DIV_SETUP): + loDivider = RF_LODIVIDER_MASK & setupCommand->prop_div.loDivider; + /* Sub-1GHz front-end. */ + if (loDivider != 0) + sub1GHz = true; + break; + default: + break; + } + + /* Sub-1 GHz */ + if (paType == RF_TxPowerTable_HighPA) { + /* PA enable --> HIGH PA */ + /* LNA enable --> Sub-1 GHz */ + /* Note: RFC_GPO3 is a work-around because the RFC_GPO1 */ + /* is sometimes not de-asserted on CC1352 Rev A. */ + IOCPortConfigureSet(BOARD_RF_HIGH_PA, + IOC_PORT_RFC_GPO3, IOC_IOMODE_NORMAL); + IOCPortConfigureSet(BOARD_RF_SUB1GHZ, + IOC_PORT_RFC_GPO0, IOC_IOMODE_NORMAL); + } else { + /* RF core active --> Sub-1 GHz */ + IOCPortConfigureSet(BOARD_RF_HIGH_PA, + IOC_PORT_GPIO, IOC_IOMODE_NORMAL); + IOCPortConfigureSet(BOARD_RF_SUB1GHZ, + IOC_PORT_GPIO, IOC_IOMODE_NORMAL); + GPIO_setOutputEnableDio(BOARD_RF_SUB1GHZ, GPIO_OUTPUT_ENABLE); + } + } else { + /* Reset the IO multiplexer to GPIO functionality */ + IOCPortConfigureSet(BOARD_RF_HIGH_PA, + IOC_PORT_GPIO, IOC_IOMODE_NORMAL); + IOCPortConfigureSet(BOARD_RF_SUB1GHZ, + IOC_PORT_GPIO, IOC_IOMODE_NORMAL); + } +} diff --git a/boards/arm/beagle_bcf/doc/img/beagleconnect_freedom.webp b/boards/arm/beagle_bcf/doc/img/beagleconnect_freedom.webp new file mode 100644 index 0000000000000000000000000000000000000000..cd3e3f667737b860e2cf3b361bf6c21c4efe2895 GIT binary patch literal 18066 zcmZU)19T?A)-D|LjcsFMJCnR|GO=xEVw)4&n%K5&+qP}zpYz@Su6ypfwW@nn@3pJy z*-!1R?ylaYC@CfuE(QXkCMqPaD$k`32Lb|u{O=$K2Z;d%0ZPkDuw#ILfa0**tc%se zO@4icBs^RZ&VIwr5Ss=L)Hs^>3-1Sns|(ibfJu%=I*WWFF`9P<?O}2kpzpLU<(SBW@hb+j-*@`C+M+UpqWPJv zbBM-YbX;S_rKv3PcTTv``4|4G;xqjOO{06IQ^I8ZpH$CQ1I{lqD2a00IW+O)A77?r zBsu``(%*C$Sz!JCv@flwa(Pu7b>3vX{y$mg-69DN}Dia@$ z2RWz-Q$?Hs6;0oh8fZaGhmK3jtBDk^Oa}>J#Y96c7Z5 z0*qntP-%pN!1aJ*R#}M6D0;YZuH-r>voRF+SLJ))l7bDP7^lb(WaN7nU`SaL#@K(@q-&AK*QyJg% z)?#;fPz@2YaN`*}yktU1OfT(_+@h8y4MFIk8QdYjIU~Ww+gbr!DZ;J88l`HiM?e=U z16vnVutM^%ZSe~eK;s@kFgQZPzXm*C3yN3gB^eCd)=r#B8T1{J-! zOl@0y-TQc08Whc9Wx0>iT$EWGYGK#xJ`1Rb_y8V3C7Qe>S^!k_6qP2(IGNj25x1G7c@uo}JX027>A3`}XV1zuLd&Jvv9{FaX438!@H)?Y{OOvW?zu_VKdN zAys19Xhkgz$2MtS?{wC-^lIO%%QS^c)hvpHb1hC9&OeEkzFjuoe50d6>&!P2-$69ei2w;9eqDu#U3>LD8dPG1gm{C#6aa7at*djTQx2 z-a#Z9Dm4qDunI;Vs){TH0s#|HDsli9n*c(gsOay1M1f4926_cbyn{#zvI@j929ENl z>i>jt$0;9pitvGZsbS1$U_Bqt6~N%k@0jH5ILpu2+2WCV<3(zBz509Z(8T6+@B3Cs zq&fL>&*;V{<#^Hefw9K59{U6g^UigbtIv<` zXqX#65fthB$v$2X_r|lC&?wft|D!k<*`H&F*H_>MI&?qVS7qny4_BryaAz-?>meJD zYmF4~)Detxp|_jurUr5O^nUik?jV_` zKZd_&Atg)6=p|%(pk4N2zLfr9+y57#y}C~B$IJnXkw8m*R?SB+J%jgc^*B%8w(qOl z{@vFzRl-K~=f*{=oaZ|@+4jfa^{ZJ&b4IrhYbzkEm){cyoJB(KEo!IGKP+tGr$w+z zZ8%%}Rk(BB&Y)9CRty19lgWze!5GLc*?@*ft;5b*ci=;egxK1EQy)_HfSDeO?+BbO z!uNg4_S1WNJvYW6$d#0>GmM5);1&ruQ^b+`y1d%{UcC%>{+gJsDn^|ymFd!MaIYVu z8s5BEnnP3+NL~;nk2SdrseK7bL=bs8t1-aN zG9B0x%N%ciBc72uV&===h$r!xri7!Q*QtmeXu=)YS3K_B_{BoxcoSaD@>ThWGsYb<~qfShvaN z`wPldPL`;sfC)C3wqpBT28(rYrO4sq=4kVgC(6+P)uILWJz>j79f;^I;aqWAP9w><#!lTOXv-NXKP>(n83Z$U!)wE5%0#CLNH%=^07waoRZ@%+&u z1E<)(h2uf3p1F z-X_6va^bep(dE(azsto)vd8yPeG{SQ%Dq{?G34$=x3ji<%^G!`Fe_nOvL>l$>#ehW z>6c}Gr9@wVDx7hYPu}(VZf+OkidK-?Z)!QwI$mgP&(Z$%r}}VO%?ghnetf%n``EH` z=^87cL|Gn@R86CI5Bv7ss!qP4VN=E{Nrqh98)|h$T0Ieeq}(Iy`%Ues04JMH%|(txr;+Ta^eXk+aH5b) zUrZQ>$3ZY5T=ROx2F~4O_I*{D95Bky#>}*Ti(1v+SP{AWch`U0L-xLF>{2Hj1(gI6 zrV0##76ji9yp^;>C~rij=foMiK0}IWJP(CTB2u4Fn9UGB>IVtCv%RKfFi)hBa!qXb zp*`+3Vs09aqtMXXYn#^HPRZDMri{|{q`A(v!k)qQB4YzWs{ z;)L!U`V#Ysy~%#CNElXV#EEK>HqVaEAGPW(DaMc2z_l?ySb|<{I2Exn`02M#KI4^R zKf;YUFJDwk1eX-}=K)4M9=j(o0FsnKSV|rPZiIy?NLgBp7SX+?X@>L^F;`iYMaU#e zM^KprrWIU1HlL?q#hSqH=6h$_P0%DW12MKJ9gZdOECH-AkP*E?7{!p7>&P4vBU5>- z5DxBNGR!zaXBX1$)Z2|iveq4O(8o@3 z-G;uL{3#&$d^(_yY5YfDR=>kv7CI_&Xap-RvequPirmBlzCP7hujP=#qyzLu7+7iG zoorv;>kQnq157)_XhhIIxwbx7vhYgQ5jhh@YX=N~+;{k-qbBiSh!Vx=OoBnO&w==r zttOhPRh9K$)64XIXO85@-s%(*y5tqRi3e?>>U$EhYn518UGK*D*3F1`d^kk?Hlx|G z`7Y9OBZVDW?_{9-vwK}yLj?K-*f{}5Vlzf0Fn?5F6`+Xm`4Czo7!r)5W@b7)j=10Q zg;eRE%YJ`%&Hr%V!<_`<5m$I3$RC#L#xDiHKz z6C#)BA&v(Fs=wTrg}5DT?WLJfI$(v5`p2QgG>Z4B6A8vsW0Q;J<{2|9B17;1kY#KJ z-ka;~AKvO2Ixe#iAC*zuF6)1OEs~LeKrNC#$!&IBeHc}>SZ|;WS0%VzY6(ET+qv#L zV`aH+ZDz3-Y}SQNzoTDFCZt^Z-dtv}j%l!TzmEI56MmfHYzQjaG!3qe3>UOn~VVSoq$*H zl>px0l?yX!-e?Q+{j6X*`cgxD*IyR4fmbI?gC6Zh(VzU?F3<`yE)o9kcuiIJBE6en z&)kt)V`y_Wvo*_lp71gU4O;rE=akU|MzD;$rYqOBd?6G<8}zu(yxLyyk~1z9b6K1| zD-hxb_QSdZUA|AH_;GKWLY>c1K4y5LiFHP5J>7q0P#Vg&WV+8-L{43Qf30mTf37{E zGZU(|!nS{|qTvfmXW=asX&E;o#bgg7uUyaNJarqMUu~C#$PXY~|I9_3ILh{!f8XpT zjGlqleK#T+!nyX{HRBL;{jQP11~Z>_HMm%G)kVAr^)vCtul;a`aeRVa1{)#OU-XK` zK1G0tAVSO$01FnQ?&Igd=0xjRf|1Ao%)V#Ekmu_6j^Ts?Qfg71CB8t+<5&5f<$0n;~GX;n;D1hAJlaiJcMqFAU!3T=!IJ`k@thyT&d7og z=ATE4?fT!-(l8Kb%#&3yAk(Nb3`L2`A*zO0Ti-yecx4a4FXw@DTpjZWIE zrfXQvm&p*Dzsba41T79va@nCeoezI|g3WZ9E4L!Ak_C{H7EtH6=A!++f@nQ(7e{dC zY1zSWqiJbq=Og+y97T&Of`1iLF*9j83>p{X?&amnSG9cBnJMpWi2?DnTOa-Oid1IM z^XC0T1b>x~x^G#bDc4>@H-9_^oet=C=ZE8D`{L82@gpJ$Yhy}b{AFGs8LlpuCB)G! z6>49+jf>+dS~=&ItC%{AQ|Lwu^Dq1q+1+|aQGTW${`!6W*Bk)g49znmDf`G}+~0J9 zlt(ULOYc&q$7-f=PRaIJ%cK0fJfq1uV7e=5gcmn`dYy9}lMyZac~TyW58+R>h0Ew8 z8vHGTCt2=qiB@9gd;s;_G~5frpLz?*7=%&A((foAp>6=3g);}rnJemBb_#;$d08wfhzy!gRUk`4HzGBc`A?n1( z+_UQMhYjhnl7S39fC%Lg2GkFMKV}JB0Vbmgr#+|odl;_N+7uE{Grx40Ky94-C7@hk%FtKwXs1S2Av2zL1 z2e5>WX9}zbKTZW+5MNS2*}E{+Bx38sNCx5zATFQT7h-)eW{6=xa0vygu}dslS}(FnTJJh2A1k>_?8ARh znbQlQn#%J^X#NLsgr-Q`GHLp_B?^mjgr8Y(0pV<=_=Zl*$&024sf#>IU>_m@t6L+u z<%PY=P8x|CFLi3}<)oma>5V0nys4cb)LB~Y{v^mk4wJCTKSQPgQ^+N=VK@?F0Nu$R z1!0SS<{^LhLOxFH3;=Q#KzJV(h+T3fh?)9X%z{NGdR$X`k>_(YgT_-y98Gf|Sqo~w zO`uR%?aE6*UAQuEP=#~EY+=U!QEd*(9J6GFSZb2y+K=G$YL4HG?QTOznbmCiKG=VnYesOeJ*a`+5;E22%fBP(X>& z8|GDrx>bs*ld^Nwf=CTE41>xw2kPZ+BGi^~oQMt_g2+KXa5Clf1 zk^EEYTlWvZ{?!OR4UoMMOu~k6IRQrgr}VE%8ggJL!9UXf_0u>)N)kM=+6%#2vIbm6 z38Xj@`lp|>`Zxf>i;qL=4g};n?TAvjFr_hp1Avw&M#N$$ye&~U_!D;Pj}yc$c8AvmyRteDMYl}2g+R*ls z2ofSKC2slC9ya(wWa}W?6Brl6>%w%@^qq$g?R5j|NP6|O{SZiwmD!-yq4O01LC0;k zkYGqJ@Tw0g!}0aB#&y5^b#KFT7~&H@urm3slj=vK_IWxwTX>ErzznI?wIk=aZ~4)I zR(%1g$06|9n&mb(S&W|!PwjX!P9#ZY@zIA?g%4sq^>vh?Rl6VIwNG)py$3nL{ZaJ1 z!_o zMGGp@hCB&ew2lvZNk!db@&wGh;c(C^@)y!kDCx!Q;OG2T=oa2zww{_Rhf$gs|M>{E zI&@M};@P9I;f}qp{>q|t3=LZ8-3@087F;kzv;a)zHRLgO$t=|PCjmbnMF(=bRT+x z`HFrse;0pDx5vD6e}1ocaKF_*P4BS2QN0j0{*36Z&;B00xSPCSk}SR)jDp2mZtnk+ zEh>{GmL_||Z!abwRW@ELNspF=|&WG8M*dGT$6$(G) zAS3*Z$((rFF;&U$28F9v+uoDgSW>6IMh-!z*-kXh*#SLI9m?I~$?6sGuG)`IrR}&c zbxV!6zCrv2x_|oqNZ+?1I-mc#HS{{u-3hIP!6v|V;eYL8^yzSU{ToR8px>RLVei{} zPjVo)XQ@fDpu$qNrj(Wjb%F((hw3UlI+g+p6u4SWbt5y$ro9ITJmk#NtjG_c?1)_h zyC0++)E9X0;fp3O77`EKJUmNU65q;boiB(yW+o1y zozNefUEhJ398RAGBZ5!|Qla_p-(kB&sd-TNKfl4Re`9__L z3S4#}cLK2}X>g`4Y~rKM)t-}{~$8|d@EE0H!o z1%$iv-;AwR3&&wk35=&HQA15L=gBbtS8Mxmsqmg#hpsVS8g)7sb-ufJD2m`8e_GeI z-d7dHpufZvv?JV#tk;$q8&I<9WK&QbWoHu|T+I}Wd%O7`;m#_Gn1MKX>p za3>}%yTg>V2x1b;8B4@_k!AG>2PB4$5Kd_Lq_jO897~i8mg$hoyxy%5TlN1a9j}`^ zkAoHJXt<#GuDpkIZFu(BD!wRb;3rHUWn!GQLyIjZ7+1tdajE0iFNLt<2!QGrL{tT& z;euHC14w@H=^El@CBWU*{Xb+&nW6YPpti#N4nc9k^l?P}@rFvTJeO-kzxU0qZo2ct zf0})y>|-H|aA8Q4Ey!zX!!B3a@Wh_R6wM7CxqDtKi!^DORq>C}&;rui+KM+Ca#$&Mylx2rgm zG_Qyt!s0%PLupO@^^gnOMq?SSaG8`e+ob$U^p+zzm6lhRrG24}+ zfj6~Ns1Xn}*+18XtJF!9U!T?p9GZK9rI>xr?mJGC?-jiRotJ`k5Y zE&AiFxygJ45toWFNCu3xnxto_{}$$A<fX5RIlFxj8SxZ zntd10h{K;C+rP4*>$VcgSMZ{;s28=;O)5&%dCx}qBy4}_K93JnRQ$(@V?{l|HoxVi z187$;uU|XcXN3lB9OU*Rd*%4pKRhyO{YU?p3eb7JmLj>r1CsMi{!9CR^_EJ+v|(4$ z=rDTuEjHl7_awBGKqdfUW zm{zgrrV%rzgw+<8O>eA@?s*ZL5V?6x3OpZ+wwPC~li-oY3TaA@kX%n>?y0FA{*ysa z^$wFFj&$Pv-d6^}&b-J&pOfC)n#lP85+FHZWG<1HTmhp&fEPeH9PxX!!)-0Qh48mV z?Ejt$8h_4vF*WPlha><=)KpkB9foT9?|lARyZ}&+|Cz@l_r%Fk6;0N_dI-UrP zxA?5(Hjp^zMxdw1qO@WEV{;Sm+I_gG;FCW6y}1Tdjoz(gK-|mz{#Kgw%{41g(0mRl zXslHB&FVAF+VPqAn`Dka4AnM5a80$KImAm7YOax@gLiL+BdL^rck`kKa5$9%l zQvuitgvJxl`Q@bi*OsV!4g%i5hH@JZ%T($0Adogsfl!@(d5nA|;2e?3J7!TF=Klct z{|6!Q`eo)`);B*4K0FVP1^ud$o7atddrXy%fi|c-b)LmlR~yApTL1qVF#$Wim3m?# zZq}Jt=S^d)k$b@x2Q;^YIUQ#cR0g-IEfz`Viticr)Q*2(t?+Mml zJF|vE#sYPRS%1paS#LZeIM5!ZSfnKw2?vu=;pR|K>M24+5e?C*;3`X4^5kvRIHLYA zS_y2&KXhX7wB|&GC+oXb-eYt_0fdRE#cjRnd^JeY1D;_91$MC5Mj3b_qJV*vw;s4l)+UgIXxai>yO zRsW@gW)Bv$-Yps_p|-V+g>4OZ;!@j%9UMp9fJPsF@hXi*U##Uk= z%HW6|81f3c9O%Kv+ee_pXD>VaS3eD`;q|8}ji#liok{v>oJyU3$9&iNCiz6p(Se_1 z;pyCzUvp&ZhnZ={MJKcnw; zkov?vdD$bScBT}T`ey@X#+;~-VFe0Ah1f)}RK!O{M)s`=m3s&-IrEkUZ1=yk@-${> zx*}!9H9;7%&Cf`F*`w?;sWQ6sGf{hEV{rOe>X^LzdYHpH?=sOy_+36wLth|2HSzB6 z*f$J`-u9%k>eyN6pcm9PHH!NG@-=e?ZCwgMPqlvFK`rcVSoch$%6Mxtw#TY;n-AJ1y-# zUGr3IU;<8E^OG}9{junW4(~x2n&fhm8Ql|JxQgr!!%A!H!&5;D&IrCLMVQ<-7T7A` zuz_}P2VZw)ZAAM`EFXV6^BGWm>+ctZ0qNE=_m~Z3*3L88p4yO$SpEh<$d=laxn%9r zuqSpRVa8I78GN9U-`0~!EsySBPT|3tJ2>S$055zmw{;#t)Xh)%ghr1QE+u53X1a4R zf~J_a`AM|?KF=BeOjanJxT&Z77An{AMV&1m12`PXzU%pi8bfgpBsgZ+4E#|Ec(>uh zA>sV0l+OM$5PG#rU`ilX_@YVWSUDxJZ4;!}Nuw=%h?$L3bz6VUkPWWNW(rsw^&O{u zj2%?TMfsW-`kqU=QvrDKPkmS++CLz%n%u+n4cRNLOIu%IwnwCkl1ExP=bB4`c0dI; zP~j#|xj#kJ1?D~mwfBCKz23+@c<0wY?gpvIbkfsR;n-?~?u)n@=o?Rl7aBlXbiRMC zA1%W1*}qI`{_aB>w@pq=){dck^o)9u>k*>1O4UVgpD(PR?yglQC3p~yb71%6*}HKm z#bAw2%6)1wx)THM3hl){W!9l~F&O zvY!W{)9U=gg={sqtWBdCstr3VJx8F=bGLcts4#SLXR%3aUV4d-qkF)Q(ykH+p)*W< zG}jy&p_)U|bbMaS$q549fzI)w^JsUq1@(I1L}56O zl;gJ7oDNsNoZ_F)+j|FdT=6hZf&h8fu=eD!I_G4cAw4+fFD!&GCtN^x|FwdxeL;z`ODNh|Mn0T#eiYaX(R*&R z!4}xKeA;|cy=t?$c?k|ZDO5s-GT-mV0N<}=yzhU1WuvQH{{>6&ej8L}&u*(DyWfNq za%(V<3}Q&88JN1-BU5{4%iSfWKMGk#P~SEz>N|NRhf#zeXL>Rb7jKU=UqHXuOewpA zm27+y)vj;)#io=>XmJ7jD&7#phUJ-POtSccfn=qk{ZAbbSD_il<1fn}uk>%D7>ypZ zcKh68C!mMB(I3RZ7#07AkWfn1^qIO%o~r<%V_4WIEB+G?2Eq#mnPAZxDS1aBNX5va z0Rw?5#1g^O0v%o5>#WWS*;L-9BuNausp3o-Esw@9r^#-OS%7v93S)-*V}UwC(ZUy{ zp*N`Q#s?sfR;tzFek0k+-tN(e1+vz{XOTV7pKj7a9@I+{@adx^3#@ zj_1e8yHOuvFcI-odPt5B)5kxWpg<0e?!@kC+!-=F{B$TL!vlYl$iLDbO~S0Go@^h8 zA_j0X5j^(#87kUhDH&24`oPCX9R_&4A0fjG;psRy`ufwW#LQurl)8Gy*bOsDG!wd3 z9r*Ida~ua~hxzv9n=$yOx&?ne{5c znEU5?Y@#*7UyQ#MQb55YonI%kYSY6`r!ip@kL(&-jhwhteCkH5cXr_36c`3_FHIm9 zg~*p+7#KzpkUz*d5EO^vpW!Dw2B~BSiPjajg+$!uhfkEh;p$%tsG37RNlf zAO&1vSXWz}0up>6MAZ)gLxMVY)vzE9bU(d(u`5};sRDg>T4v9VmGIq@iOO7%>Gyf~m==(7?)RYsI_9OqXCjPkcFbzF~s!!fGDFkg*K40CSHt(iHJI| zi3CGbbae-41|@uPwT1Zf15rE;Ry%`jkvouaWH>pMyO#33i9yg3tJj6^!Uz)Tnku2I ztqODSCn-=2WMb;`acDj8AbBs8jEas7>FBzzStiC1EdIrwEDfvFkV87O2$JbTDuLa; zj`eUX&6?=aqgeeJ;?1UROl2f!sEa+IKo+W$NvUMr`j9L}P;nc6*_#OYJA4o}a zYZMK`TIEI91yDne9t6#bl|^p zD;vfw>sQYni&ow5vQ@-ktSyRaWII3Q=AEf%T47UK2;7zEK(JZwLYs<1G_1Rg`92w5 zGA^=k`>k!cokwlaf3awrkPyq$NVMT_pjH3wB*pa~W$x=qWL)0rNnRICLJj4x^Xyj? z=Yx0*>XA$Evn1n>OQx>?G<4kTkoE}*$P%sM}cdS~W%< zW8W8Okj%nZh};~Cy$g+0A8>$&AxW&@%mOEKt7LKnE*vI0oa_Zl;y_xuRoYNisOh=^ zjA3(bgVW@G|882qV}?{Bm0tLDR+%c}c;`y}qo%-xA}6S2QuCp0y;&xfrsseORfCEU zUi~Vl=HZJwt#cxUKW+5t@SFl1gB(j#@s)#hu^g9INiJtn`fGdOB0tj|#v4U6zt!-q zc$Sq`wYfNv(u@@o>nzl^`^A$?$J$V+jFmz7*=*C|!GYofG3~vAQ7nVOBY@ZT@#tV4 zc6Gj;ryMpIza9TD4{BEPz%UpgHlpWvRQqhE>Pd+$d-v@$Se{u(z|8Cc$!4oi%drMh|1kCM3yf2jY@{j`uYReh%L3W|gF*Pw5L2DSGY! zew>L;PFzk4{S!-}KUq@ul}=Dq$B?uBeMU1LgQZ<-M|ls02}79v4ZE}D0pv#%UX#8- z4&BGPkv?@rJnf~ni`pY3oNB9sfoLBv7tk3b$fmj zS)HCBaQFkM=8q3v*A3fzgp%VEBRs_|;e5oeLSdRjlJBry$7NfL8!R=>7JG_2k46Zb zY7RnEhL3ORh@b5Di`V7-jiS2pe``8ZV`bw-g)(pm`}66X8`<_zG!c*5dBy9;yYvfC zpFD4@>&S9u`0kkIPrMR;QJO?s4dubvVG3XV^I~ z3OfB|o2C+oXi^uTYD*jFa}+b!PWPt5jFciLrUVN-vT&-E5!yqJzFA)x(-Hm`$`3by ze!!3>@LwlivZts2!HmIN7k zHGZ~K+)eGNSHoJM#q6|JJ<1R2(qCfKIG(ObEnxdb3;0lvSszkt9wrG3zhU< zn^g$5ovO9c4Gf#@{?S%3o3mJ%9(U8o+srZB7GmQLsEk|~zt%-it9LXqNc$vpB5yLE zm8J|GAZn@-GI-MB5NejuVou>y8xq0ulnGeAA@Culo{E4nvtVXtdQbWjz)Lb7^mFpH zr*yLlu#~Gx`bv7uVL*AVy-15^u|8NE!M=~XMa1x<57qAklxAMh&g{Dpqxa7(!B5^H zRv))Q%ZBfhs*$oAjV3ErjD%^rccMcM9iK(gdw-(D;i&1m`nmSsLHQ_L^Y|2}L(bx+ z3Jc@ZT1v|9FIW|GNo0b&c#!$hsG)=ELXDp_63O@Hnl1{si9%b`60?kP$!CS-OLvF{ zyfsp+{qFH-XKQ3G=D}PM9*QSGGZ657s%LS-X6&XDzY#6e+F#LWniaWD33@J@5>yj_ zGre|sf`6~JkY8A}!#6>eNd$gUV^_K_ zOQCUpqw2V~&`GKxjE5aRuJl-_&rnK_ulH^_hiqTJv$9LKVL;sc(h=K$6*p6k>7QTD z{%G2UzxlFtibA$~C^=XWfBZ>OHlc!~;-r83+hr2ma420bE>taHFRvx#*w6Xf6>w9d z-3vI6lvXFtlHoGg`w8Gl{(hPmde)ntqiDYbxpM~OzmCHehY~FZ)&Z1hiwGr#u9v%} zC?W(9>xzh>%S=KA$Y!dCrT2B_;^CZ}VU`zUxC+l2K*oKXE_Quay8L&;kQDN{)#YG( zVWUA3oFL>a7C{1WF&b25KLX>>nh^B+bRG@lC`8$AR)2(ZORiB$v(_G8*9_UQ3j z^Ye%|Nkb`&Zsm2BaFQ_Sb5@j?)|t%WnQv|oRac!VF5i1zN$QQ3+@MQu`}F-s(i&Ux8q zet;U(Q65X2ZQshJvz*vRDGY`CC!p{akHZz-h23mh6$(xyRLZjtBB#4(nSDYn7x89R zq27957KHH^-tCji0{iE*E$QXE^mGzScLr-Bgwwe!KcYdG<2J^T2p}sX029ijzH zg|f%ASe~2I7)6wKrzTILqP^Lb9AJ<>F7z2O2ONG~H-W2*hL_H}9=Jeu%PmoLKZhP< z{EX&l1x&L)Zpu+oQ-a=ZdY)+!h^Fwn53R!}&rI**=LCe>ODI@vXl;ooO=+Y!vnV3{ zazVzNH|x_9c+vf{MaiAqh`PB3OAF)JtB9k)I5?%9LE*UTx&YOu&w<%YB->zbEwir8c?8+s+_ z8M=u<3Tb)%l+AR4>LvuWoVY%$clKU8}I^VtHr6=H}y|s%QSboA!$E z$Euu(m$ur<+6Yf~Sco_uQ+o}x*@0-k_V22*vMF&7--j#KN<0z1qQRe?KSBU(&@ZaA z%S;lCN?0jw(%jvrtf9~w^DMnYX4LXRUH&^se(IRHV=?c}I1C#h> zA%=}fBujVy*pIuxrCN2@EMOir;p{AFa~wH?iU zCqf#hut1Z8q9EvX`{X)aA$UUH@=};ecFpUfzcD0YxyRX>9RXI@g`e31WgDLQ?ZY%l z-ZF#3BuMRw9g+r8Gw9VfbK3tPvuUiR3G(Ga`$t5z1wT>;R0L>}Y9jPmCPDEh9ommVW3u++AV4P=Ek(x3%dB27tWLR##FFLuND+k{dMtN z&_R)YruiXgCf-~Q&G=~(7tJ+Uc|2!2q)yZot?0b-@4MSXz2ZGLO*KG5Wlc}*ztg%^ z`+gT_2bZivmClgzO`%t-=cJw$#bfzfFCP>cYK#ZYQj^<(xsnO!P=ndfzS1en7;1e8 z^n}Xx?(yIjvz#)=ILTGc?^M ze?{HY7}%}Tty)aV=o3_ZSh05$rsyV5gQ=M`z()RPDZN`TZXp}78S|o^VI!fsE4BUV zz!)==PIP-K&@LSNUs*?=fK`?LNN^-AIPA9ImM7TIj;Ogk&> zTvG=LLiysPHn(r{GftxFt5g`GBHux+tRvyUpPK9^q6&k)59fGn9g{<9Zmu=lCx1P3EVd!rV8st_*}%6&cdB zvx>DYObt()^JulZWsW2AwA*--8b4TLf*~ zeTEF{-JBs31-`J@lj{pXu(X35S-Qc5E@)MgXxSrzt;w7+j6Jb(JoW?RjoHg~b{~TT2Reg18HLj(KaraqNUgHAHndfpm=!B{Fj zSYeH8gf>?##`^6Ai#6YlVdDUqF)GSK(3q2MnfrB@GVdiUBpMJ9g(X4FPWmsio2jYSA^vi>cck~~m5o8%{WfldiIHvc68H^vu#Od8Y!?l&iM zTb=G^6moka!Au}fb3tQxxcnu^3g$+dt1sInKTb3F2_Yl-sq2_0g z#&46?vPA<8t-sytt5<9GJ8cAFzZ7du2cnF+(r@xYT~ORuQT+*o{(`g}}4KKJb-1$7MIM@^|$o}32ScdKkr?1VX3 z>ib<8Oi#05!zwafY{A#f8GXY@J)dM_1OR{ZAad{SaaOGu0tB2<4UjoqK_1tuYge%VSfU={j6<6KR>Nwy5s(@TtG zlwE77akuaIE+&rN>i|l_7!R1z@CN4T@5kJoUM!niXIgI&#-DxHr3YwQy;{ZpO-PBY z!ym!=g#UHodTj^Aq^zDFGe84Rt7^!erem`ev^8iwa)3yi^rKyj{Z@HN{+q3Ha%6>g z6`c?IJJ@5-?xt-eDD(GevV-M$huhV=?ZR`P$TXj7_ zES&%k2$1y*QS`ySOmEUSqeEwoILP%H6~GJ!ABybH4i z@E#D5eC`|9FS6#5j-p9i$_|ZxyCxS2uV&=8+d(Pm&ixeE8x_gKLc2MtgWuxTvMo+X zPqf((H;FJNGDX21&&UeNe3v{j0h9T{(tI-fNvJz?Da=QjBixUzeJ26C4_5?rI+Z~( zklwysKAe;)+dqy)T@a+N;A=f3QL3Ld#(Kuy(W?Z%WJ}FO;}JkqM*U|O7ro9(MY|@r z<0ahnA{)lBUm&4NK+nzUKG~fW15{jDP%z2C>*VfYNRM^1^Y25hYv=VE@LS8K$>B^e zi5T!%hbJGjZ;u5suK5t+cXEkLvY52c)3(L%aTojA6Wq{0qZ+%=l!iflWZg1R0dmc zF_pL_0E~<1Zl&X&+n0S<@z4WHnTGRIaF>B5x>psH85rcRpBrW-%uSe^F*ags#Mz0n z6J{xlzc6&oNXcg43Jo1FK=kcXzzU8zr8uv%u}$3JL%MYtSV6UW{Ge=LG=+mi#ww{{ z=WTcsL1@v_IWqHk zp~kGI1dk&K=)|1!qw$foj0zenToy{$@ogMGj&&aF+3^L&*8w(9iCFeos7o%|Sql#Z zocK<{SPj(^(M%qcjamWFxm=+YS}rnw?o8F+pN-VytTH*Q8KEe43o0<~>i(`0W+VGG zzDURyRO1$b9rgf=!Ch=~lVAYFUorG6TWu?Ei`?q@AC^$G)P&KZ@!;nXwekV95(XzZ zRAB=5!OH+OQy}x`Z@0dycOviwkqt(TKXqMZ<1k%^6$*VwX`Z>vMCRv0VM9b1Ux*GP zoX-@$l`Vo-i%&OyYVzl=!pVFnG1t++=sSTa!zQBrRRSJH_NV z!T?B&)C@f{P_UP{j0;P;KCSB6bPxHqlf-ysNkczj)`lCg&clX!E5dAS8t$4`Ftc% zN2cHm4rox-Cg;2U3H(uWC@=7}r%fU`tEK-kHApjx5%0bb0*DV_*QRv#7We-M{EHPV zLhL_I)}(f+_oi@#LmuY`)3bbKMA8LHu;Z0~O7s%pamqY@SKiW`NqPVUE#S`Y*Q9u$ z8f9Wb6fRG2DB_nc;;= zxO{W!to(sS+quH2)_oHC2*qy0mqm=pR^facTYC*GJJQba37Wxcs}pP1GT*&mV@RjUBN!PQ*8>mrF}Vgk zp4YbZpsQ}ng%Nn~rrKRm=O|)H8N#eqM|kpoy5C!JNZ1$j>;HNIoZ%u+Hw} zc@;K6KHNAD^5csX;zK!N?Wv%3O*4EGW4X|vx_a_?WsmKzloxE?MH`<2|GD+GY?2e> z`m!(AQ0YB!4=m6kSwD3)< OvF;j;U5{|oY5)K^t`SoJ literal 0 HcmV?d00001 diff --git a/boards/arm/beagle_bcf/doc/img/beagleconnect_freedom_back_annotated.webp b/boards/arm/beagle_bcf/doc/img/beagleconnect_freedom_back_annotated.webp new file mode 100644 index 0000000000000000000000000000000000000000..92e409e8adf9bbbcf52d3201ba52ffa108cc584f GIT binary patch literal 65866 zcmV*IKxe;FNk&FO0RaG4MM6+kP&il$0000G0001g1OT}M06|PpNIFFT00I9eBuMc8 zcxyzY?%@yH{zXpv|9i|@TuC4V0>Rzgi@UoNsX$u_l;UosSX->c-HVq3#VN&#Ymo#E zfe3M3oyQ+*v-5n;X7-tVy%N#?2>=GLy$+qlX^>C9z<&k)EAU@|{|W}t&TWE6$=VHQ z*{HG2^}o|Q4eJ^-w!2Z|rc|t5RGF{AGpu^6)-?hg=hN@VtK_t_R4S&W+nJ3{qc&Z@ zj7%yfKi$wo=`dw@qqa@U1*sT2kBAmutvdB2F(>!q<*}g-DzP&cW!;3yUXI~vu6~-X z&5XT$U_rkcg_LZZCbG-CS~Z@o>X0ITqTH*Usd9vJ=o_?d_;`2w=tdz5#?8Op zcZXkT(cWui9H97-mwhm$gCho|pq+f$y|n|&XqYv>Msxm2;Zev9YT>HHpbUK2Q@D!H zQAop^{hyatGiaKs6ECKs&>tHJHyY*OxT?a#;56aZ%0l|? zf(2X?3=wq?7uWY-#<)`7UCTws?obG&+($LT8>7?k;62?;Lj@}r>j*?l+TSCP2~$>H z7-d37A5#f-fNDF2YMq7|9b>7+4;QTFM+YJ1{yid;`BGHizkAJ7aZ3D!DCB#4nPYOuJ*oc6z^%_j><#3RYFZb5x<{RgtZEu6oX$R zc)2Qzr2H}oo$Ei{^ZF71@A}Kea;w;0n#isy6`ZeGXpd{6J7d`DlY|K<-7eCfzVtg+!3^{b&_eoZyA`1v24QuHTyEy$Tqwz#lHN8GPEf#q3y!F1m4IyB%jhd z4F}KXA#fh^Qu8C_vg0x(LqEQg)@hhp;(8w9q$lh0sflhEI+ts8#3T_{{M+iBhG{TB zCk;85cmJ!S-m6H~2lL`P(^s+=OhIYOtjK>13;CH36XMJL zQyVZX+!nfI9-h5E)(#;Pw#?p}CfDR9WZ8ozJ&*QgCTgi;?8~%xouf+5I1k`jzH(4p zR|Tj?q{}l`dRA`thsh564SPPRGVm^K@Jps8^dVKw`2hgTbI@uI06Y%LGEr3lpy*`> z9S;J4M(-(O8pyPijit(ZFdt-c%(q~^NS0X#=93-6e+B@cK0uk2`blOJ6-?VTVfkycnEY#PHQ1`G_~UyE82jt@Tar+gG3~4pPbrF_F`MUMoRNn+N!`_MS~MYGm7VZkdM9b%82H=qb)RGyJx%8 z1~W87-;779W-Si}wsi`n3_Bt~$U?v5$~-nEeD4qT2hU11BiyLdTQwNXb3YvG;R%fE z0y-Jj1cI<$bG7o&t8NMqQaR`YVVP&9_37BDOK0;g-7L1P8njN% z%*@Qp&`OypD>E}QGkYS0J)suAR3#jEZY1YfHDGnu(`cuMLljFXwp|g_q?!32QkFTY zakFO4nnyt0Bx>D>07q7QPKs$9u)5qv3Z=CK$5wksuh@EEvBGmH!$k@(S1v7CuyQPAH& z#&5vxY@)@TXQ~qvdoZ|sd{FF?RI=fP-AqNAU;n_@w+}38QKg{{H&M5f^M1Nza7HL&dCtb zCWdDVEo{wd?Xc!Y_M z_8khA>}rsMJPxD0JKs^rg2s7aE{bGxvENTCc%_{OLxz7w3KY7{BnRP(=7M#8k3^>)9^I~~)#fcM*Dt1G zwD3}0K`IgJJ=?__6M`j;=OM>O^T9f__*6|O=g(0 zyPnDpb<-m{G&jDylSmoNnW$i=lDYsunVS|6bN`*+u5_S>%EP~8%V`%g(ei)Q0HArS zEMwYJJ*eDrtr=q6+Ll3_6)w2L){kg0Ykp)}e^-9qre4kZ?MAM-m4#Nfc>qB9=aj*nYL;aOT{d!N zgH1LFI>ro^$TBOze5^G@H07oyrD}P!(KHAEK(UK9ugfq~HwpuQVkJ6uhXw%r&&V=s zEljdWKz@XoYCmmqS}{|`Uy5)(!;>78KE|IbG*2tbJg*D@VV4|(#{vPMek^Sa-C35M zbV0+teHSy)(K(m*-qfKyd#P)MR)&3wbyrC%(g?;&H0dt z_VNba4#f1hTx6->C)(xC3gUdfPM3`YeEfa)>CyI3nQa+OyHkDupx!Q9Mb!p?7O`ws zi%iNb2JjJG~-F-m+cy}LM zpLjPP0Hby8J_1g=`+zS@?mlWJx%(*o(%nbV=LP;N@Lz%dT!7&P{$l{53j9~#zXJai z`0xJ$h%WG7f&b)Q!{d$9zng#PJ;7pribGE?^$H6vj+FEbjH;NUD*>Q)rmT~Bm&ZQCC z3T#x((lcVZAyDnLwN>iC6D|#m?y9unKRXK{~ zD~8v{>@ir2nZ7jD#etZ3VcWXBce0VzOb%mM;J^Qq<7Gi#iWm5=z<&k)`@f)G75J~f ze+B;gKcFHC{_?uOe+B+4_($Ujglsn-;JMb_ z2ULx5_o3Y3?gPfU{TN_$_tD4gM_;!e{oQ^HaQiXP{l~6kFYW zlzZvsL%A5;dvHTi-Fx_tO+@z>>VRO&g=`HmFIsKH87;cI;L1%neB++w2ajz0@5z%V zPo5_jkpW~~JV!u=|}xo|ueGT^3r4*-Zf?Ct|1F1!1H&Kd4L zd{4XkfZ1+8J~g@f=wo#E(bw%qKer$K-F^%(x%(LC_G7Tyk0EY9zCw2&%iMhwy6*1d zQ>~kis*ljUN6mlGorgMdd^EbX=)3$U$NqZsr4ij)a2t_@EZE+r0>5l7@Sp2%OMzdu z7WmKgx2?c`E`P=L0>A7i@Sp2%r@Iesi@Oh4;P#_iuDg$rEABp^XR5mo)%bKbAE54c z$Kc)rpy;RTj-NSa{leeY|G9km-{@?27yz8c)62TIjXpj;e#JX(Pj`pmSWTZ7Zax6o z#k%`|2}XAx;rHErzzVk?U%LJ1Yy5vd`nmn+@AhMW+mC@JcOQe?ehhZ|F@ksZF$3Lv zcpP>2(J0Z)hyQ+b@8P>d@76FDBNS&pI2{4_|-pu?orsKvQ<2W1(jl~K|{u~ z7@Q457uU#khNPSG(aj|SE7^!1EXx->3t^nzsF?$smQ}JHjkTB7~gP|vglId`)qWrpCx$WVw zP!0eBdtTx51ps)>(#mV+DuUHwdwHj-v)n#s40Qd^w?p+iThk*I8Nf?{wv~Iu)C6Bb7BF|P zP25~$YC7dG0ru7@{Gz{X1V z-Ef$`2b=rnxZikM!nS}*?AvCS!&ZfDu)zJs9I$h+iFw=Na+q#UFQeOyrS^9zX}JmhbSW;MFu(EsRdO+7Y?f!pSKK<$QdoQ3d38R(V+`RJdz z)v4WK-hCsoaNAuGh^R|T%S9)WX;HW;oX!7jv!lQ-JKcT2dbb}_+dHf=&9yr32RoPTd#ZPX;aFv{ub#N~0Dvmz-F-mCd+t79 zK(4!wpeyb^V2Rt0k#0Zw8Qp#Kbw9uWqlswgzT#6o!1o_Od%TuN$+fEmZUTxaHSt18lGAOqpu_e@+S?EYtRM|~?b_=-Y*zH7<8D=fTICHw;yD)- zD1_AnRsZH}HX@>7Z2(f^Pvp=Irz$La}cqSs^{oY={4Ep?_Ma1YT6zP-AG}L*8i1=rD zU|XhKfa5w$FEy&8JScf8Lh+T4WpQBqHK|FZKXFHz8)W5J}k; zuMNmHI%X0g=5z%HvEq9~93zeNmPfJ{f>hlsciSVZOT zi1@ow1ez_#c9edHh~t?A*no(~)gq{q$aqvuKs5Gd6V@W)NimE;#-rv(M14o5V+He( zB)bJS9x-hmeP@mCP(mpP7ux)b>GK>q{mT}GIl?xuEt2I2=u+}3DMV;B7HR_X!1RH-) z*;4B{(*J4+C&}*wO5ulkRzfbL$Zv)bvzbjP^#F-Z?O=oNA(X=9O6RC^wj|(k&e9;g z*o>dEMYECcW8T(!=14+9edp*ml*Y$JEvWXO=nrdHqOkj5V7i(>o#{jsCKArmY#CqUbll%4seD#b~~*A^P2i7%@;A>39L z1=f&vGsx1{QlV|<3>AGU5&G^H%EX8-t}-F8h)MZ@ytAH``Whu7qp>rjIVuq!DqHaV zTYT38N$IU)QNAQ^GiRw`nnb)R=?uYGi8$_M0p^NtF_02=i$$rEL>m7kSPs1>5r29* zMP;KULH8+GuK8YU2@QyWAz2KH_es)Tm$L#(q`~wxILA{>QgABBiej zpnncw%Q$PbVkO~TaVM$JF$s9v1gsakD6VTIfgJE06~!|rK6}Y}SQe~vvrH0@GYp*N z3ja_qz8~0H^NyGv)d!M*D?4ug)myjizi0mNosP+X3b#p0=nA$5@28(}xu??vGQC+CUZnsQd!#4-7IdRIcx#Y!(CR-X`b6AkHQze%M4g{n{XKq60@i z&{K>5u(~|h8#3vMK@7&{(~AIkj`bS;j>UlTyK~4eUTMvNouP}9s1`fX7o6+xK^rdr z7Zpw2XSeo$Urhz}b0vmtx%wp9p--=E`@9qflmqCVz+!-R?_-H3vGEz##})zmRn51> z7$~KSUR_H8PPf9haIxal4GUC(&AlhKa=h@T&3Y+~3xVcWc9um&G)UU=?#Y`j?C{dasyb(IwKV>2}6 zdW`>Zi9;998rCpS7_M;3FXt_x?}E`CB9zWp<&7Va+I;NN5_Z+xk%A)U-~Svb0sUDF zkM_IY8PMT;+O_fF0#sP=ARFnN8}(~FrL)C#dx})&|7~iUa^OoO@m34^4PY=zuFpV` znr?Mb+Tr7WzU6O-zH|`E| zsv5jT`rj#QL+cMn>ir6|8^m0czJj7o8*YnwfgY*9BfyFBKZa7cMr|eJB9gmNL%G4M zh1XUT`J1{n^vgi{8zwtZeR3t?V9xV}R4V%aOXkM1r! zI_`Xum|~u4JP;0_+$drUN-dymMc=;mXP!QICqboa47f72k7 zL}WF$Fq*8KR)laHSrphnP&>&O>nwHBNyNt*76zJ#N~y~d{Y=8^2n#K9B!VB|ELDw{ zh{r`NG)yDvSuvJq5(&41EmV$|2yJ_3$?u{>>{MC^xlPnQH7T2zl#aOs>`+(;x+xJc z<(ws$C=J@aV0i&a`oX{wg+CUbaX481Ng|GTI8CJzUxhd z4%7Cp+ zo>DKNA2`=uUp(U}X1d*51-AQ+d&P^+bg!Qpm?Q8Q6E7aa!O~!RgDX7Uo_6P)EPyi8 zuO%C(r2lwvY%#E#t2pmws!>GxkC(nH4#KiNplEg^LmbA(V*6N&?5;)_5 zb^4APP2Vqj*6;&Cx#0T!zZxypk-cjAgV3Vc%B%o*w_JMhY0P`azP!D2L~#&MQDNNS z2e04L_wD18GwY~9HfMkUz$dJ1MTb_12vma5>OzqfDpI#}s0YaDqS?l_xc2{VlI{7d zJgW~|@atOYu30|0OL2uzsxp0Mu3YQDl{0&nQIVx!TR6YSij@VgSlo*fOyOUuQf2B^ zDqBdE2k`24B*BDq);?QSnG-_UaKmc@I#~Z^LjxtF0w{M%y<-K{EPsSb}%c-)+e*k;i)@n*r)1zJ{PHN zeDsaKQ&;5@Qa*cuw>=?S4JcB>mJs&HbK*x7<;(s`JN)LRA=UMJN;q*PE+X}{Q||6lb8=CnNkciCynoRn?f;5!+BCnR1SYk&ZIl*8ocjeiI~bMEvQf0} zTiU{n*CPG5`8aEBQl$V-`P<7)AZC1SznZO{o-xB0g8hhPv-i0=2`PG}Shg#O%(t zjN`?{e@o2QY|3I3vwpZW<$9FF>!HqB=~vQ#t8MT;g(5%UNlKM>EK2bwqQVniR?5GX z25nF0tdmwEuKHUm{Z?$RBS}##VNp73#r2_*l_5rHz?II~Hz<*>OIT}?A-1%Jq(Jy7 z24xD0Ti4mjB9zFpUQXFGsfep+t({J6xowDnG6!|c$jI}_QJO7GHQD)gRx0$6RjMP zifC7aV^uYF>R6Wvj01r0V!fLW@Zaa|1M0`S`_LS4_W={#ehf6Z`{-lL_cKE(;wxF} zpc9+6tsqzG)SzV5i6*9HqAc>ARK%3B)*?%6nN0=JCsQ*MUHhg#e_1Z{FS~PvfZxP6 z){^poR6Hx{l=U%4#GOLcD#eNIeFZ^SSpnvW%s9Xj{3aFG{GGC@aT2jpX)WNY*#7Zn ziH7syN^59koK);qIAvbPrNJ;1Z2UoN^FWZC*RNjF@l_&YQ9WKQTou08(Trp-ccI;s`K^N_d}f>pos(hyVGNeehG1==sb zR>dMw@jobpIjII(e(K^g^aSB+CJ6#vGsN_!sx=s*m4sguP8!sEApu)_Y=WX^#dJCh zC^rTf3y%#VGE4*;eSepN2W7!&@A8&*{NZr0v+6bRT&)b0mBDxKrSVc1awY_ENtb}@Z9XAUCfMH#7; zb-uSJ2pBN(rq*%Vn!dQ(j71r%GEDu&pp0bp;bO&K)PpKZ*6bFYXTy7u(-+tj^v z`Oy3}0U&T__ho-xz3srO$Ch>r1%av3;R7-lp#Eg@ORYor?EikLr2zXq+wXd-qmwc5 z)bJq419G1Jf%NrNfkQQZfe!T3fbbO2^nHm;27oHE)7RrC3I5%et%@o@Saq4M-+Vub zx)a9qujUQ%Iw1;;hqidi#M_{1m|7r3VEMX@=v%j3ASV>(Te@~5(bg#&z|lhaqY3k! zsA|vq`)x|Pc+(R9`+azr0A8(D-guvyPT$nne^<2h5<*>f!KJq;>7q@Iz5YuJPdYS8 zME1m|?#QJph5uzjyTY7MiimDASFEJ)qR(o3OH0Y+@hE=7twEml)Y+Gg^iJPX)4tNH z6HxSNJF8J)DKaO1gU=-M=+K;d(<21osxFVxA)Wc8KYMvgNTYv|%=Uk%ScAUCrGMsy`L?EJ|gWC`q|bj z3JHztNnVl1tVyH$D9)r&N_%`3=OX2=RhNi}t4OY48fUH1TcrQ1dbUK~Kw_h75m)p% zV^ZZliZx|`9je)Sr2gedNl+|Cl0P)C;(rXK@Q{x+tan)`|$%Ds2hAh*Fr|K?)`z*>B2QQ0+u% z+^n!N6Nz5Su|z(nQOxhF+0siZ3Ajg1KaW2NGYqg${Fy{N4zuKSnymYwq(w6&^^!$} zV{PCzqcp~pr(f6;!f?KYhG`O!QpZy9XtF-mV2MVexOXe86}l@C`X2Nv_nx%%7CP%C zLfg(#<#@8PKOw9bTe47Omwm03iIoVPNWUuaq;2EOdKo0b(8W^CB(ikvNPEGQtQFbA zP;0f4q++%NB#^dUVZkUBT`kojtvy4;Z4%j&BG&4qO2r(P#7lP{#sB}0SO4!v#Owd} zBRndf5hpEOEY*}Yzkl+Vl>b25MhjgH5}|8vscHgQIjsnTr7Q_-5ZPlJ>Zarw!k?42 z2+W&iN<>-%OC?^Bm0X*&`f)7DGLhW~v{o@rDyGxV>kMJ0;T9raNyPKwmVEyv>%XF; zDdrd$lJ7-!RBbKnsYIBD&=2Mk_Mxf;kHZqNPi+Ynk+nlf8u+i)u_JA=#WfGCYmP`n zQf&#SpGej|4+}6qg6qEg#} z<&aB~a4y)IW*bR=1yBIEh=EJDY~Qwhm%V%T+5Y?AsSE^67u5-0TS`5X1mj4M!b*<` z;(u0Kflf&hkk}4vtoEFoxRyWz>zrd1K5cI?5GC%2D77Ql{JlX6E`&$|booHe(IQ}7 zIX;_unPU{TK+kwmGQQ%d;`k;rU95{+@8%C^9R5)j)0q>=0Kf)L~W2(Z;-d@|)e zj@5w8T%XruBz&y~Nm1=(AQYogMPl3-2zHh_OTC1FAeprfW|Q!CS`gT-?DUVGV){!R zlwfcDqdDT!U1*~KX@P|d1Ski+5JlRLfnayZU0S+5?#4+6_;lU=JVS33uR)u5ZEh6> z*c~$b=$kCPk-qw@*GGmH0s;NH?~KaO8%3+ndUa@UFbGSv`78uLwT%h9qq0tSR)c`P zpWW0^i;rDd4y098tWmfA14P@meYF4%1obH0qG$gBwC&%sc_|MNSY5nv_x=M!+P_D$ zNDTc!{;(g6j0>C)W1my@cWl z)$Q4j!hKpqs2!jPZP=@yi2JsT)Yzo%crpV;pK_qN(l)N%jzk`5oqG5arCrJv2UC$` z{rzu)s4x%3cstnAN;X1Kb-~SK120lj?)wv;hYF#rx#)I^fv2!3>&4E_-U6u_t$dJX zwfmJ$$O~|DR{Fw zd4(T|0?(8J0G~xh7NYn*BZ@z1tlExJM~q1Kr|kr&a)C!OUv@WB|7b*Fwc|M}pJgKT zb(0k~a1*si#S7uY6@4xa{`RL}rcVY$|#JssH*DyUJcgV&8WJfX-=1 z@cV|Asz##(#y7K}NgPsgu|gUUd94v$@C2xq@?>B_Yg;s{Py%n3w8M7~68x|{1e`>o zx2w$*D^L>mdRWoyMp}NTOVoKCIkyvdXYn}&D65mv?De!M3`h9~nNcd>8K}Ko7@m9tmJ+Jt) zM3rL6!JSGgH4>x&N88jYlPp|vi?od#04za?+^(>|ZKcSEiY(C}BSBBXtbD;s#2%$B z(~$66?@2qU0Z{CginE>;JkL-hvl(g8OvxN1IJu6MB`A?M18q?3BrPMAw2R&Vsv}Zy z#m|E8KNQinWrHL)c&3C=V_8Y^@M<#TDhl}o}l|7Rt6g-Vk>6@j3@1%y0K(EEnyaVQyQX6 zTPYPq4bxXZSm*;$7^iRm0G}k}W!5MF!2g`wQ|bjlYdI?wVx+-19BgfvLY8TUY7JR) zz~We=BrN2tzyfOAD^8mFfGA#;0(14gyv&zizFh86{7OznJFu$SEDisau*v%vSud(U zmFFbgh_DoLP73an0_!DjQ6gs;kOm_RVz}aG0T$+E=9sDX$vsf}9Wnd7tU;rADKJe0 z+q~#c;{j()_&4lbQg~<)iGwP0$hY zq88Ywm|>8BlZEWitl$ayyC?uCKTjm(Z7;B~?Q`0_>&Mx|^@*W?er*tt2aTgd@K0U{ zA5HGJ@EyuN;IrCDM0{_s*?*&ndUvXUy@d~x^SB~jVkzlyc6l|`2Tt_qGr4}66 z&NctrKw9iXKcE3LyJpIZWyGZ0gJ?o~`IL7#@(Tnk%_1PW7iSv;ugswvf3YUmAHG9R z$n^$bHGIOqnY_68w98+IfSrLu&m^1Z#HU>uT^Q^S{raCYo*ZrT>RJk*1B8G7cWi2! zBQsC>-NyQ5dfbp-z+>PogUHhN)BwA^hTbz$?ERvmAf(^7PfY|Q zEH44J1~>nD;qn!tT|WQIh5;a;Z{5%4{j!3(%NLAn90kc~T2LScn$u9t5BMv@G$rfp5+^touygTL=-aT24>-~@qF&Qx;%!vU4`fPtuwC8cu+9vPZyzNiOQ9&< zb^7YfTSU9@mvJqEg;196GyAvATd2E!(TJK}0{J!iX4!@<1a4kCe_#c*VA%Oo9!WL6+uB4)5B~}cn>KNDv%Y(CFb{gS5eTa26(j2ebX|MnUA#!+UYwm% zTO~~K&-On25KrOQyE_JkIzpk=h*qtzLo@U_l4$(9sck;r$0E%$H&n$a!}j}t4a&t`_)4uQd|G;01sifqFv`~K735H zM|Un6QeI`vV@4(t`lg31{;PCI`STU*X!;0=H|{7*g{Id`m{YpxZQ?-XkL4Lgt1sXiV zJiB2c=K#<3GL6RqEt2@UtsO=GK-!x&1=ywNaGOUGW5;@%HT{4DUoL8;Zw5->GNldv zhmnffQRD@m#=QHvU~puG=kmg zX3Cu?jZea@)JvuXp7bIt=vE$X5;$17MTUuZMh>p9p+mMb#MiKC0TTUJ-~+;Nj#=mf ziO6hj|&*xDkL$ggZE@r*1VIH9T)^)adV&6a)!vT&z~v?D42 zsGA}YINHi;dgQi|R}#J{UbxGB3rE!sEBwg9`DP)d=48qwzmSyE%1Xd>sW_^#VJQ+G zjietltDhuYpros{>Y^H#W61pxiB%{DmB=aN}`QvmSUgYF{I7gR6*#Y;3lu5nn{6EnQqw`{$& z+WafU@>*#67^g>zkHZ{RC)on#zE9yXAIpopmaQ4h9rihIDKDST1!p@-y%*hG+zfS4 z_1JteFY|EvVUFQ`M0SEF?WkG36sh>u%CGd$wk521UJm~acS!9Rh9Zl!T?zoGnjjJU za4Spbk=azn;TI|$;I|KD82FVWZCfkBx257wnnaPd2mqkyQ;EoJYvo&d#Fi)RRbCEL z`w6FQR$xqI~*KLGSe3pu`%rFx{ z&%>?22C0}1)>TJHGYrTkE4q{!e8Wq_Znc%*>(rPHvJSrNq7X#$RT9cG)#3>HU2Scc zQ5v$^*Z?a?dmD0rtficV$p0iEvkO@N&P0irYNSQH&f{VHcz*%HmSv($<8go-{SdHT z>bW#r3ASaZiLgV^D}$t`6~OWsy%g;Bwjt~a9r$^iOk;X=`GwI8b$@)KvBS656%(54 zo?Lm)%Pi0-otVoZHo#m-(0>88mU}~1?oiPDWFjYR5Lor!EddWIgRN~oP~l`@Ag#ok zyqV#*GQN>N>&y_7_jC_aT2V(1J(-0TGbR`Ht#(ju(X1gQwHw%4{F)RT4X{bElB~-` z0D?CgNlE`sWep-vxHP{-yKAURB3-!TH zMVALWVcNZAfV|%Nyx9+6KGmAJF*i$VLR*df000!b6w~cGoYug76O3g z@$w6(o34+_;YDLiy*8yJ2yAR(Si1*Uys!p_M-V z^!3$%133>re-eFEAiTKBU&p-qH04O6`kDM@3oZ|=A4FsV* zDs=mH!bIv$_@+Z?H3-X9U-y9*UHXYmYLFpCRq=1kyK9qk(O#q0WCvn)vL59bXI))& z^wu-~-W2VPi~FWG^8r~>OeM~voOu27HWQ-kkpc5q0Kj<$1d7*30dl2?yf>qqc(*(N zeDcB7CliZkXpXEf9RNVNlkrokMXcl~Q1lkciX+Wn1;gi2{mYemkNzRrqrd+;x~>;# zUl`?uEouM={zooS7p>N;l_*;_EFZ+V22{;=$MYz1KIv#D52CzIpuCtqCO}zanO+_$ zGIam5kD1xxO#g6mj{U7aN~?vWF)yNDwsRo!AW5 zIxE2i=vn*QwMR~f_~^#*jeS61<_8qjf4q}w;6-B6zW?jX!r&_8lo}DMI1pYmJJ}Tg zu29{cUwkFbVeKk^4#1yYF9w{y}3x@$N51dO<^Jus*<4UcrF*ko$zZ}`LFg(B-FU8FhQf3 zh?qzMyr-w2`0uxt`^sELV)>0e zjmkkXA61g|x@3}s|3wm0D~W|TrWRe5mq_Xsjf|(+heY$^h$;D+g;)=w`w59n{Y1vA z@Qy4z=|xJ=Ef!+7=t?{z2Up5?J@tgWDMgC<4+erCCc3U#f^G-PcjJ-p^hTt>Dh49E zrRb(2!3kC6yE&xgwjpLL1M$AR=zbw7rMleV7ewi((h^pzp=Fz$E4&z6$HoHk)<07Qnice8D=b0oFxxlyNW(V_sk? z|mCYqh+m@ivdu+oG;3}I$T1HcX;8&(0yDb6mD@oe6^4$OZM~D?iVIu9!aV7<+~aQg#GPDQp7WsVFi#d)I`wpaQV*rFT!R6Ns9FhLry0ms>KoX zyIQ`3Pjy7Stwt1d&t(^GhZ5njpB(*QknsbLlf=*E$SQJ|U04W2K*w}q{t1!upk6dV zCqjWN_<>nSZbXRYH&Rl%g1q1P4KaUL0MZ&Hu?ok%34vl~$k0wx%6!n`nu!SQ?$SV< z=MhH1FdRsMvVZXeWX$#g*}vG#CwkH4Tp8vI#YRg#RlVf79pkz zQ2@%~Ex(vJS)Akh*9icZv*;q9vIwgcgt_|HA>s)!!5ju5zCN%Vik*mfSS6-%(d@x` zl^AM#MAUa?61>hJ;sy})9OsOG{F)LM@AE=@JeNa=DE<-=7cdE(a}jmj#03*fPS|FD z#eQ0V-$uJ$Hir7N2!}TBov^nxK$O0h5b?MtgP>fGh_6bEtmqBr>v3sN(gPwN+F=+C zG=XWn^EICn2dqNG4^SMil8Q!&oAMYLJ#WW_ZB@s@dl zh}qvLSOWFnSVZK1Q4;_~uQ*pZ?J3hX+qMI0x_F&-u1vEz5y4kFL`?cj$qq#RoQ{Zi zDh!D1nCw*HQpzkw+h13pOYL~)>Ox@iCu*?o$6CA{x$g@^Phw^dBPRurbR{$MI->u_}-ncEPE_Kf@LD zDEbH5n=*tV+^9^a$}o)+8C3rl%`;Drsb9=bBczAg1=S#xHwnn2)tt>GfZV3P{6D?}bOhu>qNFa#5;$J2-=ToDuoINAp`DGrir-o_hK;zv{y@BM> zxy}?~Tp}I#hp{N6?xmg%nNJPqR6nT(1QuSLY$p6gZ&zC8m2bm=Y_E0Bl?bfk>Pz+t_T3X*cjqI3cuq(K2dpLcO_rqT&r}Cbi~&UBTG55 z^nNk$6HAmLvt)-PF+8agS<3NcDmNay{8kQ0C(45TA-@_3G3<>5wz=jR6A>AMLC}He z#JpQl+YDab9PCB-2+qP}1W81cqmveQ_x%d5D-~MXXniw@| z%vH12)uaK@&W}j}dOdoDg&f{|YZtd-Zyai|R?KE*^djghXdyl%xe&{gJo_wlfphy6 zkP%aWLHE3ob55Of^b5|vOi`PrA9jhc6E3lr3FsB!Rm@=U_e#dXD318 zvThNiydr%!t`lQZ{A%|}JZaSjSnO}vJ4$`CRJ|RR2+H>@^Ag`7R}MhkuuGq`JwNRF zEJ?$t4v!)9E1+fFiHni@aS^uX?_!tz;@l;fzBUD6D_PZyw1WT0LAm~N`XCv72l=KI ztsx5rinv^T?3APNfh^`CX+QbvM)1;4!8vACZr5uL?&Uo}5v_#P2N&@>i-=zNENIa9 zV@n$r#&xdlIm(dZl5hpF?$9ZyGuE)6&=~LX1T@mM&erw}*Hx^wz_0^HrfhdmSsG;k z7${c4Fve2YIM6%m=sWlcFm{(Uk7;QG@L zn@s)i5BO~zcDe@;@zt`+zE*;;H)vkcyNJtR4#;t*LS<{@CkXZ33gOy1b495yp_(d& zE1e35mrtL5UTgNUeJw|E`Fx+POO!O-eTsNVa!YEGr0cuPs)5X-c}xz7uqqzm|biH-Oq-x z?v3LPzM2C-nhw{bpOPU7mW>onnG*nuH!a$JkQjk69vDxLJ8^n|ADpjH#sk}7_p6on z$R3scc3UqNF#7kaUi}u$y%RSnN27Ejh0II|N-z(aT~jkzME@TaB%Cw;qc}Xo*UV>j zSJ|syYseVxvg%dY$lkh)ZAttb?Ze6NV&JD+Ie1#>0X*ow#dCkP#(o}rWgr2;9fd!p zwK(jKvY`Sc#o8(;namcRHU#E8Ij4kg5&Xde_l2&WcfDA^YzV~PZo&Y6^|l{@016Arzo8sYZNOlXi>}@AWEwac>^cD3h4_KZOK2pH9wRMF3}} z*!hkMm2WEnyk2*kukzu7;lneq&D0kqBq**=-Q%wpLMMhIYE%ZChYmw>cVV;Rjc$2MO<) zCCGA(^{KfDXPyoPv454SK4fMwW4_;aL@nUy!9A!p)fc2iC)*shcF)J#YRnU(_cqEM zv=rz?NshZVRbMXIQX`|;Nn=1-P=A%4=X%3kZ`b$@M+Jp`+a^(}dJ~;EdAG^SCSqBc z01Aq$ydJC_{T-Vf8D9pe3i7-&*_x%yYfnN;JMc`>lXLWyGxMwr+#n&V7W3vj$&e-< zK-c%8V&rChJ^F~5I}r+nCA~sI+6K9sS@x04d9LbR${rIrDWSTX6P$T&l*AfeEyPKX z^EF7KKPWlo;wzL^)&pIs#=BK@D!czA%<*bVs^g)3d4W~w`(1rCO`Dn znsfY*N~T&uy!>vY>4 z$CP#UPw!tnkY7C?dRH?qH5oax-%}rp-&$wa)7N)Bbo~7vvEKHd%%AYj{F~Re-5$K> znfTY_W$caLX5T4a!gnn@Ka;xg34JoUwEdj1qd(za?>Y4eeJ209jwe6tx%OW11on~s zmOR`23i-Bu-p<7P=x+PI{94{odV>CjH}VnpS@%!1woAmB5Lnrz;7s;GkcrhT@b zXq>xa9Ef8^2L%i!1!t1`zkcIL3v3jaTM6x<6Hb2C^Xz1S-+03vGA_N(dfKuScnj6l z@2Xk%Tev+8E{`g4>(K@Y0Z*{z8>!a7bdKu^S%4vL4Jv3h8-I3TKpL0RJ-jysCOj1d zRK>2AV#a9qXAb{4{*flw2&CX-BWyHc`|7&YgLn4u!w_dfl(SSc0Tgva=tW6z8Y(BV zcOZnhb>9-oiDhAOc0hWLJbFgaB0C?!D)Jp`1a}`^_ha?@m&0uOx4`fyF#vx5eqioD zM@9-rGsnguS#P45pJk|)d9mG;^G2sAWwmIX*U3H1uY87MgDvgt6`p1qnH2{NAO(*H zi^Wh)$kITk(fJQ^{o7P6hr6uYi@CwD`}$otN~Pd(TQC6KGtUD*D*;q`f4$iIH(<{Y zFzut^-+M|XAw~St=>I(mD8wS@j#%KLdUyV>BTxPyO(=d?AA0pDWZ8Ku5%Gt9c|zzF8c3l6OrA zSwGDi;>L~zHcFXNL$vFxi5_56GY^{751@Us2II!)0t73*2k z0QQM1lP1X>_?mt7Ru57Auz^UIq;W*JmyA6<`dspR3(EHeJ{!nh^;y8X!Ca19^yvUH zCC2~y=P0CIO(>|WXdI&wCkHwx-UYr_!Ec$oR!feX#K5f0@bAMMTY8a}xiFdC82o`9 zB0b5y!d1@%I!@H@TsdnMW3_vctn;rmpK4BJkD`?~p^vw|{%LQYQ&qM|Me=S}fjsF} z7_=g@{~aU$ofJs^X!X`-2LS8sQnf%zRag%C}+IY3oe&UEuZ};6QwwUqp*6WR5F_q`8{^) zDHH%)*dEj}<*n=ldP^eT)CQ5U1pzOTQ1B;55>Ts25JSE*bvWTijj)cAz7}lsKi&Ty zuam=>t#Lli9jOVxiiBASDX@f-8CjC(e=jP1?SupS8`6#c`{5=rQAN@ScDxsne1y83 zCaTn%LTwyB#q=Yt>w9Zn87=T0&!s0pT;+WJUSt2bD!PFOD-m{2M0bJ&1*-lV;u@a#B8`mZMVMu#zN8 zwKiOy4!IM4wUd>?;nDEvtiCzDX>y|{fbsuNBh7qUzl=u)7 z7@_(gP~MTOXTv9i!KQ94m6Rq9hv4SKoVKtvmBSaXURuA=b8PdrkF1t%6L`q5_90=z zj3XlgdQqdq2oz4A;nCxiI12b3I(+W`S?F91Om6->;G9l+4zjcgiiBeTGq^=>_-6=M z*pALTg-e2)&I&vLg?h&`lu_WuHU|MgR?!x0gm%$nF#;ozRfttuFZKmBmjsJbY^E*GLN+6}B~eNAziH+|DH($%WY>P^62*IHSq8S@ zMm+p0&io^38F`{}wIXp`A|Bp;kEZPZtYu3t_OIMZP?L5{yP>|VwXm;?g8l(+Qfl#& z;1(pUtUHj>-O#RQBU~wTm3zwQnW`>3g#Jp>;c2{5dy6X^JXrLcLEWe1XDNB>R&DN zjBtqIg<4expeQzOvccblOE_lQSNUDo zG~D|x>yc8*(yM5{;-=UBHwxrhNi*$U*ET^#g}v>+n9HlJzeVj8SlEdvnwZ%9F`TyU z+hn#gX?kN!DwS)OA13v3mph^i8ITSmx`~d=S`F=1kY7xnPUv<}Wud%v#v%=k8hQZ* zm)F=$Du+@BBxr?cP%VC=Lf}^in^u+EZtTfALO z&K9c6)*=6U47X7wcl^arnzry=hnl09b0C!PHK&kn=u+R zimnLwHt`lLmpf2FTA+l>X!Ch+F>Hm)oxB#toByGj|GlDte5^=~q6w~Cj*}tOr810+ zJvlYzA?VBWP1-?bv8GAJEoP0{46g1W;CR3-3K7j^5u7+U1~KELp?CbI$=%9}_tA9^ z1uw2`p+Y8Apn*7ECWVE$i|;+SMS{@-GT|ov_tYlG?iy!4jfBMJyO|k3$)zQS@SwG& z6BV;S&P&?h+{1G}j)VcF+}yT*?psrquG4kMYt}Jd zE1`IKbi}B{3;al)WAGsT`M1^UUy0U#kXLAeE>pwM-&PEiY_aBxOPqFawe6pmOPoOP zBCdjU^4pg*AkXoW*QA?g`eaP@!B5bgV>$p&IVDrPp$?2P0YHqR4P)iavauZ?>p;{TolAnEiDj zG7z~UNtaQUi}O~ZLP*$XF4y5o5y5^YQ*4|G$lqXmz&nmznEcjgr3^p z3%9ul0PFEC(C%FnTyH@{T3Rn13#O`}_KI3K+o?ojCJ|?`>LYm^yQX`x>XiNFS3z*3 zo2Mw>lPp$okj*>@d~|*iNRd2-<*wx72$U_;`WqW6M>_fV4`zYADJJxyi8{!%VzJtlF)b zCgQ0L`1`n;xNZ3bSAXbCf#q~Veh%N~BwzK?M-+`hURWgD+FaVqaCM+aWrlHP52>^v zlblYuzitkMPwc;P{>;XdV6gB_PBchpyny`$#&aVqJjT4=U>Afl8TT3b_);HaWF}@S z1hL){joexwS!mASZp~+_`oM5h@T7ED<gvgu5GZODS|kpM$gn{40%zm=?JU58xPWMeBy14@_2k4ZC)pbF>!(U4(i zP&~1Bq@)W6$GJSke=uHItHRsc)sR|UVoTFlhHDsMCOF{tBg{74U!fc>TF=?^>^(T;0;17JDJuyF>9{$^R*8MO!AE8!1n;*9KP4w z(R)fkm7=lKwXon3J+OwtW=CQgs^XR|$ni!HK}Fh8*w6=MR|28CXPTu$nIi95qUV^x zH}!{&atLw|bA%FUz$fyFRn)6Lg?@v6m&2`%cXQ0OCA~ONpw~@~W`+O7L!v%Eds&~I zBFoH&KDeq;H%uWj8Zf^CXbKw^X^lebF78v-mR#0u}s;pE?Ay~{_GZ9R#B;uonF2%RSSh&+vdXj@iG7Wz=Q29Xy~+<>QO=O$m=+wiA!&NU*TqARg}# z6f?-RxY>S^?+l4fZr5T*GaWmxj7vaw4kckxf-QKvw9wyh4?I5Wq+;QI3aW7bU@V*c zRZmA1a~B_1Cq(HaLzYAn(LFtuOqr!feVEYrcQhod=tl8KpgNnQEA)d!l=hj};>5f` zVp-uptw!0#`sQV-JtxxSCqJwya5_akdg_?qFfPcZ<^czjW6NO(6ZWOf7A$w3Nn(__ z| z)VlIdTqzA=>_zwM?k;itO~~-`CBHpiDJeC!_E7C8oGP#%;F%puBe-{&h7H9N$=^w< zO{j1zj1`vJTDWVdovQS+C;=m2!u|};UuvxHZgMnptDy`J>gnFo?G8hl#^?Dt z@ZxK{#p6_+X&ty7gNfx&|0Q`nipECm&ppWpAJ0VoE4$aoxBuwXq<(-nbyjsEw5w`G zRbItxk&+GS9+(hJhqHAQm~?VVV;Ph0ixv`I1GiZZ7XV!3kr}%9BiYDR8q45`jy6o#EF{pN zEX=&J$dI!N(mKM$$g#6Q&>1CKD6J_2F=0`!-ySrI6{$T9f7f=h>L13Vm3!CuNYb~@ z1*L#JwYfQMtUsBBCJ-MSVpklE0a$SS^<#E@Ij$9EMYEM2>Ou>jNJ@v#wnOxdkftTL z1I+gGlqQyDc^34&NB>$;T+H{7Yv-3UmX4FW(@?85oj&_f4U8rQaK*7pdA*LxhtAJb zVXBe0J6s+y;gDW_u$W%yY`bw@*Nu50tKU7fvX(1k(G=4)OHNsS26x}#SVkHnA`{TV z2+2=H#!rNe`K*E5teKrz%2vPRb$0t+{)i;m(AyCE(u2qw;zl4=w!t`%*_D!IlH}dW ze!-suGDQ~-0bO>VgX}t*E%JhKW~&vf<_=-5MdFxxlikIdjS1n*-%0uD$wrWEhjG+T z*&R+jdD4~-O_yoIoGUZ1D$Wwll#R#h@Q8vSo5xpMyO!?yMO&FE<|tsKbkDIHU{rX_ zm+(f3!r$i~PyRA1P>2;qWrN4?nzafkZ@NiibisRs2Jldd&U%E?BKA)}g-V`QS*AhY1u0 zM0}GZpxdo)SR+%WH*nG|0puuk1!0%7?Y%$d9Ie%=>y&%4Tpndp2$x2R!e_v-*c_^F zGL?wRp>=^BgLm7bD`^o&3pg5JSs>SZh7(muR5n@aKSD40U~SS+h>DNLJ4?mNV5n*$8a3sd^%x*9J_-sSEws7sRr2xu7vQTaN(&f*&GM1Jzj z5x6C(QrOoPH7=o8cpRBGg;XO$OAb#6%e}T3E5EO+me~0L?p)09YYqB(g7hqsEvq^D z01(*~yPry`&IQA}BFajv@M@jr?~ z)s}J=CwBN*k@ll&3s1ow)|IyGYQ4G53#EDL*ljlFRj{VLX)X2Uj_*f(z2z!DCDs+M z_zY&QZ}wvJ@adfD_4YN`0323}P$e3G8KdAr<10znz9P9iy`ay2?OR}Z>y$uVT=Aiu zM*~?Xsr=ZvhXF~TD~-%E^~i9FMe$iGLWd;{pCZJF;mtD=&*2- z1vMz$=8i{ip6Qunw!Pvyab87RFLt%|7zG7sqDF>%Kmg^^??Ao5w7`GXuVI z!uD{xLdmLpWB7)ft(3z`lCqDZ<_ajyQR?2nkj?p$kzYCk-ozawRM3(7 zRkwJDsb-aF2+(cBFqc&<@<)EV&czMhp>a8BDNuq~FFR9@@CBw^B^p3hHx>fdQ?6k7 zC$7J$w%8Lxfy9>$ox288K;_4r#|3yyH#*2|>8$sG zB}FBH+91UOI4P(+(8+A0<4-bk!{ApOqSGDquPtukE5gHT6s|`Mu(%rVQb!`k($;vJ zozG(6CT}3@egz@v;W!}W@6^lZ5!mga4jfaT!iiV>LZt3+UWy4vK+FscVmmOlgp9IQ zC&USyOYBhS`{`Wp&IF3)jo1=yYJntfFP$4ts$b6&kz1mr>9?gOu}wRw;F@UMQh+g^ zGNPI-Cmzp%gue~j;Tv4eB26|#_B%PBJJE5REn4-~p6(-*3OXAqIs|R6(>Gk6!ae-o7v;8lu9OHlLaHta8$lNu6ghpR?kJlDOkXm4rH7MPUNQxmIAQI4_8WQ>3>~XfCtTj>GFIh6;TSW zO@cLlCH`>@dDxMDyK3vU%2Z{X;;zw=EUfjyuRkO~TrDywbvq$T|19oax?3L$gq}cv zpG5Y6@o%U=f!0@SC`fmE(9>SfO^Oa2+VEoI-5mfr0Wyl|G zNFyMYe2QEaWY7A!EGXl(KGbD&E5yXz|7$-i()CI4peemGN?p8&3^>V)&^ZbAR2v0o zW$osyBD(zz3?q2|8U>wAglu1-XOx}I-hsA=&P0Tnl)k^!_1CQUj(sKc2hb%>oxv<6 zwIWQ|byuONbF0h(fBQb5dRiW4W7ob5=~ZzX+sV~XH5{1EHQfoUW*YJTh;TWyOztXw zd{Kcq)Yg}pl5?$bqJjJlqbMcJ`4JWSWxdfGaCR6@zVqwuv0RaQ9XCXHYsYIf$$MGU z)za!mryaKqNj@(lFAi$D+6Zv~Sx)-8-8%1G)jA|{LdYb;fBjTqL#DO&ES z_t{xJ9~ZO-(RMz%hXK-`nswg;k`+MbJ>a=_P6<+Fs_ zrq}{{{;LMCq$%DqsOfVgUCW?0aW<@7-}$`7mNIlH?DzL({f_-((e*i`Ie;F0V2U}_ zTyV0DzX-HN6|y>UB3A$l0SYExQ@vc3-*sbH8|1psNJpGA=P!{6j26dPpv4}~@~l(- zW7twcLIz_kYtI=25GN|m=_#o~dhtpSWJeBVQ;iJbNb&agn% zU{y_@GCHs($rS5QfFF^1oHjgE4y>EWLBw`QyxWP$FwJQTZij#xf`DFx#s8IQrwGc+ zRB;?o-LFYIPONY_#;tMbFwb`5BTO!?L%LDn_{;-mepkK3z+BvyXg)uA2vthGX6M*4 z^$=g>g^)-A`20@P_OX`P{HG;<>f!%g^CAW?HsQpi`|kH)kNFXPpwF>BmA!Gi$79b4 z;r>^_<)2mjWhR$?vSM|z+yJ*OG0{KD_<)^Y%zA~S81V;+9Muf6WWytNZ}XZ zwv$$a#Nz*_sQYjAL#q;Z>Z!U=pmMQ^2qh7l-gfO#D-U898zKkQ<%k)C&ycj8~t z^SfSgrKG1f-J=Ug4^O!OUq^wy0EDx~bY*(F2f^h}lpgwP?!l@Tp9G5T)=M~|CjN_> zacO^Vw`cCjg~vjEZr1^T5SCE>{x!A}j7fMo9oMkf3Y#A&t#P}&Lgc3dY^!A9H^3I0?~A9yJVPfC?3p?z z=!l84OD~?USO1YbsPOXzgmXgYi~ijNGH=`GEfY$ScrL3l%O&eJpBU8J%=Gy&gWK_k zCE*O}G8WwJY67=!+sH<|2aqM#1$k8JDO?n3rUXA(JSV8FFCu9*7;x%ZW1VIR(zay` znMGV|Y+pk$C-L~5n;<$ONCUVASALxprTrC8w*Mfc^IRojbs#XUpt%;e9#Uab59hQ< zOg&Y3E3mA{(QO2(gUkLve+H|+?=>yROS@aR8DKms;1X{UfTK|3dhK*j+O50-(IABO8(~`n(-TqZ`IjuGj6~)@OMtAOotOyKt!Hn#%8}|Pr6a8(Fj-Q@3N4NARY>zIw`!r z<9?2KuT3Hs!Q4Bfv^bJM(lh-v=PPg;Zfs;pkUx!$qynn~-4y6B+vjkyZ};&GGC|tS zT}Uv1u379D3MPHuD^_dgTh9$o8(zN0Lv^7Er8Alw7*v8|vJR9I8K6A)3>!VSI}j(c zna29#4XWhs4;Xg&mHzoT&I=aXe;wUu1eSjkDCqJ2C`zhe1bjI;EOh2*!eEN9xsjnW z>SQmT*FZWj(gesVXtP8c|DD}$8OW(7Q_M!jIw?C95X9%pYxcu2Ru?D7m6q6GoEh<22S1AeBddw>y@cr-5-6FeP ztoXKg4F=*ms62FaB|^EPU~hou3x~vyse$pv#pNQ_sRqi=A8ksSC8LLi7)B^Hh)wyK zJ*kFm7my&rl*irVFBNn*VG69-6#yVXd;uB?EtZl(1UR7?y~JbqtZ7HauP0Sh9zICJADyD&q=6_1S4*6X890l+w}~ zc128yD*^}U93vYc|L0+*caRzp!2sqS4%F^<+%2AsKFCo>OE$5xrycL#`U9Z@P%-ko zRgog*F{+uEWNU=6=Tk3irlVFtz_(?zbbrd0)Q^UUl2|Uco9l%U2gPddJIyy(N%1^@V5jASp5{6t zq3hjhEfuq5zr2t5ibVxC;w~0P2-v-hh|<#xzfjqNcmJ;ZS|dGBL0OP5gacs@UN(HtN@(q z7305VC%!#69L?&o=~=z3k)E%pKot(&go1iG{@O+9$mcP2lccH!R3d-kZ2>rn>6dnm7fAKATjg z;1zSx!|eMt@Lg|tnYY<5|K<J0D$KG zaJ^jw_^Yp!QsVhN4_?Gr3Rn^v%s!1b1ASq zaASdy?*t`>uTbk9e4{*hS$b;hy}F|{A~%Ull}P^6>n<~(0ubS0OxK|$CHPpF5){mfJORj2fY zCeQ;NYs;U5X@y?5vVH-JJ?`Fh)oT`O<(AOpUB2t;^#jDJd)pVd_?Fo21+1d?K-5`- zcjulhGyVPR-Z-SvO2wMSpx}tUz$)3E_4Az>_bnYK)|uRhTe0^CwaHT2@U>Bk(P%MX zD6lc;I?_~2Wwl_k*~Y8IBAg&8PahuWAU!la6Z99hVlMwoJ8o?!VMTM zmEMZ}p(spJ{eer#W+rU(a;!h!Z2So+T{sjb3oyH_bl3c?AhdrLnC7p5#CukRDu||2 z(lpX2X(yXk4x73#o(@W)bnbl&tmOH%SD(NDM*1)s8PokR*O{#=b_;YUFSw%BTZj!W z7r1Q(Q?BLSGYWN6wZ+Qyi)^Ir>*H6qjP}(rHk+aZ;M^F7zx!T!MX9j8^lBQvQ%q}i2JcwD@pr-y5vwVqbRRmM9Wlm;mL`aZ$W?)KD~xvp7g&nv&LV_ za3>6PV%<)w>mbjIv6#4nL4D!OU7&US#8ct)p#_B;gfYc_;1?=&HxistX`S23PnlnN zOBjvHxKKcpAEGqQ4sh?L%uDj zr+R>{(9X*?V%$L_JiXFp;4G46^OZ~0Vo%=y8qhB<*LT?vQPLR3owBut^lep_7p`kv z+gpy-ZZs?lHg~r^=z}O(_iU2cQN)%Qkf66TcM3idFf;~A9BAyVOvgE*og=kyLY6nL z`csmC)l&G|w0BM`)LqWgT^AwgTvFd#Qp*+8`YAi=;l>TTr{48JPi`2u}X{06YcS zi=g(qab%|2X_i&2VeKz!vkP_ir@E3=F-JPioVBM# zotfjSc&uhRMu{xvS_=o~uvzDwKMPb-2uMGaT;f8*l)vke{#@H(2~4!77w#oD+G2QX zbDDRC<^x#C;U;}iB5{vk9fwnkWE`Efzvrh`^Zn=9j9Z6-K;xE ztm#!RG=k+;^{DR;67Pfvru+eflmP^Bh?G7(R=vWh#k+}U=f|yVGScra#|!z(*LtoK zsl6Ol{sHCu>Yz|W&j|E-HR>lb?U}{shm?|HH4IL5Tm_%!Gm9nfzNg4Oy6D!~D19ZY zNkVJMBTxlpek^T?0zi;^6J-w2eDzTYS_VDASXlqq7JsH{g6d|Etw&kECz#-#S>9>a zLg>Lx>pZ=gGH=C^fZ{{?fE#eh|J5bm;M>MdDkm;5mj$?|zy%j%$A~+O3`cW*Jfsej z0%~lF=nV0IHs#F%KoVgavcyFg4+`A$@v0;Mb>j z73wm6{^Z57yRXbmr9rrO^Ok)Tv+?y1_C+nI{PLjB>Ghj%>$X`%`>~Nl6qi!6?XQ9q zGzO~Q5Day!^I6y#IA^wI+j_l!1IM{d695<9=S;_y>`l${+NLU1w4vq)?w9TWEbf(& z^7uz$JJnUchL<0oKRNJ`GIIgb9bMK@AQPP(ehJja*KpJOs|oQ;-vq}LZp60w&zT7P zQflTH63R+`VuT^cLX{#EF8{-$4dhA(u3+l3^*vrTXN6;O^yt7=$ZR#v{*at~a2%O| za$a%w-~itgELSYlG97H9{Vq1s-=HTKnFpI%9B>NtBr84~3#yl@a_3P7 z9T_QFM8@9EBscV+xR0JP_zY=iIpFoiXC!sq?QV*~BM7Wfo=qO^f*=CQ4-NYaHMW|` zw~Cb+*xV>mpJ8)@oXAyS1A-<)tH7xzB#bM*IHWYhBb`~)LA|VHJEddS)t+Ks)3zsg z50C(?ZA`H%1jyhrNcn=PN%lVexuCH{>-x?f;Lvi*k&jIIS11p#Yz==soc7GH=t~=_ zq$uknsuXsS-6&%E&k-#{u=i}S$%v&5DQtSu7hw25-))0XE2C{F@^9!oIss9uO5MgM zna(zQZ|;Z@$LO$Veb1FC9N8DDN`YjCf7NievwMi%tRIZ{q<%6>elEy-!}bv{kI?;z zP1d(2E^~u7r3_x^3Jak)O)jFT?`h%{CG03{**Z4lY$fQ|nOj-d9Fz@4Zdb=l>o^!{ zFPyGd=C>001Z~A-e-Z8u&R!RW0=Bxq(|NS%E5=S#RPP=E-Ho zLL>tQvcBWs?`@z66xTUv{g;~ z)h{;i$9JUl3Nt2g#}30FD_$vb!3@QLj&8)hnL2H;c5nrd$GD6#RHSQlT6tJQp3~4pHFjx zIGv=yGgX|N8Y_Kt%LU*qq$O}h&hyLlI~C+IVJFFVO<}@gsiwNB=a6sQ@xPxq&kObt z<|8Vo>EgEi7c2;cs)6jm$c`VkQ2Lu7w1e31cJX(BbtY14z}MFKqloIAix3mS@wgvd zC2F}G6iD!~%y^1-JN`%cUG zkGS5jxktyQM(K(Xjm#oO2(PZY4tM8b)G(a6D>Rav2tr*%T&2lV^wlM@W;2?zU&HG! zs*%wkKy}O#p70#1D99~6C2uh-qHQ$P&`F((>PA-aSM>k%86ECujxGvV!4<`#%3>+=$0i;E`p?iHN(H6y-4E)D& z#DoRrG$OTU8@@A|OnxjdR9vsZ0IeUQZArbod2-Gt(~WaI8Rh~^?*yaqpD)Avh8Msk zCZ8+Crgm?)$$T_DD)>=t)RW70ls)jvkj*)$&ni@W)Hz!&y4`k5#jx z4uM2Ozxvk>3kQ17Q74573}%{(m*8ZPtrv0_AD%rC`f zU}M{;#>hTgY>K%?FD3(kj5?Q_1=lxeHa$zMg!g(y$9Cm3kA~Nxozm zC(4GM3J7*z=T{0Qb4Qa8&RJCQ0Z0i<$ler?1PeUwEj9Cs^gFio*&8OhF)R6(%}hrX z>JK_6o0+CH@D!*=C&A?D6B>UalmVRps4rXepre5d#b=6oQi{^_P=+Q=SkJswfw_$x zc44c|FQdZQryxJ%r}F*9T9QF37%VQ&R9O38xq}hNFjIjs zqv}dgGvE_U@wA{Ksn|WDUr6*R@_$=ET-%C=B_C6VY>c@CL*%Uv7Jwz1?N+m0l5WZV zVqFqi87o-;4N=Z>K=K0rWsg9l^R7)4kDuFTcxjf%@L4`$M!PrVQBJ%=Gu9G^=f2mT zx|vU1_z=QSnJ$26Q^4L?Bt$B2sVyI#ra_|U9jcRD8|5)xL+z|7+AqSn7Cp-O z${qr2L5#yy4^6tEM}((VL!d0&GS_f~M8)TvVpk8r5B~*Y&m5Vi%2$kr2BPN*f}`O> zf{;*NcW7iujqOWWHQ+P3b!_W51C1D6KQvH;DN}e!4$Tpf&N*FaQ?J)du{;dFc}M3) z)g>98l2C}ral(W#h?~S=YD~+WbgYd2x`~76yvMI40h&6kD+%7`yLLG4__Z48H$|p( zMnFG(Ob$T8!L@&A`i#^3zgXB6ufx(b*Z)dtfs`m)z;)h22IILL zC_(rKF%oSFGaNjlhrnDd`djK$4ZhGD_T2pzv(i%CJ*OMMJpaHlYqsFSn?$cHYF-LD z_OO2h!dj`tDRXGT*?7r?XjYAD{6<7eI;d5aZ23krqia#}@iyd11YdAA-gPcA2Cc8t z+2u)w73o{X65@rS+rPiq0dqbjb_^$rIgBlE7%tx5ehi-rHd>^5rbB%v~;V6L@qaw?`F263v+trIL*UG(0-| zVePS#Q7OeyJMMiTX`jK>F5yM`dq))cdW-MYU3YGnQ1r$eVkf=Nf7Pd3ize}!HgT>fSx1qAL_Y*OGezjW=S_L{1FT>W zTJATCt54Jq+ykIFB&cP-C-tsSJYpkn#O$gkoeeb2!3b(aE%CpC(t~hkACMg)MSdre z5s>;l8WI&6Gt@srxl0X6sgiR-$`_7odSFNTj}X}SA$V?ic^#KS{yzXiK)k9V>LX?EXR0)U!c1T^|b-6r_)RD4mX2bxwPlVFkLZmvV)2!(?* zwud589w&xH2*KZxG0GI*(gmPPru$5bLynLH-P9ZTEC4{+Dc#FGCNGziLGS`M=VoYW zDAlu*Vdq}p^)Z$%j13S>&Us7v8@U{$4n@{q-HlyipJP&s^op?goali2`v(wIF^tXc zGznXGK=0!?ue^m;e|!rIq~puld>d0`2LQqrOnf4@YaH+L z>#pdy!cB=r_3%Q569^*CA;Ad)w9D4cADLYsRPpT$YJruOF9lKf69e*GDwdDx_RSK} zmoG=^r7zh=NbNogwyxMHLL1R$v-1f1g?JwJe07jOfNXlsyIq^6tj<`RAJ0+fam&6ea>4xDgsST4$cHV~Po8O4p*XkLw5D_|8 zXn0#NLnNni65;4`v_lQxGKD8$rbznjbxJ}3q+iZBel(I|n5#N|BT_%?h+G^VbWiZ| zGjRl+v^eo}=h(L?PhQ^7YDo%!?WzU(HN>9LNO7`!5V4>Ut@@kGJt;{KPZ9fbI-gsO zFe-S0xm~nu1y2fxut{k;ajsd+)@=~8i8Ugvs<{KlZ_{1Mc1zUHNH0b@N6DTY#Z!wQ zM>n9+e65T42hn6}P;Rulk{J#M_{Uq)a81P&-_+Ws@$k~>t zieJaszdUkBg6@iCsw>&x1l<$}JRbdw^Z|_r{Uc6aya1nC35s3Zqq<}+7aSl1*u{`} zAp=P(WK3A#ia!;9W`0MFbDe|c*;&hg6$T3bcANv`ns{VXE2j3g4t7$x_DbGvxI9wey3&+LVGFu_)ij$>3Id(nxv1?hp_1x@4M40yW%RIiy z1!lQYX=5Fsva2s_%`ftC&2o~K3UQzY?V+&A0Yj^meGA^-(4X|#XAFvl{$$6JCw^jc zaMu13bW!^R%Lxi zvtw_9yHe+>YfQ_Q#$(}~t@iJMmrIq)Nc^9t#4?+;RO%#vqtZJ}wNY6Fqm4Y2#j*uV zxO?!h#3e@}&h|eUytm^yZ^41aU$#dN@spgnnmiHx8+w#yS&y_QHu|G?Ib}Kl^}q+@ zfKNt7)H!x$S67gsGn{*v`}Dy7P#>1P19X@G00AaFl{&`8|mzUmeARi;CUtLllCpy)0bOkHqUuTv*Zcptes}2T!@DJ5%E!TZkT`fc^B2 z2xX~oN_9Q@<<_=y>q_1XA8mUVdxp-xqb#MFu0J6o7SM10dVxUrgqtWn!z*CUZ?neQ zMe?q|l})KxIu|ZJz=?{-_bZV76K_8pP&&ea2k7#;r-)K$2?_kLrv|-(_=gQ7#4y|# zSL-NwzSA5~#&bi7L9QZ&Z){V}I%zK6^R`*Dc{B2$`DZy9Nj7u7O&;bnC~d}7RrUn( z-`##1wtC&FnLq4e`djljuVr-Z9 z8I?ILp-(QcnN6B3hfC8p@`NQ;fa-H5v6d4FJ#lP}N;`vhMK^s zi==`&-MA#H6p>`zYe-TebGLSa-HqQ=PrqF!+4jeEkCPS5jVgq`68nXr`}POZObV4<)l;Q2{`Wp-u|tw#0ud}CncGP!2f_*|SP z-rCYegh0msT|?Og#qWvy%8gUz4IsYNj;Bbpc^Y}l451{+LOfs9v^M%jc z6CaYzMlAOVD6l$cGlB7l395Saaxy)X5|wwY>G*rYq>gmmpfqL(G(pwzYY{$Q zF*b{dmx1m{R8(n9EPG(De6_a$l%nTU>L-rZpwqJrcm#w={wN_j^gE*&KOLb$WJ0}X ztd&;+=6(?{Ea_sDdhRIn8m`1B=ZlB{kDT~UCQyYFyemh9RoS(l4y*P{bq;8zF!LH3 zhuPRSgh`daoqK^fv-ko`09b{F?!8F35{=g$I~pfo^I@>am2yHLPTByUpmdIZk@s29 zvkQWr3fkU^jpY0bq*F?U1;5i@XCUZrKb%mD0L}5nbjK@GT?Ud!2aF+9*YZG^+NM*u z{8(TqC{u)j>_<%Ak?f$+#PJTL4#v_&u#UtJa0pGHfIG%HF?)4`0(xqH?XP}x+1^$q zcEE66ka$6%(F}(leQ_}JBalr?yEKZTg(pr_>sYUixb}rqJ&^*O+~mB7DT%Nb7t;s zj%9vWKSj`WmJZf!J#Fv=NRg>^8PXuG8CkHy9G<<%tQwjt(J*E$AO_Li?C=SoZO^?-+O$H$}IZ=_qLe)m8TbP>3Qh;sSEfWJ>E z)MJi5l1dXEb+NA~uLL;NyI*1}Kp)G>&XcqXJ+=NO2xTT29$G=&T0;K9NAHx5zeXn8 ziK+-IZduHozQSP;CkxvGfjk(Ug#&VY3hnPpvfPy5v#fmX3oYCBaX394n0M~f!7EFV zp<=7=1yYrW-mg64s)UkDA#n!Wt)3@@yF~+EhUfwg68rm{0Iv}qT79ywH&RM3LaibxO~^Z#f>K zdLoz}aY^vgI*<-!`IrC$7*q^a&G=-cpb5CBI^20a6EIE7{mFpgmQpA4$2Mpl)X1ao zVyx525(F>)-&HKi79=M#iW#Iq#&P(Q)0oWntSVN|tqm1_vc-_`h0a%q2&m}6lI)8| zIr!PrU!{C#;-68;CV{;|UMKQxJLK>{W~ulZw=Q9-ESIj-z66i}05P9dREBJpgSP@2 z53@e#x$l9dA!;9e@JRBamReuIZ>DmGPIeBXZ)y39V)m)z|~0h-UuaFu=w~ zNl<_=1OBt1sZ(pwg_D^5Rr5JyOE+VYE$uTfTvv^X>}g%%BZH05N(m9c#{{?ZrFc8{ z5e!gVX$j419jC(gtVGF18ZFT^_OK9>?Wkp-ALB?V)V1&o3%mZc*l z&-Y>I5>aO*WZCm5h>>gCzO6L`LWeg@X>F4o1Oz8&qy^-3orUv6H_#MK3wbT=Q*0aB z$@|wR(4DGT2cQ@tFRF=OD^At9^*%rx9vx%=#agYUUMhy7bzMxE=#&+2(77t~pYh8) zU?{j=M~*-tShT z-v+XGWBFj*o>s>E`SWG=so9#_K%X^95Q4hm8fCr4bR<>wzYj&F&|7nivSPaHjv~(^ z7qEN%vU?lWW4~%9?ljA!@IiMyI0i{;$cjBK^SWbbpvEw(p zTAK?G3f>D8aFW0@E3IKNoOGFJCCHK}7GaO076mM`U&$kxb6UDIaw-@eV{~yPvJTaR&M~RV!G4CMCpcH(HnvSybug4K zz+Qo|8|IU0z+}__00aiY>&CN!eq+@3tRU|@I@@!t7)|!H=a>X5Yox@yHS<}1jtJKQ zF-Q()I&!Cy9fu#ei6U5=HkP%_<6zW+pE!TswpjQ})~u*L$Uoq^sR1p9B3Bfk4S4A)RZ$p(Q3 z+nI%!j*>#kWy>dW*$%XH+Pa5quLu)$RbpxsF<3S%(6zgMN>uj9XOp$BUalCh5j$Tn zMTVdK`MBVcJL26)%jgileQ-`eDg-`-;W~cD>DKe%QSdONhhJ@;y90TZb>-Tx7DNFj zi=UEd-i>ZIZEPm_BdCnR#Cxj`K1!;eiM#f3aK)SLFn=QO>sEpI3JuV5%fP<0T(wFkiaqZm_!VpHXVYVa7_;J)J09kyC?o+|>d z*^OllKst?(7OB1H0008x3I}eKVWDs9%2QX{(U$Zxam~B`qYi+pOtWF3)JwFBD$m4m zP|^$q$5iAe;$gZ2DdHuhFY zfxSKQGj{pgW-&J?8eumgOV8b^Qd)!^i@1xKyKJ(DBQhZM(q{^E&>N2MLco@KV zlZ(0#w3~CH&`6W()X})CaeJ4GJ;tDvGub$;)|&jsT19rSNJI+(te6RjW8sjWSnBL# z{PEUCt`@*&>Ey#>{SPjFJj8Qc#CAvw_qMVXdwBf^N8S8)1+d>YkPbIZ5sEgR?(Ert z&K2duk=RP)(TIoRbVLmGAoJ$b2~f+hLozg6pmPC=6ZY*LP#YCn@ zm*VzC=LU{}SW#w~0xrpDXG(|JI&!|&3GzZBXr}0Lhqx2Evt4f37QBHjgUF)70mi!i}e-k5AT__eJT0ZF{F zGJy-Fie2T%6AN@TvrwRf`~glR@x1Kdfy4Rjbi4egP*#`}as5a>MaKd}kKfPo+j1s! z-+@lua@J0&+FglNeE#5R+>+x|r9hLA`9l_Q%TMlg>fCaMPL>gT&0)J@MUhJD&=kLo z3u2>}E+qT5Ni@cki0w#6T35wXc_X~C7EL3Y^@@0@?z9x{!aQs}FKLf_x8}-+G2KVX zkCd1R3zbSH@-V3hGhLz%wROBcsmFW@CJ|$g@XRS?)q*#`bmzzTj5`#wc)w{Dv!NMj zOUBt2jRSvjxew94#PIG+LW`kK(vOgSL&_vMGYhO&TYl5ZE&A%b`2}pudeuCKU4PNf zB5UKLF+4xFphsKkgIs}^z5bl}VF> z(fwr3B%6n?3_zdbUj=G8#7*yb4%)g`tz>&soe(==B$B}nBumMYFkrCgZj zTO&CRkD4gx8^$x_J@H(>Q_-~s&q}n+>6W+TQX^vy;voSxFiQSd<7iKfl-B< zn$z~Ll!VJErL9?^5by@jbUIo_Qdb1a8P&gP!*@**CIA=I0A`=e{U)9ZhKE`|&1$0e zouxk)c+8nh?#`xJiYEY{L1v<6o%LDhcg0T;_*f~;Pu3>^ok?f(rn{(2xaCh@mrUwK zZdWDZq45bugaRekLV!s9a3%`KbdGJ9!}gtmW~!+ZSEurGnikT6spHLWcz4pYO^_q# z@gDbCI#D1XfZ|-8ImQ+aD-V*5a}o()FErDK-T8UBgHhZBzLBf(&+tEIoTPxP+)b5e z6SAl|*nM&RcGY!a`)rXz&HivJGH^}Y`C2L$eC z&gdu|jQku@!iO+bnI@Bz)LG%2#kY_kr=I~%a4Wes8QvhM?2!=lSco_GeGf-QPq#V- z&=j*c&Q~UDH~IGHzG5wI>B)UO?1eywiy#!#Jfj;#|cS6!@9DYD#K> z=*@oU)~yoqsl_yMM{xsr+g>JNOY5*S7yAu-fn`DHUTfe-XcdnL_84pQmG5l zt}JexC^7P;mQ(gemUakCc_|IPQNlE^%;Q_n&`2yi@dsRGF?dt6LF%6f8LOT+DWPO! z*-jrHQ4RTf!y7n&kebwPZLPP1W5_4_PQFqd+%ZWja)zIbsp=}C>av#vDyY-RaNdHJ zoHYDfl|I}TD0*!faF%GBWrcmw3sMDvaYfWnjd;Wq{WHR(uR-K$pQM*gJzSe-yac193QOmm-4v%7{@&bKgA1`BR3wmMb7nW z=IIAvD2sBTP<1)Ddq&hpl2vUpGxd2eJT(R@#00{y7Mb$S$n$#YgXJaIxN50;+?F8c~+LV#i^wL@583?@MhBAHAY zFhkxXHdatPMP3T~m*z}Ok$7b?O7}KZjKN~9Y%ZF6ACCt*E%h=q5VvyOEn`Vk9uR7V z4ilVPa(1GHOn&L@zDLJ3?!sLkdeA~^gE>$| zKWTBb!={R%R<6ZO@mgZZ#%|nm3Pi-s)RU4R004W~_dD}gHs&gj=y}nXxcW20Tg~^55}%|UMYXcRr2avoTS3U|HzOQ@cvR12WGjJc1F%#KBcm99Lf%zD zREZl51|a3OfM%oW*Kg1`+x2B(y?{3`?uPX`UMts4Cz!DU3%qNMrCGr_yzGK>gKGWy z4@wRyb?lgFz$WqVK3vFoU)Qk!!S!RVd9(MR?NsB#t;iQ*l8FPo87N*;jI|>{>pVCN z99m7c7x^lS=Tl+P_t|PX$3Q#_H~4KXu0O>ziy*30JaXVgz?erh6D}7D?pmE7PA%U8 za4bQn>yfS~<)|ATm`OtUC$Y2XJprGfMm5i%FDE3t+9bh@xi}$hHP`j%`ZfVKg2L1Q zK&wmCE<;w@X>_E}eP-aV_W=N_W%Vj%2w)j@M*<^ZnakMhhM9agBh?=+cvd#Irv4iFMP+XxXibB@2RRTpO)_4MxqS| z&Hs?drgU66WYG}u0LvklYQ&;`Ynb~bZVSW!U@K@3sJ7ejU(hs!uAY?ZlHzSxQ1<9{ z7LuX~CN`(Li=GFYR^hXHf5Q}cf1(Z#q>#|*C6z|9Mq0+HDSAKb0qnLCEgP6Z|ILA&R>UxeLEY)&xHKytfTu%fEP%}{AeKcCRJZC2i0p!{{^|&6GZ$5yDN+(N z-wT9Vs(vj=7zKgjgnbhycfCp2F@HqZ_gkW;=-q~5F}La@utE=Kl&Ra}n`ifR}i<}tEC7wkZ?mQG-*!Mt~vHa(Rf8$EE%h6w1HX{z$%!F-y_dstd#Wf- z=|hg0GK}?0_Pwr5t5g{MIxGKfuyGW@J1Y`XR_NxZ$k9tL#1m%G{rP;ZjIUFM4d1*E zO>$>p%U%-ZM9EEwg|7$>((bINgvg=JUUW%A!})b@9$n&@oq!ai)+{fX%(iaO@>SQY z4g(ITH*};?8T=57B|hlIS0ABvbBZ4a*<+-7>w%sXmst<~miDcR4i&1qR~>922$v<` zI|_{#vL@&c^t`DpUbvJ10013nGVgEqQT}w2351kko3bo^o|H-`v#C0>W0ZG zpu-xPfKAYMnG1;3&0tk6>sWvh+G=^cit6dP#N-27**R(QPXO9;cpK$lW2dcpdzg=> zI^01xvb^WO zWpTkM#SlCX+QVa53MYV3m_n0uI>_;uDmI@^xbFn=NPJrw;a;Rkfr2Qc$ESr?MGKh* zw$sEID z0d2MN&GZ1`DlAiSI~L-1cLbM0Nz>6Ci%OVpbx7`8$mUPxgP@e=4NSKH!hu|PC6UBK zU_pkIzwXX$+Y9D0D}9 z5+`TO2_Ed);r{Koy*Yt5qg8y?*l&#K@~^8Vd<9bf%GkoL-H@`0uz}i{U02u43~FJB-AhTQm*nsY$5;`)wAM&<6;~m6MDv zACT;1c%p&N02HO(7NAsymVXc%sCfh|Q3$$O=J+v6qZy^555t@yRRibol-U3R5!K73 zlOT`8I^!ZLPCnQWzK<<87*F^UK|M|y>7c1Bpu9T z=Mk0{lf>mMn|Y!F(UNPllXiW30O}X7v%4=**KYP)GCVJWlVE&!uD%Tx`a}6O;=c%u zrfIQvF8>~^B<2299<{*1|I{}Dzb7>dK>va3NFc=g{X*;{%rIy)=2!IXFN_Id(X^^Z z8d8WinwEdMzbP@hGpt__!!mA7%NmqOM$#v4*~s5?{6B=`J_`;|_fEE9nkKX3hnA;T z+nMVq-?Jy^5$tpEvO`7c()D)O_pzJ0?P~aNLX&OSNO2|v&W$@9(Q9;!7S_Eaj=lv z*l_Bev(R2vq=fW(jM`C~&VJc*GebaD1RCDr_AVmIEc?*tWj$;1&AEcG8|V%?gag#} z$ocxNn*B+E836J&&41Q8Xrt0pr|DTy-~O0p7C}Si+R0b=YM*f3dF6%yb^Lt^4 zAsphK!#{N0Z#I(cirBH22HGSHHrR#iEwUW@OVHA#xl6}Z1(V`Ei*008OFy?8o^_ik zC1QHq2TdS+WMB8v4MQ~Ts=*b+BvMB{0o@%nY)c73=fhx2n)9UD&j9m150`>kPa4Go z$|C60ltRt`1I_(FE%yo_M7$F4Qr8bkLJ>A!&v<=wY`{o})UUjWvXAG@P%X z^LWEAPflRoqD7H=_*~5<%<%BFEywE$9VZmWaHX&XMg7ck zeq(YgSd1^hYp$aMRIQ@70Ufc6>g;GAfnUhzug&=$Q7V3_yfI&Yl4cUFYI)(hKfK}ZBVtpG}^iQ!10)=HNp8I4%P5GJA-BNyb=Q70I6OQj8h1y8~|l+iR~Bnomr^(MS73bhFkBJbk?1l z!9wKfWtLHe5aLb)R~~3hM--c88zEM?RG6o-!@`Yw@Mz?p6T~GY_*{_;>gb~%X}qs= zG(iVd>lu5L#9dKu-HSow3UMRRgHif`U!E=f$l!EDc_U>3sq+8db;_Amn~?QSwZ0jZ`g(zV(g-z~Brm&XT5 zhxqHsM6*Rue3xB z^N~Q_jlKt1Q^SbE`MV0p?Bc{TUO57_i0|{9@;dsSYmB zAZnAn*q_YnZ$JOa#Ey}=*`N)16UHG_onriBR_#qw>onioN3T_+r!?&7@&9zSM}YHy zN^DWMbfD2+Z{3L0$DY@f$pmFC3@(iyHBOi+dh{Fn3 zMcTcVMDJ4wjaUw8usah+JoocQt&gR6wzaaNyQC)RINC7O|BL>a?_TK?TauXngc(b3 zXLC?1wIs zGFEglY(cqK$+fEbwg}yH5?6Zu;X2JuzIiL?otzz~%~WGN6htiaVHs}_MqVxIJa=%D zj;qV}V&Yhpm=p|Kb{5e66?{#|xj1)eFFCWHM)>stROB{0f%77b=x{{ZWQfEm{Cs-0X7n}WBx## zK6p{@r>mgME>sz-_ZIH(hrfVWjY4-(ELZuDiS<(a^AIH_P&9CMS1+%~V}#u_K^Ex^ z%8@BFrh@SqJphgcuPMA2GBU-A7ykR;PSOp;#AuCGci z-N>cR4+&LJUBcb4hW#FjS9IY+gWyvy`UcHIFkA;MY04 za!5()+Z|-97aojL`XZqzJ?pduW_aa-J5{1yHYYA2Qfz2@>c!bM4DM5!{!CIyDbh4o zFV^T?q~CX2VONJ1Z|`h9v{~NqM!gQ3sN)r=&VgURoBB2Oa68WF{|-u5(W!&$5PWv7 zI{D5L11R;BrtQrN#Q4Lhtqtah_N_U#>{2qX1;T^%6ZMxIcPobDgnMp%s5Ge*ZSO(F z<9{2(cDfPizIaNDbMN?Tff^HtDzCqXYB^j*yOvBY1*-cQ3Rif8b(2@K88{UF<|9pnCwB44HO8%bKBvfkx56!Nf< zY4EsMULkE z6pjav7BVy7tzMmA*Rdy;RW033L@c-mB=xQUtqqsuMafN zDI5o2jiUT+xW3&(se)DcBy#Owid?$Ioc194^x%4sA@Rf-&xc{;7%c`mxt7(IXfNcU zY{+~GSU7Sh5Gdz=5~LYf5P$%lFTfL@BP4lB1`EB`zR&JDC6S(SWOf4wcl(%6dGE!6 zgulOSNq#*Qr1Tj}XbY?az4*gD4jFm|I&F-{QQlh}mG|x91z@`1nf3=x_I!R=1yBJ} zf>_xt;3F(6r{Mpb?6(*+kyGpQl!__g7L>|rFuZqu2Hqd>kzQE%ctWHzgh6wE)D5Sk9r3GrNNi zi3Y3x#;mH^D)n-ZMWe??IVI60+R1bfj>HCi1eh2Oj>y+zGi|(W8;u1&{uY)yNOYqw zPHDm3%aw$Rqo-2(u~u>YIc*(jMaMLz|`SLX1AC@m^zI(l!>jnRz_KP1VYXN zu58QWr3gphLeFxI@LfvfgdOuW0|~4D@6w`ha_y`mBM9PJwl;HE8n2<1;j#QL z9Fhb#)xW)ELM3?PF-nc;7+l5vtXKrH=L&^+CPW$VS(#QczURRJ{2!s#3wSaJlKK4n z4$aA}+g4sMG+z(5l3nzx9u}k|o7sc2Y(;7Sf~vRIls0DupH4jsDTNOHvNc%qo_Pke z_*)E&m8uw>9GK)r8H8_C^d8_biplh|VKG$YtN%r(47}H)xO*RlBu1=6E+%XI$H#Wv%$|5(W_~M8ij>5zC!bQ)ZQH@ znZY33Ic_ZXQ2or1A;cY=A`HBNcKTxV*smjD&5dY6pyElyVIN=9oV#hvZKh3uE806DW zDI!#t-}3~f73NW8-YqQ3h%!Ng4NT1kJ%wn-i|}2^&1l+}dm}3X;pGkg_ZJ{v7;wkl z&zg_D5I4bTg^)v=*FFd_x~GZS15x*aT#UAd!w+5G<={m}v!*m!@3IMqeHL2{Zofmp zcV%Kmxnlb|1yL{o0hx-T*|s&m`rn$ANa)O8)Jv~fY6&j5O~1L-WE|TLN5kOyNT}Q1 zB7{hwR(H8Ub~2Q-u5jN&Emzq*PEm66P22E66VZ&bRoVN=d5&MNU0xE%^8D;)c z4P8XRZ;g|^A<#FJj@z>a`pK+!to}z2hwUh@UI2j*3v4$EoO8W&phhs^S$ubL1eH~J zK+PO#j;RnvYr*591+EvLKseiiI-*HqhmB9D6YxJrMn*=!k9P`k0N4suflxn z1;!twBKsp%Pju^}gml-L^oEOl$X8jD4|BhvNV}P%79s2(QIEjZK_HssU=zYo4)b~` z-x{Ss1qw&Mifrhw>Oa0%=$CF!0CEf)b7y7$M?frJnNm%L$VMm%?uIsP;DX&mlR$H% z6a%+h{>PicOrJw}qoB&u^H=A6jhpS|qrRI)N-czWIICIn3SmP2fj(}$tjCh~_va-R zfgE4sj@Yk9uXK9DV1yXx#;U)s*h0C#00#qd!FSEFf)@@JLXD`;TJ=$NtFo^HI}*9{ zcjQsTuh(J?Uyf*rL8ei_OO^+gNVx&n$E@s{-VD4bLa%pM zdAkH3z=AQwq2_~&8ybCDG#TA2*jA*d{cYVvh*y{i#$Xy6Ef?DHepys0#ly9 z1x$Dd1UOc7WatSZG%hD4GN1>p4T#P2%CSBcJ=4wiL{j@6^n-l_;a!!1QqYb7T$S#U z-zPS+LRWt=aod3o8mG9XO!cKZE_ZerHd+NXxr{=AKHY$np%W=@P}V9{NU~Su5IabGTv-ztY(mA+4Css*e*G!;V@hrSDxnmQ2Axb!eez{s=Q)IynwAqmc$thg z9DV&w=Lq|5K)fDo9i|m$8#oCcjN&jkq+Ix6#+kTS>0OP%J*?Ud0Xh-w4OlK(} z{te?yuiuY>eJDI@C?hV)N&SHP%4qd4Mk%aTO+9{&3BSN|uJzJvo>SSXFu8@wgo@`& zJ|bmu49b&v#;M)>SMzlQ?EAdwd!a;)O^L|30j z*q-q*%EDHvqOmrV(=X!WH-9)Vs!qBJAo5?N!94a%>t9g{m`EDk z%~YM|E7Ds4Q6CRxVW2xWDJ;A-*Z7mSA1{@$ply^w8~J3@0Ba72cKV&b z59wL=W-_(vg%?x{O7|wKXd;uKoE=j5 zn-ry*%66N?{oA)M!1R=W5S^Y#JrxStpGoWgj5Xb+4&$+VOrS5~gC=^__CWT?COad^ z!69?He==oD)IJ}esvG~Bd2C*6KouMrE!G+ z2szqAqW&yBsFn$=&Y2$RoIKxmhudE`iruKDt0V#JMJ6eP3TJA;3#&}UoX(-F_j-uW z7MfL?#Sc(RBpph!n^q1$O!U3%Hjuiehz|5C4GE{>y9K`ebh45(8*zSIBw^}$MbU%>?XR3QzCaFpw ziTd%?FAHt7RdCfn`ML+u+nn8^iV?zL7NV3FxTpX;BE-@hCx_Ud@+Q8U%mFofael{W}=Wrg<9C2a!BcbgE$t?QL63UI&8`nB}6RfFgFbr z{_;Lvx&Fww{8akszAiNe%CI}#Aiyq9xv)zc04^UbGGQ-N$XeD`=O?5xUJeypr0jq% z$q*i{1jfKyt>UDY{HNG72&kn*ad!TBDxFNLyG{tpV^XQv2g3gv+j$ax0gNzeRb?_n zMdWEc?-yrk9B=h3WdV_~g*st@9k)Hh#u}^Ls{O$z2txYj>uThpT##+es(FRXEcBmG6W9{rM6@U3K;A1D=RlY`Ls-IJ#N}WgQClW_z-}wplamRq{el0XphBgzH+fO-FZWf$Z zZ?)~e6uS=9Gc!+igZ2NSZS)cDMkwcCyB&kvn5lVD8=n25{8@~Jn~a?TS!Sse&5edFCl7czq5}KXxa5B3mI>2Z@UtRvJLTy;b=mY8@CjOPcUm`t^*p7c_*$BTSWl z?43L{`Jg@}v^jA&B9}t3IhRe5GBEcvaJ`9lezpW-i^8LS^3I&Pv$L7zgh}?Tfup}@BaDE(ps7R?ZwYb1^PUFoIP5I(ay0Ih?m+73r8 zrx0lVCSm^%82);%O!Ng^KwUW+qLAL(QPH8#p|51>@w#jqKVi~r&%yrv=Ey-D9&l1= zQlGmXS0)S1Ee@k(N>x1p#PMpmlWxc?(Gz7SLa-w9tUoe%FvgJWjDa0=h3PW0s#iR^ zAn7(?_ky8xOa>atNto^Vm2H9siVpxTBuFQ6tws&LJ~T-XrHqKKiL4fnH6}KWX^!|E z@4&Oz;_AN9x!^g33bD0O1!S-ntqEASth9BMFL!#0#R(vot&*#6 z=rKl6e+$ieL%CgQ!J!J(uzCP~ygtf%j|60_;6W336U{LU+p zo9XxR(^isqi_um1YM>hIU#fR5tpwTjT#o}d*<@kL-Bhk0Xmff{pg*>2XhX@$)~9#; z0`-$Jb^4kUK6j$g$ga+(*0^LJ;c=>aQhM7#LxApTg^hpTT>I5|y3AnhAC&a5ry0pK zO_lXYc{7jD=mjTO{(FJT291D6$qs`Vqgmao6?`Ba_psk!LKg3IOx#IyS^D7F;7ko@ z?-`q#1`22L7dP6VY2^XjJtM;LuijQhjxp>v{)!jm9(A{jZz7+?++A1JVSq);S2hvZ zOo#cb2myA4``XYIq@|R3o@imSo?Yq$1~|X_DWg2yJk>|bfrMz{D?M5LjlECdiKD1J zB;b0pnfZY+gT*RFoJ8iQr?x+AG7^nY!<7$AQk%4+wX;*Uelwa8g}u5n^A9GnA|Lo7 z3OLLzV@YE46>~|wj5s#uGRzq`lC#^x8g~xNMOK&Hr~A|`Hfz?U8!}lzLt>!1@Nf5d z3^xEZ`4x8%09mV2+V=a!>w`7F**4{B~_aMm!wO z%cU?tVgUhUy{)^8==^CVY@PEpE-Es|^-yQF;jih^!3@b%31c!IcCc=P$AZ{| z2P8=5bP5R^YMQ}5FN!LF3^lILjpH%teJ(0NdxJrE$maelPX=^f<&2wBLA29zya^No28A3k!%@~=Ai^ApdfF4j71$(>ZJ4S0r_ zLn2~R=p5A36uh-eqNxN>@DdVhUnbyUVo<5^s~-fZ7++skRUlewVa64|8ebw<{;UXy z7j8<>n2Gm@rXLB}$XL-!P{a~0YV7i%dY7@~7LGe>fRdjRs6CjEY}MM~s{<_YJMcjvH=8FBTijIlk_9eOy2~_wVHr9! z=Z&wzcmpge|GT&<$r z&{70fR5YmNuQ*+|1~p)(k#5X4Gpj$s6+ETeOB(4!7I?Q7Qpf?kvD}n_=4Wb#+W!lj zx@G^hu8;NMlIVo3;#&_IXUf;oD1BBl759DtlgHuWTCRlI1Yg>!>*%k1ar26YKC#>4 zT97LhA|4p(+psm=fyuhhDzB*pTQL)o6+ExiQr^Pk9T8fJps5p7`rVo=W#F6lE27Xw z^#$oxdYbZZw?5Q7%_4;xeZ_Qhk=m8Kb4D{*_kywJUtIpI0)ai>0*bhy9gzmKy9=7$r&BPjY1}v;adP zHO*f10211k#}Mv0`F`8af-uSOY43{=dA71TMZCjZA+hO%-u)zQ9A|xyIp63aX(Ohqojq0+ZK2M=6IkcYR@ME~T9 zq1oY|J%DAO=%c%y6qZu(do+Yi(g|974b+PPWXl0j+ zAJG|txF})O0@qWaIU#K7_j(2s+uJ!J)=;}+$YUc^x+OH1xkWKQh)-&^!OS(@-g<%< zUJd&z;{a+7KYF^hB=X-98V#-bneR$`Qt@=z(K9|m(TkDah^3PpzS%v}wO*?Mtc9k3 zNlUZXSg;H!Q1U|iaN0{;dKZsYE);l69VF5H>%d!{SFR@Hk8W@4H-_3~N#}4;CJr4Z zG*XC`_t{jY%eshcw;Y}^5$*e5tHF-}o}vv}Uwd&6$k#&*N>?`(rzbXGpfDwd;f;ix734}h^#g=i4Oa@A&SvgWA(&dau(d;P{x%=>Fm+_R?q7OJor}C#$3|@3f z&VpD#;&nD1x>pTDuzaEF5A%Z4MP{&H)WIMXaMR+R7=e8Bol&x?;qU6cJ5iQVRsnJqLnxo}f$-!_DCknQVwUzT%>ocmW``G1ewFV~NuYCq-DJ zvgUPDg>Uk33QJ9#E2wak<3o9`)|eM?pdUqagW=XNdxc&9K{G8KqrsCG&y8eALih|R zrBU*+P${71dMWQz##%3R=bFlzthiEQGByd>ZXqyP8Eb&miWk;vxh>YAI?!}S9rY7m zRqfGz3lWt>g3Z9zV<#|;R7OJs>t9w0WLJ_PUI6ihWK$#mH4~F<0T!k&Oj>3&RO-RO zva}JxuLNA~_v@K^aN__?lbXfoaB7q~I4JUAM<*W`@Rey4+D#cJkypHvpLrTDvc7WK z$N3hjod3XtatvqjDHq_pk}p6@$K!vogEDP@?Rip3JbIPS9kn_0tiHZGilfu+JZ4hJ zE!2u}E8opv{YV6+Yo|-Aq8LKtocu^TT%!xC)y-uH8HWMDa{0Y{)b6XdciSy-Yq^&P zS!AnYlEvW7>pn+{+pK^z4*=fbxx}s<*=*2gl3;%uSU{k$V47pLeftE@w?;P*E~kbt zgMkuGwrgDvqh)QSsNVw}iimqP-6L}jVPc(+bX=gdlJ6DIXC|C6a z`VpYm)F!%Z0Gc=8se)(RM$MFF{2P`)OW%Nd?(F0QaYi`hRgns(EP$yfd*|aS&>ftT ze}W!~Z?*5qdp^~7AnC~dxN6n@5$a=z@-aac9`;)g`pA0@$;))i^I*ls!<4NHFe}v^ zJ+xkr#kcA)uqn4)(bn86In@%oy5jsX`4aP|q4mUiIBp-%mF&Z*=vpi87BXoDEHNxe z0Mz{9^5Y{$6NtQi02_`0f_c@pxvRa5%!2E8J+^`6uH>@a#vqak7f;_rul8s4rYzFf z;sL1HkuN%A6^I?SbA@?6!05l4=TS>@{Aw~PnU;qb!o^@j4DW3U!~xC3-{5=CDX~cV zd!&chITWcqm%mriP?F$l14f{d2GQ^4BqV|AA8vD&ppX$f#tIl? z>si^{$xv^15h17VcYIgEwnnL}h5=z1f!5GjrY!O!;0R?hi-? zRz?-iwst!RPy%weqV#OE$ia8xh}j&_)Z>~TdgW!H-Q4E*?+UlnYAzNzmzbrmoFV2w zECH&xTjT`0?igiS1sw5NZxdd!#Ld@0C`%s3dTG&L)Ow5SxVF~L7$S2);dd-~ z{;Euqja4M8)_{^^SEQ=KVGhENds-=BpI%|UN-0v-U%z@(CbSBZP=g5pxblY)Tj>T3 zn@s5?`2Dwk6POaLHuti!tp0qz+wPPI%-i8$06Ejf>ATF-2KE$P9m8Sk;g~rA7Z6p$ z&z(bi5%yt6YZPZBJ_FVz$2-=C?;^)5Nd7wLuMBE|6CJbuPJtuSrAb+pWIxY1TdPzQd@z0i~3Ng@M!@8@(zqoG6ET(=jJbbY**e z8&SP9JoC+DTV;Nw*X5B{ky8)DX08#8{9vdRZ`RhiqOqro?UU>^C~_vMe?no(k>k-1 zVum=)1nyoHXiBD0xn>KzJ33X93+wehU#zWFY{?Y@v=h_8Mx1ZLhO1!xgKc8BEeI%# zIC+8&Hucy(Xc5q)b#>k!#&;g<1^|VQK*ibXPTM`XA$-s3VRQnX9$>NiilDk?dlEX7BCSS)ah zZ{H|VsGyAZ7*R4)e3E?q6@?Qi<(n(G3O@EGPz+Fbq-fZVU55JWv7T@T|7+TL3ubcM zA^$D{E5(H*1}WeC3@sKeiG0eN0c+p-SV3mB(%V@4GLzKPcx)tq$L>EhX_vp6kjk1x zS0Ar3bFjf_BI)g<5&Im0c@7L1#`H3hhIy8F!Xd${qMX)oeAkBzo$7nd!gx~; zlqJ>my&u7qxd}Ms-^R&N*w~N!ky_kV+ zWP><6==QV#BTO=1m5R?+?^%3cAEdA{ZlfT8R2#T67P-_Uz6Zj9iKHf)*#FH-j6eu! zmT=?j2(hZ+ch%owBCod6mTTO3kMzMrsiuhpxi#vthA@o>58_FUq0K*-%oPX&;!rxF zvxbzVOGwVh-q=O6N7v8l_a5+5oCN$Cgyp_6+DPO7jH~-WZ4ui!8h0VMm$?^Z+H#_k z4pcT7QgQeRD+q=1eyb|VeB!8`wDQiHWObDyS6lML1INyeG~A0`G@P8ye}Qa3gFxua zF)|(!6~&FN1y6+zvnkHI38@Js_W8cN>s>p>gCjM;;Hi9CI``9FAQ4%-2E)je?W$r* zo;ac^qfo0i4zSp}l3p(^8Zl8Li})*FT1*6ch>wU|`G{dr^sblXUOCIqDN$uuFujZ< zVDb(LjXWDKnz_T*Kte`EvvOjG6_qucRFx}Ew<#82n`p+Cql-cNe;qdpmOnSk4dO10VOG24|i%s6O%BQu#Fpp9X@{?_lumJdSe#@tBXq$6PuLQ3YIWK3n|>XSV(- zbl}ixHdv3k_$cpRM_7@b(68UR6eOh1<%WI33!DYTA%T;$&$3PPcL2iGbKaHTI?-t+ z?PFja??jGiKzsoI@%3UFGLYtg()1pidS?`%whslE38Vm)O7c#K37?n zvO76|Q&9lix1Lo5)&_%{VO~@Hd*i&|Ac`$(4w%wyi9h|Fo}I<}+(3=I`r$~&HfM`D zAqNsK2o!>c!nyt=Lch&z9WwM2?;Z*FB4iiStVYH0);(|XM{xr<=}i`Jdm51QcMp99@im0 z3O;eB%`&edjE<)A@M0oTy>OU$xTSViPmRHQzpGU5-7oIx<;4O`K+RyK!rABbbsRj{ z#+5i17FTGK-CVHspEmc}^z{!17@sKj^SmTMabHH<;TR3*T|c2g2)K zU}T)!TJo>kXW;o|ze6QjBLNQ=17nKv41>Y0&xMhV9t1OCjj8h`e5Ba$Mx}nT5)LRr zgnql&gThfFSbf|Zm#b%2NY&*=Jrt#oa?y|lFyB;#3GHFG?Uvo#N9of_!_=A_wyUBS zSC=*}$NbS**e3L69PRpw6xON^2>Xl*gWQ#+Bmv(+8dV659g83FdqeOT++AD3w zM|-T|)n4O{oN*gQ-OQ2qx>hoUBH9h>e_=6Hif&7}G6DGpveW->zCt$DJMoVW{*V#Glfcvce0F z25J;OYD_WO@Qfz0EQvR?5ik`T3$+R;(2o9n)37SuiK zeR))L9-TQqQ0X{rHx#n*Mb(b2z<6+MBe@fCo3N)gmrZ}%HyK{5N(IphABDl3IGUOa;kkxRpVlS$rUj_#x-0kk z!H9NKNkYYLe#S2241s#9i8T`u-*Wq9E4pDukqwQgo~CFfP0?v3!^CpMx;IMWLuScz zH8JExN_H*s0A_{EBJyCEm76t>L+S(W$6oNJgs!#%DSV3%f|6q8IP|ujpfHw$$z=9S z$CvJB zoB2`XPAXHTu-rnVQw=@E5{RtXbPpB$tE#vI&n&$mrwA5L(-E@?ga}H|=JAAGnJiNH zMTYWt&x;pjZ@FF{ZcFG>g89=O#7m>V)E_`PDN`4PiA7B1oXB>oqdI_I)hH*=vcrf1cil<@MBMO8>Y>p*wfn9=o2< zsP(gnTndRp2l;Qlq7K*_+;ROrpf`!s6yD~xy6~^9@ISN`$m0jfBwZL|Sz1^>pyefZ zlY)mItW^-|b-F%4a1HEiDtJpVmlwyZ1YB#LOYM5t4TR4#cj0;51Iy9O@lVdc z=q*qK4V;zUuL2hpX=q$B5}Mrk_6UG|5{6lE@PaF;-(06?mj5zuPj+VySzU{XA~1>C zIr^zX|64*`66Sk)qcKc57KG&T=d3d8MB(wo`jLM6uw@LKt5sJ^@`DE2h7O*msqNbD zjxdXAH;)N#1aqsKjXrjb8D5+=XdzQLU6o+1ynW2sIK2(Hg9o?XTO#=i#zP}gNx4UUVBsHxE-e}2Zat;^W_Lp%~$FHFet_fe?9x;VCrCUnOn@9tp1ix1fO@7-ys&9!3xTpqgm@!ezV-K^en0@& z*Hz)W$&{Ng)~*#>y4^I~n=jRqb&-jH7JY=SB`+sxsXD~AEQYk%LawRtm;v&UnB2(9 z+oH~Y??$AK03Asa3OvEwQZSKyFax!Sc69AbGJrDS@b@!Ep;2wVm}&b?hlwUF<|0$Z z``ZuoGB>Nn9uNPg_NMmKcGyw{#FP#xlw2pR`FDac7pTUajjI+Lb{81pDa>3h*!&~4ziMmeUN>& zf~SB2Cp$8$+0$I@ShB-|bl`M2fvIgV_2_FJ{tZ`9LfmUwMlXL`>0DV}+lw$(cYR<~ zr{!Mgr1wqg@?COU6K^dojd>q>Xc{|n3-F_V$$;L9{_(BZi2S22=HlKak6cjBU+sAt zGlVo}FvZ4R3Nb4I-kXWDooWBn+IO_siW+NwH3}M(tj)-XI`w!bvl@{umvVli=2lVi zy-EOi^>uN^*`r$ z%dt$}ltkEmmxRg|oli7jqx2sZ<%zK`dxnlO8KXWd?L* zF^7Uqj)k$ua&(SV(Ws-`7u`QTNGk+hxofAJ_VEn0?iSsS(v@va%hTiB_&RH=^P}#> zKlh7An>-NOmpUBS*w*}4m6ao+sys>$m7wW^t@#$9EcURJ5;P6ML-V$gM)dM~J1Epp zKECn+;+e4#9D*$D?4>wBy8{mkQ$DBsgkj^WL_ntUYS`Vr$H_WFW{mz{Z2^+$8$#+a zEj7|E2<3)oX)$ZO{c=z1BnUvD!1w1bcx(FSrKA)wI5~#4xp?{uY(bka3rU(6o$#=*;&9C?Tq!*Rd=i<4MfeW2*9n8fV^~ z*kA`JVjW_I$piUepfdSst2|%+`sm7m_6IPwqo$JJ`g_$gnodwZKxV->;Qu?;mnH!d zjxNmv39mf3<4hujQ|XG6)tFwby~)hW8Fo-@o+8v~Mi!A_inff5st}KjbB6%mpxm?x z{KE-hC}bQgagf#8kSJ!&CBceVh`k65z4N9cTpWGdZT`53p6?DdIdb{9MnNzbpJ8{t z8t6XOdap5p4j^tzJwtk07+UI#=R&`@M5Uny97=?dhf-%Mdm3~8Jh&0Gukb0;)w?XK z>6#UU*+HBpDgvUa!G#RP+4~UGN?M=bwpzew)uZ78h1er4$KLP>C;+@3HK`Mk$Rq&Z zTjf&3{ic#gZ<{$1{VAroHWHj z^avk7Jh~rJ;OiL=p1pf(fic~2vf7BwTjiIu#)t@c9ErM|MRtL~_>XCQ1oz#nNt}UR zC#j0Psuw}u+s5Fa!l!&mk5i%)t>yXI&E9i`Gb!*W~6?t_sn*|B7C+QUSC0c9q z_yW0*u2hYK0g-5R$LWw0+uq#BJGC^i@+%(CmIr#f;0$~PjVmZep5RS*OaS-Guc+p) z5zT}P?fDox$GoG-R(dJRUr(HGLYAB&+Tpx(;`r(+1BL_z7v74bijY5NyBVRyG^^Fb z8c;e2+A5TF@ap?OkZJP}SjdyiG?fHzRu^*X>Tut4`@S`TmUTlu@1@rZR-)j?;$i>D zg;-U?svk@O0fA7~2>!*K`&!^Bki&YHT& zaY_52yI6)>UH|e`MYkie70%N%U2IHz3m~skg6JKXut!%eiLd>+0AANbKx1MMk!QcL zxM8WXcshlC<|+jxdEYibh#EMz-s+$&>LNwqJldggl8q(5Qb5kk4XgDLq);430`WX< zHF1}&m5GT6T)unVyKaMQUi)Q}|5&gq(622n%CL5PymFalN5t~`J)-~WYdg0eaHBU{ zZVH0{VY+yb^=0emy~X}S^6E!E7ZNOD>CW54M+i4UVIDUQm#YhPD-GIvjsNZU&StosgmO%TbR}7jFF6bs~ z_+`=l%e7)NncO1ba&xXa1FipH$r87_v4atC!; zLRV9h=hdmxs3|2LQ7=fl$UfQXDbE5y8rx`PkjOF*j^48M^WU(X|8_W1VJ)xN!oP{V zX9%92TV9G)Vq+q=Q}3(=>Q3`r(B-FXrO~bxe@=q}$VY!9Ze>ks0`@p9)P4^ObIA*r z7l=|CEpn6cV8!rV7P^$ijI7OlwNWK*bEkHDC~?HtdlW1SK+8TgQCH9-GOTPqeI{(@DzxsFpgzawW~}9jeiIH(a`s-LJ8_b%PCV*pUCE?5Re2 z%OPq-b#1di^E|7Q>|U5XQKe8U%&G5pN+K}k%CgMuG!4BR!zGE_L!rwaa&&s z`UNwNZRmKg-7{`{EA8MYQXfP=mp7~dms2-9eka*fJ~caEubX#!6;3CG1PBVga3DH*pt!a@f;u%qgb{el!*a?o}CrOo-s>=NUU))+^kP?|?-n!qPa zERPALM_I#x6#T!;2BmqG14e!I!B71zOKVW6G5KaWNj<}&e@cgvv4E>Zl6SloZ7U@MG~Ad8EYNr^U`4{|Rfl!GC_kISBx zz_zL{g(Alh+mQLAJwWid+WKc_Q7gLV!cK+%G#{&yNU2GO06vJZghmVlvuK=XpN3Z2 z*h+@MGjpm4w%(2r1>b>mLWYgZ(0dT{)L_p57;AUu(+9&d|2jtA_a^-)WP3LAL2Amf z4LE{DMZNrpTc-uz?e_wYYW)PJxs!rr;W0#g$^7q2rv`?CmuSU{!KRoYmBSxYY8o#j zyD%aAs^kQAen%qH7Hr8vegvoo3oYYqd-ZI-r|$dBJVLCd#30E)yP`eiei*QIzGLyaJC zj`KD>nhBjLNNwJZLd5Qk1$v(0f_sv$_~u9Rz*ay!+KK1qTIt2nG-PP%yC9u2-BS+k z&Rs1%!Hu}G!X5?z$chTV37C)*viHAl6ZGm zss)~xW=Jc&MAWsyC^#GSOns~NCC?>E3?W$EH>gkaGrp$z9p386^3-I%6M2YnV33 z?7ql2A$hfzQA4Y3#DS}B#|Ov#DWY~LXVc$${#8*j9oTcwGkdl_!{im(xxy#$+Bt&p zV?^*>!Nw_)+8GTQV7@v%G9K%k4TZ`}`-2R==^x--l#3WtMA@Bn;`2P<060C^sBiL8 zW&G#;aSSjhbPN_eK~1c3!#Yd{7?u_bs)op{oMSyqH@U)4pX+ulDXOjrcxsN)!HUUS zKt5zUZ}?V_5w|2J_I`Kl=Za8_yAqYP`k>On{V$51VY?Zm6K4TpR$AAl!ZFi6W_sMl zDa8CD_@?=_b*x!m-NEnV1<{}LX&E|Ou-_Eg2DH!oiJW+TP9RH0j09iftE*AOY51IA zUO-NY5U8Xan&)5#iYc+Ot})oR~G)yqv1-i%d|}RXfW$x2n6? z_1EECtX-|we&Cc47dH>c(g)Pu?fg~)7mZk@9HU?Nt6-{4Pw$c>m*aZudx!*c>h`T` zFS#7TZX~8=ICq6fQopWfIpB74hkL7ztdlAw5hs-uAqZtF;c{qARqt13?X}MDKV@$$oX_s zKoD?2wd2#OW*;G8d^LUm8p?dgvJ*x@+#4G1<@-d+vsjFc zKkkqurSqx`^J`@yErVFj=TXTOl`nIs)JsqUky#ygtz=~E{0#dP$4b|_ki}C{04ppL zE(*)VaKTGXUI_nu#+d__H%+x~u)tl=F+V&wU7G=%($I>j2Bvhs@*La^I{i+~1t)() zN}};Vre%el!TRW<=s+Jh(Xd-&z$kqU9T4>iRzKWSYu??fUAdp2UX6mI z<687YqVB3E%&A=gZy?;9#d9RBNYtGr#+iXJcY(mu|6Y*j3f!>OScJ9U%Uqns>I$=^ zsMD101*+>PPi)WlsXaaz^^;OMW}Wq_d@u!;7yu`D4e!{w0o_HO z5cSKkL*smiwL|%pLB;6J<#IXpO`ip-w{sx$&p~Tbj!>EbE_8 z?s3_hkyzd(uJupI33pr2O$;#NOEX6s7up>cd3y-cVw(hh?283M;FTl zs6tHGg2_tSKt*79v=(lg1uKk@RoFca>7EsKe*e5|Fm%g(#R=RA^WPx6wlf#&Kx8?W)}&*9}&u| z%Lj)+PMjGn51k%U%7n?+7)2mRw;)EAl$3DdhhEKG-_(yT!T+jc1|houqoe_AlGWy0 zSLQwRi6+e}B|)%)g=-Q1N0YkaASmqV7YWM75@skA%Lp9v9LBWA9Z=$$ZaQ+hZ$k z0W%*XlorYRb@P=3ag{iu)91My3p@DRa9KCd)}+MeOH$B`gXpf&*JjC5{GzG5rH5B< z`!r6EPLXUJ?*46rik7r;Qs^HW;2o4hX z3X$D@(x7-7i9h{{-#K+B^d?&lG{}<+SC+E9276=41JxygbY*cAt(* zbGExY2mBlRZ@UMB+{Eibp6*Vb^tH+vrF~&Oeu-Y@7ufo3!N$1|2bLFebkyCPF>v#c z-z%uJa&GS>6i$vBV&8?mJ(&rCKN;U)%n@24qS^Io&OJ0 zvwznkqa$yKw|aHFqGMx%vDWc4 zZp1EC_Rz&3rnun*GKSPinFg2(xhqoc?e36?J0#Fmhk(_JoM{wH;~3GJ5+jsfUH|y- z{Pj%VF0f-1p)KMCH(PpYSmckT%#=|<<0>E;^!yEd8!je)S)}07(C0Y5AmWq=4Bcj> z(z6B|`}a>Ghtf}!>eG862@%mrA>wCLO!#za3$iqYaLh(5s~_&WgopIMMKqy6-r-0K zQ%Uq0b((wHlQ0AF+gg<#VO7?;;8M?*#f=8 z83xKK5MHS`mJ+RV)w^1YQCYqq|FpIPIRHOd>d7X(Ex*->=Fb1UAjn0P zPfa@{#ForLCs^YhBnOm(IhHgkD4v;hdSGa9w8d*2GyZxn97X;cvFqBo zRtIOaeRqgKI<5Nd7tLv#!ak0Uq*n@_4Pm^yXNp--(KPFcE5~$T&LBaAGyWRZ^7N;4 zsTd4Z?seiQ0axe%001{UXG(HW%hTe(ZY*-OxP}t&n5HgHq%sADk@uM^Ti(T#Vqb`) zNdanhqEWeG(-4mPUmaRl*4c`@+#l98wIDbBE+mZpV1vh!tLF3tenx1k9 z1mV;vNvFn`1*LjrGn0=K6-)tJ8d?kAwN@bswtI>cv_s&;8!lCSUx08TWBS4{M#Cjd zE5~0SHe^!ZFGX5>p<{$=uQLYR{@!jh+%>2x`gaP9f@;~&wg< z-%NBFQaB3?cdB>Xcs$t`ak_hTt4PF?W&iIdKvQaI!e}(z#eF*(A)P2a2r4Aw` zQ5<%FSUK3nlCGRteht7u$Si}YCFb;P7ZvfO><>dcs|b~A_8~4|7$As%&yUR>Vpf?Z zcvPn|*4Vg*$0yH9X9V)8c(s-#hU^f`5Ag7AAGlxyVW^DHuRPXge6{;pr&f|uY#GP0 z-*3Et#5o8H;q?)j%UN=wSS$%M6}swb1owF-$Lz}9qiS6vJ=c~fFx8N!AvjW#ANx#J zvU|kuZx=}fFW)q<;tfl$BqL9!7nvi*nNj0v&XIg}t6sfT6mzX3B=$=Ol8iIwYKMvUug5@2kauN+qTDic(D&^e6E)kDGDN! z+_fXEjCW9_K^d`;G(*e`?Y9K+=>d84`FsQo(@L`s+XKV<>^Cv_DKt0s#T(GK``=ND zMz~}6tML9HZy1Z*Rzb#Zbhp?fRSx2^FKuCMnSv6TO^b87##i&I&L_ ztPf$~0_TO^LPTi8z`18hq=W_qK*Y7#(=ttx0jvN30C)+``4FP2|Faj8X0f+y`spe% zK@5-}=mplm(FDWvpGFw!iGCg|4^71&3g^4Gs1+n>3NuSCBBqCUg-d`Z@=is;Dh`yn z$#D|^o(Q>XD5XR1AxSoGS>g3Rh%EgX>3`f_K2N3fEBO$~7aLc@jGTaBmO7a2xZTQN zK@Kz>>t<0~Pn-Z)*<%Q2ce?KP1SH#zSH{PZtw;C*0Oo>yw6Cm}TnQt%P`t~KfG~}M z^zkHX&%hHO5{-z5<$;mG3tZSC#}UShA3YYKyA({jI1p@&SeOiD+upUF{znmGGAf#C zE;OamM` zlL7C!kkyxoU_x}Nft%4Ew+zD1LNY#M5)w4Y5y}tbp;zq(F2nss1XvxNT!jr4#y!AN zPLGJ`g?`At;~u^KKIPLEff-(SxzShqeQ(q3`h{>tu!lgQ>#1SEHSp@nIEcM=@|j#; z6f4BH5HMlMDnhSq^m?>6aWAK00Hek zZiVKo9V73lW|dfki3Sjcl^!87V&i?nDpsp4t9nu7L19F1?MoV*4G!N$Hgzxbqpx;a z?)$KZN2RPI>h#>X*2nTV3Ik9Z)1qCfQ-ho~t$Y>3SYM^s2)9gy2X=&tE>p%@;;r#_ zZ$EzKimaO6q!j1#Uhtw(A%W$2v)dRf!~xlcG~rHQ3iIm9eSqgwSTJTNq!Ur{v)LY%YR>RmcwpA6C1d-J99o{XZI*f&NSx-a zkv-4$CYFH0#H*t{gOljo^&u={Ja$1Mv5JPWO+jGV)U`f$_yTP1gvHSfrgJ*d$1WGSPaW+P)NegD-ufO6&D zNOrfQOpM~7fglB>$c~a3Ullqr11n3d5Hq4(iFcGrAZcCHl1V&AhUotJ-(=p%2bsvA5rJ)OaIl!o;H>-zW86rM!$uVy8bWF$l* zv)V8k*h3%~X{QnPd6FR(i?eT4IJDFJ9Nc6pb)w5~VSk!ES(ZlmC>G1 zQ9})7cy6>MOHNXmcRe`m$VaQXZ-sqzU66!G=b>ISb?Lyaf)2SMaa5!!4&<%*ZdBlD zupyWog#xUeC1sI?vH%}5{GtX!a|=^QB^f+}RiAog>#DfKetLhEOe9D$t@NQSVqKwk zaWUZtDK0}QQ%rgz9)2)K>tu*{C_D&_I%@BnqEG12+a88-{(3d7E?lZB!KASOgI6re z^bLAGh{}K@u6uUV;HoROv%eb7mqvM-_x>8U$AwV-gI~~^>816VZWMbAC0R& zw~580Aau<0S&DC9nOx|7D#(BGw;28S*!BQ`QAKI z885kDbbI;Xy@}G^)?e+iw00046+AUXz|26fg zxpf9@JY)t-mm-*9npyjuOviL8T9M9wBpT#ar^fUaSnpkc`ncl^mox5h+3BDxs=Xm+ z^ndyTJ$t<+c=(`rNwp8^!vRudSq154?CcA`-t}`ow(2C|uk46Yaj;*=0FqdxwzdJC y=VSxOzo8~9FCd;H3t8u?L9sxei!tpyO`=fXo%ux7)Bs69J>VZ(GmroP0002(8&IzR literal 0 HcmV?d00001 diff --git a/boards/arm/beagle_bcf/doc/img/beagleconnect_freedom_front_annotated.webp b/boards/arm/beagle_bcf/doc/img/beagleconnect_freedom_front_annotated.webp new file mode 100644 index 0000000000000000000000000000000000000000..89aa3dcdcf2bc4de0fabc28b6a60015fe3a5a414 GIT binary patch literal 81452 zcmV*FKx)5INk&E_J^=t%MM6+kP&il$0000G000121pw{?06|PpNUK%=00I9eBuMc8 zcxyzY?%@yH{xwqj|9fO?U0D`)cXxLw#T|-PaJLGjE$&)D3dOY)X|YnExO;J5-(_89 z$MX1NW-^&PpP9)fdA*3}{{(>Suu>d)j45?NRrZ7bKKSp0|33Kdga7`|t%~YC`f8sp zSh)uq3-LSn2_It{`^&rmWXh!8#<;Vuk8DOX4dvoLGg)m?}=XNTrfAZcs;6o*0-tEBqn<2;DEFrRK^cx#a6K1B1S zVc`lRrqa?F6sB06_pj(#w9ckkOj+I<3IfseZ{I*AQNdZSP^h~!yse_!A;!a~`JQU! zcx#j{48)wnt@TPF|Nd94DA+RreChVl?GKM5iDt3od21{f#N@T*6+ukx-8m@Wm@0e~ zeJmYS;H^o9a1ft-5v=?Po$?li{WV`BEs{}OMc$fb3JFbr)Mb=COr0ZU6!`0U{FJ?m zl2KxH-dg7f3h~{UU8nPy(IwC z7vxjo_>7K2a#?duc6MfFW@bi4hLJ@P^sd;Y23`VwLn5t*Dk^Wnmt~^|?OkEkG+!P9 z=bOktywjRd*pxnC#XJklUSCz`g1*i!6A~NsiB3^d`yzVQ-WFoi_KE#_IqlJR^4>Tk zIc>V1f~Ms|lz84#4-u^v=T;=$xHwob)8!R<+W+`?7|k-ofU1^X!j&;huW0nRW2%(* zEM}mmZQGh(5z{9YJ@6lE#d;96D?ReKklh)nfaxBKo_O{jDV{^>r1R*3v)dySFP-0^ z)N9K@kKDF7OySb%73S4j*90nBYCpidd-D$l1xwkBn3tbDPNP`Ke+cvTlX@vtd{?n~ zeE6cFGKHCF#615CB@`*06Hx~ETc84^!d;XDnx-*|lc3!w4~%c8IGJpg3E-9D3X{fB zC>vboqbP|uiSohBeo7MNYnzM!@0M1OG>k!6;TpYSB=`@M7p8us82QvBGr+SE3Xzic zP;O|QtPEl1qx|q`1w}~R7#RXC*C;@A8&HlIS6>0rEJ>Dt8}*70pB*SqOlqq5XptgQ zz|DGvhki546%!jOJQ^m-7I2+L(ZQ@n`Qp1OijH!xWDNMNqGKA$8SfTSaOArpYcLO1 zaD1F2YrsRkiVf|rC~r)xtJo;_TIPVW6&s)1U z0;6)QSMgv(oad0-bV`mFf%6p@eJu22Qxi;LVeD7lgGi}k*ex2S<1@awY@^&UU**Mo zq`q-ogNj4`6Nx+dDtHogp{H3S*fqfbh5n%2ixP?p!%_Ne@&kaj@5SM$rlMz2Cs`!k zlm`H4nL)R#R*H*4kEoZ^0RX`7q&OU8Jd7GiB5^g;u2dA=aE#)jZVL6XTG;6ii^CtD zMoqDJQ^BrP2IYQKT=ce355Kdk@>!A3+bQmSwvv1zfj6T^Ql>L zuGwh!xRAnv*(3sJymLMlC8g}=Z!IqHYI^lDmoiB;6c&c#^m*~ivP%{h_>B2&@hPKp zbFW8{GSlC?E9$cn#fQG4OKvBHh0jUqT&uxAzMoh(J#VRjz;8`bO-efe(0u16^XC8n zgN;2LSMzyU`zC!IzlXgD0I5Ca1>u;pXA)Uek#u({>hav&=Gt7?I zm>ol_NBC&9`oI$Hez`-3@uz} zz;mSQzkx~%zs0$9vHmk=$gdgbFnUonJ#fv}?~K_2dt=I=Rf#CsVCLgjX0&Io^b7zO z!#;iF0FBR{<{)M7L?|u5f82AHCWx#J9h!fyqXAdLCPvvIvNoi%x8&Tot_bj0ai7(W z#?Ol=E`TXJVfVk6FJHcN!STQU{(Jsrtd$(6>EDI`k4%$m4yf&AWlZ-2Uc*+IC>2#& zc>w@g|Dd3tzyQa7etv#ol}2B)k(D}12mDqzBN^pP(*w_etE_a2ucFA{x6tZbl5!?# zf$xgfBqDaX5AYtgpHA;Zmjf(N~!ggBM^CxoNL9v zoztxJ`p3r!D{`!pW|OSBTMh0BKS!hV#!8Z6Pf0l);vN`crWXF<5B9|_iJNVX4(zKvrdUQ> zaPy~D3S}rtd`=Kz{S@3>@D9ClSC`U&p}}z!`OF`RFyPzj5>ou%V0V>zPNODD673#B zUYBtfETI?Lp6y(BBpyZI`f%%y$CHufKY+V+I~7ivU4;B$aNEbZ^zv@m)aYzSrjOkQ z6P;v4XDE`iyM<)FvHetrqwm1&<)a7mD502tYgDGoc?Stq+}A1Bjy>ACbgRRx z5^0Zs%!?uzzd;Fhw!!WTzv*CS35}u66Y1ngC;(J_Zuhj1`)ViKT`L9vMXo53_6q1i zH~=t9?Q+|@&-awws|o-BpIfC8b~pe4v&rsuKKE6Kwfhe2XVapoqGX?d)`EQ>D0kyWGLC^kId+ z@hJKJ<>#(K4-`%jcL>RB<1XLB(oa$YclF6tIJHP81lMWY)G$fBYPd)H6H34_b=}h=lSWxek{+qV;Ch2wS|&+BxF^sZg)gF_iD~}=$xZL$j{K)k z5;jfI@aMaVRWfOc&5A{mAJ^i~cbQEZ!lb^u>89kMLWn8UX6WaifBxwR$HRvX9Xf2{ zhR0SU`(j1D3^Q|3Dvs%+;m0sB9Vyj9aZzN>!)z82k>!jOyjYu`z;ClqI!>A#z(>TQ zEK~^9xxgZ&pY-$Lq3l)@O2F2X4Au^F_te(7qHlf5iuSg&G@HVw{0*dS>bYZYSv$=5 zwYJWMe4jl;hgp}8KC?+T?y;nUEe;x#))5*NtaFNFmZUWzSL%$RFl;o0DRUuLQFb3wRO4tpq1rwbVXD0WY(xfTil z&?ManBAXrc@W#zYu}0(=T^<0S#0w?QbfoS3T6TVCoY`A*bImMrHFX96V75v%XZ`JJ zz30H|%VKr~9x8a4P1MO~ZWnfqo9osAc7}seO>7;zu{QVQ^t9`kq2ST(r4Ih=2LJ=J z+=GY10ibn)RD&mL`UUlTg>JsvI>5i#b)-xyWyL=F7&o+PFg*(0Y}wzb?iY_yx{dz( zVmiA0{kb!VNSl@lAH?i*8@g&XvMwOzq*+i(w%uR9<)te$&S(ukd8SMrgRWu2`D2-<{{kE)_L!WSJ4Op%SOl!cia`wsryM7y80 z$|FoVvi+VFC2orqY5%qsD3J1m%~L_8YHN^6)uF60jf;QGYac2X zv!%X#5|f*U74XT$9HhSW)uK{71Pr>6gG6SZ>+dHAvs{@}uXy3|T{a}-RTcluh@!~e z>BP8Fe2Wo@&Dl^`{*^W-KRDDjJD)dI`V@+0Y#$d&okXIK7L$8rjM9ShQh(<~g&jZ< zeb<~*=zb)8N07{GsUEo2e3=I|-6|&dPXw2#7ShaP!zb6NYj5^yfB$@fpONv`X}=Lk}8uTI95)5;a? z{=BB5&&9?z)Jc(NG`Jrr)+k+c7CC8{MuYb?FOsXV^&I~7&<7p68M#ZGS1F^C6aT0l-1~he;@q!!GD6B`oVu6{P)3sAN;54HSL4{{(q~fs#Tw> zRb{nNtGW@XQe_zjDph+z)v3(8i-HOjn|WYz?#{tQ&A?iEt2+Q6t)eFt(vM@HBGf@x@y%7 z)v8&lRo|&r{iac?dQe!c%JP|775-OMtqRXnQmevygThs+(0FzE=%GV~3>`9fkn@54 z9rtZtMz7+;k>zT0Y&E{!+C;+(6I`}V<0gV^P_>|5{fF=PaR%26jTT*uO3e^vdg6b3 zh7?dI!ptvRD!<`93fpqMzmF;rzOCg#+j}VdtR*3;M7V-myVppfbzOie(cS!9D%?Xd zO;Z^)qQvSP^y`t-ceT}s(i?GTltc`!)2I+-H0H1n$$e2ug(#gv&;^1_Jyea#ydwy| zRyC@VOwwvqqekf@tyitu@WFo{{P)3s?p&{GR5yjBwW>ztV@R5#Y7}~nAZveBBUnw) zyNc>YZPUrws#iDi+e=JR3s5(Lx~~YaE!3(V!GQN{wTGf}JRy9erYO-q8 z6xFJ!s#VietEQ_~%}}kHrCRl!YSm^&t?GUuwJP%nwJLm2Nv#S`mQ$<3TYW-QsxbTf zf)V}Q+$%zz$)0sDrZ?unuW02O!mM1(pD%5`vejw`w^9*bwH9}0xTLH3&8g>!$-+#0 z@%NnCIvyhWZn+)vK3TX4Pmj&4tW~3F;zG$4aVYHg)umlA^t@<7!L#q?6;``xb{&O( zt0lMK1sO;rd#;wcO|xf6;)_;X0@hfN)H}7*Y)aoiGH;i2#!NFIx&IVYn`z2Hw+2c5 zN#~?qG!o3tVN`4CB@mO?(2;gM68*Bgx=bdQxk&CpN9Ep-g%i|j0?!e2G1$QXD`5xq zDmA6v5)@U|!8|1VL8Q7&GiSAv2}-SR$801ms9i+vp z5jFiknzEXI@Splsix2+epX$|d|&7{SYQz)8mQI;93v#Y z{nJLs+kP6gnPCon?2^EUbX7Id2a14FQ?7oZ@{eaNW0DyFtT+IjDVkU*J`fzkbi5!-YGbO=$zj zrezf7Ia(eRjq-`ig+ZV~WlR0Lmk+2lS)S~e`}LPIoll$UeA1)|LmC8u;!-~FazZgJ zC`x4m*Xn}OR4(wm4yaRE#)3-K!y;-`zcOl7Ux8ZHB-N_Ps#Q}|tEQ?}O;fF!u39xi zwQ81X)g0BTUm3Nky9Ly$OheVG@NRjvD*UUIS`}XF7N}B%nWyIr>e-`5j~?B-y4xPs9)LD%rf|6=F_=&W)B~?k5fUAA1!fTjDP`1k_yh2u(j0aS}A?JqkBV1qp38$5aY7_?PVaS1zhcAzEXvoci~b2?ec^L}XSA z^{WPH1f?}}u$8pf3Mw^K69`JIW(R9XdsR$TCcCAx0{;>8sGx(%q+JSDsnP8rXs^ye z%S^)7f=Uexu@GY!1`fk7k(K?CYE6M_#M~(82*y~6IvJu`0|T-M$r=Ps^PM6oxf7_% zq&48;v&>3_b%l>JXz+|2)7M&+ndim1K*WO=i(z7|{!|KdUhD=_nmRn-_!nX$~%xdNao z+wc3Iw+Qp+@B5Y20iU7GCam1FMX;NHn%%Rc7Ua_MiR|UUz%wIEa4REVkX6eh*o<=n zd_iI9VPriz{r7`(sm}U*@1k#=e)ARQnKP$<)-(hZmmWp>mUadGd?TB$OOoVXPb;Yd zMX4w8s;>bYYCAlT;BGbmrKtxI*9kZ_dLg;JtPhGc+gHGOq)B44jtAx1}{3Sz5?Z%ZJ;Zi%+lH<1sjfcrMFdDo2+D8&$#eCO6yaU zY>$d_3%@9_O;xhlzT!60B(Y6XvSD0jE{$HG#6DfohOhe?9BDf|K&gF(vJKOJYgf?E zH?sM5VIbg`R9H*O7L?OGk1p<(gJ9Uje9CK()~t8A#=1W zIIVUzkL-4&GUj3l;8^*7-k52yA||~Pa2}MKCx$o6C}IBe;}(87ZwwC=SHMgI7nkOd zu@^h}D_tzzT=|sE8$(P#KC911jyrdBwSB|FS_O!?vnvB_d1Z)bwKz7LT+K~;w5A5b zi>^?;4qdwm@}m|N0%d=;Ph6RXGQl@PwXOwr+43mWWD%x0E9T7fvW&bBSG%CwB^SWd zPh6_^M>YzZeKtNw-uI{kw`x(c0eoJCo2Jie6uxP50a+hASIfocXOs~x;?_F>No041 z%lR;MsK%LYLbjaXWCrKnEQ)RNAJcmEn7Ah{&myBShm}a~+ww9$ zQMMjy<^uqrud~~nSJA{-=v9I&eHAyhjS=89Xt6o3qg*sW_^smRM1J5Hv@@@xZVE|j zl{RT@fOD&G+Eq=XnyDiY#`RD<7FvqlV^*G*e>X zcdmSfs!_-MxM{blN2RvrRx>(pqPZdqk410^+>UvYSqd%N`fz7~3ruQKXg$)zV5h6K z!-RQR>ycrzEap{awQyD^nWQyJ97NV)VKMKLOPMH=zES4nadHX1NRYXg z3Q=}TXRw5zS7p?VnkJL;vsT^6@GCJf^+4SSDnBH|Jd;s7f=*FH*wzPu8c|vUPSE)g z0XeI}L6zu5ac)rMw^V^y?+oz+b)ubm7r?j0svB_`*}}|9e*VX2MLfjBL@-jZF`wU?f@ylFvo<57`ME(FUSG|hQCBa zd{|YUf!9h(2qUu)(RQ+t24sT`ZXhBa2$pBy{vwh=-8YD6*$@eG!kTvx(e$ZIgFV~U zR~qo&gNW>=5RezPPe8<*1?3rtsfQz_90?YYmgn5dW48a{bU<%emPLfM_{#XpN$jj7k%o6F}(R# z`uNjv!W}cXd0{QJYQ!Pp2A%u><|ATURe1^~4{)vE=+g;i7KLj~x%y36hL?Q9j>Vc- z6tFGp@lQ?ll$wBu=`BHq*gPH4I!LC1Pb;~g?Q+G6f@hz8;pdvB)mbwV_E!#l95Q`$`Dty!{d-l_V0=`3cHSoD?yH^KZ1x`HFA|3;ar%} znMkO0xvvWYlabi7B`8$vH6o6ZB{07t;t`!(C7~*p7O_Zd&IoR`Um?MpeCbmr8qv~2 zmH_Cz;yVIv!45GQS`bI`$4qdWI!f9NZr4WUO{qlhH z5hcr&r*4@-e!Lm-mn!epQjrFkP7`O$dL;T>5Ql|Gc2aF|VFC)5DKFr1#X>av`4%W$ zp1!5>8$2+k%$WUm-^S24>dC2jO?-LKRGf71{@WP0zI%9hMm4RhC;S#!3DukhoFR<; zOiTjWE<5)uDn`K3udZ(Fo1Yhbo!Q49y^Epm+xve^sigI=BENoNLu#k&sLi-iWZoMV z1<1xMD=Fux7)zF^v$LYl3Bx7gp=o|76A3h39q8v;rC$<}+U&c9MLnu&r))^|*Mqg( z>R(_{s5e^3Z<;!*mr9mxkh2Q0q-|ov!e>G}5}Lg>!Ud-5BcwWexseA|<0jHRGdk!V9prG$o zklAEll-y^W%f*uXQIisJZpprd&x_|=M-Lib2ZZQ{hR z7sYX*N91!l2s$skTlthQ?XyY4nNCW*5{XN}o>1W@B4O$6plp=z606B;ntN%J zkoX-MN3F9(BBs12R4Gm*aGZnsslv-{C9BEu))td@+SgHkt4O3b@`P$8iN$mW%`$~& z>ZpWSL*9izN5ff>$ZqKoy%&oa#F*uN+r(ilc^88mjZiOW;jCdAVZ)qNjwfxa>P+oq zvaJ1_m5nCt7f_oi`G&0QR?Z?HkTyppCcCAxfHP#hD&QJ>K+Bk5=`7x;!H>2(cIpMm0+$a&KcI7gl!$T$|%V$vFN zfd&sriSG+8R=rM)X|Z2kPPIg_nCzf&y6|$_$!cDf-~{!~vqU`Yu5ksbp0JUTGCKgo zVg-5U{2hH_6N$`bo>0j*BEb%IP&Gk#sr6+wyY<|l$h^0#;NEYl0zBsb>V-{sIe&N3 zfoOa~-XXoCE+&yks_qE|UlNJTW)AY-7vA$?a+>tc;Hsw5WI+r7KnvZ298B8lW{#m7+;A^>Pw?UL>|@J)*W5;;g7z;cucy{NtCl} zEdX47rl$%gbB;gANba>@KnmmyN*}cmbH4>}4_%W>x%64S;5lnMUbN8c-OLc+uIqWz zCJfvCfd-I~ylD#3Ab$|KFp-R`U6sLA|IyD`irH@W(St`F`NiJ}7Ao1&?=G&c0hfzR zIG1E`mo@p)j1s`FT*EdMqz=$ET=OW46uEMBS>K<8g8613*)_#gOq61w3J7$I=Gim&wQjo&mnxtAaS+#14yhdNH&(|x~(s%jHZY8z67%KIjy>hKk zm(S{6N+&OwDv9{l8utCFwQgOrcw*ZE3@_Re-DWOdOWze=_bspY#B|NKytN>mO)u8f z(YR!2yEEE~LN>qprJhz!GED*r=yNp5hVIY4JExRunp$g~n~=_ysBJCu9#_P|_ek@Y z=|L_OT9t~zkNYxMMlxOcsIV&s1~_4kB%QZude!|Wl>H1k6GfU40INvyuMRuNcp%>Khcp+eMr- zh(~ho7nh4{V5E&cIYPr-K28eXL@|6@-E;Z@MbY}XBW4v6%#M?b+{!O$_#H*TCpUKT zsZ|tkp2rk+RUGh;kAp%FNy5MUWFol(C5@Vi!oxX^3xLM5z#+zG9!s}uVTIGlYJ6zd>$eME<8ad`T&VGMqQ6)7eH$UsEQK`bD zzI8~{pG=7k-X^Y zF1nVGW1?_&^x0YE8Fdt#>q_0~g&dN=9Q2 zzB`cETSd8yw}=3yw$DTOL@aVzI~Yfnse`Y!z| zSPb=)dRjyxy^(|AEKyl4SCjB-07GLQ+C?XRA;g*^$JJA>nL*gEH?#BBQCNRQQodoC|bN<_%GoLgY0~ot29w z$=ub6&vB8!WyCelAYe5(3_K$ekBfLpnhhfHEjTpnA!;7Tbn2#%#Ex(ha#bw0GNgrH z6`rxHBlt!nHfcR2Xp<%iQPmwm_iTbeA^ z*-tG3Gu<8=2J)Nc-Wx!L)loJ`%;9KJxnop=9J`C`#U;zM)e^@@Zh6m|^cg80;AALi78IaPI zEqVJgmlprORh<-)*bz=bu8PHPOdf_NynO9?)U8{ixW5~ipwcz#*5kis=^#dyliku; z*(j1sA3O0mCKgM87TSo4b?Wh6t856vn=XH)I`ybqw^|V&Zy@;N4Yy*FQ|X)Z>h$cI zI(~c_FTU{heX1MZzrC=yiI1!&_!3F+Rh__ckzj{YB46L%?#8C1@}3-ZZB4rXULptY zd=QtCO5cR1M<p>s+AmJ^h_NIiB}I8dPK zOBC>#d>k6Yq6p@W@YJTWqVTQ?mv-sG%4jdI*=OLyba_HT(j*^nvC;_}-AtPb01cL+ zkj+D#={BM$Udiv7gO;UI||ykf*6AY-4*T^H3y@`*>tiQ6yu_J8P9Aw4By* z8PnadLEsJZv{YcWL5`S>VsSmxBl}t`5~@1uU=o_Sql|=&Iq}P?l{_w6wrttbueufj z@0h1G0%J!y(rg!tyAevKxVe>m!TaZFtw#=umJ7@_ z#1XSuEN+H-WFuIScwWR=-4vmv)a6C#$-|cdGkxR;mWah^KaZ?=rbwLjcUJhZ(4G`l z!t^o=E553ek*rAk3?6xbdm=Fxoa=T9ZI@07Q|^th&ICHCnII09!JZi`6o;fn9H4Km zuyXqWFHgVzQpjK3mj#@d`K2^CYgsxkx?cswP6DUCzl+0v#XYpDuSDTjJ(sY*g>^cN zpJRFuvUZ;=U^YmFh@}0!T`McmTA*xfE)X?Ddz`#%Qx7+TNP`7)d!dj5lN`ADyu~r3&=Y*O5Dpi>Ktxi^;5ia8vMnhl5O&Y;6@)}J2NJ3yVd^7IT z(3cS-UHL%^f7>J6UBAq17r~2f&CgeC-$UQ+D?Y2`%a6XoCyTc35$v|*pVsh|(cn>k zX&|iCw4ZnF;d}S5bGjGP@TIRXc+qcr=(}^>#HPXGqN%&#trZ2HePdFjOFo@`Ph^qK zwxr)X8eG#f*c4?&LE94cx6{jKl4?l-;iE2PqI*q`=a=C{Q-9+-E7F-wKl4eDhy+ZD zK@zR!nz&GKbvn{KZB+qR0%yb`fvL;#%Vw&!@`?Lc9<4375xT0cQyrjFOS61>KQl)q6&B=mDFNbIX7 z9K!Y?{db3QF)XqosoR6)GUL3yT8~huX@gzRFR&o>ua*&qZfQvHKM~GmSw+AyolEZw zB-T7hAro>0h5Ni3x1Q-Jg1`ETLHJoD**eZi<<}^NFDp8WxQGNlEi025@9hmS2?&4E za>;id#W16j81yg_g_pw}%|>zj%2{6%NjOa=Gr`LXJcUAzuEM2Pt|;IRJ^h&VNOopR z2f-Ia;#`m;&1NL}?*JuCy<|b*7!J%v6vsDZ=ofmGFr4h5N}Nc!BL_{!_t+*f-DFh8&Ut;6;z`@W*mV<) zE{>`vl4a^3i+NPc%Udn5t0B&+CWyr>`jvV|+FG!0XB3H?){e?Wla<*_7V{l=dGiH! z#@|_)D6tqvzwn!+O?OZ|Q6%E4IEuJSR!jvs%-O=;-WLMfrg4_@ZdlLpCs%)5 z<8bx-p%t~@{lRFfkhU7Q6ud49**!rF2W69VwTKhVd{zY5xf*9M%t(%HHY4Nsw~+xP zNWLQe5l~cp;QUFB80-xY1>dzSIdL7pd4Urma4Zry`v1%lb2tLz8}Dj^B*_;veIuBh zu?#oAA6fc6s0QK~vCT?K!eE92RQ#8E=PCf_$XzxP(*a54W5 z8||L91hEWTkU|7|w~Gcim)>EdnsIw6a53MKG!k-tD*#M8~-i`JFm%|sO zQqB5LeGpH5yMxJsvpkz$3S12w{BIVuvd#?(0GIV052Xk#^GyE$kaf(KTA;}6M`kzK zVm8)dfJc3YLn+kCy)!vKh^k+MDVzWL`?O$B9b7S>qy~5lZ8Ll4@zeA@zT=zLp}?zu z!>L>TIxX1a+rMrV0z4~MfGOH%>48(H`TqOJPoGuR1JC{qrfm7^G<{F*ThO%t1EQ<( z@e{7E9{AV#`q9@{3vSf-_zBiW1N_S`7>1Eb>~+3=yc-yBtH#HVzP>t;*ku>G8M}9E zb^W)^zdBtty1HIc$kUfy7>=Wx*|@c(+{74ssqUjyZPB|85wFyAgMWj`n+_j8LGxq# zmi8;5;YU-r#gOrnggs$++u}M^5jyk@)e4b)d@CgUmZ$tH z(orPYdmn3D$v-~zZp_g^p&V-eVMGEmw^iU);-^%kc-HPJE>+l;iDcXE4lu|% z&V@Rt6)T9Gc6$^{0s@b(}YWn3rP6~EnR4O2g%R;)=$o1nrQ%lh+Qa1b_5@zOyYt!i*wMeK+<;v z5K!uf4TYaN&BujuCs?HWi;sDzbqNW5*N?Gl{RWBsueP%a*O2;88gQ!fAJQ=QE1ir3 zGdFdt+wY`R7&wlH;tx=4zv0k2g}9vl!YlL_5}7?o!>QQcNd0$hU8;B;iH+|D0L8B% z!6))L3fhYzc%}e{h?7Xi)NXPPL}R)ch04b$o9Nsx>_oo}$v+t=H2q2>G_f5QpPx|# zZ%UqxW%Bgxi@jy}m11KSJ^ldP1$i}__8LgvBn2a0ZP7bg|oQ6QzE(AuVw zf+s^cbjc6{T*Po2noAP?sH^;fD7;m`F60b~;{75{3f@Lqnuo|_#=BPdiTL1bC%r8c zz;Oc8??hsaJ)Qafj-vRwJg3leNOVktsaCRbyV*6*5C?M~Cp~hhf%^?Io$84qw2^T% z3u(AoU=^dt!7UmmHR8pA9mT0-23hQazmV{ScGFNKS2$UW^n6xK9y7tU25BO+N9$+_ z6}D@H)z3oE{YWRnSaHB@8ZI-C@XIeqJD>xA^isZJH&+QYj6(nUecJi}W+|SQJ z_d98pRMP$p0MH#0i_5_d0?$*#+)*Ag(aT#)QdVMufg#QirmU4O(jn+UHIeM-cIVW zMio2kGZRzfj@Ym>!1=cn_(?0U_BjMy2zJuVBoZru>!&PXNBd`!mD0$ra2RwD?nT$nDOl zY7AMX(UBL(I^=Js-y#mj0-g9Dp+-teX)3h=06@UM-p#2Xu&)v&2xBKc{C{FaCAtl8 z?VnCq?gS7T%q1tGzB6W-I9!h4q~A)`of0rOhosbw;IL7w7^HUv=bch%@vA}7I_KRi z1c&}-1@T`|J|O>AtBAz(WjN_(WD#Xv>LsQ8GAPh$qms+!b#Vf!upv76z9!O%G-el5?t)4oEP3lS9OlCcxQeZZ7qX z6$4iT*I9@;R|f2hZZnaQy*2_k2G38YTh1>9fP2K+Z1Qfk0?7)^ub*V1RKT9A0{r__ z`)t*&gH+$Y`P(i98Q{~u)snMM-$e^M>iLB=okPIQyn*ke1mUrl8-a`dGvCwAyt6pC z9&368pESF` z=YzSE_GWow);Eibf}1sZs_Piwp9v^jww$ob77b*;?fikZ#gQywvF{cY1DCb!j%U-$ za({F%@M-9N&L}+Vqsd{wvGCCCx8B4GH|Ev#P5ttN%VFJrzVb3Ambx*oZ)_e=0Qk(` z@7L?EVq%GW_urp0tLs2A+Ft-5;B7?moc%zeRF5`XC)Zmt_?3$LBJ(L zHNdMTxOn*r^eq{x1-`YRB`c6wwtx@tF2$ra0RX5JEosw2E!1;F=9 zvp4ab8iwu4oUi^dJFs0JmLE9#wb+y803R)yelQ!o$!%Ksgnx+|^@LluY9RwZOknAn z_2^r>Lb!%EU1a4t^+>E$Hkgr;xTY>F3@-Z(c;vwQjBO&p=prlEsVB@@Wr7&~e2P}9 zTaUVRs}$5zOIzj3Q!kU#1)TWkz-L8W)7P8(@0*l#`liL+THhs@mx%t`@5iU5lb9NH zd3keR3F=Kh9q?K8q<4Zh+XZMf?qwK;krX2OZ@(X(mM+Ycw-**QHt@of9)I-N`*aE? zKH5LBusgIqzQWZrE)<#<#iHP?_eT1=P-a~s(mUs`mKvAzJujM&At^?3-;K- zpT4MW;85cq7Kt>jkL1+i7ScU_tigq#x#>vyv+j(v6#p^sUgDg0BGjY}$l?d{~K-|F1}Y>s+l1nvw63Q1j{_0GMeb2$S17 z(yc`?yjqAu_18$pJ^s?s`{v-*@H1W={^0dhdxfO_YTz<3M+7jbr3>AYkXXz2Iw1HSs6W|Nn2}I z;VVL*3<0G;W#gE8WJ2+!HMpmNZ?8?z073cmR!>IX#t={l1Shv zC(G!O(^}F=+c#%RyrZ$;_A2oXa{l`Mr#E?SOG!#==p^vGSnSepn2&@%Leh`u0H9uq zSWI%Vjvl6tQcn6vJ!m>d+nGLcU*rQj)7SpMH2BZ^8t>(;At|f5laQ-o@w?8MW;02t5av90x}4sy^PBF!e_m<#s9Swu{!>ps6TcH1;| zZH)4$Bczd^m$zMK_dOzFT0{2*p0_&_WH-|0bxlxNNb1S}G%Cn(xJ8jFT1gFt(M9aEq^72Iu7I zEhj0xv6G++VzEa{k$BR60RSldP9&`ToP14>l)BPU))048dWc^B6ff^flHw~nF&q_( zb->{eX}0sEO|lEQBoZn0ob2wyejFaIByx7W)|(CvIqV3}Bq_e9FiMwfVreStoeql6M+s| zrHRAW;8eGn7P);uO2T`s7+#9)u%g#L)yvavA}6aeI4^ih9RBp@(!)g9Ce0F}vipET z-(8~cxU4g1nn;OLq0$mYj|+B9+xjAld413%ftW*q9ALav3^IEF*P;)}O799KZ;-Uv z&k@vqY<**RWnI#CY}>Zov2EKnI=0iXZQHifLC3aj8(*H8cksq9ubpsX`)W8P>n3r=3GLPc@*h?wk%c;NLF2HdblLY{vcl1I#48{KA<#3l%)1I~UDLW<2l-iq?qs~{329BEv)l5%vya~x-)W^}> z9ORmMh-9Ie`lX-eP}fD^sI$3oaTA{bwYx1b)e5zg^lZW3-=Mc7?_~9@jEp+iacfIm zT?(4pl5P=M`zf;}M^KgZF|83}B0Jf%6fU->@dR z$lK435^U)e_}ENqBhXhA=)0G;i;Wv)_XCh$yeZln9HPPOE*@-K3t6Ma>I-oG;z?n` z9?XsIaUxJVPh+d9rV0>JF`n`AeC{I!#;M_9kX#3Cu;9s7mS+z5~zEFj>>@9*3c` zsSnANU&OFd!hEj){8!QzfJ&aF{KhQc01$07jN4K9^)xcwmb6?hNY=xutkCA9Rr{PS zK40Rn=QK4_EyjT^Ss*KQCQ~n4pX1qkEA#V?U8-7KDp5|?$nlXQZG8JoB!Eqzzy%(9%t zF5j~uZEBNvMX0JK%q&Y$zhvTQ6K{N1QC%1axXU2ZS7n6dVjINk+^7|jE~)m9^9Srv zNxG;Yi!(PX^wSVicEuU1z42HaMoXr$l9;fjT*fEKTd6Rlm#digT;u;T#eXON<53f& znLw_@>d#_?ts$f8NNIo9R`~X}X9jhbfu@(aBjz}OB)hnqp0?>w*y=4V1Pa0sD6eD7- zeY@up;>JrhFgVAP6oiu=Hv@dc#di44DIPFQvE$}j@tji03fweDtnRcdMUl3g6Q9A% zh}x#C6bwkHb6PPko1$2W(%`8jJc{rMMm^sxrZrq8H_y|;bN?4Xak&Rj&9K2MY}W_wsnj!#^aZ-0wsQ4)jd z8imy*UT1hQqNKBH_hJILF9Ais29U*nGNuiHysANu5+h#_SCGn6`ysiH=Lxw%N_ z0E1%?>UuLdA#qc^{Vkv|vEAvKk1lZJ;&RAaLeb0Qq}mzHAO?C4&~%I-8|`k_BMq`W zORk;zKDHK@Q<6nGj_=<3NJ+R35;1N&~BrAz0^(_#+WJ6e1)hzb9qKEKQ znSyp(YGt4SX%mMt zM*f7|m;+e7fEMt+1igA7=8p|UV0XWwlB_6Z&C32J;~owc7NBQR@Z>S9{0a}>UghUg zL&54HDrv{X3Si&?f*6Ll0L~C^`aJ2dqs&jJq^2*$1~)XBa&r`_ z?K$Tos9w{{<%t0idk8>Zv3OYi z+(fBL;%p>Oh^^mtB#N)y_ba_|&1W#-hz|03A3z`@Fjf&V_W8P-7Mt{aSSPBRVjTiD`J0xnB$c9VJBFhz zwx3<6*@&V z21ms!Jh+qu5#Ygyw``dU?Pa-#rjy1LeCesrchX7oydDsW{b3CD;wvVcIUGCq-s_>g z2-sMbHGYBbJ7(VOsXIj#*n;bhh!~a7R38AOWfSUFz>c7EA2MuWEtL^})p{|b2$t-j zogB99{WQWqIM3+u0-$u33X7P)3)KH+?4fx`*I0%zd;yPZv*@lpJkZJTfrN(0jCPm; z$v|q_Eh;>ool7`jR!|bmY(BR#a$)N;_MCIyxSJ991FsGrapu+TDz=lwMxG&uFb=h& z%EM4dc>H}9U@*n^*y00O5PgDkKYJsX=>ds{X3hFHb)exd4dKDey9Uj~arE&DzJw>` zgDWdF_s&Ox#UQvnQB1!8U}hegJ&1Oe2*+=*xgh+i=GY)75`eyIx>&o>j9G81d+aDG z$LlT|t1zF7)=bO7FND{MhsJ9onJkGeuOgWg5X@3}PIls^HXkc+36J5i2=~kE<1YKO zW8kN!7l?fQvIso%mJi!+$uL$OyS%gFi6+^(-96H@V~wL|VEXK`dd~0(C9B>P+Ow5x z!eGB_S|e^6mfy9B;^X|hE3Tu748xi;1DiP86M*Iw(tNm9hIixPKFq#&FS9zJZ2l!=jSRwY6lr)E@o5cl^Kp3#xUA5mtXm2PV171`i?mRTs@?&!(K7!k7t+DQfOlLFU^-O~dg!X(zX`$|anX)V3B+ zd(p{56e+`Pw}V&4QUzUqA$wG?R<>F_X<8B+)S<>8sr<4=wd4Z*?CL1q_=N*Wo4$QO zbnK1NC%2KdlQ$)D+@SYNENs71LwOiJNRw0mq04XiC7=}v2xtN2{4FIe6PK{pY+o;k z`y>zapz5p8ji~wgxf9%g#uiYL9k~O(y0Fm0*5Y|L<9G`P1a}RN7YT9j})x0-|y*;7yqQEkokI zbYUC3uIKbTd2Yjy>)LFZCTEcB*b~nChJ}tMIcUEy^#lvFB zToAf87KKD6J}^6qZFr!u>qU9~MJXOH0nADp4+5_gVKRy;o9xH^il2wdj`Lf?+zk{(vG5%e7Lb4(>|X z05bgYxod$y&il_GpzVAkIf!`UsM^-*p)SG zPB5ULPV#pmKN_CfQTp^gj0JeCKsFnqUVe1O!y}Z#((AUvTu7lq8n5U5QOl3)mD->C z(*@uMS;l8DwMUbzwV2}ZiZ+Y@NXV}Vr28AWbzpZu^e3uY|oqI@&PIH5h?waKL7S+Vk1V($-JBY@4@9GSr~912j2>SoHtNb=45VEm^_AO-=O^_UTL zxXEK#G$-$OyMe6`kqvz}B>`~5Qjp3C)4|c+QVmY3d^+HhH;00FxsU16{ zL+oSL>F{T4A!xr^0WoA7TO*^xBk&*KPP(p-i@`j1zt|`bp@mcUj0G5FUdVczPRVV= zD=(a2-BX2rld}lJ1C1|vZq)h8-hED$5%)}5>cs+vhvqzmE>Hpro66NCoPNaRt zVC+Kd>duYsT3pJJ>+$*`(gZ(YAxPi(rQj5WtW9wbkK|Jv`z~wD!`S^XMWE>!7%JNk z4&Plh5%%Iw3VXyz1!*Qyyl;fEm(%#&Ixn!hrK&*svQ8#h^XF%pKT2kqX#QGYzBOiV z-xCIG^jlf%eh0BEdyddIr-PfWa&Y0kR@`bodqq5d;GiWH$$^oGWz3?+g)vs)yb56% zfvP9R{L7cUwG|jlvF92<6P~d}&Rw8t)DcejPM|m{-UOJ!Gc$iMxa61HEy%+URd80k z>E~B@J>XOB-PbR*q%gEHTr4xzc=PM-WGIO|a-t@%%oKOAz|wjulFt%hOYUFO6)df2 z<$^$tLzGR3;ObI=&bgwqBpQjbpg&JyC3IEERgiLQ3=^3FTEXy$uIzKEAm=?O1-XFP z1?Dhj4Ko5cAz`G^vZxRIxb8&2G|~z%nvgE8+2h*efwdQ6eB~5xg@H?x{E8=f&=4iw z+CW;XFMcjahCg_y(UztF2zz-jZPI{M-W(jV@%CEv)tMpD_BV9$aaAKw=oR7m`BCxw zmd+M@lOSG8ng_fRVD*T};ue`s7=Elq1(8%Q6PvjHch1GXu`eo{V+8v8>3=*#2K66* z0Es`&G270(fH8ssB=65^}L+I7gL?SJy2^q3aaVOJ6ci# zUxI(wXDQ;8v7)*`TEDW-1U<2o>f$bF9ai<&fu@ePb7yM-!50{yKOhLRp3OGZ zTzY@aoD@D?HC$XWHumi{Du^9119q-n;7p8QY2G+1c^YBSxvUcxdsGGgUG&q_F>ZOV z21tjpo)`P%{ZJ`zeCp{9hlIr@b1^AeE^hIp!Hb*0)E;P-xw(c~g`RlykX2w^5=Y3= zY=UXzH5Kx^(6=cEdP0}5%aP2Ay9Ulde6BQk9V$n(e!{U)Tkwf!h?y_xfi+Sz;EQ^y z>{_JI-Hdg-?k#;r+UD?S)&6RC?&p%M)wcU z(dPRDhF(FA^{OreF3%0tQ(rU|T&%J%z6$is0cK6_4S+VuNW7QdWj zf#~Jwi>k$jtn;U_%y?*7+!RL?=A=)vZc@&Ib%`%Z8@B(zOLEU>U zpblJ7j8`7spPHeKq?}U!0*P0T(9Jv3?e;kNMCS^xsOIm`g1n583xDb3r@y9DYz%#a z{-!K}Qpybns7U$Y2VPn|i@K990h`Vba=1~UAT@i(%c~SW*7%T>w(=uJ4i`nNV zPtRPT%>w%kpHNpJ79MJ4?liaAMI_62oLjo+d5XLE=i!@0!5dz-siX9%zSWF1oA+GY zOl8l)etEleMCr5&Y~|BDxpKXFQXlO>_SIc=Vzw+ndrD(O1Zx~@I3%#K!G~z80!L)A zs~;!5aMl*hZ87ht%#msu(@V;KUsQJ6k@`S4G5N~Emn8h-yO;;Rczulu56#OUFVX_S zzVbG`bAxv>d_8ZSNVFSVB|F}!2m<{$Rgl$%ZqFh(CwDv#fsSELQqxIjo1OcY<kSstdbq_l!J@CWC)qxD7@w6d(|hzX6sc#xOTEXQ6+VzJ00wfcl{)zAp3x_Q z;m_%ho~N(dp2qGk?u2dM(J$CD(2wY+kEhR+)E-u!CtsCE$GYYSicl76)+pQYi*KVD+qnEAgo)-L_50&?nGrbw#z>oSb;y3qO zo6nxu$?mVE&$UJPBR)?)g-`S+vv;!z-~F!x->Q#|FZ|P~3A>w~sn4CSv={XEqgVQu zn#-*{zBAv5hlDS+PAjjEvj^Nqz6-v)uiw7qAA=9%U(D}YwZ2upSzj%mcH7`DM~{4O ze0yDOUrYNoFEQWz0b782b6?XQt-fhrOCK#q;N9?5UoT(v&nTZspYWecM)X^JX1mt; z&78vhqxlBLGYs|SsT$0U(y&NJEko`v;0U{%)vOEFPGP|b|NadYX_|C0G#O-QvhNT0 zR@O82`SMbKMfs>|;MUz@GL&nT*Nap5ZT>#SD5Y$CY!sCu3(F6je4zaVZbBS#@z>h3JPUV{Cnh!Q3@a@BlGIZ)gsTEYUancC1MqU`xmjf)acM8efv49qT~KH z!~YsXM`LW=0)CsD%BOj(Dk9Z}bq?r+e6dWVl-FVU50Shvbspq2`f0#&PKrN1*1sh6 zANT2Ng@^4hc>YU<(t2Q6YiFeumgtWt|3vQmEjrJL5EzAK^{*RUY`>4{}u7R+HV@DU$LM;j`&TYDa7<+DqYs*})<@*JJs$2W07x0gByNQ~Yj=dVz6`f>6SAAtt zbN{|R|28ELYYhnO2m1@rq>}VU{0l7RAF)dyI0g3X3W|8M*!L;w3b+{&vOXq&bfEd| zJw(8AjFv`b{h^^gV+=|RzG|mJI2$B0@R1^f{Tqv~G+P6E7zHSY+Z^?d)5b9~ z&kd|#w<7-1zW;s#>1~F@4u6wA>4EPSqd>cm%LmqPP+2+7w`A-Z!Esc%R8kABgiO>= zost!V-K~-85|`V+ki2fC>SolGtN8X+)V~}N2MYVe0@rs+{Te*QwcaOLmo>QZhtIz$ z{l5>(JWqSHu)SWsSF$*tL2V*-V6=e1}Q z{%*C;+uY+$bjU1)xssep9MgKJwCWHT_1Bs@EvOp!vF>N$Y1lnT=7Q!?>@^1$-6Sg@ z`Mp$t+;IxXcT+4RU%obyuW;%=m02X5WM+lZvWW=wBP%J&sm|x(I5t2Tc~EtYN#NCZO&Kl2C6x7s=uA?|#BVId#)r zkH_UU9Y)PEVVIP#C0v0{!vI=$wsM!_t~9tuOMX8PUl4Vzz+jb?ywmnOYwG8fKC3*p z1QgBK@S48f;-gjmza633Yi zB_7+a&URK-qLKQ@!(tM_YdlLK7du@qmJ$X}vA<&@q@fcBs7eKX40@6sAJd|^rC7y((5m4`6TC3$k;tQeg3i>r%=!Q z1r_=x#|yFMmS|(!c6zmRv<;M`Ex8yEx=@#^? zvlPi<>G3nF$xkB;*vk$u<(P^Ra2U;zz}qLuGR<;XsPsI8U+TThcnOW#P&6*WRN|-p z=1$ZER*ybRfd5Y(jF96jK5Z5m zAnQrT+4A_Jt5f^t%}X_T(w3aMO7>2AMqtk`hpse~zj483ll9;6O_rM8>0={T42zgb zz$t46hSpB-mKtoh`^L%Tl|FUfZ{q03LTY*uBNn2F8ue+|ZDmn^Zp~79JRD8- ztYt;^%?X_wIAj8Oi~nz4|K@w7AE3ReB(bUrNm9I@B!#>1PreHtk6Ph#?$V;&ioq-h zqL;mA$CLJSKLV0u)7r)N@dBRaaN;8R!r%BjSjW>j7Om<-D@Eqnrj%q~i6XCnTqO*D z*rQ!E)XrY4)J95rC)NMgV*a0hmo1HQ*1|ia(p0k69!@~p47tKUkO<}+fL_m`wbb7) z1Z>Kkkc${r6or+-u;C`6-LMuTs-bXbYynOSG*)u$R3DH8&^UsXOW|1j4{iC!27>y8 zyf2C3+dgGCUX+;5_5h%)j;R?@Try!nSRpfmQRBegom)&^hd*=5mUE@1m|45UFXN?+Y~clZ+J7VNWF+&y-DmBV%2EG$ zPpKc#wwD~Q)L)yEBzvu|u11%x7xWrJVGKAnS;)E-GN#HGS{%PwOK(i5*De!E{lqu( z^QwvnoR70_`j5aRR&fu!9gWa;B3Bctv~T7AZzq#>iVi;Uy{8FIFe=6$!jpf=hHJ=~ ztcXZAh*BOz|9tegr_DSgW!CILlet-#-1}_;es@Ymw2DimpoL5H4$CF}ha1;iz#dth6B15{1u7_9sMe|L9X0pQ} z)U)bYwBiS2Us{9)IZM>Bg00-^2TyJ#ItmS-N41>1@*<1XeS&!=KuH3r;fiVq^kRs& zUVWH(`na?4_LVY}fcK8UyTGF0Z@tUCyCH6wOjMahZ|fTp(jH8*jGS-TWx9GVBF2v2 zxHOToD|#Od9fG+UTlE|AB!~v!KH?~qbNQ`vT(YEcGFb25&CWkHH6~?YA%FaR!|m~e z`_*u`w0qT-6}3BA{dCkHBk&6}+VSGbw|2kr6y*;x?#{!{snRFm`SSOc!g*U7E1v4# zoMoBq7chIFmr+rMY)6M_wZbmW%Qm#x`zxDYTh%nfEbuy2UenHf|G&}u`{*f|P7_Na zg!i{|QVKM(tP!@c?MaGj2Q1iFs?YXh;}Y=@%BtAYUheEA(n&#lcwL>1=#6;CN+J$+ z{6&3~RA?XEl5-Kwl~sBNu|15!^@q{Ihz#C(xnY}jfTyD9^%)0NT#jY^nS+Vnt%#!S zjuniK7R0U{QlarH(O=g>BpIwg!A695{bX@`}E3RQ%DXM19V1=FF$7kVyjg$MAO;1JVAcKxe4&X z!#|qzDr|0lR;1huUkezgGs+#=QH6s^P{qv_ZtVwg(a>{fEyDq^E?n-l?GrTgXWaXo zgp?mT9{8=`#D%+RaXJP+O|7xMP=BP2r!rhh%HDeJ{mFF6a>JA(hyHK(_Z>ETn?8^B zA!@hyp7lr@T1IK}lBVv|Vl~RyBZ2eVUkhVQpW!>&6UReBYn#eFxrPf4?JtfwOkF|6 zgN|u(S)(xt9#Wo@AESXZ`_%E+QqLrTM#&XtvhC}2SmX>JzVs$)fBOF0}K~Q^0#>3|KW@$zR8de?69eUDk03cj} zmxO^`pb9PS+kf;a+uZ!ib^kNu3Hx(E<%*YXj*v5qj5i(ZrdtIHl4609`{eIA>t1J* zSOpgOFtFJEB)waVE-64CoxZ0LDuT$qv8_=egIepwZw|@lpd@?r;MYj*#m_#$%IW%a4yh9%w|`l#0@Rn1b#=UOeP>> zF))Y&X+oJH688_~4k!Rm*ns_6f|7yjR3-Fv#UczOvS+4d)S90}dGGUL_Y?bGil1fi z3E%$Xf7!9H;IPjA``V(`hvt*S?hlR9^>jMee)+|@(FD*B|1gxtE1e8U_o`?&W7Sh_ z^wI5lb4T-ASU^L1r>m>;YVGA(F2x{#Wx6r0DR5W|Oa@tWTDvKMK zXK=`EgTpJg)R^qd0CZ2C!;C2vp3v-D0xuC&f@o^b5VTa2Yjcb^p;asI79jJ}*O|kS z5KnL_v7>BYbnIwdu&Pne)_m9yPdzYC&^M(K5ntT~O@@iJM#2k~CQzOcrC&RZG|^@r zh_`!8$<6XLh5u6jW&zRTrI;CkO-g2sG$^2JM`VV3O{c3;tN`!iRsEmNJxjKca`4;; zn5V9sgEkIc^Sm#(vP~Sxv>SVFLtyZzVx(kzHVl(~!yibK0nk=f+~jJx+hnP^*%)|A zs=CI~{Bzck@quhfvS;z&bm=LNc2qIE2wh%QJ)6{_3I`98Vvo9KOu{r`5|-`;P{%ka z6injYi7g7pYhme*wzU==zS)`ACaNnm6=JpMH^629s9gd51Jd+RQzFz3JpNlJ=J@M( zWc)9`_jkuCduuq+DZB!JaIBmLB&?qbFwToXMSfJ7T57bX1JDpj7@P+G0^T8MVkCDd z;D1Q6+h8Q-?02vX9@o>L<4()P|7IB<6~RZcY@N zC)vERa`;GagEeGSa2ddW-EUg_tH9qAbs^4J$3j!!vK)+IPPE1Jo>9egAL-W>JjolCwV zaz0I#!P#8;n6yl-;p{c!=v4nc2Y+BAK@e)d6dZzQ=a4r$A5q9FaGgDb)K)~Any&Xj z3?lae&i2(l%RIbX-n60)w|gOIMOx?=-7y*Hhv-YqK>cYT24)D3@arO1=Oe+yQx51U z_t8D6ZN9;6mb$@PmjYD?L6U8Vy*}*p+~Xxs5!J;nU&sAz+cb< zd>I(J>Pu~A_E(YoKb3Txxqe8vVOb@`trVil=e1um7>TWbQ6CK#0Vr?LQ5{z;H&9+&lLvF>s^`7ZOziCVHp zZb~7qL4Y6x24Rz}8-L%?P_*aMZ&*$Wk7HFubVnAED@zea7XNd-1wH4&TcrxC#P*Vr zFS=;JT^iV?Fh8(0;U;+j4+&HAd}&~npnbuieiz8@XW6m(ZD+n8mZ<{{K8ca z4fg`m0uSlxO5vxU%8V>D7`ho5$qp84kWELn%DE}K2Il@KN^{_;-NO!&PW>IPU=2lh z6LkalxlAbqQnaKMq3LL#2B1fgro$&hAwjGTSZZ6zM=AN)U0w2Nnnty@9$k$kExMtq z?z?nIc5#E`ya?$#HhDePUjZEt(0R=kv1E6^d=wj0vrd-p?fM3J!5odlRLf!4Bg98~ z>`6mTNtrsKyaMp&)y#&8Wt@|Et`458)aijN_#5SXMDxG$CBrY+-Rg|mm+=8AGU zz!f4n-W6$u`xOBec-D5=89A94&)j_ohlWLPU?t3|LD%iwf)py9UHF5*^n#47=?q{b zy~kT>TBX)=qJsx@wDK;Vt;uTr*(38E z@+ut*bG3)5C84!-wwoZeDRSk?kqy}(NFjU=?()4GxhBx^ev09M>8CLXc0!9EJKhrK z9Soj;5LNzEKz`opu58h5HWoglB)8qQU`t{()v zhZNg!ZJBz1m_v&rGy|+s{I`oow=hdxYsfVqo=thleaK_MgxeD{xTt2fGl)cvk$Jb1 zJR88n=t~ZMCQT+Ye=M4#wG9|ZSE*Dym!pC;Kmk^2(jm}5e{wofWg@p-BN#mT zdNbZ}msCF3<<>r*O=CAVz=PKKh^^;5v z)Ycwr5UL=ThWCeGcbt^2P+VX2mFQXqU|nO`0+(Q(_}&7wu!`pq4+u6 z!xGvZ$@%ic2{di>d#f^{T~Y46g3h^6ApS~c^lU4YW?`bf_%LJH=gi{eiNxxnIj7EB&x~Oe+H^Kn zO~z`O}Ey9nDnjTWXT-kh-2sgfE*9Z+7vF%7gf@V#=Pu2R-R z%V$U2e)9mXWbnS@S3WBr!pv5Mx?f4opN7w+W~t{h>^dLz!)oeJTM^XUNQWoDmR;`P zincX@?qvP6dbzFt{43^{JnhBTB;a#nvL}-}(0|9{ZU3Yu{F0a5NMc>m3Zj{DNmvW8@5xx6L5836M+r}r0awXnW;@s2RNxe5 zw`K1JdL(9eYQ&QU+j;SfR6+88i677H{XPX!=?EsQ=jB!V4%nIy+zI0{Vmx?L3d?9$U%y;`vyy%hbJ4EX^+b2EG};>w^5q9%T>mT?Ti`-VDvR=Wv?iY< zmusZUdU#X<$B0X1>P*xzb|ggF?){Ek15TbxKchr;ZVO&NQlAAK*+n&{)`RIyzYmg)^m@lM0=+^7Jp z2K^DFvsv=!3tF`v87gw@ko@)o)HTWZ#k2R2&Xh(HbI3TCywRv)AbP6nW$4R_1wR{( zJ!Vez7+#I`XMWx518OaHW>vzlrt z^2XZvKB-2%_4yItPYI~}@&?G&&$o1ypM5e%YZ$^kY(dDcY9$Ou|{HyRXX+ zbscBCD~0b`VIp=vyj`S_J8R+Ah@a%W)uSy2yXr)*{pV*j0}tMDMIL`J_@{>7VH`Lcf?P|!B|Czuhi zF(6JLR%J~x_pUZe#W2=w_5LnjpBZ~JMfLqA(KZB$O1e7nOd;s}&fIM>)Fpwqu(wGV z(ypl89}FOZii;DiKGLUD=FUW}68_JAgLY3@WM2DcDK}I=+xpEfb%OPR7U+tvJ{=&E zz)huM#tA}bDo7!_T3$TH`{7zz+&k7XI;Uw1==7`6oS+ZO@uv7JFIl8n53J2=dU@3~ z;+MAD^;tyvDiYA!ebE+R_da7=33K2el|KkDJ%@`Z&ge$&_urXZHC4dO_)$4Rb{hq4 ziz052=~^X?t8vgqupb~{2)tH8ra3P(WQBmdXqvryYRG-s(LXz9`#^pyCa}>=^7uhf z9YE+q9SU24qTiIzGTAd(;Kev$lTz2t-`r8 zFzgi^3Oawskn;S7c{JXJQaZK!h|B; zazbv6J?Sop3N?%cgm0bqtBj+)eTnFsK_uEr&6l(A6PdCy`|F05R{^Ez++)`|`$N{S zp__KYfM*qoNS*({U4=n{C_$lUn;MQhjMJcfAm*cG@=5Li$}_i4`QT@{PHn z>ZksuujbB+W*Qm;v37J$dkofp2Am80Cxl){KlQQYfJto20(^(CwL8=pr0p73l^aJ| z4!lu|T_vD=h2k4Cf+*o)I=F+*8)l^)Z9zkCayx4GTi(*33o5R~TdkOo?~%@a6i*kU zHnu(wH!Ahet&@R}k2Nx^DjyLhfn;8?0f)%qN1+uQIdGrd#o4x?@N4DVd+xeHNu+FN z13CUX?Xj*?*_frZb2v&r(FVqR(8lbKzZRb%xIkR#m-= zD0g(!^OG@(69WUPr6=TCJ9NZf3V$C>*5_8-5(XTl6wJfS>2tZs~^;S2TV*!$n%NIwu)Lnm}iKe=t;(#E%%zaX;{gSh6{?LL z2hLMi4_LzlyC+uN{qvDESfr}gC!mLEyKBL%_ILuZd&p%XxWQyRFPwitFa*+Gy;RpR z%*30}UY{vl5MZHoP(N61t9_Xhm@H@6qXBCp7ELb-IrXY4NA3@Qq_d_GpIH~kCO1M9 z^yy$WrdfvlO4xFdPtu1z@E9y^8CC_}?B_7K&lNIMzxjLKJGop;NymOZ`=1Ex|E2w> zEE_lmw#+bTzf!GYPEhrO1ed3FG>wqr(AG0QPSQk9n8v=W+IYEeOm3NmEYF8?lY}8( zxghEXh8$v}%QGb+)LbG7_cJLYdGAsG0jvM#7~hsuohTY;(QV5+SD9DjzW(v^)0ktL zb$InE$3Goi>uuE0p;nRmCxn_LFpOFFUHV!WcTtWEiP48ZTkQlEATa<}#@GAvr=us+ zt@r)>mNe0HhJaB71h)?4GGM60fw}fqKhrdmb;HnK*&A(R-fX(WB>?z zp#Li~@{OX=MYpxL;^M_eIjgXR%qhiwEw%O^{xBC9Yk}h>cQ_dL*DEw4E}fJ8cqWuDjH3rTw3=jth1f>~WRb7BDq+k5^0OM(6!tP2a_ z!r2u1+Y87-Or@X$Y`F&520Cr=&kGFjUsySl&Ovb=um<*bfT{S2Fl>}DtmOx+!)Tb` z0`r|v)=Y7?C>sU-&#UF1rjfamLnpD1hDVbT#f1vzRF$?y9q%3O#W%R6JlKbbI&A;C z`p*wHs7E{egtUaZ06wVsqe!ho0QbzFYmYtq!&3KUtI9TsdnVEKmH4okam04hz)l8q>;c4U zthaI(Dpf{adicDPH!`c1aq}R);fVK#xQV-DhFH7!Q@$Im zFE}l=FUgT`h$Wq`^feLftWAiYs6>zICPJ1&uYFTczsX>Nu^v!5p3w&}<9P+xu4f^) zy8l-y*cp?8&p~SIY9}ehefR=!az&%FGdq-t}Kro@A)q+thZqx zqX-PoR9sR9E#{B#pI`#FnT!=n3CkP;>?I5=_O{K!n!fgNvhXg~leb{(N)AFsEudnu zJTGmkrg_Q`DXMORr%S5fHb$wtZ*&Wg_8|=yN)AN`H%4UYVCE&8zZap?24I2@opMb$ zkY^!Q38|p<&`cCIY#XoHM9YtoCi~$N!N_0hy9R`K0N;n8FJjjp9ev$MUbvhDtH9c5 zJ5@X=UnEV>?`nZ`_?I(-taFP75yLk+i^nJl_L>$0#rB2x!?^JF6?cXBF2^vZPz!lJ7Yt?62 zlNaaVk+0Xl?C-~I!m$w|f#OtxJxo7@x=M<{@?A~}lLQ*>u_77tNT4uU#lL`Qa5JR6 zz|Cdly^3PU+`&(0i!YP=16_QdkR?lib7$`wtG54b9=57^Im+7Hk(8|Y?*kvvX3 z5W=V;lMOIG%=1$}0WfzF;WCKj%`-W`8%T%ul`sH-1^giyDSEYC!*FdyUImhXV-xAt z+O+obsgsqY954%Nea`ht-oo}ZC%?Anto22FNC>(0ltyi&@Kq8riDy*dZ>3(Yo#>Nh z)B<4MJ;QZ^4-m+3j!YgD50L-hFe0RMyuC3z?gn)34wjL+`yygIgb-85h z4FUkDpV_A7APpH7zjA#nX4fE3{Y9O5qBfp$s*;M~Ww_52FuK2OCf3TqfEa%b0020f zo%PMJi^ZZ6QRe&`AkQ~B-a0M>ON`#SaGut?iWeH?N&m%2256)X06_fWp;Olhd38-6 z^5iH1&WMnnqsvTo84W=wLSES)U4I(| z-IG{h_qj)@+Uk|WW-9|$262-j(ta{G6h0x8m3Sx6gx9)F;lY(r;sLgvMN{7p9L{X0 zdlk${CT6-munzQ_u%;r{sV_7q;`4Vl3!IRy|D$z-cG|fbq^1P+sg8@zBNgu2$1F`UAwRE_*f(elVQ*Qwki8mBeHu z9AT`HYVjxkU`w9e00SEZibcq2&Ke3W|JcVNHO)#sSZ7@YvZ|oAi1Uu4n6bb6$zG8v zXWtgyJh2%(Mq(NK<=2i`l7;hA<+5&zk9gH92{eP}E`s!NK!2RT4_=aPT$VpIT&ZyQ zjWR0Y*)hZgvA*Z=)cK8ZeX8Bc!+%UI2uzbO?R_1xuwotwvZoIRg z-oie9yPD4Vzj~#o`I)dEA?8ZrtxLB>k2&Zl=GkEbEiS&HndNQoku_1*(8;oQ_=A%5 zaGc5hv<5+HV)Z-B4nY4EH5Q(R{zllLz$8l)7{3sfuJU$zV7U=g`c1#J8eFFj+fwe_}d2xb?pplVEW!@Iu(Xi$CZnQ16Vs&w>4MZ<<`Wg=#=H9 zHMF#YEaNhaHs{a`fM#rfDyYuj{Pju zU22Ye%+Ag#=!z)0Wn?KAJoXgz{{fajX}|9^)03}V?A=+YCOt`DKY+RoHlc+kJ;2L| z$(*;cPav+6X0Ye72YvEk=8?vuzzYAchnO`;>>-L6_$_|Hr8a~eXnTz4VIc4Sew7bL zaN4VA1K?nB_U!8sAC_huiifMU&y;|M(IoP4LF1m#w4~vM&KxR4G}|00002uRVMffr$Jb1_FXfA+Z-ZloKU(dFMN`l|h{s&q z3$A}#d3ej07pI>Vl%&D2mx~V;yvxH*dVfnZS^Wq4949Du>EAP@Tsb5fh6urJ*mMVU zkdGxYy-xqj96(PQcy`0r7>4&xy#!F2ZQ_F@>5sndEq za9+_aK3v;S926X*Vz4d zBVa<}D0_uJSnHUw_7FFH3mEp0B*>v;o{Y%5`rSIbf?F?y0;=)`{{tuP9!At6!0ZP0 zkwdRVlHz$_g@@LCO!LtR`|4;5BJ07fv^8-v*qnTu;)CkNHw3i|Z*Vcf*Sw_I5s#)6 zK!wNaolH04_BK@b_kPL*ZCyT1ZS^wkB1SvCI*tfK7T9YvZj8W~AWR$(Yl1o?ahsx^ zRtjE)Hh{NePM>?6&s<~gShp#f_pGYbK=~SIA(pyE8NDwC4N(IJ}iT} z$5dW0hLx}px+%D5__4>fZ!mT|Y{$E~F})usnW~(+ly;XpLqGQ|V3%|jOg%PROj7aU zgl2VnN$!2$Xu+hBVSQ$^FLJ|mIa>f{YYf`kSPUBOAZM7-=y!0+0-TP)Q)vG7xy*@Ohi^h;%^^3=)m*g7FmS{#et4{{Y*>TCS8OZDIKyWgafcZkb>>h{X z!M>xgZ2uz(JFQiX*HXkqFrE%u6q^kO*8**Y&iKSRE3;}aTaAP8&MzN3Oi2)o0H4j; zfe7XcI-cWVqIxS9GGcSoPa=9ka#ad2+u4!cjA@?d-ENfob43i)3=3)6;0Rm5R?b>J?1SBWQ@;}!Cebpw+cc@f`LUI1FI4~JY!pgmT)jzLQ1`QKa^ciOXVY?zyJUO#sgqZ2QT_QR<$)2kA{XIRMO4rnHyt9Z4*4$ z_&R8U7eJ}f{0C=zRPu4l9~;BO`a|@ra@(Kg#A)9r>GnlsS#XJi-$mnc*E~$31qTE} zi(C?@n=^S@7QUH<-`|7v4#7lVdS)a#@B|0_d>*AFIm^a?+2>{Qrz(;LB_#;!LNF)3 zs0w=O1hhjSagf+tqOYws3}UeDc>L(X9v^kv(f%1EoH{?cYN)-jQi%jva`;=Wp7?l5 zgNuDNR2rH3lw;H2VjUM9=R$dAqKURC6od&W;+F#ZobDR*8mDa5zEqay(MqoL_dLpn zfEf3i6jT!B(rT|uYgfP>R@1gOFl{diIbWMX%(4%nR9O3cz;cqX@i0;i61jK7pB2^1 z#WX{0`+tkDYiLiaV;r=*Vh3p)O$mWiRj#I7M^Vjc3H-_wY?;E>Z3sP!6d@x2VRL~Q zu7reeu4sZrX7h_4N(2WV&Nx@K#I1pHgN4Qx&w?1d?M1Ph=q_Fo!{|={V4ppEq@&}t z(|Ob#c!!h&O%Tp`>|rR0G^f!fC5AblLj&bO5tM85?ap0 ztgJW$w(g!b`c?&a_S7;L53KKMnMY_G#MlO&Rl2(d zZ;0k84So6AcDH%f4K8tf{T)+K7Udfc1dDl`F*EhZ=y;Ut+U;_8Ru{W*ZgFk}v9SW6 z>GB}XWG0m`4pOeU`Y%i~S*;edYU~=9;S~|N2#OK(duaRGX0RHJ=ppKG^#5^*TP)=hj<5DB%*zh|5K9qh32FQ%b;6Oye`v)t`y!-uw$cE zLw*B!dhHG)%LJo6w#!NRr;|Nl!Gn_Dg36Ivbp9{nNMgjGVBP0)1Jm5+HvOw z4slyX8}CSQnMXWl*sxCqHLmi=LuwHA|F{cSl+*kjCtET2H8Fyl_$pRf$wa(mkIvIL za2Xh1eWv_vMQMI`{0BHP*bHOajxY*iyk}M{1XxKhH(rS{7kw4&sID8!qqnX(F)mEG z|98l*&Qv<#9;_qdoJZk8zbag8vAEgPREwl%M=OR)Yz-9*+T@JttlMa#;4FIHw>e63 zu{h_}@2Dqvdix!WE#n zwyCh--%p+fGiPc#pjS`6@dWRmaT{eO<`JIY9QKO_0_PTtE0YgdMaJyjzR ziozYkt|wYe`N>$&*p1!mthJz#&sY_0bwvnS9Fq0`Sc2=Kg8pOZ*+-(fV(wQ_bJV=00000000000000000000002WEl%O@moU%&Y ziEK#Hzex)DKp3FaD&iCF<<5tEG0s;}yBrWL0d+H$O?fN3iW2o5OZ@`^7F`x?iDL(+V8_kLAau_ zYu)V#7NjI{wm`Kb7g8Qq+PfVwWmoIv&eq6vI2D&&gdd7k`a_@q001W8G^mp(0&NrM zX)yC~u3hmSp7wrCdg;`D9EMkWBj~A1E)X!Q=2a01HTD~j+9r=JX_?5WFmHC@X- zS@;qnqiX@M4D6V(f6EnMf@*sRF`+`iUVaBhy-j^oI0=ofJ>ieNe+t$hmUN!Z#pm#-R1Y}^OP>`e5cmxluCc9mRNrT zkDX1N&h@S16%!n#iWDomL=SfOjprWvb7usBvZ(KhQ8b3+q)X9hl-J2f#& zFl%ykf)aT_8o5=$$#Bx6$8h|ORVWwQ-pg^j2YGenYD;;9T6|B=tV<#ZkPl4wuG{as ze;Ke6eY=Xc&RmfBB^OVOWv8N%V{wZM?}Hl!*x9jqflR7ENuar1W5H0 z@Vn824~4s*z30tIZy2|J8Q@hNlj~6y=TwE7RvKeJ;^5*L1}_wHsSzG`869#j)+MZW zUm5?JQ)ldvYZSh&4?kH-Xm&L;QUnmlmdEsj8-xn+iouCtOjP(yOEj>wmUKbDM#E{4zf&WftYlDNBHYvIj{gACVEB-q;LB2uI zhtBl$;_=Z8A?8BKoto>#!U2tY4R=b-k7ChRm@YIGxLK6-sdTz70}C$He_!h^&V>fP zwv1)j+6D#9Ps`lG5qTW)j5nga1OxVlpPIdtdj05t*=9evJ^M>$+EN`h;Zl%z^-QuP z92y5qw0)|z2_NYov$(&~;%m)iEu-%47J;0udigIP3=TiCis}olrl(sfaE$ZJGF&m# z=fDRNxw>w)TXiguuT)?a+IMKeaz3E<0z-C+W0aZ0TkRAwbkL$NTM$Skt&<=0ZWJWnldZ8>&3@ z47W$U^Lj2`Z7#p?%5iq&XMg6S*|7bx$YWugjG(k(;`g5kYud2Sst8-*Gu1U-9|;8R z;Va~;H}cqb4Y2na|L=u(Hd-=DC$zN>E(CL6!m&Qh#yHZ?tGEZn$TI+bFaQSy_V9*c zvsd^|qrsg#JW!;k=x@SgLa6}1i4LLeB6BwC!--gt8kI%30|-K&|NnkD&Xwwb*oNvu z+7L~XgRO65U~$F@!zY-N74#(Jnvtc+wMiF2R5N=guoA5a!GFJe9_|II@>o?PN+fX2 zJ&ik)^$+Q?~8x5caYwA}5i^1hI#uitOuY_E^`G(iCA^eS7<-br))*q&$6Zx?J zQRaMiJJ|7 zN4l9HGY)PV1C=~aHMd7mt7hRJ7v|LptAz=xpTT(UW}S>Bwu5CrsQj~5v4=vsIXl#U z+H~Us>*2I;27Su)sz)ZF)1eZJC z57B-$__Vt49QUZrN_TP~SMqb8#q|U8#9*NjkkFo@%GNjJm78gpnWX*qKD>^-9T~v- zf3n{~6>nCjQRb*tf$(R>f>p2Xpf($&B-Z>4H{7eG0Jl|SV?0?|E;uQtcS(42cYhAK z?-z2nV+o=1$DUr_dQ8erhKB{(&Z<1EwG409tuEi^0lzkx>ZNmz?0G^vYRc(j9y?DFprV{s-1v!4 zQkB#A+#p+BQtV(HAAZGz;9SRknpIZd3po7I&JkX5hWHE6if{Mq_i-O^Nw^tC%8cVb zR$U5YfLpsqZtu}csAQVshT3Y`M?rP{JGkGA2$a@IMR>~h=ll@>=i>Xs=H-~GR$%?W{8)xO!)dvNLxNVhY@CH;I zZjmPc5y3-11YFF&zZWKnz~jQY;V_lVmmQ7bZOaG6&MzpbqY1f6f%Ti$ruU^n(Ha#n zR%rkL00~Q1KWg?Vvq*V)U*6Les$K*l3$5*3J@KPJhU)=@Xyqecvz|OfuETOXgb=~F zidfC7_bkZiX=RvKLV z#jRY1;j46Z53xsi47ee9sAuFvI&N0O%9W|58}4>vsTZ^Xf%auxkPrKjIW=4|15tgn z%VQTQf_?KB5(j`^hIT<+TO{PF>^jw!kq9-R+HfG?v^*7fn`6K5fG%83a8wZmjb-^u zQ3P^8UbbtnZj;Avaq+>&r9l{=d5L@h+ZO=pw#UMDuUs8_dUL`21PJ+RnsM3^?lI4Q zHQ+4pknUify2ccT&LD%^3LyAYVAah_gER5%%;iK!f$n%Mvv=d!o6(ML(1qv!B`x>V z{n%l#6*IgZnkze09clQGflu1x%(j?8?pB ztDYsY-4vzeXA^DxHbsdw+Qb2x`*BH5Zo4i13I+W#|T#SZE5HuRY-lWMdsI$RF)LmF96SB3YW-__a()s8^<1cAb)S?GHxYqMPF4An^$YHy|#)Ou(Q&{;(CBrk1=a zMl#H0_f9`MZ+@rjq#cDsUBHhkR4w@_)^DuzKY`*Y1Q}`g?*1C7SH}RLbB@C$4k;YIRe$1*p+w};1p@zN z{nG6$=&+WtS2e-#m~CUvNXN2`1pTZgOhvSOx*B# zmv0#cxIA#L3b2Q=h{70fsb>HH00sP`_Rw`IUeA)H{*SohE$irzE)fgks*MfXs4%$^ zIvdGtK(EVRt;h5Rp!YBf^nX|26^%K>Sa-7{nM%=1r8{gLv~qEVB!83@JN$UDl177l zME|qqvy(?Xayb*&LLqAer-M7C@~_cH95%RF$st<~n*k$>LIT4)7?^vWXBHk0bu%85 zxG&pd&4Z_5@3cI;34f`cD8VN%^6|_ROiGEf;Ndo@%rnr?D|(T% zACeBG%UmIE0)@OtL0`YW%@LtbSzR2#g-n_hR-3E6&g`*JRKbbS{;R&ku68XPq2%+Z z0pCZQKlCUAcU)tcQI}kpp;3wFvqoWMfOg&9kLBiA)t5@f(x*yX$)DwalZXl%au*^% zf@lL*AXE=p02=)a;qdQB5-v=jV;yC?x^LncFINv;zk-t^jb&a3+&jaf-&uS!1)vdz z&O{I6;bMr!ybzBVNJk)A@UOg5t_q}8fzyC)e!ko#1gI0Xa*(m=eSC`jR7YUp)P!E z?s6BS&db&0j8DZzPZ%t=f!f z1;4La{=}ZR9!k7Umo%7mi(2DA-cZ_04ZmTn(po=QXCR4{7~^hW7V!jdwRdTKgKS#j zsVz5({bO3)*BDH@B!m9o`%lowo?cNs;6@?a|J(?$YqMkxXJ(gYINK=)t6`Mm22Uo( zkecPB-fm3v?VJD&{3sWIoKs-Cj8ECgG=8yX7dScyhhXAho#7l zw)|KtA-+pFr~ElhHPfwfeScOGq?7F;pZU;9b(I`74>6`KeR{qOOyD%{%0G>>HN-aW zX|gK#bwX`0c3JqLU=lcNHa^=ieEELa=mF>Ur+7#c94Z|mJHgy=003{;06}AF_qf#f z)cGgx=<;>ITJ^CJUimb@?0xb4oN3AyMRUEOKKA-^1K55_?k3%X*p2*7z-NG~4?#crJjAOt&MKkV0LmTEZi zXf-IC5&{rDHMkei-a4!B3d;^y?J@;}3w}u6?bg502+&Iw5K5@>o-&P_=*mVponl($ z;C<<60000Ru#-}}vM2;1j{n6&9d*C%PQrC?IB~pk)EA@*3QraMd*Cv3l!yX_;D7_K%z4OxA7aF480F#S@=$s@n_3tlhL)ZXE z>=3cZj}fGGiBpB{5d~s18r1Os$vfSK2wq0|z(}A8D2tlzknu4=&Jdsvm`M=j%72~C zT^i4D%p=YCst0>J<>cSdrat;=jWAU>rMjB8zqlg;Y7n@N%a06Y?~fS#C~hCSL5a1XBNc}7q`ozX1)ijB4%5m`9H4dbk9I&VGY(`QV~k^ zwm?-KT*;Kl5j@2?tC03GHJv`uFMu-$&y4Q^zNVX1Po#$&^c8fA#IV!STv^mRyI`-Kl7%2_U;^I-9_%87E>wKxbn}#K zL7YpSL;wIfA&^wB@%fO()u{r|uLy@wT+4BhptyZQgn{gcTHG~D4)Q`-A)H5w@WfSC zyW;5veshtN81l*VQ5=UO!k8JC62oa%_xC4ZE5Q%)EIG!CF`OXY^z6az;-_T({O!tK zO|ULz_b!29<&9W(83JLTd39*B<~@pmd>sJZ&ba_jqUwmcKj%^TnR`xp;*itlPe}HP zLr}i9SK*&Sow3)r=*wxYTM@&-RI97X(^7V*abWnd{rm?yj~5S$(YQLNhv|n{y_~`_ zG>AmDWG#N}F$Wyx-=4RLag(eyew9HP5CBR$fjz7hmDW9sIj`5ALs`6%COzH~;sH@0r%h`>PN!pS*AcWA7dS{*um}DKb znj~s&M>#Py7R^ACIur88U?_Fi<0`s=Xz&040=YUYuTPHtpfFACz|#+7lT)(NbHk8y z%_!4=hV2NiKk|6RKY`L)lymEa^%#@2n458qfCYI)Z#Nc@g--JWDP5PHeZPqWGaIXz zQK5HqKv<0cfSrW%A(WADDYInEus%s&(?#=*g9Nb00z~-t0kPGDT)QmRYJK8WvNH{| zq1q6ok-3P;hQ;|Jniwrnt1>%$)bifsR~^)F;HTEsSY2;M+J_p_Ww#}OM44SQrx;s7 zCy##64~KPz@Kdx~|KR3-93@G}Ry=x3LlvdInDr)m*>%jM+L}*a4H@3yoV%{4ThNO% zdL=bAl4^rth}A$jwvW>BI+onbSvf6hnb7DYr%o+<2P0O%UnQbnT(KBurYI(Z6wbqZ zbDQ582xP}Sk7eb;yQDz4@Qs)`S3npABtPhbiPHc80SJluj3SJ7Cjg~Q_Bl$W!&NYj zy>k*6b6@_((=cBCMlK~J9*G4erE@@oOVQjLh#2*N3cGFng_?PUG?A*6cQGqE-%|w#(w`@WhAwI<|2b43Z z&^DU_C-ZA0oFt*`vUPv!$&^yiYf&5%EQ|nL!PrUOBUrf%D5-NPW}aCr;p({_o&OAeq8%k$EZfAzVZPLL}nhwhc!G2c4r>?l9fcJ`l`T z5u7D;d=%<)$@0xd(9T)<#@&lj$=1#_WTD`o8y(z84C^2T9p_ zm`U&uu$e)ZZ8HpnNSRJ{hI=Y3Tpom*cvKJoA5!tgE98b`UMV1SWV(gbhB=~5j;z|& zkx4^Mq19Pb1|UGn6)MVJJg>F8pLbGwSKsThylqa4wFV(&MN@(+)^Y)*Q^ewjIgy5G>foaDaJIBaza{RNRt7!1TIOYlt-` z-|o8UIc;7#s2!1?WT0D530_sf`U9O#YsiXAsqTn9*%>xxtb{=kUbe%t<)+^4JKC`8 zSwMbjj1_l%XI!YexsX1^L&Ad^>05HPGjr1jb|rHg<(Ur7xY?lCP`^au%+57ZSC*h) zJELBik$8+pOS>%JB`wt5qo!xUonc$G73+^G*oq|ry}V=GhRKVDC~G<+LRoa6?;0{* zAFUNPe63+Xta)X0iIau>IAcJ-IyGCJl%P$#x)f5hvg&q=K?Q<64+;;!s4{m=)uSHV zZF_-_BX#|Svos8W@Mrmp+lYnjUR{D*&@1=zq3Ld(MasI6>S$Y?gVG6aHmjQ^GgJJ$ zG#+5M`Ab+i<5_s$`G89=YRnq_VSEKa+(U9I`B@jAJsKC#m1MHI<7csEeRK1nR!+O|0>;M_52ARmU>ge00@w@O7Zpdp=0?dN*J z|L1}R9cm{bod--BHa@k6C;yLZy)7T4Qy0Wf5>Ool40#=takvLPOJLBAe+jZ|?XE)d zAg8&$YtY^E@pOtV0063Yphi2G5ymm5Opn%H%V5n1$ab#tor4k>zrio8Fw+8Z9o-@3*{IKWXOGV!B@6UwaVkjh z+XcK)b>o2zb3IpK7r#s_k;*&_n}t1RP32w((jbGe04qq)8~d8=4XqdmPOBYN;pbwb ze)v(GZCzB5z|)s!d;O){S{{QOGX;5a*b#J{bJZWx()KBGD%bM3h<#b!+f2ZM1Q@#&7=Q8=Fba=+Z7RTdZjS*g1f%#ttThha0P+3ktV{LK z{MmLz1K_bV?J2dLLYNs_8^gr_B(qDNL&4z}4Nh!k`{1WSof+Gu9GY2*I-$KoS}w4z zoK4Di4Tc}b@zdHT+0&18lBpXXY?ACuCRSGpfS>^dOOFbjKtPK=b%ID#zZD~0SOFOH zW;w7lW^DD6arO~ZkAZ>8Yc2S|joD~;( zC|b@7fBIOQt!zhXW}AzH4v)SC_H(Mo)`6!TTEz_``p0`MZIhLMQDR7k3#u{Wn5`~Ix|67D^obu98l2CRK27FZqjP@ zXRa@6FErMm0003{!@tz=6P~3V8wcFUj$l?=eYtsVw}Y(B%^!<01Bqg^glqefwaOfL zioal*H??~H*`#Zd0g9Z58}p9t#p#sjOo|3ejfE>f+C&L%)*EbrRAwvv`KVi)?Y&O0 z0nn#ibrPDtI;ix7v`L($Q*eUcg*7ixw%qA`!gXBAwXWk=>JbZ0d5Jc*j=3}Q3 zu(9P#b%V7^qgJvv=2u?1H>X>bPxEwzw4ccPBc}zFy^?oPmtwJ(%&w8Tw4VpJ;)$#7 z5hW`e#2hFty*&5}e4JFf43=)0v}gziv%?nm@U4`7C0%9(14=PRdp9-92t?=#a+mIX zxzwZ?eO$EF0-w1}hwd;ZS8&^WQJ6%&h^nBfk@1HVeC8sJ8z~@UAx(LPVsFDUnWB|D zK(-@oJWudpC}J(pgMiK|q!c3vtEi-_ROBHRx_h6 zBlRS>INrqL2E>O$syde2MJq#sJR$TUtoc_h_w$CCz1l;5;Hy_Q#6y{Ob!7{MJ7oQ@ z%27%}FHfS~S3G5%&HFwLjS=jtHi{eVL9v!Kr#qZ!7ji0nFUI}(2VGwj^hB?? zR|{@`#S z?RB(M7S=+$EFi(o@uwLvrmqOokVXli3^M%Ajls$*rJb~VTR>u;F`b&>8k#_wd+hiP z0r=G2hj}`LByWero{_^Ko{baoWM(KZK8AurKA*9EYrkmM?1@3AVX|nRHGzqkmn`3ZLc*SYWch;@ba-^LUtNV|)o8&X2VQ>CuvvNyg;SS*Ae4I;Y-;%oEDC{t~3PkPaf68%k}Am`nK* z+uH*V5OYZTu$84Y!d^AfJws{P*Aj;$ei?VGaw!%Vc7@Yf=njnZiRIMYgYqp%F1%qigm5N5z1aw!qw~u9F`&dXAE;I*jBo5W87Ow2jj4i&C-klB|{!0x! zT?1N%wX^=l%U3z+M;E|(Jng#i;2k&4&ggnSz^^FNcaG8>DeK zhb4EAwUIEVh|z31^j@$T6Jh*u0n%zWvIF@&%gyaklt`G*fuwsPGeaIXe`E~>#L=rj z@gnkGjl?!g7EK3=ZFqz#fj{(9>{{a=TQBYOHp!=|)K*G%SE((GY;q=}g~x_Jf8Q(U zl=?tpP$g^NXqXPhda|(Qj}Fd!<)31+3*p3$$NLwa2Z^Z)$Bda-I|;5CUaVBgGr;Fn zv?ZI>N$4*@8HS$f<_PWNHMw@5$ueKslGUnq4j!(bhkfT>LqbuLQNbXhqvrF99$Ruw zUaf4Ie@pefAxJX66-q{pC^0KOeEP>Bpaf_HRz{4>M>T$z9Mf1>NO-A%Ew{{r5er(b z2+S+*(-~l4=FFbYpX5VtWaztkvBj{x%m^aq7G!ys<<1z(oxH<8a~gQSEyNU!gPO9A z5h2>mH1Zh)#!wmD-V^b&V^jX}aW`9CpPU5Ni1V?gTFdICnfK+dGtX5w z!4A>^8#hdZ)1Y*p1;S5nqqso+mfvB6^5O?Axo39{0cLo~#pu7kHcfKYCJcUma~J!yOpQH@TWm8)d7s`m56Fc%VAx4Tns|-vHgDszEY%Cmp%9L4{W#HZ zJ_FV5xKUNi;U@y~$!bV*0Q$KB?z=Wr`J+>F$u>MDR%Qu7fG|G&?v2=g_={jtj*(WT zCBYW(tn%1JhtIpe<8)|(u9W=|ixk8J;*u2e42N?JhwWju z1=`0^?UOtgn&u}VYn--afCc(rf@7p@8+Q*2o*Wc5cf0F>dfYoS$=KdPy^toin5piv z_h_>}>@W7HWuC2J+rsHo&E0i2=gGUCt(Cs=uqiqT%o`+3JpiBo+^7Hm9;~Gw;7bw0 ziP)o9DtVy^`hjTlcShWqcSVK=8OCh_umgWVY0QV}K-Z}6rf7{!Th|q##^kw@2ZEQ< z)!>mYNlYagg;dHTgDH&jdxd)R1&jq1^3C^ZUoUW4Oq?=Nv zm7}ArCYtB2CP6IE+m1^LYxH|HEJC6U2)xESN*; zLOw0ClJPm{hXCt&WYk}$vXb0HtDAzxC-ZUPy{N=E9TtzvZWB_+m-Y|)k9V>i(ekwT zutwC^7o2N=?U|BoxM2!ZT!4YFDqOZChW&fJWVo98V|y7#X~#%53hY?L`k|^wZHn!i zL^Dg~MST<;ia7f7P2B%(a1=H9OOT0p)@oDxiP%AtbgoC;Po-b}!PVs$Id#K`15>2x z9hH;Ddgqjz^Xq86VQBg9@pey{x`vf69_SbO!#>-FgvztPH;Q;K8 zJjS5@hl&&RSSN4 z*SjIkFf8q^-{X6Oq=TXe%@N|LfzU?h0rhQOFwE?G(6!jHy>9GDxVJv+9aeN-3c z1Qb@Lw{FALGJ6eAgY!BP~i=sB+KO%eX`uz)weH0m+yrVjxW!Fi2DNSnD}#9 z8LI2n@Rfd;e#>|0;<*lSS#lLaKxjcShT)=oW>wVp?sDsGKM1HpSv%xog5W2`YnQ3maTrQKoW>24|~@Su|{1I9*D3LMgTA z7Dsw$65_(uq~-pignXh)IqH7;-I{+*r``&T@HOF1aF4~Nnj$v-`9@rsf_Tfb$}Tic z$*s)qm9{a!v(D%A@do=c#!rJ!!e7N_Qn%jVOvncis9F!%P~yQu?#wvxx9sL0E7v@b zLS;{{zoy3yLt`@MVoNC$E+kfz?8dJI!KA1DMda(21gdS^Q`lR5H$by+hK_5!PM>Ax zb_>@%b_6A%&#TJL`n0|(FXlMb6tRPjdK^1@`zw`)IG z<|=%8pR2pZaF}q6Cn{*Lk76{f$Y@9e^;J?9?3=MV0u~)LPpf5Iu$oL$ZMSJgk(Q=!=M#D91F+rJRq34!-OWm^flyMabb;tfOLKttHDAi|J4mQ%gb8+?k*m z&&1O4W3|l`cI0_fad1wc7FV2n&jl(7^nW~7d;KFzj{6{aDstxu0Z}+TGtAzP7AG2p z1W)rTU1s5He^GUYv4S5Hlyw@9+RVC{LJzB}(wMl77WoA}MI2%cA`+V6hDWT#)V1G! zUmPf>35cIm?TH8zO zHVO+60`02w2lS5kBy47cgdq?qQt<3}S&ufHsEQ7>*~2gWXY`i*`4!L!sCuf3TI;bu zny~Z~skd|Vz#A@rIx#omR4WOR=GD15zuGf2KEUr5Z5{tZIBAVjcmDewI~)oh*_RanUj<0AMYH%0=@cEy3&OWMwR{E! ztlR~yuU9Pamuy3-Q(fTgQKkSM4a2szqwT41qoc9ZQvdr#F9==-#un`CeP~Jo&noaL zV}SF9%7=4vWDc0R0pCcZU!%8}rv*gjTy2vB4=V14>8{-}VL7fWa-fOf2{s^~w7AiT*iYh9$p!`K|-; zU9rpvjA<{dO*wLgo`jXcL1iOSlTPI@MPx8$09!vuZ-}Et-GMx@*pl&BcvA``X#P$6 z!C@MBxnVw&?h2)uEfz9PGKu^HIZrSYOn@7Jks=2@_k@ZSPuA&h04iiv))xq2Sa08z zQZ|C^n6qWKQlaWqZX1!}c~cGpd4{2{kbu;uHX{O7aW5*Jw3vOSYdr|9clW+>xTsG< zatMBGau17Ur%s3>U{0$z7L-%`GGTI8S!z?ze| z-Oh;4lww>c1nUlyC<M!n z1knL18POlIqvQeyd(;kXrlR(nhP~RqMlxZt$73eR*g@u0e*{$YTO7hrNGzA+B)b4# z7~Zl!hx&@ut_0l)gLe;{iejb!0000O9qz-@9L8}ig;K<*51F3qna<)FX3DfM`m+`T zLU;fgR^wu>!;{E=&RrU~If_1`d@?6!W9vV&JV>T*M6h5CJ8&Ot!F*k%(Mrpd#17t# zZzH2tuden6Jf&h4-3tQWDE2j{q}pmNnvw9#^*K_BrS^#-UhA<&eARut@-AEe@0WCghs9t+mB$ z9o#G`0LZA^{aPJXIQmzqWX3RjHTB+_ zNZVrP1RhJ@RJ%>?p`8RXcVyp6EV5raN65-?NpTM6ECKR|M>Gu?I$L$qr+LU5i)1au zAm`O_q-;!9h}P~Ot|3dQdh^^OIPn(V&_e{GrQ%B@v#*la^$hWEPx|g%BuZ}P*A~Tt zoY^W9;HRC3J$AEG7JbC|7eGQZlUa8j5+6nC{GVHe@^AovEVdW%RcGMyr`{wk*x^z6 zfJXv_09ZYfuM7a6D}beDYUo09ibzJDHU5!E%>1ZCY7sr4(4O#X>;E@wcHpP7sP~T4 z@bW80;4SxzHWh?sDqr>?aad^-IyDRe*=zVSEk9FzdNJM^*0skmwmeKGUj?(99d@kq zkfZzo3y|M;pQDpfD-V8G?e=V;L+m(Vj#pE4n=Uy_NU6?H|r(b zGA{N4PlsDV9YFSpRvS#W)L1UA!RwMCj2-`^xsO>ml5S947|hu5dQ;INEQ(CWJ&jXj|!qUHf#;RQ!iT{3O&Ncfz zvE`BA?`&BtEqOEjkWbmCqlzlzRkaVd3kto{!$9A=o~Q%srGyeS{hWS{xudm!nJpgJWtI=s43d&kop1@&IXWPnC8p>^nX=qHH6 z+Ta%q{Wkce;>W;Q8@=0e07>ywS13_i-!T>cGHyEjZBT6%EXMcy*EfGakX3J+%hUSGeEsU-z6-`JFjCWt(@>G#zMVGf< z@zLBV@Xx-erEVDKB3~$pnDb@JS=M&4@Om93?TLNL-#Bw&^6N*jZ^eIGW}p02o~R$P zhYC~vhUylr4aCHse%tjyIpVGxZSsuyL`iGm9iY;V;izw z{NlUDmFOqgzdt=Bdk8V>Sp5mh0g@{iaSB_EH37tzE=~IhRoyu#d1HdT_$v+*m|+u{ zgbH6@=Anfh3ExTVJs-qZ`Oo@)+d8uEd@qfko7YW$$hZOL0IMcRpZ6cj0ZRS9V0dX2 zyOd+lX0*R@o&0hF%>hHV+O8)Y;fv8e|Ka8;fp7o-YewKymdF0EjO5j;Ll2n8^1yet zk$L;wX6yP}f`VUSF5K&LIJ!>2ZII|s_=5+vp^)vn(H3V8g;<#mARWH1r@aqIvcHZLfC>Kg3PQ*-5_oF z&bucYfHs4&*%gPJ8a;efl!O}8jQ~YH;0mFLArci5?Gx&JA{te~C}Z9gZaza_upULY~7pz1` zhMWI4OD0JD2PZ)}XGYjH*QoG0VXI2r^;KT;r+#6=PQW4Ji@&BZ1l`{S6{`5#Fa2&v z8Ft`qV;bUb$qhk#+5I_@Hwm$@B7|Ms-q;M~@%78kYCP-pgji1DWhQ7qw)Hnt>_>j| zQ1BhP3Y{ww0G46ilkujT=lEjGVaZ7C3;f${&buvEFhQg#3t}c)F8Rf_r+^IEK|rD_ zEib7B%v3ZU0Zn!(Gs!CSMF(0c`HuFLeK@ zyMDavG~`Gio_uAih)biWMQccB(~$pLnAg5Jddnm^lTa4W!2&O^LW^-+y7eo3cUGhE zzC?t00=$ufVsZ)BQ=99y+h|MUG;zr3(KFBKk_$LSkEfc?G#5zUYV)N-`1xmo5E<5y zVlO}l?m-Gee#gt$yelW0sbB4&@SIp005?F$zsffGbbajwAosnA^LJe1$(FoxA@WKv zh;Jq^R5`DQb&P%VLvRFa1@_BRV>p7wl>V{2^==MwFk!7~YRe@)+cUSxExHu0?I>a~ z5M+Dhj8EY|G?*Yd*2|&9roY;V0UborzkS(Cj1cZ?hYKwENNYYb2M^0fngehJXT2FL6*v`(*nv@eG!DWma;ekvXRckHT?TKiWl< zCd-WptmXTpL)+YcSXor5c$?oz&*p@YB_B&Lni|&sBFwO}J#7>}S2xu>>_|Ngh$w!x z?wzpm_$1Ars!iw<8RXRi;J7C69pG=j2x6!^a=bt7N@wC|QPaLn>g~RH&kG`P)lIYG zy^Gw?MH+bC2{D3#<1)50Y1S*%0GdcCzob&a_p|Dq+dfuc9l6EC%+ZK6Pucm}rHoF} zWmO+pCk}?^vs})~jUZ%Z_z3_20F#@~_>=LF)tus}FY5edeBDt0B_JgXhx&CEY0O)P zrL|y+MjVZlFun-%7~i~YG65?zHSb@p&!DL)$Iv!E=Z%pq z?cA!m<}?kT`A*D=p1^XZiclf9yzgzUU6SP8>6%oBtU=e=i8>~QW7)y{?jPWD{GLh9C1^Q63+~A+Ji=xfEFrY2cZJqFGRYgJYe(ql~813%* zG;Z)9nm7q0TiV(NivgG@4l{_irT4F1cYHQJ4srq#9TT<_rA$@TWECW5>_Y*9oinTv ztF-=2$E7w#vnzf#IrWbc?2IPpnD&}B8v5qW6B}rTrbUmg~;_9SyqnBG7CfxV^O4|+z zU<#^ja@_f~F$uPBUH14Ylu5K%!w8ZM#u8C6EufVxV>$%hLk!(0=Edq0Ll5$_WSa|I z#S=VGSEFk#Is&mxQPh^}z7W>#2wj-1&CF_tlOs zBI_&|%|HI6?K})6j>~Tb4&h;oD6e_$^D;284!TsIM`Qq_D4Qc8KIfW77y*xd&#+tk z*8*Xrb7_D(eIuw>ZN!e@L4D=I;?pJ zB4oogBPUN7oBo7#R=kBHn9u!~vb@@|1&+IC<&cQ2B#YvOMRb?)f|)hq+^4(}sYRe-rEurlj0d6hb2zl0cp#y>;)YeUM2hA^YJ3o$thkYO5|!4X`{d)d zH)eQyNi`z!HnB1Ayo-@u#&p zNmwsgK8@Bv$+d$34E<#!Mn0ng*A#iDn0U*53j{a)7Vx7THY;-udIj?1C2nbe+Kb$b zN$;M;7e5PZQ%?-5%J6&}Nc6w0&@xFQX{dao0C-Pz(ZjiM)B5JxvelIIcTTU=t;HUh@N^^$>eG z8{y#+*q2C~G$m~@RXkxXB_&V!!ZSPehuBjwVq&)t5nUh)^%(lQK$VcN$?8;fLQnoh zZk@Yqr1`obS(GjSROG8&9wK5ZgX^@U4n=r*=mCS7ZgBF-1gF#bFKA6``v-ByP*|g7 z*o=MM@6#3n7WNN|>2L%jztE0DWgSq{+tG5Z#lxr^FFWINsZWoKN_P}(Nk{BQ`~*rT z{aUO$041z}X<>#vrnKa?TQbs$uvXQGW}i3Tu&(q4G>Tr0Xih!klDVz-@dOcaHe=#G>zs>0^04y`~P^|)4!mPjn4q{?; z0x#d@2zv8kEDf*wy>{hQ7YnSET7us%g{Nnezlt3Jm@=yYKj`k%CMw|gv_dJ53|!x> z>Pcl%mA>s8tI&dZwBeuH5XOj!_xI9?4?t3O`}sdfCHR$=a2!7$z&egIzf3(~Ue4w6 z>id4w*|7c?fOKg5h!^P~b705&Y7@=TeQ2rAckxo4%NlhYY^9|=Uu_NZoFX?D&P0pN z0Zw^r_51M(eJ+n)ktC+opU8%&d-yU~WN8uSTx-g*tn(JlT3lS~_$d^*+_i4i=7RkSP>zucMUqh+-vfZrLRm-=0HO6lw~0B7;>zh8uHrX7~QjKIre^;ztl=>F2N0xCLrzv>mZ~+88eE*()>zB zqB1Kub}AMYQoCz-{8X5Y#&> z>IN00_Xq7tZwnj@)2V6W9KB}9r~+AQuQQFU7^AAEWw=z?OdU+-X77qO7B+ae$(lwL zP76hQdJA=Ya-~AUy(qgprjy&m5*uVKz%u(Z^j5LXv3&y!_3L|Vi*A4U*j6#lX30}0 zq0MZEwKE@Pks{=znC+P)2t-(ke27?2pzR7Y3O=i3bzVAL00XASYuA7+GIXALLl=30D2w)|% zI07*K&7|OL^Yo0QZmP#o=!>NsFQ9^7!SG0n1@FP@DuTBVsYfsb(8sxKW6jmqan?08 zKc(*lao|^(kNk_&C7F8t40QYCu`7kHF{=8|tE#2N)-5uhvY|XW5wrIu`A*hXB^@7p zkVavMTjcdVIpL|j8u`C*#$!CwyT))J4k87ofZER*S`LE|W*$Z`5R8A$0dEucqq|Z` z5V)=rN73B=g3+&U1_w5E}8!oQMghkf57GbN@c+ii|C02uDg*hsoJ&2IO)-3`n9UeXUQN?yDfm@tFCW{zc{Z~QRL#~vXEWc^I%+RCla&re>TdnvBJW{@2uM05 zZ+YK5d3cjw&UhEWlF%E}C^fx(WW&Y~Z^GZ;J)A$I>6vfYp6<5&5oKa0=MoZjCC^(3 za2f(yt!;L5Q;hvgqfQ8oT`ECtHjMBgrbCgZ;(!ycH9^)VUFfKV5Z9%zL}%jKWl%lE z5!c7&9o&gv7b5e7nErTwlyjaLwyla2@G4;??Hl5ZLvu1;8DW^m*cj7SwV-i5&b*_m2$Oxjh2Muk;qYb(Ebkn`ltCx{x z{*Vsf$ZCj)Rp~dhainQo9R5&F&n+!17#hP4G)SJx0>+m(ePvzaRY|+Dl|BtLN4~zE zK3uUsgDq!gPtjMbl*X%DUZOK}U98;F$nV}(N4c#ft}OCZ753!S@%B~9iSke)gVlqR zZ_N`4IELeFh?W%LOy6|mAgnNfY-Q4Hgy-b|&@%Q$zW4w@mPm~q_Jg~?baWZOG*V4^ zcP9s&yjl~?0tR0M^AvP>_}T(pbEA-BlKa8cclpXiT&F8<_-?g5C!N?=!V8dk&yp;w zb9ed`IM;OzPKUnH;+JcoKjAww-p~tjBJrK)4+SUCwF3()kD7X?Y8Wyxe9)6$#G+|C zG&8{wvw@va5S6X%XytyHkeMlwwq3fIOT>iCXVnLX_i7TUXTKXPes@!-pSIao-LVZg zkrJC~`vz!|E5K4al7za;U7oXXn*ynFyG4FG{{rW=c4VVY5KT2f(H3D+9gXi@)lwgf zN!CO-#D&62G$Zic`Z`!zw6F3`0Q&sc67|nEm(>y>fqyg8XQ^yyS^<+{A)4wE3gE^} z_J3j*g#W96&T(HAfVMpe#<F)CAM@1w6h- zgqsnVDI|%eL^BL9soL@67|HzQ*97Z(H6JY{ZSjXTF{6(EAi)hlv9)m1OUS zxw9jWdi9E@qR1&O1kGS_I_<`K7Yx6jnCDZXKS}(DHy2$}DpmB_L^!9hR(D$!3NH_L z6~J77GSRV7Pq2#QC=*_6C(IEI{E3zDl!!M+8uMcF?VBNUF-2`?!YAbn&F=ZU%}z6z z5QrL{ktMQAusnmnYDf|7%bZU?Nn=_f(U3r6)<5jp)L73=NuRC8v7j<;vueO?MaTSp zb$uboV$yAbE%b_jTpa?s+L;}ilH17Ly?`$BcpKXDRLAVvld{cu_5T)NWALbZcF11g zP-^E5chkqGR{iDs9P@}RtPVuaVWoHZ(($Jl1$<$CFbBYkkfelow(WEn5o?ZND!T@o zUbvi5d>}^hGOL;01ZU_gJLXke;S6 z)-*%UlE8qjn(`L4D=M%Gw^IYh=nhek82$kdYLIu)?wc^*1UEAwu@< z_hB55eYm!4g;+9Q9Ey>+I>;MBCQ1GX+;!^#8R~g@`~TwIo9L0M$MDaxv7d%X6|ahrRBee0am+}gpJIKP zlW#4D(f?|{?it1ndr#U=^IOjF6Krc#u}BHb;FosZt}PsLk_@q)kIm&dhK$rxn&k+2 zFEd^2Ro)8T(x@xExHi^|=je1z#ej7j^S!yvj$QdCPSM+UJ9=f1r7dL;=g~6kXudvs zW$T~Mao@0Ajldh@bOCoelfY>v9L`{D-#6IMA2559FS~URXf*Tx?iqjXhFCEs_9hUm`Hj-Y7E{5=P zmniQS-^eTYAm@;pz_PCsSvWhfe^6JR&xbt+4vD}yFi;%|$3e7=SsIi9D9{k0(R_&Q zx~NLm{1 zp|<0Z<&4d1#Yy4Fy;w(0H?s!V?&H~d#9PMX{c$*9Xm4A=S+txTW=x!r4Zws>IvuZ2 zm~dZ|sw_p<+-F#Lw)=+9RhbH6qmqA$ACszH++i2ZpQVt&u8}tO!qz}!egJ8DSXDoIK_W2Hb@LkrBR_&9fa9f_rC-a?cFBpg2k^d80a`3U zm@@RiQY0s=opT3_O#zCbww3*hB`4@QIwMy6&s6(htIq>m6Rkl?Eya+E)U3%o3ttr1 zbbBgV!Wr*`X%G2LHv_I$QO+$mnTF4a9bE|qs zou~VbxJ9(~HW$7G0TJ$NiIr|8w>+pmMbX^YO|pYGKS`Cmj^8%rx>Y|Ki$J9NYUt1^ z%uFp<azqDC}FSoU%H}X=xIK%l+Sld6a?p4pjxGXj?3Fb z4TW96z0VT<;35Jl^}5t~F4hZDyQ^Ohu@ld^r{wGIWra4{-t^J4TnVR3yUKBDkK`Pk zNlq%>gy0DLB<`bz{7{3zMZ&U4HY@YQ6rZqCdLf)kLO9bu1FLFh3&ezREATZ{r^zsj%X zNp8MiQ(WLMmmaWP_u9XUb>x66=3!!AV&$3SNf~ry8ue}(NzMCffNU8=3iDJNqn61V zAoR{ln^gpM9EFS@y`bOk4# z7l3KGnxOJc6dMX-C&eG#Bf=+y6-L)24I%!2@279G8lBwFt+r*=8AG1W7*S?0j9Y#u zKQ&$F81-}YVDmIV$v4RHdrY%el4o2gT+#mv1g`Zlq#W>kNXzje4G@#ws{`aZ7;ugN z0l4igwRPF9@q&{#+)jc#5j-ndEyaxF6ePHC9S;UOUz(gKb&B|Wsy-_r5n92%&0rLXq8!;U zUtkb3wH{lL692IV9hVDlc<+4rrT8x(FuM}jL}+5qZ+Z{)eQ?y(CqmQ@H}1Fy#M}~v z+8h63@K#3sT~l_OuyuPs-)aR5�MKWtwGj<0IqpEJH%y$~%XxiE7m2`*%`Y zPC0<(0U#1&F*{Agtqvd<-rPTM0$YbQ)q(I@uDf^Sq&TVI7Q;Nh7Wv4+nE4q+#V-?Z z>fq9S3qPF{zZF8tB*M3jHZo~P%1#S$ zO@9my+W2reQ^q}GaoYv9p`b*L)CKH1{TD*^Ua`{ z7AoD2Pmt9Rl9j1U;7rX+V_@`MS+=T>F4U&!vP&p>2aG4uDnbtvt=Z=fnOL7jF?k87 z-bz1@f=@CRkL{|~9P8PqHm%w3wxhQWvD%=|m5brrATg_FZpsU6x}tdOC^Q`%`##EW z7H`!%dhMM@(cq0?FFZ{dEjdqIk^L-n<1dSrWeeF=8@5e!ok7Em@t6$+tKRGy#>YRm z6|#44yc~`<0SC8vGI4pC`doB#jDdhkaY%!IBwm45n!6=*^eE8D__9zeQc}lhJ>iZ!z1yYGddp37G zF;T}&lu`kH0FG@_>>G+*0MVo~t8naDP_wnCadhT+z6nMFe}wM#MY{8Q{@BGKI<*QI z+5Dx*9?4P&usFEGg;3vI>BNXuUq^V>QRbYNn*b%W*=8_}#rIDZ>qG>d|M&$D-$ph2 z{Z$|EvZeBGP`jT#k8B=2_=>_f=2NYe zf2nro>9j8E=it78;@6T7VHjTrP zetY*+ZDu;3^5osroF#5IDlC`1Jn|v63-x&m&|p#_Ulc_we=X;gm{oW6LE4K(^Kmhb z3j0oiSyPzNHx_CKKbh6e!b1_q91e2p@uac;dvxQZ7YZ5v&A;}Iqx!z99+{CD3n=}x zq>Kd>frAPvO>$1NmFTO%QPrko~v^PBcQvdaF?tcBBZC0l8OB9kI zmn>UBeY>wKbD4znl=%{#JWy9}GWZWA$x1Pvq1YHWgbb#-@C%v_fOD>!)DDFk$kM() z6|(2K_Q*2N8OG_b$SI8rmsWn0eV~4HqtgCfRzKD42|Kgtri{`)SK{(-eXU|di=3k;JD;SAjIpeP-!apRLo4lyR#D8cI|FWW_Eszd@G`m|7g-IpvWmSvfhJbdRZ&U~A%PsqGtI+tycNveRj zYA;XE*^WME7c2)7cIhMYMuF7vW-jb~1GRGsEJ@%L*|r z?|kOCz;pRpE1ipJ9AQPLwAaP4{UoU)=W*|8%W6~CVW+iBP{)~Hv+pfM?Jal!5bfH& z@y-m2*hb%zV3%1~B(7iIWcp&38b> zDUU0g%Txn$NbPXX_0=>E7*)&v5I2yxKKfH4*0tLBscKyE?s7aa5V-fERn>a9Ug%!- zenbxs=JlSw6`LoZ7sZrduwvjPNa+UE8kWwzZeBB!d%Y%W=vYwfDH`#CCW?#fx#{Rg z&eC0J3W7#{V8kc{UJR`!mm9UBW?;WWBKB#+CHrqo(cC#jBp>x^MEpBpK1cJ!Ue*oS z=Hg5eHN&{RpO|4!-ZvR(_dh~}WI76SuKYl>uGO=~TV1l` zi7~qmj%KQ@Owok?qIvYwf#a7==1e9pkBq4BUviPuGZxDa|HJImBWYi&Lk5zyUx&Nw z$>K5!Mc>{HPR@kefQn|&g0DF@IxP^scc;-`O>sh~+Y+M|WKnn5EZ!@qxpT1N@lYhq z3^9j<@_n7jy(7CWiNF2Hn_cy9sgF=5PD}r+{=smu!$D54YcjsbQWTue;w^5GgOSV2 zgoWSN6}lM)n#{_`!3PZxXI+-P)?bJEzI#_O7k%5`J?4z)e`xcgw%J&K^1bu!+H)jP zDLV=RJHOBXY4+!9Fq+_tM?p}W%&M6XaTj(Er63K-$1EJaqsR3Ig0?__*H7X9p%a?c z2xS3vGncr4HP4q&|NiAc9u6b9KkxtTip$s2@E?h zr;7xOuGZaZ^J^xH8PTvMAWZLd1VJ3EBQZ%()?YG&BBJ7ku$*lmuEL(UcSstwS)=_uYk zzTg_n2*uq*tZI8vYA-i5D;*+@mQMoeVdV75LC7v58Mw4}*lH(*37=1+9D_6Y>1M%Q zJ@Lb0p5z*`J7L5ESk;TzcA@s^ILf=wk^I;Kw548kX%_886}nm-1SAKWy%3!iQARJ> z=7*CFYG=ZVwZgbbt_&q;!P$yEC@J%5K~|qe3XQ70wnDdzZOs91lRxbBXn-AoZ@GF# z%_-+_T)@~SJc~{SbSj93%bQT56a@;SoAknWGC)Nsnz4yP<4NZwKyp}6VOj)PiwFf5 zgWxUsEeG9Ta&Qg3$^X8tm$!U!eog$Qsf3$2^$olxsD_RV=E>eK$8c&8kiY5*+MxBM z$GFu^d#WE;kR&445=upmolg_C$+mR8 zaVg4P6(ks2768JR0c0tXUhYz!MEY^Vrhj7FfiVbOhdAR5HC*^^W|b<0m*9sib~+_v z*;&*@h=KyPgRXA+GaKN5;yJG9Tq~u-e5ha`-CI`HdWa0gJA-uK49vM?A?g!v(ppS~ z=}r@SguMa&2w|l~-tW5Ew=YmFN!;51>+h9m*Bf2Gu5HKMD41evJP+u;r~4I0G9vga z`q!}C5Xl#;sc}Q=r)_4JJ7|i8B7@D6DilJfr!5mUUtms2Ljem& zZmmzUfN$VlXX7m1&dRcj3d%yY-_{PScH$;lF@w|VUlAbgNPu;irrbhYR>uWBM#(~; z2m~I0S}CmUrDsG-19*sZrMfO}!8*sZeLY7B*k_nCf&GKB&pwEREwRL`y$j+mp#Z(q2;NPfL zsu+|9H-``xruLLh($+9&t0ulB0NTd;df0d+M7llq@E2EY}s=V}LB>L(N<&96*EM*>{ODE3IQy6JX?JZHeQ*ss#Xj7Mc7@pEH z4Ta-k!(}3lq!ac{No>rv=DQQvkOz)5R0Yg&G3uhC;PYs?`nQ0LMJw32Vgnr&pn5(f zN(Vm_2Bp7i{BRlal1uYS<{1~`Tc}$>ZcU(aALsYno>Y{*EWLz8CAEU`BNrP3b63N9 z0)ub+4_Xr1DiQ_0(R_BjturczfEX-`de&*jK(=OXv*Lk{rYvFyW?+@xcQNJ?^k4R# z;!hV4bLK}ILEsm23Ex-ihv085s+9mykD`)Aiw@UjX?{GMTR_Q3l2DbO$84HNf*d2b4DvL2I#TY6k0*CJ|E~IbBS@;DX<<86f0Z%~6 zW<*GS{_an`$b>Ru>*#=sSw~xl_Tb~8kBf(|yxZoTMO=}$UTh@J>$MKPaH$+xTEzZ* zUOj>{dh&~uW8@jAX0uKG&1Z>Arwx`URe#=5Xpic`<`7)?)kI$hi%;l|mJNfQ6JRTjEexQp-Hl}6UhsvH~^oz^Dqxo~C_k9)lzS>Mte@eScx&q-W zaI5p|{u|$k^qxQcJ3Csz`utcUhe9XkQ-s_PcZ`8CSiFSvWD7!sZQ^z<(q`>4?3TGv zyzo}l^k=CsuYleu;FJb<*HqYo3uW$LlflU>Hpr zu^Ry9Mk%f?VFYRP;8NQqYR|Kyt+5GS>o(pa6kIOCcrf~&DwdBa{XHXgl6S}pcd?7^ zCKQl+95Hqbqt(NT0Ba{P*ZWyZjvC~@V)M!51X}Dx2+qwB)1@KPJw9w7VjKTjuQ%y_id1E`ACcIoIcBjV0kpp6~IHG6-12!pFYU z9m-2as{!ZI<3uk(Jr~9txwRvDcTo9-X=HWCRi)U?XPcQu< zsmmJ;yBqhiXrx7Gg|mf6+$PhnT=gecmZX8AvZ+b+?1IZLRvXCZ+-l;UHsvs6qdwVQ_>4E{o$^}3A+u!s(YAa5bKR7uaUtF%HVI0Z6 zk2xHST&*gSylLHd1wpX^&M=ZVk1mZ`Ozs&r5tKGZ53z`daSpd!ojiKD1lo?!RNgbQ zv%9pE5-du_gHt}SJ|a{F9Ldz&6C_&+KZ6XXpFHdI|I|Uqkuu|rHniLu(rOH$Rt8*0 zyGHrGQYU+^r$`}b0k97myyw|fle;PkB^_=7^OCac)N+=?i_>bGu>^jlzCq zmdG0u?aYO2GJk^~nf+P-Kw*@uEKlw#axSPZUfGEGLcKd%-gG z3qkx`01|cyS0I~C)*ag#b>h{WMOujQ zaUNm|+gB(;GS=4w-D7mWtvI+p#&M(#1mxS*tPqZf5BuS-(+vP*TU`=akMb&tLzjU8 zFX%tOT0b*U){5(!9I}-wWnO$4G=vx#%j7{QdEzYEm6571%it0??)vE`y8e2OjqdFT zln_f{TRLNNXdJnczKB-_0_;H!JGj5#j6;N#IFP3!^*m}xjlfz4wv`!fo?nb10bDV( z2D*Y^|M#+cXR>na1@FJOt>XYHsHGng^kwV*!Hb2>&||Y{r5C%3v7IaWg8?T3tX8N~ z?xs!Kb}c|@&(;L2s-Ucr%-;8{YV*`=mf<@Mdi`JkyY0;%@xI4v{B~!qWHWSyoRZ7q zm{pFhwbwD4VFjpG;f0#_uA*+0Vu=0oeHLhDZnnp{&tZr0e^N`U0O_c<-s%Aq~K zelIN0BLu{hRF9?iN_yPYtQe3fq6}b!zZPZxHG(f}$k;f*?D5jYR_;neK=BP<1WZJ| zM2LK-SNH@J)UAy2kA!vxJ|vNZkv12p+`^^hM!P2eg0`5QUvM zzD&KXSJI*au6xC| zy@duoB~JAZE#G)O!$~M?(+ zA8j!vQTdewtc{+rG_*&c6TnO;s2Y(;PU4!FFoFP@TTz}OA7ZXhi!z5#EbXd_3cjAt3jj~d+E{f%!YL`9nNd{6kt*wz7A0$mJ{5L%{HUo&?knu4oy#r|=@D{!y$*RCj(X*N$rHdERz!Z8+6`AH1iZrH^eYLz z(V3iGmRkD~CP07q@ZdmYL_&{Q_1IA2HSfY_v2uMIi4f`kq|%3t5J;fQ@qaMZ{aCGqE!5K|OZ6W@g(W zTY2cmtf5C)=G@vbs00FQe08y4FWzn#Hn&;sZD~FsK8$b|aaYRL#hh`7`sf{cy@sm9 z<8ol_U#7uQ6yG=#&Bzku4K~(9{pEnL#r2SysSXyH%d7fit__K(5=o8o>FvG|IkVOU zP?QN*aFnCFmfG8#4PIo|SJ_=$mU%1NK%?9i&>Fok74Or!cL+`XmVf$-;jsz$_N!#9hx@b0QqJi z=CwxiZ5_HvZ(0uiiI-V!lhP5hS=o9!WEJllo}2Lj&MK0`uVfM@gp;HbK%3f{ZgOS3 zkq)#@D<%0PZiYv9=e|0&G7jSYNc9Q?6wn}n;5bIpeGU_o74pea zjlMaBtsuXHh0n#*34A`bln_x9e^sjUuwPSihW99PPcigR*#xCY*vlw`zue1Ug|-_C85S*v0kM` zWym7G_#0Ic6fIrFaF$t-&RDQxQ{a?Ua926R&R#3btp$A>1G11a6uX`0<+QHR978nd zI2K+xcPizz;&*Jl#WRDdpFE+l2?|WZo*bX7joT3t`WT>$Yt3E2sq+htjMmR@tPKn2 z+`E1R8GW@>h%Yrjuy4i#?}6xvTrUMcy~lA$Bh`X!uBdz#z95NQU**p*Mmjs^I$N{O zp@$;WeZGO_>zsC51vdBI{b)$U@G6@Z_A#-*@rypxSWn(xs--LKG#%;8F9>}y?+6gl zX0iPcY{75^At$Z!iNa6C>1cr1Op6GwuUI*_`|H|}x#pxL=V)whgy_g*8U{1}CB|F; z)g$6HD533eY@lt@nCx{;`GNK$6O)=`=O44N5?N-&FG8CK`R|^DceENQieCV~=J=0|Q3fru<{v z*?y+PK$aK5`M0aAZuK|RYTC&zC>p0JznJ8R#m`CN!un7(QFnj#(7&NWU-H^Z?Z#Ul zLeykbDG+P!Xz933`T6lca1DRZ+fEbe?%RhL11o0dS-x!9%WzPj%A>wczMcpSS55PZ zFw03<5h;vAp$0Ue0LdQEYhWLXI7?eG+~A(95tA_d4PR?~Z;C6rrDw2c8UnGze^v@oM(U5-@|im5dv z8c!pyc-6DGo({RKHqvEiXHP`$kTd!r7dd=tY4?Q;XuBa9aIe=|Lg64r4rv+rM+0mI z4Fw2@xubWz@Y0MqzXEgU&$MnZE-{NO;{GgNkvb)MZ@i@9y4{SW`*fLHfSXzVy4wkvc3>U64fVp>kSUL zxNxJs+fdT|C-SpnD(cx0#o5nh;e4g@#op2v-hO;mM^LW?{@ft5r~ncw9hh>gXTc68 z<;4keRoo|ENH1Z^{%qSK^B4{oo%g3wbo;A8MeqkL^SY8t|E5k3#c<-zjsD5dGXCmo zC`a*v(*c(=Aa?-Ghd#Z1z78e-X*JgY?#1ko71|UHPQ6f4#`GSe_fE3e=GRdHZ|^X(nrXB&W`Ru(!Tx)cw=NvpEOg7lH|jB6m{g zP7IcLI@6q>Rjd*^COyRHscE7HgZQE>nk?^JBWqQXTocZS!f=Zk72wnx^Ri>?ev&AK z#v-CN!D;f2Ej&N6M=k3>(gv+`b5>}|UJG)O9jPWn-@0y?h2FvP>nUbGaV(o`bfSz* zxQPMTW^{3FMfK@dk%@rf_VjEGj>kS-vopBJZHF7%ntBR(#O)-ei*FhR`{s{Lm&UD_ z6G}EVjE7}7DvVtRI}4VkHCH3-b_zyjYfc9;Bwww?>nE^;PW3#@=sPyJiGa-w13VVR zg>^tfVx#U5Qv}ox@-4GsQJ3AO1UyXOlxJkTn3Q8s7q|`Ru-YpyFCw@2lAo~vK_|6N zjpKTh;xYg*ItdR|(iqTg+o88=Wy&6|&yivV72ZZ^_RUb^21Qe=h-_CssqBs}9GKyH zq7OnCd74xfg^nh#5BHp?&2Qf+zG?t%$6=0pR>;eeG3PFkHZvQsjTs4C7Zk?wlXn|V zWafosU_%a&VxODzK@xaRCTj|`&35a+T*cB2aoWpuc zmbD(|Ib>YHMaA3jk*2rh!xucA#x|8UHZ-BRs>zv>`aMC*`<*Ikay_czPeIbP2tt0u z_m9!r-oE6WJ0sh+6EVf~OfGW-mTh7%R%YQu_!xCy;60D67tarbMZP}OYkJEkgE-&5 z=@XOI6qTItoD)LMaVrH0^@H5_S5s866XSerPtvp0ePt4=IDf`*KfQO?hcvou7%8C> z(xQtu>M~8s%tT8P%BDg3liQ%BSN_&Vb#Wb~irsh}Fe3`Fy*dVU3GWM%6*h0wzwLDO zE))dDjpWc7z>%(I2sDxeqh3yt(NJxxA&{$?!ijT8uA*U^b5!!=CA8@Uh;VKtP2C$B zK>}3X8U+SXXta=r4nb6@px2Ql{drH+`D(Ff4SO^;e2@Re_#nh{!Uc`vm=ys$DKQ|B zv1C7x5SU@b8K{q$1+O+`Fzv5pJlRP|>OV&+C;h2yWxg7OEzmtmw1e7f#fJNnx>^#T z9tQ!NNWMHc=dm;r{Zt)(_QOHWT~9@ftC!In4zH-4?CL!#^8=qRa@8H4*a?9gYNhYA zYdIN?qEx2bwhyuPLbs7Vy;%r!HM{MqvkLjLz#-xseZBjYfF8+BM(x6(HG6G>DS<4z(r5}Q1Z{wG3Z&+ z{;`aB5>VNn3$GZspU@dJ$8S}RYuAgH+kKK6l+jMeLIJz}Fsac^U8N}{aruRun#9CG7E9wv`iCcJl~>P6ry$2W9jV6>_Rt(^P*{I)jJ;4 zW+dp=d!_=I6@DOb%YWlP7;X(Hhy6M^4C7a-m(PX;o9FS7m{Uu{%Q8@F1z}Pz=pLqH zhPK%#ABf1#J3BAJ*Z9DO+e_NK>cs_>kG3jM$g-&XGY`UmeT&;JrZ)$%80Ubhy-v?s z-h9a9cFA(JD@vcdjbFvTS?pK~4WQ)7Xh>~7^fpFEm`r?Nl)U%f9hGQp;#7h2M8Mym_Egf z0qf+9?WN=vp~jR10}|tp%0w#1Jaf-DmDUKR*iYP>{YkJI;S;UbM0(!IU8y|Gk4?y$ zU*LxAc{Awp^dE|x`7tqq{^r1T&S&U+ncr!9IFrL+|v%Ht>p^ zA#_X~Zy5OiW;t~&i2qz%&L_|+09T@Ko|Hpfitu*uWH3Ei+Gh(eLq~y_+_9O*6xW8m z@!*;j)O4L(iCWVD?#^4Xc$p=u+R_sxA`ox1)FWajobH3Kn6U>GbbQygQ;MxLA=w5B z7MGgHeC(ACGM$c3t#EzP>uXj-UCax-ILk;jq;-0=70gQ)BY5eE^G%m9L95dOv9McI zMRt$1zHpa700iSOSbilwSP&Qu)?bTD6?_mQi#QUP2sW#zQ05G0n`cYZg0qUD2x%*%|1L(>yf^kv>fugvg@j9Cpp;9zM_mE?=WMlt%|`xp`h;m%8HuVM7oFE`DWO zELZDKhTAP~fq?^edUB%Yv9g9Ai5}boG#8Hhbt1FwK8(hQTFb{=ct{q#2S-*&DX#_O z$*$J`c_*eFtNE#<#1c%Z4s>5k6UJ^m?4>_%O@m~BP3327y_bpfCQM?91=m8d)F#~E z4@=lQVuz)tKZmis9Cg|jbOS1o8*-CstitM#XPII6pxkcms3Be2fPy!7OGkg4=COQQ z(gcb-U+PEu2YHT7KF6TSJW21NY8tv^fpUU`)6jeR*$3vYm=Q}A3XuxQoiDxdpAByg z)Ngj3p9d{#t=%BJYl-f9xt%%l?{Tuqf0ADbSWhe!sQ2t#lLalk>^*Xde%AKHSy$sk zcgC_PV(W*?Rk2tj<~_==aL)+3Y;VNr;=FCz>AT%Sz&gs6)_!C1?KjFi|%^;5TJju4RNkoXZ>Hw>x8&x1H`=r+dLfD>6-4xeiB^y2EPa+qP@{XDhKKV5jekZt8w}!x?}Pa9rfD$0lnC z#W@9S1B@=Wm!Nk3j-t*3rZ@9D+&l!rQ~TspUQYkp3dhNgw&#kgkvV0bB-+5kayKoz z65JFtWZuKK=u-@7CaLN3$D3K~i}!UUP|ElXkeNW_w&@j0-w6))R==fBU)7U5ZXvwY z8u@{lYOXXLaJA$}ol+0D)-0dPBz_Km@0s8Euo_y2ifYN@zU0UI?LnA~8Yw0o3uarQ zfQWE5ge}zEz|yGE4ZU?=sHTJ?|SOfWlLiack}5#g-GkwSe?&M5VjJ3=OjnXNZuV=o^}8|0`D%N% zayiI!QouPl+}U+8d!UxsK=ip2S~Mt--L<`)i)XosTl#s=z*ao0z)N>Pp><=c4zf^c zDkf)3O`9j#H~N!Em(KfLSz4RgHuth*uRE2Lho193_JIcfE`_Xn>FXV8Iul#de_}#Z zv+MYtwxb?)4N2kR;n~5gmq;|xp&%y~7iH&m%UlCA3t=AeAY@a|_0KpK#yfhv29i88 zwL3z$0KZ1K2{#=1WW5=B_`1!c>No*G)Y{>X8=SNu^W+i~OPM6#F>rvl=2ee4XHb>w zwn!WyGf-Rk`lXnX2l*QW@a771CTenAlE9!=`vYZ>#%54|6t5LskH^sz`%O(v+Gvj! z9gY6pNxl!nnq3FsKH<@b4x^C77ML>nblXQnfA~kY1L=n&;f6ctb&1-rjHN#m6Pd^~ zr*wsfs6$J|_Z0(me<41<*Y8&9(6;Mmvu5NXr@sNk`eM1>yHmP@s>0KoG0wy5Rkrnt z!>{>o@j&q(w^|KLDTP#~6~~@<9uuJOOuFq*B3L^vatOY(-3ELYP4SxxVbR=$Pbrf9 z9Cwx9k%I!cUxc$*ou+P~1gN+fMqDVzKVbJFnOZyzApXyP0&7e5 z)4qImuvIeb*@|?^(S_-XD z#VW#brw-g;_dcqTz%kL;-^7%s5nF2IU{&-&oI3co(HaNsP(T)3#H`oonqUH!6cQxD zh409n_SfB58Idm!%{y+1k^P}Zm@Ro={(s?c-@5cLe7w;LiqS;KrQ%rJEBXg_V)6*= zpvME{5Cqfm-L;ihDFB(Vf556&cZ&*-tl!zO{VcO*sL|Oc!>EapXSoIS2wE@9LminP zylAoSz|hR+2u#jymc-H?{Hl@;M5de6ZYPAqzp?faes4g}=e$L$EZ)p*T{aM<><(h1 z{#1B(NMe2^nlec2n-0;<-QqVuzz+eZ{!1rA@u@#OV*?Fh$;SB~x00kpQmGLKte{#~ zmShXF=Ep6gY$qc+w`78RFlre~Gj708LpXQ$a%+D#|GSR)FXQEbQ($>N(I$V?$1O)W zfoPjU8OTgcsN6ug+LZsF!Q>M8%TI#6JCxC*6d8#ARjoy`mRfOJgQX65bF9>lP(D*b z+M@CQ;>C+B%DB}qu-)lv{LWmmsEUpTh#+`_w8=839u1vyPA2Q*`}k}Z291LokBaZo zsm=<25m}?zldSCk06ECCj}q-b3{$W^R#*dgL?BUA@9PG*Qn|Fr{Z;2uxjh6)a>YGV02c|pG684AzCgdi9^odm`B<-9} z%L_*ix;B67y3ii5q&H>CCI0Jqmu3f?0HHsX40Y*R8Rc4D%WG(YDS?X4F+A z1&NvEFASlJ;|yA_Q5EB1h;|CI*lz5-R(S3xGO$R zTK0DnZ2-(9(U~9vaF0(btx2P2rI&p<1kjb{S;JEj4F5rkbXB24Dxt*BZk}wN4u+$5 zbvRU`&>2JvLAuClli22?@h6FJ6j7htT?Jzs)Pr zp;$+g>KdPTo(~998IX&E^i|XC?)-N#tEo{cS7cOnQ~S*+BmdJ1BtrvX+ARrousShQ z^QS=Vw;o(0z@b#=Mr{3jsFs5o%aEvXnWx9u9o%R#gqke4MosGYNU)nuS-Zp={@m71 z-)WKkw=K9z1zP$oVz{DQVinv1JWi-9T5b2ACM%u@0Adw`Vk@> z!7pK;y)Y3NVyq4)VAQiEIii`yn?UAhejtf8)nr|qN=|Nf=IjI-;laP(P}>vkuJhm6q>#)0;qIpE>W;1O** zqn<+ebC!R|8)XuR7x6;GX|M^liz9+QwJWDf>6rr5h{Jf2d;qqWQk%4sEe*wOTwf%? zHQ$Ju2{Q*6VI6JPct^Y7Z?hLHT_zNm1P!M)6Uj5T(LcC?U@&$3P3m{GvdWbN(iUFT zL^>1+Vlk2f#Vzrl*>_5w9i*lN^+XJaYuRxg60ts28UK5s%rC`6U-zw*!7q8pIJmnb zRP}cQ*h4ba__p{FL6#rCHS2ZC|F~;QX-{-kh()bg2=NM(Ij!zuu?mUDR z{KRY;7Tv-a?7(46!RDLsgD~^$Hji-`QrD@IvewP$h_3hd6_TZZuD$~ezT60NAu42N zA@pU>B}y+Kxbu%AW|38IxH(SqJ&(owK6%H)VW2eza=1*jYS9`hytsYfG(Py+r{DUI zSUM?GS#HSygO%VW>dNj$0A}0CnqL9O@IwiyXS(72e1Tj$>0PhQ_&Fn~MlH#!REjxC zh|8S=OUaunO>{h$>bmr!ZrP5?OA)wHx)wL_^wjowk{Y}>`}}WY+Kev~Ob|0nOO{WB zsr1uKR?g#k!0*3$m=CV31+$f-u4f1Jh1z=q&W$F1#mo zB!^{E8#dD&lT(>U`}1zw{XP(Lsh6NiyY3_6W%Mj1qXI2WEjQ%F^YqK7!hXMsuGyQY zVoc<0O5n`l$=wIpzy41t*<3Lh!;{QxR?y#P0I3aSr~_a3P&QUEPLB zdgeyiSSJt@QY6PanyF&_ADEXHG3@Lud^m?uZ<0J@jz&*i-KHy8ajoIE z=bH#d-#oTI%pcvh(K5a!GH?Mk)x{9+h(HalV>O}oOhp3$Wq;}$nm=^+aPL`n9NB*I zgDGH#0J2p4T8tI#jKl<1hT}8h_lvRxJewl|`0?3JW7MFQdH)HP1+agD(W$E|egE(3 zVpPQ)E!?!A?i9v{)h&1+?0gkQ@~`C|13Af34TxRT#_53e&PD)cm125e2mFoe0sTgP z=|YStQBv>$?1k0r&b3w~=~k6_c&@j{pIuCyDVf=9$wF-N?NOX#W$r&0bqG_0ovT?o z=aDi6ZA$i$)u+r7J0Gp)BQanx&I7op21{N`Ft}-$%^hE8DfngJ4;t79r>G_XuH?8K z(_PFl>eE;S$vxGKADD}@i4Idr^N3V?UxsOd2<-yN8C zb*GH5X&SU3z}Le-tkiVdtq&b)@mimvd^aHGmgdt9Ng+mWl%N_XE2UJ8lh=VIdV!7> z-;jS`F>Wt;!*5Th{*eFI)giLa6PWk_N?#-&qNFcg_Xy>H0-%z{ZLC84*|v<_OUH+~ zn?J&eEWKbmc@tlN7kE1{yIW~hGtg#A{JoG1Naa*0eazbs1_IulC9{f>knrnWvseh{ zl~EEynLNBwNfJw%ar>lt1atLYIpODe%kH2_5|`%08h0=+wKwwbLx3!108i$%_mP;- z3R;6a`B;tvk)9|V>2YRk;3afZE~~rv`r(mbtxdx%_`yII3bz(0LfnZ!&*Me2Ra1QB zeJ&OiB2Jgu~rmD(sH(-|3wRbD8-H*Z1 z?c%FK-9Mf1{@*ecO+5@4fSigD(`<7{0KqPThXd_sH5oo*!#YT=QS`)|1ZH0QjT3m> z_jBzAQlwsw96jMMW&qU8u8GtwUPL^K#v^rP$B?`9FFj%n89kK|snD`mJv(FMJ70DQ z`6owYB(&l(f8yxwe$9@*=Q+sP4|FhC!5W^V<`EO;>#xdL!FLsl(AC^n0oP)vGj5-* zzlZ-%l*h|={kJuY#`sLR@(ot&HREjYW8m|?i~fJs{alBme%d-<`;zgW!6ks9CXkF` z%Fjzvg+~zvwj;M?9-4vzSz%Q;TDrrty_`acuN4cIsd?}u$Zq{RBhLEOrm;frFb=v%epV&YG`gc!)(tYpaY-9+;m}_CQ7%jq` z!`51P&RovjkBT}rWfvLqoTP7q_R_Cmp9pRrpWiK!cZ*4AOK&O2Xl<%>V`(PQA@l|D zyH%;KL)_b|E@jraOD^fhLM7GrRi(Nf7s%nwO|0gj92CnEGXxrq3uPAp-QZr^%8Cnb z7YWoT0e+f2B>%$Uttt<8(U-~h8WOfqHQ#y+W4Vgv6nOlbM`d|#PwhJ~PG4Ix?%Kl}WaR(C1jy%F39^vg9qgyo6j_JbV#d;-*9ZB*?WNAXNAhS>n8S z%EDA=Nh9EQIqLl8TRU*v)g()iM_s?pFHc2c{Q%hB6vqt=R*%301klb>b6ziKA!wQ0 zDr*eUnhs0Y#qUgpE#ZSIIrPet%T6=}LWL>dj(oNg*;$!sP4v+AL>IJ5ljTt)UdwqN zg5le}S-xF^_UaMkU{D)^c(PN1;=v2anH8}}5!PY&mAW!;m7ZFUSuq%<^KIvbACrpk zZ~uyq2Z2po?|@eufk}q&=!DLwd80WP8PMgHE;+Xt1YcSpuejy<*+OHCEEm~|gNsCz zo7F#@yDT0um4BVo?OuYn9>p+uH3ANdHHGvV1LWJLnnC~q+D*c6@Wx8+)+RoUv0Rfb`9$QL4p1K`NktZ*;RP_^z zNtEbBZ`oK-ke=PcYEoH;5e9xS!G ze!Bu5!k&V{?1vz_N$nOTL{%FK+GbrH-@?4CLNe`x2wc01E&=g0Ord{tx$;4pga5r) zmD1XM0jI>nV?)~(xgZZ%58q! zgA@tczBe*3h_>We@lM^SPqu_z&7-fnca+#DVicEXd)P9gaI(>v3_=!h+bTB(l`k2l z>bZ;DofLK!(x>wV(2&}i!Y@zpSOwm=*GUL-Z$$&L|H+JTI()huZ25d5_nO%$NY|xs z6{9op5;NJZ4E!A>be9otk|5=nY_FuTtn&wceQwvK!w`!dH(t$yMJJ#=3Rdgnp^P|e z7tfUj85@?Ffr9cEv*z&mRKvosQ#L|yV1FIaeJ1ZIMU%e_wRw!27{&OVeP7=#h5T^* zxDt`!Nadk;in084!(Fg*{IHn~VnhyvCYJ$6B~Mu@MrEWY$-Q-D&j}d#yhz0(#jv9r z?>L>iM>c%l3`6YczZ6HfJL1P33uMW?R33b4(hj66=;1;&=K~q{jig6eS&FqL2r~uv zkVx!YwiI^4^%mS7<2;GxiAWdg7LMOmedAaIXW=^}B3)+-nv^qu8$!l>c#vQ&fXdXy z`jI_XULMl?xMB>S=Y~{gc2jqHW)*Uj8Nt*B2?d4KLCqYyVKjPP?3^t73W^1{Z=4_h zFvX))$Q@Rrboh8SyxPD~2s>S=BN+5$1wmcDkj*%4GG!sa_>zDNlx;n>&MrcZf?I&v zN)2yw)L|Iga)gW0H9Pb|hpR(&OaJ=@s*UNxN?s3Cq_7lM=_3~QC&E}jF|^iTjdxOI zK89Ks%N$WzzeiZ)3FbdYeUleqBcTD4#;eXiz|j{?^QwhWr7FrL!-8DIi0G$5{nas) zR@&@ShgoKuySJXcHO>jWS_Byi?3CK8DJOI!taSUJzVn^E39~kUMp^wcw0N9%J0J<$ z^CXXwFLso9gNEw=RFdb$#t10_yIpGK6>5})dMXs3s*gu#yR z=z=W$1D_>a4>6J82IiQS?-JR9o3A)ryXo_@*L8?DJ!>ik1y|Yb{E=70nyW!uOXlC$ z3cJyX?89Z(3!(nUymzj}borR@q|dwh(+1=#K37P;?DbTvR(@U6A(1TZ4}i&uS4 z`bnOR!(0L0HwHPH{L9kRg;`n)00F;TXK}Cd;&I#*swd$Bj0EtP z|J>u}<7+d1*>}KUsetZH-;VN!H&rrA~qUGl;v7XvF=_1greL!-$-KCaVJhf#H#{jKs)H$ ziQcohQHHZKc7EG>=5t)_>K;Q!ZygTF=QDR&%Zm3VyS@n zOZien4jfEuVG@w@p^DMmYm}7y(nG2`fy(^2@i(m`T^MBfn`KNNq*B5dNOGi>4g31G zC&CcKuNk2B2^iO>$-2%k5~me!^}HRubyjjUZ)W&io>nh?vu&u^VLSK8A3Axyl12V? zd<8cf1R#N z0da49dLN_tu^v0h846{yA%j9cJdN7^m$8W7Vb?+aUB=U_uS>C=QrtsU4}jvGUt#P%?#3|j3S2#C5J)?s8FRqOZmw1 zm*c#w3yl}#CP1M7nxmL}_xjxTxFnz)AszZghJvKr)A{~A`*l7aa%B-?_22*9fNNxAso81 z4yjkb*Mw-pSF+EKiu3kEtG;o#Iu1imP+@#xY3byK$9^(RHY;CsOJd7|jEalWS#*LJ z3?MdkJd^Y?Twm>~9<$Iag<54m)DCl<`%VR__Oq4B3>>G3V*n}wdb+$7umi`mh_W_;xo(I$#Cx)nSQX;e7l^qaq||uyM`73tfS7H4fK`T*}L{V2?`}AF|r4dTSc$cz+08HYuiWv~o2V+0!>*pnTFJqMr)_ ze&qmn0#nUqDZ_f>pAVq7Wll9Xx|H{C`4Lb7Ag2r5COud#`(9te`PXUDJ`0BfY2jEP zf%E`EtysL4WSgwA&@1j;t*WL#bBF_B&1+Z20tPA(TvN3KXDXzI*0XM$zxY%Mv;ZO}1HHO$hj|riMzKAkGYYiJ$6hABQbP1i*<)%%L6s2!1n$$S^0wDKf z7?a=NWN0=_Y8c0jvR3q7EcE#2~NkOiX2MP zpM7-S4kg}%(i_Tm@e}9`ptgtgk>a)GDX@G)0Uw7lTgsh)|%j2j+>u9$r#}S@UV+HgJMxl!atJWfRwH1 z_n}c2>+mUbr^tc!T&D!tqi}B+c#5YfCL5T#B~fJx29qn%RtFeyp|2nAv+46C9K-XX zvQ(HWbvxBdjX;RH^*X>l(9}e&ZFQX2iGnM{e4bd4}zyRAtiCk1W-h!3(Q~;wbxl z8~jqals2*3v+!51EFCM?9y0Z?am8W4^|hrY5_4m`9b3gXsEsC8B_8|;$W2DVSS0O! zL%; zOM_`z9S`#}R4zxb&Ywq3k&*c`uE(}!P%T@m;Xcg}NJz9Us@ex*lUK{}pcHdb_UN$i zr=vLjE?6cuIsjMBoLK%&Q7;N6!SXxL9wss+ zk)(GGmjBYOD0f_s1Xd3Ac6%`H9Q~i8SS@xbcHI_bX@F&O9r3EFxd-K1P;pdX5Ah_> z40LK7Rf7Qub7km7=wC#HtaiE_@OQb^?W)hpQ^BSy=jvK(V*RqB<0DVl0ZAIAi z%OTeuK4t||kHI)KGaU!=3Q5cN2(o>I555>-lZ52Q7YjA+8MI-MylRz;x1pOA-HxCT z=^rF3YD)QWzWbP-5>35x+=vcY`cNifb>t--4l6!oL}@BX=mX79_xvWLRb5SdI2MBW zEe8q9fDxD@>=RuHF>5)E%Z53vhd&9z%FnZd<5mc8`4jUVr0qmGVyW1DrsKhwjto{dnPtp9;m*9ye;u|mn-(y4Vso(8Ar3TP_zU~8#!)0KcP z(UXs_zNq+2jX-sTmH+?#_rXvZ{aAg<0!q&L87R5g^{*KTfd;B!<_*u&O;jaiLU}sW z#>~zc2wv$(Kda~C_B8!RUjv6xkaE5;SJb@&LG7JgE%$w`n>B9j&wV=ENycpZBqC7u`1eV6Xc z9}Ts`zLZGf&Zvl5lZ2d%7(YL_&^mDsgeF3{hka#ksrXNG$LQxHpUBzm5)M(G`?#+7 z7vrbf7)WTIoB@hcoeb11%0`ZISI7u7pKI#aQzPENL^XoT=_&daF zaTTMIOpDtPKQc~HuD)@z2o*YJzXzlXXGJEwphmRoGu6rvMTj9Ofknn|(bmNWJ@9o0 ziOTosymm)g0Lh0Pm5qQUDfKZ*3OhxoDLa16!>x6C4yRs=WQP}t?j#4N_B9k7xlt}& z#@7#bt_^CEYg|o0j+)AaY!ZX>@`h(o2XL2y?y2@b45!0{n@s1su6K3DCqz=e!tZ_? z6xbxrJu0txa_TO*+&pa_?21Fba+jHJ^J($G0ASVYeqj+P&mLEL;ca%6$T45v#oMw|e?MgZpWC*i+4rBd*bX6LfC~xdCC074sJmI^h8kcnGmUr@iW)H|3#gtj^ z#RTUBou+okYN}^mlCkPZ+k}BzWf?zAuQXW->(oHQdNx55zygXvCPz*}5>8unhC~p+ zfb8QCaK#Yq9*NW;v{A5m+2dJTKBfRyP`mn5hBgaZM$178{CLp91_p)2wY?Z<#VfRo zixAGNPj`~Z)bwsF$<~BiXwrgu5D1AlR%;ojfcv-SEFzC7$8sK@1p=FT zXnJW}`dp55vV|O)x)fyx11QWfyE*fE(To5ZCmNWjz?`f>K2NHP-v7>9-~P?vTRgib zUvG1cM8Yo9vckE%MjZ?S7k`qGo=#wy~w%ix1In89JYh?9=rlt_;yoX zUS-_>adLa$49{Ej0(03SYJ*ypnF2ox3pp!GM#`kiQ{_33F@h-0dkmB}i;>^1P0qL} zT_1rj{*@rG9C!WCJK+JGF)J}fU%ewpoC#Y*%5hrG>`0lRrbc-x!7Ez3G&TA`G8wkK z98zLy>G{t4JEM$v0lU3D{Y~iCLb3=08t`KT(!H=MLVe}h6)?<*nR+%~yUlf|Q}Z(y zE>zeulUZq@O=Q~RCw4NEHVv4q@*VdrwJe z8q%6St?lHHP90_3hcinOmWDR2OS?KO$6fIROXh@AC0cK4M!%ADH$A|ol9eMcOac{t zE}j1K%8RGguvloLTc-y-`b#pH8pXBXLzdK?qS{^SmOBdwEFvx^?iR3j(jnII>6y}Lx+kLTyG<4`tlIy(vz6A89F^|{0F!LxY;~;WU|wC!=q7gTs<4_k!cZN z^F~-qcJ(F31t}OJtK5-KrK0{ciTk7l*JP*DiY4Ao&5Co*l<29k%BBzw;G*UBcvDt5 z%mX;^>eJb_6i72cq}B4S)7P!Eux0Si+axUMGbm%sg;k-BYLIF$O8%5mlwRYf_9uC) zlpOLf7{c01N<~r5FSWf&gU+G6*&0E%NN~LvJ}B3qmVh)*30(sB((mo zkCTk^ZF3nv3ftBeN_DZ$sNu{ zL;_OMR0&8QF1Lz2WIJ5Tr9_6EFPA#JV0=y6aRJvTx}Y4iBb=}D0jsR9A+6sl3A=O_pfvYQZ(@xd#@ zK3rVTtO#lLFv;M#-01_Ll*8aFI6S~6GhyW%)X>H${~ldOWaGG6p1O0qz! zO-LE+FnR`1fe*aDNQbmtlQ*9MDc+2zL>{UYqrwQ z>_dYVZY-Zl;*gbJU+LW79SFMc|23y&mR-yK3t(MZ5E<2)I>OijNEeWtQ8OHtWVS%N zvUNpzM<;;CoQA;#jwFqv3NZ_n9-12F7o&IaKK`$w*>aR}fzFl1xIzQCE^pRed8hgu zKoE~ux_STr>sZV8NRC??4<*ehwLh$WM;!Hzbt=@ z#-_FH_Az)caTe5{KRs%Hf^cj3@lV1R9|9DZC9s<9Yu?gE_Ae#EBV0NnrwUs5D4WJE~ zSw`nQEc+GE>k5X(q$s|A&r%>b&7bzR57Nwf3WR9mO+Tw*wq2yimZEZ@-tmq@$d3+! zqT6DxJ3D%Y*97ySJ@7S}QOY}N1VH_Aq5bc86|{2YB7OW1%_OC%%wzPIx&yjyT}!qCi)iH<+cy1zO~vBnQI(q4Cd#;((KZbg z5f*z-B>J4(Z9rW0P|=bFuH_?!`G5cb0Fjt%oZSEeRs+@L+x6o4jL{djDe;6TUAT&+ zqtV=oX5t6NJ;ns`Pab(pFeDWv&W85vQ(Tw(G?oj`>YEe8%UN|Lor1S+u)b2YN{prQ z$~xT8OxBdu%el=M6>{Bx!sojvVSlJh##llEH_4*Ph?nk;~93#JVxuXZx7FUthO^7}tcFj;0`}Y6^ zS;eHl6G&*BU~;v;O8$~+_xfM&ECYFV2Tw*hV7T)1^8Q;sE{=ZxQ$;Y8Y``+|BKL3! zm=0N*W)9kVOB0Yd5%9hk>>rDt8@D#;$qu@~4jT_#O`?12jnv&Eb0j`)OF(vb!kaf2 z6~Xf%EEkx;X`>JrDf}bJR%uKAryk3KG~7MEclck1J(rhqzbZXw0BKYkYEjuuoPvJh zzWM1tN@Q$JJJTNQWh(zWJ`%_M#9Am*OTn#m`m ziF`62LFgEx-4(J5LP>FOg2v3yOVKp@G`Zsyf$ORYnw+i zf&<>l3ZifT000A9fC0TMXp5iAY3lYeuot3Ff10jTX=hQ{XSb1ZAG=b?ZK6hN6jk}E zt2#~=RdSMLRh1+u38yA3htOfxJYfsaQW5r6xa22{Pq#E<6OX~LDMrrPW<~Bj=GX{M zgc26pxarsYX@C?XeaJ4RgN@~}itCxcfMXyzM_fM$+5WDT@Vif092~*GXM8}_w zAOwNQL2L7x3oFn*fZ2V}-bj02NT+^Re$;%K)JTgyYBDw%QB}T3oqr}%<_?<*QP2o@ z(EptBbj}|4QWN(uXpT9$FIWt$Sc9xu0&@ zC()v~?-j81iN0|qP^;F{kL$Dt%`QNiJ7kWEX~qRgXE>4Be_YYpnd@Awrs5JBJa-#0&!fwd zLT4qk=Gqq+jAx_evk!aZplT0Og`DjaiHtnCWvyQCqq`>*%y$K<^YfIH*8@cEM@Km1 z(X>UdjLqD~*11{;b~yN_**C2^fR|wk3B+?!m9eFZ`&`0}e(|A1Q1)o*fa8Dw000E3 zfx`h@xBvnmObmOE+)!V=u#nHifeJ(b005BOXQ8eA>Xj%z#<`JzXde0gji7sHDGP$G zZq~cwO$OTBWm<#CRjRTpmG?lre$HMmtx|TNJ2~0}uDiwWRl#o_ZWz1-(y2F|tRxhqq=MI=+G*h&>h6+lDsN8sIdY$*ect6E#%QQDrK!6<} zM2%HD=`j)l08!m{@3Qo8*w@}h51rnz&&QYY)aHSwjg&XuR8{?#?Lvi7MUKa5<|4q3 zC)bvVn#zDzaVyt2B~m7A61YRgZjLNEjSiD58S|@F_%+q>domq~LA=?t?WPdmbMTCI z+-Z@@{CFn#Q&PYna%e5=SRtSP1Em3ZuujNYg{>V4;)KNYn9FGBgtDnx_^a%wi7Fgg z5MR-COv59u7TjNlZsSJ}jQ33kUSxofcP5SRVo%{s<8;TAWe>Kp;=HYe4Q>$f$Yx#U zA=L<%vVIl~etf4xVJkfr+CE~7Z-)40o|;~W7bwP%l!?d4NA~RbO)D&t_WLCJ<@%f?m)S^Ai+1_8&?t^!E=xfX z6`;f)*f zEL?h2uj-r@{-?C zCZ4Nh?3#!=oautL`FzhX-;QmGrTKgW+1IHhtt$36@rQ%$c-h#l!1%BS^*J?4;Shku z?Hj8XgxT0vAko$u!ZCH`+l#RMll_*?zw3NO<0aPcEa({|N2t*m_35cWfB_2p9R$;( zyIH5){suNWunyLLC7qni=qKD>GaoT)0YQb-DVh2Aqc?33)R{JS$tegw&^GIJOmmrS z^*U5h(!Pu}FcysGV(Ld@<_gZs@HhQWzJxE&O3lV1>)h_!@OR20(W#Ml)ER1GR^CKV z8kOaIpRWkeCPr;eA8`sAf=Rxbq)Bn^OfK#>%i}0|DsOR1vvWG+bhIDZzl+j%y8oG7 z7z>^PZ=hY@>Ow($?zC^X6X#DC8XCC7JkzQ^Y?H`Sb$tWga8_ySUY!VU2M1I{aBEXr z&N|~U%@?m@h{(lQ-j4IR6ko}^>uGLZHlm5!F$P&Gkbq8?rFT)bfY!8w^&wFaU_bx> zSWFM1SfU|%QWkcRoA@Mdf6R=vY8yp->IsNuqFBS7Oa#4&;9;Aw%rN3WHMYEnm{H(y z=v>NYz)kh_BJUC|+>?>78+u)ri~Zh~D4AhcOHT&J^TXX<+l?tS27W*1_=ULMhNagz8d}_D*P^q& z8?B*0@m5)hSI&9wOSV{eH-Th{psKA1>Tqe2?lopo|s;( zjDq#VConhun{T0O>O3o^7*m=Amh~sAYWD8V6aclL#BoKBYuUA6Jt0_=@|0eqGz)`yk5IsimnY Date: Tue, 7 Mar 2023 19:03:55 +0100 Subject: [PATCH 0576/1906] west.yml: Update hal_atmel Update to latest hal_atmel with fixups and documentation. Signed-off-by: Gerson Fernando Budke --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 0e9b88dc1883..732d105dc354 100644 --- a/west.yml +++ b/west.yml @@ -52,7 +52,7 @@ manifest: groups: - hal - name: hal_atmel - revision: d45adfb6897aba323cac29cdda8070ce4f23f014 + revision: f47a9a8b55677b5d03bf7f066f907e6b74c9e57d path: modules/hal/atmel groups: - hal From 88cedcf5c588c4e229657df022963cb6ed2b9fe8 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Sun, 5 Mar 2023 22:03:59 +0100 Subject: [PATCH 0577/1906] drivers: clock: Add Atmel SAM PMC driver Add initial version of clock control for Atmel SAM SoC series. This add support to Power Management which allows control peripherals clock. Signed-off-by: Gerson Fernando Budke --- drivers/clock_control/CMakeLists.txt | 1 + drivers/clock_control/Kconfig | 2 + drivers/clock_control/Kconfig.sam | 9 ++ drivers/clock_control/clock_control_sam_pmc.c | 150 ++++++++++++++++++ dts/arm/atmel/sam3x.dtsi | 9 ++ dts/arm/atmel/sam4e.dtsi | 9 ++ dts/arm/atmel/sam4l.dtsi | 9 ++ dts/arm/atmel/sam4s.dtsi | 9 ++ dts/arm/atmel/same70.dtsi | 9 ++ dts/bindings/clock/atmel,sam-pmc.yaml | 51 ++++++ .../drivers/clock_control/atmel_sam_pmc.h | 37 +++++ .../zephyr/dt-bindings/clock/atmel_sam_pmc.h | 16 ++ soc/arm/atmel_sam/Kconfig.defconfig | 3 + 13 files changed, 314 insertions(+) create mode 100644 drivers/clock_control/Kconfig.sam create mode 100644 drivers/clock_control/clock_control_sam_pmc.c create mode 100644 dts/bindings/clock/atmel,sam-pmc.yaml create mode 100644 include/zephyr/drivers/clock_control/atmel_sam_pmc.h create mode 100644 include/zephyr/dt-bindings/clock/atmel_sam_pmc.h diff --git a/drivers/clock_control/CMakeLists.txt b/drivers/clock_control/CMakeLists.txt index 034db40ad60e..857a62e52e29 100644 --- a/drivers/clock_control/CMakeLists.txt +++ b/drivers/clock_control/CMakeLists.txt @@ -21,6 +21,7 @@ zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_NRF clock_cont zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_NRF_DRIVER_CALIBRATION nrf_clock_calibration.c) zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RV32M1_PCC clock_control_rv32m1_pcc.c) zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_INFINEON_CAT1 clock_control_ifx_cat1.c) +zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_SAM clock_control_sam_pmc.c) if(CONFIG_CLOCK_CONTROL_STM32_CUBE) diff --git a/drivers/clock_control/Kconfig b/drivers/clock_control/Kconfig index 7cb07258a6ea..1f2a2347fa96 100644 --- a/drivers/clock_control/Kconfig +++ b/drivers/clock_control/Kconfig @@ -68,4 +68,6 @@ source "drivers/clock_control/Kconfig.aspeed" source "drivers/clock_control/Kconfig.gd32" +source "drivers/clock_control/Kconfig.sam" + endif # CLOCK_CONTROL diff --git a/drivers/clock_control/Kconfig.sam b/drivers/clock_control/Kconfig.sam new file mode 100644 index 000000000000..59c095abc14c --- /dev/null +++ b/drivers/clock_control/Kconfig.sam @@ -0,0 +1,9 @@ +# Copyright (c) 2023 Gerson Fernando Budke +# SPDX-License-Identifier: Apache-2.0 + +config CLOCK_CONTROL_SAM + bool "Atmel SAM clock control" + default y + depends on DT_HAS_ATMEL_SAM_PMC_ENABLED + help + Enable driver for Atmel SAM Clock Control. diff --git a/drivers/clock_control/clock_control_sam_pmc.c b/drivers/clock_control/clock_control_sam_pmc.c new file mode 100644 index 000000000000..cb37e8dcd842 --- /dev/null +++ b/drivers/clock_control/clock_control_sam_pmc.c @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2023 Gerson Fernando Budke + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT atmel_sam_pmc + +#include + +#include +#include +#include +#include +#include + +#include +LOG_MODULE_REGISTER(clock_control, CONFIG_CLOCK_CONTROL_LOG_LEVEL); + +static int atmel_sam_clock_control_on(const struct device *dev, + clock_control_subsys_t sys) +{ + ARG_UNUSED(dev); + + const struct atmel_sam_pmc_config *cfg = (const struct atmel_sam_pmc_config *)sys; + + if (cfg == NULL) { + LOG_ERR("The PMC config can not be NULL."); + return -ENXIO; + } + + LOG_DBG("Type: %x, Id: %d", cfg->clock_type, cfg->peripheral_id); + + switch (cfg->clock_type) { + case PMC_TYPE_PERIPHERAL: + soc_pmc_peripheral_enable(cfg->peripheral_id); + break; + default: + LOG_ERR("The PMC clock type is not implemented."); + return -ENODEV; + } + + return 0; +} + +static int atmel_sam_clock_control_off(const struct device *dev, + clock_control_subsys_t sys) +{ + ARG_UNUSED(dev); + + const struct atmel_sam_pmc_config *cfg = (const struct atmel_sam_pmc_config *)sys; + + if (cfg == NULL) { + LOG_ERR("The PMC config can not be NULL."); + return -ENXIO; + } + + LOG_DBG("Type: %x, Id: %d", cfg->clock_type, cfg->peripheral_id); + + switch (cfg->clock_type) { + case PMC_TYPE_PERIPHERAL: + soc_pmc_peripheral_disable(cfg->peripheral_id); + break; + default: + LOG_ERR("The PMC clock type is not implemented."); + return -ENODEV; + } + + return 0; +} + +static int atmel_sam_clock_control_get_rate(const struct device *dev, + clock_control_subsys_t sys, + uint32_t *rate) +{ + ARG_UNUSED(dev); + + const struct atmel_sam_pmc_config *cfg = (const struct atmel_sam_pmc_config *)sys; + + if (cfg == NULL) { + LOG_ERR("The PMC config can not be NULL."); + return -ENXIO; + } + + LOG_DBG("Type: %x, Id: %d", cfg->clock_type, cfg->peripheral_id); + + switch (cfg->clock_type) { + case PMC_TYPE_PERIPHERAL: + *rate = SOC_ATMEL_SAM_MCK_FREQ_HZ; + break; + default: + LOG_ERR("The PMC clock type is not implemented."); + return -ENODEV; + } + + LOG_DBG("Rate: %d", *rate); + + return 0; +} + +static enum clock_control_status +atmel_sam_clock_control_get_status(const struct device *dev, + clock_control_subsys_t sys) +{ + ARG_UNUSED(dev); + + const struct atmel_sam_pmc_config *cfg = (const struct atmel_sam_pmc_config *)sys; + enum clock_control_status status; + + if (cfg == NULL) { + LOG_ERR("The PMC config can not be NULL."); + return -ENXIO; + } + + LOG_DBG("Type: %x, Id: %d", cfg->clock_type, cfg->peripheral_id); + + switch (cfg->clock_type) { + case PMC_TYPE_PERIPHERAL: + status = soc_pmc_peripheral_is_enabled(cfg->peripheral_id) > 0 + ? CLOCK_CONTROL_STATUS_ON + : CLOCK_CONTROL_STATUS_OFF; + break; + default: + LOG_ERR("The PMC clock type is not implemented."); + return -ENODEV; + } + + return status; +} + +static struct clock_control_driver_api atmel_sam_clock_control_api = { + .on = atmel_sam_clock_control_on, + .off = atmel_sam_clock_control_off, + .get_rate = atmel_sam_clock_control_get_rate, + .get_status = atmel_sam_clock_control_get_status, +}; + +static int atmel_sam_clock_control_init(const struct device *dev) +{ + ARG_UNUSED(dev); + + return 0; +} + +DEVICE_DT_INST_DEFINE(0, atmel_sam_clock_control_init, + NULL, + NULL, + NULL, + PRE_KERNEL_1, CONFIG_CLOCK_CONTROL_INIT_PRIORITY, + &atmel_sam_clock_control_api); diff --git a/dts/arm/atmel/sam3x.dtsi b/dts/arm/atmel/sam3x.dtsi index 56299175a3a5..17b1b97a0b57 100644 --- a/dts/arm/atmel/sam3x.dtsi +++ b/dts/arm/atmel/sam3x.dtsi @@ -6,6 +6,7 @@ #include #include +#include / { aliases { @@ -28,6 +29,14 @@ }; soc { + pmc: pmc@400e0600 { + compatible = "atmel,sam-pmc"; + reg = <0x400e0600 0x200>; + interrupts = <5 0>; + #clock-cells = <2>; + status = "okay"; + }; + sram0: memory@20070000 { compatible = "mmio-sram"; reg = <0x20070000 0x18000>; diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index 1ee52c97ae11..1a766e216183 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -7,6 +7,7 @@ #include #include #include +#include / { aliases { @@ -37,6 +38,14 @@ }; soc { + pmc: pmc@400e0400 { + compatible = "atmel,sam-pmc"; + reg = <0x400e0400 0x200>; + interrupts = <5 0>; + #clock-cells = <2>; + status = "okay"; + }; + sram0: memory@20000000 { compatible = "mmio-sram"; }; diff --git a/dts/arm/atmel/sam4l.dtsi b/dts/arm/atmel/sam4l.dtsi index cb3052880ff8..296471a7c55a 100644 --- a/dts/arm/atmel/sam4l.dtsi +++ b/dts/arm/atmel/sam4l.dtsi @@ -7,6 +7,7 @@ #include #include #include +#include / { chosen { @@ -50,6 +51,14 @@ }; soc { + pmc: pmc@400e0000 { + compatible = "atmel,sam-pmc"; + reg = <0x400e0000 0x740>; + interrupts = <22 0>; + #clock-cells = <2>; + status = "okay"; + }; + flashcalw: flash-controller@400a0000 { compatible = "atmel,sam4l-flashcalw-controller"; reg = <0x400a0000 0x400>; diff --git a/dts/arm/atmel/sam4s.dtsi b/dts/arm/atmel/sam4s.dtsi index 3d4489460179..8e67afbbb3d1 100644 --- a/dts/arm/atmel/sam4s.dtsi +++ b/dts/arm/atmel/sam4s.dtsi @@ -9,6 +9,7 @@ #include #include #include +#include / { aliases { @@ -39,6 +40,14 @@ }; soc { + pmc: pmc@400e0400 { + compatible = "atmel,sam-pmc"; + reg = <0x400e0400 0x200>; + interrupts = <5 0>; + #clock-cells = <2>; + status = "okay"; + }; + sram0: memory@20100000 { compatible = "mmio-sram"; }; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index b22454a7d9cc..6d774b38cc34 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -9,6 +9,7 @@ #include #include #include +#include / { aliases { @@ -47,6 +48,14 @@ }; soc { + pmc: pmc@400e0600 { + compatible = "atmel,sam-pmc"; + reg = <0x400e0600 0x200>; + interrupts = <5 0>; + #clock-cells = <2>; + status = "okay"; + }; + eefc: flash-controller@400e0c00 { compatible = "atmel,sam-flash-controller"; reg = <0x400e0c00 0x200>; diff --git a/dts/bindings/clock/atmel,sam-pmc.yaml b/dts/bindings/clock/atmel,sam-pmc.yaml new file mode 100644 index 000000000000..5eb066979c71 --- /dev/null +++ b/dts/bindings/clock/atmel,sam-pmc.yaml @@ -0,0 +1,51 @@ +# Copyright (c) 2023 Gerson Fernando Budke +# SPDX-License-Identifier: Apache-2.0 + +description: | + Atmel Power Management Controller (PMC) + + The Power Management Controller (PMC) optimizes power consumption by + controlling all system and user peripheral clocks. The PMC enables/disables + the clock inputs to many of the peripherals and the processor. + + To specify the clocks in a peripheral, the standard clocks property needs + to be used, e.g.: + + uart: uart@xxx { + ... + clocks = <&pmc PMC_TYPE_PERIPHERAL p-id>; + ... + }; + + In this example the clock-type was defined as PMC_TYPE_PERIPHERAL and the + peripheral-id was defined as p-id. The p-id number should be consulted on + datasheet, usually it is available at Product Mapping figure. + + NOTE: The predefined clock type cell is defined at + include/zephyr/drivers/clock_clontrol/atmel_sam_pmc.h header file. + + The clock-type constants are: + PMC_TYPE_CORE + PMC_TYPE_SYSTEM + PMC_TYPE_PERIPHERAL + PMC_TYPE_GCK + PMC_TYPE_PROGRAMMABLE + +compatible: "atmel,sam-pmc" + +include: [clock-controller.yaml, base.yaml] + +properties: + reg: + required: true + + "#clock-cells": + const: 2 + description: | + from common clock binding; shall be set to 2. The first entry is the type + of the clock (core, system, peripheral or generated) and the second entry + it's the peripheral identification index as provided by the datasheet. + +clock-cells: + - clock-type + - peripheral-id diff --git a/include/zephyr/drivers/clock_control/atmel_sam_pmc.h b/include/zephyr/drivers/clock_control/atmel_sam_pmc.h new file mode 100644 index 000000000000..3a57a4ce011c --- /dev/null +++ b/include/zephyr/drivers/clock_control/atmel_sam_pmc.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 Gerson Fernando Budke +#include + +#define SAM_DT_PMC_CONTROLLER DEVICE_DT_GET(DT_NODELABEL(pmc)) + +struct atmel_sam_pmc_config { + uint32_t clock_type; + uint32_t peripheral_id; +}; + +#define SAM_DT_CLOCK_PMC_CFG(clock_id, node_id) \ + { \ + .clock_type = DT_CLOCKS_CELL_BY_IDX(node_id, clock_id, clock_type), \ + .peripheral_id = DT_CLOCKS_CELL_BY_IDX(node_id, clock_id, peripheral_id)\ + } + +#define SAM_DT_INST_CLOCK_PMC_CFG(inst) SAM_DT_CLOCK_PMC_CFG(0, DT_DRV_INST(inst)) + +#define SAM_DT_CLOCKS_PMC_CFG(node_id) \ + { \ + LISTIFY(DT_NUM_CLOCKS(node_id), \ + SAM_DT_CLOCK_PMC_CFG, (,), node_id) \ + } + +#define SAM_DT_INST_CLOCKS_PMC_CFG(inst) \ + SAM_DT_CLOCKS_PMC_CFG(DT_DRV_INST(inst)) + +#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_ATMEL_SAM_PMC_H_ */ diff --git a/include/zephyr/dt-bindings/clock/atmel_sam_pmc.h b/include/zephyr/dt-bindings/clock/atmel_sam_pmc.h new file mode 100644 index 000000000000..aa7b0680017c --- /dev/null +++ b/include/zephyr/dt-bindings/clock/atmel_sam_pmc.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Gerson Fernando Budke Date: Sun, 5 Mar 2023 22:24:36 +0100 Subject: [PATCH 0578/1906] drivers: serial: sam: Update to use clock control This update Atmel SAM uart and usart drivers to use clock control drivers. Signed-off-by: Gerson Fernando Budke --- drivers/serial/uart_sam.c | 15 +++++++-------- drivers/serial/usart_sam.c | 17 ++++++++--------- dts/arm/atmel/sam3x.dtsi | 10 +++++----- dts/arm/atmel/sam4e.dtsi | 8 ++++---- dts/arm/atmel/sam4l.dtsi | 8 ++++---- dts/arm/atmel/sam4s.dtsi | 8 ++++---- dts/arm/atmel/same70.dtsi | 16 ++++++++-------- dts/bindings/serial/atmel,sam-uart.yaml | 4 +--- dts/bindings/serial/atmel,sam-usart.yaml | 4 +--- 9 files changed, 42 insertions(+), 48 deletions(-) diff --git a/drivers/serial/uart_sam.c b/drivers/serial/uart_sam.c index 49cdc0ad0da8..7f39396abc0c 100644 --- a/drivers/serial/uart_sam.c +++ b/drivers/serial/uart_sam.c @@ -1,6 +1,7 @@ /* * Copyright (c) 2017 Piotr Mienkowski * Copyright (c) 2018 Justin Watson + * Copyright (c) 2023 Gerson Fernando Budke * SPDX-License-Identifier: Apache-2.0 */ @@ -8,10 +9,6 @@ /** @file * @brief UART driver for Atmel SAM MCU family. - * - * Note: - * - Error handling is not implemented. - * - The driver works only in polling mode, interrupt mode is not implemented. */ #include @@ -21,12 +18,13 @@ #include #include #include +#include #include /* Device constant configuration parameters */ struct uart_sam_dev_cfg { Uart *regs; - uint32_t periph_id; + const struct atmel_sam_pmc_config clock_cfg; const struct pinctrl_dev_config *pcfg; #ifdef CONFIG_UART_INTERRUPT_DRIVEN @@ -40,7 +38,7 @@ struct uart_sam_dev_data { #ifdef CONFIG_UART_INTERRUPT_DRIVEN uart_irq_callback_user_data_t irq_cb; /* Interrupt Callback */ - void *irq_cb_data; /* Interrupt Callback Arg */ + void *irq_cb_data; /* Interrupt Callback Arg */ #endif /* CONFIG_UART_INTERRUPT_DRIVEN */ }; @@ -391,7 +389,8 @@ static int uart_sam_init(const struct device *dev) Uart * const uart = cfg->regs; /* Enable UART clock in PMC */ - soc_pmc_peripheral_enable(cfg->periph_id); + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&cfg->clock_cfg); /* Connect pins to the peripheral */ retval = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); @@ -445,7 +444,7 @@ static const struct uart_driver_api uart_sam_driver_api = { #define UART_SAM_DECLARE_CFG(n, IRQ_FUNC_INIT) \ static const struct uart_sam_dev_cfg uart##n##_sam_config = { \ .regs = (Uart *)DT_INST_REG_ADDR(n), \ - .periph_id = DT_INST_PROP(n, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \ \ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ \ diff --git a/drivers/serial/usart_sam.c b/drivers/serial/usart_sam.c index ddad4afce46d..78b18455cd99 100644 --- a/drivers/serial/usart_sam.c +++ b/drivers/serial/usart_sam.c @@ -1,6 +1,7 @@ /* - * Copyright (c) 2018 Justin Watson * Copyright (c) 2016 Piotr Mienkowski + * Copyright (c) 2018 Justin Watson + * Copyright (c) 2023 Gerson Fernando Budke * SPDX-License-Identifier: Apache-2.0 */ @@ -8,10 +9,6 @@ /** @file * @brief USART driver for Atmel SAM MCU family. - * - * Note: - * - Only basic USART features sufficient to support printf functionality - * are currently implemented. */ #include @@ -21,14 +18,15 @@ #include #include #include +#include #include /* Device constant configuration parameters */ struct usart_sam_dev_cfg { Usart *regs; - uint32_t periph_id; - bool hw_flow_control; + const struct atmel_sam_pmc_config clock_cfg; const struct pinctrl_dev_config *pcfg; + bool hw_flow_control; #ifdef CONFIG_UART_INTERRUPT_DRIVEN uart_irq_config_func_t irq_config_func; @@ -485,7 +483,8 @@ static int usart_sam_init(const struct device *dev) Usart * const usart = cfg->regs; /* Enable USART clock in PMC */ - soc_pmc_peripheral_enable(cfg->periph_id); + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&cfg->clock_cfg); /* Connect pins to the peripheral */ retval = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); @@ -542,7 +541,7 @@ static const struct uart_driver_api usart_sam_driver_api = { #define USART_SAM_DECLARE_CFG(n, IRQ_FUNC_INIT) \ static const struct usart_sam_dev_cfg usart##n##_sam_config = { \ .regs = (Usart *)DT_INST_REG_ADDR(n), \ - .periph_id = DT_INST_PROP(n, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \ .hw_flow_control = DT_INST_PROP(n, hw_flow_control), \ \ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ diff --git a/dts/arm/atmel/sam3x.dtsi b/dts/arm/atmel/sam3x.dtsi index 17b1b97a0b57..81b72bd6d63a 100644 --- a/dts/arm/atmel/sam3x.dtsi +++ b/dts/arm/atmel/sam3x.dtsi @@ -100,7 +100,7 @@ compatible = "atmel,sam-uart"; reg = <0x400e0800 0x124>; interrupts = <8 1>; - peripheral-id = <8>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 8>; status = "disabled"; }; @@ -108,7 +108,7 @@ compatible = "atmel,sam-usart"; reg = <0x40098000 0x130>; interrupts = <17 0>; - peripheral-id = <17>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 17>; status = "disabled"; }; @@ -116,7 +116,7 @@ compatible = "atmel,sam-usart"; reg = <0x4009c000 0x130>; interrupts = <18 0>; - peripheral-id = <18>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 18>; status = "disabled"; }; @@ -124,7 +124,7 @@ compatible = "atmel,sam-usart"; reg = <0x400a0000 0x130>; interrupts = <19 0>; - peripheral-id = <19>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 19>; status = "disabled"; }; @@ -132,7 +132,7 @@ compatible = "atmel,sam-usart"; reg = <0x400a4000 0x130>; interrupts = <20 0>; - peripheral-id = <20>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 20>; status = "disabled"; }; diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index 1a766e216183..44e657852fc2 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -110,7 +110,7 @@ compatible = "atmel,sam-uart"; reg = <0x400e0600 0x140>; interrupts = <7 1>; - peripheral-id = <7>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 7>; status = "disabled"; }; @@ -118,7 +118,7 @@ compatible = "atmel,sam-uart"; reg = <0x40060600 0x200>; interrupts = <45 1>; - peripheral-id = <45>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 45>; status = "disabled"; }; @@ -126,7 +126,7 @@ compatible = "atmel,sam-usart"; reg = <0x400a0000 0x4000>; interrupts = <14 1>; - peripheral-id = <14>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 14>; status = "disabled"; }; @@ -134,7 +134,7 @@ compatible = "atmel,sam-usart"; reg = <0x400a4000 0x4000>; interrupts = <15 1>; - peripheral-id = <15>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 15>; status = "disabled"; }; diff --git a/dts/arm/atmel/sam4l.dtsi b/dts/arm/atmel/sam4l.dtsi index 296471a7c55a..7f92fdc30ff3 100644 --- a/dts/arm/atmel/sam4l.dtsi +++ b/dts/arm/atmel/sam4l.dtsi @@ -134,28 +134,28 @@ compatible = "atmel,sam-usart"; reg = <0x40024000 0x4000>; interrupts = <65 1>; - peripheral-id = <8>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 8>; status = "disabled"; }; usart1: usart@40028000 { compatible = "atmel,sam-usart"; reg = <0x40028000 0x4000>; interrupts = <66 1>; - peripheral-id = <9>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 9>; status = "disabled"; }; usart2: usart@4002c000 { compatible = "atmel,sam-usart"; reg = <0x4002c000 0x4000>; interrupts = <67 1>; - peripheral-id = <10>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 10>; status = "disabled"; }; usart3: usart@40030000 { compatible = "atmel,sam-usart"; reg = <0x40030000 0x4000>; interrupts = <68 1>; - peripheral-id = <11>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 11>; status = "disabled"; }; diff --git a/dts/arm/atmel/sam4s.dtsi b/dts/arm/atmel/sam4s.dtsi index 8e67afbbb3d1..5ce8e7965188 100644 --- a/dts/arm/atmel/sam4s.dtsi +++ b/dts/arm/atmel/sam4s.dtsi @@ -112,7 +112,7 @@ compatible = "atmel,sam-uart"; reg = <0x400e0600 0x200>; interrupts = <8 1>; - peripheral-id = <8>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 8>; status = "disabled"; }; @@ -120,7 +120,7 @@ compatible = "atmel,sam-uart"; reg = <0x400e0800 0x200>; interrupts = <9 1>; - peripheral-id = <9>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 9>; status = "disabled"; }; @@ -139,7 +139,7 @@ compatible = "atmel,sam-usart"; reg = <0x40024000 0x130>; interrupts = <14 1>; - peripheral-id = <14>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 14>; status = "disabled"; }; @@ -147,7 +147,7 @@ compatible = "atmel,sam-usart"; reg = <0x40028000 0x130>; interrupts = <15 1>; - peripheral-id = <15>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 15>; status = "disabled"; }; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index 6d774b38cc34..905db378580e 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -139,7 +139,7 @@ compatible = "atmel,sam-uart"; reg = <0x400e0800 0x100>; interrupts = <7 1>; - peripheral-id = <7>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 7>; status = "disabled"; }; @@ -147,7 +147,7 @@ compatible = "atmel,sam-uart"; reg = <0x400e0a00 0x100>; interrupts = <8 1>; - peripheral-id = <8>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 8>; status = "disabled"; }; @@ -155,7 +155,7 @@ compatible = "atmel,sam-uart"; reg = <0x400e1a00 0x100>; interrupts = <44 1>; - peripheral-id = <44>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 44>; status = "disabled"; }; @@ -163,7 +163,7 @@ compatible = "atmel,sam-uart"; reg = <0x400e1c00 0x100>; interrupts = <45 1>; - peripheral-id = <45>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 45>; status = "disabled"; }; @@ -171,7 +171,7 @@ compatible = "atmel,sam-uart"; reg = <0x400e1e00 0x100>; interrupts = <46 1>; - peripheral-id = <46>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 46>; status = "disabled"; }; @@ -179,7 +179,7 @@ compatible = "atmel,sam-usart"; reg = <0x40024000 0x100>; interrupts = <13 0>; - peripheral-id = <13>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 13>; status = "disabled"; }; @@ -187,7 +187,7 @@ compatible = "atmel,sam-usart"; reg = <0x40028000 0x100>; interrupts = <14 0>; - peripheral-id = <14>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 14>; status = "disabled"; }; @@ -195,7 +195,7 @@ compatible = "atmel,sam-usart"; reg = <0x4002c000 0x100>; interrupts = <15 0>; - peripheral-id = <15>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 15>; status = "disabled"; }; diff --git a/dts/bindings/serial/atmel,sam-uart.yaml b/dts/bindings/serial/atmel,sam-uart.yaml index 8534d0b2324c..5b37cacc3ab1 100644 --- a/dts/bindings/serial/atmel,sam-uart.yaml +++ b/dts/bindings/serial/atmel,sam-uart.yaml @@ -13,7 +13,5 @@ properties: interrupts: required: true - peripheral-id: - type: int - description: peripheral ID + clocks: required: true diff --git a/dts/bindings/serial/atmel,sam-usart.yaml b/dts/bindings/serial/atmel,sam-usart.yaml index cb81deca1afb..005567a362e8 100644 --- a/dts/bindings/serial/atmel,sam-usart.yaml +++ b/dts/bindings/serial/atmel,sam-usart.yaml @@ -13,7 +13,5 @@ properties: interrupts: required: true - peripheral-id: - type: int - description: peripheral ID + clocks: required: true From c77c1cc197f651999aa537ded121a390a03460ba Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Sun, 5 Mar 2023 23:04:27 +0100 Subject: [PATCH 0579/1906] drivers: gpio: sam: Update to use clock control This update Atmel SAM gpio and pinctrl drivers to use clock control drivers. Signed-off-by: Gerson Fernando Budke --- drivers/gpio/gpio_sam.c | 12 ++++++---- drivers/gpio/gpio_sam4l.c | 12 ++++++---- drivers/pinctrl/pinctrl_sam.c | 31 +++++++++++++------------ dts/arm/atmel/sam3x.dtsi | 10 ++++---- dts/arm/atmel/sam4e.dtsi | 10 ++++---- dts/arm/atmel/sam4l.dtsi | 6 ++--- dts/arm/atmel/sam4s.dtsi | 6 ++--- dts/arm/atmel/same70.dtsi | 10 ++++---- dts/bindings/gpio/atmel,sam-gpio.yaml | 7 +++--- dts/bindings/gpio/atmel,sam4l-gpio.yaml | 3 +++ 10 files changed, 60 insertions(+), 47 deletions(-) diff --git a/drivers/gpio/gpio_sam.c b/drivers/gpio/gpio_sam.c index f82c6f5cffe0..2f0ea2198357 100644 --- a/drivers/gpio/gpio_sam.c +++ b/drivers/gpio/gpio_sam.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2018 Justin Watson + * Copyright (c) 2023 Gerson Fernando Budke * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,6 +13,7 @@ #include #include #include +#include #include #include @@ -24,7 +26,8 @@ struct gpio_sam_config { struct gpio_driver_config common; Pio *regs; config_func_t config_func; - uint32_t periph_id; + + const struct atmel_sam_pmc_config clock_cfg; }; struct gpio_sam_runtime { @@ -305,8 +308,9 @@ int gpio_sam_init(const struct device *dev) { const struct gpio_sam_config * const cfg = dev->config; - /* The peripheral clock must be enabled for the interrupts to work. */ - soc_pmc_peripheral_enable(cfg->periph_id); + /* Enable GPIO clock in PMC. This is necessary to enable interrupts */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&cfg->clock_cfg); cfg->config_func(dev); @@ -321,7 +325,7 @@ int gpio_sam_init(const struct device *dev) .port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n),\ }, \ .regs = (Pio *)DT_INST_REG_ADDR(n), \ - .periph_id = DT_INST_PROP(n, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \ .config_func = port_##n##_sam_config_func, \ }; \ \ diff --git a/drivers/gpio/gpio_sam4l.c b/drivers/gpio/gpio_sam4l.c index 9a3029b28912..8b3cef0335f1 100644 --- a/drivers/gpio/gpio_sam4l.c +++ b/drivers/gpio/gpio_sam4l.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 Justin Watson - * Copyright (c) 2020 Gerson Fernando Budke + * Copyright (c) 2020-2023 Gerson Fernando Budke * * SPDX-License-Identifier: Apache-2.0 */ @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -24,7 +25,8 @@ struct gpio_sam_config { struct gpio_driver_config common; Gpio *regs; config_func_t config_func; - uint32_t periph_id; + + const struct atmel_sam_pmc_config clock_cfg; }; struct gpio_sam_runtime { @@ -230,7 +232,9 @@ int gpio_sam_init(const struct device *dev) { const struct gpio_sam_config * const cfg = dev->config; - soc_pmc_peripheral_enable(cfg->periph_id); + /* Enable GPIO clock in PM */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&cfg->clock_cfg); cfg->config_func(dev); @@ -254,7 +258,7 @@ int gpio_sam_init(const struct device *dev) .port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n),\ }, \ .regs = (Gpio *)DT_INST_REG_ADDR(n), \ - .periph_id = DT_INST_PROP(n, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \ .config_func = port_##n##_sam_config_func, \ }; \ \ diff --git a/drivers/pinctrl/pinctrl_sam.c b/drivers/pinctrl/pinctrl_sam.c index d00c3b580b14..b2a42baf4bcc 100644 --- a/drivers/pinctrl/pinctrl_sam.c +++ b/drivers/pinctrl/pinctrl_sam.c @@ -1,10 +1,11 @@ /* - * Copyright (c) 2022, Gerson Fernando Budke + * Copyright (c) 2022-2023, Gerson Fernando Budke * * SPDX-License-Identifier: Apache-2.0 */ #include +#include #include /** Utility macro that expands to the GPIO port address if it exists */ @@ -13,9 +14,9 @@ (DT_REG_ADDR(DT_NODELABEL(nodelabel)),)) /** Utility macro that expands to the GPIO Peripheral ID if it exists */ -#define SAM_PORT_PERIPH_ID_OR_NONE(nodelabel) \ +#define SAM_PORT_CLOCKS_OR_NONE(nodelabel) \ IF_ENABLED(DT_NODE_EXISTS(DT_NODELABEL(nodelabel)), \ - (DT_PROP(DT_NODELABEL(nodelabel), peripheral_id),)) + (SAM_DT_CLOCK_PMC_CFG(0, DT_NODELABEL(nodelabel)),)) /** SAM port addresses */ static const uint32_t sam_port_addrs[] = { @@ -33,19 +34,19 @@ static const uint32_t sam_port_addrs[] = { #endif }; -/** SAM port peripheral id */ -static const uint32_t sam_port_periph_id[] = { +/** SAM port clocks */ +static const struct atmel_sam_pmc_config sam_port_clocks[] = { #ifdef ID_GPIO - SAM_PORT_PERIPH_ID_OR_NONE(gpioa) - SAM_PORT_PERIPH_ID_OR_NONE(gpiob) - SAM_PORT_PERIPH_ID_OR_NONE(gpioc) + SAM_PORT_CLOCKS_OR_NONE(gpioa) + SAM_PORT_CLOCKS_OR_NONE(gpiob) + SAM_PORT_CLOCKS_OR_NONE(gpioc) #else - SAM_PORT_PERIPH_ID_OR_NONE(pioa) - SAM_PORT_PERIPH_ID_OR_NONE(piob) - SAM_PORT_PERIPH_ID_OR_NONE(pioc) - SAM_PORT_PERIPH_ID_OR_NONE(piod) - SAM_PORT_PERIPH_ID_OR_NONE(pioe) - SAM_PORT_PERIPH_ID_OR_NONE(piof) + SAM_PORT_CLOCKS_OR_NONE(pioa) + SAM_PORT_CLOCKS_OR_NONE(piob) + SAM_PORT_CLOCKS_OR_NONE(pioc) + SAM_PORT_CLOCKS_OR_NONE(piod) + SAM_PORT_CLOCKS_OR_NONE(pioe) + SAM_PORT_CLOCKS_OR_NONE(piof) #endif }; @@ -63,7 +64,7 @@ static void pinctrl_configure_pin(pinctrl_soc_pin_t pin) #else soc_pin.regs = (Pio *) sam_port_addrs[port_idx]; #endif - soc_pin.periph_id = sam_port_periph_id[port_idx]; + soc_pin.periph_id = sam_port_clocks[port_idx].peripheral_id; soc_pin.mask = 1 << SAM_PINMUX_PIN_GET(pin); soc_pin.flags = SAM_PINCTRL_FLAGS_GET(pin) << SOC_GPIO_FLAGS_POS; diff --git a/dts/arm/atmel/sam3x.dtsi b/dts/arm/atmel/sam3x.dtsi index 81b72bd6d63a..7943a1d349b0 100644 --- a/dts/arm/atmel/sam3x.dtsi +++ b/dts/arm/atmel/sam3x.dtsi @@ -146,7 +146,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e0e00 0x190>; interrupts = <11 1>; - peripheral-id = <11>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 11>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -156,7 +156,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1000 0x190>; interrupts = <12 1>; - peripheral-id = <12>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 12>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -166,7 +166,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1200 0x190>; interrupts = <13 1>; - peripheral-id = <13>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 13>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -176,7 +176,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1400 0x190>; interrupts = <14 1>; - peripheral-id = <14>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 14>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -186,7 +186,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1600 0x190>; interrupts = <15 1>; - peripheral-id = <15>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 15>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index 44e657852fc2..55d6d2580d9b 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -165,7 +165,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e0e00 0x200>; interrupts = <9 1>; - peripheral-id = <9>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 9>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -175,7 +175,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1000 0x200>; interrupts = <10 1>; - peripheral-id = <10>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 10>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -185,7 +185,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1200 0x200>; interrupts = <11 1>; - peripheral-id = <11>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 11>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -195,7 +195,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1400 0x200>; interrupts = <12 1>; - peripheral-id = <12>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 12>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -205,7 +205,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1600 0x200>; interrupts = <13 1>; - peripheral-id = <13>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 13>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; diff --git a/dts/arm/atmel/sam4l.dtsi b/dts/arm/atmel/sam4l.dtsi index 7f92fdc30ff3..eb06ea1b1f61 100644 --- a/dts/arm/atmel/sam4l.dtsi +++ b/dts/arm/atmel/sam4l.dtsi @@ -180,7 +180,7 @@ compatible = "atmel,sam4l-gpio"; reg = <0x400e1000 0x200>; interrupts = <25 1>, <26 1>, <27 1>, <28 1>; - peripheral-id = <68>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 68>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -189,7 +189,7 @@ compatible = "atmel,sam4l-gpio"; reg = <0x400e1200 0x200>; interrupts = <29 1>, <30 1>, <31 1>, <32 1>; - peripheral-id = <68>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 68>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -198,7 +198,7 @@ compatible = "atmel,sam4l-gpio"; reg = <0x400e1400 0x200>; interrupts = <33 1>, <34 1>, <35 1>, <36 1>; - peripheral-id = <68>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 68>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; diff --git a/dts/arm/atmel/sam4s.dtsi b/dts/arm/atmel/sam4s.dtsi index 5ce8e7965188..a79bf4dd7a47 100644 --- a/dts/arm/atmel/sam4s.dtsi +++ b/dts/arm/atmel/sam4s.dtsi @@ -162,7 +162,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e0e00 0x190>; interrupts = <11 1>; - peripheral-id = <11>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 11>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -172,7 +172,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1000 0x190>; interrupts = <12 1>; - peripheral-id = <12>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 12>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -182,7 +182,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1200 0x190>; interrupts = <13 1>; - peripheral-id = <13>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 13>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index 905db378580e..77c24e309934 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -236,7 +236,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e0e00 0x190>; interrupts = <10 1>; - peripheral-id = <10>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 10>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -246,7 +246,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1000 0x190>; interrupts = <11 1>; - peripheral-id = <11>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 11>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -256,7 +256,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1200 0x190>; interrupts = <12 1>; - peripheral-id = <12>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 12>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -266,7 +266,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1400 0x190>; interrupts = <16 1>; - peripheral-id = <16>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 16>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; @@ -276,7 +276,7 @@ compatible = "atmel,sam-gpio"; reg = <0x400e1600 0x190>; interrupts = <17 1>; - peripheral-id = <17>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 17>; gpio-controller; #gpio-cells = <2>; #atmel,pin-cells = <2>; diff --git a/dts/bindings/gpio/atmel,sam-gpio.yaml b/dts/bindings/gpio/atmel,sam-gpio.yaml index 3be0b7944948..b212915086e5 100644 --- a/dts/bindings/gpio/atmel,sam-gpio.yaml +++ b/dts/bindings/gpio/atmel,sam-gpio.yaml @@ -1,3 +1,6 @@ +# Copyright (c) 2021-2023, Gerson Fernando Budke +# SPDX-License-Identifier: Apache-2.0 + description: SAM GPIO PORT node compatible: "atmel,sam-gpio" @@ -11,9 +14,7 @@ properties: interrupts: required: true - peripheral-id: - type: int - description: peripheral ID + clocks: required: true "#gpio-cells": diff --git a/dts/bindings/gpio/atmel,sam4l-gpio.yaml b/dts/bindings/gpio/atmel,sam4l-gpio.yaml index 9e10bd6afa3a..9b7d03883ff3 100644 --- a/dts/bindings/gpio/atmel,sam4l-gpio.yaml +++ b/dts/bindings/gpio/atmel,sam4l-gpio.yaml @@ -1,3 +1,6 @@ +# Copyright (c) 2021-2023, Gerson Fernando Budke +# SPDX-License-Identifier: Apache-2.0 + description: SAM4L GPIO PORT node compatible: "atmel,sam4l-gpio" From 3c7988c52aef51ed0a113ceb978e5189e052a219 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Sun, 5 Mar 2023 23:16:18 +0100 Subject: [PATCH 0580/1906] drivers: eth: sam: Update to use clock control This update Atmel SAM ethernet driver to use clock control drivers. Signed-off-by: Gerson Fernando Budke --- drivers/ethernet/eth_sam_gmac.c | 8 +++++--- drivers/ethernet/eth_sam_gmac_priv.h | 4 ++-- dts/arm/atmel/sam4e.dtsi | 2 +- dts/arm/atmel/same70.dtsi | 2 +- dts/bindings/ethernet/atmel,sam-gmac.yaml | 10 ++-------- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/ethernet/eth_sam_gmac.c b/drivers/ethernet/eth_sam_gmac.c index 7b7ad0fb6b25..f6d6ed2bb6cd 100644 --- a/drivers/ethernet/eth_sam_gmac.c +++ b/drivers/ethernet/eth_sam_gmac.c @@ -1,6 +1,7 @@ /* * Copyright (c) 2016 Piotr Mienkowski * Copyright (c) 2018 Antmicro Ltd + * Copyright (c) 2023 Gerson Fernando Budke * * SPDX-License-Identifier: Apache-2.0 */ @@ -43,6 +44,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include #include #include +#include #include #include "eth_sam_gmac_priv.h" @@ -1776,8 +1778,8 @@ static int eth_initialize(const struct device *dev) #ifdef CONFIG_SOC_FAMILY_SAM /* Enable GMAC module's clock */ - soc_pmc_peripheral_enable(cfg->periph_id); - + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&cfg->clock_cfg); #else /* Enable MCLK clock on GMAC */ MCLK->AHBMASK.reg |= MCLK_AHBMASK_GMAC; @@ -2212,7 +2214,7 @@ static const struct eth_sam_dev_cfg eth0_config = { .regs = (Gmac *)DT_INST_REG_ADDR(0), .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0), #ifdef CONFIG_SOC_FAMILY_SAM - .periph_id = DT_INST_PROP_OR(0, peripheral_id, 0), + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(0), #endif .config_func = eth0_irq_config, #if DT_NODE_EXISTS(DT_INST_CHILD(0, phy)) diff --git a/drivers/ethernet/eth_sam_gmac_priv.h b/drivers/ethernet/eth_sam_gmac_priv.h index 78e7dee96bdf..0f38c90172e2 100644 --- a/drivers/ethernet/eth_sam_gmac_priv.h +++ b/drivers/ethernet/eth_sam_gmac_priv.h @@ -261,10 +261,10 @@ struct gmac_queue { /* Device constant configuration parameters */ struct eth_sam_dev_cfg { Gmac *regs; - const struct pinctrl_dev_config *pcfg; #ifdef CONFIG_SOC_FAMILY_SAM - uint32_t periph_id; + const struct atmel_sam_pmc_config clock_cfg; #endif + const struct pinctrl_dev_config *pcfg; void (*config_func)(void); const struct device *phy_dev; }; diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index 55d6d2580d9b..eddd3c199dfa 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -141,7 +141,7 @@ gmac: ethernet@40034000 { compatible = "atmel,sam-gmac"; reg = <0x40034000 0x4000>; - peripheral-id = <44>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 44>; interrupts = <44 0>; interrupt-names = "gmac"; num-queues = <1>; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index 77c24e309934..e7e33d922eb0 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -321,7 +321,7 @@ gmac: ethernet@40050000 { compatible = "atmel,sam-gmac"; reg = <0x40050000 0x4000>; - peripheral-id = <39>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 39>; interrupts = <39 0>, <66 0>, <67 0>; interrupt-names = "gmac", "q1", "q2"; num-queues = <3>; diff --git a/dts/bindings/ethernet/atmel,sam-gmac.yaml b/dts/bindings/ethernet/atmel,sam-gmac.yaml index d73210c7c7da..cd32c2312d58 100644 --- a/dts/bindings/ethernet/atmel,sam-gmac.yaml +++ b/dts/bindings/ethernet/atmel,sam-gmac.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Gerson Fernando Budke +# Copyright (c) 2021-2023 Gerson Fernando Budke # SPDX-License-Identifier: Apache-2.0 description: Atmel SAM-family GMAC Ethernet @@ -8,11 +8,5 @@ compatible: "atmel,sam-gmac" include: atmel,gmac-common.yaml properties: - peripheral-id: - type: int + clocks: required: true - description: | - The peripheral identifier is required for Atmel SAMs MCUs to indicate - which is the clock line associated with a specific peripheral. This - clock line is defined at Power Management Controller (PMC) and it - enables the peripheral. From eb2c6d7e2c8baed6e5f2f1edf11605a547b3f838 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Mon, 6 Mar 2023 22:52:12 +0100 Subject: [PATCH 0581/1906] drivers: timer: sam: Update to use clock control This update Atmel SAM timer driver to use clock control drivers. Signed-off-by: Gerson Fernando Budke --- drivers/counter/counter_sam_tc.c | 9 ++++++--- dts/arm/atmel/sam3x.dtsi | 12 +++++++++--- dts/arm/atmel/sam4e.dtsi | 12 +++++++++--- dts/arm/atmel/sam4l.dtsi | 4 ++-- dts/arm/atmel/sam4s.dtsi | 8 ++++++-- dts/arm/atmel/same70.dtsi | 16 ++++++++++++---- dts/bindings/timer/atmel,sam-tc.yaml | 4 +--- 7 files changed, 45 insertions(+), 20 deletions(-) diff --git a/drivers/counter/counter_sam_tc.c b/drivers/counter/counter_sam_tc.c index 10dcd3353a9a..61b6b188c33a 100644 --- a/drivers/counter/counter_sam_tc.c +++ b/drivers/counter/counter_sam_tc.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Piotr Mienkowski + * Copyright (c) 2023, Gerson Fernando Budke * * SPDX-License-Identifier: Apache-2.0 */ @@ -31,6 +32,7 @@ #include #include #include +#include #include #include @@ -51,11 +53,11 @@ struct counter_sam_dev_cfg { uint32_t reg_cmr; uint32_t reg_rc; void (*irq_config_func)(const struct device *dev); + const struct atmel_sam_pmc_config clock_cfg[TCCHANNEL_NUMBER]; const struct pinctrl_dev_config *pcfg; uint8_t clk_sel; bool nodivclk; uint8_t tc_chan_num; - uint8_t periph_id[TCCHANNEL_NUMBER]; }; struct counter_sam_alarm_data { @@ -322,7 +324,8 @@ static int counter_sam_initialize(const struct device *dev) } /* Enable channel's clock */ - soc_pmc_peripheral_enable(dev_cfg->periph_id[dev_cfg->tc_chan_num]); + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&dev_cfg->clock_cfg[dev_cfg->tc_chan_num]); /* Clock and Mode Selection */ tc_ch->TC_CMR = dev_cfg->reg_cmr; @@ -384,7 +387,7 @@ static const struct counter_sam_dev_cfg counter_##n##_sam_config = { \ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ .nodivclk = DT_INST_PROP(n, nodivclk), \ .tc_chan_num = DT_INST_PROP_OR(n, channel, 0), \ - .periph_id = DT_INST_PROP(n, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCKS_PMC_CFG(n), \ }; \ \ static struct counter_sam_dev_data counter_##n##_sam_data; \ diff --git a/dts/arm/atmel/sam3x.dtsi b/dts/arm/atmel/sam3x.dtsi index 7943a1d349b0..2ef636718dd6 100644 --- a/dts/arm/atmel/sam3x.dtsi +++ b/dts/arm/atmel/sam3x.dtsi @@ -199,7 +199,9 @@ interrupts = <27 0 28 0 29 0>; - peripheral-id = <27 28 29>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 27>, + <&pmc PMC_TYPE_PERIPHERAL 28>, + <&pmc PMC_TYPE_PERIPHERAL 29>; status = "disabled"; }; @@ -209,7 +211,9 @@ interrupts = <30 0 31 0 32 0>; - peripheral-id = <30 31 32>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 30>, + <&pmc PMC_TYPE_PERIPHERAL 31>, + <&pmc PMC_TYPE_PERIPHERAL 32>; status = "disabled"; }; @@ -219,7 +223,9 @@ interrupts = <33 0 34 0 35 0>; - peripheral-id = <33 34 35>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 33>, + <&pmc PMC_TYPE_PERIPHERAL 34>, + <&pmc PMC_TYPE_PERIPHERAL 35>; status = "disabled"; }; }; diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index eddd3c199dfa..3691aefa64ad 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -218,7 +218,9 @@ interrupts = <21 0 22 0 23 0>; - peripheral-id = <21 22 23>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 21>, + <&pmc PMC_TYPE_PERIPHERAL 22>, + <&pmc PMC_TYPE_PERIPHERAL 23>; status = "disabled"; }; @@ -228,7 +230,9 @@ interrupts = <24 0 25 0 26 0>; - peripheral-id = <24 25 26>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 24>, + <&pmc PMC_TYPE_PERIPHERAL 25>, + <&pmc PMC_TYPE_PERIPHERAL 26>; status = "disabled"; }; @@ -238,7 +242,9 @@ interrupts = <27 0 28 0 29 0>; - peripheral-id = <27 28 29>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 27>, + <&pmc PMC_TYPE_PERIPHERAL 28>, + <&pmc PMC_TYPE_PERIPHERAL 29>; status = "disabled"; }; diff --git a/dts/arm/atmel/sam4l.dtsi b/dts/arm/atmel/sam4l.dtsi index eb06ea1b1f61..bd0e2cfe1364 100644 --- a/dts/arm/atmel/sam4l.dtsi +++ b/dts/arm/atmel/sam4l.dtsi @@ -211,7 +211,7 @@ interrupts = <55 0 56 0 57 0>; - peripheral-id = <2>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 2>; status = "disabled"; }; @@ -221,7 +221,7 @@ interrupts = <58 0 59 0 60 0>; - peripheral-id = <3>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 3>; status = "disabled"; }; diff --git a/dts/arm/atmel/sam4s.dtsi b/dts/arm/atmel/sam4s.dtsi index a79bf4dd7a47..5f07ee3d455c 100644 --- a/dts/arm/atmel/sam4s.dtsi +++ b/dts/arm/atmel/sam4s.dtsi @@ -195,7 +195,9 @@ interrupts = <23 0 24 0 25 0>; - peripheral-id = <23 24 25>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 23>, + <&pmc PMC_TYPE_PERIPHERAL 24>, + <&pmc PMC_TYPE_PERIPHERAL 25>; status = "disabled"; }; @@ -205,7 +207,9 @@ interrupts = <26 0 27 0 28 0>; - peripheral-id = <26 27 28>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 26>, + <&pmc PMC_TYPE_PERIPHERAL 27>, + <&pmc PMC_TYPE_PERIPHERAL 28>; status = "disabled"; }; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index e7e33d922eb0..0f344defb99a 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -340,7 +340,9 @@ interrupts = <23 0 24 0 25 0>; - peripheral-id = <23 24 25>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 23>, + <&pmc PMC_TYPE_PERIPHERAL 24>, + <&pmc PMC_TYPE_PERIPHERAL 25>; status = "disabled"; }; @@ -350,7 +352,9 @@ interrupts = <26 0 27 0 28 0>; - peripheral-id = <26 27 28>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 26>, + <&pmc PMC_TYPE_PERIPHERAL 27>, + <&pmc PMC_TYPE_PERIPHERAL 28>; status = "disabled"; }; @@ -360,7 +364,9 @@ interrupts = <47 0 48 0 49 0>; - peripheral-id = <47 48 49>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 47>, + <&pmc PMC_TYPE_PERIPHERAL 48>, + <&pmc PMC_TYPE_PERIPHERAL 49>; status = "disabled"; }; @@ -370,7 +376,9 @@ interrupts = <50 0 51 0 52 0>; - peripheral-id = <50 51 52>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 50>, + <&pmc PMC_TYPE_PERIPHERAL 51>, + <&pmc PMC_TYPE_PERIPHERAL 52>; status = "disabled"; }; diff --git a/dts/bindings/timer/atmel,sam-tc.yaml b/dts/bindings/timer/atmel,sam-tc.yaml index a0b87cffcaab..fa1d5d48118b 100644 --- a/dts/bindings/timer/atmel,sam-tc.yaml +++ b/dts/bindings/timer/atmel,sam-tc.yaml @@ -15,9 +15,7 @@ properties: interrupts: required: true - peripheral-id: - type: array - description: peripheral ID + clocks: required: true channel: From 08015c8f575b471a26717354886724670f19e18e Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Tue, 7 Mar 2023 19:06:47 +0100 Subject: [PATCH 0582/1906] drivers: hwinfo: sam: Update to use clock control This update Atmel SAM hwinfo reset cause driver to use clock control driver. Signed-off-by: Gerson Fernando Budke --- drivers/hwinfo/hwinfo_sam_rstc.c | 8 +++++--- dts/arm/atmel/sam4s.dtsi | 2 +- dts/arm/atmel/same70.dtsi | 2 +- dts/bindings/hwinfo/atmel,sam-rstc.yaml | 4 +--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/hwinfo/hwinfo_sam_rstc.c b/drivers/hwinfo/hwinfo_sam_rstc.c index 6b58593035fb..8a4823913918 100644 --- a/drivers/hwinfo/hwinfo_sam_rstc.c +++ b/drivers/hwinfo/hwinfo_sam_rstc.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2022 Basalte bv + * Copyright (c) 2023 Gerson Fernando Budke * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,8 +9,7 @@ #include #include -#include -#include +#include BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 1, "No atmel,sam-rstc compatible device found"); @@ -56,12 +56,14 @@ int z_impl_hwinfo_get_supported_reset_cause(uint32_t *supported) static int hwinfo_rstc_init(const struct device *dev) { Rstc *regs = (Rstc *)DT_INST_REG_ADDR(0); + const struct atmel_sam_pmc_config clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(0); uint32_t mode; ARG_UNUSED(dev); /* Enable RSTC in PMC */ - soc_pmc_peripheral_enable(DT_INST_PROP(0, peripheral_id)); + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&clock_cfg); /* Get current Mode Register value */ mode = regs->RSTC_MR; diff --git a/dts/arm/atmel/sam4s.dtsi b/dts/arm/atmel/sam4s.dtsi index 5f07ee3d455c..bfc5bb6344db 100644 --- a/dts/arm/atmel/sam4s.dtsi +++ b/dts/arm/atmel/sam4s.dtsi @@ -216,7 +216,7 @@ rstc: rstc@400e1400 { compatible = "atmel,sam-rstc"; reg = <0x400e1400 0x10>; - peripheral-id = <1>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 1>; user-nrst; }; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index 0f344defb99a..73dafc5c3e17 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -452,7 +452,7 @@ rstc: rstc@400e1800 { compatible = "atmel,sam-rstc"; reg = <0x400e1800 0x10>; - peripheral-id = <1>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 1>; user-nrst; }; }; diff --git a/dts/bindings/hwinfo/atmel,sam-rstc.yaml b/dts/bindings/hwinfo/atmel,sam-rstc.yaml index e53182bc176c..4ae05c5579b5 100644 --- a/dts/bindings/hwinfo/atmel,sam-rstc.yaml +++ b/dts/bindings/hwinfo/atmel,sam-rstc.yaml @@ -11,9 +11,7 @@ properties: reg: required: true - peripheral-id: - type: int - description: peripheral ID + clocks: required: true user-nrst: From 6d4c0da459d9248cd2886267b76ad39f380a8924 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Tue, 7 Mar 2023 19:08:53 +0100 Subject: [PATCH 0583/1906] drivers: hwinfo: sam: Make compatible whole series This update devicetree entries and Kconfig definition to allow use of reset cause on all SAM series. Signed-off-by: Gerson Fernando Budke --- drivers/hwinfo/Kconfig | 3 +-- dts/arm/atmel/sam3x.dtsi | 7 +++++++ dts/arm/atmel/sam4e.dtsi | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/hwinfo/Kconfig b/drivers/hwinfo/Kconfig index afe80944c329..ae53d1859428 100644 --- a/drivers/hwinfo/Kconfig +++ b/drivers/hwinfo/Kconfig @@ -89,8 +89,7 @@ config HWINFO_RPI_PICO config HWINFO_SAM_RSTC bool "Atmel SAM reset cause" default y - depends on SOC_SERIES_SAM4S || SOC_SERIES_SAME70 || \ - SOC_SERIES_SAMV71 + depends on SOC_FAMILY_SAM && !SOC_SERIES_SAM4L help Enable Atmel SAM reset cause hwinfo driver. diff --git a/dts/arm/atmel/sam3x.dtsi b/dts/arm/atmel/sam3x.dtsi index 2ef636718dd6..dcc54deb88e1 100644 --- a/dts/arm/atmel/sam3x.dtsi +++ b/dts/arm/atmel/sam3x.dtsi @@ -228,6 +228,13 @@ <&pmc PMC_TYPE_PERIPHERAL 35>; status = "disabled"; }; + + rstc: rstc@400e1a00 { + compatible = "atmel,sam-rstc"; + reg = <0x400e1a00 0x10>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 1>; + user-nrst; + }; }; }; diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index 3691aefa64ad..16605670e165 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -248,6 +248,13 @@ status = "disabled"; }; + rstc: rstc@400e1800 { + compatible = "atmel,sam-rstc"; + reg = <0x400e1800 0x10>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 1>; + user-nrst; + }; + smc: smc@40060000 { compatible = "atmel,sam-smc"; #address-cells = <1>; From c4f1d98ef67f62a1c1d697cd85d8dc23d3cea2fc Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Tue, 7 Mar 2023 19:25:10 +0100 Subject: [PATCH 0584/1906] drivers: i2c: sam: Update to use clock control This update Atmel SAM twi, twihs and twim drivers to use clock control driver. Signed-off-by: Gerson Fernando Budke --- drivers/i2c/i2c_sam4l_twim.c | 12 +++++++----- drivers/i2c/i2c_sam_twi.c | 11 +++++++---- drivers/i2c/i2c_sam_twihs.c | 11 +++++++---- dts/arm/atmel/sam3x.dtsi | 4 ++-- dts/arm/atmel/sam4e.dtsi | 4 ++-- dts/arm/atmel/sam4l.dtsi | 8 ++++---- dts/arm/atmel/sam4s.dtsi | 4 ++-- dts/arm/atmel/same70.dtsi | 6 +++--- dts/bindings/i2c/atmel,sam-i2c-twi.yaml | 4 +--- dts/bindings/i2c/atmel,sam-i2c-twihs.yaml | 4 +--- dts/bindings/i2c/atmel,sam-i2c-twim.yaml | 6 ++---- 11 files changed, 38 insertions(+), 36 deletions(-) diff --git a/drivers/i2c/i2c_sam4l_twim.c b/drivers/i2c/i2c_sam4l_twim.c index 407996790da1..93e008c57eb9 100644 --- a/drivers/i2c/i2c_sam4l_twim.c +++ b/drivers/i2c/i2c_sam4l_twim.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2017 Piotr Mienkowski - * Copyright (c) 2020 Gerson Fernando Budke + * Copyright (c) 2020-2023 Gerson Fernando Budke * * SPDX-License-Identifier: Apache-2.0 */ @@ -23,6 +23,7 @@ #include #include #include +#include #define LOG_LEVEL CONFIG_I2C_LOG_LEVEL #include @@ -66,8 +67,8 @@ struct i2c_sam_twim_dev_cfg { Twim *regs; void (*irq_config)(void); uint32_t bitrate; + const struct atmel_sam_pmc_config clock_cfg; const struct pinctrl_dev_config *pcfg; - uint8_t periph_id; uint8_t irq_id; uint8_t std_clk_slew_lim; @@ -558,8 +559,9 @@ static int i2c_sam_twim_initialize(const struct device *dev) return ret; } - /* Enable module's clock */ - soc_pmc_peripheral_enable(cfg->periph_id); + /* Enable TWIM clock in PM */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&cfg->clock_cfg); /* Enable the module*/ twim->CR = TWIM_CR_MEN; @@ -614,7 +616,7 @@ static const struct i2c_driver_api i2c_sam_twim_driver_api = { static const struct i2c_sam_twim_dev_cfg i2c##n##_sam_config = {\ .regs = (Twim *)DT_INST_REG_ADDR(n), \ .irq_config = i2c##n##_sam_irq_config, \ - .periph_id = DT_INST_PROP(n, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \ .irq_id = DT_INST_IRQN(n), \ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ .bitrate = DT_INST_PROP(n, clock_frequency), \ diff --git a/drivers/i2c/i2c_sam_twi.c b/drivers/i2c/i2c_sam_twi.c index 254fa6846062..61256a35eea8 100644 --- a/drivers/i2c/i2c_sam_twi.c +++ b/drivers/i2c/i2c_sam_twi.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2017 Piotr Mienkowski + * Copyright (c) 2023 Gerson Fernando Budke * * SPDX-License-Identifier: Apache-2.0 */ @@ -23,6 +24,7 @@ #include #include #include +#include #define LOG_LEVEL CONFIG_I2C_LOG_LEVEL #include @@ -43,8 +45,8 @@ struct i2c_sam_twi_dev_cfg { Twi *regs; void (*irq_config)(void); uint32_t bitrate; + const struct atmel_sam_pmc_config clock_cfg; const struct pinctrl_dev_config *pcfg; - uint8_t periph_id; uint8_t irq_id; }; @@ -325,8 +327,9 @@ static int i2c_sam_twi_initialize(const struct device *dev) return ret; } - /* Enable module's clock */ - soc_pmc_peripheral_enable(dev_cfg->periph_id); + /* Enable TWI clock in PMC */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&dev_cfg->clock_cfg); /* Reset TWI module */ twi->TWI_CR = TWI_CR_SWRST; @@ -364,7 +367,7 @@ static const struct i2c_driver_api i2c_sam_twi_driver_api = { static const struct i2c_sam_twi_dev_cfg i2c##n##_sam_config = { \ .regs = (Twi *)DT_INST_REG_ADDR(n), \ .irq_config = i2c##n##_sam_irq_config, \ - .periph_id = DT_INST_PROP(n, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \ .irq_id = DT_INST_IRQN(n), \ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ .bitrate = DT_INST_PROP(n, clock_frequency), \ diff --git a/drivers/i2c/i2c_sam_twihs.c b/drivers/i2c/i2c_sam_twihs.c index 6a68951ce5d0..034adee22271 100644 --- a/drivers/i2c/i2c_sam_twihs.c +++ b/drivers/i2c/i2c_sam_twihs.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2017 Piotr Mienkowski + * Copyright (c) 2023 Gerson Fernando Budke * * SPDX-License-Identifier: Apache-2.0 */ @@ -21,6 +22,7 @@ #include #include #include +#include #define LOG_LEVEL CONFIG_I2C_LOG_LEVEL #include @@ -43,8 +45,8 @@ struct i2c_sam_twihs_dev_cfg { Twihs *regs; void (*irq_config)(void); uint32_t bitrate; + const struct atmel_sam_pmc_config clock_cfg; const struct pinctrl_dev_config *pcfg; - uint8_t periph_id; uint8_t irq_id; }; @@ -296,8 +298,9 @@ static int i2c_sam_twihs_initialize(const struct device *dev) return ret; } - /* Enable module's clock */ - soc_pmc_peripheral_enable(dev_cfg->periph_id); + /* Enable TWIHS clock in PMC */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&dev_cfg->clock_cfg); /* Reset the module */ twihs->TWIHS_CR = TWIHS_CR_SWRST; @@ -335,7 +338,7 @@ static const struct i2c_driver_api i2c_sam_twihs_driver_api = { static const struct i2c_sam_twihs_dev_cfg i2c##n##_sam_config = {\ .regs = (Twihs *)DT_INST_REG_ADDR(n), \ .irq_config = i2c##n##_sam_irq_config, \ - .periph_id = DT_INST_PROP(n, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \ .irq_id = DT_INST_IRQN(n), \ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ .bitrate = DT_INST_PROP(n, clock_frequency), \ diff --git a/dts/arm/atmel/sam3x.dtsi b/dts/arm/atmel/sam3x.dtsi index dcc54deb88e1..bed468fcbbae 100644 --- a/dts/arm/atmel/sam3x.dtsi +++ b/dts/arm/atmel/sam3x.dtsi @@ -79,7 +79,7 @@ clock-frequency = ; reg = <0x4008c000 0x128>; interrupts = <22 0>; - peripheral-id = <22>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 22>; status = "disabled"; #address-cells = <1>; #size-cells = <0>; @@ -90,7 +90,7 @@ clock-frequency = ; reg = <0x40090000 0x128>; interrupts = <23 0>; - peripheral-id = <23>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 23>; status = "disabled"; #address-cells = <1>; #size-cells = <0>; diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index 16605670e165..0d7db875607d 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -79,7 +79,7 @@ clock-frequency = ; reg = <0x400a8000 0x4000>; interrupts = <17 0>; - peripheral-id = <17>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 17>; status = "disabled"; #address-cells = <1>; #size-cells = <0>; @@ -90,7 +90,7 @@ clock-frequency = ; reg = <0x400ac000 0x4000>; interrupts = <18 0>; - peripheral-id = <18>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 18>; status = "disabled"; #address-cells = <1>; #size-cells = <0>; diff --git a/dts/arm/atmel/sam4l.dtsi b/dts/arm/atmel/sam4l.dtsi index bd0e2cfe1364..eb030e365687 100644 --- a/dts/arm/atmel/sam4l.dtsi +++ b/dts/arm/atmel/sam4l.dtsi @@ -84,7 +84,7 @@ clock-frequency = ; reg = <0x40018000 0x4000>; interrupts = <61 0>; - peripheral-id = <4>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 4>; status = "disabled"; #address-cells = <1>; #size-cells = <0>; @@ -94,7 +94,7 @@ clock-frequency = ; reg = <0x4001c000 0x4000>; interrupts = <63 0>; - peripheral-id = <6>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 6>; status = "disabled"; #address-cells = <1>; #size-cells = <0>; @@ -104,7 +104,7 @@ clock-frequency = ; reg = <0x40078000 0x4000>; interrupts = <77 0>; - peripheral-id = <21>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 21>; status = "disabled"; #address-cells = <1>; #size-cells = <0>; @@ -114,7 +114,7 @@ clock-frequency = ; reg = <0x4007c000 0x4000>; interrupts = <78 0>; - peripheral-id = <22>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 22>; status = "disabled"; #address-cells = <1>; #size-cells = <0>; diff --git a/dts/arm/atmel/sam4s.dtsi b/dts/arm/atmel/sam4s.dtsi index bfc5bb6344db..e043c12ac8e4 100644 --- a/dts/arm/atmel/sam4s.dtsi +++ b/dts/arm/atmel/sam4s.dtsi @@ -81,7 +81,7 @@ clock-frequency = ; reg = <0x40018000 0x128>; interrupts = <19 0>; - peripheral-id = <19>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 19>; status = "disabled"; #address-cells = <1>; #size-cells = <0>; @@ -92,7 +92,7 @@ clock-frequency = ; reg = <0x4001c000 0x128>; interrupts = <20 0>; - peripheral-id = <20>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 20>; status = "disabled"; #address-cells = <1>; #size-cells = <0>; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index 73dafc5c3e17..8695876e3e70 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -89,7 +89,7 @@ #size-cells = <0>; reg = <0x40018000 0x12B>; interrupts = <19 0>; - peripheral-id = <19>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 19>; status = "disabled"; }; @@ -100,7 +100,7 @@ #size-cells = <0>; reg = <0x4001c000 0x12B>; interrupts = <20 0>; - peripheral-id = <20>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 20>; status = "disabled"; }; @@ -111,7 +111,7 @@ #size-cells = <0>; reg = <0x40060000 0x12B>; interrupts = <41 0>; - peripheral-id = <41>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 41>; status = "disabled"; }; diff --git a/dts/bindings/i2c/atmel,sam-i2c-twi.yaml b/dts/bindings/i2c/atmel,sam-i2c-twi.yaml index 491ac2f475af..c22646160d5e 100644 --- a/dts/bindings/i2c/atmel,sam-i2c-twi.yaml +++ b/dts/bindings/i2c/atmel,sam-i2c-twi.yaml @@ -16,7 +16,5 @@ properties: interrupts: required: true - peripheral-id: - type: int - description: peripheral ID + clocks: required: true diff --git a/dts/bindings/i2c/atmel,sam-i2c-twihs.yaml b/dts/bindings/i2c/atmel,sam-i2c-twihs.yaml index 22cd734c9177..abaad2cf27ce 100644 --- a/dts/bindings/i2c/atmel,sam-i2c-twihs.yaml +++ b/dts/bindings/i2c/atmel,sam-i2c-twihs.yaml @@ -16,7 +16,5 @@ properties: interrupts: required: true - peripheral-id: - type: int - description: peripheral ID + clocks: required: true diff --git a/dts/bindings/i2c/atmel,sam-i2c-twim.yaml b/dts/bindings/i2c/atmel,sam-i2c-twim.yaml index 1eb5aece5583..1b865d256ca3 100644 --- a/dts/bindings/i2c/atmel,sam-i2c-twim.yaml +++ b/dts/bindings/i2c/atmel,sam-i2c-twim.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2020 Gerson Fernando Budke +# Copyright (c) 2020-2023 Gerson Fernando Budke # SPDX-License-Identifier: Apache-2.0 description: | @@ -48,10 +48,8 @@ properties: interrupts: required: true - peripheral-id: - type: int + clocks: required: true - description: peripheral ID std-clk-slew-lim: type: int From 91e219c644d6f9136d95ab738fa8428f6e91fba6 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Tue, 7 Mar 2023 19:37:11 +0100 Subject: [PATCH 0585/1906] drivers: entropy: sam/sam0: Update to use clock control This update Atmel SAM trng driver to use clock control driver. Signed-off-by: Gerson Fernando Budke --- drivers/entropy/entropy_sam.c | 8 ++++++-- dts/arm/atmel/sam4l.dtsi | 2 +- dts/arm/atmel/samd5x.dtsi | 1 - dts/arm/atmel/same70.dtsi | 2 +- dts/arm/atmel/saml2x.dtsi | 1 - dts/bindings/rng/atmel,sam-trng.yaml | 5 ----- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/entropy/entropy_sam.c b/drivers/entropy/entropy_sam.c index 1f2c1e2c5049..0a98d50201be 100644 --- a/drivers/entropy/entropy_sam.c +++ b/drivers/entropy/entropy_sam.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2018 Aurelien Jarno + * Copyright (c) 2023 Gerson Fernando Budke * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,6 +9,7 @@ #include #include +#include #include #include #include @@ -165,8 +167,10 @@ static int entropy_sam_init(const struct device *dev) /* Enable the TRNG */ trng->CTRLA.bit.ENABLE = 1; #else - /* Enable the user interface clock */ - soc_pmc_peripheral_enable(DT_INST_PROP(0, peripheral_id)); + /* Enable TRNG in PMC */ + const struct atmel_sam_pmc_config clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(0); + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&clock_cfg); /* Enable the TRNG */ trng->TRNG_CR = TRNG_CR_KEY_PASSWD | TRNG_CR_ENABLE; diff --git a/dts/arm/atmel/sam4l.dtsi b/dts/arm/atmel/sam4l.dtsi index eb030e365687..213ec57a87df 100644 --- a/dts/arm/atmel/sam4l.dtsi +++ b/dts/arm/atmel/sam4l.dtsi @@ -229,7 +229,7 @@ compatible = "atmel,sam-trng"; reg = <0x40068000 0x4000>; interrupts = <73 0>; - peripheral-id = <17>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 17>; status = "okay"; }; diff --git a/dts/arm/atmel/samd5x.dtsi b/dts/arm/atmel/samd5x.dtsi index 4a4b5508a1eb..e16267df66ce 100644 --- a/dts/arm/atmel/samd5x.dtsi +++ b/dts/arm/atmel/samd5x.dtsi @@ -279,7 +279,6 @@ trng: random@42002800 { compatible = "atmel,sam-trng"; reg = <0x42002800 0x1e>; - peripheral-id = <0>; interrupts = <131 0>; }; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index 8695876e3e70..bfb282f70e31 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -386,7 +386,7 @@ compatible = "atmel,sam-trng"; reg = <0x40070000 0x4000>; interrupts = <57 0>; - peripheral-id = <57>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 57>; status = "okay"; }; diff --git a/dts/arm/atmel/saml2x.dtsi b/dts/arm/atmel/saml2x.dtsi index 768ec3d78984..ef4f88d54a19 100644 --- a/dts/arm/atmel/saml2x.dtsi +++ b/dts/arm/atmel/saml2x.dtsi @@ -195,7 +195,6 @@ trng: random@42003800 { compatible = "atmel,sam-trng"; reg = <0x42003800 0x24>; - peripheral-id = <0>; interrupts = <27 0>; }; }; diff --git a/dts/bindings/rng/atmel,sam-trng.yaml b/dts/bindings/rng/atmel,sam-trng.yaml index 23adaca31fb7..2df7a588d17c 100644 --- a/dts/bindings/rng/atmel,sam-trng.yaml +++ b/dts/bindings/rng/atmel,sam-trng.yaml @@ -13,8 +13,3 @@ properties: interrupts: required: true - - peripheral-id: - type: int - description: peripheral ID - required: true From 4f59d504411c9a89cde29bc1321eceac0f25ff3e Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Tue, 7 Mar 2023 19:43:12 +0100 Subject: [PATCH 0586/1906] drivers: spi: sam: Update to use clock control This update Atmel SAM spi driver to use clock control driver. Signed-off-by: Gerson Fernando Budke --- drivers/spi/spi_sam.c | 10 +++++++--- dts/arm/atmel/sam4e.dtsi | 2 +- dts/arm/atmel/sam4l.dtsi | 2 +- dts/arm/atmel/sam4s.dtsi | 2 +- dts/arm/atmel/same70.dtsi | 4 ++-- dts/bindings/spi/atmel,sam-spi.yaml | 4 +--- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/spi/spi_sam.c b/drivers/spi/spi_sam.c index 4e5bc7140dce..23ad86910bd6 100644 --- a/drivers/spi/spi_sam.c +++ b/drivers/spi/spi_sam.c @@ -1,6 +1,7 @@ /* * Copyright (c) 2017 Google LLC. * Copyright (c) 2018 qianfan Zhao. + * Copyright (c) 2023 Gerson Fernando Budke. * * SPDX-License-Identifier: Apache-2.0 */ @@ -17,6 +18,7 @@ LOG_MODULE_REGISTER(spi_sam); #include #include #include +#include #include #define SAM_SPI_CHIP_SELECT_COUNT 4 @@ -27,7 +29,7 @@ LOG_MODULE_REGISTER(spi_sam); /* Device constant configuration parameters */ struct spi_sam_config { Spi *regs; - uint32_t periph_id; + const struct atmel_sam_pmc_config clock_cfg; const struct pinctrl_dev_config *pcfg; bool loopback; @@ -680,7 +682,9 @@ static int spi_sam_init(const struct device *dev) const struct spi_sam_config *cfg = dev->config; struct spi_sam_data *data = dev->data; - soc_pmc_peripheral_enable(cfg->periph_id); + /* Enable SPI clock in PMC */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&cfg->clock_cfg); err = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); if (err < 0) { @@ -729,7 +733,7 @@ static const struct spi_driver_api spi_sam_driver_api = { #define SPI_SAM_DEFINE_CONFIG(n) \ static const struct spi_sam_config spi_sam_config_##n = { \ .regs = (Spi *)DT_INST_REG_ADDR(n), \ - .periph_id = DT_INST_PROP(n, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ .loopback = DT_INST_PROP(n, loopback), \ COND_CODE_1(SPI_SAM_USE_DMA(n), (SPI_DMA_INIT(n)), ()) \ diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index 0d7db875607d..1febdd9fba9e 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -102,7 +102,7 @@ #size-cells = <0>; reg = <0x40088000 0x4000>; interrupts = <19 0>; - peripheral-id = <19>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 19>; status = "disabled"; }; diff --git a/dts/arm/atmel/sam4l.dtsi b/dts/arm/atmel/sam4l.dtsi index 213ec57a87df..cca4ddd41d9e 100644 --- a/dts/arm/atmel/sam4l.dtsi +++ b/dts/arm/atmel/sam4l.dtsi @@ -124,7 +124,7 @@ compatible = "atmel,sam-spi"; reg = <0x40008000 0x4000>; interrupts = <54 0>; - peripheral-id = <1>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 1>; status = "disabled"; #address-cells = <1>; #size-cells = <0>; diff --git a/dts/arm/atmel/sam4s.dtsi b/dts/arm/atmel/sam4s.dtsi index e043c12ac8e4..8dfca4682125 100644 --- a/dts/arm/atmel/sam4s.dtsi +++ b/dts/arm/atmel/sam4s.dtsi @@ -104,7 +104,7 @@ #size-cells = <0>; reg = <0x40008000 0x4000>; interrupts = <21 0>; - peripheral-id = <21>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 21>; status = "disabled"; }; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index bfb282f70e31..a4605d541c55 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -121,7 +121,7 @@ #size-cells = <0>; reg = <0x40008000 0x4000>; interrupts = <21 0>; - peripheral-id = <21>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 21>; status = "disabled"; }; @@ -131,7 +131,7 @@ #size-cells = <0>; reg = <0x40058000 0x4000>; interrupts = <42 0>; - peripheral-id = <42>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 42>; status = "disabled"; }; diff --git a/dts/bindings/spi/atmel,sam-spi.yaml b/dts/bindings/spi/atmel,sam-spi.yaml index fc5e3bc7e3a8..d97b59fa0945 100644 --- a/dts/bindings/spi/atmel,sam-spi.yaml +++ b/dts/bindings/spi/atmel,sam-spi.yaml @@ -16,9 +16,7 @@ properties: interrupts: required: true - peripheral-id: - type: int - description: peripheral ID + clocks: required: true loopback: From 41ab680a4fae854e5028c4e44b0616d26009ea3b Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Tue, 7 Mar 2023 19:47:48 +0100 Subject: [PATCH 0587/1906] drivers: can: sam: Update to use clock control This update Atmel SAM can driver to use clock control driver. Signed-off-by: Gerson Fernando Budke --- drivers/can/can_sam.c | 9 ++++++--- dts/arm/atmel/same70.dtsi | 4 ++-- dts/bindings/can/atmel,sam-can.yaml | 4 +--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/can/can_sam.c b/drivers/can/can_sam.c index 86183d20af84..cbf8c28db31a 100644 --- a/drivers/can/can_sam.c +++ b/drivers/can/can_sam.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -20,8 +21,8 @@ LOG_MODULE_REGISTER(can_sam, CONFIG_CAN_LOG_LEVEL); struct can_sam_config { void (*config_irq)(void); + const struct atmel_sam_pmc_config clock_cfg; const struct pinctrl_dev_config *pcfg; - uint8_t pmc_id; int divider; }; @@ -44,7 +45,9 @@ static void can_sam_clock_enable(const struct can_sam_config *sam_cfg) REG_PMC_PCK5 = PMC_PCK_CSS_UPLL_CLK | PMC_PCK_PRES(sam_cfg->divider - 1); PMC->PMC_SCER |= PMC_SCER_PCK5; - soc_pmc_peripheral_enable(sam_cfg->pmc_id); + /* Enable CAN clock in PMC */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&sam_cfg->clock_cfg); } static int can_sam_init(const struct device *dev) @@ -136,7 +139,7 @@ static void config_can_##inst##_irq(void) #define CAN_SAM_CFG_INST(inst) \ static const struct can_sam_config can_sam_cfg_##inst = { \ - .pmc_id = DT_INST_PROP(inst, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(inst), \ .divider = DT_INST_PROP(inst, divider), \ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ .config_irq = config_can_##inst##_irq, \ diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index a4605d541c55..c72c0991211b 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -424,7 +424,7 @@ reg-names = "m_can"; interrupts = <35 0>, <36 0>; interrupt-names = "LINE_0", "LINE_1"; - peripheral-id = <35>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 35>; divider = <6>; sjw = <1>; sample-point = <875>; @@ -439,7 +439,7 @@ reg-names = "m_can"; interrupts = <37 0>, <38 0>; interrupt-names = "LINE_0", "LINE_1"; - peripheral-id = <37>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 37>; divider = <6>; sjw = <1>; sample-point = <875>; diff --git a/dts/bindings/can/atmel,sam-can.yaml b/dts/bindings/can/atmel,sam-can.yaml index 81fca805f214..7f00f6d2325e 100644 --- a/dts/bindings/can/atmel,sam-can.yaml +++ b/dts/bindings/can/atmel,sam-can.yaml @@ -13,10 +13,8 @@ properties: interrupts: required: true - peripheral-id: - type: int + clocks: required: true - description: peripheral ID divider: type: int From 3bc47d77b2a953c6e0228fdaf9b5272f5ff4d3f5 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Tue, 7 Mar 2023 19:51:15 +0100 Subject: [PATCH 0588/1906] drivers: dac: sam: Update to use clock control This update Atmel SAM dac driver to use clock control driver. Signed-off-by: Gerson Fernando Budke --- drivers/dac/dac_sam.c | 8 +++++--- dts/arm/atmel/same70.dtsi | 2 +- dts/bindings/dac/atmel,sam-dac.yaml | 5 +---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/dac/dac_sam.c b/drivers/dac/dac_sam.c index 9eb8a70b4380..724d10ba83ff 100644 --- a/drivers/dac/dac_sam.c +++ b/drivers/dac/dac_sam.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -33,10 +34,10 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_SOC_SERIES_SAME70) || /* Device constant configuration parameters */ struct dac_sam_dev_cfg { Dacc *regs; + const struct atmel_sam_pmc_config clock_cfg; const struct pinctrl_dev_config *pcfg; void (*irq_config)(void); uint8_t irq_id; - uint8_t periph_id; uint8_t prescaler; }; @@ -133,7 +134,8 @@ static int dac_sam_init(const struct device *dev) } /* Enable DAC clock in PMC */ - soc_pmc_peripheral_enable(dev_cfg->periph_id); + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&dev_cfg->clock_cfg); retval = pinctrl_apply_state(dev_cfg->pcfg, PINCTRL_STATE_DEFAULT); if (retval < 0) { @@ -171,7 +173,7 @@ static const struct dac_sam_dev_cfg dacc_sam_config = { .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0), .irq_id = DT_INST_IRQN(0), .irq_config = dacc_irq_config, - .periph_id = DT_INST_PROP(0, peripheral_id), + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(0), .prescaler = DT_INST_PROP(0, prescaler), }; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index c72c0991211b..3e4f1fbcde24 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -221,7 +221,7 @@ compatible = "atmel,sam-dac"; reg = <0x40040000 0x100>; interrupts = <30 0>; - peripheral-id = <30>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 30>; status = "disabled"; #io-channel-cells = <1>; }; diff --git a/dts/bindings/dac/atmel,sam-dac.yaml b/dts/bindings/dac/atmel,sam-dac.yaml index 6ca131438a9a..6b650d2bec12 100644 --- a/dts/bindings/dac/atmel,sam-dac.yaml +++ b/dts/bindings/dac/atmel,sam-dac.yaml @@ -13,11 +13,8 @@ properties: reg: required: true - peripheral-id: - type: int + clocks: required: true - description: | - peripheral ID prescaler: type: int From bf4669605718f928452bed057dd3d19edd2c9d8a Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Tue, 7 Mar 2023 19:55:11 +0100 Subject: [PATCH 0589/1906] drivers: dma: sam: Update to use clock control This update Atmel SAM xdmac driver to use clock control driver. Signed-off-by: Gerson Fernando Budke --- drivers/dma/dma_sam_xdmac.c | 10 ++++++---- dts/arm/atmel/same70.dtsi | 4 ++-- dts/bindings/dma/atmel,sam-xdmac.yaml | 4 +--- .../i2s/i2s_api/boards/sam_e70_xplained.overlay | 3 +++ tests/drivers/i2s/i2s_api/boards/sam_v71_xult.overlay | 3 +++ 5 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 tests/drivers/i2s/i2s_api/boards/sam_e70_xplained.overlay create mode 100644 tests/drivers/i2s/i2s_api/boards/sam_v71_xult.overlay diff --git a/drivers/dma/dma_sam_xdmac.c b/drivers/dma/dma_sam_xdmac.c index e35f38c5c333..08eeec05b261 100644 --- a/drivers/dma/dma_sam_xdmac.c +++ b/drivers/dma/dma_sam_xdmac.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "dma_sam_xdmac.h" #define LOG_LEVEL CONFIG_DMA_LOG_LEVEL @@ -38,7 +39,7 @@ struct sam_xdmac_channel_cfg { struct sam_xdmac_dev_cfg { Xdmac *regs; void (*irq_config)(void); - uint8_t periph_id; + const struct atmel_sam_pmc_config clock_cfg; uint8_t irq_id; }; @@ -357,8 +358,9 @@ static int sam_xdmac_initialize(const struct device *dev) /* Configure interrupts */ dev_cfg->irq_config(); - /* Enable module's clock */ - soc_pmc_peripheral_enable(dev_cfg->periph_id); + /* Enable XDMAC clock in PMC */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&dev_cfg->clock_cfg); /* Disable all channels */ xdmac->XDMAC_GD = UINT32_MAX; @@ -391,7 +393,7 @@ static void dma0_sam_irq_config(void) static const struct sam_xdmac_dev_cfg dma0_sam_config = { .regs = (Xdmac *)DT_INST_REG_ADDR(0), .irq_config = dma0_sam_irq_config, - .periph_id = DT_INST_PROP(0, peripheral_id), + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(0), .irq_id = DT_INST_IRQN(0), }; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index 3e4f1fbcde24..355626c84947 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -394,14 +394,14 @@ compatible = "atmel,sam-xdmac"; reg = <0x40078000 0x400>; interrupts = <58 0>; - peripheral-id = <58>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 58>; #dma-cells = <2>; status = "disabled"; }; ssc: ssc@40004000 { compatible = "atmel,sam-ssc"; - reg = <0x40004000 0x400>; + reg = <0x40004000 0x4000>; interrupts = <22 0>; peripheral-id = <22>; status = "disabled"; diff --git a/dts/bindings/dma/atmel,sam-xdmac.yaml b/dts/bindings/dma/atmel,sam-xdmac.yaml index cd7a2d79b682..8e2f3f384c91 100644 --- a/dts/bindings/dma/atmel,sam-xdmac.yaml +++ b/dts/bindings/dma/atmel,sam-xdmac.yaml @@ -14,9 +14,7 @@ properties: interrupts: required: true - peripheral-id: - type: int - description: peripheral ID + clocks: required: true "#dma-cells": diff --git a/tests/drivers/i2s/i2s_api/boards/sam_e70_xplained.overlay b/tests/drivers/i2s/i2s_api/boards/sam_e70_xplained.overlay new file mode 100644 index 000000000000..bfc67069c150 --- /dev/null +++ b/tests/drivers/i2s/i2s_api/boards/sam_e70_xplained.overlay @@ -0,0 +1,3 @@ +&xdmac { + status = "okay"; +}; diff --git a/tests/drivers/i2s/i2s_api/boards/sam_v71_xult.overlay b/tests/drivers/i2s/i2s_api/boards/sam_v71_xult.overlay new file mode 100644 index 000000000000..bfc67069c150 --- /dev/null +++ b/tests/drivers/i2s/i2s_api/boards/sam_v71_xult.overlay @@ -0,0 +1,3 @@ +&xdmac { + status = "okay"; +}; From 033c7eddec40bdc6e1cdb9818879b4cecdc64c41 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Tue, 7 Mar 2023 20:01:44 +0100 Subject: [PATCH 0590/1906] drivers: memc: sam: Update to use clock control This update Atmel SAM SMC driver to use clock control driver. Signed-off-by: Gerson Fernando Budke --- drivers/memc/memc_sam_smc.c | 11 ++++++----- dts/arm/atmel/sam4e.dtsi | 2 +- dts/arm/atmel/sam4s.dtsi | 2 +- dts/bindings/memory-controllers/atmel,sam-smc.yaml | 8 +++----- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/memc/memc_sam_smc.c b/drivers/memc/memc_sam_smc.c index ab3d76610540..7ba355c1609e 100644 --- a/drivers/memc/memc_sam_smc.c +++ b/drivers/memc/memc_sam_smc.c @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -23,11 +24,9 @@ struct memc_smc_bank_config { struct memc_smc_config { Smc *regs; - uint32_t periph_id; - size_t banks_len; const struct memc_smc_bank_config *banks; - + const struct atmel_sam_pmc_config clock_cfg; const struct pinctrl_dev_config *pcfg; }; @@ -37,7 +36,9 @@ static int memc_smc_init(const struct device *dev) const struct memc_smc_config *cfg = dev->config; SmcCs_number *bank; - soc_pmc_peripheral_enable(cfg->periph_id); + /* Enable SMC clock in PMC */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&cfg->clock_cfg); ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); if (ret < 0) { @@ -93,7 +94,7 @@ static int memc_smc_init(const struct device *dev) PINCTRL_DT_INST_DEFINE(inst); \ static const struct memc_smc_config smc_config_##inst = { \ .regs = (Smc *)DT_INST_REG_ADDR(inst), \ - .periph_id = DT_INST_PROP(inst, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(inst), \ .banks_len = ARRAY_SIZE(smc_bank_config_##inst), \ .banks = smc_bank_config_##inst, \ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index 1febdd9fba9e..92216f94cbc6 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -260,7 +260,7 @@ #address-cells = <1>; #size-cells = <0>; reg = <0x40060000 0x200>; - peripheral-id = <8>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 8>; status = "disabled"; }; }; diff --git a/dts/arm/atmel/sam4s.dtsi b/dts/arm/atmel/sam4s.dtsi index 8dfca4682125..bcc1ae532764 100644 --- a/dts/arm/atmel/sam4s.dtsi +++ b/dts/arm/atmel/sam4s.dtsi @@ -225,7 +225,7 @@ #address-cells = <1>; #size-cells = <0>; reg = <0x400e0000 0x200>; - peripheral-id = <10>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 10>; status = "disabled"; }; }; diff --git a/dts/bindings/memory-controllers/atmel,sam-smc.yaml b/dts/bindings/memory-controllers/atmel,sam-smc.yaml index a755dd2eb0c9..57e646bd73a5 100644 --- a/dts/bindings/memory-controllers/atmel,sam-smc.yaml +++ b/dts/bindings/memory-controllers/atmel,sam-smc.yaml @@ -67,6 +67,9 @@ properties: reg: required: true + clocks: + required: true + "#address-cells": required: true const: 1 @@ -75,11 +78,6 @@ properties: required: true const: 0 - peripheral-id: - type: int - description: peripheral ID - required: true - child-binding: description: | Child device nodes are representing devices connected to the EBI/SMC bus. From 5522e655819ae22d9da86ccae82f269a7abbb053 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Tue, 7 Mar 2023 20:12:54 +0100 Subject: [PATCH 0591/1906] drivers: usb: sam: Update to use clock control This update Atmel SAM usbhs driver to use clock control driver. Signed-off-by: Gerson Fernando Budke --- drivers/usb/device/usb_dc_sam_usbhs.c | 14 ++++++++++---- dts/arm/atmel/sam4l.dtsi | 2 +- dts/arm/atmel/same70.dtsi | 2 +- dts/bindings/usb/atmel,sam-usbc.yaml | 6 ++---- dts/bindings/usb/atmel,sam-usbhs.yaml | 4 +--- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/usb/device/usb_dc_sam_usbhs.c b/drivers/usb/device/usb_dc_sam_usbhs.c index 3111836a4350..a6ade2a6100a 100644 --- a/drivers/usb/device/usb_dc_sam_usbhs.c +++ b/drivers/usb/device/usb_dc_sam_usbhs.c @@ -7,6 +7,7 @@ #define DT_DRV_COMPAT atmel_sam_usbhs #include +#include #include #include #include @@ -309,10 +310,12 @@ static void usb_dc_isr(void) /* Attach USB for device connection */ int usb_dc_attach(void) { + const struct atmel_sam_pmc_config clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(0); uint32_t regval; - /* Start the peripheral clock */ - soc_pmc_peripheral_enable(DT_INST_PROP(0, peripheral_id)); + /* Enable USBHS clock in PMC */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&clock_cfg); /* Enable the USB controller in device mode with the clock frozen */ USBHS->USBHS_CTRL = USBHS_CTRL_UIMOD | USBHS_CTRL_USBE | @@ -359,6 +362,8 @@ int usb_dc_attach(void) /* Detach the USB device */ int usb_dc_detach(void) { + const struct atmel_sam_pmc_config clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(0); + /* Detach the device */ USBHS->USBHS_DEVCTRL |= USBHS_DEVCTRL_DETACH; @@ -368,8 +373,9 @@ int usb_dc_detach(void) /* Disable the USB controller and freeze the clock */ USBHS->USBHS_CTRL = USBHS_CTRL_UIMOD | USBHS_CTRL_FRZCLK; - /* Disable the peripheral clock */ - soc_pmc_peripheral_enable(DT_INST_PROP(0, peripheral_id)); + /* Disable USBHS clock in PMC */ + (void)clock_control_off(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&clock_cfg); /* Disable interrupt */ irq_disable(DT_INST_IRQN(0)); diff --git a/dts/arm/atmel/sam4l.dtsi b/dts/arm/atmel/sam4l.dtsi index cca4ddd41d9e..1f11478044fa 100644 --- a/dts/arm/atmel/sam4l.dtsi +++ b/dts/arm/atmel/sam4l.dtsi @@ -166,7 +166,7 @@ interrupt-names = "usbc"; maximum-speed = "full-speed"; num-bidir-endpoints = <8>; - peripheral-id = <101>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 101>; status = "disabled"; }; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index 355626c84947..5ceb04921dec 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -314,7 +314,7 @@ interrupt-names = "usbhs"; maximum-speed = "high-speed"; num-bidir-endpoints = <10>; - peripheral-id = <34>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 34>; status = "disabled"; }; diff --git a/dts/bindings/usb/atmel,sam-usbc.yaml b/dts/bindings/usb/atmel,sam-usbc.yaml index 9d38082a886e..eda0c34b6fc0 100644 --- a/dts/bindings/usb/atmel,sam-usbc.yaml +++ b/dts/bindings/usb/atmel,sam-usbc.yaml @@ -1,5 +1,5 @@ # Copyright (c) 2018 Aurelien Jarno -# Copyright (c) 2020 Gerson Fernando Budke +# Copyright (c) 2020*2023 Gerson Fernando Budke # SPDX-License-Identifier: Apache-2.0 description: | @@ -18,7 +18,5 @@ properties: interrupts: required: true - peripheral-id: - type: int + clocks: required: true - description: peripheral ID diff --git a/dts/bindings/usb/atmel,sam-usbhs.yaml b/dts/bindings/usb/atmel,sam-usbhs.yaml index ca9bdc62a3c6..e6c4c6110ef6 100644 --- a/dts/bindings/usb/atmel,sam-usbhs.yaml +++ b/dts/bindings/usb/atmel,sam-usbhs.yaml @@ -17,7 +17,5 @@ properties: interrupts: required: true - peripheral-id: - type: int + clocks: required: true - description: peripheral ID From d2e9b4682c731ece93bfe2a6b6c845c7524977ff Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Tue, 7 Mar 2023 23:00:53 +0100 Subject: [PATCH 0592/1906] drivers: pwm: sam: Update to use clock control This update Atmel SAM pwm driver to use clock control driver. Signed-off-by: Gerson Fernando Budke --- drivers/pwm/pwm_sam.c | 11 ++++++----- dts/arm/atmel/sam4s.dtsi | 2 +- dts/arm/atmel/same70.dtsi | 4 ++-- dts/bindings/pwm/atmel,sam-pwm.yaml | 4 +--- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/pwm/pwm_sam.c b/drivers/pwm/pwm_sam.c index 805a3f30a0d1..64b6f8456f75 100644 --- a/drivers/pwm/pwm_sam.c +++ b/drivers/pwm/pwm_sam.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -23,8 +24,8 @@ LOG_MODULE_REGISTER(pwm_sam, CONFIG_PWM_LOG_LEVEL); struct sam_pwm_config { Pwm *regs; + const struct atmel_sam_pmc_config clock_cfg; const struct pinctrl_dev_config *pcfg; - uint32_t id; uint8_t prescaler; uint8_t divider; }; @@ -96,15 +97,15 @@ static int sam_pwm_init(const struct device *dev) const struct sam_pwm_config *config = dev->config; Pwm * const pwm = config->regs; - uint32_t id = config->id; uint8_t prescaler = config->prescaler; uint8_t divider = config->divider; int retval; /* FIXME: way to validate prescaler & divider */ - /* Enable the PWM peripheral */ - soc_pmc_peripheral_enable(id); + /* Enable PWM clock in PMC */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&config->clock_cfg); retval = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); if (retval < 0) { @@ -127,7 +128,7 @@ static const struct pwm_driver_api sam_pwm_driver_api = { static const struct sam_pwm_config sam_pwm_config_##inst = { \ .regs = (Pwm *)DT_INST_REG_ADDR(inst), \ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ - .id = DT_INST_PROP(inst, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(inst), \ .prescaler = DT_INST_PROP(inst, prescaler), \ .divider = DT_INST_PROP(inst, divider), \ }; \ diff --git a/dts/arm/atmel/sam4s.dtsi b/dts/arm/atmel/sam4s.dtsi index bcc1ae532764..6a1a1e6b1002 100644 --- a/dts/arm/atmel/sam4s.dtsi +++ b/dts/arm/atmel/sam4s.dtsi @@ -128,7 +128,7 @@ compatible = "atmel,sam-pwm"; reg = <0x40020000 0x4000>; interrupts = <31 1>; - peripheral-id = <31>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 31>; prescaler = <10>; divider = <1>; #pwm-cells = <3>; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index 5ceb04921dec..9c9a3806a7c5 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -287,7 +287,7 @@ compatible = "atmel,sam-pwm"; reg = <0x40020000 0x4000>; interrupts = <31 0>; - peripheral-id = <31>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 31>; status = "disabled"; prescaler = <10>; divider = <1>; @@ -298,7 +298,7 @@ compatible = "atmel,sam-pwm"; reg = <0x4005c000 0x4000>; interrupts = <60 0>; - peripheral-id = <60>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 60>; status = "disabled"; prescaler = <10>; divider = <1>; diff --git a/dts/bindings/pwm/atmel,sam-pwm.yaml b/dts/bindings/pwm/atmel,sam-pwm.yaml index 11b175887c13..fe7459b35870 100644 --- a/dts/bindings/pwm/atmel,sam-pwm.yaml +++ b/dts/bindings/pwm/atmel,sam-pwm.yaml @@ -17,9 +17,7 @@ properties: interrupts: required: true - peripheral-id: - type: int - description: peripheral ID + clocks: required: true prescaler: From 9f0255131ae1d2556af8581fc9b430cfc6f405f0 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Tue, 7 Mar 2023 23:04:45 +0100 Subject: [PATCH 0593/1906] drivers: pwm: sam: Enable sam3x and sam4e SoCs Add support to Atmel SAM SAM3X and SAM4E PWM feature. Signed-off-by: Gerson Fernando Budke --- boards/arm/arduino_due/arduino_due-pinctrl.dtsi | 9 ++++++++- boards/arm/arduino_due/arduino_due.dts | 8 ++++++++ boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi | 9 ++++++++- boards/arm/sam4e_xpro/sam4e_xpro.dts | 10 +++++++++- dts/arm/atmel/sam3x.dtsi | 11 +++++++++++ dts/arm/atmel/sam4e.dtsi | 11 +++++++++++ 6 files changed, 55 insertions(+), 3 deletions(-) diff --git a/boards/arm/arduino_due/arduino_due-pinctrl.dtsi b/boards/arm/arduino_due/arduino_due-pinctrl.dtsi index 23156e23cac8..08f369eed7dc 100644 --- a/boards/arm/arduino_due/arduino_due-pinctrl.dtsi +++ b/boards/arm/arduino_due/arduino_due-pinctrl.dtsi @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Gerson Fernando Budke + * Copyright (c) 2022-2023, Gerson Fernando Budke * SPDX-License-Identifier: Apache-2.0 */ @@ -52,4 +52,11 @@ ; }; }; + + pwm0_default: pwm0_default { + group1 { + pinmux = , + ; + }; + }; }; diff --git a/boards/arm/arduino_due/arduino_due.dts b/boards/arm/arduino_due/arduino_due.dts index f8e361bd393b..bbfc92b110c7 100644 --- a/boards/arm/arduino_due/arduino_due.dts +++ b/boards/arm/arduino_due/arduino_due.dts @@ -13,6 +13,7 @@ uart-0 = &uart; i2c-0 = &twi0; i2c-1 = &twi1; + pwm-0 = &pwm0; led0 = &yellow_led; watchdog0 = &wdt; }; @@ -64,4 +65,11 @@ pinctrl-names = "default"; }; +&pwm0 { + status = "okay"; + + pinctrl-0 = <&pwm0_default>; + pinctrl-names = "default"; +}; + arduino_i2c: &twi1 { }; diff --git a/boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi b/boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi index 0ab0c73ddfa8..749b794667c2 100644 --- a/boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi +++ b/boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Gerson Fernando Budke + * Copyright (c) 2022-2023, Gerson Fernando Budke * SPDX-License-Identifier: Apache-2.0 */ @@ -74,4 +74,11 @@ ; }; }; + + pwm0_default: pwm0_default { + group1 { + pinmux = , + ; + }; + }; }; diff --git a/boards/arm/sam4e_xpro/sam4e_xpro.dts b/boards/arm/sam4e_xpro/sam4e_xpro.dts index 7a30c4ffc2d9..c42b1934af5c 100644 --- a/boards/arm/sam4e_xpro/sam4e_xpro.dts +++ b/boards/arm/sam4e_xpro/sam4e_xpro.dts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Gerson Fernando Budke + * Copyright (c) 2019-2023 Gerson Fernando Budke * * SPDX-License-Identifier: Apache-2.0 */ @@ -15,6 +15,7 @@ aliases { i2c-0 = &twi0; + pwm-0 = &pwm0; led0 = &yellow_led_1; sw0 = &user_button; wdog = &wdt; @@ -187,6 +188,13 @@ pinctrl-names = "default"; }; +&pwm0 { + status = "okay"; + + pinctrl-0 = <&pwm0_default>; + pinctrl-names = "default"; +}; + &wdt { status = "okay"; }; diff --git a/dts/arm/atmel/sam3x.dtsi b/dts/arm/atmel/sam3x.dtsi index bed468fcbbae..594ea66dc8c3 100644 --- a/dts/arm/atmel/sam3x.dtsi +++ b/dts/arm/atmel/sam3x.dtsi @@ -229,6 +229,17 @@ status = "disabled"; }; + pwm0: pwm@40094000 { + compatible = "atmel,sam-pwm"; + reg = <0x40094000 0x4000>; + interrupts = <36 1>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 36>; + prescaler = <10>; + divider = <1>; + #pwm-cells = <3>; + status = "disabled"; + }; + rstc: rstc@400e1a00 { compatible = "atmel,sam-rstc"; reg = <0x400e1a00 0x10>; diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index 92216f94cbc6..38f8f3f1825a 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -248,6 +248,17 @@ status = "disabled"; }; + pwm0: pwm@40000000 { + compatible = "atmel,sam-pwm"; + reg = <0x40000000 0x4000>; + interrupts = <36 1>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 36>; + prescaler = <10>; + divider = <1>; + #pwm-cells = <3>; + status = "disabled"; + }; + rstc: rstc@400e1800 { compatible = "atmel,sam-rstc"; reg = <0x400e1800 0x10>; From f1b68beca179d46ad5497c36e741a3c298b52277 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Wed, 8 Mar 2023 20:06:01 +0100 Subject: [PATCH 0594/1906] drivers: ssc: sam: Update to use clock control This update Atmel SAM ssc driver to use clock control driver. Signed-off-by: Gerson Fernando Budke --- drivers/i2s/i2s_sam_ssc.c | 10 ++++++---- dts/arm/atmel/same70.dtsi | 2 +- dts/bindings/arm/atmel,sam-ssc.yaml | 4 +--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/i2s/i2s_sam_ssc.c b/drivers/i2s/i2s_sam_ssc.c index b2eb5a9bf3d2..b0fa42672c98 100644 --- a/drivers/i2s/i2s_sam_ssc.c +++ b/drivers/i2s/i2s_sam_ssc.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #define LOG_DOMAIN dev_i2s_sam_ssc @@ -69,8 +70,8 @@ struct i2s_sam_dev_cfg { const struct device *dev_dma; Ssc *regs; void (*irq_config)(void); + const struct atmel_sam_pmc_config clock_cfg; const struct pinctrl_dev_config *pcfg; - uint8_t periph_id; uint8_t irq_id; }; @@ -974,8 +975,9 @@ static int i2s_sam_initialize(const struct device *dev) return ret; } - /* Enable module's clock */ - soc_pmc_peripheral_enable(dev_cfg->periph_id); + /* Enable SSC clock in PMC */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&dev_cfg->clock_cfg); /* Reset the module, disable receiver & transmitter */ ssc->SSC_CR = SSC_CR_RXDIS | SSC_CR_TXDIS | SSC_CR_SWRST; @@ -1015,7 +1017,7 @@ static const struct i2s_sam_dev_cfg i2s0_sam_config = { .dev_dma = DEVICE_DT_GET(DT_INST_DMAS_CTLR_BY_NAME(0, tx)), .regs = (Ssc *)DT_INST_REG_ADDR(0), .irq_config = i2s0_sam_irq_config, - .periph_id = DT_INST_PROP(0, peripheral_id), + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(0), .irq_id = DT_INST_IRQN(0), .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0), }; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index 9c9a3806a7c5..2f4d6aa2db20 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -403,7 +403,7 @@ compatible = "atmel,sam-ssc"; reg = <0x40004000 0x4000>; interrupts = <22 0>; - peripheral-id = <22>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 22>; status = "disabled"; }; diff --git a/dts/bindings/arm/atmel,sam-ssc.yaml b/dts/bindings/arm/atmel,sam-ssc.yaml index 26fff20c7624..f373b670bdd2 100644 --- a/dts/bindings/arm/atmel,sam-ssc.yaml +++ b/dts/bindings/arm/atmel,sam-ssc.yaml @@ -16,9 +16,7 @@ properties: interrupts: required: true - peripheral-id: - type: int - description: peripheral ID + clocks: required: true dmas: From dc45d7a922089c76e72a128f5b5560455382fc47 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Wed, 8 Mar 2023 23:03:27 +0100 Subject: [PATCH 0595/1906] drivers: sensors: qdec_sam: Update to use clock control This update Atmel SAM QDEC driver to use clock control driver. Signed-off-by: Gerson Fernando Budke --- boards/arm/sam_e70_xplained/sam_e70_xplained.dts | 10 +++++++++- drivers/sensor/qdec_sam/qdec_sam.c | 12 +++++++----- dts/bindings/sensor/atmel,sam-tc-qdec.yaml | 4 +--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/boards/arm/sam_e70_xplained/sam_e70_xplained.dts b/boards/arm/sam_e70_xplained/sam_e70_xplained.dts index 05636e2dddd9..968b19e7562d 100644 --- a/boards/arm/sam_e70_xplained/sam_e70_xplained.dts +++ b/boards/arm/sam_e70_xplained/sam_e70_xplained.dts @@ -1,7 +1,7 @@ /* * Copyright (c) 2017 Piotr Mienkowski * Copyright (c) 2017 Justin Watson - * Copyright (c) 2020 Gerson Fernando Budke + * Copyright (c) 2020-2023 Gerson Fernando Budke * * SPDX-License-Identifier: Apache-2.0 */ @@ -15,3 +15,11 @@ model = "Atmel SAM E70 Xplained board"; compatible = "atmel,sam_e70_xplained", "atmel,same70q21", "atmel,same70"; }; + +&tc0 { + status = "okay"; + compatible = "atmel,sam-tc-qdec"; + + pinctrl-0 = <&tc0_qdec_default>; + pinctrl-names = "default"; +}; diff --git a/drivers/sensor/qdec_sam/qdec_sam.c b/drivers/sensor/qdec_sam/qdec_sam.c index 05f228c58e64..2b731e02a7f4 100644 --- a/drivers/sensor/qdec_sam/qdec_sam.c +++ b/drivers/sensor/qdec_sam/qdec_sam.c @@ -18,6 +18,7 @@ #include #include #include +#include #include LOG_MODULE_REGISTER(qdec_sam, CONFIG_SENSOR_LOG_LEVEL); @@ -25,8 +26,8 @@ LOG_MODULE_REGISTER(qdec_sam, CONFIG_SENSOR_LOG_LEVEL); /* Device constant configuration parameters */ struct qdec_sam_dev_cfg { Tc *regs; + const struct atmel_sam_pmc_config clock_cfg[TCCHANNEL_NUMBER]; const struct pinctrl_dev_config *pcfg; - uint8_t periph_id[TCCHANNEL_NUMBER]; }; /* Device run time data */ @@ -103,9 +104,10 @@ static int qdec_sam_initialize(const struct device *dev) return retval; } - for (int i = 0; i < ARRAY_SIZE(dev_cfg->periph_id); i++) { - /* Enable module's clock */ - soc_pmc_peripheral_enable(dev_cfg->periph_id[i]); + for (int i = 0; i < ARRAY_SIZE(dev_cfg->clock_cfg); i++) { + /* Enable TC clock in PMC */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&dev_cfg->clock_cfg[i]); } qdec_sam_configure(dev); @@ -125,7 +127,7 @@ static const struct sensor_driver_api qdec_sam_driver_api = { static const struct qdec_sam_dev_cfg qdec##n##_sam_config = { \ .regs = (Tc *)DT_INST_REG_ADDR(n), \ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ - .periph_id = DT_INST_PROP(n, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCKS_PMC_CFG(n), \ }; \ \ static struct qdec_sam_dev_data qdec##n##_sam_data; \ diff --git a/dts/bindings/sensor/atmel,sam-tc-qdec.yaml b/dts/bindings/sensor/atmel,sam-tc-qdec.yaml index 2effbfda4848..c7a52e7ddfc3 100644 --- a/dts/bindings/sensor/atmel,sam-tc-qdec.yaml +++ b/dts/bindings/sensor/atmel,sam-tc-qdec.yaml @@ -15,7 +15,5 @@ properties: interrupts: required: true - peripheral-id: - type: array - description: peripheral ID + clocks: required: true From 6634d6b4ff4039ab32ea4d11fb36d57df302f812 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Thu, 9 Mar 2023 18:07:27 +0100 Subject: [PATCH 0596/1906] drivers: afec: sam: Update to use clock control This update Atmel SAM afec driver to use clock control driver. Signed-off-by: Gerson Fernando Budke --- drivers/adc/adc_sam_afec.c | 9 ++++++--- dts/arm/atmel/same70.dtsi | 4 ++-- dts/bindings/adc/atmel,sam-afec.yaml | 4 +--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/adc/adc_sam_afec.c b/drivers/adc/adc_sam_afec.c index df83d381b8ca..dce5044544d0 100644 --- a/drivers/adc/adc_sam_afec.c +++ b/drivers/adc/adc_sam_afec.c @@ -22,6 +22,7 @@ #include #include #include +#include #define ADC_CONTEXT_USES_KERNEL_TIMER #include "adc_context.h" @@ -60,7 +61,7 @@ struct adc_sam_data { struct adc_sam_cfg { Afec *regs; cfg_func_t cfg_func; - uint32_t periph_id; + const struct atmel_sam_pmc_config clock_cfg; const struct pinctrl_dev_config *pcfg; }; @@ -287,7 +288,9 @@ static int adc_sam_init(const struct device *dev) | AFEC_ACR_PGA1EN | AFEC_ACR_IBCTL(1); - soc_pmc_peripheral_enable(cfg->periph_id); + /* Enable AFEC clock in PMC */ + (void)clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t *)&cfg->clock_cfg); /* Connect pins to the peripheral */ retval = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); @@ -359,7 +362,7 @@ static void adc_sam_isr(const struct device *dev) static const struct adc_sam_cfg adc##n##_sam_cfg = { \ .regs = (Afec *)DT_INST_REG_ADDR(n), \ .cfg_func = adc##n##_sam_cfg_func, \ - .periph_id = DT_INST_PROP(n, peripheral_id), \ + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ }; \ \ diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index 2f4d6aa2db20..9b8b5a21f622 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -203,7 +203,7 @@ compatible = "atmel,sam-afec"; reg = <0x4003c000 0x100>; interrupts = <29 0>; - peripheral-id = <29>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 29>; status = "disabled"; #io-channel-cells = <1>; }; @@ -212,7 +212,7 @@ compatible = "atmel,sam-afec"; reg = <0x40064000 0x100>; interrupts = <40 0>; - peripheral-id = <40>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 40>; status = "disabled"; #io-channel-cells = <1>; }; diff --git a/dts/bindings/adc/atmel,sam-afec.yaml b/dts/bindings/adc/atmel,sam-afec.yaml index e2efbea7b947..2b6c33ac8d1e 100644 --- a/dts/bindings/adc/atmel,sam-afec.yaml +++ b/dts/bindings/adc/atmel,sam-afec.yaml @@ -13,9 +13,7 @@ properties: interrupts: required: true - peripheral-id: - type: int - description: peripheral ID + clocks: required: true "#io-channel-cells": From 6951160dd2f3371152ce9316b64f41c366359b4e Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Thu, 9 Mar 2023 18:10:17 +0100 Subject: [PATCH 0597/1906] drivers: afec: sam: Enable sam4e SoCs Add support to Atmel SAM SAM4E AFEC feature. Signed-off-by: Gerson Fernando Budke --- boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi | 13 +++++++ boards/arm/sam4e_xpro/sam4e_xpro.dts | 14 ++++++++ drivers/adc/adc_sam_afec.c | 14 ++++++-- dts/arm/atmel/sam4e.dtsi | 18 ++++++++++ samples/drivers/adc/boards/sam4e_xpro.overlay | 35 +++++++++++++++++++ 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 samples/drivers/adc/boards/sam4e_xpro.overlay diff --git a/boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi b/boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi index 749b794667c2..e83b9eeffe89 100644 --- a/boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi +++ b/boards/arm/sam4e_xpro/sam4e_xpro-pinctrl.dtsi @@ -6,6 +6,19 @@ #include &pinctrl { + afec0_default: afec0_default { + group1 { + pinmux = , + ; + }; + }; + afec1_default: afec1_default { + group1 { + pinmux = , + ; + }; + }; + gmac_mii: gmac_mii { group1 { pinmux = , diff --git a/boards/arm/sam4e_xpro/sam4e_xpro.dts b/boards/arm/sam4e_xpro/sam4e_xpro.dts index c42b1934af5c..24bcfc7f4a84 100644 --- a/boards/arm/sam4e_xpro/sam4e_xpro.dts +++ b/boards/arm/sam4e_xpro/sam4e_xpro.dts @@ -126,6 +126,20 @@ clock-frequency = <120000000>; }; +&afec0 { + status = "okay"; + + pinctrl-0 = <&afec0_default>; + pinctrl-names = "default"; +}; + +&afec1 { + status = "okay"; + + pinctrl-0 = <&afec1_default>; + pinctrl-names = "default"; +}; + &twi0 { status = "okay"; diff --git a/drivers/adc/adc_sam_afec.c b/drivers/adc/adc_sam_afec.c index dce5044544d0..167122d8450b 100644 --- a/drivers/adc/adc_sam_afec.c +++ b/drivers/adc/adc_sam_afec.c @@ -1,6 +1,7 @@ /* * Copyright (c) 2017 comsuisse AG * Copyright (c) 2018 Justin Watson + * Copyright (c) 2023 Gerson Fernando Budke * * SPDX-License-Identifier: Apache-2.0 */ @@ -33,8 +34,10 @@ LOG_MODULE_REGISTER(adc_sam_afec); #define NUM_CHANNELS 12 - #define CONF_ADC_PRESCALER ((SOC_ATMEL_SAM_MCK_FREQ_HZ / 15000000) - 1) +#ifndef AFEC_MR_ONE +#define AFEC_MR_ONE AFEC_MR_ANACH +#endif typedef void (*cfg_func_t)(const struct device *dev); @@ -106,11 +109,13 @@ static int adc_sam_channel_setup(const struct device *dev, return -EINVAL; } +#ifdef AFEC_11147 /* Set single ended channels to unsigned and differential channels * to signed conversions. */ afec->AFEC_EMR &= ~(AFEC_EMR_SIGNMODE( AFEC_EMR_SIGNMODE_SE_UNSG_DF_SIGN_Val)); +#endif return 0; } @@ -284,9 +289,12 @@ static int adc_sam_init(const struct device *dev) } /* Enable PGA and Current Bias. */ - afec->AFEC_ACR = AFEC_ACR_PGA0EN + afec->AFEC_ACR = AFEC_ACR_IBCTL(1) +#ifdef AFEC_11147 + | AFEC_ACR_PGA0EN | AFEC_ACR_PGA1EN - | AFEC_ACR_IBCTL(1); +#endif + ; /* Enable AFEC clock in PMC */ (void)clock_control_on(SAM_DT_PMC_CONTROLLER, diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index 38f8f3f1825a..98e8fe583e0f 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -50,6 +50,24 @@ compatible = "mmio-sram"; }; + afec0: adc@400b0000 { + compatible = "atmel,sam-afec"; + reg = <0x400b0000 0x4000>; + interrupts = <30 0>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 30>; + status = "disabled"; + #io-channel-cells = <1>; + }; + + afec1: adc@400b4000 { + compatible = "atmel,sam-afec"; + reg = <0x400b4000 0x4000>; + interrupts = <31 0>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 31>; + status = "disabled"; + #io-channel-cells = <1>; + }; + eefc: flash-controller@400e0a00 { compatible = "atmel,sam-flash-controller"; reg = <0x400e0a00 0x200>; diff --git a/samples/drivers/adc/boards/sam4e_xpro.overlay b/samples/drivers/adc/boards/sam4e_xpro.overlay new file mode 100644 index 000000000000..f83fec237c14 --- /dev/null +++ b/samples/drivers/adc/boards/sam4e_xpro.overlay @@ -0,0 +1,35 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2023, Gerson Fernando Budke + */ + +#include + +/ { + zephyr,user { + /* adjust channel number according to pinmux in board.dts */ + io-channels = <&afec0 0>, <&afec0 6>; + }; +}; + +&afec0 { + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <12>; + }; + + channel@6 { + reg = <6>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <12>; + }; +}; From 2a24bb263ab60da5753eacdb50211800f25432ac Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Thu, 9 Mar 2023 19:01:27 +0100 Subject: [PATCH 0598/1906] drivers: wdt: sam: Update to use clock control This update Atmel SAM wdt devicetree to use clock control information. Signed-off-by: Gerson Fernando Budke --- dts/arm/atmel/sam3x.dtsi | 2 +- dts/arm/atmel/sam4e.dtsi | 2 +- dts/arm/atmel/sam4s.dtsi | 2 +- dts/arm/atmel/same70.dtsi | 2 +- dts/bindings/watchdog/atmel,sam-watchdog.yaml | 4 +--- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/dts/arm/atmel/sam3x.dtsi b/dts/arm/atmel/sam3x.dtsi index 594ea66dc8c3..0825af7ade69 100644 --- a/dts/arm/atmel/sam3x.dtsi +++ b/dts/arm/atmel/sam3x.dtsi @@ -70,7 +70,7 @@ compatible = "atmel,sam-watchdog"; reg = <0x400e1a50 0xc>; interrupts = <4 0>; - peripheral-id = <4>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 4>; status = "disabled"; }; diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index 98e8fe583e0f..1f8e402bfceb 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -88,7 +88,7 @@ compatible = "atmel,sam-watchdog"; reg = <0x400e1850 0x10>; interrupts = <4 0>; - peripheral-id = <4>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 4>; status = "disabled"; }; diff --git a/dts/arm/atmel/sam4s.dtsi b/dts/arm/atmel/sam4s.dtsi index 6a1a1e6b1002..0027ebb4f5e4 100644 --- a/dts/arm/atmel/sam4s.dtsi +++ b/dts/arm/atmel/sam4s.dtsi @@ -72,7 +72,7 @@ compatible = "atmel,sam-watchdog"; reg = <0x400e1450 0xc>; interrupts = <4 0>; - peripheral-id = <4>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 4>; status = "disabled"; }; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index 9b8b5a21f622..cd2bd92233ea 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -78,7 +78,7 @@ compatible = "atmel,sam-watchdog"; reg = <0x400e1850 0xc>; interrupts = <4 0>; - peripheral-id = <4>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 4>; status = "disabled"; }; diff --git a/dts/bindings/watchdog/atmel,sam-watchdog.yaml b/dts/bindings/watchdog/atmel,sam-watchdog.yaml index adbfca4e6d9b..588d9e60e447 100644 --- a/dts/bindings/watchdog/atmel,sam-watchdog.yaml +++ b/dts/bindings/watchdog/atmel,sam-watchdog.yaml @@ -14,7 +14,5 @@ properties: interrupts: required: true - peripheral-id: - type: int - description: peripheral ID + clocks: required: true From 1dce3c3ee2e9db41a0111709c337bafce1a45834 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Thu, 9 Mar 2023 19:04:15 +0100 Subject: [PATCH 0599/1906] drivers: eefc: sam: Update to use clock control This update Atmel SAM eefc devicetree to use clock control information. Signed-off-by: Gerson Fernando Budke --- dts/arm/atmel/sam3x.dtsi | 2 +- dts/arm/atmel/sam4e.dtsi | 2 +- dts/arm/atmel/sam4s.dtsi | 2 +- dts/arm/atmel/same70.dtsi | 2 +- dts/bindings/flash_controller/atmel,sam-flash-controller.yaml | 4 +--- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/dts/arm/atmel/sam3x.dtsi b/dts/arm/atmel/sam3x.dtsi index 0825af7ade69..f9dc33e458ae 100644 --- a/dts/arm/atmel/sam3x.dtsi +++ b/dts/arm/atmel/sam3x.dtsi @@ -46,7 +46,7 @@ eefc: flash-controller@400e0a00 { compatible = "atmel,sam-flash-controller"; reg = <0x400e0a00 0x200>; - peripheral-id = <6>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 6>; #address-cells = <1>; #size-cells = <1>; diff --git a/dts/arm/atmel/sam4e.dtsi b/dts/arm/atmel/sam4e.dtsi index 1f8e402bfceb..cb809eee42ca 100644 --- a/dts/arm/atmel/sam4e.dtsi +++ b/dts/arm/atmel/sam4e.dtsi @@ -71,7 +71,7 @@ eefc: flash-controller@400e0a00 { compatible = "atmel,sam-flash-controller"; reg = <0x400e0a00 0x200>; - peripheral-id = <6>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 6>; #address-cells = <1>; #size-cells = <1>; diff --git a/dts/arm/atmel/sam4s.dtsi b/dts/arm/atmel/sam4s.dtsi index 0027ebb4f5e4..63a0a2e9cbae 100644 --- a/dts/arm/atmel/sam4s.dtsi +++ b/dts/arm/atmel/sam4s.dtsi @@ -55,7 +55,7 @@ eefc: flash-controller@400e0a00 { compatible = "atmel,sam-flash-controller"; reg = <0x400e0a00 0x200>; - peripheral-id = <6>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 6>; #address-cells = <1>; #size-cells = <1>; diff --git a/dts/arm/atmel/same70.dtsi b/dts/arm/atmel/same70.dtsi index cd2bd92233ea..35131962a2c7 100644 --- a/dts/arm/atmel/same70.dtsi +++ b/dts/arm/atmel/same70.dtsi @@ -60,7 +60,7 @@ compatible = "atmel,sam-flash-controller"; reg = <0x400e0c00 0x200>; interrupts = <6 0>; - peripheral-id = <6>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 6>; #address-cells = <1>; #size-cells = <1>; diff --git a/dts/bindings/flash_controller/atmel,sam-flash-controller.yaml b/dts/bindings/flash_controller/atmel,sam-flash-controller.yaml index 1a768f6136ef..64a84a03758b 100644 --- a/dts/bindings/flash_controller/atmel,sam-flash-controller.yaml +++ b/dts/bindings/flash_controller/atmel,sam-flash-controller.yaml @@ -8,7 +8,5 @@ compatible: "atmel,sam-flash-controller" include: flash-controller.yaml properties: - peripheral-id: - type: int - description: peripheral ID + clocks: required: true From 3c76bd06e47e75ec7654ffe63bc788b5c04c5817 Mon Sep 17 00:00:00 2001 From: Ahmed Moheb Date: Sun, 23 Oct 2022 11:54:32 +0200 Subject: [PATCH 0600/1906] tests: bluetooth: host: Add mocks for ecc.c Add required mocks to be able to compile/test /bluetooth/host/ecc.c Signed-off-by: Ahmed Moheb --- subsys/bluetooth/host/ecc.c | 23 +++++++++++++ tests/bluetooth/host/ecc/CMakeLists.txt | 23 +++++++++++++ .../bluetooth/host/ecc/mocks/ecc_help_utils.c | 11 +++++++ .../bluetooth/host/ecc/mocks/ecc_help_utils.h | 15 +++++++++ tests/bluetooth/host/ecc/mocks/hci_core.c | 19 +++++++++++ tests/bluetooth/host/ecc/mocks/hci_core.h | 16 ++++++++++ tests/bluetooth/host/ecc/mocks/net_buf.c | 13 ++++++++ tests/bluetooth/host/ecc/mocks/net_buf.h | 13 ++++++++ .../host/ecc/mocks/net_buf_expects.c | 32 +++++++++++++++++++ .../host/ecc/mocks/net_buf_expects.h | 23 +++++++++++++ .../bluetooth/host/ecc/testing_common_defs.h | 5 +++ 11 files changed, 193 insertions(+) create mode 100644 tests/bluetooth/host/ecc/CMakeLists.txt create mode 100644 tests/bluetooth/host/ecc/mocks/ecc_help_utils.c create mode 100644 tests/bluetooth/host/ecc/mocks/ecc_help_utils.h create mode 100644 tests/bluetooth/host/ecc/mocks/hci_core.c create mode 100644 tests/bluetooth/host/ecc/mocks/hci_core.h create mode 100644 tests/bluetooth/host/ecc/mocks/net_buf.c create mode 100644 tests/bluetooth/host/ecc/mocks/net_buf.h create mode 100644 tests/bluetooth/host/ecc/mocks/net_buf_expects.c create mode 100644 tests/bluetooth/host/ecc/mocks/net_buf_expects.h create mode 100644 tests/bluetooth/host/ecc/testing_common_defs.h diff --git a/subsys/bluetooth/host/ecc.c b/subsys/bluetooth/host/ecc.c index 82afefc72eb3..0195ed5bd40e 100644 --- a/subsys/bluetooth/host/ecc.c +++ b/subsys/bluetooth/host/ecc.c @@ -7,6 +7,7 @@ #include +#include #include #include "ecc.h" @@ -236,3 +237,25 @@ void bt_hci_evt_le_dhkey_complete(struct net_buf *buf) cb(evt->status ? NULL : evt->dhkey); } } + +#ifdef ZTEST_UNITTEST +uint8_t const *bt_ecc_get_public_key(void) +{ + return pub_key; +} + +uint8_t const *bt_ecc_get_internal_debug_public_key(void) +{ + return debug_public_key; +} + +sys_slist_t *bt_ecc_get_pub_key_cb_slist(void) +{ + return &pub_key_cb_slist; +} + +bt_dh_key_cb_t *bt_ecc_get_dh_key_cb(void) +{ + return &dh_key_cb; +} +#endif /* ZTEST_UNITTEST */ diff --git a/tests/bluetooth/host/ecc/CMakeLists.txt b/tests/bluetooth/host/ecc/CMakeLists.txt new file mode 100644 index 000000000000..078f46b1afdc --- /dev/null +++ b/tests/bluetooth/host/ecc/CMakeLists.txt @@ -0,0 +1,23 @@ +# +# CMakeLists.txt file for creating of mocks library. +# + +add_library(mocks STATIC + mocks/net_buf.c + mocks/net_buf_expects.c + mocks/hci_core.c + mocks/ecc_help_utils.c + + ${ZEPHYR_BASE}/subsys/bluetooth/host/ecc.c + ${ZEPHYR_BASE}/subsys/logging/log_minimal.c +) + +target_include_directories(mocks PUBLIC + . + ${ZEPHYR_BASE}/subsys/bluetooth + ${ZEPHYR_BASE}/subsys/bluetooth/host + ${ZEPHYR_BASE}/tests/bluetooth/host + ${ZEPHYR_BASE}/tests/bluetooth/host/ecc/mocks +) + +target_link_libraries(mocks PRIVATE test_interface) diff --git a/tests/bluetooth/host/ecc/mocks/ecc_help_utils.c b/tests/bluetooth/host/ecc/mocks/ecc_help_utils.c new file mode 100644 index 000000000000..daff4dd7173d --- /dev/null +++ b/tests/bluetooth/host/ecc/mocks/ecc_help_utils.c @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "ecc_help_utils.h" + +#include + +#include diff --git a/tests/bluetooth/host/ecc/mocks/ecc_help_utils.h b/tests/bluetooth/host/ecc/mocks/ecc_help_utils.h new file mode 100644 index 000000000000..2d7ba49e737b --- /dev/null +++ b/tests/bluetooth/host/ecc/mocks/ecc_help_utils.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +typedef void (*bt_dh_key_cb_t)(const uint8_t *key); + +/* ecc.c declarations */ +uint8_t const *bt_ecc_get_public_key(void); +uint8_t const *bt_ecc_get_internal_debug_public_key(void); +sys_slist_t *bt_ecc_get_pub_key_cb_slist(void); +bt_dh_key_cb_t *bt_ecc_get_dh_key_cb(void); diff --git a/tests/bluetooth/host/ecc/mocks/hci_core.c b/tests/bluetooth/host/ecc/mocks/hci_core.c new file mode 100644 index 000000000000..4deee11a4960 --- /dev/null +++ b/tests/bluetooth/host/ecc/mocks/hci_core.c @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mocks/hci_core.h" + +#include +#include + +#include + +struct bt_dev bt_dev = { + .manufacturer = 0x1234, +}; + +DEFINE_FAKE_VALUE_FUNC(struct net_buf *, bt_hci_cmd_create, uint16_t, uint8_t); +DEFINE_FAKE_VALUE_FUNC(int, bt_hci_cmd_send_sync, uint16_t, struct net_buf *, struct net_buf **); diff --git a/tests/bluetooth/host/ecc/mocks/hci_core.h b/tests/bluetooth/host/ecc/mocks/hci_core.h new file mode 100644 index 000000000000..fd78465062c9 --- /dev/null +++ b/tests/bluetooth/host/ecc/mocks/hci_core.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* List of fakes used by this unit tester */ +#define HCI_CORE_FFF_FAKES_LIST(FAKE) \ + FAKE(bt_hci_cmd_create) \ + FAKE(bt_hci_cmd_send_sync) + +DECLARE_FAKE_VALUE_FUNC(struct net_buf *, bt_hci_cmd_create, uint16_t, uint8_t); +DECLARE_FAKE_VALUE_FUNC(int, bt_hci_cmd_send_sync, uint16_t, struct net_buf *, struct net_buf **); diff --git a/tests/bluetooth/host/ecc/mocks/net_buf.c b/tests/bluetooth/host/ecc/mocks/net_buf.c new file mode 100644 index 000000000000..3b0d5102d8d7 --- /dev/null +++ b/tests/bluetooth/host/ecc/mocks/net_buf.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include + +DEFINE_FAKE_VALUE_FUNC(void *, net_buf_simple_add, struct net_buf_simple *, size_t); diff --git a/tests/bluetooth/host/ecc/mocks/net_buf.h b/tests/bluetooth/host/ecc/mocks/net_buf.h new file mode 100644 index 000000000000..bcf78fa83aa0 --- /dev/null +++ b/tests/bluetooth/host/ecc/mocks/net_buf.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* List of fakes used by this unit tester */ +#define NET_BUF_FFF_FAKES_LIST(FAKE) FAKE(net_buf_simple_add) + +DECLARE_FAKE_VALUE_FUNC(void *, net_buf_simple_add, struct net_buf_simple *, size_t); diff --git a/tests/bluetooth/host/ecc/mocks/net_buf_expects.c b/tests/bluetooth/host/ecc/mocks/net_buf_expects.c new file mode 100644 index 000000000000..2e9ee3484adf --- /dev/null +++ b/tests/bluetooth/host/ecc/mocks/net_buf_expects.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mocks/net_buf.h" +#include "mocks/net_buf_expects.h" + +#include +#include + +void expect_single_call_net_buf_simple_add(struct net_buf_simple *buf, size_t len) +{ + const char *func_name = "net_buf_simple_add"; + + zassert_equal(net_buf_simple_add_fake.call_count, 1, "'%s()' was called more than once", + func_name); + + zassert_equal(net_buf_simple_add_fake.arg0_val, buf, + "'%s()' was called with incorrect '%s' value", func_name, "buf"); + zassert_equal(net_buf_simple_add_fake.arg1_val, len, + "'%s()' was called with incorrect '%s' value", func_name, "len"); +} + +void expect_not_called_net_buf_simple_add(void) +{ + const char *func_name = "net_buf_simple_add"; + + zassert_equal(net_buf_simple_add_fake.call_count, 0, "'%s()' was called unexpectedly", + func_name); +} diff --git a/tests/bluetooth/host/ecc/mocks/net_buf_expects.h b/tests/bluetooth/host/ecc/mocks/net_buf_expects.h new file mode 100644 index 000000000000..a6b76220f179 --- /dev/null +++ b/tests/bluetooth/host/ecc/mocks/net_buf_expects.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/* + * Validate expected behaviour when net_buf_simple_add() is called + * + * Expected behaviour: + * - net_buf_simple_add() to be called once with correct parameters + */ +void expect_single_call_net_buf_simple_add(struct net_buf_simple *buf, size_t len); + +/* + * Validate expected behaviour when net_buf_simple_add() isn't called + * + * Expected behaviour: + * - net_buf_simple_add() isn't called at all + */ +void expect_not_called_net_buf_simple_add(void); diff --git a/tests/bluetooth/host/ecc/testing_common_defs.h b/tests/bluetooth/host/ecc/testing_common_defs.h new file mode 100644 index 000000000000..5407ea3e2e8c --- /dev/null +++ b/tests/bluetooth/host/ecc/testing_common_defs.h @@ -0,0 +1,5 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ From a774314e692a5d0d9ef2e5422f8f360a8cbb22f8 Mon Sep 17 00:00:00 2001 From: Ahmed Moheb Date: Sun, 23 Oct 2022 13:13:43 +0200 Subject: [PATCH 0601/1906] tests: bluetooth: host: Add UT for bt_pub_key_is_debug() Unit test project for bt_pub_key_is_debug(). This is part of subsys/bluetooth/host/ecc.c unit testing. Signed-off-by: Ahmed Moheb --- .../ecc/bt_pub_key_is_debug/CMakeLists.txt | 16 ++++++ .../host/ecc/bt_pub_key_is_debug/prj.conf | 9 +++ .../host/ecc/bt_pub_key_is_debug/src/main.c | 57 +++++++++++++++++++ .../ecc/bt_pub_key_is_debug/testcase.yaml | 5 ++ 4 files changed, 87 insertions(+) create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_is_debug/CMakeLists.txt create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_is_debug/prj.conf create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_is_debug/src/main.c create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_is_debug/testcase.yaml diff --git a/tests/bluetooth/host/ecc/bt_pub_key_is_debug/CMakeLists.txt b/tests/bluetooth/host/ecc/bt_pub_key_is_debug/CMakeLists.txt new file mode 100644 index 000000000000..47f0b07b4a86 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_is_debug/CMakeLists.txt @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +set(SOURCES + src/main.c +) + +project(bt_pub_key_is_debug) + +find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) + +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/ecc mocks) + +target_link_libraries(testbinary PRIVATE mocks host_mocks) diff --git a/tests/bluetooth/host/ecc/bt_pub_key_is_debug/prj.conf b/tests/bluetooth/host/ecc/bt_pub_key_is_debug/prj.conf new file mode 100644 index 000000000000..542d140aa567 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_is_debug/prj.conf @@ -0,0 +1,9 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_BT=y +CONFIG_BT_CENTRAL=y +CONFIG_BT_MAX_PAIRED=7 +CONFIG_ASSERT=y +CONFIG_ASSERT_LEVEL=2 +CONFIG_ASSERT_VERBOSE=y +CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/ecc/bt_pub_key_is_debug/src/main.c b/tests/bluetooth/host/ecc/bt_pub_key_is_debug/src/main.c new file mode 100644 index 000000000000..6de7b4599700 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_is_debug/src/main.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mocks/ecc_help_utils.h" + +#include +#include + +#include + +DEFINE_FFF_GLOBALS; + +ZTEST_SUITE(bt_pub_key_is_debug, NULL, NULL, NULL, NULL, NULL); + +/* + * Test bt_pub_key_is_debug() returns 'true' if key passed matches the internal debug key + * + * Constraints: + * - The key passed matches the internal debug key + * + * Expected behaviour: + * - bt_pub_key_is_debug() returns 'true' + */ +ZTEST(bt_pub_key_is_debug, test_key_matches_internal_key) +{ + bool result; + uint8_t const *internal_dbg_public_key = bt_ecc_get_internal_debug_public_key(); + uint8_t testing_public_key[BT_PUB_KEY_LEN] = {0}; + + memcpy(testing_public_key, internal_dbg_public_key, BT_PUB_KEY_LEN); + + result = bt_pub_key_is_debug(testing_public_key); + + zassert_true(result, "Unexpected error code '%d' was returned", result); +} + +/* + * Test bt_pub_key_is_debug() returns 'false' if key passed doesn't match the internal debug key + * + * Constraints: + * - The key passed doesn't match the internal debug key + * + * Expected behaviour: + * - bt_pub_key_is_debug() returns 'false' + */ +ZTEST(bt_pub_key_is_debug, test_key_mismatches_internal_key) +{ + bool result; + uint8_t testing_public_key[BT_PUB_KEY_LEN] = {0}; + + result = bt_pub_key_is_debug(testing_public_key); + + zassert_false(result, "Unexpected error code '%d' was returned", result); +} diff --git a/tests/bluetooth/host/ecc/bt_pub_key_is_debug/testcase.yaml b/tests/bluetooth/host/ecc/bt_pub_key_is_debug/testcase.yaml new file mode 100644 index 000000000000..ee6383d329f2 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_is_debug/testcase.yaml @@ -0,0 +1,5 @@ +common: + tags: test_framework bluetooth host +tests: + bluetooth.host.bt_pub_key_is_debug.default: + type: unit From fac21b3616a8b2e7a5eb89ff18dee95c31856881 Mon Sep 17 00:00:00 2001 From: Ahmed Moheb Date: Sun, 23 Oct 2022 13:29:09 +0200 Subject: [PATCH 0602/1906] tests: bluetooth: host: Add UT for bt_pub_key_gen() Unit test project for bt_pub_key_gen(). This is part of subsys/bluetooth/host/ecc.c unit testing. Signed-off-by: Ahmed Moheb --- subsys/bluetooth/host/ecc.c | 1 + tests/bluetooth/host/ecc/CMakeLists.txt | 1 + .../host/ecc/bt_pub_key_gen/CMakeLists.txt | 17 ++ .../host/ecc/bt_pub_key_gen/prj.conf | 9 + .../host/ecc/bt_pub_key_gen/src/main.c | 164 +++++++++++++++ .../src/test_suite_invalid_inputs.c | 193 ++++++++++++++++++ .../host/ecc/bt_pub_key_gen/testcase.yaml | 10 + .../host/ecc/mocks/hci_core_expects.c | 51 +++++ .../host/ecc/mocks/hci_core_expects.h | 39 ++++ 9 files changed, 485 insertions(+) create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_gen/CMakeLists.txt create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_gen/prj.conf create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_gen/src/main.c create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_gen/src/test_suite_invalid_inputs.c create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_gen/testcase.yaml create mode 100644 tests/bluetooth/host/ecc/mocks/hci_core_expects.c create mode 100644 tests/bluetooth/host/ecc/mocks/hci_core_expects.h diff --git a/subsys/bluetooth/host/ecc.c b/subsys/bluetooth/host/ecc.c index 0195ed5bd40e..7f23b2c8392e 100644 --- a/subsys/bluetooth/host/ecc.c +++ b/subsys/bluetooth/host/ecc.c @@ -61,6 +61,7 @@ int bt_pub_key_gen(struct bt_pub_key_cb *new_cb) LOG_WRN("ECC Debug keys HCI command not available"); } else { atomic_set_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + __ASSERT_NO_MSG(new_cb->func != NULL); new_cb->func(debug_public_key); return 0; } diff --git a/tests/bluetooth/host/ecc/CMakeLists.txt b/tests/bluetooth/host/ecc/CMakeLists.txt index 078f46b1afdc..4f3af9f81604 100644 --- a/tests/bluetooth/host/ecc/CMakeLists.txt +++ b/tests/bluetooth/host/ecc/CMakeLists.txt @@ -6,6 +6,7 @@ add_library(mocks STATIC mocks/net_buf.c mocks/net_buf_expects.c mocks/hci_core.c + mocks/hci_core_expects.c mocks/ecc_help_utils.c ${ZEPHYR_BASE}/subsys/bluetooth/host/ecc.c diff --git a/tests/bluetooth/host/ecc/bt_pub_key_gen/CMakeLists.txt b/tests/bluetooth/host/ecc/bt_pub_key_gen/CMakeLists.txt new file mode 100644 index 000000000000..2e0f6c046d5d --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_gen/CMakeLists.txt @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +set(SOURCES + src/main.c + src/test_suite_invalid_inputs.c +) + +project(bt_pub_key_gen) + +find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) + +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/ecc mocks) + +target_link_libraries(testbinary PRIVATE mocks host_mocks) diff --git a/tests/bluetooth/host/ecc/bt_pub_key_gen/prj.conf b/tests/bluetooth/host/ecc/bt_pub_key_gen/prj.conf new file mode 100644 index 000000000000..542d140aa567 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_gen/prj.conf @@ -0,0 +1,9 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_BT=y +CONFIG_BT_CENTRAL=y +CONFIG_BT_MAX_PAIRED=7 +CONFIG_ASSERT=y +CONFIG_ASSERT_LEVEL=2 +CONFIG_ASSERT_VERBOSE=y +CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/ecc/bt_pub_key_gen/src/main.c b/tests/bluetooth/host/ecc/bt_pub_key_gen/src/main.c new file mode 100644 index 000000000000..45d4f5723313 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_gen/src/main.c @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mocks/ecc_help_utils.h" +#include "mocks/hci_core.h" +#include "mocks/hci_core_expects.h" + +#include +#include +#include + +#include +#include + +DEFINE_FFF_GLOBALS; + +static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) +{ + sys_slist_t *pub_key_cb_slist = bt_ecc_get_pub_key_cb_slist(); + + memset(&bt_dev, 0x00, sizeof(struct bt_dev)); + sys_slist_init(pub_key_cb_slist); + + HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); +} + +ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); + +ZTEST_SUITE(bt_pub_key_gen, NULL, NULL, NULL, NULL, NULL); + +static void bt_pub_key_gen_debug_key_callback(const uint8_t key[BT_PUB_KEY_LEN]) +{ + uint8_t const *internal_dbg_key = bt_ecc_get_internal_debug_public_key(); + const char *func_name = "bt_pub_key_gen_null_key_callback"; + + zassert_equal_ptr(key, internal_dbg_key, "'%s()' was called with incorrect '%s' value", + func_name, "key"); +} + +/* + * Test using the internal debug public key + * + * Constraints: + * - "LE Read Local P-256 Public Key" command is supported + * - "LE Generate DH Key" command is supported + * - "ECC Debug Keys" command is supported + * - 'CONFIG_BT_USE_DEBUG_KEYS' is enabled + * + * Expected behaviour: + * - bt_pub_key_gen() returns 0 (success) + */ +ZTEST(bt_pub_key_gen, test_using_internal_debug_public_key) +{ + int result; + bool flags_check; + struct bt_pub_key_cb new_cb = {0}; + + Z_TEST_SKIP_IFNDEF(CONFIG_BT_USE_DEBUG_KEYS); + + new_cb.func = bt_pub_key_gen_debug_key_callback; + + /* Set "LE Read Local P-256 Public Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(1); + /* Set "LE Generate DH Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(2); + /* Set "ECC Debug Keys" command support bit */ + bt_dev.supported_commands[41] |= BIT(2); + + atomic_clear_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + bt_hci_cmd_send_sync_fake.return_val = 0; + + result = bt_pub_key_gen(&new_cb); + + expect_not_called_bt_hci_cmd_send_sync(); + + zassert_ok(result, "Unexpected error code '%d' was returned", result); + + flags_check = atomic_test_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + zassert_true(flags_check, "Flags were not correctly set"); +} + +static void bt_pub_key_gen_callback(const uint8_t key[BT_PUB_KEY_LEN]) +{ + zassert_unreachable("Unexpected call to '%s()' occurred", __func__); +} + +/* + * Test generating a public key request + * + * Constraints: + * - "LE Read Local P-256 Public Key" command is supported + * - "LE Generate DH Key" command is supported + * - bt_hci_cmd_send_sync() succeeds and returns 0 + * + * Expected behaviour: + * - bt_pub_key_gen() returns 0 (success) + */ +ZTEST(bt_pub_key_gen, test_public_key_generation_request_passes) +{ + int result; + bool flags_check; + struct bt_pub_key_cb new_cb = {0}; + + new_cb.func = bt_pub_key_gen_callback; + + /* Set "LE Read Local P-256 Public Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(1); + /* Set "LE Generate DH Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(2); + + atomic_set_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + bt_hci_cmd_send_sync_fake.return_val = 0; + + result = bt_pub_key_gen(&new_cb); + + expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_LE_P256_PUBLIC_KEY); + + zassert_ok(result, "Unexpected error code '%d' was returned", result); + + flags_check = atomic_test_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + zassert_false(flags_check, "Flags were not correctly set"); + + flags_check = atomic_test_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY); + zassert_true(flags_check, "Flags were not correctly set"); +} + +/* + * Test generating a public key request while 'BT_DEV_PUB_KEY_BUSY' flag is set + * + * Constraints: + * - "LE Read Local P-256 Public Key" command is supported + * - "LE Generate DH Key" command is supported + * - bt_hci_cmd_send_sync() isn't called + * + * Expected behaviour: + * - bt_pub_key_gen() returns 0 (success) + */ +ZTEST(bt_pub_key_gen, test_no_public_key_generation_request_duplication) +{ + int result; + bool flags_check; + struct bt_pub_key_cb new_cb = {0}; + + new_cb.func = bt_pub_key_gen_callback; + + /* Set "LE Read Local P-256 Public Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(1); + /* Set "LE Generate DH Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(2); + + atomic_set_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY); + + result = bt_pub_key_gen(&new_cb); + + expect_not_called_bt_hci_cmd_send_sync(); + + zassert_ok(result, "Unexpected error code '%d' was returned", result); + + flags_check = atomic_test_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY); + zassert_true(flags_check, "Flags were not correctly set"); +} diff --git a/tests/bluetooth/host/ecc/bt_pub_key_gen/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/ecc/bt_pub_key_gen/src/test_suite_invalid_inputs.c new file mode 100644 index 000000000000..97bc5b3020e3 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_gen/src/test_suite_invalid_inputs.c @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "host_mocks/assert.h" +#include "mocks/ecc_help_utils.h" +#include "mocks/hci_core.h" +#include "mocks/hci_core_expects.h" + +#include +#include + +#include +#include + +ZTEST_SUITE(bt_pub_key_gen_invalid_cases, NULL, NULL, NULL, NULL, NULL); + +/* + * Test passing NULL reference for the callback function pointer argument + * + * Constraints: + * - NULL reference is used for the callback function pointer argument + * + * Expected behaviour: + * - An assertion is raised and execution stops + */ +ZTEST(bt_pub_key_gen_invalid_cases, test_null_key_reference) +{ + expect_assert(); + bt_pub_key_gen(NULL); +} + +/* + * Test using the internal debug public key, but the callback is set to NULL + * + * Constraints: + * - "LE Read Local P-256 Public Key" command is supported + * - "LE Generate DH Key" command is supported + * - "ECC Debug Keys" command is supported + * - 'CONFIG_BT_USE_DEBUG_KEYS' is enabled + * + * Expected behaviour: + * - An assertion is raised and execution stops + */ +ZTEST(bt_pub_key_gen_invalid_cases, test_using_internal_debug_public_key) +{ + struct bt_pub_key_cb new_cb = {0}; + + Z_TEST_SKIP_IFNDEF(CONFIG_BT_USE_DEBUG_KEYS); + + expect_assert(); + new_cb.func = NULL; + + /* Set "LE Read Local P-256 Public Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(1); + /* Set "LE Generate DH Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(2); + /* Set "ECC Debug Keys" command support bit */ + bt_dev.supported_commands[41] |= BIT(2); + + bt_pub_key_gen(&new_cb); +} + +/* + * Test public key generation isn't supported if "LE Read Local P-256 Public Key" command + * isn't supported + * + * Constraints: + * - "LE Read Local P-256 Public Key" command isn't supported + * - "LE Generate DH Key" command is supported + * + * Expected behaviour: + * - bt_pub_key_gen() returns a negative error code (-ENOTSUP) + */ +ZTEST(bt_pub_key_gen_invalid_cases, test_le_read_local_p_256_pub_key_cmd_not_supported) +{ + int result; + struct bt_pub_key_cb new_cb = {0}; + + /* Clear "LE Read Local P-256 Public Key" command support bit */ + bt_dev.supported_commands[34] &= ~BIT(1); + /* Set "LE Generate DH Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(2); + + result = bt_pub_key_gen(&new_cb); + + zassert_true(result == -ENOTSUP, "Unexpected error code '%d' was returned", result); +} + +/* + * Test public key generation isn't supported if "LE Generate DH Key command isn't supported + * + * Constraints: + * - "LE Read Local P-256 Public Key" command is supported + * - "LE Generate DH Key" command isn't supported + * + * Expected behaviour: + * - bt_pub_key_gen() returns a negative error code (-ENOTSUP) + */ +ZTEST(bt_pub_key_gen_invalid_cases, test_le_generate_dh_key_cmd_not_supported) +{ + int result; + struct bt_pub_key_cb new_cb = {0}; + + /* Set "LE Read Local P-256 Public Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(1); + /* Clear "LE Generate DH Key" command support bit */ + bt_dev.supported_commands[34] &= ~BIT(2); + + result = bt_pub_key_gen(&new_cb); + + zassert_true(result == -ENOTSUP, "Unexpected error code '%d' was returned", result); +} + +/* + * Test public key generation fails if the callback is already registered + * + * Constraints: + * - "LE Read Local P-256 Public Key" command is supported + * - "LE Generate DH Key" command is supported + * - Callback passed is already registered + * + * Expected behaviour: + * - bt_pub_key_gen() returns a negative error code (-EALREADY) + */ +ZTEST(bt_pub_key_gen_invalid_cases, test_callback_already_registered) +{ + int result; + struct bt_pub_key_cb new_cb = {0}; + + /* Set "LE Read Local P-256 Public Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(1); + /* Set "LE Generate DH Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(2); + + bt_pub_key_gen(&new_cb); + result = bt_pub_key_gen(&new_cb); + + zassert_true(result == -EALREADY, "Unexpected error code '%d' was returned", result); +} + +static void bt_pub_key_gen_null_key_callback(const uint8_t key[BT_PUB_KEY_LEN]) +{ + const char *func_name = "bt_pub_key_gen_null_key_callback"; + + zassert_is_null(key, "'%s()' was called with incorrect '%s' value", func_name, "key"); +} + +/* + * Test public key generation fails when reading public key fails + * + * Constraints: + * - "LE Read Local P-256 Public Key" command is supported + * - "LE Generate DH Key" command is supported + * - bt_hci_cmd_send_sync() fails and returns a negative error code + * + * Expected behaviour: + * - bt_pub_key_gen() returns a negative error code + */ +ZTEST(bt_pub_key_gen_invalid_cases, test_reading_le_read_local_p_256_pub_key_fails) +{ + int result; + bool flags_check; + struct bt_pub_key_cb new_cb = {0}; + sys_slist_t *pub_key_cb_slist = bt_ecc_get_pub_key_cb_slist(); + + new_cb.func = bt_pub_key_gen_null_key_callback; + + /* Set "LE Read Local P-256 Public Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(1); + /* Set "LE Generate DH Key" command support bit */ + bt_dev.supported_commands[34] |= BIT(2); + + atomic_set_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + bt_hci_cmd_send_sync_fake.return_val = -1; + + result = bt_pub_key_gen(&new_cb); + + expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_LE_P256_PUBLIC_KEY); + + zassert_true(result < 0, "Unexpected error code '%d' was returned", result); + + flags_check = atomic_test_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + zassert_false(flags_check, "Flags were not correctly set"); + + flags_check = atomic_test_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY); + zassert_false(flags_check, "Flags were not correctly set"); + + zassert_is_null(pub_key_cb_slist->head, "Incorrect value was set to list head"); + zassert_is_null(pub_key_cb_slist->tail, "Incorrect value was set to list tail"); +} diff --git a/tests/bluetooth/host/ecc/bt_pub_key_gen/testcase.yaml b/tests/bluetooth/host/ecc/bt_pub_key_gen/testcase.yaml new file mode 100644 index 000000000000..51b166359a45 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_gen/testcase.yaml @@ -0,0 +1,10 @@ +common: + tags: test_framework bluetooth host +tests: + bluetooth.host.bt_pub_key_gen.default: + type: unit + bluetooth.host.bt_pub_key_gen.bt_use_debug_keys_enabled: + type: unit + extra_configs: + - CONFIG_BT_SMP=y + - CONFIG_BT_USE_DEBUG_KEYS=y diff --git a/tests/bluetooth/host/ecc/mocks/hci_core_expects.c b/tests/bluetooth/host/ecc/mocks/hci_core_expects.c new file mode 100644 index 000000000000..d2d07bab6563 --- /dev/null +++ b/tests/bluetooth/host/ecc/mocks/hci_core_expects.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mocks/hci_core.h" +#include "mocks/hci_core_expects.h" + +#include +#include + +void expect_single_call_bt_hci_cmd_create(uint16_t opcode, uint8_t param_len) +{ + const char *func_name = "bt_hci_cmd_create"; + + zassert_equal(bt_hci_cmd_create_fake.call_count, 1, "'%s()' was called more than once", + func_name); + + zassert_equal(bt_hci_cmd_create_fake.arg0_val, opcode, + "'%s()' was called with incorrect '%s' value", func_name, "opcode"); + zassert_equal(bt_hci_cmd_create_fake.arg1_val, param_len, + "'%s()' was called with incorrect '%s' value", func_name, "param_len"); +} + +void expect_not_called_bt_hci_cmd_create(void) +{ + const char *func_name = "bt_hci_cmd_create"; + + zassert_equal(bt_hci_cmd_create_fake.call_count, 0, "'%s()' was called unexpectedly", + func_name); +} + +void expect_single_call_bt_hci_cmd_send_sync(uint16_t opcode) +{ + const char *func_name = "bt_hci_cmd_send_sync"; + + zassert_equal(bt_hci_cmd_send_sync_fake.call_count, 1, "'%s()' was called more than once", + func_name); + + zassert_equal(bt_hci_cmd_send_sync_fake.arg0_val, opcode, + "'%s()' was called with incorrect '%s' value", func_name, "opcode"); +} + +void expect_not_called_bt_hci_cmd_send_sync(void) +{ + const char *func_name = "bt_hci_cmd_send_sync"; + + zassert_equal(bt_hci_cmd_send_sync_fake.call_count, 0, "'%s()' was called unexpectedly", + func_name); +} diff --git a/tests/bluetooth/host/ecc/mocks/hci_core_expects.h b/tests/bluetooth/host/ecc/mocks/hci_core_expects.h new file mode 100644 index 000000000000..08dc8c7af04c --- /dev/null +++ b/tests/bluetooth/host/ecc/mocks/hci_core_expects.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/* + * Validate expected behaviour when bt_hci_cmd_create() is called + * + * Expected behaviour: + * - bt_hci_cmd_create() to be called once with correct parameters + */ +void expect_single_call_bt_hci_cmd_create(uint16_t opcode, uint8_t param_len); + +/* + * Validate expected behaviour when bt_hci_cmd_create() isn't called + * + * Expected behaviour: + * - bt_hci_cmd_create() isn't called at all + */ +void expect_not_called_bt_hci_cmd_create(void); + +/* + * Validate expected behaviour when bt_hci_cmd_send_sync() is called + * + * Expected behaviour: + * - bt_hci_cmd_send_sync() to be called once with correct parameters + */ +void expect_single_call_bt_hci_cmd_send_sync(uint16_t opcode); + +/* + * Validate expected behaviour when bt_hci_cmd_send_sync() isn't called + * + * Expected behaviour: + * - bt_hci_cmd_send_sync() isn't called at all + */ +void expect_not_called_bt_hci_cmd_send_sync(void); From aebd5d84a0de26e50df0b0a2da61d1d4406e2e70 Mon Sep 17 00:00:00 2001 From: Ahmed Moheb Date: Tue, 25 Oct 2022 09:48:18 +0200 Subject: [PATCH 0603/1906] tests: bluetooth: host: Add UT for bt_pub_key_get() Unit test project for bt_pub_key_get(). This is part of subsys/bluetooth/host/ecc.c unit testing. Signed-off-by: Ahmed Moheb --- .../host/ecc/bt_pub_key_get/CMakeLists.txt | 17 ++++ .../host/ecc/bt_pub_key_get/prj.conf | 9 +++ .../host/ecc/bt_pub_key_get/src/main.c | 77 +++++++++++++++++++ .../src/test_suite_invalid_inputs.c | 64 +++++++++++++++ .../host/ecc/bt_pub_key_get/testcase.yaml | 10 +++ 5 files changed, 177 insertions(+) create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_get/CMakeLists.txt create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_get/prj.conf create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_get/src/main.c create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_get/src/test_suite_invalid_inputs.c create mode 100644 tests/bluetooth/host/ecc/bt_pub_key_get/testcase.yaml diff --git a/tests/bluetooth/host/ecc/bt_pub_key_get/CMakeLists.txt b/tests/bluetooth/host/ecc/bt_pub_key_get/CMakeLists.txt new file mode 100644 index 000000000000..88de552aca43 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_get/CMakeLists.txt @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +set(SOURCES + src/main.c + src/test_suite_invalid_inputs.c +) + +project(bt_pub_key_get) + +find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) + +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/ecc mocks) + +target_link_libraries(testbinary PRIVATE mocks host_mocks) diff --git a/tests/bluetooth/host/ecc/bt_pub_key_get/prj.conf b/tests/bluetooth/host/ecc/bt_pub_key_get/prj.conf new file mode 100644 index 000000000000..542d140aa567 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_get/prj.conf @@ -0,0 +1,9 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_BT=y +CONFIG_BT_CENTRAL=y +CONFIG_BT_MAX_PAIRED=7 +CONFIG_ASSERT=y +CONFIG_ASSERT_LEVEL=2 +CONFIG_ASSERT_VERBOSE=y +CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/ecc/bt_pub_key_get/src/main.c b/tests/bluetooth/host/ecc/bt_pub_key_get/src/main.c new file mode 100644 index 000000000000..9ba0d051ef8d --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_get/src/main.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mocks/ecc_help_utils.h" + +#include +#include +#include + +#include +#include + +DEFINE_FFF_GLOBALS; + +static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) +{ + memset(&bt_dev, 0x00, sizeof(struct bt_dev)); +} + +ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); + +ZTEST_SUITE(bt_pub_key_get, NULL, NULL, NULL, NULL, NULL); + +/* + * Test getting currently used public key if 'BT_DEV_HAS_PUB_KEY' is set and + * 'CONFIG_BT_USE_DEBUG_KEYS' isn't enabled + * + * Constraints: + * - 'BT_DEV_HAS_PUB_KEY' flag is set + * - 'CONFIG_BT_USE_DEBUG_KEYS' isn't enabled + * + * Expected behaviour: + * - A valid reference value is returned + */ +ZTEST(bt_pub_key_get, test_bt_dev_has_pub_key_set) +{ + const uint8_t *pub_key; + + Z_TEST_SKIP_IFDEF(CONFIG_BT_USE_DEBUG_KEYS); + + atomic_set_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + + pub_key = bt_pub_key_get(); + + zassert_equal(pub_key, bt_ecc_get_public_key(), "Incorrect reference was returned"); +} + +/* + * Test getting currently used debug public key if 'CONFIG_BT_USE_DEBUG_KEYS' is enabled and + * "ECC Debug Keys" command is supported + * + * Constraints: + * - 'CONFIG_BT_USE_DEBUG_KEYS' is enabled + * - "ECC Debug Keys" command is supported + * - 'BT_DEV_HAS_PUB_KEY' flag is set (just for testing and it shouldn't affect the result) + * + * Expected behaviour: + * - A valid reference value is returned + */ +ZTEST(bt_pub_key_get, test_get_debug_pub_key1) +{ + const uint8_t *pub_key; + + Z_TEST_SKIP_IFNDEF(CONFIG_BT_USE_DEBUG_KEYS); + + /* Set "ECC Debug Keys" command support bit */ + bt_dev.supported_commands[41] |= BIT(2); + atomic_set_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + + pub_key = bt_pub_key_get(); + + zassert_equal(pub_key, bt_ecc_get_internal_debug_public_key(), + "Incorrect reference was returned"); +} diff --git a/tests/bluetooth/host/ecc/bt_pub_key_get/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/ecc/bt_pub_key_get/src/test_suite_invalid_inputs.c new file mode 100644 index 000000000000..5e53460b6c2c --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_get/src/test_suite_invalid_inputs.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include + +ZTEST_SUITE(bt_pub_key_get_invalid_cases, NULL, NULL, NULL, NULL, NULL); + +/* + * Test getting currently used public key if 'BT_DEV_HAS_PUB_KEY' isn't set and + * 'CONFIG_BT_USE_DEBUG_KEYS' isn't enabled + * + * Constraints: + * - 'BT_DEV_HAS_PUB_KEY' flag isn't set + * - 'CONFIG_BT_USE_DEBUG_KEYS' isn't enabled + * + * Expected behaviour: + * - NULL value is returned + */ +ZTEST(bt_pub_key_get_invalid_cases, test_bt_dev_has_pub_key_not_set) +{ + const uint8_t *pub_key; + + Z_TEST_SKIP_IFDEF(CONFIG_BT_USE_DEBUG_KEYS); + + atomic_clear_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + + pub_key = bt_pub_key_get(); + + zassert_is_null(pub_key, "Incorrect reference was returned"); +} + +/* + * Test getting currently used debug public key if 'CONFIG_BT_USE_DEBUG_KEYS' is enabled, but + * "ECC Debug Keys" command isn't supported + * + * Constraints: + * - 'CONFIG_BT_USE_DEBUG_KEYS' is enabled + * - "ECC Debug Keys" command isn't supported + * - 'BT_DEV_HAS_PUB_KEY' flag isn't set + * + * Expected behaviour: + * - NULL value is returned + */ +ZTEST(bt_pub_key_get_invalid_cases, test_get_debug_pub_key) +{ + const uint8_t *pub_key; + + Z_TEST_SKIP_IFNDEF(CONFIG_BT_USE_DEBUG_KEYS); + + /* Clear "ECC Debug Keys" command support bit */ + bt_dev.supported_commands[41] &= ~BIT(2); + atomic_clear_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + + pub_key = bt_pub_key_get(); + + zassert_is_null(pub_key, "Incorrect reference was returned"); +} diff --git a/tests/bluetooth/host/ecc/bt_pub_key_get/testcase.yaml b/tests/bluetooth/host/ecc/bt_pub_key_get/testcase.yaml new file mode 100644 index 000000000000..d198c40ddee5 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_pub_key_get/testcase.yaml @@ -0,0 +1,10 @@ +common: + tags: test_framework bluetooth host +tests: + bluetooth.host.bt_pub_key_get.default: + type: unit + bluetooth.host.bt_pub_key_get.bt_use_debug_keys_enabled: + type: unit + extra_configs: + - CONFIG_BT_SMP=y + - CONFIG_BT_USE_DEBUG_KEYS=y From 48000cd5a4dbbf2fca4c0215e310bc04f1378f72 Mon Sep 17 00:00:00 2001 From: Ahmed Moheb Date: Tue, 25 Oct 2022 11:22:33 +0200 Subject: [PATCH 0604/1906] tests: bluetooth: host: Add UT for bt_dh_key_gen() Unit test project for bt_dh_key_gen(). This is part of subsys/bluetooth/host/ecc.c unit testing. Signed-off-by: Ahmed Moheb --- .../host/ecc/bt_dh_key_gen/CMakeLists.txt | 17 ++ .../bluetooth/host/ecc/bt_dh_key_gen/prj.conf | 9 + .../host/ecc/bt_dh_key_gen/src/main.c | 116 ++++++++++ .../src/test_suite_invalid_inputs.c | 208 ++++++++++++++++++ .../host/ecc/bt_dh_key_gen/testcase.yaml | 10 + 5 files changed, 360 insertions(+) create mode 100644 tests/bluetooth/host/ecc/bt_dh_key_gen/CMakeLists.txt create mode 100644 tests/bluetooth/host/ecc/bt_dh_key_gen/prj.conf create mode 100644 tests/bluetooth/host/ecc/bt_dh_key_gen/src/main.c create mode 100644 tests/bluetooth/host/ecc/bt_dh_key_gen/src/test_suite_invalid_inputs.c create mode 100644 tests/bluetooth/host/ecc/bt_dh_key_gen/testcase.yaml diff --git a/tests/bluetooth/host/ecc/bt_dh_key_gen/CMakeLists.txt b/tests/bluetooth/host/ecc/bt_dh_key_gen/CMakeLists.txt new file mode 100644 index 000000000000..aac575f6f930 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_dh_key_gen/CMakeLists.txt @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +set(SOURCES + src/main.c + src/test_suite_invalid_inputs.c +) + +project(bt_dh_key_gen) + +find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) + +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host/ecc mocks) + +target_link_libraries(testbinary PRIVATE mocks host_mocks) diff --git a/tests/bluetooth/host/ecc/bt_dh_key_gen/prj.conf b/tests/bluetooth/host/ecc/bt_dh_key_gen/prj.conf new file mode 100644 index 000000000000..542d140aa567 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_dh_key_gen/prj.conf @@ -0,0 +1,9 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_BT=y +CONFIG_BT_CENTRAL=y +CONFIG_BT_MAX_PAIRED=7 +CONFIG_ASSERT=y +CONFIG_ASSERT_LEVEL=2 +CONFIG_ASSERT_VERBOSE=y +CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/host/ecc/bt_dh_key_gen/src/main.c b/tests/bluetooth/host/ecc/bt_dh_key_gen/src/main.c new file mode 100644 index 000000000000..20638ad580db --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_dh_key_gen/src/main.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mocks/ecc_help_utils.h" +#include "mocks/hci_core.h" +#include "mocks/hci_core_expects.h" +#include "mocks/net_buf.h" +#include "mocks/net_buf_expects.h" + +#include +#include +#include + +#include +#include + +DEFINE_FFF_GLOBALS; + +static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture) +{ + bt_dh_key_cb_t *dh_key_cb = bt_ecc_get_dh_key_cb(); + + *dh_key_cb = NULL; + memset(&bt_dev, 0x00, sizeof(struct bt_dev)); + + HCI_CORE_FFF_FAKES_LIST(RESET_FAKE); +} + +ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); + +ZTEST_SUITE(bt_dh_key_gen, NULL, NULL, NULL, NULL, NULL); + +static void bt_dh_key_unreachable_cb(const uint8_t key[BT_DH_KEY_LEN]) +{ + zassert_unreachable("Unexpected call to '%s()' occurred", __func__); +} + +/* + * Test DH key generation succeeds + * + * Constraints: + * - 'BT_DEV_HAS_PUB_KEY' flag is set + * - 'BT_DEV_PUB_KEY_BUSY' flag isn't set + * - 'CONFIG_BT_USE_DEBUG_KEYS' isn't enabled + * + * Expected behaviour: + * - bt_dh_key_gen() returns 0 (success) + */ +ZTEST(bt_dh_key_gen, test_generate_dh_key_passes) +{ + int result; + struct net_buf net_buff = {0}; + struct bt_hci_cp_le_generate_dhkey cp = {0}; + const uint8_t remote_pk[BT_PUB_KEY_LEN] = {0}; + + Z_TEST_SKIP_IFDEF(CONFIG_BT_USE_DEBUG_KEYS); + + atomic_set_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + atomic_clear_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY); + + /* This makes hci_generate_dhkey_v1() succeeds and returns 0 */ + net_buf_simple_add_fake.return_val = &cp; + bt_hci_cmd_create_fake.return_val = &net_buff; + bt_hci_cmd_send_sync_fake.return_val = 0; + + result = bt_dh_key_gen(remote_pk, bt_dh_key_unreachable_cb); + + expect_single_call_net_buf_simple_add(&net_buff.b, sizeof(cp)); + expect_single_call_bt_hci_cmd_create(BT_HCI_OP_LE_GENERATE_DHKEY, sizeof(cp)); + expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_LE_GENERATE_DHKEY); + + zassert_ok(result, "Unexpected error code '%d' was returned", result); +} + +/* + * Test DH key generation succeeds with 'CONFIG_BT_USE_DEBUG_KEYS' enabled + * + * Constraints: + * - 'BT_DEV_HAS_PUB_KEY' flag is set + * - 'BT_DEV_PUB_KEY_BUSY' flag isn't set + * - 'CONFIG_BT_USE_DEBUG_KEYS' is enabled + * + * Expected behaviour: + * - bt_dh_key_gen() returns 0 (success) + */ +ZTEST(bt_dh_key_gen, test_generate_dh_key_passes_with_debug_keys_enabled) +{ + int result; + struct net_buf net_buff = {0}; + struct bt_hci_cp_le_generate_dhkey_v2 cp = {0}; + const uint8_t remote_pk[BT_PUB_KEY_LEN] = {0}; + + Z_TEST_SKIP_IFNDEF(CONFIG_BT_USE_DEBUG_KEYS); + + atomic_set_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + atomic_clear_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY); + + /* Set "ECC Debug Keys" command support bit */ + bt_dev.supported_commands[41] |= BIT(2); + + /* This makes hci_generate_dhkey_v2() succeeds and returns 0 */ + net_buf_simple_add_fake.return_val = &cp; + bt_hci_cmd_create_fake.return_val = &net_buff; + bt_hci_cmd_send_sync_fake.return_val = 0; + + result = bt_dh_key_gen(remote_pk, bt_dh_key_unreachable_cb); + + expect_single_call_net_buf_simple_add(&net_buff.b, sizeof(cp)); + expect_single_call_bt_hci_cmd_create(BT_HCI_OP_LE_GENERATE_DHKEY_V2, sizeof(cp)); + expect_single_call_bt_hci_cmd_send_sync(BT_HCI_OP_LE_GENERATE_DHKEY_V2); + + zassert_ok(result, "Unexpected error code '%d' was returned", result); +} diff --git a/tests/bluetooth/host/ecc/bt_dh_key_gen/src/test_suite_invalid_inputs.c b/tests/bluetooth/host/ecc/bt_dh_key_gen/src/test_suite_invalid_inputs.c new file mode 100644 index 000000000000..b8da191fe3f9 --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_dh_key_gen/src/test_suite_invalid_inputs.c @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "host_mocks/assert.h" +#include "mocks/ecc_help_utils.h" +#include "mocks/hci_core.h" +#include "mocks/hci_core_expects.h" +#include "mocks/net_buf.h" +#include "mocks/net_buf_expects.h" + +#include +#include + +#include +#include + +ZTEST_SUITE(bt_dh_key_gen_invalid_cases, NULL, NULL, NULL, NULL, NULL); + +static void bt_dh_key_unreachable_cb(const uint8_t key[BT_DH_KEY_LEN]) +{ + zassert_unreachable("Unexpected call to '%s()' occurred", __func__); +} + +/* + * Test passing NULL reference for the 'remote_pk' argument + * + * Constraints: + * - NULL reference is used for the 'remote_pk' argument + * + * Expected behaviour: + * - An assertion is raised and execution stops + */ +ZTEST(bt_dh_key_gen_invalid_cases, test_null_remote_pk_reference) +{ + expect_assert(); + bt_dh_key_gen(NULL, bt_dh_key_unreachable_cb); +} + +/* + * Test passing NULL reference for the 'dh_key_cb' argument + * + * Constraints: + * - NULL reference is used for the 'dh_key_cb' argument + * + * Expected behaviour: + * - An assertion is raised and execution stops + */ +ZTEST(bt_dh_key_gen_invalid_cases, test_null_dh_key_cb_reference) +{ + const uint8_t remote_pk[BT_PUB_KEY_LEN] = {0}; + + expect_assert(); + bt_dh_key_gen(remote_pk, NULL); +} + +/* + * Test DH key generation fails if the callback is already registered + * + * Constraints: + * - 'BT_DEV_HAS_PUB_KEY' flag is set + * - 'BT_DEV_PUB_KEY_BUSY' flag isn't set + * + * Expected behaviour: + * - bt_dh_key_gen() returns a negative error code (-EALREADY) + */ +ZTEST(bt_dh_key_gen_invalid_cases, test_callback_already_registered) +{ + int result; + struct net_buf net_buff = {0}; + struct bt_hci_cp_le_generate_dhkey cp = {0}; + const uint8_t remote_pk[BT_PUB_KEY_LEN] = {0}; + + atomic_set_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + atomic_clear_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY); + + /* This makes hci_generate_dhkey_v1() succeeds and returns 0 */ + net_buf_simple_add_fake.return_val = &cp; + bt_hci_cmd_create_fake.return_val = &net_buff; + bt_hci_cmd_send_sync_fake.return_val = 0; + + /* Pass first call that will set dh_key_cb = cb*/ + bt_dh_key_gen(remote_pk, bt_dh_key_unreachable_cb); + result = bt_dh_key_gen(remote_pk, bt_dh_key_unreachable_cb); + + zassert_true(result == -EALREADY, "Unexpected error code '%d' was returned", result); +} + +static void bt_dh_key_unreachable_2nd_trial_cb(const uint8_t key[BT_DH_KEY_LEN]) +{ + zassert_unreachable("Unexpected call to '%s()' occurred", __func__); +} + +/* + * Test DH key generation fails if a current key generation cycle hasn't been finished yet and + * 'dh_key_cb' isn't NULL. + * + * Constraints: + * - 'BT_DEV_HAS_PUB_KEY' flag is set + * - 'BT_DEV_PUB_KEY_BUSY' flag isn't set + * + * Expected behaviour: + * - bt_dh_key_gen() returns a negative error code (-EBUSY) + */ +ZTEST(bt_dh_key_gen_invalid_cases, test_generate_key_parallel_with_running_one) +{ + int result; + struct net_buf net_buff = {0}; + struct bt_hci_cp_le_generate_dhkey cp = {0}; + const uint8_t remote_pk[BT_PUB_KEY_LEN] = {0}; + + atomic_set_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + atomic_clear_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY); + + /* This makes hci_generate_dhkey_v1() succeeds and returns 0 */ + net_buf_simple_add_fake.return_val = &cp; + bt_hci_cmd_create_fake.return_val = &net_buff; + bt_hci_cmd_send_sync_fake.return_val = 0; + + /* Pass first call that will set dh_key_cb = cb*/ + bt_dh_key_gen(remote_pk, bt_dh_key_unreachable_cb); + result = bt_dh_key_gen(remote_pk, bt_dh_key_unreachable_2nd_trial_cb); + + zassert_true(result == -EBUSY, "Unexpected error code '%d' was returned", result); +} + +/* + * Test DH key generation fails if a current key generation cycle hasn't been finished yet and + * 'dh_key_cb' isn't NULL. + * + * Constraints: + * - 'BT_DEV_PUB_KEY_BUSY' flag is set + * + * Expected behaviour: + * - bt_dh_key_gen() returns a negative error code (-EBUSY) + */ +ZTEST(bt_dh_key_gen_invalid_cases, test_bt_dev_pub_key_busy_set) +{ + int result; + const uint8_t remote_pk[BT_PUB_KEY_LEN] = {0}; + + atomic_set_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY); + + result = bt_dh_key_gen(remote_pk, bt_dh_key_unreachable_cb); + + zassert_true(result == -EBUSY, "Unexpected error code '%d' was returned", result); +} + +/* + * Test DH key generation fails if the 'BT_DEV_HAS_PUB_KEY' flag isn't set + * + * Constraints: + * - 'BT_DEV_HAS_PUB_KEY' flag isn't set + * - 'BT_DEV_PUB_KEY_BUSY' flag isn't set + * + * Expected behaviour: + * - bt_dh_key_gen() returns a negative error code (-EADDRNOTAVAIL) + */ +ZTEST(bt_dh_key_gen_invalid_cases, test_device_has_no_pub_key) +{ + int result; + const uint8_t remote_pk[BT_PUB_KEY_LEN] = {0}; + + atomic_clear_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + atomic_clear_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY); + + result = bt_dh_key_gen(remote_pk, bt_dh_key_unreachable_cb); + + zassert_true(result == -EADDRNOTAVAIL, "Unexpected error code '%d' was returned", result); +} + +/* + * Test DH key generation fails when hci_generate_dhkey_v1/2() fails + * + * Constraints: + * - 'BT_DEV_HAS_PUB_KEY' flag is set + * - 'BT_DEV_PUB_KEY_BUSY' flag isn't set + * - 'hci_generate_dhkey_v1/2()' fails and returns a negative error code (-ENOBUFS) + * + * Expected behaviour: + * - bt_dh_key_gen() returns a negative error code (-ENOBUFS) + */ +ZTEST(bt_dh_key_gen_invalid_cases, test_hci_generate_dhkey_vx_fails) +{ + int result; + bt_dh_key_cb_t *dh_key_cb; + const uint8_t remote_pk[BT_PUB_KEY_LEN] = {0}; + + atomic_set_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + atomic_clear_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY); + + if (IS_ENABLED(CONFIG_BT_USE_DEBUG_KEYS)) { + /* Set "ECC Debug Keys" command support bit */ + bt_dev.supported_commands[41] |= BIT(2); + } + + /* This makes hci_generate_dhkey_vx() fails and returns (-ENOBUFS) */ + bt_hci_cmd_create_fake.return_val = NULL; + + result = bt_dh_key_gen(remote_pk, bt_dh_key_unreachable_cb); + + zassert_true(result == -ENOBUFS, "Unexpected error code '%d' was returned", result); + + dh_key_cb = bt_ecc_get_dh_key_cb(); + zassert_is_null(*dh_key_cb, "Unexpected callback reference was set"); +} diff --git a/tests/bluetooth/host/ecc/bt_dh_key_gen/testcase.yaml b/tests/bluetooth/host/ecc/bt_dh_key_gen/testcase.yaml new file mode 100644 index 000000000000..bea176ee50cd --- /dev/null +++ b/tests/bluetooth/host/ecc/bt_dh_key_gen/testcase.yaml @@ -0,0 +1,10 @@ +common: + tags: test_framework bluetooth host +tests: + bluetooth.host.bt_dh_key_gen.default: + type: unit + bluetooth.host.bt_dh_key_gen.bt_use_debug_keys_enabled: + type: unit + extra_configs: + - CONFIG_BT_SMP=y + - CONFIG_BT_USE_DEBUG_KEYS=y From 84665de122cffd641bd42322150fbb5dc89db91c Mon Sep 17 00:00:00 2001 From: Yonatan Schachter Date: Sat, 26 Feb 2022 19:25:03 +0200 Subject: [PATCH 0605/1906] soc: rpi_pico: Added panic handler Some pico-sdk drivers call a panic function, originally implemented as part of the Pico's C runtime. This commit adds a Zephyr compatible implementation of panic, so that those drivers could be compiled with Zephyr. Signed-off-by: Yonatan Schachter --- soc/arm/rpi_pico/rp2/soc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/soc/arm/rpi_pico/rp2/soc.c b/soc/arm/rpi_pico/rp2/soc.c index 3df9b983723e..69681016b384 100644 --- a/soc/arm/rpi_pico/rp2/soc.c +++ b/soc/arm/rpi_pico/rp2/soc.c @@ -13,9 +13,12 @@ * for the Raspberry Pi RP2040 family processor. */ +#include + #include #include #include +#include #include #include @@ -61,4 +64,18 @@ static int rp2040_init(const struct device *arg) return 0; } +/* + * Some pico-sdk drivers call panic on fatal error. + * This alternative implementation of panic handles the panic + * through Zephyr. + */ +void __attribute__((noreturn)) panic(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + vprintf(fmt, args); + k_fatal_halt(K_ERR_CPU_EXCEPTION); +} + SYS_INIT(rp2040_init, PRE_KERNEL_1, 0); From 15535edbfe3016a7bda06f63df4c5894f2ed273d Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Wed, 18 Jan 2023 08:57:14 +0900 Subject: [PATCH 0606/1906] modules: hal_rpi_pico: Enable DMA driver Enable DMA driver. Add the path of the DMA driver header into include paths. `hardware_claim` is depends by DMA driver, also enable it. Signed-off-by: TOKITA Hiroshi --- modules/hal_rpi_pico/CMakeLists.txt | 10 ++++++++++ modules/hal_rpi_pico/Kconfig | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/modules/hal_rpi_pico/CMakeLists.txt b/modules/hal_rpi_pico/CMakeLists.txt index 880af90a594b..9db2b66e4d94 100644 --- a/modules/hal_rpi_pico/CMakeLists.txt +++ b/modules/hal_rpi_pico/CMakeLists.txt @@ -100,6 +100,16 @@ if(CONFIG_HAS_RPI_PICO) zephyr_include_directories_ifdef(CONFIG_PICOSDK_USE_ADC ${rp2_common_dir}/hardware_adc/include) + zephyr_library_sources_ifdef(CONFIG_PICOSDK_USE_DMA + ${rp2_common_dir}/hardware_dma/dma.c) + zephyr_include_directories_ifdef(CONFIG_PICOSDK_USE_DMA + ${rp2_common_dir}/hardware_dma/include) + + zephyr_library_sources_ifdef(CONFIG_PICOSDK_USE_CLAIM + ${rp2_common_dir}/hardware_claim/claim.c) + zephyr_include_directories_ifdef(CONFIG_PICOSDK_USE_CLAIM + ${rp2_common_dir}/hardware_claim/include) + # Some flash driver functions must be executed from the RAM. # Originally pico-sdk places them in the RW data section, so this # implementation does the same. diff --git a/modules/hal_rpi_pico/Kconfig b/modules/hal_rpi_pico/Kconfig index 9bb327b8735b..ecb4c4993c6a 100644 --- a/modules/hal_rpi_pico/Kconfig +++ b/modules/hal_rpi_pico/Kconfig @@ -28,3 +28,13 @@ config PICOSDK_USE_ADC bool help Use the ADC driver from pico-sdk + +config PICOSDK_USE_DMA + bool + help + Use the DMA driver from pico-sdk + +config PICOSDK_USE_CLAIM + bool + help + Use the "claim" driver from pico-sdk From 08606eac442de16044325f42991f66d8cf4b8f8d Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Wed, 18 Jan 2023 08:13:54 +0900 Subject: [PATCH 0607/1906] drivers: dma: rpi_pico: add support for RaspberryPi Pico DMA Adding RaspberryPi Pico DMA driver. Signed-off-by: TOKITA Hiroshi --- boards/arm/rpi_pico/rpi_pico.yaml | 1 + drivers/dma/CMakeLists.txt | 1 + drivers/dma/Kconfig | 2 + drivers/dma/Kconfig.rpi_pico | 12 + drivers/dma/dma_rpi_pico.c | 384 ++++++++++++++++++ dts/arm/rpi_pico/rp2040.dtsi | 13 + dts/bindings/dma/raspberrypi,pico-dma.yaml | 42 ++ include/zephyr/dt-bindings/dma/rpi_pico_dma.h | 64 +++ 8 files changed, 519 insertions(+) create mode 100644 drivers/dma/Kconfig.rpi_pico create mode 100644 drivers/dma/dma_rpi_pico.c create mode 100644 dts/bindings/dma/raspberrypi,pico-dma.yaml create mode 100644 include/zephyr/dt-bindings/dma/rpi_pico_dma.h diff --git a/boards/arm/rpi_pico/rpi_pico.yaml b/boards/arm/rpi_pico/rpi_pico.yaml index 96aa12649e64..d3baa1f1822f 100644 --- a/boards/arm/rpi_pico/rpi_pico.yaml +++ b/boards/arm/rpi_pico/rpi_pico.yaml @@ -18,3 +18,4 @@ supported: - watchdog - pwm - flash + - dma diff --git a/drivers/dma/CMakeLists.txt b/drivers/dma/CMakeLists.txt index d5f76cbccabf..d73d0a87e08c 100644 --- a/drivers/dma/CMakeLists.txt +++ b/drivers/dma/CMakeLists.txt @@ -27,3 +27,4 @@ zephyr_library_sources_ifdef(CONFIG_DMA_GD32 dma_gd32.c) zephyr_library_sources_ifdef(CONFIG_DMA_ESP32 dma_esp32_gdma.c) zephyr_library_sources_ifdef(CONFIG_DMA_MCHP_XEC dma_mchp_xec.c) zephyr_library_sources_ifdef(CONFIG_DMA_XMC4XXX dma_xmc4xxx.c) +zephyr_library_sources_ifdef(CONFIG_DMA_RPI_PICO dma_rpi_pico.c) diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig index 4e20a43224e2..76daa4cabee4 100644 --- a/drivers/dma/Kconfig +++ b/drivers/dma/Kconfig @@ -56,4 +56,6 @@ source "drivers/dma/Kconfig.xec" source "drivers/dma/Kconfig.xmc4xxx" +source "drivers/dma/Kconfig.rpi_pico" + endif # DMA diff --git a/drivers/dma/Kconfig.rpi_pico b/drivers/dma/Kconfig.rpi_pico new file mode 100644 index 000000000000..434ac9fdf14c --- /dev/null +++ b/drivers/dma/Kconfig.rpi_pico @@ -0,0 +1,12 @@ +# Copyright (c) 2023 Tokita, Hiroshi +# SPDX-License-Identifier: Apache-2.0 + +config DMA_RPI_PICO + bool "Raspberry Pi Pico DMA driver" + default y + depends on DT_HAS_RASPBERRYPI_PICO_DMA_ENABLED + select PICOSDK_USE_DMA + select PICOSDK_USE_CLAIM + depends on RESET + help + DMA driver for RaspberryPi Pico. diff --git a/drivers/dma/dma_rpi_pico.c b/drivers/dma/dma_rpi_pico.c new file mode 100644 index 000000000000..57c23ced657f --- /dev/null +++ b/drivers/dma/dma_rpi_pico.c @@ -0,0 +1,384 @@ +/* + * Copyright (c) 2023 TOKITA Hiroshi + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define DT_DRV_COMPAT raspberrypi_pico_dma + +#define DMA_INT_ERROR_FLAGS \ + (DMA_CH0_CTRL_TRIG_AHB_ERROR_BITS | DMA_CH0_CTRL_TRIG_READ_ERROR_BITS | \ + DMA_CH0_CTRL_TRIG_WRITE_ERROR_BITS) + +LOG_MODULE_REGISTER(dma_rpi_pico, CONFIG_DMA_LOG_LEVEL); + +struct dma_rpi_pico_config { + uint32_t reg; + uint32_t channels; + struct reset_dt_spec reset; + void (*irq_configure)(void); + uint32_t *irq0_channels; + size_t irq0_channels_size; +}; + +struct dma_rpi_pico_channel { + dma_callback_t callback; + void *user_data; + uint32_t direction; + dma_channel_config config; + void *source_address; + void *dest_address; + size_t block_size; +}; + +struct dma_rpi_pico_data { + struct dma_context ctx; + struct dma_rpi_pico_channel *channels; +}; + +/* + * Register access functions + */ + +static inline void rpi_pico_dma_channel_clear_error_flags(const struct device *dev, + uint32_t channel) +{ + const struct dma_rpi_pico_config *cfg = dev->config; + + ((dma_hw_t *)cfg->reg)->ch[channel].al1_ctrl &= ~DMA_INT_ERROR_FLAGS; +} + +static inline uint32_t rpi_pico_dma_channel_get_error_flags(const struct device *dev, + uint32_t channel) +{ + const struct dma_rpi_pico_config *cfg = dev->config; + + return ((dma_hw_t *)cfg->reg)->ch[channel].al1_ctrl & DMA_INT_ERROR_FLAGS; +} + +static inline void rpi_pico_dma_channel_abort(const struct device *dev, uint32_t channel) +{ + const struct dma_rpi_pico_config *cfg = dev->config; + + ((dma_hw_t *)cfg->reg)->abort = BIT(channel); +} + +/* + * Utility functions + */ + +static inline uint32_t dma_rpi_pico_transfer_size(uint32_t width) +{ + switch (width) { + case 4: + return DMA_SIZE_32; + case 2: + return DMA_SIZE_16; + default: + return DMA_SIZE_8; + } +} + +static inline uint32_t dma_rpi_pico_channel_irq(const struct device *dev, uint32_t channel) +{ + const struct dma_rpi_pico_config *cfg = dev->config; + + for (size_t i = 0; i < cfg->irq0_channels_size; i++) { + if (cfg->irq0_channels[i] == channel) { + return 0; + } + } + + return 1; +} + +/* + * API functions + */ + +static int dma_rpi_pico_config(const struct device *dev, uint32_t channel, + struct dma_config *dma_cfg) +{ + const struct dma_rpi_pico_config *cfg = dev->config; + struct dma_rpi_pico_data *data = dev->data; + + if (channel >= cfg->channels) { + LOG_ERR("channel must be < %" PRIu32 " (%" PRIu32 ")", cfg->channels, channel); + return -EINVAL; + } + + if (dma_cfg->block_count != 1) { + LOG_ERR("chained block transfer not supported."); + return -ENOTSUP; + } + + if (dma_cfg->channel_priority > 3) { + LOG_ERR("channel_priority must be < 4 (%" PRIu32 ")", dma_cfg->channel_priority); + return -EINVAL; + } + + if (dma_cfg->head_block->source_addr_adj == DMA_ADDR_ADJ_DECREMENT) { + LOG_ERR("source_addr_adj not supported DMA_ADDR_ADJ_DECREMENT"); + return -ENOTSUP; + } + + if (dma_cfg->head_block->dest_addr_adj == DMA_ADDR_ADJ_DECREMENT) { + LOG_ERR("dest_addr_adj not supported DMA_ADDR_ADJ_DECREMENT"); + return -ENOTSUP; + } + + if (dma_cfg->head_block->source_addr_adj != DMA_ADDR_ADJ_INCREMENT && + dma_cfg->head_block->source_addr_adj != DMA_ADDR_ADJ_NO_CHANGE) { + LOG_ERR("invalid source_addr_adj %" PRIu16, dma_cfg->head_block->source_addr_adj); + return -ENOTSUP; + } + if (dma_cfg->head_block->dest_addr_adj != DMA_ADDR_ADJ_INCREMENT && + dma_cfg->head_block->dest_addr_adj != DMA_ADDR_ADJ_NO_CHANGE) { + LOG_ERR("invalid dest_addr_adj %" PRIu16, dma_cfg->head_block->dest_addr_adj); + return -ENOTSUP; + } + + if (dma_cfg->source_data_size != 1 && dma_cfg->source_data_size != 2 && + dma_cfg->source_data_size != 4) { + LOG_ERR("source_data_size must be 1, 2, or 4 (%" PRIu32 ")", + dma_cfg->source_data_size); + return -EINVAL; + } + + if (dma_cfg->source_data_size != dma_cfg->dest_data_size) { + return -EINVAL; + } + + if (dma_cfg->dest_data_size != 1 && dma_cfg->dest_data_size != 2 && + dma_cfg->dest_data_size != 4) { + LOG_ERR("dest_data_size must be 1, 2, or 4 (%" PRIu32 ")", dma_cfg->dest_data_size); + return -EINVAL; + } + + if (dma_cfg->channel_direction > PERIPHERAL_TO_MEMORY) { + LOG_ERR("channel_direction must be MEMORY_TO_MEMORY, " + "MEMORY_TO_PERIPHERAL or PERIPHERAL_TO_MEMORY (%" PRIu32 ")", + dma_cfg->channel_direction); + return -ENOTSUP; + } + + data->channels[channel].config = dma_channel_get_default_config(channel); + + data->channels[channel].source_address = (void *)dma_cfg->head_block->source_address; + data->channels[channel].dest_address = (void *)dma_cfg->head_block->dest_address; + data->channels[channel].block_size = dma_cfg->head_block->block_size; + channel_config_set_read_increment(&data->channels[channel].config, + dma_cfg->head_block->source_addr_adj == + DMA_ADDR_ADJ_INCREMENT); + channel_config_set_write_increment(&data->channels[channel].config, + dma_cfg->head_block->dest_addr_adj == + DMA_ADDR_ADJ_INCREMENT); + channel_config_set_transfer_data_size( + &data->channels[channel].config, + dma_rpi_pico_transfer_size(dma_cfg->source_data_size)); + channel_config_set_dreq(&data->channels[channel].config, + RPI_PICO_DMA_SLOT_TO_DREQ(dma_cfg->dma_slot)); + channel_config_set_high_priority(&data->channels[channel].config, + !!(dma_cfg->channel_priority)); + + data->channels[channel].callback = dma_cfg->dma_callback; + data->channels[channel].user_data = dma_cfg->user_data; + data->channels[channel].direction = dma_cfg->channel_direction; + + return 0; +} + +static int dma_rpi_pico_reload(const struct device *dev, uint32_t ch, uint32_t src, uint32_t dst, + size_t size) +{ + const struct dma_rpi_pico_config *cfg = dev->config; + struct dma_rpi_pico_data *data = dev->data; + + if (ch >= cfg->channels) { + LOG_ERR("reload channel must be < %" PRIu32 " (%" PRIu32 ")", cfg->channels, ch); + return -EINVAL; + } + + if (dma_channel_is_busy(ch)) { + return -EBUSY; + } + + data->channels[ch].source_address = (void *)src; + data->channels[ch].dest_address = (void *)dst; + data->channels[ch].block_size = size; + dma_channel_configure(ch, &data->channels[ch].config, data->channels[ch].dest_address, + data->channels[ch].source_address, data->channels[ch].block_size, + true); + + return 0; +} + +static int dma_rpi_pico_start(const struct device *dev, uint32_t ch) +{ + const struct dma_rpi_pico_config *cfg = dev->config; + struct dma_rpi_pico_data *data = dev->data; + + if (ch >= cfg->channels) { + LOG_ERR("start channel must be < %" PRIu32 " (%" PRIu32 ")", cfg->channels, ch); + return -EINVAL; + } + + dma_irqn_acknowledge_channel(dma_rpi_pico_channel_irq(dev, ch), ch); + dma_irqn_set_channel_enabled(dma_rpi_pico_channel_irq(dev, ch), ch, true); + + dma_channel_configure(ch, &data->channels[ch].config, data->channels[ch].dest_address, + data->channels[ch].source_address, data->channels[ch].block_size, + true); + + return 0; +} + +static int dma_rpi_pico_stop(const struct device *dev, uint32_t ch) +{ + const struct dma_rpi_pico_config *cfg = dev->config; + + if (ch >= cfg->channels) { + LOG_ERR("stop channel must be < %" PRIu32 " (%" PRIu32 ")", cfg->channels, ch); + return -EINVAL; + } + + dma_irqn_set_channel_enabled(dma_rpi_pico_channel_irq(dev, ch), ch, false); + rpi_pico_dma_channel_clear_error_flags(dev, ch); + + /* + * Considering the possibility of being called in an interrupt context, + * it does not wait until the abort bit becomes clear. + * Ensure the busy status is canceled with dma_get_status + * before the next transfer starts. + */ + rpi_pico_dma_channel_abort(dev, ch); + + return 0; +} + +static int dma_rpi_pico_get_status(const struct device *dev, uint32_t ch, struct dma_status *stat) +{ + const struct dma_rpi_pico_config *cfg = dev->config; + struct dma_rpi_pico_data *data = dev->data; + + if (ch >= cfg->channels) { + LOG_ERR("channel must be < %" PRIu32 " (%" PRIu32 ")", cfg->channels, ch); + return -EINVAL; + } + + stat->pending_length = 0; + stat->dir = data->channels[ch].direction; + stat->busy = dma_channel_is_busy(ch); + + return 0; +} + +static bool dma_rpi_pico_api_chan_filter(const struct device *dev, int ch, void *filter_param) +{ + uint32_t filter; + + if (!filter_param) { + LOG_ERR("filter_param must not be NULL"); + return false; + } + + filter = *((uint32_t *)filter_param); + + return (filter & BIT(ch)); +} + +static int dma_rpi_pico_init(const struct device *dev) +{ + const struct dma_rpi_pico_config *cfg = dev->config; + + (void)reset_line_toggle_dt(&cfg->reset); + + cfg->irq_configure(); + + return 0; +} + +static void dma_rpi_pico_isr(const struct device *dev) +{ + const struct dma_rpi_pico_config *cfg = dev->config; + struct dma_rpi_pico_data *data = dev->data; + int err = 0; + + for (uint32_t i = 0; i < cfg->channels; i++) { + if (!dma_irqn_get_channel_status(dma_rpi_pico_channel_irq(dev, i), i)) { + continue; + } + + if (rpi_pico_dma_channel_get_error_flags(dev, i)) { + err = -EIO; + } + + dma_irqn_acknowledge_channel(dma_rpi_pico_channel_irq(dev, i), i); + dma_irqn_set_channel_enabled(dma_rpi_pico_channel_irq(dev, i), i, false); + rpi_pico_dma_channel_clear_error_flags(dev, i); + + if (data->channels[i].callback) { + data->channels[i].callback(dev, data->channels[i].user_data, i, err); + } + } +} + +static const struct dma_driver_api dma_rpi_pico_driver_api = { + .config = dma_rpi_pico_config, + .reload = dma_rpi_pico_reload, + .start = dma_rpi_pico_start, + .stop = dma_rpi_pico_stop, + .get_status = dma_rpi_pico_get_status, + .chan_filter = dma_rpi_pico_api_chan_filter, +}; + +#define IRQ_CONFIGURE(n, inst) \ + IRQ_CONNECT(DT_INST_IRQ_BY_IDX(inst, n, irq), DT_INST_IRQ_BY_IDX(inst, n, priority), \ + dma_rpi_pico_isr, DEVICE_DT_INST_GET(inst), 0); \ + irq_enable(DT_INST_IRQ_BY_IDX(inst, n, irq)); + +#define CONFIGURE_ALL_IRQS(inst, n) LISTIFY(n, IRQ_CONFIGURE, (), inst) + +#define RPI_PICO_DMA_INIT(inst) \ + static void dma_rpi_pico##inst##_irq_configure(void) \ + { \ + CONFIGURE_ALL_IRQS(inst, DT_NUM_IRQS(DT_DRV_INST(inst))); \ + } \ + static uint32_t dma_rpi_pico##inst##_irq0_channels[] = \ + DT_INST_PROP_OR(inst, irq0_channels, {0}); \ + static const struct dma_rpi_pico_config dma_rpi_pico##inst##_config = { \ + .reg = DT_INST_REG_ADDR(inst), \ + .channels = DT_INST_PROP(inst, dma_channels), \ + .reset = RESET_DT_SPEC_INST_GET(inst), \ + .irq_configure = dma_rpi_pico##inst##_irq_configure, \ + .irq0_channels = dma_rpi_pico##inst##_irq0_channels, \ + .irq0_channels_size = ARRAY_SIZE(dma_rpi_pico##inst##_irq0_channels), \ + }; \ + static struct dma_rpi_pico_channel \ + dma_rpi_pico##inst##_channels[DT_INST_PROP(inst, dma_channels)]; \ + ATOMIC_DEFINE(dma_rpi_pico_atomic##inst, DT_INST_PROP(inst, dma_channels)); \ + static struct dma_rpi_pico_data dma_rpi_pico##inst##_data = { \ + .ctx = \ + { \ + .magic = DMA_MAGIC, \ + .atomic = dma_rpi_pico_atomic##inst, \ + .dma_channels = DT_INST_PROP(inst, dma_channels), \ + }, \ + .channels = dma_rpi_pico##inst##_channels, \ + }; \ + \ + DEVICE_DT_INST_DEFINE(inst, &dma_rpi_pico_init, NULL, &dma_rpi_pico##inst##_data, \ + &dma_rpi_pico##inst##_config, POST_KERNEL, CONFIG_DMA_INIT_PRIORITY, \ + &dma_rpi_pico_driver_api); + +DT_INST_FOREACH_STATUS_OKAY(RPI_PICO_DMA_INIT) diff --git a/dts/arm/rpi_pico/rp2040.dtsi b/dts/arm/rpi_pico/rp2040.dtsi index 591041136b68..eebb68a61d40 100644 --- a/dts/arm/rpi_pico/rp2040.dtsi +++ b/dts/arm/rpi_pico/rp2040.dtsi @@ -186,6 +186,19 @@ #pwm-cells = <3>; }; + dma: dma@50000000 { + compatible = "raspberrypi,pico-dma"; + reg = <0x50000000 DT_SIZE_K(64)>; + resets = <&reset RPI_PICO_RESETS_RESET_DMA>; + clocks = <&system_clk>; + interrupts = <11 RPI_PICO_DEFAULT_IRQ_PRIORITY>, + <12 RPI_PICO_DEFAULT_IRQ_PRIORITY>; + interrupt-names = "dma0", "dma1"; + dma-channels = <12>; + status = "disabled"; + #dma-cells = <3>; + }; + vreg: vreg@40064000 { compatible = "raspberrypi,core-supply-regulator"; reg = <0x40064000 1>; diff --git a/dts/bindings/dma/raspberrypi,pico-dma.yaml b/dts/bindings/dma/raspberrypi,pico-dma.yaml new file mode 100644 index 000000000000..35960fbca7fe --- /dev/null +++ b/dts/bindings/dma/raspberrypi,pico-dma.yaml @@ -0,0 +1,42 @@ +# Copyright (c) 2023 TOKITA Hiroshi +# SPDX-License-Identifier: Apache-2.0 + +description: | + Raspberry Pi Pico GPIO + + channel: Select channel for data transmitting + + slot: Select peripheral data request + Use the definitions defined in `zephyr/dt-bindings/dma/rpi_pico_dma.h`. + + channel-config: A 32bit mask specifying the DMA channel configuration + - bit 3: Enable Quiet IRQ + - bit 1: Enable Byte Swap + - bit 0: Enable High Priority + +compatible: "raspberrypi,pico-dma" + +include: [dma-controller.yaml, reset-device.yaml] + +properties: + reg: + required: true + + interrupts: + required: true + + dma-channels: + required: true + + irq0-channels: + type: uint8-array + default: [0, 2, 4, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30] + description: Channels list that uses the irq0 + + "#dma-cells": + const: 3 + +dma-cells: + - channel + - slot + - channel-config diff --git a/include/zephyr/dt-bindings/dma/rpi_pico_dma.h b/include/zephyr/dt-bindings/dma/rpi_pico_dma.h new file mode 100644 index 000000000000..f181a31beba9 --- /dev/null +++ b/include/zephyr/dt-bindings/dma/rpi_pico_dma.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 TOKITA Hiroshi + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_RPI_PICO_DMA_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_RPI_PICO_DMA_H_ + +/* + * Use lower 6-bit of inverted DREQ value for `slot` cell. + * Need to be able to work for memory-to-memory transfer + * with zero, which is the default value. + */ +#define RPI_PICO_DMA_SLOT_TO_DREQ(s) (~(s)&0x3F) +#define RPI_PICO_DMA_DREQ_TO_SLOT RPI_PICO_DMA_SLOT_TO_DREQ + +#define RPI_PICO_DMA_SLOT_PIO0_TX0 RPI_PICO_DMA_DREQ_TO_SLOT(0x00) +#define RPI_PICO_DMA_SLOT_PIO0_TX1 RPI_PICO_DMA_DREQ_TO_SLOT(0x01) +#define RPI_PICO_DMA_SLOT_PIO0_TX2 RPI_PICO_DMA_DREQ_TO_SLOT(0x02) +#define RPI_PICO_DMA_SLOT_PIO0_TX3 RPI_PICO_DMA_DREQ_TO_SLOT(0x03) +#define RPI_PICO_DMA_SLOT_PIO0_RX0 RPI_PICO_DMA_DREQ_TO_SLOT(0x04) +#define RPI_PICO_DMA_SLOT_PIO0_RX1 RPI_PICO_DMA_DREQ_TO_SLOT(0x05) +#define RPI_PICO_DMA_SLOT_PIO0_RX2 RPI_PICO_DMA_DREQ_TO_SLOT(0x06) +#define RPI_PICO_DMA_SLOT_PIO0_RX3 RPI_PICO_DMA_DREQ_TO_SLOT(0x07) +#define RPI_PICO_DMA_SLOT_PIO1_TX0 RPI_PICO_DMA_DREQ_TO_SLOT(0x08) +#define RPI_PICO_DMA_SLOT_PIO1_TX1 RPI_PICO_DMA_DREQ_TO_SLOT(0x09) +#define RPI_PICO_DMA_SLOT_PIO1_TX2 RPI_PICO_DMA_DREQ_TO_SLOT(0x0A) +#define RPI_PICO_DMA_SLOT_PIO1_TX3 RPI_PICO_DMA_DREQ_TO_SLOT(0x0B) +#define RPI_PICO_DMA_SLOT_PIO1_RX0 RPI_PICO_DMA_DREQ_TO_SLOT(0x0C) +#define RPI_PICO_DMA_SLOT_PIO1_RX1 RPI_PICO_DMA_DREQ_TO_SLOT(0x0D) +#define RPI_PICO_DMA_SLOT_PIO1_RX2 RPI_PICO_DMA_DREQ_TO_SLOT(0x0E) +#define RPI_PICO_DMA_SLOT_PIO1_RX3 RPI_PICO_DMA_DREQ_TO_SLOT(0x0F) +#define RPI_PICO_DMA_SLOT_SPI0_TX RPI_PICO_DMA_DREQ_TO_SLOT(0x10) +#define RPI_PICO_DMA_SLOT_SPI0_RX RPI_PICO_DMA_DREQ_TO_SLOT(0x11) +#define RPI_PICO_DMA_SLOT_SPI1_TX RPI_PICO_DMA_DREQ_TO_SLOT(0x12) +#define RPI_PICO_DMA_SLOT_SPI1_RX RPI_PICO_DMA_DREQ_TO_SLOT(0x13) +#define RPI_PICO_DMA_SLOT_UART0_TX RPI_PICO_DMA_DREQ_TO_SLOT(0x14) +#define RPI_PICO_DMA_SLOT_UART0_RX RPI_PICO_DMA_DREQ_TO_SLOT(0x15) +#define RPI_PICO_DMA_SLOT_UART1_TX RPI_PICO_DMA_DREQ_TO_SLOT(0x16) +#define RPI_PICO_DMA_SLOT_UART1_RX RPI_PICO_DMA_DREQ_TO_SLOT(0x17) +#define RPI_PICO_DMA_SLOT_PWM_WRAP0 RPI_PICO_DMA_DREQ_TO_SLOT(0x18) +#define RPI_PICO_DMA_SLOT_PWM_WRAP1 RPI_PICO_DMA_DREQ_TO_SLOT(0x19) +#define RPI_PICO_DMA_SLOT_PWM_WRAP2 RPI_PICO_DMA_DREQ_TO_SLOT(0x1A) +#define RPI_PICO_DMA_SLOT_PWM_WRAP3 RPI_PICO_DMA_DREQ_TO_SLOT(0x1B) +#define RPI_PICO_DMA_SLOT_PWM_WRAP4 RPI_PICO_DMA_DREQ_TO_SLOT(0x1C) +#define RPI_PICO_DMA_SLOT_PWM_WRAP5 RPI_PICO_DMA_DREQ_TO_SLOT(0x1D) +#define RPI_PICO_DMA_SLOT_PWM_WRAP6 RPI_PICO_DMA_DREQ_TO_SLOT(0x1E) +#define RPI_PICO_DMA_SLOT_PWM_WRAP7 RPI_PICO_DMA_DREQ_TO_SLOT(0x1F) +#define RPI_PICO_DMA_SLOT_I2C0_TX RPI_PICO_DMA_DREQ_TO_SLOT(0x30) +#define RPI_PICO_DMA_SLOT_I2C0_RX RPI_PICO_DMA_DREQ_TO_SLOT(0x31) +#define RPI_PICO_DMA_SLOT_I2C1_TX RPI_PICO_DMA_DREQ_TO_SLOT(0x32) +#define RPI_PICO_DMA_SLOT_I2C1_RX RPI_PICO_DMA_DREQ_TO_SLOT(0x33) +#define RPI_PICO_DMA_SLOT_ADC RPI_PICO_DMA_DREQ_TO_SLOT(0x34) +#define RPI_PICO_DMA_SLOT_XIP_STREAM RPI_PICO_DMA_DREQ_TO_SLOT(0x35) +#define RPI_PICO_DMA_SLOT_XIP_SSITX RPI_PICO_DMA_DREQ_TO_SLOT(0x36) +#define RPI_PICO_DMA_SLOT_XIP_SSIRX RPI_PICO_DMA_DREQ_TO_SLOT(0x37) +#define RPI_PICO_DMA_SLOT_DMA_TIMER0 RPI_PICO_DMA_DREQ_TO_SLOT(0x3B) +#define RPI_PICO_DMA_SLOT_DMA_TIMER1 RPI_PICO_DMA_DREQ_TO_SLOT(0x3C) +#define RPI_PICO_DMA_SLOT_DMA_TIMER2 RPI_PICO_DMA_DREQ_TO_SLOT(0x3D) +#define RPI_PICO_DMA_SLOT_DMA_TIMER3 RPI_PICO_DMA_DREQ_TO_SLOT(0x3E) +#define RPI_PICO_DMA_SLOT_FORCE RPI_PICO_DMA_DREQ_TO_SLOT(0x3F) + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_RPI_PICO_DMA_H_ */ From 774affe2e946af7712d7b8a5e0fd05b37cbb2941 Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Wed, 18 Jan 2023 08:56:33 +0900 Subject: [PATCH 0608/1906] tests: dma: loop_transfer: add overlay for RaspberryPi Pico Add overlay file for rpi_pico target. Signed-off-by: TOKITA Hiroshi --- tests/drivers/dma/loop_transfer/boards/rpi_pico.overlay | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/drivers/dma/loop_transfer/boards/rpi_pico.overlay diff --git a/tests/drivers/dma/loop_transfer/boards/rpi_pico.overlay b/tests/drivers/dma/loop_transfer/boards/rpi_pico.overlay new file mode 100644 index 000000000000..b70c452e4250 --- /dev/null +++ b/tests/drivers/dma/loop_transfer/boards/rpi_pico.overlay @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2023 Tokita, Hiroshi + * + * SPDX-License-Identifier: Apache-2.0 + */ + +test_dma: &dma { + status = "okay"; +}; From 05e78fa1287a87c7ebd8b459945cdda66cc5d021 Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Mon, 20 Mar 2023 12:52:56 +0100 Subject: [PATCH 0609/1906] Tests: bsim: update permutations compilation script The script that compiles different permutations of Kconfig settings for the control procedures must build each permutation in sequence. The current implementation of the compile-script starts each build in the background. This PR fixes that so that each build now is run sequentially. Signed-off-by: Andries Kruithof --- tests/bsim/bluetooth/_compile_permutate_kconfigs.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/bsim/bluetooth/_compile_permutate_kconfigs.sh b/tests/bsim/bluetooth/_compile_permutate_kconfigs.sh index 50260320e9df..5b2682390335 100755 --- a/tests/bsim/bluetooth/_compile_permutate_kconfigs.sh +++ b/tests/bsim/bluetooth/_compile_permutate_kconfigs.sh @@ -15,7 +15,7 @@ DEBUG_PERMUTATE=false : "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ directory}" -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}" +WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" BOARD="${BOARD:-nrf52_bsim}" BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" @@ -62,10 +62,13 @@ perm_compile() { echo "Compile with config overlay:" cat $3 fi - local app=tests/bsim/bluetooth/edtt_ble_test_app/hci_test_app + local app=tests/bsim/bluetooth/ll/edtt/hci_test_app local conf_file=prj_dut_llcp.conf local conf_overlay=$3 - compile +# Note: we need to call '_compile' instead of 'compile' because the latter starts +# compilations in parallel, but here we need to do it in serial since we modify +# the configuration file between each run + _compile if [ ! -f ${executable_name} ]; then compile_failures=$(expr $compile_failures + 1) fi From 264ccd2e67c7f3906072d40194b70f48a5c27b0e Mon Sep 17 00:00:00 2001 From: Frode van der Meeren Date: Mon, 20 Mar 2023 13:11:31 +0000 Subject: [PATCH 0610/1906] samples: Bluetooth: Kconfig for limited printout in some ISO samples Add kconfig to let the ISO broadcast and ISO receive samples report packets no more than once per set interval of packets. Signed-off-by: Frode van der Meeren --- samples/bluetooth/iso_broadcast/Kconfig | 13 +++++++++++++ samples/bluetooth/iso_broadcast/src/main.c | 8 ++++---- samples/bluetooth/iso_receive/Kconfig | 20 ++++++++++++++++++++ samples/bluetooth/iso_receive/src/main.c | 19 +++++++++++++++---- 4 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 samples/bluetooth/iso_broadcast/Kconfig create mode 100644 samples/bluetooth/iso_receive/Kconfig diff --git a/samples/bluetooth/iso_broadcast/Kconfig b/samples/bluetooth/iso_broadcast/Kconfig new file mode 100644 index 000000000000..21df24566f6b --- /dev/null +++ b/samples/bluetooth/iso_broadcast/Kconfig @@ -0,0 +1,13 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "Kconfig.zephyr" + +mainmenu "Bluetooth: ISO Broadcast" + +config ISO_PRINT_INTERVAL + int "Interval between each packet report" + range 1 360000 + default 1 + help + Only print the packet report once in a given interval of ISO packets. diff --git a/samples/bluetooth/iso_broadcast/src/main.c b/samples/bluetooth/iso_broadcast/src/main.c index 2e177b8099cd..96312c3d825b 100644 --- a/samples/bluetooth/iso_broadcast/src/main.c +++ b/samples/bluetooth/iso_broadcast/src/main.c @@ -167,13 +167,13 @@ void main(void) } - iso_send_count++; - seq_num++; - - if ((iso_send_count % 100) == 0) { + if ((iso_send_count % CONFIG_ISO_PRINT_INTERVAL) == 0) { printk("Sending value %u\n", iso_send_count); } + iso_send_count++; + seq_num++; + timeout_counter--; if (!timeout_counter) { timeout_counter = INITIAL_TIMEOUT_COUNTER; diff --git a/samples/bluetooth/iso_receive/Kconfig b/samples/bluetooth/iso_receive/Kconfig new file mode 100644 index 000000000000..22e164ebfe4b --- /dev/null +++ b/samples/bluetooth/iso_receive/Kconfig @@ -0,0 +1,20 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "Kconfig.zephyr" + +mainmenu "Bluetooth: ISO Receive" + +config ISO_PRINT_INTERVAL + int "Interval between each packet report" + range 1 360000 + default 1 + help + Only print the packet report once in a given interval of ISO packets. + +config ISO_ALIGN_PRINT_INTERVALS + bool "Align report interval with incoming packets" + help + Align interval-counter with packet number from incoming ISO packets. + This may be needed if report printouts are to be synchronized between + the iso_broadcast sample and the iso_receive sample. diff --git a/samples/bluetooth/iso_receive/src/main.c b/samples/bluetooth/iso_receive/src/main.c index ad59970806a2..5567d49757e0 100644 --- a/samples/bluetooth/iso_receive/src/main.c +++ b/samples/bluetooth/iso_receive/src/main.c @@ -30,6 +30,8 @@ static bt_addr_le_t per_addr; static uint8_t per_sid; static uint32_t per_interval_us; +static uint32_t iso_recv_count; + static K_SEM_DEFINE(sem_per_adv, 0, 1); static K_SEM_DEFINE(sem_per_sync, 0, 1); static K_SEM_DEFINE(sem_per_sync_lost, 0, 1); @@ -215,12 +217,19 @@ static void iso_recv(struct bt_iso_chan *chan, const struct bt_iso_recv_info *in if (buf->len == sizeof(count)) { count = sys_get_le32(buf->data); + if (IS_ENABLED(CONFIG_ISO_ALIGN_PRINT_INTERVALS)) { + iso_recv_count = count; + } } - str_len = bin2hex(buf->data, buf->len, data_str, sizeof(data_str)); - printk("Incoming data channel %p flags 0x%x seq_num %u ts %u len %u: " - "%s (counter value %u)\n", chan, info->flags, info->seq_num, - info->ts, buf->len, data_str, count); + if ((iso_recv_count % CONFIG_ISO_PRINT_INTERVAL) == 0) { + str_len = bin2hex(buf->data, buf->len, data_str, sizeof(data_str)); + printk("Incoming data channel %p flags 0x%x seq_num %u ts %u len %u: " + "%s (counter value %u)\n", chan, info->flags, info->seq_num, + info->ts, buf->len, data_str, count); + } + + iso_recv_count++; } static void iso_connected(struct bt_iso_chan *chan) @@ -280,6 +289,8 @@ void main(void) uint32_t sem_timeout_us; int err; + iso_recv_count = 0; + printk("Starting Synchronized Receiver Demo\n"); #if defined(HAS_LED) From f2d04ab1894c7b553aa6fc3b657e18762e30b806 Mon Sep 17 00:00:00 2001 From: Evgeniy Paltsev Date: Mon, 20 Mar 2023 18:55:48 +0000 Subject: [PATCH 0611/1906] twister: fix timeout status for the device handler Currently in binary handler and qemu handler we have status `failed` in case of test timeout, but in device handler we have status `error` This not only adds inconsistency between handlers, but also prevents us from usage test retry functionality for the runs on HW. Fix timeout status by changing it to `failed` instead of `error`. Signed-off-by: Eugeniy Paltsev Signed-off-by: Evgeniy Paltsev --- scripts/pylib/twister/twisterlib/handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pylib/twister/twisterlib/handlers.py b/scripts/pylib/twister/twisterlib/handlers.py index e69be4480758..7d70f76d7e14 100755 --- a/scripts/pylib/twister/twisterlib/handlers.py +++ b/scripts/pylib/twister/twisterlib/handlers.py @@ -630,7 +630,7 @@ def handle(self): if harness.state == "failed": self.instance.reason = "Failed" elif not flash_error: - self.instance.status = "error" + self.instance.status = "failed" self.instance.reason = "Timeout" if self.instance.status == "error": From 36f592ddbc97adae5875f2ad3ab9018572e0d342 Mon Sep 17 00:00:00 2001 From: Hein Wessels Date: Tue, 21 Mar 2023 09:17:44 +0100 Subject: [PATCH 0612/1906] drivers: adc: stm32: only handle OVR flag when supported STM32 ADC DMA support added in #52965 incorrectly assumed that all ADC devices have a OVR flag. This commit changes the driver to only account for it if it's found in the LL drivers. Signed-off-by: Hein Wessels --- drivers/adc/adc_stm32.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/adc/adc_stm32.c b/drivers/adc/adc_stm32.c index df57613020f0..f5cb173db080 100644 --- a/drivers/adc/adc_stm32.c +++ b/drivers/adc/adc_stm32.c @@ -794,7 +794,11 @@ static void dma_callback(const struct device *dev, void *user_data, LOG_DBG("dma callback"); if (channel == data->dma.channel) { +#if !defined(CONFIG_SOC_SERIES_STM32F1X) if (LL_ADC_IsActiveFlag_OVR(adc) || (status == 0)) { +#else + if (status == 0) { +#endif /* !defined(CONFIG_SOC_SERIES_STM32F1X) */ data->samples_count = data->channel_count; data->buffer += data->channel_count; /* Stop the DMA engine, only to start it again when the callback returns @@ -803,7 +807,9 @@ static void dma_callback(const struct device *dev, void *user_data, * within adc_context_start_sampling */ dma_stop(data->dma.dma_dev, data->dma.channel); +#if !defined(CONFIG_SOC_SERIES_STM32F1X) LL_ADC_ClearFlag_OVR(adc); +#endif /* !defined(CONFIG_SOC_SERIES_STM32F1X) */ /* No need to invalidate the cache because it's assumed that * the address is in a non-cacheable SRAM region. */ @@ -1087,7 +1093,9 @@ static int start_read(const struct device *dev, */ adc_stm32_enable(adc); +#if !defined(CONFIG_SOC_SERIES_STM32F1X) LL_ADC_ClearFlag_OVR(adc); +#endif /* !defined(CONFIG_SOC_SERIES_STM32F1X) */ #if !defined(CONFIG_ADC_STM32_DMA) #if defined(CONFIG_SOC_SERIES_STM32F0X) || \ From 2e53128d523acfca9ed1961af1f86dd5ede3a4fe Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 21 Mar 2023 15:42:52 +0100 Subject: [PATCH 0613/1906] doc: bluetooth: mesh: Relocate foundation models Solicitation PDU RPL and On-Demand Private GATT Proxy models are foundation models. Signed-off-by: Pavel Vasilyev --- doc/connectivity/bluetooth/api/mesh/models.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/connectivity/bluetooth/api/mesh/models.rst b/doc/connectivity/bluetooth/api/mesh/models.rst index 4bdfef5d05b3..cbc649674629 100644 --- a/doc/connectivity/bluetooth/api/mesh/models.rst +++ b/doc/connectivity/bluetooth/api/mesh/models.rst @@ -20,16 +20,17 @@ used by network administrators to configure and diagnose mesh nodes. priv_beacon_cli op_agg_cli op_agg_srv + srpl + od Model specification models ************************** -In addition to the foundation models defined in the Bluetooth mesh specification, the Bluetooth Mesh Model Specification defines several models, some of which are implemented in Zephyr: +In addition to the foundation models defined in the Bluetooth mesh specification, the Bluetooth Mesh +Model Specification defines several models, some of which are implemented in Zephyr: .. toctree:: :maxdepth: 1 blob dfu - srpl - od From 08f4a82038a272812a4793293d821ed7869411ff Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Tue, 21 Mar 2023 16:21:41 +0100 Subject: [PATCH 0614/1906] Bluetooth: Mesh: Remove deprecated health API Deprecated Health client and server API has been deprecated for two releases: 3.2.0 and 3.3.0. Signed-off-by: Pavel Vasilyev --- include/zephyr/bluetooth/mesh/health_cli.h | 213 --------------------- include/zephyr/bluetooth/mesh/health_srv.h | 13 -- subsys/bluetooth/mesh/health_cli.c | 101 ---------- subsys/bluetooth/mesh/health_srv.c | 5 - 4 files changed, 332 deletions(-) diff --git a/include/zephyr/bluetooth/mesh/health_cli.h b/include/zephyr/bluetooth/mesh/health_cli.h index f8b3260aa828..21fc5a93e6af 100644 --- a/include/zephyr/bluetooth/mesh/health_cli.h +++ b/include/zephyr/bluetooth/mesh/health_cli.h @@ -110,219 +110,6 @@ struct bt_mesh_health_cli { BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_HEALTH_CLI, bt_mesh_health_cli_op, \ &(cli_data)->pub, cli_data, &bt_mesh_health_cli_cb) -/** @brief Set Health client model instance to use for communication. - * - * @param model Health Client model instance from the composition data. - * - * @return 0 on success, or (negative) error code on failure. - */ -__deprecated int bt_mesh_health_cli_set(struct bt_mesh_model *model); - -/** @brief Get the registered fault state for the given Company ID. - * - * This method can be used asynchronously by setting @p test_id - * and ( @p faults or @p fault_count ) as NULL This way the method - * will not wait for response and will return immediately after - * sending the command. - * - * To process the response arguments of an async method, register - * the @c fault_status callback in @c bt_mesh_health_cli struct. - * - * @see bt_mesh_health_faults - * - * @param addr Target node element address. - * @param app_idx Application index to encrypt with. - * @param cid Company ID to get the registered faults of. - * @param test_id Test ID response buffer. - * @param faults Fault array response buffer. - * @param fault_count Fault count response buffer. - * - * @return 0 on success, or (negative) error code on failure. - */ -__deprecated int bt_mesh_health_fault_get(uint16_t addr, uint16_t app_idx, uint16_t cid, - uint8_t *test_id, uint8_t *faults, size_t *fault_count); - -/** @brief Clear the registered faults for the given Company ID. - * - * This method can be used asynchronously by setting @p test_id - * and ( @p faults or @p fault_count ) as NULL This way the method - * will not wait for response and will return immediately after - * sending the command. - * - * To process the response arguments of an async method, register - * the @c fault_status callback in @c bt_mesh_health_cli struct. - * - * @see bt_mesh_health_faults - * - * @param addr Target node element address. - * @param app_idx Application index to encrypt with. - * @param cid Company ID to clear the registered faults for. - * @param test_id Test ID response buffer. - * @param faults Fault array response buffer. - * @param fault_count Fault count response buffer. - * - * @return 0 on success, or (negative) error code on failure. - */ -__deprecated int bt_mesh_health_fault_clear(uint16_t addr, uint16_t app_idx, uint16_t cid, - uint8_t *test_id, uint8_t *faults, size_t *fault_count); - -/** @brief Clear the registered faults for the given Company ID (unacked). - * - * @see bt_mesh_health_faults - * - * @param addr Target node element address. - * @param app_idx Application index to encrypt with. - * @param cid Company ID to clear the registered faults for. - * - * @return 0 on success, or (negative) error code on failure. - */ -__deprecated int bt_mesh_health_fault_clear_unack(uint16_t addr, uint16_t app_idx, uint16_t cid); - -/** @brief Invoke a self-test procedure for the given Company ID. - * - * This method can be used asynchronously by setting @p faults - * or @p fault_count as NULL This way the method will not wait - * for response and will return immediately after sending the command. - * - * To process the response arguments of an async method, register - * the @c fault_status callback in @c bt_mesh_health_cli struct. - * - * @param addr Target node element address. - * @param app_idx Application index to encrypt with. - * @param cid Company ID to invoke the test for. - * @param test_id Test ID response buffer. - * @param faults Fault array response buffer. - * @param fault_count Fault count response buffer. - * - * @return 0 on success, or (negative) error code on failure. - */ -__deprecated int bt_mesh_health_fault_test(uint16_t addr, uint16_t app_idx, uint16_t cid, - uint8_t test_id, uint8_t *faults, size_t *fault_count); - -/** @brief Invoke a self-test procedure for the given Company ID (unacked). - * - * @param addr Target node element address. - * @param app_idx Application index to encrypt with. - * @param cid Company ID to invoke the test for. - * @param test_id Test ID response buffer. - * - * @return 0 on success, or (negative) error code on failure. - */ -__deprecated int bt_mesh_health_fault_test_unack(uint16_t addr, uint16_t app_idx, uint16_t cid, - uint8_t test_id); - -/** @brief Get the target node's Health fast period divisor. - * - * The health period divisor is used to increase the publish rate when a fault - * is registered. Normally, the Health server will publish with the period in - * the configured publish parameters. When a fault is registered, the publish - * period is divided by (1 << divisor). For example, if the target node's - * Health server is configured to publish with a period of 16 seconds, and the - * Health fast period divisor is 5, the Health server will publish with an - * interval of 500 ms when a fault is registered. - * - * This method can be used asynchronously by setting @p divisor - * as NULL. This way the method will not wait for response and will - * return immediately after sending the command. - * - * To process the response arguments of an async method, register - * the @c period_status callback in @c bt_mesh_health_cli struct. - * - * @param addr Target node element address. - * @param app_idx Application index to encrypt with. - * @param divisor Health period divisor response buffer. - * - * @return 0 on success, or (negative) error code on failure. - */ -__deprecated int bt_mesh_health_period_get(uint16_t addr, uint16_t app_idx, uint8_t *divisor); - -/** @brief Set the target node's Health fast period divisor. - * - * The health period divisor is used to increase the publish rate when a fault - * is registered. Normally, the Health server will publish with the period in - * the configured publish parameters. When a fault is registered, the publish - * period is divided by (1 << divisor). For example, if the target node's - * Health server is configured to publish with a period of 16 seconds, and the - * Health fast period divisor is 5, the Health server will publish with an - * interval of 500 ms when a fault is registered. - * - * This method can be used asynchronously by setting @p updated_divisor - * as NULL. This way the method will not wait for response and will - * return immediately after sending the command. - * - * To process the response arguments of an async method, register - * the @c period_status callback in @c bt_mesh_health_cli struct. - * - * @param addr Target node element address. - * @param app_idx Application index to encrypt with. - * @param divisor New Health period divisor. - * @param updated_divisor Health period divisor response buffer. - * - * @return 0 on success, or (negative) error code on failure. - */ -__deprecated int bt_mesh_health_period_set(uint16_t addr, uint16_t app_idx, uint8_t divisor, - uint8_t *updated_divisor); - -/** @brief Set the target node's Health fast period divisor (unacknowledged). - * - * This is an unacknowledged version of this API. - * - * @param addr Target node element address. - * @param app_idx Application index to encrypt with. - * @param divisor New Health period divisor. - * - * @return 0 on success, or (negative) error code on failure. - */ -__deprecated int bt_mesh_health_period_set_unack(uint16_t addr, uint16_t app_idx, uint8_t divisor); - -/** @brief Get the current attention timer value. - * - * This method can be used asynchronously by setting @p attention - * as NULL. This way the method will not wait for response and will - * return immediately after sending the command. - * - * To process the response arguments of an async method, register - * the @c attention_status callback in @c bt_mesh_health_cli struct. - * - * @param addr Target node element address. - * @param app_idx Application index to encrypt with. - * @param attention Attention timer response buffer, measured in seconds. - * - * @return 0 on success, or (negative) error code on failure. - */ -__deprecated int bt_mesh_health_attention_get(uint16_t addr, uint16_t app_idx, uint8_t *attention); - -/** @brief Set the attention timer. - * - * This method can be used asynchronously by setting @p updated_attention - * as NULL. This way the method will not wait for response and will - * return immediately after sending the command. - * - * To process the response arguments of an async method, register - * the @c attention_status callback in @c bt_mesh_health_cli struct. - * - * @param addr Target node element address. - * @param app_idx Application index to encrypt with. - * @param attention New attention timer time, in seconds. - * @param updated_attention Attention timer response buffer, measured in - * seconds. - * - * @return 0 on success, or (negative) error code on failure. - */ -__deprecated int bt_mesh_health_attention_set(uint16_t addr, uint16_t app_idx, uint8_t attention, - uint8_t *updated_attention); - -/** @brief Set the attention timer (unacknowledged). - * - * @param addr Target node element address. - * @param app_idx Application index to encrypt with. - * @param attention New attention timer time, in seconds. - * - * @return 0 on success, or (negative) error code on failure. - */ -__deprecated int bt_mesh_health_attention_set_unack(uint16_t addr, uint16_t app_idx, - uint8_t attention); - /** @brief Get the registered fault state for the given Company ID. * * This method can be used asynchronously by setting @p test_id diff --git a/include/zephyr/bluetooth/mesh/health_srv.h b/include/zephyr/bluetooth/mesh/health_srv.h index 1615d9c8d92c..a15633ab5cb1 100644 --- a/include/zephyr/bluetooth/mesh/health_srv.h +++ b/include/zephyr/bluetooth/mesh/health_srv.h @@ -206,19 +206,6 @@ struct bt_mesh_health_srv { #define BT_MESH_HEALTH_TEST_INFO(cid, tests...) \ (cid & 0xff), (cid >> 8), sizeof((uint8_t[]){ tests }), tests - -/** @brief Notify the stack that the fault array state of the given element has - * changed. - * - * This prompts the Health server on this element to publish the current fault - * array if periodic publishing is disabled. - * - * @param elem Element to update the fault state of. - * - * @return 0 on success, or (negative) error code otherwise. - */ -__deprecated int bt_mesh_fault_update(struct bt_mesh_elem *elem); - /** @brief Notify the stack that the fault array state of the given element has * changed. * diff --git a/subsys/bluetooth/mesh/health_cli.c b/subsys/bluetooth/mesh/health_cli.c index f9544c9e45f4..924005f48821 100644 --- a/subsys/bluetooth/mesh/health_cli.c +++ b/subsys/bluetooth/mesh/health_cli.c @@ -28,8 +28,6 @@ LOG_MODULE_REGISTER(bt_mesh_health_cli); static int32_t msg_timeout; -static struct bt_mesh_health_cli *health_cli; - struct health_fault_param { uint16_t cid; uint8_t *expect_test_id; @@ -189,91 +187,6 @@ const struct bt_mesh_model_op bt_mesh_health_cli_op[] = { BT_MESH_MODEL_OP_END, }; -int bt_mesh_health_attention_get(uint16_t addr, uint16_t app_idx, uint8_t *attention) -{ - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(app_idx, addr); - - return bt_mesh_health_cli_attention_get(health_cli, &ctx, attention); -} - -int bt_mesh_health_attention_set(uint16_t addr, uint16_t app_idx, - uint8_t attention, uint8_t *updated_attention) -{ - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(app_idx, addr); - - return bt_mesh_health_cli_attention_set(health_cli, &ctx, attention, updated_attention); -} - -int bt_mesh_health_attention_set_unack(uint16_t addr, uint16_t app_idx, uint8_t attention) -{ - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(app_idx, addr); - - return bt_mesh_health_cli_attention_set_unack(health_cli, &ctx, attention); -} - -int bt_mesh_health_period_get(uint16_t addr, uint16_t app_idx, uint8_t *divisor) -{ - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(app_idx, addr); - - return bt_mesh_health_cli_period_get(health_cli, &ctx, divisor); -} - -int bt_mesh_health_period_set(uint16_t addr, uint16_t app_idx, uint8_t divisor, - uint8_t *updated_divisor) -{ - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(app_idx, addr); - - return bt_mesh_health_cli_period_set(health_cli, &ctx, divisor, updated_divisor); -} - -int bt_mesh_health_period_set_unack(uint16_t addr, uint16_t app_idx, uint8_t divisor) -{ - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(app_idx, addr); - - return bt_mesh_health_cli_period_set_unack(health_cli, &ctx, divisor); -} - -int bt_mesh_health_fault_test(uint16_t addr, uint16_t app_idx, uint16_t cid, uint8_t test_id, - uint8_t *faults, size_t *fault_count) -{ - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(app_idx, addr); - - return bt_mesh_health_cli_fault_test(health_cli, &ctx, cid, test_id, faults, fault_count); -} - -int bt_mesh_health_fault_test_unack(uint16_t addr, uint16_t app_idx, uint16_t cid, uint8_t test_id) -{ - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(app_idx, addr); - - return bt_mesh_health_cli_fault_test_unack(health_cli, &ctx, cid, test_id); -} - -int bt_mesh_health_fault_clear(uint16_t addr, uint16_t app_idx, uint16_t cid, - uint8_t *test_id, uint8_t *faults, - size_t *fault_count) -{ - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(app_idx, addr); - - return bt_mesh_health_cli_fault_clear(health_cli, &ctx, cid, test_id, faults, fault_count); -} - -int bt_mesh_health_fault_clear_unack(uint16_t addr, uint16_t app_idx, - uint16_t cid) -{ - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(app_idx, addr); - - return bt_mesh_health_cli_fault_clear_unack(health_cli, &ctx, cid); -} - -int bt_mesh_health_fault_get(uint16_t addr, uint16_t app_idx, uint16_t cid, - uint8_t *test_id, uint8_t *faults, - size_t *fault_count) -{ - struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(app_idx, addr); - - return bt_mesh_health_cli_fault_get(health_cli, &ctx, cid, test_id, faults, fault_count); -} - int bt_mesh_health_cli_attention_get(struct bt_mesh_health_cli *cli, struct bt_mesh_msg_ctx *ctx, uint8_t *attention) { @@ -489,19 +402,6 @@ void bt_mesh_health_cli_timeout_set(int32_t timeout) msg_timeout = timeout; } -int bt_mesh_health_cli_set(struct bt_mesh_model *model) -{ - if (!model->user_data) { - LOG_ERR("No Health Client context for given model"); - return -EINVAL; - } - - health_cli = model->user_data; - msg_timeout = CONFIG_BT_MESH_HEALTH_CLI_TIMEOUT; - - return 0; -} - static int health_cli_init(struct bt_mesh_model *model) { struct bt_mesh_health_cli *cli = model->user_data; @@ -514,7 +414,6 @@ static int health_cli_init(struct bt_mesh_model *model) } cli->model = model; - health_cli = cli; msg_timeout = CONFIG_BT_MESH_HEALTH_CLI_TIMEOUT; cli->pub.msg = &cli->pub_buf; diff --git a/subsys/bluetooth/mesh/health_srv.c b/subsys/bluetooth/mesh/health_srv.c index 8ea2ec4398c7..bfab40b6ef96 100644 --- a/subsys/bluetooth/mesh/health_srv.c +++ b/subsys/bluetooth/mesh/health_srv.c @@ -384,11 +384,6 @@ static int health_pub_update(struct bt_mesh_model *mod) return 0; } -int bt_mesh_fault_update(struct bt_mesh_elem *elem) -{ - return bt_mesh_health_srv_fault_update(elem); -} - int bt_mesh_health_srv_fault_update(struct bt_mesh_elem *elem) { struct bt_mesh_model *mod; From e990ab941ddd9df894d73d75a9c12eae97a81f07 Mon Sep 17 00:00:00 2001 From: Troels Nilsson Date: Thu, 24 Nov 2022 10:50:58 +0100 Subject: [PATCH 0615/1906] Bluetooth: controller: Add option for ticker to return expiration info It is now possible (via the extended ticker interface) to ask for expiration information for another ticker ID to be returned in the ticker callback. This utilises the extended ticker interface and a callback function with a different context to keep the current ticker interface as unchanged as possible. Signed-off-by: Troels Nilsson --- subsys/bluetooth/controller/ticker/ticker.c | 459 ++++++++++++++++++-- subsys/bluetooth/controller/ticker/ticker.h | 45 +- 2 files changed, 463 insertions(+), 41 deletions(-) diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index 5f3b69ee77d7..65808c74d249 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -21,6 +21,24 @@ ****************************************************************************/ #define DOUBLE_BUFFER_SIZE 2 +#if defined(CONFIG_BT_TICKER_EXT) +#if !defined(CONFIG_BT_CTLR_ADV_AUX_SET) +#define BT_CTLR_ADV_AUX_SET 0 +#else +#define BT_CTLR_ADV_AUX_SET CONFIG_BT_CTLR_ADV_AUX_SET +#endif +#if !defined(CONFIG_BT_CTLR_ADV_SYNC_SET) +#define BT_CTLR_ADV_SYNC_SET 0 +#else +#define BT_CTLR_ADV_SYNC_SET CONFIG_BT_CTLR_ADV_SYNC_SET +#endif +#if defined(CONFIG_BT_CTLR_ADV_ISO) +#define TICKER_EXPIRE_INFO_MAX (BT_CTLR_ADV_AUX_SET + BT_CTLR_ADV_SYNC_SET*2) +#else +#define TICKER_EXPIRE_INFO_MAX (BT_CTLR_ADV_AUX_SET + BT_CTLR_ADV_SYNC_SET) +#endif /* !CONFIG_BT_CTLR_ADV_ISO */ +#endif /* CONFIG_BT_TICKER_EXT */ + /***************************************************************************** * Types ****************************************************************************/ @@ -70,11 +88,11 @@ struct ticker_node { */ }; -#if !defined(CONFIG_BT_TICKER_LOW_LAT) && \ - !defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) #if defined(CONFIG_BT_TICKER_EXT) struct ticker_ext *ext_data; /* Ticker extension data */ #endif /* CONFIG_BT_TICKER_EXT */ +#if !defined(CONFIG_BT_TICKER_LOW_LAT) && \ + !defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) uint8_t must_expire; /* Node must expire, even if it * collides with other nodes */ @@ -89,6 +107,16 @@ struct ticker_node { */ }; +struct ticker_expire_info_internal { + uint32_t ticks_to_expire; + uint32_t remainder; + uint16_t lazy; + uint8_t ticker_id; + uint8_t outdated:1; + uint8_t found:1; + uint8_t last:1; +}; + /* Operations to be performed in ticker_job. * Possible values for field "op" in struct ticker_user_op */ @@ -107,7 +135,7 @@ struct ticker_node { #define TICKER_RESCHEDULE_STATE_PENDING 1 #define TICKER_RESCHEDULE_STATE_DONE 2 -#if defined(CONFIG_BT_TICKER_EXT) +#if defined(CONFIG_BT_TICKER_EXT) && !defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) #define TICKER_RESCHEDULE_PENDING(_ticker) \ (_ticker->ext_data && (_ticker->ext_data->reschedule_state == \ TICKER_RESCHEDULE_STATE_PENDING)) @@ -156,7 +184,8 @@ struct ticker_user_op_update { * >1: latency = lazy - 1 */ uint8_t force; /* Force update */ -#if defined(CONFIG_BT_TICKER_EXT) +#if defined(CONFIG_BT_TICKER_EXT) && !defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) &&\ + !defined(CONFIG_BT_TICKER_LOW_LAT) uint8_t must_expire; /* Node must expire, even if it * collides with other nodes: * 0x00: Do nothing @@ -164,6 +193,9 @@ struct ticker_user_op_update { * 0x02: Enable must_expire */ #endif +#if defined(CONFIG_BT_TICKER_EXT) + uint8_t expire_info_id; +#endif }; /* User operation data structure for yield/stop opcode. Used for passing yield/ @@ -271,6 +303,10 @@ struct ticker_instance { */ #endif /* !CONFIG_BT_TICKER_SLOT_AGNOSTIC */ +#if defined(CONFIG_BT_TICKER_EXT) + struct ticker_expire_info_internal expire_infos[TICKER_EXPIRE_INFO_MAX]; + bool expire_infos_outdated; +#endif /* CONFIG_BT_TICKER_EXT */ ticker_caller_id_get_cb_t caller_id_get_cb; /* Function for retrieving * the caller id from user @@ -300,6 +336,8 @@ static struct ticker_instance _instance[TICKER_INSTANCE_MAX]; * Static Functions ****************************************************************************/ +static inline uint8_t ticker_add_to_remainder(uint32_t *remainder, uint32_t to_add); + /** * @brief Update elapsed index * @@ -905,6 +943,181 @@ static uint8_t ticker_resolve_collision(struct ticker_node *nodes, * !CONFIG_BT_TICKER_SLOT_AGNOSTIC */ +#if defined(CONFIG_BT_TICKER_EXT) +/** + * @brief Get expiration delta from one ticker id to another ticker id + * + * @details Helper function to get expiration info between two tickers + * + * @param instance Ticker instance + * @param to_ticker_id Target ticker id + * @param from_ticker_id Ticker id to compare with + * @param expire_info Pointer to ticker_expire_info that will + * get populated with the result + * + * @internal + */ +static void ticker_get_expire_info(struct ticker_instance *instance, uint8_t to_ticker_id, + uint8_t from_ticker_id, + struct ticker_expire_info_internal *expire_info) +{ + struct ticker_node *current_node; + uint32_t acc_ticks_to_expire = 0; + uint8_t current_ticker_id; + uint32_t from_ticks = 0; + bool from_found = false; + uint32_t to_ticks = 0; + bool to_found = false; + + current_ticker_id = instance->ticker_id_head; + current_node = &instance->nodes[instance->ticker_id_head]; + while (current_ticker_id != TICKER_NULL && (!to_found || !from_found)) { + /* Accumulate expire ticks */ + acc_ticks_to_expire += current_node->ticks_to_expire; + + if (current_ticker_id == from_ticker_id) { + from_ticks = acc_ticks_to_expire; + from_found = true; + } else if (current_ticker_id == to_ticker_id) { + to_ticks = acc_ticks_to_expire; + to_found = true; + } + + current_ticker_id = current_node->next; + current_node = &instance->nodes[current_ticker_id]; + } + + if (to_found && from_found) { + struct ticker_node *to_ticker = &instance->nodes[to_ticker_id]; + uint32_t to_remainder = to_ticker->remainder_current; + + if (from_ticks > to_ticks) { + /* from ticker is scheduled after the to ticker - use period + * to give an result + */ + if (to_ticker->ticks_periodic == 0) { + /* single shot ticker */ + expire_info->found = 0; + return; + } + while (to_ticks < from_ticks) { + to_ticks += to_ticker->ticks_periodic; + to_ticks += ticker_add_to_remainder(&to_remainder, + to_ticker->remainder_periodic); + } + } + + expire_info->ticks_to_expire = to_ticks - from_ticks; + expire_info->remainder = to_remainder; + expire_info->lazy = to_ticker->lazy_current; + expire_info->found = 1; + } else { + expire_info->found = 0; + } +} + +/** + * @brief Allocate an expire info for the given ticker ID + * + * @param instance Ticker instance + * @param ticker_id Ticker ID to allocate for + * + * @return Returns TICKER_STATUS_SUCCESS if the allocation succeeded, + * TICKER_STATUS_FAILURE otherwise + * + * @internal + */ +static uint32_t ticker_alloc_expire_info(struct ticker_instance *instance, uint8_t ticker_id) +{ + uint32_t status = TICKER_STATUS_FAILURE; + uint8_t is_last = 0; + + for (int i = 0; i < TICKER_EXPIRE_INFO_MAX; i++) { + if (instance->expire_infos[i].ticker_id == TICKER_NULL) { + struct ticker_node *ticker = &instance->nodes[ticker_id]; + + instance->expire_infos[i].ticker_id = ticker_id; + instance->expire_infos[i].outdated = true; + instance->expire_infos[i].last = is_last; + ticker->ext_data->other_expire_info = &instance->expire_infos[i]; + instance->expire_infos_outdated = true; + status = TICKER_STATUS_SUCCESS; + break; + } else if (instance->expire_infos[i].last && i < TICKER_EXPIRE_INFO_MAX - 1) { + instance->expire_infos[i].last = 0; + is_last = 1; + } + } + + return status; +} + +/** + * @brief Free a previously allocated expire info for the given ticker ID + * + * @param instance Ticker instance + * @param ticker_id Ticker ID to free up the allocation for + * + * @internal + */ +static void ticker_free_expire_info(struct ticker_instance *instance, uint8_t ticker_id) +{ + uint8_t is_last = 0; + uint8_t index; + + for (index = 0; index < TICKER_EXPIRE_INFO_MAX; index++) { + if (instance->expire_infos[index].ticker_id == ticker_id) { + instance->expire_infos[index].ticker_id = TICKER_NULL; + is_last = instance->expire_infos[index].last; + instance->expire_infos[index].last = 0; + break; + } + } + + if (is_last) { + /* Find new last used element and mark it */ + for (; index >= 0; index--) { + if (instance->expire_infos[index].ticker_id != TICKER_NULL || index == 0) { + instance->expire_infos[index].last = 1; + break; + } + } + } +} + +/** + * @brief Mark all expire infos involving a ticker ID as outdated + * + * @details If a ticker moves this function should be called to mark all expiration + * infos (if any) that involve that ticker as outdated and in need of re-calculation. + * If any expiration infos involving the ticker_id is found, the ticker instances + * expire_infos_outdated flag is also set. + * + * @param instance Ticker instance + * @param ticker_id ID of ticker that has moved + * + * @internal + */ +static void ticker_mark_expire_info_outdated(struct ticker_instance *instance, uint8_t ticker_id) +{ + for (int i = 0; i < TICKER_EXPIRE_INFO_MAX; i++) { + if (instance->expire_infos[i].ticker_id != TICKER_NULL) { + uint8_t current_id = instance->expire_infos[i].ticker_id; + struct ticker_node *ticker = &instance->nodes[current_id]; + + if (current_id == ticker_id || + ticker->ext_data->expire_info_id == ticker_id) { + instance->expire_infos[i].outdated = true; + instance->expire_infos_outdated = true; + } + } + if (instance->expire_infos[i].last) { + break; + } + } +} +#endif /* CONFIG_BT_TICKER_EXT */ + /** * @brief Ticker worker * @@ -1064,7 +1277,11 @@ void ticker_worker(void *param) /* Scheduled timeout is acknowledged to be complete */ ticker->ack--; - if (ticker->timeout_func) { + if (ticker->timeout_func +#if defined(CONFIG_BT_TICKER_EXT) + || (ticker->ext_data && ticker->ext_data->ext_timeout_func) +#endif /* CONFIG_BT_TICKER_EXT */ + ) { uint32_t ticks_at_expire; ticks_at_expire = (instance->ticks_current + @@ -1072,9 +1289,43 @@ void ticker_worker(void *param) ticker->ticks_to_expire_minus) & HAL_TICKER_CNTR_MASK; +#if defined(CONFIG_BT_TICKER_EXT) +#endif /* CONFIG_BT_TICKER_EXT */ DEBUG_TICKER_TASK(1); /* Invoke the timeout callback */ - ticker->timeout_func(ticks_at_expire, + +#if defined(CONFIG_BT_TICKER_EXT) + if (ticker->ext_data && ticker->ext_data->ext_timeout_func) { + struct ticker_expire_info_internal *expire_info; + struct ticker_ext_context ext_context; + ticker_timeout_func timeout_func; + + timeout_func = ticker->ext_data->ext_timeout_func; + expire_info = ticker->ext_data->other_expire_info; + + if (ticker->ext_data->expire_info_id != TICKER_NULL) { + LL_ASSERT(expire_info && !expire_info->outdated); + } + + ext_context.context = ticker->context; + if (expire_info && expire_info->found) { + ext_context.other_expire_info = (void *)expire_info; + } else { + ext_context.other_expire_info = NULL; + } + + timeout_func(ticks_at_expire, + ticks_drift, + ticker->remainder_current, + must_expire_skip ? + TICKER_LAZY_MUST_EXPIRE : + ticker->lazy_current, + ticker->force, + &ext_context); + } else +#endif /* CONFIG_BT_TICKER_EXT */ + { + ticker->timeout_func(ticks_at_expire, ticks_drift, ticker->remainder_current, must_expire_skip ? @@ -1082,6 +1333,7 @@ void ticker_worker(void *param) ticker->lazy_current, ticker->force, ticker->context); + } DEBUG_TICKER_TASK(0); if (!IS_ENABLED(CONFIG_BT_TICKER_LOW_LAT) && @@ -1181,25 +1433,28 @@ static void ticks_to_expire_prep(struct ticker_node *ticker, } /** - * @brief Increment remainder + * @brief Add to remainder * * @details Calculates whether the remainder should increments expiration time * for above-microsecond precision counter HW. The remainder enables improved * ticker precision, but is disabled for for sub-microsecond precision * configurations. + * Note: This is the same functionality as ticker_remainder_inc(), except this + * function allows doing the calculation without modifying any tickers * - * @param ticker Pointer to ticker node + * @param remainder Pointer to remainder to add to + * @param to_add Remainder value to add * - * @return Returns 1 to indicate increment is due, otherwise 0 + * @return Returns 1 to indicate ticks increment is due, otherwise 0 * @internal */ -static uint8_t ticker_remainder_inc(struct ticker_node *ticker) +static inline uint8_t ticker_add_to_remainder(uint32_t *remainder, uint32_t to_add) { #ifdef HAL_TICKER_REMAINDER_RANGE - ticker->remainder_current += ticker->remainder_periodic; - if ((ticker->remainder_current < BIT(31)) && - (ticker->remainder_current > (HAL_TICKER_REMAINDER_RANGE >> 1))) { - ticker->remainder_current -= HAL_TICKER_REMAINDER_RANGE; + *remainder += to_add; + if ((*remainder < BIT(31)) && + (*remainder > (HAL_TICKER_REMAINDER_RANGE >> 1))) { + *remainder -= HAL_TICKER_REMAINDER_RANGE; return 1; } return 0; @@ -1208,6 +1463,24 @@ static uint8_t ticker_remainder_inc(struct ticker_node *ticker) #endif } +/** + * @brief Increment remainder + * + * @details Calculates whether the remainder should increments expiration time + * for above-microsecond precision counter HW. The remainder enables improved + * ticker precision, but is disabled for for sub-microsecond precision + * configurations. + * + * @param ticker Pointer to ticker node + * + * @return Returns 1 to indicate increment is due, otherwise 0 + * @internal + */ +static uint8_t ticker_remainder_inc(struct ticker_node *ticker) +{ + return ticker_add_to_remainder(&ticker->remainder_current, ticker->remainder_periodic); +} + /** * @brief Decrement remainder * @@ -1269,7 +1542,8 @@ static void ticker_job_op_cb(struct ticker_user_op *user_op, uint8_t status) * from user operation upon exit * @internal */ -static inline void ticker_job_node_update(struct ticker_node *ticker, +static inline uint32_t ticker_job_node_update(struct ticker_instance *instance, + struct ticker_node *ticker, struct ticker_user_op *user_op, uint32_t ticks_now, uint32_t ticks_current, @@ -1312,7 +1586,7 @@ static inline void ticker_job_node_update(struct ticker_node *ticker, ticker->ticks_to_expire_minus += user_op->params.update.ticks_drift_minus; -#if defined(CONFIG_BT_TICKER_EXT) +#if defined(CONFIG_BT_TICKER_EXT) && !defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) /* TODO: An improvement on this could be to only consider the drift * (ADV => randomization) if re-sceduling fails. We would still store * the drift ticks here, but not actually update the node. That would @@ -1325,7 +1599,7 @@ static inline void ticker_job_node_update(struct ticker_node *ticker, user_op->params.update.ticks_drift_plus - user_op->params.update.ticks_drift_minus; } -#endif /* CONFIG_BT_TICKER_EXT */ +#endif /* CONFIG_BT_TICKER_EXT && !CONFIG_BT_TICKER_SLOT_AGNOSTIC */ ticks_to_expire_prep(ticker, ticks_current, ticks_now); @@ -1344,7 +1618,8 @@ static inline void ticker_job_node_update(struct ticker_node *ticker, ticker->force = user_op->params.update.force; } -#if defined(CONFIG_BT_TICKER_EXT) +#if defined(CONFIG_BT_TICKER_EXT) && !defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) &&\ + !defined(CONFIG_BT_TICKER_LOW_LAT) /* Update must_expire parameter */ if (user_op->params.update.must_expire) { /* 1: disable, 2: enable */ @@ -1352,8 +1627,33 @@ static inline void ticker_job_node_update(struct ticker_node *ticker, } #endif /* CONFIG_BT_TICKER_EXT */ +#if defined(CONFIG_BT_TICKER_EXT) + if (ticker->ext_data && user_op->params.update.expire_info_id != user_op->id) { + if (user_op->params.update.expire_info_id != TICKER_NULL && + !ticker->ext_data->other_expire_info) { + uint32_t status; + + status = ticker_alloc_expire_info(instance, user_op->id); + if (status) { + return status; + } + } else if (user_op->params.update.expire_info_id == TICKER_NULL && + ticker->ext_data->other_expire_info) { + ticker_free_expire_info(instance, user_op->id); + ticker->ext_data->other_expire_info = NULL; + } + + ticker->ext_data->expire_info_id = user_op->params.update.expire_info_id; + if (ticker->ext_data->expire_info_id != TICKER_NULL) { + ticker_mark_expire_info_outdated(instance, user_op->id); + } + } +#endif + ticker->next = *insert_head; *insert_head = user_op->id; + + return TICKER_STATUS_SUCCESS; } /** @@ -1385,10 +1685,14 @@ static inline void ticker_job_node_manage(struct ticker_instance *instance, ticker->ticks_to_expire = ticker_dequeue(instance, user_op->id); /* Update node and insert back */ - ticker_job_node_update(ticker, user_op, ticks_now, + ticker_job_node_update(instance, ticker, user_op, ticks_now, instance->ticks_current, ticks_elapsed, insert_head); +#if defined(CONFIG_BT_TICKER_EXT) + ticker_mark_expire_info_outdated(instance, user_op->id); +#endif /* CONFIG_BT_TICKER_EXT */ + /* Set schedule status of node * as updating. */ @@ -1400,6 +1704,15 @@ static inline void ticker_job_node_manage(struct ticker_instance *instance, ticker->ticks_to_expire = ticker_dequeue(instance, user_op->id); +#if defined(CONFIG_BT_TICKER_EXT) + if (ticker->ext_data && ticker->ext_data->expire_info_id != TICKER_NULL) { + ticker_free_expire_info(instance, user_op->id); + ticker->ext_data->other_expire_info = NULL; + } + + ticker_mark_expire_info_outdated(instance, user_op->id); +#endif /* CONFIG_BT_TICKER_EXT */ + /* Reset schedule status of node */ ticker->req = ticker->ack; } @@ -1536,6 +1849,10 @@ static inline uint8_t ticker_job_list_manage(struct ticker_instance *instance, (user_op->params.update.ticks_slot_plus == 0U) && (user_op->params.update.ticks_slot_minus == 0U) && #endif /* CONFIG_BT_TICKER_SLOT_AGNOSTIC */ +#if defined(CONFIG_BT_TICKER_EXT) + (!ticker->ext_data || + user_op->params.update.expire_info_id == user_op->id) && +#endif /* CONFIG_BT_TICKER_EXT */ (user_op->params.update.lazy == 0U) && (user_op->params.update.force == 0U))) { ticker_job_op_cb(user_op, @@ -1660,6 +1977,10 @@ static inline void ticker_job_worker_bh(struct ticker_instance *instance, /* ticker expired, set ticks_to_expire zero */ ticker->ticks_to_expire = 0U; +#if defined(CONFIG_BT_TICKER_EXT) + ticker_mark_expire_info_outdated(instance, instance->ticker_id_head); +#endif + /* remove the expired ticker from head */ instance->ticker_id_head = ticker->next; @@ -1794,9 +2115,10 @@ static inline void ticker_job_worker_bh(struct ticker_instance *instance, * * @internal */ -static inline void ticker_job_op_start(struct ticker_node *ticker, - struct ticker_user_op *user_op, - uint32_t ticks_current) +static inline uint32_t ticker_job_op_start(struct ticker_instance *instance, + struct ticker_node *ticker, + struct ticker_user_op *user_op, + uint32_t ticks_current) { struct ticker_user_op_start *start = (void *)&user_op->params.start; @@ -1811,10 +2133,24 @@ static inline void ticker_job_op_start(struct ticker_node *ticker, (start->lazy == TICKER_LAZY_MUST_EXPIRE) ? 1U : 0U; } #endif /* !CONFIG_BT_TICKER_SLOT_AGNOSTIC */ +#endif /* CONFIG_BT_TICKER_LOW_LAT */ #if defined(CONFIG_BT_TICKER_EXT) ticker->ext_data = start->ext_data; + if (ticker->ext_data) { + ticker->ext_data->other_expire_info = NULL; + if (ticker->ext_data->ext_timeout_func && + ticker->ext_data->expire_info_id != TICKER_NULL) { + uint32_t status; + + status = ticker_alloc_expire_info(instance, user_op->id); + if (status) { + return status; + } + } + } + + ticker_mark_expire_info_outdated(instance, user_op->id); #endif /* CONFIG_BT_TICKER_EXT */ -#endif /* CONFIG_BT_TICKER_LOW_LAT */ ticker->ticks_periodic = start->ticks_periodic; ticker->remainder_periodic = start->remainder_periodic; @@ -1832,6 +2168,8 @@ static inline void ticker_job_op_start(struct ticker_node *ticker, ticker->remainder_current = 0U; ticker->lazy_current = 0U; ticker->force = 1U; + + return TICKER_STATUS_SUCCESS; } #if !defined(CONFIG_BT_TICKER_LOW_LAT) @@ -1869,7 +2207,7 @@ static inline uint8_t ticker_job_insert(struct ticker_instance *instance, return TICKER_STATUS_SUCCESS; } -#if defined(CONFIG_BT_TICKER_EXT) +#if defined(CONFIG_BT_TICKER_EXT) && !defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) /** * @brief Re-schedule ticker nodes within slot_window * @@ -2073,6 +2411,8 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, ext_data->reschedule_state = TICKER_RESCHEDULE_STATE_DONE; + ticker_mark_expire_info_outdated(instance, ticker_id_head); + /* Check for other pending re-schedules and set exit flag */ rescheduling = 1U; rescheduled = 1U; @@ -2080,7 +2420,7 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, return rescheduled; } -#endif /* CONFIG_BT_TICKER_EXT */ +#endif /* CONFIG_BT_TICKER_EXT && !CONFIG_BT_TICKER_SLOT_AGNOSTIC */ #else /* !CONFIG_BT_TICKER_LOW_LAT */ /** @@ -2234,7 +2574,7 @@ static inline void ticker_job_list_insert(struct ticker_instance *instance, struct ticker_user_op *user_op; struct ticker_node *ticker; uint8_t id_insert; - uint8_t status; + uint8_t status = TICKER_STATUS_SUCCESS; if (insert_head != TICKER_NULL) { /* Prepare insert of ticker node specified by @@ -2275,13 +2615,15 @@ static inline void ticker_job_list_insert(struct ticker_instance *instance, } /* Prepare ticker for start */ - ticker_job_op_start(ticker, user_op, + status = ticker_job_op_start(instance, ticker, user_op, instance->ticks_current); } - /* Insert ticker node */ - status = ticker_job_insert(instance, id_insert, ticker, - &insert_head); + if (!status) { + /* Insert ticker node */ + status = ticker_job_insert(instance, id_insert, ticker, + &insert_head); + } if (user_op) { ticker_job_op_cb(user_op, status); @@ -2525,6 +2867,40 @@ ticker_job_compare_update(struct ticker_instance *instance, return 0U; } +#if defined(CONFIG_BT_TICKER_EXT) +/** + * @brief Run through all expire infos and update them if needed + * + * @details Runs through all expire_infos and runs ticker_get_expire_info() + * for any that are marked as outdated. Clears the expire_infos_outdated + * flag when done + * + * @param param Pointer to ticker instance + * + * @internal + */ +static void ticker_job_update_expire_infos(struct ticker_instance *instance) +{ + for (int i = 0; i < TICKER_EXPIRE_INFO_MAX; i++) { + struct ticker_expire_info_internal *info = &instance->expire_infos[i]; + + if (info->ticker_id != TICKER_NULL && info->outdated) { + struct ticker_node *ticker = &instance->nodes[info->ticker_id]; + + ticker_get_expire_info(instance, ticker->ext_data->expire_info_id, + info->ticker_id, info); + info->outdated = false; + } + + if (info->last) { + break; + } + } + + instance->expire_infos_outdated = false; +} +#endif /* CONFIG_BT_TICKER_EXT */ + /** * @brief Ticker job * @@ -2622,7 +2998,8 @@ void ticker_job(void *param) /* Handle insertions */ ticker_job_list_insert(instance, insert_head); -#if defined(CONFIG_BT_TICKER_EXT) +#if defined(CONFIG_BT_TICKER_EXT) && !defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) &&\ + !defined(CONFIG_BT_TICKER_LOW_LAT) /* Re-schedule any pending nodes with slot_window */ if (ticker_job_reschedule_in_window(instance, ticks_elapsed)) { flag_compare_update = 1U; @@ -2651,6 +3028,12 @@ void ticker_job(void *param) * CONFIG_BT_TICKER_PRIORITY_SET */ +#if defined(CONFIG_BT_TICKER_EXT) + if (instance->expire_infos_outdated) { + ticker_job_update_expire_infos(instance); + } +#endif /* CONFIG_BT_TICKER_EXT */ + /* update compare if head changed */ if (flag_compare_update) { compare_trigger = ticker_job_compare_update(instance, @@ -2755,6 +3138,13 @@ uint8_t ticker_init(uint8_t instance_index, uint8_t count_node, void *node, instance->ticks_slot_previous = 0U; #endif /* !CONFIG_BT_TICKER_SLOT_AGNOSTIC */ +#if defined(CONFIG_BT_TICKER_EXT) + for (int i = 0; i < TICKER_EXPIRE_INFO_MAX; i++) { + instance->expire_infos[i].ticker_id = TICKER_NULL; + instance->expire_infos[i].last = 1; + } +#endif + return TICKER_STATUS_SUCCESS; } @@ -2944,7 +3334,7 @@ uint8_t ticker_update(uint8_t instance_index, uint8_t user_id, return ticker_update_ext(instance_index, user_id, ticker_id, ticks_drift_plus, ticks_drift_minus, ticks_slot_plus, ticks_slot_minus, lazy, - force, fp_op_func, op_context, 0); + force, fp_op_func, op_context, 0, ticker_id); } uint8_t ticker_update_ext(uint8_t instance_index, uint8_t user_id, @@ -2953,7 +3343,7 @@ uint8_t ticker_update_ext(uint8_t instance_index, uint8_t user_id, uint32_t ticks_slot_plus, uint32_t ticks_slot_minus, uint16_t lazy, uint8_t force, ticker_op_func fp_op_func, void *op_context, - uint8_t must_expire) + uint8_t must_expire, uint8_t expire_info_id) #endif /* CONFIG_BT_TICKER_EXT */ { struct ticker_instance *instance = &_instance[instance_index]; @@ -2984,7 +3374,10 @@ uint8_t ticker_update_ext(uint8_t instance_index, uint8_t user_id, user_op->params.update.lazy = lazy; user_op->params.update.force = force; #if defined(CONFIG_BT_TICKER_EXT) +#if !defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) && !defined(CONFIG_BT_TICKER_LOW_LAT) user_op->params.update.must_expire = must_expire; +#endif /* CONFIG_BT_TICKER_EXT && !CONFIG_BT_TICKER_SLOT_AGNOSTIC && !CONFIG_BT_TICKER_LOW_LAT */ + user_op->params.update.expire_info_id = expire_info_id; #endif /* CONFIG_BT_TICKER_EXT */ user_op->status = TICKER_STATUS_BUSY; user_op->fp_op_func = fp_op_func; diff --git a/subsys/bluetooth/controller/ticker/ticker.h b/subsys/bluetooth/controller/ticker/ticker.h index 25487ff29b80..0b0d0bf88c3b 100644 --- a/subsys/bluetooth/controller/ticker/ticker.h +++ b/subsys/bluetooth/controller/ticker/ticker.h @@ -37,19 +37,23 @@ /** \brief Timer node type size. */ -#if defined(CONFIG_BT_TICKER_LOW_LAT) +#if defined(CONFIG_BT_TICKER_EXT) +#if defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) #define TICKER_NODE_T_SIZE 40 +#elif defined(CONFIG_BT_TICKER_LOW_LAT) +#define TICKER_NODE_T_SIZE 44 #else -#if defined(CONFIG_BT_TICKER_EXT) #define TICKER_NODE_T_SIZE 48 -#else +#endif /* CONFIG_BT_TICKER_SLOT_AGNOSTIC */ +#else /* CONFIG_BT_TICKER_EXT */ #if defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) #define TICKER_NODE_T_SIZE 36 +#elif defined(CONFIG_BT_TICKER_LOW_LAT) +#define TICKER_NODE_T_SIZE 40 #else #define TICKER_NODE_T_SIZE 44 #endif /* CONFIG_BT_TICKER_SLOT_AGNOSTIC */ #endif /* CONFIG_BT_TICKER_EXT */ -#endif /* CONFIG_BT_TICKER_LOW_LAT */ /** \brief Timer user type size. */ @@ -58,7 +62,11 @@ /** \brief Timer user operation type size. */ #if defined(CONFIG_BT_TICKER_EXT) +#if defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) +#define TICKER_USER_OP_T_SIZE 44 +#else #define TICKER_USER_OP_T_SIZE 48 +#endif /* CONFIG_BT_TICKER_SLOT_AGNOSTIC */ #else #if defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) #define TICKER_USER_OP_T_SIZE 40 @@ -101,6 +109,18 @@ typedef void (*ticker_timeout_func) (uint32_t ticks_at_expire, uint16_t lazy, uint8_t force, void *context); + +struct ticker_expire_info { + uint32_t ticks_to_expire; + uint32_t remainder; + uint16_t lazy; +}; + +struct ticker_ext_context { + void *context; + struct ticker_expire_info *other_expire_info; +}; + /** \brief Timer operation complete function type. */ typedef void (*ticker_op_func) (uint32_t status, void *op_context); @@ -173,8 +193,13 @@ uint32_t ticker_ticks_diff_get(uint32_t ticks_now, uint32_t ticks_old); uint8_t ticker_priority_set(uint8_t instance_index, uint8_t user_id, uint8_t ticker_id, int8_t priority, ticker_op_func fp_op_func, void *op_context); +#endif /* !CONFIG_BT_TICKER_LOW_LAT && !CONFIG_BT_TICKER_SLOT_AGNOSTIC */ + #if defined(CONFIG_BT_TICKER_EXT) struct ticker_ext { + ticker_timeout_func ext_timeout_func; + +#if !defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) uint32_t ticks_slot_window;/* Window in which the slot * reservation may be re-scheduled * to avoid collision @@ -184,6 +209,13 @@ struct ticker_ext { * node. See defines * TICKER_RESCHEDULE_STATE_XXX */ +#endif /* CONFIG_BT_TICKER_SLOT_AGNOSTIC */ + uint8_t expire_info_id; /* Other ticker ID for which + * the ext_timeout_func should include expire + * info for + * Set to TICKER_NULL if not used + */ + void *other_expire_info; }; uint8_t ticker_start_ext(uint8_t instance_index, uint8_t user_id, @@ -200,8 +232,5 @@ uint8_t ticker_update_ext(uint8_t instance_index, uint8_t user_id, uint32_t ticks_slot_plus, uint32_t ticks_slot_minus, uint16_t lazy, uint8_t force, ticker_op_func fp_op_func, void *op_context, - uint8_t must_expire); + uint8_t must_expire, uint8_t expire_info_id); #endif /* CONFIG_BT_TICKER_EXT */ -#endif /* !CONFIG_BT_TICKER_LOW_LAT && - * !CONFIG_BT_TICKER_SLOT_AGNOSTIC - */ From 714d74b77b1f4bad9df427511a6a1fb1d6b74b6e Mon Sep 17 00:00:00 2001 From: Troels Nilsson Date: Wed, 30 Nov 2022 15:12:56 +0100 Subject: [PATCH 0616/1906] Bluetooth: controller: Use new ticker feature to get offsets Updated the 3 places in extended advertising where the ticker was previously inquired about the expiration of another ticker ID in a separate mayfly (adv_aux, adv_sync and adv_iso). It will now use the new ticker feature where another ticker IDs expiration info will be added to the callback. Channel map updates are now handled in ticker_cb and applied immediately if the ticker is not running Signed-off-by: Troels Nilsson --- subsys/bluetooth/controller/Kconfig | 1 + .../bluetooth/controller/Kconfig.ll_sw_split | 1 - subsys/bluetooth/controller/ll_sw/lll_adv.h | 8 + .../bluetooth/controller/ll_sw/lll_adv_aux.h | 2 + .../bluetooth/controller/ll_sw/lll_adv_iso.h | 2 + .../bluetooth/controller/ll_sw/lll_adv_sync.h | 2 + .../controller/ll_sw/nordic/lll/lll_adv.c | 14 + .../controller/ll_sw/nordic/lll/lll_adv_aux.c | 86 +++--- .../ll_sw/nordic/lll/lll_adv_sync.c | 7 + subsys/bluetooth/controller/ll_sw/ull_adv.c | 93 ++++++- .../bluetooth/controller/ll_sw/ull_adv_aux.c | 255 ++++++++++-------- .../controller/ll_sw/ull_adv_internal.h | 22 +- .../bluetooth/controller/ll_sw/ull_adv_iso.c | 95 ++----- .../bluetooth/controller/ll_sw/ull_adv_sync.c | 220 +++++++-------- .../controller/ll_sw/ull_adv_types.h | 2 - subsys/bluetooth/controller/ticker/ticker.c | 2 +- 16 files changed, 429 insertions(+), 383 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index ef792cf0fb8c..8b80bcae2e3a 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -546,6 +546,7 @@ config BT_CTLR_ADV_EXT depends on BT_CTLR_ADV_EXT_SUPPORT select BT_CTLR_CHAN_SEL_2 if BT_LL_SW_SPLIT && BT_BROADCASTER select BT_CTLR_SCAN_REQ_NOTIFY if BT_LL_SW_SPLIT && BT_BROADCASTER + select BT_TICKER_EXT default y if BT_EXT_ADV help Enable support for Bluetooth 5.0 LE Advertising Extensions in the diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 7971b18c58d4..7bd71a5f9c79 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -833,7 +833,6 @@ config BT_TICKER_NEXT_SLOT_GET_MATCH config BT_TICKER_EXT bool "Ticker extensions" - depends on !BT_TICKER_LOW_LAT && !BT_TICKER_SLOT_AGNOSTIC default y if BT_BROADCASTER help This option enables ticker extensions such as re-scheduling of diff --git a/subsys/bluetooth/controller/ll_sw/lll_adv.h b/subsys/bluetooth/controller/ll_sw/lll_adv.h index 3488071c54e7..cb74ccb93ed6 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_adv.h +++ b/subsys/bluetooth/controller/ll_sw/lll_adv.h @@ -82,6 +82,10 @@ struct lll_adv_iso { uint8_t giv[8]; struct ccm ccm_tx; + /* contains the offset in ticks from the adv_sync pointing to this ISO */ + uint32_t ticks_sync_pdu_offset; + uint16_t iso_lazy; + uint16_t stream_handle[BT_CTLR_ADV_ISO_STREAM_MAX]; }; @@ -111,6 +115,10 @@ struct lll_adv_sync { struct pdu_adv *last_pdu; #endif /* CONFIG_BT_CTLR_ADV_PDU_LINK */ + /* contains the offset in us from adv_aux pointing to this sync */ + uint32_t us_adv_sync_pdu_offset; + uint16_t sync_lazy; + #if defined(CONFIG_BT_CTLR_ADV_ISO) struct lll_adv_iso *iso; uint8_t volatile iso_chm_done_req; diff --git a/subsys/bluetooth/controller/ll_sw/lll_adv_aux.h b/subsys/bluetooth/controller/ll_sw/lll_adv_aux.h index 926a3af517a3..ad6bf6a6f99c 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_adv_aux.h +++ b/subsys/bluetooth/controller/ll_sw/lll_adv_aux.h @@ -12,3 +12,5 @@ extern uint8_t ull_adv_aux_lll_handle_get(struct lll_adv_aux *lll); extern struct pdu_adv_aux_ptr * ull_adv_aux_lll_offset_fill(struct pdu_adv *pdu, uint32_t ticks_offset, uint32_t remainder_us, uint32_t start_us); + +extern void ull_adv_aux_lll_auxptr_fill(struct pdu_adv *pdu, struct lll_adv *lll_adv); diff --git a/subsys/bluetooth/controller/ll_sw/lll_adv_iso.h b/subsys/bluetooth/controller/ll_sw/lll_adv_iso.h index 689ea5286764..7fda6e70056f 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_adv_iso.h +++ b/subsys/bluetooth/controller/ll_sw/lll_adv_iso.h @@ -10,3 +10,5 @@ void lll_adv_iso_create_prepare(void *param); void lll_adv_iso_prepare(void *param); extern struct lll_adv_iso_stream *ull_adv_iso_lll_stream_get(uint16_t handle); + +extern void ull_adv_iso_lll_biginfo_fill(struct pdu_adv *pdu, struct lll_adv_sync *lll_sync); diff --git a/subsys/bluetooth/controller/ll_sw/lll_adv_sync.h b/subsys/bluetooth/controller/ll_sw/lll_adv_sync.h index 25c46889d7f0..661bbe2cd6f8 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_adv_sync.h +++ b/subsys/bluetooth/controller/ll_sw/lll_adv_sync.h @@ -9,3 +9,5 @@ int lll_adv_sync_reset(void); void lll_adv_sync_prepare(void *param); extern uint16_t ull_adv_sync_lll_handle_get(struct lll_adv_sync *lll); + +extern void ull_adv_sync_lll_syncinfo_fill(struct pdu_adv *pdu, struct lll_adv_aux *lll_aux); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c index 984d0642d8b9..69e9cbef8e54 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c @@ -1039,6 +1039,20 @@ static int prepare_cb(struct lll_prepare_param *p) { uint32_t ret; +#if defined(CONFIG_BT_CTLR_ADV_EXT) + if (lll->aux) { + /* fill in aux ptr in pdu */ + ull_adv_aux_lll_auxptr_fill(pdu, lll); + + /* NOTE: as first primary channel PDU does not use remainder, the packet + * timer is started one tick in advance to start the radio with + * microsecond precision, hence compensate for the higher start_us value + * captured at radio start of the first primary channel PDU. + */ + lll->aux->ticks_pri_pdu_offset += 1U; + } +#endif + ret = lll_prepare_done(lll); LL_ASSERT(!ret); } diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c index 784bea71364a..51c8b9066ba6 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c @@ -35,6 +35,7 @@ #include "lll_adv.h" #include "lll_adv_pdu.h" #include "lll_adv_aux.h" +#include "lll_adv_sync.h" #include "lll_filter.h" #include "lll_internal.h" @@ -42,6 +43,8 @@ #include "lll_adv_internal.h" #include "lll_prof_internal.h" +#include "ull_adv_types.h" + #include "hal/debug.h" static int init_reset(void); @@ -107,17 +110,16 @@ static int init_reset(void) static int prepare_cb(struct lll_prepare_param *p) { - struct pdu_adv_com_ext_adv *pri_com_hdr; + struct pdu_adv_com_ext_adv *com_hdr; uint32_t ticks_at_event, ticks_at_start; - struct pdu_adv *pri_pdu, *sec_pdu; - struct pdu_adv_aux_ptr *aux_ptr; - struct pdu_adv_ext_hdr *pri_hdr; + struct ll_adv_aux_set *aux; + struct pdu_adv *pdu; struct lll_adv_aux *lll; struct lll_adv *lll_adv; struct ull_hdr *ull; uint32_t remainder; uint32_t start_us; - uint8_t *pri_dptr; + uint8_t chan_idx; uint8_t phy_s; uint8_t upd; uint32_t aa; @@ -125,55 +127,18 @@ static int prepare_cb(struct lll_prepare_param *p) DEBUG_RADIO_START_A(1); lll = p->param; + aux = HDR_LLL2ULL(lll); /* FIXME: get latest only when primary PDU without Aux PDUs */ upd = 0U; - sec_pdu = lll_adv_aux_data_latest_get(lll, &upd); - LL_ASSERT(sec_pdu); + pdu = lll_adv_aux_data_latest_get(lll, &upd); + LL_ASSERT(pdu); - /* Get reference to primary PDU */ lll_adv = lll->adv; - pri_pdu = lll_adv_data_curr_get(lll_adv); - LL_ASSERT(pri_pdu->type == PDU_ADV_TYPE_EXT_IND); - - /* Get reference to extended header */ - pri_com_hdr = (void *)&pri_pdu->adv_ext_ind; - pri_hdr = (void *)pri_com_hdr->ext_hdr_adv_data; - pri_dptr = pri_hdr->data; - - /* NOTE: We shall be here in auxiliary PDU prepare due to - * aux_ptr flag being set in the extended common header - * flags. Hence, ext_hdr_len is non-zero, an explicit check - * is not needed. - */ - LL_ASSERT(pri_com_hdr->ext_hdr_len); - /* traverse through adv_addr, if present */ - if (pri_hdr->adv_addr) { - pri_dptr += BDADDR_SIZE; - } - - /* traverse through tgt_addr, if present */ - if (pri_hdr->tgt_addr) { - pri_dptr += BDADDR_SIZE; - } - - /* No CTEInfo flag in primary and secondary channel PDU */ - - /* traverse through adi, if present */ - if (pri_hdr->adi) { - pri_dptr += sizeof(struct pdu_adv_adi); - } - - aux_ptr = (void *)pri_dptr; - - /* Abort if no aux_ptr filled */ - if (unlikely(!pri_hdr->aux_ptr || !PDU_ADV_AUX_PTR_OFFSET_GET(aux_ptr))) { - radio_isr_set(lll_isr_early_abort, lll); - radio_disable(); - - return 0; - } + chan_idx = lll_chan_sel_2(lll->data_chan_counter, aux->data_chan_id, + aux->chm[aux->chm_first].data_chan_map, + aux->chm[aux->chm_first].data_chan_count); /* Increment counter used in ULL for channel index calculation */ lll->data_chan_counter++; @@ -200,14 +165,17 @@ static int prepare_cb(struct lll_prepare_param *p) radio_crc_configure(PDU_CRC_POLYNOMIAL, PDU_AC_CRC_IV); - /* Use channel idx in aux_ptr */ - lll_chan_set(aux_ptr->chan_idx); + /* Set the channel index */ + lll_chan_set(chan_idx); /* Set the Radio Tx Packet */ - radio_pkt_tx_set(sec_pdu); + radio_pkt_tx_set(pdu); + + /* Get reference to extended header */ + com_hdr = (void *)&pdu->adv_ext_ind; /* Switch to Rx if connectable or scannable */ - if (pri_com_hdr->adv_mode & (BT_HCI_LE_ADV_PROP_CONN | + if (com_hdr->adv_mode & (BT_HCI_LE_ADV_PROP_CONN | BT_HCI_LE_ADV_PROP_SCAN)) { struct pdu_adv *scan_pdu; @@ -227,7 +195,7 @@ static int prepare_cb(struct lll_prepare_param *p) * into the scan response. */ memcpy(&scan_pdu->adv_ext_ind.ext_hdr.data[ADVA_OFFSET], - &sec_pdu->adv_ext_ind.ext_hdr.data[ADVA_OFFSET], + &pdu->adv_ext_ind.ext_hdr.data[ADVA_OFFSET], BDADDR_SIZE); } @@ -255,9 +223,9 @@ static int prepare_cb(struct lll_prepare_param *p) } #if defined(CONFIG_BT_CTLR_ADV_AUX_PDU_BACK2BACK) - } else if (sec_pdu->adv_ext_ind.ext_hdr_len && - sec_pdu->adv_ext_ind.ext_hdr.aux_ptr) { - lll->last_pdu = sec_pdu; + } else if (pdu->adv_ext_ind.ext_hdr_len && + pdu->adv_ext_ind.ext_hdr.aux_ptr) { + lll->last_pdu = pdu; radio_isr_set(isr_tx_chain, lll); radio_tmr_tifs_set(EVENT_B2B_MAFS_US); @@ -306,6 +274,12 @@ static int prepare_cb(struct lll_prepare_param *p) { uint32_t ret; +#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) + if (pdu->adv_ext_ind.ext_hdr_len && pdu->adv_ext_ind.ext_hdr.sync_info) { + ull_adv_sync_lll_syncinfo_fill(pdu, lll); + } +#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ + ret = lll_prepare_done(lll); LL_ASSERT(!ret); } diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c index abfc94c2c301..4f77e5789635 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c @@ -33,6 +33,7 @@ #include "lll_adv.h" #include "lll_adv_pdu.h" #include "lll_adv_sync.h" +#include "lll_adv_iso.h" #include "lll_df_types.h" #include "lll_internal.h" @@ -247,6 +248,12 @@ static int prepare_cb(struct lll_prepare_param *p) { uint32_t ret; +#if defined(CONFIG_BT_CTLR_ADV_ISO) + if (lll->iso) { + ull_adv_iso_lll_biginfo_fill(pdu, lll); + } +#endif /* CONFIG_BT_CTLR_ADV_ISO */ + ret = lll_prepare_done(lll); LL_ASSERT(!ret); } diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv.c b/subsys/bluetooth/controller/ll_sw/ull_adv.c index 0e2900890453..2ee311691092 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv.c @@ -79,6 +79,7 @@ static uint16_t adv_time_get(struct pdu_adv *pdu, struct pdu_adv *pdu_scan, static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, uint32_t remainder, uint16_t lazy, uint8_t force, void *param); + static void ticker_update_op_cb(uint32_t status, void *param); #if defined(CONFIG_BT_PERIPHERAL) @@ -1277,15 +1278,36 @@ uint8_t ll_adv_enable(uint8_t enable) lll->is_hdcd = !interval && (pdu_adv->type == PDU_ADV_TYPE_DIRECT_IND); if (lll->is_hdcd) { ret_cb = TICKER_STATUS_BUSY; - ret = ticker_start(TICKER_INSTANCE_ID_CTLR, +#if defined(CONFIG_BT_TICKER_EXT) +#if !defined(CONFIG_BT_CTLR_JIT_SCHEDULING) + ll_adv_ticker_ext[handle].ticks_slot_window = 0; +#endif /* CONFIG_BT_CTLR_JIT_SCHEDULING */ + ll_adv_ticker_ext[handle].ext_timeout_func = ticker_cb; + ll_adv_ticker_ext[handle].expire_info_id = TICKER_NULL; + + ret = ticker_start_ext( +#else + ret = ticker_start( +#endif + TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, (TICKER_ID_ADV_BASE + handle), ticks_anchor, 0, (adv->ull.ticks_slot + ticks_slot_overhead), TICKER_NULL_REMAINDER, TICKER_NULL_LAZY, (adv->ull.ticks_slot + ticks_slot_overhead), - ticker_cb, adv, - ull_ticker_status_give, (void *)&ret_cb); +#if defined(CONFIG_BT_TICKER_EXT) + NULL, +#else + ticker_cb, +#endif /* CONFIG_BT_TICKER_EXT */ + adv, + ull_ticker_status_give, (void *)&ret_cb +#if defined(CONFIG_BT_TICKER_EXT) + , + &ll_adv_ticker_ext[handle] +#endif /* CONFIG_BT_TICKER_EXT */ + ); ret = ull_ticker_status_take(ret, &ret_cb); if (ret != TICKER_STATUS_SUCCESS) { goto failure_cleanup; @@ -1467,8 +1489,24 @@ uint8_t ll_adv_enable(uint8_t enable) ret_cb = TICKER_STATUS_BUSY; #if defined(CONFIG_BT_TICKER_EXT) +#if !defined(CONFIG_BT_CTLR_JIT_SCHEDULING) ll_adv_ticker_ext[handle].ticks_slot_window = ULL_ADV_RANDOM_DELAY + ticks_slot; +#endif /* CONFIG_BT_CTLR_JIT_SCHEDULING */ + + ll_adv_ticker_ext[handle].ext_timeout_func = ticker_cb; + +#if defined(CONFIG_BT_CTLR_ADV_EXT) + if (lll->aux) { + uint8_t aux_handle = ull_adv_aux_handle_get(aux); + + ll_adv_ticker_ext[handle].expire_info_id = TICKER_ID_ADV_AUX_BASE + + aux_handle; + } else +#endif /* CONFIG_BT_CTLR_ADV_EXT */ + { + ll_adv_ticker_ext[handle].expire_info_id = TICKER_NULL; + } ret = ticker_start_ext( #else @@ -1489,7 +1527,12 @@ uint8_t ll_adv_enable(uint8_t enable) TICKER_NULL_LAZY, #endif /* !CONFIG_BT_TICKER_LOW_LAT && !CONFIG_BT_CTLR_LOW_LAT */ ticks_slot, - ticker_cb, adv, +#if defined(CONFIG_BT_TICKER_EXT) + NULL, +#else + ticker_cb, +#endif /* CONFIG_BT_TICKER_EXT */ + adv, ull_ticker_status_give, (void *)&ret_cb #if defined(CONFIG_BT_TICKER_EXT) @@ -1722,6 +1765,19 @@ struct ll_adv_set *ull_adv_is_created_get(uint8_t handle) return adv; } + +void ull_adv_aux_created(struct ll_adv_set *adv) +{ + if (adv->lll.aux && adv->is_enabled) { + uint8_t aux_handle = ull_adv_aux_handle_get(HDR_LLL2ULL(adv->lll.aux)); + uint8_t handle = ull_adv_handle_get(adv); + + ticker_update_ext(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, + (TICKER_ID_ADV_BASE + handle), 0, 0, 0, 0, 0, 0, + ticker_update_op_cb, adv, 0, + TICKER_ID_ADV_AUX_BASE + aux_handle); + } +} #endif /* CONFIG_BT_CTLR_ADV_EXT */ uint8_t ull_adv_data_set(struct ll_adv_set *adv, uint8_t len, @@ -2239,7 +2295,12 @@ static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, static memq_link_t link; static struct mayfly mfy = {0, 0, &link, NULL, lll_adv_prepare}; static struct lll_prepare_param p; +#if defined(CONFIG_BT_TICKER_EXT) + struct ticker_ext_context *context = param; + struct ll_adv_set *adv = context->context; +#else struct ll_adv_set *adv = param; +#endif /* CONFIG_BT_TICKER_EXT */ uint32_t random_delay; struct lll_adv *lll; uint32_t ret; @@ -2280,17 +2341,29 @@ static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, p.param = lll; mfy.param = &p; - /* Kick LLL prepare */ - ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, - TICKER_USER_ID_LLL, 0, &mfy); - LL_ASSERT(!ret); - #if defined(CONFIG_BT_CTLR_ADV_EXT) && (CONFIG_BT_CTLR_ADV_AUX_SET > 0) if (adv->lll.aux) { - ull_adv_aux_offset_get(adv); + uint32_t ticks_to_expire; + uint32_t other_remainder; + + LL_ASSERT(context->other_expire_info); + + /* Adjust ticks to expire based on remainder value */ + ticks_to_expire = context->other_expire_info->ticks_to_expire; + other_remainder = context->other_expire_info->remainder; + hal_ticker_remove_jitter(&ticks_to_expire, &other_remainder); + + /* Store the ticks and remainder offset for aux ptr population in LLL */ + adv->lll.aux->ticks_pri_pdu_offset = ticks_to_expire; + adv->lll.aux->us_pri_pdu_offset = other_remainder; } #endif /* CONFIG_BT_CTLR_ADV_EXT && (CONFIG_BT_CTLR_ADV_AUX_SET > 0) */ + /* Kick LLL prepare */ + ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, + TICKER_USER_ID_LLL, 0, &mfy); + LL_ASSERT(!ret); + #if defined(CONFIG_BT_CTLR_JIT_SCHEDULING) adv->ticks_at_expire = ticks_at_expire; adv->delay_at_expire = adv->delay; diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c index dab9282c2125..d2d0a5fa549a 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c @@ -58,14 +58,16 @@ static uint32_t aux_time_get(const struct ll_adv_aux_set *aux, static uint32_t aux_time_min_get(const struct ll_adv_aux_set *aux); static uint8_t aux_time_update(struct ll_adv_aux_set *aux, struct pdu_adv *pdu, struct pdu_adv *pdu_scan); -static void mfy_aux_offset_get(void *param); static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, uint32_t remainder, uint16_t lazy, uint8_t force, void *param); -static void ticker_op_cb(uint32_t status, void *param); static struct ll_adv_aux_set ll_adv_aux_pool[CONFIG_BT_CTLR_ADV_AUX_SET]; static void *adv_aux_free; + +#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) +static struct ticker_ext ll_adv_aux_ticker_ext[CONFIG_BT_CTLR_ADV_AUX_SET]; +#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ #endif /* (CONFIG_BT_CTLR_ADV_AUX_SET > 0) */ static uint16_t did_unique[PDU_ADV_SID_COUNT]; @@ -1397,6 +1399,14 @@ uint8_t ull_adv_aux_chm_update(void) aux->chm[chm_last].data_chan_count = ull_chan_map_get(aux->chm[chm_last].data_chan_map); aux->chm_last = chm_last; + + if (!aux->is_started) { + /* Ticker not started yet, apply new channel map now + * Note that it should be safe to modify chm_first here + * since advertising is not active + */ + aux->chm_first = aux->chm_last; + } } /* TODO: Should failure due to Channel Map Update being already in @@ -1494,6 +1504,7 @@ uint8_t ull_adv_aux_hdr_set_clear(struct ll_adv_set *adv, } lll_aux = &aux->lll; + ull_adv_aux_created(adv); is_aux_new = 1U; } else { @@ -2475,6 +2486,42 @@ uint32_t ull_adv_aux_evt_init(struct ll_adv_aux_set *aux, return ticks_slot_overhead; } +#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) +static void ticker_update_op_cb(uint32_t status, void *param) +{ + LL_ASSERT(status == TICKER_STATUS_SUCCESS || + param == ull_disable_mark_get()); +} + +void ull_adv_sync_started_stopped(struct ll_adv_aux_set *aux) +{ + if (aux->is_started) { + struct lll_adv_sync *lll_sync = aux->lll.adv->sync; + struct ll_adv_sync_set *sync; + uint8_t aux_handle; + + LL_ASSERT(lll_sync); + + sync = HDR_LLL2ULL(lll_sync); + aux_handle = ull_adv_aux_handle_get(aux); + + if (sync->is_started) { + uint8_t sync_handle = ull_adv_sync_handle_get(sync); + + ticker_update_ext(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, + (TICKER_ID_ADV_AUX_BASE + aux_handle), 0, 0, 0, 0, 0, 0, + ticker_update_op_cb, aux, 0, + TICKER_ID_ADV_SYNC_BASE + sync_handle); + } else { + ticker_update_ext(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, + (TICKER_ID_ADV_AUX_BASE + aux_handle), 0, 0, 0, 0, 0, 0, + ticker_update_op_cb, aux, 0, + TICKER_NULL); + } + } +} +#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ + uint32_t ull_adv_aux_start(struct ll_adv_aux_set *aux, uint32_t ticks_anchor, uint32_t ticks_slot_overhead) { @@ -2487,15 +2534,40 @@ uint32_t ull_adv_aux_start(struct ll_adv_aux_set *aux, uint32_t ticks_anchor, aux_handle = ull_adv_aux_handle_get(aux); interval_us = aux->interval * PERIODIC_INT_UNIT_US; +#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) + ll_adv_aux_ticker_ext[aux_handle].ext_timeout_func = ticker_cb; + if (aux->lll.adv->sync) { + struct ll_adv_sync_set *sync = HDR_LLL2ULL(aux->lll.adv->sync); + uint8_t sync_handle = ull_adv_sync_handle_get(sync); + + ll_adv_aux_ticker_ext[aux_handle].expire_info_id = TICKER_ID_ADV_SYNC_BASE + + sync_handle; + } else { + ll_adv_aux_ticker_ext[aux_handle].expire_info_id = TICKER_NULL; + } +#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ + ret_cb = TICKER_STATUS_BUSY; - ret = ticker_start(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, + ret = ticker_start_ext( + TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, (TICKER_ID_ADV_AUX_BASE + aux_handle), ticks_anchor, 0U, HAL_TICKER_US_TO_TICKS(interval_us), HAL_TICKER_REMAINDER(interval_us), TICKER_NULL_LAZY, (aux->ull.ticks_slot + ticks_slot_overhead), - ticker_cb, aux, - ull_ticker_status_give, (void *)&ret_cb); +#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) + NULL, +#else + ticker_cb, +#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ + aux, + ull_ticker_status_give, (void *)&ret_cb, +#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) + &ll_adv_aux_ticker_ext[aux_handle]); +#else + NULL); +#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ + ret = ull_ticker_status_take(ret, &ret_cb); return ret; @@ -2587,23 +2659,6 @@ uint32_t ull_adv_aux_time_get(const struct ll_adv_aux_set *aux, uint8_t pdu_len, return aux_time_get(aux, pdu, pdu_len, pdu_scan_len); } -void ull_adv_aux_offset_get(struct ll_adv_set *adv) -{ - static memq_link_t link; - static struct mayfly mfy = {0, 0, &link, NULL, mfy_aux_offset_get}; - uint32_t ret; - - /* NOTE: Single mayfly instance is sufficient as primary channel PDUs - * use time reservation, and this mayfly shall complete within - * the radio event. Multiple advertising sets do not need - * independent mayfly allocations. - */ - mfy.param = adv; - ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_ULL_LOW, 1, - &mfy); - LL_ASSERT(!ret); -} - struct pdu_adv_aux_ptr *ull_adv_aux_lll_offset_fill(struct pdu_adv *pdu, uint32_t ticks_offset, uint32_t remainder_us, @@ -2955,97 +3010,50 @@ static uint8_t aux_time_update(struct ll_adv_aux_set *aux, struct pdu_adv *pdu, return BT_HCI_ERR_SUCCESS; } -static void mfy_aux_offset_get(void *param) +void ull_adv_aux_lll_auxptr_fill(struct pdu_adv *pdu, struct lll_adv *adv) { + struct lll_adv_aux *lll_aux = adv->aux; struct pdu_adv_aux_ptr *aux_ptr; - struct lll_adv_aux *lll_aux; struct ll_adv_aux_set *aux; - uint32_t ticks_to_expire; uint8_t data_chan_count; uint8_t *data_chan_map; - uint32_t ticks_current; - struct ll_adv_set *adv; - struct pdu_adv *pdu; - uint32_t remainder; - uint8_t ticker_id; - uint8_t retry; - uint8_t id; + uint16_t chan_counter; + uint32_t offset_us; + uint16_t pdu_us; - adv = param; - lll_aux = adv->lll.aux; aux = HDR_LLL2ULL(lll_aux); - ticker_id = TICKER_ID_ADV_AUX_BASE + ull_adv_aux_handle_get(aux); - - id = TICKER_NULL; - ticks_to_expire = 0U; - ticks_current = 0U; - retry = 4U; - do { - uint32_t volatile ret_cb; - uint32_t ticks_previous; - uint32_t ret; - bool success; - - ticks_previous = ticks_current; - - ret_cb = TICKER_STATUS_BUSY; - ret = ticker_next_slot_get_ext(TICKER_INSTANCE_ID_CTLR, - TICKER_USER_ID_ULL_LOW, - &id, &ticks_current, - &ticks_to_expire, &remainder, - NULL, NULL, NULL, - ticker_op_cb, (void *)&ret_cb); - if (ret == TICKER_STATUS_BUSY) { - while (ret_cb == TICKER_STATUS_BUSY) { - ticker_job_sched(TICKER_INSTANCE_ID_CTLR, - TICKER_USER_ID_ULL_LOW); - } - } - - success = (ret_cb == TICKER_STATUS_SUCCESS); - LL_ASSERT(success); - LL_ASSERT((ticks_current == ticks_previous) || retry--); + chan_counter = lll_aux->data_chan_counter; - LL_ASSERT(id != TICKER_NULL); - } while (id != ticker_id); - - /* Adjust ticks to expire based on remainder value */ - hal_ticker_remove_jitter(&ticks_to_expire, &remainder); - - /* Store the ticks offset for population in other advertising primary - * channel PDUs. + /* The offset has to be at least T_MAFS microseconds from the end of packet + * In addition, the offset recorded in the aux ptr has the same requirement and this + * offset is in steps of 30 microseconds; So use the quantized value in check */ - lll_aux->ticks_pri_pdu_offset = ticks_to_expire; + pdu_us = PDU_AC_US(pdu->len, adv->phy_p, adv->phy_flags); + offset_us = HAL_TICKER_TICKS_TO_US(lll_aux->ticks_pri_pdu_offset) + + lll_aux->us_pri_pdu_offset; + if ((offset_us/OFFS_UNIT_30_US)*OFFS_UNIT_30_US < EVENT_MAFS_US + pdu_us) { + struct ll_adv_aux_set *aux = HDR_LLL2ULL(lll_aux); + uint32_t interval_us; - /* NOTE: as first primary channel PDU does not use remainder, the packet - * timer is started one tick in advance to start the radio with - * microsecond precision, hence compensate for the higher start_us value - * captured at radio start of the first primary channel PDU. - */ - lll_aux->ticks_pri_pdu_offset += 1U; + /* Offset too small, point to next aux packet instead */ + interval_us = aux->interval * PERIODIC_INT_UNIT_US; + offset_us = offset_us + interval_us; + lll_aux->ticks_pri_pdu_offset = HAL_TICKER_US_TO_TICKS(offset_us); + lll_aux->us_pri_pdu_offset = offset_us - + HAL_TICKER_TICKS_TO_US(lll_aux->ticks_pri_pdu_offset); + chan_counter++; + } - /* Store the microsecond remainder offset for population in other - * advertising primary channel PDUs. - */ - lll_aux->us_pri_pdu_offset = remainder; + /* Fill the aux offset */ + aux_ptr = ull_adv_aux_lll_offset_fill(pdu, lll_aux->ticks_pri_pdu_offset, + lll_aux->us_pri_pdu_offset, 0U); - /* Fill the aux offset in the first Primary channel PDU */ - /* FIXME: we are in ULL_LOW context, fill offset in LLL context? */ - pdu = lll_adv_data_latest_peek(&adv->lll); - aux_ptr = ull_adv_aux_lll_offset_fill(pdu, ticks_to_expire, remainder, - 0U); - /* Process channel map update, if any */ - if (aux->chm_first != aux->chm_last) { - /* Use channelMapNew */ - aux->chm_first = aux->chm_last; - } - - /* Calculate the radio channel to use */ + /* Calculate and fill the radio channel to use */ data_chan_map = aux->chm[aux->chm_first].data_chan_map; data_chan_count = aux->chm[aux->chm_first].data_chan_count; - aux_ptr->chan_idx = lll_chan_sel_2(lll_aux->data_chan_counter, + aux_ptr->chan_idx = lll_chan_sel_2(chan_counter, aux->data_chan_id, data_chan_map, data_chan_count); } @@ -3057,7 +3065,12 @@ static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, static memq_link_t link; static struct mayfly mfy = {0, 0, &link, NULL, lll_adv_aux_prepare}; static struct lll_prepare_param p; +#if defined(CONFIG_BT_CTLR_ADV_PERIODIC) + struct ticker_ext_context *context = param; + struct ll_adv_aux_set *aux = context->context; +#else struct ll_adv_aux_set *aux = param; +#endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ struct lll_adv_aux *lll; uint32_t ret; uint8_t ref; @@ -3078,33 +3091,57 @@ static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, p.param = lll; mfy.param = &p; - /* Kick LLL prepare */ - ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, - TICKER_USER_ID_LLL, 0, &mfy); - LL_ASSERT(!ret); - #if defined(CONFIG_BT_CTLR_ADV_PERIODIC) struct ll_adv_set *adv; adv = HDR_LLL2ULL(lll->adv); if (adv->lll.sync) { + struct lll_adv_sync *lll_sync = adv->lll.sync; struct ll_adv_sync_set *sync; - sync = HDR_LLL2ULL(adv->lll.sync); + sync = HDR_LLL2ULL(adv->lll.sync); if (sync->is_started) { - sync->aux_remainder = remainder; - ull_adv_sync_offset_get(adv); + uint32_t ticks_to_expire; + uint32_t sync_remainder_us; + + LL_ASSERT(context->other_expire_info); + + /* Reduce a tick for negative remainder and return positive remainder + * value. + */ + ticks_to_expire = context->other_expire_info->ticks_to_expire; + sync_remainder_us = context->other_expire_info->remainder; + hal_ticker_remove_jitter(&ticks_to_expire, &sync_remainder_us); + + /* Add a tick for negative remainder and return positive remainder + * value. + */ + hal_ticker_add_jitter(&ticks_to_expire, &remainder); + + /* Store the offset in us */ + lll_sync->us_adv_sync_pdu_offset = HAL_TICKER_TICKS_TO_US(ticks_to_expire) + + sync_remainder_us - remainder; + + /* store the lazy value */ + lll_sync->sync_lazy = context->other_expire_info->lazy; } } #endif /* CONFIG_BT_CTLR_ADV_PERIODIC */ + /* Process channel map update, if any */ + if (aux->chm_first != aux->chm_last) { + /* Use channelMapNew */ + aux->chm_first = aux->chm_last; + } + + /* Kick LLL prepare */ + ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, + TICKER_USER_ID_LLL, 0, &mfy); + LL_ASSERT(!ret); + DEBUG_RADIO_PREPARE_A(1); } -static void ticker_op_cb(uint32_t status, void *param) -{ - *((uint32_t volatile *)param) = status; -} #else /* !(CONFIG_BT_CTLR_ADV_AUX_SET > 0) */ static int init_reset(void) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h b/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h index ce983350e015..341f010adeb3 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h @@ -107,9 +107,6 @@ struct ll_adv_aux_set *ull_adv_aux_get(uint8_t handle); uint32_t ull_adv_aux_time_get(const struct ll_adv_aux_set *aux, uint8_t pdu_len, uint8_t pdu_scan_len); -/* helper function to schedule a mayfly to get aux offset */ -void ull_adv_aux_offset_get(struct ll_adv_set *adv); - /* Below are BT Spec v5.2, Vol 6, Part B Section 2.3.4 Table 2.12 defined */ #define ULL_ADV_PDU_HDR_FIELD_NONE 0 #define ULL_ADV_PDU_HDR_FIELD_ADVA BIT(0) @@ -165,6 +162,9 @@ void ull_adv_sync_pdu_init(struct pdu_adv *pdu, uint8_t ext_hdr_flags, uint8_t ull_adv_sync_pdu_cte_info_set(struct pdu_adv *pdu, const struct pdu_cte_info *cte_info); #if defined(CONFIG_BT_CTLR_ADV_EXT) +/* notify adv_set that an aux instance has been created for it */ +void ull_adv_aux_created(struct ll_adv_set *adv); + /* helper to get information whether ADI field is avaialbe in extended advertising PDU */ static inline bool ull_adv_sync_pdu_had_adi(const struct pdu_adv *pdu) { @@ -197,6 +197,13 @@ ull_adv_aux_hdr_len_fill(struct pdu_adv_com_ext_adv *com_hdr, uint8_t len) { com_hdr->ext_hdr_len = len - PDU_AC_EXT_HEADER_SIZE_MIN; } + +/* notify adv_aux_set that a sync instance has been started/stopped for it */ +void ull_adv_sync_started_stopped(struct ll_adv_aux_set *aux); + +/* notify adv_sync_set that an iso instance has been created for it */ +void ull_adv_iso_created(struct ll_adv_sync_set *sync); + #endif /* CONFIG_BT_CTLR_ADV_EXT */ /* helper function to get next unique DID value */ @@ -222,6 +229,9 @@ int ull_adv_sync_reset_finalize(void); /* Return ll_adv_sync_set context (unconditional) */ struct ll_adv_sync_set *ull_adv_sync_get(uint8_t handle); +/* Return the sync set handle given the sync set instance */ +uint16_t ull_adv_sync_handle_get(struct ll_adv_sync_set *sync); + /* helper function to release periodic advertising instance */ void ull_adv_sync_release(struct ll_adv_sync_set *sync); @@ -276,9 +286,6 @@ void ull_adv_sync_extra_data_set_clear(void *extra_data_prev, uint16_t hdr_rem_fields, void *data); -/* helper function to schedule a mayfly to get sync offset */ -void ull_adv_sync_offset_get(struct ll_adv_set *adv); - int ull_adv_iso_init(void); int ull_adv_iso_reset(void); @@ -291,9 +298,6 @@ uint8_t ull_adv_iso_chm_update(void); /* helper function to cleanup after channel map update complete */ void ull_adv_iso_chm_complete(struct node_rx_hdr *rx); -/* helper function to schedule a mayfly to get BIG offset */ -void ull_adv_iso_offset_get(struct ll_adv_sync_set *sync); - /* helper function to handle adv ISO done BIG complete events */ void ull_adv_iso_done_complete(struct node_rx_event_done *done); diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index 78afbff27436..a59c132af475 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -62,7 +62,6 @@ static uint32_t adv_iso_start(struct ll_adv_iso_set *adv_iso, uint32_t iso_interval_us); static uint8_t adv_iso_chm_update(uint8_t big_handle); static void adv_iso_chm_complete_commit(struct lll_adv_iso *lll_iso); -static void mfy_iso_offset_get(void *param); static void pdu_big_info_chan_map_phy_set(uint8_t *chm_phy, uint8_t *chan_map, uint8_t phy); static inline struct pdu_big_info *big_info_get(struct pdu_adv *pdu); @@ -72,7 +71,6 @@ static inline void big_info_offset_fill(struct pdu_big_info *bi, static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, uint32_t remainder, uint16_t lazy, uint8_t force, void *param); -static void ticker_op_cb(uint32_t status, void *param); static void ticker_stop_op_cb(uint32_t status, void *param); static void adv_iso_disable(void *param); static void disabled_cb(void *param); @@ -485,6 +483,9 @@ uint8_t ll_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis, /* Associate the ISO instance with a Periodic Advertising */ lll_adv_sync->iso = lll_adv_iso; + /* Notify the sync instance */ + ull_adv_iso_created(HDR_LLL2ULL(lll_adv_sync)); + /* Commit the BIGInfo in the ACAD field of Periodic Advertising */ lll_adv_sync_data_enqueue(lll_adv_sync, ter_idx); @@ -709,18 +710,6 @@ uint8_t ll_adv_iso_by_hci_handle_new(uint8_t hci_handle, uint8_t *handle) } #endif /* CONFIG_BT_CTLR_HCI_ADV_HANDLE_MAPPING */ -void ull_adv_iso_offset_get(struct ll_adv_sync_set *sync) -{ - static memq_link_t link; - static struct mayfly mfy = {0U, 0U, &link, NULL, mfy_iso_offset_get}; - uint32_t ret; - - mfy.param = sync; - ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_ULL_LOW, 1, - &mfy); - LL_ASSERT(!ret); -} - void ull_adv_iso_done_complete(struct node_rx_event_done *done) { struct ll_adv_iso_set *adv_iso; @@ -1063,71 +1052,32 @@ static void adv_iso_chm_complete_commit(struct lll_adv_iso *lll_iso) lll_adv_sync_data_enqueue(lll_sync, ter_idx); } -static void mfy_iso_offset_get(void *param) +void ull_adv_iso_lll_biginfo_fill(struct pdu_adv *pdu, struct lll_adv_sync *lll_sync) { - struct lll_adv_sync *lll_sync; - struct ll_adv_sync_set *sync; struct lll_adv_iso *lll_iso; - uint32_t ticks_to_expire; + uint16_t latency_prepare; struct pdu_big_info *bi; - uint32_t ticks_current; uint64_t payload_count; - struct pdu_adv *pdu; - uint8_t ticker_id; - uint16_t lazy; - uint8_t retry; - uint8_t id; - - sync = param; - lll_sync = &sync->lll; - lll_iso = lll_sync->iso; - ticker_id = TICKER_ID_ADV_ISO_BASE + lll_iso->handle; - id = TICKER_NULL; - ticks_to_expire = 0U; - ticks_current = 0U; - retry = 4U; - do { - uint32_t volatile ret_cb; - uint32_t ticks_previous; - uint32_t ret; - bool success; - - ticks_previous = ticks_current; - - ret_cb = TICKER_STATUS_BUSY; - ret = ticker_next_slot_get_ext(TICKER_INSTANCE_ID_CTLR, - TICKER_USER_ID_ULL_LOW, - &id, &ticks_current, - &ticks_to_expire, NULL, &lazy, - NULL, NULL, - ticker_op_cb, (void *)&ret_cb); - if (ret == TICKER_STATUS_BUSY) { - /* Busy wait until Ticker Job is enabled after any Radio - * event is done using the Radio hardware. Ticker Job - * ISR is disabled during Radio events in LOW_LAT - * feature to avoid Radio ISR latencies. - */ - while (ret_cb == TICKER_STATUS_BUSY) { - ticker_job_sched(TICKER_INSTANCE_ID_CTLR, - TICKER_USER_ID_ULL_LOW); - } - } - - success = (ret_cb == TICKER_STATUS_SUCCESS); - LL_ASSERT(success); - - LL_ASSERT((ticks_current == ticks_previous) || retry--); + lll_iso = lll_sync->iso; - LL_ASSERT(id != TICKER_NULL); - } while (id != ticker_id); + /* Calculate current payload count. If refcount is non-zero, we have called + * prepare and the LLL implementation has incremented latency_prepare already. + * In this case we need to subtract lazy + 1 from latency_prepare + */ + latency_prepare = lll_iso->latency_prepare; + if (ull_ref_get(HDR_LLL2ULL(lll_iso))) { + /* We are in post-prepare. latency_prepare is already + * incremented by lazy + 1 for next event + */ + latency_prepare -= lll_iso->iso_lazy + 1; + } - payload_count = lll_iso->payload_count + ((lll_iso->latency_prepare + - lazy) * lll_iso->bn); + payload_count = lll_iso->payload_count + ((latency_prepare + + lll_iso->iso_lazy) * lll_iso->bn); - pdu = lll_adv_sync_data_latest_peek(lll_sync); bi = big_info_get(pdu); - big_info_offset_fill(bi, ticks_to_expire, 0U); + big_info_offset_fill(bi, lll_iso->ticks_sync_pdu_offset, 0U); bi->payload_count_framing[0] = payload_count; bi->payload_count_framing[1] = payload_count >> 8; bi->payload_count_framing[2] = payload_count >> 16; @@ -1243,11 +1193,6 @@ static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, DEBUG_RADIO_PREPARE_A(1); } -static void ticker_op_cb(uint32_t status, void *param) -{ - *((uint32_t volatile *)param) = status; -} - static void ticker_stop_op_cb(uint32_t status, void *param) { static memq_link_t link; diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c index 4ca059a87e56..c45a545fc510 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_sync.c @@ -51,23 +51,21 @@ static int init_reset(void); static uint8_t adv_type_check(struct ll_adv_set *adv); static inline struct ll_adv_sync_set *sync_acquire(void); static inline void sync_release(struct ll_adv_sync_set *sync); -static inline uint16_t sync_handle_get(struct ll_adv_sync_set *sync); static uint32_t sync_time_get(const struct ll_adv_sync_set *sync, const struct pdu_adv *pdu); static inline uint8_t sync_remove(struct ll_adv_sync_set *sync, struct ll_adv_set *adv, uint8_t enable); static uint8_t sync_chm_update(uint8_t handle); -static void mfy_sync_offset_get(void *param); static inline struct pdu_adv_sync_info *sync_info_get(struct pdu_adv *pdu); static inline void sync_info_offset_fill(struct pdu_adv_sync_info *si, - uint32_t ticks_offset, - uint32_t remainder_us, - uint32_t start_us); + uint32_t offs); +#if defined(CONFIG_BT_CTLR_ADV_ISO) +static struct ticker_ext ll_adv_sync_ticker_ext[CONFIG_BT_CTLR_ADV_SYNC_SET]; +#endif /* CONFIG_BT_CTLR_ADV_ISO */ static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, uint32_t remainder, uint16_t lazy, uint8_t force, void *param); -static void ticker_op_cb(uint32_t status, void *param); static struct ll_adv_sync_set ll_adv_sync_pool[CONFIG_BT_CTLR_ADV_SYNC_SET]; static void *adv_sync_free; @@ -212,6 +210,26 @@ uint8_t ll_adv_sync_param_set(uint8_t handle, uint16_t interval, uint16_t flags) return 0; } +#if defined(CONFIG_BT_CTLR_ADV_ISO) +static void ticker_update_op_cb(uint32_t status, void *param) +{ + LL_ASSERT(status == TICKER_STATUS_SUCCESS || + param == ull_disable_mark_get()); +} + +void ull_adv_iso_created(struct ll_adv_sync_set *sync) +{ + if (sync->lll.iso && sync->is_started) { + uint8_t iso_handle = sync->lll.iso->handle; + uint8_t handle = ull_adv_sync_handle_get(sync); + + ticker_update_ext(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, + (TICKER_ID_ADV_SYNC_BASE + handle), 0, 0, 0, 0, 0, 0, + ticker_update_op_cb, sync, 0, TICKER_ID_ADV_ISO_BASE + iso_handle); + } +} +#endif /* CONFIG_BT_CTLR_ADV_ISO */ + uint8_t ll_adv_sync_ad_data_set(uint8_t handle, uint8_t op, uint8_t len, uint8_t const *const data) { @@ -961,6 +979,9 @@ uint8_t ll_adv_sync_enable(uint8_t handle, uint8_t enable) } aux->is_started = 1U; + } else { + /* notify the auxiliary set */ + ull_adv_sync_started_stopped(HDR_LLL2ULL(lll_aux)); } } @@ -1047,9 +1068,14 @@ struct ll_adv_sync_set *ull_adv_sync_get(uint8_t handle) return &ll_adv_sync_pool[handle]; } +uint16_t ull_adv_sync_handle_get(struct ll_adv_sync_set *sync) +{ + return mem_index_get(sync, ll_adv_sync_pool, sizeof(struct ll_adv_sync_set)); +} + uint16_t ull_adv_sync_lll_handle_get(struct lll_adv_sync *lll) { - return sync_handle_get((void *)lll->hdr.parent); + return ull_adv_sync_handle_get((void *)lll->hdr.parent); } void ull_adv_sync_release(struct ll_adv_sync_set *sync) @@ -1134,17 +1160,38 @@ uint32_t ull_adv_sync_start(struct ll_adv_set *adv, interval_us = (uint32_t)sync->interval * PERIODIC_INT_UNIT_US; - sync_handle = sync_handle_get(sync); + sync_handle = ull_adv_sync_handle_get(sync); + +#if defined(CONFIG_BT_CTLR_ADV_ISO) + ll_adv_sync_ticker_ext[sync_handle].ext_timeout_func = ticker_cb; + if (sync->lll.iso) { + ll_adv_sync_ticker_ext[sync_handle].expire_info_id = + TICKER_ID_ADV_ISO_BASE + sync->lll.iso->handle; + } else { + ll_adv_sync_ticker_ext[sync_handle].expire_info_id = TICKER_NULL; + } +#endif /* CONFIG_BT_CTLR_ADV_ISO */ ret_cb = TICKER_STATUS_BUSY; - ret = ticker_start(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, + ret = ticker_start_ext(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, (TICKER_ID_ADV_SYNC_BASE + sync_handle), ticks_anchor, 0U, HAL_TICKER_US_TO_TICKS(interval_us), HAL_TICKER_REMAINDER(interval_us), TICKER_NULL_LAZY, (sync->ull.ticks_slot + ticks_slot_overhead), - ticker_cb, sync, - ull_ticker_status_give, (void *)&ret_cb); +#if defined(CONFIG_BT_CTLR_ADV_ISO) + NULL, +#else + ticker_cb, +#endif /* CONFIG_BT_CTLR_ADV_ISO */ + sync, + ull_ticker_status_give, (void *)&ret_cb, +#if defined(CONFIG_BT_CTLR_ADV_ISO) + &ll_adv_sync_ticker_ext[sync_handle] +#else + NULL +#endif /* CONFIG_BT_CTLR_ADV_ISO */ + ); ret = ull_ticker_status_take(ret, &ret_cb); return ret; @@ -1175,7 +1222,7 @@ uint8_t ull_adv_sync_time_update(struct ll_adv_sync_set *sync, ret_cb = TICKER_STATUS_BUSY; ret = ticker_update(TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, - (TICKER_ID_ADV_SYNC_BASE + sync_handle_get(sync)), + (TICKER_ID_ADV_SYNC_BASE + ull_adv_sync_handle_get(sync)), 0, 0, ticks_plus, ticks_minus, 0, 0, ull_ticker_status_give, (void *)&ret_cb); ret = ull_ticker_status_take(ret, &ret_cb); @@ -1316,18 +1363,6 @@ void ull_adv_sync_info_fill(struct ll_adv_sync_set *sync, si->evt_cntr = 0U; } -void ull_adv_sync_offset_get(struct ll_adv_set *adv) -{ - static memq_link_t link; - static struct mayfly mfy = {0, 0, &link, NULL, mfy_sync_offset_get}; - uint32_t ret; - - mfy.param = adv; - ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_ULL_LOW, 1, - &mfy); - LL_ASSERT(!ret); -} - void ull_adv_sync_pdu_init(struct pdu_adv *pdu, uint8_t ext_hdr_flags, uint8_t phy_s, uint8_t phy_flags, struct pdu_cte_info *cte_info) @@ -1924,12 +1959,6 @@ static inline void sync_release(struct ll_adv_sync_set *sync) mem_release(sync, &adv_sync_free); } -static inline uint16_t sync_handle_get(struct ll_adv_sync_set *sync) -{ - return mem_index_get(sync, ll_adv_sync_pool, - sizeof(struct ll_adv_sync_set)); -} - static uint32_t sync_time_get(const struct ll_adv_sync_set *sync, const struct pdu_adv *pdu) { @@ -1952,7 +1981,7 @@ static uint8_t sync_stop(struct ll_adv_sync_set *sync) uint8_t sync_handle; int err; - sync_handle = sync_handle_get(sync); + sync_handle = ull_adv_sync_handle_get(sync); err = ull_ticker_stop_with_mark(TICKER_ID_ADV_SYNC_BASE + sync_handle, sync, &sync->lll); @@ -1992,6 +2021,11 @@ static inline uint8_t sync_remove(struct ll_adv_sync_set *sync, } sync->is_started = 0U; + + if (adv->lll.aux) { + /* notify the auxiliary set */ + ull_adv_sync_started_stopped(HDR_LLL2ULL(adv->lll.aux)); + } } if (!enable) { @@ -2007,6 +2041,7 @@ static uint8_t sync_chm_update(uint8_t handle) ULL_ADV_HDR_DATA_ACAD_PTR_SIZE]; struct pdu_adv_sync_chm_upd_ind *chm_upd_ind; struct lll_adv_sync *lll_sync; + struct ll_adv_sync_set *sync; struct pdu_adv *pdu_prev; struct ll_adv_set *adv; uint8_t acad_len_prev; @@ -2090,92 +2125,37 @@ static uint8_t sync_chm_update(uint8_t handle) ull_chan_map_get(lll_sync->chm[chm_last].data_chan_map); lll_sync->chm_instant = instant; - /* Commit the Channel Map Indication in the ACAD field of Periodic - * Advertising - */ - lll_adv_sync_data_enqueue(lll_sync, ter_idx); + sync = HDR_LLL2ULL(lll_sync); + if (sync->is_started) { + /* Commit the Channel Map Indication in the ACAD field of Periodic + * Advertising + */ + lll_adv_sync_data_enqueue(lll_sync, ter_idx); + } /* Initiate the Channel Map Indication */ lll_sync->chm_last = chm_last; + if (!sync->is_started) { + /* Sync not started yet, apply new channel map now */ + lll_sync->chm_first = lll_sync->chm_last; + } + return 0; } -static void mfy_sync_offset_get(void *param) +void ull_adv_sync_lll_syncinfo_fill(struct pdu_adv *pdu, struct lll_adv_aux *lll_aux) { - struct ll_adv_set *adv = param; struct lll_adv_sync *lll_sync; - struct ll_adv_sync_set *sync; struct pdu_adv_sync_info *si; - uint32_t sync_remainder_us; - uint32_t aux_remainder_us; - uint32_t ticks_to_expire; - uint32_t ticks_current; - struct pdu_adv *pdu; - uint32_t remainder; uint8_t chm_first; - uint8_t ticker_id; - uint16_t lazy; - uint8_t retry; - uint8_t id; - - lll_sync = adv->lll.sync; - sync = HDR_LLL2ULL(lll_sync); - ticker_id = TICKER_ID_ADV_SYNC_BASE + sync_handle_get(sync); - - id = TICKER_NULL; - ticks_to_expire = 0U; - ticks_current = 0U; - retry = 4U; - do { - uint32_t volatile ret_cb; - uint32_t ticks_previous; - uint32_t ret; - bool success; - - ticks_previous = ticks_current; - - ret_cb = TICKER_STATUS_BUSY; - ret = ticker_next_slot_get_ext(TICKER_INSTANCE_ID_CTLR, - TICKER_USER_ID_ULL_LOW, - &id, &ticks_current, - &ticks_to_expire, &remainder, - &lazy, NULL, NULL, - ticker_op_cb, (void *)&ret_cb); - if (ret == TICKER_STATUS_BUSY) { - while (ret_cb == TICKER_STATUS_BUSY) { - ticker_job_sched(TICKER_INSTANCE_ID_CTLR, - TICKER_USER_ID_ULL_LOW); - } - } - - success = (ret_cb == TICKER_STATUS_SUCCESS); - LL_ASSERT(success); - - LL_ASSERT((ticks_current == ticks_previous) || retry--); - - LL_ASSERT(id != TICKER_NULL); - } while (id != ticker_id); - - /* Reduced a tick for negative remainder and return positive remainder - * value. - */ - hal_ticker_remove_jitter(&ticks_to_expire, &remainder); - sync_remainder_us = remainder; - /* Add a tick for negative remainder and return positive remainder - * value. - */ - remainder = sync->aux_remainder; - hal_ticker_add_jitter(&ticks_to_expire, &remainder); - aux_remainder_us = remainder; + lll_sync = lll_aux->adv->sync; - pdu = lll_adv_aux_data_latest_peek(adv->lll.aux); si = sync_info_get(pdu); - sync_info_offset_fill(si, ticks_to_expire, sync_remainder_us, - aux_remainder_us); + sync_info_offset_fill(si, lll_sync->us_adv_sync_pdu_offset); si->evt_cntr = lll_sync->event_counter + lll_sync->latency_prepare + - lazy; + lll_sync->sync_lazy; /* Fill the correct channel map to use if at or past the instant */ if (lll_sync->chm_first != lll_sync->chm_last) { @@ -2238,14 +2218,8 @@ static inline struct pdu_adv_sync_info *sync_info_get(struct pdu_adv *pdu) } static inline void sync_info_offset_fill(struct pdu_adv_sync_info *si, - uint32_t ticks_offset, - uint32_t remainder_us, - uint32_t start_us) + uint32_t offs) { - uint32_t offs; - - offs = HAL_TICKER_TICKS_TO_US(ticks_offset) + remainder_us - start_us; - if (offs >= OFFS_ADJUST_US) { offs -= OFFS_ADJUST_US; si->offs_adjust = 1U; @@ -2269,7 +2243,12 @@ static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, static memq_link_t link; static struct mayfly mfy = {0, 0, &link, NULL, lll_adv_sync_prepare}; static struct lll_prepare_param p; +#if defined(CONFIG_BT_CTLR_ADV_ISO) + struct ticker_ext_context *context = param; + struct ll_adv_sync_set *sync = context->context; +#else struct ll_adv_sync_set *sync = param; +#endif /* CONFIG_BT_CTLR_ADV_ISO */ struct lll_adv_sync *lll; uint32_t ret; uint8_t ref; @@ -2290,21 +2269,22 @@ static void ticker_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, p.param = lll; mfy.param = &p; - /* Kick LLL prepare */ - ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, - TICKER_USER_ID_LLL, 0, &mfy); - LL_ASSERT(!ret); - #if defined(CONFIG_BT_CTLR_ADV_ISO) if (lll->iso) { - ull_adv_iso_offset_get(sync); + struct lll_adv_iso *lll_iso = lll->iso; + + LL_ASSERT(context->other_expire_info); + + /* Check: No need for remainder in this case? */ + lll_iso->ticks_sync_pdu_offset = context->other_expire_info->ticks_to_expire; + lll_iso->iso_lazy = context->other_expire_info->lazy; } #endif /* CONFIG_BT_CTLR_ADV_ISO */ - DEBUG_RADIO_PREPARE_A(1); -} + /* Kick LLL prepare */ + ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, + TICKER_USER_ID_LLL, 0, &mfy); + LL_ASSERT(!ret); -static void ticker_op_cb(uint32_t status, void *param) -{ - *((uint32_t volatile *)param) = status; + DEBUG_RADIO_PREPARE_A(1); } diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_types.h b/subsys/bluetooth/controller/ll_sw/ull_adv_types.h index d1cafd2b843f..9a1475dbf6fd 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_types.h +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_types.h @@ -91,8 +91,6 @@ struct ll_adv_sync_set { uint8_t is_enabled:1; uint8_t is_started:1; uint8_t is_data_cmplt:1; - - uint32_t aux_remainder; }; struct ll_adv_iso_set { diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index 65808c74d249..13e366f41e86 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -1299,7 +1299,7 @@ void ticker_worker(void *param) struct ticker_expire_info_internal *expire_info; struct ticker_ext_context ext_context; ticker_timeout_func timeout_func; - + timeout_func = ticker->ext_data->ext_timeout_func; expire_info = ticker->ext_data->other_expire_info; From 20ab0578d28796facd53b97e453d924d158189aa Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 20 Mar 2023 13:32:33 +0000 Subject: [PATCH 0617/1906] cmake: Change prj_.conf deprecation location Moves the deprecation notice for prj_.conf files to the proper location where other deprecation notices are located. Signed-off-by: Jamie McCrae --- cmake/modules/FindDeprecated.cmake | 7 +++++++ cmake/modules/configuration_files.cmake | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmake/modules/FindDeprecated.cmake b/cmake/modules/FindDeprecated.cmake index 6296c1701a83..2e6905070120 100644 --- a/cmake/modules/FindDeprecated.cmake +++ b/cmake/modules/FindDeprecated.cmake @@ -105,6 +105,13 @@ if("SOURCES" IN_LIST Deprecated_FIND_COMPONENTS) endif() endif() +if("PRJ_BOARD" IN_LIST Deprecated_FIND_COMPONENTS) + # This code was deprecated after Zephyr v3.3.0 + list(REMOVE_ITEM Deprecated_FIND_COMPONENTS PRJ_BOARD) + message(DEPRECATION "'prj_.conf' files are deprecated and should be " + "replaced with board Kconfig fragments instead.") +endif() + if(NOT "${Deprecated_FIND_COMPONENTS}" STREQUAL "") message(STATUS "The following deprecated component(s) could not be found: " "${Deprecated_FIND_COMPONENTS}") diff --git a/cmake/modules/configuration_files.cmake b/cmake/modules/configuration_files.cmake index 74fc7cecbb64..e5db53fd0880 100644 --- a/cmake/modules/configuration_files.cmake +++ b/cmake/modules/configuration_files.cmake @@ -67,8 +67,7 @@ elseif(CACHED_CONF_FILE) set(CONF_FILE ${CACHED_CONF_FILE}) elseif(EXISTS ${APPLICATION_CONFIG_DIR}/prj_${BOARD}.conf) set(CONF_FILE ${APPLICATION_CONFIG_DIR}/prj_${BOARD}.conf) - message(WARNING "Note that `prj_.conf` files are deprecated and should be " - "replaced with board Kconfig fragments instead.") + find_package(Deprecated COMPONENTS PRJ_BOARD) elseif(EXISTS ${APPLICATION_CONFIG_DIR}/prj.conf) set(CONF_FILE ${APPLICATION_CONFIG_DIR}/prj.conf) set(CONF_FILE_INCLUDE_FRAGMENTS true) From 32a48f2f55cdf0e37b8199bd7850d7b4ba8128d4 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Tue, 21 Mar 2023 20:07:04 +0000 Subject: [PATCH 0618/1906] armclang: Fix building cortex-m4 w/o floating point When we build for a SoC that has a cortex-m4 w/o a FPU that utilizes CMSIS headers with armclang (like mec1501modular_assy6885) we get the following warning: modules/hal/cmsis/CMSIS/Core/Include/core_cm4.h:93:8: warning: "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" [-W#warnings] #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" Fix the by setting -mfloat-abi=soft for such cases that don't have FPU enabled. Fixes #56068 Signed-off-by: Kumar Gala --- cmake/compiler/armclang/target.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/compiler/armclang/target.cmake b/cmake/compiler/armclang/target.cmake index 54ddefda0485..a43197461212 100644 --- a/cmake/compiler/armclang/target.cmake +++ b/cmake/compiler/armclang/target.cmake @@ -38,6 +38,8 @@ else() elseif(CONFIG_FP_HARDABI) list(APPEND TOOLCHAIN_C_FLAGS -mfloat-abi=hard) endif() + else() + list(APPEND TOOLCHAIN_C_FLAGS -mfloat-abi=soft) endif() endif() From 209eb20056037d2d37ef2837d4fc4a7d8a30dc4f Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Tue, 21 Mar 2023 23:09:02 +0000 Subject: [PATCH 0619/1906] doc: modules: add link to new contributor expectations page Also mention that drafts reduce notification spam. Signed-off-by: Marc Herbert --- doc/develop/modules.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/develop/modules.rst b/doc/develop/modules.rst index 1f5b9737b31c..a75f1f849e3a 100644 --- a/doc/develop/modules.rst +++ b/doc/develop/modules.rst @@ -1031,7 +1031,9 @@ module. To avoid merging changes to master with pull request information, the pull request should be marked as ``DNM`` (Do Not Merge) or preferably a draft pull request to make sure it is not merged by mistake and to allow for the module to -be merged first and be assigned a permanent commit hash. Once the module is +be merged first and be assigned a permanent commit hash. Drafts reduce noise by +not automatically notifying anyone until marked as "Ready for review". +Once the module is merged, the revision will need to be changed either by the submitter or by the maintainer to the commit hash of the module which reflects the changes. @@ -1088,7 +1090,8 @@ Process for submitting changes to existing modules ================================================== #. Submit the changes using a pull request to an existing repository following - the :ref:`contribution guidelines `. + the :ref:`contribution guidelines ` and + :ref:`expectations `. #. Submit a pull request changing the entry referencing the module into the :zephyr_file:`west.yml` of the main Zephyr tree with the following information: From a7c011b0bee4ca3bd72f192641bee56526a07e7a Mon Sep 17 00:00:00 2001 From: Raul Pando Date: Wed, 15 Feb 2023 20:02:02 +0000 Subject: [PATCH 0620/1906] Drivers: I2S: STM32: Mishandling of Master Clock output (MCK) Remedial rework to handle the enabling of the I2S master clock output based on the presence of an introduced DT property. For details see issue/54841. Signed-off-by: Raul Pando --- drivers/i2s/i2s_ll_stm32.c | 55 +++++++++++++++++++++++++----- drivers/i2s/i2s_ll_stm32.h | 1 + dts/bindings/i2s/st,stm32-i2s.yaml | 6 ++++ 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/drivers/i2s/i2s_ll_stm32.c b/drivers/i2s/i2s_ll_stm32.c index 9205a99c7c55..020f5e82b6ee 100644 --- a/drivers/i2s/i2s_ll_stm32.c +++ b/drivers/i2s/i2s_ll_stm32.c @@ -148,7 +148,8 @@ static int i2s_stm32_set_clock(const struct device *dev, /* wait until PLLI2S gets locked */ while (!LL_RCC_PLLI2S_IsReady()) { if (plli2s_ms_count++ > PLLI2S_MAX_MS_TIME) { - return -EIO; + LOG_ERR("PLLI2S failed to lock on time"); + return -EINVAL; } /* wait 1 ms */ @@ -162,9 +163,11 @@ static int i2s_stm32_set_clock(const struct device *dev, freq_in /= CONFIG_I2S_STM32_PLLI2S_PLLR; #endif /* CONFIG_I2S_STM32_USE_PLLI2S_ENABLE */ - /* Select clock source */ - LL_RCC_SetI2SClockSource(cfg->i2s_clk_sel); - + /* Ensure the frequency is achievable */ + if ((uint32_t) freq_in < bit_clk_freq) { + LOG_ERR("The requested sample rate exceeds the source clock"); + return -EINVAL; + } /* * The ratio between input clock (I2SxClk) and output * clock on the pad (I2S_CK) is obtained using the @@ -175,11 +178,20 @@ static int i2s_stm32_set_clock(const struct device *dev, i2s_odd = (i2s_div & 0x1) ? 1 : 0; i2s_div >>= 1; + /* i2s_div == 0 || i2s_div == 1 are forbidden */ + if (i2s_div < 2U) { + LOG_ERR("The linear prescaler value is unsupported"); + return -EINVAL; + } + LOG_DBG("i2s_div: %d - i2s_odd: %d", i2s_div, i2s_odd); LL_I2S_SetPrescalerLinear(cfg->i2s, i2s_div); LL_I2S_SetPrescalerParity(cfg->i2s, i2s_odd); + /* Select clock source */ + LL_RCC_SetI2SClockSource(cfg->i2s_clk_sel); + return 0; } @@ -188,8 +200,18 @@ static int i2s_stm32_configure(const struct device *dev, enum i2s_dir dir, { const struct i2s_stm32_cfg *const cfg = dev->config; struct i2s_stm32_data *const dev_data = dev->data; + /* For words greater than 16-bit the channel length is considered 32-bit */ + const uint32_t channel_length = i2s_cfg->word_size > 16U ? 32U : 16U; + /* + * comply with the i2s_config driver remark: + * When I2S data format is selected parameter channels is ignored, + * number of words in a frame is always 2. + */ + const uint32_t num_channels = i2s_cfg->format & I2S_FMT_DATA_FORMAT_MASK + ? 2U : i2s_cfg->channels; struct stream *stream; uint32_t bit_clk_freq; + bool enable_mck; int ret; if (dir == I2S_DIR_RX) { @@ -224,23 +246,39 @@ static int i2s_stm32_configure(const struct device *dev, enum i2s_dir dir, memcpy(&stream->cfg, i2s_cfg, sizeof(struct i2s_config)); + /* conditions to enable master clock output */ + enable_mck = stream->master && cfg->master_clk_sel; + /* set I2S bitclock */ bit_clk_freq = i2s_cfg->frame_clk_freq * - i2s_cfg->word_size * i2s_cfg->channels; + channel_length * num_channels; + + if (enable_mck) { + /* + * Compensate for the master clock dividers. + * MCK = N * CK, where N: + * 8 when the channel frame is 16-bit wide + * 4 when the channel frame is 32-bit wide + */ + bit_clk_freq *= channel_length == 16U ? 4U * 2U : 4U; + } ret = i2s_stm32_set_clock(dev, bit_clk_freq); if (ret < 0) { return ret; } - /* set I2S Master Clock */ - if (stream->master) { + /* set I2S Master Clock output in the MCK pin, enabled in the DT */ + if (enable_mck) { LL_I2S_EnableMasterClock(cfg->i2s); } else { LL_I2S_DisableMasterClock(cfg->i2s); } - /* set I2S Data Format */ + /* + * set I2S Data Format + * 16-bit data extended on 32-bit channel length excluded + */ if (i2s_cfg->word_size == 16U) { LL_I2S_SetDataFormat(cfg->i2s, LL_I2S_DATAFORMAT_16B); } else if (i2s_cfg->word_size == 24U) { @@ -908,6 +946,7 @@ static const struct i2s_stm32_cfg i2s_stm32_config_##index = { \ .i2s_clk_sel = CLK_SEL_##clk_sel, \ .pcfg = PINCTRL_DT_DEV_CONFIG_GET(DT_NODELABEL(i2s##index)), \ .irq_config = i2s_stm32_irq_config_func_##index, \ + .master_clk_sel = DT_PROP(DT_NODELABEL(i2s##index), mck_enabled)\ }; \ \ struct queue_item rx_##index##_ring_buf[CONFIG_I2S_STM32_RX_BLOCK_COUNT + 1];\ diff --git a/drivers/i2s/i2s_ll_stm32.h b/drivers/i2s/i2s_ll_stm32.h index 97738e9c5480..abf2e2dd6fd0 100644 --- a/drivers/i2s/i2s_ll_stm32.h +++ b/drivers/i2s/i2s_ll_stm32.h @@ -69,6 +69,7 @@ struct i2s_stm32_cfg { uint32_t i2s_clk_sel; const struct pinctrl_dev_config *pcfg; void (*irq_config)(const struct device *dev); + bool master_clk_sel; }; struct stream { diff --git a/dts/bindings/i2s/st,stm32-i2s.yaml b/dts/bindings/i2s/st,stm32-i2s.yaml index 4deb6bfd5432..1de415d0ddf9 100644 --- a/dts/bindings/i2s/st,stm32-i2s.yaml +++ b/dts/bindings/i2s/st,stm32-i2s.yaml @@ -25,3 +25,9 @@ properties: pinctrl-names: required: true + + mck-enabled: + type: boolean + description: | + Master Clock Output function. + An mck pin must be listed within pinctrl-0 when enabling this property. From 57784df5f0df665ef5012f0ad7e3528494a27b12 Mon Sep 17 00:00:00 2001 From: Magdalena Kasenberg Date: Wed, 15 Feb 2023 11:22:04 +0100 Subject: [PATCH 0621/1906] LE Audio: Refactor server ASE callbacks to return rsp object From now app layer is able to return explicit response code and reason that will appear in ASE Control Point notification. Fixes issues of ASCS/SR/SPE/BI-(07/08/09)-C PTS test cases, where PTS was receiving wrong response codes and reasons. Signed-off-by: Magdalena Kasenberg --- include/zephyr/bluetooth/audio/bap.h | 118 ++++- samples/bluetooth/hap_ha/src/bap_unicast_sr.c | 32 +- .../bluetooth/unicast_audio_server/src/main.c | 37 +- subsys/bluetooth/audio/ascs.c | 428 +++++++++--------- subsys/bluetooth/audio/bap_broadcast_source.c | 2 +- subsys/bluetooth/audio/bap_stream.c | 21 +- subsys/bluetooth/audio/bap_stream.h | 5 +- subsys/bluetooth/audio/bap_unicast_client.c | 4 +- subsys/bluetooth/audio/bap_unicast_server.c | 19 +- subsys/bluetooth/audio/shell/bap.c | 31 +- .../audio/src/bap_unicast_server_test.c | 32 +- .../bluetooth/audio/src/cap_acceptor_test.c | 33 +- 12 files changed, 458 insertions(+), 304 deletions(-) diff --git a/include/zephyr/bluetooth/audio/bap.h b/include/zephyr/bluetooth/audio/bap.h index f94a2db744de..f055c507711b 100644 --- a/include/zephyr/bluetooth/audio/bap.h +++ b/include/zephyr/bluetooth/audio/bap.h @@ -154,6 +154,62 @@ enum bt_bap_ascs_reason { BT_BAP_ASCS_REASON_CIS = 0x0a, }; +/** @brief Structure storing values of fields of ASE Control Point notification. */ +struct bt_bap_ascs_rsp { + /** @brief Value of the Response Code field. */ + enum bt_bap_ascs_rsp_code code; + + /** + * @brief Value of the Reason field. + * + * The meaning of this value depend on the Response Code field. + */ + union { + /** + * @brief Response reason + * + * If the Response Code is one of the following: + * - @ref BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED + * - @ref BT_BAP_ASCS_RSP_CODE_CONF_REJECTED + * - @ref BT_BAP_ASCS_RSP_CODE_CONF_INVALID + * all values from @ref bt_bap_ascs_reason can be used. + * + * If the Response Code is one of the following: + * - @ref BT_BAP_ASCS_RSP_CODE_SUCCESS + * - @ref BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED + * - @ref BT_BAP_ASCS_RSP_CODE_INVALID_LENGTH + * - @ref BT_BAP_ASCS_RSP_CODE_INVALID_ASE + * - @ref BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE + * - @ref BT_BAP_ASCS_RSP_CODE_INVALID_DIR + * - @ref BT_BAP_ASCS_RSP_CODE_CAP_UNSUPPORTED + * - @ref BT_BAP_ASCS_RSP_CODE_NO_MEM + * - @ref BT_BAP_ASCS_RSP_CODE_UNSPECIFIED + * only value @ref BT_BAP_ASCS_REASON_NONE shall be used. + */ + enum bt_bap_ascs_reason reason; + + /** + * @brief Response metadata type + * + * If the Response Code is one of the following: + * - @ref BT_BAP_ASCS_RSP_CODE_METADATA_UNSUPPORTED + * - @ref BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED + * - @ref BT_BAP_ASCS_RSP_CODE_METADATA_INVALID + * the value of the Metadata Type shall be used. + */ + enum bt_audio_metadata_type metadata_type; + }; +}; + +/** + * @brief Macro used to initialise the object storing values of ASE Control Point notification. + * + * @param c Response Code field + * @param r Reason field - @ref bt_bap_ascs_reason or @ref bt_audio_metadata_type (see notes in + * @ref bt_bap_ascs_rsp). + */ +#define BT_BAP_ASCS_RSP(c, r) (struct bt_bap_ascs_rsp) { .code = c, .reason = r } + /** @brief Abstract Audio Broadcast Source structure. */ struct bt_bap_broadcast_source; @@ -580,12 +636,14 @@ struct bt_bap_unicast_server_cb { * @param[out] stream Pointer to stream that will be configured for the endpoint. * @param[out] pref Pointer to a QoS preference object that shall be populated with * values. Invalid values will reject the codec configuration request. + * @param[out] rsp Object for the ASE operation response. Only used if the return + * value is non-zero. * * @return 0 in case of success or negative value in case of error. */ int (*config)(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_audio_dir dir, const struct bt_codec *codec, struct bt_bap_stream **stream, - struct bt_codec_qos_pref *const pref); + struct bt_codec_qos_pref *const pref, struct bt_bap_ascs_rsp *rsp); /** * @brief Stream reconfig request callback @@ -598,11 +656,14 @@ struct bt_bap_unicast_server_cb { * @param[in] codec Codec configuration. * @param[out] pref Pointer to a QoS preference object that shall be populated with * values. Invalid values will reject the codec configuration request. + * @param[out] rsp Object for the ASE operation response. Only used if the return + * value is non-zero. * * @return 0 in case of success or negative value in case of error. */ int (*reconfig)(struct bt_bap_stream *stream, enum bt_audio_dir dir, - const struct bt_codec *codec, struct bt_codec_qos_pref *const pref); + const struct bt_codec *codec, struct bt_codec_qos_pref *const pref, + struct bt_bap_ascs_rsp *rsp); /** * @brief Stream QoS request callback @@ -610,73 +671,86 @@ struct bt_bap_unicast_server_cb { * QoS callback is called whenever an Audio Stream Quality of * Service needs to be configured. * - * @param stream Stream object being reconfigured. - * @param qos Quality of Service configuration. + * @param[in] stream Stream object being reconfigured. + * @param[in] qos Quality of Service configuration. + * @param[out] rsp Object for the ASE operation response. Only used if the return + * value is non-zero. * * @return 0 in case of success or negative value in case of error. */ - int (*qos)(struct bt_bap_stream *stream, const struct bt_codec_qos *qos); + int (*qos)(struct bt_bap_stream *stream, const struct bt_codec_qos *qos, + struct bt_bap_ascs_rsp *rsp); /** * @brief Stream Enable request callback * * Enable callback is called whenever an Audio Stream is requested to be enabled to stream. * - * @param stream Stream object being enabled. - * @param meta Metadata entries - * @param meta_count Number of metadata entries + * @param[in] stream Stream object being enabled. + * @param[in] meta Metadata entries + * @param[in] meta_count Number of metadata entries + * @param[out] rsp Object for the ASE operation response. Only used if the return + * value is non-zero. * * @return 0 in case of success or negative value in case of error. */ int (*enable)(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count); + size_t meta_count, struct bt_bap_ascs_rsp *rsp); /** * @brief Stream Start request callback * * Start callback is called whenever an Audio Stream is requested to start streaming. * - * @param stream Stream object. + * @param[in] stream Stream object. + * @param[out] rsp Object for the ASE operation response. Only used if the return + * value is non-zero. * * @return 0 in case of success or negative value in case of error. */ - int (*start)(struct bt_bap_stream *stream); + int (*start)(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp); /** * @brief Stream Metadata update request callback * * Metadata callback is called whenever an Audio Stream is requested to update its metadata. * - * @param stream Stream object. - * @param meta Metadata entries - * @param meta_count Number of metadata entries + * @param[in] stream Stream object. + * @param[in] meta Metadata entries + * @param[in] meta_count Number of metadata entries + * @param[out] rsp Object for the ASE operation response. Only used if the return + * value is non-zero. * * @return 0 in case of success or negative value in case of error. */ int (*metadata)(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count); + size_t meta_count, struct bt_bap_ascs_rsp *rsp); /** * @brief Stream Disable request callback * * Disable callback is called whenever an Audio Stream is requested to disable the stream. * - * @param stream Stream object being disabled. + * @param[in] stream Stream object being disabled. + * @param[out] rsp Object for the ASE operation response. Only used if the return + * value is non-zero. * * @return 0 in case of success or negative value in case of error. */ - int (*disable)(struct bt_bap_stream *stream); + int (*disable)(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp); /** * @brief Stream Stop callback * * Stop callback is called whenever an Audio Stream is requested to stop streaming. * - * @param stream Stream object. + * @param[in] stream Stream object. + * @param[out] rsp Object for the ASE operation response. Only used if the return + * value is non-zero. * * @return 0 in case of success or negative value in case of error. */ - int (*stop)(struct bt_bap_stream *stream); + int (*stop)(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp); /** * @brief Stream release callback @@ -684,11 +758,13 @@ struct bt_bap_unicast_server_cb { * Release callback is called whenever a new Audio Stream needs to be released and thus * deallocated. * - * @param stream Stream object. + * @param[in] stream Stream object. + * @param[out] rsp Object for the ASE operation response. Only used if the return + * value is non-zero. * * @return 0 in case of success or negative value in case of error. */ - int (*release)(struct bt_bap_stream *stream); + int (*release)(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp); }; /** diff --git a/samples/bluetooth/hap_ha/src/bap_unicast_sr.c b/samples/bluetooth/hap_ha/src/bap_unicast_sr.c index ed187ea22a68..65eed96c8e65 100644 --- a/samples/bluetooth/hap_ha/src/bap_unicast_sr.c +++ b/samples/bluetooth/hap_ha/src/bap_unicast_sr.c @@ -189,7 +189,7 @@ static struct bt_bap_stream *stream_alloc(void) static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_audio_dir dir, const struct bt_codec *codec, struct bt_bap_stream **stream, - struct bt_codec_qos_pref *const pref) + struct bt_codec_qos_pref *const pref, struct bt_bap_ascs_rsp *rsp) { printk("ASE Codec Config: conn %p ep %p dir %u\n", conn, ep, dir); @@ -198,7 +198,7 @@ static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_ *stream = stream_alloc(); if (*stream == NULL) { printk("No streams available\n"); - + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NO_MEM, BT_BAP_ASCS_REASON_NONE); return -ENOMEM; } @@ -214,17 +214,21 @@ static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_ } static int lc3_reconfig(struct bt_bap_stream *stream, enum bt_audio_dir dir, - const struct bt_codec *codec, struct bt_codec_qos_pref *const pref) + const struct bt_codec *codec, struct bt_codec_qos_pref *const pref, + struct bt_bap_ascs_rsp *rsp) { printk("ASE Codec Reconfig: stream %p\n", stream); print_codec(codec); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED, BT_BAP_ASCS_REASON_NONE); + /* We only support one QoS at the moment, reject changes */ return -ENOEXEC; } -static int lc3_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos) +static int lc3_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos, + struct bt_bap_ascs_rsp *rsp) { printk("QoS: stream %p qos %p\n", stream, qos); @@ -234,14 +238,14 @@ static int lc3_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos) } static int lc3_enable(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count) + size_t meta_count, struct bt_bap_ascs_rsp *rsp) { printk("Enable: stream %p meta_count %u\n", stream, meta_count); return 0; } -static int lc3_start(struct bt_bap_stream *stream) +static int lc3_start(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Start: stream %p\n", stream); @@ -308,14 +312,18 @@ static bool valid_metadata_type(uint8_t type, uint8_t len) } static int lc3_metadata(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count) + size_t meta_count, struct bt_bap_ascs_rsp *rsp) { printk("Metadata: stream %p meta_count %u\n", stream, meta_count); for (size_t i = 0; i < meta_count; i++) { - if (!valid_metadata_type(meta->data.type, meta->data.data_len)) { + const struct bt_codec_data *data = &meta[i]; + + if (!valid_metadata_type(data->data.type, data->data.data_len)) { printk("Invalid metadata type %u or length %u\n", - meta->data.type, meta->data.data_len); + data->data.type, data->data.data_len); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED, + data->data.type); return -EINVAL; } @@ -324,21 +332,21 @@ static int lc3_metadata(struct bt_bap_stream *stream, const struct bt_codec_data return 0; } -static int lc3_disable(struct bt_bap_stream *stream) +static int lc3_disable(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Disable: stream %p\n", stream); return 0; } -static int lc3_stop(struct bt_bap_stream *stream) +static int lc3_stop(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Stop: stream %p\n", stream); return 0; } -static int lc3_release(struct bt_bap_stream *stream) +static int lc3_release(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Release: stream %p\n", stream); return 0; diff --git a/samples/bluetooth/unicast_audio_server/src/main.c b/samples/bluetooth/unicast_audio_server/src/main.c index 9d081a89ae3e..3ac4e184d94b 100644 --- a/samples/bluetooth/unicast_audio_server/src/main.c +++ b/samples/bluetooth/unicast_audio_server/src/main.c @@ -261,7 +261,7 @@ static struct bt_bap_stream *stream_alloc(enum bt_audio_dir dir) static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_audio_dir dir, const struct bt_codec *codec, struct bt_bap_stream **stream, - struct bt_codec_qos_pref *const pref) + struct bt_codec_qos_pref *const pref, struct bt_bap_ascs_rsp *rsp) { printk("ASE Codec Config: conn %p ep %p dir %u\n", conn, ep, dir); @@ -270,6 +270,7 @@ static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_ *stream = stream_alloc(dir); if (*stream == NULL) { printk("No streams available\n"); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NO_MEM, BT_BAP_ASCS_REASON_NONE); return -ENOMEM; } @@ -291,7 +292,8 @@ static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_ } static int lc3_reconfig(struct bt_bap_stream *stream, enum bt_audio_dir dir, - const struct bt_codec *codec, struct bt_codec_qos_pref *const pref) + const struct bt_codec *codec, struct bt_codec_qos_pref *const pref, + struct bt_bap_ascs_rsp *rsp) { printk("ASE Codec Reconfig: stream %p\n", stream); @@ -302,11 +304,14 @@ static int lc3_reconfig(struct bt_bap_stream *stream, enum bt_audio_dir dir, lc3_decoder = NULL; #endif + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED, BT_BAP_ASCS_REASON_NONE); + /* We only support one QoS at the moment, reject changes */ return -ENOEXEC; } -static int lc3_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos) +static int lc3_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos, + struct bt_bap_ascs_rsp *rsp) { printk("QoS: stream %p qos %p\n", stream, qos); @@ -323,7 +328,7 @@ static int lc3_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos) } static int lc3_enable(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count) + size_t meta_count, struct bt_bap_ascs_rsp *rsp) { printk("Enable: stream %p meta_count %u\n", stream, meta_count); @@ -334,11 +339,15 @@ static int lc3_enable(struct bt_bap_stream *stream, const struct bt_codec_data * if (freq < 0) { printk("Error: Codec frequency not set, cannot start codec."); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_CONF_INVALID, + BT_BAP_ASCS_REASON_CODEC_DATA); return -1; } if (frame_duration_us < 0) { printk("Error: Frame duration not set, cannot start codec."); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_CONF_INVALID, + BT_BAP_ASCS_REASON_CODEC_DATA); return -1; } @@ -351,6 +360,8 @@ static int lc3_enable(struct bt_bap_stream *stream, const struct bt_codec_data * if (lc3_decoder == NULL) { printk("ERROR: Failed to setup LC3 encoder - wrong parameters?\n"); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_CONF_INVALID, + BT_BAP_ASCS_REASON_CODEC_DATA); return -1; } } @@ -359,7 +370,7 @@ static int lc3_enable(struct bt_bap_stream *stream, const struct bt_codec_data * return 0; } -static int lc3_start(struct bt_bap_stream *stream) +static int lc3_start(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Start: stream %p\n", stream); @@ -425,14 +436,18 @@ static bool valid_metadata_type(uint8_t type, uint8_t len) } static int lc3_metadata(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count) + size_t meta_count, struct bt_bap_ascs_rsp *rsp) { printk("Metadata: stream %p meta_count %u\n", stream, meta_count); for (size_t i = 0; i < meta_count; i++) { - if (!valid_metadata_type(meta->data.type, meta->data.data_len)) { + const struct bt_codec_data *data = &meta[i]; + + if (!valid_metadata_type(data->data.type, data->data.data_len)) { printk("Invalid metadata type %u or length %u\n", - meta->data.type, meta->data.data_len); + data->data.type, data->data.data_len); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED, + data->data.type); return -EINVAL; } @@ -441,21 +456,21 @@ static int lc3_metadata(struct bt_bap_stream *stream, const struct bt_codec_data return 0; } -static int lc3_disable(struct bt_bap_stream *stream) +static int lc3_disable(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Disable: stream %p\n", stream); return 0; } -static int lc3_stop(struct bt_bap_stream *stream) +static int lc3_stop(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Stop: stream %p\n", stream); return 0; } -static int lc3_release(struct bt_bap_stream *stream) +static int lc3_release(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Release: stream %p\n", stream); return 0; diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index aa87d7594377..cf3dbc2fe0a2 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -902,65 +902,6 @@ static void ascs_cp_rsp_add(uint8_t id, uint8_t op, uint8_t code, ase_rsp->reason = reason; } -static void ascs_cp_rsp_add_errno(uint8_t id, uint8_t op, int err, - uint8_t reason) -{ - LOG_DBG("id %u op %u err %d reason %u", id, op, err, reason); - - switch (err) { - case -ENOBUFS: - case -ENOMEM: - return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_NO_MEM, - BT_BAP_ASCS_REASON_NONE); - case -EINVAL: - switch (op) { - case BT_ASCS_CONFIG_OP: - /* Fallthrough */ - case BT_ASCS_QOS_OP: - return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_CONF_INVALID, reason); - case BT_ASCS_ENABLE_OP: - /* Fallthrough */ - case BT_ASCS_METADATA_OP: - return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_METADATA_INVALID, - reason); - default: - return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, - BT_BAP_ASCS_REASON_NONE); - } - case -ENOTSUP: - switch (op) { - case BT_ASCS_CONFIG_OP: - /* Fallthrough */ - case BT_ASCS_QOS_OP: - return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED, - reason); - case BT_ASCS_ENABLE_OP: - /* Fallthrough */ - case BT_ASCS_METADATA_OP: - return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_METADATA_UNSUPPORTED, - reason); - default: - return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, - BT_BAP_ASCS_REASON_NONE); - } - case -EBADMSG: - return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, - BT_BAP_ASCS_REASON_NONE); - case -EACCES: - switch (op) { - case BT_ASCS_METADATA_OP: - return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED, - reason); - default: - return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, - BT_BAP_ASCS_REASON_NONE); - } - default: - return ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, - BT_BAP_ASCS_REASON_NONE); - } -} - static void ascs_cp_rsp_success(uint8_t id, uint8_t op) { ascs_cp_rsp_add(id, op, BT_BAP_ASCS_RSP_CODE_SUCCESS, BT_BAP_ASCS_REASON_NONE); @@ -969,6 +910,8 @@ static void ascs_cp_rsp_success(uint8_t id, uint8_t op) static void ase_release(struct bt_ascs_ase *ase) { uint8_t ase_id = ASE_ID(ase); + struct bt_bap_ascs_rsp rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); int err; LOG_DBG("ase %p state %s", ase, bt_bap_ep_state_str(ase->ep.status.state)); @@ -979,13 +922,21 @@ static void ase_release(struct bt_ascs_ase *ase) } if (unicast_server_cb != NULL && unicast_server_cb->release != NULL) { - err = unicast_server_cb->release(ase->ep.stream); + err = unicast_server_cb->release(ase->ep.stream, &rsp); } else { err = -ENOTSUP; + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + BT_BAP_ASCS_REASON_NONE); } if (err) { - ascs_cp_rsp_add_errno(ase_id, BT_ASCS_RELEASE_OP, err, BT_BAP_ASCS_REASON_NONE); + if (rsp.code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, + BT_BAP_ASCS_REASON_NONE); + } + + LOG_ERR("Release failed: err %d, code %u, reason %u", err, rsp.code, rsp.reason); + ascs_cp_rsp_add(ase_id, BT_ASCS_RELEASE_OP, rsp.code, rsp.reason); return; } @@ -999,6 +950,8 @@ static void ase_disable(struct bt_ascs_ase *ase) { struct bt_bap_stream *stream; struct bt_bap_ep *ep; + struct bt_bap_ascs_rsp rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); int err; LOG_DBG("ase %p", ase); @@ -1013,23 +966,29 @@ static void ase_disable(struct bt_ascs_ase *ase) break; default: LOG_WRN("Invalid operation in state: %s", bt_bap_ep_state_str(ep->status.state)); - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_DISABLE_OP, -EBADMSG, - BT_BAP_ASCS_REASON_NONE); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_DISABLE_OP, + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, BT_BAP_ASCS_REASON_NONE); return; } stream = ep->stream; if (unicast_server_cb != NULL && unicast_server_cb->disable != NULL) { - err = unicast_server_cb->disable(stream); + err = unicast_server_cb->disable(stream, &rsp); } else { err = -ENOTSUP; + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + BT_BAP_ASCS_REASON_NONE); } if (err) { - LOG_ERR("Disable failed: %d", err); - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_DISABLE_OP, err, - BT_BAP_ASCS_REASON_NONE); + if (rsp.code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, + BT_BAP_ASCS_REASON_NONE); + } + + LOG_ERR("Disable failed: err %d, code %u, reason %u", err, rsp.code, rsp.reason); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_DISABLE_OP, rsp.code, rsp.reason); return; } @@ -1315,6 +1274,8 @@ static bool ascs_codec_config_store(struct bt_data *data, void *user_data) struct codec_lookup_id_data { uint8_t id; + uint16_t cid; + uint16_t vid; struct bt_codec *codec; }; @@ -1322,7 +1283,8 @@ static bool codec_lookup_id(const struct bt_pacs_cap *cap, void *user_data) { struct codec_lookup_id_data *data = user_data; - if (cap->codec->id == data->id) { + if (cap->codec->id == data->id && cap->codec->cid == data->cid && + cap->codec->vid == data->vid) { data->codec = cap->codec; return false; @@ -1332,14 +1294,19 @@ static bool codec_lookup_id(const struct bt_pacs_cap *cap, void *user_data) } static int ascs_ep_set_codec(struct bt_bap_ep *ep, uint8_t id, uint16_t cid, uint16_t vid, - struct net_buf_simple *buf, uint8_t len, struct bt_codec *codec) + struct net_buf_simple *buf, uint8_t len, struct bt_codec *codec, + struct bt_bap_ascs_rsp *rsp) { struct net_buf_simple ad; struct codec_lookup_id_data lookup_data = { .id = id, + .cid = cid, + .vid = vid, }; if (ep == NULL && codec == NULL) { + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_CONF_INVALID, + BT_BAP_ASCS_REASON_CODEC_DATA); return -EINVAL; } @@ -1352,6 +1319,8 @@ static int ascs_ep_set_codec(struct bt_bap_ep *ep, uint8_t id, uint16_t cid, uin LOG_DBG("Codec with id %u for dir %s is not supported by our capabilities", id, bt_audio_dir_str(ep->dir)); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_CONF_INVALID, + BT_BAP_ASCS_REASON_CODEC); return -ENOENT; } @@ -1366,6 +1335,7 @@ static int ascs_ep_set_codec(struct bt_bap_ep *ep, uint8_t id, uint16_t cid, uin codec->path_id = lookup_data.codec->path_id; if (len == 0 || buf == NULL) { + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, BT_BAP_ASCS_REASON_NONE); return 0; } @@ -1379,19 +1349,23 @@ static int ascs_ep_set_codec(struct bt_bap_ep *ep, uint8_t id, uint16_t cid, uin if (ad.len) { LOG_ERR("Unable to parse Codec Config: len %u", ad.len); (void)memset(codec, 0, sizeof(*codec)); - + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_CONF_INVALID, + BT_BAP_ASCS_REASON_CODEC_DATA); return -EINVAL; } + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, BT_BAP_ASCS_REASON_NONE); return 0; } -static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, - const struct bt_ascs_config *cfg, - struct net_buf_simple *buf) +static void ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, + const struct bt_ascs_config *cfg, + struct net_buf_simple *buf) { struct bt_bap_stream *stream; struct bt_codec codec; + struct bt_bap_ascs_rsp rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); int err; LOG_DBG("ase %p latency 0x%02x phy 0x%02x codec 0x%02x " @@ -1402,17 +1376,18 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, if (cfg->latency < BT_ASCS_CONFIG_LATENCY_LOW || cfg->latency > BT_ASCS_CONFIG_LATENCY_HIGH) { LOG_WRN("Invalid latency: 0x%02x", cfg->latency); - ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_CONF_INVALID, + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, + BT_BAP_ASCS_RSP_CODE_CONF_INVALID, BT_BAP_ASCS_REASON_LATENCY); - return 0; + return; } if (cfg->phy < BT_ASCS_CONFIG_PHY_LE_1M || cfg->phy > BT_ASCS_CONFIG_PHY_LE_CODED) { LOG_WRN("Invalid PHY: 0x%02x", cfg->phy); - ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_CONF_INVALID, - BT_BAP_ASCS_REASON_PHY); - return 0; + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, + BT_BAP_ASCS_RSP_CODE_CONF_INVALID, BT_BAP_ASCS_REASON_PHY); + return; } switch (ase->ep.status.state) { @@ -1428,7 +1403,7 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, bt_bap_ep_state_str(ase->ep.status.state)); ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, 0x00); - return 0; + return; } /* Store current codec configuration to be able to restore it @@ -1436,14 +1411,14 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, */ (void)memcpy(&codec, &ase->ep.codec, sizeof(codec)); - if (ascs_ep_set_codec(&ase->ep, cfg->codec.id, - sys_le16_to_cpu(cfg->codec.cid), - sys_le16_to_cpu(cfg->codec.vid), - buf, cfg->cc_len, &ase->ep.codec)) { + err = ascs_ep_set_codec(&ase->ep, cfg->codec.id, + sys_le16_to_cpu(cfg->codec.cid), + sys_le16_to_cpu(cfg->codec.vid), + buf, cfg->cc_len, &ase->ep.codec, &rsp); + if (err) { (void)memcpy(&ase->ep.codec, &codec, sizeof(codec)); - ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_CONF_INVALID, - BT_BAP_ASCS_REASON_CODEC_DATA); - return 0; + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, rsp.code, rsp.reason); + return; } if (ase->ep.stream != NULL) { @@ -1452,21 +1427,27 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, err = unicast_server_cb->reconfig(ase->ep.stream, ase->ep.dir, &ase->ep.codec, - &ase->ep.qos_pref); + &ase->ep.qos_pref, + &rsp); } else { err = -ENOTSUP; + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + BT_BAP_ASCS_REASON_NONE); } - if (err != 0) { - uint8_t reason = BT_BAP_ASCS_REASON_CODEC_DATA; + if (err) { + if (rsp.code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, + BT_BAP_ASCS_REASON_NONE); + } - LOG_ERR("Reconfig failed: %d", err); + LOG_ERR("Reconfig failed: err %d, code %u, reason %u", + err, rsp.code, rsp.reason); (void)memcpy(&ase->ep.codec, &codec, sizeof(codec)); - ascs_cp_rsp_add_errno(ASE_ID(ase), - BT_ASCS_CONFIG_OP, - err, reason); - return 0; + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, rsp.code, rsp.reason); + + return; } stream = ase->ep.stream; @@ -1474,23 +1455,28 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, stream = NULL; if (unicast_server_cb != NULL && unicast_server_cb->config != NULL) { - err = unicast_server_cb->config(ascs->conn, &ase->ep, - ase->ep.dir, + err = unicast_server_cb->config(ascs->conn, &ase->ep, ase->ep.dir, &ase->ep.codec, &stream, - &ase->ep.qos_pref); + &ase->ep.qos_pref, &rsp); } else { err = -ENOTSUP; + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + BT_BAP_ASCS_REASON_NONE); } - if (err != 0 || stream == NULL) { - LOG_ERR("Config failed, err: %d, stream %p", err, stream); + if (err || stream == NULL) { + if (rsp.code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, + BT_BAP_ASCS_REASON_NONE); + } + + LOG_ERR("Config failed: err %d, stream %p, code %u, reason %u", + err, stream, rsp.code, rsp.reason); (void)memcpy(&ase->ep.codec, &codec, sizeof(codec)); - ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, - BT_BAP_ASCS_RSP_CODE_CONF_REJECTED, - BT_BAP_ASCS_REASON_CODEC_DATA); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, rsp.code, rsp.reason); - return err; + return; } bt_bap_stream_init(stream); @@ -1501,8 +1487,6 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, bt_bap_stream_attach(ascs->conn, stream, &ase->ep, &ase->ep.codec); ascs_ep_set_state(&ase->ep, BT_BAP_EP_STATE_CODEC_CONFIGURED); - - return 0; } int bt_ascs_config_ase(struct bt_conn *conn, struct bt_bap_stream *stream, struct bt_codec *codec, @@ -1512,6 +1496,8 @@ int bt_ascs_config_ase(struct bt_conn *conn, struct bt_bap_stream *stream, struc struct bt_ascs *ascs; struct bt_ascs_ase *ase; struct bt_bap_ep *ep; + struct bt_bap_ascs_rsp rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); CHECKIF(conn == NULL || stream == NULL || codec == NULL || qos_pref == NULL) { LOG_DBG("NULL value(s) supplied)"); @@ -1549,7 +1535,7 @@ int bt_ascs_config_ase(struct bt_conn *conn, struct bt_bap_stream *stream, struc } err = ascs_ep_set_codec(ep, codec->id, sys_le16_to_cpu(codec->cid), - sys_le16_to_cpu(codec->vid), NULL, 0, &ep->codec); + sys_le16_to_cpu(codec->vid), NULL, 0, &ep->codec, &rsp); if (err) { return err; } @@ -1623,7 +1609,6 @@ static ssize_t ascs_config(struct bt_ascs *ascs, struct net_buf_simple *buf) for (uint8_t i = 0; i < req->num_ases; i++) { struct bt_ascs_ase *ase; - int err; cfg = net_buf_simple_pull_mem(buf, sizeof(*cfg)); @@ -1639,17 +1624,13 @@ static ssize_t ascs_config(struct bt_ascs *ascs, struct net_buf_simple *buf) } if (!ase) { - ascs_cp_rsp_add(cfg->ase, BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_NO_MEM, - 0x00); + ascs_cp_rsp_add(cfg->ase, BT_ASCS_CONFIG_OP, + BT_BAP_ASCS_RSP_CODE_NO_MEM, 0x00); LOG_WRN("No free ASE found for config ASE ID 0x%02x", cfg->ase); continue; } - err = ase_config(ascs, ase, cfg, buf); - if (err != 0) { - LOG_WRN("Malformed ASE Config"); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - } + ase_config(ascs, ase, cfg, buf); } return buf->size; @@ -1668,12 +1649,16 @@ void bt_ascs_foreach_ep(struct bt_conn *conn, bt_bap_ep_func_t func, void *user_ } static int ase_stream_qos(struct bt_bap_stream *stream, struct bt_codec_qos *qos, - struct bt_ascs *ascs, uint8_t cig_id, uint8_t cis_id) + struct bt_ascs *ascs, uint8_t cig_id, uint8_t cis_id, + struct bt_bap_ascs_rsp *rsp) { struct bt_bap_ep *ep; + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, BT_BAP_ASCS_REASON_NONE); - if (stream == NULL || stream->ep == NULL || qos == NULL) { + CHECKIF(stream == NULL || stream->ep == NULL || qos == NULL) { LOG_DBG("Invalid input stream, ep or qos pointers"); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, + BT_BAP_ASCS_REASON_NONE); return -EINVAL; } @@ -1689,23 +1674,34 @@ static int ase_stream_qos(struct bt_bap_stream *stream, struct bt_codec_qos *qos break; default: LOG_WRN("Invalid operation in state: %s", bt_bap_ep_state_str(ep->status.state)); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, + BT_BAP_ASCS_REASON_NONE); return -EBADMSG; } - if (!bt_audio_valid_qos(qos)) { + rsp->reason = bt_audio_verify_qos(qos); + if (rsp->reason != BT_BAP_ASCS_REASON_NONE) { + rsp->code = BT_BAP_ASCS_RSP_CODE_CONF_INVALID; return -EINVAL; } - if (!bt_bap_stream_valid_qos(stream, qos)) { + rsp->reason = bt_bap_stream_verify_qos(stream, qos); + if (rsp->reason != BT_BAP_ASCS_REASON_NONE) { + rsp->code = BT_BAP_ASCS_RSP_CODE_CONF_INVALID; return -EINVAL; } if (unicast_server_cb != NULL && unicast_server_cb->qos != NULL) { - int err; + int err = unicast_server_cb->qos(stream, qos, rsp); - err = unicast_server_cb->qos(stream, qos); - if (err != 0) { - LOG_DBG("Application returned error: %d", err); + if (err) { + if (rsp->code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, + BT_BAP_ASCS_REASON_NONE); + } + + LOG_DBG("Application returned error: err %d status %u reason %u", + err, rsp->code, rsp->reason); return err; } } @@ -1721,6 +1717,8 @@ static int ase_stream_qos(struct bt_bap_stream *stream, struct bt_codec_qos *qos iso = bap_iso_get_or_new(ascs, cig_id, cis_id); if (iso == NULL) { LOG_ERR("Could not allocate bap_iso"); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NO_MEM, + BT_BAP_ASCS_REASON_NONE); return -ENOMEM; } @@ -1728,6 +1726,8 @@ static int ase_stream_qos(struct bt_bap_stream *stream, struct bt_codec_qos *qos LOG_ERR("iso %p already in use in dir %s", &iso->chan, bt_audio_dir_str(ep->dir)); bt_bap_iso_unref(iso); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_CONF_INVALID, + BT_BAP_ASCS_REASON_CIS); return -EALREADY; } @@ -1754,6 +1754,7 @@ static int ase_stream_qos(struct bt_bap_stream *stream, struct bt_codec_qos *qos ascs_iso_listen(stream); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, BT_BAP_ASCS_REASON_NONE); return 0; } @@ -1764,6 +1765,8 @@ static void ase_qos(struct bt_ascs_ase *ase, const struct bt_ascs_qos *qos) struct bt_codec_qos *cqos = &ep->qos; const uint8_t cig_id = qos->cig; const uint8_t cis_id = qos->cis; + struct bt_bap_ascs_rsp rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); int err; cqos->interval = sys_get_le24(qos->interval); @@ -1779,38 +1782,16 @@ static void ase_qos(struct bt_ascs_ase *ase, const struct bt_ascs_qos *qos) qos->cis, cqos->interval, cqos->framing, cqos->phy, cqos->sdu, cqos->rtn, cqos->latency, cqos->pd); - err = ase_stream_qos(stream, cqos, ase->ascs, cig_id, cis_id); + err = ase_stream_qos(stream, cqos, ase->ascs, cig_id, cis_id, &rsp); if (err) { - uint8_t reason = BT_BAP_ASCS_REASON_NONE; - - LOG_ERR("QoS failed: err %d", err); - - if (err == -ENOTSUP) { - if (cqos->interval == 0) { - reason = BT_BAP_ASCS_REASON_INTERVAL; - } else if (cqos->framing == 0xff) { - reason = BT_BAP_ASCS_REASON_FRAMING; - } else if (cqos->phy == 0) { - reason = BT_BAP_ASCS_REASON_PHY; - } else if (cqos->sdu == 0xffff) { - reason = BT_BAP_ASCS_REASON_SDU; - } else if (cqos->latency == 0) { - reason = BT_BAP_ASCS_REASON_LATENCY; - } else if (cqos->pd == 0) { - reason = BT_BAP_ASCS_REASON_PD; - } - } else if (err == -EALREADY) { - reason = BT_BAP_ASCS_REASON_CIS; - /* FIXME: Ugly workaround to send Response_Code - * 0x09 = Invalid Configuration Parameter Value - */ - err = -EINVAL; + if (rsp.code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, + BT_BAP_ASCS_REASON_NONE); } - + LOG_ERR("QoS failed: err %d, code %u, reason %u", err, rsp.code, rsp.reason); memset(cqos, 0, sizeof(*cqos)); - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_QOS_OP, - err, reason); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_QOS_OP, rsp.code, rsp.reason); return; } @@ -1889,6 +1870,7 @@ static bool ascs_codec_store_metadata(struct bt_data *data, void *user_data) struct ascs_parse_result { int err; + struct bt_bap_ascs_rsp *rsp; size_t count; const struct bt_bap_ep *ep; }; @@ -1908,6 +1890,8 @@ static bool ascs_parse_metadata(struct bt_data *data, void *user_data) if (result->count > CONFIG_BT_CODEC_MAX_METADATA_COUNT) { LOG_ERR("Not enough buffers for Codec Config Metadata: %zu > %zu", result->count, CONFIG_BT_CODEC_MAX_METADATA_LEN); + *result->rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NO_MEM, + BT_BAP_ASCS_REASON_NONE); result->err = -ENOMEM; return false; @@ -1916,6 +1900,8 @@ static bool ascs_parse_metadata(struct bt_data *data, void *user_data) if (data_len > CONFIG_BT_CODEC_MAX_METADATA_LEN) { LOG_ERR("Not enough space for Codec Config Metadata: %u > %zu", data->data_len, CONFIG_BT_CODEC_MAX_METADATA_LEN); + *result->rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NO_MEM, + BT_BAP_ASCS_REASON_NONE); result->err = -ENOMEM; return false; @@ -1930,7 +1916,8 @@ static bool ascs_parse_metadata(struct bt_data *data, void *user_data) if (!bt_pacs_context_available(ep->dir, context)) { LOG_WRN("Context 0x%04x is unavailable", context); - + *result->rsp = BT_BAP_ASCS_RSP( + BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED, data_type); result->err = -EACCES; return false; @@ -1963,9 +1950,11 @@ static bool ascs_parse_metadata(struct bt_data *data, void *user_data) return true; } -static int ascs_verify_metadata(const struct net_buf_simple *buf, struct bt_bap_ep *ep) +static int ascs_verify_metadata(const struct net_buf_simple *buf, struct bt_bap_ep *ep, + struct bt_bap_ascs_rsp *rsp) { struct ascs_parse_result result = { + .rsp = rsp, .count = 0U, .err = 0, .ep = ep @@ -1984,9 +1973,13 @@ static int ascs_verify_metadata(const struct net_buf_simple *buf, struct bt_bap_ if (meta_ltv.len > 2) { /* Value of the Metadata Type field in error */ + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_METADATA_INVALID, + meta_ltv.data[2]); return meta_ltv.data[2]; } + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_METADATA_INVALID, + BT_BAP_ASCS_REASON_NONE); return -EINVAL; } @@ -1994,12 +1987,15 @@ static int ascs_verify_metadata(const struct net_buf_simple *buf, struct bt_bap_ } static int ascs_ep_set_metadata(struct bt_bap_ep *ep, struct net_buf_simple *buf, uint8_t len, - struct bt_codec *codec) + struct bt_codec *codec, struct bt_bap_ascs_rsp *rsp) { struct net_buf_simple meta_ltv; int err; + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, BT_BAP_ASCS_REASON_NONE); if (ep == NULL && codec == NULL) { + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, + BT_BAP_ASCS_REASON_NONE); return -EINVAL; } @@ -2007,6 +2003,7 @@ static int ascs_ep_set_metadata(struct bt_bap_ep *ep, struct net_buf_simple *buf if (len == 0) { (void)memset(codec->meta, 0, sizeof(codec->meta)); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, BT_BAP_ASCS_REASON_NONE); return 0; } @@ -2019,7 +2016,7 @@ static int ascs_ep_set_metadata(struct bt_bap_ep *ep, struct net_buf_simple *buf net_buf_simple_pull_mem(buf, len), len); - err = ascs_verify_metadata(&meta_ltv, ep); + err = ascs_verify_metadata(&meta_ltv, ep, rsp); if (err != 0) { return err; } @@ -2033,13 +2030,15 @@ static int ascs_ep_set_metadata(struct bt_bap_ep *ep, struct net_buf_simple *buf return 0; } -static int ase_metadata(struct bt_ascs_ase *ase, uint8_t op, - struct bt_ascs_metadata *meta, - struct net_buf_simple *buf) +static void ase_metadata(struct bt_ascs_ase *ase, uint8_t op, + struct bt_ascs_metadata *meta, + struct net_buf_simple *buf) { struct bt_codec_data metadata_backup[CONFIG_BT_CODEC_MAX_DATA_COUNT]; struct bt_bap_stream *stream; struct bt_bap_ep *ep; + struct bt_bap_ascs_rsp rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); uint8_t state; int err; @@ -2056,10 +2055,9 @@ static int ase_metadata(struct bt_ascs_ase *ase, uint8_t op, break; default: LOG_WRN("Invalid operation in state: %s", bt_bap_ep_state_str(state)); - err = -EBADMSG; - ascs_cp_rsp_add_errno(ASE_ID(ase), op, err, - buf->len ? *buf->data : 0x00); - return err; + ascs_cp_rsp_add(ASE_ID(ase), op, BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, + BT_BAP_ASCS_REASON_NONE); + return; } if (!meta->len) { @@ -2068,42 +2066,40 @@ static int ase_metadata(struct bt_ascs_ase *ase, uint8_t op, /* Backup existing metadata */ (void)memcpy(metadata_backup, ep->codec.meta, sizeof(metadata_backup)); - err = ascs_ep_set_metadata(ep, buf, meta->len, &ep->codec); + err = ascs_ep_set_metadata(ep, buf, meta->len, &ep->codec, &rsp); if (err) { - if (err < 0) { - ascs_cp_rsp_add_errno(ASE_ID(ase), op, err, 0x00); - } else { - ascs_cp_rsp_add(ASE_ID(ase), op, BT_BAP_ASCS_RSP_CODE_METADATA_INVALID, - err); - } - return 0; + ascs_cp_rsp_add(ASE_ID(ase), op, rsp.code, rsp.reason); + return; } stream = ep->stream; if (unicast_server_cb != NULL && unicast_server_cb->metadata != NULL) { err = unicast_server_cb->metadata(stream, ep->codec.meta, - ep->codec.meta_count); + ep->codec.meta_count, &rsp); } else { err = -ENOTSUP; + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + BT_BAP_ASCS_REASON_NONE); } if (err) { + if (rsp.code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, + BT_BAP_ASCS_REASON_NONE); + } + /* Restore backup */ - (void)memcpy(ep->codec.meta, metadata_backup, - sizeof(metadata_backup)); + (void)memcpy(ep->codec.meta, metadata_backup, sizeof(metadata_backup)); - LOG_ERR("Metadata failed: %d", err); - ascs_cp_rsp_add_errno(ASE_ID(ase), op, err, - buf->len ? *buf->data : 0x00); - return err; + LOG_ERR("Metadata failed: err %d, code %u, reason %u", err, rsp.code, rsp.reason); + ascs_cp_rsp_add(ASE_ID(ase), op, rsp.code, rsp.reason); + return; } /* Set the state to the same state to trigger the notifications */ ascs_ep_set_state(ep, ep->status.state); done: ascs_cp_rsp_success(ASE_ID(ase), op); - - return 0; } static int ase_enable(struct bt_ascs_ase *ase, struct bt_ascs_metadata *meta, @@ -2111,6 +2107,8 @@ static int ase_enable(struct bt_ascs_ase *ase, struct bt_ascs_metadata *meta, { struct bt_bap_stream *stream; struct bt_bap_ep *ep; + struct bt_bap_ascs_rsp rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); int err; LOG_DBG("ase %p buf->len %u", ase, buf->len); @@ -2121,33 +2119,36 @@ static int ase_enable(struct bt_ascs_ase *ase, struct bt_ascs_metadata *meta, if (ep->status.state != BT_BAP_EP_STATE_QOS_CONFIGURED) { err = -EBADMSG; LOG_WRN("Invalid operation in state: %s", bt_bap_ep_state_str(ep->status.state)); - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_ENABLE_OP, err, BT_BAP_ASCS_REASON_NONE); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_ENABLE_OP, + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, BT_BAP_ASCS_REASON_NONE); return err; } - err = ascs_ep_set_metadata(ep, buf, meta->len, &ep->codec); + err = ascs_ep_set_metadata(ep, buf, meta->len, &ep->codec, &rsp); if (err) { - if (err < 0) { - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_ENABLE_OP, - err, 0x00); - } else { - ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_ENABLE_OP, - BT_BAP_ASCS_RSP_CODE_METADATA_INVALID, err); - } - return 0; + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_ENABLE_OP, rsp.code, rsp.reason); + return err; } stream = ep->stream; if (unicast_server_cb != NULL && unicast_server_cb->enable != NULL) { err = unicast_server_cb->enable(stream, ep->codec.meta, - ep->codec.meta_count); + ep->codec.meta_count, &rsp); } else { err = -ENOTSUP; + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + BT_BAP_ASCS_REASON_NONE); } if (err) { - LOG_ERR("Enable rejected: %d", err); - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_ENABLE_OP, err, BT_BAP_ASCS_REASON_NONE); + if (rsp.code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, + BT_BAP_ASCS_REASON_NONE); + } + + LOG_ERR("Enable rejected: err %d, code %u, reason %u", err, rsp.code, rsp.reason); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_ENABLE_OP, rsp.code, rsp.reason); + return -EFAULT; } @@ -2217,6 +2218,8 @@ static ssize_t ascs_enable(struct bt_ascs *ascs, struct net_buf_simple *buf) static void ase_start(struct bt_ascs_ase *ase) { struct bt_bap_ep *ep; + struct bt_bap_ascs_rsp rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); int err; LOG_DBG("ase %p", ase); @@ -2226,8 +2229,8 @@ static void ase_start(struct bt_ascs_ase *ase) /* Valid for an ASE only if ASE_State field = 0x02 (QoS Configured) */ if (ep->status.state != BT_BAP_EP_STATE_ENABLING) { LOG_WRN("Invalid operation in state: %s", bt_bap_ep_state_str(ep->status.state)); - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_START_OP, -EBADMSG, - BT_BAP_ASCS_REASON_NONE); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, BT_BAP_ASCS_REASON_NONE); return; } @@ -2239,8 +2242,8 @@ static void ase_start(struct bt_ascs_ase *ase) */ if (ep->dir == BT_AUDIO_DIR_SINK) { LOG_WRN("Start failed: invalid operation for Sink"); - ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, BT_BAP_ASCS_RSP_CODE_INVALID_DIR, - BT_BAP_ASCS_REASON_NONE); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, + BT_BAP_ASCS_RSP_CODE_INVALID_DIR, BT_BAP_ASCS_REASON_NONE); return; } else if (ep->iso->chan.state != BT_ISO_STATE_CONNECTED) { /* An ASE may not go into the streaming state unless the CIS @@ -2249,19 +2252,27 @@ static void ase_start(struct bt_ascs_ase *ase) LOG_WRN("Start failed: CIS not connected: %u", ep->iso->chan.state); ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, - BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, BT_BAP_ASCS_REASON_NONE); + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, + BT_BAP_ASCS_REASON_NONE); return; } if (unicast_server_cb != NULL && unicast_server_cb->start != NULL) { - err = unicast_server_cb->start(ep->stream); + err = unicast_server_cb->start(ep->stream, &rsp); } else { err = -ENOTSUP; + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + BT_BAP_ASCS_REASON_NONE); } if (err) { - LOG_ERR("Start failed: %d", err); - ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, err, BT_BAP_ASCS_REASON_NONE); + if (rsp.code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, + BT_BAP_ASCS_REASON_NONE); + } + + LOG_ERR("Start failed: err %d, code %u, reason %u", err, rsp.code, rsp.reason); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, rsp.code, rsp.reason); return; } @@ -2377,6 +2388,8 @@ static void ase_stop(struct bt_ascs_ase *ase) { struct bt_bap_stream *stream; struct bt_bap_ep *ep; + struct bt_bap_ascs_rsp rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); int err; LOG_DBG("ase %p", ase); @@ -2398,21 +2411,28 @@ static void ase_stop(struct bt_ascs_ase *ase) if (ep->status.state != BT_BAP_EP_STATE_DISABLING) { LOG_WRN("Invalid operation in state: %s", bt_bap_ep_state_str(ep->status.state)); - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_STOP_OP, -EBADMSG, - BT_BAP_ASCS_REASON_NONE); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_STOP_OP, + BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, BT_BAP_ASCS_REASON_NONE); return; } stream = ep->stream; if (unicast_server_cb != NULL && unicast_server_cb->stop != NULL) { - err = unicast_server_cb->stop(stream); + err = unicast_server_cb->stop(stream, &rsp); } else { err = -ENOTSUP; + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + BT_BAP_ASCS_REASON_NONE); } if (err) { - LOG_ERR("Stop failed: %d", err); - ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_STOP_OP, err, BT_BAP_ASCS_REASON_NONE); + if (rsp.code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, + BT_BAP_ASCS_REASON_NONE); + } + + LOG_ERR("Stop failed: err %d, code %u, reason %u", err, rsp.code, rsp.reason); + ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_STOP_OP, rsp.code, rsp.reason); return; } diff --git a/subsys/bluetooth/audio/bap_broadcast_source.c b/subsys/bluetooth/audio/bap_broadcast_source.c index ab1df281c4eb..21f2d41248b9 100644 --- a/subsys/bluetooth/audio/bap_broadcast_source.c +++ b/subsys/bluetooth/audio/bap_broadcast_source.c @@ -540,7 +540,7 @@ static bool valid_create_param(const struct bt_bap_broadcast_source_create_param return false; } - CHECKIF(!bt_audio_valid_qos(qos)) { + CHECKIF(bt_audio_verify_qos(qos) != BT_BAP_ASCS_REASON_NONE) { LOG_DBG("param->qos is invalid"); return false; } diff --git a/subsys/bluetooth/audio/bap_stream.c b/subsys/bluetooth/audio/bap_stream.c index 1a0ae50585b8..3951bc8807e9 100644 --- a/subsys/bluetooth/audio/bap_stream.c +++ b/subsys/bluetooth/audio/bap_stream.c @@ -136,39 +136,39 @@ int bt_bap_ep_get_info(const struct bt_bap_ep *ep, struct bt_bap_ep_info *info) } #if defined(CONFIG_BT_BAP_UNICAST) || defined(CONFIG_BT_BAP_BROADCAST_SOURCE) -bool bt_audio_valid_qos(const struct bt_codec_qos *qos) +enum bt_bap_ascs_reason bt_audio_verify_qos(const struct bt_codec_qos *qos) { if (qos->interval < BT_ISO_SDU_INTERVAL_MIN || qos->interval > BT_ISO_SDU_INTERVAL_MAX) { LOG_DBG("Interval not within allowed range: %u (%u-%u)", qos->interval, BT_ISO_SDU_INTERVAL_MIN, BT_ISO_SDU_INTERVAL_MAX); - return false; + return BT_BAP_ASCS_REASON_INTERVAL; } if (qos->framing > BT_CODEC_QOS_FRAMED) { LOG_DBG("Invalid Framing 0x%02x", qos->framing); - return false; + return BT_BAP_ASCS_REASON_FRAMING; } if (qos->phy != BT_CODEC_QOS_1M && qos->phy != BT_CODEC_QOS_2M && qos->phy != BT_CODEC_QOS_CODED) { LOG_DBG("Invalid PHY 0x%02x", qos->phy); - return false; + return BT_BAP_ASCS_REASON_PHY; } if (qos->sdu > BT_ISO_MAX_SDU) { LOG_DBG("Invalid SDU %u", qos->sdu); - return false; + return BT_BAP_ASCS_REASON_SDU; } if (qos->latency < BT_ISO_LATENCY_MIN || qos->latency > BT_ISO_LATENCY_MAX) { LOG_DBG("Invalid Latency %u", qos->latency); - return false; + return BT_BAP_ASCS_REASON_LATENCY; } - return true; + return BT_BAP_ASCS_REASON_NONE; } int bt_bap_stream_send(struct bt_bap_stream *stream, struct net_buf *buf, @@ -203,7 +203,8 @@ static bool bt_bap_stream_is_broadcast(const struct bt_bap_stream *stream) (IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SINK) && bt_bap_ep_is_broadcast_snk(stream->ep)); } -bool bt_bap_stream_valid_qos(const struct bt_bap_stream *stream, const struct bt_codec_qos *qos) +enum bt_bap_ascs_reason bt_bap_stream_verify_qos(const struct bt_bap_stream *stream, + const struct bt_codec_qos *qos) { const struct bt_codec_qos_pref *qos_pref = &stream->ep->qos_pref; @@ -215,10 +216,10 @@ bool bt_bap_stream_valid_qos(const struct bt_bap_stream *stream, const struct bt if (!IN_RANGE(qos->pd, qos_pref->pd_min, qos_pref->pd_max)) { LOG_DBG("Presentation Delay not within range: min %u max %u pd %u", qos_pref->pd_min, qos_pref->pd_max, qos->pd); - return false; + return BT_BAP_ASCS_REASON_PD; } - return true; + return BT_BAP_ASCS_REASON_NONE; } void bt_bap_stream_detach(struct bt_bap_stream *stream) diff --git a/subsys/bluetooth/audio/bap_stream.h b/subsys/bluetooth/audio/bap_stream.h index 0c51b47509c1..378b8dbcc88f 100644 --- a/subsys/bluetooth/audio/bap_stream.h +++ b/subsys/bluetooth/audio/bap_stream.h @@ -24,8 +24,9 @@ void bt_audio_codec_qos_to_iso_qos(struct bt_iso_chan_io_qos *io, void bt_bap_stream_detach(struct bt_bap_stream *stream); -bool bt_audio_valid_qos(const struct bt_codec_qos *qos); +enum bt_bap_ascs_reason bt_audio_verify_qos(const struct bt_codec_qos *qos); -bool bt_bap_stream_valid_qos(const struct bt_bap_stream *stream, const struct bt_codec_qos *qos); +enum bt_bap_ascs_reason bt_bap_stream_verify_qos(const struct bt_bap_stream *stream, + const struct bt_codec_qos *qos); struct bt_iso_chan *bt_bap_stream_iso_chan_get(struct bt_bap_stream *stream); diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index ec8e7a6b935d..0fdc582a7700 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -2205,7 +2205,7 @@ static int stream_param_check(const struct bt_bap_unicast_group_stream_param *pa return -EALREADY; } - CHECKIF(!bt_audio_valid_qos(param->qos)) + CHECKIF(bt_audio_verify_qos(param->qos) != BT_BAP_ASCS_REASON_NONE) { LOG_ERR("Invalid QoS"); return -EINVAL; @@ -2520,7 +2520,7 @@ int bt_bap_unicast_client_qos(struct bt_conn *conn, struct bt_bap_unicast_group return -EINVAL; } - if (!bt_bap_stream_valid_qos(stream, stream->qos)) { + if (bt_bap_stream_verify_qos(stream, stream->qos) != BT_BAP_ASCS_REASON_NONE) { return -EINVAL; } diff --git a/subsys/bluetooth/audio/bap_unicast_server.c b/subsys/bluetooth/audio/bap_unicast_server.c index 1b923e3903c4..0fe6449185bc 100644 --- a/subsys/bluetooth/audio/bap_unicast_server.c +++ b/subsys/bluetooth/audio/bap_unicast_server.c @@ -58,6 +58,8 @@ int bt_bap_unicast_server_unregister_cb(const struct bt_bap_unicast_server_cb *c int bt_bap_unicast_server_reconfig(struct bt_bap_stream *stream, const struct bt_codec *codec) { struct bt_bap_ep *ep; + struct bt_bap_ascs_rsp rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); int err; ep = stream->ep; @@ -65,7 +67,7 @@ int bt_bap_unicast_server_reconfig(struct bt_bap_stream *stream, const struct bt if (unicast_server_cb != NULL && unicast_server_cb->reconfig != NULL) { err = unicast_server_cb->reconfig(stream, ep->dir, codec, - &ep->qos_pref); + &ep->qos_pref, &rsp); } else { err = -ENOTSUP; } @@ -108,11 +110,13 @@ int bt_bap_unicast_server_metadata(struct bt_bap_stream *stream, struct bt_codec size_t meta_count) { struct bt_bap_ep *ep; + struct bt_bap_ascs_rsp rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); int err; if (unicast_server_cb != NULL && unicast_server_cb->metadata != NULL) { - err = unicast_server_cb->metadata(stream, meta, meta_count); + err = unicast_server_cb->metadata(stream, meta, meta_count, &rsp); } else { err = -ENOTSUP; } @@ -124,6 +128,7 @@ int bt_bap_unicast_server_metadata(struct bt_bap_stream *stream, struct bt_codec } if (err) { + LOG_ERR("Metadata failed: err %d, code %u, reason %u", err, rsp.code, rsp.reason); return err; } @@ -136,15 +141,18 @@ int bt_bap_unicast_server_metadata(struct bt_bap_stream *stream, struct bt_codec int bt_bap_unicast_server_disable(struct bt_bap_stream *stream) { struct bt_bap_ep *ep; + struct bt_bap_ascs_rsp rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); int err; if (unicast_server_cb != NULL && unicast_server_cb->disable != NULL) { - err = unicast_server_cb->disable(stream); + err = unicast_server_cb->disable(stream, &rsp); } else { err = -ENOTSUP; } if (err != 0) { + LOG_ERR("Disable failed: err %d, code %u, reason %u", err, rsp.code, rsp.reason); return err; } @@ -164,15 +172,18 @@ int bt_bap_unicast_server_disable(struct bt_bap_stream *stream) int bt_bap_unicast_server_release(struct bt_bap_stream *stream) { + struct bt_bap_ascs_rsp rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, + BT_BAP_ASCS_REASON_NONE); int err; if (unicast_server_cb != NULL && unicast_server_cb->release != NULL) { - err = unicast_server_cb->release(stream); + err = unicast_server_cb->release(stream, &rsp); } else { err = -ENOTSUP; } if (err != 0) { + LOG_ERR("Release failed: err %d, code %u, reason %u", err, rsp.code, rsp.reason); return err; } diff --git a/subsys/bluetooth/audio/shell/bap.c b/subsys/bluetooth/audio/shell/bap.c index 537e4be1bdc0..038f9a7fab4c 100644 --- a/subsys/bluetooth/audio/shell/bap.c +++ b/subsys/bluetooth/audio/shell/bap.c @@ -469,7 +469,7 @@ static struct bt_bap_stream *stream_alloc(void) static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_audio_dir dir, const struct bt_codec *codec, struct bt_bap_stream **stream, - struct bt_codec_qos_pref *const pref) + struct bt_codec_qos_pref *const pref, struct bt_bap_ascs_rsp *rsp) { shell_print(ctx_shell, "ASE Codec Config: conn %p ep %p dir %u", conn, ep, dir); @@ -479,6 +479,8 @@ static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_ if (*stream == NULL) { shell_print(ctx_shell, "No unicast_streams available"); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NO_MEM, BT_BAP_ASCS_REASON_NONE); + return -ENOMEM; } @@ -492,7 +494,8 @@ static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_ } static int lc3_reconfig(struct bt_bap_stream *stream, enum bt_audio_dir dir, - const struct bt_codec *codec, struct bt_codec_qos_pref *const pref) + const struct bt_codec *codec, struct bt_codec_qos_pref *const pref, + struct bt_bap_ascs_rsp *rsp) { shell_print(ctx_shell, "ASE Codec Reconfig: stream %p", stream); @@ -507,7 +510,8 @@ static int lc3_reconfig(struct bt_bap_stream *stream, enum bt_audio_dir dir, return 0; } -static int lc3_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos) +static int lc3_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos, + struct bt_bap_ascs_rsp *rsp) { shell_print(ctx_shell, "QoS: stream %p %p", stream, qos); @@ -517,7 +521,7 @@ static int lc3_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos) } static int lc3_enable(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count) + size_t meta_count, struct bt_bap_ascs_rsp *rsp) { shell_print(ctx_shell, "Enable: stream %p meta_count %zu", stream, meta_count); @@ -525,7 +529,7 @@ static int lc3_enable(struct bt_bap_stream *stream, const struct bt_codec_data * return 0; } -static int lc3_start(struct bt_bap_stream *stream) +static int lc3_start(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { shell_print(ctx_shell, "Start: stream %p", stream); @@ -579,17 +583,20 @@ static bool valid_metadata_type(uint8_t type, uint8_t len) } static int lc3_metadata(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count) + size_t meta_count, struct bt_bap_ascs_rsp *rsp) { shell_print(ctx_shell, "Metadata: stream %p meta_count %zu", stream, meta_count); for (size_t i = 0; i < meta_count; i++) { - if (!valid_metadata_type(meta->data.type, meta->data.data_len)) { + const struct bt_codec_data *data = &meta[i]; + + if (!valid_metadata_type(data->data.type, data->data.data_len)) { shell_print(ctx_shell, "Invalid metadata type %u or length %u", - meta->data.type, meta->data.data_len); - + data->data.type, data->data.data_len); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED, + data->data.type); return -EINVAL; } } @@ -597,21 +604,21 @@ static int lc3_metadata(struct bt_bap_stream *stream, const struct bt_codec_data return 0; } -static int lc3_disable(struct bt_bap_stream *stream) +static int lc3_disable(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { shell_print(ctx_shell, "Disable: stream %p", stream); return 0; } -static int lc3_stop(struct bt_bap_stream *stream) +static int lc3_stop(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { shell_print(ctx_shell, "Stop: stream %p", stream); return 0; } -static int lc3_release(struct bt_bap_stream *stream) +static int lc3_release(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { shell_print(ctx_shell, "Release: stream %p", stream); diff --git a/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c index ad2cb6a49bd0..8dc432f4b112 100644 --- a/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_unicast_server_test.c @@ -57,7 +57,7 @@ static struct bt_bap_stream *stream_alloc(void) static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_audio_dir dir, const struct bt_codec *codec, struct bt_bap_stream **stream, - struct bt_codec_qos_pref *const pref) + struct bt_codec_qos_pref *const pref, struct bt_bap_ascs_rsp *rsp) { printk("ASE Codec Config: conn %p ep %p dir %u\n", conn, ep, dir); @@ -66,7 +66,7 @@ static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_ *stream = stream_alloc(); if (*stream == NULL) { printk("No streams available\n"); - + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NO_MEM, BT_BAP_ASCS_REASON_NONE); return -ENOMEM; } @@ -82,17 +82,20 @@ static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_ } static int lc3_reconfig(struct bt_bap_stream *stream, enum bt_audio_dir dir, - const struct bt_codec *codec, struct bt_codec_qos_pref *const pref) + const struct bt_codec *codec, struct bt_codec_qos_pref *const pref, + struct bt_bap_ascs_rsp *rsp) { printk("ASE Codec Reconfig: stream %p\n", stream); print_codec(codec); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED, BT_BAP_ASCS_REASON_NONE); /* We only support one QoS at the moment, reject changes */ return -ENOEXEC; } -static int lc3_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos) +static int lc3_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos, + struct bt_bap_ascs_rsp *rsp) { printk("QoS: stream %p qos %p\n", stream, qos); @@ -102,14 +105,14 @@ static int lc3_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos) } static int lc3_enable(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count) + size_t meta_count, struct bt_bap_ascs_rsp *rsp) { printk("Enable: stream %p meta_count %zu\n", stream, meta_count); return 0; } -static int lc3_start(struct bt_bap_stream *stream) +static int lc3_start(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Start: stream %p\n", stream); @@ -160,15 +163,18 @@ static bool valid_metadata_type(uint8_t type, uint8_t len) } static int lc3_metadata(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count) + size_t meta_count, struct bt_bap_ascs_rsp *rsp) { printk("Metadata: stream %p meta_count %zu\n", stream, meta_count); for (size_t i = 0; i < meta_count; i++) { - if (!valid_metadata_type(meta->data.type, meta->data.data_len)) { - printk("Invalid metadata type %u or length %u\n", meta->data.type, - meta->data.data_len); + const struct bt_codec_data *data = &meta[i]; + if (!valid_metadata_type(data->data.type, data->data.data_len)) { + printk("Invalid metadata type %u or length %u\n", data->data.type, + data->data.data_len); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED, + data->data.type); return -EINVAL; } } @@ -176,21 +182,21 @@ static int lc3_metadata(struct bt_bap_stream *stream, const struct bt_codec_data return 0; } -static int lc3_disable(struct bt_bap_stream *stream) +static int lc3_disable(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Disable: stream %p\n", stream); return 0; } -static int lc3_stop(struct bt_bap_stream *stream) +static int lc3_stop(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Stop: stream %p\n", stream); return 0; } -static int lc3_release(struct bt_bap_stream *stream) +static int lc3_release(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Release: stream %p\n", stream); diff --git a/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c b/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c index c9920695f2eb..1e840cd31449 100644 --- a/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_acceptor_test.c @@ -257,7 +257,8 @@ static struct bt_bap_stream *unicast_stream_alloc(void) static int unicast_server_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_audio_dir dir, const struct bt_codec *codec, struct bt_bap_stream **stream, - struct bt_codec_qos_pref *const pref) + struct bt_codec_qos_pref *const pref, + struct bt_bap_ascs_rsp *rsp) { printk("ASE Codec Config: conn %p ep %p dir %u\n", conn, ep, dir); @@ -266,6 +267,7 @@ static int unicast_server_config(struct bt_conn *conn, const struct bt_bap_ep *e *stream = unicast_stream_alloc(); if (*stream == NULL) { printk("No streams available\n"); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NO_MEM, BT_BAP_ASCS_REASON_NONE); return -ENOMEM; } @@ -281,7 +283,8 @@ static int unicast_server_config(struct bt_conn *conn, const struct bt_bap_ep *e static int unicast_server_reconfig(struct bt_bap_stream *stream, enum bt_audio_dir dir, const struct bt_codec *codec, - struct bt_codec_qos_pref *const pref) + struct bt_codec_qos_pref *const pref, + struct bt_bap_ascs_rsp *rsp) { printk("ASE Codec Reconfig: stream %p\n", stream); @@ -289,11 +292,14 @@ static int unicast_server_reconfig(struct bt_bap_stream *stream, enum bt_audio_d *pref = unicast_qos_pref; + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED, BT_BAP_ASCS_REASON_NONE); + /* We only support one QoS at the moment, reject changes */ return -ENOEXEC; } -static int unicast_server_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos) +static int unicast_server_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos, + struct bt_bap_ascs_rsp *rsp) { printk("QoS: stream %p qos %p\n", stream, qos); @@ -303,14 +309,14 @@ static int unicast_server_qos(struct bt_bap_stream *stream, const struct bt_code } static int unicast_server_enable(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count) + size_t meta_count, struct bt_bap_ascs_rsp *rsp) { printk("Enable: stream %p meta_count %zu\n", stream, meta_count); return 0; } -static int unicast_server_start(struct bt_bap_stream *stream) +static int unicast_server_start(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Start: stream %p\n", stream); @@ -361,15 +367,18 @@ static bool valid_metadata_type(uint8_t type, uint8_t len) } static int unicast_server_metadata(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count) + size_t meta_count, struct bt_bap_ascs_rsp *rsp) { printk("Metadata: stream %p meta_count %zu\n", stream, meta_count); for (size_t i = 0; i < meta_count; i++) { - if (!valid_metadata_type(meta->data.type, meta->data.data_len)) { - printk("Invalid metadata type %u or length %u\n", - meta->data.type, meta->data.data_len); + const struct bt_codec_data *data = &meta[i]; + if (!valid_metadata_type(data->data.type, data->data.data_len)) { + printk("Invalid metadata type %u or length %u\n", data->data.type, + data->data.data_len); + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED, + data->data.type); return -EINVAL; } } @@ -377,21 +386,21 @@ static int unicast_server_metadata(struct bt_bap_stream *stream, const struct bt return 0; } -static int unicast_server_disable(struct bt_bap_stream *stream) +static int unicast_server_disable(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Disable: stream %p\n", stream); return 0; } -static int unicast_server_stop(struct bt_bap_stream *stream) +static int unicast_server_stop(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Stop: stream %p\n", stream); return 0; } -static int unicast_server_release(struct bt_bap_stream *stream) +static int unicast_server_release(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp) { printk("Release: stream %p\n", stream); From a5057e96d12e9d2fc1593ed027c2a37222e785ac Mon Sep 17 00:00:00 2001 From: Omkar Kulkarni Date: Sat, 18 Mar 2023 19:44:48 +0100 Subject: [PATCH 0622/1906] bluetooth: mesh: Do not skip PDU forwarding on ADV Fixes a bug where goto statement results into network layer skipping the forwarding of unicast message on the ADV bearer, if the message gets succesfully sent on the GATT bearer. This is undesirable. Node has no knowledge of which external entity has which unicast address. It may be possible that Proxy node can deliberately add unicast addresses of other nodes to the whitelist to receive some traffic for sniffing. Signed-off-by: Omkar Kulkarni --- subsys/bluetooth/mesh/net.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/subsys/bluetooth/mesh/net.c b/subsys/bluetooth/mesh/net.c index 55f697454e24..ee1a515c904e 100644 --- a/subsys/bluetooth/mesh/net.c +++ b/subsys/bluetooth/mesh/net.c @@ -579,12 +579,8 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf, BT_MESH_ADV(buf)->cb_data = cb_data; /* Deliver to GATT Proxy Clients if necessary. */ - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && - bt_mesh_proxy_relay(buf, tx->ctx->addr) && - BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { - - err = 0; - goto done; + if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { + (void)bt_mesh_proxy_relay(buf, tx->ctx->addr); } /* Deliver to GATT Proxy Servers if necessary. */ From 2fe4a4a2181744c73c0aafccbbedf9d28793d6be Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 11 Oct 2022 13:13:15 +0300 Subject: [PATCH 0623/1906] drivers: watchdog: Add Intel TCO Watchdog driver This adds a basic Intel TCO watchdog driver. The driver doesn't support windowed timeouts (a non-zero window.min value) or callbacks. The driver currently assumes TCO version 6, which can be found e.g. on Elkhart Lake and Raptor Lake platforms. The driver also expects the TCOBA base address to be specified through DTS, rather than doing runtime lookup (using e.g. ACPI or PCIe). Signed-off-by: Johan Hedberg --- drivers/watchdog/CMakeLists.txt | 1 + drivers/watchdog/Kconfig | 2 + drivers/watchdog/Kconfig.tco | 11 + drivers/watchdog/wdt_tco.c | 275 +++++++++++++++++++++++ dts/bindings/watchdog/intel,tco-wdt.yaml | 8 + dts/x86/intel/raptor_lake.dtsi | 5 + 6 files changed, 302 insertions(+) create mode 100644 drivers/watchdog/Kconfig.tco create mode 100644 drivers/watchdog/wdt_tco.c create mode 100644 dts/bindings/watchdog/intel,tco-wdt.yaml diff --git a/drivers/watchdog/CMakeLists.txt b/drivers/watchdog/CMakeLists.txt index e4f25a098e04..bd6fbf465d17 100644 --- a/drivers/watchdog/CMakeLists.txt +++ b/drivers/watchdog/CMakeLists.txt @@ -26,6 +26,7 @@ zephyr_library_sources_ifdef(CONFIG_WDT_RPI_PICO wdt_rpi_pico.c) zephyr_library_sources_ifdef(CONFIG_WDT_SAM wdt_sam.c) zephyr_library_sources_ifdef(CONFIG_WDT_SAM0 wdt_sam0.c) zephyr_library_sources_ifdef(CONFIG_WDT_SIFIVE wdt_sifive.c) +zephyr_library_sources_ifdef(CONFIG_WDT_TCO wdt_tco.c) zephyr_library_sources_ifdef(CONFIG_WDT_XEC wdt_mchp_xec.c) zephyr_library_sources_ifdef(CONFIG_WDT_COUNTER wdt_counter.c) zephyr_library_sources_ifdef(CONFIG_WDT_NXP_S32 wdt_nxp_s32.c) diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 05f43080445e..e8db5f5c29d7 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -100,4 +100,6 @@ source "drivers/watchdog/Kconfig.smartbond" source "drivers/watchdog/Kconfig.ti_tps382x" +source "drivers/watchdog/Kconfig.tco" + endif # WATCHDOG diff --git a/drivers/watchdog/Kconfig.tco b/drivers/watchdog/Kconfig.tco new file mode 100644 index 000000000000..2e479e37efd9 --- /dev/null +++ b/drivers/watchdog/Kconfig.tco @@ -0,0 +1,11 @@ +# Intel TCO WDT support + +# Copyright (c) 2022 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +config WDT_TCO + bool "Intel TCO Watchdog driver" + default y + depends on DT_HAS_INTEL_TCO_WDT_ENABLED + help + Enable support for Intel TCO WDT driver. diff --git a/drivers/watchdog/wdt_tco.c b/drivers/watchdog/wdt_tco.c new file mode 100644 index 000000000000..8c6382ad4bb6 --- /dev/null +++ b/drivers/watchdog/wdt_tco.c @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ +#define DT_DRV_COMPAT intel_tco_wdt + +#include +#include +#include + +LOG_MODULE_REGISTER(wdt_tco, CONFIG_WDT_LOG_LEVEL); + +#define TCO_WDT_NODE DT_NODELABEL(tco_wdt) + +#define BASE(d) ((struct tco_config *)(d)->config)->base + +#define TCO_RLD(d) (BASE(d) + 0x00) /* TCO Timer Reload/Curr. Value */ +#define TCO_DAT_IN(d) (BASE(d) + 0x02) /* TCO Data In Register */ +#define TCO_DAT_OUT(d) (BASE(d) + 0x03) /* TCO Data Out Register */ +#define TCO1_STS(d) (BASE(d) + 0x04) /* TCO1 Status Register */ +#define TCO2_STS(d) (BASE(d) + 0x06) /* TCO2 Status Register */ +#define TCO1_CNT(d) (BASE(d) + 0x08) /* TCO1 Control Register */ +#define TCO2_CNT(d) (BASE(d) + 0x0a) /* TCO2 Control Register */ +#define TCO_MSG(d) (BASE(d) + 0x0c) /* TCO Message Registers */ +#define TCO_WDSTATUS(d) (BASE(d) + 0x0e) /* TCO Watchdog Status Register */ +#define TCO_TMR(d) (BASE(d) + 0x12) /* TCO Timer Register */ + +/* TCO1_STS bits */ +#define STS_NMI2SMI BIT(0) +#define STS_OS_TCO_SMI BIT(1) +#define STS_TCO_INT BIT(2) +#define STS_TIMEOUT BIT(3) +#define STS_NEWCENTURY BIT(7) +#define STS_BIOSWR BIT(8) +#define STS_CPUSCI BIT(9) +#define STS_CPUSMI BIT(10) +#define STS_CPUSERR BIT(12) +#define STS_SLVSEL BIT(13) + +/* TCO2_STS bits */ +#define STS_INTRD_DET BIT(0) +#define STS_SECOND_TO BIT(1) +#define STS_NRSTRAP BIT(2) +#define STS_SMLINK_SLAVE_SMI BIT(3) + +/* TCO1_CNT bits */ +#define CNT_NR_MSUS BIT(0) +#define CNT_NMI_NOW BIT(8) +#define CNT_NMI2SMI_EN BIT(9) +#define CNT_TCO_TMR_HALT BIT(11) +#define CNT_TCO_LOCK BIT(12) + +/* TCO_TMR bits */ +#define TMR_TCOTMR BIT_MASK(10) +#define TMR_MIN 0x04 +#define TMR_MAX 0x3f + +struct tco_data { + struct k_spinlock lock; + bool no_reboot; +}; + +struct tco_config { + io_port_t base; +}; + +static int set_no_reboot(const struct device *dev, bool set) +{ + uint16_t val, newval; + + val = sys_in16(TCO1_CNT(dev)); + + if (set) { + val |= CNT_NR_MSUS; + } else { + val &= ~CNT_NR_MSUS; + } + + sys_out16(val, TCO1_CNT(dev)); + newval = sys_in16(TCO1_CNT(dev)); + + if (val != newval) { + return -EIO; + } + + return 0; +} + +static int tco_setup(const struct device *dev, uint8_t options) +{ + struct tco_data *data = dev->data; + k_spinlock_key_t key; + uint16_t val; + int err; + + key = k_spin_lock(&data->lock); + + err = set_no_reboot(dev, data->no_reboot); + if (err) { + k_spin_unlock(&data->lock, key); + LOG_ERR("Failed to update no_reboot bit (err %d)", err); + return err; + } + + /* Reload the timer */ + sys_out16(0x01, TCO_RLD(dev)); + + /* Enable the timer to start counting by clearing the TCO_TMR_HALT field */ + val = sys_in16(TCO1_CNT(dev)); + val &= ~CNT_TCO_TMR_HALT; + sys_out16(val, TCO1_CNT(dev)); + val = sys_in16(TCO1_CNT(dev)); + + k_spin_unlock(&data->lock, key); + + if ((val & CNT_TCO_TMR_HALT) == CNT_TCO_TMR_HALT) { + return -EIO; + } + + return 0; +} + +static int tco_disable(const struct device *dev) +{ + struct tco_data *data = dev->data; + k_spinlock_key_t key; + uint16_t val; + + key = k_spin_lock(&data->lock); + + /* Set the TCO_TMR_HALT field so that the timer gets halted */ + val = sys_in16(TCO1_CNT(dev)); + val |= CNT_TCO_TMR_HALT; + sys_out16(val, TCO1_CNT(dev)); + val = sys_in16(TCO1_CNT(dev)); + + set_no_reboot(dev, true); + + k_spin_unlock(&data->lock, key); + + if ((val & CNT_TCO_TMR_HALT) == 0) { + return -EIO; + } + + return 0; +} + +static uint16_t msec_to_ticks(uint32_t msec) +{ + /* Convert from milliseconds to timer ticks. The timer is clocked at + * approximately 0.6 seconds. + */ + return ((msec / MSEC_PER_SEC) * 10) / 6; +} + +static int tco_install_timeout(const struct device *dev, + const struct wdt_timeout_cfg *cfg) +{ + struct tco_data *data = dev->data; + k_spinlock_key_t key; + uint16_t val, ticks; + + /* TCO watchdog doesn't support windowed timeouts */ + if (cfg->window.min != 0) { + return -EINVAL; + } + + /* No callback support */ + if (cfg->callback != NULL) { + return -ENOTSUP; + } + + ticks = msec_to_ticks(cfg->window.max); + + LOG_DBG("window.max %u -> ticks %u", cfg->window.max, ticks); + + if (ticks < TMR_MIN || ticks > TMR_MAX) { + return -EINVAL; + } + + switch (cfg->flags) { + case WDT_FLAG_RESET_SOC: + data->no_reboot = false; + break; + case WDT_FLAG_RESET_NONE: + data->no_reboot = true; + break; + case WDT_FLAG_RESET_CPU_CORE: + LOG_ERR("CPU-only reset not supported"); + return -ENOTSUP; + default: + LOG_ERR("Unknown watchdog configuration flags"); + return -EINVAL; + } + + key = k_spin_lock(&data->lock); + + /* Set the TCO_TMR field. This value is loaded into the timer each time + * the TCO_RLD register is written. + */ + val = sys_in16(TCO_TMR(dev)); + val &= ~TMR_TCOTMR; + val |= ticks; + sys_out16(val, TCO_TMR(dev)); + val = sys_in16(TCO_TMR(dev)); + + k_spin_unlock(&data->lock, key); + + if ((val & TMR_TCOTMR) != ticks) { + LOG_ERR("val %u", val); + return -EIO; + } + + return 0; +} + +static int tco_feed(const struct device *dev, int channel_id) +{ + struct tco_data *data = dev->data; + k_spinlock_key_t key; + + key = k_spin_lock(&data->lock); + + /* TCORLD: Writing any value to this register will reload the timer to + * prevent the timeout. + */ + sys_out16(0x01, TCO_RLD(dev)); + + k_spin_unlock(&data->lock, key); + + return 0; +} + +static const struct wdt_driver_api tco_driver_api = { + .setup = tco_setup, + .disable = tco_disable, + .install_timeout = tco_install_timeout, + .feed = tco_feed, +}; + +static int wdt_init(const struct device *dev) +{ + const struct tco_config *config = dev->config; + struct tco_data *data = dev->data; + k_spinlock_key_t key; + + LOG_DBG("Using 0x%04x as TCOBA", config->base); + + key = k_spin_lock(&data->lock); + + sys_out16(STS_TIMEOUT, TCO1_STS(dev)); /* Clear the Time Out Status bit */ + sys_out16(STS_SECOND_TO, TCO2_STS(dev)); /* Clear SECOND_TO_STS bit */ + + set_no_reboot(dev, data->no_reboot); + + k_spin_unlock(&data->lock, key); + + if (IS_ENABLED(CONFIG_WDT_DISABLE_AT_BOOT)) { + tco_disable(dev); + } + + return 0; +} + +static struct tco_data wdt_data = { +}; + +static const struct tco_config wdt_config = { + .base = DT_REG_ADDR(TCO_WDT_NODE), +}; + +DEVICE_DT_DEFINE(TCO_WDT_NODE, wdt_init, NULL, &wdt_data, &wdt_config, + PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, + &tco_driver_api); diff --git a/dts/bindings/watchdog/intel,tco-wdt.yaml b/dts/bindings/watchdog/intel,tco-wdt.yaml new file mode 100644 index 000000000000..af1f00902d74 --- /dev/null +++ b/dts/bindings/watchdog/intel,tco-wdt.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2022 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +description: Intel TCO Watchdog driver binding + +compatible: "intel,tco-wdt" + +include: base.yaml diff --git a/dts/x86/intel/raptor_lake.dtsi b/dts/x86/intel/raptor_lake.dtsi index 55e21825a095..723f72fc4996 100644 --- a/dts/x86/intel/raptor_lake.dtsi +++ b/dts/x86/intel/raptor_lake.dtsi @@ -413,5 +413,10 @@ reg = <0x70 0x0D 0x71 0x0D>; status = "okay"; }; + + tco_wdt: tco_wdt@400 { + compatible = "intel,tco-wdt"; + reg = <0x0400 0x20>; + }; }; }; From 4bfebf0a9c12291d1caab12b9b81cf293431f06f Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 17 Oct 2022 12:52:32 +0300 Subject: [PATCH 0624/1906] samples: watchdog: Add support for Intel TCO watchdog Add appropriate configuration parameters for using the Intel TCO watchdog driver with the rpl_crb board. Signed-off-by: Johan Hedberg --- boards/x86/rpl_crb/rpl_crb.dts | 4 ++++ boards/x86/rpl_crb/rpl_crb.yaml | 2 ++ samples/drivers/watchdog/boards/rpl_crb.overlay | 9 +++++++++ samples/drivers/watchdog/src/main.c | 3 +++ .../watchdog/wdt_basic_api/boards/rpl_crb.overlay | 9 +++++++++ tests/drivers/watchdog/wdt_basic_api/src/test_wdt.c | 4 ++++ 6 files changed, 31 insertions(+) create mode 100644 samples/drivers/watchdog/boards/rpl_crb.overlay create mode 100644 tests/drivers/watchdog/wdt_basic_api/boards/rpl_crb.overlay diff --git a/boards/x86/rpl_crb/rpl_crb.dts b/boards/x86/rpl_crb/rpl_crb.dts index 2558a399e2b6..59d0baf52e79 100644 --- a/boards/x86/rpl_crb/rpl_crb.dts +++ b/boards/x86/rpl_crb/rpl_crb.dts @@ -20,4 +20,8 @@ zephyr,console = &uart_ec_0; zephyr,shell-uart = &uart_ec_0; }; + + aliases { + watchdog0 = &tco_wdt; + }; }; diff --git a/boards/x86/rpl_crb/rpl_crb.yaml b/boards/x86/rpl_crb/rpl_crb.yaml index b48d3829ca29..995382f8bd7c 100644 --- a/boards/x86/rpl_crb/rpl_crb.yaml +++ b/boards/x86/rpl_crb/rpl_crb.yaml @@ -5,6 +5,8 @@ arch: x86 toolchain: - zephyr ram: 2048 +supported: + - watchdog testing: ignore_tags: - net diff --git a/samples/drivers/watchdog/boards/rpl_crb.overlay b/samples/drivers/watchdog/boards/rpl_crb.overlay new file mode 100644 index 000000000000..660b55c05121 --- /dev/null +++ b/samples/drivers/watchdog/boards/rpl_crb.overlay @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2023 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&tco_wdt { + status = "okay"; +}; diff --git a/samples/drivers/watchdog/src/main.c b/samples/drivers/watchdog/src/main.c index af9aeceda30c..b93b1e1c62f6 100644 --- a/samples/drivers/watchdog/src/main.c +++ b/samples/drivers/watchdog/src/main.c @@ -31,6 +31,9 @@ #define WDT_MAX_WINDOW 24U #define WDT_MIN_WINDOW 18U #define WDG_FEED_INTERVAL 12U +#elif DT_HAS_COMPAT_STATUS_OKAY(intel_tco_wdt) +#define WDT_ALLOW_CALLBACK 0 +#define WDT_MAX_WINDOW 3000U #endif #ifndef WDT_ALLOW_CALLBACK diff --git a/tests/drivers/watchdog/wdt_basic_api/boards/rpl_crb.overlay b/tests/drivers/watchdog/wdt_basic_api/boards/rpl_crb.overlay new file mode 100644 index 000000000000..660b55c05121 --- /dev/null +++ b/tests/drivers/watchdog/wdt_basic_api/boards/rpl_crb.overlay @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2023 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&tco_wdt { + status = "okay"; +}; diff --git a/tests/drivers/watchdog/wdt_basic_api/src/test_wdt.c b/tests/drivers/watchdog/wdt_basic_api/src/test_wdt.c index d5772ee11f7f..43bb751277f6 100644 --- a/tests/drivers/watchdog/wdt_basic_api/src/test_wdt.c +++ b/tests/drivers/watchdog/wdt_basic_api/src/test_wdt.c @@ -103,6 +103,10 @@ #define WDT_TEST_MAX_WINDOW 20000U #define TIMEOUTS 0 #endif +#if DT_HAS_COMPAT_STATUS_OKAY(intel_tco_wdt) +#define TIMEOUTS 0 +#define WDT_TEST_MAX_WINDOW 3000U +#endif #define WDT_TEST_STATE_IDLE 0 #define WDT_TEST_STATE_CHECK_RESET 1 From b8d441842a804c423cf3b0161a68b5b0cad5060e Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Fri, 17 Mar 2023 07:45:24 +0100 Subject: [PATCH 0625/1906] Bluetooth: audio: ascs: Add cleanup function This adds ascs_cleanup() function guarded by ZTEST_UNITTEST. The purpose of it is to clean up the ASCS between the tests. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index cf3dbc2fe0a2..6bc329013365 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -2717,4 +2717,41 @@ static int control_point_notify(struct bt_conn *conn, const void *data, uint16_t return bt_gatt_notify_uuid(conn, BT_UUID_ASCS_ASE_CP, ascs_svc.attrs, data, len); } +#if defined(ZTEST_UNITTEST) +static void ase_cleanup(struct bt_ascs_ase *ase) +{ + if (ase->ep.iso != NULL) { + bt_bap_iso_unbind_ep(ase->ep.iso, &ase->ep); + } + + if (ase->ep.stream != NULL) { + bt_bap_stream_detach(ase->ep.stream); + } + + bt_ascs_ase_return_to_slab(ase); +} + +void ascs_cleanup(void) +{ + for (size_t i = 0; i < ARRAY_SIZE(sessions); i++) { + struct bt_ascs *session = &sessions[i]; + sys_snode_t *node, *tmp; + + if (session->conn == NULL) { + continue; + } + + SYS_SLIST_FOR_EACH_NODE_SAFE(&session->ases, node, tmp) { + struct bt_ascs_ase *ase; + + ase = CONTAINER_OF(node, struct bt_ascs_ase, node); + + ase_cleanup(ase); + } + + bt_conn_unref(session->conn); + session->conn = NULL; + } +} +#endif /* ZTEST_UNITTEST */ #endif /* BT_BAP_UNICAST_SERVER */ From 269290d614a11ebc9dd5d1b0aac8dfb6185b2be2 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Fri, 17 Mar 2023 08:07:32 +0100 Subject: [PATCH 0626/1906] tests: bluetooth: audio: Add mocks for audio This adds common mocks to be used while unit testing Bluetooth Audio code. Signed-off-by: Mariusz Skamra --- tests/bluetooth/audio/mocks/CMakeLists.txt | 34 +++ .../audio/mocks/include/ascs_help_utils.h | 8 + .../audio/mocks/include/bap_stream.h | 31 +++ .../audio/mocks/include/bap_stream_expects.h | 226 ++++++++++++++++++ .../audio/mocks/include/bap_unicast_server.h | 35 +++ .../include/bap_unicast_server_expects.h | 111 +++++++++ tests/bluetooth/audio/mocks/include/conn.h | 17 ++ .../audio/mocks/include/expects_util.h | 32 +++ tests/bluetooth/audio/mocks/include/gatt.h | 24 ++ .../audio/mocks/include/gatt_expects.h | 111 +++++++++ tests/bluetooth/audio/mocks/include/iso.h | 24 ++ .../audio/mocks/include/mock_kernel.h | 31 +++ tests/bluetooth/audio/mocks/include/pacs.h | 19 ++ tests/bluetooth/audio/mocks/mock-sections.ld | 21 ++ tests/bluetooth/audio/mocks/src/bap_stream.c | 58 +++++ .../audio/mocks/src/bap_unicast_server.c | 59 +++++ tests/bluetooth/audio/mocks/src/conn.c | 31 +++ tests/bluetooth/audio/mocks/src/fatal.c | 13 + tests/bluetooth/audio/mocks/src/gatt.c | 221 +++++++++++++++++ tests/bluetooth/audio/mocks/src/iso.c | 14 ++ tests/bluetooth/audio/mocks/src/kernel.c | 18 ++ tests/bluetooth/audio/mocks/src/mem_slab.c | 28 +++ tests/bluetooth/audio/mocks/src/pacs.c | 11 + 23 files changed, 1177 insertions(+) create mode 100644 tests/bluetooth/audio/mocks/CMakeLists.txt create mode 100644 tests/bluetooth/audio/mocks/include/ascs_help_utils.h create mode 100644 tests/bluetooth/audio/mocks/include/bap_stream.h create mode 100644 tests/bluetooth/audio/mocks/include/bap_stream_expects.h create mode 100644 tests/bluetooth/audio/mocks/include/bap_unicast_server.h create mode 100644 tests/bluetooth/audio/mocks/include/bap_unicast_server_expects.h create mode 100644 tests/bluetooth/audio/mocks/include/conn.h create mode 100644 tests/bluetooth/audio/mocks/include/expects_util.h create mode 100644 tests/bluetooth/audio/mocks/include/gatt.h create mode 100644 tests/bluetooth/audio/mocks/include/gatt_expects.h create mode 100644 tests/bluetooth/audio/mocks/include/iso.h create mode 100644 tests/bluetooth/audio/mocks/include/mock_kernel.h create mode 100644 tests/bluetooth/audio/mocks/include/pacs.h create mode 100644 tests/bluetooth/audio/mocks/mock-sections.ld create mode 100644 tests/bluetooth/audio/mocks/src/bap_stream.c create mode 100644 tests/bluetooth/audio/mocks/src/bap_unicast_server.c create mode 100644 tests/bluetooth/audio/mocks/src/conn.c create mode 100644 tests/bluetooth/audio/mocks/src/fatal.c create mode 100644 tests/bluetooth/audio/mocks/src/gatt.c create mode 100644 tests/bluetooth/audio/mocks/src/iso.c create mode 100644 tests/bluetooth/audio/mocks/src/kernel.c create mode 100644 tests/bluetooth/audio/mocks/src/mem_slab.c create mode 100644 tests/bluetooth/audio/mocks/src/pacs.c diff --git a/tests/bluetooth/audio/mocks/CMakeLists.txt b/tests/bluetooth/audio/mocks/CMakeLists.txt new file mode 100644 index 000000000000..c01ffeb05458 --- /dev/null +++ b/tests/bluetooth/audio/mocks/CMakeLists.txt @@ -0,0 +1,34 @@ +# +# Copyright (c) 2023 Codecoup +# +# SPDX-License-Identifier: Apache-2.0 +# +# CMakeLists.txt file for creating of mocks library. +# + +add_library(mocks STATIC + src/bap_stream.c + src/bap_unicast_server.c + src/conn.c + src/fatal.c + src/gatt.c + src/iso.c + src/kernel.c + src/mem_slab.c + src/pacs.c +) + +target_include_directories(mocks PUBLIC + include + ${ZEPHYR_BASE}/tests/bluetooth/audio + ${ZEPHYR_BASE}/subsys/bluetooth + ${ZEPHYR_BASE}/subsys/bluetooth/audio +) + +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/host host_mocks) + +target_link_libraries(mocks PRIVATE test_interface host_mocks) + +target_link_options(mocks PUBLIC + -T "${ZEPHYR_BASE}/tests/bluetooth/audio/mocks/mock-sections.ld" +) diff --git a/tests/bluetooth/audio/mocks/include/ascs_help_utils.h b/tests/bluetooth/audio/mocks/include/ascs_help_utils.h new file mode 100644 index 000000000000..5c7dcd9a9e8f --- /dev/null +++ b/tests/bluetooth/audio/mocks/include/ascs_help_utils.h @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* ascs.c declarations */ +void ascs_cleanup(void); diff --git a/tests/bluetooth/audio/mocks/include/bap_stream.h b/tests/bluetooth/audio/mocks/include/bap_stream.h new file mode 100644 index 000000000000..553c0cded746 --- /dev/null +++ b/tests/bluetooth/audio/mocks/include/bap_stream.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef MOCKS_BAP_STREAM_H_ +#define MOCKS_BAP_STREAM_H_ + +#include +#include + +extern struct bt_bap_stream_ops mock_bap_stream_ops; + +void mock_bap_stream_init(void); +void mock_bap_stream_cleanup(void); + +DECLARE_FAKE_VOID_FUNC(mock_bap_stream_configured_cb, struct bt_bap_stream *, + const struct bt_codec_qos_pref *); +DECLARE_FAKE_VOID_FUNC(mock_bap_stream_qos_set_cb, struct bt_bap_stream *); +DECLARE_FAKE_VOID_FUNC(mock_bap_stream_enabled_cb, struct bt_bap_stream *); +DECLARE_FAKE_VOID_FUNC(mock_bap_stream_metadata_updated_cb, struct bt_bap_stream *); +DECLARE_FAKE_VOID_FUNC(mock_bap_stream_disabled_cb, struct bt_bap_stream *); +DECLARE_FAKE_VOID_FUNC(mock_bap_stream_released_cb, struct bt_bap_stream *); +DECLARE_FAKE_VOID_FUNC(mock_bap_stream_started_cb, struct bt_bap_stream *); +DECLARE_FAKE_VOID_FUNC(mock_bap_stream_stopped_cb, struct bt_bap_stream *, uint8_t); +DECLARE_FAKE_VOID_FUNC(mock_bap_stream_recv_cb, struct bt_bap_stream *, + const struct bt_iso_recv_info *, struct net_buf *); +DECLARE_FAKE_VOID_FUNC(mock_bap_stream_sent_cb, struct bt_bap_stream *); + +#endif /* MOCKS_BAP_STREAM_H_ */ diff --git a/tests/bluetooth/audio/mocks/include/bap_stream_expects.h b/tests/bluetooth/audio/mocks/include/bap_stream_expects.h new file mode 100644 index 000000000000..32985e5b4322 --- /dev/null +++ b/tests/bluetooth/audio/mocks/include/bap_stream_expects.h @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef MOCKS_BAP_STREAM_EXPECTS_H_ +#define MOCKS_BAP_STREAM_EXPECTS_H_ + +#include + +#include "bap_stream.h" +#include "expects_util.h" + +#define expect_bt_bap_stream_ops_configured_called_once(_stream, _pref) \ +do { \ + const char *func_name = "bt_bap_stream_ops.configured"; \ + \ + zassert_equal(1, mock_bap_stream_configured_cb_fake.call_count, \ + "'%s()' was called %u times, but expected once", \ + func_name, mock_bap_stream_configured_cb_fake.call_count); \ + \ + IF_NOT_EMPTY(_stream, ( \ + zassert_equal_ptr(_stream, mock_bap_stream_configured_cb_fake.arg0_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "stream");)) \ + \ + IF_NOT_EMPTY(_pref, ( \ + /* TODO */ \ + zassert_unreachable("Not implemented");)) \ +} while (0) + +static inline void expect_bt_bap_stream_ops_configured_not_called(void) +{ + const char *func_name = "bt_bap_stream_ops.configured"; + + zassert_equal(0, mock_bap_stream_configured_cb_fake.call_count, + "'%s()' was called unexpectedly", func_name); +} + +static inline void expect_bt_bap_stream_ops_qos_set_called_once(struct bt_bap_stream *stream) +{ + const char *func_name = "bt_bap_stream_ops.qos_set"; + + zassert_equal(1, mock_bap_stream_qos_set_cb_fake.call_count, + "'%s()' was called %u times, but expected once", + func_name, mock_bap_stream_qos_set_cb_fake.call_count); + + zassert_equal_ptr(stream, mock_bap_stream_qos_set_cb_fake.arg0_val, + "'%s()' was called with incorrect '%s'", func_name, "stream"); +} + +static inline void expect_bt_bap_stream_ops_qos_set_not_called(void) +{ + const char *func_name = "bt_bap_stream_ops.qos_set"; + + zassert_equal(1, mock_bap_stream_qos_set_cb_fake.call_count, + "'%s()' was called unexpectedly", func_name); +} + +static inline void expect_bt_bap_stream_ops_enabled_called_once(struct bt_bap_stream *stream) +{ + const char *func_name = "bt_bap_stream_ops.enabled"; + + zassert_equal(1, mock_bap_stream_enabled_cb_fake.call_count, + "'%s()' was called %u times, but expected once", + func_name, mock_bap_stream_enabled_cb_fake.call_count); + + zassert_equal_ptr(stream, mock_bap_stream_enabled_cb_fake.arg0_val, + "'%s()' was called with incorrect '%s'", func_name, "stream"); +} + +static inline void expect_bt_bap_stream_ops_enabled_not_called(void) +{ + const char *func_name = "bt_bap_stream_ops.enabled"; + + zassert_equal(0, mock_bap_stream_enabled_cb_fake.call_count, + "'%s()' was called unexpectedly", func_name); +} + +static inline void expect_bt_bap_stream_ops_metadata_updated_called_once( + struct bt_bap_stream *stream) +{ + const char *func_name = "bt_bap_stream_ops.metadata_updated"; + + zassert_equal(1, mock_bap_stream_metadata_updated_cb_fake.call_count, + "'%s()' was called %u times, but expected once", + func_name, mock_bap_stream_metadata_updated_cb_fake.call_count); + + zassert_equal_ptr(stream, mock_bap_stream_metadata_updated_cb_fake.arg0_val, + "'%s()' was called with incorrect '%s'", func_name, "stream"); +} + +static inline void expect_bt_bap_stream_ops_metadata_updated_not_called(void) +{ + const char *func_name = "bt_bap_stream_ops.metadata_updated"; + + zassert_equal(0, mock_bap_stream_metadata_updated_cb_fake.call_count, + "'%s()' was called unexpectedly", func_name); +} + +static inline void expect_bt_bap_stream_ops_disabled_called_once(struct bt_bap_stream *stream) +{ + const char *func_name = "bt_bap_stream_ops.disabled"; + + zassert_equal(1, mock_bap_stream_disabled_cb_fake.call_count, + "'%s()' was called %u times, but expected once", + func_name, mock_bap_stream_disabled_cb_fake.call_count); + + zassert_equal_ptr(stream, mock_bap_stream_disabled_cb_fake.arg0_val, + "'%s()' was called with incorrect '%s'", func_name, "stream"); +} + +static inline void expect_bt_bap_stream_ops_disabled_not_called(void) +{ + const char *func_name = "bt_bap_stream_ops.disabled"; + + zassert_equal(0, mock_bap_stream_disabled_cb_fake.call_count, + "'%s()' was called unexpectedly", func_name); +} + +static inline void expect_bt_bap_stream_ops_released_called_once(struct bt_bap_stream *stream) +{ + const char *func_name = "bt_bap_stream_ops.released"; + + zassert_equal(1, mock_bap_stream_released_cb_fake.call_count, + "'%s()' was called %u times, but expected once", + func_name, mock_bap_stream_released_cb_fake.call_count); + + zassert_equal_ptr(stream, mock_bap_stream_released_cb_fake.arg0_val, + "'%s()' was called with incorrect '%s'", func_name, "stream"); +} + +static inline void expect_bt_bap_stream_ops_released_not_called(void) +{ + const char *func_name = "bt_bap_stream_ops.released"; + + zassert_equal(0, mock_bap_stream_released_cb_fake.call_count, + "'%s()' was called unexpectedly", func_name); +} + +static inline void expect_bt_bap_stream_ops_started_called_once(struct bt_bap_stream *stream) +{ + const char *func_name = "bt_bap_stream_ops.started"; + + zassert_equal(1, mock_bap_stream_started_cb_fake.call_count, + "'%s()' was called %u times, but expected once", + func_name, mock_bap_stream_started_cb_fake.call_count); + + zassert_equal_ptr(stream, mock_bap_stream_started_cb_fake.arg0_val, + "'%s()' was called with incorrect '%s'", func_name, "stream"); +} + +static inline void expect_bt_bap_stream_ops_started_not_called(void) +{ + const char *func_name = "bt_bap_stream_ops.started"; + + zassert_equal(0, mock_bap_stream_started_cb_fake.call_count, + "'%s()' was called unexpectedly", func_name); +} + +static inline void expect_bt_bap_stream_ops_stopped_called_once(struct bt_bap_stream *stream, + uint8_t reason) +{ + const char *func_name = "bt_bap_stream_ops.stopped"; + + zassert_equal(1, mock_bap_stream_stopped_cb_fake.call_count, + "'%s()' was called %u times, but expected once", + func_name, mock_bap_stream_stopped_cb_fake.call_count); + + zassert_equal_ptr(stream, mock_bap_stream_stopped_cb_fake.arg0_val, + "'%s()' was called with incorrect '%s'", func_name, "stream"); +} + +static inline void expect_bt_bap_stream_ops_stopped_not_called(void) +{ + const char *func_name = "bt_bap_stream_ops.stopped"; + + zassert_equal(0, mock_bap_stream_stopped_cb_fake.call_count, + "'%s()' was called unexpectedly", func_name); +} + +static inline void expect_bt_bap_stream_ops_recv_called_once(struct bt_bap_stream *stream, + const struct bt_iso_recv_info *info, + struct net_buf *buf) +{ + const char *func_name = "bt_bap_stream_ops.recv"; + + zassert_equal(1, mock_bap_stream_recv_cb_fake.call_count, + "'%s()' was called %u times, but expected once", + func_name, mock_bap_stream_recv_cb_fake.call_count); + + zassert_equal_ptr(stream, mock_bap_stream_recv_cb_fake.arg0_val, + "'%s()' was called with incorrect '%s'", func_name, "stream"); + /* TODO: validate info && buf */ +} + +static inline void expect_bt_bap_stream_ops_recv_not_called(void) +{ + const char *func_name = "bt_bap_stream_ops.recv"; + + zassert_equal(0, mock_bap_stream_recv_cb_fake.call_count, + "'%s()' was called unexpectedly", func_name); +} + +static inline void expect_bt_bap_stream_ops_sent_called_once(struct bt_bap_stream *stream) +{ + const char *func_name = "bt_bap_stream_ops.sent"; + + zassert_equal(1, mock_bap_stream_sent_cb_fake.call_count, + "'%s()' was called %u times, but expected once", + func_name, mock_bap_stream_sent_cb_fake.call_count); + + zassert_equal_ptr(stream, mock_bap_stream_sent_cb_fake.arg0_val, + "'%s()' was called with incorrect '%s'", func_name, "stream"); +} + +static inline void expect_bt_bap_stream_ops_sent_not_called(void) +{ + const char *func_name = "bt_bap_stream_ops.sent"; + + zassert_equal(0, mock_bap_stream_sent_cb_fake.call_count, + "'%s()' was called unexpectedly", func_name); +} + +#endif /* MOCKS_BAP_STREAM_EXPECTS_H_ */ diff --git a/tests/bluetooth/audio/mocks/include/bap_unicast_server.h b/tests/bluetooth/audio/mocks/include/bap_unicast_server.h new file mode 100644 index 000000000000..dc6bf33a4c3a --- /dev/null +++ b/tests/bluetooth/audio/mocks/include/bap_unicast_server.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef MOCKS_BAP_UNICAST_SERVER_H_ +#define MOCKS_BAP_UNICAST_SERVER_H_ + +#include +#include + +extern const struct bt_bap_unicast_server_cb mock_bap_unicast_server_cb; + +void mock_bap_unicast_server_init(void); +void mock_bap_unicast_server_cleanup(void); + +DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_config, struct bt_conn *, + const struct bt_bap_ep *, enum bt_audio_dir, const struct bt_codec *, + struct bt_bap_stream **, struct bt_codec_qos_pref *const); +DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_reconfig, struct bt_bap_stream *, + enum bt_audio_dir, const struct bt_codec *, + struct bt_codec_qos_pref *const); +DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_qos, struct bt_bap_stream *, + const struct bt_codec_qos *); +DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_enable, struct bt_bap_stream *, + const struct bt_codec_data *, size_t); +DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_start, struct bt_bap_stream *); +DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_metadata, struct bt_bap_stream *, + const struct bt_codec_data *, size_t); +DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_disable, struct bt_bap_stream *); +DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_stop, struct bt_bap_stream *); +DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_release, struct bt_bap_stream *); + +#endif /* MOCKS_BAP_UNICAST_SERVER_H_ */ diff --git a/tests/bluetooth/audio/mocks/include/bap_unicast_server_expects.h b/tests/bluetooth/audio/mocks/include/bap_unicast_server_expects.h new file mode 100644 index 000000000000..269e85dec9bb --- /dev/null +++ b/tests/bluetooth/audio/mocks/include/bap_unicast_server_expects.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef MOCKS_BAP_UNICAST_SERVER_EXPECTS_H_ +#define MOCKS_BAP_UNICAST_SERVER_EXPECTS_H_ + +#include + +#include "bap_unicast_server.h" +#include "expects_util.h" + +#define expect_bt_bap_unicast_server_cb_config_called_once(_conn, _ep, _dir, _codec) \ +do { \ + const char *func_name = "bt_bap_unicast_server_cb.config"; \ + \ + zassert_equal(1, mock_bap_unicast_server_cb_config_fake.call_count, \ + "'%s()' was called %u times, but expected once", \ + func_name, mock_bap_unicast_server_cb_config_fake.call_count); \ + \ + IF_NOT_EMPTY(_conn, ( \ + zassert_equal_ptr(_conn, mock_bap_unicast_server_cb_config_fake.arg0_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "conn");)) \ + \ + IF_NOT_EMPTY(_ep, ( \ + zassert_equal_ptr(_ep, mock_bap_unicast_server_cb_config_fake.arg1_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "ep");)) \ + \ + IF_NOT_EMPTY(_dir, ( \ + zassert_equal(_dir, mock_bap_unicast_server_cb_config_fake.arg2_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "_dir");)) \ + \ + IF_NOT_EMPTY(_codec, ( \ + /* TODO */ \ + zassert_unreachable("Not implemented");)) \ +} while (0) + +#define expect_bt_bap_unicast_server_cb_qos_called_once(_stream, _qos) \ +do { \ + const char *func_name = "bt_bap_unicast_server_cb.qos"; \ + \ + zassert_equal(1, mock_bap_unicast_server_cb_qos_fake.call_count, \ + "'%s()' was called %u times, but expected once", \ + func_name, mock_bap_unicast_server_cb_qos_fake.call_count); \ + \ + IF_NOT_EMPTY(_stream, ( \ + zassert_equal_ptr(_stream, mock_bap_unicast_server_cb_qos_fake.arg0_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "stream");)) \ + \ + IF_NOT_EMPTY(_qos, ( \ + /* TODO */ \ + zassert_unreachable("Not implemented");)) \ +} while (0) + +#define expect_bt_bap_unicast_server_cb_enable_called_once(_stream, _meta, _meta_count) \ +do { \ + const char *func_name = "bt_bap_unicast_server_cb.enable"; \ + \ + zassert_equal(1, mock_bap_unicast_server_cb_enable_fake.call_count, \ + "'%s()' was called %u times, but expected once", \ + func_name, mock_bap_unicast_server_cb_enable_fake.call_count); \ + \ + IF_NOT_EMPTY(_stream, ( \ + zassert_equal_ptr(_stream, mock_bap_unicast_server_cb_enable_fake.arg0_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "stream");)) \ + \ + IF_NOT_EMPTY(_meta, ( \ + /* TODO */ \ + zassert_unreachable("Not implemented");)) \ + \ + IF_NOT_EMPTY(_meta_count, ( \ + /* TODO */ \ + zassert_unreachable("Not implemented");)) \ +} while (0) + +#define expect_bt_bap_unicast_server_cb_disable_called_once(_stream) \ +do { \ + const char *func_name = "bt_bap_unicast_server_cb.disable"; \ + \ + zassert_equal(1, mock_bap_unicast_server_cb_disable_fake.call_count, \ + "'%s()' was called %u times, but expected once", \ + func_name, mock_bap_unicast_server_cb_disable_fake.call_count); \ + \ + IF_NOT_EMPTY(_stream, ( \ + zassert_equal_ptr(_stream, mock_bap_unicast_server_cb_disable_fake.arg0_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "stream");)) \ +} while (0) + +#define expect_bt_bap_unicast_server_cb_release_called_once(_stream) \ +do { \ + const char *func_name = "bt_bap_unicast_server_cb.release"; \ + \ + zassert_equal(1, mock_bap_unicast_server_cb_release_fake.call_count, \ + "'%s()' was called %u times, but expected once", \ + func_name, mock_bap_unicast_server_cb_release_fake.call_count); \ + \ + IF_NOT_EMPTY(_stream, ( \ + zassert_equal_ptr(_stream, mock_bap_unicast_server_cb_release_fake.arg0_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "stream");)) \ +} while (0) + +#endif /* MOCKS_BAP_UNICAST_SERVER_EXPECTS_H_ */ diff --git a/tests/bluetooth/audio/mocks/include/conn.h b/tests/bluetooth/audio/mocks/include/conn.h new file mode 100644 index 000000000000..b1544734836a --- /dev/null +++ b/tests/bluetooth/audio/mocks/include/conn.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef MOCKS_CONN_H_ +#define MOCKS_CONN_H_ + +#include + +struct bt_conn { + uint8_t index; + struct bt_conn_info info; +}; + +#endif /* MOCKS_CONN_H_ */ diff --git a/tests/bluetooth/audio/mocks/include/expects_util.h b/tests/bluetooth/audio/mocks/include/expects_util.h new file mode 100644 index 000000000000..2de7bb4c688b --- /dev/null +++ b/tests/bluetooth/audio/mocks/include/expects_util.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef MOCKS_UTIL_H_ +#define MOCKS_UTIL_H_ + +#include +#include + +#define CHECK_EMPTY(_x) UTIL_BOOL(IS_EMPTY(_x)) +#define COND_CODE_EMPTY(_x, _if_any_code, _else_code) \ + COND_CODE_1(CHECK_EMPTY(_x), _if_any_code, _else_code) +#define IF_EMPTY(_a, _code) COND_CODE_EMPTY(_a, _code, ()) +#define IF_NOT_EMPTY(_a, _code) COND_CODE_EMPTY(_a, (), _code) + +#define expect_data(_func_name, _arg_name, _exp_data, _data, _len) \ + IF_NOT_EMPTY(_exp_data, (expect_data_equal(_func_name, _arg_name, _exp_data, _data, _len);)) + +static inline void expect_data_equal(const char *func_name, const char *arg_name, + const uint8_t *expect, const uint8_t *data, size_t len) +{ + for (size_t i = 0U; i < len; i++) { + zexpect_equal(expect[i], data[i], + "'%s()' was called with incorrect %s[%zu]=0x%02x != 0x%02x value", + func_name, arg_name, i, data[i], expect[i]); + } +} + +#endif /* MOCKS_UTIL_H_ */ diff --git a/tests/bluetooth/audio/mocks/include/gatt.h b/tests/bluetooth/audio/mocks/include/gatt.h new file mode 100644 index 000000000000..de23223fc0ba --- /dev/null +++ b/tests/bluetooth/audio/mocks/include/gatt.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef MOCKS_GATT_H_ +#define MOCKS_GATT_H_ + +#include +#include + +void mock_bt_gatt_init(void); +void mock_bt_gatt_cleanup(void); + +DECLARE_FAKE_VALUE_FUNC(int, mock_bt_gatt_notify_cb, struct bt_conn *, + struct bt_gatt_notify_params *); +DECLARE_FAKE_VALUE_FUNC(ssize_t, bt_gatt_attr_read, struct bt_conn *, + const struct bt_gatt_attr *, void *, uint16_t, uint16_t, const void *, + uint16_t); + +void bt_gatt_notify_cb_reset(void); + +#endif /* MOCKS_GATT_H_ */ diff --git a/tests/bluetooth/audio/mocks/include/gatt_expects.h b/tests/bluetooth/audio/mocks/include/gatt_expects.h new file mode 100644 index 000000000000..67eebf53bbe3 --- /dev/null +++ b/tests/bluetooth/audio/mocks/include/gatt_expects.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef MOCKS_GATT_EXPECTS_H_ +#define MOCKS_GATT_EXPECTS_H_ + +#include + +#include "gatt.h" +#include "expects_util.h" + +#define expect_bt_gatt_attr_read_called_once(_conn, _attr, _buf, _buf_len, _offset, _value, \ + _value_len) \ +do { \ + const char *func_name = "bt_gatt_attr_read"; \ + \ + zassert_equal(1, bt_gatt_attr_read_fake.call_count, \ + "'%s()' was called %u times, but expected once", \ + func_name, bt_gatt_attr_read_fake.call_count); \ + \ + IF_NOT_EMPTY(_conn, ( \ + zassert_equal_ptr(_conn, bt_gatt_attr_read_fake.arg0_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "conn");)) \ + \ + IF_NOT_EMPTY(_attr, ( \ + zassert_equal_ptr(_attr, bt_gatt_attr_read_fake.arg1_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "attr");)) \ + \ + IF_NOT_EMPTY(_buf, ( \ + zassert_equal_ptr(_buf, bt_gatt_attr_read_fake.arg2_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "buf");)) \ + \ + IF_NOT_EMPTY(_buf_len, ( \ + zassert_equal(_buf_len, bt_gatt_attr_read_fake.arg3_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "_buf_len");)) \ + \ + IF_NOT_EMPTY(_offset, ( \ + zassert_equal(_offset, bt_gatt_attr_read_fake.arg4_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "offset");)) \ + \ + /* assert if _data is valid, but _len is empty */ \ + IF_EMPTY(_value_len, (IF_NOT_EMPTY(_value, (zassert_unreachable();)))) \ + \ + IF_NOT_EMPTY(_value_len, ( \ + zassert_equal(_value_len, bt_gatt_attr_read_fake.arg6_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "value_len"); \ + expect_data(func_name, "value", _value, bt_gatt_attr_read_fake.arg5_val, \ + _value_len);)) \ +} while (0) + +#define expect_bt_gatt_notify_cb_called_once(_conn, _uuid, _attr, _data, _len) \ +do { \ + const char *func_name = "bt_gatt_notify_cb"; \ + struct bt_gatt_notify_params *params; \ + \ + IF_NOT_EMPTY(_conn, ( \ + zassert_equal_ptr(_conn, mock_bt_gatt_notify_cb_fake.arg0_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "conn");)) \ + \ + params = mock_bt_gatt_notify_cb_fake.arg1_val; \ + \ + /* params->uuid is optional */ \ + if (params->uuid) { \ + IF_NOT_EMPTY(_uuid, ( \ + zassert_true(bt_uuid_cmp(_uuid, params->uuid) == 0, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "params->uuid");)) \ + } else { \ + IF_NOT_EMPTY(_attr, ( \ + zassert_equal_ptr(_attr, params->attr, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "params->attr");)) \ + } \ + \ + /* assert if _data is valid, but _len is empty */ \ + IF_EMPTY(_len, (IF_NOT_EMPTY(_data, (zassert_unreachable();)))) \ + \ + IF_NOT_EMPTY(_len, ( \ + zassert_equal(_len, params->len, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "params->len"); \ + expect_data(func_name, "params->data", _data, params->data, _len);)) \ +} while (0) + +static inline void expect_bt_gatt_attr_read_not_called(void) +{ + const char *func_name = "bt_gatt_attr_read"; + + zassert_equal(0, bt_gatt_attr_read_fake.call_count, + "'%s()' was called unexpectedly", func_name); +} + +static inline void expect_bt_gatt_notify_cb_not_called(void) +{ + const char *func_name = "bt_gatt_notify_cb"; + + zassert_equal(0, mock_bt_gatt_notify_cb_fake.call_count, + "'%s()' was called unexpectedly", func_name); +} + +#endif /* MOCKS_GATT_EXPECTS_H_ */ diff --git a/tests/bluetooth/audio/mocks/include/iso.h b/tests/bluetooth/audio/mocks/include/iso.h new file mode 100644 index 000000000000..aa1a9f0446a4 --- /dev/null +++ b/tests/bluetooth/audio/mocks/include/iso.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef MOCKS_ISO_H_ +#define MOCKS_ISO_H_ + +#include +#include + +/* List of fakes used by this unit tester */ +#define ISO_FFF_FAKES_LIST(FAKE) \ + FAKE(bt_iso_chan_send) \ + FAKE(bt_iso_server_register) \ + FAKE(bt_iso_chan_disconnect) \ + +DECLARE_FAKE_VALUE_FUNC(int, bt_iso_chan_send, struct bt_iso_chan *, struct net_buf *, uint16_t, + uint32_t); +DECLARE_FAKE_VALUE_FUNC(int, bt_iso_server_register, struct bt_iso_server *); +DECLARE_FAKE_VALUE_FUNC(int, bt_iso_chan_disconnect, struct bt_iso_chan *); + +#endif /* MOCKS_ISO_H_ */ diff --git a/tests/bluetooth/audio/mocks/include/mock_kernel.h b/tests/bluetooth/audio/mocks/include/mock_kernel.h new file mode 100644 index 000000000000..239949dd2531 --- /dev/null +++ b/tests/bluetooth/audio/mocks/include/mock_kernel.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef MOCKS_KERNEL_H_ +#define MOCKS_KERNEL_H_ + +#include +#include + +/* List of fakes used by this unit tester */ +#define KERNEL_FFF_FAKES_LIST(FAKE) \ + FAKE(z_timeout_remaining) \ + FAKE(k_work_schedule) \ + FAKE(k_work_cancel_delayable_sync) \ + FAKE(k_work_init_delayable) \ + FAKE(k_work_cancel_delayable) \ + FAKE(k_work_reschedule) \ + +DECLARE_FAKE_VALUE_FUNC(k_ticks_t, z_timeout_remaining, const struct _timeout *); +DECLARE_FAKE_VALUE_FUNC(int, k_work_schedule, struct k_work_delayable *, k_timeout_t); +DECLARE_FAKE_VALUE_FUNC(bool, k_work_cancel_delayable_sync, struct k_work_delayable *, + struct k_work_sync *); +DECLARE_FAKE_VOID_FUNC(k_work_init_delayable, struct k_work_delayable *, k_work_handler_t); +DECLARE_FAKE_VALUE_FUNC(int, k_work_cancel_delayable, struct k_work_delayable *); +DECLARE_FAKE_VALUE_FUNC(int, k_work_reschedule, struct k_work_delayable *, k_timeout_t); + +#endif /* MOCKS_KERNEL_H_ */ diff --git a/tests/bluetooth/audio/mocks/include/pacs.h b/tests/bluetooth/audio/mocks/include/pacs.h new file mode 100644 index 000000000000..384622d9cf71 --- /dev/null +++ b/tests/bluetooth/audio/mocks/include/pacs.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef MOCKS_PACS_H_ +#define MOCKS_PACS_H_ + +#include +#include + +/* List of fakes used by this unit tester */ +#define PACS_FFF_FAKES_LIST(FAKE) \ + FAKE(bt_pacs_cap_foreach) \ + +DECLARE_FAKE_VOID_FUNC(bt_pacs_cap_foreach, enum bt_audio_dir, bt_pacs_cap_foreach_func_t, void *); + +#endif /* MOCKS_PACS_H_ */ diff --git a/tests/bluetooth/audio/mocks/mock-sections.ld b/tests/bluetooth/audio/mocks/mock-sections.ld new file mode 100644 index 000000000000..e00c81047e73 --- /dev/null +++ b/tests/bluetooth/audio/mocks/mock-sections.ld @@ -0,0 +1,21 @@ +/* + * Copyright 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +SECTIONS +{ + bt_conn_cb_area : ALIGN(4) + { + _bt_conn_cb_list_start = .; + KEEP(*(SORT_BY_NAME(._bt_conn_cb.static.*))) + _bt_conn_cb_list_end = .; + } + bt_gatt_service_static_area : ALIGN(4) + { + _bt_gatt_service_static_list_start = .; + KEEP(*(SORT_BY_NAME(._bt_gatt_service_static.static.*))) + _bt_gatt_service_static_list_end = .; + } +} diff --git a/tests/bluetooth/audio/mocks/src/bap_stream.c b/tests/bluetooth/audio/mocks/src/bap_stream.c new file mode 100644 index 000000000000..3d589bc79afc --- /dev/null +++ b/tests/bluetooth/audio/mocks/src/bap_stream.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "bap_stream.h" + +/* List of fakes used by this unit tester */ +#define FFF_FAKES_LIST(FAKE) \ + FAKE(mock_bap_stream_configured_cb) \ + FAKE(mock_bap_stream_qos_set_cb) \ + FAKE(mock_bap_stream_enabled_cb) \ + FAKE(mock_bap_stream_metadata_updated_cb) \ + FAKE(mock_bap_stream_disabled_cb) \ + FAKE(mock_bap_stream_released_cb) \ + FAKE(mock_bap_stream_started_cb) \ + FAKE(mock_bap_stream_stopped_cb) \ + FAKE(mock_bap_stream_recv_cb) \ + FAKE(mock_bap_stream_sent_cb) \ + +struct bt_bap_stream_ops mock_bap_stream_ops; + +DEFINE_FAKE_VOID_FUNC(mock_bap_stream_configured_cb, struct bt_bap_stream *, + const struct bt_codec_qos_pref *); +DEFINE_FAKE_VOID_FUNC(mock_bap_stream_qos_set_cb, struct bt_bap_stream *); +DEFINE_FAKE_VOID_FUNC(mock_bap_stream_enabled_cb, struct bt_bap_stream *); +DEFINE_FAKE_VOID_FUNC(mock_bap_stream_metadata_updated_cb, struct bt_bap_stream *); +DEFINE_FAKE_VOID_FUNC(mock_bap_stream_disabled_cb, struct bt_bap_stream *); +DEFINE_FAKE_VOID_FUNC(mock_bap_stream_released_cb, struct bt_bap_stream *); +DEFINE_FAKE_VOID_FUNC(mock_bap_stream_started_cb, struct bt_bap_stream *); +DEFINE_FAKE_VOID_FUNC(mock_bap_stream_stopped_cb, struct bt_bap_stream *, uint8_t); +DEFINE_FAKE_VOID_FUNC(mock_bap_stream_recv_cb, struct bt_bap_stream *, + const struct bt_iso_recv_info *, struct net_buf *); +DEFINE_FAKE_VOID_FUNC(mock_bap_stream_sent_cb, struct bt_bap_stream *); + +void mock_bap_stream_init(void) +{ + FFF_FAKES_LIST(RESET_FAKE); + + mock_bap_stream_ops.configured = mock_bap_stream_configured_cb; + mock_bap_stream_ops.qos_set = mock_bap_stream_qos_set_cb; + mock_bap_stream_ops.enabled = mock_bap_stream_enabled_cb; + mock_bap_stream_ops.metadata_updated = mock_bap_stream_metadata_updated_cb; + mock_bap_stream_ops.disabled = mock_bap_stream_disabled_cb; + mock_bap_stream_ops.released = mock_bap_stream_released_cb; + mock_bap_stream_ops.started = mock_bap_stream_started_cb; + mock_bap_stream_ops.stopped = mock_bap_stream_stopped_cb; + mock_bap_stream_ops.recv = mock_bap_stream_recv_cb; + mock_bap_stream_ops.sent = mock_bap_stream_sent_cb; +} + +void mock_bap_stream_cleanup(void) +{ + +} diff --git a/tests/bluetooth/audio/mocks/src/bap_unicast_server.c b/tests/bluetooth/audio/mocks/src/bap_unicast_server.c new file mode 100644 index 000000000000..70e864afaef8 --- /dev/null +++ b/tests/bluetooth/audio/mocks/src/bap_unicast_server.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "bap_unicast_server.h" + +/* List of fakes used by this unit tester */ +#define FFF_FAKES_LIST(FAKE) \ + FAKE(mock_bap_unicast_server_cb_config) \ + FAKE(mock_bap_unicast_server_cb_reconfig) \ + FAKE(mock_bap_unicast_server_cb_qos) \ + FAKE(mock_bap_unicast_server_cb_enable) \ + FAKE(mock_bap_unicast_server_cb_start) \ + FAKE(mock_bap_unicast_server_cb_metadata) \ + FAKE(mock_bap_unicast_server_cb_disable) \ + FAKE(mock_bap_unicast_server_cb_stop) \ + FAKE(mock_bap_unicast_server_cb_release) \ + +void mock_bap_unicast_server_init(void) +{ + FFF_FAKES_LIST(RESET_FAKE); +} + +void mock_bap_unicast_server_cleanup(void) +{ + +} + +DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_config, struct bt_conn *, + const struct bt_bap_ep *, enum bt_audio_dir, const struct bt_codec *, + struct bt_bap_stream **, struct bt_codec_qos_pref *const); +DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_reconfig, struct bt_bap_stream *, + enum bt_audio_dir, const struct bt_codec *, struct bt_codec_qos_pref *const); +DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_qos, struct bt_bap_stream *, + const struct bt_codec_qos *); +DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_enable, struct bt_bap_stream *, + const struct bt_codec_data *, size_t); +DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_start, struct bt_bap_stream *); +DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_metadata, struct bt_bap_stream *, + const struct bt_codec_data *, size_t); +DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_disable, struct bt_bap_stream *); +DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_stop, struct bt_bap_stream *); +DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_release, struct bt_bap_stream *); + +const struct bt_bap_unicast_server_cb mock_bap_unicast_server_cb = { + .config = mock_bap_unicast_server_cb_config, + .reconfig = mock_bap_unicast_server_cb_reconfig, + .qos = mock_bap_unicast_server_cb_qos, + .enable = mock_bap_unicast_server_cb_enable, + .start = mock_bap_unicast_server_cb_start, + .metadata = mock_bap_unicast_server_cb_metadata, + .disable = mock_bap_unicast_server_cb_disable, + .stop = mock_bap_unicast_server_cb_stop, + .release = mock_bap_unicast_server_cb_release, +}; diff --git a/tests/bluetooth/audio/mocks/src/conn.c b/tests/bluetooth/audio/mocks/src/conn.c new file mode 100644 index 000000000000..223483951fb2 --- /dev/null +++ b/tests/bluetooth/audio/mocks/src/conn.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "conn.h" + +uint8_t bt_conn_index(const struct bt_conn *conn) +{ + return conn->index; +} + +int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info) +{ + *info = conn->info; + + return 0; +} + +struct bt_conn *bt_conn_ref(struct bt_conn *conn) +{ + return conn; +} + +void bt_conn_unref(struct bt_conn *conn) +{ + +} diff --git a/tests/bluetooth/audio/mocks/src/fatal.c b/tests/bluetooth/audio/mocks/src/fatal.c new file mode 100644 index 000000000000..f36f518b3457 --- /dev/null +++ b/tests/bluetooth/audio/mocks/src/fatal.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +void z_fatal_error(unsigned int reason, const z_arch_esf_t *esf) +{ + ztest_test_fail(); +} diff --git a/tests/bluetooth/audio/mocks/src/gatt.c b/tests/bluetooth/audio/mocks/src/gatt.c new file mode 100644 index 000000000000..1af07a7e41ff --- /dev/null +++ b/tests/bluetooth/audio/mocks/src/gatt.c @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include "gatt.h" + +/* List of fakes used by this unit tester */ +#define FFF_FAKES_LIST(FAKE) \ + FAKE(mock_bt_gatt_notify_cb) \ + FAKE(bt_gatt_attr_read) \ + +DEFINE_FAKE_VALUE_FUNC(int, mock_bt_gatt_notify_cb, struct bt_conn *, + struct bt_gatt_notify_params *); +DEFINE_FAKE_VALUE_FUNC(ssize_t, bt_gatt_attr_read, struct bt_conn *, const struct bt_gatt_attr *, + void *, uint16_t, uint16_t, const void *, uint16_t); + +ssize_t bt_gatt_attr_read_service(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) +{ + zassert_unreachable("Unexpected call to '%s()' occurred", __func__); + return 0; +} + +ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) +{ + zassert_unreachable("Unexpected call to '%s()' occurred", __func__); + return 0; +} + +ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) +{ + zassert_unreachable("Unexpected call to '%s()' occurred", __func__); + return 0; +} + +ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn, const struct bt_gatt_attr *attr, + const void *buf, uint16_t len, uint16_t offset, uint8_t flags) +{ + zassert_unreachable("Unexpected call to '%s()' occurred", __func__); + return 0; +} + +void mock_bt_gatt_init(void) +{ + FFF_FAKES_LIST(RESET_FAKE); +} + +static void notify_params_deep_copy_destroy(void) +{ + struct bt_gatt_notify_params *copy; + + for (unsigned int i = 0; i < mock_bt_gatt_notify_cb_fake.call_count; i++) { + copy = mock_bt_gatt_notify_cb_fake.arg1_history[i]; + + /* Free UUID deep copy */ + if (copy->uuid) { + free((void *)copy->uuid); + } + + free(copy); + } +} + +void mock_bt_gatt_cleanup(void) +{ + notify_params_deep_copy_destroy(); +} + +static struct bt_uuid *uuid_deep_copy(const struct bt_uuid *uuid) +{ + struct bt_uuid *copy; + + switch (uuid->type) { + case BT_UUID_TYPE_16: + copy = malloc(sizeof(struct bt_uuid_16)); + zassert_not_null(copy); + memcpy(copy, uuid, sizeof(struct bt_uuid_16)); + break; + case BT_UUID_TYPE_32: + copy = malloc(sizeof(struct bt_uuid_32)); + zassert_not_null(copy); + memcpy(copy, uuid, sizeof(struct bt_uuid_32)); + break; + case BT_UUID_TYPE_128: + copy = malloc(sizeof(struct bt_uuid_128)); + zassert_not_null(copy); + memcpy(copy, uuid, sizeof(struct bt_uuid_128)); + break; + default: + zassert_unreachable("Unexpected uuid->type 0x%02x", uuid->type); + } + + return copy; +} + +static struct bt_gatt_notify_params *notify_params_deep_copy(struct bt_gatt_notify_params *params) +{ + struct bt_gatt_notify_params *copy; + + copy = malloc(sizeof(*params)); + zassert_not_null(copy); + + memcpy(copy, params, sizeof(*params)); + + if (params->uuid != NULL) { + copy->uuid = uuid_deep_copy(params->uuid); + } + + return copy; +} + +int bt_gatt_notify_cb(struct bt_conn *conn, struct bt_gatt_notify_params *params) +{ + zassert_not_null(params, "'%s()' was called with incorrect '%s' value", __func__, "params"); + + /* Either params->uuid, params->attr, or both has to be provided */ + zassert_true(params->uuid != NULL || params->attr != NULL, + "'%s()' was called with incorrect '%s' value", __func__, + "params->uuid or params->attr"); + + return mock_bt_gatt_notify_cb(conn, notify_params_deep_copy(params)); +} + +void bt_gatt_notify_cb_reset(void) +{ + notify_params_deep_copy_destroy(); + + RESET_FAKE(mock_bt_gatt_notify_cb); +} + +#define foreach_attr_type_dyndb(...) +#define last_static_handle BT_ATT_LAST_ATTRIBUTE_HANDLE + +/* Exact copy of subsys/bluetooth/host/gatt.c:gatt_foreach_iter() */ +static uint8_t gatt_foreach_iter(const struct bt_gatt_attr *attr, + uint16_t handle, uint16_t start_handle, + uint16_t end_handle, + const struct bt_uuid *uuid, + const void *attr_data, uint16_t *num_matches, + bt_gatt_attr_func_t func, void *user_data) +{ + uint8_t result; + + /* Stop if over the requested range */ + if (handle > end_handle) { + return BT_GATT_ITER_STOP; + } + + /* Check if attribute handle is within range */ + if (handle < start_handle) { + return BT_GATT_ITER_CONTINUE; + } + + /* Match attribute UUID if set */ + if (uuid && bt_uuid_cmp(uuid, attr->uuid)) { + return BT_GATT_ITER_CONTINUE; + } + + /* Match attribute user_data if set */ + if (attr_data && attr_data != attr->user_data) { + return BT_GATT_ITER_CONTINUE; + } + + *num_matches -= 1; + + result = func(attr, handle, user_data); + + if (!*num_matches) { + return BT_GATT_ITER_STOP; + } + + return result; +} + +/* Exact copy of subsys/bluetooth/host/gatt.c:bt_gatt_foreach_attr_type() */ +void bt_gatt_foreach_attr_type(uint16_t start_handle, uint16_t end_handle, + const struct bt_uuid *uuid, + const void *attr_data, uint16_t num_matches, + bt_gatt_attr_func_t func, void *user_data) +{ + size_t i; + + if (!num_matches) { + num_matches = UINT16_MAX; + } + + if (start_handle <= last_static_handle) { + uint16_t handle = 1; + + STRUCT_SECTION_FOREACH(bt_gatt_service_static, static_svc) { + /* Skip ahead if start is not within service handles */ + if (handle + static_svc->attr_count < start_handle) { + handle += static_svc->attr_count; + continue; + } + + for (i = 0; i < static_svc->attr_count; i++, handle++) { + if (gatt_foreach_iter(&static_svc->attrs[i], + handle, start_handle, + end_handle, uuid, + attr_data, &num_matches, + func, user_data) == + BT_GATT_ITER_STOP) { + return; + } + } + } + } + + /* Iterate over dynamic db */ + foreach_attr_type_dyndb(start_handle, end_handle, uuid, attr_data, + num_matches, func, user_data); +} diff --git a/tests/bluetooth/audio/mocks/src/iso.c b/tests/bluetooth/audio/mocks/src/iso.c new file mode 100644 index 000000000000..8dc88bca5eb7 --- /dev/null +++ b/tests/bluetooth/audio/mocks/src/iso.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "iso.h" + +DEFINE_FAKE_VALUE_FUNC(int, bt_iso_chan_send, struct bt_iso_chan *, struct net_buf *, uint16_t, + uint32_t); +DEFINE_FAKE_VALUE_FUNC(int, bt_iso_server_register, struct bt_iso_server *); +DEFINE_FAKE_VALUE_FUNC(int, bt_iso_chan_disconnect, struct bt_iso_chan *); diff --git a/tests/bluetooth/audio/mocks/src/kernel.c b/tests/bluetooth/audio/mocks/src/kernel.c new file mode 100644 index 000000000000..3905898d9be6 --- /dev/null +++ b/tests/bluetooth/audio/mocks/src/kernel.c @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "mock_kernel.h" + +DEFINE_FAKE_VALUE_FUNC(k_ticks_t, z_timeout_remaining, const struct _timeout *); +DEFINE_FAKE_VALUE_FUNC(int, k_work_schedule, struct k_work_delayable *, k_timeout_t); +DEFINE_FAKE_VALUE_FUNC(bool, k_work_cancel_delayable_sync, struct k_work_delayable *, + struct k_work_sync *); +DEFINE_FAKE_VOID_FUNC(k_work_init_delayable, struct k_work_delayable *, k_work_handler_t); +DEFINE_FAKE_VALUE_FUNC(int, k_work_cancel_delayable, struct k_work_delayable *); +DEFINE_FAKE_VALUE_FUNC(int, k_work_reschedule, struct k_work_delayable *, k_timeout_t); diff --git a/tests/bluetooth/audio/mocks/src/mem_slab.c b/tests/bluetooth/audio/mocks/src/mem_slab.c new file mode 100644 index 000000000000..7ec8b9f1e51b --- /dev/null +++ b/tests/bluetooth/audio/mocks/src/mem_slab.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +int k_mem_slab_alloc(struct k_mem_slab *slab, void **mem, k_timeout_t timeout) +{ + if (slab->num_used >= slab->num_blocks) { + *mem = NULL; + return -ENOMEM; + } + + *mem = malloc(slab->block_size); + zassert_not_null(*mem); + + slab->num_used++; + return 0; +} + +void k_mem_slab_free(struct k_mem_slab *slab, void **mem) +{ + free(*mem); + slab->num_used--; +} diff --git a/tests/bluetooth/audio/mocks/src/pacs.c b/tests/bluetooth/audio/mocks/src/pacs.c new file mode 100644 index 000000000000..7f059404ad8a --- /dev/null +++ b/tests/bluetooth/audio/mocks/src/pacs.c @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "pacs.h" + +DEFINE_FAKE_VOID_FUNC(bt_pacs_cap_foreach, enum bt_audio_dir, bt_pacs_cap_foreach_func_t, void *); From b176c51785c7e0b32bb7972988e27a53decae3ba Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Fri, 17 Mar 2023 08:09:31 +0100 Subject: [PATCH 0627/1906] tests: Bluetooth: audio: Add initial ASCS unit tests This adds initial ASCS unit tests. Failing test cases have been conditionally skipped with Zephyr issue number. Signed-off-by: Mariusz Skamra --- tests/bluetooth/audio/ascs/CMakeLists.txt | 15 + tests/bluetooth/audio/ascs/prj.conf | 24 + tests/bluetooth/audio/ascs/src/main.c | 738 ++++++++++++++++++ tests/bluetooth/audio/ascs/testcase.yaml | 5 + tests/bluetooth/audio/ascs/uut/CMakeLists.txt | 26 + 5 files changed, 808 insertions(+) create mode 100644 tests/bluetooth/audio/ascs/CMakeLists.txt create mode 100644 tests/bluetooth/audio/ascs/prj.conf create mode 100644 tests/bluetooth/audio/ascs/src/main.c create mode 100644 tests/bluetooth/audio/ascs/testcase.yaml create mode 100644 tests/bluetooth/audio/ascs/uut/CMakeLists.txt diff --git a/tests/bluetooth/audio/ascs/CMakeLists.txt b/tests/bluetooth/audio/ascs/CMakeLists.txt new file mode 100644 index 000000000000..f5aa3782b3e4 --- /dev/null +++ b/tests/bluetooth/audio/ascs/CMakeLists.txt @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +project(bluetooth_ascs) +find_package(Zephyr COMPONENTS unittest HINTS $ENV{ZEPHYR_BASE}) + +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/audio/ascs/uut uut) + +target_link_libraries(testbinary PRIVATE uut) + +target_sources(testbinary + PRIVATE + src/main.c +) diff --git a/tests/bluetooth/audio/ascs/prj.conf b/tests/bluetooth/audio/ascs/prj.conf new file mode 100644 index 000000000000..ed2d370bb6d8 --- /dev/null +++ b/tests/bluetooth/audio/ascs/prj.conf @@ -0,0 +1,24 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y + +CONFIG_BT=y +CONFIG_BT_MAX_CONN=1 +CONFIG_BT_ISO_MAX_CHAN=1 +CONFIG_BT_AUDIO=y +CONFIG_BT_ASCS=y +CONFIG_BT_ASCS_ASE_SNK_COUNT=2 +CONFIG_BT_ASCS_ASE_SRC_COUNT=2 +CONFIG_BT_ASCS_MAX_ACTIVE_ASES=1 +CONFIG_BT_BAP_UNICAST_SERVER=y +CONFIG_BT_ISO_MAX_CHAN=2 + +CONFIG_BT_DEBUG_LOG=y +CONFIG_BT_ASCS_LOG_LEVEL_DBG=y +CONFIG_BT_BAP_ISO_LOG_LEVEL_DBG=y +CONFIG_BT_BAP_STREAM_LOG_LEVEL_DBG=y +CONFIG_BT_BAP_UNICAST_SERVER_LOG_LEVEL_DBG=y + +CONFIG_ASSERT=y +CONFIG_ASSERT_LEVEL=2 +CONFIG_ASSERT_VERBOSE=y +CONFIG_ASSERT_ON_ERRORS=y diff --git a/tests/bluetooth/audio/ascs/src/main.c b/tests/bluetooth/audio/ascs/src/main.c new file mode 100644 index 000000000000..61aa8b4cda61 --- /dev/null +++ b/tests/bluetooth/audio/ascs/src/main.c @@ -0,0 +1,738 @@ +/* main.c - Application main entry point */ + +/* + * Copyright (c) 2023 Codecoup + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "assert.h" +#include "ascs_help_utils.h" +#include "bap_unicast_server.h" +#include "bap_unicast_server_expects.h" +#include "bap_stream.h" +#include "bap_stream_expects.h" +#include "conn.h" +#include "gatt.h" +#include "gatt_expects.h" +#include "iso.h" +#include "mock_kernel.h" +#include "pacs.h" + +DEFINE_FFF_GLOBALS; + +struct attr_found_data { + const struct bt_gatt_attr *attr; + uint16_t found_cnt; +}; + +static uint8_t attr_found_func(const struct bt_gatt_attr *attr, uint16_t handle, + void *user_data) +{ + struct attr_found_data *data = user_data; + + data->attr = attr; + data->found_cnt++; + + return BT_GATT_ITER_CONTINUE; +} + +static const struct bt_gatt_attr *ascs_get_attr(const struct bt_uuid *uuid, uint16_t nth) +{ + struct attr_found_data data = { + .attr = NULL, + .found_cnt = 0, + }; + + if (nth == 0) { + return NULL; + } + + bt_gatt_foreach_attr_type(0x0001, 0xFFFF, uuid, NULL, nth, attr_found_func, &data); + + if (data.found_cnt != nth) { + return NULL; + } + + return data.attr; +} + +static void mock_init_rule_before(const struct ztest_unit_test *test, void *fixture) +{ + mock_bap_unicast_server_init(); + ISO_FFF_FAKES_LIST(RESET_FAKE); + KERNEL_FFF_FAKES_LIST(RESET_FAKE); + PACS_FFF_FAKES_LIST(RESET_FAKE); + mock_bap_stream_init(); + mock_bt_gatt_init(); +} + +static void mock_destroy_rule_after(const struct ztest_unit_test *test, void *fixture) +{ + mock_bap_unicast_server_cleanup(); + mock_bap_stream_cleanup(); + mock_bt_gatt_cleanup(); +} + +ZTEST_RULE(mock_rule, mock_init_rule_before, mock_destroy_rule_after); + +ZTEST_SUITE(ascs_attrs_test_suite, NULL, NULL, NULL, NULL, NULL); + +ZTEST(ascs_attrs_test_suite, test_has_sink_ase_chrc) +{ + Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK); + + zassert_not_null(ascs_get_attr(BT_UUID_ASCS_ASE_SNK, 1)); + zassert_not_null(ascs_get_attr(BT_UUID_ASCS_ASE_SNK, CONFIG_BT_ASCS_ASE_SNK_COUNT)); +} + +ZTEST(ascs_attrs_test_suite, test_has_source_ase_chrc) +{ + Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SRC); + + zassert_not_null(ascs_get_attr(BT_UUID_ASCS_ASE_SRC, 1)); + zassert_not_null(ascs_get_attr(BT_UUID_ASCS_ASE_SRC, CONFIG_BT_ASCS_ASE_SRC_COUNT)); +} + +ZTEST(ascs_attrs_test_suite, test_has_single_control_point_chrc) +{ + zassert_not_null(ascs_get_attr(BT_UUID_ASCS_ASE_CP, 1)); + zassert_is_null(ascs_get_attr(BT_UUID_ASCS_ASE_CP, 2)); +} + +static struct bt_codec lc3_codec = + BT_CODEC_LC3(BT_CODEC_LC3_FREQ_ANY, BT_CODEC_LC3_DURATION_10, + BT_CODEC_LC3_CHAN_COUNT_SUPPORT(1), 40u, 120u, 1u, + (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA)); + +static const struct bt_codec_qos_pref qos_pref = BT_CODEC_QOS_PREF(true, BT_GAP_LE_PHY_2M, + 0x02, 10, 40000, 40000, + 40000, 40000); + +static void pacs_cap_foreach_custom_fake(enum bt_audio_dir dir, bt_pacs_cap_foreach_func_t func, + void *user_data) +{ + static const struct bt_pacs_cap cap[] = { + { + &lc3_codec, + }, + }; + + for (size_t i = 0; i < ARRAY_SIZE(cap); i++) { + if (func(&cap[i], user_data) == false) { + break; + } + } +} + +struct ascs_ase_control_test_suite_fixture { + struct bt_conn conn; + struct bt_bap_stream stream; + const struct bt_gatt_attr *ase_cp; + const struct bt_gatt_attr *ase_snk; +}; + +static void conn_init(struct bt_conn *conn) +{ + memset(conn, 0, sizeof(*conn)); + + conn->index = 0; + conn->info.type = BT_CONN_TYPE_LE; + conn->info.role = BT_CONN_ROLE_PERIPHERAL; + conn->info.state = BT_CONN_STATE_CONNECTED; + conn->info.security.level = BT_SECURITY_L3; + conn->info.security.enc_key_size = BT_ENC_KEY_SIZE_MAX; + conn->info.security.flags = BT_SECURITY_FLAG_OOB | BT_SECURITY_FLAG_SC; +} + +static void *ascs_ase_control_test_suite_setup(void) +{ + struct ascs_ase_control_test_suite_fixture *fixture; + + fixture = malloc(sizeof(*fixture)); + zassert_not_null(fixture); + + conn_init(&fixture->conn); + fixture->ase_cp = ascs_get_attr(BT_UUID_ASCS_ASE_CP, 1); + fixture->ase_snk = ascs_get_attr(BT_UUID_ASCS_ASE_SNK, 1); + + bt_bap_unicast_server_register_cb(&mock_bap_unicast_server_cb); + + return fixture; +} + +static void ascs_ase_control_test_suite_before(void *f) +{ + struct ascs_ase_control_test_suite_fixture *fixture = f; + + ARG_UNUSED(fixture); + + bt_pacs_cap_foreach_fake.custom_fake = pacs_cap_foreach_custom_fake; +} + +static void ascs_ase_control_test_suite_after(void *f) +{ + ascs_cleanup(); +} + +static void ascs_ase_control_test_suite_teardown(void *f) +{ + struct ascs_ase_control_test_suite_fixture *fixture = f; + + bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb); + + free(fixture); +} + +ZTEST_SUITE(ascs_ase_control_test_suite, NULL, ascs_ase_control_test_suite_setup, + ascs_ase_control_test_suite_before, ascs_ase_control_test_suite_after, + ascs_ase_control_test_suite_teardown); + +ZTEST_F(ascs_ase_control_test_suite, test_sink_ase_read_state_idle) +{ + uint8_t data_expected[] = { + 0x01, /* ASE_ID */ + 0x00, /* ASE_State = Idle */ + }; + ssize_t ret; + + Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK); + + ret = fixture->ase_snk->read(&fixture->conn, fixture->ase_snk, NULL, 0, 0); + zassert_false(ret < 0, "attr->read returned unexpected (err 0x%02x)", + BT_GATT_ERR(ret)); + + expect_bt_gatt_attr_read_called_once(&fixture->conn, fixture->ase_snk, EMPTY, + EMPTY, 0x0000, data_expected, sizeof(data_expected)); +} + +ZTEST_F(ascs_ase_control_test_suite, test_sink_ase_control_operation_zero_length_write) +{ + uint8_t buf[] = {}; + ssize_t ret; + + ret = fixture->ase_cp->write(&fixture->conn, fixture->ase_cp, (void *)buf, 0, 0, 0); + zassert_true(ret < 0, "ase_cp_attr->write returned unexpected (err 0x%02x)", + BT_GATT_ERR(ret)); +} + +static void test_unsupported_opcode(struct ascs_ase_control_test_suite_fixture *fixture, + uint8_t opcode) +{ + uint8_t buf[] = { + opcode, /* Opcode */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + }; + uint8_t data_expected[] = { + opcode, /* Opcode */ + 0xFF, /* Number_of_ASEs */ + 0x00, /* ASE_ID[0] */ + 0x01, /* Response_Code[0] = Unsupported Opcode */ + 0x00, /* Reason[0] */ + }; + + fixture->ase_cp->write(&fixture->conn, fixture->ase_cp, (void *)buf, sizeof(buf), 0, 0); + + expect_bt_gatt_notify_cb_called_once(&fixture->conn, BT_UUID_ASCS_ASE_CP, + fixture->ase_cp, data_expected, sizeof(data_expected)); +} + +ZTEST_F(ascs_ase_control_test_suite, test_unsupported_opcode_0x00) +{ + test_unsupported_opcode(fixture, 0x00); +} + +ZTEST_F(ascs_ase_control_test_suite, test_unsupported_opcode_rfu) +{ + test_unsupported_opcode(fixture, 0x09); +} + +static void test_codec_configure_invalid_length(struct ascs_ase_control_test_suite_fixture *fixture, + const uint8_t *buf, size_t len) +{ + const uint8_t data_expected[] = { + 0x01, /* Opcode */ + 0xFF, /* Number_of_ASEs */ + 0x00, /* ASE_ID[0] */ + 0x02, /* Response_Code[0] = Invalid Length */ + 0x00, /* Reason[0] */ + }; + + fixture->ase_cp->write(&fixture->conn, fixture->ase_cp, buf, len, 0, 0); + + expect_bt_gatt_notify_cb_called_once(&fixture->conn, BT_UUID_ASCS_ASE_CP, + fixture->ase_cp, data_expected, sizeof(data_expected)); +} + +/* + * Test correctly formatted ASE Control Point 'Invalid Length' notification is sent + * + * ASCS_v1.0; 5 ASE Control operations + * "A client-initiated ASE Control operation shall be defined as an invalid length operation + * if the Number_of_ASEs parameter value is less than 1" + * + * Constraints: + * - Number_of_ASEs is set to 0 + * - Config Codec operation parameter array is valid + * + * Expected behaviour: + * - "If the Response_Code value is 0x01 or 0x02, Number_of_ASEs shall be set to 0xFF." + * - ASE Control Point notification is correctly formatted + */ +ZTEST_F(ascs_ase_control_test_suite, test_codec_configure_invalid_length_number_of_ases_0x00) +{ + const uint8_t buf[] = { + 0x01, /* Opcode = Config Codec */ + 0x00, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + 0x01, /* Target_Latency[0] = Target low latency */ + 0x02, /* Target_PHY[0] = LE 2M PHY */ + 0x06, /* Codec_ID[0].Coding_Format = LC3 */ + 0x00, 0x00, /* Codec_ID[0].Company_ID */ + 0x00, 0x00, /* Codec_ID[0].Vendor_Specific_Codec_ID */ + 0x00, /* Codec_Specific_Configuration_Length[0] */ + }; + + test_codec_configure_invalid_length(fixture, buf, sizeof(buf)); +} + +/* + * Test correctly formatted ASE Control Point 'Invalid Length' notification is sent + * + * ASCS_v1.0; 5 ASE Control operations + * "A client-initiated ASE Control operation shall be defined as an invalid length operation(...) + * if the Number_of_ASEs parameter value does not match the number of parameter arrays written by + * the client" + * + * Constraints: + * - Number_of_ASEs is set to 1 + * - Config Codec operation parameter arrays != Number_of_ASEs and is set to 2 + * + * Expected behaviour: + * - "If the Response_Code value is 0x01 or 0x02, Number_of_ASEs shall be set to 0xFF." + * - ASE Control Point notification is correctly formatted + */ +ZTEST_F(ascs_ase_control_test_suite, test_codec_configure_invalid_length_too_many_parameter_arrays) +{ + const uint8_t buf[] = { + 0x01, /* Opcode = Config Codec */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + 0x01, /* Target_Latency[0] = Target low latency */ + 0x02, /* Target_PHY[0] = LE 2M PHY */ + 0x06, /* Codec_ID[0].Coding_Format = LC3 */ + 0x00, 0x00, /* Codec_ID[0].Company_ID */ + 0x00, 0x00, /* Codec_ID[0].Vendor_Specific_Codec_ID */ + 0x00, /* Codec_Specific_Configuration_Length[0] */ + 0x02, /* ASE_ID[1] */ + 0x01, /* Target_Latency[1] = Target low latency */ + 0x02, /* Target_PHY[1] = LE 2M PHY */ + 0x06, /* Codec_ID[1].Coding_Format = LC3 */ + 0x00, 0x00, /* Codec_ID[1].Company_ID */ + 0x00, 0x00, /* Codec_ID[1].Vendor_Specific_Codec_ID */ + 0x00, /* Codec_Specific_Configuration_Length[1] */ + }; + + test_codec_configure_invalid_length(fixture, buf, sizeof(buf)); +} + +/* + * Test correctly formatted ASE Control Point 'Invalid Length' notification is sent + * + * ASCS_v1.0; 5 ASE Control operations + * "A client-initiated ASE Control operation shall be defined as an invalid length operation + * if the total length of all parameters written by the client is not equal to the total length + * of all fixed parameters plus the length of any variable length parameters for that operation" + * + * Constraints: + * - Number_of_ASEs is set to 1 + * - Config Codec operation parameter arrays == Number_of_ASEs + * - Codec_Specific_Configuration_Length[i] > sizeof(Codec_Specific_Configuration[i]) + * + * Expected behaviour: + * - "If the Response_Code value is 0x01 or 0x02, Number_of_ASEs shall be set to 0xFF." + * - ASE Control Point notification is correctly formatted + */ +ZTEST_F(ascs_ase_control_test_suite, + test_codec_configure_invalid_length_codec_specific_configuration_too_short) +{ + uint8_t buf[] = { + 0x01, /* Opcode = Config Codec */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + 0x01, /* Target_Latency[0] = Target low latency */ + 0x02, /* Target_PHY[0] = LE 2M PHY */ + 0x06, /* Codec_ID[0].Coding_Format = LC3 */ + 0x00, 0x00, /* Codec_ID[0].Company_ID */ + 0x00, 0x00, /* Codec_ID[0].Vendor_Specific_Codec_ID */ + 0x05, /* Codec_Specific_Configuration_Length[0] */ + 0x00, 0x00, /* Codec_Specific_Configuration[0] */ + 0x00, 0x00, + }; + + test_codec_configure_invalid_length(fixture, buf, sizeof(buf)); +} + +/* + * Test correctly formatted ASE Control Point 'Invalid Length' notification is sent + * + * ASCS_v1.0; 5 ASE Control operations + * "A client-initiated ASE Control operation shall be defined as an invalid length operation + * if the total length of all parameters written by the client is not equal to the total length + * of all fixed parameters plus the length of any variable length parameters for that operation" + * + * Constraints: + * - Number_of_ASEs is set to 1 + * - Config Codec operation parameter arrays == Number_of_ASEs + * - Codec_Specific_Configuration_Length[i] < sizeof(Codec_Specific_Configuration[i]) + * + * Expected behaviour: + * - "If the Response_Code value is 0x01 or 0x02, Number_of_ASEs shall be set to 0xFF." + * - ASE Control Point notification is correctly formatted + */ +ZTEST_F(ascs_ase_control_test_suite, + test_codec_configure_invalid_length_codec_specific_configuration_too_long) +{ + uint8_t buf[] = { + 0x01, /* Opcode = Config Codec */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + 0x01, /* Target_Latency[0] = Target low latency */ + 0x02, /* Target_PHY[0] = LE 2M PHY */ + 0x06, /* Codec_ID[0].Coding_Format = LC3 */ + 0x00, 0x00, /* Codec_ID[0].Company_ID */ + 0x00, 0x00, /* Codec_ID[0].Vendor_Specific_Codec_ID */ + 0x05, /* Codec_Specific_Configuration_Length[0] */ + 0x00, 0x00, /* Codec_Specific_Configuration[0] */ + 0x00, 0x00, + 0x00, 0x00, + }; + + test_codec_configure_invalid_length(fixture, buf, sizeof(buf)); +} + +/* + * Test correctly formatted ASE Control Point 'Invalid ASE_ID' notification is sent + * + * Constraints: + * - Number_of_ASEs is set to 1 + * - Requested ASE_ID is not present on the server. + * + * Expected behaviour: + * - Correctly formatted ASE Control Point notification is sent with Invalid ASE_ID response code. + */ +static void test_codec_configure_invalid_ase_id(struct ascs_ase_control_test_suite_fixture *fixture, + uint8_t ase_id) +{ + const uint8_t buf[] = { + 0x01, /* Opcode = Config Codec */ + 0x01, /* Number_of_ASEs */ + ase_id, /* ASE_ID[0] */ + 0x01, /* Target_Latency[0] = Target low latency */ + 0x02, /* Target_PHY[0] = LE 2M PHY */ + 0x06, /* Codec_ID[0].Coding_Format = LC3 */ + 0x00, 0x00, /* Codec_ID[0].Company_ID */ + 0x00, 0x00, /* Codec_ID[0].Vendor_Specific_Codec_ID */ + 0x00, /* Codec_Specific_Configuration_Length[0] */ + }; + const uint8_t data_expected[] = { + 0x01, /* Opcode */ + 0x01, /* Number_of_ASEs */ + ase_id, /* ASE_ID[0] */ + 0x03, /* Response_Code[0] = Invalid ASE_ID */ + 0x00, /* Reason[0] */ + }; + + fixture->ase_cp->write(&fixture->conn, fixture->ase_cp, buf, sizeof(buf), 0, 0); + + expect_bt_gatt_notify_cb_called_once(&fixture->conn, BT_UUID_ASCS_ASE_CP, + fixture->ase_cp, data_expected, sizeof(data_expected)); +} + +ZTEST_F(ascs_ase_control_test_suite, test_codec_configure_invalid_ase_id_0x00) +{ + test_codec_configure_invalid_ase_id(fixture, 0x00); +} + +ZTEST_F(ascs_ase_control_test_suite, test_codec_configure_invalid_ase_id_unavailable) +{ + test_codec_configure_invalid_ase_id(fixture, (CONFIG_BT_ASCS_ASE_SNK_COUNT + + CONFIG_BT_ASCS_ASE_SRC_COUNT + 1)); +} + +static void test_codec_configure_target_latency_out_of_range( + struct ascs_ase_control_test_suite_fixture *fixture, uint8_t target_latency) +{ + const uint8_t buf[] = { + 0x01, /* Opcode = Config Codec */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + target_latency, /* Target_Latency[0] */ + 0x02, /* Target_PHY[0] = LE 2M PHY */ + 0x06, /* Codec_ID[0].Coding_Format = LC3 */ + 0x00, 0x00, /* Codec_ID[0].Company_ID */ + 0x00, 0x00, /* Codec_ID[0].Vendor_Specific_Codec_ID */ + 0x00, /* Codec_Specific_Configuration_Length[0] */ + }; + const uint8_t data_expected[] = { + 0x01, /* Opcode */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + 0x00, /* Response_Code[0] = Success */ + 0x00, /* Reason[0] */ + }; + + fixture->ase_cp->write(&fixture->conn, fixture->ase_cp, buf, sizeof(buf), 0, 0); + + expect_bt_gatt_notify_cb_called_once(&fixture->conn, BT_UUID_ASCS_ASE_CP, + fixture->ase_cp, data_expected, sizeof(data_expected)); +} + +ZTEST_F(ascs_ase_control_test_suite, test_codec_configure_target_latency_out_of_range_0x00) +{ + /* TODO: Remove once resolved */ + Z_TEST_SKIP_IFNDEF(BUG_55794); + + test_codec_configure_target_latency_out_of_range(fixture, 0x00); +} + +ZTEST_F(ascs_ase_control_test_suite, test_codec_configure_target_latency_out_of_range_0x04) +{ + /* TODO: Remove once resolved */ + Z_TEST_SKIP_IFNDEF(BUG_55794); + + test_codec_configure_target_latency_out_of_range(fixture, 0x04); +} + +static void test_codec_configure_target_phy_out_of_range( + struct ascs_ase_control_test_suite_fixture *fixture, uint8_t target_phy) +{ + const uint8_t buf[] = { + 0x01, /* Opcode = Config Codec */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + 0x01, /* Target_Latency[0] */ + target_phy, /* Target_PHY[0] */ + 0x06, /* Codec_ID[0].Coding_Format = LC3 */ + 0x00, 0x00, /* Codec_ID[0].Company_ID */ + 0x00, 0x00, /* Codec_ID[0].Vendor_Specific_Codec_ID */ + 0x00, /* Codec_Specific_Configuration_Length[0] */ + }; + const uint8_t data_expected[] = { + 0x01, /* Opcode */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + 0x00, /* Response_Code[0] = Success */ + 0x00, /* Reason[0] */ + }; + + fixture->ase_cp->write(&fixture->conn, fixture->ase_cp, buf, sizeof(buf), 0, 0); + + expect_bt_gatt_notify_cb_called_once(&fixture->conn, BT_UUID_ASCS_ASE_CP, + fixture->ase_cp, data_expected, sizeof(data_expected)); +} + +ZTEST_F(ascs_ase_control_test_suite, test_codec_configure_target_phy_out_of_range_0x00) +{ + /* TODO: Remove once resolved */ + Z_TEST_SKIP_IFNDEF(BUG_55794); + + test_codec_configure_target_phy_out_of_range(fixture, 0x00); +} + +ZTEST_F(ascs_ase_control_test_suite, test_codec_configure_target_phy_out_of_range_0x04) +{ + /* TODO: Remove once resolved */ + Z_TEST_SKIP_IFNDEF(BUG_55794); + + test_codec_configure_target_phy_out_of_range(fixture, 0x04); +} + +static struct bt_bap_stream *stream_allocated; + +int unicast_server_cb_config_custom_fake(struct bt_conn *conn, const struct bt_bap_ep *ep, + enum bt_audio_dir dir, const struct bt_codec *codec, + struct bt_bap_stream **stream, + struct bt_codec_qos_pref *const pref) +{ + *stream = stream_allocated; + *pref = qos_pref; + + bt_bap_stream_cb_register(*stream, &mock_bap_stream_ops); + + return 0; +} + +static void ase_cp_write_codec_config(const struct bt_gatt_attr *attr, struct bt_conn *conn, + struct bt_bap_stream *stream) +{ + const uint8_t buf[] = { + 0x01, /* Opcode = Config Codec */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + 0x01, /* Target_Latency[0] = Target low latency */ + 0x02, /* Target_PHY[0] = LE 2M PHY */ + 0x06, /* Codec_ID[0].Coding_Format = LC3 */ + 0x00, 0x00, /* Codec_ID[0].Company_ID */ + 0x00, 0x00, /* Codec_ID[0].Vendor_Specific_Codec_ID */ + 0x00, /* Codec_Specific_Configuration_Length[0] */ + }; + + ssize_t ret; + + stream_allocated = stream; + mock_bap_unicast_server_cb_config_fake.custom_fake = unicast_server_cb_config_custom_fake; + + ret = attr->write(conn, attr, (void *)buf, sizeof(buf), 0, 0); + zassert_false(ret < 0, "cp_attr->write returned unexpected (err 0x%02x)", BT_GATT_ERR(ret)); + + stream_allocated = NULL; +} + +ZTEST_F(ascs_ase_control_test_suite, test_sink_ase_control_codec_configure_from_idle) +{ + Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK); + + ase_cp_write_codec_config(fixture->ase_cp, &fixture->conn, &fixture->stream); + expect_bt_bap_unicast_server_cb_config_called_once(&fixture->conn, EMPTY, BT_AUDIO_DIR_SINK, + EMPTY); + expect_bt_bap_stream_ops_configured_called_once(&fixture->stream, EMPTY); +} + +static void ase_cp_write_config_qos(const struct bt_gatt_attr *attr, struct bt_conn *conn, + struct bt_bap_stream *stream) +{ + const uint8_t buf[] = { + 0x02, /* Opcode = Config QoS */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + 0x01, /* CIG_ID[0] */ + 0x01, /* CIS_ID[0] */ + 0xFF, 0x00, 0x00, /* SDU_Interval[0] */ + 0x00, /* Framing[0] */ + 0x02, /* PHY[0] */ + 0x64, 0x00, /* Max_SDU[0] */ + 0x02, /* Retransmission_Number[0] */ + 0x0A, 0x00, /* Max_Transport_Latency[0] */ + 0x40, 0x9C, 0x00, /* Presentation_Delay[0] */ + }; + ssize_t ret; + + ret = attr->write(conn, attr, (void *)buf, sizeof(buf), 0, 0); + zassert_false(ret < 0, "attr->write returned unexpected (err 0x%02x)", BT_GATT_ERR(ret)); +} + +ZTEST_F(ascs_ase_control_test_suite, test_sink_ase_control_qos_configure_from_codec_configured) +{ + Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK); + + /* Preamble */ + ase_cp_write_codec_config(fixture->ase_cp, &fixture->conn, &fixture->stream); + + ase_cp_write_config_qos(fixture->ase_cp, &fixture->conn, &fixture->stream); + expect_bt_bap_unicast_server_cb_qos_called_once(&fixture->stream, EMPTY); + expect_bt_bap_stream_ops_qos_set_called_once(&fixture->stream); +} + +static void ase_cp_write_enable(const struct bt_gatt_attr *attr, struct bt_conn *conn, + struct bt_bap_stream *stream) +{ + const uint8_t buf[] = { + 0x03, /* Opcode = Enable */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + 0x00, /* Metadata_Length[0] */ + }; + ssize_t ret; + + ret = attr->write(conn, attr, (void *)buf, sizeof(buf), 0, 0); + zassert_false(ret < 0, "attr->write returned unexpected (err 0x%02x)", BT_GATT_ERR(ret)); +} + +ZTEST_F(ascs_ase_control_test_suite, test_sink_ase_control_enable_from_qos_configured) +{ + Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK); + + /* Preamble */ + ase_cp_write_codec_config(fixture->ase_cp, &fixture->conn, &fixture->stream); + ase_cp_write_config_qos(fixture->ase_cp, &fixture->conn, &fixture->stream); + + ase_cp_write_enable(fixture->ase_cp, &fixture->conn, &fixture->stream); + expect_bt_bap_unicast_server_cb_enable_called_once(&fixture->stream, EMPTY, EMPTY); + expect_bt_bap_stream_ops_enabled_called_once(&fixture->stream); +} + +static void ase_cp_write_disable(const struct bt_gatt_attr *attr, struct bt_conn *conn, + struct bt_bap_stream *stream) +{ + const uint8_t buf[] = { + 0x05, /* Opcode = Disable */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + }; + ssize_t ret; + + ret = attr->write(conn, attr, (void *)buf, sizeof(buf), 0, 0); + zassert_false(ret < 0, "attr->write returned unexpected (err 0x%02x)", BT_GATT_ERR(ret)); +} + +ZTEST_F(ascs_ase_control_test_suite, test_sink_ase_control_disable_from_enabling) +{ + Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK); + + /* Preamble */ + ase_cp_write_codec_config(fixture->ase_cp, &fixture->conn, &fixture->stream); + ase_cp_write_config_qos(fixture->ase_cp, &fixture->conn, &fixture->stream); + ase_cp_write_enable(fixture->ase_cp, &fixture->conn, &fixture->stream); + + /* Reset the bap_stream_ops.qos_set callback that is expected to be called again */ + mock_bap_stream_qos_set_cb_reset(); + + ase_cp_write_disable(fixture->ase_cp, &fixture->conn, &fixture->stream); + expect_bt_bap_unicast_server_cb_disable_called_once(&fixture->stream); + expect_bt_bap_stream_ops_qos_set_called_once(&fixture->stream); +} + +static void ase_cp_write_release(const struct bt_gatt_attr *attr, struct bt_conn *conn, + struct bt_bap_stream *stream) +{ + const uint8_t buf[] = { + 0x08, /* Opcode = Disable */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + }; + ssize_t ret; + + ret = attr->write(conn, attr, (void *)buf, sizeof(buf), 0, 0); + zassert_false(ret < 0, "attr->write returned unexpected (err 0x%02x)", BT_GATT_ERR(ret)); +} + +ZTEST_F(ascs_ase_control_test_suite, test_sink_ase_control_release_from_qos_configured) +{ + Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK); + + /* Preamble */ + ase_cp_write_codec_config(fixture->ase_cp, &fixture->conn, &fixture->stream); + ase_cp_write_config_qos(fixture->ase_cp, &fixture->conn, &fixture->stream); + ase_cp_write_enable(fixture->ase_cp, &fixture->conn, &fixture->stream); + ase_cp_write_disable(fixture->ase_cp, &fixture->conn, &fixture->stream); + + /* QoS configured state */ + + ase_cp_write_release(fixture->ase_cp, &fixture->conn, &fixture->stream); + expect_bt_bap_unicast_server_cb_release_called_once(&fixture->stream); + expect_bt_bap_stream_ops_released_called_once(&fixture->stream); +} diff --git a/tests/bluetooth/audio/ascs/testcase.yaml b/tests/bluetooth/audio/ascs/testcase.yaml new file mode 100644 index 000000000000..7647e8268592 --- /dev/null +++ b/tests/bluetooth/audio/ascs/testcase.yaml @@ -0,0 +1,5 @@ +common: + tags: bluetooth bluetooth_audio +tests: + bluetooth.audio.ascs.test: + type: unit diff --git a/tests/bluetooth/audio/ascs/uut/CMakeLists.txt b/tests/bluetooth/audio/ascs/uut/CMakeLists.txt new file mode 100644 index 000000000000..ad4aba9a501a --- /dev/null +++ b/tests/bluetooth/audio/ascs/uut/CMakeLists.txt @@ -0,0 +1,26 @@ +# +# Copyright (c) 2022 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# +# CMakeLists.txt file for creating of uut library. +# + +add_library(uut STATIC + ${ZEPHYR_BASE}/subsys/bluetooth/audio/ascs.c + ${ZEPHYR_BASE}/subsys/bluetooth/audio/audio.c + ${ZEPHYR_BASE}/subsys/bluetooth/audio/bap_iso.c + ${ZEPHYR_BASE}/subsys/bluetooth/audio/bap_stream.c + ${ZEPHYR_BASE}/subsys/bluetooth/audio/bap_unicast_server.c + ${ZEPHYR_BASE}/subsys/bluetooth/common/bt_str.c + ${ZEPHYR_BASE}/subsys/bluetooth/host/data.c + ${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c + ${ZEPHYR_BASE}/subsys/logging/log_minimal.c + ${ZEPHYR_BASE}/subsys/net/buf_simple.c +) + +add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/audio/mocks mocks) + +target_link_libraries(uut PUBLIC test_interface mocks) + +target_compile_options(uut PRIVATE -std=c11 -include ztest.h) From e9f12f21d57c9603b02c7bc64bb4c88491bdb5de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hidalgo=20Mu=C3=B1oz=20de=20Rivera?= Date: Wed, 8 Mar 2023 20:36:20 +0100 Subject: [PATCH 0628/1906] samples: Updated README for tracing application sample MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated README.txt to .rst format file Signed-off-by: Alejandro Hidalgo Muñoz de Rivera --- samples/subsys/tracing/README.rst | 103 ++++++++++++++++++++++++++++++ samples/subsys/tracing/README.txt | 64 ------------------- 2 files changed, 103 insertions(+), 64 deletions(-) create mode 100644 samples/subsys/tracing/README.rst delete mode 100644 samples/subsys/tracing/README.txt diff --git a/samples/subsys/tracing/README.rst b/samples/subsys/tracing/README.rst new file mode 100644 index 000000000000..adaa62c20863 --- /dev/null +++ b/samples/subsys/tracing/README.rst @@ -0,0 +1,103 @@ +.. _tracing_sample: + +Send Tracing Formatted Packet To The Host With Supported Backends +################################################################# + +Overview +******** + +This application can be used to demonstrate the tracing feature. The tracing +formatted packet will be sent to the host with the currently supported tracing +backend under tracing generic infrastructure. + +Requirements +************ + +Depends of the boards which you are using, choose one of .conf files for use tracing subsys. + +Usage for UART Tracing Backend +****************************** + +Build a UART-tracing image with: + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/tracing + :board: mps2_an521 + :conf: "prj_uart.conf" + :goals: build + :compact: + +or: + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/tracing + :board: mps2_an521 + :conf: "prj_uart_ctf.conf" + :goals: build + :compact: + +.. note:: You may need to set "zephyr,tracing-uart" property under the chosen node in your devicetree. See :zephyr_file:`boards/mps2_an521.overlay` for an example. + +After the application has run for a while, check the trace output file. + +Usage for USB Tracing Backend +***************************** + +Build a USB-tracing image with: + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/tracing + :board: sam_e70_xplained + :conf: "prj_usb.conf" + :goals: build + :compact: + +or: + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/tracing + :board: sam_e70_xplained + :conf: "prj_usb_ctf.conf" + :goals: build + :compact: + +After the serial console has stable output like this: + +.. code-block:: console + + threadA: Hello World! + threadB: Hello World! + threadA: Hello World! + threadB: Hello World! + +Connect the board's USB port to the host device and +run the :zephyr_file:`trace_capture_usb.py` script on the host: + +.. code-block:: console + + sudo python3 trace_capture_usb.py -v 0x2FE9 -p 0x100 -o channel0_0 + +The VID and PID of USB device can be configured, just adjusting it accordingly. + +Usage for POSIX Tracing Backend +******************************* + +Build a POSIX-tracing image with: + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/tracing + :board: native_posix + :conf: "prj_native_posix.conf" + :goals: build + :compact: + +or: + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/tracing + :board: native_posix + :conf: "prj_native_posix_ctf.conf" + :goals: build + :compact: + +After the application has run for a while, check the trace output file. diff --git a/samples/subsys/tracing/README.txt b/samples/subsys/tracing/README.txt deleted file mode 100644 index ef7e8d8ddae2..000000000000 --- a/samples/subsys/tracing/README.txt +++ /dev/null @@ -1,64 +0,0 @@ -Title: Send Tracing Formatted Packet To The Host With Supported Backends - -Description: - -This application can be used to demonstrate the tracing feature. The tracing -formatted packet will be sent to the host with the currently supported tracing -backend under tracing generic infrastructure. - --------------------------------------------------------------------------------- - -Usage for UART Tracing Backend: - -Build a UART-tracing image with: - - cmake -DBOARD=mps2_an521 -DCONF_FILE=prj_uart.conf .. - -or: - - cmake -DBOARD=mps2_an521 -DCONF_FILE=prj_uart_ctf.conf .. - -NOTE: You may need to set 'zephyr,tracing-uart' property under the chosen -node in your devicetree. See boards/mps2_an521.overlay for an example. - -After the application has run for a while, check the trace output file. - --------------------------------------------------------------------------------- - -Usage for USB Tracing Backend - -Build a USB-tracing image with: - - cmake -DBOARD=sam_e70_xplained -DCONF_FILE=prj_usb.conf .. - -or: - - cmake -DBOARD=sam_e70_xplained -DCONF_FILE=prj_usb_ctf.conf .. - -After the serial console has stable output like this: - - threadA: Hello World! - threadB: Hello World! - threadA: Hello World! - threadB: Hello World! - -connect the board's USB port to the host device and -run the trace_capture_usb.py script on the host: - - sudo python3 trace_capture_usb.py -v 0x2FE9 -p 0x100 -o channel0_0 - -The VID and PID of USB device can be configured, just adjusting it accordingly. - --------------------------------------------------------------------------------- - -Usage for POSIX Tracing Backend - -Build a POSIX-tracing image with: - - cmake -DBOARD=native_posix -DCONF_FILE=prj_native_posix.conf .. - -or: - - cmake -DBOARD=native_posix -DCONF_FILE=prj_native_posix_ctf.conf .. - -After the application has run for a while, check the trace output file. From 147aada0b506ad25d41b82614b96d5c0968ece28 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 22 Mar 2023 09:58:24 +0100 Subject: [PATCH 0629/1906] tests controller permute build: Move to ll folder This is a controller test. Let's move it to the controller folder. Signed-off-by: Alberto Escolar Piedras --- tests/bsim/bluetooth/{ => ll}/_compile_permutate_kconfigs.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/bsim/bluetooth/{ => ll}/_compile_permutate_kconfigs.sh (100%) diff --git a/tests/bsim/bluetooth/_compile_permutate_kconfigs.sh b/tests/bsim/bluetooth/ll/_compile_permutate_kconfigs.sh similarity index 100% rename from tests/bsim/bluetooth/_compile_permutate_kconfigs.sh rename to tests/bsim/bluetooth/ll/_compile_permutate_kconfigs.sh From 159e633f330556b4dfa8ef6b7b20ffc21eeb1f40 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Wed, 22 Mar 2023 10:01:02 +0100 Subject: [PATCH 0630/1906] MAINTAINERS: Add tests/bsim infra scripts to nrf52_bsim category Today these scripts are orphan. Let's better set them as owned by the nrf52_bsim maintainer. Signed-off-by: Alberto Escolar Piedras --- MAINTAINERS.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index 742c106acaea..14d4437a2033 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -1826,6 +1826,9 @@ nRF52 BSIM: files: - boards/posix/nrf52_bsim/ - tests/boards/nrf52_bsim/ + - tests/bsim/ + files-exclude: + - tests/bsim/*/ labels: - "platform: nRF52 BSIM" From 82efb21e91a241d62608d5dd841fcadfc6afef96 Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Mon, 20 Mar 2023 15:06:47 +0100 Subject: [PATCH 0631/1906] MAINTAINERS: move mesh and ll from bsim/tests to their proper section The babblesim tests for bluetooth have been moved to a new folder. To ensure that the proper people still get involved this PR adds the bsim/tests/bluetooth/ll folder to the bluetooth controller section and similar for the mesh babblesim folder Signed-off-by: Andries Kruithof --- MAINTAINERS.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index 14d4437a2033..243ed51f1737 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -203,6 +203,7 @@ Bluetooth: - subsys/bluetooth/services/ - subsys/bluetooth/shell/ - tests/bluetooth/ + - tests/bsim/bluetooth/ files-exclude: - include/zephyr/bluetooth/mesh/ - subsys/bluetooth/controller/ @@ -211,9 +212,11 @@ Bluetooth: - subsys/bluetooth/audio/ - include/zephyr/bluetooth/audio/ - tests/bsim/bluetooth/audio/ + - tests/bsim/bluetooth/ll/ - tests/bluetooth/controller/ - tests/bluetooth/mesh_*/ - tests/bluetooth/mesh/ + - tests/bsim/bluetooth/mesh/ - tests/bluetooth/shell/audio* labels: - "area: Bluetooth" @@ -233,6 +236,7 @@ Bluetooth controller: files: - subsys/bluetooth/controller/ - tests/bluetooth/controller/ + - tests/bsim/bluetooth/ll/ labels: - "area: Bluetooth Controller" - "area: Bluetooth" @@ -250,6 +254,7 @@ Bluetooth Mesh: - subsys/bluetooth/mesh/ - include/zephyr/bluetooth/mesh/ - tests/bluetooth/mesh*/ + - tests/bsim/bluetooth/mesh/ - samples/bluetooth/mesh/ labels: - "area: Bluetooth Mesh" From b3545b34cfe00e51d3a0d5d552112376aa41161f Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Wed, 22 Mar 2023 11:55:29 +0200 Subject: [PATCH 0632/1906] arch: x86: zefi: Remove unneeded include Fixes unneeded chain of includes. Since zefi is built separately (using python script), any dependency creates include chain with possibly missing configuration options. Signed-off-by: Andrei Emeltchenko --- arch/x86/zefi/efi.h | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/x86/zefi/efi.h b/arch/x86/zefi/efi.h index 3e280517877d..9be17c53e140 100644 --- a/arch/x86/zefi/efi.h +++ b/arch/x86/zefi/efi.h @@ -10,7 +10,6 @@ #ifndef _ASMLANGUAGE #include -#include #define __abi __attribute__((ms_abi)) From 26ebceed55b94b6e9bc98e2bf4c892a05404bf16 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Wed, 22 Mar 2023 10:19:40 +0100 Subject: [PATCH 0633/1906] kconfig: add note about increasing default stack sizes for -O0 Add a note about increasing default stack sizes to the CONFIG_NO_OPTIMIZATIONS help text. Signed-off-by: Henrik Brix Andersen --- Kconfig.zephyr | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 5164fdf2d1f0..43f0f4321777 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -360,6 +360,9 @@ config NO_OPTIMIZATIONS help Compiler optimizations will be set to -O0 independently of other options. + + Selecting this option will likely require manual tuning of the + default stack sizes in order to avoid stack overflows. endchoice config COMPILER_WARNINGS_AS_ERRORS From 70f1e83c214b91c400c530f1c611618b36416f0a Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Wed, 7 Sep 2022 15:21:25 +0300 Subject: [PATCH 0634/1906] smbus: dts: Add bindings for SMBus controllers Adds bindings for SMBus controllers. Signed-off-by: Andrei Emeltchenko --- dts/bindings/smbus/smbus-controller.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 dts/bindings/smbus/smbus-controller.yaml diff --git a/dts/bindings/smbus/smbus-controller.yaml b/dts/bindings/smbus/smbus-controller.yaml new file mode 100644 index 000000000000..fd8ec574b88e --- /dev/null +++ b/dts/bindings/smbus/smbus-controller.yaml @@ -0,0 +1,19 @@ +# Copyright (c) 2022 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +# Common fields for SMBus controllers + +include: base.yaml + +bus: smbus + +properties: + "#address-cells": + required: true + const: 1 + "#size-cells": + required: true + const: 0 + clock-frequency: + type: int + description: Initial clock frequency in Hz From 0633b8c75cf74437834c4c3cfec1752bd0c16b6e Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Wed, 21 Sep 2022 09:43:55 +0300 Subject: [PATCH 0635/1906] smbus: dts: Add bindings for SMBus peripherals Add bindings for SMBus peripheral devices on a bus. Signed-off-by: Andrei Emeltchenko --- dts/bindings/smbus/smbus-device.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 dts/bindings/smbus/smbus-device.yaml diff --git a/dts/bindings/smbus/smbus-device.yaml b/dts/bindings/smbus/smbus-device.yaml new file mode 100644 index 000000000000..5721a06a2b6e --- /dev/null +++ b/dts/bindings/smbus/smbus-device.yaml @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +# Common fields for SMBus devices + +include: [base.yaml, power.yaml] + +on-bus: smbus + +properties: + reg: + required: true + description: device address on SMBus bus From adff73d618bde2c83e9e6566ff199e27a79b7aad Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Wed, 7 Sep 2022 15:30:23 +0300 Subject: [PATCH 0636/1906] smbus: Introduce SMBus subsystem driver API Introduces SMBus driver API for SMBus controllers. Signed-off-by: Andrei Emeltchenko --- drivers/CMakeLists.txt | 1 + drivers/Kconfig | 1 + drivers/smbus/CMakeLists.txt | 6 + drivers/smbus/Kconfig | 30 ++ drivers/smbus/smbus_handlers.c | 130 +++++ include/zephyr/drivers/smbus.h | 937 +++++++++++++++++++++++++++++++++ 6 files changed, 1105 insertions(+) create mode 100644 drivers/smbus/CMakeLists.txt create mode 100644 drivers/smbus/Kconfig create mode 100644 drivers/smbus/smbus_handlers.c create mode 100644 include/zephyr/drivers/smbus.h diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index eb626f2868a7..98d5b55a2b9d 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -35,6 +35,7 @@ add_subdirectory_ifdef(CONFIG_FUEL_GAUGE fuel_gauge) add_subdirectory_ifdef(CONFIG_GPIO gpio) add_subdirectory_ifdef(CONFIG_HWINFO hwinfo) add_subdirectory_ifdef(CONFIG_I2C i2c) +add_subdirectory_ifdef(CONFIG_SMBUS smbus) add_subdirectory_ifdef(CONFIG_I2S i2s) add_subdirectory_ifdef(CONFIG_I3C i3c) add_subdirectory_ifdef(CONFIG_IEEE802154 ieee802154) diff --git a/drivers/Kconfig b/drivers/Kconfig index e462c28a440d..1439d5330719 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -35,6 +35,7 @@ source "drivers/hwinfo/Kconfig" source "drivers/i2c/Kconfig" source "drivers/i2s/Kconfig" source "drivers/i3c/Kconfig" +source "drivers/smbus/Kconfig" source "drivers/ieee802154/Kconfig" source "drivers/input/Kconfig" source "drivers/interrupt_controller/Kconfig" diff --git a/drivers/smbus/CMakeLists.txt b/drivers/smbus/CMakeLists.txt new file mode 100644 index 000000000000..a2d2e75e4899 --- /dev/null +++ b/drivers/smbus/CMakeLists.txt @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() + + +zephyr_library_sources_ifdef(CONFIG_USERSPACE smbus_handlers.c) diff --git a/drivers/smbus/Kconfig b/drivers/smbus/Kconfig new file mode 100644 index 000000000000..808aa74845fb --- /dev/null +++ b/drivers/smbus/Kconfig @@ -0,0 +1,30 @@ +# SMBus configuration options + +# Copyright (c) 2022 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +menuconfig SMBUS + bool "SMBus Drivers" + help + Enable SMBus Driver Configuration + +if SMBUS + +config SMBUS_STATS + bool "SMBus device Stats" + depends on STATS + help + Enable SMBus Stats. + +config SMBUS_INIT_PRIORITY + int "Init priority" + default KERNEL_INIT_PRIORITY_DEVICE + help + SMBus device driver initialization priority. + + +module = SMBUS +module-str = smbus +source "subsys/logging/Kconfig.template.log_config" + +endif # SMBUS diff --git a/drivers/smbus/smbus_handlers.c b/drivers/smbus/smbus_handlers.c new file mode 100644 index 000000000000..93ae3eb9a60f --- /dev/null +++ b/drivers/smbus/smbus_handlers.c @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +static inline int z_vrfy_smbus_configure(const struct device *dev, + uint32_t dev_config) +{ + Z_OOPS(Z_SYSCALL_DRIVER_SMBUS(dev, configure)); + + return z_impl_smbus_configure(dev, dev_config); +} +#include + +static inline int z_vrfy_smbus_get_config(const struct device *dev, + uint32_t *dev_config) +{ + Z_OOPS(Z_SYSCALL_DRIVER_SMBUS(dev, get_config)); + Z_OOPS(Z_SYSCALL_MEMORY_WRITE(dev_config, sizeof(uint32_t))); + + return z_impl_smbus_get_config(dev, dev_config); +} +#include + +static inline int z_vrfy_smbus_quick(const struct device *dev, uint16_t addr, + enum smbus_direction rw) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + + return z_impl_smbus_quick(dev, addr, rw); +} +#include + +static inline int z_vrfy_smbus_byte_write(const struct device *dev, + uint16_t addr, uint8_t byte) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + + return z_impl_smbus_byte_write(dev, addr, byte); +} +#include + +static inline int z_vrfy_smbus_byte_read(const struct device *dev, + uint16_t addr, uint8_t *byte) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + Z_OOPS(Z_SYSCALL_MEMORY_WRITE(byte, sizeof(uint8_t))); + + return z_impl_smbus_byte_read(dev, addr, byte); +} +#include + +static inline int z_vrfy_smbus_byte_data_write(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t byte) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + + return z_impl_smbus_byte_data_write(dev, addr, cmd, byte); +} +#include + +static inline int z_vrfy_smbus_byte_data_read(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t *byte) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + Z_OOPS(Z_SYSCALL_MEMORY_WRITE(byte, sizeof(uint8_t))); + + return z_impl_smbus_byte_data_read(dev, addr, cmd, byte); +} +#include + +static inline int z_vrfy_smbus_word_data_write(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint16_t word) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + + return z_impl_smbus_word_data_write(dev, addr, cmd, word); +} +#include + +static inline int z_vrfy_smbus_word_data_read(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint16_t *word) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + Z_OOPS(Z_SYSCALL_MEMORY_WRITE(word, sizeof(uint16_t))); + + return z_impl_smbus_word_data_read(dev, addr, cmd, word); +} +#include + +static inline int z_vrfy_smbus_pcall(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint16_t send_word, uint16_t *recv_word) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + Z_OOPS(Z_SYSCALL_MEMORY_WRITE(recv_word, sizeof(uint16_t))); + + return z_impl_smbus_pcall(dev, addr, cmd, send_word, recv_word); +} +#include + +static inline int z_vrfy_smbus_block_write(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t count, uint8_t *buf) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + Z_OOPS(Z_SYSCALL_MEMORY_READ(buf, count)); + + return z_impl_smbus_block_write(dev, addr, cmd, count, buf); +} +#include + +static inline int z_vrfy_smbus_block_read(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t *count, uint8_t *buf) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + Z_OOPS(Z_SYSCALL_MEMORY_WRITE(count, sizeof(uint8_t))); + + return z_impl_smbus_block_read(dev, addr, cmd, count, buf); +} +#include diff --git a/include/zephyr/drivers/smbus.h b/include/zephyr/drivers/smbus.h new file mode 100644 index 000000000000..872f0481f29a --- /dev/null +++ b/include/zephyr/drivers/smbus.h @@ -0,0 +1,937 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_SMBUS_H_ +#define ZEPHYR_INCLUDE_DRIVERS_SMBUS_H_ + +/** + * @brief SMBus Interface + * @defgroup smbus_interface SMBus Interface + * @ingroup io_interfaces + * @{ + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name SMBus Protocol commands + * @{ + * + * SMBus Specification defines following SMBus protocols operations + */ + +/** + * SMBus Quick protocol is very simple command with no data sent or + * received. Peripheral may denote only R/W bit, which can still be + * used for the peripheral management, for example to switch peripheral + * On/Off. Quick protocol can also be used for peripheral devices + * scanning. + * + * @code + * 0 1 + * 0 1 2 3 4 5 6 7 8 9 0 + * +-+-+-+-+-+-+-+-+-+-+-+ + * |S| Periph Addr |D|A|P| + * +-+-+-+-+-+-+-+-+-+-+-+ + * @endcode + */ +#define SMBUS_CMD_QUICK 0b000 + +/** + * SMBus Byte protocol can send or receive one byte of data. + * + * @code + * Byte Write + * + * 0 1 2 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |S| Periph Addr |W|A| Command code |A|P| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * Byte Read + * + * 0 1 2 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |S| Periph Addr |R|A| Byte received |N|P| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * @endcode + */ +#define SMBUS_CMD_BYTE 0b001 + +/** + * SMBus Byte Data protocol send first byte (command) followed + * by read or write one byte. + * + * @code + * Byte Data Write + * + * 0 1 2 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |S| Periph Addr |W|A| Command code |A| Data Write |A|P| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * Byte Data Read + * + * 0 1 2 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |S| Periph Addr |W|A| Command code |A|S| Periph Addr |R|A| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Data Read |N|P| + * +-+-+-+-+-+-+-+-+-+-+ + * @endcode + */ +#define SMBUS_CMD_BYTE_DATA 0b010 + +/** + * SMBus Word Data protocol send first byte (command) followed + * by read or write two bytes. + * + * @code + * Word Data Write + * + * 0 1 2 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |S| Periph Addr |W|A| Command code |A| Data Write Low|A| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Data Write Hi |A|P| + * +-+-+-+-+-+-+-+-+-+-+ + * + * Word Data Read + * + * 0 1 2 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |S| Periph Addr |W|A| Command code |A|S| Periph Addr |R| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |A| Data Read Low |A| Data Read Hi |N|P| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * @endcode + */ +#define SMBUS_CMD_WORD_DATA 0b011 + +/** + * SMBus Process Call protocol is basically Write Word followed by + * Wead Word. It is named so because command sends data and waits + * for the perihperal to return reply. + * + * @code + * 0 1 2 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |S| Periph Addr |W|A| Command code |A| Data Write Low|A| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Data Write Hi |A|S| Periph Addr |R|A| Data Read Low |A| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Data Read Hi |N|P| + * +-+-+-+-+-+-+-+-+-+-+ + * @endcode + */ +#define SMBUS_CMD_PROC_CALL 0b100 + +/** + * SMBus Block protocol reads or writes block of data up to 32 bytes. + * Count byte specifies the amount of data. + * + * @code + * + * SMBus Block Write + * + * 0 1 2 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |S| Periph Addr |W|A| Command code |A| Send Count=N |A| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Data Write 1 |A| ... |A| Data Write N |A|P| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * SMBus Block Read + * + * 0 1 2 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |S| Periph Addr |W|A| Command code |A|S| Periph Addr |R| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |A| Recv Count=N |A| Data Read 1 |A| ... |A| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Data Read N |N|P| + * +-+-+-+-+-+-+-+-+-+-+ + * @endcode + */ +#define SMBUS_CMD_BLOCK 0b101 + +/** + * SMBus Block Write - Block Read Process Call protocol is basically + * Block Write followed by Block Read + * + * @code + * 0 1 2 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |S| Periph Addr |W|A| Command code |A| Count = N |A| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Data Write 1 |A| ... |A| Data Write N |A|S| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Periph Addr |R|A| Recv Count=N |A| Data Read 1 |A| | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | ... |A| Data Read N |N|P| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * @endcode + */ +#define SMBUS_CMD_BLOCK_PROC 0b111 +/** @} */ + +/** Maximum number of bytes in SMBus Block protocol */ +#define SMBUS_BLOCK_BYTES_MAX 32 + +/** + * @name SMBus device functionality + * @{ + * + * Following parameters describes functionality of SMBus device + */ + +/** Peripheral to act as Controller. */ +#define SMBUS_MODE_CONTROLLER BIT(0) + +/** Support Packet Error Code (PEC) checking */ +#define SMBUS_MODE_PEC BIT(1) + +/** @} */ + +/** + * @name SMBus special reserved addresses + * @{ + * + * Following addresses are reserved by SMBus specification + */ + +/** + * @brief Alert Response Address (ARA) + * + * A broadcast address used by the system host as part of the + * Alert Response Protocol. + */ +#define SMBUS_ADDRESS_ARA 0x0c + +/** @} */ + +/** + * @name SMBus read / write direction + * @{ + */ + +/** @brief SMBus read / write direction */ +enum smbus_direction { + /** Write message to SMBus */ + SMBUS_MSG_WRITE = 0, + /** Read message from SMBus */ + SMBUS_MSG_READ = 1, +}; + +/** @} */ + +/** @cond INTERNAL_HIDDEN */ +#define SMBUS_MSG_RW_MASK BIT(0) +/** @endcond */ + +/** + * @brief Complete SMBus DT information + * + * @param bus SMBus bus + * @param addr peripheral address + */ +struct smbus_dt_spec { + const struct device *bus; + uint16_t addr; +}; + +/** + * @brief Structure initializer for smbus_dt_spec from devicetree + * + * This helper macro expands to a static initializer for a struct + * smbus_dt_spec by reading the relevant bus and address data from + * the devicetree. + * + * @param node_id Devicetree node identifier for the SMBus device whose + * struct smbus_dt_spec to create an initializer for + */ +#define SMBUS_DT_SPEC_GET(node_id) \ + { \ + .bus = DEVICE_DT_GET(DT_BUS(node_id)), \ + .addr = DT_REG_ADDR(node_id) \ + } + +/** + * @brief Structure initializer for smbus_dt_spec from devicetree instance + * + * This is equivalent to + * SMBUS_DT_SPEC_GET(DT_DRV_INST(inst)). + * + * @param inst Devicetree instance number + */ +#define SMBUS_DT_SPEC_INST_GET(inst) SMBUS_DT_SPEC_GET(DT_DRV_INST(inst)) + +/** + * @cond INTERNAL_HIDDEN + * + * These are for internal use only, so skip these in + * public documentation. + */ + +typedef int (*smbus_api_configure_t)(const struct device *dev, + uint32_t dev_config); +typedef int (*smbus_api_get_config_t)(const struct device *dev, + uint32_t *dev_config); +typedef int (*smbus_api_quick_t)(const struct device *dev, + uint16_t addr, enum smbus_direction); +typedef int (*smbus_api_byte_write_t)(const struct device *dev, + uint16_t addr, uint8_t byte); +typedef int (*smbus_api_byte_read_t)(const struct device *dev, + uint16_t addr, uint8_t *byte); +typedef int (*smbus_api_byte_data_write_t)(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t byte); +typedef int (*smbus_api_byte_data_read_t)(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t *byte); +typedef int (*smbus_api_word_data_write_t)(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint16_t word); +typedef int (*smbus_api_word_data_read_t)(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint16_t *word); +typedef int (*smbus_api_pcall_t)(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint16_t send_word, uint16_t *recv_word); +typedef int (*smbus_api_block_write_t)(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t count, uint8_t *buf); +typedef int (*smbus_api_block_read_t)(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t *count, uint8_t *buf); +typedef int (*smbus_api_block_pcall_t)(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t send_count, uint8_t *send_buf, + uint8_t *recv_count, uint8_t *recv_buf); + +__subsystem struct smbus_driver_api { + smbus_api_configure_t configure; + smbus_api_get_config_t get_config; + smbus_api_quick_t smbus_quick; + smbus_api_byte_write_t smbus_byte_write; + smbus_api_byte_read_t smbus_byte_read; + smbus_api_byte_data_write_t smbus_byte_data_write; + smbus_api_byte_data_read_t smbus_byte_data_read; + smbus_api_word_data_write_t smbus_word_data_write; + smbus_api_word_data_read_t smbus_word_data_read; + smbus_api_pcall_t smbus_pcall; + smbus_api_block_write_t smbus_block_write; + smbus_api_block_read_t smbus_block_read; + smbus_api_block_pcall_t smbus_block_pcall; +}; + +/** + * @endcond + */ + +#if defined(CONFIG_SMBUS_STATS) || defined(__DOXYGEN__) + +#include + +/** @cond INTERNAL_HIDDEN */ + +STATS_SECT_START(smbus) +STATS_SECT_ENTRY32(bytes_read) +STATS_SECT_ENTRY32(bytes_written) +STATS_SECT_ENTRY32(command_count) +STATS_SECT_END; + +STATS_NAME_START(smbus) +STATS_NAME(smbus, bytes_read) +STATS_NAME(smbus, bytes_written) +STATS_NAME(smbus, command_count) +STATS_NAME_END(smbus); + +struct smbus_device_state { + struct device_state devstate; + struct stats_smbus stats; +}; + +/** + * @brief Define a statically allocated and section assigned smbus device state + */ +#define Z_SMBUS_DEVICE_STATE_DEFINE(node_id, dev_name) \ + static struct smbus_device_state Z_DEVICE_STATE_NAME(dev_name) \ + __attribute__((__section__(".z_devstate"))); + +/** + * @brief Define an smbus device init wrapper function + * + * This does device instance specific initialization of common data + * (such as stats) and calls the given init_fn + */ +#define Z_SMBUS_INIT_FN(dev_name, init_fn) \ + static inline int \ + UTIL_CAT(dev_name, _init)(const struct device *dev) \ + { \ + struct smbus_device_state *state = \ + CONTAINER_OF(dev->state, \ + struct smbus_device_state, \ + devstate); \ + stats_init(&state->stats.s_hdr, STATS_SIZE_32, 4, \ + STATS_NAME_INIT_PARMS(smbus)); \ + stats_register(dev->name, &(state->stats.s_hdr)); \ + return init_fn(dev); \ + } + +/** @endcond */ + +/** + * @brief Updates the SMBus stats + * + * @param dev SMBus device to update stats for + * @param sent Number of bytes sent + * @param recv Number of bytes received + */ +static inline void smbus_xfer_stats(const struct device *dev, uint8_t sent, + uint8_t recv) +{ + struct smbus_device_state *state = + CONTAINER_OF(dev->state, struct smbus_device_state, devstate); + + STATS_INC(state->stats, command_count); + STATS_INCN(state->stats, bytes_read, recv); + STATS_INCN(state->stats, bytes_written, sent); +} + +/** + * @brief Like DEVICE_DT_DEFINE() with SMBus specifics. + * + * @details Defines a device which implements the SMBus API. May + * generate a custom device_state container struct and init_fn + * wrapper when needed depending on SMBus @kconfig{CONFIG_SMBUS_STATS}. + * + * @param node_id The devicetree node identifier. + * + * @param init_fn Name of the init function of the driver. + * + * @param pm_device PM device resources reference + * (NULL if device does not use PM). + * + * @param data_ptr Pointer to the device's private data. + * + * @param cfg_ptr The address to the structure containing the + * configuration information for this instance of the driver. + * + * @param level The initialization level. See SYS_INIT() for + * details. + * + * @param prio Priority within the selected initialization level. See + * SYS_INIT() for details. + * + * @param api_ptr Provides an initial pointer to the API function struct + * used by the driver. Can be NULL. + */ +#define SMBUS_DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \ + data_ptr, cfg_ptr, level, prio, \ + api_ptr, ...) \ + Z_SMBUS_DEVICE_STATE_DEFINE(node_id, \ + Z_DEVICE_DT_DEV_NAME(node_id)); \ + Z_SMBUS_INIT_FN(Z_DEVICE_DT_DEV_NAME(node_id), init_fn) \ + Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_NAME(node_id), \ + DEVICE_DT_NAME(node_id), \ + &UTIL_CAT(Z_DEVICE_DT_DEV_NAME(node_id), _init),\ + pm_device, \ + data_ptr, cfg_ptr, level, prio, \ + api_ptr, \ + &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_NAME \ + (node_id)).devstate), \ + __VA_ARGS__) + +#else /* CONFIG_SMBUS_STATS */ + +static inline void smbus_xfer_stats(const struct device *dev, uint8_t sent, + uint8_t recv) +{ + ARG_UNUSED(dev); + ARG_UNUSED(sent); + ARG_UNUSED(recv); +} + +#define SMBUS_DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \ + data_ptr, cfg_ptr, level, prio, \ + api_ptr, ...) \ + DEVICE_DT_DEFINE(node_id, &init_fn, pm_device, \ + data_ptr, cfg_ptr, level, prio, \ + api_ptr, __VA_ARGS__) + +#endif /* CONFIG_SMBUS_STATS */ + +/** + * @brief Like SMBUS_DEVICE_DT_DEFINE() for an instance of a DT_DRV_COMPAT + * compatible + * + * @param inst instance number. This is replaced by + * DT_DRV_COMPAT(inst) in the call to SMBUS_DEVICE_DT_DEFINE(). + * + * @param ... other parameters as expected by SMBUS_DEVICE_DT_DEFINE(). + */ +#define SMBUS_DEVICE_DT_INST_DEFINE(inst, ...) \ + SMBUS_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__) + +/** + * @brief Configure operation of a SMBus host controller. + * + * @param dev Pointer to the device structure for the driver instance. + * @param dev_config Bit-packed 32-bit value to the device runtime configuration + * for the SMBus controller. + * + * @retval 0 If successful. + * @retval -EIO General input / output error, failed to configure device. + */ +__syscall int smbus_configure(const struct device *dev, uint32_t dev_config); + +static inline int z_impl_smbus_configure(const struct device *dev, + uint32_t dev_config) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + return api->configure(dev, dev_config); +} + +/** + * @brief Get configuration of a SMBus host controller. + * + * This routine provides a way to get current configuration. It is allowed to + * call the function before smbus_configure, because some SMBus ports can be + * configured during init process. However, if the SMBus port is not configured, + * smbus_get_config returns an error. + * + * smbus_get_config can return cached config or probe hardware, but it has to be + * up to date with current configuration. + * + * @param dev Pointer to the device structure for the driver instance. + * @param dev_config Pointer to return bit-packed 32-bit value of + * the SMBus controller configuration. + * + * @retval 0 If successful. + * @retval -EIO General input / output error. + * @retval -ENOSYS If get config is not implemented + */ +__syscall int smbus_get_config(const struct device *dev, uint32_t *dev_config); + +static inline int z_impl_smbus_get_config(const struct device *dev, + uint32_t *dev_config) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->get_config == NULL) { + return -ENOSYS; + } + + return api->get_config(dev, dev_config); +} + +/** + * @brief Perform SMBus Quick operation + * + * This routine provides a generic interface to perform SMBus Quick + * operation. + * + * @param dev Pointer to the device structure for an SMBus + * driver configured in controller mode. + * @param addr Address of the SMBus peripheral device. + * @param direction Direction Read or Write. + * + * @retval 0 If successful. + * @retval -ENOSYS If not implemented by the driver. + * @retval -EIO General input / output error. + */ +__syscall int smbus_quick(const struct device *dev, uint16_t addr, + enum smbus_direction direction); + +static inline int z_impl_smbus_quick(const struct device *dev, uint16_t addr, + enum smbus_direction direction) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_quick == NULL) { + return -ENOSYS; + } + + if (direction != SMBUS_MSG_READ && direction != SMBUS_MSG_WRITE) { + return -EINVAL; + } + + return api->smbus_quick(dev, addr, direction); +} + +/** + * @brief Perform SMBus Byte Write operation + * + * This routine provides a generic interface to perform SMBus + * Byte Write operation. + * + * @param dev Pointer to the device structure for an SMBus + * driver configured in controller mode. + * @param addr Address of the SMBus peripheral device. + * @param byte Byte to be sent to the peripheral device. + * + * @retval 0 If successful. + * @retval -ENOSYS If not implemented by the driver. + * @retval -EIO General input / output error. + */ +__syscall int smbus_byte_write(const struct device *dev, uint16_t addr, + uint8_t byte); + +static inline int z_impl_smbus_byte_write(const struct device *dev, + uint16_t addr, uint8_t byte) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_byte_write == NULL) { + return -ENOSYS; + } + + return api->smbus_byte_write(dev, addr, byte); +} + +/** + * @brief Perform SMBus Byte Read operation + * + * This routine provides a generic interface to perform SMBus + * Byte Read operation. + * + * @param dev Pointer to the device structure for an SMBus + * driver configured in controller mode. + * @param addr Address of the SMBus peripheral device. + * @param byte Byte received from the peripheral device. + * + * @retval 0 If successful. + * @retval -ENOSYS If not implemented by the driver. + * @retval -EIO General input / output error. + */ +__syscall int smbus_byte_read(const struct device *dev, uint16_t addr, + uint8_t *byte); + +static inline int z_impl_smbus_byte_read(const struct device *dev, + uint16_t addr, uint8_t *byte) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_byte_read == NULL) { + return -ENOSYS; + } + + return api->smbus_byte_read(dev, addr, byte); +} + +/** + * @brief Perform SMBus Byte Data Write operation + * + * This routine provides a generic interface to perform SMBus + * Byte Data Write operation. + * + * @param dev Pointer to the device structure for an SMBus + * driver configured in controller mode. + * @param addr Address of the SMBus peripheral device. + * @param cmd Command byte which is sent to peripheral device first. + * @param byte Byte to be sent to the peripheral device. + * + * @retval 0 If successful. + * @retval -ENOSYS If not implemented by the driver. + * @retval -EIO General input / output error. + */ +__syscall int smbus_byte_data_write(const struct device *dev, uint16_t addr, + uint8_t cmd, uint8_t byte); + +static inline int z_impl_smbus_byte_data_write(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t byte) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_byte_data_write == NULL) { + return -ENOSYS; + } + + return api->smbus_byte_data_write(dev, addr, cmd, byte); +} + +__syscall int smbus_byte_data_read(const struct device *dev, uint16_t addr, + uint8_t cmd, uint8_t *byte); + +/** + * @brief Perform SMBus Byte Data Read operation + * + * This routine provides a generic interface to perform SMBus + * Byte Data Read operation. + * + * @param dev Pointer to the device structure for an SMBus + * driver configured in controller mode. + * @param addr Address of the SMBus peripheral device. + * @param cmd Command byte which is sent to peripheral device first. + * @param byte Byte received from the peripheral device. + * + * @retval 0 If successful. + * @retval -ENOSYS If not implemented by the driver. + * @retval -EIO General input / output error. + */ +static inline int z_impl_smbus_byte_data_read(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t *byte) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_byte_data_read == NULL) { + return -ENOSYS; + } + + return api->smbus_byte_data_read(dev, addr, cmd, byte); +} + +/** + * @brief Perform SMBus Word Data Write operation + * + * This routine provides a generic interface to perform SMBus + * Word Data Write operation. + * + * @param dev Pointer to the device structure for an SMBus + * driver configured in controller mode. + * @param addr Address of the SMBus peripheral device. + * @param cmd Command byte which is sent to peripheral device first. + * @param word Word (16-bit) to be sent to the peripheral device. + * + * @retval 0 If successful. + * @retval -ENOSYS If not implemented by the driver. + * @retval -EIO General input / output error. + */ +__syscall int smbus_word_data_write(const struct device *dev, uint16_t addr, + uint8_t cmd, uint16_t word); + +static inline int z_impl_smbus_word_data_write(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint16_t word) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_word_data_write == NULL) { + return -ENOSYS; + } + + return api->smbus_word_data_write(dev, addr, cmd, word); +} + +/** + * @brief Perform SMBus Word Data Read operation + * + * This routine provides a generic interface to perform SMBus + * Word Data Read operation. + * + * @param dev Pointer to the device structure for an SMBus + * driver configured in controller mode. + * @param addr Address of the SMBus peripheral device. + * @param cmd Command byte which is sent to peripheral device first. + * @param word Word (16-bit) received from the peripheral device. + * + * @retval 0 If successful. + * @retval -ENOSYS If not implemented by the driver. + * @retval -EIO General input / output error. + */ +__syscall int smbus_word_data_read(const struct device *dev, uint16_t addr, + uint8_t cmd, uint16_t *word); + +static inline int z_impl_smbus_word_data_read(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint16_t *word) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_word_data_read == NULL) { + return -ENOSYS; + } + + return api->smbus_word_data_read(dev, addr, cmd, word); +} + +/** + * @brief Perform SMBus Process Call operation + * + * This routine provides a generic interface to perform SMBus + * Process Call operation, which means Write 2 bytes following by + * Read 2 bytes. + * + * @param dev Pointer to the device structure for an SMBus + * driver configured in controller mode. + * @param addr Address of the SMBus peripheral device. + * @param cmd Command byte which is sent to peripheral device first. + * @param send_word Word (16-bit) to be sent to the peripheral device. + * @param recv_word Word (16-bit) received from the peripheral device. + * + * @retval 0 If successful. + * @retval -ENOSYS If not implemented by the driver. + * @retval -EIO General input / output error. + */ +__syscall int smbus_pcall(const struct device *dev, uint16_t addr, + uint8_t cmd, uint16_t send_word, uint16_t *recv_word); + +static inline int z_impl_smbus_pcall(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint16_t send_word, uint16_t *recv_word) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_pcall == NULL) { + return -ENOSYS; + } + + return api->smbus_pcall(dev, addr, cmd, send_word, recv_word); +} + +/** + * @brief Perform SMBus Block Write operation + * + * This routine provides a generic interface to perform SMBus + * Block Write operation. + * + * @param dev Pointer to the device structure for an SMBus + * driver configured in controller mode. + * @param addr Address of the SMBus peripheral device. + * @param cmd Command byte which is sent to peripheral device first. + * @param count Size of the data block buffer. Maximum 32 bytes. + * @param buf Data block buffer to be sent to the peripheral device. + * + * @retval 0 If successful. + * @retval -ENOSYS If not implemented by the driver. + * @retval -EIO General input / output error. + */ +__syscall int smbus_block_write(const struct device *dev, uint16_t addr, + uint8_t cmd, uint8_t count, uint8_t *buf); + +static inline int z_impl_smbus_block_write(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t count, uint8_t *buf) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_block_write == NULL) { + return -ENOSYS; + } + + if (count < 1 || count > SMBUS_BLOCK_BYTES_MAX) { + return -EINVAL; + } + + return api->smbus_block_write(dev, addr, cmd, count, buf); +} + +/** + * @brief Perform SMBus Block Read operation + * + * This routine provides a generic interface to perform SMBus + * Block Read operation. + * + * @param dev Pointer to the device structure for an SMBus + * driver configured in controller mode. + * @param addr Address of the SMBus peripheral device. + * @param cmd Command byte which is sent to peripheral device first. + * @param count Size of the data peripheral sent. Maximum 32 bytes. + * @param buf Data block buffer received from the peripheral device. + * + * @retval 0 If successful. + * @retval -ENOSYS If not implemented by the driver. + * @retval -EIO General input / output error. + */ +__syscall int smbus_block_read(const struct device *dev, uint16_t addr, + uint8_t cmd, uint8_t *count, uint8_t *buf); + +static inline int z_impl_smbus_block_read(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t *count, uint8_t *buf) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_block_read == NULL) { + return -ENOSYS; + } + + return api->smbus_block_read(dev, addr, cmd, count, buf); +} + +/** + * @brief Perform SMBus Block Process Call operation + * + * This routine provides a generic interface to perform SMBus + * Block Process Call operation. This operation is basically + * Block Write followed by Block Read. + * + * @param dev Pointer to the device structure for an SMBus + * driver configured in controller mode. + * @param addr Address of the SMBus peripheral device. + * @param cmd Command byte which is sent to peripheral device first. + * @param snd_count Size of the data block buffer to send. + * @param snd_buf Data block buffer send to the peripheral device. + * @param rcv_count Size of the data peripheral sent. + * @param rcv_buf Data block buffer received from the peripheral device. + * + * @retval 0 If successful. + * @retval -ENOSYS If not implemented by the driver. + * @retval -EIO General input / output error. + */ +__syscall int smbus_block_pcall(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t snd_count, uint8_t *snd_buf, + uint8_t *rcv_count, uint8_t *rcv_buf); + +static inline int z_impl_smbus_block_pcall(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t snd_count, uint8_t *snd_buf, + uint8_t *rcv_count, uint8_t *rcv_buf) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_block_pcall == NULL) { + return -ENOSYS; + } + + return api->smbus_block_pcall(dev, addr, cmd, snd_count, snd_buf, + rcv_count, rcv_buf); +} + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#include + +#endif /* ZEPHYR_INCLUDE_DRIVERS_SMBUS_H_ */ From 5fc55364a25f0f2615528b89f295647efa206e23 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Wed, 7 Sep 2022 16:36:24 +0300 Subject: [PATCH 0637/1906] smbus: shell: Add SMBus subsystem shell module Add SMBus shell module for testing. This allows arbitrary boards with SMBus driver supported exploring the SMBus communication with peripheral devices. Signed-off-by: Andrei Emeltchenko --- drivers/smbus/CMakeLists.txt | 1 + drivers/smbus/Kconfig | 7 + drivers/smbus/smbus_shell.c | 414 +++++++++++++++++++++++++++++++++++ 3 files changed, 422 insertions(+) create mode 100644 drivers/smbus/smbus_shell.c diff --git a/drivers/smbus/CMakeLists.txt b/drivers/smbus/CMakeLists.txt index a2d2e75e4899..b4e9718daf95 100644 --- a/drivers/smbus/CMakeLists.txt +++ b/drivers/smbus/CMakeLists.txt @@ -2,5 +2,6 @@ zephyr_library() +zephyr_library_sources_ifdef(CONFIG_SMBUS_SHELL smbus_shell.c) zephyr_library_sources_ifdef(CONFIG_USERSPACE smbus_handlers.c) diff --git a/drivers/smbus/Kconfig b/drivers/smbus/Kconfig index 808aa74845fb..5e7efa85fb95 100644 --- a/drivers/smbus/Kconfig +++ b/drivers/smbus/Kconfig @@ -10,6 +10,13 @@ menuconfig SMBUS if SMBUS +config SMBUS_SHELL + bool "SMBus Shell" + default y + depends on SHELL + help + Enable SMBus Shell. + config SMBUS_STATS bool "SMBus device Stats" depends on STATS diff --git a/drivers/smbus/smbus_shell.c b/drivers/smbus/smbus_shell.c new file mode 100644 index 000000000000..9ecbefa495b6 --- /dev/null +++ b/drivers/smbus/smbus_shell.c @@ -0,0 +1,414 @@ +/* + * Copyright (c) 2018 Prevas A/S + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +#include +LOG_MODULE_REGISTER(smbus_shell, CONFIG_LOG_DEFAULT_LEVEL); + +/** + * smbus_shell is a highly modified version from i2c_shell. Basically only scan + * logic remains from i2c_shell + */ + +/** + * Simplify argument parsing, smbus arguments always go in this order: + * smbus + */ +#define ARGV_DEV 1 +#define ARGV_ADDR 2 +#define ARGV_CMD 3 + +/** + * This sends SMBUS messages without any data (i.e. stop condition after + * sending just the address). If there is an ACK for the address, it + * is assumed there is a device present. + * + * WARNING: As there is no standard SMBUS detection command, this code + * uses arbitrary SMBus commands (namely SMBus quick write to probe for + * devices. + * This operation can confuse your SMBUS bus, cause data loss, and is + * known to corrupt the Atmel AT24RF08 EEPROM found on many IBM + * Thinkpad laptops. + * + * https://manpages.debian.org/buster/i2c-tools/i2cdetect.8.en.html + */ + +/* smbus scan */ +static int cmd_smbus_scan(const struct shell *sh, size_t argc, char **argv) +{ + const struct device *dev; + uint8_t cnt = 0, first = 0x04, last = 0x77; + + dev = device_get_binding(argv[ARGV_DEV]); + if (!dev) { + shell_error(sh, "SMBus: Device %s not found", argv[ARGV_DEV]); + return -ENODEV; + } + + shell_print(sh, " 0 1 2 3 4 5 6 7 8 9 a b c d e f"); + for (uint8_t i = 0; i <= last; i += 16) { + shell_fprintf(sh, SHELL_NORMAL, "%02x: ", i); + + for (uint8_t j = 0; j < 16; j++) { + if (i + j < first || i + j > last) { + shell_fprintf(sh, SHELL_NORMAL, " "); + continue; + } + + if (smbus_quick(dev, i + j, SMBUS_MSG_WRITE) == 0) { + shell_fprintf(sh, SHELL_NORMAL, "%02x ", i + j); + ++cnt; + } else { + shell_fprintf(sh, SHELL_NORMAL, "-- "); + } + } + + shell_print(sh, ""); + } + + shell_print(sh, "%u devices found on %s", cnt, argv[ARGV_DEV]); + + return 0; +} + +/* smbus quick */ +static int cmd_smbus_quick(const struct shell *sh, size_t argc, char **argv) +{ + const struct device *dev; + uint8_t addr; + int ret; + + dev = device_get_binding(argv[ARGV_DEV]); + if (!dev) { + shell_error(sh, "SMBus: Device %s not found", argv[ARGV_DEV]); + return -ENODEV; + } + + addr = strtol(argv[ARGV_ADDR], NULL, 16); + + ret = smbus_quick(dev, addr, SMBUS_MSG_WRITE); + if (ret < 0) { + shell_error(sh, "SMBus: Failed quick cmd, perip: 0x%02x", addr); + } + + return ret; +} + +/* smbus byte_read */ +static int cmd_smbus_byte_read(const struct shell *sh, size_t argc, char **argv) +{ + const struct device *dev; + uint8_t addr; + uint8_t out; + int ret; + + dev = device_get_binding(argv[ARGV_DEV]); + if (!dev) { + shell_error(sh, "SMBus: Device %s not found", argv[ARGV_DEV]); + return -ENODEV; + } + + addr = strtol(argv[ARGV_ADDR], NULL, 16); + + ret = smbus_byte_read(dev, addr, &out); + if (ret < 0) { + shell_error(sh, "SMBus: Failed to read from periph: 0x%02x", + addr); + return -EIO; + } + + shell_print(sh, "Output: 0x%x", out); + + return 0; +} + +/* smbus byte_write */ +static int cmd_smbus_byte_write(const struct shell *sh, + size_t argc, char **argv) +{ + const struct device *dev; + uint8_t addr; + uint8_t value; + int ret; + + dev = device_get_binding(argv[ARGV_DEV]); + if (!dev) { + shell_error(sh, "SMBus: Device %s not found", argv[ARGV_DEV]); + return -ENODEV; + } + + addr = strtol(argv[ARGV_ADDR], NULL, 16); + /* First byte is command */ + value = strtol(argv[ARGV_CMD], NULL, 16); + + ret = smbus_byte_write(dev, addr, value); + if (ret < 0) { + shell_error(sh, "SMBus: Failed to write to periph: 0x%02x", + addr); + return -EIO; + } + + return 0; +} + +/* smbus byte_data_read */ +static int cmd_smbus_byte_data_read(const struct shell *sh, + size_t argc, char **argv) +{ + const struct device *dev; + uint8_t addr, command; + uint8_t out; + int ret; + + dev = device_get_binding(argv[ARGV_DEV]); + if (!dev) { + shell_error(sh, "SMBus: Device %s not found", argv[ARGV_DEV]); + return -ENODEV; + } + + addr = strtol(argv[ARGV_ADDR], NULL, 16); + command = strtol(argv[ARGV_CMD], NULL, 16); + + ret = smbus_byte_data_read(dev, addr, command, &out); + if (ret < 0) { + shell_error(sh, "SMBus: Failed to read from periph: 0x%02x", + addr); + return -EIO; + } + + shell_print(sh, "Output: 0x%x", out); + + return 0; +} + +/* smbus byte_data_write */ +static int cmd_smbus_byte_data_write(const struct shell *sh, + size_t argc, char **argv) +{ + const struct device *dev; + uint8_t addr, command; + uint8_t value; + int ret; + + dev = device_get_binding(argv[ARGV_DEV]); + if (!dev) { + shell_error(sh, "SMBus: Device %s not found", argv[ARGV_DEV]); + return -ENODEV; + } + + addr = strtol(argv[ARGV_ADDR], NULL, 16); + command = strtol(argv[ARGV_CMD], NULL, 16); + value = strtol(argv[4], NULL, 16); + + ret = smbus_byte_data_write(dev, addr, command, value); + if (ret < 0) { + shell_error(sh, "SMBus: Failed to write to periph: 0x%02x", + addr); + return -EIO; + } + + return 0; +} + +/* smbus word_data_read */ +static int cmd_smbus_word_data_read(const struct shell *sh, + size_t argc, char **argv) +{ + const struct device *dev; + uint8_t addr, command; + uint16_t out; + int ret; + + dev = device_get_binding(argv[ARGV_DEV]); + if (!dev) { + shell_error(sh, "SMBus: Device %s not found", argv[ARGV_DEV]); + return -ENODEV; + } + + addr = strtol(argv[ARGV_ADDR], NULL, 16); + command = strtol(argv[ARGV_CMD], NULL, 16); + + ret = smbus_word_data_read(dev, addr, command, &out); + if (ret < 0) { + shell_error(sh, "SMBus: Failed to read from periph: 0x%02x", + addr); + return -EIO; + } + + shell_print(sh, "Output: 0x%04x", out); + + return 0; +} + +/* smbus word_data_write */ +static int cmd_smbus_word_data_write(const struct shell *sh, + size_t argc, char **argv) +{ + const struct device *dev; + uint8_t addr, command; + uint16_t value; + int ret; + + dev = device_get_binding(argv[ARGV_DEV]); + if (!dev) { + shell_error(sh, "SMBus: Device %s not found", argv[ARGV_DEV]); + return -ENODEV; + } + + addr = strtol(argv[ARGV_ADDR], NULL, 16); + command = strtol(argv[ARGV_CMD], NULL, 16); + value = strtol(argv[4], NULL, 16); + + ret = smbus_word_data_write(dev, addr, command, value); + if (ret < 0) { + shell_error(sh, "SMBus: Failed to write to periph: 0x%02x", + addr); + return -EIO; + } + + return 0; +} + +/* smbus block_write */ +static int cmd_smbus_block_write(const struct shell *sh, + size_t argc, char **argv) +{ + const struct device *dev; + uint8_t addr, command; + uint8_t count = argc - 4; + char **p = &argv[4]; /* start data bytes */ + uint8_t buf[32]; /* max block count */ + int ret; + + if (count == 0 || count > sizeof(buf)) { + return -EINVAL; + } + + dev = device_get_binding(argv[ARGV_DEV]); + if (!dev) { + shell_error(sh, "SMBus: Device %s not found", argv[ARGV_DEV]); + return -ENODEV; + } + + addr = strtol(argv[ARGV_ADDR], NULL, 16); + command = strtol(argv[ARGV_CMD], NULL, 16); + + for (int i = 0; i < count; i++) { + buf[i] = (uint8_t)strtoul(p[i], NULL, 16); + } + + LOG_HEXDUMP_DBG(buf, count, "Constructed block buffer"); + + ret = smbus_block_write(dev, addr, command, count, buf); + if (ret < 0) { + shell_error(sh, "Failed block write to periph: 0x%02x", + addr); + return ret; + } + + return 0; +} + +/* smbus block_read */ +static int cmd_smbus_block_read(const struct shell *sh, + size_t argc, char **argv) +{ + const struct device *dev; + uint8_t addr, command; + uint8_t buf[32]; /* max block count */ + uint8_t count; + int ret; + + dev = device_get_binding(argv[ARGV_DEV]); + if (!dev) { + shell_error(sh, "SMBus: Device %s not found", argv[ARGV_DEV]); + return -ENODEV; + } + + addr = strtol(argv[ARGV_ADDR], NULL, 16); + command = strtol(argv[ARGV_CMD], NULL, 16); + + ret = smbus_block_read(dev, addr, command, &count, buf); + if (ret < 0) { + shell_error(sh, "Failed block read from periph: 0x%02x", + addr); + return ret; + } + + if (count == 0 || count > sizeof(buf)) { + shell_error(sh, "Returned count %u", count); + return -ENODATA; + } + + shell_hexdump(sh, buf, count); + + return 0; +} + +/* Device name autocompletion support */ +static void device_name_get(size_t idx, struct shell_static_entry *entry) +{ + const struct device *dev = shell_device_lookup(idx, "smbus"); + + entry->syntax = (dev != NULL) ? dev->name : NULL; + entry->handler = NULL; + entry->help = NULL; + entry->subcmd = NULL; +} + +SHELL_DYNAMIC_CMD_CREATE(dsub_device_name, device_name_get); + +SHELL_STATIC_SUBCMD_SET_CREATE(sub_smbus_cmds, + SHELL_CMD_ARG(quick, &dsub_device_name, + "SMBus Quick command\n" + "Usage: quick ", + cmd_smbus_quick, 3, 0), + SHELL_CMD_ARG(scan, &dsub_device_name, + "Scan SMBus peripheral devices command\n" + "Usage: scan ", + cmd_smbus_scan, 2, 0), + SHELL_CMD_ARG(byte_read, &dsub_device_name, + "SMBus: byte read command\n" + "Usage: byte_read ", + cmd_smbus_byte_read, 3, 0), + SHELL_CMD_ARG(byte_write, &dsub_device_name, + "SMBus: byte write command\n" + "Usage: byte_write ", + cmd_smbus_byte_write, 4, 0), + SHELL_CMD_ARG(byte_data_read, &dsub_device_name, + "SMBus: byte data read command\n" + "Usage: byte_data_read ", + cmd_smbus_byte_data_read, 4, 0), + SHELL_CMD_ARG(byte_data_write, &dsub_device_name, + "SMBus: byte data write command\n" + "Usage: byte_data_write ", + cmd_smbus_byte_data_write, 5, 0), + SHELL_CMD_ARG(word_data_read, &dsub_device_name, + "SMBus: word data read command\n" + "Usage: word_data_read ", + cmd_smbus_word_data_read, 4, 0), + SHELL_CMD_ARG(word_data_write, &dsub_device_name, + "SMBus: word data write command\n" + "Usage: word_data_write ", + cmd_smbus_word_data_write, 5, 0), + SHELL_CMD_ARG(block_write, &dsub_device_name, + "SMBus: Block Write command\n" + "Usage: block_write [, ...]", + cmd_smbus_block_write, 4, 32), + SHELL_CMD_ARG(block_read, &dsub_device_name, + "SMBus: Block Read command\n" + "Usage: block_read ", + cmd_smbus_block_read, 4, 0), + SHELL_SUBCMD_SET_END /* Array terminated. */ +); + +SHELL_CMD_REGISTER(smbus, &sub_smbus_cmds, "smbus commands", NULL); From 90e6bf8e9ff90831538401f41c762b616b6ef69d Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Thu, 29 Sep 2022 17:43:22 +0300 Subject: [PATCH 0638/1906] smbus: doc: Add Documentation for SMBus subsystem API Add some basic documentation and API reference for SMBus. Signed-off-by: Andrei Emeltchenko --- doc/develop/api/overview.rst | 4 ++ doc/hardware/peripherals/index.rst | 1 + doc/hardware/peripherals/smbus.rst | 64 ++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 doc/hardware/peripherals/smbus.rst diff --git a/doc/develop/api/overview.rst b/doc/develop/api/overview.rst index 7cdf1b6bdde2..d2bc12aef48c 100644 --- a/doc/develop/api/overview.rst +++ b/doc/develop/api/overview.rst @@ -249,6 +249,10 @@ between major releases are available in the :ref:`zephyr_release_notes`. - Experimental - 3.2 + * - :ref:`smbus_api` + - Experimental + - 3.4 + * - :ref:`spi_api` - Stable - 1.0 diff --git a/doc/hardware/peripherals/index.rst b/doc/hardware/peripherals/index.rst index 136044246a88..5f67a85c0ce2 100644 --- a/doc/hardware/peripherals/index.rst +++ b/doc/hardware/peripherals/index.rst @@ -26,6 +26,7 @@ Peripherals i2c_eeprom_target.rst i2c.rst i3c.rst + smbus.rst ipm.rst kscan.rst led.rst diff --git a/doc/hardware/peripherals/smbus.rst b/doc/hardware/peripherals/smbus.rst new file mode 100644 index 000000000000..3169da3b64c2 --- /dev/null +++ b/doc/hardware/peripherals/smbus.rst @@ -0,0 +1,64 @@ +.. _smbus_api: + +SMBus +##### + +.. contents:: + :local: + :depth: 2 + +Overview +******** + +System Management Bus (SMBus) is derived from I2C for communication +with devices on the motherboard. A system may use SMBus to communicate +with the peripherals on the motherboard without using dedicated control +lines. With SMBus peripheral can provide various manufacturer information, +report errors, accept control parameters, etc. + +Devices on the bus can operate in three roles: as a "controller" that +initiates transactions and controls the clock, a "peripheral" that +responds to transaction commands, or a "host", which is a specialized +controller, that provides the main interface to the system's CPU. +Zephyr has API for "controller" role. + +In SMBus peripheral devices can initiate communication with Controller +with two methods: + +* **Host Notify protocol**: Peripheral device that supports Host Notify + protocol behaive as a Controller to perform the notification. It writes + three-bytes message to a special address "SMBus Host (0x08)" with own + address and two bytes of relevant data. +* **SMBALERT# signal**: Peripheral device uses special signal SMBALERT# to + to request attention from the Controller. Controller needs to read one byte + from the special "SMBus Alert Response Address (ARA) (0x0c)". The peripheral + device responds with data byte containing own address. + +Currently, the API is based on `SMBus Specification`_ version 2.0 + +.. note:: + See :ref:`coding_guideline_inclusive_language` for information about + the terminology used in this API. + +.. _smbus-controller-api: + +SMBus Controller API +******************** + +Zephyr's SMBus controller API is used when an SMBus device controls the bus, +in particularly the start and stop conditions and the clock. This is +the most common mode, used to interact with SMbus peripherals. + +Configuration Options +********************* + +Related configuration options: + +* :kconfig:option:`CONFIG_SMBUS` + +API Reference +************* + +.. doxygengroup:: smbus_interface + +.. _SMBus Specification: http://smbus.org/specs/smbus20.pdf From af984aa58b8fc49f6da83b5e4f52affaaa9bddbf Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Wed, 14 Sep 2022 11:31:49 +0300 Subject: [PATCH 0639/1906] drivers: smbus: Add Intel PCH driver register header Add header file for Intel PCH SMBus driver. Signed-off-by: Andrei Emeltchenko --- drivers/smbus/intel_pch_smbus.h | 148 ++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 drivers/smbus/intel_pch_smbus.h diff --git a/drivers/smbus/intel_pch_smbus.h b/drivers/smbus/intel_pch_smbus.h new file mode 100644 index 000000000000..38007c6e4e6f --- /dev/null +++ b/drivers/smbus/intel_pch_smbus.h @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * Intel I/O Controller Hub (ICH) later renamed to Intel Platform Controller + * Hub (PCH) SMbus driver. + * + * PCH provides SMBus 2.0 - compliant Host Controller. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_DRIVERS_SMBUS_PCH_H_ +#define ZEPHYR_DRIVERS_SMBUS_PCH_H_ + +/* PCI Configuration Space registers */ + +/* Host Configuration (HCFG) - Offset 40h, 8 bits */ +#define PCH_SMBUS_HCFG 0x10 +#define PCH_SMBUS_HCFG_HST_EN BIT(0) /* Enable SMBus controller */ + +/* PCH SMBus I/O and Memory Mapped registers */ + +/* Host Status Register Address (HSTS) */ +#define PCH_SMBUS_HSTS 0x00 +#define PCH_SMBUS_HSTS_HOST_BUSY BIT(0) /* Host Busy */ +#define PCH_SMBUS_HSTS_INTERRUPT BIT(1) /* Interrupt */ +#define PCH_SMBUS_HSTS_DEV_ERROR BIT(2) /* Device Error */ +#define PCH_SMBUS_HSTS_BUS_ERROR BIT(3) /* Bus Error */ +#define PCH_SMBUS_HSTS_FAILED BIT(4) /* Failed */ +#define PCH_SMBUS_HSTS_SMB_ALERT BIT(5) /* SMB Alert */ +#define PCH_SMBUS_HSTS_INUSE BIT(6) /* In Use */ +#define PCH_SMBUS_HSTS_BYTE_DONE BIT(7) /* Byte Done */ + +#define PCH_SMBUS_HSTS_ERROR (PCH_SMBUS_HSTS_DEV_ERROR | \ + PCH_SMBUS_HSTS_BUS_ERROR | \ + PCH_SMBUS_HSTS_FAILED) + +/* Host Control Register (HCTL) */ +#define PCH_SMBUS_HCTL 0x02 /* Host Control */ +#define PCH_SMBUS_HCTL_INTR_EN BIT(0) /* INT Enable */ +#define PCH_SMBUS_HCTL_KILL BIT(1) /* Kill current trans */ +#define PCH_SMBUS_HCTL_CMD GENMASK(4, 2) /* Command */ +/* SMBUS Commands */ +#define PCH_SMBUS_HCTL_CMD_QUICK (0 << 2) /* Quick cmd*/ +#define PCH_SMBUS_HCTL_CMD_BYTE (1 << 2) /* Byte cmd */ +#define PCH_SMBUS_HCTL_CMD_BYTE_DATA (2 << 2) /* Byte Data cmd */ +#define PCH_SMBUS_HCTL_CMD_WORD_DATA (3 << 2) /* Word Data cmd */ +#define PCH_SMBUS_HCTL_CMD_PROC_CALL (4 << 2) /* Process Call cmd */ +#define PCH_SMBUS_HCTL_CMD_BLOCK (5 << 2) /* Block cmd */ +#define PCH_SMBUS_HCTL_CMD_I2C_READ (6 << 2) /* I2C Read cmd */ +#define PCH_SMBUS_HCTL_CMD_BLOCK_PROC (7 << 2) /* Block Process cmd */ + +#define PCH_SMBUS_HCTL_CMD_SET(cmd) (cmd << 2) + +#define PCH_SMBUS_HCTL_CMD_GET(val) (val & PCH_SMBUS_HCTL_CMD) + +#define PCH_SMBUS_HCTL_LAST_BYTE BIT(5) /* Last byte block op */ +#define PCH_SMBUS_HCTL_START BIT(6) /* Start SMBUS cmd */ +#define PCH_SMBUS_HCTL_PEC_EN BIT(7) /* Enable PEC */ + +/* Host Command Register (HCMD) */ +#define PCH_SMBUS_HCMD 0x03 + +/* Transmit Slave Address Register (TSA) */ +#define PCH_SMBUS_TSA 0x04 +#define PCH_SMBUS_TSA_RW BIT(0) /* Direction */ +#define PCH_SMBUS_TSA_ADDR_MASK GENMASK(7, 1) /* Address mask */ + +/* Set 7-bit address */ +#define PCH_SMBUS_TSA_ADDR_SET(addr) (((addr) & BIT_MASK(7)) << 1) + +/* Get Peripheral address from register value */ +#define PCH_SMBUS_TSA_ADDR_GET(reg) ((reg >> 1) & BIT_MASK(7)) + +/* Data 0 Register (HD0) */ +#define PCH_SMBUS_HD0 0x05 /* Data 0 / Count */ + +/* Data 1 Register (HD1) */ +#define PCH_SMBUS_HD1 0x06 /* Data 1 */ + +/* Host Block Data (HBD) */ +#define PCH_SMBUS_HBD 0x07 /* Host block data */ + +/* Packet Error Check Data Register (PEC) */ +#define PCH_SMBUS_PEC 0x08 /* PEC data */ + +/* Receive Slave Address Register (RSA) */ +#define PCH_SMBUS_RSA 0x09 /* Receive slave addr */ + +/* Slave Data Register (SD) (16 bits) */ +#define PCH_SMBUS_SD 0x0a /* Slave data */ + +/* Auxiliary Status (AUXS) */ +#define PCH_SMBUS_AUXS 0x0c /* Auxiliary Status */ +#define PCH_SMBUS_AUXS_CRC_ERROR BIT(0) /* CRC error */ + +/* Auxiliary Control (AUXC) */ +#define PCH_SMBUS_AUXC 0x0d /* Auxiliary Control */ +#define PCH_SMBUS_AUXC_AAC BIT(0) /* Auto append CRC */ +#define PCH_SMBUS_AUXC_EN_32BUF BIT(1) /* Enable 32-byte buf */ + +/* SMLink Pin Control Register (SMLC) */ +#define PCH_SMBUS_SMLC 0x0e /* SMLink pin control */ + +/* SMBus Pin control Register (SMBC) */ +#define PCH_SMBUS_SMBC 0x0f /* SMBus pin control */ +#define PCH_SMBUS_SMBC_CLK_CUR_STS BIT(0) /* SMBCLK pin status */ +#define PCH_SMBUS_SMBC_DATA_CUR_STS BIT(1) /* SMBDATA pin status */ +#define PCH_SMBUS_SMBC_CLK_CTL BIT(2) /* SMBCLK pin CTL */ + +/* Slave Status Register (SSTS) */ +#define PCH_SMBUS_SSTS 0x10 /* Slave Status */ +#define PCH_SMBUS_SSTS_HNS BIT(0) /* Host Notify Status */ + +/* Slave Command Register (SCMD) */ +#define PCH_SMBUS_SCMD 0x11 /* Slave Command */ +#define PCH_SMBUS_SCMD_HNI_EN BIT(0) /* Host Notify INT En */ +#define PCH_SMBUS_SCMD_HNW_EN BIT(1) /* Host Notify Wake */ +#define PCH_SMBUS_SCMD_SMBALERT_DIS BIT(2) /* Disable Smbalert */ + +/* Notify Device Address Register (NDA) */ +#define PCH_SMBUS_NDA 0x14 /* Notify Device addr */ + +/* Notify Data Low Byte Register (NDLB) */ +#define PCH_SMBUS_NDLB 0x16 /* Notify Data low */ + +/* Notify Data High Byte Register (NDHB) */ +#define PCH_SMBUS_NDHB 0x17 /* Notify Data high */ + +/* Debug helpers */ + +#if CONFIG_SMBUS_LOG_LEVEL >= LOG_LEVEL_DBG +/* Dump HSTS register using define to show calling function */ +#define pch_dump_register_hsts(reg) \ + LOG_DBG("HSTS: 0x%02x: %s%s%s%s%s%s%s%s", reg, \ + reg & PCH_SMBUS_HSTS_HOST_BUSY ? "[Host Busy] " : "", \ + reg & PCH_SMBUS_HSTS_INTERRUPT ? "[Interrupt] " : "", \ + reg & PCH_SMBUS_HSTS_DEV_ERROR ? "[Device Error] " : "",\ + reg & PCH_SMBUS_HSTS_BUS_ERROR ? "[Bus Error] " : "", \ + reg & PCH_SMBUS_HSTS_FAILED ? "[Failed] " : "", \ + reg & PCH_SMBUS_HSTS_SMB_ALERT ? "[SMBALERT] " : "", \ + reg & PCH_SMBUS_HSTS_BYTE_DONE ? "[Byte Done] " : "", \ + reg & PCH_SMBUS_HSTS_INUSE ? "[In USE] " : ""); +#else +#define pch_dump_register_hsts(reg) +#endif + +#endif /* ZEPHYR_DRIVERS_SMBUS_PCH_H_ */ From 4099bc2e63dbf687923028d10e6d966e8fe313d3 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Thu, 8 Sep 2022 16:51:10 +0300 Subject: [PATCH 0640/1906] drivers: smbus: Add Intel ICH / PCH SMbus driver Add driver supporting Intel I/O Controller Hub (ICH), later renamed to Intel Platform Controller Hub (PCH). Signed-off-by: Andrei Emeltchenko --- drivers/smbus/CMakeLists.txt | 1 + drivers/smbus/Kconfig | 30 ++ drivers/smbus/intel_pch_smbus.c | 817 ++++++++++++++++++++++++++++++++ 3 files changed, 848 insertions(+) create mode 100644 drivers/smbus/intel_pch_smbus.c diff --git a/drivers/smbus/CMakeLists.txt b/drivers/smbus/CMakeLists.txt index b4e9718daf95..e7c76704d2bc 100644 --- a/drivers/smbus/CMakeLists.txt +++ b/drivers/smbus/CMakeLists.txt @@ -3,5 +3,6 @@ zephyr_library() zephyr_library_sources_ifdef(CONFIG_SMBUS_SHELL smbus_shell.c) +zephyr_library_sources_ifdef(CONFIG_SMBUS_INTEL_PCH intel_pch_smbus.c) zephyr_library_sources_ifdef(CONFIG_USERSPACE smbus_handlers.c) diff --git a/drivers/smbus/Kconfig b/drivers/smbus/Kconfig index 5e7efa85fb95..561062c6e972 100644 --- a/drivers/smbus/Kconfig +++ b/drivers/smbus/Kconfig @@ -34,4 +34,34 @@ module = SMBUS module-str = smbus source "subsys/logging/Kconfig.template.log_config" +config SMBUS_INTEL_PCH + bool "SMBus Intel PCH driver" + default y + depends on DT_HAS_INTEL_PCH_SMBUS_ENABLED + help + Enable Intel Platform Controller Hub (PCH) SMBus driver. + +if SMBUS_INTEL_PCH + +choice SMBUS_INTEL_PCH_ACCESS + bool "SMBus register access mode" + default SMBUS_INTEL_PCH_ACCESS_IO + help + Default PCH register access mode. Set default access IO so + that both Qemu Q35 and Intel hardware are supported. + +config SMBUS_INTEL_PCH_ACCESS_IO + bool "I/O PCH SMBus Register Access Mode" + help + Access PCH SMBus registers through I/O space. + +config SMBUS_INTEL_PCH_ACCESS_MMIO + bool "MMIO PCH SMBus Register Access Mode" + help + Access PCH SMBus registers though MMIO space. + +endchoice + +endif # SMBUS_INTEL_PCH + endif # SMBUS diff --git a/drivers/smbus/intel_pch_smbus.c b/drivers/smbus/intel_pch_smbus.c new file mode 100644 index 000000000000..35d146db8b99 --- /dev/null +++ b/drivers/smbus/intel_pch_smbus.c @@ -0,0 +1,817 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * Intel I/O Controller Hub (ICH) later renamed to Intel Platform Controller + * Hub (PCH) SMbus driver. + * + * PCH provides SMBus 2.0 - compliant Host Controller. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include + +#define DT_DRV_COMPAT intel_pch_smbus + +#include +LOG_MODULE_REGISTER(intel_pch, CONFIG_SMBUS_LOG_LEVEL); + +#include "intel_pch_smbus.h" + +/** + * @note Following notions are used: + * * periph_addr - Peripheral address (Slave address mentioned in the Specs) + * * command - First byte to send in the SMBus protocol operations except for + * Quick and Byte Read. Also known as register. + */ + +/** + * Intel PCH configuration acquired from DTS during device initialization + */ +struct pch_config { + /* IRQ configuration function */ + void (*config_func)(const struct device *dev); + /* PCIE BDF got from DTS */ + pcie_bdf_t pcie_bdf; + /* PCIE ID got from DTS */ + pcie_id_t pcie_id; +}; + +/** + * Intel PCH internal driver data + */ +struct pch_data { + DEVICE_MMIO_RAM; + io_port_t sba; + uint32_t config; + uint8_t status; + + struct k_mutex mutex; + struct k_sem completion_sync; +}; + +/** + * Helpers for accessing Intel PCH SMBus registers. Depending on + * configuration option MMIO or IO method will be used. + */ +#if defined(CONFIG_SMBUS_INTEL_PCH_ACCESS_MMIO) +static uint8_t pch_reg_read(const struct device *dev, uint8_t reg) +{ + return sys_read8(DEVICE_MMIO_GET(dev) + reg); +} + +static void pch_reg_write(const struct device *dev, uint8_t reg, uint8_t val) +{ + sys_write8(val, DEVICE_MMIO_GET(dev) + reg); +} +#elif defined(CONFIG_SMBUS_INTEL_PCH_ACCESS_IO) +static uint8_t pch_reg_read(const struct device *dev, uint8_t reg) +{ + struct pch_data *data = dev->data; + + return sys_in8(data->sba + reg); +} + +static void pch_reg_write(const struct device *dev, uint8_t reg, uint8_t val) +{ + struct pch_data *data = dev->data; + + sys_out8(val, data->sba + reg); +} +#else +#error Wrong PCH Register Access Mode +#endif + +static int pch_configure(const struct device *dev, uint32_t config) +{ + struct pch_data *data = dev->data; + + LOG_DBG("dev %p config 0x%x", dev, config); + + /* Keep config for a moment */ + data->config = config; + + return 0; +} + +static int pch_get_config(const struct device *dev, uint32_t *config) +{ + struct pch_data *data = dev->data; + + *config = data->config; + + return 0; +} + +/* Device initialization function */ +static int pch_smbus_init(const struct device *dev) +{ + const struct pch_config * const config = dev->config; + struct pch_data *data = dev->data; + struct pcie_bar mbar; + uint32_t val; + + if (!pcie_probe(config->pcie_bdf, config->pcie_id)) { + LOG_ERR("Cannot probe PCI device"); + return -ENODEV; + } + + val = pcie_conf_read(config->pcie_bdf, PCIE_CONF_CMDSTAT); + if (val & PCIE_CONF_CMDSTAT_INTERRUPT) { + LOG_WRN("Pending interrupt, continuing"); + } + + if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_ACCESS_MMIO)) { + pcie_probe_mbar(config->pcie_bdf, 0, &mbar); + pcie_set_cmd(config->pcie_bdf, PCIE_CONF_CMDSTAT_MEM, true); + + device_map(DEVICE_MMIO_RAM_PTR(dev), mbar.phys_addr, mbar.size, + K_MEM_CACHE_NONE); + + LOG_DBG("Mapped 0x%lx size 0x%lx to 0x%lx", + mbar.phys_addr, mbar.size, DEVICE_MMIO_GET(dev)); + } else { + pcie_set_cmd(config->pcie_bdf, PCIE_CONF_CMDSTAT_IO, true); + val = pcie_conf_read(config->pcie_bdf, PCIE_CONF_BAR4); + if (!PCIE_CONF_BAR_IO(val)) { + LOG_ERR("Cannot read IO BAR"); + return -EINVAL; + } + + data->sba = PCIE_CONF_BAR_ADDR(val); + + LOG_DBG("Using I/O address 0x%x", data->sba); + } + + val = pcie_conf_read(config->pcie_bdf, PCH_SMBUS_HCFG); + if ((val & PCH_SMBUS_HCFG_HST_EN) == 0) { + LOG_ERR("SMBus Host Controller is disabled"); + return -EINVAL; + } + + /* Initialize mutex and semaphore */ + k_mutex_init(&data->mutex); + k_sem_init(&data->completion_sync, 0, 1); + + config->config_func(dev); + + if (pch_configure(dev, SMBUS_MODE_CONTROLLER)) { + LOG_ERR("SMBus: Cannot set default configuration"); + return -EIO; + } + + return 0; +} + +static int pch_prepare_transfer(const struct device *dev) +{ + uint8_t hsts; + + hsts = pch_reg_read(dev, PCH_SMBUS_HSTS); + + pch_dump_register_hsts(hsts); + + if (hsts & PCH_SMBUS_HSTS_HOST_BUSY) { + LOG_ERR("Return BUSY status"); + return -EBUSY; + } + + /* Check and clear HSTS status bits */ + hsts &= PCH_SMBUS_HSTS_ERROR | PCH_SMBUS_HSTS_BYTE_DONE | + PCH_SMBUS_HSTS_INTERRUPT; + if (hsts) { + pch_reg_write(dev, PCH_SMBUS_HSTS, hsts); + } + + /* TODO: Clear also CRC check bits */ + + return 0; +} + +static int pch_check_status(const struct device *dev) +{ + struct pch_data *data = dev->data; + uint8_t status = data->status; + + /** + * Device Error means following: + * - unsupported Command Field Unclaimed Cycle + * - Host Device timeout + * - CRC Error + */ + if (status & PCH_SMBUS_HSTS_DEV_ERROR) { + uint8_t auxs = pch_reg_read(dev, PCH_SMBUS_AUXS); + + LOG_WRN("Device Error (DERR) received"); + + if (auxs & PCH_SMBUS_AUXS_CRC_ERROR) { + LOG_DBG("AUXS register 0x%02x", auxs); + /* Clear CRC error status bit */ + pch_reg_write(dev, PCH_SMBUS_AUXS, + PCH_SMBUS_AUXS_CRC_ERROR); + } + + return -EIO; + } + + /** + * Transaction collision, several masters are trying to access + * the bus and PCH detects arbitration lost. + */ + if (status & PCH_SMBUS_HSTS_BUS_ERROR) { + LOG_WRN("Bus Error (BERR) received"); + + return -EAGAIN; + } + + /** + * Source of interrupt is failed bus transaction. This is set in + * response to KILL set to terminate the host transaction + */ + if (status & PCH_SMBUS_HSTS_FAILED) { + LOG_WRN("Failed (FAIL) received"); + + return -EIO; + } + + return 0; +} + +static int pch_smbus_block_start(const struct device *dev, uint16_t periph_addr, + uint8_t rw, uint8_t command, uint8_t count, + uint8_t *buf, uint8_t protocol) +{ + uint8_t reg; + int ret; + + LOG_DBG("addr %x rw %d command %x", periph_addr, rw, command); + + /* Set TSA register */ + reg = PCH_SMBUS_TSA_ADDR_SET(periph_addr); + reg |= rw & SMBUS_MSG_RW_MASK; + pch_reg_write(dev, PCH_SMBUS_TSA, reg); + + /* Set HCMD register */ + pch_reg_write(dev, PCH_SMBUS_HCMD, command); + + /* Enable 32-byte buffer mode (E32b) to send block of data */ + reg = pch_reg_read(dev, PCH_SMBUS_AUXC); + reg |= PCH_SMBUS_AUXC_EN_32BUF; + pch_reg_write(dev, PCH_SMBUS_AUXC, reg); + + /* In E32B mode read and write to PCH_SMBUS_HBD translates to + * read and write to 32 byte storage array, index needs to be + * cleared by reading HCTL + */ + reg = pch_reg_read(dev, PCH_SMBUS_HCTL); + ARG_UNUSED(reg); /* Avoid 'Dead assignment' warning */ + + if (rw == SMBUS_MSG_WRITE) { + /* Write count */ + pch_reg_write(dev, PCH_SMBUS_HD0, count); + + /* Write data to send */ + for (int i = 0; i < count; i++) { + pch_reg_write(dev, PCH_SMBUS_HBD, buf[i]); + } + } + + ret = pch_prepare_transfer(dev); + if (ret < 0) { + return ret; + } + + /* Set HCTL register */ + reg = PCH_SMBUS_HCTL_CMD_SET(protocol); + reg |= PCH_SMBUS_HCTL_START; + reg |= PCH_SMBUS_HCTL_INTR_EN; + pch_reg_write(dev, PCH_SMBUS_HCTL, reg); + + return 0; +} + +/* Start PCH SMBus operation */ +static int pch_smbus_start(const struct device *dev, uint16_t periph_addr, + enum smbus_direction rw, uint8_t command, + uint8_t *buf, uint8_t protocol) +{ + uint8_t reg; + int ret; + + LOG_DBG("addr %x rw %d command %x", periph_addr, rw, command); + + /* Set TSA register */ + reg = PCH_SMBUS_TSA_ADDR_SET(periph_addr); + reg |= rw & SMBUS_MSG_RW_MASK; + pch_reg_write(dev, PCH_SMBUS_TSA, reg); + + /* Write command for every but QUICK op */ + if (protocol != SMBUS_CMD_QUICK) { + /* Set HCMD register */ + pch_reg_write(dev, PCH_SMBUS_HCMD, command); + + /* Set Host Data 0 (HD0) register */ + if (rw == SMBUS_MSG_WRITE && protocol != SMBUS_CMD_BYTE) { + pch_reg_write(dev, PCH_SMBUS_HD0, buf[0]); + + /* If we need to write second byte */ + if (protocol == SMBUS_CMD_WORD_DATA || + protocol == SMBUS_CMD_PROC_CALL) { + pch_reg_write(dev, PCH_SMBUS_HD1, buf[1]); + } + } + } + + ret = pch_prepare_transfer(dev); + if (ret < 0) { + return ret; + } + + /* Set HCTL register */ + reg = PCH_SMBUS_HCTL_CMD_SET(protocol); + reg |= PCH_SMBUS_HCTL_START; + reg |= PCH_SMBUS_HCTL_INTR_EN; + pch_reg_write(dev, PCH_SMBUS_HCTL, reg); + + return 0; +} + +/* Implementation of PCH SMBus API */ + +/* Implementation of SMBus Quick */ +static int pch_smbus_quick(const struct device *dev, uint16_t periph_addr, + enum smbus_direction rw) +{ + struct pch_data *data = dev->data; + int ret; + + LOG_DBG("dev %p addr 0x%02x direction %x", dev, periph_addr, rw); + + k_mutex_lock(&data->mutex, K_FOREVER); + + ret = pch_smbus_start(dev, periph_addr, rw, 0, NULL, SMBUS_CMD_QUICK); + if (ret < 0) { + goto unlock; + } + + /* Wait for completion from ISR */ + ret = k_sem_take(&data->completion_sync, K_MSEC(30)); + if (ret != 0) { + LOG_ERR("SMBus Quick timed out"); + ret = -ETIMEDOUT; + goto unlock; + } + + ret = pch_check_status(dev); + +unlock: + k_mutex_unlock(&data->mutex); + + return ret; +} + +/* Implementation of SMBus Byte Write */ +static int pch_smbus_byte_write(const struct device *dev, uint16_t periph_addr, + uint8_t command) +{ + struct pch_data *data = dev->data; + int ret; + + LOG_DBG("dev %p addr 0x%02x command 0x%02x", dev, periph_addr, command); + + k_mutex_lock(&data->mutex, K_FOREVER); + + ret = pch_smbus_start(dev, periph_addr, SMBUS_MSG_WRITE, command, NULL, + SMBUS_CMD_BYTE); + if (ret < 0) { + goto unlock; + } + + /* Wait for completion from ISR */ + ret = k_sem_take(&data->completion_sync, K_MSEC(30)); + if (ret != 0) { + LOG_ERR("SMBus Byte Write timed out"); + ret = -ETIMEDOUT; + goto unlock; + } + + ret = pch_check_status(dev); + +unlock: + k_mutex_unlock(&data->mutex); + + return ret; +} + +/* Implementation of SMBus Byte Read */ +static int pch_smbus_byte_read(const struct device *dev, uint16_t periph_addr, + uint8_t *byte) +{ + struct pch_data *data = dev->data; + int ret; + + LOG_DBG("dev %p addr 0x%02x", dev, periph_addr); + + k_mutex_lock(&data->mutex, K_FOREVER); + + ret = pch_smbus_start(dev, periph_addr, SMBUS_MSG_READ, 0, NULL, + SMBUS_CMD_BYTE); + if (ret < 0) { + goto unlock; + } + + /* Wait for completion from ISR */ + ret = k_sem_take(&data->completion_sync, K_MSEC(30)); + if (ret != 0) { + LOG_ERR("SMBus Byte Read timed out"); + ret = -ETIMEDOUT; + goto unlock; + } + + ret = pch_check_status(dev); + if (ret < 0) { + goto unlock; + } + + *byte = pch_reg_read(dev, PCH_SMBUS_HD0); + +unlock: + k_mutex_unlock(&data->mutex); + + return ret; +} + +/* Implementation of SMBus Byte Data Write */ +static int pch_smbus_byte_data_write(const struct device *dev, + uint16_t periph_addr, + uint8_t command, uint8_t byte) +{ + struct pch_data *data = dev->data; + int ret; + + LOG_DBG("dev %p addr 0x%02x command 0x%02x", dev, periph_addr, command); + + k_mutex_lock(&data->mutex, K_FOREVER); + + ret = pch_smbus_start(dev, periph_addr, SMBUS_MSG_WRITE, command, + &byte, SMBUS_CMD_BYTE_DATA); + if (ret < 0) { + goto unlock; + } + + /* Wait for completion from ISR */ + ret = k_sem_take(&data->completion_sync, K_MSEC(30)); + if (ret != 0) { + LOG_ERR("SMBus Byte Data Write timed out"); + ret = -ETIMEDOUT; + goto unlock; + } + + ret = pch_check_status(dev); + +unlock: + k_mutex_unlock(&data->mutex); + + return ret; +} + +/* Implementation of SMBus Byte Data Read */ +static int pch_smbus_byte_data_read(const struct device *dev, + uint16_t periph_addr, + uint8_t command, uint8_t *byte) +{ + struct pch_data *data = dev->data; + int ret; + + LOG_DBG("dev %p addr 0x%02x command 0x%02x", dev, periph_addr, command); + + k_mutex_lock(&data->mutex, K_FOREVER); + + ret = pch_smbus_start(dev, periph_addr, SMBUS_MSG_READ, command, + NULL, SMBUS_CMD_BYTE_DATA); + if (ret < 0) { + goto unlock; + } + + /* Wait for completion from ISR */ + ret = k_sem_take(&data->completion_sync, K_MSEC(30)); + if (ret != 0) { + LOG_ERR("SMBus Byte Data Read timed out"); + ret = -ETIMEDOUT; + goto unlock; + } + + ret = pch_check_status(dev); + if (ret < 0) { + goto unlock; + } + + *byte = pch_reg_read(dev, PCH_SMBUS_HD0); + +unlock: + k_mutex_unlock(&data->mutex); + + return ret; +} + +/* Implementation of SMBus Word Data Write */ +static int pch_smbus_word_data_write(const struct device *dev, + uint16_t periph_addr, + uint8_t command, uint16_t word) +{ + struct pch_data *data = dev->data; + int ret; + + LOG_DBG("dev %p addr 0x%02x command 0x%02x", dev, periph_addr, command); + + k_mutex_lock(&data->mutex, K_FOREVER); + + ret = pch_smbus_start(dev, periph_addr, SMBUS_MSG_WRITE, command, + (uint8_t *)&word, SMBUS_CMD_WORD_DATA); + if (ret < 0) { + goto unlock; + } + + /* Wait for completion from ISR */ + ret = k_sem_take(&data->completion_sync, K_MSEC(30)); + if (ret != 0) { + LOG_ERR("SMBus Word Data Write timed out"); + ret = -ETIMEDOUT; + goto unlock; + } + + ret = pch_check_status(dev); + +unlock: + k_mutex_unlock(&data->mutex); + + return ret; +} + +/* Implementation of SMBus Word Data Read */ +static int pch_smbus_word_data_read(const struct device *dev, + uint16_t periph_addr, + uint8_t command, uint16_t *word) +{ + struct pch_data *data = dev->data; + uint8_t *p = (uint8_t *)word; + int ret; + + LOG_DBG("dev %p addr 0x%02x command 0x%02x", dev, periph_addr, command); + + k_mutex_lock(&data->mutex, K_FOREVER); + + ret = pch_smbus_start(dev, periph_addr, SMBUS_MSG_READ, command, + NULL, SMBUS_CMD_WORD_DATA); + if (ret < 0) { + goto unlock; + } + + /* Wait for completion from ISR */ + ret = k_sem_take(&data->completion_sync, K_MSEC(30)); + if (ret != 0) { + LOG_ERR("SMBus Word Data Read timed out"); + ret = -ETIMEDOUT; + goto unlock; + } + + ret = pch_check_status(dev); + if (ret < 0) { + goto unlock; + } + + p[0] = pch_reg_read(dev, PCH_SMBUS_HD0); + p[1] = pch_reg_read(dev, PCH_SMBUS_HD1); + +unlock: + k_mutex_unlock(&data->mutex); + + return ret; +} + +/* Implementation of SMBus Process Call */ +static int pch_smbus_pcall(const struct device *dev, + uint16_t periph_addr, uint8_t command, + uint16_t send_word, uint16_t *recv_word) +{ + struct pch_data *data = dev->data; + uint8_t *p = (uint8_t *)recv_word; + int ret; + + LOG_DBG("dev %p addr 0x%02x command 0x%02x", dev, periph_addr, command); + + k_mutex_lock(&data->mutex, K_FOREVER); + + ret = pch_smbus_start(dev, periph_addr, SMBUS_MSG_WRITE, command, + (uint8_t *)&send_word, SMBUS_CMD_PROC_CALL); + if (ret < 0) { + goto unlock; + } + + /* Wait for completion from ISR */ + ret = k_sem_take(&data->completion_sync, K_MSEC(30)); + if (ret != 0) { + LOG_ERR("SMBus Proc Call timed out"); + ret = -ETIMEDOUT; + goto unlock; + } + + ret = pch_check_status(dev); + if (ret < 0) { + goto unlock; + } + + p[0] = pch_reg_read(dev, PCH_SMBUS_HD0); + p[1] = pch_reg_read(dev, PCH_SMBUS_HD1); + +unlock: + k_mutex_unlock(&data->mutex); + + return ret; +} + +/* Implementation of SMBus Block Write */ +static int pch_smbus_block_write(const struct device *dev, uint16_t periph_addr, + uint8_t command, uint8_t count, uint8_t *buf) +{ + struct pch_data *data = dev->data; + int ret; + + LOG_DBG("dev %p addr 0x%02x command 0x%02x count %u", + dev, periph_addr, command, count); + + k_mutex_lock(&data->mutex, K_FOREVER); + + ret = pch_smbus_block_start(dev, periph_addr, SMBUS_MSG_WRITE, command, + count, buf, SMBUS_CMD_BLOCK); + if (ret < 0) { + goto unlock; + } + + /* Wait for completion from ISR */ + ret = k_sem_take(&data->completion_sync, K_MSEC(30)); + if (ret != 0) { + LOG_ERR("SMBus Block Write timed out"); + ret = -ETIMEDOUT; + goto unlock; + } + + ret = pch_check_status(dev); + +unlock: + k_mutex_unlock(&data->mutex); + + return ret; +} + +/* Implementation of SMBus Block Read */ +static int pch_smbus_block_read(const struct device *dev, uint16_t periph_addr, + uint8_t command, uint8_t *count, uint8_t *buf) +{ + struct pch_data *data = dev->data; + int ret; + + LOG_DBG("dev %p addr 0x%02x command 0x%02x", + dev, periph_addr, command); + + k_mutex_lock(&data->mutex, K_FOREVER); + + ret = pch_smbus_block_start(dev, periph_addr, SMBUS_MSG_READ, command, + 0, buf, SMBUS_CMD_BLOCK); + if (ret < 0) { + goto unlock; + } + + /* Wait for completion from ISR */ + ret = k_sem_take(&data->completion_sync, K_MSEC(30)); + if (ret != 0) { + LOG_ERR("SMBus Block Read timed out"); + ret = -ETIMEDOUT; + goto unlock; + } + + ret = pch_check_status(dev); + if (ret < 0) { + goto unlock; + } + + *count = pch_reg_read(dev, PCH_SMBUS_HD0); + if (*count == 0 || *count > SMBUS_BLOCK_BYTES_MAX) { + ret = -ENODATA; + goto unlock; + } + + for (int i = 0; i < *count; i++) { + buf[i] = pch_reg_read(dev, PCH_SMBUS_HBD); + } + +unlock: + k_mutex_unlock(&data->mutex); + + return ret; +} + +static const struct smbus_driver_api funcs = { + .configure = pch_configure, + .get_config = pch_get_config, + .smbus_quick = pch_smbus_quick, + .smbus_byte_write = pch_smbus_byte_write, + .smbus_byte_read = pch_smbus_byte_read, + .smbus_byte_data_write = pch_smbus_byte_data_write, + .smbus_byte_data_read = pch_smbus_byte_data_read, + .smbus_word_data_write = pch_smbus_word_data_write, + .smbus_word_data_read = pch_smbus_word_data_read, + .smbus_pcall = pch_smbus_pcall, + .smbus_block_write = pch_smbus_block_write, + .smbus_block_read = pch_smbus_block_read, +}; + +static void smbus_isr(const struct device *dev) +{ + const struct pch_config * const config = dev->config; + struct pch_data *data = dev->data; + uint32_t sts; + uint8_t status; + + sts = pcie_conf_read(config->pcie_bdf, PCIE_CONF_CMDSTAT); + if (!(sts & PCIE_CONF_CMDSTAT_INTERRUPT)) { + LOG_ERR("Not our interrupt"); + return; + } + + status = pch_reg_read(dev, PCH_SMBUS_HSTS); + + /* HSTS dump if logging is enabled */ + pch_dump_register_hsts(status); + + if (status & PCH_SMBUS_HSTS_BYTE_DONE) { + LOG_WRN("BYTE_DONE interrupt is not used"); + } + + /* Clear IRQ sources */ + pch_reg_write(dev, PCH_SMBUS_HSTS, status); + + data->status = status; + + k_sem_give(&data->completion_sync); +} + +/* Device macro initialization / DTS hackery */ + +/* PCI BDF is hacked into REG_ADDR */ +#define DT_INST_PCIE_BDF(n) DT_INST_REG_ADDR(n) + +/* PCI ID is hacked into REG_SIZE */ +#define DT_INST_PCIE_ID(n) DT_INST_REG_SIZE(n) + +#define SMBUS_PCH_IRQ_FLAGS_SENSE0(n) 0 +#define SMBUS_PCH_IRQ_FLAGS_SENSE1(n) DT_INST_IRQ(n, sense) +#define SMBUS_PCH_IRQ_FLAGS(n) \ + _CONCAT(SMBUS_PCH_IRQ_FLAGS_SENSE, DT_INST_IRQ_HAS_CELL(n, sense))(n) + +#define SMBUS_IRQ_CONFIG(n) \ + BUILD_ASSERT(IS_ENABLED(CONFIG_DYNAMIC_INTERRUPTS), \ + "SMBus PCIe requires dynamic interrupts"); \ + static void pch_config_##n(const struct device *dev) \ + { \ + ARG_UNUSED(dev); \ + unsigned int irq; \ + if (DT_INST_IRQN(n) == PCIE_IRQ_DETECT) { \ + irq = pcie_alloc_irq(DT_INST_PCIE_BDF(n)); \ + if (irq == PCIE_CONF_INTR_IRQ_NONE) { \ + return; \ + } \ + } else { \ + irq = DT_INST_IRQN(n); \ + pcie_conf_write(DT_INST_PCIE_BDF(n), \ + PCIE_CONF_INTR, irq); \ + } \ + pcie_connect_dynamic_irq(DT_INST_PCIE_BDF(n), irq, \ + DT_INST_IRQ(n, priority), \ + (void (*)(const void *))smbus_isr, \ + DEVICE_DT_INST_GET(n), \ + SMBUS_PCH_IRQ_FLAGS(n)); \ + pcie_irq_enable(DT_INST_PCIE_BDF(n), irq); \ + LOG_DBG("Configure irq %d", irq); \ + } + +#define SMBUS_DEVICE_INIT(n) \ + static void pch_config_##n(const struct device *dev); \ + static const struct pch_config pch_config_data_##n = { \ + .config_func = pch_config_##n, \ + .pcie_bdf = DT_INST_PCIE_BDF(n), \ + .pcie_id = DT_INST_PCIE_ID(n), \ + }; \ + static struct pch_data smbus_##n##_data; \ + SMBUS_DEVICE_DT_INST_DEFINE(n, pch_smbus_init, NULL, \ + &smbus_##n##_data, &pch_config_data_##n, \ + POST_KERNEL, CONFIG_SMBUS_INIT_PRIORITY, \ + &funcs); \ + SMBUS_IRQ_CONFIG(n); + +DT_INST_FOREACH_STATUS_OKAY(SMBUS_DEVICE_INIT) From cb2a10c2544efc2bd96fd15129582e13feb78673 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Fri, 9 Sep 2022 11:56:17 +0300 Subject: [PATCH 0641/1906] smbus: dts: Add Intel PCH SMBus driver bindings Add bindings for Intel PCH SMBus driver. Signed-off-by: Andrei Emeltchenko --- dts/bindings/smbus/intel,pch-smbus.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 dts/bindings/smbus/intel,pch-smbus.yaml diff --git a/dts/bindings/smbus/intel,pch-smbus.yaml b/dts/bindings/smbus/intel,pch-smbus.yaml new file mode 100644 index 000000000000..3dcdbb57a187 --- /dev/null +++ b/dts/bindings/smbus/intel,pch-smbus.yaml @@ -0,0 +1,12 @@ +# Copyright (c) 2022 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +description: Intel Platform Controller Hub SMBus node + +compatible: "intel,pch-smbus" + +include: smbus-controller.yaml + +properties: + interrupts: + required: true From 2de1936acc78aed33f54690a6ec19dc4da1ae316 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Thu, 29 Sep 2022 16:40:31 +0300 Subject: [PATCH 0642/1906] drivers: smbus: pch: Add Block Process Call operation Add SMBus Block Process Call implementation for Intel PCH SMBus driver. Signed-off-by: Andrei Emeltchenko --- drivers/smbus/intel_pch_smbus.c | 51 +++++++++++++++++++++++++++++++++ drivers/smbus/smbus_handlers.c | 14 +++++++++ 2 files changed, 65 insertions(+) diff --git a/drivers/smbus/intel_pch_smbus.c b/drivers/smbus/intel_pch_smbus.c index 35d146db8b99..1dd671415991 100644 --- a/drivers/smbus/intel_pch_smbus.c +++ b/drivers/smbus/intel_pch_smbus.c @@ -716,6 +716,56 @@ static int pch_smbus_block_read(const struct device *dev, uint16_t periph_addr, return ret; } +/* Implementation of SMBus Block Process Call */ +static int pch_smbus_block_pcall(const struct device *dev, + uint16_t periph_addr, uint8_t command, + uint8_t send_count, uint8_t *send_buf, + uint8_t *recv_count, uint8_t *recv_buf) +{ + struct pch_data *data = dev->data; + int ret; + + LOG_DBG("dev %p addr 0x%02x command 0x%02x", + dev, periph_addr, command); + + k_mutex_lock(&data->mutex, K_FOREVER); + + ret = pch_smbus_block_start(dev, periph_addr, SMBUS_MSG_WRITE, command, + send_count, send_buf, SMBUS_CMD_BLOCK_PROC); + if (ret < 0) { + goto unlock; + } + + /* Wait for completion from ISR */ + ret = k_sem_take(&data->completion_sync, K_MSEC(30)); + if (ret != 0) { + LOG_ERR("SMBus Block Process Call timed out"); + ret = -ETIMEDOUT; + goto unlock; + } + + ret = pch_check_status(dev); + if (ret < 0) { + goto unlock; + } + + *recv_count = pch_reg_read(dev, PCH_SMBUS_HD0); + if (*recv_count == 0 || + *recv_count + send_count > SMBUS_BLOCK_BYTES_MAX) { + ret = -ENODATA; + goto unlock; + } + + for (int i = 0; i < *recv_count; i++) { + recv_buf[i] = pch_reg_read(dev, PCH_SMBUS_HBD); + } + +unlock: + k_mutex_unlock(&data->mutex); + + return ret; +} + static const struct smbus_driver_api funcs = { .configure = pch_configure, .get_config = pch_get_config, @@ -729,6 +779,7 @@ static const struct smbus_driver_api funcs = { .smbus_pcall = pch_smbus_pcall, .smbus_block_write = pch_smbus_block_write, .smbus_block_read = pch_smbus_block_read, + .smbus_block_pcall = pch_smbus_block_pcall, }; static void smbus_isr(const struct device *dev) diff --git a/drivers/smbus/smbus_handlers.c b/drivers/smbus/smbus_handlers.c index 93ae3eb9a60f..547814fe6923 100644 --- a/drivers/smbus/smbus_handlers.c +++ b/drivers/smbus/smbus_handlers.c @@ -128,3 +128,17 @@ static inline int z_vrfy_smbus_block_read(const struct device *dev, return z_impl_smbus_block_read(dev, addr, cmd, count, buf); } #include + +static inline int z_vrfy_smbus_block_pcall(const struct device *dev, + uint16_t addr, uint8_t cmd, + uint8_t snd_count, uint8_t *snd_buf, + uint8_t *rcv_count, uint8_t *rcv_buf) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + Z_OOPS(Z_SYSCALL_MEMORY_READ(snd_buf, snd_count)); + Z_OOPS(Z_SYSCALL_MEMORY_WRITE(rcv_count, sizeof(uint8_t))); + + return z_impl_smbus_block_pcall(dev, addr, cmd, snd_count, snd_buf, + rcv_count, rcv_buf); +} +#include From 2146b19cc737917b094ae953bde210ea1e3c9e12 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Wed, 5 Oct 2022 15:40:39 +0300 Subject: [PATCH 0643/1906] smbus: Add Host Notify and smbalert API Add API for SMBus Host Notify and SMBALERT. Signed-off-by: Andrei Emeltchenko --- drivers/smbus/smbus_handlers.c | 23 ++++++- include/zephyr/drivers/smbus.h | 98 ++++++++++++++++++++++++++++ include/zephyr/drivers/smbus_utils.h | 85 ++++++++++++++++++++++++ 3 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 include/zephyr/drivers/smbus_utils.h diff --git a/drivers/smbus/smbus_handlers.c b/drivers/smbus/smbus_handlers.c index 547814fe6923..fd03a7cad487 100644 --- a/drivers/smbus/smbus_handlers.c +++ b/drivers/smbus/smbus_handlers.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include +#include static inline int z_vrfy_smbus_configure(const struct device *dev, uint32_t dev_config) @@ -142,3 +143,23 @@ static inline int z_vrfy_smbus_block_pcall(const struct device *dev, rcv_count, rcv_buf); } #include + +static inline int z_vrfy_smbus_manage_smbalert_cb(const struct device *dev, + struct smbus_callback *cb, + bool set) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + + return z_impl_smbus_manage_smbalert_cb(dev, cb, set); +} +#include + +static inline int z_vrfy_smbus_manage_host_notify_cb(const struct device *dev, + struct smbus_callback *cb, + bool set) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + + return z_impl_smbus_manage_host_notify_cb(dev, cb, set); +} +#include diff --git a/include/zephyr/drivers/smbus.h b/include/zephyr/drivers/smbus.h index 872f0481f29a..d20786f7d11c 100644 --- a/include/zephyr/drivers/smbus.h +++ b/include/zephyr/drivers/smbus.h @@ -209,6 +209,12 @@ extern "C" { /** Support Packet Error Code (PEC) checking */ #define SMBUS_MODE_PEC BIT(1) +/** Support Host Notify functionality */ +#define SMBUS_MODE_HOST_NOTIFY BIT(2) + +/** Support SMBALERT signal functionality */ +#define SMBUS_MODE_SMBALERT BIT(3) + /** @} */ /** @@ -247,6 +253,32 @@ enum smbus_direction { #define SMBUS_MSG_RW_MASK BIT(0) /** @endcond */ +struct smbus_callback; + +typedef void (*smbus_callback_handler_t)(const struct device *dev, + struct smbus_callback *cb, + uint8_t addr); + +/** + * @brief SMBus callback structure + * + * Used to register a callback in the driver instance callback list. + * As many callbacks as needed can be added as long as each of them + * are unique pointers of struct smbus_callback. + * + * Note: Such struct should not be allocated on stack. + */ +struct smbus_callback { + /** This should be used in driver for a callback list management */ + sys_snode_t node; + + /** Actual callback function being called when relevant */ + smbus_callback_handler_t handler; + + /** Peripheral device address */ + uint8_t addr; +}; + /** * @brief Complete SMBus DT information * @@ -326,6 +358,12 @@ typedef int (*smbus_api_block_pcall_t)(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t send_count, uint8_t *send_buf, uint8_t *recv_count, uint8_t *recv_buf); +typedef int (*smbus_api_manage_smbalert_cb_t)(const struct device *dev, + struct smbus_callback *cb, + bool set); +typedef int (*smbus_api_manage_host_notify_cb_t)(const struct device *dev, + struct smbus_callback *cb, + bool set); __subsystem struct smbus_driver_api { smbus_api_configure_t configure; @@ -341,6 +379,8 @@ __subsystem struct smbus_driver_api { smbus_api_block_write_t smbus_block_write; smbus_api_block_read_t smbus_block_read; smbus_api_block_pcall_t smbus_block_pcall; + smbus_api_manage_smbalert_cb_t smbus_manage_smbalert_cb; + smbus_api_manage_host_notify_cb_t smbus_manage_host_notify_cb; }; /** @@ -547,6 +587,64 @@ static inline int z_impl_smbus_get_config(const struct device *dev, return api->get_config(dev, dev_config); } +/** + * @brief Add SMBUSALERT callback for a SMBus host controller. + * + * @param dev Pointer to the device structure for the driver instance. + * @param cb Pointer to a callback structure. + * @param set A boolean indicating insertion or removal of the callback. + * + * @retval 0 If successful. + * @retval -EIO General input / output error, failed to configure device. + * @retval -ENOSYS If get config is not implemented + */ +__syscall int smbus_manage_smbalert_cb(const struct device *dev, + struct smbus_callback *cb, + bool set); + +static inline int z_impl_smbus_manage_smbalert_cb(const struct device *dev, + struct smbus_callback *cb, + bool set) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_manage_smbalert_cb == NULL) { + return -ENOSYS; + } + + return api->smbus_manage_smbalert_cb(dev, cb, set); +} + +/** + * @brief Add Host Notify callback for a SMBus host controller. + * + * @param dev Pointer to the device structure for the driver instance. + * @param cb Pointer to a callback structure. + * @param set A boolean indicating insertion or removal of the callback. + * + * @retval 0 If successful. + * @retval -EIO General input / output error, failed to configure device. + * @retval -ENOSYS If get config is not implemented + */ +__syscall int smbus_manage_host_notify_cb(const struct device *dev, + struct smbus_callback *cb, + bool set); + +static inline int z_impl_smbus_manage_host_notify_cb(const struct device *dev, + struct smbus_callback *cb, + bool set) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_manage_host_notify_cb == NULL) { + return -ENOSYS; + } + + return api->smbus_manage_host_notify_cb(dev, cb, set); +} + /** * @brief Perform SMBus Quick operation * diff --git a/include/zephyr/drivers/smbus_utils.h b/include/zephyr/drivers/smbus_utils.h new file mode 100644 index 000000000000..426891dfdf6f --- /dev/null +++ b/include/zephyr/drivers/smbus_utils.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_DRIVERS_SMBUS_SMBUS_UTILS_H_ +#define ZEPHYR_DRIVERS_SMBUS_SMBUS_UTILS_H_ + +/** + * @brief Generic function to insert or remove a callback from a callback list + * + * @param callbacks A pointer to the original list of callbacks (can be NULL) + * @param callback A pointer of the callback to insert or remove from the list + * @param set A boolean indicating insertion or removal of the callback + * + * @return 0 on success, negative errno otherwise. + */ +static inline int smbus_manage_smbus_callback(sys_slist_t *callbacks, + struct smbus_callback *callback, + bool set) +{ + __ASSERT(callback, "No callback!"); + __ASSERT(callback->handler, "No callback handler!"); + + if (!sys_slist_is_empty(callbacks)) { + if (!sys_slist_find_and_remove(callbacks, &callback->node)) { + if (!set) { + return -ENOENT; + } + } + } else { + if (!set) { + return -ENOENT; + } + } + + if (set) { + sys_slist_prepend(callbacks, &callback->node); + } + + return 0; +} + +/** + * @brief Generic function to go through and fire callback from a callback list + * + * @param list A pointer on the SMBus callback list + * @param dev A pointer on the SMBus device instance + * @param addr A SMBus peripheral device address. + */ +static inline void smbus_fire_callbacks(sys_slist_t *list, + const struct device *dev, + uint8_t addr) +{ + struct smbus_callback *cb, *tmp; + + SYS_SLIST_FOR_EACH_CONTAINER_SAFE(list, cb, tmp, node) { + if (cb->addr == addr) { + __ASSERT(cb->handler, "No callback handler!"); + cb->handler(dev, cb, addr); + } + } +} + +/** + * @brief Helper to initialize a struct smbus_callback properly + * + * @param callback A valid Application's callback structure pointer. + * @param handler A valid handler function pointer. + * @param addr A SMBus peripheral device address. + */ +static inline void smbus_init_callback(struct smbus_callback *callback, + smbus_callback_handler_t handler, + uint8_t addr) +{ + __ASSERT(callback, "Callback pointer should not be NULL"); + __ASSERT(handler, "Callback handler pointer should not be NULL"); + + callback->handler = handler; + callback->addr = addr; +} + + +#endif /* ZEPHYR_DRIVERS_SMBUS_SMBUS_UTILS_H_ */ From fe46408ff2dc385808a1a4e5b01ed605b94edfb1 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Wed, 5 Oct 2022 16:34:20 +0300 Subject: [PATCH 0644/1906] drivers: smbus: Implement Host Notify and SMBALERT for PCH Implement SMBus Host Notify and SMBALERT for Intel PCH driver. Signed-off-by: Andrei Emeltchenko --- drivers/smbus/Kconfig | 12 +++ drivers/smbus/intel_pch_smbus.c | 161 +++++++++++++++++++++++++++++++- 2 files changed, 172 insertions(+), 1 deletion(-) diff --git a/drivers/smbus/Kconfig b/drivers/smbus/Kconfig index 561062c6e972..927c70c1c301 100644 --- a/drivers/smbus/Kconfig +++ b/drivers/smbus/Kconfig @@ -62,6 +62,18 @@ config SMBUS_INTEL_PCH_ACCESS_MMIO endchoice +config SMBUS_INTEL_PCH_HOST_NOTIFY + bool "SMBus Intel PCH Host Notify support" + default y + help + Support Host Notify from peripheral devices. + +config SMBUS_INTEL_PCH_SMBALERT + bool "SMBus Intel PCH SMBALERT signal support" + default y + help + Support SMBALERT signal from peripheral devices. + endif # SMBUS_INTEL_PCH endif # SMBUS diff --git a/drivers/smbus/intel_pch_smbus.c b/drivers/smbus/intel_pch_smbus.c index 1dd671415991..2916217cee0b 100644 --- a/drivers/smbus/intel_pch_smbus.c +++ b/drivers/smbus/intel_pch_smbus.c @@ -21,6 +21,7 @@ #include LOG_MODULE_REGISTER(intel_pch, CONFIG_SMBUS_LOG_LEVEL); +#include #include "intel_pch_smbus.h" /** @@ -53,6 +54,21 @@ struct pch_data { struct k_mutex mutex; struct k_sem completion_sync; + const struct device *dev; + + /* smbalert callback list */ + sys_slist_t smbalert_cbs; + /* smbalert work */ + struct k_work smb_alert_work; + + /* Host Notify callback list */ + sys_slist_t host_notify_cbs; + /* Host Notify work */ + struct k_work host_notify_work; + /* Host Notify peripheral device address */ + uint8_t notify_addr; + /* Host Notify data received */ + uint16_t notify_data; }; /** @@ -87,12 +103,107 @@ static void pch_reg_write(const struct device *dev, uint8_t reg, uint8_t val) #error Wrong PCH Register Access Mode #endif +static void host_notify_work(struct k_work *work) +{ + struct pch_data *data = CONTAINER_OF(work, struct pch_data, + host_notify_work); + const struct device *dev = data->dev; + uint8_t addr = data->notify_addr; + + smbus_fire_callbacks(&data->host_notify_cbs, dev, addr); +} + +static void smbalert_work(struct k_work *work) +{ + struct pch_data *data = CONTAINER_OF(work, struct pch_data, + smb_alert_work); + const struct device *dev = data->dev; + + /** + * There might be several peripheral devices and the he highest + * priority (lowest address) device wins arbitration, we need to + * read them all. + * + * The format of the transaction is: + * + * 0 1 2 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |S| Alert Addr |R|A| Address |X|N|P| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + do { + uint8_t addr; + int ret; + + ret = smbus_byte_read(dev, SMBUS_ADDRESS_ARA, &addr); + if (ret < 0) { + LOG_DBG("Cannot read peripheral address (anymore)"); + return; + } + + LOG_DBG("Read addr 0x%02x, ret %d", addr, ret); + + smbus_fire_callbacks(&data->smbalert_cbs, dev, addr); + } while (true); +} + +static int pch_smbus_manage_smbalert_cb(const struct device *dev, + struct smbus_callback *cb, + bool set) +{ + struct pch_data *data = dev->data; + + LOG_DBG("dev %p cb %p set %d", dev, cb, set); + + return smbus_manage_smbus_callback(&data->smbalert_cbs, cb, set); +} + +static int pch_smbus_manage_host_notify_cb(const struct device *dev, + struct smbus_callback *cb, + bool set) +{ + struct pch_data *data = dev->data; + + LOG_DBG("dev %p cb %p set %d", dev, cb, set); + + return smbus_manage_smbus_callback(&data->host_notify_cbs, cb, set); +} + static int pch_configure(const struct device *dev, uint32_t config) { struct pch_data *data = dev->data; LOG_DBG("dev %p config 0x%x", dev, config); + if (config & SMBUS_MODE_HOST_NOTIFY) { + uint8_t status; + + if (!IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY)) { + LOG_ERR("Error configuring Host Notify"); + return -EINVAL; + } + + /* Enable Host Notify interrupts */ + status = pch_reg_read(dev, PCH_SMBUS_SCMD); + status |= PCH_SMBUS_SCMD_HNI_EN; + pch_reg_write(dev, PCH_SMBUS_SCMD, status); + } + + if (config & SMBUS_MODE_SMBALERT) { + uint8_t status; + + if (!IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_SMBALERT)) { + LOG_ERR("Error configuring SMBALERT"); + return -EINVAL; + } + + /* Disable SMBALERT_DIS */ + status = pch_reg_read(dev, PCH_SMBUS_SCMD); + status &= ~PCH_SMBUS_SCMD_SMBALERT_DIS; + pch_reg_write(dev, PCH_SMBUS_SCMD, status); + } + /* Keep config for a moment */ data->config = config; @@ -158,6 +269,17 @@ static int pch_smbus_init(const struct device *dev) k_mutex_init(&data->mutex); k_sem_init(&data->completion_sync, 0, 1); + data->dev = dev; + + /* Initialize work structures */ + if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_SMBALERT)) { + k_work_init(&data->smb_alert_work, smbalert_work); + } + + if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY)) { + k_work_init(&data->host_notify_work, host_notify_work); + } + config->config_func(dev); if (pch_configure(dev, SMBUS_MODE_CONTROLLER)) { @@ -303,7 +425,7 @@ static int pch_smbus_start(const struct device *dev, uint16_t periph_addr, uint8_t reg; int ret; - LOG_DBG("addr %x rw %d command %x", periph_addr, rw, command); + LOG_DBG("addr 0x%02x rw %d command %x", periph_addr, rw, command); /* Set TSA register */ reg = PCH_SMBUS_TSA_ADDR_SET(periph_addr); @@ -780,6 +902,8 @@ static const struct smbus_driver_api funcs = { .smbus_block_write = pch_smbus_block_write, .smbus_block_read = pch_smbus_block_read, .smbus_block_pcall = pch_smbus_block_pcall, + .smbus_manage_smbalert_cb = pch_smbus_manage_smbalert_cb, + .smbus_manage_host_notify_cb = pch_smbus_manage_host_notify_cb, }; static void smbus_isr(const struct device *dev) @@ -795,6 +919,34 @@ static void smbus_isr(const struct device *dev) return; } + /** + * Handle first Host Notify since for that we need to read SSTS + * register and for all other sources HSTS. + * + * Intel PCH implements Host Notify protocol in hardware. + */ + if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY) && + data->config & SMBUS_MODE_HOST_NOTIFY) { + status = pch_reg_read(dev, PCH_SMBUS_SSTS); + if (status & PCH_SMBUS_SSTS_HNS) { + /* Notify address */ + data->notify_addr = + pch_reg_read(dev, PCH_SMBUS_NDA) >> 1; + + /* Notify data */ + data->notify_data = pch_reg_read(dev, PCH_SMBUS_NDLB); + data->notify_data |= + pch_reg_read(dev, PCH_SMBUS_NDHB) << 8; + + k_work_submit(&data->host_notify_work); + + /* Clear Host Notify */ + pch_reg_write(dev, PCH_SMBUS_SSTS, PCH_SMBUS_SSTS_HNS); + + return; + } + } + status = pch_reg_read(dev, PCH_SMBUS_HSTS); /* HSTS dump if logging is enabled */ @@ -804,6 +956,13 @@ static void smbus_isr(const struct device *dev) LOG_WRN("BYTE_DONE interrupt is not used"); } + /* Handle SMBALERT# signal */ + if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_SMBALERT) && + data->config & SMBUS_MODE_SMBALERT && + status & PCH_SMBUS_HSTS_SMB_ALERT) { + k_work_submit(&data->smb_alert_work); + } + /* Clear IRQ sources */ pch_reg_write(dev, PCH_SMBUS_HSTS, status); From fe9dfcfcd192dc36393572507f88ec7028dd74cc Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Tue, 25 Oct 2022 11:45:52 +0300 Subject: [PATCH 0645/1906] board: raptor_lake: Add smbus to the board's DTS Add PCH SMBus driver to Raptor Lake device tree. Signed-off-by: Andrei Emeltchenko --- dts/x86/intel/raptor_lake.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dts/x86/intel/raptor_lake.dtsi b/dts/x86/intel/raptor_lake.dtsi index 723f72fc4996..bc9f86fc8689 100644 --- a/dts/x86/intel/raptor_lake.dtsi +++ b/dts/x86/intel/raptor_lake.dtsi @@ -41,6 +41,17 @@ compatible = "intel,pcie"; ranges; + smbus0: smbus@fc00 { + compatible = "intel,pch-smbus"; + #address-cells = <1>; + #size-cells = <0>; + reg = ; + interrupts = <18 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + + status = "okay"; + }; + i2c0: i2c0 { compatible = "snps,designware-i2c"; clock-frequency = ; From f2b6fb9cd2a549c6838715ca2514783655c85fec Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Fri, 12 Aug 2022 17:27:21 +0300 Subject: [PATCH 0646/1906] board: elkhart_lake: Add smbus to the board's DTS Add PCH SMBus to Elkhart Lake device tree. Signed-off-by: Andrei Emeltchenko --- dts/x86/intel/elkhart_lake.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dts/x86/intel/elkhart_lake.dtsi b/dts/x86/intel/elkhart_lake.dtsi index 62d89751a929..7b1ab2f6ba9b 100644 --- a/dts/x86/intel/elkhart_lake.dtsi +++ b/dts/x86/intel/elkhart_lake.dtsi @@ -189,6 +189,17 @@ current-speed = <115200>; }; + smbus0: smbus@fc00 { + compatible = "intel,pch-smbus"; + #address-cells = <1>; + #size-cells = <0>; + reg = ; + interrupts = <16 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; + interrupt-parent = <&intc>; + + status = "okay"; + }; + i2c0: i2c0 { compatible = "snps,designware-i2c"; clock-frequency = ; From 3e0a88e8dadf56b7165864222a0fc0441ac166ef Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Mon, 21 Nov 2022 12:36:23 +0200 Subject: [PATCH 0647/1906] board: qemu_x86_64: Add SMBus DTS configuration Add SMBus specific configuration to qemu_x86_64 device tree since this board does not have issues with dynamic IRQ allocation. Signed-off-by: Andrei Emeltchenko --- boards/x86/qemu_x86/qemu_x86_64.dts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/boards/x86/qemu_x86/qemu_x86_64.dts b/boards/x86/qemu_x86/qemu_x86_64.dts index 92522ab8a4ea..83bf2c7fd0f2 100644 --- a/boards/x86/qemu_x86/qemu_x86_64.dts +++ b/boards/x86/qemu_x86/qemu_x86_64.dts @@ -4,3 +4,17 @@ */ #include "qemu_x86.dts" + +&pcie0 { + smbus0: smbus0 { + compatible = "intel,pch-smbus"; + #address-cells = <1>; + #size-cells = <0>; + vendor-id = <0x8086>; + device-id = <0x2930>; + interrupts = ; + interrupt-parent = <&intc>; + + status = "okay"; + }; +}; From cf423b3eaae95a07e3eb6980a6b847396efe27df Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Thu, 25 Aug 2022 09:51:46 +0300 Subject: [PATCH 0648/1906] samples: Add smbus shell sample application Add smbus sample for testing SMBus commands. Signed-off-by: Andrei Emeltchenko --- samples/drivers/smbus/CMakeLists.txt | 12 ++++ samples/drivers/smbus/README.rst | 71 +++++++++++++++++++ samples/drivers/smbus/boards/qemu_x86_64.conf | 3 + samples/drivers/smbus/prj.conf | 10 +++ samples/drivers/smbus/qemu_x86_64.overlay | 17 +++++ samples/drivers/smbus/sample.yaml | 13 ++++ samples/drivers/smbus/src/main.c | 12 ++++ 7 files changed, 138 insertions(+) create mode 100644 samples/drivers/smbus/CMakeLists.txt create mode 100644 samples/drivers/smbus/README.rst create mode 100644 samples/drivers/smbus/boards/qemu_x86_64.conf create mode 100644 samples/drivers/smbus/prj.conf create mode 100644 samples/drivers/smbus/qemu_x86_64.overlay create mode 100644 samples/drivers/smbus/sample.yaml create mode 100644 samples/drivers/smbus/src/main.c diff --git a/samples/drivers/smbus/CMakeLists.txt b/samples/drivers/smbus/CMakeLists.txt new file mode 100644 index 000000000000..5fa4d8718cbe --- /dev/null +++ b/samples/drivers/smbus/CMakeLists.txt @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +if(BOARD STREQUAL qemu_x86_64) + LIST(APPEND QEMU_EXTRA_FLAGS -machine q35) +endif() + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(smbus) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/drivers/smbus/README.rst b/samples/drivers/smbus/README.rst new file mode 100644 index 000000000000..e1f8fec8db91 --- /dev/null +++ b/samples/drivers/smbus/README.rst @@ -0,0 +1,71 @@ +.. _samples_smbus_shell: + +SMBus Shell Sample +################## + +Overview +******** + +This is a simple SMBus shell sample that allows arbitrary boards with SMBus +driver supported exploring the SMBus communication with peripheral devices. + +Building and Running +******************** + +This project can be built and executed on as follows: + +.. zephyr-app-commands:: + :zephyr-app: zephyr/samples/drivers/smbus + :host-os: unix + :board: qemu_x86_64 + :goals: run + :compact: + +Sample Output +============= + +Output from console when application started:: + + *** Booting Zephyr OS build zephyr-v3.2.0-804-gfedd72615e82 *** + Start SMBUS shell sample qemu_x86_64 + uart:~$ + +List avaibalbe SMBus shell commands with:: + + uart:~$ smbus + smbus - smbus commands + Subcommands: + quick :SMBus Quick command + Usage: quick + scan :Scan SMBus peripheral devices command + Usage: scan + byte_read :SMBus: byte read command + Usage: byte_read + byte_write :SMBus: byte write command + Usage: byte_write + byte_data_read :SMBus: byte data read command + Usage: byte_data_read + byte_data_write :SMBus: byte data write command + Usage: byte_data_write + word_data_read :SMBus: word data read command + Usage: word_data_read + word_data_write :SMBus: word data write command + Usage: word_data_write + block_write :SMBus: Block Write command + Usage: block_write [, ...] + block_read :SMBus: Block Read command + Usage: block_read + +Scan for available SMBus devices with command:: + + uart:~$ smbus scan smbus@fb00 + 0 1 2 3 4 5 6 7 8 9 a b c d e f + 00: -- -- -- -- -- -- -- -- -- -- -- -- + 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 50: 50 51 52 53 54 55 56 57 -- -- -- -- -- -- -- -- + 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 70: -- -- -- -- -- -- -- -- + 8 devices found on smbus@fb00 diff --git a/samples/drivers/smbus/boards/qemu_x86_64.conf b/samples/drivers/smbus/boards/qemu_x86_64.conf new file mode 100644 index 000000000000..844c7c51a6f8 --- /dev/null +++ b/samples/drivers/smbus/boards/qemu_x86_64.conf @@ -0,0 +1,3 @@ +CONFIG_DYNAMIC_INTERRUPTS=y + +CONFIG_PCIE=y diff --git a/samples/drivers/smbus/prj.conf b/samples/drivers/smbus/prj.conf new file mode 100644 index 000000000000..a02baae7ec92 --- /dev/null +++ b/samples/drivers/smbus/prj.conf @@ -0,0 +1,10 @@ +CONFIG_SMBUS=y +CONFIG_SMBUS_INTEL_PCH=y +CONFIG_SMBUS_LOG_LEVEL_DBG=y +CONFIG_USERSPACE=y +CONFIG_SHELL=y +CONFIG_LOG=y + +CONFIG_EEPROM=y +CONFIG_EEPROM_EMULATOR=n +CONFIG_EEPROM_SIMULATOR=n diff --git a/samples/drivers/smbus/qemu_x86_64.overlay b/samples/drivers/smbus/qemu_x86_64.overlay new file mode 100644 index 000000000000..408695b795f2 --- /dev/null +++ b/samples/drivers/smbus/qemu_x86_64.overlay @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +&smbus0 { + eeprom2: smbus_eeprom@50 { + compatible = "jedec,smbus-eeprom"; + reg = <0x50>; + size = <0x100>; + + status = "okay"; + }; +}; diff --git a/samples/drivers/smbus/sample.yaml b/samples/drivers/smbus/sample.yaml new file mode 100644 index 000000000000..b129ddae4156 --- /dev/null +++ b/samples/drivers/smbus/sample.yaml @@ -0,0 +1,13 @@ +sample: + description: SMBus sample + name: smbus sample +common: + platform_allow: qemu_x86_64 ehl_crb rpl_crb + harness: console + harness_config: + type: one_line + regex: + - "Start SMBUS shell sample" +tests: + sample.drivers.smbus.shell: + tags: smbus diff --git a/samples/drivers/smbus/src/main.c b/samples/drivers/smbus/src/main.c new file mode 100644 index 000000000000..8a8f48a4d137 --- /dev/null +++ b/samples/drivers/smbus/src/main.c @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +void main(void) +{ + printk("Start SMBUS shell sample %s\n", CONFIG_BOARD); +} From a242e572ce4b1935a7cf07e2f7882025b3d3212a Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Fri, 9 Sep 2022 17:48:31 +0300 Subject: [PATCH 0649/1906] tests: drivers: Add tests for Intel PCH SMBus driver Add test testing Intel PCH SMBus driver using Qemu x86_64 with machine q35 SMBus controller emulation and default "eeprom"-like peripheral. Signed-off-by: Andrei Emeltchenko --- tests/drivers/smbus/smbus_api/CMakeLists.txt | 13 ++ .../smbus/smbus_api/boards/qemu_x86_64.conf | 3 + tests/drivers/smbus/smbus_api/prj.conf | 5 + .../drivers/smbus/smbus_api/src/test_smbus.c | 111 +++++++++++++ .../smbus/smbus_api/src/test_smbus_qemu.c | 148 ++++++++++++++++++ tests/drivers/smbus/smbus_api/testcase.yaml | 22 +++ 6 files changed, 302 insertions(+) create mode 100644 tests/drivers/smbus/smbus_api/CMakeLists.txt create mode 100644 tests/drivers/smbus/smbus_api/boards/qemu_x86_64.conf create mode 100644 tests/drivers/smbus/smbus_api/prj.conf create mode 100644 tests/drivers/smbus/smbus_api/src/test_smbus.c create mode 100644 tests/drivers/smbus/smbus_api/src/test_smbus_qemu.c create mode 100644 tests/drivers/smbus/smbus_api/testcase.yaml diff --git a/tests/drivers/smbus/smbus_api/CMakeLists.txt b/tests/drivers/smbus/smbus_api/CMakeLists.txt new file mode 100644 index 000000000000..80e2b78c3627 --- /dev/null +++ b/tests/drivers/smbus/smbus_api/CMakeLists.txt @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +if(BOARD STREQUAL qemu_x86_64) + LIST(APPEND QEMU_EXTRA_FLAGS -machine q35) +endif() + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(smbus_api) + +target_sources(app PRIVATE src/test_smbus.c) +target_sources_ifdef(CONFIG_BOARD_QEMU_X86_64 app PRIVATE src/test_smbus_qemu.c) diff --git a/tests/drivers/smbus/smbus_api/boards/qemu_x86_64.conf b/tests/drivers/smbus/smbus_api/boards/qemu_x86_64.conf new file mode 100644 index 000000000000..844c7c51a6f8 --- /dev/null +++ b/tests/drivers/smbus/smbus_api/boards/qemu_x86_64.conf @@ -0,0 +1,3 @@ +CONFIG_DYNAMIC_INTERRUPTS=y + +CONFIG_PCIE=y diff --git a/tests/drivers/smbus/smbus_api/prj.conf b/tests/drivers/smbus/smbus_api/prj.conf new file mode 100644 index 000000000000..5dc81c75693a --- /dev/null +++ b/tests/drivers/smbus/smbus_api/prj.conf @@ -0,0 +1,5 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y + +CONFIG_SMBUS=y +CONFIG_SMBUS_INTEL_PCH=y diff --git a/tests/drivers/smbus/smbus_api/src/test_smbus.c b/tests/drivers/smbus/smbus_api/src/test_smbus.c new file mode 100644 index 000000000000..74b3d27250db --- /dev/null +++ b/tests/drivers/smbus/smbus_api/src/test_smbus.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * Verify SMBUS Basic API, tests should work on any board + */ + +#include +#include +#include +#include + +BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(smbus0), okay), + "SMBus node is disabled!"); + +#define FAKE_ADDRESS 0x10 + +/** + * The test is run in userspace only if CONFIG_USERSPACE option is + * enabled, otherwise it is the same as ZTEST() + */ +ZTEST_USER(test_smbus_general, test_smbus_basic_api) +{ + const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(smbus0)); + uint32_t cfg = SMBUS_MODE_CONTROLLER; + uint32_t cfg_tmp; + int ret; + + zassert_true(device_is_ready(dev), "Device is not ready"); + + ret = smbus_configure(dev, cfg); + zassert_ok(ret, "SMBUS config failed"); + + ret = smbus_get_config(dev, &cfg_tmp); + zassert_ok(ret, "SMBUS get_config failed"); + + zassert_equal(cfg, cfg_tmp, "get_config returned invalid config"); +} + +/** + * The test is run in userspace only if CONFIG_USERSPACE option is + * enabled, otherwise it is the same as ZTEST() + */ +ZTEST_USER(test_smbus_general, test_smbus_callback_api) +{ + const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(smbus0)); + void *dummy; /* For the dummy function pointer use this */ + int ret; + + /* Note! Only for test using stack variables to ease userspace tests */ + struct smbus_callback callback = { + .handler = (void *)&dummy, + .addr = FAKE_ADDRESS, + }; + + zassert_true(device_is_ready(dev), "Device is not ready"); + + /* Try to remove not existing callback */ + ret = smbus_manage_smbalert_cb(dev, &callback, false); + zassert_equal(ret, -ENOENT, "Callback remove failed"); + + /* Set callback */ + ret = smbus_manage_smbalert_cb(dev, &callback, true); + zassert_ok(ret, "Callback set failed"); + + /* Remove existing callback */ + ret = smbus_manage_smbalert_cb(dev, &callback, false); + zassert_ok(ret, "Callback remove failed"); +} + +/** + * The test is run in userspace only if CONFIG_USERSPACE option is + * enabled, otherwise it is the same as ZTEST() + */ +ZTEST_USER(test_smbus_general, test_smbus_api_errors) +{ + const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(smbus0)); + uint8_t fake_addr = 0x10; + uint8_t buf[2]; + int ret; + + zassert_true(device_is_ready(dev), "Device is not ready"); + + /* Test parsing SMBus quick */ + ret = smbus_quick(dev, fake_addr, 3); + zassert_equal(ret, -EINVAL, "Wrong parameter check failed"); + + /* Test parsing SMBus block_write */ + ret = smbus_block_write(dev, fake_addr, 0, 0, buf); + zassert_equal(ret, -EINVAL, "Wrong parameter check failed"); + ret = smbus_block_write(dev, fake_addr, 0, SMBUS_BLOCK_BYTES_MAX + 1, + buf); + zassert_equal(ret, -EINVAL, "Wrong parameter check failed"); +} + +/* Setup is needed for userspace access */ +static void *smbus_test_setup(void) +{ + const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(smbus0)); + + zassert_true(device_is_ready(dev), "Device is not ready"); + + k_object_access_grant(dev, k_current_get()); + + return NULL; +} + +ZTEST_SUITE(test_smbus_general, NULL, smbus_test_setup, NULL, NULL, NULL); diff --git a/tests/drivers/smbus/smbus_api/src/test_smbus_qemu.c b/tests/drivers/smbus/smbus_api/src/test_smbus_qemu.c new file mode 100644 index 000000000000..74d8ba4408e2 --- /dev/null +++ b/tests/drivers/smbus/smbus_api/src/test_smbus_qemu.c @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * @addtogroup t_smbus_basic + * @{ + * @defgroup t_smbus + * @brief TestPurpose: verify SMBUS can read and write + * @} + */ + +#include +#include +#include + +BUILD_ASSERT(DT_NODE_HAS_STATUS(DT_NODELABEL(smbus0), okay), + "SMBus node is disabled!"); + +/* Qemu q35 has default emulated EEPROM-like devices */ +#define QEMU_SMBUS_EEPROM_ADDR 0x50 +#define QEMU_SMBUS_EEPROM_SIZE 256 + +/** + * The test is run in userspace only if CONFIG_USERSPACE option is + * enabled, otherwise it is the same as ZTEST() + */ +ZTEST_USER(test_smbus_qemu, test_smbus_api_read_write) +{ + int ret; + + const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(smbus0)); + + zassert_true(device_is_ready(dev), "Device is not ready"); + + /* Test SMBus quick */ + ret = smbus_quick(dev, QEMU_SMBUS_EEPROM_ADDR, SMBUS_MSG_WRITE); + zassert_ok(ret, "SMBUS Quick W failed, ret %d", ret); + + ret = smbus_quick(dev, QEMU_SMBUS_EEPROM_ADDR, SMBUS_MSG_READ); + zassert_ok(ret, "SMBUS Quick R failed, ret %d", ret); + + /* Test SMBus Read / Write Byte Data */ + for (uint16_t addr = 0; addr < QEMU_SMBUS_EEPROM_SIZE; addr++) { + /* Randomize buffer */ + uint8_t send_byte = (uint8_t)addr; + uint8_t recv_byte; + + ret = smbus_byte_data_write(dev, QEMU_SMBUS_EEPROM_ADDR, addr, + send_byte); + zassert_ok(ret, "SMBUS write byte data failed, ret %d", ret); + + ret = smbus_byte_data_read(dev, QEMU_SMBUS_EEPROM_ADDR, addr, + &recv_byte); + zassert_ok(ret, "SMBUS read byte data failed, ret %d", ret); + + zassert_equal(send_byte, recv_byte, "SMBUS data compare fail"); + } + + /* Test SMBus Read / Write Word Data */ + for (uint16_t addr = 0; addr < QEMU_SMBUS_EEPROM_SIZE; addr += 2) { + uint16_t send_word = addr; + uint16_t recv_word; + + ret = smbus_word_data_write(dev, QEMU_SMBUS_EEPROM_ADDR, addr, + send_word); + zassert_ok(ret, "SMBUS write word data failed, ret %d", ret); + + ret = smbus_word_data_read(dev, QEMU_SMBUS_EEPROM_ADDR, addr, + &recv_word); + zassert_ok(ret, "SMBUS read word data failed, ret %d", ret); + + zassert_equal(send_word, recv_word, "SMBUS data compare fail"); + } + + /* Test SMBus Read / Write Byte on special Qemu SMBus peripheral */ + for (uint16_t addr = 0; addr < QEMU_SMBUS_EEPROM_SIZE; addr++) { + /* Randomize buffer */ + uint8_t send_byte = (uint8_t)addr; + uint8_t recv_byte; + + /* Write byte data to EEPROM device */ + ret = smbus_byte_data_write(dev, QEMU_SMBUS_EEPROM_ADDR, addr, + send_byte); + zassert_ok(ret, "SMBUS write byte data failed, ret %d", ret); + + /** + * Reading is done through executing two consequitive + * operations: write, which sets offset, followed by read, which + * reads data from given offset + */ + + ret = smbus_byte_write(dev, QEMU_SMBUS_EEPROM_ADDR, addr); + zassert_ok(ret, "SMBUS write byte failed, ret %d", ret); + + ret = smbus_byte_read(dev, QEMU_SMBUS_EEPROM_ADDR, &recv_byte); + zassert_ok(ret, "SMBUS read byte failed, ret %d", ret); + zassert_equal(send_byte, recv_byte, "SMBUS data compare fail"); + } + + /** + * The Qemu SMBus implementation does not always correctly + * emulate SMBus Block protocol, however it is good enough + * to test Block Write followed by Block Read + */ + + /* Test SMBus Block Write / Block Read */ + for (uint16_t addr = 0; addr < QEMU_SMBUS_EEPROM_SIZE; + addr += SMBUS_BLOCK_BYTES_MAX) { + uint8_t send_block[SMBUS_BLOCK_BYTES_MAX]; + uint8_t recv_block[SMBUS_BLOCK_BYTES_MAX]; + uint8_t count; + + /* Poor man randomize ;) */ + for (int i = 0; i < sizeof(send_block); i++) { + send_block[i] = addr + i; + } + ret = smbus_block_write(dev, QEMU_SMBUS_EEPROM_ADDR, addr, + sizeof(send_block), send_block); + zassert_ok(ret, "SMBUS write block failed, ret %d", ret); + + ret = smbus_block_read(dev, QEMU_SMBUS_EEPROM_ADDR, addr, + &count, recv_block); + zassert_ok(ret, "SMBUS read block failed, ret %d", ret); + + zassert_equal(count, SMBUS_BLOCK_BYTES_MAX, + "Read wrong %d of bytes", count); + + zassert_true(!memcmp(send_block, recv_block, count), + "Read / Write data differs"); + } +} + +/* Setup is needed for userspace access */ +static void *smbus_test_setup(void) +{ + const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(smbus0)); + + zassert_true(device_is_ready(dev), "Device is not ready"); + + k_object_access_grant(dev, k_current_get()); + + return NULL; +} + +ZTEST_SUITE(test_smbus_qemu, NULL, smbus_test_setup, NULL, NULL, NULL); diff --git a/tests/drivers/smbus/smbus_api/testcase.yaml b/tests/drivers/smbus/smbus_api/testcase.yaml new file mode 100644 index 000000000000..6c7fb8712050 --- /dev/null +++ b/tests/drivers/smbus/smbus_api/testcase.yaml @@ -0,0 +1,22 @@ +common: + platform_allow: ehl_crb rpl_crb + tags: smbus +tests: + drivers.smbus.api: + platform_allow: qemu_x86_64 + drivers.smbus.api.access.mmio: + platform_exclude: qemu_x86_64 + extra_configs: + - CONFIG_SMBUS_INTEL_PCH_ACCESS_MMIO=y + drivers.smbus.api_user: + platform_allow: qemu_x86_64 + extra_configs: + - CONFIG_USERSPACE=y + drivers.smbus.api_stats: + platform_allow: qemu_x86_64 + extra_configs: + - CONFIG_STATS=y + drivers.smbus.api.debug: + platform_allow: qemu_x86_64 + extra_configs: + - CONFIG_SMBUS_LOG_LEVEL_DBG=y From a35c889687134cbfd0a030d4697da9f1b82e41df Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Thu, 29 Sep 2022 16:20:34 +0300 Subject: [PATCH 0650/1906] tests: smbus: Add SMBus unit tests Add SMBus unit tests which emulate SMBus controller and connected test peripheral device. This allows to test also rare SMBus protocols like Process Call and Block Process Call. Signed-off-by: Andrei Emeltchenko --- tests/drivers/smbus/smbus_emul/CMakeLists.txt | 10 + tests/drivers/smbus/smbus_emul/README.rst | 8 + tests/drivers/smbus/smbus_emul/prj.conf | 4 + tests/drivers/smbus/smbus_emul/src/emul.c | 451 ++++++++++++++++++ tests/drivers/smbus/smbus_emul/src/emul.h | 44 ++ tests/drivers/smbus/smbus_emul/src/smbus.c | 383 +++++++++++++++ tests/drivers/smbus/smbus_emul/testcase.yaml | 8 + 7 files changed, 908 insertions(+) create mode 100644 tests/drivers/smbus/smbus_emul/CMakeLists.txt create mode 100644 tests/drivers/smbus/smbus_emul/README.rst create mode 100644 tests/drivers/smbus/smbus_emul/prj.conf create mode 100644 tests/drivers/smbus/smbus_emul/src/emul.c create mode 100644 tests/drivers/smbus/smbus_emul/src/emul.h create mode 100644 tests/drivers/smbus/smbus_emul/src/smbus.c create mode 100644 tests/drivers/smbus/smbus_emul/testcase.yaml diff --git a/tests/drivers/smbus/smbus_emul/CMakeLists.txt b/tests/drivers/smbus/smbus_emul/CMakeLists.txt new file mode 100644 index 000000000000..b52ef0c47298 --- /dev/null +++ b/tests/drivers/smbus/smbus_emul/CMakeLists.txt @@ -0,0 +1,10 @@ +#SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(test_smbus_emul) + +target_include_directories(app PRIVATE ${ZEPHYR_BASE}/drivers/smbus) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/drivers/smbus/smbus_emul/README.rst b/tests/drivers/smbus/smbus_emul/README.rst new file mode 100644 index 000000000000..f0ce42421db1 --- /dev/null +++ b/tests/drivers/smbus/smbus_emul/README.rst @@ -0,0 +1,8 @@ +.. _smbus_emul_tests: + +SMBUS unit tests +################ + +Unit tests emulate SMBus hardware controller and connected SMBus peripheral +device by redirecting I/O read / write to a memory buffer. This allows to +cover all SMBus protocol commands. diff --git a/tests/drivers/smbus/smbus_emul/prj.conf b/tests/drivers/smbus/smbus_emul/prj.conf new file mode 100644 index 000000000000..9dd20e849040 --- /dev/null +++ b/tests/drivers/smbus/smbus_emul/prj.conf @@ -0,0 +1,4 @@ +CONFIG_ZTEST=y +CONFIG_LOG=y +CONFIG_ZTEST_NEW_API=y +CONFIG_ENTROPY_GENERATOR=y diff --git a/tests/drivers/smbus/smbus_emul/src/emul.c b/tests/drivers/smbus/smbus_emul/src/emul.c new file mode 100644 index 000000000000..6ae27326bfb5 --- /dev/null +++ b/tests/drivers/smbus/smbus_emul/src/emul.c @@ -0,0 +1,451 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include + +#include + +#include +LOG_MODULE_REGISTER(emul, LOG_LEVEL_DBG); + +#include "emul.h" + +/** + * Emulate Intel PCH Host Controller hardware as PCI device with I/O access + */ + +/* PCI Configuration space */ +uint32_t pci_config_area[32] = { + [PCIE_CONF_CMDSTAT] = PCIE_CONF_CMDSTAT_INTERRUPT, /* Mark INT */ + [8] = 1, /* I/O BAR */ + [16] = 1, /* Enable SMBus */ +}; + +/* I/O and MMIO registers */ +uint8_t io_area[24] = { + 0, +}; + +struct e32_block { + uint8_t buf[SMBUS_BLOCK_BYTES_MAX]; + uint8_t offset; +} e32; + +/** + * Emulate SMBus peripheral device, connected to the bus as + * simple EEPROM device of size 256 bytes + */ + +/* List of peripheral devices registered */ +sys_slist_t peripherals; + +void emul_register_smbus_peripheral(struct smbus_peripheral *peripheral) +{ + sys_slist_prepend(&peripherals, &peripheral->node); +} + +static struct smbus_peripheral *emul_get_smbus_peripheral(uint8_t addr) +{ + struct smbus_peripheral *peripheral, *tmp; + + SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&peripherals, peripheral, tmp, node) { + if (peripheral->addr == addr) { + return peripheral; + } + } + + return NULL; +} + +static bool peripheral_handle_smbalert(void) +{ + struct smbus_peripheral *peripheral, *tmp, *found = NULL; + + SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&peripherals, peripheral, tmp, node) { + if (peripheral->smbalert && !peripheral->smbalert_handled) { + found = peripheral; + } + } + + if (found == NULL) { + LOG_WRN("No (more) smbalert handlers found"); + return false; + } + + LOG_DBG("Return own address: 0x%02x", found->addr); + + io_area[PCH_SMBUS_HD0] = found->addr; + found->smbalert_handled = true; + + return true; +} + +bool peripheral_handle_host_notify(void) +{ + struct smbus_peripheral *peripheral, *tmp; + + SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&peripherals, peripheral, tmp, node) { + if (peripheral->host_notify) { + LOG_DBG("Save own peripheral address to NDA"); + io_area[PCH_SMBUS_NDA] = peripheral->addr << 1; + + return true; + } + } + + return false; +} + +static void peripheral_write(uint8_t reg, uint8_t value) +{ + uint8_t addr = PCH_SMBUS_TSA_ADDR_GET(io_area[PCH_SMBUS_TSA]); + struct smbus_peripheral *peripheral; + + peripheral = emul_get_smbus_peripheral(addr); + if (peripheral) { + peripheral->raw_data[reg] = value; + LOG_DBG("peripheral: [0x%02x] <= 0x%02x", reg, value); + } else { + LOG_ERR("Peripheral not found, addr 0x%02x", addr); + } +} + +static void peripheral_read(uint8_t reg, uint8_t *value) +{ + uint8_t addr = PCH_SMBUS_TSA_ADDR_GET(io_area[PCH_SMBUS_TSA]); + struct smbus_peripheral *peripheral; + + peripheral = emul_get_smbus_peripheral(addr); + if (peripheral) { + *value = peripheral->raw_data[reg]; + LOG_DBG("peripheral: [0x%02x] => 0x%02x", reg, *value); + } else { + LOG_ERR("Peripheral not found, addr 0x%02x", addr); + } +} + +static void emul_start_smbus_protocol(void) +{ + uint8_t smbus_cmd = PCH_SMBUS_HCTL_CMD_GET(io_area[PCH_SMBUS_HCTL]); + bool write = + (io_area[PCH_SMBUS_TSA] & PCH_SMBUS_TSA_RW) == SMBUS_MSG_WRITE; + uint8_t addr = PCH_SMBUS_TSA_ADDR_GET(io_area[PCH_SMBUS_TSA]); + struct smbus_peripheral *peripheral; + + LOG_DBG("Start SMBUS protocol"); + + if (unlikely(addr == SMBUS_ADDRESS_ARA)) { + if (peripheral_handle_smbalert()) { + goto isr; + } + } + + peripheral = emul_get_smbus_peripheral(addr); + if (peripheral == NULL) { + LOG_WRN("Set Device Error"); + emul_set_io(emul_get_io(PCH_SMBUS_HSTS) | + PCH_SMBUS_HSTS_DEV_ERROR, PCH_SMBUS_HSTS); + goto isr; + } + + switch (smbus_cmd) { + case PCH_SMBUS_HCTL_CMD_QUICK: + LOG_DBG("Quick command"); + break; + case PCH_SMBUS_HCTL_CMD_BYTE: + if (write) { + LOG_DBG("Byte Write command"); + peripheral_write(0, io_area[PCH_SMBUS_HCMD]); + } else { + LOG_DBG("Byte Read command"); + peripheral_read(0, &io_area[PCH_SMBUS_HD0]); + } + break; + case PCH_SMBUS_HCTL_CMD_BYTE_DATA: + if (write) { + LOG_DBG("Byte Data Write command"); + peripheral_write(io_area[PCH_SMBUS_HCMD], + io_area[PCH_SMBUS_HD0]); + } else { + LOG_DBG("Byte Data Read command"); + peripheral_read(io_area[PCH_SMBUS_HCMD], + &io_area[PCH_SMBUS_HD0]); + } + break; + case PCH_SMBUS_HCTL_CMD_WORD_DATA: + if (write) { + LOG_DBG("Word Data Write command"); + peripheral_write(io_area[PCH_SMBUS_HCMD], + io_area[PCH_SMBUS_HD0]); + peripheral_write(io_area[PCH_SMBUS_HCMD] + 1, + io_area[PCH_SMBUS_HD1]); + + } else { + LOG_DBG("Word Data Read command"); + peripheral_read(io_area[PCH_SMBUS_HCMD], + &io_area[PCH_SMBUS_HD0]); + peripheral_read(io_area[PCH_SMBUS_HCMD] + 1, + &io_area[PCH_SMBUS_HD1]); + } + break; + case PCH_SMBUS_HCTL_CMD_PROC_CALL: + if (!write) { + LOG_ERR("Incorrect operation flag"); + return; + } + + LOG_DBG("Process Call command"); + + peripheral_write(io_area[PCH_SMBUS_HCMD], + io_area[PCH_SMBUS_HD0]); + peripheral_write(io_area[PCH_SMBUS_HCMD] + 1, + io_area[PCH_SMBUS_HD1]); + + /** + * For the testing purposes implement data + * swap for the Proc Call, that would be + * easy for testing. + * + * Note: real device should have some other + * logic for Proc Call. + */ + peripheral_read(io_area[PCH_SMBUS_HCMD], + &io_area[PCH_SMBUS_HD1]); + peripheral_read(io_area[PCH_SMBUS_HCMD] + 1, + &io_area[PCH_SMBUS_HD0]); + break; + case PCH_SMBUS_HCTL_CMD_BLOCK: + if (write) { + uint8_t count = io_area[PCH_SMBUS_HD0]; + uint8_t reg = io_area[PCH_SMBUS_HCMD]; + + LOG_DBG("Block Write command"); + + if (count > SMBUS_BLOCK_BYTES_MAX) { + return; + } + + for (int i = 0; i < count; i++) { + peripheral_write(reg++, e32.buf[i]); + } + } else { + /** + * count is set by peripheral device, just + * assume it to be maximum block count + */ + uint8_t count = SMBUS_BLOCK_BYTES_MAX; + uint8_t reg = io_area[PCH_SMBUS_HCMD]; + + LOG_DBG("Block Read command"); + + for (int i = 0; i < count; i++) { + peripheral_read(reg++, &e32.buf[i]); + } + + /* Set count */ + io_area[PCH_SMBUS_HD0] = count; + } + break; + case PCH_SMBUS_HCTL_CMD_BLOCK_PROC: + if (!write) { + LOG_ERR("Incorrect operation flag"); + } else { + uint8_t snd_count = io_area[PCH_SMBUS_HD0]; + uint8_t reg = io_area[PCH_SMBUS_HCMD]; + uint8_t rcv_count; + + LOG_DBG("Block Process Call command"); + + if (snd_count > SMBUS_BLOCK_BYTES_MAX) { + return; + } + + /** + * Make Block Process Call swap block buffer bytes + * for testing purposes only, return the same "count" + * bytes + */ + for (int i = 0; i < snd_count; i++) { + peripheral_write(reg++, e32.buf[i]); + } + + rcv_count = snd_count; + if (snd_count + rcv_count > SMBUS_BLOCK_BYTES_MAX) { + return; + } + + for (int i = 0; i < rcv_count; i++) { + peripheral_read(--reg, &e32.buf[i]); + } + + /* Clear offset count */ + e32.offset = 0; + + /* Set count */ + io_area[PCH_SMBUS_HD0] = rcv_count; + } + break; + default: + LOG_ERR("Protocol is not implemented yet in emul"); + break; + } + +isr: + if (io_area[PCH_SMBUS_HCTL] & PCH_SMBUS_HCTL_INTR_EN) { + /* Fire emulated interrupt if enabled */ + run_isr(EMUL_SMBUS_INTR); + } +} + +static void emul_evaluate_write(uint8_t value, io_port_t addr) +{ + switch (addr) { + case PCH_SMBUS_HCTL: + if (value & PCH_SMBUS_HCTL_START) { + /* This is write only */ + io_area[PCH_SMBUS_HCTL] = value & ~PCH_SMBUS_HCTL_START; + + emul_start_smbus_protocol(); + } + break; + default: + break; + } +} + +static const char *pch_get_reg_name(uint8_t reg) +{ + switch (reg) { + case PCH_SMBUS_HSTS: + return "HSTS"; + case PCH_SMBUS_HCTL: + return "HCTL"; + case PCH_SMBUS_HCMD: + return "HCMD"; + case PCH_SMBUS_TSA: + return "TSA"; + case PCH_SMBUS_HD0: + return "HD0"; + case PCH_SMBUS_HD1: + return "HD1"; + case PCH_SMBUS_HBD: + return "HBD"; + case PCH_SMBUS_PEC: + return "PEC"; + case PCH_SMBUS_RSA: + return "RSA"; + case PCH_SMBUS_SD: + return "SD"; + case PCH_SMBUS_AUXS: + return "AUXS"; + case PCH_SMBUS_AUXC: + return "AUXC"; + case PCH_SMBUS_SMLC: + return "SMLC"; + case PCH_SMBUS_SMBC: + return "SMBC"; + case PCH_SMBUS_SSTS: + return "SSTS"; + case PCH_SMBUS_SCMD: + return "SCMD"; + case PCH_SMBUS_NDA: + return "NDA"; + case PCH_SMBUS_NDLB: + return "NDLB"; + case PCH_SMBUS_NDHB: + return "NDHB"; + default: + return "Unknown"; + } +} + +uint32_t emul_pci_read(unsigned int reg) +{ + LOG_DBG("PCI [%x] => 0x%x", reg, pci_config_area[reg]); + return pci_config_area[reg]; +} + +void emul_pci_write(pcie_bdf_t bdf, unsigned int reg, uint32_t value) +{ + LOG_DBG("PCI [%x] <= 0x%x", reg, value); + pci_config_area[reg] = value; +} + +/* This function is used to set registers for emulation purpose */ +void emul_set_io(uint8_t value, io_port_t addr) +{ + io_area[addr] = value; +} + +uint8_t emul_get_io(io_port_t addr) +{ + return io_area[addr]; +} + +void emul_out8(uint8_t value, io_port_t addr) +{ + switch (addr) { + case PCH_SMBUS_HSTS: + /* Writing clears status bits */ + io_area[addr] &= ~value; + break; + case PCH_SMBUS_SSTS: + /* Writing clears status bits */ + io_area[addr] &= ~value; + break; + case PCH_SMBUS_HBD: + /* Using internal E32 buffer offset */ + e32.buf[e32.offset++] = value; + break; + case PCH_SMBUS_AUXC: + if (value & PCH_SMBUS_AUXC_EN_32BUF) { + LOG_DBG("Enabled 32 bit buffer block mode"); + } + io_area[addr] = value; + break; + default: + io_area[addr] = value; + break; + } + + LOG_DBG("I/O [%s] <= 0x%x => 0x%x", pch_get_reg_name(addr), value, + io_area[addr]); + + /** + * Evaluate should decide about starting actual SMBus + * protocol transaction emulation + */ + emul_evaluate_write(value, addr); +} + +uint8_t emul_in8(io_port_t addr) +{ + uint8_t value; + + switch (addr) { + case PCH_SMBUS_HBD: + /* Using internal E32 buffer offset */ + value = e32.buf[e32.offset++]; + break; + case PCH_SMBUS_HCTL: + /* Clear e32 block buffer offset */ + e32.offset = 0; + LOG_WRN("E32 buffer offset is cleared"); + value = io_area[addr]; + break; + default: + value = io_area[addr]; + break; + } + + LOG_DBG("I/O [%s] => 0x%x", pch_get_reg_name(addr), value); + + return value; +} diff --git a/tests/drivers/smbus/smbus_emul/src/emul.h b/tests/drivers/smbus/smbus_emul/src/emul.h new file mode 100644 index 000000000000..520d81c6dca1 --- /dev/null +++ b/tests/drivers/smbus/smbus_emul/src/emul.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* Read from PCI configuration space */ +uint32_t emul_pci_read(unsigned int reg); + +/* Write to PCI configuration space */ +void emul_pci_write(pcie_bdf_t bdf, unsigned int reg, uint32_t value); + +void emul_out8(uint8_t data, io_port_t addr); +uint8_t emul_in8(io_port_t addr); + +void emul_set_io(uint8_t value, io_port_t addr); +uint8_t emul_get_io(io_port_t addr); + +enum emul_isr_type { + EMUL_SMBUS_INTR, + EMUL_SMBUS_SMBALERT, + EMUL_SMBUS_HOST_NOTIFY, +}; + +void run_isr(enum emul_isr_type); + +struct smbus_peripheral { + sys_snode_t node; + uint8_t raw_data[256]; + uint8_t offset; + uint8_t addr; + bool smbalert; + bool smbalert_handled; + bool host_notify; +}; + +bool peripheral_handle_host_notify(void); + +static inline void peripheral_clear_smbalert(struct smbus_peripheral *periph) +{ + periph->smbalert_handled = false; +} + +void emul_register_smbus_peripheral(struct smbus_peripheral *peripheral); diff --git a/tests/drivers/smbus/smbus_emul/src/smbus.c b/tests/drivers/smbus/smbus_emul/src/smbus.c new file mode 100644 index 000000000000..4c62a1a9c551 --- /dev/null +++ b/tests/drivers/smbus/smbus_emul/src/smbus.c @@ -0,0 +1,383 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#include +#include + +#include "emul.h" + +#define CONFIG_SMBUS_LOG_LEVEL LOG_LEVEL_DBG + +#define PERIPH_ADDR 0x10 + +static uint8_t mock_sys_in8(io_port_t port) +{ + return emul_in8(port); +} + +static void mock_sys_out8(uint8_t data, io_port_t port) +{ + emul_out8(data, port); +} + +static uint32_t mock_conf_read(pcie_bdf_t bdf, unsigned int reg) +{ + return emul_pci_read(reg); +} + +#if defined(PCIE_CONF_WRITE) +static void mock_conf_write(pcie_bdf_t bdf, unsigned int reg, uint32_t data) +{ + emul_pci_write(bdf, reg, data); +} + +#define pcie_conf_write(bdf, reg, val) mock_conf_write(bdf, reg, val) +#endif /* PCIE_CONF_WRITE */ + +/* Redefine PCIE access */ +#define pcie_conf_read(bdf, reg) mock_conf_read(bdf, reg) + +/* Redefine sys_in function */ +#define sys_in8(port) mock_sys_in8(port) +#define sys_out8(data, port) mock_sys_out8(data, port) + +#define CONFIG_SMBUS_INTEL_PCH_ACCESS_IO +#define device_map(a, b, c, d) +#define pcie_probe(bdf, id) 1 +#define pcie_set_cmd(a, b, c) + +#define SMBUS_EMUL "smbus_emul" + +#ifdef PERIPHERAL_INT +#define CONFIG_SMBUS_INTEL_PCH_SMBALERT 1 +#define CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY 1 +#endif + +#include "intel_pch_smbus.c" + +void run_isr(enum emul_isr_type type) +{ + const struct device *const dev = device_get_binding(SMBUS_EMUL); + + switch (type) { + case EMUL_SMBUS_INTR: + emul_set_io(emul_get_io(PCH_SMBUS_HSTS) | + PCH_SMBUS_HSTS_INTERRUPT, PCH_SMBUS_HSTS); + break; + case EMUL_SMBUS_SMBALERT: + emul_set_io(emul_get_io(PCH_SMBUS_HSTS) | + PCH_SMBUS_HSTS_SMB_ALERT, PCH_SMBUS_HSTS); + break; + case EMUL_SMBUS_HOST_NOTIFY: + emul_set_io(emul_get_io(PCH_SMBUS_SSTS)| + PCH_SMBUS_SSTS_HNS, PCH_SMBUS_SSTS); + peripheral_handle_host_notify(); + break; + default: + break; + } + + smbus_isr(dev); +} + +static void config_function(const struct device *dev) +{ + TC_PRINT("Emulator device configuration\n"); +} +static struct pch_data smbus_data; +static struct pch_config pch_config_data = { + .config_func = config_function, +}; +DEVICE_DEFINE(dummy_driver, SMBUS_EMUL, &pch_smbus_init, + NULL, &smbus_data, &pch_config_data, APPLICATION, + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &funcs); + +ZTEST(test_smbus_emul, test_byte) +{ + const struct device *const dev = device_get_binding(SMBUS_EMUL); + uint8_t snd_byte, rcv_byte; + int ret; + + zassert_not_null(dev, "Device not found"); + + ret = smbus_quick(dev, PERIPH_ADDR, 1); + zassert_ok(ret, "SMBus Quick failed"); + + snd_byte = (uint8_t)sys_rand32_get(); + + ret = smbus_byte_write(dev, PERIPH_ADDR, snd_byte); + zassert_ok(ret, "SMBus Byte Write failed"); + + ret = smbus_byte_read(dev, PERIPH_ADDR, &rcv_byte); + zassert_ok(ret, "SMBus Byte Read failed"); + + zassert_equal(snd_byte, rcv_byte, "Data mismatch"); + + ret = smbus_byte_data_write(dev, PERIPH_ADDR, 0, snd_byte); + zassert_ok(ret, "SMBus Byte Data Write failed"); + + ret = smbus_byte_data_read(dev, PERIPH_ADDR, 0, &rcv_byte); + zassert_ok(ret, "SMBus Byte Data Read failed"); + + zassert_equal(snd_byte, rcv_byte, "Data mismatch"); +} + +ZTEST(test_smbus_emul, test_word) +{ + const struct device *const dev = device_get_binding(SMBUS_EMUL); + uint16_t snd_word, rcv_word; + uint8_t snd_byte; + int ret; + + zassert_not_null(dev, "Device not found"); + + snd_word = (uint16_t)sys_rand32_get(); + + ret = smbus_word_data_write(dev, PERIPH_ADDR, 0, snd_word); + zassert_ok(ret, "SMBus Word Data Write failed"); + + ret = smbus_word_data_read(dev, PERIPH_ADDR, 0, &rcv_word); + zassert_ok(ret, "SMBus Byte Data Read failed"); + + zassert_equal(snd_word, rcv_word, "Data mismatch"); + + /* Test 2 byte writes following word read */ + + snd_byte = (uint8_t)sys_rand32_get(); + + ret = smbus_byte_data_write(dev, PERIPH_ADDR, 0, snd_byte); + zassert_ok(ret, "SMBus Byte Data Write failed"); + ret = smbus_byte_data_write(dev, PERIPH_ADDR, 1, snd_byte); + zassert_ok(ret, "SMBus Byte Data Write failed"); + + ret = smbus_word_data_read(dev, PERIPH_ADDR, 0, &rcv_word); + zassert_ok(ret, "SMBus Byte Data Read failed"); + + zassert_equal(snd_byte << 8 | snd_byte, rcv_word, "Data mismatch"); +} + +ZTEST(test_smbus_emul, test_proc_call) +{ + const struct device *const dev = device_get_binding(SMBUS_EMUL); + uint16_t snd_word, rcv_word; + int ret; + + zassert_not_null(dev, "Device not found"); + + snd_word = (uint16_t)sys_rand32_get(); + zassert_not_equal(snd_word, 0, "Random number generator misconfgured"); + + ret = smbus_pcall(dev, PERIPH_ADDR, 0x0, snd_word, &rcv_word); + zassert_ok(ret, "SMBus Proc Call failed"); + + /* Our emulated Proc Call swaps bytes */ + zassert_equal(snd_word, __bswap_16(rcv_word), "Data mismatch"); +} + +ZTEST(test_smbus_emul, test_block) +{ + const struct device *const dev = device_get_binding(SMBUS_EMUL); + uint8_t snd_block[SMBUS_BLOCK_BYTES_MAX]; + uint8_t rcv_block[SMBUS_BLOCK_BYTES_MAX]; + uint8_t snd_count, rcv_count; + int ret; + + zassert_not_null(dev, "Device not found"); + + for (int i = 0; i < sizeof(snd_block); i++) { + snd_block[i] = (uint8_t)sys_rand32_get(); + } + + snd_count = sizeof(snd_block); + + ret = smbus_block_write(dev, PERIPH_ADDR, 0, snd_count, snd_block); + zassert_ok(ret, "SMBUS write block failed, ret %d", ret); + + ret = smbus_block_read(dev, PERIPH_ADDR, 0, &rcv_count, rcv_block); + zassert_ok(ret, "SMBUS read block failed, ret %d", ret); + + zassert_equal(snd_count, rcv_count, "Block count differs"); + zassert_true(!memcmp(snd_block, rcv_block, rcv_count), + "Data mismatch"); +} + +ZTEST(test_smbus_emul, test_block_pcall) +{ + const struct device *const dev = device_get_binding(SMBUS_EMUL); + uint8_t snd_block[SMBUS_BLOCK_BYTES_MAX]; + uint8_t rcv_block[SMBUS_BLOCK_BYTES_MAX]; + uint8_t snd_count, rcv_count; + int ret; + + zassert_not_null(dev, "Device not found"); + + for (int i = 0; i < sizeof(snd_block); i++) { + snd_block[i] = (uint8_t)sys_rand32_get(); + } + + snd_count = SMBUS_BLOCK_BYTES_MAX / 2; + ret = smbus_block_pcall(dev, PERIPH_ADDR, 0, snd_count, snd_block, + &rcv_count, rcv_block); + zassert_ok(ret, "SMBUS block pcall failed, ret %d", ret); + zassert_equal(snd_count, rcv_count, "Block count differs"); + + /** + * Verify that our emulated peripheral swapped bytes in the block + * buffer + */ + for (int i = 0; i < rcv_count; i++) { + zassert_equal(snd_block[i], rcv_block[rcv_count - (i + 1)], + "Data mismatch, not swapped"); + + } +} + +/* SMBALERT handling */ + +/* False by default */ +bool smbalert_handled; + +static void smbalert_cb(const struct device *dev, struct smbus_callback *cb, + uint8_t addr) +{ + LOG_DBG("SMBALERT callback"); + + smbalert_handled = true; +} + +struct smbus_callback smbalert_callback = { + .handler = smbalert_cb, + .addr = PERIPH_ADDR, +}; + +/* Host Notify handling */ + +/* False by default */ +bool notify_handled; + +static void notify_cb(const struct device *dev, struct smbus_callback *cb, + uint8_t addr) +{ + LOG_DBG("Notify callback"); + + notify_handled = true; +} + +struct smbus_callback notify_callback = { + .handler = notify_cb, + .addr = PERIPH_ADDR, +}; + +/* Setup peripheral SMBus device on a bus */ + +struct smbus_peripheral peripheral = { + .addr = PERIPH_ADDR, + .smbalert = true, + .host_notify = true, +}; + +ZTEST(test_smbus_emul, test_alert) +{ + const struct device *const dev = device_get_binding(SMBUS_EMUL); + int ret; + + Z_TEST_SKIP_IFNDEF(CONFIG_SMBUS_INTEL_PCH_SMBALERT); + + zassert_not_null(dev, "Device not found"); + + /* Try to remove not existing callback */ + ret = smbus_manage_smbalert_cb(dev, &smbalert_callback, false); + zassert_equal(ret, -ENOENT, "Callback remove failed"); + + /* Set callback */ + ret = smbus_manage_smbalert_cb(dev, &smbalert_callback, true); + zassert_ok(ret, "Callback set failed"); + + /* Emulate SMBus alert from peripheral device */ + peripheral_clear_smbalert(&peripheral); + smbalert_handled = false; + + /* Run without configure smbalert */ + run_isr(EMUL_SMBUS_SMBALERT); + + /* Wait for delayed work handled */ + k_sleep(K_MSEC(100)); + + /* Verify that smbalert is NOT handled */ + zassert_false(smbalert_handled, "smbalert is not handled"); + + /* Now enable smbalert */ + ret = smbus_configure(dev, SMBUS_MODE_CONTROLLER | SMBUS_MODE_SMBALERT); + zassert_ok(ret, "Configure failed"); + + /* Emulate SMBus alert again */ + run_isr(EMUL_SMBUS_SMBALERT); + + /* Wait for delayed work handled */ + k_sleep(K_MSEC(100)); + + /* Verify that smbalert is not handled */ + zassert_true(smbalert_handled, "smbalert is not handled"); +} + +ZTEST(test_smbus_emul, test_host_notify) +{ + const struct device *const dev = device_get_binding(SMBUS_EMUL); + int ret; + + Z_TEST_SKIP_IFNDEF(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY); + + zassert_not_null(dev, "Device not found"); + + /* Try to remove not existing callback */ + ret = smbus_manage_host_notify_cb(dev, ¬ify_callback, false); + zassert_equal(ret, -ENOENT, "Callback remove failed"); + + /* Set callback */ + ret = smbus_manage_host_notify_cb(dev, ¬ify_callback, true); + zassert_ok(ret, "Callback set failed"); + + /* Emulate SMBus alert from peripheral device */ + notify_handled = false; + + /* Run without configuring Host Notify */ + run_isr(EMUL_SMBUS_HOST_NOTIFY); + + /* Wait for delayed work handled */ + k_sleep(K_MSEC(100)); + + /* Verify that smbalert is NOT handled */ + zassert_false(notify_handled, "smbalert is not handled"); + + /* Now enable smbalert */ + ret = smbus_configure(dev, + SMBUS_MODE_CONTROLLER | SMBUS_MODE_HOST_NOTIFY); + zassert_ok(ret, "Configure failed"); + + /* Emulate SMBus alert again */ + run_isr(EMUL_SMBUS_HOST_NOTIFY); + + /* Wait for delayed work handled */ + k_sleep(K_MSEC(100)); + + /* Verify that smbalert is handled */ + zassert_true(notify_handled, "smbalert is not handled"); +} + +/* Test setup function */ +static void *smbus_emul_setup(void) +{ + emul_register_smbus_peripheral(&peripheral); + + return NULL; +} + +ZTEST_SUITE(test_smbus_emul, NULL, smbus_emul_setup, NULL, NULL, NULL); diff --git a/tests/drivers/smbus/smbus_emul/testcase.yaml b/tests/drivers/smbus/smbus_emul/testcase.yaml new file mode 100644 index 000000000000..26fc9254c55c --- /dev/null +++ b/tests/drivers/smbus/smbus_emul/testcase.yaml @@ -0,0 +1,8 @@ +common: + platform_allow: native_posix +tests: + drivers.smbus.emul: + tags: smbus + drivers.smbus.emul.peripheral.interrupt: + tags: smbus + extra_args: EXTRA_CFLAGS=-DPERIPHERAL_INT=1 From 14923f41312707fa6bcdee53d6152c71fdbbeeb6 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Fri, 4 Nov 2022 18:03:32 +0200 Subject: [PATCH 0651/1906] smbus: Refactor callbacks API The callbacks API was similar to gpio / espi callbacks API. Refactor it to use more intuitive names for set / remove callbacks. Signed-off-by: Andrei Emeltchenko --- drivers/smbus/intel_pch_smbus.c | 44 ++++++--- drivers/smbus/smbus_handlers.c | 36 +++++-- include/zephyr/drivers/smbus.h | 98 ++++++++++++++----- include/zephyr/drivers/smbus_utils.h | 44 +++++---- .../drivers/smbus/smbus_api/src/test_smbus.c | 22 ++++- tests/drivers/smbus/smbus_emul/src/smbus.c | 8 +- 6 files changed, 180 insertions(+), 72 deletions(-) diff --git a/drivers/smbus/intel_pch_smbus.c b/drivers/smbus/intel_pch_smbus.c index 2916217cee0b..c43f6e41ec8e 100644 --- a/drivers/smbus/intel_pch_smbus.c +++ b/drivers/smbus/intel_pch_smbus.c @@ -148,26 +148,44 @@ static void smbalert_work(struct k_work *work) } while (true); } -static int pch_smbus_manage_smbalert_cb(const struct device *dev, - struct smbus_callback *cb, - bool set) +static int pch_smbus_smbalert_set_sb(const struct device *dev, + struct smbus_callback *cb) { struct pch_data *data = dev->data; - LOG_DBG("dev %p cb %p set %d", dev, cb, set); + LOG_DBG("dev %p cb %p", dev, cb); - return smbus_manage_smbus_callback(&data->smbalert_cbs, cb, set); + return smbus_callback_set(&data->smbalert_cbs, cb); } -static int pch_smbus_manage_host_notify_cb(const struct device *dev, - struct smbus_callback *cb, - bool set) +static int pch_smbus_smbalert_remove_sb(const struct device *dev, + struct smbus_callback *cb) { struct pch_data *data = dev->data; - LOG_DBG("dev %p cb %p set %d", dev, cb, set); + LOG_DBG("dev %p cb %p", dev, cb); - return smbus_manage_smbus_callback(&data->host_notify_cbs, cb, set); + return smbus_callback_remove(&data->smbalert_cbs, cb); +} + +static int pch_smbus_host_notify_set_cb(const struct device *dev, + struct smbus_callback *cb) +{ + struct pch_data *data = dev->data; + + LOG_DBG("dev %p cb %p", dev, cb); + + return smbus_callback_set(&data->host_notify_cbs, cb); +} + +static int pch_smbus_host_notify_remove_cb(const struct device *dev, + struct smbus_callback *cb) +{ + struct pch_data *data = dev->data; + + LOG_DBG("dev %p cb %p", dev, cb); + + return smbus_callback_remove(&data->host_notify_cbs, cb); } static int pch_configure(const struct device *dev, uint32_t config) @@ -902,8 +920,10 @@ static const struct smbus_driver_api funcs = { .smbus_block_write = pch_smbus_block_write, .smbus_block_read = pch_smbus_block_read, .smbus_block_pcall = pch_smbus_block_pcall, - .smbus_manage_smbalert_cb = pch_smbus_manage_smbalert_cb, - .smbus_manage_host_notify_cb = pch_smbus_manage_host_notify_cb, + .smbus_smbalert_set_cb = pch_smbus_smbalert_set_sb, + .smbus_smbalert_remove_cb = pch_smbus_smbalert_remove_sb, + .smbus_host_notify_set_cb = pch_smbus_host_notify_set_cb, + .smbus_host_notify_remove_cb = pch_smbus_host_notify_remove_cb, }; static void smbus_isr(const struct device *dev) diff --git a/drivers/smbus/smbus_handlers.c b/drivers/smbus/smbus_handlers.c index fd03a7cad487..0c9797888308 100644 --- a/drivers/smbus/smbus_handlers.c +++ b/drivers/smbus/smbus_handlers.c @@ -144,22 +144,38 @@ static inline int z_vrfy_smbus_block_pcall(const struct device *dev, } #include -static inline int z_vrfy_smbus_manage_smbalert_cb(const struct device *dev, - struct smbus_callback *cb, - bool set) +static inline int z_vrfy_smbus_smbalert_set_cb(const struct device *dev, + struct smbus_callback *cb) { Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); - return z_impl_smbus_manage_smbalert_cb(dev, cb, set); + return z_impl_smbus_smbalert_set_cb(dev, cb); } -#include +#include -static inline int z_vrfy_smbus_manage_host_notify_cb(const struct device *dev, - struct smbus_callback *cb, - bool set) +static inline int z_vrfy_smbus_smbalert_remove_cb(const struct device *dev, + struct smbus_callback *cb) { Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); - return z_impl_smbus_manage_host_notify_cb(dev, cb, set); + return z_impl_smbus_smbalert_remove_cb(dev, cb); } -#include +#include + +static inline int z_vrfy_smbus_host_notify_set_cb(const struct device *dev, + struct smbus_callback *cb) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + + return z_impl_smbus_host_notify_set_cb(dev, cb); +} +#include + +static inline int z_vrfy_smbus_host_notify_remove_cb(const struct device *dev, + struct smbus_callback *cb) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SMBUS)); + + return z_impl_smbus_host_notify_remove_cb(dev, cb); +} +#include diff --git a/include/zephyr/drivers/smbus.h b/include/zephyr/drivers/smbus.h index d20786f7d11c..02e673c1e478 100644 --- a/include/zephyr/drivers/smbus.h +++ b/include/zephyr/drivers/smbus.h @@ -358,12 +358,10 @@ typedef int (*smbus_api_block_pcall_t)(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t send_count, uint8_t *send_buf, uint8_t *recv_count, uint8_t *recv_buf); -typedef int (*smbus_api_manage_smbalert_cb_t)(const struct device *dev, - struct smbus_callback *cb, - bool set); -typedef int (*smbus_api_manage_host_notify_cb_t)(const struct device *dev, - struct smbus_callback *cb, - bool set); +typedef int (*smbus_api_smbalert_cb_t)(const struct device *dev, + struct smbus_callback *cb); +typedef int (*smbus_api_host_notify_cb_t)(const struct device *dev, + struct smbus_callback *cb); __subsystem struct smbus_driver_api { smbus_api_configure_t configure; @@ -379,8 +377,10 @@ __subsystem struct smbus_driver_api { smbus_api_block_write_t smbus_block_write; smbus_api_block_read_t smbus_block_read; smbus_api_block_pcall_t smbus_block_pcall; - smbus_api_manage_smbalert_cb_t smbus_manage_smbalert_cb; - smbus_api_manage_host_notify_cb_t smbus_manage_host_notify_cb; + smbus_api_smbalert_cb_t smbus_smbalert_set_cb; + smbus_api_smbalert_cb_t smbus_smbalert_remove_cb; + smbus_api_host_notify_cb_t smbus_host_notify_set_cb; + smbus_api_host_notify_cb_t smbus_host_notify_remove_cb; }; /** @@ -592,28 +592,51 @@ static inline int z_impl_smbus_get_config(const struct device *dev, * * @param dev Pointer to the device structure for the driver instance. * @param cb Pointer to a callback structure. - * @param set A boolean indicating insertion or removal of the callback. * * @retval 0 If successful. * @retval -EIO General input / output error, failed to configure device. * @retval -ENOSYS If get config is not implemented */ -__syscall int smbus_manage_smbalert_cb(const struct device *dev, - struct smbus_callback *cb, - bool set); +__syscall int smbus_smbalert_set_cb(const struct device *dev, + struct smbus_callback *cb); -static inline int z_impl_smbus_manage_smbalert_cb(const struct device *dev, - struct smbus_callback *cb, - bool set) +static inline int z_impl_smbus_smbalert_set_cb(const struct device *dev, + struct smbus_callback *cb) { const struct smbus_driver_api *api = (const struct smbus_driver_api *)dev->api; - if (api->smbus_manage_smbalert_cb == NULL) { + if (api->smbus_smbalert_set_cb == NULL) { return -ENOSYS; } - return api->smbus_manage_smbalert_cb(dev, cb, set); + return api->smbus_smbalert_set_cb(dev, cb); +} + +/** + * @brief Remove SMBUSALERT callback from a SMBus host controller. + * + * @param dev Pointer to the device structure for the driver instance. + * @param cb Pointer to a callback structure. + * + * @retval 0 If successful. + * @retval -EIO General input / output error, failed to configure device. + * @retval -ENOSYS If get config is not implemented + */ +__syscall int smbus_smbalert_remove_cb(const struct device *dev, + struct smbus_callback *cb); + +static inline int z_impl_smbus_smbalert_remove_cb(const struct device *dev, + struct smbus_callback *cb) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_smbalert_remove_cb == NULL) { + return -ENOSYS; + } + + return api->smbus_smbalert_remove_cb(dev, cb); } /** @@ -621,28 +644,51 @@ static inline int z_impl_smbus_manage_smbalert_cb(const struct device *dev, * * @param dev Pointer to the device structure for the driver instance. * @param cb Pointer to a callback structure. - * @param set A boolean indicating insertion or removal of the callback. * * @retval 0 If successful. * @retval -EIO General input / output error, failed to configure device. * @retval -ENOSYS If get config is not implemented */ -__syscall int smbus_manage_host_notify_cb(const struct device *dev, - struct smbus_callback *cb, - bool set); +__syscall int smbus_host_notify_set_cb(const struct device *dev, + struct smbus_callback *cb); + +static inline int z_impl_smbus_host_notify_set_cb(const struct device *dev, + struct smbus_callback *cb) +{ + const struct smbus_driver_api *api = + (const struct smbus_driver_api *)dev->api; + + if (api->smbus_host_notify_set_cb == NULL) { + return -ENOSYS; + } + + return api->smbus_host_notify_set_cb(dev, cb); +} + +/** + * @brief Remove Host Notify callback from a SMBus host controller. + * + * @param dev Pointer to the device structure for the driver instance. + * @param cb Pointer to a callback structure. + * + * @retval 0 If successful. + * @retval -EIO General input / output error, failed to configure device. + * @retval -ENOSYS If get config is not implemented + */ +__syscall int smbus_host_notify_remove_cb(const struct device *dev, + struct smbus_callback *cb); -static inline int z_impl_smbus_manage_host_notify_cb(const struct device *dev, - struct smbus_callback *cb, - bool set) +static inline int z_impl_smbus_host_notify_remove_cb(const struct device *dev, + struct smbus_callback *cb) { const struct smbus_driver_api *api = (const struct smbus_driver_api *)dev->api; - if (api->smbus_manage_host_notify_cb == NULL) { + if (api->smbus_host_notify_remove_cb == NULL) { return -ENOSYS; } - return api->smbus_manage_host_notify_cb(dev, cb, set); + return api->smbus_host_notify_remove_cb(dev, cb); } /** diff --git a/include/zephyr/drivers/smbus_utils.h b/include/zephyr/drivers/smbus_utils.h index 426891dfdf6f..0158d2c5a521 100644 --- a/include/zephyr/drivers/smbus_utils.h +++ b/include/zephyr/drivers/smbus_utils.h @@ -8,35 +8,45 @@ #define ZEPHYR_DRIVERS_SMBUS_SMBUS_UTILS_H_ /** - * @brief Generic function to insert or remove a callback from a callback list + * @brief Generic function to insert a callback to a callback list * * @param callbacks A pointer to the original list of callbacks (can be NULL) - * @param callback A pointer of the callback to insert or remove from the list - * @param set A boolean indicating insertion or removal of the callback + * @param callback A pointer of the callback to insert to the list * * @return 0 on success, negative errno otherwise. */ -static inline int smbus_manage_smbus_callback(sys_slist_t *callbacks, - struct smbus_callback *callback, - bool set) +static inline int smbus_callback_set(sys_slist_t *callbacks, + struct smbus_callback *callback) { __ASSERT(callback, "No callback!"); __ASSERT(callback->handler, "No callback handler!"); if (!sys_slist_is_empty(callbacks)) { - if (!sys_slist_find_and_remove(callbacks, &callback->node)) { - if (!set) { - return -ENOENT; - } - } - } else { - if (!set) { - return -ENOENT; - } + sys_slist_find_and_remove(callbacks, &callback->node); } - if (set) { - sys_slist_prepend(callbacks, &callback->node); + sys_slist_prepend(callbacks, &callback->node); + + return 0; +} + +/** + * @brief Generic function to remove a callback from a callback list + * + * @param callbacks A pointer to the original list of callbacks (can be NULL) + * @param callback A pointer of the callback to remove from the list + * + * @return 0 on success, negative errno otherwise. + */ +static inline int smbus_callback_remove(sys_slist_t *callbacks, + struct smbus_callback *callback) +{ + __ASSERT(callback, "No callback!"); + __ASSERT(callback->handler, "No callback handler!"); + + if (sys_slist_is_empty(callbacks) || + !sys_slist_find_and_remove(callbacks, &callback->node)) { + return -ENOENT; } return 0; diff --git a/tests/drivers/smbus/smbus_api/src/test_smbus.c b/tests/drivers/smbus/smbus_api/src/test_smbus.c index 74b3d27250db..e3eda7ceee3f 100644 --- a/tests/drivers/smbus/smbus_api/src/test_smbus.c +++ b/tests/drivers/smbus/smbus_api/src/test_smbus.c @@ -58,16 +58,32 @@ ZTEST_USER(test_smbus_general, test_smbus_callback_api) zassert_true(device_is_ready(dev), "Device is not ready"); + /* Smbalert callbacks */ + + /* Try to remove not existing callback */ + ret = smbus_smbalert_remove_cb(dev, &callback); + zassert_equal(ret, -ENOENT, "Callback remove failed"); + + /* Set callback */ + ret = smbus_smbalert_set_cb(dev, &callback); + zassert_ok(ret, "Callback set failed"); + + /* Remove existing callback */ + ret = smbus_smbalert_remove_cb(dev, &callback); + zassert_ok(ret, "Callback remove failed"); + + /* Host Notify callbacks */ + /* Try to remove not existing callback */ - ret = smbus_manage_smbalert_cb(dev, &callback, false); + ret = smbus_host_notify_remove_cb(dev, &callback); zassert_equal(ret, -ENOENT, "Callback remove failed"); /* Set callback */ - ret = smbus_manage_smbalert_cb(dev, &callback, true); + ret = smbus_host_notify_set_cb(dev, &callback); zassert_ok(ret, "Callback set failed"); /* Remove existing callback */ - ret = smbus_manage_smbalert_cb(dev, &callback, false); + ret = smbus_host_notify_remove_cb(dev, &callback); zassert_ok(ret, "Callback remove failed"); } diff --git a/tests/drivers/smbus/smbus_emul/src/smbus.c b/tests/drivers/smbus/smbus_emul/src/smbus.c index 4c62a1a9c551..451859c841ef 100644 --- a/tests/drivers/smbus/smbus_emul/src/smbus.c +++ b/tests/drivers/smbus/smbus_emul/src/smbus.c @@ -294,11 +294,11 @@ ZTEST(test_smbus_emul, test_alert) zassert_not_null(dev, "Device not found"); /* Try to remove not existing callback */ - ret = smbus_manage_smbalert_cb(dev, &smbalert_callback, false); + ret = smbus_smbalert_remove_cb(dev, &smbalert_callback); zassert_equal(ret, -ENOENT, "Callback remove failed"); /* Set callback */ - ret = smbus_manage_smbalert_cb(dev, &smbalert_callback, true); + ret = smbus_smbalert_set_cb(dev, &smbalert_callback); zassert_ok(ret, "Callback set failed"); /* Emulate SMBus alert from peripheral device */ @@ -338,11 +338,11 @@ ZTEST(test_smbus_emul, test_host_notify) zassert_not_null(dev, "Device not found"); /* Try to remove not existing callback */ - ret = smbus_manage_host_notify_cb(dev, ¬ify_callback, false); + ret = smbus_host_notify_remove_cb(dev, ¬ify_callback); zassert_equal(ret, -ENOENT, "Callback remove failed"); /* Set callback */ - ret = smbus_manage_host_notify_cb(dev, ¬ify_callback, true); + ret = smbus_host_notify_set_cb(dev, ¬ify_callback); zassert_ok(ret, "Callback set failed"); /* Emulate SMBus alert from peripheral device */ From a42ab2729f65cbcb511e99fad2b79e84e959548f Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Thu, 17 Nov 2022 15:35:09 +0200 Subject: [PATCH 0652/1906] smbus: Convert to use runtime BDF lookup Convert PCH SMBus driver, tests and samples to use new dynamic BDF lookup. Signed-off-by: Andrei Emeltchenko --- drivers/smbus/intel_pch_smbus.c | 41 +++++++++------------- dts/bindings/smbus/intel,pch-smbus.yaml | 2 +- dts/x86/intel/elkhart_lake.dtsi | 5 +-- dts/x86/intel/raptor_lake.dtsi | 5 +-- tests/drivers/smbus/smbus_emul/src/smbus.c | 4 +++ 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/drivers/smbus/intel_pch_smbus.c b/drivers/smbus/intel_pch_smbus.c index c43f6e41ec8e..c254c49a702a 100644 --- a/drivers/smbus/intel_pch_smbus.c +++ b/drivers/smbus/intel_pch_smbus.c @@ -37,10 +37,7 @@ LOG_MODULE_REGISTER(intel_pch, CONFIG_SMBUS_LOG_LEVEL); struct pch_config { /* IRQ configuration function */ void (*config_func)(const struct device *dev); - /* PCIE BDF got from DTS */ - pcie_bdf_t pcie_bdf; - /* PCIE ID got from DTS */ - pcie_id_t pcie_id; + struct pcie_dev *pcie; }; /** @@ -245,19 +242,19 @@ static int pch_smbus_init(const struct device *dev) struct pcie_bar mbar; uint32_t val; - if (!pcie_probe(config->pcie_bdf, config->pcie_id)) { + if (config->pcie->bdf == PCIE_BDF_NONE) { LOG_ERR("Cannot probe PCI device"); return -ENODEV; } - val = pcie_conf_read(config->pcie_bdf, PCIE_CONF_CMDSTAT); + val = pcie_conf_read(config->pcie->bdf, PCIE_CONF_CMDSTAT); if (val & PCIE_CONF_CMDSTAT_INTERRUPT) { LOG_WRN("Pending interrupt, continuing"); } if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_ACCESS_MMIO)) { - pcie_probe_mbar(config->pcie_bdf, 0, &mbar); - pcie_set_cmd(config->pcie_bdf, PCIE_CONF_CMDSTAT_MEM, true); + pcie_probe_mbar(config->pcie->bdf, 0, &mbar); + pcie_set_cmd(config->pcie->bdf, PCIE_CONF_CMDSTAT_MEM, true); device_map(DEVICE_MMIO_RAM_PTR(dev), mbar.phys_addr, mbar.size, K_MEM_CACHE_NONE); @@ -265,8 +262,8 @@ static int pch_smbus_init(const struct device *dev) LOG_DBG("Mapped 0x%lx size 0x%lx to 0x%lx", mbar.phys_addr, mbar.size, DEVICE_MMIO_GET(dev)); } else { - pcie_set_cmd(config->pcie_bdf, PCIE_CONF_CMDSTAT_IO, true); - val = pcie_conf_read(config->pcie_bdf, PCIE_CONF_BAR4); + pcie_set_cmd(config->pcie->bdf, PCIE_CONF_CMDSTAT_IO, true); + val = pcie_conf_read(config->pcie->bdf, PCIE_CONF_BAR4); if (!PCIE_CONF_BAR_IO(val)) { LOG_ERR("Cannot read IO BAR"); return -EINVAL; @@ -277,7 +274,7 @@ static int pch_smbus_init(const struct device *dev) LOG_DBG("Using I/O address 0x%x", data->sba); } - val = pcie_conf_read(config->pcie_bdf, PCH_SMBUS_HCFG); + val = pcie_conf_read(config->pcie->bdf, PCH_SMBUS_HCFG); if ((val & PCH_SMBUS_HCFG_HST_EN) == 0) { LOG_ERR("SMBus Host Controller is disabled"); return -EINVAL; @@ -933,7 +930,7 @@ static void smbus_isr(const struct device *dev) uint32_t sts; uint8_t status; - sts = pcie_conf_read(config->pcie_bdf, PCIE_CONF_CMDSTAT); + sts = pcie_conf_read(config->pcie->bdf, PCIE_CONF_CMDSTAT); if (!(sts & PCIE_CONF_CMDSTAT_INTERRUPT)) { LOG_ERR("Not our interrupt"); return; @@ -993,12 +990,6 @@ static void smbus_isr(const struct device *dev) /* Device macro initialization / DTS hackery */ -/* PCI BDF is hacked into REG_ADDR */ -#define DT_INST_PCIE_BDF(n) DT_INST_REG_ADDR(n) - -/* PCI ID is hacked into REG_SIZE */ -#define DT_INST_PCIE_ID(n) DT_INST_REG_SIZE(n) - #define SMBUS_PCH_IRQ_FLAGS_SENSE0(n) 0 #define SMBUS_PCH_IRQ_FLAGS_SENSE1(n) DT_INST_IRQ(n, sense) #define SMBUS_PCH_IRQ_FLAGS(n) \ @@ -1009,33 +1000,33 @@ static void smbus_isr(const struct device *dev) "SMBus PCIe requires dynamic interrupts"); \ static void pch_config_##n(const struct device *dev) \ { \ - ARG_UNUSED(dev); \ + const struct pch_config * const config = dev->config; \ unsigned int irq; \ if (DT_INST_IRQN(n) == PCIE_IRQ_DETECT) { \ - irq = pcie_alloc_irq(DT_INST_PCIE_BDF(n)); \ + irq = pcie_alloc_irq(config->pcie->bdf); \ if (irq == PCIE_CONF_INTR_IRQ_NONE) { \ return; \ } \ } else { \ irq = DT_INST_IRQN(n); \ - pcie_conf_write(DT_INST_PCIE_BDF(n), \ + pcie_conf_write(config->pcie->bdf, \ PCIE_CONF_INTR, irq); \ } \ - pcie_connect_dynamic_irq(DT_INST_PCIE_BDF(n), irq, \ + pcie_connect_dynamic_irq(config->pcie->bdf, irq, \ DT_INST_IRQ(n, priority), \ (void (*)(const void *))smbus_isr, \ DEVICE_DT_INST_GET(n), \ SMBUS_PCH_IRQ_FLAGS(n)); \ - pcie_irq_enable(DT_INST_PCIE_BDF(n), irq); \ + pcie_irq_enable(config->pcie->bdf, irq); \ LOG_DBG("Configure irq %d", irq); \ } #define SMBUS_DEVICE_INIT(n) \ + DEVICE_PCIE_INST_DECLARE(n); \ static void pch_config_##n(const struct device *dev); \ static const struct pch_config pch_config_data_##n = { \ + DEVICE_PCIE_INST_INIT(n, pcie), \ .config_func = pch_config_##n, \ - .pcie_bdf = DT_INST_PCIE_BDF(n), \ - .pcie_id = DT_INST_PCIE_ID(n), \ }; \ static struct pch_data smbus_##n##_data; \ SMBUS_DEVICE_DT_INST_DEFINE(n, pch_smbus_init, NULL, \ diff --git a/dts/bindings/smbus/intel,pch-smbus.yaml b/dts/bindings/smbus/intel,pch-smbus.yaml index 3dcdbb57a187..b3475f3ae31f 100644 --- a/dts/bindings/smbus/intel,pch-smbus.yaml +++ b/dts/bindings/smbus/intel,pch-smbus.yaml @@ -5,7 +5,7 @@ description: Intel Platform Controller Hub SMBus node compatible: "intel,pch-smbus" -include: smbus-controller.yaml +include: [smbus-controller.yaml, pcie-device.yaml] properties: interrupts: diff --git a/dts/x86/intel/elkhart_lake.dtsi b/dts/x86/intel/elkhart_lake.dtsi index 7b1ab2f6ba9b..056f2dbfd258 100644 --- a/dts/x86/intel/elkhart_lake.dtsi +++ b/dts/x86/intel/elkhart_lake.dtsi @@ -189,11 +189,12 @@ current-speed = <115200>; }; - smbus0: smbus@fc00 { + smbus0: smbus0 { compatible = "intel,pch-smbus"; #address-cells = <1>; #size-cells = <0>; - reg = ; + vendor-id = <0x8086>; + device-id = <0x4b23>; interrupts = <16 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; interrupt-parent = <&intc>; diff --git a/dts/x86/intel/raptor_lake.dtsi b/dts/x86/intel/raptor_lake.dtsi index bc9f86fc8689..25c19f52aced 100644 --- a/dts/x86/intel/raptor_lake.dtsi +++ b/dts/x86/intel/raptor_lake.dtsi @@ -41,11 +41,12 @@ compatible = "intel,pcie"; ranges; - smbus0: smbus@fc00 { + smbus0: smbus0 { compatible = "intel,pch-smbus"; #address-cells = <1>; #size-cells = <0>; - reg = ; + vendor-id = <0x8086>; + device-id = <0x7a23>; interrupts = <18 IRQ_TYPE_LOWEST_LEVEL_LOW 3>; interrupt-parent = <&intc>; diff --git a/tests/drivers/smbus/smbus_emul/src/smbus.c b/tests/drivers/smbus/smbus_emul/src/smbus.c index 451859c841ef..8157fa1aef48 100644 --- a/tests/drivers/smbus/smbus_emul/src/smbus.c +++ b/tests/drivers/smbus/smbus_emul/src/smbus.c @@ -93,9 +93,13 @@ static void config_function(const struct device *dev) TC_PRINT("Emulator device configuration\n"); } static struct pch_data smbus_data; +/* Zero initialized, dummy device does not care about pcie ids */ +static struct pcie_dev pcie_params; static struct pch_config pch_config_data = { .config_func = config_function, + .pcie = &pcie_params, }; + DEVICE_DEFINE(dummy_driver, SMBUS_EMUL, &pch_smbus_init, NULL, &smbus_data, &pch_config_data, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &funcs); From 97c55ce46c1fe43837da71aabafe52979f2c8142 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Mon, 3 Oct 2022 12:01:15 +0300 Subject: [PATCH 0653/1906] smbus: Update CODEOWNERS and MAINTAINERS files Update CODEOWNERS and MAINTAINERS files. Signed-off-by: Andrei Emeltchenko --- CODEOWNERS | 5 +++++ MAINTAINERS.yml | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CODEOWNERS b/CODEOWNERS index 539c3bc26cf4..548179896829 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -415,6 +415,7 @@ /drivers/serial/uart_hvc_xen_consoleio.c @lorc @firscity /drivers/serial/Kconfig.it8xxx2 @GTLin08 /drivers/serial/uart_ite_it8xxx2.c @GTLin08 +/drivers/smbus/ @finikorg /drivers/disk/ @jfischer-no /drivers/disk/sdmmc_sdhc.h @JunYangNXP /drivers/disk/sdmmc_stm32.c @anthonybrandon @@ -561,6 +562,7 @@ /dts/bindings/sensor/*bme680* @BoschSensortec /dts/bindings/sensor/*ina23* @bbilas /dts/bindings/sensor/st* @avisconti +/dts/bindings/smbus/ @finikorg /dts/bindings/cpu/intel,niosv.yaml @sweeaun /dts/common/ @galak /include/ @nashif @carlescufi @galak @MaureenHelm @@ -585,6 +587,7 @@ /include/zephyr/drivers/led.h @Mani-Sadhasivam /include/zephyr/drivers/led_strip.h @mbolivar-nordic /include/zephyr/drivers/sensor.h @MaureenHelm +/include/zephyr/drivers/smbus.h @finikorg /include/zephyr/drivers/spi.h @tbursztyka /include/zephyr/drivers/lora.h @Mani-Sadhasivam /include/zephyr/drivers/peci.h @albertofloyd @franciscomunoz @sjvasanth1 @@ -696,6 +699,7 @@ /samples/drivers/eeprom/ @henrikbrixandersen /samples/drivers/ht16k33/ @henrikbrixandersen /samples/drivers/lora/ @Mani-Sadhasivam +/samples/drivers/smbus/ @finikorg /samples/subsys/lorawan/ @Mani-Sadhasivam /samples/modules/canopennode/ @henrikbrixandersen /samples/net/ @rlubos @tbursztyka @@ -844,6 +848,7 @@ scripts/build/gen_image_info.py @tejlmand /tests/drivers/flash_simulator/ @de-nordic /tests/drivers/gpio/ @mnkp /tests/drivers/hwinfo/ @alexanderwachter +/tests/drivers/smbus/ @finikorg /tests/drivers/spi/ @tbursztyka /tests/drivers/uart/uart_async_api/ @Mierunski /tests/drivers/w1/ @str4t0m diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index 243ed51f1737..d8f50bc19bd6 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -1221,6 +1221,20 @@ Release Notes: labels: - "area: Sensors" +"Drivers: SMBus": + status: maintained + maintainers: + - finikorg + files: + - drivers/smbus/ + - dts/bindings/smbus/ + - include/zephyr/drivers/smbus.h + - samples/drivers/smbus/ + - tests/drivers/smbus/ + - doc/hardware/peripherals/smbus.rst + labels: + - "area: SMBus" + "Drivers: SPI": status: maintained maintainers: From e829b72ad5cc2bf57685bc9612f462e6a0de3d37 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Mon, 20 Mar 2023 13:24:57 +0200 Subject: [PATCH 0654/1906] drivers: smbus: pch: Wrap respective code with ifdefs Wrap code for SMBALERT and HOST_NOTIFY with configuration ifdefs. Signed-off-by: Andrei Emeltchenko --- drivers/smbus/intel_pch_smbus.c | 75 ++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/drivers/smbus/intel_pch_smbus.c b/drivers/smbus/intel_pch_smbus.c index c254c49a702a..2bc05ce5c631 100644 --- a/drivers/smbus/intel_pch_smbus.c +++ b/drivers/smbus/intel_pch_smbus.c @@ -53,11 +53,14 @@ struct pch_data { struct k_sem completion_sync; const struct device *dev; +#if defined(CONFIG_SMBUS_INTEL_PCH_SMBALERT) /* smbalert callback list */ sys_slist_t smbalert_cbs; /* smbalert work */ struct k_work smb_alert_work; +#endif /* CONFIG_SMBUS_INTEL_PCH_SMBALERT */ +#if defined(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY) /* Host Notify callback list */ sys_slist_t host_notify_cbs; /* Host Notify work */ @@ -66,6 +69,7 @@ struct pch_data { uint8_t notify_addr; /* Host Notify data received */ uint16_t notify_data; +#endif /* CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY */ }; /** @@ -100,6 +104,7 @@ static void pch_reg_write(const struct device *dev, uint8_t reg, uint8_t val) #error Wrong PCH Register Access Mode #endif +#if defined(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY) static void host_notify_work(struct k_work *work) { struct pch_data *data = CONTAINER_OF(work, struct pch_data, @@ -110,6 +115,28 @@ static void host_notify_work(struct k_work *work) smbus_fire_callbacks(&data->host_notify_cbs, dev, addr); } +static int pch_smbus_host_notify_set_cb(const struct device *dev, + struct smbus_callback *cb) +{ + struct pch_data *data = dev->data; + + LOG_DBG("dev %p cb %p", dev, cb); + + return smbus_callback_set(&data->host_notify_cbs, cb); +} + +static int pch_smbus_host_notify_remove_cb(const struct device *dev, + struct smbus_callback *cb) +{ + struct pch_data *data = dev->data; + + LOG_DBG("dev %p cb %p", dev, cb); + + return smbus_callback_remove(&data->host_notify_cbs, cb); +} +#endif /* CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY */ + +#if defined(CONFIG_SMBUS_INTEL_PCH_SMBALERT) static void smbalert_work(struct k_work *work) { struct pch_data *data = CONTAINER_OF(work, struct pch_data, @@ -164,26 +191,7 @@ static int pch_smbus_smbalert_remove_sb(const struct device *dev, return smbus_callback_remove(&data->smbalert_cbs, cb); } - -static int pch_smbus_host_notify_set_cb(const struct device *dev, - struct smbus_callback *cb) -{ - struct pch_data *data = dev->data; - - LOG_DBG("dev %p cb %p", dev, cb); - - return smbus_callback_set(&data->host_notify_cbs, cb); -} - -static int pch_smbus_host_notify_remove_cb(const struct device *dev, - struct smbus_callback *cb) -{ - struct pch_data *data = dev->data; - - LOG_DBG("dev %p cb %p", dev, cb); - - return smbus_callback_remove(&data->host_notify_cbs, cb); -} +#endif /* CONFIG_SMBUS_INTEL_PCH_SMBALERT */ static int pch_configure(const struct device *dev, uint32_t config) { @@ -287,13 +295,14 @@ static int pch_smbus_init(const struct device *dev) data->dev = dev; /* Initialize work structures */ - if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_SMBALERT)) { - k_work_init(&data->smb_alert_work, smbalert_work); - } - if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY)) { - k_work_init(&data->host_notify_work, host_notify_work); - } +#if defined(CONFIG_SMBUS_INTEL_PCH_SMBALERT) + k_work_init(&data->smb_alert_work, smbalert_work); +#endif /* CONFIG_SMBUS_INTEL_PCH_SMBALERT */ + +#if defined(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY) + k_work_init(&data->host_notify_work, host_notify_work); +#endif /* CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY */ config->config_func(dev); @@ -917,10 +926,14 @@ static const struct smbus_driver_api funcs = { .smbus_block_write = pch_smbus_block_write, .smbus_block_read = pch_smbus_block_read, .smbus_block_pcall = pch_smbus_block_pcall, +#if defined(CONFIG_SMBUS_INTEL_PCH_SMBALERT) .smbus_smbalert_set_cb = pch_smbus_smbalert_set_sb, .smbus_smbalert_remove_cb = pch_smbus_smbalert_remove_sb, +#endif /* CONFIG_SMBUS_INTEL_PCH_SMBALERT */ +#if defined(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY) .smbus_host_notify_set_cb = pch_smbus_host_notify_set_cb, .smbus_host_notify_remove_cb = pch_smbus_host_notify_remove_cb, +#endif /* CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY */ }; static void smbus_isr(const struct device *dev) @@ -942,8 +955,8 @@ static void smbus_isr(const struct device *dev) * * Intel PCH implements Host Notify protocol in hardware. */ - if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY) && - data->config & SMBUS_MODE_HOST_NOTIFY) { +#if defined(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY) + if (data->config & SMBUS_MODE_HOST_NOTIFY) { status = pch_reg_read(dev, PCH_SMBUS_SSTS); if (status & PCH_SMBUS_SSTS_HNS) { /* Notify address */ @@ -963,6 +976,7 @@ static void smbus_isr(const struct device *dev) return; } } +#endif /* CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY */ status = pch_reg_read(dev, PCH_SMBUS_HSTS); @@ -974,11 +988,12 @@ static void smbus_isr(const struct device *dev) } /* Handle SMBALERT# signal */ - if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_SMBALERT) && - data->config & SMBUS_MODE_SMBALERT && +#if defined(CONFIG_SMBUS_INTEL_PCH_SMBALERT) + if (data->config & SMBUS_MODE_SMBALERT && status & PCH_SMBUS_HSTS_SMB_ALERT) { k_work_submit(&data->smb_alert_work); } +#endif /* CONFIG_SMBUS_INTEL_PCH_SMBALERT */ /* Clear IRQ sources */ pch_reg_write(dev, PCH_SMBUS_HSTS, status); From 9b95e3d64a8ba83478352e8bf30e3f5c1e678410 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Mon, 20 Mar 2023 13:27:48 +0200 Subject: [PATCH 0655/1906] tests: smbus: Test disabling configuration options Add tests with some configuration option disabled: CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY and CONFIG_SMBUS_INTEL_PCH_SMBALERT. Signed-off-by: Andrei Emeltchenko --- tests/drivers/smbus/smbus_api/testcase.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/drivers/smbus/smbus_api/testcase.yaml b/tests/drivers/smbus/smbus_api/testcase.yaml index 6c7fb8712050..16ab2b416990 100644 --- a/tests/drivers/smbus/smbus_api/testcase.yaml +++ b/tests/drivers/smbus/smbus_api/testcase.yaml @@ -16,6 +16,14 @@ tests: platform_allow: qemu_x86_64 extra_configs: - CONFIG_STATS=y + drivers.smbus.api.no_smbalert: + platform_allow: qemu_x86_64 + extra_configs: + - CONFIG_SMBUS_INTEL_PCH_SMBALERT=n + drivers.smbus.api.no_host_notify: + platform_allow: qemu_x86_64 + extra_configs: + - CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY=n drivers.smbus.api.debug: platform_allow: qemu_x86_64 extra_configs: From b0e6a6f8a7257895cd9ac8033813a239aec717ef Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Mon, 20 Mar 2023 13:30:16 +0200 Subject: [PATCH 0656/1906] tests: smbus: Fix testing for disabled configuration When some configuration options are disabled, test for -ENOSYS. Signed-off-by: Andrei Emeltchenko --- .../drivers/smbus/smbus_api/src/test_smbus.c | 57 ++++++++++++++++--- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/tests/drivers/smbus/smbus_api/src/test_smbus.c b/tests/drivers/smbus/smbus_api/src/test_smbus.c index e3eda7ceee3f..57bf23dff227 100644 --- a/tests/drivers/smbus/smbus_api/src/test_smbus.c +++ b/tests/drivers/smbus/smbus_api/src/test_smbus.c @@ -44,7 +44,7 @@ ZTEST_USER(test_smbus_general, test_smbus_basic_api) * The test is run in userspace only if CONFIG_USERSPACE option is * enabled, otherwise it is the same as ZTEST() */ -ZTEST_USER(test_smbus_general, test_smbus_callback_api) +ZTEST_USER(test_smbus_general, test_smbus_smbalert_api) { const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(smbus0)); void *dummy; /* For the dummy function pointer use this */ @@ -62,29 +62,72 @@ ZTEST_USER(test_smbus_general, test_smbus_callback_api) /* Try to remove not existing callback */ ret = smbus_smbalert_remove_cb(dev, &callback); - zassert_equal(ret, -ENOENT, "Callback remove failed"); + if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_SMBALERT)) { + zassert_equal(ret, -ENOENT, "Callback remove failed"); + } else { + zassert_equal(ret, -ENOSYS, "Check for ENOSYS failed"); + } /* Set callback */ ret = smbus_smbalert_set_cb(dev, &callback); - zassert_ok(ret, "Callback set failed"); + if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_SMBALERT)) { + zassert_ok(ret, "Callback set failed"); + } else { + zassert_equal(ret, -ENOSYS, "Check for ENOSYS failed"); + } /* Remove existing callback */ ret = smbus_smbalert_remove_cb(dev, &callback); - zassert_ok(ret, "Callback remove failed"); + if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_SMBALERT)) { + zassert_ok(ret, "Callback remove failed"); + } else { + zassert_equal(ret, -ENOSYS, "Check for ENOSYS failed"); + } +} + +/** + * The test is run in userspace only if CONFIG_USERSPACE option is + * enabled, otherwise it is the same as ZTEST() + */ +ZTEST_USER(test_smbus_general, test_smbus_host_notify_api) +{ + const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(smbus0)); + void *dummy; /* For the dummy function pointer use this */ + int ret; + + /* Note! Only for test using stack variables to ease userspace tests */ + struct smbus_callback callback = { + .handler = (void *)&dummy, + .addr = FAKE_ADDRESS, + }; + + zassert_true(device_is_ready(dev), "Device is not ready"); /* Host Notify callbacks */ /* Try to remove not existing callback */ ret = smbus_host_notify_remove_cb(dev, &callback); - zassert_equal(ret, -ENOENT, "Callback remove failed"); + if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY)) { + zassert_equal(ret, -ENOENT, "Callback remove failed"); + } else { + zassert_equal(ret, -ENOSYS, "Check for ENOSYS failed"); + } /* Set callback */ ret = smbus_host_notify_set_cb(dev, &callback); - zassert_ok(ret, "Callback set failed"); + if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY)) { + zassert_ok(ret, "Callback set failed"); + } else { + zassert_equal(ret, -ENOSYS, "Check for ENOSYS failed"); + } /* Remove existing callback */ ret = smbus_host_notify_remove_cb(dev, &callback); - zassert_ok(ret, "Callback remove failed"); + if (IS_ENABLED(CONFIG_SMBUS_INTEL_PCH_HOST_NOTIFY)) { + zassert_ok(ret, "Callback remove failed"); + } else { + zassert_equal(ret, -ENOSYS, "Check for ENOSYS failed"); + } } /** From 0f2a352cbdf121bb42acee6935707f8fc794cf18 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Wed, 22 Mar 2023 11:31:40 +0000 Subject: [PATCH 0657/1906] Revert "xtensa: remove ELF section address rewriting" This reverts commit 7a85983ebcf283b521331695fc80a49c623cc395. This commit was merged prematurely and is causing issues on multiple platforms. Signed-off-by: Anas Nashif --- soc/xtensa/intel_adsp/common/CMakeLists.txt | 4 ++ soc/xtensa/intel_adsp/common/fix_elf_addrs.py | 51 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100755 soc/xtensa/intel_adsp/common/fix_elf_addrs.py diff --git a/soc/xtensa/intel_adsp/common/CMakeLists.txt b/soc/xtensa/intel_adsp/common/CMakeLists.txt index 1d480f5a0f46..c9ed156b891b 100644 --- a/soc/xtensa/intel_adsp/common/CMakeLists.txt +++ b/soc/xtensa/intel_adsp/common/CMakeLists.txt @@ -30,6 +30,7 @@ zephyr_library_link_libraries(INTEL_ADSP_COMMON) target_include_directories(INTEL_ADSP_COMMON INTERFACE include) target_link_libraries(INTEL_ADSP_COMMON INTERFACE intel_adsp_common) +set(ELF_FIX ${PYTHON_EXECUTABLE} ${SOC_DIR}/${ARCH}/${SOC_FAMILY}/common/fix_elf_addrs.py) set(KERNEL_REMAPPED ${CMAKE_BINARY_DIR}/zephyr/${KERNEL_NAME}-remapped.elf) set(EXTMAN ${CMAKE_BINARY_DIR}/zephyr/extman.bin) @@ -73,6 +74,9 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/zephyr/${KERNEL_NAME}.elf ${KERNEL_REMAPPED} + COMMAND ${ELF_FIX} ${CMAKE_OBJCOPY} ${KERNEL_REMAPPED} + ${CONFIG_XTENSA_CACHED_REGION} ${CONFIG_XTENSA_UNCACHED_REGION} + # Extract modules for rimage COMMAND ${CMAKE_OBJCOPY} --only-section .imr diff --git a/soc/xtensa/intel_adsp/common/fix_elf_addrs.py b/soc/xtensa/intel_adsp/common/fix_elf_addrs.py new file mode 100755 index 000000000000..c9a75e1dcd71 --- /dev/null +++ b/soc/xtensa/intel_adsp/common/fix_elf_addrs.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2020-2022 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +# ADSP devices have their RAM regions mapped twice. The first mapping +# is set in the CPU to bypass the L1 cache, and so access through +# pointers in that region is coherent between CPUs (but slow). The +# second region accesses the same memory through the L1 cache and +# requires careful flushing when used with shared data. +# +# This distinction is exposed in the linker script, where some symbols +# (e.g. stack regions) are linked into cached memory, but others +# (general kernel memory) are not. But the rimage signing tool +# doesn't understand that and fails if regions aren't contiguous. +# +# Walk the sections in the ELF file, changing the VMA/LMA of each +# uncached section to the equivalent address in the cached area of +# memory. + +import os +import sys +from elftools.elf.elffile import ELFFile + +objcopy_bin = sys.argv[1] +elffile = sys.argv[2] +cached_reg = int(sys.argv[3]) +uncached_reg = int(sys.argv[4]) + +uc_min = uncached_reg << 29 +uc_max = uc_min | 0x1fffffff +cache_off = "0x%x" % ((cached_reg - uncached_reg) << 29) + +fixup =[] +with open(elffile, "rb") as fd: + elf = ELFFile(fd) + for s in elf.iter_sections(): + addr = s.header.sh_addr + if uc_min <= addr <= uc_max and s.header.sh_size != 0: + print(f"fix_elf_addrs.py: Moving section {s.name} to cached SRAM region") + fixup.append(s.name) + +for s in fixup: + # Note redirect: the sof-derived linker scripts currently emit + # some zero-length sections at address zero. This is benign, and + # the linker is happy, but objcopy will emit an unsilenceable + # error (no --quiet option, no -Werror=no-whatever, nothing). + # Just swallow the error stream for now pending rework to the + # linker framework. + cmd = f"{objcopy_bin} --change-section-address {s}+{cache_off} {elffile} 2>{os.devnull}" + os.system(cmd) From 1ebb49eeee516446f5b9ea8455c41e6838260d23 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 22 Mar 2023 08:46:32 +0100 Subject: [PATCH 0658/1906] bluetooth: ascs: Fix NULL pointer dereference in ascs_ase_read "The (ATT attribute read) callback can also be used locally to read the contents of the attribute in which case no connection will be set." This means that callback may be called with NULL conn. Since for ascs_ase_read NULL conn object have no meaning just return error. Signed-off-by: Szymon Janc --- subsys/bluetooth/audio/ascs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 6bc329013365..ecbd0a2fc6ca 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -1207,12 +1207,18 @@ static ssize_t ascs_ase_read(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) { - struct bt_ascs *ascs = ascs_get(conn); + struct bt_ascs *ascs; struct bt_ascs_ase *ase; uint8_t ase_id; LOG_DBG("conn %p attr %p buf %p len %u offset %u", (void *)conn, attr, buf, len, offset); + if (!conn) { + return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); + } + + ascs = ascs_get(conn); + ase_id = POINTER_TO_UINT(BT_AUDIO_CHRC_USER_DATA(attr)); if (ase_id > ASE_COUNT) { From 3ff1e973672b68a943ff42965c744fe5bd76db6d Mon Sep 17 00:00:00 2001 From: Franciszek Zdobylak Date: Wed, 22 Mar 2023 10:46:41 +0100 Subject: [PATCH 0659/1906] fs: Fix Kconfig formatting - use tabs instead of spaces in indentation - use 2 spaces instead of tab in help message Signed-off-by: Franciszek Zdobylak --- subsys/fs/Kconfig | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/subsys/fs/Kconfig b/subsys/fs/Kconfig index bb6c9352a531..a019b01395be 100644 --- a/subsys/fs/Kconfig +++ b/subsys/fs/Kconfig @@ -32,16 +32,16 @@ config FILE_SYSTEM_MAX_TYPES register them. A slot is required for each type. config FILE_SYSTEM_MAX_FILE_NAME - int "Optional override for maximum file name length" - default -1 - help - Specify the maximum file name allowed across all enabled file - system types. Zero or a negative value selects the maximum - file name length for enabled in-tree file systems. This - default may be inappropriate when registering an out-of-tree - file system. Selecting a value less than the actual length - supported by a file system may result in memory access - violations. + int "Optional override for maximum file name length" + default -1 + help + Specify the maximum file name allowed across all enabled file + system types. Zero or a negative value selects the maximum + file name length for enabled in-tree file systems. This + default may be inappropriate when registering an out-of-tree + file system. Selecting a value less than the actual length + supported by a file system may result in memory access + violations. config FILE_SYSTEM_SHELL bool "File system shell" @@ -75,8 +75,7 @@ endif # FILE_SYSTEM_SHELL config FILE_SYSTEM_MKFS bool "Allow to format file system" help - Enables function fs_mkfs that can be used to format a storage - device. + Enables function fs_mkfs that can be used to format a storage device. config FUSE_FS_ACCESS bool "FUSE based access to file system partitions" From 8eddd4861522bde7a85a2792c1c0427b3f8be6ff Mon Sep 17 00:00:00 2001 From: Dean Sellers Date: Wed, 8 Mar 2023 13:23:33 +1000 Subject: [PATCH 0660/1906] drivers: uart: esp32: Add RS485 half duplex hardware mode Support for the hardware mode where pin configured as DTR is asserterted when UART transmits. Signed-off-by: Dean Sellers --- drivers/serial/uart_esp32.c | 50 ++++++++++--------- dts/bindings/serial/espressif,esp32-uart.yaml | 8 +++ 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/drivers/serial/uart_esp32.c b/drivers/serial/uart_esp32.c index 595f2e339f8f..f8d6823f64dc 100644 --- a/drivers/serial/uart_esp32.c +++ b/drivers/serial/uart_esp32.c @@ -106,9 +106,9 @@ struct uart_esp32_data { #endif }; -#define UART_FIFO_LIMIT (UART_LL_FIFO_DEF_LEN) -#define UART_TX_FIFO_THRESH 0x1 -#define UART_RX_FIFO_THRESH 0x16 +#define UART_FIFO_LIMIT (UART_LL_FIFO_DEF_LEN) +#define UART_TX_FIFO_THRESH 0x1 +#define UART_RX_FIFO_THRESH 0x16 #if CONFIG_UART_INTERRUPT_DRIVEN || CONFIG_UART_ASYNC_API static void uart_esp32_isr(void *arg); @@ -152,8 +152,7 @@ static int uart_esp32_err_check(const struct device *dev) } #ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE -static int uart_esp32_config_get(const struct device *dev, - struct uart_config *cfg) +static int uart_esp32_config_get(const struct device *dev, struct uart_config *cfg) { struct uart_esp32_data *data = dev->data; uart_parity_t parity; @@ -223,6 +222,10 @@ static int uart_esp32_config_get(const struct device *dev, return -ENOTSUP; } + if (uart_hal_is_mode_rs485_half_duplex(&data->hal)) { + cfg->flow_ctrl = UART_CFG_FLOW_CTRL_RS485; + } + return 0; } #endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */ @@ -293,6 +296,8 @@ static int uart_esp32_configure(const struct device *dev, const struct uart_conf return -ENOTSUP; } + uart_hal_set_mode(&data->hal, UART_MODE_UART); + switch (cfg->flow_ctrl) { case UART_CFG_FLOW_CTRL_NONE: uart_hal_set_hw_flow_ctrl(&data->hal, UART_HW_FLOWCTRL_DISABLE, 0); @@ -300,6 +305,9 @@ static int uart_esp32_configure(const struct device *dev, const struct uart_conf case UART_CFG_FLOW_CTRL_RTS_CTS: uart_hal_set_hw_flow_ctrl(&data->hal, UART_HW_FLOWCTRL_CTS_RTS, 10); break; + case UART_CFG_FLOW_CTRL_RS485: + uart_hal_set_mode(&data->hal, UART_MODE_RS485_HALF_DUPLEX); + break; default: return -ENOTSUP; } @@ -313,8 +321,7 @@ static int uart_esp32_configure(const struct device *dev, const struct uart_conf #ifdef CONFIG_UART_INTERRUPT_DRIVEN -static int uart_esp32_fifo_fill(const struct device *dev, - const uint8_t *tx_data, int len) +static int uart_esp32_fifo_fill(const struct device *dev, const uint8_t *tx_data, int len) { struct uart_esp32_data *data = dev->data; uint32_t written = 0; @@ -327,8 +334,7 @@ static int uart_esp32_fifo_fill(const struct device *dev, return written; } -static int uart_esp32_fifo_read(const struct device *dev, - uint8_t *rx_data, const int len) +static int uart_esp32_fifo_read(const struct device *dev, uint8_t *rx_data, const int len) { struct uart_esp32_data *data = dev->data; const int num_rx = uart_hal_get_rxfifo_len(&data->hal); @@ -362,7 +368,7 @@ static int uart_esp32_irq_tx_ready(const struct device *dev) struct uart_esp32_data *data = dev->data; return (uart_hal_get_txfifo_len(&data->hal) > 0 && - uart_hal_get_intr_ena_status(&data->hal) & UART_INTR_TXFIFO_EMPTY); + uart_hal_get_intr_ena_status(&data->hal) & UART_INTR_TXFIFO_EMPTY); } static void uart_esp32_irq_rx_disable(const struct device *dev) @@ -420,8 +426,7 @@ static int uart_esp32_irq_update(const struct device *dev) return 1; } -static void uart_esp32_irq_callback_set(const struct device *dev, - uart_irq_callback_user_data_t cb, +static void uart_esp32_irq_callback_set(const struct device *dev, uart_irq_callback_user_data_t cb, void *cb_data) { struct uart_esp32_data *data = dev->data; @@ -880,12 +885,8 @@ static int uart_esp32_init(const struct device *dev) int ret = uart_esp32_configure(dev, &data->uart_config); #if CONFIG_UART_INTERRUPT_DRIVEN || CONFIG_UART_ASYNC_API - data->irq_line = - esp_intr_alloc(config->irq_source, - 0, - (ISR_HANDLER)uart_esp32_isr, - (void *)dev, - NULL); + data->irq_line = esp_intr_alloc(config->irq_source, 0, (ISR_HANDLER)uart_esp32_isr, + (void *)dev, NULL); #endif #if CONFIG_UART_ASYNC_API if (config->dma_dev) { @@ -912,7 +913,7 @@ static const DRAM_ATTR struct uart_driver_api uart_esp32_api = { .poll_out = uart_esp32_poll_out, .err_check = uart_esp32_err_check, #ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE - .configure = uart_esp32_configure, + .configure = uart_esp32_configure, .config_get = uart_esp32_config_get, #endif #ifdef CONFIG_UART_INTERRUPT_DRIVEN @@ -930,7 +931,7 @@ static const DRAM_ATTR struct uart_driver_api uart_esp32_api = { .irq_is_pending = uart_esp32_irq_is_pending, .irq_update = uart_esp32_irq_update, .irq_callback_set = uart_esp32_irq_callback_set, -#endif /* CONFIG_UART_INTERRUPT_DRIVEN */ +#endif /* CONFIG_UART_INTERRUPT_DRIVEN */ #if CONFIG_UART_ASYNC_API .callback_set = uart_esp32_async_callback_set, .tx = uart_esp32_async_tx, @@ -972,9 +973,12 @@ static const DRAM_ATTR struct uart_driver_api uart_esp32_api = { .parity = UART_CFG_PARITY_NONE, \ .stop_bits = UART_CFG_STOP_BITS_1, \ .data_bits = UART_CFG_DATA_BITS_8, \ - .flow_ctrl = COND_CODE_1(DT_NODE_HAS_PROP(idx, hw_flow_control), \ - (UART_CFG_FLOW_CTRL_RTS_CTS), \ - (UART_CFG_FLOW_CTRL_NONE))}, \ + .flow_ctrl = MAX(COND_CODE_1(DT_INST_PROP(idx, hw_rs485_hd_mode), \ + (UART_CFG_FLOW_CTRL_RS485), \ + (UART_CFG_FLOW_CTRL_NONE)), \ + COND_CODE_1(DT_INST_PROP(idx, hw_flow_control), \ + (UART_CFG_FLOW_CTRL_RTS_CTS), \ + (UART_CFG_FLOW_CTRL_NONE)))}, \ .hal = \ { \ .dev = (uart_dev_t *)DT_INST_REG_ADDR(idx), \ diff --git a/dts/bindings/serial/espressif,esp32-uart.yaml b/dts/bindings/serial/espressif,esp32-uart.yaml index 82f114476619..313d9039a5b5 100644 --- a/dts/bindings/serial/espressif,esp32-uart.yaml +++ b/dts/bindings/serial/espressif,esp32-uart.yaml @@ -13,3 +13,11 @@ properties: pinctrl-names: required: true + + hw-rs485-hd-mode: + type: boolean + description: | + Enable the hardware RS485 half duplex mode. + Overrides hw-flow-control if both are set. + Using this mode, the pin assigned to DTR + is asserted during transmission. From 5a0834f16f1aaf8b204faa35272be43d8c8a0734 Mon Sep 17 00:00:00 2001 From: Dean Sellers Date: Fri, 17 Mar 2023 09:35:06 +1000 Subject: [PATCH 0661/1906] west: hal_espressif: Update to latest revision Espressif hal to 8ee9650. Signed-off-by: Dean Sellers --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 732d105dc354..29cba5455125 100644 --- a/west.yml +++ b/west.yml @@ -57,7 +57,7 @@ manifest: groups: - hal - name: hal_espressif - revision: d2564ca5c14439888f7c4351884a2cf4db517a33 + revision: 8ee96508f329c7e59fcbf739f060cf12082dd805 path: modules/hal/espressif west-commands: west/west-commands.yml groups: From fc3d8a83aa0c40ee244124714dba4f087f39577f Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Mon, 20 Mar 2023 11:47:42 +0100 Subject: [PATCH 0662/1906] tests bsim/net: Add simple echo test over 802.15.4 Add a simple selfchecking test for the 15.4 stack, based on the echo client / server sample apps. It relies on the bs_tests hooks to register a test timer callback, which after a deadline will check how many packets the echo client has got back as expected, and if over a threshold considers the test passed. Signed-off-by: Alberto Escolar Piedras --- tests/bsim/compile.sh | 1 + tests/bsim/net/compile.sh | 26 ++++++ .../bsim/net/sockets/echo_test/CMakeLists.txt | 47 +++++++++++ tests/bsim/net/sockets/echo_test/Kconfig | 4 + .../net/sockets/echo_test/overlay-802154.conf | 20 +++++ tests/bsim/net/sockets/echo_test/prj.conf | 51 +++++++++++ .../net/sockets/echo_test/src/echo_test.c | 84 +++++++++++++++++++ .../net/sockets/echo_test/src/test_main.c | 14 ++++ .../tests_scripts/echo_test_802154.sh | 30 +++++++ 9 files changed, 277 insertions(+) create mode 100755 tests/bsim/net/compile.sh create mode 100644 tests/bsim/net/sockets/echo_test/CMakeLists.txt create mode 100644 tests/bsim/net/sockets/echo_test/Kconfig create mode 100644 tests/bsim/net/sockets/echo_test/overlay-802154.conf create mode 100644 tests/bsim/net/sockets/echo_test/prj.conf create mode 100644 tests/bsim/net/sockets/echo_test/src/echo_test.c create mode 100644 tests/bsim/net/sockets/echo_test/src/test_main.c create mode 100755 tests/bsim/net/sockets/echo_test/tests_scripts/echo_test_802154.sh diff --git a/tests/bsim/compile.sh b/tests/bsim/compile.sh index beec89f937c9..788d69670f4c 100755 --- a/tests/bsim/compile.sh +++ b/tests/bsim/compile.sh @@ -22,5 +22,6 @@ run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/audio/compile.sh run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/host/compile.sh run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/ll/compile.sh run_in_background ${ZEPHYR_BASE}/tests/bsim/bluetooth/mesh/compile.sh +run_in_background ${ZEPHYR_BASE}/tests/bsim/net/compile.sh wait_for_background_jobs diff --git a/tests/bsim/net/compile.sh b/tests/bsim/net/compile.sh new file mode 100755 index 000000000000..a21832b49318 --- /dev/null +++ b/tests/bsim/net/compile.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +# Compile all the applications needed by the network bsim tests + +#set -x #uncomment this line for debugging +set -ue + +: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" +: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" +: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ + directory}" + +WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" +BOARD="${BOARD:-nrf52_bsim}" +BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" + +mkdir -p ${WORK_DIR} + +source ${ZEPHYR_BASE}/tests/bsim/compile.source + +app=samples/net/sockets/echo_server conf_overlay=overlay-802154.conf compile +app=tests/bsim/net/sockets/echo_test conf_overlay=overlay-802154.conf compile + +wait_for_background_jobs diff --git a/tests/bsim/net/sockets/echo_test/CMakeLists.txt b/tests/bsim/net/sockets/echo_test/CMakeLists.txt new file mode 100644 index 000000000000..f47c68435c51 --- /dev/null +++ b/tests/bsim/net/sockets/echo_test/CMakeLists.txt @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(sockets_echo_client_self_test) + +if(CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED AND + (CONFIG_NET_SAMPLE_PSK_HEADER_FILE STREQUAL "dummy_psk.h")) + add_custom_target(development_psk + COMMAND ${CMAKE_COMMAND} -E echo "----------------------------------------------------------" + COMMAND ${CMAKE_COMMAND} -E echo "--- WARNING: Using dummy PSK! Only suitable for ---" + COMMAND ${CMAKE_COMMAND} -E echo "--- development. Set NET_SAMPLE_PSK_HEADER_FILE to use ---" + COMMAND ${CMAKE_COMMAND} -E echo "--- own pre-shared key. ---" + COMMAND ${CMAKE_COMMAND} -E echo "----------------------------------------------------------" + ) + add_dependencies(app development_psk) +endif() + +set(echo_client_path ${ZEPHYR_BASE}/samples/net/sockets/echo_client) + +target_include_directories(app PRIVATE ${echo_client_path}/src/) + +target_sources(app PRIVATE + src/echo_test.c + src/test_main.c +) + +target_sources( app PRIVATE ${echo_client_path}/src/echo-client.c) +target_sources_ifdef(CONFIG_NET_UDP app PRIVATE ${echo_client_path}/src/udp.c) +target_sources_ifdef(CONFIG_NET_TCP app PRIVATE ${echo_client_path}/src/tcp.c) +target_sources_ifdef(CONFIG_NET_VLAN app PRIVATE ${echo_client_path}/src/vlan.c) + +include(${ZEPHYR_BASE}/samples/net/common/common.cmake) + +set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/) + +generate_inc_file_for_target( + app + ${echo_client_path}/src/echo-apps-cert.der + ${gen_dir}/echo-apps-cert.der.inc + ) + +zephyr_include_directories( + $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ + $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ + ) diff --git a/tests/bsim/net/sockets/echo_test/Kconfig b/tests/bsim/net/sockets/echo_test/Kconfig new file mode 100644 index 000000000000..7c48b4fca91d --- /dev/null +++ b/tests/bsim/net/sockets/echo_test/Kconfig @@ -0,0 +1,4 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +source "${ZEPHYR_BASE}/samples/net/sockets/echo_client/Kconfig" diff --git a/tests/bsim/net/sockets/echo_test/overlay-802154.conf b/tests/bsim/net/sockets/echo_test/overlay-802154.conf new file mode 100644 index 000000000000..afd9259ee5ab --- /dev/null +++ b/tests/bsim/net/sockets/echo_test/overlay-802154.conf @@ -0,0 +1,20 @@ +# This file content is just a copy of the echo client overlay-802154.conf + +CONFIG_BT=n + +# Disable TCP and IPv4 (TCP disabled to avoid heavy traffic) +CONFIG_NET_TCP=n +CONFIG_NET_IPV4=n + +CONFIG_NET_CONFIG_NEED_IPV6=y +CONFIG_NET_CONFIG_NEED_IPV4=n +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_CONFIG_PEER_IPV4_ADDR="" +CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2" +CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::1" + +CONFIG_NET_L2_IEEE802154=y +CONFIG_NET_L2_IEEE802154_SHELL=y +CONFIG_NET_L2_IEEE802154_LOG_LEVEL_INF=y + +CONFIG_NET_CONFIG_IEEE802154_CHANNEL=26 diff --git a/tests/bsim/net/sockets/echo_test/prj.conf b/tests/bsim/net/sockets/echo_test/prj.conf new file mode 100644 index 000000000000..e0bb985c985b --- /dev/null +++ b/tests/bsim/net/sockets/echo_test/prj.conf @@ -0,0 +1,51 @@ +# This file content is just a copy of the echo client prj.conf + +# Generic networking options +CONFIG_NETWORKING=y +CONFIG_NET_UDP=y +CONFIG_NET_TCP=y +CONFIG_NET_IPV6=y +CONFIG_NET_IPV4=y +CONFIG_NET_SOCKETS=y +CONFIG_NET_SOCKETS_POSIX_NAMES=y +CONFIG_NET_SOCKETS_POLL_MAX=4 +CONFIG_NET_CONNECTION_MANAGER=y + +# Kernel options +CONFIG_MAIN_STACK_SIZE=2048 +CONFIG_ENTROPY_GENERATOR=y +CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_INIT_STACKS=y + +# Logging +CONFIG_NET_LOG=y +CONFIG_LOG=y +CONFIG_NET_STATISTICS=y +CONFIG_PRINTK=y + +# Network buffers +CONFIG_NET_PKT_RX_COUNT=16 +CONFIG_NET_PKT_TX_COUNT=16 +CONFIG_NET_BUF_RX_COUNT=80 +CONFIG_NET_BUF_TX_COUNT=80 +CONFIG_NET_CONTEXT_NET_PKT_POOL=y + +# IP address options +CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3 +CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4 +CONFIG_NET_MAX_CONTEXTS=10 + +# Network shell +CONFIG_NET_SHELL=y + +# The addresses are selected so that qemu<->qemu connectivity works ok. +# For linux<->qemu connectivity, create a new conf file and swap the +# addresses (so that peer address is ending to 2). +CONFIG_NET_CONFIG_SETTINGS=y +CONFIG_NET_CONFIG_NEED_IPV6=y +CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2" +CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::1" +CONFIG_NET_CONFIG_NEED_IPV4=y +CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.2" +CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.1" +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 diff --git a/tests/bsim/net/sockets/echo_test/src/echo_test.c b/tests/bsim/net/sockets/echo_test/src/echo_test.c new file mode 100644 index 000000000000..e1ac2e1c418b --- /dev/null +++ b/tests/bsim/net/sockets/echo_test/src/echo_test.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * Copyright (c) 2017-2019 Oticon A/S + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "bs_types.h" +#include "bs_tracing.h" +#include "time_machine.h" +#include "bstests.h" + +#include "common.h" /* From echo_client */ + +#define WAIT_TIME 20 /* Seconds */ +#define PASS_THRESHOLD 100 /* Packets */ + +extern enum bst_result_t bst_result; + +#define FAIL(...) \ + do { \ + bst_result = Failed; \ + bs_trace_error_time_line(__VA_ARGS__); \ + } while (0) + +#define PASS(...) \ + do { \ + bst_result = Passed; \ + bs_trace_info_time(1, __VA_ARGS__); \ + } while (0) + +static void test_echo_client_init(void) +{ + /* We set an absolute deadline in 30 seconds */ + bst_ticker_set_next_tick_absolute(WAIT_TIME*1e6); + bst_result = In_progress; +} + +static void test_echo_client_tick(bs_time_t HW_device_time) +{ + /* + * If in WAIT_TIME seconds we did not get enough packets through + * we consider the test failed + */ + + extern struct configs conf; + int packet_count = 0; + + if ((IS_ENABLED(CONFIG_NET_TCP)) && IS_ENABLED(CONFIG_NET_IPV6)) { + packet_count = conf.ipv6.tcp.counter; + } else if ((IS_ENABLED(CONFIG_NET_UDP)) && IS_ENABLED(CONFIG_NET_IPV6)) { + packet_count = conf.ipv6.udp.counter; + } + + bs_trace_info_time(2, "%i packets received, expected >= %i\n", + packet_count, PASS_THRESHOLD); + + if (packet_count >= PASS_THRESHOLD) { + PASS("echo_client PASSED\n"); + bs_trace_exit("Done, disconnecting from simulation\n"); + } else { + FAIL("echo_client FAILED (Did not pass after %i seconds)\n", + WAIT_TIME); + } +} + +static const struct bst_test_instance test_echo_client[] = { + { + .test_id = "echo_client", + .test_descr = "Test based on the echo client sample. " + "It expects to be connected to a compatible echo server, " + "waits for 20 seconds, and checks how many packets have been " + "exchanged correctly", + .test_post_init_f = test_echo_client_init, + .test_tick_f = test_echo_client_tick, + }, + BSTEST_END_MARKER +}; + +struct bst_test_list *test_echo_client_install(struct bst_test_list *tests) +{ + tests = bst_add_tests(tests, test_echo_client); + return tests; +} diff --git a/tests/bsim/net/sockets/echo_test/src/test_main.c b/tests/bsim/net/sockets/echo_test/src/test_main.c new file mode 100644 index 000000000000..9e65c8041eee --- /dev/null +++ b/tests/bsim/net/sockets/echo_test/src/test_main.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "bstests.h" + +extern struct bst_test_list *test_echo_client_install(struct bst_test_list *tests); + +bst_test_install_t test_installers[] = { + test_echo_client_install, + NULL +}; diff --git a/tests/bsim/net/sockets/echo_test/tests_scripts/echo_test_802154.sh b/tests/bsim/net/sockets/echo_test/tests_scripts/echo_test_802154.sh new file mode 100755 index 000000000000..2f5f64cd79a9 --- /dev/null +++ b/tests/bsim/net/sockets/echo_test/tests_scripts/echo_test_802154.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Copyright 2018 Oticon A/S +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +# Simple selfchecking test for the 15.4 stack, based on the echo client / server sample apps +# It relies on the bs_tests hooks to register a test timer callback, which after a deadline +# will check how many packets the echo client has got back as expected, and if over a threshold +# it considers the test passed + +simulation_id="echo_test_154" +verbosity_level=2 + +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + +EXECUTE_TIMEOUT=100 + +cd ${BSIM_OUT_PATH}/bin + +Execute ./bs_${BOARD}_tests_bsim_net_sockets_echo_test_prj_conf_overlay-802154_conf \ + -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1 \ + -testid=echo_client + +Execute ./bs_${BOARD}_samples_net_sockets_echo_server_prj_conf_overlay-802154_conf\ + -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=1 \ + +Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ + -D=2 -sim_length=60e6 -argschannel -at=40 $@ + +wait_for_background_jobs #Wait for all programs in background and return != 0 if any fails From 6decd2d55f33b547d7e39f323ea878e44fd71034 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Tue, 21 Mar 2023 11:58:53 +0100 Subject: [PATCH 0663/1906] samples echo_client/server: Add overlay for nrf52_bsim To disable the flash by default so the openthread RAM settings backend is used instead. This allows using this samples with the overlay-ot.conf directly in the simulated nrf52_bsim. Signed-off-by: Alberto Escolar Piedras --- samples/net/sockets/echo_client/boards/nrf52_bsim.conf | 4 ++++ samples/net/sockets/echo_server/boards/nrf52_bsim.conf | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 samples/net/sockets/echo_client/boards/nrf52_bsim.conf create mode 100644 samples/net/sockets/echo_server/boards/nrf52_bsim.conf diff --git a/samples/net/sockets/echo_client/boards/nrf52_bsim.conf b/samples/net/sockets/echo_client/boards/nrf52_bsim.conf new file mode 100644 index 000000000000..367c31f24e80 --- /dev/null +++ b/samples/net/sockets/echo_client/boards/nrf52_bsim.conf @@ -0,0 +1,4 @@ +# The nrf52 HW models do not have a flash model yet. Even though it is possible to use different +# replacements, the easiest one is to disable the flash, so when configured with openthread +# it will use the OPENTHREAD_SETTINGS_RAM +CONFIG_FLASH=n diff --git a/samples/net/sockets/echo_server/boards/nrf52_bsim.conf b/samples/net/sockets/echo_server/boards/nrf52_bsim.conf new file mode 100644 index 000000000000..367c31f24e80 --- /dev/null +++ b/samples/net/sockets/echo_server/boards/nrf52_bsim.conf @@ -0,0 +1,4 @@ +# The nrf52 HW models do not have a flash model yet. Even though it is possible to use different +# replacements, the easiest one is to disable the flash, so when configured with openthread +# it will use the OPENTHREAD_SETTINGS_RAM +CONFIG_FLASH=n From b6c6de386cd79e641c72f4704ce65e5be0284cd9 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Tue, 21 Mar 2023 12:20:12 +0100 Subject: [PATCH 0664/1906] tests bsim/net: Add simple echo test over OpenThread Expand the tests/bsim/net/sockets/echo_test with a variant using OpenThread Signed-off-by: Alberto Escolar Piedras --- tests/bsim/net/compile.sh | 3 ++ .../sockets/echo_test/boards/nrf52_bsim.conf | 4 ++ .../net/sockets/echo_test/overlay-ot.conf | 43 +++++++++++++++++++ .../net/sockets/echo_test/src/echo_test.c | 6 +++ .../echo_test/tests_scripts/echo_test_ot.sh | 30 +++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 tests/bsim/net/sockets/echo_test/boards/nrf52_bsim.conf create mode 100644 tests/bsim/net/sockets/echo_test/overlay-ot.conf create mode 100755 tests/bsim/net/sockets/echo_test/tests_scripts/echo_test_ot.sh diff --git a/tests/bsim/net/compile.sh b/tests/bsim/net/compile.sh index a21832b49318..e134d7ee5d65 100755 --- a/tests/bsim/net/compile.sh +++ b/tests/bsim/net/compile.sh @@ -23,4 +23,7 @@ source ${ZEPHYR_BASE}/tests/bsim/compile.source app=samples/net/sockets/echo_server conf_overlay=overlay-802154.conf compile app=tests/bsim/net/sockets/echo_test conf_overlay=overlay-802154.conf compile +app=samples/net/sockets/echo_server conf_overlay=overlay-ot.conf compile +app=tests/bsim/net/sockets/echo_test conf_overlay=overlay-ot.conf compile + wait_for_background_jobs diff --git a/tests/bsim/net/sockets/echo_test/boards/nrf52_bsim.conf b/tests/bsim/net/sockets/echo_test/boards/nrf52_bsim.conf new file mode 100644 index 000000000000..367c31f24e80 --- /dev/null +++ b/tests/bsim/net/sockets/echo_test/boards/nrf52_bsim.conf @@ -0,0 +1,4 @@ +# The nrf52 HW models do not have a flash model yet. Even though it is possible to use different +# replacements, the easiest one is to disable the flash, so when configured with openthread +# it will use the OPENTHREAD_SETTINGS_RAM +CONFIG_FLASH=n diff --git a/tests/bsim/net/sockets/echo_test/overlay-ot.conf b/tests/bsim/net/sockets/echo_test/overlay-ot.conf new file mode 100644 index 000000000000..83ead1cf289d --- /dev/null +++ b/tests/bsim/net/sockets/echo_test/overlay-ot.conf @@ -0,0 +1,43 @@ +# This file content is just a copy of the echo client overlay-ot.conf + +CONFIG_NEWLIB_LIBC=y + +# Disable TCP and IPv4 (TCP disabled to avoid heavy traffic) +CONFIG_NET_TCP=n +CONFIG_NET_IPV4=n + +CONFIG_NET_IPV6_NBR_CACHE=n +CONFIG_NET_IPV6_MLD=n +CONFIG_NET_CONFIG_NEED_IPV4=n +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_CONFIG_PEER_IPV4_ADDR="" + +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 +CONFIG_MAIN_STACK_SIZE=2560 + +# Enable OpenThread shell +CONFIG_SHELL=y +CONFIG_OPENTHREAD_SHELL=y +CONFIG_SHELL_STACK_SIZE=3072 + +CONFIG_NET_L2_OPENTHREAD=y + +CONFIG_OPENTHREAD_DEBUG=y +CONFIG_OPENTHREAD_L2_DEBUG=y +CONFIG_OPENTHREAD_L2_LOG_LEVEL_INF=y + +CONFIG_OPENTHREAD_CHANNEL=26 +CONFIG_OPENTHREAD_NETWORKKEY="00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff" + +CONFIG_NET_CONFIG_MY_IPV6_ADDR="fdde:ad00:beef::1" +CONFIG_NET_CONFIG_PEER_IPV6_ADDR="fdde:ad00:beef::2" + +# mbedTLS tweaks +CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=768 + +# A sample configuration to enable Thread Joiner, uncomment if needed +#CONFIG_OPENTHREAD_JOINER=y +#CONFIG_OPENTHREAD_JOINER_AUTOSTART=y + +# Enable diagnostic module, uncomment if needed +#CONFIG_OPENTHREAD_DIAG=y diff --git a/tests/bsim/net/sockets/echo_test/src/echo_test.c b/tests/bsim/net/sockets/echo_test/src/echo_test.c index e1ac2e1c418b..0a9e73b45112 100644 --- a/tests/bsim/net/sockets/echo_test/src/echo_test.c +++ b/tests/bsim/net/sockets/echo_test/src/echo_test.c @@ -12,7 +12,13 @@ #include "common.h" /* From echo_client */ +#if defined(CONFIG_NET_L2_OPENTHREAD) +/* Open thread takes ~15 seconds to connect in ideal conditions */ +#define WAIT_TIME 25 /* Seconds */ +#else #define WAIT_TIME 20 /* Seconds */ +#endif + #define PASS_THRESHOLD 100 /* Packets */ extern enum bst_result_t bst_result; diff --git a/tests/bsim/net/sockets/echo_test/tests_scripts/echo_test_ot.sh b/tests/bsim/net/sockets/echo_test/tests_scripts/echo_test_ot.sh new file mode 100755 index 000000000000..9f9be1cccade --- /dev/null +++ b/tests/bsim/net/sockets/echo_test/tests_scripts/echo_test_ot.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Copyright 2018 Oticon A/S +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +# Simple selfchecking test for openthread, based on the echo client / server sample apps +# It relies on the bs_tests hooks to register a test timer callback, which after a deadline +# will check how many packets the echo client has got back as expected, and if over a threshold +# it considers the test passed + +simulation_id="echo_test_ot" +verbosity_level=2 + +source ${ZEPHYR_BASE}/tests/bsim/sh_common.source + +EXECUTE_TIMEOUT=100 + +cd ${BSIM_OUT_PATH}/bin + +Execute ./bs_${BOARD}_tests_bsim_net_sockets_echo_test_prj_conf_overlay-ot_conf \ + -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1 \ + -testid=echo_client + +Execute ./bs_${BOARD}_samples_net_sockets_echo_server_prj_conf_overlay-ot_conf\ + -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=1 \ + +Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ + -D=2 -sim_length=60e6 -argschannel -at=40 $@ + +wait_for_background_jobs #Wait for all programs in background and return != 0 if any fails From a89b86a99eeb1a54afb4f0569dd823f54df69269 Mon Sep 17 00:00:00 2001 From: Nazar Palamar Date: Thu, 16 Feb 2023 12:38:08 +0200 Subject: [PATCH 0665/1906] modules: hal_infineon: Added support of BT controller fw blobs - Added Cmakefiles for modules\hal_infineon\btstack-integration\, where handle generation of Bluetooth include blob from HCD binary. - Supported following device/modules: -- CYW43012/MURATA-1LV module -- CYW4343W/MURATA-1DX module -- CYW43439/MURATA-1YN module -- CYW4373/STERLING-LWB5plus module - Added possibility to use user provided BT Firmware HCD file via kconfig (path must be defined in CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB) - Updated top makefile Signed-off-by: Nazar Palamar --- modules/hal_infineon/CMakeLists.txt | 6 ++- .../btstack-integration/CMakeLists.txt | 49 +++++++++++++++++++ .../w_bt_firmware_controller.c | 17 +++++++ west.yml | 2 +- 4 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 modules/hal_infineon/btstack-integration/CMakeLists.txt create mode 100644 modules/hal_infineon/btstack-integration/w_bt_firmware_controller.c diff --git a/modules/hal_infineon/CMakeLists.txt b/modules/hal_infineon/CMakeLists.txt index 4e5989d2b960..7dae3dfe8484 100644 --- a/modules/hal_infineon/CMakeLists.txt +++ b/modules/hal_infineon/CMakeLists.txt @@ -19,8 +19,6 @@ if (CONFIG_SOC_FAMILY_INFINEON_CAT1A OR CONFIG_SOC_FAMILY_PSOC6) add_subdirectory(mtb-pdl-cat1) endif() - - if (CONFIG_SOC_FAMILY_INFINEON_CAT1A) ## Add mtb-hal-cat1 sources for CAT1 devices add_subdirectory(mtb-hal-cat1) @@ -29,5 +27,9 @@ if (CONFIG_SOC_FAMILY_INFINEON_CAT1A) if(CONFIG_SOC_PSOC6_CM0P_IMAGE_SLEEP) add_subdirectory(cat1cm0p) endif() +endif() +## Add btstack-integration for CYW43xx BT devices +if (CONFIG_BT_CYW43XXX) + add_subdirectory(btstack-integration) endif() diff --git a/modules/hal_infineon/btstack-integration/CMakeLists.txt b/modules/hal_infineon/btstack-integration/CMakeLists.txt new file mode 100644 index 000000000000..ef6a64cff3dd --- /dev/null +++ b/modules/hal_infineon/btstack-integration/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright (c) 2022 Cypress Semiconductor Corporation. +# +# SPDX-License-Identifier: Apache-2.0 + +set(hal_dir ${ZEPHYR_HAL_INFINEON_MODULE_DIR}) +set(hal_ble_dir ${hal_dir}/bluetooth-freertos) +set(hal_blobs_dir ${hal_dir}/zephyr/blobs/img/bluetooth/firmware) +set(blob_gen_inc_file ${ZEPHYR_BINARY_DIR}/include/generated/bt_firmware.hcd.inc) + +######################################################################################### +# BT firmware +######################################################################################### +# CYW43012 modules +if(CONFIG_CYW43012_MURATA_1LV) + set(blob_hcd_file ${hal_blobs_dir}/COMPONENT_43012/COMPONENT_MURATA-1LV/bt_firmware.hcd) +endif() + +# CYW4343W modules +if(CONFIG_CYW4343W_MURATA_1DX) + set(blob_hcd_file ${hal_blobs_dir}/COMPONENT_4343W/COMPONENT_MURATA-1DX/bt_firmware.hcd) +endif() + +# CYW43439 modules +if(CONFIG_CYW43439_MURATA_1YN) + set(blob_hcd_file ${hal_blobs_dir}/COMPONENT_43439/COMPONENT_MURATA-1YN/bt_firmware.hcd) +endif() + +# CYW4373 modules +if(CONFIG_CYW4373_STERLING_LWB5PLUS) + set(blob_hcd_file ${hal_blobs_dir}/COMPONENT_4373/COMPONENT_STERLING-LWB5plus/bt_firmware.hcd) +endif() + +# use user provided FIRMWARE HCD file (path must be defined in CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB) +if(CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB) + # Allowed to pass absolute path to HCD blob file, or relative path from Application folder. + if(IS_ABSOLUTE ${CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB}) + set(blob_hcd_file ${CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB}) + else() + set(blob_hcd_file ${APPLICATION_SOURCE_DIR}/${CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB}) + endif() +endif() + +# generate Bluetooth include blob from HCD binary +if(EXISTS ${blob_hcd_file}) + message(INFO " generate include of blob Bluetooth file: ${blob_hcd_file}") + + generate_inc_file_for_target(app ${blob_hcd_file} ${blob_gen_inc_file}) + zephyr_library_sources(${CMAKE_CURRENT_SOURCE_DIR}/w_bt_firmware_controller.c) +endif() diff --git a/modules/hal_infineon/btstack-integration/w_bt_firmware_controller.c b/modules/hal_infineon/btstack-integration/w_bt_firmware_controller.c new file mode 100644 index 000000000000..1fd05cbcb1bc --- /dev/null +++ b/modules/hal_infineon/btstack-integration/w_bt_firmware_controller.c @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 Cypress Semiconductor Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +const uint8_t brcm_patchram_format = 0x01; +/* Configuration Data Records (Write_RAM) */ +#ifndef FW_DATBLOCK_SEPARATE_FROM_APPLICATION +const uint8_t brcm_patchram_buf[] = { + #include +}; + +const int brcm_patch_ram_length = sizeof(brcm_patchram_buf); +#endif /* FW_DATBLOCK_SEPARATE_FROM_APPLICATION */ diff --git a/west.yml b/west.yml index 29cba5455125..21f53a7bce10 100644 --- a/west.yml +++ b/west.yml @@ -73,7 +73,7 @@ manifest: groups: - hal - name: hal_infineon - revision: 8485083ad91d3e2cc5d706da3464716718a6a42e + revision: 15d8a4278611fb2dc6ca52108c36ec1f4caab14e path: modules/hal/infineon groups: - hal From f91e35d44734b5a7dd508c296386c85b791e222e Mon Sep 17 00:00:00 2001 From: Nazar Palamar Date: Fri, 29 Apr 2022 10:34:00 +0300 Subject: [PATCH 0666/1906] driver: bluetooth: Added Infineon cyw43xxx BT driver Added initial version of Infineon cyw43xxx BT ( H4 HCI extension drivers/bluetooth/hci/CMakeLists.txt) Add initial version of binding file for Infineon CYW43xx BT HCI extension driver. Signed-off-by: Nazar Palamar --- drivers/bluetooth/hci/CMakeLists.txt | 1 + drivers/bluetooth/hci/Kconfig | 13 + drivers/bluetooth/hci/Kconfig.infineon | 137 ++++++++ drivers/bluetooth/hci/cyw43xxx.c | 294 ++++++++++++++++++ .../bluetooth/infineon,cyw43xxx-bt-hci.yaml | 75 +++++ 5 files changed, 520 insertions(+) create mode 100644 drivers/bluetooth/hci/Kconfig.infineon create mode 100644 drivers/bluetooth/hci/cyw43xxx.c create mode 100644 dts/bindings/bluetooth/infineon,cyw43xxx-bt-hci.yaml diff --git a/drivers/bluetooth/hci/CMakeLists.txt b/drivers/bluetooth/hci/CMakeLists.txt index 1e1f61ac64e0..236752ca5c34 100644 --- a/drivers/bluetooth/hci/CMakeLists.txt +++ b/drivers/bluetooth/hci/CMakeLists.txt @@ -1,6 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_library_sources_ifdef(CONFIG_BT_B91 hci_b91.c) +zephyr_library_sources_ifdef(CONFIG_BT_CYW43XXX cyw43xxx.c) zephyr_library_sources_ifdef(CONFIG_BT_ESP32 hci_esp32.c) zephyr_library_sources_ifdef(CONFIG_BT_H4 h4.c) zephyr_library_sources_ifdef(CONFIG_BT_H5 h5.c) diff --git a/drivers/bluetooth/hci/Kconfig b/drivers/bluetooth/hci/Kconfig index d243428729d1..c5913b7d90af 100644 --- a/drivers/bluetooth/hci/Kconfig +++ b/drivers/bluetooth/hci/Kconfig @@ -109,6 +109,19 @@ config BT_STM32_IPM_RX_STACK_SIZE depends on BT_STM32_IPM default 512 +menuconfig BT_CYW43XXX + bool "CYW43XXX BT connectivity" + default y + select BT_HCI_SETUP + depends on GPIO + depends on DT_HAS_INFINEON_CYW43XXX_BT_HCI_ENABLED + depends on BT_H4 + help + Infineon's AIROC™ Wi-Fi & combos portfolio integrates + IEEE 802.11a/b/g/n/ac/ax Wi-Fi and Bluetooth® 5.2 in a single-chip + solution to enable small-form-factor IoT designs. +source "drivers/bluetooth/hci/Kconfig.infineon" + config BT_DRIVER_QUIRK_NO_AUTO_DLE bool "Host auto-initiated Data Length Update quirk" depends on BT_AUTO_DATA_LEN_UPDATE diff --git a/drivers/bluetooth/hci/Kconfig.infineon b/drivers/bluetooth/hci/Kconfig.infineon new file mode 100644 index 000000000000..acbbfe2ed12a --- /dev/null +++ b/drivers/bluetooth/hci/Kconfig.infineon @@ -0,0 +1,137 @@ +# Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon company) or +# an affiliate of Cypress Semiconductor Corporation +# SPDX-License-Identifier: Apache-2.0 + +if BT_CYW43XXX + +choice CYW43XXX_PART + prompt "Select CYW43XXX part" + +config CYW4343W + bool "CYW4343W" + help + Enable Infineon CYW4343W BLE connectivity, + More information about CYW4343W device you can find on + https://www.infineon.com/cms/en/product/wireless-connectivity/airoc-wi-fi-plus-bluetooth-combos/cyw4343w/ + +config CYW4373 + bool "CYW4373" + help + Enable Infineon CYW4373 BLE connectivity, + More information about CYW4373 device you can find on + https://www.infineon.com/cms/en/product/wireless-connectivity/airoc-wi-fi-plus-bluetooth-combos/cyw4373/ + +config CYW43012 + bool "CYW43012" + help + Enable Infineon CYW43012 BLE connectivity, + More information about CYW43012 device you can find on + https://www.infineon.com/cms/en/product/wireless-connectivity/airoc-wi-fi-plus-bluetooth-combos/cyw43012/ + +config CYW43438 + bool "CYW43438" + help + Enable Infineon CYW43438 BLE connectivity, + More information about CYW43438 device you can find on + https://www.infineon.com/cms/en/product/wireless-connectivity/airoc-wi-fi-plus-bluetooth-combos/cyw43438/ + +config CYW43439 + bool "CYW43439" + help + Enable Infineon CYW43439 BLE connectivity, + More information about CYW43439 device you can find on + https://www.infineon.com/cms/en/product/wireless-connectivity/airoc-wi-fi-plus-bluetooth-combos/cyw43439/ + +config BT_CYW43XXX_CUSTOM + bool "Custom CYW43xx device/module" + help + Select Custom CYW43xx device/module. For this option, + user must to provide path to BT firmware HCD file for + custom or vendor CYW43xx modules in CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB. + +endchoice + +choice CYW43012_MODULE + prompt "Select CYW43012 module" + depends on CYW43012 + +config CYW43012_MURATA_1LV + bool "MURATA-1LV" + help + Murata Type 1LV module based on Infineon CYW43012 combo chipset + which supports Wi-Fi® 802.11a/b/g/n + Bluetooth® 5.0 BR/EDR/LE + up to 72.2Mbps PHY data rate on Wi-fi® and 3Mbps PHY data rate + on Bluetooth®. 2Mbps LE PHY is also supported. + + Detailed information about Murata Type 1LV module you can find on + https://www.murata.com/en-us/products/connectivitymodule/wi-fi-bluetooth/overview/lineup/type1lv + +endchoice + +choice CYW4343W_MODULE + prompt "Select CYW4343W module" + depends on CYW4343W + +config CYW4343W_MURATA_1DX + bool "MURATA-1DX" + help + Murata Type 1DX modules based on Infineon CYW4343W combo chipset + which supports Wi-Fi® 802.11b/g/n + Bluetooth® 5.1 BR/EDR/LE + up to 65Mbps PHY data rate on Wi-fi® and 3Mbps PHY data rate + on Bluetooth®. + + Detailed information about Type 1DX module you can find on + https://www.murata.com/en-us/products/connectivitymodule/wi-fi-bluetooth/overview/lineup/type1dx + +endchoice + +choice CYW4373_MODULE + prompt "Select CYW4373 module" + depends on CYW4373 + +config CYW4373_STERLING_LWB5PLUS + bool "STERLING-LWB5plus" + help + Laird Sterling LWB5+ 802.11ac / Bluetooth 5.0 M.2 Carrier Board + (E-Type Key w/ SDIO/UART) + + Detailed information about Type Sterling LWB5+ module you can find on + https://www.lairdconnect.com/wireless-modules/wifi-modules-bluetooth/sterling-lwb5-plus-wifi-5-bluetooth-5-module + +endchoice + +choice CYW43439_MODULE + prompt "Select CYW43439 module" + depends on CYW43439 + +config CYW43439_MURATA_1YN + bool "MURATA_1YN" + help + Murata Type 1YN module based on Infineon CYW43439 combo chipset + which supports Wi-Fi® 802.11b/g/n + Bluetooth® 5.2 BR/EDR/LE + up to 65Mbps PHY data rate on Wi-fi® and 3Mbps PHY data rate on + Bluetooth®. + + Detailed information about Murata Type 1YN module you can find on + https://www.murata.com/en-us/products/connectivitymodule/wi-fi-bluetooth/overview/lineup/type1yn + +endchoice + +config CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB + depends on BT_CYW43XXX_CUSTOM + string "Path to user BT firmware HCD file" + help + Path to BT firmware HCD file for custom or vendor CYW43xx modules. + It can be absolute path, or relative from project folder. + +# Change size of command lengths. It for vendor commands related to +# firmware downloading. +config BT_BUF_CMD_TX_SIZE + default 255 + +# Disable ATT_ENFORCE_FLOW feature, CYW43XX informs about frees buffer +# (HCL Number Of Completed Packets event) after second packet. +config BT_ATT_ENFORCE_FLOW + default n + +endif # BT_CYW43XXX diff --git a/drivers/bluetooth/hci/cyw43xxx.c b/drivers/bluetooth/hci/cyw43xxx.c new file mode 100644 index 000000000000..1b3eaa2f6845 --- /dev/null +++ b/drivers/bluetooth/hci/cyw43xxx.c @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon company) or + * an affiliate of Cypress Semiconductor Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @brief CYW43xxx HCI extension driver. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER) +#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL +#include +LOG_MODULE_REGISTER(cyw43xxx_driver); + +#include + +#define DT_DRV_COMPAT infineon_cyw43xxx_bt_hci + +/* BT settling time after power on */ +#define BT_POWER_ON_SETTLING_TIME_MS (500u) + +/* Stabilization delay after FW loading */ +#define BT_STABILIZATION_DELAY_MS (250u) + +/* HCI Command packet from Host to Controller */ +#define HCI_COMMAND_PACKET (0x01) + +/* Length of UPDATE BAUD RATE command */ +#define HCI_VSC_UPDATE_BAUD_RATE_LENGTH (6u) + +/* Default BAUDRATE */ +#define HCI_UART_DEFAULT_BAUDRATE (115200) + +/* Externs for CY43xxx controller FW */ +extern const uint8_t brcm_patchram_buf[]; +extern const int brcm_patch_ram_length; + +enum { + BT_HCI_VND_OP_DOWNLOAD_MINIDRIVER = 0xFC2E, + BT_HCI_VND_OP_WRITE_RAM = 0xFC4C, + BT_HCI_VND_OP_LAUNCH_RAM = 0xFC4E, + BT_HCI_VND_OP_UPDATE_BAUDRATE = 0xFC18, +}; + +/* bt_h4_vnd_setup function. + * This function executes vendor-specific commands sequence to + * initialize BT Controller before BT Host executes Reset sequence. + * bt_h4_vnd_setup function must be implemented in vendor-specific HCI + * extansion module if CONFIG_BT_HCI_SETUP is enabled. + */ +int bt_h4_vnd_setup(const struct device *dev); + +static int bt_hci_uart_set_baudrate(const struct device *bt_uart_dev, uint32_t baudrate) +{ + struct uart_config uart_cfg; + int err; + + /* Get current UART configuration */ + err = uart_config_get(bt_uart_dev, &uart_cfg); + if (err) { + return err; + } + + if (uart_cfg.baudrate != baudrate) { + /* Re-configure UART */ + uart_cfg.baudrate = baudrate; + err = uart_configure(bt_uart_dev, &uart_cfg); + if (err) { + return err; + } + + /* Revert Interrupt options */ + uart_irq_rx_enable(bt_uart_dev); + } + return 0; +} + +static int bt_update_controller_baudrate(const struct device *bt_uart_dev, uint32_t baudrate) +{ + /* + * NOTE from datasheet for update baudrate: + * - To speed up application downloading, the MCU host commands the CYWxxx device + * to communicate at a new, higher rate by issuing the following Vendor Specific + * UPDATE_BAUDRATE command: + * 01 18 FC 06 00 00 xx xx xx xx + * In the above command, the xx xx xx xx bytes specify the 32-bit little-endian + * value of the new rate in bits per second. For example, + * 115200 is represented as 00 C2 01 00. + * The following response to the UPDATE_BAUDRATE command is expected within 100 ms: + * 04 0E 04 01 18 FC 00 + * - The host switches to the new baud rate after receiving the response at the old + * baud rate. + */ + struct net_buf *buf; + int err; + uint8_t hci_data[HCI_VSC_UPDATE_BAUD_RATE_LENGTH]; + + /* Baudrate is loaded LittleEndian */ + hci_data[0] = 0; + hci_data[1] = 0; + hci_data[2] = (uint8_t)(baudrate & 0xFFUL); + hci_data[3] = (uint8_t)((baudrate >> 8) & 0xFFUL); + hci_data[4] = (uint8_t)((baudrate >> 16) & 0xFFUL); + hci_data[5] = (uint8_t)((baudrate >> 24) & 0xFFUL); + + /* Allocate buffer for update uart baudrate command. + * It will be BT_HCI_OP_RESET with extra parameters. + */ + buf = bt_hci_cmd_create(BT_HCI_VND_OP_UPDATE_BAUDRATE, + HCI_VSC_UPDATE_BAUD_RATE_LENGTH); + if (buf == NULL) { + LOG_ERR("Unable to allocate command buffer"); + return -ENOMEM; + } + + /* Add data part of packet */ + net_buf_add_mem(buf, &hci_data, HCI_VSC_UPDATE_BAUD_RATE_LENGTH); + + /* Send update uart baudrate command. */ + err = bt_hci_cmd_send_sync(BT_HCI_VND_OP_UPDATE_BAUDRATE, buf, NULL); + if (err) { + return err; + } + + /* Re-configure Uart baudrate */ + err = bt_hci_uart_set_baudrate(bt_uart_dev, baudrate); + if (err) { + return err; + } + + return 0; +} + +static int bt_firmware_download(const uint8_t *firmware_image, uint32_t size) +{ + uint8_t *data = (uint8_t *)firmware_image; + volatile uint32_t remaining_length = size; + struct net_buf *buf; + int err; + + LOG_DBG("Executing Fw downloading for CYW43xx device"); + + /* Send hci_download_minidriver command */ + err = bt_hci_cmd_send_sync(BT_HCI_VND_OP_DOWNLOAD_MINIDRIVER, NULL, NULL); + if (err) { + return err; + } + + /* The firmware image (.hcd format) contains a collection of hci_write_ram + * command + a block of the image, followed by a hci_write_ram image at the end. + * Parse and send each individual command and wait for the response. This is to + * ensure the integrity of the firmware image sent to the bluetooth chip. + */ + while (remaining_length) { + size_t data_length = data[2]; /* data length from firmware image block */ + uint16_t op_code = *(uint16_t *)data; + + /* Allocate buffer for hci_write_ram/hci_launch_ram command. */ + buf = bt_hci_cmd_create(op_code, data_length); + if (buf == NULL) { + LOG_ERR("Unable to allocate command buffer"); + return err; + } + + /* Add data part of packet */ + net_buf_add_mem(buf, &data[3], data_length); + + /* Send hci_write_ram command. */ + err = bt_hci_cmd_send_sync(op_code, buf, NULL); + if (err) { + return err; + } + + switch (op_code) { + case BT_HCI_VND_OP_WRITE_RAM: + /* Update remaining length and data pointer: + * content of data length + 2 bytes of opcode and 1 byte of data length. + */ + data += data_length + 3; + remaining_length -= data_length + 3; + break; + + case BT_HCI_VND_OP_LAUNCH_RAM: + remaining_length = 0; + break; + + default: + return -ENOMEM; + } + } + + LOG_DBG("Fw downloading complete"); + return 0; +} + +int bt_h4_vnd_setup(const struct device *dev) +{ + int err; + uint32_t default_uart_speed = DT_PROP(DT_INST_BUS(0), current_speed); + uint32_t hci_operation_speed = DT_INST_PROP_OR(0, hci_operation_speed, default_uart_speed); + uint32_t fw_download_speed = DT_INST_PROP_OR(0, fw_download_speed, default_uart_speed); + + /* Check BT Uart instance */ + if (!device_is_ready(dev)) { + return -EINVAL; + } + +#if DT_INST_NODE_HAS_PROP(0, bt_reg_on_gpios) + struct gpio_dt_spec bt_reg_on = GPIO_DT_SPEC_GET(DT_DRV_INST(0), bt_reg_on_gpios); + + /* Check BT REG_ON gpio instance */ + if (!device_is_ready(bt_reg_on.port)) { + LOG_ERR("Error: failed to configure bt_reg_on %s pin %d", + bt_reg_on.port->name, bt_reg_on.pin); + return -EIO; + } + + /* Configure bt_reg_on as output */ + err = gpio_pin_configure_dt(&bt_reg_on, GPIO_OUTPUT); + if (err) { + LOG_ERR("Error %d: failed to configure bt_reg_on %s pin %d", + err, bt_reg_on.port->name, bt_reg_on.pin); + return err; + } + err = gpio_pin_set_dt(&bt_reg_on, 1); + if (err) { + return err; + } +#endif /* DT_INST_NODE_HAS_PROP(0, bt_reg_on_gpios) */ + + /* BT settling time after power on */ + (void)k_msleep(BT_POWER_ON_SETTLING_TIME_MS); + + /* Send HCI_RESET */ + err = bt_hci_cmd_send_sync(BT_HCI_OP_RESET, NULL, NULL); + if (err) { + return err; + } + + /* Re-configure baudrate for BT Controller */ + if (fw_download_speed != default_uart_speed) { + err = bt_update_controller_baudrate(dev, fw_download_speed); + if (err) { + return err; + } + } + + /* BT firmware download */ + err = bt_firmware_download(brcm_patchram_buf, (uint32_t) brcm_patch_ram_length); + if (err) { + return err; + } + + /* Stabilization delay */ + (void)k_msleep(BT_STABILIZATION_DELAY_MS); + + /* When FW launched, HCI UART baudrate should be configured to default */ + if (fw_download_speed != default_uart_speed) { + err = bt_hci_uart_set_baudrate(dev, default_uart_speed); + if (err) { + return err; + } + } + + /* Send HCI_RESET */ + err = bt_hci_cmd_send_sync(BT_HCI_OP_RESET, NULL, NULL); + if (err) { + return err; + } + + /* Set host controller functionality to user defined baudrate + * after fw downloading. + */ + if (hci_operation_speed != default_uart_speed) { + err = bt_update_controller_baudrate(dev, hci_operation_speed); + if (err) { + return err; + } + } + + return 0; +} diff --git a/dts/bindings/bluetooth/infineon,cyw43xxx-bt-hci.yaml b/dts/bindings/bluetooth/infineon,cyw43xxx-bt-hci.yaml new file mode 100644 index 000000000000..e45c7c359835 --- /dev/null +++ b/dts/bindings/bluetooth/infineon,cyw43xxx-bt-hci.yaml @@ -0,0 +1,75 @@ +# Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon company) or +# an affiliate of Cypress Semiconductor Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +description: | + CYW43xxx Connectivity that uses Zephyr's Bluetooth Host Controller Interface UART + driver. + + Example of enabling CYW43xxx device: + + &uart2 { + status = "okay"; + current-speed = <115200>; + + /* HCI-UART pins*/ + pinctrl-0 = <&p3_1_scb2_uart_tx &p3_0_scb2_uart_rx + &p3_2_scb2_uart_rts &p3_3_scb2_uart_cts>; + pinctrl-names = "default"; + + bt-hci { + status = "okay"; + compatible = "infineon,cyw43xxx-bt-hci"; + bt-reg-on-gpios = <&gpio_prt3 4 (GPIO_ACTIVE_HIGH)>; + + fw-download-speed = <3000000>; + }; + }; + + NOTE1: The UART bus speed (current_speed) for zephyr_bt_uart should be the same + as the default baudrate defined in CYW43xx firmware (default 115200). + + NOTE2: Use fw-download-speed and hci-operation-speed properties to configure UART + speeds for firmware download (fw-download-speed) and HCI operation + (hci-operation-speed). + If hci-operation-speed or fw-download-speed are not defined in bt-hci node, + cyw43xx driver will use bus/current-speed as default speed. + + NOTE3: CYW43xxx requires fetch binary files of BT controller. To fetch binary blobs: + west blobs fetch hal_infineon + +compatible: "infineon,cyw43xxx-bt-hci" + +include: base.yaml + +properties: + bt-reg-on-gpios: + description: | + Power-up/down gpio to control the internal regulators used + by the Bluetooth section of CYW43xx device. + type: phandle-array + + bt-dev-wake-gpios: + description: | + Bluetooth device wake-up gpio. Signal from the host to the + CYW43xx indicating that the host requires attention. + type: phandle-array + + bt-host-wake-gpios: + description: | + Host wake-up gpio. Signal from the CYW43xx to the host + indicating that the CYW43xx requires attention. + type: phandle-array + + hci-operation-speed: + type: int + description: | + HCI UART boudrate for feature operation. If not defined + bus/current-speed wil be used as default. + + fw-download-speed: + type: int + description: | + HCI UART boudrate for FW dowload operation. If not defined + bus/current-speed wil be used as default. From 8fb4a186677279ce01107430e0f5814d94c5a94b Mon Sep 17 00:00:00 2001 From: Nazar Palamar Date: Wed, 1 Mar 2023 11:44:41 +0200 Subject: [PATCH 0667/1906] boards: arm: cy8cproto-062-4343w: enable BLE features Enable BLE features for CY8CPROTO-062-4343W board. Signed-off-by: Nazar Palamar --- .../arm/cy8cproto_062_4343w/Kconfig.defconfig | 30 +++++++++++++++++++ .../cy8cproto_062_4343w-pinctrl.dtsi | 17 +++++++++++ .../cy8cproto_062_4343w.dts | 27 +++++++++++++++++ .../cy8cproto_062_4343w_defconfig | 3 ++ 4 files changed, 77 insertions(+) diff --git a/boards/arm/cy8cproto_062_4343w/Kconfig.defconfig b/boards/arm/cy8cproto_062_4343w/Kconfig.defconfig index 198537aa929b..14c47a06e584 100644 --- a/boards/arm/cy8cproto_062_4343w/Kconfig.defconfig +++ b/boards/arm/cy8cproto_062_4343w/Kconfig.defconfig @@ -8,4 +8,34 @@ if BOARD_CY8CPROTO_062_4343W config BOARD default "cy8cproto_062_4343w" +if WIFI || BT + +# Select CYW43XXX part and module +choice CYW43XXX_PART + default CYW4343W +endchoice + +choice CYW4343W_MODULE + default CYW4343W_MURATA_1DX +endchoice + +endif # WIFI || BT + + +if BT + +# Select HCI components +config UART + bool + default y + +config BT_UART + default y + +choice BT_HCI_BUS_TYPE + default BT_H4 +endchoice + +endif # BT + endif # BOARD_CY8CPROTO_062_4343W diff --git a/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w-pinctrl.dtsi b/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w-pinctrl.dtsi index 073a5517d7ba..d86f9b67bfa7 100644 --- a/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w-pinctrl.dtsi +++ b/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w-pinctrl.dtsi @@ -3,6 +3,23 @@ * SPDX-License-Identifier: Apache-2.0 */ +/* Configure pin control bias mode for uart2 pins */ +&p3_1_scb2_uart_tx { + drive-push-pull; +}; + +&p3_0_scb2_uart_rx { + input-enable; +}; + +&p3_2_scb2_uart_rts { + drive-push-pull; +}; + +&p3_3_scb2_uart_cts { + input-enable; +}; + /* Configure pin control bias mode for uart5 pins */ &p5_1_scb5_uart_tx { drive-push-pull; diff --git a/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w.dts b/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w.dts index c09b64e91f26..48544362c242 100644 --- a/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w.dts +++ b/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w.dts @@ -22,6 +22,7 @@ zephyr,flash = &flash0; zephyr,console = &uart5; zephyr,shell-uart = &uart5; + zephyr,bt_uart = &uart2; }; }; @@ -33,6 +34,32 @@ pinctrl-names = "default"; }; +&uart2 { + status = "okay"; + /* The UART bus speed (current_speed) for zephyr_bt_uart should be the same + * as the default baudrate defined in CYW43xx firmware (default 115200). + */ + + current-speed = <115200>; + + /* HCI-UART pins*/ + pinctrl-0 = <&p3_1_scb2_uart_tx &p3_0_scb2_uart_rx &p3_2_scb2_uart_rts &p3_3_scb2_uart_cts>; + pinctrl-names = "default"; + + bt-hci { + status = "okay"; + compatible = "infineon,cyw43xxx-bt-hci"; + bt-reg-on-gpios = <&gpio_prt3 4 (GPIO_ACTIVE_HIGH)>; + + /* Configuration UART speeds for firmware download (fw-download-speed) and + * HCI operation (hci-operation-speed). + * If hci-operation-speed or fw-download-speed are not defined in bt-hci{...} + * node, cyw43xx driver will use bus/current-speed as default speed. + */ + fw-download-speed = <3000000>; + }; +}; + /* System clock configuration */ &fll0 { status = "okay"; diff --git a/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w_defconfig b/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w_defconfig index 937b4b587bdd..c36ce13e1a87 100644 --- a/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w_defconfig +++ b/boards/arm/cy8cproto_062_4343w/cy8cproto_062_4343w_defconfig @@ -24,5 +24,8 @@ CONFIG_SERIAL=y # Enable pin controller CONFIG_PINCTRL=y +# Enable GPIO driver +CONFIG_GPIO=y + # Enable clock controller CONFIG_CLOCK_CONTROL=y From 23807100208e988e77b4fc3673ca75b8af4224a3 Mon Sep 17 00:00:00 2001 From: Alvaro Garcia Date: Thu, 17 Nov 2022 21:42:58 +0100 Subject: [PATCH 0668/1906] drivers: Added fuel gauge max17048 Added support for fuel gauge max17048 Signed-off-by: Alvaro Garcia --- drivers/fuel_gauge/CMakeLists.txt | 1 + drivers/fuel_gauge/Kconfig | 2 + drivers/fuel_gauge/max17048/CMakeLists.txt | 8 + drivers/fuel_gauge/max17048/Kconfig | 20 ++ drivers/fuel_gauge/max17048/emul_max17048.c | 152 +++++++++ drivers/fuel_gauge/max17048/max17048.c | 293 ++++++++++++++++++ drivers/fuel_gauge/max17048/max17048.h | 34 ++ dts/bindings/fuel-gauge/maxim,max17048.yaml | 10 + samples/fuel_gauge/fuel_gauge.rst | 10 + samples/fuel_gauge/max17048/CMakeLists.txt | 8 + samples/fuel_gauge/max17048/README.rst | 51 +++ .../boards/nrf52840dk_nrf52840.overlay | 18 ++ samples/fuel_gauge/max17048/prj.conf | 1 + samples/fuel_gauge/max17048/sample.yaml | 9 + samples/fuel_gauge/max17048/src/main.c | 104 +++++++ samples/index.rst | 1 + .../fuel_gauge/max17048/CMakeLists.txt | 8 + .../max17048/boards/native_posix.conf | 6 + .../max17048/boards/native_posix.overlay | 11 + tests/drivers/fuel_gauge/max17048/prj.conf | 7 + .../fuel_gauge/max17048/src/test_max17048.c | 114 +++++++ .../drivers/fuel_gauge/max17048/testcase.yaml | 5 + 22 files changed, 873 insertions(+) create mode 100644 drivers/fuel_gauge/max17048/CMakeLists.txt create mode 100644 drivers/fuel_gauge/max17048/Kconfig create mode 100644 drivers/fuel_gauge/max17048/emul_max17048.c create mode 100644 drivers/fuel_gauge/max17048/max17048.c create mode 100644 drivers/fuel_gauge/max17048/max17048.h create mode 100644 dts/bindings/fuel-gauge/maxim,max17048.yaml create mode 100644 samples/fuel_gauge/fuel_gauge.rst create mode 100644 samples/fuel_gauge/max17048/CMakeLists.txt create mode 100644 samples/fuel_gauge/max17048/README.rst create mode 100644 samples/fuel_gauge/max17048/boards/nrf52840dk_nrf52840.overlay create mode 100644 samples/fuel_gauge/max17048/prj.conf create mode 100644 samples/fuel_gauge/max17048/sample.yaml create mode 100644 samples/fuel_gauge/max17048/src/main.c create mode 100644 tests/drivers/fuel_gauge/max17048/CMakeLists.txt create mode 100644 tests/drivers/fuel_gauge/max17048/boards/native_posix.conf create mode 100644 tests/drivers/fuel_gauge/max17048/boards/native_posix.overlay create mode 100644 tests/drivers/fuel_gauge/max17048/prj.conf create mode 100644 tests/drivers/fuel_gauge/max17048/src/test_max17048.c create mode 100644 tests/drivers/fuel_gauge/max17048/testcase.yaml diff --git a/drivers/fuel_gauge/CMakeLists.txt b/drivers/fuel_gauge/CMakeLists.txt index aa58fc36a926..a2d8148a1a47 100644 --- a/drivers/fuel_gauge/CMakeLists.txt +++ b/drivers/fuel_gauge/CMakeLists.txt @@ -1,5 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 add_subdirectory_ifdef(CONFIG_SBS_GAUGE_NEW_API sbs_gauge) +add_subdirectory_ifdef(CONFIG_MAX17048 max17048) zephyr_library_sources_ifdef(CONFIG_USERSPACE fuel_gauge_syscall_handlers.c) diff --git a/drivers/fuel_gauge/Kconfig b/drivers/fuel_gauge/Kconfig index 9555f8a39e1e..929dd060490a 100644 --- a/drivers/fuel_gauge/Kconfig +++ b/drivers/fuel_gauge/Kconfig @@ -19,6 +19,8 @@ config FUEL_GAUGE_INIT_PRIORITY help Battery fuel gauge initialization priority. +source "drivers/fuel_gauge/max17048/Kconfig" + source "drivers/fuel_gauge/sbs_gauge/Kconfig" endif # FUEL_GAUGE diff --git a/drivers/fuel_gauge/max17048/CMakeLists.txt b/drivers/fuel_gauge/max17048/CMakeLists.txt new file mode 100644 index 000000000000..6d614e670bee --- /dev/null +++ b/drivers/fuel_gauge/max17048/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() + +zephyr_library_sources(max17048.c) + +zephyr_include_directories_ifdef(CONFIG_EMUL_MAX17048 .) +zephyr_library_sources_ifdef(CONFIG_EMUL_MAX17048 ./emul_max17048.c) diff --git a/drivers/fuel_gauge/max17048/Kconfig b/drivers/fuel_gauge/max17048/Kconfig new file mode 100644 index 000000000000..1866614fc78a --- /dev/null +++ b/drivers/fuel_gauge/max17048/Kconfig @@ -0,0 +1,20 @@ +# MAX17048 Li-Ion battery fuel gauge + +# Copyright (c) 2023, Alvaro Garcia +# SPDX-License-Identifier: Apache-2.0 + + +config MAX17048 + bool "MAX17048 Li-Po fuel gauge" + default y + depends on DT_HAS_MAXIM_MAX17048_ENABLED + select I2C + help + Enable driver for the MAX17048 fuel gauge device. + +config EMUL_MAX17048 + bool "Emulate an MAX17048 fuel gague" + depends on EMUL + help + It provides readings which follow a simple sequence, thus allowing + test code to check that things are working as expected. diff --git a/drivers/fuel_gauge/max17048/emul_max17048.c b/drivers/fuel_gauge/max17048/emul_max17048.c new file mode 100644 index 000000000000..b80ee98dae68 --- /dev/null +++ b/drivers/fuel_gauge/max17048/emul_max17048.c @@ -0,0 +1,152 @@ +/* + * Copyright 2023, Alvaro Garcia + * + * SPDX-License-Identifier: Apache-2.0 + * + * Emulator for max17048 fuel gauge + */ + + +#define DT_DRV_COMPAT maxim_max17048 + + +#include +LOG_MODULE_REGISTER(maxim_max17048); + +#include +#include +#include +#include +#include + +#include "max17048.h" + +/** Static configuration for the emulator */ +struct max17048_emul_cfg { + /** I2C address of emulator */ + uint16_t addr; +}; + +static int emul_max17048_reg_write(const struct emul *target, int reg, int val) +{ + + return -EIO; +} + +static int emul_max17048_reg_read(const struct emul *target, int reg, int *val) +{ + + switch (reg) { + case REGISTER_VERSION: + *val = 0x1000; + break; + case REGISTER_CRATE: + *val = 0x4000; + break; + case REGISTER_SOC: + *val = 0x3525; + break; + case REGISTER_VCELL: + *val = 0x4387; + break; + default: + LOG_ERR("Unknown register 0x%x read", reg); + return -EIO; + } + LOG_INF("read 0x%x = 0x%x", reg, *val); + + return 0; +} + +static int max17048_emul_transfer_i2c(const struct emul *target, struct i2c_msg *msgs, + int num_msgs, int addr) +{ + /* Largely copied from emul_bmi160.c */ + struct max17048_emul_data *data; + unsigned int val; + int reg; + int rc; + + data = target->data; + + __ASSERT_NO_MSG(msgs && num_msgs); + + i2c_dump_msgs_rw("emul", msgs, num_msgs, addr, false); + switch (num_msgs) { + case 2: + if (msgs->flags & I2C_MSG_READ) { + LOG_ERR("Unexpected read"); + return -EIO; + } + if (msgs->len != 1) { + LOG_ERR("Unexpected msg0 length %d", msgs->len); + return -EIO; + } + reg = msgs->buf[0]; + + /* Now process the 'read' part of the message */ + msgs++; + if (msgs->flags & I2C_MSG_READ) { + switch (msgs->len - 1) { + case 1: + rc = emul_max17048_reg_read(target, reg, &val); + if (rc) { + /* Return before writing bad value to message buffer */ + return rc; + } + + /* SBS uses SMBus, which sends data in little-endian format. */ + sys_put_le16(val, msgs->buf); + break; + default: + LOG_ERR("Unexpected msg1 length %d", msgs->len); + return -EIO; + } + } else { + /* We write a word (2 bytes by the SBS spec) */ + if (msgs->len != 2) { + LOG_ERR("Unexpected msg1 length %d", msgs->len); + } + uint16_t value = sys_get_le16(msgs->buf); + + rc = emul_max17048_reg_write(target, reg, value); + } + break; + default: + LOG_ERR("Invalid number of messages: %d", num_msgs); + return -EIO; + } + + return rc; +} + +static const struct i2c_emul_api max17048_emul_api_i2c = { + .transfer = max17048_emul_transfer_i2c, +}; + +/** + * Set up a new emulator (I2C) + * + * @param emul Emulation information + * @param parent Device to emulate + * @return 0 indicating success (always) + */ +static int emul_max17048_init(const struct emul *target, const struct device *parent) +{ + ARG_UNUSED(target); + ARG_UNUSED(parent); + + return 0; +} + +/* + * Main instantiation macro. + */ +#define MAX17048_EMUL(n) \ + static const struct max17048_emul_cfg max17048_emul_cfg_##n = { \ + .addr = DT_INST_REG_ADDR(n), \ + }; \ + EMUL_DT_INST_DEFINE(n, emul_max17048_init, NULL, \ + &max17048_emul_cfg_##n, &max17048_emul_api_i2c, NULL) + +DT_INST_FOREACH_STATUS_OKAY(MAX17048_EMUL) diff --git a/drivers/fuel_gauge/max17048/max17048.c b/drivers/fuel_gauge/max17048/max17048.c new file mode 100644 index 000000000000..e04e1ed4d4a3 --- /dev/null +++ b/drivers/fuel_gauge/max17048/max17048.c @@ -0,0 +1,293 @@ +/* max17048.c - Driver for max17048 battery fuel gauge */ + +/* + * Copyright (c) 2023 Alvaro Garcia Gomez + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT maxim_max17048 + +#include "max17048.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +LOG_MODULE_REGISTER(MAX17048); + +#if DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 0 +#warning "MAX17048 driver enabled without any devices" +#endif + +/** + * Storage for the fuel gauge basic information + */ +struct max17048_data { + /* Charge as percentage */ + uint8_t charge; + /* Voltage as mV */ + uint16_t voltage; + + /* Time in minutes */ + uint16_t time_to_full; + uint16_t time_to_empty; + /* True if battery chargin, false if discharging */ + bool charging; +}; + +/** + * I2C communication + * The way we read a value is first writing the address we want to read and then + * wait for 2 bytes containing the data. + */ +int max17048_read_register(const struct device *dev, uint8_t registerId, uint16_t *response) +{ + uint8_t max17048_buffer[2]; + const struct max17048_config *cfg = dev->config; + int rc = i2c_write_read_dt(&cfg->i2c, ®isterId, sizeof(registerId), max17048_buffer, + sizeof(max17048_buffer)); + if (rc != 0) { + LOG_ERR("Unable to read register, error %d", rc); + return rc; + } + + *response = sys_get_be16(max17048_buffer); + return 0; +} + +/** + * Raw value from the internal ADC + */ +int max17048_adc(const struct device *i2c_dev, uint16_t *response) +{ + return max17048_read_register(i2c_dev, REGISTER_VCELL, response); +} + +/** + * Battery voltage + */ +int max17048_voltage(const struct device *i2c_dev, uint16_t *response) +{ + int rc = max17048_adc(i2c_dev, response); + + if (rc < 0) { + return rc; + } + /** + * Once the value is read, it has to be converted to volts. The datasheet + * https://www.analog.com/media/en/technical-documentation/data-sheets/ + * MAX17048-MAX17049.pdf + * Page 10, Table 2. Register Summary: 78.125µV/cell + * Max17048 only supports one cell so we just have to multiply the value by 78.125 to + * obtain µV and then divide the value to obtain V. + * But to avoid floats, instead of using 78.125 we will use 78125 and use this value as + * milli volts instead of volts. + */ + + *response = *response * 78125 / 1000000; + return 0; +} + +/** + * Battery percentage still available + */ +int max17048_percent(const struct device *i2c_dev, uint8_t *response) +{ + uint16_t data; + int rc = max17048_read_register(i2c_dev, REGISTER_SOC, &data); + + if (rc < 0) { + return rc; + } + /** + * Once the value is read, it has to be converted to percentage. The datasheet + * https://www.analog.com/media/en/technical-documentation/data-she4ets/ + * MAX17048-MAX17049.pdf + * Page 10, Table 2. Register Summary: 1%/256 + * So to obtain the total percentaje we just divide the read value by 256 + */ + *response = data / 256; + return 0; +} + +/** + * Percentage of the total battery capacity per hour, positive is charging or + * negative if discharging + */ +int max17048_crate(const struct device *i2c_dev, int16_t *response) +{ + int rc = max17048_read_register(i2c_dev, REGISTER_CRATE, response); + + if (rc < 0) { + return rc; + } + + /** + * Once the value is read, it has to be converted to something useful. The datasheet + * https://www.analog.com/media/en/technical-documentation/data-sheets/ + * MAX17048-MAX17049.pdf + * Page 11, Table 2. Register Summary (continued): 0.208%/hr + * To avoid floats, the value will be multiplied by 208 instead of 0.208, taking into + * account that the value will be 1000 times higher + */ + *response = *response * 208; + return 0; +} + +/** + * Initialize and verify the chip. The datasheet says that the version register + * should be 0x10. If not, or the chip is malfunctioning or it is not a MAX17048 at all + */ +static int max17048_init(const struct device *dev) +{ + const struct max17048_config *cfg = dev->config; + uint16_t version; + int rc = max17048_read_register(dev, REGISTER_VERSION, &version); + + if (!device_is_ready(cfg->i2c.bus)) { + LOG_ERR("Bus device is not ready"); + return -ENODEV; + } + + if (rc < 0) { + LOG_ERR("Cannot read from I2C"); + return rc; + } + + version = version & 0xFFF0; + if (version != 0x10) { + LOG_ERR("Something found at the provided I2C address, but it is not a MAX17048"); + LOG_ERR("The version registers should be 0x10 but got %x. Maybe your wiring is " + "wrong or it is a fake chip\n", + version); + return -ENODEV; + } + + return 0; +} + +/** + * Get a single property from the fuel gauge + */ +static int max17048_get_prop(const struct device *dev, struct fuel_gauge_get_property *prop) +{ + struct max17048_data *data = dev->data; + int rc = 0; + + switch (prop->property_type) { + case FUEL_GAUGE_RUNTIME_TO_EMPTY: + prop->value.runtime_to_empty = data->time_to_empty; + break; + case FUEL_GAUGE_RUNTIME_TO_FULL: + prop->value.runtime_to_full = data->time_to_full; + break; + case FUEL_GAUGE_STATE_OF_CHARGE: + prop->value.state_of_charge = data->charge; + break; + case FUEL_GAUGE_VOLTAGE: + prop->value.voltage = data->voltage; + break; + default: + rc = -ENOTSUP; + } + + prop->status = rc; + + return rc; +} + +/** + * Get all possible properties from the fuel gague + */ +static int max17048_get_props(const struct device *dev, struct fuel_gauge_get_property *props, + size_t len) +{ + int err_count = 0; + struct max17048_data *data = dev->data; + int rc = max17048_percent(dev, &data->charge); + int16_t crate; + + if (rc < 0) { + LOG_ERR("Error while reading battery percentage"); + return rc; + } + + rc = max17048_voltage(dev, &data->voltage); + if (rc < 0) { + LOG_ERR("Error while reading battery voltage"); + return rc; + } + + /** + * Crate (current rate) is the current percentage of the battery charged or drained + * per hour + */ + rc = max17048_crate(dev, &crate); + if (rc < 0) { + LOG_ERR("Error while reading battery current rate"); + return rc; + } + + /** + * May take some time until the chip detects the change between discharging to charging + * (and vice versa) especially if your device consumes little power + */ + data->charging = crate > 0; + + + /** + * In the following code, we multiply by 1000 the charge to increase the precision. If we + * just truncate the division without this multiplier, the precision lost is very + * significant when converting it into minutes (the value given is in hours) + * + * The value coming from crate is already 1000 times higher (check the function + * max17048_crate to + * see the reason) so the multiplier for the charge + * will be 1000000 + */ + if (data->charging) { + uint8_t percentage_pending = 100 - data->charge; + uint32_t hours_pending = percentage_pending * 1000000 / crate; + + data->time_to_empty = 0; + data->time_to_full = hours_pending * 60 / 1000; + } else { + /* Discharging */ + uint32_t hours_pending = data->charge * 1000000 / -crate; + + data->time_to_empty = hours_pending * 60 / 1000; + data->time_to_full = 0; + } + + for (int i = 0; i < len; i++) { + int ret = max17048_get_prop(dev, props + i); + + err_count += ret ? 1 : 0; + } + + err_count = (err_count == len) ? -1 : err_count; + + return err_count; +} + +static const struct fuel_gauge_driver_api max17048_driver_api = { + .get_property = &max17048_get_props, +}; + +#define MAX17048_DEFINE(inst) \ + static struct max17048_data max17048_data_##inst; \ + \ + static const struct max17048_config max17048_config_##inst = { \ + .i2c = I2C_DT_SPEC_INST_GET(inst)}; \ + \ + DEVICE_DT_INST_DEFINE(inst, &max17048_init, NULL, &max17048_data_##inst, \ + &max17048_config_##inst, POST_KERNEL, \ + CONFIG_FUEL_GAUGE_INIT_PRIORITY, &max17048_driver_api); + +DT_INST_FOREACH_STATUS_OKAY(MAX17048_DEFINE) diff --git a/drivers/fuel_gauge/max17048/max17048.h b/drivers/fuel_gauge/max17048/max17048.h new file mode 100644 index 000000000000..8dc388e2ec92 --- /dev/null +++ b/drivers/fuel_gauge/max17048/max17048.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Alvaro Garcia Gomez + * + * SPDX-License-Identifier: Apache-2.0 + */ + + +#ifndef ZEPHYR_DRIVERS_SENSOR_MAX17048_MAX17048_H_ +#define ZEPHYR_DRIVERS_SENSOR_MAX17048_MAX17048_H_ + +#include + +#define REGISTER_VCELL 0x02 +#define REGISTER_SOC 0x04 +#define REGISTER_MODE 0x06 +#define REGISTER_VERSION 0x08 +#define REGISTER_HIBRT 0x0A +#define REGISTER_CONFIG 0x0C +#define REGISTER_VALRT 0x14 +#define REGISTER_CRATE 0x16 +#define REGISTER_VRESET 0x18 +#define REGISTER_CHIP_ID 0x19 +#define REGISTER_STATUS 0x1A +#define REGISTER_TABLE 0x40 +#define REGISTER_COMMAND 0xFE + +#define RESET_COMMAND 0x5400 +#define QUICKSTART_MODE 0x4000 + +struct max17048_config { + struct i2c_dt_spec i2c; +}; + +#endif /* ZEPHYR_DRIVERS_SENSOR_MAX17048_MAX17048_H_ */ diff --git a/dts/bindings/fuel-gauge/maxim,max17048.yaml b/dts/bindings/fuel-gauge/maxim,max17048.yaml new file mode 100644 index 000000000000..2aeb3d0f9dff --- /dev/null +++ b/dts/bindings/fuel-gauge/maxim,max17048.yaml @@ -0,0 +1,10 @@ +# Copyright (c) 2023 Alvaro Garcia Gomez +# SPDX-License-Identifier: Apache-2.0 + +description: | + Maxim MAX17048 Fuel Gauge with ModelGauge. See more info at: + https://www.maximintegrated.com/en/products/power/battery-management/MAX17048.html + +compatible: "maxim,max17048" + +include: [i2c-device.yaml, fuel-gauge.yaml] diff --git a/samples/fuel_gauge/fuel_gauge.rst b/samples/fuel_gauge/fuel_gauge.rst new file mode 100644 index 000000000000..979180fb72be --- /dev/null +++ b/samples/fuel_gauge/fuel_gauge.rst @@ -0,0 +1,10 @@ +.. _fuel_gauge-samples: + +Fuel Gauge Samples +################## + +.. toctree:: + :maxdepth: 1 + :glob: + + **/* diff --git a/samples/fuel_gauge/max17048/CMakeLists.txt b/samples/fuel_gauge/max17048/CMakeLists.txt new file mode 100644 index 000000000000..68b9bc1d7d77 --- /dev/null +++ b/samples/fuel_gauge/max17048/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(max17048) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/samples/fuel_gauge/max17048/README.rst b/samples/fuel_gauge/max17048/README.rst new file mode 100644 index 000000000000..bd26aa315239 --- /dev/null +++ b/samples/fuel_gauge/max17048/README.rst @@ -0,0 +1,51 @@ +.. _MAX17048_sample: + +MAX17048 Li-Ion battery fuel gauge +################################### + +Overview +******** + +This sample shows how to use the Zephyr :ref:`fuel_gauge_api` API driver for the `MAX17048` fuel gauge. + +.. _MAX17048: https://www.maximintegrated.com/en/products/power/battery-management/MAX17048.html + +The sample periodically reads battery percentage and power status + +Building and Running +******************** + +The sample can be configured to support MAX17048 fuel gauge connected via either I2C. It only needs +an I2C pin configuration + +Features +******** +By using this fuel gauge you can get the following information: + * Battery charge status as percentage + * Total time until battery is fully charged or discharged + * Battery voltage + * Charging state: if charging or discharging + + +Notes +***** +The charging state and the time to full/empty are estimated and based on the last consumption average. That means that +if you plug/unplug a charger it will take some time until it is actually detected by the chip. Don't try to plug/unplug +to see in real time the charging status change because it will not work. If you really need to know exactly the moment +when the battery is being charged you will need other method. + +Sample output +************* + +``` +*** Booting Zephyr OS build 16043f62a40a *** +Found device "max17048@36", getting fuel gauge data +Time to empty 1911 +Time to full 0 +Charge 72% +Voltage 3968 +Time to empty 1911 +Time to full 0 +Charge 72% +Voltage 3968 +``` diff --git a/samples/fuel_gauge/max17048/boards/nrf52840dk_nrf52840.overlay b/samples/fuel_gauge/max17048/boards/nrf52840dk_nrf52840.overlay new file mode 100644 index 000000000000..52d6b9ad598c --- /dev/null +++ b/samples/fuel_gauge/max17048/boards/nrf52840dk_nrf52840.overlay @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 Alvaro Garcia Gomez + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&i2c0 { + status = "okay"; + compatible = "nordic,nrf-twim"; + pinctrl-0 = <&i2c0_default>; + pinctrl-1 = <&i2c0_sleep>; + pinctrl-names = "default", "sleep"; + max17048:max17048@36 { + compatible = "maxim,max17048"; + status = "ok"; + reg = <0x36 >; + }; +}; diff --git a/samples/fuel_gauge/max17048/prj.conf b/samples/fuel_gauge/max17048/prj.conf new file mode 100644 index 000000000000..aeb0cb44b209 --- /dev/null +++ b/samples/fuel_gauge/max17048/prj.conf @@ -0,0 +1 @@ +CONFIG_FUEL_GAUGE=y diff --git a/samples/fuel_gauge/max17048/sample.yaml b/samples/fuel_gauge/max17048/sample.yaml new file mode 100644 index 000000000000..0ae4d6c7f3d3 --- /dev/null +++ b/samples/fuel_gauge/max17048/sample.yaml @@ -0,0 +1,9 @@ +sample: + name: MAX17048 Sensor sample +tests: + sample.sensor.max17048: + build_only: true + platform_allow: nrf52dk_nrf52832 + integration_platforms: + - nrf52dk_nrf52832 + tags: fuel_gauge diff --git a/samples/fuel_gauge/max17048/src/main.c b/samples/fuel_gauge/max17048/src/main.c new file mode 100644 index 000000000000..e55cd2ec5c4d --- /dev/null +++ b/samples/fuel_gauge/max17048/src/main.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2023 Alvaro Garcia Gomez + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + + + +void main(void) +{ + const struct device *const dev = DEVICE_DT_GET_ANY(maxim_max17048); + int ret = 0; + + if (dev == NULL) { + printk("\nError: no device found.\n"); + return; + } + + if (!device_is_ready(dev)) { + printk("\nError: Device \"%s\" is not ready; " + "check the driver initialization logs for errors.\n", + dev->name); + return; + } + + + + printk("Found device \"%s\", getting fuel gauge data\n", dev->name); + + if (dev == NULL) { + return; + } + + while (1) { + + struct fuel_gauge_get_property props[] = { + { + .property_type = FUEL_GAUGE_RUNTIME_TO_EMPTY, + }, + { + .property_type = FUEL_GAUGE_RUNTIME_TO_FULL, + }, + { + .property_type = FUEL_GAUGE_STATE_OF_CHARGE, + }, + { + .property_type = FUEL_GAUGE_VOLTAGE, + } + }; + + ret = fuel_gauge_get_prop(dev, props, ARRAY_SIZE(props)); + if (ret < 0) { + printk("Error: cannot get properties\n"); + } else { + if (ret != 0) { + printk("Warning: Some properties failed\n"); + } + + if (props[0].status == 0) { + printk("Time to empty %d\n", props[0].value.runtime_to_empty); + } else { + printk( + "Property FUEL_GAUGE_RUNTIME_TO_EMPTY failed with error %d\n", + props[0].status + ); + } + + if (props[1].status == 0) { + printk("Time to full %d\n", props[1].value.runtime_to_full); + } else { + printk( + "Property FUEL_GAUGE_RUNTIME_TO_FULL failed with error %d\n", + props[1].status + ); + } + + if (props[2].status == 0) { + printk("Charge %d%%\n", props[2].value.state_of_charge); + } else { + printk( + "Property FUEL_GAUGE_STATE_OF_CHARGE failed with error %d\n", + props[2].status + ); + } + + if (props[3].status == 0) { + printk("Voltage %d\n", props[3].value.voltage); + } else { + printk( + "Property FUEL_GAUGE_VOLTAGE failed with error %d\n", + props[3].status + ); + } + } + + + k_sleep(K_MSEC(5000)); + } +} diff --git a/samples/index.rst b/samples/index.rst index 82d4af143a78..0ba36eeaebbb 100644 --- a/samples/index.rst +++ b/samples/index.rst @@ -27,6 +27,7 @@ Samples and Demos tfm_integration/tfm_integration.rst modules/* compression/* + fuel_gauge/* .. comment To add a new sample document, please use the template available under diff --git a/tests/drivers/fuel_gauge/max17048/CMakeLists.txt b/tests/drivers/fuel_gauge/max17048/CMakeLists.txt new file mode 100644 index 000000000000..b4db71637d25 --- /dev/null +++ b/tests/drivers/fuel_gauge/max17048/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(device) + +FILE(GLOB app_sources src/test_max17048.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/drivers/fuel_gauge/max17048/boards/native_posix.conf b/tests/drivers/fuel_gauge/max17048/boards/native_posix.conf new file mode 100644 index 000000000000..5b4680bc37b3 --- /dev/null +++ b/tests/drivers/fuel_gauge/max17048/boards/native_posix.conf @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_EMUL=y +CONFIG_EMUL_MAX17048=y +CONFIG_I2C=y +CONFIG_I2C_EMUL=y diff --git a/tests/drivers/fuel_gauge/max17048/boards/native_posix.overlay b/tests/drivers/fuel_gauge/max17048/boards/native_posix.overlay new file mode 100644 index 000000000000..fb8db1280a91 --- /dev/null +++ b/tests/drivers/fuel_gauge/max17048/boards/native_posix.overlay @@ -0,0 +1,11 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + */ + +&i2c0 { + max17048: max17048@36 { + compatible = "maxim,max17048"; + reg = <0x36>; + status = "okay"; + }; +}; diff --git a/tests/drivers/fuel_gauge/max17048/prj.conf b/tests/drivers/fuel_gauge/max17048/prj.conf new file mode 100644 index 000000000000..23ceb0b3cdd5 --- /dev/null +++ b/tests/drivers/fuel_gauge/max17048/prj.conf @@ -0,0 +1,7 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_I2C=y +CONFIG_TEST_USERSPACE=y +CONFIG_LOG=y + +CONFIG_FUEL_GAUGE=y diff --git a/tests/drivers/fuel_gauge/max17048/src/test_max17048.c b/tests/drivers/fuel_gauge/max17048/src/test_max17048.c new file mode 100644 index 000000000000..b62ff9dd1796 --- /dev/null +++ b/tests/drivers/fuel_gauge/max17048/src/test_max17048.c @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2023 Alvaro Garcia Gomez + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct max17048_fixture { + const struct device *dev; + const struct fuel_gauge_driver_api *api; +}; + +static void *max17048_setup(void) +{ + static ZTEST_DMEM struct max17048_fixture fixture; + + fixture.dev = DEVICE_DT_GET_ANY(maxim_max17048); + + k_object_access_all_grant(fixture.dev); + + zassert_true(device_is_ready(fixture.dev), "Fuel Gauge not found"); + + return &fixture; +} + +ZTEST_USER_F(max17048, test_get_all_props_failed_returns_negative) +{ + struct fuel_gauge_get_property props[] = { + { + /* Invalid property */ + .property_type = FUEL_GAUGE_PROP_MAX, + }, + }; + + int ret = fuel_gauge_get_prop(fixture->dev, props, ARRAY_SIZE(props)); + + zassert_equal(props[0].status, -ENOTSUP, "Getting bad property %d has a good status.", + props[0].property_type); + + zassert_true(ret < 0); +} + +ZTEST_USER_F(max17048, test_get_some_props_failed_returns_failed_prop_count) +{ + struct fuel_gauge_get_property props[] = { + { + /* First invalid property */ + .property_type = FUEL_GAUGE_PROP_MAX, + }, + { + /* Second invalid property */ + .property_type = FUEL_GAUGE_PROP_MAX, + }, + { + /* Valid property */ + .property_type = FUEL_GAUGE_VOLTAGE, + }, + + }; + + int ret = fuel_gauge_get_prop(fixture->dev, props, ARRAY_SIZE(props)); + + zassert_equal(props[0].status, -ENOTSUP, "Getting bad property %d has a good status.", + props[0].property_type); + + zassert_equal(props[1].status, -ENOTSUP, "Getting bad property %d has a good status.", + props[1].property_type); + + zassert_ok(props[2].status, "Property %d getting %d has a bad status.", 2, + props[2].property_type); + + zassert_equal(ret, 2); +} + + +ZTEST_USER_F(max17048, test_get_props__returns_ok) +{ + /* Validate what props are supported by the driver */ + + struct fuel_gauge_get_property props[] = { + { + .property_type = FUEL_GAUGE_RUNTIME_TO_EMPTY, + }, + { + .property_type = FUEL_GAUGE_RUNTIME_TO_FULL, + }, + { + .property_type = FUEL_GAUGE_STATE_OF_CHARGE, + }, + { + .property_type = FUEL_GAUGE_VOLTAGE, + } + }; + + int ret = fuel_gauge_get_prop(fixture->dev, props, ARRAY_SIZE(props)); + + for (int i = 0; i < ARRAY_SIZE(props); i++) { + zassert_ok(props[i].status, "Property %d getting %d has a bad status.", i, + props[i].property_type); + } + + zassert_ok(ret); +} + + +ZTEST_SUITE(max17048, NULL, max17048_setup, NULL, NULL, NULL); diff --git a/tests/drivers/fuel_gauge/max17048/testcase.yaml b/tests/drivers/fuel_gauge/max17048/testcase.yaml new file mode 100644 index 000000000000..742d2fee9ea5 --- /dev/null +++ b/tests/drivers/fuel_gauge/max17048/testcase.yaml @@ -0,0 +1,5 @@ +tests: + # section.subsection + drivers.max17048: + filter: dt_compat_enabled("maxim,max17048") + platform_allow: native_posix From a00713bc450a1053fcb6f202fd3e298366a716a3 Mon Sep 17 00:00:00 2001 From: Andy Sinclair Date: Mon, 13 Mar 2023 13:29:30 +0000 Subject: [PATCH 0669/1906] drivers: regulator: Added initial voltage configuration The regulator driver has a configured min/max range that is used to limit set values, and to initialise the regulator. A new init value has been added, so that the startup voltage can be higher than the lowest permitted value. Signed-off-by: Andy Sinclair --- drivers/regulator/regulator_common.c | 7 +++++++ dts/bindings/regulator/regulator.yaml | 4 ++++ include/zephyr/drivers/regulator.h | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/drivers/regulator/regulator_common.c b/drivers/regulator/regulator_common.c index cc705238a090..e5cefaf06dcb 100644 --- a/drivers/regulator/regulator_common.c +++ b/drivers/regulator/regulator_common.c @@ -28,6 +28,13 @@ int regulator_common_init(const struct device *dev, bool is_enabled) } } + if (config->init_uv > INT32_MIN) { + ret = regulator_set_voltage(dev, config->init_uv, config->init_uv); + if (ret < 0) { + return ret; + } + } + /* If we have valid range values, we try to match them before enabling */ if ((config->min_uv > INT32_MIN) || (config->max_uv < INT32_MAX)) { diff --git a/dts/bindings/regulator/regulator.yaml b/dts/bindings/regulator/regulator.yaml index 1f1edca6a36f..16a21511ef96 100644 --- a/dts/bindings/regulator/regulator.yaml +++ b/dts/bindings/regulator/regulator.yaml @@ -15,6 +15,10 @@ properties: type: string description: A string used as a descriptive name for regulator outputs + regulator-init-microvolt: + type: int + description: Voltage set during initialisation + regulator-min-microvolt: type: int description: smallest voltage consumers may set diff --git a/include/zephyr/drivers/regulator.h b/include/zephyr/drivers/regulator.h index 8cda3a7e68bb..2098eb687455 100644 --- a/include/zephyr/drivers/regulator.h +++ b/include/zephyr/drivers/regulator.h @@ -123,6 +123,8 @@ struct regulator_common_config { int32_t min_uv; /** Maximum allowed voltage, in microvolts. */ int32_t max_uv; + /** Initial voltage, in microvolts. */ + int32_t init_uv; /** Minimum allowed current, in microamps. */ int32_t min_ua; /** Maximum allowed current, in microamps. */ @@ -148,6 +150,8 @@ struct regulator_common_config { INT32_MIN), \ .max_uv = DT_PROP_OR(node_id, regulator_max_microvolt, \ INT32_MAX), \ + .init_uv = DT_PROP_OR(node_id, regulator_init_microvolt, \ + INT32_MIN), \ .min_ua = DT_PROP_OR(node_id, regulator_min_microamp, \ INT32_MIN), \ .max_ua = DT_PROP_OR(node_id, regulator_max_microamp, \ From 7e905604d727b4310730f04b7cb64606d8f59bba Mon Sep 17 00:00:00 2001 From: Franciszek Zdobylak Date: Wed, 22 Mar 2023 10:54:49 +0100 Subject: [PATCH 0670/1906] boards: hifive_unmatched: Update openocd cfg name Use name that matches board name. Signed-off-by: Franciszek Zdobylak --- ...{openocd_hifive_unleashed.cfg => openocd_hifive_unmatched.cfg} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename boards/riscv/hifive_unmatched/support/{openocd_hifive_unleashed.cfg => openocd_hifive_unmatched.cfg} (100%) diff --git a/boards/riscv/hifive_unmatched/support/openocd_hifive_unleashed.cfg b/boards/riscv/hifive_unmatched/support/openocd_hifive_unmatched.cfg similarity index 100% rename from boards/riscv/hifive_unmatched/support/openocd_hifive_unleashed.cfg rename to boards/riscv/hifive_unmatched/support/openocd_hifive_unmatched.cfg From 8d21ea0d8a9660bc6a34c6c34a3e8372daad077a Mon Sep 17 00:00:00 2001 From: Sylvio Alves Date: Wed, 22 Mar 2023 08:28:31 -0300 Subject: [PATCH 0671/1906] soc: esp32s3: enable zephyr toolchain SDK 0.16 includes ESP32-S3 toolchain. This PR enable its usage. Signed-off-by: Sylvio Alves --- boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml index b7e19268e9d0..2dc7b7888d06 100644 --- a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml +++ b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml @@ -3,7 +3,7 @@ name: ESP32-S3 DevKitM type: mcu arch: xtensa toolchain: - - espressif + - zephyr supported: - gpio - uart From c84fdfe438b0ef5da3f164794f34850f82160094 Mon Sep 17 00:00:00 2001 From: Jonathan Rico Date: Wed, 22 Mar 2023 12:33:04 +0100 Subject: [PATCH 0672/1906] Bluetooth: controller: fix kconfig dependency BT_TICKER_EXT is being selected undiscriminately, but it's a Zephyr controller feature. Signed-off-by: Jonathan Rico --- subsys/bluetooth/controller/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 8b80bcae2e3a..313d08f64d19 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -546,7 +546,7 @@ config BT_CTLR_ADV_EXT depends on BT_CTLR_ADV_EXT_SUPPORT select BT_CTLR_CHAN_SEL_2 if BT_LL_SW_SPLIT && BT_BROADCASTER select BT_CTLR_SCAN_REQ_NOTIFY if BT_LL_SW_SPLIT && BT_BROADCASTER - select BT_TICKER_EXT + select BT_TICKER_EXT if BT_LL_SW_SPLIT default y if BT_EXT_ADV help Enable support for Bluetooth 5.0 LE Advertising Extensions in the From 7c6f2d78d28516b11a6d5ba698f871fd1b35bcbd Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 22 Mar 2023 13:18:17 +0100 Subject: [PATCH 0673/1906] tests: Bluetooth: ascs: Fix bap_unicast_server_cb mocks This fixes merge conflict issue by adding missing function parameters that were introduced in 57784df5f0df665ef5012f0ad7e3528494a27b12. Signed-off-by: Mariusz Skamra --- tests/bluetooth/audio/ascs/src/main.c | 4 +++- .../audio/mocks/include/bap_unicast_server.h | 23 +++++++++++------- .../audio/mocks/src/bap_unicast_server.c | 24 ++++++++++++------- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/tests/bluetooth/audio/ascs/src/main.c b/tests/bluetooth/audio/ascs/src/main.c index 61aa8b4cda61..fa2724139256 100644 --- a/tests/bluetooth/audio/ascs/src/main.c +++ b/tests/bluetooth/audio/ascs/src/main.c @@ -566,10 +566,12 @@ static struct bt_bap_stream *stream_allocated; int unicast_server_cb_config_custom_fake(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_audio_dir dir, const struct bt_codec *codec, struct bt_bap_stream **stream, - struct bt_codec_qos_pref *const pref) + struct bt_codec_qos_pref *const pref, + struct bt_bap_ascs_rsp *rsp) { *stream = stream_allocated; *pref = qos_pref; + *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, BT_BAP_ASCS_REASON_NONE); bt_bap_stream_cb_register(*stream, &mock_bap_stream_ops); diff --git a/tests/bluetooth/audio/mocks/include/bap_unicast_server.h b/tests/bluetooth/audio/mocks/include/bap_unicast_server.h index dc6bf33a4c3a..77d10b3f5d5b 100644 --- a/tests/bluetooth/audio/mocks/include/bap_unicast_server.h +++ b/tests/bluetooth/audio/mocks/include/bap_unicast_server.h @@ -17,19 +17,24 @@ void mock_bap_unicast_server_cleanup(void); DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_config, struct bt_conn *, const struct bt_bap_ep *, enum bt_audio_dir, const struct bt_codec *, - struct bt_bap_stream **, struct bt_codec_qos_pref *const); + struct bt_bap_stream **, struct bt_codec_qos_pref *const, + struct bt_bap_ascs_rsp *); DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_reconfig, struct bt_bap_stream *, enum bt_audio_dir, const struct bt_codec *, - struct bt_codec_qos_pref *const); + struct bt_codec_qos_pref *const, struct bt_bap_ascs_rsp *); DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_qos, struct bt_bap_stream *, - const struct bt_codec_qos *); + const struct bt_codec_qos *, struct bt_bap_ascs_rsp *); DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_enable, struct bt_bap_stream *, - const struct bt_codec_data *, size_t); -DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_start, struct bt_bap_stream *); + const struct bt_codec_data *, size_t, struct bt_bap_ascs_rsp *); +DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_start, struct bt_bap_stream *, + struct bt_bap_ascs_rsp *); DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_metadata, struct bt_bap_stream *, - const struct bt_codec_data *, size_t); -DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_disable, struct bt_bap_stream *); -DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_stop, struct bt_bap_stream *); -DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_release, struct bt_bap_stream *); + const struct bt_codec_data *, size_t, struct bt_bap_ascs_rsp *); +DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_disable, struct bt_bap_stream *, + struct bt_bap_ascs_rsp *); +DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_stop, struct bt_bap_stream *, + struct bt_bap_ascs_rsp *); +DECLARE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_release, struct bt_bap_stream *, + struct bt_bap_ascs_rsp *); #endif /* MOCKS_BAP_UNICAST_SERVER_H_ */ diff --git a/tests/bluetooth/audio/mocks/src/bap_unicast_server.c b/tests/bluetooth/audio/mocks/src/bap_unicast_server.c index 70e864afaef8..b59180d0a426 100644 --- a/tests/bluetooth/audio/mocks/src/bap_unicast_server.c +++ b/tests/bluetooth/audio/mocks/src/bap_unicast_server.c @@ -32,19 +32,25 @@ void mock_bap_unicast_server_cleanup(void) DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_config, struct bt_conn *, const struct bt_bap_ep *, enum bt_audio_dir, const struct bt_codec *, - struct bt_bap_stream **, struct bt_codec_qos_pref *const); + struct bt_bap_stream **, struct bt_codec_qos_pref *const, + struct bt_bap_ascs_rsp *); DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_reconfig, struct bt_bap_stream *, - enum bt_audio_dir, const struct bt_codec *, struct bt_codec_qos_pref *const); + enum bt_audio_dir, const struct bt_codec *, struct bt_codec_qos_pref *const, + struct bt_bap_ascs_rsp *); DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_qos, struct bt_bap_stream *, - const struct bt_codec_qos *); + const struct bt_codec_qos *, struct bt_bap_ascs_rsp *); DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_enable, struct bt_bap_stream *, - const struct bt_codec_data *, size_t); -DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_start, struct bt_bap_stream *); + const struct bt_codec_data *, size_t, struct bt_bap_ascs_rsp *); +DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_start, struct bt_bap_stream *, + struct bt_bap_ascs_rsp *); DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_metadata, struct bt_bap_stream *, - const struct bt_codec_data *, size_t); -DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_disable, struct bt_bap_stream *); -DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_stop, struct bt_bap_stream *); -DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_release, struct bt_bap_stream *); + const struct bt_codec_data *, size_t, struct bt_bap_ascs_rsp *); +DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_disable, struct bt_bap_stream *, + struct bt_bap_ascs_rsp *); +DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_stop, struct bt_bap_stream *, + struct bt_bap_ascs_rsp *); +DEFINE_FAKE_VALUE_FUNC(int, mock_bap_unicast_server_cb_release, struct bt_bap_stream *, + struct bt_bap_ascs_rsp *); const struct bt_bap_unicast_server_cb mock_bap_unicast_server_cb = { .config = mock_bap_unicast_server_cb_config, From 28d0789c37799f5287e240157489f9e9ec9b153c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Wed, 22 Mar 2023 15:14:30 +0100 Subject: [PATCH 0674/1906] tests: uart_mix_fifo_poll: Use "counter_dev" node label MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test needs a counter device. Introduce a node label that allows selecting one in dts overlays instead of using hard-coded `timer0`. Signed-off-by: Andrzej Głąbek --- .../uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.overlay | 2 +- .../boards/nrf5340dk_nrf5340_cpuapp.overlay | 2 +- .../uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.overlay | 2 +- tests/drivers/uart/uart_mix_fifo_poll/src/main.c | 8 +++++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.overlay b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.overlay index 23683b8910ec..65c68671ba54 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.overlay +++ b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.overlay @@ -64,6 +64,6 @@ interrupts = <17 2>; }; -&timer0 { +counter_dev: &timer0 { status = "okay"; }; diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.overlay b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.overlay index 897d1ea07c4f..6ace0eb70b63 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.overlay +++ b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -35,6 +35,6 @@ interrupts = <21 2>; }; -&timer0 { +counter_dev: &timer0 { status = "okay"; }; diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.overlay b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.overlay index f43044e17267..cec7d7c85624 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.overlay +++ b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.overlay @@ -35,6 +35,6 @@ interrupts = <21 2>; }; -&timer0 { +counter_dev: &timer0 { status = "okay"; }; diff --git a/tests/drivers/uart/uart_mix_fifo_poll/src/main.c b/tests/drivers/uart/uart_mix_fifo_poll/src/main.c index bc67d4327b9d..b2969c303cac 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/src/main.c +++ b/tests/drivers/uart/uart_mix_fifo_poll/src/main.c @@ -33,6 +33,12 @@ #define UART_DEVICE_DEV DT_CHOSEN(zephyr_console) #endif +#if DT_NODE_EXISTS(DT_NODELABEL(counter_dev)) +#define COUNTER_NODE DT_NODELABEL(counter_dev) +#else +#define COUNTER_NODE DT_NODELABEL(timer0) +#endif + struct rx_source { int cnt; uint8_t prev; @@ -63,7 +69,7 @@ static struct test_data test_data[3]; static struct test_data int_async_data; static const struct device *const counter_dev = - DEVICE_DT_GET(DT_NODELABEL(timer0)); + DEVICE_DT_GET(COUNTER_NODE); static const struct device *const uart_dev = DEVICE_DT_GET(UART_DEVICE_DEV); From 67d851fb648acb5bea1f0a26a7c369437684d66f Mon Sep 17 00:00:00 2001 From: Declan Snyder Date: Wed, 22 Mar 2023 10:26:31 -0500 Subject: [PATCH 0675/1906] boards: mimxrt101X_evk: Add flash chosen node RT series now uses flash chosen node, add to RT101X boards Signed-off-by: Declan Snyder --- boards/arm/mimxrt1010_evk/mimxrt1010_evk.dts | 1 + boards/arm/mimxrt1015_evk/mimxrt1015_evk.dts | 1 + 2 files changed, 2 insertions(+) diff --git a/boards/arm/mimxrt1010_evk/mimxrt1010_evk.dts b/boards/arm/mimxrt1010_evk/mimxrt1010_evk.dts index a573ed12c7e3..9f080309ee5c 100644 --- a/boards/arm/mimxrt1010_evk/mimxrt1010_evk.dts +++ b/boards/arm/mimxrt1010_evk/mimxrt1010_evk.dts @@ -23,6 +23,7 @@ zephyr,itcm = &itcm; zephyr,console = &lpuart1; zephyr,shell-uart = &lpuart1; + zephyr,flash = &at25sf128a; }; leds { diff --git a/boards/arm/mimxrt1015_evk/mimxrt1015_evk.dts b/boards/arm/mimxrt1015_evk/mimxrt1015_evk.dts index 97992dbdb263..d535567ef68a 100644 --- a/boards/arm/mimxrt1015_evk/mimxrt1015_evk.dts +++ b/boards/arm/mimxrt1015_evk/mimxrt1015_evk.dts @@ -23,6 +23,7 @@ zephyr,itcm = &itcm; zephyr,console = &lpuart1; zephyr,shell-uart = &lpuart1; + zephyr,flash = &at25sf128a; }; leds { From 368f2e729c8bdb1c62833d6dd0e9df0b6f124763 Mon Sep 17 00:00:00 2001 From: Tristan Honscheid Date: Wed, 22 Mar 2023 13:15:20 -0600 Subject: [PATCH 0676/1906] microchip: espi: Fix bug in dependency on ESPI Kconfig `Kconfig.xec` for the ESPI drivers requires DT_HAS_MICROCHIP_XEC_ESPI_SAF_ENABLED and DT_HAS_MICROCHIP_XEC_ESPI_SAF_V2_ENABLED for ESPI_XEC and ESPI_XEC_V2, respectively, but SAF is not mandatory for using ESPI. This is a bug and should be dependent on DT_HAS_MICROCHIP_XEC_ESPI_ENABLED and DT_HAS_MICROCHIP_XEC_ESPI_ENABLED, respectively. Also make these default to `y` so they can be automatically enabled by the device tree. Signed-off-by: Tristan Honscheid --- drivers/espi/Kconfig.xec | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/espi/Kconfig.xec b/drivers/espi/Kconfig.xec index 7c9285dbf37f..b110f91cfb0f 100644 --- a/drivers/espi/Kconfig.xec +++ b/drivers/espi/Kconfig.xec @@ -5,13 +5,15 @@ config ESPI_XEC bool "XEC Microchip ESPI driver" - depends on DT_HAS_MICROCHIP_XEC_ESPI_SAF_ENABLED + default y + depends on DT_HAS_MICROCHIP_XEC_ESPI_ENABLED help Enable the Microchip XEC ESPI driver for MEC15xx family. config ESPI_XEC_V2 bool "XEC Microchip ESPI V2 driver" - depends on DT_HAS_MICROCHIP_XEC_ESPI_SAF_V2_ENABLED + default y + depends on DT_HAS_MICROCHIP_XEC_ESPI_V2_ENABLED help Enable the Microchip XEC ESPI driver for MEC172x series. From 2cbe097b29ac060affb45005782ec20e4653c661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 21 Mar 2023 15:16:56 +0100 Subject: [PATCH 0677/1906] tests: drivers: uart: Use "dut" node label to select UART to be tested MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... to limit #if chains in these tests and make it easier to add new boards. Signed-off-by: Andrzej Głąbek --- .../boards/atsamd21_xpro.overlay | 2 +- .../boards/atsame54_xpro.overlay | 2 +- .../boards/atsaml21_xpro.overlay | 2 +- .../boards/atsamr21_xpro.overlay | 2 +- .../boards/atsamr34_xpro.overlay | 2 +- .../boards/b_u585i_iot02a.overlay | 2 +- .../boards/disco_l475_iot1.overlay | 2 +- .../boards/esp32c3_devkitm.overlay | 2 +- .../uart_async_api/boards/frdm_k82f.overlay | 2 +- .../boards/mimxrt1010_evk.overlay | 2 +- .../boards/mimxrt1015_evk.overlay | 2 +- .../boards/mimxrt1020_evk.overlay | 2 +- .../boards/mimxrt1024_evk.overlay | 2 +- .../boards/mimxrt1050_evk.overlay | 2 +- .../boards/mimxrt1060_evk.overlay | 2 +- .../boards/mimxrt1060_evkb.overlay | 2 +- .../boards/mimxrt1064_evk.overlay | 2 +- .../boards/mimxrt1160_evk_cm4.overlay | 2 +- .../boards/mimxrt1160_evk_cm7.overlay | 2 +- .../boards/mimxrt1170_evk_cm4.overlay | 2 +- .../boards/mimxrt1170_evk_cm7.overlay | 2 +- .../boards/nrf52840dk_nrf52840.overlay | 2 +- .../boards/nrf5340dk_nrf5340_cpuapp.overlay | 2 +- .../boards/nrf9160dk_nrf9160.overlay | 2 +- .../boards/nucleo_f103rb.overlay | 2 +- .../boards/nucleo_f207zg.overlay | 2 +- .../boards/nucleo_f429zi.overlay | 2 +- .../boards/nucleo_f746zg.overlay | 2 +- .../boards/nucleo_f767zi.overlay | 2 +- .../boards/nucleo_g071rb.overlay | 2 +- .../boards/nucleo_g474re.overlay | 2 +- .../boards/nucleo_h723zg.overlay | 2 +- .../boards/nucleo_h743zi.overlay | 2 +- .../boards/nucleo_l152re.overlay | 2 +- .../boards/nucleo_l4r5zi.overlay | 2 +- .../boards/nucleo_l552ze_q.overlay | 2 +- .../boards/nucleo_l552ze_q_ns.overlay | 2 +- .../boards/nucleo_u575zi_q.overlay | 2 +- .../boards/nucleo_wb55rg.overlay | 2 +- .../boards/nucleo_wl55jc.overlay | 2 +- .../uart_async_api/boards/segger_rtt.overlay | 2 +- .../boards/stm32f3_disco.overlay | 2 +- .../boards/stm32l562e_dk.overlay | 2 +- .../boards/stm32l562e_dk_ns.overlay | 2 +- .../uart_async_api/boards/twr_ke18f.overlay | 2 +- .../boards/xmc45_relax_kit.overlay | 2 +- .../uart/uart_async_api/src/test_uart.h | 72 ++----------------- .../uart/uart_async_api/src/test_uart_async.c | 2 +- .../boards/nrf52840dk_nrf52840.overlay | 2 +- .../boards/nrf5340dk_nrf5340_cpuapp.overlay | 2 +- .../boards/nrf9160dk_nrf9160.overlay | 2 +- .../uart/uart_mix_fifo_poll/src/main.c | 18 ++--- .../boards/nrf52840dk_nrf52840.overlay | 2 +- .../uart/uart_pm/nrf_rx_disable.overlay | 2 +- tests/drivers/uart/uart_pm/src/main.c | 14 ++-- 55 files changed, 68 insertions(+), 140 deletions(-) diff --git a/tests/drivers/uart/uart_async_api/boards/atsamd21_xpro.overlay b/tests/drivers/uart/uart_async_api/boards/atsamd21_xpro.overlay index dd7bf28f3029..5118ff59dcaf 100644 --- a/tests/drivers/uart/uart_async_api/boards/atsamd21_xpro.overlay +++ b/tests/drivers/uart/uart_async_api/boards/atsamd21_xpro.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&sercom1 { +dut: &sercom1 { /* Internally loop-back TX and RX on PAD0 */ rxpo = <0>; txpo = <0>; diff --git a/tests/drivers/uart/uart_async_api/boards/atsame54_xpro.overlay b/tests/drivers/uart/uart_async_api/boards/atsame54_xpro.overlay index 352cbeaf2abe..1ea33cab5ae0 100644 --- a/tests/drivers/uart/uart_async_api/boards/atsame54_xpro.overlay +++ b/tests/drivers/uart/uart_async_api/boards/atsame54_xpro.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&sercom1 { +dut: &sercom1 { status = "okay"; compatible = "atmel,sam0-uart"; current-speed = <115200>; diff --git a/tests/drivers/uart/uart_async_api/boards/atsaml21_xpro.overlay b/tests/drivers/uart/uart_async_api/boards/atsaml21_xpro.overlay index 42c6b298e8b6..1fefe7d52b13 100644 --- a/tests/drivers/uart/uart_async_api/boards/atsaml21_xpro.overlay +++ b/tests/drivers/uart/uart_async_api/boards/atsaml21_xpro.overlay @@ -8,7 +8,7 @@ status = "okay"; }; -&sercom1 { +dut: &sercom1 { /* internally loop-back Tx and Rx on PAD0 */ rxpo = <0>; txpo = <0>; diff --git a/tests/drivers/uart/uart_async_api/boards/atsamr21_xpro.overlay b/tests/drivers/uart/uart_async_api/boards/atsamr21_xpro.overlay index cc6af1714e77..81bf5bf22bcf 100644 --- a/tests/drivers/uart/uart_async_api/boards/atsamr21_xpro.overlay +++ b/tests/drivers/uart/uart_async_api/boards/atsamr21_xpro.overlay @@ -18,7 +18,7 @@ dma-names = "rx", "tx"; }; -&sercom3 { +dut: &sercom3 { status = "okay"; compatible = "atmel,sam0-uart"; current-speed = <115200>; diff --git a/tests/drivers/uart/uart_async_api/boards/atsamr34_xpro.overlay b/tests/drivers/uart/uart_async_api/boards/atsamr34_xpro.overlay index 0e7a6c43b62e..980af8e46359 100644 --- a/tests/drivers/uart/uart_async_api/boards/atsamr34_xpro.overlay +++ b/tests/drivers/uart/uart_async_api/boards/atsamr34_xpro.overlay @@ -21,7 +21,7 @@ }; }; }; -&sercom2 { +dut: &sercom2 { status = "okay"; compatible = "atmel,sam0-uart"; current-speed = <115200>; diff --git a/tests/drivers/uart/uart_async_api/boards/b_u585i_iot02a.overlay b/tests/drivers/uart/uart_async_api/boards/b_u585i_iot02a.overlay index 8be4bfca4e9f..d669d95d7ed8 100644 --- a/tests/drivers/uart/uart_async_api/boards/b_u585i_iot02a.overlay +++ b/tests/drivers/uart/uart_async_api/boards/b_u585i_iot02a.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&usart3 { +dut: &usart3 { dmas = <&gpdma1 0 29 STM32_DMA_PERIPH_TX &gpdma1 1 28 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/disco_l475_iot1.overlay b/tests/drivers/uart/uart_async_api/boards/disco_l475_iot1.overlay index 526612620d1b..051b9bb4d4c0 100644 --- a/tests/drivers/uart/uart_async_api/boards/disco_l475_iot1.overlay +++ b/tests/drivers/uart/uart_async_api/boards/disco_l475_iot1.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&uart4 { +dut: &uart4 { dmas = <&dma2 3 2 (STM32_DMA_PERIPH_TX | STM32_DMA_PRIORITY_HIGH)>, <&dma2 5 2 (STM32_DMA_PERIPH_RX | STM32_DMA_PRIORITY_HIGH)>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/esp32c3_devkitm.overlay b/tests/drivers/uart/uart_async_api/boards/esp32c3_devkitm.overlay index bf7b845cb553..8fdb4f5e90cb 100644 --- a/tests/drivers/uart/uart_async_api/boards/esp32c3_devkitm.overlay +++ b/tests/drivers/uart/uart_async_api/boards/esp32c3_devkitm.overlay @@ -17,7 +17,7 @@ }; }; -&uart1 { +dut: &uart1 { status = "okay"; current-speed = <115200>; pinctrl-0 = <&uart1_test>; diff --git a/tests/drivers/uart/uart_async_api/boards/frdm_k82f.overlay b/tests/drivers/uart/uart_async_api/boards/frdm_k82f.overlay index 294f1a769e0b..32b83b5c016c 100644 --- a/tests/drivers/uart/uart_async_api/boards/frdm_k82f.overlay +++ b/tests/drivers/uart/uart_async_api/boards/frdm_k82f.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&lpuart0 { +dut: &lpuart0 { status = "okay"; current-speed = <115200>; nxp,loopback; diff --git a/tests/drivers/uart/uart_async_api/boards/mimxrt1010_evk.overlay b/tests/drivers/uart/uart_async_api/boards/mimxrt1010_evk.overlay index 31b706038156..b5730afcc629 100644 --- a/tests/drivers/uart/uart_async_api/boards/mimxrt1010_evk.overlay +++ b/tests/drivers/uart/uart_async_api/boards/mimxrt1010_evk.overlay @@ -6,7 +6,7 @@ }; }; -&lpuart4 { +dut: &lpuart4 { status = "okay"; current-speed = <115200>; }; diff --git a/tests/drivers/uart/uart_async_api/boards/mimxrt1015_evk.overlay b/tests/drivers/uart/uart_async_api/boards/mimxrt1015_evk.overlay index cc6e2506f0ce..5f9852e0b23e 100644 --- a/tests/drivers/uart/uart_async_api/boards/mimxrt1015_evk.overlay +++ b/tests/drivers/uart/uart_async_api/boards/mimxrt1015_evk.overlay @@ -6,7 +6,7 @@ }; }; -&lpuart4 { +dut: &lpuart4 { status = "okay"; current-speed = <115200>; nxp,loopback; diff --git a/tests/drivers/uart/uart_async_api/boards/mimxrt1020_evk.overlay b/tests/drivers/uart/uart_async_api/boards/mimxrt1020_evk.overlay index 64987242a185..37f2577dc2a0 100644 --- a/tests/drivers/uart/uart_async_api/boards/mimxrt1020_evk.overlay +++ b/tests/drivers/uart/uart_async_api/boards/mimxrt1020_evk.overlay @@ -6,7 +6,7 @@ }; }; -&lpuart2 { +dut: &lpuart2 { status = "okay"; current-speed = <115200>; nxp,loopback; diff --git a/tests/drivers/uart/uart_async_api/boards/mimxrt1024_evk.overlay b/tests/drivers/uart/uart_async_api/boards/mimxrt1024_evk.overlay index c52ae7b201cb..5c76a2a49023 100644 --- a/tests/drivers/uart/uart_async_api/boards/mimxrt1024_evk.overlay +++ b/tests/drivers/uart/uart_async_api/boards/mimxrt1024_evk.overlay @@ -6,7 +6,7 @@ }; }; -&lpuart2 { +dut: &lpuart2 { status = "okay"; current-speed = <115200>; }; diff --git a/tests/drivers/uart/uart_async_api/boards/mimxrt1050_evk.overlay b/tests/drivers/uart/uart_async_api/boards/mimxrt1050_evk.overlay index ac510763951a..a31110fc10f9 100644 --- a/tests/drivers/uart/uart_async_api/boards/mimxrt1050_evk.overlay +++ b/tests/drivers/uart/uart_async_api/boards/mimxrt1050_evk.overlay @@ -6,7 +6,7 @@ }; }; -&lpuart3 { +dut: &lpuart3 { status = "okay"; current-speed = <115200>; nxp,loopback; diff --git a/tests/drivers/uart/uart_async_api/boards/mimxrt1060_evk.overlay b/tests/drivers/uart/uart_async_api/boards/mimxrt1060_evk.overlay index ac510763951a..a31110fc10f9 100644 --- a/tests/drivers/uart/uart_async_api/boards/mimxrt1060_evk.overlay +++ b/tests/drivers/uart/uart_async_api/boards/mimxrt1060_evk.overlay @@ -6,7 +6,7 @@ }; }; -&lpuart3 { +dut: &lpuart3 { status = "okay"; current-speed = <115200>; nxp,loopback; diff --git a/tests/drivers/uart/uart_async_api/boards/mimxrt1060_evkb.overlay b/tests/drivers/uart/uart_async_api/boards/mimxrt1060_evkb.overlay index ac510763951a..a31110fc10f9 100644 --- a/tests/drivers/uart/uart_async_api/boards/mimxrt1060_evkb.overlay +++ b/tests/drivers/uart/uart_async_api/boards/mimxrt1060_evkb.overlay @@ -6,7 +6,7 @@ }; }; -&lpuart3 { +dut: &lpuart3 { status = "okay"; current-speed = <115200>; nxp,loopback; diff --git a/tests/drivers/uart/uart_async_api/boards/mimxrt1064_evk.overlay b/tests/drivers/uart/uart_async_api/boards/mimxrt1064_evk.overlay index ac510763951a..a31110fc10f9 100644 --- a/tests/drivers/uart/uart_async_api/boards/mimxrt1064_evk.overlay +++ b/tests/drivers/uart/uart_async_api/boards/mimxrt1064_evk.overlay @@ -6,7 +6,7 @@ }; }; -&lpuart3 { +dut: &lpuart3 { status = "okay"; current-speed = <115200>; nxp,loopback; diff --git a/tests/drivers/uart/uart_async_api/boards/mimxrt1160_evk_cm4.overlay b/tests/drivers/uart/uart_async_api/boards/mimxrt1160_evk_cm4.overlay index e1261ac9c10b..4f031193d152 100644 --- a/tests/drivers/uart/uart_async_api/boards/mimxrt1160_evk_cm4.overlay +++ b/tests/drivers/uart/uart_async_api/boards/mimxrt1160_evk_cm4.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&lpuart2 { +dut: &lpuart2 { status = "okay"; current-speed = <115200>; nxp,loopback; diff --git a/tests/drivers/uart/uart_async_api/boards/mimxrt1160_evk_cm7.overlay b/tests/drivers/uart/uart_async_api/boards/mimxrt1160_evk_cm7.overlay index 64987242a185..37f2577dc2a0 100644 --- a/tests/drivers/uart/uart_async_api/boards/mimxrt1160_evk_cm7.overlay +++ b/tests/drivers/uart/uart_async_api/boards/mimxrt1160_evk_cm7.overlay @@ -6,7 +6,7 @@ }; }; -&lpuart2 { +dut: &lpuart2 { status = "okay"; current-speed = <115200>; nxp,loopback; diff --git a/tests/drivers/uart/uart_async_api/boards/mimxrt1170_evk_cm4.overlay b/tests/drivers/uart/uart_async_api/boards/mimxrt1170_evk_cm4.overlay index e1261ac9c10b..4f031193d152 100644 --- a/tests/drivers/uart/uart_async_api/boards/mimxrt1170_evk_cm4.overlay +++ b/tests/drivers/uart/uart_async_api/boards/mimxrt1170_evk_cm4.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&lpuart2 { +dut: &lpuart2 { status = "okay"; current-speed = <115200>; nxp,loopback; diff --git a/tests/drivers/uart/uart_async_api/boards/mimxrt1170_evk_cm7.overlay b/tests/drivers/uart/uart_async_api/boards/mimxrt1170_evk_cm7.overlay index 64987242a185..37f2577dc2a0 100644 --- a/tests/drivers/uart/uart_async_api/boards/mimxrt1170_evk_cm7.overlay +++ b/tests/drivers/uart/uart_async_api/boards/mimxrt1170_evk_cm7.overlay @@ -6,7 +6,7 @@ }; }; -&lpuart2 { +dut: &lpuart2 { status = "okay"; current-speed = <115200>; nxp,loopback; diff --git a/tests/drivers/uart/uart_async_api/boards/nrf52840dk_nrf52840.overlay b/tests/drivers/uart/uart_async_api/boards/nrf52840dk_nrf52840.overlay index 86f2ea169cd5..33db6c30e053 100644 --- a/tests/drivers/uart/uart_async_api/boards/nrf52840dk_nrf52840.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nrf52840dk_nrf52840.overlay @@ -50,7 +50,7 @@ pinctrl-names = "default", "sleep"; }; -&uart0 { +dut: &uart0 { compatible = "nordic,nrf-uarte"; current-speed = <115200>; status = "okay"; diff --git a/tests/drivers/uart/uart_async_api/boards/nrf5340dk_nrf5340_cpuapp.overlay b/tests/drivers/uart/uart_async_api/boards/nrf5340dk_nrf5340_cpuapp.overlay index 05c75d22d15d..81ae813daf3c 100644 --- a/tests/drivers/uart/uart_async_api/boards/nrf5340dk_nrf5340_cpuapp.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -17,7 +17,7 @@ }; }; -&uart1 { +dut: &uart1 { compatible = "nordic,nrf-uarte"; current-speed = <115200>; status = "okay"; diff --git a/tests/drivers/uart/uart_async_api/boards/nrf9160dk_nrf9160.overlay b/tests/drivers/uart/uart_async_api/boards/nrf9160dk_nrf9160.overlay index 1fbe8f25e1fc..db661098ad88 100644 --- a/tests/drivers/uart/uart_async_api/boards/nrf9160dk_nrf9160.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nrf9160dk_nrf9160.overlay @@ -17,7 +17,7 @@ }; }; -&uart1 { +dut: &uart1 { current-speed = <115200>; compatible = "nordic,nrf-uarte"; status = "okay"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_f103rb.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_f103rb.overlay index ea896616cdd5..034670edfb92 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_f103rb.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_f103rb.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&usart1 { +dut: &usart1 { dmas = <&dma1 4 STM32_DMA_PERIPH_TX>, <&dma1 5 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_f207zg.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_f207zg.overlay index 387550a8b98d..f727d709a387 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_f207zg.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_f207zg.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&usart6 { +dut: &usart6 { dmas = <&dma2 7 5 0x28440 0x03>, <&dma2 2 5 0x28480 0x03>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_f429zi.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_f429zi.overlay index 36db5f980db5..c5174fda3ff4 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_f429zi.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_f429zi.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&usart6 { +dut: &usart6 { dmas = <&dma2 7 5 0x28440 0x03>, <&dma2 2 5 0x28480 0x03>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_f746zg.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_f746zg.overlay index d40b5b3b9495..e9ee7174e10d 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_f746zg.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_f746zg.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&usart6 { +dut: &usart6 { dmas = <&dma2 7 5 0x28440 0x03>, <&dma2 2 5 0x28480 0x03>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_f767zi.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_f767zi.overlay index 36db5f980db5..c5174fda3ff4 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_f767zi.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_f767zi.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&usart6 { +dut: &usart6 { dmas = <&dma2 7 5 0x28440 0x03>, <&dma2 2 5 0x28480 0x03>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_g071rb.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_g071rb.overlay index 359c257a8b18..4d24dc2e752b 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_g071rb.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_g071rb.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&usart1 { +dut: &usart1 { dmas = <&dmamux1 5 51 STM32_DMA_PERIPH_TX>, <&dmamux1 4 50 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_g474re.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_g474re.overlay index 9e782d979574..63259383dea4 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_g474re.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_g474re.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&usart1 { +dut: &usart1 { dmas = <&dmamux1 2 25 STM32_DMA_PERIPH_TX>, <&dmamux1 1 24 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_h723zg.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_h723zg.overlay index 6c0321e3dce3..1eef7ad3ae93 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_h723zg.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_h723zg.overlay @@ -2,7 +2,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -&usart2 { +dut: &usart2 { dmas = <&dmamux1 2 44 STM32_DMA_PERIPH_TX>, <&dmamux1 3 43 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_h743zi.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_h743zi.overlay index 322ac98adec3..13c49ed1337f 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_h743zi.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_h743zi.overlay @@ -2,7 +2,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -&usart2 { +dut: &usart2 { dmas = <&dmamux1 2 44 STM32_DMA_PERIPH_TX>, <&dmamux1 3 43 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_l152re.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_l152re.overlay index 2bf12cb21bce..13ca9a1b2518 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_l152re.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_l152re.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&usart3 { +dut: &usart3 { pinctrl-0 = <&usart3_tx_pb10 &usart3_rx_pb11>; pinctrl-names = "default"; current-speed = <115200>; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_l4r5zi.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_l4r5zi.overlay index 0c6942dfc025..547eb79e757d 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_l4r5zi.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_l4r5zi.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&usart3 { +dut: &usart3 { dmas = <&dmamux1 5 29 STM32_DMA_PERIPH_TX>, <&dmamux1 4 28 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_l552ze_q.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_l552ze_q.overlay index fe7610d3bc05..bc491885737a 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_l552ze_q.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_l552ze_q.overlay @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -&usart3 { +dut: &usart3 { dmas = <&dmamux1 5 30 STM32_DMA_PERIPH_TX>, <&dmamux1 4 29 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_l552ze_q_ns.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_l552ze_q_ns.overlay index fe7610d3bc05..bc491885737a 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_l552ze_q_ns.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_l552ze_q_ns.overlay @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -&usart3 { +dut: &usart3 { dmas = <&dmamux1 5 30 STM32_DMA_PERIPH_TX>, <&dmamux1 4 29 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_u575zi_q.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_u575zi_q.overlay index fd7cc456d10f..c730061c17a0 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_u575zi_q.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_u575zi_q.overlay @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -&usart2 { +dut: &usart2 { dmas = <&gpdma1 0 27 STM32_DMA_PERIPH_TX &gpdma1 1 26 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_wb55rg.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_wb55rg.overlay index 5a6ea12945f6..19da29a73709 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_wb55rg.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_wb55rg.overlay @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -&lpuart1 { +dut: &lpuart1 { /delete-property/ hw-flow-control; dmas = <&dmamux1 0 17 (STM32_DMA_PERIPH_TX | STM32_DMA_PRIORITY_HIGH) &dmamux1 1 16 (STM32_DMA_PERIPH_RX | STM32_DMA_PRIORITY_HIGH)>; diff --git a/tests/drivers/uart/uart_async_api/boards/nucleo_wl55jc.overlay b/tests/drivers/uart/uart_async_api/boards/nucleo_wl55jc.overlay index 1b9611d4ff8e..6387e96e6496 100644 --- a/tests/drivers/uart/uart_async_api/boards/nucleo_wl55jc.overlay +++ b/tests/drivers/uart/uart_async_api/boards/nucleo_wl55jc.overlay @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -&usart1 { +dut: &usart1 { dmas = <&dmamux1 11 18 (STM32_DMA_PERIPH_TX | STM32_DMA_PRIORITY_HIGH) &dmamux1 1 17 (STM32_DMA_PERIPH_RX | STM32_DMA_PRIORITY_HIGH)>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/segger_rtt.overlay b/tests/drivers/uart/uart_async_api/boards/segger_rtt.overlay index 31e1eac64ec6..d7eb016cd5dd 100644 --- a/tests/drivers/uart/uart_async_api/boards/segger_rtt.overlay +++ b/tests/drivers/uart/uart_async_api/boards/segger_rtt.overlay @@ -5,7 +5,7 @@ zephyr,console = &rtt0; }; - rtt0: rtt_chan0 { + dut: rtt0: rtt_chan0 { compatible = "segger,rtt-uart"; status = "okay"; }; diff --git a/tests/drivers/uart/uart_async_api/boards/stm32f3_disco.overlay b/tests/drivers/uart/uart_async_api/boards/stm32f3_disco.overlay index ab44d7709828..c30d89f0f5ee 100644 --- a/tests/drivers/uart/uart_async_api/boards/stm32f3_disco.overlay +++ b/tests/drivers/uart/uart_async_api/boards/stm32f3_disco.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&usart2 { +dut: &usart2 { dmas = <&dma1 7 STM32_DMA_PERIPH_TX>, <&dma1 6 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/stm32l562e_dk.overlay b/tests/drivers/uart/uart_async_api/boards/stm32l562e_dk.overlay index fe7610d3bc05..bc491885737a 100644 --- a/tests/drivers/uart/uart_async_api/boards/stm32l562e_dk.overlay +++ b/tests/drivers/uart/uart_async_api/boards/stm32l562e_dk.overlay @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -&usart3 { +dut: &usart3 { dmas = <&dmamux1 5 30 STM32_DMA_PERIPH_TX>, <&dmamux1 4 29 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/stm32l562e_dk_ns.overlay b/tests/drivers/uart/uart_async_api/boards/stm32l562e_dk_ns.overlay index fe7610d3bc05..bc491885737a 100644 --- a/tests/drivers/uart/uart_async_api/boards/stm32l562e_dk_ns.overlay +++ b/tests/drivers/uart/uart_async_api/boards/stm32l562e_dk_ns.overlay @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -&usart3 { +dut: &usart3 { dmas = <&dmamux1 5 30 STM32_DMA_PERIPH_TX>, <&dmamux1 4 29 STM32_DMA_PERIPH_RX>; dma-names = "tx", "rx"; diff --git a/tests/drivers/uart/uart_async_api/boards/twr_ke18f.overlay b/tests/drivers/uart/uart_async_api/boards/twr_ke18f.overlay index e1261ac9c10b..4f031193d152 100644 --- a/tests/drivers/uart/uart_async_api/boards/twr_ke18f.overlay +++ b/tests/drivers/uart/uart_async_api/boards/twr_ke18f.overlay @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&lpuart2 { +dut: &lpuart2 { status = "okay"; current-speed = <115200>; nxp,loopback; diff --git a/tests/drivers/uart/uart_async_api/boards/xmc45_relax_kit.overlay b/tests/drivers/uart/uart_async_api/boards/xmc45_relax_kit.overlay index dc27b1ef5abb..c08d00873660 100644 --- a/tests/drivers/uart/uart_async_api/boards/xmc45_relax_kit.overlay +++ b/tests/drivers/uart/uart_async_api/boards/xmc45_relax_kit.overlay @@ -2,7 +2,7 @@ #include -&usic2ch0 { +dut: &usic2ch0 { compatible = "infineon,xmc4xxx-uart"; current-speed = <921600>; pinctrl-0 = <&uart_tx_p5_0_u2c0 &uart_rx_p5_1_u2c0>; diff --git a/tests/drivers/uart/uart_async_api/src/test_uart.h b/tests/drivers/uart/uart_async_api/src/test_uart.h index 44eba8ede2d5..2bfa470e464f 100644 --- a/tests/drivers/uart/uart_async_api/src/test_uart.h +++ b/tests/drivers/uart/uart_async_api/src/test_uart.h @@ -19,76 +19,12 @@ /* RX and TX pins have to be connected together*/ -/* RTT is first so that when testing RTT we ensure it - * get selected over any other SoC specific uart - */ -#if defined(CONFIG_UART_RTT) -#define UART_DEVICE_DEV DT_NODELABEL(rtt0) -#elif defined(CONFIG_BOARD_NRF52840DK_NRF52840) -#define UART_DEVICE_DEV DT_NODELABEL(uart0) -#elif defined(CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP) -#define UART_DEVICE_DEV DT_NODELABEL(uart1) -#elif defined(CONFIG_BOARD_NRF9160DK_NRF9160) -#define UART_DEVICE_DEV DT_NODELABEL(uart1) -#elif defined(CONFIG_BOARD_ATSAMD21_XPRO) -#define UART_DEVICE_DEV DT_NODELABEL(sercom1) -#elif defined(CONFIG_BOARD_ATSAMR21_XPRO) -#define UART_DEVICE_DEV DT_NODELABEL(sercom3) -#elif defined(CONFIG_BOARD_ATSAML21_XPRO) -#define UART_DEVICE_NAME DT_NODELABEL(sercom1) -#elif defined(CONFIG_BOARD_ATSAMR34_XPRO) -#define UART_DEVICE_NAME DT_NODELABEL(sercom2) -#elif defined(CONFIG_BOARD_ATSAME54_XPRO) -#define UART_DEVICE_DEV DT_NODELABEL(sercom1) -#elif defined(CONFIG_BOARD_NUCLEO_F103RB) || \ - defined(CONFIG_BOARD_NUCLEO_G071RB) || \ - defined(CONFIG_BOARD_NUCLEO_G474RE) || \ - defined(CONFIG_BOARD_NUCLEO_WL55JC) -#define UART_DEVICE_DEV DT_NODELABEL(usart1) -#elif defined(CONFIG_BOARD_NUCLEO_H723ZG) || \ - defined(CONFIG_BOARD_NUCLEO_H743ZI) || \ - defined(CONFIG_BOARD_STM32F3_DISCO) || \ - defined(CONFIG_BOARD_NUCLEO_U575ZI_Q) -#define UART_DEVICE_DEV DT_NODELABEL(usart2) -#elif defined(CONFIG_BOARD_NUCLEO_L4R5ZI) || \ - defined(CONFIG_BOARD_NUCLEO_L152RE) || \ - defined(CONFIG_BOARD_STM32L562E_DK) || \ - defined(CONFIG_BOARD_NUCLEO_L552ZE_Q) || \ - defined(CONFIG_BOARD_B_U585I_IOT02A) -#define UART_DEVICE_DEV DT_NODELABEL(usart3) -#elif defined(CONFIG_BOARD_DISCO_L475_IOT1) -#define UART_DEVICE_DEV DT_NODELABEL(uart4) -#elif defined(CONFIG_BOARD_NUCLEO_F429ZI) || \ - defined(CONFIG_BOARD_NUCLEO_F207ZG) || \ - defined(CONFIG_BOARD_NUCLEO_F767ZI) || \ - defined(CONFIG_BOARD_NUCLEO_F746ZG) -#define UART_DEVICE_DEV DT_NODELABEL(usart6) -#elif defined(CONFIG_BOARD_FRDM_K82F) -#define UART_DEVICE_DEV DT_NODELABEL(lpuart0) -#elif defined(CONFIG_BOARD_NUCLEO_WB55RG) -#define UART_DEVICE_DEV DT_NODELABEL(lpuart1) -#elif defined(CONFIG_BOARD_MIMXRT1020_EVK) || \ - defined(CONFIG_BOARD_MIMXRT1024_EVK) || \ - defined(CONFIG_BOARD_MIMXRT1160_EVK_CM4) || \ - defined(CONFIG_BOARD_MIMXRT1170_EVK_CM4) || \ - defined(CONFIG_BOARD_MIMXRT1160_EVK_CM7) || \ - defined(CONFIG_BOARD_MIMXRT1170_EVK_CM7) || \ - defined(CONFIG_BOARD_TWR_KE18F) -#define UART_DEVICE_DEV DT_NODELABEL(lpuart2) -#elif defined(CONFIG_BOARD_MIMXRT1050_EVK) || \ - defined(CONFIG_BOARD_MIMXRT1060_EVK) || \ - defined(CONFIG_BOARD_MIMXRT1060_EVKB) || \ - defined(CONFIG_BOARD_MIMXRT1064_EVK) -#define UART_DEVICE_DEV DT_NODELABEL(lpuart3) -#elif defined(CONFIG_BOARD_MIMXRT1010_EVK) || \ - defined(CONFIG_BOARD_MIMXRT1015_EVK) -#define UART_DEVICE_DEV DT_NODELABEL(lpuart4) +#if DT_NODE_EXISTS(DT_NODELABEL(dut)) +#define UART_NODE DT_NODELABEL(dut) #elif defined(CONFIG_SOC_ESP32C3) - #define UART_DEVICE_DEV DT_NODELABEL(uart1) -#elif defined(CONFIG_BOARD_XMC45_RELAX_KIT) -#define UART_DEVICE_DEV DT_NODELABEL(usic2ch0) +#define UART_NODE DT_NODELABEL(uart1) #else -#define UART_DEVICE_DEV DT_CHOSEN(zephyr_console) +#define UART_NODE DT_CHOSEN(zephyr_console) #endif #endif /* __TEST_UART_H__ */ diff --git a/tests/drivers/uart/uart_async_api/src/test_uart_async.c b/tests/drivers/uart/uart_async_api/src/test_uart_async.c index b1a1780fffcc..75b4a05a0100 100644 --- a/tests/drivers/uart/uart_async_api/src/test_uart_async.c +++ b/tests/drivers/uart/uart_async_api/src/test_uart_async.c @@ -14,7 +14,7 @@ K_SEM_DEFINE(rx_disabled, 0, 1); ZTEST_BMEM volatile bool failed_in_isr; ZTEST_BMEM static const struct device *const uart_dev = - DEVICE_DT_GET(UART_DEVICE_DEV); + DEVICE_DT_GET(UART_NODE); static void read_abort_timeout(struct k_timer *timer); K_TIMER_DEFINE(read_abort_timer, read_abort_timeout, NULL); diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.overlay b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.overlay index 65c68671ba54..57e6a77cb020 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.overlay +++ b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.overlay @@ -50,7 +50,7 @@ pinctrl-names = "default", "sleep"; }; -&uart0 { +dut: &uart0 { compatible = "nordic,nrf-uarte"; current-speed = <115200>; status = "okay"; diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.overlay b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.overlay index 6ace0eb70b63..5f226b8f30f8 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.overlay +++ b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -21,7 +21,7 @@ }; }; -&uart1 { +dut: &uart1 { current-speed = <115200>; compatible = "nordic,nrf-uarte"; status = "okay"; diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.overlay b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.overlay index cec7d7c85624..5cde22eafe74 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.overlay +++ b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.overlay @@ -21,7 +21,7 @@ }; }; -&uart1 { +dut: &uart1 { current-speed = <115200>; compatible = "nordic,nrf-uarte"; status = "okay"; diff --git a/tests/drivers/uart/uart_mix_fifo_poll/src/main.c b/tests/drivers/uart/uart_mix_fifo_poll/src/main.c index b2969c303cac..f26cce740c0c 100644 --- a/tests/drivers/uart/uart_mix_fifo_poll/src/main.c +++ b/tests/drivers/uart/uart_mix_fifo_poll/src/main.c @@ -17,20 +17,16 @@ #include /* RX and TX pins have to be connected together*/ -#if defined(CONFIG_BOARD_NRF52840DK_NRF52840) -#define UART_DEVICE_DEV DT_NODELABEL(uart0) -#elif defined(CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP) -#define UART_DEVICE_DEV DT_NODELABEL(uart1) -#elif defined(CONFIG_BOARD_NRF9160DK_NRF9160) -#define UART_DEVICE_DEV DT_NODELABEL(uart1) +#if DT_NODE_EXISTS(DT_NODELABEL(dut)) +#define UART_NODE DT_NODELABEL(dut) #elif defined(CONFIG_BOARD_ATSAMD21_XPRO) -#define UART_DEVICE_DEV DT_NODELABEL(sercom1) +#define UART_NODE DT_NODELABEL(sercom1) #elif defined(CONFIG_BOARD_ATSAMR21_XPRO) -#define UART_DEVICE_DEV DT_NODELABEL(sercom3) +#define UART_NODE DT_NODELABEL(sercom3) #elif defined(CONFIG_BOARD_ATSAME54_XPRO) -#define UART_DEVICE_DEV DT_NODELABEL(sercom1) +#define UART_NODE DT_NODELABEL(sercom1) #else -#define UART_DEVICE_DEV DT_CHOSEN(zephyr_console) +#define UART_NODE DT_CHOSEN(zephyr_console) #endif #if DT_NODE_EXISTS(DT_NODELABEL(counter_dev)) @@ -71,7 +67,7 @@ static struct test_data int_async_data; static const struct device *const counter_dev = DEVICE_DT_GET(COUNTER_NODE); static const struct device *const uart_dev = - DEVICE_DT_GET(UART_DEVICE_DEV); + DEVICE_DT_GET(UART_NODE); static bool async; static bool int_driven; diff --git a/tests/drivers/uart/uart_pm/boards/nrf52840dk_nrf52840.overlay b/tests/drivers/uart/uart_pm/boards/nrf52840dk_nrf52840.overlay index 86f2ea169cd5..33db6c30e053 100644 --- a/tests/drivers/uart/uart_pm/boards/nrf52840dk_nrf52840.overlay +++ b/tests/drivers/uart/uart_pm/boards/nrf52840dk_nrf52840.overlay @@ -50,7 +50,7 @@ pinctrl-names = "default", "sleep"; }; -&uart0 { +dut: &uart0 { compatible = "nordic,nrf-uarte"; current-speed = <115200>; status = "okay"; diff --git a/tests/drivers/uart/uart_pm/nrf_rx_disable.overlay b/tests/drivers/uart/uart_pm/nrf_rx_disable.overlay index 2ffb37311c7f..8b751d12bd5f 100644 --- a/tests/drivers/uart/uart_pm/nrf_rx_disable.overlay +++ b/tests/drivers/uart/uart_pm/nrf_rx_disable.overlay @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: Apache-2.0 */ -&uart0 { +&dut { disable-rx; }; diff --git a/tests/drivers/uart/uart_pm/src/main.c b/tests/drivers/uart/uart_pm/src/main.c index 3d7f1b9dc84f..3f4977f7be3b 100644 --- a/tests/drivers/uart/uart_pm/src/main.c +++ b/tests/drivers/uart/uart_pm/src/main.c @@ -9,12 +9,8 @@ #include #include -#if defined(CONFIG_BOARD_NRF52840DK_NRF52840) -#define LABEL uart0 -#endif - -#define UART_DEVICE_DEV DT_NODELABEL(LABEL) -#define HAS_RX DT_NODE_HAS_PROP(DT_NODELABEL(LABEL), rx_pin) +#define UART_NODE DT_NODELABEL(dut) +#define HAS_RX DT_NODE_HAS_PROP(UART_NODE, rx_pin) static void polling_verify(const struct device *dev, bool is_async, bool active) { @@ -156,7 +152,7 @@ ZTEST(uart_pm, test_uart_pm_in_idle) { const struct device *dev; - dev = DEVICE_DT_GET(UART_DEVICE_DEV); + dev = DEVICE_DT_GET(UART_NODE); zassert_true(device_is_ready(dev), "uart device is not ready"); state_verify(dev, PM_DEVICE_STATE_ACTIVE); @@ -179,7 +175,7 @@ ZTEST(uart_pm, test_uart_pm_poll_tx) { const struct device *dev; - dev = DEVICE_DT_GET(UART_DEVICE_DEV); + dev = DEVICE_DT_GET(UART_NODE); zassert_true(device_is_ready(dev), "uart device is not ready"); communication_verify(dev, true); @@ -221,7 +217,7 @@ ZTEST(uart_pm, test_uart_pm_poll_tx_interrupted) const struct device *dev; char str[] = "test"; - dev = DEVICE_DT_GET(UART_DEVICE_DEV); + dev = DEVICE_DT_GET(UART_NODE); zassert_true(device_is_ready(dev), "uart device is not ready"); k_timer_user_data_set(&pm_timer, (void *)dev); From 8cba27aab31699b33d14e2f0099461113b6eadb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 21 Mar 2023 15:30:03 +0100 Subject: [PATCH 0678/1906] tests: drivers: uart_pm: Fix testing of no-RX case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of checking the `rx-pin` property that got deprecated and removed, the test needs to check the `disable-rx` property. Signed-off-by: Andrzej Głąbek --- tests/drivers/uart/uart_pm/src/main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/drivers/uart/uart_pm/src/main.c b/tests/drivers/uart/uart_pm/src/main.c index 3f4977f7be3b..71875a857920 100644 --- a/tests/drivers/uart/uart_pm/src/main.c +++ b/tests/drivers/uart/uart_pm/src/main.c @@ -10,7 +10,7 @@ #include #define UART_NODE DT_NODELABEL(dut) -#define HAS_RX DT_NODE_HAS_PROP(UART_NODE, rx_pin) +#define DISABLED_RX DT_PROP(UART_NODE, disable_rx) static void polling_verify(const struct device *dev, bool is_async, bool active) { @@ -18,7 +18,7 @@ static void polling_verify(const struct device *dev, bool is_async, bool active) char outs[] = "abc"; int err; - if (!HAS_RX || is_async) { + if (DISABLED_RX || is_async) { /* If no RX pin just run few poll outs to check that it does * not hang. */ @@ -78,7 +78,7 @@ static bool async_verify(const struct device *dev, bool active) zassert_equal(err, 0, "Unexpected err: %d", err); - if (HAS_RX) { + if (!DISABLED_RX) { err = uart_rx_enable(dev, rxbuf, sizeof(rxbuf), 1 * USEC_PER_MSEC); zassert_equal(err, 0, "Unexpected err: %d", err); } @@ -88,7 +88,7 @@ static bool async_verify(const struct device *dev, bool active) k_busy_wait(10000); - if (HAS_RX) { + if (!DISABLED_RX) { err = uart_rx_disable(dev); zassert_equal(err, 0, "Unexpected err: %d", err); @@ -239,8 +239,8 @@ ZTEST(uart_pm, test_uart_pm_poll_tx_interrupted) void *uart_pm_setup(void) { - if (!HAS_RX) { - PRINT("No RX pin\n"); + if (DISABLED_RX) { + PRINT("RX is disabled\n"); } return NULL; From 9dc9f0a0fde69a3ec3f50784804cc40d65207385 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 17 Mar 2023 11:19:57 +0100 Subject: [PATCH 0679/1906] drivers: can: common: add missing static for sample_point_for_bitrate() Add missing static keyword for internal function sample_point_for_bitrate(). Signed-off-by: Henrik Brix Andersen --- drivers/can/can_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/can/can_common.c b/drivers/can/can_common.c index 4eafb0f1ccd4..526762fd4f66 100644 --- a/drivers/can/can_common.c +++ b/drivers/can/can_common.c @@ -232,7 +232,7 @@ int can_calc_prescaler(const struct device *dev, struct can_timing *timing, * @param bitrate The bitrate in bits/second. * @return The sample point in permille. */ -uint16_t sample_point_for_bitrate(uint32_t bitrate) +static uint16_t sample_point_for_bitrate(uint32_t bitrate) { uint16_t sample_pnt; From d5672c9ee32c48ba7f49cf5698d98dd42a69e5ec Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 17 Mar 2023 11:21:26 +0100 Subject: [PATCH 0680/1906] drivers: can: check timing parameters Check the requested CAN timing parameters against the min/max values supported by the driver and return an error if they are out of range. Signed-off-by: Henrik Brix Andersen --- drivers/can/can_common.c | 55 ++++++++++++++++++++++++++++++++++++ include/zephyr/drivers/can.h | 34 +++++----------------- 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/drivers/can/can_common.c b/drivers/can/can_common.c index 526762fd4f66..8271c99acd05 100644 --- a/drivers/can/can_common.c +++ b/drivers/can/can_common.c @@ -250,6 +250,41 @@ static uint16_t sample_point_for_bitrate(uint32_t bitrate) return sample_pnt; } +static int check_timing_in_range(const struct can_timing *timing, + const struct can_timing *min, + const struct can_timing *max) +{ + if (timing->sjw != CAN_SJW_NO_CHANGE && + !IN_RANGE(timing->sjw, min->sjw, max->sjw)) { + return -ENOTSUP; + } + + if (!IN_RANGE(timing->prop_seg, min->prop_seg, max->prop_seg) || + !IN_RANGE(timing->phase_seg1, min->phase_seg1, max->phase_seg1) || + !IN_RANGE(timing->phase_seg2, min->phase_seg2, max->phase_seg2) || + !IN_RANGE(timing->prescaler, min->prescaler, max->prescaler)) { + return -ENOTSUP; + } + + return 0; +} + +int z_impl_can_set_timing(const struct device *dev, + const struct can_timing *timing) +{ + const struct can_driver_api *api = (const struct can_driver_api *)dev->api; + const struct can_timing *min = can_get_timing_min(dev); + const struct can_timing *max = can_get_timing_max(dev); + int err; + + err = check_timing_in_range(timing, min, max); + if (err != 0) { + return err; + } + + return api->set_timing(dev, timing); +} + int z_impl_can_set_bitrate(const struct device *dev, uint32_t bitrate) { struct can_timing timing; @@ -285,6 +320,26 @@ int z_impl_can_set_bitrate(const struct device *dev, uint32_t bitrate) } #ifdef CONFIG_CAN_FD_MODE +int z_impl_can_set_timing_data(const struct device *dev, + const struct can_timing *timing_data) +{ + const struct can_driver_api *api = (const struct can_driver_api *)dev->api; + const struct can_timing *min = can_get_timing_data_min(dev); + const struct can_timing *max = can_get_timing_data_max(dev); + int err; + + if (api->set_timing_data == NULL) { + return -ENOSYS; + } + + err = check_timing_in_range(timing_data, min, max); + if (err != 0) { + return err; + } + + return api->set_timing_data(dev, timing_data); +} + int z_impl_can_set_bitrate_data(const struct device *dev, uint32_t bitrate_data) { struct can_timing timing_data; diff --git a/include/zephyr/drivers/can.h b/include/zephyr/drivers/can.h index 600b0fda3eb3..89b6d3c47104 100644 --- a/include/zephyr/drivers/can.h +++ b/include/zephyr/drivers/can.h @@ -234,6 +234,11 @@ struct can_bus_err_cnt { uint8_t rx_err_cnt; }; +/** Synchronization Jump Width (SJW) value to indicate that the SJW should not + * be changed by the timing calculation. + */ +#define CAN_SJW_NO_CHANGE 0 + /** * @brief CAN bus timing structure * @@ -868,25 +873,12 @@ __syscall int can_calc_timing_data(const struct device *dev, struct can_timing * * @retval 0 If successful. * @retval -EBUSY if the CAN controller is not in stopped state. * @retval -EIO General input/output error, failed to configure device. + * @retval -ENOTSUP if the timing parameters are not supported by the driver. * @retval -ENOSYS if CAN-FD support is not implemented by the driver. */ __syscall int can_set_timing_data(const struct device *dev, const struct can_timing *timing_data); -#ifdef CONFIG_CAN_FD_MODE -static inline int z_impl_can_set_timing_data(const struct device *dev, - const struct can_timing *timing_data) -{ - const struct can_driver_api *api = (const struct can_driver_api *)dev->api; - - if (api->set_timing_data == NULL) { - return -ENOSYS; - } - - return api->set_timing_data(dev, timing_data); -} -#endif /* CONFIG_CAN_FD_MODE */ - /** * @brief Set the bitrate for the data phase of the CAN-FD controller * @@ -936,11 +928,6 @@ __syscall int can_set_bitrate_data(const struct device *dev, uint32_t bitrate_da int can_calc_prescaler(const struct device *dev, struct can_timing *timing, uint32_t bitrate); -/** Synchronization Jump Width (SJW) value to indicate that the SJW should not - * be changed by the timing calculation. - */ -#define CAN_SJW_NO_CHANGE 0 - /** * @brief Configure the bus timing of a CAN controller. * @@ -953,19 +940,12 @@ int can_calc_prescaler(const struct device *dev, struct can_timing *timing, * * @retval 0 If successful. * @retval -EBUSY if the CAN controller is not in stopped state. + * @retval -ENOTSUP if the timing parameters are not supported by the driver. * @retval -EIO General input/output error, failed to configure device. */ __syscall int can_set_timing(const struct device *dev, const struct can_timing *timing); -static inline int z_impl_can_set_timing(const struct device *dev, - const struct can_timing *timing) -{ - const struct can_driver_api *api = (const struct can_driver_api *)dev->api; - - return api->set_timing(dev, timing); -} - /** * @brief Get the supported modes of the CAN controller * From 7486fe7a83007af8554ef70a02f5f63b10f9dee9 Mon Sep 17 00:00:00 2001 From: Lucas Tamborrino Date: Thu, 16 Feb 2023 15:07:13 -0300 Subject: [PATCH 0681/1906] dts: esp32s3: add TRNG support Add True Random Number Generator support on esp32s3 Signed-off-by: Lucas Tamborrino --- boards/xtensa/esp32s3_devkitm/Kconfig.defconfig | 3 +++ boards/xtensa/esp32s3_devkitm/doc/index.rst | 2 ++ boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts | 4 ++++ boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml | 1 + dts/xtensa/espressif/esp32s3.dtsi | 7 +++++++ 5 files changed, 17 insertions(+) diff --git a/boards/xtensa/esp32s3_devkitm/Kconfig.defconfig b/boards/xtensa/esp32s3_devkitm/Kconfig.defconfig index b4e160532cd5..17fa3ca55b29 100644 --- a/boards/xtensa/esp32s3_devkitm/Kconfig.defconfig +++ b/boards/xtensa/esp32s3_devkitm/Kconfig.defconfig @@ -6,3 +6,6 @@ config BOARD default "esp32s3_devkitm" depends on BOARD_ESP32S3_DEVKITM + +config ENTROPY_GENERATOR + default y diff --git a/boards/xtensa/esp32s3_devkitm/doc/index.rst b/boards/xtensa/esp32s3_devkitm/doc/index.rst index f65feafac015..ec76afca2c7a 100644 --- a/boards/xtensa/esp32s3_devkitm/doc/index.rst +++ b/boards/xtensa/esp32s3_devkitm/doc/index.rst @@ -96,6 +96,8 @@ Current Zephyr's ESP32-S3-DevKitM board supports the following features: +------------+------------+-------------------------------------+ | Watchdog | on-chip | watchdog | +------------+------------+-------------------------------------+ +| TRNG | on-chip | entropy | ++------------+------------+-------------------------------------+ Prerequisites ------------- diff --git a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts index cc62ac7be527..cc7cbf0e2c58 100644 --- a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts +++ b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.dts @@ -109,6 +109,10 @@ status = "okay"; }; +&trng0 { + status = "okay"; +}; + &flash0 { status = "okay"; partitions { diff --git a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml index 2dc7b7888d06..29c7282ed24b 100644 --- a/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml +++ b/boards/xtensa/esp32s3_devkitm/esp32s3_devkitm.yaml @@ -11,6 +11,7 @@ supported: - spi - counter - watchdog + - entropy testing: ignore_tags: - net diff --git a/dts/xtensa/espressif/esp32s3.dtsi b/dts/xtensa/espressif/esp32s3.dtsi index faa8e029c48a..f4673df96df5 100644 --- a/dts/xtensa/espressif/esp32s3.dtsi +++ b/dts/xtensa/espressif/esp32s3.dtsi @@ -13,6 +13,7 @@ / { chosen { + zephyr,entropy = &trng0; zephyr,flash-controller = &flash; }; @@ -251,5 +252,11 @@ clocks = <&rtc ESP32_TIMG1_MODULE>; status = "disabled"; }; + + trng0: trng@6003507c { + compatible = "espressif,esp32-trng"; + reg = <0x6003507c 0x4>; + status = "disabled"; + }; }; }; From 0b457102194e0a043f1b633495b01f5e1b51243f Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 2 Nov 2022 10:42:55 +0100 Subject: [PATCH 0682/1906] drivers: adc: adc_sam: Introduce Atmel SAM ADC driver This commit adds support for Atmel SAM ADC driver with up to 16 channels. Signed-off-by: Pieter De Gendt --- drivers/adc/CMakeLists.txt | 1 + drivers/adc/Kconfig | 2 + drivers/adc/Kconfig.sam | 10 + drivers/adc/adc_sam.c | 419 ++++++++++++++++++++++++++++ drivers/adc/adc_shell.c | 2 + dts/bindings/adc/atmel,sam-adc.yaml | 61 ++++ 6 files changed, 495 insertions(+) create mode 100644 drivers/adc/Kconfig.sam create mode 100644 drivers/adc/adc_sam.c create mode 100644 dts/bindings/adc/atmel,sam-adc.yaml diff --git a/drivers/adc/CMakeLists.txt b/drivers/adc/CMakeLists.txt index 7b1c0fe96bd8..676be802d1b8 100644 --- a/drivers/adc/CMakeLists.txt +++ b/drivers/adc/CMakeLists.txt @@ -13,6 +13,7 @@ zephyr_library_sources_ifdef(CONFIG_ADC_MCUX_LPADC adc_mcux_lpadc.c) zephyr_library_sources_ifdef(CONFIG_ADC_SAM_AFEC adc_sam_afec.c) zephyr_library_sources_ifdef(CONFIG_ADC_NRFX_ADC adc_nrfx_adc.c) zephyr_library_sources_ifdef(CONFIG_ADC_NRFX_SAADC adc_nrfx_saadc.c) +zephyr_library_sources_ifdef(CONFIG_ADC_SAM adc_sam.c) zephyr_library_sources_ifdef(CONFIG_ADC_SAM0 adc_sam0.c) zephyr_library_sources_ifdef(CONFIG_ADC_STM32 adc_stm32.c) zephyr_library_sources_ifdef(CONFIG_ADC_XEC adc_mchp_xec.c) diff --git a/drivers/adc/Kconfig b/drivers/adc/Kconfig index cbcd81eda7cb..149f5172c5d0 100644 --- a/drivers/adc/Kconfig +++ b/drivers/adc/Kconfig @@ -54,6 +54,8 @@ source "drivers/adc/Kconfig.nrfx" source "drivers/adc/Kconfig.sam_afec" +source "drivers/adc/Kconfig.sam" + source "drivers/adc/Kconfig.sam0" source "drivers/adc/Kconfig.stm32" diff --git a/drivers/adc/Kconfig.sam b/drivers/adc/Kconfig.sam new file mode 100644 index 000000000000..20c1bd4249df --- /dev/null +++ b/drivers/adc/Kconfig.sam @@ -0,0 +1,10 @@ +# Copyright (c) 2022, Basalte bv +# SPDX-License-Identifier: Apache-2.0 + +config ADC_SAM + bool "Atmel SAM series ADC Driver" + default y + depends on DT_HAS_ATMEL_SAM_ADC_ENABLED + select ADC_CONFIGURABLE_INPUTS + help + Enable Atmel SAM MCU Family Analog-to-Digital Converter (ADC) driver. diff --git a/drivers/adc/adc_sam.c b/drivers/adc/adc_sam.c new file mode 100644 index 000000000000..3536a88af4d5 --- /dev/null +++ b/drivers/adc/adc_sam.c @@ -0,0 +1,419 @@ +/* + * Copyright (c) 2022, Basalte bv + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT atmel_sam_adc + +#include +#include +#include +#include + +#define ADC_CONTEXT_USES_KERNEL_TIMER +#include "adc_context.h" + +#include +#include +LOG_MODULE_REGISTER(adc_sam, CONFIG_ADC_LOG_LEVEL); + +#define SAM_ADC_NUM_CHANNELS 16 +#define SAM_ADC_TEMP_CHANNEL 15 + +struct adc_sam_config { + Adc *regs; + const struct atmel_sam_pmc_config clock_cfg; + + uint8_t prescaler; + uint8_t startup_time; + uint8_t settling_time; + uint8_t tracking_time; + + const struct pinctrl_dev_config *pcfg; + void (*config_func)(const struct device *dev); +}; + +struct adc_sam_data { + struct adc_context ctx; + const struct device *dev; + + /* Pointer to the buffer in the sequence. */ + uint16_t *buffer; + + /* Pointer to the beginning of a sample. Consider the number of + * channels in the sequence: this buffer changes by that amount + * so all the channels would get repeated. + */ + uint16_t *repeat_buffer; + + /* Number of active channels to fill buffer */ + uint8_t num_active_channels; +}; + +static uint8_t count_bits(uint32_t val) +{ + uint8_t res = 0; + + while (val) { + res += val & 1U; + val >>= 1; + } + + return res; +} + +static int adc_sam_channel_setup(const struct device *dev, + const struct adc_channel_cfg *channel_cfg) +{ + const struct adc_sam_config *const cfg = dev->config; + Adc *const adc = cfg->regs; + + uint8_t channel_id = channel_cfg->channel_id; + + if (channel_cfg->differential) { + if (channel_id != (channel_cfg->input_positive / 2U) + || channel_id != (channel_cfg->input_negative / 2U)) { + LOG_ERR("Invalid ADC differential input for channel %u", channel_id); + return -EINVAL; + } + } else { + if (channel_id != channel_cfg->input_positive) { + LOG_ERR("Invalid ADC single-ended input for channel %u", channel_id); + return -EINVAL; + } + } + + if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) { + LOG_ERR("Invalid ADC channel acquisition time"); + return -EINVAL; + } + + if (channel_cfg->reference != ADC_REF_EXTERNAL0) { + LOG_ERR("Invalid ADC channel reference (%d)", channel_cfg->reference); + return -EINVAL; + } + + /* Enable internal temperature sensor (channel 15 / single-ended) */ + if (channel_cfg->channel_id == SAM_ADC_TEMP_CHANNEL) { + adc->ADC_ACR |= ADC_ACR_TSON; + } + + /* Set channel mode, always on both inputs */ + if (channel_cfg->differential) { + adc->ADC_COR |= (ADC_COR_DIFF0 | ADC_COR_DIFF1) << (channel_id * 2U); + } else { + adc->ADC_COR &= ~((ADC_COR_DIFF0 | ADC_COR_DIFF1) << (channel_id * 2U)); + } + + /* Reset current gain */ + adc->ADC_CGR &= ~(ADC_CGR_GAIN0_Msk << (channel_id * 2U)); + + switch (channel_cfg->gain) { + case ADC_GAIN_1_2: + if (!channel_cfg->differential) { + LOG_ERR("ADC 1/2x gain only allowed for differential channel"); + return -EINVAL; + } + /* NOP */ + break; + case ADC_GAIN_1: + adc->ADC_CGR |= ADC_CGR_GAIN0(1) << (channel_id * 2U); + break; + case ADC_GAIN_2: + adc->ADC_CGR |= ADC_CGR_GAIN0(2) << (channel_id * 2U); + break; + case ADC_GAIN_4: + if (channel_cfg->differential) { + LOG_ERR("ADC 4x gain only allowed for single-ended channel"); + return -EINVAL; + } + adc->ADC_CGR |= ADC_CGR_GAIN0(3) << (channel_id * 2U); + break; + default: + LOG_ERR("Invalid ADC channel gain (%d)", channel_cfg->gain); + return -EINVAL; + } + + return 0; +} + +static void adc_sam_start_conversion(const struct device *dev) +{ + const struct adc_sam_config *const cfg = dev->config; + Adc *const adc = cfg->regs; + + adc->ADC_CR = ADC_CR_START; +} + +/** + * This is only called once at the beginning of all the conversions, + * all channels as a group. + */ +static void adc_context_start_sampling(struct adc_context *ctx) +{ + struct adc_sam_data *data = CONTAINER_OF(ctx, struct adc_sam_data, ctx); + const struct adc_sam_config *const cfg = data->dev->config; + Adc *const adc = cfg->regs; + + data->num_active_channels = count_bits(ctx->sequence.channels); + + /* Disable all */ + adc->ADC_CHDR = 0xffff; + + /* Enable selected */ + adc->ADC_CHER = ctx->sequence.channels; + + LOG_DBG("Starting conversion for %u channels", data->num_active_channels); + + adc_sam_start_conversion(data->dev); +} + +static void adc_context_update_buffer_pointer(struct adc_context *ctx, bool repeat) +{ + struct adc_sam_data *data = CONTAINER_OF(ctx, struct adc_sam_data, ctx); + + if (repeat) { + data->buffer = data->repeat_buffer; + } +} + +static int check_buffer_size(const struct adc_sequence *sequence, + uint8_t active_channels) +{ + size_t needed_buffer_size = active_channels * sizeof(uint16_t); + + if (sequence->options) { + needed_buffer_size *= (1 + sequence->options->extra_samplings); + } + + if (sequence->buffer_size < needed_buffer_size) { + LOG_ERR("Provided buffer is too small (%u/%u)", + sequence->buffer_size, needed_buffer_size); + return -ENOMEM; + } + + return 0; +} + +static int start_read(const struct device *dev, + const struct adc_sequence *sequence) +{ + struct adc_sam_data *data = dev->data; + uint32_t channels = sequence->channels; + int error; + + /* Signal an error if the channel selection is invalid (no channels or + * a non-existing one is selected). + */ + if (channels == 0U || + (channels & (~0UL << SAM_ADC_NUM_CHANNELS))) { + LOG_ERR("Invalid selection of channels"); + return -EINVAL; + } + + if (sequence->oversampling != 0U) { + LOG_ERR("Oversampling is not supported"); + return -EINVAL; + } + + if (sequence->resolution != 12U) { + LOG_ERR("ADC resolution %d is not valid", sequence->resolution); + return -EINVAL; + } + + data->num_active_channels = count_bits(channels); + + error = check_buffer_size(sequence, data->num_active_channels); + if (error) { + return error; + } + + data->buffer = sequence->buffer; + data->repeat_buffer = sequence->buffer; + + /* At this point we allow the scheduler to do other things while + * we wait for the conversions to complete. This is provided by the + * adc_context functions. However, the caller of this function is + * blocked until the results are in. + */ + adc_context_start_read(&data->ctx, sequence); + + return adc_context_wait_for_completion(&data->ctx); +} + +static int adc_sam_read(const struct device *dev, + const struct adc_sequence *sequence) +{ + struct adc_sam_data *data = dev->data; + int error; + + adc_context_lock(&data->ctx, false, NULL); + error = start_read(dev, sequence); + adc_context_release(&data->ctx, error); + + return error; +} + +static void adc_sam_isr(const struct device *dev) +{ + const struct adc_sam_config *const cfg = dev->config; + struct adc_sam_data *data = dev->data; + Adc *const adc = cfg->regs; + + uint16_t result; + + if (adc->ADC_ISR & ADC_ISR_DRDY) { + result = adc->ADC_LCDR & ADC_LCDR_LDATA_Msk; + + *data->buffer++ = result; + data->num_active_channels--; + + if (data->num_active_channels == 0) { + /* Called once all conversions have completed.*/ + adc_context_on_sampling_done(&data->ctx, dev); + } else { + adc_sam_start_conversion(dev); + } + } +} + +static int adc_sam_init(const struct device *dev) +{ + const struct adc_sam_config *const cfg = dev->config; + struct adc_sam_data *data = dev->data; + Adc *const adc = cfg->regs; + + int ret; + uint32_t frequency, conv_periods; + + /* Get peripheral clock frequency */ + ret = clock_control_get_rate(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t)&cfg->clock_cfg, + &frequency); + if (ret < 0) { + LOG_ERR("Failed to get ADC peripheral clock rate (%d)", ret); + return -ENODEV; + } + + /* Calculate ADC clock frequency */ + frequency = frequency / 2U / (cfg->prescaler + 1U); + if (frequency < 1000000U || frequency > 22000000U) { + LOG_ERR("Invalid ADC clock frequency %d (1MHz < freq < 22Mhz)", frequency); + return -EINVAL; + } + + /* The number of ADC pulses for conversion */ + conv_periods = MAX(20U, cfg->tracking_time + 6U); + + /* Calculate the sampling frequency */ + frequency /= conv_periods; + + /* Reset ADC controller */ + adc->ADC_CR = ADC_CR_SWRST; + + /* Reset Mode */ + adc->ADC_MR = 0U; + + /* Reset PDC transfer */ + adc->ADC_PTCR = ADC_PTCR_RXTDIS | ADC_PTCR_TXTDIS; + adc->ADC_RCR = 0U; + adc->ADC_RNCR = 0U; + + /* Set prescaler, timings and allow different analog settings for each channel */ + adc->ADC_MR = ADC_MR_PRESCAL(cfg->prescaler) + | ADC_MR_STARTUP(cfg->startup_time) + | ADC_MR_SETTLING(cfg->settling_time) + | ADC_MR_TRACKTIM(cfg->tracking_time) + | ADC_MR_TRANSFER(2U) /* Should be 2 to guarantee the optimal hold time. */ + | ADC_MR_ANACH_ALLOWED; + + /** + * Set bias current control + * IBCTL = 00 is the required value for a sampling frequency below 500 kHz, + * and IBCTL = 01 for a sampling frequency between 500 kHz and 1 MHz. + */ + adc->ADC_ACR = ADC_ACR_IBCTL(frequency < 500000U ? 0U : 1U); + + /* Enable ADC clock in PMC */ + ret = clock_control_on(SAM_DT_PMC_CONTROLLER, + (clock_control_subsys_t)&cfg->clock_cfg); + if (ret < 0) { + LOG_ERR("Failed to enable ADC clock (%d)", ret); + return -ENODEV; + } + + ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); + if (ret < 0) { + return ret; + } + + cfg->config_func(dev); + + /* Enable data ready interrupt */ + adc->ADC_IER = ADC_IER_DRDY; + + data->dev = dev; + + adc_context_unlock_unconditionally(&data->ctx); + + return 0; +} + +#ifdef CONFIG_ADC_ASYNC +static int adc_sam_read_async(const struct device *dev, + const struct adc_sequence *sequence, + struct k_poll_signal *async) +{ + struct adc_sam_data *data = dev->data; + int error; + + adc_context_lock(&data->ctx, true, async); + error = start_read(dev, sequence); + adc_context_release(&data->ctx, error); + + return error; +} +#endif + +static const struct adc_driver_api adc_sam_api = { + .channel_setup = adc_sam_channel_setup, + .read = adc_sam_read, +#ifdef CONFIG_ADC_ASYNC + .read_async = adc_sam_read_async, +#endif +}; + +#define ADC_SAM_DEVICE(n) \ + PINCTRL_DT_INST_DEFINE(n); \ + static void adc_sam_irq_config_##n(const struct device *dev) \ + { \ + IRQ_CONNECT(DT_INST_IRQN(n), \ + DT_INST_IRQ(n, priority), \ + adc_sam_isr, \ + DEVICE_DT_INST_GET(n), 0); \ + irq_enable(DT_INST_IRQN(n)); \ + } \ + static const struct adc_sam_config adc_sam_config_##n = { \ + .regs = (Adc *)DT_INST_REG_ADDR(n), \ + .clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \ + .prescaler = DT_INST_PROP(n, prescaler), \ + .startup_time = DT_INST_ENUM_IDX(n, startup_time), \ + .settling_time = DT_INST_ENUM_IDX(n, settling_time), \ + .tracking_time = DT_INST_ENUM_IDX(n, tracking_time), \ + .config_func = &adc_sam_irq_config_##n, \ + .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ + }; \ + static struct adc_sam_data adc_sam_data_##n = { \ + ADC_CONTEXT_INIT_TIMER(adc_sam_data_##n, ctx), \ + ADC_CONTEXT_INIT_LOCK(adc_sam_data_##n, ctx), \ + ADC_CONTEXT_INIT_SYNC(adc_sam_data_##n, ctx), \ + .dev = DEVICE_DT_INST_GET(n), \ + }; \ + DEVICE_DT_INST_DEFINE(n, adc_sam_init, NULL, \ + &adc_sam_data_##n, \ + &adc_sam_config_##n, POST_KERNEL, \ + CONFIG_ADC_INIT_PRIORITY, \ + &adc_sam_api); + +DT_INST_FOREACH_STATUS_OKAY(ADC_SAM_DEVICE) diff --git a/drivers/adc/adc_shell.c b/drivers/adc/adc_shell.c index 342420719d53..31f8c05f3782 100644 --- a/drivers/adc/adc_shell.c +++ b/drivers/adc/adc_shell.c @@ -15,6 +15,8 @@ #define DT_DRV_COMPAT atmel_sam_afec #elif DT_HAS_COMPAT_STATUS_OKAY(espressif_esp32_adc) #define DT_DRV_COMPAT espressif_esp32_adc +#elif DT_HAS_COMPAT_STATUS_OKAY(atmel_sam_adc) +#define DT_DRV_COMPAT atmel_sam_adc #elif DT_HAS_COMPAT_STATUS_OKAY(atmel_sam0_adc) #define DT_DRV_COMPAT atmel_sam0_adc #elif DT_HAS_COMPAT_STATUS_OKAY(ite_it8xxx2_adc) diff --git a/dts/bindings/adc/atmel,sam-adc.yaml b/dts/bindings/adc/atmel,sam-adc.yaml new file mode 100644 index 000000000000..6f78a6b5788f --- /dev/null +++ b/dts/bindings/adc/atmel,sam-adc.yaml @@ -0,0 +1,61 @@ +# Copyright (c) 2022, Basalte bv +# SPDX-License-Identifier: Apache-2.0 + +description: Atmel SAM family ADC + +compatible: "atmel,sam-adc" + +include: [adc-controller.yaml, pinctrl-device.yaml] + +properties: + reg: + required: true + + interrupts: + required: true + + clocks: + required: true + + prescaler: + type: int + required: true + description: CPU clock prescaler applied to get the ADC clock. + + startup-time: + type: int + required: true + description: | + ADC startup time in ADC clock cycles. + enum: [0, 8, 16, 24, 64, 80, 96, 112, 512, 576, 640, 704, 768, 832, 896, 960] + + settling-time: + type: int + required: true + description: | + ADC settling time in ADC clock cycles. When the gain, offset + or differential input parameters of the analog cell change + between two channels, the analog cell may need a specific + settling time before starting the tracking phase. + enum: [3, 5, 9, 17] + + tracking-time: + type: int + required: true + description: | + ADC tracking time in ADC clock cycles. A minimal tracking time + is necessary for the ADC to guarantee the best converted final + value between two channel selections. + enum: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] + + "#io-channel-cells": + const: 1 + + pinctrl-0: + required: true + + pinctrl-names: + required: true + +io-channel-cells: + - input From 33f7c2e7863c2d5b8136a18d6285330cc4695870 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Wed, 2 Nov 2022 10:48:46 +0100 Subject: [PATCH 0683/1906] dts: arm: atmel: Add ADC support to Atmel SAM4S Add ADC device tree entry for the Atmel SAM4S SoC. Signed-off-by: Pieter De Gendt --- dts/arm/atmel/sam4s.dtsi | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/dts/arm/atmel/sam4s.dtsi b/dts/arm/atmel/sam4s.dtsi index 63a0a2e9cbae..bbbc05e8f7fa 100644 --- a/dts/arm/atmel/sam4s.dtsi +++ b/dts/arm/atmel/sam4s.dtsi @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -213,6 +214,17 @@ status = "disabled"; }; + adc0: adc@40038000 { + compatible = "atmel,sam-adc"; + reg = <0x40038000 0x4000>; + interrupts = <29 1>; + clocks = <&pmc PMC_TYPE_PERIPHERAL 29>; + #address-cells = <1>; + #size-cells = <0>; + #io-channel-cells = <1>; + status = "disabled"; + }; + rstc: rstc@400e1400 { compatible = "atmel,sam-rstc"; reg = <0x400e1400 0x10>; From a47bdf3f02ebef5fd80a13e221a5d5b212a29452 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Thu, 3 Nov 2022 12:04:36 +0100 Subject: [PATCH 0684/1906] boards: arm: sam4s_xplained: Enable ADC support Enable ADC entry in device tree and pinctrl (PB0/PB1). Update doc/yaml files to include ADC info. Signed-off-by: Pieter De Gendt --- boards/arm/sam4s_xplained/doc/index.rst | 2 ++ .../arm/sam4s_xplained/sam4s_xplained-pinctrl.dtsi | 6 ++++++ boards/arm/sam4s_xplained/sam4s_xplained.dts | 12 ++++++++++++ boards/arm/sam4s_xplained/sam4s_xplained.yaml | 1 + 4 files changed, 21 insertions(+) diff --git a/boards/arm/sam4s_xplained/doc/index.rst b/boards/arm/sam4s_xplained/doc/index.rst index 689a13a20c7d..092079cb984c 100644 --- a/boards/arm/sam4s_xplained/doc/index.rst +++ b/boards/arm/sam4s_xplained/doc/index.rst @@ -58,6 +58,8 @@ features: +-----------+------------+-------------------------------------+ | PWM | on-chip | pwm | +-----------+------------+-------------------------------------+ +| ADC | on-chip | adc | ++-----------+------------+-------------------------------------+ Other hardware features are not currently supported by Zephyr. diff --git a/boards/arm/sam4s_xplained/sam4s_xplained-pinctrl.dtsi b/boards/arm/sam4s_xplained/sam4s_xplained-pinctrl.dtsi index 951c5e14503d..703e04ca5e12 100644 --- a/boards/arm/sam4s_xplained/sam4s_xplained-pinctrl.dtsi +++ b/boards/arm/sam4s_xplained/sam4s_xplained-pinctrl.dtsi @@ -48,6 +48,12 @@ ; }; }; + adc0_default: adc0_default { + group1 { + pinmux = , + ; + }; + }; smc_default: smc_default { group1 { pinmux = , diff --git a/boards/arm/sam4s_xplained/sam4s_xplained.dts b/boards/arm/sam4s_xplained/sam4s_xplained.dts index 571dbfb778f3..8010dd0f5686 100644 --- a/boards/arm/sam4s_xplained/sam4s_xplained.dts +++ b/boards/arm/sam4s_xplained/sam4s_xplained.dts @@ -176,6 +176,18 @@ pinctrl-names = "default"; }; +&adc0 { + status = "okay"; + + pinctrl-0 = <&adc0_default>; + pinctrl-names = "default"; + + prescaler = <9>; + startup-time = <64>; + settling-time = <3>; + tracking-time = <2>; +}; + &wdt { status = "okay"; }; diff --git a/boards/arm/sam4s_xplained/sam4s_xplained.yaml b/boards/arm/sam4s_xplained/sam4s_xplained.yaml index 9f8511d80875..3b537a2b56e2 100644 --- a/boards/arm/sam4s_xplained/sam4s_xplained.yaml +++ b/boards/arm/sam4s_xplained/sam4s_xplained.yaml @@ -7,6 +7,7 @@ toolchain: - gnuarmemb - xtools supported: + - adc - gpio - memc - pwm From 3cbac9613472c4e793566ed7aa5f79c9a08d1350 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Thu, 3 Nov 2022 12:08:59 +0100 Subject: [PATCH 0685/1906] tests: drivers: adc: adc_api: Add sam4s_xplained board Define ADC channel configuration for the SAM4S Xplained internal temperature sensor. Signed-off-by: Pieter De Gendt --- tests/drivers/adc/adc_api/src/test_adc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/drivers/adc/adc_api/src/test_adc.c b/tests/drivers/adc/adc_api/src/test_adc.c index 28e4106c86c7..d87a51f919df 100644 --- a/tests/drivers/adc/adc_api/src/test_adc.c +++ b/tests/drivers/adc/adc_api/src/test_adc.c @@ -189,6 +189,16 @@ #define ADC_ACQUISITION_TIME ADC_ACQ_TIME_DEFAULT #define ADC_1ST_CHANNEL_ID 0 +#elif defined(CONFIG_BOARD_SAM4S_XPLAINED) + +#define ADC_DEVICE_NODE DT_INST(0, atmel_sam_adc) +#define ADC_RESOLUTION 12 +#define ADC_GAIN ADC_GAIN_1 +#define ADC_REFERENCE ADC_REF_EXTERNAL0 +#define ADC_ACQUISITION_TIME ADC_ACQ_TIME_DEFAULT +#define ADC_1ST_CHANNEL_ID 15 +#define ADC_1ST_CHANNEL_INPUT 15 + #elif defined(CONFIG_SOC_FAMILY_SAM0) #include #define ADC_DEVICE_NODE DT_INST(0, atmel_sam0_adc) From 497d4899df92f0938318ad588419cc25c1e358bc Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Thu, 3 Nov 2022 12:10:25 +0100 Subject: [PATCH 0686/1906] samples: drivers: adc: Add sam4s_xplained overlay Add a board overlay for sam4s_xplained. Channel 5 (PB1) is enabled as well as the internal temperature sensor. Signed-off-by: Pieter De Gendt --- .../drivers/adc/boards/sam4s_xplained.overlay | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 samples/drivers/adc/boards/sam4s_xplained.overlay diff --git a/samples/drivers/adc/boards/sam4s_xplained.overlay b/samples/drivers/adc/boards/sam4s_xplained.overlay new file mode 100644 index 000000000000..08e39bedbb61 --- /dev/null +++ b/samples/drivers/adc/boards/sam4s_xplained.overlay @@ -0,0 +1,39 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2022, Basalte bv + */ + +#include + +/ { + zephyr,user { + /* adjust channel number according to pinmux in board.dts */ + io-channels = <&adc0 5>, <&adc0 15>; + }; +}; + +&adc0 { + #address-cells = <1>; + #size-cells = <0>; + + /* External ADC(+) */ + channel@5 { + reg = <5>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_EXTERNAL0"; + zephyr,acquisition-time = ; + zephyr,input-positive = <5>; + zephyr,resolution = <12>; + }; + + /* Internal temperature sensor */ + channel@f { + reg = <15>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_EXTERNAL0"; + zephyr,acquisition-time = ; + zephyr,input-positive = <15>; + zephyr,resolution = <12>; + }; +}; From 5ec8aa4bb08ce155c64ed9e0bbd993a79b0a6823 Mon Sep 17 00:00:00 2001 From: Hein Wessels Date: Wed, 22 Mar 2023 11:55:28 +0100 Subject: [PATCH 0687/1906] tests: drivers: adc_dma: fix sampling interval failing NXP tests In 6e21ebf the sampling interval was changed, which caused the issue #56070. This is fixed by allowing different boards to specify a sampling period. Also changed the test_task_with_interval to verify that the supplied interval was used. Signed-off-by: Hein Wessels --- tests/drivers/adc/adc_dma/src/test_adc.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/drivers/adc/adc_dma/src/test_adc.c b/tests/drivers/adc/adc_dma/src/test_adc.c index 2a65681f9d68..04bf27bd4bfd 100644 --- a/tests/drivers/adc/adc_dma/src/test_adc.c +++ b/tests/drivers/adc/adc_dma/src/test_adc.c @@ -2,6 +2,7 @@ * Copyright (c) 2018 Nordic Semiconductor ASA * Copyright (c) 2016 Intel Corporation * Copyright (c) 2020, NXP + * Copyright (c) 2023, Nobleo Technology * * SPDX-License-Identifier: Apache-2.0 */ @@ -23,6 +24,7 @@ #define ADC_1ST_CHANNEL_ID 26 #define COUNTER_NODE_NAME pit0 #define HW_TRIGGER_INTERVAL (2U) +#define SAMPLE_INTERVAL_US HW_TRIGGER_INTERVAL #elif defined(CONFIG_BOARD_FRDM_K82F) @@ -34,6 +36,7 @@ #define ADC_1ST_CHANNEL_ID 26 #define COUNTER_NODE_NAME pit0 #define HW_TRIGGER_INTERVAL (2U) +#define SAMPLE_INTERVAL_US HW_TRIGGER_INTERVAL #elif defined(CONFIG_BOARD_NUCLEO_H743ZI) @@ -64,8 +67,12 @@ #define BUFFER_MEM_REGION EMPTY #endif -/* for DMA HW trigger interval need large than HW trigger interval*/ -#define SAMPLE_INTERVAL_US (10000U) +/* The sample interval between consecutive samplings. Some drivers require + * specific values to function. + */ +#if !defined(SAMPLE_INTERVAL_US) +#define SAMPLE_INTERVAL_US 0 +#endif #define BUFFER_SIZE 24 #ifndef ALIGNMENT @@ -284,7 +291,7 @@ static int test_task_asynchronous_call(void) const struct adc_sequence_options options = { .extra_samplings = 4, /* Start consecutive samplings as fast as possible. */ - .interval_us = 0, + .interval_us = SAMPLE_INTERVAL_US, }; const struct adc_sequence sequence = { .options = &options, @@ -348,7 +355,7 @@ static int test_task_with_interval(void) int64_t milliseconds_spent; const struct adc_sequence_options options = { - .interval_us = 500UL, /*make this double to sample time*/ + .interval_us = 100 * 1000, /* 10 ms - much larger than expected sampling time */ .callback = sample_with_interval_callback, .extra_samplings = 1, }; @@ -372,7 +379,7 @@ static int test_task_with_interval(void) time_stamp = k_uptime_get(); ret = adc_read(adc_dev, &sequence); milliseconds_spent = k_uptime_delta(&time_stamp); - printk("now spend = %lldms\n", milliseconds_spent); + zassert_true(milliseconds_spent >= (options.interval_us / 1000UL)); zassert_equal(ret, 0, "adc_read() failed with code %d", ret); } check_samples2(1 + options.extra_samplings); @@ -438,7 +445,6 @@ static int test_task_repeated_samplings(void) */ .extra_samplings = 2, /* Start consecutive samplings as fast as possible. */ - /* but the interval shall be larger than the HW trigger*/ .interval_us = SAMPLE_INTERVAL_US, }; const struct adc_sequence sequence = { From 317bd5af3015fcb858feb3f5a38fce35b69e3424 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 22 Mar 2023 10:01:49 +0100 Subject: [PATCH 0688/1906] Bluetooth: Host: Missing unref for PAST sync_info When we supply the conn pointer of the remote device that provides the PAST information, we do a lookup on the conn_handle using bt_conn_lookup_handle which takes a reference count. This count is never dereferenced again. This commit adds calls to bt_conn_unref to ensure that we do not keep the reference count after the function returns. Signed-off-by: Emil Gydesen --- subsys/bluetooth/host/scan.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/subsys/bluetooth/host/scan.c b/subsys/bluetooth/host/scan.c index 4eb11d4307a3..e074895a6343 100644 --- a/subsys/bluetooth/host/scan.c +++ b/subsys/bluetooth/host/scan.c @@ -1064,6 +1064,7 @@ void bt_hci_le_past_received(struct net_buf *buf) if (!per_adv_sync) { LOG_WRN("Could not allocate new PA sync from PAST"); per_adv_sync_terminate(sys_le16_to_cpu(evt->sync_handle)); + bt_conn_unref(sync_info.conn); return; } @@ -1094,6 +1095,8 @@ void bt_hci_le_past_received(struct net_buf *buf) listener->synced(per_adv_sync, &sync_info); } } + + bt_conn_unref(sync_info.conn); } #endif /* CONFIG_BT_CONN */ From 7ec4a6a19e2aa775e5766c8420ff6e740589c7f9 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 22 Mar 2023 10:09:36 +0100 Subject: [PATCH 0689/1906] Bluetooth: host: df: Add missing bt_conn_unref in error cases Added missing bt_conn_unref where bt_conn_lookup_handle is called, but where the function returns without providing the conn pointer to the caller. Signed-off-by: Emil Gydesen --- subsys/bluetooth/host/direction.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subsys/bluetooth/host/direction.c b/subsys/bluetooth/host/direction.c index c5cc3817bb74..76c4b190b24e 100644 --- a/subsys/bluetooth/host/direction.c +++ b/subsys/bluetooth/host/direction.c @@ -689,11 +689,13 @@ int hci_df_prepare_connection_iq_report(struct net_buf *buf, if (!atomic_test_bit(conn->flags, BT_CONN_CTE_RX_ENABLED)) { LOG_ERR("Received conn CTE report when CTE receive disabled"); + bt_conn_unref(conn); return -EINVAL; } if (!(conn->cte_types & BIT(evt->cte_type))) { LOG_DBG("CTE filtered out by cte_type: %u", evt->cte_type); + bt_conn_unref(conn); return -EINVAL; } @@ -739,11 +741,13 @@ int hci_df_vs_prepare_connection_iq_report(struct net_buf *buf, if (!atomic_test_bit(conn->flags, BT_CONN_CTE_RX_ENABLED)) { LOG_ERR("Received conn CTE report when CTE receive disabled"); + bt_conn_unref(conn); return -EINVAL; } if (!(conn->cte_types & BIT(evt->cte_type))) { LOG_DBG("CTE filtered out by cte_type: %u", evt->cte_type); + bt_conn_unref(conn); return -EINVAL; } @@ -862,6 +866,7 @@ int hci_df_prepare_conn_cte_req_failed(struct net_buf *buf, if (!atomic_test_bit(conn->flags, BT_CONN_CTE_REQ_ENABLED)) { LOG_ERR("Received conn CTE request notification when CTE REQ disabled"); + bt_conn_unref(conn); return -EINVAL; } From 6fc8ca7863700e46d30e6ddc0e7f07aedcbfa908 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 22 Mar 2023 10:16:02 +0100 Subject: [PATCH 0690/1906] Bluetooth: iso: Add misisng bt_conn_unref in error cases The ISO hci_le_cis_req event handler was missing calls to bt_conn_unref and bt_iso_cleanup_acl to properly clearn up the reference counters. Signed-off-by: Emil Gydesen --- subsys/bluetooth/host/iso.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subsys/bluetooth/host/iso.c b/subsys/bluetooth/host/iso.c index 8a72ae9e8706..12d25e26c733 100644 --- a/subsys/bluetooth/host/iso.c +++ b/subsys/bluetooth/host/iso.c @@ -985,6 +985,7 @@ void hci_le_cis_established(struct net_buf *buf) CHECKIF(iso->type != BT_CONN_TYPE_ISO) { LOG_DBG("Invalid connection type %u", iso->type); + bt_conn_unref(iso); return; } @@ -1230,6 +1231,8 @@ void hci_le_cis_req(struct net_buf *buf) if (err != 0) { LOG_ERR("Failed to reject CIS"); } + + bt_conn_unref(acl); return; } @@ -1253,6 +1256,7 @@ void hci_le_cis_req(struct net_buf *buf) err = iso_accept(acl, iso); if (err) { LOG_DBG("App rejected ISO %d", err); + bt_iso_cleanup_acl(iso); bt_conn_unref(iso); hci_le_reject_cis(cis_handle, BT_HCI_ERR_INSUFFICIENT_RESOURCES); @@ -1265,6 +1269,7 @@ void hci_le_cis_req(struct net_buf *buf) err = hci_le_accept_cis(cis_handle); if (err) { + bt_iso_cleanup_acl(iso); bt_conn_unref(iso); hci_le_reject_cis(cis_handle, BT_HCI_ERR_INSUFFICIENT_RESOURCES); From e587047dc6b77c28ea399e272c41beb2cd52f142 Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Fri, 27 Jan 2023 17:09:55 -0600 Subject: [PATCH 0691/1906] drivers: adc: rewrite mcux LPADC driver Rewrite MCUX LPADC driver, to better utilize hardware. the following changes have been applied: - channel numbers now correspond to hardware channel command slots, use "input_positive" and "input_negative" fields along with channel definitions in dt-bindings/adc/mcux-lpadc.h to select a channel - the number of channel command slots available is configurable via CONFIG_LPADC_CHANNEL_COUNT - Side A and side B channels are now supported - differential channel mode is now supported - ADC channels now are sampled via hardware, without additional software triggering Signed-off-by: Daniel DeGrasse --- drivers/adc/Kconfig.mcux | 12 ++ drivers/adc/adc_mcux_lpadc.c | 214 +++++++++++++++----- include/zephyr/dt-bindings/adc/mcux-lpadc.h | 30 +++ 3 files changed, 203 insertions(+), 53 deletions(-) create mode 100644 include/zephyr/dt-bindings/adc/mcux-lpadc.h diff --git a/drivers/adc/Kconfig.mcux b/drivers/adc/Kconfig.mcux index f3828e9620b1..c53ffeee468c 100644 --- a/drivers/adc/Kconfig.mcux +++ b/drivers/adc/Kconfig.mcux @@ -29,6 +29,7 @@ config ADC_MCUX_12B1MSPS_SAR config ADC_MCUX_LPADC bool "MCUX LPADC driver" default y + select ADC_CONFIGURABLE_INPUTS depends on DT_HAS_NXP_LPC_LPADC_ENABLED help Enable the MCUX LPADC driver. @@ -97,4 +98,15 @@ config LPADC_DO_OFFSET_CALIBRATION help Do offset calibration +config LPADC_CHANNEL_COUNT + int "LPADC channel count" + default 15 + range 1 15 + help + Amount of hardware command channels to use, reduce to save RAM. + The user can reduce this value if their application uses fewer than + 15 ADC channels. This value corresponds to how many of the CMD + registers can be configured within the ADC. + + endif # ADC_MCUX_LPADC diff --git a/drivers/adc/adc_mcux_lpadc.c b/drivers/adc/adc_mcux_lpadc.c index ae49d8f9e02b..3bb2b131f81a 100644 --- a/drivers/adc/adc_mcux_lpadc.c +++ b/drivers/adc/adc_mcux_lpadc.c @@ -65,21 +65,24 @@ struct mcux_lpadc_data { uint16_t *buffer; uint16_t *repeat_buffer; uint32_t channels; - uint8_t channel_id; - lpadc_hardware_average_mode_t average; -#if defined(FSL_FEATURE_LPADC_HAS_CMDL_MODE) \ - && FSL_FEATURE_LPADC_HAS_CMDL_MODE - lpadc_conversion_resolution_mode_t resolution; -#endif /* FSL_FEATURE_LPADC_HAS_CMDL_MODE */ + lpadc_conv_command_config_t cmd_config[CONFIG_LPADC_CHANNEL_COUNT]; }; + + static int mcux_lpadc_channel_setup(const struct device *dev, const struct adc_channel_cfg *channel_cfg) { - uint8_t channel_id = channel_cfg->channel_id; - if (channel_id > 31) { - LOG_ERR("Channel %d is not valid", channel_id); + + struct mcux_lpadc_data *data = dev->data; + lpadc_conv_command_config_t *cmd; + uint8_t channel_side; + uint8_t channel_num; + + /* User may configure maximum number of active channels */ + if (channel_cfg->channel_id >= CONFIG_LPADC_CHANNEL_COUNT) { + LOG_ERR("Channel %d is not valid", channel_cfg->channel_id); return -EINVAL; } @@ -88,37 +91,94 @@ static int mcux_lpadc_channel_setup(const struct device *dev, return -EINVAL; } + /* Select ADC CMD register to configure based off channel ID */ + cmd = &data->cmd_config[channel_cfg->channel_id]; + + /* If bit 5 of input_positive is set, then channel side B is used */ + channel_side = 0x20 & channel_cfg->input_positive; + /* Channel number is selected by lower 4 bits of input_positive */ + channel_num = ADC_CMDL_ADCH(channel_cfg->input_positive); + + LOG_DBG("Channel num: %u, channel side: %c", channel_num, + channel_side == 0 ? 'A' : 'B'); + + LPADC_GetDefaultConvCommandConfig(cmd); + if (channel_cfg->differential) { - LOG_ERR("Differential channels are not supported"); + /* Channel pairs must match in differential mode */ + if ((ADC_CMDL_ADCH(channel_cfg->input_positive)) != + (ADC_CMDL_ADCH(channel_cfg->input_negative))) { + return -ENOTSUP; + } + +#if defined(FSL_FEATURE_LPADC_HAS_CMDL_DIFF) && FSL_FEATURE_LPADC_HAS_CMDL_DIFF + /* Check to see which channel is the positive input */ + if (channel_cfg->input_positive & 0x20) { + /* Channel B is positive side */ + cmd->sampleChannelMode = + kLPADC_SampleChannelDiffBothSideBA; + } else { + /* Channel A is positive side */ + cmd->sampleChannelMode = + kLPADC_SampleChannelDiffBothSideAB; + } +#else + cmd->sampleChannelMode = kLPADC_SampleChannelDiffBothSide; +#endif + } else if (channel_side != 0) { + cmd->sampleChannelMode = kLPADC_SampleChannelSingleEndSideB; + } else { + /* Default value for sampleChannelMode is SideA */ + } +#if defined(FSL_FEATURE_LPADC_HAS_CMDL_CSCALE) && FSL_FEATURE_LPADC_HAS_CMDL_CSCALE + /* + * The true scaling factor used by the LPADC is 30/64, instead of + * 1/2. Select 1/2 as this is the closest scaling factor available + * in Zephyr. + */ + if (channel_cfg->gain == ADC_GAIN_1_2) { + LOG_INF("Channel gain of 30/64 selected"); + cmd->sampleScaleMode = kLPADC_SamplePartScale; + } else if (channel_cfg->gain == ADC_GAIN_1) { + cmd->sampleScaleMode = kLPADC_SampleFullScale; + } else { + LOG_ERR("Invalid channel gain"); return -EINVAL; } - +#else if (channel_cfg->gain != ADC_GAIN_1) { LOG_ERR("Invalid channel gain"); return -EINVAL; } +#endif if (channel_cfg->reference != ADC_REF_EXTERNAL0) { LOG_ERR("Invalid channel reference"); return -EINVAL; } + cmd->channelNumber = channel_num; return 0; } static int mcux_lpadc_start_read(const struct device *dev, const struct adc_sequence *sequence) { + const struct mcux_lpadc_config *config = dev->config; struct mcux_lpadc_data *data = dev->data; + lpadc_hardware_average_mode_t hardware_average_mode; + uint8_t channel, last_enabled; #if defined(FSL_FEATURE_LPADC_HAS_CMDL_MODE) \ && FSL_FEATURE_LPADC_HAS_CMDL_MODE + lpadc_conversion_resolution_mode_t resolution_mode; + switch (sequence->resolution) { case 12: case 13: - data->resolution = kLPADC_ConversionResolutionStandard; + resolution_mode = kLPADC_ConversionResolutionStandard; break; case 16: - data->resolution = kLPADC_ConversionResolutionHigh; + resolution_mode = kLPADC_ConversionResolutionHigh; break; default: LOG_ERR("Unsupported resolution %d", sequence->resolution); @@ -135,28 +195,28 @@ static int mcux_lpadc_start_read(const struct device *dev, switch (sequence->oversampling) { case 0: - data->average = kLPADC_HardwareAverageCount1; + hardware_average_mode = kLPADC_HardwareAverageCount1; break; case 1: - data->average = kLPADC_HardwareAverageCount2; + hardware_average_mode = kLPADC_HardwareAverageCount2; break; case 2: - data->average = kLPADC_HardwareAverageCount4; + hardware_average_mode = kLPADC_HardwareAverageCount4; break; case 3: - data->average = kLPADC_HardwareAverageCount8; + hardware_average_mode = kLPADC_HardwareAverageCount8; break; case 4: - data->average = kLPADC_HardwareAverageCount16; + hardware_average_mode = kLPADC_HardwareAverageCount16; break; case 5: - data->average = kLPADC_HardwareAverageCount32; + hardware_average_mode = kLPADC_HardwareAverageCount32; break; case 6: - data->average = kLPADC_HardwareAverageCount64; + hardware_average_mode = kLPADC_HardwareAverageCount64; break; case 7: - data->average = kLPADC_HardwareAverageCount128; + hardware_average_mode = kLPADC_HardwareAverageCount128; break; default: LOG_ERR("Unsupported oversampling value %d", @@ -164,6 +224,41 @@ static int mcux_lpadc_start_read(const struct device *dev, return -ENOTSUP; } + /* + * Now, look at the selected channels to determine which ADC channels + * we need to configure, and set those channels up. + * + * Since this ADC supports chaining channels in hardware, we will + * start with the highest channel ID and work downwards, chaining + * channels as we go. + */ + channel = CONFIG_LPADC_CHANNEL_COUNT; + last_enabled = 0; + while (channel-- > 0) { + if (sequence->channels & BIT(channel)) { + /* Setup this channel command */ +#if defined(FSL_FEATURE_LPADC_HAS_CMDL_MODE) && FSL_FEATURE_LPADC_HAS_CMDL_MODE + data->cmd_config[channel].conversionResolutionMode = + resolution_mode; +#endif + data->cmd_config[channel].hardwareAverageMode = + hardware_average_mode; + if (last_enabled) { + /* Chain channel */ + data->cmd_config[channel].chainedNextCommandNumber = + last_enabled + 1; + LOG_DBG("Chaining channel %u to %u", + channel, last_enabled); + } else { + /* End of chain */ + data->cmd_config[channel].chainedNextCommandNumber = 0; + last_enabled = channel; + } + LPADC_SetConvCommandConfig(config->base, + channel + 1, &data->cmd_config[channel]); + } + }; + data->buffer = sequence->buffer; adc_context_start_read(&data->ctx, sequence); @@ -196,31 +291,17 @@ static void mcux_lpadc_start_channel(const struct device *dev) { const struct mcux_lpadc_config *config = dev->config; struct mcux_lpadc_data *data = dev->data; + lpadc_conv_trigger_config_t trigger_config; + uint8_t first_channel; - data->channel_id = find_lsb_set(data->channels) - 1; - - LOG_DBG("Starting channel %d", data->channel_id); + first_channel = find_lsb_set(data->channels) - 1; - lpadc_conv_command_config_t cmd_config; - - LPADC_GetDefaultConvCommandConfig(&cmd_config); - cmd_config.channelNumber = data->channel_id % CHANNELS_PER_SIDE; - /* Select channel side based on next bit */ - cmd_config.sampleChannelMode = (data->channel_id < CHANNELS_PER_SIDE) ? - kLPADC_SampleChannelSingleEndSideA : - kLPADC_SampleChannelSingleEndSideB; -#if defined(FSL_FEATURE_LPADC_HAS_CMDL_MODE) \ - && FSL_FEATURE_LPADC_HAS_CMDL_MODE - cmd_config.conversionResolutionMode = data->resolution; -#endif /* FSL_FEATURE_LPADC_HAS_CMDL_MODE */ - cmd_config.hardwareAverageMode = data->average; - LPADC_SetConvCommandConfig(config->base, 1, &cmd_config); - - lpadc_conv_trigger_config_t trigger_config; + LOG_DBG("Starting channel %d, input %d", first_channel, + data->cmd_config[first_channel].channelNumber); LPADC_GetDefaultConvTriggerConfig(&trigger_config); - trigger_config.targetCommandId = 1; + trigger_config.targetCommandId = first_channel + 1; /* configures trigger0. */ LPADC_SetConvTriggerConfig(config->base, 0, &trigger_config); @@ -258,6 +339,9 @@ static void mcux_lpadc_isr(const struct device *dev) ADC_Type *base = config->base; lpadc_conv_result_t conv_result; + lpadc_sample_channel_mode_t conv_mode; + int16_t result; + uint16_t channel; #if (defined(FSL_FEATURE_LPADC_FIFO_COUNT) \ && (FSL_FEATURE_LPADC_FIFO_COUNT == 2U)) @@ -266,21 +350,45 @@ static void mcux_lpadc_isr(const struct device *dev) LPADC_GetConvResult(base, &conv_result); #endif /* FSL_FEATURE_LPADC_FIFO_COUNT */ - /* For 12-bit resolution the MSB will be 0. - So a 3 bit shift is also needed. */ - uint16_t result = data->ctx.sequence.resolution < 16 ? - conv_result.convValue >> 3 : conv_result.convValue; - - LOG_DBG("Finished channel %d. Result is 0x%04x", - data->channel_id, result); + channel = conv_result.commandIdSource - 1; + LOG_DBG("Finished channel %d. Raw result is 0x%04x", + channel, conv_result.convValue); + /* + * For 12 or 13 bit resolution the the LSBs will be 0, so a bit shift + * is needed. For differential modes, the ADC conversion to + * millivolts expects to use a shift one less than the resolution. + * + * For 16 bit modes, the adc value can be left untouched. ADC + * API should treat the value as signed if the channel is + * in differential mode + */ + conv_mode = data->cmd_config[channel].sampleChannelMode; + if (data->ctx.sequence.resolution < 15) { + result = ((conv_result.convValue >> 3) & 0xFFF); +#if defined(FSL_FEATURE_LPADC_HAS_CMDL_DIFF) && FSL_FEATURE_LPADC_HAS_CMDL_DIFF + if (conv_mode == kLPADC_SampleChannelDiffBothSideAB || + conv_mode == kLPADC_SampleChannelDiffBothSideBA) { +#else + if (conv_mode == kLPADC_SampleChannelDiffBothSide) { +#endif + if ((conv_result.convValue & 0x8000)) { + /* 13 bit mode, MSB is sign bit. (2's complement) */ + result -= 0x1000; + } + } + *data->buffer++ = result; + } else { + *data->buffer++ = conv_result.convValue; + } - *data->buffer++ = result; - data->channels &= ~BIT(data->channel_id); + data->channels &= ~BIT(channel); - if (data->channels) { - mcux_lpadc_start_channel(dev); - } else { + /* + * Hardware will automatically continue sampling, so no need + * to issue new trigger + */ + if (data->channels == 0) { adc_context_on_sampling_done(&data->ctx, dev); } } diff --git a/include/zephyr/dt-bindings/adc/mcux-lpadc.h b/include/zephyr/dt-bindings/adc/mcux-lpadc.h new file mode 100644 index 000000000000..176e4aebe409 --- /dev/null +++ b/include/zephyr/dt-bindings/adc/mcux-lpadc.h @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2023 NXP + */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_MCUX_LPADC_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_MCUX_LPADC_H_ + +#define MCUX_LPADC_CH0A (0x0) +#define MCUX_LPADC_CH0B (0x20) +#define MCUX_LPADC_CH1A (0x1) +#define MCUX_LPADC_CH1B (0x21) +#define MCUX_LPADC_CH2A (0x2) +#define MCUX_LPADC_CH2B (0x22) +#define MCUX_LPADC_CH3A (0x3) +#define MCUX_LPADC_CH3B (0x23) +#define MCUX_LPADC_CH4A (0x4) +#define MCUX_LPADC_CH4B (0x24) +#define MCUX_LPADC_CH5A (0x5) +#define MCUX_LPADC_CH5B (0x25) +#define MCUX_LPADC_CH6A (0x6) +#define MCUX_LPADC_CH6B (0x26) +#define MCUX_LPADC_CH7A (0x7) +#define MCUX_LPADC_CH7B (0x27) +#define MCUX_LPADC_CH8A (0x8) +#define MCUX_LPADC_CH8B (0x28) + + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_MCUX_LPADC_H_ */ From 6240fb5f6601113a2bea0ba2d7e10982dce64e61 Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Fri, 3 Mar 2023 17:01:55 -0600 Subject: [PATCH 0692/1906] tests: drivers: adc: update for LPADC API change Update test/drivers/adc/adc_api to support the new channel configuration method used by the LPADC driver. Signed-off-by: Daniel DeGrasse --- tests/drivers/adc/adc_api/src/test_adc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/drivers/adc/adc_api/src/test_adc.c b/tests/drivers/adc/adc_api/src/test_adc.c index d87a51f919df..d6f383b1400d 100644 --- a/tests/drivers/adc/adc_api/src/test_adc.c +++ b/tests/drivers/adc/adc_api/src/test_adc.c @@ -333,6 +333,7 @@ defined(CONFIG_BOARD_MIMXRT1170_EVK_CM7) || \ defined(CONFIG_BOARD_MIMXRT685_EVK) || \ defined(CONFIG_BOARD_MIMXRT595_EVK) +#include #define ADC_DEVICE_NODE DT_INST(0, nxp_lpc_lpadc) #define ADC_RESOLUTION 12 #define ADC_GAIN ADC_GAIN_1 @@ -340,6 +341,8 @@ #define ADC_ACQUISITION_TIME ADC_ACQ_TIME_DEFAULT #define ADC_1ST_CHANNEL_ID 0 #define ADC_2ND_CHANNEL_ID 1 +#define ADC_1ST_CHANNEL_INPUT MCUX_LPADC_CH0A +#define ADC_2ND_CHANNEL_INPUT MCUX_LPADC_CH1A #elif defined(CONFIG_BOARD_NPCX7M6FB_EVB) || \ defined(CONFIG_BOARD_NPCX9M6F_EVB) From 4629b626c84cae2e2581aebb023d8e8cc88cdca1 Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Fri, 3 Mar 2023 17:42:31 -0600 Subject: [PATCH 0693/1906] samples: drivers: adc: update board overlays for LPADC API change Update board overlays for boards with LPADC IP present on their SOCs, to use new LPADC API for channel numbering. For the RT595 and LPCxpresso55S69 EVKs, additional channels are enabled to demonstrate the resolution and differential channel features of the LPADC. Signed-off-by: Daniel DeGrasse --- .../lpcxpresso55s69-pinctrl.dtsi | 5 ++- .../mimxrt595_evk_cm33-pinctrl.dtsi | 1 + .../adc/boards/lpcxpresso55s69_cpu0.overlay | 43 +++++++++++++++---- .../adc/boards/mimxrt1160_evk_cm7.overlay | 4 +- .../adc/boards/mimxrt1170_evk_cm7.overlay | 3 ++ .../adc/boards/mimxrt595_evk_cm33.overlay | 20 ++++++--- .../adc/boards/mimxrt685_evk_cm33.overlay | 10 +++-- 7 files changed, 66 insertions(+), 20 deletions(-) diff --git a/boards/arm/lpcxpresso55s69/lpcxpresso55s69-pinctrl.dtsi b/boards/arm/lpcxpresso55s69/lpcxpresso55s69-pinctrl.dtsi index 1eea01b5e248..bb8c82053c8e 100644 --- a/boards/arm/lpcxpresso55s69/lpcxpresso55s69-pinctrl.dtsi +++ b/boards/arm/lpcxpresso55s69/lpcxpresso55s69-pinctrl.dtsi @@ -67,8 +67,9 @@ pinmux_lpadc0: pinmux_lpadc0 { group0 { pinmux = , - , - ; + , + , + ; slew-rate = "standard"; nxp,analog-mode; }; diff --git a/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33-pinctrl.dtsi b/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33-pinctrl.dtsi index 4bbab86e6de3..4e742cab5d86 100644 --- a/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33-pinctrl.dtsi +++ b/boards/arm/mimxrt595_evk/mimxrt595_evk_cm33-pinctrl.dtsi @@ -143,6 +143,7 @@ pinmux_lpadc0: pinmux_lpadc0 { group0 { pinmux = , + , ; slew-rate = "normal"; drive-strength = "normal"; diff --git a/samples/drivers/adc/boards/lpcxpresso55s69_cpu0.overlay b/samples/drivers/adc/boards/lpcxpresso55s69_cpu0.overlay index d3191ca18833..30ced141a500 100644 --- a/samples/drivers/adc/boards/lpcxpresso55s69_cpu0.overlay +++ b/samples/drivers/adc/boards/lpcxpresso55s69_cpu0.overlay @@ -1,15 +1,15 @@ /* * SPDX-License-Identifier: Apache-2.0 * - * Copyright 2022 NXP + * Copyright 2022-2023 NXP */ #include +#include / { zephyr,user { - /* adjust channel number according to pinmux in board.dts */ - io-channels = <&adc0 0>, <&adc0 8>; + io-channels = <&adc0 0 &adc0 1 &adc0 2>; }; }; @@ -21,29 +21,56 @@ * To use this sample: * - Connect VREFN_TARGET to GND, and VREFP_TARGET to 3v3 * (Resistors J8 and J9, should be populated by default) + * LPADC0 CH0A and CH0B are set up in differential mode * - Connect LPADC0 CH0A signal to voltage between 0~3.3V (P19 pin 4) * - Connect LPADC0 CH0B signal to voltage between 0~3.3V (P19 pin 2) + * LPADC0 CH4A is set up in single ended mode + * - Connect LPADC0 CH4A signal to voltage between 0~3.3V (P17 pin 19) + * LPADC0 CH4B is set up in single ended mode + * - Connect LPADC0 CH4B signal to voltage between 0~3.3V (P18 pin 1) */ + /* + * Channel 0 is used for differential mode, with 13 bit resolution + * CH0A (plus side) is routed to P19 pin 4 + * CH0B (minus side) is routed to P19 pin 2 + */ channel@0 { reg = <0>; zephyr,gain = "ADC_GAIN_1"; zephyr,reference = "ADC_REF_EXTERNAL0"; zephyr,vref-mv = <3300>; zephyr,acquisition-time = ; - zephyr,resolution = <12>; + zephyr,resolution = <13>; + zephyr,input-positive = ; + zephyr,input-negative = ; + }; + + /* + * Channel 1 is used in single ended mode, with 16 bit resolution + * CH4A is routed to P17 pin 19 + */ + channel@1 { + reg = <1>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_EXTERNAL0"; + zephyr,vref-mv = <3300>; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + zephyr,input-positive = ; }; /* - * Channel 8 corresponds to ADC CH0B. - * Channel 9 corresponds to CH1B, etc + * Channel 2 is used in single ended mode, with 12 bit resolution + * CH4B is routed to P18 pin 1 */ - channel@8 { - reg = <8>; + channel@2 { + reg = <2>; zephyr,gain = "ADC_GAIN_1"; zephyr,reference = "ADC_REF_EXTERNAL0"; zephyr,vref-mv = <3300>; zephyr,acquisition-time = ; zephyr,resolution = <12>; + zephyr,input-positive = ; }; }; diff --git a/samples/drivers/adc/boards/mimxrt1160_evk_cm7.overlay b/samples/drivers/adc/boards/mimxrt1160_evk_cm7.overlay index e9c33956ff1e..2046beca36a8 100644 --- a/samples/drivers/adc/boards/mimxrt1160_evk_cm7.overlay +++ b/samples/drivers/adc/boards/mimxrt1160_evk_cm7.overlay @@ -1,10 +1,11 @@ /* * SPDX-License-Identifier: Apache-2.0 * - * Copyright (c) 2021, NXP + * Copyright 2021,2023 NXP */ #include +#include / { zephyr,user { @@ -29,5 +30,6 @@ zephyr,vref-mv = <1800>; zephyr,acquisition-time = ; zephyr,resolution = <12>; + zephyr,input-positive = ; }; }; diff --git a/samples/drivers/adc/boards/mimxrt1170_evk_cm7.overlay b/samples/drivers/adc/boards/mimxrt1170_evk_cm7.overlay index d2d77de5a698..a5f55a8f0407 100644 --- a/samples/drivers/adc/boards/mimxrt1170_evk_cm7.overlay +++ b/samples/drivers/adc/boards/mimxrt1170_evk_cm7.overlay @@ -2,9 +2,11 @@ * SPDX-License-Identifier: Apache-2.0 * * Copyright (c) 2020 Linaro Limited + * Copyright 2023 NXP */ #include +#include / { zephyr,user { @@ -29,5 +31,6 @@ zephyr,vref-mv = <1800>; zephyr,acquisition-time = ; zephyr,resolution = <12>; + zephyr,input-positive = ; }; }; diff --git a/samples/drivers/adc/boards/mimxrt595_evk_cm33.overlay b/samples/drivers/adc/boards/mimxrt595_evk_cm33.overlay index 2ef2bbb083b3..dde9813536e8 100644 --- a/samples/drivers/adc/boards/mimxrt595_evk_cm33.overlay +++ b/samples/drivers/adc/boards/mimxrt595_evk_cm33.overlay @@ -2,14 +2,16 @@ * SPDX-License-Identifier: Apache-2.0 * * Copyright (c) 2020 Linaro Limited + * Copyright 2023 NXP */ #include +#include / { zephyr,user { /* adjust channel number according to pinmux in board.dts */ - io-channels = <&lpadc0 0>, <&lpadc0 2>; + io-channels = <&lpadc0 0>, <&lpadc0 1>; }; }; @@ -19,8 +21,11 @@ /* * To use this sample: - * - Connect LPADC0 CH0 signal to voltage between 0~1.8V (J30 pin 1) - * - Connect LPADC0 CH2 signal to voltage between 0~1.8V (J30 pin 3) + * LPADC0 CH0A and CH0B are set up in differential mode (B-A) + * - Connect LPADC0 CH0A signal to voltage between 0~1.8V (J30 pin 1) + * - Connect LPADC0 CH0B signal to voltage between 0~1.8V (J30 pin 2) + * LPADC0 CH2A is set up in single ended mode + * - Connect LPADC0 CH2A signal to voltage between 0~1.8V (J30 pin 3) */ channel@0 { @@ -29,15 +34,18 @@ zephyr,reference = "ADC_REF_EXTERNAL0"; zephyr,vref-mv = <1800>; zephyr,acquisition-time = ; - zephyr,resolution = <12>; + zephyr,resolution = <13>; + zephyr,input-positive = ; + zephyr,input-negative = ; }; - channel@2 { - reg = <2>; + channel@1 { + reg = <1>; zephyr,gain = "ADC_GAIN_1"; zephyr,reference = "ADC_REF_EXTERNAL0"; zephyr,vref-mv = <1800>; zephyr,acquisition-time = ; zephyr,resolution = <12>; + zephyr,input-positive = ; }; }; diff --git a/samples/drivers/adc/boards/mimxrt685_evk_cm33.overlay b/samples/drivers/adc/boards/mimxrt685_evk_cm33.overlay index 1802e878e99f..3e2e5693e57a 100644 --- a/samples/drivers/adc/boards/mimxrt685_evk_cm33.overlay +++ b/samples/drivers/adc/boards/mimxrt685_evk_cm33.overlay @@ -2,14 +2,16 @@ * SPDX-License-Identifier: Apache-2.0 * * Copyright (c) 2020 Linaro Limited + * Copyright 2023 NXP */ #include +#include / { zephyr,user { /* adjust channel number according to pinmux in board.dts */ - io-channels = <&lpadc0 0>, <&lpadc0 8>; + io-channels = <&lpadc0 0>, <&lpadc0 1>; }; }; @@ -31,14 +33,16 @@ zephyr,vref-mv = <1800>; zephyr,acquisition-time = ; zephyr,resolution = <12>; + zephyr,input-positive = ; }; - channel@8 { - reg = <8>; + channel@1 { + reg = <1>; zephyr,gain = "ADC_GAIN_1"; zephyr,reference = "ADC_REF_EXTERNAL0"; zephyr,vref-mv = <1800>; zephyr,acquisition-time = ; zephyr,resolution = <12>; + zephyr,input-positive = ; }; }; From 6c0b68672dd87a6f18bec69a2568d779b89502f9 Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Fri, 3 Mar 2023 17:44:15 -0600 Subject: [PATCH 0694/1906] samples: drivers: adc: treat samples as signed when using diff mode Treat sample data as signed when using differential mode for ADC sampling, so that negative differential samples will be converted correctly. Signed-off-by: Daniel DeGrasse --- samples/drivers/adc/src/main.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/samples/drivers/adc/src/main.c b/samples/drivers/adc/src/main.c index a24790f85b4a..120506897943 100644 --- a/samples/drivers/adc/src/main.c +++ b/samples/drivers/adc/src/main.c @@ -68,14 +68,22 @@ void main(void) if (err < 0) { printk("Could not read (%d)\n", err); continue; - } else { - printk("%"PRIu16, buf); } - /* conversion to mV may not be supported, skip if not */ - val_mv = buf; + /* + * If using differential mode, the 16 bit value + * in the ADC sample buffer should be a signed 2's + * complement value. + */ + if (adc_channels[i].channel_cfg.differential) { + val_mv = (int32_t)((int16_t)buf); + } else { + val_mv = (int32_t)buf; + } + printk("%"PRId32, val_mv); err = adc_raw_to_millivolts_dt(&adc_channels[i], &val_mv); + /* conversion to mV may not be supported, skip if not */ if (err < 0) { printk(" (value in mV not available)\n"); } else { From 69ef610c03fe1b1515f141ca0f871f8170d0854c Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Fri, 3 Mar 2023 17:52:34 -0600 Subject: [PATCH 0695/1906] doc: release/3.4: add note about LPADC API change Add note highlighting change to LPADC channel selection setup, so that users will be aware they need to change their devicetree configuration Signed-off-by: Daniel DeGrasse --- doc/releases/release-notes-3.4.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/releases/release-notes-3.4.rst b/doc/releases/release-notes-3.4.rst index 02229e81e07e..a2ece3076916 100644 --- a/doc/releases/release-notes-3.4.rst +++ b/doc/releases/release-notes-3.4.rst @@ -243,6 +243,11 @@ Drivers and Sensors * ADC + * MCUX LPADC driver now uses the channel parameter to select a software channel + configuration buffer. Use ``zephyr,input-positive`` and + ``zephyr,input-negative`` devicetree properties to select the hardware + channel(s) to link a software channel configuration to. + * Battery-backed RAM * Added MCP7940N battery-backed RTC SRAM driver. From 4a53645448baba2b9bdc785dc787c1725ddcc4bd Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Mon, 6 Mar 2023 12:13:50 +0100 Subject: [PATCH 0696/1906] drivers: udc: add helper function to send UDC endpoint event Add helper function to send UDC endpoint event to a higher level that takes fewer arguments. Signed-off-by: Johann Fischer --- drivers/usb/udc/udc_common.c | 27 +++++++++++++++++++++++---- drivers/usb/udc/udc_common.h | 16 ++++++++++++++++ drivers/usb/udc/udc_kinetis.c | 8 ++++---- drivers/usb/udc/udc_nrf.c | 18 +++++++----------- drivers/usb/udc/udc_virtual.c | 8 ++++---- 5 files changed, 54 insertions(+), 23 deletions(-) diff --git a/drivers/usb/udc/udc_common.c b/drivers/usb/udc/udc_common.c index 025bffc88090..bbfa4d3fbbc4 100644 --- a/drivers/usb/udc/udc_common.c +++ b/drivers/usb/udc/udc_common.c @@ -183,6 +183,25 @@ int udc_submit_event(const struct device *dev, return data->event_cb(dev, &drv_evt); } +int udc_submit_ep_event(const struct device *dev, + struct net_buf *const buf, + const int err) +{ + struct udc_data *data = dev->data; + const struct udc_event drv_evt = { + .type = UDC_EVT_EP_REQUEST, + .buf = buf, + .status = err, + .dev = dev, + }; + + if (!udc_is_initialized(dev)) { + return -EPERM; + } + + return data->event_cb(dev, &drv_evt); +} + static uint8_t ep_attrib_get_transfer(uint8_t attributes) { return attributes & USB_EP_TRANSFER_TYPE_MASK; @@ -850,7 +869,7 @@ int udc_ctrl_submit_s_out_status(const struct device *dev, ret = -ENOMEM; } - return udc_submit_event(dev, UDC_EVT_EP_REQUEST, ret, data->setup); + return udc_submit_ep_event(dev, data->setup, ret); } int udc_ctrl_submit_s_in_status(const struct device *dev) @@ -869,7 +888,7 @@ int udc_ctrl_submit_s_in_status(const struct device *dev) ret = -ENOMEM; } - return udc_submit_event(dev, UDC_EVT_EP_REQUEST, ret, data->setup); + return udc_submit_ep_event(dev, data->setup, ret); } int udc_ctrl_submit_s_status(const struct device *dev) @@ -884,7 +903,7 @@ int udc_ctrl_submit_s_status(const struct device *dev) ret = -ENOMEM; } - return udc_submit_event(dev, UDC_EVT_EP_REQUEST, ret, data->setup); + return udc_submit_ep_event(dev, data->setup, ret); } int udc_ctrl_submit_status(const struct device *dev, @@ -894,7 +913,7 @@ int udc_ctrl_submit_status(const struct device *dev, bi->status = true; - return udc_submit_event(dev, UDC_EVT_EP_REQUEST, 0, buf); + return udc_submit_ep_event(dev, buf, 0); } bool udc_ctrl_stage_is_data_out(const struct device *dev) diff --git a/drivers/usb/udc/udc_common.h b/drivers/usb/udc/udc_common.h index dd5ef3eaff64..9d0d29a4e353 100644 --- a/drivers/usb/udc/udc_common.h +++ b/drivers/usb/udc/udc_common.h @@ -150,6 +150,22 @@ int udc_submit_event(const struct device *dev, const int status, struct net_buf *const buf); +/** + * @brief Helper function to send UDC endpoint event to a higher level. + * + * Type of this event is hardcoded to UDC_EVT_EP_REQUEST. + * The callback would typically sends UDC even to a message queue (k_msgq). + * + * @param[in] dev Pointer to device struct of the driver instance + * @param[in] buf Pointer to UDC request buffer + * @param[in] err Request result + * + * @return 0 on success, all other values should be treated as error. + * @retval -EPERM controller is not initialized + */ +int udc_submit_ep_event(const struct device *dev, + struct net_buf *const buf, + const int err); /** * @brief Helper function to enable endpoint. * diff --git a/drivers/usb/udc/udc_kinetis.c b/drivers/usb/udc/udc_kinetis.c index 3cc4fb625a61..d06151b1fa2a 100644 --- a/drivers/usb/udc/udc_kinetis.c +++ b/drivers/usb/udc/udc_kinetis.c @@ -331,7 +331,7 @@ static inline int work_handler_setup(const struct device *dev) err = usbfsotg_ctrl_feed_dout(dev, udc_data_stage_length(buf), false, true); if (err == -ENOMEM) { - err = udc_submit_event(dev, UDC_EVT_EP_REQUEST, err, buf); + err = udc_submit_ep_event(dev, buf, err); } } else if (udc_ctrl_stage_is_data_in(dev)) { /* @@ -397,7 +397,7 @@ static inline int work_handler_out(const struct device *dev, err = udc_ctrl_submit_s_out_status(dev, buf); } } else { - err = udc_submit_event(dev, UDC_EVT_EP_REQUEST, 0, buf); + err = udc_submit_ep_event(dev, buf, 0); } return err; @@ -434,7 +434,7 @@ static inline int work_handler_in(const struct device *dev, return 0; } - return udc_submit_event(dev, UDC_EVT_EP_REQUEST, 0, buf); + return udc_submit_ep_event(dev, buf, 0); } static void usbfsotg_event_submit(const struct device *dev, @@ -735,7 +735,7 @@ static int usbfsotg_ep_dequeue(const struct device *dev, cfg->stat.halted = false; buf = udc_buf_get_all(dev, cfg->addr); if (buf) { - udc_submit_event(dev, UDC_EVT_EP_REQUEST, -ECONNABORTED, buf); + udc_submit_ep_event(dev, buf, -ECONNABORTED); } udc_ep_set_busy(dev, cfg->addr, false); diff --git a/drivers/usb/udc/udc_nrf.c b/drivers/usb/udc/udc_nrf.c index b5f88d063f56..9977499a1338 100644 --- a/drivers/usb/udc/udc_nrf.c +++ b/drivers/usb/udc/udc_nrf.c @@ -113,8 +113,7 @@ static void udc_event_xfer_in_next(const struct device *dev, const uint8_t ep) if (err != NRFX_SUCCESS) { LOG_ERR("ep 0x%02x nrfx error: %x", ep, err); /* REVISE: remove from endpoint queue? ASSERT? */ - udc_submit_event(dev, UDC_EVT_EP_REQUEST, - -ECONNREFUSED, buf); + udc_submit_ep_event(dev, buf, -ECONNREFUSED); } else { udc_ep_set_busy(dev, ep, true); } @@ -179,7 +178,7 @@ static void udc_event_xfer_in(const struct device *dev, return udc_event_xfer_ctrl_in(dev, buf); } - udc_submit_event(dev, UDC_EVT_EP_REQUEST, 0, buf); + udc_submit_ep_event(dev, buf, 0); break; case NRFX_USBD_EP_ABORTED: @@ -192,8 +191,7 @@ static void udc_event_xfer_in(const struct device *dev, } udc_ep_set_busy(dev, ep, false); - udc_submit_event(dev, UDC_EVT_EP_REQUEST, - -ECONNABORTED, buf); + udc_submit_ep_event(dev, buf, -ECONNABORTED); break; default: @@ -241,8 +239,7 @@ static void udc_event_xfer_out_next(const struct device *dev, const uint8_t ep) if (err != NRFX_SUCCESS) { LOG_ERR("ep 0x%02x nrfx error: %x", ep, err); /* REVISE: remove from endpoint queue? ASSERT? */ - udc_submit_event(dev, UDC_EVT_EP_REQUEST, - -ECONNREFUSED, buf); + udc_submit_ep_event(dev, buf, -ECONNREFUSED); } else { udc_ep_set_busy(dev, ep, true); } @@ -284,7 +281,7 @@ static void udc_event_xfer_out(const struct device *dev, if (ep == USB_CONTROL_EP_OUT) { udc_event_xfer_ctrl_out(dev, buf); } else { - udc_submit_event(dev, UDC_EVT_EP_REQUEST, 0, buf); + udc_submit_ep_event(dev, buf, 0); } break; @@ -340,7 +337,7 @@ static int udc_event_xfer_setup(const struct device *dev) LOG_DBG("s:%p|feed for -out-", buf); err = usbd_ctrl_feed_dout(dev, udc_data_stage_length(buf)); if (err == -ENOMEM) { - err = udc_submit_event(dev, UDC_EVT_EP_REQUEST, err, buf); + err = udc_submit_ep_event(dev, buf, err); } } else if (udc_ctrl_stage_is_data_in(dev)) { err = udc_ctrl_submit_s_in_status(dev); @@ -529,8 +526,7 @@ static int udc_nrf_ep_dequeue(const struct device *dev, */ buf = udc_buf_get_all(dev, cfg->addr); if (buf) { - udc_submit_event(dev, UDC_EVT_EP_REQUEST, - -ECONNABORTED, buf); + udc_submit_ep_event(dev, buf, -ECONNABORTED); } else { LOG_INF("ep 0x%02x queue is empty", cfg->addr); } diff --git a/drivers/usb/udc/udc_virtual.c b/drivers/usb/udc/udc_virtual.c index d2a6d6e30ed3..9d469378d553 100644 --- a/drivers/usb/udc/udc_virtual.c +++ b/drivers/usb/udc/udc_virtual.c @@ -116,7 +116,7 @@ static int vrt_handle_setup(const struct device *dev, * Pass it on to the higher level which will * halt control OUT endpoint. */ - err = udc_submit_event(dev, UDC_EVT_EP_REQUEST, err, buf); + err = udc_submit_ep_event(dev, buf, err); } } else if (udc_ctrl_stage_is_data_in(dev)) { LOG_DBG("s: %p | submit for -in-", buf); @@ -189,7 +189,7 @@ static int vrt_handle_out(const struct device *dev, if (ep == USB_CONTROL_EP_OUT) { err = vrt_handle_ctrl_out(dev, buf); } else { - err = udc_submit_event(dev, UDC_EVT_EP_REQUEST, 0, buf); + err = udc_submit_ep_event(dev, buf, 0); } } @@ -264,7 +264,7 @@ static int vrt_handle_in(const struct device *dev, if (ep == USB_CONTROL_EP_IN) { err = isr_handle_ctrl_in(dev, buf); } else { - err = udc_submit_event(dev, UDC_EVT_EP_REQUEST, 0, buf); + err = udc_submit_ep_event(dev, buf, 0); } } @@ -406,7 +406,7 @@ static int udc_vrt_ep_dequeue(const struct device *dev, /* Draft dequeue implementation */ buf = udc_buf_get_all(dev, cfg->addr); if (buf) { - udc_submit_event(dev, UDC_EVT_EP_REQUEST, -ECONNABORTED, buf); + udc_submit_ep_event(dev, buf, -ECONNABORTED); } irq_unlock(lock_key); From 39218112abdcda18b7b7f3b1735deeea7d4c28c5 Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Mon, 6 Mar 2023 12:56:58 +0100 Subject: [PATCH 0697/1906] drivers: udc_nrf: do not use UDC_EVT_EP_REQUEST without net_buf pointer Do not use UDC_EVT_EP_REQUEST event without a valid pointer to a request buffer. No changes needed in the upper layer because it requires valid buffer pointer for this type of event anyway. Signed-off-by: Johann Fischer --- drivers/usb/udc/udc_nrf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/udc/udc_nrf.c b/drivers/usb/udc/udc_nrf.c index 9977499a1338..b33a994eddef 100644 --- a/drivers/usb/udc/udc_nrf.c +++ b/drivers/usb/udc/udc_nrf.c @@ -197,7 +197,7 @@ static void udc_event_xfer_in(const struct device *dev, default: LOG_ERR("Unexpected event (nrfx_usbd): %d, ep 0x%02x", event->data.eptransfer.status, ep); - udc_submit_event(dev, UDC_EVT_EP_REQUEST, -EIO, NULL); + udc_submit_event(dev, UDC_EVT_ERROR, -EIO, NULL); break; } } @@ -289,7 +289,7 @@ static void udc_event_xfer_out(const struct device *dev, default: LOG_ERR("Unexpected event (nrfx_usbd): %d, ep 0x%02x", event->data.eptransfer.status, ep); - udc_submit_event(dev, UDC_EVT_EP_REQUEST, -EIO, NULL); + udc_submit_event(dev, UDC_EVT_ERROR, -EIO, NULL); break; } } From ad81b3b79747991c6773882f9cd6e8b2f9da8bef Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Mon, 6 Mar 2023 13:56:51 +0100 Subject: [PATCH 0698/1906] drivers: udc: move transfer status to buffer info structure This allows us to get the result of synchronous transfer without any hacks, just from the net_buf structure. Signed-off-by: Johann Fischer --- drivers/usb/udc/udc_common.c | 3 +++ include/zephyr/drivers/usb/udc.h | 2 ++ subsys/usb/device_next/usbd_core.c | 6 ++---- tests/drivers/udc/src/main.c | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/usb/udc/udc_common.c b/drivers/usb/udc/udc_common.c index bbfa4d3fbbc4..3fb7b39ba007 100644 --- a/drivers/usb/udc/udc_common.c +++ b/drivers/usb/udc/udc_common.c @@ -187,6 +187,7 @@ int udc_submit_ep_event(const struct device *dev, struct net_buf *const buf, const int err) { + struct udc_buf_info *bi = udc_get_buf_info(buf); struct udc_data *data = dev->data; const struct udc_event drv_evt = { .type = UDC_EVT_EP_REQUEST, @@ -199,6 +200,8 @@ int udc_submit_ep_event(const struct device *dev, return -EPERM; } + bi->err = err; + return data->event_cb(dev, &drv_evt); } diff --git a/include/zephyr/drivers/usb/udc.h b/include/zephyr/drivers/usb/udc.h index 2150d6f20563..301a36bffde6 100644 --- a/include/zephyr/drivers/usb/udc.h +++ b/include/zephyr/drivers/usb/udc.h @@ -191,6 +191,8 @@ struct udc_buf_info { unsigned int queued : 1; /** Transfer owner (usually pointer to a class instance) */ void *owner; + /** Transfer result, 0 on success, other values on error */ + int err; } __packed; /** diff --git a/subsys/usb/device_next/usbd_core.c b/subsys/usb/device_next/usbd_core.c index 81e3627456a0..37d766ac654d 100644 --- a/subsys/usb/device_next/usbd_core.c +++ b/subsys/usb/device_next/usbd_core.c @@ -43,11 +43,9 @@ static int event_handler_ep_request(struct usbd_contex *const uds_ctx, bi = udc_get_buf_info(event->buf); if (USB_EP_GET_IDX(bi->ep) == 0) { - ret = usbd_handle_ctrl_xfer(uds_ctx, event->buf, - event->status); + ret = usbd_handle_ctrl_xfer(uds_ctx, event->buf, bi->err); } else { - ret = usbd_class_handle_xfer(uds_ctx, event->buf, - event->status); + ret = usbd_class_handle_xfer(uds_ctx, event->buf, bi->err); } if (ret) { diff --git a/tests/drivers/udc/src/main.c b/tests/drivers/udc/src/main.c index da78a6742fde..43ff416f2aae 100644 --- a/tests/drivers/udc/src/main.c +++ b/tests/drivers/udc/src/main.c @@ -41,7 +41,7 @@ static void event_ep_request(const struct device *dev, struct udc_event event) err = udc_ep_buf_free(dev, event.buf); zassert_ok(err, "Failed to free request buffer"); - if (event.status == -ECONNABORTED && bi->ep == last_used_ep) { + if (bi->err == -ECONNABORTED && bi->ep == last_used_ep) { k_sem_give(&ep_queue_sem); } } From 9d91333a435155bd774d4986ea4571bd874b696d Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Mon, 6 Mar 2023 14:16:07 +0100 Subject: [PATCH 0699/1906] drivers: udc: simplify udc_submit_event() Since we have a dedicated function for UDC_EVT_EP_REQUEST type events, we can now simplify udc_submit_event() and remove buf parameter. Signed-off-by: Johann Fischer --- drivers/usb/udc/udc_common.c | 5 +---- drivers/usb/udc/udc_common.h | 4 +--- drivers/usb/udc/udc_kinetis.c | 20 ++++++++++---------- drivers/usb/udc/udc_nrf.c | 16 ++++++++-------- drivers/usb/udc/udc_virtual.c | 12 ++++++------ include/zephyr/drivers/usb/udc.h | 4 ++-- 6 files changed, 28 insertions(+), 33 deletions(-) diff --git a/drivers/usb/udc/udc_common.c b/drivers/usb/udc/udc_common.c index 3fb7b39ba007..736f4462f174 100644 --- a/drivers/usb/udc/udc_common.c +++ b/drivers/usb/udc/udc_common.c @@ -165,13 +165,11 @@ void udc_ep_buf_clear_zlp(const struct net_buf *const buf) int udc_submit_event(const struct device *dev, const enum udc_event_type type, - const int status, - struct net_buf *const buf) + const int status) { struct udc_data *data = dev->data; struct udc_event drv_evt = { .type = type, - .buf = buf, .status = status, .dev = dev, }; @@ -192,7 +190,6 @@ int udc_submit_ep_event(const struct device *dev, const struct udc_event drv_evt = { .type = UDC_EVT_EP_REQUEST, .buf = buf, - .status = err, .dev = dev, }; diff --git a/drivers/usb/udc/udc_common.h b/drivers/usb/udc/udc_common.h index 9d0d29a4e353..76614ac8c477 100644 --- a/drivers/usb/udc/udc_common.h +++ b/drivers/usb/udc/udc_common.h @@ -140,15 +140,13 @@ void udc_buf_put(struct udc_ep_config *const ep_cfg, * @param[in] dev Pointer to device struct of the driver instance * @param[in] type Event type * @param[in] status Event status - * @param[in] buf Pointer to UDC request buffer * * @return 0 on success, all other values should be treated as error. * @retval -EPERM controller is not initialized */ int udc_submit_event(const struct device *dev, const enum udc_event_type type, - const int status, - struct net_buf *const buf); + const int status); /** * @brief Helper function to send UDC endpoint event to a higher level. diff --git a/drivers/usb/udc/udc_kinetis.c b/drivers/usb/udc/udc_kinetis.c index d06151b1fa2a..188fca5f1e82 100644 --- a/drivers/usb/udc/udc_kinetis.c +++ b/drivers/usb/udc/udc_kinetis.c @@ -447,7 +447,7 @@ static void usbfsotg_event_submit(const struct device *dev, ret = k_mem_slab_alloc(&usbfsotg_ee_slab, (void **)&ev, K_NO_WAIT); if (ret) { - udc_submit_event(dev, UDC_EVT_ERROR, ret, NULL); + udc_submit_event(dev, UDC_EVT_ERROR, ret); } ev->dev = dev; @@ -471,7 +471,7 @@ static void xfer_work_handler(struct k_work *item) ev->dev, ev->ep, ev->event); ep_cfg = udc_get_ep_cfg(ev->dev, ev->ep); if (unlikely(ep_cfg == NULL)) { - udc_submit_event(ev->dev, UDC_EVT_ERROR, -ENODATA, NULL); + udc_submit_event(ev->dev, UDC_EVT_ERROR, -ENODATA); goto xfer_work_error; } @@ -495,7 +495,7 @@ static void xfer_work_handler(struct k_work *item) } if (unlikely(err)) { - udc_submit_event(ev->dev, UDC_EVT_ERROR, err, NULL); + udc_submit_event(ev->dev, UDC_EVT_ERROR, err); } /* Peek next transer */ @@ -569,7 +569,7 @@ static ALWAYS_INLINE void isr_handle_xfer_done(const struct device *dev, usbfsotg_event_submit(dev, ep, USBFSOTG_EVT_SETUP); } else { LOG_ERR("No buffer for ep 0x00"); - udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS, NULL); + udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS); } break; @@ -587,7 +587,7 @@ static ALWAYS_INLINE void isr_handle_xfer_done(const struct device *dev, if (buf == NULL) { LOG_ERR("No buffer for ep 0x%02x", ep); - udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS, NULL); + udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS); break; } @@ -614,7 +614,7 @@ static ALWAYS_INLINE void isr_handle_xfer_done(const struct device *dev, buf = udc_buf_peek(dev, ep_cfg->addr); if (buf == NULL) { LOG_ERR("No buffer for ep 0x%02x", ep); - udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS, NULL); + udc_submit_event(dev, UDC_EVT_ERROR, -ENOBUFS); break; } @@ -646,12 +646,12 @@ static void usbfsotg_isr_handler(const struct device *dev) if (istatus & USB_ISTAT_USBRST_MASK) { base->ADDR = 0U; - udc_submit_event(dev, UDC_EVT_RESET, 0, NULL); + udc_submit_event(dev, UDC_EVT_RESET, 0); } if (istatus == USB_ISTAT_ERROR_MASK) { LOG_DBG("ERROR IRQ 0x%02x", base->ERRSTAT); - udc_submit_event(dev, UDC_EVT_ERROR, base->ERRSTAT, NULL); + udc_submit_event(dev, UDC_EVT_ERROR, base->ERRSTAT); base->ERRSTAT = 0xFF; } @@ -687,7 +687,7 @@ static void usbfsotg_isr_handler(const struct device *dev) base->INTEN |= USB_INTEN_RESUMEEN_MASK; udc_set_suspended(dev, true); - udc_submit_event(dev, UDC_EVT_SUSPEND, 0, NULL); + udc_submit_event(dev, UDC_EVT_SUSPEND, 0); } if (istatus & USB_ISTAT_RESUME_MASK) { @@ -696,7 +696,7 @@ static void usbfsotg_isr_handler(const struct device *dev) base->INTEN &= ~USB_INTEN_RESUMEEN_MASK; udc_set_suspended(dev, false); - udc_submit_event(dev, UDC_EVT_RESUME, 0, NULL); + udc_submit_event(dev, UDC_EVT_RESUME, 0); } /* Clear interrupt status bits */ diff --git a/drivers/usb/udc/udc_nrf.c b/drivers/usb/udc/udc_nrf.c index b33a994eddef..ccae117c6f86 100644 --- a/drivers/usb/udc/udc_nrf.c +++ b/drivers/usb/udc/udc_nrf.c @@ -197,7 +197,7 @@ static void udc_event_xfer_in(const struct device *dev, default: LOG_ERR("Unexpected event (nrfx_usbd): %d, ep 0x%02x", event->data.eptransfer.status, ep); - udc_submit_event(dev, UDC_EVT_ERROR, -EIO, NULL); + udc_submit_event(dev, UDC_EVT_ERROR, -EIO); break; } } @@ -289,7 +289,7 @@ static void udc_event_xfer_out(const struct device *dev, default: LOG_ERR("Unexpected event (nrfx_usbd): %d, ep 0x%02x", event->data.eptransfer.status, ep); - udc_submit_event(dev, UDC_EVT_ERROR, -EIO, NULL); + udc_submit_event(dev, UDC_EVT_ERROR, -EIO); break; } } @@ -421,22 +421,22 @@ static void usbd_event_handler(nrfx_usbd_evt_t const *const hal_evt) LOG_INF("SUSPEND state detected"); nrfx_usbd_suspend(); udc_set_suspended(udc_nrf_dev, true); - udc_submit_event(udc_nrf_dev, UDC_EVT_SUSPEND, 0, NULL); + udc_submit_event(udc_nrf_dev, UDC_EVT_SUSPEND, 0); break; case NRFX_USBD_EVT_RESUME: LOG_INF("RESUMING from suspend"); udc_set_suspended(udc_nrf_dev, false); - udc_submit_event(udc_nrf_dev, UDC_EVT_RESUME, 0, NULL); + udc_submit_event(udc_nrf_dev, UDC_EVT_RESUME, 0); break; case NRFX_USBD_EVT_WUREQ: LOG_INF("Remote wakeup initiated"); break; case NRFX_USBD_EVT_RESET: LOG_INF("Reset"); - udc_submit_event(udc_nrf_dev, UDC_EVT_RESET, 0, NULL); + udc_submit_event(udc_nrf_dev, UDC_EVT_RESET, 0); break; case NRFX_USBD_EVT_SOF: - udc_submit_event(udc_nrf_dev, UDC_EVT_SOF, 0, NULL); + udc_submit_event(udc_nrf_dev, UDC_EVT_SOF, 0); udc_sof_check_iso_out(udc_nrf_dev); break; case NRFX_USBD_EVT_EPTRANSFER: @@ -465,12 +465,12 @@ static void udc_nrf_power_handler(nrfx_power_usb_evt_t pwr_evt) break; case NRFX_POWER_USB_EVT_READY: LOG_INF("POWER event ready"); - udc_submit_event(udc_nrf_dev, UDC_EVT_VBUS_READY, 0, NULL); + udc_submit_event(udc_nrf_dev, UDC_EVT_VBUS_READY, 0); nrfx_usbd_start(true); break; case NRFX_POWER_USB_EVT_REMOVED: LOG_INF("POWER event removed"); - udc_submit_event(udc_nrf_dev, UDC_EVT_VBUS_REMOVED, 0, NULL); + udc_submit_event(udc_nrf_dev, UDC_EVT_VBUS_REMOVED, 0); break; default: LOG_ERR("Unknown power event %d", pwr_evt); diff --git a/drivers/usb/udc/udc_virtual.c b/drivers/usb/udc/udc_virtual.c index 9d469378d553..b26a693c2e2e 100644 --- a/drivers/usb/udc/udc_virtual.c +++ b/drivers/usb/udc/udc_virtual.c @@ -307,19 +307,19 @@ static ALWAYS_INLINE void udc_vrt_thread_handler(void *arg) switch (vrt_ev->type) { case UVB_EVT_VBUS_REMOVED: - err = udc_submit_event(dev, UDC_EVT_VBUS_REMOVED, 0, NULL); + err = udc_submit_event(dev, UDC_EVT_VBUS_REMOVED, 0); break; case UVB_EVT_VBUS_READY: - err = udc_submit_event(dev, UDC_EVT_VBUS_READY, 0, NULL); + err = udc_submit_event(dev, UDC_EVT_VBUS_READY, 0); break; case UVB_EVT_SUSPEND: - err = udc_submit_event(dev, UDC_EVT_SUSPEND, 0, NULL); + err = udc_submit_event(dev, UDC_EVT_SUSPEND, 0); break; case UVB_EVT_RESUME: - err = udc_submit_event(dev, UDC_EVT_RESUME, 0, NULL); + err = udc_submit_event(dev, UDC_EVT_RESUME, 0); break; case UVB_EVT_RESET: - err = udc_submit_event(dev, UDC_EVT_RESET, 0, NULL); + err = udc_submit_event(dev, UDC_EVT_RESET, 0); break; case UVB_EVT_REQUEST: err = vrt_handle_request(dev, vrt_ev->pkt); @@ -329,7 +329,7 @@ static ALWAYS_INLINE void udc_vrt_thread_handler(void *arg) }; if (err) { - udc_submit_event(dev, UDC_EVT_ERROR, err, NULL); + udc_submit_event(dev, UDC_EVT_ERROR, err); } k_mem_slab_free(&udc_vrt_slab, (void **)&vrt_ev); diff --git a/include/zephyr/drivers/usb/udc.h b/include/zephyr/drivers/usb/udc.h index 301a36bffde6..f5f74ec12782 100644 --- a/include/zephyr/drivers/usb/udc.h +++ b/include/zephyr/drivers/usb/udc.h @@ -158,11 +158,11 @@ struct udc_event { union { /** Event value */ uint32_t value; + /** Event status value, if any */ + int status; /** Pointer to request used only for UDC_EVT_EP_REQUEST */ struct net_buf *buf; }; - /** Event status, 0 on success, other values on error */ - int status; /** Pointer to device struct */ const struct device *dev; }; From 6c0626215bb011b7b03b700d4fbca0bb8c3e352c Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Tue, 21 Mar 2023 14:27:56 +0100 Subject: [PATCH 0700/1906] devicetree: Add DT_INST_PROP_LEN_OR Add the instance-based version of DT_PROP_LEN_OR. Signed-off-by: Pieter De Gendt --- include/zephyr/devicetree.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/zephyr/devicetree.h b/include/zephyr/devicetree.h index a9920fa44cbc..8267898cfb58 100644 --- a/include/zephyr/devicetree.h +++ b/include/zephyr/devicetree.h @@ -3395,6 +3395,16 @@ #define DT_INST_PROP_OR(inst, prop, default_value) \ DT_PROP_OR(DT_DRV_INST(inst), prop, default_value) +/** + * @brief Like DT_INST_PROP_LEN(), but with a fallback to @p default_value + * @param inst instance number + * @param prop lowercase-and-underscores property name + * @param default_value a fallback value to expand to + * @return DT_INST_PROP_LEN(inst, prop) or @p default_value + */ +#define DT_INST_PROP_LEN_OR(inst, prop, default_value) \ + DT_PROP_LEN_OR(DT_DRV_INST(inst), prop, default_value) + /** * @deprecated Use DT_INST_PROP(inst, label) * @brief Get a `DT_DRV_COMPAT` instance's `label` property From 85d8f8e0dbf9dcda8e58768928319c265fe1848b Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Tue, 21 Mar 2023 14:34:58 +0100 Subject: [PATCH 0701/1906] tests: devicetree: add tests for DT_INST_PROP_LEN_OR Add test coverage for the DT_INST_PROP_LEN_OR macro. Signed-off-by: Pieter De Gendt --- tests/lib/devicetree/api/src/main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/lib/devicetree/api/src/main.c b/tests/lib/devicetree/api/src/main.c index 509ffcaa09ff..6e2ff8aa9f88 100644 --- a/tests/lib/devicetree/api/src/main.c +++ b/tests/lib/devicetree/api/src/main.c @@ -214,6 +214,11 @@ ZTEST(devicetree_api, test_default_prop_access) zassert_equal(DT_INST_PROP_OR(0, misc_prop, X), 1234, ""); zassert_equal(DT_INST_PROP_OR(0, not_a_property, -1), -1, ""); +#undef DT_DRV_COMPAT +#define DT_DRV_COMPAT vnd_array_holder + zassert_equal(DT_INST_PROP_LEN_OR(0, a, X), 3, ""); + zassert_equal(DT_INST_PROP_LEN_OR(0, not_a_property, -1), -1, ""); + #undef DT_DRV_COMPAT #define DT_DRV_COMPAT vnd_adc_temp_sensor zassert_equal(DT_INST_PHA_BY_IDX_OR(0, dmas, 1, channel, X), 3, ""); From c2951ef7c60184b6a60516fb5f50bd2b62debac2 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 11:30:01 -0500 Subject: [PATCH 0702/1906] drivers: sensor: iis3dhhc: Store sensor trigger as a pointer Fixes the iis3dhhc sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/iis3dhhc/iis3dhhc.h | 1 + drivers/sensor/iis3dhhc/iis3dhhc_trigger.c | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/sensor/iis3dhhc/iis3dhhc.h b/drivers/sensor/iis3dhhc/iis3dhhc.h index 116a6d76a536..5b49beb34f40 100644 --- a/drivers/sensor/iis3dhhc/iis3dhhc.h +++ b/drivers/sensor/iis3dhhc/iis3dhhc.h @@ -39,6 +39,7 @@ struct iis3dhhc_data { struct gpio_callback gpio_cb; sensor_trigger_handler_t handler_drdy; + const struct sensor_trigger *trig_drdy; const struct device *dev; #if defined(CONFIG_IIS3DHHC_TRIGGER_OWN_THREAD) diff --git a/drivers/sensor/iis3dhhc/iis3dhhc_trigger.c b/drivers/sensor/iis3dhhc/iis3dhhc_trigger.c index 3d4c18595c1f..f1e76376e10b 100644 --- a/drivers/sensor/iis3dhhc/iis3dhhc_trigger.c +++ b/drivers/sensor/iis3dhhc/iis3dhhc_trigger.c @@ -51,6 +51,7 @@ int iis3dhhc_trigger_set(const struct device *dev, if (trig->chan == SENSOR_CHAN_ACCEL_XYZ) { iis3dhhc->handler_drdy = handler; + iis3dhhc->trig_drdy = trig; if (handler) { /* dummy read: re-trigger interrupt */ iis3dhhc_acceleration_raw_get(iis3dhhc->ctx, raw); @@ -70,13 +71,10 @@ int iis3dhhc_trigger_set(const struct device *dev, static void iis3dhhc_handle_interrupt(const struct device *dev) { struct iis3dhhc_data *iis3dhhc = dev->data; - struct sensor_trigger drdy_trigger = { - .type = SENSOR_TRIG_DATA_READY, - }; const struct iis3dhhc_config *cfg = dev->config; if (iis3dhhc->handler_drdy != NULL) { - iis3dhhc->handler_drdy(dev, &drdy_trigger); + iis3dhhc->handler_drdy(dev, iis3dhhc->trig_drdy); } gpio_pin_interrupt_configure_dt(&cfg->int_gpio, GPIO_INT_EDGE_TO_ACTIVE); From 0c3bfc2762e290463193b47114762d8966f21274 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 11:51:49 -0500 Subject: [PATCH 0703/1906] drivers: sensor: ina23x: Store sensor trigger as a pointer Fixes the ina23x sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/ina23x/ina230.h | 1 + drivers/sensor/ina23x/ina230_trigger.c | 5 ++--- drivers/sensor/ina23x/ina237.c | 5 ++--- drivers/sensor/ina23x/ina23x_trigger.h | 1 + 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/sensor/ina23x/ina230.h b/drivers/sensor/ina23x/ina230.h index c5d80b0fe558..04cfc013d6fd 100644 --- a/drivers/sensor/ina23x/ina230.h +++ b/drivers/sensor/ina23x/ina230.h @@ -42,6 +42,7 @@ struct ina230_data { struct gpio_callback gpio_cb; struct k_work work; sensor_trigger_handler_t handler_alert; + const struct sensor_trigger *trig_alert; #endif /* CONFIG_INA230_TRIGGER */ }; diff --git a/drivers/sensor/ina23x/ina230_trigger.c b/drivers/sensor/ina23x/ina230_trigger.c index 89a59f00c008..e46d9dbaf992 100644 --- a/drivers/sensor/ina23x/ina230_trigger.c +++ b/drivers/sensor/ina23x/ina230_trigger.c @@ -16,7 +16,6 @@ LOG_MODULE_DECLARE(INA230, CONFIG_SENSOR_LOG_LEVEL); static void ina230_gpio_callback(const struct device *port, struct gpio_callback *cb, uint32_t pin) { - struct sensor_trigger ina230_trigger; struct ina230_data *ina230 = CONTAINER_OF(cb, struct ina230_data, gpio_cb); const struct device *dev = (const struct device *)ina230->dev; @@ -25,8 +24,7 @@ static void ina230_gpio_callback(const struct device *port, ARG_UNUSED(cb); if (ina230->handler_alert) { - ina230_trigger.type = SENSOR_TRIG_DATA_READY; - ina230->handler_alert(dev, &ina230_trigger); + ina230->handler_alert(dev, ina230->trig_alert); } } @@ -39,6 +37,7 @@ int ina230_trigger_set(const struct device *dev, ARG_UNUSED(trig); ina230->handler_alert = handler; + ina230->trig_alert = trig; return 0; } diff --git a/drivers/sensor/ina23x/ina237.c b/drivers/sensor/ina23x/ina237.c index 6f5c296a9ac3..b1142a558ebd 100644 --- a/drivers/sensor/ina23x/ina237.c +++ b/drivers/sensor/ina23x/ina237.c @@ -260,7 +260,6 @@ static void ina237_trigger_work_handler(struct k_work *work) struct ina23x_trigger *trigg = CONTAINER_OF(work, struct ina23x_trigger, conversion_work); struct ina237_data *data = CONTAINER_OF(trigg, struct ina237_data, trigger); const struct ina237_config *config = data->dev->config; - struct sensor_trigger ina237_trigger; int ret; uint16_t reg_alert; @@ -277,8 +276,7 @@ static void ina237_trigger_work_handler(struct k_work *work) } if (data->trigger.handler_alert) { - ina237_trigger.type = SENSOR_TRIG_DATA_READY; - data->trigger.handler_alert(data->dev, &ina237_trigger); + data->trigger.handler_alert(data->dev, data->trigger.trig_alert); } } @@ -361,6 +359,7 @@ static int ina237_trigger_set(const struct device *dev, } ina237->trigger.handler_alert = handler; + ina237->trigger.trig_alert = trig; return 0; } diff --git a/drivers/sensor/ina23x/ina23x_trigger.h b/drivers/sensor/ina23x/ina23x_trigger.h index d13c885ac9e5..b7b4089ac639 100644 --- a/drivers/sensor/ina23x/ina23x_trigger.h +++ b/drivers/sensor/ina23x/ina23x_trigger.h @@ -15,6 +15,7 @@ struct ina23x_trigger { struct gpio_callback gpio_cb; struct k_work conversion_work; sensor_trigger_handler_t handler_alert; + const struct sensor_trigger *trig_alert; }; int ina23x_trigger_mode_init(struct ina23x_trigger *trigg, From 16140bf4851424a9a714eeaf311e3cab36fd2ddb Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 11:52:37 -0500 Subject: [PATCH 0704/1906] drivers: sensor: isl29035: Store sensor trigger as a pointer Fixes the isl29035 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/isl29035/isl29035.h | 2 +- drivers/sensor/isl29035/isl29035_trigger.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/sensor/isl29035/isl29035.h b/drivers/sensor/isl29035/isl29035.h index 5b8255090a77..e77a9d2e60c8 100644 --- a/drivers/sensor/isl29035/isl29035.h +++ b/drivers/sensor/isl29035/isl29035.h @@ -116,7 +116,7 @@ struct isl29035_driver_data { const struct device *dev; struct gpio_callback gpio_cb; - struct sensor_trigger th_trigger; + const struct sensor_trigger *th_trigger; sensor_trigger_handler_t th_handler; #if defined(CONFIG_ISL29035_TRIGGER_OWN_THREAD) diff --git a/drivers/sensor/isl29035/isl29035_trigger.c b/drivers/sensor/isl29035/isl29035_trigger.c index 092380154f8e..b5cfc669fed5 100644 --- a/drivers/sensor/isl29035/isl29035_trigger.c +++ b/drivers/sensor/isl29035/isl29035_trigger.c @@ -114,7 +114,7 @@ static void isl29035_thread_cb(const struct device *dev) } if (drv_data->th_handler != NULL) { - drv_data->th_handler(dev, &drv_data->th_trigger); + drv_data->th_handler(dev, drv_data->th_trigger); } setup_int(dev, true); @@ -157,7 +157,7 @@ int isl29035_trigger_set(const struct device *dev, setup_int(dev, false); drv_data->th_handler = handler; - drv_data->th_trigger = *trig; + drv_data->th_trigger = trig; /* enable interrupt callback */ setup_int(dev, true); From 0ed618c609142bf5ed70075a1f8af37b4f077f64 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 11:53:33 -0500 Subject: [PATCH 0705/1906] drivers: sensor: ism330dhcx: Store sensor trigger as a pointer Fixes the ism330dhcx sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/ism330dhcx/ism330dhcx.h | 3 +++ drivers/sensor/ism330dhcx/ism330dhcx_trigger.c | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/sensor/ism330dhcx/ism330dhcx.h b/drivers/sensor/ism330dhcx/ism330dhcx.h index 063140c6201f..fd3a431637dc 100644 --- a/drivers/sensor/ism330dhcx/ism330dhcx.h +++ b/drivers/sensor/ism330dhcx/ism330dhcx.h @@ -96,8 +96,11 @@ struct ism330dhcx_data { #ifdef CONFIG_ISM330DHCX_TRIGGER struct gpio_callback gpio_cb; sensor_trigger_handler_t handler_drdy_acc; + const struct sensor_trigger *trig_drdy_acc; sensor_trigger_handler_t handler_drdy_gyr; + const struct sensor_trigger *trig_drdy_gyr; sensor_trigger_handler_t handler_drdy_temp; + const struct sensor_trigger *trig_drdy_temp; #if defined(CONFIG_ISM330DHCX_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_ISM330DHCX_THREAD_STACK_SIZE); diff --git a/drivers/sensor/ism330dhcx/ism330dhcx_trigger.c b/drivers/sensor/ism330dhcx/ism330dhcx_trigger.c index 996d28e218e2..0500a4041973 100644 --- a/drivers/sensor/ism330dhcx/ism330dhcx_trigger.c +++ b/drivers/sensor/ism330dhcx/ism330dhcx_trigger.c @@ -135,6 +135,7 @@ int ism330dhcx_trigger_set(const struct device *dev, if (trig->chan == SENSOR_CHAN_ACCEL_XYZ) { ism330dhcx->handler_drdy_acc = handler; + ism330dhcx->trig_drdy_acc = trig; if (handler) { return ism330dhcx_enable_xl_int(dev, ISM330DHCX_EN_BIT); } else { @@ -142,6 +143,7 @@ int ism330dhcx_trigger_set(const struct device *dev, } } else if (trig->chan == SENSOR_CHAN_GYRO_XYZ) { ism330dhcx->handler_drdy_gyr = handler; + ism330dhcx->trig_drdy_gyr = trig; if (handler) { return ism330dhcx_enable_g_int(dev, ISM330DHCX_EN_BIT); } else { @@ -151,6 +153,7 @@ int ism330dhcx_trigger_set(const struct device *dev, #if defined(CONFIG_ISM330DHCX_ENABLE_TEMP) else if (trig->chan == SENSOR_CHAN_DIE_TEMP) { ism330dhcx->handler_drdy_temp = handler; + ism330dhcx->trig_drdy_temp = trig; if (handler) { return ism330dhcx_enable_t_int(dev, ISM330DHCX_EN_BIT); } else { @@ -169,9 +172,6 @@ int ism330dhcx_trigger_set(const struct device *dev, static void ism330dhcx_handle_interrupt(const struct device *dev) { struct ism330dhcx_data *ism330dhcx = dev->data; - struct sensor_trigger drdy_trigger = { - .type = SENSOR_TRIG_DATA_READY, - }; const struct ism330dhcx_config *cfg = dev->config; ism330dhcx_status_reg_t status; @@ -190,16 +190,16 @@ static void ism330dhcx_handle_interrupt(const struct device *dev) } if ((status.xlda) && (ism330dhcx->handler_drdy_acc != NULL)) { - ism330dhcx->handler_drdy_acc(dev, &drdy_trigger); + ism330dhcx->handler_drdy_acc(dev, ism330dhcx->trig_drdy_acc); } if ((status.gda) && (ism330dhcx->handler_drdy_gyr != NULL)) { - ism330dhcx->handler_drdy_gyr(dev, &drdy_trigger); + ism330dhcx->handler_drdy_gyr(dev, ism330dhcx->trig_drdy_gyr); } #if defined(CONFIG_ISM330DHCX_ENABLE_TEMP) if ((status.tda) && (ism330dhcx->handler_drdy_temp != NULL)) { - ism330dhcx->handler_drdy_temp(dev, &drdy_trigger); + ism330dhcx->handler_drdy_temp(dev, ism330dhcx->trig_drdy_temp); } #endif } From 0461ff22d5bec7701508b5eb4f149d5829922b4a Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 11:54:13 -0500 Subject: [PATCH 0706/1906] drivers: sensor: ite_vcmp_it8xxx2: Store sensor trigger as a pointer Fixes the ite_vcmp_it8xxx2 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/ite_vcmp_it8xxx2/vcmp_ite_it8xxx2.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/sensor/ite_vcmp_it8xxx2/vcmp_ite_it8xxx2.c b/drivers/sensor/ite_vcmp_it8xxx2/vcmp_ite_it8xxx2.c index 5a33cb9356df..2d3a04747c97 100644 --- a/drivers/sensor/ite_vcmp_it8xxx2/vcmp_ite_it8xxx2.c +++ b/drivers/sensor/ite_vcmp_it8xxx2/vcmp_ite_it8xxx2.c @@ -69,6 +69,7 @@ struct vcmp_it8xxx2_data { struct k_work work; /* Sensor trigger hanlder to notify user of assetion */ sensor_trigger_handler_t handler; + const struct sensor_trigger *trig; /* Pointer of voltage comparator device */ const struct device *vcmp; }; @@ -148,13 +149,9 @@ static void it8xxx2_vcmp_trigger_work_handler(struct k_work *item) { struct vcmp_it8xxx2_data *data = CONTAINER_OF(item, struct vcmp_it8xxx2_data, work); - struct sensor_trigger trigger = { - .type = SENSOR_TRIG_THRESHOLD, - .chan = SENSOR_CHAN_VOLTAGE - }; if (data->handler) { - data->handler(data->vcmp, &trigger); + data->handler(data->vcmp, data->trig); } } @@ -214,6 +211,7 @@ static int vcmp_ite_it8xxx2_trigger_set(const struct device *dev, } data->handler = handler; + data->trig = trig; vcmp_work_addr[config->vcmp_ch] = (uint32_t) &data->work; From 5bb2323435591284c24ed4f64e0b6a2751f19f92 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 11:59:18 -0500 Subject: [PATCH 0707/1906] drivers: sensor: lis2dh: Store sensor trigger as a pointer Fixes the lis2dh sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/lis2dh/lis2dh.h | 2 ++ drivers/sensor/lis2dh/lis2dh_trigger.c | 25 ++++++++++--------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/drivers/sensor/lis2dh/lis2dh.h b/drivers/sensor/lis2dh/lis2dh.h index eb5a1921ea68..72cc710ed9ec 100644 --- a/drivers/sensor/lis2dh/lis2dh.h +++ b/drivers/sensor/lis2dh/lis2dh.h @@ -257,7 +257,9 @@ struct lis2dh_data { struct gpio_callback gpio_int2_cb; sensor_trigger_handler_t handler_drdy; + const struct sensor_trigger *trig_drdy; sensor_trigger_handler_t handler_anymotion; + const struct sensor_trigger *trig_anymotion; atomic_t trig_flags; enum sensor_channel chan_drdy; diff --git a/drivers/sensor/lis2dh/lis2dh_trigger.c b/drivers/sensor/lis2dh/lis2dh_trigger.c index 494423049185..a30536f037a6 100644 --- a/drivers/sensor/lis2dh/lis2dh_trigger.c +++ b/drivers/sensor/lis2dh/lis2dh_trigger.c @@ -31,7 +31,8 @@ static inline void setup_int1(const struct device *dev, static int lis2dh_trigger_drdy_set(const struct device *dev, enum sensor_channel chan, - sensor_trigger_handler_t handler) + sensor_trigger_handler_t handler, + const struct sensor_trigger *trig) { const struct lis2dh_config *cfg = dev->config; struct lis2dh_data *lis2dh = dev->data; @@ -51,6 +52,7 @@ static int lis2dh_trigger_drdy_set(const struct device *dev, LIS2DH_EN_DRDY1_INT1, 0); lis2dh->handler_drdy = handler; + lis2dh->trig_drdy = trig; if ((handler == NULL) || (status < 0)) { return status; } @@ -126,7 +128,8 @@ static inline void setup_int2(const struct device *dev, } static int lis2dh_trigger_anym_set(const struct device *dev, - sensor_trigger_handler_t handler) + sensor_trigger_handler_t handler, + const struct sensor_trigger *trig) { const struct lis2dh_config *cfg = dev->config; struct lis2dh_data *lis2dh = dev->data; @@ -161,6 +164,7 @@ static int lis2dh_trigger_anym_set(const struct device *dev, ®_val); lis2dh->handler_anymotion = handler; + lis2dh->trig_anymotion = trig; if ((handler == NULL) || (status < 0)) { return status; } @@ -196,9 +200,9 @@ int lis2dh_trigger_set(const struct device *dev, { if (trig->type == SENSOR_TRIG_DATA_READY && trig->chan == SENSOR_CHAN_ACCEL_XYZ) { - return lis2dh_trigger_drdy_set(dev, trig->chan, handler); + return lis2dh_trigger_drdy_set(dev, trig->chan, handler, trig); } else if (trig->type == SENSOR_TRIG_DELTA) { - return lis2dh_trigger_anym_set(dev, handler); + return lis2dh_trigger_anym_set(dev, handler, trig); } return -ENOTSUP; @@ -352,13 +356,8 @@ static void lis2dh_thread_cb(const struct device *dev) if (cfg->gpio_drdy.port && atomic_test_and_clear_bit(&lis2dh->trig_flags, TRIGGED_INT1)) { - struct sensor_trigger drdy_trigger = { - .type = SENSOR_TRIG_DATA_READY, - .chan = lis2dh->chan_drdy, - }; - if (likely(lis2dh->handler_drdy != NULL)) { - lis2dh->handler_drdy(dev, &drdy_trigger); + lis2dh->handler_drdy(dev, lis2dh->trig_drdy); } @@ -375,10 +374,6 @@ static void lis2dh_thread_cb(const struct device *dev) if (cfg->gpio_int.port && atomic_test_and_clear_bit(&lis2dh->trig_flags, TRIGGED_INT2)) { - struct sensor_trigger anym_trigger = { - .type = SENSOR_TRIG_DELTA, - .chan = lis2dh->chan_drdy, - }; uint8_t reg_val; if (cfg->hw.anym_latch) { @@ -395,7 +390,7 @@ static void lis2dh_thread_cb(const struct device *dev) } if (likely(lis2dh->handler_anymotion != NULL)) { - lis2dh->handler_anymotion(dev, &anym_trigger); + lis2dh->handler_anymotion(dev, lis2dh->trig_anymotion); } /* Reactivate level triggered interrupt if handler did not From 281f61672b7094642829b2761a938b4a03832dee Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 12:00:43 -0500 Subject: [PATCH 0708/1906] drivers: sensor: lis2ds12: Store sensor trigger as a pointer Fixes the lis2ds12 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/lis2ds12/lis2ds12.h | 2 +- drivers/sensor/lis2ds12/lis2ds12_trigger.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/sensor/lis2ds12/lis2ds12.h b/drivers/sensor/lis2ds12/lis2ds12.h index 0bbccb294a92..1720f4ff228a 100644 --- a/drivers/sensor/lis2ds12/lis2ds12.h +++ b/drivers/sensor/lis2ds12/lis2ds12.h @@ -57,7 +57,7 @@ struct lis2ds12_data { #ifdef CONFIG_LIS2DS12_TRIGGER struct gpio_callback gpio_cb; - struct sensor_trigger data_ready_trigger; + const struct sensor_trigger *data_ready_trigger; sensor_trigger_handler_t data_ready_handler; const struct device *dev; diff --git a/drivers/sensor/lis2ds12/lis2ds12_trigger.c b/drivers/sensor/lis2ds12/lis2ds12_trigger.c index f03d8fccde94..11d55fe61ecd 100644 --- a/drivers/sensor/lis2ds12/lis2ds12_trigger.c +++ b/drivers/sensor/lis2ds12/lis2ds12_trigger.c @@ -42,7 +42,7 @@ static void lis2ds12_handle_drdy_int(const struct device *dev) struct lis2ds12_data *data = dev->data; if (data->data_ready_handler != NULL) { - data->data_ready_handler(dev, &data->data_ready_trigger); + data->data_ready_handler(dev, data->data_ready_trigger); } } @@ -203,7 +203,7 @@ int lis2ds12_trigger_set(const struct device *dev, /* re-trigger lost interrupt */ lis2ds12_acceleration_raw_get(ctx, raw); - data->data_ready_trigger = *trig; + data->data_ready_trigger = trig; lis2ds12_init_interrupt(dev); return gpio_pin_interrupt_configure_dt(&cfg->gpio_int, From 363b1876f8a534235eaa987c03ad9e9d7fac768e Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 12:01:45 -0500 Subject: [PATCH 0709/1906] drivers: sensor: lis2dw12: Store sensor trigger as a pointer Fixes the lis2dw12 sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/lis2dw12/lis2dw12.h | 5 +++ drivers/sensor/lis2dw12/lis2dw12_trigger.c | 40 ++++++---------------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/drivers/sensor/lis2dw12/lis2dw12.h b/drivers/sensor/lis2dw12/lis2dw12.h index 8672b2e813d3..ba61a764114d 100644 --- a/drivers/sensor/lis2dw12/lis2dw12.h +++ b/drivers/sensor/lis2dw12/lis2dw12.h @@ -113,15 +113,20 @@ struct lis2dw12_data { struct gpio_callback gpio_cb; sensor_trigger_handler_t drdy_handler; + const struct sensor_trigger *drdy_trig; #ifdef CONFIG_LIS2DW12_TAP sensor_trigger_handler_t tap_handler; + const struct sensor_trigger *tap_trig; sensor_trigger_handler_t double_tap_handler; + const struct sensor_trigger *double_tap_trig; #endif /* CONFIG_LIS2DW12_TAP */ #ifdef CONFIG_LIS2DW12_THRESHOLD sensor_trigger_handler_t threshold_handler; + const struct sensor_trigger *threshold_trig; #endif /* CONFIG_LIS2DW12_THRESHOLD */ #ifdef CONFIG_LIS2DW12_FREEFALL sensor_trigger_handler_t freefall_handler; + const struct sensor_trigger *freefall_trig; #endif /* CONFIG_LIS2DW12_FREEFALL */ #if defined(CONFIG_LIS2DW12_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_LIS2DW12_THREAD_STACK_SIZE); diff --git a/drivers/sensor/lis2dw12/lis2dw12_trigger.c b/drivers/sensor/lis2dw12/lis2dw12_trigger.c index 5fcf90a92ada..6dd7e456ca11 100644 --- a/drivers/sensor/lis2dw12/lis2dw12_trigger.c +++ b/drivers/sensor/lis2dw12/lis2dw12_trigger.c @@ -124,6 +124,7 @@ int lis2dw12_trigger_set(const struct device *dev, switch (trig->type) { case SENSOR_TRIG_DATA_READY: lis2dw12->drdy_handler = handler; + lis2dw12->drdy_trig = trig; if (state) { /* dummy read: re-trigger interrupt */ lis2dw12_acceleration_raw_get(ctx, raw); @@ -144,11 +145,13 @@ int lis2dw12_trigger_set(const struct device *dev, /* Set single TAP trigger */ if (trig->type == SENSOR_TRIG_TAP) { lis2dw12->tap_handler = handler; + lis2dw12->tap_trig = trig; return lis2dw12_enable_int(dev, SENSOR_TRIG_TAP, state); } /* Set double TAP trigger */ lis2dw12->double_tap_handler = handler; + lis2dw12->double_tap_trig = trig; return lis2dw12_enable_int(dev, SENSOR_TRIG_DOUBLE_TAP, state); #endif /* CONFIG_LIS2DW12_TAP */ #ifdef CONFIG_LIS2DW12_THRESHOLD @@ -156,6 +159,7 @@ int lis2dw12_trigger_set(const struct device *dev, { LOG_DBG("Set trigger %d (handler: %p)\n", trig->type, handler); lis2dw12->threshold_handler = handler; + lis2dw12->threshold_trig = trig; return lis2dw12_enable_int(dev, SENSOR_TRIG_THRESHOLD, state); } #endif @@ -163,6 +167,7 @@ int lis2dw12_trigger_set(const struct device *dev, case SENSOR_TRIG_FREEFALL: LOG_DBG("Set freefall %d (handler: %p)\n", trig->type, handler); lis2dw12->freefall_handler = handler; + lis2dw12->freefall_trig = trig; return lis2dw12_enable_int(dev, SENSOR_TRIG_FREEFALL, state); break; #endif /* CONFIG_LIS2DW12_FREEFALL */ @@ -176,13 +181,8 @@ static int lis2dw12_handle_drdy_int(const struct device *dev) { struct lis2dw12_data *data = dev->data; - struct sensor_trigger drdy_trig = { - .type = SENSOR_TRIG_DATA_READY, - .chan = SENSOR_CHAN_ALL, - }; - if (data->drdy_handler) { - data->drdy_handler(dev, &drdy_trig); + data->drdy_handler(dev, data->drdy_trig); } return 0; @@ -194,13 +194,8 @@ static int lis2dw12_handle_single_tap_int(const struct device *dev) struct lis2dw12_data *data = dev->data; sensor_trigger_handler_t handler = data->tap_handler; - struct sensor_trigger pulse_trig = { - .type = SENSOR_TRIG_TAP, - .chan = SENSOR_CHAN_ALL, - }; - if (handler) { - handler(dev, &pulse_trig); + handler(dev, data->tap_trig); } return 0; @@ -211,13 +206,8 @@ static int lis2dw12_handle_double_tap_int(const struct device *dev) struct lis2dw12_data *data = dev->data; sensor_trigger_handler_t handler = data->double_tap_handler; - struct sensor_trigger pulse_trig = { - .type = SENSOR_TRIG_DOUBLE_TAP, - .chan = SENSOR_CHAN_ALL, - }; - if (handler) { - handler(dev, &pulse_trig); + handler(dev, data->double_tap_trig); } return 0; @@ -230,13 +220,8 @@ static int lis2dw12_handle_wu_ia_int(const struct device *dev) struct lis2dw12_data *lis2dw12 = dev->data; sensor_trigger_handler_t handler = lis2dw12->threshold_handler; - struct sensor_trigger thresh_trig = { - .type = SENSOR_TRIG_THRESHOLD, - .chan = SENSOR_CHAN_ALL, - }; - if (handler) { - handler(dev, &thresh_trig); + handler(dev, lis2dw12->threshold_trig); } return 0; @@ -249,13 +234,8 @@ static int lis2dw12_handle_ff_ia_int(const struct device *dev) struct lis2dw12_data *lis2dw12 = dev->data; sensor_trigger_handler_t handler = lis2dw12->freefall_handler; - struct sensor_trigger freefall_trig = { - .type = SENSOR_TRIG_FREEFALL, - .chan = SENSOR_CHAN_ALL, - }; - if (handler) { - handler(dev, &freefall_trig); + handler(dev, lis2dw12->freefall_trig); } return 0; From 8cb81ff37151972f6327f3d0b1189327a745cc98 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 12:02:23 -0500 Subject: [PATCH 0710/1906] drivers: sensor: lis2mdl: Store sensor trigger as a pointer Fixes the lis2mdl sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/lis2mdl/lis2mdl.h | 1 + drivers/sensor/lis2mdl/lis2mdl_trigger.c | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/sensor/lis2mdl/lis2mdl.h b/drivers/sensor/lis2mdl/lis2mdl.h index e788eb4a58ab..2b5b04eb430f 100644 --- a/drivers/sensor/lis2mdl/lis2mdl.h +++ b/drivers/sensor/lis2mdl/lis2mdl.h @@ -56,6 +56,7 @@ struct lis2mdl_data { struct gpio_callback gpio_cb; sensor_trigger_handler_t handler_drdy; + const struct sensor_trigger *trig_drdy; #if defined(CONFIG_LIS2MDL_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_LIS2MDL_THREAD_STACK_SIZE); diff --git a/drivers/sensor/lis2mdl/lis2mdl_trigger.c b/drivers/sensor/lis2mdl/lis2mdl_trigger.c index c0eb1b37e1fd..b47039dd1685 100644 --- a/drivers/sensor/lis2mdl/lis2mdl_trigger.c +++ b/drivers/sensor/lis2mdl/lis2mdl_trigger.c @@ -45,6 +45,7 @@ int lis2mdl_trigger_set(const struct device *dev, if (trig->chan == SENSOR_CHAN_MAGN_XYZ) { lis2mdl->handler_drdy = handler; + lis2mdl->trig_drdy = trig; if (handler) { /* fetch raw data sample: re-trigger lost interrupt */ lis2mdl_magnetic_raw_get(ctx, raw); @@ -63,12 +64,9 @@ static void lis2mdl_handle_interrupt(const struct device *dev) { struct lis2mdl_data *lis2mdl = dev->data; const struct lis2mdl_config *const cfg = dev->config; - struct sensor_trigger drdy_trigger = { - .type = SENSOR_TRIG_DATA_READY, - }; if (lis2mdl->handler_drdy != NULL) { - lis2mdl->handler_drdy(dev, &drdy_trigger); + lis2mdl->handler_drdy(dev, lis2mdl->trig_drdy); } if (cfg->single_mode) { From 54433a961085ec42c3a3db70012a48da1b62b2ff Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 12:03:05 -0500 Subject: [PATCH 0711/1906] drivers: sensor: lis3mdl: Store sensor trigger as a pointer Fixes the lis3mdl sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/lis3mdl/lis3mdl.h | 2 +- drivers/sensor/lis3mdl/lis3mdl_trigger.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/sensor/lis3mdl/lis3mdl.h b/drivers/sensor/lis3mdl/lis3mdl.h index ca9f81706cc5..7b90fc3ac10c 100644 --- a/drivers/sensor/lis3mdl/lis3mdl.h +++ b/drivers/sensor/lis3mdl/lis3mdl.h @@ -119,7 +119,7 @@ struct lis3mdl_data { const struct device *dev; struct gpio_callback gpio_cb; - struct sensor_trigger data_ready_trigger; + const struct sensor_trigger *data_ready_trigger; sensor_trigger_handler_t data_ready_handler; #if defined(CONFIG_LIS3MDL_TRIGGER_OWN_THREAD) diff --git a/drivers/sensor/lis3mdl/lis3mdl_trigger.c b/drivers/sensor/lis3mdl/lis3mdl_trigger.c index 9b3f2d09616a..50cc2c64a43f 100644 --- a/drivers/sensor/lis3mdl/lis3mdl_trigger.c +++ b/drivers/sensor/lis3mdl/lis3mdl_trigger.c @@ -46,7 +46,7 @@ int lis3mdl_trigger_set(const struct device *dev, return 0; } - drv_data->data_ready_trigger = *trig; + drv_data->data_ready_trigger = trig; gpio_pin_interrupt_configure_dt(&config->irq_gpio, GPIO_INT_EDGE_TO_ACTIVE); @@ -79,7 +79,7 @@ static void lis3mdl_thread_cb(const struct device *dev) if (drv_data->data_ready_handler != NULL) { drv_data->data_ready_handler(dev, - &drv_data->data_ready_trigger); + drv_data->data_ready_trigger); } gpio_pin_interrupt_configure_dt(&config->irq_gpio, From 5354bffc6baa9518206b93dca5f6470a76db5e2f Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 12:03:49 -0500 Subject: [PATCH 0712/1906] drivers: sensor: lps22hh: Store sensor trigger as a pointer Fixes the lps22hh sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/lps22hh/lps22hh.h | 2 +- drivers/sensor/lps22hh/lps22hh_trigger.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/sensor/lps22hh/lps22hh.h b/drivers/sensor/lps22hh/lps22hh.h index da68a890b0a4..48f2d03200e7 100644 --- a/drivers/sensor/lps22hh/lps22hh.h +++ b/drivers/sensor/lps22hh/lps22hh.h @@ -60,7 +60,7 @@ struct lps22hh_data { #ifdef CONFIG_LPS22HH_TRIGGER struct gpio_callback gpio_cb; - struct sensor_trigger data_ready_trigger; + const struct sensor_trigger *data_ready_trigger; sensor_trigger_handler_t handler_drdy; const struct device *dev; diff --git a/drivers/sensor/lps22hh/lps22hh_trigger.c b/drivers/sensor/lps22hh/lps22hh_trigger.c index 09511a057a4e..9c9075a849ac 100644 --- a/drivers/sensor/lps22hh/lps22hh_trigger.c +++ b/drivers/sensor/lps22hh/lps22hh_trigger.c @@ -48,6 +48,7 @@ int lps22hh_trigger_set(const struct device *dev, if (trig->chan == SENSOR_CHAN_ALL) { lps22hh->handler_drdy = handler; + lps22hh->data_ready_trigger = trig; if (handler) { /* dummy read: re-trigger interrupt */ if (lps22hh_pressure_raw_get(ctx, &raw_press) < 0) { @@ -72,12 +73,9 @@ static void lps22hh_handle_interrupt(const struct device *dev) int ret; struct lps22hh_data *lps22hh = dev->data; const struct lps22hh_config *cfg = dev->config; - struct sensor_trigger drdy_trigger = { - .type = SENSOR_TRIG_DATA_READY, - }; if (lps22hh->handler_drdy != NULL) { - lps22hh->handler_drdy(dev, &drdy_trigger); + lps22hh->handler_drdy(dev, lps22hh->data_ready_trigger); } #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i3c) From 1157df85a75d3f1749206245b02ca9dbbb3bdfa0 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 12:04:26 -0500 Subject: [PATCH 0713/1906] drivers: sensor: lsm6dsl: Store sensor trigger as a pointer Fixes the lsm6dsl sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/lsm6dsl/lsm6dsl.h | 2 +- drivers/sensor/lsm6dsl/lsm6dsl_trigger.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/sensor/lsm6dsl/lsm6dsl.h b/drivers/sensor/lsm6dsl/lsm6dsl.h index 1f6dc47485ef..b36781083b87 100644 --- a/drivers/sensor/lsm6dsl/lsm6dsl.h +++ b/drivers/sensor/lsm6dsl/lsm6dsl.h @@ -675,7 +675,7 @@ struct lsm6dsl_data { const struct device *dev; struct gpio_callback gpio_cb; - struct sensor_trigger data_ready_trigger; + const struct sensor_trigger *data_ready_trigger; sensor_trigger_handler_t data_ready_handler; #if defined(CONFIG_LSM6DSL_TRIGGER_OWN_THREAD) diff --git a/drivers/sensor/lsm6dsl/lsm6dsl_trigger.c b/drivers/sensor/lsm6dsl/lsm6dsl_trigger.c index 26c4a8e5feab..8bf04c1b3b61 100644 --- a/drivers/sensor/lsm6dsl/lsm6dsl_trigger.c +++ b/drivers/sensor/lsm6dsl/lsm6dsl_trigger.c @@ -63,7 +63,7 @@ int lsm6dsl_trigger_set(const struct device *dev, return 0; } - drv_data->data_ready_trigger = *trig; + drv_data->data_ready_trigger = trig; setup_irq(dev, true); if (gpio_pin_get_dt(&config->int_gpio) > 0) { @@ -90,7 +90,7 @@ static void lsm6dsl_thread_cb(const struct device *dev) if (drv_data->data_ready_handler != NULL) { drv_data->data_ready_handler(dev, - &drv_data->data_ready_trigger); + drv_data->data_ready_trigger); } setup_irq(dev, true); From 0d4f0deaadd582ac84f2d63a94ab303b5fd94d1d Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 12:05:11 -0500 Subject: [PATCH 0714/1906] drivers: sensor: lsm6dso: Store sensor trigger as a pointer Fixes the lsm6dso sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/lsm6dso/lsm6dso.h | 3 +++ drivers/sensor/lsm6dso/lsm6dso_trigger.c | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/sensor/lsm6dso/lsm6dso.h b/drivers/sensor/lsm6dso/lsm6dso.h index 76eceac3ad03..bc28f32db47a 100644 --- a/drivers/sensor/lsm6dso/lsm6dso.h +++ b/drivers/sensor/lsm6dso/lsm6dso.h @@ -107,8 +107,11 @@ struct lsm6dso_data { #ifdef CONFIG_LSM6DSO_TRIGGER struct gpio_callback gpio_cb; sensor_trigger_handler_t handler_drdy_acc; + const struct sensor_trigger *trig_drdy_acc; sensor_trigger_handler_t handler_drdy_gyr; + const struct sensor_trigger *trig_drdy_gyr; sensor_trigger_handler_t handler_drdy_temp; + const struct sensor_trigger *trig_drdy_temp; #if defined(CONFIG_LSM6DSO_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_LSM6DSO_THREAD_STACK_SIZE); diff --git a/drivers/sensor/lsm6dso/lsm6dso_trigger.c b/drivers/sensor/lsm6dso/lsm6dso_trigger.c index 3a89f200bc0f..6a84305fd8f8 100644 --- a/drivers/sensor/lsm6dso/lsm6dso_trigger.c +++ b/drivers/sensor/lsm6dso/lsm6dso_trigger.c @@ -135,6 +135,7 @@ int lsm6dso_trigger_set(const struct device *dev, if (trig->chan == SENSOR_CHAN_ACCEL_XYZ) { lsm6dso->handler_drdy_acc = handler; + lsm6dso->trig_drdy_acc = trig; if (handler) { return lsm6dso_enable_xl_int(dev, LSM6DSO_EN_BIT); } else { @@ -142,6 +143,7 @@ int lsm6dso_trigger_set(const struct device *dev, } } else if (trig->chan == SENSOR_CHAN_GYRO_XYZ) { lsm6dso->handler_drdy_gyr = handler; + lsm6dso->trig_drdy_gyr = trig; if (handler) { return lsm6dso_enable_g_int(dev, LSM6DSO_EN_BIT); } else { @@ -151,6 +153,7 @@ int lsm6dso_trigger_set(const struct device *dev, #if defined(CONFIG_LSM6DSO_ENABLE_TEMP) else if (trig->chan == SENSOR_CHAN_DIE_TEMP) { lsm6dso->handler_drdy_temp = handler; + lsm6dso->trig_drdy_temp = trig; if (handler) { return lsm6dso_enable_t_int(dev, LSM6DSO_EN_BIT); } else { @@ -169,9 +172,6 @@ int lsm6dso_trigger_set(const struct device *dev, static void lsm6dso_handle_interrupt(const struct device *dev) { struct lsm6dso_data *lsm6dso = dev->data; - struct sensor_trigger drdy_trigger = { - .type = SENSOR_TRIG_DATA_READY, - }; const struct lsm6dso_config *cfg = dev->config; stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; lsm6dso_status_reg_t status; @@ -191,16 +191,16 @@ static void lsm6dso_handle_interrupt(const struct device *dev) } if ((status.xlda) && (lsm6dso->handler_drdy_acc != NULL)) { - lsm6dso->handler_drdy_acc(dev, &drdy_trigger); + lsm6dso->handler_drdy_acc(dev, lsm6dso->trig_drdy_acc); } if ((status.gda) && (lsm6dso->handler_drdy_gyr != NULL)) { - lsm6dso->handler_drdy_gyr(dev, &drdy_trigger); + lsm6dso->handler_drdy_gyr(dev, lsm6dso->trig_drdy_gyr); } #if defined(CONFIG_LSM6DSO_ENABLE_TEMP) if ((status.tda) && (lsm6dso->handler_drdy_temp != NULL)) { - lsm6dso->handler_drdy_temp(dev, &drdy_trigger); + lsm6dso->handler_drdy_temp(dev, lsm6dso->trig_drdy_temp); } #endif } From 59fe77a6b4a17f18378b0c409fc178e230b45faf Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 22 Mar 2023 12:05:58 -0500 Subject: [PATCH 0715/1906] drivers: sensor: lsm9ds0_gyro: Store sensor trigger as a pointer Fixes the lsm9ds0_gyro sensor driver to store the user-supplied sensor trigger as a pointer rather than a copy. This enables the trigger handler to use CONTAINER_OF to retrieve a context pointer when the trigger is embedded in a larger struct. Signed-off-by: Maureen Helm --- drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.h | 2 +- drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro_trigger.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.h b/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.h index 7bfb825bd14a..bcdfcf615408 100644 --- a/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.h +++ b/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.h @@ -230,7 +230,7 @@ struct lsm9ds0_gyro_data { const struct device *dev; struct gpio_callback gpio_cb; - struct sensor_trigger trigger_drdy; + const struct sensor_trigger *trigger_drdy; sensor_trigger_handler_t handler_drdy; #endif diff --git a/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro_trigger.c b/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro_trigger.c index 54270560d81a..fea1e5e4c5a5 100644 --- a/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro_trigger.c +++ b/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro_trigger.c @@ -52,7 +52,7 @@ int lsm9ds0_gyro_trigger_set(const struct device *dev, } data->handler_drdy = handler; - data->trigger_drdy = *trig; + data->trigger_drdy = trig; if (i2c_reg_update_byte_dt(&config->i2c, LSM9DS0_GYRO_REG_CTRL_REG3_G, LSM9DS0_GYRO_MASK_CTRL_REG3_G_I2_DRDY, @@ -88,7 +88,7 @@ static void lsm9ds0_gyro_thread_main(const struct device *dev) k_sem_take(&data->sem, K_FOREVER); if (data->handler_drdy) { - data->handler_drdy(dev, &data->trigger_drdy); + data->handler_drdy(dev, data->trigger_drdy); } setup_drdy(dev, true); From 95168e6776d6c8803a5e1f3ed10e1a8b6bc98311 Mon Sep 17 00:00:00 2001 From: Jaska Uimonen Date: Wed, 1 Mar 2023 08:13:48 +0200 Subject: [PATCH 0716/1906] soc: intel_adsp: cavs: start using zephyr power management Start using zephyr power management in cavs platform in a similar way that is already done in ace. This commit only addresses the power off/on sequence. Runtime power management is not implemented. Signed-off-by: Jaska Uimonen --- dts/xtensa/intel/intel_adsp_cavs25.dtsi | 16 ++ dts/xtensa/intel/intel_adsp_cavs25_tgph.dtsi | 14 ++ soc/xtensa/intel_adsp/cavs/CMakeLists.txt | 1 + .../intel_adsp/cavs/asm_ldo_management.h | 108 ++++++++++++ .../intel_adsp/cavs/asm_memory_management.h | 76 +++++++++ soc/xtensa/intel_adsp/cavs/power.c | 81 +++++++++ soc/xtensa/intel_adsp/cavs/power_down_cavs.S | 157 ++++++++++++++++++ 7 files changed, 453 insertions(+) create mode 100644 soc/xtensa/intel_adsp/cavs/asm_ldo_management.h create mode 100644 soc/xtensa/intel_adsp/cavs/asm_memory_management.h create mode 100644 soc/xtensa/intel_adsp/cavs/power_down_cavs.S diff --git a/dts/xtensa/intel/intel_adsp_cavs25.dtsi b/dts/xtensa/intel/intel_adsp_cavs25.dtsi index 0a199dd17e4f..c904f9a89f80 100644 --- a/dts/xtensa/intel/intel_adsp_cavs25.dtsi +++ b/dts/xtensa/intel/intel_adsp_cavs25.dtsi @@ -16,6 +16,7 @@ device_type = "cpu"; compatible = "cdns,tensilica-xtensa-lx6"; reg = <0>; + cpu-power-states = <&d3>; i-cache-line-size = <64>; d-cache-line-size = <64>; }; @@ -24,18 +25,33 @@ device_type = "cpu"; compatible = "cdns,tensilica-xtensa-lx6"; reg = <1>; + cpu-power-states = <&d3>; }; cpu2: cpu@2 { device_type = "cpu"; compatible = "cdns,tensilica-xtensa-lx6"; reg = <2>; + cpu-power-states = <&d3>; }; cpu3: cpu@3 { device_type = "cpu"; compatible = "cdns,tensilica-xtensa-lx6"; reg = <3>; + cpu-power-states = <&d3>; + }; + }; + + power-states { + /* PM_STATE_SOFT_OFF can be entered only by calling pm_state_force. + * The procedure is triggered by IPC from the HOST (SET_DX). + */ + d3: off { + compatible = "zephyr,power-state"; + power-state-name = "soft-off"; + min-residency-us = <2147483647>; + exit-latency-us = <0>; }; }; diff --git a/dts/xtensa/intel/intel_adsp_cavs25_tgph.dtsi b/dts/xtensa/intel/intel_adsp_cavs25_tgph.dtsi index 205574193676..246c026f7446 100644 --- a/dts/xtensa/intel/intel_adsp_cavs25_tgph.dtsi +++ b/dts/xtensa/intel/intel_adsp_cavs25_tgph.dtsi @@ -16,6 +16,7 @@ device_type = "cpu"; compatible = "cdns,tensilica-xtensa-lx6"; reg = <0>; + cpu-power-states = <&d3>; i-cache-line-size = <64>; d-cache-line-size = <64>; }; @@ -24,6 +25,19 @@ device_type = "cpu"; compatible = "cdns,tensilica-xtensa-lx6"; reg = <1>; + cpu-power-states = <&d3>; + }; + }; + + power-states { + /* PM_STATE_SOFT_OFF can be entered only by calling pm_state_force. + * The procedure is triggered by IPC from the HOST (SET_DX). + */ + d3: off { + compatible = "zephyr,power-state"; + power-state-name = "soft-off"; + min-residency-us = <2147483647>; + exit-latency-us = <0>; }; }; diff --git a/soc/xtensa/intel_adsp/cavs/CMakeLists.txt b/soc/xtensa/intel_adsp/cavs/CMakeLists.txt index a691ba31363b..2a0cbdc463c6 100644 --- a/soc/xtensa/intel_adsp/cavs/CMakeLists.txt +++ b/soc/xtensa/intel_adsp/cavs/CMakeLists.txt @@ -9,6 +9,7 @@ zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) zephyr_library_sources( sram.c power.c + power_down_cavs.S ) if(CONFIG_SMP OR CONFIG_MP_MAX_NUM_CPUS GREATER 1) diff --git a/soc/xtensa/intel_adsp/cavs/asm_ldo_management.h b/soc/xtensa/intel_adsp/cavs/asm_ldo_management.h new file mode 100644 index 000000000000..4ac6b378a080 --- /dev/null +++ b/soc/xtensa/intel_adsp/cavs/asm_ldo_management.h @@ -0,0 +1,108 @@ +/* Copyright (c) 2023 Intel Corporation + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __ZEPHYR_CAVS_LIB_ASM_LDO_MANAGEMENT_H__ +#define __ZEPHYR_CAVS_LIB_ASM_LDO_MANAGEMENT_H__ + +#ifdef _ASMLANGUAGE + +#define SHIM_BASE 0x00071F00 +#define SHIM_LDOCTL 0xA4 +#define SHIM_LDOCTL_HPSRAM_MASK (3 << 0 | 3 << 16) +#define SHIM_LDOCTL_LPSRAM_MASK (3 << 2) +#define SHIM_LDOCTL_HPSRAM_LDO_ON (3 << 0 | 3 << 16) +#define SHIM_LDOCTL_LPSRAM_LDO_ON (3 << 2) +#define SHIM_LDOCTL_HPSRAM_LDO_OFF (0 << 0) +#define SHIM_LDOCTL_LPSRAM_LDO_OFF (0 << 2) +#define SHIM_LDOCTL_HPSRAM_LDO_BYPASS (BIT(0) | BIT(16)) +#define SHIM_LDOCTL_LPSRAM_LDO_BYPASS BIT(2) + +.macro m_cavs_set_ldo_state state, ax +movi \ax, (SHIM_BASE + SHIM_LDOCTL) +s32i \state, \ax, 0 +memw +/* wait loop > 300ns (min 100ns required) */ +movi \ax, 128 +1 : +addi \ax, \ax, -1 +nop +bnez \ax, 1b +.endm + +.macro m_cavs_set_hpldo_state state, ax, ay +movi \ax, (SHIM_BASE + SHIM_LDOCTL) +l32i \ay, \ax, 0 + +movi \ax, ~(SHIM_LDOCTL_HPSRAM_MASK) +and \ay, \ax, \ay +or \state, \ay, \state + +m_cavs_set_ldo_state \state, \ax +.endm + +.macro m_cavs_set_lpldo_state state, ax, ay +movi \ax, (SHIM_BASE + SHIM_LDOCTL) +l32i \ay, \ax, 0 +/* LP SRAM mask */ +movi \ax, ~(SHIM_LDOCTL_LPSRAM_MASK) +and \ay, \ax, \ay +or \state, \ay, \state + +m_cavs_set_ldo_state \state, \ax +.endm + +.macro m_cavs_set_ldo_on_state ax, ay, az +movi \ay, (SHIM_BASE + SHIM_LDOCTL) +l32i \az, \ay, 0 + +movi \ax, ~(SHIM_LDOCTL_HPSRAM_MASK | SHIM_LDOCTL_LPSRAM_MASK) +and \az, \ax, \az +movi \ax, (SHIM_LDOCTL_HPSRAM_LDO_ON | SHIM_LDOCTL_LPSRAM_LDO_ON) +or \ax, \az, \ax + +m_cavs_set_ldo_state \ax, \ay +.endm + +.macro m_cavs_set_ldo_off_state ax, ay, az +/* wait loop > 300ns (min 100ns required) */ +movi \ax, 128 +1 : + addi \ax, \ax, -1 + nop + bnez \ax, 1b +movi \ay, (SHIM_BASE + SHIM_LDOCTL) +l32i \az, \ay, 0 + +movi \ax, ~(SHIM_LDOCTL_HPSRAM_MASK | SHIM_LDOCTL_LPSRAM_MASK) +and \az, \az, \ax + +movi \ax, (SHIM_LDOCTL_HPSRAM_LDO_OFF | SHIM_LDOCTL_LPSRAM_LDO_OFF) +or \ax, \ax, \az + +s32i \ax, \ay, 0 +l32i \ax, \ay, 0 +.endm + +.macro m_cavs_set_ldo_bypass_state ax, ay, az +/* wait loop > 300ns (min 100ns required) */ +movi \ax, 128 +1 : + addi \ax, \ax, -1 + nop + bnez \ax, 1b +movi \ay, (SHIM_BASE + SHIM_LDOCTL) +l32i \az, \ay, 0 + +movi \ax, ~(SHIM_LDOCTL_HPSRAM_MASK | SHIM_LDOCTL_LPSRAM_MASK) +and \az, \az, \ax + +movi \ax, (SHIM_LDOCTL_HPSRAM_LDO_BYPASS | SHIM_LDOCTL_LPSRAM_LDO_BYPASS) +or \ax, \ax, \az + +s32i \ax, \ay, 0 +l32i \ax, \ay, 0 +.endm + +#endif +#endif /* __ZEPHYR_CAVS_LIB_ASM_LDO_MANAGEMENT_H__ */ diff --git a/soc/xtensa/intel_adsp/cavs/asm_memory_management.h b/soc/xtensa/intel_adsp/cavs/asm_memory_management.h new file mode 100644 index 000000000000..1b247094fb04 --- /dev/null +++ b/soc/xtensa/intel_adsp/cavs/asm_memory_management.h @@ -0,0 +1,76 @@ +/* Copyright (c) 2023 Intel Corporation + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __ZEPHYR_CAVS_LIB_ASM_MEMORY_MANAGEMENT_H__ +#define __ZEPHYR_CAVS_LIB_ASM_MEMORY_MANAGEMENT_H__ + +#ifdef _ASMLANGUAGE + +#define HSPGCTL0 0x71D10 +#define HSRMCTL0 0x71D14 +#define HSPGISTS0 0x71D18 + +#define LSPGCTL 0x71D50 +#define LSRMCTL 0x71D54 +#define LSPGISTS 0x71D58 + +#define SHIM_HSPGCTL(x) (HSPGCTL0 + 0x10 * (x)) +#define SHIM_HSPGISTS(x) (HSPGISTS0 + 0x10 * (x)) + +#define LPSRAM_MASK 0x1 +/** + * Macro powers down entire HPSRAM. On entry literals and code for section from + * where this code is executed need to be placed in memory which is not + * HPSRAM (in case when this code is located in HPSRAM, lock memory in L1$ or + * L1 SRAM) + */ +.macro m_cavs_hpsram_power_down_entire ax, ay, az + /* SEGMENT #0 */ + movi \az, SHIM_HSPGCTL(0) + movi \ax, SHIM_HSPGISTS(0) + movi \ay, 0x1FFFFFFF /* HPSRAM_MASK(0) */ + s32i \ay, \ax, 0 + memw +1 : + l32i \ax, \az, 0 + bne \ax, \ay, 1b + + /* SEGMENT #1 */ + movi \az, SHIM_HSPGCTL(1) + movi \ax, SHIM_HSPGISTS(1) + movi \ay, 0x0FFFFFFF /* HPSRAM_MASK(1) */ + s32i \ay, \ax, 0 + memw +1 : + l32i \ax, \az, 0 + bne \ax, \ay, 1b +.endm + +.macro m_cavs_hpsram_power_change segment_index, mask, ax, ay, az + movi \ax, SHIM_HSPGCTL(\segment_index) + movi \ay, SHIM_HSPGISTS(\segment_index) + s32i \mask, \ax, 0 + memw + /* assumed that HDA shared dma buffer will be in LPSRAM */ +1 : + l32i \ax, \ay, 0 + bne \ax, \mask, 1b +.endm + +.macro m_cavs_lpsram_power_down_entire ax, ay, az, loop_cnt_addr + movi \az, LSPGISTS + movi \ax, LSPGCTL + movi \ay, LPSRAM_MASK + s32i \ay, \ax, 0 + memw + /* assumed that HDA shared dma buffer will be in LPSRAM */ + movi \ax, \loop_cnt_addr + l32i \ax, \ax, 0 +1 : + addi \ax, \ax, -1 + bnez \ax, 1b +.endm + +#endif +#endif diff --git a/soc/xtensa/intel_adsp/cavs/power.c b/soc/xtensa/intel_adsp/cavs/power.c index ce4e20695004..df0f4eed8ce7 100644 --- a/soc/xtensa/intel_adsp/cavs/power.c +++ b/soc/xtensa/intel_adsp/cavs/power.c @@ -10,6 +10,9 @@ #include #include #include +#include +#include +#include #include #include @@ -32,6 +35,84 @@ LOG_MODULE_REGISTER(soc); #endif +#ifdef CONFIG_PM + +#define SRAM_ALIAS_BASE 0x9E000000 +#define SRAM_ALIAS_MASK 0xFF000000 +#define EBB_BANKS_IN_SEGMENT 32 +#define SRAM_ALIAS_OFFSET 0x20000000 + +#define L2_INTERRUPT_NUMBER 4 +#define L2_INTERRUPT_MASK (1<= 0; + * --seg_index) { + * cavs_hpsram_power_change(seg_index, mask[seg_index]); + * } + * where mask is given in pu32_hpsram_mask register + */ + + .set seg_index, MAX_MEMORY_SEGMENTS - 1 + .rept MAX_MEMORY_SEGMENTS + l32i temp_reg0, pu32_hpsram_mask, 4 * seg_index + m_cavs_hpsram_power_change\ + /*segment_index=*/ seg_index,\ + /*mask=*/ temp_reg0,\ + temp_reg1,\ + temp_reg2,\ + temp_reg3 + .set seg_index, seg_index - 1 + .endr + + +/* mandatory sequence for LDO OFF - effectively executes: + * WAIT_300NS(); + * m_cavs_set_ldo_hpsram_on_state() + */ + movi temp_reg0, 128 +1 : + addi temp_reg0, temp_reg0, -1 + bnez temp_reg0, 1b + + movi temp_reg0, SHIM_LDOCTL_HPSRAM_LDO_OFF + m_cavs_set_hpldo_state temp_reg0, temp_reg1, temp_reg2 + +_PD_SEND_IPC: +/* Send IPC reply for SET_DX message */ + movi temp_reg1, 0 + s32i temp_reg1, host_base, IPC_DIPCIDD + + movi temp_reg1, set_dx_reply + l32i temp_reg1, temp_reg1, 0 + s32i temp_reg1, host_base, IPC_DIPCIDR + +_PD_SLEEP: +/* effecfively executes: + * xmp_spin() + * waiti 5 + */ + movi temp_reg0, 128 +loop: + addi temp_reg0, temp_reg0, -1 + bnez temp_reg0, loop + + extw + extw + waiti 5 + 1: + j 1b + +.size power_down_cavs , . - power_down_cavs + + From 7ad7402f8e7cc53ca7875c27dc55dfa7a9ebb063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Wed, 22 Mar 2023 09:43:28 +0100 Subject: [PATCH 0717/1906] Bluetooth: Mesh: Change rpr cli @defgroup name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the documentation @defgroup tag for RPR client, as it does not align with other parts of the RPR implementation. Signed-off-by: Anders Storrø --- include/zephyr/bluetooth/mesh/rpr_cli.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zephyr/bluetooth/mesh/rpr_cli.h b/include/zephyr/bluetooth/mesh/rpr_cli.h index fc1ed27707c7..ad7e9e1b7ee4 100644 --- a/include/zephyr/bluetooth/mesh/rpr_cli.h +++ b/include/zephyr/bluetooth/mesh/rpr_cli.h @@ -6,7 +6,7 @@ /** * @file - * @defgroup bt_mesh_pbr_cli Remote Provisioning Client model + * @defgroup bt_mesh_rpr_cli Remote Provisioning Client model * @{ * @brief API For Remote Provisioning Client model * From 09a32928aad9ecef13aaf7ea29d7054edc4338fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Wed, 22 Mar 2023 09:43:29 +0100 Subject: [PATCH 0718/1906] Bluetooth: Mesh: RPR cli @ mod elem 0 check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add check to the Remote Provisioning Client model init call that verifies that the model is located at the root element. Signed-off-by: Anders Storrø --- subsys/bluetooth/mesh/rpr_cli.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subsys/bluetooth/mesh/rpr_cli.c b/subsys/bluetooth/mesh/rpr_cli.c index 40b4cf51362c..da5fe39c513a 100644 --- a/subsys/bluetooth/mesh/rpr_cli.c +++ b/subsys/bluetooth/mesh/rpr_cli.c @@ -372,6 +372,12 @@ static void link_timeout(struct k_work *work) static int rpr_cli_init(struct bt_mesh_model *mod) { + if (mod->elem_idx) { + LOG_ERR("Remote provisioning client must be initialized " + "on first element"); + return -EINVAL; + } + struct bt_mesh_rpr_cli *cli = mod->user_data; cli->mod = mod; From 2356195ae77dd0d7044044aa67c2298380346a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Storr=C3=B8?= Date: Wed, 22 Mar 2023 09:44:21 +0100 Subject: [PATCH 0719/1906] Doc: Bluetooth: Mesh: Add RPR docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds documentation for the Remote provisioning server and client models. Signed-off-by: Anders Storrø --- .../bluetooth/api/mesh/models.rst | 2 + .../bluetooth/api/mesh/rpr_cli.rst | 132 ++++++++++++++++++ .../bluetooth/api/mesh/rpr_srv.rst | 30 ++++ 3 files changed, 164 insertions(+) create mode 100644 doc/connectivity/bluetooth/api/mesh/rpr_cli.rst create mode 100644 doc/connectivity/bluetooth/api/mesh/rpr_srv.rst diff --git a/doc/connectivity/bluetooth/api/mesh/models.rst b/doc/connectivity/bluetooth/api/mesh/models.rst index cbc649674629..85453a788082 100644 --- a/doc/connectivity/bluetooth/api/mesh/models.rst +++ b/doc/connectivity/bluetooth/api/mesh/models.rst @@ -20,6 +20,8 @@ used by network administrators to configure and diagnose mesh nodes. priv_beacon_cli op_agg_cli op_agg_srv + rpr_cli + rpr_srv srpl od diff --git a/doc/connectivity/bluetooth/api/mesh/rpr_cli.rst b/doc/connectivity/bluetooth/api/mesh/rpr_cli.rst new file mode 100644 index 000000000000..38cb8849f9e5 --- /dev/null +++ b/doc/connectivity/bluetooth/api/mesh/rpr_cli.rst @@ -0,0 +1,132 @@ +.. _bluetooth_mesh_models_rpr_cli: + +Remote Provisioning Client +########################## + +The Remote Provisioning Client model is a foundation model defined by the Bluetooth +mesh specification. It is enabled with the +:kconfig:option:`CONFIG_BT_MESH_RPR_CLI` option. + +The Remote Provisioning Client model is introduced in the Bluetooth Mesh Protocol +Specification version 1.1. +This model provides functionality to remotely provision devices into a mesh network, and perform Node Provisioning Protocol Interface procedures by interacting with mesh nodes that support the :ref:`bluetooth_mesh_models_rpr_srv` model. + +The Remote Provisioning Client model communicates with a Remote Provisioning Server model +using the device key of the node containing the target Remote Provisioning Server model instance. + +If present, the Remote Provisioning Client model must be instantiated on the primary +element. + +Scanning +******** + +The scanning procedure is used to scan for unprovisioned devices located nearby the Remote Provisioning Server. The Remote Provisioning Client starts a scan procedure by using the :c:func:`bt_mesh_rpr_scan_start` call: + +.. code-block:: C + + static void rpr_scan_report(struct bt_mesh_rpr_cli *cli, + const struct bt_mesh_rpr_node *srv, + struct bt_mesh_rpr_unprov *unprov, + struct net_buf_simple *adv_data) + { + + } + + struct bt_mesh_rpr_cli rpr_cli = { + .scan_report = rpr_scan_report, + }; + + const struct bt_mesh_rpr_node srv = { + .addr = 0x0004, + .net_idx = 0, + .ttl = BT_MESH_TTL_DEFAULT, + }; + + struct bt_mesh_rpr_scan_status status; + uint8_t *uuid = NULL; + uint8_t timeout = 10; + uint8_t max_devs = 3; + + bt_mesh_rpr_scan_start(&rpr_cli, &srv, uuid, timeout, max_devs, &status); + +The above example shows pseudo code for starting a scan procedure on the target Remote Provisioning Server node. This +procedure will start a ten-second, multiple-device scanning where the generated scan report will contain +a maximum of three unprovisioned devices. If the UUID argument was specified, the same procedure would +only scan for the device with the corresponding UUID. After the procedure completes, the +server sends the scan report that will be handled in the client's :c:member:`bt_mesh_rpr_cli.scan_report` callback. + +Additionally, the Remote Provisioning Client model also supports extended scanning with the +:c:func:`bt_mesh_rpr_scan_start_ext` call. Extended scanning supplements regular scanning by allowing the +Remote Provisioning Server to report additional data for a specific device. The Remote Provisioning Server will use active scanning to request +a scan response from the unprovisioned device if it is supported by the unprovisioned device. + +Provisioning +************ + +The Remote Provisioning Client starts a provisioning procedure by using the :c:func:`bt_mesh_provision_remote` call: + +.. code-block:: C + + struct bt_mesh_rpr_cli rpr_cli; + + const struct bt_mesh_rpr_node srv = { + .addr = 0x0004, + .net_idx = 0, + .ttl = BT_MESH_TTL_DEFAULT, + }; + + uint8_t uuid[16] = { 0xaa }; + uint16_t addr = 0x0006; + uint16_t net_idx = 0; + + bt_mesh_provision_remote(&rpr_cli, &srv, uuid, net_idx, addr); + +The above example shows pseudo code for remotely provisioning a device through a Remote Provisioning Server node. This +procedure will attempt to provision the device with the corresponding UUID, and assign the address 0x0006 +to its primary element using the network key located at index zero. + +.. note:: + During the remote provisioning, the same :c:struct:`bt_mesh_prov` callbacks are triggered as for ordinary + provisioning. See section :ref:`bluetooth_mesh_provisioning` for further details. + +Re-provisioning +*************** + +In addition to scanning and provisioning functionality, the Remote Provisioning Client also provides means to +reconfigure node addresses, device keys and Composition Data on devices that support the +:ref:`bluetooth_mesh_models_rpr_srv` model. This is provided through the Node Provisioning Protocol Interface +(NPPI) which supports the following three procedures: + +* Device Key Refresh procedure: Used to change the device key of the Target node without a need to reconfigure the node. +* Node Address Refresh procedure: Used to change the node’s device key and unicast address. +* Node Composition Refresh procedure: Used to change the device key of the node, and to add or delete models or features of the node. + +The three NPPI procedures can be initiated with the :c:func:`bt_mesh_reprovision_remote` call: + +.. code-block:: C + + struct bt_mesh_rpr_cli rpr_cli; + struct bt_mesh_rpr_node srv = { + .addr = 0x0006, + .net_idx = 0, + .ttl = BT_MESH_TTL_DEFAULT, + }; + + bool composition_changed = false; + uint16_t new_addr = 0x0009; + + bt_mesh_reprovision_remote(&rpr_cli, &srv, new_addr, composition_changed); + +The above example shows pseudo code for triggering a Node Address Refresh procedure on the Target node. +The specific procedure is not chosen directly, but rather through the other parameters that are inputted. +In the example we can see that the current unicast address of the Target is 0x0006, while the new address is +set to 0x0009. If the two addresses were the same, and the ``composition_changed`` flag was set to true, this code +would instead trigger a Node Composition Refresh procedure. If the two addresses were the same, and +the ``composition_changed`` flag was set to false, this code would trigger a Device Key Refresh procedure. + +API reference +************* + +.. doxygengroup:: bt_mesh_rpr_cli + :project: Zephyr + :members: diff --git a/doc/connectivity/bluetooth/api/mesh/rpr_srv.rst b/doc/connectivity/bluetooth/api/mesh/rpr_srv.rst new file mode 100644 index 000000000000..f958ef31bd93 --- /dev/null +++ b/doc/connectivity/bluetooth/api/mesh/rpr_srv.rst @@ -0,0 +1,30 @@ +.. _bluetooth_mesh_models_rpr_srv: + +Remote Provisioning Server +########################## + +The Remote Provisioning Server model is a foundation model defined by the Bluetooth +mesh specification. It is enabled with the +:kconfig:option:`CONFIG_BT_MESH_RPR_SRV` option. + +The Remote Provisioning Server model is introduced in the Bluetooth Mesh Protocol +Specification version 1.1, and is used to support the functionality of remotely +provisioning devices into a mesh network. + +The Remote Provisioning Server does not have an API of its own, but relies on a +:ref:`bluetooth_mesh_models_rpr_cli` to control it. The Remote Provisioning Server +model only accepts messages encrypted with the node's device key. + +If present, the Remote Provisioning Server model must be instantiated on the primary +element. + +Note that after refreshing the device key, node address or Composition Data through a Node Provisioning Protocol +Interface (NPPI) procedure, the :c:member:`bt_mesh_prov.reprovisioned` callback is triggered. See section +:ref:`bluetooth_mesh_models_rpr_cli` for further details. + +API reference +************* + +.. doxygengroup:: bt_mesh_rpr_srv + :project: Zephyr + :members: From 91140cbd9bf44c7e523fcc5ce98d142a738ac8d6 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Wed, 22 Mar 2023 13:30:16 +0100 Subject: [PATCH 0720/1906] manifest: Update TF-M to use the accepted upstream patches Revert the locally fixed issues for the zephyr 3.3.0 release and replace them with the official fixes submitted upstream. Signed-off-by: Joakim Andersson --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 21f53a7bce10..cb97e04c48d7 100644 --- a/west.yml +++ b/west.yml @@ -231,7 +231,7 @@ manifest: groups: - debug - name: trusted-firmware-m - revision: a8313be08816a2ed9d883c6b79fb4e5d2bef81c2 + revision: 60fbdb43fb371d811a7d5d88709cb06fa92b7b68 path: modules/tee/tf-m/trusted-firmware-m groups: - tee From f6a0d9c7f7227784e60cc91a132b8dcec7bccc04 Mon Sep 17 00:00:00 2001 From: Manimaran A Date: Sat, 4 Mar 2023 23:36:05 +0530 Subject: [PATCH 0721/1906] driver: adc: microchip: MEC172x driver clean up adc_mchp_xec_v2.c driver clean up by variable name change and redundant macro removal. Signed-off-by: Manimaran A --- drivers/adc/adc_mchp_xec_v2.c | 150 +++++++++++++++++----------------- 1 file changed, 73 insertions(+), 77 deletions(-) diff --git a/drivers/adc/adc_mchp_xec_v2.c b/drivers/adc/adc_mchp_xec_v2.c index 6b3b0b72cc07..0dc8a6a86320 100644 --- a/drivers/adc/adc_mchp_xec_v2.c +++ b/drivers/adc/adc_mchp_xec_v2.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2019 Intel Corporation. + * Copyright (c) 2023 Microchip Technology Inc. * * SPDX-License-Identifier: Apache-2.0 */ @@ -33,17 +34,6 @@ LOG_MODULE_REGISTER(adc_mchp_xec); #define XEC_ADC_CTRL_START_SINGLE BIT(1) #define XEC_ADC_CTRL_ACTIVATE BIT(0) -struct adc_xec_config { - uintptr_t base_addr; - uint8_t girq_single; - uint8_t girq_single_pos; - uint8_t girq_repeat; - uint8_t girq_repeat_pos; - uint8_t pcr_regidx; - uint8_t pcr_bitpos; - const struct pinctrl_dev_config *pcfg; -}; - /* ADC implements two interrupt signals: * One-shot(single) conversion of a set of channels * Repeat conversion of a set of channels @@ -55,14 +45,6 @@ enum adc_pm_policy_state_flag { ADC_PM_POLICY_STATE_FLAG_COUNT, }; -struct adc_xec_data { - struct adc_context ctx; - uint16_t *buffer; - uint16_t *repeat_buffer; -#ifdef CONFIG_PM_DEVICE - ATOMIC_DEFINE(pm_policy_state_flag, ADC_PM_POLICY_STATE_FLAG_COUNT); -#endif -}; struct adc_xec_regs { uint32_t control_reg; @@ -78,17 +60,27 @@ struct adc_xec_regs { uint32_t sar_control_reg; }; -#define ADC_XEC_CONFIG(dev) \ - ((struct adc_xec_config const *)(dev)->config) - -#define ADC_XEC_DATA(dev) \ - ((struct adc_xec_data *const)(dev)->data) +struct adc_xec_config { + struct adc_xec_regs *regs; -#define ADC_XEC_REG_BASE(dev) \ - ((struct adc_xec_regs *)ADC_XEC_CONFIG(dev)->base_addr) + uint8_t girq_single; + uint8_t girq_single_pos; + uint8_t girq_repeat; + uint8_t girq_repeat_pos; + uint8_t pcr_regidx; + uint8_t pcr_bitpos; + const struct pinctrl_dev_config *pcfg; +}; -#define ADC_XEC_0_REG_BASE \ - (struct adc_xec_regs *)(DT_INST_REG_ADDR(0)) +struct adc_xec_data { + struct adc_context ctx; + const struct device *adc_dev; + uint16_t *buffer; + uint16_t *repeat_buffer; +#ifdef CONFIG_PM_DEVICE + ATOMIC_DEFINE(pm_policy_state_flag, ADC_PM_POLICY_STATE_FLAG_COUNT); +#endif +}; #ifdef CONFIG_PM_DEVICE static void adc_xec_pm_policy_state_lock_get(struct adc_xec_data *data, @@ -111,16 +103,17 @@ static void adc_xec_pm_policy_state_lock_put(struct adc_xec_data *data, static void adc_context_start_sampling(struct adc_context *ctx) { struct adc_xec_data *data = CONTAINER_OF(ctx, struct adc_xec_data, ctx); - struct adc_xec_regs *adc_regs = ADC_XEC_0_REG_BASE; + const struct device *adc_dev = data->adc_dev; + const struct adc_xec_config * const devcfg = adc_dev->config; + struct adc_xec_regs *regs = devcfg->regs; data->repeat_buffer = data->buffer; #ifdef CONFIG_PM_DEVICE adc_xec_pm_policy_state_lock_get(data, ADC_PM_POLICY_STATE_SINGLE_FLAG); #endif - - adc_regs->single_reg = ctx->sequence.channels; - adc_regs->control_reg |= XEC_ADC_CTRL_START_SINGLE; + regs->single_reg = ctx->sequence.channels; + regs->control_reg |= XEC_ADC_CTRL_START_SINGLE; } static void adc_context_update_buffer_pointer(struct adc_context *ctx, @@ -136,10 +129,9 @@ static void adc_context_update_buffer_pointer(struct adc_context *ctx, static int adc_xec_channel_setup(const struct device *dev, const struct adc_channel_cfg *channel_cfg) { - struct adc_xec_regs *adc_regs = ADC_XEC_0_REG_BASE; - uint32_t reg; - - ARG_UNUSED(dev); + const struct adc_xec_config *const cfg = dev->config; + struct adc_xec_regs * const regs = cfg->regs; + uint32_t areg; if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) { return -EINVAL; @@ -154,26 +146,26 @@ static int adc_xec_channel_setup(const struct device *dev, } /* Setup VREF */ - reg = adc_regs->vref_channel_reg; - reg &= ~MCHP_ADC_CH_VREF_SEL_MASK(channel_cfg->channel_id); + areg = regs->vref_channel_reg; + areg &= ~MCHP_ADC_CH_VREF_SEL_MASK(channel_cfg->channel_id); if (channel_cfg->reference == ADC_REF_INTERNAL) { - reg |= MCHP_ADC_CH_VREF_SEL_PAD(channel_cfg->channel_id); + areg |= MCHP_ADC_CH_VREF_SEL_PAD(channel_cfg->channel_id); } else if (channel_cfg->reference == ADC_REF_EXTERNAL0) { - reg |= MCHP_ADC_CH_VREF_SEL_GPIO(channel_cfg->channel_id); + areg |= MCHP_ADC_CH_VREF_SEL_GPIO(channel_cfg->channel_id); } else { return -EINVAL; } - adc_regs->vref_channel_reg = reg; + regs->vref_channel_reg = areg; /* Differential mode? */ - reg = adc_regs->sar_control_reg; - reg &= ~BIT(MCHP_ADC_SAR_CTRL_SELDIFF_POS); + areg = regs->sar_control_reg; + areg &= ~BIT(MCHP_ADC_SAR_CTRL_SELDIFF_POS); if (channel_cfg->differential != 0) { - reg |= MCHP_ADC_SAR_CTRL_SELDIFF_EN; + areg |= MCHP_ADC_SAR_CTRL_SELDIFF_EN; } - adc_regs->sar_control_reg = reg; + regs->sar_control_reg = areg; return 0; } @@ -206,9 +198,10 @@ static bool adc_xec_validate_buffer_size(const struct adc_sequence *sequence) static int adc_xec_start_read(const struct device *dev, const struct adc_sequence *sequence) { - struct adc_xec_regs *adc_regs = ADC_XEC_REG_BASE(dev); - struct adc_xec_data *data = ADC_XEC_DATA(dev); - uint32_t reg; + const struct adc_xec_config *const cfg = dev->config; + struct adc_xec_regs * const regs = cfg->regs; + struct adc_xec_data * const data = dev->data; + uint32_t sar_ctrl; if (sequence->channels & ~BIT_MASK(MCHP_ADC_MAX_CHAN)) { LOG_ERR("Incorrect channels, bitmask 0x%x", sequence->channels); @@ -226,20 +219,20 @@ static int adc_xec_start_read(const struct device *dev, } /* Setup ADC resolution */ - reg = adc_regs->sar_control_reg; - reg &= ~(MCHP_ADC_SAR_CTRL_RES_MASK | - (1 << MCHP_ADC_SAR_CTRL_SHIFTD_POS)); + sar_ctrl = regs->sar_control_reg; + sar_ctrl &= ~(MCHP_ADC_SAR_CTRL_RES_MASK | + (1 << MCHP_ADC_SAR_CTRL_SHIFTD_POS)); if (sequence->resolution == 12) { - reg |= MCHP_ADC_SAR_CTRL_RES_12_BITS; + sar_ctrl |= MCHP_ADC_SAR_CTRL_RES_12_BITS; } else if (sequence->resolution == 10) { - reg |= MCHP_ADC_SAR_CTRL_RES_10_BITS; - reg |= MCHP_ADC_SAR_CTRL_SHIFTD_EN; + sar_ctrl |= MCHP_ADC_SAR_CTRL_RES_10_BITS; + sar_ctrl |= MCHP_ADC_SAR_CTRL_SHIFTD_EN; } else { return -EINVAL; } - adc_regs->sar_control_reg = reg; + regs->sar_control_reg = sar_ctrl; data->buffer = sequence->buffer; @@ -251,7 +244,7 @@ static int adc_xec_start_read(const struct device *dev, static int adc_xec_read(const struct device *dev, const struct adc_sequence *sequence) { - struct adc_xec_data *data = ADC_XEC_DATA(dev); + struct adc_xec_data * const data = dev->data; int error; adc_context_lock(&data->ctx, false, NULL); @@ -266,7 +259,7 @@ static int adc_xec_read_async(const struct device *dev, const struct adc_sequence *sequence, struct k_poll_signal *async) { - struct adc_xec_data *data = ADC_XEC_DATA(dev); + struct adc_xec_data * const data = dev->data; int error; adc_context_lock(&data->ctx, true, async); @@ -279,10 +272,11 @@ static int adc_xec_read_async(const struct device *dev, static void xec_adc_get_sample(const struct device *dev) { - struct adc_xec_regs *adc_regs = ADC_XEC_REG_BASE(dev); - struct adc_xec_data *data = ADC_XEC_DATA(dev); + const struct adc_xec_config *const cfg = dev->config; + struct adc_xec_regs * const regs = cfg->regs; + struct adc_xec_data * const data = dev->data; uint32_t idx; - uint32_t channels = adc_regs->status_reg; + uint32_t channels = regs->status_reg; uint32_t ch_status = channels; uint32_t bit; @@ -297,7 +291,7 @@ static void xec_adc_get_sample(const struct device *dev) while (bit != 0) { idx = bit - 1; - *data->buffer = (uint16_t)adc_regs->channel_read_reg[idx]; + *data->buffer = (uint16_t)regs->channel_read_reg[idx]; data->buffer++; channels &= ~BIT(idx); @@ -305,21 +299,21 @@ static void xec_adc_get_sample(const struct device *dev) } /* Clear the status register */ - adc_regs->status_reg = ch_status; + regs->status_reg = ch_status; } -static void adc_xec_isr(const struct device *dev) +static void adc_xec_single_isr(const struct device *dev) { - const struct adc_xec_config *const cfg = ADC_XEC_CONFIG(dev); - struct adc_xec_regs *adc_regs = ADC_XEC_REG_BASE(dev); - struct adc_xec_data *data = ADC_XEC_DATA(dev); - uint32_t reg; + const struct adc_xec_config *const cfg = dev->config; + struct adc_xec_regs * const regs = cfg->regs; + struct adc_xec_data * const data = dev->data; + uint32_t ctrl; /* Clear START_SINGLE bit and clear SINGLE_DONE_STATUS */ - reg = adc_regs->control_reg; - reg &= ~XEC_ADC_CTRL_START_SINGLE; - reg |= XEC_ADC_CTRL_SINGLE_DONE_STATUS; - adc_regs->control_reg = reg; + ctrl = regs->control_reg; + ctrl &= ~XEC_ADC_CTRL_START_SINGLE; + ctrl |= XEC_ADC_CTRL_SINGLE_DONE_STATUS; + regs->control_reg = ctrl; /* Also clear GIRQ source status bit */ mchp_xec_ecia_girq_src_clr(cfg->girq_single, cfg->girq_single_pos); @@ -378,18 +372,20 @@ struct adc_driver_api adc_xec_api = { static int adc_xec_init(const struct device *dev) { - const struct adc_xec_config *const cfg = ADC_XEC_CONFIG(dev); - struct adc_xec_regs *adc_regs = ADC_XEC_REG_BASE(dev); - struct adc_xec_data *data = ADC_XEC_DATA(dev); + const struct adc_xec_config *const cfg = dev->config; + struct adc_xec_regs * const regs = cfg->regs; + struct adc_xec_data * const data = dev->data; int ret; + data->adc_dev = dev; + ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); if (ret != 0) { LOG_ERR("XEC ADC V2 pinctrl setup failed (%d)", ret); return ret; } - adc_regs->control_reg = XEC_ADC_CTRL_ACTIVATE + regs->control_reg = XEC_ADC_CTRL_ACTIVATE | XEC_ADC_CTRL_POWER_SAVER_DIS | XEC_ADC_CTRL_SINGLE_DONE_STATUS | XEC_ADC_CTRL_REPEAT_DONE_STATUS; @@ -402,7 +398,7 @@ static int adc_xec_init(const struct device *dev) IRQ_CONNECT(DT_INST_IRQN(0), DT_INST_IRQ(0, priority), - adc_xec_isr, DEVICE_DT_INST_GET(0), 0); + adc_xec_single_isr, DEVICE_DT_INST_GET(0), 0); irq_enable(DT_INST_IRQN(0)); adc_context_unlock_unconditionally(&data->ctx); @@ -413,7 +409,7 @@ static int adc_xec_init(const struct device *dev) PINCTRL_DT_INST_DEFINE(0); static struct adc_xec_config adc_xec_dev_cfg_0 = { - .base_addr = (uintptr_t)(DT_INST_REG_ADDR(0)), + .regs = (struct adc_xec_regs *)(DT_INST_REG_ADDR(0)), .girq_single = (uint8_t)(DT_INST_PROP_BY_IDX(0, girqs, 0)), .girq_single_pos = (uint8_t)(DT_INST_PROP_BY_IDX(0, girqs, 1)), .girq_repeat = (uint8_t)(DT_INST_PROP_BY_IDX(0, girqs, 2)), From 51b1c5b9d6b61d70583fbd869effc03f8a3aad4b Mon Sep 17 00:00:00 2001 From: Manimaran A Date: Sun, 5 Mar 2023 12:52:59 +0530 Subject: [PATCH 0722/1906] driver: adc: microchip: Merged MEC172x and MEC15xx version drivers. Updated the "adc_mchp_xec_v2.c" adc driver to support both MEC172x and MEC15xx SOC. ADC smapling clock configuration updated using DTS. Signed-off-by: Manimaran A --- drivers/adc/adc_mchp_xec_v2.c | 55 +++++++++++++++++++--- dts/arm/microchip/mec1501hsz.dtsi | 4 +- dts/arm/microchip/mec172xnsz.dtsi | 1 + dts/bindings/adc/microchip,xec-adc-v2.yaml | 5 ++ 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/drivers/adc/adc_mchp_xec_v2.c b/drivers/adc/adc_mchp_xec_v2.c index 0dc8a6a86320..b2b5fe1856e0 100644 --- a/drivers/adc/adc_mchp_xec_v2.c +++ b/drivers/adc/adc_mchp_xec_v2.c @@ -12,7 +12,9 @@ LOG_MODULE_REGISTER(adc_mchp_xec); #include +#ifdef CONFIG_SOC_SERIES_MEC172X #include +#endif #include #include #include @@ -302,6 +304,39 @@ static void xec_adc_get_sample(const struct device *dev) regs->status_reg = ch_status; } +#ifdef CONFIG_SOC_SERIES_MEC172X +static inline void adc_xec_girq_clr(uint8_t girq_idx, uint8_t girq_posn) +{ + mchp_xec_ecia_girq_src_clr(girq_idx, girq_posn); +} + +static inline void adc_xec_girq_en(uint8_t girq_idx, uint8_t girq_posn) +{ + mchp_xec_ecia_girq_src_en(girq_idx, girq_posn); +} + +static inline void adc_xec_girq_dis(uint8_t girq_idx, uint8_t girq_posn) +{ + mchp_xec_ecia_girq_src_dis(girq_idx, girq_posn); +} +#else + +static inline void adc_xec_girq_clr(uint8_t girq_idx, uint8_t girq_posn) +{ + MCHP_GIRQ_SRC(girq_idx) = BIT(girq_posn); +} + +static inline void adc_xec_girq_en(uint8_t girq_idx, uint8_t girq_posn) +{ + MCHP_GIRQ_ENSET(girq_idx) = BIT(girq_posn); +} + +static inline void adc_xec_girq_dis(uint8_t girq_idx, uint8_t girq_posn) +{ + MCHP_GIRQ_ENCLR(girq_idx) = MCHP_KBC_IBF_GIRQ; +} +#endif + static void adc_xec_single_isr(const struct device *dev) { const struct adc_xec_config *const cfg = dev->config; @@ -316,7 +351,7 @@ static void adc_xec_single_isr(const struct device *dev) regs->control_reg = ctrl; /* Also clear GIRQ source status bit */ - mchp_xec_ecia_girq_src_clr(cfg->girq_single, cfg->girq_single_pos); + adc_xec_girq_clr(cfg->girq_single, cfg->girq_single_pos); xec_adc_get_sample(dev); @@ -329,6 +364,7 @@ static void adc_xec_single_isr(const struct device *dev) LOG_DBG("ADC ISR triggered."); } + #ifdef CONFIG_PM_DEVICE static int adc_xec_pm_action(const struct device *dev, enum pm_device_action action) { @@ -370,6 +406,11 @@ struct adc_driver_api adc_xec_api = { .ref_internal = XEC_ADC_VREF_ANALOG, }; +/* ADC Config Register */ +#define XEC_ADC_CFG_CLK_VAL(clk_time) ( \ + (clk_time << MCHP_ADC_CFG_CLK_LO_TIME_POS) | \ + (clk_time << MCHP_ADC_CFG_CLK_HI_TIME_POS)) + static int adc_xec_init(const struct device *dev) { const struct adc_xec_config *const cfg = dev->config; @@ -385,16 +426,18 @@ static int adc_xec_init(const struct device *dev) return ret; } + regs->config_reg = XEC_ADC_CFG_CLK_VAL(DT_INST_PROP(0, clktime)); + regs->control_reg = XEC_ADC_CTRL_ACTIVATE | XEC_ADC_CTRL_POWER_SAVER_DIS | XEC_ADC_CTRL_SINGLE_DONE_STATUS | XEC_ADC_CTRL_REPEAT_DONE_STATUS; - mchp_xec_ecia_girq_src_dis(cfg->girq_single, cfg->girq_single_pos); - mchp_xec_ecia_girq_src_dis(cfg->girq_repeat, cfg->girq_repeat_pos); - mchp_xec_ecia_girq_src_clr(cfg->girq_single, cfg->girq_single_pos); - mchp_xec_ecia_girq_src_clr(cfg->girq_repeat, cfg->girq_repeat_pos); - mchp_xec_ecia_girq_src_en(cfg->girq_single, cfg->girq_single_pos); + adc_xec_girq_dis(cfg->girq_repeat, cfg->girq_repeat_pos); + adc_xec_girq_clr(cfg->girq_repeat, cfg->girq_repeat_pos); + adc_xec_girq_dis(cfg->girq_single, cfg->girq_single_pos); + adc_xec_girq_clr(cfg->girq_single, cfg->girq_single_pos); + adc_xec_girq_en(cfg->girq_single, cfg->girq_single_pos); IRQ_CONNECT(DT_INST_IRQN(0), DT_INST_IRQ(0, priority), diff --git a/dts/arm/microchip/mec1501hsz.dtsi b/dts/arm/microchip/mec1501hsz.dtsi index a8a7c776b78e..61ecf96833d2 100644 --- a/dts/arm/microchip/mec1501hsz.dtsi +++ b/dts/arm/microchip/mec1501hsz.dtsi @@ -416,9 +416,11 @@ #pwm-cells = <3>; }; adc0: adc@40007c00 { - compatible = "microchip,xec-adc"; + compatible = "microchip,xec-adc-v2"; reg = <0x40007c00 0x90>; interrupts = <78 0>, <79 0>; + girqs = <17 8>, <17 9>; + pcrs = <3 3>; status = "disabled"; #io-channel-cells = <1>; clktime = <32>; diff --git a/dts/arm/microchip/mec172xnsz.dtsi b/dts/arm/microchip/mec172xnsz.dtsi index 79fda18c4e8b..e07f5c523729 100644 --- a/dts/arm/microchip/mec172xnsz.dtsi +++ b/dts/arm/microchip/mec172xnsz.dtsi @@ -695,6 +695,7 @@ pcrs = <3 3>; status = "disabled"; #io-channel-cells = <1>; + clktime = <32>; }; kscan0: kscan@40009c00 { compatible = "microchip,xec-kscan"; diff --git a/dts/bindings/adc/microchip,xec-adc-v2.yaml b/dts/bindings/adc/microchip,xec-adc-v2.yaml index 38039b7f1545..fd8abbfe60e5 100644 --- a/dts/bindings/adc/microchip,xec-adc-v2.yaml +++ b/dts/bindings/adc/microchip,xec-adc-v2.yaml @@ -28,6 +28,11 @@ properties: required: true description: ADC PCR register index and bit position + clktime: + type: int + required: true + description: ADC clock high & low time count value <1:255> + pinctrl-0: required: true From c3b2dbd1fbb8ad9ab7f9d1decf25b9354d6143f6 Mon Sep 17 00:00:00 2001 From: Manimaran A Date: Sun, 5 Mar 2023 13:10:25 +0530 Subject: [PATCH 0723/1906] driver: adc: microchip: Keep single adc driver for MEC devices Deleted adc_mchp_xec.c and microchip,xec-adc.yaml file. DTSI, yaml, CMakeLists.txt and Kconfig.xec files are updated for compatible. Signed-off-by: Manimaran A --- drivers/adc/CMakeLists.txt | 1 - drivers/adc/Kconfig.xec | 9 +- drivers/adc/adc_mchp_xec.c | 276 ++++++++---- drivers/adc/adc_mchp_xec_v2.c | 476 --------------------- dts/arm/microchip/mec1501hsz.dtsi | 2 +- dts/arm/microchip/mec172xnsz.dtsi | 2 +- dts/bindings/adc/microchip,xec-adc-v2.yaml | 43 -- dts/bindings/adc/microchip,xec-adc.yaml | 11 + 8 files changed, 214 insertions(+), 606 deletions(-) delete mode 100644 drivers/adc/adc_mchp_xec_v2.c delete mode 100644 dts/bindings/adc/microchip,xec-adc-v2.yaml diff --git a/drivers/adc/CMakeLists.txt b/drivers/adc/CMakeLists.txt index 676be802d1b8..68950ede8aa9 100644 --- a/drivers/adc/CMakeLists.txt +++ b/drivers/adc/CMakeLists.txt @@ -24,7 +24,6 @@ zephyr_library_sources_ifdef(CONFIG_USERSPACE adc_handlers.c) zephyr_library_sources_ifdef(CONFIG_ADC_CC32XX adc_cc32xx.c) zephyr_library_sources_ifdef(CONFIG_ADC_CC13XX_CC26XX adc_cc13xx_cc26xx.c) zephyr_library_sources_ifdef(CONFIG_ADC_EMUL adc_emul.c) -zephyr_library_sources_ifdef(CONFIG_ADC_XEC_V2 adc_mchp_xec_v2.c) zephyr_library_sources_ifdef(CONFIG_ADC_TEST adc_test.c) zephyr_library_sources_ifdef(CONFIG_ADC_ADS1X1X adc_ads1x1x.c) zephyr_library_sources_ifdef(CONFIG_ADC_GD32 adc_gd32.c) diff --git a/drivers/adc/Kconfig.xec b/drivers/adc/Kconfig.xec index b711a3a3c0b5..7f031dff0067 100644 --- a/drivers/adc/Kconfig.xec +++ b/drivers/adc/Kconfig.xec @@ -1,7 +1,7 @@ # Microchip XEC ADC configuration # Copyright (c) 2019 Intel Corporation -# Copyright (c) 2021 Microchip Technology Inc. +# Copyright (c) 2023 Microchip Technology Inc. # SPDX-License-Identifier: Apache-2.0 config ADC_XEC @@ -10,10 +10,3 @@ config ADC_XEC depends on DT_HAS_MICROCHIP_XEC_ADC_ENABLED help Enable ADC driver for Microchip XEC MCU series. - -config ADC_XEC_V2 - bool "Microchip XEC series ADC V2 driver" - default y - depends on DT_HAS_MICROCHIP_XEC_ADC_V2_ENABLED - help - Enable ADC driver for Microchip XEC MEC172x MCU series. diff --git a/drivers/adc/adc_mchp_xec.c b/drivers/adc/adc_mchp_xec.c index 5bdaca5c195d..f2ec21ab06c9 100644 --- a/drivers/adc/adc_mchp_xec.c +++ b/drivers/adc/adc_mchp_xec.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2019 Intel Corporation. + * Copyright (c) 2023 Microchip Technology Inc. * * SPDX-License-Identifier: Apache-2.0 */ @@ -11,7 +12,12 @@ LOG_MODULE_REGISTER(adc_mchp_xec); #include +#ifdef CONFIG_SOC_SERIES_MEC172X +#include +#endif #include +#include +#include #include #include #include @@ -30,15 +36,17 @@ LOG_MODULE_REGISTER(adc_mchp_xec); #define XEC_ADC_CTRL_START_SINGLE BIT(1) #define XEC_ADC_CTRL_ACTIVATE BIT(0) -struct adc_xec_config { - const struct pinctrl_dev_config *pcfg; +/* ADC implements two interrupt signals: + * One-shot(single) conversion of a set of channels + * Repeat conversion of a set of channels + * Channel sets for single and repeat may be different. + */ +enum adc_pm_policy_state_flag { + ADC_PM_POLICY_STATE_SINGLE_FLAG, + ADC_PM_POLICY_STATE_REPEAT_FLAG, + ADC_PM_POLICY_STATE_FLAG_COUNT, }; -struct adc_xec_data { - struct adc_context ctx; - uint16_t *buffer; - uint16_t *repeat_buffer; -}; struct adc_xec_regs { uint32_t control_reg; @@ -54,18 +62,60 @@ struct adc_xec_regs { uint32_t sar_control_reg; }; -#define ADC_XEC_REG_BASE \ - ((struct adc_xec_regs *)(DT_INST_REG_ADDR(0))) +struct adc_xec_config { + struct adc_xec_regs *regs; + + uint8_t girq_single; + uint8_t girq_single_pos; + uint8_t girq_repeat; + uint8_t girq_repeat_pos; + uint8_t pcr_regidx; + uint8_t pcr_bitpos; + const struct pinctrl_dev_config *pcfg; +}; + +struct adc_xec_data { + struct adc_context ctx; + const struct device *adc_dev; + uint16_t *buffer; + uint16_t *repeat_buffer; +#ifdef CONFIG_PM_DEVICE + ATOMIC_DEFINE(pm_policy_state_flag, ADC_PM_POLICY_STATE_FLAG_COUNT); +#endif +}; + +#ifdef CONFIG_PM_DEVICE +static void adc_xec_pm_policy_state_lock_get(struct adc_xec_data *data, + enum adc_pm_policy_state_flag flag) +{ + if (atomic_test_and_set_bit(data->pm_policy_state_flag, flag) == 0) { + pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES); + } +} + +static void adc_xec_pm_policy_state_lock_put(struct adc_xec_data *data, + enum adc_pm_policy_state_flag flag) +{ + if (atomic_test_and_clear_bit(data->pm_policy_state_flag, flag) == 1) { + pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES); + } +} +#endif static void adc_context_start_sampling(struct adc_context *ctx) { struct adc_xec_data *data = CONTAINER_OF(ctx, struct adc_xec_data, ctx); - struct adc_xec_regs *adc_regs = ADC_XEC_REG_BASE; + const struct device *adc_dev = data->adc_dev; + const struct adc_xec_config * const devcfg = adc_dev->config; + struct adc_xec_regs *regs = devcfg->regs; data->repeat_buffer = data->buffer; - adc_regs->single_reg = ctx->sequence.channels; - adc_regs->control_reg |= XEC_ADC_CTRL_START_SINGLE; +#ifdef CONFIG_PM_DEVICE + adc_xec_pm_policy_state_lock_get(data, ADC_PM_POLICY_STATE_SINGLE_FLAG); +#endif + regs->single_reg = ctx->sequence.channels; + regs->control_reg |= XEC_ADC_CTRL_START_SINGLE; } static void adc_context_update_buffer_pointer(struct adc_context *ctx, @@ -81,10 +131,9 @@ static void adc_context_update_buffer_pointer(struct adc_context *ctx, static int adc_xec_channel_setup(const struct device *dev, const struct adc_channel_cfg *channel_cfg) { - struct adc_xec_regs *adc_regs = ADC_XEC_REG_BASE; - uint32_t reg; - - ARG_UNUSED(dev); + const struct adc_xec_config *const cfg = dev->config; + struct adc_xec_regs * const regs = cfg->regs; + uint32_t areg; if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) { return -EINVAL; @@ -99,26 +148,26 @@ static int adc_xec_channel_setup(const struct device *dev, } /* Setup VREF */ - reg = adc_regs->vref_channel_reg; - reg &= ~MCHP_ADC_CH_VREF_SEL_MASK(channel_cfg->channel_id); + areg = regs->vref_channel_reg; + areg &= ~MCHP_ADC_CH_VREF_SEL_MASK(channel_cfg->channel_id); if (channel_cfg->reference == ADC_REF_INTERNAL) { - reg |= MCHP_ADC_CH_VREF_SEL_PAD(channel_cfg->channel_id); + areg |= MCHP_ADC_CH_VREF_SEL_PAD(channel_cfg->channel_id); } else if (channel_cfg->reference == ADC_REF_EXTERNAL0) { - reg |= MCHP_ADC_CH_VREF_SEL_GPIO(channel_cfg->channel_id); + areg |= MCHP_ADC_CH_VREF_SEL_GPIO(channel_cfg->channel_id); } else { return -EINVAL; } - adc_regs->vref_channel_reg = reg; + regs->vref_channel_reg = areg; /* Differential mode? */ - reg = adc_regs->sar_control_reg; - reg &= ~BIT(MCHP_ADC_SAR_CTRL_SELDIFF_POS); + areg = regs->sar_control_reg; + areg &= ~BIT(MCHP_ADC_SAR_CTRL_SELDIFF_POS); if (channel_cfg->differential != 0) { - reg |= MCHP_ADC_SAR_CTRL_SELDIFF_EN; + areg |= MCHP_ADC_SAR_CTRL_SELDIFF_EN; } - adc_regs->sar_control_reg = reg; + regs->sar_control_reg = areg; return 0; } @@ -151,9 +200,10 @@ static bool adc_xec_validate_buffer_size(const struct adc_sequence *sequence) static int adc_xec_start_read(const struct device *dev, const struct adc_sequence *sequence) { - struct adc_xec_regs *adc_regs = ADC_XEC_REG_BASE; - struct adc_xec_data *data = dev->data; - uint32_t reg; + const struct adc_xec_config *const cfg = dev->config; + struct adc_xec_regs * const regs = cfg->regs; + struct adc_xec_data * const data = dev->data; + uint32_t sar_ctrl; if (sequence->channels & ~BIT_MASK(MCHP_ADC_MAX_CHAN)) { LOG_ERR("Incorrect channels, bitmask 0x%x", sequence->channels); @@ -171,20 +221,20 @@ static int adc_xec_start_read(const struct device *dev, } /* Setup ADC resolution */ - reg = adc_regs->sar_control_reg; - reg &= ~(MCHP_ADC_SAR_CTRL_RES_MASK | - (1 << MCHP_ADC_SAR_CTRL_SHIFTD_POS)); + sar_ctrl = regs->sar_control_reg; + sar_ctrl &= ~(MCHP_ADC_SAR_CTRL_RES_MASK | + (1 << MCHP_ADC_SAR_CTRL_SHIFTD_POS)); if (sequence->resolution == 12) { - reg |= MCHP_ADC_SAR_CTRL_RES_12_BITS; + sar_ctrl |= MCHP_ADC_SAR_CTRL_RES_12_BITS; } else if (sequence->resolution == 10) { - reg |= MCHP_ADC_SAR_CTRL_RES_10_BITS; - reg |= MCHP_ADC_SAR_CTRL_SHIFTD_EN; + sar_ctrl |= MCHP_ADC_SAR_CTRL_RES_10_BITS; + sar_ctrl |= MCHP_ADC_SAR_CTRL_SHIFTD_EN; } else { return -EINVAL; } - adc_regs->sar_control_reg = reg; + regs->sar_control_reg = sar_ctrl; data->buffer = sequence->buffer; @@ -196,7 +246,7 @@ static int adc_xec_start_read(const struct device *dev, static int adc_xec_read(const struct device *dev, const struct adc_sequence *sequence) { - struct adc_xec_data *data = dev->data; + struct adc_xec_data * const data = dev->data; int error; adc_context_lock(&data->ctx, false, NULL); @@ -206,12 +256,12 @@ static int adc_xec_read(const struct device *dev, return error; } -#if defined(CONFIG_ADC_ASYNC) +#ifdef CONFIG_ADC_ASYNC static int adc_xec_read_async(const struct device *dev, const struct adc_sequence *sequence, struct k_poll_signal *async) { - struct adc_xec_data *data = dev->data; + struct adc_xec_data * const data = dev->data; int error; adc_context_lock(&data->ctx, true, async); @@ -222,12 +272,13 @@ static int adc_xec_read_async(const struct device *dev, } #endif /* CONFIG_ADC_ASYNC */ -static int xec_adc_get_sample(const struct device *dev) +static void xec_adc_get_sample(const struct device *dev) { - struct adc_xec_regs *adc_regs = ADC_XEC_REG_BASE; - struct adc_xec_data *data = dev->data; + const struct adc_xec_config *const cfg = dev->config; + struct adc_xec_regs * const regs = cfg->regs; + struct adc_xec_data * const data = dev->data; uint32_t idx; - uint32_t channels = adc_regs->status_reg; + uint32_t channels = regs->status_reg; uint32_t ch_status = channels; uint32_t bit; @@ -241,7 +292,8 @@ static int xec_adc_get_sample(const struct device *dev) bit = find_lsb_set(channels); while (bit != 0) { idx = bit - 1; - *data->buffer = (uint16_t)adc_regs->channel_read_reg[idx]; + + *data->buffer = (uint16_t)regs->channel_read_reg[idx]; data->buffer++; channels &= ~BIT(idx); @@ -249,44 +301,102 @@ static int xec_adc_get_sample(const struct device *dev) } /* Clear the status register */ - adc_regs->status_reg = ch_status; + regs->status_reg = ch_status; +} - /* Return error when requested ADC conversion was incomplete - * for some channels. - */ - if (ch_status != adc_regs->single_reg) { - return -EIO; - } +#ifdef CONFIG_SOC_SERIES_MEC172X +static inline void adc_xec_girq_clr(uint8_t girq_idx, uint8_t girq_posn) +{ + mchp_xec_ecia_girq_src_clr(girq_idx, girq_posn); +} - return 0; +static inline void adc_xec_girq_en(uint8_t girq_idx, uint8_t girq_posn) +{ + mchp_xec_ecia_girq_src_en(girq_idx, girq_posn); } -static void adc_xec_isr(const struct device *dev) +static inline void adc_xec_girq_dis(uint8_t girq_idx, uint8_t girq_posn) { - struct adc_xec_regs *adc_regs = ADC_XEC_REG_BASE; - struct adc_xec_data *data = dev->data; - uint32_t reg; - int ret; + mchp_xec_ecia_girq_src_dis(girq_idx, girq_posn); +} +#else + +static inline void adc_xec_girq_clr(uint8_t girq_idx, uint8_t girq_posn) +{ + MCHP_GIRQ_SRC(girq_idx) = BIT(girq_posn); +} + +static inline void adc_xec_girq_en(uint8_t girq_idx, uint8_t girq_posn) +{ + MCHP_GIRQ_ENSET(girq_idx) = BIT(girq_posn); +} + +static inline void adc_xec_girq_dis(uint8_t girq_idx, uint8_t girq_posn) +{ + MCHP_GIRQ_ENCLR(girq_idx) = MCHP_KBC_IBF_GIRQ; +} +#endif + +static void adc_xec_single_isr(const struct device *dev) +{ + const struct adc_xec_config *const cfg = dev->config; + struct adc_xec_regs * const regs = cfg->regs; + struct adc_xec_data * const data = dev->data; + uint32_t ctrl; /* Clear START_SINGLE bit and clear SINGLE_DONE_STATUS */ - reg = adc_regs->control_reg; - reg &= ~XEC_ADC_CTRL_START_SINGLE; - reg |= XEC_ADC_CTRL_SINGLE_DONE_STATUS; - adc_regs->control_reg = reg; + ctrl = regs->control_reg; + ctrl &= ~XEC_ADC_CTRL_START_SINGLE; + ctrl |= XEC_ADC_CTRL_SINGLE_DONE_STATUS; + regs->control_reg = ctrl; /* Also clear GIRQ source status bit */ - MCHP_GIRQ_SRC(MCHP_ADC_GIRQ) = MCHP_ADC_SNG_DONE_GIRQ_VAL; + adc_xec_girq_clr(cfg->girq_single, cfg->girq_single_pos); - ret = xec_adc_get_sample(dev); - if (ret) { - adc_context_complete(&data->ctx, ret); - } else { - adc_context_on_sampling_done(&data->ctx, dev); - } + xec_adc_get_sample(dev); + +#ifdef CONFIG_PM_DEVICE + adc_xec_pm_policy_state_lock_put(data, ADC_PM_POLICY_STATE_SINGLE_FLAG); +#endif + + adc_context_on_sampling_done(&data->ctx, dev); LOG_DBG("ADC ISR triggered."); } + +#ifdef CONFIG_PM_DEVICE +static int adc_xec_pm_action(const struct device *dev, enum pm_device_action action) +{ + const struct adc_xec_config *const devcfg = dev->config; + struct adc_xec_regs *adc_regs = ADC_XEC_REG_BASE(dev); + int ret; + + switch (action) { + case PM_DEVICE_ACTION_RESUME: + ret = pinctrl_apply_state(devcfg->pcfg, PINCTRL_STATE_DEFAULT); + /* ADC activate */ + adc_regs->control_reg |= XEC_ADC_CTRL_ACTIVATE; + break; + case PM_DEVICE_ACTION_SUSPEND: + /* ADC deactivate */ + adc_regs->control_reg &= ~(XEC_ADC_CTRL_ACTIVATE); + /* If application does not want to turn off ADC pins it will + * not define pinctrl-1 for this node. + */ + ret = pinctrl_apply_state(devcfg->pcfg, PINCTRL_STATE_SLEEP); + if (ret == -ENOENT) { /* pinctrl-1 does not exist. */ + ret = 0; + } + break; + default: + ret = -ENOTSUP; + } + + return ret; +} +#endif /* CONFIG_PM_DEVICE */ + struct adc_driver_api adc_xec_api = { .channel_setup = adc_xec_channel_setup, .read = adc_xec_read, @@ -304,29 +414,34 @@ struct adc_driver_api adc_xec_api = { static int adc_xec_init(const struct device *dev) { const struct adc_xec_config *const cfg = dev->config; - struct adc_xec_regs *adc_regs = ADC_XEC_REG_BASE; - struct adc_xec_data *data = dev->data; + struct adc_xec_regs * const regs = cfg->regs; + struct adc_xec_data * const data = dev->data; int ret; + data->adc_dev = dev; + ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); if (ret != 0) { - LOG_ERR("XEC ADC pinctrl setup failed (%d)", ret); + LOG_ERR("XEC ADC V2 pinctrl setup failed (%d)", ret); return ret; } - adc_regs->config_reg = XEC_ADC_CFG_CLK_VAL(DT_INST_PROP(0, clktime)); + regs->config_reg = XEC_ADC_CFG_CLK_VAL(DT_INST_PROP(0, clktime)); - adc_regs->control_reg = XEC_ADC_CTRL_ACTIVATE + regs->control_reg = XEC_ADC_CTRL_ACTIVATE | XEC_ADC_CTRL_POWER_SAVER_DIS | XEC_ADC_CTRL_SINGLE_DONE_STATUS | XEC_ADC_CTRL_REPEAT_DONE_STATUS; - MCHP_GIRQ_SRC(MCHP_ADC_GIRQ) = MCHP_ADC_SNG_DONE_GIRQ_VAL; - MCHP_GIRQ_ENSET(MCHP_ADC_GIRQ) = MCHP_ADC_SNG_DONE_GIRQ_VAL; + adc_xec_girq_dis(cfg->girq_repeat, cfg->girq_repeat_pos); + adc_xec_girq_clr(cfg->girq_repeat, cfg->girq_repeat_pos); + adc_xec_girq_dis(cfg->girq_single, cfg->girq_single_pos); + adc_xec_girq_clr(cfg->girq_single, cfg->girq_single_pos); + adc_xec_girq_en(cfg->girq_single, cfg->girq_single_pos); IRQ_CONNECT(DT_INST_IRQN(0), DT_INST_IRQ(0, priority), - adc_xec_isr, DEVICE_DT_INST_GET(0), 0); + adc_xec_single_isr, DEVICE_DT_INST_GET(0), 0); irq_enable(DT_INST_IRQN(0)); adc_context_unlock_unconditionally(&data->ctx); @@ -337,6 +452,13 @@ static int adc_xec_init(const struct device *dev) PINCTRL_DT_INST_DEFINE(0); static struct adc_xec_config adc_xec_dev_cfg_0 = { + .regs = (struct adc_xec_regs *)(DT_INST_REG_ADDR(0)), + .girq_single = (uint8_t)(DT_INST_PROP_BY_IDX(0, girqs, 0)), + .girq_single_pos = (uint8_t)(DT_INST_PROP_BY_IDX(0, girqs, 1)), + .girq_repeat = (uint8_t)(DT_INST_PROP_BY_IDX(0, girqs, 2)), + .girq_repeat_pos = (uint8_t)(DT_INST_PROP_BY_IDX(0, girqs, 3)), + .pcr_regidx = (uint8_t)(DT_INST_PROP_BY_IDX(0, pcrs, 0)), + .pcr_bitpos = (uint8_t)(DT_INST_PROP_BY_IDX(0, pcrs, 1)), .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0), }; @@ -346,7 +468,9 @@ static struct adc_xec_data adc_xec_dev_data_0 = { ADC_CONTEXT_INIT_SYNC(adc_xec_dev_data_0, ctx), }; -DEVICE_DT_INST_DEFINE(0, adc_xec_init, NULL, +PM_DEVICE_DT_INST_DEFINE(0, adc_xec_pm_action); + +DEVICE_DT_INST_DEFINE(0, adc_xec_init, PM_DEVICE_DT_INST_GET(0), &adc_xec_dev_data_0, &adc_xec_dev_cfg_0, PRE_KERNEL_1, CONFIG_ADC_INIT_PRIORITY, &adc_xec_api); diff --git a/drivers/adc/adc_mchp_xec_v2.c b/drivers/adc/adc_mchp_xec_v2.c deleted file mode 100644 index b2b5fe1856e0..000000000000 --- a/drivers/adc/adc_mchp_xec_v2.c +++ /dev/null @@ -1,476 +0,0 @@ -/* - * Copyright (c) 2019 Intel Corporation. - * Copyright (c) 2023 Microchip Technology Inc. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#define DT_DRV_COMPAT microchip_xec_adc_v2 - -#define LOG_LEVEL CONFIG_ADC_LOG_LEVEL -#include -LOG_MODULE_REGISTER(adc_mchp_xec); - -#include -#ifdef CONFIG_SOC_SERIES_MEC172X -#include -#endif -#include -#include -#include -#include -#include -#include - -#define ADC_CONTEXT_USES_KERNEL_TIMER -#include "adc_context.h" - -#define XEC_ADC_VREF_ANALOG 3300 - -/* ADC Control Register */ -#define XEC_ADC_CTRL_SINGLE_DONE_STATUS BIT(7) -#define XEC_ADC_CTRL_REPEAT_DONE_STATUS BIT(6) -#define XER_ADC_CTRL_SOFT_RESET BIT(4) -#define XEC_ADC_CTRL_POWER_SAVER_DIS BIT(3) -#define XEC_ADC_CTRL_START_REPEAT BIT(2) -#define XEC_ADC_CTRL_START_SINGLE BIT(1) -#define XEC_ADC_CTRL_ACTIVATE BIT(0) - -/* ADC implements two interrupt signals: - * One-shot(single) conversion of a set of channels - * Repeat conversion of a set of channels - * Channel sets for single and repeat may be different. - */ -enum adc_pm_policy_state_flag { - ADC_PM_POLICY_STATE_SINGLE_FLAG, - ADC_PM_POLICY_STATE_REPEAT_FLAG, - ADC_PM_POLICY_STATE_FLAG_COUNT, -}; - - -struct adc_xec_regs { - uint32_t control_reg; - uint32_t delay_reg; - uint32_t status_reg; - uint32_t single_reg; - uint32_t repeat_reg; - uint32_t channel_read_reg[8]; - uint32_t unused[18]; - uint32_t config_reg; - uint32_t vref_channel_reg; - uint32_t vref_control_reg; - uint32_t sar_control_reg; -}; - -struct adc_xec_config { - struct adc_xec_regs *regs; - - uint8_t girq_single; - uint8_t girq_single_pos; - uint8_t girq_repeat; - uint8_t girq_repeat_pos; - uint8_t pcr_regidx; - uint8_t pcr_bitpos; - const struct pinctrl_dev_config *pcfg; -}; - -struct adc_xec_data { - struct adc_context ctx; - const struct device *adc_dev; - uint16_t *buffer; - uint16_t *repeat_buffer; -#ifdef CONFIG_PM_DEVICE - ATOMIC_DEFINE(pm_policy_state_flag, ADC_PM_POLICY_STATE_FLAG_COUNT); -#endif -}; - -#ifdef CONFIG_PM_DEVICE -static void adc_xec_pm_policy_state_lock_get(struct adc_xec_data *data, - enum adc_pm_policy_state_flag flag) -{ - if (atomic_test_and_set_bit(data->pm_policy_state_flag, flag) == 0) { - pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES); - } -} - -static void adc_xec_pm_policy_state_lock_put(struct adc_xec_data *data, - enum adc_pm_policy_state_flag flag) -{ - if (atomic_test_and_clear_bit(data->pm_policy_state_flag, flag) == 1) { - pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES); - } -} -#endif - -static void adc_context_start_sampling(struct adc_context *ctx) -{ - struct adc_xec_data *data = CONTAINER_OF(ctx, struct adc_xec_data, ctx); - const struct device *adc_dev = data->adc_dev; - const struct adc_xec_config * const devcfg = adc_dev->config; - struct adc_xec_regs *regs = devcfg->regs; - - data->repeat_buffer = data->buffer; - -#ifdef CONFIG_PM_DEVICE - adc_xec_pm_policy_state_lock_get(data, ADC_PM_POLICY_STATE_SINGLE_FLAG); -#endif - regs->single_reg = ctx->sequence.channels; - regs->control_reg |= XEC_ADC_CTRL_START_SINGLE; -} - -static void adc_context_update_buffer_pointer(struct adc_context *ctx, - bool repeat_sampling) -{ - struct adc_xec_data *data = CONTAINER_OF(ctx, struct adc_xec_data, ctx); - - if (repeat_sampling) { - data->buffer = data->repeat_buffer; - } -} - -static int adc_xec_channel_setup(const struct device *dev, - const struct adc_channel_cfg *channel_cfg) -{ - const struct adc_xec_config *const cfg = dev->config; - struct adc_xec_regs * const regs = cfg->regs; - uint32_t areg; - - if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) { - return -EINVAL; - } - - if (channel_cfg->channel_id >= MCHP_ADC_MAX_CHAN) { - return -EINVAL; - } - - if (channel_cfg->gain != ADC_GAIN_1) { - return -EINVAL; - } - - /* Setup VREF */ - areg = regs->vref_channel_reg; - areg &= ~MCHP_ADC_CH_VREF_SEL_MASK(channel_cfg->channel_id); - - if (channel_cfg->reference == ADC_REF_INTERNAL) { - areg |= MCHP_ADC_CH_VREF_SEL_PAD(channel_cfg->channel_id); - } else if (channel_cfg->reference == ADC_REF_EXTERNAL0) { - areg |= MCHP_ADC_CH_VREF_SEL_GPIO(channel_cfg->channel_id); - } else { - return -EINVAL; - } - - regs->vref_channel_reg = areg; - - /* Differential mode? */ - areg = regs->sar_control_reg; - areg &= ~BIT(MCHP_ADC_SAR_CTRL_SELDIFF_POS); - if (channel_cfg->differential != 0) { - areg |= MCHP_ADC_SAR_CTRL_SELDIFF_EN; - } - regs->sar_control_reg = areg; - - return 0; -} - -static bool adc_xec_validate_buffer_size(const struct adc_sequence *sequence) -{ - int chan_count = 0; - size_t buff_need; - uint32_t chan_mask; - - for (chan_mask = 0x80; chan_mask != 0; chan_mask >>= 1) { - if (chan_mask & sequence->channels) { - chan_count++; - } - } - - buff_need = chan_count * sizeof(uint16_t); - - if (sequence->options) { - buff_need *= 1 + sequence->options->extra_samplings; - } - - if (buff_need > sequence->buffer_size) { - return false; - } - - return true; -} - -static int adc_xec_start_read(const struct device *dev, - const struct adc_sequence *sequence) -{ - const struct adc_xec_config *const cfg = dev->config; - struct adc_xec_regs * const regs = cfg->regs; - struct adc_xec_data * const data = dev->data; - uint32_t sar_ctrl; - - if (sequence->channels & ~BIT_MASK(MCHP_ADC_MAX_CHAN)) { - LOG_ERR("Incorrect channels, bitmask 0x%x", sequence->channels); - return -EINVAL; - } - - if (sequence->channels == 0UL) { - LOG_ERR("No channel selected"); - return -EINVAL; - } - - if (!adc_xec_validate_buffer_size(sequence)) { - LOG_ERR("Incorrect buffer size"); - return -ENOMEM; - } - - /* Setup ADC resolution */ - sar_ctrl = regs->sar_control_reg; - sar_ctrl &= ~(MCHP_ADC_SAR_CTRL_RES_MASK | - (1 << MCHP_ADC_SAR_CTRL_SHIFTD_POS)); - - if (sequence->resolution == 12) { - sar_ctrl |= MCHP_ADC_SAR_CTRL_RES_12_BITS; - } else if (sequence->resolution == 10) { - sar_ctrl |= MCHP_ADC_SAR_CTRL_RES_10_BITS; - sar_ctrl |= MCHP_ADC_SAR_CTRL_SHIFTD_EN; - } else { - return -EINVAL; - } - - regs->sar_control_reg = sar_ctrl; - - data->buffer = sequence->buffer; - - adc_context_start_read(&data->ctx, sequence); - - return adc_context_wait_for_completion(&data->ctx); -} - -static int adc_xec_read(const struct device *dev, - const struct adc_sequence *sequence) -{ - struct adc_xec_data * const data = dev->data; - int error; - - adc_context_lock(&data->ctx, false, NULL); - error = adc_xec_start_read(dev, sequence); - adc_context_release(&data->ctx, error); - - return error; -} - -#ifdef CONFIG_ADC_ASYNC -static int adc_xec_read_async(const struct device *dev, - const struct adc_sequence *sequence, - struct k_poll_signal *async) -{ - struct adc_xec_data * const data = dev->data; - int error; - - adc_context_lock(&data->ctx, true, async); - error = adc_xec_start_read(dev, sequence); - adc_context_release(&data->ctx, error); - - return error; -} -#endif /* CONFIG_ADC_ASYNC */ - -static void xec_adc_get_sample(const struct device *dev) -{ - const struct adc_xec_config *const cfg = dev->config; - struct adc_xec_regs * const regs = cfg->regs; - struct adc_xec_data * const data = dev->data; - uint32_t idx; - uint32_t channels = regs->status_reg; - uint32_t ch_status = channels; - uint32_t bit; - - /* - * Using the enabled channel bit set, from - * lowest channel number to highest, find out - * which channel is enabled and copy the ADC - * values from hardware registers to the data - * buffer. - */ - bit = find_lsb_set(channels); - while (bit != 0) { - idx = bit - 1; - - *data->buffer = (uint16_t)regs->channel_read_reg[idx]; - data->buffer++; - - channels &= ~BIT(idx); - bit = find_lsb_set(channels); - } - - /* Clear the status register */ - regs->status_reg = ch_status; -} - -#ifdef CONFIG_SOC_SERIES_MEC172X -static inline void adc_xec_girq_clr(uint8_t girq_idx, uint8_t girq_posn) -{ - mchp_xec_ecia_girq_src_clr(girq_idx, girq_posn); -} - -static inline void adc_xec_girq_en(uint8_t girq_idx, uint8_t girq_posn) -{ - mchp_xec_ecia_girq_src_en(girq_idx, girq_posn); -} - -static inline void adc_xec_girq_dis(uint8_t girq_idx, uint8_t girq_posn) -{ - mchp_xec_ecia_girq_src_dis(girq_idx, girq_posn); -} -#else - -static inline void adc_xec_girq_clr(uint8_t girq_idx, uint8_t girq_posn) -{ - MCHP_GIRQ_SRC(girq_idx) = BIT(girq_posn); -} - -static inline void adc_xec_girq_en(uint8_t girq_idx, uint8_t girq_posn) -{ - MCHP_GIRQ_ENSET(girq_idx) = BIT(girq_posn); -} - -static inline void adc_xec_girq_dis(uint8_t girq_idx, uint8_t girq_posn) -{ - MCHP_GIRQ_ENCLR(girq_idx) = MCHP_KBC_IBF_GIRQ; -} -#endif - -static void adc_xec_single_isr(const struct device *dev) -{ - const struct adc_xec_config *const cfg = dev->config; - struct adc_xec_regs * const regs = cfg->regs; - struct adc_xec_data * const data = dev->data; - uint32_t ctrl; - - /* Clear START_SINGLE bit and clear SINGLE_DONE_STATUS */ - ctrl = regs->control_reg; - ctrl &= ~XEC_ADC_CTRL_START_SINGLE; - ctrl |= XEC_ADC_CTRL_SINGLE_DONE_STATUS; - regs->control_reg = ctrl; - - /* Also clear GIRQ source status bit */ - adc_xec_girq_clr(cfg->girq_single, cfg->girq_single_pos); - - xec_adc_get_sample(dev); - -#ifdef CONFIG_PM_DEVICE - adc_xec_pm_policy_state_lock_put(data, ADC_PM_POLICY_STATE_SINGLE_FLAG); -#endif - - adc_context_on_sampling_done(&data->ctx, dev); - - LOG_DBG("ADC ISR triggered."); -} - - -#ifdef CONFIG_PM_DEVICE -static int adc_xec_pm_action(const struct device *dev, enum pm_device_action action) -{ - const struct adc_xec_config *const devcfg = dev->config; - struct adc_xec_regs *adc_regs = ADC_XEC_REG_BASE(dev); - int ret; - - switch (action) { - case PM_DEVICE_ACTION_RESUME: - ret = pinctrl_apply_state(devcfg->pcfg, PINCTRL_STATE_DEFAULT); - /* ADC activate */ - adc_regs->control_reg |= XEC_ADC_CTRL_ACTIVATE; - break; - case PM_DEVICE_ACTION_SUSPEND: - /* ADC deactivate */ - adc_regs->control_reg &= ~(XEC_ADC_CTRL_ACTIVATE); - /* If application does not want to turn off ADC pins it will - * not define pinctrl-1 for this node. - */ - ret = pinctrl_apply_state(devcfg->pcfg, PINCTRL_STATE_SLEEP); - if (ret == -ENOENT) { /* pinctrl-1 does not exist. */ - ret = 0; - } - break; - default: - ret = -ENOTSUP; - } - - return ret; -} -#endif /* CONFIG_PM_DEVICE */ - -struct adc_driver_api adc_xec_api = { - .channel_setup = adc_xec_channel_setup, - .read = adc_xec_read, -#if defined(CONFIG_ADC_ASYNC) - .read_async = adc_xec_read_async, -#endif - .ref_internal = XEC_ADC_VREF_ANALOG, -}; - -/* ADC Config Register */ -#define XEC_ADC_CFG_CLK_VAL(clk_time) ( \ - (clk_time << MCHP_ADC_CFG_CLK_LO_TIME_POS) | \ - (clk_time << MCHP_ADC_CFG_CLK_HI_TIME_POS)) - -static int adc_xec_init(const struct device *dev) -{ - const struct adc_xec_config *const cfg = dev->config; - struct adc_xec_regs * const regs = cfg->regs; - struct adc_xec_data * const data = dev->data; - int ret; - - data->adc_dev = dev; - - ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); - if (ret != 0) { - LOG_ERR("XEC ADC V2 pinctrl setup failed (%d)", ret); - return ret; - } - - regs->config_reg = XEC_ADC_CFG_CLK_VAL(DT_INST_PROP(0, clktime)); - - regs->control_reg = XEC_ADC_CTRL_ACTIVATE - | XEC_ADC_CTRL_POWER_SAVER_DIS - | XEC_ADC_CTRL_SINGLE_DONE_STATUS - | XEC_ADC_CTRL_REPEAT_DONE_STATUS; - - adc_xec_girq_dis(cfg->girq_repeat, cfg->girq_repeat_pos); - adc_xec_girq_clr(cfg->girq_repeat, cfg->girq_repeat_pos); - adc_xec_girq_dis(cfg->girq_single, cfg->girq_single_pos); - adc_xec_girq_clr(cfg->girq_single, cfg->girq_single_pos); - adc_xec_girq_en(cfg->girq_single, cfg->girq_single_pos); - - IRQ_CONNECT(DT_INST_IRQN(0), - DT_INST_IRQ(0, priority), - adc_xec_single_isr, DEVICE_DT_INST_GET(0), 0); - irq_enable(DT_INST_IRQN(0)); - - adc_context_unlock_unconditionally(&data->ctx); - - return 0; -} - -PINCTRL_DT_INST_DEFINE(0); - -static struct adc_xec_config adc_xec_dev_cfg_0 = { - .regs = (struct adc_xec_regs *)(DT_INST_REG_ADDR(0)), - .girq_single = (uint8_t)(DT_INST_PROP_BY_IDX(0, girqs, 0)), - .girq_single_pos = (uint8_t)(DT_INST_PROP_BY_IDX(0, girqs, 1)), - .girq_repeat = (uint8_t)(DT_INST_PROP_BY_IDX(0, girqs, 2)), - .girq_repeat_pos = (uint8_t)(DT_INST_PROP_BY_IDX(0, girqs, 3)), - .pcr_regidx = (uint8_t)(DT_INST_PROP_BY_IDX(0, pcrs, 0)), - .pcr_bitpos = (uint8_t)(DT_INST_PROP_BY_IDX(0, pcrs, 1)), - .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0), -}; - -static struct adc_xec_data adc_xec_dev_data_0 = { - ADC_CONTEXT_INIT_TIMER(adc_xec_dev_data_0, ctx), - ADC_CONTEXT_INIT_LOCK(adc_xec_dev_data_0, ctx), - ADC_CONTEXT_INIT_SYNC(adc_xec_dev_data_0, ctx), -}; - -PM_DEVICE_DT_INST_DEFINE(0, adc_xec_pm_action); - -DEVICE_DT_INST_DEFINE(0, adc_xec_init, PM_DEVICE_DT_INST_GET(0), - &adc_xec_dev_data_0, &adc_xec_dev_cfg_0, - PRE_KERNEL_1, CONFIG_ADC_INIT_PRIORITY, - &adc_xec_api); diff --git a/dts/arm/microchip/mec1501hsz.dtsi b/dts/arm/microchip/mec1501hsz.dtsi index 61ecf96833d2..aad3dadf8274 100644 --- a/dts/arm/microchip/mec1501hsz.dtsi +++ b/dts/arm/microchip/mec1501hsz.dtsi @@ -416,7 +416,7 @@ #pwm-cells = <3>; }; adc0: adc@40007c00 { - compatible = "microchip,xec-adc-v2"; + compatible = "microchip,xec-adc"; reg = <0x40007c00 0x90>; interrupts = <78 0>, <79 0>; girqs = <17 8>, <17 9>; diff --git a/dts/arm/microchip/mec172xnsz.dtsi b/dts/arm/microchip/mec172xnsz.dtsi index e07f5c523729..099a976d846f 100644 --- a/dts/arm/microchip/mec172xnsz.dtsi +++ b/dts/arm/microchip/mec172xnsz.dtsi @@ -688,7 +688,7 @@ status = "disabled"; }; adc0: adc@40007c00 { - compatible = "microchip,xec-adc-v2"; + compatible = "microchip,xec-adc"; reg = <0x40007c00 0x90>; interrupts = <78 0>, <79 0>; girqs = <17 8>, <17 9>; diff --git a/dts/bindings/adc/microchip,xec-adc-v2.yaml b/dts/bindings/adc/microchip,xec-adc-v2.yaml deleted file mode 100644 index fd8abbfe60e5..000000000000 --- a/dts/bindings/adc/microchip,xec-adc-v2.yaml +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) 2019, Intel Corporation -# Copyright (c) 2021, Microchip Technology Inc. -# SPDX-License-Identifier: Apache-2.0 - -description: Microchip XEC ADC - -compatible: "microchip,xec-adc-v2" - -include: [adc-controller.yaml, pinctrl-device.yaml] - -properties: - reg: - required: true - - interrupts: - required: true - - "#io-channel-cells": - const: 1 - - girqs: - type: array - required: true - description: Array of pairs of GIRQ number and bit position - - pcrs: - type: array - required: true - description: ADC PCR register index and bit position - - clktime: - type: int - required: true - description: ADC clock high & low time count value <1:255> - - pinctrl-0: - required: true - - pinctrl-names: - required: true - -io-channel-cells: - - input diff --git a/dts/bindings/adc/microchip,xec-adc.yaml b/dts/bindings/adc/microchip,xec-adc.yaml index 81be1734eb7b..d642e11130c0 100644 --- a/dts/bindings/adc/microchip,xec-adc.yaml +++ b/dts/bindings/adc/microchip,xec-adc.yaml @@ -1,4 +1,5 @@ # Copyright (c) 2019, Intel Corporation +# Copyright (c) 2021, Microchip Technology Inc. # SPDX-License-Identifier: Apache-2.0 description: Microchip XEC ADC @@ -17,6 +18,16 @@ properties: "#io-channel-cells": const: 1 + girqs: + type: array + required: true + description: Array of pairs of GIRQ number and bit position + + pcrs: + type: array + required: true + description: ADC PCR register index and bit position + clktime: type: int required: true From 754920a74f57eb05a5a9c3eb06ea2222ca454f66 Mon Sep 17 00:00:00 2001 From: Manimaran A Date: Sun, 5 Mar 2023 13:21:16 +0530 Subject: [PATCH 0724/1906] drivers: adc: microchip: Added MEC15xx board overlay Added MEC15xx board overlay in sample folder. Signed-off-by: Manimaran A --- .../adc/boards/mec15xxevb_assy6853.overlay | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 samples/drivers/adc/boards/mec15xxevb_assy6853.overlay diff --git a/samples/drivers/adc/boards/mec15xxevb_assy6853.overlay b/samples/drivers/adc/boards/mec15xxevb_assy6853.overlay new file mode 100644 index 000000000000..3307849fdaaf --- /dev/null +++ b/samples/drivers/adc/boards/mec15xxevb_assy6853.overlay @@ -0,0 +1,44 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2023 Microchip Technology Inc. + */ + +/ { + zephyr,user { + io-channels = <&adc0 4>, <&adc0 5>, <&adc0 6>, <&adc0 7>; + }; +}; +&adc0 { + #address-cells = <1>; + #size-cells = <0>; + + channel@4 { + reg = <4>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = <0>; + zephyr,resolution = <12>; + }; + channel@5 { + reg = <5>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = <0>; + zephyr,resolution = <12>; + }; + channel@6 { + reg = <6>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = <0>; + zephyr,resolution = <12>; + }; + channel@7 { + reg = <7>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = <0>; + zephyr,resolution = <12>; + }; +}; From c42a1559889ba3ad28d18eb991b55969c893377d Mon Sep 17 00:00:00 2001 From: Manimaran A Date: Tue, 7 Mar 2023 16:37:04 +0530 Subject: [PATCH 0725/1906] driver: clock control: Microchip XEC fix missing domain parameter The clock control driver requires three pieces of information: PCR register index, bit position, and clock domain. Clock domain was missing from DT information and MCHP macros. Signed-off-by: Manimaran A --- drivers/interrupt_controller/intc_mchp_ecia_xec.c | 3 ++- dts/arm/microchip/mec1501hsz.dtsi | 2 +- dts/arm/microchip/mec172xnsz.dtsi | 5 ++--- dts/bindings/clock/microchip,xec-pcr.yaml | 3 ++- soc/arm/microchip_mec/common/soc_pcr.h | 5 +++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/interrupt_controller/intc_mchp_ecia_xec.c b/drivers/interrupt_controller/intc_mchp_ecia_xec.c index fec5a3b47dd6..977ad4a56fac 100644 --- a/drivers/interrupt_controller/intc_mchp_ecia_xec.c +++ b/drivers/interrupt_controller/intc_mchp_ecia_xec.c @@ -47,7 +47,8 @@ #define ECIA_XEC_PCR_INFO \ MCHP_XEC_PCR_SCR_ENCODE(DT_INST_CLOCKS_CELL(0, regidx), \ - DT_INST_CLOCKS_CELL(0, bitpos)) + DT_INST_CLOCKS_CELL(0, bitpos), \ + DT_INST_CLOCKS_CELL(0, domain)) struct xec_girq_config { uintptr_t base; diff --git a/dts/arm/microchip/mec1501hsz.dtsi b/dts/arm/microchip/mec1501hsz.dtsi index aad3dadf8274..6b817d53fbc1 100644 --- a/dts/arm/microchip/mec1501hsz.dtsi +++ b/dts/arm/microchip/mec1501hsz.dtsi @@ -61,7 +61,7 @@ /* pin configured only if the sources is set to PIN */ pinctrl-0 = <&clk_32khz_in_gpio165>; pinctrl-names = "default"; - #clock-cells = <2>; + #clock-cells = <3>; }; ecia: ecia@4000e000 { reg = <0x4000e000 0x400>; diff --git a/dts/arm/microchip/mec172xnsz.dtsi b/dts/arm/microchip/mec172xnsz.dtsi index 099a976d846f..8a7511dea388 100644 --- a/dts/arm/microchip/mec172xnsz.dtsi +++ b/dts/arm/microchip/mec172xnsz.dtsi @@ -59,13 +59,13 @@ /* pin configured only if one of the sources is set to PIN */ pinctrl-0 = <&clk_32khz_in_gpio165>; pinctrl-names = "default"; - #clock-cells = <2>; + #clock-cells = <3>; }; ecia: ecia@4000e000 { compatible = "microchip,xec-ecia"; reg = <0x4000e000 0x400>; direct-capable-girqs = <13 14 15 16 17 18 19 20 21 23>; - clocks = <&pcr 1 0>; + clocks = <&pcr 1 0 MCHP_XEC_PCR_CLK_PERIPH>; #address-cells = <1>; #size-cells = <1>; @@ -721,7 +721,6 @@ interrupts = <91 2>; girqs = < MCHP_XEC_ECIA(18, 1, 10, 91) >; pcrs = <4 8>; - clocks = <&pcr 1 0>; clock-frequency = <12000000>; lines = <1>; chip-select = <0>; diff --git a/dts/bindings/clock/microchip,xec-pcr.yaml b/dts/bindings/clock/microchip,xec-pcr.yaml index 2bd974400f2d..5a07aec6d40a 100644 --- a/dts/bindings/clock/microchip,xec-pcr.yaml +++ b/dts/bindings/clock/microchip,xec-pcr.yaml @@ -94,8 +94,9 @@ properties: required: true "#clock-cells": - const: 2 + const: 3 clock-cells: - regidx - bitpos + - domain diff --git a/soc/arm/microchip_mec/common/soc_pcr.h b/soc/arm/microchip_mec/common/soc_pcr.h index 81ce966b8e14..ea29f4a56d14 100644 --- a/soc/arm/microchip_mec/common/soc_pcr.h +++ b/soc/arm/microchip_mec/common/soc_pcr.h @@ -12,8 +12,9 @@ extern "C" { #endif /* slp_idx = [0, 4], bitpos = [0, 31] refer above */ -#define MCHP_XEC_PCR_SCR_ENCODE(slp_idx, bitpos) \ - (((uint16_t)(slp_idx) & 0x7u) | (((uint16_t)bitpos & 0x1fu) << 3)) +#define MCHP_XEC_PCR_SCR_ENCODE(slp_idx, bitpos, domain) \ + ((((uint32_t)(domain) & 0xff) << 24) | (((bitpos) & 0x1f) << 3) \ + | ((uint32_t)(slp_idx) & 0x7)) #define MCHP_XEC_PCR_SCR_GET_IDX(e) ((e) & 0x7u) #define MCHP_XEC_PCR_SCR_GET_BITPOS(e) (((e) & 0xf8u) >> 3) From f6619a86881d638655ef2c848d2b8a76237c95bc Mon Sep 17 00:00:00 2001 From: Jay Vasanth Date: Mon, 12 Dec 2022 17:56:06 -0500 Subject: [PATCH 0726/1906] drivers: espi: Update Microchip MEC172x eSPI virtual wires to use DT Modify Mircrochip MEC172x eSPI driver to get eSPI virtual wire hardware routing from device tree. Signed-off-by: Jay Vasanth --- drivers/espi/espi_mchp_xec_v2.c | 284 ++++++++++++------ drivers/espi/espi_mchp_xec_v2.h | 11 +- .../microchip/mec172x/mec172x-vw-routing.dtsi | 127 +++++++- .../espi/microchip,xec-espi-vw-routing.yaml | 30 +- soc/arm/microchip_mec/common/soc_dt.h | 22 ++ 5 files changed, 352 insertions(+), 122 deletions(-) diff --git a/drivers/espi/espi_mchp_xec_v2.c b/drivers/espi/espi_mchp_xec_v2.c index 3c54086e0ff8..618b2ddc73cc 100644 --- a/drivers/espi/espi_mchp_xec_v2.c +++ b/drivers/espi/espi_mchp_xec_v2.c @@ -84,7 +84,7 @@ LOG_MODULE_REGISTER(espi, CONFIG_ESPI_LOG_LEVEL); * 4h | SMVW00 | PME# | WAKE# | res | OOB_RST_ACK | * 5h | SMVW01 | SLV_BOOT_STS | ERR_NONFATAL | ERR_FATAL | SLV_BT_DONE | * 6h | SMVW02 | HOST_RST_ACK | RCIN# | SMI# | SCI# | - * 7h | MSVW02 | res | res | res | HOS_RST_WARN| + * 7h | MSVW02 | res | NMIOUT# | SMIOUT# | HOS_RST_WARN| * ------------------------------------------------------------------------| * Platform specific virtual wires * ------------------------------------------------------------------------| @@ -97,74 +97,53 @@ LOG_MODULE_REGISTER(espi, CONFIG_ESPI_LOG_LEVEL); * 46h | SMVW05 | generic | generic | generic | generic | * 47h | MSVW07 | res | res | res | HOST_C10 | * 4Ah | MSVW08 | res | res | DNX_WARN | res | + * These are configurable by overriding device tree vw routing | + * 50h | SMVW06 | ocb_3 | ocb_2 | ocb_1 | ocb_0 | + * 51h | SMVW07 | gpio_7 | gpio_6 | gpio_5 | gpio_4 | + * 52h | SMVW08 | gpio_11 | gpio_10 | gpio_9 | gpio_8 | */ - static const struct xec_signal vw_tbl[] = { - /* MSVW00 */ - [ESPI_VWIRE_SIGNAL_SLP_S3] = {MCHP_MSVW00, ESPI_VWIRE_SRC_ID0, - ESPI_MASTER_TO_SLAVE}, - [ESPI_VWIRE_SIGNAL_SLP_S4] = {MCHP_MSVW00, ESPI_VWIRE_SRC_ID1, - ESPI_MASTER_TO_SLAVE}, - [ESPI_VWIRE_SIGNAL_SLP_S5] = {MCHP_MSVW00, ESPI_VWIRE_SRC_ID2, - ESPI_MASTER_TO_SLAVE}, - /* MSVW01 */ - [ESPI_VWIRE_SIGNAL_SUS_STAT] = {MCHP_MSVW01, ESPI_VWIRE_SRC_ID0, - ESPI_MASTER_TO_SLAVE}, - [ESPI_VWIRE_SIGNAL_PLTRST] = {MCHP_MSVW01, ESPI_VWIRE_SRC_ID1, - ESPI_MASTER_TO_SLAVE}, - [ESPI_VWIRE_SIGNAL_OOB_RST_WARN] = {MCHP_MSVW01, ESPI_VWIRE_SRC_ID2, - ESPI_MASTER_TO_SLAVE}, - /* SMVW00 */ - [ESPI_VWIRE_SIGNAL_OOB_RST_ACK] = {MCHP_SMVW00, ESPI_VWIRE_SRC_ID0, - ESPI_SLAVE_TO_MASTER}, - [ESPI_VWIRE_SIGNAL_WAKE] = {MCHP_SMVW00, ESPI_VWIRE_SRC_ID2, - ESPI_SLAVE_TO_MASTER}, - [ESPI_VWIRE_SIGNAL_PME] = {MCHP_SMVW00, ESPI_VWIRE_SRC_ID3, - ESPI_SLAVE_TO_MASTER}, - /* SMVW01 */ - [ESPI_VWIRE_SIGNAL_SLV_BOOT_DONE] = {MCHP_SMVW01, ESPI_VWIRE_SRC_ID0, - ESPI_SLAVE_TO_MASTER}, - [ESPI_VWIRE_SIGNAL_ERR_FATAL] = {MCHP_SMVW01, ESPI_VWIRE_SRC_ID1, - ESPI_SLAVE_TO_MASTER}, - [ESPI_VWIRE_SIGNAL_ERR_NON_FATAL] = {MCHP_SMVW01, ESPI_VWIRE_SRC_ID2, - ESPI_SLAVE_TO_MASTER}, - [ESPI_VWIRE_SIGNAL_SLV_BOOT_STS] = {MCHP_SMVW01, ESPI_VWIRE_SRC_ID3, - ESPI_SLAVE_TO_MASTER}, - /* SMVW02 */ - [ESPI_VWIRE_SIGNAL_SCI] = {MCHP_SMVW02, ESPI_VWIRE_SRC_ID0, - ESPI_SLAVE_TO_MASTER}, - [ESPI_VWIRE_SIGNAL_SMI] = {MCHP_SMVW02, ESPI_VWIRE_SRC_ID1, - ESPI_SLAVE_TO_MASTER}, - [ESPI_VWIRE_SIGNAL_RST_CPU_INIT] = {MCHP_SMVW02, ESPI_VWIRE_SRC_ID2, - ESPI_SLAVE_TO_MASTER}, - [ESPI_VWIRE_SIGNAL_HOST_RST_ACK] = {MCHP_SMVW02, ESPI_VWIRE_SRC_ID3, - ESPI_SLAVE_TO_MASTER}, - /* MSVW02 */ - [ESPI_VWIRE_SIGNAL_HOST_RST_WARN] = {MCHP_MSVW02, ESPI_VWIRE_SRC_ID0, - ESPI_MASTER_TO_SLAVE}, - /* SMVW03 */ - [ESPI_VWIRE_SIGNAL_SUS_ACK] = {MCHP_SMVW03, ESPI_VWIRE_SRC_ID0, - ESPI_SLAVE_TO_MASTER}, - [ESPI_VWIRE_SIGNAL_DNX_ACK] = {MCHP_SMVW03, ESPI_VWIRE_SRC_ID1, - ESPI_SLAVE_TO_MASTER}, - /* MSVW03 */ - [ESPI_VWIRE_SIGNAL_SUS_WARN] = {MCHP_MSVW03, ESPI_VWIRE_SRC_ID0, - ESPI_MASTER_TO_SLAVE}, - [ESPI_VWIRE_SIGNAL_SUS_PWRDN_ACK] = {MCHP_MSVW03, ESPI_VWIRE_SRC_ID1, - ESPI_MASTER_TO_SLAVE}, - [ESPI_VWIRE_SIGNAL_SLP_A] = {MCHP_MSVW03, ESPI_VWIRE_SRC_ID3, - ESPI_MASTER_TO_SLAVE}, - /* MSVW04 */ - [ESPI_VWIRE_SIGNAL_SLP_LAN] = {MCHP_MSVW04, ESPI_VWIRE_SRC_ID0, - ESPI_MASTER_TO_SLAVE}, - [ESPI_VWIRE_SIGNAL_SLP_WLAN] = {MCHP_MSVW04, ESPI_VWIRE_SRC_ID1, - ESPI_MASTER_TO_SLAVE}, - /* MSVW07 */ - [ESPI_VWIRE_SIGNAL_HOST_C10] = {MCHP_MSVW07, ESPI_VWIRE_SRC_ID0, - ESPI_MASTER_TO_SLAVE}, - /* MSVW08 */ - [ESPI_VWIRE_SIGNAL_DNX_WARN] = {MCHP_MSVW08, ESPI_VWIRE_SRC_ID1, - ESPI_MASTER_TO_SLAVE}, + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLP_S3, vw_slp_s3_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLP_S4, vw_slp_s4_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLP_S5, vw_slp_s5_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OOB_RST_WARN, vw_oob_rst_warn), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_PLTRST, vw_pltrst_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SUS_STAT, vw_sus_stat_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_HOST_RST_WARN, vw_host_rst_warn), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_NMIOUT, vw_nmiout_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SMIOUT, vw_smiout_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLP_A, vw_slp_a_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SUS_PWRDN_ACK, vw_sus_pwrdn_ack), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SUS_WARN, vw_sus_warn_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLP_WLAN, vw_slp_wlan_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLP_LAN, vw_slp_lan_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_HOST_C10, vw_host_c10), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_DNX_WARN, vw_dnx_warn), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_PME, vw_pme_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_WAKE, vw_wake_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OOB_RST_ACK, vw_oob_rst_ack), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_BOOT_STS, vw_slave_boot_status), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_ERR_NON_FATAL, vw_error_non_fatal), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_ERR_FATAL, vw_error_fatal), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_BOOT_DONE, vw_slave_boot_done), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_HOST_RST_ACK, vw_host_rst_ack), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_RST_CPU_INIT, vw_rcin_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SMI, vw_smi_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SCI, vw_sci_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_DNX_ACK, vw_dnx_ack), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SUS_ACK, vw_sus_ack_n), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_0, vw_c2t_gpio_0), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_1, vw_c2t_gpio_1), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_2, vw_c2t_gpio_2), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_3, vw_c2t_gpio_3), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_4, vw_c2t_gpio_4), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_5, vw_c2t_gpio_5), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_6, vw_c2t_gpio_6), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_7, vw_c2t_gpio_7), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_0, vw_c2t_gpio_8), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_1, vw_c2t_gpio_9), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_2, vw_c2t_gpio_10), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_3, vw_c2t_gpio_11), }; /* Buffer size are expressed in bytes */ @@ -318,6 +297,7 @@ static int espi_xec_send_vwire(const struct device *dev, struct xec_signal signal_info = vw_tbl[signal]; uint8_t xec_id = signal_info.xec_reg_idx; uint8_t src_id = signal_info.bit; + uint8_t dir; uintptr_t regaddr; if ((src_id >= ESPI_VWIRE_SRC_ID_MAX) || @@ -325,13 +305,19 @@ static int espi_xec_send_vwire(const struct device *dev, return -EINVAL; } - if (signal_info.dir == ESPI_MASTER_TO_SLAVE) { + if (!((signal_info.flags >> ESPI_XEC_SIGNAL_FLAG_EN_POS) & BIT(0))) { + return -EIO; /* VW not enabled */ + } + + dir = (signal_info.flags >> ESPI_XEC_SIGNAL_FLAG_DIR_POS) & BIT(0); + + if (dir == ESPI_MASTER_TO_SLAVE) { regaddr = xec_msvw_addr(dev, xec_id); sys_write8(level, regaddr + MSVW_BI_SRC0 + src_id); } - if (signal_info.dir == ESPI_SLAVE_TO_MASTER) { + if (dir == ESPI_SLAVE_TO_MASTER) { regaddr = xec_smvw_addr(dev, xec_id); sys_write8(level, regaddr + SMVW_BI_SRC0 + src_id); @@ -356,6 +342,7 @@ static int espi_xec_receive_vwire(const struct device *dev, struct xec_signal signal_info = vw_tbl[signal]; uint8_t xec_id = signal_info.xec_reg_idx; uint8_t src_id = signal_info.bit; + uint8_t dir; uintptr_t regaddr; if ((src_id >= ESPI_VWIRE_SRC_ID_MAX) || @@ -363,12 +350,18 @@ static int espi_xec_receive_vwire(const struct device *dev, return -EINVAL; } - if (signal_info.dir == ESPI_MASTER_TO_SLAVE) { + if (!((signal_info.flags >> ESPI_XEC_SIGNAL_FLAG_EN_POS) & BIT(0))) { + return -EIO; /* VW not enabled */ + } + + dir = (signal_info.flags >> ESPI_XEC_SIGNAL_FLAG_DIR_POS) & BIT(0); + + if (dir == ESPI_MASTER_TO_SLAVE) { regaddr = xec_msvw_addr(dev, xec_id); *level = sys_read8(regaddr + MSVW_BI_SRC0 + src_id) & BIT(0); } - if (signal_info.dir == ESPI_SLAVE_TO_MASTER) { + if (dir == ESPI_SLAVE_TO_MASTER) { regaddr = xec_smvw_addr(dev, xec_id); *level = sys_read8(regaddr + SMVW_BI_SRC0 + src_id) & BIT(0); } @@ -1160,27 +1153,81 @@ static void vw_pltrst_handler(int girq_id, int src, void *user) espi_send_callbacks(&data->callbacks, dev, evt); } +static void vw_sus_stat_handler(int girq_id, int src, void *user) +{ + const struct device *dev = (const struct device *)user; + + notify_host_warning(dev, ESPI_VWIRE_SIGNAL_SUS_STAT); +} + +static void vw_slp_wlan_handler(int girq_id, int src, void *user) +{ + const struct device *dev = (const struct device *)user; + + notify_system_state(dev, ESPI_VWIRE_SIGNAL_SLP_WLAN); +} + +static void vw_slp_lan_handler(int girq_id, int src, void *user) +{ + const struct device *dev = (const struct device *)user; + + notify_system_state(dev, ESPI_VWIRE_SIGNAL_SLP_LAN); +} + +static void vw_host_c10_handler(int girq_id, int src, void *user) +{ + const struct device *dev = (const struct device *)user; + + notify_system_state(dev, ESPI_VWIRE_SIGNAL_HOST_C10); +} + +static void vw_nmiout_handler(int girq_id, int src, void *user) +{ + const struct device *dev = (const struct device *)user; + + notify_system_state(dev, ESPI_VWIRE_SIGNAL_NMIOUT); +} + +static void vw_smiout_handler(int girq_id, int src, void *user) +{ + const struct device *dev = (const struct device *)user; + + notify_system_state(dev, ESPI_VWIRE_SIGNAL_SMIOUT); +} + const struct espi_vw_isr m2s_vwires_isr[] = { - {ESPI_VWIRE_SIGNAL_SLP_S3, MCHP_MSVW00_GIRQ, MCHP_MSVW00_SRC0_GIRQ_POS, - vw_slp3_handler}, - {ESPI_VWIRE_SIGNAL_SLP_S4, MCHP_MSVW00_GIRQ, MCHP_MSVW00_SRC1_GIRQ_POS, - vw_slp4_handler}, - {ESPI_VWIRE_SIGNAL_SLP_S5, MCHP_MSVW00_GIRQ, MCHP_MSVW00_SRC2_GIRQ_POS, - vw_slp5_handler}, - {ESPI_VWIRE_SIGNAL_PLTRST, MCHP_MSVW01_GIRQ, MCHP_MSVW01_SRC1_GIRQ_POS, - vw_pltrst_handler}, + {ESPI_VWIRE_SIGNAL_SLP_S3, MCHP_MSVW00_GIRQ, + MCHP_MSVW00_SRC0_GIRQ_POS, vw_slp3_handler}, + {ESPI_VWIRE_SIGNAL_SLP_S4, MCHP_MSVW00_GIRQ, + MCHP_MSVW00_SRC1_GIRQ_POS, vw_slp4_handler}, + {ESPI_VWIRE_SIGNAL_SLP_S5, MCHP_MSVW00_GIRQ, + MCHP_MSVW00_SRC2_GIRQ_POS, vw_slp5_handler}, {ESPI_VWIRE_SIGNAL_OOB_RST_WARN, MCHP_MSVW01_GIRQ, MCHP_MSVW01_SRC2_GIRQ_POS, vw_oob_rst_handler}, + {ESPI_VWIRE_SIGNAL_PLTRST, MCHP_MSVW01_GIRQ, + MCHP_MSVW01_SRC1_GIRQ_POS, vw_pltrst_handler}, + {ESPI_VWIRE_SIGNAL_SUS_STAT, MCHP_MSVW01_GIRQ, + MCHP_MSVW01_SRC0_GIRQ_POS, vw_sus_stat_handler}, {ESPI_VWIRE_SIGNAL_HOST_RST_WARN, MCHP_MSVW02_GIRQ, MCHP_MSVW02_SRC0_GIRQ_POS, vw_host_rst_warn_handler}, - {ESPI_VWIRE_SIGNAL_SUS_WARN, MCHP_MSVW03_GIRQ, - MCHP_MSVW03_SRC0_GIRQ_POS, vw_sus_warn_handler}, - {ESPI_VWIRE_SIGNAL_SUS_PWRDN_ACK, MCHP_MSVW03_GIRQ, - MCHP_MSVW03_SRC1_GIRQ_POS, vw_sus_pwrdn_ack_handler}, + {ESPI_VWIRE_SIGNAL_NMIOUT, MCHP_MSVW02_GIRQ, + MCHP_MSVW02_SRC1_GIRQ_POS, vw_nmiout_handler}, + {ESPI_VWIRE_SIGNAL_SMIOUT, MCHP_MSVW02_GIRQ, + MCHP_MSVW02_SRC2_GIRQ_POS, vw_smiout_handler}, {ESPI_VWIRE_SIGNAL_SLP_A, MCHP_MSVW03_GIRQ, MCHP_MSVW03_SRC3_GIRQ_POS, vw_sus_slp_a_handler}, + {ESPI_VWIRE_SIGNAL_SUS_PWRDN_ACK, MCHP_MSVW03_GIRQ, + MCHP_MSVW03_SRC1_GIRQ_POS, vw_sus_pwrdn_ack_handler}, + {ESPI_VWIRE_SIGNAL_SUS_WARN, MCHP_MSVW03_GIRQ, + MCHP_MSVW03_SRC0_GIRQ_POS, vw_sus_warn_handler}, + {ESPI_VWIRE_SIGNAL_SLP_WLAN, MCHP_MSVW04_GIRQ, + MCHP_MSVW04_SRC1_GIRQ_POS, vw_slp_wlan_handler}, + {ESPI_VWIRE_SIGNAL_SLP_LAN, MCHP_MSVW04_GIRQ, + MCHP_MSVW04_SRC0_GIRQ_POS, vw_slp_lan_handler}, + {ESPI_VWIRE_SIGNAL_HOST_C10, MCHP_MSVW07_GIRQ, + MCHP_MSVW07_SRC0_GIRQ_POS, vw_host_c10_handler}, {ESPI_VWIRE_SIGNAL_DNX_WARN, MCHP_MSVW08_GIRQ, - MCHP_MSVW08_SRC1_GIRQ_POS, vw_sus_dnx_warn_handler} + MCHP_MSVW08_SRC1_GIRQ_POS, vw_sus_dnx_warn_handler}, }; static int espi_xec_init(const struct device *dev); @@ -1292,6 +1339,54 @@ static void espi_xec_connect_irqs(const struct device *dev) #endif } +/* Check each VW register set host index is present. + * Some VW's power up with the host index and others do not. + */ +static void xec_vw_config(const struct device *dev) +{ + for (int i = 0; i < ARRAY_SIZE(vw_tbl); i++) { + const struct xec_signal *p = &vw_tbl[i]; + uint32_t regaddr = xec_smvw_addr(dev, p->xec_reg_idx) + SMVW_BI_INDEX; + uint8_t dir = (p->flags >> ESPI_XEC_SIGNAL_FLAG_DIR_POS) & BIT(0); + uint8_t en = (p->flags & BIT(ESPI_XEC_SIGNAL_FLAG_EN_POS)); + + if (en) { + if (dir) { + regaddr = xec_msvw_addr(dev, p->xec_reg_idx); + regaddr += MSVW_BI_INDEX; + } + + if (sys_read8(regaddr) != p->host_idx) { + sys_write8(p->host_idx, regaddr); + } + } + } +} + +static int xec_register_vw_handlers(const struct device *dev) +{ + for (int i = 0; i < ARRAY_SIZE(m2s_vwires_isr); i++) { + const struct espi_vw_isr *vwi = &m2s_vwires_isr[i]; + struct xec_signal signal_info = vw_tbl[vwi->signal]; + uint8_t xec_id = signal_info.xec_reg_idx; + + /* enables interrupt in eSPI MSVWn register */ + xec_espi_vw_intr_ctrl(dev, xec_id, signal_info.bit, + MSVW_IRQ_SEL_EDGE_BOTH); + + /* register handler */ + int ret = mchp_xec_ecia_set_callback(vwi->girq_id, vwi->girq_pos, + vwi->the_isr, (void *)dev); + if (ret) { + return -EIO; + } + + mchp_xec_ecia_girq_src_en(vwi->girq_id, vwi->girq_pos); + } + + return 0; +} + /* * Initialize eSPI hardware and associated peripherals blocks using eSPI * as their host interface. @@ -1370,24 +1465,15 @@ static int espi_xec_init(const struct device *dev) regs->PCSTS = MCHP_ESPI_PC_STS_EN_CHG; regs->PCIEN |= MCHP_ESPI_PC_IEN_EN_CHG; + xec_vw_config(dev); + /* register VWire handlers with their aggregated GIRQs * in the ECIA driver */ - for (int i = 0; i < ARRAY_SIZE(m2s_vwires_isr); i++) { - const struct espi_vw_isr *vwi = &m2s_vwires_isr[i]; - struct xec_signal signal_info = vw_tbl[vwi->signal]; - uint8_t xec_id = signal_info.xec_reg_idx; - - /* enables interrupt in eSPI MSVWn register */ - xec_espi_vw_intr_ctrl(dev, xec_id, signal_info.bit, - MSVW_IRQ_SEL_EDGE_BOTH); - - /* register handler */ - ret = mchp_xec_ecia_set_callback(vwi->girq_id, vwi->girq_pos, - vwi->the_isr, (void *)dev); - __ASSERT_NO_MSG(ret == 0); - - mchp_xec_ecia_girq_src_en(vwi->girq_id, vwi->girq_pos); + ret = xec_register_vw_handlers(dev); + if (ret) { + LOG_ERR("XEX eSPI V2 register VW handlers error %d", ret); + return ret; } /* Enable interrupts for each logical channel enable assertion */ diff --git a/drivers/espi/espi_mchp_xec_v2.h b/drivers/espi/espi_mchp_xec_v2.h index dd456525ed08..2e3b9a1830a4 100644 --- a/drivers/espi/espi_mchp_xec_v2.h +++ b/drivers/espi/espi_mchp_xec_v2.h @@ -12,7 +12,7 @@ #include #include -#define ESPI_XEC_V2_DEBUG 1 +/* #define ESPI_XEC_V2_DEBUG 1 */ struct espi_isr { uint8_t girq_id; @@ -61,10 +61,14 @@ struct espi_xec_data { #define ESPI_XEC_DATA(dev) \ ((struct espi_xec_data * const)(dev)->data) +#define ESPI_XEC_SIGNAL_FLAG_EN_POS 0 +#define ESPI_XEC_SIGNAL_FLAG_DIR_POS 4 + struct xec_signal { - uint8_t xec_reg_idx; + uint8_t host_idx; uint8_t bit; - uint8_t dir; + uint8_t xec_reg_idx; + uint8_t flags; }; enum mchp_msvw_regs { @@ -104,7 +108,6 @@ enum xec_espi_girq_idx { max_girq_idx, }; - int xec_host_dev_init(const struct device *dev); int xec_host_dev_connect_irqs(const struct device *dev); diff --git a/dts/arm/microchip/mec172x/mec172x-vw-routing.dtsi b/dts/arm/microchip/mec172x/mec172x-vw-routing.dtsi index 8d3439abecda..8ac794e20f7c 100644 --- a/dts/arm/microchip/mec172x/mec172x-vw-routing.dtsi +++ b/dts/arm/microchip/mec172x/mec172x-vw-routing.dtsi @@ -4,8 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define MSVW 0 -#define SMVW 1 +#define MSVW 1 +#define SMVW 0 / { mchp-xec-espi-vw-routing { @@ -16,99 +16,216 @@ /* Host-index MSVW/SMVW MSVW/SMVW-index source */ vw-reg = <0x02 MSVW 0 0>; vw-girq = <24 0>; + status = "okay"; }; vw-slp-s4-n { vw-reg = <0x02 MSVW 0 1>; vw-girq = <24 1>; + status = "okay"; }; vw-slp-s5-n { vw-reg = <0x02 MSVW 0 2>; vw-girq = <24 2>; + status = "okay"; }; vw-sus-stat-n { vw-reg = <0x03 MSVW 1 0>; vw-girq = <24 4>; + status = "okay"; }; vw-pltrst-n { vw-reg = <0x03 MSVW 1 1>; vw-girq = <24 5>; + status = "okay"; }; vw-oob-rst-warn { vw-reg = <0x03 MSVW 1 2>; vw-girq = <24 6>; + status = "okay"; }; vw-host-rst-warn { vw-reg = <0x07 MSVW 2 0>; vw-girq = <24 8>; + status = "okay"; + }; + vw-smiout-n { + vw-reg = <0x07 MSVW 2 1>; + vw-girq = <24 9>; + status = "disabled"; + }; + vw-nmiout-n { + vw-reg = <0x07 MSVW 2 2>; + vw-girq = <24 10>; + status = "disabled"; }; vw-sus-warn-n { vw-reg = <0x41 MSVW 3 0>; vw-girq = <24 12>; + status = "okay"; }; vw-sus-pwrdn-ack { vw-reg = <0x41 MSVW 3 1>; vw-girq = <24 13>; + status = "okay"; }; vw-slp-a-n { vw-reg = <0x41 MSVW 3 3>; vw-girq = <24 15>; + status = "okay"; }; vw-slp-lan-n { vw-reg = <0x42 MSVW 4 0>; vw-girq = <24 16>; + status = "okay"; }; - vw-slp-wlen-n { + vw-slp-wlan-n { vw-reg = <0x42 MSVW 4 1>; vw-girq = <24 17>; + status = "okay"; }; vw-host-c10 { vw-reg = <0x47 MSVW 7 0>; vw-girq = <25 0>; + status = "okay"; }; vw-dnx-warn { vw-reg = <0x4a MSVW 8 1>; vw-girq = <25 5>; + status = "okay"; }; /* Device to Host (SMVW) do not have SoC interrupts */ vw-oob-rst-ack { vw-reg = <0x04 SMVW 0 0>; + status = "okay"; }; vw-wake-n { vw-reg = <0x04 SMVW 0 2>; + status = "okay"; }; vw-pme-n { vw-reg = <0x04 SMVW 0 3>; + status = "okay"; }; - vw-slave-boot-load-done { + vw-slave-boot-done { vw-reg = <0x05 SMVW 1 0>; + status = "okay"; }; vw-error-fatal { vw-reg = <0x05 SMVW 1 1>; + status = "okay"; }; vw-error-non-fatal { vw-reg = <0x05 SMVW 1 2>; + status = "okay"; }; - vw-slave-boot-load-status { + vw-slave-boot-status { vw-reg = <0x05 SMVW 1 3>; + status = "okay"; }; vw-sci-n { vw-reg = <0x06 SMVW 2 0>; + status = "okay"; }; vw-smi-n { vw-reg = <0x06 SMVW 2 1>; + status = "okay"; }; vw-rcin-n { vw-reg = <0x06 SMVW 2 2>; + status = "okay"; }; vw-host-rst-ack { vw-reg = <0x06 SMVW 2 3>; + status = "okay"; }; vw-sus-ack-n { vw-reg = <0x40 SMVW 3 0>; + status = "okay"; }; vw-dnx-ack { vw-reg = <0x40 SMVW 3 1>; + status = "okay"; + }; + vw-c2t-gpio-0 { + vw-reg = <0x50 SMVW 6 0>; + status = "disabled"; + }; + vw-c2t-gpio-1 { + vw-reg = <0x50 SMVW 6 1>; + status = "disabled"; + }; + vw-c2t-gpio-2 { + vw-reg = <0x50 SMVW 6 2>; + status = "disabled"; + }; + vw-c2t-gpio-3 { + vw-reg = <0x50 SMVW 6 3>; + status = "disabled"; + }; + vw-c2t-gpio-4 { + vw-reg = <0x51 SMVW 7 0>; + status = "disabled"; + }; + vw-c2t-gpio-5 { + vw-reg = <0x51 SMVW 7 1>; + status = "disabled"; + }; + vw-c2t-gpio-6 { + vw-reg = <0x51 SMVW 7 2>; + status = "disabled"; + }; + vw-c2t-gpio-7 { + vw-reg = <0x51 SMVW 7 3>; + status = "disabled"; + }; + vw-c2t-gpio-8 { + vw-reg = <0x52 SMVW 8 0>; + status = "disabled"; + }; + vw-c2t-gpio-9 { + vw-reg = <0x52 SMVW 8 1>; + status = "disabled"; + }; + vw-c2t-gpio-10 { + vw-reg = <0x52 SMVW 8 2>; + status = "disabled"; + }; + vw-c2t-gpio-11 { + vw-reg = <0x52 SMVW 8 3>; + status = "disabled"; + }; + vw-c2t-gpio-12 { + vw-reg = <0x53 SMVW 9 0>; + status = "disabled"; + }; + vw-c2t-gpio-13 { + vw-reg = <0x53 SMVW 9 1>; + status = "disabled"; + }; + vw-c2t-gpio-14 { + vw-reg = <0x53 SMVW 9 2>; + status = "disabled"; + }; + vw-c2t-gpio-15 { + vw-reg = <0x53 SMVW 9 3>; + status = "disabled"; + }; + vw-c2t-gpio-16 { + vw-reg = <0x54 SMVW 10 0>; + status = "disabled"; + }; + vw-c2t-gpio-17 { + vw-reg = <0x54 SMVW 10 1>; + status = "disabled"; + }; + vw-c2t-gpio-18 { + vw-reg = <0x54 SMVW 10 2>; + status = "disabled"; + }; + vw-c2t-gpio-19 { + vw-reg = <0x54 SMVW 10 3>; + status = "disabled"; }; }; }; diff --git a/dts/bindings/espi/microchip,xec-espi-vw-routing.yaml b/dts/bindings/espi/microchip,xec-espi-vw-routing.yaml index 89e2f709926a..07aa443d7471 100644 --- a/dts/bindings/espi/microchip,xec-espi-vw-routing.yaml +++ b/dts/bindings/espi/microchip,xec-espi-vw-routing.yaml @@ -5,20 +5,22 @@ description: Microchip XEC eSPI Virtual Wire routing compatible: "microchip,xec-espi-vw-routing" +include: [base.yaml] + child-binding: - description: | - Child node containing the routing of an eSPI virtual wire to the SoC - VW registers and ECIA GIRQ registers. - properties: - vw-reg: - type: array - required: true - description: vw signal's register index and vw bitmask. + description: | + Child node containing the routing of an eSPI virtual wire to the SoC + VW registers and ECIA GIRQ registers. + properties: + vw-reg: + type: array + required: true + description: vw signal's register index and vw bitmask. - vw-girq: - type: array - description: | - Routing of MSVW source to aggregated GIRQs + vw-girq: + type: array + description: | + Routing of MSVW source to aggregated GIRQs - Example: OOB_RST_WARN is source 2 of MSVW01 routed to GIRQ24 b[5] - vw-girq = <24 5>; + For example, OOB_RST_WARN is source 2 of MSVW01 routed + to GIRQ24 b[5]. vw-girq = <24 5>; diff --git a/soc/arm/microchip_mec/common/soc_dt.h b/soc/arm/microchip_mec/common/soc_dt.h index f1263d1b81e6..eb2b497e6fb0 100644 --- a/soc/arm/microchip_mec/common/soc_dt.h +++ b/soc/arm/microchip_mec/common/soc_dt.h @@ -7,6 +7,8 @@ #ifndef _MICROCHIP_XEC_SOC_DT_H_ #define _MICROCHIP_XEC_SOC_DT_H_ +#include + #define MCHP_XEC_NO_PULL 0x0 #define MCHP_XEC_PULL_UP 0x1 #define MCHP_XEC_PULL_DOWN 0x2 @@ -23,4 +25,24 @@ #define MCHP_XEC_DRVSTR_12MA 0x4 #define MCHP_XEC_FUNC_INVERT 0x1 +#define MCHP_DT_NODE_FROM_VWTABLE(name) DT_CHILD(DT_PATH(mchp_xec_espi_vw_routing), name) +#define MCHP_DT_VW_NODE_HAS_STATUS(name) DT_NODE_HAS_STATUS(MCHP_DT_NODE_FROM_VWTABLE(name), okay) + +/* Macro to store DT status in bit 0 and VW direction in bit 4 of flags */ +#define MCHP_DT_ESPI_VW_FLAGS(vw) \ + ((uint8_t)(MCHP_DT_VW_NODE_HAS_STATUS(vw)) & 0x01U) \ + | (((uint8_t)DT_PROP_BY_IDX(MCHP_DT_NODE_FROM_VWTABLE(vw), vw_reg, 1)) << 4) + +/* Macro for the eSPI driver VW table entries. + * e is a symbol from enum espi_vwire_signal. + * vw is a node from the XEC ESPI VW routing file. + */ +#define MCHP_DT_ESPI_VW_ENTRY(e, vw) \ +[(e)] = { \ + .host_idx = DT_PROP_BY_IDX(MCHP_DT_NODE_FROM_VWTABLE(vw), vw_reg, 0), \ + .bit = DT_PROP_BY_IDX(MCHP_DT_NODE_FROM_VWTABLE(vw), vw_reg, 3), \ + .xec_reg_idx = DT_PROP_BY_IDX(MCHP_DT_NODE_FROM_VWTABLE(vw), vw_reg, 2), \ + .flags = MCHP_DT_ESPI_VW_FLAGS(vw), \ +} + #endif /* _MICROCHIP_XEC_SOC_DT_H_ */ From b0ce525b909392e91272d6e9ac9deacfa8f5b8d8 Mon Sep 17 00:00:00 2001 From: Jay Vasanth Date: Thu, 16 Feb 2023 15:58:54 +0530 Subject: [PATCH 0727/1906] drivers: espi: Microchip MEC172x eSPI VW initialization update Change device tree VW routing to a form allowing overrides. Add two new DT optional properties for specifying the reset source and reset value of each virtual wire. Only virtual wires that are enabled using the status property are modified. NOTE: eSPI virtual wires are controlled in groups of 4 by hardware. The optional reset signal source properties applies to all four virtual wires in the group. If this field is changed from the hardware default, it should be changed for only one virtual wire in the group. If the property exists in more than one wire in the group it must be set to the same value. Signed-off-by: Jay Vasanth --- drivers/espi/espi_mchp_xec_v2.c | 105 +++++++++++++----- drivers/espi/espi_mchp_xec_v2.h | 3 - .../microchip/mec172x/mec172x-vw-routing.dtsi | 98 ++++++++-------- .../espi/microchip,xec-espi-vw-routing.yaml | 57 +++++++--- soc/arm/microchip_mec/common/soc_dt.h | 23 +++- 5 files changed, 186 insertions(+), 100 deletions(-) diff --git a/drivers/espi/espi_mchp_xec_v2.c b/drivers/espi/espi_mchp_xec_v2.c index 618b2ddc73cc..d1099292d49c 100644 --- a/drivers/espi/espi_mchp_xec_v2.c +++ b/drivers/espi/espi_mchp_xec_v2.c @@ -132,18 +132,18 @@ static const struct xec_signal vw_tbl[] = { MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SCI, vw_sci_n), MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_DNX_ACK, vw_dnx_ack), MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SUS_ACK, vw_sus_ack_n), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_0, vw_c2t_gpio_0), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_1, vw_c2t_gpio_1), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_2, vw_c2t_gpio_2), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_3, vw_c2t_gpio_3), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_4, vw_c2t_gpio_4), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_5, vw_c2t_gpio_5), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_6, vw_c2t_gpio_6), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_7, vw_c2t_gpio_7), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_0, vw_c2t_gpio_8), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_1, vw_c2t_gpio_9), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_2, vw_c2t_gpio_10), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_3, vw_c2t_gpio_11), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_0, vw_t2c_gpio_0), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_1, vw_t2c_gpio_1), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_2, vw_t2c_gpio_2), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_3, vw_t2c_gpio_3), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_4, vw_t2c_gpio_4), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_5, vw_t2c_gpio_5), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_6, vw_t2c_gpio_6), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_7, vw_t2c_gpio_7), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_0, vw_t2c_gpio_8), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_1, vw_t2c_gpio_9), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_2, vw_t2c_gpio_10), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_3, vw_t2c_gpio_11), }; /* Buffer size are expressed in bytes */ @@ -305,11 +305,11 @@ static int espi_xec_send_vwire(const struct device *dev, return -EINVAL; } - if (!((signal_info.flags >> ESPI_XEC_SIGNAL_FLAG_EN_POS) & BIT(0))) { + if (!(signal_info.flags & BIT(MCHP_DT_ESPI_VW_FLAG_STATUS_POS))) { return -EIO; /* VW not enabled */ } - dir = (signal_info.flags >> ESPI_XEC_SIGNAL_FLAG_DIR_POS) & BIT(0); + dir = (signal_info.flags >> MCHP_DT_ESPI_VW_FLAG_DIR_POS) & BIT(0); if (dir == ESPI_MASTER_TO_SLAVE) { regaddr = xec_msvw_addr(dev, xec_id); @@ -350,11 +350,11 @@ static int espi_xec_receive_vwire(const struct device *dev, return -EINVAL; } - if (!((signal_info.flags >> ESPI_XEC_SIGNAL_FLAG_EN_POS) & BIT(0))) { + if (!(signal_info.flags & BIT(MCHP_DT_ESPI_VW_FLAG_STATUS_POS))) { return -EIO; /* VW not enabled */ } - dir = (signal_info.flags >> ESPI_XEC_SIGNAL_FLAG_DIR_POS) & BIT(0); + dir = (signal_info.flags >> MCHP_DT_ESPI_VW_FLAG_DIR_POS) & BIT(0); if (dir == ESPI_MASTER_TO_SLAVE) { regaddr = xec_msvw_addr(dev, xec_id); @@ -1339,26 +1339,75 @@ static void espi_xec_connect_irqs(const struct device *dev) #endif } +/* MSVW is a 96-bit register and SMVW is a 64-bit register. + * Each MSVW/SMVW controls a group of 4 eSPI virtual wires. + * Host index located in b[7:0] + * Reset source located in b[9:8] + * Reset VW values SRC[3:0] located in b[15:12]. + * MSVW current VW state values located in bits[64, 72, 80, 88] + * SMVW current VW state values located in bits[32, 40, 48, 56] + */ +static void xec_vw_cfg_properties(const struct xec_signal *p, uint32_t regaddr, uint8_t dir) +{ + uint32_t src_ofs = 4u; + uint8_t src_pos = (8u * p->bit); + uint8_t rst_state = (p->flags >> MCHP_DT_ESPI_VW_FLAG_RST_STATE_POS) + & MCHP_DT_ESPI_VW_FLAG_RST_STATE_MSK0; + uint8_t rst_src = rst_src = (p->flags >> MCHP_DT_ESPI_VW_FLAG_RST_SRC_POS) + & MCHP_DT_ESPI_VW_FLAG_RST_SRC_MSK0; + + if (dir) { + src_ofs = 8u; + } + + if (rst_state || rst_src) { /* change reset source or state ? */ + sys_write8(0, regaddr); /* disable register */ + + uint8_t temp = sys_read8(regaddr + 1u); + + if (rst_state) { /* change reset state and default value of this vwire? */ + rst_state--; + if (rst_state) { + temp |= BIT(p->bit + 4u); + sys_set_bit(regaddr + src_ofs, src_pos); + } else { + temp |= ~BIT(p->bit + 4u); + sys_clear_bit(regaddr + src_ofs, src_pos); + } + } + + if (rst_src) { /* change reset source of all vwires in this group? */ + rst_src--; + temp = (temp & ~0x3u) | (rst_src & 0x3u); + } + + sys_write8(temp, regaddr + 1u); + } + + if (sys_read8(regaddr) != p->host_idx) { + sys_write8(p->host_idx, regaddr); + } +} + /* Check each VW register set host index is present. * Some VW's power up with the host index and others do not. + * NOTE: Virtual wires are in groups of 4. Disabling one wire in a group + * will disable all wires in the group. We do not implement disabling. */ static void xec_vw_config(const struct device *dev) { - for (int i = 0; i < ARRAY_SIZE(vw_tbl); i++) { + for (int i = ESPI_VWIRE_SIGNAL_SLV_GPIO_0; i < ARRAY_SIZE(vw_tbl); i++) { const struct xec_signal *p = &vw_tbl[i]; - uint32_t regaddr = xec_smvw_addr(dev, p->xec_reg_idx) + SMVW_BI_INDEX; - uint8_t dir = (p->flags >> ESPI_XEC_SIGNAL_FLAG_DIR_POS) & BIT(0); - uint8_t en = (p->flags & BIT(ESPI_XEC_SIGNAL_FLAG_EN_POS)); + uint32_t regaddr = xec_smvw_addr(dev, p->xec_reg_idx); + uint8_t dir = (p->flags >> MCHP_DT_ESPI_VW_FLAG_DIR_POS) & BIT(0); + uint8_t en = (p->flags & BIT(MCHP_DT_ESPI_VW_FLAG_STATUS_POS)); - if (en) { - if (dir) { - regaddr = xec_msvw_addr(dev, p->xec_reg_idx); - regaddr += MSVW_BI_INDEX; - } + if (dir) { + regaddr = xec_msvw_addr(dev, p->xec_reg_idx); + } - if (sys_read8(regaddr) != p->host_idx) { - sys_write8(p->host_idx, regaddr); - } + if (en) { + xec_vw_cfg_properties(p, regaddr, dir); } } } diff --git a/drivers/espi/espi_mchp_xec_v2.h b/drivers/espi/espi_mchp_xec_v2.h index 2e3b9a1830a4..a9236e1c0c39 100644 --- a/drivers/espi/espi_mchp_xec_v2.h +++ b/drivers/espi/espi_mchp_xec_v2.h @@ -61,9 +61,6 @@ struct espi_xec_data { #define ESPI_XEC_DATA(dev) \ ((struct espi_xec_data * const)(dev)->data) -#define ESPI_XEC_SIGNAL_FLAG_EN_POS 0 -#define ESPI_XEC_SIGNAL_FLAG_DIR_POS 4 - struct xec_signal { uint8_t host_idx; uint8_t bit; diff --git a/dts/arm/microchip/mec172x/mec172x-vw-routing.dtsi b/dts/arm/microchip/mec172x/mec172x-vw-routing.dtsi index 8ac794e20f7c..a9ed8e01d96a 100644 --- a/dts/arm/microchip/mec172x/mec172x-vw-routing.dtsi +++ b/dts/arm/microchip/mec172x/mec172x-vw-routing.dtsi @@ -12,218 +12,218 @@ compatible = "microchip,xec-espi-vw-routing"; /* eSPI Virtual Vire (VW) routing */ - vw-slp-s3-n { + vw_slp_s3_n: vw_slp_s3_n { /* Host-index MSVW/SMVW MSVW/SMVW-index source */ vw-reg = <0x02 MSVW 0 0>; vw-girq = <24 0>; status = "okay"; }; - vw-slp-s4-n { + vw_slp_s4_n: vw_slp_s4_n { vw-reg = <0x02 MSVW 0 1>; vw-girq = <24 1>; status = "okay"; }; - vw-slp-s5-n { + vw_slp_s5_n: vw_slp_s5_n { vw-reg = <0x02 MSVW 0 2>; vw-girq = <24 2>; status = "okay"; }; - vw-sus-stat-n { + vw_sus_stat_n: vw_sus_stat_n { vw-reg = <0x03 MSVW 1 0>; vw-girq = <24 4>; status = "okay"; }; - vw-pltrst-n { + vw_pltrst_n: vw_pltrst_n { vw-reg = <0x03 MSVW 1 1>; vw-girq = <24 5>; status = "okay"; }; - vw-oob-rst-warn { + vw_oob_rst_warn: vw_oob_rst_warn { vw-reg = <0x03 MSVW 1 2>; vw-girq = <24 6>; status = "okay"; }; - vw-host-rst-warn { + vw_host_rst_warn: vw_host_rst_warn { vw-reg = <0x07 MSVW 2 0>; vw-girq = <24 8>; status = "okay"; }; - vw-smiout-n { + vw_smiout_n: vw_smiout_n { vw-reg = <0x07 MSVW 2 1>; vw-girq = <24 9>; status = "disabled"; }; - vw-nmiout-n { + vw_nmiout_n: vw_nmiout_n { vw-reg = <0x07 MSVW 2 2>; vw-girq = <24 10>; status = "disabled"; }; - vw-sus-warn-n { + vw_sus_warn_n: vw_sus_warn_n { vw-reg = <0x41 MSVW 3 0>; vw-girq = <24 12>; status = "okay"; }; - vw-sus-pwrdn-ack { + vw_sus_pwrdn_ack: vw_sus_pwrdn_ack { vw-reg = <0x41 MSVW 3 1>; vw-girq = <24 13>; status = "okay"; }; - vw-slp-a-n { + vw_slp_a_n: vw_slp_a_n { vw-reg = <0x41 MSVW 3 3>; vw-girq = <24 15>; status = "okay"; }; - vw-slp-lan-n { + vw_slp_lan_n: vw_slp_lan_n { vw-reg = <0x42 MSVW 4 0>; vw-girq = <24 16>; status = "okay"; }; - vw-slp-wlan-n { + vw_slp_wlan_n: vw_slp_wlan_n { vw-reg = <0x42 MSVW 4 1>; vw-girq = <24 17>; status = "okay"; }; - vw-host-c10 { + vw_host_c10: vw_host_c10 { vw-reg = <0x47 MSVW 7 0>; vw-girq = <25 0>; status = "okay"; }; - vw-dnx-warn { + vw_dnx_warn: vw_dnx_warn { vw-reg = <0x4a MSVW 8 1>; vw-girq = <25 5>; status = "okay"; }; /* Device to Host (SMVW) do not have SoC interrupts */ - vw-oob-rst-ack { + vw_oob_rst_ack: vw_oob_rst_ack { vw-reg = <0x04 SMVW 0 0>; status = "okay"; }; - vw-wake-n { + vw_wake_n: vw_wake_n { vw-reg = <0x04 SMVW 0 2>; status = "okay"; }; - vw-pme-n { + vw_pme_n: vw_pme_n { vw-reg = <0x04 SMVW 0 3>; status = "okay"; }; - vw-slave-boot-done { + vw_slave_boot_done: vw_slave_boot_done { vw-reg = <0x05 SMVW 1 0>; status = "okay"; }; - vw-error-fatal { + vw_error_fatal: vw_error_fatal { vw-reg = <0x05 SMVW 1 1>; status = "okay"; }; - vw-error-non-fatal { + vw_error_non_fatal: vw_error_non_fatal { vw-reg = <0x05 SMVW 1 2>; status = "okay"; }; - vw-slave-boot-status { + vw_slave_boot_status: vw_slave_boot_status { vw-reg = <0x05 SMVW 1 3>; status = "okay"; }; - vw-sci-n { + vw_sci_n: vw_sci_n { vw-reg = <0x06 SMVW 2 0>; status = "okay"; }; - vw-smi-n { + vw_smi_n: vw_smi_n { vw-reg = <0x06 SMVW 2 1>; status = "okay"; }; - vw-rcin-n { + vw_rcin_n: vw_rcin_n { vw-reg = <0x06 SMVW 2 2>; status = "okay"; }; - vw-host-rst-ack { + vw_host_rst_ack: vw_host_rst_ack { vw-reg = <0x06 SMVW 2 3>; status = "okay"; }; - vw-sus-ack-n { + vw_sus_ack_n: vw_sus_ack_n { vw-reg = <0x40 SMVW 3 0>; status = "okay"; }; - vw-dnx-ack { + vw_dnx_ack: vw_dnx_ack { vw-reg = <0x40 SMVW 3 1>; status = "okay"; }; - vw-c2t-gpio-0 { + vw_t2c_gpio_0: vw_t2c_gpio_0 { vw-reg = <0x50 SMVW 6 0>; status = "disabled"; }; - vw-c2t-gpio-1 { + vw_t2c_gpio_1: vw_t2c_gpio_1 { vw-reg = <0x50 SMVW 6 1>; status = "disabled"; }; - vw-c2t-gpio-2 { + vw_t2c_gpio_2: vw_t2c_gpio_2 { vw-reg = <0x50 SMVW 6 2>; status = "disabled"; }; - vw-c2t-gpio-3 { + vw_t2c_gpio_3: vw_t2c_gpio_3 { vw-reg = <0x50 SMVW 6 3>; status = "disabled"; }; - vw-c2t-gpio-4 { + vw_t2c_gpio_4: vw_t2c_gpio_4 { vw-reg = <0x51 SMVW 7 0>; status = "disabled"; }; - vw-c2t-gpio-5 { + vw_t2c_gpio_5: vw_t2c_gpio_5 { vw-reg = <0x51 SMVW 7 1>; status = "disabled"; }; - vw-c2t-gpio-6 { + vw_t2c_gpio_6: vw_t2c_gpio_6 { vw-reg = <0x51 SMVW 7 2>; status = "disabled"; }; - vw-c2t-gpio-7 { + vw_t2c_gpio_7: vw_t2c_gpio_7 { vw-reg = <0x51 SMVW 7 3>; status = "disabled"; }; - vw-c2t-gpio-8 { + vw_t2c_gpio_8: vw_t2c_gpio_8 { vw-reg = <0x52 SMVW 8 0>; status = "disabled"; }; - vw-c2t-gpio-9 { + vw_t2c_gpio_9: vw_t2c_gpio_9 { vw-reg = <0x52 SMVW 8 1>; status = "disabled"; }; - vw-c2t-gpio-10 { + vw_t2c_gpio_10: vw_t2c_gpio_10 { vw-reg = <0x52 SMVW 8 2>; status = "disabled"; }; - vw-c2t-gpio-11 { + vw_t2c_gpio_11: vw_t2c_gpio_11 { vw-reg = <0x52 SMVW 8 3>; status = "disabled"; }; - vw-c2t-gpio-12 { + vw_t2c_gpio_12: vw_t2c_gpio_12 { vw-reg = <0x53 SMVW 9 0>; status = "disabled"; }; - vw-c2t-gpio-13 { + vw_t2c_gpio_13: vw_t2c_gpio_13 { vw-reg = <0x53 SMVW 9 1>; status = "disabled"; }; - vw-c2t-gpio-14 { + vw_t2c_gpio_14: vw_t2c_gpio_14 { vw-reg = <0x53 SMVW 9 2>; status = "disabled"; }; - vw-c2t-gpio-15 { + vw_t2c_gpio_15: vw_t2c_gpio_15 { vw-reg = <0x53 SMVW 9 3>; status = "disabled"; }; - vw-c2t-gpio-16 { + vw_t2c_gpio_16: vw_t2c_gpio_16 { vw-reg = <0x54 SMVW 10 0>; status = "disabled"; }; - vw-c2t-gpio-17 { + vw_t2c_gpio_17: vw_t2c_gpio_17 { vw-reg = <0x54 SMVW 10 1>; status = "disabled"; }; - vw-c2t-gpio-18 { + vw_t2c_gpio_18: vw_t2c_gpio_18 { vw-reg = <0x54 SMVW 10 2>; status = "disabled"; }; - vw-c2t-gpio-19 { + vw_t2c_gpio_19: vw_t2c_gpio_19 { vw-reg = <0x54 SMVW 10 3>; status = "disabled"; }; diff --git a/dts/bindings/espi/microchip,xec-espi-vw-routing.yaml b/dts/bindings/espi/microchip,xec-espi-vw-routing.yaml index 07aa443d7471..ec7f2bc2b598 100644 --- a/dts/bindings/espi/microchip,xec-espi-vw-routing.yaml +++ b/dts/bindings/espi/microchip,xec-espi-vw-routing.yaml @@ -8,19 +8,44 @@ compatible: "microchip,xec-espi-vw-routing" include: [base.yaml] child-binding: - description: | - Child node containing the routing of an eSPI virtual wire to the SoC - VW registers and ECIA GIRQ registers. - properties: - vw-reg: - type: array - required: true - description: vw signal's register index and vw bitmask. - - vw-girq: - type: array - description: | - Routing of MSVW source to aggregated GIRQs - - For example, OOB_RST_WARN is source 2 of MSVW01 routed - to GIRQ24 b[5]. vw-girq = <24 5>; + description: | + Child node containing the routing of an eSPI virtual wire to the SoC + VW registers and ECIA GIRQ registers. + properties: + vw-reg: + type: array + required: true + description: vw signal's register index and vw bitmask. + + vw-girq: + type: array + description: | + Routing of MSVW source to aggregated GIRQs + + For example, OOB_RST_WARN is source 2 of MSVW01 routed + to GIRQ24 b[5]. vw-girq = <24 5>; + + reset-state: + type: string + description: | + Optional default virtual wire state on reset (0 or 1). + If the property is not present hardware default is used. + enum: + - "HW_DFLT" + - "0" + - "1" + + reset-source: + type: string + description: | + Optional reset source in addition to chip reset. + 0 is ESPI_RESET, 1 is RESET_SYS, 2 is RESET_SIO, + and 3 is ESPI Platform Reset. If this property is not + present the hardware default is used. Note: reset source + affects all four virtual wires in the VW group. + enum: + - "HW_DFLT" + - "ESPI_RESET" + - "RESET_SYS" + - "RESET_SIO" + - "PLTRST" diff --git a/soc/arm/microchip_mec/common/soc_dt.h b/soc/arm/microchip_mec/common/soc_dt.h index eb2b497e6fb0..9202011e3633 100644 --- a/soc/arm/microchip_mec/common/soc_dt.h +++ b/soc/arm/microchip_mec/common/soc_dt.h @@ -25,13 +25,28 @@ #define MCHP_XEC_DRVSTR_12MA 0x4 #define MCHP_XEC_FUNC_INVERT 0x1 +#define MCHP_DT_ESPI_VW_FLAG_STATUS_POS 0 +#define MCHP_DT_ESPI_VW_FLAG_DIR_POS 1 +#define MCHP_DT_ESPI_VW_FLAG_RST_STATE_POS 2 +#define MCHP_DT_ESPI_VW_FLAG_RST_STATE_MSK0 0x3 +#define MCHP_DT_ESPI_VW_FLAG_RST_SRC_POS 4 +#define MCHP_DT_ESPI_VW_FLAG_RST_SRC_MSK0 0x7 + #define MCHP_DT_NODE_FROM_VWTABLE(name) DT_CHILD(DT_PATH(mchp_xec_espi_vw_routing), name) #define MCHP_DT_VW_NODE_HAS_STATUS(name) DT_NODE_HAS_STATUS(MCHP_DT_NODE_FROM_VWTABLE(name), okay) -/* Macro to store DT status in bit 0 and VW direction in bit 4 of flags */ -#define MCHP_DT_ESPI_VW_FLAGS(vw) \ - ((uint8_t)(MCHP_DT_VW_NODE_HAS_STATUS(vw)) & 0x01U) \ - | (((uint8_t)DT_PROP_BY_IDX(MCHP_DT_NODE_FROM_VWTABLE(vw), vw_reg, 1)) << 4) +/* Macro to store eSPI virtual wire DT flags + * b[0] = DT status property 0 is disabled, 1 enabled, + * b[1] = VW direction 0(EC target to host controller), 1(host controller to EC target) + * b[3:2] = default virtual wire state 0(HW default), 1(low), 2(high) + * b[6:4] = virtual wire state reset event: + * 0(HW default), 1(ESPI_RESET), 2(RESET_SYS), 3(RESET_SIO), 4(PLTRST) + */ +#define MCHP_DT_ESPI_VW_FLAGS(vw) \ + ((uint8_t)(MCHP_DT_VW_NODE_HAS_STATUS(vw)) & 0x01U) | \ + ((((uint8_t)DT_PROP_BY_IDX(MCHP_DT_NODE_FROM_VWTABLE(vw), vw_reg, 1)) & 0x1) << 1) | \ + ((((uint8_t)DT_ENUM_IDX_OR(MCHP_DT_NODE_FROM_VWTABLE(vw), reset_state, 0)) & 0x3) << 2) | \ + ((((uint8_t)DT_ENUM_IDX_OR(MCHP_DT_NODE_FROM_VWTABLE(vw), reset_source, 0)) & 0x7) << 4) /* Macro for the eSPI driver VW table entries. * e is a symbol from enum espi_vwire_signal. From ff100463828ba8acce647be49a449d5068fda25e Mon Sep 17 00:00:00 2001 From: Jay Vasanth Date: Thu, 2 Mar 2023 18:45:57 -0500 Subject: [PATCH 0728/1906] include: espi.h: Update OCB virtual wires mappings update espi_vwire_signal enum to refer all platform specific usage virtual wires to ESPI_VWIRE_SIGNAL_SLV_GPIO_x Virtual wires used for USB-C port over current (OCB) have been defined as macros mapped to the corresponding espi_vwire_signal enum Signed-off-by: Jay Vasanth --- drivers/espi/espi_mchp_xec_v2.c | 8 ++++---- include/zephyr/drivers/espi.h | 16 ++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/espi/espi_mchp_xec_v2.c b/drivers/espi/espi_mchp_xec_v2.c index d1099292d49c..82983cfeffaa 100644 --- a/drivers/espi/espi_mchp_xec_v2.c +++ b/drivers/espi/espi_mchp_xec_v2.c @@ -140,10 +140,10 @@ static const struct xec_signal vw_tbl[] = { MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_5, vw_t2c_gpio_5), MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_6, vw_t2c_gpio_6), MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_7, vw_t2c_gpio_7), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_0, vw_t2c_gpio_8), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_1, vw_t2c_gpio_9), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_2, vw_t2c_gpio_10), - MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_OCB_3, vw_t2c_gpio_11), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_8, vw_t2c_gpio_8), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_9, vw_t2c_gpio_9), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_10, vw_t2c_gpio_10), + MCHP_DT_ESPI_VW_ENTRY(ESPI_VWIRE_SIGNAL_SLV_GPIO_11, vw_t2c_gpio_11), }; /* Buffer size are expressed in bytes */ diff --git a/include/zephyr/drivers/espi.h b/include/zephyr/drivers/espi.h index bdf45a790a42..d2f77622fc58 100644 --- a/include/zephyr/drivers/espi.h +++ b/include/zephyr/drivers/espi.h @@ -242,17 +242,21 @@ enum espi_vwire_signal { ESPI_VWIRE_SIGNAL_SLV_GPIO_5, ESPI_VWIRE_SIGNAL_SLV_GPIO_6, ESPI_VWIRE_SIGNAL_SLV_GPIO_7, - - /* USB-C port over current */ - ESPI_VWIRE_SIGNAL_OCB_0, - ESPI_VWIRE_SIGNAL_OCB_1, - ESPI_VWIRE_SIGNAL_OCB_2, - ESPI_VWIRE_SIGNAL_OCB_3, + ESPI_VWIRE_SIGNAL_SLV_GPIO_8, + ESPI_VWIRE_SIGNAL_SLV_GPIO_9, + ESPI_VWIRE_SIGNAL_SLV_GPIO_10, + ESPI_VWIRE_SIGNAL_SLV_GPIO_11, /* Number of Virtual Wires */ ESPI_VWIRE_SIGNAL_COUNT }; +/* USB-C port over current */ +#define ESPI_VWIRE_SIGNAL_OCB_0 ESPI_VWIRE_SIGNAL_SLV_GPIO_0 +#define ESPI_VWIRE_SIGNAL_OCB_1 ESPI_VWIRE_SIGNAL_SLV_GPIO_1 +#define ESPI_VWIRE_SIGNAL_OCB_2 ESPI_VWIRE_SIGNAL_SLV_GPIO_2 +#define ESPI_VWIRE_SIGNAL_OCB_3 ESPI_VWIRE_SIGNAL_SLV_GPIO_3 + /* eSPI LPC peripherals. */ enum lpc_peripheral_opcode { /* Read transactions */ From b2f3d35540256a1613dec803f514be5573c51349 Mon Sep 17 00:00:00 2001 From: Jay Vasanth Date: Mon, 12 Dec 2022 18:03:47 -0500 Subject: [PATCH 0729/1906] samples: drivers: espi: update MEC172x espi sample MEC172x espi sample to use eSPI virtual wire hardware routing through device tree Signed-off-by: Jay Vasanth --- .../espi/boards/mec172xevb_assy6906.overlay | 52 +++++++++++++++++++ .../dts/bindings/mec172x-board-power.yaml | 24 +++++++++ .../drivers/espi/prj_mec172xevb_assy6906.conf | 13 +++++ samples/drivers/espi/src/main.c | 20 +++++++ 4 files changed, 109 insertions(+) create mode 100644 samples/drivers/espi/boards/mec172xevb_assy6906.overlay create mode 100644 samples/drivers/espi/dts/bindings/mec172x-board-power.yaml create mode 100644 samples/drivers/espi/prj_mec172xevb_assy6906.conf diff --git a/samples/drivers/espi/boards/mec172xevb_assy6906.overlay b/samples/drivers/espi/boards/mec172xevb_assy6906.overlay new file mode 100644 index 000000000000..c65331784c5c --- /dev/null +++ b/samples/drivers/espi/boards/mec172xevb_assy6906.overlay @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2020 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + board_power: resources { + compatible = "microchip,mec172x-board-power"; + /* MCHP_GPIO_012 */ + pwrg-gpios = <&gpio_000_036 10 GPIO_ACTIVE_HIGH>; + /* MCHP_GPIO_0054 */ + rsm-gpios = <&gpio_040_076 12 GPIO_ACTIVE_HIGH>; + }; +}; + +&espi_saf0 { + status = "okay"; +}; + +/* Enable Target to Controller Virtual Wires GPIO 0 - 3 */ +&vw_t2c_gpio_0 { + status = "okay"; + reset-state = "1"; + reset-source = "ESPI_RESET"; +}; + +&vw_t2c_gpio_1 { + status = "okay"; + reset-state = "1"; + reset-source = "ESPI_RESET"; +}; + +&vw_t2c_gpio_2 { + status = "okay"; + reset-state = "1"; + reset-source = "ESPI_RESET"; +}; + +&vw_t2c_gpio_3 { + status = "okay"; + reset-state = "1"; + reset-source = "ESPI_RESET"; +}; + +&spi0 { + status = "okay"; + clock-frequency = <24000000>; + port-sel = <0>; + chip-select = <0>; + lines = <4>; +}; diff --git a/samples/drivers/espi/dts/bindings/mec172x-board-power.yaml b/samples/drivers/espi/dts/bindings/mec172x-board-power.yaml new file mode 100644 index 000000000000..8506c524d13f --- /dev/null +++ b/samples/drivers/espi/dts/bindings/mec172x-board-power.yaml @@ -0,0 +1,24 @@ +# Copyright (c) 2020, Microchip Technology Inc. +# SPDX-License-Identifier: Apache-2.0 + +compatible: "microchip,mec172x-board-power" + +description: | + This binding provides MEC172x board gpio power rails resources to + build and run samples/drives/espi in Zephyr. + GPIOs required before performing a eSPI host-slave handshake + +properties: + pwrg-gpios: + type: phandle-array + required: true + description: | + Board GPIO input used to detect that power rails are stable. + + rsm-gpios: + type: phandle-array + required: true + description: | + Board GPIO output used to notify eSPI master to ackwnowledge + power has stabilized and bare minimum initialization in eSPI slave + is complete so eSPI master can proceed with eSPI handshake. diff --git a/samples/drivers/espi/prj_mec172xevb_assy6906.conf b/samples/drivers/espi/prj_mec172xevb_assy6906.conf new file mode 100644 index 000000000000..ecdb27d5f61e --- /dev/null +++ b/samples/drivers/espi/prj_mec172xevb_assy6906.conf @@ -0,0 +1,13 @@ +# eSPI + mec172xevb_assy6906 +CONFIG_ESPI=y +CONFIG_LOG=y +CONFIG_LOG_BUFFER_SIZE=4096 +CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=100 +# Disable only for this board to check notifications +CONFIG_ESPI_AUTOMATIC_WARNING_ACKNOWLEDGE=n +# Sample code doesn't handle ACPI host communication +CONFIG_ESPI_PERIPHERAL_HOST_IO=n +# Test SAF flash portal read/erase/write on EVB +CONFIG_ESPI_SAF=y +CONFIG_SPI=y +CONFIG_SPI_XEC_QMSPI_LDMA=y diff --git a/samples/drivers/espi/src/main.c b/samples/drivers/espi/src/main.c index b17b154f5293..7bdef1e53a47 100644 --- a/samples/drivers/espi/src/main.c +++ b/samples/drivers/espi/src/main.c @@ -133,6 +133,25 @@ static const struct espi_saf_flash_cfg flash_w25q128 = { * by QMSPI driver. * Use SAF hardware default TAG map. */ +#ifdef CONFIG_ESPI_SAF_XEC_V2 +static const struct espi_saf_cfg saf_cfg1 = { + .nflash_devices = 1U, + .hwcfg = { + .version = 2U, /* TODO */ + .flags = 0U, /* TODO */ + .qmspi_cpha = 0U, /* TODO */ + .qmspi_cs_timing = 0U, /* TODO */ + .flash_pd_timeout = 0U, /* TODO */ + .flash_pd_min_interval = 0U, /* TODO */ + .generic_descr = { + MCHP_SAF_EXIT_CM_DESCR12, MCHP_SAF_EXIT_CM_DESCR13, + MCHP_SAF_POLL_DESCR14, MCHP_SAF_POLL_DESCR15 + }, + .tag_map = { 0U, 0U, 0U } + }, + .flash_cfgs = (struct espi_saf_flash_cfg *)&flash_w25q128 +}; +#else static const struct espi_saf_cfg saf_cfg1 = { .nflash_devices = 1U, .hwcfg = { @@ -148,6 +167,7 @@ static const struct espi_saf_cfg saf_cfg1 = { }, .flash_cfgs = (struct espi_saf_flash_cfg *)&flash_w25q128 }; +#endif /* * Example for SAF driver set protection regions API. From 4e822592b8bc4a9c5d9f44cf9736250ecd23fd41 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Thu, 23 Mar 2023 10:24:48 +0100 Subject: [PATCH 0730/1906] mm: intel: adsp: simplify code in mm_drv_intel_adsp_regions.c temporary_table is a trivial copy of virtual_memory_regions, it isn't clear why it's needed. All the more that it's freely mixed with virtual_memory_regions itself. Also change a variable name to avoid confusion and improve indentation. Signed-off-by: Guennadi Liakhovetski --- drivers/mm/mm_drv_intel_adsp_regions.c | 27 ++++++++++++-------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/drivers/mm/mm_drv_intel_adsp_regions.c b/drivers/mm/mm_drv_intel_adsp_regions.c index 571dfbb19bfe..05919a9fcde5 100644 --- a/drivers/mm/mm_drv_intel_adsp_regions.c +++ b/drivers/mm/mm_drv_intel_adsp_regions.c @@ -21,40 +21,37 @@ const struct sys_mm_drv_region *sys_mm_drv_query_memory_regions(void) } static inline void append_region(void *address, uint32_t mem_size, - uint32_t attributes, uint32_t position, uint32_t *checksum) + uint32_t attributes, uint32_t position, uint32_t *total_size) { virtual_memory_regions[position].addr = address; virtual_memory_regions[position].size = mem_size; virtual_memory_regions[position].attr = attributes; - checksum += mem_size; + total_size += mem_size; } int calculate_memory_regions(uintptr_t static_alloc_end_ptr) { - struct sys_mm_drv_region *temporary_table = - (struct sys_mm_drv_region *)&virtual_memory_regions[0]; - - int i, checksum = 0; + int i, total_size = 0; for (i = 0; i < CONFIG_MP_MAX_NUM_CPUS; i++) { append_region((void *)(static_alloc_end_ptr + i * CORE_HEAP_SIZE), - CORE_HEAP_SIZE, MEM_REG_ATTR_CORE_HEAP, i, &checksum); + CORE_HEAP_SIZE, MEM_REG_ATTR_CORE_HEAP, i, &total_size); } - append_region((void *)((uintptr_t) - virtual_memory_regions[i - 1].addr + temporary_table[i - 1].size), - CORE_HEAP_SIZE, MEM_REG_ATTR_SHARED_HEAP, i, &checksum); + append_region((void *)((uintptr_t)virtual_memory_regions[i - 1].addr + + virtual_memory_regions[i - 1].size), + CORE_HEAP_SIZE, MEM_REG_ATTR_SHARED_HEAP, i, &total_size); i++; - append_region((void *)((uintptr_t) - virtual_memory_regions[i - 1].addr + temporary_table[i - 1].size), - OPPORTUNISTIC_REGION_SIZE, MEM_REG_ATTR_OPPORTUNISTIC_MEMORY, i, &checksum); + append_region((void *)((uintptr_t)virtual_memory_regions[i - 1].addr + + virtual_memory_regions[i - 1].size), + OPPORTUNISTIC_REGION_SIZE, MEM_REG_ATTR_OPPORTUNISTIC_MEMORY, i, &total_size); i++; /* Apending last region as 0 so iterators know where table is over * check is for size = 0; */ - append_region((void *)0, 0, 0, i, &checksum); + append_region(NULL, 0, 0, i, &total_size); - if (checksum > L2_VIRTUAL_SRAM_SIZE) { + if (total_size > L2_VIRTUAL_SRAM_SIZE) { return -EINVAL; } From 0727cacd88b4b488b44c580b8d81784556f1cd35 Mon Sep 17 00:00:00 2001 From: Lucas Tamborrino Date: Thu, 23 Feb 2023 09:04:41 -0300 Subject: [PATCH 0731/1906] tests: drivers: gpio_basic_api: add overlays for esp32s2/c3/s3 Add support for the following boards: - esp32s2_saola - esp32c3_devkitm - esp32s3_devkitm Signed-off-by: Lucas Tamborrino --- .../gpio_basic_api/boards/esp32c3_devkitm.overlay | 13 +++++++++++++ .../gpio_basic_api/boards/esp32s2_saola.overlay | 13 +++++++++++++ .../gpio_basic_api/boards/esp32s3_devkitm.overlay | 13 +++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/drivers/gpio/gpio_basic_api/boards/esp32c3_devkitm.overlay create mode 100644 tests/drivers/gpio/gpio_basic_api/boards/esp32s2_saola.overlay create mode 100644 tests/drivers/gpio/gpio_basic_api/boards/esp32s3_devkitm.overlay diff --git a/tests/drivers/gpio/gpio_basic_api/boards/esp32c3_devkitm.overlay b/tests/drivers/gpio/gpio_basic_api/boards/esp32c3_devkitm.overlay new file mode 100644 index 000000000000..6c4f3e2e2266 --- /dev/null +++ b/tests/drivers/gpio/gpio_basic_api/boards/esp32c3_devkitm.overlay @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + resources { + compatible = "test-gpio-basic-api"; + out-gpios = <&gpio0 4 0>; + in-gpios = <&gpio0 5 0>; + }; +}; diff --git a/tests/drivers/gpio/gpio_basic_api/boards/esp32s2_saola.overlay b/tests/drivers/gpio/gpio_basic_api/boards/esp32s2_saola.overlay new file mode 100644 index 000000000000..6c4f3e2e2266 --- /dev/null +++ b/tests/drivers/gpio/gpio_basic_api/boards/esp32s2_saola.overlay @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + resources { + compatible = "test-gpio-basic-api"; + out-gpios = <&gpio0 4 0>; + in-gpios = <&gpio0 5 0>; + }; +}; diff --git a/tests/drivers/gpio/gpio_basic_api/boards/esp32s3_devkitm.overlay b/tests/drivers/gpio/gpio_basic_api/boards/esp32s3_devkitm.overlay new file mode 100644 index 000000000000..6c4f3e2e2266 --- /dev/null +++ b/tests/drivers/gpio/gpio_basic_api/boards/esp32s3_devkitm.overlay @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + resources { + compatible = "test-gpio-basic-api"; + out-gpios = <&gpio0 4 0>; + in-gpios = <&gpio0 5 0>; + }; +}; From e40254a44ad3eaeb294e260a9fee324c5d129746 Mon Sep 17 00:00:00 2001 From: Pavlo Havrylyuk Date: Thu, 2 Mar 2023 12:07:46 +0200 Subject: [PATCH 0732/1906] soc: infineon_cat1: add HardFp support PSoC 6 Added HardFp support for PSoC 6 Signed-off-by: Pavlo Havrylyuk --- soc/arm/infineon_cat1/psoc6/Kconfig.soc | 1 + 1 file changed, 1 insertion(+) diff --git a/soc/arm/infineon_cat1/psoc6/Kconfig.soc b/soc/arm/infineon_cat1/psoc6/Kconfig.soc index 2e8ca4e75741..d1652cca8407 100644 --- a/soc/arm/infineon_cat1/psoc6/Kconfig.soc +++ b/soc/arm/infineon_cat1/psoc6/Kconfig.soc @@ -10,6 +10,7 @@ config SOC_DIE_PSOC6 select CPU_HAS_ARM_MPU select SOC_FAMILY_INFINEON_CAT1A select DYNAMIC_INTERRUPTS + select CPU_HAS_FPU # Infineon PSoC6_01 die config SOC_DIE_PSOC6_01 From 97fe4833d887c6e019ef3fa672c3a0f72e38c7ab Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Wed, 22 Mar 2023 14:08:46 -0700 Subject: [PATCH 0733/1906] tests: mem_protect: remove code to recover spinlock The variable need_recover_spinlock is always set to false so the spinlock recovery code is effectively no-op. So remove everything related to the variable. Signed-off-by: Daniel Leung --- tests/kernel/mem_protect/mem_protect/src/common.c | 4 ---- .../mem_protect/mem_protect/src/mem_domain.c | 15 --------------- 2 files changed, 19 deletions(-) diff --git a/tests/kernel/mem_protect/mem_protect/src/common.c b/tests/kernel/mem_protect/mem_protect/src/common.c index 3a89e45a15ae..c6f4f00d4e1d 100644 --- a/tests/kernel/mem_protect/mem_protect/src/common.c +++ b/tests/kernel/mem_protect/mem_protect/src/common.c @@ -8,16 +8,12 @@ ZTEST_BMEM volatile bool valid_fault; -extern void post_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf); - void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) { printk("Caught system error -- reason %d %d\n", reason, valid_fault); if (valid_fault) { printk("fatal error expected as part of test case\n"); valid_fault = false; /* reset back to normal */ - - post_fatal_error_handler(reason, pEsf); } else { printk("fatal error was unexpected, aborting\n"); printk("PROJECT EXECUTION FAILED\n"); diff --git a/tests/kernel/mem_protect/mem_protect/src/mem_domain.c b/tests/kernel/mem_protect/mem_protect/src/mem_domain.c index 57a25f00ff44..5c4c6c1ce81c 100644 --- a/tests/kernel/mem_protect/mem_protect/src/mem_domain.c +++ b/tests/kernel/mem_protect/mem_protect/src/mem_domain.c @@ -411,19 +411,8 @@ ZTEST(mem_protect_domain, test_mem_part_overlap) extern struct k_spinlock z_mem_domain_lock; -static ZTEST_BMEM bool need_recover_spinlock; - static struct k_mem_domain test_domain_fail; -void post_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) -{ - if (need_recover_spinlock) { - k_spin_release(&z_mem_domain_lock); - - need_recover_spinlock = false; - } -} - static volatile uint8_t __aligned(MEM_REGION_ALLOC) exceed_buf[MEM_REGION_ALLOC]; @@ -451,7 +440,6 @@ ZTEST(mem_protect_domain, test_mem_part_assert_add_overmax) "domain still have room of partitions(%d).", max_parts); - need_recover_spinlock = false; set_fault_valid(false); /* Add one more partition will fail due to exceeding */ @@ -478,7 +466,6 @@ ZTEST(mem_protect_domain, test_mem_domain_remove_part_fail) { struct k_mem_partition *no_parts = &find_no_part; - need_recover_spinlock = false; set_fault_valid(false); zassert_not_equal( @@ -505,7 +492,6 @@ ZTEST(mem_protect_domain, test_mem_domain_init_fail) struct k_mem_partition *no_parts[] = {&ro_part, 0}; /* init another domain fail */ - need_recover_spinlock = false; set_fault_valid(false); zassert_not_equal( @@ -607,7 +593,6 @@ ZTEST(mem_protect_domain, test_mem_part_remove_error_zerosize) no_parts->size = 0U; /* remove partition fail */ - need_recover_spinlock = false; set_fault_valid(false); zassert_not_equal( From 1cc7e41438606dd52e9da9edd2bc22e49d519f82 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Wed, 22 Mar 2023 10:28:05 +0000 Subject: [PATCH 0734/1906] cmake: mcuboot: Add Kconfig for passing west sign arguments The commit adds CONFIG_MCUBOOT_CMAKE_WEST_SIGN_PARAMS Kconfig option to allow passing arguments to west sign. The option is used to pass arguments that immediately follow west sign in cmake invocations and replaces hardcoded "--quiet" parameter, but defaults to the "--quiet" value to keep current behaviour. New Kconfig option allows to pass arguments to west sign without modifying cmake/mcuboot.cmake. Signed-off-by: Dominik Ermel --- Kconfig.zephyr | 12 ++++++++++++ cmake/mcuboot.cmake | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 43f0f4321777..1b64208c4eba 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -791,6 +791,18 @@ config BOOTLOADER_MCUBOOT if BOOTLOADER_MCUBOOT +config MCUBOOT_CMAKE_WEST_SIGN_PARAMS + string "Extra parameters to west sign" + default "--quiet" + help + Parameters that are passed by cmake to west sign, just after + the command, before all other parameters needed for image + signing. + By default this is set to "--quiet" to prevent extra, non-error, + diagnostic messages from west sign. This does not affect signing + tool for which extra parameters are passed with + MCUBOOT_EXTRA_IMGTOOL_ARGS. + config MCUBOOT_SIGNATURE_KEY_FILE string "Path to the mcuboot signing key file" default "" diff --git a/cmake/mcuboot.cmake b/cmake/mcuboot.cmake index 4f9b9bcca2b9..a6c18cc1a295 100644 --- a/cmake/mcuboot.cmake +++ b/cmake/mcuboot.cmake @@ -71,7 +71,9 @@ function(zephyr_mcuboot_tasks) endif() # Basic 'west sign' command and output format independent arguments. - set(west_sign ${WEST} sign --quiet --tool imgtool + separate_arguments(west_sign_extra UNIX_COMMAND ${CONFIG_MCUBOOT_CMAKE_WEST_SIGN_PARAMS}) + set(west_sign ${WEST} sign ${west_sign_extra} + --tool imgtool --tool-path "${imgtool_path}" --build-dir "${APPLICATION_BINARY_DIR}") From 0d95e1684c04967e18d912ca89bb093e7d1f1442 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Wed, 22 Mar 2023 10:37:58 +0000 Subject: [PATCH 0735/1906] doc/release-notes/3.4: Note on CONFIG_MCUBOOT_CMAKE_WEST_SIGN_PARAMS Note on addition of Kconfig option CONFIG_MCUBOOT_CMAKE_WEST_SIGN_PARAMS. Signed-off-by: Dominik Ermel --- doc/releases/release-notes-3.4.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/releases/release-notes-3.4.rst b/doc/releases/release-notes-3.4.rst index a2ece3076916..e5b3012371c6 100644 --- a/doc/releases/release-notes-3.4.rst +++ b/doc/releases/release-notes-3.4.rst @@ -382,6 +382,9 @@ HALs MCUboot ******* +* Added :kconfig:option:`CONFIG_MCUBOOT_CMAKE_WEST_SIGN_PARAMS` that allows to pass arguments to + west sign when invoked from cmake. + Storage ******* From fbf851cdc4d8f0afe60131aea6154945f126d778 Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Mon, 20 Mar 2023 22:45:41 -0600 Subject: [PATCH 0736/1906] util.h: Add dependency on time_units.h The WAIT_FOR macro uses the 'k_us_to_cyc_ceil32' function declared in zephyr/sys/time_units.h. It should have been included. Fixes #56006 Signed-off-by: Yuval Peress --- include/zephyr/sys/util.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/zephyr/sys/util.h b/include/zephyr/sys/util.h index 62c6391e4d65..2608fdb6d5f9 100644 --- a/include/zephyr/sys/util.h +++ b/include/zephyr/sys/util.h @@ -559,6 +559,11 @@ char *utf8_lcpy(char *dst, const char *src, size_t n); } #endif +/* This file must be included at the end of the !_ASMLANGUAGE guard. + * It depends on macros defined in this file above which cannot be forward declared. + */ +#include + #endif /* !_ASMLANGUAGE */ /** @brief Number of bytes in @p x kibibytes */ From b7e265265da4c6146e1f1c4c91a345b42d273084 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 22 Mar 2023 17:03:34 +0100 Subject: [PATCH 0737/1906] Bluetooth: BAP: Do not allow start op when CIS is connecting When the CIS is connecting we should not allow sending the receiver start ready command. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/bap_unicast_client.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index 0fdc582a7700..3c5530fea6b9 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -1944,6 +1944,7 @@ static int unicast_client_stream_connect(struct bt_bap_stream *stream) case BT_ISO_STATE_DISCONNECTED: return bt_iso_chan_connect(¶m, 1); case BT_ISO_STATE_CONNECTING: + return -EBUSY; case BT_ISO_STATE_CONNECTED: return -EALREADY; default: From a8b2ff88de38709788215dea0020cf4caa55987a Mon Sep 17 00:00:00 2001 From: Benedikt Schmidt Date: Tue, 14 Feb 2023 13:27:37 +0100 Subject: [PATCH 0738/1906] drivers: gpio: remove not required header Move the content of the header for the MCP23S17 into the source file. Signed-off-by: Benedikt Schmidt --- drivers/gpio/gpio_mcp23s17.c | 56 +++++++++++++++++++++++- drivers/gpio/gpio_mcp23s17.h | 82 ------------------------------------ 2 files changed, 55 insertions(+), 83 deletions(-) delete mode 100644 drivers/gpio/gpio_mcp23s17.h diff --git a/drivers/gpio/gpio_mcp23s17.c b/drivers/gpio/gpio_mcp23s17.c index 8860fbceedba..14fbadc61528 100644 --- a/drivers/gpio/gpio_mcp23s17.c +++ b/drivers/gpio/gpio_mcp23s17.c @@ -20,12 +20,66 @@ #include #include -#include "gpio_mcp23s17.h" #define LOG_LEVEL CONFIG_GPIO_LOG_LEVEL #include LOG_MODULE_REGISTER(gpio_mcp23s17); +/* Register definitions */ +#define REG_IODIR_PORTA 0x00 +#define REG_IODIR_PORTB 0x01 +#define REG_IPOL_PORTA 0x02 +#define REG_IPOL_PORTB 0x03 +#define REG_GPINTEN_PORTA 0x04 +#define REG_GPINTEN_PORTB 0x05 +#define REG_DEFVAL_PORTA 0x06 +#define REG_DEFVAL_PORTB 0x07 +#define REG_INTCON_PORTA 0x08 +#define REG_INTCON_PORTB 0x09 +#define REG_GPPU_PORTA 0x0C +#define REG_GPPU_PORTB 0x0D +#define REG_INTF_PORTA 0x0E +#define REG_INTF_PORTB 0x0F +#define REG_INTCAP_PORTA 0x10 +#define REG_INTCAP_PORTB 0x11 +#define REG_GPIO_PORTA 0x12 +#define REG_GPIO_PORTB 0x13 +#define REG_OLAT_PORTA 0x14 +#define REG_OLAT_PORTB 0x15 + +#define MCP23S17_ADDR 0x40 +#define MCP23S17_READBIT 0x01 + +/** Configuration data */ +struct mcp23s17_config { + /* gpio_driver_config needs to be first */ + struct gpio_driver_config common; + + struct spi_dt_spec bus; +}; + +/** Runtime driver data */ +struct mcp23s17_drv_data { + /* gpio_driver_data needs to be first */ + struct gpio_driver_data data; + + struct k_sem lock; + + struct { + uint16_t iodir; + uint16_t ipol; + uint16_t gpinten; + uint16_t defval; + uint16_t intcon; + uint16_t iocon; + uint16_t gppu; + uint16_t intf; + uint16_t intcap; + uint16_t gpio; + uint16_t olat; + } reg_cache; +}; + /** * @brief Read both port 0 and port 1 registers of certain register function. * diff --git a/drivers/gpio/gpio_mcp23s17.h b/drivers/gpio/gpio_mcp23s17.h deleted file mode 100644 index ef7ade2acd84..000000000000 --- a/drivers/gpio/gpio_mcp23s17.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2020 Geanix ApS - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @file Header file for the MCP23S17 driver. - */ - -#ifndef ZEPHYR_DRIVERS_GPIO_GPIO_MCP23S17_H_ -#define ZEPHYR_DRIVERS_GPIO_GPIO_MCP23S17_H_ - -#include - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Register definitions */ -#define REG_IODIR_PORTA 0x00 -#define REG_IODIR_PORTB 0x01 -#define REG_IPOL_PORTA 0x02 -#define REG_IPOL_PORTB 0x03 -#define REG_GPINTEN_PORTA 0x04 -#define REG_GPINTEN_PORTB 0x05 -#define REG_DEFVAL_PORTA 0x06 -#define REG_DEFVAL_PORTB 0x07 -#define REG_INTCON_PORTA 0x08 -#define REG_INTCON_PORTB 0x09 -#define REG_GPPU_PORTA 0x0C -#define REG_GPPU_PORTB 0x0D -#define REG_INTF_PORTA 0x0E -#define REG_INTF_PORTB 0x0F -#define REG_INTCAP_PORTA 0x10 -#define REG_INTCAP_PORTB 0x11 -#define REG_GPIO_PORTA 0x12 -#define REG_GPIO_PORTB 0x13 -#define REG_OLAT_PORTA 0x14 -#define REG_OLAT_PORTB 0x15 - -#define MCP23S17_ADDR 0x40 -#define MCP23S17_READBIT 0x01 - -/** Configuration data */ -struct mcp23s17_config { - /* gpio_driver_config needs to be first */ - struct gpio_driver_config common; - - struct spi_dt_spec bus; -}; - -/** Runtime driver data */ -struct mcp23s17_drv_data { - /* gpio_driver_data needs to be first */ - struct gpio_driver_data data; - - struct k_sem lock; - - struct { - uint16_t iodir; - uint16_t ipol; - uint16_t gpinten; - uint16_t defval; - uint16_t intcon; - uint16_t iocon; - uint16_t gppu; - uint16_t intf; - uint16_t intcap; - uint16_t gpio; - uint16_t olat; - } reg_cache; -}; - -#ifdef __cplusplus -} -#endif - -#endif /* ZEPHYR_DRIVERS_GPIO_GPIO_MCP23S17_H_ */ From 1009b9152aa1f2dd3c6bca4401fd01c032aa1e79 Mon Sep 17 00:00:00 2001 From: Benedikt Schmidt Date: Tue, 14 Feb 2023 13:31:09 +0100 Subject: [PATCH 0739/1906] drivers: gpio: remove doxygen comments in MCP23S17 driver Remove the doxygen comments in the driver for the MCP23S17. Signed-off-by: Benedikt Schmidt --- drivers/gpio/gpio_mcp23s17.c | 50 ------------------------------------ 1 file changed, 50 deletions(-) diff --git a/drivers/gpio/gpio_mcp23s17.c b/drivers/gpio/gpio_mcp23s17.c index 14fbadc61528..96a266fdf6dd 100644 --- a/drivers/gpio/gpio_mcp23s17.c +++ b/drivers/gpio/gpio_mcp23s17.c @@ -6,10 +6,6 @@ #define DT_DRV_COMPAT microchip_mcp23s17 -/** - * @file Driver for MCP23S17 SPI-based GPIO driver. - */ - #include #include @@ -80,17 +76,6 @@ struct mcp23s17_drv_data { } reg_cache; }; -/** - * @brief Read both port 0 and port 1 registers of certain register function. - * - * Given the register in reg, read the pair of port 0 and port 1. - * - * @param dev Device struct of the MCP23S17. - * @param reg Register to read (the PORTA of the pair of registers). - * @param buf Buffer to read data into. - * - * @return 0 if successful, failed otherwise. - */ static int read_port_regs(const struct device *dev, uint8_t reg, uint16_t *buf) { @@ -138,17 +123,6 @@ static int read_port_regs(const struct device *dev, uint8_t reg, return 0; } -/** - * @brief Write both port 0 and port 1 registers of certain register function. - * - * Given the register in reg, write the pair of port 0 and port 1. - * - * @param dev Device struct of the MCP23S17. - * @param reg Register to write into (the PORTA of the pair of registers). - * @param buf Buffer to write data from. - * - * @return 0 if successful, failed otherwise. - */ static int write_port_regs(const struct device *dev, uint8_t reg, uint16_t value) { @@ -188,15 +162,6 @@ static int write_port_regs(const struct device *dev, uint8_t reg, return 0; } -/** - * @brief Setup the pin direction (input or output) - * - * @param dev Device struct of the MCP23S17 - * @param pin The pin number - * @param flags Flags of pin or port - * - * @return 0 if successful, failed otherwise - */ static int setup_pin_dir(const struct device *dev, uint32_t pin, int flags) { struct mcp23s17_drv_data *drv_data = dev->data; @@ -225,15 +190,6 @@ static int setup_pin_dir(const struct device *dev, uint32_t pin, int flags) return ret; } -/** - * @brief Setup the pin pull up/pull down status - * - * @param dev Device struct of the MCP23S17 - * @param pin The pin number - * @param flags Flags of pin or port - * - * @return 0 if successful, failed otherwise - */ static int setup_pin_pullupdown(const struct device *dev, uint32_t pin, int flags) { @@ -402,12 +358,6 @@ static const struct gpio_driver_api api_table = { .pin_interrupt_configure = mcp23s17_pin_interrupt_configure, }; -/** - * @brief Initialization function of MCP23S17 - * - * @param dev Device struct - * @return 0 if successful, failed otherwise. - */ static int mcp23s17_init(const struct device *dev) { const struct mcp23s17_config *config = dev->config; From 7f0774397ed2924d21e7679ad8f452689ed7eba7 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Thu, 23 Mar 2023 17:02:42 +0100 Subject: [PATCH 0740/1906] Bluetooth: Clean up public header inclusion A bit of cleanup in the public header files inclusion policy and statements: - Include only what is needed if possible - Include in the right location - Include in the right order Fixes #55971. Signed-off-by: Carles Cufi --- include/zephyr/bluetooth/a2dp-codec.h | 2 ++ include/zephyr/bluetooth/a2dp.h | 2 ++ include/zephyr/bluetooth/addr.h | 3 ++- include/zephyr/bluetooth/audio/aics.h | 1 - include/zephyr/bluetooth/audio/audio.h | 13 +++++++------ include/zephyr/bluetooth/audio/bap.h | 6 +++--- include/zephyr/bluetooth/audio/bap_lc3_preset.h | 1 + include/zephyr/bluetooth/audio/cap.h | 3 ++- include/zephyr/bluetooth/audio/csip.h | 2 -- include/zephyr/bluetooth/audio/has.h | 3 ++- include/zephyr/bluetooth/audio/lc3.h | 1 - include/zephyr/bluetooth/audio/mcc.h | 3 ++- include/zephyr/bluetooth/audio/media_proxy.h | 3 ++- include/zephyr/bluetooth/audio/micp.h | 3 ++- include/zephyr/bluetooth/audio/tbs.h | 4 +++- include/zephyr/bluetooth/audio/vcp.h | 3 ++- include/zephyr/bluetooth/audio/vocs.h | 3 ++- include/zephyr/bluetooth/avdtp.h | 4 ++-- include/zephyr/bluetooth/bluetooth.h | 1 + include/zephyr/bluetooth/buf.h | 3 ++- include/zephyr/bluetooth/controller.h | 2 ++ include/zephyr/bluetooth/crypto.h | 1 + include/zephyr/bluetooth/direction.h | 2 ++ include/zephyr/bluetooth/ead.h | 1 - include/zephyr/bluetooth/gap.h | 4 ++-- include/zephyr/bluetooth/gatt.h | 5 ++++- include/zephyr/bluetooth/hci.h | 6 ++++-- include/zephyr/bluetooth/hci_raw.h | 2 ++ include/zephyr/bluetooth/hci_vs.h | 2 ++ include/zephyr/bluetooth/iso.h | 8 ++++---- include/zephyr/bluetooth/mesh.h | 3 ++- include/zephyr/bluetooth/mesh/access.h | 2 +- include/zephyr/bluetooth/mesh/blob.h | 3 ++- include/zephyr/bluetooth/mesh/blob_cli.h | 3 ++- include/zephyr/bluetooth/mesh/blob_io_flash.h | 2 ++ include/zephyr/bluetooth/mesh/cdb.h | 4 +++- include/zephyr/bluetooth/mesh/cfg.h | 1 + include/zephyr/bluetooth/mesh/cfg_cli.h | 3 +++ include/zephyr/bluetooth/mesh/dfu.h | 3 ++- include/zephyr/bluetooth/mesh/dfu_metadata.h | 5 ++++- include/zephyr/bluetooth/mesh/health_cli.h | 2 ++ include/zephyr/bluetooth/mesh/health_srv.h | 2 ++ include/zephyr/bluetooth/mesh/heartbeat.h | 2 ++ .../zephyr/bluetooth/mesh/large_comp_data_cli.h | 2 ++ .../zephyr/bluetooth/mesh/large_comp_data_srv.h | 2 ++ include/zephyr/bluetooth/mesh/main.h | 5 +++++ include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h | 3 +++ include/zephyr/bluetooth/mesh/od_priv_proxy_srv.h | 2 ++ include/zephyr/bluetooth/mesh/op_agg_cli.h | 2 ++ include/zephyr/bluetooth/mesh/op_agg_srv.h | 2 ++ include/zephyr/bluetooth/mesh/proxy.h | 4 ++++ include/zephyr/bluetooth/mesh/sar_cfg.h | 2 ++ include/zephyr/bluetooth/mesh/sar_cfg_cli.h | 1 + include/zephyr/bluetooth/mesh/sar_cfg_srv.h | 1 + include/zephyr/bluetooth/mesh/sol_pdu_rpl_cli.h | 3 +++ include/zephyr/bluetooth/services/bas.h | 2 +- include/zephyr/bluetooth/services/hrs.h | 2 ++ include/zephyr/bluetooth/services/ots.h | 14 ++++++++------ include/zephyr/bluetooth/testing.h | 2 ++ include/zephyr/bluetooth/uuid.h | 2 ++ 60 files changed, 134 insertions(+), 49 deletions(-) diff --git a/include/zephyr/bluetooth/a2dp-codec.h b/include/zephyr/bluetooth/a2dp-codec.h index 3c8022d61407..9e4e5ea34792 100644 --- a/include/zephyr/bluetooth/a2dp-codec.h +++ b/include/zephyr/bluetooth/a2dp-codec.h @@ -20,6 +20,8 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_A2DP_CODEC_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_A2DP_CODEC_H_ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/a2dp.h b/include/zephyr/bluetooth/a2dp.h index 74d93898b65c..3df6db1a6fd8 100644 --- a/include/zephyr/bluetooth/a2dp.h +++ b/include/zephyr/bluetooth/a2dp.h @@ -10,6 +10,8 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_ +#include + #include #ifdef __cplusplus diff --git a/include/zephyr/bluetooth/addr.h b/include/zephyr/bluetooth/addr.h index d824d948e67f..4178dfb1df2c 100644 --- a/include/zephyr/bluetooth/addr.h +++ b/include/zephyr/bluetooth/addr.h @@ -10,9 +10,10 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_ADDR_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_ADDR_H_ +#include #include + #include -#include #ifdef __cplusplus extern "C" { diff --git a/include/zephyr/bluetooth/audio/aics.h b/include/zephyr/bluetooth/audio/aics.h index 206ad8c0ed26..93b810d27854 100644 --- a/include/zephyr/bluetooth/audio/aics.h +++ b/include/zephyr/bluetooth/audio/aics.h @@ -26,7 +26,6 @@ * [Experimental] Users should note that the APIs can change as a part of ongoing development. */ -#include #include #ifdef __cplusplus diff --git a/include/zephyr/bluetooth/audio/audio.h b/include/zephyr/bluetooth/audio/audio.h index 6de9da2a4555..32a38535b89d 100644 --- a/include/zephyr/bluetooth/audio/audio.h +++ b/include/zephyr/bluetooth/audio/audio.h @@ -11,6 +11,13 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_AUDIO_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_AUDIO_H_ +/** + * @brief Bluetooth Audio + * @defgroup bt_audio Bluetooth Audio + * @ingroup bluetooth + * @{ + */ + #include #include #include @@ -19,12 +26,6 @@ #include #include -/** - * @brief Bluetooth Audio - * @defgroup bt_audio Bluetooth Audio - * @ingroup bluetooth - * @{ - */ #ifdef __cplusplus extern "C" { diff --git a/include/zephyr/bluetooth/audio/bap.h b/include/zephyr/bluetooth/audio/bap.h index f055c507711b..5b08212a68a2 100644 --- a/include/zephyr/bluetooth/audio/bap.h +++ b/include/zephyr/bluetooth/audio/bap.h @@ -9,9 +9,6 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_BAP_ #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_BAP_ -#include -#include -#include /** * @brief Bluetooth Basic Audio Profile (BAP) @@ -20,6 +17,9 @@ * @{ */ +#include +#include + #if defined(CONFIG_BT_BAP_SCAN_DELEGATOR) #define BT_BAP_SCAN_DELEGATOR_MAX_METADATA_LEN CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_METADATA_LEN #define BT_BAP_SCAN_DELEGATOR_MAX_SUBGROUPS CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_SUBGROUPS diff --git a/include/zephyr/bluetooth/audio/bap_lc3_preset.h b/include/zephyr/bluetooth/audio/bap_lc3_preset.h index 3781be1a6db1..0886c1804260 100644 --- a/include/zephyr/bluetooth/audio/bap_lc3_preset.h +++ b/include/zephyr/bluetooth/audio/bap_lc3_preset.h @@ -8,6 +8,7 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_BAP_LC3_PRESET_ #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_BAP_LC3_PRESET_ + #include /** Struct to hold a BAP defined LC3 preset */ diff --git a/include/zephyr/bluetooth/audio/cap.h b/include/zephyr/bluetooth/audio/cap.h index 36c50e036ec8..c122bfb1cc81 100644 --- a/include/zephyr/bluetooth/audio/cap.h +++ b/include/zephyr/bluetooth/audio/cap.h @@ -19,7 +19,8 @@ * as a part of ongoing development. */ -#include +#include + #include #include #include diff --git a/include/zephyr/bluetooth/audio/csip.h b/include/zephyr/bluetooth/audio/csip.h index c2508f846a55..85fbc6d0e4a7 100644 --- a/include/zephyr/bluetooth/audio/csip.h +++ b/include/zephyr/bluetooth/audio/csip.h @@ -18,8 +18,6 @@ * [Experimental] Users should note that the APIs can change as a part of ongoing development. */ -#include -#include #include #ifdef __cplusplus diff --git a/include/zephyr/bluetooth/audio/has.h b/include/zephyr/bluetooth/audio/has.h index dad5b9c3d7e7..3dc54a749e53 100644 --- a/include/zephyr/bluetooth/audio/has.h +++ b/include/zephyr/bluetooth/audio/has.h @@ -22,8 +22,9 @@ * ongoing development. */ -#include #include + +#include #include #ifdef __cplusplus diff --git a/include/zephyr/bluetooth/audio/lc3.h b/include/zephyr/bluetooth/audio/lc3.h index 3bce7a96f050..9fd8b9ae94f2 100644 --- a/include/zephyr/bluetooth/audio/lc3.h +++ b/include/zephyr/bluetooth/audio/lc3.h @@ -18,7 +18,6 @@ * @{ */ -#include #include #ifdef __cplusplus diff --git a/include/zephyr/bluetooth/audio/mcc.h b/include/zephyr/bluetooth/audio/mcc.h index 5b81d9724f64..9744bb058633 100644 --- a/include/zephyr/bluetooth/audio/mcc.h +++ b/include/zephyr/bluetooth/audio/mcc.h @@ -21,7 +21,8 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MCC_ #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_MCC_ -#include +#include + #include #include #include diff --git a/include/zephyr/bluetooth/audio/media_proxy.h b/include/zephyr/bluetooth/audio/media_proxy.h index a3e029fc29f2..34e3e7126f69 100644 --- a/include/zephyr/bluetooth/audio/media_proxy.h +++ b/include/zephyr/bluetooth/audio/media_proxy.h @@ -36,8 +36,9 @@ * as a part of ongoing development. */ +#include #include -#include + #include /* TODO: Remove dependency on mcs.h */ diff --git a/include/zephyr/bluetooth/audio/micp.h b/include/zephyr/bluetooth/audio/micp.h index 3e358e2319af..c12d3cac6c71 100644 --- a/include/zephyr/bluetooth/audio/micp.h +++ b/include/zephyr/bluetooth/audio/micp.h @@ -19,7 +19,8 @@ * as a part of ongoing development. */ -#include +#include + #include #ifdef __cplusplus diff --git a/include/zephyr/bluetooth/audio/tbs.h b/include/zephyr/bluetooth/audio/tbs.h index 752c2f3619fa..895ffd4f9bda 100644 --- a/include/zephyr/bluetooth/audio/tbs.h +++ b/include/zephyr/bluetooth/audio/tbs.h @@ -10,7 +10,9 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_TBS_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_TBS_H_ -#include +#include +#include + #include /* Call States */ diff --git a/include/zephyr/bluetooth/audio/vcp.h b/include/zephyr/bluetooth/audio/vcp.h index 14af9ab3cc60..961fed483d5a 100644 --- a/include/zephyr/bluetooth/audio/vcp.h +++ b/include/zephyr/bluetooth/audio/vcp.h @@ -19,7 +19,8 @@ * as a part of ongoing development. */ -#include +#include + #include #include diff --git a/include/zephyr/bluetooth/audio/vocs.h b/include/zephyr/bluetooth/audio/vocs.h index 2a99fab7c503..eee5c43533a5 100644 --- a/include/zephyr/bluetooth/audio/vocs.h +++ b/include/zephyr/bluetooth/audio/vocs.h @@ -26,7 +26,8 @@ * [Experimental] Users should note that the APIs can change as a part of ongoing development. */ -#include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/include/zephyr/bluetooth/avdtp.h b/include/zephyr/bluetooth/avdtp.h index fb35052e46b0..396025814b80 100644 --- a/include/zephyr/bluetooth/avdtp.h +++ b/include/zephyr/bluetooth/avdtp.h @@ -10,12 +10,12 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AVDTP_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_AVDTP_H_ +#include + #ifdef __cplusplus extern "C" { #endif -#include - /** @brief AVDTP SEID Information */ struct bt_avdtp_seid_info { /** Stream End Point ID */ diff --git a/include/zephyr/bluetooth/bluetooth.h b/include/zephyr/bluetooth/bluetooth.h index f448f683691a..43dc6adc35f0 100644 --- a/include/zephyr/bluetooth/bluetooth.h +++ b/include/zephyr/bluetooth/bluetooth.h @@ -19,6 +19,7 @@ #include #include + #include #include #include diff --git a/include/zephyr/bluetooth/buf.h b/include/zephyr/bluetooth/buf.h index db59b694d13f..b6c377a93693 100644 --- a/include/zephyr/bluetooth/buf.h +++ b/include/zephyr/bluetooth/buf.h @@ -18,7 +18,8 @@ * @{ */ -#include +#include + #include #include #include diff --git a/include/zephyr/bluetooth/controller.h b/include/zephyr/bluetooth/controller.h index 1f45ddbe9834..f4c64fa5cbc4 100644 --- a/include/zephyr/bluetooth/controller.h +++ b/include/zephyr/bluetooth/controller.h @@ -17,6 +17,8 @@ * @{ */ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/crypto.h b/include/zephyr/bluetooth/crypto.h index 4a8a75d9cdfd..c5cbfd8a0e55 100644 --- a/include/zephyr/bluetooth/crypto.h +++ b/include/zephyr/bluetooth/crypto.h @@ -19,6 +19,7 @@ */ #include +#include #ifdef __cplusplus extern "C" { diff --git a/include/zephyr/bluetooth/direction.h b/include/zephyr/bluetooth/direction.h index 7b24f7da88ac..59407bc25d8a 100644 --- a/include/zephyr/bluetooth/direction.h +++ b/include/zephyr/bluetooth/direction.h @@ -7,6 +7,8 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_DF_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_DF_H_ +#include + /** Constant Tone Extension (CTE) types. */ enum bt_df_cte_type { /** Convenience value for purposes where non of CTE types is allowed. */ diff --git a/include/zephyr/bluetooth/ead.h b/include/zephyr/bluetooth/ead.h index 8a166d0ec271..1128044839cf 100644 --- a/include/zephyr/bluetooth/ead.h +++ b/include/zephyr/bluetooth/ead.h @@ -6,7 +6,6 @@ #include #include - #include /** Randomizer size in bytes */ diff --git a/include/zephyr/bluetooth/gap.h b/include/zephyr/bluetooth/gap.h index ed76372b573c..f7d1766a6e71 100644 --- a/include/zephyr/bluetooth/gap.h +++ b/include/zephyr/bluetooth/gap.h @@ -11,12 +11,12 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_GAP_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_GAP_H_ +#include + #ifdef __cplusplus extern "C" { #endif -#include - /** * @brief Bluetooth Generic Access Profile defines and Assigned Numbers. * @defgroup bt_gap_defines Defines and Assigned Numbers diff --git a/include/zephyr/bluetooth/gatt.h b/include/zephyr/bluetooth/gatt.h index 255ca1dac5cf..cec5a9b87ad1 100644 --- a/include/zephyr/bluetooth/gatt.h +++ b/include/zephyr/bluetooth/gatt.h @@ -17,9 +17,12 @@ * @{ */ +#include #include -#include + #include + +#include #include #include #include diff --git a/include/zephyr/bluetooth/hci.h b/include/zephyr/bluetooth/hci.h index 185bcf93ddfa..f0625de39711 100644 --- a/include/zephyr/bluetooth/hci.h +++ b/include/zephyr/bluetooth/hci.h @@ -8,10 +8,12 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_HCI_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_HCI_H_ -#include -#include #include +#include #include + +#include +#include #include #include #include diff --git a/include/zephyr/bluetooth/hci_raw.h b/include/zephyr/bluetooth/hci_raw.h index 7f660454b2f7..8a0b4a376800 100644 --- a/include/zephyr/bluetooth/hci_raw.h +++ b/include/zephyr/bluetooth/hci_raw.h @@ -17,6 +17,8 @@ * @{ */ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/hci_vs.h b/include/zephyr/bluetooth/hci_vs.h index 483e9610a772..aea92846e562 100644 --- a/include/zephyr/bluetooth/hci_vs.h +++ b/include/zephyr/bluetooth/hci_vs.h @@ -9,6 +9,8 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_HCI_VS_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_HCI_VS_H_ +#include + #include #ifdef __cplusplus diff --git a/include/zephyr/bluetooth/iso.h b/include/zephyr/bluetooth/iso.h index b758b7d1bb73..87c1eb15f7ee 100644 --- a/include/zephyr/bluetooth/iso.h +++ b/include/zephyr/bluetooth/iso.h @@ -18,15 +18,15 @@ * @{ */ -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include #include +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Headroom needed for outgoing ISO SDUs */ diff --git a/include/zephyr/bluetooth/mesh.h b/include/zephyr/bluetooth/mesh.h index 736e64ae62d5..8eadaa56bb48 100644 --- a/include/zephyr/bluetooth/mesh.h +++ b/include/zephyr/bluetooth/mesh.h @@ -10,8 +10,9 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_H_ -#include #include + +#include #include #include diff --git a/include/zephyr/bluetooth/mesh/access.h b/include/zephyr/bluetooth/mesh/access.h index 8ac7c6c18177..80e3948f1eb4 100644 --- a/include/zephyr/bluetooth/mesh/access.h +++ b/include/zephyr/bluetooth/mesh/access.h @@ -10,8 +10,8 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_ACCESS_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_ACCESS_H_ -#include #include +#include #include /* Internal macros used to initialize array members */ diff --git a/include/zephyr/bluetooth/mesh/blob.h b/include/zephyr/bluetooth/mesh/blob.h index abed9148020c..e8af7aad6f83 100644 --- a/include/zephyr/bluetooth/mesh/blob.h +++ b/include/zephyr/bluetooth/mesh/blob.h @@ -14,9 +14,10 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_BLOB_H__ #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_BLOB_H__ -#include #include +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/mesh/blob_cli.h b/include/zephyr/bluetooth/mesh/blob_cli.h index 8219c3301e87..cb66e45768e4 100644 --- a/include/zephyr/bluetooth/mesh/blob_cli.h +++ b/include/zephyr/bluetooth/mesh/blob_cli.h @@ -14,9 +14,10 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_BLOB_CLI_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_BLOB_CLI_H_ +#include + #include #include -#include #ifdef __cplusplus extern "C" { diff --git a/include/zephyr/bluetooth/mesh/blob_io_flash.h b/include/zephyr/bluetooth/mesh/blob_io_flash.h index d9ba2086350c..0b1dccb1c33c 100644 --- a/include/zephyr/bluetooth/mesh/blob_io_flash.h +++ b/include/zephyr/bluetooth/mesh/blob_io_flash.h @@ -14,6 +14,8 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_BLOB_IO_FLASH_H__ #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_BLOB_IO_FLASH_H__ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/mesh/cdb.h b/include/zephyr/bluetooth/mesh/cdb.h index c74b30948a68..f202a4f6904d 100644 --- a/include/zephyr/bluetooth/mesh/cdb.h +++ b/include/zephyr/bluetooth/mesh/cdb.h @@ -6,7 +6,9 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_CDB_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_CDB_H_ -#include +#include +#include + #include #ifdef __cplusplus diff --git a/include/zephyr/bluetooth/mesh/cfg.h b/include/zephyr/bluetooth/mesh/cfg.h index bef8a52de8ee..7d1ca4e868f5 100644 --- a/include/zephyr/bluetooth/mesh/cfg.h +++ b/include/zephyr/bluetooth/mesh/cfg.h @@ -12,6 +12,7 @@ #include #include + #include /** diff --git a/include/zephyr/bluetooth/mesh/cfg_cli.h b/include/zephyr/bluetooth/mesh/cfg_cli.h index 74bd7ade70a1..6a827be3805f 100644 --- a/include/zephyr/bluetooth/mesh/cfg_cli.h +++ b/include/zephyr/bluetooth/mesh/cfg_cli.h @@ -17,6 +17,9 @@ * @{ */ +#include +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/mesh/dfu.h b/include/zephyr/bluetooth/mesh/dfu.h index b9e7ce4702a0..7bc945e1ae00 100644 --- a/include/zephyr/bluetooth/mesh/dfu.h +++ b/include/zephyr/bluetooth/mesh/dfu.h @@ -15,8 +15,9 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_DFU_H__ #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_DFU_H__ -#include #include + +#include #include #ifdef __cplusplus diff --git a/include/zephyr/bluetooth/mesh/dfu_metadata.h b/include/zephyr/bluetooth/mesh/dfu_metadata.h index d32d2cc8a234..8aea661ede74 100644 --- a/include/zephyr/bluetooth/mesh/dfu_metadata.h +++ b/include/zephyr/bluetooth/mesh/dfu_metadata.h @@ -15,9 +15,12 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_DFU_METADATA_H__ #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_DFU_METADATA_H__ -#include +#include + #include +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/mesh/health_cli.h b/include/zephyr/bluetooth/mesh/health_cli.h index 21fc5a93e6af..2f13dd88ccfb 100644 --- a/include/zephyr/bluetooth/mesh/health_cli.h +++ b/include/zephyr/bluetooth/mesh/health_cli.h @@ -10,6 +10,8 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_HEALTH_CLI_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_HEALTH_CLI_H_ +#include + /** * @brief Health Client Model * @defgroup bt_mesh_health_cli Health Client Model diff --git a/include/zephyr/bluetooth/mesh/health_srv.h b/include/zephyr/bluetooth/mesh/health_srv.h index a15633ab5cb1..8f1d195e13ee 100644 --- a/include/zephyr/bluetooth/mesh/health_srv.h +++ b/include/zephyr/bluetooth/mesh/health_srv.h @@ -17,6 +17,8 @@ * @{ */ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/mesh/heartbeat.h b/include/zephyr/bluetooth/mesh/heartbeat.h index bbf72b6e5a99..597c39800cec 100644 --- a/include/zephyr/bluetooth/mesh/heartbeat.h +++ b/include/zephyr/bluetooth/mesh/heartbeat.h @@ -10,6 +10,8 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_HEARTBEAT_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_HEARTBEAT_H_ +#include + #include /** diff --git a/include/zephyr/bluetooth/mesh/large_comp_data_cli.h b/include/zephyr/bluetooth/mesh/large_comp_data_cli.h index 7006410757bd..ae23cda468f7 100644 --- a/include/zephyr/bluetooth/mesh/large_comp_data_cli.h +++ b/include/zephyr/bluetooth/mesh/large_comp_data_cli.h @@ -13,6 +13,8 @@ #ifndef BT_MESH_LARGE_COMP_DATA_CLI_H__ #define BT_MESH_LARGE_COMP_DATA_CLI_H__ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/mesh/large_comp_data_srv.h b/include/zephyr/bluetooth/mesh/large_comp_data_srv.h index e2b82e769ff2..461a681e2d7c 100644 --- a/include/zephyr/bluetooth/mesh/large_comp_data_srv.h +++ b/include/zephyr/bluetooth/mesh/large_comp_data_srv.h @@ -13,6 +13,8 @@ #ifndef BT_MESH_LARGE_COMP_DATA_SRV_H__ #define BT_MESH_LARGE_COMP_DATA_SRV_H__ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/mesh/main.h b/include/zephyr/bluetooth/mesh/main.h index d1c2b753c831..5ac5447acea5 100644 --- a/include/zephyr/bluetooth/mesh/main.h +++ b/include/zephyr/bluetooth/mesh/main.h @@ -10,6 +10,11 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_MAIN_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_MAIN_H_ +#include +#include + +#include + /** * @brief Provisioning * @defgroup bt_mesh_prov Provisioning diff --git a/include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h b/include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h index 5db996fe44d3..554723c93d49 100644 --- a/include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h +++ b/include/zephyr/bluetooth/mesh/od_priv_proxy_cli.h @@ -13,6 +13,9 @@ #ifndef BT_MESH_OD_PRIV_PROXY_CLI_H__ #define BT_MESH_OD_PRIV_PROXY_CLI_H__ + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/mesh/od_priv_proxy_srv.h b/include/zephyr/bluetooth/mesh/od_priv_proxy_srv.h index 82cd116adf85..d0a7c7e38d36 100644 --- a/include/zephyr/bluetooth/mesh/od_priv_proxy_srv.h +++ b/include/zephyr/bluetooth/mesh/od_priv_proxy_srv.h @@ -14,6 +14,8 @@ #ifndef BT_MESH_OD_PRIV_PROXY_SRV_H__ #define BT_MESH_OD_PRIV_PROXY_SRV_H__ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/mesh/op_agg_cli.h b/include/zephyr/bluetooth/mesh/op_agg_cli.h index 8ca45492bf34..1e838d865a62 100644 --- a/include/zephyr/bluetooth/mesh/op_agg_cli.h +++ b/include/zephyr/bluetooth/mesh/op_agg_cli.h @@ -13,6 +13,8 @@ #ifndef BT_MESH_OP_AGG_CLI_H__ #define BT_MESH_OP_AGG_CLI_H__ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/mesh/op_agg_srv.h b/include/zephyr/bluetooth/mesh/op_agg_srv.h index c9d7013f8292..687b6126c87a 100644 --- a/include/zephyr/bluetooth/mesh/op_agg_srv.h +++ b/include/zephyr/bluetooth/mesh/op_agg_srv.h @@ -13,6 +13,8 @@ #ifndef BT_MESH_OP_AGG_SRV_H__ #define BT_MESH_OP_AGG_SRV_H__ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/mesh/proxy.h b/include/zephyr/bluetooth/mesh/proxy.h index 3ff85dd78862..b42db35e0fcc 100644 --- a/include/zephyr/bluetooth/mesh/proxy.h +++ b/include/zephyr/bluetooth/mesh/proxy.h @@ -10,6 +10,10 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_PROXY_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_PROXY_H_ +#include + +#include + /** * @brief Proxy * @defgroup bt_mesh_proxy Proxy diff --git a/include/zephyr/bluetooth/mesh/sar_cfg.h b/include/zephyr/bluetooth/mesh/sar_cfg.h index c94c71fe9bf6..5f071be0c4a4 100644 --- a/include/zephyr/bluetooth/mesh/sar_cfg.h +++ b/include/zephyr/bluetooth/mesh/sar_cfg.h @@ -14,6 +14,8 @@ #ifndef BT_MESH_SAR_CFG_H__ #define BT_MESH_SAR_CFG_H__ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/mesh/sar_cfg_cli.h b/include/zephyr/bluetooth/mesh/sar_cfg_cli.h index e5d3f597db40..7882174512e4 100644 --- a/include/zephyr/bluetooth/mesh/sar_cfg_cli.h +++ b/include/zephyr/bluetooth/mesh/sar_cfg_cli.h @@ -10,6 +10,7 @@ #ifndef BT_MESH_SAR_CFG_CLI_H__ #define BT_MESH_SAR_CFG_CLI_H__ +#include #include /** diff --git a/include/zephyr/bluetooth/mesh/sar_cfg_srv.h b/include/zephyr/bluetooth/mesh/sar_cfg_srv.h index 846e5e728536..9ca79f5a0861 100644 --- a/include/zephyr/bluetooth/mesh/sar_cfg_srv.h +++ b/include/zephyr/bluetooth/mesh/sar_cfg_srv.h @@ -10,6 +10,7 @@ #ifndef BT_MESH_SAR_CFG_SRV_H__ #define BT_MESH_SAR_CFG_SRV_H__ +#include #include /** diff --git a/include/zephyr/bluetooth/mesh/sol_pdu_rpl_cli.h b/include/zephyr/bluetooth/mesh/sol_pdu_rpl_cli.h index 8269c25441b2..ab818eeeb611 100644 --- a/include/zephyr/bluetooth/mesh/sol_pdu_rpl_cli.h +++ b/include/zephyr/bluetooth/mesh/sol_pdu_rpl_cli.h @@ -13,6 +13,9 @@ #ifndef BT_MESH_SOL_PDU_RPL_CLI_H__ #define BT_MESH_SOL_PDU_RPL_CLI_H__ + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/services/bas.h b/include/zephyr/bluetooth/services/bas.h index 06a3b295bab4..594133464014 100644 --- a/include/zephyr/bluetooth/services/bas.h +++ b/include/zephyr/bluetooth/services/bas.h @@ -18,7 +18,7 @@ * as a part of ongoing development. */ -#include +#include #ifdef __cplusplus extern "C" { diff --git a/include/zephyr/bluetooth/services/hrs.h b/include/zephyr/bluetooth/services/hrs.h index b05f42432311..097998f5caf3 100644 --- a/include/zephyr/bluetooth/services/hrs.h +++ b/include/zephyr/bluetooth/services/hrs.h @@ -17,6 +17,8 @@ * as a part of ongoing development. */ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/zephyr/bluetooth/services/ots.h b/include/zephyr/bluetooth/services/ots.h index 69a0ec7031a2..bc9d097af786 100644 --- a/include/zephyr/bluetooth/services/ots.h +++ b/include/zephyr/bluetooth/services/ots.h @@ -17,20 +17,22 @@ * as a part of ongoing development. */ -#ifdef __cplusplus -extern "C" { -#endif - #include -#include -#include +#include + #include + +#include #include #include #include #include #include +#ifdef __cplusplus +extern "C" { +#endif + /** @brief Size of OTS object ID (in bytes). */ #define BT_OTS_OBJ_ID_SIZE 6 diff --git a/include/zephyr/bluetooth/testing.h b/include/zephyr/bluetooth/testing.h index 67aacedc78c8..9cfda4e11779 100644 --- a/include/zephyr/bluetooth/testing.h +++ b/include/zephyr/bluetooth/testing.h @@ -11,6 +11,8 @@ #ifndef ZEPHYR_INCLUDE_BLUETOOTH_TESTING_H_ #define ZEPHYR_INCLUDE_BLUETOOTH_TESTING_H_ +#include + #if defined(CONFIG_BT_MESH) #include #endif /* CONFIG_BT_MESH */ diff --git a/include/zephyr/bluetooth/uuid.h b/include/zephyr/bluetooth/uuid.h index 0a48614fb26a..eb35f929b322 100644 --- a/include/zephyr/bluetooth/uuid.h +++ b/include/zephyr/bluetooth/uuid.h @@ -17,6 +17,8 @@ * @{ */ +#include + #include #ifdef __cplusplus From 92d6df6620ac8a2e5b45268b333f4348bdf5d65d Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Thu, 9 Feb 2023 12:34:37 +0100 Subject: [PATCH 0741/1906] dts: arm: nordic: introduce easydma-maxcnt-bits The number of available EasyDMA MAXCNT bits is now defined per-instance in Devicetree. Signed-off-by: Gerard Marull-Paretas --- drivers/spi/spi_nrfx_spim.c | 9 ++++----- drivers/spi/spi_nrfx_spis.c | 12 ++++-------- dts/arm/nordic/nrf51822.dtsi | 2 ++ dts/arm/nordic/nrf52805.dtsi | 1 + dts/arm/nordic/nrf52810.dtsi | 1 + dts/arm/nordic/nrf52811.dtsi | 2 ++ dts/arm/nordic/nrf52820.dtsi | 2 ++ dts/arm/nordic/nrf52832.dtsi | 3 +++ dts/arm/nordic/nrf52833.dtsi | 4 ++++ dts/arm/nordic/nrf52840.dtsi | 4 ++++ dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi | 5 +++++ dts/arm/nordic/nrf5340_cpunet.dtsi | 1 + dts/arm/nordic/nrf9160_common.dtsi | 4 ++++ dts/bindings/spi/nordic,nrf-spi-common.yaml | 7 +++++++ 14 files changed, 44 insertions(+), 13 deletions(-) diff --git a/drivers/spi/spi_nrfx_spim.c b/drivers/spi/spi_nrfx_spim.c index 1ba69554233b..fd8e3c24794e 100644 --- a/drivers/spi/spi_nrfx_spim.c +++ b/drivers/spi/spi_nrfx_spim.c @@ -27,9 +27,6 @@ LOG_MODULE_REGISTER(spi_nrfx_spim, CONFIG_SPI_LOG_LEVEL); #define SPI_BUFFER_IN_RAM 1 #endif -/* Maximum chunk length (depends on the EasyDMA bits, equal for all instances) */ -#define MAX_CHUNK_LEN BIT_MASK(SPIM0_EASYDMA_MAXCNT_SIZE) - struct spi_nrfx_data { struct spi_context ctx; const struct device *dev; @@ -51,6 +48,7 @@ struct spi_nrfx_config { uint32_t max_freq; nrfx_spim_config_t def_config; void (*irq_connect)(void); + uint16_t max_chunk_len; const struct pinctrl_dev_config *pcfg; #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 bool anomaly_58_workaround; @@ -319,8 +317,8 @@ static void transfer_next_chunk(const struct device *dev) tx_buf = dev_data->buffer; } #endif - if (chunk_len > MAX_CHUNK_LEN) { - chunk_len = MAX_CHUNK_LEN; + if (chunk_len > dev_config->max_chunk_len) { + chunk_len = dev_config->max_chunk_len; } dev_data->chunk_len = chunk_len; @@ -602,6 +600,7 @@ static int spi_nrfx_init(const struct device *dev) }, \ .irq_connect = irq_connect##idx, \ .pcfg = PINCTRL_DT_DEV_CONFIG_GET(SPIM(idx)), \ + .max_chunk_len = BIT_MASK(SPIM_PROP(idx, easydma_maxcnt_bits)),\ COND_CODE_1(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58, \ (.anomaly_58_workaround = \ SPIM_PROP(idx, anomaly_58_workaround),), \ diff --git a/drivers/spi/spi_nrfx_spis.c b/drivers/spi/spi_nrfx_spis.c index 18924b288930..b61c9459cb30 100644 --- a/drivers/spi/spi_nrfx_spis.c +++ b/drivers/spi/spi_nrfx_spis.c @@ -23,16 +23,10 @@ struct spi_nrfx_config { nrfx_spis_t spis; nrfx_spis_config_t config; void (*irq_connect)(void); + uint16_t max_buf_len; const struct pinctrl_dev_config *pcfg; }; -/* Maximum buffer length (depends on the EasyDMA bits, equal for all instances) */ -#if defined(SPIS0_EASYDMA_MAXCNT_SIZE) -#define MAX_BUF_LEN BIT_MASK(SPIS0_EASYDMA_MAXCNT_SIZE) -#else -#define MAX_BUF_LEN BIT_MASK(SPIS1_EASYDMA_MAXCNT_SIZE) -#endif - static inline nrf_spis_mode_t get_nrf_spis_mode(uint16_t operation) { if (SPI_MODE_GET(operation) & SPI_MODE_CPOL) { @@ -119,7 +113,8 @@ static void prepare_for_transfer(const struct device *dev, const struct spi_nrfx_config *dev_config = dev->config; int status; - if (tx_buf_len > MAX_BUF_LEN || rx_buf_len > MAX_BUF_LEN) { + if (tx_buf_len > dev_config->max_buf_len || + rx_buf_len > dev_config->max_buf_len) { LOG_ERR("Invalid buffer sizes: Tx %d/Rx %d", tx_buf_len, rx_buf_len); status = -EINVAL; @@ -295,6 +290,7 @@ static int spi_nrfx_init(const struct device *dev) }, \ .irq_connect = irq_connect##idx, \ .pcfg = PINCTRL_DT_DEV_CONFIG_GET(SPIS(idx)), \ + .max_buf_len = BIT_MASK(SPIS_PROP(idx, easydma_maxcnt_bits)), \ }; \ DEVICE_DT_DEFINE(SPIS(idx), \ spi_nrfx_init, \ diff --git a/dts/arm/nordic/nrf51822.dtsi b/dts/arm/nordic/nrf51822.dtsi index 3fa875ac9003..1e6b0e886e71 100644 --- a/dts/arm/nordic/nrf51822.dtsi +++ b/dts/arm/nordic/nrf51822.dtsi @@ -86,6 +86,7 @@ reg = <0x40003000 0x1000>; interrupts = <3 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <8>; status = "disabled"; }; @@ -112,6 +113,7 @@ reg = <0x40004000 0x1000>; interrupts = <4 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <8>; status = "disabled"; }; diff --git a/dts/arm/nordic/nrf52805.dtsi b/dts/arm/nordic/nrf52805.dtsi index ee89039448d8..c2c5ddd35328 100644 --- a/dts/arm/nordic/nrf52805.dtsi +++ b/dts/arm/nordic/nrf52805.dtsi @@ -123,6 +123,7 @@ reg = <0x40004000 0x1000>; interrupts = <4 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <14>; status = "disabled"; }; diff --git a/dts/arm/nordic/nrf52810.dtsi b/dts/arm/nordic/nrf52810.dtsi index da166f1ed966..be196352fe2f 100644 --- a/dts/arm/nordic/nrf52810.dtsi +++ b/dts/arm/nordic/nrf52810.dtsi @@ -127,6 +127,7 @@ reg = <0x40004000 0x1000>; interrupts = <4 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <10>; status = "disabled"; }; diff --git a/dts/arm/nordic/nrf52811.dtsi b/dts/arm/nordic/nrf52811.dtsi index ade3f54e9041..f41565d94c6c 100644 --- a/dts/arm/nordic/nrf52811.dtsi +++ b/dts/arm/nordic/nrf52811.dtsi @@ -140,6 +140,7 @@ reg = <0x40003000 0x1000>; interrupts = <3 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <14>; status = "disabled"; }; @@ -157,6 +158,7 @@ reg = <0x40004000 0x1000>; interrupts = <4 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <14>; status = "disabled"; }; diff --git a/dts/arm/nordic/nrf52820.dtsi b/dts/arm/nordic/nrf52820.dtsi index 83e882df2819..b641535a9be1 100644 --- a/dts/arm/nordic/nrf52820.dtsi +++ b/dts/arm/nordic/nrf52820.dtsi @@ -129,6 +129,7 @@ reg = <0x40003000 0x1000>; interrupts = <3 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <15>; status = "disabled"; }; @@ -163,6 +164,7 @@ reg = <0x40004000 0x1000>; interrupts = <4 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <15>; status = "disabled"; }; diff --git a/dts/arm/nordic/nrf52832.dtsi b/dts/arm/nordic/nrf52832.dtsi index c82d992d1a47..3005e60e5737 100644 --- a/dts/arm/nordic/nrf52832.dtsi +++ b/dts/arm/nordic/nrf52832.dtsi @@ -127,6 +127,7 @@ reg = <0x40003000 0x1000>; interrupts = <3 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <8>; status = "disabled"; }; @@ -161,6 +162,7 @@ reg = <0x40004000 0x1000>; interrupts = <4 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <8>; status = "disabled"; }; @@ -427,6 +429,7 @@ reg = <0x40023000 0x1000>; interrupts = <35 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <8>; status = "disabled"; }; diff --git a/dts/arm/nordic/nrf52833.dtsi b/dts/arm/nordic/nrf52833.dtsi index 37390dfc9fe6..6994e7649d83 100644 --- a/dts/arm/nordic/nrf52833.dtsi +++ b/dts/arm/nordic/nrf52833.dtsi @@ -134,6 +134,7 @@ reg = <0x40003000 0x1000>; interrupts = <3 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; status = "disabled"; }; @@ -168,6 +169,7 @@ reg = <0x40004000 0x1000>; interrupts = <4 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; status = "disabled"; }; @@ -441,6 +443,7 @@ reg = <0x40023000 0x1000>; interrupts = <35 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; status = "disabled"; }; @@ -497,6 +500,7 @@ reg = <0x4002f000 0x1000>; interrupts = <47 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; rx-delay-supported; rx-delay = <2>; status = "disabled"; diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index 3efa10b25e30..0fb5fb753cd4 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -129,6 +129,7 @@ reg = <0x40003000 0x1000>; interrupts = <3 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; status = "disabled"; }; @@ -163,6 +164,7 @@ reg = <0x40004000 0x1000>; interrupts = <4 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; status = "disabled"; }; @@ -436,6 +438,7 @@ reg = <0x40023000 0x1000>; interrupts = <35 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; status = "disabled"; }; @@ -502,6 +505,7 @@ reg = <0x4002f000 0x1000>; interrupts = <47 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; rx-delay-supported; rx-delay = <2>; status = "disabled"; diff --git a/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi b/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi index 09267d53eb27..eeed23eb6d30 100644 --- a/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp_peripherals.dtsi @@ -90,6 +90,7 @@ spi0: spi@8000 { reg = <0x8000 0x1000>; interrupts = <8 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; status = "disabled"; }; @@ -129,6 +130,7 @@ spi1: spi@9000 { reg = <0x9000 0x1000>; interrupts = <9 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; status = "disabled"; }; @@ -146,6 +148,7 @@ spi4: spi@a000 { reg = <0xa000 0x1000>; interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; rx-delay-supported; rx-delay = <2>; status = "disabled"; @@ -180,6 +183,7 @@ spi2: spi@b000 { reg = <0xb000 0x1000>; interrupts = <11 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; status = "disabled"; }; @@ -219,6 +223,7 @@ spi3: spi@c000 { reg = <0xc000 0x1000>; interrupts = <12 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; status = "disabled"; }; diff --git a/dts/arm/nordic/nrf5340_cpunet.dtsi b/dts/arm/nordic/nrf5340_cpunet.dtsi index 69069f5d9e0b..aed053a5a7f2 100644 --- a/dts/arm/nordic/nrf5340_cpunet.dtsi +++ b/dts/arm/nordic/nrf5340_cpunet.dtsi @@ -203,6 +203,7 @@ reg = <0x41013000 0x1000>; interrupts = <19 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <16>; status = "disabled"; }; diff --git a/dts/arm/nordic/nrf9160_common.dtsi b/dts/arm/nordic/nrf9160_common.dtsi index 49e23554b853..676dd99d60f6 100644 --- a/dts/arm/nordic/nrf9160_common.dtsi +++ b/dts/arm/nordic/nrf9160_common.dtsi @@ -218,6 +218,7 @@ spi0: spi@8000 { reg = <0x8000 0x1000>; interrupts = <8 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <13>; status = "disabled"; }; @@ -233,6 +234,7 @@ spi1: spi@9000 { reg = <0x9000 0x1000>; interrupts = <9 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <13>; status = "disabled"; }; @@ -248,6 +250,7 @@ spi2: spi@a000 { reg = <0xa000 0x1000>; interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <13>; status = "disabled"; }; @@ -263,6 +266,7 @@ spi3: spi@b000 { reg = <0xb000 0x1000>; interrupts = <11 NRF_DEFAULT_IRQ_PRIORITY>; max-frequency = ; + easydma-maxcnt-bits = <13>; status = "disabled"; }; diff --git a/dts/bindings/spi/nordic,nrf-spi-common.yaml b/dts/bindings/spi/nordic,nrf-spi-common.yaml index 02e0ba61e604..d9c0d2f9ae3a 100644 --- a/dts/bindings/spi/nordic,nrf-spi-common.yaml +++ b/dts/bindings/spi/nordic,nrf-spi-common.yaml @@ -29,3 +29,10 @@ properties: The overrun character (ORC) is used when all bytes from the TX buffer are sent, but the transfer continues due to RX. Defaults to 0xff (line high), the most common value used in SPI transfers. + + easydma-maxcnt-bits: + type: int + required: true + description: | + Maximum number of bits available in the EasyDMA MAXCNT register. This + property must be set at SoC level DTS files. From 852b3e9e172d8248a32e6cf998f34e2e26b1034e Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Sun, 12 Feb 2023 09:26:56 +0530 Subject: [PATCH 0742/1906] Bluetooth: Controller: Reschedule unreserved ticker with slot window Update ticker implementation to reschedule unreserved ticker that use ticks_slot_window. This will avoid unreserved ticker from continuously overlapping with reserved tickers. And the change is required to reduce processing overheads before reserve ticker timeout callback executes. Unreserved tickers with ticks_slot_window will always yield to any colliding reserved or unreserved tickers. The implementation moves unreserved tickers (no ticks_slot value, in this case continuous scan window) to end of a colliding reserved/unreserved ticker so that reserved tickers (like central role) do not have high overheads due to unreserved ticker's prepare (scanner) be preempted everytime before reserved ticker's prepare (central). Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/ticker/ticker.c | 211 +++++++++++++------- 1 file changed, 140 insertions(+), 71 deletions(-) diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index 13e366f41e86..02047ba32493 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -136,10 +136,13 @@ struct ticker_expire_info_internal { #define TICKER_RESCHEDULE_STATE_DONE 2 #if defined(CONFIG_BT_TICKER_EXT) && !defined(CONFIG_BT_TICKER_SLOT_AGNOSTIC) +#define TICKER_HAS_SLOT_WINDOW(_ticker) \ + ((_ticker)->ext_data && ((_ticker)->ext_data->ticks_slot_window != 0U)) #define TICKER_RESCHEDULE_PENDING(_ticker) \ (_ticker->ext_data && (_ticker->ext_data->reschedule_state == \ TICKER_RESCHEDULE_STATE_PENDING)) #else +#define TICKER_HAS_SLOT_WINDOW(_ticker) 0 #define TICKER_RESCHEDULE_PENDING(_ticker) 0 #endif @@ -794,6 +797,13 @@ static uint8_t ticker_resolve_collision(struct ticker_node *nodes, #endif /* !CONFIG_BT_TICKER_PRIORITY_SET */ uint16_t lazy_current = ticker->lazy_current; + uint32_t ticker_ticks_slot; + + if (TICKER_HAS_SLOT_WINDOW(ticker) && !ticker->ticks_slot) { + ticker_ticks_slot = HAL_TICKER_RESCHEDULE_MARGIN; + } else { + ticker_ticks_slot = ticker->ticks_slot; + } /* Check if this ticker node will starve next node which has * latency or higher priority @@ -813,7 +823,7 @@ static uint8_t ticker_resolve_collision(struct ticker_node *nodes, /* Accumulate ticks_to_expire for each node */ acc_ticks_to_expire += ticker_next->ticks_to_expire; - if (acc_ticks_to_expire > ticker->ticks_slot) { + if (acc_ticks_to_expire > ticker_ticks_slot) { break; } @@ -876,49 +886,73 @@ static uint8_t ticker_resolve_collision(struct ticker_node *nodes, #endif /* !CONFIG_BT_TICKER_PRIORITY_SET */ +#if defined(CONFIG_BT_TICKER_EXT) #if defined(CONFIG_BT_TICKER_EXT_SLOT_WINDOW_YIELD) #if defined(CONFIG_BT_TICKER_PRIORITY_SET) /* Does next node have higher priority? */ uint8_t next_has_priority = - (!ticker_next->ext_data || - !ticker_next->ext_data->ticks_slot_window) && + (!TICKER_HAS_SLOT_WINDOW(ticker_next) && ((lazy_next - ticker_next->priority) > (lazy_current - ticker->priority)); #endif /* CONFIG_BT_TICKER_PRIORITY_SET */ - /* Can the current ticker with ticks_slot_window be - * scheduled after the colliding ticker? - */ - uint8_t curr_has_ticks_slot_window = - (ticker->ext_data && - ticker->ext_data->ticks_slot_window && - ((acc_ticks_to_expire + - ticker_next->ticks_slot) < - (ticker->ext_data->ticks_slot_window - - ticker->ticks_slot))); - /* Colliding next ticker does not use ticks_slot_window * or it does not fit after the current ticker within * the ticks_slot_window. */ uint8_t next_not_ticks_slot_window = - (!ticker_next->ext_data || - !ticker_next->ext_data->ticks_slot_window || + (!TICKER_HAS_SLOT_WINDOW(ticker_next) || ((acc_ticks_to_expire + ticker_next->ext_data->ticks_slot_window - ticker_next->ticks_slot) < ticker->ticks_slot)); + + /* Can the current ticker with ticks_slot_window be + * scheduled after the colliding ticker? + */ + uint8_t curr_has_ticks_slot_window = + (TICKER_HAS_SLOT_WINDOW(ticker) && + ((acc_ticks_to_expire + + ticker_next->ticks_slot) < + (ticker->ext_data->ticks_slot_window - + ticker->ticks_slot))); + #else /* !CONFIG_BT_TICKER_EXT_SLOT_WINDOW_YIELD */ #if defined(CONFIG_BT_TICKER_PRIORITY_SET) /* Does next node have higher priority? */ uint8_t next_has_priority = (lazy_next - ticker_next->priority) > (lazy_current - ticker->priority); -#endif /* CONFIG_BT_TICKER_PRIORITY_SET */ - uint8_t curr_has_ticks_slot_window = 0U; +#endif /* CONFIG_BT_TICKER_PRIORITY_SET */ uint8_t next_not_ticks_slot_window = 1U; + + /* Can the current ticker with ticks_slot_window be + * scheduled after the colliding ticker? + * NOTE: Tickers with ticks_slot_window and no + * ticks_slot (unreserved) be always scheduled + * after the colliding ticker. + */ + uint8_t curr_has_ticks_slot_window = + (TICKER_HAS_SLOT_WINDOW(ticker) && + !ticker->ticks_slot && + ((acc_ticks_to_expire + + ticker_next->ticks_slot) < + (ticker->ext_data->ticks_slot_window))); + #endif /* !CONFIG_BT_TICKER_EXT_SLOT_WINDOW_YIELD */ +#else /* !CONFIG_BT_TICKER_EXT */ +#if defined(CONFIG_BT_TICKER_PRIORITY_SET) + /* Does next node have higher priority? */ + uint8_t next_has_priority = + (lazy_next - ticker_next->priority) > + (lazy_current - ticker->priority); + +#endif /* CONFIG_BT_TICKER_PRIORITY_SET */ + uint8_t next_not_ticks_slot_window = 1U; + uint8_t curr_has_ticks_slot_window = 0U; + +#endif /* !CONFIG_BT_TICKER_EXT */ /* Check if next node is within this reservation slot * and wins conflict resolution @@ -1211,10 +1245,11 @@ void ticker_worker(void *param) /* Check if node has slot reservation and resolve any collision * with other ticker nodes */ - if (ticker->ticks_slot != 0U && - (slot_reserved || - (instance->ticks_slot_previous > ticks_expired) || - ticker_resolve_collision(node, ticker))) { + if (((ticker->ticks_slot != 0U) || + TICKER_HAS_SLOT_WINDOW(ticker)) && + (slot_reserved || + (instance->ticks_slot_previous > ticks_expired) || + ticker_resolve_collision(node, ticker))) { #if defined(CONFIG_BT_TICKER_EXT) struct ticker_ext *ext_data = ticker->ext_data; @@ -1248,6 +1283,7 @@ void ticker_worker(void *param) ticker->ack--; continue; } + /* Continue but perform shallow expiry */ must_expire_skip = 1U; } @@ -1274,6 +1310,7 @@ void ticker_worker(void *param) #endif /* CONFIG_BT_TICKER_LOW_LAT || * CONFIG_BT_TICKER_SLOT_AGNOSTIC */ + /* Scheduled timeout is acknowledged to be complete */ ticker->ack--; @@ -2228,41 +2265,32 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, uint32_t ticks_elapsed) { struct ticker_node *nodes; - struct ticker_node *ticker; - struct ticker_node *node; - struct ticker_ext *ext_data; - - uint32_t window_start_ticks; - uint32_t window_end_ticks; - uint32_t ticks_to_expire; - uint32_t ticks_start_offset; - uint32_t ticks_slot_window = 0; - - uint8_t ticker_id_head; - uint8_t ticker_id_iter; - uint8_t ticker_id_prev; - - uint8_t rescheduling = 1U; - uint8_t rescheduled = 0U; + uint8_t rescheduling = 1U; + uint8_t rescheduled = 0U; nodes = &instance->nodes[0]; /* Do until all pending re-schedules handled */ while (rescheduling) { - ticker_id_head = instance->ticker_id_head; - rescheduling = 0U; + uint32_t ticks_to_expire_offset = 0U; + uint32_t ticks_start_offset = 0U; + uint32_t window_start_ticks = 0U; + uint32_t ticks_slot_window = 0U; + uint32_t ticks_to_expire = 0U; + struct ticker_ext *ext_data; + struct ticker_node *ticker; + uint8_t ticker_id_head; + uint8_t ticker_id_prev; + uint8_t ticker_id_iter; + uint32_t ticks_slot; - ticks_start_offset = 0U; - window_start_ticks = 0U; - window_end_ticks = 0U; - ticks_to_expire = 0U; + rescheduling = 0U; /* Find first pending re-schedule */ + ticker_id_head = instance->ticker_id_head; while (ticker_id_head != TICKER_NULL) { ticker = &nodes[ticker_id_head]; - ext_data = ticker->ext_data; - if (ext_data && ext_data->reschedule_state == - TICKER_RESCHEDULE_STATE_PENDING) { + if (TICKER_RESCHEDULE_PENDING(ticker)) { /* Pending reschedule found */ break; } @@ -2293,6 +2321,7 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, * ticker would have the best possible window to re-schedule in * and not be restricted to ticks_slot_window - ticks_drift. */ + ext_data = ticker->ext_data; if (ext_data->ticks_drift < ext_data->ticks_slot_window) { ticks_slot_window = ext_data->ticks_slot_window - ext_data->ticks_drift; @@ -2301,17 +2330,33 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, ticker_id_iter = TICKER_NULL; } + /* Use ticker's reserved time ticks_slot, else for unreserved + * tickers use the reschedule margin as ticks_slot. + */ + if (ticker->ticks_slot) { + ticks_slot = ticker->ticks_slot; + } else { + LL_ASSERT(TICKER_HAS_SLOT_WINDOW(ticker)); + + ticks_slot = HAL_TICKER_RESCHEDULE_MARGIN; + } + /* Try to find available slot for re-scheduling */ - while (ticker_id_iter != TICKER_NULL && - ticks_start_offset + ticker->ticks_slot <= - ticks_slot_window) { + while ((ticker_id_iter != TICKER_NULL) && + ((ticks_start_offset + ticks_slot) <= + ticks_slot_window)) { + uint32_t window_end_ticks = 0U; + struct ticker_node *node; node = &nodes[ticker_id_iter]; + ticks_to_expire_offset += node->ticks_to_expire; - if (node->ext_data && - node->ext_data->reschedule_state == - TICKER_RESCHEDULE_STATE_PENDING) { - /* Skip other pending re-schedule nodes */ + /* Skip other pending re-schedule nodes and + * tickers with no reservation or not periodic + */ + if (TICKER_RESCHEDULE_PENDING(node) || + !node->ticks_slot || + !node->ticks_periodic) { ticker_id_iter = node->next; continue; } @@ -2319,12 +2364,12 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, /* Calculate end of window. Since window may be aligned * with expiry of next node, we add a margin */ - if (node->ticks_to_expire > + if (ticks_to_expire_offset > HAL_TICKER_RESCHEDULE_MARGIN) { window_end_ticks = MIN(ticks_slot_window, ticks_start_offset + - node->ticks_to_expire - + ticks_to_expire_offset - HAL_TICKER_RESCHEDULE_MARGIN); } else { /* Next expiry is too close - try the next @@ -2334,12 +2379,22 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, } /* Calculate new ticks_to_expire as end of window minus - * slot size => place at end of window. + * slot size. */ - if (window_end_ticks > ticks_start_offset + - ticker->ticks_slot) { - ticks_to_expire = window_end_ticks - - ticker->ticks_slot; + if (window_end_ticks > (ticks_start_offset + + ticks_slot)) { + if (!ticker->ticks_slot) { + /* Place at start of window */ + ticks_to_expire = window_start_ticks; + } else { + /* Place at end of window. This ensures + * that ticker with slot window and that + * uses ticks_slot does not take the + * interval of the colliding ticker. + */ + ticks_to_expire = window_end_ticks - + ticks_slot; + } } else { /* No space in window - try the next node */ ticks_to_expire = 0; @@ -2348,10 +2403,10 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, /* Decide if the re-scheduling ticker node fits in the * slot found - break if it fits */ - if (ticks_to_expire != 0U && - ticks_to_expire >= window_start_ticks && - ticks_to_expire <= window_end_ticks - - ticker->ticks_slot) { + if ((ticks_to_expire != 0U) && + (ticks_to_expire >= window_start_ticks) && + (ticks_to_expire <= (window_end_ticks - + ticks_slot))) { /* Re-scheduled node fits before this node */ break; } @@ -2359,17 +2414,29 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, /* We din't find a valid slot for re-scheduling - try * the next node */ - ticks_start_offset += node->ticks_to_expire; - window_start_ticks = node->ticks_to_expire + + ticks_start_offset += ticks_to_expire_offset; + window_start_ticks = ticks_start_offset + node->ticks_slot; - ticks_to_expire = ticks_slot_window - - ticker->ticks_slot; + ticks_to_expire_offset = 0U; + + if (!ticker->ticks_slot) { + /* Try at the end of the next node */ + ticks_to_expire = window_start_ticks; + } else { + /* Try at the end of the slot window. This + * ensures that ticker with slot window and that + * uses ticks_slot does not take the interval of + * the colliding ticker. + */ + ticks_to_expire = ticks_slot_window - + ticks_slot; + } ticker_id_iter = node->next; } - ticker->ext_data->ticks_drift += ticks_to_expire - - ticker->ticks_to_expire; + ext_data->ticks_drift += ticks_to_expire - + ticker->ticks_to_expire; ticker->ticks_to_expire = ticks_to_expire; ticker_id_iter = nodes[ticker_id_head].next; ticker_id_prev = TICKER_NULL; @@ -2378,6 +2445,8 @@ static uint8_t ticker_job_reschedule_in_window(struct ticker_instance *instance, * delta times */ while (ticker_id_iter != TICKER_NULL) { + struct ticker_node *node; + node = &nodes[ticker_id_iter]; if (ticker->ticks_to_expire > node->ticks_to_expire) { /* Node is after this - adjust delta */ From 925066ae1f0b8b4b295d9b5a4c8e7e52c0890a76 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Sun, 12 Feb 2023 11:19:00 +0530 Subject: [PATCH 0743/1906] Bluetooth: Controller: Continuous scan with ticks_slot_window Use ticks_slot_window for continuous scanning. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/ll_sw/ull_scan.c | 33 +++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull_scan.c b/subsys/bluetooth/controller/ll_sw/ull_scan.c index d86337baf062..2643771756dd 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_scan.c +++ b/subsys/bluetooth/controller/ll_sw/ull_scan.c @@ -76,6 +76,10 @@ static void ext_disabled_cb(void *param); static struct ll_scan_set ll_scan[BT_CTLR_SCAN_SET]; +#if defined(CONFIG_BT_TICKER_EXT) +static struct ticker_ext ll_scan_ticker_ext[BT_CTLR_SCAN_SET]; +#endif /* CONFIG_BT_TICKER_EXT */ + uint8_t ll_scan_params_set(uint8_t type, uint16_t interval, uint16_t window, uint8_t own_addr_type, uint8_t filter_policy) { @@ -415,6 +419,8 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan) ticks_slot_overhead = 0U; } + handle = ull_scan_handle_get(scan); + lll->ticks_window = scan->ticks_window; if ((lll->ticks_window + HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US)) < @@ -422,6 +428,12 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan) scan->ull.ticks_slot = (lll->ticks_window + HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_START_US)); + +#if defined(CONFIG_BT_TICKER_EXT) + ll_scan_ticker_ext[handle].ticks_slot_window = + scan->ull.ticks_slot + ticks_slot_overhead; +#endif /* CONFIG_BT_TICKER_EXT */ + } else { if (IS_ENABLED(CONFIG_BT_CTLR_SCAN_UNRESERVED)) { scan->ull.ticks_slot = 0U; @@ -431,9 +443,11 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan) } lll->ticks_window = 0U; - } - handle = ull_scan_handle_get(scan); +#if defined(CONFIG_BT_TICKER_EXT) + ll_scan_ticker_ext[handle].ticks_slot_window = ticks_interval; +#endif /* CONFIG_BT_TICKER_EXT */ + } if (false) { @@ -580,7 +594,13 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan) #endif /* CONFIG_BT_CENTRAL && CONFIG_BT_CTLR_SCHED_ADVANCED */ ret_cb = TICKER_STATUS_BUSY; - ret = ticker_start(TICKER_INSTANCE_ID_CTLR, + +#if defined(CONFIG_BT_TICKER_EXT) + ret = ticker_start_ext( +#else + ret = ticker_start( +#endif /* CONFIG_BT_TICKER_EXT */ + TICKER_INSTANCE_ID_CTLR, TICKER_USER_ID_THREAD, TICKER_ID_SCAN_BASE + handle, (ticks_anchor + ticks_offset), 0, ticks_interval, HAL_TICKER_REMAINDER((uint64_t)lll->interval * @@ -588,7 +608,12 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan) TICKER_NULL_LAZY, (scan->ull.ticks_slot + ticks_slot_overhead), ticker_cb, scan, - ull_ticker_status_give, (void *)&ret_cb); + ull_ticker_status_give, (void *)&ret_cb +#if defined(CONFIG_BT_TICKER_EXT) + , + &ll_scan_ticker_ext[handle] +#endif /* CONFIG_BT_TICKER_EXT */ + ); ret = ull_ticker_status_take(ret, &ret_cb); if (ret != TICKER_STATUS_SUCCESS) { return BT_HCI_ERR_CMD_DISALLOWED; From 245b9c666ec9d2754cd554a8809301d40f08568e Mon Sep 17 00:00:00 2001 From: Piotr Mienkowski Date: Thu, 23 Mar 2023 21:38:53 +0100 Subject: [PATCH 0744/1906] MAINTAINERS: remove inactive self as GPIO maintainer I am no longer able to act as GPIO subsystem maintainer. I would like to degrade my role to collaborator. Signed-off-by: Piotr Mienkowski --- MAINTAINERS.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index d8f50bc19bd6..79e7e0c72c12 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -865,12 +865,11 @@ Release Notes: - "area: Fuel Gauge" "Drivers: GPIO": - status: maintained - maintainers: - - mnkp + status: odd fixes collaborators: - henrikbrixandersen - cfriedt + - mnkp files: - doc/hardware/peripherals/gpio.rst - drivers/gpio/ From b161c7fca47f4cb3f7c18c552c50a74b876ee952 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Thu, 9 Feb 2023 11:53:32 +0530 Subject: [PATCH 0745/1906] Bluetooth: Controller: Fix ticker to reduce RTC min compare offset Fix ticker to explicitly trigger worker when ticks_to_expire is less than or equal to elapsed time. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/ticker/ticker.c | 27 +++++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index 02047ba32493..b7e5a9b076d4 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -2868,8 +2868,8 @@ ticker_job_compare_update(struct ticker_instance *instance, { struct ticker_node *ticker; uint32_t ticks_to_expire; - uint32_t ctr_post; - uint32_t ctr; + uint32_t ctr_curr; + uint32_t ctr_prev; uint32_t cc; uint32_t i; @@ -2913,25 +2913,36 @@ ticker_job_compare_update(struct ticker_instance *instance, * ahead of compare value to be set. */ i = 10U; + ctr_curr = cntr_cnt_get(); do { uint32_t ticks_elapsed; + uint32_t ticks_diff; LL_ASSERT(i); i--; - ctr = cntr_cnt_get(); cc = instance->ticks_current; - ticks_elapsed = ticker_ticks_diff_get(ctr, cc) + - HAL_TICKER_CNTR_CMP_OFFSET_MIN + + ticks_diff = ticker_ticks_diff_get(ctr_curr, cc); + /* Under BT_TICKER_LOW_LAT, bsim test fails, pending + * investigation immediate trigger not used for + * BT_TICKER_LOW_LAT. + */ + if (!IS_ENABLED(CONFIG_BT_TICKER_LOW_LAT) && + (ticks_diff >= ticks_to_expire)) { + return 1U; + } + + ticks_elapsed = ticks_diff + HAL_TICKER_CNTR_CMP_OFFSET_MIN + HAL_TICKER_CNTR_SET_LATENCY; cc += MAX(ticks_elapsed, ticks_to_expire); cc &= HAL_TICKER_CNTR_MASK; instance->trigger_set_cb(cc); - ctr_post = cntr_cnt_get(); - } while ((ticker_ticks_diff_get(ctr_post, ctr) + + ctr_prev = ctr_curr; + ctr_curr = cntr_cnt_get(); + } while ((ticker_ticks_diff_get(ctr_curr, ctr_prev) + HAL_TICKER_CNTR_CMP_OFFSET_MIN) > - ticker_ticks_diff_get(cc, ctr)); + ticker_ticks_diff_get(cc, ctr_prev)); return 0U; } From 88c3fe894fb0c881fd2ce815437c2843517076ad Mon Sep 17 00:00:00 2001 From: Rainer Paat Date: Wed, 22 Mar 2023 12:44:31 +0200 Subject: [PATCH 0746/1906] drivers: ethernet: w5500: Fix promiscuous mode Enabling MAC filtering by default on hw start and disabling it when promiscuous mode is activated. Signed-off-by: Rainer Paat --- drivers/ethernet/eth_w5500.c | 48 +++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/ethernet/eth_w5500.c b/drivers/ethernet/eth_w5500.c index 6cdec80c1229..bad65a3a60cf 100644 --- a/drivers/ethernet/eth_w5500.c +++ b/drivers/ethernet/eth_w5500.c @@ -340,37 +340,45 @@ static int w5500_set_config(const struct device *dev, enum ethernet_config_type type, const struct ethernet_config *config) { - uint8_t mode; - uint8_t mr = W5500_S0_MR_MF; - - w5500_spi_read(dev, W5500_S0_MR, &mode, 1); - if (IS_ENABLED(CONFIG_NET_PROMISCUOUS_MODE) && - type == ETHERNET_CONFIG_TYPE_PROMISC_MODE) { - if (config->promisc_mode) { - if (!(mode & BIT(mr))) { - return -EALREADY; + switch (type) { + case ETHERNET_CONFIG_TYPE_PROMISC_MODE: + if (IS_ENABLED(CONFIG_NET_PROMISCUOUS_MODE)) { + uint8_t mode; + uint8_t mr = W5500_S0_MR_MF; + + w5500_spi_read(dev, W5500_S0_MR, &mode, 1); + + if (config->promisc_mode) { + if (!(mode & BIT(mr))) { + return -EALREADY; + } + + /* disable MAC filtering */ + WRITE_BIT(mode, mr, 0); + } else { + if (mode & BIT(mr)) { + return -EALREADY; + } + + /* enable MAC filtering */ + WRITE_BIT(mode, mr, 1); } - } - /* clear */ - WRITE_BIT(mode, mr, 0); - } else { - if (mode & BIT(mr)) { - return -EALREADY; + return w5500_spi_write(dev, W5500_S0_MR, &mode, 1); } - /* set */ - WRITE_BIT(mode, mr, 1); + return -ENOTSUP; + default: + return -ENOTSUP; } - - return w5500_spi_write(dev, W5500_S0_MR, &mode, 1); } static int w5500_hw_start(const struct device *dev) { - uint8_t mode = S0_MR_MACRAW; + uint8_t mode = S0_MR_MACRAW | BIT(W5500_S0_MR_MF); uint8_t mask = IR_S0; + /* configure Socket 0 with MACRAW mode and MAC filtering enabled */ w5500_spi_write(dev, W5500_S0_MR, &mode, 1); w5500_command(dev, S0_CR_OPEN); From 2d26baaeb1b764350fe226a4089395d958154168 Mon Sep 17 00:00:00 2001 From: Rainer Paat Date: Wed, 22 Mar 2023 12:45:24 +0200 Subject: [PATCH 0747/1906] drivers: ethernet: w5500: MAC change support Devicetree local-mac-address and zephyr,random-mac-address support added. Updated w5500_set_config() to support ETHERNET_CONFIG_TYPE_MAC_ADDRESS and change the MAC address at runtime. Signed-off-by: Rainer Paat --- drivers/ethernet/eth_w5500.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/ethernet/eth_w5500.c b/drivers/ethernet/eth_w5500.c index bad65a3a60cf..c2e1cac18845 100644 --- a/drivers/ethernet/eth_w5500.c +++ b/drivers/ethernet/eth_w5500.c @@ -340,7 +340,26 @@ static int w5500_set_config(const struct device *dev, enum ethernet_config_type type, const struct ethernet_config *config) { + struct w5500_runtime *ctx = dev->data; + switch (type) { + case ETHERNET_CONFIG_TYPE_MAC_ADDRESS: + memcpy(ctx->mac_addr, + config->mac_address.addr, + sizeof(ctx->mac_addr)); + w5500_spi_write(dev, W5500_SHAR, ctx->mac_addr, sizeof(ctx->mac_addr)); + LOG_INF("%s MAC set to %02x:%02x:%02x:%02x:%02x:%02x", + dev->name, + ctx->mac_addr[0], ctx->mac_addr[1], + ctx->mac_addr[2], ctx->mac_addr[3], + ctx->mac_addr[4], ctx->mac_addr[5]); + + /* Register Ethernet MAC Address with the upper layer */ + net_if_set_link_addr(ctx->iface, ctx->mac_addr, + sizeof(ctx->mac_addr), + NET_LINK_ETHERNET); + + return 0; case ETHERNET_CONFIG_TYPE_PROMISC_MODE: if (IS_ENABLED(CONFIG_NET_PROMISCUOUS_MODE)) { uint8_t mode; @@ -441,6 +460,7 @@ static void w5500_set_macaddr(const struct device *dev) { struct w5500_runtime *ctx = dev->data; +#if DT_INST_PROP(0, zephyr_random_mac_address) /* override vendor bytes */ memset(ctx->mac_addr, '\0', sizeof(ctx->mac_addr)); ctx->mac_addr[0] = WIZNET_OUI_B0; @@ -449,6 +469,7 @@ static void w5500_set_macaddr(const struct device *dev) if (ctx->generate_mac) { ctx->generate_mac(ctx->mac_addr); } +#endif w5500_spi_write(dev, W5500_SHAR, ctx->mac_addr, sizeof(ctx->mac_addr)); } @@ -548,6 +569,9 @@ static int w5500_init(const struct device *dev) } static struct w5500_runtime w5500_0_runtime = { +#if NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(0)) + .mac_addr = DT_INST_PROP(0, local_mac_address), +#endif .generate_mac = w5500_random_mac, .tx_sem = Z_SEM_INITIALIZER(w5500_0_runtime.tx_sem, 1, UINT_MAX), From 38fdba17c59edfa50b5e32775efbac9b99adf99b Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Fri, 24 Mar 2023 13:35:57 +0200 Subject: [PATCH 0748/1906] doc: smbus: Cleanup SMBus documentation Fix typos and general improvements of the documentation. Signed-off-by: Andrei Emeltchenko --- include/zephyr/drivers/smbus.h | 128 ++++++++++++++++++--------------- 1 file changed, 71 insertions(+), 57 deletions(-) diff --git a/include/zephyr/drivers/smbus.h b/include/zephyr/drivers/smbus.h index 02e673c1e478..a33d18227ce1 100644 --- a/include/zephyr/drivers/smbus.h +++ b/include/zephyr/drivers/smbus.h @@ -255,6 +255,13 @@ enum smbus_direction { struct smbus_callback; +/** + * @brief Define SMBus callback handler function signature. + * + * @param dev Pointer to the device structure for the SMBus driver instance. + * @param cb Structure smbus_callback owning this handler. + * @param addr Address of the SMBus peripheral device. + */ typedef void (*smbus_callback_handler_t)(const struct device *dev, struct smbus_callback *cb, uint8_t addr); @@ -283,7 +290,7 @@ struct smbus_callback { * @brief Complete SMBus DT information * * @param bus SMBus bus - * @param addr peripheral address + * @param addr Address of the SMBus peripheral device. */ struct smbus_dt_spec { const struct device *bus; @@ -442,7 +449,8 @@ struct smbus_device_state { /** * @brief Updates the SMBus stats * - * @param dev SMBus device to update stats for + * @param dev Pointer to the device structure for the SMBus driver instance + * to update stats for. * @param sent Number of bytes sent * @param recv Number of bytes received */ @@ -535,12 +543,12 @@ static inline void smbus_xfer_stats(const struct device *dev, uint8_t sent, /** * @brief Configure operation of a SMBus host controller. * - * @param dev Pointer to the device structure for the driver instance. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param dev_config Bit-packed 32-bit value to the device runtime configuration * for the SMBus controller. * * @retval 0 If successful. - * @retval -EIO General input / output error, failed to configure device. + * @retval -EIO General input / output error. */ __syscall int smbus_configure(const struct device *dev, uint32_t dev_config); @@ -564,13 +572,14 @@ static inline int z_impl_smbus_configure(const struct device *dev, * smbus_get_config can return cached config or probe hardware, but it has to be * up to date with current configuration. * - * @param dev Pointer to the device structure for the driver instance. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param dev_config Pointer to return bit-packed 32-bit value of * the SMBus controller configuration. * * @retval 0 If successful. * @retval -EIO General input / output error. - * @retval -ENOSYS If get config is not implemented + * @retval -ENOSYS If function smbus_get_config() is not implemented + * by the driver. */ __syscall int smbus_get_config(const struct device *dev, uint32_t *dev_config); @@ -590,12 +599,13 @@ static inline int z_impl_smbus_get_config(const struct device *dev, /** * @brief Add SMBUSALERT callback for a SMBus host controller. * - * @param dev Pointer to the device structure for the driver instance. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param cb Pointer to a callback structure. * * @retval 0 If successful. - * @retval -EIO General input / output error, failed to configure device. - * @retval -ENOSYS If get config is not implemented + * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_smbalert_set_cb() is not implemented + * by the driver. */ __syscall int smbus_smbalert_set_cb(const struct device *dev, struct smbus_callback *cb); @@ -616,12 +626,13 @@ static inline int z_impl_smbus_smbalert_set_cb(const struct device *dev, /** * @brief Remove SMBUSALERT callback from a SMBus host controller. * - * @param dev Pointer to the device structure for the driver instance. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param cb Pointer to a callback structure. * * @retval 0 If successful. - * @retval -EIO General input / output error, failed to configure device. - * @retval -ENOSYS If get config is not implemented + * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_smbalert_remove_cb() is not implemented + * by the driver. */ __syscall int smbus_smbalert_remove_cb(const struct device *dev, struct smbus_callback *cb); @@ -642,12 +653,13 @@ static inline int z_impl_smbus_smbalert_remove_cb(const struct device *dev, /** * @brief Add Host Notify callback for a SMBus host controller. * - * @param dev Pointer to the device structure for the driver instance. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param cb Pointer to a callback structure. * * @retval 0 If successful. - * @retval -EIO General input / output error, failed to configure device. - * @retval -ENOSYS If get config is not implemented + * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_host_notify_set_cb() is not implemented + * by the driver. */ __syscall int smbus_host_notify_set_cb(const struct device *dev, struct smbus_callback *cb); @@ -668,12 +680,13 @@ static inline int z_impl_smbus_host_notify_set_cb(const struct device *dev, /** * @brief Remove Host Notify callback from a SMBus host controller. * - * @param dev Pointer to the device structure for the driver instance. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param cb Pointer to a callback structure. * * @retval 0 If successful. - * @retval -EIO General input / output error, failed to configure device. - * @retval -ENOSYS If get config is not implemented + * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_host_notify_remove_cb() is not implemented + * by the driver. */ __syscall int smbus_host_notify_remove_cb(const struct device *dev, struct smbus_callback *cb); @@ -697,14 +710,15 @@ static inline int z_impl_smbus_host_notify_remove_cb(const struct device *dev, * This routine provides a generic interface to perform SMBus Quick * operation. * - * @param dev Pointer to the device structure for an SMBus + * @param dev Pointer to the device structure for the SMBus driver instance. * driver configured in controller mode. * @param addr Address of the SMBus peripheral device. * @param direction Direction Read or Write. * * @retval 0 If successful. - * @retval -ENOSYS If not implemented by the driver. * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_quick() is not implemented + * by the driver. */ __syscall int smbus_quick(const struct device *dev, uint16_t addr, enum smbus_direction direction); @@ -732,14 +746,14 @@ static inline int z_impl_smbus_quick(const struct device *dev, uint16_t addr, * This routine provides a generic interface to perform SMBus * Byte Write operation. * - * @param dev Pointer to the device structure for an SMBus - * driver configured in controller mode. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param addr Address of the SMBus peripheral device. * @param byte Byte to be sent to the peripheral device. * * @retval 0 If successful. - * @retval -ENOSYS If not implemented by the driver. * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_byte_write() is not implemented + * by the driver. */ __syscall int smbus_byte_write(const struct device *dev, uint16_t addr, uint8_t byte); @@ -763,14 +777,14 @@ static inline int z_impl_smbus_byte_write(const struct device *dev, * This routine provides a generic interface to perform SMBus * Byte Read operation. * - * @param dev Pointer to the device structure for an SMBus - * driver configured in controller mode. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param addr Address of the SMBus peripheral device. * @param byte Byte received from the peripheral device. * * @retval 0 If successful. - * @retval -ENOSYS If not implemented by the driver. * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_byte_read() is not implemented + * by the driver. */ __syscall int smbus_byte_read(const struct device *dev, uint16_t addr, uint8_t *byte); @@ -794,15 +808,15 @@ static inline int z_impl_smbus_byte_read(const struct device *dev, * This routine provides a generic interface to perform SMBus * Byte Data Write operation. * - * @param dev Pointer to the device structure for an SMBus - * driver configured in controller mode. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param addr Address of the SMBus peripheral device. * @param cmd Command byte which is sent to peripheral device first. * @param byte Byte to be sent to the peripheral device. * * @retval 0 If successful. - * @retval -ENOSYS If not implemented by the driver. * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_byte_data_write() is not implemented + * by the driver. */ __syscall int smbus_byte_data_write(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t byte); @@ -821,28 +835,28 @@ static inline int z_impl_smbus_byte_data_write(const struct device *dev, return api->smbus_byte_data_write(dev, addr, cmd, byte); } -__syscall int smbus_byte_data_read(const struct device *dev, uint16_t addr, - uint8_t cmd, uint8_t *byte); - /** * @brief Perform SMBus Byte Data Read operation * * This routine provides a generic interface to perform SMBus * Byte Data Read operation. * - * @param dev Pointer to the device structure for an SMBus - * driver configured in controller mode. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param addr Address of the SMBus peripheral device. * @param cmd Command byte which is sent to peripheral device first. * @param byte Byte received from the peripheral device. * * @retval 0 If successful. - * @retval -ENOSYS If not implemented by the driver. * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_byte_data_read() is not implemented + * by the driver. */ +__syscall int smbus_byte_data_read(const struct device *dev, uint16_t addr, + uint8_t cmd, uint8_t *byte); + static inline int z_impl_smbus_byte_data_read(const struct device *dev, - uint16_t addr, uint8_t cmd, - uint8_t *byte) + uint16_t addr, uint8_t cmd, + uint8_t *byte) { const struct smbus_driver_api *api = (const struct smbus_driver_api *)dev->api; @@ -860,15 +874,15 @@ static inline int z_impl_smbus_byte_data_read(const struct device *dev, * This routine provides a generic interface to perform SMBus * Word Data Write operation. * - * @param dev Pointer to the device structure for an SMBus - * driver configured in controller mode. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param addr Address of the SMBus peripheral device. * @param cmd Command byte which is sent to peripheral device first. * @param word Word (16-bit) to be sent to the peripheral device. * * @retval 0 If successful. - * @retval -ENOSYS If not implemented by the driver. * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_word_data_write() is not implemented + * by the driver. */ __syscall int smbus_word_data_write(const struct device *dev, uint16_t addr, uint8_t cmd, uint16_t word); @@ -893,22 +907,22 @@ static inline int z_impl_smbus_word_data_write(const struct device *dev, * This routine provides a generic interface to perform SMBus * Word Data Read operation. * - * @param dev Pointer to the device structure for an SMBus - * driver configured in controller mode. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param addr Address of the SMBus peripheral device. * @param cmd Command byte which is sent to peripheral device first. * @param word Word (16-bit) received from the peripheral device. * * @retval 0 If successful. - * @retval -ENOSYS If not implemented by the driver. * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_word_data_read() is not implemented + * by the driver. */ __syscall int smbus_word_data_read(const struct device *dev, uint16_t addr, uint8_t cmd, uint16_t *word); static inline int z_impl_smbus_word_data_read(const struct device *dev, - uint16_t addr, uint8_t cmd, - uint16_t *word) + uint16_t addr, uint8_t cmd, + uint16_t *word) { const struct smbus_driver_api *api = (const struct smbus_driver_api *)dev->api; @@ -927,16 +941,16 @@ static inline int z_impl_smbus_word_data_read(const struct device *dev, * Process Call operation, which means Write 2 bytes following by * Read 2 bytes. * - * @param dev Pointer to the device structure for an SMBus - * driver configured in controller mode. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param addr Address of the SMBus peripheral device. * @param cmd Command byte which is sent to peripheral device first. * @param send_word Word (16-bit) to be sent to the peripheral device. * @param recv_word Word (16-bit) received from the peripheral device. * * @retval 0 If successful. - * @retval -ENOSYS If not implemented by the driver. * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_pcall() is not implemented + * by the driver. */ __syscall int smbus_pcall(const struct device *dev, uint16_t addr, uint8_t cmd, uint16_t send_word, uint16_t *recv_word); @@ -961,16 +975,16 @@ static inline int z_impl_smbus_pcall(const struct device *dev, * This routine provides a generic interface to perform SMBus * Block Write operation. * - * @param dev Pointer to the device structure for an SMBus - * driver configured in controller mode. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param addr Address of the SMBus peripheral device. * @param cmd Command byte which is sent to peripheral device first. * @param count Size of the data block buffer. Maximum 32 bytes. * @param buf Data block buffer to be sent to the peripheral device. * * @retval 0 If successful. - * @retval -ENOSYS If not implemented by the driver. * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_block_write() is not implemented + * by the driver. */ __syscall int smbus_block_write(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t count, uint8_t *buf); @@ -999,16 +1013,16 @@ static inline int z_impl_smbus_block_write(const struct device *dev, * This routine provides a generic interface to perform SMBus * Block Read operation. * - * @param dev Pointer to the device structure for an SMBus - * driver configured in controller mode. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param addr Address of the SMBus peripheral device. * @param cmd Command byte which is sent to peripheral device first. * @param count Size of the data peripheral sent. Maximum 32 bytes. * @param buf Data block buffer received from the peripheral device. * * @retval 0 If successful. - * @retval -ENOSYS If not implemented by the driver. * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_block_read() is not implemented + * by the driver. */ __syscall int smbus_block_read(const struct device *dev, uint16_t addr, uint8_t cmd, uint8_t *count, uint8_t *buf); @@ -1034,8 +1048,7 @@ static inline int z_impl_smbus_block_read(const struct device *dev, * Block Process Call operation. This operation is basically * Block Write followed by Block Read. * - * @param dev Pointer to the device structure for an SMBus - * driver configured in controller mode. + * @param dev Pointer to the device structure for the SMBus driver instance. * @param addr Address of the SMBus peripheral device. * @param cmd Command byte which is sent to peripheral device first. * @param snd_count Size of the data block buffer to send. @@ -1044,8 +1057,9 @@ static inline int z_impl_smbus_block_read(const struct device *dev, * @param rcv_buf Data block buffer received from the peripheral device. * * @retval 0 If successful. - * @retval -ENOSYS If not implemented by the driver. * @retval -EIO General input / output error. + * @retval -ENOSYS If function smbus_block_pcall() is not implemented + * by the driver. */ __syscall int smbus_block_pcall(const struct device *dev, uint16_t addr, uint8_t cmd, From fd078b6746af423fb3d998b81da4ac1fffd41ffc Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Fri, 24 Mar 2023 13:37:51 +0200 Subject: [PATCH 0749/1906] samples: smbus: Remove qemu_x86_64 overlay Remove overlay added by mistake. SMBus EEPROM PR is not merged and the dts would be updated for qemu_x86_64 board's dts. Signed-off-by: Andrei Emeltchenko --- samples/drivers/smbus/qemu_x86_64.overlay | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 samples/drivers/smbus/qemu_x86_64.overlay diff --git a/samples/drivers/smbus/qemu_x86_64.overlay b/samples/drivers/smbus/qemu_x86_64.overlay deleted file mode 100644 index 408695b795f2..000000000000 --- a/samples/drivers/smbus/qemu_x86_64.overlay +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2022 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -&smbus0 { - eeprom2: smbus_eeprom@50 { - compatible = "jedec,smbus-eeprom"; - reg = <0x50>; - size = <0x100>; - - status = "okay"; - }; -}; From 12b863067c0eeb77cd86a015d3708b6a59a4339a Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Wed, 22 Mar 2023 19:31:16 +0000 Subject: [PATCH 0750/1906] bindings: test: add a test input device binding Add a vnd,input-device binding to be used for testing. Signed-off-by: Fabio Baltieri --- dts/bindings/test/vnd,input-device.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 dts/bindings/test/vnd,input-device.yaml diff --git a/dts/bindings/test/vnd,input-device.yaml b/dts/bindings/test/vnd,input-device.yaml new file mode 100644 index 000000000000..6cad4920352c --- /dev/null +++ b/dts/bindings/test/vnd,input-device.yaml @@ -0,0 +1,6 @@ +# Copyright 2023 Google LLC +# SPDX-License-Identifier: Apache-2.0 + +description: Test input device + +compatible: "vnd,input-device" From 5b36b4fa1609dbe19640e9225f5008caed704be0 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Wed, 1 Feb 2023 15:38:23 +0000 Subject: [PATCH 0751/1906] input: add a longpress device Add an input device to take input key events as an input and generates short press or long press devices as output. Signed-off-by: Fabio Baltieri --- .../input/zephyr,input-longpress.yaml | 68 +++++++++ subsys/input/CMakeLists.txt | 2 + subsys/input/Kconfig | 5 + subsys/input/input_longpress.c | 141 ++++++++++++++++++ 4 files changed, 216 insertions(+) create mode 100644 dts/bindings/input/zephyr,input-longpress.yaml create mode 100644 subsys/input/input_longpress.c diff --git a/dts/bindings/input/zephyr,input-longpress.yaml b/dts/bindings/input/zephyr,input-longpress.yaml new file mode 100644 index 000000000000..c69169026320 --- /dev/null +++ b/dts/bindings/input/zephyr,input-longpress.yaml @@ -0,0 +1,68 @@ +# Copyright 2023 Google LLC +# SPDX-License-Identifier: Apache-2.0 + +description: | + Input longpress pseudo-device + + Listens for key events as an input and produces key events as output + corresponding to short and long press. + + Can be optionally be associated to a specific device to listen for events + only from that device. Example configuration: + + longpress { + input = <&buttons>; + compatible = "zephyr,input-longpress"; + input-codes = , ; + short-codes = , ; + long-codes = , ; + long-delay-ms = <1000>; + }; + + Example output: + + input event: dev=buttons SYN type= 1 code= 11 value=1 # INPUT_KEY_0 press + # release before one second + input event: dev=buttons SYN type= 1 code= 11 value=0 # INPUT_KEY_0 release + input event: dev=longpress SYN type= 1 code= 30 value=1 # INPUT_KEY_A press + input event: dev=longpress SYN type= 1 code= 30 value=0 # INPUT_KEY_A release + + input event: dev=buttons SYN type= 1 code= 11 value=1 # INPUT_KEY_0 press + # hold for more than one second + input event: dev=longpress SYN type= 1 code= 45 value=1 # INPUT_KEY_A press + # wait for release + input event: dev=buttons SYN type= 1 code= 11 value=0 # INPUT_KEY_0 release + input event: dev=longpress SYN type= 1 code= 45 value=0 # INPUT_KEY_A release + +compatible: "zephyr,input-longpress" + +properties: + input: + type: phandle + description: | + Input device phandle, if not specified listen for input from all devices. + + input-codes: + type: array + required: true + description: | + Array of input event key codes (INPUT_KEY_* or INPUT_BTN_*). + + short-codes: + type: array + required: true + description: | + Array of key codes to be generated for short press (INPUT_KEY_* or + INPUT_BTN_*). + + long-codes: + type: array + required: true + description: | + Array of key codes to be generated for long press (INPUT_KEY_* or + INPUT_BTN_*). + + long-delay-ms: + type: int + required: true + description: Time delay to register a long press in milliseconds. diff --git a/subsys/input/CMakeLists.txt b/subsys/input/CMakeLists.txt index 6a5b1c4bc13b..593123774bba 100644 --- a/subsys/input/CMakeLists.txt +++ b/subsys/input/CMakeLists.txt @@ -3,3 +3,5 @@ zephyr_library() zephyr_library_sources(input.c) + +zephyr_library_sources_ifdef(CONFIG_INPUT_LONGPRESS input_longpress.c) diff --git a/subsys/input/Kconfig b/subsys/input/Kconfig index bad6f8ed043b..6282841759eb 100644 --- a/subsys/input/Kconfig +++ b/subsys/input/Kconfig @@ -67,4 +67,9 @@ config INPUT_THREAD_STACK_SIZE endif # INPUT_MODE_THREAD +config INPUT_LONGPRESS + bool "Input longpress" + default y + depends on DT_HAS_ZEPHYR_INPUT_LONGPRESS_ENABLED + endif # INPUT diff --git a/subsys/input/input_longpress.c b/subsys/input/input_longpress.c new file mode 100644 index 000000000000..1e216caa6aac --- /dev/null +++ b/subsys/input/input_longpress.c @@ -0,0 +1,141 @@ +/* + * Copyright 2023 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT zephyr_input_longpress + +#include +#include +#include + +#include +LOG_MODULE_REGISTER(input_longpress, CONFIG_INPUT_LOG_LEVEL); + +struct longpress_config { + const struct device *input_dev; + const uint16_t *input_codes; + const uint16_t *short_codes; + const uint16_t *long_codes; + uint32_t long_delays_ms; + uint8_t num_codes; +}; + +struct longpress_data_entry { + const struct device *dev; + struct k_work_delayable work; + uint8_t index; + bool long_fired; +}; + +struct longpress_data { + /* support data for every input code */ + struct longpress_data_entry *entries; +}; + +static void longpress_deferred(struct k_work *work) +{ + struct longpress_data_entry *entry = CONTAINER_OF( + work, struct longpress_data_entry, work); + const struct device *dev = entry->dev; + const struct longpress_config *cfg = dev->config; + uint16_t code; + + code = cfg->long_codes[entry->index]; + + input_report_key(dev, code, 1, true, K_FOREVER); + + entry->long_fired = true; +} + +static void longpress_cb(const struct device *dev, struct input_event *evt) +{ + const struct longpress_config *cfg = dev->config; + struct longpress_data *data = dev->data; + struct longpress_data_entry *entry; + int i; + + if (evt->type != INPUT_EV_KEY) { + return; + } + + for (i = 0; i < cfg->num_codes; i++) { + if (evt->code == cfg->input_codes[i]) { + break; + } + } + if (i == cfg->num_codes) { + LOG_DBG("ignored code %d", evt->code); + return; + } + + entry = &data->entries[i]; + + if (evt->value) { + entry->long_fired = false; + k_work_schedule(&entry->work, K_MSEC(cfg->long_delays_ms)); + } else { + k_work_cancel_delayable(&entry->work); + if (entry->long_fired) { + input_report_key(dev, cfg->long_codes[i], 0, true, K_FOREVER); + } else { + input_report_key(dev, cfg->short_codes[i], 1, true, K_FOREVER); + input_report_key(dev, cfg->short_codes[i], 0, true, K_FOREVER); + } + } +} + +static int longpress_init(const struct device *dev) +{ + const struct longpress_config *cfg = dev->config; + struct longpress_data *data = dev->data; + + if (cfg->input_dev && !device_is_ready(cfg->input_dev)) { + LOG_ERR("input device not ready"); + return -ENODEV; + } + + for (int i = 0; i < cfg->num_codes; i++) { + struct longpress_data_entry *entry = &data->entries[i]; + + entry->dev = dev; + entry->index = i; + k_work_init_delayable(&entry->work, longpress_deferred); + } + + return 0; +} + +#define INPUT_LONGPRESS_DEFINE(inst) \ + BUILD_ASSERT(DT_INST_PROP_LEN(inst, input_codes) == \ + DT_INST_PROP_LEN(inst, short_codes)); \ + BUILD_ASSERT(DT_INST_PROP_LEN(inst, input_codes) == \ + DT_INST_PROP_LEN(inst, long_codes)); \ + static void longpress_cb_##inst(struct input_event *evt) \ + { \ + longpress_cb(DEVICE_DT_INST_GET(inst), evt); \ + } \ + INPUT_LISTENER_CB_DEFINE(DEVICE_DT_GET_OR_NULL(DT_INST_PHANDLE(inst, input)), \ + longpress_cb_##inst); \ + static const uint16_t longpress_input_codes_##inst[] = DT_INST_PROP(inst, input_codes); \ + static const uint16_t longpress_short_codes_##inst[] = DT_INST_PROP(inst, short_codes); \ + static const uint16_t longpress_long_codes_##inst[] = DT_INST_PROP(inst, long_codes); \ + static const struct longpress_config longpress_config_##inst = { \ + .input_dev = DEVICE_DT_GET_OR_NULL(DT_INST_PHANDLE(inst, input)), \ + .input_codes = longpress_input_codes_##inst, \ + .short_codes = longpress_short_codes_##inst, \ + .long_codes = longpress_long_codes_##inst, \ + .num_codes = DT_INST_PROP_LEN(inst, input_codes), \ + .long_delays_ms = DT_INST_PROP(inst, long_delay_ms), \ + }; \ + static struct longpress_data_entry longpress_data_entries_##inst[DT_INST_PROP_LEN( \ + inst, input_codes)]; \ + static struct longpress_data longpress_data_##inst = { \ + .entries = longpress_data_entries_##inst, \ + }; \ + DEVICE_DT_INST_DEFINE(inst, longpress_init, NULL, \ + &longpress_data_##inst, &longpress_config_##inst, \ + APPLICATION, CONFIG_INPUT_INIT_PRIORITY, NULL); + +DT_INST_FOREACH_STATUS_OKAY(INPUT_LONGPRESS_DEFINE) From 8bd0e13fc7d66a95194a9f5caf87daf8b469a949 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Tue, 14 Mar 2023 19:38:30 +0000 Subject: [PATCH 0752/1906] test: input: add tests for input_longpress Add a testsuite for the input-longpress driver. Signed-off-by: Fabio Baltieri --- .../input/input_longpress/CMakeLists.txt | 9 ++ .../boards/native_posix.overlay | 22 +++++ .../boards/native_posix_64.overlay | 6 ++ tests/subsys/input/input_longpress/prj.conf | 6 ++ tests/subsys/input/input_longpress/src/main.c | 99 +++++++++++++++++++ .../input/input_longpress/testcase.yaml | 8 ++ 6 files changed, 150 insertions(+) create mode 100644 tests/subsys/input/input_longpress/CMakeLists.txt create mode 100644 tests/subsys/input/input_longpress/boards/native_posix.overlay create mode 100644 tests/subsys/input/input_longpress/boards/native_posix_64.overlay create mode 100644 tests/subsys/input/input_longpress/prj.conf create mode 100644 tests/subsys/input/input_longpress/src/main.c create mode 100644 tests/subsys/input/input_longpress/testcase.yaml diff --git a/tests/subsys/input/input_longpress/CMakeLists.txt b/tests/subsys/input/input_longpress/CMakeLists.txt new file mode 100644 index 000000000000..0babd606bc37 --- /dev/null +++ b/tests/subsys/input/input_longpress/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(input_longpress) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/subsys/input/input_longpress/boards/native_posix.overlay b/tests/subsys/input/input_longpress/boards/native_posix.overlay new file mode 100644 index 000000000000..92fd8ed2bc0d --- /dev/null +++ b/tests/subsys/input/input_longpress/boards/native_posix.overlay @@ -0,0 +1,22 @@ +/* + * Copyright 2023 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/ { + fake_input_device: fake-device { + compatible = "vnd,input-device"; + }; + + longpress: longpress { + input = <&fake_input_device>; + compatible = "zephyr,input-longpress"; + input-codes = , ; + short-codes = , ; + long-codes = , ; + long-delay-ms = <100>; + }; +}; diff --git a/tests/subsys/input/input_longpress/boards/native_posix_64.overlay b/tests/subsys/input/input_longpress/boards/native_posix_64.overlay new file mode 100644 index 000000000000..166e6f02e82d --- /dev/null +++ b/tests/subsys/input/input_longpress/boards/native_posix_64.overlay @@ -0,0 +1,6 @@ +/* + * Copyright 2023 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "native_posix.overlay" diff --git a/tests/subsys/input/input_longpress/prj.conf b/tests/subsys/input/input_longpress/prj.conf new file mode 100644 index 000000000000..b101f410c698 --- /dev/null +++ b/tests/subsys/input/input_longpress/prj.conf @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_INPUT=y +CONFIG_INPUT_MODE_SYNCHRONOUS=y diff --git a/tests/subsys/input/input_longpress/src/main.c b/tests/subsys/input/input_longpress/src/main.c new file mode 100644 index 000000000000..b1714bf976da --- /dev/null +++ b/tests/subsys/input/input_longpress/src/main.c @@ -0,0 +1,99 @@ +/* + * Copyright 2023 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +static const struct device *const fake_dev = DEVICE_DT_GET( + DT_NODELABEL(fake_input_device)); +static const struct device *const longpress_dev = DEVICE_DT_GET( + DT_NODELABEL(longpress)); + +static int device_init(const struct device *dev) +{ + return 0; +} + +DEVICE_DT_DEFINE(DT_INST(0, vnd_input_device), device_init, NULL, NULL, NULL, + PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, NULL); + +static int event_count; +static struct input_event last_events[2]; + +static void test_cb(struct input_event *evt) +{ + TC_PRINT("%s: %d %x %d\n", __func__, event_count, evt->code, evt->value); + + event_count++; + memcpy(&last_events[1], &last_events[0], sizeof(struct input_event)); + memcpy(&last_events[0], evt, sizeof(struct input_event)); +} +INPUT_LISTENER_CB_DEFINE(longpress_dev, test_cb); + +ZTEST(longpress, test_longpress_test) +{ + zassert_equal(event_count, 0); + + /* ignored */ + input_report_key(fake_dev, INPUT_KEY_3, 1, true, K_FOREVER); + input_report_key(fake_dev, INPUT_KEY_3, 0, true, K_FOREVER); + zassert_equal(event_count, 0); + input_report_abs(fake_dev, INPUT_KEY_0, 1, true, K_FOREVER); + input_report_abs(fake_dev, INPUT_KEY_0, 0, true, K_FOREVER); + zassert_equal(event_count, 0); + + /* short press */ + input_report_key(fake_dev, INPUT_KEY_0, 1, true, K_FOREVER); + k_sleep(K_MSEC(50)); + input_report_key(fake_dev, INPUT_KEY_0, 0, true, K_FOREVER); + zassert_equal(event_count, 2); + zassert_equal(last_events[1].type, INPUT_EV_KEY); + zassert_equal(last_events[1].code, INPUT_KEY_A); + zassert_equal(last_events[1].value, 1); + zassert_equal(last_events[0].type, INPUT_EV_KEY); + zassert_equal(last_events[0].code, INPUT_KEY_A); + zassert_equal(last_events[0].value, 0); + + /* short press - other key */ + input_report_key(fake_dev, INPUT_KEY_1, 1, true, K_FOREVER); + k_sleep(K_MSEC(50)); + input_report_key(fake_dev, INPUT_KEY_1, 0, true, K_FOREVER); + zassert_equal(event_count, 4); + zassert_equal(last_events[1].type, INPUT_EV_KEY); + zassert_equal(last_events[1].code, INPUT_KEY_B); + zassert_equal(last_events[1].value, 1); + zassert_equal(last_events[0].type, INPUT_EV_KEY); + zassert_equal(last_events[0].code, INPUT_KEY_B); + zassert_equal(last_events[0].value, 0); + + /* long press */ + input_report_key(fake_dev, INPUT_KEY_0, 1, true, K_FOREVER); + k_sleep(K_MSEC(150)); + input_report_key(fake_dev, INPUT_KEY_0, 0, true, K_FOREVER); + zassert_equal(event_count, 6); + zassert_equal(last_events[1].type, INPUT_EV_KEY); + zassert_equal(last_events[1].code, INPUT_KEY_X); + zassert_equal(last_events[1].value, 1); + zassert_equal(last_events[0].type, INPUT_EV_KEY); + zassert_equal(last_events[0].code, INPUT_KEY_X); + zassert_equal(last_events[0].value, 0); + + /* long press - other key */ + input_report_key(fake_dev, INPUT_KEY_1, 1, true, K_FOREVER); + k_sleep(K_MSEC(150)); + input_report_key(fake_dev, INPUT_KEY_1, 0, true, K_FOREVER); + zassert_equal(event_count, 8); + zassert_equal(last_events[1].type, INPUT_EV_KEY); + zassert_equal(last_events[1].code, INPUT_KEY_Y); + zassert_equal(last_events[1].value, 1); + zassert_equal(last_events[0].type, INPUT_EV_KEY); + zassert_equal(last_events[0].code, INPUT_KEY_Y); + zassert_equal(last_events[0].value, 0); +} + +ZTEST_SUITE(longpress, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/subsys/input/input_longpress/testcase.yaml b/tests/subsys/input/input_longpress/testcase.yaml new file mode 100644 index 000000000000..fcb0369168a7 --- /dev/null +++ b/tests/subsys/input/input_longpress/testcase.yaml @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +tests: + input.input_longpress: + platform_allow: native_posix native_posix_64 + tags: drivers input + integration_platforms: + - native_posix From 6b8bc83f543675f5bfb1648a1d1c7d20d0c47116 Mon Sep 17 00:00:00 2001 From: scott worley Date: Fri, 24 Mar 2023 07:22:55 -0400 Subject: [PATCH 0753/1906] tests: adc: Microchip XEC fix ADC API test and ADC shell Microchip XEC ADC and ADC V2 driver were merged into one That PR did not change the ADC API test and ADC shell resulting in twister build failures. Fixed both ADC API test and ADC shell. Signed-off-by: scott worley --- drivers/adc/adc_shell.c | 2 -- tests/drivers/adc/adc_api/src/test_adc.c | 12 ++---------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/adc/adc_shell.c b/drivers/adc/adc_shell.c index 31f8c05f3782..ea9c48d28e56 100644 --- a/drivers/adc/adc_shell.c +++ b/drivers/adc/adc_shell.c @@ -23,8 +23,6 @@ #define DT_DRV_COMPAT ite_it8xxx2_adc #elif DT_HAS_COMPAT_STATUS_OKAY(microchip_xec_adc) #define DT_DRV_COMPAT microchip_xec_adc -#elif DT_HAS_COMPAT_STATUS_OKAY(microchip_xec_adc_v2) -#define DT_DRV_COMPAT microchip_xec_adc_v2 #elif DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_adc) #define DT_DRV_COMPAT nordic_nrf_adc #elif DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_saadc) diff --git a/tests/drivers/adc/adc_api/src/test_adc.c b/tests/drivers/adc/adc_api/src/test_adc.c index d6f383b1400d..83d50ab8e2d1 100644 --- a/tests/drivers/adc/adc_api/src/test_adc.c +++ b/tests/drivers/adc/adc_api/src/test_adc.c @@ -310,7 +310,8 @@ #define ADC_2ND_CHANNEL_ID 1 #elif defined(CONFIG_BOARD_MEC15XXEVB_ASSY6853) || \ - defined(CONFIG_BOARD_MEC1501MODULAR_ASSY6885) + defined(CONFIG_BOARD_MEC1501MODULAR_ASSY6885) || \ + defined(CONFIG_BOARD_MEC172XEVB_ASSY6906) #define ADC_DEVICE_NODE DT_INST(0, microchip_xec_adc) #define ADC_RESOLUTION 12 #define ADC_GAIN ADC_GAIN_1 @@ -319,15 +320,6 @@ #define ADC_1ST_CHANNEL_ID 4 #define ADC_2ND_CHANNEL_ID 5 -#elif defined(CONFIG_BOARD_MEC172XEVB_ASSY6906) -#define ADC_DEVICE_NODE DT_INST(0, microchip_xec_adc_v2) -#define ADC_RESOLUTION 12 -#define ADC_GAIN ADC_GAIN_1 -#define ADC_REFERENCE ADC_REF_INTERNAL -#define ADC_ACQUISITION_TIME ADC_ACQ_TIME_DEFAULT -#define ADC_1ST_CHANNEL_ID 4 -#define ADC_2ND_CHANNEL_ID 5 - #elif defined(CONFIG_BOARD_LPCXPRESSO55S69_CPU0) || \ defined(CONFIG_BOARD_LPCXPRESSO55S28) || \ defined(CONFIG_BOARD_MIMXRT1170_EVK_CM7) || \ From dd5e476f86ec40a2da20c78419433b4d5bc790a5 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Sat, 17 Dec 2022 16:42:13 +0100 Subject: [PATCH 0754/1906] Bluetooth: Audio: Shell: Add CAP Acceptor Set Member AD data Add automatic adding of the CAP Acceptor Set Member AD data. This also moves the CAP Acceptor service data into the cap_acceptor.c shell implementation. Signed-off-by: Emil Gydesen --- subsys/bluetooth/audio/shell/CMakeLists.txt | 2 +- subsys/bluetooth/audio/shell/audio.h | 1 + subsys/bluetooth/audio/shell/bap.c | 12 +--- subsys/bluetooth/audio/shell/cap_acceptor.c | 68 +++++++++++++++++++++ 4 files changed, 72 insertions(+), 11 deletions(-) diff --git a/subsys/bluetooth/audio/shell/CMakeLists.txt b/subsys/bluetooth/audio/shell/CMakeLists.txt index 47e90c5b79be..43b4cd879505 100644 --- a/subsys/bluetooth/audio/shell/CMakeLists.txt +++ b/subsys/bluetooth/audio/shell/CMakeLists.txt @@ -52,7 +52,7 @@ zephyr_library_sources_ifdef( has.c ) zephyr_library_sources_ifdef( - CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER + CONFIG_BT_CAP_ACCEPTOR cap_acceptor.c ) zephyr_library_sources_ifdef( diff --git a/subsys/bluetooth/audio/shell/audio.h b/subsys/bluetooth/audio/shell/audio.h index 1776812637d5..233c6204a5bf 100644 --- a/subsys/bluetooth/audio/shell/audio.h +++ b/subsys/bluetooth/audio/shell/audio.h @@ -21,5 +21,6 @@ ssize_t audio_ad_data_add(struct bt_data *data, const size_t data_size, const bo const bool connectable); ssize_t audio_pa_data_add(struct bt_data *data_array, const size_t data_array_size); ssize_t csis_ad_data_add(struct bt_data *data, const size_t data_size, const bool discoverable); +size_t cap_acceptor_ad_data_add(struct bt_data data[], size_t data_size, bool discoverable); #endif /* __AUDIO_H */ diff --git a/subsys/bluetooth/audio/shell/bap.c b/subsys/bluetooth/audio/shell/bap.c index 038f9a7fab4c..739291b962ea 100644 --- a/subsys/bluetooth/audio/shell/bap.c +++ b/subsys/bluetooth/audio/shell/bap.c @@ -27,6 +27,7 @@ #include #include "shell/bt.h" +#include "audio.h" #define LOCATION BT_AUDIO_LOCATION_FRONT_LEFT #define CONTEXT BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA @@ -2620,16 +2621,7 @@ static ssize_t connectable_ad_data_add(struct bt_data *data_array, } if (IS_ENABLED(CONFIG_BT_CAP_ACCEPTOR)) { - static const uint8_t ad_cap_announcement[3] = { - BT_UUID_16_ENCODE(BT_UUID_CAS_VAL), - BT_AUDIO_UNICAST_ANNOUNCEMENT_TARGETED, - }; - - __ASSERT(data_array_size > ad_len, "No space for AD_CAP_ANNOUNCEMENT"); - data_array[ad_len].type = BT_DATA_SVC_DATA16; - data_array[ad_len].data_len = ARRAY_SIZE(ad_cap_announcement); - data_array[ad_len].data = &ad_cap_announcement[0]; - ad_len++; + ad_len += cap_acceptor_ad_data_add(data_array, data_array_size - ad_len, true); } if (ARRAY_SIZE(ad_ext_uuid16) > 0) { diff --git a/subsys/bluetooth/audio/shell/cap_acceptor.c b/subsys/bluetooth/audio/shell/cap_acceptor.c index 63e5b1c791ec..fd4c5ba66932 100644 --- a/subsys/bluetooth/audio/shell/cap_acceptor.c +++ b/subsys/bluetooth/audio/shell/cap_acceptor.c @@ -15,6 +15,22 @@ #include #include "shell/bt.h" +static size_t ad_cap_announcement_data_add(struct bt_data data[], size_t data_size) +{ + static const uint8_t ad_cap_announcement[3] = { + BT_UUID_16_ENCODE(BT_UUID_CAS_VAL), + BT_AUDIO_UNICAST_ANNOUNCEMENT_TARGETED, + }; + + __ASSERT(data_size > 0, "No space for AD_CAP_ANNOUNCEMENT"); + data[0].type = BT_DATA_SVC_DATA16; + data[0].data_len = ARRAY_SIZE(ad_cap_announcement); + data[0].data = &ad_cap_announcement[0]; + + return 1U; +} + +#if defined(CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER) extern const struct shell *ctx_shell; static struct bt_csip_set_member_svc_inst *cap_csip_svc_inst; static uint8_t sirk_read_rsp = BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT; @@ -261,3 +277,55 @@ SHELL_STATIC_SUBCMD_SET_CREATE(cap_acceptor_cmds, SHELL_CMD_ARG_REGISTER(cap_acceptor, &cap_acceptor_cmds, "Bluetooth CAP acceptor shell commands", cmd_cap_acceptor, 1, 1); + +size_t cap_acceptor_ad_data_add(struct bt_data data[], size_t data_size, bool discoverable) +{ + size_t ad_len = 0; + + if (!discoverable) { + return ad_len; + } + + if (IS_ENABLED(CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER) && cap_csip_svc_inst != NULL) { + static uint8_t ad_rsi[BT_CSIP_RSI_SIZE]; + int err; + + ad_len += ad_cap_announcement_data_add(data, data_size); + + /* A privacy-enabled Set Member should only advertise RSI values derived + * from a SIRK that is exposed in encrypted form. + */ + if (IS_ENABLED(CONFIG_BT_PRIVACY) && + !IS_ENABLED(CONFIG_BT_CSIP_SET_MEMBER_ENC_SIRK_SUPPORT)) { + shell_warn(ctx_shell, "RSI derived from unencrypted SIRK"); + } + + err = bt_csip_set_member_generate_rsi(cap_csip_svc_inst, ad_rsi); + if (err != 0) { + shell_error(ctx_shell, "Failed to generate RSI (err %d)", err); + + return err; + } + + __ASSERT(data_size > ad_len, "No space for AD_RSI"); + data[ad_len].type = BT_DATA_CSIS_RSI; + data[ad_len].data_len = ARRAY_SIZE(ad_rsi); + data[ad_len].data = &ad_rsi[0]; + ad_len++; + } + + return ad_len; +} + +#else /* !CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER */ + +size_t cap_acceptor_ad_data_add(struct bt_data data[], size_t data_size, bool discoverable) +{ + if (!discoverable) { + return 0U; + } + + return ad_cap_announcement_data_add(data, data_size); +} + +#endif /* CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER */ From eb62e974dc92ae74c9468136aea28ad2057ab1c4 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Mon, 23 Jan 2023 15:11:31 +0100 Subject: [PATCH 0755/1906] Samples: Bluetooth: Fix unicast client ASCS discovery The unicast client used the BT_DATA_UUID16_SOME and BT_DATA_UUID16_ALL instead BT_DATA_SVC_DATA16 for discovering ASCS servers. BT_DATA_SVC_DATA16 is the right one to use, as that is mandatory for a server to advertise, and the UUID ones are only recommended. Furthermore, the service data of the ASCS server can now also be retrieved. Signed-off-by: Emil Gydesen --- .../bluetooth/unicast_audio_client/src/main.c | 80 +++++++++++-------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/samples/bluetooth/unicast_audio_client/src/main.c b/samples/bluetooth/unicast_audio_client/src/main.c index e23ed6343382..1892e77abb31 100644 --- a/samples/bluetooth/unicast_audio_client/src/main.c +++ b/samples/bluetooth/unicast_audio_client/src/main.c @@ -366,51 +366,65 @@ static void print_codec_capabilities(const struct bt_codec *codec) static bool check_audio_support_and_connect(struct bt_data *data, void *user_data) { + struct net_buf_simple ascs_svc_data; bt_addr_le_t *addr = user_data; - int i; + uint8_t announcement_type; + uint32_t audio_contexts; + struct bt_uuid *uuid; + uint16_t uuid_val; + uint8_t meta_len; + size_t min_size; + int err; printk("[AD]: %u data_len %u\n", data->type, data->data_len); - switch (data->type) { - case BT_DATA_UUID16_SOME: - case BT_DATA_UUID16_ALL: - if (data->data_len % sizeof(uint16_t) != 0U) { - printk("AD malformed\n"); - return true; /* Continue */ - } + if (data->type != BT_DATA_SVC_DATA16) { + return true; /* Continue parsing to next AD data type */ + } + + if (data->data_len < sizeof(uuid_val)) { + printk("AD invalid size %u\n", data->data_len); + return true; /* Continue parsing to next AD data type */ + } - for (i = 0; i < data->data_len; i += sizeof(uint16_t)) { - struct bt_uuid *uuid; - uint16_t uuid_val; - int err; + net_buf_simple_init_with_data(&ascs_svc_data, (void *)data->data, + data->data_len); - memcpy(&uuid_val, &data->data[i], sizeof(uuid_val)); - uuid = BT_UUID_DECLARE_16(sys_le16_to_cpu(uuid_val)); - if (bt_uuid_cmp(uuid, BT_UUID_ASCS) != 0) { - continue; - } + uuid_val = net_buf_simple_pull_le16(&ascs_svc_data); + uuid = BT_UUID_DECLARE_16(sys_le16_to_cpu(uuid_val)); + if (bt_uuid_cmp(uuid, BT_UUID_ASCS) != 0) { + /* We are looking for the ASCS service data */ + return true; /* Continue parsing to next AD data type */ + } - err = bt_le_scan_stop(); - if (err != 0) { - printk("Failed to stop scan: %d\n", err); - return false; - } + min_size = sizeof(announcement_type) + sizeof(audio_contexts) + sizeof(meta_len); + if (ascs_svc_data.len < min_size) { + printk("AD invalid size %u\n", data->data_len); + return false; /* Stop parsing */ + } - printk("Audio server found; connecting\n"); + announcement_type = net_buf_simple_pull_u8(&ascs_svc_data); + audio_contexts = net_buf_simple_pull_le32(&ascs_svc_data); + meta_len = net_buf_simple_pull_u8(&ascs_svc_data); - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, - &default_conn); - if (err != 0) { - printk("Create conn to failed (%u)\n", err); - start_scan(); - } + err = bt_le_scan_stop(); + if (err != 0) { + printk("Failed to stop scan: %d\n", err); + return false; /* Stop parsing */ + } - return false; /* Stop parsing */ - } + printk("Audio server found with type %u, contexts 0x%08x and meta_len %u; connecting\n", + announcement_type, audio_contexts, meta_len); + + err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, + BT_LE_CONN_PARAM_DEFAULT, + &default_conn); + if (err != 0) { + printk("Create conn to failed (%u)\n", err); + start_scan(); } - return true; + return false; /* Stop parsing */ } static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, From c26d6931c1e21253870e5571d957eb75b6da145f Mon Sep 17 00:00:00 2001 From: Kevin Townsend Date: Thu, 23 Mar 2023 16:44:43 +0100 Subject: [PATCH 0756/1906] manifest: trusted-firmware-m: Add OTP flash fixes Updates TF-M to include various fixes for OTP flash memory handling. Signed-off-by: Kevin Townsend --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index cb97e04c48d7..b0bea8a00b0c 100644 --- a/west.yml +++ b/west.yml @@ -231,7 +231,7 @@ manifest: groups: - debug - name: trusted-firmware-m - revision: 60fbdb43fb371d811a7d5d88709cb06fa92b7b68 + revision: 2d4edabafd9d59f37b16d7fe38f5f7ebab8495a4 path: modules/tee/tf-m/trusted-firmware-m groups: - tee From ae5b424a2bcf33e0513591b4edd738f1962267db Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 22 Mar 2023 20:32:21 +0530 Subject: [PATCH 0757/1906] Bluetooth: Host: Fix handling of incomplete data status adv reports When receiving extended advertising reports with incomplete data status, it is not necessary to mark for recovering from currently assembled fragments, but rather drop them and start a fresh assembly of subsequently received extended advertising reports. Timing changes in the Controller cause Periodic Advertising PDUs AUX_SYNC_IND + AUX_CHAIN_IND to be placed between primary channel ADV_EXT_IND and AUX_ADV_IND. This causes the Controller to generate alternating incomplete and complete data status reports, exposing the Host bug that is fixed in this commit. Relates to commit ba09a252ecd8 ("bluetooth: host: refactor bt_hci_le_per_adv_report data reassembly"). Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/host/scan.c | 1 - 1 file changed, 1 deletion(-) diff --git a/subsys/bluetooth/host/scan.c b/subsys/bluetooth/host/scan.c index e074895a6343..70955ce78288 100644 --- a/subsys/bluetooth/host/scan.c +++ b/subsys/bluetooth/host/scan.c @@ -831,7 +831,6 @@ void bt_hci_le_per_adv_report(struct net_buf *buf) LOG_DBG("Received incomplete advertising data. " "Advertising report dropped."); - per_adv_sync->report_truncated = true; net_buf_simple_reset(&per_adv_sync->reassembly); } else if (evt->data_status == BT_HCI_LE_ADV_EVT_TYPE_DATA_STATUS_PARTIAL) { From b208fc52c7c10140aec106b8b41705de4a7bae8c Mon Sep 17 00:00:00 2001 From: Hein Wessels Date: Fri, 24 Mar 2023 09:37:00 +0100 Subject: [PATCH 0758/1906] tests: drivers: dma: stm32h7: use auto generated linker section Change this test to use the automatically generated linker section to place the buffer in SRAM4, instead of using the manually created region added in 088d38f. This is in preperation of removing the manually created section. Signed-off-by: Hein Wessels --- tests/drivers/dma/chan_blen_transfer/boards/nucleo_h743zi.conf | 2 +- tests/drivers/dma/loop_transfer/boards/nucleo_h743zi.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/drivers/dma/chan_blen_transfer/boards/nucleo_h743zi.conf b/tests/drivers/dma/chan_blen_transfer/boards/nucleo_h743zi.conf index a04f2512f1d4..9baa0e8a2fcb 100644 --- a/tests/drivers/dma/chan_blen_transfer/boards/nucleo_h743zi.conf +++ b/tests/drivers/dma/chan_blen_transfer/boards/nucleo_h743zi.conf @@ -5,7 +5,7 @@ CONFIG_DMA_LOOP_TRANSFER_NUMBER_OF_DMAS=2 # Required by BDMA which only has access to # a NOCACHE SRAM4 section. All other DMAs also # has access to this section. -CONFIG_DMA_LOOP_TRANSFER_SRAM_SECTION=".sram4" +CONFIG_DMA_LOOP_TRANSFER_SRAM_SECTION="SRAM4.dma" # Required for SRAM4 to be non-cachable CONFIG_NOCACHE_MEMORY=y diff --git a/tests/drivers/dma/loop_transfer/boards/nucleo_h743zi.conf b/tests/drivers/dma/loop_transfer/boards/nucleo_h743zi.conf index c665fccc9530..6d04df24ec15 100644 --- a/tests/drivers/dma/loop_transfer/boards/nucleo_h743zi.conf +++ b/tests/drivers/dma/loop_transfer/boards/nucleo_h743zi.conf @@ -4,7 +4,7 @@ CONFIG_DMA_LOOP_TRANSFER_NUMBER_OF_DMAS=2 # Required by BDMA which only has access to # a NOCACHE SRAM4 section. All other DMAs also # has access to this section. -CONFIG_DMA_LOOP_TRANSFER_SRAM_SECTION=".sram4" +CONFIG_DMA_LOOP_TRANSFER_SRAM_SECTION="SRAM4.dma" # Required for SRAM4 to be non-cachable CONFIG_NOCACHE_MEMORY=y From 641722afabb3eba8fea7df5629c138d971359965 Mon Sep 17 00:00:00 2001 From: Hein Wessels Date: Fri, 24 Mar 2023 09:38:23 +0100 Subject: [PATCH 0759/1906] tests: drivers: adc_dma: stm32h7: use auto generated linker section Change this test to use the automatically generated linker section to place the buffer in SRAM4, instead of using the manually created region added in 088d38f. This is in preperation of removing the manually created section. Signed-off-by: Hein Wessels --- tests/drivers/adc/adc_dma/src/test_adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/drivers/adc/adc_dma/src/test_adc.c b/tests/drivers/adc/adc_dma/src/test_adc.c index 04bf27bd4bfd..22cf30593c20 100644 --- a/tests/drivers/adc/adc_dma/src/test_adc.c +++ b/tests/drivers/adc/adc_dma/src/test_adc.c @@ -48,7 +48,7 @@ #define ADC_1ST_CHANNEL_ID 1 #define ADC_2ND_CHANNEL_ID 7 #define ALIGNMENT 32 -#define BUFFER_MEM_REGION __attribute__((__section__(".sram4"))) +#define BUFFER_MEM_REGION __attribute__((__section__("SRAM4.dma"))) #endif From 68b9be8381ff462b162342aeb4b08700942f682f Mon Sep 17 00:00:00 2001 From: Hein Wessels Date: Fri, 24 Mar 2023 09:38:58 +0100 Subject: [PATCH 0760/1906] soc: arm: stm32h7: remove manual linker section Remove the manually created linker section, because it's already automatically generated for all sram regions in the DTS with the "zephyr,memory-region" compatibility. Signed-off-by: Hein Wessels --- soc/arm/st_stm32/stm32h7/sections.ld | 9 --------- 1 file changed, 9 deletions(-) diff --git a/soc/arm/st_stm32/stm32h7/sections.ld b/soc/arm/st_stm32/stm32h7/sections.ld index d99f87c11dac..5f4fd794dd2a 100644 --- a/soc/arm/st_stm32/stm32h7/sections.ld +++ b/soc/arm/st_stm32/stm32h7/sections.ld @@ -25,12 +25,3 @@ SECTION_DATA_PROLOGUE(eth_stm32,(NOLOAD),) } GROUP_DATA_LINK_IN(LINKER_DT_NODE_REGION_NAME(DT_NODELABEL(sram2)), LINKER_DT_NODE_REGION_NAME(DT_NODELABEL(sram2))) #endif #endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(sram4), okay) -SECTION_PROLOGUE (sram4, ABSOLUTE(DT_REG_ADDR(DT_NODELABEL(sram4))) (NOLOAD),) -{ - __sram4_start = .; - KEEP(*(SORT_BY_NAME(".sram4*"))) - __sram4_end = .; -} GROUP_DATA_LINK_IN(SRAM4, SRAM4) -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(sram4), okay) */ From fc8560fc85b31397288a9dcc61dc49b546108eb5 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 24 Mar 2023 12:21:45 +0100 Subject: [PATCH 0761/1906] Bluetooth: tester: Fix not updating value length on write Previously tests were passing only because initial value in database and PTS value used for testing had same length. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp_gatt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/bluetooth/tester/src/btp_gatt.c b/tests/bluetooth/tester/src/btp_gatt.c index 0bdf8361b0f2..4d5e412f7a25 100644 --- a/tests/bluetooth/tester/src/btp_gatt.c +++ b/tests/bluetooth/tester/src/btp_gatt.c @@ -411,6 +411,7 @@ static ssize_t write_value(struct bt_conn *conn, } memcpy(value->data + offset, buf, len); + value->len = len; /* Maximum attribute value size is 512 bytes */ __ASSERT_NO_MSG(value->len < 512); From 0b6bfbd9ea394596922e18f3d9ce457c131f7f03 Mon Sep 17 00:00:00 2001 From: Bartosz Bilas Date: Thu, 23 Mar 2023 12:29:58 +0100 Subject: [PATCH 0762/1906] gpio: add gpio_add/remove callback dt functions Add `gpio_add_callback_dt` and `gpio_remove_callback_dt` functions that allow the user to pass `gpio_dt_spec` directly. Signed-off-by: Bartosz Bilas --- include/zephyr/drivers/gpio.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/zephyr/drivers/gpio.h b/include/zephyr/drivers/gpio.h index d9b7a685ab39..d73e20c8aa61 100644 --- a/include/zephyr/drivers/gpio.h +++ b/include/zephyr/drivers/gpio.h @@ -1444,6 +1444,23 @@ static inline int gpio_add_callback(const struct device *port, return api->manage_callback(port, callback, true); } +/** + * @brief Add an application callback. + * + * This is equivalent to: + * + * gpio_add_callback(spec->port, callback); + * + * @param spec GPIO specification from devicetree. + * @param callback A valid application's callback structure pointer. + * @return a value from gpio_add_callback(). + */ +static inline int gpio_add_callback_dt(const struct gpio_dt_spec *spec, + struct gpio_callback *callback) +{ + return gpio_add_callback(spec->port, callback); +} + /** * @brief Remove an application callback. * @param port Pointer to the device structure for the driver instance. @@ -1473,6 +1490,23 @@ static inline int gpio_remove_callback(const struct device *port, return api->manage_callback(port, callback, false); } +/** + * @brief Remove an application callback. + * + * This is equivalent to: + * + * gpio_remove_callback(spec->port, callback); + * + * @param spec GPIO specification from devicetree. + * @param callback A valid application's callback structure pointer. + * @return a value from gpio_remove_callback(). + */ +static inline int gpio_remove_callback_dt(const struct gpio_dt_spec *spec, + struct gpio_callback *callback) +{ + return gpio_remove_callback(spec->port, callback); +} + /** * @brief Function to get pending interrupts * From bcc0a3b9aa4f3aa3792cfae2382604fa94cc841d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Tue, 14 Feb 2023 09:24:38 -0800 Subject: [PATCH 0763/1906] scripts: add list_devicetree_bindings_changes.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This automates much of the drudgery of enumerating changes to devicetree bindings at release time. Some customizations and release-specific tweaks to the script will probably always be needed, but it's a good starting point. Signed-off-by: Martí Bolívar --- .../list_devicetree_bindings_changes.py | 531 ++++++++++++++++++ 1 file changed, 531 insertions(+) create mode 100755 scripts/release/list_devicetree_bindings_changes.py diff --git a/scripts/release/list_devicetree_bindings_changes.py b/scripts/release/list_devicetree_bindings_changes.py new file mode 100755 index 000000000000..c28c0e640b24 --- /dev/null +++ b/scripts/release/list_devicetree_bindings_changes.py @@ -0,0 +1,531 @@ +#!/usr/bin/env python3 + +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +from collections import defaultdict +from dataclasses import dataclass +from pathlib import Path +from typing import Any, Callable, Dict, List, Optional, Set, Union +import argparse +import contextlib +import glob +import os +import subprocess +import sys +import tempfile + +# TODO: include changes to child bindings + +HERE = Path(__file__).parent.resolve() +ZEPHYR_BASE = HERE.parent.parent +SCRIPTS = ZEPHYR_BASE / 'scripts' + +sys.path.insert(0, str(SCRIPTS / 'dts' / 'python-devicetree' / 'src')) + +from devicetree.edtlib import Binding, bindings_from_paths, load_vendor_prefixes_txt + +# The Compat type is a (compatible, on_bus) pair, which is used as a +# lookup key for bindings. The name "compat" matches edtlib's internal +# variable for this; it's a bit of a misnomer, but let's be +# consistent. +@dataclass +class Compat: + compatible: str + on_bus: Optional[str] + + def __hash__(self): + return hash((self.compatible, self.on_bus)) + +class BindingChange: + '''Marker type for an individual change that happened to a + binding between the start and end commits. See subclasses + below for concrete changes. + ''' + +Compat2Binding = Dict[Compat, Binding] +Binding2Changes = Dict[Binding, List[BindingChange]] + +@dataclass +class Changes: + '''Container for all the changes that happened between the + start and end commits.''' + + vnds: List[str] + vnd2added: Dict[str, Compat2Binding] + vnd2removed: Dict[str, Compat2Binding] + vnd2changes: Dict[str, Binding2Changes] + +@dataclass +class ModifiedSpecifier2Cells(BindingChange): + space: str + start: List[str] + end: List[str] + +@dataclass +class ModifiedBuses(BindingChange): + start: List[str] + end: List[str] + +@dataclass +class AddedProperty(BindingChange): + property: str + +@dataclass +class RemovedProperty(BindingChange): + property: str + +@dataclass +class ModifiedPropertyType(BindingChange): + property: str + start: str + end: str + +@dataclass +class ModifiedPropertyEnum(BindingChange): + property: str + start: Any + end: Any + +@dataclass +class ModifiedPropertyConst(BindingChange): + property: str + start: Any + end: Any + +@dataclass +class ModifiedPropertyDefault(BindingChange): + property: str + start: Any + end: Any + +@dataclass +class ModifiedPropertyDeprecated(BindingChange): + property: str + start: bool + end: bool + +@dataclass +class ModifiedPropertyRequired(BindingChange): + property: str + start: bool + end: bool + +def get_changes_between( + compat2binding_start: Compat2Binding, + compat2binding_end: Compat2Binding +) -> Changes: + vnd2added: Dict[str, Compat2Binding] = \ + group_compat2binding_by_vnd({ + compat: compat2binding_end[compat] + for compat in compat2binding_end + if compat not in compat2binding_start + }) + + vnd2removed: Dict[str, Compat2Binding] = \ + group_compat2binding_by_vnd({ + compat: compat2binding_start[compat] + for compat in compat2binding_start + if compat not in compat2binding_end + }) + + vnd2changes = group_binding2changes_by_vnd( + get_binding2changes(compat2binding_start, + compat2binding_end)) + + vnds_set: Set[str] = set() + vnds_set.update(set(vnd2added.keys()), + set(vnd2removed.keys()), + set(vnd2changes.keys())) + + return Changes(vnds=sorted(vnds_set), + vnd2added=vnd2added, + vnd2removed=vnd2removed, + vnd2changes=vnd2changes) + +def group_compat2binding_by_vnd( + compat2binding: Compat2Binding +) -> Dict[str, Compat2Binding]: + '''Convert *compat2binding* to a dict mapping vendor prefixes + to the subset of *compat2binding* with that vendor prefix.''' + ret: Dict[str, Compat2Binding] = defaultdict(dict) + + for compat, binding in compat2binding.items(): + ret[get_vnd(binding.compatible)][compat] = binding + + return ret + +def group_binding2changes_by_vnd( + binding2changes: Binding2Changes +) -> Dict[str, Binding2Changes]: + '''Convert *binding2chages* to a dict mapping vendor prefixes + to the subset of *binding2changes* with that vendor prefix.''' + ret: Dict[str, Binding2Changes] = defaultdict(dict) + + for binding, changes in binding2changes.items(): + ret[get_vnd(binding.compatible)][binding] = changes + + return ret + +def get_vnd(compatible: str) -> str: + '''Return the vendor prefix or the empty string.''' + if ',' not in compatible: + return '' + + return compatible.split(',')[0] + +def get_binding2changes( + compat2binding_start: Compat2Binding, + compat2binding_end: Compat2Binding +) -> Binding2Changes: + ret: Binding2Changes = {} + + for compat, binding in compat2binding_end.items(): + if compat not in compat2binding_start: + continue + + binding_start = compat2binding_start[compat] + binding_end = compat2binding_end[compat] + + binding_changes: List[BindingChange] = \ + get_binding_changes(binding_start, binding_end) + if binding_changes: + ret[binding] = binding_changes + + return ret + +def get_binding_changes( + binding_start: Binding, + binding_end: Binding +) -> List[BindingChange]: + '''Enumerate the changes to a binding given its start and end values.''' + ret: List[BindingChange] = [] + + assert binding_start.compatible == binding_end.compatible + assert binding_start.on_bus == binding_end.on_bus + + common_props: Set[str] = set(binding_start.prop2specs).intersection( + set(binding_end.prop2specs)) + + ret.extend(get_modified_specifier2cells(binding_start, binding_end)) + ret.extend(get_modified_buses(binding_start, binding_end)) + ret.extend(get_added_properties(binding_start, binding_end)) + ret.extend(get_removed_properties(binding_start, binding_end)) + ret.extend(get_modified_property_type(binding_start, binding_end, + common_props)) + ret.extend(get_modified_property_enum(binding_start, binding_end, + common_props)) + ret.extend(get_modified_property_const(binding_start, binding_end, + common_props)) + ret.extend(get_modified_property_default(binding_start, binding_end, + common_props)) + ret.extend(get_modified_property_deprecated(binding_start, binding_end, + common_props)) + ret.extend(get_modified_property_required(binding_start, binding_end, + common_props)) + + return ret + +def get_modified_specifier2cells( + binding_start: Binding, + binding_end: Binding +) -> List[BindingChange]: + ret: List[BindingChange] = [] + start = binding_start.specifier2cells + end = binding_end.specifier2cells + + if start == end: + return [] + + for space, cells_end in end.items(): + cells_start = start.get(space) + if cells_start != cells_end: + ret.append(ModifiedSpecifier2Cells(space, + start=cells_start, + end=cells_end)) + for space, cells_start in start.items(): + if space not in end: + ret.append(ModifiedSpecifier2Cells(space, + start=cells_start, + end=None)) + + return ret + +def get_modified_buses( + binding_start: Binding, + binding_end: Binding +) -> List[BindingChange]: + start = binding_start.buses + end = binding_end.buses + + if start == end: + return [] + + return [ModifiedBuses(start=start, end=end)] + +def get_added_properties( + binding_start: Binding, + binding_end: Binding +) -> List[BindingChange]: + return [AddedProperty(prop) for prop in binding_end.prop2specs + if prop not in binding_start.prop2specs] + +def get_removed_properties( + binding_start: Binding, + binding_end: Binding +) -> List[BindingChange]: + return [RemovedProperty(prop) for prop in binding_start.prop2specs + if prop not in binding_end.prop2specs] + +def get_modified_property_type( + binding_start: Binding, + binding_end: Binding, + common_props: Set[str] +) -> List[BindingChange]: + return get_modified_property_helper( + common_props, + lambda prop: binding_start.prop2specs[prop].type, + lambda prop: binding_end.prop2specs[prop].type, + ModifiedPropertyType) + +def get_modified_property_enum( + binding_start: Binding, + binding_end: Binding, + common_props: Set[str] +) -> List[BindingChange]: + return get_modified_property_helper( + common_props, + lambda prop: binding_start.prop2specs[prop].enum, + lambda prop: binding_end.prop2specs[prop].enum, + ModifiedPropertyEnum) + +def get_modified_property_const( + binding_start: Binding, + binding_end: Binding, + common_props: Set[str] +) -> List[BindingChange]: + return get_modified_property_helper( + common_props, + lambda prop: binding_start.prop2specs[prop].const, + lambda prop: binding_end.prop2specs[prop].const, + ModifiedPropertyConst) + +def get_modified_property_default( + binding_start: Binding, + binding_end: Binding, + common_props: Set[str] +) -> List[BindingChange]: + return get_modified_property_helper( + common_props, + lambda prop: binding_start.prop2specs[prop].default, + lambda prop: binding_end.prop2specs[prop].default, + ModifiedPropertyDefault) + +def get_modified_property_deprecated( + binding_start: Binding, + binding_end: Binding, + common_props: Set[str] +) -> List[BindingChange]: + return get_modified_property_helper( + common_props, + lambda prop: binding_start.prop2specs[prop].deprecated, + lambda prop: binding_end.prop2specs[prop].deprecated, + ModifiedPropertyDeprecated) + +def get_modified_property_required( + binding_start: Binding, + binding_end: Binding, + common_props: Set[str] +) -> List[BindingChange]: + return get_modified_property_helper( + common_props, + lambda prop: binding_start.prop2specs[prop].required, + lambda prop: binding_end.prop2specs[prop].required, + ModifiedPropertyRequired) + +def get_modified_property_helper( + common_props: Set[str], + start_fn: Callable[[str], Any], + end_fn: Callable[[str], Any], + change_constructor: Callable[[str, Any, Any], BindingChange] +) -> List[BindingChange]: + + ret = [] + for prop in common_props: + start = start_fn(prop) + end = end_fn(prop) + if start != end: + ret.append(change_constructor(prop, start, end)) + return ret + +def load_compat2binding(commit: str) -> Compat2Binding: + '''Load a map from compatible to binding with that compatible, + based on the bindings in zephyr at the given commit.''' + + @contextlib.contextmanager + def git_worktree(directory: os.PathLike, commit: str): + fspath = os.fspath(directory) + subprocess.run(['git', 'worktree', 'add', '--detach', fspath, commit], + check=True) + yield + print('removing worktree...') + subprocess.run(['git', 'worktree', 'remove', fspath], check=True) + + ret: Compat2Binding = {} + with tempfile.TemporaryDirectory(prefix='dt_bindings_worktree') as tmpdir: + with git_worktree(tmpdir, commit): + tmpdir_bindings = Path(tmpdir) / 'dts' / 'bindings' + binding_files = [] + binding_files.extend(glob.glob(f'{tmpdir_bindings}/**/*.yml', + recursive=True)) + binding_files.extend(glob.glob(f'{tmpdir_bindings}/**/*.yaml', + recursive=True)) + bindings: List[Binding] = bindings_from_paths( + binding_files, ignore_errors=True) + for binding in bindings: + compat = Compat(binding.compatible, binding.on_bus) + assert compat not in ret + ret[compat] = binding + + return ret + +def compatible_sort_key(data: Union[Compat, Binding]) -> str: + '''Sort key used by Printer.''' + return (data.compatible, data.on_bus or '') + +class Printer: + '''Helper class for formatting output.''' + + def __init__(self, outfile): + self.outfile = outfile + self.vnd2vendor_name = load_vendor_prefixes_txt( + ZEPHYR_BASE / 'dts' / 'bindings' / 'vendor-prefixes.txt') + + def print(self, *args, **kwargs): + kwargs['file'] = self.outfile + print(*args, **kwargs) + + def print_changes(self, changes: Changes): + for vnd in changes.vnds: + if vnd: + vnd_fmt = f' ({vnd})' + else: + vnd_fmt = '' + self.print(f'* {self.vendor_name(vnd)}{vnd_fmt}:\n') + + added = changes.vnd2added[vnd] + if added: + self.print(' * New bindings:\n') + self.print_compat2binding( + added, + lambda binding: f':dtcompatible:`{binding.compatible}`' + ) + + removed = changes.vnd2removed[vnd] + if removed: + self.print(' * Removed bindings:\n') + self.print_compat2binding( + removed, + lambda binding: f'``{binding.compatible}``' + ) + + modified = changes.vnd2changes[vnd] + if modified: + self.print(' * Modified bindings:\n') + self.print_binding2changes(modified) + + def print_compat2binding( + self, + compat2binding: Compat2Binding, + formatter: Callable[[Binding], str] + ) -> None: + for compat in sorted(compat2binding, key=compatible_sort_key): + self.print(f' * {formatter(compat2binding[compat])}') + self.print() + + def print_binding2changes(self, binding2changes: Binding2Changes) -> None: + for binding, changes in binding2changes.items(): + on_bus = f' (on {binding.on_bus} bus)' if binding.on_bus else '' + self.print(f' * :dtcompatible:`{binding.compatible}`{on_bus}:\n') + for change in changes: + self.print_change(change) + self.print() + + def print_change(self, change: BindingChange) -> None: + def print(msg): + self.print(f' * {msg}') + def print_prop_change(details): + print(f'property ``{change.property}`` {details} changed from ' + f'{change.start} to {change.end}') + if isinstance(change, ModifiedSpecifier2Cells): + print(f'specifier cells for space "{change.space}" ' + f'are now named: {change.end} (old value: {change.start})') + elif isinstance(change, ModifiedBuses): + print(f'bus list changed from {change.start} to {change.end}') + elif isinstance(change, AddedProperty): + print(f'new property: ``{change.property}``') + elif isinstance(change, RemovedProperty): + print(f'removed property: ``{change.property}``') + elif isinstance(change, ModifiedPropertyType): + print_prop_change('type') + elif isinstance(change, ModifiedPropertyEnum): + print_prop_change('enum value') + elif isinstance(change, ModifiedPropertyConst): + print_prop_change('const value') + elif isinstance(change, ModifiedPropertyDefault): + print_prop_change('default value') + elif isinstance(change, ModifiedPropertyDeprecated): + print_prop_change('deprecation status') + elif isinstance(change, ModifiedPropertyRequired): + if not change.start and change.end: + print(f'property ``{change.property}`` is now required') + else: + print(f'property ``{change.property}`` is no longer required') + else: + raise ValueError(f'unknown type for {change}: {type(change)}') + + def vendor_name(self, vnd: str) -> str: + # Necessary due to the patch for openthread. + + if vnd == 'openthread': + # FIXME: we have to go beyond the dict since this + # compatible isn't in vendor-prefixes.txt, but we have + # binding(s) for it. We need to fix this in CI by + # rejecting unknown vendors in a bindings check. + return 'OpenThread' + if vnd == '': + return 'Generic or vendor-independent' + return self.vnd2vendor_name[vnd] + +def parse_args() -> argparse.Namespace: + parser = argparse.ArgumentParser( + allow_abbrev=False, + description=''' +Print human-readable descriptions of changes to devicetree +bindings between two commits, in .rst format suitable for copy/pasting +into the release notes. +''', + formatter_class=argparse.RawDescriptionHelpFormatter + ) + parser.add_argument('start', metavar='START-COMMIT', + help='''what you want to compare bindings against + (typically the previous release's tag)''') + parser.add_argument('end', metavar='END-COMMIT', + help='''what you want to know bindings changes for + (typically 'main')''') + parser.add_argument('file', help='where to write the .rst output to') + return parser.parse_args() + +def main(): + args = parse_args() + + compat2binding_start = load_compat2binding(args.start) + compat2binding_end = load_compat2binding(args.end) + changes = get_changes_between(compat2binding_start, + compat2binding_end) + + with open(args.file, 'w') as outfile: + Printer(outfile).print_changes(changes) + +if __name__ == '__main__': + main() From ff2efd7ae531b2ac8218e65cc6389a10e82f035e Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Fri, 24 Mar 2023 07:14:45 -0400 Subject: [PATCH 0764/1906] net: socket: socketpair: remove experimental status Socketpair functionality has matured enough to be used in a consistent way now regardless of architecture or platform, even on `native_posix`. Remove the experimental status to reflect that. Signed-off-by: Chris Friedt --- subsys/net/lib/sockets/Kconfig | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/subsys/net/lib/sockets/Kconfig b/subsys/net/lib/sockets/Kconfig index 22c2d254352a..b4c2ada0d6c0 100644 --- a/subsys/net/lib/sockets/Kconfig +++ b/subsys/net/lib/sockets/Kconfig @@ -244,13 +244,11 @@ config NET_SOCKETS_CAN_RECEIVERS Socket-CAN interface. config NET_SOCKETPAIR - bool "Support for the socketpair syscall [EXPERIMENTAL]" - select EXPERIMENTAL + bool "Support for socketpair" select PIPES depends on HEAP_MEM_POOL_SIZE != 0 help - Choose y here if you would like to use the socketpair(2) - system call. + Communicate over a pair of connected, unnamed UNIX domain sockets. config NET_SOCKETPAIR_BUFFER_SIZE int "Size of the intermediate buffer, in bytes" From 6898094111816cfaab6d491a526685aba52f5e21 Mon Sep 17 00:00:00 2001 From: Daniel Nejezchleb Date: Thu, 23 Mar 2023 14:40:31 +0100 Subject: [PATCH 0765/1906] net: shell: Fix shell freeze Adds clean up after failed ping from shell, so it does not freeze the output. Signed-off-by: Daniel Nejezchleb --- subsys/net/ip/net_shell.c | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index 72f62d653f4d..c2f0d17ab0a7 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -4492,6 +4492,7 @@ static void ping_work(struct k_work *work) if (ret != 0) { PR_WARNING("Failed to send ping, err: %d", ret); + ping_done(ctx); return; } From 80ca540522c27dcc12b97cc582fa386ca06713fa Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Fri, 6 Jan 2023 16:49:23 -0800 Subject: [PATCH 0766/1906] snippets: basic build system boilerplate Basic things needed to integrate the new 'snippets' feature into the build system. The main CMake variable which controls snippets is SNIPPET. It is a whitespace-or-semicolon-separated list of snippet names. - Add minimal new cmake module for processing snippets. This just has basic infrastructure for processing a SNIPPET variable into SNIPPET_AS_LIST, and warning the user if they try to change it too late. - Integrate the new module into the build system, via zephyr_default.cmake This is anologous to the shields and boards modules' boilerplate and input variables. Signed-off-by: Marti Bolivar --- cmake/modules/snippets.cmake | 35 ++++++++++++++++++++++++++++++ cmake/modules/zephyr_default.cmake | 1 + 2 files changed, 36 insertions(+) create mode 100644 cmake/modules/snippets.cmake diff --git a/cmake/modules/snippets.cmake b/cmake/modules/snippets.cmake new file mode 100644 index 000000000000..3d01c362fa3b --- /dev/null +++ b/cmake/modules/snippets.cmake @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (c) 2021, Nordic Semiconductor ASA + +# Snippets support +# +# Outcome: +# The following variables will be defined when this module completes: +# +# - SNIPPET_AS_LIST: CMake list of snippet names, created from the +# SNIPPET variable + +include_guard(GLOBAL) + +include(extensions) + +# Warn the user if SNIPPET changes later. Such changes are ignored. +zephyr_check_cache(SNIPPET WATCH) + +# Putting the body into a function prevents us from polluting the +# parent scope. We'll set our outcome variables in the parent scope of +# the function to ensure the outcome of the module. +function(zephyr_process_snippets) + if (SNIPPET) + message(STATUS "Snippet(s): ${SNIPPET}") + else() + set(SNIPPET_AS_LIST "" PARENT_SCOPE) + return() + endif() + + string(REPLACE " " ";" SNIPPET_AS_LIST "${SNIPPET}") + set(SNIPPET_AS_LIST "${SNIPPET_AS_LIST}" PARENT_SCOPE) +endfunction() + +zephyr_process_snippets() diff --git a/cmake/modules/zephyr_default.cmake b/cmake/modules/zephyr_default.cmake index 908d03fceb97..0e41a253dd1f 100644 --- a/cmake/modules/zephyr_default.cmake +++ b/cmake/modules/zephyr_default.cmake @@ -81,6 +81,7 @@ list(APPEND zephyr_cmake_modules zephyr_module) list(APPEND zephyr_cmake_modules boards) list(APPEND zephyr_cmake_modules shields) +list(APPEND zephyr_cmake_modules snippets) list(APPEND zephyr_cmake_modules arch) list(APPEND zephyr_cmake_modules configuration_files) From 06c9bf47b37c0722559f3333c2e85240d4ecbddb Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Sat, 7 Jan 2023 15:27:07 -0800 Subject: [PATCH 0767/1906] snippets: initial snippet.yml support Add a new script, snippets.py, which is responsible for searching SNIPPET_ROOT for snippet definitions, validating them, and informing the build system about what needs doing as a result. Use this script in snippets.cmake to: - validate any discovered snippet.yml files - error out on undefined snippets - add a 'snippets' build system target that prints all snippet names (analogous to 'boards' and 'shields' targets) - handle any specific build system settings properly, by include()-ing a file it generates With this patch, you can define or extend a snippet in a snippet.yml file anywhere underneath a directory in SNIPPET_ROOT. The snippet.yml file format has a schema whose initial definition is in a new file, snippet-schema.yml. This initial snippet.yml file format supports adding .overlay and .conf files, like this: name: foo append: DTC_OVERLAY_FILE: foo.overlay OVERLAY_CONFIG: foo.conf boards: myboard: append: DTC_OVERLAY_FILE: myboard.overlay OVERLAY_CONFIG: myboard.conf /my-regular-expression-over-board-names/: append: DTC_OVERLAY_FILE: myregexp.overlay OVERLAY_CONFIG: myregexp.conf (Note that since the snippet feature is intended to be extensible, the same snippet name may appear in multiple files throughout any directory in SNIPPET_ROOT, with each addition augmenting prior ones.) This initial syntax aligns with the following snippet design goals: - extensible: you can add board-specific support for an existing snippet in another module - able to combine multiple types of configuration: we can now apply a .overlay and .conf at the same time - specializable: this allows you to define settings that only apply to a selectable set of boards (including with regular expression support for matching against multiple similar boards that follow a naming convention) - DRY: you can use regular expressions to apply the same snippet settings to multiple boards like this: /(board1|board2|...)/ This patch is not trying to design and implement everything up front. Additional features can and will be added to the snippet.yml format over time; using YAML as a format allows us to make backwards-compatible extensions as needed. Signed-off-by: Marti Bolivar --- cmake/modules/snippets.cmake | 102 +++++++++- scripts/schemas/snippet-schema.yml | 45 ++++ scripts/snippets.py | 316 +++++++++++++++++++++++++++++ 3 files changed, 457 insertions(+), 6 deletions(-) create mode 100644 scripts/schemas/snippet-schema.yml create mode 100644 scripts/snippets.py diff --git a/cmake/modules/snippets.cmake b/cmake/modules/snippets.cmake index 3d01c362fa3b..c3929c86b430 100644 --- a/cmake/modules/snippets.cmake +++ b/cmake/modules/snippets.cmake @@ -4,11 +4,33 @@ # Snippets support # +# This module: +# +# - searches for snippets in zephyr and any modules +# - validates the SNIPPET input variable, if any +# +# If SNIPPET contains a snippet name that is not found, an error +# will be raised, and the list of valid snippets will be printed. +# # Outcome: # The following variables will be defined when this module completes: # # - SNIPPET_AS_LIST: CMake list of snippet names, created from the # SNIPPET variable +# - SNIPPET_ROOT: CMake list of snippet roots, deduplicated and with +# ZEPHYR_BASE appended at the end +# +# The following variables may be updated when this module completes: +# - DTC_OVERLAY_FILE +# - OVERLAY_CONFIG +# +# The following targets will be defined when this CMake module completes: +# - snippets: when invoked, a list of valid snippets will be printed +# +# Optional variables: +# - SNIPPET_ROOT: input CMake list of snippet roots (directories containing +# additional snippet implementations); this should not include ZEPHYR_BASE, +# as that will be added by this module include_guard(GLOBAL) @@ -21,15 +43,83 @@ zephyr_check_cache(SNIPPET WATCH) # parent scope. We'll set our outcome variables in the parent scope of # the function to ensure the outcome of the module. function(zephyr_process_snippets) - if (SNIPPET) - message(STATUS "Snippet(s): ${SNIPPET}") - else() + set(snippets_py ${ZEPHYR_BASE}/scripts/snippets.py) + set(snippets_generated ${CMAKE_BINARY_DIR}/zephyr/snippets_generated.cmake) + + # Set SNIPPET_AS_LIST, removing snippets_generated.cmake if we are + # running cmake again and snippets are no longer requested. + if (NOT DEFINED SNIPPET) set(SNIPPET_AS_LIST "" PARENT_SCOPE) - return() + file(REMOVE ${snippets_generated}) + else() + string(REPLACE " " ";" SNIPPET_AS_LIST "${SNIPPET}") + set(SNIPPET_AS_LIST "${SNIPPET_AS_LIST}" PARENT_SCOPE) + endif() + + # Set SNIPPET_ROOT. + list(APPEND SNIPPET_ROOT ${APPLICATION_SOURCE_DIR}) + list(APPEND SNIPPET_ROOT ${ZEPHYR_BASE}) + unset(real_snippet_root) + foreach(snippet_dir ${SNIPPET_ROOT}) + # The user might have put a symbolic link in here, for example. + file(REAL_PATH ${snippet_dir} real_snippet_dir) + list(APPEND real_snippet_root ${real_snippet_dir}) + endforeach() + set(SNIPPET_ROOT ${real_snippet_root}) + list(REMOVE_DUPLICATES SNIPPET_ROOT) + set(SNIPPET_ROOT "${SNIPPET_ROOT}" PARENT_SCOPE) + + # Generate and include snippets_generated.cmake. + # The Python script is responsible for checking for unknown + # snippets. + set(snippet_root_args) + foreach(root IN LISTS SNIPPET_ROOT) + list(APPEND snippet_root_args --snippet-root "${root}") + endforeach() + set(requested_snippet_args) + foreach(snippet_name ${SNIPPET_AS_LIST}) + list(APPEND requested_snippet_args --snippet "${snippet_name}") + endforeach() + execute_process(COMMAND ${PYTHON_EXECUTABLE} + ${snippets_py} + ${snippet_root_args} + ${requested_snippet_args} + --cmake-out ${snippets_generated} + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE ret) + if(${ret}) + message(FATAL_ERROR "${output}") + endif() + include(${snippets_generated}) + + # Propagate include()d build system settings to the caller. + set(DTC_OVERLAY_FILE ${DTC_OVERLAY_FILE} PARENT_SCOPE) + set(OVERLAY_CONFIG ${OVERLAY_CONFIG} PARENT_SCOPE) + + # Create the 'snippets' target. Each snippet is printed in a + # separate command because build system files are not fond of + # newlines. + list(TRANSFORM SNIPPET_NAMES PREPEND "COMMAND;${CMAKE_COMMAND};-E;echo;" + OUTPUT_VARIABLE snippets_target_cmd) + add_custom_target(snippets ${snippets_target_cmd} USES_TERMINAL) + + # If snippets were requested, print messages for each one. + if(SNIPPET_AS_LIST) + # Print the requested snippets. + set(snippet_names "Snippet(s):") + foreach(snippet IN LISTS SNIPPET_AS_LIST) + string(APPEND snippet_names " ${snippet}") + endforeach() + message(STATUS "${snippet_names}") endif() - string(REPLACE " " ";" SNIPPET_AS_LIST "${SNIPPET}") - set(SNIPPET_AS_LIST "${SNIPPET_AS_LIST}" PARENT_SCOPE) + # Re-run cmake if any files we depend on changed. + set_property(DIRECTORY APPEND PROPERTY + CMAKE_CONFIGURE_DEPENDS + ${snippets_py} + ${SNIPPET_PATHS} # generated variable + ) endfunction() zephyr_process_snippets() diff --git a/scripts/schemas/snippet-schema.yml b/scripts/schemas/snippet-schema.yml new file mode 100644 index 000000000000..d6c46d543238 --- /dev/null +++ b/scripts/schemas/snippet-schema.yml @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (c) 2022, Nordic Semiconductor ASA + +# A pykwalify schema for basic validation of the snippet.yml format. + +schema;append-schema: + # Sub-schema for appending onto CMake list variables. + # See uses under 'append:' keys below. + type: map + mapping: + DTC_OVERLAY_FILE: + type: str + OVERLAY_CONFIG: + type: str + +type: map +mapping: + name: + required: true + type: str + append: + example: | + Snippet-wide appending can be done here: + + name: foo + append: + DTC_OVERLAY_FILE: m3.overlay + include: append-schema + boards: + example: | + Board-specific appending can be done here: + + name: foo + boards: + qemu_cortex_m3: + append: + DTC_OVERLAY_FILE: m3.overlay + type: map + mapping: + regex;(.*): + type: map + mapping: + append: + include: append-schema diff --git a/scripts/snippets.py b/scripts/snippets.py new file mode 100644 index 000000000000..7b838573a2c7 --- /dev/null +++ b/scripts/snippets.py @@ -0,0 +1,316 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2022, Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +'''Internal snippets tool. +This is part of the build system's support for snippets. +It is not meant for use outside of the build system. + +Output CMake variables: + +- SNIPPET_NAMES: CMake list of discovered snippet names +- SNIPPET_FOUND_{snippet}: one per discovered snippet +''' + +from collections import defaultdict, UserDict +from dataclasses import dataclass, field +from pathlib import Path +from typing import Dict, Iterable, List, Set +import argparse +import logging +import os +import pykwalify.core +import pykwalify.errors +import re +import sys +import textwrap +import yaml + +# Marker type for an 'append:' configuration. Maps variables +# to the list of values to append to them. +Appends = Dict[str, List[str]] + +def _new_append(): + return defaultdict(list) + +def _new_board2appends(): + return defaultdict(_new_append) + +@dataclass +class Snippet: + '''Class for keeping track of all the settings discovered for an + individual snippet.''' + + name: str + appends: Appends = field(default_factory=_new_append) + board2appends: Dict[str, Appends] = field(default_factory=_new_board2appends) + + def process_data(self, pathobj: Path, snippet_data: dict): + '''Process the data in a snippet.yml file, after it is loaded into a + python object and validated by pykwalify.''' + def append_value(variable, value): + if variable in ('DTC_OVERLAY_FILE', 'OVERLAY_CONFIG'): + path = pathobj.parent / value + if not path.is_file(): + _err(f'snippet file {pathobj}: {variable}: file not found: {path}') + return f'"{path}"' + _err(f'unknown append variable: {variable}') + + for variable, value in snippet_data.get('append', {}).items(): + self.appends[variable].append(append_value(variable, value)) + for board, settings in snippet_data.get('boards', {}).items(): + if board.startswith('/') and not board.endswith('/'): + _err(f"snippet file {pathobj}: board {board} starts with '/', so " + "it must end with '/' to use a regular expression") + for variable, value in settings.get('append', {}).items(): + self.board2appends[board][variable].append( + append_value(variable, value)) + +class Snippets(UserDict): + '''Type for all the information we have discovered about all snippets. + As a dict, this maps a snippet's name onto the Snippet object. + Any additional global attributes about all snippets go here as + instance attributes.''' + + def __init__(self, requested: Iterable[str] = None): + super().__init__() + self.paths: Set[Path] = set() + self.requested: Set[str] = set(requested or []) + +class SnippetsError(Exception): + '''Class for signalling expected errors''' + + def __init__(self, msg): + self.msg = msg + +class SnippetToCMakePrinter: + '''Helper class for printing a Snippets's semantics to a .cmake + include file for use by snippets.cmake.''' + + def __init__(self, snippets: Snippets, out_file): + self.snippets = snippets + self.out_file = out_file + self.section = '#' * 79 + + def print_cmake(self): + '''Print to the output file provided to the constructor.''' + # TODO: add source file info + snippets = self.snippets + snippet_names = sorted(snippets.keys()) + snippet_path_list = " ".join( + sorted(f'"{path}"' for path in snippets.paths)) + + self.print('''\ +# WARNING. THIS FILE IS AUTO-GENERATED. DO NOT MODIFY! +# +# This file contains build system settings derived from your snippets. +# Its contents are an implementation detail that should not be used outside +# of Zephyr's snippets CMake module. +# +# See the Snippets guide in the Zephyr documentation for more information. +''') + + self.print(f'''\ +{self.section} +# Global information about all snippets. + +# The name of every snippet that was discovered. +set(SNIPPET_NAMES {' '.join(f'"{name}"' for name in snippet_names)}) +# The paths to all the snippet.yml files. One snippet +# can have multiple snippet.yml files. +set(SNIPPET_PATHS {snippet_path_list}) +''') + + for snippet_name in snippet_names: + if snippet_name not in snippets.requested: + continue + self.print_cmake_for(snippets[snippet_name]) + self.print() + + def print_cmake_for(self, snippet: Snippet): + self.print(f'''\ +{self.section} +# Snippet '{snippet.name}' + +# Common variable appends.''') + self.print_appends(snippet.appends, 0) + for board, appends in snippet.board2appends.items(): + self.print_appends_for_board(board, appends) + + def print_appends_for_board(self, board: str, appends: Appends): + if board.startswith('/'): + board_re = board[1:-1] + self.print(f'''\ +# Appends for board regular expression '{board_re}' +if("${{BOARD}}" MATCHES "^{board_re}$")''') + else: + self.print(f'''\ +# Appends for board '{board}' +if("${{BOARD}}" STREQUAL "{board}")''') + self.print_appends(appends, 1) + self.print('endif()') + + def print_appends(self, appends: Appends, indent: int): + space = ' ' * indent + for name, values in appends.items(): + for value in values: + self.print(f'{space}list(APPEND {name} {value})') + + def print(self, *args, **kwargs): + kwargs['file'] = self.out_file + print(*args, **kwargs) + +# Name of the file containing the pykwalify schema for snippet.yml +# files. +SCHEMA_PATH = str(Path(__file__).parent / 'schemas' / 'snippet-schema.yml') +with open(SCHEMA_PATH, 'r') as f: + SNIPPET_SCHEMA = yaml.safe_load(f.read()) + +# The name of the file which contains metadata about the snippets +# being defined in a directory. +SNIPPET_YML = 'snippet.yml' + +# Regular expression for validating snippet names. Snippet names must +# begin with an alphanumeric character, and may contain alphanumeric +# characters or underscores. This is intentionally very restrictive to +# keep things consistent and easy to type and remember. We can relax +# this a bit later if needed. +SNIPPET_NAME_RE = re.compile('[A-Za-z0-9][A-Za-z0-9_-]*') + +# Logger for this module. +LOG = logging.getLogger('snippets') + +def _err(msg): + raise SnippetsError(f'error: {msg}') + +def parse_args(): + parser = argparse.ArgumentParser(description='snippets helper', + allow_abbrev=False) + parser.add_argument('--snippet-root', default=[], action='append', type=Path, + help='''a SNIPPET_ROOT element; may be given + multiple times''') + parser.add_argument('--snippet', dest='snippets', default=[], action='append', + help='''a SNIPPET element; may be given + multiple times''') + parser.add_argument('--cmake-out', type=Path, + help='''file to write cmake output to; include() + this file after calling this script''') + return parser.parse_args() + +def setup_logging(): + # Silence validation errors from pykwalify, which are logged at + # logging.ERROR level. We want to handle those ourselves as + # needed. + logging.getLogger('pykwalify').setLevel(logging.CRITICAL) + logging.basicConfig(level=logging.INFO, + format=' %(name)s: %(message)s') + +def process_snippets(args: argparse.Namespace) -> Snippets: + '''Process snippet.yml files under each *snippet_root* + by recursive search. Return a Snippets object describing + the results of the search. + ''' + # This will contain information about all the snippets + # we discover in each snippet_root element. + snippets = Snippets(requested=args.snippets) + + # Process each path in snippet_root in order, adjusting + # snippets as needed for each one. + for root in args.snippet_root: + process_snippets_in(root, snippets) + + return snippets + +def process_snippets_in(root_dir: Path, snippets: Snippets) -> None: + '''Process snippet.yml files in *root_dir*, + updating *snippets* as needed.''' + + if not root_dir.is_dir(): + LOG.warning(f'SNIPPET_ROOT {root_dir} ' + 'is not a directory; ignoring it') + return + + snippets_dir = root_dir / 'snippets' + if not snippets_dir.is_dir(): + return + + for dirpath, _, filenames in os.walk(snippets_dir): + if SNIPPET_YML not in filenames: + continue + + snippet_yml = Path(dirpath) / SNIPPET_YML + snippet_data = load_snippet_yml(snippet_yml) + name = snippet_data['name'] + if name not in snippets: + snippets[name] = Snippet(name=name) + snippets[name].process_data(snippet_yml, snippet_data) + snippets.paths.add(snippet_yml) + +def load_snippet_yml(snippet_yml: Path) -> dict: + '''Load a snippet.yml file *snippet_yml*, validate the contents + against the schema, and do other basic checks. Return the dict + of the resulting YAML data.''' + + with open(snippet_yml, 'r') as f: + try: + snippet_data = yaml.safe_load(f.read()) + except yaml.scanner.ScannerError: + _err(f'snippets file {snippet_yml} is invalid YAML') + + def pykwalify_err(e): + return f'''\ +invalid {SNIPPET_YML} file: {snippet_yml} +{textwrap.indent(e.msg, ' ')} +''' + + try: + pykwalify.core.Core(source_data=snippet_data, + schema_data=SNIPPET_SCHEMA).validate() + except pykwalify.errors.PyKwalifyException as e: + _err(pykwalify_err(e)) + + name = snippet_data['name'] + if not SNIPPET_NAME_RE.fullmatch(name): + _err(f"snippet file {snippet_yml}: invalid snippet name '{name}'; " + 'snippet names must begin with a letter ' + 'or number, and may only contain letters, numbers, ' + 'dashes (-), and underscores (_)') + + return snippet_data + +def check_for_errors(snippets: Snippets) -> None: + unknown_snippets = sorted(snippet for snippet in snippets.requested + if snippet not in snippets) + if unknown_snippets: + all_snippets = '\n '.join(sorted(snippets)) + _err(f'''\ +snippets not found: {', '.join(unknown_snippets)} + Please choose from among the following snippets: + {all_snippets}''') + +def write_cmake_out(snippets: Snippets, cmake_out: Path) -> None: + '''Write a cmake include file to *cmake_out* which + reflects the information in *snippets*. + + The contents of this file should be considered an implementation + detail and are not meant to be used outside of snippets.cmake.''' + if not cmake_out.parent.exists(): + cmake_out.parent.mkdir() + with open(cmake_out, 'w') as f: + SnippetToCMakePrinter(snippets, f).print_cmake() + +def main(): + args = parse_args() + setup_logging() + try: + snippets = process_snippets(args) + check_for_errors(snippets) + except SnippetsError as e: + LOG.critical(e.msg) + sys.exit(1) + write_cmake_out(snippets, args.cmake_out) + +if __name__ == "__main__": + main() From 3f282da0e829c02f354296a230b4a3403fd070a8 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Sat, 7 Jan 2023 15:25:10 -0800 Subject: [PATCH 0768/1906] zephyr modules: add 'snippet_root' support to module.yml This key may appear in a module.yml's 'settings' map, and works analogously to the already existing 'board_root', 'dts_root', etc. keys: if set, its value is interpreted as a directory that will be added to SNIPPET ROOT. For example, if a module.yml contains: settings: snippet_root: foo Then 'foo', relative to the module's base directory, will be added to SNIPPET_ROOT. This then means that any snippets in foo/snippets will be discovered by the build system. Signed-off-by: Marti Bolivar --- scripts/zephyr_module.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/zephyr_module.py b/scripts/zephyr_module.py index e0cf18d56456..eb5c0eb7bfe6 100755 --- a/scripts/zephyr_module.py +++ b/scripts/zephyr_module.py @@ -86,6 +86,9 @@ dts_root: required: false type: str + snippet_root: + required: false + type: str soc_root: required: false type: str @@ -270,7 +273,7 @@ def process_settings(module, meta): out_text = "" if build_settings is not None: - for root in ['board', 'dts', 'soc', 'arch', 'module_ext', 'sca']: + for root in ['board', 'dts', 'snippet', 'soc', 'arch', 'module_ext', 'sca']: setting = build_settings.get(root+'_root', None) if setting is not None: root_path = PurePath(module) / setting From 5880feee338721bb02182b7be39559f4ccb94f08 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 9 Jan 2023 16:17:51 -0800 Subject: [PATCH 0769/1906] west: build: add -S argument Writing '-S foo' is a convenience shorthand for adding snippets at CMake time without having to add '-- -DSNIPPET=foo' to the west build command line. It is worth adding a new one-letter command line option because snippets are anticipated to be a very commonly used feature. Signed-off-by: Marti Bolivar --- scripts/west_commands/build.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/west_commands/build.py b/scripts/west_commands/build.py index 9f030707ed9d..ee987db61094 100644 --- a/scripts/west_commands/build.py +++ b/scripts/west_commands/build.py @@ -130,6 +130,13 @@ def do_add_parser(self, parser_adder): group.add_argument('-n', '--just-print', '--dry-run', '--recon', dest='dry_run', action='store_true', help="just print build commands; don't run them") + group.add_argument('-S', '--snippet', dest='snippets', + action='append', default=[], + help='''add the argument to SNIPPET; may be given + multiple times. Forces CMake to run again if given. + Do not use this option with manually specified + -DSNIPPET... cmake arguments: the results are + undefined''') group = parser.add_mutually_exclusive_group() group.add_argument('--sysbuild', action='store_true', @@ -196,7 +203,7 @@ def do_run(self, args, remainder): else: self._update_cache() if (self.args.cmake or self.args.cmake_opts or - self.args.cmake_only): + self.args.cmake_only or self.args.snippets): self.run_cmake = True else: self.run_cmake = True @@ -469,6 +476,8 @@ def _run_cmake(self, board, origin, cmake_opts): cmake_opts = [] if self.args.cmake_opts: cmake_opts.extend(self.args.cmake_opts) + if self.args.snippets: + cmake_opts.append(f'-DSNIPPET={";".join(self.args.snippets)}') user_args = config_get('cmake-args', None) if user_args: From 1f9ab853541983f6eb6e349ee3ee902a63d2dcef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Thu, 9 Mar 2023 13:10:28 -0800 Subject: [PATCH 0770/1906] west: build: appease the linter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The linter is complaining about unnecessary parens. Signed-off-by: Martí Bolívar --- scripts/west_commands/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/west_commands/build.py b/scripts/west_commands/build.py index ee987db61094..6797ff1c48d0 100644 --- a/scripts/west_commands/build.py +++ b/scripts/west_commands/build.py @@ -191,7 +191,7 @@ def do_run(self, args, remainder): 'treating unknown build.pristine value "{}" as "never"'. format(pristine)) pristine = 'never' - self.auto_pristine = (pristine == 'auto') + self.auto_pristine = pristine == 'auto' log.dbg('pristine: {} auto_pristine: {}'.format(pristine, self.auto_pristine), From ee4b134dd604159cbb21a39ad6b93237f3974122 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 9 Jan 2023 15:46:59 -0800 Subject: [PATCH 0771/1906] doc: add snippets documentation Document this new build system feature. Since its purpose is customizing application builds, the logical place for the main body of documentation is in a new snippets/ directory in doc/build/. Create that directory and add its initial documentation. Like boards and samples, however, we expect people to write documentation for each snippet within the directory that defines the snippet itself. Therefore, add a new top-level snippets/ directory and stub out the documentation needed to document individual snippets as well. Add documentation and cross-references in other required places as well. Signed-off-by: Marti Bolivar --- doc/build/index.rst | 1 + doc/build/snippets/design.rst | 37 +++++ doc/build/snippets/index.rst | 25 ++++ doc/build/snippets/using.rst | 39 +++++ doc/build/snippets/writing.rst | 188 +++++++++++++++++++++++++ doc/conf.py | 3 + doc/develop/modules.rst | 6 + doc/develop/west/build-flash-debug.rst | 5 + snippets/index.rst | 10 ++ 9 files changed, 314 insertions(+) create mode 100644 doc/build/snippets/design.rst create mode 100644 doc/build/snippets/index.rst create mode 100644 doc/build/snippets/using.rst create mode 100644 doc/build/snippets/writing.rst create mode 100644 snippets/index.rst diff --git a/doc/build/index.rst b/doc/build/index.rst index dc0c6bceffd0..75be277c7219 100644 --- a/doc/build/index.rst +++ b/doc/build/index.rst @@ -11,5 +11,6 @@ Build and Configuration Systems cmake/index.rst dts/index kconfig/index.rst + snippets/index.rst zephyr_cmake_package.rst sysbuild/index.rst diff --git a/doc/build/snippets/design.rst b/doc/build/snippets/design.rst new file mode 100644 index 000000000000..03d80f597ec0 --- /dev/null +++ b/doc/build/snippets/design.rst @@ -0,0 +1,37 @@ +Snippets Design +############### + +This page documents design goals for the snippets feature. +Further information can be found in `Issue #51834`_. + +.. _Issue #51834: https://github.com/zephyrproject-rtos/zephyr/issues/51834 + +- **extensible**: for example, it is possible to add board support for an + existing built-in snippet without modifying the zephyr repository + +- **composable**: it is possible to use multiple snippets at once, for example + using: + + .. code-block:: console + + west build -S -S ... + +- **able to combine multiple types of configuration**: snippets make it possible + to store multiple different types of build system settings in one place, and + apply them all together + +- **specializable**: for example, it is possible to customize a snippet's + behavior for a particular board, or board revision + +- **future-proof and backwards-compatible**: arbitrary future changes to the + snippets feature will be possible without breaking backwards compatibility + for older snippets + +- **applicable to purely "software" changes**: unlike the shields feature, + snippets do not assume the presence of a "daughterboard", "shield", "hat", or + any other type of external assembly which is connected to the main board + +- **DRY** (don't repeat yourself): snippets allow you to skip unnecessary + repetition; for example, you can apply the same board-specific configuration + to boards ``foo`` and ``bar`` by specifying ``/(foo|bar)/`` as a regular + expression for the settings, which will then apply to both boards diff --git a/doc/build/snippets/index.rst b/doc/build/snippets/index.rst new file mode 100644 index 000000000000..53db2b8f1989 --- /dev/null +++ b/doc/build/snippets/index.rst @@ -0,0 +1,25 @@ +.. _snippets: + +Snippets +######## + +Snippets are a way to save build system settings in one place, and then use +those settings when you build any Zephyr application. This lets you save common +configuration separately when it applies to multiple different applications. + +Some example use cases for snippets are: + +- changing your board's console backend from a "real" UART to a USB CDC-ACM UART +- enabling frequently-used debugging options +- applying interrelated configuration settings to your "main" CPU and a + co-processor core on an AMP SoC + +The following pages document this feature. + +.. toctree:: + :maxdepth: 1 + + using.rst + /snippets/index.rst + writing.rst + design.rst diff --git a/doc/build/snippets/using.rst b/doc/build/snippets/using.rst new file mode 100644 index 000000000000..608e2924302e --- /dev/null +++ b/doc/build/snippets/using.rst @@ -0,0 +1,39 @@ +.. _using-snippets: + +Using Snippets +############## + +.. tip:: + + See :ref:`built-in-snippets` for a list of snippets that are provided by + Zephyr. + +Snippets have names. You use snippets by giving their names to the build +system. + +With west build +*************** + +To use a snippet named ``foo`` when building an application ``app``: + +.. code-block:: console + + west build -S foo app + +To use multiple snippets: + +.. code-block:: console + + west build -S snippet1 -S snippet2 [...] app + +With cmake +********** + +If you are running CMake directly instead of using ``west build``, use the +``SNIPPET`` variable. This is a whitespace- or semicolon-separated list of +snippet names you want to use. For example: + +.. code-block:: console + + cmake -Sapp -Bbuild -DSNIPPET="snippet1;snippet2" [...] + cmake --build build diff --git a/doc/build/snippets/writing.rst b/doc/build/snippets/writing.rst new file mode 100644 index 000000000000..66101e8e2b63 --- /dev/null +++ b/doc/build/snippets/writing.rst @@ -0,0 +1,188 @@ +Writing Snippets +################ + +.. contents:: + :local: + +Basics +****** + +Snippets are defined using YAML files named :file:`snippet.yml`. + +A :file:`snippet.yml` file contains the name of the snippet, along with +additional build system settings, like this: + +.. code-block:: yaml + + name: snippet-name + # ... build system settings go here ... + +Build system settings go in other keys in the file as described later on in +this page. + +You can combine settings whenever they appear under the same keys. For example, +you can combine a snippet-specific devicetree overlay and a ``.conf`` file like +this: + +.. code-block:: yaml + + name: foo + append: + DTC_OVERLAY_FILE: foo.overlay + OVERLAY_CONFIG: foo.conf + +Namespacing +*********** + +When writing devicetree overlays in a snippet, use ``snippet_`` or +``snippet-`` as a namespace prefix when choosing names for node labels, +node names, etc. This avoids namespace conflicts. + +For example, if your snippet is named ``foo-bar``, write your devicetree +overlays like this: + +.. code-block:: DTS + + chosen { + zephyr,baz = &snippet_foo_bar_dev; + }; + + snippet_foo_bar_dev: device@12345678 { + /* ... */ + }; + +Where snippets are located +************************** + +The build system looks for snippets in these places: + +#. In directories configured by the :makevar:`SNIPPET_ROOT` CMake variable. + This always includes the zephyr repository (so + :zephyr_file:`zephyr/snippets` is always a source of snippets) and the + application source directory (so :file:`/snippets` is also). + + Additional directories can be added manually at CMake time. + + The variable is a whitespace- or semicolon-separated list of directories + which may contain snippet definitions. + + For each directory in the list, the build system looks for + :file:`snippet.yml` files underneath a subdirectory named :file:`snippets/`, + if one exists. + + For example, if :makevar:`SNIPPET_ROOT` is set to ``/foo;/bar``, the build + system will look for :file:`snippet.yml` files underneath the following + subdirectories: + + - :file:`/foo/snippets/` + - :file:`/bar/snippets/` + + The :file:`snippet.yml` files can be nested anywhere underneath these + locations. + +#. In any :ref:`module ` whose :file:`module.yml` file provides a + ``snippet_root`` setting. + + For example, in a zephyr module named ``baz``, you can add this to your + :file:`module.yml` file: + + .. code-block:: yaml + + settings: + snippet_root: . + + And then any :file:`snippet.yml` files in ``baz/snippets`` will + automatically be discovered by the build system, just as if + the path to ``baz`` had appeared in :makevar:`SNIPPET_ROOT`. + +Processing order +**************** + +The order that snippets are processed is currently not defined. +Therefore, you should write your :file:`snippet.yml` file so that +it is not dependent on other snippets. + +.. _snippets-devicetree-overlays: + +Devicetree overlays (``.overlay``) +********************************** + +This :file:`snippet.yml` adds :file:`foo.overlay` to the build: + +.. code-block:: yaml + + name: foo + append: + DTC_OVERLAY_FILE: foo.overlay + +The path to :file:`foo.overlay` is relative to the directory containing +:file:`snippet.yml`. + +.. _snippets-conf-files: + +``.conf`` files +*************** + +This :file:`snippet.yml` adds :file:`foo.conf` to the build: + +.. code-block:: yaml + + name: foo + append: + OVERLAY_CONFIG: foo.conf + +The path to :file:`foo.conf` is relative to the directory containing +:file:`snippet.yml`. + +Board-specific settings +*********************** + +You can write settings that only apply to some boards. + +The settings described here are applied in **addition** to snippet settings +that apply to all boards. (This is similar, for example, to the way that an +application with both :file:`prj.conf` and :file:`boards/foo.conf` files will +use both ``.conf`` files in the build when building for board ``foo``, instead +of just :file:`boards/foo.conf`) + +By name +======= + +.. code-block:: yaml + + name: ... + boards: + bar: # settings for board "bar" go here + append: + DTC_OVERLAY_FILE: bar.overlay + baz: # settings for board "baz" go here + append: + DTC_OVERLAY_FILE: baz.overlay + +The above example uses :file:`bar.overlay` when building for board ``bar``, and +:file:`baz.overlay` when building for ``baz``. + +By regular expression +===================== + +You can enclose the board name in slashes (``/``) to match the name against a +regular expression in the `CMake syntax`_. The regular expression must match +the entire board name. + +.. _CMake syntax: + https://cmake.org/cmake/help/latest/command/string.html#regex-specification + +For example: + +.. code-block:: yaml + + name: foo + boards: + /my_vendor_.*/: + append: + DTC_OVERLAY_FILE: my_vendor.overlay + +The above example uses devicetree overlay :file:`my_vendor.overlay` when +building for either board ``my_vendor_board1`` or ``my_vendor_board2``. It +would not use the overlay when building for either ``another_vendor_board`` or +``x_my_vendor_board``. diff --git a/doc/conf.py b/doc/conf.py index 4229a782327a..aeccbd204b07 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -269,6 +269,7 @@ vcs_link_prefixes = { "samples/.*": "", "boards/.*": "", + "snippets/.*": "", ".*": "doc", } vcs_link_exclude = [ @@ -290,6 +291,8 @@ (ZEPHYR_BASE, "boards/**/doc"), (ZEPHYR_BASE, "samples/**/*.rst"), (ZEPHYR_BASE, "samples/**/doc"), + (ZEPHYR_BASE, "snippets/**/*.rst"), + (ZEPHYR_BASE, "snippets/**/doc"), ] external_content_keep = [ "reference/kconfig/*", diff --git a/doc/develop/modules.rst b/doc/develop/modules.rst index a75f1f849e3a..88467223481d 100644 --- a/doc/develop/modules.rst +++ b/doc/develop/modules.rst @@ -850,6 +850,12 @@ Build settings supported in the :file:`module.yml` file are: - ``dts_root``: Contains additional dts files related to the architecture/soc families. Additional dts files must be located in a :file:`/dts` folder. +- ``snippet_root``: Contains additional snippets that are available for use. + These snippets must be defined in :file:`snippet.yml` files underneath the + :file:`/snippets` folder. For example, if you have + ``snippet_root: foo``, then you should place your module's + :file:`snippet.yml` files in :file:`/foo/snippets` or any + nested subdirectory. - ``soc_root``: Contains additional SoCs that are available to the build system. Additional SoCs must be located in a :file:`/soc` folder. - ``arch_root``: Contains additional architectures that are available to the diff --git a/doc/develop/west/build-flash-debug.rst b/doc/develop/west/build-flash-debug.rst index df8fe9216579..8fd682721787 100644 --- a/doc/develop/west/build-flash-debug.rst +++ b/doc/develop/west/build-flash-debug.rst @@ -350,6 +350,11 @@ build the specific target for the target, for example:: west build --sysbuild --domain hello_world --target help +Use a snippet +------------- + +See :ref:`using-snippets`. + .. _west-building-config: Configuration Options diff --git a/snippets/index.rst b/snippets/index.rst new file mode 100644 index 000000000000..f0604abfae43 --- /dev/null +++ b/snippets/index.rst @@ -0,0 +1,10 @@ +.. _built-in-snippets: + +Built-in snippets +################# + +.. toctree:: + :maxdepth: 1 + :glob: + + **/* From cac263ec3f2aacbf2f3580c74805fcc74f57357a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Wed, 8 Mar 2023 14:39:54 -0800 Subject: [PATCH 0772/1906] snippets: add cdc-acm-console MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This snippet is based on samples/subsys/usb/console. Since it's a snippet, it can be used in any application as long as its requirements are met. This makes it more general purpose. Signed-off-by: Martí Bolívar --- snippets/cdc-acm-console/README.rst | 36 +++++++++++++++++++ snippets/cdc-acm-console/cdc-acm-console.conf | 8 +++++ .../cdc-acm-console/cdc-acm-console.overlay | 17 +++++++++ snippets/cdc-acm-console/snippet.yml | 4 +++ 4 files changed, 65 insertions(+) create mode 100644 snippets/cdc-acm-console/README.rst create mode 100644 snippets/cdc-acm-console/cdc-acm-console.conf create mode 100644 snippets/cdc-acm-console/cdc-acm-console.overlay create mode 100644 snippets/cdc-acm-console/snippet.yml diff --git a/snippets/cdc-acm-console/README.rst b/snippets/cdc-acm-console/README.rst new file mode 100644 index 000000000000..c1d165b771de --- /dev/null +++ b/snippets/cdc-acm-console/README.rst @@ -0,0 +1,36 @@ +.. _snippet-cdc-acm-console: + +CDC-ACM Console Snippet (cdc-acm-console) +######################################### + +.. code-block:: console + + west build -S cdc-acm-console [...] + +Overview +******** + +This snippet redirects serial console output to a CDC ACM UART. The USB device +which should be used is configured using :ref:`devicetree`. + +Requirements +************ + +Hardware support for: + +- :kconfig:option:`CONFIG_USB_DEVICE_STACK` +- :kconfig:option:`CONFIG_SERIAL` +- :kconfig:option:`CONFIG_CONSOLE` +- :kconfig:option:`CONFIG_UART_CONSOLE` +- :kconfig:option:`CONFIG_UART_LINE_CTRL` + +A devicetree node with node label ``zephyr_udc0`` that points to an enabled USB +device node with driver support. This should look roughly like this in +:ref:`your devicetree `: + +.. code-block:: DTS + + zephyr_udc0: usbd@deadbeef { + compatible = "vnd,usb-device"; + /* ... */ + }; diff --git a/snippets/cdc-acm-console/cdc-acm-console.conf b/snippets/cdc-acm-console/cdc-acm-console.conf new file mode 100644 index 000000000000..28103411fc3e --- /dev/null +++ b/snippets/cdc-acm-console/cdc-acm-console.conf @@ -0,0 +1,8 @@ +CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_DEVICE_PRODUCT="Zephyr USB console sample" +CONFIG_USB_DEVICE_PID=0x0004 + +CONFIG_SERIAL=y +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y +CONFIG_UART_LINE_CTRL=y diff --git a/snippets/cdc-acm-console/cdc-acm-console.overlay b/snippets/cdc-acm-console/cdc-acm-console.overlay new file mode 100644 index 000000000000..91e61886e522 --- /dev/null +++ b/snippets/cdc-acm-console/cdc-acm-console.overlay @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2021, 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + zephyr,console = &snippet_cdc_acm_console_uart; + }; +}; + +&zephyr_udc0 { + snippet_cdc_acm_console_uart: snippet_cdc_acm_console_uart { + compatible = "zephyr,cdc-acm-uart"; + }; +}; diff --git a/snippets/cdc-acm-console/snippet.yml b/snippets/cdc-acm-console/snippet.yml new file mode 100644 index 000000000000..eab58a30a40e --- /dev/null +++ b/snippets/cdc-acm-console/snippet.yml @@ -0,0 +1,4 @@ +name: cdc-acm-console +append: + OVERLAY_CONFIG: cdc-acm-console.conf + DTC_OVERLAY_FILE: cdc-acm-console.overlay From a7aafcbbdc2a212d6cd0858a6fc2219e1fe9df77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Wed, 22 Mar 2023 12:55:36 -0700 Subject: [PATCH 0773/1906] tests: add snippet test suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an initial test suite for the basic SNIPPET_ROOT, SNIPPET, and 'append' features in snippet.yml. Signed-off-by: Martí Bolívar --- tests/cmake/snippets/CMakeLists.txt | 12 +++++++++++ tests/cmake/snippets/Kconfig | 14 +++++++++++++ tests/cmake/snippets/app.overlay | 4 ++++ .../snippets/bar/bar.overlay | 3 +++ .../snippets/bar/snippet.yml | 3 +++ tests/cmake/snippets/prj.conf | 2 ++ tests/cmake/snippets/snippets/foo/foo.conf | 1 + tests/cmake/snippets/snippets/foo/snippet.yml | 3 +++ tests/cmake/snippets/src/main.c | 20 +++++++++++++++++++ tests/cmake/snippets/testcase.yaml | 6 ++++++ 10 files changed, 68 insertions(+) create mode 100644 tests/cmake/snippets/CMakeLists.txt create mode 100644 tests/cmake/snippets/Kconfig create mode 100644 tests/cmake/snippets/app.overlay create mode 100644 tests/cmake/snippets/extra_snippet_root/snippets/bar/bar.overlay create mode 100644 tests/cmake/snippets/extra_snippet_root/snippets/bar/snippet.yml create mode 100644 tests/cmake/snippets/prj.conf create mode 100644 tests/cmake/snippets/snippets/foo/foo.conf create mode 100644 tests/cmake/snippets/snippets/foo/snippet.yml create mode 100644 tests/cmake/snippets/src/main.c create mode 100644 tests/cmake/snippets/testcase.yaml diff --git a/tests/cmake/snippets/CMakeLists.txt b/tests/cmake/snippets/CMakeLists.txt new file mode 100644 index 000000000000..43ac5a365540 --- /dev/null +++ b/tests/cmake/snippets/CMakeLists.txt @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +set(SNIPPET_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/extra_snippet_root") +set(SNIPPET foo bar) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(test_snippets) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/cmake/snippets/Kconfig b/tests/cmake/snippets/Kconfig new file mode 100644 index 000000000000..54d3f14e1e52 --- /dev/null +++ b/tests/cmake/snippets/Kconfig @@ -0,0 +1,14 @@ +# Copyright 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +mainmenu "Snippet tests" + +menu "Zephyr" +source "Kconfig.zephyr" +endmenu + +config FOO + int "Helper option for testing snippet foo" + default 1 + help + This option's value should be overridden by the foo snippet. diff --git a/tests/cmake/snippets/app.overlay b/tests/cmake/snippets/app.overlay new file mode 100644 index 000000000000..178dbfabb1c2 --- /dev/null +++ b/tests/cmake/snippets/app.overlay @@ -0,0 +1,4 @@ +/ { + /* This node will be deleted by the bar snippet. */ + deleted-by-bar {}; +}; diff --git a/tests/cmake/snippets/extra_snippet_root/snippets/bar/bar.overlay b/tests/cmake/snippets/extra_snippet_root/snippets/bar/bar.overlay new file mode 100644 index 000000000000..e960c3cf7bba --- /dev/null +++ b/tests/cmake/snippets/extra_snippet_root/snippets/bar/bar.overlay @@ -0,0 +1,3 @@ +/ { + /delete-node/ deleted-by-bar; +}; diff --git a/tests/cmake/snippets/extra_snippet_root/snippets/bar/snippet.yml b/tests/cmake/snippets/extra_snippet_root/snippets/bar/snippet.yml new file mode 100644 index 000000000000..914371337791 --- /dev/null +++ b/tests/cmake/snippets/extra_snippet_root/snippets/bar/snippet.yml @@ -0,0 +1,3 @@ +name: bar +append: + DTC_OVERLAY_FILE: bar.overlay diff --git a/tests/cmake/snippets/prj.conf b/tests/cmake/snippets/prj.conf new file mode 100644 index 000000000000..9228251051ec --- /dev/null +++ b/tests/cmake/snippets/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y diff --git a/tests/cmake/snippets/snippets/foo/foo.conf b/tests/cmake/snippets/snippets/foo/foo.conf new file mode 100644 index 000000000000..3647569a3b79 --- /dev/null +++ b/tests/cmake/snippets/snippets/foo/foo.conf @@ -0,0 +1 @@ +CONFIG_FOO=2 diff --git a/tests/cmake/snippets/snippets/foo/snippet.yml b/tests/cmake/snippets/snippets/foo/snippet.yml new file mode 100644 index 000000000000..22817d7ebf1b --- /dev/null +++ b/tests/cmake/snippets/snippets/foo/snippet.yml @@ -0,0 +1,3 @@ +name: foo +append: + OVERLAY_CONFIG: foo.conf diff --git a/tests/cmake/snippets/src/main.c b/tests/cmake/snippets/src/main.c new file mode 100644 index 000000000000..9f83af10cf35 --- /dev/null +++ b/tests/cmake/snippets/src/main.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +ZTEST_SUITE(snippet_tests, NULL, NULL, NULL, NULL, NULL); + +ZTEST(snippet_tests, test_foo) +{ + zassert_equal(CONFIG_FOO, 2, "foo snippet should set CONFIG_FOO=2"); +} + +ZTEST(snippet_tests, test_bar) +{ + zassert_equal(DT_NODE_EXISTS(DT_PATH(deleted_by_bar)), 0, + "bar snippet should delete /deleted-by-bar node"); +} diff --git a/tests/cmake/snippets/testcase.yaml b/tests/cmake/snippets/testcase.yaml new file mode 100644 index 000000000000..27198d0d1263 --- /dev/null +++ b/tests/cmake/snippets/testcase.yaml @@ -0,0 +1,6 @@ +tests: + cmake.snippets: + tags: snippets + platform_allow: native_posix qemu_x86 qemu_x86_64 qemu_cortex_m3 + integration_platforms: + - native_posix From 672aeace88c6300fd7f8e7a53d12fbeb9ad815a0 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Fri, 24 Mar 2023 19:10:50 +0000 Subject: [PATCH 0774/1906] libc: share time() between minimal libc and armclang libc Introduce a place to share implementations of libc functions that are needed by different libc versions. Place time() in this common location so it can be shared when building for either minimal libc or armclang libc. Signed-off-by: Kumar Gala --- cmake/toolchain/armclang/Kconfig | 1 + lib/libc/CMakeLists.txt | 2 ++ lib/libc/Kconfig | 1 + lib/libc/common/CMakeLists.txt | 4 ++++ lib/libc/common/Kconfig | 7 +++++++ lib/libc/{minimal => common}/source/time/time.c | 0 lib/libc/minimal/CMakeLists.txt | 1 - lib/libc/minimal/Kconfig | 1 + 8 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 lib/libc/common/CMakeLists.txt create mode 100644 lib/libc/common/Kconfig rename lib/libc/{minimal => common}/source/time/time.c (100%) diff --git a/cmake/toolchain/armclang/Kconfig b/cmake/toolchain/armclang/Kconfig index c2df1e1024aa..72ae8149eeeb 100644 --- a/cmake/toolchain/armclang/Kconfig +++ b/cmake/toolchain/armclang/Kconfig @@ -15,6 +15,7 @@ choice LIBC_IMPLEMENTATION config ARMCLANG_STD_LIBC bool "ARM Compiler C library" + select COMMON_LIBC_TIME if POSIX_CLOCK help Use the full Arm Compiler runtime libraries. A reduced Zephyr minimal libc will be used for library functionality diff --git a/lib/libc/CMakeLists.txt b/lib/libc/CMakeLists.txt index 3f298b157fc9..e640e36c145c 100644 --- a/lib/libc/CMakeLists.txt +++ b/lib/libc/CMakeLists.txt @@ -5,3 +5,5 @@ add_subdirectory_ifdef(CONFIG_ARMCLANG_STD_LIBC armstdc) add_subdirectory_ifdef(CONFIG_MINIMAL_LIBC minimal) add_subdirectory_ifdef(CONFIG_NEWLIB_LIBC newlib) add_subdirectory_ifdef(CONFIG_PICOLIBC picolibc) + +add_subdirectory(common) diff --git a/lib/libc/Kconfig b/lib/libc/Kconfig index 11768537fe32..4e55388bf27a 100644 --- a/lib/libc/Kconfig +++ b/lib/libc/Kconfig @@ -75,6 +75,7 @@ endchoice # LIBC_IMPLEMENTATION config HAS_NEWLIB_LIBC_NANO bool +rsource "common/Kconfig" rsource "minimal/Kconfig" rsource "newlib/Kconfig" rsource "picolibc/Kconfig" diff --git a/lib/libc/common/CMakeLists.txt b/lib/libc/common/CMakeLists.txt new file mode 100644 index 000000000000..207cef418f6a --- /dev/null +++ b/lib/libc/common/CMakeLists.txt @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() +zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_TIME source/time/time.c) diff --git a/lib/libc/common/Kconfig b/lib/libc/common/Kconfig new file mode 100644 index 000000000000..6e155957f216 --- /dev/null +++ b/lib/libc/common/Kconfig @@ -0,0 +1,7 @@ +# Copyright (c) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +config COMMON_LIBC_TIME + bool + help + common implementation of time(). diff --git a/lib/libc/minimal/source/time/time.c b/lib/libc/common/source/time/time.c similarity index 100% rename from lib/libc/minimal/source/time/time.c rename to lib/libc/common/source/time/time.c diff --git a/lib/libc/minimal/CMakeLists.txt b/lib/libc/minimal/CMakeLists.txt index a13ecbacd25c..65996456fbc9 100644 --- a/lib/libc/minimal/CMakeLists.txt +++ b/lib/libc/minimal/CMakeLists.txt @@ -33,7 +33,6 @@ zephyr_library_sources( if(CONFIG_MINIMAL_LIBC_TIME) zephyr_library_sources(source/time/gmtime.c) - zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK source/time/time.c) endif() zephyr_library_sources_ifdef(CONFIG_MINIMAL_LIBC_RAND source/stdlib/rand.c) diff --git a/lib/libc/minimal/Kconfig b/lib/libc/minimal/Kconfig index 30e0f0385fea..521f17b98fc1 100644 --- a/lib/libc/minimal/Kconfig +++ b/lib/libc/minimal/Kconfig @@ -66,6 +66,7 @@ config MINIMAL_LIBC_RAND config MINIMAL_LIBC_TIME bool "Time functions" + select COMMON_LIBC_TIME if POSIX_CLOCK default y help Enable time() and gmtime_r() for the minimal libc. From adde272ab7f2e3491d9744a62ec63377082c1160 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Fri, 24 Mar 2023 15:47:15 +0000 Subject: [PATCH 0775/1906] board: npcx: use templates for the openocd setup The NPCX boards use the normal openocd setup with custom --cmd-load and --cmd-verify. This can be done using the normal template instead of calling board_set_flasher_ifnset and board_set_debugger_ifnset directly Verified that the runner is indeed being called with the correct arguments after this commit. Signed-off-by: Fabio Baltieri --- boards/arm/npcx7m6fb_evb/board.cmake | 9 +++------ boards/arm/npcx9m6f_evb/board.cmake | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/boards/arm/npcx7m6fb_evb/board.cmake b/boards/arm/npcx7m6fb_evb/board.cmake index 3b45d5712a0d..51e7fd4c66fd 100644 --- a/boards/arm/npcx7m6fb_evb/board.cmake +++ b/boards/arm/npcx7m6fb_evb/board.cmake @@ -1,9 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 -board_set_flasher_ifnset(openocd) -board_set_debugger_ifnset(openocd) +board_runner_args(openocd --cmd-load "npcx_write_image") +board_runner_args(openocd --cmd-verify "npcx_verify_image") -board_finalize_runner_args(openocd - --cmd-load "npcx_write_image" - --cmd-verify "npcx_verify_image" - ) +include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake) diff --git a/boards/arm/npcx9m6f_evb/board.cmake b/boards/arm/npcx9m6f_evb/board.cmake index 3b45d5712a0d..51e7fd4c66fd 100644 --- a/boards/arm/npcx9m6f_evb/board.cmake +++ b/boards/arm/npcx9m6f_evb/board.cmake @@ -1,9 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 -board_set_flasher_ifnset(openocd) -board_set_debugger_ifnset(openocd) +board_runner_args(openocd --cmd-load "npcx_write_image") +board_runner_args(openocd --cmd-verify "npcx_verify_image") -board_finalize_runner_args(openocd - --cmd-load "npcx_write_image" - --cmd-verify "npcx_verify_image" - ) +include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake) From 1c0ade0051238f80abcf08b1e1b58c6704781374 Mon Sep 17 00:00:00 2001 From: Chris St John Date: Thu, 23 Mar 2023 15:35:08 +0000 Subject: [PATCH 0776/1906] Bluetooth: Audio: fix possible overflow in BASE LTV decode Consistently process BIS data, codec data and codec metadata. Range check count of data received so that buffer overflow cannot occur. Signed-off-by: Chris St John --- subsys/bluetooth/audio/bap_broadcast_sink.c | 32 ++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/audio/bap_broadcast_sink.c b/subsys/bluetooth/audio/bap_broadcast_sink.c index 160e78ac36ad..36b931663701 100644 --- a/subsys/bluetooth/audio/bap_broadcast_sink.c +++ b/subsys/bluetooth/audio/bap_broadcast_sink.c @@ -403,6 +403,11 @@ static bool net_buf_decode_bis_data(struct net_buf_simple *buf, struct bt_bap_ba while (ltv_buf.len != 0) { struct bt_codec_data *bis_codec_data; + if (bis->data_count >= ARRAY_SIZE(bis->data)) { + LOG_WRN("BIS data overflow; discarding"); + break; + } + bis_codec_data = &bis->data[bis->data_count]; if (!net_buf_decode_codec_ltv(<v_buf, @@ -411,6 +416,7 @@ static bool net_buf_decode_bis_data(struct net_buf_simple *buf, struct bt_bap_ba bis->data_count); return false; } + bis->data_count++; } } @@ -457,13 +463,22 @@ static bool net_buf_decode_subgroup(struct net_buf_simple *buf, * broadcasted BASEs */ while (ltv_buf.len != 0) { - struct bt_codec_data *codec_data = &codec->data[codec->data_count++]; + struct bt_codec_data *codec_data; + + if (codec->data_count >= ARRAY_SIZE(codec->data)) { + LOG_WRN("BIS codec data overflow; discarding"); + break; + } + + codec_data = &codec->data[codec->data_count]; if (!net_buf_decode_codec_ltv(<v_buf, codec_data)) { LOG_DBG("Failed to decode codec config data for entry %u", - codec->data_count - 1); + codec->data_count); return false; } + + codec->data_count++; } if (buf->len < sizeof(len)) { @@ -490,13 +505,22 @@ static bool net_buf_decode_subgroup(struct net_buf_simple *buf, * broadcasted BASEs */ while (ltv_buf.len != 0) { - struct bt_codec_data *metadata = &codec->meta[codec->meta_count++]; + struct bt_codec_data *metadata; + + if (codec->meta_count >= ARRAY_SIZE(codec->meta)) { + LOG_WRN("BIS codec metadata overflow; discarding"); + break; + } + + metadata = &codec->meta[codec->meta_count]; if (!net_buf_decode_codec_ltv(<v_buf, metadata)) { LOG_DBG("Failed to decode codec metadata for entry %u", - codec->meta_count - 1); + codec->meta_count); return false; } + + codec->meta_count++; } for (int i = 0; i < subgroup->bis_count; i++) { From 577d4b004fa6dfff5c2f14bd6186a292fe1c27c9 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 22 Mar 2023 10:14:07 +0100 Subject: [PATCH 0777/1906] bluetooth: tester: Add MESH and LE Audio overlays Initially I was hoping we can avoid dedicated overlays and have all config options enabled but it turned out that built-in services may affect other tests (especially core related like GAP and GATT). Signed-off-by: Szymon Janc --- tests/bluetooth/tester/overlay-le-audio.conf | 24 +++++++++ tests/bluetooth/tester/overlay-mesh.conf | 24 +++++++++ tests/bluetooth/tester/prj.conf | 55 +------------------- 3 files changed, 50 insertions(+), 53 deletions(-) create mode 100644 tests/bluetooth/tester/overlay-le-audio.conf create mode 100644 tests/bluetooth/tester/overlay-mesh.conf diff --git a/tests/bluetooth/tester/overlay-le-audio.conf b/tests/bluetooth/tester/overlay-le-audio.conf new file mode 100644 index 000000000000..ccb2e4aa97c5 --- /dev/null +++ b/tests/bluetooth/tester/overlay-le-audio.conf @@ -0,0 +1,24 @@ +CONFIG_BT_AUDIO=y +CONFIG_BT_BAP_UNICAST_SERVER=y + +# PACS +CONFIG_BT_PAC_SNK_LOC_WRITEABLE=y +CONFIG_BT_PAC_SRC_LOC_WRITEABLE=y + +# Volume Offset Control Service +CONFIG_BT_VOCS_MAX_INSTANCE_COUNT=2 +CONFIG_BT_VOCS_CLIENT_MAX_INSTANCE_COUNT=2 + +# Audio Input Control Service +CONFIG_BT_AICS_MAX_INSTANCE_COUNT=4 +CONFIG_BT_AICS_CLIENT_MAX_INSTANCE_COUNT=4 + +# Volume Control +CONFIG_BT_VCP_VOL_REND=y +CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT=2 +CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT=2 +CONFIG_BT_VCP_VOL_REND_LOG_LEVEL_DBG=y + +# IAS +CONFIG_BT_IAS=y +CONFIG_BT_IAS_CLIENT=y diff --git a/tests/bluetooth/tester/overlay-mesh.conf b/tests/bluetooth/tester/overlay-mesh.conf new file mode 100644 index 000000000000..963b864ba2b9 --- /dev/null +++ b/tests/bluetooth/tester/overlay-mesh.conf @@ -0,0 +1,24 @@ +CONFIG_BT_MESH=y +CONFIG_BT_MESH_RELAY=y +CONFIG_BT_MESH_PB_ADV=y +CONFIG_BT_MESH_PB_GATT=y +CONFIG_BT_MESH_LOW_POWER=y +CONFIG_BT_MESH_LPN_AUTO=n +CONFIG_BT_MESH_GATT_PROXY=y +CONFIG_BT_MESH_LABEL_COUNT=2 +CONFIG_BT_MESH_SUBNET_COUNT=2 +CONFIG_BT_MESH_MODEL_GROUP_COUNT=2 +CONFIG_BT_MESH_APP_KEY_COUNT=4 +CONFIG_BT_MESH_IV_UPDATE_TEST=y +CONFIG_BT_MESH_CFG_CLI=y +CONFIG_BT_MESH_HEALTH_CLI=y +CONFIG_BT_MESH_FRIEND=y +CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=32 +CONFIG_BT_MESH_RX_SEG_MAX=13 +CONFIG_BT_MESH_TX_SEG_MSG_COUNT=3 +CONFIG_BT_MESH_LPN_POLL_TIMEOUT=100 +CONFIG_BT_MESH_PROVISIONER=y +CONFIG_BT_MESH_CDB=y +CONFIG_BT_MESH_CDB_NODE_COUNT=3 +CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y +CONFIG_BT_MESH_MSG_CACHE_SIZE=10 diff --git a/tests/bluetooth/tester/prj.conf b/tests/bluetooth/tester/prj.conf index ef4365079a34..35abe022d218 100644 --- a/tests/bluetooth/tester/prj.conf +++ b/tests/bluetooth/tester/prj.conf @@ -1,5 +1,6 @@ CONFIG_TEST=y CONFIG_UART_PIPE=y +CONFIG_UART_CONSOLE=n CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 CONFIG_BT=y @@ -28,60 +29,8 @@ CONFIG_BT_MAX_CONN=2 CONFIG_BT_MAX_PAIRED=2 CONFIG_BT_GATT_NOTIFY_MULTIPLE=y CONFIG_BT_ATT_RETRY_ON_SEC_ERR=n - -CONFIG_BT_MESH=y -CONFIG_BT_MESH_RELAY=y -CONFIG_BT_MESH_PB_ADV=y -CONFIG_BT_MESH_PB_GATT=y -CONFIG_BT_MESH_LOW_POWER=y -CONFIG_BT_MESH_LPN_AUTO=n -CONFIG_BT_MESH_GATT_PROXY=y -CONFIG_BT_MESH_LABEL_COUNT=2 -CONFIG_BT_MESH_SUBNET_COUNT=2 -CONFIG_BT_MESH_MODEL_GROUP_COUNT=2 -CONFIG_BT_MESH_APP_KEY_COUNT=4 -CONFIG_BT_MESH_IV_UPDATE_TEST=y -CONFIG_BT_MESH_CFG_CLI=y -CONFIG_BT_MESH_HEALTH_CLI=y -CONFIG_BT_MESH_FRIEND=y -CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=32 -CONFIG_BT_MESH_RX_SEG_MAX=13 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=3 -CONFIG_BT_MESH_LPN_POLL_TIMEOUT=100 -CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_CDB=y -CONFIG_BT_MESH_CDB_NODE_COUNT=3 -CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y -CONFIG_BT_MESH_MSG_CACHE_SIZE=10 +CONFIG_BT_GATT_DYNAMIC_DB=y CONFIG_BT_TINYCRYPT_ECC=y CONFIG_BT_TESTING=y CONFIG_UTF8=y - -CONFIG_UART_CONSOLE=n - -# LE Audio Section -CONFIG_BT_AUDIO=y -CONFIG_BT_BAP_UNICAST_SERVER=y - -# PACS -CONFIG_BT_PAC_SNK_LOC_WRITEABLE=y -CONFIG_BT_PAC_SRC_LOC_WRITEABLE=y - -# Volume Offset Control Service -CONFIG_BT_VOCS_MAX_INSTANCE_COUNT=2 -CONFIG_BT_VOCS_CLIENT_MAX_INSTANCE_COUNT=2 - -# Audio Input Control Service -CONFIG_BT_AICS_MAX_INSTANCE_COUNT=4 -CONFIG_BT_AICS_CLIENT_MAX_INSTANCE_COUNT=4 - -#Volume Control -CONFIG_BT_VCP_VOL_REND=y -CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT=2 -CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT=2 -CONFIG_BT_VCP_VOL_REND_LOG_LEVEL_DBG=y - -# IAS -CONFIG_BT_IAS=y -CONFIG_BT_IAS_CLIENT=y From 7073da025723f0a56689390d380ebfc3d06f99bc Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 17 Mar 2023 12:14:58 +0100 Subject: [PATCH 0778/1906] drivers: can: common: include sync segment in timing calculation Always include the SYNC segment of 1 time quanta when calculating ts1 and ts2. Fixes: #55919 Signed-off-by: Henrik Brix Andersen --- drivers/can/can_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/can/can_common.c b/drivers/can/can_common.c index 8271c99acd05..16fa51a01426 100644 --- a/drivers/can/can_common.c +++ b/drivers/can/can_common.c @@ -99,7 +99,7 @@ static int update_sampling_pnt(uint32_t ts, uint32_t sp, struct can_timing *res, } } else if (ts1 < ts1_min) { ts1 = ts1_min; - ts2 = ts - ts1; + ts2 = ts - CAN_SYNC_SEG - ts1; if (ts2 < min->phase_seg2) { return -1; } From ffefc6441b14ec9d1301c5a1671569c13ec74c8e Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 17 Mar 2023 12:16:10 +0100 Subject: [PATCH 0779/1906] drivers: can: common: respect the range limits of phase_seg1 Respect the range limits of phase_seg1 when attempting to distribute ts1 between prop_seg and phase_seg1. Even distribution may not be possible if the allowed ranges of prop_seg and phase_seg1 are not equal. Fixes: #55919 Signed-off-by: Henrik Brix Andersen --- drivers/can/can_common.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/can/can_common.c b/drivers/can/can_common.c index 16fa51a01426..f6c02ccedd0d 100644 --- a/drivers/can/can_common.c +++ b/drivers/can/can_common.c @@ -105,9 +105,21 @@ static int update_sampling_pnt(uint32_t ts, uint32_t sp, struct can_timing *res, } } + res->phase_seg2 = ts2; + + /* Attempt to distribute ts1 evenly between prop_seq and phase_seg1 */ res->prop_seg = CLAMP(ts1 / 2, min->prop_seg, max->prop_seg); res->phase_seg1 = ts1 - res->prop_seg; - res->phase_seg2 = ts2; + + if (res->phase_seg1 > max->phase_seg1) { + /* Even ts1 distribution not possible, decrease phase_seg1 */ + res->phase_seg1 = max->phase_seg1; + res->prop_seg = ts1 - res->phase_seg1; + } else if (res->phase_seg1 < min->phase_seg1) { + /* Even ts1 distribution not possible, increase phase_seg1 */ + res->phase_seg1 = min->phase_seg1; + res->prop_seg = ts1 - res->phase_seg1; + } sp_calc = (CAN_SYNC_SEG + ts1) * 1000 / ts; From 718099607e3d45b8e2372f312640448c68a07cbd Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Mon, 20 Mar 2023 15:14:00 +0100 Subject: [PATCH 0780/1906] drivers: can: common: document sample point calculation function Add documentation for the update_sampling_pnt() function and rename a few internal variables to improve readability. Signed-off-by: Henrik Brix Andersen --- drivers/can/can_common.c | 90 +++++++++++++++++++++++++++------------- 1 file changed, 62 insertions(+), 28 deletions(-) diff --git a/drivers/can/can_common.c b/drivers/can/can_common.c index f6c02ccedd0d..c7902ee9d201 100644 --- a/drivers/can/can_common.c +++ b/drivers/can/can_common.c @@ -78,52 +78,86 @@ int z_impl_can_add_rx_filter_msgq(const struct device *dev, struct k_msgq *msgq, return api->add_rx_filter(dev, can_msgq_put, msgq, filter); } -static int update_sampling_pnt(uint32_t ts, uint32_t sp, struct can_timing *res, +/** + * @brief Update the timing given a total number of time quanta and a sample point. + * + * @code{.text} + * + * +---------------------------------------------------+ + * | Nominal bit time in time quanta (total_tq) | + * +--------------+----------+------------+------------+ + * | sync_seg | prop_seg | phase_seg1 | phase_seg2 | + * +--------------+----------+------------+------------+ + * | CAN_SYNG_SEG | tseg1 | tseg2 | + * +--------------+-----------------------+------------+ + * ^ + * sample_pnt + * @endcode + * + * @see @a can_timing + * + * @param total_tq Total number of time quanta. + * @param sample_pnt Sampling point in permill of the entire bit time. + * @param[out] res Result is written into the @a can_timing struct provided. + * @param max Maximum timing parameters values. + * @param min Minimum timing parameters values. + * @return Absolute sample point error. + */ +static int update_sampling_pnt(uint32_t total_tq, uint32_t sample_pnt, + struct can_timing *res, const struct can_timing *max, const struct can_timing *min) { - uint16_t ts1_max = max->phase_seg1 + max->prop_seg; - uint16_t ts1_min = min->phase_seg1 + min->prop_seg; - uint32_t sp_calc; - uint16_t ts1, ts2; - - ts2 = ts - (ts * sp) / 1000; - ts2 = CLAMP(ts2, min->phase_seg2, max->phase_seg2); - ts1 = ts - CAN_SYNC_SEG - ts2; - - if (ts1 > ts1_max) { - ts1 = ts1_max; - ts2 = ts - CAN_SYNC_SEG - ts1; - if (ts2 > max->phase_seg2) { + uint16_t tseg1_max = max->phase_seg1 + max->prop_seg; + uint16_t tseg1_min = min->phase_seg1 + min->prop_seg; + uint32_t sample_pnt_res; + uint16_t tseg1, tseg2; + + /* Calculate number of time quanta in tseg2 for given sample point */ + tseg2 = total_tq - (total_tq * sample_pnt) / 1000; + tseg2 = CLAMP(tseg2, min->phase_seg2, max->phase_seg2); + + /* Calculate number of time quanta in tseg1 */ + tseg1 = total_tq - CAN_SYNC_SEG - tseg2; + if (tseg1 > tseg1_max) { + /* Sample point location must be decreased */ + tseg1 = tseg1_max; + tseg2 = total_tq - CAN_SYNC_SEG - tseg1; + if (tseg2 > max->phase_seg2) { return -1; } - } else if (ts1 < ts1_min) { - ts1 = ts1_min; - ts2 = ts - CAN_SYNC_SEG - ts1; - if (ts2 < min->phase_seg2) { + } else if (tseg1 < tseg1_min) { + /* Sample point location must be increased */ + tseg1 = tseg1_min; + tseg2 = total_tq - CAN_SYNC_SEG - tseg1; + if (tseg2 < min->phase_seg2) { return -1; } } - res->phase_seg2 = ts2; + res->phase_seg2 = tseg2; - /* Attempt to distribute ts1 evenly between prop_seq and phase_seg1 */ - res->prop_seg = CLAMP(ts1 / 2, min->prop_seg, max->prop_seg); - res->phase_seg1 = ts1 - res->prop_seg; + /* Attempt to distribute tseg1 evenly between prop_seq and phase_seg1 */ + res->prop_seg = CLAMP(tseg1 / 2, min->prop_seg, max->prop_seg); + res->phase_seg1 = tseg1 - res->prop_seg; if (res->phase_seg1 > max->phase_seg1) { - /* Even ts1 distribution not possible, decrease phase_seg1 */ + /* Even tseg1 distribution not possible, decrease phase_seg1 */ res->phase_seg1 = max->phase_seg1; - res->prop_seg = ts1 - res->phase_seg1; + res->prop_seg = tseg1 - res->phase_seg1; } else if (res->phase_seg1 < min->phase_seg1) { - /* Even ts1 distribution not possible, increase phase_seg1 */ + /* Even tseg1 distribution not possible, increase phase_seg1 */ res->phase_seg1 = min->phase_seg1; - res->prop_seg = ts1 - res->phase_seg1; + res->prop_seg = tseg1 - res->phase_seg1; } - sp_calc = (CAN_SYNC_SEG + ts1) * 1000 / ts; + /* Calculate the resulting sample point */ + sample_pnt_res = (CAN_SYNC_SEG + tseg1) * 1000 / total_tq; - return sp_calc > sp ? sp_calc - sp : sp - sp_calc; + /* Return the absolute sample point error */ + return sample_pnt_res > sample_pnt ? + sample_pnt_res - sample_pnt : + sample_pnt - sample_pnt_res; } /* Internal function to do the actual calculation */ From 6180f9679974d5c9f8ba8cb390c5693b96c6f2f7 Mon Sep 17 00:00:00 2001 From: Fabian Blatz Date: Wed, 15 Mar 2023 11:01:54 +0100 Subject: [PATCH 0781/1906] serial: Add driver for emulated UART The emulated UART controller will aid in automated integration testing. Signed-off-by: Fabian Blatz --- drivers/serial/CMakeLists.txt | 1 + drivers/serial/Kconfig | 2 + drivers/serial/Kconfig.emul | 13 ++ drivers/serial/uart_emul.c | 192 ++++++++++++++++++++++ dts/bindings/serial/zephyr,uart-emul.yaml | 27 +++ include/zephyr/drivers/serial/uart_emul.h | 89 ++++++++++ 6 files changed, 324 insertions(+) create mode 100644 drivers/serial/Kconfig.emul create mode 100644 drivers/serial/uart_emul.c create mode 100644 dts/bindings/serial/zephyr,uart-emul.yaml create mode 100644 include/zephyr/drivers/serial/uart_emul.h diff --git a/drivers/serial/CMakeLists.txt b/drivers/serial/CMakeLists.txt index 863e16ea2b13..eab1819b9905 100644 --- a/drivers/serial/CMakeLists.txt +++ b/drivers/serial/CMakeLists.txt @@ -57,6 +57,7 @@ zephyr_library_sources_ifdef(CONFIG_UART_NXP_S32_LINFLEXD uart_nxp_s32_linflexd. zephyr_library_sources_ifdef(CONFIG_UART_CDNS uart_cdns.c) zephyr_library_sources_ifdef(CONFIG_UART_OPENTITAN uart_opentitan.c) zephyr_library_sources_ifdef(CONFIG_UART_HOSTLINK uart_hostlink.c) +zephyr_library_sources_ifdef(CONFIG_UART_EMUL uart_emul.c) zephyr_library_sources_ifdef(CONFIG_USERSPACE uart_handlers.c) diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index 8dd7147a22d7..e3657a6eba0e 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig @@ -216,4 +216,6 @@ source "drivers/serial/Kconfig.altera" source "drivers/serial/Kconfig.hostlink" +source "drivers/serial/Kconfig.emul" + endif # SERIAL diff --git a/drivers/serial/Kconfig.emul b/drivers/serial/Kconfig.emul new file mode 100644 index 000000000000..67134b9485c8 --- /dev/null +++ b/drivers/serial/Kconfig.emul @@ -0,0 +1,13 @@ +# Emulated UART configuration options + +# Copyright (c) 2023 Fabian Blatz +# SPDX-License-Identifier: Apache-2.0 + +config UART_EMUL + bool "Emulated UART driver [EXPERIMENTAL]" + default y + depends on DT_HAS_ZEPHYR_UART_EMUL_ENABLED + select RING_BUFFER + select EXPERIMENTAL + help + Enable the emulated UART driver. diff --git a/drivers/serial/uart_emul.c b/drivers/serial/uart_emul.c new file mode 100644 index 000000000000..90a1d6a9e773 --- /dev/null +++ b/drivers/serial/uart_emul.c @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2023 Fabian Blatz + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT zephyr_uart_emul + +#include +#include +#include +#include +#include + +#include +LOG_MODULE_REGISTER(uart_emul, CONFIG_UART_LOG_LEVEL); + +struct uart_emul_config { + bool loopback; +}; + +/* Device run time data */ +struct uart_emul_data { + struct uart_config cfg; + + struct ring_buf *rx_rb; + struct k_spinlock rx_lock; + + uart_emul_callback_tx_data_ready_t tx_data_ready_cb; + void *user_data; + + struct ring_buf *tx_rb; + struct k_spinlock tx_lock; +}; + +int uart_emul_poll_in(const struct device *dev, unsigned char *p_char) +{ + struct uart_emul_data *drv_data = dev->data; + k_spinlock_key_t key; + uint32_t read; + + key = k_spin_lock(&drv_data->rx_lock); + read = ring_buf_get(drv_data->rx_rb, p_char, 1); + k_spin_unlock(&drv_data->rx_lock, key); + + if (!read) { + LOG_DBG("Rx buffer is empty"); + return -1; + } + + return 0; +} + +void uart_emul_poll_out(const struct device *dev, unsigned char out_char) +{ + struct uart_emul_data *drv_data = dev->data; + const struct uart_emul_config *drv_cfg = dev->config; + k_spinlock_key_t key; + uint32_t written; + + key = k_spin_lock(&drv_data->tx_lock); + written = ring_buf_put(drv_data->tx_rb, &out_char, 1); + k_spin_unlock(&drv_data->tx_lock, key); + + if (!written) { + LOG_DBG("Tx buffer is full"); + return; + } + + if (drv_cfg->loopback) { + uart_emul_put_rx_data(dev, &out_char, 1); + } + if (drv_data->tx_data_ready_cb) { + (drv_data->tx_data_ready_cb)(dev, ring_buf_size_get(drv_data->tx_rb), + drv_data->user_data); + } +} + +int uart_emul_err_check(const struct device *dev) +{ + return 0; +} + +int uart_emul_configure(const struct device *dev, const struct uart_config *cfg) +{ + struct uart_emul_data *drv_data = dev->data; + + memcpy(&drv_data->cfg, cfg, sizeof(struct uart_config)); + return 0; +} + +int uart_emul_config_get(const struct device *dev, struct uart_config *cfg) +{ + const struct uart_emul_data *drv_data = dev->data; + + memcpy(cfg, &drv_data->cfg, sizeof(struct uart_config)); + return 0; +} + +static const struct uart_driver_api uart_emul_api = { + .poll_in = uart_emul_poll_in, + .poll_out = uart_emul_poll_out, + .config_get = uart_emul_config_get, + .configure = uart_emul_configure, + .err_check = uart_emul_err_check +}; + +void uart_emul_callback_tx_data_ready_set(const struct device *dev, + uart_emul_callback_tx_data_ready_t cb, void *user_data) +{ + struct uart_emul_data *drv_data = dev->data; + + drv_data->tx_data_ready_cb = cb; + drv_data->user_data = user_data; +} + +uint32_t uart_emul_put_rx_data(const struct device *dev, uint8_t *data, size_t size) +{ + struct uart_emul_data *drv_data = dev->data; + k_spinlock_key_t key; + uint32_t count; + + key = k_spin_lock(&drv_data->rx_lock); + count = ring_buf_put(drv_data->rx_rb, data, size); + k_spin_unlock(&drv_data->rx_lock, key); + return count; +} + +uint32_t uart_emul_get_tx_data(const struct device *dev, uint8_t *data, size_t size) +{ + struct uart_emul_data *drv_data = dev->data; + k_spinlock_key_t key; + uint32_t count; + + key = k_spin_lock(&drv_data->tx_lock); + count = ring_buf_get(drv_data->tx_rb, data, size); + k_spin_unlock(&drv_data->tx_lock, key); + return count; +} + +uint32_t uart_emul_flush_rx_data(const struct device *dev) +{ + struct uart_emul_data *drv_data = dev->data; + k_spinlock_key_t key; + uint32_t count; + + key = k_spin_lock(&drv_data->rx_lock); + count = ring_buf_size_get(drv_data->rx_rb); + ring_buf_reset(drv_data->rx_rb); + k_spin_unlock(&drv_data->rx_lock, key); + return count; +} + +uint32_t uart_emul_flush_tx_data(const struct device *dev) +{ + struct uart_emul_data *drv_data = dev->data; + k_spinlock_key_t key; + uint32_t count; + + key = k_spin_lock(&drv_data->tx_lock); + count = ring_buf_size_get(drv_data->tx_rb); + ring_buf_reset(drv_data->tx_rb); + k_spin_unlock(&drv_data->tx_lock, key); + return count; +} + +static int uart_emul_init(const struct device *dev) +{ + return 0; +} + +#define UART_EMUL_RX_FIFO_SIZE(inst) (DT_INST_PROP(inst, rx_fifo_size)) +#define UART_EMUL_TX_FIFO_SIZE(inst) (DT_INST_PROP(inst, tx_fifo_size)) + +#define DEFINE_UART_EMUL(inst) \ + \ + RING_BUF_DECLARE(uart_emul_##inst##_rx_rb, UART_EMUL_RX_FIFO_SIZE(inst)); \ + RING_BUF_DECLARE(uart_emul_##inst##_tx_rb, UART_EMUL_TX_FIFO_SIZE(inst)); \ + \ + static struct uart_emul_config uart_emul_cfg_##inst = { \ + .loopback = DT_INST_PROP(inst, loopback), \ + }; \ + static struct uart_emul_data uart_emul_data_##inst = { \ + .rx_rb = &uart_emul_##inst##_rx_rb, \ + .tx_rb = &uart_emul_##inst##_tx_rb, \ + }; \ + \ + DEVICE_DT_INST_DEFINE(inst, uart_emul_init, NULL, &uart_emul_data_##inst, \ + &uart_emul_cfg_##inst, PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY, \ + &uart_emul_api); + +DT_INST_FOREACH_STATUS_OKAY(DEFINE_UART_EMUL) diff --git a/dts/bindings/serial/zephyr,uart-emul.yaml b/dts/bindings/serial/zephyr,uart-emul.yaml new file mode 100644 index 000000000000..d3d50dc9e937 --- /dev/null +++ b/dts/bindings/serial/zephyr,uart-emul.yaml @@ -0,0 +1,27 @@ +# Copyright (c) 2023, Fabian Blatz +# SPDX-License-Identifier: Apache-2.0 + +description: UART Emulator + +compatible: "zephyr,uart-emul" + +include: uart-controller.yaml + +properties: + tx-fifo-size: + type: int + default: 256 + description: | + Size of the virtual UART TX FIFO + + rx-fifo-size: + type: int + default: 256 + description: | + Size of the virtual UART RX FIFO + + loopback: + type: boolean + description: | + Connects TX to RX internally creating a loop back connection. Useful + for testing. diff --git a/include/zephyr/drivers/serial/uart_emul.h b/include/zephyr/drivers/serial/uart_emul.h new file mode 100644 index 000000000000..f2d59c0705c3 --- /dev/null +++ b/include/zephyr/drivers/serial/uart_emul.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2023 Fabian Blatz + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Backend API for emulated UART + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_SERIAL_UART_EMUL_H_ +#define ZEPHYR_INCLUDE_DRIVERS_SERIAL_UART_EMUL_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Define the application callback function signature for + * uart_emul_callback_tx_data_ready_set() function. + * + * @param dev UART device instance + * @param size Number of available bytes in TX buffer + * @param user_data Arbitrary user data + */ +typedef void (*uart_emul_callback_tx_data_ready_t)(const struct device *dev, size_t size, + void *user_data); + +/** + * @brief Set the TX data ready callback + * + * This sets up the callback that is called every time data + * was appended to the TX buffer. + * + * @param dev The emulated UART device instance + * @param cb Pointer to the callback function + * @param user_data Data to pass to callback function + */ +void uart_emul_callback_tx_data_ready_set(const struct device *dev, + uart_emul_callback_tx_data_ready_t cb, void *user_data); + +/** + * @brief Write (copy) data to RX buffer + * + * @param dev The emulated UART device instance + * @param data The data to append + * @param size Number of bytes to append + * + * @return Number of bytes appended + */ +uint32_t uart_emul_put_rx_data(const struct device *dev, uint8_t *data, size_t size); + +/** + * @brief Read data from TX buffer + * + * @param dev The emulated UART device instance + * @param data The address of the output buffer + * @param size Number of bytes to read + * + * @return Number of bytes written to the output buffer + */ +uint32_t uart_emul_get_tx_data(const struct device *dev, uint8_t *data, size_t size); + +/** + * @brief Clear RX buffer content + * + * @param dev The emulated UART device instance + * + * @return Number of cleared bytes + */ +uint32_t uart_emul_flush_rx_data(const struct device *dev); + +/** + * @brief Clear TX buffer content + * + * @param dev The emulated UART device instance + * + * @return Number of cleared bytes + */ +uint32_t uart_emul_flush_tx_data(const struct device *dev); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_DRIVERS_SERIAL_UART_EMUL_H_ */ From 1a132fabc01abb3cfc01621243b0f5ea7de71866 Mon Sep 17 00:00:00 2001 From: Fabian Blatz Date: Wed, 15 Mar 2023 11:03:36 +0100 Subject: [PATCH 0782/1906] tests: drivers: uart: add uart_emul test Add test of the uart emulator polling API. Signed-off-by: Fabian Blatz --- tests/drivers/uart/uart_emul/CMakeLists.txt | 9 +++ .../uart/uart_emul/boards/qemu_x86.overlay | 15 ++++ tests/drivers/uart/uart_emul/prj.conf | 3 + tests/drivers/uart/uart_emul/src/main.c | 78 +++++++++++++++++++ tests/drivers/uart/uart_emul/testcase.yaml | 7 ++ 5 files changed, 112 insertions(+) create mode 100644 tests/drivers/uart/uart_emul/CMakeLists.txt create mode 100644 tests/drivers/uart/uart_emul/boards/qemu_x86.overlay create mode 100644 tests/drivers/uart/uart_emul/prj.conf create mode 100644 tests/drivers/uart/uart_emul/src/main.c create mode 100644 tests/drivers/uart/uart_emul/testcase.yaml diff --git a/tests/drivers/uart/uart_emul/CMakeLists.txt b/tests/drivers/uart/uart_emul/CMakeLists.txt new file mode 100644 index 000000000000..78fc07f2383b --- /dev/null +++ b/tests/drivers/uart/uart_emul/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(uart_emul) + +target_sources(app PRIVATE + src/main.c + ) diff --git a/tests/drivers/uart/uart_emul/boards/qemu_x86.overlay b/tests/drivers/uart/uart_emul/boards/qemu_x86.overlay new file mode 100644 index 000000000000..93e580fd41ae --- /dev/null +++ b/tests/drivers/uart/uart_emul/boards/qemu_x86.overlay @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2023 Fabian Blatz + * + * SPDX-License-Identifier: Apache-2.0 +*/ + +/ { + euart0: uart-emul { + compatible = "zephyr,uart-emul"; + status = "okay"; + current-speed = <0>; + rx-fifo-size = <256>; + tx-fifo-size = <256>; + }; +}; diff --git a/tests/drivers/uart/uart_emul/prj.conf b/tests/drivers/uart/uart_emul/prj.conf new file mode 100644 index 000000000000..99676d377b45 --- /dev/null +++ b/tests/drivers/uart/uart_emul/prj.conf @@ -0,0 +1,3 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_SERIAL=y diff --git a/tests/drivers/uart/uart_emul/src/main.c b/tests/drivers/uart/uart_emul/src/main.c new file mode 100644 index 000000000000..5e698d0b1e96 --- /dev/null +++ b/tests/drivers/uart/uart_emul/src/main.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023 Fabian Blatz + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#define EMUL_UART_NODE DT_NODELABEL(euart0) +#define EMUL_UART_RX_FIFO_SIZE DT_PROP(EMUL_UART_NODE, rx_fifo_size) +#define EMUL_UART_TX_FIFO_SIZE DT_PROP(EMUL_UART_NODE, tx_fifo_size) +#define SAMPLE_DATA_SIZE MIN(EMUL_UART_RX_FIFO_SIZE, EMUL_UART_TX_FIFO_SIZE) + +struct uart_emul_fixture { + const struct device *dev; + uint8_t sample_data[SAMPLE_DATA_SIZE]; +}; + +static void *uart_emul_setup(void) +{ + static struct uart_emul_fixture fixture = {.dev = DEVICE_DT_GET(EMUL_UART_NODE)}; + + for (size_t i = 0; i < SAMPLE_DATA_SIZE; i++) { + fixture.sample_data[i] = i; + } + + zassert_not_null(fixture.dev); + return &fixture; +} + +static void uart_emul_before(void *f) +{ + struct uart_emul_fixture *fixture = f; + + uart_emul_flush_rx_data(fixture->dev); + uart_emul_flush_tx_data(fixture->dev); +} + +ZTEST_F(uart_emul, test_polling_out) +{ + uint8_t tx_content[SAMPLE_DATA_SIZE] = {0}; + size_t tx_len; + + for (size_t i = 0; i < SAMPLE_DATA_SIZE; i++) { + uart_poll_out(fixture->dev, fixture->sample_data[i]); + } + + tx_len = uart_emul_get_tx_data(fixture->dev, tx_content, sizeof(tx_content)); + zassert_equal(tx_len, SAMPLE_DATA_SIZE, "TX buffer length does not match"); + zassert_mem_equal(tx_content, fixture->sample_data, SAMPLE_DATA_SIZE); + + /* No more data in TX buffer */ + tx_len = uart_emul_get_tx_data(fixture->dev, tx_content, sizeof(tx_content)); + zassert_equal(tx_len, 0, "TX buffer should be empty"); +} + +ZTEST_F(uart_emul, test_polling_in) +{ + uint8_t rx_content[SAMPLE_DATA_SIZE] = {0}; + int rc; + + uart_emul_put_rx_data(fixture->dev, fixture->sample_data, SAMPLE_DATA_SIZE); + + for (size_t i = 0; i < SAMPLE_DATA_SIZE; i++) { + rc = uart_poll_in(fixture->dev, &rx_content[i]); + zassert_equal(rc, 0, "RX buffer should contain data"); + } + zassert_mem_equal(rx_content, fixture->sample_data, SAMPLE_DATA_SIZE); + + /* No more data in RX buffer */ + rc = uart_poll_in(fixture->dev, &rx_content[0]); + zassert_equal(rc, -1, "RX buffer should be empty"); +} + +ZTEST_SUITE(uart_emul, NULL, uart_emul_setup, uart_emul_before, NULL, NULL); diff --git a/tests/drivers/uart/uart_emul/testcase.yaml b/tests/drivers/uart/uart_emul/testcase.yaml new file mode 100644 index 000000000000..26403170cddf --- /dev/null +++ b/tests/drivers/uart/uart_emul/testcase.yaml @@ -0,0 +1,7 @@ +common: + tags: drivers uart + harness: ztest + depends_on: uart_emul +tests: + drivers.uart_emul.polling: + platform_allow: qemu_x86 From 9d50b143ae7e4c7a06cbd5b11f199bcd8ce19d15 Mon Sep 17 00:00:00 2001 From: Alexander Mihajlovic Date: Wed, 1 Mar 2023 21:57:50 +0100 Subject: [PATCH 0783/1906] dts: bindings: Add Pmod connector GPIO nexus Add a GPIO nexus binding for Pmod interface connectors. This commit also includes a header file with macros that map signal names in the Pmod specification to the corresponding indices in the GPIO nexus, meant for use in devicetree files. Signed-off-by: Alexander Mihajlovic --- dts/bindings/gpio/digilent,pmod.yaml | 36 +++ .../zephyr/dt-bindings/gpio/digilent-pmod.h | 227 ++++++++++++++++++ 2 files changed, 263 insertions(+) create mode 100644 dts/bindings/gpio/digilent,pmod.yaml create mode 100644 include/zephyr/dt-bindings/gpio/digilent-pmod.h diff --git a/dts/bindings/gpio/digilent,pmod.yaml b/dts/bindings/gpio/digilent,pmod.yaml new file mode 100644 index 000000000000..5753b638f82a --- /dev/null +++ b/dts/bindings/gpio/digilent,pmod.yaml @@ -0,0 +1,36 @@ +# Copyright (c) 2023 Elektronikutvecklingsbyrån EUB AB +# SPDX-License-Identifier: Apache-2.0 + +description: | + GPIO pins exposed on a Digilent Pmod interface. + + This binding provides a nexus mapping for 8 pins where parent pins 0 + through 3 correspond to IO1 through IO4, and parent pins 4 through 7 + correspond to IO5 through IO8, as depicted below for a 12-pin connector. + + 12-pin Pmod interface: + + 0 IO1 IO5 4 + 1 IO2 IO6 5 + 2 IO3 IO7 6 + 3 IO4 IO8 7 + - GND GND - + - VDD VDD - + + This binding can also be used with the 6-pin Pmod connector variant which + is a proper subset of the 12-pin connector. In that case parent pins 4 + through 7 are omitted from the GPIO nexus node, resulting in a mapping + as depicted below. + + 6-pin Pmod interface: + + 0 IO1 + 1 IO2 + 2 IO3 + 3 IO4 + - GND + - VDD + +compatible: "digilent,pmod" + +include: [gpio-nexus.yaml, base.yaml] diff --git a/include/zephyr/dt-bindings/gpio/digilent-pmod.h b/include/zephyr/dt-bindings/gpio/digilent-pmod.h new file mode 100644 index 000000000000..38cd9099b77f --- /dev/null +++ b/include/zephyr/dt-bindings/gpio/digilent-pmod.h @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2023 Elektronikutvecklingsbyrån EUB AB + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Pmod GPIO nexus signal index definitions + * + * Defines meant to be used in conjunction with the "digilent,pmod" + * GPIO nexus mapping. + * + * Example usage: + * + * @code{.dts} + * &spi1 { + * cs-gpios = <&pmod0 PMOD_SPI_CS GPIO_ACTIVE_LOW>; + * + * example_device: example-dev@0 { + * compatible = "vnd,spi-device"; + * reg = <0>; + * }; + * }; + * @endcode + */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_DIGILENT_PMOD_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_DIGILENT_PMOD_H_ + +/** + * For reference see the Pmod interface specification: + * https://digilent.com/reference/_media/reference/pmod/pmod-interface-specification-1_2_0.pdf + */ + +/* GPIO */ + +/** + * @brief IO[n] signal on a Pmod GPIO nexus node following + * Pmod Interface Type 1 or 1A (GPIO or expanded GPIO) + * + * The Pmod GPIO nexus maps pin indexes 0..7 to IO1..IO8. + */ +#define PMOD_IO(n) ((n) - 1) + +/* SPI */ + +/** + * @brief SPI CS signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 2 (SPI) peripherals. + */ +#define PMOD_SPI_CS PMOD_IO(1) + +/** + * @brief SPI MOSI signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 2 (SPI) peripherals. + */ +#define PMOD_SPI_MOSI PMOD_IO(2) + +/** + * @brief SPI MISO signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 2 (SPI) peripherals. + */ +#define PMOD_SPI_MISO PMOD_IO(3) + +/** + * @brief SPI SCK signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 2 (SPI) peripherals. + */ +#define PMOD_SPI_SCK PMOD_IO(4) + +/* Expanded SPI */ + +/** + * @brief SPI CS signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 2A (expanded SPI) peripherals. + */ +#define PMOD_EXP_SPI_CS PMOD_IO(1) + +/** + * @brief SPI MOSI signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 2A (expanded SPI) peripherals. + */ +#define PMOD_EXP_SPI_MOSI PMOD_IO(2) + +/** + * @brief SPI MISO signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 2A (expanded SPI) peripherals. + */ +#define PMOD_EXP_SPI_MISO PMOD_IO(3) + +/** + * @brief SPI SCK signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 2A (expanded SPI) peripherals. + */ +#define PMOD_EXP_SPI_SCK PMOD_IO(4) + +/** + * @brief INT alternate signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 2A (expanded SPI) peripherals. + */ +#define PMOD_EXP_SPI_INT PMOD_IO(5) + +/** + * @brief RESET alternate signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 2A (expanded SPI) peripherals. + */ +#define PMOD_EXP_SPI_RESET PMOD_IO(6) + +/** + * @brief SPI CS2 alternate signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 2A (expanded SPI) peripherals. + */ +#define PMOD_EXP_SPI_CS2 PMOD_IO(7) + +/** + * @brief SPI CS3 alternate signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 2A (expanded SPI) peripherals. + */ +#define PMOD_EXP_SPI_CS3 PMOD_IO(8) + +/* Expanded UART */ + +/** + * @brief INT alternate signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 3A (expanded UART) peripherals. + */ +#define PMOD_EXP_UART_INT PMOD_IO(5) + +/** + * @brief RESET alternate signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 3A (expanded UART) peripherals. + */ +#define PMOD_EXP_UART_RESET PMOD_IO(6) + +/* H-bridge */ + +/** + * @brief DIR signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 4 (H-bridge) peripherals. + */ +#define PMOD_HBRIDGE_DIR PMOD_IO(1) + +/** + * @brief EN signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 4 (H-bridge) peripherals. + */ +#define PMOD_HBRIDGE_EN PMOD_IO(2) + +/* Dual H-bridge */ + +/** + * @brief DIR1 signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 5 (dual H-bridge) peripherals. + */ +#define PMOD_DUAL_HBRIDGE_DIR1 PMOD_IO(1) + +/** + * @brief EN1 signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 5 (dual H-bridge) peripherals. + */ +#define PMOD_DUAL_HBRIDGE_EN1 PMOD_IO(2) + +/** + * @brief DIR2 signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 5 (dual H-bridge) peripherals. + */ +#define PMOD_DUAL_HBRIDGE_DIR2 PMOD_IO(3) + +/** + * @brief EN2 signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 5 (dual H-bridge) peripherals. + */ +#define PMOD_DUAL_HBRIDGE_EN2 PMOD_IO(4) + +/* Expanded dual H-bridge */ + +/** + * @brief DIR1 signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 5A (expanded dual H-bridge) peripherals. + */ +#define PMOD_EXP_DUAL_HBRIDGE_DIR1 PMOD_IO(1) + +/** + * @brief EN1 signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 5A (expanded dual H-bridge) peripherals. + */ +#define PMOD_EXP_DUAL_HBRIDGE_EN1 PMOD_IO(2) + +/** + * @brief DIR2 signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 5A (expanded dual H-bridge) peripherals. + */ +#define PMOD_EXP_DUAL_HBRIDGE_DIR2 PMOD_IO(5) + +/** + * @brief EN2 signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 5A (expanded dual H-bridge) peripherals. + */ +#define PMOD_EXP_DUAL_HBRIDGE_EN2 PMOD_IO(6) + +/* I2C */ + +/** + * @brief INT signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 6 (I2C) peripherals. + */ +#define PMOD_I2C_INT PMOD_IO(1) + +/** + * @brief RESET signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 6 (I2C) peripherals. + */ +#define PMOD_I2C_RESET PMOD_IO(2) + +/** + * @brief SCL signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 6 (I2C) peripherals. + */ +#define PMOD_I2C_SCL PMOD_IO(3) + +/** + * @brief SDA signal index on a Pmod GPIO nexus node. + * Used with Pmod Interface Type 6 (I2C) peripherals. + */ +#define PMOD_I2C_SDA PMOD_IO(4) + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_DIGILENT_PMOD_H_ */ From dfaa1d56828f1dcb6f5bba9f323f24212b7c30c2 Mon Sep 17 00:00:00 2001 From: Alexander Mihajlovic Date: Sun, 12 Mar 2023 19:30:27 +0100 Subject: [PATCH 0784/1906] boards: stm32h735g_disco: Add pmod connector Add pmod connector dts description. Signed-off-by: Alexander Mihajlovic --- .../arm/stm32h735g_disco/pmod_connector.dtsi | 22 +++++++++++++++++++ .../arm/stm32h735g_disco/stm32h735g_disco.dts | 1 + 2 files changed, 23 insertions(+) create mode 100644 boards/arm/stm32h735g_disco/pmod_connector.dtsi diff --git a/boards/arm/stm32h735g_disco/pmod_connector.dtsi b/boards/arm/stm32h735g_disco/pmod_connector.dtsi new file mode 100644 index 000000000000..8028cc55b257 --- /dev/null +++ b/boards/arm/stm32h735g_disco/pmod_connector.dtsi @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Elektronikutvecklingsbyrån EUB AB + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + pmod0: pmod-connector { + compatible = "digilent,pmod"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <0 0 &gpiof 9 0>, /* IO1 */ + <1 0 &gpiof 7 0>, /* IO2 */ + <2 0 &gpiof 6 0>, /* IO3 */ + <3 0 &gpiof 8 0>, /* IO4 */ + <4 0 &gpioh 12 0>, /* IO5 */ + <5 0 &gpioh 1 0>; /* IO6 */ + /* IO7 - not connected */ + /* IO8 - not connected */ + }; +}; diff --git a/boards/arm/stm32h735g_disco/stm32h735g_disco.dts b/boards/arm/stm32h735g_disco/stm32h735g_disco.dts index f8b296acc906..143176dab063 100644 --- a/boards/arm/stm32h735g_disco/stm32h735g_disco.dts +++ b/boards/arm/stm32h735g_disco/stm32h735g_disco.dts @@ -7,6 +7,7 @@ /dts-v1/; #include #include +#include "pmod_connector.dtsi" / { model = "STMicroelectronics STM32H735G DISCOVERY board"; From de81c48a244150c6ebc8422dcddb29a6bca4e322 Mon Sep 17 00:00:00 2001 From: Alexander Mihajlovic Date: Sun, 12 Mar 2023 19:32:04 +0100 Subject: [PATCH 0785/1906] boards: stm32h747i_disco: Add pmod connector Add pmod connector dts description. Signed-off-by: Alexander Mihajlovic --- .../arm/stm32h747i_disco/pmod_connector.dtsi | 22 +++++++++++++++++++ .../stm32h747i_disco/stm32h747i_disco.dtsi | 1 + 2 files changed, 23 insertions(+) create mode 100644 boards/arm/stm32h747i_disco/pmod_connector.dtsi diff --git a/boards/arm/stm32h747i_disco/pmod_connector.dtsi b/boards/arm/stm32h747i_disco/pmod_connector.dtsi new file mode 100644 index 000000000000..cc96b687d07f --- /dev/null +++ b/boards/arm/stm32h747i_disco/pmod_connector.dtsi @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Elektronikutvecklingsbyrån EUB AB + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + pmod0: pmod-connector { + compatible = "digilent,pmod"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <0 0 &gpioa 11 0>, /* IO1 */ + <1 0 &gpioc 3 0>, /* IO2 */ + <2 0 &gpioc 2 0>, /* IO3 */ + <3 0 &gpioa 12 0>, /* IO4 */ + <4 0 &gpioc 6 0>, /* IO5 */ + <5 0 &gpioj 13 0>; /* IO6 */ + /* IO7 - not connected */ + /* IO8 - not connected */ + }; +}; diff --git a/boards/arm/stm32h747i_disco/stm32h747i_disco.dtsi b/boards/arm/stm32h747i_disco/stm32h747i_disco.dtsi index 67c288640342..bf331dfdc0c8 100644 --- a/boards/arm/stm32h747i_disco/stm32h747i_disco.dtsi +++ b/boards/arm/stm32h747i_disco/stm32h747i_disco.dtsi @@ -5,6 +5,7 @@ */ #include "arduino_r3_connector.dtsi" +#include "pmod_connector.dtsi" / { leds { From 10a7baba0e911d1cedc80b6cf2de1e41eb5b4f4c Mon Sep 17 00:00:00 2001 From: Sylvio Alves Date: Tue, 7 Mar 2023 08:42:00 -0300 Subject: [PATCH 0786/1906] soc: esp32s3: add bluetooth support This only adds proper HEAP and HCI definition to enable BLE support to ESP32-S3. Signed-off-by: Sylvio Alves --- soc/riscv/esp32c3/Kconfig.soc | 10 ++++++++++ soc/xtensa/esp32s3/Kconfig.soc | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/soc/riscv/esp32c3/Kconfig.soc b/soc/riscv/esp32c3/Kconfig.soc index 7464b1504f1f..c155af6ebd3f 100644 --- a/soc/riscv/esp32c3/Kconfig.soc +++ b/soc/riscv/esp32c3/Kconfig.soc @@ -95,4 +95,14 @@ config ESP32_PHY_MAX_TX_POWER int default ESP32_PHY_MAX_WIFI_TX_POWER +config MAC_BB_PD + bool "Power down MAC and baseband of Wi-Fi and Bluetooth when PHY is disabled" + depends on SOC_ESP32C3 && TICKLESS_KERNEL + default n + help + If enabled, the MAC and baseband of Wi-Fi and Bluetooth will be powered + down when PHY is disabled. Enabling this setting reduces power consumption + by a small amount but increases RAM use by approximately 4 KB(Wi-Fi only), + 2 KB(Bluetooth only) or 5.3 KB(Wi-Fi + Bluetooth). + endif diff --git a/soc/xtensa/esp32s3/Kconfig.soc b/soc/xtensa/esp32s3/Kconfig.soc index 9c8dee0ade83..a49264690b3f 100644 --- a/soc/xtensa/esp32s3/Kconfig.soc +++ b/soc/xtensa/esp32s3/Kconfig.soc @@ -261,6 +261,15 @@ config ESP32S3_DATA_CACHE_WRAP The wrap length equals to ESP32S3_DATA_CACHE_LINE_SIZE. However, it depends on complex conditions. +config MAC_BB_PD + bool "Power down MAC and baseband of Wi-Fi and Bluetooth when PHY is disabled" + depends on SOC_ESP32S3 && TICKLESS_KERNEL + default n + help + If enabled, the MAC and baseband of Wi-Fi and Bluetooth will be powered + down when PHY is disabled. Enabling this setting reduces power consumption + by a small amount but increases RAM use by approximat + endmenu # Cache config endif # SOC_ESP32S3 From 0567557d4f26d910486fcf34486655e38a93e022 Mon Sep 17 00:00:00 2001 From: Sylvio Alves Date: Thu, 9 Mar 2023 20:56:05 -0300 Subject: [PATCH 0787/1906] boards: esp32xx: update BT heap of all espressif boards Current internal BT heap uses custom heap area, which reserves unused RAM area. In order to free up some RAM, BT HAL implementation was changed to use sysheap instead. With this change, something around ~13kb is now available for application, optmizing RAM usage. Signed-off-by: Sylvio Alves --- boards/riscv/esp32c3_devkitm/Kconfig.defconfig | 2 +- boards/riscv/icev_wireless/Kconfig.defconfig | 2 +- boards/riscv/stamp_c3/Kconfig.defconfig | 2 +- boards/riscv/xiao_esp32c3/Kconfig.defconfig | 2 +- boards/xtensa/esp32/Kconfig.defconfig | 2 +- boards/xtensa/esp32_ethernet_kit/Kconfig.defconfig | 2 +- boards/xtensa/esp32_net/Kconfig.defconfig | 2 +- boards/xtensa/esp32s2_franzininho/Kconfig.defconfig | 5 ----- boards/xtensa/esp32s3_devkitm/Kconfig.defconfig | 8 ++++++++ boards/xtensa/esp_wrover_kit/Kconfig.defconfig | 2 +- boards/xtensa/heltec_wifi_lora32_v2/Kconfig.defconfig | 2 +- boards/xtensa/m5stickc_plus/Kconfig.defconfig | 2 +- boards/xtensa/odroid_go/Kconfig.defconfig | 2 +- boards/xtensa/olimex_esp32_evb/Kconfig.defconfig | 2 +- 14 files changed, 20 insertions(+), 17 deletions(-) diff --git a/boards/riscv/esp32c3_devkitm/Kconfig.defconfig b/boards/riscv/esp32c3_devkitm/Kconfig.defconfig index bb789e7ecd1e..3686c1e8ad34 100644 --- a/boards/riscv/esp32c3_devkitm/Kconfig.defconfig +++ b/boards/riscv/esp32c3_devkitm/Kconfig.defconfig @@ -9,7 +9,7 @@ config BOARD config HEAP_MEM_POOL_SIZE default 98304 if WIFI - default 16384 if BT + default 40960 if BT default 4096 choice BT_HCI_BUS_TYPE diff --git a/boards/riscv/icev_wireless/Kconfig.defconfig b/boards/riscv/icev_wireless/Kconfig.defconfig index 730c40e0704e..84ce94865596 100644 --- a/boards/riscv/icev_wireless/Kconfig.defconfig +++ b/boards/riscv/icev_wireless/Kconfig.defconfig @@ -7,7 +7,7 @@ config BOARD config HEAP_MEM_POOL_SIZE default 98304 if WIFI - default 16384 if BT + default 40960 if BT default 4096 choice BT_HCI_BUS_TYPE diff --git a/boards/riscv/stamp_c3/Kconfig.defconfig b/boards/riscv/stamp_c3/Kconfig.defconfig index 56e120d5d1e1..cbd96af9cd05 100644 --- a/boards/riscv/stamp_c3/Kconfig.defconfig +++ b/boards/riscv/stamp_c3/Kconfig.defconfig @@ -9,7 +9,7 @@ config BOARD config HEAP_MEM_POOL_SIZE default 98304 if WIFI - default 16384 if BT + default 40960 if BT default 4096 if BT diff --git a/boards/riscv/xiao_esp32c3/Kconfig.defconfig b/boards/riscv/xiao_esp32c3/Kconfig.defconfig index 1f227163ebc2..e67ddbcc42e1 100644 --- a/boards/riscv/xiao_esp32c3/Kconfig.defconfig +++ b/boards/riscv/xiao_esp32c3/Kconfig.defconfig @@ -7,7 +7,7 @@ config BOARD config HEAP_MEM_POOL_SIZE default 98304 if WIFI - default 16384 if BT + default 40960 if BT default 4096 choice BT_HCI_BUS_TYPE diff --git a/boards/xtensa/esp32/Kconfig.defconfig b/boards/xtensa/esp32/Kconfig.defconfig index 2e6bad1caeb9..c2880e62d490 100644 --- a/boards/xtensa/esp32/Kconfig.defconfig +++ b/boards/xtensa/esp32/Kconfig.defconfig @@ -12,7 +12,7 @@ config ENTROPY_GENERATOR config HEAP_MEM_POOL_SIZE default 98304 if WIFI - default 16384 if BT + default 40960 if BT default 4096 choice BT_HCI_BUS_TYPE diff --git a/boards/xtensa/esp32_ethernet_kit/Kconfig.defconfig b/boards/xtensa/esp32_ethernet_kit/Kconfig.defconfig index f01138d4e0b2..aed4adc50a84 100644 --- a/boards/xtensa/esp32_ethernet_kit/Kconfig.defconfig +++ b/boards/xtensa/esp32_ethernet_kit/Kconfig.defconfig @@ -19,7 +19,7 @@ config ENTROPY_GENERATOR config HEAP_MEM_POOL_SIZE default 98304 if WIFI - default 16384 if BT + default 40960 if BT default 4096 choice BT_HCI_BUS_TYPE diff --git a/boards/xtensa/esp32_net/Kconfig.defconfig b/boards/xtensa/esp32_net/Kconfig.defconfig index 1160bf88abff..928a4c06de9c 100644 --- a/boards/xtensa/esp32_net/Kconfig.defconfig +++ b/boards/xtensa/esp32_net/Kconfig.defconfig @@ -12,7 +12,7 @@ config ENTROPY_GENERATOR config HEAP_MEM_POOL_SIZE default 98304 if WIFI - default 16384 if BT + default 40960 if BT default 4096 choice BT_HCI_BUS_TYPE diff --git a/boards/xtensa/esp32s2_franzininho/Kconfig.defconfig b/boards/xtensa/esp32s2_franzininho/Kconfig.defconfig index 75fa938598f7..94937f824dc5 100644 --- a/boards/xtensa/esp32s2_franzininho/Kconfig.defconfig +++ b/boards/xtensa/esp32s2_franzininho/Kconfig.defconfig @@ -12,9 +12,4 @@ config ENTROPY_GENERATOR config HEAP_MEM_POOL_SIZE default 98304 if WIFI - default 16384 if BT default 4096 - -choice BT_HCI_BUS_TYPE - default BT_ESP32 if BT -endchoice diff --git a/boards/xtensa/esp32s3_devkitm/Kconfig.defconfig b/boards/xtensa/esp32s3_devkitm/Kconfig.defconfig index 17fa3ca55b29..9bfcc1bf9991 100644 --- a/boards/xtensa/esp32s3_devkitm/Kconfig.defconfig +++ b/boards/xtensa/esp32s3_devkitm/Kconfig.defconfig @@ -9,3 +9,11 @@ config BOARD config ENTROPY_GENERATOR default y + +config HEAP_MEM_POOL_SIZE + default 40960 if BT + default 4096 + +choice BT_HCI_BUS_TYPE + default BT_ESP32 if BT +endchoice diff --git a/boards/xtensa/esp_wrover_kit/Kconfig.defconfig b/boards/xtensa/esp_wrover_kit/Kconfig.defconfig index e7808253dabf..65efe16093d7 100644 --- a/boards/xtensa/esp_wrover_kit/Kconfig.defconfig +++ b/boards/xtensa/esp_wrover_kit/Kconfig.defconfig @@ -9,7 +9,7 @@ config BOARD config HEAP_MEM_POOL_SIZE default 98304 if WIFI - default 16384 if BT + default 40960 if BT default 4096 choice BT_HCI_BUS_TYPE diff --git a/boards/xtensa/heltec_wifi_lora32_v2/Kconfig.defconfig b/boards/xtensa/heltec_wifi_lora32_v2/Kconfig.defconfig index 16f56dacaed6..d8e0ba31dba5 100644 --- a/boards/xtensa/heltec_wifi_lora32_v2/Kconfig.defconfig +++ b/boards/xtensa/heltec_wifi_lora32_v2/Kconfig.defconfig @@ -12,7 +12,7 @@ config ENTROPY_GENERATOR config HEAP_MEM_POOL_SIZE default 98304 if WIFI - default 16384 if BT + default 40960 if BT default 4096 choice BT_HCI_BUS_TYPE diff --git a/boards/xtensa/m5stickc_plus/Kconfig.defconfig b/boards/xtensa/m5stickc_plus/Kconfig.defconfig index f07a92a253cc..2fdc31f40082 100644 --- a/boards/xtensa/m5stickc_plus/Kconfig.defconfig +++ b/boards/xtensa/m5stickc_plus/Kconfig.defconfig @@ -12,7 +12,7 @@ config ENTROPY_GENERATOR config HEAP_MEM_POOL_SIZE default 98304 if WIFI - default 16384 if BT + default 40960 if BT default 4096 choice BT_HCI_BUS_TYPE diff --git a/boards/xtensa/odroid_go/Kconfig.defconfig b/boards/xtensa/odroid_go/Kconfig.defconfig index 2c313d769b00..7193624673e0 100644 --- a/boards/xtensa/odroid_go/Kconfig.defconfig +++ b/boards/xtensa/odroid_go/Kconfig.defconfig @@ -18,7 +18,7 @@ config ENTROPY_GENERATOR config HEAP_MEM_POOL_SIZE default 98304 if WIFI - default 16384 if BT + default 40960 if BT default 4096 choice BT_HCI_BUS_TYPE diff --git a/boards/xtensa/olimex_esp32_evb/Kconfig.defconfig b/boards/xtensa/olimex_esp32_evb/Kconfig.defconfig index eda48addc3ad..8e788f6a3938 100644 --- a/boards/xtensa/olimex_esp32_evb/Kconfig.defconfig +++ b/boards/xtensa/olimex_esp32_evb/Kconfig.defconfig @@ -13,7 +13,7 @@ config ENTROPY_GENERATOR config HEAP_MEM_POOL_SIZE default 98304 if WIFI - default 16384 if BT + default 40960 if BT default 4096 choice BT_HCI_BUS_TYPE From afe57dd3d604f71fb125267e16f28be43768b3f7 Mon Sep 17 00:00:00 2001 From: Sylvio Alves Date: Wed, 22 Mar 2023 10:55:31 -0300 Subject: [PATCH 0788/1906] west.yml: update hal_espressif to bring ESP32S3 BLE support This update includes the following: * Add ESP32-S3 support * Modify BT heap to use system heap instead of custom heap, which adds ~13kB of RAM to application. Fixes #55653 #54131 Signed-off-by: Sylvio Alves --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index b0bea8a00b0c..7935abd87bfe 100644 --- a/west.yml +++ b/west.yml @@ -57,7 +57,7 @@ manifest: groups: - hal - name: hal_espressif - revision: 8ee96508f329c7e59fcbf739f060cf12082dd805 + revision: d7576d0da639acbd9a191a3eb7e4f3f3476c9641 path: modules/hal/espressif west-commands: west/west-commands.yml groups: From 2c5d7d78ddcc2b4204f5352e682dd06e5336f4bd Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 24 Mar 2023 09:27:27 +0100 Subject: [PATCH 0789/1906] drivers: gpio: test: add driver config and data structs Add config and data structs to the vnd,gpio test driver as these are required by the GPIO API. Fixes: #55884 Signed-off-by: Henrik Brix Andersen --- drivers/gpio/gpio_test.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio_test.c b/drivers/gpio/gpio_test.c index 0a821be59312..65d22991ce90 100644 --- a/drivers/gpio/gpio_test.c +++ b/drivers/gpio/gpio_test.c @@ -13,6 +13,17 @@ #define DT_DRV_COMPAT vnd_gpio #include +#include + +struct vnd_gpio_config { + /* gpio_driver_config needs to be first */ + struct gpio_driver_config common; +}; + +struct vnd_gpio_data { + /* gpio_driver_data needs to be first */ + struct gpio_driver_data common; +}; static int vnd_gpio_pin_configure(const struct device *port, gpio_pin_t pin, @@ -89,10 +100,19 @@ static int vnd_gpio_init(const struct device *dev) return 0; } -#define VND_GPIO_INIT(n) \ - DEVICE_DT_INST_DEFINE(n, &vnd_gpio_init, NULL, \ - NULL, NULL, POST_KERNEL, \ - CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ +#define VND_GPIO_INIT(n) \ + static const struct vnd_gpio_config vnd_gpio_config_##n = { \ + .common = { \ + .port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n), \ + }, \ + }; \ + \ + static struct vnd_gpio_data vnd_gpio_data_##n; \ + \ + DEVICE_DT_INST_DEFINE(n, &vnd_gpio_init, NULL, \ + &vnd_gpio_data_##n, &vnd_gpio_config_##n, \ + POST_KERNEL, \ + CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ &vnd_gpio_api); DT_INST_FOREACH_STATUS_OKAY(VND_GPIO_INIT) From e440b023dd2a122a5ed14dbabf39400b4ed38bd0 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Fri, 24 Mar 2023 09:29:05 +0100 Subject: [PATCH 0790/1906] drivers: gpio: test: use CONFIG_GPIO_INIT_PRIORITY for init priority Use the dedicated CONFIG_GPIO_INIT_PRIORITY for vnd,gpio test driver initialization priority. Signed-off-by: Henrik Brix Andersen --- drivers/gpio/gpio_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpio_test.c b/drivers/gpio/gpio_test.c index 65d22991ce90..67a29bdad157 100644 --- a/drivers/gpio/gpio_test.c +++ b/drivers/gpio/gpio_test.c @@ -112,7 +112,7 @@ static int vnd_gpio_init(const struct device *dev) DEVICE_DT_INST_DEFINE(n, &vnd_gpio_init, NULL, \ &vnd_gpio_data_##n, &vnd_gpio_config_##n, \ POST_KERNEL, \ - CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ + CONFIG_GPIO_INIT_PRIORITY, \ &vnd_gpio_api); DT_INST_FOREACH_STATUS_OKAY(VND_GPIO_INIT) From 9011a067f21d2cd7dc01a179503c981d34834c59 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Tue, 21 Mar 2023 13:17:36 +0100 Subject: [PATCH 0791/1906] Bluetooth: Mesh: split rpr cli ack ctx for provisionning and scanning PR adds 2 acknowledgment contexts to RPR client to handle scanning and provisioning in parallel. Signed-off-by: Aleksandr Khromykh --- include/zephyr/bluetooth/mesh/rpr_cli.h | 3 +- subsys/bluetooth/mesh/rpr_cli.c | 47 +++++++++++++------------ 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/include/zephyr/bluetooth/mesh/rpr_cli.h b/include/zephyr/bluetooth/mesh/rpr_cli.h index ad7e9e1b7ee4..ee17e1739cb9 100644 --- a/include/zephyr/bluetooth/mesh/rpr_cli.h +++ b/include/zephyr/bluetooth/mesh/rpr_cli.h @@ -83,7 +83,8 @@ struct bt_mesh_rpr_cli { /* Internal parameters */ - struct bt_mesh_msg_ack_ctx ack_ctx; + struct bt_mesh_msg_ack_ctx scan_ack_ctx; + struct bt_mesh_msg_ack_ctx prov_ack_ctx; struct { struct k_work_delayable timeout; diff --git a/subsys/bluetooth/mesh/rpr_cli.c b/subsys/bluetooth/mesh/rpr_cli.c index da5fe39c513a..b2615c4165a8 100644 --- a/subsys/bluetooth/mesh/rpr_cli.c +++ b/subsys/bluetooth/mesh/rpr_cli.c @@ -84,7 +84,7 @@ static void tx_complete(struct bt_mesh_rpr_cli *cli, int err, void *cb_data) LOG_DBG("%d", err); cli->link.tx_pdu++; - bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx); + bt_mesh_msg_ack_ctx_clear(&cli->prov_ack_ctx); if (bearer.tx.cb) { bearer.tx.cb(err, cb_data); @@ -143,7 +143,7 @@ static int handle_link_report(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx } /* The server uses the link report to notify about failed tx */ - if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, RPR_OP_LINK_REPORT, + if (bt_mesh_msg_ack_ctx_match(&cli->prov_ack_ctx, RPR_OP_LINK_REPORT, srv.addr, &cb_data) && link.status != BT_MESH_RPR_SUCCESS) { tx_complete(cli, -ECANCELED, cb_data); @@ -184,10 +184,10 @@ static int handle_link_status(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx LOG_DBG("0x%04x: status: %u state: %u", srv.addr, link.status, link.state); - if (bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, RPR_OP_LINK_STATUS, + if (bt_mesh_msg_ack_ctx_match(&cli->prov_ack_ctx, RPR_OP_LINK_STATUS, srv.addr, (void **)&rsp)) { *rsp = link; - bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + bt_mesh_msg_ack_ctx_rx(&cli->prov_ack_ctx); } if (cli->link.srv.addr == srv.addr) { @@ -223,7 +223,7 @@ static int handle_pdu_outbound_report(struct bt_mesh_model *mod, struct bt_mesh_ k_work_reschedule(&cli->link.timeout, K_SECONDS(cli->link.time)); - if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, RPR_OP_PDU_OUTBOUND_REPORT, + if (!bt_mesh_msg_ack_ctx_match(&cli->prov_ack_ctx, RPR_OP_PDU_OUTBOUND_REPORT, srv.addr, &cb_data) || num != cli->link.tx_pdu) { LOG_WRN("Non-matching PDU report (%u)", num); @@ -273,7 +273,7 @@ static int handle_scan_caps_status(struct bt_mesh_model *mod, struct bt_mesh_msg struct bt_mesh_rpr_node srv = RPR_NODE(ctx); struct bt_mesh_rpr_caps *caps; - if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, RPR_OP_SCAN_CAPS_STATUS, + if (!bt_mesh_msg_ack_ctx_match(&cli->scan_ack_ctx, RPR_OP_SCAN_CAPS_STATUS, srv.addr, (void **)&caps)) { LOG_WRN("Unexpected scan caps rsp from 0x%04x", srv.addr); return 0; @@ -285,7 +285,7 @@ static int handle_scan_caps_status(struct bt_mesh_model *mod, struct bt_mesh_msg LOG_DBG("max devs: %u active scan: %u", caps->max_devs, caps->active_scan); - bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + bt_mesh_msg_ack_ctx_rx(&cli->scan_ack_ctx); return 0; } @@ -329,7 +329,7 @@ static int handle_scan_status(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx struct bt_mesh_rpr_scan_status *status; struct bt_mesh_rpr_node srv = RPR_NODE(ctx); - if (!bt_mesh_msg_ack_ctx_match(&cli->ack_ctx, RPR_OP_SCAN_STATUS, + if (!bt_mesh_msg_ack_ctx_match(&cli->scan_ack_ctx, RPR_OP_SCAN_STATUS, srv.addr, (void **)&status)) { LOG_WRN("Unexpected scan status from 0x%04x", srv.addr); return 0; @@ -342,7 +342,7 @@ static int handle_scan_status(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx LOG_DBG("status: %u state: %u max devs: %u timeout: %u seconds", status->status, status->scan, status->max_devs, status->timeout); - bt_mesh_msg_ack_ctx_rx(&cli->ack_ctx); + bt_mesh_msg_ack_ctx_rx(&cli->scan_ack_ctx); return 0; } @@ -383,7 +383,8 @@ static int rpr_cli_init(struct bt_mesh_model *mod) cli->mod = mod; cli->link.time = LINK_TIMEOUT_SECONDS_DEFAULT; - bt_mesh_msg_ack_ctx_init(&cli->ack_ctx); + bt_mesh_msg_ack_ctx_init(&cli->scan_ack_ctx); + bt_mesh_msg_ack_ctx_init(&cli->prov_ack_ctx); k_work_init_delayable(&cli->link.timeout, link_timeout); mod->keys[0] = BT_MESH_KEY_DEV_ANY; mod->flags |= BT_MESH_MOD_DEVKEY_ONLY; @@ -428,27 +429,27 @@ static const struct bt_mesh_send_cb pdu_send_cb = { }; static int tx_wait(struct bt_mesh_rpr_cli *cli, - const struct bt_mesh_rpr_node *srv, + struct bt_mesh_msg_ack_ctx *ack_ctx, const struct bt_mesh_rpr_node *srv, struct net_buf_simple *buf, uint32_t rsp, void *rsp_ctx) { struct bt_mesh_msg_ctx ctx = LINK_CTX(srv, false); int err; - err = bt_mesh_msg_ack_ctx_prepare(&cli->ack_ctx, rsp, srv->addr, rsp_ctx); + err = bt_mesh_msg_ack_ctx_prepare(ack_ctx, rsp, srv->addr, rsp_ctx); if (err) { return err; } err = bt_mesh_model_send(cli->mod, &ctx, buf, NULL, NULL); if (err) { - bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx); + bt_mesh_msg_ack_ctx_clear(ack_ctx); LOG_WRN("TX fail"); return err; } - err = bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(tx_timeout)); + err = bt_mesh_msg_ack_ctx_wait(ack_ctx, K_MSEC(tx_timeout)); - bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx); + bt_mesh_msg_ack_ctx_clear(ack_ctx); return err; } @@ -467,7 +468,7 @@ static void link_reset(struct bt_mesh_rpr_cli *cli) k_work_cancel_delayable(&cli->link.timeout); cli->link.srv.addr = BT_MESH_ADDR_UNASSIGNED; cli->link.state = BT_MESH_RPR_LINK_IDLE; - bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx); + bt_mesh_msg_ack_ctx_clear(&cli->prov_ack_ctx); } static void link_closed(struct bt_mesh_rpr_cli *cli, @@ -494,7 +495,7 @@ int bt_mesh_rpr_scan_caps_get(struct bt_mesh_rpr_cli *cli, BT_MESH_MODEL_BUF_DEFINE(buf, RPR_OP_SCAN_CAPS_GET, 0); bt_mesh_model_msg_init(&buf, RPR_OP_SCAN_CAPS_GET); - return tx_wait(cli, srv, &buf, RPR_OP_SCAN_CAPS_STATUS, caps); + return tx_wait(cli, &cli->scan_ack_ctx, srv, &buf, RPR_OP_SCAN_CAPS_STATUS, caps); } int bt_mesh_rpr_scan_get(struct bt_mesh_rpr_cli *cli, @@ -504,7 +505,7 @@ int bt_mesh_rpr_scan_get(struct bt_mesh_rpr_cli *cli, BT_MESH_MODEL_BUF_DEFINE(buf, RPR_OP_SCAN_GET, 0); bt_mesh_model_msg_init(&buf, RPR_OP_SCAN_GET); - return tx_wait(cli, srv, &buf, RPR_OP_SCAN_STATUS, status); + return tx_wait(cli, &cli->scan_ack_ctx, srv, &buf, RPR_OP_SCAN_STATUS, status); } int bt_mesh_rpr_scan_start(struct bt_mesh_rpr_cli *cli, @@ -527,7 +528,7 @@ int bt_mesh_rpr_scan_start(struct bt_mesh_rpr_cli *cli, net_buf_simple_add_mem(&buf, uuid, 16); } - return tx_wait(cli, srv, &buf, RPR_OP_SCAN_STATUS, status); + return tx_wait(cli, &cli->scan_ack_ctx, srv, &buf, RPR_OP_SCAN_STATUS, status); } int bt_mesh_rpr_scan_start_ext(struct bt_mesh_rpr_cli *cli, @@ -564,7 +565,7 @@ int bt_mesh_rpr_scan_stop(struct bt_mesh_rpr_cli *cli, BT_MESH_MODEL_BUF_DEFINE(buf, RPR_OP_SCAN_STOP, 0); bt_mesh_model_msg_init(&buf, RPR_OP_SCAN_STOP); - return tx_wait(cli, srv, &buf, RPR_OP_SCAN_STATUS, status); + return tx_wait(cli, &cli->scan_ack_ctx, srv, &buf, RPR_OP_SCAN_STATUS, status); } int bt_mesh_rpr_link_get(struct bt_mesh_rpr_cli *cli, @@ -574,7 +575,7 @@ int bt_mesh_rpr_link_get(struct bt_mesh_rpr_cli *cli, BT_MESH_MODEL_BUF_DEFINE(buf, RPR_OP_LINK_GET, 0); bt_mesh_model_msg_init(&buf, RPR_OP_LINK_GET); - return tx_wait(cli, srv, &buf, RPR_OP_LINK_STATUS, rsp); + return tx_wait(cli, &cli->prov_ack_ctx, srv, &buf, RPR_OP_LINK_STATUS, rsp); } int bt_mesh_rpr_link_close(struct bt_mesh_rpr_cli *cli, @@ -585,7 +586,7 @@ int bt_mesh_rpr_link_close(struct bt_mesh_rpr_cli *cli, bt_mesh_model_msg_init(&buf, RPR_OP_LINK_CLOSE); net_buf_simple_add_u8(&buf, PROV_BEARER_LINK_STATUS_FAIL); - return tx_wait(cli, srv, &buf, RPR_OP_LINK_STATUS, rsp); + return tx_wait(cli, &cli->prov_ack_ctx, srv, &buf, RPR_OP_LINK_STATUS, rsp); } static int link_open_prov(struct bt_mesh_rpr_cli *cli, @@ -660,7 +661,7 @@ static int send(struct bt_mesh_rpr_cli *cli, struct net_buf_simple *buf, return -EINVAL; } - err = bt_mesh_msg_ack_ctx_prepare(&cli->ack_ctx, + err = bt_mesh_msg_ack_ctx_prepare(&cli->prov_ack_ctx, RPR_OP_PDU_OUTBOUND_REPORT, cli->link.srv.addr, cb_data); if (err) { From 5ed6245f84bc8c45aa53f9230e11798924ab26e3 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Tue, 21 Mar 2023 16:42:13 +0100 Subject: [PATCH 0792/1906] tests: Bluetooth: Mesh: bsim to check parallel work in remote provisioning The commit adds bsim test to check ability to handle proviosioning and scanning in parallel in remote provisioning models. Signed-off-by: Aleksandr Khromykh --- .../bsim/bluetooth/mesh/src/test_provision.c | 66 +++++++++++++++++++ .../provision/pb_remote_parallel.sh | 19 ++++++ 2 files changed, 85 insertions(+) create mode 100755 tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_parallel.sh diff --git a/tests/bsim/bluetooth/mesh/src/test_provision.c b/tests/bsim/bluetooth/mesh/src/test_provision.c index 2431fde9993d..5bd57aeead43 100644 --- a/tests/bsim/bluetooth/mesh/src/test_provision.c +++ b/tests/bsim/bluetooth/mesh/src/test_provision.c @@ -85,6 +85,7 @@ static uint8_t *uuid_to_provision; static struct k_sem reprov_sem; #if IS_RPR_PRESENT +static struct k_sem scan_sem; /* Remote Provisioning models related variables. */ static uint8_t *uuid_to_provision_remote; static void rpr_scan_report(struct bt_mesh_rpr_cli *cli, const struct bt_mesh_rpr_node *srv, @@ -773,6 +774,69 @@ static void test_provisioner_pb_remote_client_reprovision(void) PASS(); } +static void rpr_scan_report_parallel(struct bt_mesh_rpr_cli *cli, + const struct bt_mesh_rpr_node *srv, + struct bt_mesh_rpr_unprov *unprov, + struct net_buf_simple *adv_data) +{ + if (!uuid_to_provision_remote || memcmp(uuid_to_provision_remote, unprov->uuid, 16)) { + return; + } + + LOG_INF("Scanning dev idx 2 succeeded.\n"); + k_sem_give(&scan_sem); +} + +static void test_provisioner_pb_remote_client_parallel(void) +{ + static uint8_t uuid[16]; + uint16_t pb_remote_server_addr; + struct bt_mesh_rpr_scan_status scan_status; + + memcpy(uuid, dev_uuid, 16); + + k_sem_init(&prov_sem, 0, 1); + k_sem_init(&scan_sem, 0, 1); + + bt_mesh_device_setup(&prov, &rpr_cli_comp); + + ASSERT_OK(bt_mesh_cdb_create(test_net_key)); + ASSERT_OK(bt_mesh_provision(test_net_key, 0, 0, 0, 0x0001, dev_key)); + + /* Provision the 2nd device over PB-Adv. */ + ASSERT_OK(provision_adv(1, &pb_remote_server_addr)); + + struct bt_mesh_rpr_node srv = { + .addr = pb_remote_server_addr, + .net_idx = 0, + .ttl = 3, + }; + + rpr_cli.scan_report = rpr_scan_report_parallel; + + LOG_INF("Scanning dev idx 2 and provisioning dev idx 3 in parallel ...\n"); + /* provisioning device with dev index 2 */ + uuid[6] = '0' + 2; + ASSERT_OK(bt_mesh_provision_remote(&rpr_cli, &srv, uuid, 0, prov_addr)); + /* scanning device with dev index 3 */ + uuid[6] = '0' + 3; + uuid_to_provision_remote = uuid; + ASSERT_OK(bt_mesh_rpr_scan_start(&rpr_cli, &srv, uuid, 5, 1, &scan_status)); + ASSERT_EQUAL(BT_MESH_RPR_SUCCESS, scan_status.status); + ASSERT_EQUAL(BT_MESH_RPR_SCAN_SINGLE, scan_status.scan); + ASSERT_EQUAL(1, scan_status.max_devs); + ASSERT_EQUAL(5, scan_status.timeout); + + ASSERT_OK(k_sem_take(&scan_sem, K_SECONDS(20))); + ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); + + /* Provisioning device index 3. Need it to succeed provisionee test scenario. */ + ASSERT_OK(bt_mesh_provision_remote(&rpr_cli, &srv, uuid, 0, prov_addr)); + ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); + + PASS(); +} + /** @brief Verify robustness of NPPI procedures on a RPR Client by running Device Key Refresh, * Node Composition Refresh and Node Address Refresh procedures. */ @@ -1236,6 +1300,8 @@ static const struct bst_test_instance test_connect[] = { "Provisioner: pb-remote provisioning, resetting and reprov-ing multiple times."), TEST_CASE(provisioner, pb_remote_client_nppi_robustness, "Provisioner: pb-remote provisioning, NPPI robustness."), + TEST_CASE(provisioner, pb_remote_client_parallel, + "Provisioner: pb-remote provisioning, parallel scanning and provisioning."), #endif BSTEST_END_MARKER diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_parallel.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_parallel.sh new file mode 100755 index 000000000000..aec30c65f101 --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_parallel.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +# Test a parallel work scanning and provisioning work on RPR client and server. Procedure: +# 1. A provisioner with the RPR client provisions itself; +# 2. The provisioner provisions a device with the RPR server; +# 3. The provisioner provisions an unprovisioned device idx 2 through the node with RPR server; +# 4. The provisioner scans for an unprovisioned device idx 3 through the node with RPR server; +# 5. The provisioner checks scanning and provisioning succeeded; +# 6. The provisioner provisions an unprovisioned device idx 3 through the node with RPR server; +conf=prj_mesh1d1_conf +RunTest mesh_prov_pb_remote_parallel \ + prov_provisioner_pb_remote_client_parallel \ + prov_device_pb_remote_server_unproved \ + prov_device_pb_adv_no_oob \ + prov_device_pb_adv_no_oob From 0deeb5ff6547519867a8a1d4cd0f213dbf8f3c84 Mon Sep 17 00:00:00 2001 From: Luca Fancellu Date: Mon, 13 Mar 2023 11:16:25 +0000 Subject: [PATCH 0793/1906] soc: include: fvp_aemv8r: Define device memory as device tree node A recent change introduced the possibility to declare MPU memory regions using the device tree and the framework described in zephyr/linker/devicetree_regions.h. So remove the device region declared in mpu_regions[] and the used defines for the addresses, rename REGION_DEVICE_ATTR to REGION_IO_ATTR in arm_mpu.h to be compatible with the framework and add a device tree node to fvp_baser_aemv8r.dts to describe the device memory region. Signed-off-by: Luca Fancellu --- boards/arm64/fvp_baser_aemv8r/fvp_baser_aemv8r.dts | 7 +++++++ include/zephyr/arch/arm64/cortex_r/arm_mpu.h | 2 +- soc/arm64/arm/fvp_aemv8r/arm_mpu_regions.c | 9 --------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/boards/arm64/fvp_baser_aemv8r/fvp_baser_aemv8r.dts b/boards/arm64/fvp_baser_aemv8r/fvp_baser_aemv8r.dts index 0466adfda18b..86b95839506b 100644 --- a/boards/arm64/fvp_baser_aemv8r/fvp_baser_aemv8r.dts +++ b/boards/arm64/fvp_baser_aemv8r/fvp_baser_aemv8r.dts @@ -36,6 +36,13 @@ compatible = "mmio-dram"; reg = <0x0 DT_SIZE_M(128)>; }; + + device_region: memory@80000000 { + compatible = "zephyr,memory-region", "mmio-dram"; + reg = <0x80000000 DT_SIZE_M(2048)>; + zephyr,memory-region = "DEVICE_REGION"; + zephyr,memory-region-mpu = "IO"; + }; }; }; diff --git a/include/zephyr/arch/arm64/cortex_r/arm_mpu.h b/include/zephyr/arch/arm64/cortex_r/arm_mpu.h index 12280f49eb4d..0c9ad2c00192 100644 --- a/include/zephyr/arch/arm64/cortex_r/arm_mpu.h +++ b/include/zephyr/arch/arm64/cortex_r/arm_mpu.h @@ -132,7 +132,7 @@ * recommended to use these helper defines only for configuring * fixed MPU regions at build-time. */ -#define REGION_DEVICE_ATTR \ +#define REGION_IO_ATTR \ { \ /* AP, XN, SH */ \ .rbar = NOT_EXEC | P_RW_U_NA_Msk | NON_SHAREABLE_Msk, \ diff --git a/soc/arm64/arm/fvp_aemv8r/arm_mpu_regions.c b/soc/arm64/arm/fvp_aemv8r/arm_mpu_regions.c index 97b08d418b4f..ab261e2e45db 100644 --- a/soc/arm64/arm/fvp_aemv8r/arm_mpu_regions.c +++ b/soc/arm64/arm/fvp_aemv8r/arm_mpu_regions.c @@ -10,9 +10,6 @@ #include #include -#define DEVICE_REGION_START 0x80000000UL -#define DEVICE_REGION_END 0xFFFFFFFFUL - static const struct arm_mpu_region mpu_regions[] = { /* Region 0 */ MPU_REGION_ENTRY("FLASH_0", @@ -43,12 +40,6 @@ static const struct arm_mpu_region mpu_regions[] = { (uintptr_t)__kernel_ram_end, REGION_RAM_ATTR), - /* Region 4 device region */ - MPU_REGION_ENTRY("DEVICE", - DEVICE_REGION_START, - DEVICE_REGION_END, - REGION_DEVICE_ATTR), - /* Extra regions defined in device tree */ LINKER_DT_REGION_MPU(MPU_REGION_ENTRY_FROM_DTS) }; From e0c90b93939c392274efcc52d7c0a65c2d84d2bd Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Mon, 27 Mar 2023 15:26:45 +0200 Subject: [PATCH 0794/1906] scripts: requirements: Move requests and pyserial to base Both the requests and pyserial Python packages are used by west commands (west fetch and west build -b esp* respectively) so move them to the requirements-base.txt file. Fixes #56215. Fixes #56224. Signed-off-by: Carles Cufi --- scripts/requirements-base.txt | 2 ++ scripts/requirements-run-test.txt | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/requirements-base.txt b/scripts/requirements-base.txt index 6b0f98fa2b94..ce3d29cf4899 100644 --- a/scripts/requirements-base.txt +++ b/scripts/requirements-base.txt @@ -19,6 +19,8 @@ packaging progress psutil pylink-square +pyserial +requests # for ram/rom reports anytree diff --git a/scripts/requirements-run-test.txt b/scripts/requirements-run-test.txt index 43401ec4480e..71ee53d78062 100644 --- a/scripts/requirements-run-test.txt +++ b/scripts/requirements-run-test.txt @@ -2,9 +2,6 @@ # # things used by twister or related in run time testing -# used to connect to boards for console IO -pyserial - # used to flash & debug various boards pyocd>=0.29.0 From c5fbcc468ef64b5b89004d0e81300f206521ed4a Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Mon, 27 Mar 2023 10:16:26 +0100 Subject: [PATCH 0795/1906] snippets: Fix cmake path output on Windows Uses linux style path output instead of windows style to prevent issues with cmake assuming the slashes are for escape code sequences. Signed-off-by: Jamie McCrae --- scripts/snippets.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/snippets.py b/scripts/snippets.py index 7b838573a2c7..2158613a1490 100644 --- a/scripts/snippets.py +++ b/scripts/snippets.py @@ -16,7 +16,7 @@ from collections import defaultdict, UserDict from dataclasses import dataclass, field -from pathlib import Path +from pathlib import Path, PurePosixPath from typing import Dict, Iterable, List, Set import argparse import logging @@ -27,6 +27,7 @@ import sys import textwrap import yaml +import platform # Marker type for an 'append:' configuration. Maps variables # to the list of values to append to them. @@ -99,6 +100,17 @@ def print_cmake(self): # TODO: add source file info snippets = self.snippets snippet_names = sorted(snippets.keys()) + + if platform.system() == "Windows": + # Change to linux-style paths for windows to avoid cmake escape character code issues + snippets.paths = set(map(lambda x: str(PurePosixPath(x)), snippets.paths)) + + for this_snippet in snippets: + for snippet_append in (snippets[this_snippet].appends): + snippets[this_snippet].appends[snippet_append] = \ + set(map(lambda x: str(x.replace("\\", "/")), \ + snippets[this_snippet].appends[snippet_append])) + snippet_path_list = " ".join( sorted(f'"{path}"' for path in snippets.paths)) From ccd88a4b611ca4dfe3985709d3cd36021910a6c2 Mon Sep 17 00:00:00 2001 From: Kumar Amit Mehta Date: Tue, 7 Mar 2023 02:31:05 +0100 Subject: [PATCH 0796/1906] documentation: samples: smp: Fix pathname for SMP sample examples SMP sample applications are located in the 'arch' directory. This patch fixes the pathname for SMP sample examples. Signed-off-by: Kumar Amit Mehta --- samples/arch/smp/pi/README.rst | 2 +- samples/arch/smp/pktqueue/README.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/arch/smp/pi/README.rst b/samples/arch/smp/pi/README.rst index e4bbf4677513..ffdd5540ecc0 100644 --- a/samples/arch/smp/pi/README.rst +++ b/samples/arch/smp/pi/README.rst @@ -26,7 +26,7 @@ required for all the calculation to be done. It can be built and executed on Synopsys ARC HSDK board as follows: .. zephyr-app-commands:: - :zephyr-app: samples/smp/pi + :zephyr-app: samples/arch/smp/pi :host-os: unix :board: qemu_x86_64 :goals: run diff --git a/samples/arch/smp/pktqueue/README.rst b/samples/arch/smp/pktqueue/README.rst index f9889e7900b6..dd2d12213826 100644 --- a/samples/arch/smp/pktqueue/README.rst +++ b/samples/arch/smp/pktqueue/README.rst @@ -64,7 +64,7 @@ This project outputs total time required for processing all packet headers. It can be built and executed on QEMU as follows: .. zephyr-app-commands:: - :zephyr-app: samples/smp_pktqueue + :zephyr-app: samples/arch/smp/pktqueue :host-os: unix :board: qemu_x86_64 :goals: run From 40ec70fd2ad5ab52bfa077066d04c994e6a33987 Mon Sep 17 00:00:00 2001 From: Jeppe Odgaard Date: Fri, 24 Feb 2023 16:05:58 +0100 Subject: [PATCH 0797/1906] drivers: sensor: mcux qdec single-phase option Add binding and sensor attribute to allow single phase mode where only one signal is required from the encoder. The signal must be connected to Phase A input. Signed-off-by: Jeppe Odgaard --- drivers/sensor/qdec_mcux/qdec_mcux.c | 20 ++++++++++++++++++-- dts/bindings/sensor/nxp,mcux-qdec.yaml | 7 +++++++ include/zephyr/drivers/sensor/qdec_mcux.h | 2 ++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/sensor/qdec_mcux/qdec_mcux.c b/drivers/sensor/qdec_mcux/qdec_mcux.c index 4d6e4b88b70d..047ad3cc3a4e 100644 --- a/drivers/sensor/qdec_mcux/qdec_mcux.c +++ b/drivers/sensor/qdec_mcux/qdec_mcux.c @@ -37,6 +37,12 @@ struct qdec_mcux_data { uint16_t counts_per_revolution; }; +static enc_decoder_work_mode_t int_to_work_mode(int32_t val) +{ + return val == 0 ? kENC_DecoderWorkAsNormalMode : + kENC_DecoderWorkAsSignalPhaseCountMode; +} + static int qdec_mcux_attr_set(const struct device *dev, enum sensor_channel ch, enum sensor_attribute attr, const struct sensor_value *val) { @@ -46,7 +52,7 @@ static int qdec_mcux_attr_set(const struct device *dev, enum sensor_channel ch, return -ENOTSUP; } - switch (attr) { + switch ((enum sensor_attribute_qdec_mcux) attr) { case SENSOR_ATTR_QDEC_MOD_VAL: if (val->val1 <= 0 || val->val1 > UINT16_MAX) { LOG_ERR("SENSOR_ATTR_QDEC_MOD_VAL value invalid"); @@ -54,6 +60,10 @@ static int qdec_mcux_attr_set(const struct device *dev, enum sensor_channel ch, } data->counts_per_revolution = val->val1; return 0; + case SENSOR_ATTR_QDEC_ENABLE_SINGLE_PHASE: + data->qdec_config.decoderWorkMode = + int_to_work_mode(val->val1); + return 0; default: return -ENOTSUP; } @@ -68,10 +78,14 @@ static int qdec_mcux_attr_get(const struct device *dev, enum sensor_channel ch, return -ENOTSUP; } - switch (attr) { + switch ((enum sensor_attribute_qdec_mcux) attr) { case SENSOR_ATTR_QDEC_MOD_VAL: val->val1 = data->counts_per_revolution; return 0; + case SENSOR_ATTR_QDEC_ENABLE_SINGLE_PHASE: + val->val1 = data->qdec_config.decoderWorkMode == + kENC_DecoderWorkAsNormalMode ? 0 : 1; + return 0; default: return -ENOTSUP; } @@ -179,6 +193,8 @@ static void init_inputs(const struct device *dev) init_inputs(dev); \ \ ENC_GetDefaultConfig(&data->qdec_config); \ + data->qdec_config.decoderWorkMode = int_to_work_mode( \ + DT_INST_PROP(n, single_phase_mode)); \ ENC_Init(config->base, &data->qdec_config); \ \ /* Update the position counter with initial value. */ \ diff --git a/dts/bindings/sensor/nxp,mcux-qdec.yaml b/dts/bindings/sensor/nxp,mcux-qdec.yaml index ce16be40b106..e868cb230c20 100644 --- a/dts/bindings/sensor/nxp,mcux-qdec.yaml +++ b/dts/bindings/sensor/nxp,mcux-qdec.yaml @@ -21,6 +21,13 @@ properties: This is a number that is used to determine how many revolutions were done based on the current counter's value. + single-phase-mode: + type: boolean + description: | + Bypass the quadrature decoder. A positive transition of the PHASEA input + generates a count signal. The PHASEB input and the REV bit control the + counter direction. + xbar: type: phandle required: true diff --git a/include/zephyr/drivers/sensor/qdec_mcux.h b/include/zephyr/drivers/sensor/qdec_mcux.h index b122b48896c8..e8037f3a97dd 100644 --- a/include/zephyr/drivers/sensor/qdec_mcux.h +++ b/include/zephyr/drivers/sensor/qdec_mcux.h @@ -12,6 +12,8 @@ enum sensor_attribute_qdec_mcux { /* Number of counts per revolution */ SENSOR_ATTR_QDEC_MOD_VAL = SENSOR_ATTR_PRIV_START, + /* Single phase counting */ + SENSOR_ATTR_QDEC_ENABLE_SINGLE_PHASE, }; #endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_QDEC_MCUX_H_ */ From a5865949d9cdb027f270d65eb8da479175444db9 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Wed, 22 Mar 2023 09:39:13 +0100 Subject: [PATCH 0798/1906] samples: drivers: counter: alarm: Fix nordic DKs After reworking counter driver to use device tree this sample stopped to compile for nordic DKs. Providing overlays to fix the compliation. Signed-off-by: Krzysztof Chruscinski --- samples/drivers/counter/alarm/Kconfig | 4 ---- samples/drivers/counter/alarm/boards/nrf51dk_nrf51422.overlay | 3 +++ .../drivers/counter/alarm/boards/nrf52840dk_nrf52840.overlay | 3 +++ samples/drivers/counter/alarm/boards/nrf52dk_nrf52832.overlay | 3 +++ .../drivers/counter/alarm/boards/nrf9160dk_nrf9160.overlay | 3 +++ samples/drivers/counter/alarm/src/main.c | 2 +- 6 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 samples/drivers/counter/alarm/boards/nrf51dk_nrf51422.overlay create mode 100644 samples/drivers/counter/alarm/boards/nrf52840dk_nrf52840.overlay create mode 100644 samples/drivers/counter/alarm/boards/nrf52dk_nrf52832.overlay create mode 100644 samples/drivers/counter/alarm/boards/nrf9160dk_nrf9160.overlay diff --git a/samples/drivers/counter/alarm/Kconfig b/samples/drivers/counter/alarm/Kconfig index 030a80b7709e..9259c85ded11 100644 --- a/samples/drivers/counter/alarm/Kconfig +++ b/samples/drivers/counter/alarm/Kconfig @@ -3,10 +3,6 @@ # Copyright (c) 2019 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -config COUNTER_RTC0 - bool - default y if SOC_FAMILY_NRF - config COUNTER_SAM0_TC32 bool default y if BOARD_ATSAMD20_XPRO diff --git a/samples/drivers/counter/alarm/boards/nrf51dk_nrf51422.overlay b/samples/drivers/counter/alarm/boards/nrf51dk_nrf51422.overlay new file mode 100644 index 000000000000..5e37ad9fff92 --- /dev/null +++ b/samples/drivers/counter/alarm/boards/nrf51dk_nrf51422.overlay @@ -0,0 +1,3 @@ +&rtc0 { + status = "okay"; +}; diff --git a/samples/drivers/counter/alarm/boards/nrf52840dk_nrf52840.overlay b/samples/drivers/counter/alarm/boards/nrf52840dk_nrf52840.overlay new file mode 100644 index 000000000000..5e37ad9fff92 --- /dev/null +++ b/samples/drivers/counter/alarm/boards/nrf52840dk_nrf52840.overlay @@ -0,0 +1,3 @@ +&rtc0 { + status = "okay"; +}; diff --git a/samples/drivers/counter/alarm/boards/nrf52dk_nrf52832.overlay b/samples/drivers/counter/alarm/boards/nrf52dk_nrf52832.overlay new file mode 100644 index 000000000000..5e37ad9fff92 --- /dev/null +++ b/samples/drivers/counter/alarm/boards/nrf52dk_nrf52832.overlay @@ -0,0 +1,3 @@ +&rtc0 { + status = "okay"; +}; diff --git a/samples/drivers/counter/alarm/boards/nrf9160dk_nrf9160.overlay b/samples/drivers/counter/alarm/boards/nrf9160dk_nrf9160.overlay new file mode 100644 index 000000000000..5e37ad9fff92 --- /dev/null +++ b/samples/drivers/counter/alarm/boards/nrf9160dk_nrf9160.overlay @@ -0,0 +1,3 @@ +&rtc0 { + status = "okay"; +}; diff --git a/samples/drivers/counter/alarm/src/main.c b/samples/drivers/counter/alarm/src/main.c index 82005e5b1cae..2df543004063 100644 --- a/samples/drivers/counter/alarm/src/main.c +++ b/samples/drivers/counter/alarm/src/main.c @@ -21,7 +21,7 @@ struct counter_alarm_cfg alarm_cfg; #define TIMER DT_NODELABEL(tc0) #elif defined(CONFIG_COUNTER_MICROCHIP_MCP7940N) #define TIMER DT_NODELABEL(extrtc0) -#elif defined(CONFIG_COUNTER_RTC0) +#elif defined(CONFIG_COUNTER_NRF_RTC) #define TIMER DT_NODELABEL(rtc0) #elif defined(CONFIG_COUNTER_TIMER_STM32) #define TIMER DT_INST(0, st_stm32_counter) From e0082eded7cf42f8816fe3e3b4973b0d2eb148b1 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Wed, 22 Mar 2023 09:40:20 +0100 Subject: [PATCH 0799/1906] drivers: timer: nrf_rtc_timer: Add guard against conflict Add missing guard which prevents use of nrf_rtc_timer on the same RTC instance (RTC1) as counter driver instance. Signed-off-by: Krzysztof Chruscinski --- drivers/timer/Kconfig.nrf_rtc | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/timer/Kconfig.nrf_rtc b/drivers/timer/Kconfig.nrf_rtc index f332113c00ad..5e64545067a6 100644 --- a/drivers/timer/Kconfig.nrf_rtc +++ b/drivers/timer/Kconfig.nrf_rtc @@ -8,6 +8,7 @@ config NRF_RTC_TIMER depends on CLOCK_CONTROL depends on SOC_COMPATIBLE_NRF select TICKLESS_CAPABLE + depends on !$(dt_nodelabel_enabled,rtc1) help This module implements a kernel device driver for the nRF Real Time Counter NRF_RTC1 and provides the standard "system clock driver" From b096e092fa786cda80ac80bf1e87ad4f71c533ec Mon Sep 17 00:00:00 2001 From: Romain Mahoux Date: Tue, 1 Nov 2022 09:09:22 +0100 Subject: [PATCH 0800/1906] drivers/apbuart: correct the baud formula The formula of set_baud first function was not consistent with the get_baud one. Signed-off-by: Romain Mahoux --- drivers/serial/uart_apbuart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/serial/uart_apbuart.c b/drivers/serial/uart_apbuart.c index 32659347d90a..a50fb126e0a7 100644 --- a/drivers/serial/uart_apbuart.c +++ b/drivers/serial/uart_apbuart.c @@ -225,7 +225,7 @@ static void set_baud(volatile struct apbuart_regs *const regs, uint32_t baud) core_clk_hz = sys_clock_hw_cycles_per_sec(); /* Calculate Baud rate generator "scaler" number */ - scaler = (((core_clk_hz * 10) / (baud * 8)) - 5) / 10; + scaler = (core_clk_hz / (baud * 8)) - 1; /* Set new baud rate by setting scaler */ regs->scaler = scaler; From fd94ca7e78e641462cd917dad197f655f76337be Mon Sep 17 00:00:00 2001 From: Pete Dietl Date: Mon, 27 Mar 2023 13:15:30 +0200 Subject: [PATCH 0801/1906] cmake: modules: Make modules.cmake check more precise When checking that modules contain a file `modules/modules.cmake`, the CMake file only actually checked for the existence of the module root, not the `modules/modules.cmake` file inside of it. Signed-off-by: Pete Dietl --- cmake/modules/zephyr_module.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmake/modules/zephyr_module.cmake b/cmake/modules/zephyr_module.cmake index 3dcae3ea61b5..05d13cf5f246 100644 --- a/cmake/modules/zephyr_module.cmake +++ b/cmake/modules/zephyr_module.cmake @@ -122,11 +122,12 @@ if(WEST OR ZEPHYR_MODULES) # later wins. therefore we reverse the list before processing. list(REVERSE MODULE_EXT_ROOT) foreach(root ${MODULE_EXT_ROOT}) - if(NOT EXISTS ${root}) - message(FATAL_ERROR "No `modules.cmake` found in module root `${root}`.") + set(module_cmake_file_path modules/modules.cmake) + if(NOT EXISTS ${root}/${module_cmake_file_path}) + message(FATAL_ERROR "No `${module_cmake_file_path}` found in module root `${root}`.") endif() - include(${root}/modules/modules.cmake) + include(${root}/${module_cmake_file_path}) endforeach() foreach(module ${zephyr_modules_txt}) From 4a39c0c49f037a2974efbd7b79d0e4a5814bdfb8 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Wed, 22 Mar 2023 15:45:54 -0700 Subject: [PATCH 0802/1906] tests: mem_protect/sys_sem: print FAILED when faulting If there are any CPU exceptions, printing a failed message would allow twister to stop early instead of waiting for timeout. Signed-off-by: Daniel Leung --- tests/kernel/mem_protect/sys_sem/src/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/kernel/mem_protect/sys_sem/src/main.c b/tests/kernel/mem_protect/sys_sem/src/main.c index 6ebac5c80dc3..5304c435e120 100644 --- a/tests/kernel/mem_protect/sys_sem/src/main.c +++ b/tests/kernel/mem_protect/sys_sem/src/main.c @@ -568,6 +568,14 @@ ZTEST_USER(sys_sem_1cpu, test_sem_multiple_threads_wait) * @} */ +void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) +{ + printk("Caught system error -- reason %d\n", reason); + printk("Unexpected fault during test\n"); + printk("PROJECT EXECUTION FAILED\n"); + k_fatal_halt(reason); +} + void *sys_sem_setup(void) { #ifdef CONFIG_USERSPACE From e35733d2ff62a892cd0a5209820e671a9586e038 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Wed, 22 Mar 2023 15:48:04 -0700 Subject: [PATCH 0803/1906] tests: mem_protect/syscalls: print FAILED when faulting If there are any CPU exceptions, printing a failed message would allow twister to stop early instead of waiting for timeout. Signed-off-by: Daniel Leung --- tests/kernel/mem_protect/syscalls/src/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/kernel/mem_protect/syscalls/src/main.c b/tests/kernel/mem_protect/syscalls/src/main.c index ccc4311e99ad..2e03c4090650 100644 --- a/tests/kernel/mem_protect/syscalls/src/main.c +++ b/tests/kernel/mem_protect/syscalls/src/main.c @@ -36,6 +36,14 @@ char kernel_string[BUF_SIZE]; char kernel_buf[BUF_SIZE]; ZTEST_BMEM char user_string[BUF_SIZE]; +void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf) +{ + printk("Caught system error -- reason %d\n", reason); + printk("Unexpected fault during test\n"); + printk("PROJECT EXECUTION FAILED\n"); + k_fatal_halt(reason); +} + size_t z_impl_string_nlen(char *src, size_t maxlen, int *err) { return z_user_string_nlen(src, maxlen, err); From 674e23820fdbe8434d4c53e9988d4e5ab6388dae Mon Sep 17 00:00:00 2001 From: Alexander Svensen Date: Tue, 21 Mar 2023 14:54:23 +0100 Subject: [PATCH 0804/1906] sd: Return ret if error in sdmmc_spi_read_cxd - Check OCR when sending CMD58, reject if 0 Signed-off-by: Alexander Svensen --- subsys/sd/sdmmc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/subsys/sd/sdmmc.c b/subsys/sd/sdmmc.c index 084df891e460..d29c99c0e59b 100644 --- a/subsys/sd/sdmmc.c +++ b/subsys/sd/sdmmc.c @@ -78,7 +78,17 @@ static int sdmmc_spi_send_ocr(struct sd_card *card, uint32_t arg) ret = sdhc_request(card->sdhc, &cmd, NULL); + if (ret) { + LOG_DBG("CMD58 failed: %d", ret); + return ret; + } + card->ocr = cmd.response[1]; + if (card->ocr == 0) { + LOG_DBG("No OCR detected"); + return -ENOTSUP; + } + return ret; } From 5ec4aaff5c676841dc1932096bd0606435fb0c26 Mon Sep 17 00:00:00 2001 From: Patryk Duda Date: Mon, 27 Mar 2023 15:00:47 +0200 Subject: [PATCH 0805/1906] boards: beagle_bcf: Fix undefined references to pinctrl and gpio device This patch fixes undefined references when compiling tests/drivers/flash for beagleconnect_freedom board using following command: west build -b beagleconnect_freedom tests/drivers/flash Adding CONFIG_PINCTRL fixes undefined references to 'pinctrl_lookup_state' and 'pinctrl_configure_pins'. Adding CONFIG_GPIO fixes undefined reference to '__device_dts_ord_13' from spi_nor and spi_cc13xx_cc26xx drivers. Fixes #56181 Signed-off-by: Patryk Duda --- boards/arm/beagle_bcf/beagleconnect_freedom_defconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/boards/arm/beagle_bcf/beagleconnect_freedom_defconfig b/boards/arm/beagle_bcf/beagleconnect_freedom_defconfig index dce21b525e6d..af58105267c9 100644 --- a/boards/arm/beagle_bcf/beagleconnect_freedom_defconfig +++ b/boards/arm/beagle_bcf/beagleconnect_freedom_defconfig @@ -5,6 +5,9 @@ # SPDX-License-Identifier: Apache-2.0 # +CONFIG_GPIO=y +CONFIG_PINCTRL=y + CONFIG_SOC_SERIES_CC13X2X7_CC26X2X7=y CONFIG_SOC_CC1352P7=y CONFIG_BOARD_BEAGLECONNECT_FREEDOM=y From f7f47dc43772f383528673dfa57cecbc5b4a711f Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Tue, 21 Mar 2023 17:26:23 +0100 Subject: [PATCH 0806/1906] drivers: adc: stm32 adc driver must wait about 1ms after enabling After enabling the ADC, the peripheral has a certain delay (about 1ms) to set its ADC Ready flag in the ADC ISR register. In between, the ADRDY is still 0 and the ADEN is 1 in the CR. The ADC can be used for conversion, only when the ADRDY bit is set Signed-off-by: Francois Ramu --- drivers/adc/adc_stm32.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/adc/adc_stm32.c b/drivers/adc/adc_stm32.c index f5cb173db080..a6c7fd571330 100644 --- a/drivers/adc/adc_stm32.c +++ b/drivers/adc/adc_stm32.c @@ -666,21 +666,21 @@ static int adc_stm32_enable(ADC_TypeDef *adc) LL_ADC_ClearFlag_ADRDY(adc); LL_ADC_Enable(adc); - /* - * Enabling ADC modules in L4, WB, G0 and G4 series may fail if they are - * still not stabilized, this will wait for a short time to ensure ADC - * modules are properly enabled. + * Enabling ADC modules in WL, L4, WB, G0 and G4 series may fail if they are + * still not stabilized, this will wait for a short time (about 1ms) + * to ensure ADC modules are properly enabled. */ uint32_t count_timeout = 0; while (LL_ADC_IsActiveFlag_ADRDY(adc) == 0) { if (LL_ADC_IsEnabled(adc) == 0UL) { LL_ADC_Enable(adc); - count_timeout++; - if (count_timeout == 10) { - return -ETIMEDOUT; - } + } + count_timeout++; + k_busy_wait(100); + if (count_timeout >= 10) { + return -ETIMEDOUT; } } #else From 3af095b122716ec2e9806eb1dccc5d6574ba2315 Mon Sep 17 00:00:00 2001 From: Declan Snyder Date: Mon, 27 Mar 2023 17:33:55 -0500 Subject: [PATCH 0807/1906] drivers: pinctrl: pinctrl_kinetis: Fix port array Fix port array definition in kinetis pinctrl driver so that it handles more flexibly the cases where the number of PORT peripherals is more than 3, rather than only handling the case where there are 5. Signed-off-by: Declan Snyder --- drivers/pinctrl/pinctrl_kinetis.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/pinctrl/pinctrl_kinetis.c b/drivers/pinctrl/pinctrl_kinetis.c index ae3aaa71b3f5..1f2973b571f6 100644 --- a/drivers/pinctrl/pinctrl_kinetis.c +++ b/drivers/pinctrl/pinctrl_kinetis.c @@ -15,8 +15,10 @@ static PORT_Type *ports[] = { (PORT_Type *)DT_REG_ADDR(DT_NODELABEL(porta)), (PORT_Type *)DT_REG_ADDR(DT_NODELABEL(portb)), (PORT_Type *)DT_REG_ADDR(DT_NODELABEL(portc)), -#if DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 5 +#if DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) > 3 (PORT_Type *)DT_REG_ADDR(DT_NODELABEL(portd)), +#endif +#if DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) > 4 (PORT_Type *)DT_REG_ADDR(DT_NODELABEL(porte)), #endif }; From af01a0f31398e3b63df568f052e449a130c30a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Battrel?= Date: Fri, 24 Mar 2023 09:56:04 +0100 Subject: [PATCH 0808/1906] Bluetooth: Logging: Move all logging symbols together MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move all Kconfig symbols related to Bluetooth logging into the newly created `Kconfig.logging`. The logging symbols are now grouped by into a menu "Bluetooth logging". Closely related symbols are grouped with each others. For example, audio related logging symbol are found behind a submenu "Audio" inside the "Bluetooth logging". The deprecated logging symbols have also been moved in a submenu of "Bluetooth logging", it's easier to avoid them so. Behavior of the Bluetooth logging system: When `LOG` symbol is selected, if Bluetooth is enabled (`BT` symbol selected), the Bluetooth logging is enabled. If the user does not set any log level, the Bluetooth logging symbols will inherit the log level of `BT_LOG_LEVEL`. If the user does not set the level of `BT_LOG_LEVEL`, the default log level will be the one defined by the logging subsystem. Which currently is `LOG_LEVEL_INF`. Signed-off-by: Théo Battrel --- subsys/bluetooth/Kconfig | 5 +- subsys/bluetooth/Kconfig.logging | 1083 +++++++++++++++++++++ subsys/bluetooth/audio/Kconfig.aics | 32 - subsys/bluetooth/audio/Kconfig.bap | 113 --- subsys/bluetooth/audio/Kconfig.cap | 36 - subsys/bluetooth/audio/Kconfig.csip | 41 - subsys/bluetooth/audio/Kconfig.has | 23 - subsys/bluetooth/audio/Kconfig.mcs | 30 - subsys/bluetooth/audio/Kconfig.mctl | 11 - subsys/bluetooth/audio/Kconfig.micp | 28 - subsys/bluetooth/audio/Kconfig.mpl | 11 - subsys/bluetooth/audio/Kconfig.pacs | 13 - subsys/bluetooth/audio/Kconfig.tbs | 29 - subsys/bluetooth/audio/Kconfig.vcp | 28 - subsys/bluetooth/audio/Kconfig.vocs | 32 - subsys/bluetooth/common/Kconfig | 30 - subsys/bluetooth/crypto/Kconfig | 17 - subsys/bluetooth/host/Kconfig | 173 ---- subsys/bluetooth/host/Kconfig.gatt | 28 - subsys/bluetooth/host/Kconfig.l2cap | 13 - subsys/bluetooth/lib/Kconfig | 5 - subsys/bluetooth/mesh/Kconfig | 233 ----- subsys/bluetooth/services/Kconfig.bas | 10 +- subsys/bluetooth/services/Kconfig.hrs | 4 - subsys/bluetooth/services/Kconfig.tps | 10 +- subsys/bluetooth/services/ias/Kconfig.ias | 16 - subsys/bluetooth/services/ots/Kconfig | 22 - 27 files changed, 1086 insertions(+), 990 deletions(-) create mode 100644 subsys/bluetooth/Kconfig.logging diff --git a/subsys/bluetooth/Kconfig b/subsys/bluetooth/Kconfig index 83c4d9d7cccc..568427e7d12c 100644 --- a/subsys/bluetooth/Kconfig +++ b/subsys/bluetooth/Kconfig @@ -15,10 +15,6 @@ menuconfig BT if BT -module = BT -module-str = bt -source "subsys/logging/Kconfig.template.log_config" - choice BT_STACK_SELECTION prompt "Bluetooth Stack Selection" default BT_HCI @@ -188,6 +184,7 @@ rsource "controller/Kconfig" rsource "shell/Kconfig" rsource "crypto/Kconfig" rsource "lib/Kconfig" +rsource "Kconfig.logging" endif # BT_HCI diff --git a/subsys/bluetooth/Kconfig.logging b/subsys/bluetooth/Kconfig.logging new file mode 100644 index 000000000000..68fb2274deb8 --- /dev/null +++ b/subsys/bluetooth/Kconfig.logging @@ -0,0 +1,1083 @@ +# Bluetooth logging configuration options + +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +menuconfig BT_LOG + bool "Bluetooth logging" + default y if LOG && BT + imply LOG_FUNC_NAME_PREFIX_INF + imply LOG_FUNC_NAME_PREFIX_WRN + imply LOG_FUNC_NAME_PREFIX_ERR + imply LOG_FUNC_NAME_PREFIX_DBG + select BT_DEBUG + select BT_LOG_LEGACY + +if BT_LOG + +menuconfig BT_LOG_LEGACY + bool "Bluetooth legacy logging options" + +if BT_LOG_LEGACY + +# COMMON + +config BT_DEBUG_HCI_DRIVER + bool "[DEPRECATED] Bluetooth HCI driver debug" + select DEPRECATED + help + This option enables debug support for the active + Bluetooth HCI driver, including the Controller-side HCI layer + when included in the build. + +config BT_DEBUG_RPA + bool "[DEPRECATED] Bluetooth Resolvable Private Address (RPA) debug" + select DEPRECATED + depends on BT_RPA + help + This option enables debug support for the Bluetooth + Resolvable Private Address (RPA) generation and resolution. + +menu "[DEPRECATED] Audio" + +# AICS + +config BT_DEBUG_AICS + bool "[DEPRECATED] Audio Input Control Service debug" + select DEPRECATED + help + Use this option to enable Audio Input Control Service debug logs for + the Bluetooth Audio functionality. + +config BT_DEBUG_AICS_CLIENT + bool "[DEPRECATED] Audio Input Control Service client debug" + select DEPRECATED + help + Use this option to enable Audio Input Control Service client debug + logs for the Bluetooth Audio functionality. + +# BAP + +config BT_BAP_DEBUG_STREAM + bool "[DEPRECATED] Basic Audio Profile Stream debug" + select DEPRECATED + depends on BT_BAP_STREAM + help + Use this option to enable Basic Audio Profile Stream debug logs. + +config BT_DEBUG_ASCS + bool "[DEPRECATED] Audio Stream Control Service debug" + select DEPRECATED + depends on BT_ASCS + help + Use this option to enable Audio Stream Control Service debug logs for + the Bluetooth Audio functionality. + +config BT_DEBUG_BAP_UNICAST_SERVER + bool "[DEPRECATED] Bluetooth Audio Unicast Server debug" + select DEPRECATED + depends on BT_BAP_UNICAST_SERVER + help + Use this option to enable Bluetooth Audio Unicast Server debug logs + for the Bluetooth Audio functionality. + +config BT_DEBUG_BAP_UNICAST_CLIENT + bool "[DEPRECATED] Basic Audio Profile client debug" + select DEPRECATED + depends on BT_BAP_UNICAST_CLIENT + help + Use this option to enable Basic Audio Profile debug logs for the + Bluetooth Audio functionality. + +config BT_DEBUG_BAP_BROADCAST_SOURCE + bool "[DEPRECATED] Bluetooth Audio Broadcast Source debug" + select DEPRECATED + depends on BT_BAP_BROADCAST_SOURCE + help + Use this option to enable Bluetooth Audio Broadcast Source debug logs + for the Bluetooth Audio functionality. + +config BT_DEBUG_BAP_BROADCAST_SINK + bool "[DEPRECATED] Bluetooth Audio Broadcast Sink debug" + select DEPRECATED + depends on BT_BAP_BROADCAST_SINK + help + Use this option to enable Bluetooth Audio Broadcast Sink debug logs + for the Bluetooth Audio functionality. + +config BT_DEBUG_BAP_SCAN_DELEGATOR + bool "[DEPRECATED] Broadcast Audio Scan Service debug" + select DEPRECATED + depends on BT_BAP_SCAN_DELEGATOR + help + Use this option to enable Broadcast Audio Scan Service debug logs for + the Bluetooth Audio functionality. + +config BT_DEBUG_BAP_BROADCAST_ASSISTANT + bool "[DEPRECATED] Broadcast Audio Scan Service client debug" + select DEPRECATED + depends on BT_BAP_BROADCAST_ASSISTANT + help + Use this option to enable Broadcast Audio Scan Service client + debug logs for the Bluetooth Audio functionality. + +# CAP + +config BT_DEBUG_CAP_ACCEPTOR + bool "[DEPRECATED] Common Audio Profile debug" + select DEPRECATED + depends on BT_CAP_ACCEPTOR + help + Use this option to enable CAP debug logs for the + Bluetooth Audio functionality. + +config BT_DEBUG_CAP_INITIATOR + bool "[DEPRECATED] Common Audio Profile Initiator debug" + select DEPRECATED + depends on BT_CAP_INITIATOR + help + Use this option to enable CAP Initiator debug logs for the + Bluetooth Audio functionality. + +# CISP + +config BT_DEBUG_CSIP_SET_MEMBER + bool "[DEPRECATED] Coordinated Set Identification Service debug" + select DEPRECATED + help + Use this option to enable Coordinated Set Identification Service debug + logs for the Bluetooth Audio functionality. + +config BT_DEBUG_CSIP_SET_COORDINATOR + bool "[DEPRECATED] Coordinated Set Identification Profile Set Coordinator debug" + select DEPRECATED + help + Use this option to enable Coordinated Set Identification Profile + Set Coordinator debug logs for the Bluetooth Audio functionality. + +config BT_DEBUG_CSIP_SET_MEMBER_CRYPTO + bool "[DEPRECATED] Coordinated Set Identification Profile crypto functions debug" + select DEPRECATED + depends on BT_CSIP_SET_COORDINATOR || BT_CSIP_SET_MEMBER + help + Use this option to enable Coordinated Set Identification Profile + crypto functions debug logs for the Bluetooth Audio functionality. + +# HAS + +config BT_DEBUG_HAS + bool "[DEPRECATED] Hearing Access Service debug" + select DEPRECATED + help + This option enables enables Hearing Access Service debug logs. + +config BT_DEBUG_HAS_CLIENT + bool "[DEPRECATED] Hearing Access Service Client debug" + select DEPRECATED + depends on BT_HAS_CLIENT + help + This option enables enables Hearing Access Service Client debug logs. + +# MCS + +config BT_DEBUG_MCS + bool "[DEPRECATED] Media Control Service debug" + select DEPRECATED + help + Use this option to enable Media Control Service debug logs for the + Bluetooth Audio functionality. + +config BT_DEBUG_MCC + bool "[DEPRECATED] Media Control Client debug" + select DEPRECATED + help + Use this option to enable Media Control Client debug logs for the + Bluetooth Audio functionality. + +# MCTL + +config MCTL_DEBUG + bool "[DEPRECATED] Media control debug" + select DEPRECATED + help + Use this option to enable Media control debug logs + +# MICP + +config BT_DEBUG_MICP_MIC_DEV + bool "[DEPRECATED] Microphone Control Profile Microphone Device debug" + select DEPRECATED + help + Use this option to enable Microphone Control Profile + Microphone Device debug logs for the Bluetooth Audio functionality. + +config BT_DEBUG_MICP_MIC_CTLR + bool "[DEPRECATED] Microphone Control Profile Microphone Controller debug" + select DEPRECATED + help + Use this option to enable Microphone Control Profile Microphone + Controller debug logs for the Bluetooth Audio functionality. + +# MPL + +config BT_DEBUG_MPL + bool "[DEPRECATED] Media player debug" + select DEPRECATED + help + Enables debug logs for the media player + +# PACS + +config BT_DEBUG_PACS + bool "[DEPRECATED] Published Audio Capabilities Service debug" + select DEPRECATED + depends on BT_PACS + help + Use this option to enable Published Audio Capabilities Service debug + logs for the Bluetooth Audio functionality. + +# TBS + +config BT_DEBUG_TBS + bool "[DEPRECATED] Telephone Bearer Service debug" + select DEPRECATED + help + Use this option to enable Telephone Bearer Service debug logs for the + Bluetooth Audio functionality. + +config BT_DEBUG_TBS_CLIENT + bool "[DEPRECATED] Telephone Bearer Service client debug" + select DEPRECATED + help + Use this option to enable Telephone Bearer Service client debug logs + for the Bluetooth Audio functionality. + +# VCP + +config BT_DEBUG_VCP_VOL_REND + bool "[DEPRECATED] Volume Control Profile Volume Renderer debug" + select DEPRECATED + help + Use this option to enable Volume Control Profile debug logs for the + Bluetooth Audio functionality. + +config BT_DEBUG_VCP_VOL_CTLR + bool "[DEPRECATED] Volume Control Profile Volume Controller debug" + select DEPRECATED + help + Use this option to enable Volume Control Profile Volume Controller + debug logs for the Bluetooth Audio functionality. + +# VOCS + +config BT_DEBUG_VOCS + bool "[DEPRECATED] Volume Offset Control Service debug" + select DEPRECATED + help + Use this option to enable Volume Offset Control Service debug logs for + the Bluetooth Audio functionality. + +config BT_DEBUG_VOCS_CLIENT + bool "[DEPRECATED] Volume Offset Control Service client debug" + select DEPRECATED + help + Use this option to enable Volume Offset Control Service client debug + logs for the Bluetooth Audio functionality. + +endmenu # [DEPRECATED] Audio + +menu "[DEPRECATED] Others" + +# CRYPTO (subsys/bluetooth/crypto/Kconfig) + +config BT_DEBUG_CRYPTO + bool "[DEPRECATED] Bluetooth Cryptographic Toolbox debug" + select DEPRECATED + depends on BT_CRYPTO + help + This option enables debug log output for the Bluetooth + Cryptographic Toolbox. + + WARNING: This option prints out private security keys such as + the Long Term Key. + Use of this feature in production is strongly discouraged. + +# GATT + +config BT_DEBUG_ATT + bool "[DEPRECATED] Bluetooth Attribute Protocol (ATT) debug" + select DEPRECATED + help + This option enables debug support for the Bluetooth + Attribute Protocol (ATT). + +config BT_DEBUG_GATT + bool "[DEPRECATED] Bluetooth Generic Attribute Profile (GATT) debug" + select DEPRECATED + help + This option enables debug support for the Bluetooth + Generic Attribute Profile (GATT). + +# L2CAP + +config BT_DEBUG_L2CAP + bool "[DEPRECATED] Bluetooth L2CAP debug" + select DEPRECATED + depends on BT_DEBUG + help + This option enables debug support for the Bluetooth + L2ACP layer. + +# HOST (subsys/bluetooth/host/Kconfig) + +config BT_DEBUG_DF + bool "[DEPRECATED] Bluetooth Direction Finding debug" + select DEPRECATED + help + This option enables debug support for Bluetooth Direction Finding + +config BT_DEBUG_SETTINGS + bool "[DEPRECATED] Bluetooth storage debug" + select DEPRECATED + depends on BT_SETTINGS + help + This option enables debug support for Bluetooth storage. + +config BT_DEBUG_HCI_CORE + bool "[DEPRECATED] Bluetooth HCI core debug" + select DEPRECATED + help + This option enables debug support for Bluetooth HCI + core. + +config BT_DEBUG_CONN + bool "[DEPRECATED] Bluetooth connection debug" + select DEPRECATED + depends on BT_CONN || BT_ISO + help + This option enables debug support for Bluetooth + connection handling. + +config BT_DEBUG_ISO + bool "[DEPRECATED] ISO channel debug" + select DEPRECATED + help + Use this option to enable ISO channels debug logs for the + Bluetooth Audio functionality. + +config BT_DEBUG_KEYS + bool "[DEPRECATED] Bluetooth security keys debug" + select DEPRECATED + depends on BT_HCI_HOST + depends on BT_SMP + help + This option enables debug support for the handling of + Bluetooth security keys. + + WARNING: This option prints out private security keys such as + the Long Term Key. + Use of this feature in production is strongly discouraged. + +config BT_DEBUG_SMP + bool "[DEPRECATED] Bluetooth Security Manager Protocol (SMP) debug" + select DEPRECATED + depends on BT_HCI_HOST + depends on BT_SMP + help + This option enables debug support for the Bluetooth + Security Manager Protocol (SMP). + + WARNING: This option prints out private security keys such as + the Long Term Key. + Use of this feature in production is strongly discouraged. + +config BT_DEBUG_SERVICE + bool "[DEPRECATED] Bluetooth Services debug" + select DEPRECATED + depends on BT_CONN + help + This option enables debug support for the Bluetooth + Services. + +endmenu # [DEPRECATED] Others + +menu "[DEPRECATED] BR/EDR" + +config BT_DEBUG_RFCOMM + bool "[DEPRECATED] Bluetooth RFCOMM debug" + select DEPRECATED + depends on BT_RFCOMM + help + This option enables debug support for the Bluetooth + RFCOMM layer. + +config BT_DEBUG_HFP_HF + bool "[DEPRECATED] Bluetooth Hands Free Profile (HFP) debug" + select DEPRECATED + depends on BT_HFP_HF + help + This option enables debug support for the Bluetooth + Hands Free Profile (HFP). + +config BT_DEBUG_AVDTP + bool "[DEPRECATED] Bluetooth AVDTP debug" + select DEPRECATED + depends on BT_AVDTP + help + This option enables debug support for the Bluetooth AVDTP. + +config BT_DEBUG_A2DP + bool "[DEPRECATED] Bluetooth A2DP debug" + select DEPRECATED + depends on BT_A2DP + help + This option enables debug support for the Bluetooth + A2DP profile. + +config BT_DEBUG_SDP + bool "[DEPRECATED] Bluetooth Service Discovery Protocol (SDP) debug" + select DEPRECATED + depends on BT_BREDR + help + This option enables debug support for the Bluetooth + Service Discovery Protocol (SDP). + +endmenu # [DEPRECATED] BR/EDR + +# MESH (subsys/bluetooth/mesh/Kconfig) + +menu "[DEPRECATED] Mesh" + +config BT_MESH_DEBUG + bool "[DEPRECATED] Debug logs" + select DEPRECATED + depends on BT_DEBUG + help + Use this option to enable debug logs for the Bluetooth + Mesh functionality. + +config BT_MESH_DEBUG_NET + bool "[DEPRECATED] Network layer debug" + select DEPRECATED + help + Use this option to enable Network layer debug logs for the + Bluetooth mesh functionality. + +config BT_MESH_DEBUG_RPL + bool "[DEPRECATED] Replay protection list debug" + select DEPRECATED + help + Use this option to enable Replay protection list debug logs + for the Bluetooth mesh functionality. + +config BT_MESH_DEBUG_TRANS + bool "[DEPRECATED] Transport layer debug" + select DEPRECATED + help + Use this option to enable Transport layer debug logs for the + Bluetooth mesh functionality. + +config BT_MESH_DEBUG_BEACON + bool "[DEPRECATED] Beacon debug" + select DEPRECATED + help + Use this option to enable Beacon-related debug logs for the + Bluetooth mesh functionality. + +config BT_MESH_DEBUG_CRYPTO + bool "[DEPRECATED] Crypto debug" + select DEPRECATED + help + Use this option to enable cryptographic debug logs for the + Bluetooth mesh functionality. + +config BT_MESH_DEBUG_KEYS + bool "[DEPRECATED] Key management debug" + select DEPRECATED + help + Use this option to enable key management debug logs for the + Bluetooth mesh functionality. + +config BT_MESH_DEBUG_PROV + bool "[DEPRECATED] Provisioning debug" + select DEPRECATED + help + Use this option to enable Provisioning debug logs for the + Bluetooth mesh functionality. + +config BT_MESH_DEBUG_PROVISIONER + bool "[DEPRECATED] Provisioner debug" + select DEPRECATED + help + Use this option to enable Provisioner debug logs for the + Bluetooth mesh functionality. + +config BT_MESH_DEBUG_PROV_DEVICE + bool "[DEPRECATED] Provisioning device debug" + select DEPRECATED + help + Use this option to enable Provisioning device debug logs for the + Bluetooth Mesh functionality. + +config BT_MESH_DEBUG_ACCESS + bool "[DEPRECATED] Access layer debug" + select DEPRECATED + help + Use this option to enable Access layer and device composition + related debug logs for Bluetooth mesh. + +config BT_MESH_DEBUG_MODEL + bool "[DEPRECATED] Foundation model debug" + select DEPRECATED + help + Use this option to enable debug logs for the Foundation + Models. + +config BT_MESH_DEBUG_ADV + bool "[DEPRECATED] Advertising debug" + select DEPRECATED + help + Use this option to enable advertising debug logs for + the Bluetooth mesh functionality. + +config BT_MESH_DEBUG_LOW_POWER + bool "[DEPRECATED] Low Power debug" + select DEPRECATED + help + Use this option to enable Low Power debug logs for the + Bluetooth mesh functionality. + +config BT_MESH_DEBUG_FRIEND + bool "[DEPRECATED] Friend debug" + select DEPRECATED + help + Use this option to enable Friend debug logs for the + Bluetooth mesh functionality. + +config BT_MESH_DEBUG_PROXY + bool "[DEPRECATED] Proxy debug" + select DEPRECATED + depends on BT_MESH_GATT + help + Use this option to enable Proxy protocol debug logs. + +config BT_MESH_DEBUG_SETTINGS + bool "[DEPRECATED] Persistent settings debug" + select DEPRECATED + depends on BT_SETTINGS + help + Use this option to enable persistent settings debug logs. + +config BT_MESH_DEBUG_CDB + bool "[DEPRECATED] Configuration database debug" + select DEPRECATED + depends on BT_MESH_CDB + help + Use this option to enable configuration database debug logs. + +config BT_MESH_DEBUG_CFG + bool "[DEPRECATED] Configuration debug" + select DEPRECATED + help + Use this option to enable node configuration debug logs for the + Bluetooth mesh functionality. + +endmenu # [DEPRECATED] Mesh + +menu "[DEPRECATED] Services" + +# IAS + +config BT_DEBUG_IAS_CLIENT + bool "[DEPRECATED] Immediate Alert Service Client debug" + select DEPRECATED + depends on BT_IAS_CLIENT + help + This option enables enables Immediate Alert Service Client debug logs. + +# OTS + +# TODO: Unify logging for OTS server and client - the client uses +# "BT" debugging, the server does not. + +config BT_DEBUG_OTS_CLIENT + bool "[DEPRECATED] Object Transfer Service Client debug" + select DEPRECATED + help + Use this option to enable Object Transfer Client debug logs + +endmenu # [DEPRECATED] Services + +endif # BT_DEPRECATED_LOG + +# (subsys/bluetooth/Kconfig) + +module = BT +module-str = "Bluetooth" +source "subsys/logging/Kconfig.template.log_config" + +# COMMON (subsys/bluetooth/common/Kconfig) + +module = BT_HCI_DRIVER +legacy-debug-sym = BT_DEBUG_HCI_DRIVER +module-str = "Bluetooth HCI driver" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_RPA +legacy-debug-sym = BT_DEBUG_RPA +module-str = "Bluetooth Resolvable Private Address (RPA)" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +menu "Audio" + +# AICS + +module = BT_AICS +legacy-debug-sym = BT_DEBUG_AICS +module-str = "Audio Input Control Service" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_AICS_CLIENT +legacy-debug-sym = BT_DEBUG_AICS_CLIENT +module-str = "Audio Input Control Service client" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +# BAP + +module = BT_BAP_STREAM +legacy-debug-sym = BT_BAP_DEBUG_STREAM +module-str = "Bluetooth Audio Stream" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +parent-module = BT +module = BT_AUDIO_CODEC +module-str = "Bluetooth Audio Codec" +source "subsys/logging/Kconfig.template.log_config_inherit" + +module = BT_ASCS +legacy-debug-sym = BT_DEBUG_ASCS +module-str = "Audio Stream Control Service" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_BAP_UNICAST_SERVER +legacy-debug-sym = BT_DEBUG_BAP_UNICAST_SERVER +module-str = "Bluetooth Audio Unicast Server" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_BAP_UNICAST_CLIENT +legacy-debug-sym = BT_DEBUG_BAP_UNICAST_CLIENT +module-str = "Basic Audio Profile" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_BAP_BROADCAST_SOURCE +legacy-debug-sym = BT_DEBUG_BAP_BROADCAST_SOURCE +module-str = "Bluetooth Audio Broadcast Source" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_BAP_BROADCAST_SINK +legacy-debug-sym = BT_DEBUG_BAP_BROADCAST_SINK +module-str = "Bluetooth Audio Broadcast Sink" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_BAP_SCAN_DELEGATOR +legacy-debug-sym = BT_DEBUG_BAP_SCAN_DELEGATOR +module-str = "Broadcast Audio Scan Service" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_BAP_BROADCAST_ASSISTANT +legacy-debug-sym = BT_DEBUG_BAP_BROADCAST_ASSISTANT +module-str = "Broadcast Audio Scan Service client debug" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +parent-module = BT +module = BT_BAP_ISO +module-str = "Bluetooth Audio ISO" +source "subsys/logging/Kconfig.template.log_config_inherit" + +# CAP + +module = BT_CAP_ACCEPTOR +legacy-debug-sym = BT_DEBUG_CAP_ACCEPTOR +module-str = "Common Audio Profile Acceptor" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_CAP_INITIATOR +legacy-debug-sym = BT_DEBUG_CAP_INITIATOR +module-str = "Common Audio Profile Initiator" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +parent-module = BT +module = BT_CAP_STREAM +module-str = "Common Audio Profile Stream" +source "subsys/logging/Kconfig.template.log_config_inherit" + +# CSIP + +module = BT_CSIP_SET_MEMBER +legacy-debug-sym = BT_DEBUG_CSIP_SET_MEMBER +module-str = "Coordinated Set Identification Service" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_CSIP_SET_COORDINATOR +legacy-debug-sym = BT_DEBUG_CSIP_SET_COORDINATOR +module-str = "Coordinated Set Identification Profile Set Coordinator" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_CSIP_SET_MEMBER_CRYPTO +legacy-debug-sym = BT_DEBUG_CSIP_SET_MEMBER_CRYPTO +module-str = "Coordinated Set Identification Profile crypto functions" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +# HAS + +module = BT_HAS +legacy-debug-sym = BT_DEBUG_HAS +module-str = "Hearing Access Service" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_HAS_CLIENT +legacy-debug-sym = BT_DEBUG_HAS_CLIENT +module-str = "Hearing Access Service Client" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +# MCS + +module = BT_MCS +legacy-debug-sym = BT_DEBUG_MCS +module-str = "Media Control Service" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MCC +legacy-debug-sym = BT_DEBUG_MCC +module-str = "Media Control Client" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +# MCTL + +module = MCTL +legacy-debug-sym = MCTL_DEBUG +module-str = "Media control" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +# MICP + +module = BT_MICP_MIC_DEV +legacy-debug-sym = BT_DEBUG_MICP_MIC_DEV +module-str = "Microphone Control Profile Microphone Device" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MICP_MIC_CTLR +legacy-debug-sym = BT_DEBUG_MICP_MIC_CTLR +module-str = "Microphone Control Profile Microphone Controller" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +# MPL + +module = BT_MPL +legacy-debug-sym = BT_DEBUG_MPL +module-str = "Media player" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +# PACS + +module = BT_PACS +legacy-debug-sym = BT_DEBUG_PACS +module-str = "Published Audio Capabilities Service" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +# TBS + +module = BT_TBS +legacy-debug-sym = BT_DEBUG_TBS +module-str = "Telephone Bearer Service" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_TBS_CLIENT +legacy-debug-sym = BT_DEBUG_TBS_CLIENT +module-str = "Telephone Bearer Service client" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +# VCP + +module = BT_VCP_VOL_REND +legacy-debug-sym = BT_DEBUG_VCP_VOL_REND +module-str = "Volume Control Profile Voluem Renderer" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_VCP_VOL_CTLR +legacy-debug-sym = BT_DEBUG_VCP_VOL_CTLR +module-str = "Volume Control Profile Volume Controller" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +# VOCS + +module = BT_VOCS +legacy-debug-sym = BT_DEBUG_VOCS +module-str = "Volume Offset Control Service" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_VOCS_CLIENT +legacy-debug-sym = BT_DEBUG_VOCS_CLIENT +module-str = "Volume Offset Control Service client" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +endmenu # Audio + +menu "Others" + +# CRYPTO (subsys/bluetooth/crypto/Kconfig) + +module = BT_CRYPTO +legacy-debug-sym = BT_DEBUG_CRYPTO +module-str = "Bluetooth Cryptographic Toolbox" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +# GATT + +module = BT_ATT +legacy-debug-sym = BT_DEBUG_ATT +module-str = "Bluetooth Attribute Protocol (ATT)" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_GATT +legacy-debug-sym = BT_DEBUG_GATT +module-str = "Bluetooth Generic Attribute Profile (GATT)" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +# L2CAP + +module = BT_L2CAP +legacy-debug-sym = BT_DEBUG_L2CAP +module-str = "Bluetooth L2CAP" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +# LIB (subsys/bluetooth/lib/Kconfig) + +parent-module = BT +module = BT_EAD +module-str = "Bluetooth Encrypted Advertising Data" +source "subsys/logging/Kconfig.template.log_config_inherit" + +# HOST (subsys/bluetooth/host/Kconfig) + +module = BT_DF +legacy-debug-sym = BT_DEBUG_DF +module-str = "Bluetooth Direction Finding" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_SETTINGS +legacy-debug-sym = BT_DEBUG_SETTINGS +module-str = "Bluetooth storage" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_HCI_CORE +legacy-debug-sym = BT_DEBUG_HCI_CORE +module-str = "Bluetooth HCI core" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_CONN +legacy-debug-sym = BT_DEBUG_CONN +module-str = "Bluetooth connection" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_ISO +legacy-debug-sym = BT_DEBUG_ISO +module-str = "ISO channel" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_KEYS +legacy-debug-sym = BT_DEBUG_KEYS +module-str = "Bluetooth security keys" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_SMP +legacy-debug-sym = BT_DEBUG_SMP +module-str = "Bluetooth Security Manager Protocol" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_SERVICE +legacy-debug-sym = BT_DEBUG_SERVICE +module-str = "Bluetooth Services" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +endmenu # Others + +menu "BR/EDR" + +module = BT_RFCOMM +legacy-debug-sym = BT_DEBUG_RFCOMM +module-str = "Bluetooth RFCOMM" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_HFP_HF +legacy-debug-sym = BT_DEBUG_HFP_HF +module-str = "Bluetooth Hands Free Profile (HFP)" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_AVDTP +legacy-debug-sym = BT_DEBUG_AVDTP +module-str = "Bluetooth AVDTP debug" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_A2DP +legacy-debug-sym = BT_DEBUG_A2DP +module-str = "Bluetooth A2DP" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_SDP +legacy-debug-sym = BT_DEBUG_SDP +module-str = "Bluetooth Service Discovery Protocol (SDP)" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +endmenu # BR/EDR + +# MESH (subsys/bluetooth/mesh/Kconfig) + +menu "Mesh" + +module = BT_MESH +legacy-debug-sym = BT_MESH_DEBUG +module-str = "Debug logs" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_NET +legacy-debug-sym = BT_MESH_DEBUG_NET +module-str = "Network layer" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_RPL +legacy-debug-sym = BT_MESH_DEBUG_RPL +module-str = "Replay protection list" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_TRANS +legacy-debug-sym = BT_MESH_DEBUG_TRANS +module-str = "Transport layer" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_BEACON +legacy-debug-sym = BT_MESH_DEBUG_BEACON +module-str = "Beacon" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_CRYPTO +legacy-debug-sym = BT_MESH_DEBUG_CRYPTO +module-str = "Crypto" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_KEYS +legacy-debug-sym = BT_MESH_DEBUG_KEYS +module-str = "Key management" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_PROV +legacy-debug-sym = BT_MESH_DEBUG_PROV +module-str = "Provisioning" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_PROVISIONER +legacy-debug-sym = BT_MESH_DEBUG_PROVISIONER +module-str = "Provisioner" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_PROV_DEVICE +legacy-debug-sym = BT_MESH_DEBUG_PROV_DEVICE +module-str = "Provisioning device" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_ACCESS +legacy-debug-sym = BT_MESH_DEBUG_ACCESS +module-str = "Access layer" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_MODEL +legacy-debug-sym = BT_MESH_DEBUG_MODEL +module-str = "Foundation model" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_DFU +module-str = "DFU model" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_ADV +legacy-debug-sym = BT_MESH_DEBUG_ADV +module-str = "Advertising" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_LOW_POWER +legacy-debug-sym = BT_MESH_DEBUG_LOW_POWER +module-str = "Low Power" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_FRIEND +legacy-debug-sym = BT_MESH_DEBUG_FRIEND +module-str = "Friend" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_PROXY +legacy-debug-sym = BT_MESH_DEBUG_PROXY +module-str = "Proxy" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_SETTINGS +legacy-debug-sym = BT_MESH_DEBUG_SETTINGS +module-str = "Persistent settings" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_CDB +legacy-debug-sym = BT_MESH_DEBUG_CDB +module-str = "Configuration database" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_MESH_CFG +legacy-debug-sym = BT_MESH_DEBUG_CFG +module-str = "Configuration" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +endmenu # Mesh + +menu "Services" + +# BAS + +module = BT_BAS +module-str = BAS +source "subsys/logging/Kconfig.template.log_config" + +# HRS + +module = BT_HRS +module-str = HRS +source "subsys/logging/Kconfig.template.log_config" + +# TPS + +module = BT_TPS +module-str = TPS +source "subsys/logging/Kconfig.template.log_config" + +# IAS + +module = BT_IAS_CLIENT +legacy-debug-sym = BT_DEBUG_IAS_CLIENT +module-str = "Immediate Alert Service Client" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_IAS +module-str = IAS +source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config" + +# OTS (subsys/bluetooth/services/ots/Kconfig) + +module = BT_OTS_CLIENT +legacy-debug-sym = BT_DEBUG_OTS_CLIENT +module-str = "Object Transfer Service Client" +source "subsys/bluetooth/common/Kconfig.template.log_config_bt" + +module = BT_OTS +module-str = BT_OTS +source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config" + +endmenu # Services + +endif # BT_LOG diff --git a/subsys/bluetooth/audio/Kconfig.aics b/subsys/bluetooth/audio/Kconfig.aics index 5dcddd504fff..a8bf4dd864cd 100644 --- a/subsys/bluetooth/audio/Kconfig.aics +++ b/subsys/bluetooth/audio/Kconfig.aics @@ -32,20 +32,6 @@ config BT_AICS_MAX_INPUT_DESCRIPTION_SIZE help This option sets the maximum input description size in octets. -############# DEBUG ############# - -config BT_DEBUG_AICS - bool "Audio Input Control Service debug" - select DEPRECATED - help - Use this option to enable Audio Input Control Service debug logs for - the Bluetooth Audio functionality. - -module = BT_AICS -legacy-debug-sym = BT_DEBUG_AICS -module-str = "Audio Input Control Service" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_AICS ##################### Audio Input Control Service Client ##################### @@ -64,21 +50,3 @@ config BT_AICS_CLIENT select EXPERIMENTAL help This hidden option enables support for Audio Input Control Service. - -if BT_AICS_CLIENT - -############# DEBUG ############# - -config BT_DEBUG_AICS_CLIENT - bool "Audio Input Control Service client debug" - select DEPRECATED - help - Use this option to enable Audio Input Control Service client debug - logs for the Bluetooth Audio functionality. - -module = BT_AICS_CLIENT -legacy-debug-sym = BT_DEBUG_AICS_CLIENT -module-str = "Audio Input Control Service client" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -endif # BT_AICS_CLIENT diff --git a/subsys/bluetooth/audio/Kconfig.bap b/subsys/bluetooth/audio/Kconfig.bap index c07e044e8cf7..3a66cbfbb88d 100644 --- a/subsys/bluetooth/audio/Kconfig.bap +++ b/subsys/bluetooth/audio/Kconfig.bap @@ -253,23 +253,6 @@ config BT_BAP_BROADCAST_ASSISTANT_RECV_STATE_COUNT endif # BT_BAP_BROADCAST_ASSISTANT -config BT_BAP_DEBUG_STREAM - bool "Basic Audio Profile Stream debug" - select DEPRECATED - depends on BT_BAP_STREAM - help - Use this option to enable Basic Audio Profile Stream debug logs. - -module = BT_BAP_STREAM -legacy-debug-sym = BT_BAP_DEBUG_STREAM -module-str = "Bluetooth Audio Stream" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -parent-module = BT -module = BT_AUDIO_CODEC -module-str = "Bluetooth Audio Codec" -source "subsys/logging/Kconfig.template.log_config_inherit" - config BT_BAP_DEBUG_STREAM_DATA bool "Bluetooth Audio Stream data debug" depends on BT_BAP_STREAM_LOG_LEVEL_DBG @@ -278,107 +261,11 @@ config BT_BAP_DEBUG_STREAM_DATA the Bluetooth Audio functionality. This will enable debug logs for all audio data received and sent. -config BT_DEBUG_ASCS - bool "Audio Stream Control Service debug" - select DEPRECATED - depends on BT_ASCS - help - Use this option to enable Audio Stream Control Service debug logs for - the Bluetooth Audio functionality. - -module = BT_ASCS -legacy-debug-sym = BT_DEBUG_ASCS -module-str = "Audio Stream Control Service" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_BAP_UNICAST_SERVER - bool "Bluetooth Audio Unicast Server debug" - select DEPRECATED - depends on BT_BAP_UNICAST_SERVER - help - Use this option to enable Bluetooth Audio Unicast Server debug logs - for the Bluetooth Audio functionality. - -module = BT_BAP_UNICAST_SERVER -legacy-debug-sym = BT_DEBUG_BAP_UNICAST_SERVER -module-str = "Bluetooth Audio Unicast Server" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_BAP_UNICAST_CLIENT - bool "Basic Audio Profile client debug" - select DEPRECATED - depends on BT_BAP_UNICAST_CLIENT - help - Use this option to enable Basic Audio Profile debug logs for the - Bluetooth Audio functionality. - -module = BT_BAP_UNICAST_CLIENT -legacy-debug-sym = BT_DEBUG_BAP_UNICAST_CLIENT -module-str = "Basic Audio Profile" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_BAP_BROADCAST_SOURCE - bool "Bluetooth Audio Broadcast Source debug" - select DEPRECATED - depends on BT_BAP_BROADCAST_SOURCE - help - Use this option to enable Bluetooth Audio Broadcast Source debug logs - for the Bluetooth Audio functionality. - -module = BT_BAP_BROADCAST_SOURCE -legacy-debug-sym = BT_DEBUG_BAP_BROADCAST_SOURCE -module-str = "Bluetooth Audio Broadcast Source" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_BAP_BROADCAST_SINK - bool "Bluetooth Audio Broadcast Sink debug" - select DEPRECATED - depends on BT_BAP_BROADCAST_SINK - help - Use this option to enable Bluetooth Audio Broadcast Sink debug logs - for the Bluetooth Audio functionality. - -module = BT_BAP_BROADCAST_SINK -legacy-debug-sym = BT_DEBUG_BAP_BROADCAST_SINK -module-str = "Bluetooth Audio Broadcast Sink" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_BAP_SCAN_DELEGATOR - bool "Broadcast Audio Scan Service debug" - select DEPRECATED - depends on BT_BAP_SCAN_DELEGATOR - help - Use this option to enable Broadcast Audio Scan Service debug logs for - the Bluetooth Audio functionality. - -module = BT_BAP_SCAN_DELEGATOR -legacy-debug-sym = BT_DEBUG_BAP_SCAN_DELEGATOR -module-str = "Broadcast Audio Scan Service" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_BAP_BROADCAST_ASSISTANT - bool "Broadcast Audio Scan Service client debug" - select DEPRECATED - depends on BT_BAP_BROADCAST_ASSISTANT - help - Use this option to enable Broadcast Audio Scan Service client - debug logs for the Bluetooth Audio functionality. - -module = BT_BAP_BROADCAST_ASSISTANT -legacy-debug-sym = BT_DEBUG_BAP_BROADCAST_ASSISTANT -module-str = "Broadcast Audio Scan Service client debug" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - config BT_BAP_STREAM # Virtual/hidden option bool default y if BT_ASCS || BT_BAP_UNICAST_CLIENT || \ BT_BAP_BROADCAST_SOURCE || BT_BAP_BROADCAST_SINK -parent-module = BT -module = BT_BAP_ISO -module-str = "Bluetooth Audio ISO" -source "subsys/logging/Kconfig.template.log_config_inherit" - rsource "Kconfig.pacs" rsource "Kconfig.ascs" diff --git a/subsys/bluetooth/audio/Kconfig.cap b/subsys/bluetooth/audio/Kconfig.cap index 9f71d61b720f..66da848563c8 100644 --- a/subsys/bluetooth/audio/Kconfig.cap +++ b/subsys/bluetooth/audio/Kconfig.cap @@ -26,45 +26,9 @@ config BT_CAP_ACCEPTOR_SET_MEMBER Enabling will take one of the allocated CSIS instances (BT_CSIP_SET_MEMBER_MAX_INSTANCE_COUNT). -config BT_DEBUG_CAP_ACCEPTOR - bool "Common Audio Profile debug" - select DEPRECATED - depends on BT_CAP_ACCEPTOR - help - Use this option to enable CAP debug logs for the - Bluetooth Audio functionality. - -module = BT_CAP_ACCEPTOR -legacy-debug-sym = BT_DEBUG_CAP_ACCEPTOR -module-str = "Common Audio Profile Acceptor" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - config BT_CAP_INITIATOR bool "Common Audio Profile Initiator Role Support [EXPERIMENTAL]" depends on (BT_BAP_UNICAST_CLIENT && BT_CSIP_SET_COORDINATOR) || BT_BAP_BROADCAST_SOURCE select EXPERIMENTAL help Enabling this will enable the CAP Initiator role. - -module = BT_CAP_INITIATOR -legacy-debug-sym = BT_DEBUG_CAP_INITIATOR -module-str = "Common Audio Profile Initiator" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_CAP_INITIATOR - bool "Common Audio Profile Initiator debug" - select DEPRECATED - depends on BT_CAP_INITIATOR - help - Use this option to enable CAP Initiator debug logs for the - Bluetooth Audio functionality. - -module = BT_CAP_INITIATOR -legacy-debug-sym = BT_DEBUG_CAP_INITIATOR -module-str = "Common Audio Profile Initiator" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -parent-module = BT -module = BT_CAP_STREAM -module-str = "Common Audio Profile Stream" -source "subsys/logging/Kconfig.template.log_config_inherit" diff --git a/subsys/bluetooth/audio/Kconfig.csip b/subsys/bluetooth/audio/Kconfig.csip index c9004b211ebe..046b36de0a1b 100644 --- a/subsys/bluetooth/audio/Kconfig.csip +++ b/subsys/bluetooth/audio/Kconfig.csip @@ -47,20 +47,6 @@ config BT_CSIP_SET_MEMBER_MAX_INSTANCE_COUNT Enabling BT_CAP_ACCEPTOR_SET_MEMBER will take one of the allocated instances. -############### DEBUG ############### - -config BT_DEBUG_CSIP_SET_MEMBER - bool "Coordinated Set Identification Service debug" - select DEPRECATED - help - Use this option to enable Coordinated Set Identification Service debug - logs for the Bluetooth Audio functionality. - -module = BT_CSIP_SET_MEMBER -legacy-debug-sym = BT_DEBUG_CSIP_SET_MEMBER -module-str = "Coordinated Set Identification Service" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_CSIP_SET_MEMBER #################### Coordinated Set Identification Client #################### @@ -101,31 +87,4 @@ config BT_CSIP_SET_COORDINATOR_ENC_SIRK_SUPPORT help Enables support encrypting the SIRK. -############### DEBUG ############### - -config BT_DEBUG_CSIP_SET_COORDINATOR - bool "Coordinated Set Identification Profile Set Coordinator debug" - select DEPRECATED - help - Use this option to enable Coordinated Set Identification Profile - Set Coordinator debug logs for the Bluetooth Audio functionality. - -module = BT_CSIP_SET_COORDINATOR -legacy-debug-sym = BT_DEBUG_CSIP_SET_COORDINATOR -module-str = "Coordinated Set Identification Profile Set Coordinator" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_CSIP_SET_COORDINATOR - -config BT_DEBUG_CSIP_SET_MEMBER_CRYPTO - bool "Coordinated Set Identification Profile crypto functions debug" - select DEPRECATED - depends on BT_CSIP_SET_COORDINATOR || BT_CSIP_SET_MEMBER - help - Use this option to enable Coordinated Set Identification Profile - crypto functions debug logs for the Bluetooth Audio functionality. - -module = BT_CSIP_SET_MEMBER_CRYPTO -legacy-debug-sym = BT_DEBUG_CSIP_SET_MEMBER_CRYPTO -module-str = "Coordinated Set Identification Profile crypto functions" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" diff --git a/subsys/bluetooth/audio/Kconfig.has b/subsys/bluetooth/audio/Kconfig.has index ffe525a80a96..9e96a3824ca8 100644 --- a/subsys/bluetooth/audio/Kconfig.has +++ b/subsys/bluetooth/audio/Kconfig.has @@ -34,17 +34,6 @@ config BT_HAS_PRESET_NAME_DYNAMIC endif # BT_HAS_PRESET_SUPPORT -config BT_DEBUG_HAS - bool "Hearing Access Service debug" - select DEPRECATED - help - This option enables enables Hearing Access Service debug logs. - -module = BT_HAS -legacy-debug-sym = BT_DEBUG_HAS -module-str = "Hearing Access Service" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_HAS config BT_HAS_CLIENT @@ -56,15 +45,3 @@ config BT_HAS_CLIENT select UTF8 help This option enables support for Hearing Access Service Client. - -config BT_DEBUG_HAS_CLIENT - bool "Hearing Access Service Client debug" - select DEPRECATED - depends on BT_HAS_CLIENT - help - This option enables enables Hearing Access Service Client debug logs. - -module = BT_HAS_CLIENT -legacy-debug-sym = BT_DEBUG_HAS_CLIENT -module-str = "Hearing Access Service Client" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" diff --git a/subsys/bluetooth/audio/Kconfig.mcs b/subsys/bluetooth/audio/Kconfig.mcs index 78c81db90384..1f3904cc5360 100644 --- a/subsys/bluetooth/audio/Kconfig.mcs +++ b/subsys/bluetooth/audio/Kconfig.mcs @@ -17,22 +17,6 @@ config BT_MCS help This option enables support for the Media Control Service. -if BT_MCS - -config BT_DEBUG_MCS - bool "Media Control Service debug" - select DEPRECATED - help - Use this option to enable Media Control Service debug logs for the - Bluetooth Audio functionality. - -module = BT_MCS -legacy-debug-sym = BT_DEBUG_MCS -module-str = "Media Control Service" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -endif # BT_MCS - #### Media Control Client ################################ config BT_MCC @@ -136,18 +120,4 @@ config BT_MCC_SHELL help This option enables shell support for the Media Control Client. -#### MCC Debug logs #### - -config BT_DEBUG_MCC - bool "Media Control Client debug" - select DEPRECATED - help - Use this option to enable Media Control Client debug logs for the - Bluetooth Audio functionality. - -module = BT_MCC -legacy-debug-sym = BT_DEBUG_MCC -module-str = "Media Control Client" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_MCC diff --git a/subsys/bluetooth/audio/Kconfig.mctl b/subsys/bluetooth/audio/Kconfig.mctl index ed4a56f26b7d..cb14218068cf 100644 --- a/subsys/bluetooth/audio/Kconfig.mctl +++ b/subsys/bluetooth/audio/Kconfig.mctl @@ -57,15 +57,4 @@ config MCTL_REMOTE_PLAYER_CONTROL_OBJECTS This options enables support for accessing objects (tracks, groups, search results, ...) on a remote media player -config MCTL_DEBUG - bool "Media control debug" - select DEPRECATED - help - Use this option to enable Media control debug logs - -module = MCTL -legacy-debug-sym = MCTL_DEBUG -module-str = "Media control" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # MCTL diff --git a/subsys/bluetooth/audio/Kconfig.micp b/subsys/bluetooth/audio/Kconfig.micp index ec5b7ff9e23e..49b675027342 100644 --- a/subsys/bluetooth/audio/Kconfig.micp +++ b/subsys/bluetooth/audio/Kconfig.micp @@ -33,20 +33,6 @@ config BT_MICP_MIC_DEV_AICS This hidden option makes it possible to easily check if AICS is enabled for Microphone Control Profile Microphone Device. -############# DEBUG ############# - -config BT_DEBUG_MICP_MIC_DEV - bool "Microphone Control Profile Microphone Device debug" - select DEPRECATED - help - Use this option to enable Microphone Control Profile - Microphone Device debug logs for the Bluetooth Audio functionality. - -module = BT_MICP_MIC_DEV -legacy-debug-sym = BT_DEBUG_MICP_MIC_DEV -module-str = "Microphone Control Profile Microphone Device" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_MICP_MIC_DEV ########### Microphone Control Profile Microphone Controller ########### @@ -77,18 +63,4 @@ config BT_MICP_MIC_CTLR_AICS This hidden option makes it possible to easily check if AICS is enabled for MICP client. -############# DEBUG ############# - -config BT_DEBUG_MICP_MIC_CTLR - bool "Microphone Control Profile Microphone Controller debug" - select DEPRECATED - help - Use this option to enable Microphone Control Profile Microphone - Controller debug logs for the Bluetooth Audio functionality. - -module = BT_MICP_MIC_CTLR -legacy-debug-sym = BT_DEBUG_MICP_MIC_CTLR -module-str = "Microphone Control Profile Microphone Controller" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_MICP_MIC_CTLR diff --git a/subsys/bluetooth/audio/Kconfig.mpl b/subsys/bluetooth/audio/Kconfig.mpl index 43d09c11bb19..2e7fcb384200 100644 --- a/subsys/bluetooth/audio/Kconfig.mpl +++ b/subsys/bluetooth/audio/Kconfig.mpl @@ -107,15 +107,4 @@ config BT_MPL_TRACK_MAX_SIZE endif # BT_MPL_OBJECTS -config BT_DEBUG_MPL - bool "Media player debug" - select DEPRECATED - help - Enables debug logs for the media player - -module = BT_MPL -legacy-debug-sym = BT_DEBUG_MPL -module-str = "Media player" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_MPL diff --git a/subsys/bluetooth/audio/Kconfig.pacs b/subsys/bluetooth/audio/Kconfig.pacs index af95e2122bc7..32087d2cf3df 100644 --- a/subsys/bluetooth/audio/Kconfig.pacs +++ b/subsys/bluetooth/audio/Kconfig.pacs @@ -88,17 +88,4 @@ endif # BT_PAC_SRC config BT_PACS def_bool BT_PAC_SNK || BT_PAC_SRC -config BT_DEBUG_PACS - bool "Published Audio Capabilities Service debug" - select DEPRECATED - depends on BT_PACS - help - Use this option to enable Published Audio Capabilities Service debug - logs for the Bluetooth Audio functionality. - -module = BT_PACS -legacy-debug-sym = BT_DEBUG_PACS -module-str = "Published Audio Capabilities Service" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endmenu diff --git a/subsys/bluetooth/audio/Kconfig.tbs b/subsys/bluetooth/audio/Kconfig.tbs index cc9c093d0be4..33304b504949 100644 --- a/subsys/bluetooth/audio/Kconfig.tbs +++ b/subsys/bluetooth/audio/Kconfig.tbs @@ -126,21 +126,6 @@ config BT_TBS_AUTHORIZATION If set to true, then any writable characteristics will require authorization per connection. - -############# DEBUG ############# - -config BT_DEBUG_TBS - bool "Telephone Bearer Service debug" - select DEPRECATED - help - Use this option to enable Telephone Bearer Service debug logs for the - Bluetooth Audio functionality. - -module = BT_TBS -legacy-debug-sym = BT_DEBUG_TBS -module-str = "Telephone Bearer Service" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_TBS @@ -322,20 +307,6 @@ config BT_TBS_CLIENT_CALL_FRIENDLY_NAME help This option enables support for reading Call Friendly Name. -############# DEBUG ############# - -config BT_DEBUG_TBS_CLIENT - bool "Telephone Bearer Service client debug" - select DEPRECATED - help - Use this option to enable Telephone Bearer Service client debug logs - for the Bluetooth Audio functionality. - -module = BT_TBS_CLIENT -legacy-debug-sym = BT_DEBUG_TBS_CLIENT -module-str = "Telephone Bearer Service client" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_TBS_CLIENT if BT_TBS || BT_TBS_CLIENT diff --git a/subsys/bluetooth/audio/Kconfig.vcp b/subsys/bluetooth/audio/Kconfig.vcp index 57c46b6d0e9e..9e5f6c06a18e 100644 --- a/subsys/bluetooth/audio/Kconfig.vcp +++ b/subsys/bluetooth/audio/Kconfig.vcp @@ -46,20 +46,6 @@ config BT_VCP_VOL_REND_AICS This hidden option makes it possible to easily check if AICS is enabled for VCS. -############# DEBUG ############# - -config BT_DEBUG_VCP_VOL_REND - bool "Volume Control Profile Volume Renderer debug" - select DEPRECATED - help - Use this option to enable Volume Control Profile debug logs for the - Bluetooth Audio functionality. - -module = BT_VCP_VOL_REND -legacy-debug-sym = BT_DEBUG_VCP_VOL_REND -module-str = "Volume Control Profile Voluem Renderer" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_VCP_VOL_REND ################### Volume Control Profile Volume Controller ################### @@ -105,18 +91,4 @@ config BT_VCP_VOL_CTLR_AICS This hidden option makes it possible to easily check if AICS is enabled for VCS client. -############# DEBUG ############# - -config BT_DEBUG_VCP_VOL_CTLR - bool "Volume Control Profile Volume Controller debug" - select DEPRECATED - help - Use this option to enable Volume Control Profile Volume Controller - debug logs for the Bluetooth Audio functionality. - -module = BT_VCP_VOL_CTLR -legacy-debug-sym = BT_DEBUG_VCP_VOL_CTLR -module-str = "Volume Control Profile Volume Controller" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_VCP_VOL_CTLR diff --git a/subsys/bluetooth/audio/Kconfig.vocs b/subsys/bluetooth/audio/Kconfig.vocs index 55d4075fb8b1..2b1e4362b13e 100644 --- a/subsys/bluetooth/audio/Kconfig.vocs +++ b/subsys/bluetooth/audio/Kconfig.vocs @@ -31,20 +31,6 @@ config BT_VOCS_MAX_OUTPUT_DESCRIPTION_SIZE help This option sets the maximum output description size in octets. -############# DEBUG ############# - -config BT_DEBUG_VOCS - bool "Volume Offset Control Service debug" - select DEPRECATED - help - Use this option to enable Volume Offset Control Service debug logs for - the Bluetooth Audio functionality. - -module = BT_VOCS -legacy-debug-sym = BT_DEBUG_VOCS -module-str = "Volume Offset Control Service" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_VOCS ##################### Volume Offset Control Service Client ##################### @@ -63,21 +49,3 @@ config BT_VOCS_CLIENT select EXPERIMENTAL help This hidden option enables support for Volume Offset Control Service. - -if BT_VOCS_CLIENT - -############# DEBUG ############# - -config BT_DEBUG_VOCS_CLIENT - bool "Volume Offset Control Service client debug" - select DEPRECATED - help - Use this option to enable Volume Offset Control Service client debug - logs for the Bluetooth Audio functionality. - -module = BT_VOCS_CLIENT -legacy-debug-sym = BT_DEBUG_VOCS_CLIENT -module-str = "Volume Offset Control Service client" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -endif # BT_VOCS_CLIENT diff --git a/subsys/bluetooth/common/Kconfig b/subsys/bluetooth/common/Kconfig index 19a04d171829..e2d82c7f372f 100644 --- a/subsys/bluetooth/common/Kconfig +++ b/subsys/bluetooth/common/Kconfig @@ -368,33 +368,3 @@ config BT_DEBUG_MONITOR_RTT_BUFFER_SIZE endif # BT_DEBUG_MONITOR_RTT endchoice # Bluetooth debug type - -if BT_DEBUG - -config BT_DEBUG_HCI_DRIVER - bool "Bluetooth HCI driver debug" - select DEPRECATED - help - This option enables debug support for the active - Bluetooth HCI driver, including the Controller-side HCI layer - when included in the build. - -module = BT_HCI_DRIVER -legacy-debug-sym = BT_DEBUG_HCI_DRIVER -module-str = "Bluetooth HCI driver" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_RPA - bool "Bluetooth Resolvable Private Address (RPA) debug" - select DEPRECATED - depends on BT_RPA - help - This option enables debug support for the Bluetooth - Resolvable Private Address (RPA) generation and resolution. - -module = BT_RPA -legacy-debug-sym = BT_DEBUG_RPA -module-str = "Bluetooth Resolvable Private Address (RPA)" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -endif # BT_DEBUG diff --git a/subsys/bluetooth/crypto/Kconfig b/subsys/bluetooth/crypto/Kconfig index 7f61037e0142..ccf5a8b641b4 100644 --- a/subsys/bluetooth/crypto/Kconfig +++ b/subsys/bluetooth/crypto/Kconfig @@ -8,20 +8,3 @@ config BT_CRYPTO select TINYCRYPT_AES_CMAC help This option enables the Bluetooth Cryptographic Toolbox. - -config BT_DEBUG_CRYPTO - bool "Bluetooth Cryptographic Toolbox debug" - select DEPRECATED - depends on BT_CRYPTO - help - This option enables debug log output for the Bluetooth - Cryptographic Toolbox. - - WARNING: This option prints out private security keys such as - the Long Term Key. - Use of this feature in production is strongly discouraged. - -module = BT_CRYPTO -legacy-debug-sym = BT_DEBUG_CRYPTO -module-str = "Bluetooth Cryptographic Toolbox" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index e448ecf36b3d..c58a5eb0b606 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -880,17 +880,6 @@ config BT_DF_VS_CONN_IQ_REPORT_16_BITS_IQ_SAMPLES extenstion to handle connection IQ report with samples that are in 16 bit signed integer format. -config BT_DEBUG_DF - bool "Bluetooth Direction Finding debug" - select DEPRECATED - help - This option enables debug support for Bluetooth Direction Finding - -module = BT_DF -legacy-debug-sym = BT_DEBUG_DF -module-str = "Bluetooth Direction Finding" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_DF endif # BT_HCI_HOST @@ -939,55 +928,6 @@ config BT_PER_ADV_SYNC_BUF_SIZE if BT_DEBUG -config BT_DEBUG_SETTINGS - bool "Bluetooth storage debug" - select DEPRECATED - depends on BT_SETTINGS - help - This option enables debug support for Bluetooth storage. - -module = BT_SETTINGS -legacy-debug-sym = BT_DEBUG_SETTINGS -module-str = "Bluetooth storage" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_HCI_CORE - bool "Bluetooth HCI core debug" - select DEPRECATED - help - This option enables debug support for Bluetooth HCI - core. - -module = BT_HCI_CORE -legacy-debug-sym = BT_DEBUG_HCI_CORE -module-str = "Bluetooth HCI core" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_CONN - bool "Bluetooth connection debug" - select DEPRECATED - depends on BT_CONN || BT_ISO - help - This option enables debug support for Bluetooth - connection handling. - -module = BT_CONN -legacy-debug-sym = BT_DEBUG_CONN -module-str = "Bluetooth connection" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_ISO - bool "ISO channel debug" - select DEPRECATED - help - Use this option to enable ISO channels debug logs for the - Bluetooth Audio functionality. - -module = BT_ISO -legacy-debug-sym = BT_DEBUG_ISO -module-str = "ISO channel" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - config BT_DEBUG_ISO_DATA bool "ISO channel data debug" depends on BT_ISO_LOG_LEVEL_DBG @@ -996,42 +936,6 @@ config BT_DEBUG_ISO_DATA Bluetooth Audio functionality. This will enable debug logs for all ISO data received and sent. -config BT_DEBUG_KEYS - bool "Bluetooth security keys debug" - select DEPRECATED - depends on BT_HCI_HOST - depends on BT_SMP - help - This option enables debug support for the handling of - Bluetooth security keys. - - WARNING: This option prints out private security keys such as - the Long Term Key. - Use of this feature in production is strongly discouraged. - -module = BT_KEYS -legacy-debug-sym = BT_DEBUG_KEYS -module-str = "Bluetooth security keys" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_SMP - bool "Bluetooth Security Manager Protocol (SMP) debug" - select DEPRECATED - depends on BT_HCI_HOST - depends on BT_SMP - help - This option enables debug support for the Bluetooth - Security Manager Protocol (SMP). - - WARNING: This option prints out private security keys such as - the Long Term Key. - Use of this feature in production is strongly discouraged. - -module = BT_SMP -legacy-debug-sym = BT_DEBUG_SMP -module-str = "Bluetooth Security Manager Protocol" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - config BT_SMP_SELFTEST bool "Bluetooth SMP self tests executed on init" depends on BT_SMP_LOG_LEVEL_DBG @@ -1047,83 +951,6 @@ config BT_SMP_FORCE_BREDR supporting BR/EDR Secure Connections. This option is solely for testing and should never be enabled on production devices. -config BT_DEBUG_RFCOMM - bool "Bluetooth RFCOMM debug" - select DEPRECATED - depends on BT_RFCOMM - help - This option enables debug support for the Bluetooth - RFCOMM layer. - -module = BT_RFCOMM -legacy-debug-sym = BT_DEBUG_RFCOMM -module-str = "Bluetooth RFCOMM" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_HFP_HF - bool "Bluetooth Hands Free Profile (HFP) debug" - select DEPRECATED - depends on BT_HFP_HF - help - This option enables debug support for the Bluetooth - Hands Free Profile (HFP). - -module = BT_HFP_HF -legacy-debug-sym = BT_DEBUG_HFP_HF -module-str = "Bluetooth Hands Free Profile (HFP)" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_AVDTP - bool "Bluetooth AVDTP debug" - select DEPRECATED - depends on BT_AVDTP - help - This option enables debug support for the Bluetooth AVDTP. - -module = BT_AVDTP -legacy-debug-sym = BT_DEBUG_AVDTP -module-str = "Bluetooth AVDTP debug" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_A2DP - bool "Bluetooth A2DP debug" - select DEPRECATED - depends on BT_A2DP - help - This option enables debug support for the Bluetooth - A2DP profile. - -module = BT_A2DP -legacy-debug-sym = BT_DEBUG_A2DP -module-str = "Bluetooth A2DP" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_SDP - bool "Bluetooth Service Discovery Protocol (SDP) debug" - select DEPRECATED - depends on BT_BREDR - help - This option enables debug support for the Bluetooth - Service Discovery Protocol (SDP). - -module = BT_SDP -legacy-debug-sym = BT_DEBUG_SDP -module-str = "Bluetooth Service Discovery Protocol (SDP)" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_SERVICE - bool "Bluetooth Services debug" - select DEPRECATED - depends on BT_CONN - help - This option enables debug support for the Bluetooth - Services. - -module = BT_SERVICE -legacy-debug-sym = BT_DEBUG_SERVICE -module-str = "Bluetooth Services" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_DEBUG config BT_LOG_SNIFFER_INFO diff --git a/subsys/bluetooth/host/Kconfig.gatt b/subsys/bluetooth/host/Kconfig.gatt index 13e61c8539a6..d3cf7146db34 100644 --- a/subsys/bluetooth/host/Kconfig.gatt +++ b/subsys/bluetooth/host/Kconfig.gatt @@ -276,32 +276,4 @@ config DEVICE_NAME_GATT_WRITABLE_AUTHEN endif #BT_DEVICE_NAME_GATT_WRITABLE -if BT_DEBUG - -config BT_DEBUG_ATT - bool "Bluetooth Attribute Protocol (ATT) debug" - select DEPRECATED - help - This option enables debug support for the Bluetooth - Attribute Protocol (ATT). - -module = BT_ATT -legacy-debug-sym = BT_DEBUG_ATT -module-str = "Bluetooth Attribute Protocol (ATT)" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_DEBUG_GATT - bool "Bluetooth Generic Attribute Profile (GATT) debug" - select DEPRECATED - help - This option enables debug support for the Bluetooth - Generic Attribute Profile (GATT). - -module = BT_GATT -legacy-debug-sym = BT_DEBUG_GATT -module-str = "Bluetooth Generic Attribute Profile (GATT)" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -endif # BT_DEBUG - endmenu diff --git a/subsys/bluetooth/host/Kconfig.l2cap b/subsys/bluetooth/host/Kconfig.l2cap index f582e1838f37..2d172595ad97 100644 --- a/subsys/bluetooth/host/Kconfig.l2cap +++ b/subsys/bluetooth/host/Kconfig.l2cap @@ -58,17 +58,4 @@ config BT_L2CAP_ECRED This option enables support for LE Connection oriented Channels with Enhanced Credit Based Flow Control support on dynamic L2CAP Channels. -config BT_DEBUG_L2CAP - bool "Bluetooth L2CAP debug" - select DEPRECATED - depends on BT_DEBUG - help - This option enables debug support for the Bluetooth - L2ACP layer. - -module = BT_L2CAP -legacy-debug-sym = BT_DEBUG_L2CAP -module-str = "Bluetooth L2CAP" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endmenu diff --git a/subsys/bluetooth/lib/Kconfig b/subsys/bluetooth/lib/Kconfig index d5c1cf073065..15cfa142b131 100644 --- a/subsys/bluetooth/lib/Kconfig +++ b/subsys/bluetooth/lib/Kconfig @@ -7,8 +7,3 @@ config BT_EAD select BT_HOST_CCM help Enable the Encrypted Advertising Data library - -parent-module = BT -module = BT_EAD -module-str = "Bluetooth Encrypted Advertising Data" -source "subsys/logging/Kconfig.template.log_config_inherit" diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 701dd055edff..edec033bce0c 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1551,19 +1551,6 @@ config BT_MESH_SEQ_STORE_RATE endif # BT_SETTINGS -config BT_MESH_DEBUG - bool "Debug logs" - select DEPRECATED - depends on BT_DEBUG - help - Use this option to enable debug logs for the Bluetooth - Mesh functionality. - -module = BT_MESH -legacy-debug-sym = BT_MESH_DEBUG -module-str = "Debug logs" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - if BT_MESH_LOG_LEVEL_DBG config BT_MESH_DEBUG_USE_ID_ADDR @@ -1574,226 +1561,6 @@ config BT_MESH_DEBUG_USE_ID_ADDR traces), however it should never be enabled for a production build as it compromises the privacy of the device. -config BT_MESH_DEBUG_NET - bool "Network layer debug" - select DEPRECATED - help - Use this option to enable Network layer debug logs for the - Bluetooth mesh functionality. - -module = BT_MESH_NET -legacy-debug-sym = BT_MESH_DEBUG_NET -module-str = "Network layer" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_RPL - bool "Replay protection list debug" - select DEPRECATED - help - Use this option to enable Replay protection list debug logs - for the Bluetooth mesh functionality. - -module = BT_MESH_RPL -legacy-debug-sym = BT_MESH_DEBUG_RPL -module-str = "Replay protection list" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_TRANS - bool "Transport layer debug" - select DEPRECATED - help - Use this option to enable Transport layer debug logs for the - Bluetooth mesh functionality. - -module = BT_MESH_TRANS -legacy-debug-sym = BT_MESH_DEBUG_TRANS -module-str = "Transport layer" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_BEACON - bool "Beacon debug" - select DEPRECATED - help - Use this option to enable Beacon-related debug logs for the - Bluetooth mesh functionality. - -module = BT_MESH_BEACON -legacy-debug-sym = BT_MESH_DEBUG_BEACON -module-str = "Beacon" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_CRYPTO - bool "Crypto debug" - select DEPRECATED - help - Use this option to enable cryptographic debug logs for the - Bluetooth mesh functionality. - -module = BT_MESH_CRYPTO -legacy-debug-sym = BT_MESH_DEBUG_CRYPTO -module-str = "Crypto" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_KEYS - bool "Key management debug" - select DEPRECATED - help - Use this option to enable key management debug logs for the - Bluetooth mesh functionality. - -module = BT_MESH_KEYS -legacy-debug-sym = BT_MESH_DEBUG_KEYS -module-str = "Key management" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_PROV - bool "Provisioning debug" - select DEPRECATED - help - Use this option to enable Provisioning debug logs for the - Bluetooth mesh functionality. - -module = BT_MESH_PROV -legacy-debug-sym = BT_MESH_DEBUG_PROV -module-str = "Provisioning" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_PROVISIONER - bool "Provisioner debug" - select DEPRECATED - help - Use this option to enable Provisioner debug logs for the - Bluetooth mesh functionality. - -module = BT_MESH_PROVISIONER -legacy-debug-sym = BT_MESH_DEBUG_PROVISIONER -module-str = "Provisioner" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_PROV_DEVICE - bool "Provisioning device debug" - select DEPRECATED - help - Use this option to enable Provisioning device debug logs for the - Bluetooth Mesh functionality. - -module = BT_MESH_PROV_DEVICE -legacy-debug-sym = BT_MESH_DEBUG_PROV_DEVICE -module-str = "Provisioning device" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_ACCESS - bool "Access layer debug" - select DEPRECATED - help - Use this option to enable Access layer and device composition - related debug logs for Bluetooth mesh. - -module = BT_MESH_ACCESS -legacy-debug-sym = BT_MESH_DEBUG_ACCESS -module-str = "Access layer" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_MODEL - bool "Foundation model debug" - select DEPRECATED - help - Use this option to enable debug logs for the Foundation - Models. - -module = BT_MESH_MODEL -legacy-debug-sym = BT_MESH_DEBUG_MODEL -module-str = "Foundation model" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -module = BT_MESH_DFU -module-str = "DFU model" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_ADV - bool "Advertising debug" - select DEPRECATED - help - Use this option to enable advertising debug logs for - the Bluetooth mesh functionality. - -module = BT_MESH_ADV -legacy-debug-sym = BT_MESH_DEBUG_ADV -module-str = "Advertising" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_LOW_POWER - bool "Low Power debug" - select DEPRECATED - help - Use this option to enable Low Power debug logs for the - Bluetooth mesh functionality. - -module = BT_MESH_LOW_POWER -legacy-debug-sym = BT_MESH_DEBUG_LOW_POWER -module-str = "Low Power" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_FRIEND - bool "Friend debug" - select DEPRECATED - help - Use this option to enable Friend debug logs for the - Bluetooth mesh functionality. - -module = BT_MESH_FRIEND -legacy-debug-sym = BT_MESH_DEBUG_FRIEND -module-str = "Friend" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_PROXY - bool "Proxy debug" - select DEPRECATED - depends on BT_MESH_GATT - help - Use this option to enable Proxy protocol debug logs. - -module = BT_MESH_PROXY -legacy-debug-sym = BT_MESH_DEBUG_PROXY -module-str = "Proxy" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_SETTINGS - bool "Persistent settings debug" - select DEPRECATED - depends on BT_SETTINGS - help - Use this option to enable persistent settings debug logs. - -module = BT_MESH_SETTINGS -legacy-debug-sym = BT_MESH_DEBUG_SETTINGS -module-str = "Persistent settings" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_CDB - bool "Configuration database debug" - select DEPRECATED - depends on BT_MESH_CDB - help - Use this option to enable configuration database debug logs. - -module = BT_MESH_CDB -legacy-debug-sym = BT_MESH_DEBUG_CDB -module-str = "Configuration database" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -config BT_MESH_DEBUG_CFG - bool "Configuration debug" - select DEPRECATED - help - Use this option to enable node configuration debug logs for the - Bluetooth mesh functionality. - -module = BT_MESH_CFG -legacy-debug-sym = BT_MESH_DEBUG_CFG -module-str = "Configuration" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - endif # BT_MESH_LOG_LEVEL_DBG endif # BT_MESH diff --git a/subsys/bluetooth/services/Kconfig.bas b/subsys/bluetooth/services/Kconfig.bas index 56477900c4d6..3a8789aad936 100644 --- a/subsys/bluetooth/services/Kconfig.bas +++ b/subsys/bluetooth/services/Kconfig.bas @@ -3,14 +3,6 @@ # Copyright (c) 2018 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -menuconfig BT_BAS +config BT_BAS bool "GATT Battery service" select SENSOR - -if BT_BAS - -module = BT_BAS -module-str = BAS -source "subsys/logging/Kconfig.template.log_config" - -endif # BT_BAS diff --git a/subsys/bluetooth/services/Kconfig.hrs b/subsys/bluetooth/services/Kconfig.hrs index a624ea958058..7f494e76a8cf 100644 --- a/subsys/bluetooth/services/Kconfig.hrs +++ b/subsys/bluetooth/services/Kconfig.hrs @@ -27,8 +27,4 @@ config BT_HRS_DEFAULT_PERM_RW_AUTHEN endchoice -module = BT_HRS -module-str = HRS -source "subsys/logging/Kconfig.template.log_config" - endif # BT_HRS diff --git a/subsys/bluetooth/services/Kconfig.tps b/subsys/bluetooth/services/Kconfig.tps index 4ad4b9069ce6..363e2cfc948e 100644 --- a/subsys/bluetooth/services/Kconfig.tps +++ b/subsys/bluetooth/services/Kconfig.tps @@ -3,13 +3,5 @@ # Copyright (c) 2020 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 -menuconfig BT_TPS +config BT_TPS bool "GATT TX Power service" - -if BT_TPS - -module = BT_TPS -module-str = TPS -source "subsys/logging/Kconfig.template.log_config" - -endif # BT_TPS diff --git a/subsys/bluetooth/services/ias/Kconfig.ias b/subsys/bluetooth/services/ias/Kconfig.ias index 6e4d1519ec9d..2894fe8ffe24 100644 --- a/subsys/bluetooth/services/ias/Kconfig.ias +++ b/subsys/bluetooth/services/ias/Kconfig.ias @@ -36,19 +36,3 @@ config BT_IAS_CLIENT select EXPERIMENTAL help This option enables support for Immediate Alert Service Client - -config BT_DEBUG_IAS_CLIENT - bool "Immediate Alert Service Client debug" - select DEPRECATED - depends on BT_IAS_CLIENT - help - This option enables enables Immediate Alert Service Client debug logs. - -module = BT_IAS_CLIENT -legacy-debug-sym = BT_DEBUG_IAS_CLIENT -module-str = "Immediate Alert Service Client" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -module = BT_IAS -module-str = IAS -source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config" diff --git a/subsys/bluetooth/services/ots/Kconfig b/subsys/bluetooth/services/ots/Kconfig index 25dd5faae460..294013303c4e 100644 --- a/subsys/bluetooth/services/ots/Kconfig +++ b/subsys/bluetooth/services/ots/Kconfig @@ -78,24 +78,6 @@ config BT_OTS_CLIENT help This option enables support for the Object Transfer Service Client. -if BT_OTS_CLIENT - -# TODO: Unify logging for OTS server and client - the client uses -# "BT" debugging, the server does not. - -config BT_DEBUG_OTS_CLIENT - bool "Object Transfer Service Client debug" - select DEPRECATED - help - Use this option to enable Object Transfer Client debug logs - -module = BT_OTS_CLIENT -legacy-debug-sym = BT_DEBUG_OTS_CLIENT -module-str = "Object Transfer Service Client" -source "subsys/bluetooth/common/Kconfig.template.log_config_bt" - -endif # BT_OTS_CLIENT - if BT_OTS || BT_OTS_CLIENT config BT_OTS_MAX_OBJ_CNT @@ -127,8 +109,4 @@ config BT_OTS_OBJ_MAX_NAME_LEN default 120 range 1 120 -module = BT_OTS -module-str = BT_OTS -source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config" - endif # BT_OTS || BT_OTS_CLIENT From 9c69f29d0d37aa608b575154696aba088fc2a15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Battrel?= Date: Fri, 24 Mar 2023 11:54:58 +0100 Subject: [PATCH 0809/1906] Bluetooth: Logging: Deprecate `BT_DEBUG_LOG` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deprecate Kconfig symbol `BT_DEBUG_LOG`. With the new `BT_LOG` having the same effect, `BT_DEBUG_LOG` is not useful anymore and shouldn't be used. Signed-off-by: Théo Battrel --- subsys/bluetooth/common/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/common/Kconfig b/subsys/bluetooth/common/Kconfig index e2d82c7f372f..2bcebf4e9a68 100644 --- a/subsys/bluetooth/common/Kconfig +++ b/subsys/bluetooth/common/Kconfig @@ -299,7 +299,8 @@ config BT_DEBUG_NONE Select this to disable all Bluetooth debug logs. config BT_DEBUG_LOG - bool "Normal printf-style to console" + bool "[DEPRECATED] Normal printf-style to console" + select DEPRECATED select BT_DEBUG select LOG imply LOG_FUNC_NAME_PREFIX_INF From a6809ef93a5d7580f8a4bc6f997c43e445848e04 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Fri, 3 Mar 2023 18:37:51 -0500 Subject: [PATCH 0810/1906] timer: hpet: a few improvements - That MIN_DELAY is a magic arbitrary number that is never going to be right for all cases. Get rid of it in favor of a smarter solution. - `sys_clock_set_timeout()` should not base its next match value on the current time. Tracking the `last_tick` and `last_elapsed` values avoids the need for all the tick rounding computation. - Clamp the next timeout to HPET_MAX_TICKS/2. This leaves room for the added elapsed time and any possible IRQ servicing delay. Signed-off-by: Nicolas Pitre --- drivers/timer/hpet.c | 70 ++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/drivers/timer/hpet.c b/drivers/timer/hpet.c index 66d8fa84978e..5b8233767081 100644 --- a/drivers/timer/hpet.c +++ b/drivers/timer/hpet.c @@ -37,11 +37,6 @@ * * HPET_COUNTER_CLK_PERIOD can be overridden in soc.h if * COUNTER_CLK_PERIOD is not in femtoseconds (1e-15 sec). - * - * HPET_CMP_MIN_DELAY can be overridden in soc.h to better match - * the frequency of the timers. Default is 1000 where the value - * written to the comparator must be 1000 larger than the current - * main counter value. */ /* General Configuration register */ @@ -215,11 +210,6 @@ static inline void hpet_timer_comparator_set(uint64_t val) #define HPET_COUNTER_CLK_PERIOD (1000000000000000ULL) #endif -#ifndef HPET_CMP_MIN_DELAY -/* Minimal delay for comparator before the next timer event */ -#define HPET_CMP_MIN_DELAY (1000) -#endif - /* * HPET_INT_LEVEL_TRIGGER is used to set HPET interrupt as level trigger * for ARM CPU with NVIC like EHL PSE, whose DTS interrupt setting @@ -237,6 +227,8 @@ __WARN("HPET_INT_LEVEL_TRIGGER has no effect, DTS setting is used instead") static __pinned_bss struct k_spinlock lock; static __pinned_bss uint64_t last_count; +static __pinned_bss uint64_t last_tick; +static __pinned_bss uint32_t last_elapsed; #ifdef CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME static __pinned_bss unsigned int cyc_per_tick; @@ -261,6 +253,25 @@ static inline void hpet_int_sts_set(uint32_t val) } #endif +/* ensure the comparator is always set ahead of the current counter value */ +static inline void hpet_timer_comparator_set_safe(uint64_t next) +{ + hpet_timer_comparator_set(next); + + uint64_t now = hpet_counter_get(); + + if (unlikely((int64_t)(next - now) <= 0)) { + uint32_t bump = 1; + + do { + next = now + bump; + bump *= 2; + hpet_timer_comparator_set(next); + now = hpet_counter_get(); + } while ((int64_t)(next - now) <= 0); + } +} + __isr static void hpet_isr(const void *arg) { @@ -295,14 +306,13 @@ static void hpet_isr(const void *arg) uint32_t dticks = (uint32_t)((now - last_count) / cyc_per_tick); last_count += (uint64_t)dticks * cyc_per_tick; + last_tick += dticks; + last_elapsed = 0; if (!IS_ENABLED(CONFIG_TICKLESS_KERNEL)) { uint64_t next = last_count + cyc_per_tick; - if ((int64_t)(next - now) < HPET_CMP_MIN_DELAY) { - next = now + HPET_CMP_MIN_DELAY; - } - hpet_timer_comparator_set(next); + hpet_timer_comparator_set_safe(next); } k_spin_unlock(&lock, key); @@ -354,28 +364,12 @@ void sys_clock_set_timeout(int32_t ticks, bool idle) } ticks = ticks == K_TICKS_FOREVER ? HPET_MAX_TICKS : ticks; - ticks = CLAMP(ticks - 1, 0, HPET_MAX_TICKS); + ticks = CLAMP(ticks, 0, HPET_MAX_TICKS/2); k_spinlock_key_t key = k_spin_lock(&lock); - uint64_t now = hpet_counter_get(), cyc, adj; - uint64_t max_cyc = (uint64_t)HPET_MAX_TICKS * cyc_per_tick; - - /* Round up to next tick boundary. */ - cyc = (uint64_t)ticks * cyc_per_tick; - adj = (now - last_count) + (cyc_per_tick - 1); - if (cyc <= max_cyc - adj) { - cyc += adj; - } else { - cyc = max_cyc; - } - cyc = (cyc / cyc_per_tick) * cyc_per_tick; - cyc += last_count; - - if ((int64_t)(cyc - now) < HPET_CMP_MIN_DELAY) { - cyc = now + HPET_CMP_MIN_DELAY; - } + uint64_t cyc = (last_tick + last_elapsed + ticks) * cyc_per_tick; - hpet_timer_comparator_set(cyc); + hpet_timer_comparator_set_safe(cyc); k_spin_unlock(&lock, key); #endif } @@ -391,6 +385,7 @@ uint32_t sys_clock_elapsed(void) uint64_t now = hpet_counter_get(); uint32_t ret = (uint32_t)((now - last_count) / cyc_per_tick); + last_elapsed = ret; k_spin_unlock(&lock, key); return ret; } @@ -462,12 +457,9 @@ static int sys_clock_driver_init(const struct device *dev) hpet_gconf_set(reg); - last_count = hpet_counter_get(); - if (cyc_per_tick >= HPET_CMP_MIN_DELAY) { - hpet_timer_comparator_set(last_count + cyc_per_tick); - } else { - hpet_timer_comparator_set(last_count + HPET_CMP_MIN_DELAY); - } + last_tick = hpet_counter_get() / cyc_per_tick; + last_count = last_tick * cyc_per_tick; + hpet_timer_comparator_set_safe(last_count + cyc_per_tick); return 0; } From e5b70121e7cde99cea5507958a97b3a35f99ac37 Mon Sep 17 00:00:00 2001 From: Romain Mahoux Date: Tue, 28 Mar 2023 10:15:44 +0200 Subject: [PATCH 0811/1906] samples: minimal: define an empty project configuration Cmake configuration forces projects to define a prj.conf Signed-off-by: Romain Mahoux --- samples/basic/minimal/prj.conf | 1 + 1 file changed, 1 insertion(+) create mode 100644 samples/basic/minimal/prj.conf diff --git a/samples/basic/minimal/prj.conf b/samples/basic/minimal/prj.conf new file mode 100644 index 000000000000..565c7da43580 --- /dev/null +++ b/samples/basic/minimal/prj.conf @@ -0,0 +1 @@ +# empty config From f43c7367b173b96a6cc989490dee35020549a420 Mon Sep 17 00:00:00 2001 From: Carlo Caione Date: Tue, 28 Mar 2023 10:13:35 +0200 Subject: [PATCH 0812/1906] arm64: Break circular dependency on syscall.h Commit fbf851cdc4d8f0afe60131aea6154945f126d778 is introducing a dependency between util.h and time_units.h. Now, the problem is that time_units.h is from one side included by arm64/syscall.h (syscall.h -> lib_helpers.h -> cpu.h -> util.h) but on the other side it is including syscall.h (time_units.h -> syscall.h). Break the dependency at cpu.h level. Signed-off-by: Carlo Caione --- include/zephyr/arch/arm64/cpu.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/zephyr/arch/arm64/cpu.h b/include/zephyr/arch/arm64/cpu.h index 95c9a651c1a8..6796d8d1b812 100644 --- a/include/zephyr/arch/arm64/cpu.h +++ b/include/zephyr/arch/arm64/cpu.h @@ -7,7 +7,8 @@ #ifndef ZEPHYR_INCLUDE_ARCH_ARM64_CPU_H_ #define ZEPHYR_INCLUDE_ARCH_ARM64_CPU_H_ -#include +#include +#include #define DAIFSET_FIQ_BIT BIT(0) #define DAIFSET_IRQ_BIT BIT(1) From c41dd36de242830b45ca64a6abd1d8a148a13ad3 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Mon, 27 Mar 2023 14:55:23 +0200 Subject: [PATCH 0813/1906] drivers: kconfig: unify menuconfig title strings Unify the drivers/*/Kconfig menuconfig title strings to the format " [(acronym)] [bus] drivers". Including both the full name of the driver class and an acronym makes menuconfig more user friendly as some of the acronyms are less well-known than others. It also improves Kconfig search, both via menuconfig and via the generated Kconfig documentation. Signed-off-by: Henrik Brix Andersen --- drivers/adc/Kconfig | 2 +- drivers/audio/Kconfig | 2 +- drivers/bbram/Kconfig | 2 +- drivers/bluetooth/Kconfig | 2 +- drivers/cache/Kconfig | 2 +- drivers/can/Kconfig | 2 +- drivers/clock_control/Kconfig | 2 +- drivers/coredump/Kconfig | 2 +- drivers/counter/Kconfig | 2 +- drivers/crypto/Kconfig | 2 +- drivers/dac/Kconfig | 2 +- drivers/dai/Kconfig | 2 +- drivers/disk/Kconfig | 2 +- drivers/display/Kconfig | 2 +- drivers/dma/Kconfig | 2 +- drivers/edac/Kconfig | 2 +- drivers/eeprom/Kconfig | 2 +- drivers/entropy/Kconfig | 2 +- drivers/espi/Kconfig | 2 +- drivers/ethernet/Kconfig | 2 +- drivers/flash/Kconfig | 2 +- drivers/fpga/Kconfig | 2 +- drivers/gpio/Kconfig | 2 +- drivers/hwinfo/Kconfig | 2 +- drivers/i2c/Kconfig | 2 +- drivers/i2s/Kconfig | 2 +- drivers/i3c/Kconfig | 2 +- drivers/ieee802154/Kconfig | 2 +- drivers/input/Kconfig | 2 +- drivers/interrupt_controller/Kconfig | 2 +- drivers/ipm/Kconfig | 2 +- drivers/kscan/Kconfig | 2 +- drivers/led/Kconfig | 2 +- drivers/led_strip/Kconfig | 2 +- drivers/lora/Kconfig | 2 +- drivers/mbox/Kconfig | 2 +- drivers/mdio/Kconfig | 2 +- drivers/memc/Kconfig | 2 +- drivers/mipi_dsi/Kconfig | 2 +- drivers/mm/Kconfig | 2 +- drivers/modem/Kconfig | 2 +- drivers/net/Kconfig | 2 +- drivers/neural_net/Kconfig | 2 +- drivers/peci/Kconfig | 2 +- drivers/ps2/Kconfig | 2 +- drivers/ptp_clock/Kconfig | 2 +- drivers/pwm/Kconfig | 2 +- drivers/retained_mem/Kconfig | 2 +- drivers/sdhc/Kconfig | 2 +- drivers/sensor/Kconfig | 2 +- drivers/serial/Kconfig | 2 +- drivers/smbus/Kconfig | 2 +- drivers/spi/Kconfig | 2 +- drivers/syscon/Kconfig | 2 +- drivers/timer/Kconfig | 2 +- drivers/usb/udc/Kconfig | 2 +- drivers/usb/uhc/Kconfig | 2 +- drivers/video/Kconfig | 2 +- drivers/virtualization/Kconfig | 2 +- drivers/w1/Kconfig | 2 +- drivers/watchdog/Kconfig | 2 +- drivers/wifi/Kconfig | 2 +- 62 files changed, 62 insertions(+), 62 deletions(-) diff --git a/drivers/adc/Kconfig b/drivers/adc/Kconfig index 149f5172c5d0..87487ac79f1b 100644 --- a/drivers/adc/Kconfig +++ b/drivers/adc/Kconfig @@ -7,7 +7,7 @@ # ADC options # menuconfig ADC - bool "ADC drivers" + bool "Analog-to-Digital Converter (ADC) drivers" # All platforms that implement the ADC driver are now required to # provide relevant DTS entries. help diff --git a/drivers/audio/Kconfig b/drivers/audio/Kconfig index bcc00443b160..2eb98256aac0 100644 --- a/drivers/audio/Kconfig +++ b/drivers/audio/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig AUDIO - bool "Support for Audio" + bool "Audio drivers" help Enable support for Audio diff --git a/drivers/bbram/Kconfig b/drivers/bbram/Kconfig index 84cebf27ec48..011c90e03de1 100644 --- a/drivers/bbram/Kconfig +++ b/drivers/bbram/Kconfig @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig BBRAM - bool "Battery-backed RAM drivers" + bool "Battery-backed RAM (BBRAM) drivers" help Enable BBRAM (battery-backed RAM) driver configuration. diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index b68f20ec2588..46bf62bb1a7f 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -10,7 +10,7 @@ # Controller support is an HCI driver in itself, so these HCI driver # options are only applicable if controller support hasn't been enabled. menuconfig BT_DRIVERS - bool "Bluetooth Drivers" + bool "Bluetooth drivers" default y depends on BT && !BT_CTLR diff --git a/drivers/cache/Kconfig b/drivers/cache/Kconfig index f017d9068e3a..834cc49e1813 100644 --- a/drivers/cache/Kconfig +++ b/drivers/cache/Kconfig @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig CACHE - bool "External cache controllers drivers" + bool "External cache controller drivers" default y if CACHE_MANAGEMENT help Enable support for external cache controllers drivers diff --git a/drivers/can/Kconfig b/drivers/can/Kconfig index 9875c3d1b9d8..c025c134f9c8 100644 --- a/drivers/can/Kconfig +++ b/drivers/can/Kconfig @@ -7,7 +7,7 @@ # CAN options # menuconfig CAN - bool "CAN Drivers" + bool "Controller Area Network (CAN) drivers" help Enable CAN Driver Configuration diff --git a/drivers/clock_control/Kconfig b/drivers/clock_control/Kconfig index 1f2a2347fa96..114b9f60f52e 100644 --- a/drivers/clock_control/Kconfig +++ b/drivers/clock_control/Kconfig @@ -7,7 +7,7 @@ # Clock controller drivers # menuconfig CLOCK_CONTROL - bool "Hardware clock controller support" + bool "Clock controller drivers" help Enable support for hardware clock controller. Such hardware can provide clock for other subsystem, and thus can be also used for diff --git a/drivers/coredump/Kconfig b/drivers/coredump/Kconfig index d27dd9c63a17..a3e1affcd9f1 100644 --- a/drivers/coredump/Kconfig +++ b/drivers/coredump/Kconfig @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig COREDUMP_DEVICE - bool "Coredump pseudo-device driver" + bool "Coredump pseudo-device drivers" help Enable support for a pseudo-device to help capturing desired data into core dumps. diff --git a/drivers/counter/Kconfig b/drivers/counter/Kconfig index 14169ef03fe3..ff983fb4f03f 100644 --- a/drivers/counter/Kconfig +++ b/drivers/counter/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig COUNTER - bool "Counter Drivers" + bool "Counter drivers" help Enable support for counter and timer. diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index c9c5a203bd13..245fe4891542 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -7,7 +7,7 @@ # CRYPTO options # menuconfig CRYPTO - bool "Crypto Drivers" + bool "Crypto drivers" if CRYPTO diff --git a/drivers/dac/Kconfig b/drivers/dac/Kconfig index 7902abeaaca8..7b5457214601 100644 --- a/drivers/dac/Kconfig +++ b/drivers/dac/Kconfig @@ -7,7 +7,7 @@ # DAC options # menuconfig DAC - bool "DAC drivers" + bool "Digital-to-Analog Converter (DAC) drivers" help Enable DAC (Digital to Analog Converter) driver configuration. diff --git a/drivers/dai/Kconfig b/drivers/dai/Kconfig index 09395cca72d3..770b528da6a3 100644 --- a/drivers/dai/Kconfig +++ b/drivers/dai/Kconfig @@ -7,7 +7,7 @@ # DAI Drivers # menuconfig DAI - bool "DAI drivers" + bool "Digital Audio Interface (DAI) drivers" help Enable support for the DAI interface drivers. diff --git a/drivers/disk/Kconfig b/drivers/disk/Kconfig index 4672bb2e743d..38e173e68197 100644 --- a/drivers/disk/Kconfig +++ b/drivers/disk/Kconfig @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig DISK_DRIVERS - bool "Disk Drivers" + bool "Disk drivers" help Disk Driver configuration diff --git a/drivers/display/Kconfig b/drivers/display/Kconfig index 9323683bb9e5..51800562ea1e 100644 --- a/drivers/display/Kconfig +++ b/drivers/display/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig DISPLAY - bool "Display Drivers" + bool "Display controller drivers" help Enable display drivers diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig index 76daa4cabee4..ad0df00b2c02 100644 --- a/drivers/dma/Kconfig +++ b/drivers/dma/Kconfig @@ -7,7 +7,7 @@ # DMA options # menuconfig DMA - bool "DMA driver Configuration" + bool "Direct Memory Access (DMA) drivers" if DMA config DMA_64BIT diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig index ee8763ccb543..45e499a749a6 100644 --- a/drivers/edac/Kconfig +++ b/drivers/edac/Kconfig @@ -4,7 +4,7 @@ # EDAC configuration options menuconfig EDAC - bool "Error Detection and Correction (EDAC) Drivers" + bool "Error Detection and Correction (EDAC) drivers" help Enable Error Detection and Correction (EDAC) driver. diff --git a/drivers/eeprom/Kconfig b/drivers/eeprom/Kconfig index f4f1ac55c510..e5a55bad0378 100644 --- a/drivers/eeprom/Kconfig +++ b/drivers/eeprom/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig EEPROM - bool "EEPROM hardware support" + bool "Electrically Erasable Programmable Read-Only Memory (EEPROM) drivers" help Enable support for EEPROM hardware. diff --git a/drivers/entropy/Kconfig b/drivers/entropy/Kconfig index badc4e812e94..e932f62c6bff 100644 --- a/drivers/entropy/Kconfig +++ b/drivers/entropy/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig ENTROPY_GENERATOR - bool "Entropy Drivers" + bool "Entropy drivers" help Include entropy drivers in system config. diff --git a/drivers/espi/Kconfig b/drivers/espi/Kconfig index f8ee937af575..0a8f6173b8d7 100644 --- a/drivers/espi/Kconfig +++ b/drivers/espi/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig ESPI - bool "ESPI Driver" + bool "Enhanced Serial Peripheral Interface (eSPI) bus drivers" help Enable ESPI Driver. diff --git a/drivers/ethernet/Kconfig b/drivers/ethernet/Kconfig index f7ee67f075e1..2c2e5564d25d 100644 --- a/drivers/ethernet/Kconfig +++ b/drivers/ethernet/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig ETH_DRIVER - bool "Ethernet Drivers" + bool "Ethernet drivers" default y depends on NET_L2_ETHERNET diff --git a/drivers/flash/Kconfig b/drivers/flash/Kconfig index bf6fa61c4344..17fd2563f777 100644 --- a/drivers/flash/Kconfig +++ b/drivers/flash/Kconfig @@ -30,7 +30,7 @@ config FLASH_JESD216 devices to enable building a common support module. menuconfig FLASH - bool "Flash hardware support" + bool "Flash drivers" help Enable support for the flash hardware. diff --git a/drivers/fpga/Kconfig b/drivers/fpga/Kconfig index 6657a528fa0f..de5450a1406e 100644 --- a/drivers/fpga/Kconfig +++ b/drivers/fpga/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig FPGA - bool "FPGA Drivers" + bool "Field-Programmable Gate Array (FPGA) drivers" help Enable support for FPGA drivers. diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 3e6d21ef6c89..c10c7ea1ee4c 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig GPIO - bool "GPIO Drivers" + bool "General-Purpose Input/Output (GPIO) drivers" help Include GPIO drivers in system config diff --git a/drivers/hwinfo/Kconfig b/drivers/hwinfo/Kconfig index ae53d1859428..6737438ed56e 100644 --- a/drivers/hwinfo/Kconfig +++ b/drivers/hwinfo/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig HWINFO - bool "Hardware Information driver" + bool "Hardware Information drivers" help Enable hwinfo driver. diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig index f80d6d728c8b..18f843f43e01 100644 --- a/drivers/i2c/Kconfig +++ b/drivers/i2c/Kconfig @@ -7,7 +7,7 @@ # I2C options # menuconfig I2C - bool "I2C Drivers" + bool "Inter-Integrated Circuit (I2C) bus drivers" help Enable I2C Driver Configuration diff --git a/drivers/i2s/Kconfig b/drivers/i2s/Kconfig index c194ab5bc047..37e8e2413846 100644 --- a/drivers/i2s/Kconfig +++ b/drivers/i2s/Kconfig @@ -7,7 +7,7 @@ # I2S Drivers # menuconfig I2S - bool "I2S bus drivers" + bool "Inter-IC Sound (I2S) bus drivers" help Enable support for the I2S (Inter-IC Sound) hardware bus. diff --git a/drivers/i3c/Kconfig b/drivers/i3c/Kconfig index 8d4d06b2798d..f4a343632abf 100644 --- a/drivers/i3c/Kconfig +++ b/drivers/i3c/Kconfig @@ -5,7 +5,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig I3C - bool "I3C Drivers" + bool "Improved Inter-Integrated Circuit (I3C) bus drivers" help Enable I3C Driver Configuration diff --git a/drivers/ieee802154/Kconfig b/drivers/ieee802154/Kconfig index 327d7e2d2d29..d5673ff28277 100644 --- a/drivers/ieee802154/Kconfig +++ b/drivers/ieee802154/Kconfig @@ -7,7 +7,7 @@ # IEEE 802.15.4 options # menuconfig IEEE802154 - bool "IEEE 802.15.4 drivers options" + bool "IEEE 802.15.4 drivers" depends on NETWORKING default y if NET_L2_PHY_IEEE802154 diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index f62fd27fac22..6474c64aadf9 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -3,7 +3,7 @@ if INPUT -menu "Input Drivers" +menu "Input drivers" source "drivers/input/Kconfig.gpio_keys" diff --git a/drivers/interrupt_controller/Kconfig b/drivers/interrupt_controller/Kconfig index d436bb80b80c..31b3cad62608 100644 --- a/drivers/interrupt_controller/Kconfig +++ b/drivers/interrupt_controller/Kconfig @@ -3,7 +3,7 @@ # Copyright (c) 2015 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -menu "Interrupt Controllers" +menu "Interrupt controller drivers" config ARCV2_INTERRUPT_UNIT bool "ARCv2 Interrupt Unit" diff --git a/drivers/ipm/Kconfig b/drivers/ipm/Kconfig index 6ac1eb398673..c69321349645 100644 --- a/drivers/ipm/Kconfig +++ b/drivers/ipm/Kconfig @@ -1,7 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig IPM - bool "IPM drivers" + bool "Inter-Processor Mailbox (IPM) drivers" help Include interrupt-based inter-processor mailboxes drivers in system configuration diff --git a/drivers/kscan/Kconfig b/drivers/kscan/Kconfig index f8cebd2b3e73..b19ae865c1d7 100644 --- a/drivers/kscan/Kconfig +++ b/drivers/kscan/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig KSCAN - bool "Keyboard Scan Drivers" + bool "Keyboard scan drivers" help Include Keyboard scan drivers in system config. diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig index a93e4dc83cc5..7c4f5ced0864 100644 --- a/drivers/led/Kconfig +++ b/drivers/led/Kconfig @@ -4,7 +4,7 @@ # Top-level configuration file for LED drivers. menuconfig LED - bool "LED drivers" + bool "Light-Emitting Diode (LED) drivers" help Include LED drivers in the system configuration. diff --git a/drivers/led_strip/Kconfig b/drivers/led_strip/Kconfig index e1893da1a9ea..269657dd0b8a 100644 --- a/drivers/led_strip/Kconfig +++ b/drivers/led_strip/Kconfig @@ -5,7 +5,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig LED_STRIP - bool "LED strip drivers" + bool "Light-Emitting Diode (LED) strip drivers" help Include LED strip drivers in the system configuration. diff --git a/drivers/lora/Kconfig b/drivers/lora/Kconfig index b04a4775099f..ddc1e50e6250 100644 --- a/drivers/lora/Kconfig +++ b/drivers/lora/Kconfig @@ -7,7 +7,7 @@ # Top-level configuration file for LORA drivers. menuconfig LORA - bool "LoRa support [EXPERIMENTAL]" + bool "LoRa drivers [EXPERIMENTAL]" select POLL select EXPERIMENTAL help diff --git a/drivers/mbox/Kconfig b/drivers/mbox/Kconfig index 38cb08af4ef7..58dd92f208a3 100644 --- a/drivers/mbox/Kconfig +++ b/drivers/mbox/Kconfig @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig MBOX - bool "MBOX drivers" + bool "Multi-Channel Inter-Processor Mailbox (MBOX) drivers" help Include multi-channel interrupt-based inter-processor mailboxes drivers in system configuration diff --git a/drivers/mdio/Kconfig b/drivers/mdio/Kconfig index 603efb5ee643..4fa8b9dd085f 100644 --- a/drivers/mdio/Kconfig +++ b/drivers/mdio/Kconfig @@ -7,7 +7,7 @@ # MDIO options # menuconfig MDIO - bool "MDIO Drivers" + bool "Management Data Input/Output (MDIO) drivers" help Enable MDIO Driver Configuration diff --git a/drivers/memc/Kconfig b/drivers/memc/Kconfig index 5912f7a18582..56fc44bb99ff 100644 --- a/drivers/memc/Kconfig +++ b/drivers/memc/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig MEMC - bool "Memory controllers [EXPERIMENTAL]" + bool "Memory controller drivers [EXPERIMENTAL]" select EXPERIMENTAL help Add support for memory controllers diff --git a/drivers/mipi_dsi/Kconfig b/drivers/mipi_dsi/Kconfig index 35307b765580..5e4326e8204e 100644 --- a/drivers/mipi_dsi/Kconfig +++ b/drivers/mipi_dsi/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig MIPI_DSI - bool "MIPI-DSI Host Controllers [EXPERIMENTAL]" + bool "MIPI-DSI Host Controller drivers [EXPERIMENTAL]" select EXPERIMENTAL help Add support for MIPI-DSI host controllers diff --git a/drivers/mm/Kconfig b/drivers/mm/Kconfig index 4cf229cff682..15c418c78a4b 100644 --- a/drivers/mm/Kconfig +++ b/drivers/mm/Kconfig @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig MM_DRV - bool "Memory Management Drivers [EXPERIMENTAL]" + bool "Memory Management drivers [EXPERIMENTAL]" select EXPERIMENTAL select KERNEL_VM_SUPPORT help diff --git a/drivers/modem/Kconfig b/drivers/modem/Kconfig index 02e140fb4aca..2ccaf7f78e5e 100644 --- a/drivers/modem/Kconfig +++ b/drivers/modem/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig MODEM - bool "Modem Drivers" + bool "Modem drivers" help Enable config options for modem drivers. diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index dc4ac6ccbb3a..f6e0faa334a5 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig NET_DRIVERS - bool "Network Drivers" + bool "Network drivers" if NET_DRIVERS diff --git a/drivers/neural_net/Kconfig b/drivers/neural_net/Kconfig index b6fbd63e5d6f..001893744d7f 100644 --- a/drivers/neural_net/Kconfig +++ b/drivers/neural_net/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig NEURAL_NET_ACCEL - bool "Neural Network Accelerator Drivers" + bool "Neural Network Accelerator drivers" help Enable support for Neural Network Accelerators diff --git a/drivers/peci/Kconfig b/drivers/peci/Kconfig index 120006ce840f..41e15f10ca68 100644 --- a/drivers/peci/Kconfig +++ b/drivers/peci/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig PECI - bool "PECI Driver" + bool "Platform Environment Control Interface (PECI) drivers" help Include PECI drivers in system config. diff --git a/drivers/ps2/Kconfig b/drivers/ps2/Kconfig index 8677ada48306..5233afdf6383 100644 --- a/drivers/ps2/Kconfig +++ b/drivers/ps2/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig PS2 - bool "PS/2 Drivers" + bool "PS/2 drivers" help Include PS/2 drivers in system config. diff --git a/drivers/ptp_clock/Kconfig b/drivers/ptp_clock/Kconfig index fbbbff10d979..9417d7f06332 100644 --- a/drivers/ptp_clock/Kconfig +++ b/drivers/ptp_clock/Kconfig @@ -2,6 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 config PTP_CLOCK - bool "Precision Time Protocol Clock driver support" + bool "Precision Time Protocol (PTP) Clock drivers" help Enable options for Precision Time Protocol Clock drivers. diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index e20de110e80f..021ad308033a 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig PWM - bool "PWM (Pulse Width Modulation) Drivers" + bool "Pulse Width Modulation (PWM) drivers" help Enable config options for PWM drivers. diff --git a/drivers/retained_mem/Kconfig b/drivers/retained_mem/Kconfig index c8a9862dfe06..35d218496334 100644 --- a/drivers/retained_mem/Kconfig +++ b/drivers/retained_mem/Kconfig @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig RETAINED_MEM - bool "Retained memory support" + bool "Retained memory drivers" help Enables support for drivers that can retain their data whilst the device is powered (may be lost in low power states). diff --git a/drivers/sdhc/Kconfig b/drivers/sdhc/Kconfig index f65f92859171..0969c6fa73cf 100644 --- a/drivers/sdhc/Kconfig +++ b/drivers/sdhc/Kconfig @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig SDHC - bool "SDHC drivers" + bool "Secure Digital High Capacity (SDHC) drivers" help Include drivers for SD host controller diff --git a/drivers/sensor/Kconfig b/drivers/sensor/Kconfig index 11ae4f026563..ebfdd71d6c66 100644 --- a/drivers/sensor/Kconfig +++ b/drivers/sensor/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig SENSOR - bool "Sensor Drivers" + bool "Sensor drivers" help Include sensor drivers in system config diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index e3657a6eba0e..38ab4a9e4155 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig SERIAL - bool "Serial Drivers" + bool "Serial drivers" help Enable options for serial drivers. diff --git a/drivers/smbus/Kconfig b/drivers/smbus/Kconfig index 927c70c1c301..e4581fae86b2 100644 --- a/drivers/smbus/Kconfig +++ b/drivers/smbus/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig SMBUS - bool "SMBus Drivers" + bool "System Management Bus (SMBus) drivers" help Enable SMBus Driver Configuration diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 79708f6b4200..2c2bb69e2fff 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -7,7 +7,7 @@ # SPI Drivers # menuconfig SPI - bool "SPI hardware bus support" + bool "Serial Peripheral Interface (SPI) bus drivers" help Enable support for the SPI hardware bus. diff --git a/drivers/syscon/Kconfig b/drivers/syscon/Kconfig index ad8442b3dce3..19890158203f 100644 --- a/drivers/syscon/Kconfig +++ b/drivers/syscon/Kconfig @@ -7,7 +7,7 @@ # SYSCON options # menuconfig SYSCON - bool "SYSCON (System Controller) drivers" + bool "System Controller (SYSCON) drivers" help SYSCON (System Controller) drivers. System controller node represents a register region containing a set of miscellaneous registers. The diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig index 7a9b1f901fcd..a642f004ad6f 100644 --- a/drivers/timer/Kconfig +++ b/drivers/timer/Kconfig @@ -7,7 +7,7 @@ if SYS_CLOCK_EXISTS -menu "Timer Drivers" +menu "Timer drivers" config TIMER_HAS_64BIT_CYCLE_COUNTER bool diff --git a/drivers/usb/udc/Kconfig b/drivers/usb/udc/Kconfig index 9c80af70f1ea..566c93bef670 100644 --- a/drivers/usb/udc/Kconfig +++ b/drivers/usb/udc/Kconfig @@ -3,7 +3,7 @@ menuconfig UDC_DRIVER - bool "USB device controller driver [EXPERIMENTAL]" + bool "USB device controller drivers [EXPERIMENTAL]" select EXPERIMENTAL select NET_BUF help diff --git a/drivers/usb/uhc/Kconfig b/drivers/usb/uhc/Kconfig index 65b679724db3..e6da1d4d3dff 100644 --- a/drivers/usb/uhc/Kconfig +++ b/drivers/usb/uhc/Kconfig @@ -3,7 +3,7 @@ menuconfig UHC_DRIVER - bool "USB host controller driver [EXPERIMENTAL]" + bool "USB host controller drivers [EXPERIMENTAL]" select EXPERIMENTAL select NET_BUF help diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index 40f5855f42cc..b02680b2244d 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -7,7 +7,7 @@ # VIDEO Drivers # menuconfig VIDEO - bool "VIDEO hardware support" + bool "Video drivers" help Enable support for the VIDEO. diff --git a/drivers/virtualization/Kconfig b/drivers/virtualization/Kconfig index a5ac6820a342..815484b4ed5d 100644 --- a/drivers/virtualization/Kconfig +++ b/drivers/virtualization/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig VIRTUALIZATION - bool "Virtualization guests drivers" + bool "Virtualization guest drivers" help This contains various drivers meant to support and expose features when Zephyr is running as a guest in a virtualized or emulated diff --git a/drivers/w1/Kconfig b/drivers/w1/Kconfig index f14f024dd4dd..d1cf835075b8 100644 --- a/drivers/w1/Kconfig +++ b/drivers/w1/Kconfig @@ -5,7 +5,7 @@ menuconfig W1 bool - prompt "1-Wire Drivers" + prompt "1-Wire bus drivers" select CRC help Enable 1-Wire Drivers diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index e8db5f5c29d7..77a9ac1547c0 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -5,7 +5,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig WATCHDOG - bool "Watchdog Support" + bool "Watchdog drivers" help Include support for watchdogs. diff --git a/drivers/wifi/Kconfig b/drivers/wifi/Kconfig index ea6245b33b17..4bb4197bedeb 100644 --- a/drivers/wifi/Kconfig +++ b/drivers/wifi/Kconfig @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 menuconfig WIFI - bool "Wi-Fi Drivers" + bool "Wi-Fi drivers" if WIFI From 357181be23ec8fd736a3079acac861ef5808ca82 Mon Sep 17 00:00:00 2001 From: Andreas Chmielewski Date: Mon, 27 Mar 2023 17:06:53 +0200 Subject: [PATCH 0814/1906] net: lwm2m: Add is_suspended() routine Add is_suspended() routine to have control over the rd client from the outside whether it is suspended. Signed-off-by: Andreas Chmielewski --- subsys/net/lib/lwm2m/lwm2m_rd_client.c | 19 +++++++++++++++++++ subsys/net/lib/lwm2m/lwm2m_rd_client.h | 1 + 2 files changed, 20 insertions(+) diff --git a/subsys/net/lib/lwm2m/lwm2m_rd_client.c b/subsys/net/lib/lwm2m/lwm2m_rd_client.c index 1ebb78bb622b..3bdc11eaefda 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rd_client.c +++ b/subsys/net/lib/lwm2m/lwm2m_rd_client.c @@ -246,6 +246,16 @@ static bool sm_is_registered(void) return registered; } +static bool sm_is_suspended(void) +{ + k_mutex_lock(&client.mutex, K_FOREVER); + bool suspended = (client.engine_state == ENGINE_SUSPENDED); + + k_mutex_unlock(&client.mutex); + return suspended; +} + + static uint8_t get_sm_state(void) { k_mutex_lock(&client.mutex, K_FOREVER); @@ -1516,6 +1526,15 @@ bool lwm2m_rd_client_is_registred(struct lwm2m_ctx *client_ctx) return true; } +bool lwm2m_rd_client_is_suspended(struct lwm2m_ctx *client_ctx) +{ + if (client.ctx != client_ctx || !sm_is_suspended()) { + return false; + } + + return true; +} + int lwm2m_rd_client_init(void) { diff --git a/subsys/net/lib/lwm2m/lwm2m_rd_client.h b/subsys/net/lib/lwm2m/lwm2m_rd_client.h index c0d4c39dc7b0..0fda76b126f2 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rd_client.h +++ b/subsys/net/lib/lwm2m/lwm2m_rd_client.h @@ -46,6 +46,7 @@ int lwm2m_rd_client_resume(void); int lwm2m_rd_client_timeout(struct lwm2m_ctx *client_ctx); bool lwm2m_rd_client_is_registred(struct lwm2m_ctx *client_ctx); +bool lwm2m_rd_client_is_suspended(struct lwm2m_ctx *client_ctx); #if defined(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP) void engine_bootstrap_finish(void); #endif From 70a0364c2a3decb3233c95e55d068bc6fafcc3b0 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sun, 26 Mar 2023 17:06:15 +0200 Subject: [PATCH 0815/1906] bluetooth: tester: Add support for BTP GATT Change Database command This command allows for more predictable GATT database changed tests and allows to reduce custom test configurations from autopts. Signed-off-by: Szymon Janc --- tests/bluetooth/tester/src/btp/btp_gatt.h | 7 ++- tests/bluetooth/tester/src/btp_gatt.c | 63 +++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/tests/bluetooth/tester/src/btp/btp_gatt.h b/tests/bluetooth/tester/src/btp/btp_gatt.h index 269244309927..c22bc748229e 100644 --- a/tests/bluetooth/tester/src/btp/btp_gatt.h +++ b/tests/bluetooth/tester/src/btp/btp_gatt.h @@ -319,10 +319,15 @@ struct btp_gatt_get_attribute_value_rp { uint8_t value[]; } __packed; +#define BTP_GATT_CHANGE_DB_REMOVE 0x00 +#define BTP_GATT_CHANGE_DB_ADD 0x01 +#define BTP_GATT_CHANGE_DB_ANY 0x02 + #define BTP_GATT_CHANGE_DB 0x1e struct btp_gatt_change_db_cmd { uint16_t start_handle; - uint8_t visibility; + uint16_t end_handle; + uint8_t operation; } __packed; #define BTP_GATT_EATT_CONNECT 0x1f diff --git a/tests/bluetooth/tester/src/btp_gatt.c b/tests/bluetooth/tester/src/btp_gatt.c index 4d5e412f7a25..483e6adc688d 100644 --- a/tests/bluetooth/tester/src/btp_gatt.c +++ b/tests/bluetooth/tester/src/btp_gatt.c @@ -255,6 +255,7 @@ static uint8_t supported_commands(const void *cmd, uint16_t cmd_len, tester_set_bit(rp->data, BTP_GATT_CFG_INDICATE); tester_set_bit(rp->data, BTP_GATT_GET_ATTRIBUTES); tester_set_bit(rp->data, BTP_GATT_GET_ATTRIBUTE_VALUE); + tester_set_bit(rp->data, BTP_GATT_CHANGE_DB); tester_set_bit(rp->data, BTP_GATT_EATT_CONNECT); /* octet 4 */ @@ -2319,6 +2320,63 @@ static uint8_t get_attr_val(const void *cmd, uint16_t cmd_len, return BTP_STATUS_FAILED; } +static struct bt_uuid_128 test_uuid = BT_UUID_INIT_128( + 0x94, 0x99, 0xb6, 0xa9, 0xcd, 0x1c, 0x42, 0x95, + 0xb2, 0x07, 0x2f, 0x7f, 0xec, 0xc0, 0xc7, 0x5b); + +static struct bt_gatt_attr test_attrs[] = { + BT_GATT_PRIMARY_SERVICE(&test_uuid), +}; + +static struct bt_gatt_service test_service = BT_GATT_SERVICE(test_attrs); + +static uint8_t change_database(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_gatt_change_db_cmd *cp = cmd; + static bool test_service_registered; + int err; + + /* currently support only "any" handles */ + if (cp->start_handle > 0 || cp->end_handle > 0) { + return BTP_STATUS_FAILED; + } + + switch (cp->operation) { + case BTP_GATT_CHANGE_DB_ADD: + if (test_service_registered) { + return BTP_STATUS_FAILED; + } + + err = bt_gatt_service_register(&test_service); + break; + case BTP_GATT_CHANGE_DB_REMOVE: + if (!test_service_registered) { + return BTP_STATUS_FAILED; + } + + err = bt_gatt_service_unregister(&test_service); + break; + case BTP_GATT_CHANGE_DB_ANY: + if (test_service_registered) { + err = bt_gatt_service_unregister(&test_service); + } else { + err = bt_gatt_service_register(&test_service); + } + break; + default: + return BTP_STATUS_FAILED; + } + + if (err) { + return BTP_STATUS_FAILED; + } + + test_service_registered = !test_service_registered; + + return BTP_STATUS_SUCCESS; +} + static uint8_t eatt_connect(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -2478,6 +2536,11 @@ static const struct btp_handler handlers[] = { .expect_len = sizeof(struct btp_gatt_get_attribute_value_cmd), .func = get_attr_val, }, + { + .opcode = BTP_GATT_CHANGE_DB, + .expect_len = sizeof(struct btp_gatt_change_db_cmd), + .func = change_database, + }, { .opcode = BTP_GATT_EATT_CONNECT, .expect_len = sizeof(struct btp_gatt_eatt_connect_cmd), From fc2dcc466529c7e8d98cd6f68b5043f71b597baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Fri, 24 Mar 2023 08:34:00 +0100 Subject: [PATCH 0816/1906] Bluetooth: Mesh: save stream mode in io_open() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mode affects access to flash aread for `block_start`. When mode is set to `BT_MESH_BLOB_READ` function return early, and because `BT_MESH_BLOB_READ = 0` this is default behaviour. For write flash area must be erased to allow driver to write there new data - bits can only be pulled down, so overwrite will not be permitted. Signed-off-by: Krzysztof Kopyściński --- subsys/bluetooth/mesh/blob_io_flash.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subsys/bluetooth/mesh/blob_io_flash.c b/subsys/bluetooth/mesh/blob_io_flash.c index b3af5ab7189a..283b42df8576 100644 --- a/subsys/bluetooth/mesh/blob_io_flash.c +++ b/subsys/bluetooth/mesh/blob_io_flash.c @@ -43,6 +43,8 @@ static int io_open(const struct bt_mesh_blob_io *io, { struct bt_mesh_blob_io_flash *flash = FLASH_IO(io); + flash->mode = mode; + return flash_area_open(flash->area_id, &flash->area); } From 3322bdce10f3eb168fee21dda9dff439fdeeb054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Mon, 27 Mar 2023 13:21:12 +0200 Subject: [PATCH 0817/1906] Bluetooth: Mesh: fix blob_cli.c build with Clang MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There should be logic OR, not bitwise OR in update_missing_chunks. Signed-off-by: Krzysztof Kopyściński --- subsys/bluetooth/mesh/blob_cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/bluetooth/mesh/blob_cli.c b/subsys/bluetooth/mesh/blob_cli.c index abebdb71989f..5beb7b404a03 100644 --- a/subsys/bluetooth/mesh/blob_cli.c +++ b/subsys/bluetooth/mesh/blob_cli.c @@ -210,7 +210,7 @@ static void update_missing_chunks(struct bt_mesh_blob_cli *cli) } for (size_t idx = 0; idx < cli->block.chunk_count; idx++) { - bool missing = blob_chunk_missing_get(cli->block.missing, idx) | + bool missing = blob_chunk_missing_get(cli->block.missing, idx) || blob_chunk_missing_get(target->pull->missing, idx); blob_chunk_missing_set(cli->block.missing, idx, missing); } From 4bcd03d2cb68ab91d1828ae020aeca1d643ed9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Mon, 27 Mar 2023 14:50:26 +0200 Subject: [PATCH 0818/1906] Tests: Bluetooth: Make space for Mesh tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit moves app from /tests/bluetooth/mesh to tests/bluetooth/mesh/basic. This allows to reuse /tests/bluetooth/mesh directory as location for more tests. Signed-off-by: Krzysztof Kopyściński --- tests/bluetooth/mesh/{ => basic}/CMakeLists.txt | 0 tests/bluetooth/mesh/{ => basic}/dbg.conf | 0 tests/bluetooth/mesh/{ => basic}/ext_adv.conf | 0 tests/bluetooth/mesh/{ => basic}/friend.conf | 0 tests/bluetooth/mesh/{ => basic}/gatt.conf | 0 tests/bluetooth/mesh/{ => basic}/lpn.conf | 0 tests/bluetooth/mesh/{ => basic}/multi_ext_adv.conf | 0 tests/bluetooth/mesh/{ => basic}/pb_gatt.conf | 0 tests/bluetooth/mesh/{ => basic}/prj.conf | 0 tests/bluetooth/mesh/{ => basic}/proxy.conf | 0 tests/bluetooth/mesh/{ => basic}/src/main.c | 0 tests/bluetooth/mesh/{ => basic}/testcase.yaml | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename tests/bluetooth/mesh/{ => basic}/CMakeLists.txt (100%) rename tests/bluetooth/mesh/{ => basic}/dbg.conf (100%) rename tests/bluetooth/mesh/{ => basic}/ext_adv.conf (100%) rename tests/bluetooth/mesh/{ => basic}/friend.conf (100%) rename tests/bluetooth/mesh/{ => basic}/gatt.conf (100%) rename tests/bluetooth/mesh/{ => basic}/lpn.conf (100%) rename tests/bluetooth/mesh/{ => basic}/multi_ext_adv.conf (100%) rename tests/bluetooth/mesh/{ => basic}/pb_gatt.conf (100%) rename tests/bluetooth/mesh/{ => basic}/prj.conf (100%) rename tests/bluetooth/mesh/{ => basic}/proxy.conf (100%) rename tests/bluetooth/mesh/{ => basic}/src/main.c (100%) rename tests/bluetooth/mesh/{ => basic}/testcase.yaml (100%) diff --git a/tests/bluetooth/mesh/CMakeLists.txt b/tests/bluetooth/mesh/basic/CMakeLists.txt similarity index 100% rename from tests/bluetooth/mesh/CMakeLists.txt rename to tests/bluetooth/mesh/basic/CMakeLists.txt diff --git a/tests/bluetooth/mesh/dbg.conf b/tests/bluetooth/mesh/basic/dbg.conf similarity index 100% rename from tests/bluetooth/mesh/dbg.conf rename to tests/bluetooth/mesh/basic/dbg.conf diff --git a/tests/bluetooth/mesh/ext_adv.conf b/tests/bluetooth/mesh/basic/ext_adv.conf similarity index 100% rename from tests/bluetooth/mesh/ext_adv.conf rename to tests/bluetooth/mesh/basic/ext_adv.conf diff --git a/tests/bluetooth/mesh/friend.conf b/tests/bluetooth/mesh/basic/friend.conf similarity index 100% rename from tests/bluetooth/mesh/friend.conf rename to tests/bluetooth/mesh/basic/friend.conf diff --git a/tests/bluetooth/mesh/gatt.conf b/tests/bluetooth/mesh/basic/gatt.conf similarity index 100% rename from tests/bluetooth/mesh/gatt.conf rename to tests/bluetooth/mesh/basic/gatt.conf diff --git a/tests/bluetooth/mesh/lpn.conf b/tests/bluetooth/mesh/basic/lpn.conf similarity index 100% rename from tests/bluetooth/mesh/lpn.conf rename to tests/bluetooth/mesh/basic/lpn.conf diff --git a/tests/bluetooth/mesh/multi_ext_adv.conf b/tests/bluetooth/mesh/basic/multi_ext_adv.conf similarity index 100% rename from tests/bluetooth/mesh/multi_ext_adv.conf rename to tests/bluetooth/mesh/basic/multi_ext_adv.conf diff --git a/tests/bluetooth/mesh/pb_gatt.conf b/tests/bluetooth/mesh/basic/pb_gatt.conf similarity index 100% rename from tests/bluetooth/mesh/pb_gatt.conf rename to tests/bluetooth/mesh/basic/pb_gatt.conf diff --git a/tests/bluetooth/mesh/prj.conf b/tests/bluetooth/mesh/basic/prj.conf similarity index 100% rename from tests/bluetooth/mesh/prj.conf rename to tests/bluetooth/mesh/basic/prj.conf diff --git a/tests/bluetooth/mesh/proxy.conf b/tests/bluetooth/mesh/basic/proxy.conf similarity index 100% rename from tests/bluetooth/mesh/proxy.conf rename to tests/bluetooth/mesh/basic/proxy.conf diff --git a/tests/bluetooth/mesh/src/main.c b/tests/bluetooth/mesh/basic/src/main.c similarity index 100% rename from tests/bluetooth/mesh/src/main.c rename to tests/bluetooth/mesh/basic/src/main.c diff --git a/tests/bluetooth/mesh/testcase.yaml b/tests/bluetooth/mesh/basic/testcase.yaml similarity index 100% rename from tests/bluetooth/mesh/testcase.yaml rename to tests/bluetooth/mesh/basic/testcase.yaml From 03c966d9ef2fad7647a1552e10edde588ee0ca7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Fri, 24 Mar 2023 08:58:35 +0100 Subject: [PATCH 0819/1906] tests: Bluetooth: Mesh: add unit tests for blob_io_flash module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This tests functions accessible from blob_io_flash via `bt_mesh_blob_io` object. Whole partition of slot1 is filled with test data using flash_map API and then read using blob_io_flash, by reading it as blocks and chunks. `chunk_wr` is tested my writing sample data of size of slot1 partition and checked if each chunk is written correctly, and if whole partition is filled with correct data at the end. Both of these test use `bt_mesh_blob_io_flash_init` and `io_open` to prepare stream and call `block_start` at every new block to check if flash is prepared correctly. Signed-off-by: Krzysztof Kopyściński --- .../mesh/blob_io_flash/CMakeLists.txt | 8 + tests/bluetooth/mesh/blob_io_flash/prj.conf | 23 ++ tests/bluetooth/mesh/blob_io_flash/src/main.c | 278 ++++++++++++++++++ .../mesh/blob_io_flash/testcase.yaml | 6 + 4 files changed, 315 insertions(+) create mode 100644 tests/bluetooth/mesh/blob_io_flash/CMakeLists.txt create mode 100644 tests/bluetooth/mesh/blob_io_flash/prj.conf create mode 100644 tests/bluetooth/mesh/blob_io_flash/src/main.c create mode 100644 tests/bluetooth/mesh/blob_io_flash/testcase.yaml diff --git a/tests/bluetooth/mesh/blob_io_flash/CMakeLists.txt b/tests/bluetooth/mesh/blob_io_flash/CMakeLists.txt new file mode 100644 index 000000000000..b65bae0d73e7 --- /dev/null +++ b/tests/bluetooth/mesh/blob_io_flash/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(bluetooth_blob_io_flash) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/bluetooth/mesh/blob_io_flash/prj.conf b/tests/bluetooth/mesh/blob_io_flash/prj.conf new file mode 100644 index 000000000000..e65e79147245 --- /dev/null +++ b/tests/bluetooth/mesh/blob_io_flash/prj.conf @@ -0,0 +1,23 @@ +CONFIG_ZTEST=y +CONFIG_FLASH=y +CONFIG_FLASH_PAGE_LAYOUT=y +CONFIG_FLASH_MAP=y +CONFIG_FLASH_AREA_CHECK_INTEGRITY=y +CONFIG_FLASH_SIMULATOR=y +# Written chunks have 0xFF padding on start and end to assure word alignment with flash. +# Start padding can overlap data of previous chunk; flash drivers can only pull bits down to 0, +# so overwriting with 0xFF is not possible. This config allows to "write" start padding 0xFF over +# previously witten data, which is considered overwrite although it takes no effect. +CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y + +CONFIG_BT=y +CONFIG_BT_NO_DRIVER=y +CONFIG_BT_OBSERVER=y +CONFIG_BT_PERIPHERAL=y +CONFIG_BT_MESH=y +CONFIG_BT_MESH_V1d1=y +CONFIG_BT_MESH_BLOB_SRV=y +CONFIG_BT_MESH_BLOB_CLI=y +CONFIG_BT_MESH_BLOB_IO_FLASH=y + +CONFIG_ZTEST_NEW_API=y diff --git a/tests/bluetooth/mesh/blob_io_flash/src/main.c b/tests/bluetooth/mesh/blob_io_flash/src/main.c new file mode 100644 index 000000000000..62ea471f4f17 --- /dev/null +++ b/tests/bluetooth/mesh/blob_io_flash/src/main.c @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include "mesh/blob.h" + +#define SLOT1_PARTITION slot1_partition +#define SLOT1_PARTITION_ID FIXED_PARTITION_ID(SLOT1_PARTITION) +#define SLOT1_PARTITION_SIZE FIXED_PARTITION_SIZE(SLOT1_PARTITION) +/* Chunk size is set to value that is not multiple of 4, to verify that chunks are written correctly + * even if they are not aligned with word length used in flash + */ +#define CHUNK_SIZE 65 + +static struct bt_mesh_blob_io_flash blob_flash_stream; + +static size_t chunk_size(const struct bt_mesh_blob_block *block, + uint16_t chunk_idx) +{ + if ((chunk_idx == block->chunk_count - 1) && + (block->size % CHUNK_SIZE)) { + return block->size % CHUNK_SIZE; + } + + return CHUNK_SIZE; +} + +static uint8_t block_size_to_log(size_t size) +{ + uint8_t block_size_log = 0; + + while (size > 1) { + size = size / 2; + block_size_log++; + } + + return block_size_log; +} + +ZTEST_SUITE(blob_io_flash, NULL, NULL, NULL, NULL, NULL); + +ZTEST(blob_io_flash, test_chunk_read) +{ + const struct flash_area *fa = NULL; + struct bt_mesh_blob_xfer xfer; + struct bt_mesh_blob_block block = { 0 }; + struct bt_mesh_blob_chunk chunk = { 0 }; + size_t remaining = SLOT1_PARTITION_SIZE; + off_t block_idx = 0; + uint16_t chunk_idx = 0; + uint8_t chunk_data[CHUNK_SIZE]; + uint8_t test_data[SLOT1_PARTITION_SIZE]; + uint8_t ctrl_data[SLOT1_PARTITION_SIZE]; + size_t tests_data_offset = 0; + int i, err; + + /* Fill test data with pattern */ + for (i = 0; i < SLOT1_PARTITION_SIZE; i++) { + test_data[i] = i % 0xFF; + } + + err = flash_area_open(SLOT1_PARTITION_ID, &fa); + zassert_equal(err, 0, "Preparing test data failed with err=%d", err); + + err = flash_area_erase(fa, 0, ARRAY_SIZE(ctrl_data)); + zassert_equal(err, 0, "Preparing test data failed with err=%d", err); + + err = flash_area_write(fa, 0, test_data, ARRAY_SIZE(ctrl_data)); + zassert_equal(err, 0, "Preparing test data failed with err=%d", err); + + err = flash_area_read(fa, 0, ctrl_data, ARRAY_SIZE(ctrl_data)); + zassert_equal(err, 0, "Preparing test data failed with err=%d", err); + + zassert_mem_equal(ctrl_data, test_data, ARRAY_SIZE(ctrl_data), + "Incorrect data written into flash"); + + memset(ctrl_data, 0, SLOT1_PARTITION_SIZE); + + flash_area_close(fa); + + err = bt_mesh_blob_io_flash_init(&blob_flash_stream, + SLOT1_PARTITION_ID, 0); + zassert_equal(err, 0, "BLOB I/O init failed with err=%d", err); + + err = blob_flash_stream.io.open(&blob_flash_stream.io, &xfer, BT_MESH_BLOB_READ); + zassert_equal(err, 0, "BLOB I/O open failed with err=%d", err); + + chunk.data = chunk_data; + + /* Simulate reading whole partition divided into blocks and chunk of maximum sizes */ + while (remaining > 0) { + block.chunk_count = + ceiling_fraction(CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MAX, + CHUNK_SIZE); + block.size = remaining > CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MAX + ? CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MAX + : remaining; + + /* BLOB Client should do nothing to flash area as it's in read mode */ + err = blob_flash_stream.io.block_start(&blob_flash_stream.io, &xfer, &block); + zassert_equal(err, 0, "BLOB I/O open failed with err=%d", err); + + /* `block_start` in write mode will erase flash pages that can fit block. + * Assert that at least block size of data was not erased in read mode + */ + flash_area_read(blob_flash_stream.area, block.offset, ctrl_data, block.size); + zassert_mem_equal(ctrl_data, &test_data[block.offset], block.size, + "Flash data was altered by `block_start` in read mode"); + + memset(ctrl_data, 0, SLOT1_PARTITION_SIZE); + + block.offset = block_idx * (1 << block_size_to_log(block.size)); + + for (i = 0; i < block.chunk_count; i++) { + chunk.size = chunk_size(&block, chunk_idx); + chunk.offset = CHUNK_SIZE * chunk_idx; + + err = blob_flash_stream.io.rd(&blob_flash_stream.io, &xfer, &block, &chunk); + zassert_equal(err, 0, "BLOB I/O read failed with err=%d off=%d len=%d", + err, block.offset + chunk.offset, chunk.size); + + zassert_mem_equal(&chunk_data, &test_data[tests_data_offset], chunk.size, + "Incorrect data written into flash"); + chunk_idx++; + + remaining -= chunk.size; + tests_data_offset += chunk.size; + } + block_idx++; + chunk_idx = 0; + } + + /* We read whole sector as BLOB. Try to increment every offset by one and read, + * which should attempt to read outside flash area + */ + chunk.offset++; + err = blob_flash_stream.io.rd(&blob_flash_stream.io, &xfer, &block, &chunk); + zassert_false(err == 0, "Read outside flash area successful"); + + chunk.offset--; + block.offset++; + err = blob_flash_stream.io.rd(&blob_flash_stream.io, &xfer, &block, &chunk); + zassert_false(err == 0, "Read outside flash area successful"); + + block.offset--; + blob_flash_stream.offset++; + err = blob_flash_stream.io.rd(&blob_flash_stream.io, &xfer, &block, &chunk); + zassert_false(err == 0, "Read outside flash area successful"); + + blob_flash_stream.io.close(&blob_flash_stream.io, &xfer); +} + +ZTEST(blob_io_flash, test_chunk_write) +{ + struct bt_mesh_blob_xfer xfer; + struct bt_mesh_blob_block block = { 0 }; + struct bt_mesh_blob_chunk chunk = { 0 }; + size_t remaining = SLOT1_PARTITION_SIZE; + off_t block_idx = 0; + uint16_t chunk_idx = 0; + uint8_t chunk_data[CHUNK_SIZE]; + /* 3 is maximum length of padding at the end of written chunk */ + uint8_t chunk_ctrl_data[CHUNK_SIZE + 3]; + uint8_t end_padding_len; + uint8_t test_data[SLOT1_PARTITION_SIZE]; + uint8_t erased_block_data[CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MAX]; + uint8_t ctrl_data[SLOT1_PARTITION_SIZE]; + size_t tests_data_offset = 0; + int i, j, err; + + /* Fill test data with pattern */ + for (i = 0; i < SLOT1_PARTITION_SIZE; i++) { + test_data[i] = i % 0xFF; + } + + err = bt_mesh_blob_io_flash_init(&blob_flash_stream, + SLOT1_PARTITION_ID, 0); + zassert_equal(err, 0, "BLOB I/O init failed with err=%d", err); + + err = blob_flash_stream.io.open(&blob_flash_stream.io, &xfer, BT_MESH_BLOB_WRITE); + zassert_equal(err, 0, "BLOB I/O open failed with err=%d", err); + + chunk.data = chunk_data; + + memset(erased_block_data, flash_area_erased_val(blob_flash_stream.area), + CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MAX); + /* Simulate writing whole partition divided into blocks and chunk of maximum sizes */ + while (remaining > 0) { + block.chunk_count = + ceiling_fraction(CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MAX, + CHUNK_SIZE); + block.size = remaining > CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MAX + ? CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MAX + : remaining; + block.offset = block_idx * (1 << block_size_to_log(block.size)); + + err = blob_flash_stream.io.block_start(&blob_flash_stream.io, &xfer, &block); + zassert_equal(err, 0, "BLOB I/O open failed with err=%d", err); + + flash_area_read(blob_flash_stream.area, block.offset, + ctrl_data, block.size); + + zassert_mem_equal(ctrl_data, erased_block_data, block.size, + "Flash data was not erased by `block_start` in write mode"); + + memset(ctrl_data, 0, SLOT1_PARTITION_SIZE); + + for (i = 0; i < block.chunk_count; i++) { + chunk.size = chunk_size(&block, chunk_idx); + chunk.offset = CHUNK_SIZE * chunk_idx; + + memcpy(chunk.data, + &test_data[chunk.offset + block.offset], + chunk.size); + + err = blob_flash_stream.io.wr(&blob_flash_stream.io, &xfer, &block, &chunk); + zassert_equal(err, 0, "BLOB I/O write failed with err=%d", err); + + /* To calculate end padding length we must calculate size of whole buffer + * and subtract start offset length and chunk size + */ + end_padding_len = + ROUND_UP((block.offset + chunk.offset) % + flash_area_align(blob_flash_stream.area) + + chunk.size, flash_area_align(blob_flash_stream.area)) - + (block.offset + chunk.offset) % + flash_area_align(blob_flash_stream.area) - chunk.size; + + flash_area_read(blob_flash_stream.area, block.offset + chunk.offset, + chunk_ctrl_data, chunk.size + end_padding_len); + + zassert_mem_equal(chunk_ctrl_data, chunk_data, chunk.size, + "Incorrect data written into flash"); + + /* Assert that nothing was written into end padding */ + for (j = 1; j <= end_padding_len; j++) { + zassert_equal(chunk_ctrl_data[chunk.size + j], + flash_area_erased_val(blob_flash_stream.area)); + } + chunk_idx++; + + remaining -= chunk.size; + tests_data_offset += chunk.size; + } + + block_idx++; + chunk_idx = 0; + } + + flash_area_read(blob_flash_stream.area, 0, ctrl_data, SLOT1_PARTITION_SIZE); + zassert_mem_equal(ctrl_data, test_data, SLOT1_PARTITION_SIZE, + "Incorrect chunks written into flash"); + + /* We wrote whole sector as BLOB. Try to increment every offset by one and write, + * which should attempt to write outside flash area + */ + chunk.offset++; + err = blob_flash_stream.io.wr(&blob_flash_stream.io, &xfer, &block, &chunk); + zassert_false(err == 0, "Write outside flash area successful"); + + chunk.offset--; + block.offset++; + err = blob_flash_stream.io.wr(&blob_flash_stream.io, &xfer, &block, &chunk); + zassert_false(err == 0, "Write outside flash area successful"); + + block.offset--; + blob_flash_stream.offset++; + err = blob_flash_stream.io.wr(&blob_flash_stream.io, &xfer, &block, &chunk); + zassert_false(err == 0, "Write outside flash area successful"); + + blob_flash_stream.io.close(&blob_flash_stream.io, &xfer); +} diff --git a/tests/bluetooth/mesh/blob_io_flash/testcase.yaml b/tests/bluetooth/mesh/blob_io_flash/testcase.yaml new file mode 100644 index 000000000000..2b1c724902e7 --- /dev/null +++ b/tests/bluetooth/mesh/blob_io_flash/testcase.yaml @@ -0,0 +1,6 @@ +tests: + bluetooth.mesh.blob_io_flash: + platform_allow: native_posix + tags: bluetooth mesh + integration_platforms: + - native_posix From fbe80f98e4d653bb8f2d8d0cf4128a64296c6cea Mon Sep 17 00:00:00 2001 From: Andries Kruithof Date: Thu, 23 Mar 2023 14:11:56 +0100 Subject: [PATCH 0820/1906] MAINTAINERS: add Bluetooth host section Added a Bluetooth host section, similar to what has been done for controller and mesh Signed-off-by: Andries Kruithof --- MAINTAINERS.yml | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index 79e7e0c72c12..74a096459f08 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -184,13 +184,10 @@ Bluetooth: - jhedberg collaborators: - hermabe - - jori-nordic - - alwa-nordic - Vudentz - Thalley - asbjornsabo - sjanc - - theob-pro files: - doc/connectivity/bluetooth/ - drivers/bluetooth/ @@ -199,7 +196,6 @@ Bluetooth: - samples/bluetooth/ - subsys/bluetooth/ - subsys/bluetooth/common/ - - subsys/bluetooth/host/ - subsys/bluetooth/services/ - subsys/bluetooth/shell/ - tests/bluetooth/ @@ -207,13 +203,16 @@ Bluetooth: files-exclude: - include/zephyr/bluetooth/mesh/ - subsys/bluetooth/controller/ + - subsys/bluetooth/host/ - subsys/bluetooth/mesh/ - samples/bluetooth/mesh/ - subsys/bluetooth/audio/ - include/zephyr/bluetooth/audio/ - tests/bsim/bluetooth/audio/ + - tests/bsim/bluetooth/host/ - tests/bsim/bluetooth/ll/ - tests/bluetooth/controller/ + - tests/bluetooth/host*/ - tests/bluetooth/mesh_*/ - tests/bluetooth/mesh/ - tests/bsim/bluetooth/mesh/ @@ -241,6 +240,28 @@ Bluetooth controller: - "area: Bluetooth Controller" - "area: Bluetooth" +Bluetooth host: + status: maintained + maintainers: + - jhedberg + collaborators: + - hermabe + - jori-nordic + - alwa-nordic + - Vudentz + - Thalley + - asbjornsabo + - sjanc + - theob-pro + - kruithofa + files: + - subsys/bluetooth/host/ + - tests/bluetooth/host*/ + - tests/bsim/bluetooth/host/ + labels: + - "area: Bluetooth host" + - "area: Bluetooth" + Bluetooth Mesh: status: maintained maintainers: From 31aa555890ad9377e5dfa0d606bf66d93513681c Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 22 Mar 2023 14:43:37 +0100 Subject: [PATCH 0821/1906] Bluetooth: audio: ascs: Cleanup ASCS on callback unregister This adds cleanup of ASCS that is called when upper layer unregisters it's callbacks. Without callbacks registered, the service is unusable. The ASE's that were in non-idle state stay in this state, because the implementation returns an error on every operation that is performed by the client. The cleanup added moves all the ASE's to idle state. Fixes: #56111 Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 35 ++++++++--- subsys/bluetooth/audio/ascs_internal.h | 3 + subsys/bluetooth/audio/bap_unicast_server.c | 4 +- subsys/bluetooth/audio/bap_unicast_server.h | 2 - tests/bluetooth/audio/ascs/src/main.c | 61 +++++++++++++++++-- .../audio/mocks/include/ascs_help_utils.h | 8 --- 6 files changed, 88 insertions(+), 25 deletions(-) delete mode 100644 tests/bluetooth/audio/mocks/include/ascs_help_utils.h diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index ecbd0a2fc6ca..05f3ce286aa4 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -71,6 +71,7 @@ K_MEM_SLAB_DEFINE(ase_slab, sizeof(struct bt_ascs_ase), static struct bt_ascs sessions[CONFIG_BT_MAX_CONN]; NET_BUF_SIMPLE_DEFINE_STATIC(ase_buf, CONFIG_BT_L2CAP_TX_MTU); static struct bt_bap_stream *enabling[CONFIG_BT_ISO_MAX_CHAN]; +static const struct bt_bap_unicast_server_cb *unicast_server_cb; static int control_point_notify(struct bt_conn *conn, const void *data, uint16_t len); static int ascs_ep_get_status(struct bt_bap_ep *ep, struct net_buf_simple *buf); @@ -80,6 +81,11 @@ static bool is_valid_ase_id(uint8_t ase_id) return IN_RANGE(ase_id, 1, ASE_COUNT); } +static enum bt_bap_ep_state ascs_ep_get_state(struct bt_bap_ep *ep) +{ + return ep->status.state; +} + static void bt_ascs_ase_return_to_slab(struct bt_ascs_ase *ase) { __ASSERT(ase && ase->ascs, "Non-existing ASE or ASCS"); @@ -2723,21 +2729,33 @@ static int control_point_notify(struct bt_conn *conn, const void *data, uint16_t return bt_gatt_notify_uuid(conn, BT_UUID_ASCS_ASE_CP, ascs_svc.attrs, data, len); } -#if defined(ZTEST_UNITTEST) +void bt_ascs_init(const struct bt_bap_unicast_server_cb *cb) +{ + unicast_server_cb = cb; +} + static void ase_cleanup(struct bt_ascs_ase *ase) { - if (ase->ep.iso != NULL) { - bt_bap_iso_unbind_ep(ase->ep.iso, &ase->ep); + struct bt_bap_ascs_rsp rsp; + struct bt_bap_stream *stream; + enum bt_bap_ep_state state; + + state = ascs_ep_get_state(&ase->ep); + if (state == BT_BAP_EP_STATE_IDLE || state == BT_BAP_EP_STATE_RELEASING) { + return; } - if (ase->ep.stream != NULL) { - bt_bap_stream_detach(ase->ep.stream); + stream = ase->ep.stream; + __ASSERT(stream != NULL, "ep.stream is NULL"); + + if (unicast_server_cb != NULL && unicast_server_cb->release != NULL) { + unicast_server_cb->release(stream, &rsp); } - bt_ascs_ase_return_to_slab(ase); + ascs_ep_set_state(&ase->ep, BT_BAP_EP_STATE_RELEASING); } -void ascs_cleanup(void) +void bt_ascs_cleanup(void) { for (size_t i = 0; i < ARRAY_SIZE(sessions); i++) { struct bt_ascs *session = &sessions[i]; @@ -2758,6 +2776,7 @@ void ascs_cleanup(void) bt_conn_unref(session->conn); session->conn = NULL; } + + unicast_server_cb = NULL; } -#endif /* ZTEST_UNITTEST */ #endif /* BT_BAP_UNICAST_SERVER */ diff --git a/subsys/bluetooth/audio/ascs_internal.h b/subsys/bluetooth/audio/ascs_internal.h index 4cf0f012db71..72835cdd19fe 100644 --- a/subsys/bluetooth/audio/ascs_internal.h +++ b/subsys/bluetooth/audio/ascs_internal.h @@ -331,6 +331,9 @@ static inline const char *bt_ascs_reason_str(uint8_t reason) return "Unknown"; } +void bt_ascs_init(const struct bt_bap_unicast_server_cb *cb); +void bt_ascs_cleanup(void); + void ascs_ep_set_state(struct bt_bap_ep *ep, uint8_t state); int bt_ascs_config_ase(struct bt_conn *conn, struct bt_bap_stream *stream, struct bt_codec *codec, diff --git a/subsys/bluetooth/audio/bap_unicast_server.c b/subsys/bluetooth/audio/bap_unicast_server.c index 0fe6449185bc..bb7145c8c446 100644 --- a/subsys/bluetooth/audio/bap_unicast_server.c +++ b/subsys/bluetooth/audio/bap_unicast_server.c @@ -19,7 +19,7 @@ LOG_MODULE_REGISTER(bt_bap_unicast_server, CONFIG_BT_BAP_UNICAST_SERVER_LOG_LEVEL); -const struct bt_bap_unicast_server_cb *unicast_server_cb; +static const struct bt_bap_unicast_server_cb *unicast_server_cb; int bt_bap_unicast_server_register_cb(const struct bt_bap_unicast_server_cb *cb) { @@ -34,6 +34,7 @@ int bt_bap_unicast_server_register_cb(const struct bt_bap_unicast_server_cb *cb) } unicast_server_cb = cb; + bt_ascs_init(unicast_server_cb); return 0; } @@ -50,6 +51,7 @@ int bt_bap_unicast_server_unregister_cb(const struct bt_bap_unicast_server_cb *c return -EINVAL; } + bt_ascs_cleanup(); unicast_server_cb = NULL; return 0; diff --git a/subsys/bluetooth/audio/bap_unicast_server.h b/subsys/bluetooth/audio/bap_unicast_server.h index adb7d1c48c6e..26198bcf4721 100644 --- a/subsys/bluetooth/audio/bap_unicast_server.h +++ b/subsys/bluetooth/audio/bap_unicast_server.h @@ -9,8 +9,6 @@ #include #include -extern const struct bt_bap_unicast_server_cb *unicast_server_cb; - int bt_bap_unicast_server_reconfig(struct bt_bap_stream *stream, const struct bt_codec *codec); int bt_bap_unicast_server_start(struct bt_bap_stream *stream); int bt_bap_unicast_server_metadata(struct bt_bap_stream *stream, struct bt_codec_data meta[], diff --git a/tests/bluetooth/audio/ascs/src/main.c b/tests/bluetooth/audio/ascs/src/main.c index fa2724139256..1333a1fe5133 100644 --- a/tests/bluetooth/audio/ascs/src/main.c +++ b/tests/bluetooth/audio/ascs/src/main.c @@ -19,7 +19,7 @@ #include #include "assert.h" -#include "ascs_help_utils.h" +#include "ascs_internal.h" #include "bap_unicast_server.h" #include "bap_unicast_server_expects.h" #include "bap_stream.h" @@ -168,8 +168,6 @@ static void *ascs_ase_control_test_suite_setup(void) fixture->ase_cp = ascs_get_attr(BT_UUID_ASCS_ASE_CP, 1); fixture->ase_snk = ascs_get_attr(BT_UUID_ASCS_ASE_SNK, 1); - bt_bap_unicast_server_register_cb(&mock_bap_unicast_server_cb); - return fixture; } @@ -180,19 +178,19 @@ static void ascs_ase_control_test_suite_before(void *f) ARG_UNUSED(fixture); bt_pacs_cap_foreach_fake.custom_fake = pacs_cap_foreach_custom_fake; + + bt_bap_unicast_server_register_cb(&mock_bap_unicast_server_cb); } static void ascs_ase_control_test_suite_after(void *f) { - ascs_cleanup(); + bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb); } static void ascs_ase_control_test_suite_teardown(void *f) { struct ascs_ase_control_test_suite_fixture *fixture = f; - bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb); - free(fixture); } @@ -738,3 +736,54 @@ ZTEST_F(ascs_ase_control_test_suite, test_sink_ase_control_release_from_qos_conf expect_bt_bap_unicast_server_cb_release_called_once(&fixture->stream); expect_bt_bap_stream_ops_released_called_once(&fixture->stream); } + +static void ascs_test_suite_after(void *f) +{ + bt_ascs_cleanup(); +} + +ZTEST_SUITE(ascs_test_suite, NULL, NULL, NULL, ascs_test_suite_after, NULL); + +ZTEST(ascs_test_suite, test_release_ase_on_callback_unregister) +{ + const struct bt_uuid *ase_uuid = COND_CODE_1(CONFIG_BT_ASCS_ASE_SNK, + (BT_UUID_ASCS_ASE_SNK), + (BT_UUID_ASCS_ASE_SRC)); + const struct bt_gatt_attr *ase_cp; + const struct bt_gatt_attr *ase; + struct bt_bap_stream stream; + struct bt_conn conn; + const uint8_t expect_ase_state_idle[] = { + 0x01, /* ASE_ID */ + 0x00, /* ASE_State = Idle */ + }; + + ase_cp = ascs_get_attr(BT_UUID_ASCS_ASE_CP, 1); + zassert_not_null(ase_cp); + + ase = ascs_get_attr(ase_uuid, 1); + zassert_not_null(ase); + + conn_init(&conn); + + bt_pacs_cap_foreach_fake.custom_fake = pacs_cap_foreach_custom_fake; + + bt_bap_unicast_server_register_cb(&mock_bap_unicast_server_cb); + + /* Set ASE to non-idle state */ + ase_cp_write_codec_config(ase_cp, &conn, &stream); + + /* Reset mock, as we expect ASE notification to be sent */ + bt_gatt_notify_cb_reset(); + + /* Unregister the callbacks - whis will clean up the ASCS */ + bt_bap_unicast_server_unregister_cb(&mock_bap_unicast_server_cb); + + /* Expected to notify the upper layers */ + expect_bt_bap_unicast_server_cb_release_called_once(&stream); + expect_bt_bap_stream_ops_released_called_once(&stream); + + /* Expected to notify the client */ + expect_bt_gatt_notify_cb_called_once(&conn, ase_uuid, ase, expect_ase_state_idle, + sizeof(expect_ase_state_idle)); +} diff --git a/tests/bluetooth/audio/mocks/include/ascs_help_utils.h b/tests/bluetooth/audio/mocks/include/ascs_help_utils.h deleted file mode 100644 index 5c7dcd9a9e8f..000000000000 --- a/tests/bluetooth/audio/mocks/include/ascs_help_utils.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) 2023 Codecoup - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* ascs.c declarations */ -void ascs_cleanup(void); From ee754fd02075d8c6adffd993181ae563ed6113f6 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Thu, 23 Mar 2023 09:57:22 +0100 Subject: [PATCH 0822/1906] Bluetooth: audio: ascs: Remove redundant check The ID is ensured to be valid before ase_new() function is called, as the client request is already validated. On the other hand, if function is called from server initiated procedure context, the assert shall occur as it indicates stack issue. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 05f3ce286aa4..c1797038d6f5 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -1166,9 +1166,7 @@ static struct bt_ascs_ase *ase_new(struct bt_ascs *ascs, uint8_t id) { struct bt_ascs_ase *ase; - if (!id || id > ASE_COUNT) { - return NULL; - } + __ASSERT(id > 0 && id <= ASE_COUNT, "invalid ASE_ID 0x%02x", id); ase = bt_ascs_ase_get_from_slab(); if (!ase) { From 5909a00a0019c3c709fd26db2e9541e8bc7fae89 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Thu, 23 Mar 2023 10:10:51 +0100 Subject: [PATCH 0823/1906] Bluetooth: audio: ascs: Minor refactor of ASE allocation This removes redundant bt_ascs_ase_get_from_slab function and moves it's functionality to ase_new(). It's sane, because the ASE shall be allocated from ase_new() function context only. bt_ascs_ase_return_to_slab() has been renamed to ase_free() to follow the naming convention. Furthermore, few logs have been fixed/added. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index c1797038d6f5..8a981fd684bf 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -86,27 +86,16 @@ static enum bt_bap_ep_state ascs_ep_get_state(struct bt_bap_ep *ep) return ep->status.state; } -static void bt_ascs_ase_return_to_slab(struct bt_ascs_ase *ase) +static void ase_free(struct bt_ascs_ase *ase) { __ASSERT(ase && ase->ascs, "Non-existing ASE or ASCS"); - LOG_DBG("Returning ase %p to slab", ase); + LOG_DBG("ascs %p ase %p id 0x%02x", ase->ascs, ase, ase->ep.status.id); sys_slist_find_and_remove(&ase->ascs->ases, &ase->node); k_mem_slab_free(&ase_slab, (void **)&ase); } -static struct bt_ascs_ase *bt_ascs_ase_get_from_slab(void) -{ - struct bt_ascs_ase *ase = NULL; - - if (k_mem_slab_alloc(&ase_slab, (void **)&ase, K_NO_WAIT) < 0) { - LOG_DBG("Could not get ASE from slab, out of memory"); - } - - return ase; -} - static void ase_status_changed(struct bt_bap_ep *ep, uint8_t old_state, uint8_t state) { struct bt_ascs_ase *ase = CONTAINER_OF(ep, struct bt_ascs_ase, ep); @@ -242,8 +231,7 @@ void ascs_ep_set_state(struct bt_bap_ep *ep, uint8_t state) } struct bt_ascs_ase *ase = CONTAINER_OF(ep, struct bt_ascs_ase, ep); - /* Return the ase to slab */ - bt_ascs_ase_return_to_slab(ase); + ase_free(ase); break; case BT_BAP_EP_STATE_CODEC_CONFIGURED: @@ -1168,8 +1156,8 @@ static struct bt_ascs_ase *ase_new(struct bt_ascs *ascs, uint8_t id) __ASSERT(id > 0 && id <= ASE_COUNT, "invalid ASE_ID 0x%02x", id); - ase = bt_ascs_ase_get_from_slab(); - if (!ase) { + if (k_mem_slab_alloc(&ase_slab, (void **)&ase, K_NO_WAIT) < 0) { + LOG_ERR("No available ase for ascs %p", ascs); return NULL; } @@ -1177,6 +1165,8 @@ static struct bt_ascs_ase *ase_new(struct bt_ascs *ascs, uint8_t id) ase->ascs = ascs; sys_slist_append(&ascs->ases, &ase->node); + LOG_DBG("ascs %p new ase %p id 0x%02x", ascs, ase, id); + return ase; } From e9a878c0723653015571fe429dd7cba0543f24b7 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Thu, 23 Mar 2023 11:00:13 +0100 Subject: [PATCH 0824/1906] Bluetooth: audio: ascs: Fix ASE leak if codec config failed This fixes ASE that is not returned to pool when Codec Config operation failed. The ASE is allocated in Codec Config operation context. With this fix, if the operation failed to complete, the ASE is returned back to the pool, so that it can be allocated again by this or other client. Fixes: #56138 Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 46 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 8a981fd684bf..ba2fbc54c9a7 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -1185,18 +1185,6 @@ static struct bt_ascs_ase *ase_find(struct bt_ascs *ascs, uint8_t id) return NULL; } -static struct bt_ascs_ase *ase_get(struct bt_ascs *ascs, uint8_t id) -{ - struct bt_ascs_ase *ase; - - ase = ase_find(ascs, id); - if (ase) { - return ase; - } - - return ase_new(ascs, id); -} - static ssize_t ascs_ase_read(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) @@ -1358,9 +1346,8 @@ static int ascs_ep_set_codec(struct bt_bap_ep *ep, uint8_t id, uint16_t cid, uin return 0; } -static void ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, - const struct bt_ascs_config *cfg, - struct net_buf_simple *buf) +static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, + const struct bt_ascs_config *cfg, struct net_buf_simple *buf) { struct bt_bap_stream *stream; struct bt_codec codec; @@ -1379,7 +1366,7 @@ static void ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_CONF_INVALID, BT_BAP_ASCS_REASON_LATENCY); - return; + return -EINVAL; } if (cfg->phy < BT_ASCS_CONFIG_PHY_LE_1M || @@ -1387,7 +1374,7 @@ static void ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, LOG_WRN("Invalid PHY: 0x%02x", cfg->phy); ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_CONF_INVALID, BT_BAP_ASCS_REASON_PHY); - return; + return -EINVAL; } switch (ase->ep.status.state) { @@ -1403,7 +1390,7 @@ static void ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, bt_bap_ep_state_str(ase->ep.status.state)); ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE, 0x00); - return; + return -EINVAL; } /* Store current codec configuration to be able to restore it @@ -1418,7 +1405,7 @@ static void ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, if (err) { (void)memcpy(&ase->ep.codec, &codec, sizeof(codec)); ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, rsp.code, rsp.reason); - return; + return err; } if (ase->ep.stream != NULL) { @@ -1447,7 +1434,7 @@ static void ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, (void)memcpy(&ase->ep.codec, &codec, sizeof(codec)); ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, rsp.code, rsp.reason); - return; + return err; } stream = ase->ep.stream; @@ -1476,7 +1463,7 @@ static void ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, (void)memcpy(&ase->ep.codec, &codec, sizeof(codec)); ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, rsp.code, rsp.reason); - return; + return err ? err : -ENOMEM; } bt_bap_stream_init(stream); @@ -1487,6 +1474,8 @@ static void ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, bt_bap_stream_attach(ascs->conn, stream, &ase->ep, &ase->ep.codec); ascs_ep_set_state(&ase->ep, BT_BAP_EP_STATE_CODEC_CONFIGURED); + + return 0; } int bt_ascs_config_ase(struct bt_conn *conn, struct bt_bap_stream *stream, struct bt_codec *codec, @@ -1609,6 +1598,7 @@ static ssize_t ascs_config(struct bt_ascs *ascs, struct net_buf_simple *buf) for (uint8_t i = 0; i < req->num_ases; i++) { struct bt_ascs_ase *ase; + int err; cfg = net_buf_simple_pull_mem(buf, sizeof(*cfg)); @@ -1619,10 +1609,15 @@ static ssize_t ascs_config(struct bt_ascs *ascs, struct net_buf_simple *buf) ascs_cp_rsp_add(cfg->ase, BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_INVALID_ASE, 0x00); continue; - } else { - ase = ase_get(ascs, cfg->ase); } + ase = ase_find(ascs, cfg->ase); + if (ase != NULL) { + ase_config(ascs, ase, cfg, buf); + continue; + } + + ase = ase_new(ascs, cfg->ase); if (!ase) { ascs_cp_rsp_add(cfg->ase, BT_ASCS_CONFIG_OP, BT_BAP_ASCS_RSP_CODE_NO_MEM, 0x00); @@ -1630,7 +1625,10 @@ static ssize_t ascs_config(struct bt_ascs *ascs, struct net_buf_simple *buf) continue; } - ase_config(ascs, ase, cfg, buf); + err = ase_config(ascs, ase, cfg, buf); + if (err != 0) { + ase_free(ase); + } } return buf->size; From f5b31c21a9a1af736de03c1e74bea131a25f4947 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Thu, 23 Mar 2023 12:17:36 +0100 Subject: [PATCH 0825/1906] Bluetooth: audio: ascs: Fix Response_Code for mandatory opcodes This fixes invalid Unsupported Opcode Response_Code that happened to be sent in ASE Control Point notification as the response to operation initiated with Mandatory opcode to support. When the Unicast Server callbacks are not registered, every operation that is initiated by client will fail with Unspecified Error instead. Fixes: #56139 Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 16 +++++++-------- tests/bluetooth/audio/ascs/src/main.c | 29 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index ba2fbc54c9a7..b33c2e31a0d8 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -919,7 +919,7 @@ static void ase_release(struct bt_ascs_ase *ase) err = unicast_server_cb->release(ase->ep.stream, &rsp); } else { err = -ENOTSUP; - rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, BT_BAP_ASCS_REASON_NONE); } @@ -971,7 +971,7 @@ static void ase_disable(struct bt_ascs_ase *ase) err = unicast_server_cb->disable(stream, &rsp); } else { err = -ENOTSUP; - rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, BT_BAP_ASCS_REASON_NONE); } @@ -1418,7 +1418,7 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, &rsp); } else { err = -ENOTSUP; - rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, BT_BAP_ASCS_REASON_NONE); } @@ -1447,7 +1447,7 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase, &ase->ep.qos_pref, &rsp); } else { err = -ENOTSUP; - rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, BT_BAP_ASCS_REASON_NONE); } @@ -2076,7 +2076,7 @@ static void ase_metadata(struct bt_ascs_ase *ase, uint8_t op, ep->codec.meta_count, &rsp); } else { err = -ENOTSUP; - rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, BT_BAP_ASCS_REASON_NONE); } @@ -2134,7 +2134,7 @@ static int ase_enable(struct bt_ascs_ase *ase, struct bt_ascs_metadata *meta, ep->codec.meta_count, &rsp); } else { err = -ENOTSUP; - rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, BT_BAP_ASCS_REASON_NONE); } @@ -2259,7 +2259,7 @@ static void ase_start(struct bt_ascs_ase *ase) err = unicast_server_cb->start(ep->stream, &rsp); } else { err = -ENOTSUP; - rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, BT_BAP_ASCS_REASON_NONE); } @@ -2419,7 +2419,7 @@ static void ase_stop(struct bt_ascs_ase *ase) err = unicast_server_cb->stop(stream, &rsp); } else { err = -ENOTSUP; - rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED, + rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_UNSPECIFIED, BT_BAP_ASCS_REASON_NONE); } diff --git a/tests/bluetooth/audio/ascs/src/main.c b/tests/bluetooth/audio/ascs/src/main.c index 1333a1fe5133..b7829f92e8e1 100644 --- a/tests/bluetooth/audio/ascs/src/main.c +++ b/tests/bluetooth/audio/ascs/src/main.c @@ -787,3 +787,32 @@ ZTEST(ascs_test_suite, test_release_ase_on_callback_unregister) expect_bt_gatt_notify_cb_called_once(&conn, ase_uuid, ase, expect_ase_state_idle, sizeof(expect_ase_state_idle)); } + +ZTEST(ascs_test_suite, test_abort_client_operation_if_callback_not_registered) +{ + const struct bt_gatt_attr *ase_cp; + struct bt_bap_stream stream; + struct bt_conn conn; + const uint8_t expect_ase_cp_unspecified_error[] = { + 0x01, /* Opcode */ + 0x01, /* Number_of_ASEs */ + 0x01, /* ASE_ID[0] */ + 0x0E, /* Response_Code[0] = Unspecified Error */ + 0x00, /* Reason[0] */ + }; + + ase_cp = ascs_get_attr(BT_UUID_ASCS_ASE_CP, 1); + zassert_not_null(ase_cp); + + conn_init(&conn); + + bt_pacs_cap_foreach_fake.custom_fake = pacs_cap_foreach_custom_fake; + + /* Set ASE to non-idle state */ + ase_cp_write_codec_config(ase_cp, &conn, &stream); + + /* Expected ASE Control Point notification with Unspecified Error was sent */ + expect_bt_gatt_notify_cb_called_once(&conn, BT_UUID_ASCS_ASE_CP, ase_cp, + expect_ase_cp_unspecified_error, + sizeof(expect_ase_cp_unspecified_error)); +} From 710103db1de0f19559e811b4a6ffd971c1d8da8a Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Thu, 23 Mar 2023 13:42:04 +0100 Subject: [PATCH 0826/1906] Bluetooth: iso: Add bt_iso_server_unregister function This adds function that unregisters previously registered ISO server. Signed-off-by: Mariusz Skamra --- include/zephyr/bluetooth/iso.h | 10 ++++++++++ subsys/bluetooth/host/iso.c | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/zephyr/bluetooth/iso.h b/include/zephyr/bluetooth/iso.h index 87c1eb15f7ee..c26652a029ac 100644 --- a/include/zephyr/bluetooth/iso.h +++ b/include/zephyr/bluetooth/iso.h @@ -567,6 +567,16 @@ struct bt_iso_server { */ int bt_iso_server_register(struct bt_iso_server *server); +/** @brief Unregister ISO server. + * + * Unregister previously registered ISO server. + * + * @param server Server structure. + * + * @return 0 in case of success or negative value in case of error. + */ +int bt_iso_server_unregister(struct bt_iso_server *server); + /** @brief Creates a CIG as a central * * This can called at any time, even before connecting to a remote device. diff --git a/subsys/bluetooth/host/iso.c b/subsys/bluetooth/host/iso.c index 12d25e26c733..480ffddce4dc 100644 --- a/subsys/bluetooth/host/iso.c +++ b/subsys/bluetooth/host/iso.c @@ -1094,6 +1094,22 @@ int bt_iso_server_register(struct bt_iso_server *server) return 0; } +int bt_iso_server_unregister(struct bt_iso_server *server) +{ + CHECKIF(!server) { + LOG_DBG("Invalid parameter: server %p", server); + return -EINVAL; + } + + if (iso_server != server) { + return -EINVAL; + } + + iso_server = NULL; + + return 0; +} + static int iso_accept(struct bt_conn *acl, struct bt_conn *iso) { struct bt_iso_accept_info accept_info; From 08aedc66ddae2906ff475b774cb57e3dd2f3f5fb Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Fri, 24 Mar 2023 07:32:44 +0100 Subject: [PATCH 0827/1906] Bluetooth: audio: ascs: Make use of SYS_SLIST_FOR_EACH_CONTAINER_* macros This cleans up the code a bit by replacing the occurences of SYS_SLIST_FOR_EACH_NODE with SYS_SLIST_FOR_EACH_CONTAINER(_SAFE) so that the explicit CONTAINER_OF() usage is not needed. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index b33c2e31a0d8..04c1afa7d4b6 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -1001,22 +1001,18 @@ static void ase_disable(struct bt_ascs_ase *ase) static void disconnected(struct bt_conn *conn, uint8_t reason) { struct bt_ascs *session = &sessions[bt_conn_index(conn)]; + struct bt_ascs_ase *ase, *tmp; if (session->conn == NULL) { return; } - sys_snode_t *ase_node, *s; - - SYS_SLIST_FOR_EACH_NODE_SAFE(&session->ases, ase_node, s) { - struct bt_bap_stream *stream; - struct bt_ascs_ase *ase; - - ase = CONTAINER_OF(ase_node, struct bt_ascs_ase, node); - stream = ase->ep.stream; + SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&session->ases, ase, tmp, node) { + struct bt_bap_stream *stream = ase->ep.stream; if (ase->ep.status.state != BT_BAP_EP_STATE_IDLE) { ase_release(ase); + /* At this point, `ase` object have been free'd */ if (stream != NULL) { const struct bt_bap_stream_ops *ops; @@ -1172,11 +1168,9 @@ static struct bt_ascs_ase *ase_new(struct bt_ascs *ascs, uint8_t id) static struct bt_ascs_ase *ase_find(struct bt_ascs *ascs, uint8_t id) { - sys_snode_t *ase_node; - - SYS_SLIST_FOR_EACH_NODE(&ascs->ases, ase_node) { - struct bt_ascs_ase *ase = CONTAINER_OF(ase_node, struct bt_ascs_ase, node); + struct bt_ascs_ase *ase; + SYS_SLIST_FOR_EACH_CONTAINER(&ascs->ases, ase, node) { if (ase->ep.status.id == id) { return ase; } @@ -1636,12 +1630,10 @@ static ssize_t ascs_config(struct bt_ascs *ascs, struct net_buf_simple *buf) void bt_ascs_foreach_ep(struct bt_conn *conn, bt_bap_ep_func_t func, void *user_data) { - sys_snode_t *ase_node; struct bt_ascs *ascs = ascs_get(conn); + struct bt_ascs_ase *ase, *tmp; - SYS_SLIST_FOR_EACH_NODE(&ascs->ases, ase_node) { - struct bt_ascs_ase *ase = CONTAINER_OF(ase_node, struct bt_ascs_ase, node); - + SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&ascs->ases, ase, tmp, node) { func(&ase->ep, user_data); } } @@ -2745,17 +2737,13 @@ void bt_ascs_cleanup(void) { for (size_t i = 0; i < ARRAY_SIZE(sessions); i++) { struct bt_ascs *session = &sessions[i]; - sys_snode_t *node, *tmp; + struct bt_ascs_ase *ase, *tmp; if (session->conn == NULL) { continue; } - SYS_SLIST_FOR_EACH_NODE_SAFE(&session->ases, node, tmp) { - struct bt_ascs_ase *ase; - - ase = CONTAINER_OF(node, struct bt_ascs_ase, node); - + SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&session->ases, ase, tmp, node) { ase_cleanup(ase); } From 58de595c7009ad0c6c66b933b85fcf68f729bb4c Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Thu, 23 Mar 2023 13:51:43 +0100 Subject: [PATCH 0828/1906] Bluetooth: audio: ascs: Register ISO server on ASCS init This moves the ISO server registration to bt_ascs_init. When the ASCS gets cleaned up (the callbacks are unregistered), the ISO server gets unregistered. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 46 +++++++++++---------- subsys/bluetooth/audio/ascs_internal.h | 2 +- subsys/bluetooth/audio/bap_unicast_server.c | 8 +++- tests/bluetooth/audio/mocks/include/iso.h | 2 + tests/bluetooth/audio/mocks/src/iso.c | 1 + 5 files changed, 36 insertions(+), 23 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 04c1afa7d4b6..7e453b9a5bc5 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -584,28 +584,10 @@ static int ascs_iso_accept(const struct bt_iso_accept_info *info, static int ascs_iso_listen(struct bt_bap_stream *stream) { struct bt_bap_stream **free_stream = NULL; - static struct bt_iso_server iso_server = { - .sec_level = BT_SECURITY_L2, - .accept = ascs_iso_accept, - }; - static bool server; - int err; - - LOG_DBG("stream %p conn %p", stream, (void *)stream->conn); - - if (server) { - goto done; - } - err = bt_iso_server_register(&iso_server); - if (err) { - LOG_ERR("bt_iso_server_register: %d", err); - return err; - } - server = true; + LOG_DBG("stream %p conn %p", stream, (void *)stream->conn); -done: for (size_t i = 0U; i < ARRAY_SIZE(enabling); i++) { if (enabling[i] == stream) { return 0; @@ -2707,9 +2689,28 @@ static int control_point_notify(struct bt_conn *conn, const void *data, uint16_t return bt_gatt_notify_uuid(conn, BT_UUID_ASCS_ASE_CP, ascs_svc.attrs, data, len); } -void bt_ascs_init(const struct bt_bap_unicast_server_cb *cb) +static struct bt_iso_server iso_server = { + .sec_level = BT_SECURITY_L2, + .accept = ascs_iso_accept, +}; + +int bt_ascs_init(const struct bt_bap_unicast_server_cb *cb) { + int err; + + if (unicast_server_cb != NULL) { + return -EALREADY; + } + + err = bt_iso_server_register(&iso_server); + if (err) { + LOG_ERR("Failed to register ISO server %d", err); + return err; + } + unicast_server_cb = cb; + + return 0; } static void ase_cleanup(struct bt_ascs_ase *ase) @@ -2751,6 +2752,9 @@ void bt_ascs_cleanup(void) session->conn = NULL; } - unicast_server_cb = NULL; + if (unicast_server_cb != NULL) { + bt_iso_server_unregister(&iso_server); + unicast_server_cb = NULL; + } } #endif /* BT_BAP_UNICAST_SERVER */ diff --git a/subsys/bluetooth/audio/ascs_internal.h b/subsys/bluetooth/audio/ascs_internal.h index 72835cdd19fe..32db474252a1 100644 --- a/subsys/bluetooth/audio/ascs_internal.h +++ b/subsys/bluetooth/audio/ascs_internal.h @@ -331,7 +331,7 @@ static inline const char *bt_ascs_reason_str(uint8_t reason) return "Unknown"; } -void bt_ascs_init(const struct bt_bap_unicast_server_cb *cb); +int bt_ascs_init(const struct bt_bap_unicast_server_cb *cb); void bt_ascs_cleanup(void); void ascs_ep_set_state(struct bt_bap_ep *ep, uint8_t state); diff --git a/subsys/bluetooth/audio/bap_unicast_server.c b/subsys/bluetooth/audio/bap_unicast_server.c index bb7145c8c446..9c66a6fdc3ff 100644 --- a/subsys/bluetooth/audio/bap_unicast_server.c +++ b/subsys/bluetooth/audio/bap_unicast_server.c @@ -23,6 +23,8 @@ static const struct bt_bap_unicast_server_cb *unicast_server_cb; int bt_bap_unicast_server_register_cb(const struct bt_bap_unicast_server_cb *cb) { + int err; + CHECKIF(cb == NULL) { LOG_DBG("cb is NULL"); return -EINVAL; @@ -33,8 +35,12 @@ int bt_bap_unicast_server_register_cb(const struct bt_bap_unicast_server_cb *cb) return -EALREADY; } + err = bt_ascs_init(cb); + if (err != 0) { + return err; + } + unicast_server_cb = cb; - bt_ascs_init(unicast_server_cb); return 0; } diff --git a/tests/bluetooth/audio/mocks/include/iso.h b/tests/bluetooth/audio/mocks/include/iso.h index aa1a9f0446a4..913e5a15ab31 100644 --- a/tests/bluetooth/audio/mocks/include/iso.h +++ b/tests/bluetooth/audio/mocks/include/iso.h @@ -14,11 +14,13 @@ #define ISO_FFF_FAKES_LIST(FAKE) \ FAKE(bt_iso_chan_send) \ FAKE(bt_iso_server_register) \ + FAKE(bt_iso_server_unregister) \ FAKE(bt_iso_chan_disconnect) \ DECLARE_FAKE_VALUE_FUNC(int, bt_iso_chan_send, struct bt_iso_chan *, struct net_buf *, uint16_t, uint32_t); DECLARE_FAKE_VALUE_FUNC(int, bt_iso_server_register, struct bt_iso_server *); +DECLARE_FAKE_VALUE_FUNC(int, bt_iso_server_unregister, struct bt_iso_server *); DECLARE_FAKE_VALUE_FUNC(int, bt_iso_chan_disconnect, struct bt_iso_chan *); #endif /* MOCKS_ISO_H_ */ diff --git a/tests/bluetooth/audio/mocks/src/iso.c b/tests/bluetooth/audio/mocks/src/iso.c index 8dc88bca5eb7..c9f74910167a 100644 --- a/tests/bluetooth/audio/mocks/src/iso.c +++ b/tests/bluetooth/audio/mocks/src/iso.c @@ -11,4 +11,5 @@ DEFINE_FAKE_VALUE_FUNC(int, bt_iso_chan_send, struct bt_iso_chan *, struct net_buf *, uint16_t, uint32_t); DEFINE_FAKE_VALUE_FUNC(int, bt_iso_server_register, struct bt_iso_server *); +DEFINE_FAKE_VALUE_FUNC(int, bt_iso_server_unregister, struct bt_iso_server *); DEFINE_FAKE_VALUE_FUNC(int, bt_iso_chan_disconnect, struct bt_iso_chan *); From 43d8e92bdd4df65b114d24c8bad522ffdaa495a4 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Thu, 23 Mar 2023 14:24:27 +0100 Subject: [PATCH 0829/1906] Bluetooth: audio: ascs: Fix ISO server listen incorrect behavior This fixes incorrect behavior of ISO server listen that was not handling the case of two endpoints sharing the same CIS/CIG and the endpoints belonging to different connections. Fixes: #51552 Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 116 ++++++++++++---------------------- 1 file changed, 41 insertions(+), 75 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 7e453b9a5bc5..d09727975241 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -70,12 +70,30 @@ K_MEM_SLAB_DEFINE(ase_slab, sizeof(struct bt_ascs_ase), static struct bt_ascs sessions[CONFIG_BT_MAX_CONN]; NET_BUF_SIMPLE_DEFINE_STATIC(ase_buf, CONFIG_BT_L2CAP_TX_MTU); -static struct bt_bap_stream *enabling[CONFIG_BT_ISO_MAX_CHAN]; static const struct bt_bap_unicast_server_cb *unicast_server_cb; static int control_point_notify(struct bt_conn *conn, const void *data, uint16_t len); static int ascs_ep_get_status(struct bt_bap_ep *ep, struct net_buf_simple *buf); +static void ascs_init(struct bt_ascs *ascs, struct bt_conn *conn) +{ + memset(ascs, 0, sizeof(*ascs)); + + ascs->conn = bt_conn_ref(conn); + sys_slist_init(&ascs->ases); +} + +static struct bt_ascs *ascs_get(struct bt_conn *conn) +{ + struct bt_ascs *session = &sessions[bt_conn_index(conn)]; + + if (session->conn == NULL) { + ascs_init(session, conn); + } + + return session; +} + static bool is_valid_ase_id(uint8_t ase_id) { return IN_RANGE(ase_id, 1, ASE_COUNT); @@ -179,14 +197,6 @@ static int ascs_disconnect_stream(struct bt_bap_stream *stream) LOG_DBG("%p", stream); - /* Stop listening */ - for (size_t i = 0; i < ARRAY_SIZE(enabling); i++) { - if (enabling[i] == stream) { - enabling[i] = NULL; - break; - } - } - return k_work_reschedule(&ase->disconnect_work, K_MSEC(CONFIG_BT_ASCS_ISO_DISCONNECT_DELAY)); } @@ -558,55 +568,43 @@ static int ascs_ep_get_status(struct bt_bap_ep *ep, struct net_buf_simple *buf) return 0; } -static int ascs_iso_accept(const struct bt_iso_accept_info *info, - struct bt_iso_chan **iso_chan) +static int ascs_iso_accept(const struct bt_iso_accept_info *info, struct bt_iso_chan **iso_chan) { - LOG_DBG("acl %p", (void *)info->acl); - - for (size_t i = 0U; i < ARRAY_SIZE(enabling); i++) { - struct bt_bap_stream *c = enabling[i]; + struct bt_ascs *ascs = ascs_get(info->acl); + struct bt_ascs_ase *ase; - if (c != NULL && c->ep->cig_id == info->cig_id && c->ep->cis_id == info->cis_id) { - *iso_chan = &enabling[i]->ep->iso->chan; - enabling[i] = NULL; + LOG_DBG("ascs %p", ascs); - LOG_DBG("iso_chan %p", *iso_chan); + SYS_SLIST_FOR_EACH_CONTAINER(&ascs->ases, ase, node) { + enum bt_bap_ep_state state; + struct bt_iso_chan *chan; - return 0; + if (ase->ep.cig_id != info->cig_id || ase->ep.cis_id != info->cis_id) { + continue; } - } - - LOG_ERR("No channel listening"); - - return -EPERM; -} - -static int ascs_iso_listen(struct bt_bap_stream *stream) -{ - struct bt_bap_stream **free_stream = NULL; + state = ascs_ep_get_state(&ase->ep); + if (state != BT_BAP_EP_STATE_ENABLING && state != BT_BAP_EP_STATE_QOS_CONFIGURED) { + LOG_WRN("ase %p cannot accept ISO connection", ase); + break; + } - LOG_DBG("stream %p conn %p", stream, (void *)stream->conn); + __ASSERT(ase->ep.iso != NULL, "ep %p not bound with ISO", &ase->ep); - for (size_t i = 0U; i < ARRAY_SIZE(enabling); i++) { - if (enabling[i] == stream) { - return 0; + chan = &ase->ep.iso->chan; + if (chan->iso != NULL) { + LOG_WRN("ase %p chan %p already connected", ase, chan); + return -EALREADY; } - if (enabling[i] == NULL && free_stream == NULL) { - free_stream = &enabling[i]; - } - } + *iso_chan = chan; - if (free_stream != NULL) { - *free_stream = stream; + LOG_DBG("iso_chan %p", *iso_chan); return 0; } - LOG_ERR("Unable to listen: no slot left"); - - return -ENOSPC; + return -EACCES; } static void ascs_iso_recv(struct bt_iso_chan *chan, @@ -741,7 +739,6 @@ static void ascs_ep_iso_disconnected(struct bt_bap_ep *ep, uint8_t reason) struct bt_ascs_ase *ase = CONTAINER_OF(ep, struct bt_ascs_ase, ep); const struct bt_bap_stream_ops *ops; struct bt_bap_stream *stream; - int err; stream = ep->stream; if (stream == NULL) { @@ -756,12 +753,6 @@ static void ascs_ep_iso_disconnected(struct bt_bap_ep *ep, uint8_t reason) if (ep->status.state == BT_BAP_EP_STATE_ENABLING && reason == BT_HCI_ERR_CONN_FAIL_TO_ESTAB) { LOG_DBG("Waiting for retry"); - - err = ascs_iso_listen(stream); - if (err != 0) { - LOG_ERR("Could not make stream listen: %d", err); - } - return; } @@ -790,10 +781,6 @@ static void ascs_ep_iso_disconnected(struct bt_bap_ep *ep, uint8_t reason) ascs_ep_set_state(ep, BT_BAP_EP_STATE_QOS_CONFIGURED); } } - err = ascs_iso_listen(stream); - if (err != 0) { - LOG_ERR("Could not make stream listen: %d", err); - } } } @@ -1071,25 +1058,6 @@ static struct bt_bap_iso *bap_iso_get_or_new(struct bt_ascs *ascs, uint8_t cig_i return iso; } -static void ascs_init(struct bt_ascs *ascs, struct bt_conn *conn) -{ - memset(ascs, 0, sizeof(*ascs)); - - ascs->conn = bt_conn_ref(conn); - sys_slist_init(&ascs->ases); -} - -static struct bt_ascs *ascs_get(struct bt_conn *conn) -{ - struct bt_ascs *session = &sessions[bt_conn_index(conn)]; - - if (session->conn == NULL) { - ascs_init(session, conn); - } - - return session; -} - static uint8_t ase_attr_cb(const struct bt_gatt_attr *attr, uint16_t handle, void *user_data) { @@ -1724,8 +1692,6 @@ static int ase_stream_qos(struct bt_bap_stream *stream, struct bt_codec_qos *qos ascs_ep_set_state(ep, BT_BAP_EP_STATE_QOS_CONFIGURED); - ascs_iso_listen(stream); - *rsp = BT_BAP_ASCS_RSP(BT_BAP_ASCS_RSP_CODE_SUCCESS, BT_BAP_ASCS_REASON_NONE); return 0; } From 1abee09a8b72bed1f9bf49d039b2b74edf43aab2 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Fri, 24 Mar 2023 09:21:36 +0100 Subject: [PATCH 0830/1906] Bluetooth: audio: Fix declaring conn type object in header file The fact of having such extern in iso_internal.h forces the source files that include this header to include conn_internal.h. This breaks the encapsulation of conn object. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/host/conn.c | 2 ++ subsys/bluetooth/host/iso_internal.h | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index d92b8d947d88..0907a789a5d9 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -124,6 +124,8 @@ static struct bt_conn sco_conns[CONFIG_BT_MAX_SCO_CONN]; #endif /* CONFIG_BT_CONN */ #if defined(CONFIG_BT_ISO) +extern struct bt_conn iso_conns[CONFIG_BT_ISO_MAX_CHAN]; + /* Callback TX buffers for ISO */ static struct bt_conn_tx iso_tx[CONFIG_BT_ISO_TX_BUF_COUNT]; diff --git a/subsys/bluetooth/host/iso_internal.h b/subsys/bluetooth/host/iso_internal.h index 5c20fe6acd03..10fc9409643f 100644 --- a/subsys/bluetooth/host/iso_internal.h +++ b/subsys/bluetooth/host/iso_internal.h @@ -72,10 +72,6 @@ struct bt_iso_big { #define iso(buf) ((struct iso_data *)net_buf_user_data(buf)) -#if defined(CONFIG_BT_ISO_MAX_CHAN) -extern struct bt_conn iso_conns[CONFIG_BT_ISO_MAX_CHAN]; -#endif - /* Process ISO buffer */ void hci_iso(struct net_buf *buf); From a6cdb12572c618e834ffadf217e4102f6bced933 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Fri, 24 Mar 2023 08:52:47 +0100 Subject: [PATCH 0831/1906] Bluetooth: audio: bap_stream: Remove reference to conn internals This removes the usage of conn internal API in bap_stream. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/bap_stream.c | 40 ++++++++++++++++++----------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/subsys/bluetooth/audio/bap_stream.c b/subsys/bluetooth/audio/bap_stream.c index 3951bc8807e9..1f037bb6655c 100644 --- a/subsys/bluetooth/audio/bap_stream.c +++ b/subsys/bluetooth/audio/bap_stream.c @@ -19,7 +19,6 @@ #include #include -#include "../host/conn_internal.h" #include "../host/iso_internal.h" #include "bap_iso.h" @@ -97,11 +96,11 @@ void bt_bap_stream_init(struct bt_bap_stream *stream) void bt_bap_stream_attach(struct bt_conn *conn, struct bt_bap_stream *stream, struct bt_bap_ep *ep, struct bt_codec *codec) { - LOG_DBG("conn %p stream %p ep %p codec %p", conn, stream, ep, codec); + LOG_DBG("conn %p stream %p ep %p codec %p", (void *)conn, stream, ep, codec); if (conn != NULL) { __ASSERT(stream->conn == NULL || stream->conn == conn, - "stream->conn %p already attached", stream->conn); + "stream->conn %p already attached", (void *)stream->conn); if (stream->conn == NULL) { stream->conn = bt_conn_ref(conn); } @@ -273,6 +272,17 @@ void bt_bap_stream_reset(struct bt_bap_stream *stream) bt_bap_stream_detach(stream); } +static uint8_t conn_get_role(const struct bt_conn *conn) +{ + struct bt_conn_info info; + int err; + + err = bt_conn_get_info(conn, &info); + __ASSERT(err == 0, "Failed to get conn info"); + + return info.role; +} + #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) int bt_bap_stream_config(struct bt_conn *conn, struct bt_bap_stream *stream, struct bt_bap_ep *ep, @@ -282,7 +292,7 @@ int bt_bap_stream_config(struct bt_conn *conn, struct bt_bap_stream *stream, str int err; LOG_DBG("conn %p stream %p, ep %p codec %p codec id 0x%02x " - "codec cid 0x%04x codec vid 0x%04x", conn, stream, ep, + "codec cid 0x%04x codec vid 0x%04x", (void *)conn, stream, ep, codec, codec ? codec->id : 0, codec ? codec->cid : 0, codec ? codec->vid : 0); @@ -292,11 +302,11 @@ int bt_bap_stream_config(struct bt_conn *conn, struct bt_bap_stream *stream, str } if (stream->conn != NULL) { - LOG_DBG("Stream already configured for conn %p", stream->conn); + LOG_DBG("Stream already configured for conn %p", (void *)stream->conn); return -EALREADY; } - role = conn->role; + role = conn_get_role(conn); if (role != BT_HCI_ROLE_CENTRAL) { LOG_DBG("Invalid conn role: %u, shall be central", role); return -EINVAL; @@ -331,7 +341,7 @@ int bt_bap_stream_qos(struct bt_conn *conn, struct bt_bap_unicast_group *group) uint8_t role; int err; - LOG_DBG("conn %p group %p", conn, group); + LOG_DBG("conn %p group %p", (void *)conn, group); CHECKIF(conn == NULL) { LOG_DBG("conn is NULL"); @@ -348,7 +358,7 @@ int bt_bap_stream_qos(struct bt_conn *conn, struct bt_bap_unicast_group *group) return -ENOEXEC; } - role = conn->role; + role = conn_get_role(conn); if (role != BT_HCI_ROLE_CENTRAL) { LOG_DBG("Invalid conn role: %u, shall be central", role); return -EINVAL; @@ -377,7 +387,7 @@ int bt_bap_stream_enable(struct bt_bap_stream *stream, return -EINVAL; } - role = stream->conn->role; + role = conn_get_role(stream->conn); if (role != BT_HCI_ROLE_CENTRAL) { LOG_DBG("Invalid conn role: %u, shall be central", role); return -EINVAL; @@ -409,7 +419,7 @@ int bt_bap_stream_stop(struct bt_bap_stream *stream) return -EINVAL; } - role = stream->conn->role; + role = conn_get_role(stream->conn); if (role != BT_HCI_ROLE_CENTRAL) { LOG_DBG("Invalid conn role: %u, shall be central", role); return -EINVAL; @@ -469,7 +479,7 @@ int bt_bap_stream_reconfig(struct bt_bap_stream *stream, return -EBADMSG; } - role = stream->conn->role; + role = conn_get_role(stream->conn); if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT) && role == BT_HCI_ROLE_CENTRAL) { err = bt_bap_unicast_client_config(stream, codec); } else if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_SERVER) && role == BT_HCI_ROLE_PERIPHERAL) { @@ -510,7 +520,7 @@ int bt_bap_stream_start(struct bt_bap_stream *stream) return -EBADMSG; } - role = stream->conn->role; + role = conn_get_role(stream->conn); if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT) && role == BT_HCI_ROLE_CENTRAL) { err = bt_bap_unicast_client_start(stream); } else if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_SERVER) && role == BT_HCI_ROLE_PERIPHERAL) { @@ -560,7 +570,7 @@ int bt_bap_stream_metadata(struct bt_bap_stream *stream, return -EBADMSG; } - role = stream->conn->role; + role = conn_get_role(stream->conn); if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT) && role == BT_HCI_ROLE_CENTRAL) { err = bt_bap_unicast_client_metadata(stream, meta, meta_count); } else if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_SERVER) && role == BT_HCI_ROLE_PERIPHERAL) { @@ -602,7 +612,7 @@ int bt_bap_stream_disable(struct bt_bap_stream *stream) return -EBADMSG; } - role = stream->conn->role; + role = conn_get_role(stream->conn); if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT) && role == BT_HCI_ROLE_CENTRAL) { err = bt_bap_unicast_client_disable(stream); } else if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_SERVER) && role == BT_HCI_ROLE_PERIPHERAL) { @@ -650,7 +660,7 @@ int bt_bap_stream_release(struct bt_bap_stream *stream) return -EBADMSG; } - role = stream->conn->role; + role = conn_get_role(stream->conn); if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT) && role == BT_HCI_ROLE_CENTRAL) { err = bt_bap_unicast_client_release(stream); } else if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_SERVER) && role == BT_HCI_ROLE_PERIPHERAL) { From 4d1f9973ed158617a440d1e4b77d49f6f24164df Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Fri, 24 Mar 2023 12:00:39 +0100 Subject: [PATCH 0832/1906] Bluetooth: audio: ascs: Fix double bt_bap_stream_detach call This fixes possible double bt_bap_stream_detach() function call. The bt_bap_stream_detach() called from ascs_ep_set_state state BT_BAP_EP_STATE_IDLE handler. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 1 - 1 file changed, 1 deletion(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index d09727975241..5acc594ea227 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -767,7 +767,6 @@ static void ascs_ep_iso_disconnected(struct bt_bap_ep *ep, uint8_t reason) if (ep->status.state == BT_BAP_EP_STATE_RELEASING) { bt_bap_iso_unbind_ep(ep->iso, ep); - bt_bap_stream_detach(stream); ascs_ep_set_state(ep, BT_BAP_EP_STATE_IDLE); } else { /* The ASE state machine goes into different states from this operation From 6ba2839f6f39024508e45c63c8e7bace05b62a30 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Fri, 24 Mar 2023 12:05:04 +0100 Subject: [PATCH 0833/1906] Bluetooth: audio: ascs: Unbind endpoint in idle state This moves duplicated bt_bap_iso_unbind_ep function call to be handled when ASE enters BT_BAP_EP_STATE_IDLE state. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/ascs.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index 5acc594ea227..9e944319c8de 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -234,6 +234,10 @@ void ascs_ep_set_state(struct bt_bap_ep *ep, uint8_t state) switch (state) { case BT_BAP_EP_STATE_IDLE: + if (ep->iso != NULL) { + bt_bap_iso_unbind_ep(ep->iso, ep); + } + bt_bap_stream_detach(stream); if (ops->released != NULL) { @@ -396,10 +400,6 @@ void ascs_ep_set_state(struct bt_bap_ep *ep, uint8_t state) if (ep->iso == NULL || ep->iso->chan.state == BT_ISO_STATE_DISCONNECTED) { - if (ep->iso != NULL) { - bt_bap_iso_unbind_ep(ep->iso, ep); - } - ascs_ep_set_state(ep, BT_BAP_EP_STATE_IDLE); } else { /* Either the client or the server may disconnect the @@ -766,7 +766,6 @@ static void ascs_ep_iso_disconnected(struct bt_bap_ep *ep, uint8_t reason) } if (ep->status.state == BT_BAP_EP_STATE_RELEASING) { - bt_bap_iso_unbind_ep(ep->iso, ep); ascs_ep_set_state(ep, BT_BAP_EP_STATE_IDLE); } else { /* The ASE state machine goes into different states from this operation From 73e4a736fbe03a8bf0b9f31fa0d981c75540edf3 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Mon, 27 Mar 2023 13:03:52 +0200 Subject: [PATCH 0834/1906] tests: Bluetooth: audio: Extend ISO mock implementation This adds ISO mock with very basic functionality that is needed to mock the `bt_iso_` functions used by ASCS. Signed-off-by: Mariusz Skamra --- tests/bluetooth/audio/ascs/src/main.c | 3 +- tests/bluetooth/audio/mocks/include/iso.h | 13 ++-- tests/bluetooth/audio/mocks/src/iso.c | 79 ++++++++++++++++++++++- 3 files changed, 82 insertions(+), 13 deletions(-) diff --git a/tests/bluetooth/audio/ascs/src/main.c b/tests/bluetooth/audio/ascs/src/main.c index b7829f92e8e1..cde208d61599 100644 --- a/tests/bluetooth/audio/ascs/src/main.c +++ b/tests/bluetooth/audio/ascs/src/main.c @@ -72,7 +72,7 @@ static const struct bt_gatt_attr *ascs_get_attr(const struct bt_uuid *uuid, uint static void mock_init_rule_before(const struct ztest_unit_test *test, void *fixture) { mock_bap_unicast_server_init(); - ISO_FFF_FAKES_LIST(RESET_FAKE); + mock_bt_iso_init(); KERNEL_FFF_FAKES_LIST(RESET_FAKE); PACS_FFF_FAKES_LIST(RESET_FAKE); mock_bap_stream_init(); @@ -82,6 +82,7 @@ static void mock_init_rule_before(const struct ztest_unit_test *test, void *fixt static void mock_destroy_rule_after(const struct ztest_unit_test *test, void *fixture) { mock_bap_unicast_server_cleanup(); + mock_bt_iso_cleanup(); mock_bap_stream_cleanup(); mock_bt_gatt_cleanup(); } diff --git a/tests/bluetooth/audio/mocks/include/iso.h b/tests/bluetooth/audio/mocks/include/iso.h index 913e5a15ab31..e466725b5d78 100644 --- a/tests/bluetooth/audio/mocks/include/iso.h +++ b/tests/bluetooth/audio/mocks/include/iso.h @@ -10,17 +10,12 @@ #include #include -/* List of fakes used by this unit tester */ -#define ISO_FFF_FAKES_LIST(FAKE) \ - FAKE(bt_iso_chan_send) \ - FAKE(bt_iso_server_register) \ - FAKE(bt_iso_server_unregister) \ - FAKE(bt_iso_chan_disconnect) \ +void mock_bt_iso_init(void); +void mock_bt_iso_cleanup(void); +int mock_bt_iso_accept(struct bt_conn *conn, uint8_t cig_id, uint8_t cis_id, + struct bt_iso_chan **chan); DECLARE_FAKE_VALUE_FUNC(int, bt_iso_chan_send, struct bt_iso_chan *, struct net_buf *, uint16_t, uint32_t); -DECLARE_FAKE_VALUE_FUNC(int, bt_iso_server_register, struct bt_iso_server *); -DECLARE_FAKE_VALUE_FUNC(int, bt_iso_server_unregister, struct bt_iso_server *); -DECLARE_FAKE_VALUE_FUNC(int, bt_iso_chan_disconnect, struct bt_iso_chan *); #endif /* MOCKS_ISO_H_ */ diff --git a/tests/bluetooth/audio/mocks/src/iso.c b/tests/bluetooth/audio/mocks/src/iso.c index c9f74910167a..a1bfd21d51f1 100644 --- a/tests/bluetooth/audio/mocks/src/iso.c +++ b/tests/bluetooth/audio/mocks/src/iso.c @@ -4,12 +4,85 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include +#include "conn.h" #include "iso.h" +/* List of fakes used by this unit tester */ +#define FFF_FAKES_LIST(FAKE) \ + FAKE(bt_iso_chan_send) \ + +static struct bt_iso_server *iso_server; + DEFINE_FAKE_VALUE_FUNC(int, bt_iso_chan_send, struct bt_iso_chan *, struct net_buf *, uint16_t, uint32_t); -DEFINE_FAKE_VALUE_FUNC(int, bt_iso_server_register, struct bt_iso_server *); -DEFINE_FAKE_VALUE_FUNC(int, bt_iso_server_unregister, struct bt_iso_server *); -DEFINE_FAKE_VALUE_FUNC(int, bt_iso_chan_disconnect, struct bt_iso_chan *); + +int bt_iso_server_register(struct bt_iso_server *server) +{ + zassert_not_null(server, "server is NULL"); + zassert_not_null(server->accept, "server->accept is NULL"); + zassert_is_null(iso_server, "iso_server is NULL"); + + iso_server = server; + + return 0; +} + +int bt_iso_server_unregister(struct bt_iso_server *server) +{ + zassert_not_null(server, "server is NULL"); + zassert_equal_ptr(iso_server, server, "not registered"); + + iso_server = NULL; + + return 0; +} + +int bt_iso_chan_disconnect(struct bt_iso_chan *chan) +{ + chan->state = BT_ISO_STATE_DISCONNECTED; + chan->ops->disconnected(chan, 0x13); + free(chan->iso); + + return 0; +} + +void mock_bt_iso_init(void) +{ + FFF_FAKES_LIST(RESET_FAKE); +} + +void mock_bt_iso_cleanup(void) +{ + iso_server = NULL; +} + +int mock_bt_iso_accept(struct bt_conn *conn, uint8_t cig_id, uint8_t cis_id, + struct bt_iso_chan **chan) +{ + struct bt_iso_accept_info info = { + .acl = conn, + .cig_id = cig_id, + .cis_id = cis_id, + }; + int err; + + zassert_not_null(iso_server, "iso_server is NULL"); + + err = iso_server->accept(&info, chan); + if (err != 0) { + return err; + } + + zassert_not_null(*chan, "chan is NULL"); + + (*chan)->state = BT_ISO_STATE_CONNECTED; + (*chan)->iso = malloc(sizeof(struct bt_conn)); + zassert_not_null((*chan)->iso); + + (*chan)->ops->connected(*chan); + + return 0; +} From 33767540d92ec7a8fb41af65583ae8e3673ec6fb Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Mon, 27 Mar 2023 13:07:33 +0200 Subject: [PATCH 0835/1906] tests: Bluetooth: audio: Extend kernel mocks This adds basic functionality that mocks the k_work API. The ASCS uses delayed work to defer the CIS disconnection. Signed-off-by: Mariusz Skamra --- tests/bluetooth/audio/ascs/src/main.c | 3 +- .../audio/mocks/include/mock_kernel.h | 13 +--- tests/bluetooth/audio/mocks/src/kernel.c | 59 ++++++++++++++++++- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/tests/bluetooth/audio/ascs/src/main.c b/tests/bluetooth/audio/ascs/src/main.c index cde208d61599..a25edc76d330 100644 --- a/tests/bluetooth/audio/ascs/src/main.c +++ b/tests/bluetooth/audio/ascs/src/main.c @@ -73,7 +73,7 @@ static void mock_init_rule_before(const struct ztest_unit_test *test, void *fixt { mock_bap_unicast_server_init(); mock_bt_iso_init(); - KERNEL_FFF_FAKES_LIST(RESET_FAKE); + mock_kernel_init(); PACS_FFF_FAKES_LIST(RESET_FAKE); mock_bap_stream_init(); mock_bt_gatt_init(); @@ -83,6 +83,7 @@ static void mock_destroy_rule_after(const struct ztest_unit_test *test, void *fi { mock_bap_unicast_server_cleanup(); mock_bt_iso_cleanup(); + mock_kernel_cleanup(); mock_bap_stream_cleanup(); mock_bt_gatt_cleanup(); } diff --git a/tests/bluetooth/audio/mocks/include/mock_kernel.h b/tests/bluetooth/audio/mocks/include/mock_kernel.h index 239949dd2531..2224ea02c6b9 100644 --- a/tests/bluetooth/audio/mocks/include/mock_kernel.h +++ b/tests/bluetooth/audio/mocks/include/mock_kernel.h @@ -11,21 +11,12 @@ #include #include -/* List of fakes used by this unit tester */ -#define KERNEL_FFF_FAKES_LIST(FAKE) \ - FAKE(z_timeout_remaining) \ - FAKE(k_work_schedule) \ - FAKE(k_work_cancel_delayable_sync) \ - FAKE(k_work_init_delayable) \ - FAKE(k_work_cancel_delayable) \ - FAKE(k_work_reschedule) \ +void mock_kernel_init(void); +void mock_kernel_cleanup(void); DECLARE_FAKE_VALUE_FUNC(k_ticks_t, z_timeout_remaining, const struct _timeout *); DECLARE_FAKE_VALUE_FUNC(int, k_work_schedule, struct k_work_delayable *, k_timeout_t); DECLARE_FAKE_VALUE_FUNC(bool, k_work_cancel_delayable_sync, struct k_work_delayable *, struct k_work_sync *); -DECLARE_FAKE_VOID_FUNC(k_work_init_delayable, struct k_work_delayable *, k_work_handler_t); -DECLARE_FAKE_VALUE_FUNC(int, k_work_cancel_delayable, struct k_work_delayable *); -DECLARE_FAKE_VALUE_FUNC(int, k_work_reschedule, struct k_work_delayable *, k_timeout_t); #endif /* MOCKS_KERNEL_H_ */ diff --git a/tests/bluetooth/audio/mocks/src/kernel.c b/tests/bluetooth/audio/mocks/src/kernel.c index 3905898d9be6..bbd8d368a616 100644 --- a/tests/bluetooth/audio/mocks/src/kernel.c +++ b/tests/bluetooth/audio/mocks/src/kernel.c @@ -6,13 +6,66 @@ */ #include +#include #include "mock_kernel.h" +/* List of fakes used by this unit tester */ +#define FFF_FAKES_LIST(FAKE) \ + FAKE(z_timeout_remaining) \ + FAKE(k_work_schedule) \ + FAKE(k_work_cancel_delayable_sync) \ + +/* List of k_work items to be worked. */ +static sys_slist_t work_pending; + DEFINE_FAKE_VALUE_FUNC(k_ticks_t, z_timeout_remaining, const struct _timeout *); DEFINE_FAKE_VALUE_FUNC(int, k_work_schedule, struct k_work_delayable *, k_timeout_t); DEFINE_FAKE_VALUE_FUNC(bool, k_work_cancel_delayable_sync, struct k_work_delayable *, struct k_work_sync *); -DEFINE_FAKE_VOID_FUNC(k_work_init_delayable, struct k_work_delayable *, k_work_handler_t); -DEFINE_FAKE_VALUE_FUNC(int, k_work_cancel_delayable, struct k_work_delayable *); -DEFINE_FAKE_VALUE_FUNC(int, k_work_reschedule, struct k_work_delayable *, k_timeout_t); + +void k_work_init_delayable(struct k_work_delayable *dwork, k_work_handler_t handler) +{ + dwork->work.handler = handler; +} + +int k_work_reschedule(struct k_work_delayable *dwork, k_timeout_t delay) +{ + struct k_work *work; + + /* Determine whether the work item is queued already. */ + SYS_SLIST_FOR_EACH_CONTAINER(&work_pending, work, node) { + if (work == &dwork->work) { + return 0; + } + } + + sys_slist_append(&work_pending, &dwork->work.node); + + return 0; +} + +int k_work_cancel_delayable(struct k_work_delayable *dwork) +{ + (void)sys_slist_find_and_remove(&work_pending, &dwork->work.node); + + return 0; +} + +void mock_kernel_init(void) +{ + FFF_FAKES_LIST(RESET_FAKE); + + sys_slist_init(&work_pending); +} + +void mock_kernel_cleanup(void) +{ + struct k_work *work, *tmp; + + /* Run all pending works */ + SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&work_pending, work, tmp, node) { + (void)sys_slist_remove(&work_pending, NULL, &work->node); + work->handler(work); + } +} From 507cd32072efdd94dba8f570252f092926f95f21 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Mon, 27 Mar 2023 13:11:43 +0200 Subject: [PATCH 0836/1906] tests: Bluetooth: ascs: Add test for Sink entering streaming state This adds unit test for Sink ASE entering streaming state. Signed-off-by: Mariusz Skamra --- tests/bluetooth/audio/ascs/src/main.c | 22 +++++++++++++++++++ .../include/bap_unicast_server_expects.h | 15 +++++++++++++ 2 files changed, 37 insertions(+) diff --git a/tests/bluetooth/audio/ascs/src/main.c b/tests/bluetooth/audio/ascs/src/main.c index a25edc76d330..7191bac8a613 100644 --- a/tests/bluetooth/audio/ascs/src/main.c +++ b/tests/bluetooth/audio/ascs/src/main.c @@ -739,6 +739,28 @@ ZTEST_F(ascs_ase_control_test_suite, test_sink_ase_control_release_from_qos_conf expect_bt_bap_stream_ops_released_called_once(&fixture->stream); } +ZTEST_F(ascs_ase_control_test_suite, test_sink_ase_control_streaming_from_enabling) +{ + struct bt_iso_chan *chan; + int err; + + Z_TEST_SKIP_IFNDEF(CONFIG_BT_ASCS_ASE_SNK); + + /* Preamble */ + ase_cp_write_codec_config(fixture->ase_cp, &fixture->conn, &fixture->stream); + ase_cp_write_config_qos(fixture->ase_cp, &fixture->conn, &fixture->stream); + ase_cp_write_enable(fixture->ase_cp, &fixture->conn, &fixture->stream); + + err = mock_bt_iso_accept(&fixture->conn, 0x01, 0x01, &chan); + zassert_equal(0, err, "Failed to connect iso: err %d", err); + + err = bt_bap_stream_start(&fixture->stream); + zassert_equal(0, err, "Failed to start stream: err %d", err); + + /* XXX: unicast_server_cb->start is not called for Sink ASE */ + expect_bt_bap_stream_ops_started_called_once(&fixture->stream); +} + static void ascs_test_suite_after(void *f) { bt_ascs_cleanup(); diff --git a/tests/bluetooth/audio/mocks/include/bap_unicast_server_expects.h b/tests/bluetooth/audio/mocks/include/bap_unicast_server_expects.h index 269e85dec9bb..7ff6b04b0746 100644 --- a/tests/bluetooth/audio/mocks/include/bap_unicast_server_expects.h +++ b/tests/bluetooth/audio/mocks/include/bap_unicast_server_expects.h @@ -108,4 +108,19 @@ do { func_name, "stream");)) \ } while (0) +#define expect_bt_bap_unicast_server_cb_start_called_once(_stream) \ +do { \ + const char *func_name = "bt_bap_unicast_server_cb.start"; \ + \ + zassert_true(mock_bap_unicast_server_cb_start_fake.call_count > 0, \ + "'%s()' was not called", func_name); \ + zassert_equal(1, mock_bap_unicast_server_cb_start_fake.call_count, \ + "'%s()' was called more than once", func_name); \ + \ + IF_NOT_EMPTY(_stream, ( \ + zassert_equal_ptr(_stream, mock_bap_unicast_server_cb_start_fake.arg0_val, \ + "'%s()' was called with incorrect '%s' value", \ + func_name, "stream");)) \ +} while (0) + #endif /* MOCKS_BAP_UNICAST_SERVER_EXPECTS_H_ */ From 570110e672f1eb5e1e6a8819663fe22725f11f69 Mon Sep 17 00:00:00 2001 From: Eduardo Montoya Date: Fri, 17 Mar 2023 10:44:56 +0100 Subject: [PATCH 0837/1906] drivers: ieee802154: remove not useful log Remove a warning log which shows on every delayed transmission and it is not helpful. Signed-off-by: Eduardo Montoya --- drivers/ieee802154/ieee802154_nrf5.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index b05fad58a87e..c4d89eea8479 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -562,15 +562,8 @@ static bool nrf5_tx_at(struct net_pkt *pkt, uint8_t *payload, bool cca) }, }; uint64_t tx_at = target_time_convert_to_64_bits(net_pkt_txtime(pkt) / NSEC_PER_USEC); - bool ret; - ret = nrf_802154_transmit_raw_at(payload, - tx_at, - &metadata); - if (nrf5_data.event_handler) { - LOG_WRN("TX_STARTED event will be triggered without delay"); - } - return ret; + return nrf_802154_transmit_raw_at(payload, tx_at, &metadata); } #endif /* CONFIG_NET_PKT_TXTIME */ From 4555eb94c8b5263309988bfab6f8231db17fe82f Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Thu, 16 Mar 2023 14:58:37 +0100 Subject: [PATCH 0838/1906] dts: arm: stm32h5 devices Creates the device tree for the new stm32h5 serie: from stm32h5 and other derivative mcus. Signed-off-by: Francois Ramu --- dts/arm/st/h5/stm32h5.dtsi | 234 +++++++++++++++++++++++++++++++++ dts/arm/st/h5/stm32h503.dtsi | 7 + dts/arm/st/h5/stm32h503Xb.dtsi | 21 +++ dts/arm/st/h5/stm32h562.dtsi | 99 ++++++++++++++ dts/arm/st/h5/stm32h563.dtsi | 7 + dts/arm/st/h5/stm32h573.dtsi | 7 + dts/arm/st/h5/stm32h573Xi.dtsi | 21 +++ 7 files changed, 396 insertions(+) create mode 100644 dts/arm/st/h5/stm32h5.dtsi create mode 100644 dts/arm/st/h5/stm32h503.dtsi create mode 100644 dts/arm/st/h5/stm32h503Xb.dtsi create mode 100644 dts/arm/st/h5/stm32h562.dtsi create mode 100644 dts/arm/st/h5/stm32h563.dtsi create mode 100644 dts/arm/st/h5/stm32h573.dtsi create mode 100644 dts/arm/st/h5/stm32h573Xi.dtsi diff --git a/dts/arm/st/h5/stm32h5.dtsi b/dts/arm/st/h5/stm32h5.dtsi new file mode 100644 index 000000000000..830bbaa93d7d --- /dev/null +++ b/dts/arm/st/h5/stm32h5.dtsi @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ + + +#include +#include +#include +#include +#include + +/ { + chosen { + zephyr,flash-controller = &flash; + }; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu0: cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-m33"; + reg = <0>; + #address-cells = <1>; + #size-cells = <1>; + + mpu: mpu@e000ed90 { + compatible = "arm,armv8m-mpu"; + reg = <0xe000ed90 0x40>; + arm,num-mpu-regions = <8>; + }; + }; + }; + + clocks { + clk_hse: clk-hse { + #clock-cells = <0>; + compatible = "st,stm32-hse-clock"; + status = "disabled"; + }; + + clk_hsi: clk-hsi { + #clock-cells = <0>; + compatible = "st,stm32h7-hsi-clock"; + hsi-div = <1>; /* HSI RC: 64MHz, hsi_clk = 64MHz */ + clock-frequency = ; + status = "disabled"; + }; + + clk_hsi48: clk-hsi48 { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = ; + status = "disabled"; + }; + + clk_csi: clk-csi { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = ; + status = "disabled"; + }; + + clk_lse: clk-lse { + #clock-cells = <0>; + compatible = "st,stm32-lse-clock"; + clock-frequency = <32768>; + driving-capability = <2>; + status = "disabled"; + }; + + clk_lsi: clk-lsi { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = ; + status = "disabled"; + }; + /* The pll scheme is similar to stm32u5 */ + pll1: pll: pll { + #clock-cells = <0>; + compatible = "st,stm32u5-pll-clock"; + status = "disabled"; + }; + + pll2: pll2 { + #clock-cells = <0>; + compatible = "st,stm32u5-pll-clock"; + status = "disabled"; + }; + }; + + soc { + flash: flash-controller@40022000 { + compatible = "st,stm32-flash-controller", "st,stm32l5-flash-controller"; + reg = <0x40022000 0x400>; + interrupts = <6 0>; + + #address-cells = <1>; + #size-cells = <1>; + + flash0: flash@8000000 { + compatible = "st,stm32-nv-flash", "soc-nv-flash"; + + write-block-size = <16>; + erase-block-size = <8192>; + /* maximum erase time(ms) for a 8K sector */ + max-erase-time = <5>; + }; + }; + + rcc: rcc@44020c00 { + compatible = "st,stm32u5-rcc"; + clocks-controller; + #clock-cells = <2>; + reg = <0x44020c00 0x400>; + + rctl: reset-controller { + compatible = "st,stm32-rcc-rctl"; + #reset-cells = <1>; + }; + }; + + exti: interrupt-controller@44022000 { + compatible = "st,stm32g0-exti", "st,stm32-exti"; + interrupt-controller; + #interrupt-cells = <1>; + #address-cells = <1>; + reg = <0x44022000 0x400>; + num-lines = <16>; + interrupts = <11 0>, <12 0>, <13 0>, <14 0>, + <15 0>, <16 0>, <17 0>, <18 0>, + <19 0>, <20 0>, <21 0>, <22 0>, + <23 0>, <24 0>, <25 0>, <26 0>; + interrupt-names = "line0", "line1", "line2", "line3", + "line4", "line5", "line6", "line7", + "line8", "line9", "line10", "line11", + "line12", "line13", "line14", "line15"; + line-ranges = <0 1>, <1 1>, <2 1>, <3 1>, + <4 1>, <5 1>, <6 1>, <7 1>, + <8 1>, <9 1>, <10 1>, <11 1>, + <12 1>, <13 1>, <14 1>, <15 1>; + }; + + pinctrl: pin-controller@42020000 { + compatible = "st,stm32-pinctrl"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x42020000 0x2000>; + + gpioa: gpio@42020000 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x42020000 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00000001>; + }; + + gpiob: gpio@42020400 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x42020400 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00000002>; + }; + + gpioc: gpio@42020800 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x42020800 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00000004>; + }; + + gpiod: gpio@42020c00 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x42020c00 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00000008>; + }; + + gpioh: gpio@42021c00 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x42021c00 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00000080>; + }; + }; + + usart1: serial@40013800 { + compatible = "st,stm32-usart", "st,stm32-uart"; + reg = <0x40013800 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB2 0x00004000>; + resets = <&rctl STM32_RESET(APB2, 14U)>; + interrupts = <58 0>; + status = "disabled"; + }; + + usart2: serial@40004400 { + compatible = "st,stm32-usart", "st,stm32-uart"; + reg = <0x40004400 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1 0x00020000>; + resets = <&rctl STM32_RESET(APB1L, 17U)>; + interrupts = <59 0>; + status = "disabled"; + }; + + usart3: serial@40004800 { + compatible = "st,stm32-usart", "st,stm32-uart"; + reg = <0x40004800 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1 0x00040000>; + resets = <&rctl STM32_RESET(APB1L, 18U)>; + interrupts = <60 0>; + status = "disabled"; + }; + + lpuart1: serial@44002400 { + compatible = "st,stm32-lpuart", "st,stm32-uart"; + reg = <0x44002400 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB3 0x00000040>; + resets = <&rctl STM32_RESET(APB3, 6U)>; + interrupts = <63 0>; + status = "disabled"; + }; + }; +}; + +&nvic { + arm,num-irq-priority-bits = <4>; +}; diff --git a/dts/arm/st/h5/stm32h503.dtsi b/dts/arm/st/h5/stm32h503.dtsi new file mode 100644 index 000000000000..cee676dcab11 --- /dev/null +++ b/dts/arm/st/h5/stm32h503.dtsi @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include diff --git a/dts/arm/st/h5/stm32h503Xb.dtsi b/dts/arm/st/h5/stm32h503Xb.dtsi new file mode 100644 index 000000000000..2ab6e3ae0a77 --- /dev/null +++ b/dts/arm/st/h5/stm32h503Xb.dtsi @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include + +/ { + sram0: memory@20000000 { + reg = <0x20000000 DT_SIZE_K(32)>; + }; + + soc { + flash-controller@40022000 { + flash0: flash@8000000 { + reg = <0x08000000 DT_SIZE_K(128)>; + }; + }; + }; +}; diff --git a/dts/arm/st/h5/stm32h562.dtsi b/dts/arm/st/h5/stm32h562.dtsi new file mode 100644 index 000000000000..f7db15ef8403 --- /dev/null +++ b/dts/arm/st/h5/stm32h562.dtsi @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/ { + clocks { + /* The pll scheme is similar to stm32u5 */ + pll3: pll3 { + #clock-cells = <0>; + compatible = "st,stm32u5-pll-clock"; + status = "disabled"; + }; + }; + + soc { + pinctrl: pin-controller@42020000 { + gpioe: gpio@42021000 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x42021000 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00000010>; + }; + + gpiof: gpio@42021400 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x42021400 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00000020>; + }; + + gpiog: gpio@42021800 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x42021800 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00000040>; + }; + + gpioi: gpio@42022000 { + compatible = "st,stm32-gpio"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x42022000 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00000100>; + }; + }; + + uart4: serial@40004c00 { + compatible = "st,stm32-uart"; + reg = <0x40004c00 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1 0x00080000>; + resets = <&rctl STM32_RESET(APB1L, 19U)>; + interrupts = <61 0>; + status = "disabled"; + }; + + uart5: serial@40005000 { + compatible = "st,stm32-uart"; + reg = <0x40005000 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1 0x00100000>; + resets = <&rctl STM32_RESET(APB1L, 20U)>; + interrupts = <62 0>; + status = "disabled"; + }; + + uart9: serial@40008000 { + compatible = "st,stm32-uart"; + reg = <0x40008000 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1_2 0x00000001>; + resets = <&rctl STM32_RESET(APB1H, 0U)>; + interrupts = <100 0>; + status = "disabled"; + }; + + usart10: serial@40006800 { + compatible = "st,stm32-usart", "st,stm32-uart"; + reg = <0x40006800 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1 0x04000000>; + resets = <&rctl STM32_RESET(APB1L, 26U)>; + interrupts = <86 0>; + status = "disabled"; + }; + + uart12: serial@40008400 { + compatible = "st,stm32-uart"; + reg = <0x40008400 0x400>; + clocks = <&rcc STM32_CLOCK_BUS_APB1_2 0x00000002>; + resets = <&rctl STM32_RESET(APB1H, 1U)>; + interrupts = <101 0>; + status = "disabled"; + }; + }; +}; diff --git a/dts/arm/st/h5/stm32h563.dtsi b/dts/arm/st/h5/stm32h563.dtsi new file mode 100644 index 000000000000..03225c410026 --- /dev/null +++ b/dts/arm/st/h5/stm32h563.dtsi @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include diff --git a/dts/arm/st/h5/stm32h573.dtsi b/dts/arm/st/h5/stm32h573.dtsi new file mode 100644 index 000000000000..9cf9c63acb5a --- /dev/null +++ b/dts/arm/st/h5/stm32h573.dtsi @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include diff --git a/dts/arm/st/h5/stm32h573Xi.dtsi b/dts/arm/st/h5/stm32h573Xi.dtsi new file mode 100644 index 000000000000..152d9cbd6bf4 --- /dev/null +++ b/dts/arm/st/h5/stm32h573Xi.dtsi @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include + +/ { + sram0: memory@20000000 { + reg = <0x20000000 DT_SIZE_K(640)>; + }; + + soc { + flash-controller@40022000 { + flash0: flash@8000000 { + reg = <0x08000000 DT_SIZE_M(2)>; + }; + }; + }; +}; From ea7bf8bab1de5007b4569f798a58e05fc83dbea8 Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Wed, 22 Mar 2023 10:22:59 +0100 Subject: [PATCH 0839/1906] dts: bindings: interrupt controller for the new stm32h5 serie Adds the new stm32h5 serie to the list of st,stm32g0-exti compatible : now the matching targets is C0/G0/H5/U5/L5/MP1. Signed-off-by: Francois Ramu --- dts/bindings/interrupt-controller/st,stm32g0-exti.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dts/bindings/interrupt-controller/st,stm32g0-exti.yaml b/dts/bindings/interrupt-controller/st,stm32g0-exti.yaml index 55d860cb9980..6f8704416ddb 100644 --- a/dts/bindings/interrupt-controller/st,stm32g0-exti.yaml +++ b/dts/bindings/interrupt-controller/st,stm32g0-exti.yaml @@ -4,8 +4,8 @@ description: | STM32 controller - This compatible stands for all interrupt-controller blocks for the - STM32C0/G0/L5/mp/u5. + This compatible stands for all interrupt-controller blocks with two + dedicated Rising and Falling interrupt pending registers. compatible: "st,stm32g0-exti" From 3b1dd7380b90d8fe65c71373d088be2d12040b98 Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Wed, 30 Nov 2022 09:06:42 +0100 Subject: [PATCH 0840/1906] soc: arm: stm32h5 new soc serie Introduce the new stm32h5 soc serie from STMIcroelectronics. Note that stm32h503x do not have TrustZone nor SAU Signed-off-by: Francois Ramu --- soc/arm/st_stm32/stm32h5/CMakeLists.txt | 6 ++ .../st_stm32/stm32h5/Kconfig.defconfig.series | 16 +++++ .../stm32h5/Kconfig.defconfig.stm32h503xx | 14 ++++ .../stm32h5/Kconfig.defconfig.stm32h562xx | 14 ++++ .../stm32h5/Kconfig.defconfig.stm32h563xx | 14 ++++ .../stm32h5/Kconfig.defconfig.stm32h573xx | 14 ++++ soc/arm/st_stm32/stm32h5/Kconfig.series | 19 ++++++ soc/arm/st_stm32/stm32h5/Kconfig.soc | 22 +++++++ soc/arm/st_stm32/stm32h5/linker.ld | 9 +++ soc/arm/st_stm32/stm32h5/soc.c | 65 +++++++++++++++++++ soc/arm/st_stm32/stm32h5/soc.h | 22 +++++++ 11 files changed, 215 insertions(+) create mode 100644 soc/arm/st_stm32/stm32h5/CMakeLists.txt create mode 100644 soc/arm/st_stm32/stm32h5/Kconfig.defconfig.series create mode 100644 soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h503xx create mode 100644 soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h562xx create mode 100644 soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h563xx create mode 100644 soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h573xx create mode 100644 soc/arm/st_stm32/stm32h5/Kconfig.series create mode 100644 soc/arm/st_stm32/stm32h5/Kconfig.soc create mode 100644 soc/arm/st_stm32/stm32h5/linker.ld create mode 100644 soc/arm/st_stm32/stm32h5/soc.c create mode 100644 soc/arm/st_stm32/stm32h5/soc.h diff --git a/soc/arm/st_stm32/stm32h5/CMakeLists.txt b/soc/arm/st_stm32/stm32h5/CMakeLists.txt new file mode 100644 index 000000000000..ac3ba70ace6e --- /dev/null +++ b/soc/arm/st_stm32/stm32h5/CMakeLists.txt @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_include_directories(${ZEPHYR_BASE}/drivers) +zephyr_sources( + soc.c + ) diff --git a/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.series b/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.series new file mode 100644 index 000000000000..201694ed708a --- /dev/null +++ b/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.series @@ -0,0 +1,16 @@ +# ST Microelectronics STM32H5 MCU line + +# Copyright (c) 2023 STMicroelectronics +# SPDX-License-Identifier: Apache-2.0 + +if SOC_SERIES_STM32H5X + +source "soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h5*" + +config SOC_SERIES + default "stm32h5" + +config ROM_START_OFFSET + default 0x400 if BOOTLOADER_MCUBOOT + +endif # SOC_SERIES_STM32H5X diff --git a/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h503xx b/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h503xx new file mode 100644 index 000000000000..e7d7b508baac --- /dev/null +++ b/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h503xx @@ -0,0 +1,14 @@ +# STMicroelectronics STM32H503XX MCU + +# Copyright (c) 2023 STMicroelectronics +# SPDX-License-Identifier: Apache-2.0 + +if SOC_STM32H503XX + +config SOC + default "stm32h503xx" + +config NUM_IRQS + default 134 + +endif # SOC_STM32H503XX diff --git a/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h562xx b/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h562xx new file mode 100644 index 000000000000..eb76a2d79892 --- /dev/null +++ b/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h562xx @@ -0,0 +1,14 @@ +# STMicroelectronics STM32H562XX MCU + +# Copyright (c) 2023 STMicroelectronics +# SPDX-License-Identifier: Apache-2.0 + +if SOC_STM32H562XX + +config SOC + default "stm32h562xx" + +config NUM_IRQS + default 131 + +endif # SOC_STM32H562XX diff --git a/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h563xx b/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h563xx new file mode 100644 index 000000000000..94994a7d060a --- /dev/null +++ b/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h563xx @@ -0,0 +1,14 @@ +# STMicroelectronics STM32H563XX MCU + +# Copyright (c) 2023 STMicroelectronics +# SPDX-License-Identifier: Apache-2.0 + +if SOC_STM32H563XX + +config SOC + default "stm32h563xx" + +config NUM_IRQS + default 131 + +endif # SOC_STM32H563XX diff --git a/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h573xx b/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h573xx new file mode 100644 index 000000000000..d6641c126eca --- /dev/null +++ b/soc/arm/st_stm32/stm32h5/Kconfig.defconfig.stm32h573xx @@ -0,0 +1,14 @@ +# STMicroelectronics STM32H573XX MCU + +# Copyright (c) 2023 STMicroelectronics +# SPDX-License-Identifier: Apache-2.0 + +if SOC_STM32H573XX + +config SOC + default "stm32h573xx" + +config NUM_IRQS + default 131 + +endif # SOC_STM32H573XX diff --git a/soc/arm/st_stm32/stm32h5/Kconfig.series b/soc/arm/st_stm32/stm32h5/Kconfig.series new file mode 100644 index 000000000000..ceefa3486964 --- /dev/null +++ b/soc/arm/st_stm32/stm32h5/Kconfig.series @@ -0,0 +1,19 @@ +# ST Microelectronics STM32H5 MCU series + +# Copyright (c) 2023 STMicroelectronics +# SPDX-License-Identifier: Apache-2.0 + +config SOC_SERIES_STM32H5X + bool "STM32H5x Series MCU" + select ARM + select CPU_CORTEX_M33 + select SOC_FAMILY_STM32 + select ARM_TRUSTZONE_M if !SOC_STM32H503XX + select CPU_HAS_ARM_SAU if !SOC_STM32H503XX + select CPU_HAS_ARM_MPU + select CPU_HAS_FPU + select ARMV8_M_DSP + select CPU_CORTEX_M_HAS_DWT + select HAS_STM32CUBE + help + Enable support for STM32H5 MCU series diff --git a/soc/arm/st_stm32/stm32h5/Kconfig.soc b/soc/arm/st_stm32/stm32h5/Kconfig.soc new file mode 100644 index 000000000000..3bf6a3605c0e --- /dev/null +++ b/soc/arm/st_stm32/stm32h5/Kconfig.soc @@ -0,0 +1,22 @@ +# ST Microelectronics STM32H5 MCU line + +# Copyright (c) 2023 STMicroelectronics +# SPDX-License-Identifier: Apache-2.0 + +choice +prompt "STM32H5x MCU Selection" +depends on SOC_SERIES_STM32H5X + +config SOC_STM32H503XX + bool "STM32H503XX" + +config SOC_STM32H562XX + bool "STM32H562XX" + +config SOC_STM32H563XX + bool "STM32H563XX" + +config SOC_STM32H573XX + bool "STM32H573XX" + +endchoice diff --git a/soc/arm/st_stm32/stm32h5/linker.ld b/soc/arm/st_stm32/stm32h5/linker.ld new file mode 100644 index 000000000000..8bd989bc732f --- /dev/null +++ b/soc/arm/st_stm32/stm32h5/linker.ld @@ -0,0 +1,9 @@ +/* linker.ld - Linker command/script file */ + +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include diff --git a/soc/arm/st_stm32/stm32h5/soc.c b/soc/arm/st_stm32/stm32h5/soc.c new file mode 100644 index 000000000000..67483764ad79 --- /dev/null +++ b/soc/arm/st_stm32/stm32h5/soc.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief System/hardware module for STM32H5 processor + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOG_LEVEL CONFIG_SOC_LOG_LEVEL +LOG_MODULE_REGISTER(soc); + +/** + * @brief Perform basic hardware initialization at boot. + * + * This needs to be run from the very beginning. + * So the init priority has to be 0 (zero). + * + * @return 0 + */ +static int stm32h5_init(const struct device *arg) +{ + uint32_t key; + + ARG_UNUSED(arg); + + key = irq_lock(); + + /* Install default handler that simply resets the CPU + * if configured in the kernel, NOP otherwise + */ + NMI_INIT(); + + irq_unlock(key); + + /* Enable instruction cache in 1-way (direct mapped cache) */ + LL_ICACHE_SetMode(LL_ICACHE_1WAY); + LL_ICACHE_Enable(); + + /* Update CMSIS SystemCoreClock variable (HCLK) */ + /* At reset, system core clock is set to 32 MHz from HSI with a HSIDIV = 2 */ + SystemCoreClock = 32000000; + +#if defined(PWR_UCPDR_UCPD_DBDIS) + /* Disable USB Type-C dead battery pull-down behavior */ + LL_PWR_DisableUCPDDeadBattery(); +#endif /* PWR_UCPDR_UCPD_DBDIS */ + + return 0; +} + +SYS_INIT(stm32h5_init, PRE_KERNEL_1, 0); diff --git a/soc/arm/st_stm32/stm32h5/soc.h b/soc/arm/st_stm32/stm32h5/soc.h new file mode 100644 index 000000000000..e84a2ffd0749 --- /dev/null +++ b/soc/arm/st_stm32/stm32h5/soc.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file SoC configuration macros for the STM32H5 family processors. + * + */ + + +#ifndef _STM32H5_SOC_H_ +#define _STM32H5_SOC_H_ + +#ifndef _ASMLANGUAGE + +#include + +#endif /* !_ASMLANGUAGE */ + +#endif /* _STM32H5_SOC_H_ */ From ff1969de3b6525b2447329fb976302d553aadd20 Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Wed, 30 Nov 2022 09:07:47 +0100 Subject: [PATCH 0841/1906] include: clock: stm32h5 clock definitions for clock scheme Defines the clocks for the stm32H5 device. The PLL is similar to the stm32U5 except for the mul-n from 8 to 420. The HSI is similar to the stm32h7 with a prediv. Signed-off-by: Francois Ramu --- .../clock_control/stm32_clock_control.h | 2 + .../zephyr/dt-bindings/clock/stm32h5_clock.h | 145 ++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 include/zephyr/dt-bindings/clock/stm32h5_clock.h diff --git a/include/zephyr/drivers/clock_control/stm32_clock_control.h b/include/zephyr/drivers/clock_control/stm32_clock_control.h index 064c3953be6a..4922ec481ce1 100644 --- a/include/zephyr/drivers/clock_control/stm32_clock_control.h +++ b/include/zephyr/drivers/clock_control/stm32_clock_control.h @@ -38,6 +38,8 @@ #include #elif defined(CONFIG_SOC_SERIES_STM32WLX) #include +#elif defined(CONFIG_SOC_SERIES_STM32H5X) +#include #elif defined(CONFIG_SOC_SERIES_STM32H7X) #include #elif defined(CONFIG_SOC_SERIES_STM32U5X) diff --git a/include/zephyr/dt-bindings/clock/stm32h5_clock.h b/include/zephyr/dt-bindings/clock/stm32h5_clock.h new file mode 100644 index 000000000000..c5172c4e6b64 --- /dev/null +++ b/include/zephyr/dt-bindings/clock/stm32h5_clock.h @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_STM32H5_CLOCK_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_STM32H5_CLOCK_H_ + +/** Domain clocks */ + +/* RM0481/0492, Table 47 Kernel clock distribution summary */ + +/** PLL outputs */ +#define STM32_SRC_PLL1_P 0x001 +#define STM32_SRC_PLL1_Q 0x002 +#define STM32_SRC_PLL1_R 0x003 +#define STM32_SRC_PLL2_P 0x004 +#define STM32_SRC_PLL2_Q 0x005 +#define STM32_SRC_PLL2_R 0x006 +#define STM32_SRC_PLL3_P 0x007 +#define STM32_SRC_PLL3_Q 0x008 +#define STM32_SRC_PLL3_R 0x009 +/** Fixed clocks */ +#define STM32_SRC_HSE 0x00A +#define STM32_SRC_LSE 0x00B +#define STM32_SRC_LSI 0x00C +#define STM32_SRC_CSI 0x00D +#define STM32_SRC_HSI 0x00E +#define STM32_SRC_HSI48 0x00F + +/** Core clock */ +#define STM32_SRC_SYSCLK 0x011 + +/** Clock muxes */ +#define STM32_SRC_CKPER 0x012 + +/** Bus clocks */ +#define STM32_CLOCK_BUS_AHB1 0x088 +#define STM32_CLOCK_BUS_AHB2 0x08C +#define STM32_CLOCK_BUS_AHB4 0x094 +#define STM32_CLOCK_BUS_APB1 0x09c +#define STM32_CLOCK_BUS_APB1_2 0x0A0 +#define STM32_CLOCK_BUS_APB2 0x0A4 +#define STM32_CLOCK_BUS_APB3 0x0A8 + +#define STM32_PERIPH_BUS_MIN STM32_CLOCK_BUS_AHB1 +#define STM32_PERIPH_BUS_MAX STM32_CLOCK_BUS_APB3 + +#define STM32_CLOCK_REG_MASK 0xFFU +#define STM32_CLOCK_REG_SHIFT 0U +#define STM32_CLOCK_SHIFT_MASK 0x1FU +#define STM32_CLOCK_SHIFT_SHIFT 8U +#define STM32_CLOCK_MASK_MASK 0x7U +#define STM32_CLOCK_MASK_SHIFT 13U +#define STM32_CLOCK_VAL_MASK 0x7U +#define STM32_CLOCK_VAL_SHIFT 16U + +/** + * @brief STM32H5 clock configuration bit field. + * + * - reg (1/2/3/4/5) [ 0 : 7 ] + * - shift (0..31) [ 8 : 12 ] + * - mask (0x1, 0x3, 0x7) [ 13 : 15 ] + * - val (0..7) [ 16 : 18 ] + * + * @param reg RCC_CCIPRx register offset + * @param shift Position within RCC_CCIPRx. + * @param mask Mask for the RCC_CCIPRx field. + * @param val Clock value (0, 1, ... 7). + */ +#define STM32_CLOCK(val, mask, shift, reg) \ + ((((reg) & STM32_CLOCK_REG_MASK) << STM32_CLOCK_REG_SHIFT) | \ + (((shift) & STM32_CLOCK_SHIFT_MASK) << STM32_CLOCK_SHIFT_SHIFT) | \ + (((mask) & STM32_CLOCK_MASK_MASK) << STM32_CLOCK_MASK_SHIFT) | \ + (((val) & STM32_CLOCK_VAL_MASK) << STM32_CLOCK_VAL_SHIFT)) + +/** @brief RCC_CCIPRx register offset (RM0456.pdf) */ +#define CCIPR1_REG 0xD8 +#define CCIPR2_REG 0xDC +#define CCIPR3_REG 0xE0 +#define CCIPR4_REG 0xE4 +#define CCIPR5_REG 0xE8 + +/** @brief RCC_BDCR register offset */ +#define BDCR_REG 0xF0 + +/** @brief Device domain clocks selection helpers */ +/** CCIPR1 devices */ +#define USART1_SEL(val) STM32_CLOCK(val, 7, 0, CCIPR1_REG) +#define USART2_SEL(val) STM32_CLOCK(val, 7, 3, CCIPR1_REG) +#define USART3_SEL(val) STM32_CLOCK(val, 7, 6, CCIPR1_REG) +#define USART4_SEL(val) STM32_CLOCK(val, 7, 9, CCIPR1_REG) +#define USART5_SEL(val) STM32_CLOCK(val, 7, 12, CCIPR1_REG) +#define USART6_SEL(val) STM32_CLOCK(val, 7, 15, CCIPR1_REG) +#define USART7_SEL(val) STM32_CLOCK(val, 7, 18, CCIPR1_REG) +#define USART8_SEL(val) STM32_CLOCK(val, 7, 21, CCIPR1_REG) +#define USART9_SEL(val) STM32_CLOCK(val, 7, 24, CCIPR1_REG) +#define USART10_SEL(val) STM32_CLOCK(val, 7, 27, CCIPR1_REG) +#define TIMIC_SEL(val) STM32_CLOCK(val, 1, 31, CCIPR1_REG) + +/** CCIPR2 devices */ +#define USART11_SEL(val) STM32_CLOCK(val, 7, 0, CCIPR2_REG) +#define USART12_SEL(val) STM32_CLOCK(val, 7, 4, CCIPR2_REG) +#define LPTIM1_SEL(val) STM32_CLOCK(val, 7, 8, CCIPR2_REG) +#define LPTIM2_SEL(val) STM32_CLOCK(val, 7, 12, CCIPR2_REG) +#define LPTIM3_SEL(val) STM32_CLOCK(val, 7, 16, CCIPR2_REG) +#define LPTIM4_SEL(val) STM32_CLOCK(val, 7, 20, CCIPR2_REG) +#define LPTIM5_SEL(val) STM32_CLOCK(val, 7, 24, CCIPR2_REG) +#define LPTIM6_SEL(val) STM32_CLOCK(val, 7, 28, CCIPR2_REG) + +/** CCIPR3 devices */ +#define SPI1_SEL(val) STM32_CLOCK(val, 7, 0, CCIPR3_REG) +#define SPI2_SEL(val) STM32_CLOCK(val, 7, 3, CCIPR3_REG) +#define SPI3_SEL(val) STM32_CLOCK(val, 7, 6, CCIPR3_REG) +#define SPI4_SEL(val) STM32_CLOCK(val, 7, 9, CCIPR3_REG) +#define SPI5_SEL(val) STM32_CLOCK(val, 7, 12, CCIPR3_REG) +#define SPI6_SEL(val) STM32_CLOCK(val, 7, 15, CCIPR2_REG) +#define LPUART1_SEL(val) STM32_CLOCK(val, 7, 24, CCIPR3_REG) + +/** CCIPR4 devices */ +#define OCTOSPI1_SEL(val) STM32_CLOCK(val, 3, 0, CCIPR4_REG) +#define SYSTICK_SEL(val) STM32_CLOCK(val, 3, 2, CCIPR4_REG) +#define USB_SEL(val) STM32_CLOCK(val, 3, 4, CCIPR4_REG) +#define SDMMC1_SEL(val) STM32_CLOCK(val, 1, 6, CCIPR4_REG) +#define SDMMC2_SEL(val) STM32_CLOCK(val, 1, 7, CCIPR4_REG) +#define I2C1_SEL(val) STM32_CLOCK(val, 3, 16, CCIPR4_REG) +#define I2C2_SEL(val) STM32_CLOCK(val, 3, 18, CCIPR4_REG) +#define I2C3_SEL(val) STM32_CLOCK(val, 3, 20, CCIPR4_REG) +#define I2C4_SEL(val) STM32_CLOCK(val, 3, 22, CCIPR4_REG) +#define I3C1_SEL(val) STM32_CLOCK(val, 3, 24, CCIPR4_REG) + +/** CCIPR5 devices */ +#define ADCDAC_SEL(val) STM32_CLOCK(val, 7, 0, CCIPR5_REG) +#define DAC_SEL(val) STM32_CLOCK(val, 1, 3, CCIPR5_REG) +#define RNG_SEL(val) STM32_CLOCK(val, 3, 4, CCIPR5_REG) +#define CEC_SEL(val) STM32_CLOCK(val, 3, 6, CCIPR5_REG) +#define FDCAN_SEL(val) STM32_CLOCK(val, 3, 8, CCIPR5_REG) +#define SAI1_SEL(val) STM32_CLOCK(val, 7, 16, CCIPR5_REG) +#define SAI2_SEL(val) STM32_CLOCK(val, 7, 19, CCIPR5_REG) +#define CKPER_SEL(val) STM32_CLOCK(val, 3, 30, CCIPR5_REG) + +/** BDCR devices */ +#define RTC_SEL(val) STM32_CLOCK(val, 3, 8, BDCR_REG) + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_STM32H5_CLOCK_H_ */ From 806cfbf3656604cb24e8e956ba51deb879e5fa3b Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Wed, 14 Dec 2022 14:08:30 +0100 Subject: [PATCH 0842/1906] include: bindings: reset definition for the new stm32h5 serie Defines the RCC reset registers for the stm32h5cx devices Note that all stm32h5x do not have all the bus registers. Signed-off-by: Francois Ramu --- .../zephyr/dt-bindings/reset/stm32h5_reset.h | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 include/zephyr/dt-bindings/reset/stm32h5_reset.h diff --git a/include/zephyr/dt-bindings/reset/stm32h5_reset.h b/include/zephyr/dt-bindings/reset/stm32h5_reset.h new file mode 100644 index 000000000000..117bad3b55dd --- /dev/null +++ b/include/zephyr/dt-bindings/reset/stm32h5_reset.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_RESET_STM32H5_RESET_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_RESET_STM32H5_RESET_H_ + +#include "stm32-common.h" + +/* RCC bus reset register offset */ +#define STM32_RESET_BUS_AHB1 0x60 +#define STM32_RESET_BUS_AHB2 0x64 +#define STM32_RESET_BUS_AHB4 0x6C +#define STM32_RESET_BUS_APB1L 0x74 +#define STM32_RESET_BUS_APB1H 0x78 +#define STM32_RESET_BUS_APB2 0x7C +#define STM32_RESET_BUS_APB3 0x80 + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_RESET_STM32H5_RESET_H_ */ From 4a6a703f0f97c3e769c8b404cda7b54085d4e032 Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Fri, 2 Dec 2022 11:40:03 +0100 Subject: [PATCH 0843/1906] drivers: clock control for the new stm32h5 serie Add the driver for the clock control of the new stm32h5. See the corresponding Ref Man to get the clock scheme : HSI, CSI, HSI48, HSE, LSE, and 2 or 3 PLLs Signed-off-by: Francois Ramu --- drivers/clock_control/CMakeLists.txt | 2 + drivers/clock_control/clock_stm32_ll_h5.c | 759 ++++++++++++++++++++++ 2 files changed, 761 insertions(+) create mode 100644 drivers/clock_control/clock_stm32_ll_h5.c diff --git a/drivers/clock_control/CMakeLists.txt b/drivers/clock_control/CMakeLists.txt index 857a62e52e29..209fb9fdaba5 100644 --- a/drivers/clock_control/CMakeLists.txt +++ b/drivers/clock_control/CMakeLists.txt @@ -30,6 +30,8 @@ if(CONFIG_SOC_SERIES_STM32MP1X) zephyr_library_sources(clock_stm32_ll_mp1.c) elseif(CONFIG_SOC_SERIES_STM32H7X) zephyr_library_sources(clock_stm32_ll_h7.c) +elseif(CONFIG_SOC_SERIES_STM32H5X) + zephyr_library_sources(clock_stm32_ll_h5.c) elseif(CONFIG_SOC_SERIES_STM32U5X) zephyr_library_sources(clock_stm32_ll_u5.c) else() diff --git a/drivers/clock_control/clock_stm32_ll_h5.c b/drivers/clock_control/clock_stm32_ll_h5.c new file mode 100644 index 000000000000..6fffa8ee3f0f --- /dev/null +++ b/drivers/clock_control/clock_stm32_ll_h5.c @@ -0,0 +1,759 @@ +/* + * + * Copyright (c) 2021 Linaro Limited + * Copyright (c) 2022 Thomas Stranger + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Macros to fill up prescaler values */ +#define z_ahb_prescaler(v) LL_RCC_SYSCLK_DIV_ ## v +#define ahb_prescaler(v) z_ahb_prescaler(v) + +#define z_apb1_prescaler(v) LL_RCC_APB1_DIV_ ## v +#define apb1_prescaler(v) z_apb1_prescaler(v) + +#define z_apb2_prescaler(v) LL_RCC_APB2_DIV_ ## v +#define apb2_prescaler(v) z_apb2_prescaler(v) + +#define z_apb3_prescaler(v) LL_RCC_APB3_DIV_ ## v +#define apb3_prescaler(v) z_apb3_prescaler(v) + +#define PLL1_ID 1 +#define PLL2_ID 2 +#define PLL3_ID 3 + +static uint32_t get_bus_clock(uint32_t clock, uint32_t prescaler) +{ + return clock / prescaler; +} + +__unused +/** @brief returns the pll source frequency of given pll_id */ +static uint32_t get_pllsrc_frequency(size_t pll_id) +{ + + if ((IS_ENABLED(STM32_PLL_SRC_HSI) && pll_id == PLL1_ID) || + (IS_ENABLED(STM32_PLL2_SRC_HSI) && pll_id == PLL2_ID) || + (IS_ENABLED(STM32_PLL3_SRC_HSI) && pll_id == PLL3_ID)) { + return STM32_HSI_FREQ; + } else if ((IS_ENABLED(STM32_PLL_SRC_HSE) && pll_id == PLL1_ID) || + (IS_ENABLED(STM32_PLL2_SRC_HSE) && pll_id == PLL2_ID) || + (IS_ENABLED(STM32_PLL3_SRC_HSE) && pll_id == PLL3_ID)) { + return STM32_HSE_FREQ; + } else if ((IS_ENABLED(STM32_PLL_SRC_CSI) && pll_id == PLL1_ID) || + (IS_ENABLED(STM32_PLL2_SRC_CSI) && pll_id == PLL2_ID) || + (IS_ENABLED(STM32_PLL3_SRC_CSI) && pll_id == PLL3_ID)) { + return STM32_CSI_FREQ; + } + + __ASSERT(0, "No PLL Source configured"); + return 0; +} + +static uint32_t get_startup_frequency(void) +{ + switch (LL_RCC_GetSysClkSource()) { + case LL_RCC_SYS_CLKSOURCE_STATUS_CSI: + return STM32_CSI_FREQ; + case LL_RCC_SYS_CLKSOURCE_STATUS_HSI: + return STM32_HSI_FREQ; + default: + __ASSERT(0, "Unexpected startup freq"); + return 0; + } +} + +__unused +static uint32_t get_pllout_frequency(uint32_t pllsrc_freq, + int pllm_div, + int plln_mul, + int pllout_div) +{ + __ASSERT_NO_MSG(pllm_div && pllout_div); + + return (pllsrc_freq / pllm_div) * plln_mul / pllout_div; +} + +static uint32_t get_sysclk_frequency(void) +{ +#if defined(STM32_SYSCLK_SRC_PLL) + return get_pllout_frequency(get_pllsrc_frequency(PLL1_ID), + STM32_PLL_M_DIVISOR, + STM32_PLL_N_MULTIPLIER, + STM32_PLL_R_DIVISOR); +#elif defined(STM32_SYSCLK_SRC_CSI) + return STM32_CSI_FREQ; +#elif defined(STM32_SYSCLK_SRC_HSE) + return STM32_HSE_FREQ; +#elif defined(STM32_SYSCLK_SRC_HSI) + return STM32_HSI_FREQ; +#else + __ASSERT(0, "No SYSCLK Source configured"); + return 0; +#endif + +} + +/** @brief Verifies clock is part of active clock configuration */ +static int enabled_clock(uint32_t src_clk) +{ + if ((src_clk == STM32_SRC_SYSCLK) || + ((src_clk == STM32_SRC_HSE) && IS_ENABLED(STM32_HSE_ENABLED)) || + ((src_clk == STM32_SRC_HSI) && IS_ENABLED(STM32_HSI_ENABLED)) || + ((src_clk == STM32_SRC_HSI48) && IS_ENABLED(STM32_HSI48_ENABLED)) || + ((src_clk == STM32_SRC_LSE) && IS_ENABLED(STM32_LSE_ENABLED)) || + ((src_clk == STM32_SRC_LSI) && IS_ENABLED(STM32_LSI_ENABLED)) || + ((src_clk == STM32_SRC_CSI) && IS_ENABLED(STM32_CSI_ENABLED)) || + ((src_clk == STM32_SRC_PLL1_P) && IS_ENABLED(STM32_PLL_P_ENABLED)) || + ((src_clk == STM32_SRC_PLL1_Q) && IS_ENABLED(STM32_PLL_Q_ENABLED)) || + ((src_clk == STM32_SRC_PLL1_R) && IS_ENABLED(STM32_PLL_R_ENABLED)) || + ((src_clk == STM32_SRC_PLL2_P) && IS_ENABLED(STM32_PLL2_P_ENABLED)) || + ((src_clk == STM32_SRC_PLL2_Q) && IS_ENABLED(STM32_PLL2_Q_ENABLED)) || + ((src_clk == STM32_SRC_PLL2_R) && IS_ENABLED(STM32_PLL2_R_ENABLED)) || + ((src_clk == STM32_SRC_PLL3_P) && IS_ENABLED(STM32_PLL3_P_ENABLED)) || + ((src_clk == STM32_SRC_PLL3_Q) && IS_ENABLED(STM32_PLL3_Q_ENABLED)) || + ((src_clk == STM32_SRC_PLL3_R) && IS_ENABLED(STM32_PLL3_R_ENABLED))) { + return 0; + } + + return -ENOTSUP; +} + +static inline int stm32_clock_control_on(const struct device *dev, + clock_control_subsys_t sub_system) +{ + struct stm32_pclken *pclken = (struct stm32_pclken *)(sub_system); + + ARG_UNUSED(dev); + + if (IN_RANGE(pclken->bus, STM32_PERIPH_BUS_MIN, STM32_PERIPH_BUS_MAX) == 0) { + /* Attemp to toggle a wrong periph clock bit */ + return -ENOTSUP; + } + + sys_set_bits(DT_REG_ADDR(DT_NODELABEL(rcc)) + pclken->bus, + pclken->enr); + + return 0; +} + +static inline int stm32_clock_control_off(const struct device *dev, + clock_control_subsys_t sub_system) +{ + struct stm32_pclken *pclken = (struct stm32_pclken *)(sub_system); + + ARG_UNUSED(dev); + + if (IN_RANGE(pclken->bus, STM32_PERIPH_BUS_MIN, STM32_PERIPH_BUS_MAX) == 0) { + /* Attemp to toggle a wrong periph clock bit */ + return -ENOTSUP; + } + + sys_clear_bits(DT_REG_ADDR(DT_NODELABEL(rcc)) + pclken->bus, + pclken->enr); + + return 0; +} + +static inline int stm32_clock_control_configure(const struct device *dev, + clock_control_subsys_t sub_system, + void *data) +{ + struct stm32_pclken *pclken = (struct stm32_pclken *)(sub_system); + int err; + + ARG_UNUSED(dev); + ARG_UNUSED(data); + + err = enabled_clock(pclken->bus); + if (err < 0) { + /* Attempt to configure a src clock not available or not valid */ + return err; + } + + sys_set_bits(DT_REG_ADDR(DT_NODELABEL(rcc)) + STM32_CLOCK_REG_GET(pclken->enr), + STM32_CLOCK_VAL_GET(pclken->enr) << STM32_CLOCK_SHIFT_GET(pclken->enr)); + + return 0; +} + +static int stm32_clock_control_get_subsys_rate(const struct device *dev, + clock_control_subsys_t sys, + uint32_t *rate) +{ + struct stm32_pclken *pclken = (struct stm32_pclken *)(sys); + + /* + * Get AHB Clock (= SystemCoreClock = SYSCLK/prescaler) + * SystemCoreClock is preferred to CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC + * since it will be updated after clock configuration and hence + * more likely to contain actual clock speed + */ + uint32_t ahb_clock = SystemCoreClock; + uint32_t apb1_clock = get_bus_clock(ahb_clock, STM32_APB1_PRESCALER); + uint32_t apb2_clock = get_bus_clock(ahb_clock, STM32_APB2_PRESCALER); + uint32_t apb3_clock = get_bus_clock(ahb_clock, STM32_APB3_PRESCALER); + + ARG_UNUSED(dev); + + switch (pclken->bus) { + case STM32_CLOCK_BUS_AHB1: + case STM32_CLOCK_BUS_AHB2: + case STM32_CLOCK_BUS_AHB4: + *rate = ahb_clock; + break; + case STM32_CLOCK_BUS_APB1: + case STM32_CLOCK_BUS_APB1_2: + *rate = apb1_clock; + break; + case STM32_CLOCK_BUS_APB2: + *rate = apb2_clock; + break; + case STM32_CLOCK_BUS_APB3: + *rate = apb3_clock; + break; + case STM32_SRC_SYSCLK: + *rate = get_sysclk_frequency(); + break; +#if defined(STM32_HSI_ENABLED) + case STM32_SRC_HSI: + *rate = STM32_HSI_FREQ; + break; +#endif /* STM32_HSI_ENABLED */ +#if defined(STM32_CSI_ENABLED) + case STM32_SRC_CSI: + *rate = STM32_CSI_FREQ; + break; +#endif /* STM32_MSIS_ENABLED */ +#if defined(STM32_HSE_ENABLED) + case STM32_SRC_HSE: + *rate = STM32_HSE_FREQ; + break; +#endif /* STM32_HSE_ENABLED */ +#if defined(STM32_LSE_ENABLED) + case STM32_SRC_LSE: + *rate = STM32_LSE_FREQ; + break; +#endif /* STM32_LSE_ENABLED */ +#if defined(STM32_LSI_ENABLED) + case STM32_SRC_LSI: + *rate = STM32_LSI_FREQ; + break; +#endif /* STM32_LSI_ENABLED */ +#if defined(STM32_HSI48_ENABLED) + case STM32_SRC_HSI48: + *rate = STM32_HSI48_FREQ; + break; +#endif /* STM32_HSI48_ENABLED */ +#if defined(STM32_PLL_ENABLED) + case STM32_SRC_PLL1_P: + *rate = get_pllout_frequency(get_pllsrc_frequency(PLL1_ID), + STM32_PLL_M_DIVISOR, + STM32_PLL_N_MULTIPLIER, + STM32_PLL_P_DIVISOR); + break; + case STM32_SRC_PLL1_Q: + *rate = get_pllout_frequency(get_pllsrc_frequency(PLL1_ID), + STM32_PLL_M_DIVISOR, + STM32_PLL_N_MULTIPLIER, + STM32_PLL_Q_DIVISOR); + break; + case STM32_SRC_PLL1_R: + *rate = get_pllout_frequency(get_pllsrc_frequency(PLL1_ID), + STM32_PLL_M_DIVISOR, + STM32_PLL_N_MULTIPLIER, + STM32_PLL_R_DIVISOR); + break; +#endif /* STM32_PLL_ENABLED */ +#if defined(STM32_PLL2_ENABLED) + case STM32_SRC_PLL2_P: + *rate = get_pllout_frequency(get_pllsrc_frequency(PLL2_ID), + STM32_PLL2_M_DIVISOR, + STM32_PLL2_N_MULTIPLIER, + STM32_PLL2_P_DIVISOR); + break; + case STM32_SRC_PLL2_Q: + *rate = get_pllout_frequency(get_pllsrc_frequency(PLL2_ID), + STM32_PLL2_M_DIVISOR, + STM32_PLL2_N_MULTIPLIER, + STM32_PLL2_Q_DIVISOR); + break; + case STM32_SRC_PLL2_R: + *rate = get_pllout_frequency(get_pllsrc_frequency(PLL2_ID), + STM32_PLL2_M_DIVISOR, + STM32_PLL2_N_MULTIPLIER, + STM32_PLL2_R_DIVISOR); + break; +#endif /* STM32_PLL2_ENABLED */ +#if defined(STM32_PLL3_ENABLED) + case STM32_SRC_PLL3_P: + *rate = get_pllout_frequency(get_pllsrc_frequency(PLL3_ID), + STM32_PLL3_M_DIVISOR, + STM32_PLL3_N_MULTIPLIER, + STM32_PLL3_P_DIVISOR); + break; + case STM32_SRC_PLL3_Q: + *rate = get_pllout_frequency(get_pllsrc_frequency(PLL3_ID), + STM32_PLL3_M_DIVISOR, + STM32_PLL3_N_MULTIPLIER, + STM32_PLL3_Q_DIVISOR); + break; + case STM32_SRC_PLL3_R: + *rate = get_pllout_frequency(get_pllsrc_frequency(PLL3_ID), + STM32_PLL3_M_DIVISOR, + STM32_PLL3_N_MULTIPLIER, + STM32_PLL3_R_DIVISOR); + break; +#endif /* STM32_PLL3_ENABLED */ + default: + return -ENOTSUP; + } + + return 0; +} + +static struct clock_control_driver_api stm32_clock_control_api = { + .on = stm32_clock_control_on, + .off = stm32_clock_control_off, + .get_rate = stm32_clock_control_get_subsys_rate, + .configure = stm32_clock_control_configure, +}; + +__unused +static int get_vco_input_range(uint32_t m_div, uint32_t *range, size_t pll_id) +{ + uint32_t vco_freq; + + vco_freq = get_pllsrc_frequency(pll_id) / m_div; + + if (MHZ(4) <= vco_freq && vco_freq <= MHZ(8)) { + *range = LL_RCC_PLLINPUTRANGE_4_8; + } else if (MHZ(8) < vco_freq && vco_freq <= MHZ(16)) { + *range = LL_RCC_PLLINPUTRANGE_8_16; + } else { + return -ERANGE; + } + + return 0; +} + + +__unused +static uint32_t get_vco_output_range(uint32_t vco_input_range) +{ + if (vco_input_range == LL_RCC_PLLINPUTRANGE_1_2) { + return LL_RCC_PLLVCORANGE_MEDIUM; + } + + return LL_RCC_PLLVCORANGE_WIDE; +} + +static void set_regu_voltage(uint32_t hclk_freq) +{ + if (hclk_freq < MHZ(80)) { + LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE3); + } else if (hclk_freq < MHZ(130)) { + LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE2); + } else if (hclk_freq < MHZ(180)) { + LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1); + } else { + LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE0); + } + while (LL_PWR_IsActiveFlag_VOS() == 0) { + } +} + +__unused +static void clock_switch_to_hsi(void) +{ + /* Enable HSI if not enabled */ + if (LL_RCC_HSI_IsReady() != 1) { + /* Enable HSI */ + LL_RCC_HSI_Enable(); + while (LL_RCC_HSI_IsReady() != 1) { + /* Wait for HSI ready */ + } + } + + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + + /* Set HSI as SYSCLCK source */ + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI); + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI) { + } +} + +__unused +static int set_up_plls(void) +{ +#if defined(STM32_PLL_ENABLED) || defined(STM32_PLL2_ENABLED) || \ + defined(STM32_PLL3_ENABLED) + int r; + uint32_t vco_input_range; + uint32_t vco_output_range; +#endif + +#if defined(STM32_PLL_ENABLED) + /* + * Switch to HSI and disable the PLL before configuration. + * (Switching to HSI makes sure we have a SYSCLK source in + * case we're currently running from the PLL we're about to + * turn off and reconfigure.) + */ + if (LL_RCC_GetSysClkSource() == LL_RCC_SYS_CLKSOURCE_STATUS_PLL1) { + clock_switch_to_hsi(); + } + + LL_RCC_PLL1_Disable(); + + /* Configure PLL source : Can be HSE, HSI, MSIS */ + if (IS_ENABLED(STM32_PLL_SRC_HSE)) { + /* Main PLL configuration and activation */ + LL_RCC_PLL1_SetSource(LL_RCC_PLL1SOURCE_HSE); + } else if (IS_ENABLED(STM32_PLL_SRC_CSI)) { + /* Main PLL configuration and activation */ + LL_RCC_PLL1_SetSource(LL_RCC_PLL1SOURCE_CSI); + } else if (IS_ENABLED(STM32_PLL_SRC_HSI)) { + /* Main PLL configuration and activation */ + LL_RCC_PLL1_SetSource(LL_RCC_PLL1SOURCE_HSI); + } else { + return -ENOTSUP; + } + + r = get_vco_input_range(STM32_PLL_M_DIVISOR, &vco_input_range, PLL1_ID); + if (r < 0) { + return r; + } + + vco_output_range = get_vco_output_range(vco_input_range); + + LL_RCC_PLL1_SetM(STM32_PLL_M_DIVISOR); + + /* Set VCO Input before enabling the PLL, depends on the freq of the PLL1 */ + LL_RCC_PLL1_SetVCOInputRange(vco_input_range); + /* Select VCO freq range before enabling the PLL, depends on the freq of the PLL1 */ + LL_RCC_PLL1_SetVCOOutputRange(vco_output_range); + + LL_RCC_PLL1_SetN(STM32_PLL_N_MULTIPLIER); + + LL_RCC_PLL1FRACN_Disable(); + + if (IS_ENABLED(STM32_PLL_P_ENABLED)) { + LL_RCC_PLL1_SetP(STM32_PLL_P_DIVISOR); + LL_RCC_PLL1P_Enable(); + } + + if (IS_ENABLED(STM32_PLL_Q_ENABLED)) { + LL_RCC_PLL1_SetQ(STM32_PLL_Q_DIVISOR); + LL_RCC_PLL1Q_Enable(); + } + + if (IS_ENABLED(STM32_PLL_R_ENABLED)) { + LL_RCC_PLL1_SetR(STM32_PLL_R_DIVISOR); + LL_RCC_PLL1R_Enable(); + } + + LL_RCC_PLL1_Enable(); + while (LL_RCC_PLL1_IsReady() != 1U) { + } +#else + /* Init PLL source to None */ + LL_RCC_PLL1_SetSource(LL_RCC_PLL1SOURCE_NONE); +#endif /* STM32_PLL_ENABLED */ + +#if defined(STM32_PLL2_ENABLED) + /* Configure PLL2 source */ + if (IS_ENABLED(STM32_PLL2_SRC_HSE)) { + LL_RCC_PLL2_SetSource(LL_RCC_PLL2SOURCE_HSE); + } else if (IS_ENABLED(STM32_PLL2_SRC_CSI)) { + LL_RCC_PLL2_SetSource(LL_RCC_PLL2SOURCE_CSI); + } else if (IS_ENABLED(STM32_PLL2_SRC_HSI)) { + LL_RCC_PLL2_SetSource(LL_RCC_PLL2SOURCE_HSI); + } else { + return -ENOTSUP; + } + + r = get_vco_input_range(STM32_PLL2_M_DIVISOR, &vco_input_range, PLL2_ID); + if (r < 0) { + return r; + } + + vco_output_range = get_vco_output_range(vco_input_range); + + LL_RCC_PLL2_SetM(STM32_PLL2_M_DIVISOR); + + /* Set VCO Input before enabling the PLL, depends on the freq of the PLL2 */ + LL_RCC_PLL2_SetVCOInputRange(vco_input_range); + /* Select VCO freq range before enabling the PLL, depends on the freq of the PLL2 */ + LL_RCC_PLL2_SetVCOOutputRange(vco_output_range); + + LL_RCC_PLL2_SetN(STM32_PLL2_N_MULTIPLIER); + + LL_RCC_PLL2FRACN_Disable(); + + if (IS_ENABLED(STM32_PLL2_P_ENABLED)) { + LL_RCC_PLL2_SetP(STM32_PLL2_P_DIVISOR); + LL_RCC_PLL2P_Enable(); + } + + if (IS_ENABLED(STM32_PLL2_Q_ENABLED)) { + LL_RCC_PLL2_SetQ(STM32_PLL2_Q_DIVISOR); + LL_RCC_PLL2Q_Enable(); + } + + if (IS_ENABLED(STM32_PLL2_R_ENABLED)) { + LL_RCC_PLL2_SetR(STM32_PLL2_R_DIVISOR); + LL_RCC_PLL2R_Enable(); + } + + LL_RCC_PLL2_Enable(); + while (LL_RCC_PLL2_IsReady() != 1U) { + } +#else + /* Init PLL2 source to None */ + LL_RCC_PLL2_SetSource(LL_RCC_PLL2SOURCE_NONE); +#endif /* STM32_PLL2_ENABLED */ + +#if defined(RCC_CR_PLL3ON) +#if defined(STM32_PLL3_ENABLED) + /* Configure PLL3 source */ + if (IS_ENABLED(STM32_PLL3_SRC_HSE)) { + LL_RCC_PLL3_SetSource(LL_RCC_PLL3SOURCE_HSE); + } else if (IS_ENABLED(STM32_PLL3_SRC_CSI)) { + LL_RCC_PLL3_SetSource(LL_RCC_PLL3SOURCE_CSI); + } else if (IS_ENABLED(STM32_PLL3_SRC_HSI)) { + LL_RCC_PLL3_SetSource(LL_RCC_PLL3SOURCE_HSI); + } else { + return -ENOTSUP; + } + + r = get_vco_input_range(STM32_PLL3_M_DIVISOR, &vco_input_range, PLL3_ID); + if (r < 0) { + return r; + } + + vco_output_range = get_vco_output_range(vco_input_range); + + LL_RCC_PLL3_SetM(STM32_PLL3_M_DIVISOR); + + /* Set VCO Input before enabling the PLL, depends on the freq of the PLL3 */ + LL_RCC_PLL3_SetVCOInputRange(vco_input_range); + /* Select VCO freq range before enabling the PLL, depends on the freq of the PLL3 */ + LL_RCC_PLL3_SetVCOOutputRange(vco_output_range); + + LL_RCC_PLL3_SetN(STM32_PLL3_N_MULTIPLIER); + + LL_RCC_PLL3FRACN_Disable(); + + if (IS_ENABLED(STM32_PLL3_P_ENABLED)) { + LL_RCC_PLL3_SetP(STM32_PLL3_P_DIVISOR); + LL_RCC_PLL3P_Enable(); + } + + if (IS_ENABLED(STM32_PLL3_Q_ENABLED)) { + LL_RCC_PLL3_SetQ(STM32_PLL3_Q_DIVISOR); + LL_RCC_PLL3Q_Enable(); + } + + if (IS_ENABLED(STM32_PLL3_R_ENABLED)) { + LL_RCC_PLL3_SetR(STM32_PLL3_R_DIVISOR); + LL_RCC_PLL3R_Enable(); + } + + LL_RCC_PLL3_Enable(); + while (LL_RCC_PLL3_IsReady() != 1U) { + } +#else + /* Init PLL3 source to None */ + LL_RCC_PLL3_SetSource(LL_RCC_PLL3SOURCE_NONE); +#endif /* STM32_PLL3_ENABLED */ +#endif /* (RCC_CR_PLL3ON) */ + + return 0; +} + +static void set_up_fixed_clock_sources(void) +{ + + if (IS_ENABLED(STM32_HSE_ENABLED)) { + /* Check if need to enable HSE bypass feature or not */ + if (IS_ENABLED(STM32_HSE_BYPASS)) { + LL_RCC_HSE_EnableBypass(); + } else { + LL_RCC_HSE_DisableBypass(); + } + + /* Enable HSE */ + LL_RCC_HSE_Enable(); + while (LL_RCC_HSE_IsReady() != 1) { + /* Wait for HSE ready */ + } + } + + if (IS_ENABLED(STM32_HSI_ENABLED)) { + if (IS_ENABLED(STM32_PLL_SRC_HSI) || + IS_ENABLED(STM32_PLL2_SRC_HSI) || IS_ENABLED(STM32_PLL3_SRC_HSI)) { + /* HSI calibration */ + LL_RCC_HSI_SetCalibTrimming(RCC_HSICALIBRATION_DEFAULT); + } + /* Enable HSI if not enabled */ + if (LL_RCC_HSI_IsReady() != 1) { + /* Enable HSI */ + LL_RCC_HSI_Enable(); + while (LL_RCC_HSI_IsReady() != 1) { + /* Wait for HSI ready */ + } + } + } + + if (IS_ENABLED(STM32_LSE_ENABLED)) { + if (!LL_PWR_IsEnabledBkUpAccess()) { + /* Enable write access to Backup domain */ + LL_PWR_EnableBkUpAccess(); + while (!LL_PWR_IsEnabledBkUpAccess()) { + /* Wait for Backup domain access */ + } + } + + /* Configure driving capability before enabling the LSE oscillator */ + LL_RCC_LSE_SetDriveCapability(STM32_LSE_DRIVING << RCC_BDCR_LSEDRV_Pos); + + if (IS_ENABLED(STM32_LSE_BYPASS)) { + /* Configure LSE bypass */ + LL_RCC_LSE_EnableBypass(); + } + + /* Enable LSE Oscillator */ + LL_RCC_LSE_Enable(); + /* Wait for LSE ready */ + while (!LL_RCC_LSE_IsReady()) { + } + + LL_PWR_DisableBkUpAccess(); + } + + if (IS_ENABLED(STM32_CSI_ENABLED)) { + if (IS_ENABLED(STM32_PLL_SRC_CSI) || + IS_ENABLED(STM32_PLL2_SRC_CSI) || IS_ENABLED(STM32_PLL3_SRC_CSI)) { + /* CSI calibration */ + LL_RCC_CSI_SetCalibTrimming(RCC_CSICALIBRATION_DEFAULT); + } + + /* Enable CSI */ + LL_RCC_CSI_Enable(); + + /* Wait till CSI is ready */ + while (LL_RCC_CSI_IsReady() != 1) { + } + } + + if (IS_ENABLED(STM32_LSI_ENABLED)) { + /* Enable LSI oscillator */ + LL_RCC_LSI_Enable(); + while (LL_RCC_LSI_IsReady() != 1) { + } + } + + if (IS_ENABLED(STM32_HSI48_ENABLED)) { + LL_RCC_HSI48_Enable(); + while (LL_RCC_HSI48_IsReady() != 1) { + } + } + +} + +int stm32_clock_control_init(const struct device *dev) +{ + uint32_t old_hclk_freq = 0; + int r = 0; + + ARG_UNUSED(dev); + + /* Current hclk value */ + old_hclk_freq = __LL_RCC_CALC_HCLK_FREQ(get_startup_frequency(), LL_RCC_GetAHBPrescaler()); + + /* Set voltage regulator to comply with targeted system frequency */ + set_regu_voltage(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC); + + /* Set flash latency */ + /* If freq increases, set flash latency before any clock setting */ + if (old_hclk_freq < CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC) { + LL_SetFlashLatency(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC); + } + + /* Set up individual enabled clocks */ + set_up_fixed_clock_sources(); + + /* Set up PLLs */ + r = set_up_plls(); + if (r < 0) { + return r; + } + + /* Set peripheral busses prescalers */ + LL_RCC_SetAHBPrescaler(ahb_prescaler(STM32_AHB_PRESCALER)); + LL_RCC_SetAPB1Prescaler(apb1_prescaler(STM32_APB1_PRESCALER)); + LL_RCC_SetAPB2Prescaler(apb2_prescaler(STM32_APB2_PRESCALER)); + LL_RCC_SetAPB3Prescaler(apb3_prescaler(STM32_APB3_PRESCALER)); + + if (IS_ENABLED(STM32_SYSCLK_SRC_PLL)) { + /* Set PLL1 as System Clock Source */ + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL1); + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL1) { + } + } else if (IS_ENABLED(STM32_SYSCLK_SRC_HSE)) { + /* Set HSE as SYSCLCK source */ + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSE); + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSE) { + } + } else if (IS_ENABLED(STM32_SYSCLK_SRC_CSI)) { + /* Set CSI as SYSCLCK source */ + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_CSI); + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_CSI) { + } + } else if (IS_ENABLED(STM32_SYSCLK_SRC_HSI)) { + /* Set HSI as SYSCLCK source */ + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI); + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI) { + } + } else { + return -ENOTSUP; + } + + /* Set FLASH latency */ + /* If freq not increased, set flash latency after all clock setting */ + if (old_hclk_freq >= CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC) { + LL_SetFlashLatency(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC); + } + + /* Update CMSIS variable */ + SystemCoreClock = CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC; + + return 0; +} + +/** + * @brief RCC device, note that priority is intentionally set to 1 so + * that the device init runs just after SOC init + */ +DEVICE_DT_DEFINE(DT_NODELABEL(rcc), + &stm32_clock_control_init, + NULL, + NULL, NULL, + PRE_KERNEL_1, + CONFIG_CLOCK_CONTROL_INIT_PRIORITY, + &stm32_clock_control_api); From a62fc404be36b3b15d0a76be11bf21d36b7e45b6 Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Wed, 22 Mar 2023 10:26:30 +0100 Subject: [PATCH 0844/1906] drivers: flash: stm32 flash drivers supports the new stm32h5 serie Introduce the stm32h5 serie to the the existing flash driver It is based on the stm32l5 model. Add a function to check if the flash is in dual or single bank mode. Some stm32 devices can map 2 or 1 flash banks. Adapt the FLASH register names for the stm32h5 mcu. Signed-off-by: Francois Ramu --- drivers/flash/flash_stm32.c | 2 +- drivers/flash/flash_stm32.h | 27 +++++++++++++++++++++++++++ drivers/flash/flash_stm32l5x.c | 30 +++++++++++++++++++++--------- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/drivers/flash/flash_stm32.c b/drivers/flash/flash_stm32.c index 28ba84692e60..c131a750e2df 100644 --- a/drivers/flash/flash_stm32.c +++ b/drivers/flash/flash_stm32.c @@ -126,7 +126,7 @@ static void flash_stm32_flush_caches(const struct device *dev, { #if defined(CONFIG_SOC_SERIES_STM32F0X) || defined(CONFIG_SOC_SERIES_STM32F3X) || \ defined(CONFIG_SOC_SERIES_STM32G0X) || defined(CONFIG_SOC_SERIES_STM32L5X) || \ - defined(CONFIG_SOC_SERIES_STM32U5X) + defined(CONFIG_SOC_SERIES_STM32U5X) || defined(CONFIG_SOC_SERIES_STM32H5X) ARG_UNUSED(dev); ARG_UNUSED(offset); ARG_UNUSED(len); diff --git a/drivers/flash/flash_stm32.h b/drivers/flash/flash_stm32.h index a503d80d22d4..3fd5de0e94c2 100644 --- a/drivers/flash/flash_stm32.h +++ b/drivers/flash/flash_stm32.h @@ -33,6 +33,12 @@ struct flash_stm32_priv { /* as flash node property 'write-block-size' */ #endif +#if defined(CONFIG_SOC_SERIES_STM32H5X) +/* FLASH register names differ for this serie */ +#define FLASH_NSSR_BSY FLASH_SR_BSY +#define OPTR OPTCR +#endif /* CONFIG_SOC_SERIES_STM32H5X */ + /* Differentiate between arm trust-zone non-secure/secure, and others. */ #if defined(FLASH_NSSR_NSBSY) || defined(FLASH_NSSR_BSY) /* For mcu w. TZ in non-secure mode */ #define FLASH_SECURITY_NS @@ -65,6 +71,27 @@ struct flash_stm32_priv { #define FLASH_STM32_NSPNB FLASH_NSCR_PNB #define FLASH_STM32_NSSTRT FLASH_NSCR_STRT #define FLASH_PAGE_SIZE_128_BITS FLASH_PAGE_SIZE +#elif defined(CONFIG_SOC_SERIES_STM32H5X) +#define FLASH_OPTR_SWAP_BANK FLASH_OPTCR_SWAP_BANK +#define FLASH_STM32_NSLOCK FLASH_CR_LOCK +#define FLASH_STM32_DBANK 1 +#define FLASH_STM32_NSPG FLASH_CR_PG +#define FLASH_STM32_NSBKER_MSK FLASH_CR_BKSEL_Msk +#define FLASH_STM32_NSBKER FLASH_CR_BKSEL +#define FLASH_STM32_NSPER FLASH_CR_SER +#define FLASH_STM32_NSPNB_MSK FLASH_CR_SNB_Msk +#define FLASH_STM32_NSPNB_POS FLASH_CR_SNB_Pos +#define FLASH_STM32_NSPNB FLASH_CR_PNB +#define FLASH_STM32_NSSTRT FLASH_CR_START +/* TODO: get values from the cmsis and stm32h5_hal_flash.h */ +#undef FLASH_SIZE +/* Retrieve the FLASH SIZE from the DTS instead of cmsis as it seems erroneous */ +#define FLASH_SIZE (CONFIG_FLASH_SIZE * 1024) +/* Values are redefined below from the stm32h5_hal_flash.h */ +#define FLASH_PAGE_SIZE (FLASH_SECTOR_SIZE) +#define FLASH_PAGE_NB (FLASH_SECTOR_NB) +#define FLASH_PAGE_NB_PER_BANK (FLASH_BANK_SIZE / FLASH_PAGE_SIZE) +#define FLASH_PAGE_SIZE_128_BITS FLASH_PAGE_SIZE #elif defined(CONFIG_SOC_SERIES_STM32L5X) #define FLASH_STM32_NSLOCK FLASH_NSCR_NSLOCK #define FLASH_STM32_NSPG FLASH_NSCR_NSPG diff --git a/drivers/flash/flash_stm32l5x.c b/drivers/flash/flash_stm32l5x.c index dacb270dbf93..a0b692b45c80 100644 --- a/drivers/flash/flash_stm32l5x.c +++ b/drivers/flash/flash_stm32l5x.c @@ -20,7 +20,10 @@ LOG_MODULE_REGISTER(LOG_DOMAIN); #include "flash_stm32.h" -#if defined(CONFIG_SOC_SERIES_STM32L5X) +#if defined(CONFIG_SOC_SERIES_STM32H5X) +/* at this time stm32h5 mcus have 128KB (stm32h50x) or 2MB (stm32h56x/57x) */ +#define STM32_SERIES_MAX_FLASH 2048 +#elif defined(CONFIG_SOC_SERIES_STM32L5X) #define STM32_SERIES_MAX_FLASH 512 #elif defined(CONFIG_SOC_SERIES_STM32U5X) /* at this time stm32u5 mcus have 1MB (stm32u575) or 2MB (stm32u585) */ @@ -114,6 +117,16 @@ static int icache_wait_for_invalidate_complete(void) return status; } +/* Macro to check if the flash is Dual bank or not */ +#if defined(CONFIG_SOC_SERIES_STM32H5X) +#define stm32_flash_has_2_banks(flash_device) true +#else +#define stm32_flash_has_2_banks(flash_device) \ + (((FLASH_STM32_REGS(flash_device)->OPTR & FLASH_STM32_DBANK) \ + == FLASH_STM32_DBANK) \ + ? (true) : (false)) +#endif /* CONFIG_SOC_SERIES_STM32H5X */ + /* * offset and len must be aligned on 8 for write, * positive and not beyond end of flash @@ -122,9 +135,7 @@ bool flash_stm32_valid_range(const struct device *dev, off_t offset, uint32_t len, bool write) { - FLASH_TypeDef *regs = FLASH_STM32_REGS(dev); - - if (((regs->OPTR & FLASH_STM32_DBANK) == FLASH_STM32_DBANK) && + if (stm32_flash_has_2_banks(dev) && (CONFIG_FLASH_SIZE < STM32_SERIES_MAX_FLASH)) { /* * In case of bank1/2 discontinuity, the range should not @@ -212,7 +223,7 @@ static int erase_page(const struct device *dev, unsigned int offset) return rc; } - if ((regs->OPTR & FLASH_STM32_DBANK) == FLASH_STM32_DBANK) { + if (stm32_flash_has_2_banks(dev)) { bool bank_swap; /* Check whether bank1/2 are swapped */ bank_swap = @@ -261,7 +272,7 @@ static int erase_page(const struct device *dev, unsigned int offset) /* Wait for the NSBSY bit */ rc = flash_stm32_wait_flash_idle(dev); - if ((regs->OPTR & FLASH_STM32_DBANK) == FLASH_STM32_DBANK) { + if (stm32_flash_has_2_banks(dev)) { regs->NSCR &= ~(FLASH_STM32_NSPER | FLASH_STM32_NSBKER); } else { regs->NSCR &= ~(FLASH_STM32_NSPER); @@ -356,7 +367,6 @@ void flash_stm32_page_layout(const struct device *dev, const struct flash_pages_layout **layout, size_t *layout_size) { - FLASH_TypeDef *regs = FLASH_STM32_REGS(dev); static struct flash_pages_layout stm32_flash_layout[3]; static size_t stm32_flash_layout_size; @@ -368,7 +378,7 @@ void flash_stm32_page_layout(const struct device *dev, return; } - if (((regs->OPTR & FLASH_STM32_DBANK) == FLASH_STM32_DBANK) && + if (stm32_flash_has_2_banks(dev) && (CONFIG_FLASH_SIZE < STM32_SERIES_MAX_FLASH)) { /* * For stm32l552xx with 256 kB flash or stm32u57x with 1MB flash @@ -395,9 +405,11 @@ void flash_stm32_page_layout(const struct device *dev, * with 2MB flash which has no space between banks 1 and 2. */ - if ((regs->OPTR & FLASH_STM32_DBANK) == FLASH_STM32_DBANK) { + if (stm32_flash_has_2_banks(dev)) { /* L5 flash with dualbank has 2k pages */ /* U5 flash pages are always 8 kB in size */ + /* H5 flash pages are always 8 kB in size */ + /* Considering one layout of full flash size, even with 2 banks */ stm32_flash_layout[0].pages_count = FLASH_SIZE / FLASH_PAGE_SIZE; stm32_flash_layout[0].pages_size = FLASH_PAGE_SIZE; #if defined(CONFIG_SOC_SERIES_STM32L5X) From 1f23bd7cf7edc85a840287aaf17ca04f80c69cfc Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Wed, 30 Nov 2022 15:14:59 +0100 Subject: [PATCH 0845/1906] boards: arm: stm32h573i_dk new discovery kit for the stm32h5 device Introduce the stm32h573i_dk for the stm32h573 device from STMicrolectronics. Set the pll at 240MHz sourced by HSE oscillator (25MHz). Enabling a Minimum set of peripherals. Signed-off-by: Francois Ramu --- boards/arm/stm32h573i_dk/Kconfig.board | 10 + boards/arm/stm32h573i_dk/Kconfig.defconfig | 13 + .../stm32h573i_dk/arduino_r3_connector.dtsi | 36 +++ .../stm32h573i_dk/doc/img/stm32h573i_dk.jpg | Bin 0 -> 79132 bytes boards/arm/stm32h573i_dk/doc/index.rst | 293 ++++++++++++++++++ boards/arm/stm32h573i_dk/stm32h573i_dk.dts | 119 +++++++ boards/arm/stm32h573i_dk/stm32h573i_dk.yaml | 12 + .../arm/stm32h573i_dk/stm32h573i_dk_defconfig | 26 ++ 8 files changed, 509 insertions(+) create mode 100644 boards/arm/stm32h573i_dk/Kconfig.board create mode 100644 boards/arm/stm32h573i_dk/Kconfig.defconfig create mode 100644 boards/arm/stm32h573i_dk/arduino_r3_connector.dtsi create mode 100644 boards/arm/stm32h573i_dk/doc/img/stm32h573i_dk.jpg create mode 100644 boards/arm/stm32h573i_dk/doc/index.rst create mode 100644 boards/arm/stm32h573i_dk/stm32h573i_dk.dts create mode 100644 boards/arm/stm32h573i_dk/stm32h573i_dk.yaml create mode 100644 boards/arm/stm32h573i_dk/stm32h573i_dk_defconfig diff --git a/boards/arm/stm32h573i_dk/Kconfig.board b/boards/arm/stm32h573i_dk/Kconfig.board new file mode 100644 index 000000000000..adb46f393005 --- /dev/null +++ b/boards/arm/stm32h573i_dk/Kconfig.board @@ -0,0 +1,10 @@ +# STM32H573I-DK Discovery kit board configuration +# +# Copyright (c) 2023 STMicroelectronics +# +# SPDX-License-Identifier: Apache-2.0 +# + +config BOARD_STM32H573I_DK + bool "STM32H573I-DK Discovery Development Board" + depends on SOC_STM32H573XX diff --git a/boards/arm/stm32h573i_dk/Kconfig.defconfig b/boards/arm/stm32h573i_dk/Kconfig.defconfig new file mode 100644 index 000000000000..166ce9e13dd9 --- /dev/null +++ b/boards/arm/stm32h573i_dk/Kconfig.defconfig @@ -0,0 +1,13 @@ +# STM32H573I DISCOVERY KIT board configuration +# +# Copyright (c) 2023 STMicroelectronics +# +# SPDX-License-Identifier: Apache-2.0 +# + +if BOARD_STM32H573I_DK + +config BOARD + default "stm32h573i_dk" + +endif # BOARD_STM32H573I_DK diff --git a/boards/arm/stm32h573i_dk/arduino_r3_connector.dtsi b/boards/arm/stm32h573i_dk/arduino_r3_connector.dtsi new file mode 100644 index 000000000000..386d6ad603c0 --- /dev/null +++ b/boards/arm/stm32h573i_dk/arduino_r3_connector.dtsi @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 STMicroelectronics + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + arduino_header: connector { + compatible = "arduino-header-r3"; + #gpio-cells = <2>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0 0x3f>; + gpio-map = <0 0 &gpiob 0 0>, /* A0 */ + <1 0 &gpioa 4 0>, /* A1 */ + <2 0 &gpioa 0 0>, /* A2 */ + <3 0 &gpioa 5 0>, /* A3 */ + <4 0 &gpioa 6 0>, /* A4 */ + <5 0 &gpiof 12 0>, /* A5 */ + <6 0 &gpiob 11 0>, /* D0 */ + <7 0 &gpiob 10 0>, /* D1 */ + <8 0 &gpiog 15 0>, /* D2 */ + <9 0 &gpiob 5 0>, /* D3 */ + <10 0 &gpiog 4 0>, /* D4 */ + <11 0 &gpioh 11 0>, /* D5 */ + <12 0 &gpioh 10 0>, /* D6 */ + <13 0 &gpiog 5 0>, /* D7 */ + <14 0 &gpiog 8 0>, /* D8 */ + <15 0 &gpioa 8 0>, /* D9 */ + <16 0 &gpioa 3 0>, /* D10 */ + <17 0 &gpiob 15 0>, /* D11 */ + <18 0 &gpioi 2 0>, /* D12 */ + <19 0 &gpioi 1 0>, /* D13 */ + <20 0 &gpiob 7 0>, /* D14 */ + <21 0 &gpiob 6 0>; /* D15 */ + }; +}; diff --git a/boards/arm/stm32h573i_dk/doc/img/stm32h573i_dk.jpg b/boards/arm/stm32h573i_dk/doc/img/stm32h573i_dk.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c021d1ad9ab1097be27c4ad6cf0b14eba5affadc GIT binary patch literal 79132 zcmeEtWmFtb_a+1g?iM@*_dswBL1zf=Fc5-furRoX;4T9L!GjKiySux)1$TD|$?|*O z-97KOJ-cWB-~QG8p{s9o-RD%-y?yJc+kfZ(t|1Wshp<)frf^PiiU-b{t^QR3kL@q3mY33kB9&lj}Q+Vn}CdfkeGy&loSV_{1q9= zDu^no)?2yTAk$0 zX9y-K1K;;JGNBKySrye2lN5~aG_*|}q4BT|awb7dEgdKSgzU)SxxP`zr*{8G z9LPA~FZlmoe5L7{#+uIipCm6s`hHdG68^b4`2=lx@80y@tL1+?U;=c32!DQFh_oXG zNkd$m(!Z{sYn`_~b>JqmIjZ6vu5tYi$B#)b2-4DU;*X0DxWRqZ=(yisA4bsKJ4#6a z!0v1(R|&||v-|IlmfnVa#kiY#FVln{}Y9yj!Qe3iPlp}`3@ zH=tcyCIM>Yl>J1?XwAvYQ3-x-$Wcd*5{oSUK42`L!u>DOR4^Sd1ufB#)|% z`~lh5XlWoRJ!cm9q%#atvYcYi^P6IUaJA*$FTVmP^Z)t^$?&5H_`Q4oABPM%ePbne z@BwyKqyJvChh>DilXOzwAFB3@D>ll-{_cDuO>VxeX*7D1SPgj(0%=l9d6~DWU+^ed zV+B?M7)ICT|D-rOt^ojVh5sUT$q~J5p6ZUlk4$-D?*&ja2wi)xx7}XD|01OsJh2bL zS*E!|o^RDkRh3Bn-k96h(PnGS7K!`l8nB)M`(Ap)_{dWGEkB*)4yQl$q3vv%KytJg z>7L^FkEgTd+PgR34lcW5PIo$fuRTBN$#zB&OYO1V@E7Sa75y^eQ=Uq=_e=AS?uT7J z--~W^WIoE3O~U0QQTQ01jNF~^BuAb9d^;v<1OBV~vHcMnlbMm$CYlY>6`a^4ZOp4i z0@e3GK%se>P`p8M)JArC`znVJihExBDw~5)IH;%hTqzL%SwvYm`1eqbGl)E(#GR7j|sclXDGnsxkCI) zl+<$IuzMtPt#w!S7zJ;Ge%jYu=5J_2(0PxANPT`N1nEBYP5tU`c+jSUOl)o*NL+GL zKZP71AfIljRKGE{O%^{!C(+SqV%v^fJKYGb5TAvdf7S0!rY9(ld=T~b`f&#Gu-S$} z>P?W33nU^wi2aH|*t(VgT%2zBSn5tmpmiGc<*^1jJ*SnTv83D3opmU^y0B^eyuxc2hdIlI21UT zfeDK+FOFUlq5Z2r@PDO_#OTi37B!1H}a&= ze0X+t^{&xrooO?_1TU34s@6zG7VSp`jUGVaU4T~eOG;6p%>zSfS7xuA)fQ}XZtNkVg5&PN!$aI{FoU3y&D9l84SuIgpE7gksPUC{ z?esE?gs(xJ=DkCt`3qIa>>S+m5AbbY$!tRzLfpd^Px4qvf>Fs8F7`&5@p6kLC{|>x zNn`$*X!=s~TWg~B&l?wYWpmRNX1p5u3C{OrGK9qI5*yRIVztGKZq35<>|nFMNCH}C z^|D9X%TG#VEU#v!z2>r%KVkkwA|tAd2Ty%BmV=8+rmW^wIm}3LoL{qMND<->H%nki z6~cOWmX8H~r)FlQAHdj{-mL)M*8_!L#Jdj+ z4+S8dr@^Vr0g?LyCDRG-Hci_5Oj_S={LY9Tt?Qcoj=xCGySoUl=;zUYp1LQy^&tm2 z=bE=XD&H7)cXQ^QlX#|67iZp--k&f(X-RUp+!g&xQtTBSBXrGiJ6(Ty!}O$O%>HK^ zJho-@`#KXcvGXVAm&WGUyl){7={Lvf-3#tNp8rxnf12Fd>f3d#?q2i=gGj6zY~_4C zogQ4grsEj@Sr%j!-c-&xi)Zx+e4Z}VHnu6wn`|r%PP6vvi;f6^mvuFxn>#czY)jXR zc8dzGmZKhy89E&!HtHG`SMi{a#iz@?rPu}ZOc)$$qga|cB{-nmf_=O4*6p0kRjk;0 zO?q6|j}g>p{T`E^31zf80>$W6iR=JAb_Lu%z+xAG{rpWOw_H9$$t1`QTen;dR9tY5 zC*RFD4vOE%Cy~aWHTB<$E~oTH&13Y^l>Sj%zplSRgPx?8!eWM}V?Z-j1qYY7wC93K zD7mMsGqxv8mHgK*db>B{`p-%h^%PA7k|cIT^Vzk2Nrsq7VPsN6wMb1S!3+gjfsx-b z4I?bp@7oZiH-YzmLUYy$H&Zi(RQKh)GU?zNhRgvgy9Y9>e7g@^Wm1^rlvj@*n+;oe@&T!M`$KKod)ggKL(pFh4qP~YP1jD7VmU9ZQKpFve-QMY?o3u zOHV8*W>7;?yOInTLnz%KH zX=vcp*9`P!<@zK77`-%r;dOMNZYmgV=@zdF5#TicR~!@6ci!}!S`le2UC41qT*}}% zm}&Xn!3-+CjGou`outmD9;$%FkdI$p9WL403-xNmV$y8(0D&)>Z}LQFXYRwVAMwJg z5Laj7`Lo3*h$nB=fFm6t9()9ScLhx|xv|#`a*4-5HGU@nPw#NF-i3F@(Bo4`)?`j_el=8#x#EbaD|I&6S37%=zBvI( z<9`m;N4gr7mi(h#S{r1u(1tJL^ZCn?+=e$=Pc+H0u#v;pR&S6UA6f0@*az1lPXLx( z_tRkC`q_=!+q<-bkpqWwe#hF$T}>IKFbO;#Sbcuus7(Mnz8;Y%UVgELtcIJY0@4ZFi~D4qOtB78f^>;5s1zrJ0`U&aj-8sN_-OSAg^!nJ_-{U`2mPvk?QBJ zd)ro=X_X9*__VoOy*=<_*29e;usAelXKr7YL1hltM|y5jP9hNIbkxJ`p@$z3xrQ zA)lQh`#~huPcRk4Rh}D|78idjBKa_}@G7jspf=^ffoGAQUgILKYc5QqXR-G*x8CRL z#BAuBUu;Rb6pkSABpPXb70mXX8Y0h)YF^t)Kl*hc;d)GDHGlA2r)-VvgaG?j z12~46(Oo;M2L?JIywCIs62NyU+67A$7VH4|?NL~(+;{KDp_@QZXF@_~odQS^i)Dsg z)7<{S^IkV^LAm2_baT{BFn1E?b;?EQILri7v=;Zs!l{K8+o}9Jzet3 z{cSw84#$diL#|`oM1iL}R=D3Yon5w-?|pVqS2gw;s;$mXYz9EDe8eE3lhi?Ge7sh3)5WC5R7)B$>lYOC(f#zvozyEFo zz_`dNA9>U_K7`A)o2CY&vSR|OOCn*_REPF*wcsSAGkgoA;h8Vxdg&kjxHt5k%GZrg z6koJt8USigw+l^tb#bhg4_BX`_tYHtvXnc(7TeE`(rf_ni%Z*O-0W-+fSd<_TYdX< z64Ch@cbiwLnc&KTD>KQ7C}pHLYs;Kd#!8r|ICR>QuO!}=;xW*O04#Rvk3OIA1{!+b z{vf+b4_>zb^>CYm#WqpPJ4p`pAYgRIoA~rRg+xz0&|yhX@wUp*jwx%8@_bRTyN`Lr z5*$$X&Ly6_2{M~MX#2X_Pzi|1wMNY+vlm^PHkg#ILruP^Zs9*Adr$`ppib$=8H;|=i)lpGulCR6f4PMw=HIq#d(1wUepw1z(LLF4E4TA z-KfF$5Oides~z?uGxDSkjX8e*+OrSiT3+61vJvxLjPryFcjMF^em!jsKdo&R+h>mX zaRxLtG?B%&#xW^Qo$1$$tgyrzu;;dIG{l1~Wk))WJ zX<|5FGx8UQ9N?(P0Rj1ew+^^3_l6KA5EL>&! zw&R{H9P_<;Kf17RUt`mpl1HC<&5?72Z~EjMwn}^y?TSUbdpuX~v?e`;ZlP;lH{MU@ zjze8}U=LZ-m!M-$&%V5CTU6!h8s3a^+-!lqFSaGGS^51$g6JBGo#R#<`#a@JdN{b6 zl)yB?+u5tB-bE4g15Tz&uiR!BvlOwm9HslpCm3(Z#PSfMoReE(y!q5VJ(b8^*6M7p zUcI6v%?g`L`}1+BvuQeJd_IEx>#SP41jiugnq00hd2pZ??8Fww31dK7*CJ=n7g53* ztb|OKn+JY5(9BIJV0ks7NUjvApA{4;+8hR75 zQOGb|-(+>+;6S>k)~wb@Rw`i?BlL*tU`Wfl6D?aFcjLb1NJ9+rr@g)Ya^QRF!moV=Khr<1*vh*Y*VCFKiB(?vkbIpCfghR*i7 z8XdArT)7h(pT1hR5x@CSN6}~_o2Dx3fdQxX%O!be_*D81@U*bHt4_?j!Zo@+pCOJ0 zQa`9>*CXuXQz(Mc?aO|!v9S~ZI^{nrov@a#64I=KU*|=i+Iw=%5Kx%sv{`xClbmdA zczg44_y#huyDCW5cw2hL#RwADU`Sge3dzt9pn1Hhffu~ z(r5*{(Xgv%e|ytV+&M??{(|oZAcmQ9j-`q#E`-X(DuZ;6b_{E`x0tHRqB2X9&syr8 zW7T=@y?OI*J4j^2R?oxXU4Idt<7=x|qoQ+Jo$3+#al7Xwg(FVQQ|e1fL)( zB)KLpvQ2>gt^@<1zR~em?MhLNa+l{5{g$v?w3|{KhE=RI=3G$J-;kgY6KU zRyW{M$53w}S%)3csHd|Wgk#@JdURg;gs~{7fL52h!)lGk+2SrYO2nBsk27{El>bIY z5YZ#39a;4AB;L;hCk;#a%aG}{+}jY*TIkP&ZN0Ns17!mGi?-MN0{(Bpkgp#CJmU}2 z@IojGOZ81tx`HZ6plP(S?&^dbCF2F3Tf!aO3oe9CoLZwOAdS&*)_&@4B$N5_{6u3u=q^qAZO`8#f|>%9pE7+ZXv z+yJnRNm<}zH}de=#V7yhQ1zbIkgzucqf%Zi35w*5ecrB3s~pOhV*N$(b);MN{iSjA zBDP)KNFEcL9^US@mF-4VuEgNRqgVXbna0m}MeIoUq+Z(h)o2jdRJ1 zP4@2W6FF!td8>2i?bmv^kri4NI$sN)e(_~uT$L^SsjXVfuq_Em!}7)_>l45_Rv=|t zZv?oMF~l8>!rW8~|5#=HrknZ`2e0w1mWA=neBVTl02;Q-e2jiihcDGZXbyw^ zQLYMZTwUssz=W(P{;V8`au=K<#B&@cf+>QjzB_Qt0prW@GMH;1S}YXK4OwV}iES$~u-tYwC(b{8gQrT+4nL7!UMNh>bbmYy|M9$6xhs*Iu1S-A zm%o95Ee~rfAbK|}>()Mj(vxT|tpDX?M-A$M&yKP>_-~r?wJ-SA*E8bnEv>9K%kM`8 zk$_=?&Bz#(0OL)wZ)H50SsS(R!&1+M)g~T@%8=&ZaY{d7Atni%rQ(?E)>ISAo>!U%e9RF`D