This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ecos and gettimeofday()


On Sunday 16 October 2005 05:45 am, Peter Korsgaard wrote:
[snip]
> Independently of where to put the implementation, it would also be
> very interesting to provide sub-tick resolution with HAL_CLOCK_READ -
> E.G something like (completely untested):
>
> int gettimeofday(struct timeval *tv, struct timezone *tz)
> {
>     cyg_uint32 before, after;
>     cyg_tick_count_t time;
>
>     /* repeat until we can do a HAL_CLOCK_READ and cyg_current_time
>     without getting a timer tick */
>     do {
>        before = HAL_CLOCK_READ();
>        time   = cyg_current_time();
>        after  = HAL_CLOCK_READ();
>     } while (after < before);
>
>     tv->tv_sec = time/CYGNUM_HAL_RTC_DENOMINATOR;
>     tv->tv_usec = (time%CYGNUM_HAL_RTC_DENOMINATOR)*10000;
>
>     tv->tv_usec += (10000/CYGNUM_KERNEL_COUNTERS_RTC_RESOLUTION *
>        (long long)before) / CYGNUM_KERNEL_COUNTERS_RTC_PERIOD;
>
>     if (tv->tv_usec >= 1000000)
>     {
>         tv->tv_sec++;
>         tv->tv_usec -= 1000000;
>     }
>
>     return 0;
> }
>
> The do .. while loop may need some HAL_REORDER_BARRIER() calls in
> between to make sure gcc doesn't get too clever.
>
> --
> Bye, Peter Korsgaard

This is cool. This should also be added to the clock_gettime functionality 
(probably in the same underlying code).

-Rich
-- 
Richard Pennington
Email: rich@pennware.com
http://www.pennware.com ftp://ftp.pennware.com

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]