Skip to content

Commit 570b607

Browse files
lib: add ble_radio_notification and sample
Add ble_radio_notification library and sample. Signed-off-by: Eivind Jølsgard <eivind.jolsgard@nordicsemi.no>
1 parent da48c9c commit 570b607

21 files changed

Lines changed: 694 additions & 2 deletions

File tree

CODEOWNERS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
/lib/bluetooth/ble_gq/ @nrfconnect/ncs-bm
5151
/lib/bluetooth/ble_qwr/ @nrfconnect/ncs-bm
5252
/lib/bluetooth/ble_racp/ @nrfconnect/ncs-bm
53+
/lib/bluetooth/ble_radio_notification/ @nrfconnect/ncs-bm
5354
/lib/bluetooth/peer_manager/ @nrfconnect/ncs-bm
5455
/lib/bm_buttons/ @nrfconnect/ncs-bm
5556
/lib/bm_timer/ @nrfconnect/ncs-bm
@@ -89,10 +90,11 @@
8990
/sysbuild/ @nrfconnect/ncs-co-build-system
9091

9192
# Tests
93+
/tests/lib/bluetooth/ble_adv/ @nrfconnect/ncs-bm-test
9294
/tests/lib/bluetooth/ble_conn_state/ @nrfconnect/ncs-bm
9395
/tests/lib/bluetooth/ble_qwr/ @nrfconnect/ncs-bm
9496
/tests/lib/bluetooth/ble_racp/ @nrfconnect/ncs-bm
95-
/tests/lib/bluetooth/ble_adv/ @nrfconnect/ncs-bm-test
97+
/tests/lib/bluetooth/ble_radio_notif/ @nrfconnect/ncs-bm
9698
/tests/subsys/bluetooth/services/ @nrfconnect/ncs-bm @nrfconnect/ncs-bm-test
9799
/tests/subsys/fs/bm_zms/ @nrfconnect/ncs-bm @rghaddab
98100
/tests/subsys/storage/bm_storage/ @nrfconnect/ncs-bm

doc/nrf-bm/api/api.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ Bluetooth LE Connection State library
4848
:inner:
4949
:members:
5050

51+
.. _api_ble_radio_notif:
52+
53+
Bluetooth LE Radio Notification library
54+
=======================================
55+
56+
.. doxygengroup:: ble_radio_notification
57+
:inner:
58+
:members:
59+
5160
.. _api_bm_buttons:
5261

