Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rtl872x] dynamically enable Wi-Fi stack on demand and fix BLE race c… #2664

Merged
merged 4 commits into from Jun 27, 2023

Conversation

XuGuohui
Copy link
Member

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

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@XuGuohui XuGuohui force-pushed the enhancement/rtl872x-dynamic-wifi-power branch from b53fa32 to 4d729d8 Compare June 26, 2023 06:43
@XuGuohui XuGuohui requested a review from avtolstoy June 26, 2023 06:52
*
* @returns true if it is initialized, otherwise, false.
*/
bool hal_ble_is_initialized(void* reserved);
Copy link
Member

Choose a reason for hiding this comment

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

Just a nit: for things like this perhaps might be a better idea from the get-go introduce a method to return an enum state, instead of one purpose initialized / not initialized.

@XuGuohui XuGuohui merged commit 3fe9dc9 into develop Jun 27, 2023
12 checks passed
@XuGuohui XuGuohui deleted the enhancement/rtl872x-dynamic-wifi-power branch June 27, 2023 15:22
@technobly technobly added this to the 5.4.1 milestone Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants