[Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/max136x HalMAX136xAdvanced.nc, NONE, 1.1.2.1 HalMAX136xControlP.nc, NONE, 1.1.2.1 HalMAX136xReaderP.nc, NONE, 1.1.2.1 HplMAX136x.nc, 1.1.2.1, 1.1.2.2 HplMAX136xLogicP.nc, 1.1.2.1, 1.1.2.2 MAX136x.h, 1.1.2.1, 1.1.2.2

Philip Buonadonna philipb at users.sourceforge.net
Thu Jul 6 16:20:54 PDT 2006


Update of /cvsroot/tinyos/tinyos-2.x/tos/chips/max136x
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv7925

Modified Files:
      Tag: tinyos-2_0_devel-BRANCH
	HplMAX136x.nc HplMAX136xLogicP.nc MAX136x.h 
Added Files:
      Tag: tinyos-2_0_devel-BRANCH
	HalMAX136xAdvanced.nc HalMAX136xControlP.nc 
	HalMAX136xReaderP.nc 
Log Message:
Updated support for Maxim MAX136x sensor chip

--- NEW FILE: HalMAX136xAdvanced.nc ---
/* $Id: HalMAX136xAdvanced.nc,v 1.1.2.1 2006/07/06 23:20:52 philipb Exp $ */
/*
 * Copyright (c) 2005 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.
 */
/**
 *
 * @author Kaisen Lin
 * @author Phil Buonadonna
 */

#include "MAX136x.h"

interface HalMAX136xAdvanced {
  command error_t setScanMode(max136x_scanflag_t mode, uint8_t chanlow, uint8_t chanhigh);
  event void setScanModeDone(error_t error);
  command error_t setMonitorMode(uint8_t chanlow, uint8_t chanhigh, max136x_delayflag_t delay, uint8_t thresholds[12]); 
  event void setMonitorModeDone(error_t error);
  command error_t setConversionMode(bool bDifferential, bool bBipolar);
  event void setConversionModeDone(error_t error);  
  command error_t setClock(bool bExtClk);
  event void setClockDone(error_t error); 
  command error_t setRef(max136x_selflag_t sel, bool bInRefPwr);
  event void setRefDone(error_t error);
  command error_t getStatus();
  event void getStatusDone(error_t error, uint8_t status, 
                           max136x_data_t data);
  command error_t enableAlert(bool bEnable);
  event void enableAlertDone(error_t error);
  event void alertThreshold();

}

--- NEW FILE: HalMAX136xControlP.nc ---
/* $Id: HalMAX136xControlP.nc,v 1.1.2.1 2006/07/06 23:20:52 philipb Exp $ */
/*
 * Copyright (c) 2005 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.
 */
/**
 *
 * @author Kaisen Lin
 * @author Phil Buonadonna
 */

#include "MAX136x.h"

module HalMAX136xControlP {
  provides interface HalMAX136xAdvanced;

  uses interface Resource;
  uses interface HplMAX136x;
}

implementation {
  enum {
    S_IDLE,
    S_SETSCANMODE,
    S_SETMONMODE,
    S_SETCONVMODE,
    S_SETCLK,
    S_SETREF,
  };
  uint8_t state = S_IDLE;

  uint8_t mI2CBuffer[8];
  uint8_t configByteShadow = 0x01;
  uint8_t setupByteShadow = 0x83; // 0x82 actually, but we want extended monitor write
  uint8_t monitorByteShadow = 0x0;

  error_t clientResult;

  task void signalDone_Task() {
    switch(state) {
    case S_SETSCANMODE:
      state = S_IDLE;
      call Resource.release();
      signal HalMAX136xAdvanced.setScanModeDone(clientResult);
      break;
    case S_SETMONMODE:
      state = S_IDLE;
      call Resource.release();
      signal HalMAX136xAdvanced.setMonitorModeDone(clientResult);
      break;
    case S_SETCONVMODE:
      state = S_IDLE;
      call Resource.release();
      signal HalMAX136xAdvanced.setConversionModeDone(clientResult);
      break;
    case S_SETCLK:
      state = S_IDLE;
      call Resource.release();
      signal HalMAX136xAdvanced.setClockDone(clientResult);
      break;
    case S_SETREF:
      state = S_IDLE;
      call Resource.release();
      signal HalMAX136xAdvanced.setRefDone(clientResult);
      break;
    default:
      break;
    }
  }

  command error_t HalMAX136xAdvanced.setScanMode(max136x_scanflag_t mode, uint8_t chanlow, uint8_t chanhigh) {
    // chanlow is always 0 no matter what client says
    error_t status;
    if(state != S_IDLE)
      return FAIL;
    status = call Resource.immediateRequest();
    if(status != SUCCESS)
      return status;
    state = S_SETSCANMODE;

    configByteShadow &= ~MAX136X_CONFIG_SCAN(3);
    configByteShadow |= MAX136X_CONFIG_SCAN(mode);

    configByteShadow &= ~MAX136X_CONFIG_CS(3);
    configByteShadow |= MAX136X_CONFIG_CS(chanhigh);

    mI2CBuffer[0] = configByteShadow;

    call HplMAX136x.setConfig(mI2CBuffer, 1);
    return SUCCESS;
  }

  command error_t HalMAX136xAdvanced.setMonitorMode(uint8_t chanlow, uint8_t chanhigh, max136x_delayflag_t delay, uint8_t thresholds[12]) {
    // chanlow is always 0 no matter what client says
    uint8_t i;
    error_t status;
    if(state != S_IDLE)
      return FAIL;
    status = call Resource.immediateRequest();
    if(status != SUCCESS)
      return status;
    state = S_SETMONMODE;

    configByteShadow &= ~MAX136X_CONFIG_CS(3);
    configByteShadow |= MAX136X_CONFIG_CS(chanhigh);

    monitorByteShadow &= ~MAX136X_MONITOR_DELAY(7);
    monitorByteShadow |= MAX136X_MONITOR_DELAY(delay);

    mI2CBuffer[0] = configByteShadow;
    mI2CBuffer[1] = setupByteShadow;
    mI2CBuffer[2] = monitorByteShadow;
    for(i = 0; i < 12; i++)
      mI2CBuffer[i+3] = thresholds[i];
    
    call HplMAX136x.setConfig(mI2CBuffer, 15);
    return SUCCESS;
  } 

  command error_t HalMAX136xAdvanced.setConversionMode(bool bDifferential, bool bBipolar) {
    error_t status;
    if(state != S_IDLE)
      return FAIL;
    status = call Resource.immediateRequest();
    if(status != SUCCESS)
      return status;
    state = S_SETCONVMODE;

    if(bDifferential)
      configByteShadow &= ~MAX136X_CONFIG_SE;
    else
      configByteShadow |= MAX136X_CONFIG_SE;

    if(bBipolar)
      setupByteShadow |= MAX136X_SETUP_BIP;
    else
      setupByteShadow &= ~MAX136X_SETUP_BIP;

    mI2CBuffer[0] = configByteShadow;
    mI2CBuffer[1] = setupByteShadow;
    call HplMAX136x.setConfig(mI2CBuffer, 2);
    return SUCCESS;
  }

  command error_t HalMAX136xAdvanced.setClock(bool bExtClk) {
    error_t status;
    if(state != S_IDLE)
      return FAIL;
    status = call Resource.immediateRequest();
    if(status != SUCCESS)
      return status;
    state = S_SETCLK;

    if(bExtClk)
      setupByteShadow |= MAX136X_SETUP_EXTCLK;
    else
      setupByteShadow &= ~MAX136X_SETUP_EXTCLK;

    mI2CBuffer[0] = setupByteShadow;
    call HplMAX136x.setConfig(mI2CBuffer, 1);
    return SUCCESS;
  }
  
  command error_t HalMAX136xAdvanced.setRef(max136x_selflag_t sel, bool bInRefPwr) {    error_t status;
    if(state != S_IDLE)
      return FAIL;
    status = call Resource.immediateRequest();
    if(status != SUCCESS)
      return status;
    state = S_SETREF;
    
    if(bInRefPwr)
      setupByteShadow |= MAX136X_SETUP_INTREFOFF;
    else
      setupByteShadow &= ~MAX136X_SETUP_INTREFOFF;

    setupByteShadow &=  ~MAX136X_SETUP_REFAIN3SEL(3);
    setupByteShadow |= MAX136X_SETUP_REFAIN3SEL(sel);
  }

  command error_t HalMAX136xAdvanced.getStatus() {
    // STUB
  }

  command error_t HalMAX136xAdvanced.enableAlert(bool bEnable) {
    // STUB
  }

  event void Resource.granted() {
    // intentionally left blank
  }

  async event void HplMAX136x.measureChannelsDone( error_t error, uint8_t *buf, uint8_t len ) { /* intentionally left blank */ }
  async event void HplMAX136x.setConfigDone( error_t error , uint8_t *cfgbuf, uint8_t len) {
    clientResult = error;
    post signalDone_Task();
  }
  async event void HplMAX136x.alertThreshold() {}
}

--- NEW FILE: HalMAX136xReaderP.nc ---
/* $Id: HalMAX136xReaderP.nc,v 1.1.2.1 2006/07/06 23:20:52 philipb Exp $ */
/*
 * Copyright (c) 2005 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.
 */
/**
 *
 * @author Kaisen Lin
 * @author Phil Buonadonna
 */

#include "MAX136x.h"

generic module HalMAX136xReaderP()
{
  provides interface Read<max136x_data_t> as ADC;

  uses interface HplMAX136x;
  uses interface Resource as MAX136xResource;
}

implementation {

  uint8_t channelBuf[2];
  
  command error_t ADC.read() {
    return call MAX136xResource.request();
  }

  event void MAX136xResource.granted() {
    error_t error;

    error = call HplMAX136x.measureChannels(channelBuf, 2);
    if (error) {
      call MAX136xResource.release();
      signal ADC.readDone(error,0);
    }
  }

  async event void HplMAX136x.measureChannelsDone(error_t error,
						  uint8_t *buf,
						  uint8_t len)
  {
    uint16_t result = 0;
    result = buf[0];
    result <<= 8;
    result += buf[1];
    call MAX136xResource.release();
    signal ADC.readDone(error,result);
    return;
  }

  async event void HplMAX136x.setConfigDone(error_t error,
					    uint8_t *cfgbuf,
					    uint8_t len)
  {
    // intentionally left blank
  }

  async event void HplMAX136x.alertThreshold() {}

}

Index: HplMAX136x.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/max136x/Attic/HplMAX136x.nc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** HplMAX136x.nc	24 May 2006 23:56:44 -0000	1.1.2.1
--- HplMAX136x.nc	6 Jul 2006 23:20:52 -0000	1.1.2.2
***************
*** 37,41 ****
   */
  
! interface HplMAX163x {
  
    command error_t measureChannels(uint8_t *buf,uint8_t len);
--- 37,41 ----
   */
  
! interface HplMAX136x {
  
    command error_t measureChannels(uint8_t *buf,uint8_t len);

Index: HplMAX136xLogicP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/max136x/Attic/HplMAX136xLogicP.nc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** HplMAX136xLogicP.nc	24 May 2006 23:56:44 -0000	1.1.2.1
--- HplMAX136xLogicP.nc	6 Jul 2006 23:20:52 -0000	1.1.2.2
***************
*** 39,42 ****
--- 39,44 ----
   */
  
+ #include "I2C.h"
+ 
  generic module HplMAX136xLogicP(uint16_t devAddr)
  {
***************
*** 45,49 ****
    provides interface HplMAX136x;
  
!   uses interface I2CPacketAdv;
    uses interface GpioInterrupt as InterruptAlert;
  }
--- 47,51 ----
    provides interface HplMAX136x;
  
!   uses interface I2CPacket<TI2CBasicAddr>;
    uses interface GpioInterrupt as InterruptAlert;
  }
***************
*** 61,65 ****
    };
  
-   uint8_t mI2CBuffer[16];
    uint8_t mState;
    bool mStopRequested;
--- 63,66 ----
***************
*** 80,84 ****
        return error;
  
!     error = call I2CPacket.writePacket(devAddr,len,buf,STOP_FLAG);
      
      if (error) 
--- 81,85 ----
        return error;
  
!     error = call I2CPacket.write(I2C_START | I2C_STOP, devAddr,len,buf);
      
      if (error) 
***************
*** 99,112 ****
        }
      }
