X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86%2Ftime.c;h=77683b558ef3d409a2a5d91bf3cbaca21b8fabe7;hb=4b80e9762374558077e28e321d75029645529a45;hp=3a13904f819d0776793194cee9f37f7c474166de;hpb=8bc40333b1401d7616b225945fee53d972c2f418;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86/time.c b/Kernel/arch/x86/time.c index 3a13904f..77683b55 100644 --- a/Kernel/arch/x86/time.c +++ b/Kernel/arch/x86/time.c @@ -3,33 +3,45 @@ * Timekeeping * arch/x86/time.c */ -#include +#include // === MACROS === -#define TIMER_FREQ 1024 //Hz +#define TIMER_QUANTUM 100 +// 2^(15-rate), 15: 1HZ, 5: 1024Hz, 2: 8192Hz +#define TIMER_RATE 12 // (Max: 15, Min: 2) - 15 = 1Hz, 13 = 4Hz, 12 = 8Hz, 11 = 16Hz 10 = 32Hz, 2 +#define TIMER_FREQ (0x8000>>TIMER_RATE) //Hz #define MS_PER_TICK_WHOLE (1000/(TIMER_FREQ)) #define MS_PER_TICK_FRACT ((Uint64)(1000*TIMER_FREQ-((Uint64)MS_PER_TICK_WHOLE)*0x80000000/TIMER_FREQ)) -// === PROTOTYPES === -void Time_Interrupt(); +// === IMPORTS === +extern Sint64 giTimestamp; +extern Uint64 giTicks; +extern Uint64 giPartMiliseconds; +extern void Timer_CallTimers(void); -// === GLOBALS === -Uint64 giTicks = 0; -Sint64 giTimestamp = 0; -Uint64 giPartMiliseconds = 0; +// === PROTOTYPES === +void Time_Interrupt(int); // === CODE === /** - * \fn int Time_Setup() + * \fn int Time_Setup(void) * \brief Sets the system time from the Realtime-Clock */ -int Time_Setup() +int Time_Setup(void) { Uint8 val; outb(0x70, inb(0x70)&0x7F); // Disable NMIs __asm__ __volatile__ ("cli"); // Disable normal interrupts + // Set IRQ8 firing rate + outb(0x70, 0x0A); // Set the index to register A + val = inb(0x71); // Get the current value of register A + outb(0x70, 0x0A); // Reset index to A + val &= 0xF0; + val |= TIMER_RATE; + outb(0x71, val); // Update the timer rate + // Enable IRQ8 outb(0x70, 0x0B); // Set the index to register B val = inb(0x71); // Read the current value of register B @@ -45,10 +57,10 @@ int Time_Setup() } /** - * \fn void Time_Interrupt() + * \fn void Time_Interrupt(void) * \brief Called on the timekeeping IRQ */ -void Time_Interrupt() +void Time_Interrupt(int irq) { giTicks ++; giTimestamp += MS_PER_TICK_WHOLE; @@ -57,13 +69,29 @@ void Time_Interrupt() giTimestamp ++; giPartMiliseconds -= 0x80000000; } + + Timer_CallTimers(); + + // Make sure the RTC Fires again + outb(0x70, 0x0C); // Select register C + inb(0x71); // Just throw away contents. } +#if 0 /** - * \fn Sint64 now() - * \brief Return the current timestamp + * \fn void Time_TimerThread(void) */ -Sint64 now() +void Time_TimerThread(void) { - return giTimestamp; + Sint64 next; + Threads_SetName("TIMER"); + + next = giTimestamp + TIMER_QUANTUM; + for(;;) + { + while(giTimestamp < next) Threads_Yield(); + next = giTimestamp + TIMER_QUANTUM; + Timer_CallTimers(); + } } +#endif