Пример #1
0
void thread(void)
{
	unsigned int id;
	
	id = OS_Id();
	PF3 ^= 0x08;
	Display_Message(0,line++, "Thread: ", id);
	OS_Sleep(2000);
	Display_Message(0,line++, "Thread dying ", id);
	PF3 ^= 0x08;
	OS_Kill();
}
Пример #2
0
//------------------Task 2--------------------------------
// background thread executes with SW1 button
// one foreground task created with button push
// foreground treads run for 2 sec and die
// ***********ButtonWork*************
void ButtonWork(void){
unsigned long myId = OS_Id(); 
  PE1 ^= 0x02;
  ST7735_Message(1,0,"NumCreated =",NumCreated); 
  PE1 ^= 0x02;
  OS_Sleep(50);     // set this to sleep for 50msec
  ST7735_Message(1,1,"PIDWork     =",PIDWork);
  ST7735_Message(1,2,"DataLost    =",DataLost);
  ST7735_Message(1,3,"Jitter 0.1us=",MaxJitter);
  PE1 ^= 0x02;
  OS_Kill();  // done, OS does not return from a Kill
} 
Пример #3
0
//------------------Task 2--------------------------------
// background thread executes with select button
// one foreground task created with button push
// foreground treads run for 2 sec and die
// ***********ButtonWork*************
void ButtonWork(void){
unsigned long i;
unsigned long myId = OS_Id(); 
  oLED_Message(1,0,"NumCreated =",NumCreated); 
  if(NumSamples < RUNLENGTH){   // finite time run
    for(i=0;i<20;i++){  // runs for 2 seconds
      //OS_Sleep(20);     // set this to sleep for 0.1 sec
    }
  }
  oLED_Message(1,1,"PIDWork    =",PIDWork);
  oLED_Message(1,2,"DataLost   =",DataLost);
  oLED_Message(1,3,"Jitter(us) =",MaxJitter-MinJitter);
  OS_Kill();  // done
} 
Пример #4
0
//------------------Task 2--------------------------------
// background thread executes with select button
// one foreground task created with button push
// foreground treads run for 2 sec and die
// ***********ButtonWork*************
void ButtonWork(void){
unsigned long i;
unsigned long myId = OS_Id(); 
  oLED_Message(1,0,"NumCreated =",NumCreated); 
  if(NumSamples < RUNLENGTH){   // finite time run
    for(i=0;i<40;i++){  // runs for 2 seconds
      OS_Sleep(50);     // sleep for 50ms
    }
  }
  oLED_Message(1,1,"PIDWork    =",PIDWork);
  oLED_Message(1,2,"DataLost   =",DataLost);
  oLED_Message(1,3,"0.1u Jitter=",MaxJitter1-MinJitter1);

  OS_Kill();  // done
} 
Пример #5
0
int main(void)
{
	unsigned int id;
	unsigned long time;	
	id = OS_Id();
	PF2 ^= 0x04;
	Display_Message(0,line++, "Hello world: ", id);
	OS_AddThread(thread, 128, 1);
  time = OS_Time();
	OS_Sleep(1000);
	time = (((OS_TimeDifference(time, OS_Time()))/1000ul)*125ul)/10000ul;
	Display_Message(0,line++, "Sleep time: ", time);
	PF2 ^= 0x04;
	OS_Kill();
}
Пример #6
0
void PID(void){ 
short err;  // speed error, range -100 to 100 RPM
unsigned long myId = OS_Id(); 
  PIDWork = 0;
  IntTerm = 0;
  PrevError = 0;
  Coeff[0] = 384;   // 1.5 = 384/256 proportional coefficient
  Coeff[1] = 128;   // 0.5 = 128/256 integral coefficient
  Coeff[2] = 64;    // 0.25 = 64/256 derivative coefficient*
  while(NumSamples < RUNLENGTH) { 
    for(err = -1000; err <= 1000; err++){    // made-up data
      Actuator = PID_stm32(err,Coeff)/256;
    }
    PIDWork++;        // calculation finished
  }
  for(;;){ }          // done
}
Пример #7
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; // 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
}
Пример #8
0
//------------------Task 2--------------------------------
// background thread executes with select button
// one foreground task created with button push
// foreground treads run for 2 sec and die
// ***********ButtonWork*************
void ButtonWork(void){
unsigned long i;
unsigned long myId = OS_Id(); 
  char str[20];
  sprintf(str, "NumCreated = %d", NumCreated);
  OLED_Out(BOTTOM, str); 
  if(NumSamples < RUNLENGTH){   // finite time run
    for(i=0;i<20;i++){  // runs for 2 seconds
      OS_Sleep(50);     // set this to sleep for 0.1 sec
    }
  }
  sprintf(str, "PIDWork    = %d", PIDWork);
  OLED_Out(BOTTOM, str);
  sprintf(str, "DataLost   = %d", DataLost);
  OLED_Out(BOTTOM, str);
  sprintf(str, "Jitter(us) = %d",MaxJitter-MinJitter);
  OLED_Out(BOTTOM, str);
  OLED_Out(BOTTOM, "");
  OS_Kill();  // done
  OS_Delay(OS_ARBITRARY_DELAY);
} 
Пример #9
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
}