Added Timer functions, DMA Driver and FDD driver
authorJohn Hodge <[email protected]>
Thu, 1 Oct 2009 07:55:50 +0000 (15:55 +0800)
committerJohn Hodge <[email protected]>
Thu, 1 Oct 2009 07:55:50 +0000 (15:55 +0800)
Kernel/Makefile
Kernel/arch/x86/time.c
Kernel/include/common.h

index bbafbba..e153483 100644 (file)
@@ -22,7 +22,7 @@ OBJ += heap.o messages.o debug.o modules.o lib.o syscalls.o system.o threads.o
 OBJ += binary.o bin/elf.o
 OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o vfs/memfile.o vfs/nodecache.o
 OBJ += vfs/fs/root.o vfs/fs/devfs.o vfs/fs/fat.o
-OBJ += drv/fifo.o drv/pci.o drv/ata_x86.o drv/vterm.o drv/vga.o drv/kb.o
+OBJ += drv/dma.o drv/fifo.o drv/pci.o drv/ata_x86.o drv/vterm.o drv/vga.o drv/kb.o drv/fdd.o
 OBJ := $(addsuffix .$(ARCH), $(OBJ))
 BIN = ../Acess2.$(ARCH).bin
 
index 3a13904..f7d02cc 100644 (file)
@@ -6,17 +6,28 @@
 #include <common.h>
 
 // === MACROS ===
+#define        NUM_TIMERS      8
+#define        TIMER_QUANTUM   100
 #define TIMER_FREQ     1024    //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;
+
 // === PROTOTYPES ===
 void   Time_Interrupt();
+void   Timer_CallTimers();
 
 // === GLOBALS ===
 Uint64 giTicks = 0;
 Sint64 giTimestamp = 0;
 Uint64 giPartMiliseconds = 0;
+tTimer gTimers[NUM_TIMERS];
 
 // === CODE ===
 /**
@@ -57,7 +68,28 @@ void Time_Interrupt()
                giTimestamp ++;
                giPartMiliseconds -= 0x80000000;
        }
+       
+       Timer_CallTimers();
+}
+
+/**
+ * \fn void Time_TimerThread()
+ */
+#if 0
+void Time_TimerThread()
+{
+       Sint64  next;
+       Threads_SetName("TIMER");
+       
+       next = giTimestamp + TIMER_QUANTUM;
+       for(;;)
+       {
+               while(giTimestamp < next)       Threads_Yield();
+               next = giTimestamp + TIMER_QUANTUM;     
+               Timer_CallTimers();
+       }
 }
+#endif
 
 /**
  * \fn Sint64 now()
@@ -67,3 +99,61 @@ 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;
+       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;
+               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();
+}
index 3dcab28..7bf5938 100644 (file)
@@ -106,6 +106,9 @@ extern int  Module_LoadFile(char *Path, char *ArgStr);
 // --- Timing ---
 extern Sint64  timestamp(int sec, int mins, int hrs, int day, int month, int year);
 extern Sint64  now();
+extern int     Time_CreateTimer(int Delta, void *Callback, void *Argument);
+extern void    Time_RemoveTimer(int ID);
+extern void    Time_Delay(int Delay);
 // --- Threads ---
 extern  int    Proc_Spawn(char *Path);
 extern void    Threads_Exit();

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