libpayload: Add a timeout function for getchar and getch
authorJordan Crouse <jordan.crouse@amd.com>
Tue, 8 Apr 2008 23:21:33 +0000 (23:21 +0000)
committerUwe Hermann <uwe@hermann-uwe.de>
Tue, 8 Apr 2008 23:21:33 +0000 (23:21 +0000)
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@amd.com>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3223 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1

payloads/libpayload/curses/keyboard.c
payloads/libpayload/curses/tinycurses.c
payloads/libpayload/include/libpayload.h
payloads/libpayload/libc/console.c

index 2062ac2ffed3682a41f379c49007943ee7be3857..8e9212ceda1d695963cc5e71ee19570d2d3ffcdf 100644 (file)
@@ -39,6 +39,8 @@
 
 #include "local.h"
 
+static int _halfdelay = 0;
+
 /* ============== Serial ==================== */
 
 /* FIXME:  Cook the serial correctly */
@@ -241,8 +243,13 @@ static int curses_getchar(int delay)
                                return cook_serial(c);
                        }
 
-                       if (!delay)
+                       if (delay == 0)
                                break;
+
+                       if (delay > 0) {
+                               mdelay(100);
+                               delay--;
+                       }
                }
 
                c = inb(0x60);
@@ -262,12 +269,33 @@ static int curses_getchar(int delay)
 
 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;
 }
 
index 5e707c47db893a7385f01066278e5c69d1c59ad4..6fcb43fcf8fd9d462ecd37d8665b69c91bc48883 100644 (file)
@@ -318,7 +318,6 @@ WINDOW *newwin(int num_lines, int num_columns, int begy, int begx)
        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) {}
index b74fbfeab237b594971f40c18991b4b8d39a20eb..388785dba19bfef5da93e2159f48f370c0be3bca 100644 (file)
@@ -94,6 +94,7 @@ int putchar(int c);
 int puts(const char *s);
 int havekey(void);
 int getchar(void);
+int getchar_timeout(int *ms);
 
 extern int last_putchar;
 
index b2b115b8358c534891a69a2957ebe92b6106ce1b..73e2644cd40cd428d3e153fcf8e8458b9e320c86 100644 (file)
@@ -101,3 +101,19 @@ int getchar(void)
 #endif
        }
 }
+
+int getchar_timeout(int *ms)
+{
+       while (*ms > 0) {
+               if (havekey())
+                       return getchar();
+
+               mdelay(100);
+               *ms -= 100;
+       }
+
+       if (*ms < 0)
+               *ms = 0;
+
+       return 0;
+}