Skip to main content

Windows Mobile / Windows CE Device Power States

Hello Folks,

I am back with yet another Windows Mobile / Windows CE article, this time on Power Management and Notifications. You must be wondering why i am posting lot of Windows CE related articles these days, reason is simple i am developing some WinCE device system related application where i need to explore lot of system level stuff. I thought of sharing this useful information to my buddies.
I strongly believe that PDA / Touch Screen Mobiles / Professional Mobile / Dual Mode PDA are going to rule the world and believe me people want everything in this little damn piece of electronic device and many companies are working towards make this possible. Being obsessed with electronic gadgets, sometime i ask myself what i want from my Mobile, i explained to myself that i want following things

1. Robust Phone capabilities
2. High speed internet (preferably WLAN and 3G when i am not in WiFi coverage).
3. An Accurate GPS system with inbuilt Maps (It should latch to GPS satellites in no time, i can wait for 3 - 5 secs not more than that :) ).
4. High precession Touch screen capability (preferably iPhone style or even better ).
5. High performance DVB-H TV (Should not consume more battery when watching TV).
6. Crystal Clear Document Reader.
7. Minimum 16 GB Flash Hard drive ( Higher is always better :) ).
8. Inbuilt or external micro projector (Should be able to project 42" crystal clear picture). Having said that i would also require some Audio/Video input and projector should be capable of handling videos via device WLAN and should be capable of interacting with my Device DVB-H application and all possible combinations. Hurryyyyyyyyyy ... i don't need LCD TV anymore and i can carry it anywhere in the world :).
9. High End camera with Optical zoom (I can compromise on Optical zoom but good to have 3x optical zoom).
10. High end camcorder.

..... list is not finite -:).

Let me a give a break ..... All the above sounds awesome right but each and every add-on consumes hell lot of battery power, so on OEM / ODM perspective it is important to optimize on battery front because any fancy functionality without battery performance is definately going to fail or live up to end users expectations!!!!

So, let me come to my title topic here "Power Notifications", what are they and how to handle them in Windows Mobile.

Device Power State

Device power state definitions are statically predefined. Power Manager passes a device state to a driver, and the driver is responsible for mapping the state to its device capabilities, and then performing the applicable state transition on the device.

The following table describes device power states.

Device power state Registry key Description

Full on

D0

Device is on and running. It is receiving full power from the system and is delivering full functionality to the user.

Low on

D1

Device is fully functional at a lower power or performance state than D0. D1 is applicable when the device is being used, but peak performance is unnecessary and power is at a premium.

Standby

D2

Device is partially powered, with automatic wakeup on request.

Sleep

D3

Device is partially powered, with device-initiated wakeup, if available. A device in state D3 is sleeping but capable of raising the system power state on its own. It consumes only enough power to be able to do so; which must be less than or equal to the amount of power used in state D2.

Off

D4

Device has no power. A device in state D4 should not be consuming any significant power. Some peripheral busses require static terminations that intrinsically use non-zero power when a device is physically connected to the bus. A device on such a bus can still support D4.

A physical device does not have to support all of the device power states. The only device power state that all devices must support is the full on state, D0. A driver that is issued a request to enter a power state not supported by its device enters the next available power state supported. For example, if Power Manager requests that it enter D2 and it does not support D2, the device can enter D3 or D4 instead. This can be done if Power Manager supports one of these states. If a device is requested to enter D3 and cannot wake up the system, it should enter D4 and power off, rather than staying in standby. These rules are intended to simplify driver implementation.

Power Manager appropriately maps system power states to the corresponding device power states. For example, if a device only supports device power states D0 and D4, Power Manager does not immediately request that the device enter the D4 power state when it transitions from the full on power state. Power Manager waits until the system enters a system power state in which D3 or D4 is configured as the maximum device power state for that device. If D0, D1, or D2 is configured as the maximum power state, Power Manager keeps the device at D0.

