From: Reinhard Meyer <u-boot@emk-elektronik.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] TIMER cleanup RFC, was: [PATCH 4/4] arm920t/at91/timer: replace bss variables by gd
Date: Tue, 30 Nov 2010 10:14:20 +0100 [thread overview]
Message-ID: <4CF4C06C.5090706@emk-elektronik.de> (raw)
In-Reply-To: <20101130081628.B76ADEA65E5@gemini.denx.de>
Dear Wolfgang Denk,
what we really need is only a 32 bit monotonous free running tick that increments
at a rate of at least 1 MHz. As someone pointed out a while ago, even at 1GHz that would
last for four seconds before it rolls over. But a 1HGz counter could be 64 bit internally
and always be returned as 32 bits when it is shifted right to bring it into the "few" MHz
range.
Any architecture should be able to provide such a 32 bit value. On powerpc that would
simply be tbu|tbl shifted right a few bits.
An architecture and SoC specific timer should export 3 functions:
int timer_init(void);
u32 get_tick(void); /* return the current value of the internal free running counter */
u32 get_tbclk(void); /* return the rate at which that counter increments (per second) */
A generic timer function common to *most* architectures and SoCs would use those two
functions to provice udelay() and reset_timer() and get_timer().
Any other timer functions should not be required in u-boot anymore.
However get_timer() and reset_timer() are a bit of a functional problem:
currently reset_timer() does either actually RESET the free running timer (BAD!) or
remember its current value in another (gd-)static variable which later is subtracted
when get_timer() is called. That precludes the use of several timers concurrently.
Also, since the 1000Hz base for that timer is usually derived from get_tick() by
dividing it by some value, the resulting 1000Hz base is not exhausting the 32 bits
before it wraps to zero.
Therefore I propose two new functions that are to replace reset_timer() and get_timer():
u32 init_timeout(u32 timeout_in_ms); /* return the 32 bit tick value when the timeout will be */
bool is_timeout(u32 reference); /* return true if reference is in the past */
A timeout loop would therefore be like:
u32 t_ref = timeout_init(3000); /* init a 3 second timeout */
do ... loop ... while (!is_timeout(t_ref));
coarse sketches of those functions:
u32 init_timeout(u32 ms)
{
return get_ticks() + ((u64)get_tbclk() * (u64)ms) / (u64)1000;
}
bool is_timeout(u32 reference)
{
return ((int)get_ticks() - (int)reference) > 0;
}
Unfortunately this requires to "fix" all uses of get_timer() and friends, but I see no other
long term solution to the current incoherencies.
Comments welcome (and I would provide patches)...
Reinhard
next prev parent reply other threads:[~2010-11-30 9:14 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-30 6:37 [U-Boot] [PATCH 0/4] get at91rm9200ek working with ARM relocation Andreas Bießmann
2010-11-30 6:37 ` [U-Boot] [PATCH 1/4] at91rm9200ek: add configure target for RAM boot Andreas Bießmann
2010-11-30 6:37 ` [U-Boot] [PATCH 2/4] MAKEALL: fix AT91 Andreas Bießmann
2010-11-30 6:37 ` [U-Boot] [PATCH 3/4] arm920t: fix linker skript for -pie linking Andreas Bießmann
2010-12-08 22:52 ` Wolfgang Denk
2010-12-09 7:24 ` Andreas Bießmann
2010-12-09 7:33 ` Albert ARIBAUD
2010-12-09 9:45 ` Wolfgang Denk
2010-12-09 10:32 ` Wolfgang Denk
2010-12-09 10:51 ` Andreas Bießmann
2010-11-30 6:37 ` [U-Boot] [PATCH 4/4] arm920t/at91/timer: replace bss variables by gd Andreas Bießmann
2010-11-30 7:17 ` Reinhard Meyer
2010-11-30 8:03 ` Andreas Bießmann
2010-11-30 8:16 ` Wolfgang Denk
2010-11-30 8:48 ` Andreas Bießmann
2010-11-30 9:14 ` Reinhard Meyer [this message]
2010-11-30 15:11 ` [U-Boot] TIMER cleanup RFC, was: " J. William Campbell
2010-11-30 15:48 ` Reinhard Meyer
2010-11-30 17:29 ` J. William Campbell
2010-11-30 18:06 ` [U-Boot] [PATCH 0/4] get at91rm9200ek working with ARM relocation Andreas Bießmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4CF4C06C.5090706@emk-elektronik.de \
--to=u-boot@emk-elektronik.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox