blob: 7d9a6cf75b29172ad81b1fa1f486b58e4e78de4b [file] [log] [blame]
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01001#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
9enum alarmtimer_type {
10 ALARM_REALTIME,
11 ALARM_BOOTTIME,
12
13 ALARM_NUMTYPE,
14};
15
16enum alarmtimer_restart {
17 ALARMTIMER_NORESTART,
18 ALARMTIMER_RESTART,
19};
20
21
22#define ALARMTIMER_STATE_INACTIVE 0x00
23#define ALARMTIMER_STATE_ENQUEUED 0x01
24#define ALARMTIMER_STATE_CALLBACK 0x02
25
26struct alarm {
27 struct timerqueue_node node;
28 enum alarmtimer_restart (*function)(struct alarm *, ktime_t now);
29 enum alarmtimer_type type;
30 int state;
31 void *data;
32};
33
34void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
35 enum alarmtimer_restart (*function)(struct alarm *, ktime_t));
36void alarm_start(struct alarm *alarm, ktime_t start);
37int alarm_try_to_cancel(struct alarm *alarm);
38int alarm_cancel(struct alarm *alarm);
39
40u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
41
42static inline int alarmtimer_active(const struct alarm *timer)
43{
44 return timer->state != ALARMTIMER_STATE_INACTIVE;
45}
46
47static inline int alarmtimer_is_queued(struct alarm *timer)
48{
49 return timer->state & ALARMTIMER_STATE_ENQUEUED;
50}
51
52static inline int alarmtimer_callback_running(struct alarm *timer)
53{
54 return timer->state & ALARMTIMER_STATE_CALLBACK;
55}
56
57
58struct rtc_device *alarmtimer_get_rtcdev(void);
59
60#endif