Brief Introduction to wince Power Management

Source: Internet
Author: User

The purpose of power management is to save energy. The basic energy-saving method is to make the system sleep in and out at the right time. for example, if you press the on/off button, the timer that monitors user activity times out, or the application call API can make the system sleep, if you press on/off again or other wake-up interruptions, the system will exit sleep. as a result, the power management module is inseparable from user activity, and power management is driven by user activity. GWES is part of the processing of user-system interaction in wince, so the early power management work was implemented by GWES. (GWES: graphics, windows and events subsystem. graphics, windows, and event subsystems. mainly responsible for Graphic Output and user interaction ). however, the power management module provided by GWES is too rough and rigid: All Sub-devices can only have on and suspend statuses, and applications cannot receive any status switch notifications ...... The power management module was introduced not until wince4.0 to replace the power management function in GWES. (Further, to facilitate the centralized management of the power management module, you also need to disable the original GWES power management function. the method is to set disablegwespoweroff = 1 in the Registry HKLM/system/CurrentControlSet/control/power to disable GWES from interfering with power management. the system is disabled by default. in addition, some user activities are still obtained by relying on GWES. Set activityevent = powermanager/activitytimer/useractivity in the Registry HKLM/system/GWe. this tells GWES that when input such as mouse, keyboard, and touch screen occurs, GWES needs to setevent to notify the power management module .)

The new power management module provides more complete and flexible functions. The system power supply can be set freely, the power status of sub-devices can be set separately, and the application can receive power notifications.

[System power supply]

The OEM can define the system power status as needed, such as on, screenoff, useridle, systemidle, and suspend. the system power status is a configuration scheme that represents the system power. It is a collection of power configurations of each sub-device. it sets a possible scenario and develops a power allocation policy in advance for this scenario (which sub-devices are enabled and which sub-devices are disabled ). for example, "on" may represent the general working scenario, the status of all sub-devices being turned on; "screenoff" may represent the scenario where the LCD is turned off by the user, and the LCD backlight power is turned off; useridle indicates that the user has not performed operations for a period of time, and the CPU/SOC enters the Low Power status. Suspend indicates that the device has been idle for a long time and can be suspended, power off status of all non-essential sub-devices; and so on... The definition of the Power status of the system is flexible and free. You can define the power status of the system in the registry. For example:


"Default" = DWORD: 0; D0

"Flags" = DWORD: 10000; power_state_on

The on status is defined above. Flags is the appended state information (hints). The macro definition power_state_on.defaule in PM. h indicates the default state of all sub-devices in this status.

One of the key points of the power management module is to develop a system power management policy, which includes defining the system power status and determining the conditions for switching between States. Take the default version as an example. The simple illustration is as follows:

Child, as shown in the following figure:

On: the status when the user interacts with the system.

Useridle: indicates that the user stops the input but may still be in use, for example, reading a file.

Systemidle: indicates that the user stops using the device, but the processor still works, for example, background file transfer.

Suspend: indicates the sleep state.

When the user is in use, the system is in the on state, the user stops the input, the system is automatically transferred to the useridle state, continue without the input time, enter the systemidle state, after a period of time, the system automatically enters the suspend status. the application can also call setsystempowerstate () to switch the status.

On this basis,Based on your own platform features,New policies can basically meet the needs of conventional products..

1. on/off button. (). the power management module supports the power button function. The most direct way is to add the definition of the power button in PDD, and initialize and detect the key Io. (B ). send messages from outside to the power management module to notify the button events. (c ). use the API to directly convert the status. that is, the system enters the suspend state directly by calling setsystempowerstate without using the buttons provided by the power management module. this is a common practice. We design a streaming driver with a power button. When the button is detected, call the API to convert the system power to suspend.

2. Add the backlight control. For example, open the request to display the driver to turn on the backlight in the on status, and request to display the driver to turn off the backlight in the useridle and systemidle statuses.

[Device power supply]

There are a lot of examples for implementing device drivers that support power management. The following is a brief introduction:

The power management module does not directly implement the power switch control of sub-devices. The power control of sub-devices is controlled by various devices. the power management module requests the device to control its own power supply through IOCTLs driven by the device. the power status of the system is set flexibly and freely, while the power status of the equipment is fixed. Up to five power statuses are available: D0, D1, D2, D3, and D4, which indicate full on, low on, standby, sleep and off.

