diff options
author | Simon Glass <sjg@chromium.org> | 2012-06-27 17:06:14 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-06-28 17:06:46 -0700 |
commit | 6d048199300a5fee86cdda1fb6be912f6f471804 (patch) | |
tree | ba3b3949171958f1eb30642714423aebfb8169a8 /include/timer.h | |
parent | 7957516145f33531e82a74411df2e87d41a1b2a6 (diff) | |
download | chrome-ec-6d048199300a5fee86cdda1fb6be912f6f471804.tar.gz |
Add time_since32() to return microseconds since a start time
It is useful to implement timeouts like this:
start = get_time();
while (time_since32(start) < 1000)
...
Add a function to make this easy. Note that for efficiency we only
support a 32-bit return value which limits the timeouts to about an
hour.
BUG=chrome-os-partner:10888
TEST=manual:
build for all boards
boot on snow
Change-Id: I200cb04f5a76b4c76a9bc314d927e4bab1f08a56
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26289
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'include/timer.h')
-rw-r--r-- | include/timer.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/timer.h b/include/timer.h index ed076d5199..d3a4989e05 100644 --- a/include/timer.h +++ b/include/timer.h @@ -57,4 +57,21 @@ timestamp_t get_time(void); * may be called from interrupt level. */ void timer_print_info(void); +/** + * Returns the number of microseconds that have elapsed from a start time. + * + * This function is for timing short delays typically of a few milliseconds + * or so. + * + * Note that this is limited to a maximum of 32 bits, which is around an + * hour. After that, the value returned will wrap. + * + * @param start Start time to compare against + * @return number of microseconds that have elspsed since that start time + */ +static inline unsigned time_since32(timestamp_t start) +{ + return get_time().le.lo - start.le.lo; +} + #endif /* __CROS_EC_TIMER_H */ |