[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/imote2/test/TestMDA440 EEPROM.nc, NONE, 1.1 EEPROMC.nc, NONE, 1.1 EEPROMM.nc, NONE, 1.1 MDA440.nc, 1.1, 1.2 MDA440M.nc, 1.3, 1.4 TestMDA440.nc, 1.3, 1.4 TestMDA440M.nc, 1.3, 1.4

Robbie Adler radler at users.sourceforge.net
Sat Sep 9 09:05:23 PDT 2006


Update of /cvsroot/tinyos/tinyos-1.x/contrib/imote2/test/TestMDA440
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv24214

Modified Files:
	MDA440.nc MDA440M.nc TestMDA440.nc TestMDA440M.nc 
Added Files:
	EEPROM.nc EEPROMC.nc EEPROMM.nc 
Log Message:
latest version of MDA440 test application files

--- NEW FILE: EEPROM.nc ---
interface EEPROM{
  
  command result_t write(uint8_t address, uint8_t *data, uint8_t numBytes);
  command result_t read(uint8_t address, uint8_t *data, uint8_t numBytes);
  
  command result_t getUID(uint8_t val[6]);
}

--- NEW FILE: EEPROMC.nc ---
configuration EEPROMC{

  provides{
    interface StdControl;
    interface EEPROM;
  }
}
implementation{
  components EEPROMM, 
    PXA27XInterruptM;
  
  EEPROM = EEPROMM;
  StdControl = EEPROMM;
  EEPROMM.I2CInterrupt -> PXA27XInterruptM.PXA27XIrq[PPID_I2C];
}

--- NEW FILE: EEPROMM.nc ---
includes trace;

module EEPROMM{
  provides{
    interface StdControl;
    interface EEPROM;
  }
  uses {
    interface PXA27XInterrupt as I2CInterrupt;
  }
}
implementation {
  
  bool gotReset;
  norace  bool bWriteDone;;
  norace uint8_t UID[6];
  
#define EEPROM_ADDR 0x50  
#define ASSIGN_ADDR 0x64
 
  result_t readEEPROM(uint8_t address, uint8_t *value, uint8_t numBytes){
    //send the PMIC the address that we want to read
    if(numBytes > 0){
      IDBR = EEPROM_ADDR<<1; 
      ICR |= ICR_START;
      ICR |= ICR_TB;
      while(ICR & ICR_TB);
      
      //actually send the address terminated with a STOP
      IDBR = address;
      ICR &= ~ICR_START;
      ICR |= ICR_STOP;
      ICR |= ICR_TB;
      while(ICR & ICR_TB);
      ICR &= ~ICR_STOP;
      
      
      //actually request the read of the data
      IDBR = EEPROM_ADDR<<1 | 1; 
      ICR |= ICR_START;
      ICR |= ICR_TB;
      while(ICR & ICR_TB);
      ICR &= ~ICR_START;
      
      //using Page Read Mode
      while (numBytes > 1){
	ICR |= ICR_TB;
	while(ICR & ICR_TB);
	*value = IDBR;
	value++;
	numBytes--;
      }
      
      ICR |= ICR_STOP;
      ICR |= ICR_ACKNAK;
      ICR |= ICR_TB;
      while(ICR & ICR_TB);
      *value = IDBR;
      ICR &= ~ICR_STOP;
      ICR &= ~ICR_ACKNAK;
      
      return SUCCESS;
    }
    return FAIL;
  }
  
  result_t writeEEPROM(uint8_t address, uint8_t *value, uint8_t numBytes){
    // bool bLocalWriteDone;
    if(numBytes>0){
      
      
      IDBR = EEPROM_ADDR<<1;
      ICR |= ICR_START;
      ICR |= ICR_TB;
      while(ICR & ICR_TB);
      
      IDBR = address;
      ICR &= ~ICR_START;
      ICR |= ICR_TB;
      while(ICR & ICR_TB);
      
      while(numBytes>1){
	IDBR = *value;
	ICR |= ICR_TB;
	while(ICR & ICR_TB);
	numBytes--;
	value++;
      }
      IDBR = *value;
      ICR |= ICR_STOP;
      ICR |= ICR_TB;
      while(ICR & ICR_TB);
      ICR &= ~ICR_STOP;
      
      //now, we need a way to poll for a nack
#if 0      
      ICR |= (ICR_BEIE | ICR_ITEIE);
      IDBR = EEPROM_ADDR<<1;
      ICR |= ICR_START;
      ICR |= ICR_TB;
      
      atomic{
	bWriteDone = FALSE;
      }
      do{
	atomic{
	  bLocalWriteDone = bWriteDone;
	}
      }
      while(!bLocalWriteDone);
#else
      TOSH_uwait(5000);
#endif
      return SUCCESS;
    }
    return FAIL;
  }
  
  command result_t StdControl.init(){
    //enable the clock
    //while(!bPMICenabled);
    CKEN |= CKEN14_I2C;
    //config the GPIO's
    _PXA_setaltfn(117,0x1,GPIO_IN);
    _PXA_setaltfn(118,0x1,GPIO_IN);
    //PICR = ICR_IUE | ICR_SCLE | ICR_BEIE | ICR_ITEIE ;
    ICR = ICR_IUE | ICR_SCLE;
    atomic{
      gotReset=FALSE;
    }    
    
    return call I2CInterrupt.allocate();
  }

  
  command result_t StdControl.start(){
    //init unit
    call I2CInterrupt.enable();

#if 0
    UID[0]= 0xDE;
    UID[1]= 0xAD;
    UID[2]= 0xBE;
    UID[3]= 0xEF;
    writeEEPROM(0,UID, 4);

    UID[0]= 0;
    UID[1]= 0;
    UID[2]= 0;
    UID[3]= 0;
    readEEPROM(0,UID, 4);
    trace(DBG_USR1,"Initialized EEPROM....UID = %#x %#x %#x %#x\r\n",UID[0],UID[1],UID[2],UID[3]);
#endif
    return SUCCESS;
  }
  
  
  command result_t StdControl.stop(){
    call I2CInterrupt.disable();
    CKEN &= ~CKEN14_I2C;
    PICR = 0;
    
    return SUCCESS;
  }
  
  async event void I2CInterrupt.fired(){
    uint32_t status, update=0;
    //currently, we use this to enable ACK polling
    status = ISR;
    
    if(status & ISR_ITE){
      update |= ISR_ITE;
      trace(DBG_USR1,"finished with write %#x\r\n",status);
      ICR &= ~(ICR_BEIE | ICR_ITEIE);
      
      //set the address pointer back to 0
      IDBR = 0;
      ICR &= ~ICR_START;
      ICR |= ICR_STOP;
      ICR |= ICR_TB;
      while(ICR & ICR_TB);
      ICR &= ~ICR_STOP;
      
      atomic{
	bWriteDone = TRUE;
      }
    }
    if(status & ISR_BED){
      update |= ISR_BED;
      trace(DBG_USR1,"bus error %#x\r\n",status);
    }
    PISR = update;
  }
  
  
  command result_t EEPROM.getUID(uint8_t val[6]){
    
  }

  command result_t EEPROM.write(uint8_t address, uint8_t *data, uint8_t numBytes){
    return writeEEPROM(address, data, numBytes);
  }
  
  command result_t EEPROM.read(uint8_t address, uint8_t *data, uint8_t numBytes){
    return readEEPROM(address, data, numBytes);
  }
  
}



Index: MDA440.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/imote2/test/TestMDA440/MDA440.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MDA440.nc	26 Jul 2005 01:30:47 -0000	1.1
--- MDA440.nc	9 Sep 2006 16:05:20 -0000	1.2
***************
*** 21,27 ****
    
    // Acquisition Related Commands
!   command result_t getSamples(uint8_t *buffer, uint16_t NumSamples);
    event result_t getSamplesDone(uint8_t *buffer);
!   
    //High Level selection routines
    command result_t turnOffBoard();	
--- 21,31 ----
    
    // Acquisition Related Commands
!   command result_t getSamples(uint8_t *buffer, uint16_t NumSamples,uint32_t K);
    event result_t getSamplesDone(uint8_t *buffer);
! 
!     // Acquisition Related Commands
!   command result_t startTach();
!   command result_t stopTach(uint32_t *totalTime, uint32_t *totalSamples);
!    
    //High Level selection routines
    command result_t turnOffBoard();	

Index: MDA440M.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/imote2/test/TestMDA440/MDA440M.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** MDA440M.nc	19 Sep 2005 21:08:26 -0000	1.3
--- MDA440M.nc	9 Sep 2006 16:05:20 -0000	1.4
***************
*** 1,2 ****
--- 1,4 ----
+ includes downsample;
+ 
  module MDA440M{
    provides {
***************
*** 15,19 ****
  #define VCC5_SENSOR_EN_PIN (55)
  #define VCC18_EN_PIN (56)
! #define MUX0_ACCEL_EN_PIN (57)
  #define MUX0_LOSPEED_EN_PIN (84)
  #define MUX0_TEMP_EN_PIN (83)
--- 17,22 ----
  #define VCC5_SENSOR_EN_PIN (55)
  #define VCC18_EN_PIN (56)
! #define MUX0_ACCEL_PWR_EN_PIN (30)
! #define MUX0_ACCEL_SIG_EN_PIN (57)
  #define MUX0_LOSPEED_EN_PIN (84)
  #define MUX0_TEMP_EN_PIN (83)
***************
*** 25,29 ****
    TOSH_ASSIGN_PIN(VCC5_SENSOR_EN, A, VCC5_SENSOR_EN_PIN);
    TOSH_ASSIGN_PIN(VCC18_EN, A, VCC18_EN_PIN);
!   TOSH_ASSIGN_PIN(MUX0_ACCEL_EN, A, MUX0_ACCEL_EN_PIN);
    TOSH_ASSIGN_PIN(MUX0_LOSPEED_EN, A, MUX0_LOSPEED_EN_PIN);
    TOSH_ASSIGN_PIN(MUX0_TEMP_EN, A, MUX0_TEMP_EN_PIN);
--- 28,35 ----
    TOSH_ASSIGN_PIN(VCC5_SENSOR_EN, A, VCC5_SENSOR_EN_PIN);
    TOSH_ASSIGN_PIN(VCC18_EN, A, VCC18_EN_PIN);
!   
!   TOSH_ASSIGN_PIN(MUX0_ACCEL_SIG_EN, A, MUX0_ACCEL_SIG_EN_PIN);
!   TOSH_ASSIGN_PIN(MUX0_ACCEL_PWR_EN, A, MUX0_ACCEL_PWR_EN_PIN);
!   
    TOSH_ASSIGN_PIN(MUX0_LOSPEED_EN, A, MUX0_LOSPEED_EN_PIN);
    TOSH_ASSIGN_PIN(MUX0_TEMP_EN, A, MUX0_TEMP_EN_PIN);
***************
*** 38,42 ****
      const uint8_t Mux2[4] = {106, 54, 0, 85};
      
!     
    void EnableMux(const uint8_t mux[4]){
      if(mux[3]){
--- 44,124 ----
      const uint8_t Mux2[4] = {106, 54, 0, 85};
      
!   
! #define DEFINE_PARAMTASK(funcname) \
! task void _##funcname##veneer(){\
! uint32_t argument;\
! popqueue(&paramtaskQueue,&argument);\
! funcname(argument);}
!   
! #define POST_PARAMTASK(funcname, arg) \
! {pushqueue(&paramtaskQueue, arg);post _##funcname##veneer();}
!   
!   
! #define DMASIZE 2048
!   //#define DOWNSAMPLEFACTOR 1
!   
!   
!   downsampleStates_t downsampleStates;
!   downsampleTempBuffer_t downsampleTempBuffer[DMASIZE/4];
!   
! #define NUMBUFFERS 3
!   
!   typedef struct{
!     short buf[DMASIZE] __attribute ((aligned(32)));
!     bool inuse;
!   } buffer_t;
!   
!   buffer_t tempBuffers[NUMBUFFERS];
!   
!   
!   uint8_t *getNextBuffer(){
!     int i;
!     uint8_t *ret = NULL;
!     atomic{
!       for(i=0;i<NUMBUFFERS; i++){
! 	if(tempBuffers[i].inuse == FALSE){
! 	  tempBuffers[i].inuse = TRUE;
! 	  ret = (uint8_t *)tempBuffers[i].buf;
! 	  break;
! 	}
!       }
!     }
!     return ret;
!   }
! 
!   void returnBuffer(short *buf){
!     int i;
!     atomic{
!       for(i=0;i<NUMBUFFERS; i++){
! 	if(tempBuffers[i].buf == buf){
! 	  tempBuffers[i].inuse = FALSE;
! 	}
!       }
!     }
!   }
!   
!   void initBuffer(){
!     int i;
!     atomic{
!       for(i=0;i<NUMBUFFERS; i++){
! 	tempBuffers[i].inuse = FALSE;
!       }
!     }
!   }
!   
!   uint8_t *gOutBuffer;
!   uint16_t *gOutBufferTemp;
!   uint32_t gOutBufferIncrement;
!   
!   uint16_t gOutBufferCount;
!   uint16_t gInBufferCount;
!   uint16_t gBufferCountMax;
! 
!   uint32_t gDownsampleFactor;
!   bool gDropFirstBuffer;
! 
!   uint32_t gTotalTachTime;
!   uint32_t gTotalTachSamples;
!   
    void EnableMux(const uint8_t mux[4]){
      if(mux[3]){
***************
*** 52,59 ****
        }
      }
!     
!     void SetMuxAddress(const uint8_t mux[4], uint8_t bit0, uint8_t bit1, uint8_t bit2){
!       if(mux[0]){
! 	_PXA_setaltfn(mux[0],0, GPIO_OUT);
  	if(bit0==0){ 
  	  _PXA_clrgpio(mux[0]);
--- 134,141 ----
        }
      }
!   
!   void SetMuxAddress(const uint8_t mux[4], uint8_t bit0, uint8_t bit1, uint8_t bit2){
!     if(mux[0]){
!       _PXA_setaltfn(mux[0],0, GPIO_OUT);
  	if(bit0==0){ 
  	  _PXA_clrgpio(mux[0]);
***************
*** 90,96 ****
  
        TOSH_SET_VCC3_SENSOR_EN_PIN();
!       TOSH_SET_VCC5_SENSOR_EN_PIN();
        TOSH_SET_VCC18_EN_PIN();
!       TOSH_CLR_MUX0_ACCEL_EN_PIN();
        DisableMux(Mux2);
        
--- 172,179 ----
  
        TOSH_SET_VCC3_SENSOR_EN_PIN();
!       TOSH_CLR_VCC5_SENSOR_EN_PIN();
        TOSH_SET_VCC18_EN_PIN();
!       TOSH_CLR_MUX0_ACCEL_SIG_EN_PIN();
!       TOSH_CLR_MUX0_ACCEL_PWR_EN_PIN();
        DisableMux(Mux2);
        
***************
*** 101,105 ****
        TOSH_MAKE_VCC5_SENSOR_EN_OUTPUT();
        TOSH_MAKE_VCC18_EN_OUTPUT();
!       TOSH_MAKE_MUX0_ACCEL_EN_OUTPUT();
        TOSH_MAKE_MUX0_LOSPEED_EN_OUTPUT();
        TOSH_MAKE_MUX0_TEMP_EN_OUTPUT();
--- 184,189 ----
        TOSH_MAKE_VCC5_SENSOR_EN_OUTPUT();
        TOSH_MAKE_VCC18_EN_OUTPUT();
!       TOSH_MAKE_MUX0_ACCEL_PWR_EN_OUTPUT();
!       TOSH_MAKE_MUX0_ACCEL_SIG_EN_OUTPUT();
        TOSH_MAKE_MUX0_LOSPEED_EN_OUTPUT();
        TOSH_MAKE_MUX0_TEMP_EN_OUTPUT();
***************
*** 107,110 ****
--- 191,197 ----
        TOSH_SET_CPLDRESET_PIN();
  
+       initBuffer();
+       
+       
        //put the A/D in high-resolution mode
        TOSH_MAKE_ADS1271_MODE_INPUT();
***************
*** 116,120 ****
--- 203,210 ----
        _PXA_setaltfn(107,0,GPIO_IN);
        call TACHInterrupt.enable(TOSH_FALLING_EDGE);
+       gTotalTachTime=0;
+       gTotalTachSamples=0;
        
+ 
        //HACK For now because something stange is happening
        //TOSH_SET_ADS1271_SYNC_PIN();
***************
*** 140,145 ****
      command result_t MDA440.enableHighSpeedChain(){
        TOSH_CLR_VCC3_SENSOR_EN_PIN();
!       TOSH_CLR_VCC5_SENSOR_EN_PIN();
!       TOSH_CLR_VCC18_EN_PIN();
        SetMuxAddress(Mux2,0,0,0);
        EnableMux(Mux2);
--- 230,235 ----
      command result_t MDA440.enableHighSpeedChain(){
        TOSH_CLR_VCC3_SENSOR_EN_PIN();
!       TOSH_SET_VCC5_SENSOR_EN_PIN();
!       TOSH_SET_VCC18_EN_PIN();
        SetMuxAddress(Mux2,0,0,0);
        EnableMux(Mux2);
***************
*** 149,154 ****
      command result_t MDA440.disableHighSpeedChain(){
        TOSH_SET_VCC3_SENSOR_EN_PIN();
!       TOSH_SET_VCC5_SENSOR_EN_PIN();
!       TOSH_SET_VCC18_EN_PIN();
        
        DisableMux(Mux2);
--- 239,244 ----
      command result_t MDA440.disableHighSpeedChain(){
        TOSH_SET_VCC3_SENSOR_EN_PIN();
!       TOSH_CLR_VCC5_SENSOR_EN_PIN();
!       TOSH_CLR_VCC18_EN_PIN();
        
        DisableMux(Mux2);
***************
*** 158,162 ****
      command result_t MDA440.disableLowSpeedChain(){
        TOSH_SET_VCC3_SENSOR_EN_PIN();
!       TOSH_SET_VCC5_SENSOR_EN_PIN();
        TOSH_SET_VCC18_EN_PIN();
        
--- 248,252 ----
      command result_t MDA440.disableLowSpeedChain(){
        TOSH_SET_VCC3_SENSOR_EN_PIN();
!       TOSH_CLR_VCC5_SENSOR_EN_PIN();
        TOSH_SET_VCC18_EN_PIN();
        
***************
*** 167,172 ****
      command result_t MDA440.enableLowSpeedChain(){
        TOSH_CLR_VCC3_SENSOR_EN_PIN();
!       TOSH_CLR_VCC5_SENSOR_EN_PIN();
!       TOSH_SET_VCC18_EN_PIN();  //make sure it's off
        SetMuxAddress(Mux2,0,1,0); //select Low speed
        EnableMux(Mux2);
--- 257,262 ----
      command result_t MDA440.enableLowSpeedChain(){
        TOSH_CLR_VCC3_SENSOR_EN_PIN();
!       TOSH_SET_VCC5_SENSOR_EN_PIN();
!       TOSH_CLR_VCC18_EN_PIN();  //make sure it's off
        SetMuxAddress(Mux2,0,1,0); //select Low speed
        EnableMux(Mux2);
***************
*** 176,182 ****
      command result_t MDA440.turnOffBoard(){
        TOSH_SET_VCC3_SENSOR_EN_PIN();
!       TOSH_SET_VCC5_SENSOR_EN_PIN();
!       TOSH_SET_VCC18_EN_PIN();
!       TOSH_CLR_MUX0_ACCEL_EN_PIN();
        DisableMux(Mux2);
        TOSH_CLR_MUX0_LOSPEED_EN_PIN();
--- 266,273 ----
      command result_t MDA440.turnOffBoard(){
        TOSH_SET_VCC3_SENSOR_EN_PIN();
!       TOSH_CLR_VCC5_SENSOR_EN_PIN();
!       TOSH_CLR_VCC18_EN_PIN();
!       TOSH_CLR_MUX0_ACCEL_PWR_EN_PIN();
!       TOSH_CLR_MUX0_ACCEL_SIG_EN_PIN();
        DisableMux(Mux2);
        TOSH_CLR_MUX0_LOSPEED_EN_PIN();
***************
*** 239,246 ****
      }    
      
!     command result_t MDA440.getSamples(uint8_t *buffer, uint16_t NumSamples){
        TOSH_SET_ADS1271_SYNC_PIN();
!       call BulkTxRx.BulkReceive(buffer, 2*NumSamples);
!       //TOSH_SET_ADS1271_SYNC_PIN();
        return SUCCESS;
      }
--- 330,361 ----
      }    
      
!     command result_t MDA440.getSamples(uint8_t *buffer, uint16_t NumSamples, uint32_t K){
!       uint8_t *tempBuf;
!       
        TOSH_SET_ADS1271_SYNC_PIN();
!       downsampleInit(&downsampleStates,downsampleTempBuffer);
!       
!       //need to call this the first time here
!       atomic{
! 	gOutBuffer = buffer; //buffer that we eventually need to return
! 	gOutBufferTemp = (uint16_t *) buffer; //pointer that we can manipulate with pointer arihmetic
! 	gOutBufferIncrement = DMASIZE/K;
! 	
! 	gOutBufferCount = 0; //loop counter for iterations
! 	gInBufferCount = 0;
! 
! 	gBufferCountMax = ((NumSamples/DMASIZE)* K) + ((K>1)?1:0); //precomputed number of iterations..used by both DMA side and downsample side
! 	gDropFirstBuffer = (K>1)?TRUE:FALSE;
! 	gDownsampleFactor = K;
! 
!       }
!       tempBuf = getNextBuffer();
!       if(tempBuf){
! 	call BulkTxRx.BulkReceive(tempBuf, DMASIZE*2);
!       }
!       else{
! 	trace(DBG_USR1,"unable to obtain buffer at start\r\n");
!       }
!             //TOSH_SET_ADS1271_SYNC_PIN();
        return SUCCESS;
      }
***************
*** 250,259 ****
        call  MDA440.enableHighSpeedChain();
        call  MDA440.selectMux0Channel(7);
!       _PXA_setaltfn(57,0,GPIO_OUT);
!       _PXA_setgpio(57);
        _PXA_setaltfn(85,0,GPIO_OUT);
        _PXA_setgpio(85);
        TOSH_CLR_VCC3_SENSOR_EN_PIN();
!       TOSH_CLR_VCC5_SENSOR_EN_PIN();
        TOSH_CLR_ADS1271_SYNC_PIN();
        
--- 365,375 ----
        call  MDA440.enableHighSpeedChain();
        call  MDA440.selectMux0Channel(7);
!       TOSH_SET_MUX0_ACCEL_SIG_EN_PIN();
!       TOSH_SET_MUX0_ACCEL_PWR_EN_PIN();
!       
        _PXA_setaltfn(85,0,GPIO_OUT);
        _PXA_setgpio(85);
        TOSH_CLR_VCC3_SENSOR_EN_PIN();
!       TOSH_SET_VCC5_SENSOR_EN_PIN();
        TOSH_CLR_ADS1271_SYNC_PIN();
        
***************
*** 264,273 ****
        call  MDA440.enableLowSpeedChain();
        call  MDA440.selectMux0Channel(7);
!       _PXA_setaltfn(57,0,GPIO_OUT);
!       _PXA_setgpio(57);
        _PXA_setaltfn(85,0,GPIO_OUT);
        _PXA_setgpio(85);
        TOSH_CLR_VCC3_SENSOR_EN_PIN();
!       TOSH_CLR_VCC5_SENSOR_EN_PIN();
        TOSH_CLR_ADS1271_SYNC_PIN();
        
--- 380,390 ----
        call  MDA440.enableLowSpeedChain();
        call  MDA440.selectMux0Channel(7);
!       TOSH_SET_MUX0_ACCEL_SIG_EN_PIN();
!       TOSH_SET_MUX0_ACCEL_PWR_EN_PIN();
!       
        _PXA_setaltfn(85,0,GPIO_OUT);
        _PXA_setgpio(85);
        TOSH_CLR_VCC3_SENSOR_EN_PIN();
!       TOSH_SET_VCC5_SENSOR_EN_PIN();
        TOSH_CLR_ADS1271_SYNC_PIN();
        
***************
*** 280,289 ****
        call MDA440.selectLowSpeedChannel(3);
        TOSH_SET_MUX0_LOSPEED_EN_PIN();
!       _PXA_setaltfn(57,0,GPIO_OUT);
!       _PXA_setgpio(57);
        _PXA_setaltfn(85,0,GPIO_OUT);
        _PXA_setgpio(85);
        TOSH_CLR_VCC3_SENSOR_EN_PIN();
!       TOSH_CLR_VCC5_SENSOR_EN_PIN();
        TOSH_CLR_ADS1271_SYNC_PIN();
        
--- 397,407 ----
        call MDA440.selectLowSpeedChannel(3);
        TOSH_SET_MUX0_LOSPEED_EN_PIN();
!       TOSH_SET_MUX0_ACCEL_SIG_EN_PIN();
!       TOSH_SET_MUX0_ACCEL_PWR_EN_PIN();
!       
        _PXA_setaltfn(85,0,GPIO_OUT);
        _PXA_setgpio(85);
        TOSH_CLR_VCC3_SENSOR_EN_PIN();
!       TOSH_SET_VCC5_SENSOR_EN_PIN();
        TOSH_CLR_ADS1271_SYNC_PIN();
        
***************
*** 300,309 ****
      }
          
!     event uint8_t *BulkTxRx.BulkReceiveDone(uint8_t *data, uint16_t NumBytes){
        TOSH_CLR_ADS1271_SYNC_PIN();
-       signal MDA440.getSamplesDone(data);
        return NULL;
      }
! 
    event result_t BulkTxRx.BulkTransmitDone(uint8_t *data){
        return SUCCESS;
--- 418,469 ----
      }
          
!  
!   void postProcessBuffer(uint8_t *data){
!     
!     uint32_t time = OSCR0;
!         
!     downsample(&downsampleStates, (short *)data, DMASIZE,
! 	       gOutBufferTemp,
! 	       gDownsampleFactor);
!     returnBuffer(data);
!     if(gDropFirstBuffer){
!       gDropFirstBuffer = FALSE;
!     }    
!     else{
!       gOutBufferTemp += gOutBufferIncrement;
!     }
!       
!     gOutBufferCount++;
!     
!     time = OSCR0-time;
!     trace(DBG_USR1,"downsample %d, %d\r\n",time, gOutBufferCount);
!     if(gOutBufferCount >= gBufferCountMax){
!       signal MDA440.getSamplesDone(gOutBuffer);
!     }
!     return;
!   }
!   DEFINE_PARAMTASK(postProcessBuffer);
!   
!   
!   event uint8_t *BulkTxRx.BulkReceiveDone(uint8_t *data, uint16_t NumBytes){
!     uint8_t *tempBuf= NULL;
!     
!     POST_PARAMTASK(postProcessBuffer,data);
!     gInBufferCount++;
!     
!     if( gInBufferCount < gBufferCountMax){
!       tempBuf = getNextBuffer();
!     }
!     else{
!       //iff we're done, stop the ADC, stop DMA, let the last decimate run which should signal the upper layer
        TOSH_CLR_ADS1271_SYNC_PIN();
        return NULL;
      }
!     if(!tempBuf){
!       trace(DBG_USR1,"unable to obtain buffer %d\r\n", gInBufferCount);
!     }
!     return tempBuf;
!   }
!   
    event result_t BulkTxRx.BulkTransmitDone(uint8_t *data){
        return SUCCESS;
***************
*** 311,321 ****
    
    async event void TACHInterrupt.fired(){
!     static int32_t lastValue=0;
      int32_t currentValue,totalTime;
      currentValue = OSCR0;
      call TACHInterrupt.clear();
      totalTime = currentValue-lastValue;
!     trace("RPM = %d\r\n",195000000/totalTime);
      lastValue = currentValue;
    } 
  }
--- 471,506 ----
    
    async event void TACHInterrupt.fired(){
!     static norace int32_t lastValue=0;
      int32_t currentValue,totalTime;
      currentValue = OSCR0;
      call TACHInterrupt.clear();
      totalTime = currentValue-lastValue;
!     atomic{
!       gTotalTachTime += totalTime;
!       gTotalTachSamples++;
!     }
!     
      lastValue = currentValue;
    } 
+   
+   command result_t MDA440.startTach(){
+     atomic{
+       gTotalTachTime = 0;
+       gTotalTachSamples = 0;
+     }
+   }
+   
+   command result_t MDA440.stopTach(uint32_t *totalTime, uint32_t *totalSamples){
+     if(totalTime && totalSamples){
+       atomic{
+ 	*totalTime = gTotalTachTime;
+ 	*totalSamples = gTotalTachSamples;
+       }
+       return SUCCESS;
+     }
+     else{
+       return FAIL;
+     }
+   }
+   
  }

Index: TestMDA440.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/imote2/test/TestMDA440/TestMDA440.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** TestMDA440.nc	19 Sep 2005 21:08:26 -0000	1.3
--- TestMDA440.nc	9 Sep 2006 16:05:20 -0000	1.4
***************
*** 50,53 ****
--- 50,54 ----
    Main.StdControl -> TestMDA440M.StdControl;
    Main.StdControl -> MDA440C.StdControl;
+   Main.StdControl -> TimerC.StdControl;
    TestMDA440M.Timer -> TimerC.Timer[unique("Timer")];
    TestMDA440M.Leds -> LedsC;
***************
*** 56,59 ****
--- 57,62 ----
    
    TestMDA440M.UART -> HPLFFUARTC;
+ 
+   TestMDA440M.EEPROM -> MDA440C.EEPROM;
    //BlUSH miniapps
  
***************
*** 71,75 ****
--- 74,84 ----
    BluSHC.BluSH_AppI[unique("BluSH")] -> TestMDA440M.SetTempIn;
    BluSHC.BluSH_AppI[unique("BluSH")] -> TestMDA440M.SetCurrentIn;
+ 
+   BluSHC.BluSH_AppI[unique("BluSH")] -> TestMDA440M.StartRPMCapture;
+   BluSHC.BluSH_AppI[unique("BluSH")] -> TestMDA440M.StopRPMCapture;
   
+   BluSHC.BluSH_AppI[unique("BluSH")] -> TestMDA440M.ReadCal;
+   BluSHC.BluSH_AppI[unique("BluSH")] -> TestMDA440M.WriteCal;
+   
  }
  

Index: TestMDA440M.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/imote2/test/TestMDA440/TestMDA440M.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** TestMDA440M.nc	19 Sep 2005 21:08:26 -0000	1.3
--- TestMDA440M.nc	9 Sep 2006 16:05:20 -0000	1.4
***************
*** 54,57 ****
--- 54,63 ----
      interface BluSH_AppI as SetCurrentIn;
      
+     interface BluSH_AppI as StartRPMCapture;
+     interface BluSH_AppI as StopRPMCapture;
+ 
+     interface BluSH_AppI as ReadCal;
+     interface BluSH_AppI as WriteCal;
+     
    }
    uses {
***************
*** 60,63 ****
--- 66,70 ----
      interface MDA440;
      interface HPLUART as UART;
+     interface EEPROM;
    }
  }
***************
*** 71,80 ****
    
    //I'm being lazy for now....UARTBUFFERLEN MUST BE 2x NUMSAMPLES
! #define UARTBUFFERLEN (20000)
! #define NUMSAMPLES (10000)  
    
    uint8_t dataBuffer[UARTBUFFERLEN] __attribute__((aligned(32)));
!     uint16_t dataBufferPos = 0;
!     
      command result_t StdControl.init() {
        call MDA440.init();
--- 78,88 ----
    
    //I'm being lazy for now....UARTBUFFERLEN MUST BE 2x NUMSAMPLES
! #define NUMSAMPLES (16384)  
! #define UARTBUFFERLEN (NUMSAMPLES*2)
! 
    
    uint8_t dataBuffer[UARTBUFFERLEN] __attribute__((aligned(32)));
!   uint32_t dataBufferPos = UARTBUFFERLEN;
!   
      command result_t StdControl.init() {
        call MDA440.init();
***************
*** 137,141 ****
  	  _PXA_setaltfn(gpio,0,GPIO_OUT);
  	  _PXA_clrgpio(gpio);
! 	  trace("ClearGPIO DONE\r\n",gpio);
        }
        *resBuff = 0;
--- 145,149 ----
  	  _PXA_setaltfn(gpio,0,GPIO_OUT);
  	  _PXA_clrgpio(gpio);
! 	  trace(DBG_USR1,"ClearGPIO DONE\r\n",gpio);
        }
        *resBuff = 0;
***************
*** 160,164 ****
  	_PXA_setaltfn(gpio,0,GPIO_OUT);
  	_PXA_setgpio(gpio);
! 	trace("SetGPIO DONE\r\n",gpio);
        }
        *resBuff = 0;
--- 168,172 ----
  	_PXA_setaltfn(gpio,0,GPIO_OUT);
  	_PXA_setgpio(gpio);
! 	trace(DBG_USR1,"SetGPIO DONE\r\n",gpio);
        }
        *resBuff = 0;
***************
*** 176,180 ****
      call MDA440.turnOffBoard();
      *resBuff = 0;
!     trace("Board Turned Off\r\n");
      return BLUSH_SUCCESS_DONE;
    }
--- 184,188 ----
      call MDA440.turnOffBoard();
      *resBuff = 0;
!     trace(DBG_USR1,"Board Turned Off\r\n");
      return BLUSH_SUCCESS_DONE;
    }
***************
*** 189,193 ****
  						      char *resBuff, uint8_t resLen){
      call MDA440.enableHighSpeedChain();
!     trace("High Speed Chain Enabled\r\n");
      *resBuff = 0;
      return BLUSH_SUCCESS_DONE;
--- 197,201 ----
  						      char *resBuff, uint8_t resLen){
      call MDA440.enableHighSpeedChain();
!     trace(DBG_USR1,"High Speed Chain Enabled\r\n");
      *resBuff = 0;
      return BLUSH_SUCCESS_DONE;
***************
*** 203,207 ****
  						       char *resBuff, uint8_t resLen){
      call MDA440.disableHighSpeedChain();
!     trace("High Speed Chain Disabled\r\n");
      *resBuff = 0;
      return BLUSH_SUCCESS_DONE;
--- 211,215 ----
  						       char *resBuff, uint8_t resLen){
      call MDA440.disableHighSpeedChain();
!     trace(DBG_USR1,"High Speed Chain Disabled\r\n");
      *resBuff = 0;
      return BLUSH_SUCCESS_DONE;
***************
*** 224,228 ****
        sscanf(cmdBuff,"SelectMux0Channel %d", &num);
        call MDA440.selectMux0Channel(num);
!       trace("Setting Mux0 Channel to %.3d\r\n",num);
      }
      *resBuff = 0;
--- 232,236 ----
        sscanf(cmdBuff,"SelectMux0Channel %d", &num);
        call MDA440.selectMux0Channel(num);
!       trace(DBG_USR1,"Setting Mux0 Channel to %.3d\r\n",num);
      }
      *resBuff = 0;
***************
*** 240,244 ****
  						     char *resBuff, uint8_t resLen){
      call MDA440.enableLowSpeedChain(); 
!     trace("Low Speed Chain Enabled\r\n");
      *resBuff = 0;
      return BLUSH_SUCCESS_DONE;
--- 248,252 ----
  						     char *resBuff, uint8_t resLen){
      call MDA440.enableLowSpeedChain(); 
!     trace(DBG_USR1,"Low Speed Chain Enabled\r\n");
      *resBuff = 0;
      return BLUSH_SUCCESS_DONE;
***************
*** 254,258 ****
  						      char *resBuff, uint8_t resLen){
      call MDA440.disableLowSpeedChain();
!     trace("Low Speed Chain Disabled\r\n");
      *resBuff = 0;
      return BLUSH_SUCCESS_DONE;
--- 262,266 ----
  						      char *resBuff, uint8_t resLen){
      call MDA440.disableLowSpeedChain();
!     trace(DBG_USR1,"Low Speed Chain Disabled\r\n");
      *resBuff = 0;
      return BLUSH_SUCCESS_DONE;
***************
*** 276,280 ****
        sscanf(cmdBuff,"SelectLowSpeedChannel %d", &num);
        call MDA440.selectLowSpeedChannel(num);
!       trace("Setting Low Speed Channel to %.3d\r\n",num);
      }
      *resBuff = 0;
--- 284,288 ----
        sscanf(cmdBuff,"SelectLowSpeedChannel %d", &num);
        call MDA440.selectLowSpeedChannel(num);
!       trace(DBG_USR1,"Setting Low Speed Channel to %.3d\r\n",num);
      }
      *resBuff = 0;
***************
*** 299,303 ****
        sscanf(cmdBuff,"SetAccelIn %d", &num);
        call MDA440.setAccelIn(num);
!       trace("Setting Accel Channel to %.3d\r\n",num);
      }
      *resBuff = 0;
--- 307,311 ----
        sscanf(cmdBuff,"SetAccelIn %d", &num);
        call MDA440.setAccelIn(num);
!       trace(DBG_USR1,"Setting Accel Channel to %.3d\r\n",num);
      }
      *resBuff = 0;
***************
*** 322,326 ****
        sscanf(cmdBuff,"SetTempIn %d", &num);
        call MDA440.setTempIn(num);
!       trace("Setting Accel Channel to %.3d\r\n",num);
      }
      *resBuff = 0;
--- 330,334 ----
        sscanf(cmdBuff,"SetTempIn %d", &num);
        call MDA440.setTempIn(num);
!       trace(DBG_USR1,"Setting Accel Channel to %.3d\r\n",num);
      }
      *resBuff = 0;
