Exemple #1
0
 void delayTicksLong(uint64_t delayTime) {
     while(delayTime > MAX_DELAY_IN_TICKS){
         delayTicks(MAX_DELAY_IN_TICKS);
         delayTime -= MAX_DELAY_IN_TICKS;
     }
     delayTicks(delayTime);
 }
/***************************************************************************//**
 * @brief
 *    Millisecond delay function.
 *
 * @param[in] ms Milliseconds to stay in the delay function.
 *
 * @return
 *    @ref ECODE_EMDRV_RTCDRV_OK.
 ******************************************************************************/
Ecode_t RTCDRV_Delay( uint32_t ms )
{
  uint64_t totalTicks;

  totalTicks = MSEC_TO_TICKS( ms );

  while ( totalTicks > RTC_CLOSE_TO_MAX_VALUE ) {
    delayTicks( RTC_CLOSE_TO_MAX_VALUE );
    totalTicks -= RTC_CLOSE_TO_MAX_VALUE;
  }
  delayTicks( totalTicks );

  return ECODE_EMDRV_RTCDRV_OK;
}
Exemple #3
0
	void delay()
	{
		if (disabled)
			return;

		int64_t tickDelta = SDL_GetPerformanceCounter() - lastTickCount;
		int64_t toDelay = tpf - tickDelta;

		/* Compensate for the last delta
		 * to the ideal timestep */
		toDelay -= adj.idealDiff;

		if (toDelay < 0)
			toDelay = 0;

		delayTicks(toDelay);

		uint64_t now = lastTickCount = SDL_GetPerformanceCounter();
		int64_t diff = now - adj.last;
		adj.last = now;

		/* Recalculate our temporal position
		 * relative to the ideal timestep */
		adj.idealDiff = diff - tpf + adj.idealDiff;

		if (adj.resetFlag)
		{
			adj.idealDiff = 0;
			adj.resetFlag = false;
		}
	}
void OBD2Task(void *pvParameters)
{
    pr_info("Start OBD2 task\r\n");
    size_t max_obd2_samplerate = msToTicks((TICK_RATE_HZ / MAX_OBD2_SAMPLE_RATE));
    LoggerConfig *config = getWorkingLoggerConfig();
    OBD2Config *oc = &config->OBD2Configs;
    while(1) {
        while(oc->enabled && oc->enabledPids > 0) {
            for (size_t i = 0; i < oc->enabledPids; i++) {
                PidConfig *pidCfg = &oc->pids[i];
                int value;
                unsigned char pid = pidCfg->pid;
                if (OBD2_request_PID(pid, &value, OBD2_PID_DEFAULT_TIMEOUT_MS)) {
                    OBD2_set_current_PID_value(i, value);
                    if (TRACE_LEVEL) {
                        pr_trace("read OBD2 PID ");
                        pr_trace_int(pid);
                        pr_trace("=")
                        pr_trace_int(value);
                        pr_trace("\r\n");
                    }
                } else {
                    pr_warning_int_msg("OBD2: PID read fail: ", pid);
                }
                delayTicks(max_obd2_samplerate);
            }
        }
        delayMs(OBD2_FEATURE_DISABLED_DELAY_MS);
    }
}
Exemple #5
0
/**************************************************************************//**
 * @brief Microsecond delay function
 * @param[in] usec Delay in microseconds
 *****************************************************************************/
static void delayUs( uint32_t usec )
{
  uint64_t totalTicks;

  totalTicks = (((uint64_t)CMU_ClockFreqGet(cmuClock_CORE)*usec)+500000)/1000000;

  delayTicks( totalTicks );
}
/**
 * Periodic code for test mode should go here.
 *
 * Users should override this method for code which will be called periodically
 * at a regular
 * rate while the robot is in test mode.
 */
void IterativeRobot::TestPeriodic() {
  static bool firstRun = true;
  if (firstRun) {
    printf("Default %s() method... Overload me!\n", __FUNCTION__);
    firstRun = false;
  }
  delayTicks(1);
}
Exemple #7
0
/**************************************************************************//**
 * @brief Millisecond delay function
 * @param[in] usec Delay in milliseconds
 *****************************************************************************/
