Dear =?ISO-8859-1?Q?Matthias_Wei=DFer?=, In message <4c5fa669.6070...@arcor.de> you wrote: > > >> + tmo = usec_to_tick(usec); > >> + tmp = get_ticks() + tmo; /* get current timestamp */ > >> + > >> + while (get_ticks()< tmp) /* loop till event */ > >> + /*NOP*/; > > > > This is broken when the timer wraps around. Compare the limit against > > the difference, to make use of unsigned arithmetics. > > Isn't this a theoretical problem? The timer increments with approx. > 160kHz. get_ticks() returns a 64 bit value which wraps all ~ 3*10^6 > years. I don't expect my hardware to work that long without a reboot.
Such assumptions that problems might remain theoretical have cuased enough real problems already. I mean, if it was difficult to write correct code I might turn a blind eye, but why not fix it? It's a trivial change... > Can you point me to an example where the timer stuff is done right? I > see it done differently on nearly all ARM SOCs. Rule of a thumb: to copy from ARM means copying problems. Use: while ((get_ticks() - tmp) < tmo) ; 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 Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer. - Fred Brooks, Jr. _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot