Ejemplo n.º 1
0
static uint8_t Measure(uint8_t channel, QuadTime_t *timing) {
  uint32_t timeout;
  #define TIMEOUT_VAL 0x0fff /* just some waiting time */
  
  timing->highTicks = 0;
  timing->lowTicks = 0;
  timing->lowPercent = 0;
  timing->highPercent = 0;
  taskENTER_CRITICAL();
  /* trigger on raising edge */
  timeout = 0;
  while(ChannelFct[channel]()) { /* while high ... */
    /* wait until signal goes down */
    timeout++;
    if (timeout>TIMEOUT_VAL) {
      taskEXIT_CRITICAL();
      return ERR_FAILED;
    }
  }
  /* signal is low here, wait for raising edge */
  timeout = 0;
  while(!ChannelFct[channel]()) {
    /* wait until signal goes up */
    timeout++;
    if (timeout>TIMEOUT_VAL) {
      taskEXIT_CRITICAL();
      return ERR_FAILED;
    }
  }
  /* here signal is on the raising edge */
  TU2_ResetCounter(TU2_DeviceData);
  timeout = 0;
  while(ChannelFct[channel]()) { /* while signal is high... */
    /* wait until signal goes down */
    timeout++;
    if (timeout>TIMEOUT_VAL) {
      taskEXIT_CRITICAL();
      return ERR_FAILED;
    }
  }
  /* signal is 0 now */
  timing->highTicks = TU2_GetCounterValue(TU2_DeviceData); 
  timeout = 0;
  TU2_ResetCounter(TU2_DeviceData);
  while(!ChannelFct[channel]()) { /* while signal is low... */
    /* wait until signal goes up */
    timeout++;
    if (timeout>TIMEOUT_VAL) {
      taskEXIT_CRITICAL();
      return ERR_FAILED;
    }
  }
  timing->lowTicks = TU2_GetCounterValue(TU2_DeviceData); 
  taskEXIT_CRITICAL();
  timing->lowPercent  = (timing->lowTicks*100UL)/((uint32_t)timing->highTicks+(uint32_t)timing->lowTicks);
  timing->highPercent = (timing->highTicks*100UL)/((uint32_t)timing->highTicks+(uint32_t)timing->lowTicks);
  return ERR_OK;
}
Ejemplo n.º 2
0
/* ===================================================================*/
LDD_TError RealTimeLdd1_Reset(LDD_TDeviceData *DeviceDataPtr)
{
  RealTimeLdd1_TDeviceData *DeviceDataPrv = (RealTimeLdd1_TDeviceData *)DeviceDataPtr;

  /* {Default RTOS Adapter} Critical section begin, general PE function is used */
  EnterCritical();
  (void)TU2_ResetCounter(DeviceDataPrv->LinkedDeviceDataPtr); /* Reset counter of TimerUnit */
  DeviceDataPrv->TimerTicks =  0U;     /* Reset counter of timer ticks */
  DeviceDataPrv->Overflow = FALSE;     /* Reset counter overflow flag */
  /* {Default RTOS Adapter} Critical section end, general PE function is used */
  ExitCritical();
  return ERR_OK;
}
Ejemplo n.º 3
0
/**\fn US_EventEchoCapture(LDD_TUserData *UserDataPtr)
 * \brief Echo capture event
 *
 * Called by interrupt from TU for echo capture.
 */
void US_EventEchoCapture(LDD_TUserData *UserDataPtr)
{
	US_Devices *ptr = (US_Devices *)UserDataPtr;

	if (ptr->usDevice[ptr->currentDevice].state==ECHO_TRIGGERED)
	{ /* 1st edge, this is the raising edge, start measurement */
		TU2_ResetCounter(ptr->usDevice[ptr->currentDevice].echoDevice);
		ptr->usDevice[ptr->currentDevice].state = ECHO_MEASURE;
	}
	else if (ptr->usDevice[ptr->currentDevice].state==ECHO_MEASURE)
	{ /* 2nd edge, this is the falling edge: use measurement */
		(void)TU2_GetCaptureValue(ptr->usDevice[ptr->currentDevice].echoDevice, ptr->currentDevice, &ptr->usDevice[ptr->currentDevice].capture);
		ptr->usDevice[ptr->currentDevice].state = ECHO_FINISHED;
	}
}