diff options
author | Anton Staaf <robotboy@chromium.org> | 2014-07-23 14:06:47 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-09-18 02:59:24 +0000 |
commit | a6da62d284be2c7344f774b9c1da2274b85b3af2 (patch) | |
tree | b25cddc5767430bb3749783c3e5a9efce81f28c5 /chip/host | |
parent | eff864775f25f16480955ebde7234219c6e03948 (diff) | |
download | chrome-ec-a6da62d284be2c7344f774b9c1da2274b85b3af2.tar.gz |
Queue: Add functionality needed by new USART stream driver
Previously there was no way to remove multiple units at a time
from the queue, and the queue was wasting an entry to disambiguate
full from empty. There was also no way to get the free entry
count from the queue, only the ability to query if it was above
a required amount. The queue was also storing its constant
compile time configuration as well as its dynamic state in the
same structure. This wasted RAM on configuration information
that doesn't change.
This refactor fixes these issues, making the queue suitable for
use in the new USART stream driver.
Signed-off-by: Anton Staaf <robotboy@chromium.org>
BRANCH=None
BUG=None
TEST=make buildall -j
Change-Id: I284cee52d8189928dbc4c499f87ab34e14019e5a
Reviewed-on: https://chromium-review.googlesource.com/210533
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Tested-by: Anton Staaf <robotboy@chromium.org>
Diffstat (limited to 'chip/host')
-rw-r--r-- | chip/host/uart.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/chip/host/uart.c b/chip/host/uart.c index 3721ea9c78..afde763747 100644 --- a/chip/host/uart.c +++ b/chip/host/uart.c @@ -25,12 +25,8 @@ static pthread_t input_thread; #define INPUT_BUFFER_SIZE 16 static int char_available; -static char cached_char_buf[INPUT_BUFFER_SIZE]; -static struct queue cached_char = { - .buf_bytes = INPUT_BUFFER_SIZE, - .unit_bytes = sizeof(char), - .buf = cached_char_buf, -}; + +QUEUE_CONFIG(cached_char, INPUT_BUFFER_SIZE, char); #define CONSOLE_CAPTURE_SIZE 2048 static char capture_buf[CONSOLE_CAPTURE_SIZE]; @@ -149,7 +145,7 @@ void uart_inject_char(char *s, int sz) for (i = 0; i < sz; i += INPUT_BUFFER_SIZE - 1) { num_char = MIN(INPUT_BUFFER_SIZE - 1, sz - i); - if (!queue_has_space(&cached_char, num_char)) + if (queue_space(&cached_char) < num_char) return; queue_add_units(&cached_char, s + i, num_char); char_available = num_char; @@ -173,7 +169,7 @@ void *uart_monitor_stdin(void *d) while (1) { tcsetattr(0, TCSANOW, &new_settings); rv = read(0, buf, INPUT_BUFFER_SIZE); - if (queue_has_space(&cached_char, rv)) { + if (queue_space(&cached_char) >= rv) { queue_add_units(&cached_char, buf, rv); char_available = rv; } |