[Firebug-cvs] mts400/sensors/intersema ADCError.nc,NONE,1.1 Calibration.nc,NONE,1.1 IntersemaLower.n
Brought to you by:
doolin
Update of /cvsroot/firebug/mts400/sensors/intersema In directory sc8-pr-cvs1:/tmp/cvs-serv11301 Added Files: ADCError.nc Calibration.nc IntersemaLower.nc IntersemaLowerM.nc IntersemaPressure.nc IntersemaPressureM.nc Log Message: Driver files for intersema pressure sensor. --- NEW FILE: ADCError.nc --- /* tab:4 * * * "Copyright (c) 2000-2002 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." * */ /* tab:4 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By * downloading, copying, installing or using the software you agree to * this license. If you do not agree to this license, do not download, * install, copy or use the software. * * Intel Open Source License * * Copyright (c) 2002 Intel Corporation * 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 Intel Corporation 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 INTEL OR ITS * 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. * * */ /* * * Authors: Joe Polastre * * $Id: ADCError.nc,v 1.1 2003/11/13 00:10:04 doolin Exp $ * */ interface ADCError { /** * Enables error reporting for an ADC channel. * enable() must be called when the ADC is IDLE. If it is busy * processing a request, enable() should return FAIL. * * @return SUCCESS if error reporting has been enabled */ command result_t enable(); /** * Disables error reporting for an ADC channel * disable() must be called when the ADC is IDLE. If it is busy * processing a request, disable() should return FAIL. * * @return SUCCESS if error reporting has been disabled */ command result_t disable(); /** * Notification that an error has occurred in the sampling process. * Token values are sensor specific, see the specific sensor to * determine what the error values mean. * * @param token an error code that describes the error that occurred * @return SUCCESS to continue error reporting, FAIL to disable error * reporting */ event result_t error(uint8_t token); } --- NEW FILE: Calibration.nc --- /* tab:4 * * * "Copyright (c) 2000-2002 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." * */ /* tab:4 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By * downloading, copying, installing or using the software you agree to * this license. If you do not agree to this license, do not download, * install, copy or use the software. * * Intel Open Source License * * Copyright (c) 2002 Intel Corporation * 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 Intel Corporation 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 INTEL OR ITS * 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. * * */ /* * * Authors: Joe Polastre * * $Id: Calibration.nc,v 1.1 2003/11/13 00:10:06 doolin Exp $ */ interface Calibration { command result_t getData(); event result_t dataReady(char word, uint16_t value); } --- NEW FILE: IntersemaLower.nc --- /* tab:4 * * * "Copyright (c) 2000-2002 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." * */ /* tab:4 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By * downloading, copying, installing or using the software you agree to * this license. If you do not agree to this license, do not download, * install, copy or use the software. * * Intel Open Source License * * Copyright (c) 2002 Intel Corporation * 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 Intel Corporation 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 INTEL OR ITS * 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. * * */ /* * * Authors: Joe Polastre * * $Id: IntersemaLower.nc,v 1.1 2003/11/13 00:10:06 doolin Exp $ */ includes sensorboard; configuration IntersemaLower { provides { interface ADC as Pressure; interface ADC as Temp; interface ADCError as PressError; interface ADCError as TempError; interface StdControl; interface Calibration; } } implementation { components IntersemaLowerM, TimerC; StdControl = IntersemaLowerM; Pressure = IntersemaLowerM.Pressure; Temp = IntersemaLowerM.Temp; Calibration = IntersemaLowerM; PressError = IntersemaLowerM.PressError; TempError = IntersemaLowerM.TempError; IntersemaLowerM.Timer -> TimerC.Timer[unique("Timer")]; IntersemaLowerM.TimerControl -> TimerC; // IntersemaLowerM.FlashControl -> HPLFlash; } --- NEW FILE: IntersemaLowerM.nc --- /* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */ /* tab:4 * * * "Copyright (c) 2000-2002 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." * */ /* tab:4 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By * downloading, copying, installing or using the software you agree to * this license. If you do not agree to this license, do not download, * install, copy or use the software. * * Intel Open Source License * * Copyright (c) 2002 Intel Corporation * 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 Intel Corporation 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 INTEL OR ITS * 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. * * */ /* * * Authors: Joe Polastre * * $Id: IntersemaLowerM.nc,v 1.1 2003/11/13 00:10:06 doolin Exp $ */ includes sensorboard; includes hardware; module IntersemaLowerM { provides { interface ADC as Pressure; interface ADC as Temp; interface ADCError as PressError; interface ADCError as TempError; interface StdControl; interface Calibration; } uses { // interface StdControl as FlashControl; interface Timer; interface StdControl as TimerControl; } } implementation { enum { IDLE=7, RESET=8, CALIBRATE=9, TEMP=10, PRESSURE=11, DATA_READY=12 }; //FIXME: Remove the norace and fix the rest of the atomic r/w warnings norace char state; norace char sensor; uint16_t calibration[4]; uint16_t reading; uint8_t timeout; uint8_t errornum; bool presserror, temperror; void task signalPressError() { signal PressError.error(errornum); } void task signalTempError() { signal TempError.error(errornum); } void pulse_clock() { TOSH_wait_250ns(); TOSH_wait_250ns(); PRESSURE_SET_CLOCK(); TOSH_wait_250ns(); TOSH_wait_250ns(); PRESSURE_CLEAR_CLOCK(); } char din_value() { return PRESSURE_READ_IN_PIN(); } char read_bit() { char i; PRESSURE_CLEAR_OUT_PIN(); PRESSURE_SET_CLOCK(); TOSH_wait_250ns(); TOSH_wait_250ns(); i = PRESSURE_READ_IN_PIN(); PRESSURE_CLEAR_CLOCK(); return i; } void write_bit(bool bit) { if (bit) PRESSURE_SET_OUT_PIN(); else PRESSURE_CLEAR_OUT_PIN(); pulse_clock(); } // resets the intersema device void spi_reset() { int i = 0; for (i = 0; i < 21; i++) { if (i < 16) { if ((i % 2) == 0) { write_bit(TRUE); } else { write_bit(FALSE); } } else { write_bit(FALSE); } } } uint16_t adc_read() { uint16_t result = 0; uint16_t tresult = 0; char i; TOSH_wait_250ns(); for (i = 0; i < 16; i++) { tresult = (uint16_t)read_bit(); tresult = tresult << (15-i); result += tresult; } return result; } uint16_t spi_word(char num) { int i; TOSH_wait_250ns(); TOSH_wait_250ns(); // write first byte for (i = 0; i < 3; i++) { write_bit(TRUE); } write_bit(FALSE); write_bit(TRUE); if (num == 1) { write_bit(FALSE); write_bit(TRUE); write_bit(FALSE); write_bit(TRUE); } else if (num == 2) { write_bit(FALSE); write_bit(TRUE); write_bit(TRUE); write_bit(FALSE); } else if (num == 3) { write_bit(TRUE); write_bit(FALSE); write_bit(FALSE); write_bit(TRUE); } else if (num == 4) { write_bit(TRUE); write_bit(FALSE); write_bit(TRUE); write_bit(FALSE); } for (i = 0; i < 4; i++) write_bit(FALSE); TOSH_wait_250ns(); return adc_read(); } void task gotInterrupt() { uint16_t l_reading; reading = adc_read(); l_reading = reading; atomic { // we're done, so we can be idle state = IDLE; // give the application the sensor data if (sensor == TEMP) { signal Temp.dataReady(l_reading); } else if (sensor == PRESSURE) { signal Pressure.dataReady(l_reading); } } } void sense() { int i; TOSH_wait_250ns(); TOSH_wait_250ns(); // write first byte for (i = 0; i < 3; i++) { write_bit(TRUE); } if (sensor == PRESSURE) { write_bit(TRUE); write_bit(FALSE); write_bit(TRUE); write_bit(FALSE); } else if (sensor == TEMP) { write_bit(TRUE); write_bit(FALSE); write_bit(FALSE); write_bit(TRUE); } for (i = 0; i < 5; i++) { write_bit(FALSE); } timeout = 0; call Timer.start(TIMER_ONE_SHOT, 36); // kill busy waiting for now // while (PRESSURE_READ_IN_PIN() == 1) { TOSH_wait_250ns(); TOSH_wait_250ns(); } // falling edge of int0 triggers data ready //cbi(EICRA, ISC01); //cbi(EICRA, ISC00); // enable INT0 //sbi(EIMSK, INT0); } event result_t Timer.fired() { if (PRESSURE_READ_IN_PIN() == 1) { timeout++; if (timeout > PRESSURE_TIMEOUT_TRIES) { if ((sensor == PRESSURE) && (presserror == TRUE)) { errornum = 1; call Timer.stop(); state = IDLE; post signalPressError(); return SUCCESS; } else if ((sensor == TEMP) && (temperror == TRUE)) { errornum = 1; call Timer.stop(); state = IDLE; post signalTempError(); return SUCCESS; } } call Timer.start(TIMER_ONE_SHOT, 20); } else { call Timer.stop(); post gotInterrupt(); } return SUCCESS; } TOSH_SIGNAL(PRESSURE_INTERRUPT) { post gotInterrupt(); } task void SPITask() { char i; if (state == RESET) { // if calibration is on, grab the calibration data if (sensor == CALIBRATE) { for (i = 0; i < 4; i++) { // reset the device spi_reset(); calibration[(int)i] = spi_word(i+1); } // we're done, so we can be idle state = IDLE; // send the calibration data up to the application for (i = 0; i < 4; i++) signal Calibration.dataReady(i+1, calibration[(int)i]); return; } else { // reset the device spi_reset(); // grab the sensor reading and store it locally sense(); } } } command result_t StdControl.init() { state = IDLE; presserror = temperror = FALSE; call TimerControl.init(); return SUCCESS; } command result_t StdControl.start() { UART1_DISABLE(); PRESSURE_MAKE_CLOCK_OUTPUT(); PRESSURE_MAKE_IN_INPUT(); PRESSURE_SET_IN_PIN(); PRESSURE_MAKE_OUT_OUTPUT(); return SUCCESS; } command result_t StdControl.stop() { return SUCCESS; } // tells this module whether to report back the calibration data command result_t Calibration.getData() { if (state == IDLE) { state = RESET; atomic { sensor = CALIBRATE; } post SPITask(); return SUCCESS; } return FAIL; } // no such thing async command result_t Pressure.getContinuousData() { return FAIL; } // no such thing async command result_t Temp.getContinuousData() { return FAIL; } async command result_t Pressure.getData() { if (state == IDLE) { state = RESET; atomic { sensor = PRESSURE; } post SPITask(); return SUCCESS; } return FAIL; } async command result_t Temp.getData() { if (state == IDLE) { state = RESET; sensor = TEMP; post SPITask(); return SUCCESS; } return FAIL; } command result_t PressError.enable() { if (presserror == FALSE) { atomic presserror = TRUE; return SUCCESS; } return FAIL; } command result_t PressError.disable() { if (presserror == TRUE) { atomic presserror = FALSE; return SUCCESS; } return FAIL; } command result_t TempError.enable() { if (temperror == FALSE) { atomic temperror = TRUE; return SUCCESS; } return FAIL; } command result_t TempError.disable() { if (temperror == TRUE) { atomic temperror = FALSE; return SUCCESS; } return FAIL; } default event result_t PressError.error(uint8_t token) { return SUCCESS; } default event result_t TempError.error(uint8_t token) { return SUCCESS; } async default event result_t Pressure.dataReady(uint16_t data) { return SUCCESS; } async default event result_t Temp.dataReady(uint16_t data) { return SUCCESS; } // in case people don't want to use the calibration data default event result_t Calibration.dataReady(char word, uint16_t value) { return SUCCESS; } } --- NEW FILE: IntersemaPressure.nc --- /* tab:4 * * * "Copyright (c) 2000-2002 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." * */ /* tab:4 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By * downloading, copying, installing or using the software you agree to * this license. If you do not agree to this license, do not download, * install, copy or use the software. * * Intel Open Source License * * Copyright (c) 2002 Intel Corporation * 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 Intel Corporation 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 INTEL OR ITS * 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. * * */ /* * * Authors: Joe Polastre * * $Id: IntersemaPressure.nc,v 1.1 2003/11/13 00:10:06 doolin Exp $ */ includes sensorboard; configuration IntersemaPressure { provides { interface ADC as Temperature; interface ADC as Pressure; interface Calibration; interface SplitControl; } } implementation { components IntersemaPressureM, IntersemaLower, MicaWbSwitch, TimerC; SplitControl = IntersemaPressureM; Temperature = IntersemaPressureM.Temperature; Pressure = IntersemaPressureM.Pressure; Calibration = IntersemaPressureM; IntersemaPressureM.SwitchControl -> MicaWbSwitch.StdControl; IntersemaPressureM.Switch -> MicaWbSwitch.Switch[0]; IntersemaPressureM.IOSwitch -> MicaWbSwitch.Switch[1]; IntersemaPressureM.LowerControl -> IntersemaLower.StdControl; IntersemaPressureM.LowerPressure -> IntersemaLower.Pressure; IntersemaPressureM.LowerTemp -> IntersemaLower.Temp; IntersemaPressureM.LowerCalibrate -> IntersemaLower.Calibration; IntersemaPressureM.Timer -> TimerC.Timer[unique("Timer")]; IntersemaPressureM.TimerControl -> TimerC; } --- NEW FILE: IntersemaPressureM.nc --- /* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */ /* * * Authors: Joe Polastre * * $Id: IntersemaPressureM.nc,v 1.1 2003/11/13 00:10:06 doolin Exp $ */ includes sensorboard; module IntersemaPressureM { provides { interface ADC as Temperature; interface ADC as Pressure; interface SplitControl; interface Calibration; } uses { interface StdControl as SwitchControl; interface StdControl as LowerControl; interface Calibration as LowerCalibrate; interface Switch; interface Switch as IOSwitch; interface ADC as LowerPressure; interface ADC as LowerTemp; interface Timer; interface StdControl as TimerControl; } } implementation { #include "SODebug.h" #define DBG_USR2 0 //disables printf msgs enum { IDLE, WARM_UP, WAIT_SWITCH_ON, WAIT_SWITCH_OFF, BUSY, MAIN_SWITCH_ON, MAIN_SWITCH_OFF, SWITCH_IO1, SWITCH_IO2, SWITCH_IO3, POWERON, POWEROFF, IOON = 1, IOOFF = 0 }; // FIXME: Remove the norace and fix the rest of the atomic r/w warnings. norace char state; char sensor; char iostate; char c_word; uint16_t temp,pressure; uint16_t c_value; task void initDone() { signal SplitControl.initDone(); } task void stopDone() { signal SplitControl.stopDone(); } task void startDone(){ signal SplitControl.startDone(); } task void IOBus() { atomic { if (state == BUSY) { state = SWITCH_IO1; call IOSwitch.set(MICAWB_PRESSURE_SCLK, iostate); } else if (state == SWITCH_IO1) { SODbg(DBG_USR2, "IntesemaPressure.IoBus.SCLK switch set \n"); state = SWITCH_IO2; call IOSwitch.set(MICAWB_PRESSURE_DIN, iostate); } else if (state == SWITCH_IO2) { SODbg(DBG_USR2, "IntesemaPressure.IoBus.Din switch set \n"); state = SWITCH_IO3; call IOSwitch.set(MICAWB_PRESSURE_DOUT, iostate); } else if (state == SWITCH_IO3) { SODbg(DBG_USR2, "IntesemaPressure.IOBus.all switches set \n"); state = IDLE; atomic { if (iostate == IOOFF){ call LowerControl.stop(); post stopDone(); } else { post startDone(); } } } } // else if (iostate == IOOFF) { // call LowerControl.stop(); // state = IDLE; // post stopDone(); // state = POWEROFF; //} } command result_t SplitControl.init() { state = IDLE; atomic { iostate = IOOFF; } call LowerControl.init(); call SwitchControl.init(); call TimerControl.init(); post initDone(); return SUCCESS; } command result_t SplitControl.start() { SODbg(DBG_USR2, "IntersemaPressure.start: turning on power \n"); state = MAIN_SWITCH_ON; call SwitchControl.start(); if (call Switch.set(MICAWB_PRESSURE_POWER,1) != SUCCESS) { state = WAIT_SWITCH_ON; } return SUCCESS; } command result_t SplitControl.stop() { SODbg(DBG_USR2, "IntersemaPressure.stop: turning off power \n"); state = MAIN_SWITCH_OFF; call SwitchControl.start(); if (call Switch.set(MICAWB_PRESSURE_POWER,0) != SUCCESS) { SODbg(DBG_USR2, "IntersemaPressure.stop: failed to get bus \n"); state = WAIT_SWITCH_OFF; } return SUCCESS; } event result_t Switch.getDone(char value) { return SUCCESS; } event result_t Switch.setDone(bool l_result) { if (state == WAIT_SWITCH_ON) { if (call Switch.set(MICAWB_PRESSURE_POWER,1) == SUCCESS) { state = MAIN_SWITCH_ON; } } else if (state == WAIT_SWITCH_OFF) { if (call Switch.set(MICAWB_PRESSURE_POWER,0) == SUCCESS) { state = MAIN_SWITCH_OFF; } } else if (state == MAIN_SWITCH_ON) { SODbg(DBG_USR2, "IntesemaPressure.start: power on, timer activated \n"); atomic { iostate = IOON; } state = BUSY; post IOBus(); //turn on other switches return SUCCESS; } else if (state == MAIN_SWITCH_OFF) { state = BUSY; atomic { iostate = IOOFF; } post IOBus(); // post stopDone(); // state = POWEROFF; } return SUCCESS; } event result_t Switch.setAllDone(bool l_result) { return SUCCESS; } event result_t IOSwitch.getDone(char value) { return SUCCESS; } //turn on/off all the I/O switches event result_t IOSwitch.setDone(bool l_result) { if ((state == SWITCH_IO1) || (state == SWITCH_IO2) || (state == SWITCH_IO3)) { post IOBus(); } return SUCCESS; } event result_t IOSwitch.setAllDone(bool l_result) { return SUCCESS; } event result_t Timer.fired() { if (state == WARM_UP) { SODbg(DBG_USR2, "IntesemaPressure.Timer.fired \n"); state = BUSY; post IOBus(); } return SUCCESS; } /****************************************************************************** * Get temperature or pressure data from sensor *****************************************************************************/ async command result_t Temperature.getData() { if (state == IDLE) { state = BUSY; call LowerControl.start(); call LowerTemp.getData(); return SUCCESS; } return FAIL; } async event result_t LowerTemp.dataReady(uint16_t data) { atomic { state = IDLE; } signal Temperature.dataReady(data); return SUCCESS; } async command result_t Pressure.getData() { if (state == IDLE) { state = BUSY; atomic { sensor = MICAWB_PRESSURE; iostate = IOON; } call LowerControl.start(); call LowerPressure.getData(); return SUCCESS; } return FAIL; } async event result_t LowerPressure.dataReady(uint16_t data) { state = IDLE; signal Pressure.dataReady(data); return SUCCESS; } // no such thing async command result_t Temperature.getContinuousData() { return FAIL; } // no such thing async command result_t Pressure.getContinuousData() { return FAIL; } default async event result_t Temperature.dataReady(uint16_t data) { return SUCCESS; } default async event result_t Pressure.dataReady(uint16_t data) { return SUCCESS; } /****************************************************************************** * Read calibration words (4) from sensor *****************************************************************************/ command result_t Calibration.getData() { if (state == IDLE) { SODbg(DBG_USR2, "IntesemaPressure.Calibration.getData \n"); state = BUSY; call LowerControl.start(); call LowerCalibrate.getData(); return SUCCESS; } return FAIL; } // on the last byte of calibration data, shut down the I/O interface // async event result_t LowerCalibrate.dataReady(char word, uint16_t value) { event result_t LowerCalibrate.dataReady(char word, uint16_t value) { if (word == 4) { call LowerControl.stop(); atomic { state = IDLE; } signal Calibration.dataReady(word, value); } else { call LowerControl.stop(); signal Calibration.dataReady(word, value); } return SUCCESS; } // default async event result_t Calibration.dataReady(char word, uint16_t value) { default event result_t Calibration.dataReady(char word, uint16_t value) { return SUCCESS; } } |