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

📄 power.sgml

📁 eCos操作系统源码
💻 SGML
📖 第 1 页 / 共 4 页
字号:
operations are synchronous with respect to the calling thread. The useof a separate thread inside the power management package is controlledby the configuration option <varname>CYGPKG_POWER_THREAD</varname>,which is active only if the kernel package is present and enabled bydefault.</para><para>If no separate power management thread is used then obviously theimplementations of <function>power_set_mode</function> and<function>power_set_controller_mode</function> will be somewhatdifferent: instead of waking up a separate thread to do the work,these functions will now manipulate the power controllers directly. Ifthe system does still involve multiple threads then only one threadmay call <function>power_set_mode</function> or<function>power_set_controller_mode</function> at a time: the powermanagement package will not provide any synchronization, that musthappen at a higher level. However when a power controller is invokedit can still call these functions as required.</para></refsect1><!-- }}} --></refentry><!-- }}} --><!-- {{{ Power Management Info          --><refentry id="power-info"><refmeta><refentrytitle>Power Management Information</refentrytitle></refmeta><refnamediv><refname>Obtaining Power Management Information</refname><refpurpose>finding out about the various power controllers in the system</refpurpose></refnamediv><refsynopsisdiv><funcsynopsis><funcsynopsisinfo>#include &lt;cyg/power/power.h&gt;extern PowerController __POWER__[], __POWER_END__;extern PowerController power_controller_cpu;extern cyg_handle_t    power_thread_handle;</funcsynopsisinfo><funcprototype>  <funcdef>    PowerMode <function>power_get_mode</function>  </funcdef>  <void></funcprototype><funcprototype>  <funcdef>    PowerMode <function>power_get_desired_mode</function>  </funcdef>  <void></funcprototype><funcprototype>  <funcdef>    PowerMode <function>power_get_controller_mode</function>  </funcdef>  <paramdef>    PowerController* <parameter>controller</parameter>  </paramdef></funcprototype><funcprototype>  <funcdef>    PowerMode <function>power_get_controller_desired_mode</function>  </funcdef>  <paramdef>    PowerController* <parameter>controller</parameter>  </paramdef></funcprototype><funcprototype>  <funcdef>    const char* <function>power_get_controller_id</function>  </funcdef>  <paramdef>    PowerController* <parameter>controller</parameter>  </paramdef></funcprototype></funcsynopsis></refsynopsisdiv><refsect1 id="power-info-access"><title>Accessing Power Controllers</title><para>All the power controllers in a system are held in a table, filled inat link-time. The symbols <varname>__POWER__</varname> and<varname>__POWER_END</varname> can be used to iterate through thistable, for example:</para><programlisting>PowerController* controller;for (controller  = &amp;(__POWER__[0]);     controller != &amp;(__POWER_END__);     controller++) {     &hellip;}</programlisting><para>Each controller has an associated priority, controlling the order inwhich they appear in the table. Typically a software-only componentsuch as a TCP/IP stack would use a small number for the priority, sothat it appears near the start of the table, whereas a device driverwould be nearer the back of the table. When switching to alower-powered mode the power management package will iterate throughthis table from front to back, thus ensuring that for example theTCP/IP stack gets a chance to shut down before the underlying ethernetor other hardware that the stack depends on. Similarly when switchingto a higher-powered mode the power management package will iteratethrough this table from back to front.</para><para>In most systems there will be one special controller,<varname>power_controller_cpu</varname>, which should be provided byone of the architectural, variant or platform HAL packages. Thiscontroller will always be the last entry in the table. It isresponsible for the final power down operation when switching to<type>off</type> mode. Other packages such as device drivers may ormay not declare variable identifiers for their power controllers,allowing those controllers to be accessed by name as well as by theirentries in the global table.</para></refsect1><refsect1 id="power-info-global"><title>Global Power Modes</title><para>The function <function>power_get_mode</function> can be called at anytime to determine the current power mode for the system as a whole.The return value will be one of <literal>PowerMode_Active</literal>,<literal>PowerMode_Idle</literal>, <literal>PowerMode_Sleep</literal>or <literal>PowerMode_Off</literal>. In normal circumstances it isunlikely that <literal>PowerMode_Off</literal> would be returned sincethat mode generally means that the cpu is no longer running.</para><para>The function <function>power_get_desired_mode</function> returns thepower mode that the system should be running at. Most of the time thiswill be the same value as returned by<function>power_get_mode</function>. However a different value may bereturned when in the middle of changing power modes. For example, ifthe current thread runs at a higher priority than the power managementthread then the latter may have been pre-empted in the middle of amode change: <function>power_get_mode</function> will return the modethe system was running at before the mode change started, and<function>power_get_desired_mode</function> will return the mode thesystem should end up in when the mode change completes, barringfurther calls to <function>power_set_mode</function>.</para></refsect1><refsect1 id="power-info-individual"><title>Individual Controller Power Modes</title><para>The power management package keeps track of the current and desiredmodes for each power controller, as well as the modes for the system asa whole. The function <function>power_get_controller_mode</function>takes a single argument, a pointer to a power controller, and returnsthe power mode that controller is currently running at. Similarly<function>power_get_controller_desired_mode</function> returns thepower mode that controller should be running at. Most of the time thecurrent and desired modes for a given controller will be the same, andwill also be the same as the global power mode. However if the powermanagement thread is preeempted in the middle of a mode change thensome of the controllers will have been updated to the desired globalmode, whereas others will still be at the old mode. The powermanagement package also provides functionality for manipulating<link linkend="power-change-controller">individual controllers</link>, and for <linklinkend="power-attached">detaching</link> controllers fromglobal mode changes.</para></refsect1><refsect1 id="power-info-ids"><title>Power Controller Identification</title><para>In some scenarios the power management package will run completelyautomated, and there is no need to identify individual powercontrollers. Any form of identification such as a stringdescription would serve no purpose, but would still consume memory inthe final system. In other scenarios it may be very desirable toprovide some means of identification. For example, while stilldebugging it may be useful to see a simple string when printing thecontents of a power controller structure. Alternatively, if theapplication is expected to provide some sort of user interface thatgives control over which parts of the system are enabled or disabled,a string identifier for each controller would be useful. To cope withthese scenarios the power management package provides a configurationoption <varname>CYGIMP_POWER_PROVIDE_STRINGS</varname>. When enabled,each power controller will contain a pointer to a constant stringwhich can be accessed via a function<function>power_get_controller_id</function>. When disabled the systemwill not contain these strings, and the function will not be provided.The following code illustrates how to use this function.</para><programlisting>#include &lt;stdio.h&gt;#include &lt;pkgconf/system.h&gt;#ifndef CYGPKG_POWER# error The power management package is not present.#endif#include &lt;pkgconf/power.h&gt;#ifndef CYGIMP_POWER_PROVIDE_STRINGS# error Power controller identifiers are not available.#endif#include &lt;cyg/power/power.h&gt;static const char*mode_to_string(PowerMode mode){    const char* result;    switch(mode) {      case PowerMode_Active : result = "active"; break;      case PowerMode_Idle   : result = "idle"; break;      case PowerMode_Sleep  : result = "sleep"; break;      case PowerMode_Off    : result = "off"; break;      default               : result = "&lt;unknown&gt;"; break;    }    return result;}intmain(int argc, char** argv){    PowerController* controller;    for (controller = &amp;(__POWER__[0]);         controller != &amp;(__POWER_END__);         controller++) {        printf("Controller @ %p: %s, %s\n", controller,               power_get_controller_id(controller),               mode_to_string(power_get_controller_mode(controller)));    }    return 0;}</programlisting></refsect1><refsect1 id="power-info-thread"><title>The Power Management Thread</title><para>If the power management package is configured to use a separate threadthen a handle for that thread is made available to higher-level codevia the variable <varname>power_thread_handle</varname>. This handlecan be used for a variety of purposes, including manipulating thatthread's priority.</para></refsect1></refentry><!-- }}} --><!-- {{{ Changing Power Modes           --><refentry id="power-change"><refmeta><refentrytitle>Changing Power Modes</refentrytitle></refmeta><refnamediv><refname>Changing Power Modes</refname><refpurpose>reducing or increasing power consumption as needed</refpurpose></refnamediv><refsynopsisdiv><funcsynopsis><funcsynopsisinfo>#include &lt;cyg/power/power.h&gt;</funcsynopsisinfo><funcprototype>  <funcdef>    void <function>power_set_mode</function>  </funcdef>  <paramdef>    PowerMode <parameter>new_mode</parameter>  </paramdef></funcprototype><funcprototype>  <funcdef>    void <function>power_set_controller_mode</function>  </funcdef>  <paramdef>    PowerController* <parameter>controller</parameter>  </paramdef>  <paramdef>    PowerMode <parameter>new_mode</parameter>  </paramdef></funcprototype><funcprototype>  <funcdef>    void <function>power_set_controller_mode_now</function>  </funcdef>  <paramdef>    PowerController* <parameter>controller</parameter>  </paramdef>  <paramdef>    PowerMode <parameter>new_mode</parameter>  </paramdef></funcprototype></funcsynopsis></refsynopsisdiv><refsect1 id="power-change-global"><title>Changing the Global Power Mode</title><para>The primary functionality supported by the power management package isto change the system's global power mode. This is achieved by callingthe function <function>power_set_mode</function> with a singleargument, which should be one of <literal>PowerMode_Active</literal>,<literal>PowerMode_Idle</literal>, <literal>PowerMode_Sleep</literal>or <literal>PowerMode_Off</literal>. Typically this function will onlybe invoked in certain scenarios:</para><orderedlist><listitem><para>A typical system will contain a policy module which is primarilyresponsible for initiating power mode changes, and a thread inside thepower management package. The policy module will call<function>power_set_mode</function>, which has the effect ofmanipulating some internal state in the power management package andwaking up its thread. When this thread gets scheduled to run (itspriority is controlled by a configuration option), it will iterateover the power controllers and invoke each controller to change itspower mode. There is support for a <linklinkend="power-policy-callback">callback function</link>, and for<link linkend="power-attached">detached</link> power controllers.</para></listitem><listitem><para>After a call to <function>power_set_mode</function> but before thepower management thread has had a chance to iterate over all thecontrollers, or even before the thread has been rescheduled at all,the policy module may decide that a different power mode would be moreappropriate for the current situation and calls<function>power_set_mode</function> again. This has the effect ofaborting the previous mode change, followed by the power managementthread iterating over the power controllers again for the new mode.</para></listitem><listitem><para>If there is no single policy module responsible for power modechanges, any code can call <function>power_set_mode</function>. Ifthere are multiple calls in quick succession, earlier calls willbe aborted and the system should end up in the power modecorresponding to the last call</para></listitem><listitem>

⌨️ 快捷键说明

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