[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/imote2/tos/sensorboards/AVboard Audio.nc, 1.1, 1.2 intel16.h, 1.1, 1.2 WM8940.h, 1.1, 1.2 WM8940C.nc, 1.1, 1.2 WM8940M.nc, 1.1, 1.2

Robbie Adler radler at users.sourceforge.net
Sun Nov 23 20:06:45 PST 2008


Update of /cvsroot/tinyos/tinyos-1.x/contrib/imote2/tos/sensorboards/AVboard
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv31709

Modified Files:
	Audio.nc intel16.h WM8940.h WM8940C.nc WM8940M.nc 
Log Message:
updates to WM8940 driver to allow for programmatic play and record through audio interface

Index: Audio.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/imote2/tos/sensorboards/AVboard/Audio.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Audio.nc	23 Nov 2008 00:35:06 -0000	1.1
--- Audio.nc	24 Nov 2008 04:06:43 -0000	1.2
***************
*** 9,13 ****
     *platform audio interface
     ****************************************/
!  
    /**
     *mute playback on the port
--- 9,22 ----
     *platform audio interface
     ****************************************/
!   /**
!    *Codec is ready to playback or record
!    *
!    *
!    *
!    *
!    **/
! 
!   event void ready(result_t success);
!   
    /**
     *mute playback on the port
***************
*** 19,23 ****
  
    command result_t mute(bool enable);
!   event result_t muteDone(result_t success);
      
    
--- 28,32 ----
  
    command result_t mute(bool enable);
!   event void muteDone(result_t success);
      
    
***************
*** 53,55 ****
--- 62,79 ----
    command result_t audioPlay(uint32_t *buffer, uint32_t numSamples);
    event void audioPlayDone(uint32_t *buffer, uint32_t numSamples);
+ 
+ 
+   /**
+    *start the recording of stereo data.   
+    *
+    *@param buffer:  buffer to store samples into.  Samples are 16bit stereo samples packed into a 32-bit word.  Left samples are in the low 16 bits.  Right samples are in the high 16 bits.  Must be
+    *                alligned on a 32byte boundary and have length that is integral number of 32 bytes
+    *@param numSamples:  total number of samples to record.  Since samples are effectively 32 bits, buffer must be sized appropriately.
+    *
+    *@return FAIL if error, SUCCESS otherwise
+    **/
+   command result_t audioRecord(uint32_t *buffer, uint32_t numSamples);
+   event void audioRecordDone(uint32_t *buffer, uint32_t numSamples);
+ 
+ 
  }

Index: intel16.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/imote2/tos/sensorboards/AVboard/intel16.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** intel16.h	23 Nov 2008 00:35:06 -0000	1.1
--- intel16.h	24 Nov 2008 04:06:43 -0000	1.2
***************
*** 1,2 ****
--- 1,7 ----
+ /**
+  * @author Robbie Adler
+  **/
+ 
+ 
  #ifndef __INTEL16_WAV_H__			
  #define __INTEL16_WAV_H__			

Index: WM8940.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/imote2/tos/sensorboards/AVboard/WM8940.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** WM8940.h	23 Nov 2008 00:35:06 -0000	1.1
--- WM8940.h	24 Nov 2008 04:06:43 -0000	1.2
***************
*** 1,2 ****
--- 1,6 ----
+ /**
+  * @author Robbie Adler
+  **/
+ 
  #ifndef __WM8940_H__
  #define __WM8940_H__
***************
*** 8,12 ****
  //writing of POWERMANAGEMENT1
  #define POWERMANAGEMENT1_VMID_OP_EN         (1<<8)
! #define POWERMANAGEMENT1_LVLSHIFT_EN          (1<<7)
  #define POWERMANAGEMENT1_AUXEN              (1<<6)
  #define POWERMANAGEMENT1_PLLEN              (1<<5)
--- 12,16 ----
  //writing of POWERMANAGEMENT1
  #define POWERMANAGEMENT1_VMID_OP_EN         (1<<8)
! #define POWERMANAGEMENT1_LVLSHIFT_EN        (1<<7)
  #define POWERMANAGEMENT1_AUXEN              (1<<6)
  #define POWERMANAGEMENT1_PLLEN              (1<<5)
***************
*** 19,22 ****
--- 23,29 ----
  
  #define POWERMANAGEMENT2 (2)
+ #define POWERMANAGEMENT2_BOOSTEN           (1<<4)
+ #define POWERMANAGEMENT2_INPPGAEN          (1<<2)
+ #define POWERMANAGEMENT2_ADCEN             (1)
  
  #define POWERMANAGEMENT3 (3)
