summaryrefslogtreecommitdiffstats
path: root/udelay.c
diff options
context:
space:
mode:
authorOllie Lho <ollie@sis.com.tw>2004-03-17 22:22:08 +0000
committerOllie Lho <ollie@sis.com.tw>2004-03-17 22:22:08 +0000
commitcbbf1259817896cd6339e7517404ba64aa85ed8d (patch)
tree96c21cf62ad8fd400edd11e6e68cb75fdbd6d6bf /udelay.c
parent3770a1132ee0e43836eb907229277506af05ebc8 (diff)
downloadast2050-flashrom-cbbf1259817896cd6339e7517404ba64aa85ed8d.zip
ast2050-flashrom-cbbf1259817896cd6339e7517404ba64aa85ed8d.tar.gz
Move utility functions into new source files
Corresponding to flashrom svn r6 and coreboot v2 svn r1428.
Diffstat (limited to 'udelay.c')
-rw-r--r--udelay.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/udelay.c b/udelay.c
new file mode 100644
index 0000000..9674bbe
--- /dev/null
+++ b/udelay.c
@@ -0,0 +1,43 @@
+#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;
+ void myusec_delay(int time);
+
+ printf("Setting up microsecond timing loop\n");
+ while (!ok) {
+ //fprintf(stderr, "Try %d\n", count);
+ gettimeofday(&start, 0);
+ myusec_delay(count);
+ gettimeofday(&end, 0);
+ timeusec = 1000000 * (end.tv_sec - start.tv_sec ) +
+ (end.tv_usec - start.tv_usec);
+ //fprintf(stderr, "timeusec is %d\n", timeusec);
+ 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);
+
+
+}
OpenPOWER on IntegriCloud