Policyspecific controller data, Policy-specific controller data – Comtrol eCos User Manual
Page 668
Support for Policy Modules
PowerController* controller,
PowerMode old_mode,
PowerMode new_mode,
PowerMode old_desired_mode,
powerMode new_desired_mode)
{
printf("Power mode change: %s, %s -> %d\n",
power_get_controller_id(controller),
mode_to_string(old_mode),
mode_to_string(new_mode));
CYG_UNUSED_PARAM(PowerMode, old_desired_mode);
CYG_UNUSED_PARAM(PowerMode, new_desired_mode);
}
int
main(int argc, char** argv)
{
...
power_set_policy_callback(&power_callback);
...
}
If
power_set_controller_mode_now
is used to manipulate an individual controller the policy callback will not
be invoked. This function may get called from any context including DSRs, and even if there is already a call to
the policy callback happening in some other context, so invoking the callback would usually be unsafe.
If the power management package has not been configured to use a separate thread then
power_set_mode
and
power_set_controller_mode
will manipulate the power controllers immediately and invoke the policy callback
afterwards. Therefore the policy callback will typically run in the same context as the main policy module.
Policy-specific Controller Data
Some policy modules may want to associate some additional data with each power controller. This could be
achieved by for example maintaining a hash table or similar data structure, but for convenience the power man-
agement package allows higher-level code, typically the policy module, to store and retrieve one word of data in
each power controller. The function
power_set_controller_policy_data
takes two arguments, a pointer to a
power controller and a CYG_ADDRWORD of data: by appropriate use of casts this word could be an integer or a
pointer to some data structure. The matching function
power_get_controller_policy_data
retrieves the word
previously installed, and can be cast back to an integer or pointer. The default value for the policy data is 0.
For example the following code fragment stores a simple index value in each power controller. This could then be
retrieved by the policy callback.
unsigned int
i = 0;
PowerController* controller;
for (controller = &(__POWER__[0]);
controller != &(__POWER_END__);
controller++) {
power_set_controller_policy_data(controller, (CYG_ADDRWORD) i++);
}
564