Comtrol eCos User Manual

Page 676

Advertising
background image

Implementing a Power Controller

a. If the request cannot be satisfied immediately but may be feasible in a short while, leave the

mode

field

unchanged. Higher-level code in the policy module can interpret this as a hint to retry the operation a
little bit later. This approach is also useful if the mode change can be started but will take some time to
complete, for example shutting down a socket connection, and additional processing will be needed later
on.

b. If the request is felt to be inappropriate, for example switching off a device that is still in use, the mode

change function can call

power_set_controller_mode

to reset the desired mode for this controller

back to the current mode. Higher-level code can then interpret this as a hint that there is more activity in
the system than had been apparent.

c. For a global mode change, if the new mode is felt to be inappropriate then the power controller can call

power_set_mode

to indicate this. An example of this would be the policy module deciding to switch off

the whole unit while there is still I/O activity.

Mode change functions should not directly manipulate any other fields in the PowerController data structure. If it
is necessary to keep track of additional data then static variables can be used.

It should be noted that the above are only guidelines. Their application in any given situation may be unclear.
In addition the detailed requirements of specific systems will vary, so even if the power controller for a given
device driver follows the above guidelines exactly it may turn out that slightly different behaviour would be more
appropriate for the actual system that is being developed. Fortunately the open source nature of eCos allows system
developers to fine-tune power controllers to meet their exact requirements.

572

Advertising