summaryrefslogtreecommitdiff
path: root/test/timer_calib.c
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2011-12-07 18:58:43 +0000
committerVincent Palatin <vpalatin@chromium.org>2011-12-07 19:10:02 +0000
commite24fa592d2a215d8ae67917c1d89e68cdf847a03 (patch)
tree47fbe4c55e7f4089cad7d619eded337da3bae999 /test/timer_calib.c
parent6396911897e4cd40f52636d710cee2865acf15e3 (diff)
downloadchrome-ec-e24fa592d2a215d8ae67917c1d89e68cdf847a03.tar.gz
Initial sources import 3/3
source files mainly done by Vincent. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> Change-Id: Ic2d1becd400c9b4b4a14d4a243af1bdf77d9c1e2
Diffstat (limited to 'test/timer_calib.c')
-rw-r--r--test/timer_calib.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/timer_calib.c b/test/timer_calib.c
new file mode 100644
index 0000000000..1169491c86
--- /dev/null
+++ b/test/timer_calib.c
@@ -0,0 +1,55 @@
+/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ * Copyright 2011 Google Inc.
+ *
+ * Tasks for scheduling test.
+ */
+
+#include "common.h"
+#include "uart.h"
+#include "task.h"
+#include "timer.h"
+
+uint32_t difftime(timestamp_t t0, timestamp_t t1)
+{
+ return (uint32_t)(t1.val-t0.val);
+}
+
+int timer_calib_task(void *data)
+{
+ timestamp_t t0, t1;
+ unsigned d;
+
+ uart_printf("\n=== Timer calibration ===\n");
+
+ t0 = get_time();
+ t1 = get_time();
+ uart_printf("- back-to-back get_time : %d us\n", difftime(t0, t1));
+
+ /* Sleep for 5 seconds */
+ uart_printf("- sleep 1s :\n ");
+ uart_flush_output();
+ uart_printf("Go...");
+ t0 = get_time();
+ usleep(1000000);
+ t1 = get_time();
+ uart_printf("done. delay = %d us\n", difftime(t0, t1));
+
+ /* try small usleep */
+ uart_printf("- short sleep :\n");
+ uart_flush_output();
+ for (d=128 ; d > 0; d = d / 2) {
+ t0 = get_time();
+ usleep(d);
+ t1 = get_time();
+ uart_printf(" %d us => %d us\n", d, difftime(t0, t1));
+ uart_flush_output();
+ }
+
+ uart_printf("Done.\n");
+ /* sleep forever */
+ task_wait_msg(-1);
+
+ return EC_SUCCESS;
+}