@@ -44,7 +44,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;
}
@@ -102,11 +102,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);
}
}
@@ -22,6 +22,8 @@
/* Starting to run with/setting counter = 0 won't perform immediate
* 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;
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 | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-)