[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/imote2/tos/sensorboards/Common CoarseDecimationM.nc, 1.1, 1.2

Lama Nachman lnachman at users.sourceforge.net
Sun Mar 4 23:29:21 PST 2007


Update of /cvsroot/tinyos/tinyos-1.x/contrib/imote2/tos/sensorboards/Common
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv1178/Common

Modified Files:
	CoarseDecimationM.nc 
Log Message:
Pushed out internal tree


Index: CoarseDecimationM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/imote2/tos/sensorboards/Common/CoarseDecimationM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CoarseDecimationM.nc	25 Oct 2006 15:03:53 -0000	1.1
--- CoarseDecimationM.nc	5 Mar 2007 07:29:19 -0000	1.2
***************
*** 11,32 ****
  implementation{
  #include "paramtask.h"
  
! #ifndef MAX_COURSE_DECIMATION_CHANNELS
! #define MAX_COURSE_DECIMATION_CHANNELS (4)
  #endif
    
    void processBuffer(uint32_t arg);
    DEFINE_PARAMTASK(processBuffer);
    
!    
!   extern _PTR memalign(size_t, size_t) __attribute__((C,spontaneous));
!   
    typedef struct {
      uint32_t k;
      bool kValid;
      uint8_t width;
      bool widthValid;
      bool finished;
!     int outstandingCount;
    }collectionInfo_t;
  
--- 11,37 ----
  implementation{
  #include "paramtask.h"
+ #include "bufferManagementHelper.h"
  
! #ifndef MAX_COARSE_DECIMATION_CHANNELS
! #define MAX_COARSE_DECIMATION_CHANNELS (4)
  #endif
    
+ #define NUMBUFFERS (5)
+ 
    void processBuffer(uint32_t arg);
    DEFINE_PARAMTASK(processBuffer);
    
!   void signalGetSensorDataStopped(uint32_t dataChannel);
!   DEFINE_PARAMTASK(signalGetSensorDataStopped);
! 
    typedef struct {
      uint32_t k;
+     int outstandingCount;
+     
      bool kValid;
      uint8_t width;
      bool widthValid;
      bool finished;
!     bool producerStopped;
    }collectionInfo_t;
  
***************
*** 44,55 ****
      uint32_t numSamples;
      uint8_t dataChannel;
    } inDataBufferInfo_t;
    
!   outDataBufferInfo_t gOutDataInfo[MAX_COURSE_DECIMATION_CHANNELS];
   
!   collectionInfo_t gCollectionInfo[MAX_COURSE_DECIMATION_CHANNELS];
!   downsampleTempBuffer_t *downsampleTempBuffer[MAX_COURSE_DECIMATION_CHANNELS];
    downsampleStates_t gDownsampleStates[4];
  
    void processBuffer(uint32_t arg){
      uint8_t *ret;
--- 49,222 ----
      uint32_t numSamples;
      uint8_t dataChannel;
+     bool inuse;
    } inDataBufferInfo_t;
+ 
+   typedef struct{
+     uint8_t * buf;
+     uint32_t inuse;
+   } buffer_t;
    
!   inDataBufferInfo_t gInDataBufferInfo[MAX_COARSE_DECIMATION_CHANNELS][NUMBUFFERS];
!   buffer_t tempBuffers[MAX_COARSE_DECIMATION_CHANNELS][NUMBUFFERS];
!   
!   uint32_t gTotalBuffersProcessed = 0;
!   
!   bool areBuffersFree(uint8_t channel){
!     
!     int i;
!     bool ret = TRUE;
!     
!     atomic{
!       for(i=0;i<NUMBUFFERS; i++){
! 	if((tempBuffers[channel][i].inuse == TRUE) || (tempBuffers[channel][i].buf != NULL)){
! 	  ret = FALSE;
! 	}
!       }
!     }
!     return ret;
!   }
!   
!   uint32_t getBufferLevel(uint8_t channel){
!     int i;
!     uint32_t ret =0;
!     atomic{
!       for(i=0;i<NUMBUFFERS; i++){
! 	if(tempBuffers[channel][i].inuse == FALSE){
! 	  ret++;
! 	}
!       }
!     }
!     return ret;
!   }
!   
!   uint8_t *getNextBuffer(uint8_t channel){
!     int i;
!     uint8_t *ret = NULL;
!     atomic{
!       for(i=0;i<NUMBUFFERS; i++){
! 	if(tempBuffers[channel][i].inuse == FALSE){
! 	  tempBuffers[channel][i].inuse = TRUE;
! 	  ret = (uint8_t *)tempBuffers[channel][i].buf;
! 	  break;
! 	}
!       }
!     }
!     return ret;
!   }
!   
!   void returnBuffer(uint8_t channel,uint8_t *buf){
!     int i;
!     atomic{
!       for(i=0;i<NUMBUFFERS; i++){
! 	if(tempBuffers[channel][i].buf == buf){
! 	  tempBuffers[channel][i].inuse = FALSE;
! 	  break;
! 	}
!       }
!     }
!   }
!   
!   void releaseBuffers(uint8_t channel){
!     int i;
!     
!     atomic{
!       for(i=0;i<NUMBUFFERS; i++){
! 	assert(tempBuffers[channel][i].inuse == FALSE);
! 	
! 	FREE_DBG(__FILE__,"releaseBuffers",tempBuffers[channel][i].buf);
! 	free(tempBuffers[channel][i].buf);
! 	
! 	tempBuffers[channel][i].buf = NULL;
!       }
!     }
!   }  
!   
!   void initBuffers(uint8_t channel, size_t size){
!     int i;
!     atomic{
!       for(i=0;i<NUMBUFFERS; i++){
! 	assert(tempBuffers[channel][i].buf == NULL);
! 	tempBuffers[channel][i].inuse = FALSE;
! 	if(!(tempBuffers[channel][i].buf = memalign(32, DMA_BUFFER_SIZE(size))) ){
! 	  printFatalErrorMsg("Unable to Allocate memory for CoarseDecimation of size = ",1, DMA_BUFFER_SIZE(size));
! 	}
! 	MALLOC_DBG(__FILE__,"initBuffers",tempBuffers[channel][i].buf,DMA_BUFFER_SIZE(size)); 
!       }
!     }
!   }
!     
!   uint32_t getBIBufferLevel(uint8_t dataChannel){
!     int i;
!     uint32_t ret = 0;
!     atomic{
!       for(i=0;i<NUMBUFFERS; i++){
! 	if(gInDataBufferInfo[dataChannel][i].inuse == FALSE){
! 	  ret++;
! 	}
!       }
!     }
!     return ret;
!   }
!   
!   inDataBufferInfo_t *getNextBIBuffer(uint8_t dataChannel){
!     int i;
!     inDataBufferInfo_t *ret = NULL;
!     atomic{
!       for(i=0;i<NUMBUFFERS; i++){
! 	if(gInDataBufferInfo[dataChannel][i].inuse == FALSE){
! 	  gInDataBufferInfo[dataChannel][i].inuse = TRUE;
! 	  ret = &gInDataBufferInfo[dataChannel][i];
! 	  break;
! 	}
!       }
!     }
!     return ret;
!   }
!   
!   void returnBIBuffer(uint8_t dataChannel, inDataBufferInfo_t *pBI){
!     int i;
!     atomic{
!       for(i=0;i<NUMBUFFERS; i++){
! 	if(&gInDataBufferInfo[dataChannel][i] == pBI){
! 	  gInDataBufferInfo[dataChannel][i].inuse = FALSE;
! 	}
!       }
!     }
!   }
!   
!   void initBIBuffer(uint8_t dataChannel){
!     int i;
!     atomic{
!       for(i=0;i<NUMBUFFERS; i++){
! 	gInDataBufferInfo[dataChannel][i].inuse = FALSE;
!       }
!     }
!   }
! 
!   
!   outDataBufferInfo_t gOutDataInfo[MAX_COARSE_DECIMATION_CHANNELS];
   
!   collectionInfo_t gCollectionInfo[MAX_COARSE_DECIMATION_CHANNELS];
!   downsampleTempBuffer_t *downsampleTempBuffer[MAX_COARSE_DECIMATION_CHANNELS];
    downsampleStates_t gDownsampleStates[4];
  
+   void signalGetSensorDataStopped(uint32_t dataChannel){
+     
+     assert(gCollectionInfo[dataChannel].finished);
+     assert(gCollectionInfo[dataChannel].producerStopped);
+     
+     trace(DBG_USR1,"upper levels =  %d %d\r\n",getBufferLevel(dataChannel), getBIBufferLevel(dataChannel));
+     
+     if( (getBufferLevel(dataChannel) == NUMBUFFERS) && (getBIBufferLevel(dataChannel) == NUMBUFFERS)){
+       //make sure we're not calling this twice
+       assert(areBuffersFree(dataChannel) == FALSE);
+       releaseBuffers(dataChannel);
+       FREE_DBG(__FILE__,"signalGetSensorDataStopped",downsampleTempBuffer[dataChannel]);
+       free(downsampleTempBuffer[dataChannel]);
+ 
+       signal OutData.getSensorDataStopped[dataChannel]();
+     }
+   }
+   
    void processBuffer(uint32_t arg){
      uint8_t *ret;
***************
*** 58,61 ****
--- 225,229 ----
      uint8_t dataChannel;
      
+ 
      pBI = (inDataBufferInfo_t *)arg;
      
***************
*** 69,74 ****
      gCollectionInfo[dataChannel].outstandingCount--;
      if(gCollectionInfo[dataChannel].finished){
!       free(pBI->buffer);
!       free(pBI);
        return;
      }
--- 237,245 ----
      gCollectionInfo[dataChannel].outstandingCount--;
      if(gCollectionInfo[dataChannel].finished){
!       returnBuffer(dataChannel, pBI->buffer);
!       returnBIBuffer(dataChannel,pBI);
!       if(gCollectionInfo[dataChannel].producerStopped == TRUE){
! 	POST_PARAMTASK(signalGetSensorDataStopped, dataChannel);
!       }
        return;
      }
***************
*** 94,98 ****
      if(ret == NULL){
        //we're done!
-       free(downsampleTempBuffer[dataChannel]);
        gCollectionInfo[dataChannel].kValid = FALSE;
        gCollectionInfo[dataChannel].widthValid = FALSE;
--- 265,268 ----
***************
*** 102,107 ****
        gOutDataInfo[dataChannel].buffer = ret;
      }
!     free(pBI->buffer);
!     free(pBI);
      return;
    }
--- 272,278 ----
        gOutDataInfo[dataChannel].buffer = ret;
      }
!     returnBuffer(dataChannel,pBI->buffer);
!     returnBIBuffer(dataChannel,pBI);
!     
      return;
    }
