[U-Boot] [PATCH 01/15] bootstage: Provide a default timer function

Simon Glass sjg at chromium.org
Mon May 22 11:05:22 UTC 2017


If CONFIG_SYS_TIMER_COUNTER is used we can provide a default microsecond
timer implementation.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 lib/time.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lib/time.c b/lib/time.c
index 3c49243e6a..aed1a091f2 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -36,6 +36,23 @@ unsigned long notrace timer_read_counter(void)
 	return readl(CONFIG_SYS_TIMER_COUNTER);
 #endif
 }
+
+ulong timer_get_boot_us(void)
+{
+	ulong count = timer_read_counter();
+
+#if CONFIG_SYS_TIMER_RATE == 1000000
+	return count;
+#elif CONFIG_SYS_TIMER_RATE > 1000000
+	return lldiv(count, CONFIG_SYS_TIMER_RATE / 1000000);
+#elif defined(CONFIG_SYS_TIMER_RATE)
+	return (unsigned long long)count * 1000000 / CONFIG_SYS_TIMER_RATE;
+#else
+	/* Assume the counter is in microseconds */
+	return count;
+#endif
+}
+
 #else
 extern unsigned long __weak timer_read_counter(void);
 #endif
-- 
2.13.0.303.g4ebf302169-goog



More information about the U-Boot mailing list