]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/mac/tkn154/SimpleTransferArbiterP.nc
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / tos / lib / mac / tkn154 / SimpleTransferArbiterP.nc
index 76ae05b4294bae3e70e44bd1d7c0784a50fbf22e..1262c5a2ff47b3cc8a1d5a8db4fd66cbe48207fc 100644 (file)
  * 
  * @author Kevin Klues (klues@tkn.tu-berlin.de)
  * @author Philip Levis
- * @author: Jan Hauer <hauer@tkn.tu-berlin.de> (added resource transfer)
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de> (added TransferableResource interface)
  */
  
 generic module SimpleTransferArbiterP() {
   provides {
-    interface Resource[uint8_t id];
+    interface TransferableResource as Resource[uint8_t id];
     interface ResourceRequested[uint8_t id];
-    interface ResourceTransferControl;
     interface ArbiterInfo;
-    interface GetNow<bool> as IsResourceRequested;
   }
   uses {
     interface ResourceConfigure[uint8_t id];
@@ -68,17 +66,12 @@ implementation {
   uint8_t state = RES_IDLE;
   norace uint8_t resId = NO_RES;
   norace uint8_t reqResId;
-  norace uint8_t numTransfers;
-  norace bool reqWhileTransferred;
   
   task void grantedTask();
-  task void checkResourceRequestedTask();
   
   async command error_t Resource.request[uint8_t id]() {
     signal ResourceRequested.requested[resId]();
     atomic {
-      if (numTransfers > 0)
-        reqWhileTransferred = TRUE;
       if(state == RES_IDLE) {
         state = RES_GRANTING;
         reqResId = id;
@@ -106,8 +99,6 @@ implementation {
     bool released = FALSE;
     atomic {
       if(state == RES_BUSY && resId == id) {
-        numTransfers = 0;
-        reqWhileTransferred = FALSE;
         if(call Queue.isEmpty() == FALSE) {
           reqResId = call Queue.dequeue();
           state = RES_GRANTING;
@@ -127,36 +118,19 @@ implementation {
     return FAIL;
   }
 
-  async command bool IsResourceRequested.getNow()
-  {
-    return reqWhileTransferred;
-  }
-
-  task void checkResourceRequestedTask()
-  {
-    if (numTransfers && reqWhileTransferred)
-      signal ResourceRequested.requested[resId]();
-  }
-
-  async command error_t ResourceTransferControl.transfer(uint8_t fromClient, uint8_t toClient)
+  async command error_t Resource.transferTo[uint8_t fromID](uint8_t toID)
   {
     atomic {
-      if (call ArbiterInfo.userId() == fromClient){
-        numTransfers += 1;
-        call ResourceConfigure.unconfigure[fromClient]();
+      if (call ArbiterInfo.userId() == fromID) {
+        call ResourceConfigure.unconfigure[fromID]();
         call ResourceConfigure.configure[resId]();
-        resId = toClient;
-        post checkResourceRequestedTask();
+        resId = toID;
+        signal Resource.transferredFrom[toID](fromID); // consider moving this outside the atomic
         return SUCCESS;
       }
-    } 
+    }
     return FAIL;
   }
-
-  async command error_t ResourceTransferControl.release(uint8_t client)
-  {
-    return call Resource.release[client]();
-  }
     
   /**
     Check if the Resource is currently in use
@@ -212,4 +186,6 @@ implementation {
   }
   default async command void ResourceConfigure.unconfigure[uint8_t id]() {
   }
+  default async event void Resource.transferredFrom[uint8_t id](uint8_t c) {
+  }
 }