alarmtimer.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #define ALARMTIMER_STATE_CALLBACK 0x02
  19. /**
  20. * struct alarm - Alarm timer structure
  21. * @node: timerqueue node for adding to the event list this value
  22. * also includes the expiration time.
  23. * @period: Period for recuring alarms
  24. * @function: Function pointer to be executed when the timer fires.
  25. * @type: Alarm type (BOOTTIME/REALTIME)
  26. * @enabled: Flag that represents if the alarm is set to fire or not
  27. * @data: Internal data value.
  28. */
  29. struct alarm {
  30. struct timerqueue_node node;
  31. struct hrtimer timer;
  32. enum alarmtimer_restart (*function)(struct alarm *, ktime_t now);
  33. enum alarmtimer_type type;
  34. int state;
  35. void *data;
  36. };
  37. void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
  38. enum alarmtimer_restart (*function)(struct alarm *, ktime_t));
  39. int alarm_start(struct alarm *alarm, ktime_t start);
  40. int alarm_try_to_cancel(struct alarm *alarm);
  41. int alarm_cancel(struct alarm *alarm);
  42. u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
  43. /*
  44. * A alarmtimer is active, when it is enqueued into timerqueue or the
  45. * callback function is running.
  46. */
  47. static inline int alarmtimer_active(const struct alarm *timer)
  48. {
  49. return timer->state != ALARMTIMER_STATE_INACTIVE;
  50. }
  51. /*
  52. * Helper function to check, whether the timer is on one of the queues
  53. */
  54. static inline int alarmtimer_is_queued(struct alarm *timer)
  55. {
  56. return timer->state & ALARMTIMER_STATE_ENQUEUED;
  57. }
  58. /*
  59. * Helper function to check, whether the timer is running the callback
  60. * function
  61. */
  62. static inline int alarmtimer_callback_running(struct alarm *timer)
  63. {
  64. return timer->state & ALARMTIMER_STATE_CALLBACK;
  65. }
  66. /* Provide way to access the rtc device being used by alarmtimers */
  67. struct rtc_device *alarmtimer_get_rtcdev(void);
  68. #endif