diff --git a/kernel/clock.c b/kernel/clock.c index 8d7c504..f828217 100644 --- a/kernel/clock.c +++ b/kernel/clock.c @@ -11,18 +11,32 @@ See the file LICENSE for details. // Minimum PIT frequency is 18.2Hz. #define CLICKS_PER_SECOND 20 +#define CLICKS_MILLITIME 1/CLICKS_PER_SECOND -#define TIMER0 0x40 -#define TIMER_MODE 0x43 -#define SQUARE_WAVE 0x36 -#define TIMER_FREQ 1193182 -#define TIMER_COUNT (((unsigned)TIMER_FREQ)/CLICKS_PER_SECOND) +#define TIMER0 0x40 +#define TIMER_MODE 0x43 +#define SQUARE_WAVE 0x36 +#define TIMER_FREQ 1193182 +#define TIMER_COUNT (((unsigned)TIMER_FREQ)/CLICKS_PER_SECOND) static uint32_t clicks = 0; static uint32_t seconds = 0; static struct list queue = { 0, 0 }; +static unsigned long read_pit_counter(void) { + unsigned long count = 0; + // Disable interrupts + // cli(); + // al = channel in bits 6 and 7, remaining bits clear + outb(0b0000000,TIMER_MODE); + + count = inb(TIMER0); // Low byte + count |= inb(TIMER0)<<8; // High byte + + return count; +} + static void clock_interrupt(int i, int code) { clicks++; @@ -67,6 +81,10 @@ void clock_wait(uint32_t millis) } while(total < millis); } +#ifdef KERNEL_CLOCK_EXT + #include "kernel_clock_ext.c" +#endif + void clock_init() { outb(SQUARE_WAVE, TIMER_MODE); @@ -76,5 +94,10 @@ void clock_init() interrupt_register(32, clock_interrupt); interrupt_enable(32); - printf("clock: ticking\n"); + +#ifdef KERNEL_CLOCK_EXT + CLOCKINITMESSAGE +#else + printf("clock: ticking %d %% %d\n",read_pit_counter(),TIMER_COUNT); +#endif }