Browse Source

bootstage: Define an optional microsecond timer

Define timer_get_boot_us() which returns the number of microseconds
since boot. If undefined then we use get_timer() * 1000.

We can fit this in a 32-bit register which keeps everyone happy on
the efficiency side. It will wrap around after about an hour. If we
are still looking at it after an hour then we had better not be
timing the boot.

Signed-off-by: Simon Glass <sjg@chromium.org>
Simon Glass 12 years ago
parent
commit
5ff55390ed
2 changed files with 24 additions and 0 deletions
  1. 7 0
      include/common.h
  2. 17 0
      lib/time.c

+ 7 - 0
include/common.h

@@ -206,6 +206,13 @@ typedef void (interrupt_handler_t)(void *);
 
 #endif /* CONFIG_SERIAL_MULTI */
 
+/*
+ * Return the time since boot in microseconds, This is needed for bootstage
+ * and should be defined in CPU- or board-specific code. If undefined then
+ * millisecond resolution will be used (the standard get_timer()).
+ */
+ulong timer_get_boot_us(void);
+
 /*
  * General Purpose Utilities
  */

+ 17 - 0
lib/time.c

@@ -47,3 +47,20 @@ void mdelay(unsigned long msec)
 	while (msec--)
 		udelay(1000);
 }
+
+ulong __timer_get_boot_us(void)
+{
+	static ulong base_time;
+
+	/*
+	 * We can't implement this properly. Return 0 on the first call and
+	 * larger values after that.
+	 */
+	if (base_time)
+		return get_timer(base_time) * 1000;
+	base_time = get_timer(0);
+	return 0;
+}
+
+ulong timer_get_boot_us(void)
+	__attribute__((weak, alias("__timer_get_boot_us")));