⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 power-policy.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
字号:
<!-- Copyright (C) 2003 Red Hat, Inc.                                --><!-- This material may be distributed only subject to the terms      --><!-- and conditions set forth in the Open Publication License, v1.0  --><!-- or later (the latest version is presently available at          --><!-- http://www.opencontent.org/openpub/).                           --><!-- Distribution of the work or derivative of the work in any       --><!-- standard (paper) book form is prohibited unless prior           --><!-- permission is obtained from the copyright holder.               --><HTML><HEAD><TITLE>Support for Policy Modules</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="eCos Power Management Support"HREF="services-power.html"><LINKREL="PREVIOUS"TITLE="Changing Power Modes"HREF="power-change.html"><LINKREL="NEXT"TITLE="Attached and Detached Controllers"HREF="power-attached.html"></HEAD><BODYCLASS="REFENTRY"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="power-change.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="power-attached.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="POWER-POLICY">Support for Policy Modules</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN15836"></A><H2>Name</H2>Support for Policy Modules&nbsp;--&nbsp;closer integration with higher-level code</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN15839"><H2>Synopsis</H2><DIVCLASS="FUNCSYNOPSIS"><ANAME="AEN15840"><P></P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="FUNCSYNOPSISINFO">#include &lt;cyg/power/power.h&gt;</PRE></TD></TR></TABLE><P><CODE><CODECLASS="FUNCDEF">    void power_set_policy_callback  </CODE>(    void (*)(PowerController*, PowerMode, PowerMode, PowerMode, PowerMode) callback  );</CODE></P><P><CODE><CODECLASS="FUNCDEF">    void (*)(PowerController*, PowerMode, PowerMode, PowerMode, PowerMode) power_get_policy_callback  </CODE>(void);</CODE></P><P><CODE><CODECLASS="FUNCDEF">    CYG_ADDRWORD power_get_controller_policy_data  </CODE>(    PowerController* controller  );</CODE></P><P><CODE><CODECLASS="FUNCDEF">    void power_set_controller_policy_data  </CODE>(    PowerController* controller  ,     CYG_ADDRWORD data  );</CODE></P><P></P></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="POWER-POLICY-CALLBACK"></A><H2>Policy Callbacks</H2><P>The use of a separate thread to perform power mode changes in typicalconfigurations can cause problems for some policy modules.Specifically, the policy module can request a mode change for thesystem as a whole or for an individual controller, but it does notknow when the power management thread actually gets scheduled to runagain and carry out the request. Although it would be possible for thepolicy module to perform some sort of polling, in general that isundesirable.</P><P>To avoid such problems the policy module can install a callbackfunction using <TTCLASS="FUNCTION">power_set_policy_callback</TT>. Thecurrent callback function can be retrieved using<TTCLASS="FUNCTION">power_get_policy_callback</TT>. If a callback functionhas been installed then it will be called by the power managementpackage whenever a power controller has been invoked to perform a modechange. The callback will be called in the context of the powermanagement thread, so usually it will have to make use of threadsynchronisation primitives to interact with the main policy module. Itis passed five arguments:</P><P></P><OLTYPE="1"><LI><P>The power controller that has just been invoked to perform a modechange. </P></LI><LI><P>The mode this controller was running at before the invocation.</P></LI><LI><P>The current mode this controller is now running at.</P></LI><LI><P>The desired mode before the power controller was invoked. Usually thiswill be the same as the current mode, unless the controller hasdecided for some reason that this was inappropriate.</P></LI><LI><P>The current desired mode. This will differ from the previous argumentonly if there has was another call to<TTCLASS="FUNCTION">power_set_mode</TT> or<TTCLASS="FUNCTION">power_set_controller_mode</TT> while the powercontroller was being invoked, probably by the power controller itself.</P></LI></OL><P>A simple example of a policy callback function would be:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">static voidpower_callback(    PowerController* controller,    PowerMode old_mode,    PowerMode new_mode,    PowerMode old_desired_mode,    powerMode new_desired_mode){    printf("Power mode change: %s, %s -&#62; %d\n",        power_get_controller_id(controller),        mode_to_string(old_mode),        mode_to_string(new_mode));    CYG_UNUSED_PARAM(PowerMode, old_desired_mode);    CYG_UNUSED_PARAM(PowerMode, new_desired_mode);}intmain(int argc, char** argv){    &#8230;    power_set_policy_callback(&amp;power_callback);    &#8230;}</PRE></TD></TR></TABLE><P>If <TTCLASS="FUNCTION">power_set_controller_mode_now</TT> is used tomanipulate an individual controller the policy callback will not beinvoked. This function may get called from any context including DSRs,and even if there is already a call to the policy callback happeningin some other context, so invoking the callback would usually beunsafe.</P><P>If the power management package has not been configured to use aseparate thread then <TTCLASS="FUNCTION">power_set_mode</TT> and<TTCLASS="FUNCTION">power_set_controller_mode</TT> will manipulate thepower controllers immediately and invoke the policy callbackafterwards. Therefore the policy callback will typically run in thesame context as the main policy module.</P></DIV><DIVCLASS="REFSECT1"><ANAME="POWER-POLICY-DATA"></A><H2>Policy-specific Controller Data</H2><P>Some policy modules may want to associate some additional data witheach power controller. This could be achieved by for examplemaintaining a hash table or similar data structure, but forconvenience the power management package allows higher-level code,typically the policy module, to store and retrieve one word of data ineach power controller. The function<TTCLASS="FUNCTION">power_set_controller_policy_data</TT> takes twoarguments, a pointer to a power controller and a<SPANCLASS="TYPE">CYG_ADDRWORD</SPAN> of data: by appropriate use of casts thisword could be an integer or a pointer to some data structure. Thematching function<TTCLASS="FUNCTION">power_get_controller_policy_data</TT> retrieves theword previously installed, and can be cast back to an integer orpointer. The default value for the policy data is 0.</P><P>For example the following code fragment stores a simple index value ineach power controller. This could then be retrieved by the policycallback.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">    unsigned int     i = 0;    PowerController* controller;    for (controller = &amp;(__POWER__[0]);         controller != &amp;(__POWER_END__);         controller++) {        power_set_controller_policy_data(controller, (CYG_ADDRWORD) i++);    }</PRE></TD></TR></TABLE><P>Not all policy modules will require per-controller data. Theconfiguration option<TTCLASS="VARNAME">CYGIMP_POWER_PROVIDE_POLICY_DATA</TT> can be used tocontrol this functionality, thus avoiding wasting a small amount ofmemory inside each power controller structure.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="power-change.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="power-attached.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Changing Power Modes</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="services-power.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Attached and Detached Controllers</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -