summaryrefslogtreecommitdiff
path: root/include/printf.h
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-06-06 12:16:11 -0700
committerGerrit <chrome-bot@google.com>2012-06-07 00:54:02 -0700
commitc7f2e0246e8129aa179b09c5042d0265266e3a17 (patch)
tree62a7e81c5119b9a8f09078dc85078a3396a005b8 /include/printf.h
parent3073c600786c6170cb3ff4d05ebc917f154c4ec1 (diff)
downloadchrome-ec-c7f2e0246e8129aa179b09c5042d0265266e3a17.tar.gz
Move printf() formatting to its own file to enable re-use
Also add snprintf(), and %X format code. BUG=chrome-os-partner:10206 TEST=timerinfo; should print correctly. 'ectool battery' on host side should print same serial as 'battery' on EC console. Change-Id: I5c9f69d1a20ee5d0a59440c122655adbf62c9aea Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/24635 Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Rong Chang <rongchang@chromium.org>
Diffstat (limited to 'include/printf.h')
-rw-r--r--include/printf.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/include/printf.h b/include/printf.h
new file mode 100644
index 0000000000..66e8d0c8b5
--- /dev/null
+++ b/include/printf.h
@@ -0,0 +1,47 @@
+/* Copyright (c) 2012 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.
+ */
+
+/* Printf-like functionality for Chrome EC */
+
+#ifndef __CROS_EC_PRINTF_H
+#define __CROS_EC_PRINTF_H
+
+#include <stdarg.h> /* For va_list */
+#include "common.h"
+
+/* SUPPORTED FORMAT CODES:
+ * char (%c)
+ * string (%s)
+ * native int (signed/unsigned) (%d / %u / %x / %X)
+ * int32_t / uint32_t (%d / %x / %X)
+ * int64_t / uint64_t (%ld / %lu / %lx / %lX)
+ * pointer (%p)
+ * And the following special format codes:
+ * current time in sec (%T) - interpreted as "%.6T" for fixed-point format
+ * including padding (%-5s, %8d, %08x, %016lx)
+ *
+ * Floating point output (%f / %g) is not supported, but there is a fixed-point
+ * extension for integers; a padding option of .N (where N is a number) will
+ * put a decimal before that many digits. For example, printing 123 with
+ * format code %.6d will result in "0.000123". This is most useful for
+ * printing times, voltages, and currents. */
+
+
+/* Print formatted output to a function, like vfprintf()
+ *
+ * addchar() will be called for every character to be printed, with the context
+ * pointer passed to vfnprintf(). addchar() should return 0 if the character
+ * was accepted or non-zero if the character was dropped due to overflow.
+ *
+ * Returns error if output was truncated. */
+int vfnprintf(int (*addchar)(void *context, int c), void *context,
+ const char *format, va_list args);
+
+
+/* Print formatted outut to a string */
+int snprintf(char *str, int size, const char *format, ...);
+
+
+#endif /* __CROS_EC_PRINTF_H */