[ECOS] Time questions

Andrew Lunn andrew@lunn.ch
Fri Nov 3 09:31:00 GMT 2006

On Thu, Nov 02, 2006 at 07:16:45PM -0500, Andre-John Mas wrote:
> Hi,
> I have been asked to correct an issue in our code. The time returned by the function:
>    time( time_t* )
> returns the right value, when the system has been set using
> SNTP. The issue is that a call to cyg_current_time() is made in part
> of our code, since a requirement had been made to have the time in
> milliseconds. From what I can tell this function only returns the
> time since the system booted and not the date as set by SNTP, which
> seems to be maintained by the wallclock code? Is this correct?

Yes, cyg_current_time() is no way related to wall clock time.
cyg_current_time() is the number of ticks since startup. This is
typically in 10ms ticks, but it is configurable how long a tick is.

time() will return the wallclock time with a resolution of 1s. 

You are asking for wallclock time with a resolution of less than
1s. This is currently not available. What you need is the POSIX call

 int clock_gettime(clockid_t clk_id, struct timespec *tp);

which is not implemented. Also, it is not easy to implement. To do
this you would have to extend the io/wallclock API to include a
function get_current_timespec() which would return a timespec. You
would also need to extend the API between io/wallclock and the
wallclock drivers so that they implement a call get_hw_timespec()
which would return a timespec. However this might not solve your
problem if you underlying wallclock hardware only supports time to 1s
accuracy. If this is the case you could somehow try to combine time
from the wallclock device with cyg_current_time(), but this is not
easy. Combing information from two clocks running from different
sources gives all sorts of wrap-around problems, time going backwards


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

More information about the Ecos-discuss mailing list