diff --git a/tools/platforms/msp430/pybsl/tos-bsl.in b/tools/platforms/msp430/pybsl/tos-bsl.in index 492f6b35..1c0fd495 100644 --- a/tools/platforms/msp430/pybsl/tos-bsl.in +++ b/tools/platforms/msp430/pybsl/tos-bsl.in @@ -1342,7 +1342,10 @@ class BootStrapLoader(LowLevel): self.bslTxRx(self.BSL_CHANGEBAUD, #Command: change baudrate a, l) #args are coded in adr and len time.sleep(0.010) #recomended delay - self.serialport.setBaudrate(baudrate) + try: + self.serialport.setBaudrate(baudrate) + except AttributeError: + self.serialport.baudrate = baudrate def actionReadBSLVersion(self): """informational output of BSL version number. @@ -1524,7 +1527,7 @@ def hexify(line, bytes, width=16): ) #Main: -def main(itest=1): +def main(): global DEBUG import getopt filetype = None @@ -1548,9 +1551,6 @@ def main(itest=1): dumpivt = 0 dumpinfo = 0 - bsl.invertRST = 1 - bsl.invertTEST = itest - if comPort is None and os.environ.get("GOODFET")!=None: glob_list = glob.glob(os.environ.get("GOODFET")); if len(glob_list) > 0: @@ -1904,7 +1904,7 @@ def main(itest=1): if __name__ == '__main__': try: - main(1) + main() except SystemExit: raise #let pass exit() calls except KeyboardInterrupt: @@ -1913,7 +1913,7 @@ if __name__ == '__main__': sys.exit(1) #set errorlevel for script usage except Exception, msg: #every Exception is caught and displayed if DEBUG: raise #show full trace in debug mode - #sys.stderr.write("\nAn error occoured:\n%s\n" % msg) #short messy in user mode - #sys.exit(1) #set errorlevel for script usage - main(0); + sys.stderr.write("\nAn error occoured:\n%s\n" % msg) #short messy in user mode + sys.exit(1) #set errorlevel for script usage + diff --git a/tos/chips/cc2420/CC2420.h b/tos/chips/cc2420/CC2420.h index 95523622..325dacde 100644 --- a/tos/chips/cc2420/CC2420.h +++ b/tos/chips/cc2420/CC2420.h @@ -190,6 +190,7 @@ enum { enum cc2420_enums { CC2420_TIME_ACK_TURNAROUND = 7, // jiffies CC2420_TIME_VREN = 20, // jiffies + CC2420_TIME_OSC = 64, // jiffies, about 2ms = double respect datasheet CC2420_TIME_SYMBOL = 2, // 2 symbols / jiffy CC2420_BACKOFF_PERIOD = ( 20 / CC2420_TIME_SYMBOL ), // symbols CC2420_MIN_BACKOFF = ( 20 / CC2420_TIME_SYMBOL ), // platform specific? diff --git a/tos/chips/cc2420/control/CC2420ControlC.nc b/tos/chips/cc2420/control/CC2420ControlC.nc index 3557fd3a..118d0817 100644 --- a/tos/chips/cc2420/control/CC2420ControlC.nc +++ b/tos/chips/cc2420/control/CC2420ControlC.nc @@ -86,6 +86,7 @@ implementation { CC2420ControlP.RXCTRL1 -> Spi.RXCTRL1; CC2420ControlP.RSSI -> Spi.RSSI; CC2420ControlP.TXCTRL -> Spi.TXCTRL; + CC2420ControlP.SNOP -> Spi.SNOP; components new CC2420SpiC() as SyncSpiC; CC2420ControlP.SyncResource -> SyncSpiC; diff --git a/tos/chips/cc2420/control/CC2420ControlP.nc b/tos/chips/cc2420/control/CC2420ControlP.nc index 26a0b248..59b9f2df 100644 --- a/tos/chips/cc2420/control/CC2420ControlP.nc +++ b/tos/chips/cc2420/control/CC2420ControlP.nc @@ -70,6 +70,7 @@ module CC2420ControlP @safe() { uses interface CC2420Strobe as SRFOFF; uses interface CC2420Strobe as SXOSCOFF; uses interface CC2420Strobe as SXOSCON; + uses interface CC2420Strobe as SNOP; uses interface Resource as SpiResource; uses interface Resource as RssiResource; @@ -121,6 +122,7 @@ implementation { void writeMdmctrl0(); void writeId(); void writeTxctrl(); + void startSUCCESS(); task void sync(); task void syncDone(); @@ -250,6 +252,8 @@ implementation { writeTxctrl(); } + + call StartupTimer.start( CC2420_TIME_OSC ); return SUCCESS; } @@ -285,7 +289,9 @@ implementation { return SUCCESS; } - + async command bool CC2420Power.isOn() { + return m_state == S_XOSC_STARTED; + } /***************** CC2420Config Commands ****************/ command uint8_t CC2420Config.getChannel() { atomic return m_channel; @@ -434,18 +440,28 @@ implementation { call RSTN.clr(); call RSTN.set(); signal CC2420Power.startVRegDone(); + return; + } + + if( m_state == S_XOSC_STARTING) { + //timeout on interrupt on CCA for oscillator expire + if(!(call SNOP.strobe() & CC2420_STATUS_XOSC16M_STABLE)) { + m_state = S_VREG_STARTED; + call InterruptCCA.disable(); + call StartupTimer.stop(); //to be sure not fire again + call IOCFG1.write( 0 ); + signal CC2420Power.startOscillatorDone(FAIL); + return; + } + + startSUCCESS(); + return; } } /***************** InterruptCCA Events ****************/ async event void InterruptCCA.fired() { - m_state = S_XOSC_STARTED; - call InterruptCCA.disable(); - call IOCFG1.write( 0 ); - writeId(); - call CSN.set(); - call CSN.clr(); - signal CC2420Power.startOscillatorDone(); + startSUCCESS(); } /***************** ActiveMessageAddress Events ****************/ @@ -538,7 +554,19 @@ implementation { ( (CC2420_DEF_RFPOWER & 0x1F) << CC2420_TXCTRL_PA_LEVEL ) ); } } - /***************** Defaults ****************/ + + void startSUCCESS() { + m_state = S_XOSC_STARTED; + call StartupTimer.stop(); //avoid timeout on fired interrupt + call InterruptCCA.disable(); + call IOCFG1.write( 0 ); + writeId(); + call CSN.set(); + call CSN.clr(); + signal CC2420Power.startOscillatorDone(SUCCESS); + } + + /***************** Defaults ****************/ default event void CC2420Config.syncDone( error_t error ) { } diff --git a/tos/chips/cc2420/csma/CC2420CsmaP.nc b/tos/chips/cc2420/csma/CC2420CsmaP.nc index 5f23c997..7c0f07b8 100644 --- a/tos/chips/cc2420/csma/CC2420CsmaP.nc +++ b/tos/chips/cc2420/csma/CC2420CsmaP.nc @@ -215,7 +215,10 @@ implementation { call CC2420Power.startOscillator(); } - async event void CC2420Power.startOscillatorDone() { + async event void CC2420Power.startOscillatorDone(error_t err) { + if(err) + call CC2420Power.stopVReg(); + post startDone_task(); } @@ -255,11 +258,17 @@ implementation { } task void startDone_task() { - call SubControl.start(); - call CC2420Power.rxOn(); + error_t err = FAIL; + if(call CC2420Power.isOn()) { + call SubControl.start(); + call CC2420Power.rxOn(); + call SplitControlState.forceState(S_STARTED); + err = SUCCESS; + } + else + call SplitControlState.forceState(S_STOPPED); call Resource.release(); - call SplitControlState.forceState(S_STARTED); - signal SplitControl.startDone( SUCCESS ); + signal SplitControl.startDone( err ); } task void stopDone_task() { diff --git a/tos/chips/cc2420/interfaces/CC2420Power.nc b/tos/chips/cc2420/interfaces/CC2420Power.nc index 3366bf27..41845751 100644 --- a/tos/chips/cc2420/interfaces/CC2420Power.nc +++ b/tos/chips/cc2420/interfaces/CC2420Power.nc @@ -73,7 +73,7 @@ interface CC2420Power { /** * Signals that the oscillator has been started. */ - async event void startOscillatorDone(); + async event void startOscillatorDone(error_t err); /** * Stop the oscillator. @@ -96,4 +96,11 @@ interface CC2420Power { */ async command error_t rfOff(); + /** + * Query if radio is on + * + * @return TRUE if radio is on, FALSE if is off or in an intermediate state. + */ + async command bool isOn(); + } diff --git a/tos/chips/cc2420/lpl/DefaultLplP.nc b/tos/chips/cc2420/lpl/DefaultLplP.nc index 4c5c63b4..9f276429 100644 --- a/tos/chips/cc2420/lpl/DefaultLplP.nc +++ b/tos/chips/cc2420/lpl/DefaultLplP.nc @@ -261,7 +261,17 @@ implementation { || call SendState.getState() == S_LPL_SENDING) { initializeSend(); } + return; } + /* here radio didn't start for an error, we ask radio on to send, + * so send is not possible, signal with a sendDone fails... + */ + if(!call SendState.isState(S_LPL_NOT_SENDING)) { + call SendState.toIdle(); + call SendDoneTimer.stop(); + signal Send.sendDone(currentSendMsg, FAIL); + } + /* we are not sending, not need to signal the radio On fails */ } event void SubControl.stopDone(error_t error) { @@ -270,7 +280,7 @@ implementation { if(call SendState.getState() == S_LPL_FIRST_MESSAGE || call SendState.getState() == S_LPL_SENDING) { // We're in the middle of sending a message; start the radio back up - post startRadio(); + post startRadio(); } else { call OffTimer.stop(); diff --git a/tos/chips/cc2420/lpl/PowerCycleP.nc b/tos/chips/cc2420/lpl/PowerCycleP.nc index 18f9d357..b8c6aab0 100644 --- a/tos/chips/cc2420/lpl/PowerCycleP.nc +++ b/tos/chips/cc2420/lpl/PowerCycleP.nc @@ -194,6 +194,12 @@ implementation { /***************** SubControl Events ****************/ event void SubControl.startDone(error_t error) { + if(error) { + //radio didn't start, retry + post startRadio(); + return; + } + call RadioPowerState.forceState(S_ON); //call Leds.led2On(); @@ -310,5 +316,3 @@ implementation { default event void SplitControl.stopDone(error_t error) { } } - -