7 #error 8254 timer requires TIMER_FREQ >= 19
10 static volatile uint64_t ticks;
13 irq20_timer (struct intr_frame *args UNUSED)
16 intr_yield_on_return ();
19 /* Sets up the 8254 Programmable Interrupt Timer (PIT) to
20 interrupt PIT_FREQ times per second, and registers the
21 corresponding interrupt. */
25 /* 8254 input frequency divided by TIMER_FREQ, rounded to
27 uint16_t count = (1193180 + TIMER_FREQ / 2) / TIMER_FREQ;
29 outb (0x43, 0x34); /* CW: counter 0, LSB then MSB, mode 2, binary. */
30 outb (0x40, count & 0xff);
31 outb (0x40, count >> 8);
33 intr_register (0x20, 0, IF_OFF, irq20_timer, "8254 Timer");
39 enum if_level old_level = intr_disable ();
41 intr_set_level (old_level);
46 timer_elapsed (uint64_t then)
48 uint64_t now = timer_ticks ();
49 return now > then ? now - then : ((uint64_t) -1 - then) + now + 1;
52 /* Suspends execution for at least DURATION ticks. */
54 timer_wait_until (uint64_t duration)