From c3bff1b29571c9e343baf24ec12b4b426ec30df9 Mon Sep 17 00:00:00 2001 From: smckown Date: Wed, 5 Aug 2009 02:57:08 +0000 Subject: [PATCH] Reorganize scp1000 driver code. 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 | 3 - tos/chips/scp1000/Scp1000P.nc | 53 +++----- .../tmirws/chips/scp1000/Scp1000PinsC.nc | 27 ++--- .../tmirws/chips/scp1000/Scp1000PinsP.nc | 114 ++++++++++++++++++ 4 files changed, 141 insertions(+), 56 deletions(-) create mode 100644 tos/platforms/tmirws/chips/scp1000/Scp1000PinsP.nc diff --git a/tos/chips/scp1000/Scp1000C.nc b/tos/chips/scp1000/Scp1000C.nc index 1744de4a..d84a6651 100644 --- a/tos/chips/scp1000/Scp1000C.nc +++ b/tos/chips/scp1000/Scp1000C.nc @@ -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; diff --git a/tos/chips/scp1000/Scp1000P.nc b/tos/chips/scp1000/Scp1000P.nc index 670d3d8e..7d9789f7 100644 --- a/tos/chips/scp1000/Scp1000P.nc +++ b/tos/chips/scp1000/Scp1000P.nc @@ -37,15 +37,11 @@ generic module Scp1000P() @safe() { - provides { - interface Init; - interface ReadRef; - } + provides interface ReadRef; 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; diff --git a/tos/platforms/tmirws/chips/scp1000/Scp1000PinsC.nc b/tos/platforms/tmirws/chips/scp1000/Scp1000PinsC.nc index 95d36e36..da2fb01e 100644 --- a/tos/platforms/tmirws/chips/scp1000/Scp1000PinsC.nc +++ b/tos/platforms/tmirws/chips/scp1000/Scp1000PinsC.nc @@ -35,38 +35,35 @@ 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 index 00000000..82d25a1f --- /dev/null +++ b/tos/platforms/tmirws/chips/scp1000/Scp1000PinsP.nc @@ -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 + */ + +#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; + } +} -- 2.39.2