summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerrit <chrome-bot@google.com>2012-05-22 13:43:29 -0700
committerGerrit Code Review <gerrit@gerrit.golo.chromium.org>2012-05-22 13:43:29 -0700
commit10893940380d36da933e3ad69d2af147e3c194fb (patch)
tree0aded49f705c2c5019cd9c3f53971f8d39526be9
parent9ab7beb509382a7b2e881b29c077f4342cf2b3af (diff)
parent9b44097d2399e8305f9b64f6e66c85acd18744f9 (diff)
downloadchrome-ec-10893940380d36da933e3ad69d2af147e3c194fb.tar.gz
Merge "Add support for printing fixed-point numbers"
-rw-r--r--common/smart_battery.c4
-rw-r--r--common/uart_buffering.c22
-rw-r--r--core/cortex-m/task.c16
-rw-r--r--core/cortex-m/timer.c8
-rw-r--r--include/uart.h8
5 files changed, 41 insertions, 17 deletions
diff --git a/common/smart_battery.c b/common/smart_battery.c
index 5e6017f198..eaae395777 100644
--- a/common/smart_battery.c
+++ b/common/smart_battery.c
@@ -120,8 +120,8 @@ static int command_battery(int argc, char **argv)
if (rv)
return rv;
- ccprintf(" Temp: 0x%04x = %d x 0.1K (%d C)\n",
- d, d, (d-2731)/10);
+ ccprintf(" Temp: 0x%04x = %.1d K (%.1d C)\n",
+ d, d, d - 2731);
ccprintf(" Manuf: %s\n",
battery_manufacturer_name(text, sizeof(text)) == EC_SUCCESS ?
diff --git a/common/uart_buffering.c b/common/uart_buffering.c
index 5848a30f1d..0aa3c760b7 100644
--- a/common/uart_buffering.c
+++ b/common/uart_buffering.c
@@ -387,7 +387,7 @@ int uart_vprintf(const char *format, va_list args)
{
static const char int_chars[] = "0123456789abcdef";
static const char error_str[] = "ERROR";
- char intbuf[33];
+ char intbuf[34];
/* Longest uint64 in decimal = 20
* longest uint32 in binary = 32
*/
@@ -454,6 +454,18 @@ int uart_vprintf(const char *format, va_list args)
int is_negative = 0;
int is_64bit = 0;
int base = 10;
+ int fixed_point = 0;
+
+ /* Handle fixed point numbers */
+ if (c == '.') {
+ c = *format++;
+ if (c < '0' || c > '9') {
+ format = error_str;
+ continue;
+ }
+ fixed_point = c - '0';
+ c = *format++;
+ }
if (c == 'l') {
is_64bit = 1;
@@ -464,6 +476,7 @@ int uart_vprintf(const char *format, va_list args)
if (c == 'T') {
v = get_time().val;
is_64bit = 1;
+ fixed_point = 6;
} else if (is_64bit) {
v = va_arg(args, uint64_t);
} else {
@@ -507,6 +520,13 @@ int uart_vprintf(const char *format, va_list args)
vstr = intbuf + sizeof(intbuf) - 1;
*(vstr) = '\0';
+ /* Handle digits to right of decimal for fixed point
+ * numbers. */
+ for (vlen = 0; vlen < fixed_point; vlen++)
+ *(--vstr) = int_chars[uint64divmod(&v, 10)];
+ if (fixed_point)
+ *(--vstr) = '.';
+
if (!v)
*(--vstr) = '0';
diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c
index d69b607208..3041f431c8 100644
--- a/core/cortex-m/task.c
+++ b/core/cortex-m/task.c
@@ -492,11 +492,11 @@ void mutex_unlock(struct mutex *mtx)
void task_print_list(void)
{
int i;
- ccputs("Task Ready Name Events Time (us)\n");
+ ccputs("Task Ready Name Events Time (s)\n");
for (i = 0; i < TASK_ID_COUNT; i++) {
char is_ready = (tasks_ready & (1<<i)) ? 'R' : ' ';
- ccprintf("%4d %c %-16s %08x %10ld\n", i, is_ready,
+ ccprintf("%4d %c %-16s %08x %11.6ld\n", i, is_ready,
task_names[i], tasks[i].events, tasks[i].runtime);
if (in_interrupt_context())
uart_emergency_flush();
@@ -527,13 +527,13 @@ int command_task_info(int argc, char **argv)
total += irq_dist[i];
}
}
- ccprintf("Service calls: %10d\n", svc_calls);
- ccprintf("Total exceptions: %10d\n", total + svc_calls);
- ccprintf("Task switches: %10d\n", task_switches);
- ccprintf("Task switching started: %10ld us\n", task_start_time);
- ccprintf("Time in tasks: %10ld us\n",
+ ccprintf("Service calls: %11d\n", svc_calls);
+ ccprintf("Total exceptions: %11d\n", total + svc_calls);
+ ccprintf("Task switches: %11d\n", task_switches);
+ ccprintf("Task switching started: %11.6ld s\n", task_start_time);
+ ccprintf("Time in tasks: %11.6ld s\n",
get_time().val - task_start_time);
- ccprintf("Time in exceptions: %10ld us\n", exc_total_time);
+ ccprintf("Time in exceptions: %11.6ld s\n", exc_total_time);
#endif
return EC_SUCCESS;
diff --git a/core/cortex-m/timer.c b/core/cortex-m/timer.c
index be2d0d416c..2ea927d4be 100644
--- a/core/cortex-m/timer.c
+++ b/core/cortex-m/timer.c
@@ -170,14 +170,14 @@ void timer_print_info(void)
int tskid;
ccprintf("Time: 0x%016lx us\n"
- "Deadline: 0x%016lx -> %10ld us from now\n"
+ "Deadline: 0x%016lx -> %11.6ld s from now\n"
"Active timers:\n",
t, deadline, deadline - t);
for (tskid = 0; tskid < TASK_ID_COUNT; tskid++) {
if (timer_running & (1<<tskid)) {
- ccprintf(" Tsk %2d 0x%016lx -> %10ld %x\n", tskid,
+ ccprintf(" Tsk %2d 0x%016lx -> %11.6ld\n", tskid,
timer_deadline[tskid].val,
- timer_deadline[tskid].val - t, 0xabcd);
+ timer_deadline[tskid].val - t);
if (in_interrupt_context())
uart_emergency_flush();
else
@@ -202,7 +202,7 @@ DECLARE_CONSOLE_COMMAND(waitms, command_wait);
static int command_get_time(int argc, char **argv)
{
timestamp_t ts = get_time();
- ccprintf("Time: 0x%016lx = %ld us\n", ts.val, ts.val);
+ ccprintf("Time: 0x%016lx = %.6ld s\n", ts.val, ts.val);
return EC_SUCCESS;
}
diff --git a/include/uart.h b/include/uart.h
index 17922879bc..f71d151c76 100644
--- a/include/uart.h
+++ b/include/uart.h
@@ -50,10 +50,14 @@ int uart_puts(const char *outstr);
* int64_t / uint64_t (%ld / %lu / %lx)
* pointer (%p)
* And the following special format codes:
- * current time in us (%T)
+ * 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. */
+ * 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. */
int uart_printf(const char *format, ...);
/* Print formatted output to the UART, like vprintf(). Supports the same