timer.h 1.4 KB

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