diff --git a/CODEOWNERS b/CODEOWNERS index b06f30e3a0..d40a70b5a3 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -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 diff --git a/doc/nrf-bm/api/api.rst b/doc/nrf-bm/api/api.rst index fc79992291..5460930ac0 100644 --- a/doc/nrf-bm/api/api.rst +++ b/doc/nrf-bm/api/api.rst @@ -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: diff --git a/doc/nrf-bm/libraries/bm_scheduler.rst b/doc/nrf-bm/libraries/bm_scheduler.rst new file mode 100644 index 0000000000..d01d45b1e6 --- /dev/null +++ b/doc/nrf-bm/libraries/bm_scheduler.rst @@ -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 ` diff --git a/doc/nrf-bm/libraries/event_scheduler.rst b/doc/nrf-bm/libraries/event_scheduler.rst deleted file mode 100644 index d054cc4717..0000000000 --- a/doc/nrf-bm/libraries/event_scheduler.rst +++ /dev/null @@ -1,50 +0,0 @@ -.. _lib_event_scheduler: - -Event Scheduler -############### - -.. contents:: - :local: - :depth: 2 - -The event scheduler is used for transferring execution from the interrupt context to the main application context. - -Overview -******** - -In some applications, it is beneficial to defer the execution of certain interrupts, such as those from the SoftDevice, to the main application function. -This shortens the time spent in the interrupt service routine (ISR). -It also allows for lower priority events to be raised before the previous event is fully processed. - -Configuration -************* - -The library is enabled using the Kconfig system. -Set the :kconfig:option:`CONFIG_EVENT_SCHEDULER` Kconfig option to enable the library. - -Use the :kconfig:option:`CONFIG_EVENT_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:`event_scheduler_defer` function to schedule an event for later execution in the main thread. - -To process these deferred events, call the :c:func:`event_scheduler_process` function regularly in the main application function. - -Dependencies -************ - -This library does not have any dependencies. - -API documentation -***************** - -| Header file: :file:`include/bm/event_scheduler.h` -| Source files: :file:`lib/event_scheduler/` - -:ref:`Event Scheduler library API reference ` diff --git a/doc/nrf-bm/release_notes/release_notes_changelog.rst b/doc/nrf-bm/release_notes/release_notes_changelog.rst index ebffc06962..92de979f71 100644 --- a/doc/nrf-bm/release_notes/release_notes_changelog.rst +++ b/doc/nrf-bm/release_notes/release_notes_changelog.rst @@ -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 ======= @@ -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. diff --git a/include/bm/event_scheduler.h b/include/bm/bm_scheduler.h similarity index 76% rename from include/bm/event_scheduler.h rename to include/bm/bm_scheduler.h index 6cefc75c69..6267d93148 100644 --- a/include/bm/event_scheduler.h +++ b/include/bm/bm_scheduler.h @@ -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 #include @@ -23,14 +23,14 @@ extern "C" { /** * @brief Event handler prototype. */ -typedef void (*evt_handler_t)(void *evt, size_t len); +typedef void (*bm_scheduler_fn_t)(void *evt, size_t len); /** * @brief An event to be scheduled for execution in the main thread. * * 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. */ @@ -38,7 +38,7 @@ struct event_scheduler_event { /** * @brief Event handler. */ - evt_handler_t handler; + bm_scheduler_fn_t handler; /** * @brief Event length. */ @@ -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(bm_scheduler_fn_t handler, void *data, size_t len); /** * @brief Process deferred events. @@ -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__ */ /** @} */ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f35177a0ee..f20c816d2c 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -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) diff --git a/lib/Kconfig b/lib/Kconfig index 24e383d0e9..e5b0ca1f42 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -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" diff --git a/lib/event_scheduler/CMakeLists.txt b/lib/bm_scheduler/CMakeLists.txt similarity index 74% rename from lib/event_scheduler/CMakeLists.txt rename to lib/bm_scheduler/CMakeLists.txt index 8d3828386c..17d527cc5e 100644 --- a/lib/event_scheduler/CMakeLists.txt +++ b/lib/bm_scheduler/CMakeLists.txt @@ -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) diff --git a/lib/event_scheduler/Kconfig b/lib/bm_scheduler/Kconfig similarity index 82% rename from lib/event_scheduler/Kconfig rename to lib/bm_scheduler/Kconfig index af3aae8713..34df1327d4 100644 --- a/lib/event_scheduler/Kconfig +++ b/lib/bm_scheduler/Kconfig @@ -3,14 +3,14 @@ # # 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 @@ -18,7 +18,7 @@ config EVENT_SCHEDULER_BUF_SIZE 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 source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config" diff --git a/lib/event_scheduler/event_scheduler.c b/lib/bm_scheduler/bm_scheduler.c similarity index 71% rename from lib/event_scheduler/event_scheduler.c rename to lib/bm_scheduler/bm_scheduler.c index 4a35fa9a2f..aa8acbd1d4 100644 --- a/lib/event_scheduler/event_scheduler.c +++ b/lib/bm_scheduler/bm_scheduler.c @@ -6,23 +6,23 @@ #include #include -#include +#include #include #include #include #include #include -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(bm_scheduler_fn_t handler, void *data, size_t len) { uint32_t pm; - struct event_scheduler_event *evt; + struct bm_scheduler_event *evt; if (!handler) { return -EFAULT; @@ -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(); } @@ -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)) { @@ -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); @@ -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)); @@ -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); diff --git a/samples/bluetooth/ble_hids_keyboard/src/main.c b/samples/bluetooth/ble_hids_keyboard/src/main.c index 801c2d72f6..fee0582b28 100644 --- a/samples/bluetooth/ble_hids_keyboard/src/main.c +++ b/samples/bluetooth/ble_hids_keyboard/src/main.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/samples/bluetooth/ble_hids_mouse/src/main.c b/samples/bluetooth/ble_hids_mouse/src/main.c index 6bc477aad2..3b854eea72 100644 --- a/samples/bluetooth/ble_hids_mouse/src/main.c +++ b/samples/bluetooth/ble_hids_mouse/src/main.c @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/softdevice_handler/Kconfig b/subsys/softdevice_handler/Kconfig index 1c69080d4d..b09b010072 100644 --- a/subsys/softdevice_handler/Kconfig +++ b/subsys/softdevice_handler/Kconfig @@ -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. diff --git a/subsys/softdevice_handler/nrf_sdh.c b/subsys/softdevice_handler/nrf_sdh.c index 94bbafa35b..9b67af0823 100644 --- a/subsys/softdevice_handler/nrf_sdh.c +++ b/subsys/softdevice_handler/nrf_sdh.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -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); }