コード例 #1
0
ファイル: Lab3.c プロジェクト: tach4455/EE345M
//******** Consumer *************** 
// foreground thread, accepts data from producer
// calculates FFT, sends DC component to Display
// inputs:  none
// outputs: none
void Consumer(void){ 
unsigned long data,DCcomponent; // 10-bit raw ADC sample, 0 to 1023
unsigned long t;  // time in ms
unsigned long myId = OS_Id(); 
  ADC_Collect(0, 1000, &Producer); // start ADC sampling, channel 0, 1000 Hz
  NumCreated += OS_AddThread(&Display,128,0); 
  while(NumSamples < RUNLENGTH) { 
    for(t = 0; t < 64; t++){   // collect 64 ADC samples
      data = OS_Fifo_Get();    // get from producer
      x[t] = data;             // real part is 0 to 1023, imaginary part is 0
    }
    cr4_fft_64_stm32(y,x,64);  // complex FFT of last 64 ADC values
    DCcomponent = y[0]&0xFFFF; // Real part at frequency 0, imaginary part should be zero
    OS_MailBox_Send(DCcomponent);
  }
  OS_Kill();  // done
}
コード例 #2
0
//******** Consumer *************** 
// foreground thread, accepts data from producer
// calculates FFT, sends DC component to Display
// inputs:  none
// outputs: none
void Consumer(void){ 
unsigned long data,DCcomponent;   // 12-bit raw ADC sample, 0 to 4095
unsigned long t;                  // time in 2.5 ms
unsigned long myId = OS_Id(); 
  //ADC_Collect(5, FS, &Producer); // start ADC sampling, channel 5, PD2, 400 Hz
	//OS_DisableInterrupts();
	ADC_Collect(5, FS, &Producer); // start ADC sampling, channel 5, PD2, 400 Hz	//OS_EnableInterrupts();
	
  NumCreated += OS_AddThread(&Display,128,0); 
  while(NumSamples < RUNLENGTH) { 
    PE2 = 0x04;
    for(t = 0; t < 64; t++){   // collect 64 ADC samples
      data = OS_Fifo_Get();    // get from producer
      x[t] = data;             // real part is 0 to 4095, imaginary part is 0
    }
    PE2 = 0x00;
    cr4_fft_64_stm32(y,x,64);  // complex FFT of last 64 ADC values
    DCcomponent = y[0]&0xFFFF; // Real part at frequency 0, imaginary part should be zero
    OS_MailBox_Send(DCcomponent); // called every 2.5ms*64 = 160ms
  }
  OS_Kill();  // done
}
コード例 #3
0
ファイル: command.c プロジェクト: kle8309/OS_PROJECT
/*
===================================================================================================
  COMMAND HANDLER :: adcTestHandler
  
   - parses the command line and begins a adc sampler task
   - return success value
===================================================================================================
*/
int adcTestHandler(char** tokens, uint8_t numTokens){
  // verify correct number of argument tokens, show help if invalid
  if (numTokens < 5) {
    printf("ERROR: Incorrect number of args.\n\n");
    printf("  Usage: adcCollect [channel, 0-11] [frequency, 100-10000] [numSamples]\n\n");
    return CMD_FAILURE;
  }

  // attempt to parse arguments
  int channel = atoi(tokens[2]);
  int frequency = atoi(tokens[3]);
  int numSamples = atoi(tokens[4]);

  //printf("channel = %d, freq = %d, numSamples = %d\n", channel, frequency, numSamples);

  // verify channel range
  if (channel < 0 || channel > 11){
    printf("ERROR: Channel number out of range!\n\n");
    return CMD_FAILURE;
  } 
  
  // verify frequency range
  if (frequency < 100 || frequency > 10000){
    printf("ERROR: Sample frequency out of range!\n\n");
    return CMD_FAILURE;
  } 

  // attempt to malloc a buffer, complain and fail if memory unavailable
  ADCBufferPointer = malloc(numSamples * sizeof(*ADCBufferPointer));
  if (ADCBufferPointer == NULL){
    printf("ERROR: Could not allocate sample buffer memory!\n\n");
    return CMD_FAILURE;
  } 
    
  // start adc collection task
  ADC_Collect(channel, frequency, ADCBufferPointer, numSamples);

  return CMD_SUCCESS;
}
コード例 #4
0
ファイル: Lab5.c プロジェクト: AustinBlackstone/EE345M-S2012
//*******************lab 5 main **********
int realmain(void){        // lab 5 real main
  OS_Init();           // initialize, disable interrupts
  Running = 0;         // robot not running
  DataLost = 0;        // lost data between producer and consumer
  NumSamples = 0;

//********initialize communication channels
  OS_Fifo_Init(512);    // ***note*** 4 is not big enough*****
  ADC_Collect(0, 1000, &Producer); // start ADC sampling, channel 0, 1000 Hz

//*******attach background tasks***********
  OS_AddButtonTask(&ButtonPush,2);
  OS_AddDownTask(&DownPush,3);
  OS_AddPeriodicThread(disk_timerproc,10*TIME_1MS,5);

  NumCreated = 0 ;
// create initial foreground threads
  NumCreated += OS_AddThread(&Interpreter,128,2); 
  NumCreated += OS_AddThread(&IdleTask,128,7);  // runs when nothing useful to do
 
  OS_Launch(TIMESLICE); // doesn't return, interrupts enabled in here
  return 0;             // this never executes
}