This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: # ticks per second?
- To: ecos-discuss at sourceware dot cygnus dot com
- Subject: Re: [ECOS] # ticks per second?
- From: Hugo 'NOx' Tyson <hmt at cygnus dot co dot ukx>
- Date: 30 Aug 2000 18:41:35 +0100
- Newsgroups: cygnus.sourceware.ecos.d
- Organization: Cygnus Solutions, a Red Hat company (Cambridge, UK)
- References: <2253171AF143D21185A60000F8FA748B0229A938@pluto.combitech.se> <39AD3314.56663D30@redhat.com>
- Reply-To: ecos-discuss at sources dot redhat dot com
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