1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 07:02:34 +02:00
flashrom/udelay.c
Uwe Hermann 0846f89b0a Drop a bunch of useless header files, merge them into flash.h
Corresponding to flashrom svn r128 and coreboot v2 svn r2746.

Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Stefan Reinauer <stepan@coresystems.de>
2007-08-23 13:34:59 +00:00

41 lines
828 B
C

#include <sys/time.h>
#include <stdio.h>
#include "flash.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("Calibrating delay loop... ");
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;
printf_debug("%ldM loops per second. ", (unsigned long)micro);
printf("ok\n");
}