[Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/max136x HplMAX136x.nc,
NONE, 1.1.2.1 HplMAX136xLogicP.nc, NONE, 1.1.2.1 MAX136x.h,
NONE, 1.1.2.1
Philip Buonadonna
philipb at users.sourceforge.net
Wed May 24 16:56:46 PDT 2006
Update of /cvsroot/tinyos/tinyos-2.x/tos/chips/max136x
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv24476
Added Files:
Tag: tinyos-2_0_devel-BRANCH
HplMAX136x.nc HplMAX136xLogicP.nc MAX136x.h
Log Message:
Initial support for max136x series 4-channel ADC chip. Draft only
--- NEW FILE: HplMAX136x.nc ---
/*
* Copyright (c) 2005-2006 Arch Rock 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 Arch Rock 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
* ARCHED ROCK 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
*/
/**
* Hpl interface for the MAXIM 136x series ADC chips.
*
* @author Phil Buonadonna <pbuonadonna at archrock.com>
* @version $Revision: 1.1.2.1 $ $Date: 2006/05/24 23:56:44 $
*/
interface HplMAX163x {
command error_t measureChannels(uint8_t *buf,uint8_t len);
async event void measureChannelsDone( error_t error, uint8_t *buf, uint8_t len );
command error_t setConfig( uint8_t *cfgbuf, uint8_t len);
async event void setConfigDone( error_t error , uint8_t *cfgbuf, uint8_t len);
async event void alertThreshold();
}
--- NEW FILE: HplMAX136xLogicP.nc ---
/*
* Copyright (c) 2005-2006 Arch Rock 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 Arch Rock 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
* ARCHED ROCK 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
*/
/**
* MAX136xLogicP is the driver for the MAXIM 136x series ADC chip.
* It requires an I2C packet interface and provides the HplMAX136x HPL
* interface.
*
* @author Phil Buonadonna <pbuonadonna at archrock.com>
* @version $Revision: 1.1.2.1 $ $Date: 2006/05/24 23:56:44 $
*/
generic module HplMAX136xLogicP(uint16_t devAddr)
{
provides interface Init;
provides interface SplitControl;
provides interface HplMAX136x;
uses interface I2CPacketAdv;
uses interface GpioInterrupt as InterruptAlert;
}
implementation {
enum {
STATE_IDLE,
STATE_STARTING,
STATE_STOPPING,
STATE_STOPPED,
STATE_READCH,
STATE_SETCONFIG,
STATE_ERROR
};
uint8_t mI2CBuffer[16];
uint8_t mState;
bool mStopRequested;
norace error_t mSSError;
static error_t doWrite(uint8_t nextState, uint8_t *buf, uint8_t len) {
error_t error = SUCCESS;
atomic {
if (mState == STATE_IDLE) {
mState = nextState;
}
else {
error = EBUSY;
}
}
if (error)
return error;
error = call I2CPacket.writePacket(devAddr,len,buf,STOP_FLAG);
if (error)
atomic mState = STATE_IDLE;
return error;
}
static error_t doRead(uint8_t nextState, uint8_t *buf, uint8_t len) {
error_t error = SUCCESS;
atomic {
if (mState == STATE_IDLE) {
mState = nextState;
}
else {
error = EBUSY;
}
}
if error
return error;
error = call I2CPacket.readPacket(devAddr,len,buf,STOP_FLAG);
if (error)
atomic mState = STATE_IDLE:
return error;
task void StartDone() {
atomic mState = STATE_IDLE;
signal SplitControl.startDone(SUCCESS);
return;
}
task void StopDone() {
atomic mState = STATE_STOPPED;
signal SplitControl.stopDone(mSSError);
return;
}
command error_t Init.init() {
atomic {
mStopPending = FALSE;
mState = STATE_STOPPED:
}
}
command error_t SplitControl.start() {
error_t error = SUCCESS;
atomic {
if (mState == STATE_STOPPED) {
mState = STATE_STARTING;
}
else {
error = EBUSY;
}
}
if (error)
return error;
return post StartDone();
}
command error_t SplitControl.stop() {
error_t error = SUCCESS;
atomic {
if (mState == STATE_IDLE) {
mState = STATE_STOPPING;
}
else {
error = EBUSY;
}
}
if (error)
return error;
return post StopDone();
}
command error_t HplMAX136x.measureChannels(uint8_t *buf, uint8_t len) {
return doRead(STATE_READCH,buf,len);
}
command error_t HplMAX136x.setConfig(uint8_t *configbuf, uint8_t len) {
return doWrite(STATE_SETCONFIG,configbuf,len);
}
async event void I2CPacket.readDone(uint16_t chipAddr, uint8_t len, uint8_t *buf, error_t i2c_error) {
uint16_t tempVal;
error_t error = i2c_error;
switch (mState) {
case STATE_READCH:
mState = STATE_IDLE;
signal HplMAX136x.measureChannelsDone(error, buf, len);
break;
default:
mState = STATE_IDLE;
break;
}
return;
}
async event void I2CPacket.writeDone(uint16_t chipAddr, uint8_t len, uint8_t *buf, error_t i2c_error) {
error_t error = i2c_error;
switch (mState) {
case STATE_SETCONFIG:
mState = STATE_IDLE;
signal HplMAX136x.setConfigDone(error,buf,len);
break;
default:
mState = STATE_IDLE:
break;
}
return;
}
async event void InterruptAlert.fired() {
// This alert is decoupled from whatever state the MAX136x is in.
// Upper layers must handle dealing with this alert appropriately.
signal HplMAX136x.alertThreshold();
return;
}
default event void SplitControl.startDone( error_t error ) { return; }
default event void SplitControl.stopDone( error_t error ) { return; }
default event void HplMAX136x.alertThreshold(){ return; }
}
--- NEW FILE: MAX136x.h ---
/*
* Copyright (c) 2005-2006 Arch Rock Corporation
* All rights reserved.
*
* Redistribution and use in so1urce 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 Arch Rock 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
* ARCHED ROCK 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
*/
/**
* Types and definitions for the Maxim 136x general purpose ADC chip
*
* @author Phil Buonadonna <pbuonadonna at archrock.com>
* @version $Revision: 1.1.2.1 $ $Date: 2006/05/24 23:56:44 $
*/
#ifndef _MAX136X_H
#define _MAX136X_H
#define MAX136X_CONFIG_SCAN(_x) (((_x) & 0x3) << 5)
#define MAX136X_CONFIG_CS(_x) ((()x) & 0xF) << 1)
#define MAX136X_CONFIG_SE (1 << 0)
#define MAX136X_SETUP_REFAIN3SEL(_x) (((_x) & 0x3) << 5)
#define MAX136X_SETUP_INTREFOFF (1 << 4)
#define MAX136X_SETUP_EXTCLK (1 << 3)
#define MAX136X_SETUP_BIP (1 << 2)
#define MAX136X_SETUP_NRESET (1 << 1)
#define MAX136X_SETUP_MONSETUP (1 << 0)
#endif /* _MAX136X_H */
More information about the Tinyos-2-commits
mailing list