예제 #1
0
/**
 * @brief   Enables a PWM channel.
 * @pre     The PWM unit must have been activated using @p pwmStart().
 * @post    The channel is active using the specified configuration.
 * @note    Depending on the hardware implementation this function has
 *          effect starting on the next cycle (recommended implementation)
 *          or immediately (fallback implementation).
 *
 * @param[in] pwmp      pointer to a @p PWMDriver object
 * @param[in] channel   PWM channel identifier (0...PWM_CHANNELS-1)
 * @param[in] width     PWM pulse width as clock pulses number
 *
 * @notapi
 */
void pwm_lld_enable_channel(PWMDriver *pwmp,
                            pwmchannel_t channel,
                            pwmcnt_t width)
{
  uint16_t val = width;
  if (val > MAX_PWM_VALUE)
    val = MAX_PWM_VALUE;

#if AVR_PWM_USE_TIM2 || defined(__DOXYGEN__)
  if (pwmp == &PWMD2) {
    config_channel(&TCCR2A,
                   7 - 2*channel,
                   6 - 2*channel,
                   pwmp->config->channels[channel].mode);
    TIMSK2 |= (1 << (channel + 1));
    /* Timer 2 is 8 bit */
    if (val > 0xFF)
      val = 0xFF;
    if (pwmp->config->channels[channel].callback) {
      switch (channel) {
      case 0: OCR2A = val; break;
      case 1: OCR2B = val; break;
      }
    }
    return;
  }
#endif

  uint8_t i = timer_index(pwmp);
  config_channel(regs_table[i].tccra,
                 7 - 2*channel,
                 6 - 2*channel,
                 pwmp->config->channels[channel].mode);
  volatile uint8_t *ocrh, *ocrl;
  switch (channel) {
  case 1:
    ocrh = regs_table[i].ocrbh;
    ocrl = regs_table[i].ocrbl;
    break;
  case 2:
    ocrh = regs_table[i].ocrch;
    ocrl = regs_table[i].ocrcl;
    break;
  default:
    ocrh = regs_table[i].ocrah;
    ocrl = regs_table[i].ocral;
  }
  *ocrh = val >> 8;
  *ocrl = val & 0xFF;
  *regs_table[i].tifr |= (1 << (channel + 1));
  if (pwmp->config->channels[channel].callback)
    *regs_table[i].timsk |= (1 << (channel + 1));
}
예제 #2
0
/**
 * @brief   Disables a PWM channel.
 * @pre     The PWM unit must have been activated using @p pwmStart().
 * @post    The channel is disabled and its output line returned to the
 *          idle state.
 * @note    Depending on the hardware implementation this function has
 *          effect starting on the next cycle (recommended implementation)
 *          or immediately (fallback implementation).
 *
 * @param[in] pwmp      pointer to a @p PWMDriver object
 * @param[in] channel   PWM channel identifier (0...PWM_CHANNELS-1)
 *
 * @notapi
 */
void pwm_lld_disable_channel(PWMDriver *pwmp, pwmchannel_t channel)
{
  uint8_t i = timer_index(pwmp);
  config_channel(regs_table[i].tccra,
                 7 - 2*channel,
                 6 - 2*channel,
                 PWM_OUTPUT_DISABLED);
  *regs_table[i].timsk &= ~(1 << (channel + 1));
}
예제 #3
0
static int timer_config(struct simio_device *dev,
                        const char *param, char **arg_text)
{
    struct timer *tr = (struct timer *)dev;

    if (!strcasecmp(param, "base"))
        return config_addr(&tr->base_addr, arg_text);
    if (!strcasecmp(param, "iv"))
        return config_addr(&tr->iv_addr, arg_text);
    if (!strcasecmp(param, "irq0"))
        return config_irq(&tr->irq0, arg_text);
    if (!strcasecmp(param, "irq1"))
        return config_irq(&tr->irq1, arg_text);
    if (!strcasecmp(param, "set"))
        return config_channel(tr, arg_text);

    printc_err("timer: config: unknown parameter: %s\n", param);
    return -1;
}