diff options
author | Michael Brown | 2011-03-07 20:33:50 +0100 |
---|---|---|
committer | Michael Brown | 2011-03-07 20:37:30 +0100 |
commit | 9d633bdc7113f0050a0b35df5245dee2b819a273 (patch) | |
tree | 637c56a790d95598026387b05ed086dbc606470c /src/core/getkey.c | |
parent | [console] Avoid timer wraparound problems in getchar_timeout() (diff) | |
download | ipxe-9d633bdc7113f0050a0b35df5245dee2b819a273.tar.gz ipxe-9d633bdc7113f0050a0b35df5245dee2b819a273.tar.xz ipxe-9d633bdc7113f0050a0b35df5245dee2b819a273.zip |
[console] Add a timeout parameter to getkey()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/getkey.c')
-rw-r--r-- | src/core/getkey.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/core/getkey.c b/src/core/getkey.c index 5710f190..b8e6af78 100644 --- a/src/core/getkey.c +++ b/src/core/getkey.c @@ -35,13 +35,13 @@ FILE_LICENCE ( GPL2_OR_LATER ); /** * Read character from console if available within timeout period * - * @v timeout Timeout period, in ticks + * @v timeout Timeout period, in ticks (0=indefinite) * @ret character Character read from console */ -int getchar_timeout ( unsigned long timeout ) { +static int getchar_timeout ( unsigned long timeout ) { unsigned long start = currticks(); - while ( ( currticks() - start ) < timeout ) { + while ( ( timeout == 0 ) || ( ( currticks() - start ) < timeout ) ) { step(); if ( iskey() ) return getchar(); @@ -53,6 +53,7 @@ int getchar_timeout ( unsigned long timeout ) { /** * Get single keypress * + * @v timeout Timeout period, in ticks (0=indefinite) * @ret key Key pressed * * The returned key will be an ASCII value or a KEY_XXX special @@ -60,11 +61,11 @@ int getchar_timeout ( unsigned long timeout ) { * will return "special" keys (e.g. cursor keys) as a series of * characters forming an ANSI escape sequence. */ -int getkey ( void ) { +int getkey ( unsigned long timeout ) { int character; unsigned int n = 0; - character = getchar(); + character = getchar_timeout ( timeout ); if ( character != ESC ) return character; |