Add async firmware cache clearing for multi-bond support#7
Merged
Conversation
Implements functions to clear only the firmware version field from cached DIS info, forcing it to be re-read on next connection. This solves the problem where: 1. Dongle caches MouthPad firmware version for fast reconnection 2. User updates MouthPad firmware directly via system BLE 3. Dongle incorrectly reports old cached version after reconnection New functions: - ble_dis_clear_cached_firmware_for_addr() - Clear for specific device - ble_dis_clear_all_cached_firmware() - Clear for all bonded devices New shell command: - clearfwcache - Clears cached firmware for all bonds This provides the foundation for a future protobuf message that the app can send when initiating a firmware update flow.
Implements handler for ClearFirmwareCacheWrite message that: - Clears cached firmware versions for all bonded devices - Sends ClearFirmwareCacheResponse with success status - Logs the operation for debugging This allows the app to trigger firmware cache clearing when initiating a MouthPad firmware update, preventing false 'update needed' warnings after successful updates. The handler is ready but requires proto definitions to be added to the mouthpad-proto submodule. See PROTO_CHANGES_NEEDED.md for the required proto additions. Handler location: main.c:673-687 Message tags: clear_firmware_cache_write_tag / clear_firmware_cache_response_tag
Regenerated C files from updated proto definitions that include: - ClearFirmwareCacheWrite message - ClearFirmwareCacheResponse message This completes the proto integration for the firmware cache clearing feature.
Created in-memory cache array (dis_cache[4]) that holds DIS info for all bonded devices. This cache is: - Loaded from flash at boot via settings callback - Updated when DIS discovery completes (flash + memory) - Updated when clearfwcache is called (flash + memory) - Queried on device connection to populate device_info Flow: 1. Boot: Load all cached DIS from flash into dis_cache array 2. Device connects: Copy that device's cache entry into device_info 3. Check device_info for firmware (fast path vs slow path decision) 4. DIS discovery completes: Update both flash and dis_cache 5. clearfwcache: Clear firmware field in both flash and dis_cache This ensures: - No flash reads on every connection (only at boot) - clearfwcache takes effect immediately on next reconnection - Multi-bond support: each device has its own cached DIS - Fast reconnection when firmware is cached
- Add mutex protection for dis_cache to prevent race conditions - Implement deferred flash writes using work queue to avoid blocking - Clear in-memory cache immediately, flash writes happen asynchronously - Restore response sending for ClearFirmwareCacheWrite protobuf command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Changes
Test plan