[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avrdude-dev] Win 32 port
From: |
Jan-Hinnerk Reichert |
Subject: |
Re: [avrdude-dev] Win 32 port |
Date: |
Fri, 13 Feb 2004 03:02:39 +0100 |
User-agent: |
KMail/1.5.4 |
Okay, it looks like gettimeofday() is somehow wrapped to a Windows
call. So I think we should use the usecPerfDelay() with the following
fallback.
The code is not tested. I haven't even compiled it.
================================================
unsigned usleep( unsigned int uSeconds )
{
struct timeval t1, t2;
if (usecPerfDelay(uSeconds))
return;
gettimeofday(&t2, NULL);
/*
* Wait for next tick. Otherwise we might get a shorter delay.
*
* An alternative would be to measure the timeslice once at
* startup and add it to the delay time.
*/
do {
gettimeofday(&t1, NULL);
/* NB: timercmp(&t1, &t2, ==) will not work here */
} while ((t1.tv_sec==t2.tv_sec) && (t1.tv_nsec==t2.tv.nsec));
/* loop for the remaining time */
t2.tv_sec = uSeconds / 1000000UL;
t2.tv_usec = uSeconds % 1000000UL;
timeradd(&t1, &t2, &t1);
do {
/* Give up timeslice */
sleep(0);
gettimeofday(&t2, NULL);
} while (timercmp(&t2, &t1, <));
}