예제 #1
0
//-----------------------------------------------------------------------------
static void 
vectornav_spi_end_cb(SPIDriver * spip)
{
	(void)spip;

	switch( async_vn_msg.state )
	{
	case VN_ASYNC_1ST_SPI_CB:
		chSysLockFromISR();
		spiUnselectI(VND1.spip);
		async_vn_msg.state = VN_ASYNC_1ST_SLEEP;
		gptStartOneShotI(VND1.gpdp, VN_SLEEPTIME);
		chSysUnlockFromISR();
		break;

	case VN_ASYNC_2ND_SPI_CB:
		chSysLockFromISR();
		spiUnselectI(VND1.spip);
		// here we have the register
		vectornav_dispatch_register(async_vn_msg.reg, async_vn_msg.buf_size, async_vn_msg.buf);
		async_vn_msg.state = VN_ASYNC_2ND_SLEEP;
		gptStartOneShotI(VND1.gpdp, VN_SLEEPTIME);
		chSysUnlockFromISR();
		break;

	case VN_ASYNC_INACTIVE:
	case VN_ASYNC_1ST_SLEEP:
	case VN_ASYNC_2ND_SLEEP:
	default:
		// @TODO: assert?
		break;
	}
}
예제 #2
0
/**
 * sets the alarm to the specified number of microseconds from now.
 * This function should be invoked under kernel lock which would disable interrupts.
 */
void setHardwareUsTimer(int32_t timeUs) {
	/**
	 * #259 BUG error: not positive timeUs
	 * Once in a while we night get an interrupt where we do not expect it
	 */
	if (timeUs <= 0) {
		timerFreezeCounter++;
		warning(CUSTOM_OBD_42, "local freeze cnt=%d", timerFreezeCounter);
	}
	if (timeUs < 2)
		timeUs = 2; // for some reason '1' does not really work
	efiAssertVoid(timeUs > 0, "not positive timeUs");
	efiAssertVoid(timeUs < 10 * US_PER_SECOND, "setHardwareUsTimer() too large");

	if (GPTDEVICE.state == GPT_ONESHOT)
		gptStopTimerI(&GPTDEVICE);
	efiAssertVoid(GPTDEVICE.state == GPT_READY, "hw timer");
	if (hasFirmwareError())
		return;
	gptStartOneShotI(&GPTDEVICE, timeUs);

	lastSetTimerTimeNt = getTimeNowNt();
	lastSetTimerValue = timeUs;
	isTimerPending = TRUE;
	timerRestartCounter++;
}
예제 #3
0
/**
 * sets the alarm to the specified number of microseconds from now.
 * This function should be invoked under kernel lock which would disable interrupts.
 */
void setHardwareUsTimer(int32_t timeUs) {
	setHwTimerCounter++;
	/**
	 * #259 BUG error: not positive timeUs
	 * Once in a while we night get an interrupt where we do not expect it
	 */
	if (timeUs <= 0) {
		timerFreezeCounter++;
		warning(CUSTOM_OBD_LOCAL_FREEZE, "local freeze cnt=%d", timerFreezeCounter);
	}
	if (timeUs < 2)
		timeUs = 2; // for some reason '1' does not really work
	efiAssertVoid(CUSTOM_ERR_6681, timeUs > 0, "not positive timeUs");
	if (timeUs >= 10 * US_PER_SECOND) {
		firmwareError(CUSTOM_ERR_TIMER_OVERFLOW, "setHardwareUsTimer() too long: %d", timeUs);
		return;
	}

	if (GPTDEVICE.state == GPT_ONESHOT) {
		gptStopTimerI(&GPTDEVICE);
	}
	if (GPTDEVICE.state != GPT_READY) {
		firmwareError(CUSTOM_HW_TIMER, "HW timer state %d/%d", GPTDEVICE.state, setHwTimerCounter);
		return;
	}
	if (hasFirmwareError())
		return;
	gptStartOneShotI(&GPTDEVICE, timeUs);

	lastSetTimerTimeNt = getTimeNowNt();
	lastSetTimerValue = timeUs;
	isTimerPending = TRUE;
	timerRestartCounter++;
}
예제 #4
0
/*
 * GPT2 callback.
 */
static void gpt2cb(GPTDriver *gptp) {

  (void)gptp;
  palSetPad(GPIOD, GPIOD_LED5);
  chSysLockFromIsr();
  gptStartOneShotI(&GPTD3, 1000);   /* 0.1 second pulse.*/
  chSysUnlockFromIsr();
}
예제 #5
0
파일: main.c 프로젝트: acourt/NXT-Sensor
/*
 * GPT1 callback.
 */
