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()


>>>>> "Alexander" == Alexander Neundorf <neundorf@kde.org> writes:

Hi,

 Alexander> From net/ppp/current/src/sys-ecos.c:

 Alexander> int gettimeofday(struct timeval *tv, struct timezone *tz)
 Alexander> {
 Alexander>     cyg_tick_count_t time = cyg_current_time();
 Alexander>     tv->tv_sec = time/CYGNUM_HAL_RTC_DENOMINATOR;
 Alexander>     tv->tv_usec = (time%CYGNUM_HAL_RTC_DENOMINATOR)*10000;
 Alexander>     return 0;
 Alexander> }

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

-- 
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]