2022-04-08 12:04:12 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
#include <common/glib.h>
|
|
|
|
|
|
#include "HPET/HPET.h"
|
|
|
|
|
|
#include "rtc/rtc.h"
|
|
|
|
|
|
|
2022-06-09 13:56:32 +00:00
|
|
|
|
uint64_t volatile timer_jiffies = 0; // 系统时钟计数
|
|
|
|
|
|
|
|
|
|
|
|
// 计算接下来n毫秒对应的系统时间片
|
2022-06-09 15:54:42 +00:00
|
|
|
|
#define cal_next_n_ms_jiffies(expire_ms) (timer_jiffies + expire_ms / 5 + (expire_ms % HPET0_INTERVAL ? 1 : 0))
|
2022-04-08 12:04:12 +00:00
|
|
|
|
|
|
|
|
|
|
void timer_init();
|
|
|
|
|
|
|
2022-06-09 13:56:32 +00:00
|
|
|
|
void do_timer_softirq(void *data);
|
2022-04-08 13:26:42 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 定时功能队列
|
2022-06-09 13:56:32 +00:00
|
|
|
|
*
|
2022-04-08 13:26:42 +00:00
|
|
|
|
*/
|
|
|
|
|
|
struct timer_func_list_t
|
|
|
|
|
|
{
|
|
|
|
|
|
struct List list;
|
|
|
|
|
|
uint64_t expire_jiffies;
|
2022-06-09 13:56:32 +00:00
|
|
|
|
void (*func)(void *data);
|
|
|
|
|
|
void *data;
|
|
|
|
|
|
};
|
2022-04-08 13:26:42 +00:00
|
|
|
|
|
2022-06-09 13:56:32 +00:00
|
|
|
|
extern struct timer_func_list_t timer_func_head;
|
2022-04-08 13:26:42 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 初始化定时功能
|
2022-06-09 13:56:32 +00:00
|
|
|
|
*
|
2022-04-08 13:26:42 +00:00
|
|
|
|
* @param timer_func 队列结构体
|
|
|
|
|
|
* @param func 定时功能处理函数
|
|
|
|
|
|
* @param data 传输的数据
|
2022-05-20 11:37:26 +00:00
|
|
|
|
* @param expire_ms 定时时长(单位:ms)
|
2022-04-08 13:26:42 +00:00
|
|
|
|
*/
|
2022-06-09 13:56:32 +00:00
|
|
|
|
void timer_func_init(struct timer_func_list_t *timer_func, void (*func)(void *data), void *data, uint64_t expire_ms);
|
2022-04-08 13:26:42 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 将定时功能添加到列表中
|
2022-06-09 13:56:32 +00:00
|
|
|
|
*
|
2022-04-08 13:26:42 +00:00
|
|
|
|
* @param timer_func 待添加的定时功能
|
|
|
|
|
|
*/
|
2022-06-09 13:56:32 +00:00
|
|
|
|
void timer_func_add(struct timer_func_list_t *timer_func);
|
2022-04-08 13:26:42 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 将定时功能从列表中删除
|
2022-06-09 13:56:32 +00:00
|
|
|
|
*
|
|
|
|
|
|
* @param timer_func
|
2022-04-08 13:26:42 +00:00
|
|
|
|
*/
|
2022-06-09 13:56:32 +00:00
|
|
|
|
void timer_func_del(struct timer_func_list_t *timer_func);
|