blob: 304124a6c982a14b4b9467e571f526475c212979 [file] [log] [blame]
John Stultzff3ead92011-01-11 09:42:13 -08001#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
John Stultz4b413082011-08-10 10:37:59 -070016enum alarmtimer_restart {
17 ALARMTIMER_NORESTART,
18 ALARMTIMER_RESTART,
19};
20
John Stultza28cde82011-08-10 12:30:21 -070021
22#define ALARMTIMER_STATE_INACTIVE 0x00
23#define ALARMTIMER_STATE_ENQUEUED 0x01
24#define ALARMTIMER_STATE_CALLBACK 0x02
25
John Stultz180bf812011-04-28 12:58:11 -070026/**
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 */
John Stultzff3ead92011-01-11 09:42:13 -080036struct alarm {
37 struct timerqueue_node node;
John Stultz4b413082011-08-10 10:37:59 -070038 enum alarmtimer_restart (*function)(struct alarm *, ktime_t now);
John Stultzff3ead92011-01-11 09:42:13 -080039 enum alarmtimer_type type;
John Stultza28cde82011-08-10 12:30:21 -070040 int state;
John Stultzff3ead92011-01-11 09:42:13 -080041 void *data;
42};
43
44void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
John Stultz4b413082011-08-10 10:37:59 -070045 enum alarmtimer_restart (*function)(struct alarm *, ktime_t));
John Stultz9e264762011-08-10 12:09:24 -070046void alarm_start(struct alarm *alarm, ktime_t start);
John Stultzff3ead92011-01-11 09:42:13 -080047void alarm_cancel(struct alarm *alarm);
48
John Stultzdce75a82011-08-10 11:31:03 -070049u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
50
John Stultza28cde82011-08-10 12:30:21 -070051/*
52 * A alarmtimer is active, when it is enqueued into timerqueue or the
53 * callback function is running.
54 */
55static inline int alarmtimer_active(const struct alarm *timer)
56{
57 return timer->state != ALARMTIMER_STATE_INACTIVE;
58}
59
60/*
61 * Helper function to check, whether the timer is on one of the queues
62 */
63static inline int alarmtimer_is_queued(struct alarm *timer)
64{
65 return timer->state & ALARMTIMER_STATE_ENQUEUED;
66}
67
68/*
69 * Helper function to check, whether the timer is running the callback
70 * function
71 */
72static inline int alarmtimer_callback_running(struct alarm *timer)
73{
74 return timer->state & ALARMTIMER_STATE_CALLBACK;
75}
76
77
John Stultzff3ead92011-01-11 09:42:13 -080078#endif