John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [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 | |
John Stultz | 4b41308 | 2011-08-10 10:37:59 -0700 | [diff] [blame] | 16 | enum alarmtimer_restart { |
| 17 | ALARMTIMER_NORESTART, |
| 18 | ALARMTIMER_RESTART, |
| 19 | }; |
| 20 | |
John Stultz | a28cde8 | 2011-08-10 12:30:21 -0700 | [diff] [blame] | 21 | |
| 22 | #define ALARMTIMER_STATE_INACTIVE 0x00 |
| 23 | #define ALARMTIMER_STATE_ENQUEUED 0x01 |
John Stultz | a28cde8 | 2011-08-10 12:30:21 -0700 | [diff] [blame] | 24 | |
John Stultz | 180bf81 | 2011-04-28 12:58:11 -0700 | [diff] [blame] | 25 | /** |
| 26 | * struct alarm - Alarm timer structure |
| 27 | * @node: timerqueue node for adding to the event list this value |
| 28 | * also includes the expiration time. |
| 29 | * @period: Period for recuring alarms |
| 30 | * @function: Function pointer to be executed when the timer fires. |
| 31 | * @type: Alarm type (BOOTTIME/REALTIME) |
| 32 | * @enabled: Flag that represents if the alarm is set to fire or not |
| 33 | * @data: Internal data value. |
| 34 | */ |
John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [diff] [blame] | 35 | struct alarm { |
| 36 | struct timerqueue_node node; |
John Stultz | dae373b | 2012-09-13 19:12:16 -0400 | [diff] [blame] | 37 | struct hrtimer timer; |
John Stultz | 4b41308 | 2011-08-10 10:37:59 -0700 | [diff] [blame] | 38 | enum alarmtimer_restart (*function)(struct alarm *, ktime_t now); |
John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [diff] [blame] | 39 | enum alarmtimer_type type; |
John Stultz | a28cde8 | 2011-08-10 12:30:21 -0700 | [diff] [blame] | 40 | int state; |
John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [diff] [blame] | 41 | void *data; |
| 42 | }; |
| 43 | |
| 44 | void alarm_init(struct alarm *alarm, enum alarmtimer_type type, |
John Stultz | 4b41308 | 2011-08-10 10:37:59 -0700 | [diff] [blame] | 45 | enum alarmtimer_restart (*function)(struct alarm *, ktime_t)); |
John Stultz | dae373b | 2012-09-13 19:12:16 -0400 | [diff] [blame] | 46 | int alarm_start(struct alarm *alarm, ktime_t start); |
John Stultz | 9082c46 | 2011-08-10 12:41:36 -0700 | [diff] [blame] | 47 | int alarm_try_to_cancel(struct alarm *alarm); |
| 48 | int alarm_cancel(struct alarm *alarm); |
John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [diff] [blame] | 49 | |
John Stultz | dce75a8 | 2011-08-10 11:31:03 -0700 | [diff] [blame] | 50 | u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval); |
| 51 | |
John Stultz | 57c498f | 2012-04-20 12:31:45 -0700 | [diff] [blame] | 52 | /* Provide way to access the rtc device being used by alarmtimers */ |
| 53 | struct rtc_device *alarmtimer_get_rtcdev(void); |
| 54 | |
John Stultz | ff3ead9 | 2011-01-11 09:42:13 -0800 | [diff] [blame] | 55 | #endif |