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

📄 power-controller.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!-- 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>Implementing a Power Controller</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="Attached and Detached Controllers"HREF="power-attached.html"><LINKREL="NEXT"TITLE="eCos USB Slave Support"HREF="io-usb-slave.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-attached.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="io-usb-slave.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="POWER-CONTROLLER">Implementing a Power Controller</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN15936"></A><H2>Name</H2>Implementing a Power Controller&nbsp;--&nbsp;adding power management support to device drivers andother packages</DIV><DIVCLASS="REFSECT1"><ANAME="AEN15939"></A><H2>Implementing a Power Controller</H2><P>A system will have some number of power controllers. Usually therewill be one power controller for the cpu,<TTCLASS="VARNAME">power_controller_cpu</TT>, typically provided by one ofthe HAL packages and responsible for managing the processor itself andassociated critical components such as memory. Some or all of thedevice drivers will provide power controllers, allowing the powerconsumption of the associated devices to be controlled. There may besome arbitrary number of other controllers present in the system. Thepower management package does not impose any restrictions on thenumber or nature of the power controllers in the system, other thaninsisting that at most one <TTCLASS="VARNAME">power_controller_cpu</TT> beprovided.</P><P>Each power controller involves a single data structure of type<SPANCLASS="STRUCTNAME">PowerController</SPAN>, defined in the header file<TTCLASS="FILENAME">cyg/power/power.h</TT>. These datastructures should all be placed in the table<TTCLASS="LITERAL">__POWER__</TT>, so that the power management package andother code can easily locate all the controllers in the system. Thistable is constructed at link-time, avoiding code-size or run-timeoverheads. To facilitate this the package provides two macros whichshould be used to define a power controller,<TTCLASS="LITERAL">POWER_CONTROLLER()</TT> and<TTCLASS="LITERAL">POWER_CONTROLLER_CPU()</TT>.</P><P>The macro <TTCLASS="LITERAL">POWER_CONTROLLER</TT> takes four arguments:</P><P></P><OLTYPE="1"><LI><P>A variable name. This can be used to access the power controllerdirectly, as well as via the table.</P></LI><LI><P>A priority. The table of power controllers is sorted, such that powercontrollers with a numerically lower priority come earlier in thetable. The special controller <TTCLASS="VARNAME">power_controller_cpu</TT>always comes at the end of the table. When moving from a high-powermode to a lower-powered mode, the power management package iteratesthrough the table from front to back. When moving to a higher-poweredmode the reverse direction is used. The intention is that the powercontroller for a software-only package such as a TCP/IP stack shouldappear near the start of the table, whereas the controllers for theethernet and similar devices would be near the end of the table. Hencewhen the policy module initiates a mode change to a lower-powered modethe TCP/IP stack gets a chance to cancel this mode change, before thedevices it depends on are powered down. Similarly when moving to ahigher-powered mode the devices will be re-activated before anysoftware that depends on those devices.</P><P>The header file <TTCLASS="FILENAME">cyg/power/power.h</TT> defines threepriorities <TTCLASS="LITERAL">PowerPri_Early</TT>,<TTCLASS="LITERAL">PowerPri_Typical</TT> and<TTCLASS="LITERAL">PowerPri_Late</TT>. For most controllers one of thesepriorities, possibly with a small number added or subtracted, willgive sufficient control. If an application developer is uncertainabout the relative priorities of the various controllers, a simple<AHREF="power-info.html#POWER-INFO-IDS">test program</A> that iterates overthe table will quickly eliminate any confusion.</P></LI><LI><P>A constant string identifier. If the system has been configuredwithout support for such identifiers(<TTCLASS="VARNAME">CYGIMP_POWER_PROVIDE_STRINGS</TT>) then this identiferwill be discarded at compile-time. Otherwise it will be made availableto higher-level code using the function<TTCLASS="FUNCTION">power_get_controller_id</TT>. </P></LI><LI><P>A function pointer. This will be invoked to perform actual modechanges, as described below.</P></LI></OL><P>A typical example of the use of the<TTCLASS="LITERAL">POWER_CONTROLLER</TT> macro would be as follows:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#include &lt;pkgconf/system.h&gt;#ifdef CYGPKG_POWER# include &lt;cyg/power/power.h&gt;static voidxyzzy_device_power_mode_change(    PowerController* controller,    PowerMode        desired_mode,    PowerModeChange  change){   // Do the work}static POWER_CONTROLLER(xyzzy_power_controller, \                        PowerPri_Late,          \                        "xyzzy device",         \                        &amp;xyzzy_device_power_mode_change);#endif</PRE></TD></TR></TABLE><P>This creates a variable <TTCLASS="VARNAME">xyzzy_power_controller</TT>,which is a power controller data structure that will end up near theend of the table of power controllers. Higher-level code caniterate through this table and report the string <TTCLASS="LITERAL">"xyzzydevice"</TT> to the user. Whenever there is a mode changeoperation that affects this controller, the function<TTCLASS="FUNCTION">xyzzy_device_power_mode_change</TT> will be invoked.The variable is declared static so this controller cannot bemanipulated by name in any other code. Alternatively, if the variablehad not been declared static other code could manipulate thiscontroller by name as well as through the table, especially if thepackage for the xyzzy device driver explicitly declared thisvariable in an exported header file. Obviously exporting the variableinvolves a slight risk of a name clash at link time.</P><P>The above code explicitly checks for the presence of the powermanagement package before including that package's header file orproviding any related functionality. Since power managementfunctionality is optional, such checks are recommended.</P><P>The macro <TTCLASS="LITERAL">POWER_CONTROLLER_CPU</TT> only takes twoarguments, a string identifier and a mode change function pointer.This macro always instantiates a variable<TTCLASS="VARNAME">power_controller_cpu</TT> so there is no need to providea variable name. The resulting power controller structure alwaysappears at the end of the table, so there is no need to specify apriority. Typical usage of the <TTCLASS="LITERAL">POWER_CONTROLLER_CPU</TT>macro would be:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">static voidwumpus_processor_power_mode_change(    PowerController* controller,    PowerMode        desired_mode,    PowerModeChange  change){   // Do the work}POWER_CONTROLLER_CPU("wumpus processor", \                     &amp;wumpus_processor_power_mode_change);</PRE></TD

⌨️ 快捷键说明

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