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()
.