Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
/lib/bm_buttons/ @nrfconnect/ncs-bm
/lib/bm_timer/ @nrfconnect/ncs-bm
/lib/boot_banner/ @nrfconnect/ncs-bm
/lib/event_scheduler/ @nrfconnect/ncs-bm
/lib/bm_scheduler/ @nrfconnect/ncs-bm
/lib/sensorsim/ @nrfconnect/ncs-bm
/lib/zephyr_queue/ @nrfconnect/ncs-eris

Expand Down
4 changes: 2 additions & 2 deletions doc/nrf-bm/api/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ Bare Metal Buttons library
:inner:
:members:

.. _api_event_scheduler:
.. _api_bm_scheduler:

Bare Metal Event Scheduler library
==================================

.. doxygengroup:: event_scheduler
.. doxygengroup:: bm_scheduler
:inner:
:members:

Expand Down
50 changes: 50 additions & 0 deletions doc/nrf-bm/libraries/bm_scheduler.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.. _lib_bm_scheduler:

Bare Metal scheduler
####################

.. contents::
:local:
:depth: 2

The Bare Metal scheduler is a library for scheduling functions to run on the main thread.

Overview
********

This library enables queuing and execution of functions in the main-thread context.
It can be used, for example, to defer the execution of operations from an ISR to the main thread.
This shortens the time spent in the interrupt service routine (ISR).

Configuration
*************

The library is enabled using the Kconfig system.
Set the :kconfig:option:`CONFIG_BM_SCHEDULER` Kconfig option to enable the library.

Use the :kconfig:option:`CONFIG_BM_SCHEDULER_BUF_SIZE` Kconfig option to set the size of the event scheduler buffer that the events are copied into.

Initialization
==============

The library is initialized automatically on application startup.

Usage
*****

The SoftDevice event handler can call the :c:func:`bm_scheduler_defer` function to schedule an event for later execution in the main thread.

To process these deferred events, call the :c:func:`bm_scheduler_process` function regularly in the main application loop.

Dependencies
************

This library does not have any dependencies.

API documentation
*****************

| Header file: :file:`include/bm/bm_scheduler.h`
| Source files: :file:`lib/bm_scheduler/`

:ref:`Bare Metal scheduler library API reference <api_bm_scheduler>`
50 changes: 0 additions & 50 deletions doc/nrf-bm/libraries/event_scheduler.rst

This file was deleted.

6 changes: 5 additions & 1 deletion doc/nrf-bm/release_notes/release_notes_changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ Libraries

* Fixed an issue where the client context was shared between all instances.

* :ref:`lib_bm_scheduler` library:

* Renamed library from ``event_scheduler`` to ``bm_scheduler``.

Samples
=======

Expand Down Expand Up @@ -212,7 +216,7 @@ Documentation
* Added documentation for the :ref:`lib_ble_adv` library.
* Added documentation for the :ref:`lib_ble_gatt_queue` library.
* Added documentation for the :ref:`lib_ble_queued_writes` library.
* Added documentation for the :ref:`lib_event_scheduler` library.
* Added documentation for the :ref:`lib_bm_scheduler` library.
* Added documentation for the :ref:`lib_sensorsim` library.
* Added documentation for the :ref:`lib_storage` library.
* Added documentation for the :ref:`lib_ble_queued_writes` library.
Expand Down
14 changes: 7 additions & 7 deletions include/bm/event_scheduler.h → include/bm/bm_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

/** @file
*
* @defgroup event_scheduler NCS Bare Metal Event Scheduler library
* @defgroup bm_scheduler NCS Bare Metal Event Scheduler library
* @{
*/

#ifndef EVENT_SCHEDULER_H__
#define EVENT_SCHEDULER_H__
#ifndef BM_SCHEDULER_H__
#define BM_SCHEDULER_H__

#include <stdint.h>
#include <zephyr/sys/slist.h>
Expand All @@ -30,7 +30,7 @@ typedef void (*evt_handler_t)(void *evt, size_t len);
*
Copy link
Contributor

@eivindj-nordic eivindj-nordic Nov 19, 2025

Choose a reason for hiding this comment

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

Check event handler typedef above.

