From: pipeng Date: Wed, 14 Mar 2007 03:25:05 +0000 (+0000) Subject: Change to follow TEP 109 . X-Git-Tag: tinyos/2.0.1~135 X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=commitdiff_plain;h=e1618063d0a4548a4dd9e0ae2b8c4f4b1a980fbe;p=tinyos-2.x.git Change to follow TEP 109 . --- diff --git a/tos/sensorboards/mts300/AccelConfigP.nc b/tos/sensorboards/mts300/AccelConfigP.nc index 6005babd..d5546411 100644 --- a/tos/sensorboards/mts300/AccelConfigP.nc +++ b/tos/sensorboards/mts300/AccelConfigP.nc @@ -1,44 +1,41 @@ -/* $Id$ - * Copyright (c) 2006 Intel Corporation - * All rights reserved. - * - * This file is distributed under the terms in the attached INTEL-LICENSE - * file. If you do not find these files, copies can be found by writing to - * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, - * 94704. Attention: Intel License Inquiry. - */ -/** - * Internal component for basicsb photodiode. Arbitrates access to the photo - * diode and automatically turns it on or off based on user requests. - * - * @author David Gay - */ - -#include "mts300.h" - -configuration AccelConfigP { - provides { - interface Init; - interface StdControl; - - interface Atm128AdcConfig as ConfigX; - interface Atm128AdcConfig as ConfigY; - interface ResourceConfigure as ResourceX; - interface ResourceConfigure as ResourceY; - } -} -implementation { - components AccelP, MicaBusC; - - Init = AccelP; - StdControl = AccelP; - - ConfigX = AccelP.ConfigX; - ConfigY = AccelP.ConfigY; - ResourceX = AccelP.ResourceX; - ResourceY = AccelP.ResourceY; - - AccelP.AccelPower -> MicaBusC.PW4; - AccelP.AccelAdcX -> MicaBusC.Adc3; - AccelP.AccelAdcY -> MicaBusC.Adc4; -} +/* $Id$ + * Copyright (c) 2006 Intel Corporation + * All rights reserved. + * + * This file is distributed under the terms in the attached INTEL-LICENSE + * file. If you do not find these files, copies can be found by writing to + * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, + * 94704. Attention: Intel License Inquiry. + */ +/** + * Internal component for basicsb photodiode. Arbitrates access to the photo + * diode and automatically turns it on or off based on user requests. + * + * @author David Gay + */ + +configuration AccelConfigP { + provides { + interface Resource[uint8_t client]; + interface Atm128AdcConfig as ConfigX; + interface Atm128AdcConfig as ConfigY; + } +} +implementation { + components AccelP, MicaBusC, new TimerMilliC() as WarmupTimer, + new RoundRobinArbiterC(UQ_ACCEL_RESOURCE) as Arbiter, + new SplitControlPowerManagerC() as PowerManager; + + Resource = Arbiter; + ConfigX = AccelP.ConfigX; + ConfigY = AccelP.ConfigY; + + PowerManager.ResourceDefaultOwner -> Arbiter; + PowerManager.ArbiterInfo -> Arbiter; + PowerManager.SplitControl -> AccelP; + + AccelP.Timer -> WarmupTimer; + AccelP.AccelPin -> MicaBusC.PW4; + AccelP.AccelAdcX -> MicaBusC.Adc3; + AccelP.AccelAdcY -> MicaBusC.Adc4; +} diff --git a/tos/sensorboards/mts300/AccelP.nc b/tos/sensorboards/mts300/AccelP.nc index cfe5c597..c3742a78 100644 --- a/tos/sensorboards/mts300/AccelP.nc +++ b/tos/sensorboards/mts300/AccelP.nc @@ -1,71 +1,76 @@ -#include "mts300.h" -#include "Timer.h" - -module AccelP -{ - provides interface Init; - provides interface StdControl; - - provides interface Atm128AdcConfig as ConfigX; - provides interface Atm128AdcConfig as ConfigY; - provides interface ResourceConfigure as ResourceX; - provides interface ResourceConfigure as ResourceY; - - uses interface GeneralIO as AccelPower; - uses interface MicaBusAdc as AccelAdcX; - uses interface MicaBusAdc as AccelAdcY; -} - -implementation -{ - command error_t Init.init() - { - call AccelPower.makeOutput(); - call AccelPower.clr(); - - return SUCCESS; - } - - command error_t StdControl.start() - { - call AccelPower.set(); - return SUCCESS; - } - - command error_t StdControl.stop() - { - call AccelPower.clr(); - call AccelPower.makeInput(); - - return SUCCESS; - } - - async command uint8_t ConfigX.getChannel() { - return call AccelAdcX.getChannel(); - } - - async command uint8_t ConfigX.getRefVoltage() { - return ATM128_ADC_VREF_OFF; - } - - async command uint8_t ConfigX.getPrescaler() { - return ATM128_ADC_PRESCALE; - } - - async command uint8_t ConfigY.getChannel() { - return call AccelAdcY.getChannel(); - } - - async command uint8_t ConfigY.getRefVoltage() { - return ATM128_ADC_VREF_OFF; - } - - async command uint8_t ConfigY.getPrescaler() { - return ATM128_ADC_PRESCALE; - } - - async command void ResourceX.configure() { } - async command void ResourceX.unconfigure() { } - async command void ResourceY.configure() { } - async command void ResourceY.unconfigure() {} -} \ No newline at end of file +/* $Id$ + * Copyright (c) 2006 Intel Corporation + * All rights reserved. + * + * This file is distributed under the terms in the attached INTEL-LICENSE + * file. If you do not find these files, copies can be found by writing to + * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, + * 94704. Attention: Intel License Inquiry. + */ +/** + * ADXL202JE accelerometer ADC configuration and power management. + * @author David Gay + */ +module AccelP +{ + provides { + interface SplitControl; + interface Atm128AdcConfig as ConfigX; + interface Atm128AdcConfig as ConfigY; + } + uses { + interface Timer; + interface GeneralIO as AccelPin; + interface MicaBusAdc as AccelAdcX; + interface MicaBusAdc as AccelAdcY; + } +} +implementation +{ + async command uint8_t ConfigX.getChannel() { + return call AccelAdcX.getChannel(); + } + + async command uint8_t ConfigX.getRefVoltage() { + return ATM128_ADC_VREF_OFF; + } + + async command uint8_t ConfigX.getPrescaler() { + return ATM128_ADC_PRESCALE; + } + + async command uint8_t ConfigY.getChannel() { + return call AccelAdcY.getChannel(); + } + + async command uint8_t ConfigY.getRefVoltage() { + return ATM128_ADC_VREF_OFF; + } + + async command uint8_t ConfigY.getPrescaler() { + return ATM128_ADC_PRESCALE; + } + + command error_t SplitControl.start() { + call AccelPin.makeOutput(); + call AccelPin.set(); + /* Startup time is 16.3ms for 0.1uF capacitors, + according to the ADXL202E data sheet */ + call Timer.startOneShot(17); + return SUCCESS; + } + + event void Timer.fired() { + signal SplitControl.startDone(SUCCESS); + } + + task void stopDone() { + call AccelPin.clr(); + signal SplitControl.stopDone(SUCCESS); + } + + command error_t SplitControl.stop() { + post stopDone(); + return SUCCESS; + } +} diff --git a/tos/sensorboards/mts300/MagConfigP.nc b/tos/sensorboards/mts300/MagConfigP.nc index 6f44f72f..411fb95d 100644 --- a/tos/sensorboards/mts300/MagConfigP.nc +++ b/tos/sensorboards/mts300/MagConfigP.nc @@ -11,7 +11,7 @@ * Internal component for basicsb photodiode. Arbitrates access to the photo * diode and automatically turns it on or off based on user requests. * - * @author David Gay + * @author Alif Chen */ #include "mts300.h" @@ -19,31 +19,32 @@ configuration MagConfigP { provides { - interface Init; - interface StdControl; interface Mag; - + interface Resource[uint8_t client]; interface Atm128AdcConfig as ConfigX; interface Atm128AdcConfig as ConfigY; - interface ResourceConfigure as ResourceX; - interface ResourceConfigure as ResourceY; } } implementation { - components MagP, MicaBusC, new Atm128I2CMasterC() as I2CPot; + components MagP, MicaBusC, new Atm128I2CMasterC() as I2CPot, + new TimerMilliC() as WarmupTimer, + new RoundRobinArbiterC(UQ_MAG_RESOURCE) as Arbiter, + new SplitControlPowerManagerC() as PowerManager; - Init = MagP; - StdControl = MagP; Mag = MagP; + Resource = Arbiter; ConfigX = MagP.ConfigX; ConfigY = MagP.ConfigY; - ResourceX = MagP.ResourceX; - ResourceY = MagP.ResourceY; + + PowerManager.ResourceDefaultOwner -> Arbiter; + PowerManager.ArbiterInfo -> Arbiter; + PowerManager.SplitControl -> MagP; MagP.I2CPacket -> I2CPot; - MagP.Resource -> I2CPot; + MagP.I2CResource -> I2CPot; + MagP.Timer -> WarmupTimer; MagP.MagPower -> MicaBusC.PW5; MagP.MagAdcX -> MicaBusC.Adc6; MagP.MagAdcY -> MicaBusC.Adc5; diff --git a/tos/sensorboards/mts300/MagP.nc b/tos/sensorboards/mts300/MagP.nc index a2fe23d9..0bef3947 100644 --- a/tos/sensorboards/mts300/MagP.nc +++ b/tos/sensorboards/mts300/MagP.nc @@ -4,44 +4,42 @@ module MagP { - provides interface Init; - provides interface StdControl; + provides interface SplitControl; provides interface Mag; provides interface Atm128AdcConfig as ConfigX; provides interface Atm128AdcConfig as ConfigY; - provides interface ResourceConfigure as ResourceX; - provides interface ResourceConfigure as ResourceY; + uses interface Timer; uses interface GeneralIO as MagPower; uses interface MicaBusAdc as MagAdcX; uses interface MicaBusAdc as MagAdcY; uses interface I2CPacket; - uses interface Resource; + uses interface Resource as I2CResource; } implementation { uint8_t gainData[2]; - command error_t Init.init() + command error_t SplitControl.start() { call MagPower.makeOutput(); - call MagPower.clr(); + call MagPower.set(); + call Timer.startOneShot(100); return SUCCESS; - } + } - command error_t StdControl.start() - { - call MagPower.set(); - return SUCCESS; + event void Timer.fired() { + signal SplitControl.startDone(SUCCESS); } - command error_t StdControl.stop() + command error_t SplitControl.stop() { call MagPower.clr(); call MagPower.makeInput(); + signal SplitControl.stopDone(SUCCESS); return SUCCESS; } @@ -49,19 +47,19 @@ implementation { gainData[0] = 1; // pot subaddr gainData[1] = val; // value to write - return call Resource.request(); + return call I2CResource.request(); } command error_t Mag.gainAdjustY(uint8_t val) { gainData[0] = 0; // pot subaddr gainData[1] = val; // value to write - return call Resource.request(); + return call I2CResource.request(); } /** * Resource request * */ - event void Resource.granted() + event void I2CResource.granted() { if ( call I2CPacket.write(0x3,TOS_MAG_POT_ADDR, 2, gainData) == SUCCESS) { @@ -79,7 +77,7 @@ implementation async event void I2CPacket.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) { - call Resource.release(); + call I2CResource.release(); if (gainData[0] ==1) { signal Mag.gainAdjustXDone(error); @@ -115,8 +113,12 @@ implementation return ATM128_ADC_PRESCALE; } - async command void ResourceX.configure() { } - async command void ResourceX.unconfigure() { } - async command void ResourceY.configure() { } - async command void ResourceY.unconfigure() {} + default event error_t Mag.gainAdjustXDone(bool result) + { + return result; + } + default event error_t Mag.gainAdjustYDone(bool result) + { + return result; + } } \ No newline at end of file diff --git a/tos/sensorboards/mts300/MicC.nc b/tos/sensorboards/mts300/MicC.nc index 0d096d3b..c4de5505 100644 --- a/tos/sensorboards/mts300/MicC.nc +++ b/tos/sensorboards/mts300/MicC.nc @@ -31,20 +31,17 @@ #include "mts300.h" generic configuration MicC() { - provides interface Init; - provides interface StdControl; provides interface Read; - provides interface Mic; - provides interface MicInterrupt; + provides interface MicSetting; } implementation { - components new AdcReadClientC(), MicDeviceP; + enum { + ID = unique(UQ_MIC_RESOURCE) + }; + components MicReadP, MicDeviceP, new AdcReadClientC(); - Init = MicDeviceP; - StdControl = MicDeviceP; - Read = AdcReadClientC; - Mic = MicDeviceP; - MicInterrupt = MicDeviceP; - AdcReadClientC.Atm128AdcConfig -> MicDeviceP; - AdcReadClientC.ResourceConfigure -> MicDeviceP; + Read = MicReadP.Read[ID]; + MicReadP.ActualRead[ID] -> AdcReadClientC; + AdcReadClientC.Atm128AdcConfig -> MicDeviceP.Atm128AdcConfig; + MicSetting = MicDeviceP; } diff --git a/tos/sensorboards/mts300/MicDeviceP.nc b/tos/sensorboards/mts300/MicDeviceP.nc index f2f37546..e12ac6a6 100644 --- a/tos/sensorboards/mts300/MicDeviceP.nc +++ b/tos/sensorboards/mts300/MicDeviceP.nc @@ -31,31 +31,32 @@ #include "I2C.h" configuration MicDeviceP { provides { - interface Init; - interface StdControl; - interface Mic; - interface MicInterrupt; - interface ResourceConfigure; + interface Resource[uint8_t client]; interface Atm128AdcConfig; + interface MicSetting; } } implementation { components MicP, MicaBusC, HplAtm128GeneralIOC as Pins, - HplAtm128InterruptC as IntPins, LedsC, NoLedsC, - new Atm128I2CMasterC() as I2CPot; + HplAtm128InterruptC as IntPins, + new Atm128I2CMasterC() as I2CPot, + new TimerMilliC() as WarmupTimer, + new RoundRobinArbiterC(UQ_MIC_RESOURCE) as Arbiter, + new SplitControlPowerManagerC() as PowerManager; - Init = MicP; - StdControl = MicP; - ResourceConfigure = MicP; + Resource = Arbiter; Atm128AdcConfig = MicP; - Mic = MicP; - MicInterrupt = MicP; + MicSetting = MicP; + + PowerManager.ResourceDefaultOwner -> Arbiter; + PowerManager.ArbiterInfo -> Arbiter; + PowerManager.SplitControl -> MicP; + MicP.Timer -> WarmupTimer; MicP.MicPower -> MicaBusC.PW3; MicP.MicMuxSel -> MicaBusC.PW6; MicP.MicAdc -> MicaBusC.Adc2; MicP.I2CPacket -> I2CPot; - MicP.Resource -> I2CPot; + MicP.I2CResource -> I2CPot; MicP.AlertInterrupt -> IntPins.Int7; - MicP.DebugLeds -> NoLedsC; } diff --git a/tos/sensorboards/mts300/MicP.nc b/tos/sensorboards/mts300/MicP.nc index 24e37477..4533631c 100644 --- a/tos/sensorboards/mts300/MicP.nc +++ b/tos/sensorboards/mts300/MicP.nc @@ -32,48 +32,49 @@ module MicP { - provides interface Init; - provides interface StdControl; - provides interface Mic; - provides interface MicInterrupt; - provides interface ResourceConfigure as MicResourceConfigure; + provides interface SplitControl; + provides interface MicSetting; provides interface Atm128AdcConfig as MicAtm128AdcConfig; - uses interface Leds as DebugLeds; + uses interface Timer; uses interface GeneralIO as MicPower; uses interface GeneralIO as MicMuxSel; uses interface MicaBusAdc as MicAdc; uses interface I2CPacket; - uses interface Resource; + uses interface Resource as I2CResource; uses interface HplAtm128Interrupt as AlertInterrupt; } implementation { uint8_t gainData[2]; - command error_t Init.init() + command error_t SplitControl.start() { + call AlertInterrupt.disable(); call MicPower.makeOutput(); - call MicPower.clr(); + call MicPower.set(); call MicMuxSel.makeOutput(); call MicMuxSel.clr(); - - call AlertInterrupt.disable(); - return SUCCESS; - } + + call MicSetting.muxSel(1); // Set the mux so that raw microhpone output is selected + call MicSetting.gainAdjust(64); // Set the gain of the microphone. - command error_t StdControl.start() - { - call MicPower.set(); + call Timer.startOneShot(1200); +// signal SplitControl.startDone(SUCCESS); return SUCCESS; } + + event void Timer.fired() { + signal SplitControl.startDone(SUCCESS); + } - command error_t StdControl.stop() + command error_t SplitControl.stop() { call AlertInterrupt.disable(); call MicPower.clr(); call MicPower.makeInput(); + signal SplitControl.stopDone(SUCCESS); return SUCCESS; } @@ -81,12 +82,11 @@ implementation * Resource request * */ - event void Resource.granted() + event void I2CResource.granted() { - call DebugLeds.led0Off(); if ( call I2CPacket.write(0x3,TOS_MIC_POT_ADDR, 2, gainData) == SUCCESS) { - call DebugLeds.led1On(); + return; }; } @@ -94,7 +94,7 @@ implementation * mic control * */ - command error_t Mic.muxSel(uint8_t sel) + command error_t MicSetting.muxSel(uint8_t sel) { if (sel == 0) { @@ -109,15 +109,14 @@ implementation return FAIL; } - command error_t Mic.gainAdjust(uint8_t val) + command error_t MicSetting.gainAdjust(uint8_t val) { - call DebugLeds.led0On(); gainData[0] = 0; // pot subaddr gainData[1] = val; // value to write - return call Resource.request(); + return call I2CResource.request(); } - command uint8_t Mic.readToneDetector() + command uint8_t MicSetting.readToneDetector() { bool bVal = call AlertInterrupt.getValue(); return bVal ? 1 : 0; @@ -127,26 +126,26 @@ implementation * mic interrupt control * */ - async command error_t MicInterrupt.enable() + async command error_t MicSetting.enable() { call AlertInterrupt.enable(); return SUCCESS; } - async command error_t MicInterrupt.disable() + async command error_t MicSetting.disable() { call AlertInterrupt.disable(); return SUCCESS; } - default async event error_t MicInterrupt.toneDetected() + default async event error_t MicSetting.toneDetected() { return SUCCESS; } async event void AlertInterrupt.fired() { - signal MicInterrupt.toneDetected(); + signal MicSetting.toneDetected(); } /** @@ -169,15 +168,6 @@ implementation return ATM128_ADC_PRESCALE; } - async command void MicResourceConfigure.configure() - { - call MicPower.set(); - } - - async command void MicResourceConfigure.unconfigure() - { -// call MicPower.clr(); - } /** * I2CPot2 * @@ -189,8 +179,7 @@ implementation async event void I2CPacket.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) { - call DebugLeds.led1Off(); - call Resource.release(); + call I2CResource.release(); return ; } } diff --git a/tos/sensorboards/mts300/PhotoC.nc b/tos/sensorboards/mts300/PhotoC.nc index 38f788ea..d6acb651 100644 --- a/tos/sensorboards/mts300/PhotoC.nc +++ b/tos/sensorboards/mts300/PhotoC.nc @@ -1,49 +1,25 @@ -/** - * Copyright (c) 2005-2006 Crossbow Technology, Inc. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written - * agreement is hereby granted, provided that the above copyright - * notice, the (updated) modification history and the author appear in - * all copies of this source code. - * - * Permission is also granted to distribute this software under the - * standard BSD license as contained in the TinyOS distribution. +/* $Id$ + * Copyright (c) 2006 Intel Corporation + * All rights reserved. * - * 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 HOLDERS OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA, - * OR PROFITS) 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. + * This file is distributed under the terms in the attached INTEL-LICENSE + * file. If you do not find these files, copies can be found by writing to + * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, + * 94704. Attention: Intel License Inquiry. */ - /* - * @author Hu Siquan - * - * $Id$ +/** + * Photodiode of the mts300 sensor board. + * + * @author David Gay */ #include "mts300.h" -generic configuration PhotoC() -{ +generic configuration PhotoC() { provides interface Read; - provides interface StdControl; - provides interface Init; } -implementation -{ - components new AdcReadClientC(), PhotoTempDeviceP; - - Init = PhotoTempDeviceP; - StdControl = PhotoTempDeviceP; +implementation { + components ArbitratedPhotoDeviceP; - Read = AdcReadClientC; - AdcReadClientC.Atm128AdcConfig -> PhotoTempDeviceP.PhotoAtm128AdcConfig; - AdcReadClientC.ResourceConfigure -> PhotoTempDeviceP.PhotoResourceConfigure; + Read = ArbitratedPhotoDeviceP.Read[unique(UQ_PHOTO_RESOURCE)]; } diff --git a/tos/sensorboards/mts300/PhotoTempP.nc b/tos/sensorboards/mts300/PhotoTempP.nc index dc4a6387..185f6f7a 100644 --- a/tos/sensorboards/mts300/PhotoTempP.nc +++ b/tos/sensorboards/mts300/PhotoTempP.nc @@ -1,194 +1,32 @@ -/** - * Copyright (c) 2005-2006 Crossbow Technology, Inc. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written - * agreement is hereby granted, provided that the above copyright - * notice, the (updated) modification history and the author appear in - * all copies of this source code. - * - * Permission is also granted to distribute this software under the - * standard BSD license as contained in the TinyOS distribution. - * - * 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 HOLDERS OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA, - * OR PROFITS) 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. - * - * @author Martin Turon - * @author Hu Siquan - * - * $Id$ - */ - -#include "Timer.h" - -module PhotoTempP -{ - provides - { - interface Init; //!< Standard Initialization - interface StdControl; //!< Start/Stop for Temp Sensor's Power Management - interface ResourceConfigure as TempResourceConfigure; - interface ResourceConfigure as PhotoResourceConfigure; - interface Atm128AdcConfig as TempAtm128AdcConfig; - interface Atm128AdcConfig as PhotoAtm128AdcConfig; - } - uses - { - interface GeneralIO as TempPower; - interface GeneralIO as LightPower; - interface MicaBusAdc as SensorAdc; - interface Leds as DebugLeds; - } -} -implementation -{ -/* - enum - { - STATE_IDLE = 0, - STATE_LIGHT_WARMING, //!< Powering on sensor - STATE_LIGHT_READY, //!< Power up of sensor complete - STATE_LIGHT_SAMPLING, //!< Sampling sensor - STATE_TEMP_WARMING, //!< Powering on sensor - STATE_TEMP_READY, //!< Power up of sensor complete - STATE_TEMP_SAMPLING, //!< Sampling sensor - }; - - /// Yes, this could be a simple uint8_t. There used to be more bits here, - /// but they were optimized out and removed. - union - { - uint8_t flat; - struct - { - uint8_t state : 4; //!< sensorboard state - } bits; - } g_flags; -*/ - - void inline TOSH_uwait(int u_sec) - { - /* In most cases (constant arg), the test is elided at compile-time */ - if (u_sec) - /* loop takes 4 cycles, aka 1us */ - asm volatile ( - "1: sbiw %0,1\n" - " brne 1b" : "+w" (u_sec)); - } - /** - * Initialize this component. Initialization should not assume that - * any component is running: init() cannot call any commands besides - * those that initialize other components. - * - */ - command error_t Init.init() - { - return SUCCESS; - } - - - /** - * Start the component and its subcomponents. - * - * @return SUCCESS if the component was successfully started. - */ - command error_t StdControl.start() - { - call TempPower.makeOutput(); - call TempPower.clr(); - call LightPower.makeOutput(); - call LightPower.clr(); - - return SUCCESS; - } - - /** - * Stop the component and pertinent subcomponents (not all - * subcomponents may be turned off due to wakeup timers, etc.). - * - * @return SUCCESS if the component was successfully stopped. - */ - command error_t StdControl.stop() - { - call TempPower.clr(); - call LightPower.clr(); - call TempPower.makeInput(); - call LightPower.makeInput(); - - return SUCCESS; - } - - async command uint8_t TempAtm128AdcConfig.getChannel() - { - return call SensorAdc.getChannel(); - } - - async command uint8_t TempAtm128AdcConfig.getRefVoltage() - { - return ATM128_ADC_VREF_OFF; - } - - async command uint8_t TempAtm128AdcConfig.getPrescaler() - { - return ATM128_ADC_PRESCALE; - } - - async command uint8_t PhotoAtm128AdcConfig.getChannel() - { - return call SensorAdc.getChannel(); - } - - async command uint8_t PhotoAtm128AdcConfig.getRefVoltage() - { - return ATM128_ADC_VREF_OFF; - } - - async command uint8_t PhotoAtm128AdcConfig.getPrescaler() - { - return ATM128_ADC_PRESCALE; - } - - async command void TempResourceConfigure.configure() - { - call DebugLeds.led0On(); - call LightPower.clr(); - call LightPower.makeInput(); - call TempPower.makeOutput(); - call TempPower.set(); - TOSH_uwait(1000); - } - - async command void TempResourceConfigure.unconfigure() - { - call DebugLeds.led0Off(); - call TempPower.clr(); - call TempPower.makeInput(); - } - - /** Turns on the light sensor and turns the thermistor off. */ - async command void PhotoResourceConfigure.configure() - { - call DebugLeds.led1On(); - call TempPower.clr(); - call TempPower.makeInput(); - call LightPower.makeOutput(); - call LightPower.set(); - TOSH_uwait(1000); - } - - async command void PhotoResourceConfigure.unconfigure() - { - call DebugLeds.led1Off(); - call LightPower.clr(); - call LightPower.makeInput(); - } -} +/* $Id$ + * Copyright (c) 2007 Intel Corporation + * All rights reserved. + * + * This file is distributed under the terms in the attached INTEL-LICENSE + * file. If you do not find these files, copies can be found by writing to + * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, + * 94704. Attention: Intel License Inquiry. + */ +/** + * MTS300 photo and temp sensor ADC configuration. + * @author David Gay + */ +module PhotoTempP +{ + provides interface Atm128AdcConfig; + uses interface MicaBusAdc as PhotoTempAdc; +} +implementation +{ + async command uint8_t Atm128AdcConfig.getChannel() { + return call PhotoTempAdc.getChannel(); + } + + async command uint8_t Atm128AdcConfig.getRefVoltage() { + return ATM128_ADC_VREF_OFF; + } + + async command uint8_t Atm128AdcConfig.getPrescaler() { + return ATM128_ADC_PRESCALE; + } +} diff --git a/tos/sensorboards/mts300/SensorMts300C.nc b/tos/sensorboards/mts300/SensorMts300C.nc index 12e093b2..8cd1f253 100644 --- a/tos/sensorboards/mts300/SensorMts300C.nc +++ b/tos/sensorboards/mts300/SensorMts300C.nc @@ -33,13 +33,12 @@ generic configuration SensorMts300C() { provides { - interface Init; //!< Standard Initialization - interface StdControl; //!< Start/Stop for Power Management + interface Mts300Sounder as Sounder; //!< sounder interface Read as Vref; //!< voltage interface Read as Temp; //!< Thermister interface Read as Light; //!< Photo sensor interface Read as Microphone; //!< Mic sensor - interface Read as AccelX; //!< Accelerometer sensor + interface Read as AccelX; //!< Accelerometer sensor interface Read as AccelY; //!< Accelerometer sensor interface Read as MagX; //!< magnetometer sensor interface Read as MagY; //!< magnetometer sensor @@ -47,48 +46,23 @@ generic configuration SensorMts300C() } implementation { - components SensorMts300P, HplAtm128GeneralIOC as IO, + components SounderC, new VoltageC(), + new AccelXC(), + new AccelYC(), new PhotoC(), new TempC(), new MicC(), - new MagC(), - new AccelC(), - new TimerMilliC() as WarmUpTimer; + new MagXC(), + new MagYC(); - Init = SensorMts300P.Init; - Init = PhotoC.Init; - Init = MicC.Init; - StdControl = SensorMts300P.StdControl; - Vref = SensorMts300P.Vref; - Temp = SensorMts300P.Temp; - Light = SensorMts300P.Light; - Microphone = SensorMts300P.Microphone; - AccelX = SensorMts300P.AccelX; - AccelY = SensorMts300P.AccelY; - MagX = SensorMts300P.MagX; - MagY = SensorMts300P.MagY; - - SensorMts300P.WarmUpTimer -> WarmUpTimer; - - SensorMts300P.VrefRead -> VoltageC.Read; - SensorMts300P.PhotoControl -> PhotoC.StdControl; - SensorMts300P.TempRead -> TempC.Read; - SensorMts300P.LightRead -> PhotoC.Read; - SensorMts300P.LightPower -> IO.PortE5; - SensorMts300P.TempPower -> IO.PortE6; - - SensorMts300P.MicControl -> MicC.StdControl; - SensorMts300P.Mic -> MicC.Mic; - SensorMts300P.MicRead -> MicC.Read; - - SensorMts300P.MagControl -> MagC.StdControl; - SensorMts300P.Mag -> MagC.Mag; - SensorMts300P.MagXRead -> MagC.MagX; - SensorMts300P.MagYRead -> MagC.MagY; - - SensorMts300P.AccelControl -> AccelC.StdControl; - SensorMts300P.AccelXRead -> AccelC.AccelX; - SensorMts300P.AccelYRead -> AccelC.AccelY; - + Sounder = SounderC; + Vref = VoltageC; + Temp = TempC; + Light = PhotoC; + Microphone = MicC; + AccelX = AccelXC; + AccelY = AccelYC; + MagX = MagXC; + MagY = MagYC; } diff --git a/tos/sensorboards/mts300/SounderC.nc b/tos/sensorboards/mts300/SounderC.nc index 52ec479c..a121e89e 100644 --- a/tos/sensorboards/mts300/SounderC.nc +++ b/tos/sensorboards/mts300/SounderC.nc @@ -1,45 +1,12 @@ -/** - * Copyright (c) 2005-2006 Crossbow Technology, Inc. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written - * agreement is hereby granted, provided that the above copyright - * notice, the (updated) modification history and the author appear in - * all copies of this source code. - * - * Permission is also granted to distribute this software under the - * standard BSD license as contained in the TinyOS distribution. - * - * 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 HOLDERS OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA, - * OR PROFITS) 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. - */ - /* - * @author Hu Siquan - * - * $Id$ - */ - -#include "mts300.h" - configuration SounderC { - provides interface Init; - provides interface StdControl; + provides interface Mts300Sounder; } implementation { - components SounderP, MicaBusC; + components SounderP, new TimerMilliC(), MicaBusC; - Init = SounderP; - StdControl = SounderP; + Mts300Sounder = SounderP; + SounderP.Timer -> TimerMilliC; SounderP.SounderPin -> MicaBusC.PW2; } diff --git a/tos/sensorboards/mts300/SounderP.nc b/tos/sensorboards/mts300/SounderP.nc index 7b71bc05..e5f2c064 100644 --- a/tos/sensorboards/mts300/SounderP.nc +++ b/tos/sensorboards/mts300/SounderP.nc @@ -1,65 +1,31 @@ -/** - * Copyright (c) 2005-2006 Crossbow Technology, Inc. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written - * agreement is hereby granted, provided that the above copyright - * notice, the (updated) modification history and the author appear in - * all copies of this source code. - * - * Permission is also granted to distribute this software under the - * standard BSD license as contained in the TinyOS distribution. - * - * 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 HOLDERS OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA, - * OR PROFITS) 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. - * - * @author Hu Siquan - * - * $Id$ - */ - -#include "mts300.h" - -module SounderP +module SounderP { - provides interface Init; - provides interface StdControl; - uses interface GeneralIO as SounderPin; + provides interface Mts300Sounder; + uses { + interface Timer; + interface GeneralIO as SounderPin; + } } - -implementation +implementation { - command error_t Init.init() - { -#if SOUNDER - call SounderPin.makeOutput(); - call SounderPin.clr(); -#endif - return SUCCESS; - } + command void Mts300Sounder.beep(uint16_t length) { + if (call Timer.isRunning()) + { + uint32_t remaining = call Timer.getdt(), + elapsed = call Timer.getNow() - call Timer.gett0(); - command error_t StdControl.start() - { -#if SOUNDER + /* If more time left than we are requesting, just exit */ + if (remaining > elapsed && (remaining - elapsed) > length) + return; + + /* Override timer with new duration */ + } + call Timer.startOneShot(length); + call SounderPin.makeOutput(); call SounderPin.set(); -#endif - return SUCCESS; } - command error_t StdControl.stop() - { -#if SOUNDER + event void Timer.fired() { call SounderPin.clr(); -#endif - return SUCCESS; } } diff --git a/tos/sensorboards/mts300/TempC.nc b/tos/sensorboards/mts300/TempC.nc index 7dc6ad62..03eaf4e9 100644 --- a/tos/sensorboards/mts300/TempC.nc +++ b/tos/sensorboards/mts300/TempC.nc @@ -1,42 +1,25 @@ -/** - * Copyright (c) 2005-2006 Crossbow Technology, Inc. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose, without fee, and without written - * agreement is hereby granted, provided that the above copyright - * notice, the (updated) modification history and the author appear in - * all copies of this source code. - * - * Permission is also granted to distribute this software under the - * standard BSD license as contained in the TinyOS distribution. - * - * 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 HOLDERS OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA, - * OR PROFITS) 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. - */ - /* - * @author Hu Siquan - * - * $Id$ - */ - -#include "mts300.h" - -generic configuration TempC() { - provides interface Read; -} -implementation { - components new AdcReadClientC(), PhotoTempDeviceP; - - Read = AdcReadClientC; - AdcReadClientC.Atm128AdcConfig -> PhotoTempDeviceP.TempAtm128AdcConfig; - AdcReadClientC.ResourceConfigure -> PhotoTempDeviceP.TempResourceConfigure; -} +/* $Id$ + * Copyright (c) 2006 Intel Corporation + * All rights reserved. + * + * This file is distributed under the terms in the attached INTEL-LICENSE + * file. If you do not find these files, copies can be found by writing to + * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, + * 94704. Attention: Intel License Inquiry. + */ +/** + * Photodiode of the mts300 sensor board. + * + * @author David Gay + */ + +#include "mts300.h" + +generic configuration TempC() { + provides interface Read; +} +implementation { + components ArbitratedTempDeviceP; + + Read = ArbitratedTempDeviceP.Read[unique(UQ_TEMP_RESOURCE)]; +} diff --git a/tos/sensorboards/mts300/mts300.h b/tos/sensorboards/mts300/mts300.h index 9424ae28..d2add79e 100644 --- a/tos/sensorboards/mts300/mts300.h +++ b/tos/sensorboards/mts300/mts300.h @@ -35,8 +35,12 @@ #define SOUNDER 1 #endif -#define MTS3X0_PHOTO_TEMP "mts300.photo.temp" -#define MTS3X0_MAG_RESOURCE "mts300.mag" +#define UQ_ACCEL_RESOURCE "mts300.accel" +#define UQ_PHOTO_RESOURCE "mts300.photo" +#define UQ_TEMP_RESOURCE "mts300.temp" +#define UQ_PHOTOTEMP_RESOURCE "mts300.phototemp" +#define UQ_MIC_RESOURCE "mts300.microphone" +#define UQ_MAG_RESOURCE "mts300.mag" enum {