From a906f03a253e906c9c9a8f37188db868a85a9b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20P=C3=A9rez=20Penichet?= Date: Fri, 26 Oct 2018 16:28:20 +0200 Subject: [PATCH] cc2420 return to last state when disabling carrier Made cc2420 follow the same logic as cc2538 when disabling the unmodulated carrier. Now they both return to the state they were in before the carrier was enabled. --- arch/cpu/cc2538/dev/cc2538-rf.c | 2 +- arch/dev/cc2420/cc2420.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/cpu/cc2538/dev/cc2538-rf.c b/arch/cpu/cc2538/dev/cc2538-rf.c index 23e3e11e0..cee2197e7 100644 --- a/arch/cpu/cc2538/dev/cc2538-rf.c +++ b/arch/cpu/cc2538/dev/cc2538-rf.c @@ -397,7 +397,7 @@ get_sfd_timestamp(void) } /*---------------------------------------------------------------------------*/ /* Enable or disable radio test mode emmiting modulated or unmodulated - * (carrier) signal. See datasheet page XX + * (carrier) signal. See User's Guide pages 719 and 741. */ static uint32_t prev_FRMCTRL0, prev_MDMTEST1; static uint8_t was_on; diff --git a/arch/dev/cc2420/cc2420.c b/arch/dev/cc2420/cc2420.c index 58c77e140..18b289c1d 100644 --- a/arch/dev/cc2420/cc2420.c +++ b/arch/dev/cc2420/cc2420.c @@ -1136,11 +1136,20 @@ set_send_on_cca(uint8_t enable) * (carrier) signal. See datasheet page 55. */ static uint16_t prev_MDMCTRL1, prev_DACTST; +static uint8_t was_on; static void set_test_mode(uint8_t enable, uint8_t modulated) { + radio_value_t mode; + get_value(RADIO_PARAM_POWER_MODE, &mode); + if(enable) { + if(mode == RADIO_POWER_MODE_CARRIER_ON) { + return; + } + was_on = (mode == RADIO_POWER_MODE_ON); + off(); prev_MDMCTRL1 = getreg(CC2420_MDMCTRL1); setreg(CC2420_MDMCTRL1, 0x050C); if(!modulated) { @@ -1150,12 +1159,18 @@ set_test_mode(uint8_t enable, uint8_t modulated) /* actually starts the test mode */ strobe(CC2420_STXON); } else { + if(mode != RADIO_POWER_MODE_CARRIER_ON) { + return; + } + strobe(CC2420_SRFOFF); if(!modulated) { setreg(CC2420_DACTST, prev_DACTST); } setreg(CC2420_MDMCTRL1, prev_MDMCTRL1); /* actually stops the carrier */ - strobe(CC2420_SRFOFF); + if(was_on) { + on(); + } } } /*---------------------------------------------------------------------------*/