Skip to content

Commit f6bacee

Browse files
alstrzebonskirlubos
authored andcommitted
doc: Describe CAF module suspend/resume request events support
Updates docs related to newly introduced CAF module suspend/resume request events. Describes how the events are used in nRF Desktop and CAF. Jira: NCSDK-34237 Signed-off-by: Aleksander Strzebonski <[email protected]>
1 parent f2d1dfd commit f6bacee

File tree

9 files changed

+109
-2
lines changed

9 files changed

+109
-2
lines changed

applications/nrf_desktop/board_configuration.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ Sample mouse or dongle (``nrf54h20dk/nrf54h20/cpuapp``)
173173
* Bluetooth LE and USB High-Speed transports are enabled.
174174
Bluetooth LE is configured to use Nordic Semiconductor's SoftDevice Link Layer and Low Latency Packet Mode (LLPM).
175175
USB High-Speed is configured to use the USB next stack (:kconfig:option:`CONFIG_USB_DEVICE_STACK_NEXT`).
176+
The :kconfig:option:`CONFIG_DESKTOP_BLE_ADV_CTRL_ENABLE` and :kconfig:option:`CONFIG_DESKTOP_BLE_ADV_CTRL_SUSPEND_ON_USB` Kconfig options are enabled in mouse configurations to improve the USB High-Speed report rate.
176177
* In ``debug`` configurations, logs are provided through the UART.
177178
For detailed information on working with the nRF54H20 DK, see the :ref:`ug_nrf54h20_gs` documentation.
178179
* The configurations use the Software Updates for Internet of Things (SUIT) and support firmware updates using the :ref:`nrf_desktop_dfu`.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.. _nrf_desktop_ble_adv_ctrl:
2+
3+
Bluetooth LE advertising control module
4+
#######################################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The Bluetooth LE advertising control module is responsible for controlling :ref:`caf_ble_adv`.
11+
The module is used to suspend and resume the |ble_adv|.
12+
For now, the module can only react to the USB state changes.
13+
It suspends the |ble_adv| when the active USB device is connected (USB state is set to :c:enum:`USB_STATE_ACTIVE`).
14+
It resumes the |ble_adv| when the USB is disconnected (USB state is set to :c:enum:`USB_STATE_DISCONNECTED`) and the |ble_adv| was earlier suspended.
15+
This improves the USB High-Speed performance.
16+
17+
Module events
18+
*************
19+
20+
.. include:: event_propagation.rst
21+
:start-after: table_ble_adv_ctrl_start
22+
:end-before: table_ble_adv_ctrl_end
23+
24+
.. note::
25+
|nrf_desktop_module_event_note|
26+
27+
Configuration
28+
*************
29+
30+
This module is disabled by default.
31+
To enable it, set the :ref:`CONFIG_DESKTOP_BLE_ADV_CTRL_ENABLE <config_desktop_app_options>` Kconfig option to ``y``.
32+
To enable the module to suspend and resume the :ref:`caf_ble_adv` when USB state changes, set the :ref:`CONFIG_DESKTOP_BLE_ADV_CTRL_SUSPEND_ON_USB <config_desktop_app_options>` Kconfig option to ``y``.
33+
It is recommended to enable this option if the device supports the USB High-Speed.
34+
35+
Implementation details
36+
**********************
37+
38+
This module subscribes to :c:struct:`usb_state_event` events sent by the |usb_state|.
39+
It reacts to these events by submitting :c:struct:`module_suspend_req_event` and :c:struct:`module_resume_req_event` events to the |ble_adv| when it is required.

