]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Reorganize scp1000 driver code.
authorsmckown <smckown@4bc1554a-c7f2-4f65-a403-e0be01f0239c>
Wed, 5 Aug 2009 02:57:08 +0000 (02:57 +0000)
committerR. Steve McKown <rsmckown@gmail.com>
Tue, 1 Dec 2009 03:01:42 +0000 (20:01 -0700)
The Scp1000P module now only uses GeneralIO and is not tied to anything msp430
specific.  The msp430 specific bits are in the platform dependent file
Scp1000PinsP.

tos/chips/scp1000/Scp1000C.nc
tos/chips/scp1000/Scp1000P.nc
tos/platforms/tmirws/chips/scp1000/Scp1000PinsC.nc
tos/platforms/tmirws/chips/scp1000/Scp1000PinsP.nc [new file with mode: 0644]

index 1744de4ab43cd1bbb6aeac326d96f9b018ff92cc..d84a665179d67036197f3f29c3892e9c7bd6d4be 100644 (file)
@@ -44,9 +44,6 @@ implementation {
   components new Scp1000P();
   ReadRef = Scp1000P;
 
-  components MainC;
-  MainC.SoftwareInit -> Scp1000P;
-
   components Scp1000PinsC;
   Scp1000P.CSn -> Scp1000PinsC.CSn;
   Scp1000P.PD -> Scp1000PinsC.PD;
index 670d3d8e5a661de4118419329938de5db78c0a26..7d9789f7f6d20184cddfa0c185721fb4bb890cab 100644 (file)
  
 generic module Scp1000P() @safe()
 {
-  provides {
-    interface Init;
-    interface ReadRef<scp1000_t>;
-  }
+  provides interface ReadRef<scp1000_t>;
   uses {
-    /* TODO: too platform specific, but need for disableRen() */
-    interface HplMsp430GeneralIO as CSn;
-    interface HplMsp430GeneralIO as PD;
-    interface HplMsp430GeneralIO as DRDY;
+    interface GeneralIO as CSn;
+    interface GeneralIO as PD;
+    interface GeneralIO as DRDY;
     interface GpioInterrupt as IntDRDY;
     interface Resource;
     interface SpiByte;
@@ -113,39 +109,12 @@ implementation
   {
     scp1000_t* tmp = m_ptr;
 
-    call DRDY.enableRen();
     call PD.set();
     call Resource.release();
     m_ptr = 0;
     signal ReadRef.readDone(error, tmp);
   }
 
-  command error_t Init.init()
-  {
-    /* TODO: tmicore MotePlatformC sets the pins we use up in a way that isn't
-     * ideal for our use, but changing them requires that we use platform
-     * dependent code.  Find a way to fix this.
-     *
-     * When the part is 'soldered' onto the board, aka tmirws, then
-     * MotePlatform can set it and be done, mostly.  However, DRDY will use
-     * extra energy since with the scp1000 on it pulls DRDY low most of the
-     * time, causing current through the enabled pull-up.  Best to turn it
-     * off after PD is enabled and on before PD is disabled.
-     */
-    call CSn.selectIOFunc();
-    call CSn.disableRen();
-    call CSn.set();
-    call CSn.makeOutput();
-    call PD.selectIOFunc();
-    call PD.disableRen();
-    call PD.set();
-    call PD.makeOutput();
-    call DRDY.selectIOFunc();
-    call DRDY.enableRen();
-    call DRDY.makeInput();
-    return SUCCESS;
-  }
-
   command error_t ReadRef.read(scp1000_t* ptr)
   {
     if (m_ptr || !ptr)
@@ -184,6 +153,15 @@ implementation
       return;
     }
 
+    /* We could use the low noise configuration by also doing:
+     * writeByte(0x2d, 0x03);
+     * wait_ms(100);
+     * writeByte(OPERATION, 0);
+     * wait_ms(10);
+     * writeByte(OPERATION, 0x0a); -- 0x0a is high resolution mode
+     * wait_ms(100);
+     */
+
     /* Initiate a reading.  DRDY will assert when done, ~ 500ms from now */
     tstate = TIMER_DRDY;
     call Timer.startOneShot(1024);
@@ -202,9 +180,9 @@ implementation
   task void results()
   {
     call Timer.stop();
-    m_ptr->temp = readWord(TEMPOUT);
+    m_ptr->temp = readWord(TEMPOUT); /* 20ths of a degree C */
     m_ptr->pressure = (uint32_t)readByte(DATARD8) << 16;
-    m_ptr->pressure += readWord(DATARD16);
+    m_ptr->pressure += readWord(DATARD16); /* 4ths of a Pa? */
     signalDone(SUCCESS);
     return;
   }
@@ -216,7 +194,6 @@ implementation
     tstate = TIMER_NONE;
     switch (tmp) {
       case TIMER_POWER:
-       call DRDY.disableRen();
        counter = 0;
        post check();
        break;
index 95d36e36e42b33018f7e1ef3e1c3bfe56dcc792e..da2fb01e896aa4173f86319cb178d96c1018ec5e 100644 (file)
  
 configuration Scp1000PinsC {
   provides {
-    interface HplMsp430GeneralIO as CSn;
-    interface HplMsp430GeneralIO as PD;
-    interface HplMsp430GeneralIO as DRDY;
+    interface GeneralIO as CSn;
+    interface GeneralIO as PD;
+    interface GeneralIO as DRDY;
     interface GpioInterrupt as IntDRDY;
   }
 }
 implementation {
-#if 0
   components new Msp430GpioC() as CSn_;
   CSn = CSn_.GeneralIO;
 
-  components new Msp430GpioC() as PD_;
-  PD = PD_.GeneralIO;
-
   components new Msp430GpioC() as DRDY_;
   DRDY = DRDY_.GeneralIO;
-#endif
 
   components new Msp430InterruptC() as IntDRDY_;
   IntDRDY = IntDRDY_.Interrupt;
 
   components HplMsp430GeneralIOC as IOC;
-#if 0
   CSn_.HplGeneralIO -> IOC.Port43;
-  PD_.HplGeneralIO -> IOC.Port42;
   DRDY_.HplGeneralIO -> IOC.Port26;
-#else
-  CSn = IOC.Port43;
-  PD = IOC.Port42;
-  DRDY = IOC.Port26;
-#endif
 
   components HplMsp430InterruptC as IntC;
   IntDRDY_.HplInterrupt -> IntC.Port26;
+
+  components new Scp1000PinsP() as PinsP;
+  PD = PinsP.PD;
+  PinsP.CSn -> IOC.Port43;
+  PinsP._PD -> IOC.Port42;
+  PinsP.DRDY -> IOC.Port26;
+
+  components MainC;
+  MainC.SoftwareInit -> PinsP;
 }
diff --git a/tos/platforms/tmirws/chips/scp1000/Scp1000PinsP.nc b/tos/platforms/tmirws/chips/scp1000/Scp1000PinsP.nc
new file mode 100644 (file)
index 0000000..82d25a1
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * 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 the Technische Universität Berlin nor the names
+ *   of its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/**
+ * Platform dependent scp1000 pin initialization.
+ * 
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+
+#include "Scp1000.h"
+generic module Scp1000PinsP() @safe()
+{
+  provides {
+    interface Init;
+    interface GeneralIO as PD;
+  }
+  uses {
+    interface HplMsp430GeneralIO as CSn;
+    interface HplMsp430GeneralIO as _PD;
+    interface HplMsp430GeneralIO as DRDY;
+  }
+}
+implementation
+{
+  command error_t Init.init()
+  {
+    call CSn.selectIOFunc();
+    call CSn.disableRen();
+    call CSn.set();
+    call CSn.makeOutput();
+    call _PD.selectIOFunc();
+    call _PD.disableRen();
+    call _PD.set();
+    call _PD.makeOutput();
+    call DRDY.selectIOFunc();
+    call DRDY.enableRen();
+    call DRDY.makeInput();
+    return SUCCESS;
+  }
+
+  async command void PD.set()
+  {
+    /* When we turn off the device we need to enable the pull-up so the pin
+     * doesn't float and cause unwanted current consumption.
+     */
+    call DRDY.enableRen();
+    call _PD.set();
+  }
+
+  async command void PD.clr()
+  {
+    /* When the device is powered up, we no longer need the pull-up.  This is
+     * a little bit pedantic, as the unit won't be on that long, but having
+     * the pull-up on does increase power consumption while DRDY is low during
+     * the process of taking a reading.  On the order of 2.5/35K = 71uA.
+     */
+    call _PD.clr();
+    call DRDY.disableRen();
+  }
+
+  async command void PD.toggle()
+  {
+  }
+
+  async command bool PD.get()
+  {
+    return call _PD.get();
+  }
+
+  async command void PD.makeInput()
+  {
+  }
+
+  async command bool PD.isInput()
+  {
+    return FALSE;
+  }
+
+  async command void PD.makeOutput()
+  {
+  }
+
+  async command bool PD.isOutput()
+  {
+    return TRUE;
+  }
+}