What happens when a Windows CE device suspends? What does suspend mean? Let’s look at these, but not in the technical sense of examining all of the details and twists and turns, but in terms that an application developer and maybe a user may want to know.
Suspend, also known as putting the device to sleep or on some devices turning it off, is a way to put a device in a state that it consumes very little electricity. This is important for battery operated devices, like PDAs and cell phones. The system starts to suspend when some software requests that the Operating System (OS) enter suspend.   The software could be the Start button’s Suspend item, some software provided by the device OEM that responds to the user pressing an On/Off switch or the OS itself in the form of a Power Manager that suspends the system when it is not being used.
Once the OS has been asked to suspend, it starts the process of shutting down the subsystems of the device. 
1.       First it notifies the Task Bar that the system is suspending. This is the only application that will be notified that the system is about to suspend. That means that your application cannot be notified of the pending suspend.
2.       Application message queues are shut down. This means that applications will not be receiving messages.
3.       Device drivers are asked by the Power Manager to put the hardware that they control into the appropriate power state for the device for suspend. This means that most of the drivers will power their hardware off, but not necessarily all of them. Some devices may need to keep some of the hardware powered.
4.       The kernel stops scheduling threads to run. Only the suspend thread is left running.
5.       Drivers are asked one more time to power down their hardware, this time the kernel makes the request through the device driver manager.  Many drivers wait until now to power down.
6.       The kernel sets the system up to be resumed, also known as wake up or power up. This means that it allows signals from some of the hardware to restart the system. The signal is usually the input from the power button, but it could be something else like a keyboard, touch panel or Ethernet. The real time clock is usually set to wake the system to run the next scheduled event, like an alarm.
7.       The kernel puts the RAM in a low power state that maintains the data currently stored so that it is available when the system resumes
8.       Finally, the kernel puts the CPU in a low power state
At this point, nothing is running on the CPU, which means that no applications are running, no drivers are running – nothing. The system just sits there waiting for something to wake it back up. That something needs to be hardware. When that happens the system starts to wake up:
1.       The CPU wakes up, which is actually a CPU reset event that causes the bootloader to run. The bootloader jumps back into the kernel where the kernel left off when it suspended.
2.       The kernel puts the RAM back into a power state so that it can use the RAM.
3.       The kernel asks the drivers to power up their hardware.
4.       Threads start to run again.
5.       The power manager asks the drivers to power up their hardware.
6.       The message queues are started.
7.       A message is broadcast to any application that wants to know that the system has just resumed. This is the first time that your application can know that the system suspended.
It is easy to understand why a system would power down all of the hardware, but why would a system leave some of the hardware powered?
·         The system is a music player and leaves the audio hardware powered to play music
·         The system want to wake from some hardware like keyboard or touch panel that must be powered to wake the system
The OEM has the control to determine which hardware should be powered down, and which to leave powered so that they can make systems that make sense for how they will be used.
Copyright © 2009 – Bruce Eitman
All Rights Reserved