Skip to content

Commit 93ae69f

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 2dd6816 commit 93ae69f

File tree

21 files changed

+694
-2
lines changed

21 files changed

+694
-2
lines changed

CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
/lib/ble_gq/ @nrfconnect/ncs-bm
5151
/lib/ble_qwr/ @nrfconnect/ncs-bm
5252
/lib/ble_racp/ @nrfconnect/ncs-bm
53+
/lib/ble_radio_notification/ @nrfconnect/ncs-bm
5354
/lib/bm_buttons/ @nrfconnect/ncs-bm
5455
/lib/bm_storage/ @nrfconnect/ncs-bm
5556
/lib/bm_timer/ @nrfconnect/ncs-bm
@@ -92,6 +93,7 @@
9293
/tests/lib/ble_conn_state/ @nrfconnect/ncs-bm
9394
/tests/lib/ble_qwr/ @nrfconnect/ncs-bm
9495
/tests/lib/ble_racp/ @nrfconnect/ncs-bm
96+
/tests/lib/ble_radio_notif/ @nrfconnect/ncs-bm
9597
/tests/lib/ble_adv/ @nrfconnect/ncs-bm-test
9698
/tests/lib/bm_storage/ @nrfconnect/ncs-bm
9799
/tests/subsys/bluetooth/services/ble_nus/ @nrfconnect/ncs-bm @nrfconnect/ncs-bm-test

doc/nrf-bm/api/api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ Bluetooth LE Connection State library
4444
:inner:
4545
:members:
4646

47+
.. _api_ble_radio_notif:
48+
Bluetooth LE Radio Notification library
49+
=======================================
50+
51+
.. doxygengroup:: ble_radio_notification
52+
:inner:
53+
:members:
54+
4755
Bare Metal Buttons library
4856
==========================
4957

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 notification prior to and after radio events.
11+
12+
Overview
13+
********
14+
15+
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.
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`, :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION_ON_INACTIVE` or :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+
This 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/ble_radio_notification.h`
53+
| Source files: :file:`lib/ble_radio_notification/`
54+
55+
.. doxygengroup:: ble_radio_notification

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ No changes since the latest nRF Connect SDK Bare Metal release.
5252
Libraries
5353
=========
5454

55-
No changes since the latest nRF Connect SDK Bare Metal release.
55+
* Added the :ref:`lib_ble_radio_notification` library.
5656

5757
Samples
5858
=======
5959

6060
Bluetooth samples
6161
-----------------
6262

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

6565
Peripheral samples
6666
------------------

include/ble_radio_notification.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 Event Handler
10+
*
11+
* @brief Module for propagating Radio Notification events to the application.
12+
*/
13+
14+
#ifndef BLE_RADIO_NOTIFICATION_H__
15+
#define BLE_RADIO_NOTIFICATION_H__
16+
17+
#include <stdint.h>
18+
#include <stdbool.h>
19+
#include <nrf_soc.h>
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
26+
/** @brief Application radio notification event handler type. */
27+
typedef void (*ble_radio_notification_evt_handler_t)(bool radio_active);
28+
29+
/**
30+
* @brief Function for initializing the Radio Notification module.
31+
*
32+
* @param[in] distance Distance between the ACTIVE notification signal and start of radio event.
33+
* @param[in] evt_handler Handler to be executed when a radio notification event has been received.
34+
*
35+
* @return NRF_SUCCESS on successful initialization, otherwise an error code.
36+
*/
37+
uint32_t ble_radio_notification_init(uint32_t distance,
38+
ble_radio_notification_evt_handler_t evt_handler);
39+
40+
#ifdef __cplusplus
41+
}
42+
#endif
43+
44+
#endif /* BLE_RADIO_NOTIFICATION_H__ */
45+
46+
/** @} */

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ 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_EVENT_SCHEDULER event_scheduler)
1314
add_subdirectory_ifdef(CONFIG_BM_BUTTONS bm_buttons)
1415
add_subdirectory_ifdef(CONFIG_BM_STORAGE bm_storage)

lib/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 "event_scheduler/Kconfig"
1415
rsource "bm_buttons/Kconfig"
1516
rsource "bm_storage/Kconfig"
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)

lib/ble_radio_notification/Kconfig

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
9+
if BLE_RADIO_NOTIFICATION
10+
11+
choice BLE_RADIO_NOTIFICATION_TYPE
12+
prompt "Radio notification type"
13+
default BLE_RADIO_NOTIFICATION_ON_BOTH
14+
15+
config BLE_RADIO_NOTIFICATION_ON_ACTIVE
16+
bool "on active"
17+
18+
config BLE_RADIO_NOTIFICATION_ON_INACTIVE
19+
bool "on inactive"
20+
21+
config BLE_RADIO_NOTIFICATION_ON_BOTH
22+
bool "on both active and inactive"
23+
24+
endchoice # BLE_RADIO_NOTIFICATION_TYPE
25+
26+
config BLE_RADIO_NOTIFICATION_IRQ_PRIO
27+
int "BLE Radio Notification IRQ priority"
28+
default 3
29+
help
30+
IRQ Priority level 0 and 4 are reserved by the SoftDevice.
31+
32+
33+
module=BLE_RADIO_NOTIFICATION
34+
module-dep=LOG
35+
module-str=BLE Radio Notification
36+
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
37+
38+
endif # BLE_RADIO_NOTIFICATION
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 <stdlib.h>
9+
10+
#include <ble_radio_notification.h>
11+
#include <zephyr/logging/log.h>
12+
13+
#if CONFIG_UNITY
14+
#include <cmsis.h>
15+
#define STATIC
16+
#else
17+
#define STATIC static
18+
#endif
19+
20+
LOG_MODULE_REGISTER(ble_radio_ntf, CONFIG_BLE_RADIO_NOTIFICATION_LOG_LEVEL);
21+
22+
/* Current radio state. */
23+
#if CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE
24+
static bool radio_active = true;
25+
#else
26+
static bool radio_active;
27+
#endif
28+
29+
/* Application event handler for handling Radio Notification events. */
30+
static ble_radio_notification_evt_handler_t evt_handler;
31+
32+
STATIC void radio_notification_isr(const void *arg)
33+
{
34+
ARG_UNUSED(arg);
35+
36+
#if defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_BOTH)
37+
radio_active = !radio_active;
38+
#endif
39+
40+
evt_handler(radio_active);
41+
}
42+
43+
uint32_t ble_radio_notification_init(uint32_t distance,
44+
ble_radio_notification_evt_handler_t _evt_handler)
45+
{
46+
uint8_t type = NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH;
47+
48+
if (!_evt_handler) {
49+
return NRF_ERROR_NULL;
50+
}
51+
52+
#if defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE)
53+
type = NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE;
54+
#elif defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_INACTIVE)
55+
type = NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE;
56+
#endif
57+
58+
evt_handler = _evt_handler;
59+
60+
/* Initialize Radio Notification software interrupt */
61+
IRQ_DIRECT_CONNECT(RADIO_NOTIFICATION_IRQn, CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO,
62+
radio_notification_isr, 0);
63+
64+
NVIC_ClearPendingIRQ(RADIO_NOTIFICATION_IRQn);
65+
NVIC_EnableIRQ(RADIO_NOTIFICATION_IRQn);
66+
67+
return sd_radio_notification_cfg_set(type, distance);
68+
}

0 commit comments

Comments
 (0)