summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorHeiko Schocher <hs@denx.de>2012-01-16 21:13:05 +0000
committerAlbert ARIBAUD <albert.u.boot@aribaud.net>2012-02-12 10:11:23 +0100
commit9c3483113de1204118a1b252bf4c81b899dd12b4 (patch)
tree5f7af1ceb46bd36f92f63076081174db1d84bb96 /common
parent2627c8c0a1bc64099cf6b6e2d978d666f88ef08d (diff)
downloadu-boot-9c3483113de1204118a1b252bf4c81b899dd12b4.tar.gz
common: add possibility for readline_into_buffer timeout
add possibility to add a timeout when reading a line into a buffer. Signed-off-by: Heiko Schocher <hs@denx.de> Cc: Mike Frysinger <vapier@gentoo.org> Acked-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'common')
-rw-r--r--common/cmd_nvedit.c2
-rw-r--r--common/main.c20
-rw-r--r--common/menu.c3
3 files changed, 19 insertions, 6 deletions
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 63afc82fe2..20080dc001 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -502,7 +502,7 @@ int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
else
buffer[0] = '\0';
- readline_into_buffer("edit: ", buffer);
+ readline_into_buffer("edit: ", buffer, 0);
return setenv(argv[1], buffer);
}
diff --git a/common/main.c b/common/main.c
index e96c95a038..248744ba74 100644
--- a/common/main.c
+++ b/common/main.c
@@ -685,7 +685,8 @@ static void cread_add_str(char *str, int strsize, int insert, unsigned long *num
}
}
-static int cread_line(const char *const prompt, char *buf, unsigned int *len)
+static int cread_line(const char *const prompt, char *buf, unsigned int *len,
+ int timeout)
{
unsigned long num = 0;
unsigned long eol_num = 0;
@@ -695,6 +696,7 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len)
int esc_len = 0;
char esc_save[8];
int init_len = strlen(buf);
+ int first = 1;
if (init_len)
cread_add_str(buf, init_len, 1, &num, &eol_num, buf, *len);
@@ -707,6 +709,16 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len)
WATCHDOG_RESET();
}
#endif
+ if (first && timeout) {
+ uint64_t etime = endtick(timeout);
+
+ while (!tstc()) { /* while no incoming data */
+ if (get_ticks() >= etime)
+ return -2; /* timed out */
+ WATCHDOG_RESET();
+ }
+ first = 0;
+ }
ichar = getcmd_getch();
@@ -922,11 +934,11 @@ int readline (const char *const prompt)
*/
console_buffer[0] = '\0';
- return readline_into_buffer(prompt, console_buffer);
+ return readline_into_buffer(prompt, console_buffer, 0);
}
-int readline_into_buffer (const char *const prompt, char * buffer)
+int readline_into_buffer(const char *const prompt, char *buffer, int timeout)
{
char *p = buffer;
#ifdef CONFIG_CMDLINE_EDITING
@@ -949,7 +961,7 @@ int readline_into_buffer (const char *const prompt, char * buffer)
if (prompt)
puts (prompt);
- rc = cread_line(prompt, p, &len);
+ rc = cread_line(prompt, p, &len, timeout);
return rc < 0 ? rc : len;
} else {
diff --git a/common/menu.c b/common/menu.c
index 5e0817c454..3b1e0d0820 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -222,7 +222,8 @@ static inline int menu_interactive_choice(struct menu *m, void **choice)
menu_display(m);
- readret = readline_into_buffer("Enter choice: ", cbuf);
+ readret = readline_into_buffer("Enter choice: ", cbuf,
+ m->timeout);
if (readret >= 0) {
choice_item = menu_item_by_key(m, cbuf);