static void gpt1cb(GPTDriver *gptp) {

  (void)gptp;
  palClearPad(IOPORT3, GPIOC_LED);
  chSysLockFromIsr();
  gptStartOneShotI(&GPTD2, 200);   /* 0.02 second pulse.*/
  chSysUnlockFromIsr();
}
예제 #6
0
파일: main.c 프로젝트: JustRob83/virulent
/*
 * GPIO_TRIGGER interrupt callback. Start transmit burst, disable additional
 * transmit interrupts for TRANSMIT_LOCKOUT.
 */
static void extTransmit(EXTDriver *extp, expchannel_t channel) {

  (void)extp;
  (void)channel;

  //Start transmitting
  pwmEnableChannel(&PWMD2, 3, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 5000));
  palClearPad(GPIOA, GPIO_RX);

 //Disable Transmit interrupt and start timer to reenable
  extChannelDisableI(&EXTD1, 0);              //Disable transmit interrupt
  gptStartOneShotI(&GPTD1, TRANSMIT_TIME);    //Start timer for transmit
  gptStartOneShotI(&GPTD3, TRANSMIT_LOCKOUT); //Start timer for transmit unlock


  chSysUnlockFromIsr();
}
예제 #7
0
/*
 * GPT7 callback
 */
static void gpt7cb(GPTDriver *gptp)
{
  (void)gptp;
  palSetPad(GPIOF, GPIOF_LED_RED);
  chSysLockFromISR();
  gptStartOneShotI(&GPTD1, 31250);  /* 0.1 second pulse.*/
  chSysUnlockFromISR();
}
예제 #8
0
void
vexSpiTickDelay(int16_t tick)
{
   //gptStart(spiGpt, &gpt2cfg);
   //gptPolledDelay(spiGpt, tick);

   chSysLock();
   spiThread = chThdSelf();
   gptStartOneShotI( spiGpt, tick );
   chSchGoSleepS(THD_STATE_SUSPENDED);
   chSysUnlock();
}
예제 #9
0
/**
 * sets the alarm to the specified number of microseconds from now.
 * This function should be invoked under kernel lock which would disable interrupts.
 */
void setHardwareUsTimer(int32_t timeUs) {
	if (timeUs == 1)
		timeUs = 2; // for some reason '1' does not really work
	efiAssertVoid(timeUs > 0, "neg timeUs");
	efiAssertVoid(timeUs < 10 * US_PER_SECOND, "setHardwareUsTimer() too large");

	if (GPTDEVICE.state == GPT_ONESHOT)
		gptStopTimerI(&GPTDEVICE);
	gptStartOneShotI(&GPTDEVICE, timeUs);

	lastSetTimerTime = getTimeNowUs();
	lastSetTimerValue = timeUs;
	isTimerPending = TRUE;
	timerRestartCounter++;
}
예제 #10
0
void
vMBPortTimersEnable(  )
{
#ifdef DEBUG_MB
  palClearPad (BOARD_LED2_P, BOARD_LED2);
  tmStartMeasurement (&tm);
#endif
  if (bMBPortIsWithinException() == TRUE) {
    gptStopTimerI (&GPTDRIVER);
    gptStartOneShotI(&GPTDRIVER, timerout);
  } else { 
    gptStopTimer (&GPTDRIVER);
    gptStartOneShot(&GPTDRIVER, timerout);
  }
}
예제 #11
0
void setTimer(uint32_t delay)
{
	timer1_interval = delay / DIV;
	if (dbg_is_isr())
	{
		chSysLockFromIsr();
	  	gptStartOneShotI(&GPTD1, timer1_interval);
	   	chSysUnlockFromIsr();
	}
	else
	{
		gptStopTimer (&GPTD1);
		gptStartOneShot (&GPTD1, timer1_interval);
	}
}
예제 #12
0
static void
_vs_gpt_cb(GPTDriver *gptp)
{
    (void)gptp;

    chSysLockFromIsr();

    if( nextState == kSonarStatePing )
        {
        nextState = kSonarStateWait;
        vexDigitalPinSet( vexSonars[nextSonar].pa, 0 );
        gptStartOneShotI( sonarGpt, SONAR_TIMEOUT );
        }
    else
    if( nextState == kSonarStateWait )
        {
        vexSonars[nextSonar].time_r = 0;
        vexSonars[nextSonar].time_f = SONAR_TIMEOUT;
        nextState = kSonarStateError;
        }

    chSysUnlockFromIsr();
}
예제 #13
0
/**
 * @brief   Starts the timer in one shot mode.
 *
 * @param[in] gptp      pointer to the @p GPTDriver object
 * @param[in] interval  time interval in ticks
 *
 * @api
 */
void gptStartOneShot(GPTDriver *gptp, gptcnt_t interval) {

  osalSysLock();
  gptStartOneShotI(gptp, interval);
  osalSysUnlock();
}