timer.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include <common/glib.h>
  3. #include "HPET/HPET.h"
  4. #include "rtc/rtc.h"
  5. uint64_t volatile timer_jiffies = 0; // 系统时钟计数
  6. // 计算接下来n毫秒对应的系统时间片
  7. #define cal_next_n_ms_jiffies(expire_ms) (timer_jiffies + expire_ms / 5 + expire_ms % HPET0_INTERVAL ? 1 : 0)
  8. void timer_init();
  9. void do_timer_softirq(void *data);
  10. /**
  11. * @brief 定时功能队列
  12. *
  13. */
  14. struct timer_func_list_t
  15. {
  16. struct List list;
  17. uint64_t expire_jiffies;
  18. void (*func)(void *data);
  19. void *data;
  20. };
  21. extern struct timer_func_list_t timer_func_head;
  22. /**
  23. * @brief 初始化定时功能
  24. *
  25. * @param timer_func 队列结构体
  26. * @param func 定时功能处理函数
  27. * @param data 传输的数据
  28. * @param expire_ms 定时时长(单位:ms)
  29. */
  30. void timer_func_init(struct timer_func_list_t *timer_func, void (*func)(void *data), void *data, uint64_t expire_ms);
  31. /**
  32. * @brief 将定时功能添加到列表中
  33. *
  34. * @param timer_func 待添加的定时功能
  35. */
  36. void timer_func_add(struct timer_func_list_t *timer_func);
  37. /**
  38. * @brief 将定时功能从列表中删除
  39. *
  40. * @param timer_func
  41. */
  42. void timer_func_del(struct timer_func_list_t *timer_func);