]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
strmhz(): Round numbers when printing clock frequencies
authorWolfgang Denk <wd@denx.de>
Sun, 19 Oct 2008 00:35:48 +0000 (02:35 +0200)
committerWolfgang Denk <wd@denx.de>
Tue, 21 Oct 2008 09:25:35 +0000 (11:25 +0200)
Round clock frequencies for printing.

Many boards printed off clock frequencies like 399 MHz instead of the
exact 400 MHz because numberes were not rounded. This is fixed now.

Signed-off-by: Wolfgang Denk <wd@denx.de>
include/common.h
lib_generic/strmhz.c

index e6590441369365cc127092e48c8267fbf211adf5..b8a654a8ad0dde97e863922466083b1fe24e59e8 100644 (file)
@@ -692,8 +692,9 @@ void __attribute__((weak)) show_boot_progress (int val);
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
-#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
-#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
+#define DIV_ROUND(n,d)         (((n) + ((d)/2)) / (d))
+#define DIV_ROUND_UP(n,d)      (((n) + (d) - 1) / (d))
+#define roundup(x, y)          ((((x) + ((y) - 1)) / (y)) * (y))
 
 #define ALIGN(x,a)             __ALIGN_MASK((x),(typeof(x))(a)-1)
 #define __ALIGN_MASK(x,mask)   (((x)+(mask))&~(mask))
index d0b6bc60d96a9c7b0dd9b582d1198b1a3400130d..342cf2b21269bf3b3b0cde9cfc0795b7d5440136 100644 (file)
@@ -27,9 +27,11 @@ char *strmhz (char *buf, long hz)
        long l, n;
        long m;
 
-       n = hz / 1000000L;
+       n = DIV_ROUND(hz, 1000000L);
        l = sprintf (buf, "%ld", n);
-       m = (hz % 1000000L) / 1000L;
+
+       hz -= n * 1000000L;
+       m = DIV_ROUND(hz, 1000L);
        if (m != 0)
                sprintf (buf + l, ".%03ld", m);
        return (buf);