@@ -45,7 +45,7 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
ptimer_trigger(s);
}
- if (delta == 0) {
+ if (delta == 0 && !(s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_RELOAD)) {
delta = s->delta = s->limit;
}
@@ -107,11 +107,13 @@ static void ptimer_tick(void *opaque)
{
ptimer_state *s = (ptimer_state *)opaque;
ptimer_trigger(s);
- s->delta = 0;
if (s->enabled == 2) {
+ s->delta = 0;
s->enabled = 0;
} else {
- ptimer_reload(s, 1);
+ int delta_adjust = (s->delta != 0 && s->limit != 0) ? 1 : 0;
+ s->delta = s->limit;
+ ptimer_reload(s, delta_adjust);
}
}
@@ -46,6 +46,9 @@
* trigger. */
#define PTIMER_POLICY_NO_IMMEDIATE_TRIGGER (1 << 2)
+/* Starting to run with/setting counter = 0 won't re-load counter. */
+#define PTIMER_POLICY_NO_IMMEDIATE_RELOAD (1 << 3)
+
/* ptimer.c */
typedef struct ptimer_state ptimer_state;
typedef void (*ptimer_cb)(void *opaque);
Immediate counter re-load on setting (or on starting to run with) counter = 0 is a wrong behaviour for some of the timers. Add "no immediate reload" policy that provides correct behaviour for such timers. Signed-off-by: Dmitry Osipenko <digetx@gmail.com> --- hw/core/ptimer.c | 8 +++++--- include/hw/ptimer.h | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-)