[Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/cc2420/csma
CC2420CsmaC.nc, NONE, 1.1 CC2420CsmaP.nc, NONE, 1.1
dmm
rincon at users.sourceforge.net
Tue Jul 3 17:37:16 PDT 2007
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/cc2420/control
CC2420ControlC.nc, NONE, 1.1 CC2420ControlP.nc, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/cc2420/interfaces
CC2420Config.nc, NONE, 1.1 CC2420Fifo.nc, NONE,
1.1 CC2420Packet.nc, NONE, 1.1 CC2420PacketBody.nc, NONE,
1.1 CC2420Power.nc, NONE, 1.1 CC2420Ram.nc, NONE,
1.1 CC2420Receive.nc, NONE, 1.1 CC2420Register.nc, NONE,
1.1 CC2420Strobe.nc, NONE, 1.1 CC2420Transmit.nc, NONE,
1.1 ChipSpiResource.nc, NONE, 1.1 PowerCycle.nc, NONE,
1.1 RadioBackoff.nc, NONE, 1.1 ReceiveIndicator.nc, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-2.x/tos/chips/cc2420/csma
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv30635/csma
Added Files:
CC2420CsmaC.nc CC2420CsmaP.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: CC2420CsmaC.nc ---
/*
* Copyright (c) 2005-2006 Arch Rock 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 Arch Rock 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
* ARCHED ROCK 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
*/
/**
* Basic implementation of a CSMA MAC for the ChipCon CC2420 radio.
*
* @author Jonathan Hui <jhui at archrock.com>
* @version $Revision: 1.1 $ $Date: 2007/07/04 00:37:14 $
*/
#include "CC2420.h"
#include "IEEE802154.h"
configuration CC2420CsmaC {
provides interface SplitControl;
provides interface Send;
provides interface Receive;
provides interface RadioBackoff[am_id_t amId];
}
implementation {
components CC2420CsmaP as CsmaP;
RadioBackoff = CsmaP;
SplitControl = CsmaP;
Send = CsmaP;
components CC2420ActiveMessageC;
CsmaP.AMPacket -> CC2420ActiveMessageC;
components CC2420ControlC;
CsmaP.Resource -> CC2420ControlC;
CsmaP.CC2420Power -> CC2420ControlC;
components CC2420TransmitC;
CsmaP.SubControl -> CC2420TransmitC;
CsmaP.CC2420Transmit -> CC2420TransmitC;
CsmaP.SubBackoff -> CC2420TransmitC;
components CC2420ReceiveC;
Receive = CC2420ReceiveC;
CsmaP.SubControl -> CC2420ReceiveC;
components CC2420PacketC;
CsmaP.CC2420Packet -> CC2420PacketC;
CsmaP.CC2420PacketBody -> CC2420PacketC;
components RandomC;
CsmaP.Random -> RandomC;
components new StateC();
CsmaP.SplitControlState -> StateC;
components LedsC as Leds;
CsmaP.Leds -> Leds;
}
--- NEW FILE: CC2420CsmaP.nc ---
/*
* Copyright (c) 2005-2006 Arch Rock 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 Arch Rock 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
* ARCHED ROCK 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
*/
/**
* @author Jonathan Hui <jhui at archrock.com>
* @version $Revision: 1.1 $ $Date: 2007/07/04 00:37:14 $
*/
module CC2420CsmaP {
provides interface SplitControl;
provides interface Send;
provides interface RadioBackoff[am_id_t amId];
uses interface Resource;
uses interface CC2420Power;
uses interface StdControl as SubControl;
uses interface CC2420Transmit;
uses interface RadioBackoff as SubBackoff;
uses interface Random;
uses interface AMPacket;
uses interface Leds;
uses interface CC2420Packet;
uses interface CC2420PacketBody;
uses interface State as SplitControlState;
}
implementation {
enum {
S_STOPPED,
S_STARTING,
S_STARTED,
S_STOPPING,
S_TRANSMITTING,
};
message_t* m_msg;
error_t sendErr = SUCCESS;
/** TRUE if we are to use CCA when sending the current packet */
norace bool ccaOn;
/****************** Prototypes ****************/
task void startDone_task();
task void startDone_task();
task void stopDone_task();
task void sendDone_task();
void shutdown();
/***************** SplitControl Commands ****************/
command error_t SplitControl.start() {
if(call SplitControlState.requestState(S_STARTING) == SUCCESS) {
call CC2420Power.startVReg();
return SUCCESS;
} else if(call SplitControlState.isState(S_STARTED)) {
return EALREADY;
} else if(call SplitControlState.isState(S_STARTING)) {
return SUCCESS;
}
return EBUSY;
}
command error_t SplitControl.stop() {
if (call SplitControlState.isState(S_STARTED)) {
call SplitControlState.forceState(S_STOPPING);
shutdown();
return SUCCESS;
} else if(call SplitControlState.isState(S_STOPPED)) {
return EALREADY;
} else if(call SplitControlState.isState(S_TRANSMITTING)) {
call SplitControlState.forceState(S_STOPPING);
// At sendDone, the radio will shut down
return SUCCESS;
} else if(call SplitControlState.isState(S_STOPPING)) {
return SUCCESS;
}
return EBUSY;
}
/***************** Send Commands ****************/
command error_t Send.cancel( message_t* p_msg ) {
return call CC2420Transmit.cancel();
}
command error_t Send.send( message_t* p_msg, uint8_t len ) {
cc2420_header_t* header = call CC2420PacketBody.getHeader( p_msg );
cc2420_metadata_t* metadata = call CC2420PacketBody.getMetadata( p_msg );
atomic {
if (!call SplitControlState.isState(S_STARTED)) {
return FAIL;
}
call SplitControlState.forceState(S_TRANSMITTING);
m_msg = p_msg;
}
header->length = len;
header->fcf &= 1 << IEEE154_FCF_ACK_REQ;
header->fcf |= ( ( IEEE154_TYPE_DATA << IEEE154_FCF_FRAME_TYPE ) |
( 1 << IEEE154_FCF_INTRAPAN ) |
( IEEE154_ADDR_SHORT << IEEE154_FCF_DEST_ADDR_MODE ) |
( IEEE154_ADDR_SHORT << IEEE154_FCF_SRC_ADDR_MODE ) );
header->src = call AMPacket.address();
metadata->ack = FALSE;
metadata->rssi = 0;
metadata->lqi = 0;
metadata->time = 0;
ccaOn = TRUE;
signal RadioBackoff.requestCca[((cc2420_header_t*)(m_msg->data -
sizeof(cc2420_header_t)))->type](m_msg);
call CC2420Transmit.send( m_msg, ccaOn );
return SUCCESS;
}
command void* Send.getPayload(message_t* m) {
return m->data;
}
command uint8_t Send.maxPayloadLength() {
return TOSH_DATA_LENGTH;
}
/**************** RadioBackoff Commands ****************/
/**
* Must be called within a requestInitialBackoff event
* @param backoffTime the amount of time in some unspecified units to backoff
*/
async command void RadioBackoff.setInitialBackoff[am_id_t amId](uint16_t backoffTime) {
call SubBackoff.setInitialBackoff(backoffTime);
}
/**
* Must be called within a requestCongestionBackoff event
* @param backoffTime the amount of time in some unspecified units to backoff
*/
async command void RadioBackoff.setCongestionBackoff[am_id_t amId](uint16_t backoffTime) {
call SubBackoff.setCongestionBackoff(backoffTime);
}
/**
* Enable CCA for the outbound packet. Must be called within a requestCca
* event
* @param ccaOn TRUE to enable CCA, which is the default.
*/
async command void RadioBackoff.setCca[am_id_t amId](bool useCca) {
ccaOn = useCca;
}
/**************** Events ****************/
async event void CC2420Transmit.sendDone( message_t* p_msg, error_t err ) {
atomic sendErr = err;
post sendDone_task();
}
async event void CC2420Power.startVRegDone() {
call Resource.request();
}
event void Resource.granted() {
call CC2420Power.startOscillator();
}
async event void CC2420Power.startOscillatorDone() {
post startDone_task();
}
/***************** SubBackoff Events ****************/
async event void SubBackoff.requestInitialBackoff(message_t *msg) {
call SubBackoff.setInitialBackoff ( call Random.rand16()
% (0x1F * CC2420_BACKOFF_PERIOD) + CC2420_MIN_BACKOFF);
signal RadioBackoff.requestInitialBackoff[((cc2420_header_t*)(msg->data -
sizeof(cc2420_header_t)))->type](msg);
}
async event void SubBackoff.requestCongestionBackoff(message_t *msg) {
call SubBackoff.setCongestionBackoff( call Random.rand16()
% (0x7 * CC2420_BACKOFF_PERIOD) + CC2420_MIN_BACKOFF);
signal RadioBackoff.requestCongestionBackoff[((cc2420_header_t*)(msg->data -
sizeof(cc2420_header_t)))->type](msg);
}
async event void SubBackoff.requestCca(message_t *msg) {
// Lower layers than this do not configure the CCA settings
}
/***************** Tasks ****************/
task void sendDone_task() {
error_t packetErr;
atomic packetErr = sendErr;
if(call SplitControlState.isState(S_STOPPING)) {
shutdown();
} else {
call SplitControlState.forceState(S_STARTED);
}
signal Send.sendDone( m_msg, packetErr );
}
task void startDone_task() {
call SubControl.start();
call CC2420Power.rxOn();
call Resource.release();
call SplitControlState.forceState(S_STARTED);
signal SplitControl.startDone( SUCCESS );
}
task void stopDone_task() {
call SplitControlState.forceState(S_STOPPED);
signal SplitControl.stopDone( SUCCESS );
}
/***************** Functions ****************/
/**
* Shut down all sub-components and turn off the radio
*/
void shutdown() {
call SubControl.stop();
call CC2420Power.stopVReg();
post stopDone_task();
}
/***************** Defaults ***************/
default event void SplitControl.startDone(error_t error) {
}
default event void SplitControl.stopDone(error_t error) {
}
default async event void RadioBackoff.requestInitialBackoff[am_id_t amId](
message_t *msg) {
}
default async event void RadioBackoff.requestCongestionBackoff[am_id_t amId](
message_t *msg) {
}
default async event void RadioBackoff.requestCca[am_id_t amId](
message_t *msg) {
}
}
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/cc2420/control
CC2420ControlC.nc, NONE, 1.1 CC2420ControlP.nc, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/cc2420/interfaces
CC2420Config.nc, NONE, 1.1 CC2420Fifo.nc, NONE,
1.1 CC2420Packet.nc, NONE, 1.1 CC2420PacketBody.nc, NONE,
1.1 CC2420Power.nc, NONE, 1.1 CC2420Ram.nc, NONE,
1.1 CC2420Receive.nc, NONE, 1.1 CC2420Register.nc, NONE,
1.1 CC2420Strobe.nc, NONE, 1.1 CC2420Transmit.nc, NONE,
1.1 ChipSpiResource.nc, NONE, 1.1 PowerCycle.nc, NONE,
1.1 RadioBackoff.nc, NONE, 1.1 ReceiveIndicator.nc, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-2-commits
mailing list