[Tinyos-beta-commits] CVS: tinyos-1.x/beta/platform/tsb Mic.h, NONE, 1.1 MicDriverC.nc, NONE, 1.1 MicDriverM.nc, NONE, 1.1

Joe Polastre jpolastre at users.sourceforge.net
Thu Jun 23 17:14:46 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/beta/platform/tsb
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28629

Added Files:
	Mic.h MicDriverC.nc MicDriverM.nc 
Log Message:
initial checkin of a mic driver, may not work though.  you have been warned.



--- NEW FILE: Mic.h ---
#ifndef _H_MIC_H
#define _H_MIC_H

#include "MSP430ADC12.h"

enum {
  AD5242_MIC1_ADDR = 0x00,
  AD5242_MIC2_ADDR = 0x01,
  AD5242_MIC_PWR_ADDR = 0x00,
  AD5242_MIC_FLT_ADDR = 0x00,
};

enum
{
  TOS_ADC_MIC_PORT = unique("ADCPort"),

  TOSH_ACTUAL_ADC_MIC_PORT = ASSOCIATE_ADC_CHANNEL(
    INPUT_CHANNEL_A2,
    REFERENCE_AVcc_AVss,
    REFVOLT_LEVEL_2_5
    ),
};

#endif

--- NEW FILE: MicDriverC.nc ---
/*									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."
 *
 */
/*
 *
 * Authors:		Joe Polastre
 *
 * $Id: MicDriverC.nc,v 1.1 2005/06/24 00:14:44 jpolastre Exp $
 */

includes Mic;
includes sensorboard;

configuration MicDriverC
{
  provides {
    interface SplitControl;
    interface ADC as Mic;
    interface TSBInterrupt as MicInterrupt;
    interface Potentiometer as Vrc;
    interface Potentiometer as Vrg;
    interface Potentiometer as MicInterruptSettings;
  }
}
implementation
{
  components MicDriverM, ADCC, AD5242C, MSP430InterruptC, LedsC;
  
  MicDriverM.Leds -> LedsC;

  SplitControl = MicDriverM;
  Mic = ADCC.ADC[TOS_ADC_MIC_PORT];
  MicInterrupt = MicDriverM;
  MicInterruptSettings = MicDriverM;
  Vrc = MicDriverM;
  Vrg = MicDriverM;

  MicDriverM.ADCStdControl -> ADCC;
  MicDriverM.ADCControl -> ADCC;
  MicDriverM.AD5242 -> AD5242C;
  MicDriverM.AD5242Control -> AD5242C;
  MicDriverM.MicInt -> MSP430InterruptC.Port26; // GIO3

}

--- NEW FILE: MicDriverM.nc ---
// $Id: MicDriverM.nc,v 1.1 2005/06/24 00:14:44 jpolastre Exp $
/*
 * "Copyright (c) 2000-2005 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."
 */

/**
 * @author Joe Polastre
 * Revision:  $Revision: 1.1 $
 *
 */

includes Mic;

module MicDriverM
{
  provides {
    interface SplitControl;
    interface TSBInterrupt as MicInterrupt;
    interface Potentiometer as MicVrc;
    interface Potentiometer as MicVrg;
    interface Potentiometer as MicInterruptSettings;
  }
  uses {
    interface AD5242;
    interface ADCControl;
    interface StdControl as ADCStdControl;
    interface StdControl as PotControl;
    interface StdControl as AD5242Control;
    interface MSP430Interrupt as MicInt;
    interface Leds;
  }
}

