1 <!-- Copyright (C) 2001 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of substantively modified versions of this -->
7 <!-- document is prohibited without the explicit permission of the -->
8 <!-- copyright holder. -->
9 <!-- Distribution of the work or derivative of the work in any -->
10 <!-- standard (paper) book form is prohibited unless prior -->
11 <!-- permission is obtained from the copyright holder. -->
15 >Power Management Information</TITLE
16 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
19 CONTENT="Modular DocBook HTML Stylesheet Version 1.64
22 TITLE="eCos Power Management Support"
23 HREF="services-power.html"><LINK
26 HREF="power-intro.html"><LINK
28 TITLE="Changing Power Modes"
29 HREF="power-change.html"></HEAD
48 >eCos Power Management Support</TH
56 HREF="power-intro.html"
69 HREF="power-change.html"
80 >Power Management Information</A
89 >Obtaining Power Management Information -- finding out about the various power controllers in the system</DIV
91 CLASS="REFSYNOPSISDIV"
111 CLASS="FUNCSYNOPSISINFO"
112 >#include <cyg/power/power.h>
114 extern PowerController __POWER__[], __POWER_END__;
115 extern PowerController power_controller_cpu;
116 extern cyg_handle_t power_thread_handle;</PRE
124 > PowerMode power_get_mode
132 > PowerMode power_get_desired_mode
140 > PowerMode power_get_controller_mode
142 >( PowerController* controller
149 > PowerMode power_get_controller_desired_mode
151 >( PowerController* controller
158 > const char* power_get_controller_id
160 >( PowerController* controller
170 NAME="POWER-INFO-ACCESS"
173 >Accessing Power Controllers</H2
175 >All the power controllers in a system are held in a table, filled in
176 at link-time. The symbols <TT
183 > can be used to iterate through this
184 table, for example:</P
192 CLASS="PROGRAMLISTING"
193 >PowerController* controller;
194 for (controller = &(__POWER__[0]);
195 controller != &(__POWER_END__);
204 >Each controller has an associated priority, controlling the order in
205 which they appear in the table. Typically a software-only component
206 such as a TCP/IP stack would use a small number for the priority, so
207 that it appears near the start of the table, whereas a device driver
208 would be nearer the back of the table. When switching to a
209 lower-powered mode the power management package will iterate through
210 this table from front to back, thus ensuring that for example the
211 TCP/IP stack gets a chance to shut down before the underlying ethernet
212 or other hardware that the stack depends on. Similarly when switching
213 to a higher-powered mode the power management package will iterate
214 through this table from back to front.</P
216 >In most systems there will be one special controller,
219 >power_controller_cpu</TT
220 >, which should be provided by
221 one of the architectural, variant or platform HAL packages. This
222 controller will always be the last entry in the table. It is
223 responsible for the final power down operation when switching to
227 > mode. Other packages such as device drivers may or
228 may not declare variable identifiers for their power controllers,
229 allowing those controllers to be accessed by name as well as by their
230 entries in the global table.</P
235 NAME="POWER-INFO-GLOBAL"
238 >Global Power Modes</H2
243 > can be called at any
244 time to determine the current power mode for the system as a whole.
245 The return value will be one of <TT
247 >PowerMode_Active</TT
259 >. In normal circumstances it is
263 > would be returned since
264 that mode generally means that the cpu is no longer running.</P
268 >power_get_desired_mode</TT
270 power mode that the system should be running at. Most of the time this
271 will be the same value as returned by
275 >. However a different value may be
276 returned when in the middle of changing power modes. For example, if
277 the current thread runs at a higher priority than the power management
278 thread then the latter may have been pre-empted in the middle of a
282 > will return the mode
283 the system was running at before the mode change started, and
286 >power_get_desired_mode</TT
287 > will return the mode the
288 system should end up in when the mode change completes, barring
297 NAME="POWER-INFO-INDIVIDUAL"
300 >Individual Controller Power Modes</H2
302 >The power management package keeps track of the current and desired
303 modes for each power controller, as well as the modes for the system as
304 a whole. The function <TT
306 >power_get_controller_mode</TT
308 takes a single argument, a pointer to a power controller, and returns
309 the power mode that controller is currently running at. Similarly
312 >power_get_controller_desired_mode</TT
314 power mode that controller should be running at. Most of the time the
315 current and desired modes for a given controller will be the same, and
316 will also be the same as the global power mode. However if the power
317 management thread is preeempted in the middle of a mode change then
318 some of the controllers will have been updated to the desired global
319 mode, whereas others will still be at the old mode. The power
320 management package also provides functionality for manipulating
322 HREF="power-change.html#POWER-CHANGE-CONTROLLER"
323 >individual controllers</A
325 HREF="power-attached.html"
328 global mode changes.</P
333 NAME="POWER-INFO-IDS"
336 >Power Controller Identification</H2
338 >In some scenarios the power management package will run completely
339 automated, and there is no need to identify individual power
340 controllers. Any form of identification such as a string
341 description would serve no purpose, but would still consume memory in
342 the final system. In other scenarios it may be very desirable to
343 provide some means of identification. For example, while still
344 debugging it may be useful to see a simple string when printing the
345 contents of a power controller structure. Alternatively, if the
346 application is expected to provide some sort of user interface that
347 gives control over which parts of the system are enabled or disabled,
348 a string identifier for each controller would be useful. To cope with
349 these scenarios the power management package provides a configuration
352 >CYGIMP_POWER_PROVIDE_STRINGS</TT
354 each power controller will contain a pointer to a constant string
355 which can be accessed via a function
358 >power_get_controller_id</TT
359 >. When disabled the system
360 will not contain these strings, and the function will not be provided.
361 The following code illustrates how to use this function.</P
369 CLASS="PROGRAMLISTING"
370 >#include <stdio.h>
371 #include <pkgconf/system.h>
373 # error The power management package is not present.
375 #include <pkgconf/power.h>
376 #ifndef CYGIMP_POWER_PROVIDE_STRINGS
377 # error Power controller identifiers are not available.
379 #include <cyg/power/power.h>
382 mode_to_string(PowerMode mode)
386 case PowerMode_Active : result = "active"; break;
387 case PowerMode_Idle : result = "idle"; break;
388 case PowerMode_Sleep : result = "sleep"; break;
389 case PowerMode_Off : result = "off"; break;
390 default : result = "<unknown>"; break;
396 main(int argc, char** argv)
398 PowerController* controller;
400 for (controller = &(__POWER__[0]);
401 controller != &(__POWER_END__);
403 printf("Controller @ %p: %s, %s\n", controller,
404 power_get_controller_id(controller),
405 mode_to_string(power_get_controller_mode(controller)));
416 NAME="POWER-INFO-THREAD"
419 >The Power Management Thread</H2
421 >If the power management package is configured to use a separate thread
422 then a handle for that thread is made available to higher-level code
425 >power_thread_handle</TT
427 can be used for a variety of purposes, including manipulating that
428 thread's priority.</P
445 HREF="power-intro.html"
453 HREF="services-power.html"
461 HREF="power-change.html"
480 >Changing Power Modes</TD