//************SW2Push*************
// Called when SW2 Button pushed, Lab 3 only
// Adds another foreground task
// background threads execute once and return
void SW2Push(void){
  if(OS_MsTime() > 20){ // debounce
    if(OS_AddThread(&ButtonWork,100,4)){
      NumCreated++; 
    }
    OS_ClearMsTime();  // at least 20ms between touches
  }
}
Exemple #2
0
// ******** OS_DownSwitch_Handler ************
// Check if time since last down press >.3s, for debouncing, call buttontask appropriately
// input: none,  
// output: none, 
void EvalDirBtnsHandler(){
    IntDisable(INT_GPIOE);
    GPIOPinIntClear(GPIO_PORTE_BASE, GPIO_PIN_1);
  
    while(OS_MsTime() - btndown_time < 250);  // Wait for 10 ms
	    if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1) == 0){
		    //BUTTONTASK();	   //supposed to trigger the function that button task points to
             
            // Toggle Debug LED
            if (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0) == 0)
                GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0);
            else
                GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0);
	    }	
	btndown_time=OS_MsTime();
  
    IntEnable(INT_GPIOE);
}
Exemple #3
0
// ******** OS_SelectSwitch_Handler ************
// Check if time since last switch press >.3s, for debouncing, call buttontask appropriately
// input: none,  
// output: none, 
void SelectBtnHandler(){
    IntDisable(INT_GPIOF);
	GPIOPinIntClear(GPIO_PORTF_BASE, GPIO_PIN_1);
  
	//currentTime=OS_MsTime();
    while(OS_MsTime() - SDEBOUNCEPREV < 500);  // Wait for 10 ms
	    if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1) == 0){
            // Toggle Debug LED
            if (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0) == 0)
                GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0);
            else
                GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0);
                
		    BUTTONTASK();	   //supposed to trigger the function that button task points to
	    }	
	SDEBOUNCEPREV=OS_MsTime();
  
    IntEnable(INT_GPIOF);
}
Exemple #4
0
void read_test(void) {
  int i;
  unsigned int then, now;
  eFile_Init();
  eFile_Format();
  OS_AddThread(&write_test, 128, 0);
  OS_Sleep(2000);
  then = OS_MsTime();
  // read 10 blocks
  for(i = 0; i < 10; i++) {
    eDisk_ReadBlock(buffer, i);
  }
  now = OS_MsTime();
  OS_AddThread(&SH_Shell, 128, 0);
	OS_Sleep(1000);
	OS_Suspend();
  printf("Read test took %d ms", now - then);
  eFile_Format();
  OS_Kill();
}
Exemple #5
0
//******** Robot *************** 
// foreground thread, accepts data from producer
// inputs:  none
// outputs: none
void Robot(void){   
unsigned long data;      // ADC sample, 0 to 1023
unsigned long voltage;   // in mV,      0 to 3000
unsigned long time;      // in 10msec,  0 to 1000 
unsigned long t=0;
  OS_ClearMsTime();    
  DataLost = 0;          // new run with no lost data 
  printf("Robot running...");
  eFile_RedirectToFile("Robot");
  printf("time(sec)\tdata(volts)\n\r");
  do{
    t++;
    time=OS_MsTime();            // 10ms resolution in this OS
    data = OS_Fifo_Get();        // 1000 Hz sampling get from producer
    voltage = (300*data)/1024;   // in mV
    printf("%0u.%02u\t%0u.%03u\n\r",time/100,time%100,voltage/1000,voltage%1000);
  }
  while(time < 1000);       // change this to mean 10 seconds
  eFile_EndRedirectToFile();
  printf("done.\n\r");
  Running = 0;                // robot no longer running
  OS_Kill();
}
Exemple #6
0
void write_test(void) {
  int i;
  unsigned int then, now;
  eFile_Init();
  eFile_Format();
  // format buffer with dummy data
  for(i = 0; i < 512; i++) {
    buffer[i] = 0xA5;
  }
  // possibly should just use OS_Time()
  then = OS_MsTime();
  // write 10 blocks
  for(i = 0; i < 10; i++) {
    eDisk_WriteBlock(buffer, i);
  }
//   now = OS_MsTime();
//   OS_AddThread(&SH_Shell, 128, 0);
// 	OS_Sleep(1000);
// 	OS_Suspend();
//   printf("Write test took %d ms", now - then);
//   eFile_Format();
  OS_Kill();
}
Exemple #7
0
__attribute__((long_call, section(".data"))) static int _SH_Time(void)
{
	p("%d\n", OS_MsTime());
	return 0;
}