X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86%2Ftime.c;h=6a2d0399218713d28e7830a84230cb0e11b3586d;hb=41769c02317835472d7678d3531ecfc23df8e17a;hp=49d515e4e5cd76966e8a1ffdfb0795ffda820738;hpb=fed0a8f469f7b187d26c0c8cb109bfd6930efaee;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86/time.c b/Kernel/arch/x86/time.c index 49d515e4..6a2d0399 100644 --- a/Kernel/arch/x86/time.c +++ b/Kernel/arch/x86/time.c @@ -8,10 +8,12 @@ // === MACROS === #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 +// (Max: 15, Min: 2) - 15 = 1Hz, 13 = 4Hz, 12 = 8Hz, 11 = 16Hz 10 = 32Hz, 2 = 8192Hz +#define TIMER_RATE 12 +//#define TIMER_RATE 15 #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)) +#define MS_PER_TICK_FRACT ((0x80000000*(1000%TIMER_FREQ))/TIMER_FREQ) // === IMPORTS === extern Sint64 giTimestamp; @@ -20,17 +22,20 @@ extern Uint64 giPartMiliseconds; extern void Timer_CallTimers(void); // === PROTOTYPES === -void Time_Interrupt(); +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; + Log_Log("Timer", "RTC Timer firing at %iHz (%i divisor), %i.0x%08x", + TIMER_FREQ, TIMER_RATE, MS_PER_TICK_WHOLE, MS_PER_TICK_FRACT); + outb(0x70, inb(0x70)&0x7F); // Disable NMIs __asm__ __volatile__ ("cli"); // Disable normal interrupts @@ -48,20 +53,27 @@ int Time_Setup() outb(0x70, 0x0B); // Set the index again (a read will reset the index to register D) outb(0x71, val | 0x40); // Write the previous value or'd with 0x40. This turns on bit 6 of register D - __asm__ __volatile__ ("sti"); // Disable normal interrupts - outb(0x70, inb(0x70)|0x80); // Disable NMIs + __asm__ __volatile__ ("sti"); // Re-enable normal interrupts + outb(0x70, inb(0x70)|0x80); // Re-enable NMIs // Install IRQ Handler IRQ_AddHandler(8, Time_Interrupt); + + // Make sure the RTC actually fires + outb(0x70, 0x0C); // Select register C + inb(0x71); // Just throw away contents. + return 0; } /** - * \fn void Time_Interrupt() * \brief Called on the timekeeping IRQ + * \param irq IRQ number (unused) */ -void Time_Interrupt() +void Time_Interrupt(int irq) { + //Log("RTC Tick"); + giTicks ++; giTimestamp += MS_PER_TICK_WHOLE; giPartMiliseconds += MS_PER_TICK_FRACT; @@ -79,9 +91,9 @@ void Time_Interrupt() #if 0 /** - * \fn void Time_TimerThread() + * \fn void Time_TimerThread(void) */ -void Time_TimerThread() +void Time_TimerThread(void) { Sint64 next; Threads_SetName("TIMER");