]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
timer: Allow delays with a 32-bit microsecond timer
authorSimon Glass <sjg@chromium.org>
Fri, 10 Jul 2020 00:43:14 +0000 (18:43 -0600)
committerBin Meng <bmeng.cn@gmail.com>
Fri, 17 Jul 2020 06:32:24 +0000 (14:32 +0800)
The current get_timer_us() uses 64-bit arithmetic on 32-bit machines.
When implementing microsecond-level timeouts, 32-bits is plenty. Add a
new function that uses an unsigned long. On 64-bit machines this is
still 64-bit, but this doesn't introduce a penalty. On 32-bit machines
it is more efficient.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
include/time.h
lib/time.c

index e99f9c8012701e7f0b62a37c0c71c12d2f4b8f87..3f00e68713583e12a03adbcfefff84af7815c45a 100644 (file)
@@ -17,6 +17,17 @@ unsigned long get_timer(unsigned long base);
 unsigned long timer_get_us(void);
 uint64_t get_timer_us(uint64_t base);
 
+/**
+ * get_timer_us_long() - Get the number of elapsed microseconds
+ *
+ * This uses 32-bit arithmetic on 32-bit machines, which is enough to handle
+ * delays of over an hour. For 64-bit machines it uses a 64-bit value.
+ *
+ *@base: Base time to consider
+ *@return elapsed time since @base
+ */
+unsigned long get_timer_us_long(unsigned long base);
+
 /*
  * timer_test_add_offset()
  *
index 65db0f6cda29367c6f4b2eee1666a18a3d578100..47f8c84327d8829a923abd32e4892ca5ffc39a74 100644 (file)
@@ -152,6 +152,11 @@ uint64_t __weak get_timer_us(uint64_t base)
        return tick_to_time_us(get_ticks()) - base;
 }
 
+unsigned long __weak get_timer_us_long(unsigned long base)
+{
+       return timer_get_us() - base;
+}
+
 unsigned long __weak notrace timer_get_us(void)
 {
        return tick_to_time(get_ticks() * 1000);