Skip to content

Commit

Permalink
caf: ble_adv: Improve module_state_event broadcast
Browse files Browse the repository at this point in the history
Change improves broadcast of module_state_event. This is done to prevent
reporting MODULE_STATE_READY before Bluetooth LE advertising module is
initialized and ready.

Jira: NCSDK-23082

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
Signed-off-by: Anna Wojdylo <anna.wojdylo@nordicsemi.no>
  • Loading branch information
MarekPieta committed Aug 17, 2023
1 parent 2bcbb80 commit c3784ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ Common Application Framework (CAF)
* :ref:`caf_ble_adv`:

* Updated the dependencies of the :kconfig:option:`CONFIG_CAF_BLE_ADV_FILTER_ACCEPT_LIST` Kconfig option so that it can be used when the Bluetooth controller is running on the network core.
* Improved broadcast of :c:struct:`module_state_event`.
The event informing about entering either :c:enum:`MODULE_STATE_READY` or :c:enum:`MODULE_STATE_OFF` is not submitted until the CAF Bluetooth LE advertising module is initialized and ready.

* :ref:`caf_power_manager`:

Expand Down
27 changes: 17 additions & 10 deletions subsys/caf/modules/ble_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,19 +483,26 @@ static void broadcast_module_state(enum state prev_state, enum state new_state)
bool submit_ready = false;
bool submit_off = false;

if (is_module_state_off(prev_state) && !is_module_state_off(new_state)) {
submit_ready = true;
}
__ASSERT_NO_MSG(is_module_state_disabled(prev_state) ||
!is_module_state_disabled(new_state));

if (!is_module_state_off(prev_state) && is_module_state_off(new_state)) {
submit_off = true;
}
if (is_module_state_disabled(prev_state)) {
if (!is_module_state_disabled(new_state)) {
submit_ready = true;

if (is_module_state_disabled(prev_state) && !is_module_state_disabled(new_state)) {
submit_ready = true;
}
if (is_module_state_off(new_state)) {
submit_off = true;
}
}
} else {
if (is_module_state_off(prev_state) && !is_module_state_off(new_state)) {
submit_ready = true;
}

__ASSERT_NO_MSG(!submit_ready || !submit_off);
if (!is_module_state_off(prev_state) && is_module_state_off(new_state)) {
submit_off = true;
}
}

if (submit_ready) {
module_set_state(MODULE_STATE_READY);
Expand Down

0 comments on commit c3784ca

Please sign in to comment.