[Tinyos-2-commits] CVS: tinyos-2.x/tos/platforms/telosb/mac/tkn154 Ieee802154MacC.nc, NONE, 1.1 Makefile.include, NONE, 1.1 TKN154TimingP.nc, NONE, 1.1 TKN154_platform.h, NONE, 1.1 platform_message.h, NONE, 1.1

Jan-Hinrich Hauer janhauer at users.sourceforge.net
Mon Jun 16 11:05:17 PDT 2008


Update of /cvsroot/tinyos/tinyos-2.x/tos/platforms/telosb/mac/tkn154
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv438/tos/platforms/telosb/mac/tkn154

Added Files:
	Ieee802154MacC.nc Makefile.include TKN154TimingP.nc 
	TKN154_platform.h platform_message.h 
Log Message:
TKN15.4 "platform glue code" for the TelosB platform (see tinyos-2.x/tos/lib/mac/tkn154/README.txt)

--- NEW FILE: Ieee802154MacC.nc ---
/*
 * Copyright (c) 2008, Technische Universitaet 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 Universitaet 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 $
 * $Date: 2008/06/16 18:05:13 $
 * @author: Jan Hauer <hauer at tkn.tu-berlin.de>
 * ========================================================================
 */
#include "TKN154.h"
#include "TKN154_DEBUG.h"
configuration Ieee802154MacC
{
  provides
  {
    // MCPS-SAP
    interface MCPS_DATA;
    interface MCPS_PURGE;

    // MLME-SAP
    interface MLME_ASSOCIATE;
    interface MLME_BEACON_NOTIFY;
    interface MLME_COMM_STATUS;
    interface MLME_DISASSOCIATE;
    interface MLME_GET;
/*    interface MLME_GTS;*/
    interface MLME_ORPHAN;
    interface MLME_POLL;
    interface MLME_RESET;
    interface MLME_RX_ENABLE;
    interface MLME_SCAN;
    interface MLME_SET;
    interface MLME_START;
    interface MLME_SYNC;
    interface MLME_SYNC_LOSS;
    interface IEEE154Frame;
    interface IEEE154BeaconFrame;
    interface IEEE154TxBeaconPayload;
    interface SplitControl as PromiscuousMode;
    interface Get<uint64_t> as LocalExtendedAddress;
    interface Timestamp;
    interface Packet;
  }
}
implementation
{
  components TKN154P as MAC;

  MLME_START = MAC;
  MLME_GET = MAC;
  MLME_SET = MAC;
  MLME_RESET = MAC;
  MLME_SYNC = MAC;
  MLME_SYNC_LOSS = MAC;
  MLME_BEACON_NOTIFY = MAC;
  MLME_SCAN = MAC;
  MCPS_DATA = MAC;
  MCPS_PURGE = MAC;
  MLME_ASSOCIATE = MAC;
  MLME_DISASSOCIATE = MAC;
  MLME_COMM_STATUS = MAC;
  MLME_RX_ENABLE = MAC;
  MLME_POLL = MAC;
  MLME_ORPHAN = MAC;
  IEEE154Frame = MAC;
  IEEE154BeaconFrame = MAC;
  LocalExtendedAddress = MAC;
  IEEE154TxBeaconPayload = MAC;
  PromiscuousMode = MAC;
  Packet = MAC;

  components CC2420TKN154C as PHY,
             new Alarm62500hz32VirtualizedC() as PHYAlarm1,
             new Alarm62500hz32VirtualizedC() as PHYAlarm2,
             LocalTime62500hzC, TKN154TimingP;

  // wire PHY to the PIB
  PHY.PIBUpdate[IEEE154_macShortAddress] -> MAC.PIBUpdate[IEEE154_macShortAddress];
  PHY.PIBUpdate[IEEE154_macPANId] -> MAC.PIBUpdate[IEEE154_macPANId];
  PHY.PIBUpdate[IEEE154_phyCurrentChannel] -> MAC.PIBUpdate[IEEE154_phyCurrentChannel];
  PHY.PIBUpdate[IEEE154_phyTransmitPower] -> MAC.PIBUpdate[IEEE154_phyTransmitPower];
  PHY.PIBUpdate[IEEE154_phyCCAMode] -> MAC.PIBUpdate[IEEE154_phyCCAMode];
  PHY.PIBUpdate[IEEE154_macPanCoordinator] -> MAC.PIBUpdate[IEEE154_macPanCoordinator];

  Timestamp = PHY;
  PHY.Alarm1 -> PHYAlarm1;
  PHY.Alarm2 -> PHYAlarm2;
  PHY.LocalTime -> LocalTime62500hzC;
  PHY.CaptureTime -> TKN154TimingP;
  PHY.ReliableWait -> TKN154TimingP;
  PHY.ReferenceTime -> TKN154TimingP;
  PHY.TimeCalc -> MAC;
  PHY.Leds -> LedsC;
  TKN154TimingP.TimeCalc -> MAC;
  TKN154TimingP.LocalTime -> LocalTime62500hzC;

  components new Alarm62500hz32VirtualizedC() as  MACAlarm1,
             new Alarm62500hz32VirtualizedC() as  MACAlarm2,
             new Alarm62500hz32VirtualizedC() as  MACAlarm3,
             new Alarm62500hz32VirtualizedC() as  MACAlarm4,
             new Alarm62500hz32VirtualizedC() as  MACAlarm5,
             new Alarm62500hz32VirtualizedC() as  MACAlarm6,
             new Alarm62500hz32VirtualizedC() as  MACAlarm7,
             new Alarm62500hz32VirtualizedC() as  MACAlarm8,
             new Alarm62500hz32VirtualizedC() as  MACAlarm9,

             new Timer62500C() as  MACTimer1,
             new Timer62500C() as  MACTimer2,
             new Timer62500C() as  MACTimer3,
             new Timer62500C() as  MACTimer4,
             new Timer62500C() as  MACTimer5;

  MAC.Alarm1 ->  MACAlarm1;
  MAC.Alarm2 ->  MACAlarm2;
  MAC.Alarm3 ->  MACAlarm3;
  MAC.Alarm4 ->  MACAlarm4;
  MAC.Alarm5 ->  MACAlarm5;
  MAC.Alarm6 ->  MACAlarm6;
  MAC.Alarm7 ->  MACAlarm7;
  MAC.Alarm8 ->  MACAlarm8;
  MAC.Alarm9 ->  MACAlarm9;

  MAC.Timer1 -> MACTimer1;
  MAC.Timer2 -> MACTimer2;
  MAC.Timer3 -> MACTimer3;
  MAC.Timer4 -> MACTimer4;
  MAC.Timer5 -> MACTimer5;
  MAC.LocalTime -> LocalTime62500hzC;

  // wire MAC <-> PHY
  MAC.RadioTx -> PHY;
  MAC.RadioRx -> PHY;
  MAC.RadioOff -> PHY;
  MAC.EnergyDetection -> PHY;
  MAC.PhySplitControl -> PHY;
  MAC.RadioPromiscuousMode -> PHY.RadioPromiscuousMode;
  PHY.FrameUtility -> MAC;

  components RandomC, LedsC, NoLedsC;
  MAC.Random -> RandomC;
  MAC.Leds -> LedsC;

  components NoDebugP;
  MAC.Ieee802154Debug -> NoDebugP;
}

