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 >Support for Policy Modules</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
25 TITLE="Changing Power Modes"
26 HREF="power-change.html"><LINK
28 TITLE="Attached and Detached Controllers"
29 HREF="power-attached.html"></HEAD
48 >eCos Power Management Support</TH
56 HREF="power-change.html"
69 HREF="power-attached.html"
80 >Support for Policy Modules</A
89 >Support for Policy Modules -- closer integration with higher-level code</DIV
91 CLASS="REFSYNOPSISDIV"
111 CLASS="FUNCSYNOPSISINFO"
112 >#include <cyg/power/power.h></PRE
120 > void power_set_policy_callback
122 >( void (*)(PowerController*, PowerMode, PowerMode, PowerMode, PowerMode) callback
129 > void (*)(PowerController*, PowerMode, PowerMode, PowerMode, PowerMode) power_get_policy_callback
137 > CYG_ADDRWORD power_get_controller_policy_data
139 >( PowerController* controller
146 > void power_set_controller_policy_data
148 >( PowerController* controller
159 NAME="POWER-POLICY-CALLBACK"
162 >Policy Callbacks</H2
164 >The use of a separate thread to perform power mode changes in typical
165 configurations can cause problems for some policy modules.
166 Specifically, the policy module can request a mode change for the
167 system as a whole or for an individual controller, but it does not
168 know when the power management thread actually gets scheduled to run
169 again and carry out the request. Although it would be possible for the
170 policy module to perform some sort of polling, in general that is
173 >To avoid such problems the policy module can install a callback
176 >power_set_policy_callback</TT
178 current callback function can be retrieved using
181 >power_get_policy_callback</TT
182 >. If a callback function
183 has been installed then it will be called by the power management
184 package whenever a power controller has been invoked to perform a mode
185 change. The callback will be called in the context of the power
186 management thread, so usually it will have to make use of thread
187 synchronisation primitives to interact with the main policy module. It
188 is passed five arguments:</P
195 >The power controller that has just been invoked to perform a mode
200 >The mode this controller was running at before the invocation.</P
204 >The current mode this controller is now running at.</P
208 >The desired mode before the power controller was invoked. Usually this
209 will be the same as the current mode, unless the controller has
210 decided for some reason that this was inappropriate.</P
214 >The current desired mode. This will differ from the previous argument
215 only if there has was another call to
222 >power_set_controller_mode</TT
224 controller was being invoked, probably by the power controller itself.</P
228 >A simple example of a policy callback function would be:</P
236 CLASS="PROGRAMLISTING"
239 PowerController* controller,
242 PowerMode old_desired_mode,
243 powerMode new_desired_mode)
245 printf("Power mode change: %s, %s -> %d\n",
246 power_get_controller_id(controller),
247 mode_to_string(old_mode),
248 mode_to_string(new_mode));
250 CYG_UNUSED_PARAM(PowerMode, old_desired_mode);
251 CYG_UNUSED_PARAM(PowerMode, new_desired_mode);
255 main(int argc, char** argv)
258 power_set_policy_callback(&power_callback);
267 >power_set_controller_mode_now</TT
269 manipulate an individual controller the policy callback will not be
270 invoked. This function may get called from any context including DSRs,
271 and even if there is already a call to the policy callback happening
272 in some other context, so invoking the callback would usually be
275 >If the power management package has not been configured to use a
276 separate thread then <TT
282 >power_set_controller_mode</TT
283 > will manipulate the
284 power controllers immediately and invoke the policy callback
285 afterwards. Therefore the policy callback will typically run in the
286 same context as the main policy module.</P
291 NAME="POWER-POLICY-DATA"
294 >Policy-specific Controller Data</H2
296 >Some policy modules may want to associate some additional data with
297 each power controller. This could be achieved by for example
298 maintaining a hash table or similar data structure, but for
299 convenience the power management package allows higher-level code,
300 typically the policy module, to store and retrieve one word of data in
301 each power controller. The function
304 >power_set_controller_policy_data</TT
306 arguments, a pointer to a power controller and a
310 > of data: by appropriate use of casts this
311 word could be an integer or a pointer to some data structure. The
315 >power_get_controller_policy_data</TT
317 word previously installed, and can be cast back to an integer or
318 pointer. The default value for the policy data is 0.</P
320 >For example the following code fragment stores a simple index value in
321 each power controller. This could then be retrieved by the policy
330 CLASS="PROGRAMLISTING"
331 > unsigned int i = 0;
332 PowerController* controller;
334 for (controller = &(__POWER__[0]);
335 controller != &(__POWER_END__);
337 power_set_controller_policy_data(controller, (CYG_ADDRWORD) i++);
343 >Not all policy modules will require per-controller data. The
347 >CYGIMP_POWER_PROVIDE_POLICY_DATA</TT
349 control this functionality, thus avoiding wasting a small amount of
350 memory inside each power controller structure.</P
367 HREF="power-change.html"
375 HREF="services-power.html"
383 HREF="power-attached.html"
392 >Changing Power Modes</TD
402 >Attached and Detached Controllers</TD