!     if error
        return error;
  
!     error = call I2CPacket.readPacket(devAddr,len,buf,STOP_FLAG);
  
      if (error)
!       atomic mState = STATE_IDLE:
  
      return error;
! 
  
    task void StartDone() {
--- 100,113 ----
        }
      }
!     if (error)
        return error;
  
!     error = call I2CPacket.read(I2C_START | I2C_STOP, devAddr,len,buf);
  
      if (error)
!       atomic mState = STATE_IDLE;
  
      return error;
!   }
  
    task void StartDone() {
***************
*** 124,130 ****
    command error_t Init.init() {
      atomic {
!       mStopPending = FALSE;
!       mState = STATE_STOPPED:
      }
    }
  
--- 125,132 ----
    command error_t Init.init() {
      atomic {
!       mStopRequested = FALSE;
!       mState = STATE_STOPPED;
      }
+     return SUCCESS;
    }
  
***************
*** 141,145 ****
      if (error) 
        return error;
! 
      return post StartDone();
    }
--- 143,147 ----
      if (error) 
        return error;
!     
      return post StartDone();
    }
***************
*** 171,175 ****
    }
  
!   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;
--- 173,177 ----
    }
  
!   async event void I2CPacket.readDone(error_t i2c_error, uint16_t chipAddr, uint8_t len, uint8_t *buf) {
      uint16_t tempVal;
      error_t error = i2c_error;
***************
*** 187,191 ****
    }
  
