]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Move weather instrument sensors code out of TOSDIR/chips, as they aren't.
authorsmckown <smckown@4bc1554a-c7f2-4f65-a403-e0be01f0239c>
Wed, 5 Aug 2009 02:57:07 +0000 (02:57 +0000)
committerR. Steve McKown <rsmckown@gmail.com>
Tue, 1 Dec 2009 03:01:42 +0000 (20:01 -0700)
For now, we'll place them in TOSDIR/platforms/tmirws/sensors.  Also, renamed
are the OwwSpeed files, to Anemometer, and OwwVane files to WindVane, as these
names better reflect the fact that the code isn't all that OWW or Davis
specific.

30 files changed:
tos/chips/davis/OwwSpeed.h [deleted file]
tos/chips/davis/OwwSpeedC.nc [deleted file]
tos/chips/davis/OwwSpeedP.nc [deleted file]
tos/chips/davis/OwwVane.h [deleted file]
tos/chips/davis/OwwVaneC.nc [deleted file]
tos/chips/davis/OwwVaneP.nc [deleted file]
tos/chips/oww/OwwSpeed.h [deleted file]
tos/chips/oww/OwwSpeedC.nc [deleted file]
tos/chips/oww/OwwSpeedP.nc [deleted file]
tos/chips/oww/OwwVane.h [deleted file]
tos/chips/oww/OwwVaneC.nc [deleted file]
tos/chips/oww/OwwVaneP.nc [deleted file]
tos/platforms/tmirws/chips/oww/HalOwwSpeedC.nc [deleted file]
tos/platforms/tmirws/chips/oww/HalOwwSpeedP.nc [deleted file]
tos/platforms/tmirws/chips/oww/HalOwwVaneC.nc [deleted file]
tos/platforms/tmirws/chips/oww/HalOwwVaneP.nc [deleted file]
tos/platforms/tmirws/sensors/Anemometer.h [new file with mode: 0644]
tos/platforms/tmirws/sensors/AnemometerC.nc [new file with mode: 0644]
tos/platforms/tmirws/sensors/AnemometerP.nc [new file with mode: 0644]
tos/platforms/tmirws/sensors/HalAnemometerC.nc [new file with mode: 0644]
tos/platforms/tmirws/sensors/HalAnemometerP.nc [new file with mode: 0644]
tos/platforms/tmirws/sensors/HalOwwVaneC.nc [new file with mode: 0644]
tos/platforms/tmirws/sensors/HalOwwVaneP.nc [new file with mode: 0644]
tos/platforms/tmirws/sensors/HalWindVaneC.nc [new file with mode: 0644]
tos/platforms/tmirws/sensors/HalWindVaneP.nc [new file with mode: 0644]
tos/platforms/tmirws/sensors/WindVane.h [new file with mode: 0644]
tos/platforms/tmirws/sensors/WindVaneAdcC.nc [new file with mode: 0644]
tos/platforms/tmirws/sensors/WindVaneAdcP.nc [new file with mode: 0644]
tos/platforms/tmirws/sensors/WindVaneC.nc [new file with mode: 0644]
tos/platforms/tmirws/sensors/WindVaneP.nc [new file with mode: 0644]

