From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6LBx-0002Sl-8J for qemu-devel@nongnu.org; Fri, 27 May 2016 13:04:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b6LBn-0003pN-6O for qemu-devel@nongnu.org; Fri, 27 May 2016 13:04:56 -0400 From: Dmitry Osipenko Date: Fri, 27 May 2016 20:03:32 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: Subject: [Qemu-devel] [PATCH v13 4/8] hw/ptimer: Support "on the fly" timer mode switch List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Developers , qemu-arm@nongnu.org Cc: Peter Crosthwaite , Peter Maydell Allow switching between periodic <-> oneshot modes while timer is running. Signed-off-by: Dmitry Osipenko Reviewed-by: Peter Crosthwaite --- hw/core/ptimer.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index 76ebe9b..d0b2f38 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 -- 2.8.3