Files
ViperOS/VKernel/Kernel/platform/pch/pit.vp
T
TermiNexus dcb7c5c2c0 chore(ViperOS): 落库内核侧进行中的改动(26 文件,+1573/-1805)
内容由用户产出,本次仅代为提交、未做任何语义修改;含 static 修饰符前置迁移等(新增 static 前缀 16 行)。提交消息为中性描述——如需更精确的说明请 amend。
2026-09-28 15:24:52 +08:00

27 lines
655 B
Plaintext

import asm
define PIT_CHANNEL0 = 0x40
define PIT_CHANNEL1 = 0x41
define PIT_CHANNEL2 = 0x42
define PIT_COMMAND = 0x43
def pit_init(frequency: int):
# 参数验证:确保频率为正数
if frequency <= 0: return
# 计算除数,使用16位无符号整数
divisor: uint32 = 1193180 / frequency
# 发送命令字:通道0,先低后高,模式3(方波),二进制计数
asm.outb(PIT_COMMAND, 0x36)
asm.io_wait()
# 写入低字节
asm.outb(PIT_CHANNEL0, divisor & 0xFF)
asm.io_wait()
# 写入高字节
asm.outb(PIT_CHANNEL0, (divisor >> 8) & 0xFF)
asm.io_wait()