Skip to content

sdh: simplifications and improvements#388

Merged
lemrey merged 16 commits into
nrfconnect:mainfrom
lemrey:sdh
Nov 17, 2025
Merged

sdh: simplifications and improvements#388
lemrey merged 16 commits into
nrfconnect:mainfrom
lemrey:sdh

Conversation

@lemrey
Copy link
Copy Markdown
Contributor

@lemrey lemrey commented Sep 23, 2025

  • Introduce observer priority levels, e.g. HIGHEST, HIGH, USER, USER_LOW, LOWEST
  • Remove NRF_SDH_BLE (no longer configurable)
  • Remove nrf_sdh_app_ram_start_get(), unused and not useful
  • Remove nrf_sdh_is_enabled() in favor of native SoftDevice function
  • Merge request observers with state observers
  • Remove nrf_sdh_request_continue() and add nrf_sdh_observer_ready().
  • Improve functions for stringifying events and export them
  • Split random seed request handling to a dedicated file
  • Put some Kconfigs behind menus

@lemrey lemrey requested review from a team as code owners September 23, 2025 12:38
@lemrey lemrey requested a review from a team September 23, 2025 12:39
@github-actions github-actions Bot added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Sep 23, 2025
@github-actions
Copy link
Copy Markdown

You can find the documentation preview for this PR here.

@lemrey lemrey force-pushed the sdh branch 4 times, most recently from b6616a3 to 9cf07f8 Compare September 24, 2025 07:06
@lemrey lemrey requested a review from a team as a code owner September 24, 2025 07:06
@lemrey lemrey force-pushed the sdh branch 3 times, most recently from 5fd1e4e to 749680f Compare September 24, 2025 09:53
Comment thread subsys/softdevice_handler/Kconfig Outdated
Comment thread subsys/softdevice_handler/Kconfig Outdated
Comment thread subsys/softdevice_handler/Kconfig Outdated
Comment thread subsys/softdevice_handler/rand_seed.c Outdated
Comment thread subsys/softdevice_handler/rand_seed.c Outdated
Comment thread include/nrf_sdh.h Outdated
Comment thread subsys/storage/bm_storage/sd/bm_storage_sd.c
Comment thread subsys/softdevice_handler/nrf_sdh.c
Comment thread subsys/softdevice_handler/nrf_sdh.c Outdated
Comment thread subsys/softdevice_handler/nrf_sdh.c Outdated
Comment thread include/nrf_sdh.h Outdated

/* Helper macros to check for equality */

#define _NRF_SDH_OBSERVER_PRIO_HIGHEST_HIGHEST 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don't use underscores for first character

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alright, will rename

Comment thread include/nrf_sdh_soc.h Outdated
* If :option:`CONFIG_NRF_SDH_STR_TABLES` is enabled, returns the event name.
* Otherwise, returns the supplied integer as a string.
*
* @param evt A NRF_SOC_SVCS enumeration value.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ before symbols links to it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@nordicjm Can you please provide some context on this suggestion? Thanks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks

Comment thread subsys/softdevice_handler/nrf_sdh.c Outdated
};

if (sdh_enabled) {
(void) sd_softdevice_is_enabled(&sd_is_enabled);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
(void) sd_softdevice_is_enabled(&sd_is_enabled);
(void)sd_softdevice_is_enabled(&sd_is_enabled);

fix in whole PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK

@lemrey lemrey force-pushed the sdh branch 3 times, most recently from 5032ba2 to 381bff5 Compare October 3, 2025 12:54
@lemrey lemrey requested a review from a team as a code owner October 3, 2025 12:54
@github-actions github-actions Bot added the doc-required PR must not be merged without tech writer approval. label Oct 3, 2025
@lemrey
Copy link
Copy Markdown
Contributor Author

lemrey commented Oct 3, 2025

Added changlog entries

SoftDevice handler
##################

The SoftDevice handler is a library that handles SoftDevice initialization tasks, and pulls and dispatches the SoftDevice events to registered components.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would be good with more skin on the bone, though I guess that can be added later as well.

No changes since the latest nRF Connect SDK Bare Metal release.
* Removed:

* The ``NRF_SDH_BLE`` Kconfig option.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it should be like this:

Suggested change
* The ``NRF_SDH_BLE`` Kconfig option.
* The ``CONFIG_NRF_SDH_BLE`` Kconfig option.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I ended up dropping this commit

Comment thread doc/nrf-bm/release_notes/release_notes_changelog.rst Outdated
Comment thread include/nrf_sdh.h Outdated
Comment thread include/nrf_sdh.h Outdated
Comment thread subsys/softdevice_handler/nrf_sdh_ble.c Outdated
LOG_MODULE_DECLARE(nrf_sdh, CONFIG_NRF_SDH_LOG_LEVEL);

const char *gap_evt_tostr(int evt)
const char *ble_evt_tostr(int evt)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const char *ble_evt_tostr(int evt)
const char *ble_evt_to_str(int evt)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

echo on above, to_str is english, tostr is not a word

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is corrected in b1bf672, though would be good to have it changed here as well.

Comment thread subsys/softdevice_handler/nrf_sdh_ble.c
@eivindj-nordic eivindj-nordic added this to the v1.0.0 milestone Oct 13, 2025
@eivindj-nordic
Copy link
Copy Markdown
Contributor

@lemrey Please rebase :)

