2022-04-08 12:04:12 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
#include <common/glib.h>
|
2022-07-11 02:56:24 +00:00
|
|
|
|
#include <driver/timers/HPET/HPET.h>
|
|
|
|
|
|
#include <driver/timers/rtc/rtc.h>
|
2022-04-08 12:04:12 +00:00
|
|
|
|
|
2022-06-09 13:56:32 +00:00
|
|
|
|
uint64_t volatile timer_jiffies = 0; // 系统时钟计数
|
|
|
|
|
|
|
|
|
|
|
|
// 计算接下来n毫秒对应的系统时间片
|
2022-07-12 04:01:51 +00:00
|
|
|
|
#define cal_next_n_ms_jiffies(expire_ms) (timer_jiffies + 1000*expire_ms)
|
2022-07-12 01:39:35 +00:00
|
|
|
|
// 计算接下来n微秒对应的系统时间片
|
2022-07-12 04:01:51 +00:00
|
|
|
|
#define cal_next_n_us_jiffies(expire_us) (timer_jiffies + expire_us)
|
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
|
|
|
|
|
2022-07-12 04:01:51 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief 初始化定时功能
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param timer_func 队列结构体
|
|
|
|
|
|
* @param func 定时功能处理函数
|
|
|
|
|
|
* @param data 传输的数据
|
|
|
|
|
|
* @param expire_us 定时时长(单位:us)
|
|
|
|
|
|
*/
|
|
|
|
|
|
void timer_func_init_us(struct timer_func_list_t *timer_func, void (*func)(void *data), void *data, uint64_t expire_us);
|
|
|
|
|
|
|
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);
|
2022-07-12 05:20:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t clock();
|