From 7668a4d27e9948941ee1ffe32b343dfce30f746b Mon Sep 17 00:00:00 2001 From: Sylvio Alves Date: Wed, 9 Oct 2024 21:25:11 -0300 Subject: [PATCH] drivers: counter: esp32: force capture to read value Force capture call so that timer counter value is updated accordingly. This also adds get_value_64 counter API function. Signed-off-by: Sylvio Alves --- drivers/counter/counter_esp32_tmr.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/counter/counter_esp32_tmr.c b/drivers/counter/counter_esp32_tmr.c index ef90dad51c2..90ad22df3fe 100644 --- a/drivers/counter/counter_esp32_tmr.c +++ b/drivers/counter/counter_esp32_tmr.c @@ -138,7 +138,22 @@ static int counter_esp32_get_value(const struct device *dev, uint32_t *ticks) struct counter_esp32_data *data = dev->data; k_spinlock_key_t key = k_spin_lock(&lock); + timer_ll_trigger_soft_capture(data->hal_ctx.dev, data->hal_ctx.timer_id); + *ticks = (uint32_t)timer_ll_get_counter_value(data->hal_ctx.dev, data->hal_ctx.timer_id); + + k_spin_unlock(&lock, key); + + return 0; +} + +static int counter_esp32_get_value_64(const struct device *dev, uint64_t *ticks) +{ + struct counter_esp32_data *data = dev->data; + k_spinlock_key_t key = k_spin_lock(&lock); + + timer_ll_trigger_soft_capture(data->hal_ctx.dev, data->hal_ctx.timer_id); *ticks = timer_ll_get_counter_value(data->hal_ctx.dev, data->hal_ctx.timer_id); + k_spin_unlock(&lock, key); return 0; @@ -217,6 +232,7 @@ static const struct counter_driver_api counter_api = { .start = counter_esp32_start, .stop = counter_esp32_stop, .get_value = counter_esp32_get_value, + .get_value_64 = counter_esp32_get_value_64, .set_alarm = counter_esp32_set_alarm, .cancel_alarm = counter_esp32_cancel_alarm, .set_top_value = counter_esp32_set_top_value,