***************
*** 345,349 ****
        sscanf(cmdBuff,"SetCurrentIn %d", &num);
        call MDA440.setCurrentIn(num);
!       trace("Setting Current Channel to %.3d\r\n",num);
        *resBuff = 0;
      }
--- 353,357 ----
        sscanf(cmdBuff,"SetCurrentIn %d", &num);
        call MDA440.setCurrentIn(num);
!       trace(DBG_USR1,"Setting Current Channel to %.3d\r\n",num);
        *resBuff = 0;
      }
***************
*** 361,376 ****
    task void putDataTask(){
      uint8_t * data8ptr = (uint8_t *)dataBuffer;
!       if(dataBufferPos < UARTBUFFERLEN){
! 	call UART.put(data8ptr[dataBufferPos]);
! 	dataBufferPos++;
!       }
    }
! 
    
    command BluSH_result_t GetData.callApp(char *cmdBuff, uint8_t cmdLen,
! 						      char *resBuff, uint8_t resLen){
!     call MDA440.getSamples(dataBuffer, NUMSAMPLES);
!     trace("Getting 1k samples\r\n");
!     *resBuff = 0;
      return BLUSH_SUCCESS_DONE;
    }
--- 369,391 ----
    task void putDataTask(){
      uint8_t * data8ptr = (uint8_t *)dataBuffer;
!     if(dataBufferPos < UARTBUFFERLEN){
!       call UART.put(data8ptr[dataBufferPos]);
!       dataBufferPos++;
!     }
    }
