9 #define TIMER_FREQ 1024 //Hz
10 #define MS_PER_TICK_WHOLE (1000/(TIMER_FREQ))
11 #define MS_PER_TICK_FRACT ((Uint64)(1000*TIMER_FREQ-((Uint64)MS_PER_TICK_WHOLE)*0x80000000/TIMER_FREQ))
14 void Time_Interrupt();
18 Sint64 giTimestamp = 0;
19 Uint64 giPartMiliseconds = 0;
23 * \fn int Time_Setup()
24 * \brief Sets the system time from the Realtime-Clock
30 outb(0x70, inb(0x70)&0x7F); // Disable NMIs
31 __asm__ __volatile__ ("cli"); // Disable normal interrupts
34 outb(0x70, 0x0B); // Set the index to register B
35 val = inb(0x71); // Read the current value of register B
36 outb(0x70, 0x0B); // Set the index again (a read will reset the index to register D)
37 outb(0x71, val | 0x40); // Write the previous value or'd with 0x40. This turns on bit 6 of register D
39 __asm__ __volatile__ ("sti"); // Disable normal interrupts
40 outb(0x70, inb(0x70)|0x80); // Disable NMIs
42 // Install IRQ Handler
43 IRQ_AddHandler(8, Time_Interrupt);
48 * \fn void Time_Interrupt()
49 * \brief Called on the timekeeping IRQ
54 giTimestamp += MS_PER_TICK_WHOLE;
55 giPartMiliseconds += MS_PER_TICK_FRACT;
56 if(giPartMiliseconds > 0x80000000) {
58 giPartMiliseconds -= 0x80000000;
64 * \brief Return the current timestamp