diff options
author | Matt Delco <delco@google.com> | 2019-03-05 16:38:28 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-03-20 19:51:14 -0700 |
commit | 45e420b83313d7217938737a6b7233d6c1097b90 (patch) | |
tree | 5e64f0ff1ed9fcb9e7a24365fa134242c44d5bbc /firmware | |
parent | 08bf680ff38c345928cf3907d6369d767c3df6ef (diff) | |
download | vboot-45e420b83313d7217938737a6b7233d6c1097b90.tar.gz |
firmware: add time unit conversion defines
This change adds some #defines to assist with converting
between microseconds (usec), milliseconds (msec) and full
seconds.
BUG=b:124358784
BRANCH=None
TEST=Local build and also ran "make runtests"
Change-Id: I0fd43ccb42bbd42f9ed319a29eb4015b48c879bb
Signed-off-by: Matt Delco <delco@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1504756
Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/include/vboot_api.h | 4 | ||||
-rw-r--r-- | firmware/lib/vboot_audio.c | 11 | ||||
-rw-r--r-- | firmware/stub/tpm_lite_stub.c | 4 | ||||
-rw-r--r-- | firmware/stub/vboot_api_stub_init.c | 2 |
4 files changed, 11 insertions, 10 deletions
diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h index 8dc3f962..9d8c8a0d 100644 --- a/firmware/include/vboot_api.h +++ b/firmware/include/vboot_api.h @@ -376,6 +376,10 @@ void VbExDebug(const char *format, ...) /*****************************************************************************/ /* Timer and delay (first two from utility.h) */ +#define VB_USEC_PER_MSEC 1000ULL +#define VB_MSEC_PER_SEC VB_USEC_PER_MSEC +#define VB_USEC_PER_SEC (VB_USEC_PER_MSEC * VB_MSEC_PER_SEC) + /** * Read a microsecond timer. * diff --git a/firmware/lib/vboot_audio.c b/firmware/lib/vboot_audio.c index 42a50798..e2a2655e 100644 --- a/firmware/lib/vboot_audio.c +++ b/firmware/lib/vboot_audio.c @@ -15,9 +15,6 @@ #include "vboot_audio.h" #include "vboot_common.h" -/* 1000 microsecond ticks per msec */ -#define TICKS_PER_MSEC 1000 - int audio_open_count = 0; /* Times audio has been opened */ static int audio_use_short; /* Use short delay? */ static uint64_t open_time; /* Time of last open */ @@ -55,15 +52,15 @@ int vb2_audio_looping(void) /* If we're using short delay, wait 2 seconds and don't beep */ if (audio_use_short) - return (now < 2000 * TICKS_PER_MSEC); + return (now < 2 * VB_USEC_PER_SEC); /* Otherwise, beep at 20 and 20.5 seconds */ - if ((beep_count == 0 && now > 20000 * TICKS_PER_MSEC) || - (beep_count == 1 && now > 20500 * TICKS_PER_MSEC)) { + if ((beep_count == 0 && now > 20000 * VB_MSEC_PER_SEC) || + (beep_count == 1 && now > 20500 * VB_MSEC_PER_SEC)) { VbExBeep(250, 400); beep_count++; } /* Stop after 30 seconds */ - return (now < 30000 * TICKS_PER_MSEC); + return (now < 30 * VB_USEC_PER_SEC); } diff --git a/firmware/stub/tpm_lite_stub.c b/firmware/stub/tpm_lite_stub.c index 647034e6..4eb0c528 100644 --- a/firmware/stub/tpm_lite_stub.c +++ b/firmware/stub/tpm_lite_stub.c @@ -271,8 +271,8 @@ VbError_t VbExTpmSendReceive(const uint8_t* request, uint32_t request_length, VB2_DEBUG("response (%d bytes):\n", *response_length); DbgPrintBytes(response, *response_length); VB2_DEBUG("execution time: %dms\n", - (int) ((after.tv_sec - before.tv_sec) * 1000 + - (after.tv_usec - before.tv_usec) / 1000)); + (int) ((after.tv_sec - before.tv_sec) * VB_MSEC_PER_SEC + + (after.tv_usec - before.tv_usec) / VB_USEC_PER_MSEC)); #endif #ifndef NDEBUG diff --git a/firmware/stub/vboot_api_stub_init.c b/firmware/stub/vboot_api_stub_init.c index e26390dc..aef9e8fb 100644 --- a/firmware/stub/vboot_api_stub_init.c +++ b/firmware/stub/vboot_api_stub_init.c @@ -56,7 +56,7 @@ uint64_t VbExGetTimer(void) { struct timeval tv; gettimeofday(&tv, NULL); - return (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec; + return (uint64_t)tv.tv_sec * VB_USEC_PER_SEC + (uint64_t)tv.tv_usec; } VbError_t test_mockable VbExNvStorageRead(uint8_t *buf) |