alarmtimer.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef _LINUX_ALARMTIMER_H
  2. #define _LINUX_ALARMTIMER_H
  3. #include <linux/time.h>
  4. #include <linux/hrtimer.h>
  5. #include <linux/timerqueue.h>
  6. #include <linux/rtc.h>
  7. enum alarmtimer_type {
  8. ALARM_REALTIME,
  9. ALARM_BOOTTIME,
  10. ALARM_NUMTYPE,
  11. };
  12. enum alarmtimer_restart {
  13. ALARMTIMER_NORESTART,
  14. ALARMTIMER_RESTART,
  15. };
  16. #define ALARMTIMER_STATE_INACTIVE 0x00
  17. #define ALARMTIMER_STATE_ENQUEUED 0x01
  18. /**
  19. * struct alarm - Alarm timer structure
  20. * @node: timerqueue node for adding to the event list this value
  21. * also includes the expiration time.
  22. * @period: Period for recuring alarms
  23. * @function: Function pointer to be executed when the timer fires.
  24. * @type: Alarm type (BOOTTIME/REALTIME)
  25. * @enabled: Flag that represents if the alarm is set to fire or not
  26. * @data: Internal data value.
  27. */
  28. struct alarm {
  29. struct timerqueue_node node;
  30. struct hrtimer timer;
  31. enum alarmtimer_restart (*function)(struct alarm *, ktime_t now);
  32. enum alarmtimer_type type;
  33. int state;
  34. void *data;
  35. };
  36. void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
  37. enum alarmtimer_restart (*function)(struct alarm *, ktime_t));
  38. void alarm_start(struct alarm *alarm, ktime_t start);
  39. void alarm_start_relative(struct alarm *alarm, ktime_t start);
  40. void alarm_restart(struct alarm *alarm);
  41. int alarm_try_to_cancel(struct alarm *alarm);
  42. int alarm_cancel(struct alarm *alarm);
  43. u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
  44. u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
  45. ktime_t alarm_expires_remaining(const struct alarm *alarm);
  46. /* Provide way to access the rtc device being used by alarmtimers */
  47. struct rtc_device *alarmtimer_get_rtcdev(void);
  48. #endif