pbio/drv/bluetooth: Add way to forcefully exit. #391
Merged
+112
−33
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.
Adds a generic way to forcefully stop trying to run Bluetooth functions when the Bluetooth drivers get stuck. Such as mechanism had not yet been implemented after overhauling the Bluetooth drivers.
Before, we used to try to disconnect and stop observing/scanning in the MicroPython deinit, and stop waiting in case of a shutdown request. Now we do it as part of the pbio cleanup, and enforce shutdown if it fails since this is not a recoverable state.
In practice, this was mostly happening on Technic Hub. This was when it would be stuck in a blinking state if an advertising function got stuck.
This commit was tested by adding the following intentional obstacle in one of the Bluetooth functions.
pbio_error_t pbdrv_bluetooth_peripheral_disconnect_func(pbio_os_state_t *state, void *context) { + static pbio_os_timer_t timer; + PBIO_OS_ASYNC_BEGIN(state); + while (true) { + PBIO_OS_AWAIT_MS(state, &timer, 1000); + }This would cause the de-initialization to never complete if a peripheral is connected. With this commit, it will exit the task and proceed to normal shutdown.
It will still save the user program and data, etc.