alarmtimer.h 1.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#ifndef _LINUX_ALARMTIMER_H
#define _LINUX_ALARMTIMER_H

#include <linux/time.h>
#include <linux/hrtimer.h>
#include <linux/timerqueue.h>
#include <linux/rtc.h>

enum alarmtimer_type {
	ALARM_REALTIME,
	ALARM_BOOTTIME,

	ALARM_NUMTYPE,
};

16 17 18 19 20
enum alarmtimer_restart {
	ALARMTIMER_NORESTART,
	ALARMTIMER_RESTART,
};

21 22 23 24

#define ALARMTIMER_STATE_INACTIVE	0x00
#define ALARMTIMER_STATE_ENQUEUED	0x01

25 26 27 28
/**
 * struct alarm - Alarm timer structure
 * @node:	timerqueue node for adding to the event list this value
 *		also includes the expiration time.
29
 * @timer:	hrtimer used to schedule events while running
30
 * @function:	Function pointer to be executed when the timer fires.
31 32
 * @type:	Alarm type (BOOTTIME/REALTIME).
 * @state:	Flag that represents if the alarm is set to fire or not.
33 34
 * @data:	Internal data value.
 */
35 36
struct alarm {
	struct timerqueue_node	node;
37
	struct hrtimer		timer;
38
	enum alarmtimer_restart	(*function)(struct alarm *, ktime_t now);
39
	enum alarmtimer_type	type;
40
	int			state;
41 42 43 44
	void			*data;
};

void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
45
		enum alarmtimer_restart (*function)(struct alarm *, ktime_t));
46 47
void alarm_start(struct alarm *alarm, ktime_t start);
void alarm_start_relative(struct alarm *alarm, ktime_t start);
48
void alarm_restart(struct alarm *alarm);
49 50
int alarm_try_to_cancel(struct alarm *alarm);
int alarm_cancel(struct alarm *alarm);
51

52
u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
53 54
u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
ktime_t alarm_expires_remaining(const struct alarm *alarm);
55

56 57 58
/* Provide way to access the rtc device being used by alarmtimers */
struct rtc_device *alarmtimer_get_rtcdev(void);

59
#endif