Manipulating an individual power controller, Direct manipulation of a power controller – Comtrol eCos User Manual

Page 666

Advertising
background image

Changing Power Modes

However, it is still legal for a power controller to call

power_set_mode

: effectively this is a recursive call; it is

detected by the system, and internal state is updated; the recursive

power_set_mode

call now returns, and when

the power controller returns back to the original

power_set_mode

call it detects what has happened, aborts the

previous mode change, and starts a new mode change as requested by the controller.

power_set_mode

is normally invoked from thread context. If a separate power management thread is used it can

be invoked safely from DSR context. If the system is configured not to use such a thread, it may or may not be
safe to invoke this function from DSR context: essentially the function just iterates through the various power
controllers, and the documentation or source code of each controller present in the current system will have to be
examined to determine whether or not this can happen safely in DSR context.

power_set_mode

should never be

invoked from ISR context.

Manipulating an Individual Power Controller

In some cases it is desirable to set the power mode of an individual controller separately from the mode for
the system as a whole. For example if a device is not currently being used then the associated power con-
troller could be set to

PowerMode_Off

, even while the system as a whole is still active. This can be achieved

by calling the function

power_set_controller_mode

. It takes two arguments: the first identifies a particular

controller; the second specifies the desired new power mode for that controller. The function operates in much
the same way as

power_set_mode

, for example if a separate power management thread is being used then

power_set_controller_mode

operates by manipulating some internal state and waking up that thread. The lim-

itations are also much the same as for

power_set_mode

, so for example

power_set_controller_mode

should

not be invoked from inside ISRs.

Manipulating

individual

controllers

is

often

used

in

conjunction

with

the

function

power_set_controller_attached

, allowing the policy module to specify which controllers are affected by

global mode changes.

Direct Manipulation of a Power Controller

In exceptional circumstances it may be necessary to invoke a power controller directly, bypassing the
power management thread and higher-level functionality such as

callback functions

. The function

power_set_controller_mode_now

allows this. It takes two arguments, a controller and a mode, just like

power_set_controller_mode

.

Use of

power_set_controller_mode_now

is dangerous. For example no attempt is made to synchronise with

any other power mode changes that might be happening concurrently. A possible use is when the system gets woken
up out of sleep mode: depending on the hardware, on which power controllers are present, and on the application
code it may be necessary to wake up some power controllers immediately before the system as a whole is ready to
run again.

562

Advertising