components new Scp1000P();
ReadRef = Scp1000P;
- components MainC;
- MainC.SoftwareInit -> Scp1000P;
-
components Scp1000PinsC;
Scp1000P.CSn -> Scp1000PinsC.CSn;
Scp1000P.PD -> Scp1000PinsC.PD;
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;
{
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)
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);
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;
}
tstate = TIMER_NONE;
switch (tmp) {
case TIMER_POWER:
- call DRDY.disableRen();
counter = 0;
post check();
break;
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;
}
--- /dev/null
+/*
+ * 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;
+ }
+}