/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- timerinit
1 // Intel 8253/8254/82C54 Programmable Interval Timer (PIT).
2 // Only used on uniprocessors;
3 // SMP machines use the local APIC timer.
4
5 #include "types.h"
6 #include "defs.h"
7 #include "traps.h"
8 #include "x86.h"
9
10 #define IO_TIMER1 0x040 // 8253 Timer #1
11
12 // Frequency of all three count-down timers;
13 // (TIMER_FREQ/freq) is the appropriate count
14 // to generate a frequency of freq Hz.
15
16 #define TIMER_FREQ 1193182
17 #define TIMER_DIV(x) ((TIMER_FREQ+(x)/2)/(x))
18
19 #define TIMER_MODE (IO_TIMER1 + 3) // timer mode port
20 #define TIMER_SEL0 0x00 // select counter 0
21 #define TIMER_RATEGEN 0x04 // mode 2, rate generator
22 #define TIMER_16BIT 0x30 // r/w counter 16 bits, LSB first
23
24 void
25 timerinit(void)
26 {
27 // Interrupt 100 times/sec.
28 outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
29 outb(IO_TIMER1, TIMER_DIV(100) % 256);
30 outb(IO_TIMER1, TIMER_DIV(100) / 256);
31 picenable(IRQ_TIMER);
32 }