[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain/DrainBase DrainBase.nc, NONE, 1.1 DrainBaseM.nc, NONE, 1.1 Makefile, NONE, 1.1 README, NONE, 1.1

Gilman Tolle gtolle at users.sourceforge.net
Wed Aug 31 16:02:24 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainBase
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10685/DrainBase

Added Files:
	DrainBase.nc DrainBaseM.nc Makefile README 
Log Message:
Added a README describing the use of Drain, and a version of TOSBase with ACKs enabled called DrainBase.

--- NEW FILE: DrainBase.nc ---
// $Id: DrainBase.nc,v 1.1 2005/08/31 23:02:22 gtolle Exp $

/*									tab:4
 * "Copyright (c) 2000-2003 The Regents of the University  of California.  
 * 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 THE UNIVERSITY OF CALIFORNIA 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 THE UNIVERSITY OF
 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * THE UNIVERSITY OF CALIFORNIA 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 THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 *
 * Copyright (c) 2002-2003 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.
 */

/**
 * @author Phil Buonadonna
 * @author Gilman Tolle
 */

configuration DrainBase {
}
implementation {
  components Main, DrainBaseM, RadioCRCPacket as Comm, FramerM, UART, LedsC;

  components CC2420RadioC;

  Main.StdControl -> DrainBaseM;

  DrainBaseM.UARTControl -> FramerM;
  DrainBaseM.UARTSend -> FramerM;
  DrainBaseM.UARTReceive -> FramerM;
  DrainBaseM.UARTTokenReceive -> FramerM;

  DrainBaseM.RadioControl -> Comm;
  DrainBaseM.RadioSend -> Comm;
  DrainBaseM.RadioReceive -> Comm;

  DrainBaseM.Leds -> LedsC;

  DrainBaseM.MacControl -> CC2420RadioC;

  FramerM.ByteControl -> UART;
  FramerM.ByteComm -> UART;
}

--- NEW FILE: DrainBaseM.nc ---
// $Id: DrainBaseM.nc,v 1.1 2005/08/31 23:02:22 gtolle Exp $

/*									tab:4
 * "Copyright (c) 2000-2003 The Regents of the University  of California.  
 * 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 THE UNIVERSITY OF CALIFORNIA 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 THE UNIVERSITY OF
 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * THE UNIVERSITY OF CALIFORNIA 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 THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 *
 * Copyright (c) 2002-2003 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.
 */

/*
 * @author Phil Buonadonna
 * @author Gilman Tolle
 */
  
/* 
 * DrainBaseM bridges packets between a serial channel and the radio.
 * Messages moving from serial to radio will be tagged with the group
 * ID compiled into the DrainBase, and messages moving from radio to
 * serial will be filtered by that same group id.
 */

#ifndef TOSBASE_BLINK_ON_DROP
#define TOSBASE_BLINK_ON_DROP
#endif

module DrainBaseM {
  provides interface StdControl;
  uses {
    interface StdControl as UARTControl;
    interface BareSendMsg as UARTSend;
    interface ReceiveMsg as UARTReceive;
    interface TokenReceiveMsg as UARTTokenReceive;

    interface StdControl as RadioControl;
    interface BareSendMsg as RadioSend;
    interface ReceiveMsg as RadioReceive;

    interface Leds;

    interface MacControl;
  }
}

implementation
{
  enum {
    UART_QUEUE_LEN = 12,
    RADIO_QUEUE_LEN = 12,
  };

  TOS_Msg    uartQueueBufs[UART_QUEUE_LEN];
  uint8_t    uartIn, uartOut;
  bool       uartBusy, uartCount;

  TOS_Msg    radioQueueBufs[RADIO_QUEUE_LEN];
  uint8_t    radioIn, radioOut;
  bool       radioBusy, radioCount;

  task void UARTSendTask();
  task void RadioSendTask();

  void failBlink();
  void dropBlink();
  void processUartPacket(TOS_MsgPtr Msg, bool wantsAck, uint8_t Token);

  command result_t StdControl.init() {
    result_t ok1, ok2, ok3;

    uartIn = uartOut = uartCount = 0;
    uartBusy = FALSE;

    radioIn = radioOut = radioCount = 0;
    radioBusy = FALSE;

    ok1 = call UARTControl.init();
    ok2 = call RadioControl.init();
    ok3 = call Leds.init();

    dbg(DBG_BOOT, "DrainBase initialized\n");

    return rcombine3(ok1, ok2, ok3);
  }

  command result_t StdControl.start() {
    result_t ok1, ok2;

    ok1 = call UARTControl.start();
    ok2 = call RadioControl.start();

    call MacControl.enableAck();

    return rcombine(ok1, ok2);
  }

  command result_t StdControl.stop() {
    result_t ok1, ok2;
    
    ok1 = call UARTControl.stop();
    ok2 = call RadioControl.stop();

    return rcombine(ok1, ok2);
  }

  event TOS_MsgPtr RadioReceive.receive(TOS_MsgPtr Msg) {

    dbg(DBG_USR1, "DrainBase received radio packet.\n");

    if ((!Msg->crc) || (Msg->group != TOS_AM_GROUP))
      return Msg;

    if (uartCount < UART_QUEUE_LEN) {

      memcpy(&uartQueueBufs[uartIn], Msg, sizeof(TOS_Msg));
      uartCount++;

      if( ++uartIn >= UART_QUEUE_LEN ) uartIn = 0;

      if (!uartBusy) {
	if (post UARTSendTask()) {
	  uartBusy = TRUE;
	}
      }
    } else {
      dropBlink();
    }

    return Msg;
  }
  
  task void UARTSendTask() {
    dbg (DBG_USR1, "DrainBase forwarding Radio packet to UART\n");

    if (uartCount == 0) {

      uartBusy = FALSE;

    } else {

      if (call UARTSend.send(&uartQueueBufs[uartOut]) == SUCCESS) {
	call Leds.greenToggle();
      } else {
	failBlink();
	post UARTSendTask();
      }
    }
  }

  event result_t UARTSend.sendDone(TOS_MsgPtr msg, result_t success) {

    if (!success) {
      failBlink();
    } else {
      uartCount--;
      if( ++uartOut >= UART_QUEUE_LEN ) uartOut = 0;
    }
    
    post UARTSendTask();

    return SUCCESS;
  }

  event TOS_MsgPtr UARTReceive.receive(TOS_MsgPtr Msg) {
    processUartPacket(Msg, FALSE, 0);
    return Msg;
  }

  event TOS_MsgPtr UARTTokenReceive.receive(TOS_MsgPtr Msg, uint8_t Token) {
    processUartPacket(Msg, TRUE, Token);
    return Msg;
  }

  void processUartPacket(TOS_MsgPtr Msg, bool wantsAck, uint8_t Token) {
    bool reflectToken = FALSE;

    dbg(DBG_USR1, "DrainBase received UART token packet.\n");

    if (radioCount < RADIO_QUEUE_LEN) {
      reflectToken = TRUE;

      memcpy(&radioQueueBufs[radioIn], Msg, sizeof(TOS_Msg));

      radioCount++;
      
      if( ++radioIn >= RADIO_QUEUE_LEN ) radioIn = 0;
      
      if (!radioBusy) {
	if (post RadioSendTask()) {
	  radioBusy = TRUE;
	}
      }
    } else {
      dropBlink();
    }

    if (wantsAck && reflectToken) {
      call UARTTokenReceive.ReflectToken(Token);
    }
  }

  task void RadioSendTask() {

    dbg(DBG_USR1, "DrainBase forwarding UART packet to Radio\n");

    if (radioCount == 0) {

      radioBusy = FALSE;

    } else {

      radioQueueBufs[radioOut].group = TOS_AM_GROUP;
      
      if (call RadioSend.send(&radioQueueBufs[radioOut]) == SUCCESS) {
	call Leds.redToggle();
      } else {
	failBlink();
	post RadioSendTask();
      }
    }
  }

  event result_t RadioSend.sendDone(TOS_MsgPtr msg, result_t success) {

    if (!success) {
      failBlink();
    } else {
      radioCount--;
      if( ++radioOut >= RADIO_QUEUE_LEN ) radioOut = 0;
    }
    
    post RadioSendTask();
    return SUCCESS;
  }

  void dropBlink() {
#ifdef TOSBASE_BLINK_ON_DROP
    call Leds.yellowToggle();
#endif
  }

  void failBlink() {
#ifdef TOSBASE_BLINK_ON_FAIL
    call Leds.yellowToggle();
#endif
  }
}  

--- NEW FILE: Makefile ---
COMPONENT=DrainBase
CFLAGS += -DTOSH_MAX_TASKS_LOG2=8

include $(TOSDIR)/../apps/Makerules


--- NEW FILE: README ---
README for DrainBase

DrainBase is just a version of TOSBase that enables link-layer
ACKs. The Drain collection layer depends on an ACKing TOSBase for
reliable transfer of messages.

Note that on the CC2420, enabling ACKs also enables hardware address
rejection. DrainBase will only receive messages sent to TOS_BCAST_ADDR
and the address of the DrainBase node itself, which you assigned when
you ran "make telosb install,<addr>". It's no longer a packet
snooper. Be aware of this.

The Drain tools need access to the address assigned to the
DrainBase. In a perfect world, the tools would ask the DrainBase
directly. Right now, you have to export the MOTEID environment
variable, assigned to the address of the DrainBase. If you forget to
do this, or get the wrong address, you won't get any messages over
your Drain collection tree.

-----

README for TOSBase
Author/Contact: tinyos-help at millennium.berkeley.edu

Description:

TOSBase is an application that acts as a simple bridge between the
serial and radio links.

TOSBase will copy its compiled-in group ID to messages moving from the
serial link to the radio, and will filter out incoming radio messages
that do not contain that group ID.

TOSBase includes queues in both directions, with a guarantee that once
a message enters a queue, it will eventually leave on the other
interface. The queues allow the TOSBase to handle load spikes more
gracefully.

TOSBase acknowledges a message arriving over the serial link only if
that message was successfully enqueued for delivery to the radio link.

The LEDS are programmed to toggle as follows:

RED Toggle         - Message bridged from serial to radio
GREEN Toggle       - Message bridged from radio to serial
YELLOW/BLUE Toggle - Dropped message due to queue overflow 
                     in either direction

Tools:

tools/java/net/tinyos/sf/SerialForwarder.  

See doc/serialcomm/index.html for more information using these tools.

Known bugs/limitations:

As always, a task post failure somewhere in the serial or radio stacks
may cause the TOSBase to hang. The chance of this is lessened by
including the CFLAGS += -DTOSH_MAX_TASKS_LOG2=8 line in the TOSBase
Makefile, incleasing the size of the task queue to 256.



More information about the Tinyos-beta-commits mailing list