X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fsystem%2FArbiterP.nc;h=b07f975dc4e5b2b2e762a90c020aff7772ec43cf;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hp=6bb79a2484e1e213e54046d5390ddf7613c32718;hpb=ec0de8e1ac425b0f6855d46f737c2726cd82df88;p=tinyos-2.x.git diff --git a/tos/system/ArbiterP.nc b/tos/system/ArbiterP.nc index 6bb79a24..b07f975d 100644 --- a/tos/system/ArbiterP.nc +++ b/tos/system/ArbiterP.nc @@ -32,27 +32,28 @@ * intended use.

* * This component provides the Resource, ResourceRequested, ArbiterInfo, - * and ResourceController interfaces and uses the ResourceConfigure interface as + * and ResourceDefaultOwner interfaces and uses the ResourceConfigure interface as * described in TEP 108. It provides arbitration to a shared resource. - * An Queue is used to keep track of which users have put + * A Queue is used to keep track of which users have put * in requests for the resource. Upon the release of the resource by one * of these users, the queue is checked and the next user * that has a pending request will ge granted control of the resource. If - * there are no pending requests, then the user of the ResourceController + * there are no pending requests, then the user of the ResourceDefaultOwner * interface gains access to the resource, and holds onto it until * another user makes a request. * - * @param resourceName -- The name of the Resource being shared + * @param default_owner_id -- The id of the default owner of this + * resource * * @author Kevin Klues (klues@tkn.tu-berlin.de) * @author Philip Levis */ -generic module ArbiterP(uint8_t controller_id) { +generic module ArbiterP(uint8_t default_owner_id) @safe() { provides { interface Resource[uint8_t id]; interface ResourceRequested[uint8_t id]; - interface ResourceController; + interface ResourceDefaultOwner; interface ArbiterInfo; } uses { @@ -64,10 +65,11 @@ generic module ArbiterP(uint8_t controller_id) { implementation { enum {RES_CONTROLLED, RES_GRANTING, RES_IMM_GRANTING, RES_BUSY}; - enum {CONTROLLER_ID = controller_id}; + enum {default_owner_id = default_owner_id}; + enum {NO_RES = 0xFF}; uint8_t state = RES_CONTROLLED; - norace uint8_t resId = CONTROLLER_ID; + norace uint8_t resId = default_owner_id; norace uint8_t reqResId; task void grantedTask(); @@ -81,7 +83,7 @@ implementation { } else return call Queue.enqueue(id); } - signal ResourceController.requested(); + signal ResourceDefaultOwner.requested(); return SUCCESS; } @@ -94,7 +96,7 @@ implementation { } else return FAIL; } - signal ResourceController.immediateRequested(); + signal ResourceDefaultOwner.immediateRequested(); if(resId == id) { call ResourceConfigure.configure[resId](); return SUCCESS; @@ -108,23 +110,26 @@ implementation { if(state == RES_BUSY && resId == id) { if(call Queue.isEmpty() == FALSE) { reqResId = call Queue.dequeue(); + resId = NO_RES; state = RES_GRANTING; post grantedTask(); + call ResourceConfigure.unconfigure[id](); } else { - resId = CONTROLLER_ID; + resId = default_owner_id; state = RES_CONTROLLED; - signal ResourceController.granted(); + call ResourceConfigure.unconfigure[id](); + signal ResourceDefaultOwner.granted(); } - call ResourceConfigure.unconfigure[id](); + return SUCCESS; } } return FAIL; } - async command error_t ResourceController.release() { + async command error_t ResourceDefaultOwner.release() { atomic { - if(resId == CONTROLLER_ID) { + if(resId == default_owner_id) { if(state == RES_GRANTING) { post grantedTask(); return SUCCESS; @@ -143,6 +148,10 @@ implementation { Check if the Resource is currently in use */ async command bool ArbiterInfo.inUse() { + atomic { + if (state == RES_CONTROLLED) + return FALSE; + } return TRUE; } @@ -152,7 +161,11 @@ implementation { will be 0xFF */ async command uint8_t ArbiterInfo.userId() { - atomic return resId; + atomic { + if(state != RES_BUSY) + return NO_RES; + return resId; + } } /** @@ -160,13 +173,15 @@ implementation { */ async command uint8_t Resource.isOwner[uint8_t id]() { atomic { - if(resId == id) return TRUE; + if(resId == id && state == RES_BUSY) return TRUE; else return FALSE; } } - async command uint8_t ResourceController.isOwner() { - return call Resource.isOwner[CONTROLLER_ID](); + async command uint8_t ResourceDefaultOwner.isOwner() { + atomic return (state == RES_CONTROLLED + || (resId == default_owner_id + && (state == RES_GRANTING || state == RES_IMM_GRANTING))); } task void grantedTask() { @@ -187,13 +202,13 @@ implementation { } default async event void ResourceRequested.immediateRequested[uint8_t id]() { } - default async event void ResourceController.granted() { + default async event void ResourceDefaultOwner.granted() { } - default async event void ResourceController.requested() { - call ResourceController.release(); + default async event void ResourceDefaultOwner.requested() { + call ResourceDefaultOwner.release(); } - default async event void ResourceController.immediateRequested() { - call ResourceController.release(); + default async event void ResourceDefaultOwner.immediateRequested() { + call ResourceDefaultOwner.release(); } default async command void ResourceConfigure.configure[uint8_t id]() { }