Skip to content

Commit 1413262

Browse files
eivindj-nordicb-gent
authored andcommitted
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 1413262

File tree

20 files changed

+632
-2
lines changed

20 files changed

+632
-2
lines changed

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
@@ -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

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+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(ble_radio_notification)
11+
12+
target_sources(app PRIVATE src/main.c)

0 commit comments

Comments
 (0)