Haavard Skinnemoen | b644d6b | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002-2006 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Haavard Skinnemoen | b644d6b | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 6 | */ |
| 7 | #include <common.h> |
| 8 | |
Ed Swarthout | d065acb | 2011-03-05 10:28:17 -0600 | [diff] [blame] | 9 | char *strmhz (char *buf, unsigned long hz) |
Haavard Skinnemoen | b644d6b | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 10 | { |
| 11 | long l, n; |
| 12 | long m; |
| 13 | |
Masahiro Yamada | eff8e68 | 2014-11-07 03:03:26 +0900 | [diff] [blame] | 14 | n = DIV_ROUND_CLOSEST(hz, 1000) / 1000L; |
Haavard Skinnemoen | b644d6b | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 15 | l = sprintf (buf, "%ld", n); |
Wolfgang Denk | 709e85d | 2008-10-19 02:35:48 +0200 | [diff] [blame] | 16 | |
| 17 | hz -= n * 1000000L; |
Masahiro Yamada | eff8e68 | 2014-11-07 03:03:26 +0900 | [diff] [blame] | 18 | m = DIV_ROUND_CLOSEST(hz, 1000L); |
Haavard Skinnemoen | b644d6b | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 19 | if (m != 0) |
| 20 | sprintf (buf + l, ".%03ld", m); |
| 21 | return (buf); |
| 22 | } |