!   
    
    command BluSH_result_t GetData.callApp(char *cmdBuff, uint8_t cmdLen,
! 					 char *resBuff, uint8_t resLen){
!     uint32_t K;
!     if(strlen(cmdBuff) > strlen("GetData ")){
!       sscanf(cmdBuff,"GetData %d", &K);
!       call MDA440.getSamples(dataBuffer, NUMSAMPLES, K);
!       trace(DBG_USR1,"Getting %d samples decimated by %d\r\n", NUMSAMPLES,K);
!     }
!     else{
!       call MDA440.getSamples(dataBuffer, NUMSAMPLES, 1);
!       trace(DBG_USR1,"Getting %d samples\r\n", NUMSAMPLES);
!     }
      return BLUSH_SUCCESS_DONE;
    }
***************
*** 379,384 ****
    event result_t MDA440.getSamplesDone(uint8_t *buffer){
      uint16_t *temp = (uint16_t *)dataBuffer;
!     trace("got samples %#x %#x %#x %#x %#x % #x %#x %#x %#x %#x !!!\r\n", temp[0], temp[1], temp[2], temp[3], temp[4], temp[5], temp[6], temp[7], temp[8], temp[9]);
!     dataBufferPos = 0;//2000;
      post putDataTask();
      return SUCCESS;
--- 394,399 ----
    event result_t MDA440.getSamplesDone(uint8_t *buffer){
      uint16_t *temp = (uint16_t *)dataBuffer;
!     trace(DBG_USR1,"got samples %#x %#x %#x %#x %#x % #x %#x %#x %#x %#x !!!\r\n", temp[0], temp[1], temp[2], temp[3], temp[4], temp[5], temp[6], temp[7], temp[8], temp[9]);
!     dataBufferPos = 0;
      post putDataTask();
      return SUCCESS;
***************
*** 395,398 ****
      return SUCCESS;
    }
- }
  
