]> Git Repo - qemu.git/blob - include/hw/ptimer.h
Merge remote-tracking branch 'remotes/kraxel/tags/pull-docs-20170301-1' into staging
[qemu.git] / include / hw / ptimer.h
1 /*
2  * General purpose implementation of a simple periodic countdown timer.
3  *
4  * Copyright (c) 2007 CodeSourcery.
5  *
6  * This code is licensed under the GNU LGPL.
7  */
8 #ifndef PTIMER_H
9 #define PTIMER_H
10
11 #include "qemu-common.h"
12 #include "qemu/timer.h"
13 #include "migration/vmstate.h"
14
15 /* The default ptimer policy retains backward compatibility with the legacy
16  * timers. Custom policies are adjusting the default one. Consider providing
17  * a correct policy for your timer.
18  *
19  * The rough edges of the default policy:
20  *  - Starting to run with a period = 0 emits error message and stops the
21  *    timer without a trigger.
22  *
23  *  - Setting period to 0 of the running timer emits error message and
24  *    stops the timer without a trigger.
25  *
26  *  - Starting to run with counter = 0 or setting it to "0" while timer
27  *    is running causes a trigger and reloads counter with a limit value.
28  *    If limit = 0, ptimer emits error message and stops the timer.
29  *
30  *  - Counter value of the running timer is one less than the actual value.
31  *
32  *  - Changing period/frequency of the running timer loses time elapsed
33  *    since the last period, effectively restarting the timer with a
34  *    counter = counter value at the moment of change (.i.e. one less).
35  */
36 #define PTIMER_POLICY_DEFAULT               0
37
38 /* Periodic timer counter stays with "0" for a one period before wrapping
39  * around.  */
40 #define PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD (1 << 0)
41
42 /* Running periodic timer that has counter = limit = 0 would continuously
43  * re-trigger every period.  */
44 #define PTIMER_POLICY_CONTINUOUS_TRIGGER    (1 << 1)
45
46 /* Starting to run with/setting counter to "0" won't trigger immediately,
47  * but after a one period for both oneshot and periodic modes.  */
48 #define PTIMER_POLICY_NO_IMMEDIATE_TRIGGER  (1 << 2)
49
50 /* Starting to run with/setting counter to "0" won't re-load counter
51  * immediately, but after a one period.  */
52 #define PTIMER_POLICY_NO_IMMEDIATE_RELOAD   (1 << 3)
53
54 /* Make counter value of the running timer represent the actual value and
55  * not the one less.  */
56 #define PTIMER_POLICY_NO_COUNTER_ROUND_DOWN (1 << 4)
57
58 /* ptimer.c */
59 typedef struct ptimer_state ptimer_state;
60 typedef void (*ptimer_cb)(void *opaque);
61
62 ptimer_state *ptimer_init(QEMUBH *bh, uint8_t policy_mask);
63 void ptimer_free(ptimer_state *s);
64 void ptimer_set_period(ptimer_state *s, int64_t period);
65 void ptimer_set_freq(ptimer_state *s, uint32_t freq);
66 uint64_t ptimer_get_limit(ptimer_state *s);
67 void ptimer_set_limit(ptimer_state *s, uint64_t limit, int reload);
68 uint64_t ptimer_get_count(ptimer_state *s);
69 void ptimer_set_count(ptimer_state *s, uint64_t count);
70 void ptimer_run(ptimer_state *s, int oneshot);
71 void ptimer_stop(ptimer_state *s);
72
73 extern const VMStateDescription vmstate_ptimer;
74
75 #define VMSTATE_PTIMER(_field, _state) \
76     VMSTATE_STRUCT_POINTER_V(_field, _state, 1, vmstate_ptimer, ptimer_state)
77
78 #define VMSTATE_PTIMER_ARRAY(_f, _s, _n)                                \
79     VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, 0,                   \
80                                        vmstate_ptimer, ptimer_state)
81
82 #endif
This page took 0.031718 seconds and 4 git commands to generate.