summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Delco <delco@google.com>2019-03-05 16:38:28 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-20 19:51:14 -0700
commit45e420b83313d7217938737a6b7233d6c1097b90 (patch)
tree5e64f0ff1ed9fcb9e7a24365fa134242c44d5bbc
parent08bf680ff38c345928cf3907d6369d767c3df6ef (diff)
downloadvboot-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>
-rw-r--r--firmware/include/vboot_api.h4
-rw-r--r--firmware/lib/vboot_audio.c11
-rw-r--r--firmware/stub/tpm_lite_stub.c4
-rw-r--r--firmware/stub/vboot_api_stub_init.c2
-rw-r--r--tests/vboot_api_devmode_tests.c5
5 files changed, 13 insertions, 13 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)
diff --git a/tests/vboot_api_devmode_tests.c b/tests/vboot_api_devmode_tests.c
index 8aaa4b10..73e938ad 100644
--- a/tests/vboot_api_devmode_tests.c
+++ b/tests/vboot_api_devmode_tests.c
@@ -29,7 +29,6 @@
/* Expected results */
#define MAX_NOTE_EVENTS 10
-#define TICKS_PER_MSEC 1000ULL
#define TIME_FUZZ 500
#define KBD_READ_TIME 60
@@ -206,8 +205,8 @@ uint32_t VbExKeyboardRead(void)
void VbExSleepMs(uint32_t msec)
{
- current_ticks += (uint64_t)msec * TICKS_PER_MSEC;
- current_time = current_ticks / TICKS_PER_MSEC;
+ current_ticks += (uint64_t)msec * VB_USEC_PER_MSEC;
+ current_time = current_ticks / VB_USEC_PER_MSEC;
VB2_DEBUG("VbExSleepMs(%d) -> %d\n", msec, current_time);
}