--- 410,492 ----
      return SUCCESS;
    }
  
+   command BluSH_result_t StartRPMCapture.getName(char *buff, uint8_t len){
+       
+     const char name[] = "StartRPMCapture";
+     strcpy(buff,name);
+     return BLUSH_SUCCESS_DONE;
+   }
+ 
+   command BluSH_result_t StartRPMCapture.callApp(char *cmdBuff, uint8_t cmdLen,
+ 						   char *resBuff, uint8_t resLen){
+     call MDA440.startTach();
+     trace(DBG_USR1,"StartRPMCapture DONE\r\n");
+     return BLUSH_SUCCESS_DONE;
+   }
+ 
+   command BluSH_result_t StopRPMCapture.getName(char *buff, uint8_t len){
+       
+     const char name[] = "StopRPMCapture";
+     strcpy(buff,name);
+     return BLUSH_SUCCESS_DONE;
+   }
+ 
+   command BluSH_result_t StopRPMCapture.callApp(char *cmdBuff, uint8_t cmdLen,
+ 						   char *resBuff, uint8_t resLen){
+     uint32_t totalTime, totalSamples;
+     result_t res;
+     res = call MDA440.stopTach(&totalTime, &totalSamples);
+     
+     if(res == SUCCESS && totalSamples){
+       float temp;
+       temp = (float)totalTime/(float)totalSamples;
+       trace(DBG_USR1,"StopRPMCapture %f\r\n",195000000.0 /temp);
+     }
+     else{
+       trace(DBG_USR1,"StopRPMCapture 0.0\r\n");
+     }
+     
+     return BLUSH_SUCCESS_DONE;
+   }
+ 
+   command BluSH_result_t ReadCal.getName(char *buff, uint8_t len){
+       
+     const char name[] = "ReadCal";
+     strcpy(buff,name);
+     return BLUSH_SUCCESS_DONE;
+   }
+ 
+   command BluSH_result_t ReadCal.callApp(char *cmdBuff, uint8_t cmdLen,
+ 						   char *resBuff, uint8_t resLen){
+     
+     uint32_t val;
+     
+     call EEPROM.read(0,(uint8_t *)&val,4);
+     trace(DBG_USR1,"ReadCal %#x\r\n",val);
+     return BLUSH_SUCCESS_DONE;
+   }
+ 
+   command BluSH_result_t WriteCal.getName(char *buff, uint8_t len){
+       
+     const char name[] = "WriteCal";
+     strcpy(buff,name);
+     return BLUSH_SUCCESS_DONE;
+   }
+ 
+   command BluSH_result_t WriteCal.callApp(char *cmdBuff, uint8_t cmdLen,
+ 						   char *resBuff, uint8_t resLen){
+     uint32_t val;
+     
+     if(strlen(cmdBuff) < strlen("WriteCal  ")){
+       trace(DBG_USR1,"WriteCal FAIL\r\n");
+     }
+     else{
+       sscanf(cmdBuff,"WriteCal %x",&val);
+       call EEPROM.write(0,(uint8_t *)&val,4);
+       trace(DBG_USR1,"WriteCal DONE\r\n");
+       return BLUSH_SUCCESS_DONE;
+     }
+   }
+ 
+ }
+   



More information about the Tinyos-contrib-commits mailing list