diff options
author | Sascha Hauer <sha@octopus.labnet.pengutronix.de> | 2007-09-21 21:30:59 +0200 |
---|---|---|
committer | Sascha Hauer <sha@octopus.labnet.pengutronix.de> | 2007-09-21 21:30:59 +0200 |
commit | a3110c5f8ff74da7a88ab450ca834c7a5cbfd4a7 (patch) | |
tree | 7ede6e7b0a36808ea6aebd3f56c866962eb78445 /common/console.c | |
parent | 4d17340dc13c8abd633303f5b3684e43b435a1e1 (diff) | |
download | barebox-a3110c5f8ff74da7a88ab450ca834c7a5cbfd4a7.tar.gz barebox-a3110c5f8ff74da7a88ab450ca834c7a5cbfd4a7.tar.xz |
add console buffering
Diffstat (limited to 'common/console.c')
-rw-r--r-- | common/console.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/common/console.c b/common/console.c index f359781e4d..5fbd41eff5 100644 --- a/common/console.c +++ b/common/console.c @@ -31,6 +31,8 @@ #include <fs.h> #include <reloc.h> #include <init.h> +#include <clock.h> +#include <kfifo.h> static struct console_device *first_console = NULL; @@ -132,7 +134,7 @@ int console_register(struct console_device *newcdev) } } -int getc (void) +int getc_raw(void) { struct console_device *cdev = NULL; while (1) { @@ -144,6 +146,36 @@ int getc (void) } } +static struct kfifo *console_buffer; + +int getc_buffer_flush(void) +{ + console_buffer = kfifo_alloc(1024); + return 0; +} + +postcore_initcall(getc_buffer_flush); + +int getc(void) +{ + unsigned char ch; + uint64_t start; + + start = get_time_ns(); + while (1) { + if (tstc()) { + kfifo_putc(console_buffer, getc_raw()); + + start = get_time_ns(); + } + if (is_timeout(start, 100 * USECOND) && kfifo_len(console_buffer)) + break; + } + + kfifo_getc(console_buffer, &ch); + return ch; +} + int fgetc(int fd) { char c; |