|
|
@ -94,6 +94,14 @@ int console_peek(char *c, struct console *console_, int block) |
|
|
|
|
|
|
|
|
|
|
|
int console_getc(char *c, struct console *console_) |
|
|
|
int console_getc(char *c, struct console *console_) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
*c = fgetc(console_->read_fp); |
|
|
|
|
|
|
|
if (*c == EOF) { |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fprintf(stderr, "fgetc on %d gives %x\n", fileno(console_->read_fp), *c); |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
struct usart_console *console = container_of(console_, |
|
|
|
struct usart_console *console = container_of(console_, |
|
|
|
struct usart_console, console); |
|
|
|
struct usart_console, console); |
|
|
|
|
|
|
|
|
|
|
@ -106,6 +114,7 @@ int console_getc(char *c, struct console *console_) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
|
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int console_getline(struct console *console_, char *buf, size_t n) |
|
|
|
int console_getline(struct console *console_, char *buf, size_t n) |
|
|
@ -159,6 +168,8 @@ int console_getline(struct console *console_, char *buf, size_t n) |
|
|
|
|
|
|
|
|
|
|
|
ssize_t console_read(struct console *console, char *buf, size_t n) |
|
|
|
ssize_t console_read(struct console *console, char *buf, size_t n) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
return fread(buf, n, 1, console->read_fp); |
|
|
|
|
|
|
|
#if 0 |
|
|
|
char *p = buf; |
|
|
|
char *p = buf; |
|
|
|
char c; |
|
|
|
char c; |
|
|
|
|
|
|
|
|
|
|
@ -178,6 +189,7 @@ ssize_t console_read(struct console *console, char *buf, size_t n) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return p - buf; |
|
|
|
return p - buf; |
|
|
|
|
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static ssize_t usart_write(void *cookie, const char *buf, size_t n) |
|
|
|
static ssize_t usart_write(void *cookie, const char *buf, size_t n) |
|
|
@ -236,14 +248,28 @@ static int usart_init(struct usart_console *console) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct console *console_init_fd(unsigned dev_id, FILE* rfd, FILE* wfd) { |
|
|
|
|
|
|
|
struct usart_console *console; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console = usart + dev_id; |
|
|
|
|
|
|
|
console->console.read_fp = rfd; |
|
|
|
|
|
|
|
console->console.fp = wfd; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setvbuf(console->console.fp, NULL, _IONBF, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return &console->console; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct console *console_init(unsigned dev_id) |
|
|
|
struct console *console_init(unsigned dev_id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
#if 0 |
|
|
|
cookie_io_functions_t fops = { |
|
|
|
cookie_io_functions_t fops = { |
|
|
|
.read = NULL, |
|
|
|
.read = NULL, |
|
|
|
.write = usart_write, |
|
|
|
.write = usart_write, |
|
|
|
.seek = NULL, |
|
|
|
.seek = NULL, |
|
|
|
.close = NULL, |
|
|
|
.close = NULL, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
#endif |
|
|
|
struct usart_console *console; |
|
|
|
struct usart_console *console; |
|
|
|
|
|
|
|
|
|
|
|
console = usart + dev_id; |
|
|
|
console = usart + dev_id; |
|
|
@ -261,8 +287,10 @@ struct console *console_init(unsigned dev_id) |
|
|
|
|
|
|
|
|
|
|
|
usart_init(console); |
|
|
|
usart_init(console); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
console->console.fp = fopencookie(console, "w", fops); |
|
|
|
console->console.fp = fopencookie(console, "w", fops); |
|
|
|
setvbuf(console->console.fp, NULL, _IONBF, 0); |
|
|
|
setvbuf(console->console.fp, NULL, _IONBF, 0); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
return &console->console; |
|
|
|
return &console->console; |
|
|
|
} |
|
|
|
} |
|
|
|