2007-09-09 22:02:45 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the flashrom project.
|
|
|
|
*
|
2007-09-09 22:21:05 +02:00
|
|
|
* Copyright (C) 2000 Silicon Integrated System Corporation
|
2007-09-09 22:02:45 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2004-03-17 23:22:08 +01:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <stdio.h>
|
2007-08-23 15:34:59 +02:00
|
|
|
#include "flash.h"
|
2004-03-17 23:22:08 +01:00
|
|
|
|
|
|
|
// 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;
|
2007-04-01 21:44:21 +02:00
|
|
|
for (i = 0; i < time * micro; i++) ;
|
2004-03-17 23:22:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void myusec_calibrate_delay()
|
|
|
|
{
|
|
|
|
int count = 1000;
|
|
|
|
unsigned long timeusec;
|
|
|
|
struct timeval start, end;
|
|
|
|
int ok = 0;
|
|
|
|
|
2007-04-06 13:58:03 +02:00
|
|
|
printf("Calibrating delay loop... ");
|
|
|
|
|
2004-03-17 23:22:08 +01:00
|
|
|
while (!ok) {
|
|
|
|
gettimeofday(&start, 0);
|
|
|
|
myusec_delay(count);
|
|
|
|
gettimeofday(&end, 0);
|
2004-03-20 17:46:10 +01:00
|
|
|
timeusec = 1000000 * (end.tv_sec - start.tv_sec) +
|
|
|
|
(end.tv_usec - start.tv_usec);
|
2004-03-17 23:22:08 +01:00
|
|
|
count *= 2;
|
2004-03-20 17:46:10 +01:00
|
|
|
if (timeusec < 1000000 / 4)
|
2004-03-17 23:22:08 +01:00
|
|
|
continue;
|
|
|
|
ok = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// compute one microsecond. That will be count / time
|
|
|
|
micro = count / timeusec;
|
|
|
|
|
2008-09-07 05:14:27 +02:00
|
|
|
gettimeofday(&start, 0);
|
|
|
|
myusec_delay(100);
|
|
|
|
gettimeofday(&end, 0);
|
|
|
|
timeusec = 1000000 * (end.tv_sec - start.tv_sec) +
|
|
|
|
(end.tv_usec - start.tv_usec);
|
|
|
|
printf_debug("%ldM loops per second, 100 myus = %ld us. ",
|
|
|
|
(unsigned long)micro, timeusec);
|
2007-10-18 01:55:15 +02:00
|
|
|
printf("OK.\n");
|
2004-03-17 23:22:08 +01:00
|
|
|
}
|