7
7
#ifndef TIMER_H
8
8
#define TIMER_H
9
9
10
+ /**
11
+ * @brief Timer
12
+ *
13
+ * @defgroup timer ACRN Timer
14
+ * @{
15
+ */
16
+
10
17
typedef void (* timer_handle_t )(void * data );
11
18
19
+ /**
20
+ * @brief Definition of timer tick mode
21
+ */
12
22
enum tick_mode {
13
- TICK_MODE_ONESHOT = 0 ,
14
- TICK_MODE_PERIODIC ,
23
+ TICK_MODE_ONESHOT = 0 , /**< one-shot mode */
24
+ TICK_MODE_PERIODIC , /**< periodic mode */
15
25
};
16
26
27
+ /**
28
+ * @brief Definition of timers for per-cpu
29
+ */
17
30
struct per_cpu_timers {
18
- struct list_head timer_list ; /* it's for runtime active timer list */
31
+ struct list_head timer_list ; /**< it's for runtime active timer list */
19
32
};
20
33
34
+ /**
35
+ * @brief Definition of timer
36
+ */
21
37
struct hv_timer {
22
- struct list_head node ; /* link all timers */
23
- enum tick_mode mode ; /* timer mode: one-shot or periodic */
24
- uint64_t fire_tsc ; /* tsc deadline to interrupt */
25
- uint64_t period_in_cycle ; /* period of the periodic timer in unit of TSC cycles */
26
- timer_handle_t func ; /* callback if time reached */
27
- void * priv_data ; /* func private data */
38
+ struct list_head node ; /**< link all timers */
39
+ enum tick_mode mode ; /**< timer mode: one-shot or periodic */
40
+ uint64_t fire_tsc ; /**< tsc deadline to interrupt */
41
+ uint64_t period_in_cycle ; /**< period of the periodic timer in unit of TSC cycles */
42
+ timer_handle_t func ; /**< callback if time reached */
43
+ void * priv_data ; /**< func private data */
28
44
};
29
45
30
- /*
31
- * Don't initialize a timer twice if it has been add to the timer list
32
- * after call add_timer. If u want, delete the timer from the list first.
46
+ /* External Interfaces */
47
+
48
+ /**
49
+ * @brief Initialize a timer structure.
50
+ *
51
+ * @param[in] timer Pointer to timer.
52
+ * @param[in] func irq callback if time reached.
53
+ * @param[in] priv_data func private data.
54
+ * @param[in] fire_tsc tsc deadline to interrupt.
55
+ * @param[in] mode timer mode.
56
+ * @param[in] period_in_cycle period of the periodic timer in unit of TSC cycles.
57
+ *
58
+ * @remark Don't initialize a timer twice if it has been added to the timer list
59
+ * after calling add_timer. If you want to, delete the timer from the list first.
60
+ *
61
+ * @return None
33
62
*/
34
63
static inline void initialize_timer (struct hv_timer * timer ,
35
- timer_handle_t func ,
36
- void * priv_data ,
37
- uint64_t fire_tsc ,
38
- int mode ,
39
- uint64_t period_in_cycle )
64
+ timer_handle_t func , void * priv_data ,
65
+ uint64_t fire_tsc , int mode , uint64_t period_in_cycle )
40
66
{
41
67
if (timer != NULL ) {
42
68
timer -> func = func ;
@@ -48,19 +74,62 @@ static inline void initialize_timer(struct hv_timer *timer,
48
74
}
49
75
}
50
76
77
+ /**
78
+ * @brief Check a timer whether expired.
79
+ *
80
+ * @param[in] timer Pointer to timer.
81
+ *
82
+ * @retval true if the timer is expired, false otherwise.
83
+ */
51
84
static inline bool timer_expired (const struct hv_timer * timer )
52
85
{
53
86
return ((timer -> fire_tsc == 0UL ) || (rdtsc () >= timer -> fire_tsc ));
54
87
}
55
88
56
- /*
57
- * Don't call add_timer/del_timer in the timer callback function.
89
+ /**
90
+ * @brief Add a timer.
91
+ *
92
+ * @param[in] timer Pointer to timer.
93
+ *
94
+ * @retval 0 on success
95
+ * @retval -EINVAL timer has an invalid value
96
+ *
97
+ * @remark Don't call it in the timer callback function or interrupt content.
58
98
*/
59
99
int add_timer (struct hv_timer * timer );
100
+
101
+ /**
102
+ * @brief Delete a timer.
103
+ *
104
+ * @param[in] timer Pointer to timer.
105
+ *
106
+ * @return None
107
+ *
108
+ * @remark Don't call it in the timer callback function or interrupt content.
109
+ */
60
110
void del_timer (struct hv_timer * timer );
61
111
112
+ /**
113
+ * @brief Initialize timer.
114
+ *
115
+ * @return None
116
+ */
62
117
void timer_init (void );
118
+
119
+ /**
120
+ * @brief Check tsc to make sure rdtsc is enabled.
121
+ */
63
122
void check_tsc (void );
123
+
124
+ /**
125
+ * @brief Calibrate tsc.
126
+ *
127
+ * @return None
128
+ */
64
129
void calibrate_tsc (void );
65
130
131
+ /**
132
+ * @}
133
+ */
134
+
66
135
#endif /* TIMER_H */
0 commit comments