avrdude-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avrdude-dev] Verify errors,


From: Alex Shepherd
Subject: RE: [avrdude-dev] Verify errors,
Date: Tue, 22 Jul 2003 18:21:01 +1200

> I'll also have a look at the uisp code to see what they are
> using for delays and the value of the delays

Hmmmm the uisp delay function is quite a lot more comprehensive than what
AvrDude uses.

The code is below but here is a summary of what I think it does. The
TDAPA::Delay_usec delay function first tries to use the cygwinp_delay_usec()
function which tries to use the Pentium PerformanceCounter
QueryPerformanceFrequency() and QueryPerformanceCounter() functions to loop
for the required delay polling the hardware counter.

If this is not available it gets the current time via gettimeofday() and
then uses the usleep() function for delays longer than 20ms and then checks
again to see if the usleep() function has actually delayed for the correct
time and if necessary continues to loop checking the gettimeofday() until
the correct delay has passed.

Its interesting that they use a threshold for using usleep() of 20ms and we
have had to extend our delay to 18 and 32ms. I wonder if simply delaying for
20ms would fix the problem?

It is probably worth adding the gettimeofday() polling loop around usleep()
and make our own usDelay() functions that uses both the usleep() and
gettimeofday() polling. I'll try it as see what happens

Cheers

Alex

In File: DAPA.C

void TDAPA::Delay_usec(long t)
{
  struct timeval t1, t2;

#if defined(__CYGWIN__)
  if (cygwinp_delay_usec(t))
    return;
#endif

  if (t <= 0)
    return;  /* very short delay for slow machines */
  gettimeofday(&t1, NULL);
  if (t > MIN_SLEEP_USEC)
    usleep(t - MIN_SLEEP_USEC);
  /* loop for the remaining time */
  t2.tv_sec = t / 1000000UL;
  t2.tv_usec = t % 1000000UL;
  timeradd(&t1, &t2, &t1);
  do {
    gettimeofday(&t2, NULL);
  } while (timercmp(&t2, &t1, <));
}


In file: cygwinp.C

bool cygwinp_delay_usec(long t)
{
    static bool perf_counter_checked = false;
    static bool use_perf_counter = false;
    static LARGE_INTEGER freq = 0;

    if (! perf_counter_checked) {
        if (QueryPerformanceFrequency(&freq))
            use_perf_counter = true;
        perf_counter_checked = true;
    }

    if (! use_perf_counter)
        return false;
    else {
        LARGE_INTEGER now;
        LARGE_INTEGER finish;
        QueryPerformanceCounter(&now);
        finish.QuadPart = now.QuadPart + (t * freq.QuadPart) / 1000000;
        do {
            QueryPerformanceCounter(&now);
        } while (now.QuadPart < finish.QuadPart);
        return true;
    }
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]