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

📄 power-controller.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
></TR></TABLE><P>This defines a power controller structure<TTCLASS="VARNAME">power_controller_cpu</TT>. It should not be declaredstatic since higher-level code may well want to manipulate the cpu'spower mode directly, and the variable is declared by the powermanagement package's header file.</P><P>Some care has to be taken to ensure that the power controllersactually end up in the final executable. If a power controllervariable ends up in an ordinary library and is never referenceddirectly then typically the linker will believe that the variable isnot needed and it will not end up in the executable. For eCos packagesthis can be achieved in the CDL, by specifying that the containingsource file should end up in <TTCLASS="FILENAME">libextras.a</TT> ratherthan the default <TTCLASS="FILENAME">libtarget.a</TT>:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cdl_package CYGPKG_HAL_WUMPUS_ARCH {    &#8230;    compile -library=libextras.a data.c}</PRE></TD></TR></TABLE><P>If the file <TTCLASS="FILENAME">data.c</TT> instantiates a powercontroller this is now guaranteed to end up in the final executable,as intended. Typically HAL and device driver packages will alreadyhave some data that must not be eliminated by the linker, so they willalready contain a file that gets built into<TTCLASS="FILENAME">libextras.a</TT>. For power controllers defined insideapplication code it is important that the power controllers end up in<TTCLASS="FILENAME">.o</TT> object files rather than in<TTCLASS="FILENAME">.a</TT> library archive files.</P><P>All the real work of a power controller is done by the mode changefunction. If the power management package has been configured to use aseparate thread then this mode change function will be invoked by thatthread (except for the special case of <AHREF="power-change.html#POWER-CHANGE-CONTROLLER-NOW"><TTCLASS="FUNCTION">power_set_controller_mode_now</TT></A>). If no separate thread is used then the mode change function will beinvoked directly by <TTCLASS="FUNCTION">power_set_mode</TT> or<TTCLASS="FUNCTION">power_set_controller_mode</TT>.</P><P>The mode change function will be invoked with three arguments. Thefirst argument identifies the power controller. Usually this argumentis not actually required since a given mode change function will onlyever be invoked for a single power controller. For example,<TTCLASS="FUNCTION">xyzzy_device_power_mode_change</TT> will only ever beused in conjunction with <TTCLASS="VARNAME">xyzzy_power_controller</TT>.However there may be some packages which contain multiple controllers,all of which can share a single mode change function, and in that caseit is essential to identify the specific controller. The secondargument specifies the mode the controller should switch to, ifpossible: it will be one of <TTCLASS="LITERAL">PowerMode_Active</TT>,<TTCLASS="LITERAL">PowerMode_Idle</TT>, <TTCLASS="LITERAL">PowerMode_Sleep</TT>or <TTCLASS="LITERAL">PowerMode_Off</TT>. The final argument will be one of<TTCLASS="LITERAL">PowerModeChange_Controller</TT>,PowerModeChange_ControllerNow, or<TTCLASS="LITERAL">PowerModeChange_Global</TT>, and identifies the callthat caused this invocation. For example, if the mode change functionwas invoked because of a call to <TTCLASS="FUNCTION">power_set_mode</TT>then this argument will be <TTCLASS="LITERAL">PowerModeChange_Global</TT>.It is up to each controller to decide how to interpret this finalargument. A typical controller might reject a global request to switchto <SPANCLASS="TYPE">off</SPAN> mode if the associated device is still busy, butif the request was aimed specifically at this controller then it couldinstead abort any current I/O operations and switch off the device.</P><P>The <SPANCLASS="STRUCTNAME">PowerController</SPAN> data structure containsone field, <TTCLASS="STRUCTFIELD"><I>mode</I></TT>, that needs to be updatedby the power mode change function. At all times it should indicate thecurrent mode for this controller. When a mode change is requested thedesired mode is passed as the second argument. The exact operation ofthe power mode change function depends very much on what is beingcontrolled and the current circumstances, but some guidelines arepossible:</P><P></P><OLTYPE="1"><LI><P>If the request can be satisfied without obvious detriment, do so andupdate the <TTCLASS="STRUCTFIELD"><I>mode</I></TT> field. Reducing the powerconsumption of a device that is not currently being used is generallyharmless.</P></LI><LI><P>If a request is a no-op, for example if the system is switchingfrom <SPANCLASS="TYPE">idle</SPAN> to <SPANCLASS="TYPE">sleep</SPAN> mode and the controllerdoes not distinguish between these modes, simply act as if the requestwas satisfied.</P></LI><LI><P>If a request is felt to be unsafe, for example shutting down adevice that is still in use, then the controller may decideto reject this request. This is especially true if the request was aglobal mode change as opposed to one intended specifically for thiscontroller: in the latter case the policy module should be given duedeference. There are a number of ways in which a request can berejected:</P><P></P><OLTYPE="a"><LI><P>If the request cannot be satisfied immediately but may be feasible ina short while, leave the <TTCLASS="STRUCTFIELD"><I>mode</I></TT> fieldunchanged. Higher-level code in the policy module can interpret thisas a hint to retry the operation a little bit later. This approach isalso useful if the mode change can be started but will take some timeto complete, for example shutting down a socket connection, andadditional processing will be needed later on.</P></LI><LI><P>If the request is felt to be inappropriate, for example switching offa device that is still in use, the mode change function cancall <TTCLASS="FUNCTION">power_set_controller_mode</TT> to reset thedesired mode for this controller back to the current mode.Higher-level code can then interpret this as a hint that there is moreactivity in the system than had been apparent.</P></LI><LI><P>For a global mode change, if the new mode is felt to be inappropriatethen the power controller can call <TTCLASS="FUNCTION">power_set_mode</TT>to indicate this. An example of this would be the policy moduledeciding to switch off the whole unit while there is still I/Oactivity.</P></LI></OL></LI></OL><P>Mode change functions should not directly manipulate any other fieldsin the <SPANCLASS="STRUCTNAME">PowerController</SPAN> data structure. If itis necessary to keep track of additional data then static variablescan be used.</P><P>It should be noted that the above are only guidelines. Theirapplication in any given situation may be unclear. In addition thedetailed requirements of specific systems will vary, so even if thepower controller for a given device driver follows the aboveguidelines exactly it may turn out that slightly different behaviourwould be more appropriate for the actual system that is beingdeveloped. Fortunately the open source nature of<SPANCLASS="PRODUCTNAME">eCos</SPAN> allows system developers to fine-tunepower controllers to meet their exact requirements.</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-attached.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="io-usb-slave.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Attached and Detached Controllers</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="services-power.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">eCos USB Slave Support</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

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