From 41addd09d398313e24500239334bd68c599250f9 Mon Sep 17 00:00:00 2001 From: pipeng Date: Thu, 15 Feb 2007 10:33:37 +0000 Subject: [PATCH] Add mic and mag driver . --- tos/sensorboards/mts300/AccelC.nc | 57 ++++++ tos/sensorboards/mts300/Mag.nc | 71 +++++++ tos/sensorboards/mts300/MagC.nc | 59 ++++++ tos/sensorboards/mts300/MagConfigP.nc | 50 +++++ tos/sensorboards/mts300/MagP.nc | 122 ++++++++++++ tos/sensorboards/mts300/Mic.nc | 72 +++++++ tos/sensorboards/mts300/MicC.nc | 50 +++++ tos/sensorboards/mts300/MicDeviceP.nc | 61 ++++++ tos/sensorboards/mts300/MicInterrupt.nc | 67 +++++++ tos/sensorboards/mts300/MicP.nc | 201 ++++++++++++++++++++ tos/sensorboards/mts300/PhotoTempDeviceP.nc | 51 +++++ tos/sensorboards/mts300/TempC.nc | 42 ++++ 12 files changed, 903 insertions(+) create mode 100644 tos/sensorboards/mts300/AccelC.nc create mode 100644 tos/sensorboards/mts300/Mag.nc create mode 100644 tos/sensorboards/mts300/MagC.nc create mode 100644 tos/sensorboards/mts300/MagConfigP.nc create mode 100644 tos/sensorboards/mts300/MagP.nc create mode 100644 tos/sensorboards/mts300/Mic.nc create mode 100644 tos/sensorboards/mts300/MicC.nc create mode 100644 tos/sensorboards/mts300/MicDeviceP.nc create mode 100644 tos/sensorboards/mts300/MicInterrupt.nc create mode 100644 tos/sensorboards/mts300/MicP.nc create mode 100644 tos/sensorboards/mts300/PhotoTempDeviceP.nc create mode 100644 tos/sensorboards/mts300/TempC.nc diff --git a/tos/sensorboards/mts300/AccelC.nc b/tos/sensorboards/mts300/AccelC.nc new file mode 100644 index 00000000..00102abb --- /dev/null +++ b/tos/sensorboards/mts300/AccelC.nc @@ -0,0 +1,57 @@ +// $Id$ + +/* tab:4 + * "Copyright (c) 2000-2003 The Regents of the University of California. + * 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 following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Copyright (c) 2002-2003 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. + */ +#include "mts300.h" + +generic configuration AccelC () +{ + provides interface Init; + provides interface StdControl; + provides interface Read as AccelX; + provides interface Read as AccelY; +} +implementation +{ + components AccelConfigP, + new AdcReadClientC() as AdcX, + new AdcReadClientC() as AdcY; + + Init = AccelConfigP; + StdControl = AccelConfigP; + + AccelX = AdcX; + AdcX.Atm128AdcConfig -> AccelConfigP.ConfigX; + AdcX.ResourceConfigure -> AccelConfigP.ResourceX; + + AccelY = AdcY; + AdcY.Atm128AdcConfig -> AccelConfigP.ConfigY; + AdcY.ResourceConfigure -> AccelConfigP.ResourceY; +} + diff --git a/tos/sensorboards/mts300/Mag.nc b/tos/sensorboards/mts300/Mag.nc new file mode 100644 index 00000000..676e6349 --- /dev/null +++ b/tos/sensorboards/mts300/Mag.nc @@ -0,0 +1,71 @@ +// $Id$ + +/* tab:4 + * "Copyright (c) 2000-2003 The Regents of the University of California. + * 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 following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Copyright (c) 2002-2003 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. + */ + +/* + * Authors: Alec Woo + * Date lase modified: 8/20/02 + * + * The MagSetting inteface provides an asynchronous mechanism for + * setting the gain offset for the Magnetometer on the mica sensorboard. + * This is particularly useful in calibrating the offset of the Magnetometer + * such that X and Y axis can stay in the center for idle signals. + * If not calibrated, the data you get may rail. (railing means + * the data either stays at the maximum (~785) or minimum (~240)). + * + * The gain adjust has 256 steps ranging from 0 to 255. + * + */ + +/** + * @author Alec Woo + */ + +interface Mag { + /* Effects: adjust pot setting on the X axis of the magnetometer. + * Returns: return SUCCESS of FAILED. + */ + command error_t gainAdjustX(uint8_t val); + + /* Effects: adjust pot setting on the Y axis of the magnetometer. + * Returns: return SUCCESS of FAILED. + */ + command error_t gainAdjustY(uint8_t val); + + /* Pot adjustment on the X axis of the magnetometer is finished. + * Returns: return SUCCESS. + */ + event error_t gainAdjustXDone(bool result); + + /* Pot adjustment on the Y axis of the magnetometer is finished. + * Returns: return SUCCESS. + */ + event error_t gainAdjustYDone(bool result); +} diff --git a/tos/sensorboards/mts300/MagC.nc b/tos/sensorboards/mts300/MagC.nc new file mode 100644 index 00000000..0945d43d --- /dev/null +++ b/tos/sensorboards/mts300/MagC.nc @@ -0,0 +1,59 @@ +// $Id$ + +/* tab:4 + * "Copyright (c) 2000-2003 The Regents of the University of California. + * 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 following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Copyright (c) 2002-2003 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. + */ +#include "mts300.h" + +generic configuration MagC () +{ + provides interface Init; + provides interface StdControl; + provides interface Read as MagX; + provides interface Read as MagY; + provides interface Mag; +} +implementation +{ + components MagConfigP, + new AdcReadClientC() as AdcX, + new AdcReadClientC() as AdcY; + + Init = MagConfigP; + StdControl = MagConfigP; + Mag = MagConfigP; + + MagX = AdcX; + AdcX.Atm128AdcConfig -> MagConfigP.ConfigX; + AdcX.ResourceConfigure -> MagConfigP.ResourceX; + + MagY = AdcY; + AdcY.Atm128AdcConfig -> MagConfigP.ConfigY; + AdcY.ResourceConfigure -> MagConfigP.ResourceY; +} + diff --git a/tos/sensorboards/mts300/MagConfigP.nc b/tos/sensorboards/mts300/MagConfigP.nc new file mode 100644 index 00000000..6f44f72f --- /dev/null +++ b/tos/sensorboards/mts300/MagConfigP.nc @@ -0,0 +1,50 @@ +/* $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" +#include "I2C.h" + +configuration MagConfigP { + provides { + interface Init; + interface StdControl; + interface Mag; + + interface Atm128AdcConfig as ConfigX; + interface Atm128AdcConfig as ConfigY; + interface ResourceConfigure as ResourceX; + interface ResourceConfigure as ResourceY; + } +} +implementation { + components MagP, MicaBusC, new Atm128I2CMasterC() as I2CPot; + + Init = MagP; + StdControl = MagP; + Mag = MagP; + + ConfigX = MagP.ConfigX; + ConfigY = MagP.ConfigY; + ResourceX = MagP.ResourceX; + ResourceY = MagP.ResourceY; + + MagP.I2CPacket -> I2CPot; + MagP.Resource -> I2CPot; + + 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 new file mode 100644 index 00000000..a2fe23d9 --- /dev/null +++ b/tos/sensorboards/mts300/MagP.nc @@ -0,0 +1,122 @@ +#include "mts300.h" +#include "Timer.h" +#include "I2C.h" + +module MagP +{ + provides interface Init; + provides interface StdControl; + 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 GeneralIO as MagPower; + uses interface MicaBusAdc as MagAdcX; + uses interface MicaBusAdc as MagAdcY; + uses interface I2CPacket; + uses interface Resource; +} + +implementation +{ + uint8_t gainData[2]; + + command error_t Init.init() + { + call MagPower.makeOutput(); + call MagPower.clr(); + + return SUCCESS; + } + + command error_t StdControl.start() + { + call MagPower.set(); + return SUCCESS; + } + + command error_t StdControl.stop() + { + call MagPower.clr(); + call MagPower.makeInput(); + + return SUCCESS; + } + + command error_t Mag.gainAdjustX(uint8_t val) + { + gainData[0] = 1; // pot subaddr + gainData[1] = val; // value to write + return call Resource.request(); + } + command error_t Mag.gainAdjustY(uint8_t val) + { + gainData[0] = 0; // pot subaddr + gainData[1] = val; // value to write + return call Resource.request(); + } + /** + * Resource request + * + */ + event void Resource.granted() + { + if ( call I2CPacket.write(0x3,TOS_MAG_POT_ADDR, 2, gainData) == SUCCESS) + { + return ; + } + } + /** + * I2CPot2 + * + */ + async event void I2CPacket.readDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) + { + return ; + } + + async event void I2CPacket.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) + { + call Resource.release(); + if (gainData[0] ==1) + { + signal Mag.gainAdjustXDone(error); + } + if (gainData[0] ==0) + { + signal Mag.gainAdjustYDone(error); + } + return ; + } + + async command uint8_t ConfigX.getChannel() { + return call MagAdcX.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 MagAdcY.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 diff --git a/tos/sensorboards/mts300/Mic.nc b/tos/sensorboards/mts300/Mic.nc new file mode 100644 index 00000000..8c68a64b --- /dev/null +++ b/tos/sensorboards/mts300/Mic.nc @@ -0,0 +1,72 @@ +// $Id$ + +/* tab:4 + * "Copyright (c) 2000-2003 The Regents of the University of California. + * 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 following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Copyright (c) 2002-2003 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. + */ + +/* + * Authors: Alec Woo + * Date last modified: 8/20/02 + * + * The microphone on the mica sensor board has two methods for control and + * one method to read the binary output of the tone detector. (Note: The tone + * detector's binary output can be configured as an interrupt. Please see MicInterrupt.ti) + * + * muxSel allows users to switch the ADC to sample from phase lock loop output of + * the tone detector (by setting the value to 0 (default)) or the raw voice-band output + * of the micrphone (by setting the value to 1). + * + * gainAdjust allows users to adjust the amplification gain on the microphone. The range + * is 0 to 255 with 0 being the minmum and 255 being the maximum amplification. Note that + * setting amplification too high can result in clipping (signal distortion). + * + * If an audio signal at 4.3kHz is picked up by the microphone, the tone + * detect will decode it and generate a binary ouput (0 meaning tone is detected, 1 meaning + * tone is not detected). Users can read this output simply by calling readToneDetector(). + * + */ + +/** + * @author Alec Woo + */ + +interface Mic { + /* Effect: Set the multiplexer's setting on the microphone + * Return: returns SUCCESS or FAIL + */ + command error_t muxSel(uint8_t sel); + /* Effect: Set the amplificatoin gain on the microphone + * Return: returns SUCCESS or FAIL + */ + command error_t gainAdjust(uint8_t val); + + /* Effect: returns the binary tone detector's output + * Return: 0 meaning tone is detected, 1 meanning tone is not detected + */ + command uint8_t readToneDetector(); +} diff --git a/tos/sensorboards/mts300/MicC.nc b/tos/sensorboards/mts300/MicC.nc new file mode 100644 index 00000000..0d096d3b --- /dev/null +++ b/tos/sensorboards/mts300/MicC.nc @@ -0,0 +1,50 @@ +/** + * 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 MicC() { + provides interface Init; + provides interface StdControl; + provides interface Read; + provides interface Mic; + provides interface MicInterrupt; +} +implementation { + components new AdcReadClientC(), MicDeviceP; + + Init = MicDeviceP; + StdControl = MicDeviceP; + Read = AdcReadClientC; + Mic = MicDeviceP; + MicInterrupt = MicDeviceP; + AdcReadClientC.Atm128AdcConfig -> MicDeviceP; + AdcReadClientC.ResourceConfigure -> MicDeviceP; +} diff --git a/tos/sensorboards/mts300/MicDeviceP.nc b/tos/sensorboards/mts300/MicDeviceP.nc new file mode 100644 index 00000000..f2f37546 --- /dev/null +++ b/tos/sensorboards/mts300/MicDeviceP.nc @@ -0,0 +1,61 @@ +/** + * 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" +#include "I2C.h" +configuration MicDeviceP { + provides { + interface Init; + interface StdControl; + interface Mic; + interface MicInterrupt; + interface ResourceConfigure; + interface Atm128AdcConfig; + } +} +implementation { + components MicP, MicaBusC, HplAtm128GeneralIOC as Pins, + HplAtm128InterruptC as IntPins, LedsC, NoLedsC, + new Atm128I2CMasterC() as I2CPot; + + Init = MicP; + StdControl = MicP; + ResourceConfigure = MicP; + Atm128AdcConfig = MicP; + Mic = MicP; + MicInterrupt = MicP; + + MicP.MicPower -> MicaBusC.PW3; + MicP.MicMuxSel -> MicaBusC.PW6; + MicP.MicAdc -> MicaBusC.Adc2; + MicP.I2CPacket -> I2CPot; + MicP.Resource -> I2CPot; + MicP.AlertInterrupt -> IntPins.Int7; + MicP.DebugLeds -> NoLedsC; +} diff --git a/tos/sensorboards/mts300/MicInterrupt.nc b/tos/sensorboards/mts300/MicInterrupt.nc new file mode 100644 index 00000000..780f70ce --- /dev/null +++ b/tos/sensorboards/mts300/MicInterrupt.nc @@ -0,0 +1,67 @@ +// $Id$ + +/* tab:4 + * "Copyright (c) 2000-2003 The Regents of the University of California. + * 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 following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Copyright (c) 2002-2003 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. + */ +/* + * Authors: Alec Woo + * Date last modified: 8/20/02 + * + * The microphone on the mica sensor board has the tone detector interrupt. + * If an audio signal at 4.3kHz is picked up by the microphone, the tone + * detect will decode it and generate a toneDetected interrupt if the + * interrupt is enabled. + * + */ + +/** + * @author Alec Woo + */ + + + +interface MicInterrupt +{ + /* Effects: disable interrupts + Returns: SUCCESS + */ + async command error_t disable(); + + /* Effects: enable interrupts + Returns: SUCCESS + */ + async command error_t enable(); + + /* Interrupt signal for tone detected. Note that MicInterrupt is automatically disabled + * before this event is signaled. (Upper layer needs to reenable this interrupt for future + * tone detect. + * + * Returns: SUCCESS + */ + async event error_t toneDetected(); +} diff --git a/tos/sensorboards/mts300/MicP.nc b/tos/sensorboards/mts300/MicP.nc new file mode 100644 index 00000000..24e37477 --- /dev/null +++ b/tos/sensorboards/mts300/MicP.nc @@ -0,0 +1,201 @@ +/** + * 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 "Timer.h" +#include "I2C.h" + +module MicP +{ + provides interface Init; + provides interface StdControl; + provides interface Mic; + provides interface MicInterrupt; + provides interface ResourceConfigure as MicResourceConfigure; + provides interface Atm128AdcConfig as MicAtm128AdcConfig; + + uses interface Leds as DebugLeds; + uses interface GeneralIO as MicPower; + uses interface GeneralIO as MicMuxSel; + uses interface MicaBusAdc as MicAdc; + uses interface I2CPacket; + uses interface Resource; + uses interface HplAtm128Interrupt as AlertInterrupt; +} +implementation +{ + uint8_t gainData[2]; + + command error_t Init.init() + { + call MicPower.makeOutput(); + call MicPower.clr(); + call MicMuxSel.makeOutput(); + call MicMuxSel.clr(); + + call AlertInterrupt.disable(); + return SUCCESS; + } + + command error_t StdControl.start() + { + call MicPower.set(); + return SUCCESS; + } + + command error_t StdControl.stop() + { + call AlertInterrupt.disable(); + call MicPower.clr(); + call MicPower.makeInput(); + + return SUCCESS; + } + + /** + * Resource request + * + */ + event void Resource.granted() + { + call DebugLeds.led0Off(); + if ( call I2CPacket.write(0x3,TOS_MIC_POT_ADDR, 2, gainData) == SUCCESS) + { + call DebugLeds.led1On(); + }; + } + + /** + * mic control + * + */ + command error_t Mic.muxSel(uint8_t sel) + { + if (sel == 0) + { + call MicMuxSel.clr(); + return SUCCESS; + } + else if (sel == 1) + { + call MicMuxSel.set(); + return SUCCESS; + } + return FAIL; + } + + command error_t Mic.gainAdjust(uint8_t val) + { + call DebugLeds.led0On(); + gainData[0] = 0; // pot subaddr + gainData[1] = val; // value to write + return call Resource.request(); + } + + command uint8_t Mic.readToneDetector() + { + bool bVal = call AlertInterrupt.getValue(); + return bVal ? 1 : 0; + } + + /** + * mic interrupt control + * + */ + async command error_t MicInterrupt.enable() + { + call AlertInterrupt.enable(); + return SUCCESS; + } + + async command error_t MicInterrupt.disable() + { + call AlertInterrupt.disable(); + return SUCCESS; + } + + default async event error_t MicInterrupt.toneDetected() + { + return SUCCESS; + } + + async event void AlertInterrupt.fired() + { + signal MicInterrupt.toneDetected(); + } + + /** + * + * + */ + + async command uint8_t MicAtm128AdcConfig.getChannel() + { + return call MicAdc.getChannel(); + } + + async command uint8_t MicAtm128AdcConfig.getRefVoltage() + { + return ATM128_ADC_VREF_OFF; + } + + async command uint8_t MicAtm128AdcConfig.getPrescaler() + { + return ATM128_ADC_PRESCALE; + } + + async command void MicResourceConfigure.configure() + { + call MicPower.set(); + } + + async command void MicResourceConfigure.unconfigure() + { +// call MicPower.clr(); + } + /** + * I2CPot2 + * + */ + async event void I2CPacket.readDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) + { + return ; + } + + async event void I2CPacket.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) + { + call DebugLeds.led1Off(); + call Resource.release(); + return ; + } +} + + + + + diff --git a/tos/sensorboards/mts300/PhotoTempDeviceP.nc b/tos/sensorboards/mts300/PhotoTempDeviceP.nc new file mode 100644 index 00000000..9678df50 --- /dev/null +++ b/tos/sensorboards/mts300/PhotoTempDeviceP.nc @@ -0,0 +1,51 @@ +/* $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 PhotoTempDeviceP +{ + provides + { + interface Init; + interface StdControl; + interface ResourceConfigure as PhotoResourceConfigure; + interface Atm128AdcConfig as PhotoAtm128AdcConfig; + interface ResourceConfigure as TempResourceConfigure; + interface Atm128AdcConfig as TempAtm128AdcConfig; + } +} +implementation +{ + components PhotoTempP, MicaBusC, HplAtm128GeneralIOC as Pins; +// components new FcfsArbiterC(MTS3X0_PHOTO_TEMP) as Arbiter; + components LedsC, NoLedsC; + + Init = PhotoTempP; + StdControl = PhotoTempP; + + PhotoResourceConfigure = PhotoTempP.PhotoResourceConfigure; + PhotoAtm128AdcConfig = PhotoTempP.PhotoAtm128AdcConfig; + + TempResourceConfigure = PhotoTempP.TempResourceConfigure; + TempAtm128AdcConfig = PhotoTempP.TempAtm128AdcConfig; + + PhotoTempP.LightPower -> Pins.PortE5; + PhotoTempP.TempPower -> Pins.PortE6; + PhotoTempP.SensorAdc -> MicaBusC.Adc1; + + DEBUG_LEDS(PhotoTempP); +} diff --git a/tos/sensorboards/mts300/TempC.nc b/tos/sensorboards/mts300/TempC.nc new file mode 100644 index 00000000..7dc6ad62 --- /dev/null +++ b/tos/sensorboards/mts300/TempC.nc @@ -0,0 +1,42 @@ +/** + * 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; +} -- 2.39.2