When a device driver is loaded, it should put the device into full on, D0. Before a driver is unloaded, if possible, it should put the device into off, D4. If a device enters another device power state at startup, it can issue a DevicePowerNotify request while processing IOCTL_POWER_CAPABILITIES.

How to Handle them in Windows CE

You can use following APIs to get power notifications
HANDLE RequestPowerNotifications(
HANDLE hMsgQ,
DWORD Flags
);
This function allows applications and drivers to register for power notification events.

Parameters

hMsgQ
[in] Handle to the application's message queue created with CreateMsgQueue.
Flags
[in] Set to the logical-or of the desired PBT_XXX notifications, or to POWER_NOTIFY_ALL to receive all notifications.

The following table shows the various PBT_XXX notifications.

Notification Description
PBT_TRANSITION Broadcast specifying the system power state transition.
PBT_RESUME Broadcast notifying a resume and specifies the previous state.
PBT_POWERSTATUSCHANGE Broadcast specifying that the power supply has switched either from AC to DC or from DC to AC.
PBT_POWERINFOCHANGE Broadcast specifying that a battery power status field has changed. This notification has an associated POWER_BROADCAST_POWER_INFO structure.

I am running short of my time ... I shall come back very soon with a full fledged example. Please mail me incase if you need any help on Power Management.

PS: Part of this article has been taken from Microsoft MSDN.

Comments

Popular posts from this blog

WinCE / PocketPC / Windows Mobile Power Battery Timeout - Solution

Hello Folks, I am back with yet another WinCE / Windows Mobile Solution this time it is something exciting and it is on Power Batter Suspend timeout related stuff. It is really challenging task to optimize battery life of any embedded device. Sometimes we want to control back light and battery suspend related activities through our program. OK .. here is simple question how do you control Back light, suspend timeout .. etc event through program ? To answer this question one has to understand "How WinCE operates w.r.t Power driver and what exactly happens behind the scenes". To simplify things ... i am going to divide whole things in three parts 1. WinCE OS Part whihc include Power / Battery drivers. 2. Application 3. Registry Registry : It is the place where all values gets stored i.e it acts as media for storing and retrieving values. I hope it is clear that Registry is nothing but global storage media and it has NO power to trigger anything. So that means it is of new us

What is the Current Directory in Windows CE & Windows Mobile ?

Lately i encountered  a situation where i had to find the current directory from where my application is running and all my config files reside. Question is "How do I find the current directory?" on Windows CE/Mobile devices. Desktop / PC it is just piece of cake but Windows CE / Mobile devices don't have a concept of a current directory.  Which means all pats are absolute and there is no concept called relative path. Due to lack of relative paths most of the files are loaded to the "Windows" directory and that is how Windows directory is crowded. Alternatively you can hard code directory path and insist user to load files always there. But i hate to hard code values or copy files to Windows directory.  So this has triggered to find a solution to identify my current directory. Since there is no concept of a current directory on a Windows CE / Windows Mobile device how would one locate a resource for which only a relative path is known?  That is what following c

Android Bluedroid debugging

Android Bluedroid Debugging  i.e New BT Stack from Android Community: Wow ... its been more than 2 years i updated my blog ... Am i too lazy or too busy or combination of both. Combination of both -:).  Anyways today i see a need to update my blog with some important info regarding Bluedroid debugging. Bluedroid is the latest and greatest Bluetooth stack from Android developed by Google & Broadcom jointly. So obviously Google does not have interest or resources to maintain two stacks hence they are going to drop famous BlueZ stack for good reasons.  BlueZ stack comes with lot of good tools like hcidump for debugging and i see all those tools no more work starting with Android JB MR2 a.k.a 4.3 which has Bluedroid integrated full-fledged.  So Bluedroid got to have new tools or some tools to debug but as usual Google is very poor at documenting the things and they leave finding puzzles to developers out there. SO today's quest is fining the debugging tools for Bluedroid.