Haavard Skinnemoen | 0768b7a | 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 | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Haavard Skinnemoen | 0768b7a | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 6 | */ |
| 7 | #include <common.h> |
| 8 | |
Ed Swarthout | 55f7934 | 2011-03-05 10:28:17 -0600 | [diff] [blame] | 9 | char *strmhz (char *buf, unsigned long hz) |
Haavard Skinnemoen | 0768b7a | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 10 | { |
| 11 | long l, n; |
| 12 | long m; |
| 13 | |
Masahiro Yamada | 4515992 | 2014-11-07 03:03:26 +0900 | [diff] [blame] | 14 | n = DIV_ROUND_CLOSEST(hz, 1000) / 1000L; |
Haavard Skinnemoen | 0768b7a | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 15 | l = sprintf (buf, "%ld", n); |
Wolfgang Denk | d50c7d4 | 2008-10-19 02:35:48 +0200 | [diff] [blame] | 16 | |
| 17 | hz -= n * 1000000L; |
Masahiro Yamada | 4515992 | 2014-11-07 03:03:26 +0900 | [diff] [blame] | 18 | m = DIV_ROUND_CLOSEST(hz, 1000L); |
Haavard Skinnemoen | 0768b7a | 2008-08-18 13:41:27 +0200 | [diff] [blame] | 19 | if (m != 0) |
| 20 | sprintf (buf + l, ".%03ld", m); |
| 21 | return (buf); |
| 22 | } |