Esempio n. 1
0
/**
 * @brief   Configures and activates the GPT peripheral.
 *
 * @param[in] gptp      pointer to the @p GPTDriver object
 *
 * @notapi
 */
void gpt_lld_start(GPTDriver *gptp)
{
  uint8_t psc;

  if (gptp->state == GPT_STOP) {
    /* Clock activation.*/
  }

  /* Configuration.*/

#if AVR_GPT_USE_TIM2 || defined(__DOXYGEN__)
  if (gptp == &GPTD2) {
    psc = prescaler(gptp->config->frequency, ratio_extended, PRESCALER_SIZE_EXTENDED);
    gptp->clock_source = clock_source_extended[psc] & 0x07;
    TCCR2A  = (1 << WGM21) | (0 << WGM20);
    TCCR2B  = (0 << WGM22);
    OCR2A = F_CPU / ratio_extended[psc] /gptp->config->frequency - 1;
    return;
  }
#endif

  uint8_t i = getTimerIndex(gptp);
  psc = prescaler(gptp->config->frequency, ratio_base, PRESCALER_SIZE_BASE);
  gptp->clock_source = clock_source_base[psc] & 0x07;
  *regs_table[i].tccra = (0 << WGM11)  |
                         (0 << WGM10)  |
                         (0 << COM1A1) |
                         (0 << COM1A0) |
                         (0 << COM1B1) |
                         (0 << COM1B0);
  *regs_table[i].tccrb = (1 << WGM12);
  *regs_table[i].ocr1 = 0;
  *regs_table[i].ocr2 = F_CPU / ratio_base[psc] / gptp->config->frequency - 1;
}
Esempio n. 2
0
/**
 * @brief   Configures and activates the GPT peripheral.
 *
 * @param[in] gptp      pointer to the @p GPTDriver object
 *
 * @notapi
 */
void gpt_lld_start(GPTDriver *gptp) {

  NRF_TIMER_Type *tim = gptp->tim;

  if (gptp->state == GPT_STOP) {
    osalDbgAssert(gptp->cc_int < NRF5_TIMER_COMPARE_NUM,
        "invalid capture/compare index");

    tim->INTENSET = TIMER_INTENSET_COMPARE0_Msk << gptp->cc_int;
#if NRF5_GPT_USE_TIMER0
    if (&GPTD1 == gptp)
      nvicEnableVector(TIMER0_IRQn, NRF5_GPT_TIMER0_IRQ_PRIORITY);
#endif
#if NRF5_GPT_USE_TIMER1
    if (&GPTD2 == gptp)
      nvicEnableVector(TIMER1_IRQn, NRF5_GPT_TIMER1_IRQ_PRIORITY);
#endif
#if NRF5_GPT_USE_TIMER2
    if (&GPTD3 == gptp)
      nvicEnableVector(TIMER2_IRQn, NRF5_GPT_TIMER2_IRQ_PRIORITY);
#endif
  }

  /* Prescaler value calculation.*/
  tim->PRESCALER = prescaler(gptp->config->frequency);

  /* Timer configuration.*/
  tim->MODE = TIMER_MODE_MODE_Timer << TIMER_MODE_MODE_Pos;

  switch (gptp->config->resolution) {

    case 8:
      tim->BITMODE = TIMER_BITMODE_BITMODE_08Bit << TIMER_BITMODE_BITMODE_Pos;
      break;

    case 16:
      tim->BITMODE = TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos;
      break;

#if NRF5_GPT_USE_TIMER0
    case 24:
      tim->BITMODE = TIMER_BITMODE_BITMODE_24Bit << TIMER_BITMODE_BITMODE_Pos;
      break;

    case 32:
      tim->BITMODE = TIMER_BITMODE_BITMODE_32Bit << TIMER_BITMODE_BITMODE_Pos;
      break;
#endif

    default:
      osalDbgAssert(FALSE, "invalid timer resolution");
      break;
  };
}
int Max6651ClosedLoop::prescalerMultiplier() const{
    // 0 --> 1
    // 1 --> 2
    // 2 --> 4
    // 3 --> 8
    // 4 --> 16
    // n --> 2^n
    int n = int(prescaler());
    //return (n == 0) ? 0 : 1 << n;
    return (1 << (n+1)) >> 1;
}