Skip to content

Commit

Permalink
hw/ptimer: Support "on the fly" timer mode switch
Browse files Browse the repository at this point in the history
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: f030be6.1464367869.git.digetx@gmail.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
digetx authored and pm215 committed Jun 6, 2016
1 parent 7ef6e3c commit 869e92b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions hw/core/ptimer.c
Expand Up @@ -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
Expand Down

0 comments on commit 869e92b

Please sign in to comment.