***************
*** 68,73 ****
--- 75,85 ----
  
  #define ADCCONTROL (14)
+ #define ADCCONTROL_HPFEN                    (1<<8)
+ #define ADCCONTROL_HPFAPP                   (1<<7)
+ #define ADCCONTROL_HPFCUT(_x)               ( ((_x) & 0x7) << 4)
+ #define ADCCONTROL_ADCPOL                   (1)
  
  #define ADCDIGITALVOLUME (15)
+ #define ADCDIGITALVOLUME_ADCVOL(_x)         ( (_x) & 0xFF
  
  #define NOTCHFILTER1 (16)
***************
*** 84,87 ****
--- 96,101 ----
  
  #define ALCCONTROL1  (32)
+ #define ALCCONTROL1_ALCSEL                    (1<<8)
+ 
  #define ALCCONTROL2  (33)
  #define ALCCONTROL3  (34)
***************
*** 96,100 ****
  
  #define INPUTCTRL    (44)
! #define INPPGAGAINCTROL (45)
  
  #define OUTPUTCTRL  (49)
--- 110,129 ----
  
  #define INPUTCTRL    (44)
! 
! #define INPUTCTRL_MBVSEL                      (1<<8)
! #define INPUTCTRL_AUX2INPPGA                  (1<<2)
! #define INPUTCTRL_MICN2INPPGA                 (1<<1)
! #define INPUTCTRL_MICP2INPPGA                 (1)
! 
! #define INPPGAGAINCTRL (45)
! #define INPPGAGAINCTRL_INPPGAZC              (1<<7)
! #define INPPGAGAINCTRL_INPPGAMUTE            (1<<6)
! #define INPPGAGAINCTRL_INPPGAVOL(_x)         ( (_x) & 0x3F)
! 
! #define ADCBOOSTCTRL (47)
! #define ADCBOOSTCTRL_PGABOOST                 (1<<8)
! #define ADCBOOSTCTRL_MICP2BOOSTVOL(_x)        ( ((_x) & 0x7) << 4)
! #define ADCBOOSTCTRL_AUX2BOOSTVOL(_x)         ( ((_x) & 0x7))
! 
  
  #define OUTPUTCTRL  (49)

Index: WM8940C.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/imote2/tos/sensorboards/AVboard/WM8940C.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** WM8940C.nc	23 Nov 2008 00:35:06 -0000	1.1
--- WM8940C.nc	24 Nov 2008 04:06:43 -0000	1.2
***************
*** 2,5 ****
--- 2,6 ----
    provides{
      interface StdControl;
+     interface Audio;
    }
  }
***************
*** 11,14 ****
--- 12,16 ----
    
    StdControl = WM8940M.StdControl;
+   Audio = WM8940M.Audio;
    WM8940M.I2S -> I2SC.I2S;
    WM8940M.BulkTxRx -> I2SC.BulkTxRx;

Index: WM8940M.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/imote2/tos/sensorboards/AVboard/WM8940M.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** WM8940M.nc	23 Nov 2008 00:35:06 -0000	1.1
--- WM8940M.nc	24 Nov 2008 04:06:43 -0000	1.2
***************
*** 45,54 ****
    uint8_t gPowerOnState = 0;
    I2CState_t gI2CState = I2CState_IDLE;
    
!   norace uint32_t *gRxBuffer;
    norace uint16_t gRxNumBytes, gRxBufferPos;
    
!   uint32_t gTxBuffer[TEST_LEN] __attribute__((aligned(32)));
!   uint32_t gTxNumBytes, gTxBufferPos;
  
    i2c_op_t I2CRegisterSequence[] = { 
--- 45,55 ----
    uint8_t gPowerOnState = 0;
    I2CState_t gI2CState = I2CState_IDLE;
+   norace bool gInitPlay = TRUE;
    
!   uint32_t *gRxBuffer;
    norace uint16_t gRxNumBytes, gRxBufferPos;
    
!   uint32_t *gTxBuffer;
!   norace uint32_t gTxNumBytes, gTxBufferPos;
  
    i2c_op_t I2CRegisterSequence[] = { 
***************
*** 101,109 ****
      
      trace(DBG_USR1,"Completed WM8940 PowerOn Sequence\r\n");
!     call I2S.enableRecord(FALSE);
      call I2S.enablePlayback(TRUE);
      call I2S.enableI2S(TRUE);
      
!     gTxBufferPos = 0;
      call BulkTxRx.BulkTransmit((uint8_t *)pcmdata, (pcmdatalen > 8188)? 8188: pcmdatalen);
    }
--- 102,120 ----
      
      trace(DBG_USR1,"Completed WM8940 PowerOn Sequence\r\n");
!     call I2S.enableRecord(TRUE);
      call I2S.enablePlayback(TRUE);
      call I2S.enableI2S(TRUE);
      
!     atomic{
!       gTxBufferPos = 0;
!       gTxBuffer = pcmdata;
!       gTxNumBytes = pcmdatalen;
!       
!       gRxBufferPos = 0;
!       gRxBuffer = NULL;
!       gRxNumBytes = 0;
!       
!     }
!     
      call BulkTxRx.BulkTransmit((uint8_t *)pcmdata, (pcmdatalen > 8188)? 8188: pcmdatalen);
    }
