From mboxrd@z Thu Jan 1 00:00:00 1970 From: Benoit Monin Date: Wed, 4 Mar 2009 17:08:47 +0100 (CET) Subject: [U-Boot] [PATCH] ppc: Increase precision of ticks2usec Message-ID: <9454366.19868.1236182927234.JavaMail.www@wwinf8202> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de The tick of some PowerPC cpu is running at high frequency and it can be used to get microsecond precision from it. Make use of div64 to achieve this precision in ticks2usec. Signed-off-by: Beno?t Monin --- lib_ppc/time.c | 15 +++++---------- 1 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib_ppc/time.c b/lib_ppc/time.c index 173ffab..ebda13a 100644 --- a/lib_ppc/time.c +++ b/lib_ppc/time.c @@ -22,6 +22,7 @@ */ #include +#include #ifndef CONFIG_WD_PERIOD # define CONFIG_WD_PERIOD (10 * 1000 * 1000) /* 10 seconds default*/ @@ -71,17 +72,11 @@ void udelay(unsigned long usec) unsigned long ticks2usec(unsigned long ticks) { ulong tbclk = get_tbclk(); + u64 tmp; - /* usec = ticks * 1000000 / tbclk - * Multiplication would overflow at ~4.2e3 ticks, - * so we break it up into - * usec = ( ( ticks * 1000) / tbclk ) * 1000; - */ - ticks *= 1000L; - ticks /= tbclk; - ticks *= 1000L; - - return ((ulong)ticks); + tmp = ticks * 1000000ULL; + do_div (tmp, tbclk); + return (unsigned long)tmp; } #endif /* ------------------------------------------------------------------------- */ -- Cr?ez votre adresse ?lectronique prenom.nom at laposte.net 1 Go d'espace de stockage, anti-spam et anti-virus int?gr?s.