Synchronize ESPNOWRadio RX frame handoff#2061
Open
robekl wants to merge 1 commit intomeshcore-dev:devfrom
Open
Synchronize ESPNOWRadio RX frame handoff#2061robekl wants to merge 1 commit intomeshcore-dev:devfrom
robekl wants to merge 1 commit intomeshcore-dev:devfrom
Conversation
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
This fixes the ESP-NOW radio receive handoff so callback context no longer races the main loop over a single shared RX buffer.
Problem
ESPNOWRadiocurrently receives frames like this:OnDataRecv()copies bytes into one globalrx_buflast_rx_lenrecvRaw()later readslast_rx_len, copies from that same buffer, and clears the lengthThere is no atomic handoff, no critical section, and no second buffer. If a callback lands while
recvRaw()is reading, the consumer can observe torn data, lose a packet, or read a length that no longer matches the payload currently in the buffer.Fix
This PR replaces the single shared RX slot with a small fixed-size mailbox queue:
recvRaw()pops one complete frame atomically and only then copies it into the caller bufferI also added the small no-op compatibility helpers currently expected by the ESP-NOW companion target (
getPacketsRecvErrors(),setRxBoostedGainMode(),powerOff()) so the intended build target stays green.Why this fixes it
The producer and consumer no longer share one mutable
rx_buf/last_rx_lenpair. A received frame is either fully published in a queue slot or not visible yet, andrecvRaw()only consumes stable slots after claiming them under lock.That removes the callback/main-loop race that previously allowed partial or corrupted reads under load.
Validation
Built successfully:
SenseCapIndicator-ESPNow_comp_radio_usb