🆕 double buffer

This commit is contained in:
fslongjin
2022-05-20 19:37:26 +08:00
parent 59e847294a
commit 464837eb1a
11 changed files with 168 additions and 67 deletions

View File

@ -146,11 +146,21 @@ int HPET_init()
// 使用I/O APIC 的IRQ2接收hpet定时器0的中断
apic_make_rte_entry(&entry, 34, IO_APIC_FIXED, DEST_PHYSICAL, IDLE, POLARITY_HIGH, IRR_RESET, EDGE_TRIGGER, MASKED, 0);
// 计算HPET0间隔多少个时钟周期触发一次中断
uint64_t clks_to_intr = 0.001 * HPET0_INTERVAL * HPET_freq;
if (clks_to_intr <= 0 || clks_to_intr > (HPET_freq * 8))
{
kBUG("HPET0: Numof clocks to generate interrupt is INVALID! value=%lld", clks_to_intr);
while (1)
hlt();
}
*(uint64_t *)(HPET_REG_BASE + MAIN_CNT) = 0;
io_mfence();
*(uint64_t *)(HPET_REG_BASE + TIM0_CONF) = 0x004c; // 设置定时器0为周期定时边沿触发投递到IO APIC的2号引脚这里有点绕写的是8259的引脚号但是因为禁用了8259因此会被路由到IO APIC的2号引脚
io_mfence();
*(uint64_t *)(HPET_REG_BASE + TIM0_COMP) = HPET_freq; // 1s触发一次中断
*(uint64_t *)(HPET_REG_BASE + TIM0_COMP) = clks_to_intr; // 5ms触发一次中断
//*(uint64_t *)(HPET_REG_BASE + TIM0_COMP) = HPET_freq; // 1s触发一次中断
io_mfence();
rtc_get_cmos_time(&rtc_now);

View File

@ -5,4 +5,6 @@
#include<driver/timers/rtc/rtc.h>
#define E_HPET_INIT_FAILED 1
#define HPET0_INTERVAL 5 // HPET0定时器的中断间隔为5ms
int HPET_init();

View File

@ -2,6 +2,7 @@
#include <common/kprint.h>
#include <exception/softirq.h>
#include <mm/slab.h>
#include <driver/timers/HPET/HPET.h>
void test_timer()
{
@ -25,7 +26,7 @@ void do_timer_softirq(void *data)
{
struct timer_func_list_t *tmp = container_of(list_next(&timer_func_head.list), struct timer_func_list_t, list);
while ((!list_empty(&timer_func_head.list)) && (tmp->expire_jiffies <= timer_jiffies))
{
timer_func_del(tmp);
@ -34,7 +35,7 @@ void do_timer_softirq(void *data)
tmp = container_of(list_next(&timer_func_head.list), struct timer_func_list_t, list);
}
printk_color(ORANGE, BLACK, "(HPET%ld)", timer_jiffies);
// printk_color(ORANGE, BLACK, "(HPET%ld)", timer_jiffies);
}
/**
@ -42,14 +43,15 @@ void do_timer_softirq(void *data)
*
* @param timer_func 队列结构体
* @param func 定时功能处理函数
* @param expire_jiffies 定时时长
* @param data 传输的数据
* @param expire_ms 定时时长(单位ms)
*/
void timer_func_init(struct timer_func_list_t *timer_func, void (*func)(void *data), void *data, uint64_t expire_jiffies)
void timer_func_init(struct timer_func_list_t *timer_func, void (*func)(void *data), void *data, uint64_t expire_ms)
{
list_init(&timer_func->list);
timer_func->func = func;
timer_func->data = data,
timer_func->expire_jiffies = timer_jiffies + expire_jiffies;
timer_func->expire_jiffies = timer_jiffies + expire_ms / 5 + expire_ms % HPET0_INTERVAL ? 1 : 0; // 设置过期的时间片
}
/**
@ -66,8 +68,6 @@ void timer_func_add(struct timer_func_list_t *timer_func)
tmp = container_of(list_next(&tmp->list), struct timer_func_list_t, list);
list_add(&tmp->list, &(timer_func->list));
}
/**

View File

@ -28,9 +28,9 @@ struct timer_func_list_t
* @param timer_func 队列结构体
* @param func 定时功能处理函数
* @param data 传输的数据
* @param expire_jiffies 定时时长
* @param expire_ms 定时时长(单位ms)
*/
void timer_func_init(struct timer_func_list_t * timer_func, void (*func)(void*data), void*data,uint64_t expire_jiffies);
void timer_func_init(struct timer_func_list_t * timer_func, void (*func)(void*data), void*data,uint64_t expire_ms);
/**
* @brief 将定时功能添加到列表中