- Timestamp:
- Aug 6, 2017, 7:58:22 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/x86_64/core/hal_apic.c
r237 r327 48 48 * Disable the PIC (8259A). We are going to use IOAPIC instead. 49 49 */ 50 out8(PIC1_DATA, 0xff); 51 out8(PIC2_DATA, 0xff); 52 } 53 54 /* -------------------------------------------------------------------------- */ 55 56 uint64_t pit_ticks_base __in_kdata = 0; 50 out8(PIC1_DATA, 0xFF); 51 out8(PIC2_DATA, 0xFF); 52 } 53 54 /* -------------------------------------------------------------------------- */ 55 56 static uint64_t pit_ticks_base __in_kdata = 0; 57 static uint16_t pit_ticks_last __in_kdata = 0; 57 58 58 59 #define PIT_FREQUENCY 1193182 … … 69 70 # define CMD_MODE2 0x04 /* Rate Generator */ 70 71 # define CMD_MODE3 0x06 /* Square Wave */ 71 # define CMD_MODE4 0x08 /* Software Trig erred Strobe */72 # define CMD_MODE5 0x0a /* Hardware Trig erred Strobe */72 # define CMD_MODE4 0x08 /* Software Triggered Strobe */ 73 # define CMD_MODE5 0x0a /* Hardware Triggered Strobe */ 73 74 # define CMD_LATCH 0x00 /* latch counter for reading */ 74 75 # define CMD_LSB 0x10 /* LSB, 8 bits */ … … 82 83 void hal_pit_reset(uint16_t val) 83 84 { 85 uint8_t lo, hi; 86 84 87 pit_ticks_base = 0; 85 88 86 /* Initialize PIT clock 0 to value given. */89 /* Set the initial counter value for clock 0. */ 87 90 out8(PIT_CMD, CMD_COUNTER0|CMD_MODE2|CMD_16BIT); 88 91 out8(PIT_TIMER0, (val >> 0) & 0xFF); 89 92 out8(PIT_TIMER0, (val >> 8) & 0xFF); 93 94 /* 95 * Read the current value, to initialize pit_ticks_last. Not extremely 96 * accurate, but fine. 97 */ 98 out8(PIT_CMD, CMD_COUNTER0|CMD_LATCH); 99 lo = in8(PIT_TIMER0); 100 hi = in8(PIT_TIMER0); 101 102 pit_ticks_last = (hi << 8) | lo; 90 103 } 91 104 … … 93 106 hal_pit_timer_read() 94 107 { 95 static uint16_t last;96 97 108 uint8_t lo, hi; 98 109 uint16_t ctr; … … 105 116 ctr = (hi << 8) | lo; 106 117 107 /* If the counter has wrapped, assume we're into the next tick. */108 if (ctr > last)118 /* If the counter has overflown, assume we're into the next tick. */ 119 if (ctr > pit_ticks_last) 109 120 pit_ticks_base += 0xFFFF; 110 last = ctr;121 pit_ticks_last = ctr; 111 122 112 123 ticks = pit_ticks_base + (0xFFFF - ctr); … … 124 135 125 136 nticks = 0; 126 hal_pit_reset(0 );137 hal_pit_reset(0xFFFF); 127 138 128 139 while (n > 0) { … … 130 141 /* Wait 1/muHZ sec = 1 microsecond */ 131 142 } 132 nticks++; 143 nticks++; // ??? 133 144 n--; 134 145 } … … 388 399 389 400 /* Reset the PIT */ 390 hal_pit_reset( -1);401 hal_pit_reset(0xFFFF); 391 402 392 403 pittick = hal_pit_timer_read() + 1; … … 405 416 lapictick1 = hal_lapic_read(LAPIC_CCR_TIMER); 406 417 418 if (lapictick1 > lapictick0) 419 x86_panic("LAPIC tick overflow!"); 420 407 421 /* Total number of LAPIC ticks per 1/HZ tick */ 408 lapicticks = (lapictick1 - lapictick0); 409 410 /* Finally, calibrate the timer, an interrupt each 1s. */ 411 lapicstart = - (lapicticks * 100); 422 lapicticks = (lapictick0 - lapictick1); 423 424 /* 425 * Finally, calibrate the timer, with an interrupt each 1s (10ms * 100). 426 */ 427 lapicstart = (lapicticks * 100); 412 428 hal_lapic_write(LAPIC_ICR_TIMER, lapicstart); 429 x86_printf("-> lapicticks: %z\n", (uint64_t)lapicticks); 413 430 } 414 431
Note: See TracChangeset
for help on using the changeset viewer.