zf_timer.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. *****************************************************************************
  3. * @file zf_timer.h
  4. * @author Zorb
  5. * @version V1.0.0
  6. * @date 2018-06-28
  7. * @brief 软件定时器(精度1ms)的头文件
  8. *****************************************************************************
  9. * @history
  10. *
  11. * 1. Date:2018-06-28
  12. * Author:Zorb
  13. * Modification:建立文件
  14. *
  15. *****************************************************************************
  16. */
  17. #ifndef __ZF_TIMER_H__
  18. #define __ZF_TIMER_H__
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #include "stdint.h"
  23. #include "stdbool.h"
  24. #include "zf_event.h"
  25. /* 定时器处理程序 */
  26. typedef void (*ITimerProcess)(void);
  27. /* 定时器结构 */
  28. typedef struct _Timer
  29. {
  30. uint8_t Priority; /* 事件优先级 */
  31. uint32_t Interval; /* 时间间隔(ms) */
  32. uint32_t AlarmTime; /* 定时到达时间 */
  33. bool IsAutoReset; /* 重复运行(默认开) */
  34. bool IsRunning; /* 是否正在运行(默认关) */
  35. /* 事件的处理者,事件将推送到处理者的队列 */
  36. /* 不设置处理者则本地执行(挂载Timer_process的地方) */
  37. EventHandler *pEventHandler;
  38. /* 处理事件 */
  39. ITimerProcess TimerProcess;
  40. /* 开始定时器 */
  41. void (*Start)(struct _Timer * const pTimer);
  42. /* 关闭定时器 */
  43. void (*Stop)(struct _Timer * const pTimer);
  44. /* 重新运行定时器 */
  45. void (*Restart)(struct _Timer * const pTimer);
  46. /* 销毁定时器(释放空间) */
  47. bool (*Dispose)(struct _Timer * const pTimer);
  48. } Timer;
  49. /* 创建定时器(内部分配空间) */
  50. bool Timer_create(Timer ** ppTimer);
  51. /* 开始定时器 */
  52. void Timer_start(Timer * const pTimer);
  53. /* 关闭定时器 */
  54. void Timer_stop(Timer * const pTimer);
  55. /* 重新运行定时器 */
  56. void Timer_restart(Timer * const pTimer);
  57. /* 销毁定时器(释放空间) */
  58. bool Timer_dispose(Timer * const pTimer);
  59. /* 后台运行程序(放在1ms内的循环里边) */
  60. void Timer_process(void);
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif /* __ZF_TIMER_H__ */
  65. /******************************** END OF FILE ********************************/