Sun Microsystems V2.0 manual USB inhibits deep sleep, Preconditions for deep sleeping

Page 39

If it is important that your application knows whether or not deep sleep happened, then you can alternatively execute this code:

ISleepManager sleepManager = Spot.getInstance().getSleepManager();

SleepManager.ensureDeepSleep(5000);

This code will either deep sleep for the specified time of 5,000 milliseconds, or throw an UnableToDeepSleepException to explain why deep sleep was not possible. In this case no sleeping will happen, deep or shallow. The section Preconditions for deep sleeping explains the possible reasons for a failure to deep sleep. Note that this feature is only available if you are executing in the master isolate.

USB inhibits deep sleep

USB hosts require that any device that is plugged into a USB port is able to answer requests on the USB bus. This requirement prevents the Sun SPOT from deep sleeping when it is attached to a USB host. A Sun SPOT on USB uses shallow sleep instead. Connecting a simple external battery via the USB socket will not inhibit deep sleep.

Preconditions for deep sleeping

A number of preconditions must be met in order for the Java thread scheduler to decide to deep sleep:

Deep sleep mode must not have been deactivated using the SleepManager (as shown above).

All threads must be blocked either on synchronization primitives or on a timed wait with a time to wake up at least as long as the minimum deep sleep time (including the wake time allowance)

At least one thread must be on a timed wait (that is, the Sun SPOT will not deep sleep if all threads are blocked on synchronization primitives).

All device drivers must store any necessary persistent state in RAM (to protect against the associated hardware being switched off) and agree to deep sleep. A driver may veto deep sleep if switching off its associated hardware would cause problems. In this case all drivers are set up again and a shallow sleep is performed instead.

Deep sleep behaviour of the standard drivers

Device

Condition to permit deep sleep

CC2420

Radio receiver must be off

 

Timer-counter

The counter must be stopped

PIO

All pins claimed must have been released

AIC

All interrupts must be disabled

PowerManager

All peripheral clocks must be off

Note that the appropriate way for an application to turn off the radio receiver is to give your connections the WEAK_ON or OFF policy.

The deep sleep/wake up sequence

The device drivers for the Sun SPOT are written in Java, allowing them to interact with the SleepManager when it is determining if a deep sleep should be performed. The full sequence of activities follows.

1. The Java thread scheduler discovers all threads are blocked, with at least one performing a

Thread.sleep().

39

Image 39
Contents Page Page Contents Http protocol support Introduction Deploying and running a sample application Building and deploying Sun Spot applicationsBuild Successful Total time 3 seconds \MyApplication Ant -Dport=COM2 info Total time 4 seconds \MyApplication Total time 0 seconds \MyApplication Incorporating utility classes into your application Deploying a pre-existing jarManifest and resources Excluding files from the compilationOther user properties Using the Basestation Built-in propertiesOverview Set up Base Station configuration Remote operationIntroduction Connect a Sun Spot base station Background Using short names for SPOTsManaging keys and sharing Sun SPOTs Take suitable actions during over-the-air downloadsSharing Sun SPOTs Changing the owner of a Sun SpotLimitations What is protected?Deploying and running a host application Generating a new key-pairMesh routing Configuring network featuresYour own host application Incorporating pre-existing jars into your host applicationHardware configurations and USB power Trace routeLogging Page Overview of an application ThreadsThread priorities Sun Spot device libraries Sun Spot device libraryDevice Interface Persistent properties Overriding the Ieee address Accessing flash memoryUsart Radio communication library Program Radiogram protocol Server end Client endYou can open server radiogram connections in a similar way Broadcasting Radio properties Turning the receiver off and on Conserving power using deep sleep mode Monitoring radio activityShallow Sleep Deep Sleep Activating deep sleep modeDevice Condition to permit deep sleep USB inhibits deep sleepPreconditions for deep sleeping Deep sleep behaviour of the standard driversWriting a device driver Http protocol support Configuring the http protocolSocket Proxy GUI mode Configuring projects in an IDEClasspath configuration Javadoc/source configurationDebugging Ant selectapplication Configuring Eclipse as a debug client Configuring NetBeans as a debug clientAdvanced topics Using library suitesWith adderlib as your current directory, execute the command Use the command Using the spot client SpotSerialPortException other exception in serial port comms Reference Persistent system propertiesProperty name Meaning Start address Space Use Contents of the arm directoryContents of the lib directory Memory usageContents of the bin directory preverify.exe Contents of the tests directory Contents of the upgrade directory