applications/nrf_desktop/doc/event_propagation.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ nRF Desktop event propagation
8989
+-----------------------------------------------+------------------------------+ | | |
9090
| :ref:`nrf_desktop_ble_bond` | ``ble_peer_operation_event`` | | | |
9191
+-----------------------------------------------+------------------------------+ | | |
92+
| :ref:`nrf_desktop_ble_adv_ctrl` | ``module_resume_req_event`` | | | |
93+
+-----------------------------------------------+------------------------------+ | | |
94+
| :ref:`nrf_desktop_ble_adv_ctrl` | ``module_suspend_req_event`` | | | |
95+
+-----------------------------------------------+------------------------------+ | | |
9296
| :ref:`nrf_desktop_module_state_event_sources` | ``module_state_event`` | | | |
9397
+-----------------------------------------------+------------------------------+ | | |
9498
| :ref:`nrf_desktop_power_manager` | ``power_down_event`` | | | |
@@ -119,6 +123,21 @@ nRF Desktop event propagation
119123
.. table_ble_adv_end
120124
121125
126+
.. table_ble_adv_ctrl_start
127+
128+
+------------------------------+---------------------+------------------+------------------------------+----------------------------+
129+
| Source Module | Input Event | This Module | Output Event | Sink Module |
130+
+==============================+=====================+==================+==============================+============================+
131+
| :ref:`nrf_desktop_usb_state` | ``usb_state_event`` | ``ble_adv_ctrl`` | | |
132+
+------------------------------+---------------------+ +------------------------------+----------------------------+
133+
| | | | ``module_resume_req_event`` | :ref:`nrf_desktop_ble_adv` |
134+
| | | +------------------------------+----------------------------+
135+
| | | | ``module_suspend_req_event`` | :ref:`nrf_desktop_ble_adv` |
136+
+------------------------------+---------------------+------------------+------------------------------+----------------------------+
137+
138+
.. table_ble_adv_ctrl_end
139+
140+
122141
.. table_ble_bond_start
123142
124143
+-----------------------------------------------+------------------------+--------------+------------------------------+---------------------------------------------+
@@ -1346,6 +1365,8 @@ nRF Desktop event propagation
13461365
| | | +-----------------------------------+---------------------------------------------+
13471366
| | | | ``usb_state_event`` | :ref:`nrf_desktop_battery_charger` |
13481367
| | | | +---------------------------------------------+
1368+
| | | | | :ref:`nrf_desktop_ble_adv_ctrl` |
1369+
| | | | +---------------------------------------------+
13491370
| | | | | :ref:`nrf_desktop_ble_conn_params` |
13501371
| | | | +---------------------------------------------+
13511372
| | | | | :ref:`nrf_desktop_dvfs` |

