-
Notifications
You must be signed in to change notification settings - Fork 21
lib: add ble_radio_notification and sample #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
.. _lib_ble_radio_notification: | ||
|
||
Bluetooth: Radio Notification | ||
############################# | ||
|
||
.. contents:: | ||
:local: | ||
:depth: 2 | ||
|
||
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 radio notifications and configure the distance in microseconds between the active Radio Notification signal and the radio event. | ||
|
||
Configuration | ||
************* | ||
|
||
The library is enabled and configured entirely using the Kconfig system. | ||
Set the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION` Kconfig option to enable the library. | ||
|
||
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`, the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION_ON_INACTIVE`, or the :kconfig:option:`CONFIG_BLE_RADIO_NOTIFICATION_ON_BOTH` Kconfig option, respectively. | ||
|
||
Initialization | ||
============== | ||
|
||
The library is initialized by calling the :c:func:`ble_radio_notification_init` function. | ||
|
||
Usage | ||
***** | ||
|
||
Initialize the library by calling the :c:func:`ble_radio_notification_init` function, specifying the event handler to receive the Radio Notification signal. | ||
You can specify the distance in microseconds between the Radio Notification signal and the start of the radio event. | ||
The signal raised at the start of the radio event has ``active_state`` set to ``true``. | ||
A new Radio Notification signal will be raised when the radio event completes with ``active_state`` set to ``false``. | ||
|
||
Dependencies | ||
************ | ||
|
||
This library uses the following |BMshort| libraries: | ||
|
||
* SoftDevice - :kconfig:option:`CONFIG_SOFTDEVICE` | ||
* SoftDevice handler - :kconfig:option:`CONFIG_NRF_SDH` | ||
|
||
API documentation | ||
***************** | ||
|
||
| Header file: :file:`include/bm/bluetooth/ble_radio_notification.h` | ||
| Source files: :file:`lib/bluetooth/ble_radio_notification/` | ||
|
||
:ref:`Bluetooth LE Radio Notification library API reference <api_ble_radio_notif>` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2018-2025 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
/** @file | ||
* | ||
* @defgroup ble_radio_notification Radio Notification | ||
* @{ | ||
* | ||
* @brief Module for propagating Radio Notification events to the application. | ||
*/ | ||
|
||
#ifndef BLE_RADIO_NOTIFICATION_H__ | ||
#define BLE_RADIO_NOTIFICATION_H__ | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** @brief Application radio notification event handler type. */ | ||
typedef void (*ble_radio_notification_evt_handler_t)(bool radio_active); | ||
|
||
/** | ||
* @brief Function for initializing the Radio Notification module. | ||
* | ||
* To ensure that the radio notification signal behaves in a consistent way, the radio | ||
* notifications must be configured when there is no protocol stack or other SoftDevice | ||
* activity in progress. It is recommended that the radio notification signal is | ||
* configured directly after the SoftDevice has been enabled. | ||
* | ||
* @param[in] distance Distance between the ACTIVE notification signal and start of radio event. | ||
* @param[in] evt_handler Handler to be called when a radio notification event has been received. | ||
* | ||
* @retval NRF_SUCCESS on successful initialization. | ||
* @retval NRF_ERROR_NULL if @c evt_handler is NULL. | ||
* @retval NRF_ERROR_INVALID_PARAM if the distance is invalid or radio notification type is not | ||
* properly configured. | ||
* @retval NRF_ERROR_INVALID_STATE if the protocol stack or other SoftDevice is running. Stop all | ||
* running activities and retry. | ||
*/ | ||
uint32_t ble_radio_notification_init(uint32_t distance, | ||
ble_radio_notification_evt_handler_t evt_handler); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* BLE_RADIO_NOTIFICATION_H__ */ | ||
|
||
/** @} */ | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# | ||
# Copyright (c) 2025 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
zephyr_library() | ||
zephyr_library_sources(ble_radio_notification.c) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# | ||
# Copyright (c) 2025 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
menuconfig BLE_RADIO_NOTIFICATION | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just realized that this is not expressing the dependency on SoftDevice. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eivindj-nordic What do you mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
bool "BLE Radio Notification" | ||
depends on SOFTDEVICE | ||
|
||
if BLE_RADIO_NOTIFICATION | ||
|
||
choice BLE_RADIO_NOTIFICATION_TYPE | ||
prompt "Radio notification type" | ||
default BLE_RADIO_NOTIFICATION_ON_BOTH | ||
|
||
config BLE_RADIO_NOTIFICATION_ON_ACTIVE | ||
bool "On active" | ||
|
||
config BLE_RADIO_NOTIFICATION_ON_INACTIVE | ||
bool "On inactive" | ||
|
||
config BLE_RADIO_NOTIFICATION_ON_BOTH | ||
bool "On both active and inactive" | ||
|
||
endchoice # BLE_RADIO_NOTIFICATION_TYPE | ||
|
||
config BLE_RADIO_NOTIFICATION_IRQ_PRIO | ||
vegardgu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int "BLE Radio Notification IRQ priority" | ||
default 3 | ||
|
||
module=BLE_RADIO_NOTIFICATION | ||
module-str=BLE Radio Notification | ||
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config" | ||
|
||
endif # BLE_RADIO_NOTIFICATION |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2018-2025 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include <nrf_error.h> | ||
#include <nrf_soc.h> | ||
#include <stdlib.h> | ||
|
||
#include <bm/bluetooth/ble_radio_notification.h> | ||
#include <zephyr/logging/log.h> | ||
|
||
#if CONFIG_UNITY | ||
#include <cmsis.h> | ||
#endif | ||
|
||
LOG_MODULE_REGISTER(ble_radio_ntf, CONFIG_BLE_RADIO_NOTIFICATION_LOG_LEVEL); | ||
|
||
/* Radio notification type. */ | ||
#if defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE) | ||
#define NOTIFICATION_TYPE NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE | ||
#elif defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_INACTIVE) | ||
#define NOTIFICATION_TYPE NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE | ||
#else | ||
#define NOTIFICATION_TYPE NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH | ||
#endif | ||
|
||
/* Application event handler for handling Radio Notification events. */ | ||
static ble_radio_notification_evt_handler_t evt_handler; | ||
|
||
void radio_notification_isr(const void *arg) | ||
{ | ||
static bool radio_active = IS_ENABLED(CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE); | ||
|
||
ARG_UNUSED(arg); | ||
|
||
#if defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_BOTH) | ||
radio_active = !radio_active; | ||
#endif | ||
|
||
if (evt_handler) { | ||
evt_handler(radio_active); | ||
} | ||
} | ||
|
||
uint32_t ble_radio_notification_init(uint32_t distance, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not when we are returning nrf_error. |
||
ble_radio_notification_evt_handler_t notif_evt_handler) | ||
{ | ||
if (!notif_evt_handler) { | ||
return NRF_ERROR_NULL; | ||
} | ||
|
||
evt_handler = notif_evt_handler; | ||
|
||
/* Initialize Radio Notification software interrupt */ | ||
IRQ_DIRECT_CONNECT(RADIO_NOTIFICATION_IRQn, CONFIG_BLE_RADIO_NOTIFICATION_IRQ_PRIO, | ||
radio_notification_isr, 0); | ||
|
||
NVIC_ClearPendingIRQ(RADIO_NOTIFICATION_IRQn); | ||
NVIC_EnableIRQ(RADIO_NOTIFICATION_IRQn); | ||
|
||
return sd_radio_notification_cfg_set(NOTIFICATION_TYPE, distance); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# | ||
# Copyright (c) 2025 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(ble_radio_notification) | ||
|
||
target_sources(app PRIVATE src/main.c) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# Copyright (c) 2025 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
menu "BLE Radio Notification sample" | ||
|
||
config BLE_RADIO_NOTIFICATION_DISTANCE_US | ||
int "Distance between the active notification signal and start of radio event preparation" | ||
range 50 5500 | ||
default 800 | ||
|
||
module=BLE_RADIO_NOTIFICATION_SAMPLE | ||
module-str=BLE Radio Notification Sample | ||
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config" | ||
|
||
endmenu # "BLE Radio Notification sample" | ||
|
||
source "Kconfig.zephyr" |
Uh oh!
There was an error while loading. Please reload this page.