Wed 22 Jan 12:17:36 CET 2025

This commit is contained in:
sbosse 2025-01-22 12:18:11 +01:00
parent d82f750d14
commit 5827e349b3

View File

@ -11,6 +11,7 @@ See the file LICENSE for details.
// Minimum PIT frequency is 18.2Hz. // Minimum PIT frequency is 18.2Hz.
#define CLICKS_PER_SECOND 20 #define CLICKS_PER_SECOND 20
#define CLICKS_MILLITIME 1/CLICKS_PER_SECOND
#define TIMER0 0x40 #define TIMER0 0x40
#define TIMER_MODE 0x43 #define TIMER_MODE 0x43
@ -23,6 +24,19 @@ static uint32_t seconds = 0;
static struct list queue = { 0, 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) static void clock_interrupt(int i, int code)
{ {
clicks++; clicks++;
@ -67,6 +81,10 @@ void clock_wait(uint32_t millis)
} while(total < millis); } while(total < millis);
} }
#ifdef KERNEL_CLOCK_EXT
#include "kernel_clock_ext.c"
#endif
void clock_init() void clock_init()
{ {
outb(SQUARE_WAVE, TIMER_MODE); outb(SQUARE_WAVE, TIMER_MODE);
@ -76,5 +94,10 @@ void clock_init()
interrupt_register(32, clock_interrupt); interrupt_register(32, clock_interrupt);
interrupt_enable(32); 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
} }