Skip to content

Commit 8cc6735

Browse files
lib: add ble_radio_notification and sample
Add ble_radio_notification library and sample. Signed-off-by: Eivind Jølsgard <[email protected]>
1 parent 409fabc commit 8cc6735

File tree

21 files changed

+697
-2
lines changed

21 files changed

+697
-2
lines changed

CODEOWNERS

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,24 @@
4444
/include/bm/bluetooth/ @nrfconnect/ncs-bm
4545

4646
# Libraries
47+
<<<<<<< HEAD
4748
/lib/bluetooth/ble_adv/ @nrfconnect/ncs-bm
4849
/lib/bluetooth/ble_conn_params/ @nrfconnect/ncs-bm
4950
/lib/bluetooth/ble_conn_state/ @nrfconnect/ncs-bm
5051
/lib/bluetooth/ble_gq/ @nrfconnect/ncs-bm
5152
/lib/bluetooth/ble_qwr/ @nrfconnect/ncs-bm
5253
/lib/bluetooth/ble_racp/ @nrfconnect/ncs-bm
5354
/lib/bluetooth/peer_manager/ @nrfconnect/ncs-bm
55+
=======
56+
/lib/bm_zms/ @nrfconnect/ncs-bm @rghaddab
57+
/lib/ble_adv/ @nrfconnect/ncs-bm
58+
/lib/ble_conn_params/ @nrfconnect/ncs-bm
59+
/lib/ble_conn_state/ @nrfconnect/ncs-bm
60+
/lib/ble_gq/ @nrfconnect/ncs-bm
61+
/lib/ble_qwr/ @nrfconnect/ncs-bm
62+
/lib/ble_racp/ @nrfconnect/ncs-bm
63+
/lib/ble_radio_notification/ @nrfconnect/ncs-bm
64+
>>>>>>> 142bcf3a (lib: add ble_radio_notification and sample)
5465
/lib/bm_buttons/ @nrfconnect/ncs-bm
5566
/lib/bm_timer/ @nrfconnect/ncs-bm
5667
/lib/boot_banner/ @nrfconnect/ncs-bm
@@ -89,10 +100,11 @@
89100
/sysbuild/ @nrfconnect/ncs-co-build-system
90101

91102
# Tests
103+
/tests/lib/bluetooth/ble_adv/ @nrfconnect/ncs-bm-test
92104
/tests/lib/bluetooth/ble_conn_state/ @nrfconnect/ncs-bm
93105
/tests/lib/bluetooth/ble_qwr/ @nrfconnect/ncs-bm
94106
/tests/lib/bluetooth/ble_racp/ @nrfconnect/ncs-bm
95-
/tests/lib/bluetooth/ble_adv/ @nrfconnect/ncs-bm-test
107+
/tests/lib/bluetooth/ble_radio_notif/ @nrfconnect/ncs-bm
96108
/tests/subsys/bluetooth/services/ @nrfconnect/ncs-bm @nrfconnect/ncs-bm-test
97109
/tests/subsys/fs/bm_zms/ @nrfconnect/ncs-bm @rghaddab
98110
/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
@@ -44,6 +44,15 @@ Bluetooth LE Connection State library
4444
:inner:
4545
:members:
4646

47+
.. _api_ble_radio_notif:
48+
49+
Bluetooth LE Radio Notification library
50+
=======================================
51+
52+
.. doxygengroup:: ble_radio_notification
53+
:inner:
54+
:members:
55+
4756
Bare Metal Buttons library
4857
==========================
4958

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 allows the user to subscribe to the Radio Notification signal to receive notifications before and after radio events.
11+
12+
Overview
13+
********
14+
15+
The library allows the user to register a handler to receive radio notifications and configure the distance in microseconds between the active Radio Notification signal and the radio event.
16+
17+
Configuration
18+
*************
19+
20+
The library is enabled and configured entirely using the Kconfig system.
21+
Set the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION` Kconfig option to enable the library.
22+
23+
The library uses the ``SWI02`` IRQ.
24+
Use the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO` Kconfig option to set the IRQ priority.
25+
The library can be configured to receive notifications before the radio is active, after the radio is active, or both before and after.
26+
This can be chosen by setting 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 option, respectively.
27+
28+
Initialization
29+
==============
30+
31+
The library is initialized by calling the :c:func:`ble_radio_notification_init` function.
32+
33+
Usage
34+
*****
35+
36+
Initialize the library by calling the :c:func:`ble_radio_notification_init` function, specifying the event handler to receive the Radio Notification signal.
37+
You can specify the distance in microseconds between the Radio Notification signal and the start of the radio event.
38+
The signal raised at the start of the radio event has ``active_state`` set to ``true``.
39+
A new Radio Notification signal will be raised when the radio event completes with ``active_state`` set to ``false``.
40+
41+
Dependencies
42+
************
43+
44+
This library uses the following |BMshort| libraries:
45+
46+
* SoftDevice - :kconfig:option:`CONFIG_SOFTDEVICE`
47+
* SoftDevice handler - :kconfig:option:`CONFIG_NRF_SDH`
48+
49+
API documentation
50+
*****************
51+
52+
| Header file: :file:`include/bm/bluetooth/ble_radio_notification.h`
53+
| Source files: :file:`lib/bluetooth/ble_radio_notification/`
54+
55+
: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
@@ -68,6 +68,8 @@ No changes since the latest nRF Connect SDK Bare Metal release.
6868
Libraries
6969
=========
7070

71+
* Added the :ref:`lib_ble_radio_notification` library.
72+
7173
* :ref:`lib_ble_conn_params` library:
7274

7375
* Added missing Kconfig dependencies.
@@ -88,7 +90,7 @@ Samples
8890
Bluetooth samples
8991
-----------------
9092

91-
No changes since the latest nRF Connect SDK Bare Metal release.
93+
Added the :ref:`ble_radio_ntf_sample` sample.
9294

9395
Peripheral samples
9496
------------------
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)