diff mbox series

[qemu,v3,03/20] Fixing the basic functionality of STM32 timers

Message ID 170152443229.18048.53824064267512246-3@git.sr.ht
State New
Headers show
Series Fix malfunctioning of T2-T5 timers on the STM32 platform | expand

Commit Message

~lbryndza Dec. 2, 2023, 12:09 p.m. UTC
From: Lucjan Bryndza <lbryndza.oss@icloud.com>

The current implementation of timers does not work properly
even in basic functionality. A counter configured to report
an interrupt every 10ms reports the first interrupts after a
few seconds.  There are also no properly implemented count up an
count down modes. This commit fixes bugs with interrupt
reporting and implements the basic modes of the counter's
time-base block.

Add timer get counter function

Signed-off-by: Lucjan Bryndza <lbryndza.oss@icloud.com>
---
 hw/timer/stm32f2xx_timer.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/hw/timer/stm32f2xx_timer.c b/hw/timer/stm32f2xx_timer.c
index f03f594a17..0c5586cb8b 100644
--- a/hw/timer/stm32f2xx_timer.c
+++ b/hw/timer/stm32f2xx_timer.c
@@ -48,6 +48,16 @@ 
 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
 
 
+static uint32_t stm32f2xx_timer_get_count(STM32F2XXTimerState *s)
+{
+    uint64_t cnt = ptimer_get_count(s->timer);
+    if (s->count_mode == TIMER_UP_COUNT) {
+        return s->tim_arr - (cnt & 0xffff);
+    } else {
+        return cnt & 0xffff;
+    }
+}
+
 
 static void stm32f2xx_timer_reset(DeviceState *dev)
 {