[rtl872x] dynamically enable Wi-Fi stack on demand and fix BLE race c… #2664
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
RTL872x-specific:
As of right now, the Wi-Fi stack is enabled on startup to support BLE functionality and it is always enabled during the application's life time. Thus, it consumes extremely high power that is around 60mA.
There is also deadlock and race condition in BLE HAL. The race condition happens when BLE is connected, followed by entering sleep mode.
Solution
Dynamically enable Wi-Fi stack on demand, e.g. requesting to enter BLE provisioning mode or calling
BLE.on()
/WiFi.on()
.Regarding the deadlock in BLE HAL, the workaround is to not acquire the
connectionsMutex_
in disconnect APIs, because they don't actually operate the connections data. The race condition is fixed by always clearing the advertising state explicitly in the stop function.Completeness