From 0650ae4864d810f331fc6dfa8ba78fc4b61d771d Mon Sep 17 00:00:00 2001 From: scipio Date: Tue, 10 Apr 2007 01:23:13 +0000 Subject: [PATCH] Fixed simulated timers to follow new atm128 timer stack. --- apps/tests/TestSimTimers/Makefile | 4 + apps/tests/TestSimTimers/README | 12 ++ apps/tests/TestSimTimers/TestTimerAppC.nc | 66 +++++++++++ apps/tests/TestSimTimers/TestTimerC.nc | 133 ++++++++++++++++++++++ apps/tests/TestSimTimers/script.py | 20 ++++ 5 files changed, 235 insertions(+) create mode 100644 apps/tests/TestSimTimers/Makefile create mode 100644 apps/tests/TestSimTimers/README create mode 100644 apps/tests/TestSimTimers/TestTimerAppC.nc create mode 100644 apps/tests/TestSimTimers/TestTimerC.nc create mode 100644 apps/tests/TestSimTimers/script.py diff --git a/apps/tests/TestSimTimers/Makefile b/apps/tests/TestSimTimers/Makefile new file mode 100644 index 00000000..84b6100e --- /dev/null +++ b/apps/tests/TestSimTimers/Makefile @@ -0,0 +1,4 @@ +COMPONENT=TestTimerAppC + +include $(MAKERULES) + diff --git a/apps/tests/TestSimTimers/README b/apps/tests/TestSimTimers/README new file mode 100644 index 00000000..29f24b98 --- /dev/null +++ b/apps/tests/TestSimTimers/README @@ -0,0 +1,12 @@ +TestTimer, 4/9/07 + +This application tests TinyOS millisecond timers +(TimerMilliC). It is intended for use with TOSSIM, +to test whether the timer implementation is working +correctly: its output consists of TOSSIM dbg() +statements. + +The relevant output channel is "TestTimer". + +Philip Levis + diff --git a/apps/tests/TestSimTimers/TestTimerAppC.nc b/apps/tests/TestSimTimers/TestTimerAppC.nc new file mode 100644 index 00000000..95f5fd46 --- /dev/null +++ b/apps/tests/TestSimTimers/TestTimerAppC.nc @@ -0,0 +1,66 @@ +// $Id$ + +/* tab:4 + * "Copyright (c) 2000-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." + * + * Copyright (c) 2002-2005 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. + */ + +/** + * This application sends a single active message broadcast if it has + * address 0, and then starts a timer at 1Hz. If it has any address + * other than 0, it starts a timer at 1 Hz upon receiving a broadcast + * message. The idea is to have one base station with address 0 send + * out a broadacst message to synchronize itself with all receivers. + * All Leds from the base station and any receivers of the broadcast + * should blink together. + + * It uses the radio HIL component + * ActiveMessageC, and its packets are AM type 240. + * + * @author Phil Levis + * @author Kevin Klues + * @date Nov 7 2005 + */ + +configuration TestTimerAppC {} +implementation { + components MainC, TestTimerC as App, RandomC; + components new TimerMilliC() as A; + components new TimerMilliC() as B; + components new TimerMilliC() as C; + components new TimerMilliC() as D; + + App.Boot -> MainC.Boot; + App.A -> A; + App.B -> B; + App.C -> C; + App.D -> D; + App.Random -> RandomC; + +} + + diff --git a/apps/tests/TestSimTimers/TestTimerC.nc b/apps/tests/TestSimTimers/TestTimerC.nc new file mode 100644 index 00000000..aab5ffe6 --- /dev/null +++ b/apps/tests/TestSimTimers/TestTimerC.nc @@ -0,0 +1,133 @@ +// $Id$ + +/* tab:4 + * "Copyright (c) 2000-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." + * + * 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. + */ + +/** + * Implementation of the TestTimer application. + * + * @author Phil Levis + * @date April 7 2007 + * + **/ + +module TestTimerC { + uses { + interface Boot; + interface Timer as A; + interface Timer as B; + interface Timer as C; + interface Timer as D; + interface Random; + } +} +implementation { + + uint32_t aTime; + uint32_t bTime; + uint32_t cTime; + uint32_t dTime; + + sim_time_t aStart; + sim_time_t bStart; + sim_time_t cStart; + sim_time_t dStart; + + void check(char name, sim_time_t start, uint32_t interval) { + sim_time_t now = sim_time(); + sim_time_t elapsed = now - start; + elapsed /= (sim_ticks_per_sec() / 1024); + if (elapsed != interval) { + dbg("TestTimer", "Timer %c is off. Should have fired in %u, fired in %u.\n", name, interval, (uint32_t)elapsed); + } + else { + dbg("TestTimer", "Timer %c is good.\n", name); + } + } + + void randomizeTimers() { + aTime = call Random.rand32() & 0x3ff; + bTime = call Random.rand32() & 0x3ff; + cTime = call Random.rand32() & 0x3ff; + dTime = call Random.rand32() & 0x3ff; + } + + void startTimers() { + call A.startPeriodic(aTime); + call B.startPeriodic(bTime); + call C.startOneShot(cTime); + call D.startOneShot(dTime); + aStart = bStart = cStart = dStart = sim_time(); + } + + event void Boot.booted() { + randomizeTimers(); + startTimers(); + } + + event void A.fired() { + check('A', aStart, aTime); + aStart = sim_time(); + if (aTime & 0xff) { + call A.stop(); + aTime = call Random.rand32() & 0x3ff; + call A.startPeriodic(aTime); + } + } + + event void B.fired() { + check('B', bStart, bTime); + call B.stop(); + bTime = call Random.rand32() & 0x3ff; + call B.startPeriodic(bTime); + bStart = sim_time(); + } + + event void C.fired() { + check('C', cStart, cTime); + if (cTime & 0xff) { + call C.stop(); + cTime = call Random.rand32() & 0x3ff; + } + call C.startOneShot(cTime); + cStart = sim_time(); + } + + event void D.fired() { + check('D', dStart, dTime); + dTime = call Random.rand32() & 0x3ff; + call D.startOneShot(dTime); + dStart = sim_time(); + } + +} + + + + diff --git a/apps/tests/TestSimTimers/script.py b/apps/tests/TestSimTimers/script.py new file mode 100644 index 00000000..6feb89ec --- /dev/null +++ b/apps/tests/TestSimTimers/script.py @@ -0,0 +1,20 @@ +from TOSSIM import * +import sys +import time + +t = Tossim([]) + +t.addChannel("TestTimer", sys.stdout) +#t.addChannel("Timer", sys.stdout) +#t.addChannel("HplAtm128Timer0AsyncP", sys.stdout) +#t.addChannel("Atm128AlarmAsyncP", sys.stdout) + +start = time.time(); +m1 = t.getNode(0) + +m1.bootAtTime(345321); + +for i in range(0, 1000000): + t.runNextEvent(); + + -- 2.39.2