Commit | Line | Data |
---|---|---|
ff3ead96 JS |
1 | #ifndef _LINUX_ALARMTIMER_H |
2 | #define _LINUX_ALARMTIMER_H | |
3 | ||
4 | #include <linux/time.h> | |
5 | #include <linux/hrtimer.h> | |
6 | #include <linux/timerqueue.h> | |
7 | #include <linux/rtc.h> | |
8 | ||
9 | enum alarmtimer_type { | |
10 | ALARM_REALTIME, | |
11 | ALARM_BOOTTIME, | |
12 | ||
13 | ALARM_NUMTYPE, | |
14 | }; | |
15 | ||
4b41308d JS |
16 | enum alarmtimer_restart { |
17 | ALARMTIMER_NORESTART, | |
18 | ALARMTIMER_RESTART, | |
19 | }; | |
20 | ||
a28cde81 JS |
21 | |
22 | #define ALARMTIMER_STATE_INACTIVE 0x00 | |
23 | #define ALARMTIMER_STATE_ENQUEUED 0x01 | |
24 | #define ALARMTIMER_STATE_CALLBACK 0x02 | |
25 | ||
180bf812 JS |
26 | /** |
27 | * struct alarm - Alarm timer structure | |
28 | * @node: timerqueue node for adding to the event list this value | |
29 | * also includes the expiration time. | |
30 | * @period: Period for recuring alarms | |
31 | * @function: Function pointer to be executed when the timer fires. | |
32 | * @type: Alarm type (BOOTTIME/REALTIME) | |
33 | * @enabled: Flag that represents if the alarm is set to fire or not | |
34 | * @data: Internal data value. | |
35 | */ | |
ff3ead96 JS |
36 | struct alarm { |
37 | struct timerqueue_node node; | |
4b41308d | 38 | enum alarmtimer_restart (*function)(struct alarm *, ktime_t now); |
ff3ead96 | 39 | enum alarmtimer_type type; |
a28cde81 | 40 | int state; |
ff3ead96 JS |
41 | void *data; |
42 | }; | |
43 | ||
44 | void alarm_init(struct alarm *alarm, enum alarmtimer_type type, | |
4b41308d | 45 | enum alarmtimer_restart (*function)(struct alarm *, ktime_t)); |
9e264762 | 46 | void alarm_start(struct alarm *alarm, ktime_t start); |
9082c465 JS |
47 | int alarm_try_to_cancel(struct alarm *alarm); |
48 | int alarm_cancel(struct alarm *alarm); | |
ff3ead96 | 49 | |
dce75a8c JS |
50 | u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval); |
51 | ||
a28cde81 JS |
52 | /* |
53 | * A alarmtimer is active, when it is enqueued into timerqueue or the | |
54 | * callback function is running. | |
55 | */ | |
56 | static inline int alarmtimer_active(const struct alarm *timer) | |
57 | { | |
58 | return timer->state != ALARMTIMER_STATE_INACTIVE; | |
59 | } | |
60 | ||
61 | /* | |
62 | * Helper function to check, whether the timer is on one of the queues | |
63 | */ | |
64 | static inline int alarmtimer_is_queued(struct alarm *timer) | |
65 | { | |
66 | return timer->state & ALARMTIMER_STATE_ENQUEUED; | |
67 | } | |
68 | ||
69 | /* | |
70 | * Helper function to check, whether the timer is running the callback | |
71 | * function | |
72 | */ | |
73 | static inline int alarmtimer_callback_running(struct alarm *timer) | |
74 | { | |
75 | return timer->state & ALARMTIMER_STATE_CALLBACK; | |
76 | } | |
77 | ||
78 | ||
ff3ead96 | 79 | #endif |