更改HPET的定时间隔为500us

This commit is contained in:
fslongjin 2022-07-12 09:39:35 +08:00
parent defb9e769c
commit 4208c56074
3 changed files with 6 additions and 4 deletions

View File

@ -164,7 +164,7 @@ void HPET_enable()
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;
uint64_t clks_to_intr = 0.000001 * HPET0_INTERVAL * HPET_freq;
// kdebug("clks_to_intr=%#ld", clks_to_intr);
if (clks_to_intr <= 0 || clks_to_intr > (HPET_freq * 8))
{
@ -177,7 +177,7 @@ void HPET_enable()
io_mfence();
*(uint64_t *)(HPET_REG_BASE + TIM0_CONF) = 0x004c; // 设置定时器0为周期定时边沿触发默认投递到IO APIC的2号引脚(看conf寄存器的高32bit哪一位被置1则可以投递到哪一个I/O apic引脚)
io_mfence();
*(uint64_t *)(HPET_REG_BASE + TIM0_COMP) = clks_to_intr; // 5ms触发一次中断
*(uint64_t *)(HPET_REG_BASE + TIM0_COMP) = clks_to_intr;
io_mfence();

View File

@ -6,7 +6,7 @@
#define E_HPET_INIT_FAILED 1
#define HPET0_INTERVAL 5 // HPET0定时器的中断间隔为5ms
#define HPET0_INTERVAL 500 // HPET0定时器的中断间隔为500us
int HPET_init();
/**

View File

@ -7,7 +7,9 @@
uint64_t volatile timer_jiffies = 0; // 系统时钟计数
// 计算接下来n毫秒对应的系统时间片
#define cal_next_n_ms_jiffies(expire_ms) (timer_jiffies + expire_ms / 5 + ((expire_ms % HPET0_INTERVAL) ? 1 : 0))
#define cal_next_n_ms_jiffies(expire_ms) (timer_jiffies + 1000*expire_ms / HPET0_INTERVAL + ((1000*expire_ms % HPET0_INTERVAL) ? 1 : 0))
// 计算接下来n微秒对应的系统时间片
#define cal_next_n_us_jiffies(expire_us) (timer_jiffies + expire_us / HPET0_INTERVAL + ((expire_us % HPET0_INTERVAL) ? 1 : 0))
void timer_init();