[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/scp-mac/tos/platform/micaz ClockSCP.nc, NONE, 1.1 ClockSCPM.nc, NONE, 1.1 HPLCC2420InterruptM.nc, NONE, 1.1 HPLUART0M.nc, NONE, 1.1 MakeXbowlocal, NONE, 1.1 PhyConst.h, NONE, 1.1 PhyRadio.nc, NONE, 1.1 PhyRadioM.nc, NONE, 1.1 PhyRadioMsg.h, NONE, 1.1

Wei Ye weiyeisi at users.sourceforge.net
Tue May 6 10:31:01 PDT 2008


Update of /cvsroot/tinyos/tinyos-1.x/contrib/scp-mac/tos/platform/micaz
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv9805/scp-mac/tos/platform/micaz

Added Files:
	ClockSCP.nc ClockSCPM.nc HPLCC2420InterruptM.nc HPLUART0M.nc 
	MakeXbowlocal PhyConst.h PhyRadio.nc PhyRadioM.nc 
	PhyRadioMsg.h 
Log Message:
scp-mac implementation from USC/ISI

--- NEW FILE: ClockSCP.nc ---
/*									tab:4
 * Copyright (c) 2002 the University of Southern 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 and the following
 * two paragraphs appear in all copies of this software.
 *
 * IN NO EVENT SHALL THE UNIVERSITY OF SOUTHERN 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 SOUTHERN CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * THE UNIVERSITY OF SOUTHERN 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 SOUTHERN CALIFORNIA HAS NO
 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
 * MODIFICATIONS.
 *
 * Authors:	Wei Ye
 * Date created: 1/21/2003
 *
 * This was originally used by S-MAC and was later changed for using SCP on micaz
 *
 */

interface ClockSCP
{
   // start the clock
   command void start();

   // stop the clock
   command void stop();
   
   // signal event when clock fires
   event void fire();
}

--- NEW FILE: ClockSCPM.nc ---
/*									tab:4
 * Copyright (c) 2002 the University of Southern 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 and the following
 * two paragraphs appear in all copies of this software.
 *
 * IN NO EVENT SHALL THE UNIVERSITY OF SOUTHERN 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 SOUTHERN CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * THE UNIVERSITY OF SOUTHERN 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 SOUTHERN CALIFORNIA HAS NO
 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
 * MODIFICATIONS.
 *
 * Authors:	Wei Ye
 * Date created: 3/21/2003
 *
 * This Clock is internally used by S-MAC. User can specify which hardware
 *   Timer/Counter it is based on by defining the macro SMAC_USE_COUNTER_x.
 *   By default Timer/Counter 0 is used.
 */

// The Mica-specific parts of the hardware presentation layer.

module ClockSCPM
{
  provides {
    interface ClockSCP as Clock;
  }
}

implementation
{
#define SCALE_1ms 1
#define INTERVAL_1ms 7650
#define INTERVAL_128us 1000

  command void Clock.start()
  {
    uint8_t intEnabled, scale = SCALE_1ms;
    uint16_t interval = INTERVAL_128us;
    scale |= 0x8;
    cbi(ETIMSK, OCIE3A);    // Disable output compareA match interrupt
    intEnabled = bit_is_set(SREG, 7);
    cli();      // disable interrupt before accessing 16-bit register
    __outw(0, TCNT3L);  // clear timer counter 1
    __outw(interval, OCR3AL);  // set compare match register
    if (intEnabled) sei();
    outp(scale, TCCR3B);    //prescale timer counter to be clock/8
    sbi(ETIMSK, OCIE3A); 
  }

  command void Clock.stop()
  {
    // stop the clock
    outp(0, TCCR3B);
  }
   
  TOSH_INTERRUPT(SIG_OUTPUT_COMPARE3A)
    {
      signal Clock.fire();
    }
}

--- NEW FILE: HPLCC2420InterruptM.nc ---
// $Id: HPLCC2420InterruptM.nc,v 1.1 2008/05/06 17:30:58 weiyeisi 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.
 */
/*
 *
 * Authors: Matt Miller
 * Date last modified:  $Revision: 1.1 $
 *
 */

/**
 * @author Matt Miller, Crossbow
 */

module HPLCC2420InterruptM {
  provides {
    interface HPLCC2420Interrupt as FIFOP;
    interface HPLCC2420Interrupt as FIFO;
    interface HPLCC2420Interrupt as CCA;
    interface HPLCC2420Capture as SFD;
  }
  uses {
    interface TimerCapture as SFDCapture;
    interface Timer as FIFOTimer;
    interface Timer as CCATimer;
//    interface UartDebug;
  }
}
implementation
{
    norace uint8_t FIFOWaitForState;
	norace uint8_t FIFOLastState;

    norace uint8_t CCAWaitForState;
	norace uint8_t CCALastState;
  // Add stdcontrol.init/.start to setup TimerCapture timebase

  // ************* FIFOP Interrupt handlers and dispatch *************
  
  /*********************************************************
  * 
  *  enable CC2420 fifop interrupt (on INT6 pin of ATMega128)
  CC2420 is configured for FIFOP interrupt on RXFIFO > Thresh
  where thresh is programmed in CC2420Const.h CP_IOCFGO reg. 
  Threshold is 127 asof 15apr04 (AlmostFull)
  FIFOP is asserted as long as RXFIFO>Threshold
  FIFOP is active LOW
  Type	ISCn1 ISCn0
  Hi-Lo	1	0
  Lo-Hi	1	1
  ********************************************************/
	async command result_t FIFOP.startWait(bool low_to_high) {
	    atomic {
	        CC2420_FIFOP_INT_MODE(low_to_high);
	        CC2420_FIFOP_INT_ENABLE();
	    }//atomic
	return SUCCESS;
	}

	/**
	* disables FIFOP interrupts
	*/
	async command result_t FIFOP.disable() {
		CC2420_FIFOP_INT_DISABLE();
	return SUCCESS;
	}

  /**
   * Event fired by lower level interrupt dispatch for FIFOP
   */
  TOSH_SIGNAL(TOSH_CC_FIFOP_INT) {
    result_t val = SUCCESS;
    val = signal FIFOP.fired();
    if (val == FAIL) {
        CC2420_FIFOP_INT_DISABLE();
        CC2420_FIFOP_INT_CLEAR();
    }
  } //FIFOP interrupt

  default async event result_t FIFOP.fired() { return FAIL; }
  
  // ************* FIFO Interrupt handlers and dispatch *************
  
  /**
   * enable an edge interrupt on the FIFO pin
    not INTERRUPT enabled on MICAz
    Best we can do is poll periodically and monitor line level changes
   */
  async command result_t FIFO.startWait(bool low_to_high) {

     atomic FIFOWaitForState = low_to_high; //save the state we are waiting for
	 FIFOLastState = TOSH_READ_CC_FIFO_PIN(); //get current state
     return call FIFOTimer.start(TIMER_ONE_SHOT,1); //wait 1msec
   } //.startWait

  /**
   * TImer Event fired so now check  FIFO pin level
   */
  event result_t FIFOTimer.fired() {
    uint8_t FIFOState;
    result_t val = SUCCESS;
    //check FIFO state
	 FIFOState = TOSH_READ_CC_FIFO_PIN(); //get current state
    if ((FIFOLastState != FIFOWaitForState) && (FIFOState==FIFOWaitForState)) {
		//here if found an edge
        val = signal FIFO.fired();
        if (val == FAIL) 
            return SUCCESS;  //all done
        }//if FIFO Pin
    //restart timer and try again
	FIFOLastState = FIFOState;
   return call FIFOTimer.start(TIMER_ONE_SHOT,1); //wait 1msec
  }//FIFOTimer.fired


  /**
   * disables FIFO interrupts
   */
  async command result_t FIFO.disable() {
    call FIFOTimer.stop();
    return SUCCESS;
  }

  default async event result_t FIFO.fired() { return FAIL; }

  // ************* CCA Interrupt handlers and dispatch *************
  
  /**
   * enable an edge interrupt on the CCA pin
   NOT an interrupt in MICAz. Implement as a timer polled pin monitor
   */
  async command result_t CCA.startWait(bool low_to_high) {
     atomic CCAWaitForState = low_to_high; //save the state we are waiting for
	 CCALastState = TOSH_READ_CC_CCA_PIN(); //get current state
     return call CCATimer.start(TIMER_ONE_SHOT,1); //wait 1msec
  }

  /**
   * disables CCA interrupts
   */
  async command result_t CCA.disable() {
    call CCATimer.stop();
    return SUCCESS;
  }

  /**
   * TImer Event fired so now check for CCA	level
   */
  event result_t CCATimer.fired() {
    uint8_t CCAState;
    result_t val = SUCCESS;
    //check CCA state
	 CCAState = TOSH_READ_CC_CCA_PIN(); //get current state
	//here if waiting for an edge
    if ((CCALastState != CCAWaitForState) && (CCAState==CCAWaitForState)) {
        val = signal CCA.fired();
        if (val == FAIL) 
            return SUCCESS;  //all done
        }//if CCA Pin is correct and edge found
    //restart timer and try again
	CCALastState = CCAState;
   return call CCATimer.start(TIMER_ONE_SHOT,1); //wait 1msec
  }//CCATimer.fired

  default async event result_t CCA.fired() { return FAIL; }

  // ************* SFD Interrupt handlers and dispatch *************
 /**
 SFD.enableCapture
 Configure Atmega128 TIMER1 to capture edge input of SFD signal.
 This will cause an interrupt and save TIMER1 count.
 Timer1 Timebase is set by stdControl.start - see SFDCapture Component Module
 *******************************************************************/
  async command result_t SFD.enableCapture(bool low_to_high) {
    atomic {
      //TOSH_SEL_CC_SFD_MODFUNC();
      call SFDCapture.disableEvents(); //this also clears any capture interrupt
      call SFDCapture.setEdge(low_to_high);
      //      call SFDCapture.clearOverflow();
      if (bit_is_set(TIFR, OCF0)){
//	call UartDebug.txByte(54);
      }
      call SFDCapture.enableEvents();
    }
    return SUCCESS;
  }

  async command result_t SFD.disable() {
    call SFDCapture.disableEvents();
   // TOSH_SEL_CC_SFD_IOFUNC();
    return SUCCESS;
  }
/** .captured
Handle signal from SFDCapture interface indicating an external event has
been timestamped. 
Signal client with time and disable capture timer if nolonger needed.
*****************************************************************************/
  async event void SFDCapture.captured(uint16_t time) {
    result_t val = SUCCESS;
//    call SFDCapture.clearPendingInterrupt(); //redundant?
    val = signal SFD.captured(time);     //signal client
    if (val == FAIL) {
      call SFDCapture.disableEvents();
     // call SFDCapture.clearPendingInterrupt();  //done in .disableEvents
    }
    else {  //time capture keeps running
      if (call SFDCapture.isOverflowPending()){
	if (bit_is_set(TIFR, OCF0)){
//	  call UartDebug.txByte(55);
	}
	//	call SFDCapture.clearOverflow();
      }
    }

  }//captured

  default async event result_t SFD.captured(uint16_t val) { return FAIL; }

} //Module HPLCC2420InterruptM
  

--- NEW FILE: HPLUART0M.nc ---
// $Id: HPLUART0M.nc,v 1.1 2008/05/06 17:30:58 weiyeisi 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.
 */
/*
 *
 * Authors:		Jason Hill, David Gay, Philip Levis, Phil Buonadonna, Joe Polastre
 * Date last modified:  $Revision: 1.1 $
 *
 */

// The hardware presentation layer. See hpl.h for the C side.
// Note: there's a separate C side (hpl.h) to get access to the avr macros

// The model is that HPL is stateless. If the desired interface is as stateless
// it can be implemented here (Clock, FlashBitSPI). Otherwise you should
// create a separate component


/**
 * @author Jason Hill
 * @author David Gay
 * @author Philip Levis
 * @author Phil Buonadonna
 * @author Joe Polastre
 */

module HPLUART0M {
  provides interface HPLUART as UART;

}
implementation
{
  async command result_t UART.init() {

    // UART will run at:
    // 115kbps, N-8-1

    // Set 57.6 KBps
    outp(0,UBRR0H); 
//    outp(15, UBRR0L);  // 57600 at 7.3728MHz
     outp(16, UBRR0L);  // 57600 at 8MHz
//    outp(8, UBRR0L);   // 115200 at 8MHz
//    outp(7, UBRR0L);   // 115200 at 7.3728MHz -- works

    // Set UART double speed
    outp((1<<U2X),UCSR0A);

    // Set frame format: 8 data-bits, 1 stop-bit
    outp(((1 << UCSZ1) | (1 << UCSZ0)) , UCSR0C);

    // Enable reciever and transmitter and their interrupts
    outp(((1 << RXCIE) | (1 << TXCIE) | (1 << RXEN) | (1 << TXEN)) ,UCSR0B);


    return SUCCESS;
  }

  async command result_t UART.stop() {
    outp(0x00, UCSR0A);
    outp(0x00, UCSR0B);
    outp(0x00, UCSR0C);
    return SUCCESS;
  }

  default async event result_t UART.get(uint8_t data) { return SUCCESS; }
  TOSH_SIGNAL(SIG_UART0_RECV) {
    if (inp(UCSR0A) & (1 << RXC))
      signal UART.get(inp(UDR0));
  }

  default async event result_t UART.putDone() { return SUCCESS; }

#ifdef ENABLE_UART_DEBUG
#warning "UART Interrups Redirected"
#else
  TOSH_INTERRUPT(SIG_UART0_TRANS) {
    signal UART.putDone();
  }
#endif

  command async result_t UART.put(uint8_t data) {
   atomic{
    outp(data, UDR0); 
    sbi(UCSR0A, TXC);
   }

    return SUCCESS;
  }
}

--- NEW FILE: MakeXbowlocal ---
##########################################################################
#
# MakeXbowlocal - Local Defines related to apps in contrib/xbow directory
#
##########################################################################

##########################################################################
# Settings for the the Mote Programmer,
#   If you are using MIB510 and it is connected to COM1 
#   of your PC use the following setting
#   For MIB600 use "eprb" setting and provide the hostname/IP address
##########################################################################
DEFAULT_PROGRAM=mib510
#DEFAULT_PROGRAM=eprb
MIB510=COM1
#EPRB=10.1.1.238

##########################################################################
# set Mote group id
# - default mote group  
##########################################################################
DEFAULT_LOCAL_GROUP=0xff

##########################################################################
# set radio channel (freq)
#   -Uncomment ONLY one line to choose the desired radio operating freq.
#   -Select band based on freq label tag on mote (916,433..)
#    (i.e. 433Mhz channel will not work for mote configured for 916Mhz)
##########################################################################
#
# 916 MHz Band
#
# CHANNEL_00 - 903 MHz     CHANNEL_02 - 904 MHz     CHANNEL_04 - 905 MHz
# CHANNEL_06 - 906 MHz     CHANNEL_08 - 907 MHz     CHANNEL_10 - 908 MHz
# CHANNEL_12 - 909 MHz     CHANNEL_14 - 910 MHz     CHANNEL_16 - 911 MHz
# CHANNEL_18 - 912 MHz     CHANNEL_20 - 913 MHz     CHANNEL_22 - 914 MHz
# CHANNEL_24 - 915 MHz     CHANNEL_26 - 916 MHz     CHANNEL_28 - 917 MHz
# CHANNEL_30 - 918 MHz     CHANNEL_32 - 919 MHz     CHANNEL_34 - 920 MHz
# CHANNEL_36 - 921 MHz     CHANNEL_38 - 922 MHz     CHANNEL_40 - 923 MHz
# CHANNEL_42 - 924 MHz     CHANNEL_44 - 925 MHz     CHANNEL_46 - 926 MHz
# CHANNEL_48 - 927 MHz
#CFLAGS = -DCC1K_DEFAULT_FREQ=CC1K_914_077_MHZ
#CFLAGS = -DCC1K_DEFAULT_FREQ=CC1K_915_998_MHZ
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_00
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_02
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_04
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_06
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_08
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_10
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_12
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_14
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_16
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_18
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_20
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_22
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_24
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_26
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_28
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_30
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_32
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_34
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_36
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_38
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_40
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_42
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_44
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_46
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_916BAND_CHANNEL_48
#--------------------------------------------------------------------------
# 433 MHz Band
#
# CHANNEL_00 - 433.113 MHz     CHANNEL_02 - 433.616 MHz
# CHANNEL_04 - 434.108 MHz     CHANNEL_06 - 434.618 MHz
#
#CFLAGS = -DCC1K_DEFAULT_FREQ=CC1K_433_002_MHZ
#CFLAGS = -DCC1K_DEFAULT_FREQ=CC1K_434_845_MHZ
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_433BAND_CHANNEL_00
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_433BAND_CHANNEL_02
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_433BAND_CHANNEL_04
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_433BAND_CHANNEL_06
##--------------------------------------------------------------------------
# 315 MHz Band
#
# CHANNEL_00 - 315 MHz
#
##--------------------------------------------------------------------------
#CFLAGS = -DCC1K_DEFAULT_FREQ=RADIO_315BAND_CHANNEL_00
##########################################################################


##########################################################################
# Set Radio Power 
#  - Radio transmit power is by a value (RTP) between 0x00 and 0xFF
#  - RTP = 0 for least power; =0xFF for max transmit power
#-------------------------------------------------------------------------
#  For Mica2 and Mica2Dot
#  Freq Band:  Output Power(dBm) RTP
#  916 Mhz     -20               0x02
#              -10               0x09
#               0 (1mw)          0x80
#               5                0xFF
#  433 Mhz     -20               0x01
#              -10               0x05
#               0 (1mw)          0x0F
#               10               0xFF
##########################################################################
CFLAGS += -DRADIO_XMIT_POWER=0xFF


##############################################
#
# MICAZ RF Power Levels
#TXPOWER_MAX      TXPOWER_0DBM
#TXPOWER_0DBM     0x1f   //0dBm
#TXPOWER_M3DBM    0x23   //-3dBm
#TXPOWER_M5DBM    0x19   //-5dBm
#TXPOWER_M10DBM   0x0B   //-10dBm
#TXPOWER_M15DBM   0x07   //-15dBm
#TXPOWER_M25DBM   0x03   //-25dBm
#TXPOWER_MIN      TXPOWER_M25DBM
##########################################


CFLAGS +=-DCC2420_TXPOWER=TXPOWER_MAX
#CFLAGS +=-DCC2420_TXPOWER=TXPOWER_M0DBM
#CFLAGS +=-DCC2420_TXPOWER=TXPOWER_M3DBM
#CFLAGS +=-DCC2420_TXPOWER=TXPOWER_M5DBM
#CFLAGS +=-DCC2420_TXPOWER=TXPOWER_M10DBM
#CFLAGS +=-DCC2420_TXPOWER=TXPOWER_M15DBM
#CFLAGS +=-DCC2420_TXPOWER=TXPOWER_M25DBM
#CFLAGS +=-DCC2420_TXPOWER=TXPOWER_MIN

#########################################################
#
# Zigbee Channel Selection
# CHANNEL_11 - 2405 MHz    CHANNEL_12 - 2410 MHz    CHANNEL_13 - 2415 MHz
# CHANNEL_14 - 2420 MHz    CHANNEL_15 - 2425 MHz    CHANNEL_16 - 2430 MHz
# CHANNEL_17 - 2435 MHz    CHANNEL_18 - 2440 MHz    CHANNEL_19 - 2445 MHz
# CHANNEL_20 - 2450 MHz    CHANNEL_21 - 2455 MHz    CHANNEL_22 - 2460 MHz
# CHANNEL_23 - 2465 MHz    CHANNEL_24 - 2470 MHz    CHANNEL_25 - 2475 MHz
# CHANNEL_26 - 2480 MHz
#
# 15, 20, 25 & 26 seem to be non-overlapping with 802.11
#########################################################
#CFLAGS +=-DCC2420_DEF_CHANNEL=11
#CFLAGS +=-DCC2420_DEF_CHANNEL=12
#CFLAGS +=-DCC2420_DEF_CHANNEL=13
#CFLAGS +=-DCC2420_DEF_CHANNEL=14
#CFLAGS +=-DCC2420_DEF_CHANNEL=15
#CFLAGS +=-DCC2420_DEF_CHANNEL=16
#CFLAGS +=-DCC2420_DEF_CHANNEL=17
#CFLAGS +=-DCC2420_DEF_CHANNEL=18
#CFLAGS +=-DCC2420_DEF_CHANNEL=19
#CFLAGS +=-DCC2420_DEF_CHANNEL=20
#CFLAGS +=-DCC2420_DEF_CHANNEL=21
#CFLAGS +=-DCC2420_DEF_CHANNEL=22
#CFLAGS +=-DCC2420_DEF_CHANNEL=23
#CFLAGS +=-DCC2420_DEF_CHANNEL=24
#CFLAGS +=-DCC2420_DEF_CHANNEL=25
CFLAGS +=-DCC2420_DEF_CHANNEL=26

##########################################################################


--- NEW FILE: PhyConst.h ---
/*
 * Copyright (C) 2003-2005 the University of Southern California.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * In addition to releasing this program under the LGPL, the authors are
 * willing to dual-license it under other terms. You may contact the authors
 * of this project by writing to Wei Ye, USC/ISI, 4676 Admirality Way, Suite 
 * 1001, Marina del Rey, CA 90292, USA.
 */
/*
 * Authors: Wei Ye
 *
 * Physical layer parameters
 */

#ifndef PHY_CONST
#define PHY_CONST

/***
 * These parameters are not user adjustable
 * but can be used by other components
 */

// the bandwidth on MicaZ radio is 250000b/s

// time to transmit a byte (binary microseconds) is equal to 2 symbols (each 16uS)
#define PHY_TX_BYTE_TIME 32

// carrier sense sample interval (binary microseconds)
#define PHY_CS_SAMPLE_INTERVAL 130 // We use a 1ms timer for sampling

// time to wait before sending a packet after a number of tones
#define PHY_WAIT_AFTER_TONE 500 // (us)

// maximum carrier sense extension (samples) when channel state can't be
// immediately determined by requested samples
//#define PHY_MAX_CS_EXT 4
#define PHY_MAX_CS_EXT 3

// transition delay from sleep to active (ms)
#define PHY_WAKEUP_DELAY 2

// number of sychronization bytes (start of a frame)
#define PHY_NUM_SYNC_BYTES 1

// base preamble length (bytes)
//#define BASE_PREAMBLE_LEN 18
#define PHY_BASE_PREAMBLE_LEN 4

// number of preamble bytes to be received for considering as valid preamble
//#define VALID_PRECURSOR 5
#define PHY_VALID_PRECURSOR 4

// number of bytes before each pkt with base preamble
#define PHY_BASE_PRE_BYTES (PHY_BASE_PREAMBLE_LEN + PHY_NUM_SYNC_BYTES)

// processing delay for each received packet (ms)
// mainly caused by noise level measurement
#define PHY_PROCESSING_DELAY 0.128

// Maximum receive time before aborting receiving a packet
#define PHY_MAX_RECEIVE_TIME 6 // (ms)

// Delay between timestamping outgoing packet and incoming packet
#define PHY_TIMESTAMP_DELAY 1 // in ms

// Time to load a packet into the CC2420 FIFO (before sending)
#define PHY_LOADTONE_DELAY 1 // in ms

// Number of tones to send before a packet (min 1)
#define PHY_NUMBER_OF_TONES 2

#endif

--- NEW FILE: PhyRadio.nc ---
/*
 * Copyright (C) 2003-2005 the University of Southern California.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * In addition to releasing this program under the LGPL, the authors are
 * willing to dual-license it under other terms. You may contact the authors
 * of this project by writing to Wei Ye, USC/ISI, 4676 Admirality Way, Suite 
 * 1001, Marina del Rey, CA 90292, USA.
 */
/*
 * Authors: Wei Ye
 * 
 * This is the physical layer that sends and receives a packet
 *   - accept any type and length (<= PHY_MAX_PKT_LEN in phy_radio_msg.h) of packet
 *   - sending a packet: encoding and byte spooling
 *   - receiving a packet: decoding, byte buffering
 *   - Optional CRC check
 *   - interface to radio control and physical carrier sense
 */

configuration PhyRadio
{
   provides {
      interface SplitControl;
      interface StdControl as PhyControl;
      interface RadioState;
      interface PhyPkt;
      interface PhyNotify;
      interface TxPreamble as PhyTxPreamble;
      interface CarrierSense;
      interface CsThreshold;
      interface GetSetU8 as RadioTxPower;
      interface PhyStreamByte;
      interface RadioEnergy;
   }
}

implementation
{
  components
    PhyRadioM,
    HPLCC2420C,
    CC2420ControlM,
    ClockSCPM,
    TimerC,
    LocalTimeC,
    HPLPowerManagementM,
#if defined PHY_UART_DEBUG_STATE_EVENT
    UartDebugStateEvent as UartDbg,
#elif defined PHY_UART_DEBUG_BYTE
    UartDebugByte as UartDbg,
#else
    UartDebugNone as UartDbg,
#endif
#ifdef PHY_LED_DEBUG  
    LedsC;
#else
    NoLeds as LedsC;
#endif
   
  // Implemented in this module

  SplitControl = PhyRadioM; 
  PhyControl = PhyRadioM;
  RadioState = PhyRadioM;
  PhyPkt = PhyRadioM;
  PhyNotify = PhyRadioM;
  PhyTxPreamble = PhyRadioM;
  PhyStreamByte = PhyRadioM;
  CarrierSense = PhyRadioM;
  CsThreshold = PhyRadioM;
  RadioTxPower = PhyRadioM;
  RadioEnergy = PhyRadioM;
  
  // wiring to lower layers
  
  PhyRadioM.LTimeControl -> LocalTimeC.TimeControl;
  PhyRadioM.LocalTime -> LocalTimeC;
  PhyRadioM.RxTimer -> TimerC.Timer[unique("Timer")];
  PhyRadioM.Leds -> LedsC;
  PhyRadioM.UartDebug -> UartDbg;

  PhyRadioM.CC2420SplitControl -> CC2420ControlM;
  PhyRadioM.CC2420Control -> CC2420ControlM;

  PhyRadioM.CSMAClock -> ClockSCPM.Clock;

  PhyRadioM.PowerEnable -> HPLPowerManagementM.Enable;
  PhyRadioM.PowerManagement -> HPLPowerManagementM;

  PhyRadioM.HPLChipcon -> HPLCC2420C.HPLCC2420;
  PhyRadioM.HPLChipconFIFO -> HPLCC2420C.HPLCC2420FIFO;
  PhyRadioM.FIFOP -> HPLCC2420C.InterruptFIFOP;
  PhyRadioM.SFD -> HPLCC2420C.CaptureSFD;

  CC2420ControlM.HPLChipconControl -> HPLCC2420C.StdControl;
  CC2420ControlM.HPLChipcon -> HPLCC2420C.HPLCC2420;
  CC2420ControlM.HPLChipconRAM -> HPLCC2420C.HPLCC2420RAM;
  CC2420ControlM.CCA -> HPLCC2420C.InterruptCCA;
}

--- NEW FILE: PhyRadioM.nc ---
/*
 * Copyright (C) 2003-2006 the University of Southern California.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * In addition to releasing this program under the LGPL, the authors are
[...1659 lines suppressed...]
   if (!measureEnergy) return;
   now = call LocalTime.get();
   timeElapsed = now - lastUpdateTime;
   if (lastRadioState == RADIO_SLEEP) {
     radioTime.sleepTime += timeElapsed;
   } else if (lastRadioState == RADIO_WAKEUP) {
     radioTime.wakeupTime += timeElapsed;
   } else if (lastRadioState == RADIO_IDLE) {
     radioTime.idleTime +=  timeElapsed;
   } else if (lastRadioState == RADIO_RX) {
     radioTime.rxTime +=  timeElapsed;
   } else if (lastRadioState == RADIO_TX) {
     radioTime.txTime +=  timeElapsed;
   }
   lastRadioState = radioState;
   lastUpdateTime = now;
#endif
 }  

}  // end of implementation

--- NEW FILE: PhyRadioMsg.h ---
/*
 * Copyright (C) 2003-2005 the University of Southern California.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * In addition to releasing this program under the LGPL, the authors are
 * willing to dual-license it under other terms. You may contact the authors
 * of this project by writing to Wei Ye, USC/ISI, 4676 Admirality Way, Suite 
 * 1001, Marina del Rey, CA 90292, USA.
 */
/*
 * Authors: Wei Ye
 *
 * This file defines the header fields of phy_radio that will be
 * added before the payload of each packet.
 * The upper layer (MAC) that use phy_radio should include this header
 * as its first field and CRC as its last field in each packet it 
 * declares (see smac_msg.h for example).
 */

#ifndef PHY_MSG
#define PHY_MSG

#ifndef PLATFORM_EMSTAR
#ifndef TOS_BCAST_DEFINED
#ifndef AM_H_INCLUDED
#define TOS_BCAST_ADDR 0xffff
#endif
#endif
#endif

// Maximum packet length -- including headers of all layers
// Each application can override the default max length in Makefile
// Maximum allowable value is 250
#ifndef PHY_MAX_PKT_LEN
#define PHY_MAX_PKT_LEN 120
#endif

// Physical-layer header to be put before data payload
// This is actually transmitted on the radio and used by
// the 802.15.4 phy
typedef struct {
  uint8_t length; // length of entire packet
  uint8_t fcfhi;
  uint8_t fcflo; // fcf is used by the CC2420 for specifying
  		 // ack requests, security, address modes, etc
  uint8_t dsn;   // sequence number for the 802.15.4 frame
  //  uint16_t destpan; // we use broadcast for passing the phy filters
  //  uint16_t addr; // destination address (broadcast)
} __attribute__((packed)) PhyHeader;


// packet information to be recorded by physical layer
typedef struct {
  uint32_t timestamp;   // time stamp based on LocalTime (1ms resolution)
  uint16_t strength;  // signal strength
  uint16_t noise;  // noise measurement immediately following pkt Rx
} __attribute__((packed)) PhyPktInfo;

// Physical layer packet buffer (for receiving packets)
// Sending buffer should be provided by the top-level application

#define PHY_MIN_PKT_LEN (sizeof(PhyHeader) + 2)
#define PHY_MAX_PAYLOAD (PHY_MAX_PKT_LEN - PHY_MIN_PKT_LEN)

typedef struct {
  PhyHeader hdr;
  char data[PHY_MAX_PAYLOAD];
  int16_t crc;      // last field of a packet
  PhyPktInfo info;  // not part of a packet
} __attribute__((packed)) PhyPktBuf;

#endif  // PHY_MSG



More information about the Tinyos-contrib-commits mailing list