summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorPatrick Delaunay <patrick.delaunay@st.com>2020-12-18 12:46:46 +0100
committerTom Rini <trini@konsulko.com>2021-01-15 14:36:12 -0500
commita17b38ce3902e46777322f6ec26e51b25415fa5b (patch)
tree5c494121a18ba04d7eb8e98624e7ce558bafbfbe /common
parent1e993710e8b99510a37f91fa97d9b783c6e5f32d (diff)
downloadu-boot-a17b38ce3902e46777322f6ec26e51b25415fa5b.tar.gz
u-boot-a17b38ce3902e46777322f6ec26e51b25415fa5b.tar.xz
u-boot-a17b38ce3902e46777322f6ec26e51b25415fa5b.zip
console: add console_has_tstc helper function for CONSOLE_MUX
Add the helper function console_has_tstc() and replace the test #if CONFIG_IS_ENABLED(CONSOLE_MUX) to a simple 'if' test to respect the U-Boot coding rule. No functional change. Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/console.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/common/console.c b/common/console.c
index 295c10f242..e82b5d2075 100644
--- a/common/console.c
+++ b/common/console.c
@@ -231,6 +231,7 @@ static bool console_dev_is_serial(struct stdio_dev *sdev)
#if CONFIG_IS_ENABLED(CONSOLE_MUX)
/** Console I/O multiplexing *******************************************/
+/* tstcdev: save the last stdio device with pending characters, with tstc != 0 */
static struct stdio_dev *tstcdev;
struct stdio_dev **console_devices[MAX_FILES];
int cd_count[MAX_FILES];
@@ -256,6 +257,12 @@ static int console_getc(int file)
return ret;
}
+/* Upper layer may have already called tstc(): check the saved result */
+static bool console_has_tstc(void)
+{
+ return !!tstcdev;
+}
+
static int console_tstc(int file)
{
int i, ret;
@@ -348,6 +355,11 @@ static inline int console_getc(int file)
return stdio_devices[file]->getc(stdio_devices[file]);
}
+static bool console_has_tstc(void)
+{
+ return false;
+}
+
static inline int console_tstc(int file)
{
return stdio_devices[file]->tstc(stdio_devices[file]);
@@ -405,18 +417,19 @@ int fgetc(int file)
*/
for (;;) {
WATCHDOG_RESET();
-#if CONFIG_IS_ENABLED(CONSOLE_MUX)
- /*
- * Upper layer may have already called tstc() so
- * check for that first.
- */
- if (tstcdev != NULL)
- return console_getc(file);
- console_tstc(file);
-#else
- if (console_tstc(file))
- return console_getc(file);
-#endif
+ if (CONFIG_IS_ENABLED(CONSOLE_MUX)) {
+ /*
+ * Upper layer may have already called tstc() so
+ * check for that first.
+ */
+ if (console_has_tstc())
+ return console_getc(file);
+ console_tstc(file);
+ } else {
+ if (console_tstc(file))
+ return console_getc(file);
+ }
+
/*
* If the watchdog must be rate-limited then it should
* already be handled in board-specific code.