* SUCH DAMAGE.
*/
+/**
+ * @file i386/timer.c
+ * i386 specific timer routines
+ */
+
#include <libpayload.h>
#include <arch/rdtsc.h>
-static unsigned int cpu_khz;
+/**
+ * @ingroup arch
+ * Global variable containing the speed of the processor in KHz.
+ */
+u32 cpu_khz;
/**
* Calculate the speed of the processor for use in delays.
end = rdtsc();
/*
- * The clock rate is 1193180 Hz, the number of miliseconds for a
+ * The clock rate is 1193180 Hz, the number of milliseconds for a
* period of 0xffff is 1193180 / (0xFFFF * 1000) or .0182.
* Multiply that by the number of measured clocks to get the kHz value.
*/
cpu_khz = (unsigned int)((end - start) * 1193180U / (1000 * 0xffff));
+
+ return cpu_khz;
}
static inline void _delay(unsigned int delta)
while (rdtsc() < timeout) ;
}
+/**
+ * Delay for a specified number of nanoseconds.
+ *
+ * @param n Number of nanoseconds to delay for.
+ */
void ndelay(unsigned int n)
{
_delay(n * cpu_khz / 1000000);
}
+/**
+ * Delay for a specified number of microseconds.
+ *
+ * @param n Number of microseconds to delay for.
+ */
+void udelay(unsigned int n)
+{
+ _delay(n * cpu_khz / 1000);
+}
+
+/**
+ * Delay for a specified number of milliseconds.
+ *
+ * @param m Number of milliseconds to delay for.
+ */
void mdelay(unsigned int m)
{
_delay(m * cpu_khz);
}
+/**
+ * Delay for a specified number of seconds.
+ *
+ * @param s Number of seconds to delay for.
+ */
void delay(unsigned int s)
{
_delay(s * cpu_khz * 1000);