diff --git a/CODEOWNERS b/CODEOWNERS index ea8a3dc8ec..1dd92adc08 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -49,6 +49,7 @@ /lib/ble_gq/ @nrfconnect/ncs-bm /lib/ble_qwr/ @nrfconnect/ncs-bm /lib/ble_racp/ @nrfconnect/ncs-bm +/lib/ble_radio_notification/ @nrfconnect/ncs-bm /lib/bm_buttons/ @nrfconnect/ncs-bm /lib/bm_storage/ @nrfconnect/ncs-bm /lib/bm_timer/ @nrfconnect/ncs-bm @@ -89,6 +90,7 @@ /tests/lib/bm_zms/ @nrfconnect/ncs-bm @rghaddab /tests/lib/ble_qwr/ @nrfconnect/ncs-bm /tests/lib/ble_racp/ @nrfconnect/ncs-bm +/tests/lib/ble_radio_notif/ @nrfconnect/ncs-bm /tests/lib/ble_adv/ @nrfconnect/ncs-bm-test /tests/lib/bm_storage/ @nrfconnect/ncs-bm diff --git a/doc/nrf-bm/api/api.rst b/doc/nrf-bm/api/api.rst index 4dfec90665..ec9f99c813 100644 --- a/doc/nrf-bm/api/api.rst +++ b/doc/nrf-bm/api/api.rst @@ -42,6 +42,12 @@ Advertising and Scan Response Data Encoder .. doxygengroup:: ble_sdk_lib_advdata :inner: +Bluetooth LE Radio Notification library +======================================= + +.. doxygengroup:: ble_radio_notification + :inner: + Bare Metal Zephyr Memory Storage (ZMS) ====================================== diff --git a/doc/nrf-bm/libraries/ble_radio_notification.rst b/doc/nrf-bm/libraries/ble_radio_notification.rst new file mode 100644 index 0000000000..b18d6f13bd --- /dev/null +++ b/doc/nrf-bm/libraries/ble_radio_notification.rst @@ -0,0 +1,52 @@ +.. _lib_ble_radio_notification: + +Bluetooth: Radio Notification +############################# + +.. contents:: + :local: + :depth: 2 + +The Bluetooth Low Energy® Radio Notification library allows the user to subscribe to the Radio Notification signal to receive notification prior to and after radio events. + +Overview +******** + +The library allows the user to register a handler to receive the radio notifications and configure the distance in microseconds between the active Radio Notification signal and the radio event. + +Configuration +************* + +The library is enabled and configured entirely using the Kconfig system. +Set the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION` Kconfig option to enable the library. + +The library uses the ``SWI02`` IRQ. Use the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO` Kconfig option to set the IRQ priority. + +Initialization +============== + +The library is initialized by calling the :c:func:`ble_radio_notification_init` function. + +Usage +***** + +Initialize the library by calling the :c:func:`ble_radio_notification_init` function, specifying the event handler to receive the Radio Notification signal. +You can specify the distance in microseconds between the Radio Notification signal and the start of the radio event. +This event has ``active_state`` set to ``true``. +A new Radio Notification signal will be raised when the radio event completes with ``active_state`` set to ``false``. + +Dependencies +************ + +This library uses the following |BMshort| libraries: + +* SoftDevice - :kconfig:option:`CONFIG_SOFTDEVICE` +* SoftDevice handler - :kconfig:option:`CONFIG_NRF_SDH` + +API documentation +***************** + +| Header file: :file:`include/ble_radio_notification.h` +| Source files: :file:`lib/ble_radio_notification/` + + .. doxygengroup:: ble_radio_notification diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index e19bea6259..5163985413 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -52,7 +52,7 @@ No changes since the latest nRF Connect SDK Bare Metal release. Libraries ========= -No changes since the latest nRF Connect SDK Bare Metal release. +Added the :ref:`lib_ble_radio_notification` library. Samples ======= @@ -60,7 +60,7 @@ Samples Bluetooth samples ----------------- -No changes since the latest nRF Connect SDK Bare Metal release. +Added the :ref:`ble_radio_ntf_sample` sample. Peripheral samples ------------------ diff --git a/include/ble_radio_notification.h b/include/ble_radio_notification.h new file mode 100644 index 0000000000..a42622e64e --- /dev/null +++ b/include/ble_radio_notification.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018-2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +/** @file + * + * @defgroup ble_radio_notification Radio Notification Event Handler + * + * @brief Module for propagating Radio Notification events to the application. + */ + +#ifndef BLE_RADIO_NOTIFICATION_H__ +#define BLE_RADIO_NOTIFICATION_H__ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @brief Application radio notification event handler type. */ +typedef void (*ble_radio_notification_evt_handler_t)(bool radio_active); + +/** + * @brief Function for initializing the Radio Notification module. + * + * @param[in] distance Distance between the ACTIVE notification signal and start of radio event. + * @param[in] evt_handler Handler to be executed when a radio notification event has been received. + * + * @return NRF_SUCCESS on successful initialization, otherwise an error code. + */ +uint32_t ble_radio_notification_init(uint32_t distance, + ble_radio_notification_evt_handler_t evt_handler); + +#ifdef __cplusplus +} +#endif + +#endif /* BLE_RADIO_NOTIFICATION_H__ */ + +/** @} */ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 7cd28e8ee8..0866b2589d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -8,6 +8,7 @@ add_subdirectory_ifdef(CONFIG_BLE_ADV ble_adv) add_subdirectory_ifdef(CONFIG_BLE_CONN_PARAMS ble_conn_params) add_subdirectory_ifdef(CONFIG_BLE_GATT_QUEUE ble_gq) add_subdirectory_ifdef(CONFIG_BLE_RACP ble_racp) +add_subdirectory_ifdef(CONFIG_BLE_RADIO_NOTIFICATION ble_radio_notification) add_subdirectory_ifdef(CONFIG_EVENT_SCHEDULER event_scheduler) add_subdirectory_ifdef(CONFIG_BM_BUTTONS bm_buttons) add_subdirectory_ifdef(CONFIG_BM_STORAGE bm_storage) diff --git a/lib/Kconfig b/lib/Kconfig index a1fe1029d0..9243fd4322 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -9,6 +9,7 @@ rsource "ble_adv/Kconfig" rsource "ble_conn_params/Kconfig" rsource "ble_gq/Kconfig" rsource "ble_racp/Kconfig" +rsource "ble_radio_notification/Kconfig" rsource "event_scheduler/Kconfig" rsource "bm_buttons/Kconfig" rsource "bm_storage/Kconfig" diff --git a/lib/ble_radio_notification/CMakeLists.txt b/lib/ble_radio_notification/CMakeLists.txt new file mode 100644 index 0000000000..9da3e52501 --- /dev/null +++ b/lib/ble_radio_notification/CMakeLists.txt @@ -0,0 +1,7 @@ +# +# Copyright (c) 2025 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# +zephyr_library() +zephyr_library_sources(ble_radio_notification.c) diff --git a/lib/ble_radio_notification/Kconfig b/lib/ble_radio_notification/Kconfig new file mode 100644 index 0000000000..125881da39 --- /dev/null +++ b/lib/ble_radio_notification/Kconfig @@ -0,0 +1,38 @@ +# +# Copyright (c) 2025 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# +menuconfig BLE_RADIO_NOTIFICATION + bool "BLE Radio Notification" + +if BLE_RADIO_NOTIFICATION + +choice BLE_RADIO_NOTIFICATION_TYPE + prompt "Radio notification type" + default BLE_RADIO_NOTIFICATION_ON_BOTH + +config BLE_RADIO_NOTIFICATION_ON_ACTIVE + bool "on active" + +config BLE_RADIO_NOTIFICATION_ON_INACTIVE + bool "on inactive" + +config BLE_RADIO_NOTIFICATION_ON_BOTH + bool "on both active and inactive" + +endchoice # BLE_RADIO_NOTIFICATION_TYPE + +config BLE_RADIO_NOTIFICATION_IRQ_PRIO + int "Radio Notification IRQ priority" + default 3 + help + IRQ Priority level 0 and 4 are reserved by the SoftDevice. + + +module=BLE_RADIO_NTF +module-dep=LOG +module-str=BLE Radio Notification +source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config" + +endif # BLE_RADIO_NOTIFICATION diff --git a/lib/ble_radio_notification/ble_radio_notification.c b/lib/ble_radio_notification/ble_radio_notification.c new file mode 100644 index 0000000000..8d0725323e --- /dev/null +++ b/lib/ble_radio_notification/ble_radio_notification.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2018-2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include +#include + +#include +#include + +#if CONFIG_UNITY +#include +#define STATIC +#else +#define STATIC static +#endif + +LOG_MODULE_REGISTER(ble_radio_ntf, CONFIG_BLE_RADIO_NTF_LOG_LEVEL); + +/* Current radio state. */ +#if CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE +static bool radio_active = true; +#else +static bool radio_active; +#endif + +/* Application event handler for handling Radio Notification events. */ +static ble_radio_notification_evt_handler_t evt_handler; + +STATIC void radio_notification_isr(const void *arg) +{ + ARG_UNUSED(arg); + +#if defined CONFIG_BLE_RADIO_NOTIFICATION_ON_BOTH + radio_active = !radio_active; +#endif + + if (evt_handler != NULL) { + evt_handler(radio_active); + } +} + +uint32_t ble_radio_notification_init(uint32_t distance, + ble_radio_notification_evt_handler_t _evt_handler) +{ + uint8_t type = NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH; + +#if defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE) + type = NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE; +#elif defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_INACTIVE) + type = NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE; +#endif + + evt_handler = _evt_handler; + + /* Initialize Radio Notification software interrupt */ + IRQ_DIRECT_CONNECT(RADIO_NOTIFICATION_IRQn, CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO, + radio_notification_isr, 0); + + NVIC_ClearPendingIRQ(RADIO_NOTIFICATION_IRQn); + NVIC_EnableIRQ(RADIO_NOTIFICATION_IRQn); + + return sd_radio_notification_cfg_set(type, distance); +} diff --git a/samples/bluetooth/ble_radio_notification/CMakeLists.txt b/samples/bluetooth/ble_radio_notification/CMakeLists.txt new file mode 100644 index 0000000000..a5eb2c95ad --- /dev/null +++ b/samples/bluetooth/ble_radio_notification/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (c) 2025 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(ble_radio_ntf) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/bluetooth/ble_radio_notification/Kconfig b/samples/bluetooth/ble_radio_notification/Kconfig new file mode 100644 index 0000000000..11246bda82 --- /dev/null +++ b/samples/bluetooth/ble_radio_notification/Kconfig @@ -0,0 +1,21 @@ +# +# Copyright (c) 2025 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +menu "BLE Radio Notification sample" + +config BLE_RADIO_NOTIFICATION_DISTANCE_US + int "Distance between the active notification signal and start of radio event preparation" + range 50 5500 + default 800 + +module=BLE_RADIO_NTF_SAMPLE +module-dep=LOG +module-str=BLE Radio Notification Sample +source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config" + +endmenu # "BLE Radio Notification sample" + +source "Kconfig.zephyr" diff --git a/samples/bluetooth/ble_radio_notification/README.rst b/samples/bluetooth/ble_radio_notification/README.rst new file mode 100644 index 0000000000..f02cd0d337 --- /dev/null +++ b/samples/bluetooth/ble_radio_notification/README.rst @@ -0,0 +1,100 @@ +.. _ble_radio_ntf_sample: + +Bluetooth: Radio Notifications +############################## + +.. contents:: + :local: + :depth: 2 + +The Radio Notification sample demonstrates how you can use the :ref:`lib_ble_radio_notification` library using |BMlong|. + +Requirements +************ + +The sample supports the following development kits: + +.. tabs:: + + .. group-tab:: Simple board variants + + The following board variants do **not** have DFU capabilities. + + .. list-table:: + :header-rows: 1 + + * - Hardware platform + - PCA + - SoftDevice + - Board target + * - `nRF54L15 DK`_ + - PCA10156 + - S115 + - bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice + * - `nRF54L15 DK`_ (emulating nRF54L10) + - PCA10156 + - S115 + - bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice + * - `nRF54L15 DK`_ (emulating nRF54L05) + - PCA10156 + - S115 + - bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice + + .. group-tab:: MCUboot board variants + + The following board variants have DFU capabilities. + + .. list-table:: + :header-rows: 1 + + * - Hardware platform + - PCA + - SoftDevice + - Board target + * - `nRF54L15 DK`_ + - PCA10156 + - S115 + - bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot + * - `nRF54L15 DK`_ (emulating nRF54L10) + - PCA10156 + - S115 + - bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot + * - `nRF54L15 DK`_ (emulating nRF54L05) + - PCA10156 + - S115 + - bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot + +Overview +******** + +The sample initialize the radio notification library and register a handler to trigger both when the radio will be enabled and disabled. +The handler toggle the LED0 depending on the radio state. + +Programming the S115 SoftDevice +******************************* + +.. include:: /includes/softdevice_flash.txt + +.. _ble_radio_notification_sample_testing: + +Building and running +******************** + +This sample can be found under :file:`samples/bluetooth/ble_radio_notification/` in the |BMshort| folder structure. + +.. include:: /includes/create_sample.txt + +.. include:: /includes/configure_and_build_sample.txt + +.. include:: /includes/program_sample.txt + +Testing +======= + +You can test this sample using `nRF Connect for Desktop`_ with the `Serial Terminal app`_. +Make sure that these are installed before starting the testing procedure. + +1. Compile and program the application. +#. In the Serial Terminal, observe that the ``BLE Radio Notification sample started`` message is printed. +#. Observe that the LED0 blinks while the device is advertising and radio is active. +#. Observe that the LED0 stops blinking when advertising stops. diff --git a/samples/bluetooth/ble_radio_notification/prj.conf b/samples/bluetooth/ble_radio_notification/prj.conf new file mode 100644 index 0000000000..01ef6a730d --- /dev/null +++ b/samples/bluetooth/ble_radio_notification/prj.conf @@ -0,0 +1,24 @@ +CONFIG_LOG=y +CONFIG_LOG_BACKEND_BM_UARTE=y + +CONFIG_SOFTDEVICE=y +CONFIG_NRF_SDH=y + +CONFIG_BLE_ADV=y +CONFIG_BLE_ADV_NAME="nRF_BM_Radio_Ntf" +CONFIG_BLE_ADV_EXTENDED_ADVERTISING=n +CONFIG_BLE_ADV_DIRECTED_ADVERTISING=n + +# BLE connection parameter +CONFIG_BLE_CONN_PARAMS=y + +CONFIG_BLE_ADV_FAST_ADVERTISING_INTERVAL=400 +CONFIG_BLE_ADV_SLOW_ADVERTISING_INTERVAL=1600 + +# Radio Notifications +CONFIG_BLE_RADIO_NOTIFICATION=y + +# Enable RNG +CONFIG_NRF_SECURITY=y +CONFIG_MBEDTLS_PSA_CRYPTO_C=y +CONFIG_PSA_WANT_GENERATE_RANDOM=y diff --git a/samples/bluetooth/ble_radio_notification/sample.yaml b/samples/bluetooth/ble_radio_notification/sample.yaml new file mode 100644 index 0000000000..a1c567521c --- /dev/null +++ b/samples/bluetooth/ble_radio_notification/sample.yaml @@ -0,0 +1,20 @@ +sample: + name: Bluetooth Radio Notification Sample +tests: + sample.ble_radio_ntf: + build_only: true + integration_platforms: + - bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice + - bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice + - bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice + - bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot + - bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot + - bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot + platform_allow: + - bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice + - bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice + - bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice + - bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot + - bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot + - bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot + tags: ci_build diff --git a/samples/bluetooth/ble_radio_notification/src/main.c b/samples/bluetooth/ble_radio_notification/src/main.c new file mode 100644 index 0000000000..6afdbd3c03 --- /dev/null +++ b/samples/bluetooth/ble_radio_notification/src/main.c @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +LOG_MODULE_REGISTER(app, CONFIG_BLE_RADIO_NTF_SAMPLE_LOG_LEVEL); + +BLE_ADV_DEF(ble_adv); /* BLE advertising instance */ + +static void led_init(void) +{ + nrf_gpio_cfg_output(BOARD_PIN_LED_0); +} + +static void led_set(bool state) +{ + nrf_gpio_pin_write(BOARD_PIN_LED_0, + (state ? BOARD_LED_ACTIVE_STATE : !BOARD_LED_ACTIVE_STATE)); +} + +static void ble_adv_evt_handler(struct ble_adv *adv, const struct ble_adv_evt *adv_evt) +{ + switch (adv_evt->evt_type) { + case BLE_ADV_EVT_ERROR: + LOG_ERR("Advertising error %d", adv_evt->error.reason); + break; + default: + break; + } +} + +void on_conn_params_evt(const struct ble_conn_params_evt *evt) +{ + int err; + + switch (evt->id) { + case BLE_CONN_PARAMS_EVT_REJECTED: + err = sd_ble_gap_disconnect(evt->conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE); + if (err) { + LOG_ERR("Disconnect failed on conn params update rejection, nrf_error %#x", + err); + } else { + LOG_INF("Disconnected from peer, unacceptable conn params"); + } + break; + + default: + break; + } +} + +static void ble_radio_notification_evt_handler(bool radio_active) +{ + led_set(radio_active); +} + +int main(void) +{ + int err; + + struct ble_adv_config ble_adv_cfg = { + .conn_cfg_tag = CONFIG_NRF_SDH_BLE_CONN_TAG, + .evt_handler = ble_adv_evt_handler, + .adv_data = { + .name_type = BLE_ADV_DATA_FULL_NAME, + .flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE, + }, + + }; + + LOG_INF("BLE Radio Notification sample started"); + + led_init(); + + err = nrf_sdh_enable_request(); + if (err) { + LOG_ERR("Failed to enable SoftDevice, err %d", err); + goto idle; + } + + LOG_INF("SoftDevice enabled"); + + err = ble_radio_notification_init(CONFIG_BLE_RADIO_NOTIFICATION_DISTANCE_US, + ble_radio_notification_evt_handler); + if (err != NRF_SUCCESS) { + LOG_ERR("Failed to enable BLE, err %d", err); + goto idle; + } + + err = nrf_sdh_ble_enable(CONFIG_NRF_SDH_BLE_CONN_TAG); + if (err) { + LOG_ERR("Failed to enable BLE, err %d", err); + goto idle; + } + + LOG_INF("Bluetooth enabled"); + + err = ble_conn_params_evt_handler_set(on_conn_params_evt); + if (err) { + LOG_ERR("Failed to setup conn param event handler, err %d", err); + goto idle; + } + + err = ble_adv_init(&ble_adv, &ble_adv_cfg); + if (err) { + LOG_ERR("Failed to initialize advertising, err %d", err); + goto idle; + } + + err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); + if (err) { + LOG_ERR("Failed to start advertising, err %d", err); + goto idle; + } + + LOG_INF("Advertising as %s", CONFIG_BLE_ADV_NAME); + +idle: + while (true) { + while (LOG_PROCESS()) { + } + + /* Wait for an event. */ + __WFE(); + + /* Clear Event Register */ + __SEV(); + __WFE(); + } + + return 0; +} diff --git a/tests/lib/ble_radio_notif/CMakeLists.txt b/tests/lib/ble_radio_notif/CMakeLists.txt new file mode 100644 index 0000000000..3c7e99989e --- /dev/null +++ b/tests/lib/ble_radio_notif/CMakeLists.txt @@ -0,0 +1,45 @@ +# +# Copyright (c) 2025 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(test_ble_radio_ntf) + +set(SOFTDEVICE_VARIANT "s115") +set(SOFTDEVICE_INCLUDE_DIR "${ZEPHYR_NRF_BM_MODULE_DIR}/components/softdevice/${SOFTDEVICE_VARIANT}/${SOFTDEVICE_VARIANT}_API/include") + +cmock_handle(${SOFTDEVICE_INCLUDE_DIR}/nrf_soc.h + WORD_EXCLUDE + "__STATIC_INLINE") + +cmock_handle(mocks/cmsis.h) + +add_compile_definitions( + SVCALL_AS_NORMAL_FUNCTION=1 + NRF54L15_XXAA) + +target_compile_definitions( app PRIVATE + CONFIG_BLE_RADIO_NOTIFICATION_ON_BOTH=1 + CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO=5 + SWI02_IRQn=0 +) + +# Generate and add test file +test_runner_generate(src/unity_test.c) +target_sources(app PRIVATE src/unity_test.c) + +target_include_directories(app PRIVATE ${ZEPHYR_NRF_BM_MODULE_DIR}/include) +target_include_directories(app PRIVATE ${SOFTDEVICE_INCLUDE_DIR}) +target_include_directories(app PRIVATE ${ZEPHYR_HAL_NORDIC_MODULE_DIR}/nrfx/mdk) +target_include_directories(app PRIVATE ${ZEPHYR_CMSIS_MODULE_DIR}/CMSIS/Core/Include) + +target_sources(app + PRIVATE + ${ZEPHYR_NRF_BM_MODULE_DIR}/lib/ble_radio_notification/ble_radio_notification.c +) +zephyr_include_directories(${ZEPHYR_NRF_BM_MODULE_DIR}/include) diff --git a/tests/lib/ble_radio_notif/mocks/cmsis.h b/tests/lib/ble_radio_notif/mocks/cmsis.h new file mode 100644 index 0000000000..360e9dacee --- /dev/null +++ b/tests/lib/ble_radio_notif/mocks/cmsis.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef int IRQn_Type; + +void NVIC_ClearPendingIRQ(IRQn_Type IRQn); +void NVIC_EnableIRQ(IRQn_Type IRQn); + +#ifdef __cplusplus +} +#endif diff --git a/tests/lib/ble_radio_notif/prj.conf b/tests/lib/ble_radio_notif/prj.conf new file mode 100644 index 0000000000..a8788847da --- /dev/null +++ b/tests/lib/ble_radio_notif/prj.conf @@ -0,0 +1,6 @@ +# +# Copyright (c) 2025 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# +CONFIG_UNITY=y diff --git a/tests/lib/ble_radio_notif/src/unity_test.c b/tests/lib/ble_radio_notif/src/unity_test.c new file mode 100644 index 0000000000..4ae0114c05 --- /dev/null +++ b/tests/lib/ble_radio_notif/src/unity_test.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ +#include +#include +#include +#include +#include + +#include + +#include "cmock_nrf_soc.h" +#include "cmock_cmsis.h" + +extern void radio_notification_isr(const void *arg); +bool radio_active; + +static void ble_radio_notification_evt_handler(bool _radio_active) +{ + radio_active = _radio_active; +} + +void test_ble_radio_notification_init_invalid_param(void) +{ + int ret; + + __cmock_NVIC_ClearPendingIRQ_Expect(RADIO_NOTIFICATION_IRQn); + __cmock_NVIC_EnableIRQ_Expect(RADIO_NOTIFICATION_IRQn); + __cmock_sd_radio_notification_cfg_set_ExpectAndReturn( + NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, 800, NRF_ERROR_INVALID_PARAM); + ret = ble_radio_notification_init(800, ble_radio_notification_evt_handler); + TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_PARAM, ret); +} + +void test_ble_radio_notification_init(void) +{ + int ret; + + __cmock_NVIC_ClearPendingIRQ_Expect(RADIO_NOTIFICATION_IRQn); + __cmock_NVIC_EnableIRQ_Expect(RADIO_NOTIFICATION_IRQn); + __cmock_sd_radio_notification_cfg_set_ExpectAndReturn( + NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, 800, NRF_SUCCESS); + ret = ble_radio_notification_init(800, ble_radio_notification_evt_handler); + TEST_ASSERT_EQUAL(NRF_SUCCESS, ret); +} + +void test_ble_radio_notification(void) +{ + TEST_ASSERT_FALSE(radio_active); + radio_notification_isr(NULL); + TEST_ASSERT_TRUE(radio_active); + radio_notification_isr(NULL); + TEST_ASSERT_FALSE(radio_active); +} + +void setUp(void) +{ +} +void tearDown(void) +{ +} + +extern int unity_main(void); + +int main(void) +{ + return unity_main(); +} diff --git a/tests/lib/ble_radio_notif/testcase.yaml b/tests/lib/ble_radio_notif/testcase.yaml new file mode 100644 index 0000000000..4ed4fd7267 --- /dev/null +++ b/tests/lib/ble_radio_notif/testcase.yaml @@ -0,0 +1,4 @@ +tests: + lib.ble_radio_ntf: + platform_allow: native_sim + tags: unittest