From dee72c99a3a9c1e5d8cf63a25709dec03762abfc Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Tue, 25 Oct 2016 08:42:11 -0700 Subject: [PATCH] Disable receiver when changing the channel config. (#873) --- examples/platforms/cc2538/radio.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/examples/platforms/cc2538/radio.c b/examples/platforms/cc2538/radio.c index 0a8cb22ed..ee2c8ebbd 100644 --- a/examples/platforms/cc2538/radio.c +++ b/examples/platforms/cc2538/radio.c @@ -69,6 +69,7 @@ static ThreadError sReceiveError; static uint8_t sTransmitPsdu[IEEE802154_MAX_LENGTH]; static uint8_t sReceivePsdu[IEEE802154_MAX_LENGTH]; +static uint8_t sChannel = 0; static PhyState sState = kStateDisabled; static bool sIsReceiverEnabled = false; @@ -109,7 +110,24 @@ void disableReceiver(void) void setChannel(uint8_t channel) { - HWREG(RFCORE_XREG_FREQCTRL) = 11 + (channel - 11) * 5; + if (sChannel != channel) + { + bool enabled = false; + + if (sIsReceiverEnabled) + { + disableReceiver(); + enabled = true; + } + + HWREG(RFCORE_XREG_FREQCTRL) = 11 + (channel - 11) * 5; + sChannel = channel; + + if (enabled) + { + enableReceiver(); + } + } } void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64)