summaryrefslogtreecommitdiffstats
path: root/common/console.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2007-07-05 18:01:48 +0200
committerSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-07-05 18:01:48 +0200
commitaf347d05abb8b69fe846d09419a3e0abe1eeb1cd (patch)
tree212425b237eb095ee911894b5b79d8312373752c /common/console.c
parent31fc4bbff6f0e58bc3266833da7de4b2df9c7efd (diff)
downloadbarebox-af347d05abb8b69fe846d09419a3e0abe1eeb1cd.tar.gz
barebox-af347d05abb8b69fe846d09419a3e0abe1eeb1cd.tar.xz
svn_rev_380
add support for multipple consoles
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c109
1 files changed, 90 insertions, 19 deletions
diff --git a/common/console.c b/common/console.c
index 8882d4fc39..3fe737be28 100644
--- a/common/console.c
+++ b/common/console.c
@@ -28,42 +28,112 @@
#include <console.h>
#include <exports.h>
#include <serial.h>
+#include <driver.h>
+#include <fs.h>
-void serial_printf (const char *fmt, ...)
+static struct console_device *first_console;
+
+int console_register(struct console_device *newcdev)
{
- va_list args;
- uint i;
- char printbuffer[CFG_PBSIZE];
+ struct console_device *cdev = first_console;
+
+ if (!first_console) {
+ first_console = newcdev;
+ return 0;
+ }
+
+ while (1) {
+ if (!cdev->next) {
+ cdev->next = newcdev;
+ return 0;
+ }
+ cdev = cdev->next;
+ }
+}
- va_start (args, fmt);
+int getc (void)
+{
+ struct console_device *cdev = NULL;
+
+ while (1) {
+ if (!cdev)
+ cdev = first_console;
+ if (cdev->flags & CONSOLE_STDIN && !cdev->tstc(cdev))
+ return cdev->getc(cdev);
+ cdev = cdev->next;
+ }
+}
- /* For this to work, printbuffer must be larger than
- * anything we ever want to print.
- */
- i = vsprintf (printbuffer, fmt, args);
- va_end (args);
+int fgetc(int fd)
+{
+ char c;
- serial_puts (printbuffer);
+ if (!fd)
+ return getc();
+ return read(fd, &c, 1);
}
-int getc (void)
+int tstc (void)
{
- return serial_getc ();
+ struct console_device *cdev = first_console;
+
+ while (cdev) {
+ if (cdev->flags & CONSOLE_STDIN && cdev->tstc(cdev))
+ return 1;
+ cdev = cdev->next;
+ }
+
+ return 0;
}
-int tstc (void)
+void console_putc(unsigned int ch, char c)
{
- return serial_tstc ();
+ struct console_device *cdev = first_console;
+
+ while (cdev) {
+ if (cdev->flags & ch)
+ cdev->putc(cdev, c);
+ cdev = cdev->next;
+ }
}
-void putc (const char c)
+int fputc(int fd, char c)
{
- serial_putc (c);
+ if (fd == 1)
+ putc(c);
+ else if (fd == 2)
+ eputc(c);
+ else
+ return write(fd, &c, 1);
+ return 0;
}
-void puts (const char *s)
+void console_puts(unsigned int ch, const char *str)
{
- serial_puts (s);
+ struct console_device *cdev = first_console;
+
+ while (cdev) {
+ if (cdev->flags & ch) {
+ const char *s = str;
+ while (*s) {
+ cdev->putc(cdev, *s);
+ if (*s++ == '\n')
+ cdev->putc(cdev, '\r');
+ }
+ }
+ cdev = cdev->next;
+ }
+}
+
+int fputs(int fd, const char *s)
+{
+ if (fd == 1)
+ puts(s);
+ else if (fd == 2)
+ eputs(s);
+ else
+ return write(fd, s, strlen(s));
+ return 0;
}
void printf (const char *fmt, ...)
@@ -137,3 +207,4 @@ void clear_ctrlc (void)
{
ctrlc_was_pressed = 0;
}
+