***************
*** 136,140 ****
       *16.) Disable DAC soft mute (DACMU = 0)
       *
!      *
       **/
      
--- 147,158 ----
       *16.) Disable DAC soft mute (DACMU = 0)
       *
!      *17.) TODO!!!  ADD initialization for record path (not included on page 64)...rough flow is below
!      *18.) Configure Mic biasing
!      *19.) Configure input PGA settings
!      *20.) Configure boost circuit
!      *21.) Set ADC volume
!      *22.) enable ADC
!      
!      
       **/
      
***************
*** 143,147 ****
        //Reset internal registers with SW reset command
        address = SOFTWARERESET;
!       data = 0;//norace hack!!!
  
        break;
--- 161,165 ----
        //Reset internal registers with SW reset command
        address = SOFTWARERESET;
!       data = 0;
  
        break;
***************
*** 194,198 ****
        // enable analogue amplifier bias control (BIASEN = 1) and VMID buffer (BUFIOEN = 1)
        address = POWERMANAGEMENT1;
!       data = POWERMANAGEMENT1_VMID_OP_EN | POWERMANAGEMENT1_LVLSHIFT_EN | POWERMANAGEMENT1_VMIDSEL(1) | POWERMANAGEMENT1_BIASEN | POWERMANAGEMENT1_BUFIOEN;
        break;
      
--- 212,216 ----
        // enable analogue amplifier bias control (BIASEN = 1) and VMID buffer (BUFIOEN = 1)
        address = POWERMANAGEMENT1;
!       data = POWERMANAGEMENT1_VMID_OP_EN | POWERMANAGEMENT1_LVLSHIFT_EN | POWERMANAGEMENT1_VMIDSEL(1) | POWERMANAGEMENT1_BIASEN | POWERMANAGEMENT1_BUFIOEN | POWERMANAGEMENT1_MICBEN;
        break;
      
***************
*** 317,322 ****
        //data for DAC and ADC are in left phase.  This should put data in lower 16 bits of I2S FIFO
        break;
! 
      case 29:
        //we're done!
        gPowerOnState = 0;
--- 335,364 ----
        //data for DAC and ADC are in left phase.  This should put data in lower 16 bits of I2S FIFO
        break;
!       
      case 29:
+       //connect microphone to input PGA
+       address = INPUTCTRL;
+       data  = INPUTCTRL_MICN2INPPGA | INPUTCTRL_MICP2INPPGA;
+       break;
+       
+     case 30:
+       //enable input PGA, ADC, and BOOST
+       address = POWERMANAGEMENT2;
+       data = POWERMANAGEMENT2_INPPGAEN | POWERMANAGEMENT2_ADCEN | POWERMANAGEMENT2_BOOSTEN;
+       break;
+ 
+     case 31:
+       //set pga volume to max, disable pga mute, set pga to update on first zero crossing
+       address = INPPGAGAINCTRL;
+       data = INPPGAGAINCTRL_INPPGAZC | INPPGAGAINCTRL_INPPGAVOL(0x3F);
+       break;
+          
+     case 32:
+       //set the adc digital attenuation to 0db (value of 0xFF)
+       address = ADCDIGITALVOLUME;
+       data = 0xFF;
+       break;
+       
+     case 33:
        //we're done!
        gPowerOnState = 0;