Copy link
Copy Markdown
Contributor

@b-gent b-gent left a comment

Choose a reason for hiding this comment

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

Approving for the changelog items but we will need more rst documentation before the release.

@b-gent b-gent added the doc-postponed PR requires documentation updates, tech writer review happens later. label Oct 29, 2025
@lemrey lemrey requested a review from a team as a code owner November 5, 2025 09:25
@lemrey
Copy link
Copy Markdown
Contributor Author

lemrey commented Nov 6, 2025

@nordicjm could you please have a look again?

* A SoftDevice observer has a defined priority, which determines the order with
* which the observer receives relevant events compared to other observers.
*
* Five priority levels are defined: highest, high, user, user low, lowest.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
* Five priority levels are defined: highest, high, user, user low, lowest.
* Five priority levels are defined: highest, high, user, user low, and lowest.

Add a placeholder entry for sdh to be able to reference it
in the changelog.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
It is more correct to use an SoC observer to do this, rather than doing
it directly in nrf_sdh_soc (the stack observer).  Make the feature
optional, and leave it enabled by default.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Introduce an allowed set of priorities for observers, with validity checks.
These are: HIGHEST, HIGH, USER, USER_LOW, LOWEST.

These could be extended ala SYS_INIT to include a priority within a level,
but it seemed a bit overkill for now.

Each library or piece of code in the SDK shall have an hardcoded priority,
because just changing the priority of one component would break the others.
In general, a component's observer must have a lower priority than the
observers in its dependencies.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Add GATTS and GATTC event strings to the table.
Renamed gap_evt_tostr() to ble_evt_tostr() to reflect that it now
can print all BLE events.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Add a Kconfig menu for clock configuration, to make the menu nicer.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Add a Kconfig menu for BLE configuration, to make the menu nicer.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Rework the functions in nrf_sdh_ble and nrf_sdh_soc that mapped BLE and
SOC events to their stringified version to make them public and align
their names. Instead of printing "unknown" if the event is not known,
default to printing its numerical value in hexadecimal.

That is also the default behavior if CONFIG_NRF_SDH_STR_TABLES is unset,
and the table is not compiled. This is better than toggling the
availability of the whole function, because we avoid conditional
compilation around it.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Update the assert message at the end of the polling loops to print
which kind of event we failed to pull, e.g. SoC or BLE.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
There is no reason for this API to be in this library.
It could be added to a dedicated library later to avoid
having to rely on DT macros to retrieve this information.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
There was a distinction between observers that could stop the SoftDevice
state changes, and those that didn't. The former were called
"request observers" and the latter "state observers".

Since both observers are interested in the SoftDevice state,
this commit merges the two, keeping only "state observers",
for the purpose of simplifying things a bit.

Now, state observers can return non-zero to these events:
- NRF_SDH_STATE_EVT_ENABLE_PREPARE and
- NRF_SDH_STATE_EVT_DISABLE_PREPARE
to halt the state change.

The return value from the observer is ignored for other events.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
These can return -EBUSY, which was missing.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
This patch moves the state observers into RAM and adds a new field
`is_busy` that is used to maintain their busy state when a request
to change the SoftDevice state is made. That is used to avoid
sending the _PREPARE event multiple times to the same observer.

The new function nrf_sdh_observer_ready() inspects the state of all
observers and dispatches the events only to non-ready observers,
differently from nrf_sdh_request_continue() which sent the events to all
observers unconditionally instead.

When the last observer makes itself ready, the SoftDevice state
change takes place (from within nrf_sdh_observer_ready()).

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Use the native SoftDevice function sd_softdevice_is_enabled() instead.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Only check if the SoftDevice handler is suspended,
not if the SoftDevice is enabled.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Rename an internal variable.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Remove these, and force users to put a semicolon themselves.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Nov 14, 2025

CLA assistant check
All committers have signed the CLA.

@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 Nov 14, 2025
@lemrey
Copy link
Copy Markdown
Contributor Author

lemrey commented Nov 17, 2025

@nrfconnect/ncs-bm-test @nrfconnect/ncs-eris please have a look.

@lemrey lemrey merged commit 48e721c into nrfconnect:main Nov 17, 2025
12 checks passed
@lemrey
Copy link
Copy Markdown
Contributor Author

lemrey commented Dec 10, 2025

Added documentation to #515

@lemrey lemrey removed the doc-postponed PR requires documentation updates, tech writer review happens later. label Dec 10, 2025
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.

8 participants