[U-Boot] [RFC] Review of U-Boot timer API

Reinhard Meyer
2011-05-26T04:19:34Z

Dear Graeme Russ,
> On closer inspection, some do, some don't. All ARMv7 (OMAP, S5P, Tegra2)
> do. at91 is odd - It looks like it uses interrupts, but get_timer() and
> udelay() both end up calling get_timer_raw() (with udelay only having
> millisecond resolution it seems). Some others can be configured to
> increment the timer using an interrupt. ARM is, quite frankly, a complete
> mess - It has a mass of *_timer_masked() functions which the core timer
> functions are 'wafer thin' wrapper around, udelay() silently resets
> the timebase trashing get_timer() loops etc.

Please look at current master for at91.

http://git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/cpu/arm926ejs/at91/timer.c;h=a0876879d3907af553d832bea187a062a22b9bd4;hb=5d1ee00b1fe1180503f6dfc10e87a6c6e74778f3

AT91 uses a 32 bit hardware register that by means of a prescaler is made
to increment at a rate in the low megahertz range.

This results in a wrap approximately every 1000 seconds.
Actually this would be sufficient for all known uses of udelay() and get_timer()
timeout loops. However, this hardware register is extended to 64 bits by software
every time it is read (by detecting rollovers).

Since a wrap of that 64 bit "tick" would occur after the earth has ended,
it is simple to obtain milliseconds from it by doing a 64 bit division.

Best Regards,
Reinhard