📄 timer.c
字号:
// Intel 8253/8254/82C54 Programmable Interval Timer (PIT).// Only used on uniprocessors;// SMP machines use the local APIC timer.#include "types.h"#include "defs.h"#include "traps.h"#include "x86.h"#define IO_TIMER1 0x040 // 8253 Timer #1// Frequency of all three count-down timers;// (TIMER_FREQ/freq) is the appropriate count// to generate a frequency of freq Hz.#define TIMER_FREQ 1193182#define TIMER_DIV(x) ((TIMER_FREQ+(x)/2)/(x))#define TIMER_MODE (IO_TIMER1 + 3) // timer mode port#define TIMER_SEL0 0x00 // select counter 0#define TIMER_RATEGEN 0x04 // mode 2, rate generator#define TIMER_16BIT 0x30 // r/w counter 16 bits, LSB firstvoidtimer_init(void){ // Interrupt 100 times/sec. outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT); outb(IO_TIMER1, TIMER_DIV(100) % 256); outb(IO_TIMER1, TIMER_DIV(100) / 256); pic_enable(IRQ_TIMER);}// Blank page
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -