Skip to content

Commit

Permalink
drivers/at86rf2xx: improve precondition checks on state transition
Browse files Browse the repository at this point in the history
The rational behind this change is the following:
If the transceiver is in any *_BUSY state when `at86rf2xx_set_state()`
gets called this would bypass the `(state == old_state)` check and
unneeded state transitions could be triggered.
  • Loading branch information
thomaseichinger committed Nov 1, 2016
1 parent 9fc75c1 commit 4ebbda8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/at86rf2xx/at86rf2xx_getset.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,6 @@ void at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state)
{
uint8_t old_state = at86rf2xx_get_status(dev);

if (state == old_state) {
return;
}
/* make sure there is no ongoing transmission, or state transition already
* in progress */
while (old_state == AT86RF2XX_STATE_BUSY_RX_AACK ||
Expand All @@ -440,6 +437,10 @@ void at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state)
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 */
if ((old_state == AT86RF2XX_STATE_RX_AACK_ON &&
state == AT86RF2XX_STATE_TX_ARET_ON) ||
Expand Down

0 comments on commit 4ebbda8

Please sign in to comment.