示例#1
0
void eicu_cb(EICUDriver *eicup, eicuchannel_t channel, uint32_t w, uint32_t p) {
  (void)eicup;
  (void)p;
  switch (channel) {
  case EICU_CHANNEL_1:
    if (abs((int32_t)w - (int32_t)ST2US(pulse_led3.high)) > tolerance)
      osalSysHalt("ch1");
    break;
  case EICU_CHANNEL_2:
    if (abs((int32_t)w - (int32_t)ST2US(pulse_led4.high)) > tolerance)
      osalSysHalt("ch2");
    break;
  case EICU_CHANNEL_3:
    if (abs((int32_t)w - (int32_t)ST2US(pulse_led5.high)) > tolerance)
      osalSysHalt("ch3");
    break;
  case EICU_CHANNEL_4:
    if (abs((int32_t)w - (int32_t)ST2US(pulse_led6.high)) > tolerance)
      osalSysHalt("ch4");
    break;
  default:
    osalSysHalt("unhandled case");
    break;
  }
}
示例#2
0
文件: hrt.c 项目: Coonat2/ardupilot
uint64_t hrt_micros()
{
	static volatile uint64_t last_micros;

    /*
      use chSysGetStatusAndLockX() to prevent an interrupt while
      allowing this call from any context
     */
	syssts_t sts = chSysGetStatusAndLockX();
	uint64_t micros;
	micros = timer_base + (uint64_t)chVTGetSystemTimeX();
	// we are doing this to avoid an additional interupt routing
	// since we are definitely going to get called atleast once in
	// a full timer period
	if (last_micros > micros) {
        const uint64_t step = ST2US(1ULL<<CH_CFG_ST_RESOLUTION);
		timer_base += step;
		micros += step;
	}
	last_micros = micros;
	chSysRestoreStatusX(sts);
	return micros;
}