Skip to content

Commit e5a75ba

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 36a0ccc commit e5a75ba

File tree

21 files changed

+654
-2
lines changed

21 files changed

+654
-2
lines changed

CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
/lib/ble_gq/ @nrfconnect/ncs-bm
5050
/lib/ble_qwr/ @nrfconnect/ncs-bm
5151
/lib/ble_racp/ @nrfconnect/ncs-bm
52+
/lib/ble_radio_notification/ @nrfconnect/ncs-bm
5253
/lib/bm_buttons/ @nrfconnect/ncs-bm
5354
/lib/bm_storage/ @nrfconnect/ncs-bm
5455
/lib/bm_timer/ @nrfconnect/ncs-bm
@@ -89,6 +90,7 @@
8990
/tests/lib/bm_zms/ @nrfconnect/ncs-bm @rghaddab
9091
/tests/lib/ble_qwr/ @nrfconnect/ncs-bm
9192
/tests/lib/ble_racp/ @nrfconnect/ncs-bm
93+
/tests/lib/ble_radio_notif/ @nrfconnect/ncs-bm
9294
/tests/lib/ble_adv/ @nrfconnect/ncs-bm-test
9395
/tests/lib/bm_storage/ @nrfconnect/ncs-bm
9496

doc/nrf-bm/api/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Advertising and Scan Response Data Encoder
4242
.. doxygengroup:: ble_sdk_lib_advdata
4343
:inner:
4444

45+
Bluetooth LE Radio Notification library
46+
=======================================
47+
48+
.. doxygengroup:: ble_radio_notification
49+
:inner:
50+
4551
Bare Metal Zephyr Memory Storage (ZMS)
4652
======================================
4753

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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. Use the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO` Kconfig option to set the IRQ priority.
24+
25+
Initialization
26+
==============
27+
28+
The library is initialized by calling the :c:func:`ble_radio_notification_init` function.
29+
30+
Usage
31+
*****
32+
33+
Initialize the library by calling the :c:func:`ble_radio_notification_init` function, specifying the event handler to receive the Radio Notification signal.
34+
You can specify the distance in microseconds between the Radio Notification signal and the start of the radio event.
35+
This event has ``active_state`` set to ``true``.
36+
A new Radio Notification signal will be raised when the radio event completes with ``active_state`` set to ``false``.
37+
38+
Dependencies
39+
************
40+
41+
This library uses the following |BMshort| libraries:
42+
43+
* SoftDevice - :kconfig:option:`CONFIG_SOFTDEVICE`
44+
* SoftDevice handler - :kconfig:option:`CONFIG_NRF_SDH`
45+
46+
API documentation
47+
*****************
48+
49+
| Header file: :file:`include/ble_radio_notification.h`
50+
| Source files: :file:`lib/ble_radio_notification/`
51+
52+
.. 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
@@ -8,6 +8,7 @@ add_subdirectory_ifdef(CONFIG_BLE_ADV ble_adv)
88
add_subdirectory_ifdef(CONFIG_BLE_CONN_PARAMS ble_conn_params)
99
add_subdirectory_ifdef(CONFIG_BLE_GATT_QUEUE ble_gq)
1010
add_subdirectory_ifdef(CONFIG_BLE_RACP ble_racp)
11+
add_subdirectory_ifdef(CONFIG_BLE_RADIO_NOTIFICATION ble_radio_notification)
1112
add_subdirectory_ifdef(CONFIG_EVENT_SCHEDULER event_scheduler)
1213
add_subdirectory_ifdef(CONFIG_BM_BUTTONS bm_buttons)
1314
add_subdirectory_ifdef(CONFIG_BM_STORAGE bm_storage)

lib/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ rsource "ble_adv/Kconfig"
99
rsource "ble_conn_params/Kconfig"
1010
rsource "ble_gq/Kconfig"
1111
rsource "ble_racp/Kconfig"
12+
rsource "ble_radio_notification/Kconfig"
1213
rsource "event_scheduler/Kconfig"
1314
rsource "bm_buttons/Kconfig"
1415
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 "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_NTF
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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2018-2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <errno.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_NTF_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+
/* Application event handler for handling Radio Notification events. */
29+
static ble_radio_notification_evt_handler_t evt_handler;
30+
31+
STATIC void radio_notification_isr(const void *arg)
32+
{
33+
ARG_UNUSED(arg);
34+
35+
#if defined CONFIG_BLE_RADIO_NOTIFICATION_ON_BOTH
36+
radio_active = !radio_active;
37+
#endif
38+
39+
if (evt_handler != NULL) {
40+
evt_handler(radio_active);
41+
}
42+
}
43+
44+
uint32_t ble_radio_notification_init(uint32_t distance,
45+
ble_radio_notification_evt_handler_t _evt_handler)
46+
{
47+
uint8_t type = NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH;
48+
49+
#if defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE)
50+
type = NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE;
51+
#elif defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_INACTIVE)
52+
type = NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE;
53+
#endif
54+
55+
evt_handler = _evt_handler;
56+
57+
/* Initialize Radio Notification software interrupt */
58+
IRQ_DIRECT_CONNECT(RADIO_NOTIFICATION_IRQn, CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO,
59+
radio_notification_isr, 0);
60+
61+
NVIC_ClearPendingIRQ(RADIO_NOTIFICATION_IRQn);
62+
NVIC_EnableIRQ(RADIO_NOTIFICATION_IRQn);
63+
64+
return sd_radio_notification_cfg_set(type, distance);
65+
}

0 commit comments

Comments
 (0)