Files
OpenCellular/include/printf.h
Randall Spangler c7f2e0246e 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>
2012-06-07 00:54:02 -07:00

48 lines
1.6 KiB
C

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