summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@google.com>2020-04-30 16:31:29 -0600
committerCommit Bot <commit-bot@chromium.org>2020-05-04 20:27:48 +0000
commit9a6eba9f0f9206318bf711e9f8499ecd532c7077 (patch)
tree4b54e406110418e26bbecf146baeb69c4104094e
parent9655e231ebcb7c10152684c3e3b7021e0c52670c (diff)
downloadchrome-ec-9a6eba9f0f9206318bf711e9f8499ecd532c7077.tar.gz
tcpmv2: add debug level for TC state machine
BUG=none BRANCH=none TEST=verify default and changing debug level works Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I9e1b6485166641e2dd8e9680b0ae0125d84ec3e3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2175377 Tested-by: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Auto-Submit: Denis Brockus <dbrockus@chromium.org>
-rw-r--r--common/usbc/usb_pd_console.c1
-rw-r--r--common/usbc/usb_tc_drp_acc_trysrc_sm.c68
-rw-r--r--include/usb_sm.h7
-rw-r--r--include/usb_tc_sm.h7
4 files changed, 78 insertions, 5 deletions
diff --git a/common/usbc/usb_pd_console.c b/common/usbc/usb_pd_console.c
index 053374d874..70b51bbf1a 100644
--- a/common/usbc/usb_pd_console.c
+++ b/common/usbc/usb_pd_console.c
@@ -34,6 +34,7 @@ test_export_static int command_pd(int argc, char **argv)
prl_set_debug_level(level);
pe_set_debug_level(level);
+ tc_set_debug_level(level);
ccprintf("debug=%d\n", level);
return EC_SUCCESS;
}
diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
index 203f33f4e1..182307ee41 100644
--- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c
+++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
@@ -24,7 +24,6 @@
* USB Type-C DRP with Accessory and Try.SRC module
* See Figure 4-16 in Release 1.4 of USB Type-C Spec.
*/
-
#ifdef CONFIG_COMMON_RUNTIME
#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
@@ -33,6 +32,25 @@
#define CPRINTS(format, args...)
#endif
+#define CPRINTF_LX(x, format, args...) \
+ do { \
+ if (tc_debug_level >= x) \
+ CPRINTF(format, ## args); \
+ } while (0)
+#define CPRINTF_L1(format, args...) CPRINTF_LX(1, format, ## args)
+#define CPRINTF_L2(format, args...) CPRINTF_LX(2, format, ## args)
+#define CPRINTF_L3(format, args...) CPRINTF_LX(3, format, ## args)
+
+#define CPRINTS_LX(x, format, args...) \
+ do { \
+ if (tc_debug_level >= x) \
+ CPRINTS(format, ## args); \
+ } while (0)
+#define CPRINTS_L1(format, args...) CPRINTS_LX(1, format, ## args)
+#define CPRINTS_L2(format, args...) CPRINTS_LX(2, format, ## args)
+#define CPRINTS_L3(format, args...) CPRINTS_LX(3, format, ## args)
+
+
/* Type-C Layer Flags */
/* Flag to note we are sourcing VCONN */
#define TC_FLAGS_VCONN_ON BIT(0)
@@ -154,7 +172,21 @@ enum usb_tc_state {
/* Forward declare the full list of states. This is indexed by usb_tc_state */
static const struct usb_state tc_states[];
-#ifdef CONFIG_COMMON_RUNTIME
+/*
+ * We will use DEBUG LABELS if we will be able to print (COMMON RUNTIME)
+ * and either CONFIG_USB_PD_DEBUG_LEVEL is not defined (no override) or
+ * we are overriding and the level is not DISABLED.
+ *
+ * If we can't print or the CONFIG_USB_PD_DEBUG_LEVEL is defined to be 0
+ * then the DEBUG LABELS will be removed from the build.
+ */
+#if defined(CONFIG_COMMON_RUNTIME) && \
+ (!defined(CONFIG_USB_PD_DEBUG_LEVEL) || \
+ (CONFIG_USB_PD_DEBUG_LEVEL > 0))
+#define USB_PD_DEBUG_LABELS
+#endif
+
+#ifdef USB_PD_DEBUG_LABELS
/* List of human readable state names for console debugging */
static const char * const tc_state_names[] = {
[TC_DISABLED] = "Disabled",
@@ -184,6 +216,19 @@ static const char * const tc_state_names[] = {
[TC_CC_RD] = "SS:CC_RD",
[TC_CC_RP] = "SS:CC_RP",
};
+#else
+/*
+ * Reference so IS_ENABLED section below that references the names
+ * will compile and the optimizer will remove it.
+ */
+extern const char **tc_state_names;
+#endif
+
+/* Debug log level - higher number == more log */
+#ifdef CONFIG_USB_PD_DEBUG_LEVEL
+static const enum debug_level tc_debug_level = CONFIG_USB_PD_DEBUG_LEVEL;
+#else
+static enum debug_level tc_debug_level = DEBUG_LEVEL_1;
#endif
/* Generate a compiler error if invalid states are referenced */
@@ -509,7 +554,10 @@ static inline void pd_dev_dump_info(uint16_t dev_id, uint32_t *hash)
const char *tc_get_current_state(int port)
{
- return tc_state_names[get_state_tc(port)];
+ if (IS_ENABLED(USB_PD_DEBUG_LABELS))
+ return tc_state_names[get_state_tc(port)];
+ else
+ return "";
}
uint32_t tc_get_flags(int port)
@@ -815,7 +863,7 @@ bool pd_get_partner_unconstr_power(int port)
const char *pd_get_task_state_name(int port)
{
- return tc_state_names[get_state_tc(port)];
+ return tc_get_current_state(port);
}
void pd_vbus_low(int port)
@@ -1116,7 +1164,10 @@ static enum usb_tc_state get_last_state_tc(const int port)
static void print_current_state(const int port)
{
- CPRINTS("C%d: %s", port, tc_state_names[get_state_tc(port)]);
+ if (IS_ENABLED(USB_PD_DEBUG_LABELS))
+ CPRINTS_L1("C%d: %s", port, tc_state_names[get_state_tc(port)]);
+ else
+ CPRINTS("C%d: tc-st%d", port, get_state_tc(port));
}
static void handle_device_access(int port)
@@ -3198,6 +3249,13 @@ static void tc_cc_open_entry(const int port)
}
}
+void tc_set_debug_level(enum debug_level debug_level)
+{
+#ifndef CONFIG_USB_PD_DEBUG_LEVEL
+ tc_debug_level = debug_level;
+#endif
+}
+
void tc_run(const int port)
{
/*
diff --git a/include/usb_sm.h b/include/usb_sm.h
index ea17d55ab9..e4a08c38bf 100644
--- a/include/usb_sm.h
+++ b/include/usb_sm.h
@@ -49,6 +49,13 @@ enum sm_local_state {
/*
* A state machine can use these debug levels to regulate the amount of debug
* information printed on the EC console
+ *
+ * The states currently defined are
+ * Level 0: disabled
+ * Level 1: state names
+ *
+ * Note that higher log level causes timing changes and thus may affect
+ * performance.
*/
enum debug_level {
DEBUG_DISABLE,
diff --git a/include/usb_tc_sm.h b/include/usb_tc_sm.h
index a96ab05b1a..47f65d430a 100644
--- a/include/usb_tc_sm.h
+++ b/include/usb_tc_sm.h
@@ -306,6 +306,13 @@ void tc_event_check(int port, int evt);
void tc_run(const int port);
/**
+ * Sets the debug level for the TC layer
+ *
+ * @param level debug level
+ */
+void tc_set_debug_level(enum debug_level level);
+
+/**
* Start error recovery
*
* @param port USB-C port number