implementation
{

  enum {
    OFF = 0,
    IDLE,
    START,
    START_O1, // mic circuit power on
    START_O2, // filter circuit power on
    STOP,
    STOP_O1,
    STOP_O2,
    GAIN,
    VRG,
    VRC,
  };

  uint8_t state;
  uint8_t gain;
  uint8_t vrg, vrc;

  task void initDone() {
    signal SplitControl.initDone();
  }

  command result_t SplitControl.init() {
    atomic {
      // state is off
      state = OFF;
    }
    call ADCStdControl.init();
    call AD5242Control.init();
    return post initDone();
  }

  command result_t SplitControl.start() {
    uint8_t _state = OFF;
    atomic {
      if (state == OFF) {
	state = START;
	_state = state;
      }
    }
    if (_state == START) {
      call ADCStdControl.start();
      call ADCControl.init();
      if (!call ADCControl.bindPort(TOS_ADC_MIC_PORT, 
				    TOSH_ACTUAL_ADC_MIC_PORT)) {
	state = OFF;
	return FAIL;
      }
      TOSH_SEL_ADC2_MODFUNC();
      call AD5242Control.start();
      return call AD5242.start(AD5242_MIC_PWR_ADDR);
    }
    return FAIL;
  }

  event void AD5242.startDone(uint8_t _addr, result_t _result) {
    uint8_t _state = OFF;
    atomic {
      if (state == START) {
	state = START_O1;
	_state = state;
      }
    }
    // turn on the microphone circuit
    if (_state == START_O1) {
      if (!(call AD5242.setOutput1(AD5242_MIC_PWR_ADDR, TRUE))) {
	atomic state = IDLE;
	signal SplitControl.startDone();
      }
    }
  }

  command result_t SplitControl.stop() {
    uint8_t _state = OFF;
    atomic {
      if (state == IDLE) {
	state = STOP;
	_state = state;
      }
    }
    if (_state == STOP) {
      // questionable whether this should be here...
      call ADCStdControl.stop();
      TOSH_SEL_ADC2_IOFUNC();
      return call AD5242.stop(AD5242_MIC_PWR_ADDR);
    }
    return FAIL;
  }

  event void AD5242.stopDone(uint8_t _addr, result_t _result) {
    uint8_t _state = OFF;
    atomic {
      if (state == STOP) {
	state = STOP_O1;
	_state = state;
      }
    }
    if (_state == STOP_O1) {
      if (!(call AD5242.setOutput1(AD5242_MIC_PWR_ADDR, FALSE))) {
	atomic state = IDLE;
	signal SplitControl.stopDone();
      }
    }
  }

  event void AD5242.setOutput1Done(uint8_t _addr, result_t _result) { 
    uint8_t _state = OFF;
    atomic {
      if (state == START_O1) {
	state = START_O2;
	_state = state;
      }
      else if (state == STOP_O1) {
	state = STOP_O2;
	_state = state;
      }
    }

    // turn on the filter
    if (_state == START_O2) {
      if (!(call AD5242.setOutput2(AD5242_MIC_PWR_ADDR, TRUE))) {
	atomic state = IDLE;
	signal SplitControl.startDone();
      }
    }
    // turn on the filter
    else if (_state == STOP_O2) {
      if (!(call AD5242.setOutput2(AD5242_MIC_PWR_ADDR, FALSE))) {
	atomic state = IDLE;
	signal SplitControl.stopDone();
      }
    }
  }

  event void AD5242.setOutput2Done(uint8_t _addr, result_t _result) { 
    atomic {
      if ((state == START_O2) || (state == STOP_O2)) {
	_state = state;
	state = IDLE;
      }
    }
    if (_state == START_O2) 
      signal SplitControl.startDone();
    else if (_state == STOP_O2) {
      call AD5242Control.stop();
      signal SplitControl.stopDone();
    }
  }

  event void AD5242.setPot1Done(uint8_t _addr, result_t _result) { 
    atomic {
      if (state == VRC) {
        _state = state;
        state = IDLE;
      }
      else if (state == VRG) {
        _state = state;
        state = IDLE;
      }
    }

    if (_state == VRC) {
      signal Vrc.setDone(vrc, _result);
    }
    if (_state == VRG) {
      signal Vrg.setDone(vrc, _result);
    }
  }
  event void AD5242.getPot1Done(uint8_t _addr, uint8_t _val, result_t _result) { }
  event void AD5242.getPot2Done(uint8_t _addr, uint8_t _val, result_t _result) { }
  event void AD5242.setPot2Done(uint8_t _addr, result_t _result) { 
    uint8_t _state = OFF;
    atomic {
      if (state == GAIN) {
        _state = state;
        state = IDLE;
      }
    }

    if (_state == GAIN) {
      signal MicInterruptSettings.setDone(gain, _result);
    }
  }

  command result_t Vrg.set(uint8_t _value) {
    uint8_t _state = OFF;
    atomic {
      if (state == IDLE) {
        state = VRG;
        _state = state;
      }
    }
    if (_state == VRG) {
      atomic vrg = _value;
      return call AD5242.setPot1(AD5242_MIC1_ADDR, vrg);
    }
    return FAIL;
  }

  command uint8_t Vrg.get() {
    return vrg;
  }

  default event void Vrg.setDone(uint8_t value, result_t result) { }

  command result_t Vrc.set(uint8_t _value) {
    uint8_t _state = OFF;
    atomic {
      if (state == IDLE) {
        state = VRC;
        _state = state;
      }
    }
    if (_state == VRC) {
      atomic vrc = _value;
      return call AD5242.setPot1(AD5242_MIC2_ADDR, vrc);
    }
    return FAIL;
  }

  command uint8_t Vrc.get() {
    return vrc;
  }

  default event void Vrc.setDone(uint8_t value, result_t result) { }

  command result_t MicInterruptSettings.set(uint8_t _gain) {
    uint8_t _state = OFF;
    atomic {
      if (state == IDLE) {
        state = GAIN;
        _state = state;
      }
    }
    if (_state == GAIN) {
      atomic gain = _gain;
      return call AD5242.setPot2(AD5242_MIC1_ADDR, gain);
    }
    return FAIL;
  }

  default event void MicInterruptSettings.setDone(uint8_t _gain, result_t _result) { }

  command uint8_t MicInterruptSettings.get() {
    return gain;
  }

  async command result_t MicInterrupt.enable() {
    atomic {
      TOSH_MAKE_MIC_INT_INPUT();
      call MicInt.disable();
      call MicInt.clear();
      call MicInt.edge(FALSE);
      call MicInt.enable();
    }
    return SUCCESS;
  }

  async command result_t MicInterrupt.disable() {
    atomic {
      call MicInt.disable();
      call MicInt.clear();
      TOSH_MAKE_MIC_INT_OUTPUT();
    }
    return SUCCESS;
  }

  default async event void MicInterrupt.fired() { }

  async event void MicInt.fired() {
    signal MicInterrupt.fired();
    call MicInt.clear();
  }

}



More information about the Tinyos-beta-commits mailing list