5362
Bare Metal Buttons library
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
.. _lib_ble_radio_notification:
2+
3+
Bluetooth: Radio Notification
4+
#############################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The Bluetooth Low Energy® Radio Notification library provides an interface for subscribing to the Radio Notification signal, allowing the application to receive notifications before and after radio events occur.
11+
12+
Overview
13+
********
14+
15+
This library enables applications to register a handler for receiving radio notifications.
16+
You can also use it to configure the interval in microseconds between the active Radio Notification signal and the radio event.
17+
18+
Configuration
19+
*************
20+
21+
The library is enabled and configured using the Kconfig system.
22+
Set the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION` Kconfig option to enable the library.
23+
24+
The library uses the ``SWI02`` IRQ.
25+
Use the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO` Kconfig option to set the IRQ priority.
26+
27+
The library can be configured to receive notifications before the radio is active, after the radio is active, or both before and after.
28+
You can select this using the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE`, the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION_ON_INACTIVE`, or the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION_ON_BOTH` Kconfig options, respectively.
29+
30+
Initialization
31+
==============
32+
33+
Initialize the library by calling the :c:func:`ble_radio_notification_init` function.
34+
35+
Usage
36+
*****
37+
38+
When initializing the library with the :c:func:`ble_radio_notification_init` function, make sure to specify the event handler to receive the Radio Notification signal.
39+
You can specify the interval in microseconds between the Radio Notification signal and the start of the radio event.
40+
The signal raised at the start of the radio event has ``active_state`` set to ``true``.
41+
A new Radio Notification signal will be raised when the radio event completes with ``active_state`` set to ``false``.
42+
43+
Sample
44+
******
45+
46+
The usage of this library is demonstrated in the :ref:`ble_radio_ntf_sample` sample.
47+
48+
Dependencies
49+
************
50+
51+
This library uses the following |BMshort| libraries:
52+
53+
* SoftDevice - :kconfig:option:`CONFIG_SOFTDEVICE`
54+
* SoftDevice handler - :kconfig:option:`CONFIG_NRF_SDH`
55+
56+
API documentation
57+
*****************
58+
59+
| Header file: :file:`include/bm/bluetooth/ble_radio_notification.h`
60+
| Source files: :file:`lib/bluetooth/ble_radio_notification/`
61+
62+
:ref:`Bluetooth LE Radio Notification library API reference <api_ble_radio_notif>`

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ No changes since the latest nRF Connect SDK Bare Metal release.
6969
Libraries
7070
=========
7171

72+
* Added the :ref:`lib_ble_radio_notification` library.
73+
7274
* Updated the following libraries to return ``nrf_errors`` instead of ``errnos``:
7375

7476
* :ref:`lib_ble_adv`.
@@ -117,7 +119,7 @@ Samples
117119
Bluetooth samples
118120
-----------------
119121

120-
No changes since the latest nRF Connect SDK Bare Metal release.
122+
Added the :ref:`ble_radio_ntf_sample` sample.
121123

122124
Peripheral samples
123125
------------------
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2018-2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/** @file
8+
*
9+
* @defgroup ble_radio_notification Radio Notification
10+
* @{
11+
*
12+
* @brief Module for propagating Radio Notification events to the application.
13+
*/
14+
15+
#ifndef BLE_RADIO_NOTIFICATION_H__
16+
#define BLE_RADIO_NOTIFICATION_H__
17+
18+
#include <stdint.h>
19+
#include <stdbool.h>
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
/** @brief Application radio notification event handler type. */
26+
typedef void (*ble_radio_notification_evt_handler_t)(bool radio_active);
27+
28+
/**
29+
* @brief Function for initializing the Radio Notification module.
30+
*
31+
* To ensure that the radio notification signal behaves in a consistent way, the radio
32+
* notifications must be configured when there is no protocol stack or other SoftDevice
33+
* activity in progress. It is recommended that the radio notification signal is
34+
* configured directly after the SoftDevice has been enabled.
35+
*
36+
* @param[in] distance Distance between the ACTIVE notification signal and start of radio event.
37+
* @param[in] evt_handler Handler to be called when a radio notification event has been received.
38+
*
39+
* @retval NRF_SUCCESS on successful initialization.
40+
* @retval NRF_ERROR_NULL if @c evt_handler is NULL.
41+
* @retval NRF_ERROR_INVALID_PARAM if the distance is invalid or radio notification type is not
42+
* properly configured.
43+
* @retval NRF_ERROR_INVALID_STATE if the protocol stack or other SoftDevice is running. Stop all
44+
* running activities and retry.
45+
*/
46+
uint32_t ble_radio_notification_init(uint32_t distance,
47+
ble_radio_notification_evt_handler_t evt_handler);
48+
49+
#ifdef __cplusplus
50+
}
51+
#endif
52+
53+
#endif /* BLE_RADIO_NOTIFICATION_H__ */
54+
55+
/** @} */

lib/bluetooth/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ add_subdirectory_ifdef(CONFIG_BLE_CONN_PARAMS ble_conn_params)
99
add_subdirectory_ifdef(CONFIG_BLE_CONN_STATE ble_conn_state)
1010
add_subdirectory_ifdef(CONFIG_BLE_GATT_QUEUE ble_gq)
1111
add_subdirectory_ifdef(CONFIG_BLE_RACP ble_racp)
12+
add_subdirectory_ifdef(CONFIG_BLE_RADIO_NOTIFICATION ble_radio_notification)
1213
add_subdirectory_ifdef(CONFIG_BLE_QWR ble_qwr)
1314
add_subdirectory_ifdef(CONFIG_PEER_MANAGER peer_manager)

lib/bluetooth/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ rsource "ble_conn_params/Kconfig"
1010
rsource "ble_conn_state/Kconfig"
1111
rsource "ble_gq/Kconfig"
1212
rsource "ble_racp/Kconfig"
13+
rsource "ble_radio_notification/Kconfig"
1314
rsource "ble_qwr/Kconfig"
1415
rsource "peer_manager/Kconfig"
1516

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
zephyr_library()
7+
zephyr_library_sources(ble_radio_notification.c)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
menuconfig BLE_RADIO_NOTIFICATION
7+
bool "BLE Radio Notification"
8+
depends on SOFTDEVICE
9+
10+
if BLE_RADIO_NOTIFICATION
11+
12+
choice BLE_RADIO_NOTIFICATION_TYPE
13+
prompt "Radio notification type"
14+
default BLE_RADIO_NOTIFICATION_ON_BOTH
15+
16+
config BLE_RADIO_NOTIFICATION_ON_ACTIVE
17+
bool "On active"
18+
19+
config BLE_RADIO_NOTIFICATION_ON_INACTIVE
20+
bool "On inactive"
21+
22+
config BLE_RADIO_NOTIFICATION_ON_BOTH
23+
bool "On both active and inactive"
24+
25+
endchoice # BLE_RADIO_NOTIFICATION_TYPE
26+
27+
config BLE_RADIO_NOTIFICATION_IRQ_PRIO
28+
int "BLE Radio Notification IRQ priority"
29+
default 3
30+
31+
module=BLE_RADIO_NOTIFICATION
32+
module-str=BLE Radio Notification
33+
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
34+
35+
endif # BLE_RADIO_NOTIFICATION
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2018-2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <nrf_error.h>
8+
#include <nrf_soc.h>
9+
#include <stdlib.h>
10+
11+
#include <bm/bluetooth/ble_radio_notification.h>
12+
#include <zephyr/logging/log.h>
13+
14+
#if CONFIG_UNITY
15+
#include <cmsis.h>
16+
#endif
17+
18+
LOG_MODULE_REGISTER(ble_radio_ntf, CONFIG_BLE_RADIO_NOTIFICATION_LOG_LEVEL);
19+
20+
/* Radio notification type. */
21+
#if defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE)
22+
#define NOTIFICATION_TYPE NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE
23+
#elif defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_INACTIVE)
24+
#define NOTIFICATION_TYPE NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE
25+
#else
26+
#define NOTIFICATION_TYPE NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH
27+
#endif
28+
29+
/* Application event handler for handling Radio Notification events. */
30+
static ble_radio_notification_evt_handler_t evt_handler;
31+
32+
void radio_notification_isr(const void *arg)
33+
{
34+
static bool radio_active = IS_ENABLED(CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE);
35+
36+
ARG_UNUSED(arg);
37+
38+
#if defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_BOTH)
39+
radio_active = !radio_active;
40+
#endif
41+
42+
if (evt_handler) {
43+
evt_handler(radio_active);
44+
}
45+
}
46+
47+
uint32_t ble_radio_notification_init(uint32_t distance,
48+
ble_radio_notification_evt_handler_t notif_evt_handler)
49+
{
50+
if (!notif_evt_handler) {
51+
return NRF_ERROR_NULL;
52+
}
53+
54+
evt_handler = notif_evt_handler;
55+
56+
/* Initialize Radio Notification software interrupt */
57+
IRQ_DIRECT_CONNECT(RADIO_NOTIFICATION_IRQn, CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO,
58+
radio_notification_isr, 0);
59+
60+
NVIC_ClearPendingIRQ(RADIO_NOTIFICATION_IRQn);
61+
NVIC_EnableIRQ(RADIO_NOTIFICATION_IRQn);
62+
63+
return sd_radio_notification_cfg_set(NOTIFICATION_TYPE, distance);
64+
}

0 commit comments

Comments
 (0)