summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2022-07-08 15:16:42 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-07-15 18:48:19 +0000
commit171fe207e672191cc9dbec722999e24d81798f16 (patch)
treec169a841daaaf6dddc605a1abc42a489a32e5c3e /common
parent8c001c5ab9b1216bfbc2b7f50f1f6fa95a225f7a (diff)
downloadchrome-ec-171fe207e672191cc9dbec722999e24d81798f16.tar.gz
tree: Replace %pT with snprintf_timestamp
Using standard format specifiers makes it easier to switch between the "builtin" EC standard library and the C standard library provided by the toolchain (or Zephyr). BRANCH=none BUG=b:238433667, b:234181908 TEST=On icetower v0.1 with servo_micro and J-Trace attached: > reboot observe console shows timestamps Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I6660ff22ebc6ba74f1245ff83026f5919b356a02 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3756178 Reviewed-by: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/acpi.c6
-rw-r--r--common/capsense.c6
-rw-r--r--common/console_output.c5
-rw-r--r--common/host_command.c5
-rw-r--r--common/keyboard_scan.c10
-rw-r--r--common/lb_common.c5
-rw-r--r--common/motion_sense.c7
-rw-r--r--common/port80.c11
-rw-r--r--common/printf.c25
9 files changed, 44 insertions, 36 deletions
diff --git a/common/acpi.c b/common/acpi.c
index ffb6acbc22..c6fe21f248 100644
--- a/common/acpi.c
+++ b/common/acpi.c
@@ -15,6 +15,7 @@
#include "host_command.h"
#include "keyboard_backlight.h"
#include "lpc.h"
+#include "printf.h"
#include "pwm.h"
#include "timer.h"
#include "tablet_mode.h"
@@ -315,13 +316,14 @@ int acpi_ap_to_ec(int is_cmd, uint8_t value, uint8_t *resultptr)
#endif
#ifdef CONFIG_KEYBOARD_BACKLIGHT
case EC_ACPI_MEM_KEYBOARD_BACKLIGHT:
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
/*
* Debug output with CR not newline, because the host
* does a lot of keyboard backlights and it scrolls the
* debug console.
*/
- CPRINTF("\r[%pT ACPI kblight %d]", PRINTF_TIMESTAMP_NOW,
- data);
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("\r[%s ACPI kblight %d]", ts_str, data);
kblight_set(data);
kblight_enable(data > 0);
break;
diff --git a/common/capsense.c b/common/capsense.c
index e5c3880e2a..ede5a05190 100644
--- a/common/capsense.c
+++ b/common/capsense.c
@@ -9,6 +9,7 @@
#include "hooks.h"
#include "i2c.h"
#include "keyboard_protocol.h"
+#include "printf.h"
#include "timer.h"
/* Console output macro */
@@ -48,11 +49,12 @@ static void capsense_change_deferred(void)
static uint8_t cur_val;
uint8_t new_val;
int i, n, c;
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
new_val = capsense_read_bitmask();
if (new_val != cur_val) {
- CPRINTF("[%pT capsense 0x%02x: ", PRINTF_TIMESTAMP_NOW,
- new_val);
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("[%s capsense 0x%02x: ", ts_str, 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 4cd45127c9..0471559838 100644
--- a/common/console_output.c
+++ b/common/console_output.c
@@ -6,6 +6,7 @@
/* Console output module for Chrome EC */
#include "console.h"
+#include "printf.h"
#include "uart.h"
#include "usb_console.h"
#include "util.h"
@@ -114,12 +115,14 @@ int cprints(enum console_channel channel, const char *format, ...)
{
int r, rv;
va_list args;
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
/* Filter out inactive channels */
if (console_channel_is_disabled(channel))
return EC_SUCCESS;
- rv = cprintf(channel, "[%pT ", PRINTF_TIMESTAMP_NOW);
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ rv = cprintf(channel, "[%s ", ts_str);
va_start(args, format);
r = uart_vprintf(format, args);
diff --git a/common/host_command.c b/common/host_command.c
index 775632c3bf..417a2f3465 100644
--- a/common/host_command.c
+++ b/common/host_command.c
@@ -12,6 +12,7 @@
#include "host_command.h"
#include "link_defs.h"
#include "lpc.h"
+#include "printf.h"
#include "shared_mem.h"
#include "system.h"
#include "task.h"
@@ -588,11 +589,13 @@ static void dump_host_command_suppressed(int force)
{
#ifdef CONFIG_SUPPRESSED_HOST_COMMANDS
int i;
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
if (!force && !timestamp_expired(suppressed_cmd_deadline, NULL))
return;
- CPRINTF("[%pT HC Suppressed:", PRINTF_TIMESTAMP_NOW);
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("[%s HC Suppressed:", ts_str);
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 b35a90ac16..d9f9e16417 100644
--- a/common/keyboard_scan.c
+++ b/common/keyboard_scan.c
@@ -19,6 +19,7 @@
#include "keyboard_scan.h"
#include "keyboard_test.h"
#include "lid_switch.h"
+#include "printf.h"
#include "switch.h"
#include "system.h"
#include "tablet_mode.h"
@@ -166,8 +167,10 @@ void keyboard_scan_enable(int enable, enum kb_scan_disable_masks mask)
static void print_state(const uint8_t *state, const char *msg)
{
int c;
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
- CPRINTF("[%pT KB %s:", PRINTF_TIMESTAMP_NOW, msg);
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("[%s KB %s:", ts_str, msg);
for (c = 0; c < keyboard_cols; c++) {
if (state[c])
CPRINTF(" %02x", state[c]);
@@ -647,7 +650,10 @@ 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("[%pT kb deltaT", PRINTF_TIMESTAMP_NOW);
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
+
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("[%s kb deltaT", ts_str);
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 7cdd0067dd..5d565bb77f 100644
--- a/common/lb_common.c
+++ b/common/lb_common.c
@@ -97,6 +97,7 @@
#include "ec_commands.h"
#include "i2c.h"
#include "lb_common.h"
+#include "printf.h"
#include "util.h"
/* Console output macros */
@@ -274,8 +275,10 @@ uint8_t lb_get_brightness(void)
void lb_init(int use_lock)
{
int i;
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
- CPRINTF("[%pT LB_init_vals ", PRINTF_TIMESTAMP_NOW);
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("[%s LB_init_vals ", ts_str);
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 776949b8aa..c47105a480 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -24,6 +24,7 @@
#include "motion_lid.h"
#include "motion_orientation.h"
#include "online_calibration.h"
+#include "printf.h"
#include "power.h"
#include "queue.h"
#include "tablet_mode.h"
@@ -933,8 +934,10 @@ void motion_sense_task(void *u)
}
}
if (IS_ENABLED(CONFIG_CMD_ACCEL_INFO) && (accel_disp)) {
- CPRINTF("[%pT event 0x%08x ", PRINTF_TIMESTAMP_NOW,
- event);
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
+
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("[%s event 0x%08x ", ts_str, 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 c7c9d714ff..66ad48be5e 100644
--- a/common/port80.c
+++ b/common/port80.c
@@ -11,6 +11,7 @@
#include "hooks.h"
#include "host_command.h"
#include "port80.h"
+#include "printf.h"
#include "task.h"
#include "timer.h"
#include "util.h"
@@ -39,6 +40,8 @@ DECLARE_DEFERRED(port80_dump_buffer);
void port_80_write(int data)
{
+ char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];
+
/*
* By default print_in_int is disabled if:
* 1. CONFIG_BRINGUP is not defined
@@ -53,9 +56,11 @@ void port_80_write(int data)
* dump the current port80 buffer to EC console. This is to allow
* developers to help debug BIOS progress by tracing port80 messages.
*/
- if (print_in_int)
- CPRINTF("%c[%pT Port 80: 0x%02x]", scroll ? '\n' : '\r',
- PRINTF_TIMESTAMP_NOW, data);
+ if (print_in_int) {
+ snprintf_timestamp_now(ts_str, sizeof(ts_str));
+ CPRINTF("%c[%s Port 80: 0x%02x]", scroll ? '\n' : '\r', ts_str,
+ data);
+ }
hook_call_deferred(&port80_dump_buffer_data, 4 * SECOND);
diff --git a/common/printf.c b/common/printf.c
index 01e9d0f544..b3e9d45109 100644
--- a/common/printf.c
+++ b/common/printf.c
@@ -394,30 +394,11 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
ptrval = va_arg(args, void *);
/*
* Avoid null pointer dereference for %ph.
- * %pT and %pP can accept null.
+ * %pP can accept null.
*/
- if (ptrval == NULL && ptrspec != 'T' &&
- ptrspec != 'P')
+ if (ptrval == NULL && ptrspec != 'P')
continue;
- /* %pT - print a timestamp. */
- if (ptrspec == 'T' &&
- (!IS_ENABLED(CONFIG_ZEPHYR) ||
- IS_ENABLED(CONFIG_PLATFORM_EC_TIMER))) {
- flags |= PF_64BIT;
- if (ptrval == PRINTF_TIMESTAMP_NOW)
- 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 == 'h') {
+ else if (ptrspec == 'h') {
/* %ph - Print a hex byte buffer. */
struct hex_buffer_params *hexbuf =
ptrval;