Пример #1
0
static void REF_MeasureRaw(SensorTimeType raw[NOF_SENSORS]) {
  uint8_t cnt; /* number of sensor */
  uint8_t i;
  TMOUT1_CounterHandle timeout;

  FRTOS1_xSemaphoreTake(mutexHandle, portMAX_DELAY);
  if (ledON) {
    LED_IR_On(); /* IR LED's on */
    WAIT1_Waitus(200);
  }
  for(i=0;i<NOF_SENSORS;i++) {
    SensorFctArray[i].SetOutput(); /* turn I/O line as output */
    SensorFctArray[i].SetVal(); /* put high */
    raw[i] = MAX_SENSOR_VALUE;
  }
  WAIT1_Waitus(20); /* give at least 10 us to charge the capacitor */
  timeout = TMOUT1_GetCounter(20/TMOUT1_TICK_PERIOD_MS); /* set up timeout counter */
  FRTOS1_vTaskSuspendAll();
  
  (void)TU1_ResetCounter(timerHandle); /* reset timer counter */
  for(i=0;i<NOF_SENSORS;i++) {
    SensorFctArray[i].SetInput(); /* turn I/O line as input */
  }
  do {
    cnt = 0;
    if (TMOUT1_CounterExpired(timeout)) {
      break; /* get out of wile loop */
    }
    for(i=0;i<NOF_SENSORS;i++) {
      if (raw[i]==MAX_SENSOR_VALUE) { /* not measured yet? */
        if (SensorFctArray[i].GetVal()==0) {
          raw[i] = TU1_GetCounterValue(timerHandle);
        }
      } else { /* have value */
        cnt++;
      }
    }
  } while(cnt!=NOF_SENSORS);
  TMOUT1_LeaveCounter(timeout);
  FRTOS1_xTaskResumeAll();
  if (ledON) {
    LED_IR_Off(); /* IR LED's off */
    WAIT1_Waitus(200);
  }
  FRTOS1_xSemaphoreGive(mutexHandle);
}
Пример #2
0
static portTASK_FUNCTION(TaskAccelOrientation, pvParameters) {
    int16_t x,z;
    UI1_DisplayOrientation orientation;

    (void)pvParameters;
    FRTOS1_vTaskSuspend(NULL);
    for (;;) {
        {   /* protect critical section in display */
            x = ACCEL_GetX();
            z = ACCEL_GetZ();
#if PL_TWR_LCD_REV_0
            if (z>=VAL_1G && x>=VAL_MINUS_1G) {
                orientation = UI1_ORIENTATION_LANDSCAPE180;
            } else if (z<=VAL_MINUS_1G && x>=VAL_MINUS_1G) {
                orientation = UI1_ORIENTATION_LANDSCAPE;
            } else if (x<=VAL_MINUS_1G && z>=VAL_MINUS_1G) {
                orientation = UI1_ORIENTATION_PORTRAIT;
            } else {
                orientation = UI1_ORIENTATION_PORTRAIT180;
            }
#elif PL_TWR_LCD_REV_A
            if (z>=VAL_1G && x>=VAL_MINUS_1G) {
                orientation = UI1_ORIENTATION_LANDSCAPE;
            } else if (z<=VAL_MINUS_1G && x>=VAL_MINUS_1G) {
                orientation = UI1_ORIENTATION_LANDSCAPE180;
            } else if (x<=VAL_MINUS_1G && z>=VAL_MINUS_1G) {
                orientation = UI1_ORIENTATION_PORTRAIT180;
            } else {
                orientation = UI1_ORIENTATION_PORTRAIT;
            }
#endif
            if (orientation != UI1_GetDisplayOrientation()) {
                /* need to do some protection, as we are changing the display.... */
                GDisp1_GetDisplay();
                FRTOS1_vTaskSuspendAll();
                UI1_SetDisplayOrientation(orientation);
                FRTOS1_xTaskResumeAll();
                GDisp1_GiveDisplay();
            }
        }
        FRTOS1_vTaskDelay(500/portTICK_RATE_MS);
    } /* for */
}