From: andreaskoepke Date: Mon, 1 Oct 2007 17:58:07 +0000 (+0000) Subject: refactor MAC protocols: X-Git-Tag: release_tinyos_2_1_0_0~702 X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=commitdiff_plain;h=51db927a421fd91ba610a9fdc80790b4c7775e38;p=tinyos-2.x.git refactor MAC protocols: - separate time difference computation (need to pin point a bug) --- diff --git a/tos/chips/tda5250/mac/CsmaMacC.nc b/tos/chips/tda5250/mac/CsmaMacC.nc index 9966cf8b..6413c88d 100644 --- a/tos/chips/tda5250/mac/CsmaMacC.nc +++ b/tos/chips/tda5250/mac/CsmaMacC.nc @@ -60,6 +60,7 @@ implementation { new Alarm32khz16C() as Timer, new TimerMilliC() as ReRxTimer, DuplicateC, + TimeDiffC, RandomLfsrC #ifdef MAC_DEBUG ,PlatformLedsC @@ -99,6 +100,7 @@ implementation { CsmaMacP.ReRxTimer -> ReRxTimer; CsmaMacP.Duplicate -> DuplicateC; + CsmaMacP.TimeDiff16 -> TimeDiffC; #ifdef MAC_DEBUG CsmaMacP.Led0 -> PlatformLedsC.Led0; diff --git a/tos/chips/tda5250/mac/CsmaMacP.nc b/tos/chips/tda5250/mac/CsmaMacP.nc index 46c19d3f..ec790e74 100644 --- a/tos/chips/tda5250/mac/CsmaMacP.nc +++ b/tos/chips/tda5250/mac/CsmaMacP.nc @@ -72,6 +72,7 @@ module CsmaMacP { interface Timer as ReRxTimer; interface Duplicate; + interface TimeDiff16; interface Alarm as Timer; async command am_addr_t amAddress(); @@ -303,17 +304,9 @@ implementation } 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; } diff --git a/tos/chips/tda5250/mac/RedMacC.nc b/tos/chips/tda5250/mac/RedMacC.nc index 3421fe92..2da8ffa6 100644 --- a/tos/chips/tda5250/mac/RedMacC.nc +++ b/tos/chips/tda5250/mac/RedMacC.nc @@ -63,7 +63,7 @@ implementation { RssiFixedThresholdCMC as Cca, new Alarm32khz16C() as Timer, new Alarm32khz16C() as SampleTimer, - RandomLfsrC, LocalTimeC, DuplicateC; + RandomLfsrC, LocalTimeC, DuplicateC, TimeDiffC; components ActiveMessageAddressC; RedMacP.amAddress -> ActiveMessageAddressC; @@ -98,6 +98,8 @@ implementation { RedMacP.LocalTime32kHz -> LocalTimeC; RedMacP.Duplicate -> DuplicateC; + RedMacP.TimeDiff16 -> TimeDiffC; + RedMacP.TimeDiff32 -> TimeDiffC; /* components PlatformLedsC; RedMacP.Led0 -> PlatformLedsC.Led0; diff --git a/tos/chips/tda5250/mac/RedMacP.nc b/tos/chips/tda5250/mac/RedMacP.nc index 41739aa3..b6ecbc88 100644 --- a/tos/chips/tda5250/mac/RedMacP.nc +++ b/tos/chips/tda5250/mac/RedMacP.nc @@ -74,6 +74,8 @@ module RedMacP { interface LocalTime as LocalTime32kHz; interface Duplicate; + interface TimeDiff16; + interface TimeDiff32; async command am_addr_t amAddress(); /* @@ -485,17 +487,9 @@ implementation } 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; } @@ -1023,18 +1017,9 @@ implementation } 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); } } diff --git a/tos/chips/tda5250/mac/SpeckMacDC.nc b/tos/chips/tda5250/mac/SpeckMacDC.nc index 77b9bc83..b58dc71c 100644 --- a/tos/chips/tda5250/mac/SpeckMacDC.nc +++ b/tos/chips/tda5250/mac/SpeckMacDC.nc @@ -64,7 +64,9 @@ implementation { new Alarm32khz16C() as Timer, new Alarm32khz16C() as SampleTimer, RandomLfsrC, - LocalTimeC, DuplicateC; + LocalTimeC, + DuplicateC, + TimeDiffC; components ActiveMessageAddressC; SpeckMacDP.amAddress -> ActiveMessageAddressC; @@ -100,6 +102,8 @@ implementation { SpeckMacDP.LocalTime32kHz -> LocalTimeC; SpeckMacDP.Duplicate -> DuplicateC; + SpeckMacDP.TimeDiff16 -> TimeDiffC; + SpeckMacDP.TimeDiff32 -> TimeDiffC; /* components PlatformLedsC; SpeckMacDP.Led0 -> PlatformLedsC.Led0; diff --git a/tos/chips/tda5250/mac/SpeckMacDP.nc b/tos/chips/tda5250/mac/SpeckMacDP.nc index 271cdd51..5b2bf770 100644 --- a/tos/chips/tda5250/mac/SpeckMacDP.nc +++ b/tos/chips/tda5250/mac/SpeckMacDP.nc @@ -73,6 +73,8 @@ module SpeckMacDP { interface LocalTime as LocalTime32kHz; interface Duplicate; + interface TimeDiff16; + interface TimeDiff32; async command am_addr_t amAddress(); /* @@ -474,17 +476,9 @@ implementation } 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; } @@ -1006,19 +1000,10 @@ implementation } } - 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); } } diff --git a/tos/chips/tda5250/mac/TimeDiff.nc b/tos/chips/tda5250/mac/TimeDiff.nc new file mode 100644 index 00000000..7e7edbce --- /dev/null +++ b/tos/chips/tda5250/mac/TimeDiff.nc @@ -0,0 +1,39 @@ +/* -*- 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); +} diff --git a/tos/chips/tda5250/mac/TimeDiff16.nc b/tos/chips/tda5250/mac/TimeDiff16.nc new file mode 100644 index 00000000..44955b1b --- /dev/null +++ b/tos/chips/tda5250/mac/TimeDiff16.nc @@ -0,0 +1,39 @@ +/* -*- 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); +} diff --git a/tos/chips/tda5250/mac/TimeDiff32.nc b/tos/chips/tda5250/mac/TimeDiff32.nc new file mode 100644 index 00000000..8f4b0eaa --- /dev/null +++ b/tos/chips/tda5250/mac/TimeDiff32.nc @@ -0,0 +1,39 @@ +/* -*- 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); +} diff --git a/tos/chips/tda5250/mac/TimeDiffC.nc b/tos/chips/tda5250/mac/TimeDiffC.nc new file mode 100644 index 00000000..162084d7 --- /dev/null +++ b/tos/chips/tda5250/mac/TimeDiffC.nc @@ -0,0 +1,64 @@ +/* -*- 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; + } +} +