--- NEW FILE: Makefile.include ---
CFLAGS += -I$(TOSDIR)/platforms/telosb/mac/tkn154 \
	-I$(TOSDIR)/platforms/telosb/mac/tkn154/timer \
	-I$(TOSDIR)/chips/cc2420_tkn154


--- NEW FILE: TKN154TimingP.nc ---
/*
 * Copyright (c) 2008, Technische Universitaet Berlin
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * extraification, 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 Universitaet 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 $
 * $Date: 2008/06/16 18:05:14 $
 * @author: Jan Hauer <hauer at tkn.tu-berlin.de>
 * ========================================================================
 */

/** 
 * NOTE:
 * In slotted CSMA-CA frames must be sent on backoff boundaries (slot width:
 * 320 us). On TelosB the only clock source with sufficient accuracy is the
 * external quartz, unfortunately it is not precise enough (32.768 Hz).
 * Therefore, currently the following code is not even trying to achieve
 * accurate timing. 
 */

#include "TKN154_platform.h"
module TKN154TimingP
{
  provides interface CaptureTime;
  provides interface ReliableWait;
  provides interface ReferenceTime;
  uses interface TimeCalc;
  uses interface LocalTime<T62500hz>;
}
implementation
{

#define UWAIT1 nop();nop();nop();nop()
#define UWAIT2 UWAIT1;UWAIT1
#define UWAIT4 UWAIT2;UWAIT2
#define UWAIT8 UWAIT4;UWAIT4

  async command void CaptureTime.convert(uint16_t time, ieee154_reftime_t *localTime, int16_t offset)
  {
    // TimerB is used for capturing, it is sourced by ACLK (32768Hz),
    // we now need to convert the capture "time" into ieee154_reftime_t.
    // With the 32768Hz quartz we don't have enough precision anyway,
    // so the code below generates a timestamp that is not accurate
    // (deviating about +-50 microseconds; this could probably
    // improved if we don't go through LocalTime)
    uint16_t tbr1, tbr2, delta;
    uint32_t now;
    atomic {
      do {
        tbr1 = TBR;
        tbr2 = TBR;
      } while (tbr1 != tbr2); // majority vote required (see msp430 manual)
      now = call LocalTime.get(); 
    }
    if (time < tbr1)
      delta = tbr1 - time;
    else
      delta = ~(time - tbr1) + 1;
    *localTime = now - delta*2 + offset;
  }

  async command void ReliableWait.busyWait(uint16_t dt)
  {
    uint32_t start = call LocalTime.get();
    while (!call TimeCalc.hasExpired(start, dt))
      ;
  }

  async command void ReliableWait.waitCCA(ieee154_reftime_t *t0, uint16_t dt)
  {
    while (!call TimeCalc.hasExpired(*t0, dt))
      ;
    signal ReliableWait.waitCCADone();
  }

  async command void ReliableWait.waitTx(ieee154_reftime_t *t0, uint16_t dt)
  {
    while (!call TimeCalc.hasExpired(*t0, dt))
      ;
    signal ReliableWait.waitTxDone();
  }

  async command void ReliableWait.waitRx(ieee154_reftime_t *t0, uint16_t dt)
  {
    while (!call TimeCalc.hasExpired(*t0, dt))
      ;
    signal ReliableWait.waitRxDone();
  }
 
  async command void ReferenceTime.getNow(ieee154_reftime_t* reftime, uint16_t dt)
  {
    *reftime = call LocalTime.get();
  }

  async command uint32_t ReferenceTime.toLocalTime(ieee154_reftime_t* refTime)
  {
    return *refTime;
  } 

}