***************
*** 335,339 ****
        if(writeRegister(address, data) == FAIL){
  	post continuePowerOnSequence();
!       }
        else{
  	gPowerOnState++;
--- 377,381 ----
        if(writeRegister(address, data) == FAIL){
  	post continuePowerOnSequence();
!       }  
        else{
  	gPowerOnState++;
***************
*** 347,351 ****
    }
    command result_t StdControl.init(){
-     int i;
      /**
       *
--- 389,392 ----
***************
*** 366,383 ****
       *
       **/
!     for(i =0; i< TEST_LEN; i++){
!       
!       //make our data signal...just a 100Hz sin
!       //values should be in lower 16 bits, but should be stored as 32 bits
! #if 0
!       int16_t data = (int16_t)(32767.0*sin(2*3.14159265*100*i/TEST_LEN)); 
!       gTxBuffer[i] = (data & 0xFFFF) | ((data & 0xFFFF)<<16);
! #else
!       gTxBuffer[i] = 0xFFFF0000;
! #endif
!     }
!     gTxNumBytes = TEST_LEN*4;
!     //cleanDCache((uint8_t *)gTxBuffer, gTxNumBytes);
!     
      call I2CSequenceControl.init();
      call I2S.setAudioClkDivider(PXA_SYSCLK);
--- 407,411 ----
       *
       **/
! 
      call I2CSequenceControl.init();
      call I2S.setAudioClkDivider(PXA_SYSCLK);
***************
*** 433,468 ****
    event void I2S.initI2SDone(){
      //host interface to codec is initialized.  now initialize the actual codec
! #if 1
      if(issuePowerOnSequence() == FAIL){
        trace(DBG_USR1,"WM8940.issuePowerOnSequence() failed\r\n");
      }
- #else
-     call I2S.enableRecord(FALSE);
-     call I2S.enablePlayback(TRUE);
-     call I2S.enableI2S(TRUE);
-     
-     gTxBufferPos = 0;
-     call BulkTxRx.BulkTransmit((uint8_t *)pcmdata, (pcmdatalen > 8188)? 8188: pcmdatalen);
- #endif
    }
    
!   task void BulkReceiveDone(){
!     //needs to be protected....but needs to be rewritten anyway to use more than one buffer
!     //this is only here as a reminder that invalidateDCache must be called on the buffer after
!     //it's been received
!     invalidateDCache((uint8_t *)gRxBuffer, gRxNumBytes);
      
    }
    
    async event uint8_t *BulkTxRx.BulkReceiveDone(uint8_t *RxBuffer, uint16_t NumBytes){
      
!     gRxBuffer = (uint32_t*)RxBuffer;
!     gRxNumBytes = NumBytes;
      
!     return NULL;
! 
    }
    
    task void transmitDone(){
      uint32_t pos;
  
--- 461,507 ----
    event void I2S.initI2SDone(){
      //host interface to codec is initialized.  now initialize the actual codec
! 
      if(issuePowerOnSequence() == FAIL){
        trace(DBG_USR1,"WM8940.issuePowerOnSequence() failed\r\n");
      }
    }
    
!   task void recordDone(){
!     uint32_t *buffer;
!     uint32_t numBytes;
! 
!     
!     atomic{
!       buffer = gRxBuffer;
!       gRxBuffer = NULL;
!     
!       gRxBufferPos = 0;
! 
!       numBytes = gRxNumBytes;
!       gRxNumBytes = 0;
!     }
!     invalidateDCache((uint8_t *)buffer, numBytes);
! 
!     signal Audio.audioRecordDone(buffer, numBytes/4);
      
    }
    
+ 
    async event uint8_t *BulkTxRx.BulkReceiveDone(uint8_t *RxBuffer, uint16_t NumBytes){
      
!     //gRxBufferPos and gRxNumBytes protected by ARM ISR
!     gRxBufferPos += NumBytes;
      
!     if(gRxBufferPos >= gRxNumBytes){
! 	post recordDone();
! 	return NULL;
!       }
!     else{
!       return (uint8_t *)gRxBuffer + gRxBufferPos;
!     }
    }
    
    task void transmitDone(){
+     //debugging task
      uint32_t pos;
  
***************
*** 474,490 ****
    }
    
    async event uint8_t *BulkTxRx.BulkTransmitDone(uint8_t *TxBuffer, uint16_t NumBytes){
!     post transmitDone();
        
      gTxBufferPos += NumBytes;
      
!     if(gTxBufferPos >= pcmdatalen){
!       return NULL;
      }
      else{
!       //call BulkTxRx.BulkTransmit((uint8_t *)(pcmdata+gTxBufferPos), ((pcmdatalen-gTxBufferPos) > 8188)? 8188: (pcmdatalen-gTxBufferPos));
!       return ((uint8_t *)pcmdata) + gTxBufferPos;
      }
-    
    }
      
--- 513,571 ----
    }
    
+   task void signalAudioReady(){
+     atomic{
+       gTxBuffer = NULL;
+       gTxNumBytes = 0;
+       gTxBufferPos = 0;
+     }
+     signal Audio.ready(SUCCESS);
+   }
+   
+ 
+   task void playbackDone(){
+     uint32_t *buffer;
+     uint32_t numBytes;
+ 
+     
+     atomic{
+       buffer = gTxBuffer;
+       gTxBuffer = NULL;
+     
+       gTxBufferPos = 0;
+ 
+       numBytes = gTxNumBytes;
+       gTxNumBytes = 0;
+     }
+     
+     signal Audio.audioPlayDone(buffer, numBytes/4);
+     
+   }
+   
+   
    async event uint8_t *BulkTxRx.BulkTransmitDone(uint8_t *TxBuffer, uint16_t NumBytes){
!     //post transmitDone();
        
      gTxBufferPos += NumBytes;
      
!     if(gInitPlay == TRUE){
!       if(gTxBufferPos >= gTxNumBytes){
! 	post signalAudioReady();
! 	gInitPlay = FALSE;
! 	return NULL;
!       }
!       else{
! 	return ((uint8_t *)pcmdata) + gTxBufferPos;
!       }
      }
      else{
!       if(gTxBufferPos >= gTxNumBytes){
! 	post playbackDone();
! 	return NULL;
!       }
!       else{
! 	//call BulkTxRx.BulkTransmit((uint8_t *)(pcmdata+gTxBufferPos), ((pcmdatalen-gTxBufferPos) > 8188)? 8188: (pcmdatalen-gTxBufferPos));
! 	return (uint8_t *)gTxBuffer + gTxBufferPos;
!       }
      }
    }
      
***************
*** 544,550 ****
    }
    
!   default event result_t Audio.muteDone(result_t success){
      
!     return success;
    }
    
--- 625,631 ----
    }
    
