summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMyles Watson <mylesgw@chromium.org>2015-02-13 11:45:21 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-02-21 00:49:36 +0000
commitdb19a8e2c9a3c97be2ef1894cf113130592edba5 (patch)
tree6755d4c10e8542053dcbaff43596880542ded281
parenteb775b49b83e039a92fd67a9b8d6049d0f0cc70d (diff)
downloadchrome-ec-db19a8e2c9a3c97be2ef1894cf113130592edba5.tar.gz
common: Add the possibility to filter UART input
Add CONFIG_UART_INPUT_FILTER, which is undefined by default. BUG=chrome-os-partner:36745 TEST=buildall for the case where it is not defined. Added a filter function to the btle code on hadoken. Tested reset, transmit test, receive test, test end, and test mode end. BRANCH=None Signed-off-by: Myles Watson <mylesgw@chromium.org> Change-Id: I3a9c067ffcb114449b61f468271a48491a8c7ec5 Reviewed-on: https://chromium-review.googlesource.com/250580 Tested-by: Myles Watson <mylesgw@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Myles Watson <mylesgw@chromium.org>
-rw-r--r--common/uart_buffering.c10
-rw-r--r--include/config.h3
-rw-r--r--include/uart.h11
3 files changed, 24 insertions, 0 deletions
diff --git a/common/uart_buffering.c b/common/uart_buffering.c
index 6e93804e61..8037320340 100644
--- a/common/uart_buffering.c
+++ b/common/uart_buffering.c
@@ -157,6 +157,10 @@ void uart_process_input(void)
for (i = cur_head; i != rx_buf_head; i = RX_BUF_NEXT(i)) {
int c = rx_buf[i];
+#ifdef CONFIG_UART_INPUT_FILTER /* TODO(crosbug.com/p/36745): */
+#error "Filtering the UART input with DMA enabled is NOT SUPPORTED!"
+#endif
+
if (c == CTRL('S')) {
/* Software flow control - XOFF */
uart_suspended = 1;
@@ -197,6 +201,12 @@ void uart_process_input(void)
int c = uart_read_char();
int rx_buf_next = RX_BUF_NEXT(rx_buf_head);
+#ifdef CONFIG_UART_INPUT_FILTER
+ /* Intercept the input before it goes to the console */
+ if (uart_input_filter(c))
+ continue;
+#endif
+
if (c == CTRL('S')) {
/* Software flow control - XOFF */
uart_suspended = 1;
diff --git a/include/config.h b/include/config.h
index 18f2b45c89..5c6d17f99e 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1143,6 +1143,9 @@
/* UART index (number) for host UART, if present */
#undef CONFIG_UART_HOST
+/* Use uart_input_filter() to filter UART input. See prototype in uart.h */
+#undef CONFIG_UART_INPUT_FILTER
+
/*
* UART receive buffer size in bytes. Must be a power of 2 for macros in
* common/uart_buffering.c to work properly. Must be larger than
diff --git a/include/uart.h b/include/uart.h
index 2f0bc8bd8c..6128962726 100644
--- a/include/uart.h
+++ b/include/uart.h
@@ -227,6 +227,17 @@ void uart_deepsleep_interrupt(enum gpio_signal signal);
#define uart_deepsleep_interrupt NULL
#endif
+#ifdef CONFIG_UART_INPUT_FILTER
+/**
+ * Application-specific input filter, which takes the next input character as
+ * a parameter.
+ *
+ * Return 0 to allow the character to be handled by the console, non-zero if
+ * the character was handled by the filter.
+ */
+int uart_input_filter(int c);
+#endif
+
/*
* COMx functions
*/