Not all device drivers support power management (at least, early device drivers do not support power management ). the power management module provides a specification and architecture for device drivers. Drivers meeting the specifications are incorporated into the power management module. the following conditions must be met to support power management for a stream drive control device: 1. declare that you support power management (iclass value ). 2. ioctls.3. the supported Power status and related features must be reported when the driver is loaded. 4. * ** _ powerdown and *** _ powerup interfaces receive System sleep and wake-up notifications. in addition, the design driver should also understand that the device may not have all five States, but can work at least in D0. The power management module may require the device to enter any power status of the device, it is not just the ones that the device reports that it supports. If it is required to enter an unsupported state, it should enter another State that it supports higher power consumption. The current State does not need to be set repeatedly; the power status of the device varies with the power status of the system. in addition to the flow drive, many built-in drivers need to support power management. summary: 1. the display driver uses the extcode interface (setpowermanagement command, similar to IOCTLs) to control the power supply of the display driver and the backlight. 2. the keyboard driver interface keybddriverpowerhandler.3. the touch screen is touchpanelpowerhandler.4. the built-in network miniport driver is the miniportreset interface. 5. the PCMCIA driver is powerup and powerdown. there are also some built-in drivers such as printers and infrared.

[Oal support for power management]

[System idle status]

When no thread is ready to run, the kernel calls oemidle (). this function can be modified and customized by the OEM in BSP. in this function, we usually require the CPU to enter the low power state to save current consumption. generally, the CPU/SOC provides the idle sleep mode. when an interruption or wake-up event occurs, ensure that the CPU rapidly leaves the idle status and returns the running status.

The system idle status is different from the preceding useridle status. The former is driven by CPU load, indicating that the system is idle, and the latter is driven by user activity, indicating that the user is idle.

Recommendation process of an oemidle:

Calculate the next wakeup time based on the dwreschedtime variable.

Judge the sleep type. If needed, adjust the wake-up time.

Idle processor and clock


Determine the wake-up source

Update the curmsec and idle count values.

[System suspend status]

When you press the off button or the application calls the API to enter the suspend state, the kernel calls the oempoweroff () function. the system is suspended in the oempoweroff () function. After the system is awakened, it continues to be executed from where oempoweroff () is suspended. when oempoweroff () is enabled, the sleep mode is selected based on the sleep mode of the CPU chip and the lowest power consumption mode is selected. if the lowest power consumption mode provided by the CPU chip is the powerdown mode, the processing is complicated, because after the wake-up is executed from the reset, the environment during suspension needs to be restored, so that the application does not know that it has been suspended. this process is generally followed: Turn off the screen, clear the framebuffer, save the necessary registers to the memory, set Io, save the General registers, save the wakeup address, static interrupt, clear the cache, enable wake-up of source disconnection, set the SDRAM auto-Refresh, And the CPU enters the powerdown. the wake-up process is the opposite. for other modes other than the powerdown mode, such as the slow clock mode, the process is much simpler. The most important thing is to set the wake-up source (generally any interruption can be awakened), and the SDRAM enters the self-Refresh state.

[SDRAM control]

The power consumption of SDRAM is relatively high. Generally, in addition to LCD backlights, SDRAM is the largest power consumption device in the system. mobile SDRAM and normal SDRAM are common types. Compared with normal SDRAM, mobile SDRAM increases the Temperature Compensation Auto-Refresh, local array auto-Refresh, and deep sleep features, making it more suitable for devices with limited power consumption, (But mobile SDRAM is working at a lower voltage (1.8 ~ 2.5 V), I think, some 3.3v bus CPU may not be suitable, because the bus will increase many levels of conversion circuit .)

In the oempoweroff () function, save the current environment to the SDRAM, and then enable the SDRAM to enter the auto-Refresh state. The CPU can enter the lowest power consumption sleep mode. After waking up, You need to exit the auto-Refresh state.

[Application Layer in Power Supply Management]

The power management module also provides an application layer interface to allow applications to participate in power management.

The application layer can use setsystempowerstate () to set the system power status. You can use setdevicepower to set the power status of sub-devices. You can use setpowerrequirement to notify the power management module to set sub-devices in special power status, does not change with system power supply. in addition, the power management also provides message queues, and the application layer can also send related messages (pbt_resume, pbt_powerstatuschange, pbt_transition, pbt_powerinfochange) through the requestpowerconfigurications function request power management module ).

There may be several considerations for designing an application: Do not use the CPU as quickly as possible. for example, a very small animation, even with only 1% of the CPU, will make some systems unable to enter low power consumption. here is 2: (1) when the application is not in foreground, stop occupying the CPU. (2) When the user does not interact with the application, the CPU usage of the application is stopped. some other applications may be the opposite. When playing a media file, you do not want to automatically enter the suspend mode when you start playing the video. you can (1) reset the timer at some time. (2) or set all the timers to 0 to stop power management (tcpmp is like this ).

[Power management system implementation]

The power management module is a dynamic link library PM. DLL. you can select the power management component in the Pb catalog window to add it to the OS. for example, Microsoft provides two options ). the first represents the complete function, all API full function implementations, and the second represents the empty implementation (interfaces are provided in the form, but empty functions ).

