[coreboot] r3223 - in trunk/payloads/libpayload: curses include libc
svn at coreboot.org
svn at coreboot.org
Wed Apr 9 01:21:34 CEST 2008
Author: uwe
Date: 2008-04-09 01:21:33 +0200 (Wed, 09 Apr 2008)
New Revision: 3223
Modified:
trunk/payloads/libpayload/curses/keyboard.c
trunk/payloads/libpayload/curses/tinycurses.c
trunk/payloads/libpayload/include/libpayload.h
trunk/payloads/libpayload/libc/console.c
Log:
libpayload: Add a timeout function for getchar and getch
Implement a timeout option for getchar() to return after so many
milliseconds. Also implement the same thing for curses using
the halfdelay() function.
Signed-off-by: Jordan Crouse <jordan.crouse at amd.com>
Acked-by: Uwe Hermann <uwe at hermann-uwe.de>
Modified: trunk/payloads/libpayload/curses/keyboard.c
===================================================================
--- trunk/payloads/libpayload/curses/keyboard.c 2008-04-07 23:33:50 UTC (rev 3222)
+++ trunk/payloads/libpayload/curses/keyboard.c 2008-04-08 23:21:33 UTC (rev 3223)
@@ -39,6 +39,8 @@
#include "local.h"
+static int _halfdelay = 0;
+
/* ============== Serial ==================== */
/* FIXME: Cook the serial correctly */
@@ -241,8 +243,13 @@
return cook_serial(c);
}
- if (!delay)
+ if (delay == 0)
break;
+
+ if (delay > 0) {
+ mdelay(100);
+ delay--;
+ }
}
c = inb(0x60);
@@ -262,15 +269,36 @@
int wgetch(WINDOW *win)
{
- return curses_getchar(win->_delay);
+ int delay = -1;
+
+ if (_halfdelay || win->_delay)
+ delay = win->_delay ? 0 : _halfdelay;
+
+ return curses_getchar(delay);
}
int nodelay(WINDOW *win, NCURSES_BOOL flag)
{
- win->_delay = flag ? 0 : -1;
+ win->_delay = flag ? 1 : 0;
return 0;
}
+int halfdelay(int tenths)
+{
+ if (tenths > 255)
+ return ERR;
+
+ _halfdelay = tenths;
+ return 0;
+}
+
+int nocbreak(void)
+{
+ /* Remove half delay timeout. */
+ _halfdelay = 0;
+ return 0;
+}
+
#ifdef CONFIG_VGA_CONSOLE
void curses_enable_vga(int state)
{
Modified: trunk/payloads/libpayload/curses/tinycurses.c
===================================================================
--- trunk/payloads/libpayload/curses/tinycurses.c 2008-04-07 23:33:50 UTC (rev 3222)
+++ trunk/payloads/libpayload/curses/tinycurses.c 2008-04-08 23:21:33 UTC (rev 3223)
@@ -318,7 +318,6 @@
return win;
}
/* D */ int nl(void) { SP->_nl = TRUE; return OK; }
-int nocbreak(void) { /* TODO */ return(*(int *)0); }
/* D */ int noecho(void) { SP->_echo = FALSE; return OK; }
/* D */ int nonl(void) { SP->_nl = FALSE; return OK; }
// void noqiflush (void) {}
Modified: trunk/payloads/libpayload/include/libpayload.h
===================================================================
--- trunk/payloads/libpayload/include/libpayload.h 2008-04-07 23:33:50 UTC (rev 3222)
+++ trunk/payloads/libpayload/include/libpayload.h 2008-04-08 23:21:33 UTC (rev 3223)
@@ -94,6 +94,7 @@
int puts(const char *s);
int havekey(void);
int getchar(void);
+int getchar_timeout(int *ms);
extern int last_putchar;
Modified: trunk/payloads/libpayload/libc/console.c
===================================================================
--- trunk/payloads/libpayload/libc/console.c 2008-04-07 23:33:50 UTC (rev 3222)
+++ trunk/payloads/libpayload/libc/console.c 2008-04-08 23:21:33 UTC (rev 3223)
@@ -101,3 +101,19 @@
#endif
}
}
+
+int getchar_timeout(int *ms)
+{
+ while (*ms > 0) {
+ if (havekey())
+ return getchar();
+
+ mdelay(100);
+ *ms -= 100;
+ }
+
+ if (*ms < 0)
+ *ms = 0;
+
+ return 0;
+}
More information about the coreboot
mailing list