-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.c
43 lines (38 loc) · 1.21 KB
/
timer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "timer.h"
#include "kernel.h"
#include "irq.h"
#include "isrs.h"
#include "console.h"
void timer_phase(int hz)
{
int divisor = 1193180 / hz; /* Calculate our divisor */
outb(0x43, 0x36); /* Set our command byte 0x36 */
outb(0x40, divisor & 0xFF); /* Set low byte of divisor */
outb(0x40, divisor >> 8); /* Set high byte of divisor */
}
/* This will keep track of how many ticks that the system
* has been running for */
unsigned int timer_ticks = 0;
/* Handles the timer. In this case, it's very simple: We
* increment the 'timer_ticks' variable every time the
* timer fires. By default, the timer fires 18.222 times
* per second. Why 18.222Hz? Some engineer at IBM must've
* been smoking something funky */
void timer_handler(struct regs *r)
{
/* Increment our 'tick count' */
timer_ticks++;
/* Every 18 clocks (approximately 1 second), we will
* display a message on the screen */
if (timer_ticks % 18 == 0)
{
//kputs("One second has passed\n");
}
}
/* Sets up the system clock by installing the timer handler
* into IRQ0 */
void timer_install()
{
/* Installs 'timer_handler' to IRQ0 */
irq_install_handler(0, timer_handler);
}