> -----Original Message-----
> From: u-boot-boun...@lists.denx.de [mailto:u-boot-boun...@lists.denx.de]
> On Behalf Of Wolfgang Denk
> Sent: Tuesday, October 26, 2010 10:59 AM
> To: Reinhard Meyer
> Cc: Menon, Nishanth; u-boot
> Subject: Re: [U-Boot] [PATCH v2] mmc: omap: timeout counter fix
> 
> Dear Reinhard Meyer,
> 
> In message <4cc62b6c.30...@emk-elektronik.de> you wrote:
> >
> > In such cases I prefer to use:
> >
> >     uint64_t etime;
> > ...
> >     etime = get_ticks() + get_tbclk(); /* 1 second */
> >     do {
> >             whatever;
> >             udelay (xx);
> >     } while (condition && get_ticks() <= etime);
> >
> > That is far more accurate than calling udelay() 100000 times.
> 
> It may be more accuratre, but it may also be HORRIBLY WRONG!!
> 
> Do NOT do that!! NEVER implement such a delay loop as
> 
>       end = time() + delay;
>       while (time() < end)
>               ...
> 
> 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.
> 
> 
> Correct implementation of a timeout like that should always look like
> that:
> 
>       start = time();
>       while ((time() - start) < delay)
>               ...
> 
> This works much better (assuming unsigned arithmetics).
[Ghorai] Thanks.. This is the best approach. 
Otherwise udelay() will increase the boot time. 

> 
> 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: w...@denx.de
> Ein weiser Herrscher kann in einem großen Land  mehr  Gutes  bewirken
> als  in  einem kleinen - ein dummer Herrscher aber auch viel mehr Un-
> fug. Da weise Herrscher seltener sind als dumme, war ich schon  immer
> gegen große Reiche skeptisch.                   - Herbert Rosendorfer
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to