Commenting is nice (also disabled debug in FDD driver)
[tpg/acess2.git] / Kernel / arch / x86 / time.c
index 79ea4d0..77683b5 100644 (file)
@@ -3,39 +3,31 @@
  * Timekeeping
  * arch/x86/time.c
  */
-#include <common.h>
+#include <acess.h>
 
 // === MACROS ===
-#define        NUM_TIMERS      8
 #define        TIMER_QUANTUM   100
-#define TIMER_RATE     13      // (Max: 15, Min: 2) - 15 = 1Hz, 13 = 4Hz, 10 = 1024Hz
-#define TIMER_FREQ     (32768>>TIMER_RATE)     //Hz
+// 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))
 
-// === TYPEDEFS ===
-typedef struct sTimer {
-        int    FiresAfter;
-       void    (*Callback)(void*);
-       void    *Argument;
-} tTimer;
+// === IMPORTS ===
+extern Sint64  giTimestamp;
+extern Uint64  giTicks;
+extern Uint64  giPartMiliseconds;
+extern void    Timer_CallTimers(void);
 
 // === PROTOTYPES ===
-void   Time_Interrupt();
-void   Timer_CallTimers();
-
-// === GLOBALS ===
-Uint64 giTicks = 0;
-Sint64 giTimestamp = 0;
-Uint64 giPartMiliseconds = 0;
-tTimer gTimers[NUM_TIMERS];
+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;
        
@@ -65,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;
@@ -78,8 +70,6 @@ void Time_Interrupt()
                giPartMiliseconds -= 0x80000000;
        }
        
-       //Log("giTimestamp = %lli", giTimestamp);
-       
        Timer_CallTimers();
 
        // Make sure the RTC Fires again
@@ -87,11 +77,11 @@ void Time_Interrupt()
        inb(0x71);      // Just throw away contents.
 }
 
+#if 0
 /**
- * \fn void Time_TimerThread()
+ * \fn void Time_TimerThread(void)
  */
-#if 0
-void Time_TimerThread()
+void Time_TimerThread(void)
 {
        Sint64  next;
        Threads_SetName("TIMER");
@@ -105,75 +95,3 @@ void Time_TimerThread()
        }
 }
 #endif
-
-/**
- * \fn Sint64 now()
- * \brief Return the current timestamp
- */
-Sint64 now()
-{
-       return giTimestamp;
-}
-
-/**
- * \fn void Timer_CallTimers()
- */
-void Timer_CallTimers()
-{
-        int    i;
-       void    (*callback)(void *);
-       
-       for(i = 0;
-               i < NUM_TIMERS;
-               i ++)
-       {
-               if(gTimers[i].Callback == NULL) continue;
-               if(giTimestamp < gTimers[i].FiresAfter) continue;
-               callback = gTimers[i].Callback;
-               gTimers[i].Callback = NULL;
-               callback(gTimers[i].Argument);
-       }
-}
-
-/**
- * \fn int Time_CreateTimer(int Delta, void *Callback, void *Argument)
- */
-int Time_CreateTimer(int Delta, void *Callback, void *Argument)
-{
-        int    ret;
-       
-       if(Callback == NULL)    return -1;
-       
-       for(ret = 0;
-               ret < NUM_TIMERS;
-               ret++)
-       {
-               if(gTimers[ret].Callback != NULL)       continue;
-               gTimers[ret].Callback = Callback;
-               gTimers[ret].FiresAfter = giTimestamp + Delta;
-               gTimers[ret].Argument = Argument;
-               //Log("Callback = %p", Callback);
-               //Log("Timer %i fires at %lli", ret, gTimers[ret].FiresAfter);
-               return ret;
-       }
-       return -1;
-}
-
-/**
- * \fn void Time_RemoveTimer(int ID)
- */
-void Time_RemoveTimer(int ID)
-{
-       if(ID < 0 || ID >= NUM_TIMERS)  return;
-       gTimers[ID].Callback = NULL;
-}
-
-/**
- * \fn void Time_Delay(int Delay)
- * \brief Delay for a small ammount of time
- */
-void Time_Delay(int Delay)
-{
-       Sint64  dest = giTimestamp + Delay;
-       while(dest < giTimestamp)       Threads_Yield();
-}

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