[uClinux-dev] gettimeofday problem

Andy Pichotta apichotta at controlproductsinc.com
Wed Aug 14 09:25:59 EDT 2002


I am new to Linux and was looking for ways to get small time delays.
It looks like getitimer and setitimer may come in handy.

Also I now see why my sample code acts the way it does.  The kernel code
in time.c does a "usec -= 1000000;" then adds 1 to the "sec" variable
every second.  My code displays sec and usec every 1 second.  It is now
obvious why the usec value does not change each time I printf it at one
second intervals.  From now on I will dig a little deeper before posting
dumb questions.

Thanks,
Andy


-----Original Message-----
From: owner-uclinux-dev at uclinux.org
[mailto:owner-uclinux-dev at uclinux.org] On Behalf Of Kendrick Hamilton
Sent: Tuesday, August 13, 2002 3:21 PM
To: uclinux-dev at uclinux.org
Subject: Re: [uClinux-dev] gettimeofday problem

Have you looked at getitimer(2)


Kendrick Hamilton E.I.T.
SED Systems, a division of Calian Ltd.
18 Innovation Blvd.
PO Box 1464
Saskatoon, Saskatchewan
Canada
S7N 3R1

Hamilton at sedsystems.ca
Tel: (306) 933-1453
Fax: (306) 933-1486

On Tue, 13 Aug 2002, Andy Pichotta wrote:

> I am running uClinux 2.4.17 on cold fire 5272C3 rev 2.2 development
> board.
>
> I wanted to get a time delay down in the ms range and thought I could
> use gettimeofday().
>
> The output from my test code below shows .tv_usec never changes.
>
> usec value always stays at what ever value I set it to.
>
> Is this a kernel bug or am I doing something wrong?
>
>
>
> The output from the following code is:
>
> /mnt/modbus>./time_test
>
> 146, 1
>
> 147, 1
>
> 148, 1
>
> 149, 1
>
> 150, 1
>
> 151, 1
>
> 152, 1
>
> 153, 1
>
> 154, 1
>
> 155, 1
>
> /mnt/modbus>
>
>
>
> This is the code:
>
>
>
> #include <time.h>
>
> #include <stdio.h>
>
> #include <string.h>
>
> #include <sys/time.h>
>
>
>
> int main()
>
> {
>
> int x;
>
> struct timeval sec_and_us;
>
> struct timezone zone;
>
> time_t start;
>
>
>
> sec_and_us.tv_usec = 1;  // Set to some arbitrary value
>
> sec_and_us.tv_sec = 145;
>
> settimeofday(&sec_and_us, &zone); // Set it
>
>
>
> for(x=0; x<10; x++)
>
> {
>
> time(&start);
>
> while(time(NULL) <= start) ;        // Wait here for 1 second
>
>
>
> if(gettimeofday(&sec_and_us, &zone) == 0)
>
>             printf("\n%ld, %ld", sec_and_us.tv_sec,
sec_and_us.tv_usec);
>
> else
>
>             printf("\nget time error");
>
> }
>
>   return 0;
>
> }
>
>
>
> Thanks,
>
> Andy
>
>

This message resent by the uclinux-dev at uclinux.org list server
http://www.uClinux.org/

This message resent by the uclinux-dev at uclinux.org list server http://www.uClinux.org/



More information about the uClinux-dev mailing list