summaryrefslogtreecommitdiff
path: root/util/flashrom/udelay.c
diff options
context:
space:
mode:
authorStefan Reinauer <stepan@openbios.org>2005-11-24 10:45:34 +0000
committerStefan Reinauer <stepan@openbios.org>2005-11-24 10:45:34 +0000
commit7d5c7a7f1794cf846f2b62813c81f0f2a0ac5b54 (patch)
tree3ea89e5f20c249f3c0c8f31408577d3141214d3a /util/flashrom/udelay.c
parente0e137844adc8366de58514b10ed962da46ce77b (diff)
downloadcoreboot-7d5c7a7f1794cf846f2b62813c81f0f2a0ac5b54.tar.xz
rename the directory to match the program name
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@2102 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/flashrom/udelay.c')
-rw-r--r--util/flashrom/udelay.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/util/flashrom/udelay.c b/util/flashrom/udelay.c
new file mode 100644
index 0000000000..30b8dde261
--- /dev/null
+++ b/util/flashrom/udelay.c
@@ -0,0 +1,37 @@
+#include <sys/time.h>
+#include <stdio.h>
+
+// count to a billion. Time it. If it's < 1 sec, count to 10B, etc.
+unsigned long micro = 1;
+
+void myusec_delay(int time)
+{
+ volatile unsigned long i;
+ for (i = 0; i < time * micro; i++);
+}
+
+void myusec_calibrate_delay()
+{
+ int count = 1000;
+ unsigned long timeusec;
+ struct timeval start, end;
+ int ok = 0;
+
+ printf("Setting up microsecond timing loop\n");
+ while (!ok) {
+ gettimeofday(&start, 0);
+ myusec_delay(count);
+ gettimeofday(&end, 0);
+ timeusec = 1000000 * (end.tv_sec - start.tv_sec) +
+ (end.tv_usec - start.tv_usec);
+ count *= 2;
+ if (timeusec < 1000000 / 4)
+ continue;
+ ok = 1;
+ }
+
+ // compute one microsecond. That will be count / time
+ micro = count / timeusec;
+
+ fprintf(stderr, "%ldM loops per second\n", (unsigned long) micro);
+}