Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions tools/platforms/msp430/pybsl/tos-bsl.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1524,7 +1527,7 @@ def hexify(line, bytes, width=16):
)

#Main:
def main(itest=1):
def main():
global DEBUG
import getopt
filetype = None
Expand All @@ -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:
Expand Down Expand Up @@ -1904,7 +1904,7 @@ def main(itest=1):

if __name__ == '__main__':
try:
main(1)
main()
except SystemExit:
raise #let pass exit() calls
except KeyboardInterrupt:
Expand All @@ -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


1 change: 1 addition & 0 deletions tos/chips/cc2420/CC2420.h
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
1 change: 1 addition & 0 deletions tos/chips/cc2420/control/CC2420ControlC.nc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 37 additions & 9 deletions tos/chips/cc2420/control/CC2420ControlP.nc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,6 +122,7 @@ implementation {
void writeMdmctrl0();
void writeId();
void writeTxctrl();
void startSUCCESS();

task void sync();
task void syncDone();
Expand Down Expand Up @@ -250,6 +252,8 @@ implementation {

writeTxctrl();
}

call StartupTimer.start( CC2420_TIME_OSC );
return SUCCESS;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 ****************/
Expand Down Expand Up @@ -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 ) {
}

Expand Down
19 changes: 14 additions & 5 deletions tos/chips/cc2420/csma/CC2420CsmaP.nc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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() {
Expand Down
9 changes: 8 additions & 1 deletion tos/chips/cc2420/interfaces/CC2420Power.nc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();

}
12 changes: 11 additions & 1 deletion tos/chips/cc2420/lpl/DefaultLplP.nc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions tos/chips/cc2420/lpl/PowerCycleP.nc
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -310,5 +316,3 @@ implementation {
default event void SplitControl.stopDone(error_t error) {
}
}