avr-chat
[Top][All Lists]
Advanced

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

Re: [avr-chat] Avrdude : how to slow it down ?


From: Bernard Fouché
Subject: Re: [avr-chat] Avrdude : how to slow it down ?
Date: Wed, 14 Sep 2005 17:31:08 +0200
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Joerg Wunsch wrote:


?! :-/
The overhead of calling usleep() is apparently already larger than the
amount of delay caused by it.  Also, there's a system-dependent
granularity of which delays can be had with this kind of sleep
functions, often it's just 10 ms granularity (i.e. 100 Hz clock
frequency).  You can just write usleep(1) as well.
On kernel 2.6.x usleep(3) works well now. This was posted some time ago when kernel 2.4.x had some granularity problems, I just ran it on kernel 2.6.12 and it was okay by 1 or 2 ms:

#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>

#define MILLISEC_DIFF(new, old, diff)   {                              \
       (diff) = (((new).tv_sec  - (old).tv_sec)  * 1000L ) +           \
                (((new).tv_usec - (old).tv_usec) / 1000L );             \
}

int main(int args, char ** argv) {

       int time;
       struct timeval time1,time2;
       long elapsed;

       if(args < 2) {
               printf("USAGE: sleep <time in milliseconds>\n");
               exit(0);
       }

       time = atoi(argv[1]);

       while(1) {

               gettimeofday(&time1, NULL);
               usleep(time*1000);
               gettimeofday(&time2, NULL);

               MILLISEC_DIFF(time2, time1, elapsed);

printf("time 1 = <%ld:%ld>, time 2 = <%ld:%ld> ,elapsed =%ld\n\n",time1.tv_sec, time1.tv_usec, time2.tv_sec, time2.tv_usec, elapsed);
       }
}





reply via email to

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