--- NEW FILE: TKN154_platform.h ---
/*
 * Copyright (c) 2008, Technische Universitaet 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 Universitaet 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 $
 * $Date: 2008/06/16 18:05:14 $
 * @author Jan Hauer <hauer at tkn.tu-berlin.de>
 * ========================================================================
 */

#ifndef __TKN154_platform_H
#define __TKN154_platform_H

/**************************************************** 
 * The following constants define guard times on Tmote Sky / TelosB. 
 * All values are in symbol time (1 symbol = 16 us)
 */

enum {
  // guard time to give up the token before actual end of CAP/CFP
  IEEE154_RADIO_GUARD_TIME = 1000,

  // the expected time for a RadioTx.prepare() operation to execute (return)
  IEEE154_RADIO_TX_PREPARE_DELAY = 220,

  // the *guaranteed maximum* time between calling a RadioTx.transmit() and the
  // first PPDU bit being put onto the channel, assuming that RadioTx.transmit() 
  // is called inside an atomic block
  IEEE154_RADIO_TX_SEND_DELAY = 100,

  // the expected time for a RadioRx.prepare() operation to execute (return)
  IEEE154_RADIO_RX_PREPARE_DELAY = 300,

  // the *guaranteed maximum* time between calling a RadioTx.transmit() and the
  // first PPDU bit being put onto the channel, assuming that RadioTx.transmit() 
  // is called inside an atomic block
  IEEE154_RADIO_RX_DELAY = 100,

  // defines at what time the MAC payload for a beacon frame is assembled prior
  // to the next scheduled beacon transmission time; must be smaller than both
  // the beacon interval and IEEE154_RADIO_TX_PREPARE_DELAY
  BEACON_PAYLOAD_UPDATE_INTERVAL = 2500, 
};

typedef uint32_t ieee154_reftime_t;

#endif


--- NEW FILE: platform_message.h ---



#ifndef PLATFORM_MESSAGE_H
#define PLATFORM_MESSAGE_H

#include <Serial.h>

#ifndef IEEE154_OLD_INTERFACES
#include <TKN154_MAC.h>
#else
typedef struct {
  uint8_t control;  // stores length (lower 7 bits), top bit -> promiscuous mode
  uint8_t mhr[23];
} ieee154_header_t;

typedef struct {
  uint8_t rssi;
  uint8_t linkQuality;
  uint32_t timestamp;
} ieee154_metadata_t;
#endif

#ifdef TOSH_DATA_LENGTH
#undef TOSH_DATA_LENGTH
#endif
// TOSH_DATA_LENGTH may be smaller than 118, but then we'll
// not be able to receive/send all IEEE 802.15.4 packets 
#define TOSH_DATA_LENGTH 118

typedef union message_header {
  ieee154_header_t ieee154;
  serial_header_t serial;
} message_header_t;

typedef union TOSRadioFooter {
} message_footer_t;

typedef union TOSRadioMetadata {
  ieee154_metadata_t ieee154;
} message_metadata_t;

#endif



More information about the Tinyos-2-commits mailing list