alarm.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * File : alarm.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2012-10-27 heyuanjie87 first version.
  23. */
  24. #ifndef __ALARM_H__
  25. #define __ALARM_H__
  26. #include <time.h>
  27. #define RT_ALARM_TM_NOW -1 /* set the alarm tm_day,tm_mon,tm_sec,etc.
  28. to now.we also call it "don't care" value */
  29. /* alarm flags */
  30. #define RT_ALARM_ONESHOT 0x000 /* only alarm onece */
  31. #define RT_ALARM_DAILY 0x100 /* alarm everyday */
  32. #define RT_ALARM_WEEKLY 0x200 /* alarm weekly at Monday or Friday etc. */
  33. #define RT_ALARM_MONTHLY 0x400 /* alarm monthly at someday */
  34. #define RT_ALARM_YAERLY 0x800 /* alarm yearly at a certain date */
  35. /* alarm control cmd */
  36. #define RT_ALARM_CTRL_MODIFY 1 /* modify alarm time or alarm flag */
  37. typedef struct rt_alarm *rt_alarm_t;
  38. typedef void (*rt_alarm_callback_t)(rt_alarm_t alarm, time_t timestamp);
  39. /* used for low level RTC driver */
  40. struct rt_rtc_wkalarm
  41. {
  42. rt_bool_t enable; /* 0 = alarm disabled, 1 = alarm enabled */
  43. rt_int32_t tm_sec; /* alarm at tm_sec */
  44. rt_int32_t tm_min; /* alarm at tm_min */
  45. rt_int32_t tm_hour; /* alarm at tm_hour */
  46. };
  47. struct rt_alarm
  48. {
  49. rt_list_t list;
  50. rt_uint32_t flag;
  51. rt_alarm_callback_t callback;
  52. struct tm wktime;
  53. };
  54. struct rt_alarm_setup
  55. {
  56. rt_uint32_t flag; /* alarm flag */
  57. struct tm wktime; /* when will the alarm wake up user */
  58. };
  59. struct rt_alarm_container
  60. {
  61. rt_list_t head;
  62. struct rt_mutex mutex;
  63. struct rt_event event;
  64. struct rt_alarm *current;
  65. };
  66. rt_alarm_t rt_alarm_create(rt_alarm_callback_t callback,
  67. struct rt_alarm_setup *setup);
  68. rt_err_t rt_alarm_control(rt_alarm_t alarm, int cmd, void *arg);
  69. void rt_alarm_update(rt_device_t dev, rt_uint32_t event);
  70. rt_err_t rt_alarm_delete(rt_alarm_t alarm);
  71. rt_err_t rt_alarm_start(rt_alarm_t alarm);
  72. rt_err_t rt_alarm_stop(rt_alarm_t alarm);
  73. void rt_alarm_system_init(void);
  74. #endif /* __ALARM_H__ */