コード例 #1
0
ファイル: bldc.c プロジェクト: kjellhar/chibi-bldc
/* The PWM Counter Reset will put the PWM system in "ACTIVE" state, which
 * is defined as the state when the channel is active and a compare event
 * has not yet taken place.
 */
static void cdPwmCounterReset(PWMDriver *pwmp) {
  (void) pwmp;

  chSysLockFromIsr();
  palWriteGroup (PWM_OUT_PORT, PWM_OUT_PORT_MASK, PWM_OUT_OFFSET,  bldc.pwmOutT0);

  // Calculate and initiate the state change
  // Consider moving this to a thread to further slim down the ISR callback
  if (!halIsCounterWithin(bldc.prevStateChange, bldc.nextStateChange)) {

    // Prepare next state
    if (bldc.directionFwd) {
      bldc.nextState++;
    }
    else {
      bldc.nextState--;
    }

    // Wrap the state counter
    bldc.nextState = (bldc.nextState+bldc.stateCount)%bldc.stateCount;

    // Prepare the next state change.
    bldc.prevStateChange = bldc.nextStateChange;
    bldc.nextStateChange += bldc.stateChangeInterval;
  }
  chSysUnlockFromIsr();
}
コード例 #2
0
ファイル: hal.c プロジェクト: JustRob83/virulent
/**
 * @brief   Polled delay.
 * @note    The real delays is always few cycles in excess of the specified
 *          value.
 * @note    This is an optional service that could not be implemented in
 *          all HAL implementations.
 * @note    This function can be called from any context.
 *
 * @param[in] ticks     number of ticks
 *
 * @special
 */
void halPolledDelay(halrtcnt_t ticks) {
  halrtcnt_t start = halGetCounterValue();
  halrtcnt_t timeout  = start + (ticks);
  while (halIsCounterWithin(start, timeout))
    ;
}