Skip to content

Conversation

eivindj-nordic
Copy link
Contributor

Add ble_radio_notification library and sample.

@eivindj-nordic eivindj-nordic added this to the v0.9.0 milestone Sep 2, 2025
@eivindj-nordic eivindj-nordic self-assigned this Sep 2, 2025
@eivindj-nordic eivindj-nordic requested review from a team as code owners September 2, 2025 08:54
@github-actions github-actions bot added changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. doc-required PR must not be merged without tech writer approval. labels Sep 2, 2025
@github-actions
Copy link

github-actions bot commented Sep 2, 2025

You can find the documentation preview for this PR here.

@eivindj-nordic eivindj-nordic requested a review from a team as a code owner September 2, 2025 08:59
@github-actions github-actions bot removed the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Sep 2, 2025
@eivindj-nordic eivindj-nordic force-pushed the radio_notif branch 4 times, most recently from 8c2a381 to 974e8c4 Compare September 2, 2025 14:22
CODEOWNERS Outdated
/tests/lib/bm_zms/ @nrfconnect/ncs-bm @rghaddab
/tests/lib/ble_qwr/ @nrfconnect/ncs-bm
/tests/lib/ble_racp/ @nrfconnect/ncs-bm
/tests/lib/ble_radio_notif/ @nrfconnect/ncs-bm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alignment is off

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected.

#define STATIC static
#endif

