public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] # ticks per second?
@ 2000-08-30  7:44 Andreas.Karlsson
  2000-08-30  9:15 ` Jonathan Larmour
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas.Karlsson @ 2000-08-30  7:44 UTC (permalink / raw)
  To: ecos-discuss

Hi,



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?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [ECOS] # ticks per second?
  2000-08-30  7:44 [ECOS] # ticks per second? Andreas.Karlsson
@ 2000-08-30  9:15 ` Jonathan Larmour
  2000-08-30 10:45   ` Hugo 'NOx' Tyson
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Larmour @ 2000-08-30  9:15 UTC (permalink / raw)
  To: Andreas.Karlsson; +Cc: ecos-discuss

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;

Jifl
-- 
Red Hat, 35 Cambridge Place, Cambridge, UK. CB2 1NS  Tel: +44 (1223) 728762
"Plan to be spontaneous tomorrow."  ||  These opinions are all my own fault

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [ECOS] # ticks per second?
  2000-08-30  9:15 ` Jonathan Larmour
@ 2000-08-30 10:45   ` Hugo 'NOx' Tyson
  2000-08-30 11:05     ` Grant Edwards
  0 siblings, 1 reply; 5+ messages in thread
From: Hugo 'NOx' Tyson @ 2000-08-30 10:45 UTC (permalink / raw)
  To: ecos-discuss


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [ECOS] # ticks per second?
  2000-08-30 10:45   ` Hugo 'NOx' Tyson
@ 2000-08-30 11:05     ` Grant Edwards
  2000-08-31  4:15       ` Hugo 'NOx' Tyson
  0 siblings, 1 reply; 5+ messages in thread
From: Grant Edwards @ 2000-08-30 11:05 UTC (permalink / raw)
  To: ecos-discuss; +Cc: ecos-discuss

On Wed, Aug 30, 2000 at 06:41:35PM +0100, Hugo 'NOx' Tyson wrote:

> 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.
[...]
> 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?

Since it's not possible to change the clock tick period at
run-time (right?), I'd try for a pre-processor constant.  But
that might be pretty hard to do in an accurate, general way.

-- 
Grant Edwards
grante@visi.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [ECOS] # ticks per second?
  2000-08-30 11:05     ` Grant Edwards
@ 2000-08-31  4:15       ` Hugo 'NOx' Tyson
  0 siblings, 0 replies; 5+ messages in thread
From: Hugo 'NOx' Tyson @ 2000-08-31  4:15 UTC (permalink / raw)
  To: ecos-discuss


Grant Edwards <grante@visi.com> writes:
> On Wed, Aug 30, 2000 at 06:41:35PM +0100, Hugo 'NOx' Tyson wrote:
> > 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.
> [...]
> > 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?
> 
> Since it's not possible to change the clock tick period at
> run-time (right?), I'd try for a pre-processor constant.  But
> that might be pretty hard to do in an accurate, general way.

Precisely!

The thing within the kernel will create for you a "converter" object to or
from "system clocks" from or to any unit of your choice - you then use the
converter object to change eg. N seconds into M system ticks.  Or vice
versa, whatever...

You're right, any application would only create a very small number of
these of these during startup, but the calculation involved is way beyond
the preprocessor and so forth.  So to generalize fully, it's done at
runtime.  (This is one of the very very few examples of stuff I feel it's
OK to do at runtime, even though the result is the same every time - and it
also makes it easier to test properly)

	- Huge

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-08-31  4:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-30  7:44 [ECOS] # ticks per second? Andreas.Karlsson
2000-08-30  9:15 ` Jonathan Larmour
2000-08-30 10:45   ` Hugo 'NOx' Tyson
2000-08-30 11:05     ` Grant Edwards
2000-08-31  4:15       ` Hugo 'NOx' Tyson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).