static void delayMs( uint32_t msec )
{
  uint64_t totalTicks;

  BITMAP_USBHandler();

  totalTicks = (((uint64_t)CMU_ClockFreqGet(cmuClock_CORE)*msec)+500)/1000;

  delayTicks( totalTicks );
}
int CAN_device_tx_msg(uint8_t channel, CAN_msg * msg, unsigned int timeoutMs)
{
        CanTxMsg TxMessage;

        /* Transmit Structure preparation */
        if (msg->isExtendedAddress) {
                TxMessage.ExtId = msg->addressValue;
                TxMessage.IDE = CAN_ID_EXT;
        } else {
                TxMessage.StdId = msg->addressValue;
                TxMessage.IDE = CAN_ID_STD;
        }

        TxMessage.RTR = CAN_RTR_DATA;
        TxMessage.DLC = msg->dataLength;
        memcpy(TxMessage.Data, msg->data, msg->dataLength);

        CAN_TypeDef* chan = channel == 0 ? CAN1 : CAN2;
        const uint8_t mailbox = CAN_Transmit(chan, &TxMessage);

        /*
         * Then they don't want to wait.  Ok.  Let caller know if they
         * got a mailbox then.  If not, message was unable to be sent.
         */
        if (0 == timeoutMs)
                return mailbox != CAN_TxStatus_NoMailBox;

        /* Using ticks avoids a race-condition */
        size_t ticks = getCurrentTicks();
        const size_t trigger = ticks + msToTicks(timeoutMs);
        uint8_t status = CAN_TxStatus_Failed;

        while(ticks <= trigger) {
                status = CAN_TransmitStatus(chan, mailbox);
                if (CAN_TxStatus_Pending != status)
                        break;

                /*
                 * Not using yield here as it will cause lower priority tasks
                 * to starve.  Yield only allows tasks of equal or greater
                 * priority to run.
                 */
                delayTicks(1);

                ticks = getCurrentTicks();
        }

        if (CAN_TxStatus_Pending == status)
                CAN_CancelTransmit(chan, mailbox);

        return status == CAN_TxStatus_Ok;
}
void delayMicrosecondsWithPulse(uint32_t duration, int pin)
{
  uint32_t toggleCount = ((uint32_t)(duration * TOGGLES_PER_SECOND) / US_PER_SEC)+1;
  bool GpioPinDriveHigh = true;

  while (toggleCount) {

    // Flip the pin we're bit-banging.

    digitalWrite(pin, GpioPinDriveHigh);
    GpioPinDriveHigh = !GpioPinDriveHigh;

    // Wait an appropriate amount of time.  We need to
    // subtract a "fudge factor" to accomodate for loop latency.
    // The "fudge factor" could be confirmed using an oscilliscope.
    // All I needed to do is see what number gives us 38KHz!

    delayTicks(TICKS_PER_TOGGLE - TICKS_PER_TOGGLE_FUDGE_FACTOR);
    toggleCount = toggleCount - 1;
  }

  digitalWrite(pin, LOW);
}
/* static */ 
inline void SoftwareSerial::tunedDelay(uint16_t delay) 
{
  //delay in tick counts
  delayTicks(delay);
}
//
// The receive routine called by the interrupt handler
//
void SoftwareSerial::recv()
{
  noInterrupts();
  uint8_t d = 0;
  // If RX line is high, then we don't see any start bit
  // so interrupt is probably not for us
  if (invertedLogic ? digitalRead(_rxPin) : !digitalRead(_rxPin))
  {
    // The very first start bit the sketch receives takes about 5us longer
    if(firstStartBit && !isSOCGpio)
    {
      delayTicks(initRxCenteringDelay);
    }
    else
    {
      delayTicks(rxCenteringDelay);
    }

    for (uint8_t i=8; i > 0; --i)
    {
      // compensate for the centering delay if the ISR was too late and missed the center of the start bit.
      if(i == 8) 
      {
        if(firstStartBit && !isSOCGpio) 
        {
          delayTicks(initRxIntraBitDelay);
        }
        else
        {
          delayTicks(firstIntraBitDelay);
        }
      }
      else
      {
        delayTicks(rxIntraBitDelay);
      }
      d >>= 1;
      if (digitalRead(_rxPin))
        d |= 0x80;
      firstStartBit = false;
    }
    
    if (invertedLogic)
      d = ~d;

    uint8_t next = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF;
    if (next != _receive_buffer_head)
    {
      // save new data in buffer: tail points to where byte goes
      _receive_buffer[_receive_buffer_tail] = d; // save new byte
      _receive_buffer_tail = next;
    } 
    else 
    {
      DebugPulse(_DEBUG_PIN1, 1);
      bufferOverflow = true;
    }

    // wait until we see a stop bit/s or timeout;
    uint8_t loopTimeout = 32;
    if(invertedLogic)
    {
      while(digitalRead(_rxPin) && (loopTimeout >0))
      {
        delayTicks(bitDelay >> 4);
        loopTimeout--;
      }
    }
    else
    {
      while(!digitalRead(_rxPin) && (loopTimeout >0))
      {
        delayTicks(bitDelay >> 4);
        loopTimeout--;
      }
    }
    DebugPulse(_DEBUG_PIN1, 1);
  }
void Curie_I2S::lastFrameDelay()
{
    delayTicks(frameDelay);
}