new Alarm32khz16C() as Timer,
new TimerMilliC() as ReRxTimer,
DuplicateC,
+ TimeDiffC,
RandomLfsrC
#ifdef MAC_DEBUG
,PlatformLedsC
CsmaMacP.ReRxTimer -> ReRxTimer;
CsmaMacP.Duplicate -> DuplicateC;
+ CsmaMacP.TimeDiff16 -> TimeDiffC;
#ifdef MAC_DEBUG
CsmaMacP.Led0 -> PlatformLedsC.Led0;
interface Timer<TMilli> as ReRxTimer;
interface Duplicate;
+ interface TimeDiff16;
interface Alarm<T32khz, uint16_t> as Timer;
async command am_addr_t amAddress();
}
void interruptBackoffTimer() {
- uint16_t now;
if(call Timer.isRunning()) {
- restLaufzeit = call Timer.getAlarm();
+ restLaufzeit = call TimeDiff16.computeDelta(call Timer.getAlarm(), call Timer.getNow());
call Timer.stop();
- now = call Timer.getNow();
- if(restLaufzeit >= now) {
- restLaufzeit = restLaufzeit - now;
- }
- else {
- restLaufzeit = (uint16_t)(-1) - restLaufzeit + now;
- }
if(restLaufzeit > BACKOFF_MASK) {
restLaufzeit = call Random.rand16() & 0xFF;
}
RssiFixedThresholdCMC as Cca,
new Alarm32khz16C() as Timer,
new Alarm32khz16C() as SampleTimer,
- RandomLfsrC, LocalTimeC, DuplicateC;
+ RandomLfsrC, LocalTimeC, DuplicateC, TimeDiffC;
components ActiveMessageAddressC;
RedMacP.amAddress -> ActiveMessageAddressC;
RedMacP.LocalTime32kHz -> LocalTimeC;
RedMacP.Duplicate -> DuplicateC;
+ RedMacP.TimeDiff16 -> TimeDiffC;
+ RedMacP.TimeDiff32 -> TimeDiffC;
/* components PlatformLedsC;
RedMacP.Led0 -> PlatformLedsC.Led0;
interface LocalTime<T32khz> as LocalTime32kHz;
interface Duplicate;
+ interface TimeDiff16;
+ interface TimeDiff32;
async command am_addr_t amAddress();
/*
}
void interruptBackoffTimer() {
- uint16_t now;
if(call Timer.isRunning()) {
- restLaufzeit = call Timer.getAlarm();
- call Timer.stop();
- now = call Timer.getNow();
- if(restLaufzeit >= now) {
- restLaufzeit = restLaufzeit - now;
- }
- else {
- restLaufzeit = (uint16_t)(-1) - restLaufzeit + now;
- }
+ restLaufzeit = call TimeDiff16.computeDelta(call Timer.getAlarm(), call Timer.getNow());
+ call Timer.stop();
if(restLaufzeit > MIN_BACKOFF_MASK << MAX_LONG_RETRY) {
restLaufzeit = call Random.rand16() & ZERO_BACKOFF_MASK;
}
}
async event void RadioTimeStamping.transmittedSFD( uint16_t time, message_t* p_msg ) {
- uint32_t now;
- uint32_t mTime;
if((macState == TX) && (p_msg == txBufPtr)) {
- now = call LocalTime32kHz.get();
- mTime = getMetadata(p_msg)->time;
- if(now >= mTime) {
- txMacHdr->time = now - mTime;
- }
- else {
- // assume a clock wrap here
- txMacHdr->time = (uint32_t)(-1) - mTime + now;
- }
+ txMacHdr->time =
+ call TimeDiff32.computeDelta(call LocalTime32kHz.get(), getMetadata(p_msg)->time);
}
}
new Alarm32khz16C() as Timer,
new Alarm32khz16C() as SampleTimer,
RandomLfsrC,
- LocalTimeC, DuplicateC;
+ LocalTimeC,
+ DuplicateC,
+ TimeDiffC;
components ActiveMessageAddressC;
SpeckMacDP.amAddress -> ActiveMessageAddressC;
SpeckMacDP.LocalTime32kHz -> LocalTimeC;
SpeckMacDP.Duplicate -> DuplicateC;
+ SpeckMacDP.TimeDiff16 -> TimeDiffC;
+ SpeckMacDP.TimeDiff32 -> TimeDiffC;
/* components PlatformLedsC;
SpeckMacDP.Led0 -> PlatformLedsC.Led0;
interface LocalTime<T32khz> as LocalTime32kHz;
interface Duplicate;
+ interface TimeDiff16;
+ interface TimeDiff32;
async command am_addr_t amAddress();
/*
}
void interruptBackoffTimer() {
- uint16_t now;
if(call Timer.isRunning()) {
- restLaufzeit = call Timer.getAlarm();
- call Timer.stop();
- now = call Timer.getNow();
- if(restLaufzeit >= now) {
- restLaufzeit = restLaufzeit - now;
- }
- else {
- restLaufzeit = (uint16_t)(-1) - restLaufzeit + now;
- }
+ restLaufzeit = call TimeDiff16.computeDelta(call Timer.getAlarm(), call Timer.getNow());
+ call Timer.stop();
if(restLaufzeit > MIN_BACKOFF_MASK << MAX_LONG_RETRY) {
restLaufzeit = call Random.rand16() & ZERO_BACKOFF_MASK;
}
}
}
- async event void RadioTimeStamping.transmittedSFD( uint16_t time, message_t* p_msg ) {
- uint32_t now;
- uint32_t mTime;
+ async event void RadioTimeStamping.transmittedSFD(uint16_t time, message_t* p_msg ) {
if((macState == TX) && (p_msg == txBufPtr)) {
- now = call LocalTime32kHz.get();
- mTime = getMetadata(p_msg)->time;
- if(now >= mTime) {
- txMacHdr->time = now - mTime;
- }
- else {
- // assume a clock wrap here
- txMacHdr->time = (uint32_t)(-1) - mTime + now;
- }
+ txMacHdr->time =
+ call TimeDiff32.computeDelta(call LocalTime32kHz.get(), getMetadata(p_msg)->time);
}
}
--- /dev/null
+/* -*- mode:c++; indent-tabs-mode: nil -*-
+ * Copyright (c) 2007, 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.
+ */
+
+/**
+ * Manipulate time differences, with overflow checking
+ * @author: Andreas Koepke (koepke@tkn.tu-berlin.de
+ */
+
+interface TimeDiff {
+ /** compute delta of two times (now - past),
+ checks for overflow assuming that now is always > past */
+ async command uint32_t computeDelta(uint32_t time_now, uint32_t time_past);
+}
--- /dev/null
+/* -*- mode:c++; indent-tabs-mode: nil -*-
+ * Copyright (c) 2007, 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.
+ */
+
+/**
+ * Manipulate time differences, with overflow checking
+ * @author: Andreas Koepke (koepke@tkn.tu-berlin.de
+ */
+
+interface TimeDiff16 {
+ /** compute delta of two times (now - past),
+ checks for overflow assuming that now is always > past */
+ async command uint16_t computeDelta(uint16_t time_now, uint16_t time_past);
+}
--- /dev/null
+/* -*- mode:c++; indent-tabs-mode: nil -*-
+ * Copyright (c) 2007, 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.
+ */
+
+/**
+ * Manipulate time differences, with overflow checking
+ * @author: Andreas Koepke (koepke@tkn.tu-berlin.de
+ */
+
+interface TimeDiff32 {
+ /** compute delta of two times (now - past),
+ checks for overflow assuming that now is always > past */
+ async command uint32_t computeDelta(uint32_t time_now, uint32_t time_past);
+}
--- /dev/null
+/* -*- mode:c++; indent-tabs-mode: nil -*-
+ * Copyright (c) 2007, 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.
+ */
+
+/**
+ * Implementation of timediff interface
+ * @author: Andreas Koepke (koepke@tkn.tu-berlin.de)
+ */
+
+module TimeDiffC {
+ provides {
+ interface TimeDiff32;
+ interface TimeDiff16;
+ }
+}
+implementation {
+ async command uint32_t TimeDiff32.computeDelta(uint32_t time_now, uint32_t time_past) {
+ uint32_t rval;
+ if(time_now >= time_past) {
+ rval = time_now - time_past;
+ }
+ else {
+ rval = (uint32_t)(-1) - time_past + time_now;
+ }
+ return rval;
+ }
+
+ async command uint16_t TimeDiff16.computeDelta(uint16_t time_now, uint16_t time_past) {
+ uint16_t rval;
+ if(time_now >= time_past) {
+ rval = time_now - time_past;
+ }
+ else {
+ rval = (uint16_t)(-1) - time_past + time_now;
+ }
+ return rval;
+ }
+}
+