Skip to content

Commit 2f5eb93

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 2f5eb93

File tree

19 files changed

+634
-0
lines changed

19 files changed

+634
-0
lines changed

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

include/ble_radio_notification.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 The time from an Active event until the radio is activated.
33+
* @param[in] evt_handler Handler to be executed when a radio notification event has been
34+
* received.
35+
*
36+
* @return NRF_SUCCESS on successful initialization, otherwise an error code.
37+
*/
38+
uint32_t ble_radio_notification_init(uint32_t distance,
39+
ble_radio_notification_evt_handler_t evt_handler);
40+
41+
#ifdef __cplusplus
42+
}
43+
#endif
44+
45+
#endif /* BLE_RADIO_NOTIFICATION_H__ */
46+
47+
/** @} */

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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
config BLE_RADIO_NOTIFICATION_IRQ_PRIO
12+
int "Radio Notification IRQ priority"
13+
default 3
14+
15+
16+
module=BLE_RADIO_NTF
17+
module-dep=LOG
18+
module-str=BLE Radio Notification
19+
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
20+
21+
endif # BLE_RADIO_NOTIFICATION
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
21+
LOG_MODULE_REGISTER(ble_radio_ntf, CONFIG_BLE_RADIO_NTF_LOG_LEVEL);
22+
23+
/* Current radio state. */
24+
static bool radio_active;
25+
/* Application event handler for handling Radio Notification events. */
26+
static ble_radio_notification_evt_handler_t evt_handler;
27+
28+
STATIC void radio_notification_isr(const void *arg)
29+
{
30+
ARG_UNUSED(arg);
31+
32+
radio_active = !radio_active;
33+
if (evt_handler != NULL) {
34+
evt_handler(radio_active);
35+
}
36+
}
37+
38+
uint32_t ble_radio_notification_init(uint32_t distance,
39+
ble_radio_notification_evt_handler_t _evt_handler)
40+
{
41+
evt_handler = _evt_handler;
42+
43+
/* Initialize Radio Notification software interrupt */
44+
IRQ_DIRECT_CONNECT(RADIO_NOTIFICATION_IRQn, CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO,
45+
radio_notification_isr, 0);
46+
47+
NVIC_ClearPendingIRQ(RADIO_NOTIFICATION_IRQn);
48+
NVIC_EnableIRQ(RADIO_NOTIFICATION_IRQn);
49+
50+
return sd_radio_notification_cfg_set(NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, distance);
51+
}
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_ntf)
11+
12+
target_sources(app PRIVATE src/main.c)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
menu "BLE Radio Notification sample"
8+
9+
config BLE_RADIO_NOTIFICATION_DISTANCE_US
10+
int "Distance between the active notification signal and start of radio event preparation"
11+
range 50 5500
12+
default 800
13+
14+
module=BLE_RADIO_NTF_SAMPLE
15+
module-dep=LOG
16+
module-str=BLE Radio Notification Sample
17+
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
18+
19+
endmenu # "BLE Radio Notification sample"
20+
21+
source "Kconfig.zephyr"

0 commit comments

Comments
 (0)