[ECOS] # ticks per second?

Hugo 'NOx' Tyson hmt@cygnus.co.ukx
Wed Aug 30 10:45:00 GMT 2000


Jonathan Larmour <jlarmour@redhat.com> writes:

> Andreas.Karlsson@combitechsystems.com wrote:
> > 
> > Is this rows correct to obtain the number of ticks per second? I want some
> > 
> > timers to go off after some seconds.
> > 
> > /Andreas
> > 
> > cyg_resolution_t clock_res;
> > 
> > cyg_handle_t clock_handle;
> > 
> > cyg_uint32 sec;
> > 
> > clock_handle=cyg_real_time_clock();
> > 
> > clock_res=cyg_clock_get_resolution(clock_handle);
> > 
> > sec=(clock_res.divisor/clock_res.dividend)*1000000000; //dividend/divisor?
> 
> Yes, although you run the risk of underflow: divisor would typically be
> something like 100 whereas dividend would be 1E9. So try using:
> 
> unsigned long long lltmp;
> tmp = (clock_res.divisor*1000000000)/clock_res.dividend;
> sec = tmp;

And there is a C++ solution to this within the kernel.  See the test
clockcnv.cxx in the kernel tests directory for how to use it, and clock.cxx
in the kernel source for its implementation.

It reduces and factorizes the big numbers so that instead of doing

	K * DIVISOR * 10^N / DIVIDEND

or whatever, it does

	K * A / C * B / D

where ABCD are chosen such that

	A * B    DIVISOR * 10^N
	----- == --------------
	C * D       DIVIDEND

thus making it all far less likely to underflow or lose precision.

It doesn't (yet) have a KAPI (C) API.  It's used within the uITRON
implementation to get milliSecond clocks, which is bare C++.

Feel free to design and contribute a KAPI API?

HTH
	- Huge


More information about the Ecos-discuss mailing list