Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 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 | |
| 16 | enum 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 | |
| 26 | struct 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 | |
| 34 | void alarm_init(struct alarm *alarm, enum alarmtimer_type type, |
| 35 | enum alarmtimer_restart (*function)(struct alarm *, ktime_t)); |
| 36 | void alarm_start(struct alarm *alarm, ktime_t start); |
| 37 | int alarm_try_to_cancel(struct alarm *alarm); |
| 38 | int alarm_cancel(struct alarm *alarm); |
| 39 | |
| 40 | u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval); |
| 41 | |
| 42 | static inline int alarmtimer_active(const struct alarm *timer) |
| 43 | { |
| 44 | return timer->state != ALARMTIMER_STATE_INACTIVE; |
| 45 | } |
| 46 | |
| 47 | static inline int alarmtimer_is_queued(struct alarm *timer) |
| 48 | { |
| 49 | return timer->state & ALARMTIMER_STATE_ENQUEUED; |
| 50 | } |
| 51 | |
| 52 | static inline int alarmtimer_callback_running(struct alarm *timer) |
| 53 | { |
| 54 | return timer->state & ALARMTIMER_STATE_CALLBACK; |
| 55 | } |
| 56 | |
| 57 | |
| 58 | struct rtc_device *alarmtimer_get_rtcdev(void); |
| 59 | |
| 60 | #endif |