{"id":229,"date":"2009-11-28T04:59:15","date_gmt":"2009-11-28T09:59:15","guid":{"rendered":"http:\/\/www.e-consystems.com\/blog\/?p=229"},"modified":"2023-08-15T12:34:55","modified_gmt":"2023-08-15T07:04:55","slug":"customizing-windows-ce-power-manager-driver","status":"publish","type":"post","link":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/customizing-windows-ce-power-manager-driver\/","title":{"rendered":"Customizing Power Manager for SetSystemPowerState()"},"content":{"rendered":"<p style=\"text-align: justify;\">Changing the system state can be as simple as a <em>cup of tea!<\/em> by calling <em>SetSystemPowerstate()<\/em> API. But not all power states can be allowed to set through this API in the default cases. For example setting to \u201cSystemIdle\u201d using this API will be failed.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: justify;\">There are some use cases, we may need to set \u201c<em>systemIdle<\/em>\u201d through our application\/driver or we may need to deny the application\/driver to set some power states.\u00a0 Sometimes, we would like to have our own power state created and it may be allowed to set from the application\/driver.\u00a0 To do this, we have to customize the Windows CE power manager.<\/p>\n<p style=\"text-align: justify;\"><strong>Customizing the Power Manager (Windows CE)<\/strong><\/p>\n<ul style=\"text-align: justify;\">\n<li>Since PM driver is the public component, it is not advisable to change the public code directly. We have to copy the PM driver from \\WINCE600\\PUBLIC\\COMMON\\OAK\\DRIVERS\\PM to your BSP driver folder and perform sysgen capture on the PM driver.<\/li>\n<\/ul>\n<ul style=\"text-align: justify;\">\n<li>All power states codes are available on <em>PM\\PDD\\DEFAULT\\pwstates.cpp. PowerStateOn, PowerStateUserIdle, PowerStateSystemIdle, PowerStateSuspended, PowerStateResuming, PowerStateColdReboot<\/em><strong> <\/strong>and <em>PowerStateReboot<\/em> are the power states classes derived from PowerState class of <em>PM\\PDD\\DEFAULT\\pwsdef.cpp<\/em> and<em> pwsdef.h<\/em><em>class PowerStateUserIdle : public PowerState <\/em><em>{<\/em><em>public:<br \/>\nPowerStateUserIdle(PowerStateManager *pPwrStateMgr, PowerState * pNextPowerState = NULL )<br \/>\n:\u00a0\u00a0 PowerState(pPwrStateMgr,pNextPowerState)<br \/>\n{;\u00a0 };<\/em><br \/>\n<em> .\u00a0\u00a0 \/*Remaining power states<\/em><br \/>\n<em> .\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 code *\/<br \/>\n.<br \/>\n.<br \/>\n.<br \/>\nvirtual BOOL AppsCanRequestState() { return TRUE; }<br \/>\n};<\/em><em><br \/>\n<\/em><\/li>\n<\/ul>\n<p style=\"text-align: justify;\">The above code snippet is the power state class for user idle, derived from PowerState class. Similarly, all power states are having their own classes\u00a0 as explained above.<\/p>\n<p style=\"text-align: justify;\">Allowing or denying to set the corresponding power state by calling <em>SetSystemPowerState ()<\/em> is evaluated by the \u201cpower state manager\u201d through\u00a0\u00a0 virtual BOOL <em>AppsCanRequestState () { return TRUE; }<\/em> function of each power state class. This function is defined as a virtual function in PowerState base class and it can be overridden by the derived power state class based on their needs. Below given figure explains the call flow of <em>SetSystemPowerState ()<\/em> API.<\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"alignnone size-full wp-image-254\" src=\"\/images\/blog\/customizing-windows-ce-power-manager-driver31.PNG\" alt=\"customizing-windows-ce-power-manager-driver31\" \/><\/p>\n<p style=\"text-align: justify;\"><em>Fig: Call flow of SetSystemPowerStateAPI<\/em><\/p>\n<ul style=\"text-align: justify;\">\n<li>If <em>AppsCanRequestState()<\/em> is return TRUE, Application\/driver can set the corresponding power states through <em>SetSystemPowerState()<\/em> API. <em>AppsCanRequestState() <\/em>will return FALSE in the PowerState base class and the derived class will override this function to return TRUE, if they need to set through <em>SetSystemPowerstate()<\/em> API.<\/li>\n<\/ul>\n<ul style=\"text-align: justify;\">\n<li><em>AppsCanRequestState()<\/em> function is not overridden by the SystemIdle state. Because of this, calling <em>SetSystemPowerState()<\/em> with this state as a parameter will not work. If you want to enable, you have to override the <em>AppsCanRequestState()<\/em> function as explained in the above code snippet.<\/li>\n<\/ul>\n<ul style=\"text-align: justify;\">\n<li>If you have your own power state, you have to override the function as explained above to set from application\/driver.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Changing the system state can be as simple as a cup of tea! by calling&#8230;<\/p>\n","protected":false},"author":12,"featured_media":1368,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[213],"tags":[77,89,320],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts\/229"}],"collection":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/comments?post=229"}],"version-history":[{"count":1,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts\/229\/revisions"}],"predecessor-version":[{"id":2950,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/posts\/229\/revisions\/2950"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/media\/1368"}],"wp:attachment":[{"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/media?parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/categories?post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.e-consystems.com\/blog\/system-on-module-som\/wp-json\/wp\/v2\/tags?post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}