X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Farch%2Fx86%2Ftime.c;h=54e59a5d2d9ac520ebaa8dedbddda239304db8ae;hb=902813fd2da685f025636a13d9f176b592cc8b33;hp=9b59b30b100c94f68cc184bcc2f386450e5b32e9;hpb=51ab5f489bc356940c95cc936fd0508e8f07ea97;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/arch/x86/time.c b/KernelLand/Kernel/arch/x86/time.c index 9b59b30b..54e59a5d 100644 --- a/KernelLand/Kernel/arch/x86/time.c +++ b/KernelLand/Kernel/arch/x86/time.c @@ -4,6 +4,7 @@ * arch/x86/time.c */ #include +#include // === MACROS === #define TIMER_QUANTUM 100 @@ -15,6 +16,7 @@ #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 US_PER_TICK (1000*1000/(TIMER_FREQ)) // === IMPORTS === extern volatile Sint64 giTimestamp; @@ -119,6 +121,21 @@ void Time_Interrupt(int IRQ, void *Ptr) inb(0x71); // Just throw away contents. } +void Time_MicroSleep(Uint16 Microsecs) // max 64 ms +{ + Uint64 cur_tsc = Time_ReadTSC(); + // tsc_per_us * Microsec + Uint64 delta_tsc = (Uint64)Microsecs * giTime_TSCPerTick / US_PER_TICK; + Uint64 tgt_tsc = cur_tsc + delta_tsc; + + if( tgt_tsc < cur_tsc ) + while(Time_ReadTSC() > cur_tsc) + ; + + while( Time_ReadTSC() < tgt_tsc ) + ; +} + Uint64 Time_ReadTSC(void) { Uint32 a, d;