at86rf2xx: fix race conditions and PHY states representation #12069
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.
Contribution description
This PR summarizes in:
1. Define PHY states for the at86rf2xx.
Now the at86rf2xx_set_state function receives a PHY state instead of an internal AT86RF2XX representation.This simplifies the state machine and integration of Basic Mode:
E.g
at86rf2xx_set_state(dev, AT86RF2XX_PHY_RX)
will internally set the transceiver to AT86RF2XX_STATE_RX_AACK_ON in Extended Mode but to AT86RF2XX_STATE_RX_ON in Basic Mode.2. Now it's possible to retrieve the TRX state with a variable, instead of polling via
at86rf2xx_get_status
.This variable is synchronized with the transceiver via interrupts (e.g RX_START interrupt set
dev->state=AT86RF2XX_PHY_RX_BUSY
. Then, the RX_DONE event sets the variable back to a non BUSY event).See how this simplifies the _isr function and how this prevents race conditions (send command is rejected if "dev->state" is in one of the BUSY states. No need to poll the device).
3. Move from Dynamic buffer protection to Static buffer protection:
Dynamic buffer protection is released on at86rf2xx_fb_stop. The current work around was to go set the transceiver state to PLL_ON before reading the frame buffer.
With static buffer protection the detection of SFD is disabled on RX_END, and re-enabled on packet read/drop.
This changes fix the issue described on #11256 (it makes @miri64 tests pass), so it's an alternative to #11264
Basic Mode support comes next :)
Discussion/RFC
In practice, the RX_START event tells the PHY layer that the SFD was detected. Thus, this event is mandatory for synchronizing the dev->state variable.
Also, the transmission (regardless of Basic or Extended mode) always ends with the TX_DONE event. So, RX_START and TRX_END must be mandatory if a PHY layer is present (so far, the
at86rf2xx_netdev.c
is the PHY layer implementation of the driver).The question is, do we still want the TELL_RX_START, TELL_RX_DONE and TELL_TX_DONE configurations?
If yes, they MUST be activated in the at86rf2xx_netdev layer.
Testing procedure
Run #11256. Check the test passes (that means no "Unexpected payload. This test failed!").
Issues/PRs references
Fixes #11256
Alternative to #11264
Depends on #12062