[Tinyos-2-commits] CVS: tinyos-2.x/tos/system/arbiters ArbiterP.nc,
NONE, 1.1.2.1 AsyncArbiterP.nc, NONE,
1.1.2.1 AsyncFcfsArbiterC.nc, NONE,
1.1.2.1 AsyncFcfsPriorityArbiterC.nc, NONE,
1.1.2.1 AsyncPriorityArbiterP.nc, NONE,
1.1.2.1 AsyncRoundRobinArbiterC.nc, NONE,
1.1.2.1 AsyncRoundRobinPriorityArbiterC.nc, NONE,
1.1.2.1 FcfsArbiterC.nc, NONE, 1.1.2.1 FcfsPriorityArbiterC.nc,
NONE, 1.1.2.1 ImmediateArbiterC.nc, NONE,
1.1.2.1 NoArbiterC.nc, NONE, 1.1.2.1 PriorityArbiterP.nc, NONE,
1.1.2.1 RoundRobinArbiterC.nc, NONE,
1.1.2.1 RoundRobinPriorityArbiterC.nc, NONE, 1.1.2.1
Kevin Klues
klueska at users.sourceforge.net
Mon May 15 11:15:36 PDT 2006
Update of /cvsroot/tinyos/tinyos-2.x/tos/system/arbiters
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11401/tos/system/arbiters
Added Files:
Tag: tos-2-resource-pm-eval-cand
ArbiterP.nc AsyncArbiterP.nc AsyncFcfsArbiterC.nc
AsyncFcfsPriorityArbiterC.nc AsyncPriorityArbiterP.nc
AsyncRoundRobinArbiterC.nc AsyncRoundRobinPriorityArbiterC.nc
FcfsArbiterC.nc FcfsPriorityArbiterC.nc ImmediateArbiterC.nc
NoArbiterC.nc PriorityArbiterP.nc RoundRobinArbiterC.nc
RoundRobinPriorityArbiterC.nc
Log Message:
new arbiter implementations
--- NEW FILE: ArbiterP.nc ---
/*
* "Copyright (c) 2005 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/05/15 18:15:34 $
* ========================================================================
*/
/**
* Please refer to TEP 108 for more information about this component and its
* intended use.<br><br>
*
* This component provides the Resource, ArbiterInfo, and Resource
* Controller interfaces and uses the ResourceConfigure interface as
* described in TEP 108. It provides arbitration to a shared resource.
* An array 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 array 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 resource becomes idle and any
* user can put in a request and immediately receive access to the
* Resource.
*
* @param <b>resourceName</b> -- The name of the Resource being shared
*
* @author Kevin Klues (klues at tkn.tu-berlin.de)
* @author Philip Levis
*/
generic module ArbiterP(uint8_t controllerId) {
provides {
interface Resource[uint8_t id];
interface ResourceController;
interface ArbiterInfo;
}
uses {
interface ResourceConfigure[uint8_t id];
interface Queue;
}
}
implementation {
enum {RES_IDLE, RES_GRANTING, RES_BUSY};
enum {NO_RES = 0xFF};
enum {CONTROLLER_ID = controllerId};
uint8_t state = RES_IDLE;
uint8_t resId = NO_RES;
uint8_t reqResId;
task void grantedTask();
task void requestedTask();
/**
Request the use of the shared resource
If the user has not already requested access to the
resource, the request will be either served immediately
or queued for later service.
A SUCCESS value will be returned and the user will receive
the granted() event in synchronous context once it has
been given access to the resource.
Whenever requests are queued, the current owner of the bus
will receive a requested() event, notifying him that another
user would like to have access to the resource.
If the user has already requested access to the resource and
is waiting on a pending granted() event, an EBUSY value will
be returned to the caller.
*/
command error_t Resource.request[uint8_t id]() {
if(state == RES_IDLE) {
atomic state = RES_GRANTING;
atomic reqResId = id;
post grantedTask();
return SUCCESS;
}
if(resId == CONTROLLER_ID)
post requestedTask();
return call Queue.push(id);
}
command error_t ResourceController.request() {
call Resource.request[CONTROLLER_ID]();
}
command error_t ResourceController.immediateRequest() {
if(state == RES_IDLE) {
atomic state = RES_BUSY;
atomic resId = CONTROLLER_ID;
return SUCCESS;
}
return FAIL;
}
/**
Release the use of the shared resource
The resource will only actually be released if
there are no pending requests for the resource.
If requests are pending, then the next pending request
will be serviced, according to a First come first serve
arbitration scheme. If no requests are currently
pending, then the resource is released, and any
users can put in a request for immediate access to
the resource.
*/
command void Resource.release[uint8_t id]() {
if (state == RES_BUSY && resId == id) {
reqResId = call Queue.pop();
if(reqResId != NO_RES) {
atomic state = RES_GRANTING;
post grantedTask();
}
else {
atomic resId = NO_RES;
atomic state = RES_IDLE;
signal ResourceController.idle();
}
call ResourceConfigure.unconfigure[id]();
}
}
command void ResourceController.release() {
call Resource.release[CONTROLLER_ID]();
}
/**
Check if the Resource is currently in use
*/
async command bool ArbiterInfo.inUse() {
atomic {
if ( state == RES_IDLE )
return FALSE;
}
return TRUE;
}
/**
Returns the current user of the Resource.
If there is no current user, the return value
will be 0xFF
*/
async command uint8_t ArbiterInfo.userId() {
atomic return resId;
}
/**
* Returns my user id.
*/
async command uint8_t Resource.isOwner[uint8_t id]() {
atomic {
if(resId == id) return TRUE;
else return FALSE;
}
}
async command uint8_t ResourceController.isOwner() {
return call Resource.isOwner[CONTROLLER_ID]();
}
//Task for pulling the Resource.granted() signal
//into synchronous context
task void grantedTask() {
atomic resId = reqResId;
atomic state = RES_BUSY;
call ResourceConfigure.configure[resId]();
signal Resource.granted[resId]();
}
//Task for pulling the ResourceController.requested() signal
//into synchronous context
task void requestedTask() {
signal ResourceController.requested();
}
//Default event/command handlers for all of the other
//potential users/providers of the parameterized interfaces
//that have not been connected to.
default event void Resource.granted[uint8_t id]() {
signal ResourceController.granted();
}
default event void ResourceController.granted() {
}
default event void ResourceController.requested() {
}
default event void ResourceController.idle() {
}
default async command void ResourceConfigure.configure[uint8_t id]() {
}
default async command void ResourceConfigure.unconfigure[uint8_t id]() {
}
}
--- NEW FILE: AsyncArbiterP.nc ---
/*
* "Copyright (c) 2005 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/05/15 18:15:34 $
* ========================================================================
*/
/**
* Please refer to TEP 108 for more information about this component and its
* intended use.<br><br>
*
* This component provides the Resource, ArbiterInfo, and Resource
* Controller interfaces and uses the ResourceConfigure interface as
* described in TEP 108. It provides arbitration to a shared resource.
* An array 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 array 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 resource becomes idle and any
* user can put in a request and immediately receive access to the
* Resource.
*
* @param <b>resourceName</b> -- The name of the Resource being shared
*
* @author Kevin Klues (klues at tkn.tu-berlin.de)
* @author Philip Levis
*/
generic module AsyncArbiterP(uint8_t controllerId) {
provides {
interface AsyncResource[uint8_t id];
interface AsyncResourceController;
interface ArbiterInfo;
}
uses {
interface ResourceConfigure[uint8_t id];
interface AsyncQueue as Queue;
}
}
implementation {
enum {RES_IDLE, RES_GRANTING, RES_BUSY};
enum {NO_RES = 0xFF};
enum {CONTROLLER_ID = controllerId};
uint8_t state = RES_IDLE;
uint8_t resId = NO_RES;
uint8_t reqResId;
task void grantedTask();
task void requestedTask();
task void idleTask();
/**
Request the use of the shared resource
If the user has not already requested access to the
resource, the request will be either served immediately
or queued for later service.
A SUCCESS value will be returned and the user will receive
the granted() event in synchronous context once it has
been given access to the resource.
Whenever requests are queued, the current owner of the bus
will receive a requested() event, notifying him that another
user would like to have access to the resource.
If the user has already requested access to the resource and
is waiting on a pending granted() event, an EBUSY value will
be returned to the caller.
*/
async command error_t AsyncResource.request[uint8_t id]() {
atomic {
if(state == RES_IDLE) {
state = RES_GRANTING;
reqResId = id;
post grantedTask();
return SUCCESS;
}
if(resId == CONTROLLER_ID)
post requestedTask();
return call Queue.push(id);
}
}
async command error_t AsyncResourceController.request() {
call AsyncResource.request[CONTROLLER_ID]();
}
async command error_t AsyncResourceController.immediateRequest() {
atomic {
if(state == RES_IDLE) {
state = RES_BUSY;
resId = CONTROLLER_ID;
return SUCCESS;
}
return FAIL;
}
}
/**
Release the use of the shared resource
The resource will only actually be released if
there are no pending requests for the resource.
If requests are pending, then the next pending request
will be serviced, according to a First come first serve
arbitration scheme. If no requests are currently
pending, then the resource is released, and any
users can put in a request for immediate access to
the resource.
*/
async command void AsyncResource.release[uint8_t id]() {
bool released = FALSE;
atomic {
if (state == RES_BUSY && resId == id) {
reqResId = call Queue.pop();
if(reqResId != NO_RES) {
state = RES_GRANTING;
post grantedTask();
}
else {
resId = NO_RES;
state = RES_IDLE;
post idleTask();
}
released = TRUE;
}
}
if(released == TRUE)
call ResourceConfigure.unconfigure[id]();
}
async command void AsyncResourceController.release() {
call AsyncResource.release[CONTROLLER_ID]();
}
/**
Check if the Resource is currently in use
*/
async command bool ArbiterInfo.inUse() {
atomic {
if ( state == RES_IDLE )
return FALSE;
}
return TRUE;
}
/**
Returns the current user of the Resource.
If there is no current user, the return value
will be 0xFF
*/
async command uint8_t ArbiterInfo.userId() {
atomic return resId;
}
/**
* Returns my user id.
*/
async command uint8_t AsyncResource.isOwner[uint8_t id]() {
atomic {
if(resId == id) return TRUE;
else return FALSE;
}
}
async command uint8_t AsyncResourceController.isOwner() {
return call AsyncResource.isOwner[CONTROLLER_ID]();
}
task void grantedTask() {
uint8_t tmpId;
atomic {
tmpId = resId = reqResId;
state = RES_BUSY;
}
call ResourceConfigure.configure[tmpId]();
signal AsyncResource.granted[tmpId]();
}
task void requestedTask() {
signal AsyncResourceController.requested();
}
task void idleTask() {
signal AsyncResourceController.idle();
}
//Default event/command handlers
default event void AsyncResource.granted[uint8_t id]() {
signal AsyncResourceController.granted();
}
default event void AsyncResourceController.granted() {
}
default event void AsyncResourceController.requested() {
}
default event void AsyncResourceController.idle() {
}
default async command void ResourceConfigure.configure[uint8_t id]() {
}
default async command void ResourceConfigure.unconfigure[uint8_t id]() {
}
}
--- NEW FILE: AsyncFcfsArbiterC.nc ---
/*
* "Copyright (c) 2005 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/05/15 18:15:34 $
* ========================================================================
*/
/**
* Please refer to TEP 108 for more information about this component and its
* intended use.<br><br>
*
* This component provides the Resource, ArbiterInfo, and Resource
* Controller interfaces and uses the ResourceConfigure interface as
* described in TEP 108. It provides arbitration to a shared resource in
* an FCFS fashion. An array 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 array is checked and the next user (in FCFS order)
* that has a pending request will ge granted control of the resource. If
* there are no pending requests, then the resource becomes idle and any
* user can put in a request and immediately receive access to the
* Resource.
*
* @param <b>resourceName</b> -- The name of the Resource being shared
*
* @author Kevin Klues (klues at tkn.tu-berlin.de)
* @author Philip Levis
*/
generic configuration AsyncFcfsArbiterC(char resourceName[]) {
provides {
interface AsyncResource as Resource[uint8_t id];
interface AsyncResourceController as ResourceController;
interface ArbiterInfo;
}
}
implementation {
components MainC;
components new AsyncFcfsQueueC(uniqueCount(resourceName)) as Queue;
components new AsyncArbiterP(uniqueCount(resourceName)) as Arbiter;
MainC.SoftwareInit -> Queue;
Resource = Arbiter;
ResourceController = Arbiter;
ArbiterInfo = Arbiter;
Arbiter.Queue -> Queue;
}
--- NEW FILE: AsyncFcfsPriorityArbiterC.nc ---
/*
* "Copyright (c) 2005 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/05/15 18:15:34 $
* ========================================================================
*/
/**
* Please refer to TEP 108 for more information about this component and its
* intended use.<br><br>
*
* This component provides the Resource, ArbiterInfo, and Resource
* Controller interfaces and uses the ResourceConfigure interface as
* described in TEP 108. It provides arbitration to a shared resource in a
* round robin fashion. An array 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 array is checked and the next user (in round
* robin order) that has a pending request will ge granted control of the
* resource. If there are no pending requests, then the resource becomes
* idle and any user can put in a request and immediately receive access to
* the round robin order * Resource.
*
* @param <b>resourceName</b> -- The name of the Resource being shared
*
* @author Kevin Klues (klues at tkn.tu-berlin.de)
* @author Philip Levis
*/
generic configuration AsyncFcfsPriorityArbiterC(char resourceName[]) {
provides {
interface AsyncResource as Resource[uint8_t id];
interface AsyncResourceController as HighPriorityClient;
interface AsyncResourceController as LowPriorityClient;
interface ArbiterInfo;
}
}
implementation {
components MainC;
components new AsyncFcfsQueueC(uniqueCount(resourceName)) as Queue;
components new AsyncPriorityArbiterP(uniqueCount(resourceName), uniqueCount(resourceName) + 1) as Arbiter;
MainC.SoftwareInit -> Queue;
Resource = Arbiter;
HighPriorityClient = Arbiter.HighPriorityClient;
LowPriorityClient = Arbiter.LowPriorityClient;
ArbiterInfo = Arbiter;
Arbiter.Queue -> Queue;
}
--- NEW FILE: AsyncPriorityArbiterP.nc ---
/*
* "Copyright (c) 2005 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/05/15 18:15:34 $
* ========================================================================
*/
/**
* Please refer to TEP 108 for more information about this component and its
* intended use.<br><br>
*
* This component provides the Resource, ArbiterInfo, and Resource
* Controller interfaces and uses the ResourceConfigure interface as
* described in TEP 108. An additional ResourceController interface is
* provided to allow clients of differing Priorities to control the
* Resource according to some policy implemented in an external
* component. This component provides arbitration to a shared resource in
* an FCFS fashion. An array 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 array is checked and the next user (in first-come
* first-served order) that has a pending request will ge granted control
* of the resource. If there are no pending requests, then the resource
* becomes idle and any user can put in a request and immediately receive
* access to the Resource.
*
* @param <b>resourceName</b> -- The name of the Resource being shared
*
* @author Kevin Klues (klues at tkn.tu-berlin.de)
* @author Philip Levis
* @author Philipp Huppertz
*/
generic module AsyncPriorityArbiterP(uint8_t highPriorityClientId, uint8_t lowPriorityClientId) {
provides {
interface AsyncResource as Resource[uint8_t id];
interface AsyncResourceController as HighPriorityClient;
interface AsyncResourceController as LowPriorityClient;
interface ArbiterInfo;
}
uses {
interface ResourceConfigure[uint8_t id];
interface AsyncQueue as Queue;
}
}
implementation {
enum {RES_IDLE, RES_GRANTING, RES_BUSY};
enum {NO_RES = 0xFF};
enum {LOW_PRIORITY_CLIENT_ID = lowPriorityClientId};
enum {HIGH_PRIORITY_CLIENT_ID = highPriorityClientId};
uint8_t state = RES_IDLE;
uint8_t resId = NO_RES;
uint8_t reqResId = NO_RES;
bool hpreq = FALSE; // request from the high priority client
task void grantedTask();
task void lowRequestedTask();
task void highRequestedTask();
task void lowIdleTask();
task void highIdleTask();
/**
Request the use of the shared resource
If the user has not already requested access to the
resource, the request will be either served immediately
or queued for later service.
A SUCCESS value will be returned and the user will receive
the granted() event in synchronous context once it has
been given access to the resource.
Whenever requests are queued, the highest priority client
will receive a requested() event after he receives granted(),
notifying him that another user would like to have access to the resource.
If the user has already requested access to the resource and
is waiting on a pending granted() event, an EBUSY value will
be returned to the caller.
*/
async command error_t Resource.request[uint8_t id]() {
atomic {
if(state == RES_IDLE ) {
state = RES_GRANTING;
atomic reqResId = id;
post grantedTask();
return SUCCESS;
}
if(resId == LOW_PRIORITY_CLIENT_ID)
post lowRequestedTask();
else if (resId == HIGH_PRIORITY_CLIENT_ID)
post highRequestedTask();
return call Queue.push(id);
}
}
async command error_t LowPriorityClient.request() {
atomic {
if((state == RES_IDLE) && (!hpreq)) {
state = RES_GRANTING;
reqResId = LOW_PRIORITY_CLIENT_ID;
post grantedTask();
return SUCCESS;
}
return EBUSY;
}
}
async command error_t HighPriorityClient.request() {
atomic {
hpreq = TRUE;
if(resId == LOW_PRIORITY_CLIENT_ID)
post lowRequestedTask();
if(state == RES_IDLE) {
state = RES_GRANTING;
reqResId = HIGH_PRIORITY_CLIENT_ID;
post grantedTask();
}
return SUCCESS;
}
}
async command error_t LowPriorityClient.immediateRequest() {
atomic {
if((state == RES_IDLE) && (!hpreq)) {
state = RES_GRANTING;
resId = LOW_PRIORITY_CLIENT_ID;
return SUCCESS;
}
return EBUSY;
}
}
async command error_t HighPriorityClient.immediateRequest() {
atomic {
if(state == RES_IDLE) {
state = RES_GRANTING;
resId = HIGH_PRIORITY_CLIENT_ID;
return SUCCESS;
}
return EBUSY;
}
}
/**
Release the use of the shared resource
The resource will only actually be released if
there are no pending requests for the resource.
If requests are pending, then the next pending request
will be serviced, according to a Fist come first serve
arbitration scheme. If no requests are currently
pending, then the resource is released, and any
users can put in a request for immediate access to
the resource.
*/
async command void Resource.release[uint8_t id]() {
bool released = FALSE;
atomic {
if (state == RES_BUSY && resId == id) {
reqResId = call Queue.pop();
if(reqResId != NO_RES) {
state = RES_GRANTING;
post grantedTask();
}
else {
resId = NO_RES;
state = RES_IDLE;
post highIdleTask();
post lowIdleTask();
}
released = TRUE;
}
}
if(released == TRUE)
call ResourceConfigure.unconfigure[id]();
}
async command void LowPriorityClient.release() {
call Resource.release[LOW_PRIORITY_CLIENT_ID]();
}
async command void HighPriorityClient.release() {
call Resource.release[HIGH_PRIORITY_CLIENT_ID]();
}
/**
Check if the Resource is currently in use
*/
async command bool ArbiterInfo.inUse() {
atomic {
if ( state == RES_IDLE )
return FALSE;
}
return TRUE;
}
/**
Returns the current user of the Resource.
If there is no current user, the return value
will be 0xFF
*/
async command uint8_t ArbiterInfo.userId() {
atomic return resId;
}
/**
* Returns my user id.
*/
async command uint8_t Resource.isOwner[uint8_t id]() {
atomic {
if(resId == id) return TRUE;
else return FALSE;
}
}
async command uint8_t LowPriorityClient.isOwner() {
return call Resource.isOwner[LOW_PRIORITY_CLIENT_ID]();
}
async command uint8_t HighPriorityClient.isOwner() {
return call Resource.isOwner[HIGH_PRIORITY_CLIENT_ID]();
}
task void grantedTask() {
uint8_t tmpId;
atomic {
tmpId = resId = reqResId;
state = RES_BUSY;
}
if(tmpId == HIGH_PRIORITY_CLIENT_ID) {
signal HighPriorityClient.granted();
// lets throw pending request at him...
if (call Queue.isEmpty() == FALSE) {
signal HighPriorityClient.requested();
}
}
else if(tmpId == LOW_PRIORITY_CLIENT_ID)
signal LowPriorityClient.granted();
else {
call ResourceConfigure.configure[tmpId]();
signal Resource.granted[tmpId]();
}
}
task void lowRequestedTask() {
signal LowPriorityClient.requested();
}
task void highRequestedTask() {
signal HighPriorityClient.requested();
}
task void highIdleTask() {
signal HighPriorityClient.idle();
}
task void lowIdleTask() {
signal LowPriorityClient.idle();
}
//Default event/command handlers
default event void Resource.granted[uint8_t id]() {
signal LowPriorityClient.granted();
}
default event void LowPriorityClient.granted() {
}
default event void LowPriorityClient.requested() {
}
default event void LowPriorityClient.idle() {
}
default event void HighPriorityClient.granted() {
}
default event void HighPriorityClient.requested() {
}
default event void HighPriorityClient.idle() {
}
default async command void ResourceConfigure.configure[uint8_t id]() {
}
default async command void ResourceConfigure.unconfigure[uint8_t id]() {
}
}
--- NEW FILE: AsyncRoundRobinArbiterC.nc ---
/*
* "Copyright (c) 2005 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/05/15 18:15:34 $
* ========================================================================
*/
/**
* Please refer to TEP 108 for more information about this component and its
* intended use.<br><br>
*
* This component provides the Resource, ArbiterInfo, and Resource
* Controller interfaces and uses the ResourceConfigure interface as
* described in TEP 108. It provides arbitration to a shared resource in
* an FCFS fashion. An array 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 array is checked and the next user (in FCFS order)
* that has a pending request will ge granted control of the resource. If
* there are no pending requests, then the resource becomes idle and any
* user can put in a request and immediately receive access to the
* Resource.
*
* @param <b>resourceName</b> -- The name of the Resource being shared
*
* @author Kevin Klues (klues at tkn.tu-berlin.de)
* @author Philip Levis
*/
generic configuration AsyncRoundRobinArbiterC(char resourceName[]) {
provides {
interface AsyncResource as Resource[uint8_t id];
interface AsyncResourceController as ResourceController;
interface ArbiterInfo;
}
}
implementation {
components MainC;
components new AsyncRoundRobinQueueC(uniqueCount(resourceName)) as Queue;
components new AsyncArbiterP(uniqueCount(resourceName)) as Arbiter;
MainC.SoftwareInit -> Queue;
Resource = Arbiter;
ResourceController = Arbiter;
ArbiterInfo = Arbiter;
Arbiter.Queue -> Queue;
}
--- NEW FILE: AsyncRoundRobinPriorityArbiterC.nc ---
/*
* "Copyright (c) 2005 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/05/15 18:15:34 $
* ========================================================================
*/
/**
* Please refer to TEP 108 for more information about this component and its
* intended use.<br><br>
*
* This component provides the Resource, ArbiterInfo, and Resource
* Controller interfaces and uses the ResourceConfigure interface as
* described in TEP 108. It provides arbitration to a shared resource in a
* round robin fashion. An array 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 array is checked and the next user (in round
* robin order) that has a pending request will ge granted control of the
* resource. If there are no pending requests, then the resource becomes
* idle and any user can put in a request and immediately receive access to
* the round robin order * Resource.
*
* @param <b>resourceName</b> -- The name of the Resource being shared
*
* @author Kevin Klues (klues at tkn.tu-berlin.de)
* @author Philip Levis
*/
generic configuration AsyncRoundRobinPriorityArbiterC(char resourceName[]) {
provides {
interface AsyncResource as Resource[uint8_t id];
interface AsyncResourceController as HighPriorityClient;
interface AsyncResourceController as LowPriorityClient;
interface ArbiterInfo;
}
}
implementation {
components MainC;
components new AsyncRoundRobinQueueC(uniqueCount(resourceName)) as Queue;
components new AsyncPriorityArbiterP(uniqueCount(resourceName), uniqueCount(resourceName) + 1) as Arbiter;
MainC.SoftwareInit -> Queue;
Resource = Arbiter;
HighPriorityClient = Arbiter.HighPriorityClient;
LowPriorityClient = Arbiter.LowPriorityClient;
ArbiterInfo = Arbiter;
Arbiter.Queue -> Queue;
}
--- NEW FILE: FcfsArbiterC.nc ---
/*
* "Copyright (c) 2005 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/05/15 18:15:34 $
* ========================================================================
*/
/**
* Please refer to TEP 108 for more information about this component and its
* intended use.<br><br>
*
* This component provides the Resource, ArbiterInfo, and Resource
* Controller interfaces and uses the ResourceConfigure interface as
* described in TEP 108. It provides arbitration to a shared resource in
* an FCFS fashion. An array 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 array is checked and the next user (in FCFS order)
* that has a pending request will ge granted control of the resource. If
* there are no pending requests, then the resource becomes idle and any
* user can put in a request and immediately receive access to the
* Resource.
*
* @param <b>resourceName</b> -- The name of the Resource being shared
*
* @author Kevin Klues (klues at tkn.tu-berlin.de)
* @author Philip Levis
*/
generic configuration FcfsArbiterC(char resourceName[]) {
provides {
interface Resource[uint8_t id];
interface ResourceController;
interface ArbiterInfo;
}
}
implementation {
components MainC;
components new FcfsQueueC(uniqueCount(resourceName)) as Queue;
components new ArbiterP(uniqueCount(resourceName)) as Arbiter;
MainC.SoftwareInit -> Queue;
Resource = Arbiter;
ResourceController = Arbiter;
ArbiterInfo = Arbiter;
Arbiter.Queue -> Queue;
}
--- NEW FILE: FcfsPriorityArbiterC.nc ---
/*
* "Copyright (c) 2005 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/05/15 18:15:34 $
* ========================================================================
*/
/**
* Please refer to TEP 108 for more information about this component and its
* intended use.<br><br>
*
* This component provides the Resource, ArbiterInfo, and Resource
* Controller interfaces and uses the ResourceConfigure interface as
* described in TEP 108. It provides arbitration to a shared resource in
* an FCFS fashion. An array 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 array is checked and the next user (in FCFS order)
* that has a pending request will ge granted control of the resource. If
* there are no pending requests, then the resource becomes idle and any
* user can put in a request and immediately receive access to the
* Resource.
*
* @param <b>resourceName</b> -- The name of the Resource being shared
*
* @author Kevin Klues (klues at tkn.tu-berlin.de)
* @author Philip Levis
*/
generic configuration FcfsPriorityArbiterC(char resourceName[]) {
provides {
interface Resource[uint8_t id];
interface ResourceController as HighPriorityClient;
interface ResourceController as LowPriorityClient;
interface ArbiterInfo;
}
}
implementation {
components MainC;
components new FcfsQueueC(uniqueCount(resourceName)) as Queue;
components new PriorityArbiterP(uniqueCount(resourceName), uniqueCount(resourceName) + 1) as Arbiter;
MainC.SoftwareInit -> Queue;
Resource = Arbiter;
HighPriorityClient = Arbiter.HighPriorityClient;
LowPriorityClient = Arbiter.LowPriorityClient;
ArbiterInfo = Arbiter;
Arbiter.Queue -> Queue;
}
--- NEW FILE: ImmediateArbiterC.nc ---
/*
* "Copyright (c) 2005 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/05/15 18:15:34 $
* ========================================================================
*/
/**
* Please refer to TEP 108 for more information about this component and its
* intended use.<br><br>
*
* This component provides the Resource, ArbiterInfo, and Resource
* Controller interfaces and uses the ResourceConfigure interface as
* described in TEP 108. It provides arbitration to a shared resource.
* An array 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 array 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 resource becomes idle and any
* user can put in a request and immediately receive access to the
* Resource.
*
* @author Kevin Klues (klues at tkn.tu-berlin.de)
*/
generic module ImmediateArbiterC() {
provides {
interface ImmediateResource[uint8_t id];
interface ArbiterInfo;
}
uses {
interface ResourceConfigure[uint8_t id];
}
}
implementation {
enum {RES_IDLE, RES_BUSY};
enum {NO_RES = 0xFF};
uint8_t state = RES_IDLE;
uint8_t resId = NO_RES;
/**
* Request immediate access to the shared resource. Requests are
* not queued. A return value
* of SUCCESS signifies that the resource has been granted to you,
* while a return value of EBUSY signifies that the resource is
* currently being used.
*/
async command error_t Resource.request[uint8_t id]() {
bool granted = FALSE;
atomic {
if(state == RES_IDLE) {
state = RES_BUSY;
resId = id;
granted = TRUE;
}
}
if(granted == TRUE) {
call ResourceConfigure.configure[id]();
return SUCCESS;
}
return EBUSY;
}
/**
Release the use of the shared resource
*/
async command void Resource.release[uint8_t id]() {
bool released = FALSE;
atomic {
if(state == RES_BUSY && resId == id) {
resId = NO_RES;
state = RES_IDLE;
released = TRUE;
}
}
if(released == TRUE)
call ResourceConfigure.unconfigure[id]();
}
/**
Check if the Resource is currently in use
*/
async command bool ArbiterInfo.inUse() {
atomic {
if (state == RES_IDLE)
return FALSE;
}
return TRUE;
}
/**
Returns the current user of the Resource.
If there is no current user, the return value
will be 0xFF
*/
async command uint8_t ArbiterInfo.userId() {
atomic return resId;
}
/**
* Returns my user id.
*/
async command uint8_t Resource.isOwner[uint8_t id]() {
atomic {
if(resId == id) return TRUE;
else return FALSE;
}
}
default command void ResourceConfigure.configure[uint8_t id]() {
}
default command void ResourceConfigure.unconfigure[uint8_t id]() {
}
}
--- NEW FILE: NoArbiterC.nc ---
/*
* Copyright (c) 2006 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/**
* A do-nothing arbiter for non-shared resources which need to pretend to
* have arbitration. Just grants all requests, without any error
* checking. Does still call ResourceConfigure at the right time.
*
* @author David Gay
*/
generic module NoArbiterC() {
provides interface Resource;
uses interface ResourceConfigure;
}
implementation {
task void granted() {
call ResourceConfigure.configure();
signal Resource.granted();
}
async command error_t Resource.request() {
post granted();
return SUCCESS;
}
async command error_t Resource.immediateRequest() {
call ResourceConfigure.configure();
return SUCCESS;
}
async command void Resource.release() {
call ResourceConfigure.unconfigure();
}
async command uint8_t Resource.isOwner() {
return TRUE;
}
default async command void ResourceConfigure.configure() { }
default async command void ResourceConfigure.unconfigure() { }
}
--- NEW FILE: PriorityArbiterP.nc ---
/*
* "Copyright (c) 2005 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/05/15 18:15:34 $
* ========================================================================
*/
/**
* Please refer to TEP 108 for more information about this component and its
* intended use.<br><br>
*
* This component provides the Resource, ArbiterInfo, and Resource
* Controller interfaces and uses the ResourceConfigure interface as
* described in TEP 108. An additional ResourceController interface is
* provided to allow clients of differing Priorities to control the
* Resource according to some policy implemented in an external
* component. This component provides arbitration to a shared resource in
* an FCFS fashion. An array 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 array is checked and the next user (in first-come
* first-served order) that has a pending request will ge granted control
* of the resource. If there are no pending requests, then the resource
* becomes idle and any user can put in a request and immediately receive
* access to the Resource.
*
* @param <b>resourceName</b> -- The name of the Resource being shared
*
* @author Kevin Klues (klues at tkn.tu-berlin.de)
* @author Philip Levis
* @author Philipp Huppertz
*/
generic module PriorityArbiterP(uint8_t highPriorityClientId, uint8_t lowPriorityClientId) {
provides {
interface Resource[uint8_t id];
interface ResourceController as HighPriorityClient;
interface ResourceController as LowPriorityClient;
interface ArbiterInfo;
}
uses {
interface ResourceConfigure[uint8_t id];
interface Queue;
}
}
implementation {
enum {RES_IDLE, RES_GRANTING, RES_BUSY};
enum {NO_RES = 0xFF};
enum {LOW_PRIORITY_CLIENT_ID = lowPriorityClientId};
enum {HIGH_PRIORITY_CLIENT_ID = highPriorityClientId};
uint8_t state = RES_IDLE;
uint8_t resId = NO_RES;
uint8_t reqResId = NO_RES;
bool hpreq = FALSE; // request from the high priority client
task void grantedTask();
task void lowRequestedTask();
task void highRequestedTask();
/**
Request the use of the shared resource
If the user has not already requested access to the
resource, the request will be either served immediately
or queued for later service.
A SUCCESS value will be returned and the user will receive
the granted() event in synchronous context once it has
been given access to the resource.
Whenever requests are queued, the highest priority client
will receive a requested() event after he receives granted(),
notifying him that another user would like to have access to the resource.
If the user has already requested access to the resource and
is waiting on a pending granted() event, an EBUSY value will
be returned to the caller.
*/
command error_t Resource.request[uint8_t id]() {
if(state == RES_IDLE ) {
state = RES_GRANTING;
atomic reqResId = id;
post grantedTask();
return SUCCESS;
}
if(resId == LOW_PRIORITY_CLIENT_ID)
post lowRequestedTask();
else if (resId == HIGH_PRIORITY_CLIENT_ID)
post highRequestedTask();
return call Queue.push(id);
}
command error_t LowPriorityClient.request() {
if((state == RES_IDLE) && (!hpreq)) {
state = RES_GRANTING;
reqResId = LOW_PRIORITY_CLIENT_ID;
post grantedTask();
return SUCCESS;
}
return EBUSY;
}
command error_t HighPriorityClient.request() {
if (resId == LOW_PRIORITY_CLIENT_ID)
signal LowPriorityClient.requested();
hpreq = TRUE;
if(state == RES_IDLE) {
state = RES_GRANTING;
reqResId = HIGH_PRIORITY_CLIENT_ID;
post grantedTask();
}
return SUCCESS;
}
async command error_t LowPriorityClient.immediateRequest() {
if((state == RES_IDLE) && (!hpreq)) {
state = RES_GRANTING;
resId = LOW_PRIORITY_CLIENT_ID;
return SUCCESS;
}
return EBUSY;
}
async command error_t HighPriorityClient.immediateRequest() {
if(state == RES_IDLE) {
state = RES_GRANTING;
resId = HIGH_PRIORITY_CLIENT_ID;
return SUCCESS;
}
return EBUSY;
}
/**
Release the use of the shared resource
The resource will only actually be released if
there are no pending requests for the resource.
If requests are pending, then the next pending request
will be serviced, according to a Fist come first serve
arbitration scheme. If no requests are currently
pending, then the resource is released, and any
users can put in a request for immediate access to
the resource.
*/
command void Resource.release[uint8_t id]() {
if (state == RES_BUSY && resId == id) {
reqResId = call Queue.pop();
if(reqResId != NO_RES) {
state = RES_GRANTING;
post grantedTask();
}
else {
atomic resId = NO_RES;
state = RES_IDLE;
signal HighPriorityClient.idle();
signal LowPriorityClient.idle();
}
call ResourceConfigure.unconfigure[id]();
}
}
command void LowPriorityClient.release() {
call Resource.release[LOW_PRIORITY_CLIENT_ID]();
}
command void HighPriorityClient.release() {
call Resource.release[HIGH_PRIORITY_CLIENT_ID]();
}
/**
Check if the Resource is currently in use
*/
async command bool ArbiterInfo.inUse() {
atomic {
if ( state == RES_IDLE )
return FALSE;
}
return TRUE;
}
/**
Returns the current user of the Resource.
If there is no current user, the return value
will be 0xFF
*/
async command uint8_t ArbiterInfo.userId() {
atomic return resId;
}
/**
* Returns my user id.
*/
async command uint8_t Resource.isOwner[uint8_t id]() {
atomic {
if(resId == id) return TRUE;
else return FALSE;
}
}
async command uint8_t LowPriorityClient.isOwner() {
return call Resource.isOwner[LOW_PRIORITY_CLIENT_ID]();
}
async command uint8_t HighPriorityClient.isOwner() {
return call Resource.isOwner[HIGH_PRIORITY_CLIENT_ID]();
}
//Task for pulling the Resource.granted() signal
//into synchronous context
task void grantedTask() {
atomic resId = reqResId;
state = RES_BUSY;
if(resId == HIGH_PRIORITY_CLIENT_ID) {
signal HighPriorityClient.granted();
// lets throw pending request at him...
if (call Queue.isEmpty() == FALSE) {
signal HighPriorityClient.requested();
}
}
else if(resId == LOW_PRIORITY_CLIENT_ID)
signal LowPriorityClient.granted();
else {
call ResourceConfigure.configure[resId]();
signal Resource.granted[resId]();
}
}
//Task for pulling the ResourceController.requested() signal
//into synchronous context
task void lowRequestedTask() {
signal LowPriorityClient.requested();
}
//Task for pulling the ResourceController.requested() signal
//into synchronous context
task void highRequestedTask() {
signal HighPriorityClient.requested();
}
//Default event/command handlers for all of the other
//potential users/providers of the parameterized interfaces
//that have not been connected to.
default event void Resource.granted[uint8_t id]() {
signal LowPriorityClient.granted();
}
default event void LowPriorityClient.granted() {
}
default event void LowPriorityClient.requested() {
}
default event void LowPriorityClient.idle() {
}
default event void HighPriorityClient.granted() {
}
default event void HighPriorityClient.requested() {
}
default event void HighPriorityClient.idle() {
}
default async command void ResourceConfigure.configure[uint8_t id]() {
}
default async command void ResourceConfigure.unconfigure[uint8_t id]() {
}
}
--- NEW FILE: RoundRobinArbiterC.nc ---
/*
* "Copyright (c) 2005 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/05/15 18:15:34 $
* ========================================================================
*/
/**
* Please refer to TEP 108 for more information about this component and its
* intended use.<br><br>
*
* This component provides the Resource, ArbiterInfo, and Resource
* Controller interfaces and uses the ResourceConfigure interface as
* described in TEP 108. It provides arbitration to a shared resource in a
* round robin fashion. An array 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 array is checked and the next user (in round
* robin order) that has a pending request will ge granted control of the
* resource. If there are no pending requests, then the resource becomes
* idle and any user can put in a request and immediately receive access to
* the round robin order * Resource.
*
* @param <b>resourceName</b> -- The name of the Resource being shared
*
* @author Kevin Klues (klues at tkn.tu-berlin.de)
* @author Philip Levis
*/
generic configuration RoundRobinArbiterC(char resourceName[]) {
provides {
interface Resource[uint8_t id];
interface ResourceController;
interface ArbiterInfo;
}
}
implementation {
components MainC;
components new RoundRobinQueueC(uniqueCount(resourceName)) as Queue;
components new ArbiterP(uniqueCount(resourceName)) as Arbiter;
MainC.SoftwareInit -> Queue;
Resource = Arbiter;
ResourceController = Arbiter;
ArbiterInfo = Arbiter;
Arbiter.Queue -> Queue;
}
--- NEW FILE: RoundRobinPriorityArbiterC.nc ---
/*
* "Copyright (c) 2005 Washington University in St. Louis.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
* OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
* UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS."
*/
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* - Revision -------------------------------------------------------------
* $Revision: 1.1.2.1 $
* $Date: 2006/05/15 18:15:34 $
* ========================================================================
*/
/**
* Please refer to TEP 108 for more information about this component and its
* intended use.<br><br>
*
* This component provides the Resource, ArbiterInfo, and Resource
* Controller interfaces and uses the ResourceConfigure interface as
* described in TEP 108. It provides arbitration to a shared resource in a
* round robin fashion. An array 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 array is checked and the next user (in round
* robin order) that has a pending request will ge granted control of the
* resource. If there are no pending requests, then the resource becomes
* idle and any user can put in a request and immediately receive access to
* the round robin order * Resource.
*
* @param <b>resourceName</b> -- The name of the Resource being shared
*
* @author Kevin Klues (klues at tkn.tu-berlin.de)
* @author Philip Levis
*/
generic configuration RoundRobinPriorityArbiterC(char resourceName[]) {
provides {
interface Resource[uint8_t id];
interface ResourceController as HighPriorityClient;
interface ResourceController as LowPriorityClient;
interface ArbiterInfo;
}
}
implementation {
components MainC;
components new RoundRobinQueueC(uniqueCount(resourceName)) as Queue;
components new PriorityArbiterP(uniqueCount(resourceName), uniqueCount(resourceName) + 1) as Arbiter;
MainC.SoftwareInit -> Queue;
Resource = Arbiter;
HighPriorityClient = Arbiter.HighPriorityClient;
LowPriorityClient = Arbiter.LowPriorityClient;
ArbiterInfo = Arbiter;
Arbiter.Queue -> Queue;
}
More information about the Tinyos-2-commits
mailing list