The code structure of the power management module is hierarchical, MDD + PDD. MDD is an abstract public database and does not need to be modified. PDD is platform-related and the main changes are in PDD. for platform features, Microsoft provides two types of PDD examples. one is default and the other is PDA. default is used. if you want to use the PDA version, you must specify the environment variable in the system.Sysgen_pm_pdaMain differences between. Default and PDA versions:

The default version defines four statuses: On, useridle, systemidle, and suspend;

The PDA version defines on, screenoff, unattended, resume, and suspend.

Simple Description of the default version: The useridle status indicates that the user is in use but has no operation. For example, read the. systemidle status description that the user is stopped, but the system still works, such as file transfer.

PDA version Description: screenoff status description user requests to turn off the screen backlight. is automatically disabled by the user. Unlike useridle, useridle is automatically disabled. the unattended status indicates that the background is working and the user is not aware of it. For example, ActiveSync wakes up the system synchronization every five minutes, and then continues the suspend. The resume status describes the wake-up scenario, for example, after a wake-up request, the system determines the status to be switched to within the specified time; otherwise, the system continues the suspend operation.

[How to customize the power management module]

Pm.dllis required by device.exe.exe. device.exe is required first. Check the Device Manager Component in the Pb catalog or sysgen_device variable. Second, you should still select the power management component Power Management full.

Solution 1 (Recommended solution): Create a PM directory in the driver directory of BSP, complete the implementation of the PDD part of the power management module, and link MDD to generate a PM. DLL replaces the PM of the original system. DLL.

PDD refer to the Code platform. cpp provided by Microsoft. The main modification is to increase the Execution Unit of the state transition action.

Solution 2: do not modify the power management part at all, because although the default PDD has no action during status conversion, it broadcasts the pbt_transition message and can intercept the message for status conversion. this approach is not as direct as solution 1. if the process is implemented, a valuable process resource is also wasted.

[Considerations affecting system power consumption]

1. system clock period

The typical wince system clock cycle is 1 ms. Increasing the clock cycle will further reduce the power consumption of devices. You can modify the system clock in oeminit () à oaltimerinit.

2. variable system clock cycle variable tick sched

In a typical design, WinCE generates a system clock interruption every millisecond, so the idle will exit every 1 ms. If no thread is found to be ready, the idle will continue. for designs with limited power consumption, you can consider changing the system clock cycle to the idle status. in this way, the idle status will not be awakened by unnecessary system clock interruptions during the expected period.

3. LCD backlight adjustment policy

The early design used an independent driver to control and adjust the backlight. The principle of the backlight driver was briefly introduced: the backlight driver started a monitoring working thread and kept waiting for three events:

1. backlightchangeevent

2. powerchangedevent)

3. powermanager/activitytimer/useractivity (user input event)

Read the timeout value from the Registry. When a timeout event occurs, turn off the system backlight. when a user re-initiates a 3rd event during the backlight off period, the backlight is turned on. the Registry timeout value determines the working time of the backlight. similar to setting Screen Protection time on PC. in addition, the backlight driver also needs to provide support for switching the system power status. turn off the backlight when power is down, and turn on the backlight when power is up.

The power supply management module can define a system power status to describe the scene where the backlight is off (for example, when the backlight is disabled in the useridle or screenoff status, the backlight is turned on in the on status, the Backlight Drive can be canceled.

4. leakage current of the IO port

No-load Io should be set to the input port. If the input is suspended, the door circuit switch may cause current consumption. The load Io is set according to the situation, and the output is usually low.

5. Battery drive

The main function of battery driver is to monitor the power of the system. It provides other modules and applications to query the power status of the system, such as AC, battary power supply, and battery power.



Appendix: Introduction to the resume status in WinCE

When a resume occurs the kernel is the first to execute. A device will only resume from a halted state if an interrupt occurs and the CPU has been programmed to wake when an interrupt occurs.

To resume a device

  1. The Kernel performs the following clean-up tasks before resuming normal scheduling:

    • If this is an shx, it CILSOemflushcache.
    • CILSInitclockTo re-Initialize timer hardware to a 1 MS tick.
    • CILS filesys.exe with a power on notification.
    • Callgwes with a power on notification.
    • Initializes the kitl interrupt if one is in use.
  2. Power Manager then CILSFilesystempowerfunctionWith the (fsnotify_power_on) argument.
  3. On the resume, GWES performs the following tasks:
    • Restores video memory from Ram.
    • Powers on the window manager.
    • Sets the screen contrast.
    • Shows the startup UI screen, if required.
    • Posts A message to the taskbar to tell it the device has resumed by send a wm_powerbroadcast message with pbt_apmresumesuspend parameter.
    • Sends the same message to the user notification subsystem.
    • Triggers applications that have requested to be triggered on resume.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.