[U-Boot] [PATCH v2] mmc: omap: timeout counter fix

Wolfgang Denk wd at denx.de
Tue Oct 26 07:48:12 CEST 2010


Dear Reinhard Meyer,

In message <4CC66A67.4000608 at emk-elektronik.de> you wrote:
>
> > It fails in case the timer wraps around.
> >
> > Assume 32 bit counters, start time = 0xFFFFFFF0, delay = 0x20. It
> > will compute end = 0x10, the while codition is immediately false, and
> > you don't have any delay at all, which most probably generates a
> > false error condition.
> 
> I used and assumed a 64 bit counter, that will not wrap around while
> our civilization still exists...


The code is still wrong, and as a simple correct implementation exists
there is no excuse for using such incorrect code.

Please fix that!

> If get_ticks() is only 32 bits worth, both methods will misbehave
> at a 32 bit wrap over.

No.

> > 	start = time();
> > 	while ((time() - start)<  delay)
> > 		...
> >
> > This works much better (assuming unsigned arithmetics).
> 
> True, provided the underlying timer is really 64 bits, otherwise
> this fails, too...

You are wrong. Try for example this:

--------------------- snip -------------------
#include <stdio.h>

int main(void)
{
	unsigned int time = 0xFFFFFFF0;
	unsigned int delay = 0x20;
	unsigned int start;

	start = time;

	printf("start=0x%X\n", start);

	while ((time - start) < delay) {
		printf("time=0x%X...\n", time);
		++time;
	}

	return 0;
}
--------------------- snip -------------------

> Best would be to assign get_ticks() to a 32 bit unsigned and use
> 32 bit vars for start and delay as well.

? But that's what I wrote?

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Speculation is always more interesting than facts.
                                    - Terry Pratchett, _Making_Money_


More information about the U-Boot mailing list