summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/cr50/rdd.c2
-rw-r--r--board/twinkie/simpletrace.c11
-rw-r--r--board/zinger/usb_pd_policy.c3
-rw-r--r--common/acpi.c3
-rw-r--r--common/battery.c2
-rw-r--r--common/capsense.c3
-rw-r--r--common/console_output.c2
-rw-r--r--common/host_command.c2
-rw-r--r--common/keyboard_scan.c4
-rw-r--r--common/lb_common.c2
-rw-r--r--common/motion_sense.c3
-rw-r--r--common/port80.c3
-rw-r--r--common/printf.c43
-rw-r--r--driver/accel_lis2dw12.c6
-rw-r--r--driver/accelgyro_lsm6dsm.c3
-rw-r--r--include/console.h4
-rw-r--r--include/printf.h5
17 files changed, 66 insertions, 35 deletions
diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c
index f25dc89798..2d1403ec02 100644
--- a/board/cr50/rdd.c
+++ b/board/cr50/rdd.c
@@ -304,7 +304,7 @@ static void ccd_state_change_hook(void)
if (flags_now == flags_want)
return;
- CPRINTF("[%T CCD state:");
+ CPRINTF("[%pT CCD state:", PRINTF_TIMESTAMP_NOW);
print_state_flags(CC_USB, flags_want);
CPRINTF("]\n");
diff --git a/board/twinkie/simpletrace.c b/board/twinkie/simpletrace.c
index 750d5f67c7..f68a09adcf 100644
--- a/board/twinkie/simpletrace.c
+++ b/board/twinkie/simpletrace.c
@@ -111,7 +111,7 @@ static void print_packet(int head, uint32_t *payload)
const char *prole;
if (trace_mode == TRACE_MODE_RAW) {
- ccprintf("%T[%04x]", head);
+ ccprintf("%pT[%04x]", PRINTF_TIMESTAMP_NOW, head);
for (i = 0; i < cnt; i++)
ccprintf(" %08x", payload[i]);
ccputs("\n");
@@ -119,7 +119,8 @@ static void print_packet(int head, uint32_t *payload)
}
name = cnt ? data_msg_name[typ] : ctrl_msg_name[typ];
prole = head & (PD_ROLE_SOURCE << 8) ? "SRC" : "SNK";
- ccprintf("%T %s/%d [%04x]%s", prole, id, head, name);
+ ccprintf("%pT %s/%d [%04x]%s",
+ PRINTF_TIMESTAMP_NOW, prole, id, head, name);
if (!cnt) { /* Control message : we are done */
ccputs("\n");
return;
@@ -150,11 +151,11 @@ static void print_packet(int head, uint32_t *payload)
static void print_error(enum pd_rx_errors err)
{
if (err == PD_RX_ERR_INVAL)
- ccprintf("%T TMOUT\n");
+ ccprintf("%pT TMOUT\n", PRINTF_TIMESTAMP_NOW);
else if (err == PD_RX_ERR_HARD_RESET)
- ccprintf("%T HARD-RST\n");
+ ccprintf("%pT HARD-RST\n", PRINTF_TIMESTAMP_NOW);
else if (err == PD_RX_ERR_UNSUPPORTED_SOP)
- ccprintf("%T SOP*\n");
+ ccprintf("%pT SOP*\n", PRINTF_TIMESTAMP_NOW);
else
ccprintf("ERR %d\n", err);
}
diff --git a/board/zinger/usb_pd_policy.c b/board/zinger/usb_pd_policy.c
index c5b2694989..52a87c285b 100644
--- a/board/zinger/usb_pd_policy.c
+++ b/board/zinger/usb_pd_policy.c
@@ -533,7 +533,8 @@ int pd_custom_vdm(int port, int cnt, uint32_t *payload,
if (PD_VDO_VID(payload[0]) != USB_VID_GOOGLE || !gfu_mode)
return 0;
- debug_printf("%T] VDM/%d [%d] %08x\n", cnt, cmd, payload[0]);
+ debug_printf("%pT] VDM/%d [%d] %08x\n",
+ PRINTF_TIMESTAMP_NOW, cnt, cmd, payload[0]);
*rpayload = payload;
rsize = pd_custom_flash_vdm(port, cnt, payload);
diff --git a/common/acpi.c b/common/acpi.c
index 68134a86e0..87e9c4fd27 100644
--- a/common/acpi.c
+++ b/common/acpi.c
@@ -313,7 +313,8 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
* does a lot of keyboard backlights and it scrolls the
* debug console.
*/
- CPRINTF("\r[%T ACPI kblight %d]", data);
+ CPRINTF("\r[%pT ACPI kblight %d]",
+ PRINTF_TIMESTAMP_NOW, data);
kblight_set(data);
break;
#endif
diff --git a/common/battery.c b/common/battery.c
index 7b6c3ee5bd..67d08b4150 100644
--- a/common/battery.c
+++ b/common/battery.c
@@ -350,7 +350,7 @@ DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cutoff,
static void check_pending_cutoff(void)
{
if (battery_cutoff_state == BATTERY_CUTOFF_STATE_PENDING) {
- CPRINTF("[%T Cutting off battery in %d second(s)]\n",
+ CPRINTS("Cutting off battery in %d second(s)",
CONFIG_BATTERY_CUTOFF_DELAY_US / SECOND);
hook_call_deferred(&pending_cutoff_deferred_data,
CONFIG_BATTERY_CUTOFF_DELAY_US);
diff --git a/common/capsense.c b/common/capsense.c
index 30ce34ebce..b2413ac61f 100644
--- a/common/capsense.c
+++ b/common/capsense.c
@@ -52,7 +52,8 @@ static void capsense_change_deferred(void)
new_val = capsense_read_bitmask();
if (new_val != cur_val) {
- CPRINTF("[%T capsense 0x%02x: ", new_val);
+ CPRINTF("[%pT capsense 0x%02x: ",
+ PRINTF_TIMESTAMP_NOW, new_val);
for (i = 0; i < CAPSENSE_MASK_BITS; i++) {
/* See what changed */
n = (new_val >> i) & 0x01;
diff --git a/common/console_output.c b/common/console_output.c
index b184ffd2be..86072d9b62 100644
--- a/common/console_output.c
+++ b/common/console_output.c
@@ -89,7 +89,7 @@ int cprints(enum console_channel channel, const char *format, ...)
return EC_SUCCESS;
#endif
- rv = cprintf(channel, "[%T ");
+ rv = cprintf(channel, "[%pT ", PRINTF_TIMESTAMP_NOW);
va_start(args, format);
r = uart_vprintf(format, args);
diff --git a/common/host_command.c b/common/host_command.c
index 9e14156c6e..be178f7b6c 100644
--- a/common/host_command.c
+++ b/common/host_command.c
@@ -604,7 +604,7 @@ static void dump_host_command_suppressed(int force)
if (!force && !timestamp_expired(suppressed_cmd_deadline, NULL))
return;
- CPRINTF("[%T HC Suppressed:");
+ CPRINTF("[%pT HC Suppressed:", PRINTF_TIMESTAMP_NOW);
for (i = 0; i < ARRAY_SIZE(hc_suppressed_cmd); i++) {
CPRINTF(" 0x%x=%d", hc_suppressed_cmd[i], hc_suppressed_cnt[i]);
hc_suppressed_cnt[i] = 0;
diff --git a/common/keyboard_scan.c b/common/keyboard_scan.c
index b4dd719784..7f7d44ceec 100644
--- a/common/keyboard_scan.c
+++ b/common/keyboard_scan.c
@@ -151,7 +151,7 @@ static void print_state(const uint8_t *state, const char *msg)
{
int c;
- CPRINTF("[%T KB %s:", msg);
+ CPRINTF("[%pT KB %s:", PRINTF_TIMESTAMP_NOW, msg);
for (c = 0; c < keyboard_cols; c++) {
if (state[c])
CPRINTF(" %02x", state[c]);
@@ -529,7 +529,7 @@ static int check_keys_changed(uint8_t *state)
#ifdef CONFIG_KEYBOARD_PRINT_SCAN_TIMES
/* Print delta times from now back to each previous scan */
- CPRINTF("[%T kb deltaT");
+ CPRINTF("[%pT kb deltaT", PRINTF_TIMESTAMP_NOW);
for (i = 0; i < SCAN_TIME_COUNT; i++) {
int tnew = scan_time[
(SCAN_TIME_COUNT + scan_time_index - i) %
diff --git a/common/lb_common.c b/common/lb_common.c
index 93f01389b4..08783997fa 100644
--- a/common/lb_common.c
+++ b/common/lb_common.c
@@ -288,7 +288,7 @@ void lb_init(int use_lock)
{
int i;
- CPRINTF("[%T LB_init_vals ");
+ CPRINTF("[%pT LB_init_vals ", PRINTF_TIMESTAMP_NOW);
for (i = 0; i < ARRAY_SIZE(init_vals); i++) {
CPRINTF("%c", '0' + i % 10);
if (use_lock)
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 7f34af1fc7..ef9cdef185 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -877,7 +877,8 @@ void motion_sense_task(void *u)
#endif
#ifdef CONFIG_CMD_ACCEL_INFO
if (accel_disp) {
- CPRINTF("[%T event 0x%08x ", event);
+ CPRINTF("[%pT event 0x%08x ",
+ PRINTF_TIMESTAMP_NOW, event);
for (i = 0; i < motion_sensor_count; ++i) {
sensor = &motion_sensors[i];
CPRINTF("%s=%-5d, %-5d, %-5d ", sensor->name,
diff --git a/common/port80.c b/common/port80.c
index 7bb708e964..52264cc446 100644
--- a/common/port80.c
+++ b/common/port80.c
@@ -53,7 +53,8 @@ void port_80_write(int data)
* coming from the host.
*/
if (print_in_int)
- CPRINTF("%c[%T Port 80: 0x%02x]", scroll ? '\n' : '\r', data);
+ CPRINTF("%c[%pT Port 80: 0x%02x]",
+ scroll ? '\n' : '\r', PRINTF_TIMESTAMP_NOW, data);
else if (data < 0x100)
hook_call_deferred(&port80_dump_buffer_data, 4 * SECOND);
diff --git a/common/printf.c b/common/printf.c
index f3b912b5c1..89ee004452 100644
--- a/common/printf.c
+++ b/common/printf.c
@@ -210,6 +210,8 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
v = va_arg(args, uint32_t);
#else /* NO_UINT64_SUPPORT */
uint64_t v;
+ int ptrspec;
+ void *ptrval;
/* Handle length */
if (c == 'l') {
@@ -217,16 +219,37 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
c = *format++;
}
- /* Special-case: %T = current time */
- if (c == 'T') {
- v = get_time().val;
- flags |= PF_64BIT;
-#ifdef CONFIG_CONSOLE_VERBOSE
- precision = 6;
-#else
- precision = 3;
- v /= 1000;
-#endif
+ if (c == 'p') {
+ ptrspec = *format++;
+ ptrval = va_arg(args, void *);
+ /* %pT - print a timestamp. */
+ if (ptrspec == 'T') {
+ flags |= PF_64BIT;
+ /* NULL uses the current time. */
+ if (ptrval == NULL)
+ v = get_time().val;
+ else
+ v = *(uint64_t *)ptrval;
+
+ if (IS_ENABLED(
+ CONFIG_CONSOLE_VERBOSE)) {
+ precision = 6;
+ } else {
+ precision = 3;
+ v /= 1000;
+ }
+
+ } else if (ptrspec == 'P') {
+ /* Print a raw pointer. */
+ v = (unsigned long)ptrval;
+ if (sizeof(unsigned long) ==
+ sizeof(uint64_t))
+ flags |= PF_64BIT;
+
+ } else {
+ return EC_ERROR_INVAL;
+ }
+
} else if (flags & PF_64BIT) {
v = va_arg(args, uint64_t);
} else {
diff --git a/driver/accel_lis2dw12.c b/driver/accel_lis2dw12.c
index a38e7e91c6..66edd8723e 100644
--- a/driver/accel_lis2dw12.c
+++ b/driver/accel_lis2dw12.c
@@ -18,6 +18,7 @@
#include "util.h"
#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args)
/* Only when configured as base accel sensor, fifo and interrupt
* are supported.
@@ -463,7 +464,7 @@ static int read(const struct motion_sensor_t *s, intv3_t v)
LIS2DW12_OUT_X_L_ADDR, raw,
OUT_XYZ_SIZE);
if (ret != EC_SUCCESS) {
- CPRINTF("[%T %s type:0x%X RD XYZ Error]", s->name, s->type);
+ CPRINTS("%s type:0x%X RD XYZ Error", s->name, s->type);
return ret;
}
@@ -559,8 +560,7 @@ static int init(const struct motion_sensor_t *s)
err_unlock:
mutex_unlock(s->mutex);
- CPRINTF("[%T %s: MS Init type:0x%X Error]\n", s->name, s->type);
-
+ CPRINTS("%s: MS Init type:0x%X Error", s->name, s->type);
return EC_ERROR_UNKNOWN;
}
diff --git a/driver/accelgyro_lsm6dsm.c b/driver/accelgyro_lsm6dsm.c
index 4fc8591ee1..4c6e90b13e 100644
--- a/driver/accelgyro_lsm6dsm.c
+++ b/driver/accelgyro_lsm6dsm.c
@@ -818,8 +818,7 @@ static int init(const struct motion_sensor_t *s)
err_unlock:
mutex_unlock(s->mutex);
- CPRINTF("[%T %s: MS Init type:0x%X Error]\n", s->name, s->type);
-
+ CPRINTS("%s: MS Init type:0x%X Error", s->name, s->type);
return ret;
}
diff --git a/include/console.h b/include/console.h
index e456ded7a6..73e9d9094c 100644
--- a/include/console.h
+++ b/include/console.h
@@ -10,6 +10,8 @@
#include "common.h"
+#define PRINTF_TIMESTAMP_NOW NULL
+
/* Console command; used by DECLARE_CONSOLE_COMMAND macro. */
struct console_command {
/* Command name. Case-insensitive. */
@@ -86,7 +88,7 @@ int cprintf(enum console_channel channel, const char *format, ...);
/**
* Print formatted output with timestamp. This is like:
- * cprintf(channel, "[%T " + format + "]\n", ...)
+ * cprintf(channel, "[%pT " + format + "]\n", PRINTF_TIMESTAMP_NOW, ...)
*
* @param channel Output channel
* @param format Format string; see printf.h for valid formatting codes
diff --git a/include/printf.h b/include/printf.h
index 6162e98bd2..c55c8f7d2b 100644
--- a/include/printf.h
+++ b/include/printf.h
@@ -52,8 +52,9 @@
* - 'b' - unsigned integer, print as binary
*
* Special format codes:
- * - "%T" - current time in seconds - interpreted as "%.6T" for precision.
- * This does NOT use up any arguments.
+ * - "%pT" - current time in seconds - interpreted as "%.6T" for precision.
+ * Supply PRINTF_TIMESTAMP_NOW to use the current time, or supply a
+ * pointer to a 64-bit timestamp to print.
*/
#ifndef HIDE_EC_STDLIB