!   async event void I2CPacket.writeDone(uint16_t chipAddr, uint8_t len, uint8_t *buf, error_t i2c_error) {
      error_t error = i2c_error;
  
--- 189,193 ----
    }
  
!   async event void I2CPacket.writeDone(error_t i2c_error, uint16_t chipAddr, uint8_t len, uint8_t *buf) {
      error_t error = i2c_error;
  
***************
*** 196,201 ****
        break;
      default:
!       mState = STATE_IDLE:
! 	break;
      }
      return;
--- 198,203 ----
        break;
      default:
!       mState = STATE_IDLE;
!       break;
      }
      return;
***************
*** 212,216 ****
    default event void SplitControl.stopDone( error_t error ) { return; }
  
!   default event void HplMAX136x.alertThreshold(){ return; }
  
  }
--- 214,218 ----
    default event void SplitControl.stopDone( error_t error ) { return; }
  
!   default async event void HplMAX136x.alertThreshold(){ return; }
  
  }

Index: MAX136x.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/max136x/Attic/MAX136x.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** MAX136x.h	24 May 2006 23:56:44 -0000	1.1.2.1
--- MAX136x.h	6 Jul 2006 23:20:52 -0000	1.1.2.2
***************
*** 3,7 ****
   * All rights reserved.
   *
