From: Reinhard Meyer Date: Tue, 26 Oct 2010 09:00:49 +0200 Subject: [U-Boot] Timer implementations (was: Re: [PATCH v2] mmc: omap: timeout counter fix) In-Reply-To: <4CC66ECA.9000106@emk-elektronik.de> References: <1288054924-24989-1-git-send-email-nm@ti.com> <4CC62B6C.30601@emk-elektronik.de> <20101026052856.3D467152451@gemini.denx.de> <4CC66A67.4000608@emk-elektronik.de> <20101026054812.60816135DE3@gemini.denx.de> <4CC66ECA.9000106@emk-elektronik.de> Message-ID: <4CC67CA1.9090302@emk-elektronik.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de I just had a look at other ARM implementations of timer.c. Some have a colourful mix of 32 and 64 bits values, resulting in some 64 bit timer functions returning the upper 32 bits always cleared. Some implement udelay() in the "while (xxxtime() < endtime);" variant. I will fix this for at91 and submit a patch. I also see that: void reset_timer(void) { gd->timer_reset_value = get_ticks(); } ulong get_timer(ulong base) { return tick_to_time(get_ticks() - gd->timer_reset_value) - base; } If implemented with true 64 bits for get_ticks() that function is useable for timeout programming: ulong timeval = get_timer (0); do { ... } while (get_timer (timeval) < TIMEOUT); It appears that the "base" parameter and return value is in CONFIG_SYS_HZ units, and not in native ticks. That causes 64 bit mul/div every time get_timer() is called. Won't hurt in a timeout loop, though. I guess the theoretically unnecessary function reset_timer() might have been invented to mask the issue of 32 bit wraparounds when get_timer() is not truly 64 bits??? Reinhard