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>
This commit is contained in:
Simon Glass
2012-06-27 17:06:14 -07:00
committed by Gerrit
parent 7957516145
commit 6d04819930

View File

@@ -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 */