diff --git a/tos/chips/davis/OwwSpeed.h b/tos/chips/davis/OwwSpeed.h
deleted file mode 100644 (file)
index 9c9c9b9..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * OWW speed definitions
- * 
- * @author R. Steve McKown <smckown@gmail.com>
- */
-#ifndef OWW_SPEED_H
-#define OWW_SPEED_H
-
-typedef struct {
-  uint8_t min;
-  uint8_t avg;
-  uint8_t max;
-} oww_speed_t;
-
-#endif
diff --git a/tos/chips/davis/OwwSpeedC.nc b/tos/chips/davis/OwwSpeedC.nc
deleted file mode 100644 (file)
index 4bd255f..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * OwwSpeed sensor
- * 
- * @author R. Steve McKown <smckown@gmail.com>
- */
-#include "OwwSpeed.h"
-
-configuration OwwSpeedC {
-  provides interface ReadRef<oww_speed_t>;
-}
-implementation {
-  components OwwSpeedP;
-  ReadRef = OwwSpeedP;
-
-  components SoftwareRtcC as RtcC;
-  OwwSpeedP.Second -> RtcC;
-
-  components HalOwwSpeedC;
-  OwwSpeedP.CPSA -> HalOwwSpeedC.CPSA;
-  OwwSpeedP.CPSB -> HalOwwSpeedC.CPSB;
-}
diff --git a/tos/chips/davis/OwwSpeedP.nc b/tos/chips/davis/OwwSpeedP.nc
deleted file mode 100644 (file)
index 7f1870f..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * OwwSpeed sensor
- * 
- * @author R. Steve McKown <smckown@gmail.com>
- */
-#include "OwwSpeed.h"
-
-module OwwSpeedP {
-  provides interface ReadRef<oww_speed_t>;
-  uses {
-    interface Tick as Second;
-    interface AsyncGet<uint8_t> as CPSA;
-    interface AsyncGet<uint8_t> as CPSB;
-  }
-}
-implementation {
-  oww_speed_t* m_data;
-  uint8_t minSpeed = 255;
-  uint8_t maxSpeed;
-
-
-  /*** Support functions ***/
-
-
-  /* Convert counts per second to mph */
-  uint8_t toMph(uint8_t cps)
-  {
-    return (uint8_t)(2.453 * (cps >> 1) + 0.5);
-  }
-
-
-  /*** Method implementations ***/
-
-
-  async event void Second.fired()
-  {
-    uint8_t speed = call CPSA.get();
-
-    if (speed < minSpeed)
-      minSpeed = speed;
-    if (speed > maxSpeed)
-      maxSpeed = speed;
-  }
-
-  task void readSpeed();
-
-  command error_t ReadRef.read(oww_speed_t* data)
-  {
-    if (!data)
-      return EINVAL;
-    else if (m_data)
-      return EBUSY;
-    else {
-      m_data = data;
-      post readSpeed();
-      return SUCCESS;
-    }
-  }
-
-  void signalDone(error_t);
-
-  task void readSpeed()
-  {
-    atomic {
-      m_data->min = minSpeed;
-      m_data->avg = call CPSB.get();
-      m_data->max = maxSpeed;
-      minSpeed = 255;
-      maxSpeed = 0;
-    }
-    signalDone(SUCCESS);
-  }
-
-  void signalDone(error_t error)
-  {
-    oww_speed_t* tmp = m_data;
-
-    m_data = 0;
-    signal ReadRef.readDone(error, tmp);
-  }
-}
diff --git a/tos/chips/davis/OwwVane.h b/tos/chips/davis/OwwVane.h
deleted file mode 100644 (file)
index c1ae5d7..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * OWW vane (wind direction) definitions
- * 
- * @author R. Steve McKown <smckown@gmail.com>
- */
-#ifndef OWW_VANE_H
-#define OWW_VANE_H
-
-/* Units are degrees/2, so 90 degrees is 45 units.  This allows a full
- * circle of degrees to be represented in a single byte for small storage.
- * Resolution reduction is fine, since the OWW's native resolution is
- * 22.5 degrees.
- */
-typedef struct {
-#if 0
-  uint8_t left;
-  uint8_t avg;
-  uint8_t right;
-#else
-  uint16_t left;
-  uint16_t avg;
-  uint16_t right;
-#endif
-} oww_vane_t;
-
-#endif
diff --git a/tos/chips/davis/OwwVaneC.nc b/tos/chips/davis/OwwVaneC.nc
deleted file mode 100644 (file)
index f4ee4c1..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * OwwVane sensor
- * 
- * @author R. Steve McKown <smckown@gmail.com>
- */
-#include "OwwVane.h"
-
-configuration OwwVaneC {
-  provides interface ReadRef<oww_vane_t>;
-}
-implementation {
-  components OwwVaneP;
-  ReadRef = OwwVaneP;
-
-  components SoftwareRtcC as RtcC;
-  OwwVaneP.Second -> RtcC;
-
-  components HalOwwVaneC;
-  OwwVaneP.Vane -> HalOwwVaneC.AsyncGet;
-}
diff --git a/tos/chips/davis/OwwVaneP.nc b/tos/chips/davis/OwwVaneP.nc
deleted file mode 100644 (file)
index 35ee7d6..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * OwwVane sensor
- * 
- * @author R. Steve McKown <smckown@gmail.com>
- */
-#include "OwwVane.h"
-
-module OwwVaneP {
-  provides interface ReadRef<oww_vane_t>;
-  uses {
-    interface Tick as Second;
-    interface AsyncGet<uint8_t> as Vane;
-  }
-}
-implementation {
-#define COMPASS_COUNT  16
-
-  oww_vane_t* m_data;
-  /* compass[0] = North, 0 degrees,
-   * compass(COMPASS_COUNT/2) = South, 180 degrees.
-   */
-  uint16_t compass[COMPASS_COUNT];
-
-
-  /*** Support functions ***/
-
-
-  /* return the number of positions clockwise along the compass from start
-   * to end.
-   */
-  uint8_t distance(uint8_t start, uint8_t end)
-  {
-    return (end > start) ? end - start : (end + COMPASS_COUNT) - start;
-  }
-
-  /* circularly examine compass, starting with pos+1, for the next compass
-   * position having a value of zero.
-   */
-  uint8_t nextNonZero(uint16_t* tc, uint8_t pos)
-  {
-    do {
-      pos = (pos + 1) % COMPASS_COUNT;
-    } while (tc[pos] == 0);
-    return pos;
-  }
-
-  bool isCompassEmpty(uint16_t* tc)
-  {
-    int i;
-
-    for (i = 0; i < COMPASS_COUNT; i++) {
-      if (tc[i])
-       break;
-    }
-    return (i == COMPASS_COUNT) ? TRUE : FALSE;
-  }
-
-  /* Reduce all compass headings equally until a compass heading has a value
-   * of zero.
-   */
-  void minimizeCompass(uint16_t* tc)
-  {
-    uint8_t min = 255;
-
-    do {
-      int i;
-
-      for (i = 0; i < COMPASS_COUNT; i++) {
-       if (tc[i] < min)
-         min = tc[i];
-      }
-      if (min > 0) {
-       for (i = 0; i < COMPASS_COUNT; i++)
-         tc[i] -= min;
-      }
-    } while (min);
-  }
-
-  /* Locate the arc in which the compass[] has been constrained, defining
-   * that arc in m_data's left and right fields.  The compass arc is always
-   * defined clockwise, from left to right.
-   */
-  void findArc(uint16_t* tc)
-  {
-    uint8_t begin;
-    uint8_t save = 255;
-    uint8_t dist = 0;
-
-    begin = m_data->left = nextNonZero(tc, COMPASS_COUNT - 1);
-    do {
-      uint8_t d;
-
-      m_data->right = nextNonZero(tc, m_data->left);
-      d = distance(m_data->left, m_data->right);
-      if (d > dist) {
-       dist = d;
-       save = m_data->left;
-      }
-      m_data->left = m_data->right;
-    } while (m_data->left != begin);
-    m_data->right = save;
-    m_data->left = (save + dist) % COMPASS_COUNT;
-  }
-
-  void calcAvg(uint16_t* tc)
-  {
-    /* Find the average compass heading */
-    uint32_t sum = 0;
-    uint32_t count = 0;
-    uint32_t tmp = (m_data->right >= m_data->left) ? m_data->right :
-       m_data->right + COMPASS_COUNT;
-    int i;
-
-    for (i = m_data->left; i <= tmp; i++) {
-      uint8_t p = i % COMPASS_COUNT;
-
-      sum += tc[p] * i;
-      count += tc[p];
-    }
-    /* Reduce the sum by whole compass arcs, since only the remaining
-     * partial arc is of relevance.
-     */
-    tmp = COMPASS_COUNT * count;
-    while (sum >= tmp)
-      sum -= tmp;
-    m_data->avg = (sum == 0) ? 0 : (3600 / COMPASS_COUNT) * sum / count / 10;
-  }
-
-
-  /*** Method implementations ***/
-
-
-  async event void Second.fired()
-  {
-    const static uint8_t lookup[] = {
-      0x01, 0x03, 0x02, 0x06, 0x04, 0x0c, 0x08, 0x18,
-      0x10, 0x30, 0x20, 0x60, 0x40, 0xc0, 0x80, 0x81
-    };
-    uint8_t wind;
-    uint8_t i = 0;
-
-    wind = call Vane.get();
-    for (i = 0; i < sizeof(lookup); i++) {
-      if (lookup[i] == wind) {
-       compass[i]++;
-       return;
-      }
-    }
-  }
-
-  task void readCompass();
-
-  command error_t ReadRef.read(oww_vane_t* data)
-  {
-    if (!data)
-      return EINVAL;
-    else if (m_data)
-      return EBUSY;
-    else {
-      m_data = data;
-      post readCompass();
-      return SUCCESS;
-    }
-  }
-
-  void signalDone(error_t);
-
-  task void readCompass()
-  {
-    uint16_t tc[COMPASS_COUNT];
-
-    atomic {
-      memcpy(tc, compass, sizeof(compass));
-      memset(compass, 0, sizeof(compass));
-    }
-
-    if (isCompassEmpty(tc)) {
-      signalDone(FAIL);
-      return;
-    }
-    minimizeCompass(tc);
-    findArc(tc);
-    calcAvg(tc);
-
-    /* m_data's left, avg and right fields are currently represented in
-     * compass positions.  We must now convert those fields into units of
-     * angular degrees.
-     */
-    m_data->left = 3600U / COMPASS_COUNT * m_data->left / 10;
-    m_data->right = 3600U / COMPASS_COUNT * m_data->right / 10;
-    signalDone(SUCCESS);
-  }
-
-  void signalDone(error_t error)
-  {
-    oww_vane_t* tmp = m_data;
-
-    m_data = 0;
-    signal ReadRef.readDone(error, tmp);
-  }
-}
diff --git a/tos/chips/oww/OwwSpeed.h b/tos/chips/oww/OwwSpeed.h
deleted file mode 100644 (file)
index b47d05d..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * OWW speed definitions
- * 
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-#ifndef OWW_SPEED_H
-#define OWW_SPEED_H
-
-typedef struct {
-  uint8_t min;
-  uint8_t avg;
-  uint8_t max;
-} oww_speed_t;
-
-#endif
diff --git a/tos/chips/oww/OwwSpeedC.nc b/tos/chips/oww/OwwSpeedC.nc
deleted file mode 100644 (file)
index 97adadb..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * OwwSpeed sensor
- * 
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-#include "OwwSpeed.h"
-
-configuration OwwSpeedC {
-  provides interface ReadRef<oww_speed_t>;
-}
-implementation {
-  components OwwSpeedP;
-  ReadRef = OwwSpeedP;
-
-  components SoftwareRtcC as RtcC;
-  OwwSpeedP.Second -> RtcC;
-
-  components HalOwwSpeedC;
-  OwwSpeedP.CPSA -> HalOwwSpeedC.CPSA;
-  OwwSpeedP.CPSB -> HalOwwSpeedC.CPSB;
-}
diff --git a/tos/chips/oww/OwwSpeedP.nc b/tos/chips/oww/OwwSpeedP.nc
deleted file mode 100644 (file)
index 6d7437e..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * OwwSpeed sensor
- * 
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-#include "OwwSpeed.h"
-
-module OwwSpeedP {
-  provides interface ReadRef<oww_speed_t>;
-  uses {
-    interface Tick as Second;
-    interface AsyncGet<uint8_t> as CPSA;
-    interface AsyncGet<uint8_t> as CPSB;
-  }
-}
-implementation {
-  oww_speed_t* m_data;
-  uint8_t minSpeed = 255;
-  uint8_t maxSpeed;
-
-
-  /*** Support functions ***/
-
-
-  /* Convert counts per second to mph */
-  uint8_t toMph(uint8_t cps)
-  {
-    return (uint8_t)(2.453 * (cps >> 1) + 0.5);
-  }
-
-
-  /*** Method implementations ***/
-
-
-  async event void Second.fired()
-  {
-    uint8_t speed = call CPSA.get();
-
-    if (speed < minSpeed)
-      minSpeed = speed;
-    if (speed > maxSpeed)
-      maxSpeed = speed;
-  }
-
-  task void readSpeed();
-
-  command error_t ReadRef.read(oww_speed_t* data)
-  {
-    if (!data)
-      return EINVAL;
-    else if (m_data)
-      return EBUSY;
-    else {
-      m_data = data;
-      post readSpeed();
-      return SUCCESS;
-    }
-  }
-
-  void signalDone(error_t);
-
-  task void readSpeed()
-  {
-    atomic {
-      m_data->min = minSpeed;
-      m_data->avg = call CPSB.get();
-      m_data->max = maxSpeed;
-      minSpeed = 255;
-      maxSpeed = 0;
-    }
-    signalDone(SUCCESS);
-  }
-
-  void signalDone(error_t error)
-  {
-    oww_speed_t* tmp = m_data;
-
-    m_data = 0;
-    signal ReadRef.readDone(error, tmp);
-  }
-}
diff --git a/tos/chips/oww/OwwVane.h b/tos/chips/oww/OwwVane.h
deleted file mode 100644 (file)
index 3eab953..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * OWW vane (wind direction) definitions
- * 
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-#ifndef OWW_VANE_H
-#define OWW_VANE_H
-
-/* Units are degrees/2, so 90 degrees is 45 units.  This allows a full
- * circle of degrees to be represented in a single byte for small storage.
- * Resolution reduction is fine, since the OWW's native resolution is
- * 22.5 degrees.
- */
-typedef struct {
-#if 0
-  uint8_t left;
-  uint8_t avg;
-  uint8_t right;
-#else
-  uint16_t left;
-  uint16_t avg;
-  uint16_t right;
-#endif
-} oww_vane_t;
-
-#endif
diff --git a/tos/chips/oww/OwwVaneC.nc b/tos/chips/oww/OwwVaneC.nc
deleted file mode 100644 (file)
index 82d23cd..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * OwwVane sensor
- * 
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-#include "OwwVane.h"
-
-configuration OwwVaneC {
-  provides interface ReadRef<oww_vane_t>;
-}
-implementation {
-  components OwwVaneP;
-  ReadRef = OwwVaneP;
-
-  components SoftwareRtcC as RtcC;
-  OwwVaneP.Second -> RtcC;
-
-  components HalOwwVaneC;
-  OwwVaneP.Vane -> HalOwwVaneC.AsyncGet;
-}
diff --git a/tos/chips/oww/OwwVaneP.nc b/tos/chips/oww/OwwVaneP.nc
deleted file mode 100644 (file)
index 9755db1..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * OwwVane sensor
- * 
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-#include "OwwVane.h"
-
-module OwwVaneP {
-  provides interface ReadRef<oww_vane_t>;
-  uses {
-    interface Tick as Second;
-    interface AsyncGet<uint8_t> as Vane;
-  }
-}
-implementation {
-#define COMPASS_COUNT  16
-
-  oww_vane_t* m_data;
-  /* compass[0] = North, 0 degrees,
-   * compass(COMPASS_COUNT/2) = South, 180 degrees.
-   */
-  uint16_t compass[COMPASS_COUNT];
-
-
-  /*** Support functions ***/
-
-
-  /* return the number of positions clockwise along the compass from start
-   * to end.
-   */
-  uint8_t distance(uint8_t start, uint8_t end)
-  {
-    return (end > start) ? end - start : (end + COMPASS_COUNT) - start;
-  }
-
-  /* circularly examine compass, starting with pos+1, for the next compass
-   * position having a value of zero.
-   */
-  uint8_t nextNonZero(uint16_t* tc, uint8_t pos)
-  {
-    do {
-      pos = (pos + 1) % COMPASS_COUNT;
-    } while (tc[pos] == 0);
-    return pos;
-  }
-
-  bool isCompassEmpty(uint16_t* tc)
-  {
-    int i;
-
-    for (i = 0; i < COMPASS_COUNT; i++) {
-      if (tc[i])
-       break;
-    }
-    return (i == COMPASS_COUNT) ? TRUE : FALSE;
-  }
-
-  /* Reduce all compass headings equally until a compass heading has a value
-   * of zero.
-   */
-  void minimizeCompass(uint16_t* tc)
-  {
-    uint8_t min = 255;
-
-    do {
-      int i;
-
-      for (i = 0; i < COMPASS_COUNT; i++) {
-       if (tc[i] < min)
-         min = tc[i];
-      }
-      if (min > 0) {
-       for (i = 0; i < COMPASS_COUNT; i++)
-         tc[i] -= min;
-      }
-    } while (min);
-  }
-
-  /* Locate the arc in which the compass[] has been constrained, defining
-   * that arc in m_data's left and right fields.  The compass arc is always
-   * defined clockwise, from left to right.
-   */
-  void findArc(uint16_t* tc)
-  {
-    uint8_t begin;
-    uint8_t save = 255;
-    uint8_t dist = 0;
-
-    begin = m_data->left = nextNonZero(tc, COMPASS_COUNT - 1);
-    do {
-      uint8_t d;
-
-      m_data->right = nextNonZero(tc, m_data->left);
-      d = distance(m_data->left, m_data->right);
-      if (d > dist) {
-       dist = d;
-       save = m_data->left;
-      }
-      m_data->left = m_data->right;
-    } while (m_data->left != begin);
-    m_data->right = save;
-    m_data->left = (save + dist) % COMPASS_COUNT;
-  }
-
-  void calcAvg(uint16_t* tc)
-  {
-    /* Find the average compass heading */
-    uint32_t sum = 0;
-    uint32_t count = 0;
-    uint32_t tmp = (m_data->right >= m_data->left) ? m_data->right :
-       m_data->right + COMPASS_COUNT;
-    int i;
-
-    for (i = m_data->left; i <= tmp; i++) {
-      uint8_t p = i % COMPASS_COUNT;
-
-      sum += tc[p] * i;
-      count += tc[p];
-    }
-    /* Reduce the sum by whole compass arcs, since only the remaining
-     * partial arc is of relevance.
-     */
-    tmp = COMPASS_COUNT * count;
-    while (sum >= tmp)
-      sum -= tmp;
-    m_data->avg = (sum == 0) ? 0 : (3600 / COMPASS_COUNT) * sum / count / 10;
-  }
-
-
-  /*** Method implementations ***/
-
-
-  async event void Second.fired()
-  {
-    const static uint8_t lookup[] = {
-      0x01, 0x03, 0x02, 0x06, 0x04, 0x0c, 0x08, 0x18,
-      0x10, 0x30, 0x20, 0x60, 0x40, 0xc0, 0x80, 0x81
-    };
-    uint8_t wind;
-    uint8_t i = 0;
-
-    wind = call Vane.get();
-    for (i = 0; i < sizeof(lookup); i++) {
-      if (lookup[i] == wind) {
-       compass[i]++;
-       return;
-      }
-    }
-  }
-
-  task void readCompass();
-
-  command error_t ReadRef.read(oww_vane_t* data)
-  {
-    if (!data)
-      return EINVAL;
-    else if (m_data)
-      return EBUSY;
-    else {
-      m_data = data;
-      post readCompass();
-      return SUCCESS;
-    }
-  }
-
-  void signalDone(error_t);
-
-  task void readCompass()
-  {
-    uint16_t tc[COMPASS_COUNT];
-
-    atomic {
-      memcpy(tc, compass, sizeof(compass));
-      memset(compass, 0, sizeof(compass));
-    }
-
-    if (isCompassEmpty(tc)) {
-      signalDone(FAIL);
-      return;
-    }
-    minimizeCompass(tc);
-    findArc(tc);
-    calcAvg(tc);
-
-    /* m_data's left, avg and right fields are currently represented in
-     * compass positions.  We must now convert those fields into units of
-     * angular degrees.
-     */
-    m_data->left = 3600U / COMPASS_COUNT * m_data->left / 10;
-    m_data->right = 3600U / COMPASS_COUNT * m_data->right / 10;
-    signalDone(SUCCESS);
-  }
-
-  void signalDone(error_t error)
-  {
-    oww_vane_t* tmp = m_data;
-
-    m_data = 0;
-    signal ReadRef.readDone(error, tmp);
-  }
-}
diff --git a/tos/platforms/tmirws/chips/oww/HalOwwSpeedC.nc b/tos/platforms/tmirws/chips/oww/HalOwwSpeedC.nc
deleted file mode 100644 (file)
index de0e663..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * HAL/HPL layers for the OwwSpeed sensor.  CPSA and CPSB are independent
- * services that each provide a counts per second value that represents the
- * average CPS since the last call to CPSx.get().  The first call to
- * CPSx.get() is derived from a start time of initialization of the
- * HalOwwSpeedP component.
- * 
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-#include "OwwSpeed.h"
-
-configuration HalOwwSpeedC {
-  provides interface AsyncGet<uint8_t> as CPSA;
-  provides interface AsyncGet<uint8_t> as CPSB;
-}
-implementation {
-  components HalOwwSpeedP;
-  CPSA = HalOwwSpeedP.CPSA;
-  CPSB = HalOwwSpeedP.CPSB;
-
-  components MainC;
-  MainC.SoftwareInit -> HalOwwSpeedP.Init;
-
-  components Counter32khz32C;
-  HalOwwSpeedP.TimeCounter -> Counter32khz32C;
-
-  components Msp430CounterMicroC;
-  HalOwwSpeedP.SpinCounter -> Msp430CounterMicroC;
-}
diff --git a/tos/platforms/tmirws/chips/oww/HalOwwSpeedP.nc b/tos/platforms/tmirws/chips/oww/HalOwwSpeedP.nc
deleted file mode 100644 (file)
index fb3ed6b..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * HAL/HPL layers for the OwwSpeed sensor.
- * 
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-#include "OwwSpeed.h"
-
-module HalOwwSpeedP {
-  provides {
-    interface Init;
-    interface AsyncGet<uint8_t> as CPSA;
-    interface AsyncGet<uint8_t> as CPSB;
-  }
-  uses {
-    interface Counter<T32khz,uint32_t> as TimeCounter;
-    interface Counter<TMicro,uint16_t> as SpinCounter;
-  }
-}
-implementation {
-  uint32_t prevATime;
-  uint16_t prevASpin;
-  uint32_t prevBTime;
-  uint16_t prevBSpin;
-
-  command error_t Init.init()
-  {
-    atomic {
-      /* Initialize Timer A, clock source is io pin P1.0 */
-      TACTL = 0;
-      TACTL = TACLR | MC_2 | ID_0 | TASSEL_0;
-      P1SEL |= 1;
-    }
-    prevATime = call TimeCounter.get();
-    prevASpin = call SpinCounter.get();
-    prevBTime = prevATime;
-    prevBSpin = prevASpin;
-    return SUCCESS;
-  }
-
-  async command uint8_t CPSA.get()
-  {
-    uint32_t currTime;
-    uint16_t currSpin;
-    uint32_t deltaT;
-    uint8_t cps;
-
-    atomic {
-      currTime = call TimeCounter.get();
-      currSpin = call SpinCounter.get();
-    }
-    deltaT = (currTime - prevATime);
-    cps = ((uint32_t)(currSpin - prevASpin) * 32768U + (deltaT >> 1)) / deltaT;
-    prevATime = currTime;
-    prevASpin = currSpin;
-    return cps;
-  }
-
-  async command uint8_t CPSB.get()
-  {
-    uint32_t currTime;
-    uint16_t currSpin;
-    uint32_t deltaT;
-    uint8_t cps;
-
-    atomic {
-      currTime = call TimeCounter.get();
-      currSpin = call SpinCounter.get();
-    }
-    deltaT = (currTime - prevBTime);
-    cps = ((uint32_t)(currSpin - prevBSpin) * 32768U + (deltaT >> 1)) / deltaT;
-    prevBTime = currTime;
-    prevBSpin = currSpin;
-    return cps;
-  }
-
-  async event void TimeCounter.overflow() {}
-  async event void SpinCounter.overflow() {}
-}
diff --git a/tos/platforms/tmirws/chips/oww/HalOwwVaneC.nc b/tos/platforms/tmirws/chips/oww/HalOwwVaneC.nc
deleted file mode 100644 (file)
index a40c2ed..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * HAL/HPL layers for the OwwVane sensor.
- * 
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-#include "OwwVane.h"
-
-configuration HalOwwVaneC {
-  provides interface AsyncGet<uint8_t>;
-}
-implementation {
-  components HalOwwVaneP;
-  AsyncGet = HalOwwVaneP;
-
-  components MainC;
-  MainC.SoftwareInit -> HalOwwVaneP.Init;
-}
diff --git a/tos/platforms/tmirws/chips/oww/HalOwwVaneP.nc b/tos/platforms/tmirws/chips/oww/HalOwwVaneP.nc
deleted file mode 100644 (file)
index 4b0fa5c..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
- * 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 Titanium Mirror, Inc. 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.
- */
-/**
- * HAL/HPL layers for the OwwVane sensor.
- * 
- * @author R. Steve McKown <rsmckown@gmail.com>
- */
-#include "OwwVane.h"
-
-module HalOwwVaneP {
-  provides {
-    interface Init;
-    interface AsyncGet<uint8_t> as Vane;
-  }
-}
-implementation {
-#define WIND_IN (*TCAST(volatile uint8_t* ONE, P5IN_))
-#define WIND_DIR (*TCAST(volatile uint8_t* ONE, P5DIR_))
-#define WIND_SEL (*TCAST(volatile uint8_t* ONE, P5SEL_))
-#define WIND_REN (*TCAST(volatile uint8_t* ONE, P5REN_))
-
-  command error_t Init.init()
-  {
-    /* Initialize the port providing wind direction information */
-    WIND_DIR = 0;
-    WIND_SEL = 0;
-    WIND_REN = 0;
-    return SUCCESS;
-  }
-
-  async command uint8_t Vane.get()
-  {
-    atomic return ~WIND_IN;
-  }
-}
diff --git a/tos/platforms/tmirws/sensors/Anemometer.h b/tos/platforms/tmirws/sensors/Anemometer.h
new file mode 100644 (file)
index 0000000..936a444
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * Anemometer definitions
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+#ifndef ANEMOMETER_H
+#define ANEMOMETER_H
+
+typedef struct {
+  uint8_t min;
+  uint8_t avg;
+  uint8_t max;
+} anemometer_t;
+
+#endif
diff --git a/tos/platforms/tmirws/sensors/AnemometerC.nc b/tos/platforms/tmirws/sensors/AnemometerC.nc
new file mode 100644 (file)
index 0000000..b141ca7
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * Anemometer sensor, measuring wind speed
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+#include "Anemometer.h"
+
+configuration AnemometerC {
+  provides interface ReadRef<anemometer_t>;
+}
+implementation {
+  components AnemometerP;
+  ReadRef = AnemometerP;
+
+  components SoftwareRtcC as RtcC;
+  AnemometerP.Second -> RtcC;
+
+  components HalAnemometerC;
+  AnemometerP.CPSA -> HalAnemometerC.CPSA;
+  AnemometerP.CPSB -> HalAnemometerC.CPSB;
+}
diff --git a/tos/platforms/tmirws/sensors/AnemometerP.nc b/tos/platforms/tmirws/sensors/AnemometerP.nc
new file mode 100644 (file)
index 0000000..40f8fc3
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * Anemometer sensor, measuring wind speed
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+#include "Anemometer.h"
+
+module AnemometerP {
+  provides interface ReadRef<anemometer_t>;
+  uses {
+    interface Tick as Second;
+    interface AsyncGet<uint8_t> as CPSA;
+    interface AsyncGet<uint8_t> as CPSB;
+  }
+}
+implementation {
+  anemometer_t* m_data;
+  uint8_t minSpeed = 255;
+  uint8_t maxSpeed;
+
+
+  /*** Support functions ***/
+
+
+  /* Convert counts per second to mph */
+  uint8_t toMph(uint8_t cps)
+  {
+    return (uint8_t)(2.453 * (cps >> 1) + 0.5);
+  }
+
+
+  /*** Method implementations ***/
+
+
+  async event void Second.fired()
+  {
+    uint8_t speed = call CPSA.get();
+
+    if (speed < minSpeed)
+      minSpeed = speed;
+    if (speed > maxSpeed)
+      maxSpeed = speed;
+  }
+
+  task void readSpeed();
+
+  command error_t ReadRef.read(anemometer_t* data)
+  {
+    if (!data)
+      return EINVAL;
+    else if (m_data)
+      return EBUSY;
+    else {
+      m_data = data;
+      post readSpeed();
+      return SUCCESS;
+    }
+  }
+
+  void signalDone(error_t);
+
+  task void readSpeed()
+  {
+    atomic {
+      m_data->min = toMph(minSpeed);
+      m_data->avg = toMph(call CPSB.get());
+      m_data->max = toMph(maxSpeed);
+      minSpeed = 255;
+      maxSpeed = 0;
+    }
+    signalDone(SUCCESS);
+  }
+
+  void signalDone(error_t error)
+  {
+    anemometer_t* tmp = m_data;
+
+    m_data = 0;
+    signal ReadRef.readDone(error, tmp);
+  }
+}
diff --git a/tos/platforms/tmirws/sensors/HalAnemometerC.nc b/tos/platforms/tmirws/sensors/HalAnemometerC.nc
new file mode 100644 (file)
index 0000000..f5ada62
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * HAL layer for the Anemometer sensor.  CPSA and CPSB are independent services
+ * that each provide a counts per second value via its get() command that
+ * represents the average CPS since the last call to its get() command.  The
+ * first call to CPSx.get() uses the initialization of the HalAnemometerP
+ * component during MainC.SoftwareInit as the start time for calculating the
+ * counts per second value.
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+#include "Anemometer.h"
+
+configuration HalAnemometerC {
+  provides interface AsyncGet<uint8_t> as CPSA;
+  provides interface AsyncGet<uint8_t> as CPSB;
+}
+implementation {
+  components HalAnemometerP;
+  CPSA = HalAnemometerP.CPSA;
+  CPSB = HalAnemometerP.CPSB;
+
+  components MainC;
+  MainC.SoftwareInit -> HalAnemometerP.Init;
+
+  components Counter32khz32C;
+  HalAnemometerP.TimeCounter -> Counter32khz32C;
+
+  components Msp430CounterMicroC;
+  HalAnemometerP.SpinCounter -> Msp430CounterMicroC;
+}
diff --git a/tos/platforms/tmirws/sensors/HalAnemometerP.nc b/tos/platforms/tmirws/sensors/HalAnemometerP.nc
new file mode 100644 (file)
index 0000000..89e5928
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * HAL layer for the Anemometer sensor.
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+#include "Anemometer.h"
+
+module HalAnemometerP {
+  provides {
+    interface Init;
+    interface AsyncGet<uint8_t> as CPSA;
+    interface AsyncGet<uint8_t> as CPSB;
+  }
+  uses {
+    interface Counter<T32khz,uint32_t> as TimeCounter;
+    interface Counter<TMicro,uint16_t> as SpinCounter;
+  }
+}
+implementation {
+  uint32_t prevATime;
+  uint16_t prevASpin;
+  uint32_t prevBTime;
+  uint16_t prevBSpin;
+
+  command error_t Init.init()
+  {
+    atomic {
+      /* Initialize Timer A, clock source is io pin P1.0.  Timer A provides the
+       * clock for the SpinCounter component.
+       */
+      TACTL = 0;
+      TACTL = TACLR | MC_2 | ID_0 | TASSEL_0;
+      P1SEL |= 1;
+    }
+    prevATime = call TimeCounter.get();
+    prevASpin = call SpinCounter.get();
+    prevBTime = prevATime;
+    prevBSpin = prevASpin;
+    return SUCCESS;
+  }
+
+  async command uint8_t CPSA.get()
+  {
+    uint32_t currTime;
+    uint16_t currSpin;
+    uint32_t deltaT;
+    uint8_t cps;
+
+    atomic {
+      currTime = call TimeCounter.get();
+      currSpin = call SpinCounter.get();
+    }
+    deltaT = (currTime - prevATime);
+    cps = ((uint32_t)(currSpin - prevASpin) * 32768U + (deltaT >> 1)) / deltaT;
+    prevATime = currTime;
+    prevASpin = currSpin;
+    return cps;
+  }
+
+  async command uint8_t CPSB.get()
+  {
+    uint32_t currTime;
+    uint16_t currSpin;
+    uint32_t deltaT;
+    uint8_t cps;
+
+    atomic {
+      currTime = call TimeCounter.get();
+      currSpin = call SpinCounter.get();
+    }
+    deltaT = (currTime - prevBTime);
+    cps = ((uint32_t)(currSpin - prevBSpin) * 32768U + (deltaT >> 1)) / deltaT;
+    prevBTime = currTime;
+    prevBSpin = currSpin;
+    return cps;
+  }
+
+  async event void TimeCounter.overflow() {}
+  async event void SpinCounter.overflow() {}
+}
diff --git a/tos/platforms/tmirws/sensors/HalOwwVaneC.nc b/tos/platforms/tmirws/sensors/HalOwwVaneC.nc
new file mode 100644 (file)
index 0000000..a40c2ed
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * HAL/HPL layers for the OwwVane sensor.
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+#include "OwwVane.h"
+
+configuration HalOwwVaneC {
+  provides interface AsyncGet<uint8_t>;
+}
+implementation {
+  components HalOwwVaneP;
+  AsyncGet = HalOwwVaneP;
+
+  components MainC;
+  MainC.SoftwareInit -> HalOwwVaneP.Init;
+}
diff --git a/tos/platforms/tmirws/sensors/HalOwwVaneP.nc b/tos/platforms/tmirws/sensors/HalOwwVaneP.nc
new file mode 100644 (file)
index 0000000..4b0fa5c
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * HAL/HPL layers for the OwwVane sensor.
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+#include "OwwVane.h"
+
+module HalOwwVaneP {
+  provides {
+    interface Init;
+    interface AsyncGet<uint8_t> as Vane;
+  }
+}
+implementation {
+#define WIND_IN (*TCAST(volatile uint8_t* ONE, P5IN_))
+#define WIND_DIR (*TCAST(volatile uint8_t* ONE, P5DIR_))
+#define WIND_SEL (*TCAST(volatile uint8_t* ONE, P5SEL_))
+#define WIND_REN (*TCAST(volatile uint8_t* ONE, P5REN_))
+
+  command error_t Init.init()
+  {
+    /* Initialize the port providing wind direction information */
+    WIND_DIR = 0;
+    WIND_SEL = 0;
+    WIND_REN = 0;
+    return SUCCESS;
+  }
+
+  async command uint8_t Vane.get()
+  {
+    atomic return ~WIND_IN;
+  }
+}
diff --git a/tos/platforms/tmirws/sensors/HalWindVaneC.nc b/tos/platforms/tmirws/sensors/HalWindVaneC.nc
new file mode 100644 (file)
index 0000000..21322ae
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * HAL layer for the wind vane sensor.
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+#include "WindVane.h"
+
+configuration HalWindVaneC {
+  provides interface AsyncGet<uint8_t>;
+}
+implementation {
+  components HalWindVaneP;
+  AsyncGet = HalWindVaneP;
+
+  components MainC;
+  MainC.SoftwareInit -> HalWindVaneP.Init;
+}
diff --git a/tos/platforms/tmirws/sensors/HalWindVaneP.nc b/tos/platforms/tmirws/sensors/HalWindVaneP.nc
new file mode 100644 (file)
index 0000000..92bd42a
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * HAL/HPL layers for the WindVane sensor.
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+#include "WindVane.h"
+
+module HalWindVaneP {
+  provides {
+    interface Init;
+    interface AsyncGet<uint8_t> as Vane;
+  }
+}
+implementation {
+#define WIND_IN (*TCAST(volatile uint8_t* ONE, P5IN_))
+#define WIND_DIR (*TCAST(volatile uint8_t* ONE, P5DIR_))
+#define WIND_SEL (*TCAST(volatile uint8_t* ONE, P5SEL_))
+#define WIND_REN (*TCAST(volatile uint8_t* ONE, P5REN_))
+
+  command error_t Init.init()
+  {
+    /* Initialize the port providing wind direction information */
+    WIND_DIR = 0;
+    WIND_SEL = 0;
+    WIND_REN = 0;
+    return SUCCESS;
+  }
+
+  async command uint8_t Vane.get()
+  {
+    atomic return ~WIND_IN;
+  }
+}
diff --git a/tos/platforms/tmirws/sensors/WindVane.h b/tos/platforms/tmirws/sensors/WindVane.h
new file mode 100644 (file)
index 0000000..20afde7
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * Wind Vane (direction) definitions
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+#ifndef WIND_VANE_H
+#define WIND_VANE_H
+
+#define WINDVANE_NO_HEADING    255
+
+/* Units are degrees/2, so 90 degrees is 45 units.  This allows a full
+ * circle of degrees to be represented in a single byte.  Resolution reduction
+ * is not a problem, as the OWW's native resolution is 22.5 degrees.
+ */
+typedef struct {
+  uint8_t left;
+  uint8_t avg;
+  uint8_t right;
+} wind_vane_t;
+
+#endif
diff --git a/tos/platforms/tmirws/sensors/WindVaneAdcC.nc b/tos/platforms/tmirws/sensors/WindVaneAdcC.nc
new file mode 100644 (file)
index 0000000..472f9ec
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * Reads the ADC pin connected to the LiPoly battery.  The connection is made
+ * via a resistor divider where the battery voltage is 3x that read by the ADC.
+ * Therefore, BattV = ADC / 4096 * 1.5 * 3.
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+generic configuration BatteryAdcC() {
+  provides interface Read<uint16_t>;
+  provides interface ReadStream<uint16_t>;
+
+  provides interface Resource;
+  provides interface ReadNow<uint16_t>;
+}
+implementation {
+  components new AdcReadClientC();
+  Read = AdcReadClientC;
+
+  components new AdcReadStreamClientC();
+  ReadStream = AdcReadStreamClientC;
+
+  components BatteryAdcP;
+  AdcReadClientC.AdcConfigure -> BatteryAdcP;
+  AdcReadStreamClientC.AdcConfigure -> BatteryAdcP;
+
+  components new AdcReadNowClientC();
+  Resource = AdcReadNowClientC;
+  ReadNow = AdcReadNowClientC;
+  
+  AdcReadNowClientC.AdcConfigure -> BatteryAdcP;
+}
diff --git a/tos/platforms/tmirws/sensors/WindVaneAdcP.nc b/tos/platforms/tmirws/sensors/WindVaneAdcP.nc
new file mode 100644 (file)
index 0000000..a80362b
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * Battery ADC reading.
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+#include "Msp430Adc12.h"
+
+module BatteryAdcP {
+  provides interface AdcConfigure<const msp430adc12_channel_config_t*>;
+}
+implementation {
+  /* TODO: The internal references are unsable, varying by more than 0.1V and
+   * jumping around.  The external reference of 2.50V seems stable.
+   */
+  const msp430adc12_channel_config_t config = {
+      inch: INPUT_CHANNEL_A0,
+#if 0 /* internal references unstable */
+      sref: REFERENCE_VREFplus_AVss,
+      ref2_5v: REFVOLT_LEVEL_1_5, /* REFVOLT_LEVEL_2_5, */
+#else /* external reference is stable */
+      sref: REFERENCE_VeREFplus_AVss,
+      ref2_5v: REFVOLT_LEVEL_1_5,
+#endif
+#if 0 /* clock source doesn't seem to affect stability */
+      adc12ssel: SHT_SOURCE_ADC12OSC,
+      adc12div: SHT_CLOCK_DIV_8,
+#else
+      adc12ssel: SHT_SOURCE_ACLK,
+      adc12div: SHT_CLOCK_DIV_1,
+#endif
+      sht: SAMPLE_HOLD_8_CYCLES,
+      sampcon_ssel: SAMPCON_SOURCE_ACLK,
+      sampcon_id: SAMPCON_CLOCK_DIV_1
+  };
+  
+  async command const msp430adc12_channel_config_t* AdcConfigure.getConfiguration()
+  {
+    return &config;
+  }
+}
diff --git a/tos/platforms/tmirws/sensors/WindVaneC.nc b/tos/platforms/tmirws/sensors/WindVaneC.nc
new file mode 100644 (file)
index 0000000..1ce247f
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * WindVane sensor
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+#include "WindVane.h"
+
+configuration WindVaneC {
+  provides interface ReadRef<wind_vane_t>;
+}
+implementation {
+  components WindVaneP;
+  ReadRef = WindVaneP;
+
+  components SoftwareRtcC as RtcC;
+  WindVaneP.Second -> RtcC;
+
+  components HalWindVaneC;
+  WindVaneP.Vane -> HalWindVaneC.AsyncGet;
+}
diff --git a/tos/platforms/tmirws/sensors/WindVaneP.nc b/tos/platforms/tmirws/sensors/WindVaneP.nc
new file mode 100644 (file)
index 0000000..a6976e9
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * Copyright (c) 2008, Titanium Mirror, Inc.
+ * 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 Titanium Mirror, Inc. 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.
+ */
+/**
+ * WindVane sensor
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+#include "WindVane.h"
+
+module WindVaneP {
+  provides interface ReadRef<wind_vane_t>;
+  uses {
+    interface Tick as Second;
+    interface AsyncGet<uint8_t> as Vane;
+  }
+}
+implementation {
+#define COMPASS_COUNT  32
+
+  wind_vane_t* m_data;
+  /* compass[0] = North, 0 degrees,
+   * compass(COMPASS_COUNT/2) = South, 180 degrees.
+   */
+  uint16_t compass[COMPASS_COUNT];
+
+
+  /*** Support functions ***/
+
+
+  /* return the number of positions clockwise along the compass from start
+   * to end.
+   */
+  uint8_t distance(uint8_t start, uint8_t end)
+  {
+    return (end > start) ? end - start : (end + COMPASS_COUNT) - start;
+  }
+
+  /* circularly examine compass, starting with pos+1, for the next compass
+   * position having a value of zero.
+   */
+  uint8_t nextNonZero(uint16_t* tc, uint8_t pos)
+  {
+    do {
+      pos = (pos + 1) % COMPASS_COUNT;
+    } while (tc[pos] == 0);
+    return pos;
+  }
+
+  bool isCompassEmpty(uint16_t* tc)
+  {
+    int i;
+
+    for (i = 0; i < COMPASS_COUNT; i++) {
+      if (tc[i])
+       break;
+    }
+    return (i == COMPASS_COUNT) ? TRUE : FALSE;
+  }
+
+  /* Reduce all compass headings equally until a compass heading has a value
+   * of zero.
+   */
+  void minimizeCompass(uint16_t* tc)
+  {
+    uint8_t min = 255;
+    int i;
+
+    for (i = 0; i < COMPASS_COUNT; i++) {
+      if (tc[i] < min)
+       min = tc[i];
+    }
+    if (min > 0) {
+      for (i = 0; i < COMPASS_COUNT; i++)
+       tc[i] -= min;
+    }
+  }
+
+  /* Locate the arc in which the compass[] has been constrained, defining
+   * that arc in m_data's left and right fields.  The compass arc is always
+   * defined clockwise, from left to right.
+   */
+  void findArc(uint16_t* tc)
+  {
+    uint8_t begin;
+    uint8_t save = 255;
+    uint8_t dist = 0;
+
+    begin = m_data->left = nextNonZero(tc, COMPASS_COUNT - 1);
+    do {
+      uint8_t d;
+
+      m_data->right = nextNonZero(tc, m_data->left);
+      d = distance(m_data->left, m_data->right);
+      if (d > dist) {
+       dist = d;
+       save = m_data->left;
+      }
+      m_data->left = m_data->right;
+    } while (m_data->left != begin);
+    m_data->right = save;
+    m_data->left = (save + dist) % COMPASS_COUNT;
+  }
+
+  void calcAvg(uint16_t* tc)
+  {
+    /* Find the average compass heading */
+    uint32_t sum = 0;
+    uint32_t count = 0;
+    uint32_t tmp = (m_data->right >= m_data->left) ? m_data->right :
+       m_data->right + COMPASS_COUNT;
+    int i;
+
+    for (i = m_data->left; i <= tmp; i++) {
+      uint8_t p = i % COMPASS_COUNT;
+
+      sum += tc[p] * i;
+      count += tc[p];
+    }
+    /* Reduce the sum by whole compass arcs, since only the remaining
+     * partial arc is of relevance.
+     */
+    tmp = COMPASS_COUNT * count;
+    while (sum >= tmp)
+      sum -= tmp;
+    m_data->avg = (sum == 0) ? 0 : (1800 / COMPASS_COUNT) * sum / count / 10;
+  }
+
+
+  /*** Method implementations ***/
+
+
+  async event void Second.fired()
+  {
+    const static uint8_t lookup[] = {
+      0x01, 0x03, 0x02, 0x06, 0x04, 0x0c, 0x08, 0x18,
+      0x10, 0x30, 0x20, 0x60, 0x40, 0xc0, 0x80, 0x81
+    };
+    uint8_t wind;
+    uint8_t i = 0;
+
+    wind = call Vane.get();
+    for (i = 0; i < sizeof(lookup); i++) {
+      if (lookup[i] == wind) {
+       compass[i]++;
+       return;
+      }
+    }
+  }
+
+  task void readCompass();
+
+  command error_t ReadRef.read(wind_vane_t* data)
+  {
+    if (!data)
+      return EINVAL;
+    else if (m_data)
+      return EBUSY;
+    else {
+      m_data = data;
+      post readCompass();
+      return SUCCESS;
+    }
+  }
+
+  task void readCompass()
+  {
+    uint16_t tc[COMPASS_COUNT];
+    wind_vane_t* data = m_data;
+
+    atomic {
+      memcpy(tc, compass, sizeof(compass));
+      memset(compass, 0, sizeof(compass));
+    }
+
+    minimizeCompass(tc);
+    if (isCompassEmpty(tc)) {
+      /* If there were no readings in the compass, or each compass heading has
+       * a number of readings equal to all other compass headings, we have an
+       * indeterminate wind direction.
+       */
+      m_data->left = m_data->avg = m_data->right = WINDVANE_NO_HEADING;
+    } else {
+      findArc(tc);
+      calcAvg(tc);
+
+      /* m_data's left, avg and right fields are currently represented in
+       * compass positions.  We must now convert those fields into units of
+       * angular degrees.
+       */
+      m_data->left = 1800U / COMPASS_COUNT * m_data->left / 10;
+      m_data->right = 1800U / COMPASS_COUNT * m_data->right / 10;
+    }
+
+    m_data = 0;
+    signal ReadRef.readDone(SUCCESS, data);
+  }
+}