From: idgay Date: Tue, 22 May 2007 20:59:01 +0000 (+0000) Subject: Consistent voltage stuff for mica family based on code from X-Git-Tag: release_tools_1_2_4_1~177 X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=commitdiff_plain;h=eac1f01f66c8890a9c06d5ca02118f163d1727ae;p=tinyos-2.x.git Consistent voltage stuff for mica family based on code from Razvan Musaloiu-E. --- diff --git a/tos/platforms/mica/VoltageC.nc b/tos/platforms/mica/VoltageC.nc new file mode 100644 index 00000000..f99b346c --- /dev/null +++ b/tos/platforms/mica/VoltageC.nc @@ -0,0 +1,21 @@ +/** + * Battery Voltage. The returned value represents the difference + * between the battery voltage and V_BG (1.23V). The formula to convert + * it to mV is: 1223 * 1024 / value. + * + * @author Razvan Musaloiu-E. + */ + +generic configuration VoltageC() +{ + provides interface Read; +} + +implementation +{ + components new AdcReadClientC(), VoltageP; + + Read = AdcReadClientC; + + AdcReadClientC.Atm128AdcConfig -> VoltageP; +} diff --git a/tos/platforms/mica/VoltageNowC.nc b/tos/platforms/mica/VoltageNowC.nc new file mode 100644 index 00000000..814a04e8 --- /dev/null +++ b/tos/platforms/mica/VoltageNowC.nc @@ -0,0 +1,28 @@ +/* $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. + */ +/** + * Voltage sensor. + * + * @author David Gay + */ + +#include "hardware.h" + +generic configuration VoltageNowC() { + provides interface Resource; + provides interface ReadNow; +} +implementation { + components new AdcReadNowClientC(), VoltageP; + + ReadNow = AdcReadNowClientC; + Resource = AdcReadNowClientC; + AdcReadNowClientC.Atm128AdcConfig -> VoltageP; +} diff --git a/tos/platforms/mica/VoltageP.nc b/tos/platforms/mica/VoltageP.nc new file mode 100644 index 00000000..d6e0cd1c --- /dev/null +++ b/tos/platforms/mica/VoltageP.nc @@ -0,0 +1,29 @@ +/** + * Battery Voltage. The returned value represents the difference + * between the battery voltage and V_BG (1.23V). The formula to convert + * it to mV is: 1223 * 1024 / value. + * + * @author Razvan Musaloiu-E. + */ +module VoltageP +{ + provides interface Atm128AdcConfig; +} +implementation +{ + async command uint8_t Atm128AdcConfig.getChannel() + { + // select the 1.23V (V_BG). Reference: Table 97, page 244 from the Atmega128 + return ATM128_ADC_SNGL_1_23; + } + + 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/platforms/mica/VoltageStreamC.nc b/tos/platforms/mica/VoltageStreamC.nc new file mode 100644 index 00000000..ff477a6e --- /dev/null +++ b/tos/platforms/mica/VoltageStreamC.nc @@ -0,0 +1,26 @@ +/* $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. + */ +/** + * Voltage sensor. + * + * @author David Gay + */ + +#include "hardware.h" + +generic configuration VoltageStreamC() { + provides interface ReadStream; +} +implementation { + components VoltageP, new AdcReadStreamClientC(); + + ReadStream = AdcReadStreamClientC; + AdcReadStreamClientC.Atm128AdcConfig -> VoltageP; +} diff --git a/tos/platforms/mica2/VoltageC.nc b/tos/platforms/mica2/VoltageC.nc deleted file mode 100644 index e1dbd137..00000000 --- a/tos/platforms/mica2/VoltageC.nc +++ /dev/null @@ -1,27 +0,0 @@ -/* $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. - */ -/** - * Voltage sensor. - * - * @author David Gay - */ - -#include "hardware.h" - -generic configuration VoltageC() { - provides interface Read; -} -implementation { - components new AdcReadClientC(), VoltageDeviceP; - - Read = AdcReadClientC; - AdcReadClientC.Atm128AdcConfig -> VoltageDeviceP; - AdcReadClientC.ResourceConfigure -> VoltageDeviceP; -} diff --git a/tos/platforms/mica2/VoltageDeviceP.nc b/tos/platforms/mica2/VoltageDeviceP.nc deleted file mode 100644 index 63e94665..00000000 --- a/tos/platforms/mica2/VoltageDeviceP.nc +++ /dev/null @@ -1,32 +0,0 @@ -/* $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 voltage sensor. Arbitrates access to the voltage - * sensor and automatically turns it on or off based on user requests. - * - * @author David Gay - */ - -#include "hardware.h" - -configuration VoltageDeviceP { - provides { - interface Atm128AdcConfig; - interface ResourceConfigure; - } -} -implementation { - components VoltageP, HplAtm128GeneralIOC as Pins; - - Atm128AdcConfig = VoltageP; - ResourceConfigure = VoltageP; - - VoltageP.BatMon -> Pins.PortA5; -} diff --git a/tos/platforms/mica2/VoltageNowC.nc b/tos/platforms/mica2/VoltageNowC.nc deleted file mode 100644 index edf0c183..00000000 --- a/tos/platforms/mica2/VoltageNowC.nc +++ /dev/null @@ -1,29 +0,0 @@ -/* $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. - */ -/** - * Voltage sensor. - * - * @author David Gay - */ - -#include "hardware.h" - -generic configuration VoltageNowC() { - provides interface Resource; - provides interface ReadNow; -} -implementation { - components new AdcReadNowClientC(), VoltageDeviceP; - - ReadNow = AdcReadNowClientC; - Resource = AdcReadNowClientC; - AdcReadNowClientC.Atm128AdcConfig -> VoltageDeviceP; - AdcReadNowClientC.ResourceConfigure -> VoltageDeviceP; -} diff --git a/tos/platforms/mica2/VoltageP.nc b/tos/platforms/mica2/VoltageP.nc deleted file mode 100644 index e4376aa7..00000000 --- a/tos/platforms/mica2/VoltageP.nc +++ /dev/null @@ -1,59 +0,0 @@ -/// $Id$ - -/* - * Copyright (c) 2004-2005 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 following - * two paragraphs and the author appear in all copies of this software. - * - * IN NO EVENT SHALL CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY - * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR - * MODIFICATIONS. - */ -/** - * Internal component for voltage sensor reading. - * - * @author Hu Siquan - * @author David Gay - */ - -module VoltageP { - provides { - interface ResourceConfigure; - interface Atm128AdcConfig as VoltageConfig; - } - uses interface GeneralIO as BatMon; -} -implementation { - async command uint8_t VoltageConfig.getChannel() { - return CHANNEL_BATTERY; - } - - async command uint8_t VoltageConfig.getRefVoltage() { - return ATM128_ADC_VREF_OFF; - } - - async command uint8_t VoltageConfig.getPrescaler() { - return ATM128_ADC_PRESCALE; - } - - async command void ResourceConfigure.configure() { - call BatMon.makeOutput(); - call BatMon.set(); - } - - async command void ResourceConfigure.unconfigure() { - call BatMon.clr(); - } -} diff --git a/tos/platforms/mica2/VoltageStreamC.nc b/tos/platforms/mica2/VoltageStreamC.nc deleted file mode 100644 index 6749d892..00000000 --- a/tos/platforms/mica2/VoltageStreamC.nc +++ /dev/null @@ -1,27 +0,0 @@ -/* $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. - */ -/** - * Voltage sensor. - * - * @author David Gay - */ - -#include "hardware.h" - -generic configuration VoltageStreamC() { - provides interface ReadStream; -} -implementation { - components VoltageDeviceP, new AdcReadStreamClientC(); - - ReadStream = AdcReadStreamClientC; - AdcReadStreamClientC.Atm128AdcConfig -> VoltageDeviceP; - AdcReadStreamClientC.ResourceConfigure -> VoltageDeviceP; -} diff --git a/tos/platforms/mica2dot/VoltageDeviceP.nc b/tos/platforms/mica2dot/VoltageDeviceP.nc deleted file mode 100644 index f8081095..00000000 --- a/tos/platforms/mica2dot/VoltageDeviceP.nc +++ /dev/null @@ -1,33 +0,0 @@ -/* $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 voltage sensor. Arbitrates access to the voltage - * sensor and automatically turns it on or off based on user requests. - * - * @author David Gay - */ - -#include "hardware.h" - -configuration VoltageDeviceP { - provides { - interface Atm128AdcConfig; - interface ResourceConfigure; - } -} -implementation { - components VoltageP, HplAtm128GeneralIOC as Pins; - - Atm128AdcConfig = VoltageP; - ResourceConfigure = VoltageP; - - VoltageP.BatMon -> Pins.PortC6; - VoltageP.BatMonRef -> Pins.PortC7; -} diff --git a/tos/platforms/mica2dot/VoltageP.nc b/tos/platforms/mica2dot/VoltageP.nc deleted file mode 100644 index dc3884b4..00000000 --- a/tos/platforms/mica2dot/VoltageP.nc +++ /dev/null @@ -1,64 +0,0 @@ -/// $Id$ - -/* - * Copyright (c) 2004-2005 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 following - * two paragraphs and the author appear in all copies of this software. - * - * IN NO EVENT SHALL CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY - * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR - * MODIFICATIONS. - */ -/** - * Internal component for voltage sensor reading. - * - * @author Hu Siquan - * @author David Gay - */ - -module VoltageP { - provides { - interface ResourceConfigure; - interface Atm128AdcConfig as VoltageConfig; - } - uses { - interface GeneralIO as BatMon; - interface GeneralIO as BatMonRef; - } -} -implementation { - async command uint8_t VoltageConfig.getChannel() { - return CHANNEL_BATTERY_THERMISTOR; - } - - async command uint8_t VoltageConfig.getRefVoltage() { - return ATM128_ADC_VREF_OFF; - } - - async command uint8_t VoltageConfig.getPrescaler() { - return ATM128_ADC_PRESCALE; - } - - async command void ResourceConfigure.configure() { - call BatMonRef.makeOutput(); - call BatMonRef.clr(); - call BatMon.makeInput(); - call BatMon.clr(); - } - - async command void ResourceConfigure.unconfigure() { - call BatMonRef.makeInput(); - } -} diff --git a/tos/platforms/micaz/DemoSensorC.nc b/tos/platforms/micaz/DemoSensorC.nc index 28959a20..05bae197 100644 --- a/tos/platforms/micaz/DemoSensorC.nc +++ b/tos/platforms/micaz/DemoSensorC.nc @@ -22,7 +22,7 @@ generic configuration DemoSensorC() } implementation { - components new SineSensorC() as DemoChannel; + components new VoltageC() as DemoChannel; Read = DemoChannel; } diff --git a/tos/platforms/micaz/DemoSensorNowC.nc b/tos/platforms/micaz/DemoSensorNowC.nc index 47b2ad1d..4e12bc93 100644 --- a/tos/platforms/micaz/DemoSensorNowC.nc +++ b/tos/platforms/micaz/DemoSensorNowC.nc @@ -20,7 +20,7 @@ generic configuration DemoSensorNowC() provides interface ReadNow; } implementation { - components new AdcReadNowClientC() as Sensor; + components new VoltageNowC() as Sensor; Resource = Sensor; ReadNow = Sensor; diff --git a/tos/platforms/micaz/DemoSensorStreamC.nc b/tos/platforms/micaz/DemoSensorStreamC.nc index 0849582b..8a190d43 100644 --- a/tos/platforms/micaz/DemoSensorStreamC.nc +++ b/tos/platforms/micaz/DemoSensorStreamC.nc @@ -22,8 +22,7 @@ generic configuration DemoSensorStreamC() } implementation { - components new AdcReadStreamClientC(); + components new VoltageStreamC() as Sensor; - // An unconfigure atm128 ReadStream sensor reads the "ground" channel. - ReadStream = AdcReadStreamClientC; + ReadStream = Sensor; }