X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Flib%2Fpower%2FDeferredPowerManagerP.nc;h=209b5ffcbad38767825644d862454b77ac431a87;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hp=c3184bac13e9f8d57c6ef271259a8f62e09ad703;hpb=1ba974b83d19fc41bf80acd52726f36f7f1df297;p=tinyos-2.x.git diff --git a/tos/lib/power/DeferredPowerManagerP.nc b/tos/lib/power/DeferredPowerManagerP.nc index c3184bac..209b5ffc 100644 --- a/tos/lib/power/DeferredPowerManagerP.nc +++ b/tos/lib/power/DeferredPowerManagerP.nc @@ -29,6 +29,8 @@ */ /** + * Please refer to TEP 115 for more information about this component and its + * intended use.

* * This is the internal implementation of the deffered power management * policy for managing the power states of non-virtualized devices. @@ -45,52 +47,46 @@ * before shutting down the device once it is free. * * @author Kevin Klues (klueska@cs.wustl.edu) - * @see Please refer to TEP 115 for more information about this component and its - * intended use. */ generic module DeferredPowerManagerP(uint32_t delay) { - provides { - interface Init; - } uses { interface StdControl; interface SplitControl; interface PowerDownCleanup; - interface Init as ArbiterInit; - interface ResourceController; + interface ResourceDefaultOwner; interface ArbiterInfo; interface Timer as TimerMilli; } } implementation { - norace struct { - uint8_t stopping :1; - uint8_t requested :1; - } f; //for flags + norace bool stopping = FALSE; + norace bool requested = FALSE; + norace bool stopTimer = FALSE; - task void startTask() { + task void startTask() { + call TimerMilli.stop(); + stopTimer = FALSE; call StdControl.start(); - call SplitControl.start(); + if (call SplitControl.start()==EALREADY) + call ResourceDefaultOwner.release(); } + task void timerTask() { call TimerMilli.startOneShot(delay); } - command error_t Init.init() { - f.stopping = FALSE; - f.requested = FALSE; - call ArbiterInit.init(); - call ResourceController.immediateRequest(); - return SUCCESS; + async event void ResourceDefaultOwner.requested() { + if(stopping == FALSE) { + stopTimer = TRUE; + post startTask(); + } + else requested = TRUE; } - async event void ResourceController.requested() { - if(f.stopping == FALSE) - post startTask(); - else atomic f.requested = TRUE; + async event void ResourceDefaultOwner.immediateRequested() { } default command error_t StdControl.start() { @@ -102,37 +98,36 @@ implementation { } event void SplitControl.startDone(error_t error) { - call ResourceController.release(); + call ResourceDefaultOwner.release(); } - async event void ResourceController.idle() { - if(!(call ArbiterInfo.inUse())) - post timerTask(); + async event void ResourceDefaultOwner.granted() { + post timerTask(); } event void TimerMilli.fired() { - if(call ResourceController.immediateRequest() == SUCCESS) { - f.stopping = TRUE; - call PowerDownCleanup.cleanup(); - call StdControl.stop(); - call SplitControl.stop(); + atomic { + if(stopTimer == FALSE) { + stopping = TRUE; + call PowerDownCleanup.cleanup(); + call StdControl.stop(); + if (call SplitControl.stop()==EALREADY) + signal SplitControl.stopDone(SUCCESS); + } } } event void SplitControl.stopDone(error_t error) { - if(f.requested == TRUE) { + if(requested == TRUE) { call StdControl.start(); call SplitControl.start(); } atomic { - f.requested = FALSE; - f.stopping = FALSE; + requested = FALSE; + stopping = FALSE; } } - event void ResourceController.granted() { - } - default command error_t StdControl.stop() { return SUCCESS; }