diff options
-rw-r--r-- | common/console_output.c | 19 | ||||
-rw-r--r-- | include/console.h | 17 |
2 files changed, 27 insertions, 9 deletions
diff --git a/common/console_output.c b/common/console_output.c index 237c45cba6..aa7a558bf7 100644 --- a/common/console_output.c +++ b/common/console_output.c @@ -63,6 +63,13 @@ void console_channel_disable(const char *name) if (index >= 0 && index != CC_COMMAND) channel_mask &= ~CC_MASK(index); } + +bool console_channel_is_disabled(enum console_channel channel) +{ + if (!(CC_MASK(channel) & channel_mask)) + return true; + return false; +} #endif /* CONFIG_CONSOLE_CHANNEL */ /*****************************************************************************/ @@ -72,11 +79,9 @@ int cputs(enum console_channel channel, const char *outstr) { int rv1, rv2; -#ifdef CONFIG_CONSOLE_CHANNEL /* Filter out inactive channels */ - if (!(CC_MASK(channel) & channel_mask)) + if (console_channel_is_disabled(channel)) return EC_SUCCESS; -#endif rv1 = usb_puts(outstr); rv2 = uart_puts(outstr); @@ -89,11 +94,9 @@ int cprintf(enum console_channel channel, const char *format, ...) int rv1, rv2; va_list args; -#ifdef CONFIG_CONSOLE_CHANNEL /* Filter out inactive channels */ - if (!(CC_MASK(channel) & channel_mask)) + if (console_channel_is_disabled(channel)) return EC_SUCCESS; -#endif usb_va_start(args, format); rv1 = usb_vprintf(format, args); @@ -111,11 +114,9 @@ int cprints(enum console_channel channel, const char *format, ...) int r, rv; va_list args; -#ifdef CONFIG_CONSOLE_CHANNEL /* Filter out inactive channels */ - if (!(CC_MASK(channel) & channel_mask)) + if (console_channel_is_disabled(channel)) return EC_SUCCESS; -#endif rv = cprintf(channel, "[%pT ", PRINTF_TIMESTAMP_NOW); diff --git a/include/console.h b/include/console.h index 91800103b6..5bb1f2541f 100644 --- a/include/console.h +++ b/include/console.h @@ -10,6 +10,7 @@ #include "common.h" #include "config.h" +#include <stdbool.h> #ifdef CONFIG_ZEPHYR #include "zephyr_console_shim.h" @@ -137,6 +138,22 @@ void console_channel_enable(const char *name); void console_channel_disable(const char *name); /** + * Check if channel is disabled. + * + * @param channel Output channel + * + * @return true if channel is disabled, false if not. + */ +#ifdef CONFIG_CONSOLE_CHANNEL +bool console_channel_is_disabled(enum console_channel channel); +#else +static inline bool console_channel_is_disabled(enum console_channel channel) +{ + return false; +} +#endif + +/** * Put a string to the console channel. * * @param channel Output chanel |