drivers: esp32: add check for absolute alarm configuration

ESP32 counter based on Timer or RTC misses the
COUNTER_ALARM_CFG_ABSOLUTE flag check.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
This commit is contained in:
Sylvio Alves 2022-09-14 10:28:38 -03:00 committed by Carles Cufí
parent e8954e6c11
commit e4969ec52e
2 changed files with 13 additions and 2 deletions

View File

@ -107,8 +107,13 @@ static int counter_esp32_set_alarm(const struct device *dev, uint8_t chan_id,
counter_esp32_get_value(dev, &now);
if ((alarm_cfg->flags & COUNTER_ALARM_CFG_ABSOLUTE) == 0) {
WRITE_PERI_REG(RTC_CNTL_SLP_TIMER0_REG, (now + alarm_cfg->ticks));
} else {
WRITE_PERI_REG(RTC_CNTL_SLP_TIMER0_REG, alarm_cfg->ticks);
}
/* RTC main timer set alarm value */
WRITE_PERI_REG(RTC_CNTL_SLP_TIMER0_REG, (now + alarm_cfg->ticks));
CLEAR_PERI_REG_MASK(RTC_CNTL_SLP_TIMER1_REG, 0xffffffff);
/* RTC main timer interrupt enable */

View File

@ -140,9 +140,15 @@ static int counter_esp32_set_alarm(const struct device *dev, uint8_t chan_id,
uint32_t now;
counter_esp32_get_value(dev, &now);
k_spinlock_key_t key = k_spin_lock(&lock);
timer_hal_set_alarm_value(&data->hal_ctx, (now + alarm_cfg->ticks));
if ((alarm_cfg->flags & COUNTER_ALARM_CFG_ABSOLUTE) == 0) {
timer_hal_set_alarm_value(&data->hal_ctx, (now + alarm_cfg->ticks));
} else {
timer_hal_set_alarm_value(&data->hal_ctx, alarm_cfg->ticks);
}
timer_hal_intr_enable(&data->hal_ctx);
timer_hal_set_alarm_enable(&data->hal_ctx, TIMER_ALARM_EN);
data->alarm_cfg.callback = alarm_cfg->callback;