Commit Graph

9 Commits

Author SHA1 Message Date
Daisuke Nojiri
d3d6814b2d printf: Add sign ('+') flag
'+' flag can be used with signed integer type (%d) and causes positive
integers to be prefixed with '+' (e.g. +1745). This emphasizes output
values as a signed value. It can be mixed with left-justification flag
'-': %-+8d. It's ignored when used with unsigned integer or non-integer
types: %u, %x, %p, %s, %c, etc.

BUG=none
BRANCH=none
TEST=make buildall &&
int32_t d = 1745;
CPRINTS("'%-+8d'", -d);     /* '-1745    ' */
CPRINTS("'%-+8d'", d);      /* '+1745    ' */
CPRINTS("'%d'", d);         /* '1745' */
CPRINTS("'%+08d'", -d);     /* '000-1745' */
CPRINTS("'%+08d'", d);      /* '000+1745' */
CPRINTS("'%+d'", -d);       /* '-1745' */
CPRINTS("'%+d'", d);        /* '+1745' */
CPRINTS("'%+s'", "foo");    /* 'foo' */
CPRINTS("'%-+8s'", "foo");  /* 'foo     ' */
CPRINTS("'%+08x'", d);      /* '000006d1' */
CPRINTS("'%+u'", d);        /* '1745' */

Change-Id: I8dcd34b0cf03dbefc500b9c98fea235d85bde8d3
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/363924
2016-07-29 10:51:22 -07:00
Alec Berg
4c8553dfb1 stm32: add synchronous debug printf
Allow use of a synchronous debug printf instead of using the
full console task to save space. This can be turned on with
CONFIG_DEBUG_PRINTF, and will provide essentially a one-way
console for debugging. This is essentially expanding upon
the debug_printf work done for zinger.

BUG=chrome-os-partner:41959
BRANCH=none
TEST=tested with following CLs on glados_pd by verifying we
get a one-way console.

Change-Id: If028b5d873261890de5b270bbc00e06bdcaa7431
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/306782
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2015-10-19 13:45:49 -07:00
Vincent Palatin
686a23585e optimize printf size without the common runtime
When a platform is built without the common runtime to optimize for
flash size, remove the 64-bit support in printf to save more space
(mainly by getting rid of the uint64divmod helper).

This saves 376 bytes of flash on Zinger/MiniMuffin.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

BRANCH=none
BUG=none
TEST=make buildall and compare flash size with and without the change.
the common runtime binaries are identical excepted the version
information.

Change-Id: I1e7237e693df9ea23291c8c0fe414c3b5c716848
Reviewed-on: https://chromium-review.googlesource.com/265052
Trybot-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
2015-04-10 23:29:27 +00:00
Randall Spangler
6ab8e91658 cleanup: Remove checkpatch warnings
This make minor syntactic changes and renames some camel-cased symbols
to keep checkpatch from complaining.  The goal is to reduce the
temptation to use 'repo upload --no-verify'.

This is a big furball of find/replace, but no functional changes.

BUG=chromium:322144
BRANCH=none
TEST=build all boards; pass unit tests

Change-Id: I0269b7dd95836ef9a6e33f88c003ab0f24f842a0
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/180495
2013-12-19 00:12:28 +00:00
Randall Spangler
7f5019c9e3 Reduce stack space used by vfnprintf()
Converting some of the boolean variables in vfnprintf() to a single
flags word reduces stack usage by 8 bytes and function size by 12
bytes.  So it's slightly more efficient in both respects.

Confirmed size and stack usage improvements via 'make BOARD=rambi all
dis' and looking at the disassembly for vfnprintf()

BUG=chrome-os-partner:24148
BRANCH=none
TEST=Run taskinfo command twice and compare stack used by CONSOLE task.
     Run timerinfo and charger commands and verify output looks reasonable;
     those exercise binary and 64-bit number printing.

Change-Id: Ie4396bb0bc01dc155956fa2d8ca84c6630006729
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/177400
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2013-11-20 18:43:56 +00:00
Randall Spangler
e228692eb2 Clean up printf module
No functional changes.

BUG=chrome-os-partner:15579
BRANCH=none
TEST=boot system; debug output still shows up on EC console

Change-Id: I63f4f9481f5393aaff065b37a274236bd78622d9
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/36581
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2012-10-25 14:12:10 -07:00
Randall Spangler
7d06db201f Enhance printf()
1. Add precision to limit string length.
   ccprintf("%.4s", "foobar") prints "foob"

2. Handle '*' for length, precision fields.
   ccprintf("%.*s", 3, "foobar") prints "foo"

3. Add hex-dump code "%h"
   ccprintf("%.*s", 4, "foobar") prints 666f6f62

BUG=none
TEST=at ec console, 'hash' prints the current hash

Change-Id: I568310f2727495b021081bf58df2a0bbb3c74e73
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28704
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2012-07-30 13:41:33 -07:00
Randall Spangler
8fcfec5f7f Fix printing hex numbers
Off-by-one is not my friend.

BUG=chrome-os-partner:10206
TEST=manual

1. rw 0x20000000
2. ww back the same number printed
3. rw 0x20000000.  should match

Signed-off-by: Randall Spangler <rspangler@chromium.org>
Change-Id: I61e0d26cf4cb274a88326d4e7d24ff1c82d6e515
Reviewed-on: https://gerrit.chromium.org/gerrit/24756
Reviewed-by: Simon Glass <sjg@chromium.org>
2012-06-07 14:33:26 -07:00
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