-
Notifications
You must be signed in to change notification settings - Fork 2k
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
driver/at86rf2xx: Fix possible race condition where at86rf2xx_configure returns to the wrong state if waited on finished state in at86rf2xx_setstate #7115
Conversation
@DipSwitch Sorry, this one totally flew under my radar. I still fail to see the relation between moving an unmatched check and the mentioned race condition. What was the wrong state you landed in? |
It would try to return to AT86RF2XX_STATE_BUSY_TX_ARET in my case. |
Sorry, it took me a while. I think your change is good, the version below might still optimize the code size a bit. uint8_t at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state)
{
uint8_t old_state;
/* make sure there is no ongoing transmission, or state transition already
* in progress */
do {
old_state = at86rf2xx_get_status(dev);
} while (old_state == AT86RF2XX_STATE_BUSY_RX_AACK ||
old_state == AT86RF2XX_STATE_BUSY_TX_ARET ||
old_state == AT86RF2XX_STATE_IN_PROGRESS)
if (state == AT86RF2XX_STATE_FORCE_TRX_OFF) {
_set_state(dev, AT86RF2XX_STATE_TRX_OFF, state);
return old_state;
}
if (state == old_state) {
return old_state;
}
/* we need to go via PLL_ON if we are moving between RX_AACK_ON <-> TX_ARET_ON */
if ((old_state == AT86RF2XX_STATE_RX_AACK_ON &&
state == AT86RF2XX_STATE_TX_ARET_ON) ||
(old_state == AT86RF2XX_STATE_TX_ARET_ON &&
state == AT86RF2XX_STATE_RX_AACK_ON)) {
_set_state(dev, AT86RF2XX_STATE_PLL_ON, AT86RF2XX_STATE_PLL_ON);
}
/* check if we need to wake up from sleep mode */
else if (old_state == AT86RF2XX_STATE_SLEEP) {
DEBUG("at86rf2xx: waking up from sleep mode\n");
at86rf2xx_assert_awake(dev);
}
if (state == AT86RF2XX_STATE_SLEEP) {
/* First go to TRX_OFF */
at86rf2xx_set_state(dev, AT86RF2XX_STATE_FORCE_TRX_OFF);
/* Discard all IRQ flags, framebuffer is lost anyway */
at86rf2xx_reg_read(dev, AT86RF2XX_REG__IRQ_STATUS);
/* Go to SLEEP mode from TRX_OFF */
gpio_set(dev->params.sleep_pin);
dev->state = state;
} else {
_set_state(dev, state, state);
}
return old_state;
} |
Will update the pr tomorrow. |
Awesome, thanks! I also saw that at least |
Just activated the CI. Can we have a positive review (ACK) and merge this one for the release ? It will also be useful for #7149. |
@DipSwitch, can you merge @thomaseichinger PR and let's merge this PR since we've tested it and it works |
Murdock is complaining for some variable |
4e695c7
to
86a2af0
Compare
@thomaseichinger @DipSwitch I allowed myself to directly push the requested change proposed above and fix Murdock reported issue. Let me know if that fine for you so we can move forward here and here. Thanks ! |
@aabadie, Did you check that what you pushed is same as the PR @thomaseichinger suggested? (the on we ACK from my side) |
Well, I missed it, sorry. Need to compare and will fix asap. |
86a2af0
to
60c78b7
Compare
@biboc, should be fine now. |
Does this fix #5486 by any chance? |
@aabadie Could you please also change the commit message? |
60c78b7
to
cbbc44e
Compare
Done
Every maintainer of RIOT is able to do that under certain conditions. I don't recommend this practice but sometimes it helps. |
ping @thomaseichinger |
ACK for me, wait @thomaseichinger before merging |
when this on is merged, I'll be able to test the OT PR on IoT-LAB tomorrow afternoon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code seems good to me. ACK
@aabadie I think we should do some more thorough release testing for the at86rf2xx though.
Nope :( |
at86rf2xx_configure()
could possibly return to the wrong state after updating the phy's configuration.