Copy link
Contributor

@eivindj-nordic eivindj-nordic Nov 20, 2025

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 called something else than evt_handler_t, it is a bit too generic in my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

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

bump

* An event consists of a function (handler) and some data that the function has to process.
*/
struct event_scheduler_event {
struct bm_scheduler_event {
/**
* @brief Reserved.
*/
Expand Down Expand Up @@ -63,7 +63,7 @@ struct event_scheduler_event {
* @retval -EINVAL Invalid @p data and @p len combination.
* @retval -ENOMEM No memory to schedule this event.
*/
int event_scheduler_defer(evt_handler_t handler, void *data, size_t len);
int bm_scheduler_defer(evt_handler_t handler, void *data, size_t len);

/**
* @brief Process deferred events.
Expand All @@ -72,12 +72,12 @@ int event_scheduler_defer(evt_handler_t handler, void *data, size_t len);
*
* @retval 0 On success.
*/
int event_scheduler_process(void);
int bm_scheduler_process(void);

#ifdef __cplusplus
}
#endif

#endif /* EVENT_SCHEDULER_H__ */
#endif /* BM_SCHEDULER_H__ */

/** @} */
2 changes: 1 addition & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#

add_subdirectory(bluetooth)
add_subdirectory_ifdef(CONFIG_EVENT_SCHEDULER event_scheduler)
add_subdirectory_ifdef(CONFIG_BM_SCHEDULER bm_scheduler)
add_subdirectory_ifdef(CONFIG_BM_BUTTONS bm_buttons)
add_subdirectory_ifdef(CONFIG_BM_TIMER bm_timer)
add_subdirectory_ifdef(CONFIG_SENSORSIM sensorsim)
Expand Down
2 changes: 1 addition & 1 deletion lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
menu "Libraries"

rsource "bluetooth/Kconfig"
rsource "event_scheduler/Kconfig"
rsource "bm_scheduler/Kconfig"
rsource "bm_buttons/Kconfig"
rsource "bm_timer/Kconfig"
rsource "sensorsim/Kconfig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
zephyr_library()
zephyr_library_sources(event_scheduler.c)
zephyr_library_sources(bm_scheduler.c)
8 changes: 4 additions & 4 deletions lib/event_scheduler/Kconfig → lib/bm_scheduler/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
menuconfig EVENT_SCHEDULER
menuconfig BM_SCHEDULER
bool "Event scheduler"
help
A library to defer event processing to main().

if EVENT_SCHEDULER
if BM_SCHEDULER

config EVENT_SCHEDULER_BUF_SIZE
config BM_SCHEDULER_BUF_SIZE
int "Event buffer size"
# Maximum BLE event length is 500 (w/ 247 MTU)
default 512
help
Size of the buffer that events will be copied into.
This is a dedicated heap.

module=EVENT_SCHEDULER
module=BM_SCHEDULER
module-str=Event scheduler
Copy link
Contributor

@MirkoCovizzi MirkoCovizzi Nov 19, 2025

Choose a reason for hiding this comment

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

Shouldn't this be renamed too? Same for the prompt at the top

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe, timer and buttons say: "Buttons library" and "Timer library"
The module-str instead says "Bare metal buttons" and "Bare metal timer"

source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@

#include <errno.h>
#include <string.h>
#include <bm/event_scheduler.h>
#include <bm/bm_scheduler.h>
#include <zephyr/logging/log.h>
#include <zephyr/init.h>
#include <zephyr/sys/sys_heap.h>
#include <zephyr/sys/slist.h>
#include <zephyr/sys/util.h>

LOG_MODULE_REGISTER(event_scheduler, CONFIG_EVENT_SCHEDULER_LOG_LEVEL);
LOG_MODULE_REGISTER(bm_scheduler, CONFIG_BM_SCHEDULER_LOG_LEVEL);

static sys_slist_t event_list;
static struct sys_heap heap;
static uint8_t buf[CONFIG_EVENT_SCHEDULER_BUF_SIZE];
static uint8_t buf[CONFIG_BM_SCHEDULER_BUF_SIZE];

int event_scheduler_defer(evt_handler_t handler, void *data, size_t len)
int bm_scheduler_defer(evt_handler_t handler, void *data, size_t len)
{
uint32_t pm;
struct event_scheduler_event *evt;
struct bm_scheduler_event *evt;

if (!handler) {
return -EFAULT;
Expand All @@ -33,7 +33,7 @@ int event_scheduler_defer(evt_handler_t handler, void *data, size_t len)

pm = __get_PRIMASK();
__disable_irq();
evt = sys_heap_alloc(&heap, sizeof(struct event_scheduler_event) + len);
evt = sys_heap_alloc(&heap, sizeof(struct bm_scheduler_event) + len);
if (!pm) {
__enable_irq();
}
Expand All @@ -59,11 +59,11 @@ int event_scheduler_defer(evt_handler_t handler, void *data, size_t len)
return 0;
}

int event_scheduler_process(void)
int bm_scheduler_process(void)
{
uint32_t pm;
sys_snode_t *node;
struct event_scheduler_event *evt;
struct bm_scheduler_event *evt;

while (!sys_slist_is_empty(&event_list)) {

Expand All @@ -74,7 +74,7 @@ int event_scheduler_process(void)
__enable_irq();
}

evt = CONTAINER_OF(node, struct event_scheduler_event, node);
evt = CONTAINER_OF(node, struct bm_scheduler_event, node);
LOG_DBG("Dispatching event %p to handler %p", evt, evt->handler);
evt->handler(evt->data, evt->len);

Expand All @@ -89,7 +89,7 @@ int event_scheduler_process(void)
return 0;
}

static int event_scheduler_init(void)
static int bm_scheduler_init(void)
{
sys_slist_init(&event_list);
sys_heap_init(&heap, buf, sizeof(buf));
Expand All @@ -99,4 +99,4 @@ static int event_scheduler_init(void)
return 0;
}

SYS_INIT(event_scheduler_init, APPLICATION, 0);
SYS_INIT(bm_scheduler_init, APPLICATION, 0);
2 changes: 1 addition & 1 deletion samples/bluetooth/ble_hids_keyboard/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <bm/bluetooth/peer_manager/nrf_ble_lesc.h>
#include <bm/bluetooth/peer_manager/peer_manager.h>
#include <bm/bluetooth/peer_manager/peer_manager_handler.h>
#include <bm/event_scheduler.h>
#include <bm/bm_scheduler.h>
#include <zephyr/sys/ring_buffer.h>
#include <zephyr/toolchain.h>
#include <zephyr/logging/log.h>
Expand Down
2 changes: 1 addition & 1 deletion samples/bluetooth/ble_hids_mouse/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <bm/softdevice_handler/nrf_sdh.h>
#include <bm/softdevice_handler/nrf_sdh_ble.h>
#include <bm/event_scheduler.h>
#include <bm/bm_scheduler.h>
#include <bm/bm_buttons.h>
#include <bm/bm_timer.h>
#include <bm/sensorsim.h>
Expand Down
2 changes: 1 addition & 1 deletion subsys/softdevice_handler/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ config NRF_SDH_DISPATCH_MODEL_IRQ

config NRF_SDH_DISPATCH_MODEL_SCHED
bool "Scheduler"
depends on EVENT_SCHEDULER
depends on BM_SCHEDULER
help
SoftDevice events are passed to the application using the scheduler.

Expand Down
4 changes: 2 additions & 2 deletions subsys/softdevice_handler/nrf_sdh.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <stdint.h>
#include <nrf_sdm.h>
#include <bm/softdevice_handler/nrf_sdh.h>
#include <bm/event_scheduler.h>
#include <bm/bm_scheduler.h>
#include <zephyr/toolchain.h>
#include <zephyr/logging/log.h>
#include <zephyr/sys/atomic.h>
Expand Down Expand Up @@ -333,7 +333,7 @@ void SD_EVT_IRQHandler(void)
{
int err;

err = event_scheduler_defer(sdh_events_poll, NULL, 0);
err = bm_scheduler_defer(sdh_events_poll, NULL, 0);
if (err) {
LOG_WRN("Unable to schedule SoftDevice event, err %d", err);
}
Expand Down