!   default event void Audio.muteDone(result_t success){
      
!     return;
    }
    
***************
*** 578,583 ****
  
    command result_t Audio.audioPlay(uint32_t *buffer, uint32_t numSamples){
      
!     return FAIL;
    }
    
--- 659,695 ----
  
    command result_t Audio.audioPlay(uint32_t *buffer, uint32_t numSamples){
+     uint32_t *pBuf;
+     uint32_t bufpos;
+     bool initPlay;
      
!     atomic{
!       initPlay = gInitPlay;
!     }
!     
!     if(initPlay == TRUE){
!       //gate the acceptance of a play command until we signal audio.ready();
!       return FAIL;
!     }
!     
!     atomic{
!       pBuf = gTxBuffer;
!       bufpos = gTxBufferPos;
!     }
!     
!     if( (bufpos != 0) || (pBuf != NULL)){
!       //gate acceptance due to ongoing play command
!       return FAIL;
!     }
!     
!     atomic{
!       gTxBuffer = buffer;
!       gTxBufferPos = 0;
!       gTxNumBytes = numSamples * 4;
!     }
!     cleanDCache((uint8_t *)buffer, numSamples * 4);
!     
!     call BulkTxRx.BulkTransmit((uint8_t *)buffer, ((numSamples*4) > 8188)? 8188: (numSamples*4));
!     
!     return SUCCESS;
    }
    
***************
*** 586,588 ****
--- 698,741 ----
      return;
    }
+ 
+   command result_t Audio.audioRecord(uint32_t *buffer, uint32_t numSamples){
+     uint32_t *pBuf;
+     uint32_t bufpos;
+     bool initPlay;
+     
+     atomic{
+       initPlay = gInitPlay;
+     }
+     
+     if(initPlay == TRUE){
+       //gate the acceptance of a record command until we signal audio.ready();
+       return FAIL;
+     }
+     
+     atomic{
+       pBuf = gRxBuffer;
+       bufpos = gRxBufferPos;
+     }
+     
+     if( (bufpos != 0) || (pBuf != NULL)){
+       //gate acceptance due to ongoing record command
+       return FAIL;
+     } 
+     
+     atomic{
+       gRxBuffer = buffer;
+       gRxBufferPos = 0;
+       gRxNumBytes = numSamples * 4;
+     }
+     
+     call BulkTxRx.BulkReceive((uint8_t *)buffer, ((numSamples*4) > 8188)? 8188: (numSamples*4));
+     
+     return SUCCESS;
+   }
+   
+   default event void Audio.audioRecordDone(uint32_t *buffer, uint32_t numSamples){
+     
+     return;
+   }
+ 
  }



More information about the Tinyos-contrib-commits mailing list