[Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/cc2420/unique
UniqueReceiveC.nc, NONE, 1.1 UniqueReceiveP.nc, NONE,
1.1 UniqueSendC.nc, NONE, 1.1 UniqueSendP.nc, NONE, 1.1
dmm
rincon at users.sourceforge.net
Tue Jul 3 17:37:18 PDT 2007
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/cc2420/transmit
CC2420TransmitC.nc, NONE, 1.1 CC2420TransmitP.nc, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/cc2420 CC2420.h, 1.6,
1.7 CC2420ActiveMessageC.nc, 1.7, 1.8 CC2420ActiveMessageP.nc,
1.7, 1.8 IEEE802154.h, 1.6, 1.7 README.txt, 1.3,
1.4 htmlreport_3-July-2007_05-05-PM.tar.gz, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-2.x/tos/chips/cc2420/unique
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv30635/unique
Added Files:
UniqueReceiveC.nc UniqueReceiveP.nc UniqueSendC.nc
UniqueSendP.nc
Log Message:
New CC2420 architecture in place for 2.0.2 release. See the README.txt file for changes. Test results from TUnit testing are included.
--- NEW FILE: UniqueReceiveC.nc ---
/*
* Copyright (c) 2005-2006 Rincon Research Corporation
* 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 Rincon Research Corporation 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
* RINCON RESEARCH OR ITS 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
*/
/**
* This layer keeps a history of the past RECEIVE_HISTORY_SIZE received messages
* If the source address and dsn number of a newly received message matches
* our recent history, we drop the message because we've already seen it.
* This should sit at the bottom of the stack
* @author David Moss
*/
configuration UniqueReceiveC {
provides {
interface Receive;
interface Receive as DuplicateReceive;
}
uses {
interface Receive as SubReceive;
}
}
implementation {
components UniqueReceiveP,
CC2420PacketC,
MainC;
Receive = UniqueReceiveP.Receive;
DuplicateReceive = UniqueReceiveP.DuplicateReceive;
SubReceive = UniqueReceiveP.SubReceive;
MainC.SoftwareInit -> UniqueReceiveP;
UniqueReceiveP.CC2420PacketBody -> CC2420PacketC;
}
--- NEW FILE: UniqueReceiveP.nc ---
/*
* Copyright (c) 2005-2006 Rincon Research Corporation
* 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 Rincon Research Corporation 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
* RINCON RESEARCH OR ITS 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
*/
/**
* This layer keeps a history of the past RECEIVE_HISTORY_SIZE received messages
* If the source address and dsn number of a newly received message matches
* our recent history, we drop the message because we've already seen it.
* @author David Moss
*/
#include "CC2420.h"
module UniqueReceiveP {
provides {
interface Receive;
interface Receive as DuplicateReceive;
interface Init;
}
uses {
interface Receive as SubReceive;
interface CC2420PacketBody;
}
}
implementation {
struct {
am_addr_t source;
uint8_t dsn;
} receivedMessages[RECEIVE_HISTORY_SIZE];
uint8_t writeIndex = 0;
/** History element containing info on a source previously received from */
uint8_t recycleSourceElement;
enum {
INVALID_ELEMENT = 0xFF,
};
/***************** Init Commands *****************/
command error_t Init.init() {
int i;
for(i = 0; i < RECEIVE_HISTORY_SIZE; i++) {
receivedMessages[i].source = (am_addr_t) 0xFFFF;
receivedMessages[i].dsn = 0;
}
return SUCCESS;
}
/***************** Prototypes Commands ***************/
bool hasSeen(uint16_t msgSource, uint8_t msgDsn);
void insert(uint16_t msgSource, uint8_t msgDsn);
/***************** Receive Commands ***************/
command void *Receive.getPayload(message_t* msg, uint8_t* len) {
return call SubReceive.getPayload(msg, len);
}
command uint8_t Receive.payloadLength(message_t* msg) {
return call SubReceive.payloadLength(msg);
}
/***************** DuplicateReceive Commands ****************/
command void *DuplicateReceive.getPayload(message_t* msg, uint8_t* len) {
return call SubReceive.getPayload(msg, len);
}
command uint8_t DuplicateReceive.payloadLength(message_t* msg) {
return call SubReceive.payloadLength(msg);
}
/***************** SubReceive Events *****************/
event message_t *SubReceive.receive(message_t* msg, void* payload,
uint8_t len) {
uint16_t msgSource = (call CC2420PacketBody.getHeader(msg))->src;
uint8_t msgDsn = (call CC2420PacketBody.getHeader(msg))->dsn;
if(hasSeen(msgSource, msgDsn)) {
return signal DuplicateReceive.receive(msg, payload, len);
} else {
insert(msgSource, msgDsn);
return signal Receive.receive(msg, payload, len);
}
}
/****************** Functions ****************/
/**
* This function does two things:
* 1. It loops through our entire receive history and detects if we've
* seen this DSN before from the given source (duplicate packet)
* 2. It detects if we've seen messages from this source before, so we know
* where to update our history if it turns out this is a new message.
*
* The global recycleSourceElement variable stores the location of the next insert
* if we've received a packet from that source before. Otherwise, it's up
* to the insert() function to decide who to kick out of our history.
*/
bool hasSeen(uint16_t msgSource, uint8_t msgDsn) {
int i;
recycleSourceElement = INVALID_ELEMENT;
atomic {
for(i = 0; i < RECEIVE_HISTORY_SIZE; i++) {
if(receivedMessages[i].source == msgSource) {
if(receivedMessages[i].dsn == msgDsn) {
// Only exit this loop if we found a duplicate packet
return TRUE;
}
recycleSourceElement = i;
}
}
}
return FALSE;
}
/**
* Insert the message into the history. If we received a message from this
* source before, insert it into the same location as last time and verify
* that the "writeIndex" is not pointing to that location. Otherwise,
* insert it into the "writeIndex" location.
*/
void insert(uint16_t msgSource, uint8_t msgDsn) {
uint8_t element = recycleSourceElement;
bool increment = FALSE;
atomic {
if(element == INVALID_ELEMENT || writeIndex == element) {
// Use the writeIndex element to insert this new message into
element = writeIndex;
increment = TRUE;
}
receivedMessages[element].source = msgSource;
receivedMessages[element].dsn = msgDsn;
if(increment) {
writeIndex++;
writeIndex %= RECEIVE_HISTORY_SIZE;
}
}
}
/***************** Defaults ****************/
default event message_t *DuplicateReceive.receive(message_t *msg, void *payload, uint8_t len) {
return msg;
}
}
--- NEW FILE: UniqueSendC.nc ---
/*
* Copyright (c) 2005-2006 Rincon Research Corporation
* 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 Rincon Research Corporation 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
* RINCON RESEARCH OR ITS 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
*/
/**
* Generate a unique dsn byte for this outgoing packet
* This should sit at the top of the stack
* @author David Moss
*/
configuration UniqueSendC {
provides {
interface Send;
}
uses {
interface Send as SubSend;
}
}
implementation {
components UniqueSendP,
new StateC(),
RandomC,
CC2420PacketC,
MainC;
Send = UniqueSendP.Send;
SubSend = UniqueSendP.SubSend;
MainC.SoftwareInit -> UniqueSendP;
UniqueSendP.State -> StateC;
UniqueSendP.Random -> RandomC;
UniqueSendP.CC2420PacketBody -> CC2420PacketC;
}
--- NEW FILE: UniqueSendP.nc ---
/*
* Copyright (c) 2005-2006 Rincon Research Corporation
* 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 Rincon Research Corporation 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
* RINCON RESEARCH OR ITS 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
*/
/**
* This layer is responsible for supplying a unique data sequence number (dsn)
* to each outgoing message.
* @author David Moss
*/
module UniqueSendP {
provides {
interface Send;
interface Init;
}
uses {
interface Send as SubSend;
interface State;
interface Random;
interface CC2420PacketBody;
}
}
implementation {
uint8_t localSendId;
enum {
S_IDLE,
S_SENDING,
};
/***************** Init Commands ****************/
command error_t Init.init() {
localSendId = call Random.rand16();
return SUCCESS;
}
/***************** Send Commands ****************/
/**
* Each call to this send command gives the message a single
* DSN that does not change for every copy of the message
* sent out. For messages that are not acknowledged, such as
* a broadcast address message, the receiving end does not
* signal receive() more than once for that message.
*/
command error_t Send.send(message_t *msg, uint8_t len) {
error_t error;
if(call State.requestState(S_SENDING) == SUCCESS) {
(call CC2420PacketBody.getHeader(msg))->dsn = localSendId++;
if((error = call SubSend.send(msg, len)) != SUCCESS) {
call State.toIdle();
}
return error;
}
return EBUSY;
}
command error_t Send.cancel(message_t *msg) {
return call SubSend.cancel(msg);
}
command uint8_t Send.maxPayloadLength() {
return call SubSend.maxPayloadLength();
}
command void *Send.getPayload(message_t* msg) {
return call SubSend.getPayload(msg);
}
/***************** SubSend Events ****************/
event void SubSend.sendDone(message_t *msg, error_t error) {
call State.toIdle();
signal Send.sendDone(msg, error);
}
}
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/cc2420/transmit
CC2420TransmitC.nc, NONE, 1.1 CC2420TransmitP.nc, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/cc2420 CC2420.h, 1.6,
1.7 CC2420ActiveMessageC.nc, 1.7, 1.8 CC2420ActiveMessageP.nc,
1.7, 1.8 IEEE802154.h, 1.6, 1.7 README.txt, 1.3,
1.4 htmlreport_3-July-2007_05-05-PM.tar.gz, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-2-commits
mailing list