Kernel/x86 - Cleaning up dead code
[tpg/acess2.git] / Kernel / arch / x86_64 / time.c
index ec1e19d..03c889f 100644 (file)
@@ -4,18 +4,13 @@
  * arch/x86_64/time.c
  */
 #include <acess.h>
+#include <arch_config.h>
 
 // === MACROS ===
 #define        TIMER_QUANTUM   100
-// 2^(15-rate), 15: 1HZ, 5: 1024Hz, 2: 8192Hz
-// (Max: 15, Min: 2) - 15 = 1Hz, 13 = 4Hz, 12 = 8Hz, 11 = 16Hz 10 = 32Hz, 2 = 8192Hz
-//#define TIMER_RATE   10      // 32 Hz
-//#define TIMER_RATE   12      // 8 Hz
-#define TIMER_RATE     14      // 2Hz
-//#define TIMER_RATE   15      // 1HZ
-#define TIMER_FREQ     (0x8000>>TIMER_RATE)    //Hz
-#define MS_PER_TICK_WHOLE      (1000/(TIMER_FREQ))
-#define MS_PER_TICK_FRACT      ((0x80000000*(1000%TIMER_FREQ))/TIMER_FREQ)
+#define TIMER_FREQ     PIT_TIMER_BASE_N/(PIT_TIMER_BASE_D*PIT_TIMER_DIVISOR)
+#define MS_PER_TICK_WHOLE      (1000*(PIT_TIMER_BASE_D*PIT_TIMER_DIVISOR)/PIT_TIMER_BASE_N)
+#define MS_PER_TICK_FRACT      ((0x80000000ULL*1000ULL*PIT_TIMER_BASE_D*PIT_TIMER_DIVISOR/PIT_TIMER_BASE_N)&0x7FFFFFFF)
 
 // === IMPORTS ===
 extern volatile Sint64 giTimestamp;
@@ -28,9 +23,9 @@ volatile Uint64       giTime_TSCAtLastTick = 0;
 volatile Uint64        giTime_TSCPerTick = 0;
 
 // === PROTOTYPES ===
-Sint64 now(void);
+//Sint64       now(void);
  int   Time_Setup(void);
-void   Time_Interrupt(int);
+void   Time_UpdateTimestamp(void);
 Uint64 Time_ReadTSC(void);
 
 // === CODE ===
@@ -57,48 +52,19 @@ Sint64 now(void)
  */
 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
-       
-       // 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
-       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");   // 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.
+       Log_Log("Timer", "PIT Timer firing at %iHz, %i.0x%08x miliseconds per tick",
+               TIMER_FREQ, MS_PER_TICK_WHOLE, MS_PER_TICK_FRACT);
+
+       // TODO: Read time from RTC
        
        return 0;
 }
 
 /**
  * \brief Called on the timekeeping IRQ
- * \param irq  IRQ number (unused)
  */
-void Time_Interrupt(int irq)
+void Time_UpdateTimestamp(void)
 {
-       //Log("RTC Tick");
        Uint64  curTSC = Time_ReadTSC();
        
        if( giTime_TSCAtLastTick )
@@ -116,10 +82,6 @@ void Time_Interrupt(int irq)
        }
        
        Timer_CallTimers();
-
-       // Make sure the RTC Fires again
-       outb(0x70, 0x0C); // Select register C
-       inb(0x71);      // Just throw away contents.
 }
 
 #if 0

UCC git Repository :: git.ucc.asn.au