-
Notifications
You must be signed in to change notification settings - Fork 13
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
Open
eivindj-nordic
wants to merge
1
commit into
nrfconnect:main
Choose a base branch
from
eivindj-nordic:radio_notif
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+656
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
.. _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 notification prior to 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. | ||
|
||
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. | ||
|
||
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. | ||
This 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/ble_radio_notification.h` | ||
| Source files: :file:`lib/ble_radio_notification/` | ||
.. doxygengroup:: ble_radio_notification |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2018-2025 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
/** @file | ||
* | ||
* @defgroup ble_radio_notification Radio Notification Event Handler | ||
* | ||
* @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> | ||
#include <nrf_soc.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. | ||
* | ||
* @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. | ||
*/ | ||
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__ */ | ||
|
||
/** @} */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# | ||
# Copyright (c) 2025 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
menuconfig BLE_RADIO_NOTIFICATION | ||
bool "BLE Radio Notification" | ||
|
||
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 | ||
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. Perhaps add a range that disallows 0? 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 a help text that level 0 and 4 is reserved by the SoftDevice. |
||
int "Radio Notification IRQ priority" | ||
default 3 | ||
help | ||
IRQ Priority level 0 and 4 are reserved by the SoftDevice. | ||
|
||
|
||
module=BLE_RADIO_NTF | ||
module-dep=LOG | ||
module-str=BLE Radio Notification | ||
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config" | ||
|
||
endif # BLE_RADIO_NOTIFICATION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2018-2025 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <stdlib.h> | ||
|
||
#include <ble_radio_notification.h> | ||
#include <zephyr/logging/log.h> | ||
|
||
#if CONFIG_UNITY | ||
#include <cmsis.h> | ||
#define STATIC | ||
#else | ||
#define STATIC static | ||
#endif | ||
|
||
LOG_MODULE_REGISTER(ble_radio_ntf, CONFIG_BLE_RADIO_NTF_LOG_LEVEL); | ||
|
||
/* Current radio state. */ | ||
#if CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE | ||
static bool radio_active = true; | ||
#else | ||
static bool radio_active; | ||
#endif | ||
|
||
/* 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) | ||
{ | ||
ARG_UNUSED(arg); | ||
|
||
#if defined CONFIG_BLE_RADIO_NOTIFICATION_ON_BOTH | ||
radio_active = !radio_active; | ||
#endif | ||
|
||
if (evt_handler != NULL) { | ||
evt_handler(radio_active); | ||
} | ||
} | ||
|
||
uint32_t ble_radio_notification_init(uint32_t distance, | ||
ble_radio_notification_evt_handler_t _evt_handler) | ||
{ | ||
uint8_t type = NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH; | ||
|
||
#if defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_ACTIVE) | ||
type = NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE; | ||
#elif defined(CONFIG_BLE_RADIO_NOTIFICATION_ON_INACTIVE) | ||
type = NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE; | ||
#endif | ||
|
||
evt_handler = _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(type, distance); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ntf) | ||
|
||
target_sources(app PRIVATE src/main.c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | ||
# 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_NTF_SAMPLE | ||
module-dep=LOG | ||
module-str=BLE Radio Notification Sample | ||
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config" | ||
|
||
endmenu # "BLE Radio Notification sample" | ||
|
||
source "Kconfig.zephyr" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is the correct place to mention it, but some priority levels shall not be used.
This used to be documented in the SDS: https://docs.nordicsemi.com/bundle/sds_s140/page/SDS/s1xx/processor_avail_interrupt_latency/exception_mgmt_sd.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think it can be documented in the Kconfig option at least.