Dear all,

its quite funny to see how we go around in circles here, this proposal of Albert
now is quite close to my original proposal. Only that I factored the ms_to_ticks
AND the comparison into the timer calls:

u64 timer_setup(u32 timeout_in_ms)
{
        return get_ticks() + ms_to_ticks(timeout_in_ms);
}

int timer_expired(u64 endtime)
{
        /*
         * convert the unsigned difference to signed, to easyly
         * check for "carry". In assembly we could just do a BCC
         * after the subtraction to see whether get_ticks()
         * has passed ahead of endtime.
         */
        return (signed)(endtime - get_ticks()) < 0;
}

What can be more pragmatic and trivial than those two functions??

Usage then:

        /* let's wait 200 milliseconds */
        u64 endtime = timer_setup(200);
        do {
                ...
        } while (!timer_expired(endtime));

 
> That's where I come back to one point of my proposal: if we can get a 
> general framework for get_timer() to return a 64-bit free-running tick 

We have that already at least on PowerPC and AT91. Its called u64 
get_ticks(void)
and returns a free running 64 bit value. An associated function,
u64 get_tbclk(void) returns the frequency of that tick.

I don't think that this part of the framework needs to be discussed -
except *maybe* for function names.

> value, then we might not need a ms-based get_time() at all, because we 
> could use get_timer() as well for ms timings, provided we can convert 
> our timeout from ms to ticks, i.e.
> 
>       /* let's wait 200 milliseconds */
>       /* Timing loop uses ticks: convert 200 ms to 'timeout' ticks */
>       timeout = ms_to_ticks(200);
>       u32 start = get_timer(); /* start time, in ticks */
>       do {
>               ...
>       } while ( (get_timer() -start) < timeout);

Mandatory u64 for start AND timeout, please.
It is the same functionality as my proposal, just bears more places where
"users" might make mistakes.

But I am sure that Wolfgang will not like either of our proposals, because
the variables used in "userspace" are not in ms.

Reinhard
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to