LOG_MODULE_REGISTER(ble_radio_ntf, CONFIG_BLE_RADIO_NTF_LOG_LEVEL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOG_MODULE_REGISTER(ble_radio_ntf, CONFIG_BLE_RADIO_NTF_LOG_LEVEL);
LOG_MODULE_REGISTER(ble_radio_notification, CONFIG_BLE_RADIO_NOTIFICATION_LOG_LEVEL);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed

IRQ Priority level 0 and 4 are reserved by the SoftDevice.


module=BLE_RADIO_NTF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
module=BLE_RADIO_NTF
module=BLE_RADIO_NOTIFICATION

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed.

range 50 5500
default 800

module=BLE_RADIO_NTF_SAMPLE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix names as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 58 to 64
void setUp(void)
{
}
void tearDown(void)
{
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void setUp(void)
{
}
void tearDown(void)
{
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

/* Application event handler for handling Radio Notification events. */
static ble_radio_notification_evt_handler_t evt_handler;

STATIC void radio_notification_isr(const void *arg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we using STATIC here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se definition above. It is to be able to call the event handler from the unit test.

}
}

uint32_t ble_radio_notification_init(uint32_t distance,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not when we are returning nrf_error.

type = NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE;
#endif

evt_handler = _evt_handler;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the user be able to unset the callback? If not, we could check against NULL here, and avoid doing at every interrupt before invoking the callback. Otherwise, If it should be possible to unset the callback, we could provide an explicit de-initialization function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will move the check for evt_handler to the initialization. I don't think having a callback-unset would provide much value, unless that is also disabling the IRQ. Though, in that case, if disabling while the radio is active, the radio active state might be messed up.

Comment on lines 36 to 38
#if defined CONFIG_BLE_RADIO_NOTIFICATION_ON_BOTH
radio_active = !radio_active;
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would use the macro IS_ENABLED() here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do that anywhere else, only for runtime if's.

@eivindj-nordic
Copy link
Contributor Author

@nordicjm Please have another look.

:local:
:depth: 2

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
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.

Overview
********

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
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.


The library uses the ``SWI02`` IRQ.
Use the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO` Kconfig option to set the IRQ priority.
The library can be configured to receive notifications before the radio is active, after the radio is active or both before and after.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The library can be configured to receive notifications before the radio is active, after the radio is active or both before and after.
The library can be configured to receive notifications before the radio is active, after the radio is active, or both before and after.

The library uses the ``SWI02`` IRQ.
Use the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO` Kconfig option to set the IRQ priority.
The library can be configured to receive notifications before the radio is active, after the radio is active or both before and after.
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
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.

| Header file: :file:`include/ble_radio_notification.h`
| Source files: :file:`lib/ble_radio_notification/`
.. doxygengroup:: ble_radio_notification
Copy link
Contributor

@MirkoCovizzi MirkoCovizzi Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. doxygengroup:: ble_radio_notification
:ref:`Bluetooth LE Radio Notification library API reference <api_ble_radio_notif>`

extern "C" {
#endif


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra newline.

* @brief Function for initializing the Radio Notification module.
*
* @param[in] distance Distance between the ACTIVE notification signal and start of radio event.
* @param[in] evt_handler Handler to be executed when a radio notification event has been received.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param[in] evt_handler Handler to be executed when a radio notification event has been received.
* @param[in] evt_handler Handler to be called when a radio notification event has been received.

* @param[in] distance Distance between the ACTIVE notification signal and start of radio event.
* @param[in] evt_handler Handler to be executed when a radio notification event has been received.
*
* @return NRF_SUCCESS on successful initialization, otherwise an error code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not be more specific with the error codes returned here?

default BLE_RADIO_NOTIFICATION_ON_BOTH

config BLE_RADIO_NOTIFICATION_ON_ACTIVE
bool "on active"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool "on active"
bool "On active"

bool "on active"

config BLE_RADIO_NOTIFICATION_ON_INACTIVE
bool "on inactive"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool "on inactive"
bool "On inactive"

bool "on inactive"

config BLE_RADIO_NOTIFICATION_ON_BOTH
bool "on both active and inactive"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool "on both active and inactive"
bool "On both active and inactive"

help
IRQ Priority level 0 and 4 are reserved by the SoftDevice.


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra newline.

help
IRQ Priority level 0 and 4 are reserved by the SoftDevice.


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change



module=BLE_RADIO_NOTIFICATION
module-dep=LOG
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
module-dep=LOG

this variable does not exist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used everywhere, including https://github.com/nrfconnect/sdk-nrf-bm/blob/main/samples/boot/mcuboot_recovery_entry/Kconfig#L10. If this should be removed it should be done repo-wide as a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes cleanup in different PR but this PR updated to not add them in the new files

Copy link
Contributor Author

@eivindj-nordic eivindj-nordic Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(removed for the new files in this PR)

Copy link
Contributor Author

@eivindj-nordic eivindj-nordic Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And opened #405 for cleanup.

}

uint32_t ble_radio_notification_init(uint32_t distance,
ble_radio_notification_evt_handler_t _evt_handler)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not start variables with an underscore, this naming is reserved for compiler internal variables

return NRF_ERROR_NULL;
}

#if defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

un-indent line

default 800

module=BLE_RADIO_NOTIFICATION_SAMPLE
module-dep=LOG
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
module-dep=LOG

remove from whole PR

extern void radio_notification_isr(const void *arg);
bool radio_active;

static void ble_radio_notification_evt_handler(bool _radio_active)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above


void on_conn_params_evt(const struct ble_conn_params_evt *evt)
{
int err;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int err;
uint32_t err;


LOG_INF("SoftDevice enabled");

err = ble_radio_notification_init(CONFIG_BLE_RADIO_NOTIFICATION_DISTANCE_US,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns NRF errors. Need to address variable type and log message.

Overview
********

The sample initialize the radio notification library and register a handler to trigger both when the radio will be enabled and disabled.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The sample initialize the radio notification library and register a handler to trigger both when the radio will be enabled and disabled.
The sample initializes the radio notification library and registers a handler to trigger both when the radio will be enabled and disabled.

********

The sample initialize the radio notification library and register a handler to trigger both when the radio will be enabled and disabled.
The handler toggle the LED0 depending on the radio state.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The handler toggle the LED0 depending on the radio state.
The handler toggles the LED0 depending on the radio state.

#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
menuconfig BLE_RADIO_NOTIFICATION
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that this is not expressing the dependency on SoftDevice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. Note that this applies for most of the bluetooth libraries. So we should clean it up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eivindj-nordic What do you mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not have this dependency for many of the other ble libraries. See connection parameters etc.

@eivindj-nordic eivindj-nordic force-pushed the radio_notif branch 6 times, most recently from 137e477 to a34885f Compare October 3, 2025 07:18
@eivindj-nordic eivindj-nordic force-pushed the radio_notif branch 2 times, most recently from fe2b67f to ba0b865 Compare October 3, 2025 11:56
Copy link
Contributor

@anhmolt anhmolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, but please address comments.

@eivindj-nordic
Copy link
Contributor Author

@nordicjm Please have another look.


#include <stdint.h>
#include <stdbool.h>
#include <nrf_soc.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this is not needed here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to c-file.

CONFIG_LOG_BACKEND_BM_UARTE=y

CONFIG_SOFTDEVICE=y
CONFIG_NRF_SDH=y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just CONFIG_SOFTDEVICE should work now

CONFIG_BLE_ADV_FAST_ADVERTISING_INTERVAL=400
CONFIG_BLE_ADV_SLOW_ADVERTISING_INTERVAL=1600
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to override defaults here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly no, though it makes it more observable by looking at the LED. With default intervals it blinks quite fast regardless of the advertising mode.

NRF54L15_XXAA
CONFIG_BLE_RADIO_NOTIFICATION_ON_BOTH=1
CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO=5
SWI02_IRQn=0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhm why SWI02_IRQn=0 (equal zero?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just needed to be defined to something, updated to 30 as is what it is defined to for nRF54l15.

@eivindj-nordic eivindj-nordic force-pushed the radio_notif branch 2 times, most recently from 142bcf3 to 8cc6735 Compare October 21, 2025 12:16
Add ble_radio_notification library and sample.

Signed-off-by: Eivind Jølsgard <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-required PR must not be merged without tech writer approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants