Isaac Christensen (isaac.christensen@se-eng.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6897
-gerrit
commit 95450457945f3b6713bb6f73353ebda7e7b4fe1d Author: Gabe Black gabeblack@google.com Date: Fri Dec 6 23:30:10 2013 -0800
libpayload: Add a timer_us() function.
This function returns the number of microseconds scaled from the number of raw timer ticks. It accepts a base parameter which is subtracted from the current time, which makes it easy to keep track of relative times.
Change-Id: I55f2f9e90c0e12cda430bbe88b044f12b0b563c8 Signed-off-by: Gabe Black gabeblack@google.com Reviewed-on: https://chromium-review.googlesource.com/179600 Reviewed-by: Ronald Minnich rminnich@chromium.org Commit-Queue: Gabe Black gabeblack@chromium.org Tested-by: Gabe Black gabeblack@chromium.org (cherry picked from commit 4dd549e18d170dbf918c5b4b11bbe1f4e99b6695) Signed-off-by: Isaac Christensen isaac.christensen@se-eng.com --- payloads/libpayload/include/libpayload.h | 1 + payloads/libpayload/libc/time.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h index 48a034b..15ffefb 100644 --- a/payloads/libpayload/include/libpayload.h +++ b/payloads/libpayload/include/libpayload.h @@ -422,6 +422,7 @@ int lib_get_sysinfo(void); unsigned int get_cpu_speed(void); uint64_t timer_hz(void); uint64_t timer_raw_value(void); +uint64_t timer_us(uint64_t base); /* Generic. */ void ndelay(unsigned int n); void udelay(unsigned int n); diff --git a/payloads/libpayload/libc/time.c b/payloads/libpayload/libc/time.c index ec1c85c..0d81634 100644 --- a/payloads/libpayload/libc/time.c +++ b/payloads/libpayload/libc/time.c @@ -189,3 +189,20 @@ void delay(unsigned int s) { _delay((uint64_t)s * timer_hz()); } + +u64 timer_us(u64 base) +{ + static u64 hz; + + // Only check timer_hz once. Assume it doesn't change. + if (hz == 0) { + hz = timer_hz(); + if (hz < 1000000) { + printf("Timer frequency %lld is too low, " + "must be at least 1MHz.\n", hz); + halt(); + } + } + + return timer_raw_value() / (hz / 1000000) - base; +}