Skip to content
Snippets Groups Projects
Commit 64c62e83 authored by Martine Lenders's avatar Martine Lenders Committed by GitHub
Browse files

Merge pull request #5244 from thomaseichinger/pr/rf2xx_better_state_check

drivers/at86rf2xx: improve precondition checks on state transition
parents 7974bf2c 66db33b6
No related branches found
No related tags found
No related merge requests found
...@@ -421,7 +421,16 @@ void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state) ...@@ -421,7 +421,16 @@ void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state)
static inline void _set_state(at86rf2xx_t *dev, uint8_t state) static inline void _set_state(at86rf2xx_t *dev, uint8_t state)
{ {
at86rf2xx_reg_write(dev, AT86RF2XX_REG__TRX_STATE, state); at86rf2xx_reg_write(dev, AT86RF2XX_REG__TRX_STATE, state);
while (at86rf2xx_get_status(dev) != state);
/* To prevent a possible race condition when changing to
* RX_AACK_ON state the state doesn't get read back in that
* case. See discussion
* in https://github.com/RIOT-OS/RIOT/pull/5244
*/
if (state != AT86RF2XX_STATE_RX_AACK_ON) {
while (at86rf2xx_get_status(dev) != state);
}
dev->state = state; dev->state = state;
} }
...@@ -429,9 +438,6 @@ void at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state) ...@@ -429,9 +438,6 @@ void at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state)
{ {
uint8_t old_state = at86rf2xx_get_status(dev); uint8_t old_state = at86rf2xx_get_status(dev);
if (state == old_state) {
return;
}
/* make sure there is no ongoing transmission, or state transition already /* make sure there is no ongoing transmission, or state transition already
* in progress */ * in progress */
while (old_state == AT86RF2XX_STATE_BUSY_RX_AACK || while (old_state == AT86RF2XX_STATE_BUSY_RX_AACK ||
...@@ -440,6 +446,10 @@ void at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state) ...@@ -440,6 +446,10 @@ void at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state)
old_state = at86rf2xx_get_status(dev); old_state = at86rf2xx_get_status(dev);
} }
if (state == old_state) {
return;
}
/* we need to go via PLL_ON if we are moving between RX_AACK_ON <-> TX_ARET_ON */ /* 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 && if ((old_state == AT86RF2XX_STATE_RX_AACK_ON &&
state == AT86RF2XX_STATE_TX_ARET_ON) || state == AT86RF2XX_STATE_TX_ARET_ON) ||
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment