Power Management (1) of WM/wince code Study Series)

Source: Internet
Author: User

This article studies the power management code based on wince5.0 (Note: On the latest wince 6.0, the power management architecture has been greatly changed ).
This part of code exists in the form of PM. dll in the OS under \ public \ common \ oak \ drivers \ PM.

I. powermanagement Architecture

The Code under \ public \ common \ oak \ drivers \ PM has two power management mechanisms:
One isMinimal power management architectureIn \ public \ common \ oak \ drivers \ PM \ pmstubs \, use the sysgen_pmstubs environment variable to enable this architecture; in this architecture, only the power management API of the message interface class is supported, that is, pmrequestpowernotificati.ONS and pmstoppowernotificationsAnd pmsetsystempowerstate only supports simple processing of suincluded/resuming.
The other isFull power management architectureIn the MDD and PDD directories under \ public \ common \ oak \ drivers \ PM \, use the sysgen_pm environment variable to enable this architecture; in this architecture, all types of Power Management APIs are supported. In the full power management architecture, there are two sub-classes default and PDA. Default is used when sysgen_pm environment variable is used to enable this architecture. sysgen_pm_pda can be used to enable this subclass.
In Windows Mobile 6 (wince 5.0 core), whether it is Windows Mobile 6 Professional/Windows Mobile 6 classic (In \ public \ WPC \ oak \ MISC \ WPC. BAT) or Windows Mobile 6 standard (In \ public \ smartfon \ oak \ MISC \ smartfon. BAT) sysgen_pm = 1, sysgen_pm_pda = 1;
Next I will discuss in detail the PDA subclass.

There are nine system power statuses:
On, useridle, backlightoff, screenoff, unattended, resuming, suincluded, coldreboot, reboot.
Coldreboot and reboot statuses cannot be freely migrated in the power management state machine. They can only be accessed by calling setsystempowerstate.

In addition, Windows Mobile 6 Professional and Windows Mobile 6 classic (PPC) are configured as follows in project. Reg under \ public \ WPC \ oak \ files \.

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ timeouts]

"Acuseridle" = DWORD: 0                     ; In seconds

"Battuseridle" = DWORD: 0                    ; In seconds

"Battsuspendtimeout" = DWORD: 3C     ; In seconds

In this way, the automatic timeout enters the useridle status to shield the mode, and the automatic timeout cannot be migrated to the useridle status in PPC.

For Windows Mobile 6 Standard (smartphone), the following settings are made in project. Reg under \ public \ smartfon \ oak \ files \.

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ timeouts]

"Acsuspendtimeout" = DWORD: 0       ; In seconds

"Battsuspendtimeout" = DWORD: 0     ; In seconds

In this way, the automatic timeout mode is blocked and cannot be automatically migrated to the suspended power status in smartphone.

According to the document: Windows Mobile 6 Professional and Windows Mobile 6 classic (PPC) do not support useridle. Windows Mobile 6 Standard (that is, smartphone) does not support unattended, resuming, the three statuses of suincluded.

There are eleven events that affect system power status change:

Wake source event:
This is a wake-up event defined by the OEM itself. They are all hardware interruptions of specific options (such as USB cable or charger insertion/unplugging interruption, baseband interruption, keyboard interruption, and alarm clock interruption ). In PPC, these wake-up events are used to change the system from the suordered ded state to the resuming state. There is no suincluded status in smartphone, and the corresponding low power consumption mode enters oemidle (). In some specific hardware platforms, in order to reduce power consumption, the CPU is usually configured in low power consumption mode or stop in oemidle. For example, on the PXA27X and pxa3xx smartphone platforms, the CPU enters the standby mode in oemidle () and configures some hardware interruptions as the wake source event to wake up the CPU and exit oemidle (). In PPC, oempoweroff () is called when the system enters the susponded State or is shut down. However, in smartphone, oempoweroff () is called only when the system is shut down.

On/Off Event:
The power button is pressed. This event is only valid in PPC.
In the resuming, unattended, and screenoff statuses, press the power button to migrate the system to the on status. In the On, backlightoff, and useridle statuses, press the power button to migrate the system to the unattended status.

On event:
Application buttons is pressed. This event is only valid in PPC.
In the On, backlightoff, useridle, resuming, unattended, and screenoff statuses, the system will be migrated to the on state by pressing application buttons.

Enter unattended:
Call powerpolicynotify (ppn_unattendedmode, true) to enable the system to enter the unattended mode. M_dwunattendedmoderef and 1.
Leave unattended:
Call powerpolicynotify (ppn_unattendedmode, false) to let the system exit the unattended mode. M_dwunattendedmoderef and 1.
The unattended state will be migrated first when any status is to be migrated to the susponded state. If m_dwunattendedmoderef is 0, the system directly enters the suincluded state. When the value is not 0, the systemidletimeout timer is reset, and the system enters the suspended state only after systemidle timeout.

The following are four timeout events:

15-second timeout (that is, resumingsuspendtimeout ):
15 s timeout is actually the resumingsuspendtimeout in the code, which is specially used for the resuming status.
When the system wakes up from sushortded to the resuming status, if no one has migrated this status within 15 s, the system power status will change to the unattended status.
The 15s time is default (pwstates under public \ common \ oak \ drivers \ PM \ PDD \ PDA. h), but it can also be changed.
Modify _ T ("Batt" under text ("HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ timeouts ")
The value of resumingsuspendtimeout can change the timeout time when no external power is used. Modify _ T ("acresumingsuspendtimeout" under text ("HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ timeouts ")") Value can change the timeout time when using the external power.

Systemidle timeout (suspendtimeout ):
The timeout time when the system automatically enters the susponded state. You can change it through the control panel. In the On, backlightoff, useridle, and screenoff statuses, systemidle timeout will bring the system into the unattended state, and systemidle timeout will bring the system into the susponded state in the unattended state.
The systemidle timeout time can also be changed by modifying the registry. This time is divided into two parts: m_dwbattsuspendtimeout when external power supply is not used and m_dwacsuspendtimeout when external power supply is used.
In the code, the default value of m_dwbattsuspendtimeout is 300 s, and the default value of m_dwacsuspendtimeout is S. project under \ public \ WPC \ oak \ files \ (for PPC) or \ public \ smartfon \ oak \ files \ (for smartphone. reg. Modify the value of _ T ("battsuspendtimeout") under text ("HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ timeouts") to change m_dwbattsuspendtimeout. Change the value of _ T ("acsuspendtimeout") under text ("HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ timeouts") to m_dwacsuspendtimeout.

Backlight timeout:
The timeout time when the system automatically enters the backlightoff status. In the on state, backlight timeout will bring the system into the backlightoff State. In the backlightoff, useridle, screenoff, and unattended state, backlight timeout will be blocked.
The same time is divided into two parts: m_dwbattbacklighttimeout when no external power supply is used; default value: 30 s; m_dwacbacklighttimeout when external power supply is used; default value: 60 s. You can also change it through the control panel.
This backlight timeout time can also be changed by modifying the registry.
Modify _ T ("battbacklighttimeout") under text ("HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ timeouts ") the value of m_dwbattbacklighttimeout can be changed in the value of _ T ("batterytimeout") under text ("HKEY_CURRENT_USER \ controlpanel \ backlight.
Modify _ T ("acbacklighttimeout") under text ("HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ timeouts ") the value of m_dwacbacklighttimeout can be changed in the value of _ T ("actimeout") under text ("HKEY_CURRENT_USER \ controlpanel \ backlight.

Note: When we modify backlight timeout to avoid conflicts, we recommend that you use only one set of registry values, it is either the _ T ("battbacklighttimeout") under text ("HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ timeouts ") and _ T ("acbacklighttimeout") either use _ T ("batterytimeout") under text ("HKEY_CURRENT_USER \ controlpanel \ backlight ") and _ T ("actimeout ").
If both groups are used at the same time. code in powerstatemanager: platformloadtimeouts in the CPP file (read text first ("HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ timeouts ") the following _ T ("battbacklighttimeout") and _ T ("acbacklighttimeout") read the _ T ("batterytimeout") under text ("HKEY_CURRENT_USER \ controlpanel \ backlight ") and _ T ("actimeout"), the subsequent registry values are the actual values.

User Timeout:
This timeout mechanism is only used on Windows Mobile 6 standard devices. In Windows Mobile 6 Professional and Windows Mobile 6 classic devices, there is no useridle, and this timeout mechanism is not used.
In the on and backlightoff states, usertimeout will bring the system into the useridle state, and user timeout will be blocked in the useridle, screenoff, and unattended states.
In Windows Mobile 6 standard devices, this time is also divided into two m_dwbattuseridletimeout and m_dwacuseridletimeout.
Modify _ T ("battuseridle") under text ("HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ timeouts ") the value of m_dwbattuseridletimeout can be changed for any value of _ T ("display") under text ("HKEY_CURRENT_USER \ controlpanel \ power.
Modify _ T ("acuseridle") under text ("HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ timeouts ") the value of m_dwacuseridletimeout can be changed for any value of _ T ("display") under text ("HKEY_CURRENT_USER \ controlpanel \ power.

Like backlight timeout, do not use _ T ("battuseridle") under text ("HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ timeouts") at the same time ") and _ T ("acuseridle") and _ T ("display") values under text ("HKEY_CURRENT_USER \ controlpanel \ power, otherwise, the subsequent registry values will be the actual values.

User active event:
Activate this event when there are any user operations.
In backlightoff and useridle states, the user active event will bring the system into the on state, and the user active event will not be processed in the on, screenoff, and unattended states.
The key value in HKEY_LOCAL_MACHINE \ SYSTEM \ GWe \ activityevent is the event to be sent when GWES finds any user action-powermanager/activitytimer/useractivity. Activitytimersthreadproc in the pmtimer. cpp File() The function determines whether the current status is useractivity or userinactivity based on whether there is a powermanager/activitytimer/useractivity event in the timeout period, and then sends the powermanager/useractivity_active and powermanager/useractivity_inactive events respectively.
The corresponding activitytimers registry is in text ("HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ power \ activitytimers. In PPC, this registry has only the _ T ("useractivity") subitem, which has only the value of _ T ("timeoutms") = 100. That is to say, the timeout time for switching from the useractivity status to the userinactivity status is 100 ms. In this way, the PM module will ignore the powermanager/useractivity_inactive event, the current user active event of the PM will be notified only when the powermanager/activitytimer/useractivity event is sent by GWe.

Systemidletimerreset:
Reset systemidletimer. Calling the systemidletimerreset () function will send the _ T ("powermanager/systemidletimerreset") event. In this case, PM calls m_ppwrstatemgr-> resetsystemidletimetimeo in the powerstate: waitforevent () function of the pwstates. cpp file.Ut (true); platevent = systemactivity; in this way, m_dwcursuspendtimeout is reset and the system power status is not migrated when platevent = systemactivity.

Power Manager API (setsystempowerstate ):
The powermanager API here refers to the setsystempowerstate that can directly change the system power status.
The call path of setsystempowerstate is pmsetsystempowerstate-> platformsendsystempowers.Tate-> g_ppowerstatemanager-> sendsystempowerstate.
First, determine whether the system power status to be set can be set directly by setsystempowerstate (appscanrequeststate is called), where on, useridle, suincluded, screenoff, coldreboot, reboot can be set, backlightoff, resuming, unattended cannot be set. Next, call pnewpowerstate-> enterstate (); pnewpowerstate = setsystemstate (pnewpowerstate); m_pcurpowerstate = pnewpowerstate; setevent (m_hsystemapicalled); and set the State passed in by the function to the current system power status.

From:

Http://blog.sina.com.cn/s/blog_4ef8be9f0100e77r.html

 

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: info-contact@alibabacloud.com 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.