diff options
author | Dmitry Osipenko <digetx@gmail.com> | 2016-06-06 16:59:31 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2016-06-06 16:59:31 +0100 |
commit | 869e92b5c392eb6b2c7b398b878c435442b8e9dd (patch) | |
tree | 58e264d91ded1f669a59d96f5a50e5c0dc30b6eb /hw | |
parent | 7ef6e3cf8d29022c31d417be12042af33682e2b8 (diff) |
hw/ptimer: Support "on the fly" timer mode switch
Allow switching between periodic <-> oneshot modes while timer is running.
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Message-id: f030be6e28fbd219e1e8d22297aee367bd9af5bb.1464367869.git.digetx@gmail.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/core/ptimer.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index 76ebe9b48c..d0b2f38082 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -163,16 +163,17 @@ void ptimer_set_count(ptimer_state *s, uint64_t count) void ptimer_run(ptimer_state *s, int oneshot) { - if (s->enabled) { - return; - } - if (s->period == 0) { + bool was_disabled = !s->enabled; + + if (was_disabled && s->period == 0) { fprintf(stderr, "Timer with period zero, disabling\n"); return; } s->enabled = oneshot ? 2 : 1; - s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - ptimer_reload(s); + if (was_disabled) { + s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + ptimer_reload(s); + } } /* Pause a timer. Note that this may cause it to "lose" time, even if it |