!  * Redistribution and use in so1urce and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
--- 3,7 ----
   * All rights reserved.
   *
!  * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
***************
*** 41,45 ****
  
  #define MAX136X_CONFIG_SCAN(_x)		(((_x) & 0x3) << 5)
! #define MAX136X_CONFIG_CS(_x)		((()x) & 0xF) << 1)
  #define MAX136X_CONFIG_SE		(1 << 0)
  
--- 41,45 ----
  
  #define MAX136X_CONFIG_SCAN(_x)		(((_x) & 0x3) << 5)
! #define MAX136X_CONFIG_CS(_x)		(((_x) & 0xF) << 1)
  #define MAX136X_CONFIG_SE		(1 << 0)
  
***************
*** 51,54 ****
--- 51,82 ----
  #define MAX136X_SETUP_MONSETUP		(1 << 0)
  
+ #define MAX136X_MONITOR_DELAY(_x)       (((_x) & 0x7) << 1)
+ 
+ typedef uint16_t max136x_data_t;
+ 
+ typedef enum {
+   MAX136X_SCAN_RANGE = 0,
+   MAX136X_SCAN_REPEATED = 1,
+   MAX136X_SCAN_SINGLE = 3,
+ } max136x_scanflag_t;
+ 
+ typedef enum {
+   MAX136X_SEL_VDDREF,  		// SEL1 = 0, SEL0 = 0
+   MAX136X_SEL_EXTREF,		// SEL1 = 0, SEL0 = 1
+   MAX136X_SEL_INTREF_AIN3IN,	// SEL1 = 1, SEL0 = 0
+   MAX136X_SEL_INTREF_AIN3OUT	// SEL1 = 1, SEL0 = 1
+ } max136x_selflag_t;
+ 
+ typedef enum {
+   MAX136X_DELAY_133_0,
+   MAX136X_DELAY_66_5,
+   MAX136X_DELAY_33_3,
+   MAX136X_DELAY_16_6,
+   MAX136X_DELAY_8_3,
+   MAX136X_DELAY_4_2,
+   MAX136X_DELAY_2_0,
+   MAX136X_DELAY_1_0
+ } max136x_delayflag_t;
+ 
  
  #endif /* _MAX136X_H */



More information about the Tinyos-2-commits mailing list