add console buffering
This commit is contained in:
parent
4d17340dc1
commit
a3110c5f8f
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue