• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
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  */
36 struct alarm {
37 	struct timerqueue_node	node;
38 	struct hrtimer		timer;
39 	enum alarmtimer_restart	(*function)(struct alarm *, ktime_t now);
40 	enum alarmtimer_type	type;
41 	int			state;
42 	void			*data;
43 };
44 
45 void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
46 		enum alarmtimer_restart (*function)(struct alarm *, ktime_t));
47 int alarm_start(struct alarm *alarm, ktime_t start);
48 int alarm_start_relative(struct alarm *alarm, ktime_t start);
49 void alarm_restart(struct alarm *alarm);
50 int alarm_try_to_cancel(struct alarm *alarm);
51 int alarm_cancel(struct alarm *alarm);
52 
53 u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
54 u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
55 ktime_t alarm_expires_remaining(const struct alarm *alarm);
56 
57 /*
58  * A alarmtimer is active, when it is enqueued into timerqueue or the
59  * callback function is running.
60  */
alarmtimer_active(const struct alarm * timer)61 static inline int alarmtimer_active(const struct alarm *timer)
62 {
63 	return timer->state != ALARMTIMER_STATE_INACTIVE;
64 }
65 
66 /*
67  * Helper function to check, whether the timer is on one of the queues
68  */
alarmtimer_is_queued(struct alarm * timer)69 static inline int alarmtimer_is_queued(struct alarm *timer)
70 {
71 	return timer->state & ALARMTIMER_STATE_ENQUEUED;
72 }
73 
74 /*
75  * Helper function to check, whether the timer is running the callback
76  * function
77  */
alarmtimer_callback_running(struct alarm * timer)78 static inline int alarmtimer_callback_running(struct alarm *timer)
79 {
80 	return timer->state & ALARMTIMER_STATE_CALLBACK;
81 }
82 
83 
84 /* Provide way to access the rtc device being used by alarmtimers */
85 struct rtc_device *alarmtimer_get_rtcdev(void);
86 
87 #endif
88