Support for policy modules, Name, Synopsis – Comtrol eCos User Manual

Page 667: Policy callbacks, Callback functions

Advertising
background image

Support for Policy Modules

Name

Support for Policy Modules

— closer integration with higher-level code

Synopsis

#include

<

cyg/power/power.h

>

void power_set_policy_callback ( void (*)(PowerController*, PowerMode, PowerMode,

PowerMode, PowerMode) callback );

void (*)(PowerController*, PowerMode, PowerMode, PowerMode, PowerMode)

power_get_policy_callback (void);

CYG_ADDRWORD power_get_controller_policy_data ( PowerController* controller );

void power_set_controller_policy_data ( PowerController* controller ,

CYG_ADDRWORD

data );

Policy Callbacks

The use of a separate thread to perform power mode changes in typical configurations can cause problems for
some policy modules. Specifically, the policy module can request a mode change for the system as a whole or
for an individual controller, but it does not know when the power management thread actually gets scheduled to
run again and carry out the request. Although it would be possible for the policy module to perform some sort of
polling, in general that is undesirable.

To avoid such problems the policy module can install a callback function using

power_set_policy_callback

.

The current callback function can be retrieved using

power_get_policy_callback

. If a callback function has

been installed then it will be called by the power management package whenever a power controller has been
invoked to perform a mode change. The callback will be called in the context of the power management thread, so
usually it will have to make use of thread synchronisation primitives to interact with the main policy module. It is
passed five arguments:

1. The power controller that has just been invoked to perform a mode change.

2. The mode this controller was running at before the invocation.

3. The current mode this controller is now running at.

4. The desired mode before the power controller was invoked. Usually this will be the same as the current mode,

unless the controller has decided for some reason that this was inappropriate.

5. The current desired mode. This will differ from the previous argument only if there has was another call to

power_set_mode

or

power_set_controller_mode

while the power controller was being invoked, probably

by the power controller itself.

A simple example of a policy callback function would be:

static void

power_callback(

563

Advertising