diff options
author | Randall Spangler <rspangler@chromium.org> | 2013-08-01 14:36:43 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-08-02 17:32:26 -0700 |
commit | 889f7bdd3b77151dd5b749974c94a84ae8b2aeb8 (patch) | |
tree | 3973fd501c819b66d0504514fd7c6f2aada28b0e /include | |
parent | 078dfabb68be3573185bffdd79ef0f079002ee1e (diff) | |
download | chrome-ec-889f7bdd3b77151dd5b749974c94a84ae8b2aeb8.tar.gz |
Move input character processing from UART interrupt to console task
Previously, processing of arrow keys and control characters was done
in the interrupt handler itself. This increased the impact of UART
input on other interrupts and high-priority tasks. It also makes it
harder to implement DMA-based UART input on STM32L (in an imminent
CL), since the processing affected the circular UART input buffer
in-place.
This change turns uart_buffering.c back into a dumb I/O buffering
module, and puts all the command line editing and history support into
console.c.
Console history is done via a simple array of input lines instead of a
packed circular buffer of characters. This is a little less
RAM-efficient, but is easier to implement and read. History depth is
controlled via CONFIG_CONSOLE_HISTORY, and is 3 for STM32F and 8 for
other platforms. If we really need a greater history depth, we can
look into implementing a packed circular buffer again, but this time
at task time in console.c. Also added a 'history' command to print
the current console history.
BUG=chrome-os-partner:20485
BRANCH=none
TEST=console_edit unit test passes; 'history' command prints the last commands
Change-Id: I142a0be0d67718c58341e4569f4e2908f191d8b0
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/64363
Reviewed-by: Vic Yang <victoryang@chromium.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/config.h | 7 | ||||
-rw-r--r-- | include/uart.h | 26 |
2 files changed, 16 insertions, 17 deletions
diff --git a/include/config.h b/include/config.h index 4bfe375510..f86ab58a17 100644 --- a/include/config.h +++ b/include/config.h @@ -174,6 +174,13 @@ */ #define CONFIG_CONSOLE_CMDHELP +/* + * Number of entries in console history buffer. + * + * Boards may #undef this to reduce memory usage. + */ +#define CONFIG_CONSOLE_HISTORY 8 + /* Max length of a single line of input */ #define CONFIG_CONSOLE_INPUT_LINE_SIZE 80 diff --git a/include/uart.h b/include/uart.h index d4685cb2e7..05d4aee036 100644 --- a/include/uart.h +++ b/include/uart.h @@ -32,6 +32,14 @@ int uart_init_done(void); */ /** + * Put a single character to the UART, like putchar(). + * + * @param c Character to put + * @return EC_SUCCESS, or non-zero if output was truncated. + */ +int uart_putc(int c); + +/** * Put a null-terminated string to the UART, like fputs(). * * @return EC_SUCCESS, or non-zero if output was truncated. @@ -77,16 +85,6 @@ void uart_flush_output(void); void uart_flush_input(void); /** - * Non-destructively check for a character in the input buffer. - * - * @param c Character to search for - * - * @return the offset into the input buffer of the first match, or -1 if no - * match found in the input buffer. - */ -int uart_peek(int c); - -/** * Read a single character of input, similar to fgetc(). * * @return the character, or -1 if no input waiting. @@ -99,13 +97,7 @@ int uart_getc(void); * Reads input until one of the following conditions is met: * (1) <size-1> characters have been read. * (2) A newline ('\n') has been read. - * (3) The input buffer is empty. - * - * Condition (3) means this call never blocks. This is important - * because it prevents a race condition where the caller calls - * uart_peek() to see if input is waiting, or is notified by the - * callack that input is waiting, but then the input buffer overflows - * or someone else grabs the input before uart_gets() is called. + * (3) The input buffer is empty (this keeps the call from blocking). * * Characters are stored in <dest> and are null-terminated. * Characters include the newline if present, so that the caller can |