applications/nrf_desktop/doc/usb_state_pm.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,15 @@ The application power level is imposed using the :c:struct:`power_manager_restri
5454

5555
* If the USB state is set to :c:enum:`USB_STATE_POWERED`, the module restricts the power down level to the :c:enum:`POWER_MANAGER_LEVEL_SUSPENDED`.
5656
* If the USB state is set to :c:enum:`USB_STATE_ACTIVE`, the :c:enum:`POWER_MANAGER_LEVEL_ALIVE` is required.
57-
* If the USB state is set to :c:enum:`USB_STATE_DISCONNECTED`, any power level is allowed.
5857
* If the USB state is set to :c:enum:`USB_STATE_SUSPENDED`, the :c:enum:`POWER_MANAGER_LEVEL_SUSPENDED` is imposed.
5958
The module restricts the power down level to the :c:enum:`POWER_MANAGER_LEVEL_SUSPENDED`.
6059
The module also submits a :c:struct:`force_power_down_event` to force a quick power down.
60+
* If the USB state is set to :c:enum:`USB_STATE_DISCONNECTED`, any power level is allowed.
61+
While disconnecting the USB cable, the :c:enum:`USB_STATE_SUSPENDED` USB state might be reported before the :c:enum:`USB_STATE_DISCONNECTED` USB state.
62+
For the application to behave consistently regardless of whether the :c:enum:`USB_STATE_SUSPENDED` USB state was reported, the module also submits a :c:struct:`force_power_down_event` to force a quick power down.
63+
The module initially restricts the power down level to the :c:enum:`POWER_MANAGER_LEVEL_SUSPENDED`.
64+
Then, after the :ref:`CONFIG_DESKTOP_USB_PM_RESTRICT_REMOVE_DELAY_MS <config_desktop_app_options>` configurable delay, the module removes the power down level restriction.
65+
This allows you to take actions, such as restart Bluetooth LE advertising, after disconnecting the USB cable without going through reboot.
6166

6267
System power management latency
6368
===============================

applications/nrf_desktop/modules.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ These are valid for events that have many listeners or sources, and are gathered
1919
doc/battery_charger.rst
2020
doc/battery_meas.rst
2121
doc/ble_adv.rst
22+
doc/ble_adv_ctrl.rst
2223
doc/ble_bond.rst
2324
doc/ble_conn_params.rst
2425
doc/ble_discovery.rst

applications/nrf_desktop/src/modules/Kconfig.ble_adv_ctrl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ menuconfig DESKTOP_BLE_ADV_CTRL_ENABLE
1515
if DESKTOP_BLE_ADV_CTRL_ENABLE
1616

1717
config DESKTOP_BLE_ADV_CTRL_SUSPEND_ON_USB
18-
bool "Suspend Bluetooth LE adverising when USB is connected"
18+
bool "Suspend Bluetooth LE advertising when USB is connected"
1919
depends on DESKTOP_USB_ENABLE
2020
help
2121
Suspend CAF Bluetooth LE advertising module while HID USB is active.

doc/nrf/libraries/caf/ble_adv.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ The following Kconfig options are available for this module:
2020
* :kconfig:option:`CONFIG_CAF_BLE_ADV`
2121
* :kconfig:option:`CONFIG_CAF_BLE_ADV_PM_EVENTS`
2222
* :kconfig:option:`CONFIG_CAF_BLE_ADV_POWER_DOWN_ON_DISCONNECTION_REASON_0X15`
23+
* :kconfig:option:`CONFIG_CAF_BLE_ADV_MODULE_SUSPEND_EVENTS`
24+
* :kconfig:option:`CONFIG_CAF_BLE_ADV_SUSPEND_ON_READY`
2325
* :kconfig:option:`CONFIG_CAF_BLE_ADV_DIRECT_ADV`
2426
* :kconfig:option:`CONFIG_CAF_BLE_ADV_FAST_ADV`
2527
* :kconfig:option:`CONFIG_CAF_BLE_ADV_FAST_ADV_TIMEOUT`
@@ -71,6 +73,14 @@ Synchronizing RPA and advertising data updates
7173
With the :kconfig:option:`CONFIG_BT_PRIVACY` Kconfig option enabled, set the :kconfig:option:`CONFIG_CAF_BLE_ADV_ROTATE_RPA` option to synchronize Resolvable Private Address (RPA) rotation with the undirected advertising data update.
7274
You can control the rotation period with the :kconfig:option:`CONFIG_CAF_BLE_ADV_ROTATE_RPA_TIMEOUT` option and change the randomization factor of the rotation period with the :kconfig:option:`CONFIG_CAF_BLE_ADV_ROTATE_RPA_TIMEOUT_RAND` option.
7375

76+
Suspending the module
77+
=====================
78+
79+
When the :kconfig:option:`CONFIG_CAF_BLE_ADV_MODULE_SUSPEND_EVENTS` Kconfig option is enabled, you can suspend the module using a module suspend request event (:c:struct:`module_suspend_req_event`) directed to this module.
80+
When entering the suspended state, the module stops Bluetooth LE advertising and disconnects connected peers.
81+
You can resume the module using a module resume request event (:c:struct:`module_resume_req_event`) directed to this module.
82+
When the :kconfig:option:`CONFIG_CAF_BLE_ADV_SUSPEND_ON_READY` Kconfig option is enabled, the module is suspended automatically right after initialization.
83+
7484
Power-down
7585
==========
7686

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,13 @@ nRF Desktop
317317
* The :ref:`CONFIG_DESKTOP_HIDS_SUBSCRIBER_REPORT_MAX <config_desktop_app_options>` Kconfig option to :ref:`nrf_desktop_hids`.
318318
The option allows you to limit the number of HID input reports that can be simultaneously processed by the module.
319319
This limits the number of GATT notifications with HID reports in the Bluetooth stack.
320+
* The :ref:`nrf_desktop_ble_adv_ctrl` module that is responsible for controlling the :ref:`caf_ble_adv`.
321+
The module suspends the |ble_adv| when the active USB device is connected (USB state is set to :c:enum:`USB_STATE_ACTIVE`).
322+
The module resumes the |ble_adv| when the USB is disconnected (USB state is set to :c:enum:`USB_STATE_DISCONNECTED`) and the |ble_adv| was earlier suspended.
323+
This improves the USB High-Speed performance.
324+
To enable the module, set the :ref:`CONFIG_DESKTOP_BLE_ADV_CTRL_ENABLE <config_desktop_app_options>` Kconfig option to ``y``.
325+
To enable the module to suspend and resume the |ble_adv| when the USB state changes, set the :ref:`CONFIG_DESKTOP_BLE_ADV_CTRL_SUSPEND_ON_USB <config_desktop_app_options>` Kconfig option to ``y``.
326+
These options are enabled for targets that support the USB High-Speed.
320327

321328
* Updated:
322329

@@ -364,6 +371,12 @@ nRF Desktop
364371

365372
This change in the nRF54L10 partition map is a breaking change and cannot be performed using DFU.
366373
As a result, the DFU procedure will fail if you attempt to upgrade the sample firmware based on one of the |NCS| v3.0 releases.
374+
* The behavior of the :ref:`nrf_desktop_usb_state_pm` on USB cable disconnection.
375+
While disconnecting the USB cable, the :c:enum:`USB_STATE_SUSPENDED` USB state might be reported before the :c:enum:`USB_STATE_DISCONNECTED` USB state.
376+
For application to behave consistently regardless of whether the :c:enum:`USB_STATE_SUSPENDED` USB state was reported, the module submits a :c:struct:`force_power_down_event` to force a quick power down.
377+
The module also restricts the power down level to the :c:enum:`POWER_MANAGER_LEVEL_SUSPENDED`.
378+
Then, after the :ref:`CONFIG_DESKTOP_USB_PM_RESTRICT_REMOVE_DELAY_MS <config_desktop_app_options>` configurable delay, the module removes the power down level restriction.
379+
This allows you to take actions, such as restart Bluetooth LE advertising, after disconnecting the USB cable without going through reboot.
367380

368381
nRF Machine Learning (Edge Impulse)
369382
-----------------------------------
@@ -744,6 +757,13 @@ Common Application Framework
744757
* Removed the tracking of the active Bluetooth connections.
745758
CAF no longer assumes that the Bluetooth Peripheral device (:kconfig:option:`CONFIG_BT_PERIPHERAL`) supports only one simultaneous connection (:kconfig:option:`CONFIG_BT_MAX_CONN`).
746759

760+
* :ref:`caf_ble_adv`:
761+
762+
* Updated the module implementation to handle the newly introduced module suspend request event (:c:struct:`module_suspend_req_event`) and module resume request event (:c:struct:`module_resume_req_event`).
763+
When entering the suspended state, the module stops Bluetooth LE advertising and disconnects connected peers.
764+
To enable support for these events, use the :kconfig:option:`CONFIG_CAF_BLE_ADV_MODULE_SUSPEND_EVENTS` Kconfig option, which is enabled by default.
765+
When the :kconfig:option:`CONFIG_CAF_BLE_ADV_SUSPEND_ON_READY` Kconfig option is enabled, the module is suspended automatically right after initialization.
766+
747767
Debug libraries
748768
---------------
749769

include/caf/events/module_suspend_event.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
extern "C" {
2323
#endif
2424

25+
/**
26+
* @brief Module suspend request event
27+
*
28+
* The event is submitted by a module to request the suspension of another module.
29+
*/
2530
struct module_suspend_req_event {
2631
/** Event header. */
2732
struct app_event_header header;
@@ -35,6 +40,11 @@ struct module_suspend_req_event {
3540

3641
APP_EVENT_TYPE_DECLARE(module_suspend_req_event);
3742

43+
/**
44+
* @brief Module resume request event
45+
*
46+
* The event is submitted by a module to request the resumption of another module.
47+
*/
3848
struct module_resume_req_event {
3949
/** Event header. */
4050
struct app_event_header header;

0 commit comments

Comments
 (0)