[U-Boot] [RFC] Review of U-Boot timer API
Graeme Russ
graeme.russ at gmail.com
Wed May 25 10:38:12 CEST 2011
On 25/05/11 18:08, Wolfgang Denk wrote:
> Dear Graeme Russ,
>
> In message <BANLkTinZ_q8_vqd9mzm7BY64Hi=zuyFZTQ at mail.gmail.com> you wrote:
>>
>> With the prescaler design we are discussing, as long as we have access to
>> a free-running tick counter, it does not matter one iota if the interrupt
>> is delayed by one tick, a hundred ticks or a thousand ticks privided it
>> eventually happens within the roll-over interval of the tick counter
>
> I don't get you. In such a system, the interrupt would be the tick
> (see the PPC implementation). If you miss interrupts, you miss ticks.
Yes, you miss ticks, but if the hardware is keeping the tick counter
current in the background (i.e. without software or interrupts) then this
does not matter - The prescaler takes care of this...
The key is the prescaler takes a 'tick delta' between the last time it was
called and now, uses the 'tick frequency' to calculate a corresponding
'timer delta' which it adds to the current timer
So the frequency of calling the prescaler _does not matter_ (it does not
even need to be a regular frequency) provided the tick-counter does not do
a complete wrap (at 4GHz this is 4 seconds for a 32-bit counter) - So as
long as you call the prescaler at least every 4 seconds (and get_timer()
calls the prescaler) then you will never have a timer glitch in your timing
loop.
This relies on the tick counter wrapping properly.
So, if your tick counter is accurate, your timer is accurate even if you
are using an ISR to call the prescaler and temporarily disable interrupts
How many platforms have no hardware counter whatsoever? - These will have
to implement the timer using interrupts and suffer the accuracy loss when
interrupts are disabled (and how would these implement udelay() anyway -
hard loops I guess)
And now for the kicker - If your tick counter is microsecond resolution or
better, you can maintain microsecond, millisecond (second, minute etc)
timers trivially with a new prescaler
Regards,
Graeme
More information about the U-Boot
mailing list