diff options
author | Li-Ta Lo <ollie@lanl.gov> | 2004-03-17 22:22:08 +0000 |
---|---|---|
committer | Li-Ta Lo <ollie@lanl.gov> | 2004-03-17 22:22:08 +0000 |
commit | 115bd0549bfca99a49e5d929820af605dab715b1 (patch) | |
tree | 9cf65953314b057078a77b523d417c5b04821d38 /util/flash_and_burn/udelay.c | |
parent | fc2ad05e6f478a16e68d926448c6337f1c4fa436 (diff) |
move utility functions into new source files
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@1428 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/flash_and_burn/udelay.c')
-rw-r--r-- | util/flash_and_burn/udelay.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/util/flash_and_burn/udelay.c b/util/flash_and_burn/udelay.c new file mode 100644 index 0000000000..9674bbefd1 --- /dev/null +++ b/util/flash_and_burn/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); + + +} |