summaryrefslogtreecommitdiff
path: root/payloads/libpayload
diff options
context:
space:
mode:
Diffstat (limited to 'payloads/libpayload')
-rw-r--r--payloads/libpayload/include/libpayload.h1
-rw-r--r--payloads/libpayload/libc/time.c17
2 files changed, 18 insertions, 0 deletions
diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h
index 3e48650ec1..b36b40cb7d 100644
--- a/payloads/libpayload/include/libpayload.h
+++ b/payloads/libpayload/include/libpayload.h
@@ -423,6 +423,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 ec1c85ce8c..0d8163495b 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;
+}