Global power modes, Individual controller power modes, Power controller identification – Comtrol eCos User Manual

Page 662

Advertising
background image

Power Management Information

Global Power Modes

The function

power_get_mode

can be called at any time to determine the current power mode for the system

as a whole. The return value will be one of

PowerMode_Active

,

PowerMode_Idle

,

PowerMode_Sleep

or

Pow-

erMode_Off

. In normal circumstances it is unlikely that

PowerMode_Off

would be returned since that mode

generally means that the cpu is no longer running.

The function

power_get_desired_mode

returns the power mode that the system should be running at. Most of the

time this will be the same value as returned by

power_get_mode

. However a different value may be returned when

in the middle of changing power modes. For example, if the current thread runs at a higher priority than the power
management thread then the latter may have been pre-empted in the middle of a mode change:

power_get_mode

will return the mode the system was running at before the mode change started, and

power_get_desired_mode

will return the mode the system should end up in when the mode change completes, barring further calls to

power_set_mode

.

Individual Controller Power Modes

The power management package keeps track of the current and desired modes for each power controller, as well
as the modes for the system as a whole. The function

power_get_controller_mode

takes a single argument,

a pointer to a power controller, and returns the power mode that controller is currently running at. Similarly

power_get_controller_desired_mode

returns the power mode that controller should be running at. Most of

the time the current and desired modes for a given controller will be the same, and will also be the same as the
global power mode. However if the power management thread is preeempted in the middle of a mode change then
some of the controllers will have been updated to the desired global mode, whereas others will still be at the old
mode. The power management package also provides functionality for manipulating

individual controllers

, and for

detaching

controllers from global mode changes.

Power Controller Identification

In some scenarios the power management package will run completely automated, and there is no need to identify
individual power controllers. Any form of identification such as a string description would serve no purpose, but
would still consume memory in the final system. In other scenarios it may be very desirable to provide some
means of identification. For example, while still debugging it may be useful to see a simple string when printing
the contents of a power controller structure. Alternatively, if the application is expected to provide some sort
of user interface that gives control over which parts of the system are enabled or disabled, a string identifier
for each controller would be useful. To cope with these scenarios the power management package provides a
configuration option

CYGIMP_POWER_PROVIDE_STRINGS

. When enabled, each power controller will contain a

pointer to a constant string which can be accessed via a function

power_get_controller_id

. When disabled the

system will not contain these strings, and the function will not be provided. The following code illustrates how to
use this function.

#include

<

stdio.h

>

#include

<

pkgconf/system.h

>

#ifndef CYGPKG_POWER

# error The power management package is not present.

#endif

#include

<

pkgconf/power.h

>

#ifndef CYGIMP_POWER_PROVIDE_STRINGS

# error Power controller identifiers are not available.

558

Advertising