From f9cf38978d4a93126fc4dcb2d06de13c1ce66f42 Mon Sep 17 00:00:00 2001 From: janhauer Date: Mon, 16 Jun 2008 18:05:13 +0000 Subject: [PATCH] TKN15.4 "platform glue code" for the TelosB platform (see tinyos-2.x/tos/lib/mac/tkn154/README.txt) --- .../telosb/mac/tkn154/Ieee802154MacC.nc | 170 ++++++++++++++++++ .../telosb/mac/tkn154/Makefile.include | 4 + .../telosb/mac/tkn154/TKN154TimingP.nc | 124 +++++++++++++ .../telosb/mac/tkn154/TKN154_platform.h | 73 ++++++++ .../telosb/mac/tkn154/platform_message.h | 43 +++++ .../tkn154/timer/Alarm32khz32VirtualizedP.nc | 16 ++ .../timer/Alarm32khzTo62500hzTransformC.nc | 17 ++ .../timer/Alarm62500hz32VirtualizedC.nc | 49 +++++ .../timer/Alarm62500hz32VirtualizedHilC.nc | 48 +++++ .../timer/Alarm62500hz32VirtualizedHilP.nc | 16 ++ .../mac/tkn154/timer/HilTimer62500hzC.nc | 46 +++++ .../mac/tkn154/timer/LocalTime62500hzC.nc | 13 ++ .../mac/tkn154/timer/LocalTime62500hzP.nc | 15 ++ .../telosb/mac/tkn154/timer/Timer62500C.nc | 44 +++++ .../telosb/mac/tkn154/timer/Timer62500P.nc | 40 +++++ .../telosb/mac/tkn154/timer/Timer62500hz.h | 10 ++ 16 files changed, 728 insertions(+) create mode 100644 tos/platforms/telosb/mac/tkn154/Ieee802154MacC.nc create mode 100644 tos/platforms/telosb/mac/tkn154/Makefile.include create mode 100644 tos/platforms/telosb/mac/tkn154/TKN154TimingP.nc create mode 100644 tos/platforms/telosb/mac/tkn154/TKN154_platform.h create mode 100644 tos/platforms/telosb/mac/tkn154/platform_message.h create mode 100644 tos/platforms/telosb/mac/tkn154/timer/Alarm32khz32VirtualizedP.nc create mode 100644 tos/platforms/telosb/mac/tkn154/timer/Alarm32khzTo62500hzTransformC.nc create mode 100644 tos/platforms/telosb/mac/tkn154/timer/Alarm62500hz32VirtualizedC.nc create mode 100644 tos/platforms/telosb/mac/tkn154/timer/Alarm62500hz32VirtualizedHilC.nc create mode 100644 tos/platforms/telosb/mac/tkn154/timer/Alarm62500hz32VirtualizedHilP.nc create mode 100644 tos/platforms/telosb/mac/tkn154/timer/HilTimer62500hzC.nc create mode 100644 tos/platforms/telosb/mac/tkn154/timer/LocalTime62500hzC.nc create mode 100644 tos/platforms/telosb/mac/tkn154/timer/LocalTime62500hzP.nc create mode 100644 tos/platforms/telosb/mac/tkn154/timer/Timer62500C.nc create mode 100644 tos/platforms/telosb/mac/tkn154/timer/Timer62500P.nc create mode 100644 tos/platforms/telosb/mac/tkn154/timer/Timer62500hz.h diff --git a/tos/platforms/telosb/mac/tkn154/Ieee802154MacC.nc b/tos/platforms/telosb/mac/tkn154/Ieee802154MacC.nc new file mode 100644 index 00000000..3b7cf795 --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/Ieee802154MacC.nc @@ -0,0 +1,170 @@ +/* + * 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$ + * $Date$ + * @author: Jan Hauer + * ======================================================================== + */ +#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 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; +} diff --git a/tos/platforms/telosb/mac/tkn154/Makefile.include b/tos/platforms/telosb/mac/tkn154/Makefile.include new file mode 100644 index 00000000..2d728211 --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/Makefile.include @@ -0,0 +1,4 @@ +CFLAGS += -I$(TOSDIR)/platforms/telosb/mac/tkn154 \ + -I$(TOSDIR)/platforms/telosb/mac/tkn154/timer \ + -I$(TOSDIR)/chips/cc2420_tkn154 + diff --git a/tos/platforms/telosb/mac/tkn154/TKN154TimingP.nc b/tos/platforms/telosb/mac/tkn154/TKN154TimingP.nc new file mode 100644 index 00000000..d9713c20 --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/TKN154TimingP.nc @@ -0,0 +1,124 @@ +/* + * 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$ + * $Date$ + * @author: Jan Hauer + * ======================================================================== + */ + +/** + * 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; +} +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; + } + +} diff --git a/tos/platforms/telosb/mac/tkn154/TKN154_platform.h b/tos/platforms/telosb/mac/tkn154/TKN154_platform.h new file mode 100644 index 00000000..e129e255 --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/TKN154_platform.h @@ -0,0 +1,73 @@ +/* + * 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$ + * $Date$ + * @author Jan Hauer + * ======================================================================== + */ + +#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 + diff --git a/tos/platforms/telosb/mac/tkn154/platform_message.h b/tos/platforms/telosb/mac/tkn154/platform_message.h new file mode 100644 index 00000000..bbff8982 --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/platform_message.h @@ -0,0 +1,43 @@ + + + +#ifndef PLATFORM_MESSAGE_H +#define PLATFORM_MESSAGE_H + +#include + +#ifndef IEEE154_OLD_INTERFACES +#include +#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 diff --git a/tos/platforms/telosb/mac/tkn154/timer/Alarm32khz32VirtualizedP.nc b/tos/platforms/telosb/mac/tkn154/timer/Alarm32khz32VirtualizedP.nc new file mode 100644 index 00000000..f0a4f13b --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/timer/Alarm32khz32VirtualizedP.nc @@ -0,0 +1,16 @@ +#include "Timer62500hz.h" +configuration Alarm32khz32VirtualizedP +{ + provides interface Alarm as Alarm[ uint8_t num ]; +} +implementation +{ + components new Alarm32khz32C(), MainC; + components new VirtualizeAlarmC(T32khz, uint32_t, uniqueCount(UQ_ALARM_32KHZ32)); + + Alarm = VirtualizeAlarmC; + + MainC -> Alarm32khz32C.Init; + MainC -> VirtualizeAlarmC.Init; + VirtualizeAlarmC.AlarmFrom -> Alarm32khz32C; +} diff --git a/tos/platforms/telosb/mac/tkn154/timer/Alarm32khzTo62500hzTransformC.nc b/tos/platforms/telosb/mac/tkn154/timer/Alarm32khzTo62500hzTransformC.nc new file mode 100644 index 00000000..c51d1122 --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/timer/Alarm32khzTo62500hzTransformC.nc @@ -0,0 +1,17 @@ +// here we introduce an error +generic module Alarm32khzTo62500hzTransformC() +{ + provides interface Alarm as Alarm; + uses interface Alarm as AlarmFrom; +} +implementation +{ + async command void Alarm.start(uint32_t dt){ call AlarmFrom.start(dt >> 1);} + async command void Alarm.stop(){ call AlarmFrom.stop();} + async event void AlarmFrom.fired(){ signal Alarm.fired();} + async command bool Alarm.isRunning(){ return call AlarmFrom.isRunning();} + async command void Alarm.startAt(uint32_t t0, uint32_t dt){ call AlarmFrom.startAt(t0 >> 1, dt >> 1);} + async command uint32_t Alarm.getNow(){ return call AlarmFrom.getNow() << 1;} + async command uint32_t Alarm.getAlarm(){ return call AlarmFrom.getAlarm() << 1;} + default async event void Alarm.fired(){} +} diff --git a/tos/platforms/telosb/mac/tkn154/timer/Alarm62500hz32VirtualizedC.nc b/tos/platforms/telosb/mac/tkn154/timer/Alarm62500hz32VirtualizedC.nc new file mode 100644 index 00000000..7b946a76 --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/timer/Alarm62500hz32VirtualizedC.nc @@ -0,0 +1,49 @@ + +/* "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." + */ + +/** + * Alarm62500hzC is the alarm for async 62500hz alarms (virtualized) + * This is the place where we cheat: since we don't have a clock source + * running at 62500 Hz, we cast 2 symbols to 1 tick of the 32768 + * clock, which introduces a small error. + * + * @author Cory Sharp + * @author Jan Hauer + * @see Please refer to TEP 102 for more information about this component and its + * intended use. + */ + +//#include "Timer.h" +#include "Timer62500hz.h" +generic configuration Alarm62500hz32VirtualizedC() +{ + provides interface Alarm; +} +implementation +{ +#warning "Warning: MAC timing is not standard compliant (the symbol clock is based on the 32768 Hz oscillator)!" + components new Alarm32khzTo62500hzTransformC(); + components Alarm32khz32VirtualizedP; + + Alarm = Alarm32khzTo62500hzTransformC; + Alarm32khzTo62500hzTransformC.AlarmFrom -> Alarm32khz32VirtualizedP.Alarm[unique(UQ_ALARM_32KHZ32)]; +} + diff --git a/tos/platforms/telosb/mac/tkn154/timer/Alarm62500hz32VirtualizedHilC.nc b/tos/platforms/telosb/mac/tkn154/timer/Alarm62500hz32VirtualizedHilC.nc new file mode 100644 index 00000000..4455db52 --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/timer/Alarm62500hz32VirtualizedHilC.nc @@ -0,0 +1,48 @@ + +/* "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." + */ + +/** + * Alarm62500hzC is the alarm for async 62500hz alarms (virtualized) + * This is the place where we cheat: since we don't have a clock source + * running at 62500 Hz, we cast 2 symbols to 1 tick of the 32768 + * clock, which introduces a small error. + * + * @author Cory Sharp + * @author: Jan Hauer + * @see Please refer to TEP 102 for more information about this component and its + * intended use. + */ + +//#include "Timer.h" +#include "Timer62500hz.h" +generic configuration Alarm62500hz32VirtualizedHilC() +{ + provides interface Alarm; +} +implementation +{ + components new Alarm32khzTo62500hzTransformC(); + components Alarm62500hz32VirtualizedHilP; + + Alarm = Alarm32khzTo62500hzTransformC; + Alarm32khzTo62500hzTransformC.AlarmFrom -> Alarm62500hz32VirtualizedHilP.Alarm[unique(UQ_ALARM_32KHZ32)]; +} + diff --git a/tos/platforms/telosb/mac/tkn154/timer/Alarm62500hz32VirtualizedHilP.nc b/tos/platforms/telosb/mac/tkn154/timer/Alarm62500hz32VirtualizedHilP.nc new file mode 100644 index 00000000..c38f72a6 --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/timer/Alarm62500hz32VirtualizedHilP.nc @@ -0,0 +1,16 @@ +#include "Timer62500hz.h" +configuration Alarm62500hz32VirtualizedHilP +{ + provides interface Alarm as Alarm[ uint8_t num ]; +} +implementation +{ + components new Alarm32khz32C(), MainC; + components new VirtualizeAlarmC(T32khz, uint32_t, uniqueCount(UQ_ALARM_32KHZ32)); + + Alarm = VirtualizeAlarmC; + + MainC -> Alarm32khz32C.Init; + MainC -> VirtualizeAlarmC.Init; + VirtualizeAlarmC.AlarmFrom -> Alarm32khz32C; +} diff --git a/tos/platforms/telosb/mac/tkn154/timer/HilTimer62500hzC.nc b/tos/platforms/telosb/mac/tkn154/timer/HilTimer62500hzC.nc new file mode 100644 index 00000000..fe398425 --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/timer/HilTimer62500hzC.nc @@ -0,0 +1,46 @@ + +/* "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." + */ + +/** + * + * @author Cory Sharp + * @author: Jan Hauer (62500hz) + * @see Please refer to TEP 102 for more information about this component and its + * intended use. + */ + +#include "Timer.h" +#include "Timer62500hz.h" +configuration HilTimer62500hzC +{ + provides interface Timer as Timer62500hz[ uint8_t num ]; +} +implementation +{ + components new Alarm62500hz32VirtualizedHilC() as Alarm; + components new AlarmToTimerC(T62500hz); + components new VirtualizeTimerC(T62500hz,uniqueCount(UQ_TIMER_62500HZ)); + + Timer62500hz = VirtualizeTimerC; + + VirtualizeTimerC.TimerFrom -> AlarmToTimerC; + AlarmToTimerC.Alarm -> Alarm; +} diff --git a/tos/platforms/telosb/mac/tkn154/timer/LocalTime62500hzC.nc b/tos/platforms/telosb/mac/tkn154/timer/LocalTime62500hzC.nc new file mode 100644 index 00000000..07240b1b --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/timer/LocalTime62500hzC.nc @@ -0,0 +1,13 @@ +#include "Timer62500hz.h" +configuration LocalTime62500hzC +{ + provides interface LocalTime; +} +implementation +{ + // should be done properly one day (not wasting an alarm slot) + components new Alarm62500hz32VirtualizedC(), LocalTime62500hzP; + LocalTime = LocalTime62500hzP; + LocalTime62500hzP.Alarm -> Alarm62500hz32VirtualizedC.Alarm; +} + diff --git a/tos/platforms/telosb/mac/tkn154/timer/LocalTime62500hzP.nc b/tos/platforms/telosb/mac/tkn154/timer/LocalTime62500hzP.nc new file mode 100644 index 00000000..30911ac6 --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/timer/LocalTime62500hzP.nc @@ -0,0 +1,15 @@ +#include "Timer62500hz.h" +module LocalTime62500hzP +{ + provides interface LocalTime; + uses interface Alarm; +} +implementation +{ + async command uint32_t LocalTime.get() + { + return call Alarm.getNow(); + } + async event void Alarm.fired(){} +} + diff --git a/tos/platforms/telosb/mac/tkn154/timer/Timer62500C.nc b/tos/platforms/telosb/mac/tkn154/timer/Timer62500C.nc new file mode 100644 index 00000000..a825dfbc --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/timer/Timer62500C.nc @@ -0,0 +1,44 @@ +// $Id$ +/* + * "Copyright (c) 2005 Stanford University. 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 STANFORD UNIVERSITY 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 STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * STANFORD UNIVERSITY 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 STANFORD UNIVERSITY + * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, + * ENHANCEMENTS, OR MODIFICATIONS." + */ + +/** + * The virtualized 62500 Hz timer abstraction. Instantiating this + * component gives an 62500 Hz granularity timer. + * + * @author Philip Levis + * @author: Jan Hauer (62500hz) + * @date January 16 2006 + * @see TEP 102: Timers + */ + +#include "Timer62500hz.h" + +generic configuration Timer62500C() { + provides interface Timer; +} +implementation { + components Timer62500P; + Timer = Timer62500P.Timer62500[unique(UQ_TIMER_62500HZ)]; +} + diff --git a/tos/platforms/telosb/mac/tkn154/timer/Timer62500P.nc b/tos/platforms/telosb/mac/tkn154/timer/Timer62500P.nc new file mode 100644 index 00000000..96d22621 --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/timer/Timer62500P.nc @@ -0,0 +1,40 @@ +// $Id$ +/* tab:4 + * "Copyright (c) 2005 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." + * + */ +/* + * + * @author Philip Levis + * @author Cory Sharp + * @author: Jan Hauer (62500hz) + * @date May 16 2005 + */ + +#include "Timer.h" + +configuration Timer62500P { + provides interface Timer as Timer62500[uint8_t id]; +} +implementation { + components HilTimer62500hzC; + Timer62500 = HilTimer62500hzC; +} + diff --git a/tos/platforms/telosb/mac/tkn154/timer/Timer62500hz.h b/tos/platforms/telosb/mac/tkn154/timer/Timer62500hz.h new file mode 100644 index 00000000..bd781d68 --- /dev/null +++ b/tos/platforms/telosb/mac/tkn154/timer/Timer62500hz.h @@ -0,0 +1,10 @@ +#ifndef _H_Timer_62500hz_h +#define _H_Timer_62500hz_h + +typedef struct { } T62500hz; + +#define UQ_ALARM_32KHZ32 "Virtual.32khz32Alarm" +#define UQ_ALARM_62500HZ32 "Virtual.62500hzAlarm" +#define UQ_TIMER_62500HZ "HilTimer62500hzC.Timer" +#endif + -- 2.39.2