[ECOS] More Wallclock questions

Damir Salantic damir@INTESIS.hr
Wed Dec 5 02:47:00 GMT 2001

Jesper Skov wrote:
> Note that on some platforms the kernel clock may not be accurate over
> long periods of time.
> This can be caused by (a) inaccuracy in timer programming [even if it's
> accurate to 0.1% of the 100Hz ticks, the error will accumulate over
> time], and (b) delays in reloading the timer [some platforms do not have
> automatic reload of the timer counter, so disabling interrupts may cause
> (minimal) timer drift, which again accumulates over time].

Thanks for warning.
Unfortunatelly access to my RTC is too much time consuming. So, I can't
afford reading of it each time when time() function is called (and is called
So, I have to make some tradeoffs here. Probably some synchronization from
time to time should be neccessary.

Anyway, I solved my problem, in way to not change kernel clock, but to keep
difference between it and hardware clock in some variable and to apply
correction each time when get_hw_seconds() is called.

cyg_uint32 Cyg_WallClock::get_hw_seconds(void)
    Cyg_Clock::cyg_resolution res =
    cyg_tick_count_t secs = Cyg_Clock::real_time_clock->current_value();
    secs /= (( res.divisor * 1000000000LL ) / res.dividend) ;
    return (secs + time_difference);

Damir Salantic

More information about the Ecos-discuss mailing list