***************
*** 109,116 ****
    
    command result_t OutData.getOutputUOM[uint8_t dataChannel](uint8_t *UOM){
!     if(dataChannel < MAX_COURSE_DECIMATION_CHANNELS){
        return call InData.getOutputUOM[dataChannel](UOM);
      }
!     else{
        return FAIL;
      }
--- 280,287 ----
    
    command result_t OutData.getOutputUOM[uint8_t dataChannel](uint8_t *UOM){
!     if(dataChannel < MAX_COARSE_DECIMATION_CHANNELS){
        return call InData.getOutputUOM[dataChannel](UOM);
      }
!    else{
        return FAIL;
      }
***************
*** 119,123 ****
  
    command result_t OutData.setSensorType[uint8_t dataChannel](uint32_t sensorType){
!     if(dataChannel < MAX_COURSE_DECIMATION_CHANNELS){
        return call InData.setSensorType[dataChannel](sensorType);
      }
--- 290,294 ----
  
    command result_t OutData.setSensorType[uint8_t dataChannel](uint32_t sensorType){
!     if(dataChannel < MAX_COARSE_DECIMATION_CHANNELS){
        return call InData.setSensorType[dataChannel](sensorType);
      }
***************
*** 128,132 ****
  
    command result_t OutData.setSamplingRate[uint8_t dataChannel](uint32_t requestedSamplingRate, uint32_t *actualSamplingRate){
!     if(dataChannel < MAX_COURSE_DECIMATION_CHANNELS){
        //see what the board will be returning us for this samplingRate
        if(call InData.setSamplingRate[dataChannel](requestedSamplingRate, actualSamplingRate) == SUCCESS){
--- 299,303 ----
  
    command result_t OutData.setSamplingRate[uint8_t dataChannel](uint32_t requestedSamplingRate, uint32_t *actualSamplingRate){
!     if(dataChannel < MAX_COARSE_DECIMATION_CHANNELS){
        //see what the board will be returning us for this samplingRate
        if(call InData.setSamplingRate[dataChannel](requestedSamplingRate, actualSamplingRate) == SUCCESS){
***************
*** 143,147 ****
    
    command result_t OutData.setSampleWidth[uint8_t dataChannel](uint8_t requestedSampleWidth){
!     if(dataChannel < MAX_COURSE_DECIMATION_CHANNELS){
        if(call InData.setSampleWidth[dataChannel](requestedSampleWidth)){
  	gCollectionInfo[dataChannel].width = requestedSampleWidth;
--- 314,318 ----
    
    command result_t OutData.setSampleWidth[uint8_t dataChannel](uint8_t requestedSampleWidth){
!     if(dataChannel < MAX_COARSE_DECIMATION_CHANNELS){
        if(call InData.setSampleWidth[dataChannel](requestedSampleWidth)){
  	gCollectionInfo[dataChannel].width = requestedSampleWidth;
***************
*** 160,164 ****
      uint32_t newNumSamples;
      
!     if(dataChannel < MAX_COURSE_DECIMATION_CHANNELS){
        if(gCollectionInfo[dataChannel].kValid == FALSE){
  	trace(DBG_USR1,"FATAL ERROR:  SensorData.setSamplingRate was not called on data channel %d\r\n",dataChannel);
--- 331,335 ----
      uint32_t newNumSamples;
      
!     if(dataChannel < MAX_COARSE_DECIMATION_CHANNELS){
        if(gCollectionInfo[dataChannel].kValid == FALSE){
  	trace(DBG_USR1,"FATAL ERROR:  SensorData.setSamplingRate was not called on data channel %d\r\n",dataChannel);
***************
*** 171,183 ****
        
        if(gCollectionInfo[dataChannel].outstandingCount != 0){
! 	trace(DBG_USR1,"FATAL ERROR:  CoarseDecimation found acquisition in progress on channel %d while trying to start a new one: outstandingCount = %d\r\n",dataChannel, gCollectionInfo[dataChannel].outstandingCount);
  	return FAIL;
        }
        
        downsampleTempBuffer[dataChannel] = memalign(8,(numSamples*gCollectionInfo[dataChannel].width*gCollectionInfo[dataChannel].k)/4);
!       if(downsampleTempBuffer[dataChannel] == NULL){
! 	trace(DBG_USR1,"FATAL ERROR:  Unable to allocate temporary downsampling buffer\r\n");
! 	return FAIL;
!       }
        
        downsampleInit(&gDownsampleStates[dataChannel],downsampleTempBuffer[dataChannel]); 
--- 342,353 ----
        
        if(gCollectionInfo[dataChannel].outstandingCount != 0){
! 		
! 	printFatalErrorMsg("CoarseDecimation found acquisition in progress while trying to start a new one: outstandingCount = ",1, gCollectionInfo[dataChannel].outstandingCount);
  	return FAIL;
        }
        
        downsampleTempBuffer[dataChannel] = memalign(8,(numSamples*gCollectionInfo[dataChannel].width*gCollectionInfo[dataChannel].k)/4);
!       MALLOC_DBG(__FILE__,"OutData.getSensorData",downsampleTempBuffer[dataChannel],(numSamples*gCollectionInfo[dataChannel].width*gCollectionInfo[dataChannel].k)/4); 
!       assert(downsampleTempBuffer[dataChannel]);
        
        downsampleInit(&gDownsampleStates[dataChannel],downsampleTempBuffer[dataChannel]); 
***************
*** 186,202 ****
        gOutDataInfo[dataChannel].numSamples = numSamples;
        
        newNumSamples = numSamples * gCollectionInfo[dataChannel].k;
!       newBuffer = memalign(32, newNumSamples * gCollectionInfo[dataChannel].width);
        
!       if(newBuffer){
! 	gCollectionInfo[dataChannel].finished = FALSE;
! 	gCollectionInfo[dataChannel].outstandingCount ++;
! 	return call InData.getSensorData[dataChannel](newBuffer, newNumSamples);
!       }
!       else{
! 	free(downsampleTempBuffer[dataChannel]);
! 	trace(DBG_USR1,"FATAL ERROR:  Unable to allocate downsampling buffer\r\n");
! 	return FAIL;
!       }
      }
      else{
--- 356,369 ----
        gOutDataInfo[dataChannel].numSamples = numSamples;
        
+       gCollectionInfo[dataChannel].producerStopped = FALSE;
        newNumSamples = numSamples * gCollectionInfo[dataChannel].k;
!       initBuffers(dataChannel, newNumSamples * gCollectionInfo[dataChannel].width);
        
!       newBuffer = getNextBuffer(dataChannel);
!       
!       assert(newBuffer);
!       gCollectionInfo[dataChannel].finished = FALSE;
!       gCollectionInfo[dataChannel].outstandingCount ++;
!       return call InData.getSensorData[dataChannel](newBuffer, newNumSamples);
      }
      else{
***************
*** 210,246 ****
      uint8_t * newBuffer;
      
      if(gCollectionInfo[dataChannel].finished){
-       //drop samples if we're done.
-       gCollectionInfo[dataChannel].outstandingCount--;
        return NULL;
      }
      
!     pBI = malloc(sizeof(*pBI));
      
-     if(pBI){
-       pBI->buffer = buffer;
-       pBI->timestamp = timestamp;
-       pBI->ADCScale = ADCScale;
-       pBI->ADCOffset = ADCOffset;
-       pBI->numSamples = numSamples;
-       pBI->dataChannel = dataChannel;
-       POST_PARAMTASK(processBuffer,pBI);
-       
-       newBuffer =  memalign(32, numSamples * gCollectionInfo[dataChannel].width);
-       
-       if(newBuffer == NULL){
- 	trace(DBG_USR1,"FATAL ERROR:  Unable to allocate downsampling buffer\r\n");
-       }
-       else{
- 	gCollectionInfo[dataChannel].outstandingCount++;
-       }
-       return newBuffer;
-     }
-     else{
-       trace(DBG_USR1,"FATAL ERROR:  Unable to allocate temporary structure\r\n");
-       return NULL;
-     }
    }
  
    /****************************
  DEFAULT COMMANDS
--- 377,416 ----
      uint8_t * newBuffer;
      
+     pBI = getNextBIBuffer(dataChannel);
+     
+     assert(pBI);
+     
+     pBI->buffer = buffer;
+     pBI->timestamp = timestamp;
+     pBI->ADCScale = ADCScale;
+     pBI->ADCOffset = ADCOffset;
+     pBI->numSamples = numSamples;
+     pBI->dataChannel = dataChannel;
+     POST_PARAMTASK(processBuffer,pBI);
+     
      if(gCollectionInfo[dataChannel].finished){
        return NULL;
      }
      
!     newBuffer = getNextBuffer(dataChannel);
!     
!     assert(newBuffer);
!     gCollectionInfo[dataChannel].outstandingCount++;
!    
!     return newBuffer;
      
    }
  
+   event result_t InData.getSensorDataStopped[uint8_t dataChannel](){
+         
+     assert(gCollectionInfo[dataChannel].finished);
+     gCollectionInfo[dataChannel].producerStopped = TRUE;
+     trace(DBG_USR1,"CoarseDecimation notified that channel %d stopped\r\n",dataChannel);
+     POST_PARAMTASK(signalGetSensorDataStopped, dataChannel);
+     
+     return SUCCESS;   
+         
+   }
+   
    /****************************
  DEFAULT COMMANDS
***************
*** 272,274 ****
--- 442,449 ----
    }
    
+   default event result_t OutData.getSensorDataStopped[uint8_t dataChannel](){
+     return SUCCESS;
+   }
+   
+   
  }



More information about the Tinyos-contrib-commits mailing list